R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandMapped2Cal.cxx
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2025 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
15#include "FairLogger.h"
16#include "FairRootManager.h"
17#include "FairRunAna.h"
18#include "FairRuntimeDb.h"
19#include "R3BEventHeader.h"
20#include "R3BLogger.h"
21#include "R3BNeulandCalData.h"
24#include "R3BTCalEngine.h"
25#include "R3BTCalPar.h"
26#include "TClonesArray.h"
27#include "TH2F.h"
28#include "TMath.h"
29
31 : FairTask("NeulandMapped2Cal", 1)
32 , fNEvents(0)
33 , fPulserMode(kFALSE)
34 , fWalkEnabled(kTRUE)
35 , fMapped(NULL)
36 , fMappedTrigger(NULL)
37 , fMapPar(NULL)
38 , fCal(new TClonesArray("R3BNeulandCalData"))
39 , fNPmt(0)
40 , fTcalPar(NULL)
41 , fTrigger(-1)
42 , fClockFreq(1. / VFTX_CLOCK_MHZ * 1000.)
43{
44}
45
46R3BNeulandMapped2Cal::R3BNeulandMapped2Cal(const char* name, Int_t iVerbose)
47 : FairTask(name, iVerbose)
48 , fNEvents(0)
49 , fPulserMode(kFALSE)
50 , fWalkEnabled(kTRUE)
51 , fMapped(NULL)
52 , fMappedTrigger(NULL)
53 , fMapPar(NULL)
54 , fCal(new TClonesArray("R3BNeulandCalData"))
55 , fNPmt(0)
56 , fTcalPar(NULL)
57 , fTrigger(-1)
58 , fClockFreq(1. / VFTX_CLOCK_MHZ * 1000.)
59{
60}
61
63{
64 if (fCal)
65 {
66 delete fCal;
67 fCal = NULL;
68 fNPmt = 0;
69 }
70}
71
73{
74 fNofTcalPars = fTcalPar->GetNumModulePar();
75
76 if (fNofTcalPars == 0)
77 {
78 LOG(error) << "There are no TCal parameters in container LandTCalPar";
79 return kFATAL;
80 }
81
82 LOG(info) << "R3BNeulandMapped2Cal::Init : read " << fNofTcalPars << " calibrated modules";
83
84 FairRootManager* mgr = FairRootManager::Instance();
85 if (NULL == mgr)
86 {
87 LOG(fatal) << "FairRootManager not found";
88 }
89
90 header = dynamic_cast<R3BEventHeader*>(mgr->GetObject("EventHeader."));
91 if (NULL == header)
92 {
93 LOG(fatal) << "Branch R3BEventHeader not found";
94 }
95
96 fMapped = dynamic_cast<TClonesArray*>(mgr->GetObject("NeulandMappedData"));
97 if (NULL == fMapped)
98 {
99 LOG(fatal) << "Branch NeulandMapped not found";
100 }
101 fMappedTrigger = dynamic_cast<TClonesArray*>(mgr->GetObject("NeulandTrigMappedData"));
102 if (NULL == fMappedTrigger)
103 {
104 LOG(info) << "Branch NeulandTrigMapped not found";
105 }
106
107 mgr->Register("NeulandCalData", "Neuland", fCal, kTRUE);
108 fCal->Clear();
109
110 htcal1 = new TH2F("htcal1", "htcal1", 800, 0.5, 800.5, 500, -1., 6.);
111 htcal2 = new TH2F("htcal2", "htcal2", 800, 0.5, 800.5, 500, -1., 6.);
112 htcal3 = new TH2F("htcal3", "htcal3", 800, 0.5, 800.5, 500, -1., 6.);
113 htcal4 = new TH2F("htcal4", "htcal4", 800, 0.5, 800.5, 500, -1., 6.);
114
115 SetParameter();
116 R3BLOG(info, "Read " << fNofTcalPars << " modules");
117 return kSUCCESS;
118}
119
121{
122 // Parameter Container
123 FairRuntimeDb* rtdb = FairRuntimeDb::instance();
124 R3BLOG_IF(error, !rtdb, "FairRuntimeDb not found");
125
126 fMapPar = dynamic_cast<R3BNeulandMappingPar*>(rtdb->getContainer("neulandMappingPar"));
127 R3BLOG_IF(warn, !fMapPar, "Could not get access to neulandMappingPar container");
128
129 fTcalPar = dynamic_cast<R3BTCalPar*>(rtdb->getContainer("LandTCalPar"));
130
131 if (!fTcalPar)
132 {
133 LOG(error) << "Could not get access to LandTCalPar-Container.";
134 fNofTcalPars = 0;
135 }
136 return;
137}
138
139void R3BNeulandMapped2Cal::SetParameter()
140{
141 //--- Parameter Container ---
142 R3BLOG_IF(info, fMapPar, "Nb of planes " << fMapPar->GetNbPlanes() << " and paddles " << fMapPar->GetNbPaddles());
143 if (fMapPar)
144 {
145 fNofPlanes = fMapPar->GetNbPlanes();
146 fNofBarsPerPlane = fMapPar->GetNbPaddles();
147 }
148
149 fNofTcalPars = fTcalPar->GetNumModulePar();
150 R3BLOG_IF(fatal, fNofTcalPars == 0, "There are no TCal parameters in container TofdTCalPar");
151 return;
152}
153
155{
157 SetParameter();
158 return kSUCCESS;
159}
160
161void R3BNeulandMapped2Cal::Exec(Option_t* option)
162{
163 if (fTrigger >= 0)
164 {
165 if (header->GetTrigger() != fTrigger)
166 {
167 return;
168 }
169 }
170
171 Int_t nHits = fMapped->GetEntriesFast();
172 if (fPulserMode)
173 {
174 if (nHits < fNofPMTs)
175 {
176 return;
177 }
178 }
179 else
180 {
181 if (nHits > (fNofPMTs / 2))
182 {
183 return;
184 }
185 }
186
187 if (nHits >= fNhitmin) // ig 0
188 {
189 MakeCal();
190 }
191}
192
193void R3BNeulandMapped2Cal::MakeCal()
194{
195 Int_t nHits = 0;
196 // Map and calibrate triggers.
197 std::vector<double> trig_map(13 * fNofPlanes);
198 if (fMappedTrigger)
199 {
200 nHits = fMappedTrigger->GetEntriesFast();
201 for (int i = 0; i < nHits; ++i)
202 {
203 auto* mapped = dynamic_cast<R3BPaddleTamexMappedData*>(fMappedTrigger->At(i));
204 auto iBar = mapped->GetBarId();
205 auto par = fTcalPar->GetModuleParAt(100, iBar, 10);
206 if (!par)
207 {
208 continue;
209 }
210 auto time = par->GetTimeVFTX(mapped->fFineTime1LE);
211 trig_map.at(iBar - 1) = fClockFreq - time + mapped->fCoarseTime1LE * fClockFreq;
212 }
213 }
214 nHits = fMapped->GetEntriesFast();
215
216 R3BTCalModulePar* par;
217
218 Int_t tdc;
219 Double_t timeLE;
220 Double_t timeTE;
221
222 for (Int_t ihit = 0; ihit < nHits; ihit++)
223 {
224 R3BPaddleTamexMappedData* hit = dynamic_cast<R3BPaddleTamexMappedData*>(fMapped->At(ihit));
225 if (NULL == hit)
226 {
227 continue;
228 }
229
230 Double_t qdc = -1.;
231
232 Int_t iPlane = hit->GetPlaneId();
233 Int_t iBar = hit->GetBarId();
234 Int_t iSide = -1 == hit->fCoarseTime1LE ? 2 : 1;
235
236 auto trig_i = fMapPar->GetTrigMap(iPlane, iBar, iSide);
237 double trig_ns = NAN;
238 if (fMappedTrigger)
239 trig_ns = trig_map.at(trig_i);
240
241 if (hit->Is17())
242 {
243 // 17-th channel
244 continue;
245 }
246
247 if ((iPlane < 1) || (iPlane > fNofPlanes))
248 {
249 LOG(info) << "R3BNeulandMapped2TCal::Exec : Plane number out of range: " << iPlane;
250 continue;
251 }
252 if ((iBar < 1) || (iBar > fNofBarsPerPlane))
253 {
254 LOG(info) << "R3BNeulandMapped2TCal::Exec : Bar number out of range: " << iBar;
255 continue;
256 }
257
258 int edge = 2 * iSide - 1;
259
260 // Convert TDC to [ns] leading
261 if (!(par = fTcalPar->GetModuleParAt(iPlane, iBar, edge)))
262 {
263 LOG(debug) << "R3BNeulandTcal::Exec : Tcal par not found, barId: " << iBar << ", side: " << iSide;
264 continue;
265 }
266
267 tdc = 1 == iSide ? hit->fFineTime1LE : hit->fFineTime2LE;
268 timeLE = par->GetTimeVFTX(tdc);
269
270 // Convert TDC to [ns] trailing
271 if (!(par = fTcalPar->GetModuleParAt(iPlane, iBar, edge + 1)))
272 {
273 LOG(debug) << "R3BNeulandTcal::Exec : Tcal par not found, barId: " << iBar << ", side: " << iSide;
274 continue;
275 }
276
277 tdc = 1 == iSide ? hit->fFineTime1TE : hit->fFineTime2TE;
278 timeTE = par->GetTimeVFTX(tdc);
279
280 if (timeLE < 0. || timeLE > fClockFreq || timeTE < 0. || timeTE > fClockFreq)
281 {
282 LOG(error) << "R3BNeulandMapped2Tcal::Exec : error in time calibration: ch= " << iPlane << iBar << iSide
283 << ", tdc= " << tdc << ", time leading edge = " << timeLE << ", time trailing edge = " << timeTE;
284 continue;
285 }
286
287 if (1 == iSide)
288 {
289 htcal1->Fill((iPlane - 1) * 50 + iBar, timeLE);
290 htcal2->Fill((iPlane - 1) * 50 + iBar, timeTE);
291 }
292 if (2 == iSide)
293 {
294 htcal3->Fill((iPlane - 1) * 50 + iBar, timeLE);
295 htcal4->Fill((iPlane - 1) * 50 + iBar, timeTE);
296 }
297
298 auto coarse = 1 == iSide ? hit->fCoarseTime1LE : hit->fCoarseTime2LE;
299 timeLE = fClockFreq - timeLE + coarse * fClockFreq;
300 coarse = 1 == iSide ? hit->fCoarseTime1TE : hit->fCoarseTime2TE;
301 timeTE = fClockFreq - timeTE + coarse * fClockFreq;
302
303 if (timeTE - timeLE < 0)
304 {
305 qdc = 2048 * fClockFreq + timeTE - timeLE;
306 }
307 else
308 {
309 qdc = timeTE - timeLE;
310 }
311
312 if (fWalkEnabled)
313 timeLE = timeLE + WalkCorrection(qdc);
314
315 new ((*fCal)[fNPmt]) R3BNeulandCalData((iPlane - 1) * 50 + iBar, iSide, timeLE, trig_ns, qdc);
316 fNPmt += 1;
317 LOG(debug2) << "tot: " << qdc << "lt: " << timeLE << "trigT: " << trig_ns << "\n";
318
319 // Subtract trigger time.
320 // timeLE -= trig_ns;
321 // timeTE -= trig_ns;
322
323 // qdc = timeTE - timeLE;
324
325 // Put all times in reasonable range.
326 // double const c_range = 2048 * 5.;
327 // timeLE = fmod(timeLE + c_range + c_range/2, c_range) - c_range/2;
328 // timeTE = fmod(timeTE + c_range + c_range/2, c_range) - c_range/2;
329 // qdc = fmod(qdc + c_range + c_range/2, c_range) - c_range/2;
330 }
331}
332
334{
335 if (fVerbose && 0 == (fNEvents % 100000))
336 {
337 LOG(info) << "R3BNeulandMapped2Cal::Exec : event=" << fNEvents << " nPMTs=" << fNPmt;
338 }
339
340 if (fCal)
341 {
342 fCal->Clear();
343 fNPmt = 0;
344 }
345
346 fNEvents += 1;
347}
348
350{
351
352 htcal1->Write();
353 htcal2->Write();
354 htcal3->Write();
355 htcal4->Write();
356}
357
358Double_t R3BNeulandMapped2Cal::WalkCorrection(Double_t x)
359{
360 Double_t y = 0;
361 Double_t y0 = 0;
362 Double_t y1 = 0;
363
364 x = x * 17.2278 / 162.464;
365
366 y0 = -4.29359 + 17.3841 / sqrt(x) + 0.073181; // veronika 3
367
368 y1 = 1.59667 + 78.5274 * pow(x, -1.97051) - 4.00192 / x - 0.125473 * x + 0.00130958 * x * x; // veronika 2
369
370 y = (y0 + y1) / 2.;
371
372 if (x > 25.0000)
373 y = y0;
374 // y = -4.29359 + 17.3841/sqrt(x)+0.073181; // veronika 3
375
376 return -1. * y;
377}
378
379/*Double_t R3BNeulandMapped2Cal::WalkCorrection(Double_t x)
380{
381 Double_t y = 0;
382
383 if (x < 0.)
384 return y;
385
386 Double_t walkval[34] = { 69.5, // 18
387 68.0, // 22
388 67.6, // 26
389 65.6, // 30
390 65.0, // 34
391 63.8, // 38
392 62.9, // 42
393 62.5, // 46
394 62.1, // 50
395 61.8, // 54
396 61.5, // 58
397 61.0, // 62
398 60.85, // 66
399 60.7, // 70
400 60.55, // 74
401 60.4, // 78
402 60.3, // 82 60.25
403 60.27, // 86 60.4
404 60.05, // 90
405 60.05, // 94 60.1
406 60.0, // 98
407 59.8, // 102
408 59.7, // 106
409 59.6, // 110
410 59.6, // 114
411 59.55, // 118
412 59.4, // 122
413 59.4, // 126
414 59.3, // 130
415 59.25, // 134
416 59.05, // 138
417 59.0, // 142 58.95
418 58.95, 58.91 };
419
420 if (x < 16.)
421 y = 70.5 - x / 4.;
422
423 for (Int_t i = 0; i < 34; i++)
424 {
425
426 if (x >= 16. + 4. * i && x < 20 + 4. * i)
427 y = walkval[i];
428 }
429
430 if (x >= 152. && x < 160.)
431 y = 58.9 + 0.08 / 8. * (160. - x);
432 if (x >= 160.)
433 y = 58.55 + 0.3 / 30. * (190. - x);
434 // if (x>=160.&&x<190.) y = 58.7 + 0.4/30.*(190.-x);
435 // if (x>=190.) y = 58.5;
436
437 return 58.6 - y;
438}
439*/
440
#define R3BLOG(severity, x)
Definition R3BLogger.h:35
#define R3BLOG_IF(severity, condition, x)
Definition R3BLogger.h:46
ClassImp(R3B::Neuland::Cal2HitPar)
An analysis task to apply TCAL calibration for NeuLAND.
virtual InitStatus ReInit()
Method for re-initialization of parameter containers in case the Run ID has changed.
virtual void FinishTask()
Method for finish of the task execution.
virtual void SetParContainers()
Method for initialization of the parameter containers.
virtual void FinishEvent()
A method for finish of processing of an event.
R3BNeulandMapped2Cal()
Default constructor.
virtual InitStatus Init()
Method for task initialization.
virtual ~R3BNeulandMapped2Cal()
Destructor.
virtual void Exec(Option_t *option)
Method for event loop implementation.
const Int_t GetNbPlanes()
Accessor functions.