VMC Examples Version 6.6
Loading...
Searching...
No Matches
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
31 /// \endcond
32
33 namespace VMC
34{
35 namespace ExGarfield
36 {
37
38 //_____________________________________________________________________________
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 //_____________________________________________________________________________
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 //_____________________________________________________________________________
66 : TNamed(), fHit(0), fAbsorberVolId(), fGasVolId(), fVerboseLevel(0)
67 {
68 /// Default constructor
69 }
70
71 //_____________________________________________________________________________
73 {
74 /// Destructor
75
76 delete fHit;
77 }
78
79 //
80 // public methods
81 //
82
83 //_____________________________________________________________________________
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 //_____________________________________________________________________________
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 //_____________________________________________________________________________
122 {
123 /// Update the collected hit information from Garfield interface
124
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 //_____________________________________________________________________________
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
152 garfieldPhysics->Clear();
153 }
154
155 //_____________________________________________________________________________
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}
Definition of the GarfieldPhysics class.
static GarfieldPhysics * GetInstance()
double GetEnergyDeposit_MeV()
double GetAvalancheSize()
The calorimeter hit.
Definition Hit.h:37
void AddAvalancheSize(Double_t das)
Definition Hit.h:60
virtual void Print(Option_t *option="") const
Definition Hit.cxx:52
void AddTrackLengthAbs(Double_t dl)
Definition Hit.h:56
void AddGain(Double_t dg)
Definition Hit.h:64
void AddEdepGas(Double_t de)
Definition Hit.h:52
void AddEdepAbs(Double_t de)
Definition Hit.h:48
The calorimeter sensitive detector.
Int_t fAbsorberVolId
The absorber volume Id.
virtual void Print(Option_t *option="") const