6 #include "Tofrec02_ihep.h"
12 m_logger->info(
"UBegin =============================================");
17 std::string output_file_option =
m_reprocess_rti ?
"update" :
"recreate";
21 m_logger->info(
"Creating NAIA event tree");
31 m_logger->info(
"NAIA branches created");
35 static bool firstCall =
true;
37 m_logger->debug(
"Switching file in chain: {}",
m_tree->GetCurrentFile()->GetName());
45 return AMSEventR::Notify();
49 m_logger->debug(
"Called NtpSelector::ProcessFileInfo");
55 m_chain->m_fileInfo.FileName =
m_tree->GetCurrentFile()->GetName();
57 m_chain->m_fileInfo.Run = Run();
61 m_chain->m_fileInfo.UTCTime.first = fHeader.Time[0];
62 m_chain->m_fileInfo.UTCTime.second = fHeader.Time[0];
67 MCEventgR *primary = (nMCEventg() != 0) ? pMCEventg(0) :
nullptr;
68 m_chain->m_fileInfoMC.Charge = (primary) ? static_cast<int>(primary->Charge) : 0;
69 m_chain->m_fileInfoMC.Mass = (primary) ? primary->Mass : 0;
70 m_chain->m_fileInfoMC.MomentumRange.first = std::numeric_limits<float>::max();
71 m_chain->m_fileInfoMC.MomentumRange.second = 0;
72 auto *datacard =
m_tree->GetCurrentFile()->Get<TObjString>(
"DataCards");
74 m_logger->error(
"No Datacard Object available!");
76 m_chain->m_fileInfoMC.DatacardPID = NtpTools::GetDatacardValue<int>(datacard,
"PART");
77 m_chain->m_fileInfoMC.DatacardMomentumRange.first = NtpTools::GetDatacardValue<float>(datacard,
"PMIN");
78 m_chain->m_fileInfoMC.DatacardMomentumRange.second = NtpTools::GetDatacardValue<float>(datacard,
"PMAX");
79 m_chain->m_fileInfoMC.DatacardNGen = NtpTools::GetDatacardValue<unsigned int>(datacard,
"TRIG");
81 if (
m_chain->m_fileInfo.FileName.find(
".l1.") != std::string::npos) {
83 }
else if (
m_chain->m_fileInfo.FileName.find(
".l19.") != std::string::npos) {
85 }
else if (
m_chain->m_fileInfo.FileName.find(
".l1a9.") != std::string::npos) {
87 }
else if (
m_chain->m_fileInfo.FileName.find(
".tb.") != std::string::npos) {
95 m_chain->m_fileInfo.BadRunTag = getsetup()->IsBadRun(
m_chain->m_fileInfo.BadRunReason, UTime(), Run());
97 m_chain->m_fileInfo.BadRunTag = 2;
103 Abort(
"Aborting TSelector Loop\n");
104 if (
m_chain->m_fileInfo.Run == 0) {
112 m_chain->m_fileInfo.UTCTime.second = fHeader.Time[0];
115 SetDefaultMCTuningParameters();
116 TRCLFFKEY.ClusterCofGOpt = 1;
117 TRFITFFKEY.Zshift = -1;
119 m_chain->m_fileInfoMC.EventNo.first = std::min(
Event(),
m_chain->m_fileInfoMC.EventNo.first);
120 m_chain->m_fileInfoMC.EventNo.second = std::max(
Event(),
m_chain->m_fileInfoMC.EventNo.second);
122 MCEventgR *primary = (nMCEventg() != 0) ? pMCEventg(0) :
nullptr;
123 float p = (primary) ? primary->Momentum : 0;
124 m_chain->m_fileInfoMC.MomentumRange.first = std::min(p,
m_chain->m_fileInfoMC.MomentumRange.first);
125 m_chain->m_fileInfoMC.MomentumRange.second = std::max(p,
m_chain->m_fileInfoMC.MomentumRange.second);
127 TrLinearEtaDB::SetLinearCluster();
128 TRFITFFKEY.Zshift = 2;
131 TRFITFFKEY.ErcHeY = 0;
144 static bool got_it =
false;
146 m_logger->debug(
"UProcessCut - First event processed - Entry: {}, Run: {}, Event: {}", Entry(), Run(),
Event());
147 }
else if (Entry() % 10000 == 0) {
148 m_logger->debug(
"UProcessCut - Event processed - Entry: {}, Run: {}, Event: {}", Entry(), Run(),
Event());
152 m_logger->trace(
"Entry: {}", Entry());
157 if ((nDaqEvent() < 1) || (nLevel1() < 1)) {
163 static unsigned long lastSec = 0;
165 ParticleR *particle =
nullptr;
169 m_chain->m_event.mcTruthBase.Fill(
this);
170 m_chain->m_event.mcTruthPlus.Fill(
this);
175 m_chain->m_event.header.Fill(
this);
176 m_chain->m_event.evSummary.Fill(
this);
185 m_chain->m_rtiInfo.FillEventVariables();
194 lastSec =
m_chain->m_event.header.UTCTime;
200 m_chain->m_rtiInfo.AccumulateEventVariables(
this);
210 m_chain->m_event.daq.Fill(*pDaqEvent(0));
214 particle = pParticle(0);
221 bool has_tof =
m_chain->m_event.tofBase.Fill(particle->pBeta(), particle->pBetaH());
226 if (std::fabs(UTOFCharge - 1) < 0.5) {
228 }
else if (std::fabs(UTOFCharge - 2) < 0.5) {
230 }
else if (UTOFCharge > 2.5) {
237 m_chain->m_event.tofPlus.Fill(particle->pBeta(), particle->pBetaH());
240 if (particle->pTrTrack()) {
242 m_chain->m_event.mcTruthPlus.FillTrMCHit(particle->pTrTrack());
248 m_logger->trace(
"Track no. = {}", particle->iTrTrack());
255 bool has_track =
m_chain->m_event.trTrackBase.Fill(particle->pTrTrack());
261 if (std::fabs(innerCharge - 1) < 0.5) {
263 }
else if (std::fabs(innerCharge - 2) < 0.5) {
265 }
else if (innerCharge > 2.5) {
272 m_chain->m_event.trTrackPlus.Fill(particle->pTrTrack());
275 if (NTrTrack() > 1) {
277 TrTrackR *second_track =
nullptr;
278 for (TrTrackR &track : TrTrack()) {
279 if (&track == particle->pTrTrack() || track.GetNhits() < 5) {
283 if (!second_track || second_track->GetRigidity() < track.GetRigidity()) {
284 second_track = &track;
289 m_chain->m_event.secondTrTrackBase.Fill(second_track, TrTrackFillType::SecondTrack);
295 m_chain->m_event.trTrackBaseSt.Fill(particle->pTrTrack(), TrTrackFillType::Standalone);
298 if (std::fabs(innerCharge_St - 1) < 0.5) {
300 }
else if (std::fabs(innerCharge_St - 2) < 0.5) {
302 }
else if (innerCharge_St > 2.5) {
312 auto trdK = std::make_unique<TrdKCluster>(
this, particle->pTrTrack(), 0);
323 bool has_trd =
m_chain->m_event.trdKBase.Fill(trdK.get(), particle->pTrTrack());
333 if (particle->pEcalShower()) {
337 bool has_ecal =
m_chain->m_event.ecalBase.Fill(particle->pEcalShower());
345 m_chain->m_event.ecalPlus.Fill(particle->pEcalShower());
349 if (particle->pRichRing()) {
353 bool has_rich =
m_chain->m_event.richBase.Fill(particle->pRichRing(), particle->pRichRingB());
361 m_chain->m_event.richPlus.Fill(
this, particle->pRichRing(), particle->pRichRingB(), particle->pTrTrack());
376 if (has_tof_standalone) {
381 if (std::fabs(UTOFCharge_St - 1) < 0.5) {
383 }
else if (std::fabs(UTOFCharge_St - 2) < 0.5) {
385 }
else if (UTOFCharge_St > 2.5) {
400 auto trdK = std::make_unique<TrdKCluster>();
402 m_logger->trace(
"Building standalone TRD from TrdTrack");
406 m_logger->trace(
"Building standalone TRD from BetaH");
419 bool has_trd_standalone =
m_chain->m_event.trdKBaseSt.Fill(trdK.get(),
nullptr);
420 if (has_trd_standalone) {
434 m_chain->m_event.extHitBase.Fill(
this, use_trd);
446 ? static_cast<float>(
m_chain->m_event.ecalBase.GetCOG().z())
447 : std::numeric_limits<float>::max();
448 m_chain->m_event.trTrackBase.FillElectronVars(particle->pTrTrack(), zEcalCOG, refitKalman);
452 m_chain->m_event.trTrackPlus.FillElectronVars(particle->pTrTrack(), refitKalman);
456 m_logger->trace(
"Event mask: {}", to_string_binary<32>(
m_chain->m_event.header.Mask()));
466 void NtpSelector::UProcessFill() {}
468 void NtpSelector::UTerminate() {
470 m_chain->FillFileInfo();
472 m_chain->m_rtiInfo.FillEventVariables();
475 m_logger->info(
"UTerminate =============================================");
480 if (m_reprocess_rti) {
481 m_logger->info(
"Overwriting RTIInfo tree");
482 m_chain->m_rti.tree->BuildIndex(
"RTIInfo.UTCTime");
483 m_outputFile->WriteTObject(m_chain->m_rti.tree,
"RTI",
"Overwrite");
485 m_logger->info(
"Writing chain to file");
486 NAIA::Version versionHeader;
487 m_outputFile->WriteTObject(&versionHeader,
"VersionHeader");
490 m_benchmark.Print(m_logger);
493 void NtpSelector::DefineStandAlone() {
494 m_betahStPtr =
nullptr;
495 m_trdTrackStPtr =
nullptr;
498 auto oldOpt = TofRecH::BuildOpt;
499 TofRecH::BuildOpt = 3110;
500 m_logger->trace(
"Rebuilding Tof with opt {}", TofRecH::BuildOpt);
502 m_logger->trace(
"{} BetaH objects found", nBetaH());
504 auto getMaxQBetaH = [
this](
bool matchTrd =
true) {
506 BetaHR *maxQBetaH =
nullptr;
512 double prev_tofcharge = 0;
514 for (BetaHR &betah :
BetaH()) {
516 float temp_tofcharge = betah.GetQ(nlayers, qrms);
517 if (temp_tofcharge <= 0)
521 if (!betah.pTrdTrack())
525 unsigned int nTrdHits{0};
526 for (
unsigned int i = 0; i < betah.pTrdTrack()->NTrdSegment(); ++i) {
527 nTrdHits += betah.pTrdTrack()->pTrdSegment(i)->NTrdCluster();
533 m_logger->trace(
"StAl BetaH n. {} - Charge {} (Chi2C: {} - Chi2T: {}) - TRD hits: {}", ib, temp_tofcharge,
534 betah.GetChi2C(), betah.GetChi2T(), nTrdHits);
536 m_logger->trace(
"StAl BetaH n. {} - Charge {} (Chi2C: {} - Chi2T: {})", ib, temp_tofcharge, betah.GetChi2C(),
540 if (temp_tofcharge > prev_tofcharge) {
542 prev_tofcharge = temp_tofcharge;
549 m_betahStPtr = getMaxQBetaH(
false);
550 m_trdTrackStPtr = m_betahStPtr ? m_betahStPtr->pTrdTrack() :
nullptr;
553 TofRecH::BuildOpt = oldOpt;
This event is classified as charge 1 according to tracker standalone (0.5 < Q < 1.5)
Tof standalone data is available for this event.
This event is classified as charge 1 according to tof standalone (0.5 < Q < 1.5)
This event is classified as charge 2 according to tof (1.5 < Q < 2.5)
TrTrack data is available for this event.
This event is classified as charge >2 according to tracker standalone (Q > 2.5)
Rich data is available for this event.
Stopwatch MakeStopwatch(std::string name)
This event is classified as charge >2 according to tof (Q > 2.5)
TRD standalone data is available for this event.
unsigned long long firstentry
first entry to be processed
TrdTrackR * m_trdTrackStPtr
This event is classified as charge 1 according to tracker (0.5 < Q < 1.5)
Charge estimated using the upper half of the TRD.
bool m_isMC
is simulation?
virtual void UBegin() override
Init output.
This event is classified as charge >2 according to tof standalone (Q > 2.5)
Ecal data is available for this event.
TRD data is available for this event.
std::enable_if< EnableBitMaskOperators< Enum >::enable, bool >::type MatchAllBits(const Enum test, const Enum ones, const Enum zeroes=static_cast< Enum >(0))
This event is classified as charge 1 according to tof (0.5 < Q < 1.5)
This event is classified as charge 2 according to tracker (1.5 < Q < 2.5)
This event is classified as charge 2 according to tracker standalone (1.5 < Q < 2.5)
std::shared_ptr< spdlog::logger > m_logger
std::unique_ptr< TFile > m_outputFile
Total deposited energy in Ecal.
virtual bool UProcessCut() override
Cut, select and prescale.
This event is classified as charge >2 according to tracker (Q > 2.5)
particles shot towards Layer 1
std::enable_if< std::is_convertible< Key, size_t >::value, bool >::type ContainsKeys(const std::array< T, N > &container, Key key)
virtual bool Notify() override
Called every time a new file is loaded in the chain.
std::string m_outputFilename
This event is classified as charge 2 according to tof standalone (1.5 < Q < 2.5)
Standard tracker charge reconstruction.
void DefineStandAlone()
Select standalone objects.
particles shot towards layer 1 and passing through layer 9
Tof data is available for this event.
std::unique_ptr< NAIAChain > m_chain
unsigned long long lastentry
last entry to be processed