13#include <FairRootManager.h>
14#include <FairRunOnline.h>
18#include <TClonesArray.h>
23#include <THttpServer.h>
24#include <TStopwatch.h>
86 if (bFlagIn == kTRUE) {
88 std::cout <<
"SetSeedFinderQa(): Cannot activate Qa when seed finder not active. Exiting." << std::endl;
110 LOG(info) <<
"No " << detName <<
" digi input.";
113 LOG(info) << detName <<
" digi input.";
114 *vDigi =
new std::vector<TDigi>;
129 FairRootManager* ioman = FairRootManager::Instance();
155 if (
fbUseMuchBeamtimeDigi) LOG(fatal) <<
"DigiEvent output branch not compatible with MuchBeamtimeDigi";
158 ioman->RegisterAny(
"DigiEvent",
fDigiEvents, kTRUE);
159 if (!
fDigiEvents) LOG(fatal) <<
"Output branch was not created";
160 LOG(info) <<
"DigiEvent out instead of CbmEvent, you will need an instance of CbmTaskMakeRecoEvents in reco macro";
162 LOG(info) <<
"Exclusive TRD extraction, DigiEvents will be comparable to CbmEvents but slower";
165 LOG(info) <<
"Inclusive TRD extraction, faster but DigiEvents will noy be comparable to CbmEvents (extra digis)";
169 fEvents =
new TClonesArray(
"CbmEvent", 100);
170 ioman->Register(
"CbmEvent",
"Cbm_Event",
fEvents, IsOutputBranchPersistent(
"CbmEvent"));
171 if (!
fEvents) LOG(fatal) <<
"Output branch was not created";
172 LOG(info) <<
"CbmEvent oupput, you will need an instance of CbmTaskEventsCloneInToOut in reco macro to update them";
180 Double_t rtime =
fTimer->RealTime();
181 Double_t ctime =
fTimer->CpuTime();
182 LOG(info) <<
"CbmTaskBuildRawEvents::Init(): Real time " << rtime <<
" s, CPU time " << ctime <<
" s";
215 for (Int_t i = 0; i < nDigis; i++) {
217 vDigis->push_back(*Digi);
219 LOG(debug) <<
"Read: " << vDigis->size() <<
" " << detName <<
" digis.";
220 LOG(debug) <<
"In DigiManager: " << nDigis <<
" " << detName <<
" digis.";
235 LOG(debug2) <<
"CbmTaskBuildRawEvents::Exec => Starting sequence";
245 std::stringstream logOut;
246 logOut << std::setw(20) << std::left << GetName() <<
" [";
247 logOut << std::fixed << std::setw(8) << std::setprecision(1) << std::right << timer.RealTime() * 1000. <<
" ms] ";
248 logOut <<
"TS " <<
fNofTs;
254 logOut <<
", events " <<
fEvents->GetEntriesFast();
257 LOG(info) << logOut.str();
260 LOG(info) << seedCount <<
" trigger(s) for this TS.";
264 fTime += timer.RealTime();
266 LOG(debug2) <<
"CbmTaskBuildRawEvents::Exec => Done";
308 std::vector<CbmMatch>* vDigiMatch)
310 std::map<ECbmModuleId, UInt_t> DigiNumbers;
311 std::map<ECbmModuleId, UInt_t> DigiCounters;
312 vdSeedTimes->clear();
314 if (vDigiMatch !=
nullptr) vDigiMatch->clear();
317 DigiNumbers[system.detId] =
GetNofDigis(system.detId);
318 DigiCounters[system.detId] = 0;
323 Double_t earliestTime = -1;
326 if (DigiCounters[system.detId] < DigiNumbers[system.detId]) {
328 Double_t thisTime =
GetDigiTime(system.detId, DigiCounters[system.detId]);
329 if (thisTime < earliestTime || earliestTime == -1) {
330 nextAddedSystem = system.detId;
331 earliestTime = thisTime;
335 if (earliestTime != -1) {
337 if (vDigiMatch !=
nullptr) {
339 vDigiMatch->push_back(*digiMatch);
341 vdSeedTimes->push_back(earliestTime);
342 DigiCounters[nextAddedSystem]++;
358 std::cout <<
"FillSeedTimesFromSlidingWindow(): Error, seed detector list empty." << std::endl;
379 std::cout <<
"FillSeedTimesFromSlidingWindow(): Error, QA set but no CbmMatch found for seed detector."
390 switch (seedDet->
detId) {
458 LOG(fatal) <<
"Trying to print timings but timer not set";
461 Double_t rtime =
fTimer->RealTime();
462 Double_t ctime =
fTimer->CpuTime();
463 LOG(info) <<
"CbmTaskBuildRawEvents: Real time " << rtime <<
" s, CPU time " << ctime <<
" s";
466 LOG(fatal) <<
"Trying to print timings but timer not set";
471 LOG(info) <<
"CbmTaskBuildRawEvents (digi copy only): Real time " << rtime <<
" s, CPU time " << ctime <<
" s";
490 std::cout << std::endl;
491 LOG(info) <<
"=====================================";
492 LOG(info) << GetName() <<
": Run summary";
493 LOG(info) <<
"Time slices : " <<
fNofTs;
498 LOG(info) <<
"Time / TS : " << std::fixed << std::setprecision(2) << 1000. *
fTime / Double_t(
fNofTs)
500 LOG(info) <<
"=====================================";
521 LOG(debug) <<
"Vector: " <<
event->ToString();
522 new ((*fEvents)[
fEvents->GetEntriesFast()])
CbmEvent(std::move(*event));
533 if (!FairRootManager::Instance() || !FairRootManager::Instance()->GetSink()) {
534 LOG(error) <<
"No sink found";
537 FairSink* sink = FairRootManager::Instance()->GetSink();
546 TDirectory* oldDir = NULL;
547 TFile* histoFile = NULL;
555 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
557 const TString sFolder = vHistos[uHisto].second.data();
558 if (
nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
559 gDirectory->cd(sFolder);
562 vHistos[uHisto].first->Write();
570 for (UInt_t uCanvas = 0; uCanvas < vCanvases.size(); ++uCanvas) {
572 TString sFolder = vCanvases[uCanvas].second.data();
573 if (
nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
574 gDirectory->cd(sFolder);
577 vCanvases[uCanvas].first->Write();
590 std::ofstream timesUnsorted(
"digiTimesUnsorted.dat", std::ofstream::out);
591 timesUnsorted << std::setprecision(16);
594 for (UInt_t i = 0; i <
GetNofDigis(system.detId); i++) {
595 timesUnsorted <<
GetDigiTime(system.detId, i) << std::endl;
598 timesUnsorted.close();
599 LOG(info) <<
"Completed write of unsorted digi list.";
601 std::ofstream timesSorted(
"digiTimesSorted.dat", std::ofstream::out);
602 timesSorted << std::setprecision(16);
604 for (UInt_t i = 0; i <
fSeedTimes->size(); i++) {
605 timesSorted <<
fSeedTimes->at(i) << std::endl;
608 LOG(info) <<
"Completed DumpSeedTimesFromDetList(). Closing.";
615 LOG(debug) <<
"In Vector size: " << vEvents.size();
620 selEvent.
fTime =
event->GetStartTime();
621 selEvent.
fNumber =
event->GetNumber();
625 event->SortIndices();
661 for (uint32_t uDigiInEvt = 0; uDigiInEvt < uNbDigis; ++uDigiInEvt) {
ClassImp(CbmConverterManager)
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kMuch
Muon detection system.
@ kFsd
Forward spectator detector.
@ kRich
Ring-Imaging Cherenkov Detector.
Class for sliding window seed finder.
void SetTimeSliceMetaDataArray(TClonesArray *TimeSliceMetaDataArray)
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
std::vector< std::pair< TCanvas *, std::string > > GetCanvasVector()
void SetSeedTimes(std::vector< Double_t > *SeedTimes)
TDirectoryFile * GetOutFolder()
std::vector< CbmEvent * > & GetEventVector()
Data output access.
void SetDigis(std::vector< CbmBmonDigi > *BmonDigis)
Set digi containers.
std::vector< CbmBmonDigi > fDigis
Data vector.
CbmPsdDigiData fPsd
PSD data.
CbmTrdDigiData fTrd
TRD data.
CbmTofDigiData fTof
TOF data.
CbmStsDigiData fSts
STS data.
CbmRichDigiData fRich
RICH data.
CbmMuchDigiData fMuch
MUCH data.
CbmBmonDigiData fBmon
Beam monitor data.
Collection of digis from all detector systems within one event.
double fTime
Event trigger time [ns].
CbmDigiData fData
Event data.
uint64_t fNumber
Event identifier.
static Int_t GetNofDigis(ECbmModuleId systemId)
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
static Bool_t IsMatchPresent(ECbmModuleId systemId)
Presence of a digi match 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.
const CbmMatch * GetMatch(ECbmModuleId systemId, UInt_t index) const
Get a match object.
Class characterising one event by a collection of links (indices) to data objects,...
std::string ToString() const
static TString GetModuleNameCaps(ECbmModuleId moduleId)
std::vector< CbmMuchDigi > fDigis
Data vector.
std::vector< CbmPsdDigi > fDigis
Data vector.
std::vector< CbmRichDigi > fDigis
Data vector.
void SetIdealMode(const int32_t fileId=-1)
Switches to `‘ideal mode’' in which event times from MC data are used as triggers (no algorithm is ru...
bool IsIdealMode()
Is `‘ideal mode’' switched on?
void OutputQa()
Output QA Information.
void SetOffset(double offset)
Sets a global constant offset which is applied to each trigger time @params Value of offset.
size_t GetNofSeeds()
Returns number of seed times currently stored in buffer.
void SetQa(bool doQA=true)
Enable or disable the generation of QA information.
void FillSeedTimes(const std::vector< inType > *vIn, const std::vector< CbmMatch > *vDigiMatch=nullptr)
Function which builds event seeds @params Vector of input data (either digis or digi times)....
void Init()
Initializes QA object if set.
std::vector< CbmStsDigi > fDigis
Data vector.
Bool_t fbExclusiveTrdExtraction
Bool_t fbUseMuchBeamtimeDigi
void SetSeedFinderQa(Bool_t bFlagIn=kTRUE)
CbmAlgoBuildRawEvents * fpAlgo
timing only for filling of std::vector<Digi> fields
void SetSlidingWindowSeedFinder(int32_t minDigis, double dWindDur, double dDeadT, double dOffset=0.0)
UInt_t GetNofDigis(ECbmModuleId _system)
CbmDigiManager * fDigiMan
void ReadDigis(ECbmModuleId detId, std::vector< TDigi > *vDigis)
virtual InitStatus Init()
std::vector< CbmMuchBeamTimeDigi > * fMuchBeamTimeDigis
std::vector< CbmStsDigi > * fStsDigis
void FillSeedTimesFromSlidingWindow()
std::vector< CbmDigiEvent > * fDigiEvents
output container of CbmEvents
std::vector< CbmPsdDigi > * fPsdDigis
TStopwatch * fCopyTimer
is created when fbGetTimings is set before init
std::vector< Double_t > * fTempDigiTimes
Bool_t fbWriteHistosToFairSink
Switch ON/OFF filling of histograms.
TString fsOutFileName
Measure CPU time using stopwatch.
std::vector< CbmTrdDigi > * fTrdDigis
TClonesArray * fEvents
Enable/disabled loop based extraction of TRD digis due to 1D/2D.
std::vector< CbmTofDigi > * fTofDigis
CbmSeedFinderSlidingWindow * fSeedFinderSlidingWindow
Switch between MUCH digi classes.
std::vector< CbmMatch > * fvDigiMatchQa
std::vector< Double_t > * fSeedTimes
void ExtractSelectedData(std::vector< CbmEvent * > vEvents)
output container of CbmEvents
Bool_t fbGetTimings
Write histos to FairRootManager instead of separate file.
void InitDigis(ECbmModuleId detId, std::vector< TDigi > **vDigi)
virtual InitStatus ReInit()
std::vector< CbmMuchDigi > * fMuchDigis
virtual void Exec(Option_t *)
std::vector< RawEventBuilderDetector > fSeedTimeDetList
void AddSeedTimeFillerToList(RawEventBuilderDetector seedDet)
void SetIdealSeedFinder(const int32_t fileId=-1)
std::vector< CbmRichDigi > * fRichDigis
void DumpSeedTimesFromDetList()
Double_t GetDigiTime(ECbmModuleId _system, UInt_t _entry)
void FillSeedTimesFromDetList(std::vector< Double_t > *vdSeedTimes, std::vector< CbmMatch > *vDigiMatch=nullptr)
std::vector< CbmBmonDigi > * fBmonDigis
std::vector< CbmFsdDigi > * fFsdDigis
std::vector< CbmTofDigi > fDigis
Data vector.
std::vector< CbmTrdDigi > fDigis
Data vector.
ECbmModuleId detId
Settings.