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