CbmRoot
CbmBuildEventsIdeal.cxx
Go to the documentation of this file.
1 
6 #include "CbmBuildEventsIdeal.h"
7 
8 #include <FairLogger.h>
9 #include <FairRootManager.h>
10 #include <TClonesArray.h>
11 #include <TStopwatch.h>
12 #include <cassert>
13 #include <iomanip>
14 #include <iostream>
15 
16 #include "CbmDigiManager.h"
17 #include "CbmEvent.h"
18 #include "CbmLink.h"
19 #include "CbmMatch.h"
20 #include "CbmModuleList.h"
21 
22 using namespace std;
23 
24 
25 // ===== Constructor =====================================================
26 CbmBuildEventsIdeal::CbmBuildEventsIdeal() : FairTask("BuildEventsIdeal") {}
27 // ===========================================================================
28 
29 
30 // ===== Destructor ======================================================
32 // ===========================================================================
33 
34 
35 // ===== Task execution ==================================================
36 void CbmBuildEventsIdeal::Exec(Option_t*) {
37 
38  TStopwatch timer;
39  timer.Start();
40  std::map<Int_t, CbmEvent*> eventMap;
41  Int_t nEvents = 0;
42  UInt_t nDigisTot = 0;
43  UInt_t nDigisNoise = 0;
44 
45  // Clear output array
46  fEvents->Delete();
47 
48  for (ECbmModuleId& system : fSystems) {
49  if (!fDigiMan->IsPresent(system)) continue;
50  if (!fDigiMan->IsMatchPresent(system)) continue;
51  Int_t nDigis = fDigiMan->GetNofDigis(system);
52  UInt_t nNoise = 0;
53  LOG(info) << GetName() << ": System "
54  << CbmModuleList::GetModuleNameCaps(system) << ", digis "
55  << nDigis;
56 
57  for (Int_t iDigi = 0; iDigi < nDigis; iDigi++) {
58  const CbmMatch* match = fDigiMan->GetMatch(system, iDigi);
59  assert(match);
60 
61  // This implementation uses only MC event number from
62  // the matched link, i.e. that with the largest weight.
63  // Can be refined later on.
64  Int_t mcEventNr = match->GetMatchedLink().GetEntry();
65 
66  // Ignore digis with missing event number (noise)
67  if (mcEventNr < 0) {
68  nNoise++;
69  continue;
70  }
71 
72  // Get event pointer. If event is not yet present, create it.
73  CbmEvent* event = NULL;
74  if (eventMap.find(mcEventNr) == eventMap.end()) {
75  event = new ((*fEvents)[nEvents]) CbmEvent(nEvents);
76  eventMap[mcEventNr] = event;
77  nEvents++;
78  } else
79  event = eventMap.at(mcEventNr);
80 
81  // Fill digi index into event
82  switch (system) {
83  case ECbmModuleId::kMvd:
84  event->AddData(ECbmDataType::kMvdDigi, iDigi);
85  break;
86  case ECbmModuleId::kSts:
87  event->AddData(ECbmDataType::kStsDigi, iDigi);
88  break;
90  event->AddData(ECbmDataType::kRichDigi, iDigi);
91  break;
93  event->AddData(ECbmDataType::kMuchDigi, iDigi);
94  break;
95  case ECbmModuleId::kTrd:
96  event->AddData(ECbmDataType::kTrdDigi, iDigi);
97  break;
98  case ECbmModuleId::kTof:
99  event->AddData(ECbmDataType::kTofDigi, iDigi);
100  break;
101  case ECbmModuleId::kPsd:
102  event->AddData(ECbmDataType::kPsdDigi, iDigi);
103  break;
104  default: break;
105  } //? detector
106 
107  } //# digis
108  LOG(debug) << GetName() << ": Detector "
109  << CbmModuleList::GetModuleNameCaps(system) << ", digis "
110  << nDigis << ", noise " << nNoise;
111  nDigisTot += nDigis;
112  nDigisNoise += nNoise;
113 
114  } //# detectors
115 
116 
117  timer.Stop();
118  assert(nEvents == fEvents->GetEntriesFast());
119 
120  // --- Execution log
121  std::cout << std::endl;
122  LOG(info) << "+ " << setw(15) << GetName() << ": Time-slice " << setw(3)
123  << right << fNofEntries << ", events: " << setw(6) << nEvents
124  << ", digis: " << nDigisTot << ", noise: " << nDigisNoise
125  << ". Exec time " << fixed << setprecision(6) << timer.RealTime()
126  << " s.";
127 
128  // --- For debug: event info
129  if (gLogger->IsLogNeeded(fair::Severity::debug)) {
130  for (Int_t iEvent = 0; iEvent < fEvents->GetEntriesFast(); iEvent++) {
131  CbmEvent* event = (CbmEvent*) fEvents->At(iEvent);
132  LOG(info) << event->ToString();
133  }
134  }
135 
136  fNofEntries++;
137 }
138 // ===========================================================================
139 
140 
141 // ===== Task initialisation =============================================
143 
144  // --- Get FairRootManager instance
145  FairRootManager* ioman = FairRootManager::Instance();
146  assert(ioman);
147 
148  // --- DigiManager instance
150  fDigiMan->Init();
151 
152  std::cout << std::endl;
153  LOG(info) << "==================================================";
154  LOG(info) << GetName() << ": Initialising...";
155 
156 
157  // --- Check input data
158  for (ECbmModuleId system = ECbmModuleId::kMvd;
159  system < ECbmModuleId::kNofSystems;
160  ++system) {
161  if (fDigiMan->IsMatchPresent(system)) {
162  LOG(info) << GetName() << ": Found match branch for "
164  fSystems.push_back(system);
165  }
166  }
167  if (fSystems.empty()) {
168  LOG(fatal) << GetName() << ": No match branch found!";
169  return kFATAL;
170  }
171 
172  // Register output array (CbmEvent)
173  if (ioman->GetObject("Event")) {
174  LOG(fatal) << GetName() << ": Branch Event already exists!";
175  return kFATAL;
176  }
177  fEvents = new TClonesArray("CbmEvent", 100);
178  ioman->Register(
179  "Event", "CbmEvent", fEvents, IsOutputBranchPersistent("Event"));
180  if (!fEvents) {
181  LOG(fatal) << GetName() << ": Output branch could not be created!";
182  return kFATAL;
183  }
184 
185  LOG(info) << "==================================================";
186  std::cout << std::endl;
187 
188  return kSUCCESS;
189 }
190 // ===========================================================================
191 
192 
CbmMatch::GetMatchedLink
const CbmLink & GetMatchedLink() const
Definition: CbmMatch.h:37
CbmBuildEventsIdeal::fEvents
TClonesArray * fEvents
Definition: CbmBuildEventsIdeal.h:42
CbmMatch
Definition: CbmMatch.h:22
CbmBuildEventsIdeal::fSystems
std::vector< ECbmModuleId > fSystems
Definition: CbmBuildEventsIdeal.h:41
ECbmDataType::kRichDigi
@ kRichDigi
ECbmDataType::kStsDigi
@ kStsDigi
ECbmDataType::kMvdDigi
@ kMvdDigi
CbmDigiManager::Init
InitStatus Init()
Initialisation.
Definition: CbmDigiManager.cxx:71
CbmBuildEventsIdeal::fNofEntries
Int_t fNofEntries
Output array (class CbmEvent)
Definition: CbmBuildEventsIdeal.h:43
CbmBuildEventsIdeal.h
ECbmDataType::kTofDigi
@ kTofDigi
ECbmModuleId::kMvd
@ kMvd
Micro-Vertex Detector.
ECbmModuleId
ECbmModuleId
Definition: CbmDefs.h:33
CbmDigiManager::GetNofDigis
static Int_t GetNofDigis(ECbmModuleId systemId)
Definition: CbmDigiManager.cxx:62
ECbmModuleId::kTof
@ kTof
Time-of-flight Detector.
CbmMatch.h
CbmDigiManager::IsPresent
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
Definition: CbmDigiManager.cxx:112
CbmBuildEventsIdeal::~CbmBuildEventsIdeal
virtual ~CbmBuildEventsIdeal()
Definition: CbmBuildEventsIdeal.cxx:31
CbmDigiManager::Instance
static CbmDigiManager * Instance()
Static instance.
Definition: CbmDigiManager.h:93
CbmDigiManager::IsMatchPresent
static Bool_t IsMatchPresent(ECbmModuleId systemId)
Presence of a digi match branch.
Definition: CbmDigiManager.cxx:104
CbmBuildEventsIdeal::CbmBuildEventsIdeal
CbmBuildEventsIdeal()
Definition: CbmBuildEventsIdeal.cxx:26
CbmEvent.h
CbmModuleList::GetModuleNameCaps
static TString GetModuleNameCaps(ECbmModuleId moduleId)
Definition: CbmModuleList.cxx:77
CbmBuildEventsIdeal::fDigiMan
CbmDigiManager * fDigiMan
Definition: CbmBuildEventsIdeal.h:40
ECbmDataType::kPsdDigi
@ kPsdDigi
CbmDigiManager::GetMatch
const CbmMatch * GetMatch(ECbmModuleId systemId, UInt_t index) const
Get a match object.
Definition: CbmDigiManager.cxx:54
ECbmModuleId::kNofSystems
@ kNofSystems
For loops over active systems.
ECbmModuleId::kRich
@ kRich
Ring-Imaging Cherenkov Detector.
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmBuildEventsIdeal::Init
virtual InitStatus Init()
Definition: CbmBuildEventsIdeal.cxx:142
CbmModuleList.h
CbmBuildEventsIdeal
Definition: CbmBuildEventsIdeal.h:26
ECbmDataType::kTrdDigi
@ kTrdDigi
ECbmModuleId::kTrd
@ kTrd
Transition Radiation Detector.
CbmDigiManager.h
CbmEvent
Class characterising one event by a collection of links (indices) to data objects,...
Definition: CbmEvent.h:30
CbmBuildEventsIdeal::Exec
virtual void Exec(Option_t *opt)
Definition: CbmBuildEventsIdeal.cxx:36
ECbmModuleId::kMuch
@ kMuch
Muon detection system.
ECbmModuleId::kPsd
@ kPsd
Projectile spectator detector.
ECbmModuleId::kSts
@ kSts
Silicon Tracking System.
ECbmDataType::kMuchDigi
@ kMuchDigi