CbmRoot
Loading...
Searching...
No Matches
CbmMvdDigiToHit.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019 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// ----- CbmMvdDigiToHit source file -----
7// -------------------------------------------------------------------------
8
9// Includes from MVD
10#include "CbmMvdDigiToHit.h"
11
12#include "CbmMvdDetector.h"
13#include "CbmMvdGeoHandler.h"
14#include "CbmMvdPoint.h"
16
17// Includes from FAIR
18#include "FairModule.h"
19#include "FairRootManager.h"
20
21
22// Includes from ROOT
23#include "TClonesArray.h"
24#include "TGeoManager.h"
25#include "TMath.h"
26#include "TStopwatch.h"
27#include "TString.h"
28
29#include <chrono>
30//#include <omp.h>
31#include <cstring>
32#include <fstream>
33
34
35// Includes from C++
36#include <iomanip>
37#include <iostream>
38
39using std::endl;
40using std::fixed;
41using std::setprecision;
42using std::setw;
43
44
45// ----- Default constructor ------------------------------------------
47 : FairTask("CbmMvdDigiToHit")
48 , fMode(0)
49 , fShowDebugHistos(kFALSE)
50 , fDetector(nullptr)
51 , fInputDigis(nullptr)
52 , fHit(nullptr)
53 , fHitPluginNr()
54 , fBranchName("")
55 , fTimer()
56{
57}
58// -------------------------------------------------------------------------
59
60// ----- Standard constructor ------------------------------------------
61CbmMvdDigiToHit::CbmMvdDigiToHit(const char* name, Int_t iMode, Int_t iVerbose)
62 : FairTask(name, iVerbose)
63 , fMode(iMode)
64 , fShowDebugHistos(kFALSE)
65 , fDetector(nullptr)
66 , fInputDigis(nullptr)
67 , fHit(nullptr)
68 , fHitPluginNr(0)
69 , fBranchName("MvdDigi")
70 , fTimer()
71{
72}
73// -------------------------------------------------------------------------
74
75// ----- Destructor ----------------------------------------------------
77{
78
79 if (fHit) {
80 fHit->Delete();
81 delete fHit;
82 }
83}
84// -----------------------------------------------------------------------------
85
86// ----- Exec --------------------------------------------------------------
87void CbmMvdDigiToHit::Exec(Option_t* /*opt*/)
88{
89 // --- Start timer
90
91 fTimer.Start();
92
93 fHit->Delete();
94 if (fInputDigis && fInputDigis->GetEntriesFast() > 0) {
95 if (fVerbose) LOG(debug) << "//----------------------------------------//";
96 if (fVerbose) LOG(debug) << "Send Input";
97 fDetector->SendInputDigisToHits(fInputDigis); //Version for DigisToHits
98 if (fVerbose) LOG(debug) << "Execute HitPlugin Nr. " << fHitPluginNr;
100 if (fVerbose) LOG(debug) << "End Chain";
101 if (fVerbose) LOG(debug) << "Start writing Hit";
102 fHit->AbsorbObjects(fDetector->GetOutputHits(), 0, fDetector->GetOutputHits()->GetEntriesFast() - 1);
103 if (fVerbose) LOG(debug) << "Total of " << fHit->GetEntriesFast() << " Hit in this Event";
104 if (fVerbose) LOG(debug) << "//----------------------------------------//";
105 LOG(info) << "+ " << setw(20) << GetName() << ": Created: " << fHit->GetEntriesFast() << " Hit in " << fixed
106 << setprecision(6) << fTimer.RealTime() << " s";
107 }
108
109 fTimer.Stop();
110}
111// -----------------------------------------------------------------------------
112
113// ----- Init --------------------------------------------------------------
115{
116 LOG(info) << GetName() << ": Initialisation..." << endl;
117
118 // ********** RootManager
119 FairRootManager* ioman = FairRootManager::Instance();
120 if (!ioman) {
121 LOG(error) << GetName() << "::Init: No FairRootManager!";
122 return kFATAL;
123 }
124
125 // ********** Get input arrays
126 fInputDigis = (TClonesArray*) ioman->GetObject("MvdDigi");
127
128 if (!fInputDigis) {
129 LOG(error) << "No MvdDigi branch found. There was no MVD in the "
130 "simulation. Switch this task off";
131 return kERROR;
132 }
133
134 // ********** Register output array
135 fHit = new TClonesArray("CbmMvdHit", 10000);
136 ioman->Register("MvdHit", "Mvd Hit", fHit, IsOutputBranchPersistent("MvdHit"));
137
139
140 if (fDetector->GetSensorArraySize() > 1) {
141 if (fVerbose) LOG(info) << "succesfully loaded Geometry from file";
142 }
143 else {
144 LOG(fatal) << "Geometry couldn't be loaded from file. No MVD digitizer available.";
145 }
146
147 // Add the digi2hit plugin to all sensors
148 std::map<int, CbmMvdSensor*>& sensorMap = fDetector->GetSensorMap();
149 UInt_t plugincount = fDetector->GetPluginCount();
150
151 for (auto itr = sensorMap.begin(); itr != sensorMap.end(); itr++) {
153
154 itr->second->AddPlugin(hitTask);
155 itr->second->SetHitPlugin(plugincount);
156 }
158 fDetector->SetPluginCount(plugincount + 1);
160
162 fDetector->Init();
163
164
165 // Screen output
166 LOG(info) << GetName() << " initialised with parameters: ";
167 //PrintParameters();
168
169
170 return kSUCCESS;
171}
172
173// ----- Virtual public method Reinit ----------------------------------
174InitStatus CbmMvdDigiToHit::ReInit() { return kSUCCESS; }
175// -------------------------------------------------------------------------
176
177
178// ----- Virtual method Finish -----------------------------------------
184// -------------------------------------------------------------------------
185
186
187// ----- Private method Reset ------------------------------------------
188void CbmMvdDigiToHit::Reset() { fHit->Delete(); }
189// -------------------------------------------------------------------------
190
191// ----- Private method GetMvdGeometry ---------------------------------
193// -------------------------------------------------------------------------
194
195// ----- Private method PrintParameters --------------------------------
197
198// ----- Private method ParametersToString -----------------------------
200{
201 std::stringstream ss;
202 ss << "============================================================" << endl;
203 ss << "============== Parameters DigiToHit ====================" << endl;
204 ss << "============================================================" << endl;
205 ss << "=============== End Task ===================================" << endl;
206 return ss.str()
207}
208// -------------------------------------------------------------------------
209
210
ClassImp(CbmMvdDigiToHit)
Helper class to extract information from the GeoManager. Addapted from TrdGeoHandler byFlorian Uhlig ...
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)
virtual InitStatus Init()
TClonesArray * fInputDigis
void PrintParameters() const
virtual void Finish()
void Exec(Option_t *opt)
virtual InitStatus ReInit()
std::string ParametersToString() const
CbmMvdDetector * fDetector
TClonesArray * fHit
TStopwatch fTimer
ROOT timer.