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