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