Skip to content

Commit

Permalink
feat(FairGenericStack): Provide basic current track handling
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
ChristianTackeGSI committed Sep 19, 2024
1 parent 9676612 commit 23a39ba
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 52 deletions.
11 changes: 5 additions & 6 deletions examples/common/mcstack/FairStack.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ FairStack::FairStack(Int_t size)
, fStoreMap()
, fIndexMap()
, fPointsMap()
, fCurrentTrack(-1)
, fNPrimaries(0)
, fNParticles(0)
, fNTracks(0)
Expand Down Expand Up @@ -149,8 +148,9 @@ TParticle* FairStack::PopNextTrack(Int_t& iTrack)
return nullptr;
}

fCurrentTrack = thisParticle->GetStatusCode();
iTrack = fCurrentTrack;
const auto currentTrack = thisParticle->GetStatusCode();
SetCurrentTrack(currentTrack);
iTrack = currentTrack;

return thisParticle;
}
Expand All @@ -177,7 +177,7 @@ TParticle* FairStack::PopPrimaryForTracking(Int_t iPrim)

TParticle* FairStack::GetCurrentTrack() const
{
TParticle* currentPart = GetParticle(fCurrentTrack);
TParticle* currentPart = GetParticle(FairGenericStack::GetCurrentTrackNumber());
if (!currentPart) {
LOG(warn) << "Current track not found in stack!";
}
Expand Down Expand Up @@ -239,7 +239,7 @@ void FairStack::FillTrackArray()

Int_t FairStack::GetCurrentTrackNumber() const
{
return FSTrackMapLookup(fCurrentTrack);
return FSTrackMapLookup(FairGenericStack::GetCurrentTrackNumber());
}

void FairStack::UpdateTrackIndex(TRefArray* detList)
Expand Down Expand Up @@ -302,7 +302,6 @@ void FairStack::UpdateTrackIndex(TRefArray* detList)
void FairStack::Reset()
{
fIndex = 0;
fCurrentTrack = -1;
fNPrimaries = fNParticles = fNTracks = 0;
while (!fStack.empty()) {
fStack.pop();
Expand Down
7 changes: 0 additions & 7 deletions examples/common/mcstack/FairStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,6 @@ class FairStack : public FairGenericStack
**/
TParticle* PopPrimaryForTracking(Int_t iPrim) override;

/** Set the current track number
** Declared in TVirtualMCStack
*@param iTrack track number
**/
void SetCurrentTrack(Int_t iTrack) override { fCurrentTrack = iTrack; }

/** Get total number of tracks
** Declared in TVirtualMCStack
**/
Expand Down Expand Up @@ -241,7 +235,6 @@ class FairStack : public FairGenericStack
std::map<std::pair<Int_t, Int_t>, Int_t> fPointsMap; //!

/** Some indizes and counters **/
Int_t fCurrentTrack; //! Index of current track
Int_t fNPrimaries; //! Number of primary particles
Int_t fNParticles; //! Number of entries in fParticles
Int_t fNTracks; //! Number of entries in fTracks
Expand Down
20 changes: 19 additions & 1 deletion fairroot/base/sim/FairGenericStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ class FairGenericStack : public TVirtualMCStack
*/
Int_t GetCurrentTrackID() const { return GetCurrentTrackNumber(); }

/** Set the current track number
** Declared in TVirtualMCStack
*@param iTrack track number
**/
void SetCurrentTrack(Int_t iTrack) override { fCurrentTrack = iTrack; }

/** Get the number of the current track
** Declared in TVirtualMCStack
**/
Int_t GetCurrentTrackNumber() const override { return fCurrentTrack; }

/** Virtual method PushTrack.
** Add a TParticle to the stack.
** This function has an extra argument wrt to the function defined in the base class.
Expand Down Expand Up @@ -98,7 +109,11 @@ class FairGenericStack : public TVirtualMCStack
virtual void FinishPrimary() {}

/** Resets arrays and stack and deletes particles and tracks **/
virtual void Reset() { fFSTrackMap.clear(); }
virtual void Reset()
{
fCurrentTrack = -1;
fFSTrackMap.clear();
}

/** Register the MCTrack array to the Root Manager **/
virtual void Register() {}
Expand Down Expand Up @@ -212,6 +227,9 @@ class FairGenericStack : public TVirtualMCStack
return track;
}

private:
Int_t fCurrentTrack{-1}; //!< Index of current track

ClassDefOverride(FairGenericStack, 1);
};

Expand Down
12 changes: 5 additions & 7 deletions templates/project_root_containers/MyProjData/MyProjStack.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ MyProjStack::MyProjStack(Int_t size)
, fIndexMap()
, fIndexIter()
, fPointsMap()
, fCurrentTrack(-1)
, fNPrimaries(0)
, fNParticles(0)
, fNTracks(0)
Expand All @@ -68,7 +67,6 @@ MyProjStack::MyProjStack(const MyProjStack& right)
, fIndexMap()
, fIndexIter()
, fPointsMap()
, fCurrentTrack()
, fNPrimaries()
, fNParticles()
, fNTracks()
Expand Down Expand Up @@ -187,8 +185,9 @@ TParticle* MyProjStack::PopNextTrack(Int_t& iTrack)
return NULL;
}

