CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2019TimeWinEventBuilderAlgo.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
6
8#include "CbmDigiManager.h"
9#include "CbmEvent.h"
10#include "CbmMuchBeamTimeDigi.h"
11#include "CbmMuchDigi.h"
12#include "CbmPsdDigi.h"
13#include "CbmRichDigi.h"
14#include "CbmStsDigi.h"
15#include "CbmTofDigi.h"
16#include "CbmTrdDigi.h"
17
18#include "TimesliceMetaData.h"
19
21#include "FairRootManager.h"
22#include "FairRunOnline.h"
23#include <Logger.h>
24
26#include "TCanvas.h"
27#include "TClonesArray.h"
28#include "TH1.h"
29#include "TH2.h"
30#include "THttpServer.h"
31
33
34// ---- Default constructor --------------------------------------------
36
37// ---- Destructor -----------------------------------------------------
39
40// ---- Init -----------------------------------------------------------
42{
43 LOG(info) << "CbmMcbm2019TimeWinEventBuilderAlgo::InitAlgo => Starting sequence";
44
45 // Get a handle from the IO manager
46 FairRootManager* ioman = FairRootManager::Instance();
47
48 // Get a pointer to the previous already existing data level
50 if (fbUseMuchBeamtimeDigi) { fDigiMan->UseMuchBeamTimeDigi(); } // if (fbUseMuchBeamtimeDigi)
51 fDigiMan->Init();
52
54 if (kFALSE == CheckDataAvailable(fRefDet)) {
55 LOG(fatal) << "No digi input for reference detector, stopping there!";
56 } // if( kFALSE == CheckDataAvailable( fRefDet ) )
57
59 for (std::vector<EventBuilderDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
60 if (kFALSE == CheckDataAvailable(*det)) {
61 LOG(fatal) << "No digi input for one of selection detector, stopping there!";
62 } // if( kFALSE == CheckDataAvailable( *det ) )
63 } // for (std::vector<EventBuilderDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det)
64
66 if (fdTsStartTime < 0 || fdTsLength < 0 || fdTsOverLength < 0) {
67 fTimeSliceMetaDataArray = dynamic_cast<TClonesArray*>(ioman->GetObject("TimesliceMetaData"));
69 LOG(fatal) << "No TS metadata input found"
70 << " => Please check in the unpacking macro if the following line was "
71 "present!"
72 << std::endl
73 << "source->SetWriteOutputFlag(kTRUE); // For writing TS metadata";
74 } // if (!fTimeSliceMetaDataArray)
75 } // if ( fdTsStartTime < 0 || fdTsLength < 0 || fdTsOverLength < 0 )
76
77 if (fbFillHistos) { CreateHistograms(); } // if( fbFillHistos )
78
79 LOG(info) << "CbmMcbm2019TimeWinEventBuilderAlgo::InitAlgo => Done";
80
81 return kTRUE;
82}
83
84// ---- ProcessTs ------------------------------------------------------
86{
87 LOG_IF(info, fuNrTs % 1000 == 0) << "Begin of TS " << fuNrTs;
88
89 InitTs();
90
92
94 if (nullptr != fCurrentEvent) {
96 // fCurrentEvent->SetStartTime( fPrevTime ); // Replace Seed time with time of first digi in event?
98 fEventVector.push_back(fCurrentEvent);
99 fuCurEv++;
100
102 fCurrentEvent = nullptr;
103 } // if( nullptr != fCurrentEvent )
104
105 LOG(debug) << "Found " << fEventVector.size() << " triggered events";
106
107 if (fbFillHistos) { FillHistos(); } // if( fbFillHistos )
108
109 fuNrTs++;
110}
112{
114 int counter = 0;
115 for (CbmEvent* event : fEventVector) {
116 LOG(debug) << "Event " << counter << " has " << event->GetNofData() << " digis";
117 delete event;
118 counter++;
119 } // for( CbmEvent* event: fEventVector)
120
121 fEventVector.clear();
122}
123// ---- Finish ---------------------------------------------------------
124void CbmMcbm2019TimeWinEventBuilderAlgo::Finish() { LOG(info) << "Total errors: " << fuErrors; }
125
126// ---------------------------------------------------------------------
128{
129 // Get a handle from the IO manager
130 FairRootManager* ioman = FairRootManager::Instance();
131
132 if (ECbmModuleId::kBmon == det.detId) {
133 // Bmon is not included in DigiManager
134 fBmonDigiVec = ioman->InitObjectAs<std::vector<CbmTofDigi> const*>("BmonDigi");
135 if (!fBmonDigiVec) {
136 LOG(info) << "No Bmon digi input found.";
137 return kFALSE;
138 } // if( ! fBmonDigiVec )
139 } // if( ECbmModuleId::kBmon == det.detId )
140 else {
141 if (!fDigiMan->IsPresent(det.detId)) {
142 LOG(info) << "No " << det.sName << " digi input found.";
143 return kFALSE;
144 } // if( ! fDigiMan->IsPresent(ECbmModuleId::kSts) )
145 } // else of if( ECbmModuleId::kBmon == det.detId )
146
147 return kTRUE;
148}
149// ---------------------------------------------------------------------
151{
157 for (std::vector<EventBuilderDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
158 (*det).fuStartIndex = 0;
159 (*det).fuEndIndex = 0;
160 } // for (std::vector<EventBuilderDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det)
161}
162
164{
166 switch (fRefDet.detId) {
167 case ECbmModuleId::kSts: {
169 break;
170 } // case ECbmModuleId::kSts:
171 case ECbmModuleId::kMuch: {
172 if (fbUseMuchBeamtimeDigi) { LoopOnSeeds<CbmMuchBeamTimeDigi>(); } // if (fbUseMuchBeamtimeDigi)
173 else {
175 } // else of if (fbUseMuchBeamtimeDigi)
176 break;
177 } // case ECbmModuleId::kMuch:
178 case ECbmModuleId::kTrd: {
180 break;
181 } // case ECbmModuleId::kTrd:
182 case ECbmModuleId::kTof: {
184 break;
185 } // case ECbmModuleId::kTof:
186 case ECbmModuleId::kRich: {
188 break;
189 } // case ECbmModuleId::kRich:
190 case ECbmModuleId::kPsd: {
192 break;
193 } // case ECbmModuleId::kPsd:
194 case ECbmModuleId::kBmon: {
196 break;
197 } // case ECbmModuleId::kBmon:
198 default: {
199 LOG(fatal) << "CbmMcbm2019TimeWinEventBuilderAlgo::BuildEvents => "
200 << "Trying to search event seeds with unsupported det: " << fRefDet.sName;
201 break;
202 } // default:
203 } // switch( *det )
204}
205
206template<class DigiSeed>
208{
210 Double_t dTsStartTime = fdTsStartTime;
211 Double_t dOverlapStart = fdTsStartTime + fdTsLength;
212 Double_t dOverlapSize = fdTsOverLength;
213 if (fdTsStartTime < 0 || fdTsLength < 0 || fdTsOverLength < 0) {
215 if (nullptr == pTsMetaData)
216 LOG(fatal) << Form("CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
217 "No TS metadata found for TS %6u.",
218 fuNrTs);
219
221 dOverlapStart = pTsMetaData->GetOverlapStartTime();
222 dOverlapSize = pTsMetaData->GetOverlapDuration();
223 } // if ( fdTsStartTime < 0 || fdTsLength < 0 || fdTsOverLength < 0 )
224
226 if ((0.0 < fdEarliestTimeWinBeg && dOverlapSize < fdLatestTimeWinEnd) || (dOverlapSize < fdWidestTimeWinRange)) {
227 LOG(warning) << "CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
228 << Form("Event window not fitting in TS overlap, risk of "
229 "incomplete events: %f %f %f %f",
231 } // if end of event window does not fit in overlap for a seed at edge of TS core
232
235 Double_t dSeedWindowBeg = dTsStartTime + (0.0 < fdEarliestTimeWinBeg ? 0.0 : -fdEarliestTimeWinBeg);
236 Double_t dSeedWindowEnd = dOverlapStart + (0.0 < fdEarliestTimeWinBeg ? 0.0 : -fdEarliestTimeWinBeg);
237 if (fbIgnoreTsOverlap) {
238 dSeedWindowBeg = dTsStartTime;
239 dSeedWindowEnd = dOverlapStart;
240 } // if( fbIgnoreTsOverlap )
241
243 if (fBmonDigiVec) {
245 UInt_t uNbRefDigis = fBmonDigiVec->size();
247 for (UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi) {
248 LOG(debug) << Form("Checking seed %6u / %6u", uDigi, uNbRefDigis);
249
250 Double_t dTime = fBmonDigiVec->at(uDigi).GetTime();
251
253 CheckSeed(dTime, uDigi);
254 } // for( UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi )
255 } // if ( fBmonDigiVec )
256 else
257 LOG(fatal) << "CbmMcbm2019TimeWinEventBuilderAlgo::LoopOnSeeds => "
258 << "Bmon as reference detector but vector not found!";
259 } // if (ECbmModuleId::kBmon == fRefDet.detId)
260 else {
261 UInt_t uNbRefDigis = (0 < fDigiMan->GetNofDigis(fRefDet.detId) ? fDigiMan->GetNofDigis(fRefDet.detId) : 0);
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();
269
271 if (dTime < dSeedWindowBeg) { continue; } // if( dTime < dSeedWindowBeg )
272 else if (dSeedWindowEnd < dTime) {
273 break;
274 } // else if( dSeedWindowEnd < dTime )
275
277 CheckSeed(dTime, uDigi);
278 } // if( nullptr != pDigi )
279 } // for( UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi )
280 } // else of if (ECbmModuleId::kBmon == fRefDet.detId) => Digi containers controlled by DigiManager
281}
282
283void CbmMcbm2019TimeWinEventBuilderAlgo::CheckSeed(Double_t dSeedTime, UInt_t uSeedDigiIdx)
284{
287 if (nullptr != fCurrentEvent
289 && dSeedTime - fdPrevEvtTime < fdWidestTimeWinRange) {
291 switch (fOverMode) {
294 LOG(debug1) << "Reject seed due to overlap";
295 return;
296 break;
297 } // case EOverlapMode::NoOverlap:
300 break;
301 } // case EOverlapMode::MergeOverlap:
305 LOG(debug1) << "Reject seed because part of cluster of previous one";
306 return;
307 break;
308 } // case EOverlapMode::AllowOverlap:
309 } // switch( fOverMode )
310 } // if( prev Event exists and mode forbiden overlap present )
311 else {
314 if (nullptr != fCurrentEvent) {
316 // fCurrentEvent->SetStartTime( fPrevTime ); // Replace Seed time with time of first digi in event?
318 fEventVector.push_back(fCurrentEvent);
319 fuCurEv++;
320 } // if( nullptr != fCurrentEvent )
321 fCurrentEvent = new CbmEvent(fuCurEv, dSeedTime, 0.);
322 } // else of if( prev Event exists and mode forbiden overlap present )
323
327 switch (fRefDet.detId) {
328 case ECbmModuleId::kSts: {
330 break;
331 } // case ECbmModuleId::kSts:
332 case ECbmModuleId::kMuch: {
335 } // if (fbUseMuchBeamtimeDigi)
336 else {
338 } // else of if (fbUseMuchBeamtimeDigi)
339 break;
340 } // case ECbmModuleId::kMuch:
341 case ECbmModuleId::kTrd: {
343 break;
344 } // case ECbmModuleId::kTrd:
345 case ECbmModuleId::kTof: {
347 break;
348 } // case ECbmModuleId::kTof:
349 case ECbmModuleId::kRich: {
351 break;
352 } // case ECbmModuleId::kRich:
353 case ECbmModuleId::kPsd: {
355 break;
356 } // case ECbmModuleId::kPsd:
357 case ECbmModuleId::kBmon: {
359 break;
360 } // case ECbmModuleId::kBmon:
361 default: {
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.";
365 break;
366 } // default:
367 } // switch( fRefDet )
368
370 if (0 < fRefDet.fdTimeWinBeg) AddDigiToEvent(fRefDet, uSeedDigiIdx);
371 } // if( fdRefTimeWinBeg < fdRefTimeWinEnd )
372 else {
373 AddDigiToEvent(fRefDet, uSeedDigiIdx);
374 } // else of if( fdRefTimeWinBeg < fdRefTimeWinEnd )
375
377 for (std::vector<EventBuilderDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
378 switch ((*det).detId) {
379 case ECbmModuleId::kSts: {
380 SearchMatches<CbmStsDigi>(dSeedTime, *det);
381 break;
382 } // case ECbmModuleId::kSts:
383 case ECbmModuleId::kMuch: {
385 SearchMatches<CbmMuchBeamTimeDigi>(dSeedTime, *det);
386 } // if (fbUseMuchBeamtimeDigi)
387 else {
388 SearchMatches<CbmMuchDigi>(dSeedTime, *det);
389 } // else of if (fbUseMuchBeamtimeDigi)
390 break;
391 } // case ECbmModuleId::kMuch:
392 case ECbmModuleId::kTrd: {
393 SearchMatches<CbmTrdDigi>(dSeedTime, *det);
394 break;
395 } // case ECbmModuleId::kTrd:
396 case ECbmModuleId::kTof: {
397 SearchMatches<CbmTofDigi>(dSeedTime, *det);
398 break;
399 } // case ECbmModuleId::kTof:
400 case ECbmModuleId::kRich: {
401 SearchMatches<CbmRichDigi>(dSeedTime, *det);
402 break;
403 } // case ECbmModuleId::kRich:
404 case ECbmModuleId::kPsd: {
405 SearchMatches<CbmPsdDigi>(dSeedTime, *det);
406 break;
407 } // case ECbmModuleId::kPsd:
408 case ECbmModuleId::kBmon: {
409 SearchMatches<CbmTofDigi>(dSeedTime, *det);
410 break;
411 } // case ECbmModuleId::kBmon:
412 default: {
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.";
416 break;
417 } // default:
418 } // switch( *det )
419 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
420
423 fdPrevEvtTime = dSeedTime;
424
428
431
433 for (std::vector<EventBuilderDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
434 (*det).fuStartIndex = (*det).fuEndIndex;
435 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
436 } // If no overlap or merge overlap
437 } // if( !HasTrigger( fCurrentEvent ) )
438 else {
439 LOG(debug1) << "Reject seed due to Trigger requirements";
440 delete fCurrentEvent;
441 fCurrentEvent = nullptr;
442 } // else of if( !HasTrigger( fCurrentEvent ) )
443}
444
445template<class DigiCheck>
447{
449 UInt_t uLocalIndexStart = detMatch.fuStartIndex;
450 UInt_t uLocalIndexEnd = detMatch.fuStartIndex;
451
453 if (ECbmModuleId::kBmon == detMatch.detId) {
454 if (fBmonDigiVec) {
456 UInt_t uNbSelDigis = fBmonDigiVec->size();
458 for (UInt_t uDigi = detMatch.fuStartIndex; uDigi < uNbSelDigis; ++uDigi) {
459 Double_t dTime = fBmonDigiVec->at(uDigi).GetTime();
460
461 Double_t dTimeDiff = dTime - dSeedTime;
462
464 if (dTimeDiff < detMatch.fdTimeWinBeg) {
465 ++uLocalIndexStart;
466 continue;
467 } // if( dTimeDiff < detMatch.fdTimeWinBeg )
468 else if (detMatch.fdTimeWinEnd < dTimeDiff) {
471 uLocalIndexEnd = uDigi;
472 break;
473 } // else if( detMatch.fdTimeWinEnd < dTimeDiff ) of if( dTimeDiff < detMatch.fdTimeWinBeg )
474
475 AddDigiToEvent(detMatch, uDigi);
476
477 if (fdPrevEvtEndTime < dTime) fdPrevEvtEndTime = dTime;
478 } // for( UInt_t uDigi = 0; uDigi < uNbSelDigis; ++uDigi )
479
481 if (uLocalIndexEnd < uLocalIndexStart) uLocalIndexEnd = uNbSelDigis;
482 } // if ( fBmonDigiVec )
483 else
484 LOG(fatal) << "CbmMcbm2019TimeWinEventBuilderAlgo::SearchMatches => "
485 << "Bmon as selection detector but vector not found!";
486 } // if( ECbmModuleId::kBmon == detMatch.detId )
487 else {
488 UInt_t uNbSelDigis = (0 < fDigiMan->GetNofDigis(detMatch.detId) ? fDigiMan->GetNofDigis(detMatch.detId) : 0);
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;
496
497 LOG(debug4) << detMatch.sName << Form(" => Checking match %6u / %6u, dt %f", uDigi, uNbSelDigis, dTimeDiff);
498
500 if (dTimeDiff < detMatch.fdTimeWinBeg) {
501 ++uLocalIndexStart;
502 continue;
503 } // if( dTimeDiff < detMatch.fdTimeWinBeg )
504 else if (detMatch.fdTimeWinEnd < dTimeDiff) {
507 uLocalIndexEnd = uDigi;
508 break;
509 } // else if( detMatch.fdTimeWinEnd < dTimeDiff ) of if( dTimeDiff < detMatch.fdTimeWinBeg )
510
511 AddDigiToEvent(detMatch, uDigi);
512
513 if (fdPrevEvtEndTime < dTime) fdPrevEvtEndTime = dTime;
514 } // if( nullptr != pDigi )
515 } // for( UInt_t uDigi = 0; uDigi < uNbSelDigis; ++uDigi )
516
518 if (uLocalIndexEnd < uLocalIndexStart) uLocalIndexEnd = uNbSelDigis;
519 } // else of if( ECbmModuleId::kBmon == detMatch.detId ) => Digi containers controlled by DigiManager
520
522 detMatch.fuStartIndex = uLocalIndexStart;
523 detMatch.fuEndIndex = uLocalIndexEnd;
524}
525
530
532{
534 if (kFALSE == CheckTriggerConditions(event, fRefDet)) {
535 return kFALSE;
536 } // if (kFALSE == CheckTriggerConditions(event, fRefDet) )
537
539 for (std::vector<EventBuilderDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
540 if (kFALSE == CheckTriggerConditions(event, *det)) return kFALSE;
541 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
542
544 return kTRUE;
545}
546
548{
550 if (0 == det.fuTriggerMinDigis && det.fiTriggerMaxDigis < 0) {
551 return kTRUE;
552 } // if( 0 == det.fuTriggerMinDigis && det.fiTriggerMaxDigis < 0 )
553
555 if (ECbmModuleId::kBmon == det.detId) {
557 if (!(fBmonDigiVec)) {
558 LOG(warning) << "Event does not have digis storage for Bmon"
559 << " while the following trigger minimum are defined: " << det.fuTriggerMinDigis << " "
560 << det.fiTriggerMaxDigis;
561 return kFALSE;
562 } // if( !(fBmonDigiVec) )
563 } // if( ECbmDataType::kBmonDigi == det.detId )
564 else {
565 if (!fDigiMan->IsPresent(det.detId)) {
566 LOG(warning) << "Event does not have digis storage for " << det.sName
567 << " while the following trigger min/max are defined: " << det.fuTriggerMinDigis << " "
568 << det.fiTriggerMaxDigis;
569 return kFALSE;
570 } // if( !fDigiMan->IsPresent( det ) )
571 } // else of if( ECbmDataType::kBmonDigi == det )
572
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 "
577 << det.sName;
578 return kFALSE;
579 } // if((-1 == iNbDigis) || (static_cast<UInt_t>(iNbDigis) < det.fuTriggerMinDigis))
581 else if (0 < det.fiTriggerMaxDigis && det.fiTriggerMaxDigis < iNbDigis) {
582 LOG(debug2) << "Event Has too many digis: " << iNbDigis << " vs " << det.fiTriggerMaxDigis << " for " << det.sName;
583 return kFALSE;
584 } // else if( iNbDigis < det.fiTriggerMaxDigis )
585 else {
586 return kTRUE;
587 } // else of else if( iNbDigis < det.fiTriggerMaxDigis )
588}
589//----------------------------------------------------------------------
591{
593 /* clang-format off */
594 fhEventTime = new TH1F("hEventTime",
595 "seed time of the events; Seed time [s]; Events",
596 60000, 0, 600);
597 fhEventDt = new TH1F( "fhEventDt",
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 []",
603 10000, 0, 10000);
605 new TH2I("hNbDigiPerEvtTime",
606 "nb of all digis per event vs seed time of the events; Seed time "
607 "[s]; Nb Digis []; Events []",
608 600, 0, 600,
609 1000, 0, 10000);
610
612 for (std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
614 if( "Invalid" == (*det).sName )
615 {
616 fvhNbDigiPerEvtTimeDet.push_back( nullptr );
617 continue;
618 } // if( "Invalid" == (*det).sName )
619
620 fvhNbDigiPerEvtTimeDet.push_back(
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() ),
625 600, 0, 600,
626 4000, 0, 4000) );
627 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
628
629 AddHistoToVector(fhEventTime, "evtbuild");
630 AddHistoToVector(fhEventDt, "evtbuild");
631 AddHistoToVector(fhEventSize, "evtbuild");
633 for (std::vector<TH2*>::iterator itHist = fvhNbDigiPerEvtTimeDet.begin();
634 itHist != fvhNbDigiPerEvtTimeDet.end();
635 ++itHist) {
636 if( nullptr != (*itHist) )
637 {
638 AddHistoToVector((*itHist), "evtbuild");
639 } // if( nullptr != (*itHist) )
640 } // for( std::vector<TH2*>::iterator itHist = fvhNbDigiPerEvtTimeDet.begin(); itHist != fvhNbDigiPerEvtTimeDet.end(); ++itHist )
641
643 /* clang-format on */
644}
646{
647 Double_t dPreEvtTime = -1.0;
648 for (CbmEvent* evt : fEventVector) {
649 fhEventTime->Fill(evt->GetStartTime() * 1e-9);
650 if (0.0 <= dPreEvtTime) { fhEventDt->Fill(evt->GetStartTime() - dPreEvtTime); } // if( 0.0 <= dPreEvtTime )
651 fhEventSize->Fill(evt->GetNofData());
652 fhNbDigiPerEvtTime->Fill(evt->GetStartTime() * 1e-9, evt->GetNofData());
653
655 for (UInt_t uDetIdx = 0; uDetIdx < fvDets.size(); ++uDetIdx) {
656 if (nullptr == fvhNbDigiPerEvtTimeDet[uDetIdx]) continue;
657
658 fvhNbDigiPerEvtTimeDet[uDetIdx]->Fill(evt->GetStartTime() * 1e-9, evt->GetNofData(fvDets[uDetIdx].dataType));
659 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
660
661 dPreEvtTime = evt->GetStartTime();
662 } // for( CbmEvent * evt: fEventVector )
663}
665{
666 fhEventTime->Reset();
667 fhEventDt->Reset();
668 fhEventSize->Reset();
669
670 fhNbDigiPerEvtTime->Reset();
672 for (std::vector<TH2*>::iterator itHist = fvhNbDigiPerEvtTimeDet.begin(); itHist != fvhNbDigiPerEvtTimeDet.end();
673 ++itHist) {
674 (*itHist)->Reset();
675 } // for( std::vector<TH2*>::iterator itHist = fvhNbDigiPerEvtTimeDet.begin(); itHist != fvhNbDigiPerEvtTimeDet.end(); ++itHist )
676
677 /*
678 if( kTRUE == bResetTime )
679 {
681 fdStartTime = -1.0;
682 } // if( kTRUE == bResetTime )
683*/
684}
685//----------------------------------------------------------------------
687 std::string sNameIn, UInt_t uTriggerMinDigisIn,
688 Int_t iTriggerMaxDigisIn, Double_t fdTimeWinBegIn,
689 Double_t fdTimeWinEndIn)
690{
691
693 SetReferenceDetector(EventBuilderDetector(refDet, dataTypeIn, sNameIn, uTriggerMinDigisIn, iTriggerMaxDigisIn,
694 fdTimeWinBegIn, fdTimeWinEndIn));
695}
697 UInt_t uTriggerMinDigisIn, Int_t iTriggerMaxDigisIn,
698 Double_t fdTimeWinBegIn, Double_t fdTimeWinEndIn)
699{
700
702 AddDetector(EventBuilderDetector(selDet, dataTypeIn, sNameIn, uTriggerMinDigisIn, iTriggerMaxDigisIn, fdTimeWinBegIn,
703 fdTimeWinEndIn));
704}
705//----------------------------------------------------------------------
706//----------------------------------------------------------------------
708{
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!"
714 << refDetIn.sName;
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 "
719 "clusters!";
720 RemoveDetector(refDetIn);
721 break;
722 } // if( (*det) == refDetIn )
723 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
724
725 if (fRefDet == refDetIn) {
726 LOG(warning) << "CbmMcbm2019TimeWinEventBuilderAlgo::SetReferenceDetector => "
727 "Doing nothing, identical reference detector already in use";
728 } // if( fRefDet == refDetIn )
729 else {
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 "
734 "selection "
735 << refDetIn.sName;
736 LOG(warning) << " => "
737 "Please also remember to update the selection windows!";
738 } // else of if( fRefDet == refDetIn )
739 fRefDet = refDetIn;
740
745}
747{
748 if (fRefDet == selDet) {
749 LOG(fatal) << "CbmMcbm2019TimeWinEventBuilderAlgo::AddDetector => Cannot "
750 "add the reference detector as selection detector!"
751 << std::endl
752 << "=> Maybe first change the reference detector with "
753 "SetReferenceDetector?";
754 } // if( fRefDet == selDet )
755
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!"
761 << selDet.sName;
762 return;
763 } // if( (*det) == selDet )
764 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
765 fvDets.push_back(selDet);
766
771}
773{
775 for (std::vector<EventBuilderDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
776 if ((*det) == selDet) {
777 fvDets.erase(det);
778 return;
779 } // if( (*det) == selDet )
780 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
781 LOG(warning) << "CbmMcbm2019TimeWinEventBuilderAlgo::RemoveDetector => Doing "
782 "nothing, selection detector not in list!"
783 << selDet.sName;
784}
785//----------------------------------------------------------------------
787{
789 if (fRefDet.detId == selDet) {
791
792 LOG(debug) << "Set Trigger min limit for " << fRefDet.sName << " to " << uVal;
793
794 return;
795 } // if( fRefDet == selDet )
796
798 for (std::vector<EventBuilderDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
799 if ((*det).detId == selDet) {
800 (*det).fuTriggerMinDigis = uVal;
801
802 LOG(debug) << "Set Trigger min limit for " << (*det).sName << " to " << uVal;
803
804 return;
805 } // if( (*det).detId == selDet )
806 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
807
808 LOG(warning) << "CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerMinNumber => "
809 "Doing nothing, detector neither reference nor in selection list!"
810 << selDet;
811}
813{
815 if (fRefDet.detId == selDet) {
817
818 LOG(debug) << "Set Trigger min limit for " << fRefDet.sName << " to " << iVal;
819
820 return;
821 } // if( fRefDet == selDet )
822
824 for (std::vector<EventBuilderDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
825 if ((*det).detId == selDet) {
826 (*det).fiTriggerMaxDigis = iVal;
827
828 LOG(debug) << "Set Trigger min limit for " << (*det).sName << " to " << iVal;
829
830 return;
831 } // if( (*det).detId == selDet )
832 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
833
834 LOG(warning) << "CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerMaxNumber => "
835 "Doing nothing, detector neither reference nor in selection list!"
836 << selDet;
837}
838void CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerWindow(ECbmModuleId selDet, Double_t dWinBeg, Double_t dWinEnd)
839{
841 if (dWinEnd <= dWinBeg)
842 LOG(fatal) << "CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerWindow => "
843 "Invalid time window: [ "
844 << dWinBeg << ", " << dWinEnd << " ]";
845
846 Bool_t bFound = kFALSE;
848 if (fRefDet.detId == selDet) {
849 fRefDet.fdTimeWinBeg = dWinBeg;
850 fRefDet.fdTimeWinEnd = dWinEnd;
851
852 bFound = kTRUE;
853 } // if( fRefDet == selDet )
854
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;
860
861 bFound = kTRUE;
862 } // if( (*det).detId == selDet )
863 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
864
865 if (kFALSE == bFound) {
866 LOG(warning) << "CbmMcbm2019TimeWinEventBuilderAlgo::SetTriggerWindow => "
867 "Doing nothing, detector neither reference nor in selection list!"
868 << selDet;
869 } // if( kFALSE == bFound )
870
875}
877{
881
883 for (std::vector<EventBuilderDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
884 fdEarliestTimeWinBeg = std::min(fdEarliestTimeWinBeg, (*det).fdTimeWinBeg);
885 fdLatestTimeWinEnd = std::max(fdLatestTimeWinEnd, (*det).fdTimeWinEnd);
886 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
887}
889{
892
894 for (std::vector<EventBuilderDetector>::iterator det = fvDets.begin(); det != fvDets.end(); ++det) {
895 fdWidestTimeWinRange = std::max(fdWidestTimeWinRange, (*det).fdTimeWinEnd - (*det).fdTimeWinBeg);
896 } // for( std::vector< EventBuilderDetector >::iterator det = fvDets.begin(); det != fvDets.end(); ++det )
897}
898//----------------------------------------------------------------------
899
ClassImp(CbmConverterManager)
ECbmDataType
Definition CbmDefs.h:90
ECbmModuleId
Definition CbmDefs.h:39
@ 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,...
Definition CbmEvent.h:34
void AddData(ECbmDataType type, uint32_t index)
Definition CbmEvent.cxx:33
void SetEndTime(double endTime)
Definition CbmEvent.h:157
TH2 * fhNbDigiPerEvtTime
histogram with the nb of all digis in the event
void CheckSeed(Double_t dSeedTime, UInt_t uSeedDigiIdx)
void SetTriggerWindow(ECbmModuleId selDet, Double_t dWinBeg, Double_t dWinEnd)
void AddDigiToEvent(EventBuilderDetector &det, Int_t uIdx)
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.
Bool_t fbUseMuchBeamtimeDigi
Switch ON/OFF filling of histograms.
EOverlapMode fOverMode
Event building mode and detectors selection.
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)
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
TH1 * fhEventDt
histogram with the seed time of the events
std::vector< CbmEvent * > fEventVector
pointer to the event which is currently build
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 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...
UInt_t fuTriggerMinDigis
Minimum number of Bmon digis needed to generate a trigger, 0 means don't use for trigger generation.
UInt_t fuStartIndex
Book-keeping variables.
Double_t fdTimeWinBeg
Selection Window.
uint64_t GetOverlapDuration() const
uint64_t GetOverlapStartTime() const
uint64_t GetStartTime() const