21#include "FairRootManager.h"
22#include "FairRunOnline.h"
27#include "TClonesArray.h"
30#include "THttpServer.h"
43 LOG(info) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::InitAlgo => Starting sequence";
46 FairRootManager* ioman = FairRootManager::Instance();
55 LOG(fatal) <<
"No digi input for reference detector, stopping there!";
59 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
61 LOG(fatal) <<
"No digi input for one of selection detector, stopping there!";
69 LOG(fatal) <<
"No TS metadata input found"
70 <<
" => Please check in the unpacking macro if the following line was "
73 <<
"source->SetWriteOutputFlag(kTRUE); // For writing TS metadata";
79 LOG(info) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::InitAlgo => Done";
87 LOG_IF(info,
fuNrTs % 1000 == 0) <<
"Begin of TS " <<
fuNrTs;
105 LOG(debug) <<
"Found " <<
fEventVector.size() <<
" triggered events";
116 LOG(debug) <<
"Event " <<
counter <<
" has " <<
event->GetNofData() <<
" digis";
130 FairRootManager* ioman = FairRootManager::Instance();
134 fBmonDigiVec = ioman->InitObjectAs<std::vector<CbmTofDigi>
const*>(
"BmonDigi");
136 LOG(info) <<
"No Bmon digi input found.";
142 LOG(info) <<
"No " << det.
sName <<
" digi input found.";
157 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
158 (*det).fuStartIndex = 0;
159 (*det).fuEndIndex = 0;
199 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::BuildEvents => "
200 <<
"Trying to search event seeds with unsupported det: " <<
fRefDet.
sName;
206template<
class DigiSeed>
216 LOG(fatal) << Form(
"CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
217 "No TS metadata found for TS %6u.",
227 LOG(warning) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
228 << Form(
"Event window not fitting in TS overlap, risk of "
229 "incomplete events: %f %f %f %f",
239 dSeedWindowEnd = dOverlapStart;
247 for (UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi) {
248 LOG(debug) << Form(
"Checking seed %6u / %6u", uDigi, uNbRefDigis);
257 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
258 <<
"Bmon as reference detector but vector not found!";
263 for (UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi) {
264 LOG(debug) << Form(
"Checking seed %6u / %6u", uDigi, uNbRefDigis);
265 const DigiSeed* pDigi =
fDigiMan->
Get<DigiSeed>(uDigi);
267 if (
nullptr != pDigi) {
268 Double_t dTime = pDigi->GetTime();
271 if (dTime < dSeedWindowBeg) {
continue; }
272 else if (dSeedWindowEnd < dTime) {
294 LOG(debug1) <<
"Reject seed due to overlap";
305 LOG(debug1) <<
"Reject seed because part of cluster of previous one";
362 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
363 <<
"Trying to search matches with unsupported det: " <<
fRefDet.
sName << std::endl
364 <<
"You may want to add support for it in the method.";
377 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
378 switch ((*det).detId) {
413 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
414 <<
"Trying to search matches with unsupported det: " << (*det).sName << std::endl
415 <<
"You may want to add support for it in the method.";
433 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
434 (*det).fuStartIndex = (*det).fuEndIndex;
439 LOG(debug1) <<
"Reject seed due to Trigger requirements";
445template<
class DigiCheck>
458 for (UInt_t uDigi = detMatch.
fuStartIndex; uDigi < uNbSelDigis; ++uDigi) {
461 Double_t dTimeDiff = dTime - dSeedTime;
471 uLocalIndexEnd = uDigi;
481 if (uLocalIndexEnd < uLocalIndexStart) uLocalIndexEnd = uNbSelDigis;
484 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SearchMatches => "
485 <<
"Bmon as selection detector but vector not found!";
490 for (UInt_t uDigi = detMatch.
fuStartIndex; uDigi < uNbSelDigis; ++uDigi) {
491 const DigiCheck* pDigi =
fDigiMan->
Get<DigiCheck>(uDigi);
493 if (
nullptr != pDigi) {
494 Double_t dTime = pDigi->GetTime();
495 Double_t dTimeDiff = dTime - dSeedTime;
497 LOG(debug4) << detMatch.
sName << Form(
" => Checking match %6u / %6u, dt %f", uDigi, uNbSelDigis, dTimeDiff);
507 uLocalIndexEnd = uDigi;
518 if (uLocalIndexEnd < uLocalIndexStart) uLocalIndexEnd = uNbSelDigis;
539 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
558 LOG(warning) <<
"Event does not have digis storage for Bmon"
559 <<
" while the following trigger minimum are defined: " << det.
fuTriggerMinDigis <<
" "
566 LOG(warning) <<
"Event does not have digis storage for " << det.
sName
567 <<
" while the following trigger min/max are defined: " << det.
fuTriggerMinDigis <<
" "
574 Int_t iNbDigis =
event->GetNofData(det.
dataType);
575 if ((-1 == iNbDigis) || (
static_cast<UInt_t
>(iNbDigis) < det.
fuTriggerMinDigis)) {
576 LOG(debug2) <<
"Event does not have enough digis: " << iNbDigis <<
" vs " << det.
fuTriggerMinDigis <<
" for "
582 LOG(debug2) <<
"Event Has too many digis: " << iNbDigis <<
" vs " << det.
fiTriggerMaxDigis <<
" for " << det.
sName;
595 "seed time of the events; Seed time [s]; Events",
598 "interval in seed time of consecutive events; Seed time [s]; Events",
599 2100, -100.5, 1999.5);
601 new TH1F(
"hEventSize",
602 "nb of all digis in the event; Nb Digis []; Events []",
605 new TH2I(
"hNbDigiPerEvtTime",
606 "nb of all digis per event vs seed time of the events; Seed time "
607 "[s]; Nb Digis []; Events []",
612 for (std::vector< EventBuilderDetector >::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
614 if(
"Invalid" == (*det).sName )
621 new TH2I( Form(
"hNbDigiPerEvtTime%s", (*det).sName.data() ),
622 Form(
"nb of %s digis per event vs seed time of the events; Seed time "
623 "[s]; Nb Digis []; Events []",
624 (*det).sName.data() ),
636 if(
nullptr != (*itHist) )
647 Double_t dPreEvtTime = -1.0;
650 if (0.0 <= dPreEvtTime) {
fhEventDt->Fill(evt->GetStartTime() - dPreEvtTime); }
655 for (UInt_t uDetIdx = 0; uDetIdx <
fvDets.size(); ++uDetIdx) {
661 dPreEvtTime = evt->GetStartTime();
682 } // if( kTRUE == bResetTime )
687 std::string sNameIn, UInt_t uTriggerMinDigisIn,
688 Int_t iTriggerMaxDigisIn, Double_t fdTimeWinBegIn,
689 Double_t fdTimeWinEndIn)
694 fdTimeWinBegIn, fdTimeWinEndIn));
697 UInt_t uTriggerMinDigisIn, Int_t iTriggerMaxDigisIn,
698 Double_t fdTimeWinBegIn, Double_t fdTimeWinEndIn)
710 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
711 if ((*det) == refDetIn) {
712 LOG(warning) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetReferenceDetector => "
713 "Reference detector already in selection detector list!"
715 LOG(warning) <<
" => "
716 "It will be automatically removed from selection detector list!";
717 LOG(warning) <<
" => "
718 "Please also remember to update the selection windows to store "
726 LOG(warning) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetReferenceDetector => "
727 "Doing nothing, identical reference detector already in use";
730 LOG(info) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetReferenceDetector => "
731 <<
"Replacing " <<
fRefDet.
sName <<
" with " << refDetIn.
sName <<
" as reference detector";
732 LOG(warning) <<
" => "
733 "You may want to use AddDetector after this command to add in "
736 LOG(warning) <<
" => "
737 "Please also remember to update the selection windows!";
749 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::AddDetector => Cannot "
750 "add the reference detector as selection detector!"
752 <<
"=> Maybe first change the reference detector with "
753 "SetReferenceDetector?";
757 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
758 if ((*det) == selDet) {
759 LOG(warning) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::AddDetector => "
760 "Doing nothing, selection detector already in list!"
775 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
776 if ((*det) == selDet) {
781 LOG(warning) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::RemoveDetector => Doing "
782 "nothing, selection detector not in list!"
792 LOG(debug) <<
"Set Trigger min limit for " <<
fRefDet.
sName <<
" to " << uVal;
798 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
799 if ((*det).detId == selDet) {
800 (*det).fuTriggerMinDigis = uVal;
802 LOG(debug) <<
"Set Trigger min limit for " << (*det).sName <<
" to " << uVal;
808 LOG(warning) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerMinNumber => "
809 "Doing nothing, detector neither reference nor in selection list!"
818 LOG(debug) <<
"Set Trigger min limit for " <<
fRefDet.
sName <<
" to " << iVal;
824 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
825 if ((*det).detId == selDet) {
826 (*det).fiTriggerMaxDigis = iVal;
828 LOG(debug) <<
"Set Trigger min limit for " << (*det).sName <<
" to " << iVal;
834 LOG(warning) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerMaxNumber => "
835 "Doing nothing, detector neither reference nor in selection list!"
841 if (dWinEnd <= dWinBeg)
842 LOG(fatal) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerWindow => "
843 "Invalid time window: [ "
844 << dWinBeg <<
", " << dWinEnd <<
" ]";
846 Bool_t bFound = kFALSE;
856 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
857 if ((*det).detId == selDet) {
858 (*det).fdTimeWinBeg = dWinBeg;
859 (*det).fdTimeWinEnd = dWinEnd;
865 if (kFALSE == bFound) {
866 LOG(warning) <<
"CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerWindow => "
867 "Doing nothing, detector neither reference nor in selection list!"
883 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
894 for (std::vector<EventBuilderDetector>::iterator det =
fvDets.begin(); det !=
fvDets.end(); ++det) {
ClassImp(CbmConverterManager)
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kMuch
Muon detection system.
@ kRich
Ring-Imaging Cherenkov Detector.
static double dTsStartTime
static Int_t GetNofDigis(ECbmModuleId systemId)
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
void UseMuchBeamTimeDigi(Bool_t)
Use CbmMuchBeamTimeDigi instead of CbmMuchDigi for MUCH.
InitStatus Init()
Initialisation.
const Digi * Get(Int_t index) const
Get a digi object.
static CbmDigiManager * Instance()
Static instance.
Class characterising one event by a collection of links (indices) to data objects,...
void AddData(ECbmDataType type, uint32_t index)
void SetEndTime(double endTime)
CbmMcbm2019TimeWinEventBuilderAlgo()
CBM headers.
Double_t fdPrevEvtTime
Timeslice Counter.
TH2 * fhNbDigiPerEvtTime
histogram with the nb of all digis in the event
UInt_t fuErrors
Event Counter.
void CheckSeed(Double_t dSeedTime, UInt_t uSeedDigiIdx)
Double_t fdWidestTimeWinRange
std::vector< EventBuilderDetector > fvDets
const TimesliceMetaData * pTsMetaData
EventBuilderDetector fRefDet
void ResetHistograms(Bool_t bResetTime=kTRUE)
void SetTriggerWindow(ECbmModuleId selDet, Double_t dWinBeg, Double_t dWinEnd)
UInt_t fuNrTs
Error Counter.
void AddDigiToEvent(EventBuilderDetector &det, Int_t uIdx)
const std::vector< CbmTofDigi > * fBmonDigiVec
void UpdateTimeWinBoundariesExtrema()
TH1 * fhEventSize
histogram with the interval in seed time of consecutive events
Bool_t CheckDataAvailable(EventBuilderDetector &det)
Internal methods.
void SetTriggerMinNumber(ECbmModuleId selDet, UInt_t uVal)
Bool_t fbFillHistos
Ignore data in Overlap part of the TS.
Double_t fdEarliestTimeWinBeg
Bool_t fbUseMuchBeamtimeDigi
Switch ON/OFF filling of histograms.
Double_t fdLatestTimeWinEnd
EOverlapMode fOverMode
Event building mode and detectors selection.
void UpdateWidestTimeWinRange()
CbmDigiManager * fDigiMan
std::vector< TH2 * > fvhNbDigiPerEvtTimeDet
histogram with the nb of all digis per event vs seed time of the events
void SetReferenceDetector(ECbmModuleId refDet, ECbmDataType dataTypeIn, std::string sNameIn, UInt_t uTriggerMinDigisIn=0, Int_t iTriggerMaxDigisIn=-1, Double_t fdTimeWinBegIn=-100, Double_t fdTimeWinEndIn=100)
TClonesArray * fTimeSliceMetaDataArray
void AddDetector(ECbmModuleId selDet, ECbmDataType dataTypeIn, std::string sNameIn, UInt_t uTriggerMinDigisIn=0, Int_t iTriggerMaxDigisIn=-1, Double_t fdTimeWinBegIn=-100, Double_t fdTimeWinEndIn=100)
void AddHistoToVector(TNamed *pointer, std::string sFolder="")
For monitor algos.
UInt_t fuCurEv
histograms with the nb of digis in each detector per event vs seed time of the events
Bool_t HasTrigger(CbmEvent *)
~CbmMcbm2019TimeWinEventBuilderAlgo()
TH1 * fhEventDt
histogram with the seed time of the events
std::vector< CbmEvent * > fEventVector
pointer to the event which is currently build
CbmEvent * fCurrentEvent
Data ouptut.
Bool_t CheckTriggerConditions(CbmEvent *event, EventBuilderDetector &det)
Double_t fdPrevEvtEndTime
Save previous time information.
void SearchMatches(Double_t dSeedTime, EventBuilderDetector &detMatch)
TH1 * fhEventTime
Vector of pointers to canvases + optional folder name.
void RemoveDetector(EventBuilderDetector selDet)
void SetTriggerMaxNumber(ECbmModuleId selDet, Int_t iVal)
Int_t fiTriggerMaxDigis
Maximum number of digis per detector to generate an event, -1 means no cut, 0 means anti-coinc trigge...
Double_t GetTimeWinRange()
UInt_t fuTriggerMinDigis
Minimum number of Bmon digis needed to generate a trigger, 0 means don't use for trigger generation.
ECbmModuleId detId
Settings.
UInt_t fuStartIndex
Book-keeping variables.
Double_t fdTimeWinBeg
Selection Window.