CbmRoot
Loading...
Searching...
No Matches
CbmPsdMC.cxx
Go to the documentation of this file.
1/* Copyright (C) 2005-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Alla Maevskaya, Florian Uhlig [committer] */
4
15#include "CbmPsdMC.h"
16
17#include "CbmGeometryUtils.h"
18#include "CbmModuleList.h"
19#include "CbmPsdPoint.h"
20#include "CbmStack.h"
21
22#include "TGeoManager.h"
23#include "TKey.h"
24#include "TVirtualMC.h"
25
26#include <cassert>
27#include <string>
28
29
30// ----- Default constructor -------------------------------------------
31CbmPsdMC::CbmPsdMC(Bool_t active, const char* name)
32 : FairDetector(name, active, ToIntegralType(ECbmModuleId::kPsd))
33 , fPosX(0.)
34 , fPosZ(0.)
35 , fRotY(0.)
36 , fUserPlacement(kFALSE)
37 , fPsdPoints(new TClonesArray("CbmPsdPoint"))
38 , fTrackID(-3)
39 , fAddress(-3)
40 , fPos()
41 , fMom()
42 , fTime(-1.)
43 , fLength(-1.)
44 , fEloss(-1.)
45 , fLayerID(-1)
46 , fModuleID(-1)
47{
48}
49// -------------------------------------------------------------------------
50
51
52// ----- Destructor ----------------------------------------------------
54{
55 if (fPsdPoints) {
56 fPsdPoints->Delete();
57 delete fPsdPoints;
58 }
59}
60// -------------------------------------------------------------------------
61
62
63// ----- Construct the geometry from file ------------------------------
65{
66
67
68 /*
69 LOG(info) << GetName() << ": Constructing geometry from file "
70 << fgeoName;
71
72 // --- A TGeoManager should be present
73 assert(gGeoManager);
74
75 // --- Only ROOT geometries are supported
76 if ( ! GetGeometryFileName().EndsWith(".root") ) {
77 LOG(fatal) << GetName() << ": Geometry format of file "
78 << GetGeometryFileName() << " not supported.";
79 return;
80 }
81
82 // --- Look for PSD volume and transformation matrix in geometry file
84 TFile* oldFile = gFile;
85 TDirectory* oldDir = gDirectory;
86
87 TFile* geoFile = new TFile(fgeoName);
88 assert ( geoFile );
89 TKey* key = nullptr;
90 TIter keyIter(geoFile->GetListOfKeys());
91 Bool_t foundVolume = kFALSE;
92 Bool_t foundMatrix = kFALSE;
93 std::string volumeName = "";
94 TGeoMatrix* transformation = nullptr;
95
96 while ( (key = (TKey*)keyIter() ) ) {
97
98 if ( key->ReadObj()->InheritsFrom("TGeoVolume") ) {
99 if ( foundVolume) {
100 LOG(fatal) << GetName() << ": More than one TGeoVolume in file! "
101 << volumeName << " " << key->GetName();
102 break;
103 } //? already found a volume
104 volumeName = key->GetName();
105 foundVolume = kTRUE;
106 continue;
107 } //? key inherits from TGeoVolume
108
109 if ( key->ReadObj()->InheritsFrom("TGeoMatrix") ) {
110 if ( foundMatrix ) {
111 LOG(fatal) << GetName() << ": More than one TGeoMatrix in file! ";
112 break;
113 } //? already found a matrix
114 transformation = dynamic_cast<TGeoMatrix*>(key->ReadObj());
115 foundMatrix = kTRUE;
116 continue;
117 } //? key inherits from TGeoMatrix
118
119 } //# keys in file
120
121 if ( ! foundVolume ) LOG(fatal) << GetName() << ": No TGeoVolume in file " << fgeoName;
122 if ( ! foundMatrix ) LOG(fatal) << GetName() << ": No TGeoMatrix in file " << fgeoName;
123
124 // --- Import PSD volume
125 TGeoVolume* psdVolume = TGeoVolume::Import(fgeoName, volumeName.c_str());
126
127 // Add PSD to the geometry
128 gGeoManager->GetTopVolume()->AddNode(psdVolume, 0, transformation);
129 if (air::Logger::Logging(fair::Severity::debug)) {
130 psdVolume->Print();
131 transformation->Print();
132 }
133
134 // Register all sensitive volumes
135 for (Int_t i=0; i<psdVolume->GetNdaughters(); ++i)
136 RegisterSensitiveVolumes(psdVolume->GetNode(i));
137// RegisterSensitiveVolumes(psdVolume->GetNode(0));
138
139 LOG(debug) << GetName() << ": " << fNbOfSensitiveVol
140 << " sensitive volumes";
141 *
143 gFile = oldFile;
144 gDirectory = oldDir;
145
146 geoFile->Close();
147*/
148
149 LOG(info) << "Importing PSD geometry from ROOT file " << fgeoName.Data();
151}
152// -------------------------------------------------------------------------
153
154
155// ----- End of event action -------------------------------------------
157{
158 Print(); // Status output
159 fPsdPoints->Delete();
160}
161// -------------------------------------------------------------------------
162
163
164// ----- Print ---------------------------------------------------------
165void CbmPsdMC::Print(Option_t*) const
166{
167 LOG(info) << fName << ": " << fPsdPoints->GetEntriesFast() << " points registered in this event.";
168}
169// -------------------------------------------------------------------------
170
171
172// ----- Public method ProcessHits --------------------------------------
173Bool_t CbmPsdMC::ProcessHits(FairVolume*)
174{
175
176 // No action for neutral particles
177 if (TMath::Abs(gMC->TrackCharge()) <= 0) return kFALSE;
178
179 // --- If this is the first step for the track in the volume:
180 // Reset energy loss and store track parameters
181 if (gMC->IsTrackEntering()) {
182 fTrackID = gMC->GetStack()->GetCurrentTrackNumber();
183
184 gMC->CurrentVolOffID(1, fLayerID);
185 gMC->CurrentVolOffID(3, fModuleID);
186
188 gMC->TrackPosition(fPos);
189 gMC->TrackMomentum(fMom);
190 fTime = gMC->TrackTime() * 1.0e09;
191 fLength = gMC->TrackLength();
192 fEloss = 0.;
193 } //? track entering
194
195 // --- For all steps within active volume: sum up differential energy loss
196 fEloss += gMC->Edep();
197
198 // --- If track is leaving: get track parameters and create CbmstsPoint
199 if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
200
201 // Create CbmPsdPoint
202 Int_t size = fPsdPoints->GetEntriesFast();
203 CbmPsdPoint* psdPoint =
204 new ((*fPsdPoints)[size]) CbmPsdPoint(fTrackID, fAddress, fPos.Vect(), fMom.Vect(), fTime, fLength, fEloss);
205 psdPoint->SetModuleID(fModuleID + 1);
206
207 // --- Increment number of PsdPoints for this track in the stack
208 CbmStack* stack = dynamic_cast<CbmStack*>(gMC->GetStack());
209 assert(stack);
211
212 } //? track is exiting or stopped
213
214 return kTRUE;
215}
216// -------------------------------------------------------------------------
217
218
219// ----- Register the sensitive volumes --------------------------------
221{
222
223 TObjArray* daughters = node->GetVolume()->GetNodes();
224 for (Int_t iDaughter = 0; iDaughter < daughters->GetEntriesFast(); iDaughter++) {
225 TGeoNode* daughter = dynamic_cast<TGeoNode*>(daughters->At(iDaughter));
226 assert(daughter);
227 if (daughter->GetNdaughters() > 0) RegisterSensitiveVolumes(daughter);
228 TGeoVolume* daughterVolume = daughter->GetVolume();
229 if (CheckIfSensitive(daughterVolume->GetName())) { AddSensitiveVolume(daughterVolume); } //? Sensitive volume
230 } //# Daughter nodes
231}
232// -------------------------------------------------------------------------
233
234
ClassImp(CbmConverterManager)
XPU_D constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Definition CbmDefs.h:29
ECbmModuleId
Definition CbmDefs.h:39
@ kPsd
Projectile spectator detector.
static constexpr size_t size()
Definition KfSimdPseudo.h:2
Class for the MC transport of the CBM-PSD.
Definition CbmPsdMC.h:34
Int_t fLayerID
energy loss
Definition CbmPsdMC.h:162
virtual ~CbmPsdMC()
Definition CbmPsdMC.cxx:53
TClonesArray * fPsdPoints
Definition CbmPsdMC.h:152
virtual void ConstructGeometry()
Construct the PSD geometry in the TGeoManager.
Definition CbmPsdMC.cxx:64
CbmPsdMC(Bool_t active=kTRUE, const char *name="PSDMC")
Constructor.
Definition CbmPsdMC.cxx:31
virtual void EndOfEvent()
Action at end of event.
Definition CbmPsdMC.cxx:156
virtual Bool_t ProcessHits(FairVolume *volume=0)
Stepping action.
Definition CbmPsdMC.cxx:173
void RegisterSensitiveVolumes(TGeoNode *node)
module ID
Definition CbmPsdMC.cxx:220
virtual Bool_t CheckIfSensitive(std::string name)
Check whether a volume is sensitive.
Definition CbmPsdMC.h:67
Int_t fModuleID
layer ID
Definition CbmPsdMC.h:163
Int_t fAddress
track index
Definition CbmPsdMC.h:156
TLorentzVector fMom
position
Definition CbmPsdMC.h:158
Int_t fTrackID
Output array.
Definition CbmPsdMC.h:155
TLorentzVector fPos
address (module and layer)
Definition CbmPsdMC.h:157
Double_t fEloss
length
Definition CbmPsdMC.h:161
virtual void Print(Option_t *opt="") const
Screen log Prints current number of StsPoints in array. Virtual from TObject.
Definition CbmPsdMC.cxx:165
Double_t fTime
momentum
Definition CbmPsdMC.h:159
Double_t fLength
time
Definition CbmPsdMC.h:160
void SetModuleID(int32_t mod)
Definition CbmPsdPoint.h:59
void AddPoint(ECbmModuleId iDet)
Definition CbmStack.cxx:331
void ImportRootGeometry(TString &filename, FairModule *mod, TGeoMatrix *mat)