CbmRoot
Loading...
Searching...
No Matches
CbmRecoT0.cxx
Go to the documentation of this file.
1/* Copyright (C) 2022-2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
5
6#include "CbmRecoT0.h"
7
8#include "CbmBmonDigi.h"
9#include "CbmEvent.h"
10
11#include <FairRootManager.h>
12#include <Logger.h>
13
14#include <TClonesArray.h>
15#include <TStopwatch.h>
16
17#include <cassert>
18#include <iomanip>
19#include <iostream>
20#include <sstream>
21
22
23using std::fixed;
24using std::left;
25using std::right;
26using std::setprecision;
27using std::setw;
28
29
30// ----- Constructor ---------------------------------------------------
31CbmRecoT0::CbmRecoT0(const char* name) : FairTask(name) {}
32// -------------------------------------------------------------------------
33
34
35// ----- Destructor ----------------------------------------------------
37// -------------------------------------------------------------------------
38
39
40// ----- Initialization ------------------------------------------------
41InitStatus CbmRecoT0::Init()
42{
43
44 std::cout << std::endl;
45 LOG(info) << "==========================================================";
46 LOG(info) << GetName() << ": Initialisation";
47
48 // --- Get FairRootManager
49 FairRootManager* ioman = FairRootManager::Instance();
50 assert(ioman);
51
52 // --- Get BmonDigi array
53 fBmonDigis = ioman->InitObjectAs<const std::vector<CbmBmonDigi>*>(CbmBmonDigi::GetBranchName());
54 if (!fBmonDigis) {
55 LOG(error) << GetName() << ": No BmonDigi array!";
56 return kERROR;
57 }
58 LOG(info) << "--- Found branch BmonDigi";
59
60 // --- Get CbmEvent array
61 fEvents = dynamic_cast<TClonesArray*>(ioman->GetObject("Event"));
62 if (fEvents) {
63 LOG(info) << "--- Found branch Event";
64 }
65 else {
66 fEvents = dynamic_cast<TClonesArray*>(ioman->GetObject("CbmEvent"));
67 if (!fEvents) {
68 LOG(error) << GetName() << ": No Event nor CbmEvent branch! Task will be inactive.";
69 return kERROR;
70 }
71 LOG(info) << "--- Found branch CbmEvent";
72 }
73
74 LOG(info) << GetName() << ": Initialisation successful";
75 LOG(info) << "==========================================================";
76 std::cout << std::endl;
77 return kSUCCESS;
78}
79// -------------------------------------------------------------------------
80
81
82// ----- Public method Exec --------------------------------------------
83void CbmRecoT0::Exec(Option_t*)
84{
85
86 // Timer
87 TStopwatch timer;
88 timer.Start();
89 CbmRecoT0MoniData tsMonitor{};
90
91 // Event loop
92 Int_t nEvents = fEvents->GetEntriesFast();
93 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
94 CbmEvent* event = dynamic_cast<CbmEvent*>(fEvents->At(iEvent));
95 assert(event);
96 Int_t nDigis = event->GetNofData(ECbmDataType::kBmonDigi);
97 double tzero = -999999.;
98 switch (nDigis) {
99
100 // If there is no BMON digi, set t0 to -999999 (error code).
101 case 0: {
102 tzero = -999999.;
103 tsMonitor.fNumEvtsBmon0++;
104 break;
105 }
106
107 // If there is exactly one BMON digi, take the event time from there
108 case 1: {
109 uint32_t digiIndex = event->GetIndex(ECbmDataType::kBmonDigi, 0);
110 tzero = fBmonDigis->at(digiIndex).GetTime();
111 tsMonitor.fNumEvtsBmon1++;
112 break;
113 }
114
115 // If there are more than one BMON digis, set t0 to -999999 (error code).
116 default: {
117 tzero = -999999.;
118 tsMonitor.fNumEvtsBmonn++;
119 break;
120 }
121 }
122
123 event->SetTzero(tzero);
124 tsMonitor.fNumEvents++;
125 }
126
127
128 // Timeslice monitor
129 timer.Stop();
130 tsMonitor.fExecTime = 1000. * timer.RealTime();
131 tsMonitor.fNumTs = 1;
132 std::stringstream logOut;
133 logOut << setw(20) << left << GetName() << " [";
134 logOut << fixed << setw(8) << setprecision(1) << right << timer.RealTime() * 1000. << " ms] ";
135 logOut << "TS " << fMonitor.fNumTs << ", events " << tsMonitor.fNumEvents;
136 logOut << " (1 BMON: " << tsMonitor.fNumEvtsBmon1;
137 logOut << " , 0 BMON: " << tsMonitor.fNumEvtsBmon0;
138 logOut << " , n BMON: " << tsMonitor.fNumEvtsBmonn << ")";
139 LOG(info) << logOut.str();
140
141 // Run monitor
142 fMonitor += tsMonitor;
143}
144// -------------------------------------------------------------------------
145
146
147// ----- Public method Finish ------------------------------------------
149{
150 double tExec = fMonitor.fExecTime / double(fMonitor.fNumTs);
151 double evtsPerTs = double(fMonitor.fNumEvents) / double(fMonitor.fNumTs);
152 double fracBmon1 = 100. * double(fMonitor.fNumEvtsBmon1) / double(fMonitor.fNumEvents);
153 double fracBmon0 = 100. * double(fMonitor.fNumEvtsBmon0) / double(fMonitor.fNumEvents);
154 double fracBmonn = 100. * double(fMonitor.fNumEvtsBmonn) / double(fMonitor.fNumEvents);
155 std::cout << std::endl;
156 LOG(info) << "=====================================";
157 LOG(info) << GetName() << ": Run summary";
158 LOG(info) << "Time slices : " << fMonitor.fNumTs;
159 LOG(info) << "Exec time / TS : " << fixed << setprecision(2) << tExec << " ms";
160 LOG(info) << "Events / TS : " << fixed << setprecision(2) << evtsPerTs;
161 LOG(info) << "Fraction with 1 BMON : " << fixed << setprecision(2) << fracBmon1 << " %";
162 LOG(info) << "Fraction with 0 BMON : " << fixed << setprecision(2) << fracBmon0 << " %";
163 LOG(info) << "Fraction with n BMON : " << fixed << setprecision(2) << fracBmonn << " %";
164 LOG(info) << "=====================================";
165}
166// -------------------------------------------------------------------------
167
168
ClassImp(CbmConverterManager)
static const char * GetBranchName()
Get the desired name of the branch for this objects in the cbm output tree (static)
Definition CbmBmonDigi.h:63
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
Task class for reconstruction of the event t0.
Definition CbmRecoT0.h:50
CbmRecoT0MoniData fMonitor
Monitor data.
Definition CbmRecoT0.h:83
virtual InitStatus Init()
Initialisation.
Definition CbmRecoT0.cxx:41
virtual void Finish()
End-of-timeslice action.
CbmRecoT0(const char *name="RecoBmon")
Constructor.
Definition CbmRecoT0.cxx:31
const std::vector< CbmBmonDigi > * fBmonDigis
BMON digis.
Definition CbmRecoT0.h:79
virtual ~CbmRecoT0()
Destructor.
Definition CbmRecoT0.cxx:36
virtual void Exec(Option_t *opt)
Task execution.
Definition CbmRecoT0.cxx:83
TClonesArray * fEvents
CbmEvent.
Definition CbmRecoT0.h:80
Monitor data for Bmon reconstruction.
Definition CbmRecoT0.h:22
size_t fNumEvtsBmonn
Definition CbmRecoT0.h:27
size_t fNumEvtsBmon1
Definition CbmRecoT0.h:26
size_t fNumEvtsBmon0
Definition CbmRecoT0.h:25