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