Skip to content

Commit ca6568d

Browse files
sawenzelclaude
andcommitted
Keep stepping state in detector members instead of statics
This moves state that is carried from step to step out of function-local statics, so that each instance has its own; with one instance per detector today, the behaviour is unchanged. - TPC keeps the track length at the last track reference as a member, and builds the momentum vector as a local. - FDD keeps the energy loss, photon count and entry position of the hit being built as members, and drops an unused static. - HMPID keeps the energy loss and entry position of the charged-particle hit as members. - MaterialBudgetMap keeps the distance to the scoring boundary as a member. - The VMC application no longer caches the FairRootManager instance in a static. https://its.cern.ch/jira/browse/O2-7305 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e4270ed commit ca6568d

9 files changed

Lines changed: 56 additions & 54 deletions

File tree

‎Detectors/FIT/FDD/simulation/include/FDDSimulation/Detector.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "DetectorsBase/Detector.h"
2121
#include "DataFormatsFDD/Hit.h"
2222
#include "FDDBase/Geometry.h"
23+
#include <TVector3.h>
2324

2425
class FairModule;
2526
class FairVolume;
@@ -73,6 +74,11 @@ class Detector : public o2::base::DetImpl<Detector>
7374
std::vector<o2::fdd::Hit>* mHits = nullptr;
7475
int mTrackRefLastTrackID = -1; //! last track that received a TrackReference in the current event
7576

77+
// state of the hit being built across steps in ProcessHits
78+
Float_t mElossAD = 0.; //! energy loss collected so far
79+
Int_t mNPhotonsAD = 0; //! photons collected so far
80+
TVector3 mHitPosAD; //! position where the track entered
81+
7682
Detector& operator=(const Detector&);
7783

7884
Geometry* mGeometry = nullptr; //! Geometry

‎Detectors/FIT/FDD/simulation/src/Detector.cxx‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,29 +151,23 @@ Bool_t Detector::ProcessHits(FairVolume* vol)
151151
Int_t nPhotonsInStep_ad = Int_t(fFDDLightYield * destep_ad);
152152
nPhotonsInStep_ad = gRandom->Poisson(nPhotonsInStep_ad);
153153

154-
static Float_t eloss_ad = 0.;
155-
static Float_t tlength_ad = 0.;
156-
static Int_t nPhotons_ad = 0;
157-
158-
static TVector3 vPos;
159-
160-
eloss_ad += destep_ad;
154+
mElossAD += destep_ad;
161155

162156
if (fMC->IsTrackEntering()) {
163-
nPhotons_ad = nPhotonsInStep_ad;
164-
fMC->TrackPosition(vPos(0), vPos(1), vPos(2));
157+
mNPhotonsAD = nPhotonsInStep_ad;
158+
fMC->TrackPosition(mHitPosAD(0), mHitPosAD(1), mHitPosAD(2));
165159

166-
eloss_ad = 0.0;
160+
mElossAD = 0.0;
167161
return kFALSE;
168162
}
169-
nPhotons_ad += nPhotonsInStep_ad;
163+
mNPhotonsAD += nPhotonsInStep_ad;
170164

171165
if (fMC->IsTrackExiting() || fMC->IsTrackStop() || fMC->IsTrackDisappeared()) {
172166
Int_t trackID = fMC->GetStack()->GetCurrentTrackNumber();
173167

174168
Float_t time = fMC->TrackTime() * 1.0e9; //time from seconds to ns
175169

176-
addHit(trackID, ADsector, vPos, time, eloss_ad, nPhotons_ad);
170+
addHit(trackID, ADsector, mHitPosAD, time, mElossAD, mNPhotonsAD);
177171
return kTRUE;
178172
}
179173

‎Detectors/HMPID/simulation/include/HMPIDSimulation/Detector.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ class Detector : public o2::base::DetImpl<Detector>
9898
int mHcel5VolID = -1;
9999
int mHcel6VolID = -1;
100100

