19#include "FairFileSource.h"
20#include "FairRootManager.h"
21#include "TClonesArray.h"
31 : FairTask(
"TofBuildDigiEvents")
33 , fTimeSliceHeader(NULL)
34 , fTofTimeSliceDigis(NULL)
35 , fDigiMatches(nullptr)
36 , fInputMCEventList(NULL)
37 , fOutputMCEventList(NULL)
38 , fTofEventDigis(NULL)
40 , fNominalTriggerCounterMultiplicity()
41 , fiTriggerMultiplicity(0)
42 , fbPreserveMCBacklinks(kFALSE)
43 , fbMCEventBuilding(kFALSE)
44 , fdEventStartTime(DBL_MIN)
45 , fCounterMultiplicity()
46 , fdIdealEventWindow(1000.)
47 , fProcessedIdealEvents()
48 , fIdealEventStartTimes()
52 , fInactiveCounterSides()
75 Double_t dDigiTime = tDigi->
GetTime();
76 Double_t dDigiToT = tDigi->
GetTot();
81 for (Int_t iLink = 0; iLink < iNMCLinks; iLink++) {
89 if (0 == tLink.GetUniqueID()) {
102 DigiVector.push_back(
new CbmTofDigi(iDigiAddress, dDigiTime, dDigiToT));
124 DigiVector.push_back(
new CbmTofDigi(iDigiAddress, dDigiTime, dDigiToT));
136 Int_t iDigiModuleType = tDigi->
GetType();
137 Int_t iDigiModuleIndex = tDigi->
GetSm();
138 Int_t iDigiCounterIndex = tDigi->
GetRpc();
139 Int_t iDigiCounterSide = tDigi->
GetSide();
141 Double_t dDigiTime = tDigi->
GetTime();
142 Double_t dDigiToT = tDigi->
GetTot();
146 std::map<std::tuple<Int_t, Int_t, Int_t>, UChar_t> ActualTriggerCounterMultiplicity;
148 std::set_intersection(
151 std::inserter(ActualTriggerCounterMultiplicity, ActualTriggerCounterMultiplicity.begin()));
158 FairRootManager::Instance()->Fill();
174 1 << iDigiCounterSide;
176 auto CounterSideTuple = std::make_tuple(iDigiModuleType, iDigiModuleIndex, iDigiCounterIndex, iDigiCounterSide);
202 if (!FairRootManager::Instance()) {
203 LOG(error) <<
"FairRootManager not found.";
207 fFileSource =
dynamic_cast<FairFileSource*
>(FairRootManager::Instance()->GetSource());
209 LOG(error) <<
"Could not get pointer to FairFileSource.";
215 LOG(error) <<
"Could not retrieve branch 'TimeSlice.' from FairRootManager.";
219 fTofTimeSliceDigis =
dynamic_cast<TClonesArray*
>(FairRootManager::Instance()->GetObject(
"TofDigiExp"));
221 LOG(error) <<
"Could not retrieve branch 'TofDigiExp' from FairRootManager.";
225 fDigiMatches =
dynamic_cast<TClonesArray*
>(FairRootManager::Instance()->GetObject(
"TofDigiMatch"));
227 LOG(error) <<
"Could not retrieve branch 'TofDigiMatch' from FairRootManager.";
233 LOG(error) <<
"Could not retrieve branch 'MCEventList.' from FairRootManager.";
237 if (FairRootManager::Instance()->GetObject(
"TofPointTB")) {
238 LOG(error) <<
"Timeslice branch with MC points found. Event building would "
239 "not work properly.";
246 IsOutputBranchPersistent(
"EventList."));
249 FairRootManager::Instance()->Register(
"CbmTofDigi",
"TOF event digis",
fTofEventDigis,
250 IsOutputBranchPersistent(
"CbmTofDigi"));
290 Int_t iNCounterSides)
293 (1 == iNCounterSides) ? 1 : 3);
302 auto EventID = itEvent->first;
303 Double_t dEventStartTime = itEvent->second;
307 Int_t iDigiModuleType = tDigi->GetType();
308 Int_t iDigiModuleIndex = tDigi->GetSm();
309 Int_t iDigiCounterIndex = tDigi->GetRpc();
310 Int_t iDigiCounterSide = tDigi->GetSide();
313 1 << iDigiCounterSide;
315 auto CounterSideTuple = std::make_tuple(iDigiModuleType, iDigiModuleIndex, iDigiCounterIndex, iDigiCounterSide);
326 std::map<std::tuple<Int_t, Int_t, Int_t>, UChar_t> ActualTriggerCounterMultiplicity;
330 std::inserter(ActualTriggerCounterMultiplicity, ActualTriggerCounterMultiplicity.begin()));
337 FairRootManager::Instance()->Fill();
363 std::set<std::pair<Int_t, Int_t>> MCEventSet;
365 for (Int_t iDigi = 0; iDigi <
fTofEventDigis->GetEntriesFast(); iDigi++) {
370 for (Int_t iLink = 0; iLink < iNMCLinks; iLink++) {
373 Int_t iFileIndex = tLink.
GetFile();
374 Int_t iEventIndex = tLink.
GetEntry();
378 if (-1 < iFileIndex && -1 < iEventIndex) {
379 MCEventSet.emplace(iFileIndex, iEventIndex);
387 for (
auto const& MCEvent : MCEventSet) {
388 Int_t iFileIndex = MCEvent.first;
389 Int_t iEventIndex = MCEvent.second;
393 if (-1. != dStartTime) {
397 LOG(fatal) << Form(
"Could not find MC event (%d, %d) in the input MC event list.", iFileIndex, iEventIndex);
410 fInactiveCounterSides.emplace(std::make_tuple(iModuleType, iModuleIndex, iCounterIndex, iCounterSide));
ClassImp(CbmConverterManager)
Container class for MC events with number, file and start time.
void Sort()
Sort the list.
virtual void Clear(Option_t *)
Delete all event entries.
double GetEventTime(uint32_t event, uint32_t file)
Event start time.
bool Insert(uint32_t event, uint32_t file, double time)
const CbmLink & GetLink(int32_t i) const
int32_t GetNofLinks() const
Bookkeeping of time-slice content.
double GetStartTime() const
Double_t fdIdealEventWindow
virtual ~CbmTofBuildDigiEvents()
Int_t fiTriggerMultiplicity
std::map< std::pair< Int_t, Int_t >, std::vector< CbmTofDigi * > > fIdealEventDigis
std::map< std::tuple< Int_t, Int_t, Int_t >, UChar_t > fCounterMultiplicity
std::set< std::tuple< Int_t, Int_t, Int_t, Int_t > > fInactiveCounterSides
void ProcessIdealEvents(Double_t dProcessingTime)
std::set< std::pair< Int_t, Int_t > > fProcessedIdealEvents
CbmTimeSlice * fTimeSliceHeader
void SetTriggerCounter(Int_t iModuleType, Int_t iModuleIndex, Int_t iCounterIndex, Int_t iNCounterSides)
Double_t fdEventStartTime
std::map< std::tuple< Int_t, Int_t, Int_t >, UChar_t > fNominalTriggerCounterMultiplicity
void SetIgnoreCounterSide(Int_t iModuleType, Int_t iModuleIndex, Int_t iCounterIndex, Int_t iCounterSide)
TClonesArray * fTofTimeSliceDigis
virtual InitStatus Init()
FairFileSource * fFileSource
std::map< std::pair< Int_t, Int_t >, Double_t > fIdealEventStartTimes
TClonesArray * fTofEventDigis
virtual void Exec(Option_t *option)
CbmMCEventList * fInputMCEventList
TClonesArray * fDigiMatches
CbmMCEventList * fOutputMCEventList
Bool_t fbPreserveMCBacklinks
Data class for expanded digital TOF information.
double GetSide() const
Channel Side.
int32_t GetAddress() const
Inherited from CbmDigi.
double GetTime() const
Inherited from CbmDigi.
double GetType() const
Sm Type .
double GetRpc() const
Detector aka Module aka RPC .
double GetTot() const
Alias for GetCharge.