Skip to content

Commit 3669c9c

Browse files
authored
Add method isFromRadDecay(const int id). Checks whether particle resu… (#15470)
Add method isFromRadDecay(const int id). Checks whether particle results from radioactive decay in its history.
1 parent b826bf4 commit 3669c9c

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

  • Detectors/Base/include/DetectorsBase

Detectors/Base/include/DetectorsBase/Stack.h

Lines changed: 38 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,41 @@ 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()))
361+
return false;
362+
auto part = (mParticles[entry]);
363+
364+
// primary particle ?
365+
if (part.getProcess() == 0)
366+
return false;
367+
// particle directly from radioactive decay ?
368+
if (part.getProcess() == kPRadDecay) {
369+
return true;
370+
}
371+
372+
// search in particle history
373+
auto imo = mTrackIDtoParticlesEntry[part.getMotherTrackId()];
374+
auto isRad = false;
375+
while (imo > 0) {
376+
auto mother = (mParticles[imo]);
377+
if (mother.getProcess() == kPRadDecay) {
378+
isRad = true;
379+
break;
380+
}
381+
part = mother;
382+
imo = mTrackIDtoParticlesEntry[mother.getMotherTrackId()];
383+
}
384+
return isRad;
385+
}
386+
351387
inline bool Stack::isCurrentTrackDaughterOf(int parentid) const
352388
{
353389
// if parentid is current primary the answer is certainly yes

0 commit comments

Comments
 (0)