23 #include "FairLogger.h"
24 #include "FairRootManager.h"
25 #include "FairRunOnline.h"
29 #include "TClonesArray.h"
32 #include "THttpServer.h"
45 <<
"CbmMcbm2019TimeWinEventBuilderAlgo::InitAlgo => Starting sequence";
48 FairRootManager* ioman = FairRootManager::Instance();
57 LOG(fatal) <<
"No digi input for reference detector, stopping there!";
61 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
66 <<
"No digi input for one of selection detector, stopping there!";
72 dynamic_cast<TClonesArray*
>(ioman->GetObject(
"TimesliceMetaData"));
75 <<
"No TS metadata input found"
76 <<
" => Please check in the unpacking macro if the following line was "
79 <<
"source->SetWriteOutputFlag(kTRUE); // For writing TS metadata";
84 LOG(info) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::InitAlgo => Done";
91 LOG_IF(info,
fuNrTs % 1000 == 0) <<
"Begin of TS " <<
fuNrTs;
109 LOG(debug) <<
"Found " <<
fEventVector.size() <<
" triggered events";
119 LOG(debug) <<
"Event " <<
counter <<
" has " <<
event->GetNofData()
129 LOG(info) <<
"Total errors: " <<
fuErrors;
136 FairRootManager* ioman = FairRootManager::Instance();
140 fT0DigiVec = ioman->InitObjectAs<std::vector<CbmTofDigi>
const*>(
"T0Digi");
142 LOG(info) <<
"No T0 digi input found.";
148 LOG(info) <<
"No " << det.
sName <<
" digi input found.";
162 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
165 (*det).fuStartIndex = 0;
166 (*det).fuEndIndex = 0;
174 LoopOnSeeds<CbmStsDigi>();
178 LoopOnSeeds<CbmMuchBeamTimeDigi>();
182 LoopOnSeeds<CbmTrdDigi>();
186 LoopOnSeeds<CbmTofDigi>();
190 LoopOnSeeds<CbmRichDigi>();
194 LoopOnSeeds<CbmPsdDigi>();
198 LoopOnSeeds<CbmTofDigi>();
202 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::BuildEvents => "
203 <<
"Trying to search event seeds with unsupported det: "
210 template<
class DigiSeed>
215 LOG(fatal) << Form(
"CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
216 "No TS metadata found for TS %6u.",
223 LOG(warning) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
224 << Form(
"Event window not fitting in TS overlap, risk of "
225 "incomplete events: %f %f %f %llu",
234 Double_t dSeedWindowBeg =
237 Double_t dSeedWindowEnd =
250 for (UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi) {
251 LOG(debug) << Form(
"Checking seed %6u / %6u", uDigi, uNbRefDigis);
253 Double_t dTime =
fT0DigiVec->at(uDigi).GetTime();
260 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
261 <<
"T0 as reference detector but vector not found!";
268 for (UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi) {
269 LOG(debug) << Form(
"Checking seed %6u / %6u", uDigi, uNbRefDigis);
270 const DigiSeed* pDigi =
fDigiMan->
Get<DigiSeed>(uDigi);
272 if (
nullptr != pDigi) {
273 Double_t dTime = pDigi->GetTime();
276 if (dTime < dSeedWindowBeg) {
279 else if (dSeedWindowEnd < dTime) {
291 UInt_t uSeedDigiIdx) {
302 LOG(debug1) <<
"Reject seed due to overlap";
313 LOG(debug1) <<
"Reject seed because part of cluster of previous one";
337 SearchMatches<CbmStsDigi>(dSeedTime,
fRefDet);
341 SearchMatches<CbmMuchBeamTimeDigi>(dSeedTime,
fRefDet);
345 SearchMatches<CbmTrdDigi>(dSeedTime,
fRefDet);
349 SearchMatches<CbmTofDigi>(dSeedTime,
fRefDet);
353 SearchMatches<CbmRichDigi>(dSeedTime,
fRefDet);
357 SearchMatches<CbmPsdDigi>(dSeedTime,
fRefDet);
361 SearchMatches<CbmTofDigi>(dSeedTime,
fRefDet);
365 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
366 <<
"Trying to search matches with unsupported det: "
368 <<
"You may want to add support for it in the method.";
381 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
384 switch ((*det).detId) {
386 SearchMatches<CbmStsDigi>(dSeedTime, *det);
390 SearchMatches<CbmMuchBeamTimeDigi>(dSeedTime, *det);
394 SearchMatches<CbmTrdDigi>(dSeedTime, *det);
398 SearchMatches<CbmTofDigi>(dSeedTime, *det);
402 SearchMatches<CbmRichDigi>(dSeedTime, *det);
406 SearchMatches<CbmPsdDigi>(dSeedTime, *det);
410 SearchMatches<CbmTofDigi>(dSeedTime, *det);
414 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
415 <<
"Trying to search matches with unsupported det: "
416 << (*det).sName << std::endl
417 <<
"You may want to add support for it in the method.";
436 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
439 (*det).fuStartIndex = (*det).fuEndIndex;
444 LOG(debug1) <<
"Reject seed due to Trigger requirements";
450 template<
class DigiCheck>
464 for (UInt_t uDigi = detMatch.
fuStartIndex; uDigi < uNbSelDigis; ++uDigi) {
465 Double_t dTime =
fT0DigiVec->at(uDigi).GetTime();
467 Double_t dTimeDiff = dTime - dSeedTime;
477 uLocalIndexEnd = uDigi;
487 if (uLocalIndexEnd < uLocalIndexStart) uLocalIndexEnd = uNbSelDigis;
490 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SearchMatches => "
491 <<
"T0 as selection detector but vector not found!";
498 for (UInt_t uDigi = detMatch.
fuStartIndex; uDigi < uNbSelDigis; ++uDigi) {
499 const DigiCheck* pDigi =
fDigiMan->
Get<DigiCheck>(uDigi);
501 if (
nullptr != pDigi) {
502 Double_t dTime = pDigi->GetTime();
503 Double_t dTimeDiff = dTime - dSeedTime;
505 LOG(debug4) << detMatch.
sName
506 << Form(
" => Checking match %6u / %6u, dt %f",
519 uLocalIndexEnd = uDigi;
530 if (uLocalIndexEnd < uLocalIndexStart) uLocalIndexEnd = uNbSelDigis;
551 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
573 LOG(warning) <<
"Event does not have digis storage for T0"
574 <<
" while the following trigger minimum are defined: "
581 LOG(warning) <<
"Event does not have digis storage for " << det.
sName
582 <<
" while the following trigger min/max are defined: "
589 Int_t iNbDigis =
event->GetNofData(det.
dataType);
595 LOG(debug2) <<
"Event does not have enough digis: " << iNbDigis <<
" vs "
605 LOG(debug2) <<
"Event Has too many digis: " << iNbDigis <<
" vs "
615 "seed time of the events; Seed time [s]; Events",
618 "interval in seed time of consecutive events; Seed time [s]; Events",
619 2100, -100.5, 1999.5);
621 new TH1F(
"hEventSize",
622 "nb of all digis in the event; Nb Digis []; Events []",
625 new TH2I(
"hNbDigiPerEvtTime",
626 "nb of all digis per event vs seed time of the events; Seed time "
627 "[s]; Nb Digis []; Events []",
632 for (std::vector< EventBuilderDetector >::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
634 if(
"Invalid" == (*det).sName )
641 new TH2I( Form(
"hNbDigiPerEvtTime%s", (*det).sName.data() ),
642 Form(
"nb of %s digis per event vs seed time of the events; Seed time "
643 "[s]; Nb Digis []; Events []",
644 (*det).sName.data() ),
656 if(
nullptr != (*itHist) )
666 Double_t dPreEvtTime = -1.0;
669 if (0.0 <= dPreEvtTime) {
670 fhEventDt->Fill(evt->GetStartTime() - dPreEvtTime);
676 for (UInt_t uDetIdx = 0; uDetIdx <
fvDets.size(); ++uDetIdx) {
680 evt->GetStartTime() * 1e-9, evt->GetNofData(
fvDets[uDetIdx].dataType));
683 dPreEvtTime = evt->GetStartTime();
713 UInt_t uTriggerMinDigisIn,
714 Int_t iTriggerMaxDigisIn,
715 Double_t fdTimeWinBegIn,
716 Double_t fdTimeWinEndIn) {
730 UInt_t uTriggerMinDigisIn,
731 Int_t iTriggerMaxDigisIn,
732 Double_t fdTimeWinBegIn,
733 Double_t fdTimeWinEndIn) {
778 <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetReferenceDetector => "
779 <<
"Trying to change reference to unsupported det: " << refDet
781 <<
"This method is deprecated and will be removed soon, "
782 <<
"please use the full version of it.";
788 <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetReferenceDetector => "
789 <<
"Changing reference detector with deprecated method to: "
791 <<
"This method is deprecated, does not set all parameters "
792 <<
"and will be removed soon, please use the full version of it.";
825 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::AddDetector => "
826 <<
"Trying to change reference to unsupported det: " << selDet
828 <<
"This method is deprecated and will be removed soon, "
829 <<
"please use the full version of it.";
835 <<
"CbmMcbm2019TimeWinEventBuilderAlgo::AddDetector => "
836 <<
"Changing reference detector with deprecated method for: " << selDet
838 <<
"This method is deprecated, does not set all parameters "
839 <<
"and will be removed soon, please use the full version of it.";
844 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
847 if ((*det).detId == selDet) {
852 LOG(warning) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::RemoveDetector => Doing "
853 "nothing, selection detector not in list!"
860 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
863 if ((*det) == refDetIn) {
865 <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetReferenceDetector => "
866 "Reference detector already in selection detector list!"
870 "It will be automatically removed from selection detector list!";
873 "Please also remember to update the selection windows to store "
881 <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetReferenceDetector => "
882 "Doing nothing, identical reference detector already in use";
885 LOG(info) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetReferenceDetector => "
887 <<
" as reference detector";
890 "You may want to use AddDetector after this command to add in "
895 "Please also remember to update the selection windows!";
907 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::AddDetector => Cannot "
908 "add the reference detector as selection detector!"
910 <<
"=> Maybe first change the reference detector with "
911 "SetReferenceDetector?";
915 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
918 if ((*det) == selDet) {
919 LOG(warning) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::AddDetector => "
920 "Doing nothing, selection detector already in list!"
935 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
938 if ((*det) == selDet) {
943 LOG(warning) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::RemoveDetector => Doing "
944 "nothing, selection detector not in list!"
955 LOG(debug) <<
"Set Trigger min limit for " <<
fRefDet.
sName <<
" to "
962 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
965 if ((*det).detId == selDet) {
966 (*det).fuTriggerMinDigis = uVal;
968 LOG(debug) <<
"Set Trigger min limit for " << (*det).sName <<
" to "
976 <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerMinNumber => "
977 "Doing nothing, detector neither reference nor in selection list!"
987 LOG(debug) <<
"Set Trigger min limit for " <<
fRefDet.
sName <<
" to "
994 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
997 if ((*det).detId == selDet) {
998 (*det).fiTriggerMaxDigis = iVal;
1000 LOG(debug) <<
"Set Trigger min limit for " << (*det).sName <<
" to "
1008 <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerMaxNumber => "
1009 "Doing nothing, detector neither reference nor in selection list!"
1016 if (dWinEnd <= dWinBeg)
1017 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerWindow => "
1018 "Invalid time window: [ "
1019 << dWinBeg <<
", " << dWinEnd <<
" ]";
1021 Bool_t bFound = kFALSE;
1031 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
1034 if ((*det).detId == selDet) {
1035 (*det).fdTimeWinBeg = dWinBeg;
1036 (*det).fdTimeWinEnd = dWinEnd;
1042 if (kFALSE == bFound) {
1044 <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerWindow => "
1045 "Doing nothing, detector neither reference nor in selection list!"
1060 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();
1072 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin();