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
10
11
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#include "TGeoBBox.h"
20#include "TGeoManager.h"
21#include "TGeoPhysicalNode.h"
22#include "TKey.h"
23#include "TParticle.h"
24#include "TVector3.h"
25#include "TVirtualMC.h"
26
27#include <Logger.h>
28
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) {
58 delete fCombiTrans;
59 }
60}
61// -------------------------------------------------------------------------
62
63
64// ----- ConstructGeometry -----------------------------------------------
66{
67
68 TString fileName = GetGeometryFileName();
69
70 // --- Only ROOT geometries are supported
71 if (!fileName.EndsWith(".root")) {
72 LOG(fatal) << GetName() << ": Geometry format of file " << fileName.Data() << " not supported.";
73 }
75}
76// -------------------------------------------------------------------------
77
78
79// ----- End of event action -------------------------------------------
81{
82 Print(); // Status output
83 Reset(); // Reset the track status parameters
84}
85// -------------------------------------------------------------------------
86
87
88// ----- Initialise ----------------------------------------------------
90{
91
92 // --- Instantiate the output array
93 fStsPoints = new TClonesArray("CbmStsPoint");
94
95 // --- Get the CbmStsSetup instance and construct a map from full path
96 // --- to address for each sensor. This is needed to store the unique x
97 // --- address of the activated sensor in the CbmStsPoint class.
98 // --- Unfortunately, the full geometry path (string) is the only way
99 // --- to unambiguously identify the current active node during the
100 // --- transport. It may seem that looking up a string in a map is not
101 // --- efficient. I checked however, that the performance penalty is very
102 // --- small.
103 fAddressMap.clear();
105 fSetup->Init();
106 Int_t nUnits = fSetup->GetNofDaughters();
107 for (Int_t iUnit = 0; iUnit < nUnits; iUnit++) {
108 CbmStsElement* unit = fSetup->GetDaughter(iUnit);
109 Int_t nLadd = unit->GetNofDaughters();
110 for (Int_t iLadd = 0; iLadd < nLadd; iLadd++) {
111 CbmStsElement* ladd = unit->GetDaughter(iLadd);
112 Int_t nHlad = ladd->GetNofDaughters();
113 for (Int_t iHlad = 0; iHlad < nHlad; iHlad++) {
114 CbmStsElement* hlad = ladd->GetDaughter(iHlad);
115 Int_t nModu = hlad->GetNofDaughters();
116 for (Int_t iModu = 0; iModu < nModu; iModu++) {
117 CbmStsElement* modu = hlad->GetDaughter(iModu);
118 Int_t nSens = modu->GetNofDaughters();
119 for (Int_t iSens = 0; iSens < nSens; iSens++) {
120 CbmStsElement* sensor = modu->GetDaughter(iSens);
121 TString path = sensor->GetPnode()->GetName();
122 if (!path.BeginsWith("/")) {
123 path.Prepend("/");
124 }
125 pair<TString, Int_t> a(path, sensor->GetAddress());
126 fAddressMap.insert(a);
127 TString test = sensor->GetPnode()->GetName();
128 }
129 }
130 }
131 }
132 }
133 LOG(info) << fName << ": Address map initialised with " << Int_t(fAddressMap.size()) << " sensors. ";
134
135 // --- Call the Initialise method of the mother class
136 FairDetector::Initialize();
137}
138// -------------------------------------------------------------------------
139
140
141// ----- ProcessHits ----------------------------------------------------
142Bool_t CbmStsMC::ProcessHits(FairVolume* /*vol*/)
143{
144
145 // --- If this is the first step for the track in the sensor:
146 // Reset energy loss and store track parameters
147 if (gMC->IsTrackEntering()) {
148 fEloss = 0.;
149 fStatusIn.Reset();
150 fStatusOut.Reset();
152 }
153
154 // --- For all steps within active volume: sum up differential energy loss
155 fEloss += gMC->Edep();
156
157
158 // --- If track is leaving: get track parameters and create CbmstsPoint
159 if (gMC->IsTrackExiting() || gMC->IsTrackStop() || gMC->IsTrackDisappeared()) {
160
162
163 // --- No action if no energy loss (neutral particles)
164 // --- never suppress charged particles to produce points in no-energy-loss simulation mode
165 if (gMC->TrackCharge() == 0. && fEloss == 0. && (!fProcessNeutrals)) {
166 return kFALSE;
167 }
168
169 // --- Add a StsPoint to the output array. Increment stack counter.
170 CreatePoint();
171
172 // --- Increment number of StsPoints for this track
173 CbmStack* stack = (CbmStack*) gMC->GetStack();
175
176 } //? track is exiting or stopped
177
178
179 return kTRUE;
180}
181// -------------------------------------------------------------------------
182
183
184// ----- Reset output array and track status ---------------------------
186{
187 fStsPoints->Delete();
188 fStatusIn.Reset();
189 fStatusOut.Reset();
190 fEloss = 0.;
191}
192// -------------------------------------------------------------------------
193
194
195// ----- Screen log ----------------------------------------------------
196void CbmStsMC::Print(Option_t* /*opt*/) const
197{
198 //Int_t nHits = fStsPoints->GetEntriesFast();
199 LOG(info) << fName << ": " << fStsPoints->GetEntriesFast() << " points registered in this event.";
200}
201// -------------------------------------------------------------------------
202
203
204// =========================================================================
205// Private methods
206// =========================================================================
207
208
209// ----- Create STS point ----------------------------------------------
211{
212
213 // --- Check detector address
214 if (fStatusIn.fAddress != fStatusOut.fAddress) {
215 LOG(error) << GetName() << ": inconsistent detector addresses " << fStatusIn.fAddress << " " << fStatusOut.fAddress;
216 return NULL;
217 }
218
219 // --- Check track Id
220 if (fStatusIn.fTrackId != fStatusOut.fTrackId) {
221 LOG(error) << GetName() << ": inconsistent track Id " << fStatusIn.fTrackId << " " << fStatusOut.fTrackId;
222 return NULL;
223 }
224
225 // --- Check track PID
226 if (fStatusIn.fPid != fStatusOut.fPid) {
227 LOG(error) << GetName() << ": inconsistent track PID " << fStatusIn.fPid << " " << fStatusOut.fPid;
228 return NULL;
229 }
230
231 // --- Entry position and momentum
232 TVector3 posIn(fStatusIn.fX, fStatusIn.fY, fStatusIn.fZ);
233 TVector3 momIn(fStatusIn.fPx, fStatusIn.fPy, fStatusIn.fPz);
234
235 // --- Exit position and momentum
236 TVector3 posOut(fStatusOut.fX, fStatusOut.fY, fStatusOut.fZ);
237 TVector3 momOut(fStatusOut.fPx, fStatusOut.fPy, fStatusOut.fPz);
238
239 // --- Time and track length (average between in and out)
240 Double_t time = 0.5 * (fStatusIn.fTime + fStatusOut.fTime);
241 Double_t length = 0.5 * (fStatusIn.fLength + fStatusOut.fLength);
242
243 // --- Flag for entry/exit
244 Int_t flag = 0;
245 if (fStatusIn.fFlag) { // first coordinate is entry step
246 flag += 1;
247 }
248 if (fStatusOut.fFlag) { // second coordinate is exit step
249 flag += 2;
250 }
251
252 // --- Debug output
253 LOG(debug2) << GetName() << ": Creating point from track " << fStatusIn.fTrackId << " in sensor "
254 << fStatusIn.fAddress << ", position (" << posIn.X() << ", " << posIn.Y() << ", " << posIn.Z()
255 << "), energy loss " << fEloss;
256
257 // --- Add new point to output array
258 Int_t newIndex = fStsPoints->GetEntriesFast();
259 return new ((*fStsPoints)[fStsPoints->GetEntriesFast()])
260 CbmStsPoint(fStatusIn.fTrackId, fStatusIn.fAddress, posIn, posOut, momIn, momOut, time, length, fEloss,
261 fStatusIn.fPid, 0, newIndex, flag);
262}
263// -------------------------------------------------------------------------
264
265
266// ----- Set the current track status ----------------------------------
268{
269
270 // --- Check for TVirtualMC and TGeomanager
271 if (!(gMC && gGeoManager)) {
272 LOG(error) << fName << ": No TVirtualMC or TGeoManager instance!";
273 return;
274 }
275
276 // --- Address of current sensor
277 // --- Use the geometry path from TVirtualMC; cannot rely on
278 // --- TGeoManager here.
279 TString path = gMC->CurrentVolPath();
280 auto it = fAddressMap.find(path);
281 if (it == fAddressMap.end()) {
282 LOG(fatal) << fName << ": Path not found in address map! " << gGeoManager->GetPath();
283 status.fAddress = 0;
284 }
285 else {
286 status.fAddress = it->second;
287 }
288
289 // --- Index and PID of current track
290 status.fTrackId = gMC->GetStack()->GetCurrentTrackNumber();
291 status.fPid = gMC->GetStack()->GetCurrentTrack()->GetPdgCode();
292
293 // --- Position
294 gMC->TrackPosition(status.fX, status.fY, status.fZ);
295
296 // --- Momentum
297 Double_t dummy;
298 gMC->TrackMomentum(status.fPx, status.fPy, status.fPz, dummy);
299
300 // --- Time and track length
301 status.fTime = gMC->TrackTime() * 1.e9; // conversion into ns
302 status.fLength = gMC->TrackLength();
303
304 // --- Status flag (entry/exit or new/stopped/disappeared)
305 if (gMC->IsTrackEntering()) {
306 if (gMC->IsNewTrack()) {
307 status.fFlag = kFALSE; // Track created in sensor
308 }
309 else {
310 status.fFlag = kTRUE; // Track entering
311 }
312 }
313 else { // exiting or stopped or disappeared
314 if (gMC->IsTrackDisappeared() || gMC->IsTrackStop()) {
315 status.fFlag = kFALSE; // Track stopped or disappeared in sensor
316 }
317 else {
318 status.fFlag = kTRUE; // Track exiting
319 }
320 }
321}
322// -------------------------------------------------------------------------
323
324
325//__________________________________________________________________________
327{
329 LOG(info) << "Importing STS geometry from ROOT file " << fgeoName.Data();
331 }
332 else {
333 LOG(info) << "Constructing STS geometry from ROOT file " << fgeoName.Data();
334 FairModule::ConstructRootGeometry();
335 }
336}
337
ClassImp(CbmConverterManager)
XPU_D constexpr auto ToIntegralType(T enumerator) -> typename std::underlying_type< T >::type
Converts an element of enum class to its underlying integral type.
Definition CbmDefs.h:33
ECbmModuleId
Enumerator for module Identifiers.
Definition CbmDefs.h:45
@ kSts
Silicon Tracking System.
Definition CbmDefs.h:48
int Int_t
bool Bool_t
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:89
virtual void Reset()
Clear output array and reset current track status.
Definition CbmStsMC.cxx:185
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:210
virtual void ConstructRootGeometry(TGeoMatrix *shift=NULL)
Definition CbmStsMC.cxx:326
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:80
virtual void Print(Option_t *opt="") const
Screen log Prints current number of StsPoints in array. Virtual from TObject.
Definition CbmStsMC.cxx:196
virtual Bool_t ProcessHits(FairVolume *vol=0)
Action for a track step in a sensitive node of the STS.
Definition CbmStsMC.cxx:142
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:65
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:267
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)