VMC Examples
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
examples
ExGarfield
src
SensitiveDetector.cxx
Go to the documentation of this file.
1
//------------------------------------------------
2
// The Virtual Monte Carlo examples
3
// Copyright (C) 2007 - 2016 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 ExGarfield/src/SensitiveDetector.cxx
11
/// \brief Implementation of the ExGarfield::SensitiveDetector class
12
///
13
/// Garfield garfieldpp example adapted to Virtual Monte Carlo.
14
///
15
/// \date 28/10/2015
16
/// \author I. Hrivnacova; IPN, Orsay
17
18
#include "SensitiveDetector.h"
19
#include "Hit.h"
20
21
#include "
GarfieldPhysics.h
"
22
23
#include <Riostream.h>
24
#include <TLorentzVector.h>
25
#include <TMCRootManager.h>
26
#include <TTree.h>
27
#include <TVirtualMC.h>
28
29
/// \cond CLASSIMP
30
ClassImp(
VMC::ExGarfield::SensitiveDetector
)
31
/// \endcond
32
33
namespace
VMC
34
{
35
namespace
ExGarfield
36
{
37
38
//_____________________________________________________________________________
39
SensitiveDetector::SensitiveDetector
(
const
char
* name)
40
:
TNamed
(name,
""
),
fHit
(0),
fAbsorberVolId
(),
fGasVolId
(),
fVerboseLevel
(1)
41
{
42
/// Standard constructor.
43
/// Create hits collection.
44
/// \param name The calorimeter hits collection name
45
46
fHit
=
new
Hit
();
47
}
48
49
//_____________________________________________________________________________
50
SensitiveDetector::SensitiveDetector
(
const
SensitiveDetector
& origin)
51
:
TNamed
(origin),
52
fHit
(0),
53
fAbsorberVolId
(),
54
fGasVolId
(),
55
fVerboseLevel
(origin.
fVerboseLevel
)
56
{
57
/// Copy constructor (for cloning on worker thread in MT mode).
58
/// Create hits collection.
59
/// \param origin The source object (on master).
60
61
fHit
=
new
Hit
();
62
}
63
64
//_____________________________________________________________________________
65
SensitiveDetector::SensitiveDetector
()
66
:
TNamed
(),
fHit
(0),
fAbsorberVolId
(),
fGasVolId
(),
fVerboseLevel
(0)
67
{
68
/// Default constructor
69
}
70
71
//_____________________________________________________________________________
72
SensitiveDetector::~SensitiveDetector
()
73
{
74
/// Destructor
75
76
delete
fHit
;
77
}
78
79
//
80
// public methods
81
//
82
83
//_____________________________________________________________________________
84
void
SensitiveDetector::Initialize
()
85
{
86
/// Register hits collection in the Root manager;
87
/// set sensitive volumes.
88
89
if
(TMCRootManager::Instance())
Register
();
90
fAbsorberVolId
= gMC->VolId(
"Absorber"
);
91
fGasVolId
= gMC->VolId(
"Gas"
);
92
}
93
94
//_____________________________________________________________________________
95
Bool_t
SensitiveDetector::ProcessHits
()
96
{
97
/// Account energy deposit and track lengths for each layer in its hit.
98
99
Int_t copyNo;
100
Int_t
id
= gMC->CurrentVolID(copyNo);
101
102
if
(
id
!=
fAbsorberVolId
&&
id
!=
fGasVolId
)
return
false
;
103
104
Double_t edep = gMC->Edep();
105
Double_t step = 0.;
106
if
(gMC->TrackCharge() != 0.) step = gMC->TrackStep();
107
108
if
(
id
==
fAbsorberVolId
) {
109
fHit
->AddEdepAbs(edep);
110
fHit
->AddTrackLengthAbs(step);
111
}
112
113
if
(
id
==
fGasVolId
) {
114
fHit
->AddEdepGas(edep);
115
}
116
117
return
true
;
118
}
119
120
//_____________________________________________________________________________
121
Bool_t
SensitiveDetector::UpdateFromGarfield
()
122
{
123
/// Update the collected hit information from Garfield interface
124
125
GarfieldPhysics
* garfieldPhysics =
GarfieldPhysics::GetInstance
();
126
127
// get energy deposit from Garfield, convert it in GeV
128
Double_t edep = garfieldPhysics->
GetEnergyDeposit_MeV
() * 1e-03;
129
Double_t avalancheSize = garfieldPhysics->
GetAvalancheSize
();
130
Double_t gain = garfieldPhysics->
GetGain
();
131
132
// update hit
133
fHit
->AddEdepGas(edep);
134
fHit
->AddAvalancheSize(avalancheSize);
135
fHit
->AddGain(gain);
136
137
return
true
;
138
}
139
140
//_____________________________________________________________________________
141
void
SensitiveDetector::EndOfEvent
()
142
{
143
/// Print hits collection (if verbose) and reset hits afterwards.
144
145
if
(
fVerboseLevel
> 0)
Print
();
146
147
// Reset hits collection
148
fHit
->Reset();
149
150
// Reset data collected in Garfield
151
GarfieldPhysics
* garfieldPhysics =
GarfieldPhysics::GetInstance
();
152
garfieldPhysics->
Clear
();
153
}
154
155
//_____________________________________________________________________________
156
void
SensitiveDetector::Register
()
157
{
158
/// Register the hits collection in Root manager.
159
160
TMCRootManager::Instance()->Register(
"hit"
,
"VMC::ExGarfield::Hit"
, &
fHit
);
161
}
162
163
//_____________________________________________________________________________
164
void
SensitiveDetector::Print
(Option_t*
/*option*/
)
const
165
{
166
/// Print the hit.
167
168
fHit
->Print();
169
}
170
171
}
// namespace ExGarfield
172
}
GarfieldPhysics.h
Definition of the GarfieldPhysics class.
GarfieldPhysics
Definition
GarfieldPhysics.h:81
GarfieldPhysics::GetInstance
static GarfieldPhysics * GetInstance()
Definition
GarfieldPhysics.cxx:32
GarfieldPhysics::GetGain
double GetGain()
Definition
GarfieldPhysics.h:110
GarfieldPhysics::GetEnergyDeposit_MeV
double GetEnergyDeposit_MeV()
Definition
GarfieldPhysics.h:108
GarfieldPhysics::Clear
void Clear()
Definition
GarfieldPhysics.h:111
GarfieldPhysics::GetAvalancheSize
double GetAvalancheSize()
Definition
GarfieldPhysics.h:109
TNamed
VMC::ExGarfield::Hit
The calorimeter hit.
Definition
Hit.h:37
VMC::ExGarfield::SensitiveDetector
The calorimeter sensitive detector.
Definition
SensitiveDetector.h:39
VMC::ExGarfield::SensitiveDetector::ProcessHits
Bool_t ProcessHits()
Definition
SensitiveDetector.cxx:95
VMC::ExGarfield::SensitiveDetector::SensitiveDetector
SensitiveDetector(const char *name)
Definition
SensitiveDetector.cxx:39
VMC::ExGarfield::SensitiveDetector::fGasVolId
Int_t fGasVolId
The gas volume Id.
Definition
SensitiveDetector.h:64
VMC::ExGarfield::SensitiveDetector::Initialize
void Initialize()
Definition
SensitiveDetector.cxx:84
VMC::ExGarfield::SensitiveDetector::EndOfEvent
void EndOfEvent()
Definition
SensitiveDetector.cxx:141
VMC::ExGarfield::SensitiveDetector::UpdateFromGarfield
Bool_t UpdateFromGarfield()
Definition
SensitiveDetector.cxx:121
VMC::ExGarfield::SensitiveDetector::fVerboseLevel
Int_t fVerboseLevel
Verbosity level.
Definition
SensitiveDetector.h:65
VMC::ExGarfield::SensitiveDetector::fAbsorberVolId
Int_t fAbsorberVolId
The absorber volume Id.
Definition
SensitiveDetector.h:63
VMC::ExGarfield::SensitiveDetector::Register
void Register()
Definition
SensitiveDetector.cxx:156
VMC::ExGarfield::SensitiveDetector::~SensitiveDetector
virtual ~SensitiveDetector()
Definition
SensitiveDetector.cxx:72
VMC::ExGarfield::SensitiveDetector::fHit
Hit * fHit
The detector hit.
Definition
SensitiveDetector.h:62
VMC::ExGarfield::SensitiveDetector::SensitiveDetector
SensitiveDetector()
Definition
SensitiveDetector.cxx:65
VMC::ExGarfield::SensitiveDetector::Print
virtual void Print(Option_t *option="") const
Definition
SensitiveDetector.cxx:164
VMC::ExGarfield
Definition
FastSimulation.h:28
VMC
Definition
FastSimulation.h:26
Generated on
for VMC Examples by
1.17.0