Skip to content

Commit 23a39ba

Browse files
feat(FairGenericStack): Provide basic current track handling
The templates show a very basic handling of "the current track" in "the Stack". Provide this as a "default implementation" of FairGenericStack. People can still override it with a more sophisticated variant. examples/FairStack just shows that (currently).
1 parent 9676612 commit 23a39ba

File tree

7 files changed

+34
-52
lines changed

7 files changed

+34
-52
lines changed

examples/common/mcstack/FairStack.cxx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ FairStack::FairStack(Int_t size)
3535
, fStoreMap()
3636
, fIndexMap()
3737
, fPointsMap()
38-
, fCurrentTrack(-1)
3938
, fNPrimaries(0)
4039
, fNParticles(0)
4140
, fNTracks(0)
@@ -149,8 +148,9 @@ TParticle* FairStack::PopNextTrack(Int_t& iTrack)
149148
return nullptr;
150149
}
151150

152-
fCurrentTrack = thisParticle->GetStatusCode();
153-
iTrack = fCurrentTrack;
151+
const auto currentTrack = thisParticle->GetStatusCode();
152+
SetCurrentTrack(currentTrack);
153+
iTrack = currentTrack;
154154

155155
return thisParticle;
156156
}
@@ -177,7 +177,7 @@ TParticle* FairStack::PopPrimaryForTracking(Int_t iPrim)
177177

178178
TParticle* FairStack::GetCurrentTrack() const
179179
{
180-
TParticle* currentPart = GetParticle(fCurrentTrack);
180+
TParticle* currentPart = GetParticle(FairGenericStack::GetCurrentTrackNumber());
181181
if (!currentPart) {
182182
LOG(warn) << "Current track not found in stack!";
183183
}
@@ -239,7 +239,7 @@ void FairStack::FillTrackArray()
239239

240240
Int_t FairStack::GetCurrentTrackNumber() const
241241
{
242-
return FSTrackMapLookup(fCurrentTrack);
242+
return FSTrackMapLookup(FairGenericStack::GetCurrentTrackNumber());
243243
}
244244

245245
void FairStack::UpdateTrackIndex(TRefArray* detList)
@@ -302,7 +302,6 @@ void FairStack::UpdateTrackIndex(TRefArray* detList)
302302
void FairStack::Reset()
303303
{
304304
fIndex = 0;
305-
fCurrentTrack = -1;
306305
fNPrimaries = fNParticles = fNTracks = 0;
307306
while (!fStack.empty()) {
308307
fStack.pop();

examples/common/mcstack/FairStack.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,6 @@ class FairStack : public FairGenericStack
124124
**/
125125
TParticle* PopPrimaryForTracking(Int_t iPrim) override;
126126

127-
/** Set the current track number
128-
** Declared in TVirtualMCStack
129-
*@param iTrack track number
130-
**/
131-
void SetCurrentTrack(Int_t iTrack) override { fCurrentTrack = iTrack; }
132-
133127
/** Get total number of tracks
134128
** Declared in TVirtualMCStack
135129
**/
@@ -241,7 +235,6 @@ class FairStack : public FairGenericStack
241235
std::map<std::pair<Int_t, Int_t>, Int_t> fPointsMap; //!
242236

243237
/** Some indizes and counters **/
244-
Int_t fCurrentTrack; //! Index of current track
245238
Int_t fNPrimaries; //! Number of primary particles
246239
Int_t fNParticles; //! Number of entries in fParticles
247240
Int_t fNTracks; //! Number of entries in fTracks

fairroot/base/sim/FairGenericStack.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ class FairGenericStack : public TVirtualMCStack
4848
*/
4949
Int_t GetCurrentTrackID() const { return GetCurrentTrackNumber(); }
5050

51+
/** Set the current track number
52+
** Declared in TVirtualMCStack
53+
*@param iTrack track number
54+
**/
55+
void SetCurrentTrack(Int_t iTrack) override { fCurrentTrack = iTrack; }
56+
57+
/** Get the number of the current track
58+
** Declared in TVirtualMCStack
59+
**/
60+
Int_t GetCurrentTrackNumber() const override { return fCurrentTrack; }
61+
5162
/** Virtual method PushTrack.
5263
** Add a TParticle to the stack.
5364
** This function has an extra argument wrt to the function defined in the base class.
@@ -98,7 +109,11 @@ class FairGenericStack : public TVirtualMCStack
98109
virtual void FinishPrimary() {}
99110

100111
/** Resets arrays and stack and deletes particles and tracks **/
101-
virtual void Reset() { fFSTrackMap.clear(); }
112+
virtual void Reset()
113+
{
114+
fCurrentTrack = -1;
115+
fFSTrackMap.clear();
116+
}
102117

103118
/** Register the MCTrack array to the Root Manager **/
104119
virtual void Register() {}
@@ -212,6 +227,9 @@ class FairGenericStack : public TVirtualMCStack
212227
return track;
213228
}
214229

230+
private:
231+
Int_t fCurrentTrack{-1}; //!< Index of current track
232+
215233
ClassDefOverride(FairGenericStack, 1);
216234
};
217235

templates/project_root_containers/MyProjData/MyProjStack.cxx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ MyProjStack::MyProjStack(Int_t size)
4545
, fIndexMap()
4646
, fIndexIter()
4747
, fPointsMap()
48-
, fCurrentTrack(-1)
4948
, fNPrimaries(0)
5049
, fNParticles(0)
5150
, fNTracks(0)
@@ -68,7 +67,6 @@ MyProjStack::MyProjStack(const MyProjStack& right)
6867
, fIndexMap()
6968
, fIndexIter()
7069
, fPointsMap()
71-
, fCurrentTrack()
7270
, fNPrimaries()
7371
, fNParticles()
7472
, fNTracks()
@@ -187,8 +185,9 @@ TParticle* MyProjStack::PopNextTrack(Int_t& iTrack)
187185
return NULL;
188186
}
189187

