Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to stop decay chain at any given isotope #127

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading