CbmRoot
Loading...
Searching...
No Matches
CbmMvdDetector.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] */
4
5// -------------------------------------------------------------------------
6// ----- CbmMvdDetector source file -----
7// ----- Created 31/01/11 by M. Deveaux -----
8// -------------------------------------------------------------------------
9
10#include "CbmMvdDetector.h"
11
12#include "CbmMvdDetectorId.h" // for CbmMvdDetectorId
13#include "CbmMvdGeoHandler.h" // for CbmMvdGeoHandler
14#include "CbmMvdHelper.h" // for CbmMvdSensorTyp
15#include "CbmMvdSensor.h" // for CbmMvdSensor
16#include "CbmMvdSensorPlugin.h" // for CbmMvdSensorPlugin, MvdSensorPluginType
17#include "CbmMvdSensorTask.h" // for CbmMvdSensorTask
18
19#include <Logger.h> // for LOG, Logger
20
21#include <Rtypes.h> // for TGenericClassInfo
22#include <TClonesArray.h> // for TClonesArray
23#include <TH1.h> // for Histograms (only base class is used)
24#include <TNamed.h> // for TNamed
25#include <TObjArray.h> // for TObjArray
26#include <TRandom.h> // for TRandom, gRandom
27#include <TString.h> // for TString, operator==, operator<<
28
29//_____________________________________________________________________________
31
33
34//_____________________________________________________________________________
36{
37 if (fInstance)
38 return fInstance;
39 else {
40 fInstance = new CbmMvdDetector("A");
41 CbmMvdGeoHandler* mvdHandler = new CbmMvdGeoHandler();
42 mvdHandler->SetSensorTyp(fSensorTyp);
43 mvdHandler->Init();
44 mvdHandler->Fill();
45 mvdHandler->PrintGeoParameter();
46 return fInstance;
47 }
48}
49
50// ----- Default constructor -------------------------------------------
52 : TNamed()
53 , fSensorArray(nullptr)
54 , fSensorMap()
55 , fPluginCount(0)
56 , foutput(nullptr)
57 , foutputHits(nullptr)
58 , foutputDigis(nullptr)
59 , foutputCluster(nullptr)
60 , //khun
61 foutputDigiMatchs(nullptr)
62 , foutputHitMatchs(nullptr)
63 , fcurrentEvent(nullptr)
64 , fepsilon()
65 , fDigiPlugin(-1)
66 , fHitPlugin(-1)
67 , fClusterPlugin(-1)
68 , fSensorArrayFilled(kFALSE)
69 , initialized(kFALSE)
70 , fFinished(kFALSE)
71 , fName("")
72 , fParameter(nullptr)
73{
74
75 Fatal(GetName(), " - Do not use standard constructor");
76}
77// -------------------------------------------------------------------------
78
79
80// ----- Standard constructor ------------------------------------------
82 : TNamed()
83 , fSensorArray(new TClonesArray("CbmMvdSensor", 10))
84 , fSensorMap()
85 , fPluginCount(0)
86 , foutput(nullptr)
87 , foutputHits(nullptr)
88 , foutputDigis(nullptr)
89 , foutputCluster(nullptr)
90 , //khun
91 foutputDigiMatchs(nullptr)
92 , foutputHitMatchs(nullptr)
93 , fcurrentEvent(nullptr)
94 , fepsilon()
95 , fDigiPlugin(-1)
96 , fHitPlugin(-1)
97 , fClusterPlugin(-1)
98 , fSensorArrayFilled(kFALSE)
99 , initialized(kFALSE)
100 , fFinished(kFALSE)
101 , fName(name)
102 , fParameter(nullptr)
103{
104
105 if (fInstance) {
106 Fatal(GetName(), " - Error, singleton does already exist.");
107 }
108 else {
109 fInstance = this;
110 };
111 fepsilon[0] = fepsilon[1] = fepsilon[2] = 0;
112 fName = name;
113}
114// -------------------------------------------------------------------------
115
116
117// ----- Destructor ----------------------------------------------------
119//-----------------------------------------------------------------------
120
121// -------Setters -----------------------------------------------------
122
123void CbmMvdDetector::AddSensor(TString clearName, TString fullName, TString nodeName, CbmMvdSensorDataSheet* sensorData,
124 Int_t sensorNr, Int_t volumeId, Double_t sensorStartTime, Int_t stationNr)
125{
132 TString myname;
133
134 if (fSensorArrayFilled) {
135 Fatal(GetName(), " - Error, must add all sensors before adding plugins.");
136 }
137
138
139 Int_t nSensors = fSensorArray->GetEntriesFast();
140
141 myname = clearName;
142 myname += nSensors;
143
144 new ((*fSensorArray)[nSensors])
145 CbmMvdSensor(myname, sensorData, fullName, nodeName, sensorNr, volumeId, sensorStartTime);
146 //CbmMvdSensor(const char* name, CbmMvdSensorDataSheet* dataSheet, TString volName,
147 //TString nodeName, Int_t stationNr, Int_t volumeId, Double_t sensorStartTime);
148
149 CbmMvdSensor* sensor = (CbmMvdSensor*) fSensorArray->At(nSensors);
150 sensor->SetDataSheet(sensorData);
151 sensor->SetStation(stationNr);
152
153 // calculate the detectorId from the running sensor number
155 int detectorId = tmp.DetectorId(sensorNr);
156
157 // Add sensor to SensorMap
158 fSensorMap[detectorId] = sensor;
159
160 Float_t misalignment[3], randArray[3];
161 // TRandom3* rand = new TRandom3(0);
162 gRandom->RndmArray(3, randArray);
163 misalignment[0] = ((2 * randArray[0]) - 1) * fepsilon[0];
164 misalignment[1] = ((2 * randArray[0]) - 1) * fepsilon[1];
165 misalignment[2] = ((2 * randArray[0]) - 1) * fepsilon[2];
166 sensor->SetMisalignment(misalignment);
167 LOG(debug1) << "new sensor " << myname << " to detector added at station: " << stationNr;
168}
169
170// ----------------------------------------------------------------------
171
172Int_t CbmMvdDetector::DetectPlugin(Int_t pluginID)
173{
174 // Detects the position of a plugin with a given Plugin-ID (set in the plugin implementation constructor) in the plugin-array of the sensors
175
176
177 if (!fSensorArrayFilled) {
178 LOG(warning)
179 << "CbmMvdDetector::DetectPlugin: You tried to access sensor plugins while the detector is not initialized yet.";
180 return -1;
181 }
182 CbmMvdSensor* sensor = GetSensor(0);
183 TObjArray* pluginArray = sensor->GetPluginArray();
184
185 Int_t nPlugin = pluginArray->GetEntries();
186 for (Int_t i = 0; i < nPlugin; i++) {
187 CbmMvdSensorPlugin* plugin = (CbmMvdSensorPlugin*) pluginArray->At(i);
188 // LOG(info) <<"CbmMvdDetector::DetectPlugin: PlugInID = " << plugin->GetPluginIDNumber() << " Position: "<< i;
189 if (pluginID == plugin->GetPluginIDNumber()) {
190 return i;
191 }
192 }
193
194
195 return -1;
196}
197
198//-----------------------------------------------------------------------
200{
201
209 if (!initialized) {
210 foutput = new TClonesArray("CbmMvdPoint", 1000);
211 fcurrentEvent = new TClonesArray("CbmMvdPoint", 1000);
212 foutputDigis = new TClonesArray("CbmMvdDigi", 1000);
213 foutputDigiMatchs = new TClonesArray("CbmMatch", 1000);
214 foutputHits = new TClonesArray("CbmMvdHit", 1000);
215 foutputCluster = new TClonesArray("CbmMvdCluster", 1000); //khun
216 }
217
218 Int_t nSensors = fSensorArray->GetEntriesFast();
219 if (nSensors <= 0) LOG(fatal) << "CbmMvdDetector could not load Sensors from Geometry!";
220 CbmMvdSensor* sensor;
221
222 for (Int_t j = 0; j < nSensors; j++) {
223
224 sensor = (CbmMvdSensor*) fSensorArray->At(j);
225 LOG(debug1) << "Init Sensor " << sensor->GetName();
226 sensor->Init();
227 }
228
229 initialized = kTRUE;
230}
231//-----------------------------------------------------------------------
232
233//-----------------------------------------------------------------------
235{
236
237 Int_t nSensors = fSensorArray->GetEntriesFast();
238 CbmMvdSensor* sensor;
239
240 for (Int_t j = 0; j < nSensors; j++) {
241 sensor = (CbmMvdSensor*) fSensorArray->At(j);
242 sensor->ShowDebugHistos();
243 }
244}
245//-----------------------------------------------------------------------
246
247//-----------------------------------------------------------------------
248void CbmMvdDetector::SendInputToSensorPlugin(Int_t detectorid, Int_t nPlugin, TObject* input)
249{
250 fSensorMap[detectorid]->SendInputToPlugin(nPlugin, input);
251}
252//-----------------------------------------------------------------------
253
254//-----------------------------------------------------------------------
256{
263 foutput->Clear();
264 fcurrentEvent->Clear();
265 foutputDigis->Clear();
266 foutputDigiMatchs->Clear();
267 foutputHits->Clear();
268 foutputCluster->Clear(); //khun
269
270 Int_t nSensors = fSensorArray->GetEntriesFast();
271 CbmMvdSensor* sensor;
272 for (Int_t i = 0; i < nSensors; i++) {
273 sensor = (CbmMvdSensor*) fSensorArray->At(i);
274 //LOG(info) << "Send Chain to " << sensor->GetName() << endl;
275 sensor->ExecChain();
276 //LOG(info) << "finished Chain at "<< sensor->GetName() <<endl<< endl;
277 };
278}
279
280//-----------------------------------------------------------------------
281
282
283//-----------------------------------------------------------------------
284void CbmMvdDetector::Exec(UInt_t nLevel)
285{
292 foutput->Clear();
293 fcurrentEvent->Clear();
294 foutputDigis->Clear();
295 foutputDigiMatchs->Clear();
296 foutputHits->Clear();
297 foutputCluster->Clear(); //khun
298 Int_t nSensors = fSensorArray->GetEntriesFast();
299 CbmMvdSensor* sensor;
300 for (Int_t i = 0; i < nSensors; i++) {
301 sensor = (CbmMvdSensor*) fSensorArray->At(i);
302 sensor->Exec(nLevel);
303 }
304}
305
306//-----------------------------------------------------------------------
307
308//-----------------------------------------------------------------------
309
310void CbmMvdDetector::ExecFrom(UInt_t nLevel)
311{
312
318 foutput->Clear();
319 fcurrentEvent->Clear();
320 foutputDigis->Clear();
321 foutputDigiMatchs->Clear();
322 foutputHits->Clear();
323 foutputCluster->Clear(); //khun
324
325 Int_t nSensors = fSensorArray->GetEntriesFast();
326 CbmMvdSensor* sensor;
327 for (Int_t i = 0; i < nSensors; i++) {
328 sensor = (CbmMvdSensor*) fSensorArray->At(i);
329 sensor->ExecFrom(nLevel);
330 }
331}
332//-----------------------------------------------------------------------
333
334void CbmMvdDetector::GetOutputArray(Int_t nPlugin, TClonesArray* outputArray)
335{
336 Int_t nSensors = fSensorArray->GetEntriesFast();
337 CbmMvdSensor* sensor;
338 TClonesArray* tmpArray;
339
340
341 for (Int_t i = 0; i < nSensors; i++) {
342 sensor = (CbmMvdSensor*) fSensorArray->At(i);
343 tmpArray = sensor->GetOutputArray(nPlugin);
344 Int_t length = tmpArray->GetEntriesFast();
345 //LOG(info)<< "CbmMvdDetector::GetOutputArray - Length = " << length;
346 if (length >= 0) {
347 outputArray->AbsorbObjects(tmpArray);
348 }
349 }
350}
351
352//-----------------------------------------------------------------------
353void CbmMvdDetector::GetMatchArray(Int_t nPlugin, TClonesArray* matchArray)
354{
355 Int_t nSensors = fSensorArray->GetEntriesFast();
356 CbmMvdSensor* sensor;
357 TClonesArray* tmpArray;
358
359
360 for (Int_t i = 0; i < nSensors; i++) {
361 sensor = (CbmMvdSensor*) fSensorArray->At(i);
362 tmpArray = sensor->GetMatchArray(nPlugin);
363 Int_t length = tmpArray->GetEntriesFast();
364
365 if (length >= 0) {
366 matchArray->AbsorbObjects(tmpArray);
367 }
368 }
369}
370
371//-----------------------------------------------------------------------
372
374{
375
376 if (!fSensorArray) return -1;
377
378 CbmMvdSensor* sensor = (CbmMvdSensor*) fSensorArray->At(0);
379
380 if (sensor->GetPluginArraySize() < nPlugin) return -1;
381
382 //CbmMvdSensorPlugin* plugin= (CbmMvdSensorPlugin*)sensor->GetPluginArray()->At(nPlugin);
383
384 return sensor->GetNumberOfHistograms(nPlugin);
385};
386
387
388//-----------------------------------------------------------------------
389TH1* CbmMvdDetector::GetHistogram(UInt_t nPlugin, UInt_t nHistogram)
390{
391 if (!fSensorArray) return 0;
392
393 CbmMvdSensor* sensor = (CbmMvdSensor*) fSensorArray->At(0);
394
395 if (sensor->GetPluginArraySize() < nPlugin) return 0;
396 if (nHistogram >= sensor->GetNumberOfHistograms(nPlugin)) return 0;
397
398 TH1* mySummedHistogram = (TH1*) ((sensor->GetHistogram(nPlugin, nHistogram))->Clone());
399
400 for (Int_t i = 1; i < fSensorArray->GetEntriesFast(); i++) { // Read histograms from all sensors and add them up.
401 sensor = (CbmMvdSensor*) fSensorArray->At(i);
402 mySummedHistogram->Add((TH1*) sensor->GetHistogram(nPlugin, nHistogram));
403 }
404
405 return mySummedHistogram;
406}
407
408//-----------------------------------------------------------------------
409TH1* CbmMvdDetector::GetHistogram(UInt_t /*nLevel*/, UInt_t /*nHistogramNumber*/, UInt_t /*sensorInSensorArrayNumber*/)
410{
411 return 0;
412}
413
414//-----------------------------------------------------------------------
416{
417 if (!fFinished) {
418 Int_t nSensors = fSensorArray->GetEntriesFast();
419 CbmMvdSensor* sensor;
420 for (Int_t i = 0; i < nSensors; i++) {
421 sensor = (CbmMvdSensor*) fSensorArray->At(i);
422 sensor->Finish();
423 }
424 fFinished = kTRUE;
425 }
426}
427//-----------------------------------------------------------------------
428
ClassImp(CbmConverterManager)
Helper class to extract information from the GeoManager. Addapted from TrdGeoHandler byFlorian Uhlig ...
CbmMvdSensorTyp
Definition CbmMvdHelper.h:8
int32_t DetectorId(int32_t iStation) const
virtual ~CbmMvdDetector()
TH1 * GetHistogram(UInt_t nPlugin, UInt_t nHistogramNumber)
TClonesArray * foutputDigis
void AddSensor(TString clearName, TString fullName, TString nodeName, CbmMvdSensorDataSheet *sensorData, Int_t sensorNr, Int_t volumeId, Double_t sensorStartTime, Int_t stationNr)
void ExecFrom(UInt_t nLevel)
UInt_t GetMaxHistoNumber(UInt_t nPlugin)
static CbmMvdDetector * Instance()
Int_t DetectPlugin(Int_t pluginID)
CbmMvdSensor * GetSensor(Int_t nSensor)
Float_t fepsilon[3]
static CbmMvdDetector * fInstance
void SendInputToSensorPlugin(Int_t detectorid, Int_t nPlugin, TObject *input)
std::map< int, CbmMvdSensor * > fSensorMap
static CbmMvdSensorTyp fSensorTyp
TClonesArray * foutputCluster
TClonesArray * fcurrentEvent
void GetOutputArray(Int_t nPlugin, TClonesArray *outputArray)
TClonesArray * foutputDigiMatchs
void GetMatchArray(Int_t nPlugin, TClonesArray *matchArray)
Bool_t fSensorArrayFilled
void Exec(UInt_t nLevel)
TClonesArray * fSensorArray
TClonesArray * foutput
TClonesArray * foutputHits
void Init(Bool_t isSimulation=kFALSE)
void SetSensorTyp(CbmMvdSensorTyp typ)
virtual Int_t GetPluginIDNumber()
TClonesArray * GetMatchArray(Int_t nPlugin) const
UInt_t GetNumberOfHistograms(UInt_t nPlugin)
void SetMisalignment(Float_t misalignment[3])
TH1 * GetHistogram(UInt_t nPlugin, UInt_t nHisto)
void SetDataSheet(CbmMvdSensorDataSheet *sheet)
void SetStation(Int_t StationNumber)
void SendInputToPlugin(Int_t nPlugin, TObject *input)
TObjArray * GetPluginArray()
UInt_t GetPluginArraySize()
void Exec(UInt_t nPlugin)
void ShowDebugHistos()
void ExecFrom(UInt_t nPlugin)
TClonesArray * GetOutputArray(Int_t nPlugin) const