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