8#include "FairRootManager.h"
10#include <TClonesArray.h>
11#include <TGeoManager.h>
12#include <TStopwatch.h>
18static Double_t workTime = 0.0;
26 , fErrX(1. /
sqrt(12.))
36 fEffFunc =
new TF1(
"eff_func",
"[0]*x+[1]", 0, 3);
37 if (fDetectorId ==
kTOF1) {
39 fPointsName =
"TOF400Point";
40 fDigitsName =
"TOF400";
41 fHitsName =
"BmnTof400Hit";
42 fErrX = 1. /
sqrt(12.);
47 fPointsName =
"TOF700Point";
48 fDigitsName =
"TOF701";
49 fHitsName =
"BmnTof700Hit";
55 fTestFlnm = Form(
"Test_%s_run%d.root", fDetName.Data(), fRun);
57 treeCont =
new TTree(
"data",
"data");
58 aTofCont =
new TClonesArray(
"BmnTOF1Conteiner");
68 for (Int_t
i = 0;
i < fNDetectors;
i++) {
80InitStatus BmnTof1HitProducer::LoadDetectorConfiguration()
84 if (fDetectorId ==
kTOF1) {
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;
100 cout << this->GetName() <<
"::LoadDetectorConfiguration(): number of " << fDetName
101 <<
" Detectors from geometry file = " << fNDetectors << endl;
105 if (!SetCorrFiles()) {
106 cout << this->GetName()
107 <<
"::LoadDetectorConfiguration(): No corrections for the current run! Task will be deactivated"
114 for (Int_t
i = 0;
i < fNDetectors;
i++) {
115 Int_t DoTestForDetector =
118 DoTestForDetector = 1;
121 if (FlagFileLRcorrection)
122 pDetector[
i]->
SetCorrLR(NameFileLRcorrection);
123 if (FlagFileSlewingCorrection)
125 if (FlagFileTimeShiftCorrection)
128 pDetector[
i]->
SetGeo(pGeoUtils);
133 if (fPeriod == 6 && fDetectorId ==
kTOF1) {
149 printf(
"\n=================== %s::Init(): Start================\n", this->GetName());
151 pRandom =
new TRandom2();
154 cout <<
" Only primary particles are processed!!! \n";
157 aMcPoints = (TClonesArray*)FairRootManager::Instance()->GetObject(fPointsName.Data());
159 cout << this->GetName() <<
"::Init(): branch " << fPointsName.Data()
160 <<
" not found! Task will be deactivated" << endl;
164 aMcTracks = (TClonesArray*)FairRootManager::Instance()->GetObject(
"MCTrack");
166 cout << this->GetName() <<
"::Init(): branch MCTrack not found! Task will be deactivated" << endl;
172 cout << this->GetName() <<
"::Init(): DetectorId is incorrect. Use kTOF1 or kTOF701." << endl;
173 cout <<
" kTOF1 = " <<
kTOF1 <<
"; kTOF701 = " <<
kTOF701 <<
"; fDetectorId = " << fDetectorId << endl;
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"
186 this->GetName(), fPeriod, fRun);
191 fEventHeader = (
BmnEventHeader*)FairRootManager::Instance()->GetObject(
"BmnEventHeader.");
193 aExpDigits = (TClonesArray*)FairRootManager::Instance()->GetObject(fDigitsName.Data());
195 cout << this->GetName() <<
"::Init(): branch" << fDigitsName.Data()
196 <<
" is not found! Task will be deactivated" << endl;
202 TString NameT0Branch, NameT0Branch2;
206 NameT0Branch =
"BC2";
208 if (fRun >= 968 && fRun <= 1546) {
209 NameT0Branch =
"T0_1_A";
210 NameT0Branch2 =
"T0_2_A";
212 if (fRun >= 6587 && fRun <= 8427) {
213 NameT0Branch =
"BC2AT";
214 NameT0Branch2 =
"BC2AB";
219 NameT0Branch =
"BmnTrigInfo.";
223 LOG(info) << this->GetName() <<
"::Init(): looking for branch " << NameT0Branch <<
" for start" << endl;
227 aExpDigitsT0 = (TClonesArray*)FairRootManager::Instance()->GetObject(NameT0Branch.Data());
230 printf(
"%s::Init(): branch %s is not found! Task will be deactivated\n", this->GetName(),
231 NameT0Branch.Data());
238 cout << this->GetName() <<
"::Init(): looking for branch " << NameT0Branch2 <<
" for start" << endl;
239 aExpDigitsT0_2 = (TClonesArray*)FairRootManager::Instance()->GetObject(NameT0Branch2.Data());
241 printf(
"%s::Init(): branch %s is not found! Task will be deactivated\n", this->GetName(),
242 NameT0Branch2.Data());
250 aTofHits =
new TClonesArray(
"BmnTofHit");
251 FairRootManager::Instance()->Register(fHitsName.Data(), fDetName.Data(),
aTofHits, kTRUE);
253 if (LoadDetectorConfiguration() != kSUCCESS) {
259 printf(
"\n=================== %s::Init(): Initialization finished succesfully. ==\n\n", this->GetName());
264Bool_t BmnTof1HitProducer::HitExist(
const Double_t& val,
265 const Bool_t& isWide_strip)
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);
281 if (pRandom->Rndm() < efficiency)
287Bool_t BmnTof1HitProducer::DoubleHitExist(
const Double_t& val,
288 const Bool_t& isWide_strip,
306 if (flag ==
kTOF701 && isWide_strip) {
307 fEffFunc->SetParameters((0.05 - 0.409) / 0.9375, 0.409);
310 else if (flag ==
kTOF701 && !isWide_strip)
311 fEffFunc->SetParameters((0.05 - 0.44) / 0.5492, 0.44);
314 fEffFunc->SetParameters((0.05 - 0.339) / 0.625, 0.339);
316 Double_t efficiency = fEffFunc->Eval(val);
318 if (pRandom->Rndm() < efficiency)
319 return HitExist(val, isWide_strip);
323Bool_t BmnTof1HitProducer::TripleHitExist(
const Double_t& val,
324 const Bool_t& isWide_strip,
328 if (flag ==
kTOF701 && isWide_strip)
329 fEffFunc->SetParameters((0.078 - 0.01) / 0.9375, 0.078);
331 else if (flag ==
kTOF701 && !isWide_strip)
332 fEffFunc->SetParameters((0.095 - 0.01) / 0.5492, 0.095);
335 fEffFunc->SetParameters((0.075 - 0.01) / 0.625, 0.075);
337 Double_t efficiency = fEffFunc->Eval(val);
339 if (pRandom->Rndm() < efficiency)
340 return HitExist(val, isWide_strip);
354 printf(
"\n=================== %s::Exec(): Started ====================\n", this->GetName());
360 TVector3 pos, XYZ_smeared;
361 int nSingleHits = 0, nDoubleHits = 0, nTripleHits = 0;
364 for (Int_t pointIndex = 0, nTofPoint =
aMcPoints->GetEntriesFast(); pointIndex < nTofPoint;
371 trackID = pPoint->GetTrackID();
374 Double_t time = pRandom->Gaus(pPoint->GetTime(), fTimeSigma);
375 pPoint->Position(pos);
378 const LStrip1*
const pcStrip = pStrip;
379 if (pStrip == NULL) {
380 printf(
"UID is incorrect: UID = %d", UID);
384 Bool_t isWide_strip =
false;
390 XYZ_smeared.SetXYZ(pStrip->
center.X(), pRandom->Gaus(pos.Y(), fErrY), pStrip->
center.Z());
394 fErrY = 1.875 /
sqrt(12.);
396 fErrY = 1.09 /
sqrt(12.);
398 XYZ_smeared.SetXYZ(pRandom->Gaus(pos.X(), fErrX), pStrip->
center.Y(), pStrip->
center.Z());
401 printf(
"!!!!! WRONG DetectorID for %s reconstruction\n", fDetName.Data());
406 static const TVector3 XYZ_err(fErrX, fErrY, 0.);
409 Double_t distance = 1000;
421 if ((passed = HitExist(distance, isWide_strip)) ==
true)
426 AddHit(UID, XYZ_smeared, XYZ_err, pointIndex, trackID, time, detID);
437 if (passed && DoubleHitExist(distance, isWide_strip, detID))
454 XYZ_smeared.SetXYZ(pStrip->
center.X(), pRandom->Gaus(pos.Y(), fErrY), pStrip->
center.Z());
456 XYZ_smeared.SetXYZ(pRandom->Gaus(pos.X(), fErrX), pStrip->
center.Y(), pStrip->
center.Z());
458 printf(
"!!!!! WRONG DetectorID for %s reconstruction\n", fDetName.Data());
467 AddHit(CrossUID, XYZ_smeared, XYZ_err, pointIndex, trackID, time, detID);
475 if ((passed && TripleHitExist(distance, isWide_strip, detID)) ==
true) {
486 XYZ_smeared.SetXYZ(pStrip->
center.X(), pRandom->Gaus(pos.Y(), fErrY), pStrip->
center.Z());
488 XYZ_smeared.SetXYZ(pRandom->Gaus(pos.X(), fErrX), pStrip->
center.Y(), pStrip->
center.Z());
490 printf(
"!!!!! WRONG DetectorID for %s reconstruction\n", fDetName.Data());
495 AddHit(CrossUID, XYZ_smeared, XYZ_err, pointIndex, trackID, time, detID);
507 for (Int_t
i = 0;
i < fNDetectors;
i++)
508 pDetector[
i]->Clear();
510 for (Int_t iDig = 0; iDig <
aExpDigits->GetEntriesFast(); ++iDig) {
514 if (!OutOfRange(digTof->
GetPlane())) {
520 for (Int_t
i = 0;
i < fNDetectors;
i++) {
527 cout <<
"Start fill TClonesArray" << endl;
539 cout <<
"Fill TTree" << endl;
544 workTime += sw.RealTime();
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());
564 for (Int_t
i = 0;
i < fNDetectors;
i++)
565 pDetector[
i]->SaveHistToFile(
fTestFlnm.Data());
569 printf(
"Work time of %s: %4.2f sec.\n", this->GetName(), workTime);
576 pRandom->SetSeed(seed);
589 if (digT0->
GetMod() == 0) {
596 }
else if (fPeriod == 8) {
601 if (fRun >= 968 && fRun <= 1546) {
609 if (fRun >= 6587 && fRun <= 8427) {
610 Bool_t FlagHitTop = kFALSE, FlagHitBotom = kFALSE;
612 for (Int_t iDig = 0; iDig <
aExpDigitsT0->GetEntriesFast(); ++iDig) {
621 for (Int_t iDig = 0; iDig <
aExpDigitsT0_2->GetEntriesFast(); ++iDig) {
625 FlagHitBotom = kTRUE;
630 if (FlagHitTop && FlagHitBotom) {
637 }
else if (fPeriod == 9) {
653Bool_t BmnTof1HitProducer::IsFile(TString NameFile =
"")
655 NameFile = Form(
"%s%s%s", getenv(
"VMCWORKDIR"),
"/input/", NameFile.Data());
657 Temp.open(NameFile, ios::in );
658 return Temp.is_open();
662Bool_t BmnTof1HitProducer::SetCorrFiles()
664 FlagFileLRcorrection =
true;
665 FlagFileSlewingCorrection =
true;
666 FlagFileTimeShiftCorrection =
true;
668 NameFileLRcorrection =
"";
669 NameFileSlewingCorrection =
"";
670 NameFileTimeShiftCorrection =
"";
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);
682 if (fRun >= 2013 && fRun <= 3588) {
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);
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);
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);
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);
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);
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);
731 if (fDetectorId ==
kTOF1) {
732 NameFileLRcorrection =
"";
733 NameFileSlewingCorrection =
"";
734 NameFileTimeShiftCorrection =
"";
735 FlagFileLRcorrection =
false;
736 FlagFileSlewingCorrection =
false;
737 FlagFileTimeShiftCorrection =
false;
740 NameFileLRcorrection = Form(
"TOF701_LRCorr_RUN%i.dat", 8);
741 NameFileSlewingCorrection =
"";
742 NameFileTimeShiftCorrection =
"";
743 FlagFileLRcorrection =
true;
744 FlagFileSlewingCorrection =
false;
745 FlagFileTimeShiftCorrection =
false;
753 if (!IsFile(NameFileLRcorrection)) {
754 FlagFileLRcorrection =
false;
757 << this->GetName() <<
"::Init(): File " << NameFileLRcorrection.Data()
758 <<
" for LR correction is not found" << endl;
759 cout <<
"Check /input folder for file" << endl;
763 if (!IsFile(NameFileSlewingCorrection)) {
764 FlagFileSlewingCorrection =
false;
767 << this->GetName() <<
"::Init(): File " << NameFileSlewingCorrection.Data()
768 <<
" for Slewing correction is not found" << endl;
769 cout <<
"Check /input folder for file" << endl;
773 if (!IsFile(NameFileTimeShiftCorrection)) {
774 FlagFileTimeShiftCorrection =
false;
777 << this->GetName() <<
"::Init(): File " << NameFileTimeShiftCorrection.Data()
778 <<
" for TimeShift correction is not found" << endl;
779 cout <<
"Check /input folder for file" << endl;
788 if (FlagFileLRcorrection && FlagFileSlewingCorrection && FlagFileTimeShiftCorrection)
796Bool_t BmnTof1HitProducer::OutOfRange(Int_t iPlane = -1)
798 if (iPlane < 0 || iPlane >= fNDetectors)
808 resultTree->Branch(fHitsName.Data(), &
aTofHits);
friend F32vec4 sqrt(const F32vec4 &a)
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
virtual void Print(const Option_t *opt) 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
TFile * fileCont
—> output
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)
virtual ~BmnTof1HitProducer()
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)
void SetAmp(Double_t amp)
Double_t MinDistanceToEdge701(const TVector3 *pos, Side_t &side) const
Double_t MinDistanceToEdge(const TVector3 *pos, Side_t &side) const