36 Bool_t useMCdata, Int_t verbose,
38: BmnTofHitProducerIdeal(name, useMCdata, verbose, test),
45 h1TestDistance(nullptr),
46 h2TestNeighborPair(nullptr),
47 h2TestStrips(nullptr),
48 fSignalVelosity(1.0 / 16.0)
52 fProtonTimeCorrectionFile = NULL;
53 fMainStripSelection = 0;
54 fSelectXYCalibration = 2;
57 fDiffTimeMaxSmall = 1.3f;
58 fDiffTimeMaxBig = 4.0f;
61 fTestFlnm =
"test.BmnTofHitProducer.root";
62 effTestEfficiencySingleHit =
new TEfficiency(
63 "TOF700_effSingleHit",
"Efficiency single hit;R, cm;Side", 10000,
65 fList.Add(effTestEfficiencySingleHit);
66 effTestEfficiencyDoubleHit =
new TEfficiency(
67 "TOF700_effDoubleHit",
"Efficiency double hit;R, cm;Side", 10000,
69 fList.Add(effTestEfficiencyDoubleHit);
71 new TH1D(
"TOF700_TestDistance",
72 "Distance between strips;M, cm;Side", 1000, 0., 100.);
73 fList.Add(h1TestDistance);
79 new TH2D(
"TOF700_TestNeighborPair",
80 "Neighbor strip pairs test;stripID1;stripID2", 100, -0.5,
81 49.5, 100, -0.5, 49.5);
82 fList.Add(h2TestNeighborPair);
84 new TH2D(
"TOF700_TestXYSmeared",
85 "Smeared XY (single hit) test;#DeltaX, cm;#DeltaY, cm",
86 1000, -1., 1., 1000, -2., 2.);
87 fList.Add(h2TestXYSmeared);
88 h2TestXYSmeared2 =
new TH2D(
"TOF700_TestXYSmeared2",
89 "Smeared XY (single hit) test;X, cm;Y, cm",
90 1000, -180., 180., 1000, -180., 180.);
91 fList.Add(h2TestXYSmeared2);
92 h2TestXYSmearedDouble =
93 new TH2D(
"TOF700_TestXYSmearedDouble",
94 "Smeared XY (double hit) test;#DeltaX, cm;#DeltaY, cm",
95 1000, -2., 2., 1000, -2., 2.);
96 fList.Add(h2TestXYSmearedDouble);
97 h2TestXYSmearedDouble2 =
98 new TH2D(
"TOF700_TestXYSmearedDouble2",
99 "Smeared XY (double hit) test;X, cm;Y, cm", 1000, -180.,
100 180., 1000, -180., 180.);
101 fList.Add(h2TestXYSmearedDouble2);
103 h2TestEtaPhi =
new TH2D(
"TOF700_TestEtaPhi",
";#eta;#phi, degree", 1000,
104 -5., +5., 1000, -181., 181.);
105 fList.Add(h2TestEtaPhi);
106 h2TestRZ =
new TH2D(
"TOF700_TestRZ",
";X, cm;Y, cm", 1000, -300., 300.,
109 h2TdetIdStripId =
new TH2D(
"TOF700_TdetIdStripId",
";stripId;detId",
110 100, -0.5, 99.5, 26, -0.5, 25.5);
111 fList.Add(h2TdetIdStripId);
112 h1TestMass =
new TH1D(
"TOF700_TestMass",
"Mass", 500, 0., 100.);
113 fList.Add(h1TestMass);
114 h1TestMassLong =
new TH1D(
"TOF700_TestMassLong",
"Mass - long tracks",
116 fList.Add(h1TestMassLong);
117 h1TestOccupancyTimeShift =
118 new TH1D(
"TOF700_TestOccupancyTimeShift",
"Occupancy Time Shift",
120 fList.Add(h1TestOccupancyTimeShift);
121 h1TestOccupancyPositionShift =
122 new TH1D(
"TOF700_TestOccupancyPositionShift",
123 "Occupancy Position Shift", 200, -10., 10.);
124 fList.Add(h1TestOccupancyPositionShift);
134 LOG(debug) <<
"Begin [BmnTof700HitProducer::Init].";
136 pRandom =
new TRandom2;
137 pGeoUtils =
new BmnTofGeoUtils(fUseMCData);
138 pGeoUtils->SetVerbosity(fVerbose);
140 if (fOnlyPrimary && fVerbose > 1)
141 LOG(info) <<
" Only primary particles are processed!!! ";
144 aMcPoints = (TClonesArray *)FairRootManager::Instance()->GetObject(
147 cout <<
"BmnTof700HitProducer::Init(): branch TOFPoint not found! "
148 "Task will be deactivated"
154 (TClonesArray *)FairRootManager::Instance()->GetObject(
"MCTrack");
156 cout <<
"BmnTof700HitProducer::Init(): branch MCTrack not found! "
157 "Task will be deactivated"
163 if (strstr(fgeomFile,
"_run8"))
165 "bmn_run6666_raw.root", 0, 0,
169 "bmn_run3332_raw.root", 0, 0,
173 (TClonesArray *)FairRootManager::Instance()->GetObject(
"TOF700");
175 cout <<
"BmnTof700HitProducer::Init(): branch TOF700 not found! "
176 "Task will be deactivated"
181 if (fMCTimeFile == NULL) {
182 cout <<
"BmnTof700HitProducer::Init(): MC times file not defined! "
192 for (
int s = 0; s < 32; s++) {
196 if (fProtonTimeCorrectionFile == NULL) {
197 cout <<
"BmnTof700HitProducer::Init(): Proton-based time "
198 "corrections file not defined! Don't use corrections!"
201 TProfile2D *itcalibr = 0;
202 TProfile *itcalibrc = 0;
203 float idchambers[59] = {
204 27.1, 28.1, 3.1, 1.1, 29.1, 4.1, 33.1, 30.1, 5.1,
205 19.3, 31.1, 6.1, 2.1, 32.1, 15.2, 16.2, 17.2, 18.2,
206 19.2, 20.2, 7.1, 115.2, 113.1, 117.1, 35.1, 9.1, 37.1,
207 11.1, 39.1, 13.1, 34.1, 8.1, 36.1, 10.1, 38.1, 12.1,
208 21.2, 23.2, 25.2, 22.2, 24.2, 26.2, 107.2, 108.2, 109.2,
209 110.2, 111.2, 112.2, 114.1, 116.2, 118.1, 14.1, 40.1, 119.2,
210 120.2, 121.2, 122.2, 123.2, 124.2};
212 TString dir = getenv(
"VMCWORKDIR");
213 sprintf(fname,
"%s/input/%s", dir.Data(),
214 fProtonTimeCorrectionFile);
215 TFile *fc =
new TFile(fname,
"READ",
216 "Proton mass based calibration of BmnTOF700");
217 if (fc->IsZombie()) {
218 cout <<
"BmnTof700HitProducer::Init(): Error open Proton-based "
219 "time corrections file "
224 itcalibr = (TProfile2D *)fc->Get(
"tcalibr");
225 itcalibrc = (TProfile *)fc->Get(
"tcalibrc");
227 itcalibr = (TProfile2D *)fc->Get(
"tcalibr;1");
228 itcalibrc = (TProfile *)fc->Get(
"tcalibrc;1");
231 tofcalc[c] = itcalibrc->GetBinContent(c + 1);
235 "\n ******************* Time offsets for whole chamber "
236 "**********************\n");
238 printf(
"%d %f\n", c, tofcalc[c]);
244 "\n ******************* Time offsets for each strip "
245 "**************************\n");
248 printf(
"\n Chamber %d %.1f\n", c, idchambers[c]);
250 if (idchambers[c] >= 100.f) smax = 16;
251 for (
int s = 0; s < smax; s++) {
252 tofcals[c][s] = itcalibr->GetBinContent(c + 1, s + 1);
254 printf(
" strip %d %f\n", s, tofcals[c][s]);
259 "**************************************************"
260 "***********************\n");
268 aTofHits =
new TClonesArray(
"BmnTofHit");
269 FairRootManager::Instance()->Register(
"BmnTof700Hit",
"TOF", aTofHits,
273 pGeoUtils->ParseTGeoManager(fUseMCData, h2TestStrips,
true);
275 pGeoUtils->FindNeighborStrips(h1TestDistance, h2TestNeighborPair, fDoTest);
278 <<
"Initialization [BmnTof700HitProducer::Init] finished succesfully.";
327 if (!IsActive())
return;
329 float idchambers[59] = {
330 27.1, 28.1, 3.1, 1.1, 29.1, 4.1, 33.1, 30.1, 5.1, 19.3,
331 31.1, 6.1, 2.1, 32.1, 15.2, 16.2, 17.2, 18.2, 19.2, 20.2,
332 7.1, 115.2, 113.1, 117.1, 35.1, 9.1, 37.1, 11.1, 39.1, 13.1,
333 34.1, 8.1, 36.1, 10.1, 38.1, 12.1, 21.2, 23.2, 25.2, 22.2,
334 24.2, 26.2, 107.2, 108.2, 109.2, 110.2, 111.2, 112.2, 114.1, 116.2,
335 118.1, 14.1, 40.1, 119.2, 120.2, 121.2, 122.2, 123.2, 124.2};
339 <<
"======================== TOF700 exec started "
340 "===================="
342 static const TVector3 XYZ_err(fErrX, fErrY, 0.);
347 TVector3 pos, XYZ_smeared, mom;
348 int nSingleHits = 0, nDoubleHits = 0;
351 for (Int_t pointIndex = 0, nTofPoint = aMcPoints->GetEntriesFast();
352 pointIndex < nTofPoint; pointIndex++)
354 BmnTOFPoint *pPoint =
355 (BmnTOFPoint *)aMcPoints->UncheckedAt(pointIndex);
357 if (fVerbose > 2) pPoint->Print(
"");
359 trackID = pPoint->GetTrackID();
360 UID = pPoint->GetDetectorID();
361 if (UID == 1)
continue;
364 time = pPoint->GetTime();
366 time = pRandom->Gaus(pPoint->GetTime(),
368 Double_t length = pRandom->Gaus(pPoint->GetLength(), 1.);
369 pPoint->Position(pos);
370 pPoint->Momentum(mom);
371 Double_t p = mom.Mag();
372 p = p * (1. + pRandom->Gaus(0.04 * p));
373 Double_t cvel = 29.97925;
374 Double_t ct = cvel * time;
375 Double_t ctl = ct / length;
376 Double_t sqr = TMath::Sqrt(ctl * ctl - 1.);
377 Double_t mass = p * sqr;
380 if (pPoint->GetEnergyLoss() > elcut) h1TestMass->Fill(mass);
382 if (pPoint->GetEnergyLoss() > elcut && length > 600.)
383 h1TestMassLong->Fill(mass);
386 const LStrip *pStrip = pGeoUtils->FindStrip(UID);
387 if (pStrip == NULL)
continue;
394 XYZ_smeared.SetXYZ(pos.X(), pStrip->center.Y(),
397 XYZ_smeared.SetXYZ(pRandom->Gaus(pos.X(), fErrX),
398 pStrip->center.Y(), pStrip->center.Z());
401 Double_t distance = pStrip->MinDistanceToEdge(&pos, side);
404 if ((passed = HitExist(distance)) ==
true)
406 AddHit(UID, XYZ_smeared, XYZ_err, pointIndex, trackID, time);
410 Int_t strip = BmnTOFPoint::GetStrip(UID);
411 Int_t chamber = BmnTOFPoint::GetChamber(UID);
412 h2TestXYSmeared->Fill(pos.X() - XYZ_smeared.X(),
413 pos.Y() - XYZ_smeared.Y());
414 h2TestXYSmeared2->Fill(XYZ_smeared.X(), XYZ_smeared.Y());
415 h2TestEtaPhi->Fill(pos.Eta(),
416 pos.Phi() * TMath::RadToDeg());
417 h2TestRZ->Fill(pos.X(), pos.Y());
418 h2TdetIdStripId->Fill(strip, chamber);
422 if (fDoTest) effTestEfficiencySingleHit->Fill(passed, distance);
428 Int_t CrossUID = (side == LStrip::kUpper)
429 ? pStrip->neighboring[LStrip::kUpper]
430 : pStrip->neighboring[LStrip::kLower];
432 if (LStrip::kInvalid == CrossUID)
435 pStrip = pGeoUtils->FindStrip(CrossUID);
436 XYZ_smeared.SetXYZ(pRandom->Gaus(pos.X(), fErrX),
437 pStrip->center.Y(), pStrip->center.Z());
439 AddHit(CrossUID, XYZ_smeared, XYZ_err, pointIndex, trackID,
444 h2TestXYSmearedDouble->Fill((pos - XYZ_smeared).Mag(),
445 pos.Z() - XYZ_smeared.Z());
446 h2TestXYSmearedDouble2->Fill(XYZ_smeared.X(),
451 if (fDoTest) effTestEfficiencyDoubleHit->Fill(passed, distance);
460 for (Int_t digitIndex = 0,
461 nTof2Digits = aExpDigits->GetEntriesFast();
462 digitIndex < nTof2Digits; digitIndex++)
471 tof[chamber][strip] = pDigit->
GetTime();
472 lrdiff[chamber][strip] = pDigit->GetDiff();
478 if (fMCTimeFile && fMCTime[
i] == 0.f)
continue;
479 Double_t DiffTimeMax = fDiffTimeMaxSmall;
480 if (idchambers[
i] >= 100.f) DiffTimeMax = fDiffTimeMaxBig;
482 int clstart = -1, cstr = -1;
483 float samps = 0., timemin = 1000000000., amplmax = 0.;
485 if (idchambers[
i] >= 100.f) nstr = 16;
486 for (
int j = 0; j < nstr; j++) {
487 if (tofWidths[
i][j] > 0.) {
491 amplmax = tofWidths[
i][j];
494 if (fMainStripSelection == 0 &&
495 tof[
i][j] < timemin) {
499 if (fMainStripSelection != 0 &&
500 tofWidths[
i][j] > amplmax) {
501 amplmax = tofWidths[
i][j];
505 samps += tofWidths[
i][j];
506 if (j == (nstr - 1)) {
507 if (tof[
i][cstr] > fTimeMin &&
508 tof[
i][cstr] < fTimeMax &&
509 TMath::Abs(lrdiff[
i][cstr]) < DiffTimeMax) {
515 UID = ((
i + 1) << 8) | (cstr + 1);
516 Float_t xcl, ycl, zcl;
517 if (fSelectXYCalibration == 0)
520 else if (fSelectXYCalibration == 1)
522 lrdiff[
i][cstr], &xcl,
524 else if (fSelectXYCalibration == 2)
526 lrdiff[
i][cstr], &xcl,
528 else if (fSelectXYCalibration == 3)
530 lrdiff[
i][cstr], &xcl,
534 lrdiff[
i][cstr], &xcl,
541 crosspoint.SetXYZ(xcl, ycl, zcl);
543 AddHit(UID, crosspoint, XYZ_err, -1, -1,
544 tof[
i][cstr] + fMCTime[
i] +
547 AddHit(UID, crosspoint, XYZ_err, -1, -1,
548 tof[
i][cstr] + fMCTime[
i] +
553 h2TestXYSmeared2->Fill(crosspoint.X(),
558 h2TestRZ->Fill(xc, yc);
563 timemin = 1000000000.;
566 }
else if (clstart >= 0) {
567 if (tof[
i][cstr] > fTimeMin &&
568 tof[
i][cstr] < fTimeMax &&
569 TMath::Abs(lrdiff[
i][cstr]) < DiffTimeMax) {
575 UID = ((
i + 1) << 8) | (cstr + 1);
576 Float_t xcl = 0., ycl = 0., zcl = 0.;
577 if (fSelectXYCalibration == 0)
580 else if (fSelectXYCalibration == 1)
583 else if (fSelectXYCalibration == 2)
586 else if (fSelectXYCalibration == 3)
597 crosspoint.SetXYZ(xcl, ycl, zcl);
599 AddHit(UID, crosspoint, XYZ_err, -1, -1,
600 tof[
i][cstr] + fMCTime[
i] +
604 UID, crosspoint, XYZ_err, -1, -1,
605 tof[
i][cstr] + fMCTime[
i] + tofcalc[
i]);
609 h2TestXYSmeared2->Fill(crosspoint.X(),
614 h2TestRZ->Fill(xc, yc);
619 timemin = 1000000000.;
626 for (Int_t digitIndex = 0,
627 nTof2Digits = aExpDigits->GetEntriesFast();
628 digitIndex < nTof2Digits; digitIndex++)
636 if (fMCTimeFile && fMCTime[chamber] == 0.f)
continue;
641 Float_t dtime = pDigit->
GetTime();
642 Float_t dlrdiff = pDigit->GetDiff();
643 if (dtime < fTimeMin || dtime > fTimeMax)
continue;
644 Double_t DiffTimeMax = fDiffTimeMaxSmall;
645 if (idchambers[chamber] >= 100.f) DiffTimeMax = fDiffTimeMaxBig;
646 if (TMath::Abs(dlrdiff) > DiffTimeMax)
continue;
647 const LStrip *pStrip = pGeoUtils->FindStrip(UID);
648 Float_t xcl = 0., ycl = 0., zcl = 0.;
649 if (fSelectXYCalibration == 0)
650 fTOF2->
get_hit_xyz(chamber, strip, dlrdiff, &xcl, &ycl,
652 else if (fSelectXYCalibration == 1)
653 fTOF2->
get_hit_xyzp(chamber, strip, dlrdiff, &xcl, &ycl,
655 else if (fSelectXYCalibration == 2)
658 else if (fSelectXYCalibration == 3)
665 fTOF2->
get_hit_xyz(chamber, strip, dlrdiff, &xcl, &ycl,
669 crosspoint.SetXYZ(xcl, ycl, zcl);
672 UID, crosspoint, XYZ_err, -1, -1,
673 dtime + fMCTime[chamber] + tofcals[chamber][strip]);
675 AddHit(UID, crosspoint, XYZ_err, -1, -1,
676 dtime + fMCTime[chamber] + tofcalc[chamber]);
680 h2TestXYSmeared2->Fill(crosspoint.X(), crosspoint.Y());
681 TVector3 stripCenter(pStrip->center);
682 h2TestRZ->Fill(stripCenter.X(), stripCenter.Y());
691 MergeHitsOnStripNew();
697 int nFinally = CompressHits();
700 workTime += sw.RealTime();
703 cout <<
"BmnTof700HitProducer: single hits= " << nSingleHits
704 <<
", double hits= " << nDoubleHits <<
", final hits= " << nFinally
707 cout <<
"BmnTof700HitProducer: " << nFinally <<
" hits" << endl;
709 cout <<
"======================== TOF700 exec finished "
710 "==================="
990 float idchambers[59] = {
991 27.1, 28.1, 3.1, 1.1, 29.1, 4.1, 33.1, 30.1, 5.1, 19.3,
992 31.1, 6.1, 2.1, 32.1, 15.2, 16.2, 17.2, 18.2, 19.2, 20.2,
993 7.1, 115.2, 113.1, 117.1, 35.1, 9.1, 37.1, 11.1, 39.1, 13.1,
994 34.1, 8.1, 36.1, 10.1, 38.1, 12.1, 21.2, 23.2, 25.2, 22.2,
995 24.2, 26.2, 107.2, 108.2, 109.2, 110.2, 111.2, 112.2, 114.1, 116.2,
996 118.1, 14.1, 40.1, 119.2, 120.2, 121.2, 122.2, 123.2, 124.2};
997 bool notused[59] = {
true};
998 int order[59] = {-1};
999 int c = 0, cmin = -1, c0 = 0;
1000 float idmin = 200.f;
1001 for (c0 = 0; c0 < 59; c0++) {
1005 for (c0 = 0; c0 < 59; c0++) {
1008 for (c = 0; c < 59; c++) {
1009 if (notused[c] && (idchambers[c] < idmin)) {
1010 idmin = idchambers[c];
1017 notused[cmin] =
false;
1023 float time = 0.f, timesigma = 0.f;
1024 if (MCTimeFile == NULL) {
1025 printf(
"TOF700 MC time-of-flight file name not defined!\n");
1028 if (strlen(MCTimeFile) == 0) {
1029 printf(
"TOF700 MC time-of-flight file name not defined!\n");
1032 TString dir = getenv(
"VMCWORKDIR");
1033 sprintf(fname,
"%s/geometry/%s", dir.Data(), MCTimeFile);
1034 ft = fopen(fname,
"r");
1036 printf(
"TOF700 MC time-of-flight file %s open error!\n", fname);
1041 int cexp = 0, ic = -1;
1042 while (fscanf(ft,
"%d %f %f\n", &ic, &time, ×igma) == 3) {
1043 if (ic > 0 && ic <= 59) {
1044 cexp = order[ic - 1];
1045 fMCTime[cexp] = time;
1046 fMCTimeSigma[cexp] = timesigma;
1049 "Chamber %.1f (MC %d, EXP %d) average time-of-flight %f "
1051 idchambers[cexp], ic, cexp, time, timesigma);