BmnRoot
Loading...
Searching...
No Matches
BmnTof1HitProducer.cxx
Go to the documentation of this file.
2
3#include "BmnTOF1Point.h"
4#include "BmnTof1Digit.h"
5#include "BmnTofHit.h"
6#include "CbmMCTrack.h"
7#include "FairLogger.h"
8#include "FairRootManager.h"
9
10#include <TClonesArray.h>
11#include <TGeoManager.h>
12#include <TStopwatch.h>
13#include <TVector3.h>
14#include <iostream>
15
16using namespace std;
17
18static Double_t workTime = 0.0;
19
20//--------------------------------------------------------------------------------------------------------------------------------------
21
22BmnTof1HitProducer::BmnTof1HitProducer(const char* name, DetectorId detId, Bool_t useMCdata, Int_t verbose, Bool_t test)
23 : BmnTof1HitProducerIdeal(name, useMCdata, verbose, test)
24 , fVerbose(verbose)
25 , fTimeSigma(0.100)
26 , fErrX(1. / sqrt(12.))
27 , fErrY(0.5)
28 , fEffFunc(nullptr)
29 , pRandom(nullptr)
30 , pGeoUtils(nullptr)
31 , pDetector(nullptr)
32 , fNDetectors(0)
33 , fDetectorId(detId)
34{
35 pGeoUtils = new BmnTof1GeoUtils;
36 fEffFunc = new TF1("eff_func", "[0]*x+[1]", 0, 3);
37 if (fDetectorId == kTOF1) {
38 fDetName = "TOF400";
39 fPointsName = "TOF400Point";
40 fDigitsName = "TOF400";
41 fHitsName = "BmnTof400Hit";
42 fErrX = 1. / sqrt(12.);
43 fErrY = 0.5;
44 }
45 if (fDetectorId == kTOF701) {
46 fDetName = "TOF700";
47 fPointsName = "TOF700Point";
48 fDigitsName = "TOF701";
49 fHitsName = "BmnTof700Hit";
50 fErrX = 0.8;
51 fErrY = 0.5;
52 }
53
54 if (fDoTest) {
55 fTestFlnm = Form("Test_%s_run%d.root", fDetName.Data(), fRun);
56 fileCont = new TFile(fTestFlnm.Data(), "RECREATE");
57 treeCont = new TTree("data", "data");
58 aTofCont = new TClonesArray("BmnTOF1Conteiner");
59 treeCont->Branch(fDetName.Data(), &aTofCont);
60 }
61}
62//--------------------------------------------------------------------------------------------------------------------------------------
63
65{
66 if (!fUseMCData) {
67 if (pDetector) {
68 for (Int_t i = 0; i < fNDetectors; i++) {
69 delete pDetector[i];
70 }
71 delete[] pDetector;
72 }
73 }
74 delete fEffFunc;
75 delete pRandom;
76 delete pGeoUtils;
77}
78//--------------------------------------------------------------------------------------------------------------------------------------
79
80InitStatus BmnTof1HitProducer::LoadDetectorConfiguration()
81{
82 // Parsing geometry
83 fNDetectors = -1;
84 if (fDetectorId == kTOF1) {
85 fNDetectors = pGeoUtils->ParseTGeoManager(fUseMCData, true, fVerbose);
86 pGeoUtils->FindNeighborStrips(fVerbose);
87 }
88 if (fDetectorId == kTOF701) {
89 fNDetectors = pGeoUtils->ParseTGeoManager701(fUseMCData, true, fVerbose);
90 pGeoUtils->FindNeighborStrips701(fVerbose);
91 }
92
93 if (fNDetectors <= 0) {
94 cout << this->GetName() << "::LoadDetectorConfiguration(): No " << fDetName
95 << " detectors in geometry file for the current run! Task will be deactivated" << endl;
96 SetActive(kFALSE);
97 return kERROR;
98 }
99 if (fVerbose)
100 cout << this->GetName() << "::LoadDetectorConfiguration(): number of " << fDetName
101 << " Detectors from geometry file = " << fNDetectors << endl;
102
103 // Init BmnTOF1Detectors
104 if (!fUseMCData) {
105 if (!SetCorrFiles()) {
106 cout << this->GetName()
107 << "::LoadDetectorConfiguration(): No corrections for the current run! Task will be deactivated"
108 << endl;
109 SetActive(kFALSE);
110 return kERROR;
111 }
112
113 pDetector = new BmnTOF1Detector*[fNDetectors];
114 for (Int_t i = 0; i < fNDetectors; i++) {
115 Int_t DoTestForDetector =
116 0; // For developers only. Level of Histograms filling (0-don't fill, 1-low, 2-high).
117 if (fDoTest)
118 DoTestForDetector = 1;
119 // cout << "Detector # " << i << endl;
120 pDetector[i] = new BmnTOF1Detector(fDetectorId, i, DoTestForDetector, fVerbose);
121 if (FlagFileLRcorrection)
122 pDetector[i]->SetCorrLR(NameFileLRcorrection);
123 if (FlagFileSlewingCorrection)
124 pDetector[i]->SetCorrSlewing(NameFileSlewingCorrection);
125 if (FlagFileTimeShiftCorrection)
126 pDetector[i]->SetCorrTimeShift(NameFileTimeShiftCorrection);
127
128 pDetector[i]->SetGeo(pGeoUtils);
129
130 if (fDetectorId == kTOF701)
131 pDetector[i]->SetSpeedOfSignal("CorreSpeed.txt");
132
133 if (fPeriod == 6 && fDetectorId == kTOF1) {
134 // cout << "!!!!!!!!!!!!!!!! Kill Strip !!!!!!!!!!!!!!!!!!" << endl;
135 pDetector[i]->KillStrip(0);
136 pDetector[i]->KillStrip(47);
137 }
138 }
139 }
140
141 return kSUCCESS;
142}
143
144//--------------------------------------------------------------------------------------------------------------------------------------
145
147{
148 if (fVerbose)
149 printf("\n=================== %s::Init(): Start================\n", this->GetName());
150
151 pRandom = new TRandom2();
152
153 if (fOnlyPrimary)
154 cout << " Only primary particles are processed!!! \n"; // FIXME NOT used now ADDD
155
156 if (fUseMCData) {
157 aMcPoints = (TClonesArray*)FairRootManager::Instance()->GetObject(fPointsName.Data());
158 if (!aMcPoints) {
159 cout << this->GetName() << "::Init(): branch " << fPointsName.Data()
160 << " not found! Task will be deactivated" << endl;
161 SetActive(kFALSE);
162 return kERROR;
163 }
164 aMcTracks = (TClonesArray*)FairRootManager::Instance()->GetObject("MCTrack");
165 if (!aMcTracks) {
166 cout << this->GetName() << "::Init(): branch MCTrack not found! Task will be deactivated" << endl;
167 SetActive(kFALSE);
168 return kERROR;
169 }
170 } else {
171 if (fDetectorId != kTOF1 && fDetectorId != kTOF701) {
172 cout << this->GetName() << "::Init(): DetectorId is incorrect. Use kTOF1 or kTOF701." << endl;
173 cout << " kTOF1 = " << kTOF1 << "; kTOF701 = " << kTOF701 << "; fDetectorId = " << fDetectorId << endl;
174 SetActive(kFALSE);
175 return kERROR;
176 }
177 if (fDetectorId == kTOF701 && fPeriod < 8) {
178 std::printf("\x1b[91m"
179 "\n\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
180 "\t!!!!!!!!!!!!!!! %s !!!!!!!!!!!!!\n"
181 "\tThis task is not suitable for this period/run (Period #%d, Run #%d).\n"
182 "\tPlease use the legacy code for the Tof700HitProduser task.\n"
183 "\tFor this purpose, use some old(?) version of bmnroot.\n"
184 "\t!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
185 "\x1b[0m",
186 this->GetName(), fPeriod, fRun);
187 SetActive(kFALSE);
188 return kERROR;
189 }
190
191 fEventHeader = (BmnEventHeader*)FairRootManager::Instance()->GetObject("BmnEventHeader.");
192
193 aExpDigits = (TClonesArray*)FairRootManager::Instance()->GetObject(fDigitsName.Data());
194 if (!aExpDigits) {
195 cout << this->GetName() << "::Init(): branch" << fDigitsName.Data()
196 << " is not found! Task will be deactivated" << endl;
197 SetActive(kFALSE);
198 return kERROR;
199 }
200
201 // looking for T0 branch
202 TString NameT0Branch, NameT0Branch2;
203 if (fPeriod == 6)
204 NameT0Branch = "T0";
205 if (fPeriod == 7)
206 NameT0Branch = "BC2";
207 if (fPeriod == 8) {
208 if (fRun >= 968 && fRun <= 1546) {
209 NameT0Branch = "T0_1_A";
210 NameT0Branch2 = "T0_2_A";
211 }
212 if (fRun >= 6587 && fRun <= 8427) {
213 NameT0Branch = "BC2AT";
214 NameT0Branch2 = "BC2AB";
215 }
216 }
217 if (fPeriod == 9) {
218 // if (fRun >= 9289) {
219 NameT0Branch = "BmnTrigInfo.";
220 // }
221 }
222
223 LOG(info) << this->GetName() << "::Init(): looking for branch " << NameT0Branch << " for start" << endl;
224 if (fPeriod == 9)
225 aExpTrigInfo = (BmnTrigInfoDst*)FairRootManager::Instance()->GetObject(NameT0Branch.Data());
226 else
227 aExpDigitsT0 = (TClonesArray*)FairRootManager::Instance()->GetObject(NameT0Branch.Data());
228
229 if ((fPeriod < 9 && !aExpDigitsT0) || (fPeriod == 9 && !aExpTrigInfo)) {
230 printf("%s::Init(): branch %s is not found! Task will be deactivated\n", this->GetName(),
231 NameT0Branch.Data());
232 SetActive(kFALSE);
233 return kERROR;
234 }
235
236 if (fPeriod == 8) {
237 if (fVerbose)
238 cout << this->GetName() << "::Init(): looking for branch " << NameT0Branch2 << " for start" << endl;
239 aExpDigitsT0_2 = (TClonesArray*)FairRootManager::Instance()->GetObject(NameT0Branch2.Data());
240 if (!aExpDigitsT0_2) {
241 printf("%s::Init(): branch %s is not found! Task will be deactivated\n", this->GetName(),
242 NameT0Branch2.Data());
243 SetActive(kFALSE);
244 return kERROR;
245 }
246 }
247 }
248
249 // Create and register output array
250 aTofHits = new TClonesArray("BmnTofHit");
251 FairRootManager::Instance()->Register(fHitsName.Data(), fDetName.Data(), aTofHits, kTRUE);
252
253 if (LoadDetectorConfiguration() != kSUCCESS) {
254 SetActive(kFALSE);
255 return kERROR;
256 }
257
258 if (fVerbose)
259 printf("\n=================== %s::Init(): Initialization finished succesfully. ==\n\n", this->GetName());
260 return kSUCCESS;
261}
262//--------------------------------------------------------------------------------------------------------------------------------------
263
264Bool_t BmnTof1HitProducer::HitExist(const Double_t& val,
265 const Bool_t& isWide_strip) // val - distance to the pad edge [cm]
266{
267
268 const static Double_t slope = (0.98 - 0.95) / 0.2;
269 Double_t efficiency = (val > 0.2) ? 0.98 : (0.95 + slope * val);
270
271 //-------------------------------------
272 // 99% ---------
273 // /
274 // /
275 // /
276 // 95% /
277 // <-----------|--|
278 // 0.2 0.
279 //-------------------------------------
280
281 if (pRandom->Rndm() < efficiency)
282 return true;
283 return false;
284}
285//------------------------------------------------------------------------------------------------------------------------
286
287Bool_t BmnTof1HitProducer::DoubleHitExist(const Double_t& val,
288 const Bool_t& isWide_strip,
289 const DetectorId& flag) // val - distance to the pad edge [cm]
290{
291 // const static Double_t slope = (0.3 - 0.0) / 0.5;
292 // Double_t efficiency = (val > 0.5) ? 0. : (0.3 - slope * val);
293
294 //-------------------------------------
295 // 30% /|
296 // / |
297 // / |
298 // / |
299 // 5% / |
300 // <-----------|---------|
301 // width 0.
302 // /2
303 //-------------------------------------
304 // if (efficiency == 0.)
305 // return false;
306 if (flag == kTOF701 && isWide_strip) {
307 fEffFunc->SetParameters((0.05 - 0.409) / 0.9375, 0.409);
308 }
309
310 else if (flag == kTOF701 && !isWide_strip)
311 fEffFunc->SetParameters((0.05 - 0.44) / 0.5492, 0.44);
312
313 else
314 fEffFunc->SetParameters((0.05 - 0.339) / 0.625, 0.339);
315
316 Double_t efficiency = fEffFunc->Eval(val);
317
318 if (pRandom->Rndm() < efficiency)
319 return HitExist(val, isWide_strip);
320 return false;
321}
322
323Bool_t BmnTof1HitProducer::TripleHitExist(const Double_t& val,
324 const Bool_t& isWide_strip,
325 const DetectorId& flag) // val - distance to the pad edge [cm]
326{
327
328 if (flag == kTOF701 && isWide_strip)
329 fEffFunc->SetParameters((0.078 - 0.01) / 0.9375, 0.078);
330
331 else if (flag == kTOF701 && !isWide_strip)
332 fEffFunc->SetParameters((0.095 - 0.01) / 0.5492, 0.095);
333
334 else
335 fEffFunc->SetParameters((0.075 - 0.01) / 0.625, 0.075);
336
337 Double_t efficiency = fEffFunc->Eval(val);
338
339 if (pRandom->Rndm() < efficiency)
340 return HitExist(val, isWide_strip);
341 return false;
342}
343//--------------------------------------------------------------------------------------------------------------------------------------
344
345void BmnTof1HitProducer::Exec(Option_t* opt)
346{
347 TStopwatch sw;
348 sw.Start();
349
350 if (!IsActive())
351 return;
352
353 if (fVerbose)
354 printf("\n=================== %s::Exec(): Started ====================\n", this->GetName());
355
356 aTofHits->Clear();
357
358 Int_t UID, trackID;
359 DetectorId detID;
360 TVector3 pos, XYZ_smeared;
361 int nSingleHits = 0, nDoubleHits = 0, nTripleHits = 0;
362
363 if (fUseMCData) {
364 for (Int_t pointIndex = 0, nTofPoint = aMcPoints->GetEntriesFast(); pointIndex < nTofPoint;
365 pointIndex++) // cycle by TOF points
366 {
367 BmnTOF1Point* pPoint = (BmnTOF1Point*)aMcPoints->UncheckedAt(pointIndex);
368 if (fVerbose > 2)
369 pPoint->Print("");
370
371 trackID = pPoint->GetTrackID();
372 UID = pPoint->GetVolumeUID();
373 detID = (DetectorId)pPoint->GetDetectorID();
374 Double_t time = pRandom->Gaus(pPoint->GetTime(), fTimeSigma); // 100 ps
375 pPoint->Position(pos);
376
377 const LStrip1* pStrip = pGeoUtils->FindStrip(UID);
378 const LStrip1* const pcStrip = pStrip;
379 if (pStrip == NULL) {
380 printf("UID is incorrect: UID = %d", UID);
381 break;
382 }
383
384 Bool_t isWide_strip = false;
385 if (detID == kTOF701) {
386 isWide_strip = BmnTOF1Point::GetModule(UID) > 41 ? true : false;
387 }
388 switch (detID) {
389 case kTOF1:
390 XYZ_smeared.SetXYZ(pStrip->center.X(), pRandom->Gaus(pos.Y(), fErrY), pStrip->center.Z());
391 break;
392 case kTOF701:
393 if (isWide_strip)
394 fErrY = 1.875 / sqrt(12.);
395 else {
396 fErrY = 1.09 / sqrt(12.);
397 }
398 XYZ_smeared.SetXYZ(pRandom->Gaus(pos.X(), fErrX), pStrip->center.Y(), pStrip->center.Z());
399 break;
400 default:
401 printf("!!!!! WRONG DetectorID for %s reconstruction\n", fDetName.Data());
402 continue;
403 break;
404 }
405
406 static const TVector3 XYZ_err(fErrX, fErrY, 0.);
407
408 LStrip1::Side_t side;
409 Double_t distance = 1000;
410 if (detID == kTOF1)
411 distance = pStrip->MinDistanceToEdge(&pos, side); // [cm]
412 if (detID == kTOF701)
413 distance = pStrip->MinDistanceToEdge701(&pos, side); // [cm]
414
415 // pStrip->Dump();
416 // cout << " neighboring[0] = " << pStrip->neighboring[0]<< " neighboring[1] = " << pStrip->neighboring[1]
417 // << endl;
418 // cout << "side = " << side << endl;
419
420 bool passed;
421 if ((passed = HitExist(distance, isWide_strip)) == true) // check efficiency
422 {
423 if (pStrip->GetIsKilled() == false) {
424 // printf("\nadding hit\tMChitNo = %d,\tmod = %d,\tstr = %d\n", pointIndex,
425 // BmnTOF1Point::GetModule(UID), BmnTOF1Point::GetStrip(UID) );
426 AddHit(UID, XYZ_smeared, XYZ_err, pointIndex, trackID, time, detID);
427 nSingleHits++;
428 }
429 }
430
431 // printf("UID:\t\t\tside = %d\tmod = %d,\tstrip = %d\n", side, BmnTOF1Point::GetModule(UID),
432 // BmnTOF1Point::GetStrip(UID) ); printf("CrossUID:\t\tside = %d\tmod = %d,\tstrip = %d\n", side,
433 // BmnTOF1Point::GetModule(CrossUID), BmnTOF1Point::GetStrip(CrossUID) ); printf("CrossUID_opp:\tside =
434 // %d\tmod = %d,\tstrip = %d\n\n", side, BmnTOF1Point::GetModule(CrossUID_opposite),
435 // BmnTOF1Point::GetStrip(CrossUID_opposite) );
436
437 if (passed && DoubleHitExist(distance, isWide_strip, detID)) // check cross hit
438 {
439 // cout << "DoubleHit = true pStripUID = " << endl;
440 Int_t CrossUID = -1;
441 CrossUID = (side == LStrip1::kUpper) ? pcStrip->neighboring[LStrip1::kUpper]
442 : pcStrip->neighboring[LStrip1::kLower];
443 CrossUID = (side == LStrip1::kRight) ? pcStrip->neighboring[LStrip1::kRight]
444 : pcStrip->neighboring[LStrip1::kLeft];
445
446 // cout << "Check neighbording strip: CrossUID = " << CrossUID << endl;
447
448 // if (LStrip1::kInvalid == CrossUID)
449 // continue; // last strip on module
450
451 if (CrossUID != LStrip1::kInvalid) {
452 pStrip = pGeoUtils->FindStrip(CrossUID);
453 if (detID == kTOF1)
454 XYZ_smeared.SetXYZ(pStrip->center.X(), pRandom->Gaus(pos.Y(), fErrY), pStrip->center.Z());
455 else if (detID == kTOF701)
456 XYZ_smeared.SetXYZ(pRandom->Gaus(pos.X(), fErrX), pStrip->center.Y(), pStrip->center.Z());
457 else { // unexpected case
458 printf("!!!!! WRONG DetectorID for %s reconstruction\n", fDetName.Data());
459 continue;
460 }
461 // cout << " Save DoubleHit " << endl;
462 if (pStrip->GetIsKilled() == false
464 {
465 // printf("adding dit\tMChitNo = %d,\tmod = %d,\tstr = %d\n", pointIndex,
466 // BmnTOF1Point::GetModule(CrossUID), BmnTOF1Point::GetStrip(CrossUID) );
467 AddHit(CrossUID, XYZ_smeared, XYZ_err, pointIndex, trackID, time, detID);
468 nDoubleHits++;
469 }
470 }
471 } else {
472 passed = false;
473 }
474
475 if ((passed && TripleHitExist(distance, isWide_strip, detID)) == true) {
476 Int_t CrossUID = -1;
477
478 CrossUID = (side == LStrip1::kUpper) ? pcStrip->neighboring[LStrip1::kLower]
479 : pcStrip->neighboring[LStrip1::kUpper];
480 CrossUID = (side == LStrip1::kRight) ? pcStrip->neighboring[LStrip1::kLeft]
481 : pcStrip->neighboring[LStrip1::kRight];
482
483 if (CrossUID != LStrip1::kInvalid) {
484 pStrip = pGeoUtils->FindStrip(CrossUID);
485 if (detID == kTOF1)
486 XYZ_smeared.SetXYZ(pStrip->center.X(), pRandom->Gaus(pos.Y(), fErrY), pStrip->center.Z());
487 else if (detID == kTOF701)
488 XYZ_smeared.SetXYZ(pRandom->Gaus(pos.X(), fErrX), pStrip->center.Y(), pStrip->center.Z());
489 else {
490 printf("!!!!! WRONG DetectorID for %s reconstruction\n", fDetName.Data());
491 continue;
492 }
493 // printf("adding tit\tMChitNo = %d,\tmod = %d,\tstr = %d\n", pointIndex,
494 // BmnTOF1Point::GetModule(CrossUID), BmnTOF1Point::GetStrip(CrossUID) );
495 AddHit(CrossUID, XYZ_smeared, XYZ_err, pointIndex, trackID, time, detID);
496 nTripleHits++;
497 }
498 }
499
500 } // cycle by the TOF points
501 } else {
502 BmnTrigDigit* digT0 = FingT0Digit();
503
504 if (fDoTest)
505 aTofCont->Clear();
506
507 for (Int_t i = 0; i < fNDetectors; i++)
508 pDetector[i]->Clear();
509
510 for (Int_t iDig = 0; iDig < aExpDigits->GetEntriesFast(); ++iDig) {
511
512 BmnTof1Digit* digTof = (BmnTof1Digit*)aExpDigits->At(iDig);
513 // cout << "SETTING PLANE " << digTof->GetPlane() << "\n";
514 if (!OutOfRange(digTof->GetPlane())) {
515 // pDetector[digTof->GetPlane()]->SetDigit(digTof, iDig);
516 pDetector[digTof->GetPlane()]->SetDigitNew(digTof, iDig);
517 }
518 }
519
520 for (Int_t i = 0; i < fNDetectors; i++) {
521 // if (fEventHeader->GetEventId() == 10576)
522 // nSingleHits += pDetector[i]->FindHitsNew(digT0, aTofHits, 1);
523 // else
524 nSingleHits += pDetector[i]->FindHitsNew(digT0, aTofHits, 0);
525
526 if (fDoTest) {
527 cout << "Start fill TClonesArray" << endl;
528 pDetector[i]->FindHitsNew(digT0, aTofCont, 0);
529 }
530 }
531 }
532
533 if (fUseMCData)
534 MergeHitsOnStrip(); // save only the fastest hit in the strip. Used for MC only
535
536 int nFinally = CompressHits(); // remove blank slotes
537
538 if (fDoTest) {
539 cout << "Fill TTree" << endl;
540 treeCont->Fill();
541 }
542
543 sw.Stop();
544 workTime += sw.RealTime();
545
546 if (fVerbose) {
547 cout << fDetName << ": single hits= " << nSingleHits << ", double hits= " << nDoubleHits
548 << ", triple hits= " << nTripleHits << ", final hits= " << nFinally << endl;
549 printf("\n=================== %s::Exec(): Finished ===================\n", this->GetName());
550 }
551}
552//--------------------------------------------------------------------------------------------------------------------------------------
553
555{
556 if (fDoTest) {
557 // fTestFlnm = Form("Test_%s_run%d.root", fDetName.Data(), fRun);
558 // TFile file(fTestFlnm.Data(), "RECREATE");
559
560 if (!fUseMCData) {
561 fileCont->cd();
562 treeCont->Write();
563 fileCont->Close();
564 for (Int_t i = 0; i < fNDetectors; i++)
565 pDetector[i]->SaveHistToFile(fTestFlnm.Data());
566 }
567 }
568
569 printf("Work time of %s: %4.2f sec.\n", this->GetName(), workTime);
570}
571
572//--------------------------------------------------------------------------------------------------------------------------------------
573
575{
576 pRandom->SetSeed(seed);
577}
578//--------------------------------------------------------------------------------------------------------------------------------------
579
580BmnTrigDigit* BmnTof1HitProducer::FingT0Digit()
581{
582 BmnTrigDigit* digT0 = NULL;
583 BmnTrigDigit* digT0_1 = NULL;
584 BmnTrigDigit* digT0_2 = NULL;
585
586 if (fPeriod < 8) {
587 for (Int_t i = 0; i < aExpDigitsT0->GetEntriesFast(); i++) {
588 digT0 = (BmnTrigDigit*)aExpDigitsT0->At(i);
589 if (digT0->GetMod() == 0) {
590 // if (fVerbose)
591 // cout << "BmnTof1HitProducer::FingT0Digit(): T0 digit is found, Time = " << digT0->GetTime() <<
592 // endl;
593 return digT0; // take first T0 digit with Mod == 0. needed for ToF calculation.
594 }
595 }
596 } else if (fPeriod == 8) {
597 digT0 = new BmnTrigDigit();
598 if (aExpDigitsT0->GetEntriesFast() == 0 || aExpDigitsT0_2->GetEntriesFast() == 0)
599 return NULL;
600 // SRC 2022
601 if (fRun >= 968 && fRun <= 1546) {
602 digT0_1 = (BmnTrigDigit*)aExpDigitsT0->At(0);
603 digT0_2 = (BmnTrigDigit*)aExpDigitsT0_2->At(0);
604 digT0->SetAmp(digT0_1->GetAmp() + digT0_2->GetAmp());
605 digT0->SetTime((digT0_1->GetTime() + digT0_2->GetTime()) * 0.5);
606 }
607
608 // BMN 2022-2023
609 if (fRun >= 6587 && fRun <= 8427) {
610 Bool_t FlagHitTop = kFALSE, FlagHitBotom = kFALSE;
611
612 for (Int_t iDig = 0; iDig < aExpDigitsT0->GetEntriesFast(); ++iDig) {
613 digT0_1 = (BmnTrigDigit*)aExpDigitsT0->At(iDig);
614 // cout << "digT0_1 = " << digT0_1->GetTime() << endl;
615 if (digT0_1->GetTime() >= 1900 && digT0_1->GetTime() <= 1960) { // cut for trigger particle time
616 FlagHitTop = kTRUE;
617 break;
618 }
619 }
620
621 for (Int_t iDig = 0; iDig < aExpDigitsT0_2->GetEntriesFast(); ++iDig) {
622 digT0_2 = (BmnTrigDigit*)aExpDigitsT0_2->At(iDig);
623 // cout << "digT0_2 = " << digT0_2->GetTime() << endl;
624 if (digT0_2->GetTime() >= 1900 && digT0_2->GetTime() <= 1960) { // cut for trigger particle time
625 FlagHitBotom = kTRUE;
626 break;
627 }
628 }
629
630 if (FlagHitTop && FlagHitBotom) {
631 digT0->SetAmp(digT0_1->GetAmp() + digT0_2->GetAmp());
632 digT0->SetTime((digT0_1->GetTime() + digT0_2->GetTime()) * 0.5);
633 }
634 }
635
636 return digT0; // return Time and Amp (two PMT on one Scintillator)
637 } else if (fPeriod == 9) {
638
639 if (!aExpTrigInfo)
640 return NULL;
641
642 digT0 = new BmnTrigDigit();
643 digT0->SetAmp(aExpTrigInfo->GetT0_amp());
645
646 return digT0;
647 }
648 return NULL;
649}
650
651//--------------------------------------------------------------------------------------------------------------------------------------
652
653Bool_t BmnTof1HitProducer::IsFile(TString NameFile = "")
654{
655 NameFile = Form("%s%s%s", getenv("VMCWORKDIR"), "/input/", NameFile.Data());
656 ifstream Temp;
657 Temp.open(NameFile, ios::in /*| ios::nocreate*/);
658 return Temp.is_open();
659}
660//--------------------------------------------------------------------------------------------------------------------------------------
661
662Bool_t BmnTof1HitProducer::SetCorrFiles()
663{
664 FlagFileLRcorrection = true;
665 FlagFileSlewingCorrection = true;
666 FlagFileTimeShiftCorrection = true;
667
668 NameFileLRcorrection = "";
669 NameFileSlewingCorrection = "";
670 NameFileTimeShiftCorrection = "";
671
672 // Run 6 (03.2017)
673 if (fPeriod == 6) {
674 NameFileLRcorrection = Form("TOF400_LRCorr_RUN%i.dat", fPeriod);
675 NameFileSlewingCorrection = Form("TOF400_SlewingCorr_RUN%i.root", fPeriod);
676 NameFileTimeShiftCorrection = Form("TOF400_TimeShiftCorr_RUN%i.dat", fPeriod);
677 }
678
679 // Run 7 (03.2018 - 04.2018)
680 if (fPeriod == 7) {
681 // SRC
682 if (fRun >= 2013 && fRun <= 3588) {
683 // for first time will be used correction from BM@N
684 NameFileLRcorrection = Form("TOF400_LRCorr_RUN%i_BMN.dat", fPeriod);
685 NameFileSlewingCorrection = Form("TOF400_SlewingCorr_RUN%i_BMN.root", fPeriod);
686 NameFileTimeShiftCorrection = Form("TOF400_TimeShiftCorr_RUN%i_SRC.dat", fPeriod);
687 }
688
689 // BM@N Ar beam
690 if (fRun >= 3589 && fRun <= 4707) {
691 NameFileLRcorrection = Form("TOF400_LRCorr_RUN%i_BMN.dat", fPeriod);
692 NameFileSlewingCorrection = Form("TOF400_SlewingCorr_RUN%i_BMN.root", fPeriod);
693 NameFileTimeShiftCorrection = Form("TOF400_TimeShiftCorr_RUN%i_BMN_Ar.dat", fPeriod);
694 }
695
696 // BM@N Kr beam
697 if (fRun >= 4747 && fRun <= 5185) {
698 NameFileLRcorrection = Form("TOF400_LRCorr_RUN%i_BMN.dat", fPeriod);
699 NameFileSlewingCorrection = Form("TOF400_SlewingCorr_RUN%i_BMN.root", fPeriod);
700 NameFileTimeShiftCorrection = Form("TOF400_TimeShiftCorr_RUN%i_BMN_Kr.dat", fPeriod);
701 }
702 }
703
704 // Run 8
705 if (fPeriod == 8) {
706
707 // SRC (2022)
708 if (fRun >= 968 && fRun <= 1546) {
709 NameFileLRcorrection = Form("TOF400_LRCorr_RUN%i_SRC.dat", fPeriod);
710 NameFileSlewingCorrection = Form("TOF400_SlewingCorr_RUN%i_SRC.root", fPeriod);
711 NameFileTimeShiftCorrection = Form("TOF400_TimeShiftCorr_RUN%i_SRC.dat", fPeriod);
712 }
713
714 // BM@N (2022-2023)
715 if (fRun >= 6587 && fRun <= 8427) {
716 if (fDetectorId == kTOF1) {
717 NameFileLRcorrection = Form("TOF400_LRCorr_RUN%i.dat", fPeriod);
718 NameFileSlewingCorrection = Form("TOF400_SlewingCorr_RUN%i_v2.root", fPeriod);
719 NameFileTimeShiftCorrection = Form("TOF400_TimeShiftCorr_RUN%i_v4.dat", fPeriod);
720 }
721 if (fDetectorId == kTOF701) {
722 NameFileLRcorrection = Form("TOF701_LRCorr_RUN%i.dat", fPeriod);
723 NameFileSlewingCorrection = Form("TOF701_SlewingCorr_RUN%i.root", fPeriod);
724 NameFileTimeShiftCorrection = Form("TOF701_TimeShiftCorr_RUN%i_v2.dat", fPeriod);
725 }
726 }
727 }
728 if (fPeriod == 9) {
729
730 if (fRun >= 9289) {
731 if (fDetectorId == kTOF1) {
732 NameFileLRcorrection = "";
733 NameFileSlewingCorrection = "";
734 NameFileTimeShiftCorrection = "";
735 FlagFileLRcorrection = false;
736 FlagFileSlewingCorrection = false;
737 FlagFileTimeShiftCorrection = false;
738 }
739 if (fDetectorId == kTOF701) {
740 NameFileLRcorrection = Form("TOF701_LRCorr_RUN%i.dat", 8);
741 NameFileSlewingCorrection = "";
742 NameFileTimeShiftCorrection = "";
743 FlagFileLRcorrection = true;
744 FlagFileSlewingCorrection = false;
745 FlagFileTimeShiftCorrection = false;
746 }
747 // temporary solution
748 return kTRUE;
749 }
750 }
751
752 // check all files exist
753 if (!IsFile(NameFileLRcorrection)) {
754 FlagFileLRcorrection = false;
755 if (fVerbose) {
756 cout << endl
757 << this->GetName() << "::Init(): File " << NameFileLRcorrection.Data()
758 << " for LR correction is not found" << endl;
759 cout << "Check /input folder for file" << endl;
760 }
761 }
762
763 if (!IsFile(NameFileSlewingCorrection)) {
764 FlagFileSlewingCorrection = false;
765 if (fVerbose) {
766 cout << endl
767 << this->GetName() << "::Init(): File " << NameFileSlewingCorrection.Data()
768 << " for Slewing correction is not found" << endl;
769 cout << "Check /input folder for file" << endl;
770 }
771 }
772
773 if (!IsFile(NameFileTimeShiftCorrection)) {
774 FlagFileTimeShiftCorrection = false;
775 if (fVerbose) {
776 cout << endl
777 << this->GetName() << "::Init(): File " << NameFileTimeShiftCorrection.Data()
778 << " for TimeShift correction is not found" << endl;
779 cout << "Check /input folder for file" << endl;
780 }
781 }
782
783 // cout << "NameFileLRcorrection = " << NameFileLRcorrection << endl;
784 // cout << "NameFileSlewingCorrection = " << NameFileSlewingCorrection << endl;
785 // cout << "NameFileTimeShiftCorrection = " << NameFileTimeShiftCorrection << endl;
786
787 // return "true" in case the run is physical and correction files are found.
788 if (FlagFileLRcorrection && FlagFileSlewingCorrection && FlagFileTimeShiftCorrection)
789 return kTRUE;
790
791 // return "false" in case the run is outside physical runs or correction files are not found.
792 return kFALSE;
793}
794//--------------------------------------------------------------------------------------------------------------------------------------
795
796Bool_t BmnTof1HitProducer::OutOfRange(Int_t iPlane = -1)
797{
798 if (iPlane < 0 || iPlane >= fNDetectors)
799 return kTRUE;
800 return kFALSE;
801}
802
803void BmnTof1HitProducer::OnlineWrite(const std::unique_ptr<TTree>& resultTree)
804{
805 if (!IsActive())
806 return;
807
808 resultTree->Branch(fHitsName.Data(), &aTofHits);
809 resultTree->Fill();
810}
friend F32vec4 sqrt(const F32vec4 &a)
Definition P4_F32vec4.h:34
int i
Definition P4_F32vec4.h:22
DetectorId
@ kTOF1
@ kTOF701
Int_t FindHitsNew(BmnTrigDigit *T0, TClonesArray *TofHit, int printnaw)
Bool_t SetCorrLR(TString NameFile)
Bool_t SetCorrTimeShift(TString NameFile)
void KillStrip(Int_t NumberOfStrip)
Bool_t SetDigitNew(BmnTof1Digit *TofDigit, Int_t ind=-1)
Bool_t SetGeo(BmnTof1GeoUtils *pGeoUtils)
Bool_t SetSpeedOfSignal(TString NameFile)
Bool_t SetCorrSlewing(TString NameFile)
Int_t GetVolumeUID() const
Int_t GetModule() const
virtual void Print(const Option_t *opt) const
Short_t GetPlane() const
const LStrip1 * FindStrip(Int_t UID)
void FindNeighborStrips701(Int_t verbose=0)
Int_t ParseTGeoManager701(bool useMCinput, bool forced=false, Int_t verbose=0)
Int_t ParseTGeoManager(bool useMCinput, bool forced=false, Int_t verbose=0)
void FindNeighborStrips(Int_t verbose=0)
void AddHit(Int_t detUID, const TVector3 &posHit, const TVector3 &posHitErr, Int_t pointIndex, Int_t trackIndex, Double_t time, Int_t Idd)
TClonesArray * aExpDigits
<— MC input
TClonesArray * aTofHits
<— The T0 time is stored in 'BmnTrigInfo.' branch in Run9
BmnTrigInfoDst * aExpTrigInfo
<— Exp input for run8 SRC
TClonesArray * aExpDigitsT0
<— Exp input
TClonesArray * aExpDigitsT0_2
<— Exp input
TClonesArray * aTofCont
—> output
TClonesArray * aMcTracks
<— MC input
void SetSeed(UInt_t seed=0)
virtual InitStatus Init()
virtual void Exec(Option_t *opt)
BmnTof1HitProducer(const char *name, DetectorId detId, Bool_t useMCdata=true, Int_t verbose=1, Bool_t DoTest=false)
virtual void OnlineWrite(const std::unique_ptr< TTree > &resultTree)
Write task resul to tree.
void SetTime(Double_t time)
Double_t GetAmp() const
Double_t GetTime() const
void SetAmp(Double_t amp)
Short_t GetMod() const
Float_t GetT0_time()
Float_t GetT0_amp()
Double_t MinDistanceToEdge701(const TVector3 *pos, Side_t &side) const
TVector3 center
Double_t MinDistanceToEdge(const TVector3 *pos, Side_t &side) const
Int_t neighboring[2]
bool GetIsKilled() const
STL namespace.