VMC Examples Version 6.6
Loading...
Searching...
No Matches
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
28ClassImp(A01EmCalorimeterSD)
29 /// \endcond
30
31 using namespace std;
32
34const Int_t A01EmCalorimeterSD::fgkNofRows = 4;
35
36//_____________________________________________________________________________
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
49 new TClonesArray("A01EmCalorHit", fgkNofColumns * fgkNofRows);
50 for (Int_t i = 0; i < fgkNofColumns * fgkNofRows; i++)
51 new ((*fCalCollection)[i]) A01EmCalorHit();
52}
53
54//_____________________________________________________________________________
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
67 new TClonesArray("A01EmCalorHit", fgkNofColumns * fgkNofRows);
68 for (Int_t i = 0; i < fgkNofColumns * fgkNofRows; i++)
69 new ((*fCalCollection)[i]) A01EmCalorHit();
70}
71
72//_____________________________________________________________________________
74 : TNamed(), fCalCollection(0), fVolId(0), fWriteHits(true), fVerboseLevel(1)
75{
76 /// Default constructor
77}
78
79//_____________________________________________________________________________
81{
82 /// Destructor
83
84 if (fCalCollection) fCalCollection->Delete();
85 delete fCalCollection;
86}
87
88//
89// private methods
90//
91
92//_____________________________________________________________________________
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//_____________________________________________________________________________
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//_____________________________________________________________________________
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//_____________________________________________________________________________
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//_____________________________________________________________________________
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//_____________________________________________________________________________
189void 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//_____________________________________________________________________________
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//_____________________________________________________________________________
222{
223 /// \return The hit for the specified layer.
224 /// \param i The layer number
225
226 return (A01EmCalorHit*)fCalCollection->At(i);
227}
Definition of the A01EmCalorHit class.
Definition of the A01EmCalorimeterSD class.
The EM calorimeter hit.
void AddEdep(Double_t de)
Double_t GetEdep() const
Int_t GetVolId() const
void SetVolId(Int_t volId)
The EM calorimeter sensitive detector.
Int_t fVolId
The calorimeter volume Id.
A01EmCalorHit * GetHit(Int_t i) const
static const Int_t fgkNofRows
virtual void Print(Option_t *option="") const
Bool_t fWriteHits
Option to write hits.
Int_t fVerboseLevel
Verbosity level.
TClonesArray * fCalCollection
Hits collection.
static const Int_t fgkNofColumns