CbmRoot
Loading...
Searching...
No Matches
CbmMvdDigiToHitTB.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2020 Frankfurt Institute for Advanced Studies, Goethe-Universität Frankfurt, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andreas Redelbach [committer] */
4
5// -------------------------------------------------------------------------
6// ----- CbmMvdDigiToHitTB source file -----
7// -------------------------------------------------------------------------
8
9// Includes from MVD
10#include "CbmMvdDigiToHitTB.h"
11
12#include "CbmEvent.h"
13#include "CbmMvdDetector.h"
14#include "CbmMvdGeoHandler.h"
15#include "CbmMvdPoint.h"
17
18// Includes from FAIR
19#include "FairModule.h"
20#include "FairRootManager.h"
21
22
23// Includes from ROOT
24#include "TClonesArray.h"
25#include "TGeoManager.h"
26#include "TMath.h"
27#include "TString.h"
28
29
30// Includes from C++
31#include <iomanip>
32#include <iostream>
33
34using std::endl;
35using std::fixed;
36using std::setprecision;
37using std::setw;
38
39// ----- Default constructor ------------------------------------------
41// -------------------------------------------------------------------------
42
43// ----- Standard constructor ------------------------------------------
44CbmMvdDigiToHitTB::CbmMvdDigiToHitTB(const char* name, Int_t iMode, Int_t iVerbose)
45 : FairTask(name, iVerbose)
46 , fMode(iMode)
47 , fShowDebugHistos(kFALSE)
48 , fDetector(nullptr)
49 , fEvents(nullptr)
50 , fInputDigis(nullptr)
51 , fEventDigis(nullptr)
52 , fCluster(nullptr)
53 , fClusterPluginNr(0)
54 , fBranchName("MvdDigi")
55 , fTimer()
56{
57}
58// -------------------------------------------------------------------------
59
60// ----- Destructor ----------------------------------------------------
62{
63
64 if (fCluster) {
65 fCluster->Delete();
66 delete fCluster;
67 }
68}
69// -----------------------------------------------------------------------------
70
71// ----- Exec --------------------------------------------------------------
72void CbmMvdDigiToHitTB::Exec(Option_t* /*opt*/)
73{
74 // --- Start timer
75 fTimer.Start();
76
77 fCluster->Delete();
78
79 Int_t nEvents = fEvents->GetEntriesFast();
80 for (Int_t iEv = 0; iEv < nEvents; ++iEv) {
81 LOG(debug) << "Getting data from CbmEvent";
82 CbmEvent* event = dynamic_cast<CbmEvent*>(fEvents->At(iEv));
83 Int_t nrOfDigis = event->GetNofData(ECbmDataType::kMvdDigi);
84 fEventDigis->Delete();
85 for (Int_t nDigi = 0; nDigi < nrOfDigis; ++nDigi) {
86 Int_t iDigi = event->GetIndex(ECbmDataType::kMvdDigi, nDigi);
87 fEventDigis->AddLast((CbmMvdDigi*) fInputDigis->At(iDigi));
88 }
89 LOG(debug) << "//----------------------------------------//";
90 LOG(debug) << endl << "Send Input";
91 fDetector->SendInputDigisToHits(fEventDigis); //Version for DigisToHits
92 LOG(debug) << "Execute HitPlugin Nr. " << fClusterPluginNr;
94 LOG(debug) << "End Chain";
95 LOG(debug) << "Start writing Hit";
96 fCluster->AbsorbObjects(fDetector->GetOutputHits(), 0, fDetector->GetOutputHits()->GetEntriesFast() - 1);
97 LOG(debug) << "Total of " << fCluster->GetEntriesFast() << " Hit in this Event";
98 LOG(debug) << "//----------------------------------------//";
99 LOG(info) << "+ " << setw(20) << GetName() << ": Created: " << fCluster->GetEntriesFast() << " hit in " << fixed
100 << setprecision(6) << fTimer.RealTime() << " s";
101 }
102 fTimer.Stop();
103}
104// -----------------------------------------------------------------------------
105
106// ----- Init --------------------------------------------------------------
108{
109 LOG(info) << GetName() << ": Initialisation...";
110
111 // ********** RootManager
112 FairRootManager* ioman = FairRootManager::Instance();
113 if (!ioman) {
114 LOG(error) << GetName() << "::Init: No FairRootManager!";
115 return kFATAL;
116 }
117
118 // ********** Get input arrays
119 fEvents = dynamic_cast<TClonesArray*>(ioman->GetObject("CbmEvent"));
120
121 fInputDigis = (TClonesArray*) ioman->GetObject("MvdDigi");
122 fEventDigis = new TClonesArray("CbmMvdDigi", 10000);
123 if (!fInputDigis) {
124 LOG(error) << "No MvdDigi branch found. There was no MVD in the "
125 "simulation. Switch this task off";
126 return kERROR;
127 }
128
129 // ********** Register output array
130 fCluster = new TClonesArray("CbmMvdHit", 10000);
131 ioman->Register("MvdHit", "Mvd Hits", fCluster, IsOutputBranchPersistent("MvdHit"));
132
134
135 if (fDetector->GetSensorArraySize() > 1) {
136 LOG(debug) << "-I- succesfully loaded Geometry from file -I-";
137 }
138 else {
139 LOG(fatal) << "Geometry couldn't be loaded from file. No MVD digitizer available.";
140 }
141
142 // Add the digi2hit plugin to all sensors
143 std::map<int, CbmMvdSensor*>& sensorMap = fDetector->GetSensorMap();
144 UInt_t plugincount = fDetector->GetPluginCount();
145
146 for (auto itr = sensorMap.begin(); itr != sensorMap.end(); itr++) {
148
149 itr->second->AddPlugin(hitTask);
150 itr->second->SetHitPlugin(plugincount);
151 }
153 fDetector->SetPluginCount(plugincount + 1);
154 fHitPluginNr = (UInt_t)(fDetector->GetPluginArraySize());
155
157 fDetector->Init();
158
159
160 // Screen output
161 LOG(info) << GetName() << " initialised";
162
163 return kSUCCESS;
164}
165
166// ----- Virtual public method Reinit ----------------------------------
167InitStatus CbmMvdDigiToHitTB::ReInit() { return kSUCCESS; }
168// -------------------------------------------------------------------------
169
170
171// ----- Virtual method Finish -----------------------------------------
177// -------------------------------------------------------------------------
178
179
180// ----- Private method Reset ------------------------------------------
182// -------------------------------------------------------------------------
183
184// ----- Private method GetMvdGeometry ---------------------------------
186// -------------------------------------------------------------------------
187
188// ----- Private method PrintParameters --------------------------------
190
191// ----- Private method ParametersTo String -----------------------------
193{
194 std::stringstream ss;
195 ss << "============================================================" << endl;
196 ss << "============== Parameters DigiToHit ====================" << endl;
197 ss << "============================================================" << endl;
198 ss << "=============== End Task ===================================" << endl;
199 return ss.str();
200}
201// -------------------------------------------------------------------------
202
203
ClassImp(CbmMvdDigiToHitTB)
Helper class to extract information from the GeoManager. Addapted from TrdGeoHandler byFlorian Uhlig ...
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
size_t GetNofData() const
Definition CbmEvent.cxx:53
std::map< int, CbmMvdSensor * > & GetSensorMap()
Int_t GetPluginArraySize()
static CbmMvdDetector * Instance()
void SetSensorArrayFilled(Bool_t value=kTRUE)
UInt_t GetPluginCount()
void SetPluginCount(UInt_t count)
Int_t GetSensorArraySize()
void Exec(UInt_t nLevel)
void Exec(Option_t *opt)
TStopwatch fTimer
ROOT timer.
TClonesArray * fCluster
TClonesArray * fEvents
std::string ParametersToString() const
TClonesArray * fEventDigis
CbmMvdDetector * fDetector
virtual InitStatus ReInit()
TClonesArray * fInputDigis
virtual InitStatus Init()