CbmRoot
CbmBuildEventsIdealNew.cxx
Go to the documentation of this file.
1 
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 "CbmEventStore.h"
19 #include "CbmLink.h"
20 #include "CbmMatch.h"
21 #include "CbmModuleList.h"
22 
23 #include "CbmMuchDigi.h"
24 #include "CbmMvdDigi.h"
25 #include "CbmPsdDigi.h"
26 #include "CbmRichDigi.h"
27 #include "CbmStsDigi.h"
28 #include "CbmTofDigi.h"
29 #include "CbmTrdDigi.h"
30 
31 using namespace std;
32 
33 
34 // ===== Constructor =====================================================
36  : FairTask("BuildEventsIdealNew") {}
37 // ===========================================================================
38 
39 
40 // ===== Destructor ======================================================
42 // ===========================================================================
43 
44 
45 // ===== Task execution ==================================================
47 
48  TStopwatch timer;
49  timer.Start();
50  fEvents->Delete();
51  std::map<Int_t, CbmEventStore*> eventMap;
52  Int_t nEvents = 0;
53  UInt_t nDigisTot = 0;
54  UInt_t nDigisNoise = 0;
55 
56  for (ECbmModuleId& system : fSystems) {
57  if (!fDigiMan->IsPresent(system)) continue;
58  if (!fDigiMan->IsMatchPresent(system)) continue;
59  Int_t nDigis = fDigiMan->GetNofDigis(system);
60  UInt_t nNoise = 0;
61 
62  for (Int_t iDigi = 0; iDigi < nDigis; iDigi++) {
63  const CbmMatch* match = fDigiMan->GetMatch(system, iDigi);
64  assert(match);
65 
66  // This implementation uses only MC event number from
67  // the matched link, i.e. that with the largest weight.
68  // Can be refined later on.
69  Int_t mcEventNr = match->GetMatchedLink().GetEntry();
70 
71  // Ignore digis with missing event number (noise)
72  if (mcEventNr < 0) {
73  nNoise++;
74  continue;
75  }
76 
77  // Get event pointer. If event is not yet present, create it.
78  auto mapIt = eventMap.find(mcEventNr);
79  if (mapIt == eventMap.end()) {
80  eventMap[mcEventNr] = new CbmEventStore(nEvents++, kTRUE);
81  mapIt = eventMap.find(mcEventNr);
82  }
83  assert(mapIt != eventMap.end());
84  CbmEventStore* event = mapIt->second;
85 
86  // Fill digi into event
87  switch (system) {
88  case ECbmModuleId::kMvd: {
89  const CbmMvdDigi* digi = fDigiMan->Get<CbmMvdDigi>(iDigi);
90  event->AddDigi<CbmMvdDigi>(digi, match);
91  break;
92  }
93  case ECbmModuleId::kSts: {
94  const CbmStsDigi* digi = fDigiMan->Get<CbmStsDigi>(iDigi);
95  event->AddDigi<CbmStsDigi>(digi, match);
96  break;
97  }
98  case ECbmModuleId::kRich: {
99  const CbmRichDigi* digi = fDigiMan->Get<CbmRichDigi>(iDigi);
100  event->AddDigi<CbmRichDigi>(digi, match);
101  break;
102  }
103  case ECbmModuleId::kMuch: {
104  const CbmMuchDigi* digi = fDigiMan->Get<CbmMuchDigi>(iDigi);
105  event->AddDigi<CbmMuchDigi>(digi, match);
106  break;
107  }
108  case ECbmModuleId::kTrd: {
109  const CbmTrdDigi* digi = fDigiMan->Get<CbmTrdDigi>(iDigi);
110  event->AddDigi<CbmTrdDigi>(digi, match);
111  break;
112  }
113  case ECbmModuleId::kTof: {
114  const CbmTofDigi* digi = fDigiMan->Get<CbmTofDigi>(iDigi);
115  event->AddDigi<CbmTofDigi>(digi, match);
116  break;
117  }
118  case ECbmModuleId::kPsd: {
119  const CbmPsdDigi* digi = fDigiMan->Get<CbmPsdDigi>(iDigi);
120  event->AddDigi<CbmPsdDigi>(digi, match);
121  break;
122  }
123  default: break;
124  } //? detector
125 
126  } //# digis
127 
128  nDigisTot += nDigis;
129  nDigisNoise += nNoise;
130  } //# detectors
131 
132  // --- Fill output array
133  for (auto& entry : eventMap) {
134  assert(fEvents);
135  UInt_t nEntry = fEvents->GetEntriesFast();
136  new ((*fEvents)[nEntry]) CbmEventStore(*(entry.second));
137  delete entry.second;
138  CbmEventStore* event = (CbmEventStore*) fEvents->At(nEntry);
139  assert(event);
140  LOG(debug) << event->ToString();
141  }
142  LOG(debug) << "Created " << fEvents->GetEntriesFast() << " events";
143 
144  timer.Stop();
145 
146  // --- Execution log
147  std::cout << std::endl;
148  LOG(info) << "+ " << setw(15) << GetName() << ": Time-slice " << setw(3)
149  << right << fNofEntries << ", events: " << setw(6) << nEvents
150  << ", digis: " << nDigisTot << ", noise: " << nDigisNoise
151  << ". Exec time " << fixed << setprecision(6) << timer.RealTime()
152  << " s.";
153 
154  fNofEntries++;
155 }
156 // ===========================================================================
157 
158 
159 // ===== Task initialisation =============================================
161 
162  // --- Get FairRootManager instance
163  FairRootManager* ioman = FairRootManager::Instance();
164  assert(ioman);
165 
166  // --- DigiManager instance
168  fDigiMan->Init();
169 
170  std::cout << std::endl;
171  LOG(info) << "==================================================";
172  LOG(info) << GetName() << ": Initialising...";
173 
174 
175  // --- Check input data
176  for (ECbmModuleId system = ECbmModuleId::kMvd;
177  system < ECbmModuleId::kNofSystems;
178  ++system) {
179  if (fDigiMan->IsMatchPresent(system)) {
180  LOG(info) << GetName() << ": Found match branch for "
182  fSystems.push_back(system);
183  }
184  }
185  if (fSystems.empty()) {
186  LOG(fatal) << GetName() << ": No match branch found!";
187  return kFATAL;
188  }
189 
190  // Register output array (CbmEvent)
191  if (ioman->GetObject("Event")) {
192  LOG(fatal) << GetName() << ": Branch Event already exists!";
193  return kFATAL;
194  }
195  /*
196  fEvents = new std::vector<CbmEventStore>();
197  ioman->RegisterAny("Event", fEvents, kTRUE);
198  if ( ! fEvents ) {
199  LOG(fatal) << GetName() << ": Output branch could not be created!";
200  return kFATAL;
201  }
202  */
203  fEvents = new TClonesArray("CbmEventStore", 100);
204  ioman->Register("CbmEventStore", "Events", fEvents, kTRUE);
205 
206 
207  LOG(info) << "==================================================";
208  std::cout << std::endl;
209 
210  return kSUCCESS;
211 }
212 // ===========================================================================
213 
214 
CbmBuildEventsIdealNew::CbmBuildEventsIdealNew
CbmBuildEventsIdealNew()
Definition: CbmBuildEventsIdealNew.cxx:35
CbmMatch::GetMatchedLink
const CbmLink & GetMatchedLink() const
Definition: CbmMatch.h:37
CbmMatch
Definition: CbmMatch.h:22
CbmBuildEventsIdealNew.h
CbmMuchDigi.h
CbmBuildEventsIdealNew::~CbmBuildEventsIdealNew
virtual ~CbmBuildEventsIdealNew()
Definition: CbmBuildEventsIdealNew.cxx:41
CbmEventStore
Storable event class for CBM.
Definition: CbmEventStore.h:39
CbmPsdDigi.h
CbmRichDigi
Definition: CbmRichDigi.h:25
CbmMvdDigi.h
CbmBuildEventsIdealNew::fSystems
std::vector< ECbmModuleId > fSystems
Definition: CbmBuildEventsIdealNew.h:46
CbmDigiManager::Init
InitStatus Init()
Initialisation.
Definition: CbmDigiManager.cxx:71
CbmBuildEventsIdealNew
Definition: CbmBuildEventsIdealNew.h:31
ECbmModuleId::kMvd
@ kMvd
Micro-Vertex Detector.
ECbmModuleId
ECbmModuleId
Definition: CbmDefs.h:33
CbmDigiManager::GetNofDigis
static Int_t GetNofDigis(ECbmModuleId systemId)
Definition: CbmDigiManager.cxx:62
CbmTofDigi.h
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
CbmBuildEventsIdealNew::fNofEntries
Int_t fNofEntries
Event array.
Definition: CbmBuildEventsIdealNew.h:48
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
CbmBuildEventsIdealNew::fDigiMan
CbmDigiManager * fDigiMan
Definition: CbmBuildEventsIdealNew.h:45
CbmRichDigi.h
CbmEvent.h
CbmTrdDigi.h
CbmStsDigi.h
CbmModuleList::GetModuleNameCaps
static TString GetModuleNameCaps(ECbmModuleId moduleId)
Definition: CbmModuleList.cxx:77
CbmDigiManager::Get
const Digi * Get(Int_t index) const
Get a digi object.
Definition: CbmDigiManager.h:52
CbmBuildEventsIdealNew::Init
virtual InitStatus Init()
Definition: CbmBuildEventsIdealNew.cxx:160
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
CbmModuleList.h
CbmStsDigi
Data class for a single-channel message in the STS.
Definition: CbmStsDigi.h:29
CbmTofDigi
Data class for expanded digital TOF information.
Definition: CbmTofDigi.h:38
CbmBuildEventsIdealNew::fEvents
TClonesArray * fEvents
Definition: CbmBuildEventsIdealNew.h:47
ECbmModuleId::kTrd
@ kTrd
Transition Radiation Detector.
CbmMuchDigi
Definition: CbmMuchDigi.h:31
CbmDigiManager.h
CbmMvdDigi
Definition: CbmMvdDigi.h:21
CbmBuildEventsIdealNew::Exec
virtual void Exec(Option_t *opt)
Definition: CbmBuildEventsIdealNew.cxx:46
CbmTrdDigi
Definition: CbmTrdDigi.h:14
ECbmModuleId::kMuch
@ kMuch
Muon detection system.
ECbmModuleId::kPsd
@ kPsd
Projectile spectator detector.
CbmPsdDigi
Data class for PSD digital information.
Definition: CbmPsdDigi.h:31
ECbmModuleId::kSts
@ kSts
Silicon Tracking System.
CbmEventStore.h