115 LOG(debug) <<
"Begin [BmnTof700HitProducer::Init].";
118 pGeoUtils =
new BmnTofGeoUtils(fUseMCData);
121 if (fOnlyPrimary && fVerbose > 1)
122 LOG(info) <<
" Only primary particles are processed!!! ";
125 aMcPoints = (
TClonesArray*)FairRootManager::Instance()->GetObject(
"TOF700Point");
127 cout <<
"BmnTof700HitProducer::Init(): branch TOFPoint not found! "
128 "Task will be deactivated"
133 aMcTracks = (
TClonesArray*)FairRootManager::Instance()->GetObject(
"MCTrack");
135 cout <<
"BmnTof700HitProducer::Init(): branch MCTrack not found! "
136 "Task will be deactivated"
147 aExpDigits = (
TClonesArray*)FairRootManager::Instance()->GetObject(
"TOF700");
149 cout <<
"BmnTof700HitProducer::Init(): branch TOF700 not found! "
150 "Task will be deactivated"
156 cout <<
"BmnTof700HitProducer::Init(): MC times file not defined! "
167 for (
int s = 0; s < 32; s++) {
172 cout <<
"BmnTof700HitProducer::Init(): Proton-based time "
173 "corrections file not defined! Don't use corrections!"
178 float idchambers[59] = {27.1, 28.1, 3.1, 1.1, 29.1, 4.1, 33.1, 30.1, 5.1, 19.3, 31.1, 6.1,
179 2.1, 32.1, 15.2, 16.2, 17.2, 18.2, 19.2, 20.2, 7.1, 115.2, 113.1, 117.1,
180 35.1, 9.1, 37.1, 11.1, 39.1, 13.1, 34.1, 8.1, 36.1, 10.1, 38.1, 12.1,
181 21.2, 23.2, 25.2, 22.2, 24.2, 26.2, 107.2, 108.2, 109.2, 110.2, 111.2, 112.2,
182 114.1, 116.2, 118.1, 14.1, 40.1, 119.2, 120.2, 121.2, 122.2, 123.2, 124.2};
184 TString dir = getenv(
"VMCWORKDIR");
186 TFile* fc =
new TFile(fname,
"READ",
"Proton mass based calibration of BmnTOF700");
188 cout <<
"BmnTof700HitProducer::Init(): Error open Proton-based "
189 "time corrections file "
201 tofcalc[c] = itcalibrc->GetBinContent(c + 1);
204 printf(
"\n ******************* Time offsets for whole chamber "
205 "**********************\n");
207 printf(
"%d %f\n", c,
tofcalc[c]);
212 printf(
"\n ******************* Time offsets for each strip "
213 "**************************\n");
216 printf(
"\n Chamber %d %.1f\n", c, idchambers[c]);
218 if (idchambers[c] >= 100.f)
220 for (
int s = 0; s < smax; s++) {
221 tofcals[c][s] = itcalibr->GetBinContent(c + 1, s + 1);
223 printf(
" strip %d %f\n", s,
tofcals[c][s]);
227 "**************************************************"
228 "***********************\n");
237 FairRootManager::Instance()->Register(
"BmnTof700Hit",
"TOF", aTofHits,
kTRUE);
244 LOG(debug) <<
"Initialization [BmnTof700HitProducer::Init] finished succesfully.";
298 float idchambers[59] = {27.1, 28.1, 3.1, 1.1, 29.1, 4.1, 33.1, 30.1, 5.1, 19.3, 31.1, 6.1,
299 2.1, 32.1, 15.2, 16.2, 17.2, 18.2, 19.2, 20.2, 7.1, 115.2, 113.1, 117.1,
300 35.1, 9.1, 37.1, 11.1, 39.1, 13.1, 34.1, 8.1, 36.1, 10.1, 38.1, 12.1,
301 21.2, 23.2, 25.2, 22.2, 24.2, 26.2, 107.2, 108.2, 109.2, 110.2, 111.2, 112.2,
302 114.1, 116.2, 118.1, 14.1, 40.1, 119.2, 120.2, 121.2, 122.2, 123.2, 124.2};
306 <<
"======================== TOF700 exec started "
307 "===================="
315 int nSingleHits = 0, nDoubleHits = 0;
318 for (
Int_t pointIndex = 0, nTofPoint = aMcPoints->GetEntriesFast(); pointIndex < nTofPoint;
321 BmnTOFPoint* pPoint = (BmnTOFPoint*)aMcPoints->UncheckedAt(pointIndex);
326 trackID = pPoint->GetTrackID();
327 UID = pPoint->GetDetectorID();
332 time = pPoint->GetTime();
334 time =
pRandom->Gaus(pPoint->GetTime(),
337 pPoint->Position(pos);
338 pPoint->Momentum(mom);
340 p = p * (1. +
pRandom->Gaus(0.04 * p));
348 if (pPoint->GetEnergyLoss() > elcut)
351 if (pPoint->GetEnergyLoss() > elcut && length > 600.)
355 const LStrip* pStrip =
pGeoUtils->FindStrip(UID);
364 XYZ_smeared.
SetXYZ(pos.
X(), pStrip->center.Y(), pStrip->center.Z());
369 Double_t distance = pStrip->MinDistanceToEdge(&pos, side);
372 if ((passed =
HitExist(distance)) ==
true)
374 AddHit(UID, XYZ_smeared, XYZ_err, pointIndex, trackID, time);
378 Int_t strip = BmnTOFPoint::GetStrip(UID);
379 Int_t chamber = BmnTOFPoint::GetChamber(UID);
395 Int_t CrossUID = (side == LStrip::kUpper) ? pStrip->neighboring[LStrip::kUpper]
396 : pStrip->neighboring[LStrip::kLower];
398 if (LStrip::kInvalid == CrossUID)
404 AddHit(CrossUID, XYZ_smeared, XYZ_err, pointIndex, trackID, time);
423 for (
Int_t digitIndex = 0,
424 nTof2Digits = aExpDigits->GetEntriesFast();
425 digitIndex < nTof2Digits; digitIndex++)
432 tof[chamber][strip] = pDigit->
GetTime();
433 lrdiff[chamber][strip] = pDigit->GetDiff();
442 if (idchambers[
i] >= 100.f)
445 int clstart = -1, cstr = -1;
446 float samps = 0., timemin = 1000000000., amplmax = 0.;
448 if (idchambers[
i] >= 100.f)
450 for (
int j = 0; j < nstr; j++) {
451 if (tofWidths[
i][j] > 0.) {
455 amplmax = tofWidths[
i][j];
463 amplmax = tofWidths[
i][j];
467 samps += tofWidths[
i][j];
468 if (j == (nstr - 1)) {
477 UID = ((
i + 1) << 8) | (cstr + 1);
480 fTOF2->get_hit_xyz(
i, cstr, lrdiff[
i][cstr], &xcl, &ycl, &zcl);
482 fTOF2->get_hit_xyzp(
i, cstr, lrdiff[
i][cstr], &xcl, &ycl, &zcl);
484 fTOF2->get_hit_xyzng(
i, cstr, lrdiff[
i][cstr], &xcl, &ycl, &zcl);
486 fTOF2->get_hit_xyznl(
i, cstr, lrdiff[
i][cstr], &xcl, &ycl, &zcl);
488 fTOF2->get_hit_xyzng(
i, cstr, lrdiff[
i][cstr], &xcl, &ycl, &zcl);
490 fTOF2->get_hit_xyz(
i, cstr, lrdiff[
i][cstr], &xcl, &ycl, &zcl);
493 crosspoint.
SetXYZ(xcl, ycl, zcl);
495 AddHit(UID, crosspoint, XYZ_err, -1, -1,
498 AddHit(UID, crosspoint, XYZ_err, -1, -1,
505 fTOF2->get_strip_xyz(
i, cstr, &xc, &yc, &zc);
511 timemin = 1000000000.;
514 }
else if (clstart >= 0) {
523 UID = ((
i + 1) << 8) | (cstr + 1);
524 Float_t xcl = 0., ycl = 0., zcl = 0.;
526 fTOF2->get_hit_xyz(
i, cstr, lrdiff[
i][cstr], &xcl, &ycl, &zcl);
528 fTOF2->get_hit_xyzp(
i, cstr, lrdiff[
i][cstr], &xcl, &ycl, &zcl);
530 fTOF2->get_hit_xyzng(
i, cstr, lrdiff[
i][cstr], &xcl, &ycl, &zcl);
532 fTOF2->get_hit_xyznl(
i, cstr, lrdiff[
i][cstr], &xcl, &ycl, &zcl);
534 fTOF2->get_hit_xyzng(
i, cstr, lrdiff[
i][cstr], &xcl, &ycl, &zcl);
536 fTOF2->get_hit_xyz(
i, cstr, lrdiff[
i][cstr], &xcl, &ycl, &zcl);
539 crosspoint.
SetXYZ(xcl, ycl, zcl);
541 AddHit(UID, crosspoint, XYZ_err, -1, -1,
544 AddHit(UID, crosspoint, XYZ_err, -1, -1, tof[
i][cstr] +
fMCTime[
i] +
tofcalc[
i]);
550 fTOF2->get_strip_xyz(
i, cstr, &xc, &yc, &zc);
556 timemin = 1000000000.;
563 for (
Int_t digitIndex = 0,
564 nTof2Digits = aExpDigits->GetEntriesFast();
565 digitIndex < nTof2Digits; digitIndex++)
578 Float_t dlrdiff = pDigit->GetDiff();
579 if (dtime < fTimeMin || dtime >
fTimeMax)
582 if (idchambers[chamber] >= 100.f)
586 const LStrip* pStrip =
pGeoUtils->FindStrip(UID);
587 Float_t xcl = 0., ycl = 0., zcl = 0.;
589 fTOF2->get_hit_xyz(chamber, strip, dlrdiff, &xcl, &ycl, &zcl);
591 fTOF2->get_hit_xyzp(chamber, strip, dlrdiff, &xcl, &ycl, &zcl);
593 fTOF2->get_hit_xyzng(chamber, strip, dlrdiff, &xcl, &ycl, &zcl);
595 fTOF2->get_hit_xyznl(chamber, strip, dlrdiff, &xcl, &ycl, &zcl);
597 fTOF2->get_hit_xyzng(chamber, strip, dlrdiff, &xcl, &ycl, &zcl);
599 fTOF2->get_hit_xyz(chamber, strip, dlrdiff, &xcl, &ycl, &zcl);
602 crosspoint.
SetXYZ(xcl, ycl, zcl);
604 AddHit(UID, crosspoint, XYZ_err, -1, -1, dtime +
fMCTime[chamber] +
tofcals[chamber][strip]);
606 AddHit(UID, crosspoint, XYZ_err, -1, -1, dtime +
fMCTime[chamber] +
tofcalc[chamber]);
611 TVector3 stripCenter(pStrip->center);
612 h2TestRZ->Fill(stripCenter.
X(), stripCenter.
Y());
626 int nFinally = CompressHits();
632 cout <<
"BmnTof700HitProducer: single hits= " << nSingleHits <<
", double hits= " << nDoubleHits
633 <<
", final hits= " << nFinally << endl;
635 cout <<
"BmnTof700HitProducer: " << nFinally <<
" hits" << endl;
637 cout <<
"======================== TOF700 exec finished "
638 "==================="
658 typedef map<Int_t, BmnTofHit*> hitsMapType;
660 hitsMapType::iterator it;
662 Double_t tarrive[70000][2] = {{0.}};
663 Double_t tarrive0[70000][2] = {{0.}};
668 typedef multiset<Int_t> msUIDsType;
672 printf(
" *********** New event ****************\n");
675 for (
Int_t hitIndex = 0, nHits = aTofHits->GetEntriesFast(); hitIndex < nHits; hitIndex++)
678 assert(
nullptr != pHit);
680 Int_t UID = pHit->GetDetectorID();
687 const LStrip* pStrip =
pGeoUtils->FindStrip(UID);
693 Double_t distance1 = pStrip->DistanceFromPointToLineSegment(&pos, pStrip->A, pStrip->D);
694 Double_t distance2 = pStrip->DistanceFromPointToLineSegment(&pos, pStrip->B, pStrip->C);
698 if (tarr[1] < tarrmin)
700 it = fHits.find(UID);
702 if (it != fHits.end())
706 printf(
"Chamber %2d strip %2d before %f %f\n", UID >> 8, UID & 0xFF, tarrive[UID][0], tarrive[UID][1]);
708 if (tarrmin < tarrivemin[UID]) {
709 tarrivemin[UID] = tarrmin;
711 slowHit = it->second;
712 tarrive0[UID][0] = tarr[0];
713 tarrive0[UID][1] = tarr[1];
715 fastHit = it->second;
718 if (tarr[0] < tarrive[UID][0])
720 tarrive[UID][0] = tarr[0];
723 if (tarr[1] < tarrive[UID][1])
725 tarrive[UID][1] = tarr[1];
729 printf(
" after %f %f\n", tarrive[UID][0], tarrive[UID][1]);
732 h2TestMergedTimes->Fill(fastHit->GetTimeStamp(), slowHit->GetTimeStamp());
734 fastHit->AddLinks(slowHit->GetLinks());
735 aTofHits->Remove(slowHit);
736 it->second = fastHit;
739 fHits.insert(make_pair(UID, pHit));
740 tarrive[UID][0] = tarr[0];
741 tarrive[UID][1] = tarr[1];
742 tarrive0[UID][0] = tarr[0];
743 tarrive0[UID][1] = tarr[1];
744 if (tarr[0] < tarr[1])
745 tarrivemin[UID] = tarr[0];
747 tarrivemin[UID] = tarr[1];
749 printf(
"Chamber %2d strip %2d start %f %f\n", UID >> 8, UID & 0xFF, tarrive[UID][0], tarrive[UID][1]);
755 printf(
" -------------------- Results ------------------\n");
757 for (
Int_t hitIndex = 0, nHits = aTofHits->GetEntriesFast(); hitIndex < nHits; hitIndex++)
765 Int_t UID = pHit->GetDetectorID();
771 const LStrip* pStrip =
pGeoUtils->FindStrip(UID);
778 Double_t lstrip = (pStrip->B - pStrip->A).X();
781 Double_t xh = pStrip->center.X() + dxh;
784 Double_t told = pHit->GetTimeStamp();
785 if (fDoTest && !(pHit->
GetFlag()))
787 if (fDoTest && !(pHit->
GetFlag()))
790 printf(
"Chamber %2d strip %2d result %f %f lstrip %f shift %f\n", UID >> 8, UID & 0xFF, tarrive[UID][0],
792 printf(
" time: old %f new %f\n", told, ta);
793 printf(
" tim0: old %f old %f diff %f\n", tarrive0[UID][0], tarrive0[UID][1],
794 tarrive0[UID][0] - tarrive0[UID][1]);
795 printf(
" tim0: new %f new %f diff %f\n", tarrive[UID][0], tarrive[UID][1],
796 tarrive[UID][0] - tarrive[UID][1]);
797 printf(
" posx: old %f new %f\n", pos.
X(), xh);
798 printf(
" posy: old %f new %f\n", pos.
Y(), pos.
Y());
799 printf(
" posz: old %f new %f\n", pos.
Z(), pos.
Z());
803 pHit->SetPosition(pos);
804 pHit->SetTimeStamp(ta);
809 for (msUIDsType::const_iterator it1 = UIDs.begin(), itEnd = UIDs.end(); it1 != itEnd;
810 it1 = UIDs.upper_bound(*it1))
811 h1TestOccup->Fill(UIDs.count(*it1));
871 Int_t CorrRPC_It1, CorrT0_It1;
872 Double_t CorrPlane7Coeff_It1[5][4] = {{12.24, -3.919, 0.2624, -0.005153},
873 {-122.9, 14.84, -0.6158, 0.008724},
874 {-12.34, 0.482, 0., 0.},
875 {-12.28, 0.479, 0., 0.},
876 {-13.14, 0.5034, 0., 0.}};
878 {-5.486, 1.087, -0.07936, 0.00208}, {10.77, -2.635, 0.1984, -0.004631}, {0., 0., 0., 0.}};
886 else if (ampRPC >= 20.46 && ampRPC < 27.25)
888 else if (ampRPC >= 27.25 && ampRPC < 34.81)
890 else if (ampRPC >= 34.81 && ampRPC < 37.11)
892 else if (ampRPC >= 37.11)
895 - (CorrPlane7Coeff_It1[CorrRPC_It1][0] + CorrPlane7Coeff_It1[CorrRPC_It1][1] * ampRPC
896 + CorrPlane7Coeff_It1[CorrRPC_It1][2] * ampRPC * ampRPC
897 + CorrPlane7Coeff_It1[CorrRPC_It1][3] * ampRPC * ampRPC * ampRPC);
898 if (ampT0 >= 6.15 && ampT0 < 12.3)
900 else if (ampT0 >= 12.3 && ampT0 < 17.14)
905 - (CorrT0Coeff_It1[CorrT0_It1][0] + CorrT0Coeff_It1[CorrT0_It1][1] * ampT0
906 + CorrT0Coeff_It1[CorrT0_It1][2] * ampT0 * ampT0 + CorrT0Coeff_It1[CorrT0_It1][3] * ampT0 * ampT0 * ampT0);
914 float idchambers[59] = {27.1, 28.1, 3.1, 1.1, 29.1, 4.1, 33.1, 30.1, 5.1, 19.3, 31.1, 6.1,
915 2.1, 32.1, 15.2, 16.2, 17.2, 18.2, 19.2, 20.2, 7.1, 115.2, 113.1, 117.1,
916 35.1, 9.1, 37.1, 11.1, 39.1, 13.1, 34.1, 8.1, 36.1, 10.1, 38.1, 12.1,
917 21.2, 23.2, 25.2, 22.2, 24.2, 26.2, 107.2, 108.2, 109.2, 110.2, 111.2, 112.2,
918 114.1, 116.2, 118.1, 14.1, 40.1, 119.2, 120.2, 121.2, 122.2, 123.2, 124.2};
919 bool notused[59] = {
true};
920 int order[59] = {-1};
921 int c = 0, cmin = -1, c0 = 0;
923 for (c0 = 0; c0 < 59; c0++) {
927 for (c0 = 0; c0 < 59; c0++) {
930 for (c = 0; c < 59; c++) {
931 if (notused[c] && (idchambers[c] < idmin)) {
932 idmin = idchambers[c];
939 notused[cmin] =
false;
945 float time = 0.f, timesigma = 0.f;
946 if (MCTimeFile == NULL) {
947 printf(
"TOF700 MC time-of-flight file name not defined!\n");
950 if (strlen(MCTimeFile) == 0) {
951 printf(
"TOF700 MC time-of-flight file name not defined!\n");
954 TString dir = getenv(
"VMCWORKDIR");
955 sprintf(fname,
"%s/geometry/%s", dir.
Data(), MCTimeFile);
956 ft = fopen(fname,
"r");
958 printf(
"TOF700 MC time-of-flight file %s open error!\n", fname);
965 int cexp = 0, ic = -1;
966 while (fscanf(ft,
"%d %f %f\n", &ic, &time, ×igma) == 3) {
967 if (ic > 0 && ic <= 59) {
968 cexp = order[ic - 1];
972 printf(
"Chamber %.1f (MC %d, EXP %d) average time-of-flight %f "
974 idchambers[cexp], ic, cexp, time, timesigma);