VMC Examples
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
examples
E03
E03a
src
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
31
ClassImp(
Ex03CalorimeterSD
)
32
/// \endcond
33
34
using namespace
std;
35
36
//_____________________________________________________________________________
37
Ex03CalorimeterSD::Ex03CalorimeterSD
(
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
fAssemblyHierarchyPrinted
(kFALSE),
46
fVerboseLevel
(1)
47
{
48
/// Standard constructor.
49
/// Create hits collection and an empty hit for each layer
50
/// As the copy numbers may start from 0 or 1 (depending on
51
/// geometry model, we create one more layer for this case.)
52
/// \param name The calorimeter hits collection name
53
/// \param detector The detector construction
54
55
fCalCollection
=
new
TClonesArray(
"Ex03CalorHit"
, 500);
56
for
(Int_t i = 0; i <
fDetector
->GetNbOfLayers() + 1; i++)
57
new
((*
fCalCollection
)[i])
Ex03CalorHit
();
58
}
59
60
//_____________________________________________________________________________
61
Ex03CalorimeterSD::Ex03CalorimeterSD
(
62
const
Ex03CalorimeterSD
& origin,
Ex03DetectorConstruction
* detector)
63
:
TNamed
(origin),
64
fMC
(0),
65
fDetector
(detector),
66
fCalCollection
(0),
67
fAbsorberVolId
(origin.
fAbsorberVolId
),
68
fGapVolId
(origin.
fGapVolId
),
69
fAssemblyHierarchyPrinted
(kFALSE),
70
fVerboseLevel
(origin.
fVerboseLevel
)
71
{
72
/// Copy constructor (for clonig on worker thread in MT mode).
73
/// Create hits collection and an empty hit for each layer
74
/// As the copy numbers may start from 0 or 1 (depending on
75
/// geometry model, we create one more layer for this case.)
76
/// \param origin The source object (on master).
77
/// \param detector The detector construction
78
79
fCalCollection
=
new
TClonesArray(
"Ex03CalorHit"
, 500);
80
for
(Int_t i = 0; i <
fDetector
->GetNbOfLayers() + 1; i++)
81
new
((*
fCalCollection
)[i])
Ex03CalorHit
();
82
}
83
84
//_____________________________________________________________________________
85
Ex03CalorimeterSD::Ex03CalorimeterSD
()
86
:
TNamed
(),
87
fDetector
(0),
88
fCalCollection
(0),
89
fAbsorberVolId
(0),
90
fGapVolId
(0),
91
fAssemblyHierarchyPrinted
(kFALSE),
92
fVerboseLevel
(1)
93
{
94
/// Default constructor
95
}
96
97
//_____________________________________________________________________________
98
Ex03CalorimeterSD::~Ex03CalorimeterSD
()
99
{
100
/// Destructor
101
102
if
(
fCalCollection
)
fCalCollection
->Delete();
103
delete
fCalCollection
;
104
}
105
106
//
107
// private methods
108
//
109
110
//_____________________________________________________________________________
111
Ex03CalorHit
*
Ex03CalorimeterSD::GetHit
(Int_t i)
const
112
{
113
/// \return The hit for the specified layer.
114
/// \param i The layer number
115
116
return
(
Ex03CalorHit
*)
fCalCollection
->At(i);
117
}
118
119
//_____________________________________________________________________________
120
void
Ex03CalorimeterSD::ResetHits
()
121
{
122
/// Reset all hits in the hits collection.
123
124
for
(Int_t i = 0; i <
fCalCollection
->GetEntriesFast(); i++)
125
GetHit
(i)->
Reset
();
126
}
127
128
//
129
// public methods
130
//
131
132
//_____________________________________________________________________________
133
void
Ex03CalorimeterSD::Initialize
()
134
{
135
/// Register hits collection in the Root manager;
136
/// set sensitive volumes.
137
138
if
(TMCRootManager::Instance())
Register
();
139
140
// Keep the pointer to TVirtualMC object as a data member
141
// to avoid a possible performance penalty due to a frequent retrieval
142
// from the thread-local storage
143
fMC
= gMC;
144
145
fAbsorberVolId
=
fMC
->VolId(
"ABSO"
);
146
fGapVolId
=
fMC
->VolId(
"GAPX"
);
147
}
148
149
//_____________________________________________________________________________
150
Bool_t
Ex03CalorimeterSD::ProcessHits
()
151
{
152
/// Account energy deposit and track lengths for each layer in its hit.
153
154
Int_t copyNo;
155
Int_t
id
=
fMC
->CurrentVolID(copyNo);
156
157
if
(
id
!=
fAbsorberVolId
&&
id
!=
fGapVolId
)
return
false
;
158
159
if
(
fDetector
->GetUseAssemblies() && !
fAssemblyHierarchyPrinted
) {
160
fAssemblyHierarchyPrinted
= kTRUE;
161
cout <<
"Assembly volume hierarchy:"
<< endl;
162
for
(Int_t off = 0; off <= 6; ++off) {
163
Int_t offCopyNo = -1;
164
TString offName =
fMC
->CurrentVolOffName(off);
165
Int_t offId =
fMC
->CurrentVolOffID(off, offCopyNo);
166
cout <<
" off="
<< off <<
" name="
<< offName <<
" id="
<< offId
167
<<
" copyNo="
<< offCopyNo << endl;
168
}
169
}
170
171
fMC
->CurrentVolOffID(2, copyNo);
172
// cout << "Got copyNo "<< copyNo << " " << fMC->CurrentVolPath() << endl;
173
174
Double_t edep =
fMC
->Edep();
175
176
Double_t step = 0.;
177
if
(
fMC
->TrackCharge() != 0.) step =
fMC
->TrackStep();
178
179
if
(!
GetHit
(copyNo)) {
180
std::cerr <<
"No hit found for layer with copyNo = "
<< copyNo << endl;
181
return
false
;
182
}
183
184
if
(
id
==
fAbsorberVolId
) {
185
GetHit
(copyNo)->
AddAbs
(edep, step);
186
}
187
188
if
(
id
==
fGapVolId
) {
189
GetHit
(copyNo)->
AddGap
(edep, step);
190
}
191
192
return
true
;
193
}
194
195
//_____________________________________________________________________________
196
void
Ex03CalorimeterSD::EndOfEvent
()
197
{
198
/// Print hits collection (if verbose) and reset hits afterwards.
199
200
if
(
fVerboseLevel
> 1)
Print
();
201
202
// Reset hits collection
203
ResetHits
();
204
}
205
206
//_____________________________________________________________________________
207
void
Ex03CalorimeterSD::Register
()
208
{
209
/// Register the hits collection in Root manager.
210
211
TMCRootManager::Instance()->Register(
"hits"
,
"TClonesArray"
, &
fCalCollection
);
212
}
213
214
//_____________________________________________________________________________
215
void
Ex03CalorimeterSD::Print
(Option_t*
/*option*/
)
const
216
{
217
/// Print the hits collection.
218
219
Int_t nofHits =
fCalCollection
->GetEntriesFast();
220
221
cout <<
"\n-------->Hits Collection: in this event: "
<< endl;
222
223
for
(Int_t i = 0; i < nofHits; i++) (*
fCalCollection
)[i]->Print();
224
}
225
226
//_____________________________________________________________________________
227
void
Ex03CalorimeterSD::PrintTotal
()
const
228
{
229
/// Print the total values for all layers.
230
231
Double_t totEAbs = 0.;
232
Double_t totLAbs = 0.;
233
Double_t totEGap = 0.;
234
Double_t totLGap = 0.;
235
236
Int_t nofHits =
fCalCollection
->GetEntriesFast();
237
for
(Int_t i = 0; i < nofHits; i++) {
238
totEAbs +=
GetHit
(i)->
GetEdepAbs
();
239
totLAbs +=
GetHit
(i)->
GetTrakAbs
();
240
totEGap +=
GetHit
(i)->
GetEdepGap
();
241
totLGap +=
GetHit
(i)->
GetTrakGap
();
242
}
243
244
cout <<
" Absorber: total energy (MeV): "
<< setw(7) << totEAbs * 1.0e03
245
<<
" total track length (cm): "
<< setw(7) << totLAbs << endl
246
<<
" Gap: total energy (MeV): "
<< setw(7) << totEGap * 1.0e03
247
<<
" total track length (cm): "
<< setw(7) << totLGap << endl;
248
}
Ex03CalorimeterSD.h
Definition of the Ex03CalorimeterSD class.
Ex03CalorHit
The calorimeter hit.
Definition
Ex03CalorHit.h:32
Ex03CalorHit::Reset
void Reset()
Definition
Ex03CalorHit.cxx:61
Ex03CalorHit::GetEdepGap
Double_t GetEdepGap()
Definition
Ex03CalorHit.h:66
Ex03CalorHit::GetTrakGap
Double_t GetTrakGap()
Definition
Ex03CalorHit.h:68
Ex03CalorHit::AddAbs
void AddAbs(Double_t de, Double_t dl)
Definition
Ex03CalorHit.h:43
Ex03CalorHit::GetEdepAbs
Double_t GetEdepAbs()
Definition
Ex03CalorHit.h:62
Ex03CalorHit::GetTrakAbs
Double_t GetTrakAbs()
Definition
Ex03CalorHit.h:64
Ex03CalorHit::AddGap
void AddGap(Double_t de, Double_t dl)
Definition
Ex03CalorHit.h:52
Ex03CalorimeterSD
The calorimeter sensitive detector.
Definition
Ex03CalorimeterSD.h:36
Ex03CalorimeterSD::fDetector
Ex03DetectorConstruction * fDetector
Detector construction.
Definition
Ex03CalorimeterSD.h:64
Ex03CalorimeterSD::fCalCollection
TClonesArray * fCalCollection
Hits collection.
Definition
Ex03CalorimeterSD.h:65
Ex03CalorimeterSD::EndOfEvent
void EndOfEvent()
Definition
Ex03CalorimeterSD.cxx:196
Ex03CalorimeterSD::ProcessHits
Bool_t ProcessHits()
Definition
Ex03CalorimeterSD.cxx:150
Ex03CalorimeterSD::fVerboseLevel
Int_t fVerboseLevel
Verbosity level.
Definition
Ex03CalorimeterSD.h:69
Ex03CalorimeterSD::~Ex03CalorimeterSD
virtual ~Ex03CalorimeterSD()
Definition
Ex03CalorimeterSD.cxx:98
Ex03CalorimeterSD::fAssemblyHierarchyPrinted
Bool_t fAssemblyHierarchyPrinted
Whether assembly levels were printed.
Definition
Ex03CalorimeterSD.h:68
Ex03CalorimeterSD::fGapVolId
Int_t fGapVolId
The gap volume Id.
Definition
Ex03CalorimeterSD.h:67
Ex03CalorimeterSD::ResetHits
void ResetHits()
Definition
Ex03CalorimeterSD.cxx:120
Ex03CalorimeterSD::Register
void Register()
Definition
Ex03CalorimeterSD.cxx:207
Ex03CalorimeterSD::fAbsorberVolId
Int_t fAbsorberVolId
The absorber volume Id.
Definition
Ex03CalorimeterSD.h:66
Ex03CalorimeterSD::GetHit
Ex03CalorHit * GetHit(Int_t i) const
Definition
Ex03CalorimeterSD.cxx:111
Ex03CalorimeterSD::fMC
TVirtualMC * fMC
The VMC implementation.
Definition
Ex03CalorimeterSD.h:63
Ex03CalorimeterSD::PrintTotal
void PrintTotal() const
Definition
Ex03CalorimeterSD.cxx:227
Ex03CalorimeterSD::Ex03CalorimeterSD
Ex03CalorimeterSD(const char *name, Ex03DetectorConstruction *detector)
Definition
Ex03CalorimeterSD.cxx:37
Ex03CalorimeterSD::Initialize
void Initialize()
Definition
Ex03CalorimeterSD.cxx:133
Ex03CalorimeterSD::Print
virtual void Print(Option_t *option="") const
Definition
Ex03CalorimeterSD.cxx:215
Ex03CalorimeterSD::Ex03CalorimeterSD
Ex03CalorimeterSD()
Definition
Ex03CalorimeterSD.cxx:85
Ex03DetectorConstruction
The detector construction (via TGeo ).
Definition
Ex03DetectorConstruction.h:35
TNamed
Generated on
for VMC Examples by
1.17.0