190-
fCurrentTrack = thisParticle->GetStatusCode();
191-
iTrack = fCurrentTrack;
188+
const auto currentTrack = thisParticle->GetStatusCode();
189+
SetCurrentTrack(currentTrack);
190+
iTrack = currentTrack;
192191

193192
return thisParticle;
194193
}
@@ -220,7 +219,7 @@ TParticle* MyProjStack::PopPrimaryForTracking(Int_t iPrim)
220219
// ----- Virtual public method GetCurrentTrack -------------------------
221220
TParticle* MyProjStack::GetCurrentTrack() const
222221
{
223-
TParticle* currentPart = GetParticle(fCurrentTrack);
222+
TParticle* currentPart = GetParticle(GetCurrentTrackNumber());
224223
if (!currentPart) {
225224
LOG(warning) << "MyProjStack: Current track not found in stack!";
226225
}
@@ -342,7 +341,6 @@ void MyProjStack::UpdateTrackIndex(TRefArray* detList)
342341
void MyProjStack::Reset()
343342
{
344343
fIndex = 0;
345-
fCurrentTrack = -1;
346344
fNPrimaries = fNParticles = fNTracks = 0;
347345
while (!fStack.empty()) {
348346
fStack.pop();
@@ -384,7 +382,7 @@ void MyProjStack::AddPoint(DetectorId detId)
384382
{
385383
Int_t iDet = detId;
386384
// cout << "Add point for Detektor" << iDet << endl;
387-
pair<Int_t, Int_t> a(fCurrentTrack, iDet);
385+
pair<Int_t, Int_t> a(GetCurrentTrackID(), iDet);
388386
if (fPointsMap.find(a) == fPointsMap.end()) {
389387
fPointsMap[a] = 1;
390388
} else {

templates/project_root_containers/MyProjData/MyProjStack.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,6 @@ class MyProjStack : public FairGenericStack
125125
**/
126126
virtual TParticle* PopPrimaryForTracking(Int_t iPrim);
127127

128-
/** Set the current track number
129-
** Declared in TVirtualMCStack
130-
*@param iTrack track number
131-
**/
132-
virtual void SetCurrentTrack(Int_t iTrack) { fCurrentTrack = iTrack; }
133-
134128
/** Get total number of tracks
135129
** Declared in TVirtualMCStack
136130
**/
@@ -146,11 +140,6 @@ class MyProjStack : public FairGenericStack
146140
**/
147141
virtual TParticle* GetCurrentTrack() const;
148142

149-
/** Get the number of the current track
150-
** Declared in TVirtualMCStack
151-
**/
152-
virtual Int_t GetCurrentTrackNumber() const { return fCurrentTrack; }
153-
154143
/** Get the track number of the parent of the current track
155144
** Declared in TVirtualMCStack
156145
**/
@@ -224,7 +213,6 @@ class MyProjStack : public FairGenericStack
224213
std::map<std::pair<Int_t, Int_t>, Int_t> fPointsMap; //!
225214

226215
/** Some indizes and counters **/
227-
Int_t fCurrentTrack; //! Index of current track
228216
Int_t fNPrimaries; //! Number of primary particles
229217
Int_t fNParticles; //! Number of entries in fParticles
230218
Int_t fNTracks; //! Number of entries in fTracks

templates/project_stl_containers/MyProjData/MyProjStack.cxx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ MyProjStack::MyProjStack(Int_t size)
4545
, fIndexMap()
4646
, fIndexIter()
4747
, fPointsMap()
48-
, fCurrentTrack(-1)
4948
, fNPrimaries(0)
5049
, fNParticles(0)
5150
, fNTracks(0)
@@ -68,7 +67,6 @@ MyProjStack::MyProjStack(const MyProjStack& right)
6867
, fIndexMap()
6968
, fIndexIter()
7069
, fPointsMap()
71-
, fCurrentTrack()
7270
, fNPrimaries()
7371
, fNParticles()
7472
, fNTracks()
@@ -187,8 +185,9 @@ TParticle* MyProjStack::PopNextTrack(Int_t& iTrack)
187185
return NULL;
188186
}
189187

190-
fCurrentTrack = thisParticle->GetStatusCode();
191-
iTrack = fCurrentTrack;
188+
const auto currentTrack = thisParticle->GetStatusCode();
189+
SetCurrentTrack(currentTrack);
190+
iTrack = currentTrack;
192191

193192
return thisParticle;
194193
}
@@ -220,7 +219,7 @@ TParticle* MyProjStack::PopPrimaryForTracking(Int_t iPrim)
220219
// ----- Virtual public method GetCurrentTrack -------------------------
221220
TParticle* MyProjStack::GetCurrentTrack() const
222221
{
223-
TParticle* currentPart = GetParticle(fCurrentTrack);
222+
TParticle* currentPart = GetParticle(GetCurrentTrackNumber());
224223
if (!currentPart) {
225224
LOG(warning) << "MyProjStack: Current track not found in stack!";
226225
}
@@ -347,7 +346,6 @@ void MyProjStack::UpdateTrackIndex(TRefArray* detList)
347346
void MyProjStack::Reset()
348347
{
349348
fIndex = 0;
350-
fCurrentTrack = -1;
351349
fNPrimaries = fNParticles = fNTracks = 0;
352350
while (!fStack.empty()) {
353351
fStack.pop();
@@ -389,7 +387,7 @@ void MyProjStack::AddPoint(DetectorId detId)
389387
{
390388
Int_t iDet = detId;
391389
// cout << "Add point for Detektor" << iDet << endl;
392-
pair<Int_t, Int_t> a(fCurrentTrack, iDet);
390+
pair<Int_t, Int_t> a(GetCurrentTrackID(), iDet);
393391
if (fPointsMap.find(a) == fPointsMap.end()) {
394392
fPointsMap[a] = 1;
395393
} else {

templates/project_stl_containers/MyProjData/MyProjStack.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,6 @@ class MyProjStack : public FairGenericStack
125125
**/
126126
virtual TParticle* PopPrimaryForTracking(Int_t iPrim);
127127

128-
/** Set the current track number
129-
** Declared in TVirtualMCStack
130-
*@param iTrack track number
131-
**/
132-
virtual void SetCurrentTrack(Int_t iTrack) { fCurrentTrack = iTrack; }
133-
134128
/** Get total number of tracks
135129
** Declared in TVirtualMCStack
136130
**/
@@ -146,11 +140,6 @@ class MyProjStack : public FairGenericStack
146140
**/
147141
virtual TParticle* GetCurrentTrack() const;
148142

149-
/** Get the number of the current track
150-
** Declared in TVirtualMCStack
151-
**/
152-
virtual Int_t GetCurrentTrackNumber() const { return fCurrentTrack; }
153-
154143
/** Get the track number of the parent of the current track
155144
** Declared in TVirtualMCStack
156145
**/
@@ -224,7 +213,6 @@ class MyProjStack : public FairGenericStack
224213
std::map<std::pair<Int_t, Int_t>, Int_t> fPointsMap; //!
225214

226215
/** Some indizes and counters **/
227-
Int_t fCurrentTrack; //! Index of current track
228216
Int_t fNPrimaries; //! Number of primary particles
229217
Int_t fNParticles; //! Number of entries in fParticles
230218
Int_t fNTracks; //! Number of entries in fTracks

0 commit comments

Comments
 (0)