Skip to content

Commit

Permalink
Merge pull request #127 from rest-for-physics/decay-stop
Browse files Browse the repository at this point in the history
Add option to stop decay chain at any given isotope
  • Loading branch information
lobis committed May 17, 2024
2 parents cb9a331 + 7679256 commit 27577cf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
25 changes: 17 additions & 8 deletions inc/TRestGeant4Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class TRestGeant4Metadata : public TRestMetadata {
/// (fFullChain=true), or just a single decay (fFullChain=false).
Bool_t fFullChain = true;

/// \brief If defined, it will stop the full chain decay simulation when one of these isotope appears.
std::set<std::string> fFullChainStopIsotopes;

/// \brief The volume that serves as trigger for data storage. Only events that
/// deposit a non-zero energy on this volume will be registered.
std::vector<TString> fSensitiveVolumes;
Expand Down Expand Up @@ -210,8 +213,14 @@ class TRestGeant4Metadata : public TRestMetadata {
/// \brief Returns true in case full decay chain simulation is enabled.
inline Bool_t isFullChainActivated() const { return fFullChain; }

/// \brief Returns the value of the maximum Geant4 step size in mm for the
/// target volume.
/// \brief Returns the isotopes that will stop the full chain decay simulation.
inline std::set<std::string> GetFullChainStopIsotopes() const { return fFullChainStopIsotopes; }

inline Bool_t IsIsotopeFullChainStop(const std::string& isotope) const {
return fFullChainStopIsotopes.count(isotope) > 0;
}

/// \brief Returns the value of the maximum Geant4 step size in mm for the target volume.
inline Double_t GetMaxTargetStepSize() const { return fMaxTargetStepSize; }

/// \brief Returns the time gap, in us, required to consider a Geant4 hit as a
Expand Down Expand Up @@ -242,23 +251,23 @@ class TRestGeant4Metadata : public TRestMetadata {
inline void SetFullChain(Bool_t fullChain) { fFullChain = fullChain; }

/// It sets the location of the geometry files
inline void SetGeometryPath(std::string path) { fGeometryPath = path; }
inline void SetGeometryPath(const std::string& path) { fGeometryPath = path; }

/// It sets the main filename to be used for the GDML geometry
inline void SetGdmlFilename(std::string gdmlFile) { fGdmlFilename = gdmlFile; }
inline void SetGdmlFilename(const std::string& gdmlFile) { fGdmlFilename = gdmlFile; }

/// Returns the reference provided at the GDML file header
inline void SetGdmlReference(std::string reference) { fGdmlReference = reference; }
inline void SetGdmlReference(const std::string& reference) { fGdmlReference = reference; }

/// Returns the reference provided at the materials file header
inline void SetMaterialsReference(std::string reference) { fMaterialsReference = reference; }
inline void SetMaterialsReference(const std::string& reference) { fMaterialsReference = reference; }

/// Returns the number of events to be simulated.
inline Long64_t GetNumberOfEvents() const { return fNEvents; }

inline Long64_t GetNumberOfRequestedEntries() const { return fNRequestedEntries; }

inline Int_t GetSimulationMaxTimeSeconds() const { return fSimulationMaxTimeSeconds; }
inline Double_t GetSimulationMaxTimeSeconds() const { return fSimulationMaxTimeSeconds; }

inline Double_t GetSimulationTime() const { return fSimulationTime; }

Expand Down Expand Up @@ -398,7 +407,7 @@ class TRestGeant4Metadata : public TRestMetadata {
TRestGeant4Metadata(const TRestGeant4Metadata& metadata);
TRestGeant4Metadata& operator=(const TRestGeant4Metadata& metadata);

ClassDefOverride(TRestGeant4Metadata, 17);
ClassDefOverride(TRestGeant4Metadata, 18);

// Allow modification of otherwise inaccessible / immutable members that shouldn't be modified by the user
friend class SteppingAction;
Expand Down
12 changes: 11 additions & 1 deletion src/TRestGeant4Metadata.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
/// \endcode
///
/// * **cosmic**: This is a special type of generator that is used to simulate cosmic particles.
/// It takes no parameters. It uses the world size to produce an homogeneous cosmic ray flux (according to
/// It takes no parameters. It uses the world size to produce an accurate cosmic ray flux (according to
/// energy and angular distribution, which can be correlated) in the whole world volume. It is recommended to
/// use this instead of other approaches such as an infinite plane above as this generator will be
/// significantly more efficient since all particles are directed roughly towards the detector.
Expand Down Expand Up @@ -736,6 +736,7 @@

#include <TAxis.h>
#include <TGeoManager.h>
#include <TObjString.h>
#include <TRandom.h>
#include <TRestGDMLParser.h>
#include <TRestRun.h>
Expand Down Expand Up @@ -1103,6 +1104,15 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source,
SetFullChain(true);
}

const TString fullChainStopIsotopesString = GetParameter("fullChainStopIsotopes", sourceDefinition, "");
if (fullChainStopIsotopesString != "") {
TObjArray* fullChainStopIsotopesArray = fullChainStopIsotopesString.Tokenize(",");
for (int i = 0; i < fullChainStopIsotopesArray->GetEntries(); i++) {
TString isotope = ((TObjString*)fullChainStopIsotopesArray->At(i))->String();
fFullChainStopIsotopes.insert(isotope.Data());
}
}

// Angular distribution parameters
TiXmlElement* angularDefinition = GetElement("angular", sourceDefinition);
if (angularDefinition == nullptr) {
Expand Down

0 comments on commit 27577cf

Please sign in to comment.