101+
// state of a charged-particle hit being built across steps in ProcessHits
102+
Float_t mMipEloss = 0; //! energy loss collected in the amplification gap
103+
Double_t mMipEntry[3] = {0, 0, 0}; //! position where the track entered the gap
104+
101105
template <typename Det>
102106
friend class o2::base::DetImpl;
103107
ClassDefOverride(Detector, 1);

‎Detectors/HMPID/simulation/src/Detector.cxx‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ bool Detector::ProcessHits(FairVolume* v)
113113
} // photon hit PC
114114

115115
// Treat charged particles
116-
static Float_t eloss; // need to store mip parameters between different steps
117-
static Double_t in[3];
118116

119117
if (fMC->IsTrackEntering() && fMC->TrackCharge() && (volID == mHpad0VolID || volID == mHpad1VolID || volID == mHpad2VolID || volID == mHpad3VolID || volID == mHpad4VolID || volID == mHpad5VolID || volID == mHpad6VolID)) {
120118
// Trackref stored when entering in the pad volume
@@ -127,18 +125,18 @@ bool Detector::ProcessHits(FairVolume* v)
127125
if (fMC->TrackCharge() && (volID == mHcel0VolID || volID == mHcel1VolID || volID == mHcel2VolID || volID == mHcel3VolID || volID == mHcel4VolID || volID == mHcel5VolID || volID == mHcel6VolID)) {
128126
// charged particle in amplification gap (Hcel)
129127
if (fMC->IsTrackEntering() || fMC->IsNewTrack()) { // entering or newly created
130-
eloss = 0; // reset Eloss collector
131-
fMC->TrackPosition(in[0], in[1], in[2]); // take position at the entrance
128+
mMipEloss = 0; // reset Eloss collector
129+
fMC->TrackPosition(mMipEntry[0], mMipEntry[1], mMipEntry[2]); // take position at the entrance
132130
} else if (fMC->IsTrackExiting() || fMC->IsTrackStop() || fMC->IsTrackDisappeared()) { // exiting or disappeared
133-
eloss += fMC->Edep(); // take into account last step Eloss
131+
mMipEloss += fMC->Edep(); // take into account last step Eloss
134132
Int_t tid = fMC->GetStack()->GetCurrentTrackNumber(); // take TID
135133
Int_t pid = fMC->TrackPid(); // take PID
136134
Double_t out[3];
137135
fMC->TrackPosition(out[0], out[1], out[2]); // take MARS position at exit
138136
Float_t hitTime = (Float_t)fMC->TrackTime(); // hit formation time
139-
out[0] = 0.5 * (out[0] + in[0]); //
140-
out[1] = 0.5 * (out[1] + in[1]); // take hit position at the anod plane
141-
out[2] = 0.5 * (out[2] + in[2]);
137+
out[0] = 0.5 * (out[0] + mMipEntry[0]); //
138+
out[1] = 0.5 * (out[1] + mMipEntry[1]); // take hit position at the anod plane
139+
out[2] = 0.5 * (out[2] + mMipEntry[2]);
142140
Int_t idch; // chamber number
143141
if (volID == mHcel0VolID) {
144142
idch = 0;
@@ -157,16 +155,16 @@ bool Detector::ProcessHits(FairVolume* v)
157155
}
158156
Double_t xl, yl;
159157
o2::hmpid::Param::instance()->mars2Lors(idch, out, xl, yl); // take LORS position
160-
if (eloss > 0) {
158+
if (mMipEloss > 0) {
161159
// HIT for MIP, position near anod plane, eloss will be set to Q
162-
AddHit(out[0], out[1], out[2], hitTime, eloss, tid, idch);
163-
GenFee(eloss); // generate feedback photons
160+
AddHit(out[0], out[1], out[2], hitTime, mMipEloss, tid, idch);
161+
GenFee(mMipEloss); // generate feedback photons
164162
stack->addHit(GetDetId());
165-
eloss = 0;
163+
mMipEloss = 0;
166164
}
167165
} else {
168166
// just going inside
169-
eloss += fMC->Edep(); // collect this step eloss
167+
mMipEloss += fMC->Edep(); // collect this step eloss
170168
}
171169
return kTRUE;
172170
} // MIP in GAP

‎Detectors/TPC/simulation/include/TPCSimulation/Detector.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ class Detector : public o2::base::DetImpl<Detector>
155155
int mHitCounter = 0;
156156
int mElectronCounter = 0;
157157
int mStepCounter = 0;
158-
ElementalHit mHitLast{}; ///<! buffer last processed hit to be able to fill it to mHitsPerSectorCollection
158+
double mLastReferenceR = 0; ///<! track length at the last stored track reference (cm)
159+
ElementalHit mHitLast{}; ///<! buffer last processed hit to be able to fill it to mHitsPerSectorCollection
159160
HitGroup* mCurrentGroup = nullptr; ///<! hit group currently being filled
160161
int mOldTrackId = -1; ///<! track of the current hit group
161162
int mOldSectorId = -1; ///<! sector of the current hit group

‎Detectors/TPC/simulation/src/Detector.cxx‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ Bool_t Detector::ProcessHits(FairVolume* vol)
116116
mStepCounter++;
117117
auto& gasParam = ParameterGas::Instance();
118118
auto& detParam = ParameterDetector::Instance();
119-
const Int_t kMaxDistRef = 15; // maximal difference between 2 stored references - the parameter should be 15 cm as default
120-
static Double_t lastReferenceR = 0; // keeps last reference point in radius (cm)
119+
const Int_t kMaxDistRef = 15; // maximal difference between 2 stored references - the parameter should be 15 cm as default
121120

122121
/* This method is called from the MC stepping for the sensitive volume only */
123122
// LOG(info) << "tpc::ProcessHits";
@@ -166,7 +165,7 @@ Bool_t Detector::ProcessHits(FairVolume* vol)
166165
// if (sectorID != 0) return kFALSE;
167166

168167
// ---| momentum and beta gamma |---
169-
static TLorentzVector momentum; // static to make avoid creation/deletion of this expensive object
168+
TLorentzVector momentum;
170169
fMC->TrackMomentum(momentum);
171170

172171
const float time = fMC->TrackTime() * 1.0e9;
@@ -175,12 +174,12 @@ Bool_t Detector::ProcessHits(FairVolume* vol)
175174
if (fMC->IsTrackEntering() || fMC->IsTrackExiting()) {
176175
stack->addTrackReference(o2::TrackReference(position.X(), position.Y(), position.Z(), momentum.X(), momentum.Y(),
177176
momentum.Z(), fMC->TrackLength(), time, trackID, GetDetId()));
178-
lastReferenceR = fMC->TrackLength();
177+
mLastReferenceR = fMC->TrackLength();
179178
}
180-
if (TMath::Abs(lastReferenceR - fMC->TrackLength()) > kMaxDistRef) { /// we can speedup
179+
if (TMath::Abs(mLastReferenceR - fMC->TrackLength()) > kMaxDistRef) { /// we can speedup
181180
stack->addTrackReference(o2::TrackReference(position.X(), position.Y(), position.Z(), momentum.X(), momentum.Y(),
182181
momentum.Z(), fMC->TrackLength(), time, trackID, GetDetId()));
183-
lastReferenceR = fMC->TrackLength();
182+
mLastReferenceR = fMC->TrackLength();
184183
}
185184

186185
// ---| remove clusters between the IFC and the FC strips |---

‎Steer/include/Steer/MaterialBudgetMap.h‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,22 @@ class MaterialBudgetMap
4343
void FinishEvent();
4444

4545
private:
46-
Int_t mMode; //! mode
47-
Float_t mTotRadl; //! Total Radiation length
48-
Float_t mTotAbso; //! Total absorption length
49-
Float_t mTotGcm2; //! Total g/cm2 traversed
50-
TH2F* mHistRadl; //! Radiation length map
51-
TH2F* mHistAbso; //! Interaction length map
52-
TH2F* mHistGcm2; //! g/cm2 length map
53-
TH2F* mHistReta; //! Radiation length map as a function of eta
54-
TH2F* mRZR; //! Radiation lenghts at (R.Z)
55-
TH2F* mRZA; //! Absorbtion lengths at (R,Z)
56-
TH2F* mRZG; //! Density at (R,Z)
57-
Bool_t mStopped; //! Scoring has been stopped
58-
Float_t mRmin; //! minimum radius
59-
Float_t mZmax; //! maximum radius
60-
Float_t mRmax; //! maximum z
46+
Int_t mMode; //! mode
47+
Float_t mTotRadl; //! Total Radiation length
48+
Float_t mTotAbso; //! Total absorption length
49+
Float_t mTotGcm2; //! Total g/cm2 traversed
50+
TH2F* mHistRadl; //! Radiation length map
51+
TH2F* mHistAbso; //! Interaction length map
52+
TH2F* mHistGcm2; //! g/cm2 length map
53+
TH2F* mHistReta; //! Radiation length map as a function of eta
54+
TH2F* mRZR; //! Radiation lenghts at (R.Z)
55+
TH2F* mRZA; //! Absorbtion lengths at (R,Z)
56+
TH2F* mRZG; //! Density at (R,Z)
57+
Bool_t mStopped; //! Scoring has been stopped
58+
Float_t mRmin; //! minimum radius
59+
Float_t mZmax; //! maximum radius
60+
Float_t mRmax; //! maximum z
61+
Float_t mDistToBoundary = 0; //! distance to the scoring boundary from the previous step
6162
};
6263
} // namespace steer
6364
} // namespace o2

