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