Skip to content

Commit 900b2a1

Browse files
committed
Add method isFromRadDecay(const int id). Checks whether particle results from radioactive decay in its history.
1 parent b2ebc90 commit 900b2a1

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

  • Detectors/Base/include/DetectorsBase

Detectors/Base/include/DetectorsBase/Stack.h

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#include "SimulationDataFormat/ParticleStatus.h"
2525
#include "Rtypes.h"
2626
#include "TParticle.h"
27-
27+
#include "TVirtualMC.h"
28+
#include "TMCProcess.h"
2829
#include <map>
2930
#include <memory>
3031
#include <stack>
@@ -210,7 +211,7 @@ class Stack : public FairGenericStack
210211
/// query if a track is a direct **or** indirect daughter of a parentID
211212
/// if trackid is same as parentid it returns true
212213
bool isTrackDaughterOf(int /*trackid*/, int /*parentid*/) const;
213-
214+
bool isFromRadDecay(const int id);
214215
bool isCurrentTrackDaughterOf(int parentid) const;
215216

216217
// returns the index of the currently transported primary
@@ -348,6 +349,40 @@ inline int Stack::getMotherTrackId(int trackid) const
348349
return mParticles[entryinParticles].getMotherTrackId();
349350
}
350351

352+
inline bool Stack::isFromRadDecay(const int id)
353+
{
354+
// Check whether particle originates directly or indirectly from radioactive decay
355+
//
356+
if (id < 0 || id >= static_cast<int>(mTrackIDtoParticlesEntry.size())) {
357+
return false;
358+
}
359+
const auto entry = mTrackIDtoParticlesEntry[id];
360+
if (entry < 0 || entry >= static_cast<int>(mParticles.size())) return false;
361+
auto part = (mParticles[entry]);
362+
363+
// primary particle ?
364+
if (part.getProcess() == 0 ) return false;
365+
// particle directly from radioactive decay ?
366+
if (part.getProcess() == kPRadDecay) {
367+
return true;
368+
}
369+
370+
// search in particle history
371+
auto imo = mTrackIDtoParticlesEntry[part.getMotherTrackId()];
372+
auto isRad = false;
373+
374+
while (imo > 0 ) {
375+
auto mother = (mParticles[imo]);
376+
if (mother.getProcess() == kPRadDecay) {
377+
isRad = true;
378+
break;
379+
}
380+
part = mother;
381+
imo = mTrackIDtoParticlesEntry[mother.getMotherTrackId()];
382+
}
383+
return isRad;
384+
}
385+
351386
inline bool Stack::isCurrentTrackDaughterOf(int parentid) const
352387
{
353388
// if parentid is current primary the answer is certainly yes

0 commit comments

Comments
 (0)