CbmRoot
CbmMvdDigiToHit.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- CbmMvdDigiToHit source file -----
3 // -------------------------------------------------------------------------
4 
5 // Includes from MVD
6 #include "CbmMvdDigiToHit.h"
7 #include "CbmMvdDetector.h"
8 #include "CbmMvdPoint.h"
11 #include "tools/CbmMvdGeoHandler.h"
12 
13 // Includes from FAIR
14 #include "FairModule.h"
15 #include "FairRootManager.h"
16 
17 
18 // Includes from ROOT
19 #include "TClonesArray.h"
20 #include "TGeoManager.h"
21 
22 #include "TMath.h"
23 #include "TString.h"
24 
25 
26 #include "TStopwatch.h"
27 #include <chrono>
28 //#include <omp.h>
29 #include <cstring>
30 #include <fstream>
31 
32 
33 // Includes from C++
34 #include <iomanip>
35 #include <iostream>
36 
37 using std::cout;
38 using std::endl;
39 using std::fixed;
40 using std::setprecision;
41 using std::setw;
42 
43 
44 // ----- Default constructor ------------------------------------------
46  : FairTask("CbmMvdDigiToHit")
47  , fMode(0)
48  , fShowDebugHistos(kFALSE)
49  , fDetector(NULL)
50  , fInputDigis(NULL)
51  , fHit(NULL)
52  , fHitPluginNr()
53  , fBranchName("")
54  , fTimer() {}
55 // -------------------------------------------------------------------------
56 
57 // ----- Standard constructor ------------------------------------------
58 CbmMvdDigiToHit::CbmMvdDigiToHit(const char* name, Int_t iMode, Int_t iVerbose)
59  : FairTask(name, iVerbose)
60  , fMode(iMode)
61  , fShowDebugHistos(kFALSE)
62  , fDetector(NULL)
63  , fInputDigis(NULL)
64  , fHit(NULL)
65  , fHitPluginNr(0)
66  , fBranchName("MvdDigi")
67  , fTimer() {}
68 // -------------------------------------------------------------------------
69 
70 // ----- Destructor ----------------------------------------------------
72 
73  if (fHit) {
74  fHit->Delete();
75  delete fHit;
76  }
77 }
78 // -----------------------------------------------------------------------------
79 
80 // ----- Exec --------------------------------------------------------------
81 void CbmMvdDigiToHit::Exec(Option_t* /*opt*/) {
82  // --- Start timer
83 
84  fTimer.Start();
85 
86  fHit->Delete();
87  if (fInputDigis && fInputDigis->GetEntriesFast() > 0) {
88  if (fVerbose) cout << "//----------------------------------------//";
89  if (fVerbose) cout << endl << "Send Input" << endl;
90  fDetector->SendInputDigisToHits(fInputDigis); //Version for DigisToHits
91  if (fVerbose) cout << "Execute HitPlugin Nr. " << fHitPluginNr << endl;
93  if (fVerbose) cout << "End Chain" << endl;
94  if (fVerbose) cout << "Start writing Hit" << endl;
95  fHit->AbsorbObjects(fDetector->GetOutputHits(),
96  0,
97  fDetector->GetOutputHits()->GetEntriesFast() - 1);
98  if (fVerbose)
99  cout << "Total of " << fHit->GetEntriesFast() << " Hit in this Event"
100  << endl;
101  if (fVerbose)
102  cout << "//----------------------------------------//" << endl;
103  LOG(info) << "+ " << setw(20) << GetName()
104  << ": Created: " << fHit->GetEntriesFast() << " Hit in " << fixed
105  << setprecision(6) << fTimer.RealTime() << " s";
106  }
107 
108  fTimer.Stop();
109 }
110 // -----------------------------------------------------------------------------
111 
112 // ----- Init --------------------------------------------------------------
113 InitStatus CbmMvdDigiToHit::Init() {
114  cout << "-I- " << GetName() << ": Initialisation..." << endl;
115  cout << endl;
116  cout << "---------------------------------------------" << endl;
117  cout << "-I- Initialising " << GetName() << " ...." << endl;
118 
119  // ********** RootManager
120  FairRootManager* ioman = FairRootManager::Instance();
121  if (!ioman) {
122  cout << "-E- " << GetName() << "::Init: No FairRootManager!" << endl;
123  return kFATAL;
124  }
125 
126  // ********** Get input arrays
127  fInputDigis = (TClonesArray*) ioman->GetObject("MvdDigi");
128 
129  if (!fInputDigis) {
130  LOG(error) << "No MvdDigi branch found. There was no MVD in the "
131  "simulation. Switch this task off";
132  return kERROR;
133  }
134 
135  // ********** Register output array
136  fHit = new TClonesArray("CbmMvdHit", 10000);
137  ioman->Register(
138  "MvdHit", "Mvd Hit", fHit, IsOutputBranchPersistent("MvdHit"));
139 
141 
142  if (fDetector->GetSensorArraySize() > 1) {
143  if (fVerbose)
144  cout << endl << "-I- succesfully loaded Geometry from file -I-" << endl;
145  } else {
146  LOG(fatal)
147  << "Geometry couldn't be loaded from file. No MVD digitizer available.";
148  }
149 
151 
152  fDetector->AddPlugin(hitTask);
155  fDetector->Init();
156 
157 
158  // Screen output
159  cout << GetName() << " initialised with parameters: " << endl;
160  //PrintParameters();
161  cout << "---------------------------------------------" << endl;
162 
163 
164  return kSUCCESS;
165 }
166 
167 // ----- Virtual public method Reinit ----------------------------------
168 InitStatus CbmMvdDigiToHit::ReInit() { return kSUCCESS; }
169 // -------------------------------------------------------------------------
170 
171 
172 // ----- Virtual method Finish -----------------------------------------
174  fDetector->Finish();
175  PrintParameters();
176 }
177 // -------------------------------------------------------------------------
178 
179 
180 // ----- Private method Reset ------------------------------------------
181 void CbmMvdDigiToHit::Reset() { fHit->Delete(); }
182 // -------------------------------------------------------------------------
183 
184 // ----- Private method GetMvdGeometry ---------------------------------
186 // -------------------------------------------------------------------------
187 
188 
189 // ----- Private method PrintParameters --------------------------------
191 
192  cout << "============================================================"
193  << endl;
194  cout << "============== Parameters DigiToHit ====================" << endl;
195  cout << "============================================================"
196  << endl;
197  cout << "=============== End Task ==================================="
198  << endl;
199 }
200 // -------------------------------------------------------------------------
201 
202 
CbmMvdDetector::Instance
static CbmMvdDetector * Instance()
Definition: CbmMvdDetector.cxx:47
CbmMvdDetector.h
CbmMvdDetector::Exec
void Exec(UInt_t nLevel)
Definition: CbmMvdDetector.cxx:527
CbmMvdDetector::SendInputDigisToHits
void SendInputDigisToHits(TClonesArray *digis)
Definition: CbmMvdDetector.cxx:438
CbmMvdDetector::GetPluginArraySize
UInt_t GetPluginArraySize()
Definition: CbmMvdDetector.h:71
CbmMvdDigiToHit
Definition: CbmMvdDigiToHit.h:20
CbmMvdDigiToHit::CbmMvdDigiToHit
CbmMvdDigiToHit()
Definition: CbmMvdDigiToHit.cxx:45
CbmMvdDetector::Init
void Init()
Definition: CbmMvdDetector.cxx:278
CbmMvdDigiToHit::fHitPluginNr
UInt_t fHitPluginNr
Definition: CbmMvdDigiToHit.h:50
CbmMvdDetector::Finish
void Finish()
Definition: CbmMvdDetector.cxx:705
CbmMvdDigiToHit::Init
virtual InitStatus Init()
Definition: CbmMvdDigiToHit.cxx:113
CbmMvdDigiToHit::fShowDebugHistos
Bool_t fShowDebugHistos
Definition: CbmMvdDigiToHit.h:44
CbmMvdDigiToHit::fTimer
TStopwatch fTimer
ROOT timer.
Definition: CbmMvdDigiToHit.h:55
ClassImp
ClassImp(CbmMvdDigiToHit)
CbmMvdGeoHandler.h
Helper class to extract information from the GeoManager. Addapted from TrdGeoHandler byFlorian Uhlig ...
CbmMvdDetector::ShowDebugHistos
void ShowDebugHistos()
Definition: CbmMvdDetector.cxx:313
CbmMvdPoint.h
CbmMvdDigiToHit::fDetector
CbmMvdDetector * fDetector
Definition: CbmMvdDigiToHit.h:45
CbmMvdDigiToHit.h
CbmMvdDetector::GetOutputHits
TClonesArray * GetOutputHits()
Definition: CbmMvdDetector.cxx:595
CbmMvdDigiToHit::~CbmMvdDigiToHit
~CbmMvdDigiToHit()
Definition: CbmMvdDigiToHit.cxx:71
CbmMvdDigiToHit::fHit
TClonesArray * fHit
Definition: CbmMvdDigiToHit.h:48
CbmMvdSensorDigiToHitTask
Definition: CbmMvdSensorDigiToHitTask.h:40
CbmMvdDigiToHit::Finish
virtual void Finish()
Definition: CbmMvdDigiToHit.cxx:173
CbmMvdDigiToHit::fInputDigis
TClonesArray * fInputDigis
Definition: CbmMvdDigiToHit.h:47
CbmMvdDigiToHit::PrintParameters
void PrintParameters()
Definition: CbmMvdDigiToHit.cxx:190
CbmMvdDetector::GetSensorArraySize
Int_t GetSensorArraySize()
Definition: CbmMvdDetector.h:70
CbmMvdDigiToHit::GetMvdGeometry
void GetMvdGeometry()
Definition: CbmMvdDigiToHit.cxx:185
CbmMvdDigiToHit::Exec
void Exec(Option_t *opt)
Definition: CbmMvdDigiToHit.cxx:81
CbmMvdMimosa26AHR.h
CbmMvdDetector::AddPlugin
void AddPlugin(CbmMvdSensorPlugin *plugin)
Definition: CbmMvdDetector.cxx:186
CbmMvdDigiToHit::ReInit
virtual InitStatus ReInit()
Definition: CbmMvdDigiToHit.cxx:168
CbmMvdSensorDigiToHitTask.h
CbmMvdDigiToHit::Reset
void Reset()
Definition: CbmMvdDigiToHit.cxx:181