VMC Examples
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
examples
E03
E03b
src
Ex03bCalorimeterSD.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 Ex03bCalorimeterSD.cxx
11
/// \brief Implementation of the Ex03bCalorimeterSD 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 18/12/2018
18
/// \author I. Hrivnacova; IPN, Orsay
19
20
#include "
Ex03bCalorimeterSD.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(
Ex03bCalorimeterSD
)
32
/// \endcond
33
34
using namespace
std;
35
36
//_____________________________________________________________________________
37
Ex03bCalorimeterSD::Ex03bCalorimeterSD
(
38
const
char
* name,
Ex03DetectorConstruction
* detector)
39
:
TVirtualMCSensitiveDetector
(name,
""
),
40
fMC
(0),
41
fDetector
(detector),
42
fCalCollection
(0),
43
fAbsorberVolId
(0),
44
fGapVolId
(0),
45
fVerboseLevel
(1),
46
fPrintModulo
(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
Ex03bCalorimeterSD::Ex03bCalorimeterSD
(
63
const
Ex03bCalorimeterSD
& origin,
Ex03DetectorConstruction
* detector)
64
:
TVirtualMCSensitiveDetector
(origin),
65
fMC
(0),
66
fDetector
(detector),
67
fCalCollection
(0),
68
fAbsorberVolId
(origin.
fAbsorberVolId
),
69
fGapVolId
(origin.
fGapVolId
),
70
fVerboseLevel
(origin.
fVerboseLevel
),
71
fPrintModulo
(origin.
fPrintModulo
),
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
Ex03bCalorimeterSD::Ex03bCalorimeterSD
()
88
:
TVirtualMCSensitiveDetector
(),
89
fDetector
(0),
90
fCalCollection
(0),
91
fAbsorberVolId
(0),
92
fGapVolId
(0),
93
fVerboseLevel
(1),
94
fReflectedHit
()
95
{
96
/// Default constructor
97
}
98
99
//_____________________________________________________________________________
100
Ex03bCalorimeterSD::~Ex03bCalorimeterSD
()
101
{
102
/// Destructor
103
104
if
(
fCalCollection
)
fCalCollection
->Delete();
105
delete
fCalCollection
;
106
}
107
108
//
109
// private methods
110
//
111
112
//_____________________________________________________________________________
113
Ex03CalorHit
*
Ex03bCalorimeterSD::GetHit
(Int_t i)
const
114
{
115
/// \return The hit for the specified layer.
116
/// \param i The layer number
117
118
return
(
Ex03CalorHit
*)
fCalCollection
->At(i);
119
}
120
121
//_____________________________________________________________________________
122
void
Ex03bCalorimeterSD::ResetHits
()
123
{
124
/// Reset all hits in the hits collection.
125
126
for
(Int_t i = 0; i <
fCalCollection
->GetEntriesFast(); i++)
127
GetHit
(i)->
Reset
();
128
}
129
130
//
131
// public methods
132
//
133
134
//_____________________________________________________________________________
135
void
Ex03bCalorimeterSD::Initialize
()
136
{
137
/// Register hits collection in the Root manager;
138
/// set sensitive volumes.
139
140
if
(TMCRootManager::Instance())
Register
();
141
142
// Keep the pointer to TVirtualMC object as a data member
143
// to avoid a possible performance penalty due to a frequent retrieval
144
// from the thread-local storage
145
fMC
= gMC;
146
147
fAbsorberVolId
=
fMC
->VolId(
"ABSO"
);
148
fGapVolId
=
fMC
->VolId(
"GAPX"
);
149
}
150
151
//_____________________________________________________________________________
152
void
Ex03bCalorimeterSD::ProcessHits
()
153
{
154
/// Account energy deposit and track lengths for each layer in its hit.
155
156
Int_t copyNo;
157
Int_t
id
=
fMC
->CurrentVolID(copyNo);
158
159
if
(
id
!=
fAbsorberVolId
&&
id
!=
fGapVolId
)
return
;
160
161
const
Bool_t reflected =
fDetector
->GetUseReflection() && copyNo == 2;
162
fMC
->CurrentVolOffID(2, copyNo);
163
164
Double_t edep =
fMC
->Edep();
165
166
Double_t step = 0.;
167
if
(
fMC
->TrackCharge() != 0.) step =
fMC
->TrackStep();
168
169
if
(!
GetHit
(copyNo)) {
170
return
;
171
}
172
173
if
(
id
==
fAbsorberVolId
) {
174
GetHit
(copyNo)->
AddAbs
(edep, step);
175
if
(reflected)
fReflectedHit
.AddAbs(edep, step);
176
}
177
178
if
(
id
==
fGapVolId
) {
179
GetHit
(copyNo)->
AddGap
(edep, step);
180
if
(reflected)
fReflectedHit
.AddGap(edep, step);
181
}
182
}
183
184
//_____________________________________________________________________________
185
void
Ex03bCalorimeterSD::EndOfEvent
()
186
{
187
/// Print hits collection (if verbose) and reset hits afterwards.
188
189
if
(gMC->CurrentEvent() %
fPrintModulo
== 0) {
190
PrintTotal
();
191
}
192
193
if
(
fVerboseLevel
> 1)
Print
();
194
195
if
(
fDetector
->GetUseReflection()) {
196
cout <<
" Reflected placements (included in layer totals):"
<< endl;
197
fReflectedHit
.Print();
198
}
199
if
(
fDetector
->GetRequireReflectedHits()) {
200
if
(
fReflectedHit
.GetEdepAbs() <= 0. ||
fReflectedHit
.GetTrakAbs() <= 0. ||
201
fReflectedHit
.GetEdepGap() <= 0. ||
fReflectedHit
.GetTrakGap() <= 0.) {
202
Fatal(
"EndOfEvent"
,
"Missing hits in reflected absorber or gap"
);
203
}
204
cout <<
" Reflected hits test passed"
<< endl;
205
}
206
fReflectedHit
.Reset();
207
208
// Reset hits collection
209
ResetHits
();
210
}
211
212
//_____________________________________________________________________________
213
void
Ex03bCalorimeterSD::Register
()
214
{
215
/// Register the hits collection in Root manager.
216
217
TMCRootManager::Instance()->Register(
"hits"
,
"TClonesArray"
, &
fCalCollection
);
218
}
219
220
//_____________________________________________________________________________
221
void
Ex03bCalorimeterSD::Print
(Option_t*
/*option*/
)
const
222
{
223
/// Print the hits collection.
224
225
Int_t nofHits =
fCalCollection
->GetEntriesFast();
226
227
cout <<
"\n-------->Hits Collection: in this event: "
<< endl;
228
229
for
(Int_t i = 0; i < nofHits; i++) (*
fCalCollection
)[i]->Print();
230
}
231
232
//_____________________________________________________________________________
233
void
Ex03bCalorimeterSD::PrintTotal
()
const
234
{
235
/// Print the total values for all layers.
236
237
Double_t totEAbs = 0.;
238
Double_t totLAbs = 0.;
239
Double_t totEGap = 0.;
240
Double_t totLGap = 0.;
241
242
Int_t nofHits =
fCalCollection
->GetEntriesFast();
243
for
(Int_t i = 0; i < nofHits; i++) {
244
totEAbs +=
GetHit
(i)->
GetEdepAbs
();
245
totLAbs +=
GetHit
(i)->
GetTrakAbs
();
246
totEGap +=
GetHit
(i)->
GetEdepGap
();
247
totLGap +=
GetHit
(i)->
GetTrakGap
();
248
}
249
250
cout <<
" Absorber: total energy (MeV): "
<< setw(7) << totEAbs * 1.0e03
251
<<
" total track length (cm): "
<< setw(7) << totLAbs << endl
252
<<
" Gap: total energy (MeV): "
<< setw(7) << totEGap * 1.0e03
253
<<
" total track length (cm): "
<< setw(7) << totLGap << endl;
254
}
Ex03bCalorimeterSD.h
Definition of the Ex03bCalorimeterSD 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
Ex03DetectorConstruction
The detector construction (via TGeo ).
Definition
Ex03DetectorConstruction.h:35
Ex03bCalorimeterSD
The calorimeter sensitive detector.
Definition
Ex03bCalorimeterSD.h:40
Ex03bCalorimeterSD::Register
void Register()
Definition
Ex03bCalorimeterSD.cxx:213
Ex03bCalorimeterSD::fReflectedHit
Ex03CalorHit fReflectedHit
Reflected contribution to the layer hits.
Definition
Ex03bCalorimeterSD.h:76
Ex03bCalorimeterSD::fMC
TVirtualMC * fMC
The VMC implementation.
Definition
Ex03bCalorimeterSD.h:68
Ex03bCalorimeterSD::Ex03bCalorimeterSD
Ex03bCalorimeterSD(const char *name, Ex03DetectorConstruction *detector)
Definition
Ex03bCalorimeterSD.cxx:37
Ex03bCalorimeterSD::ResetHits
void ResetHits()
Definition
Ex03bCalorimeterSD.cxx:122
Ex03bCalorimeterSD::fPrintModulo
Int_t fPrintModulo
The event modulus number to be printed.
Definition
Ex03bCalorimeterSD.h:74
Ex03bCalorimeterSD::fDetector
Ex03DetectorConstruction * fDetector
Detector construction.
Definition
Ex03bCalorimeterSD.h:69
Ex03bCalorimeterSD::PrintTotal
void PrintTotal() const
Definition
Ex03bCalorimeterSD.cxx:233
Ex03bCalorimeterSD::Initialize
void Initialize()
Definition
Ex03bCalorimeterSD.cxx:135
Ex03bCalorimeterSD::Ex03bCalorimeterSD
Ex03bCalorimeterSD()
Definition
Ex03bCalorimeterSD.cxx:87
Ex03bCalorimeterSD::Print
virtual void Print(Option_t *option="") const
Definition
Ex03bCalorimeterSD.cxx:221
Ex03bCalorimeterSD::fCalCollection
TClonesArray * fCalCollection
Hits collection.
Definition
Ex03bCalorimeterSD.h:70
Ex03bCalorimeterSD::fAbsorberVolId
Int_t fAbsorberVolId
The absorber volume Id.
Definition
Ex03bCalorimeterSD.h:71
Ex03bCalorimeterSD::GetHit
Ex03CalorHit * GetHit(Int_t i) const
Definition
Ex03bCalorimeterSD.cxx:113
Ex03bCalorimeterSD::fGapVolId
Int_t fGapVolId
The gap volume Id.
Definition
Ex03bCalorimeterSD.h:72
Ex03bCalorimeterSD::~Ex03bCalorimeterSD
virtual ~Ex03bCalorimeterSD()
Definition
Ex03bCalorimeterSD.cxx:100
Ex03bCalorimeterSD::EndOfEvent
void EndOfEvent()
Definition
Ex03bCalorimeterSD.cxx:185
Ex03bCalorimeterSD::ProcessHits
virtual void ProcessHits()
Definition
Ex03bCalorimeterSD.cxx:152
Ex03bCalorimeterSD::fVerboseLevel
Int_t fVerboseLevel
Verbosity level.
Definition
Ex03bCalorimeterSD.h:73
TVirtualMCSensitiveDetector
Generated on
for VMC Examples by
1.17.0