Skip to content

Commit 0b4ce58

Browse files
authored
Merge pull request #142 from rest-for-physics/globalTimeReset
Global time reset
2 parents 65599da + 93dc7ce commit 0b4ce58

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

inc/TRestGeant4Metadata.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ class TRestGeant4Metadata : public TRestMetadata {
117117
/// (fFullChain=true), or just a single decay (fFullChain=false).
118118
Bool_t fFullChain = true;
119119

120+
/// \brief Reset global time in case of a long radioactive decay, the global time of
121+
/// the decay is stored in the variable offset defined on TRestGeant4Track
122+
Bool_t fResetGlobalTime = true;
123+
124+
/// \brief Time precision, in us, to determine if the global time has to be reset
125+
/// or not.
126+
Double_t fResetTimePrecision = 1;
127+
120128
/// \brief If defined, it will stop the full chain decay simulation when one of these isotope appears.
121129
std::set<std::string> fFullChainStopIsotopes;
122130

@@ -216,6 +224,11 @@ class TRestGeant4Metadata : public TRestMetadata {
216224
/// \brief Returns true in case full decay chain simulation is enabled.
217225
inline Bool_t isFullChainActivated() const { return fFullChain; }
218226

227+
/// \brief Returns true in case global time is reset for long radioactive decays.
228+
inline Bool_t isGlobalTimeReset() const { return fResetGlobalTime; }
229+
230+
inline Double_t GetResetTimePrecision() const { return fResetTimePrecision; }
231+
219232
/// \brief Returns the isotopes that will stop the full chain decay simulation.
220233
inline std::set<std::string> GetFullChainStopIsotopes() const { return fFullChainStopIsotopes; }
221234

@@ -417,7 +430,7 @@ class TRestGeant4Metadata : public TRestMetadata {
417430
TRestGeant4Metadata(const TRestGeant4Metadata& metadata);
418431
TRestGeant4Metadata& operator=(const TRestGeant4Metadata& metadata);
419432

420-
ClassDefOverride(TRestGeant4Metadata, 19);
433+
ClassDefOverride(TRestGeant4Metadata, 20);
421434

422435
// Allow modification of otherwise inaccessible / immutable members that shouldn't be modified by the user
423436
friend class SteppingAction;

inc/TRestGeant4Track.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TRestGeant4Track {
4242
std::vector<Int_t> fSecondaryTrackIDs;
4343

4444
Double_t fGlobalTimestamp;
45+
Double_t fTimeOffset = 0;
4546
Double_t fTimeLength;
4647

4748
Double_t fInitialKineticEnergy;
@@ -65,6 +66,8 @@ class TRestGeant4Track {
6566
fHits.SetTrack(this);
6667
}
6768

69+
inline void SetTimeOffset(const double tOffset) { fTimeOffset = tOffset; }
70+
6871
inline TString GetCreatorProcess() const { return fCreatorProcess; }
6972

7073
inline void AddSecondaryTrackID(Int_t trackID) { fSecondaryTrackIDs.push_back(trackID); }
@@ -76,6 +79,7 @@ class TRestGeant4Track {
7679
inline Int_t GetParentID() const { return fParentID; }
7780
inline TString GetParticleName() const { return fParticleName; }
7881
inline Double_t GetGlobalTime() const { return fGlobalTimestamp; }
82+
inline Double_t GetTimeOffset() const { return fTimeOffset; }
7983
inline Double_t GetTimeLength() const { return fTimeLength; }
8084
inline Double_t GetInitialKineticEnergy() const { return fInitialKineticEnergy; }
8185
inline TVector3 GetInitialPosition() const { return fInitialPosition; }
@@ -136,7 +140,7 @@ class TRestGeant4Track {
136140

137141
friend class TRestGeant4Event; // allows TRestGeant4Event to access private members
138142

139-
ClassDef(TRestGeant4Track, 5); // REST event superclass
143+
ClassDef(TRestGeant4Track, 6); // REST event superclass
140144

141145
// restG4
142146
public:

src/TRestGeant4Metadata.cxx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@
138138
/// * **printProgress**: if enabled, a message showing the progress of the simulation will be printed
139139
/// periodically. This option is enabled by default.
140140
///
141+
/// * **resetGlobalTime**: when enabled it reset the global time stamp in case of long radioactive decay.
142+
/// This option is enabled by default.
143+
///
144+
/// * **resetTimePrecision**: this parameter defines the time precision required to reset the global time
145+
/// in case resetGlobalTime is enabled.
146+
///
141147
/// The following example illustrates the definition of the common simulation
142148
/// parameters.
143149
///
@@ -146,6 +152,8 @@
146152
/// <parameter name="gdmlFile" value="/path/to/mySetupTemplate.gdml"/>
147153
/// <parameter name="maxTargetStepSize" value="200" units="um" />
148154
/// <parameter name="subEventTimeDelay" value="100" units="us" />
155+
/// <parameter name="resetGlobalTime" value="true" />
156+
/// <parameter name="resetTimePrecision" value="1ns" />
149157
/// \endcode
150158
///
151159
/// ## 2. The primary particle generator section
@@ -847,9 +855,11 @@ void TRestGeant4Metadata::InitFromConfigFile() {
847855
}
848856
}
849857

850-
Double_t defaultTime = 1. / REST_Units::s;
858+
Double_t defaultTime = 1. / REST_Units::us;
851859
fSubEventTimeDelay = GetDblParameterWithUnits("subEventTimeDelay", defaultTime);
852860

861+
fResetTimePrecision = GetDblParameterWithUnits("resetTimePrecision", defaultTime);
862+
853863
auto nEventsString = GetParameter("nEvents");
854864
if (nEventsString == PARAMETER_NOT_FOUND_STR) {
855865
nEventsString = GetParameter("Nevents"); // old name
@@ -872,6 +882,9 @@ void TRestGeant4Metadata::InitFromConfigFile() {
872882
fRegisterEmptyTracks = ToUpper(GetParameter("registerEmptyTracks", "false")) == "TRUE" ||
873883
ToUpper(GetParameter("registerEmptyTracks", "off")) == "ON";
874884

885+
fResetGlobalTime = ToUpper(GetParameter("resetGlobalTime", "true")) == "TRUE" ||
886+
ToUpper(GetParameter("resetGlobalTime", "on")) == "ON";
887+
875888
ReadGenerator();
876889
// Detector (old storage) section is processed after initializing geometry info in Detector Construction
877890
// This allows to use regular expression to match logical or physical volumes etc.
@@ -1508,6 +1521,14 @@ void TRestGeant4Metadata::PrintMetadata() {
15081521
RESTMetadata << "GDML geometry: " << GetGdmlReference() << RESTendl;
15091522
RESTMetadata << "GDML materials reference: " << GetMaterialsReference() << RESTendl;
15101523
RESTMetadata << "Sub-event time delay: " << GetSubEventTimeDelay() << " us" << RESTendl;
1524+
1525+
if (isGlobalTimeReset()) {
1526+
RESTMetadata << "Reset global time: enabled" << RESTendl;
1527+
RESTMetadata << "Reset Time precision " << GetResetTimePrecision() << " us" << RESTendl;
1528+
} else {
1529+
RESTMetadata << "Reset global time: disabled" << RESTendl;
1530+
}
1531+
15111532
Double_t mx = GetMagneticField().X();
15121533
Double_t my = GetMagneticField().Y();
15131534
Double_t mz = GetMagneticField().Z();
@@ -1703,6 +1724,8 @@ TRestGeant4Metadata& TRestGeant4Metadata::operator=(const TRestGeant4Metadata& m
17031724
fBiasingVolumes = metadata.fBiasingVolumes;
17041725
fMaxTargetStepSize = metadata.fMaxTargetStepSize;
17051726
fSubEventTimeDelay = metadata.fSubEventTimeDelay;
1727+
fResetTimePrecision = metadata.fResetTimePrecision;
1728+
fResetGlobalTime = metadata.fResetGlobalTime;
17061729
fFullChain = metadata.fFullChain;
17071730
fSensitiveVolumes = metadata.fSensitiveVolumes;
17081731
fNEvents = metadata.fNEvents;

src/TRestGeant4Track.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ void TRestGeant4Track::PrintTrack(size_t maxHits) const {
125125
<< ToLengthString(fLength) << endl;
126126

127127
cout << " Initial position " << VectorToString(fInitialPosition) << " mm at time "
128-
<< ToTimeString(fGlobalTimestamp) << " - Time length of " << ToTimeString(fTimeLength)
129-
<< " and spatial length of " << ToLengthString(fLength) << endl;
128+
<< ToTimeString(fGlobalTimestamp) << " - Time offset " << ToTimeString(fTimeOffset)
129+
<< " - Time length of " << ToTimeString(fTimeLength) << " and spatial length of "
130+
<< ToLengthString(fLength) << endl;
130131

131132
size_t nHits = GetNumberOfHits();
132133
if (maxHits > 0 && maxHits < nHits) {

0 commit comments

Comments
 (0)