VMC Examples
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
examples
E03
E03c
src
Ex03cCalorimeterSD.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 Ex03cCalorimeterSD.cxx
11
/// \brief Implementation of the Ex03cCalorimeterSD 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 21/08/2019
18
/// \author Benedikt Volkel, CERN
19
20
#include "
Ex03cCalorimeterSD.h
"
21
#include "Ex03CalorHit.h"
22
#include "
Ex03cDetectorConstruction.h
"
23
24
#include <Riostream.h>
25
#include <TLorentzVector.h>
26
#include <TMCManager.h>
27
#include <TMCRootManager.h>
28
#include <TTree.h>
29
#include <TVirtualMC.h>
30
31
/// \cond CLASSIMP
32
ClassImp(
Ex03cCalorimeterSD
)
33
/// \endcond
34
35
using namespace
std;
36
37
//_____________________________________________________________________________
38
Ex03cCalorimeterSD::Ex03cCalorimeterSD
(
39
const
char
* name,
Ex03cDetectorConstruction
* detector)
40
:
TNamed
(name,
""
),
41
fMC
(0),
42
fDetector
(detector),
43
fCalCollection
(0),
44
fAbsorberVolId
(0),
45
fGapVolId
(0),
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
Ex03cCalorimeterSD::Ex03cCalorimeterSD
(
62
const
Ex03cCalorimeterSD
& origin,
Ex03cDetectorConstruction
* detector)
63
:
TNamed
(origin),
64
fMC
(0),
65
fDetector
(detector),
66
fCalCollection
(0),
67
fAbsorberVolId
(origin.
fAbsorberVolId
),
68
fGapVolId
(origin.
fGapVolId
),
69
fVerboseLevel
(origin.
fVerboseLevel
)
70
{
71
/// Copy constructor (for clonig on worker thread in MT mode).
72
/// Create hits collection and an empty hit for each layer
73
/// As the copy numbers may start from 0 or 1 (depending on
74
/// geometry model, we create one more layer for this case.)
75
/// \param origin The source object (on master).
76
/// \param detector The detector construction
77
78
fCalCollection
=
new
TClonesArray(
"Ex03CalorHit"
, 500);
79
for
(Int_t i = 0; i <
fDetector
->GetNbOfLayers() + 1; i++)
80
new
((*
fCalCollection
)[i])
Ex03CalorHit
();
81
}
82
83
//_____________________________________________________________________________
84
Ex03cCalorimeterSD::Ex03cCalorimeterSD
()
85
:
TNamed
(),
86
fDetector
(0),
87
fCalCollection
(0),
88
fAbsorberVolId
(0),
89
fGapVolId
(0),
90
fVerboseLevel
(1)
91
{
92
/// Default constructor
93
}
94
95
//_____________________________________________________________________________
96
Ex03cCalorimeterSD::~Ex03cCalorimeterSD
()
97
{
98
/// Destructor
99
100
if
(
fCalCollection
)
fCalCollection
->Delete();
101
delete
fCalCollection
;
102
}
103
104
//
105
// private methods
106
//
107
108
//_____________________________________________________________________________
109
Ex03CalorHit
*
Ex03cCalorimeterSD::GetHit
(Int_t i)
const
110
{
111
/// \return The hit for the specified layer.
112
/// \param i The layer number
113
114
return
(
Ex03CalorHit
*)
fCalCollection
->At(i);
115
}
116
117
//_____________________________________________________________________________
118
void
Ex03cCalorimeterSD::ResetHits
()
119
{
120
/// Reset all hits in the hits collection.
121
122
for
(Int_t i = 0; i <
fCalCollection
->GetEntriesFast(); i++)
123
GetHit
(i)->
Reset
();
124
}
125
126
//
127
// public methods
128
//
129
130
//_____________________________________________________________________________
131
void
Ex03cCalorimeterSD::Initialize
()
132
{
133
/// Register hits collection in the Root manager;
134
/// set sensitive volumes.
135
136
if
(TMCRootManager::Instance())
Register
();
137
138
// Keep the pointer to TVirtualMC object as a data member
139
// to avoid a possible performance penalty due to a frequent retrieval
140
// from the thread-local storage
141
if
(TMCManager::Instance()) {
142
TMCManager::Instance()->ConnectEnginePointer(
fMC
);
143
}
144
else
{
145
fMC
= gMC;
146
}
147
148
fAbsorberVolId
=
fMC
->VolId(
"ABSO"
);
149
fGapVolId
=
fMC
->VolId(
"GAPX"
);
150
}
151
152
//_____________________________________________________________________________
153
Bool_t
Ex03cCalorimeterSD::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
fMC
->CurrentVolOffID(2, copyNo);
163
// cout << "Got copyNo "<< copyNo << " " << fMC->CurrentVolPath() << endl;
164
165
Double_t edep =
fMC
->Edep();
166
167
Double_t step = 0.;
168
if
(
fMC
->TrackCharge() != 0.) step =
fMC
->TrackStep();
169
170
if
(!
GetHit
(copyNo)) {
171
std::cerr <<
"No hit found for layer with copyNo = "
<< copyNo << endl;
172
return
false
;
173
}
174
175
if
(
id
==
fAbsorberVolId
) {
176
GetHit
(copyNo)->
AddAbs
(edep, step);
177
}
178
179
if
(
id
==
fGapVolId
) {
180
GetHit
(copyNo)->
AddGap
(edep, step);
181
}
182
183
return
true
;
184
}
185
186
//_____________________________________________________________________________
187
void
Ex03cCalorimeterSD::EndOfEvent
()
188
{
189
/// Print hits collection (if verbose) and reset hits afterwards.
190
191
if
(
fVerboseLevel
> 1)
Print
();
192
193
// Reset hits collection
194
ResetHits
();
195
}
196
197
//_____________________________________________________________________________
198
void
Ex03cCalorimeterSD::Register
()
199
{
200
/// Register the hits collection in Root manager.
201
202
TMCRootManager::Instance()->Register(
"hits"
,
"TClonesArray"
, &
fCalCollection
);
203
}
204
205
//_____________________________________________________________________________
206
void
Ex03cCalorimeterSD::Print
(Option_t*
/*option*/
)
const
207
{
208
/// Print the hits collection.
209
210
Int_t nofHits =
fCalCollection
->GetEntriesFast();
211
212
cout <<
"\n-------->Hits Collection: in this event: "
<< endl;
213
214
for
(Int_t i = 0; i < nofHits; i++) (*
fCalCollection
)[i]->Print();
215
}
216
217
//_____________________________________________________________________________
218
void
Ex03cCalorimeterSD::PrintTotal
()
const
219
{
220
/// Print the total values for all layers.
221
222
Double_t totEAbs = 0.;
223
Double_t totLAbs = 0.;
224
Double_t totEGap = 0.;
225
Double_t totLGap = 0.;
226
227
Int_t nofHits =
fCalCollection
->GetEntriesFast();
228
for
(Int_t i = 0; i < nofHits; i++) {
229
totEAbs +=
GetHit
(i)->
GetEdepAbs
();
230
totLAbs +=
GetHit
(i)->
GetTrakAbs
();
231
totEGap +=
GetHit
(i)->
GetEdepGap
();
232
totLGap +=
GetHit
(i)->
GetTrakGap
();
233
}
234
235
cout <<
" Absorber: total energy (MeV): "
<< setw(7) << totEAbs * 1.0e03
236
<<
" total track length (cm): "
<< setw(7) << totLAbs << endl
237
<<
" Gap: total energy (MeV): "
<< setw(7) << totEGap * 1.0e03
238
<<
" total track length (cm): "
<< setw(7) << totLGap << endl;
239
}
Ex03cCalorimeterSD.h
Definition of the Ex03cCalorimeterSD class.
Ex03cDetectorConstruction.h
Definition of the Ex03cDetectorConstruction 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
Ex03cCalorimeterSD
The calorimeter sensitive detector.
Definition
Ex03cCalorimeterSD.h:39
Ex03cCalorimeterSD::~Ex03cCalorimeterSD
virtual ~Ex03cCalorimeterSD()
Definition
Ex03cCalorimeterSD.cxx:96
Ex03cCalorimeterSD::fAbsorberVolId
Int_t fAbsorberVolId
The absorber volume Id.
Definition
Ex03cCalorimeterSD.h:69
Ex03cCalorimeterSD::Ex03cCalorimeterSD
Ex03cCalorimeterSD(const char *name, Ex03cDetectorConstruction *detector)
Definition
Ex03cCalorimeterSD.cxx:38
Ex03cCalorimeterSD::PrintTotal
void PrintTotal() const
Definition
Ex03cCalorimeterSD.cxx:218
Ex03cCalorimeterSD::fVerboseLevel
Int_t fVerboseLevel
Verbosity level.
Definition
Ex03cCalorimeterSD.h:71
Ex03cCalorimeterSD::Ex03cCalorimeterSD
Ex03cCalorimeterSD()
Definition
Ex03cCalorimeterSD.cxx:84
Ex03cCalorimeterSD::ProcessHits
Bool_t ProcessHits()
Definition
Ex03cCalorimeterSD.cxx:153
Ex03cCalorimeterSD::fGapVolId
Int_t fGapVolId
The gap volume Id.
Definition
Ex03cCalorimeterSD.h:70
Ex03cCalorimeterSD::GetHit
Ex03CalorHit * GetHit(Int_t i) const
Definition
Ex03cCalorimeterSD.cxx:109
Ex03cCalorimeterSD::Initialize
void Initialize()
Definition
Ex03cCalorimeterSD.cxx:131
Ex03cCalorimeterSD::Register
void Register()
Definition
Ex03cCalorimeterSD.cxx:198
Ex03cCalorimeterSD::fMC
TVirtualMC * fMC
The VMC implementation.
Definition
Ex03cCalorimeterSD.h:66
Ex03cCalorimeterSD::Print
virtual void Print(Option_t *option="") const
Definition
Ex03cCalorimeterSD.cxx:206
Ex03cCalorimeterSD::fDetector
Ex03cDetectorConstruction * fDetector
Detector construction.
Definition
Ex03cCalorimeterSD.h:67
Ex03cCalorimeterSD::EndOfEvent
void EndOfEvent()
Definition
Ex03cCalorimeterSD.cxx:187
Ex03cCalorimeterSD::ResetHits
void ResetHits()
Definition
Ex03cCalorimeterSD.cxx:118
Ex03cCalorimeterSD::fCalCollection
TClonesArray * fCalCollection
Hits collection.
Definition
Ex03cCalorimeterSD.h:68
Ex03cDetectorConstruction
The detector construction (via TGeo ).
Definition
Ex03cDetectorConstruction.h:40
TNamed
Generated on
for VMC Examples by
1.17.0