From 28bcb8a8ec90701e03ec5d0a8677aed074d1d949 Mon Sep 17 00:00:00 2001 From: Luis Obis Date: Mon, 21 Nov 2022 21:06:46 +0100 Subject: [PATCH 01/14] increased npoints default values --- inc/TRestGeant4ParticleSource.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/TRestGeant4ParticleSource.h b/inc/TRestGeant4ParticleSource.h index 491cbbb..87a0999 100644 --- a/inc/TRestGeant4ParticleSource.h +++ b/inc/TRestGeant4ParticleSource.h @@ -39,14 +39,14 @@ class TRestGeant4ParticleSource : public TRestGeant4Particle, public TRestMetada TString fAngularDistributionType = "Flux"; TString fAngularDistributionFilename; TString fAngularDistributionNameInFile; - size_t fAngularDistributionFormulaNPoints = 200; + size_t fAngularDistributionFormulaNPoints = 500; TF1* fAngularDistributionFunction = nullptr; TVector2 fAngularDistributionRange; TString fEnergyDistributionType = "Mono"; TString fEnergyDistributionFilename; TString fEnergyDistributionNameInFile; - size_t fEnergyDistributionFormulaNPoints = 500; + size_t fEnergyDistributionFormulaNPoints = 5000; TF1* fEnergyDistributionFunction = nullptr; TVector2 fEnergyDistributionRange; From 72995ac2b3b00f1d32b03a0b1478824d300482fe Mon Sep 17 00:00:00 2001 From: Luis Obis Date: Thu, 15 Dec 2022 12:09:48 +0100 Subject: [PATCH 02/14] add prototype for biasing info --- inc/TRestGeant4BiasingInfo.h | 14 ++++++++++++++ inc/TRestGeant4Metadata.h | 9 ++++++++- src/TRestGeant4BiasingInfo.cxx | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 inc/TRestGeant4BiasingInfo.h create mode 100644 src/TRestGeant4BiasingInfo.cxx diff --git a/inc/TRestGeant4BiasingInfo.h b/inc/TRestGeant4BiasingInfo.h new file mode 100644 index 0000000..cccba1c --- /dev/null +++ b/inc/TRestGeant4BiasingInfo.h @@ -0,0 +1,14 @@ + +#ifndef REST_TRESTGEANT4BIASINGINFO_H +#define REST_TRESTGEANT4BIASINGINFO_H + +class TRestGeant4BiasingInfo { + ClassDef(TRestGeant4BiasingInfo, 1); + + private: + public: + inline TRestGeant4BiasingInfo() = default; + inline ~TRestGeant4BiasingInfo() = default; +}; + +#endif // REST_TRESTGEANT4BIASINGINFO_H diff --git a/inc/TRestGeant4Metadata.h b/inc/TRestGeant4Metadata.h index 53b4288..f99ba14 100644 --- a/inc/TRestGeant4Metadata.h +++ b/inc/TRestGeant4Metadata.h @@ -37,6 +37,7 @@ #include #include +#include "TRestGeant4BiasingInfo.h" #include "TRestGeant4BiasingVolume.h" #include "TRestGeant4GeometryInfo.h" #include "TRestGeant4ParticleSource.h" @@ -64,6 +65,9 @@ class TRestGeant4Metadata : public TRestMetadata { /// Class used to store and retrieve physics info such as process names or particle names TRestGeant4PhysicsInfo fGeant4PhysicsInfo; + /// Class used to store and retrieve biasing info + TRestGeant4BiasingInfo fGeant4BiasingInfo; + /// Class used to store and retrieve Geant4 primary generator info TRestGeant4PrimaryGeneratorInfo fGeant4PrimaryGeneratorInfo; @@ -175,6 +179,9 @@ class TRestGeant4Metadata : public TRestMetadata { /// \brief Returns an immutable reference to the physics info inline const TRestGeant4PhysicsInfo& GetGeant4PhysicsInfo() const { return fGeant4PhysicsInfo; } + /// \brief Returns an immutable reference to the biasing info + inline const TRestGeant4BiasingInfo& GetGeant4BiasingInfo() const { return fGeant4BiasingInfo; } + /// \brief Returns an immutable reference to the primary generator info inline const TRestGeant4PrimaryGeneratorInfo& GetGeant4PrimaryGeneratorInfo() const { return fGeant4PrimaryGeneratorInfo; @@ -379,7 +386,7 @@ class TRestGeant4Metadata : public TRestMetadata { ~TRestGeant4Metadata(); - ClassDefOverride(TRestGeant4Metadata, 13); + ClassDefOverride(TRestGeant4Metadata, 14); // Allow modification of otherwise inaccessible / immutable members that shouldn't be modified by the user friend class SteppingAction; diff --git a/src/TRestGeant4BiasingInfo.cxx b/src/TRestGeant4BiasingInfo.cxx new file mode 100644 index 0000000..b4dc78a --- /dev/null +++ b/src/TRestGeant4BiasingInfo.cxx @@ -0,0 +1,2 @@ + +#include "TRestGeant4BiasingInfo.h" From f50bc67d3b839ad450653cd9a9d4e34934d08afb Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Wed, 22 Feb 2023 13:26:03 +0100 Subject: [PATCH 03/14] attempt to integrate with TRestGeant4Metadata --- inc/TRestGeant4BiasingInfo.h | 39 ++++++- inc/TRestGeant4GeometryInfo.h | 56 ++++++---- inc/TRestGeant4Metadata.h | 56 +++++----- src/TRestGeant4Metadata.cxx | 198 ++++++++++++++++++++-------------- 4 files changed, 223 insertions(+), 126 deletions(-) diff --git a/inc/TRestGeant4BiasingInfo.h b/inc/TRestGeant4BiasingInfo.h index cccba1c..7154a29 100644 --- a/inc/TRestGeant4BiasingInfo.h +++ b/inc/TRestGeant4BiasingInfo.h @@ -2,13 +2,46 @@ #ifndef REST_TRESTGEANT4BIASINGINFO_H #define REST_TRESTGEANT4BIASINGINFO_H +#include +#include +#include + class TRestGeant4BiasingInfo { - ClassDef(TRestGeant4BiasingInfo, 1); +ClassDef(TRestGeant4BiasingInfo, 1); + +private: + bool fEnabled = false; + unsigned int fSplittingFactor = 1; + bool fBiasOncePerTrack = true; + std::set fBiasingVolumes; + TVector3 fBiasingCenter; - private: - public: +public: inline TRestGeant4BiasingInfo() = default; + inline ~TRestGeant4BiasingInfo() = default; + + inline void SetEnabled(bool enabled) { fEnabled = enabled; } + + inline bool GetEnabled() const { return fEnabled; } + + inline void SetSplittingFactor(unsigned int splittingFactor) { fSplittingFactor = splittingFactor; } + + inline unsigned int GetSplittingFactor() const { return fSplittingFactor; } + + inline void SetBiasOncePerTrack(bool biasOncePerTrack) { fBiasOncePerTrack = biasOncePerTrack; } + + inline bool GetBiasOncePerTrack() const { return fBiasOncePerTrack; } + + inline void AddBiasingVolume(const std::string &volumeName) { fBiasingVolumes.insert(volumeName); } + + inline void ClearBiasingVolumes() { fBiasingVolumes.clear(); } + + inline std::set GetBiasingVolumes() const { return fBiasingVolumes; } + + inline void SetBiasingCenter(const TVector3 &biasingCenter) { fBiasingCenter = biasingCenter; } + + inline TVector3 GetBiasingCenter() const { return fBiasingCenter; } }; #endif // REST_TRESTGEANT4BIASINGINFO_H diff --git a/inc/TRestGeant4GeometryInfo.h b/inc/TRestGeant4GeometryInfo.h index 56b617a..163a563 100644 --- a/inc/TRestGeant4GeometryInfo.h +++ b/inc/TRestGeant4GeometryInfo.h @@ -12,29 +12,29 @@ class G4VPhysicalVolume; class TRestGeant4GeometryInfo { - ClassDef(TRestGeant4GeometryInfo, 3); +ClassDef(TRestGeant4GeometryInfo, 3); - private: +private: bool fIsAssembly = false; std::map fVolumeNameMap = {}; std::map fVolumeNameReverseMap = {}; - void PopulateFromGeant4World(const G4VPhysicalVolume*); + void PopulateFromGeant4World(const G4VPhysicalVolume *); - inline void InitializeOnDetectorConstruction(const TString& gdmlFilename, - const G4VPhysicalVolume* world) { + inline void InitializeOnDetectorConstruction(const TString &gdmlFilename, + const G4VPhysicalVolume *world) { PopulateFromGdml(gdmlFilename); PopulateFromGeant4World(world); } - public: +public: // Insertion order is important for GDML containers. These containers are filled from GDML only not Geant4 std::vector fGdmlNewPhysicalNames; std::vector fGdmlLogicalNames; std::map - fGeant4PhysicalNameToNewPhysicalNameMap; /* + fGeant4PhysicalNameToNewPhysicalNameMap; /* * only makes sense when using assembly */ @@ -44,23 +44,27 @@ class TRestGeant4GeometryInfo { std::map fLogicalToMaterialMap; std::map fPhysicalToPositionInWorldMap; - public: +public: inline TRestGeant4GeometryInfo() = default; - void PopulateFromGdml(const TString&); + void PopulateFromGdml(const TString &); - TString GetAlternativeNameFromGeant4PhysicalName(const TString&) const; - TString GetGeant4PhysicalNameFromAlternativeName(const TString&) const; + TString GetAlternativeNameFromGeant4PhysicalName(const TString &) const; + + TString GetGeant4PhysicalNameFromAlternativeName(const TString &) const; std::vector GetAllLogicalVolumes() const; + std::vector GetAllPhysicalVolumes() const; + std::vector GetAllAlternativePhysicalVolumes() const; - std::vector GetAllLogicalVolumesMatchingExpression(const TString&) const; - std::vector GetAllPhysicalVolumesMatchingExpression(const TString&) const; + std::vector GetAllLogicalVolumesMatchingExpression(const TString &) const; - inline bool IsValidGdmlName(const TString& volume) const { - for (const auto& name : fGdmlNewPhysicalNames) { + std::vector GetAllPhysicalVolumesMatchingExpression(const TString &) const; + + inline bool IsValidGdmlName(const TString &volume) const { + for (const auto &name: fGdmlNewPhysicalNames) { if (name == volume) { return true; } @@ -68,29 +72,39 @@ class TRestGeant4GeometryInfo { return false; } - inline bool IsValidPhysicalVolume(const TString& volume) const { + inline bool IsValidPhysicalVolume(const TString &volume) const { return fPhysicalToLogicalVolumeMap.count(volume) > 0; } - inline bool IsValidLogicalVolume(const TString& volume) const { + + inline bool IsValidLogicalVolume(const TString &volume) const { return fLogicalToPhysicalMap.count(volume) > 0; } - inline std::vector GetAllPhysicalVolumesFromLogical(const TString& logicalVolume) const { + + inline std::vector GetAllPhysicalVolumesFromLogical(const TString &logicalVolume) const { if (IsValidLogicalVolume(logicalVolume)) { return fLogicalToPhysicalMap.at(logicalVolume); } return {}; } - inline TVector3 GetPosition(const TString& volume) const { + inline TString GetLogicalVolumeFromPhysical(const TString &physicalVolume) const { + if (IsValidPhysicalVolume(physicalVolume)) { + return fPhysicalToLogicalVolumeMap.at(physicalVolume); + } + return {}; + } + + inline TVector3 GetPosition(const TString &volume) const { return fPhysicalToPositionInWorldMap.at(volume); } inline bool IsAssembly() const { return fIsAssembly; } - void InsertVolumeName(Int_t id, const TString& volumeName); + void InsertVolumeName(Int_t id, const TString &volumeName); TString GetVolumeFromID(Int_t id) const; - Int_t GetIDFromVolume(const TString& volumeName) const; + + Int_t GetIDFromVolume(const TString &volumeName) const; void Print() const; diff --git a/inc/TRestGeant4Metadata.h b/inc/TRestGeant4Metadata.h index c00d96f..81ebd3a 100644 --- a/inc/TRestGeant4Metadata.h +++ b/inc/TRestGeant4Metadata.h @@ -46,15 +46,17 @@ /// The main class to store the *Geant4* simulation conditions that will be used by *restG4*. class TRestGeant4Metadata : public TRestMetadata { - private: +private: void Initialize() override; void InitFromConfigFile() override; void ReadGenerator(); - void ReadParticleSource(TRestGeant4ParticleSource* src, TiXmlElement* sourceDefinition); + + void ReadParticleSource(TRestGeant4ParticleSource *src, TiXmlElement *sourceDefinition); void ReadDetector(); + void ReadBiasing(); bool fDetectorSectionInitialized = false; //! @@ -100,7 +102,7 @@ class TRestGeant4Metadata : public TRestMetadata { std::vector fMaxStepSize; /// \brief It the defines the primary source properties, particle type, momentum, energy, etc. - std::vector fParticleSource; //-> + std::vector fParticleSource; //-> /// \brief The number of biasing volumes used in the simulation. If zero, no biasing technique is used. Int_t fNBiasingVolumes = 0; @@ -167,23 +169,23 @@ class TRestGeant4Metadata : public TRestMetadata { /// The world magnetic field TVector3 fMagneticField = TVector3(0, 0, 0); - public: +public: std::set fActiveVolumesSet = {}; //! // Used for faster lookup /// \brief Returns the random seed that was used to generate the corresponding geant4 dataset. inline Long_t GetSeed() const { return fSeed; } /// \brief Returns an immutable reference to the geometry info - inline const TRestGeant4GeometryInfo& GetGeant4GeometryInfo() const { return fGeant4GeometryInfo; } + inline const TRestGeant4GeometryInfo &GetGeant4GeometryInfo() const { return fGeant4GeometryInfo; } /// \brief Returns an immutable reference to the physics info - inline const TRestGeant4PhysicsInfo& GetGeant4PhysicsInfo() const { return fGeant4PhysicsInfo; } + inline const TRestGeant4PhysicsInfo &GetGeant4PhysicsInfo() const { return fGeant4PhysicsInfo; } /// \brief Returns an immutable reference to the biasing info - inline const TRestGeant4BiasingInfo& GetGeant4BiasingInfo() const { return fGeant4BiasingInfo; } + inline const TRestGeant4BiasingInfo &GetGeant4BiasingInfo() const { return fGeant4BiasingInfo; } /// \brief Returns an immutable reference to the primary generator info - inline const TRestGeant4PrimaryGeneratorInfo& GetGeant4PrimaryGeneratorInfo() const { + inline const TRestGeant4PrimaryGeneratorInfo &GetGeant4PrimaryGeneratorInfo() const { return fGeant4PrimaryGeneratorInfo; } @@ -233,7 +235,7 @@ class TRestGeant4Metadata : public TRestMetadata { inline void SetSaveAllEvents(const Bool_t value) { fSaveAllEvents = value; } /// Sets the value of the Geant4 version - inline void SetGeant4Version(const TString& versionString) { fGeant4Version = versionString; } + inline void SetGeant4Version(const TString &versionString) { fGeant4Version = versionString; } /// Enables/disables the full chain decay generation. inline void SetFullChain(Bool_t fullChain) { fFullChain = fullChain; } @@ -263,13 +265,13 @@ class TRestGeant4Metadata : public TRestMetadata { inline Int_t GetNumberOfSources() const { return fParticleSource.size(); } /// Returns the name of the particle source with index n (Geant4 based names). - inline TRestGeant4ParticleSource* GetParticleSource(size_t n = 0) const { return fParticleSource[n]; } + inline TRestGeant4ParticleSource *GetParticleSource(size_t n = 0) const { return fParticleSource[n]; } /// Remove all the particle sources. void RemoveParticleSources(); /// Adds a new particle source. - void AddParticleSource(TRestGeant4ParticleSource* src); + void AddParticleSource(TRestGeant4ParticleSource *src); /////////////////////////////////////////////////////////// // Direct access to biasing volumes definition @@ -289,7 +291,7 @@ class TRestGeant4Metadata : public TRestMetadata { inline size_t GetNumberOfSensitiveVolumes() const { return fSensitiveVolumes.size(); } - inline const std::vector& GetSensitiveVolumes() const { return fSensitiveVolumes; } + inline const std::vector &GetSensitiveVolumes() const { return fSensitiveVolumes; } /// Sets the name of the sensitive volume inline void SetNumberOfEvents(Int_t n) { fNEvents = n; } @@ -299,8 +301,8 @@ class TRestGeant4Metadata : public TRestMetadata { inline void SetSimulationMaxTimeSeconds(Int_t seconds) { fSimulationMaxTimeSeconds = seconds; } /// Sets the name of the sensitive volume - inline void InsertSensitiveVolume(const TString& volume) { - for (const auto& sensitiveVolume : fSensitiveVolumes) { + inline void InsertSensitiveVolume(const TString &volume) { + for (const auto &sensitiveVolume: fSensitiveVolumes) { // Do not add duplicate volumes if (volume == sensitiveVolume) { return; @@ -317,7 +319,7 @@ class TRestGeant4Metadata : public TRestMetadata { /// name. Double_t GetStorageChance(TString volume); - Double_t GetMaxStepSize(const TString& volume); + Double_t GetMaxStepSize(const TString &volume); /// Returns the minimum event energy required for an event to be stored. inline Double_t GetMinimumEnergyStored() const { return fEnergyRangeStored.X(); } @@ -329,19 +331,19 @@ class TRestGeant4Metadata : public TRestMetadata { /// selected for data storage. inline unsigned int GetNumberOfActiveVolumes() const { return fActiveVolumes.size(); } - inline bool IsActiveVolume(const char* volumeName) const { + inline bool IsActiveVolume(const char *volumeName) const { return fActiveVolumesSet.count(volumeName) > 0; } //! - inline bool IsKeepTracksVolume(const char* volumeName) const { + inline bool IsKeepTracksVolume(const char *volumeName) const { return fRemoveUnwantedTracksVolumesToKeep.count(volumeName) > 0; } - inline bool IsKillVolume(const char* volumeName) const { return fKillVolumes.count(volumeName) > 0; } + inline bool IsKillVolume(const char *volumeName) const { return fKillVolumes.count(volumeName) > 0; } inline std::vector GetKillVolumes() const { std::vector result; - for (const auto& volume : fKillVolumes) { + for (const auto &volume: fKillVolumes) { result.emplace_back(volume); } return result; @@ -349,14 +351,16 @@ class TRestGeant4Metadata : public TRestMetadata { inline std::vector GetRemoveUnwantedTracksVolumesToKeep() const { std::vector result; - for (const auto& volume : fRemoveUnwantedTracksVolumesToKeep) { + for (const auto &volume: fRemoveUnwantedTracksVolumesToKeep) { result.emplace_back(volume); } return result; } Double_t GetCosmicFluxInCountsPerCm2PerSecond() const; + Double_t GetCosmicIntensityInCountsPerSecond() const; + Double_t GetEquivalentSimulatedTime() const; /// Returns a std::string with the name of the active volume with index n @@ -375,22 +379,26 @@ class TRestGeant4Metadata : public TRestMetadata { Int_t GetActiveVolumeID(TString name); - Bool_t isVolumeStored(const TString& volume) const; + Bool_t isVolumeStored(const TString &volume) const; - void SetActiveVolume(const TString& name, Double_t chance, Double_t maxStep = 0); + void SetActiveVolume(const TString &name, Double_t chance, Double_t maxStep = 0); void PrintMetadata() override; TRestGeant4Metadata(); - TRestGeant4Metadata(const char* configFilename, const std::string& name = ""); + + TRestGeant4Metadata(const char *configFilename, const std::string &name = ""); ~TRestGeant4Metadata(); - ClassDefOverride(TRestGeant4Metadata, 14); +ClassDefOverride(TRestGeant4Metadata, 14); // Allow modification of otherwise inaccessible / immutable members that shouldn't be modified by the user friend class SteppingAction; + friend class DetectorConstruction; + friend class TRestGeant4Hits; }; + #endif // RestCore_TRestGeant4Metadata diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index 8059c77..1d19188 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -758,8 +758,8 @@ TRestGeant4Metadata::TRestGeant4Metadata() : TRestMetadata() { Initialize(); } /// \param name The name of the specific metadata. It will be used to find the /// corresponding TRestGeant4Metadata section inside the RML. /// -TRestGeant4Metadata::TRestGeant4Metadata(const char* configFilename, const string& name) - : TRestMetadata(configFilename) { +TRestGeant4Metadata::TRestGeant4Metadata(const char *configFilename, const string &name) + : TRestMetadata(configFilename) { Initialize(); LoadConfigFromFile(fConfigFileName, name); @@ -808,17 +808,17 @@ void TRestGeant4Metadata::InitFromConfigFile() { if (ToUpper(seedString) == "RANDOM" || ToUpper(seedString) == "RAND" || ToUpper(seedString) == "AUTO" || seedString == "0") { auto dd = new double(); - fSeed = (uintptr_t)dd + (uintptr_t)this; + fSeed = (uintptr_t) dd + (uintptr_t) this; delete dd; } else { - fSeed = (Long_t)StringToInteger(seedString); + fSeed = (Long_t) StringToInteger(seedString); } gRandom->SetSeed(fSeed); // if "gdmlFile" is purely a file (without any path) and "geometryPath" is // defined, we recombine them together - if ((((string)fGdmlFilename).find_first_not_of("./~") == 0 || - ((string)fGdmlFilename).find("/") == string::npos) && + if ((((string) fGdmlFilename).find_first_not_of("./~") == 0 || + ((string) fGdmlFilename).find("/") == string::npos) && fGeometryPath != "") { if (fGeometryPath[fGeometryPath.Length() - 1] == '/') { fGdmlFilename = fGeometryPath + GetParameter("gdmlFile"); @@ -838,7 +838,7 @@ void TRestGeant4Metadata::InitFromConfigFile() { const auto fNRequestedEntriesString = GetParameter("nRequestedEntries"); fNRequestedEntries = - fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); + fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); fSaveAllEvents = ToUpper(GetParameter("saveAllEvents", "false")) == "TRUE" || ToUpper(GetParameter("saveAllEvents", "off")) == "ON"; @@ -849,10 +849,10 @@ void TRestGeant4Metadata::InitFromConfigFile() { fRegisterEmptyTracks = ToUpper(GetParameter("registerEmptyTracks", "false")) == "TRUE" || ToUpper(GetParameter("registerEmptyTracks", "off")) == "ON"; + ReadBiasing(); ReadGenerator(); // Detector (old storage) section is processed after initializing geometry info in Detector Construction // This allows to use regular expression to match logical or physical volumes etc. - ReadBiasing(); fMaxTargetStepSize = GetDblParameterWithUnits("maxTargetStepSize", -1); if (fMaxTargetStepSize > 0) { @@ -905,8 +905,8 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorType().Data()) != TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypes::COSMIC) { RESTError - << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" - << RESTendl; + << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" + << RESTendl; exit(1); } const auto source = GetParticleSource(); @@ -929,10 +929,10 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { const auto energyRange = source->GetEnergyDistributionRange(); const auto angularRange = source->GetAngularDistributionRange(); - auto function = (TF2*)source->GetEnergyAndAngularDistributionFunction()->Clone(); + auto function = (TF2 *) source->GetEnergyAndAngularDistributionFunction()->Clone(); // counts per second per cm2 (distribution is already integrated over uniform phi) const auto countsPerSecondPerCm2 = - function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); + function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); return countsPerSecondPerCm2; } @@ -949,6 +949,9 @@ Double_t TRestGeant4Metadata::GetEquivalentSimulatedTime() const { return seconds; } +/* + * OLD IMPLEMENTATION + * void TRestGeant4Metadata::ReadBiasing() { TiXmlElement* biasingDefinition = GetElement("biasing"); if (biasingDefinition == nullptr) { @@ -976,10 +979,6 @@ void TRestGeant4Metadata::ReadBiasing() { biasVolume.SetEnergyRange(Get2DVectorParameterWithUnits("energyRange", biasVolumeDefinition)); biasVolume.SetBiasingVolumeType(biasType); // For the moment all the volumes should be same type - /* TODO check that values are right if not printBiasingVolume with - getchar() biasVolume.PrintBiasingVolume(); getchar(); - */ - fBiasingVolumes.push_back(biasVolume); biasVolumeDefinition = GetNextElement(biasVolumeDefinition); n++; @@ -987,6 +986,49 @@ void TRestGeant4Metadata::ReadBiasing() { fNBiasingVolumes = n; } } +*/ + +void TRestGeant4Metadata::ReadBiasing() { + TiXmlElement *biasingDefinition = GetElement("biasing"); + if (biasingDefinition == nullptr) { + fGeant4BiasingInfo.SetEnabled(false); + return; + } + fGeant4BiasingInfo.SetEnabled(true); + + const int splittingFactor = + StringToInteger(GetParameter("splittingFactor", biasingDefinition, "1")); + + if (splittingFactor <= 1) { + RESTError << "Parameter 'splittingFactor' in biasing section must be set to an integer > 1" << RESTendl; + exit(1); + } + + fGeant4BiasingInfo.SetSplittingFactor(splittingFactor); + + const TVector3 center = + StringTo3DVector(GetParameter("center", biasingDefinition, "(0,0,0)")); + + + fGeant4BiasingInfo.SetBiasingCenter(center); + + std::set biasingVolumes; + TiXmlElement *volumeDefinition = GetElement("volume", biasingDefinition); + while (volumeDefinition != nullptr) { + string name = GetFieldValue("name", volumeDefinition); + if (name.empty() || name == "Not defined") { + RESTError << "volume inside biasing section defined without name" << RESTendl; + exit(1); + } + biasingVolumes.insert(name); + + volumeDefinition = GetNextElement(volumeDefinition); + } + + for (const auto &volume: biasingVolumes) { + fGeant4BiasingInfo.AddBiasingVolume(volume); + } +} /////////////////////////////////////////////// /// \brief Reads the generator section defined inside TRestGeant4Metadata. @@ -1022,35 +1064,35 @@ void TRestGeant4Metadata::ReadGenerator() { // center of the volume (i.e. gasTarget) but if i.e rotation or side are // defined and not relevant we should set it to -1 - TiXmlElement* generatorDefinition = GetElement("generator"); + TiXmlElement *generatorDefinition = GetElement("generator"); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorType = - SpatialGeneratorTypesToString(StringToSpatialGeneratorTypes(GetParameter( - "type", generatorDefinition, SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME)))); + SpatialGeneratorTypesToString(StringToSpatialGeneratorTypes(GetParameter( + "type", generatorDefinition, SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME)))); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorShape = - SpatialGeneratorShapesToString(StringToSpatialGeneratorShapes(GetParameter( - "shape", generatorDefinition, SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX)))); + SpatialGeneratorShapesToString(StringToSpatialGeneratorShapes(GetParameter( + "shape", generatorDefinition, SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX)))); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorFrom = GetParameter("from", generatorDefinition); if (fGeant4PrimaryGeneratorInfo.fSpatialGeneratorFrom != PARAMETER_NOT_FOUND_STR) { fGeant4PrimaryGeneratorInfo.fSpatialGeneratorShape = - SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML); + SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML); } fGeant4PrimaryGeneratorInfo.fSpatialGeneratorSize = - Get3DVectorParameterWithUnits("size", generatorDefinition, {0, 0, 0}); + Get3DVectorParameterWithUnits("size", generatorDefinition, {0, 0, 0}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorPosition = - Get3DVectorParameterWithUnits("position", generatorDefinition, {0, 0, 0}); + Get3DVectorParameterWithUnits("position", generatorDefinition, {0, 0, 0}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorRotationAxis = - Get3DVectorParameterWithUnits("rotationAxis", generatorDefinition, {0, 0, 1}); + Get3DVectorParameterWithUnits("rotationAxis", generatorDefinition, {0, 0, 1}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorRotationValue = - GetDblParameterWithUnits("rotationAngle", generatorDefinition, 0); + GetDblParameterWithUnits("rotationAngle", generatorDefinition, 0); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorSpatialDensityFunction = - GetParameter("densityFunc", generatorDefinition, "1"); + GetParameter("densityFunc", generatorDefinition, "1"); - TiXmlElement* sourceDefinition = GetElement("source", generatorDefinition); + TiXmlElement *sourceDefinition = GetElement("source", generatorDefinition); while (sourceDefinition) { string use = GetParameter("use", sourceDefinition, ""); - TRestGeant4ParticleSource* source = TRestGeant4ParticleSource::instantiate(use); + TRestGeant4ParticleSource *source = TRestGeant4ParticleSource::instantiate(use); ReadParticleSource(source, sourceDefinition); AddParticleSource(source); @@ -1067,8 +1109,8 @@ void TRestGeant4Metadata::ReadGenerator() { /////////////////////////////////////////////// /// \brief It reads the SetParticleName(GetParameter("particle", sourceDefinition)); source->SetExcitationLevel(StringToDouble(GetParameter("excitedLevel", sourceDefinition))); @@ -1081,12 +1123,12 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, } // Angular distribution parameters - TiXmlElement* angularDefinition = GetElement("angular", sourceDefinition); + TiXmlElement *angularDefinition = GetElement("angular", sourceDefinition); if (angularDefinition == nullptr) { angularDefinition = GetElement("angularDist", sourceDefinition); // old name } source->SetAngularDistributionType(GetParameter( - "type", angularDefinition, AngularDistributionTypesToString(AngularDistributionTypes::FLUX))); + "type", angularDefinition, AngularDistributionTypesToString(AngularDistributionTypes::FLUX))); if (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::TH1D) { source->SetAngularDistributionFilename(SearchFile(GetParameter("file", angularDefinition))); @@ -1097,7 +1139,7 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, source->SetAngularDistributionNameInFile(name); } source->SetAngularDistributionRange( - Get2DVectorParameterWithUnits("range", angularDefinition, {0, TMath::Pi()})); + Get2DVectorParameterWithUnits("range", angularDefinition, {0, TMath::Pi()})); if (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::FORMULA) { source->SetAngularDistributionFormula(GetParameter("name", angularDefinition)); @@ -1105,11 +1147,11 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, const auto function = source->GetAngularDistributionFunction(); if (source->GetAngularDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetAngularDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); } if (source->GetAngularDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetAngularDistributionRange( - {source->GetAngularDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetAngularDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } } if ((StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == @@ -1117,24 +1159,24 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::FORMULA2)) { source->SetAngularDistributionFormulaNPoints(static_cast(GetDblParameterWithUnits( - "nPoints", angularDefinition, source->GetAngularDistributionFormulaNPoints()))); + "nPoints", angularDefinition, source->GetAngularDistributionFormulaNPoints()))); } if (GetNumberOfSources() == 0 && StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == - AngularDistributionTypes::BACK_TO_BACK) { + AngularDistributionTypes::BACK_TO_BACK) { cout << "WARNING: First source cannot be backtoback. Setting it to isotropic" << endl; source->SetAngularDistributionType( - AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC)); + AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC)); } source->SetDirection(StringTo3DVector(GetParameter("direction", angularDefinition, "(1,0,0)"))); // Energy distribution parameters - TiXmlElement* energyDefinition = GetElement("energy", sourceDefinition); + TiXmlElement *energyDefinition = GetElement("energy", sourceDefinition); if (energyDefinition == nullptr) { energyDefinition = GetElement("energyDist", sourceDefinition); // old name } source->SetEnergyDistributionType(GetParameter( - "type", energyDefinition, EnergyDistributionTypesToString(EnergyDistributionTypes::MONO))); + "type", energyDefinition, EnergyDistributionTypesToString(EnergyDistributionTypes::MONO))); if (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == EnergyDistributionTypes::TH1D) { source->SetEnergyDistributionFilename(SearchFile(GetParameter("file", energyDefinition))); @@ -1159,11 +1201,11 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, const auto function = source->GetEnergyDistributionFunction(); if (source->GetEnergyDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetEnergyDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); } if (source->GetEnergyDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetEnergyDistributionRange( - {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } } if ((StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == @@ -1171,12 +1213,12 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == EnergyDistributionTypes::FORMULA2)) { source->SetEnergyDistributionFormulaNPoints(static_cast(GetDblParameterWithUnits( - "nPoints", energyDefinition, source->GetEnergyDistributionFormulaNPoints()))); + "nPoints", energyDefinition, source->GetEnergyDistributionFormulaNPoints()))); } if (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == - EnergyDistributionTypes::FORMULA2 && + EnergyDistributionTypes::FORMULA2 && StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == - AngularDistributionTypes::FORMULA2) { + AngularDistributionTypes::FORMULA2) { const auto empty = TString(""); auto energyDistName = GetParameter("name", energyDefinition, empty); auto angularDistName = GetParameter("name", energyDefinition, empty); @@ -1209,21 +1251,21 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, // Set energy range if (source->GetEnergyDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetEnergyDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); } if (source->GetEnergyDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetEnergyDistributionRange( - {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } // Set angular range if (source->GetAngularDistributionRangeMin() < function->GetYaxis()->GetXmin()) { source->SetAngularDistributionRange( - {function->GetYaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); + {function->GetYaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); } if (source->GetAngularDistributionRangeMax() > function->GetYaxis()->GetXmax()) { source->SetAngularDistributionRange( - {source->GetAngularDistributionRangeMin(), function->GetYaxis()->GetXmax()}); + {source->GetAngularDistributionRangeMin(), function->GetYaxis()->GetXmax()}); } } // allow custom configuration from the class @@ -1232,13 +1274,13 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, } void TRestGeant4Metadata::RemoveParticleSources() { - for (auto source : fParticleSource) { + for (auto source: fParticleSource) { delete source; } fParticleSource.clear(); } -void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource* src) { +void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource *src) { fParticleSource.push_back(src); } @@ -1258,22 +1300,22 @@ void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource* src) { /// void TRestGeant4Metadata::ReadDetector() { RESTInfo << "TRestGeant4Metadata: Processing detector section" << RESTendl; - TiXmlElement* detectorDefinition = GetElement("detector"); + TiXmlElement *detectorDefinition = GetElement("detector"); if (detectorDefinition == nullptr) { RESTError << "Detector section () is not present in metadata!" << RESTendl; exit(1); } const bool activateAllVolumes = - StringToBool(GetParameter("activateAllVolumes", detectorDefinition, "true")); + StringToBool(GetParameter("activateAllVolumes", detectorDefinition, "true")); RESTInfo << "TRestGeant4Metadata: Setting 'fActivateAllVolumes' to " << fActivateAllVolumes << RESTendl; fActivateAllVolumes = activateAllVolumes; - TiXmlElement* removeUnwantedTracksDefinition = GetElement("removeUnwantedTracks", detectorDefinition); + TiXmlElement *removeUnwantedTracksDefinition = GetElement("removeUnwantedTracks", detectorDefinition); if (removeUnwantedTracksDefinition != nullptr) { fRemoveUnwantedTracks = StringToBool(GetParameter("enabled", removeUnwantedTracksDefinition, "true")); fRemoveUnwantedTracksKeepZeroEnergyTracks = - StringToBool(GetParameter("keepZeroEnergyTracks", removeUnwantedTracksDefinition, "false")); + StringToBool(GetParameter("keepZeroEnergyTracks", removeUnwantedTracksDefinition, "false")); RESTInfo << "TRestGeant4Metadata: Setting 'fRemoveUnwantedTracks' to " << fRemoveUnwantedTracks << " with 'keepZeroEnergyTracks' option set to " << fRemoveUnwantedTracksKeepZeroEnergyTracks << RESTendl; @@ -1284,7 +1326,7 @@ void TRestGeant4Metadata::ReadDetector() { defaultStep = 0; } - TiXmlElement* volumeDefinition = GetElement("volume", detectorDefinition); + TiXmlElement *volumeDefinition = GetElement("volume", detectorDefinition); while (volumeDefinition != nullptr) { string name = GetFieldValue("name", volumeDefinition); if (name.empty() || name == "Not defined") { @@ -1294,25 +1336,25 @@ void TRestGeant4Metadata::ReadDetector() { vector physicalVolumes; if (!fGeant4GeometryInfo.IsValidGdmlName(name)) { if (fGeant4GeometryInfo.IsValidLogicalVolume(name)) { - for (const auto& physical : fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(name)) { + for (const auto &physical: fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(name)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } // does not match a explicit (gdml) physical name or a logical name, perhaps its a regular exp if (physicalVolumes.empty()) { - for (const auto& physical : - fGeant4GeometryInfo.GetAllPhysicalVolumesMatchingExpression(name)) { + for (const auto &physical: + fGeant4GeometryInfo.GetAllPhysicalVolumesMatchingExpression(name)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } if (physicalVolumes.empty()) { - for (const auto& logical : fGeant4GeometryInfo.GetAllLogicalVolumesMatchingExpression(name)) { - for (const auto& physical : - fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(logical)) { + for (const auto &logical: fGeant4GeometryInfo.GetAllLogicalVolumesMatchingExpression(name)) { + for (const auto &physical: + fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(logical)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } } @@ -1322,9 +1364,9 @@ void TRestGeant4Metadata::ReadDetector() { if (physicalVolumes.empty()) { RESTError - << "volume '" << name - << "' is not defined in the geometry. Could not match to a physical, logical volume or regex" - << RESTendl; + << "volume '" << name + << "' is not defined in the geometry. Could not match to a physical, logical volume or regex" + << RESTendl; exit(1); } @@ -1355,7 +1397,7 @@ void TRestGeant4Metadata::ReadDetector() { maxStep = defaultStep; } - for (const auto& physical : physicalVolumes) { + for (const auto &physical: physicalVolumes) { RESTInfo << "Adding " << (isSensitive ? "sensitive" : "active") << " volume from RML: '" << physical << (chance != 1 ? " with change: " + to_string(chance) : " ") << RESTendl; SetActiveVolume(physical, chance, maxStep); @@ -1402,7 +1444,7 @@ void TRestGeant4Metadata::ReadDetector() { // If the user did not add explicitly any volume to the storage section we understand // the user wants to register all the volumes if (fActivateAllVolumes) { - for (const auto& name : fGeant4GeometryInfo.GetAllPhysicalVolumes()) { + for (const auto &name: fGeant4GeometryInfo.GetAllPhysicalVolumes()) { if (!IsActiveVolume(name)) { SetActiveVolume(name, 1, defaultStep); RESTInfo << "Automatically adding active volume: '" << name << "' with chance: " << 1 @@ -1452,7 +1494,7 @@ void TRestGeant4Metadata::PrintMetadata() { RESTMetadata << "Energy range (keV): (" << GetMinimumEnergyStored() << ", " << GetMaximumEnergyStored() << ")" << RESTendl; RESTMetadata << "Number of sensitive volumes: " << GetNumberOfSensitiveVolumes() << RESTendl; - for (const auto& sensitiveVolume : fSensitiveVolumes) { + for (const auto &sensitiveVolume: fSensitiveVolumes) { RESTMetadata << "Sensitive volume: " << sensitiveVolume << RESTendl; } RESTMetadata << "Number of active volumes: " << GetNumberOfActiveVolumes() << RESTendl; @@ -1487,7 +1529,7 @@ void TRestGeant4Metadata::PrintMetadata() { /// \brief Returns the id of an active volume giving as parameter its name. Int_t TRestGeant4Metadata::GetActiveVolumeID(TString name) { Int_t id; - for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { + for (id = 0; id < (Int_t) fActiveVolumes.size(); id++) { if (fActiveVolumes[id] == name) return id; } return -1; @@ -1507,7 +1549,7 @@ Int_t TRestGeant4Metadata::GetActiveVolumeID(TString name) { /// The aim of this parameter is to define control volumes. Usually the volume /// of interest will be always registered (chance=1). /// -void TRestGeant4Metadata::SetActiveVolume(const TString& name, Double_t chance, Double_t maxStep) { +void TRestGeant4Metadata::SetActiveVolume(const TString &name, Double_t chance, Double_t maxStep) { for (size_t i = 0; i < fActiveVolumes.size(); i++) { const auto activeVolumeName = fActiveVolumes[i]; if (name == activeVolumeName) { @@ -1526,7 +1568,7 @@ void TRestGeant4Metadata::SetActiveVolume(const TString& name, Double_t chance, /// \brief Returns true if the volume named *volName* has been registered for /// data storage. /// -Bool_t TRestGeant4Metadata::isVolumeStored(const TString& volume) const { +Bool_t TRestGeant4Metadata::isVolumeStored(const TString &volume) const { for (unsigned int n = 0; n < GetNumberOfActiveVolumes(); n++) if (GetActiveVolumeName(n) == volume) return true; @@ -1538,7 +1580,7 @@ Bool_t TRestGeant4Metadata::isVolumeStored(const TString& volume) const { /// Double_t TRestGeant4Metadata::GetStorageChance(TString volume) { Int_t id; - for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { + for (id = 0; id < (Int_t) fActiveVolumes.size(); id++) { if (fActiveVolumes[id] == volume) return fChance[id]; } RESTWarning << "TRestGeant4Metadata::GetStorageChance. Volume " << volume << " not found" << RESTendl; @@ -1549,8 +1591,8 @@ Double_t TRestGeant4Metadata::GetStorageChance(TString volume) { /////////////////////////////////////////////// /// \brief Returns the maximum step at a particular active volume /// -Double_t TRestGeant4Metadata::GetMaxStepSize(const TString& volume) { - for (Int_t i = 0; i < (Int_t)fActiveVolumes.size(); i++) { +Double_t TRestGeant4Metadata::GetMaxStepSize(const TString &volume) { + for (Int_t i = 0; i < (Int_t) fActiveVolumes.size(); i++) { if (volume.EqualTo(fActiveVolumes[i], TString::kIgnoreCase)) { return fMaxStepSize[i]; } From a786f9c50c1c5a1f95d292becd47c16eff7c5d73 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 22 Feb 2023 12:26:31 +0000 Subject: [PATCH 04/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- inc/TRestGeant4BiasingInfo.h | 11 +-- inc/TRestGeant4GeometryInfo.h | 44 ++++----- inc/TRestGeant4Metadata.h | 48 +++++----- src/TRestGeant4Metadata.cxx | 162 +++++++++++++++++----------------- 4 files changed, 132 insertions(+), 133 deletions(-) diff --git a/inc/TRestGeant4BiasingInfo.h b/inc/TRestGeant4BiasingInfo.h index 7154a29..e0120cb 100644 --- a/inc/TRestGeant4BiasingInfo.h +++ b/inc/TRestGeant4BiasingInfo.h @@ -3,20 +3,21 @@ #define REST_TRESTGEANT4BIASINGINFO_H #include + #include #include class TRestGeant4BiasingInfo { -ClassDef(TRestGeant4BiasingInfo, 1); + ClassDef(TRestGeant4BiasingInfo, 1); -private: + private: bool fEnabled = false; unsigned int fSplittingFactor = 1; bool fBiasOncePerTrack = true; std::set fBiasingVolumes; TVector3 fBiasingCenter; -public: + public: inline TRestGeant4BiasingInfo() = default; inline ~TRestGeant4BiasingInfo() = default; @@ -33,13 +34,13 @@ ClassDef(TRestGeant4BiasingInfo, 1); inline bool GetBiasOncePerTrack() const { return fBiasOncePerTrack; } - inline void AddBiasingVolume(const std::string &volumeName) { fBiasingVolumes.insert(volumeName); } + inline void AddBiasingVolume(const std::string& volumeName) { fBiasingVolumes.insert(volumeName); } inline void ClearBiasingVolumes() { fBiasingVolumes.clear(); } inline std::set GetBiasingVolumes() const { return fBiasingVolumes; } - inline void SetBiasingCenter(const TVector3 &biasingCenter) { fBiasingCenter = biasingCenter; } + inline void SetBiasingCenter(const TVector3& biasingCenter) { fBiasingCenter = biasingCenter; } inline TVector3 GetBiasingCenter() const { return fBiasingCenter; } }; diff --git a/inc/TRestGeant4GeometryInfo.h b/inc/TRestGeant4GeometryInfo.h index 163a563..9e381cb 100644 --- a/inc/TRestGeant4GeometryInfo.h +++ b/inc/TRestGeant4GeometryInfo.h @@ -12,29 +12,29 @@ class G4VPhysicalVolume; class TRestGeant4GeometryInfo { -ClassDef(TRestGeant4GeometryInfo, 3); + ClassDef(TRestGeant4GeometryInfo, 3); -private: + private: bool fIsAssembly = false; std::map fVolumeNameMap = {}; std::map fVolumeNameReverseMap = {}; - void PopulateFromGeant4World(const G4VPhysicalVolume *); + void PopulateFromGeant4World(const G4VPhysicalVolume*); - inline void InitializeOnDetectorConstruction(const TString &gdmlFilename, - const G4VPhysicalVolume *world) { + inline void InitializeOnDetectorConstruction(const TString& gdmlFilename, + const G4VPhysicalVolume* world) { PopulateFromGdml(gdmlFilename); PopulateFromGeant4World(world); } -public: + public: // Insertion order is important for GDML containers. These containers are filled from GDML only not Geant4 std::vector fGdmlNewPhysicalNames; std::vector fGdmlLogicalNames; std::map - fGeant4PhysicalNameToNewPhysicalNameMap; /* + fGeant4PhysicalNameToNewPhysicalNameMap; /* * only makes sense when using assembly */ @@ -44,14 +44,14 @@ ClassDef(TRestGeant4GeometryInfo, 3); std::map fLogicalToMaterialMap; std::map fPhysicalToPositionInWorldMap; -public: + public: inline TRestGeant4GeometryInfo() = default; - void PopulateFromGdml(const TString &); + void PopulateFromGdml(const TString&); - TString GetAlternativeNameFromGeant4PhysicalName(const TString &) const; + TString GetAlternativeNameFromGeant4PhysicalName(const TString&) const; - TString GetGeant4PhysicalNameFromAlternativeName(const TString &) const; + TString GetGeant4PhysicalNameFromAlternativeName(const TString&) const; std::vector GetAllLogicalVolumes() const; @@ -59,12 +59,12 @@ ClassDef(TRestGeant4GeometryInfo, 3); std::vector GetAllAlternativePhysicalVolumes() const; - std::vector GetAllLogicalVolumesMatchingExpression(const TString &) const; + std::vector GetAllLogicalVolumesMatchingExpression(const TString&) const; - std::vector GetAllPhysicalVolumesMatchingExpression(const TString &) const; + std::vector GetAllPhysicalVolumesMatchingExpression(const TString&) const; - inline bool IsValidGdmlName(const TString &volume) const { - for (const auto &name: fGdmlNewPhysicalNames) { + inline bool IsValidGdmlName(const TString& volume) const { + for (const auto& name : fGdmlNewPhysicalNames) { if (name == volume) { return true; } @@ -72,39 +72,39 @@ ClassDef(TRestGeant4GeometryInfo, 3); return false; } - inline bool IsValidPhysicalVolume(const TString &volume) const { + inline bool IsValidPhysicalVolume(const TString& volume) const { return fPhysicalToLogicalVolumeMap.count(volume) > 0; } - inline bool IsValidLogicalVolume(const TString &volume) const { + inline bool IsValidLogicalVolume(const TString& volume) const { return fLogicalToPhysicalMap.count(volume) > 0; } - inline std::vector GetAllPhysicalVolumesFromLogical(const TString &logicalVolume) const { + inline std::vector GetAllPhysicalVolumesFromLogical(const TString& logicalVolume) const { if (IsValidLogicalVolume(logicalVolume)) { return fLogicalToPhysicalMap.at(logicalVolume); } return {}; } - inline TString GetLogicalVolumeFromPhysical(const TString &physicalVolume) const { + inline TString GetLogicalVolumeFromPhysical(const TString& physicalVolume) const { if (IsValidPhysicalVolume(physicalVolume)) { return fPhysicalToLogicalVolumeMap.at(physicalVolume); } return {}; } - inline TVector3 GetPosition(const TString &volume) const { + inline TVector3 GetPosition(const TString& volume) const { return fPhysicalToPositionInWorldMap.at(volume); } inline bool IsAssembly() const { return fIsAssembly; } - void InsertVolumeName(Int_t id, const TString &volumeName); + void InsertVolumeName(Int_t id, const TString& volumeName); TString GetVolumeFromID(Int_t id) const; - Int_t GetIDFromVolume(const TString &volumeName) const; + Int_t GetIDFromVolume(const TString& volumeName) const; void Print() const; diff --git a/inc/TRestGeant4Metadata.h b/inc/TRestGeant4Metadata.h index 81ebd3a..59e2f72 100644 --- a/inc/TRestGeant4Metadata.h +++ b/inc/TRestGeant4Metadata.h @@ -46,14 +46,14 @@ /// The main class to store the *Geant4* simulation conditions that will be used by *restG4*. class TRestGeant4Metadata : public TRestMetadata { -private: + private: void Initialize() override; void InitFromConfigFile() override; void ReadGenerator(); - void ReadParticleSource(TRestGeant4ParticleSource *src, TiXmlElement *sourceDefinition); + void ReadParticleSource(TRestGeant4ParticleSource* src, TiXmlElement* sourceDefinition); void ReadDetector(); @@ -102,7 +102,7 @@ class TRestGeant4Metadata : public TRestMetadata { std::vector fMaxStepSize; /// \brief It the defines the primary source properties, particle type, momentum, energy, etc. - std::vector fParticleSource; //-> + std::vector fParticleSource; //-> /// \brief The number of biasing volumes used in the simulation. If zero, no biasing technique is used. Int_t fNBiasingVolumes = 0; @@ -169,23 +169,23 @@ class TRestGeant4Metadata : public TRestMetadata { /// The world magnetic field TVector3 fMagneticField = TVector3(0, 0, 0); -public: + public: std::set fActiveVolumesSet = {}; //! // Used for faster lookup /// \brief Returns the random seed that was used to generate the corresponding geant4 dataset. inline Long_t GetSeed() const { return fSeed; } /// \brief Returns an immutable reference to the geometry info - inline const TRestGeant4GeometryInfo &GetGeant4GeometryInfo() const { return fGeant4GeometryInfo; } + inline const TRestGeant4GeometryInfo& GetGeant4GeometryInfo() const { return fGeant4GeometryInfo; } /// \brief Returns an immutable reference to the physics info - inline const TRestGeant4PhysicsInfo &GetGeant4PhysicsInfo() const { return fGeant4PhysicsInfo; } + inline const TRestGeant4PhysicsInfo& GetGeant4PhysicsInfo() const { return fGeant4PhysicsInfo; } /// \brief Returns an immutable reference to the biasing info - inline const TRestGeant4BiasingInfo &GetGeant4BiasingInfo() const { return fGeant4BiasingInfo; } + inline const TRestGeant4BiasingInfo& GetGeant4BiasingInfo() const { return fGeant4BiasingInfo; } /// \brief Returns an immutable reference to the primary generator info - inline const TRestGeant4PrimaryGeneratorInfo &GetGeant4PrimaryGeneratorInfo() const { + inline const TRestGeant4PrimaryGeneratorInfo& GetGeant4PrimaryGeneratorInfo() const { return fGeant4PrimaryGeneratorInfo; } @@ -235,7 +235,7 @@ class TRestGeant4Metadata : public TRestMetadata { inline void SetSaveAllEvents(const Bool_t value) { fSaveAllEvents = value; } /// Sets the value of the Geant4 version - inline void SetGeant4Version(const TString &versionString) { fGeant4Version = versionString; } + inline void SetGeant4Version(const TString& versionString) { fGeant4Version = versionString; } /// Enables/disables the full chain decay generation. inline void SetFullChain(Bool_t fullChain) { fFullChain = fullChain; } @@ -265,13 +265,13 @@ class TRestGeant4Metadata : public TRestMetadata { inline Int_t GetNumberOfSources() const { return fParticleSource.size(); } /// Returns the name of the particle source with index n (Geant4 based names). - inline TRestGeant4ParticleSource *GetParticleSource(size_t n = 0) const { return fParticleSource[n]; } + inline TRestGeant4ParticleSource* GetParticleSource(size_t n = 0) const { return fParticleSource[n]; } /// Remove all the particle sources. void RemoveParticleSources(); /// Adds a new particle source. - void AddParticleSource(TRestGeant4ParticleSource *src); + void AddParticleSource(TRestGeant4ParticleSource* src); /////////////////////////////////////////////////////////// // Direct access to biasing volumes definition @@ -291,7 +291,7 @@ class TRestGeant4Metadata : public TRestMetadata { inline size_t GetNumberOfSensitiveVolumes() const { return fSensitiveVolumes.size(); } - inline const std::vector &GetSensitiveVolumes() const { return fSensitiveVolumes; } + inline const std::vector& GetSensitiveVolumes() const { return fSensitiveVolumes; } /// Sets the name of the sensitive volume inline void SetNumberOfEvents(Int_t n) { fNEvents = n; } @@ -301,8 +301,8 @@ class TRestGeant4Metadata : public TRestMetadata { inline void SetSimulationMaxTimeSeconds(Int_t seconds) { fSimulationMaxTimeSeconds = seconds; } /// Sets the name of the sensitive volume - inline void InsertSensitiveVolume(const TString &volume) { - for (const auto &sensitiveVolume: fSensitiveVolumes) { + inline void InsertSensitiveVolume(const TString& volume) { + for (const auto& sensitiveVolume : fSensitiveVolumes) { // Do not add duplicate volumes if (volume == sensitiveVolume) { return; @@ -319,7 +319,7 @@ class TRestGeant4Metadata : public TRestMetadata { /// name. Double_t GetStorageChance(TString volume); - Double_t GetMaxStepSize(const TString &volume); + Double_t GetMaxStepSize(const TString& volume); /// Returns the minimum event energy required for an event to be stored. inline Double_t GetMinimumEnergyStored() const { return fEnergyRangeStored.X(); } @@ -331,19 +331,19 @@ class TRestGeant4Metadata : public TRestMetadata { /// selected for data storage. inline unsigned int GetNumberOfActiveVolumes() const { return fActiveVolumes.size(); } - inline bool IsActiveVolume(const char *volumeName) const { + inline bool IsActiveVolume(const char* volumeName) const { return fActiveVolumesSet.count(volumeName) > 0; } //! - inline bool IsKeepTracksVolume(const char *volumeName) const { + inline bool IsKeepTracksVolume(const char* volumeName) const { return fRemoveUnwantedTracksVolumesToKeep.count(volumeName) > 0; } - inline bool IsKillVolume(const char *volumeName) const { return fKillVolumes.count(volumeName) > 0; } + inline bool IsKillVolume(const char* volumeName) const { return fKillVolumes.count(volumeName) > 0; } inline std::vector GetKillVolumes() const { std::vector result; - for (const auto &volume: fKillVolumes) { + for (const auto& volume : fKillVolumes) { result.emplace_back(volume); } return result; @@ -351,7 +351,7 @@ class TRestGeant4Metadata : public TRestMetadata { inline std::vector GetRemoveUnwantedTracksVolumesToKeep() const { std::vector result; - for (const auto &volume: fRemoveUnwantedTracksVolumesToKeep) { + for (const auto& volume : fRemoveUnwantedTracksVolumesToKeep) { result.emplace_back(volume); } return result; @@ -379,19 +379,19 @@ class TRestGeant4Metadata : public TRestMetadata { Int_t GetActiveVolumeID(TString name); - Bool_t isVolumeStored(const TString &volume) const; + Bool_t isVolumeStored(const TString& volume) const; - void SetActiveVolume(const TString &name, Double_t chance, Double_t maxStep = 0); + void SetActiveVolume(const TString& name, Double_t chance, Double_t maxStep = 0); void PrintMetadata() override; TRestGeant4Metadata(); - TRestGeant4Metadata(const char *configFilename, const std::string &name = ""); + TRestGeant4Metadata(const char* configFilename, const std::string& name = ""); ~TRestGeant4Metadata(); -ClassDefOverride(TRestGeant4Metadata, 14); + ClassDefOverride(TRestGeant4Metadata, 14); // Allow modification of otherwise inaccessible / immutable members that shouldn't be modified by the user friend class SteppingAction; diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index 1d19188..ce1a61c 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -758,8 +758,8 @@ TRestGeant4Metadata::TRestGeant4Metadata() : TRestMetadata() { Initialize(); } /// \param name The name of the specific metadata. It will be used to find the /// corresponding TRestGeant4Metadata section inside the RML. /// -TRestGeant4Metadata::TRestGeant4Metadata(const char *configFilename, const string &name) - : TRestMetadata(configFilename) { +TRestGeant4Metadata::TRestGeant4Metadata(const char* configFilename, const string& name) + : TRestMetadata(configFilename) { Initialize(); LoadConfigFromFile(fConfigFileName, name); @@ -808,17 +808,17 @@ void TRestGeant4Metadata::InitFromConfigFile() { if (ToUpper(seedString) == "RANDOM" || ToUpper(seedString) == "RAND" || ToUpper(seedString) == "AUTO" || seedString == "0") { auto dd = new double(); - fSeed = (uintptr_t) dd + (uintptr_t) this; + fSeed = (uintptr_t)dd + (uintptr_t)this; delete dd; } else { - fSeed = (Long_t) StringToInteger(seedString); + fSeed = (Long_t)StringToInteger(seedString); } gRandom->SetSeed(fSeed); // if "gdmlFile" is purely a file (without any path) and "geometryPath" is // defined, we recombine them together - if ((((string) fGdmlFilename).find_first_not_of("./~") == 0 || - ((string) fGdmlFilename).find("/") == string::npos) && + if ((((string)fGdmlFilename).find_first_not_of("./~") == 0 || + ((string)fGdmlFilename).find("/") == string::npos) && fGeometryPath != "") { if (fGeometryPath[fGeometryPath.Length() - 1] == '/') { fGdmlFilename = fGeometryPath + GetParameter("gdmlFile"); @@ -838,7 +838,7 @@ void TRestGeant4Metadata::InitFromConfigFile() { const auto fNRequestedEntriesString = GetParameter("nRequestedEntries"); fNRequestedEntries = - fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); + fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); fSaveAllEvents = ToUpper(GetParameter("saveAllEvents", "false")) == "TRUE" || ToUpper(GetParameter("saveAllEvents", "off")) == "ON"; @@ -905,8 +905,8 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorType().Data()) != TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypes::COSMIC) { RESTError - << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" - << RESTendl; + << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" + << RESTendl; exit(1); } const auto source = GetParticleSource(); @@ -929,10 +929,10 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { const auto energyRange = source->GetEnergyDistributionRange(); const auto angularRange = source->GetAngularDistributionRange(); - auto function = (TF2 *) source->GetEnergyAndAngularDistributionFunction()->Clone(); + auto function = (TF2*)source->GetEnergyAndAngularDistributionFunction()->Clone(); // counts per second per cm2 (distribution is already integrated over uniform phi) const auto countsPerSecondPerCm2 = - function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); + function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); return countsPerSecondPerCm2; } @@ -989,31 +989,29 @@ void TRestGeant4Metadata::ReadBiasing() { */ void TRestGeant4Metadata::ReadBiasing() { - TiXmlElement *biasingDefinition = GetElement("biasing"); + TiXmlElement* biasingDefinition = GetElement("biasing"); if (biasingDefinition == nullptr) { fGeant4BiasingInfo.SetEnabled(false); return; } fGeant4BiasingInfo.SetEnabled(true); - const int splittingFactor = - StringToInteger(GetParameter("splittingFactor", biasingDefinition, "1")); + const int splittingFactor = StringToInteger(GetParameter("splittingFactor", biasingDefinition, "1")); if (splittingFactor <= 1) { - RESTError << "Parameter 'splittingFactor' in biasing section must be set to an integer > 1" << RESTendl; + RESTError << "Parameter 'splittingFactor' in biasing section must be set to an integer > 1" + << RESTendl; exit(1); } fGeant4BiasingInfo.SetSplittingFactor(splittingFactor); - const TVector3 center = - StringTo3DVector(GetParameter("center", biasingDefinition, "(0,0,0)")); - + const TVector3 center = StringTo3DVector(GetParameter("center", biasingDefinition, "(0,0,0)")); fGeant4BiasingInfo.SetBiasingCenter(center); std::set biasingVolumes; - TiXmlElement *volumeDefinition = GetElement("volume", biasingDefinition); + TiXmlElement* volumeDefinition = GetElement("volume", biasingDefinition); while (volumeDefinition != nullptr) { string name = GetFieldValue("name", volumeDefinition); if (name.empty() || name == "Not defined") { @@ -1025,7 +1023,7 @@ void TRestGeant4Metadata::ReadBiasing() { volumeDefinition = GetNextElement(volumeDefinition); } - for (const auto &volume: biasingVolumes) { + for (const auto& volume : biasingVolumes) { fGeant4BiasingInfo.AddBiasingVolume(volume); } } @@ -1064,35 +1062,35 @@ void TRestGeant4Metadata::ReadGenerator() { // center of the volume (i.e. gasTarget) but if i.e rotation or side are // defined and not relevant we should set it to -1 - TiXmlElement *generatorDefinition = GetElement("generator"); + TiXmlElement* generatorDefinition = GetElement("generator"); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorType = - SpatialGeneratorTypesToString(StringToSpatialGeneratorTypes(GetParameter( - "type", generatorDefinition, SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME)))); + SpatialGeneratorTypesToString(StringToSpatialGeneratorTypes(GetParameter( + "type", generatorDefinition, SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME)))); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorShape = - SpatialGeneratorShapesToString(StringToSpatialGeneratorShapes(GetParameter( - "shape", generatorDefinition, SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX)))); + SpatialGeneratorShapesToString(StringToSpatialGeneratorShapes(GetParameter( + "shape", generatorDefinition, SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX)))); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorFrom = GetParameter("from", generatorDefinition); if (fGeant4PrimaryGeneratorInfo.fSpatialGeneratorFrom != PARAMETER_NOT_FOUND_STR) { fGeant4PrimaryGeneratorInfo.fSpatialGeneratorShape = - SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML); + SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML); } fGeant4PrimaryGeneratorInfo.fSpatialGeneratorSize = - Get3DVectorParameterWithUnits("size", generatorDefinition, {0, 0, 0}); + Get3DVectorParameterWithUnits("size", generatorDefinition, {0, 0, 0}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorPosition = - Get3DVectorParameterWithUnits("position", generatorDefinition, {0, 0, 0}); + Get3DVectorParameterWithUnits("position", generatorDefinition, {0, 0, 0}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorRotationAxis = - Get3DVectorParameterWithUnits("rotationAxis", generatorDefinition, {0, 0, 1}); + Get3DVectorParameterWithUnits("rotationAxis", generatorDefinition, {0, 0, 1}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorRotationValue = - GetDblParameterWithUnits("rotationAngle", generatorDefinition, 0); + GetDblParameterWithUnits("rotationAngle", generatorDefinition, 0); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorSpatialDensityFunction = - GetParameter("densityFunc", generatorDefinition, "1"); + GetParameter("densityFunc", generatorDefinition, "1"); - TiXmlElement *sourceDefinition = GetElement("source", generatorDefinition); + TiXmlElement* sourceDefinition = GetElement("source", generatorDefinition); while (sourceDefinition) { string use = GetParameter("use", sourceDefinition, ""); - TRestGeant4ParticleSource *source = TRestGeant4ParticleSource::instantiate(use); + TRestGeant4ParticleSource* source = TRestGeant4ParticleSource::instantiate(use); ReadParticleSource(source, sourceDefinition); AddParticleSource(source); @@ -1109,8 +1107,8 @@ void TRestGeant4Metadata::ReadGenerator() { /////////////////////////////////////////////// /// \brief It reads the SetParticleName(GetParameter("particle", sourceDefinition)); source->SetExcitationLevel(StringToDouble(GetParameter("excitedLevel", sourceDefinition))); @@ -1123,12 +1121,12 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, } // Angular distribution parameters - TiXmlElement *angularDefinition = GetElement("angular", sourceDefinition); + TiXmlElement* angularDefinition = GetElement("angular", sourceDefinition); if (angularDefinition == nullptr) { angularDefinition = GetElement("angularDist", sourceDefinition); // old name } source->SetAngularDistributionType(GetParameter( - "type", angularDefinition, AngularDistributionTypesToString(AngularDistributionTypes::FLUX))); + "type", angularDefinition, AngularDistributionTypesToString(AngularDistributionTypes::FLUX))); if (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::TH1D) { source->SetAngularDistributionFilename(SearchFile(GetParameter("file", angularDefinition))); @@ -1139,7 +1137,7 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, source->SetAngularDistributionNameInFile(name); } source->SetAngularDistributionRange( - Get2DVectorParameterWithUnits("range", angularDefinition, {0, TMath::Pi()})); + Get2DVectorParameterWithUnits("range", angularDefinition, {0, TMath::Pi()})); if (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::FORMULA) { source->SetAngularDistributionFormula(GetParameter("name", angularDefinition)); @@ -1147,11 +1145,11 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, const auto function = source->GetAngularDistributionFunction(); if (source->GetAngularDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetAngularDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); } if (source->GetAngularDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetAngularDistributionRange( - {source->GetAngularDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetAngularDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } } if ((StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == @@ -1159,24 +1157,24 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::FORMULA2)) { source->SetAngularDistributionFormulaNPoints(static_cast(GetDblParameterWithUnits( - "nPoints", angularDefinition, source->GetAngularDistributionFormulaNPoints()))); + "nPoints", angularDefinition, source->GetAngularDistributionFormulaNPoints()))); } if (GetNumberOfSources() == 0 && StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == - AngularDistributionTypes::BACK_TO_BACK) { + AngularDistributionTypes::BACK_TO_BACK) { cout << "WARNING: First source cannot be backtoback. Setting it to isotropic" << endl; source->SetAngularDistributionType( - AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC)); + AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC)); } source->SetDirection(StringTo3DVector(GetParameter("direction", angularDefinition, "(1,0,0)"))); // Energy distribution parameters - TiXmlElement *energyDefinition = GetElement("energy", sourceDefinition); + TiXmlElement* energyDefinition = GetElement("energy", sourceDefinition); if (energyDefinition == nullptr) { energyDefinition = GetElement("energyDist", sourceDefinition); // old name } source->SetEnergyDistributionType(GetParameter( - "type", energyDefinition, EnergyDistributionTypesToString(EnergyDistributionTypes::MONO))); + "type", energyDefinition, EnergyDistributionTypesToString(EnergyDistributionTypes::MONO))); if (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == EnergyDistributionTypes::TH1D) { source->SetEnergyDistributionFilename(SearchFile(GetParameter("file", energyDefinition))); @@ -1201,11 +1199,11 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, const auto function = source->GetEnergyDistributionFunction(); if (source->GetEnergyDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetEnergyDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); } if (source->GetEnergyDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetEnergyDistributionRange( - {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } } if ((StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == @@ -1213,12 +1211,12 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == EnergyDistributionTypes::FORMULA2)) { source->SetEnergyDistributionFormulaNPoints(static_cast(GetDblParameterWithUnits( - "nPoints", energyDefinition, source->GetEnergyDistributionFormulaNPoints()))); + "nPoints", energyDefinition, source->GetEnergyDistributionFormulaNPoints()))); } if (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == - EnergyDistributionTypes::FORMULA2 && + EnergyDistributionTypes::FORMULA2 && StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == - AngularDistributionTypes::FORMULA2) { + AngularDistributionTypes::FORMULA2) { const auto empty = TString(""); auto energyDistName = GetParameter("name", energyDefinition, empty); auto angularDistName = GetParameter("name", energyDefinition, empty); @@ -1251,21 +1249,21 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, // Set energy range if (source->GetEnergyDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetEnergyDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); } if (source->GetEnergyDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetEnergyDistributionRange( - {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } // Set angular range if (source->GetAngularDistributionRangeMin() < function->GetYaxis()->GetXmin()) { source->SetAngularDistributionRange( - {function->GetYaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); + {function->GetYaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); } if (source->GetAngularDistributionRangeMax() > function->GetYaxis()->GetXmax()) { source->SetAngularDistributionRange( - {source->GetAngularDistributionRangeMin(), function->GetYaxis()->GetXmax()}); + {source->GetAngularDistributionRangeMin(), function->GetYaxis()->GetXmax()}); } } // allow custom configuration from the class @@ -1274,13 +1272,13 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, } void TRestGeant4Metadata::RemoveParticleSources() { - for (auto source: fParticleSource) { + for (auto source : fParticleSource) { delete source; } fParticleSource.clear(); } -void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource *src) { +void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource* src) { fParticleSource.push_back(src); } @@ -1300,22 +1298,22 @@ void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource *src) { /// void TRestGeant4Metadata::ReadDetector() { RESTInfo << "TRestGeant4Metadata: Processing detector section" << RESTendl; - TiXmlElement *detectorDefinition = GetElement("detector"); + TiXmlElement* detectorDefinition = GetElement("detector"); if (detectorDefinition == nullptr) { RESTError << "Detector section () is not present in metadata!" << RESTendl; exit(1); } const bool activateAllVolumes = - StringToBool(GetParameter("activateAllVolumes", detectorDefinition, "true")); + StringToBool(GetParameter("activateAllVolumes", detectorDefinition, "true")); RESTInfo << "TRestGeant4Metadata: Setting 'fActivateAllVolumes' to " << fActivateAllVolumes << RESTendl; fActivateAllVolumes = activateAllVolumes; - TiXmlElement *removeUnwantedTracksDefinition = GetElement("removeUnwantedTracks", detectorDefinition); + TiXmlElement* removeUnwantedTracksDefinition = GetElement("removeUnwantedTracks", detectorDefinition); if (removeUnwantedTracksDefinition != nullptr) { fRemoveUnwantedTracks = StringToBool(GetParameter("enabled", removeUnwantedTracksDefinition, "true")); fRemoveUnwantedTracksKeepZeroEnergyTracks = - StringToBool(GetParameter("keepZeroEnergyTracks", removeUnwantedTracksDefinition, "false")); + StringToBool(GetParameter("keepZeroEnergyTracks", removeUnwantedTracksDefinition, "false")); RESTInfo << "TRestGeant4Metadata: Setting 'fRemoveUnwantedTracks' to " << fRemoveUnwantedTracks << " with 'keepZeroEnergyTracks' option set to " << fRemoveUnwantedTracksKeepZeroEnergyTracks << RESTendl; @@ -1326,7 +1324,7 @@ void TRestGeant4Metadata::ReadDetector() { defaultStep = 0; } - TiXmlElement *volumeDefinition = GetElement("volume", detectorDefinition); + TiXmlElement* volumeDefinition = GetElement("volume", detectorDefinition); while (volumeDefinition != nullptr) { string name = GetFieldValue("name", volumeDefinition); if (name.empty() || name == "Not defined") { @@ -1336,25 +1334,25 @@ void TRestGeant4Metadata::ReadDetector() { vector physicalVolumes; if (!fGeant4GeometryInfo.IsValidGdmlName(name)) { if (fGeant4GeometryInfo.IsValidLogicalVolume(name)) { - for (const auto &physical: fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(name)) { + for (const auto& physical : fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(name)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } // does not match a explicit (gdml) physical name or a logical name, perhaps its a regular exp if (physicalVolumes.empty()) { - for (const auto &physical: - fGeant4GeometryInfo.GetAllPhysicalVolumesMatchingExpression(name)) { + for (const auto& physical : + fGeant4GeometryInfo.GetAllPhysicalVolumesMatchingExpression(name)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } if (physicalVolumes.empty()) { - for (const auto &logical: fGeant4GeometryInfo.GetAllLogicalVolumesMatchingExpression(name)) { - for (const auto &physical: - fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(logical)) { + for (const auto& logical : fGeant4GeometryInfo.GetAllLogicalVolumesMatchingExpression(name)) { + for (const auto& physical : + fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(logical)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } } @@ -1364,9 +1362,9 @@ void TRestGeant4Metadata::ReadDetector() { if (physicalVolumes.empty()) { RESTError - << "volume '" << name - << "' is not defined in the geometry. Could not match to a physical, logical volume or regex" - << RESTendl; + << "volume '" << name + << "' is not defined in the geometry. Could not match to a physical, logical volume or regex" + << RESTendl; exit(1); } @@ -1397,7 +1395,7 @@ void TRestGeant4Metadata::ReadDetector() { maxStep = defaultStep; } - for (const auto &physical: physicalVolumes) { + for (const auto& physical : physicalVolumes) { RESTInfo << "Adding " << (isSensitive ? "sensitive" : "active") << " volume from RML: '" << physical << (chance != 1 ? " with change: " + to_string(chance) : " ") << RESTendl; SetActiveVolume(physical, chance, maxStep); @@ -1444,7 +1442,7 @@ void TRestGeant4Metadata::ReadDetector() { // If the user did not add explicitly any volume to the storage section we understand // the user wants to register all the volumes if (fActivateAllVolumes) { - for (const auto &name: fGeant4GeometryInfo.GetAllPhysicalVolumes()) { + for (const auto& name : fGeant4GeometryInfo.GetAllPhysicalVolumes()) { if (!IsActiveVolume(name)) { SetActiveVolume(name, 1, defaultStep); RESTInfo << "Automatically adding active volume: '" << name << "' with chance: " << 1 @@ -1494,7 +1492,7 @@ void TRestGeant4Metadata::PrintMetadata() { RESTMetadata << "Energy range (keV): (" << GetMinimumEnergyStored() << ", " << GetMaximumEnergyStored() << ")" << RESTendl; RESTMetadata << "Number of sensitive volumes: " << GetNumberOfSensitiveVolumes() << RESTendl; - for (const auto &sensitiveVolume: fSensitiveVolumes) { + for (const auto& sensitiveVolume : fSensitiveVolumes) { RESTMetadata << "Sensitive volume: " << sensitiveVolume << RESTendl; } RESTMetadata << "Number of active volumes: " << GetNumberOfActiveVolumes() << RESTendl; @@ -1529,7 +1527,7 @@ void TRestGeant4Metadata::PrintMetadata() { /// \brief Returns the id of an active volume giving as parameter its name. Int_t TRestGeant4Metadata::GetActiveVolumeID(TString name) { Int_t id; - for (id = 0; id < (Int_t) fActiveVolumes.size(); id++) { + for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { if (fActiveVolumes[id] == name) return id; } return -1; @@ -1549,7 +1547,7 @@ Int_t TRestGeant4Metadata::GetActiveVolumeID(TString name) { /// The aim of this parameter is to define control volumes. Usually the volume /// of interest will be always registered (chance=1). /// -void TRestGeant4Metadata::SetActiveVolume(const TString &name, Double_t chance, Double_t maxStep) { +void TRestGeant4Metadata::SetActiveVolume(const TString& name, Double_t chance, Double_t maxStep) { for (size_t i = 0; i < fActiveVolumes.size(); i++) { const auto activeVolumeName = fActiveVolumes[i]; if (name == activeVolumeName) { @@ -1568,7 +1566,7 @@ void TRestGeant4Metadata::SetActiveVolume(const TString &name, Double_t chance, /// \brief Returns true if the volume named *volName* has been registered for /// data storage. /// -Bool_t TRestGeant4Metadata::isVolumeStored(const TString &volume) const { +Bool_t TRestGeant4Metadata::isVolumeStored(const TString& volume) const { for (unsigned int n = 0; n < GetNumberOfActiveVolumes(); n++) if (GetActiveVolumeName(n) == volume) return true; @@ -1580,7 +1578,7 @@ Bool_t TRestGeant4Metadata::isVolumeStored(const TString &volume) const { /// Double_t TRestGeant4Metadata::GetStorageChance(TString volume) { Int_t id; - for (id = 0; id < (Int_t) fActiveVolumes.size(); id++) { + for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { if (fActiveVolumes[id] == volume) return fChance[id]; } RESTWarning << "TRestGeant4Metadata::GetStorageChance. Volume " << volume << " not found" << RESTendl; @@ -1591,8 +1589,8 @@ Double_t TRestGeant4Metadata::GetStorageChance(TString volume) { /////////////////////////////////////////////// /// \brief Returns the maximum step at a particular active volume /// -Double_t TRestGeant4Metadata::GetMaxStepSize(const TString &volume) { - for (Int_t i = 0; i < (Int_t) fActiveVolumes.size(); i++) { +Double_t TRestGeant4Metadata::GetMaxStepSize(const TString& volume) { + for (Int_t i = 0; i < (Int_t)fActiveVolumes.size(); i++) { if (volume.EqualTo(fActiveVolumes[i], TString::kIgnoreCase)) { return fMaxStepSize[i]; } From cb92149226a7023abe6e95a0ea4d10dc1c5d0469 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Wed, 22 Feb 2023 18:53:14 +0100 Subject: [PATCH 05/14] attempt to fix pipeline failure --- src/TRestGeant4Metadata.cxx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index ce1a61c..268c7ad 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -1007,10 +1007,8 @@ void TRestGeant4Metadata::ReadBiasing() { fGeant4BiasingInfo.SetSplittingFactor(splittingFactor); const TVector3 center = StringTo3DVector(GetParameter("center", biasingDefinition, "(0,0,0)")); - fGeant4BiasingInfo.SetBiasingCenter(center); - std::set biasingVolumes; TiXmlElement* volumeDefinition = GetElement("volume", biasingDefinition); while (volumeDefinition != nullptr) { string name = GetFieldValue("name", volumeDefinition); @@ -1018,14 +1016,9 @@ void TRestGeant4Metadata::ReadBiasing() { RESTError << "volume inside biasing section defined without name" << RESTendl; exit(1); } - biasingVolumes.insert(name); - + fGeant4BiasingInfo.AddBiasingVolume(name); volumeDefinition = GetNextElement(volumeDefinition); } - - for (const auto& volume : biasingVolumes) { - fGeant4BiasingInfo.AddBiasingVolume(volume); - } } /////////////////////////////////////////////// From 624ec7f4094ad133b49180a37215c1f688681460 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Thu, 23 Feb 2023 12:56:47 +0100 Subject: [PATCH 06/14] fSplittingFactor set to int --- inc/TRestGeant4BiasingInfo.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/inc/TRestGeant4BiasingInfo.h b/inc/TRestGeant4BiasingInfo.h index e0120cb..80ee1fe 100644 --- a/inc/TRestGeant4BiasingInfo.h +++ b/inc/TRestGeant4BiasingInfo.h @@ -8,16 +8,16 @@ #include class TRestGeant4BiasingInfo { - ClassDef(TRestGeant4BiasingInfo, 1); +ClassDef(TRestGeant4BiasingInfo, 1); - private: +private: bool fEnabled = false; - unsigned int fSplittingFactor = 1; + int fSplittingFactor = 1; bool fBiasOncePerTrack = true; std::set fBiasingVolumes; TVector3 fBiasingCenter; - public: +public: inline TRestGeant4BiasingInfo() = default; inline ~TRestGeant4BiasingInfo() = default; @@ -28,19 +28,19 @@ class TRestGeant4BiasingInfo { inline void SetSplittingFactor(unsigned int splittingFactor) { fSplittingFactor = splittingFactor; } - inline unsigned int GetSplittingFactor() const { return fSplittingFactor; } + inline int GetSplittingFactor() const { return fSplittingFactor; } inline void SetBiasOncePerTrack(bool biasOncePerTrack) { fBiasOncePerTrack = biasOncePerTrack; } inline bool GetBiasOncePerTrack() const { return fBiasOncePerTrack; } - inline void AddBiasingVolume(const std::string& volumeName) { fBiasingVolumes.insert(volumeName); } + inline void AddBiasingVolume(const std::string &volumeName) { fBiasingVolumes.insert(volumeName); } inline void ClearBiasingVolumes() { fBiasingVolumes.clear(); } inline std::set GetBiasingVolumes() const { return fBiasingVolumes; } - inline void SetBiasingCenter(const TVector3& biasingCenter) { fBiasingCenter = biasingCenter; } + inline void SetBiasingCenter(const TVector3 &biasingCenter) { fBiasingCenter = biasingCenter; } inline TVector3 GetBiasingCenter() const { return fBiasingCenter; } }; From 3bc9b3d474f0b16ea5718c4f8b6f9628ed63547c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 23 Feb 2023 11:57:02 +0000 Subject: [PATCH 07/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- inc/TRestGeant4BiasingInfo.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/inc/TRestGeant4BiasingInfo.h b/inc/TRestGeant4BiasingInfo.h index 80ee1fe..4f8df37 100644 --- a/inc/TRestGeant4BiasingInfo.h +++ b/inc/TRestGeant4BiasingInfo.h @@ -8,16 +8,16 @@ #include class TRestGeant4BiasingInfo { -ClassDef(TRestGeant4BiasingInfo, 1); + ClassDef(TRestGeant4BiasingInfo, 1); -private: + private: bool fEnabled = false; int fSplittingFactor = 1; bool fBiasOncePerTrack = true; std::set fBiasingVolumes; TVector3 fBiasingCenter; -public: + public: inline TRestGeant4BiasingInfo() = default; inline ~TRestGeant4BiasingInfo() = default; @@ -34,13 +34,13 @@ ClassDef(TRestGeant4BiasingInfo, 1); inline bool GetBiasOncePerTrack() const { return fBiasOncePerTrack; } - inline void AddBiasingVolume(const std::string &volumeName) { fBiasingVolumes.insert(volumeName); } + inline void AddBiasingVolume(const std::string& volumeName) { fBiasingVolumes.insert(volumeName); } inline void ClearBiasingVolumes() { fBiasingVolumes.clear(); } inline std::set GetBiasingVolumes() const { return fBiasingVolumes; } - inline void SetBiasingCenter(const TVector3 &biasingCenter) { fBiasingCenter = biasingCenter; } + inline void SetBiasingCenter(const TVector3& biasingCenter) { fBiasingCenter = biasingCenter; } inline TVector3 GetBiasingCenter() const { return fBiasingCenter; } }; From 6ce4b6018ef60b160e7b8e438d90f840661f083a Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Thu, 23 Feb 2023 13:27:28 +0100 Subject: [PATCH 08/14] support for old biasing --- src/TRestGeant4Metadata.cxx | 236 ++++++++++++++++++------------------ 1 file changed, 121 insertions(+), 115 deletions(-) diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index 268c7ad..20368ce 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -758,8 +758,8 @@ TRestGeant4Metadata::TRestGeant4Metadata() : TRestMetadata() { Initialize(); } /// \param name The name of the specific metadata. It will be used to find the /// corresponding TRestGeant4Metadata section inside the RML. /// -TRestGeant4Metadata::TRestGeant4Metadata(const char* configFilename, const string& name) - : TRestMetadata(configFilename) { +TRestGeant4Metadata::TRestGeant4Metadata(const char *configFilename, const string &name) + : TRestMetadata(configFilename) { Initialize(); LoadConfigFromFile(fConfigFileName, name); @@ -808,17 +808,17 @@ void TRestGeant4Metadata::InitFromConfigFile() { if (ToUpper(seedString) == "RANDOM" || ToUpper(seedString) == "RAND" || ToUpper(seedString) == "AUTO" || seedString == "0") { auto dd = new double(); - fSeed = (uintptr_t)dd + (uintptr_t)this; + fSeed = (uintptr_t) dd + (uintptr_t) this; delete dd; } else { - fSeed = (Long_t)StringToInteger(seedString); + fSeed = (Long_t) StringToInteger(seedString); } gRandom->SetSeed(fSeed); // if "gdmlFile" is purely a file (without any path) and "geometryPath" is // defined, we recombine them together - if ((((string)fGdmlFilename).find_first_not_of("./~") == 0 || - ((string)fGdmlFilename).find("/") == string::npos) && + if ((((string) fGdmlFilename).find_first_not_of("./~") == 0 || + ((string) fGdmlFilename).find("/") == string::npos) && fGeometryPath != "") { if (fGeometryPath[fGeometryPath.Length() - 1] == '/') { fGdmlFilename = fGeometryPath + GetParameter("gdmlFile"); @@ -838,7 +838,7 @@ void TRestGeant4Metadata::InitFromConfigFile() { const auto fNRequestedEntriesString = GetParameter("nRequestedEntries"); fNRequestedEntries = - fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); + fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); fSaveAllEvents = ToUpper(GetParameter("saveAllEvents", "false")) == "TRUE" || ToUpper(GetParameter("saveAllEvents", "off")) == "ON"; @@ -905,8 +905,8 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorType().Data()) != TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypes::COSMIC) { RESTError - << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" - << RESTendl; + << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" + << RESTendl; exit(1); } const auto source = GetParticleSource(); @@ -929,10 +929,10 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { const auto energyRange = source->GetEnergyDistributionRange(); const auto angularRange = source->GetAngularDistributionRange(); - auto function = (TF2*)source->GetEnergyAndAngularDistributionFunction()->Clone(); + auto function = (TF2 *) source->GetEnergyAndAngularDistributionFunction()->Clone(); // counts per second per cm2 (distribution is already integrated over uniform phi) const auto countsPerSecondPerCm2 = - function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); + function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); return countsPerSecondPerCm2; } @@ -953,27 +953,67 @@ Double_t TRestGeant4Metadata::GetEquivalentSimulatedTime() const { * OLD IMPLEMENTATION * void TRestGeant4Metadata::ReadBiasing() { - TiXmlElement* biasingDefinition = GetElement("biasing"); + +} +*/ + +void TRestGeant4Metadata::ReadBiasing() { + + TiXmlElement *biasingDefinition = GetElement("biasing"); if (biasingDefinition == nullptr) { fNBiasingVolumes = 0; + fGeant4BiasingInfo.SetEnabled(false); + return; + } + string biasEnabled = GetFieldValue("value", biasingDefinition); + // biasEnabled to lowercase + std::transform(biasEnabled.begin(), biasEnabled.end(), biasEnabled.begin(), ::tolower); + if (biasEnabled == "off") { + fNBiasingVolumes = 0; + fGeant4BiasingInfo.SetEnabled(false); return; } - TString biasEnabled = GetFieldValue("value", biasingDefinition); - TString biasType = GetFieldValue("type", biasingDefinition); - RESTDebug << "Bias: " << biasEnabled << RESTendl; + RESTInfo << "Biasing is enabled" << RESTendl; + + string biasType = GetFieldValue("type", biasingDefinition); - if (biasEnabled == "on" || biasEnabled == "ON" || biasEnabled == "On" || biasEnabled == "oN") { - RESTInfo << "Biasing is enabled" << RESTendl; + if (biasType == "split") { + fGeant4BiasingInfo.SetEnabled(true); - TiXmlElement* biasVolumeDefinition = GetElement("biasingVolume", biasingDefinition); + const int splittingFactor = StringToInteger(GetParameter("splittingFactor", biasingDefinition, "1")); + + if (splittingFactor <= 1) { + RESTError << "Parameter 'splittingFactor' in biasing section must be set to an integer > 1" + << RESTendl; + exit(1); + } + + fGeant4BiasingInfo.SetSplittingFactor(splittingFactor); + + const TVector3 center = StringTo3DVector(GetParameter("center", biasingDefinition, "(0,0,0)")); + fGeant4BiasingInfo.SetBiasingCenter(center); + + TiXmlElement *volumeDefinition = GetElement("volume", biasingDefinition); + while (volumeDefinition != nullptr) { + string name = GetFieldValue("name", volumeDefinition); + if (name.empty() || name == "Not defined") { + RESTError << "volume inside biasing section defined without name" << RESTendl; + exit(1); + } + fGeant4BiasingInfo.AddBiasingVolume(name); + volumeDefinition = GetNextElement(volumeDefinition); + } + } else { + // default implementation + TiXmlElement *biasVolumeDefinition = GetElement("biasingVolume", biasingDefinition); Int_t n = 0; while (biasVolumeDefinition) { TRestGeant4BiasingVolume biasVolume; RESTDebug << "Def: " << biasVolumeDefinition << RESTendl; biasVolume.SetBiasingVolumePosition( - Get3DVectorParameterWithUnits("position", biasVolumeDefinition)); + Get3DVectorParameterWithUnits("position", biasVolumeDefinition)); biasVolume.SetBiasingFactor(StringToDouble(GetParameter("factor", biasVolumeDefinition))); biasVolume.SetBiasingVolumeSize(GetDblParameterWithUnits("size", biasVolumeDefinition)); biasVolume.SetEnergyRange(Get2DVectorParameterWithUnits("energyRange", biasVolumeDefinition)); @@ -986,40 +1026,6 @@ void TRestGeant4Metadata::ReadBiasing() { fNBiasingVolumes = n; } } -*/ - -void TRestGeant4Metadata::ReadBiasing() { - TiXmlElement* biasingDefinition = GetElement("biasing"); - if (biasingDefinition == nullptr) { - fGeant4BiasingInfo.SetEnabled(false); - return; - } - fGeant4BiasingInfo.SetEnabled(true); - - const int splittingFactor = StringToInteger(GetParameter("splittingFactor", biasingDefinition, "1")); - - if (splittingFactor <= 1) { - RESTError << "Parameter 'splittingFactor' in biasing section must be set to an integer > 1" - << RESTendl; - exit(1); - } - - fGeant4BiasingInfo.SetSplittingFactor(splittingFactor); - - const TVector3 center = StringTo3DVector(GetParameter("center", biasingDefinition, "(0,0,0)")); - fGeant4BiasingInfo.SetBiasingCenter(center); - - TiXmlElement* volumeDefinition = GetElement("volume", biasingDefinition); - while (volumeDefinition != nullptr) { - string name = GetFieldValue("name", volumeDefinition); - if (name.empty() || name == "Not defined") { - RESTError << "volume inside biasing section defined without name" << RESTendl; - exit(1); - } - fGeant4BiasingInfo.AddBiasingVolume(name); - volumeDefinition = GetNextElement(volumeDefinition); - } -} /////////////////////////////////////////////// /// \brief Reads the generator section defined inside TRestGeant4Metadata. @@ -1055,35 +1061,35 @@ void TRestGeant4Metadata::ReadGenerator() { // center of the volume (i.e. gasTarget) but if i.e rotation or side are // defined and not relevant we should set it to -1 - TiXmlElement* generatorDefinition = GetElement("generator"); + TiXmlElement *generatorDefinition = GetElement("generator"); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorType = - SpatialGeneratorTypesToString(StringToSpatialGeneratorTypes(GetParameter( - "type", generatorDefinition, SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME)))); + SpatialGeneratorTypesToString(StringToSpatialGeneratorTypes(GetParameter( + "type", generatorDefinition, SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME)))); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorShape = - SpatialGeneratorShapesToString(StringToSpatialGeneratorShapes(GetParameter( - "shape", generatorDefinition, SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX)))); + SpatialGeneratorShapesToString(StringToSpatialGeneratorShapes(GetParameter( + "shape", generatorDefinition, SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX)))); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorFrom = GetParameter("from", generatorDefinition); if (fGeant4PrimaryGeneratorInfo.fSpatialGeneratorFrom != PARAMETER_NOT_FOUND_STR) { fGeant4PrimaryGeneratorInfo.fSpatialGeneratorShape = - SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML); + SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML); } fGeant4PrimaryGeneratorInfo.fSpatialGeneratorSize = - Get3DVectorParameterWithUnits("size", generatorDefinition, {0, 0, 0}); + Get3DVectorParameterWithUnits("size", generatorDefinition, {0, 0, 0}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorPosition = - Get3DVectorParameterWithUnits("position", generatorDefinition, {0, 0, 0}); + Get3DVectorParameterWithUnits("position", generatorDefinition, {0, 0, 0}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorRotationAxis = - Get3DVectorParameterWithUnits("rotationAxis", generatorDefinition, {0, 0, 1}); + Get3DVectorParameterWithUnits("rotationAxis", generatorDefinition, {0, 0, 1}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorRotationValue = - GetDblParameterWithUnits("rotationAngle", generatorDefinition, 0); + GetDblParameterWithUnits("rotationAngle", generatorDefinition, 0); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorSpatialDensityFunction = - GetParameter("densityFunc", generatorDefinition, "1"); + GetParameter("densityFunc", generatorDefinition, "1"); - TiXmlElement* sourceDefinition = GetElement("source", generatorDefinition); + TiXmlElement *sourceDefinition = GetElement("source", generatorDefinition); while (sourceDefinition) { string use = GetParameter("use", sourceDefinition, ""); - TRestGeant4ParticleSource* source = TRestGeant4ParticleSource::instantiate(use); + TRestGeant4ParticleSource *source = TRestGeant4ParticleSource::instantiate(use); ReadParticleSource(source, sourceDefinition); AddParticleSource(source); @@ -1100,8 +1106,8 @@ void TRestGeant4Metadata::ReadGenerator() { /////////////////////////////////////////////// /// \brief It reads the SetParticleName(GetParameter("particle", sourceDefinition)); source->SetExcitationLevel(StringToDouble(GetParameter("excitedLevel", sourceDefinition))); @@ -1114,12 +1120,12 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, } // Angular distribution parameters - TiXmlElement* angularDefinition = GetElement("angular", sourceDefinition); + TiXmlElement *angularDefinition = GetElement("angular", sourceDefinition); if (angularDefinition == nullptr) { angularDefinition = GetElement("angularDist", sourceDefinition); // old name } source->SetAngularDistributionType(GetParameter( - "type", angularDefinition, AngularDistributionTypesToString(AngularDistributionTypes::FLUX))); + "type", angularDefinition, AngularDistributionTypesToString(AngularDistributionTypes::FLUX))); if (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::TH1D) { source->SetAngularDistributionFilename(SearchFile(GetParameter("file", angularDefinition))); @@ -1130,7 +1136,7 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, source->SetAngularDistributionNameInFile(name); } source->SetAngularDistributionRange( - Get2DVectorParameterWithUnits("range", angularDefinition, {0, TMath::Pi()})); + Get2DVectorParameterWithUnits("range", angularDefinition, {0, TMath::Pi()})); if (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::FORMULA) { source->SetAngularDistributionFormula(GetParameter("name", angularDefinition)); @@ -1138,11 +1144,11 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, const auto function = source->GetAngularDistributionFunction(); if (source->GetAngularDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetAngularDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); } if (source->GetAngularDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetAngularDistributionRange( - {source->GetAngularDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetAngularDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } } if ((StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == @@ -1150,24 +1156,24 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::FORMULA2)) { source->SetAngularDistributionFormulaNPoints(static_cast(GetDblParameterWithUnits( - "nPoints", angularDefinition, source->GetAngularDistributionFormulaNPoints()))); + "nPoints", angularDefinition, source->GetAngularDistributionFormulaNPoints()))); } if (GetNumberOfSources() == 0 && StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == - AngularDistributionTypes::BACK_TO_BACK) { + AngularDistributionTypes::BACK_TO_BACK) { cout << "WARNING: First source cannot be backtoback. Setting it to isotropic" << endl; source->SetAngularDistributionType( - AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC)); + AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC)); } source->SetDirection(StringTo3DVector(GetParameter("direction", angularDefinition, "(1,0,0)"))); // Energy distribution parameters - TiXmlElement* energyDefinition = GetElement("energy", sourceDefinition); + TiXmlElement *energyDefinition = GetElement("energy", sourceDefinition); if (energyDefinition == nullptr) { energyDefinition = GetElement("energyDist", sourceDefinition); // old name } source->SetEnergyDistributionType(GetParameter( - "type", energyDefinition, EnergyDistributionTypesToString(EnergyDistributionTypes::MONO))); + "type", energyDefinition, EnergyDistributionTypesToString(EnergyDistributionTypes::MONO))); if (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == EnergyDistributionTypes::TH1D) { source->SetEnergyDistributionFilename(SearchFile(GetParameter("file", energyDefinition))); @@ -1192,11 +1198,11 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, const auto function = source->GetEnergyDistributionFunction(); if (source->GetEnergyDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetEnergyDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); } if (source->GetEnergyDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetEnergyDistributionRange( - {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } } if ((StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == @@ -1204,12 +1210,12 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == EnergyDistributionTypes::FORMULA2)) { source->SetEnergyDistributionFormulaNPoints(static_cast(GetDblParameterWithUnits( - "nPoints", energyDefinition, source->GetEnergyDistributionFormulaNPoints()))); + "nPoints", energyDefinition, source->GetEnergyDistributionFormulaNPoints()))); } if (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == - EnergyDistributionTypes::FORMULA2 && + EnergyDistributionTypes::FORMULA2 && StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == - AngularDistributionTypes::FORMULA2) { + AngularDistributionTypes::FORMULA2) { const auto empty = TString(""); auto energyDistName = GetParameter("name", energyDefinition, empty); auto angularDistName = GetParameter("name", energyDefinition, empty); @@ -1242,21 +1248,21 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, // Set energy range if (source->GetEnergyDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetEnergyDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); } if (source->GetEnergyDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetEnergyDistributionRange( - {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } // Set angular range if (source->GetAngularDistributionRangeMin() < function->GetYaxis()->GetXmin()) { source->SetAngularDistributionRange( - {function->GetYaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); + {function->GetYaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); } if (source->GetAngularDistributionRangeMax() > function->GetYaxis()->GetXmax()) { source->SetAngularDistributionRange( - {source->GetAngularDistributionRangeMin(), function->GetYaxis()->GetXmax()}); + {source->GetAngularDistributionRangeMin(), function->GetYaxis()->GetXmax()}); } } // allow custom configuration from the class @@ -1265,13 +1271,13 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, } void TRestGeant4Metadata::RemoveParticleSources() { - for (auto source : fParticleSource) { + for (auto source: fParticleSource) { delete source; } fParticleSource.clear(); } -void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource* src) { +void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource *src) { fParticleSource.push_back(src); } @@ -1291,22 +1297,22 @@ void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource* src) { /// void TRestGeant4Metadata::ReadDetector() { RESTInfo << "TRestGeant4Metadata: Processing detector section" << RESTendl; - TiXmlElement* detectorDefinition = GetElement("detector"); + TiXmlElement *detectorDefinition = GetElement("detector"); if (detectorDefinition == nullptr) { RESTError << "Detector section () is not present in metadata!" << RESTendl; exit(1); } const bool activateAllVolumes = - StringToBool(GetParameter("activateAllVolumes", detectorDefinition, "true")); + StringToBool(GetParameter("activateAllVolumes", detectorDefinition, "true")); RESTInfo << "TRestGeant4Metadata: Setting 'fActivateAllVolumes' to " << fActivateAllVolumes << RESTendl; fActivateAllVolumes = activateAllVolumes; - TiXmlElement* removeUnwantedTracksDefinition = GetElement("removeUnwantedTracks", detectorDefinition); + TiXmlElement *removeUnwantedTracksDefinition = GetElement("removeUnwantedTracks", detectorDefinition); if (removeUnwantedTracksDefinition != nullptr) { fRemoveUnwantedTracks = StringToBool(GetParameter("enabled", removeUnwantedTracksDefinition, "true")); fRemoveUnwantedTracksKeepZeroEnergyTracks = - StringToBool(GetParameter("keepZeroEnergyTracks", removeUnwantedTracksDefinition, "false")); + StringToBool(GetParameter("keepZeroEnergyTracks", removeUnwantedTracksDefinition, "false")); RESTInfo << "TRestGeant4Metadata: Setting 'fRemoveUnwantedTracks' to " << fRemoveUnwantedTracks << " with 'keepZeroEnergyTracks' option set to " << fRemoveUnwantedTracksKeepZeroEnergyTracks << RESTendl; @@ -1317,7 +1323,7 @@ void TRestGeant4Metadata::ReadDetector() { defaultStep = 0; } - TiXmlElement* volumeDefinition = GetElement("volume", detectorDefinition); + TiXmlElement *volumeDefinition = GetElement("volume", detectorDefinition); while (volumeDefinition != nullptr) { string name = GetFieldValue("name", volumeDefinition); if (name.empty() || name == "Not defined") { @@ -1327,25 +1333,25 @@ void TRestGeant4Metadata::ReadDetector() { vector physicalVolumes; if (!fGeant4GeometryInfo.IsValidGdmlName(name)) { if (fGeant4GeometryInfo.IsValidLogicalVolume(name)) { - for (const auto& physical : fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(name)) { + for (const auto &physical: fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(name)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } // does not match a explicit (gdml) physical name or a logical name, perhaps its a regular exp if (physicalVolumes.empty()) { - for (const auto& physical : - fGeant4GeometryInfo.GetAllPhysicalVolumesMatchingExpression(name)) { + for (const auto &physical: + fGeant4GeometryInfo.GetAllPhysicalVolumesMatchingExpression(name)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } if (physicalVolumes.empty()) { - for (const auto& logical : fGeant4GeometryInfo.GetAllLogicalVolumesMatchingExpression(name)) { - for (const auto& physical : - fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(logical)) { + for (const auto &logical: fGeant4GeometryInfo.GetAllLogicalVolumesMatchingExpression(name)) { + for (const auto &physical: + fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(logical)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } } @@ -1355,9 +1361,9 @@ void TRestGeant4Metadata::ReadDetector() { if (physicalVolumes.empty()) { RESTError - << "volume '" << name - << "' is not defined in the geometry. Could not match to a physical, logical volume or regex" - << RESTendl; + << "volume '" << name + << "' is not defined in the geometry. Could not match to a physical, logical volume or regex" + << RESTendl; exit(1); } @@ -1388,7 +1394,7 @@ void TRestGeant4Metadata::ReadDetector() { maxStep = defaultStep; } - for (const auto& physical : physicalVolumes) { + for (const auto &physical: physicalVolumes) { RESTInfo << "Adding " << (isSensitive ? "sensitive" : "active") << " volume from RML: '" << physical << (chance != 1 ? " with change: " + to_string(chance) : " ") << RESTendl; SetActiveVolume(physical, chance, maxStep); @@ -1435,7 +1441,7 @@ void TRestGeant4Metadata::ReadDetector() { // If the user did not add explicitly any volume to the storage section we understand // the user wants to register all the volumes if (fActivateAllVolumes) { - for (const auto& name : fGeant4GeometryInfo.GetAllPhysicalVolumes()) { + for (const auto &name: fGeant4GeometryInfo.GetAllPhysicalVolumes()) { if (!IsActiveVolume(name)) { SetActiveVolume(name, 1, defaultStep); RESTInfo << "Automatically adding active volume: '" << name << "' with chance: " << 1 @@ -1485,7 +1491,7 @@ void TRestGeant4Metadata::PrintMetadata() { RESTMetadata << "Energy range (keV): (" << GetMinimumEnergyStored() << ", " << GetMaximumEnergyStored() << ")" << RESTendl; RESTMetadata << "Number of sensitive volumes: " << GetNumberOfSensitiveVolumes() << RESTendl; - for (const auto& sensitiveVolume : fSensitiveVolumes) { + for (const auto &sensitiveVolume: fSensitiveVolumes) { RESTMetadata << "Sensitive volume: " << sensitiveVolume << RESTendl; } RESTMetadata << "Number of active volumes: " << GetNumberOfActiveVolumes() << RESTendl; @@ -1520,7 +1526,7 @@ void TRestGeant4Metadata::PrintMetadata() { /// \brief Returns the id of an active volume giving as parameter its name. Int_t TRestGeant4Metadata::GetActiveVolumeID(TString name) { Int_t id; - for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { + for (id = 0; id < (Int_t) fActiveVolumes.size(); id++) { if (fActiveVolumes[id] == name) return id; } return -1; @@ -1540,7 +1546,7 @@ Int_t TRestGeant4Metadata::GetActiveVolumeID(TString name) { /// The aim of this parameter is to define control volumes. Usually the volume /// of interest will be always registered (chance=1). /// -void TRestGeant4Metadata::SetActiveVolume(const TString& name, Double_t chance, Double_t maxStep) { +void TRestGeant4Metadata::SetActiveVolume(const TString &name, Double_t chance, Double_t maxStep) { for (size_t i = 0; i < fActiveVolumes.size(); i++) { const auto activeVolumeName = fActiveVolumes[i]; if (name == activeVolumeName) { @@ -1559,7 +1565,7 @@ void TRestGeant4Metadata::SetActiveVolume(const TString& name, Double_t chance, /// \brief Returns true if the volume named *volName* has been registered for /// data storage. /// -Bool_t TRestGeant4Metadata::isVolumeStored(const TString& volume) const { +Bool_t TRestGeant4Metadata::isVolumeStored(const TString &volume) const { for (unsigned int n = 0; n < GetNumberOfActiveVolumes(); n++) if (GetActiveVolumeName(n) == volume) return true; @@ -1571,7 +1577,7 @@ Bool_t TRestGeant4Metadata::isVolumeStored(const TString& volume) const { /// Double_t TRestGeant4Metadata::GetStorageChance(TString volume) { Int_t id; - for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { + for (id = 0; id < (Int_t) fActiveVolumes.size(); id++) { if (fActiveVolumes[id] == volume) return fChance[id]; } RESTWarning << "TRestGeant4Metadata::GetStorageChance. Volume " << volume << " not found" << RESTendl; @@ -1582,8 +1588,8 @@ Double_t TRestGeant4Metadata::GetStorageChance(TString volume) { /////////////////////////////////////////////// /// \brief Returns the maximum step at a particular active volume /// -Double_t TRestGeant4Metadata::GetMaxStepSize(const TString& volume) { - for (Int_t i = 0; i < (Int_t)fActiveVolumes.size(); i++) { +Double_t TRestGeant4Metadata::GetMaxStepSize(const TString &volume) { + for (Int_t i = 0; i < (Int_t) fActiveVolumes.size(); i++) { if (volume.EqualTo(fActiveVolumes[i], TString::kIgnoreCase)) { return fMaxStepSize[i]; } From 2fa4b798d51f8bc28a0e938052fa0fbffa1ac8e9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 23 Feb 2023 12:29:28 +0000 Subject: [PATCH 09/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/TRestGeant4Metadata.cxx | 155 ++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 78 deletions(-) diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index 20368ce..0eb49f7 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -758,8 +758,8 @@ TRestGeant4Metadata::TRestGeant4Metadata() : TRestMetadata() { Initialize(); } /// \param name The name of the specific metadata. It will be used to find the /// corresponding TRestGeant4Metadata section inside the RML. /// -TRestGeant4Metadata::TRestGeant4Metadata(const char *configFilename, const string &name) - : TRestMetadata(configFilename) { +TRestGeant4Metadata::TRestGeant4Metadata(const char* configFilename, const string& name) + : TRestMetadata(configFilename) { Initialize(); LoadConfigFromFile(fConfigFileName, name); @@ -808,17 +808,17 @@ void TRestGeant4Metadata::InitFromConfigFile() { if (ToUpper(seedString) == "RANDOM" || ToUpper(seedString) == "RAND" || ToUpper(seedString) == "AUTO" || seedString == "0") { auto dd = new double(); - fSeed = (uintptr_t) dd + (uintptr_t) this; + fSeed = (uintptr_t)dd + (uintptr_t)this; delete dd; } else { - fSeed = (Long_t) StringToInteger(seedString); + fSeed = (Long_t)StringToInteger(seedString); } gRandom->SetSeed(fSeed); // if "gdmlFile" is purely a file (without any path) and "geometryPath" is // defined, we recombine them together - if ((((string) fGdmlFilename).find_first_not_of("./~") == 0 || - ((string) fGdmlFilename).find("/") == string::npos) && + if ((((string)fGdmlFilename).find_first_not_of("./~") == 0 || + ((string)fGdmlFilename).find("/") == string::npos) && fGeometryPath != "") { if (fGeometryPath[fGeometryPath.Length() - 1] == '/') { fGdmlFilename = fGeometryPath + GetParameter("gdmlFile"); @@ -838,7 +838,7 @@ void TRestGeant4Metadata::InitFromConfigFile() { const auto fNRequestedEntriesString = GetParameter("nRequestedEntries"); fNRequestedEntries = - fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); + fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); fSaveAllEvents = ToUpper(GetParameter("saveAllEvents", "false")) == "TRUE" || ToUpper(GetParameter("saveAllEvents", "off")) == "ON"; @@ -905,8 +905,8 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorType().Data()) != TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypes::COSMIC) { RESTError - << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" - << RESTendl; + << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" + << RESTendl; exit(1); } const auto source = GetParticleSource(); @@ -929,10 +929,10 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { const auto energyRange = source->GetEnergyDistributionRange(); const auto angularRange = source->GetAngularDistributionRange(); - auto function = (TF2 *) source->GetEnergyAndAngularDistributionFunction()->Clone(); + auto function = (TF2*)source->GetEnergyAndAngularDistributionFunction()->Clone(); // counts per second per cm2 (distribution is already integrated over uniform phi) const auto countsPerSecondPerCm2 = - function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); + function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); return countsPerSecondPerCm2; } @@ -958,8 +958,7 @@ void TRestGeant4Metadata::ReadBiasing() { */ void TRestGeant4Metadata::ReadBiasing() { - - TiXmlElement *biasingDefinition = GetElement("biasing"); + TiXmlElement* biasingDefinition = GetElement("biasing"); if (biasingDefinition == nullptr) { fNBiasingVolumes = 0; fGeant4BiasingInfo.SetEnabled(false); @@ -994,7 +993,7 @@ void TRestGeant4Metadata::ReadBiasing() { const TVector3 center = StringTo3DVector(GetParameter("center", biasingDefinition, "(0,0,0)")); fGeant4BiasingInfo.SetBiasingCenter(center); - TiXmlElement *volumeDefinition = GetElement("volume", biasingDefinition); + TiXmlElement* volumeDefinition = GetElement("volume", biasingDefinition); while (volumeDefinition != nullptr) { string name = GetFieldValue("name", volumeDefinition); if (name.empty() || name == "Not defined") { @@ -1006,14 +1005,14 @@ void TRestGeant4Metadata::ReadBiasing() { } } else { // default implementation - TiXmlElement *biasVolumeDefinition = GetElement("biasingVolume", biasingDefinition); + TiXmlElement* biasVolumeDefinition = GetElement("biasingVolume", biasingDefinition); Int_t n = 0; while (biasVolumeDefinition) { TRestGeant4BiasingVolume biasVolume; RESTDebug << "Def: " << biasVolumeDefinition << RESTendl; biasVolume.SetBiasingVolumePosition( - Get3DVectorParameterWithUnits("position", biasVolumeDefinition)); + Get3DVectorParameterWithUnits("position", biasVolumeDefinition)); biasVolume.SetBiasingFactor(StringToDouble(GetParameter("factor", biasVolumeDefinition))); biasVolume.SetBiasingVolumeSize(GetDblParameterWithUnits("size", biasVolumeDefinition)); biasVolume.SetEnergyRange(Get2DVectorParameterWithUnits("energyRange", biasVolumeDefinition)); @@ -1061,35 +1060,35 @@ void TRestGeant4Metadata::ReadGenerator() { // center of the volume (i.e. gasTarget) but if i.e rotation or side are // defined and not relevant we should set it to -1 - TiXmlElement *generatorDefinition = GetElement("generator"); + TiXmlElement* generatorDefinition = GetElement("generator"); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorType = - SpatialGeneratorTypesToString(StringToSpatialGeneratorTypes(GetParameter( - "type", generatorDefinition, SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME)))); + SpatialGeneratorTypesToString(StringToSpatialGeneratorTypes(GetParameter( + "type", generatorDefinition, SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME)))); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorShape = - SpatialGeneratorShapesToString(StringToSpatialGeneratorShapes(GetParameter( - "shape", generatorDefinition, SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX)))); + SpatialGeneratorShapesToString(StringToSpatialGeneratorShapes(GetParameter( + "shape", generatorDefinition, SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX)))); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorFrom = GetParameter("from", generatorDefinition); if (fGeant4PrimaryGeneratorInfo.fSpatialGeneratorFrom != PARAMETER_NOT_FOUND_STR) { fGeant4PrimaryGeneratorInfo.fSpatialGeneratorShape = - SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML); + SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML); } fGeant4PrimaryGeneratorInfo.fSpatialGeneratorSize = - Get3DVectorParameterWithUnits("size", generatorDefinition, {0, 0, 0}); + Get3DVectorParameterWithUnits("size", generatorDefinition, {0, 0, 0}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorPosition = - Get3DVectorParameterWithUnits("position", generatorDefinition, {0, 0, 0}); + Get3DVectorParameterWithUnits("position", generatorDefinition, {0, 0, 0}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorRotationAxis = - Get3DVectorParameterWithUnits("rotationAxis", generatorDefinition, {0, 0, 1}); + Get3DVectorParameterWithUnits("rotationAxis", generatorDefinition, {0, 0, 1}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorRotationValue = - GetDblParameterWithUnits("rotationAngle", generatorDefinition, 0); + GetDblParameterWithUnits("rotationAngle", generatorDefinition, 0); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorSpatialDensityFunction = - GetParameter("densityFunc", generatorDefinition, "1"); + GetParameter("densityFunc", generatorDefinition, "1"); - TiXmlElement *sourceDefinition = GetElement("source", generatorDefinition); + TiXmlElement* sourceDefinition = GetElement("source", generatorDefinition); while (sourceDefinition) { string use = GetParameter("use", sourceDefinition, ""); - TRestGeant4ParticleSource *source = TRestGeant4ParticleSource::instantiate(use); + TRestGeant4ParticleSource* source = TRestGeant4ParticleSource::instantiate(use); ReadParticleSource(source, sourceDefinition); AddParticleSource(source); @@ -1106,8 +1105,8 @@ void TRestGeant4Metadata::ReadGenerator() { /////////////////////////////////////////////// /// \brief It reads the SetParticleName(GetParameter("particle", sourceDefinition)); source->SetExcitationLevel(StringToDouble(GetParameter("excitedLevel", sourceDefinition))); @@ -1120,12 +1119,12 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, } // Angular distribution parameters - TiXmlElement *angularDefinition = GetElement("angular", sourceDefinition); + TiXmlElement* angularDefinition = GetElement("angular", sourceDefinition); if (angularDefinition == nullptr) { angularDefinition = GetElement("angularDist", sourceDefinition); // old name } source->SetAngularDistributionType(GetParameter( - "type", angularDefinition, AngularDistributionTypesToString(AngularDistributionTypes::FLUX))); + "type", angularDefinition, AngularDistributionTypesToString(AngularDistributionTypes::FLUX))); if (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::TH1D) { source->SetAngularDistributionFilename(SearchFile(GetParameter("file", angularDefinition))); @@ -1136,7 +1135,7 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, source->SetAngularDistributionNameInFile(name); } source->SetAngularDistributionRange( - Get2DVectorParameterWithUnits("range", angularDefinition, {0, TMath::Pi()})); + Get2DVectorParameterWithUnits("range", angularDefinition, {0, TMath::Pi()})); if (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::FORMULA) { source->SetAngularDistributionFormula(GetParameter("name", angularDefinition)); @@ -1144,11 +1143,11 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, const auto function = source->GetAngularDistributionFunction(); if (source->GetAngularDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetAngularDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); } if (source->GetAngularDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetAngularDistributionRange( - {source->GetAngularDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetAngularDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } } if ((StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == @@ -1156,24 +1155,24 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::FORMULA2)) { source->SetAngularDistributionFormulaNPoints(static_cast(GetDblParameterWithUnits( - "nPoints", angularDefinition, source->GetAngularDistributionFormulaNPoints()))); + "nPoints", angularDefinition, source->GetAngularDistributionFormulaNPoints()))); } if (GetNumberOfSources() == 0 && StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == - AngularDistributionTypes::BACK_TO_BACK) { + AngularDistributionTypes::BACK_TO_BACK) { cout << "WARNING: First source cannot be backtoback. Setting it to isotropic" << endl; source->SetAngularDistributionType( - AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC)); + AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC)); } source->SetDirection(StringTo3DVector(GetParameter("direction", angularDefinition, "(1,0,0)"))); // Energy distribution parameters - TiXmlElement *energyDefinition = GetElement("energy", sourceDefinition); + TiXmlElement* energyDefinition = GetElement("energy", sourceDefinition); if (energyDefinition == nullptr) { energyDefinition = GetElement("energyDist", sourceDefinition); // old name } source->SetEnergyDistributionType(GetParameter( - "type", energyDefinition, EnergyDistributionTypesToString(EnergyDistributionTypes::MONO))); + "type", energyDefinition, EnergyDistributionTypesToString(EnergyDistributionTypes::MONO))); if (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == EnergyDistributionTypes::TH1D) { source->SetEnergyDistributionFilename(SearchFile(GetParameter("file", energyDefinition))); @@ -1198,11 +1197,11 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, const auto function = source->GetEnergyDistributionFunction(); if (source->GetEnergyDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetEnergyDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); } if (source->GetEnergyDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetEnergyDistributionRange( - {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } } if ((StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == @@ -1210,12 +1209,12 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == EnergyDistributionTypes::FORMULA2)) { source->SetEnergyDistributionFormulaNPoints(static_cast(GetDblParameterWithUnits( - "nPoints", energyDefinition, source->GetEnergyDistributionFormulaNPoints()))); + "nPoints", energyDefinition, source->GetEnergyDistributionFormulaNPoints()))); } if (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == - EnergyDistributionTypes::FORMULA2 && + EnergyDistributionTypes::FORMULA2 && StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == - AngularDistributionTypes::FORMULA2) { + AngularDistributionTypes::FORMULA2) { const auto empty = TString(""); auto energyDistName = GetParameter("name", energyDefinition, empty); auto angularDistName = GetParameter("name", energyDefinition, empty); @@ -1248,21 +1247,21 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, // Set energy range if (source->GetEnergyDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetEnergyDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); } if (source->GetEnergyDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetEnergyDistributionRange( - {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } // Set angular range if (source->GetAngularDistributionRangeMin() < function->GetYaxis()->GetXmin()) { source->SetAngularDistributionRange( - {function->GetYaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); + {function->GetYaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); } if (source->GetAngularDistributionRangeMax() > function->GetYaxis()->GetXmax()) { source->SetAngularDistributionRange( - {source->GetAngularDistributionRangeMin(), function->GetYaxis()->GetXmax()}); + {source->GetAngularDistributionRangeMin(), function->GetYaxis()->GetXmax()}); } } // allow custom configuration from the class @@ -1271,13 +1270,13 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, } void TRestGeant4Metadata::RemoveParticleSources() { - for (auto source: fParticleSource) { + for (auto source : fParticleSource) { delete source; } fParticleSource.clear(); } -void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource *src) { +void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource* src) { fParticleSource.push_back(src); } @@ -1297,22 +1296,22 @@ void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource *src) { /// void TRestGeant4Metadata::ReadDetector() { RESTInfo << "TRestGeant4Metadata: Processing detector section" << RESTendl; - TiXmlElement *detectorDefinition = GetElement("detector"); + TiXmlElement* detectorDefinition = GetElement("detector"); if (detectorDefinition == nullptr) { RESTError << "Detector section () is not present in metadata!" << RESTendl; exit(1); } const bool activateAllVolumes = - StringToBool(GetParameter("activateAllVolumes", detectorDefinition, "true")); + StringToBool(GetParameter("activateAllVolumes", detectorDefinition, "true")); RESTInfo << "TRestGeant4Metadata: Setting 'fActivateAllVolumes' to " << fActivateAllVolumes << RESTendl; fActivateAllVolumes = activateAllVolumes; - TiXmlElement *removeUnwantedTracksDefinition = GetElement("removeUnwantedTracks", detectorDefinition); + TiXmlElement* removeUnwantedTracksDefinition = GetElement("removeUnwantedTracks", detectorDefinition); if (removeUnwantedTracksDefinition != nullptr) { fRemoveUnwantedTracks = StringToBool(GetParameter("enabled", removeUnwantedTracksDefinition, "true")); fRemoveUnwantedTracksKeepZeroEnergyTracks = - StringToBool(GetParameter("keepZeroEnergyTracks", removeUnwantedTracksDefinition, "false")); + StringToBool(GetParameter("keepZeroEnergyTracks", removeUnwantedTracksDefinition, "false")); RESTInfo << "TRestGeant4Metadata: Setting 'fRemoveUnwantedTracks' to " << fRemoveUnwantedTracks << " with 'keepZeroEnergyTracks' option set to " << fRemoveUnwantedTracksKeepZeroEnergyTracks << RESTendl; @@ -1323,7 +1322,7 @@ void TRestGeant4Metadata::ReadDetector() { defaultStep = 0; } - TiXmlElement *volumeDefinition = GetElement("volume", detectorDefinition); + TiXmlElement* volumeDefinition = GetElement("volume", detectorDefinition); while (volumeDefinition != nullptr) { string name = GetFieldValue("name", volumeDefinition); if (name.empty() || name == "Not defined") { @@ -1333,25 +1332,25 @@ void TRestGeant4Metadata::ReadDetector() { vector physicalVolumes; if (!fGeant4GeometryInfo.IsValidGdmlName(name)) { if (fGeant4GeometryInfo.IsValidLogicalVolume(name)) { - for (const auto &physical: fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(name)) { + for (const auto& physical : fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(name)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } // does not match a explicit (gdml) physical name or a logical name, perhaps its a regular exp if (physicalVolumes.empty()) { - for (const auto &physical: - fGeant4GeometryInfo.GetAllPhysicalVolumesMatchingExpression(name)) { + for (const auto& physical : + fGeant4GeometryInfo.GetAllPhysicalVolumesMatchingExpression(name)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } if (physicalVolumes.empty()) { - for (const auto &logical: fGeant4GeometryInfo.GetAllLogicalVolumesMatchingExpression(name)) { - for (const auto &physical: - fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(logical)) { + for (const auto& logical : fGeant4GeometryInfo.GetAllLogicalVolumesMatchingExpression(name)) { + for (const auto& physical : + fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(logical)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } } @@ -1361,9 +1360,9 @@ void TRestGeant4Metadata::ReadDetector() { if (physicalVolumes.empty()) { RESTError - << "volume '" << name - << "' is not defined in the geometry. Could not match to a physical, logical volume or regex" - << RESTendl; + << "volume '" << name + << "' is not defined in the geometry. Could not match to a physical, logical volume or regex" + << RESTendl; exit(1); } @@ -1394,7 +1393,7 @@ void TRestGeant4Metadata::ReadDetector() { maxStep = defaultStep; } - for (const auto &physical: physicalVolumes) { + for (const auto& physical : physicalVolumes) { RESTInfo << "Adding " << (isSensitive ? "sensitive" : "active") << " volume from RML: '" << physical << (chance != 1 ? " with change: " + to_string(chance) : " ") << RESTendl; SetActiveVolume(physical, chance, maxStep); @@ -1441,7 +1440,7 @@ void TRestGeant4Metadata::ReadDetector() { // If the user did not add explicitly any volume to the storage section we understand // the user wants to register all the volumes if (fActivateAllVolumes) { - for (const auto &name: fGeant4GeometryInfo.GetAllPhysicalVolumes()) { + for (const auto& name : fGeant4GeometryInfo.GetAllPhysicalVolumes()) { if (!IsActiveVolume(name)) { SetActiveVolume(name, 1, defaultStep); RESTInfo << "Automatically adding active volume: '" << name << "' with chance: " << 1 @@ -1491,7 +1490,7 @@ void TRestGeant4Metadata::PrintMetadata() { RESTMetadata << "Energy range (keV): (" << GetMinimumEnergyStored() << ", " << GetMaximumEnergyStored() << ")" << RESTendl; RESTMetadata << "Number of sensitive volumes: " << GetNumberOfSensitiveVolumes() << RESTendl; - for (const auto &sensitiveVolume: fSensitiveVolumes) { + for (const auto& sensitiveVolume : fSensitiveVolumes) { RESTMetadata << "Sensitive volume: " << sensitiveVolume << RESTendl; } RESTMetadata << "Number of active volumes: " << GetNumberOfActiveVolumes() << RESTendl; @@ -1526,7 +1525,7 @@ void TRestGeant4Metadata::PrintMetadata() { /// \brief Returns the id of an active volume giving as parameter its name. Int_t TRestGeant4Metadata::GetActiveVolumeID(TString name) { Int_t id; - for (id = 0; id < (Int_t) fActiveVolumes.size(); id++) { + for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { if (fActiveVolumes[id] == name) return id; } return -1; @@ -1546,7 +1545,7 @@ Int_t TRestGeant4Metadata::GetActiveVolumeID(TString name) { /// The aim of this parameter is to define control volumes. Usually the volume /// of interest will be always registered (chance=1). /// -void TRestGeant4Metadata::SetActiveVolume(const TString &name, Double_t chance, Double_t maxStep) { +void TRestGeant4Metadata::SetActiveVolume(const TString& name, Double_t chance, Double_t maxStep) { for (size_t i = 0; i < fActiveVolumes.size(); i++) { const auto activeVolumeName = fActiveVolumes[i]; if (name == activeVolumeName) { @@ -1565,7 +1564,7 @@ void TRestGeant4Metadata::SetActiveVolume(const TString &name, Double_t chance, /// \brief Returns true if the volume named *volName* has been registered for /// data storage. /// -Bool_t TRestGeant4Metadata::isVolumeStored(const TString &volume) const { +Bool_t TRestGeant4Metadata::isVolumeStored(const TString& volume) const { for (unsigned int n = 0; n < GetNumberOfActiveVolumes(); n++) if (GetActiveVolumeName(n) == volume) return true; @@ -1577,7 +1576,7 @@ Bool_t TRestGeant4Metadata::isVolumeStored(const TString &volume) const { /// Double_t TRestGeant4Metadata::GetStorageChance(TString volume) { Int_t id; - for (id = 0; id < (Int_t) fActiveVolumes.size(); id++) { + for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { if (fActiveVolumes[id] == volume) return fChance[id]; } RESTWarning << "TRestGeant4Metadata::GetStorageChance. Volume " << volume << " not found" << RESTendl; @@ -1588,8 +1587,8 @@ Double_t TRestGeant4Metadata::GetStorageChance(TString volume) { /////////////////////////////////////////////// /// \brief Returns the maximum step at a particular active volume /// -Double_t TRestGeant4Metadata::GetMaxStepSize(const TString &volume) { - for (Int_t i = 0; i < (Int_t) fActiveVolumes.size(); i++) { +Double_t TRestGeant4Metadata::GetMaxStepSize(const TString& volume) { + for (Int_t i = 0; i < (Int_t)fActiveVolumes.size(); i++) { if (volume.EqualTo(fActiveVolumes[i], TString::kIgnoreCase)) { return fMaxStepSize[i]; } From c4ae5a3c9bab448d938ba4a24e35d625f32c1dc0 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Mon, 27 Feb 2023 12:16:20 +0100 Subject: [PATCH 10/14] add generic "cosmic" distribution (power -2.7) --- inc/TRestGeant4PrimaryGeneratorInfo.h | 2 +- src/TRestGeant4PrimaryGeneratorInfo.cxx | 104 +++++++++++++----------- 2 files changed, 57 insertions(+), 49 deletions(-) diff --git a/inc/TRestGeant4PrimaryGeneratorInfo.h b/inc/TRestGeant4PrimaryGeneratorInfo.h index e5a49cb..9ecb007 100644 --- a/inc/TRestGeant4PrimaryGeneratorInfo.h +++ b/inc/TRestGeant4PrimaryGeneratorInfo.h @@ -48,7 +48,7 @@ EnergyDistributionTypes StringToEnergyDistributionTypes(const std::string&); enum class EnergyDistributionFormulas { COSMIC_NEUTRONS, - COSMIC_GAMMAS, + COSMIC, }; std::string EnergyDistributionFormulasToString(const EnergyDistributionFormulas&); diff --git a/src/TRestGeant4PrimaryGeneratorInfo.cxx b/src/TRestGeant4PrimaryGeneratorInfo.cxx index 5101473..a082936 100644 --- a/src/TRestGeant4PrimaryGeneratorInfo.cxx +++ b/src/TRestGeant4PrimaryGeneratorInfo.cxx @@ -16,7 +16,7 @@ using namespace std; using namespace TRestGeant4PrimaryGeneratorTypes; -string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypesToString(const SpatialGeneratorTypes& type) { +string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypesToString(const SpatialGeneratorTypes &type) { switch (type) { case SpatialGeneratorTypes::CUSTOM: return "Custom"; @@ -35,7 +35,7 @@ string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypesToString(const Spa exit(1); } -SpatialGeneratorTypes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorTypes(const string& type) { +SpatialGeneratorTypes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorTypes(const string &type) { if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::CUSTOM), TString::ECaseCompare::kIgnoreCase)) { return SpatialGeneratorTypes::CUSTOM; @@ -59,7 +59,7 @@ SpatialGeneratorTypes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGenerator } } -string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorShapesToString(const SpatialGeneratorShapes& type) { +string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorShapesToString(const SpatialGeneratorShapes &type) { switch (type) { case SpatialGeneratorShapes::GDML: return "GDML"; @@ -80,7 +80,7 @@ string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorShapesToString(const Sp exit(1); } -SpatialGeneratorShapes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorShapes(const string& type) { +SpatialGeneratorShapes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorShapes(const string &type) { if (TString(type).EqualTo(SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML), TString::ECaseCompare::kIgnoreCase)) { return SpatialGeneratorShapes::GDML; @@ -109,7 +109,7 @@ SpatialGeneratorShapes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGenerato } string TRestGeant4PrimaryGeneratorTypes::EnergyDistributionTypesToString( - const EnergyDistributionTypes& type) { + const EnergyDistributionTypes &type) { switch (type) { case EnergyDistributionTypes::TH1D: return "TH1D"; @@ -131,7 +131,7 @@ string TRestGeant4PrimaryGeneratorTypes::EnergyDistributionTypesToString( } EnergyDistributionTypes TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionTypes( - const string& type) { + const string &type) { if (TString(type).EqualTo(EnergyDistributionTypesToString(EnergyDistributionTypes::TH1D), TString::ECaseCompare::kIgnoreCase)) { return EnergyDistributionTypes::TH1D; @@ -159,12 +159,12 @@ EnergyDistributionTypes TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistribu } string TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToString( - const EnergyDistributionFormulas& type) { + const EnergyDistributionFormulas &type) { switch (type) { case EnergyDistributionFormulas::COSMIC_NEUTRONS: return "CosmicNeutrons"; - case EnergyDistributionFormulas::COSMIC_GAMMAS: - return "CosmicGammas"; + case EnergyDistributionFormulas::COSMIC: + return "Cosmic"; } cout << "TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToString - Error - Unknown energy " "distribution formula" @@ -173,14 +173,14 @@ string TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToString( } EnergyDistributionFormulas TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionFormulas( - const string& type) { + const string &type) { if (TString(type).EqualTo(EnergyDistributionFormulasToString(EnergyDistributionFormulas::COSMIC_NEUTRONS), TString::ECaseCompare::kIgnoreCase)) { return EnergyDistributionFormulas::COSMIC_NEUTRONS; } else if (TString(type).EqualTo( - EnergyDistributionFormulasToString(EnergyDistributionFormulas::COSMIC_GAMMAS), - TString::ECaseCompare::kIgnoreCase)) { - return EnergyDistributionFormulas::COSMIC_GAMMAS; + EnergyDistributionFormulasToString(EnergyDistributionFormulas::COSMIC), + TString::ECaseCompare::kIgnoreCase)) { + return EnergyDistributionFormulas::COSMIC; } else { cout << "TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionFormulas - Error - Unknown " "energyDistributionFormulas: " @@ -190,25 +190,33 @@ EnergyDistributionFormulas TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistr } TF1 TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToRootFormula( - const EnergyDistributionFormulas& type) { + const EnergyDistributionFormulas &type) { switch (type) { case EnergyDistributionFormulas::COSMIC_NEUTRONS: { // Formula from https://ieeexplore.ieee.org/document/1369506 - const char* title = "Cosmic Neutrons at Sea Level"; + const char *title = "Cosmic Neutrons at Sea Level"; auto distribution = - TF1(title, - "1.006E-6 * TMath::Exp(-0.3500 * TMath::Power(TMath::Log(x * 1E-3), 2) + 2.1451 * " - "TMath::Log(x * 1E-3)) + " - "1.011E-3 * TMath::Exp(-0.4106 * TMath::Power(TMath::Log(x * 1E-3), 2) - 0.6670 * " - "TMath::Log(x * 1E-3))", - 1E2, 1E7); + TF1(title, + "1.006E-6 * TMath::Exp(-0.3500 * TMath::Power(TMath::Log(x * 1E-3), 2) + 2.1451 * " + "TMath::Log(x * 1E-3)) + " + "1.011E-3 * TMath::Exp(-0.4106 * TMath::Power(TMath::Log(x * 1E-3), 2) - 0.6670 * " + "TMath::Log(x * 1E-3))", + 1E2, 1E7); distribution.SetNormalized(true); // Normalized, not really necessary distribution.SetTitle(title); distribution.GetXaxis()->SetTitle("Energy (keV)"); return distribution; } - case EnergyDistributionFormulas::COSMIC_GAMMAS: - exit(1); + case EnergyDistributionFormulas::COSMIC: + const char *title = "Cosmic distribution aproximation"; + auto distribution = + TF1(title, + "TMath::Power(x, -2.7)", + 1E2, 1E9); + distribution.SetNormalized(true); // Normalized, not really necessary + distribution.SetTitle(title); + distribution.GetXaxis()->SetTitle("Energy (keV)"); + return distribution; } cout << "TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToRootFormula - Error - Unknown " "energy distribution formula" @@ -217,7 +225,7 @@ TF1 TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToRootFormula( } string TRestGeant4PrimaryGeneratorTypes::AngularDistributionTypesToString( - const AngularDistributionTypes& type) { + const AngularDistributionTypes &type) { switch (type) { case AngularDistributionTypes::TH1D: return "TH1D"; @@ -239,7 +247,7 @@ string TRestGeant4PrimaryGeneratorTypes::AngularDistributionTypesToString( } AngularDistributionTypes TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionTypes( - const string& type) { + const string &type) { if (TString(type).EqualTo(AngularDistributionTypesToString(AngularDistributionTypes::TH1D), TString::ECaseCompare::kIgnoreCase)) { return AngularDistributionTypes::TH1D; @@ -267,7 +275,7 @@ AngularDistributionTypes TRestGeant4PrimaryGeneratorTypes::StringToAngularDistri } string TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToString( - const AngularDistributionFormulas& type) { + const AngularDistributionFormulas &type) { switch (type) { case AngularDistributionFormulas::COS2: return "Cos2"; @@ -281,7 +289,7 @@ string TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToString( } AngularDistributionFormulas TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionFormulas( - const string& type) { + const string &type) { if (TString(type).EqualTo(AngularDistributionFormulasToString(AngularDistributionFormulas::COS2), TString::ECaseCompare::kIgnoreCase)) { return AngularDistributionFormulas::COS2; @@ -297,28 +305,28 @@ AngularDistributionFormulas TRestGeant4PrimaryGeneratorTypes::StringToAngularDis } TF1 TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToRootFormula( - const AngularDistributionFormulas& type) { + const AngularDistributionFormulas &type) { switch (type) { case AngularDistributionFormulas::COS2: { - auto cos2 = [](double* xs, double* ps) { + auto cos2 = [](double *xs, double *ps) { if (xs[0] >= 0 && xs[0] <= TMath::Pi() / 2) { return TMath::Power(TMath::Cos(xs[0]), 2); } return 0.0; }; - const char* title = "AngularDistribution: Cos2"; + const char *title = "AngularDistribution: Cos2"; auto f = TF1(title, cos2, 0.0, TMath::Pi()); f.SetTitle(title); return f; } case AngularDistributionFormulas::COS3: { - auto cos3 = [](double* xs, double* ps) { + auto cos3 = [](double *xs, double *ps) { if (xs[0] >= 0 && xs[0] <= TMath::Pi() / 2) { return TMath::Power(TMath::Cos(xs[0]), 3); } return 0.0; }; - const char* title = "AngularDistribution: Cos3"; + const char *title = "AngularDistribution: Cos3"; auto f = TF1(title, cos3, 0.0, TMath::Pi()); f.SetTitle(title); return f; @@ -331,7 +339,7 @@ TF1 TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToRootFormula( } string TRestGeant4PrimaryGeneratorTypes::EnergyAndAngularDistributionFormulasToString( - const EnergyAndAngularDistributionFormulas& type) { + const EnergyAndAngularDistributionFormulas &type) { switch (type) { case EnergyAndAngularDistributionFormulas::COSMIC_MUONS: return "CosmicMuons"; @@ -343,7 +351,7 @@ string TRestGeant4PrimaryGeneratorTypes::EnergyAndAngularDistributionFormulasToS } EnergyAndAngularDistributionFormulas -TRestGeant4PrimaryGeneratorTypes::StringToEnergyAndAngularDistributionFormulas(const string& type) { +TRestGeant4PrimaryGeneratorTypes::StringToEnergyAndAngularDistributionFormulas(const string &type) { if (TString(type).EqualTo( EnergyAndAngularDistributionFormulasToString(EnergyAndAngularDistributionFormulas::COSMIC_MUONS), TString::ECaseCompare::kIgnoreCase)) { @@ -357,27 +365,27 @@ TRestGeant4PrimaryGeneratorTypes::StringToEnergyAndAngularDistributionFormulas(c } TF2 TRestGeant4PrimaryGeneratorTypes::EnergyAndAngularDistributionFormulasToRootFormula( - const EnergyAndAngularDistributionFormulas& type) { + const EnergyAndAngularDistributionFormulas &type) { switch (type) { case EnergyAndAngularDistributionFormulas::COSMIC_MUONS: { // Guan formula from https://arxiv.org/pdf/1509.06176.pdf // muon rest mass is 105.7 MeV // energy in keV // already integrated in phi (*2pi): formula returns (counts/cm2/s)/keV/rad(theta) - const char* title = "Cosmic Muons Energy and Angular"; + const char *title = "Cosmic Muons Energy and Angular"; auto f = - TF2(title, - "2*TMath::Pi()*1E-6*0.14*TMath::Power(x*1E-6*(1.+3.64/" - "(x*1E-6*TMath::Power(TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*" - "TMath::Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285)" - ")/(0.982960),0.5),1.29))),-2.7)*(1./" - "(1.+(1.1*x*1E-6*TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*TMath::" - "Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285))/" - "(0.982960),0.5))/115.)+0.054/" - "(1.+(1.1*x*1E-6*TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*TMath::" - "Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285))/" - "(0.982960),0.5))/850.))*(2.*TMath::Sin(y)*TMath::Pi())", - 2.0E5, 5.0E9, 0, TMath::Pi() / 2.); + TF2(title, + "2*TMath::Pi()*1E-6*0.14*TMath::Power(x*1E-6*(1.+3.64/" + "(x*1E-6*TMath::Power(TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*" + "TMath::Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285)" + ")/(0.982960),0.5),1.29))),-2.7)*(1./" + "(1.+(1.1*x*1E-6*TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*TMath::" + "Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285))/" + "(0.982960),0.5))/115.)+0.054/" + "(1.+(1.1*x*1E-6*TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*TMath::" + "Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285))/" + "(0.982960),0.5))/850.))*(2.*TMath::Sin(y)*TMath::Pi())", + 2.0E5, 5.0E9, 0, TMath::Pi() / 2.); f.SetTitle(title); /* * we need to increase the number of bins to get a smooth distribution From 631af89b4c67ea782d77e72ba764ac17969c9d82 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Feb 2023 11:18:31 +0000 Subject: [PATCH 11/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/TRestGeant4PrimaryGeneratorInfo.cxx | 94 ++++++++++++------------- 1 file changed, 45 insertions(+), 49 deletions(-) diff --git a/src/TRestGeant4PrimaryGeneratorInfo.cxx b/src/TRestGeant4PrimaryGeneratorInfo.cxx index a082936..29135a4 100644 --- a/src/TRestGeant4PrimaryGeneratorInfo.cxx +++ b/src/TRestGeant4PrimaryGeneratorInfo.cxx @@ -16,7 +16,7 @@ using namespace std; using namespace TRestGeant4PrimaryGeneratorTypes; -string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypesToString(const SpatialGeneratorTypes &type) { +string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypesToString(const SpatialGeneratorTypes& type) { switch (type) { case SpatialGeneratorTypes::CUSTOM: return "Custom"; @@ -35,7 +35,7 @@ string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypesToString(const Spa exit(1); } -SpatialGeneratorTypes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorTypes(const string &type) { +SpatialGeneratorTypes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorTypes(const string& type) { if (TString(type).EqualTo(SpatialGeneratorTypesToString(SpatialGeneratorTypes::CUSTOM), TString::ECaseCompare::kIgnoreCase)) { return SpatialGeneratorTypes::CUSTOM; @@ -59,7 +59,7 @@ SpatialGeneratorTypes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGenerator } } -string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorShapesToString(const SpatialGeneratorShapes &type) { +string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorShapesToString(const SpatialGeneratorShapes& type) { switch (type) { case SpatialGeneratorShapes::GDML: return "GDML"; @@ -80,7 +80,7 @@ string TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorShapesToString(const Sp exit(1); } -SpatialGeneratorShapes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorShapes(const string &type) { +SpatialGeneratorShapes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorShapes(const string& type) { if (TString(type).EqualTo(SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML), TString::ECaseCompare::kIgnoreCase)) { return SpatialGeneratorShapes::GDML; @@ -109,7 +109,7 @@ SpatialGeneratorShapes TRestGeant4PrimaryGeneratorTypes::StringToSpatialGenerato } string TRestGeant4PrimaryGeneratorTypes::EnergyDistributionTypesToString( - const EnergyDistributionTypes &type) { + const EnergyDistributionTypes& type) { switch (type) { case EnergyDistributionTypes::TH1D: return "TH1D"; @@ -131,7 +131,7 @@ string TRestGeant4PrimaryGeneratorTypes::EnergyDistributionTypesToString( } EnergyDistributionTypes TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionTypes( - const string &type) { + const string& type) { if (TString(type).EqualTo(EnergyDistributionTypesToString(EnergyDistributionTypes::TH1D), TString::ECaseCompare::kIgnoreCase)) { return EnergyDistributionTypes::TH1D; @@ -159,7 +159,7 @@ EnergyDistributionTypes TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistribu } string TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToString( - const EnergyDistributionFormulas &type) { + const EnergyDistributionFormulas& type) { switch (type) { case EnergyDistributionFormulas::COSMIC_NEUTRONS: return "CosmicNeutrons"; @@ -173,13 +173,12 @@ string TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToString( } EnergyDistributionFormulas TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionFormulas( - const string &type) { + const string& type) { if (TString(type).EqualTo(EnergyDistributionFormulasToString(EnergyDistributionFormulas::COSMIC_NEUTRONS), TString::ECaseCompare::kIgnoreCase)) { return EnergyDistributionFormulas::COSMIC_NEUTRONS; - } else if (TString(type).EqualTo( - EnergyDistributionFormulasToString(EnergyDistributionFormulas::COSMIC), - TString::ECaseCompare::kIgnoreCase)) { + } else if (TString(type).EqualTo(EnergyDistributionFormulasToString(EnergyDistributionFormulas::COSMIC), + TString::ECaseCompare::kIgnoreCase)) { return EnergyDistributionFormulas::COSMIC; } else { cout << "TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionFormulas - Error - Unknown " @@ -190,29 +189,26 @@ EnergyDistributionFormulas TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistr } TF1 TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToRootFormula( - const EnergyDistributionFormulas &type) { + const EnergyDistributionFormulas& type) { switch (type) { case EnergyDistributionFormulas::COSMIC_NEUTRONS: { // Formula from https://ieeexplore.ieee.org/document/1369506 - const char *title = "Cosmic Neutrons at Sea Level"; + const char* title = "Cosmic Neutrons at Sea Level"; auto distribution = - TF1(title, - "1.006E-6 * TMath::Exp(-0.3500 * TMath::Power(TMath::Log(x * 1E-3), 2) + 2.1451 * " - "TMath::Log(x * 1E-3)) + " - "1.011E-3 * TMath::Exp(-0.4106 * TMath::Power(TMath::Log(x * 1E-3), 2) - 0.6670 * " - "TMath::Log(x * 1E-3))", - 1E2, 1E7); + TF1(title, + "1.006E-6 * TMath::Exp(-0.3500 * TMath::Power(TMath::Log(x * 1E-3), 2) + 2.1451 * " + "TMath::Log(x * 1E-3)) + " + "1.011E-3 * TMath::Exp(-0.4106 * TMath::Power(TMath::Log(x * 1E-3), 2) - 0.6670 * " + "TMath::Log(x * 1E-3))", + 1E2, 1E7); distribution.SetNormalized(true); // Normalized, not really necessary distribution.SetTitle(title); distribution.GetXaxis()->SetTitle("Energy (keV)"); return distribution; } case EnergyDistributionFormulas::COSMIC: - const char *title = "Cosmic distribution aproximation"; - auto distribution = - TF1(title, - "TMath::Power(x, -2.7)", - 1E2, 1E9); + const char* title = "Cosmic distribution aproximation"; + auto distribution = TF1(title, "TMath::Power(x, -2.7)", 1E2, 1E9); distribution.SetNormalized(true); // Normalized, not really necessary distribution.SetTitle(title); distribution.GetXaxis()->SetTitle("Energy (keV)"); @@ -225,7 +221,7 @@ TF1 TRestGeant4PrimaryGeneratorTypes::EnergyDistributionFormulasToRootFormula( } string TRestGeant4PrimaryGeneratorTypes::AngularDistributionTypesToString( - const AngularDistributionTypes &type) { + const AngularDistributionTypes& type) { switch (type) { case AngularDistributionTypes::TH1D: return "TH1D"; @@ -247,7 +243,7 @@ string TRestGeant4PrimaryGeneratorTypes::AngularDistributionTypesToString( } AngularDistributionTypes TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionTypes( - const string &type) { + const string& type) { if (TString(type).EqualTo(AngularDistributionTypesToString(AngularDistributionTypes::TH1D), TString::ECaseCompare::kIgnoreCase)) { return AngularDistributionTypes::TH1D; @@ -275,7 +271,7 @@ AngularDistributionTypes TRestGeant4PrimaryGeneratorTypes::StringToAngularDistri } string TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToString( - const AngularDistributionFormulas &type) { + const AngularDistributionFormulas& type) { switch (type) { case AngularDistributionFormulas::COS2: return "Cos2"; @@ -289,7 +285,7 @@ string TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToString( } AngularDistributionFormulas TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionFormulas( - const string &type) { + const string& type) { if (TString(type).EqualTo(AngularDistributionFormulasToString(AngularDistributionFormulas::COS2), TString::ECaseCompare::kIgnoreCase)) { return AngularDistributionFormulas::COS2; @@ -305,28 +301,28 @@ AngularDistributionFormulas TRestGeant4PrimaryGeneratorTypes::StringToAngularDis } TF1 TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToRootFormula( - const AngularDistributionFormulas &type) { + const AngularDistributionFormulas& type) { switch (type) { case AngularDistributionFormulas::COS2: { - auto cos2 = [](double *xs, double *ps) { + auto cos2 = [](double* xs, double* ps) { if (xs[0] >= 0 && xs[0] <= TMath::Pi() / 2) { return TMath::Power(TMath::Cos(xs[0]), 2); } return 0.0; }; - const char *title = "AngularDistribution: Cos2"; + const char* title = "AngularDistribution: Cos2"; auto f = TF1(title, cos2, 0.0, TMath::Pi()); f.SetTitle(title); return f; } case AngularDistributionFormulas::COS3: { - auto cos3 = [](double *xs, double *ps) { + auto cos3 = [](double* xs, double* ps) { if (xs[0] >= 0 && xs[0] <= TMath::Pi() / 2) { return TMath::Power(TMath::Cos(xs[0]), 3); } return 0.0; }; - const char *title = "AngularDistribution: Cos3"; + const char* title = "AngularDistribution: Cos3"; auto f = TF1(title, cos3, 0.0, TMath::Pi()); f.SetTitle(title); return f; @@ -339,7 +335,7 @@ TF1 TRestGeant4PrimaryGeneratorTypes::AngularDistributionFormulasToRootFormula( } string TRestGeant4PrimaryGeneratorTypes::EnergyAndAngularDistributionFormulasToString( - const EnergyAndAngularDistributionFormulas &type) { + const EnergyAndAngularDistributionFormulas& type) { switch (type) { case EnergyAndAngularDistributionFormulas::COSMIC_MUONS: return "CosmicMuons"; @@ -351,7 +347,7 @@ string TRestGeant4PrimaryGeneratorTypes::EnergyAndAngularDistributionFormulasToS } EnergyAndAngularDistributionFormulas -TRestGeant4PrimaryGeneratorTypes::StringToEnergyAndAngularDistributionFormulas(const string &type) { +TRestGeant4PrimaryGeneratorTypes::StringToEnergyAndAngularDistributionFormulas(const string& type) { if (TString(type).EqualTo( EnergyAndAngularDistributionFormulasToString(EnergyAndAngularDistributionFormulas::COSMIC_MUONS), TString::ECaseCompare::kIgnoreCase)) { @@ -365,27 +361,27 @@ TRestGeant4PrimaryGeneratorTypes::StringToEnergyAndAngularDistributionFormulas(c } TF2 TRestGeant4PrimaryGeneratorTypes::EnergyAndAngularDistributionFormulasToRootFormula( - const EnergyAndAngularDistributionFormulas &type) { + const EnergyAndAngularDistributionFormulas& type) { switch (type) { case EnergyAndAngularDistributionFormulas::COSMIC_MUONS: { // Guan formula from https://arxiv.org/pdf/1509.06176.pdf // muon rest mass is 105.7 MeV // energy in keV // already integrated in phi (*2pi): formula returns (counts/cm2/s)/keV/rad(theta) - const char *title = "Cosmic Muons Energy and Angular"; + const char* title = "Cosmic Muons Energy and Angular"; auto f = - TF2(title, - "2*TMath::Pi()*1E-6*0.14*TMath::Power(x*1E-6*(1.+3.64/" - "(x*1E-6*TMath::Power(TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*" - "TMath::Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285)" - ")/(0.982960),0.5),1.29))),-2.7)*(1./" - "(1.+(1.1*x*1E-6*TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*TMath::" - "Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285))/" - "(0.982960),0.5))/115.)+0.054/" - "(1.+(1.1*x*1E-6*TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*TMath::" - "Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285))/" - "(0.982960),0.5))/850.))*(2.*TMath::Sin(y)*TMath::Pi())", - 2.0E5, 5.0E9, 0, TMath::Pi() / 2.); + TF2(title, + "2*TMath::Pi()*1E-6*0.14*TMath::Power(x*1E-6*(1.+3.64/" + "(x*1E-6*TMath::Power(TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*" + "TMath::Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285)" + ")/(0.982960),0.5),1.29))),-2.7)*(1./" + "(1.+(1.1*x*1E-6*TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*TMath::" + "Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285))/" + "(0.982960),0.5))/115.)+0.054/" + "(1.+(1.1*x*1E-6*TMath::Power((TMath::Power(TMath::Cos(y),2)+0.0105212-0.068287*TMath::" + "Power(TMath::Cos(y),0.958633)+0.0407253*TMath::Power(TMath::Cos(y),0.817285))/" + "(0.982960),0.5))/850.))*(2.*TMath::Sin(y)*TMath::Pi())", + 2.0E5, 5.0E9, 0, TMath::Pi() / 2.); f.SetTitle(title); /* * we need to increase the number of bins to get a smooth distribution From c1b8ceca872d0254ceb7e2a18a6ed351125de301 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Mon, 27 Feb 2023 17:12:54 +0100 Subject: [PATCH 12/14] add option to save kill volume energy --- inc/TRestGeant4Metadata.h | 54 +++++++------ src/TRestGeant4Metadata.cxx | 157 ++++++++++++++++++------------------ 2 files changed, 110 insertions(+), 101 deletions(-) diff --git a/inc/TRestGeant4Metadata.h b/inc/TRestGeant4Metadata.h index 59e2f72..8b5db88 100644 --- a/inc/TRestGeant4Metadata.h +++ b/inc/TRestGeant4Metadata.h @@ -46,14 +46,14 @@ /// The main class to store the *Geant4* simulation conditions that will be used by *restG4*. class TRestGeant4Metadata : public TRestMetadata { - private: +private: void Initialize() override; void InitFromConfigFile() override; void ReadGenerator(); - void ReadParticleSource(TRestGeant4ParticleSource* src, TiXmlElement* sourceDefinition); + void ReadParticleSource(TRestGeant4ParticleSource *src, TiXmlElement *sourceDefinition); void ReadDetector(); @@ -102,7 +102,7 @@ class TRestGeant4Metadata : public TRestMetadata { std::vector fMaxStepSize; /// \brief It the defines the primary source properties, particle type, momentum, energy, etc. - std::vector fParticleSource; //-> + std::vector fParticleSource; //-> /// \brief The number of biasing volumes used in the simulation. If zero, no biasing technique is used. Int_t fNBiasingVolumes = 0; @@ -158,6 +158,8 @@ class TRestGeant4Metadata : public TRestMetadata { std::set fKillVolumes; + bool fKillVolumesComputeEnergy = false; + /// If this parameter is set to 'true' it will print out on screen every time 10k events are reached. Bool_t fPrintProgress = false; //! @@ -169,23 +171,23 @@ class TRestGeant4Metadata : public TRestMetadata { /// The world magnetic field TVector3 fMagneticField = TVector3(0, 0, 0); - public: +public: std::set fActiveVolumesSet = {}; //! // Used for faster lookup /// \brief Returns the random seed that was used to generate the corresponding geant4 dataset. inline Long_t GetSeed() const { return fSeed; } /// \brief Returns an immutable reference to the geometry info - inline const TRestGeant4GeometryInfo& GetGeant4GeometryInfo() const { return fGeant4GeometryInfo; } + inline const TRestGeant4GeometryInfo &GetGeant4GeometryInfo() const { return fGeant4GeometryInfo; } /// \brief Returns an immutable reference to the physics info - inline const TRestGeant4PhysicsInfo& GetGeant4PhysicsInfo() const { return fGeant4PhysicsInfo; } + inline const TRestGeant4PhysicsInfo &GetGeant4PhysicsInfo() const { return fGeant4PhysicsInfo; } /// \brief Returns an immutable reference to the biasing info - inline const TRestGeant4BiasingInfo& GetGeant4BiasingInfo() const { return fGeant4BiasingInfo; } + inline const TRestGeant4BiasingInfo &GetGeant4BiasingInfo() const { return fGeant4BiasingInfo; } /// \brief Returns an immutable reference to the primary generator info - inline const TRestGeant4PrimaryGeneratorInfo& GetGeant4PrimaryGeneratorInfo() const { + inline const TRestGeant4PrimaryGeneratorInfo &GetGeant4PrimaryGeneratorInfo() const { return fGeant4PrimaryGeneratorInfo; } @@ -235,7 +237,7 @@ class TRestGeant4Metadata : public TRestMetadata { inline void SetSaveAllEvents(const Bool_t value) { fSaveAllEvents = value; } /// Sets the value of the Geant4 version - inline void SetGeant4Version(const TString& versionString) { fGeant4Version = versionString; } + inline void SetGeant4Version(const TString &versionString) { fGeant4Version = versionString; } /// Enables/disables the full chain decay generation. inline void SetFullChain(Bool_t fullChain) { fFullChain = fullChain; } @@ -265,13 +267,13 @@ class TRestGeant4Metadata : public TRestMetadata { inline Int_t GetNumberOfSources() const { return fParticleSource.size(); } /// Returns the name of the particle source with index n (Geant4 based names). - inline TRestGeant4ParticleSource* GetParticleSource(size_t n = 0) const { return fParticleSource[n]; } + inline TRestGeant4ParticleSource *GetParticleSource(size_t n = 0) const { return fParticleSource[n]; } /// Remove all the particle sources. void RemoveParticleSources(); /// Adds a new particle source. - void AddParticleSource(TRestGeant4ParticleSource* src); + void AddParticleSource(TRestGeant4ParticleSource *src); /////////////////////////////////////////////////////////// // Direct access to biasing volumes definition @@ -291,7 +293,7 @@ class TRestGeant4Metadata : public TRestMetadata { inline size_t GetNumberOfSensitiveVolumes() const { return fSensitiveVolumes.size(); } - inline const std::vector& GetSensitiveVolumes() const { return fSensitiveVolumes; } + inline const std::vector &GetSensitiveVolumes() const { return fSensitiveVolumes; } /// Sets the name of the sensitive volume inline void SetNumberOfEvents(Int_t n) { fNEvents = n; } @@ -301,8 +303,8 @@ class TRestGeant4Metadata : public TRestMetadata { inline void SetSimulationMaxTimeSeconds(Int_t seconds) { fSimulationMaxTimeSeconds = seconds; } /// Sets the name of the sensitive volume - inline void InsertSensitiveVolume(const TString& volume) { - for (const auto& sensitiveVolume : fSensitiveVolumes) { + inline void InsertSensitiveVolume(const TString &volume) { + for (const auto &sensitiveVolume: fSensitiveVolumes) { // Do not add duplicate volumes if (volume == sensitiveVolume) { return; @@ -319,7 +321,7 @@ class TRestGeant4Metadata : public TRestMetadata { /// name. Double_t GetStorageChance(TString volume); - Double_t GetMaxStepSize(const TString& volume); + Double_t GetMaxStepSize(const TString &volume); /// Returns the minimum event energy required for an event to be stored. inline Double_t GetMinimumEnergyStored() const { return fEnergyRangeStored.X(); } @@ -331,19 +333,23 @@ class TRestGeant4Metadata : public TRestMetadata { /// selected for data storage. inline unsigned int GetNumberOfActiveVolumes() const { return fActiveVolumes.size(); } - inline bool IsActiveVolume(const char* volumeName) const { + inline bool IsActiveVolume(const char *volumeName) const { return fActiveVolumesSet.count(volumeName) > 0; } //! - inline bool IsKeepTracksVolume(const char* volumeName) const { + inline bool IsKeepTracksVolume(const char *volumeName) const { return fRemoveUnwantedTracksVolumesToKeep.count(volumeName) > 0; } - inline bool IsKillVolume(const char* volumeName) const { return fKillVolumes.count(volumeName) > 0; } + inline bool IsKillVolume(const char *volumeName) const { return fKillVolumes.count(volumeName) > 0; } + + inline bool GetKillVolumesComputeEnergy() const { return fKillVolumesComputeEnergy; } + + void SetKillVolumesComputeEnergy(bool computeEnergy) { fKillVolumesComputeEnergy = computeEnergy; } inline std::vector GetKillVolumes() const { std::vector result; - for (const auto& volume : fKillVolumes) { + for (const auto &volume: fKillVolumes) { result.emplace_back(volume); } return result; @@ -351,7 +357,7 @@ class TRestGeant4Metadata : public TRestMetadata { inline std::vector GetRemoveUnwantedTracksVolumesToKeep() const { std::vector result; - for (const auto& volume : fRemoveUnwantedTracksVolumesToKeep) { + for (const auto &volume: fRemoveUnwantedTracksVolumesToKeep) { result.emplace_back(volume); } return result; @@ -379,19 +385,19 @@ class TRestGeant4Metadata : public TRestMetadata { Int_t GetActiveVolumeID(TString name); - Bool_t isVolumeStored(const TString& volume) const; + Bool_t isVolumeStored(const TString &volume) const; - void SetActiveVolume(const TString& name, Double_t chance, Double_t maxStep = 0); + void SetActiveVolume(const TString &name, Double_t chance, Double_t maxStep = 0); void PrintMetadata() override; TRestGeant4Metadata(); - TRestGeant4Metadata(const char* configFilename, const std::string& name = ""); + TRestGeant4Metadata(const char *configFilename, const std::string &name = ""); ~TRestGeant4Metadata(); - ClassDefOverride(TRestGeant4Metadata, 14); +ClassDefOverride(TRestGeant4Metadata, 14); // Allow modification of otherwise inaccessible / immutable members that shouldn't be modified by the user friend class SteppingAction; diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index 0eb49f7..25155d1 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -758,8 +758,8 @@ TRestGeant4Metadata::TRestGeant4Metadata() : TRestMetadata() { Initialize(); } /// \param name The name of the specific metadata. It will be used to find the /// corresponding TRestGeant4Metadata section inside the RML. /// -TRestGeant4Metadata::TRestGeant4Metadata(const char* configFilename, const string& name) - : TRestMetadata(configFilename) { +TRestGeant4Metadata::TRestGeant4Metadata(const char *configFilename, const string &name) + : TRestMetadata(configFilename) { Initialize(); LoadConfigFromFile(fConfigFileName, name); @@ -808,17 +808,17 @@ void TRestGeant4Metadata::InitFromConfigFile() { if (ToUpper(seedString) == "RANDOM" || ToUpper(seedString) == "RAND" || ToUpper(seedString) == "AUTO" || seedString == "0") { auto dd = new double(); - fSeed = (uintptr_t)dd + (uintptr_t)this; + fSeed = (uintptr_t) dd + (uintptr_t) this; delete dd; } else { - fSeed = (Long_t)StringToInteger(seedString); + fSeed = (Long_t) StringToInteger(seedString); } gRandom->SetSeed(fSeed); // if "gdmlFile" is purely a file (without any path) and "geometryPath" is // defined, we recombine them together - if ((((string)fGdmlFilename).find_first_not_of("./~") == 0 || - ((string)fGdmlFilename).find("/") == string::npos) && + if ((((string) fGdmlFilename).find_first_not_of("./~") == 0 || + ((string) fGdmlFilename).find("/") == string::npos) && fGeometryPath != "") { if (fGeometryPath[fGeometryPath.Length() - 1] == '/') { fGdmlFilename = fGeometryPath + GetParameter("gdmlFile"); @@ -838,7 +838,7 @@ void TRestGeant4Metadata::InitFromConfigFile() { const auto fNRequestedEntriesString = GetParameter("nRequestedEntries"); fNRequestedEntries = - fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); + fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); fSaveAllEvents = ToUpper(GetParameter("saveAllEvents", "false")) == "TRUE" || ToUpper(GetParameter("saveAllEvents", "off")) == "ON"; @@ -846,6 +846,9 @@ void TRestGeant4Metadata::InitFromConfigFile() { fPrintProgress = ToUpper(GetParameter("printProgress", "true")) == "TRUE" || ToUpper(GetParameter("printProgress", "on")) == "ON"; + fKillVolumesComputeEnergy = ToUpper(GetParameter("killVolumesComputeEnergy", "true")) == "TRUE" || + ToUpper(GetParameter("killVolumesComputeEnergy", "on")) == "ON"; + fRegisterEmptyTracks = ToUpper(GetParameter("registerEmptyTracks", "false")) == "TRUE" || ToUpper(GetParameter("registerEmptyTracks", "off")) == "ON"; @@ -905,8 +908,8 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorType().Data()) != TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypes::COSMIC) { RESTError - << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" - << RESTendl; + << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" + << RESTendl; exit(1); } const auto source = GetParticleSource(); @@ -929,10 +932,10 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { const auto energyRange = source->GetEnergyDistributionRange(); const auto angularRange = source->GetAngularDistributionRange(); - auto function = (TF2*)source->GetEnergyAndAngularDistributionFunction()->Clone(); + auto function = (TF2 *) source->GetEnergyAndAngularDistributionFunction()->Clone(); // counts per second per cm2 (distribution is already integrated over uniform phi) const auto countsPerSecondPerCm2 = - function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); + function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); return countsPerSecondPerCm2; } @@ -958,7 +961,7 @@ void TRestGeant4Metadata::ReadBiasing() { */ void TRestGeant4Metadata::ReadBiasing() { - TiXmlElement* biasingDefinition = GetElement("biasing"); + TiXmlElement *biasingDefinition = GetElement("biasing"); if (biasingDefinition == nullptr) { fNBiasingVolumes = 0; fGeant4BiasingInfo.SetEnabled(false); @@ -993,7 +996,7 @@ void TRestGeant4Metadata::ReadBiasing() { const TVector3 center = StringTo3DVector(GetParameter("center", biasingDefinition, "(0,0,0)")); fGeant4BiasingInfo.SetBiasingCenter(center); - TiXmlElement* volumeDefinition = GetElement("volume", biasingDefinition); + TiXmlElement *volumeDefinition = GetElement("volume", biasingDefinition); while (volumeDefinition != nullptr) { string name = GetFieldValue("name", volumeDefinition); if (name.empty() || name == "Not defined") { @@ -1005,14 +1008,14 @@ void TRestGeant4Metadata::ReadBiasing() { } } else { // default implementation - TiXmlElement* biasVolumeDefinition = GetElement("biasingVolume", biasingDefinition); + TiXmlElement *biasVolumeDefinition = GetElement("biasingVolume", biasingDefinition); Int_t n = 0; while (biasVolumeDefinition) { TRestGeant4BiasingVolume biasVolume; RESTDebug << "Def: " << biasVolumeDefinition << RESTendl; biasVolume.SetBiasingVolumePosition( - Get3DVectorParameterWithUnits("position", biasVolumeDefinition)); + Get3DVectorParameterWithUnits("position", biasVolumeDefinition)); biasVolume.SetBiasingFactor(StringToDouble(GetParameter("factor", biasVolumeDefinition))); biasVolume.SetBiasingVolumeSize(GetDblParameterWithUnits("size", biasVolumeDefinition)); biasVolume.SetEnergyRange(Get2DVectorParameterWithUnits("energyRange", biasVolumeDefinition)); @@ -1060,35 +1063,35 @@ void TRestGeant4Metadata::ReadGenerator() { // center of the volume (i.e. gasTarget) but if i.e rotation or side are // defined and not relevant we should set it to -1 - TiXmlElement* generatorDefinition = GetElement("generator"); + TiXmlElement *generatorDefinition = GetElement("generator"); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorType = - SpatialGeneratorTypesToString(StringToSpatialGeneratorTypes(GetParameter( - "type", generatorDefinition, SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME)))); + SpatialGeneratorTypesToString(StringToSpatialGeneratorTypes(GetParameter( + "type", generatorDefinition, SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME)))); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorShape = - SpatialGeneratorShapesToString(StringToSpatialGeneratorShapes(GetParameter( - "shape", generatorDefinition, SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX)))); + SpatialGeneratorShapesToString(StringToSpatialGeneratorShapes(GetParameter( + "shape", generatorDefinition, SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX)))); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorFrom = GetParameter("from", generatorDefinition); if (fGeant4PrimaryGeneratorInfo.fSpatialGeneratorFrom != PARAMETER_NOT_FOUND_STR) { fGeant4PrimaryGeneratorInfo.fSpatialGeneratorShape = - SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML); + SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML); } fGeant4PrimaryGeneratorInfo.fSpatialGeneratorSize = - Get3DVectorParameterWithUnits("size", generatorDefinition, {0, 0, 0}); + Get3DVectorParameterWithUnits("size", generatorDefinition, {0, 0, 0}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorPosition = - Get3DVectorParameterWithUnits("position", generatorDefinition, {0, 0, 0}); + Get3DVectorParameterWithUnits("position", generatorDefinition, {0, 0, 0}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorRotationAxis = - Get3DVectorParameterWithUnits("rotationAxis", generatorDefinition, {0, 0, 1}); + Get3DVectorParameterWithUnits("rotationAxis", generatorDefinition, {0, 0, 1}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorRotationValue = - GetDblParameterWithUnits("rotationAngle", generatorDefinition, 0); + GetDblParameterWithUnits("rotationAngle", generatorDefinition, 0); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorSpatialDensityFunction = - GetParameter("densityFunc", generatorDefinition, "1"); + GetParameter("densityFunc", generatorDefinition, "1"); - TiXmlElement* sourceDefinition = GetElement("source", generatorDefinition); + TiXmlElement *sourceDefinition = GetElement("source", generatorDefinition); while (sourceDefinition) { string use = GetParameter("use", sourceDefinition, ""); - TRestGeant4ParticleSource* source = TRestGeant4ParticleSource::instantiate(use); + TRestGeant4ParticleSource *source = TRestGeant4ParticleSource::instantiate(use); ReadParticleSource(source, sourceDefinition); AddParticleSource(source); @@ -1105,8 +1108,8 @@ void TRestGeant4Metadata::ReadGenerator() { /////////////////////////////////////////////// /// \brief It reads the SetParticleName(GetParameter("particle", sourceDefinition)); source->SetExcitationLevel(StringToDouble(GetParameter("excitedLevel", sourceDefinition))); @@ -1119,12 +1122,12 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, } // Angular distribution parameters - TiXmlElement* angularDefinition = GetElement("angular", sourceDefinition); + TiXmlElement *angularDefinition = GetElement("angular", sourceDefinition); if (angularDefinition == nullptr) { angularDefinition = GetElement("angularDist", sourceDefinition); // old name } source->SetAngularDistributionType(GetParameter( - "type", angularDefinition, AngularDistributionTypesToString(AngularDistributionTypes::FLUX))); + "type", angularDefinition, AngularDistributionTypesToString(AngularDistributionTypes::FLUX))); if (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::TH1D) { source->SetAngularDistributionFilename(SearchFile(GetParameter("file", angularDefinition))); @@ -1135,7 +1138,7 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, source->SetAngularDistributionNameInFile(name); } source->SetAngularDistributionRange( - Get2DVectorParameterWithUnits("range", angularDefinition, {0, TMath::Pi()})); + Get2DVectorParameterWithUnits("range", angularDefinition, {0, TMath::Pi()})); if (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::FORMULA) { source->SetAngularDistributionFormula(GetParameter("name", angularDefinition)); @@ -1143,11 +1146,11 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, const auto function = source->GetAngularDistributionFunction(); if (source->GetAngularDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetAngularDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); } if (source->GetAngularDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetAngularDistributionRange( - {source->GetAngularDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetAngularDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } } if ((StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == @@ -1155,24 +1158,24 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::FORMULA2)) { source->SetAngularDistributionFormulaNPoints(static_cast(GetDblParameterWithUnits( - "nPoints", angularDefinition, source->GetAngularDistributionFormulaNPoints()))); + "nPoints", angularDefinition, source->GetAngularDistributionFormulaNPoints()))); } if (GetNumberOfSources() == 0 && StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == - AngularDistributionTypes::BACK_TO_BACK) { + AngularDistributionTypes::BACK_TO_BACK) { cout << "WARNING: First source cannot be backtoback. Setting it to isotropic" << endl; source->SetAngularDistributionType( - AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC)); + AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC)); } source->SetDirection(StringTo3DVector(GetParameter("direction", angularDefinition, "(1,0,0)"))); // Energy distribution parameters - TiXmlElement* energyDefinition = GetElement("energy", sourceDefinition); + TiXmlElement *energyDefinition = GetElement("energy", sourceDefinition); if (energyDefinition == nullptr) { energyDefinition = GetElement("energyDist", sourceDefinition); // old name } source->SetEnergyDistributionType(GetParameter( - "type", energyDefinition, EnergyDistributionTypesToString(EnergyDistributionTypes::MONO))); + "type", energyDefinition, EnergyDistributionTypesToString(EnergyDistributionTypes::MONO))); if (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == EnergyDistributionTypes::TH1D) { source->SetEnergyDistributionFilename(SearchFile(GetParameter("file", energyDefinition))); @@ -1197,11 +1200,11 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, const auto function = source->GetEnergyDistributionFunction(); if (source->GetEnergyDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetEnergyDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); } if (source->GetEnergyDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetEnergyDistributionRange( - {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } } if ((StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == @@ -1209,12 +1212,12 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == EnergyDistributionTypes::FORMULA2)) { source->SetEnergyDistributionFormulaNPoints(static_cast(GetDblParameterWithUnits( - "nPoints", energyDefinition, source->GetEnergyDistributionFormulaNPoints()))); + "nPoints", energyDefinition, source->GetEnergyDistributionFormulaNPoints()))); } if (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == - EnergyDistributionTypes::FORMULA2 && + EnergyDistributionTypes::FORMULA2 && StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == - AngularDistributionTypes::FORMULA2) { + AngularDistributionTypes::FORMULA2) { const auto empty = TString(""); auto energyDistName = GetParameter("name", energyDefinition, empty); auto angularDistName = GetParameter("name", energyDefinition, empty); @@ -1247,21 +1250,21 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, // Set energy range if (source->GetEnergyDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetEnergyDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); } if (source->GetEnergyDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetEnergyDistributionRange( - {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } // Set angular range if (source->GetAngularDistributionRangeMin() < function->GetYaxis()->GetXmin()) { source->SetAngularDistributionRange( - {function->GetYaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); + {function->GetYaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); } if (source->GetAngularDistributionRangeMax() > function->GetYaxis()->GetXmax()) { source->SetAngularDistributionRange( - {source->GetAngularDistributionRangeMin(), function->GetYaxis()->GetXmax()}); + {source->GetAngularDistributionRangeMin(), function->GetYaxis()->GetXmax()}); } } // allow custom configuration from the class @@ -1270,13 +1273,13 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource* source, } void TRestGeant4Metadata::RemoveParticleSources() { - for (auto source : fParticleSource) { + for (auto source: fParticleSource) { delete source; } fParticleSource.clear(); } -void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource* src) { +void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource *src) { fParticleSource.push_back(src); } @@ -1296,22 +1299,22 @@ void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource* src) { /// void TRestGeant4Metadata::ReadDetector() { RESTInfo << "TRestGeant4Metadata: Processing detector section" << RESTendl; - TiXmlElement* detectorDefinition = GetElement("detector"); + TiXmlElement *detectorDefinition = GetElement("detector"); if (detectorDefinition == nullptr) { RESTError << "Detector section () is not present in metadata!" << RESTendl; exit(1); } const bool activateAllVolumes = - StringToBool(GetParameter("activateAllVolumes", detectorDefinition, "true")); + StringToBool(GetParameter("activateAllVolumes", detectorDefinition, "true")); RESTInfo << "TRestGeant4Metadata: Setting 'fActivateAllVolumes' to " << fActivateAllVolumes << RESTendl; fActivateAllVolumes = activateAllVolumes; - TiXmlElement* removeUnwantedTracksDefinition = GetElement("removeUnwantedTracks", detectorDefinition); + TiXmlElement *removeUnwantedTracksDefinition = GetElement("removeUnwantedTracks", detectorDefinition); if (removeUnwantedTracksDefinition != nullptr) { fRemoveUnwantedTracks = StringToBool(GetParameter("enabled", removeUnwantedTracksDefinition, "true")); fRemoveUnwantedTracksKeepZeroEnergyTracks = - StringToBool(GetParameter("keepZeroEnergyTracks", removeUnwantedTracksDefinition, "false")); + StringToBool(GetParameter("keepZeroEnergyTracks", removeUnwantedTracksDefinition, "false")); RESTInfo << "TRestGeant4Metadata: Setting 'fRemoveUnwantedTracks' to " << fRemoveUnwantedTracks << " with 'keepZeroEnergyTracks' option set to " << fRemoveUnwantedTracksKeepZeroEnergyTracks << RESTendl; @@ -1322,7 +1325,7 @@ void TRestGeant4Metadata::ReadDetector() { defaultStep = 0; } - TiXmlElement* volumeDefinition = GetElement("volume", detectorDefinition); + TiXmlElement *volumeDefinition = GetElement("volume", detectorDefinition); while (volumeDefinition != nullptr) { string name = GetFieldValue("name", volumeDefinition); if (name.empty() || name == "Not defined") { @@ -1332,25 +1335,25 @@ void TRestGeant4Metadata::ReadDetector() { vector physicalVolumes; if (!fGeant4GeometryInfo.IsValidGdmlName(name)) { if (fGeant4GeometryInfo.IsValidLogicalVolume(name)) { - for (const auto& physical : fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(name)) { + for (const auto &physical: fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(name)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } // does not match a explicit (gdml) physical name or a logical name, perhaps its a regular exp if (physicalVolumes.empty()) { - for (const auto& physical : - fGeant4GeometryInfo.GetAllPhysicalVolumesMatchingExpression(name)) { + for (const auto &physical: + fGeant4GeometryInfo.GetAllPhysicalVolumesMatchingExpression(name)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } if (physicalVolumes.empty()) { - for (const auto& logical : fGeant4GeometryInfo.GetAllLogicalVolumesMatchingExpression(name)) { - for (const auto& physical : - fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(logical)) { + for (const auto &logical: fGeant4GeometryInfo.GetAllLogicalVolumesMatchingExpression(name)) { + for (const auto &physical: + fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(logical)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } } @@ -1360,9 +1363,9 @@ void TRestGeant4Metadata::ReadDetector() { if (physicalVolumes.empty()) { RESTError - << "volume '" << name - << "' is not defined in the geometry. Could not match to a physical, logical volume or regex" - << RESTendl; + << "volume '" << name + << "' is not defined in the geometry. Could not match to a physical, logical volume or regex" + << RESTendl; exit(1); } @@ -1393,7 +1396,7 @@ void TRestGeant4Metadata::ReadDetector() { maxStep = defaultStep; } - for (const auto& physical : physicalVolumes) { + for (const auto &physical: physicalVolumes) { RESTInfo << "Adding " << (isSensitive ? "sensitive" : "active") << " volume from RML: '" << physical << (chance != 1 ? " with change: " + to_string(chance) : " ") << RESTendl; SetActiveVolume(physical, chance, maxStep); @@ -1440,7 +1443,7 @@ void TRestGeant4Metadata::ReadDetector() { // If the user did not add explicitly any volume to the storage section we understand // the user wants to register all the volumes if (fActivateAllVolumes) { - for (const auto& name : fGeant4GeometryInfo.GetAllPhysicalVolumes()) { + for (const auto &name: fGeant4GeometryInfo.GetAllPhysicalVolumes()) { if (!IsActiveVolume(name)) { SetActiveVolume(name, 1, defaultStep); RESTInfo << "Automatically adding active volume: '" << name << "' with chance: " << 1 @@ -1490,7 +1493,7 @@ void TRestGeant4Metadata::PrintMetadata() { RESTMetadata << "Energy range (keV): (" << GetMinimumEnergyStored() << ", " << GetMaximumEnergyStored() << ")" << RESTendl; RESTMetadata << "Number of sensitive volumes: " << GetNumberOfSensitiveVolumes() << RESTendl; - for (const auto& sensitiveVolume : fSensitiveVolumes) { + for (const auto &sensitiveVolume: fSensitiveVolumes) { RESTMetadata << "Sensitive volume: " << sensitiveVolume << RESTendl; } RESTMetadata << "Number of active volumes: " << GetNumberOfActiveVolumes() << RESTendl; @@ -1525,7 +1528,7 @@ void TRestGeant4Metadata::PrintMetadata() { /// \brief Returns the id of an active volume giving as parameter its name. Int_t TRestGeant4Metadata::GetActiveVolumeID(TString name) { Int_t id; - for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { + for (id = 0; id < (Int_t) fActiveVolumes.size(); id++) { if (fActiveVolumes[id] == name) return id; } return -1; @@ -1545,7 +1548,7 @@ Int_t TRestGeant4Metadata::GetActiveVolumeID(TString name) { /// The aim of this parameter is to define control volumes. Usually the volume /// of interest will be always registered (chance=1). /// -void TRestGeant4Metadata::SetActiveVolume(const TString& name, Double_t chance, Double_t maxStep) { +void TRestGeant4Metadata::SetActiveVolume(const TString &name, Double_t chance, Double_t maxStep) { for (size_t i = 0; i < fActiveVolumes.size(); i++) { const auto activeVolumeName = fActiveVolumes[i]; if (name == activeVolumeName) { @@ -1564,7 +1567,7 @@ void TRestGeant4Metadata::SetActiveVolume(const TString& name, Double_t chance, /// \brief Returns true if the volume named *volName* has been registered for /// data storage. /// -Bool_t TRestGeant4Metadata::isVolumeStored(const TString& volume) const { +Bool_t TRestGeant4Metadata::isVolumeStored(const TString &volume) const { for (unsigned int n = 0; n < GetNumberOfActiveVolumes(); n++) if (GetActiveVolumeName(n) == volume) return true; @@ -1576,7 +1579,7 @@ Bool_t TRestGeant4Metadata::isVolumeStored(const TString& volume) const { /// Double_t TRestGeant4Metadata::GetStorageChance(TString volume) { Int_t id; - for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { + for (id = 0; id < (Int_t) fActiveVolumes.size(); id++) { if (fActiveVolumes[id] == volume) return fChance[id]; } RESTWarning << "TRestGeant4Metadata::GetStorageChance. Volume " << volume << " not found" << RESTendl; @@ -1587,8 +1590,8 @@ Double_t TRestGeant4Metadata::GetStorageChance(TString volume) { /////////////////////////////////////////////// /// \brief Returns the maximum step at a particular active volume /// -Double_t TRestGeant4Metadata::GetMaxStepSize(const TString& volume) { - for (Int_t i = 0; i < (Int_t)fActiveVolumes.size(); i++) { +Double_t TRestGeant4Metadata::GetMaxStepSize(const TString &volume) { + for (Int_t i = 0; i < (Int_t) fActiveVolumes.size(); i++) { if (volume.EqualTo(fActiveVolumes[i], TString::kIgnoreCase)) { return fMaxStepSize[i]; } From ead68a1cc988ae1654c03abc36fea78693732215 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Feb 2023 16:13:06 +0000 Subject: [PATCH 13/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- inc/TRestGeant4Metadata.h | 48 +++++------ src/TRestGeant4Metadata.cxx | 154 ++++++++++++++++++------------------ 2 files changed, 101 insertions(+), 101 deletions(-) diff --git a/inc/TRestGeant4Metadata.h b/inc/TRestGeant4Metadata.h index 8b5db88..6542d2e 100644 --- a/inc/TRestGeant4Metadata.h +++ b/inc/TRestGeant4Metadata.h @@ -46,14 +46,14 @@ /// The main class to store the *Geant4* simulation conditions that will be used by *restG4*. class TRestGeant4Metadata : public TRestMetadata { -private: + private: void Initialize() override; void InitFromConfigFile() override; void ReadGenerator(); - void ReadParticleSource(TRestGeant4ParticleSource *src, TiXmlElement *sourceDefinition); + void ReadParticleSource(TRestGeant4ParticleSource* src, TiXmlElement* sourceDefinition); void ReadDetector(); @@ -102,7 +102,7 @@ class TRestGeant4Metadata : public TRestMetadata { std::vector fMaxStepSize; /// \brief It the defines the primary source properties, particle type, momentum, energy, etc. - std::vector fParticleSource; //-> + std::vector fParticleSource; //-> /// \brief The number of biasing volumes used in the simulation. If zero, no biasing technique is used. Int_t fNBiasingVolumes = 0; @@ -171,23 +171,23 @@ class TRestGeant4Metadata : public TRestMetadata { /// The world magnetic field TVector3 fMagneticField = TVector3(0, 0, 0); -public: + public: std::set fActiveVolumesSet = {}; //! // Used for faster lookup /// \brief Returns the random seed that was used to generate the corresponding geant4 dataset. inline Long_t GetSeed() const { return fSeed; } /// \brief Returns an immutable reference to the geometry info - inline const TRestGeant4GeometryInfo &GetGeant4GeometryInfo() const { return fGeant4GeometryInfo; } + inline const TRestGeant4GeometryInfo& GetGeant4GeometryInfo() const { return fGeant4GeometryInfo; } /// \brief Returns an immutable reference to the physics info - inline const TRestGeant4PhysicsInfo &GetGeant4PhysicsInfo() const { return fGeant4PhysicsInfo; } + inline const TRestGeant4PhysicsInfo& GetGeant4PhysicsInfo() const { return fGeant4PhysicsInfo; } /// \brief Returns an immutable reference to the biasing info - inline const TRestGeant4BiasingInfo &GetGeant4BiasingInfo() const { return fGeant4BiasingInfo; } + inline const TRestGeant4BiasingInfo& GetGeant4BiasingInfo() const { return fGeant4BiasingInfo; } /// \brief Returns an immutable reference to the primary generator info - inline const TRestGeant4PrimaryGeneratorInfo &GetGeant4PrimaryGeneratorInfo() const { + inline const TRestGeant4PrimaryGeneratorInfo& GetGeant4PrimaryGeneratorInfo() const { return fGeant4PrimaryGeneratorInfo; } @@ -237,7 +237,7 @@ class TRestGeant4Metadata : public TRestMetadata { inline void SetSaveAllEvents(const Bool_t value) { fSaveAllEvents = value; } /// Sets the value of the Geant4 version - inline void SetGeant4Version(const TString &versionString) { fGeant4Version = versionString; } + inline void SetGeant4Version(const TString& versionString) { fGeant4Version = versionString; } /// Enables/disables the full chain decay generation. inline void SetFullChain(Bool_t fullChain) { fFullChain = fullChain; } @@ -267,13 +267,13 @@ class TRestGeant4Metadata : public TRestMetadata { inline Int_t GetNumberOfSources() const { return fParticleSource.size(); } /// Returns the name of the particle source with index n (Geant4 based names). - inline TRestGeant4ParticleSource *GetParticleSource(size_t n = 0) const { return fParticleSource[n]; } + inline TRestGeant4ParticleSource* GetParticleSource(size_t n = 0) const { return fParticleSource[n]; } /// Remove all the particle sources. void RemoveParticleSources(); /// Adds a new particle source. - void AddParticleSource(TRestGeant4ParticleSource *src); + void AddParticleSource(TRestGeant4ParticleSource* src); /////////////////////////////////////////////////////////// // Direct access to biasing volumes definition @@ -293,7 +293,7 @@ class TRestGeant4Metadata : public TRestMetadata { inline size_t GetNumberOfSensitiveVolumes() const { return fSensitiveVolumes.size(); } - inline const std::vector &GetSensitiveVolumes() const { return fSensitiveVolumes; } + inline const std::vector& GetSensitiveVolumes() const { return fSensitiveVolumes; } /// Sets the name of the sensitive volume inline void SetNumberOfEvents(Int_t n) { fNEvents = n; } @@ -303,8 +303,8 @@ class TRestGeant4Metadata : public TRestMetadata { inline void SetSimulationMaxTimeSeconds(Int_t seconds) { fSimulationMaxTimeSeconds = seconds; } /// Sets the name of the sensitive volume - inline void InsertSensitiveVolume(const TString &volume) { - for (const auto &sensitiveVolume: fSensitiveVolumes) { + inline void InsertSensitiveVolume(const TString& volume) { + for (const auto& sensitiveVolume : fSensitiveVolumes) { // Do not add duplicate volumes if (volume == sensitiveVolume) { return; @@ -321,7 +321,7 @@ class TRestGeant4Metadata : public TRestMetadata { /// name. Double_t GetStorageChance(TString volume); - Double_t GetMaxStepSize(const TString &volume); + Double_t GetMaxStepSize(const TString& volume); /// Returns the minimum event energy required for an event to be stored. inline Double_t GetMinimumEnergyStored() const { return fEnergyRangeStored.X(); } @@ -333,15 +333,15 @@ class TRestGeant4Metadata : public TRestMetadata { /// selected for data storage. inline unsigned int GetNumberOfActiveVolumes() const { return fActiveVolumes.size(); } - inline bool IsActiveVolume(const char *volumeName) const { + inline bool IsActiveVolume(const char* volumeName) const { return fActiveVolumesSet.count(volumeName) > 0; } //! - inline bool IsKeepTracksVolume(const char *volumeName) const { + inline bool IsKeepTracksVolume(const char* volumeName) const { return fRemoveUnwantedTracksVolumesToKeep.count(volumeName) > 0; } - inline bool IsKillVolume(const char *volumeName) const { return fKillVolumes.count(volumeName) > 0; } + inline bool IsKillVolume(const char* volumeName) const { return fKillVolumes.count(volumeName) > 0; } inline bool GetKillVolumesComputeEnergy() const { return fKillVolumesComputeEnergy; } @@ -349,7 +349,7 @@ class TRestGeant4Metadata : public TRestMetadata { inline std::vector GetKillVolumes() const { std::vector result; - for (const auto &volume: fKillVolumes) { + for (const auto& volume : fKillVolumes) { result.emplace_back(volume); } return result; @@ -357,7 +357,7 @@ class TRestGeant4Metadata : public TRestMetadata { inline std::vector GetRemoveUnwantedTracksVolumesToKeep() const { std::vector result; - for (const auto &volume: fRemoveUnwantedTracksVolumesToKeep) { + for (const auto& volume : fRemoveUnwantedTracksVolumesToKeep) { result.emplace_back(volume); } return result; @@ -385,19 +385,19 @@ class TRestGeant4Metadata : public TRestMetadata { Int_t GetActiveVolumeID(TString name); - Bool_t isVolumeStored(const TString &volume) const; + Bool_t isVolumeStored(const TString& volume) const; - void SetActiveVolume(const TString &name, Double_t chance, Double_t maxStep = 0); + void SetActiveVolume(const TString& name, Double_t chance, Double_t maxStep = 0); void PrintMetadata() override; TRestGeant4Metadata(); - TRestGeant4Metadata(const char *configFilename, const std::string &name = ""); + TRestGeant4Metadata(const char* configFilename, const std::string& name = ""); ~TRestGeant4Metadata(); -ClassDefOverride(TRestGeant4Metadata, 14); + ClassDefOverride(TRestGeant4Metadata, 14); // Allow modification of otherwise inaccessible / immutable members that shouldn't be modified by the user friend class SteppingAction; diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index 25155d1..b8a5418 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -758,8 +758,8 @@ TRestGeant4Metadata::TRestGeant4Metadata() : TRestMetadata() { Initialize(); } /// \param name The name of the specific metadata. It will be used to find the /// corresponding TRestGeant4Metadata section inside the RML. /// -TRestGeant4Metadata::TRestGeant4Metadata(const char *configFilename, const string &name) - : TRestMetadata(configFilename) { +TRestGeant4Metadata::TRestGeant4Metadata(const char* configFilename, const string& name) + : TRestMetadata(configFilename) { Initialize(); LoadConfigFromFile(fConfigFileName, name); @@ -808,17 +808,17 @@ void TRestGeant4Metadata::InitFromConfigFile() { if (ToUpper(seedString) == "RANDOM" || ToUpper(seedString) == "RAND" || ToUpper(seedString) == "AUTO" || seedString == "0") { auto dd = new double(); - fSeed = (uintptr_t) dd + (uintptr_t) this; + fSeed = (uintptr_t)dd + (uintptr_t)this; delete dd; } else { - fSeed = (Long_t) StringToInteger(seedString); + fSeed = (Long_t)StringToInteger(seedString); } gRandom->SetSeed(fSeed); // if "gdmlFile" is purely a file (without any path) and "geometryPath" is // defined, we recombine them together - if ((((string) fGdmlFilename).find_first_not_of("./~") == 0 || - ((string) fGdmlFilename).find("/") == string::npos) && + if ((((string)fGdmlFilename).find_first_not_of("./~") == 0 || + ((string)fGdmlFilename).find("/") == string::npos) && fGeometryPath != "") { if (fGeometryPath[fGeometryPath.Length() - 1] == '/') { fGdmlFilename = fGeometryPath + GetParameter("gdmlFile"); @@ -838,7 +838,7 @@ void TRestGeant4Metadata::InitFromConfigFile() { const auto fNRequestedEntriesString = GetParameter("nRequestedEntries"); fNRequestedEntries = - fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); + fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); fSaveAllEvents = ToUpper(GetParameter("saveAllEvents", "false")) == "TRUE" || ToUpper(GetParameter("saveAllEvents", "off")) == "ON"; @@ -908,8 +908,8 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorType().Data()) != TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypes::COSMIC) { RESTError - << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" - << RESTendl; + << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" + << RESTendl; exit(1); } const auto source = GetParticleSource(); @@ -932,10 +932,10 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { const auto energyRange = source->GetEnergyDistributionRange(); const auto angularRange = source->GetAngularDistributionRange(); - auto function = (TF2 *) source->GetEnergyAndAngularDistributionFunction()->Clone(); + auto function = (TF2*)source->GetEnergyAndAngularDistributionFunction()->Clone(); // counts per second per cm2 (distribution is already integrated over uniform phi) const auto countsPerSecondPerCm2 = - function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); + function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); return countsPerSecondPerCm2; } @@ -961,7 +961,7 @@ void TRestGeant4Metadata::ReadBiasing() { */ void TRestGeant4Metadata::ReadBiasing() { - TiXmlElement *biasingDefinition = GetElement("biasing"); + TiXmlElement* biasingDefinition = GetElement("biasing"); if (biasingDefinition == nullptr) { fNBiasingVolumes = 0; fGeant4BiasingInfo.SetEnabled(false); @@ -996,7 +996,7 @@ void TRestGeant4Metadata::ReadBiasing() { const TVector3 center = StringTo3DVector(GetParameter("center", biasingDefinition, "(0,0,0)")); fGeant4BiasingInfo.SetBiasingCenter(center); - TiXmlElement *volumeDefinition = GetElement("volume", biasingDefinition); + TiXmlElement* volumeDefinition = GetElement("volume", biasingDefinition); while (volumeDefinition != nullptr) { string name = GetFieldValue("name", volumeDefinition); if (name.empty() || name == "Not defined") { @@ -1008,14 +1008,14 @@ void TRestGeant4Metadata::ReadBiasing() { } } else { // default implementation - TiXmlElement *biasVolumeDefinition = GetElement("biasingVolume", biasingDefinition); + TiXmlElement* biasVolumeDefinition = GetElement("biasingVolume", biasingDefinition); Int_t n = 0; while (biasVolumeDefinition) { TRestGeant4BiasingVolume biasVolume; RESTDebug << "Def: " << biasVolumeDefinition << RESTendl; biasVolume.SetBiasingVolumePosition( - Get3DVectorParameterWithUnits("position", biasVolumeDefinition)); + Get3DVectorParameterWithUnits("position", biasVolumeDefinition)); biasVolume.SetBiasingFactor(StringToDouble(GetParameter("factor", biasVolumeDefinition))); biasVolume.SetBiasingVolumeSize(GetDblParameterWithUnits("size", biasVolumeDefinition)); biasVolume.SetEnergyRange(Get2DVectorParameterWithUnits("energyRange", biasVolumeDefinition)); @@ -1063,35 +1063,35 @@ void TRestGeant4Metadata::ReadGenerator() { // center of the volume (i.e. gasTarget) but if i.e rotation or side are // defined and not relevant we should set it to -1 - TiXmlElement *generatorDefinition = GetElement("generator"); + TiXmlElement* generatorDefinition = GetElement("generator"); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorType = - SpatialGeneratorTypesToString(StringToSpatialGeneratorTypes(GetParameter( - "type", generatorDefinition, SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME)))); + SpatialGeneratorTypesToString(StringToSpatialGeneratorTypes(GetParameter( + "type", generatorDefinition, SpatialGeneratorTypesToString(SpatialGeneratorTypes::VOLUME)))); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorShape = - SpatialGeneratorShapesToString(StringToSpatialGeneratorShapes(GetParameter( - "shape", generatorDefinition, SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX)))); + SpatialGeneratorShapesToString(StringToSpatialGeneratorShapes(GetParameter( + "shape", generatorDefinition, SpatialGeneratorShapesToString(SpatialGeneratorShapes::BOX)))); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorFrom = GetParameter("from", generatorDefinition); if (fGeant4PrimaryGeneratorInfo.fSpatialGeneratorFrom != PARAMETER_NOT_FOUND_STR) { fGeant4PrimaryGeneratorInfo.fSpatialGeneratorShape = - SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML); + SpatialGeneratorShapesToString(SpatialGeneratorShapes::GDML); } fGeant4PrimaryGeneratorInfo.fSpatialGeneratorSize = - Get3DVectorParameterWithUnits("size", generatorDefinition, {0, 0, 0}); + Get3DVectorParameterWithUnits("size", generatorDefinition, {0, 0, 0}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorPosition = - Get3DVectorParameterWithUnits("position", generatorDefinition, {0, 0, 0}); + Get3DVectorParameterWithUnits("position", generatorDefinition, {0, 0, 0}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorRotationAxis = - Get3DVectorParameterWithUnits("rotationAxis", generatorDefinition, {0, 0, 1}); + Get3DVectorParameterWithUnits("rotationAxis", generatorDefinition, {0, 0, 1}); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorRotationValue = - GetDblParameterWithUnits("rotationAngle", generatorDefinition, 0); + GetDblParameterWithUnits("rotationAngle", generatorDefinition, 0); fGeant4PrimaryGeneratorInfo.fSpatialGeneratorSpatialDensityFunction = - GetParameter("densityFunc", generatorDefinition, "1"); + GetParameter("densityFunc", generatorDefinition, "1"); - TiXmlElement *sourceDefinition = GetElement("source", generatorDefinition); + TiXmlElement* sourceDefinition = GetElement("source", generatorDefinition); while (sourceDefinition) { string use = GetParameter("use", sourceDefinition, ""); - TRestGeant4ParticleSource *source = TRestGeant4ParticleSource::instantiate(use); + TRestGeant4ParticleSource* source = TRestGeant4ParticleSource::instantiate(use); ReadParticleSource(source, sourceDefinition); AddParticleSource(source); @@ -1108,8 +1108,8 @@ void TRestGeant4Metadata::ReadGenerator() { /////////////////////////////////////////////// /// \brief It reads the SetParticleName(GetParameter("particle", sourceDefinition)); source->SetExcitationLevel(StringToDouble(GetParameter("excitedLevel", sourceDefinition))); @@ -1122,12 +1122,12 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, } // Angular distribution parameters - TiXmlElement *angularDefinition = GetElement("angular", sourceDefinition); + TiXmlElement* angularDefinition = GetElement("angular", sourceDefinition); if (angularDefinition == nullptr) { angularDefinition = GetElement("angularDist", sourceDefinition); // old name } source->SetAngularDistributionType(GetParameter( - "type", angularDefinition, AngularDistributionTypesToString(AngularDistributionTypes::FLUX))); + "type", angularDefinition, AngularDistributionTypesToString(AngularDistributionTypes::FLUX))); if (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::TH1D) { source->SetAngularDistributionFilename(SearchFile(GetParameter("file", angularDefinition))); @@ -1138,7 +1138,7 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, source->SetAngularDistributionNameInFile(name); } source->SetAngularDistributionRange( - Get2DVectorParameterWithUnits("range", angularDefinition, {0, TMath::Pi()})); + Get2DVectorParameterWithUnits("range", angularDefinition, {0, TMath::Pi()})); if (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::FORMULA) { source->SetAngularDistributionFormula(GetParameter("name", angularDefinition)); @@ -1146,11 +1146,11 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, const auto function = source->GetAngularDistributionFunction(); if (source->GetAngularDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetAngularDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); } if (source->GetAngularDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetAngularDistributionRange( - {source->GetAngularDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetAngularDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } } if ((StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == @@ -1158,24 +1158,24 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, (StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == AngularDistributionTypes::FORMULA2)) { source->SetAngularDistributionFormulaNPoints(static_cast(GetDblParameterWithUnits( - "nPoints", angularDefinition, source->GetAngularDistributionFormulaNPoints()))); + "nPoints", angularDefinition, source->GetAngularDistributionFormulaNPoints()))); } if (GetNumberOfSources() == 0 && StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == - AngularDistributionTypes::BACK_TO_BACK) { + AngularDistributionTypes::BACK_TO_BACK) { cout << "WARNING: First source cannot be backtoback. Setting it to isotropic" << endl; source->SetAngularDistributionType( - AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC)); + AngularDistributionTypesToString(AngularDistributionTypes::ISOTROPIC)); } source->SetDirection(StringTo3DVector(GetParameter("direction", angularDefinition, "(1,0,0)"))); // Energy distribution parameters - TiXmlElement *energyDefinition = GetElement("energy", sourceDefinition); + TiXmlElement* energyDefinition = GetElement("energy", sourceDefinition); if (energyDefinition == nullptr) { energyDefinition = GetElement("energyDist", sourceDefinition); // old name } source->SetEnergyDistributionType(GetParameter( - "type", energyDefinition, EnergyDistributionTypesToString(EnergyDistributionTypes::MONO))); + "type", energyDefinition, EnergyDistributionTypesToString(EnergyDistributionTypes::MONO))); if (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == EnergyDistributionTypes::TH1D) { source->SetEnergyDistributionFilename(SearchFile(GetParameter("file", energyDefinition))); @@ -1200,11 +1200,11 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, const auto function = source->GetEnergyDistributionFunction(); if (source->GetEnergyDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetEnergyDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); } if (source->GetEnergyDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetEnergyDistributionRange( - {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } } if ((StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == @@ -1212,12 +1212,12 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == EnergyDistributionTypes::FORMULA2)) { source->SetEnergyDistributionFormulaNPoints(static_cast(GetDblParameterWithUnits( - "nPoints", energyDefinition, source->GetEnergyDistributionFormulaNPoints()))); + "nPoints", energyDefinition, source->GetEnergyDistributionFormulaNPoints()))); } if (StringToEnergyDistributionTypes(source->GetEnergyDistributionType().Data()) == - EnergyDistributionTypes::FORMULA2 && + EnergyDistributionTypes::FORMULA2 && StringToAngularDistributionTypes(source->GetAngularDistributionType().Data()) == - AngularDistributionTypes::FORMULA2) { + AngularDistributionTypes::FORMULA2) { const auto empty = TString(""); auto energyDistName = GetParameter("name", energyDefinition, empty); auto angularDistName = GetParameter("name", energyDefinition, empty); @@ -1250,21 +1250,21 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, // Set energy range if (source->GetEnergyDistributionRangeMin() < function->GetXaxis()->GetXmin()) { source->SetEnergyDistributionRange( - {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); + {function->GetXaxis()->GetXmin(), source->GetEnergyDistributionRangeMax()}); } if (source->GetEnergyDistributionRangeMax() > function->GetXaxis()->GetXmax()) { source->SetEnergyDistributionRange( - {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); + {source->GetEnergyDistributionRangeMin(), function->GetXaxis()->GetXmax()}); } // Set angular range if (source->GetAngularDistributionRangeMin() < function->GetYaxis()->GetXmin()) { source->SetAngularDistributionRange( - {function->GetYaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); + {function->GetYaxis()->GetXmin(), source->GetAngularDistributionRangeMax()}); } if (source->GetAngularDistributionRangeMax() > function->GetYaxis()->GetXmax()) { source->SetAngularDistributionRange( - {source->GetAngularDistributionRangeMin(), function->GetYaxis()->GetXmax()}); + {source->GetAngularDistributionRangeMin(), function->GetYaxis()->GetXmax()}); } } // allow custom configuration from the class @@ -1273,13 +1273,13 @@ void TRestGeant4Metadata::ReadParticleSource(TRestGeant4ParticleSource *source, } void TRestGeant4Metadata::RemoveParticleSources() { - for (auto source: fParticleSource) { + for (auto source : fParticleSource) { delete source; } fParticleSource.clear(); } -void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource *src) { +void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource* src) { fParticleSource.push_back(src); } @@ -1299,22 +1299,22 @@ void TRestGeant4Metadata::AddParticleSource(TRestGeant4ParticleSource *src) { /// void TRestGeant4Metadata::ReadDetector() { RESTInfo << "TRestGeant4Metadata: Processing detector section" << RESTendl; - TiXmlElement *detectorDefinition = GetElement("detector"); + TiXmlElement* detectorDefinition = GetElement("detector"); if (detectorDefinition == nullptr) { RESTError << "Detector section () is not present in metadata!" << RESTendl; exit(1); } const bool activateAllVolumes = - StringToBool(GetParameter("activateAllVolumes", detectorDefinition, "true")); + StringToBool(GetParameter("activateAllVolumes", detectorDefinition, "true")); RESTInfo << "TRestGeant4Metadata: Setting 'fActivateAllVolumes' to " << fActivateAllVolumes << RESTendl; fActivateAllVolumes = activateAllVolumes; - TiXmlElement *removeUnwantedTracksDefinition = GetElement("removeUnwantedTracks", detectorDefinition); + TiXmlElement* removeUnwantedTracksDefinition = GetElement("removeUnwantedTracks", detectorDefinition); if (removeUnwantedTracksDefinition != nullptr) { fRemoveUnwantedTracks = StringToBool(GetParameter("enabled", removeUnwantedTracksDefinition, "true")); fRemoveUnwantedTracksKeepZeroEnergyTracks = - StringToBool(GetParameter("keepZeroEnergyTracks", removeUnwantedTracksDefinition, "false")); + StringToBool(GetParameter("keepZeroEnergyTracks", removeUnwantedTracksDefinition, "false")); RESTInfo << "TRestGeant4Metadata: Setting 'fRemoveUnwantedTracks' to " << fRemoveUnwantedTracks << " with 'keepZeroEnergyTracks' option set to " << fRemoveUnwantedTracksKeepZeroEnergyTracks << RESTendl; @@ -1325,7 +1325,7 @@ void TRestGeant4Metadata::ReadDetector() { defaultStep = 0; } - TiXmlElement *volumeDefinition = GetElement("volume", detectorDefinition); + TiXmlElement* volumeDefinition = GetElement("volume", detectorDefinition); while (volumeDefinition != nullptr) { string name = GetFieldValue("name", volumeDefinition); if (name.empty() || name == "Not defined") { @@ -1335,25 +1335,25 @@ void TRestGeant4Metadata::ReadDetector() { vector physicalVolumes; if (!fGeant4GeometryInfo.IsValidGdmlName(name)) { if (fGeant4GeometryInfo.IsValidLogicalVolume(name)) { - for (const auto &physical: fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(name)) { + for (const auto& physical : fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(name)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } // does not match a explicit (gdml) physical name or a logical name, perhaps its a regular exp if (physicalVolumes.empty()) { - for (const auto &physical: - fGeant4GeometryInfo.GetAllPhysicalVolumesMatchingExpression(name)) { + for (const auto& physical : + fGeant4GeometryInfo.GetAllPhysicalVolumesMatchingExpression(name)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } if (physicalVolumes.empty()) { - for (const auto &logical: fGeant4GeometryInfo.GetAllLogicalVolumesMatchingExpression(name)) { - for (const auto &physical: - fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(logical)) { + for (const auto& logical : fGeant4GeometryInfo.GetAllLogicalVolumesMatchingExpression(name)) { + for (const auto& physical : + fGeant4GeometryInfo.GetAllPhysicalVolumesFromLogical(logical)) { physicalVolumes.emplace_back( - fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); + fGeant4GeometryInfo.GetAlternativeNameFromGeant4PhysicalName(physical)); } } } @@ -1363,9 +1363,9 @@ void TRestGeant4Metadata::ReadDetector() { if (physicalVolumes.empty()) { RESTError - << "volume '" << name - << "' is not defined in the geometry. Could not match to a physical, logical volume or regex" - << RESTendl; + << "volume '" << name + << "' is not defined in the geometry. Could not match to a physical, logical volume or regex" + << RESTendl; exit(1); } @@ -1396,7 +1396,7 @@ void TRestGeant4Metadata::ReadDetector() { maxStep = defaultStep; } - for (const auto &physical: physicalVolumes) { + for (const auto& physical : physicalVolumes) { RESTInfo << "Adding " << (isSensitive ? "sensitive" : "active") << " volume from RML: '" << physical << (chance != 1 ? " with change: " + to_string(chance) : " ") << RESTendl; SetActiveVolume(physical, chance, maxStep); @@ -1443,7 +1443,7 @@ void TRestGeant4Metadata::ReadDetector() { // If the user did not add explicitly any volume to the storage section we understand // the user wants to register all the volumes if (fActivateAllVolumes) { - for (const auto &name: fGeant4GeometryInfo.GetAllPhysicalVolumes()) { + for (const auto& name : fGeant4GeometryInfo.GetAllPhysicalVolumes()) { if (!IsActiveVolume(name)) { SetActiveVolume(name, 1, defaultStep); RESTInfo << "Automatically adding active volume: '" << name << "' with chance: " << 1 @@ -1493,7 +1493,7 @@ void TRestGeant4Metadata::PrintMetadata() { RESTMetadata << "Energy range (keV): (" << GetMinimumEnergyStored() << ", " << GetMaximumEnergyStored() << ")" << RESTendl; RESTMetadata << "Number of sensitive volumes: " << GetNumberOfSensitiveVolumes() << RESTendl; - for (const auto &sensitiveVolume: fSensitiveVolumes) { + for (const auto& sensitiveVolume : fSensitiveVolumes) { RESTMetadata << "Sensitive volume: " << sensitiveVolume << RESTendl; } RESTMetadata << "Number of active volumes: " << GetNumberOfActiveVolumes() << RESTendl; @@ -1528,7 +1528,7 @@ void TRestGeant4Metadata::PrintMetadata() { /// \brief Returns the id of an active volume giving as parameter its name. Int_t TRestGeant4Metadata::GetActiveVolumeID(TString name) { Int_t id; - for (id = 0; id < (Int_t) fActiveVolumes.size(); id++) { + for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { if (fActiveVolumes[id] == name) return id; } return -1; @@ -1548,7 +1548,7 @@ Int_t TRestGeant4Metadata::GetActiveVolumeID(TString name) { /// The aim of this parameter is to define control volumes. Usually the volume /// of interest will be always registered (chance=1). /// -void TRestGeant4Metadata::SetActiveVolume(const TString &name, Double_t chance, Double_t maxStep) { +void TRestGeant4Metadata::SetActiveVolume(const TString& name, Double_t chance, Double_t maxStep) { for (size_t i = 0; i < fActiveVolumes.size(); i++) { const auto activeVolumeName = fActiveVolumes[i]; if (name == activeVolumeName) { @@ -1567,7 +1567,7 @@ void TRestGeant4Metadata::SetActiveVolume(const TString &name, Double_t chance, /// \brief Returns true if the volume named *volName* has been registered for /// data storage. /// -Bool_t TRestGeant4Metadata::isVolumeStored(const TString &volume) const { +Bool_t TRestGeant4Metadata::isVolumeStored(const TString& volume) const { for (unsigned int n = 0; n < GetNumberOfActiveVolumes(); n++) if (GetActiveVolumeName(n) == volume) return true; @@ -1579,7 +1579,7 @@ Bool_t TRestGeant4Metadata::isVolumeStored(const TString &volume) const { /// Double_t TRestGeant4Metadata::GetStorageChance(TString volume) { Int_t id; - for (id = 0; id < (Int_t) fActiveVolumes.size(); id++) { + for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { if (fActiveVolumes[id] == volume) return fChance[id]; } RESTWarning << "TRestGeant4Metadata::GetStorageChance. Volume " << volume << " not found" << RESTendl; @@ -1590,8 +1590,8 @@ Double_t TRestGeant4Metadata::GetStorageChance(TString volume) { /////////////////////////////////////////////// /// \brief Returns the maximum step at a particular active volume /// -Double_t TRestGeant4Metadata::GetMaxStepSize(const TString &volume) { - for (Int_t i = 0; i < (Int_t) fActiveVolumes.size(); i++) { +Double_t TRestGeant4Metadata::GetMaxStepSize(const TString& volume) { + for (Int_t i = 0; i < (Int_t)fActiveVolumes.size(); i++) { if (volume.EqualTo(fActiveVolumes[i], TString::kIgnoreCase)) { return fMaxStepSize[i]; } From d291dfbc97d4c556a1391a81c95067fbdb9cdcf2 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Tue, 28 Feb 2023 10:35:56 +0100 Subject: [PATCH 14/14] working biasing example --- src/TRestGeant4Metadata.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index b8a5418..917b193 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -624,6 +624,8 @@ /// to stop a track after entering the volume. The track will be immediately killed and its energy deposition /// won't be computed. This is useful to speed up certain kinds of simulations. /// +/// If "killVolumesComputeEnergy" option is enabled, +/// the energy deposition in the volumes marked as kill will be computed towards the sensitive volume. /// ## 4. The biasing volumes section (optional) /// /// The REST Geant4 toolkit (*restG4*) implements a particular biasing