CbmRoot
Loading...
Searching...
No Matches
CbmStsMC.cxx
Go to the documentation of this file.
1/* Copyright (C) 2006-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese, Denis Bertini [committer], Florian Uhlig */
4
12#include "CbmStsMC.h"
13
14#include "CbmGeometryUtils.h"
15#include "CbmStack.h"
16#include "CbmStsElement.h"
17#include "CbmStsPoint.h"
18#include "CbmStsSetup.h"
19
20#include <Logger.h>
21
22#include "TGeoBBox.h"
23#include "TGeoManager.h"
24#include "TGeoPhysicalNode.h"
25#include "TKey.h"
26#include "TParticle.h"
27#include "TVector3.h"
28#include "TVirtualMC.h"
29#include <TFile.h>
30
31using std::map;
32using std::pair;
33
34// ----- Constructor ---------------------------------------------------
35CbmStsMC::CbmStsMC(Bool_t active, const char* name)
36 : FairDetector(name, active, ToIntegralType(ECbmModuleId::kSts))
37 , fStatusIn()
38 , fStatusOut()
39 , fEloss(0.)
40 , fAddressMap()
41 , fStsPoints(NULL)
42 , fSetup(NULL)
43 , fCombiTrans(NULL)
44 , fProcessNeutrals(kFALSE)
45{
46}
47// -------------------------------------------------------------------------
48
49
50// ----- Destructor ----------------------------------------------------
52{
53 if (fStsPoints) {
54 fStsPoints->Delete();
55 delete fStsPoints;
56 }
57 if (fCombiTrans) { delete fCombiTrans; }
58}
59// -------------------------------------------------------------------------
60
61
62// ----- ConstructGeometry -----------------------------------------------
64{
65
66 TString fileName = GetGeometryFileName();
67
68 // --- Only ROOT geometries are supported
69 if (!fileName.EndsWith(".root")) {
70 LOG(fatal) << GetName() << ": Geometry format of file " << fileName.Data() << " not supported.";
71 }
73}
74// -------------------------------------------------------------------------
75
76
77// ----- End of event action -------------------------------------------
79{
80 Print(); // Status output
81 Reset(); // Reset the track status parameters
82}
83// -------------------------------------------------------------------------
84
85
86// ----- Initialise ----------------------------------------------------
88{
89
90 // --- Instantiate the output array
91 fStsPoints = new TClonesArray("CbmStsPoint");
92
93 // --- Get the CbmStsSetup instance and construct a map from full path
94 // --- to address for each sensor. This is needed to store the unique x
95 // --- address of the activated sensor in the CbmStsPoint class.
96 // --- Unfortunately, the full geometry path (string) is the only way
97 // --- to unambiguously identify the current active node during the
98 // --- transport. It may seem that looking up a string in a map is not
99 // --- efficient. I checked however, that the performance penalty is very
100 // --- small.
101 fAddressMap.clear();
103 fSetup->Init();
104 Int_t nUnits = fSetup->GetNofDaughters();
105 for (Int_t iUnit = 0; iUnit < nUnits; iUnit++) {
106 CbmStsElement* unit = fSetup->GetDaughter(iUnit);
107 Int_t nLadd = unit->GetNofDaughters();
108 for (Int_t iLadd = 0; iLadd < nLadd; iLadd++) {
109 CbmStsElement* ladd = unit->GetDaughter(iLadd);
110 Int_t nHlad = ladd->GetNofDaughters();
111 for (Int_t iHlad = 0; iHlad < nHlad; iHlad++) {
112 CbmStsElement* hlad = ladd->GetDaughter(iHlad);
113 Int_t nModu = hlad->GetNofDaughters();
114 for (Int_t iModu = 0; iModu < nModu; iModu++) {
115 CbmStsElement* modu = hlad->GetDaughter(iModu);
116 Int_t nSens = modu->GetNofDaughters();
117 for (Int_t iSens = 0; iSens < nSens; iSens++) {
118 CbmStsElement* sensor = modu->GetDaughter(iSens);
119 TString path = sensor->GetPnode()->GetName();
120 if (!path.BeginsWith("/")) path.Prepend("/");
121 pair<TString, Int_t> a(path, sensor->GetAddress());
122 fAddressMap.insert(a);
123 TString test = sensor->GetPnode()->GetName();
124 }
125 }
126 }
127 }
128 }
129 LOG(info) << fName << ": Address map initialised with " << Int_t(fAddressMap.size()) << " sensors. ";
130
131 // --- Call the Initialise method of the mother class
132 FairDetector::Initialize();
133}
134// -------------------------------------------------------------------------
135
136
137// ----- ProcessHits ----------------------------------------------------
138Bool_t CbmStsMC::ProcessHits(FairVolume* /*vol*/)
139{
140
141 // --- If this is the first step for the track in the sensor:
142 // Reset energy loss and store track parameters
143 if (gMC->IsTrackEntering()) {
144 fEloss = 0.;
148 }
149
150 // --- For all steps within active volume: sum up differential energy loss
151 fEloss += gMC->Edep();
152
153
154 // --- If track is leaving: get track parameters and create CbmstsPoint
155 if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
156
158
159 // --- No action if no energy loss (neutral particles)
160 if (fEloss == 0. && (!fProcessNeutrals)) return kFALSE;
161
162 // --- Add a StsPoint to the output array. Increment stack counter.
163 CreatePoint();
164
165 // --- Increment number of StsPoints for this track
166 CbmStack* stack = (CbmStack*) gMC->GetStack();
168
169 } //? track is exiting or stopped
170
171
172 return kTRUE;
173}
174// -------------------------------------------------------------------------
175
176
177// ----- Reset output array and track status ---------------------------
179{
180 fStsPoints->Delete();
183 fEloss = 0.;
184}
185// -------------------------------------------------------------------------
186
187
188// ----- Screen log ----------------------------------------------------
189void CbmStsMC::Print(Option_t* /*opt*/) const
190{
191 //Int_t nHits = fStsPoints->GetEntriesFast();
192 LOG(info) << fName << ": " << fStsPoints->GetEntriesFast() << " points registered in this event.";
193}
194// -------------------------------------------------------------------------
195
196
197// =========================================================================
198// Private methods
199// =========================================================================
200
201
202// ----- Create STS point ----------------------------------------------
204{
205
206 // --- Check detector address
208 LOG(error) << GetName() << ": inconsistent detector addresses " << fStatusIn.fAddress << " " << fStatusOut.fAddress;
209 return NULL;
210 }
211
212 // --- Check track Id
214 LOG(error) << GetName() << ": inconsistent track Id " << fStatusIn.fTrackId << " " << fStatusOut.fTrackId;
215 return NULL;
216 }
217
218 // --- Check track PID
219 if (fStatusIn.fPid != fStatusOut.fPid) {
220 LOG(error) << GetName() << ": inconsistent track PID " << fStatusIn.fPid << " " << fStatusOut.fPid;
221 return NULL;
222 }
223
224 // --- Entry position and momentum
225 TVector3 posIn(fStatusIn.fX, fStatusIn.fY, fStatusIn.fZ);
226 TVector3 momIn(fStatusIn.fPx, fStatusIn.fPy, fStatusIn.fPz);
227
228 // --- Exit position and momentum
229 TVector3 posOut(fStatusOut.fX, fStatusOut.fY, fStatusOut.fZ);
230 TVector3 momOut(fStatusOut.fPx, fStatusOut.fPy, fStatusOut.fPz);
231
232 // --- Time and track length (average between in and out)
233 Double_t time = 0.5 * (fStatusIn.fTime + fStatusOut.fTime);
234 Double_t length = 0.5 * (fStatusIn.fLength + fStatusOut.fLength);
235
236 // --- Flag for entry/exit
237 Int_t flag = 0;
238 if (fStatusIn.fFlag) flag += 1; // first coordinate is entry step
239 if (fStatusOut.fFlag) flag += 2; // second coordinate is exit step
240
241 // --- Debug output
242 LOG(debug2) << GetName() << ": Creating point from track " << fStatusIn.fTrackId << " in sensor "
243 << fStatusIn.fAddress << ", position (" << posIn.X() << ", " << posIn.Y() << ", " << posIn.Z()
244 << "), energy loss " << fEloss;
245
246 // --- Add new point to output array
247 Int_t newIndex = fStsPoints->GetEntriesFast();
248 return new ((*fStsPoints)[fStsPoints->GetEntriesFast()])
249 CbmStsPoint(fStatusIn.fTrackId, fStatusIn.fAddress, posIn, posOut, momIn, momOut, time, length, fEloss,
250 fStatusIn.fPid, 0, newIndex, flag);
251}
252// -------------------------------------------------------------------------
253
254
255// ----- Set the current track status ----------------------------------
257{
258
259 // --- Check for TVirtualMC and TGeomanager
260 if (!(gMC && gGeoManager)) {
261 LOG(error) << fName << ": No TVirtualMC or TGeoManager instance!";
262 return;
263 }
264
265 // --- Address of current sensor
266 // --- Use the geometry path from TVirtualMC; cannot rely on
267 // --- TGeoManager here.
268 TString path = gMC->CurrentVolPath();
269 auto it = fAddressMap.find(path);
270 if (it == fAddressMap.end()) {
271 LOG(fatal) << fName << ": Path not found in address map! " << gGeoManager->GetPath();
272 status.fAddress = 0;
273 }
274 else
275 status.fAddress = it->second;
276
277 // --- Index and PID of current track
278 status.fTrackId = gMC->GetStack()->GetCurrentTrackNumber();
279 status.fPid = gMC->GetStack()->GetCurrentTrack()->GetPdgCode();
280
281 // --- Position
282 gMC->TrackPosition(status.fX, status.fY, status.fZ);
283
284 // --- Momentum
285 Double_t dummy;
286 gMC->TrackMomentum(status.fPx, status.fPy, status.fPz, dummy);
287
288 // --- Time and track length
289 status.fTime = gMC->TrackTime() * 1.e9; // conversion into ns
290 status.fLength = gMC->TrackLength();
291
292 // --- Status flag (entry/exit or new/stopped/disappeared)
293 if (gMC->IsTrackEntering()) {
294 if (gMC->IsNewTrack()) status.fFlag = kFALSE; // Track created in sensor
295 else
296 status.fFlag = kTRUE; // Track entering
297 }
298 else { // exiting or stopped or disappeared
299 if (gMC->IsTrackDisappeared() || gMC->IsTrackStop())
300 status.fFlag = kFALSE; // Track stopped or disappeared in sensor
301 else
302 status.fFlag = kTRUE; // Track exiting
303 }
304}
305// -------------------------------------------------------------------------
306
307
308//__________________________________________________________________________
310{
312 LOG(info) << "Importing STS geometry from ROOT file " << fgeoName.Data();
314 }
315 else {
316 LOG(info) << "Constructing STS geometry from ROOT file " << fgeoName.Data();
317 FairModule::ConstructRootGeometry();
318 }
319}
320
ClassImp(CbmConverterManager)
XPU_D constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Definition CbmDefs.h:29
ECbmModuleId
Definition CbmDefs.h:39
@ kSts
Silicon Tracking System.
void AddPoint(ECbmModuleId iDet)
Definition CbmStack.cxx:331
Class representing an element of the STS setup.
Int_t GetAddress() const
TGeoPhysicalNode * GetPnode() const
Int_t GetNofDaughters() const
CbmStsElement * GetDaughter(Int_t index) const
Class for the MC transport of the CBM-STS.
Definition CbmStsMC.h:40
virtual ~CbmStsMC()
Definition CbmStsMC.cxx:51
TClonesArray * fStsPoints
Definition CbmStsMC.h:158
Double_t fEloss
Track status at exit of sensor.
Definition CbmStsMC.h:156
virtual void Initialize()
Initialisation.
Definition CbmStsMC.cxx:87
virtual void Reset()
Clear output array and reset current track status.
Definition CbmStsMC.cxx:178
CbmStsMC(Bool_t active=kTRUE, const char *name="STSMC")
Definition CbmStsMC.cxx:35
CbmStsSetup * fSetup
Output array (CbmStsPoint)
Definition CbmStsMC.h:159
CbmStsTrackStatus fStatusIn
Definition CbmStsMC.h:154
CbmStsPoint * CreatePoint()
Create a new StsPoint Creates a new CbmStsPoint using the current track status information and adds i...
Definition CbmStsMC.cxx:203
virtual void ConstructRootGeometry(TGeoMatrix *shift=NULL)
Definition CbmStsMC.cxx:309
std::map< TString, Int_t > fAddressMap
Accumulated energy loss for current track.
Definition CbmStsMC.h:157
virtual void EndOfEvent()
Action at end of event.
Definition CbmStsMC.cxx:78
virtual void Print(Option_t *opt="") const
Screen log Prints current number of StsPoints in array. Virtual from TObject.
Definition CbmStsMC.cxx:189
virtual Bool_t ProcessHits(FairVolume *vol=0)
Action for a track step in a sensitive node of the STS.
Definition CbmStsMC.cxx:138
Bool_t fProcessNeutrals
Transformation matrix for geometry positioning.
Definition CbmStsMC.h:161
CbmStsTrackStatus fStatusOut
Track status at entry of sensor.
Definition CbmStsMC.h:155
TGeoCombiTrans * fCombiTrans
Pointer to static instance of CbmStsSetup.
Definition CbmStsMC.h:160
virtual void ConstructGeometry()
Construct the STS geometry in the TGeoManager.
Definition CbmStsMC.cxx:63
void SetStatus(CbmStsTrackStatus &status)
Set the current track status Set the current track status (in or out) with parameters obtained from T...
Definition CbmStsMC.cxx:256
Bool_t Init(const char *geometryFile=nullptr)
Initialise the setup.
static CbmStsSetup * Instance()
Stores status of track during transport. Auxiliary for CbmSts.
Int_t fTrackId
MCTrack index.
Int_t fPid
MCTrack PID [PDG code].
Double_t fY
x position [cm]
Double_t fPz
Momentum x component [GeV].
Double_t fX
x position [cm]
Int_t fAddress
Unique address.
Double_t fZ
x position [cm]
Double_t fPx
Momentum x component [GeV].
Double_t fLength
Length since track creation [cm].
Bool_t fFlag
Status flag. TRUE if normal entry/exit, else FALSE.
Double_t fTime
Time since track creation [ns].
Double_t fPy
Momentum x component [GeV].
Bool_t IsNewGeometryFile(TString &filename)
void ImportRootGeometry(TString &filename, FairModule *mod, TGeoMatrix *mat)