CbmRoot
Loading...
Searching...
No Matches
CbmMvdClusterfinder.cxx
Go to the documentation of this file.
1/* Copyright (C) 2014-2020 Institut fuer Kernphysik, Goethe-Universitaet Frankfurt, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Philipp Sitzmann [committer] */
4
5// -------------------------------------------------------------------------
6// ----- CbmMvdClusterfinder source file -----
7// -------------------------------------------------------------------------
9
10#include "CbmDefs.h" // for ECbmModuleId
11#include "CbmDigiManager.h" // for CbmDigiManager
12#include "CbmEvent.h" // for CbmEvent
13#include "CbmMvdDetector.h" // for CbmMvdDetector
14#include "CbmMvdDigi.h" // for CbmMvdDigi
15#include "CbmMvdSensor.h" // for CbmMvdSensor
16#include "CbmMvdSensorClusterfinderTask.h" // for CbmMvdSensorCluste...
17
18#include <FairRootManager.h> // for FairRootManager
19#include <FairTask.h> // for InitStatus, FairTask
20#include <Logger.h> // for Logger, LOG
21
22#include <TClonesArray.h> // for TClonesArray
23
24#include <iomanip> // for setprecision, setw
25#include <iostream> // for operator<<, endl
26#include <map> // for allocator, __map_i...
27#include <sstream> // for stringstream
28#include <utility> // for pair
29
30using std::endl;
31using std::fixed;
32using std::left;
33using std::right;
34using std::setprecision;
35using std::setw;
36using std::stringstream;
37
38// ----- Default constructor ------------------------------------------
40 : FairTask("MVDClusterfinder")
41 , fMode(0)
42 , fShowDebugHistos(kFALSE)
43 , fDetector(nullptr)
44 , fDigiMan(nullptr)
45 , fCluster(nullptr)
46 , fClusterPluginNr()
47 , fBranchName("")
48 , fTimer()
49{
50}
51// -------------------------------------------------------------------------
52
53// ----- Standard constructor ------------------------------------------
54CbmMvdClusterfinder::CbmMvdClusterfinder(const char* name, Int_t iMode, Int_t iVerbose)
55 : FairTask(name, iVerbose)
56 , fMode(iMode)
57 , fShowDebugHistos(kFALSE)
58 , fDetector(nullptr)
59 , fDigiMan(nullptr)
60 , fCluster(nullptr)
61 , fClusterPluginNr(0)
62 , fBranchName("MvdDigi")
63 , fTimer()
64{
65}
66// -------------------------------------------------------------------------
67
68// ----- Destructor ----------------------------------------------------
70{
71
72 if (fCluster) {
73 fCluster->Delete();
74 delete fCluster;
75 }
76}
77// -----------------------------------------------------------------------------
78
79// ----- Exec --------------------------------------------------------------
80void CbmMvdClusterfinder::Exec(Option_t* /*opt*/)
81{
82
83 // --- Start timer
84 fTimer.Start();
85 LOG(debug) << "CbmMvdClusterfinder::Exec : Starting Exec ";
86 fCluster->Delete();
87
89 ProcessData(nullptr);
90 }
91 else {
92 assert(fEvents);
93 Int_t nEvents = fEvents->GetEntriesFast();
94 LOG(debug) << setw(20) << left << GetName() << ": Processing time slice " << fNofTs << " with " << nEvents
95 << (nEvents == 1 ? " event" : " events");
96 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
97 CbmEvent* event = dynamic_cast<CbmEvent*>(fEvents->At(iEvent));
98 assert(event);
99 Int_t clustersBeforeEvent = fCluster->GetEntriesFast();
100 LOG(debug) << "Number of clusters before executing the event: " << clustersBeforeEvent;
101 ProcessData(event);
102 // when running in event based mode add the MvdCluster to the event
103 if (event) {
104 for (Int_t iCluster = clustersBeforeEvent; iCluster < fCluster->GetEntriesFast(); ++iCluster) {
105 event->AddData(ECbmDataType::kMvdCluster, iCluster);
106 }
107 LOG(debug) << "The current event contains " << event->GetNofData(ECbmDataType::kMvdCluster) << " MVD clusters";
108 }
109 }
110 }
111
112 fTimer.Stop();
113
114 stringstream logOut;
115 logOut << setw(20) << left << GetName() << " [";
116 logOut << fixed << setw(8) << setprecision(1) << right << fTimer.RealTime() * 1000. << " ms] ";
117 logOut << "TS " << fNofTs;
118 if (fEvents) logOut << ", events " << fEvents->GetEntriesFast();
119 logOut << ", digis " << fDigiMan->GetNofDigis(ECbmModuleId::kMvd);
120 logOut << ", clusters " << fCluster->GetEntriesFast();
121 LOG(info) << logOut.str();
122
123 fNofTs++;
124}
125
127{
128
129 Int_t nDigis = (event ? event->GetNofData(ECbmDataType::kMvdDigi) : fDigiMan->GetNofDigis(ECbmModuleId::kMvd));
130
131 if (nDigis > 0) {
132 if (fVerbose) LOG(debug) << "//----------------------------------------//";
133 if (fVerbose) LOG(debug) << "Send Input";
134
135 Int_t nTargetPlugin = fDetector->DetectPlugin(200);
136
137 LOG(debug) << "CbmMvdClusterfinder::Exec - nDigis= " << nDigis;
138
139 // Since the digis are distributed to several sensor tasks which creates
140 // several new arrays, the array index can't be used to link the proper
141 // digi information in the tasks to be used inside the task to link the
142 // correct MC information
143 // Add the index in the original array to to the digi itself
144 for (Int_t iDigi = 0; iDigi < nDigis; iDigi++) {
145 Int_t digiIndex = (event ? event->GetIndex(ECbmDataType::kMvdDigi, iDigi) : iDigi);
146 CbmMvdDigi* digi = new CbmMvdDigi(*(fDigiMan->Get<CbmMvdDigi>(digiIndex)));
147 digi->SetRefId(digiIndex);
148
149 fDetector->SendInputToSensorPlugin(digi->GetDetectorId(), nTargetPlugin, static_cast<TObject*>(digi));
150 }
151
152 LOG(debug) << "CbmMvdClusterfinder::Exec : Communicating with Plugin: " << nTargetPlugin;
153
154 //fDetector->SendInputDigis(fDigiMan);
155 if (fVerbose) LOG(debug) << "Execute ClusterPlugin Nr. " << fClusterPluginNr;
156 fDetector->Exec(nTargetPlugin);
157 if (fVerbose) LOG(debug) << "End Chain";
158 if (fVerbose) LOG(debug) << "Start writing Cluster";
159
160 // Get the data from all sensors
161 fDetector->GetOutputArray(nTargetPlugin, fCluster);
162
163 //fDetector->GetMatchArray (nTargetPlugin, fTmpMatch);
164 //fCluster->AbsorbObjects(fDetector->GetOutputCluster(), 0, fDetector->GetOutputCluster()->GetEntriesFast() - 1);
165 }
166}
167// -----------------------------------------------------------------------------
168
169// ----- Init --------------------------------------------------------------
171{
172 LOG(info) << GetName() << ": Initialisation...";
173
174 // ********** RootManager
175 FairRootManager* ioman = FairRootManager::Instance();
176 if (!ioman) {
177 LOG(error) << GetName() << "::Init: No FairRootManager!";
178 return kFATAL;
179 }
180
181 // ********** Get input array
183 fDigiMan->Init();
185 LOG(error) << "No MvdDigi branch found. There was no MVD in the "
186 "simulation. Switch this task off";
187 return kERROR;
188 }
189
190 // --- In event mode: get input array (CbmEvent)
192 LOG(info) << GetName() << ": Using event-by-event mode";
193 fEvents = dynamic_cast<TClonesArray*>(ioman->GetObject("CbmEvent"));
194 if (nullptr == fEvents) {
195 LOG(warn) << GetName() << ": Event mode selected but no event array found!";
196 return kFATAL;
197 } //? Event branch not present
198 } //? Event mode
199 else {
200 LOG(info) << GetName() << ": Using time-based mode";
201 }
202
203 // ********** Register output array
204 fCluster = new TClonesArray("CbmMvdCluster", 10000);
205 ioman->Register("MvdCluster", "Mvd Clusters", fCluster, IsOutputBranchPersistent("MvdCluster"));
206
208
209 if (fDetector->GetSensorArraySize() > 1) {
210 if (fVerbose) LOG(info) << "succesfully loaded Geometry from file";
211 }
212 else {
213 LOG(fatal) << "Geometry couldn't be loaded from file. No MVD digitizer available.";
214 }
215
216 // Add the cluster finder plugin to all sensors
217 std::map<int, CbmMvdSensor*>& sensorMap = fDetector->GetSensorMap();
218 UInt_t plugincount = fDetector->GetPluginCount();
219
220 for (auto itr = sensorMap.begin(); itr != sensorMap.end(); itr++) {
222
223 itr->second->AddPlugin(clusterTask);
224 itr->second->SetClusterPlugin(plugincount);
225 }
227 fDetector->SetPluginCount(plugincount + 1);
229
231 fDetector->Init();
232
233
234 // Screen output
235 LOG(info) << GetName() << " initialised with parameters: ";
236 //PrintParameters();
237
238
239 return kSUCCESS;
240}
241
242// ----- Virtual public method Reinit ----------------------------------
243InitStatus CbmMvdClusterfinder::ReInit() { return kSUCCESS; }
244// -------------------------------------------------------------------------
245
246
247// ----- Virtual method Finish -----------------------------------------
253// -------------------------------------------------------------------------
254
255// ----- Private method Reset ------------------------------------------
257// -------------------------------------------------------------------------
258
259// ----- Private method GetMvdGeometry ---------------------------------
261// -------------------------------------------------------------------------
262
263// ----- Private method PrintParameters --------------------------------
265
266// ----- Private method ParametersToString -----------------------------
268{
269 std::stringstream ss;
270 ss << "============================================================" << endl;
271 ss << "============== Parameters Clusterfinder ====================" << endl;
272 ss << "============================================================" << endl;
273 ss << "=============== End Task ===================================" << endl;
274 return ss.str();
275}
276// -------------------------------------------------------------------------
277
278
@ kMvd
Micro-Vertex Detector.
ClassImp(CbmMvdClusterfinder)
CbmDigiManager * fDigiMan
static Int_t GetNofDigis(ECbmModuleId systemId)
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
InitStatus Init()
Initialisation.
const Digi * Get(Int_t index) const
Get a digi object.
static CbmDigiManager * Instance()
Static instance.
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
Int_t fNofTs
Number of time slices processed.
void Exec(Option_t *opt)
TStopwatch fTimer
ROOT timer.
CbmMvdDetector * fDetector
virtual InitStatus Init()
virtual InitStatus ReInit()
std::string ParametersToString() const
ECbmRecoMode fEventMode
Time-slice or event-by-event.
UInt_t fClusterPluginNr
Input array of events.
CbmDigiManager * fDigiMan
void ProcessData(CbmEvent *event)
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)
Int_t GetSensorArraySize()
void Exec(UInt_t nLevel)
int32_t GetDetectorId()
Definition CbmMvdDigi.h:55
void SetRefId(int32_t refId)
Definition CbmMvdDigi.h:82