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