VMC Examples Version 6.6
Loading...
Searching...
No Matches
Ex03CalorimeterSD.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Virtual Monte Carlo examples
3// Copyright (C) 2014 - 2018 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
10/// \file Ex03CalorimeterSD.cxx
11/// \brief Implementation of the Ex03CalorimeterSD class
12///
13/// Geant4 ExampleN03 adapted to Virtual Monte Carlo \n
14/// Id: ExN03CalorimeterSD.cc,v 1.6 2002/01/09 17:24:12 ranjard Exp \n
15/// GEANT4 tag $Name: $
16///
17/// \date 06/03/2002
18/// \author I. Hrivnacova; IPN, Orsay
19
20#include "Ex03CalorimeterSD.h"
21#include "Ex03CalorHit.h"
22#include "Ex03DetectorConstruction.h"
23
24#include <Riostream.h>
25#include <TLorentzVector.h>
26#include <TMCRootManager.h>
27#include <TTree.h>
28#include <TVirtualMC.h>
29
30/// \cond CLASSIMP
31ClassImp(Ex03CalorimeterSD)
32 /// \endcond
33
34 using namespace std;
35
36//_____________________________________________________________________________
38 const char* name, Ex03DetectorConstruction* detector)
39 : TNamed(name, ""),
40 fMC(0),
41 fDetector(detector),
42 fCalCollection(0),
43 fAbsorberVolId(0),
44 fGapVolId(0),
45 fVerboseLevel(1)
46{
47 /// Standard constructor.
48 /// Create hits collection and an empty hit for each layer
49 /// As the copy numbers may start from 0 or 1 (depending on
50 /// geometry model, we create one more layer for this case.)
51 /// \param name The calorimeter hits collection name
52 /// \param detector The detector construction
53
54 fCalCollection = new TClonesArray("Ex03CalorHit", 500);
55 for (Int_t i = 0; i < fDetector->GetNbOfLayers() + 1; i++)
56 new ((*fCalCollection)[i]) Ex03CalorHit();
57}
58
59//_____________________________________________________________________________
61 const Ex03CalorimeterSD& origin, Ex03DetectorConstruction* detector)
62 : TNamed(origin),
63 fMC(0),
64 fDetector(detector),
65 fCalCollection(0),
66 fAbsorberVolId(origin.fAbsorberVolId),
67 fGapVolId(origin.fGapVolId),
68 fVerboseLevel(origin.fVerboseLevel)
69{
70 /// Copy constructor (for clonig on worker thread in MT mode).
71 /// Create hits collection and an empty hit for each layer
72 /// As the copy numbers may start from 0 or 1 (depending on
73 /// geometry model, we create one more layer for this case.)
74 /// \param origin The source object (on master).
75 /// \param detector The detector construction
76
77 fCalCollection = new TClonesArray("Ex03CalorHit", 500);
78 for (Int_t i = 0; i < fDetector->GetNbOfLayers() + 1; i++)
79 new ((*fCalCollection)[i]) Ex03CalorHit();
80}
81
82//_____________________________________________________________________________
84 : TNamed(),
85 fDetector(0),
86 fCalCollection(0),
87 fAbsorberVolId(0),
88 fGapVolId(0),
89 fVerboseLevel(1)
90{
91 /// Default constructor
92}
93
94//_____________________________________________________________________________
96{
97 /// Destructor
98
99 if (fCalCollection) fCalCollection->Delete();
100 delete fCalCollection;
101}
102
103//
104// private methods
105//
106
107//_____________________________________________________________________________
109{
110 /// \return The hit for the specified layer.
111 /// \param i The layer number
112
113 return (Ex03CalorHit*)fCalCollection->At(i);
114}
115
116//_____________________________________________________________________________
118{
119 /// Reset all hits in the hits collection.
120
121 for (Int_t i = 0; i < fCalCollection->GetEntriesFast(); i++)
122 GetHit(i)->Reset();
123}
124
125//
126// public methods
127//
128
129//_____________________________________________________________________________
131{
132 /// Register hits collection in the Root manager;
133 /// set sensitive volumes.
134
135 if (TMCRootManager::Instance()) Register();
136
137 // Keep the pointer to TVirtualMC object as a data member
138 // to avoid a possible performance penalty due to a frequent retrieval
139 // from the thread-local storage
140 fMC = gMC;
141
142 fAbsorberVolId = fMC->VolId("ABSO");
143 fGapVolId = fMC->VolId("GAPX");
144}
145
146//_____________________________________________________________________________
148{
149 /// Account energy deposit and track lengths for each layer in its hit.
150
151 Int_t copyNo;
152 Int_t id = fMC->CurrentVolID(copyNo);
153
154 if (id != fAbsorberVolId && id != fGapVolId) return false;
155
156 fMC->CurrentVolOffID(2, copyNo);
157 // cout << "Got copyNo "<< copyNo << " " << fMC->CurrentVolPath() << endl;
158
159 Double_t edep = fMC->Edep();
160
161 Double_t step = 0.;
162 if (fMC->TrackCharge() != 0.) step = fMC->TrackStep();
163
164 if (!GetHit(copyNo)) {
165 std::cerr << "No hit found for layer with copyNo = " << copyNo << endl;
166 return false;
167 }
168
169 if (id == fAbsorberVolId) {
170 GetHit(copyNo)->AddAbs(edep, step);
171 }
172
173 if (id == fGapVolId) {
174 GetHit(copyNo)->AddGap(edep, step);
175 }
176
177 return true;
178}
179
180//_____________________________________________________________________________
182{
183 /// Print hits collection (if verbose) and reset hits afterwards.
184
185 if (fVerboseLevel > 1) Print();
186
187 // Reset hits collection
188 ResetHits();
189}
190
191//_____________________________________________________________________________
193{
194 /// Register the hits collection in Root manager.
195
196 TMCRootManager::Instance()->Register("hits", "TClonesArray", &fCalCollection);
197}
198
199//_____________________________________________________________________________
200void Ex03CalorimeterSD::Print(Option_t* /*option*/) const
201{
202 /// Print the hits collection.
203
204 Int_t nofHits = fCalCollection->GetEntriesFast();
205
206 cout << "\n-------->Hits Collection: in this event: " << endl;
207
208 for (Int_t i = 0; i < nofHits; i++) (*fCalCollection)[i]->Print();
209}
210
211//_____________________________________________________________________________
213{
214 /// Print the total values for all layers.
215
216 Double_t totEAbs = 0.;
217 Double_t totLAbs = 0.;
218 Double_t totEGap = 0.;
219 Double_t totLGap = 0.;
220
221 Int_t nofHits = fCalCollection->GetEntriesFast();
222 for (Int_t i = 0; i < nofHits; i++) {
223 totEAbs += GetHit(i)->GetEdepAbs();
224 totLAbs += GetHit(i)->GetTrakAbs();
225 totEGap += GetHit(i)->GetEdepGap();
226 totLGap += GetHit(i)->GetTrakGap();
227 }
228
229 cout << " Absorber: total energy (MeV): " << setw(7) << totEAbs * 1.0e03
230 << " total track length (cm): " << setw(7) << totLAbs << endl
231 << " Gap: total energy (MeV): " << setw(7) << totEGap * 1.0e03
232 << " total track length (cm): " << setw(7) << totLGap << endl;
233}
Definition of the Ex03CalorimeterSD class.
The calorimeter hit.
Double_t GetEdepGap()
Double_t GetTrakGap()
void AddAbs(Double_t de, Double_t dl)
Double_t GetEdepAbs()
Double_t GetTrakAbs()
void AddGap(Double_t de, Double_t dl)
The calorimeter sensitive detector.
Ex03DetectorConstruction * fDetector
Detector construction.
TClonesArray * fCalCollection
Hits collection.
Int_t fVerboseLevel
Verbosity level.
Int_t fGapVolId
The gap volume Id.
Int_t fAbsorberVolId
The absorber volume Id.
Ex03CalorHit * GetHit(Int_t i) const
TVirtualMC * fMC
The VMC implementation.
virtual void Print(Option_t *option="") const
The detector construction (via TGeo )