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