fCurrentTrack = thisParticle->GetStatusCode();
iTrack = fCurrentTrack;
const auto currentTrack = thisParticle->GetStatusCode();
SetCurrentTrack(currentTrack);
iTrack = currentTrack;

return thisParticle;
}
Expand Down Expand Up @@ -220,7 +219,7 @@ TParticle* MyProjStack::PopPrimaryForTracking(Int_t iPrim)
// ----- Virtual public method GetCurrentTrack -------------------------
TParticle* MyProjStack::GetCurrentTrack() const
{
TParticle* currentPart = GetParticle(fCurrentTrack);
TParticle* currentPart = GetParticle(GetCurrentTrackNumber());
if (!currentPart) {
LOG(warning) << "MyProjStack: Current track not found in stack!";
}
Expand Down Expand Up @@ -342,7 +341,6 @@ void MyProjStack::UpdateTrackIndex(TRefArray* detList)
void MyProjStack::Reset()
{
fIndex = 0;
fCurrentTrack = -1;
fNPrimaries = fNParticles = fNTracks = 0;
while (!fStack.empty()) {
fStack.pop();
Expand Down Expand Up @@ -384,7 +382,7 @@ void MyProjStack::AddPoint(DetectorId detId)
{
Int_t iDet = detId;
// cout << "Add point for Detektor" << iDet << endl;
pair<Int_t, Int_t> a(fCurrentTrack, iDet);
pair<Int_t, Int_t> a(GetCurrentTrackID(), iDet);
if (fPointsMap.find(a) == fPointsMap.end()) {
fPointsMap[a] = 1;
} else {
Expand Down
12 changes: 0 additions & 12 deletions templates/project_root_containers/MyProjData/MyProjStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ class MyProjStack : public FairGenericStack
**/
virtual TParticle* PopPrimaryForTracking(Int_t iPrim);

/** Set the current track number
** Declared in TVirtualMCStack
*@param iTrack track number
**/
virtual void SetCurrentTrack(Int_t iTrack) { fCurrentTrack = iTrack; }

/** Get total number of tracks
** Declared in TVirtualMCStack
**/
Expand All @@ -146,11 +140,6 @@ class MyProjStack : public FairGenericStack
**/
virtual TParticle* GetCurrentTrack() const;

/** Get the number of the current track
** Declared in TVirtualMCStack
**/
virtual Int_t GetCurrentTrackNumber() const { return fCurrentTrack; }

/** Get the track number of the parent of the current track
** Declared in TVirtualMCStack
**/
Expand Down Expand Up @@ -224,7 +213,6 @@ class MyProjStack : public FairGenericStack
std::map<std::pair<Int_t, Int_t>, Int_t> fPointsMap; //!

/** Some indizes and counters **/
Int_t fCurrentTrack; //! Index of current track
Int_t fNPrimaries; //! Number of primary particles
Int_t fNParticles; //! Number of entries in fParticles
Int_t fNTracks; //! Number of entries in fTracks
Expand Down
12 changes: 5 additions & 7 deletions templates/project_stl_containers/MyProjData/MyProjStack.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ MyProjStack::MyProjStack(Int_t size)
, fIndexMap()
, fIndexIter()
, fPointsMap()
, fCurrentTrack(-1)
, fNPrimaries(0)
, fNParticles(0)
, fNTracks(0)
Expand All @@ -68,7 +67,6 @@ MyProjStack::MyProjStack(const MyProjStack& right)
, fIndexMap()
, fIndexIter()
, fPointsMap()
, fCurrentTrack()
, fNPrimaries()
, fNParticles()
, fNTracks()
Expand Down Expand Up @@ -187,8 +185,9 @@ TParticle* MyProjStack::PopNextTrack(Int_t& iTrack)
return NULL;
}

fCurrentTrack = thisParticle->GetStatusCode();
iTrack = fCurrentTrack;
const auto currentTrack = thisParticle->GetStatusCode();
SetCurrentTrack(currentTrack);
iTrack = currentTrack;

return thisParticle;
}
Expand Down Expand Up @@ -220,7 +219,7 @@ TParticle* MyProjStack::PopPrimaryForTracking(Int_t iPrim)
// ----- Virtual public method GetCurrentTrack -------------------------
TParticle* MyProjStack::GetCurrentTrack() const
{
TParticle* currentPart = GetParticle(fCurrentTrack);
TParticle* currentPart = GetParticle(GetCurrentTrackNumber());
if (!currentPart) {
LOG(warning) << "MyProjStack: Current track not found in stack!";
}
Expand Down Expand Up @@ -347,7 +346,6 @@ void MyProjStack::UpdateTrackIndex(TRefArray* detList)
void MyProjStack::Reset()
{
fIndex = 0;
fCurrentTrack = -1;
fNPrimaries = fNParticles = fNTracks = 0;
while (!fStack.empty()) {
fStack.pop();
Expand Down Expand Up @@ -389,7 +387,7 @@ void MyProjStack::AddPoint(DetectorId detId)
{
Int_t iDet = detId;
// cout << "Add point for Detektor" << iDet << endl;
pair<Int_t, Int_t> a(fCurrentTrack, iDet);
pair<Int_t, Int_t> a(GetCurrentTrackID(), iDet);
if (fPointsMap.find(a) == fPointsMap.end()) {
fPointsMap[a] = 1;
} else {
Expand Down
12 changes: 0 additions & 12 deletions templates/project_stl_containers/MyProjData/MyProjStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@ class MyProjStack : public FairGenericStack
**/
virtual TParticle* PopPrimaryForTracking(Int_t iPrim);

/** Set the current track number
** Declared in TVirtualMCStack
*@param iTrack track number
**/
virtual void SetCurrentTrack(Int_t iTrack) { fCurrentTrack = iTrack; }

/** Get total number of tracks
** Declared in TVirtualMCStack
**/
Expand All @@ -146,11 +140,6 @@ class MyProjStack : public FairGenericStack
**/
virtual TParticle* GetCurrentTrack() const;

/** Get the number of the current track
** Declared in TVirtualMCStack
**/
virtual Int_t GetCurrentTrackNumber() const { return fCurrentTrack; }

/** Get the track number of the parent of the current track
** Declared in TVirtualMCStack
**/
Expand Down Expand Up @@ -224,7 +213,6 @@ class MyProjStack : public FairGenericStack
std::map<std::pair<Int_t, Int_t>, Int_t> fPointsMap; //!

/** Some indizes and counters **/
Int_t fCurrentTrack; //! Index of current track
Int_t fNPrimaries; //! Number of primary particles
Int_t fNParticles; //! Number of entries in fParticles
Int_t fNTracks; //! Number of entries in fTracks
Expand Down

0 comments on commit 23a39ba

Please sign in to comment.