CbmRoot
Loading...
Searching...
No Matches
CbmMvdHitfinder.cxx
Go to the documentation of this file.
1/* Copyright (C) 2014-2021 Institut fuer Kernphysik, Goethe-Universitaet Frankfurt, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Philipp Sitzmann [committer], Florian Uhlig */
4
5// -------------------------------------------------------------------------
6// ----- CbmMvdHitfinder source file -----
7// -------------------------------------------------------------------------
8#include "CbmMvdHitfinder.h"
9
10#include "CbmDefs.h" // for ECbmModuleId
11#include "CbmDigiManager.h" // for CbmDigiManager
12#include "CbmEvent.h" // for CbmEvent
13#include "CbmMvdCluster.h" // for CbmMvdCluster
14#include "CbmMvdDetector.h" // for CbmMvdDetector
15#include "CbmMvdDigi.h" // for CbmMvdDigi
16#include "CbmMvdSensor.h" // for CbmMvdSensor
17#include "CbmMvdSensorFindHitTask.h" // for CbmMvdSensorFindHi...
18#include "CbmMvdSensorHitfinderTask.h" // for CbmMvdSensorHitfin...
19
20#include <FairRootManager.h> // for FairRootManager
21#include <FairTask.h> // for InitStatus, FairTask
22#include <Logger.h> // for Logger, LOG
23
24#include <TClonesArray.h> // for TClonesArray
25
26#include <iomanip> // for setprecision, setw
27#include <iostream> // for operator<<, endl
28#include <map> // for allocator, __map_i...
29#include <sstream> // for stringstream;
30#include <utility> // for pair
31
32using std::endl;
33using std::fixed;
34using std::ios_base;
35using std::right;
36using std::setprecision;
37using std::setw;
38using std::stringstream;
39
40// ----- Default constructor ------------------------------------------
42 : FairTask("MVDHitfinder")
43 , fDetector(nullptr)
44 , fDigiMan(nullptr)
45 , fInputCluster(nullptr)
46 , fHits(nullptr)
48 , fUseClusterfinder(kFALSE)
49 , fShowDebugHistos(kFALSE)
50 , fTimer()
51 , fmode(-1)
52{
53}
54// -------------------------------------------------------------------------
55
56// ----- Standard constructor ------------------------------------------
57CbmMvdHitfinder::CbmMvdHitfinder(const char* name, Int_t iVerbose)
58 : FairTask(name, iVerbose)
59 , fDetector(nullptr)
60 , fDigiMan(nullptr)
61 , fInputCluster(nullptr)
62 , fHits(nullptr)
64 , fUseClusterfinder(kFALSE)
65 , fShowDebugHistos(kFALSE)
66 , fTimer()
67 , fmode(-1)
68{
69}
70// -------------------------------------------------------------------------
71
72// ----- Standard constructor ------------------------------------------
73CbmMvdHitfinder::CbmMvdHitfinder(const char* name, Int_t mode, Int_t iVerbose)
74 : FairTask(name, iVerbose)
75 , fDetector(nullptr)
76 , fDigiMan(nullptr)
77 , fInputCluster(nullptr)
78 , fHits(nullptr)
80 , fUseClusterfinder(kFALSE)
81 , fShowDebugHistos(kFALSE)
82 , fTimer()
83 , fmode(mode)
84{
85 // fmode = mode;
86}
87// -------------------------------------------------------------------------
88
89// ----- Destructor ----------------------------------------------------
91{
92
93 if (fHits) {
94 fHits->Delete();
95 delete fHits;
96 }
97}
98// -----------------------------------------------------------------------------
99
100// ----- Exec --------------------------------------------------------------
101void CbmMvdHitfinder::Exec(Option_t* /*opt*/)
102{
103
104 using namespace std;
105
106 fHits->Clear();
107 fTimer.Start();
108
109 if (fDigiMan->IsPresent(ECbmModuleId::kMvd) || fInputCluster) { //checks if data sources are available
110 if (fVerbose) LOG(debug) << "//----------------------------------------//";
111 if (!fUseClusterfinder) {
112 LOG(fatal) << GetName() << "- Mode without cluster finder is currently not supported ";
113 }
114 }
115
116
117 LOG(debug) << "CbmMvdClusterfinder::Exec : Starting Exec ";
118
120 ProcessData(nullptr);
121 }
122 else {
123 assert(fEvents);
124 Int_t nEvents = fEvents->GetEntriesFast();
125 LOG(debug) << setw(20) << left << GetName() << ": Processing time slice " << fNofTs << " with " << nEvents
126 << (nEvents == 1 ? " event" : " events");
127 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
128 CbmEvent* event = dynamic_cast<CbmEvent*>(fEvents->At(iEvent));
129 assert(event);
130 Int_t hitsBeforeEvent = fHits->GetEntriesFast();
131 LOG(debug) << "Number of hits before executing the event: " << hitsBeforeEvent;
132 ProcessData(event);
133 // when running in event based mode add the MvdCluster to the event
134 if (event) {
135 for (Int_t iHit = hitsBeforeEvent; iHit < fHits->GetEntriesFast(); ++iHit) {
136 event->AddData(ECbmDataType::kMvdHit, iHit);
137 }
138 LOG(debug) << "The current event contains " << event->GetNofData(ECbmDataType::kMvdHit) << " MVD hits";
139 }
140 }
141 }
142
143 fTimer.Stop();
144 stringstream logOut;
145 logOut << setw(20) << left << GetName() << " [";
146 logOut << fixed << setw(8) << setprecision(1) << right << fTimer.RealTime() * 1000. << " ms] ";
147 logOut << "TS " << fNofTs;
148 if (fEvents) logOut << ", events " << fEvents->GetEntriesFast();
149 logOut << ", clusters " << fInputCluster->GetEntriesFast();
150 logOut << ", hits " << fHits->GetEntriesFast();
151 LOG(info) << logOut.str();
152
153 fNofTs++;
154}
155
156
158{
159
160 Int_t nCluster = (event ? event->GetNofData(ECbmDataType::kMvdCluster) : fInputCluster->GetEntriesFast());
161
162 if (nCluster > 0) {
163 if (fVerbose) LOG(debug) << "//----------------------------------------//";
164 if (fVerbose) LOG(debug) << "Send Input";
165
166 Int_t nTargetPlugin = fDetector->DetectPlugin(fMyPluginID);
167
168 LOG(debug) << "CbmMvdHitfinder::Exec - nDigis= " << nCluster;
169
170 // Since the clusters are distributed to several sensor tasks which creates
171 // several new arrays, the array index can't be used to link the proper
172 // digi information in the tasks to be used inside the task to link the
173 // correct MC information
174 // Add the index in the original array to to the digi itself
175 for (Int_t iCluster = 0; iCluster < nCluster; ++iCluster) {
176 Int_t clusterIndex = (event ? event->GetIndex(ECbmDataType::kMvdCluster, iCluster) : iCluster);
177 CbmMvdCluster* cluster = static_cast<CbmMvdCluster*>(fInputCluster->At(clusterIndex));
178 cluster->SetRefId(clusterIndex);
179
180 fDetector->SendInputToSensorPlugin(cluster->GetDetectorId(), nTargetPlugin, static_cast<TObject*>(cluster));
181 }
182 if (fVerbose) LOG(debug) << "Execute HitfinderPlugin Nr. " << fHitfinderPluginNr;
183
184
186 if (fVerbose) LOG(debug) << "End Chain";
187 if (fVerbose) LOG(debug) << "Start writing Hits";
188 fDetector->GetOutputArray(nTargetPlugin, fHits);
189
190 //fDetector->GetMatchArray (nTargetPlugin, fTmpMatch);
191 //fHits->AbsorbObjects(fDetector->GetOutputHits(), 0, fDetector->GetOutputHits()->GetEntriesFast() - 1);
192 }
193}
194// -----------------------------------------------------------------------------
195
196// ----- Init --------------------------------------------------------------
198{
199
200 using namespace std;
201
202 LOG(info) << GetName() << ": Initialisation...";
203
204 // ********** RootManager
205 FairRootManager* ioman = FairRootManager::Instance();
206 if (!ioman) {
207 LOG(error) << GetName() << "::Init: No FairRootManager!";
208 return kFATAL;
209 }
210
211 // ********** Get input arrays
212 if (!fUseClusterfinder) {
213 LOG(fatal) << GetName() << " - Mode without cluster finder is currently not supported ";
215 fDigiMan->Init();
216 if (!fDigiMan->IsPresent(ECbmModuleId::kMvd)) {
217 LOG(error) << "No MvdDigi branch found. There was no MVD in the "
218 "simulation. Switch this task off";
219 return kERROR;
220 }
221 }
222 else {
223 fInputCluster = (TClonesArray*) ioman->GetObject("MvdCluster");
224 if (!fInputCluster) {
225 LOG(error) << "No MvdCluster branch found. There was no MVD in the "
226 "simulation. Switch this task off";
227 return kERROR;
228 }
229 }
230
231 // --- In event mode: get input array (CbmEvent)
233 LOG(info) << GetName() << ": Using event-by-event mode";
234 fEvents = dynamic_cast<TClonesArray*>(ioman->GetObject("CbmEvent"));
235 if (nullptr == fEvents) {
236 LOG(warn) << GetName() << ": Event mode selected but no event array found!";
237 return kFATAL;
238 } //? Event branch not present
239 } //? Event mode
240 else {
241 LOG(info) << GetName() << ": Using time-based mode";
242 }
243
244 // ********** Register output array
245 fHits = new TClonesArray("CbmMvdHit", 1000);
246 ioman->Register("MvdHit", "Mvd Hits", fHits, IsOutputBranchPersistent("MvdHit"));
247
249
250
251 // Add the hit finder plugin to all sensors
252 const std::map<uint32_t, CbmMvdSensor*>& sensorMap = fDetector->GetSensorMap();
253 UInt_t plugincount = fDetector->GetPluginCount();
254
255 /*
256 if (!fUseClusterfinder) {
257
258 for (auto itr = sensorMap.begin(); itr != sensorMap.end(); itr++) {
259 CbmMvdSensorFindHitTask* hitfinderTask = new CbmMvdSensorFindHitTask();
260
261 itr->second->AddPlugin(hitfinderTask);
262 itr->second->SetHitPlugin(plugincount);
263 fMyPluginID=400;
264
265 }
266
267 else {*/
268 for (auto itr = sensorMap.begin(); itr != sensorMap.end(); itr++) {
270
271 itr->second->AddPlugin(hitfinderTask);
272 itr->second->SetHitPlugin(plugincount);
273 fMyPluginID = 300;
274 }
275 //}
276
277 fDetector->SetSensorArrayFilled(kTRUE);
278 fDetector->SetPluginCount(plugincount + 1);
279 fHitfinderPluginNr = (UInt_t)(fDetector->GetPluginArraySize());
280
281 if (fShowDebugHistos) fDetector->ShowDebugHistos();
282 fDetector->Init();
283
284
285 // Screen output
286 LOG(info) << GetName() << " initialised with parameters: ";
287 //PrintParameters();
288
289 return kSUCCESS;
290}
291
292// ----- Virtual public method Reinit ----------------------------------
293InitStatus CbmMvdHitfinder::ReInit() { return kSUCCESS; }
294// -------------------------------------------------------------------------
295
296
297// ----- Virtual method Finish -----------------------------------------
299// -------------------------------------------------------------------------
300
301
302// ----- Private method Reset ------------------------------------------
303void CbmMvdHitfinder::Reset() { fHits->Delete(); }
304// -------------------------------------------------------------------------
305
306// ----- Private method GetMvdGeometry ---------------------------------
308// -------------------------------------------------------------------------
309
310// ----- Private method PrintParameters --------------------------------
312
313// ----- Private method ParametersToString -----------------------------
315{
316 std::stringstream ss;
317 ss.setf(std::ios_base::fixed, std::ios_base::floatfield);
318 ss << "============================================================" << endl;
319 ss << "============== Parameters MvdHitfinder =====================" << endl;
320 ss << "============================================================" << endl;
321 ss << "=============== End Task ===================================" << endl;
322 return ss.str();
323}
324// -------------------------------------------------------------------------
325
@ kMvd
Micro-Vertex Detector.
Definition CbmDefs.h:47
ClassImp(CbmMvdHitfinder)
int Int_t
static CbmDigiManager * Instance()
Static instance.
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
void SetRefId(int32_t RefId)
uint32_t GetDetectorId() const
static CbmMvdDetector * Instance()
TClonesArray * fEvents
virtual InitStatus ReInit()
virtual ~CbmMvdHitfinder()
void Exec(Option_t *opt)
void PrintParameters() const
CbmDigiManager * fDigiMan
std::string ParametersToString() const
virtual void Finish()
CbmMvdDetector * fDetector
TClonesArray * fInputCluster
TStopwatch fTimer
ROOT timer.
Int_t fNofTs
Number of time slices processed.
UInt_t fHitfinderPluginNr
Input array of events.
virtual InitStatus Init()
TClonesArray * fHits
void ProcessData(CbmEvent *)
ECbmRecoMode fEventMode
Time-slice or event-by-event.
Hash for CbmL1LinkKey.