forked from R3BRootGroup/R3BRoot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathR3BPdcMapped2Cal.cxx
190 lines (160 loc) · 6.01 KB
/
R3BPdcMapped2Cal.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/******************************************************************************
* Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
* Copyright (C) 2019 Members of R3B Collaboration *
* *
* This software is distributed under the terms of the *
* GNU General Public Licence (GPL) version 3, *
* copied verbatim in the file "LICENSE". *
* *
* In applying this license GSI does not waive the privileges and immunities *
* granted to it by virtue of its status as an Intergovernmental Organization *
* or submit itself to any jurisdiction. *
******************************************************************************/
#include <assert.h>
#include "R3BPdcMapped2Cal.h"
#include "TClonesArray.h"
#include "TMath.h"
#include "FairLogger.h"
#include "FairRuntimeDb.h"
#include "R3BPdcCalData.h"
#include "R3BPdcMappedData.h"
#include "R3BTCalEngine.h"
#include "R3BEventHeader.h"
extern "C"
{
//#include "ext_data_client.h"
#include "ext_h101_pdc.h"
}
#define LENGTH(x) (sizeof x / sizeof *x)
#define IS_NAN(x) TMath::IsNaN(x)
R3BPdcMapped2Cal::R3BPdcMapped2Cal()
: FairTask("R3BPdcMapped2Cal", 1)
, fMappedItems(nullptr)
, fCalItems(new TClonesArray("R3BPdcCalData"))
, fCalTriggerItems(new TClonesArray("R3BPdcCalData"))
, fTcalPar(0)
, fNofTcalPars(0)
, fTrigger(-1)
, fClockFreq(1000. / CTDC_16_CLOCK_MHZ)
{
}
R3BPdcMapped2Cal::R3BPdcMapped2Cal(Int_t iVerbose)
: FairTask("R3BPdcMapped2Cal", iVerbose)
, fMappedItems(nullptr)
, fCalItems(new TClonesArray("R3BPdcCalData"))
, fCalTriggerItems(new TClonesArray("R3BPdcCalData"))
, fTcalPar(0)
, fNofTcalPars(0)
, fTrigger(-1)
, fClockFreq(1000. / CTDC_16_CLOCK_MHZ)
{
}
R3BPdcMapped2Cal::~R3BPdcMapped2Cal()
{
delete fCalItems;
delete fCalTriggerItems;
}
InitStatus R3BPdcMapped2Cal::Init()
{
fNofTcalPars = fTcalPar->GetNumModulePar();
if (fNofTcalPars == 0)
{
LOG(ERROR) << "There are no TCal parameters in container PdcTCalPar";
return kFATAL;
}
LOG(INFO) << "R3BPdcMapped2Cal::Init : read " << fNofTcalPars << " modules";
// try to get a handle on the EventHeader. EventHeader may not be
// present though and hence may be null. Take care when using.
FairRootManager* mgr = FairRootManager::Instance();
if (NULL == mgr)
LOG(fatal) << "FairRootManager not found";
// get access to Mapped data
fMappedItems = (TClonesArray*)mgr->GetObject("PdcMapped");
if (NULL == fMappedItems)
LOG(fatal) << "Branch PdcMapped not found";
// request storage of Cal data in output tree
mgr->Register("PdcCal", "Land", fCalItems, kTRUE);
mgr->Register("PdcTriggerCal", "Land", fCalTriggerItems, kTRUE);
return kSUCCESS;
}
// Note that the container may still be empty at this point.
void R3BPdcMapped2Cal::SetParContainers()
{
fTcalPar = (R3BTCalPar*)FairRuntimeDb::instance()->getContainer("PdcTCalPar");
if (!fTcalPar)
{
LOG(ERROR) << "Could not get access to PdcTCalPar-Container.";
fNofTcalPars = 0;
}
}
InitStatus R3BPdcMapped2Cal::ReInit()
{
SetParContainers();
return kSUCCESS;
}
void R3BPdcMapped2Cal::Exec(Option_t* option)
{
auto mapped_num = fMappedItems->GetEntriesFast();
LOG(DEBUG) << "R3BPdcMapped2Cal::Exec:fMappedItems=" << fMappedItems->GetName() << '.';
for (auto i = 0; i < mapped_num; i++)
{
auto mapped = (R3BPdcMappedData*)fMappedItems->At(i);
assert(mapped);
auto wire = mapped->GetWireId();
LOG(DEBUG) << " R3BPdcMapped2Cal::Exec:wire=" << wire
<< ":Edge=" << (mapped->GetEdgeId() == 1 ? "Leading" : "Trailing") << '.';
// Fetch tcal parameters.
R3BTCalModulePar* par;
par = fTcalPar->GetModuleParAt(mapped->GetPlaneId(), mapped->GetWireId(), mapped->GetEdgeId());
if (!par)
{
LOG(WARNING) << "R3BPdcMapped2Cal::Exec (" << fName << "): Wire=" << wire << ": TCal par not found.";
continue;
}
Double_t time_ns = -1;
// Calibrate fine time.
auto fine_raw = mapped->GetTimeFine();
if (-1 == fine_raw)
{
// TODO: Is this really ok?
continue;
}
auto fine_ns = par->GetTimeClockTDC(fine_raw);
LOG(DEBUG) << " R3BPdcMapped2Cal::Exec: Fine raw=" << fine_raw << " -> ns=" << fine_ns << '.';
if (fine_ns < 0. || fine_ns >= fClockFreq)
{
LOG(ERROR) << "R3BPdcMapped2Cal::Exec (" << fName << "): Wire=" << wire
<< ": Bad CTDC fine time (raw=" << fine_raw << ",ns=" << fine_ns << ").";
continue;
}
time_ns = mapped->GetTimeCoarse() * fClockFreq - fine_ns;
// LOG(DEBUG) << " R3BPdcMapped2Cal::Exec (" << fName << "): wire=" << wire
// << ": Time=" << time_ns << "ns.";
// cout << "mapped2cal plane: " << mapped->GetPlaneId() << " Wire: " << mapped->GetWireId()
// << " Edge: " << mapped->GetEdgeId() << " Time: " << time_ns << endl;
if (LENGTH(EXT_STR_h101_PDC_onion::PDC_P) + 1 == mapped->GetPlaneId())
{
new ((*fCalTriggerItems)[fCalTriggerItems->GetEntriesFast()])
R3BPdcCalData(mapped->GetPlaneId(), mapped->GetWireId(), mapped->GetEdgeId(), time_ns);
}
else
{
new ((*fCalItems)[fCalItems->GetEntriesFast()])
R3BPdcCalData(mapped->GetPlaneId(), mapped->GetWireId(), mapped->GetEdgeId(), time_ns);
}
}
fnEvents++;
}
void R3BPdcMapped2Cal::FinishEvent()
{
if (fCalItems)
{
fCalItems->Clear();
}
if (fCalTriggerItems)
{
fCalTriggerItems->Clear();
}
}
void R3BPdcMapped2Cal::FinishTask() {}
ClassImp(R3BPdcMapped2Cal)