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