VMC Examples
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
examples
A01
src
A01EmCalorimeterSD.cxx
Go to the documentation of this file.
1
//------------------------------------------------
2
// The Virtual Monte Carlo examples
3
// Copyright (C) 2007 - 2014 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 A01EmCalorimeterSD.cxx
11
/// \brief Implementation of the A01EmCalorimeterSD class
12
///
13
/// Geant4 example A01 adapted to Virtual Monte Carlo \n
14
///
15
/// \date 12/05/2012
16
/// \author I. Hrivnacova; IPN, Orsay
17
18
#include <Riostream.h>
19
#include <TLorentzVector.h>
20
#include <TMCRootManager.h>
21
#include <TTree.h>
22
#include <TVirtualMC.h>
23
24
#include "
A01EmCalorHit.h
"
25
#include "
A01EmCalorimeterSD.h
"
26
27
/// \cond CLASSIMP
28
ClassImp(
A01EmCalorimeterSD
)
29
/// \endcond
30
31
using namespace
std;
32
33
const
Int_t
A01EmCalorimeterSD::fgkNofColumns
= 20;
34
const
Int_t
A01EmCalorimeterSD::fgkNofRows
= 4;
35
36
//_____________________________________________________________________________
37
A01EmCalorimeterSD::A01EmCalorimeterSD
(
const
char
* name)
38
:
TNamed
(name,
""
),
39
fCalCollection
(0),
40
fVolId
(0),
41
fWriteHits
(true),
42
fVerboseLevel
(1)
43
{
44
/// Standard constructor.
45
/// Create hits collection and an empty hit for each layer.
46
/// \param name The calorimeter hits collection name
47
48
fCalCollection
=
49
new
TClonesArray(
"A01EmCalorHit"
,
fgkNofColumns
*
fgkNofRows
);
50
for
(Int_t i = 0; i <
fgkNofColumns
*
fgkNofRows
; i++)
51
new
((*
fCalCollection
)[i])
A01EmCalorHit
();
52
}
53
54
//_____________________________________________________________________________
55
A01EmCalorimeterSD::A01EmCalorimeterSD
(
const
A01EmCalorimeterSD
& origin)
56
:
TNamed
(origin),
57
fCalCollection
(0),
58
fVolId
(origin.
fVolId
),
59
fWriteHits
(origin.
fWriteHits
),
60
fVerboseLevel
(origin.
fVerboseLevel
)
61
{
62
/// Copy constructor (for clonig on worker thread in MT mode).
63
/// Create hits collection and an empty hit for each layer
64
/// \param origin The source object (on master).
65
66
fCalCollection
=
67
new
TClonesArray(
"A01EmCalorHit"
,
fgkNofColumns
*
fgkNofRows
);
68
for
(Int_t i = 0; i <
fgkNofColumns
*
fgkNofRows
; i++)
69
new
((*
fCalCollection
)[i])
A01EmCalorHit
();
70
}
71
72
//_____________________________________________________________________________
73
A01EmCalorimeterSD::A01EmCalorimeterSD
()
74
:
TNamed
(),
fCalCollection
(0),
fVolId
(0),
fWriteHits
(true),
fVerboseLevel
(1)
75
{
76
/// Default constructor
77
}
78
79
//_____________________________________________________________________________
80
A01EmCalorimeterSD::~A01EmCalorimeterSD
()
81
{
82
/// Destructor
83
84
if
(
fCalCollection
)
fCalCollection
->Delete();
85
delete
fCalCollection
;
86
}
87
88
//
89
// private methods
90
//
91
92
//_____________________________________________________________________________
93
void
A01EmCalorimeterSD::ResetHits
()
94
{
95
/// Reset all hits in the hits collection.
96
97
for
(Int_t i = 0; i <
fCalCollection
->GetEntriesFast(); i++)
98
GetHit
(i)->
Reset
();
99
}
100
101
//
102
// public methods
103
//
104
105
//_____________________________________________________________________________
106
void
A01EmCalorimeterSD::Initialize
()
107
{
108
/// Register hits collection in the Root manager;
109
/// set sensitive volumes.
110
111
if
(TMCRootManager::Instance())
Register
();
112
113
fVolId
= gMC->VolId(
"cellLogical"
);
114
}
115
116
//_____________________________________________________________________________
117
Bool_t
A01EmCalorimeterSD::ProcessHits
()
118
{
119
/// Account energy deposit for each layer in its hit.
120
121
Int_t copyNo;
122
Int_t
id
= gMC->CurrentVolID(copyNo);
123
if
(
id
!=
fVolId
)
return
false
;
124
125
Double_t edep = gMC->Edep();
126
if
(edep == 0.)
return
false
;
127
128
Int_t rowNo = copyNo;
129
Int_t columnNo;
130
gMC->CurrentVolOffID(1, columnNo);
131
// VMC adopts Root numbering of divisions starting from 1
132
rowNo--;
133
columnNo--;
134
Int_t hitID =
fgkNofRows
* columnNo + rowNo;
135
136
A01EmCalorHit
* hit =
GetHit
(hitID);
137
if
(!hit) {
138
std::cerr <<
"No hit found for layer with copyNo = "
<< copyNo << endl;
139
return
false
;
140
}
141
142
// check if it is the first touch
143
if
(hit->
GetVolId
() < 0) {
144
// Debug printing (to check hits indexing)
145
// cout << "EmCalorimeter: First Add in hit in (column, row): "
146
// << columnNo << ", " << rowNo << endl;
147
// cout << "gMC->CurrentVolName(), gMC->CurrentVolOffName(1): "
148
// << gMC->CurrentVolName() << ", " << gMC->CurrentVolOffName(1) <<
149
// endl;
150
151
// fill volume information
152
hit->
SetVolId
(
fVolId
);
153
// get transformation
154
// add later
155
}
156
157
// cout << "Adding edep [MeV]" << edep*1e03 << " in copyNo " << copyNo <<
158
// endl;
159
160
// add energy deposition
161
hit->
AddEdep
(edep);
162
163
return
true
;
164
}
165
166
//_____________________________________________________________________________
167
void
A01EmCalorimeterSD::EndOfEvent
()
168
{
169
/// Print hits collection (if verbose) and reset hits afterwards.
170
171
if
(
fVerboseLevel
> 0)
PrintTotal
();
172
173
// Reset hits collection
174
ResetHits
();
175
}
176
177
//_____________________________________________________________________________
178
void
A01EmCalorimeterSD::Register
()
179
{
180
/// Register the hits collection in Root manager.
181
182
if
(
fWriteHits
) {
183
TMCRootManager::Instance()->Register(
184
GetName(),
"TClonesArray"
, &
fCalCollection
);
185
}
186
}
187
188
//_____________________________________________________________________________
189
void
A01EmCalorimeterSD::Print
(Option_t*
/*option*/
)
const
190
{
191
/// Print the hits collection.
192
193
Int_t nofHits =
fCalCollection
->GetEntriesFast();
194
195
cout <<
"\n-------->Hits Collection: in this event: "
<< endl;
196
197
if
(
fVerboseLevel
> 1) {
198
for
(Int_t i = 0; i < nofHits; i++) (*
fCalCollection
)[i]->Print();
199
}
200
}
201
202
//_____________________________________________________________________________
203
void
A01EmCalorimeterSD::PrintTotal
()
const
204
{
205
/// Print the total values for all layers.
206
207
Int_t nofHits = 0;
208
Double_t totalEdep = 0.;
209
for
(Int_t i = 0; i <
fgkNofColumns
*
fgkNofRows
; ++i) {
210
Double_t edep =
GetHit
(i)->
GetEdep
();
211
if
(edep > 0.) {
212
nofHits++;
213
totalEdep += edep;
214
}
215
}
216
cout << GetName() <<
" has "
<< nofHits <<
" hits. Total Edep is "
217
<< totalEdep * 1e03 <<
" (MeV)"
<< endl;
218
}
219
220
//_____________________________________________________________________________
221
A01EmCalorHit
*
A01EmCalorimeterSD::GetHit
(Int_t i)
const
222
{
223
/// \return The hit for the specified layer.
224
/// \param i The layer number
225
226
return
(
A01EmCalorHit
*)
fCalCollection
->At(i);
227
}
A01EmCalorHit.h
Definition of the A01EmCalorHit class.
A01EmCalorimeterSD.h
Definition of the A01EmCalorimeterSD class.
A01EmCalorHit
The EM calorimeter hit.
Definition
A01EmCalorHit.h:31
A01EmCalorHit::AddEdep
void AddEdep(Double_t de)
Definition
A01EmCalorHit.h:45
A01EmCalorHit::Reset
void Reset()
Definition
A01EmCalorHit.cxx:58
A01EmCalorHit::GetEdep
Double_t GetEdep() const
Definition
A01EmCalorHit.h:54
A01EmCalorHit::GetVolId
Int_t GetVolId() const
Definition
A01EmCalorHit.h:53
A01EmCalorHit::SetVolId
void SetVolId(Int_t volId)
Definition
A01EmCalorHit.h:43
A01EmCalorimeterSD
The EM calorimeter sensitive detector.
Definition
A01EmCalorimeterSD.h:31
A01EmCalorimeterSD::fVolId
Int_t fVolId
The calorimeter volume Id.
Definition
A01EmCalorimeterSD.h:63
A01EmCalorimeterSD::A01EmCalorimeterSD
A01EmCalorimeterSD(const char *name)
Definition
A01EmCalorimeterSD.cxx:37
A01EmCalorimeterSD::EndOfEvent
void EndOfEvent()
Definition
A01EmCalorimeterSD.cxx:167
A01EmCalorimeterSD::Register
void Register()
Definition
A01EmCalorimeterSD.cxx:178
A01EmCalorimeterSD::GetHit
A01EmCalorHit * GetHit(Int_t i) const
Definition
A01EmCalorimeterSD.cxx:221
A01EmCalorimeterSD::fgkNofRows
static const Int_t fgkNofRows
Definition
A01EmCalorimeterSD.h:59
A01EmCalorimeterSD::~A01EmCalorimeterSD
virtual ~A01EmCalorimeterSD()
Definition
A01EmCalorimeterSD.cxx:80
A01EmCalorimeterSD::Print
virtual void Print(Option_t *option="") const
Definition
A01EmCalorimeterSD.cxx:189
A01EmCalorimeterSD::ProcessHits
Bool_t ProcessHits()
Definition
A01EmCalorimeterSD.cxx:117
A01EmCalorimeterSD::fWriteHits
Bool_t fWriteHits
Option to write hits.
Definition
A01EmCalorimeterSD.h:64
A01EmCalorimeterSD::Initialize
void Initialize()
Definition
A01EmCalorimeterSD.cxx:106
A01EmCalorimeterSD::fVerboseLevel
Int_t fVerboseLevel
Verbosity level.
Definition
A01EmCalorimeterSD.h:65
A01EmCalorimeterSD::fCalCollection
TClonesArray * fCalCollection
Hits collection.
Definition
A01EmCalorimeterSD.h:62
A01EmCalorimeterSD::PrintTotal
void PrintTotal() const
Definition
A01EmCalorimeterSD.cxx:203
A01EmCalorimeterSD::ResetHits
void ResetHits()
Definition
A01EmCalorimeterSD.cxx:93
A01EmCalorimeterSD::fgkNofColumns
static const Int_t fgkNofColumns
Definition
A01EmCalorimeterSD.h:58
A01EmCalorimeterSD::A01EmCalorimeterSD
A01EmCalorimeterSD()
Definition
A01EmCalorimeterSD.cxx:73
TNamed
Generated on
for VMC Examples by
1.17.0