16 #include "FairFileSource.h"
17 #include "FairLogger.h"
18 #include "FairRootManager.h"
20 #include "TClonesArray.h"
28 : FairTask(
"TofBuildDigiEvents")
30 , fTimeSliceHeader(NULL)
31 , fTofTimeSliceDigis(NULL)
32 , fDigiMatches(nullptr)
33 , fInputMCEventList(NULL)
34 , fOutputMCEventList(NULL)
35 , fTofEventDigis(NULL)
37 , fNominalTriggerCounterMultiplicity()
38 , fiTriggerMultiplicity(0)
39 , fbPreserveMCBacklinks(kFALSE)
40 , fbMCEventBuilding(kFALSE)
41 , fdEventStartTime(DBL_MIN)
42 , fCounterMultiplicity()
43 , fdIdealEventWindow(1000.)
44 , fProcessedIdealEvents()
45 , fIdealEventStartTimes()
49 , fInactiveCounterSides() {}
71 Double_t dDigiTime = tDigi->
GetTime();
72 Double_t dDigiToT = tDigi->
GetTot();
77 for (Int_t iLink = 0; iLink < iNMCLinks; iLink++) {
85 if (0 == tLink.GetUniqueID()) {
99 new CbmTofDigi(iDigiAddress, dDigiTime, dDigiToT));
121 DigiVector.push_back(
122 new CbmTofDigi(iDigiAddress, dDigiTime, dDigiToT));
135 Int_t iDigiModuleType = tDigi->
GetType();
136 Int_t iDigiModuleIndex = tDigi->
GetSm();
137 Int_t iDigiCounterIndex = tDigi->
GetRpc();
138 Int_t iDigiCounterSide = tDigi->
GetSide();
140 Double_t dDigiTime = tDigi->
GetTime();
141 Double_t dDigiToT = tDigi->
GetTot();
145 std::map<std::tuple<Int_t, Int_t, Int_t>, UChar_t>
146 ActualTriggerCounterMultiplicity;
148 std::set_intersection(
153 std::inserter(ActualTriggerCounterMultiplicity,
154 ActualTriggerCounterMultiplicity.begin()));
156 if (ActualTriggerCounterMultiplicity.size()
160 FairRootManager::Instance()->Fill();
175 iDigiModuleType, iDigiModuleIndex, iDigiCounterIndex)] |=
176 1 << iDigiCounterSide;
178 auto CounterSideTuple = std::make_tuple(
179 iDigiModuleType, iDigiModuleIndex, iDigiCounterIndex, iDigiCounterSide);
187 tEventDigi =
new ((*fTofEventDigis)[
fTofEventDigis->GetEntriesFast()])
191 tEventDigi =
new ((*fTofEventDigis)[
fTofEventDigis->GetEntriesFast()])
192 CbmTofDigi(iDigiAddress, dDigiTime, dDigiToT);
205 if (!FairRootManager::Instance()) {
206 LOG(error) <<
"FairRootManager not found.";
211 dynamic_cast<FairFileSource*
>(FairRootManager::Instance()->GetSource());
213 LOG(error) <<
"Could not get pointer to FairFileSource.";
218 FairRootManager::Instance()->GetObject(
"TimeSlice."));
221 <<
"Could not retrieve branch 'TimeSlice.' from FairRootManager.";
226 FairRootManager::Instance()->GetObject(
"TofDigiExp"));
229 <<
"Could not retrieve branch 'TofDigiExp' from FairRootManager.";
234 FairRootManager::Instance()->GetObject(
"TofDigiMatch"));
237 <<
"Could not retrieve branch 'TofDigiMatch' from FairRootManager.";
242 FairRootManager::Instance()->GetObject(
"MCEventList."));
245 <<
"Could not retrieve branch 'MCEventList.' from FairRootManager.";
249 if (FairRootManager::Instance()->GetObject(
"TofPointTB")) {
250 LOG(error) <<
"Timeslice branch with MC points found. Event building would "
251 "not work properly.";
257 FairRootManager::Instance()->Register(
"EventList.",
260 IsOutputBranchPersistent(
"EventList."));
263 FairRootManager::Instance()->Register(
"CbmTofDigi",
266 IsOutputBranchPersistent(
"CbmTofDigi"));
305 Int_t iNCounterSides) {
307 std::make_tuple(iModuleType, iModuleIndex, iCounterIndex),
308 (1 == iNCounterSides) ? 1 : 3);
317 auto EventID = itEvent->first;
318 Double_t dEventStartTime = itEvent->second;
322 Int_t iDigiModuleType = tDigi->GetType();
323 Int_t iDigiModuleIndex = tDigi->GetSm();
324 Int_t iDigiCounterIndex = tDigi->GetRpc();
325 Int_t iDigiCounterSide = tDigi->GetSide();
328 iDigiModuleType, iDigiModuleIndex, iDigiCounterIndex)] |=
329 1 << iDigiCounterSide;
331 auto CounterSideTuple = std::make_tuple(iDigiModuleType,
348 std::map<std::tuple<Int_t, Int_t, Int_t>, UChar_t>
349 ActualTriggerCounterMultiplicity;
351 std::set_intersection(
356 std::inserter(ActualTriggerCounterMultiplicity,
357 ActualTriggerCounterMultiplicity.begin()));
359 if (ActualTriggerCounterMultiplicity.size()
363 FairRootManager::Instance()->Fill();
386 std::set<std::pair<Int_t, Int_t>> MCEventSet;
388 for (Int_t iDigi = 0; iDigi <
fTofEventDigis->GetEntriesFast(); iDigi++) {
393 for (Int_t iLink = 0; iLink < iNMCLinks; iLink++) {
396 Int_t iFileIndex = tLink.
GetFile();
397 Int_t iEventIndex = tLink.
GetEntry();
401 if (-1 < iFileIndex && -1 < iEventIndex) {
402 MCEventSet.emplace(iFileIndex, iEventIndex);
410 for (
auto const& MCEvent : MCEventSet) {
411 Int_t iFileIndex = MCEvent.first;
412 Int_t iEventIndex = MCEvent.second;
414 Double_t dStartTime =
417 if (-1. != dStartTime) {
421 "Could not find MC event (%d, %d) in the input MC event list.",
436 Int_t iCounterSide) {
438 std::make_tuple(iModuleType, iModuleIndex, iCounterIndex, iCounterSide));