‎Steer/src/MaterialBudgetMap.cxx‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,10 @@ void MaterialBudgetMap::Stepping()
180180
// called from AliRun::Stepmanager from gustep.
181181
// Accumulate the 3 parameters step by step
182182
//
183-
static Float_t t;
184183
Float_t a, z, dens, radl, absl;
185184
Int_t i, id, copy;
186185
const char* vol;
187-
static Float_t vect[3], dir[3];
186+
Float_t vect[3], dir[3];
188187

189188
TString tmp1, tmp2;
190189
copy = 1;
@@ -212,12 +211,12 @@ void MaterialBudgetMap::Stepping()
212211
// Not the first step, add past contribution
213212
if (!mStopped) {
214213
if (absl) {
215-
mTotAbso += t / absl;
214+
mTotAbso += mDistToBoundary / absl;
216215
}
217216
if (radl) {
218-
mTotRadl += t / radl;
217+
mTotRadl += mDistToBoundary / radl;
219218
}
220-
mTotGcm2 += t * dens;
219+
mTotGcm2 += mDistToBoundary * dens;
221220
} // not stooped
222221
} // not a new track !
223222
mStopped = kTRUE;
@@ -231,7 +230,7 @@ void MaterialBudgetMap::Stepping()
231230
dir[i] = mom[i];
232231
}
233232

234-
t = eventgen::GeneratorGeantinos::PropagateCylinder(vect, dir, mRmax, mZmax);
233+
mDistToBoundary = eventgen::GeneratorGeantinos::PropagateCylinder(vect, dir, mRmax, mZmax);
235234

236235
if (step) {
237236
if (absl) {

‎Steer/src/O2MCApplication.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace steer
5959
template <typename T>
6060
void TypedVectorAttach(const char* name, fair::mq::Channel& channel, fair::mq::Parts& parts)
6161
{
62-
static auto mgr = FairRootManager::Instance();
62+
auto mgr = FairRootManager::Instance();
6363
auto vector = mgr->InitObjectAs<const std::vector<T>*>(name);
6464
if (vector) {
6565
auto buffer = (char*)&(*vector)[0];

0 commit comments

Comments
 (0)