From 9882b05114c53da5b9371f5a3953f70b338ffcba Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Thu, 30 May 2024 11:35:28 +0200 Subject: [PATCH 01/13] measure wall time --- inc/TRestGeant4Event.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/inc/TRestGeant4Event.h b/inc/TRestGeant4Event.h index 8e68e6d..9bb220e 100644 --- a/inc/TRestGeant4Event.h +++ b/inc/TRestGeant4Event.h @@ -119,6 +119,9 @@ class TRestGeant4Event : public TRestEvent { Double_t fTotalDepositedEnergy = 0; Double_t fSensitiveVolumeEnergy = 0; + double fEventTimeWall = 0; + double fEventTimeWallPrimaryGeneration = 0; + Int_t fNVolumes; std::vector fVolumeStored; std::vector fVolumeStoredNames; @@ -150,6 +153,9 @@ class TRestGeant4Event : public TRestEvent { size_t GetNumberOfHits(Int_t volID = -1) const; size_t GetNumberOfPhysicalHits(Int_t volID = -1) const; + double GetEventTimeWall() const { return fEventTimeWall; } + double GetEventTimeWallPrimaryGeneration() const { return fEventTimeWallPrimaryGeneration; } + inline const std::vector& GetTracks() const { return fTracks; } inline size_t GetNumberOfTracks() const { return fTracks.size(); } inline Int_t GetNumberOfActiveVolumes() const { return fNVolumes; } @@ -244,7 +250,7 @@ class TRestGeant4Event : public TRestEvent { // Destructor virtual ~TRestGeant4Event(); - ClassDefOverride(TRestGeant4Event, 8); // REST event superclass + ClassDefOverride(TRestGeant4Event, 9); // REST event superclass // restG4 public: From f23030ddd730ca5d3ca62d2377a1296fed6f2d35 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 8 Jun 2024 17:33:18 +0200 Subject: [PATCH 02/13] style --- src/TRestGeant4Event.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/TRestGeant4Event.cxx b/src/TRestGeant4Event.cxx index 36c3a1a..9d4ad94 100644 --- a/src/TRestGeant4Event.cxx +++ b/src/TRestGeant4Event.cxx @@ -181,9 +181,11 @@ TVector3 TRestGeant4Event::GetFirstPositionInVolume(Int_t volID) const { /// \param volID Int_t specifying volume ID /// TVector3 TRestGeant4Event::GetLastPositionInVolume(Int_t volID) const { - for (int t = GetNumberOfTracks() - 1; t >= 0; t--) - if (GetTrack(t).GetEnergyInVolume(volID) > 0) return GetTrack(t).GetLastPositionInVolume(volID); - + for (int t = GetNumberOfTracks() - 1; t >= 0; t--) { + if (GetTrack(t).GetEnergyInVolume(volID) > 0) { + return GetTrack(t).GetLastPositionInVolume(volID); + } + } Double_t nan = TMath::QuietNaN(); return {nan, nan, nan}; } From 8d501f85050da184b3e6dd0f0ffad957be56ba55 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Mon, 10 Jun 2024 08:43:37 +0200 Subject: [PATCH 03/13] timing --- inc/TRestGeant4Event.h | 2 ++ inc/TRestGeant4Metadata.h | 7 ++++++- src/TRestGeant4Metadata.cxx | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/inc/TRestGeant4Event.h b/inc/TRestGeant4Event.h index 9bb220e..418ba15 100644 --- a/inc/TRestGeant4Event.h +++ b/inc/TRestGeant4Event.h @@ -186,6 +186,8 @@ class TRestGeant4Event : public TRestEvent { return energyMap[volumeName]; } + inline void ClearTracks() { fTracks.clear(); } + TRestHits GetHits(Int_t volID = -1) const; inline TRestHits GetHitsInVolume(Int_t volID) const { return GetHits(volID); } diff --git a/inc/TRestGeant4Metadata.h b/inc/TRestGeant4Metadata.h index f9f6c33..d14004f 100644 --- a/inc/TRestGeant4Metadata.h +++ b/inc/TRestGeant4Metadata.h @@ -153,6 +153,9 @@ class TRestGeant4Metadata : public TRestMetadata { /// \brief If activated will remove tracks not present in volumes marked as "keep" or "sensitive". Bool_t fRemoveUnwantedTracks = false; + /// \brief Store event tracks (default is true) + Bool_t fStoreTracks = false; + /// \brief Option for 'removeUnwantedTracks', if enabled tracks with hits in volumes will be kept event if /// they deposit zero energy (such as neutron captures) Bool_t fRemoveUnwantedTracksKeepZeroEnergyTracks = false; @@ -380,6 +383,8 @@ class TRestGeant4Metadata : public TRestMetadata { inline bool GetRemoveUnwantedTracks() const { return fRemoveUnwantedTracks; } + bool GetStoreTracks() const { return fStoreTracks; } + inline bool GetRemoveUnwantedTracksKeepZeroEnergyTracks() const { return fRemoveUnwantedTracksKeepZeroEnergyTracks; } @@ -407,7 +412,7 @@ class TRestGeant4Metadata : public TRestMetadata { TRestGeant4Metadata(const TRestGeant4Metadata& metadata); TRestGeant4Metadata& operator=(const TRestGeant4Metadata& metadata); - ClassDefOverride(TRestGeant4Metadata, 18); + ClassDefOverride(TRestGeant4Metadata, 19); // 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 527b890..ac8cdeb 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -856,6 +856,9 @@ void TRestGeant4Metadata::InitFromConfigFile() { } fNEvents = nEventsString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(nEventsString); + fStoreTracks = ToUpper(GetParameter("storeTracks", "true")) == "TRUE" || + ToUpper(GetParameter("storeTracks", "on")) == "ON"; + const auto fNRequestedEntriesString = GetParameter("nRequestedEntries"); fNRequestedEntries = fNRequestedEntriesString == PARAMETER_NOT_FOUND_STR ? 0 : StringToInteger(fNRequestedEntriesString); @@ -1647,6 +1650,7 @@ TRestGeant4Metadata& TRestGeant4Metadata::operator=(const TRestGeant4Metadata& m fSensitiveVolumes = metadata.fSensitiveVolumes; fNEvents = metadata.fNEvents; fNRequestedEntries = metadata.fNRequestedEntries; + fStoreTracks = metadata.fStoreTracks; fSimulationMaxTimeSeconds = metadata.fSimulationMaxTimeSeconds; fSeed = metadata.fSeed; fSaveAllEvents = metadata.fSaveAllEvents; From 3977d394dd58f6e3e5d546e81fe9b12d86747873 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Thu, 20 Jun 2024 13:49:41 +0200 Subject: [PATCH 04/13] compute time --- inc/TRestGeant4Metadata.h | 2 + inc/TRestGeant4ParticleSourceCosmics.h | 1 + src/TRestGeant4Metadata.cxx | 103 +++++++++++++++++-------- 3 files changed, 72 insertions(+), 34 deletions(-) diff --git a/inc/TRestGeant4Metadata.h b/inc/TRestGeant4Metadata.h index d14004f..c1ae045 100644 --- a/inc/TRestGeant4Metadata.h +++ b/inc/TRestGeant4Metadata.h @@ -372,6 +372,8 @@ class TRestGeant4Metadata : public TRestMetadata { return result; } + double GetGeneratorSurfaceCm2() const; + Double_t GetCosmicFluxInCountsPerCm2PerSecond() const; Double_t GetCosmicIntensityInCountsPerSecond() const; Double_t GetEquivalentSimulatedTime() const; diff --git a/inc/TRestGeant4ParticleSourceCosmics.h b/inc/TRestGeant4ParticleSourceCosmics.h index c21b061..80858cd 100644 --- a/inc/TRestGeant4ParticleSourceCosmics.h +++ b/inc/TRestGeant4ParticleSourceCosmics.h @@ -30,6 +30,7 @@ class TRestGeant4ParticleSourceCosmics : public TRestGeant4ParticleSource { const char* GetName() const override { return "TRestGeant4ParticleSourceCosmics"; } std::map GetHistogramsTransformed() const { return fHistogramsTransformed; } + std::set GetParticleNames() const { return fParticleNames; } ClassDefOverride(TRestGeant4ParticleSourceCosmics, 2); }; diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index ac8cdeb..0bc4620 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -924,44 +924,54 @@ void TRestGeant4Metadata::InitFromConfigFile() { /// Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { - if (TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorTypes( - fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorType().Data()) != - TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypes::COSMIC) { - RESTError - << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'cosmic' generator" - << RESTendl; - exit(1); - } const auto source = GetParticleSource(); + + double countsPerSecondPerCm2 = 0; if (TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionTypes( - source->GetEnergyDistributionType().Data()) != - TRestGeant4PrimaryGeneratorTypes::EnergyDistributionTypes::FORMULA2) { - RESTError << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'formula2' " - "energy distribution" - << RESTendl; - exit(1); + source->GetEnergyDistributionType().Data()) == + TRestGeant4PrimaryGeneratorTypes::EnergyDistributionTypes::FORMULA2 && + TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionTypes( + source->GetAngularDistributionType().Data()) == + TRestGeant4PrimaryGeneratorTypes::AngularDistributionTypes::FORMULA2) { + const auto energyRange = source->GetEnergyDistributionRange(); + const auto angularRange = source->GetAngularDistributionRange(); + auto function = (TF2*)source->GetEnergyAndAngularDistributionFunction()->Clone(); + // counts per second per cm2 (distribution is already integrated over uniform phi) + countsPerSecondPerCm2 = + function->Integral(energyRange.X(), energyRange.Y(), angularRange.X(), angularRange.Y(), 1E-9); } - if (TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionTypes( - source->GetAngularDistributionType().Data()) != - TRestGeant4PrimaryGeneratorTypes::AngularDistributionTypes::FORMULA2) { - RESTError << "TRestGeant4Metadata::GetEquivalentSimulatedTime can only be called for 'formula' " - "angular distribution" - << RESTendl; - exit(1); + + else if (std::string(source->GetName()) == "TRestGeant4ParticleSourceCosmics") { + auto cosmicSource = dynamic_cast(source); + const auto names = cosmicSource->GetParticleNames(); + const auto histograms = cosmicSource->GetHistogramsTransformed(); + for (const auto& name : names) { + countsPerSecondPerCm2 += histograms.at(name)->Integral(); + } + } else if (TRestGeant4PrimaryGeneratorTypes::StringToEnergyDistributionTypes( + source->GetEnergyDistributionType().Data()) == + TRestGeant4PrimaryGeneratorTypes::EnergyDistributionTypes::TH2D && + TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionTypes( + source->GetAngularDistributionType().Data()) == + TRestGeant4PrimaryGeneratorTypes::AngularDistributionTypes::TH2D) { + if (TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorTypes( + fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorType().Data()) != + TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypes::COSMIC) { + throw std::runtime_error( + "Cosmic flux calculation is only supported for COSMIC spatial generator"); + } + } + + else { + throw std::runtime_error("Cosmic flux calculation is only supported for TFormula2 or TH2D sources"); } - const auto energyRange = source->GetEnergyDistributionRange(); - const auto angularRange = source->GetAngularDistributionRange(); - 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); return countsPerSecondPerCm2; } Double_t TRestGeant4Metadata::GetCosmicIntensityInCountsPerSecond() const { const auto countsPerSecondPerCm2 = GetCosmicFluxInCountsPerCm2PerSecond(); - const auto surface = fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorCosmicSurfaceTermCm2(); + const auto surface = GetGeneratorSurfaceCm2(); const auto countsPerSecond = countsPerSecondPerCm2 * surface; return countsPerSecond; } @@ -1568,13 +1578,33 @@ void TRestGeant4Metadata::SetActiveVolume(const TString& name, Double_t chance, fActiveVolumesSet.insert(name.Data()); } +double TRestGeant4Metadata::GetGeneratorSurfaceCm2() const { + const auto type = ToLower(fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorType()); + const auto shape = ToLower(fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorShape()); + + if (type == "surface" && shape == "circle") { + const auto radius = fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorSize().X(); + return TMath::Pi() * radius * radius; + } + if (type == "cosmic") { + return fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorCosmicSurfaceTermCm2(); + } + + throw std::runtime_error( + "TRestGeant4Metadata::GetGeneratorSurfaceCm2: Can only be called for 'cosmic' and 'surface/circle' " + "generators"); +} + /////////////////////////////////////////////// /// \brief Returns true if the volume named *volName* has been registered for /// data storage. /// Bool_t TRestGeant4Metadata::isVolumeStored(const TString& volume) const { - for (unsigned int n = 0; n < GetNumberOfActiveVolumes(); n++) - if (GetActiveVolumeName(n) == volume) return true; + for (auto n = 0; n < GetNumberOfActiveVolumes(); n++) { + if (GetActiveVolumeName(n) == volume) { + return true; + } + } return false; } @@ -1583,9 +1613,12 @@ Bool_t TRestGeant4Metadata::isVolumeStored(const TString& volume) const { /// \brief Returns the probability of an active volume being stored /// Double_t TRestGeant4Metadata::GetStorageChance(const TString& volume) { - Int_t id; - for (id = 0; id < (Int_t)fActiveVolumes.size(); id++) { - if (fActiveVolumes[id] == volume) return fChance[id]; + for (auto id = 0; id < (Int_t)fActiveVolumes.size(); id++) { + { + if (fActiveVolumes[id] == volume) { + return fChance[id]; + } + } } RESTWarning << "TRestGeant4Metadata::GetStorageChance. Volume " << volume << " not found" << RESTendl; @@ -1627,7 +1660,9 @@ void TRestGeant4Metadata::Merge(const TRestGeant4Metadata& metadata) { fSimulationTime += metadata.fSimulationTime; } -TRestGeant4Metadata::TRestGeant4Metadata(const TRestGeant4Metadata& metadata) { *this = metadata; } +TRestGeant4Metadata::TRestGeant4Metadata(const TRestGeant4Metadata& metadata) : TRestMetadata(metadata) { + *this = metadata; +} TRestGeant4Metadata& TRestGeant4Metadata::operator=(const TRestGeant4Metadata& metadata) { fIsMerge = metadata.fIsMerge; From cbe6e91e4978f837b42ea0902948f8c5734fac54 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:50:00 +0000 Subject: [PATCH 05/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- inc/TRestGeant4Metadata.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/TRestGeant4Metadata.h b/inc/TRestGeant4Metadata.h index c1ae045..9541701 100644 --- a/inc/TRestGeant4Metadata.h +++ b/inc/TRestGeant4Metadata.h @@ -373,7 +373,7 @@ class TRestGeant4Metadata : public TRestMetadata { } double GetGeneratorSurfaceCm2() const; - + Double_t GetCosmicFluxInCountsPerCm2PerSecond() const; Double_t GetCosmicIntensityInCountsPerSecond() const; Double_t GetEquivalentSimulatedTime() const; From bcaa5a60cc7d24d18c28ce7ecc7129db18fad75f Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Thu, 20 Jun 2024 16:36:47 +0200 Subject: [PATCH 06/13] comp --- src/TRestGeant4Metadata.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index 0bc4620..997279c 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -1600,7 +1600,7 @@ double TRestGeant4Metadata::GetGeneratorSurfaceCm2() const { /// data storage. /// Bool_t TRestGeant4Metadata::isVolumeStored(const TString& volume) const { - for (auto n = 0; n < GetNumberOfActiveVolumes(); n++) { + for (unsigned int n = 0; n < GetNumberOfActiveVolumes(); n++) { if (GetActiveVolumeName(n) == volume) { return true; } From 504fecd949593175cb429a5ff902562b0671b3ae Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Thu, 20 Jun 2024 20:36:21 +0200 Subject: [PATCH 07/13] bad simulations --- inc/TRestGeant4PrimaryGeneratorInfo.h | 4 ++-- src/TRestGeant4Metadata.cxx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/TRestGeant4PrimaryGeneratorInfo.h b/inc/TRestGeant4PrimaryGeneratorInfo.h index 239d3b4..ff4eded 100644 --- a/inc/TRestGeant4PrimaryGeneratorInfo.h +++ b/inc/TRestGeant4PrimaryGeneratorInfo.h @@ -164,8 +164,8 @@ class TRestGeant4PrimaryGeneratorInfo { /// \brief Returns cosmic surface term (cm2) for simulation time computation inline Double_t GetSpatialGeneratorCosmicSurfaceTermCm2() const { - const auto radius = GetSpatialGeneratorCosmicRadius() / 10.; - return M_PI * radius * radius; + const auto radius = GetSpatialGeneratorCosmicRadius(); + return M_PI * radius * radius * 0.01; // cm2 } /// \brief Returns the density function of the generator diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index 997279c..4ba307f 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -1584,7 +1584,7 @@ double TRestGeant4Metadata::GetGeneratorSurfaceCm2() const { if (type == "surface" && shape == "circle") { const auto radius = fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorSize().X(); - return TMath::Pi() * radius * radius; + return TMath::Pi() * radius * radius * 0.01; // cm2 } if (type == "cosmic") { return fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorCosmicSurfaceTermCm2(); From a91c40d08870315ea3b6a27a87b8bfbefd4dfa1a Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Tue, 25 Jun 2024 12:06:39 +0200 Subject: [PATCH 08/13] simulation time --- inc/TRestGeant4Metadata.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/inc/TRestGeant4Metadata.h b/inc/TRestGeant4Metadata.h index 9541701..e400bdb 100644 --- a/inc/TRestGeant4Metadata.h +++ b/inc/TRestGeant4Metadata.h @@ -133,7 +133,7 @@ class TRestGeant4Metadata : public TRestMetadata { /// \brief Time before simulation is ended and saved Double_t fSimulationMaxTimeSeconds = 0; - /// \brief The time, in seconds, that the simulation took to complete. + /// \brief The time, in seconds, that the simulation took to complete (wall time) Double_t fSimulationTime = 0; /// \brief The seed value used for Geant4 random event generator. @@ -272,8 +272,6 @@ class TRestGeant4Metadata : public TRestMetadata { inline Double_t GetSimulationMaxTimeSeconds() const { return fSimulationMaxTimeSeconds; } - inline Double_t GetSimulationTime() const { return fSimulationTime; } - // Direct access to sources definition in primary generator /////////////////////////////////////////////////////////// /// Returns the number of primary event sources defined in the generator. @@ -376,8 +374,13 @@ class TRestGeant4Metadata : public TRestMetadata { Double_t GetCosmicFluxInCountsPerCm2PerSecond() const; Double_t GetCosmicIntensityInCountsPerSecond() const; + + /// Returns the equivalent simulated time in seconds (physical time simulated) Double_t GetEquivalentSimulatedTime() const; + /// Returns the total time of the simulation in seconds (wall time) + inline Double_t GetSimulationWallTime() const { return fSimulationTime; } + /// Returns a std::string with the name of the active volume with index n inline TString GetActiveVolumeName(Int_t n) const { return fActiveVolumes[n]; } @@ -400,7 +403,7 @@ class TRestGeant4Metadata : public TRestMetadata { void SetActiveVolume(const TString& name, Double_t chance, Double_t maxStep = 0); - void SetSimulationTime(Double_t time) { fSimulationTime = time; } + void SetSimulationWallTime(Double_t time) { fSimulationTime = time; } void PrintMetadata() override; From ef7fb155be25cb5a0f2d92239ed906a197855e58 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Tue, 25 Jun 2024 12:07:03 +0200 Subject: [PATCH 09/13] merge --- macros/REST_Geant4_MergeRestG4Files.C | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/macros/REST_Geant4_MergeRestG4Files.C b/macros/REST_Geant4_MergeRestG4Files.C index 3cf1b77..c381dc6 100644 --- a/macros/REST_Geant4_MergeRestG4Files.C +++ b/macros/REST_Geant4_MergeRestG4Files.C @@ -50,15 +50,15 @@ void REST_Geant4_MergeRestG4Files(const char* outputFilename, const char* inputF // open the first file TRestGeant4Metadata mergeMetadata; - auto mergeRun = new TRestRun(); - mergeRun->SetName("run"); - mergeRun->SetOutputFileName(outputFilename); - mergeRun->FormOutputFile(); - mergeRun->GetOutputFile()->cd(); - mergeRun->SetRunType("restG4"); + TRestRun mergeRun; + mergeRun.SetName("run"); + mergeRun.SetOutputFileName(outputFilename); + mergeRun.FormOutputFile(); + mergeRun.GetOutputFile()->cd(); + mergeRun.SetRunType("restG4"); TRestGeant4Event* mergeEvent = nullptr; - auto mergeEventTree = mergeRun->GetEventTree(); + auto mergeEventTree = mergeRun.GetEventTree(); mergeEventTree->Branch("TRestGeant4EventBranch", "TRestGeant4Event", &mergeEvent); set eventIds; // std::set is sorted from lower to higher automatically @@ -71,8 +71,8 @@ void REST_Geant4_MergeRestG4Files(const char* outputFilename, const char* inputF map eventIdUpdates; // repeatedId -> newId. Make sure if there are repeated event ids in a file // (because of sub-events) they keep the same event id after modification - auto run = TRestRun(inputFiles[i].c_str()); - auto metadata = (TRestGeant4Metadata*)run.GetMetadataClass("TRestGeant4Metadata"); + TRestRun run(inputFiles[i].c_str()); + auto metadata = dynamic_cast(run.GetMetadataClass("TRestGeant4Metadata")); if (i == 0) { mergeMetadata = *metadata; } else { @@ -106,23 +106,23 @@ void REST_Geant4_MergeRestG4Files(const char* outputFilename, const char* inputF eventIds.insert(mergeEvent->GetID()); mergeEventTree->Fill(); - mergeRun->GetAnalysisTree()->Fill(); + mergeRun.GetAnalysisTree()->Fill(); eventCounter++; } } - cout << "Output filename: " << mergeRun->GetOutputFileName() << endl; - cout << "Output file: " << mergeRun->GetOutputFile() << endl; + cout << "Output filename: " << mergeRun.GetOutputFileName() << endl; + cout << "Output file: " << mergeRun.GetOutputFile() << endl; - mergeRun->GetOutputFile()->cd(); + mergeRun.GetOutputFile()->cd(); gGeoManager->Write("Geometry", TObject::kOverwrite); mergeMetadata.SetName("geant4Metadata"); mergeMetadata.Write(); - mergeRun->UpdateOutputFile(); - mergeRun->CloseFile(); + mergeRun.UpdateOutputFile(); + mergeRun.CloseFile(); // Open the file again to check the number of events TRestRun runCheck(outputFilename); From dc0664e3bb95b1a1fc2bd3209634759a94a0d436 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Wed, 24 Jul 2024 14:23:38 +0200 Subject: [PATCH 10/13] save time --- src/TRestGeant4Metadata.cxx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index 4ba307f..eeb3eea 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -954,12 +954,17 @@ Double_t TRestGeant4Metadata::GetCosmicFluxInCountsPerCm2PerSecond() const { TRestGeant4PrimaryGeneratorTypes::StringToAngularDistributionTypes( source->GetAngularDistributionType().Data()) == TRestGeant4PrimaryGeneratorTypes::AngularDistributionTypes::TH2D) { - if (TRestGeant4PrimaryGeneratorTypes::StringToSpatialGeneratorTypes( - fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorType().Data()) != - TRestGeant4PrimaryGeneratorTypes::SpatialGeneratorTypes::COSMIC) { - throw std::runtime_error( - "Cosmic flux calculation is only supported for COSMIC spatial generator"); + const auto filename = source->GetEnergyDistributionFilename(); + const auto name = source->GetEnergyDistributionNameInFile(); + TFile* file = TFile::Open(filename); + auto energyAndAngularDistributionHistogram = + file->Get(name); // it's the same for both angular and energy + if (energyAndAngularDistributionHistogram == nullptr) { + throw std::runtime_error("Histogram not found in file"); } + countsPerSecondPerCm2 = energyAndAngularDistributionHistogram->Integral(); + file->Close(); + delete file; } else { @@ -1586,7 +1591,7 @@ double TRestGeant4Metadata::GetGeneratorSurfaceCm2() const { const auto radius = fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorSize().X(); return TMath::Pi() * radius * radius * 0.01; // cm2 } - if (type == "cosmic") { + else if (type == "cosmic") { return fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorCosmicSurfaceTermCm2(); } From c26fd8ab4d3be144e6f089947707a8eb09a6e2bf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Jul 2024 12:24:15 +0000 Subject: [PATCH 11/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/TRestGeant4Metadata.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/TRestGeant4Metadata.cxx b/src/TRestGeant4Metadata.cxx index eeb3eea..489880a 100644 --- a/src/TRestGeant4Metadata.cxx +++ b/src/TRestGeant4Metadata.cxx @@ -1590,8 +1590,7 @@ double TRestGeant4Metadata::GetGeneratorSurfaceCm2() const { if (type == "surface" && shape == "circle") { const auto radius = fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorSize().X(); return TMath::Pi() * radius * radius * 0.01; // cm2 - } - else if (type == "cosmic") { + } else if (type == "cosmic") { return fGeant4PrimaryGeneratorInfo.GetSpatialGeneratorCosmicSurfaceTermCm2(); } From fe9e404da968daab0553ccf4156f139a345886b9 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 28 Sep 2024 14:44:06 +0200 Subject: [PATCH 12/13] trigger ci --- CMakeLists.txt | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 411d982..e8e75e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,16 +2,7 @@ set_library_version(LibraryVersion) add_definitions(-DLIBRARY_VERSION="${LibraryVersion}") if (${REST_DECAY0} MATCHES "ON") - add_definitions(-DUSE_Decay0) - # TODO Issue #6 at rest-framework - # ---------------------------------------------------------------------------- - # Find package Decay0 and ROOT find_package(BxDecay0 1.0.9 CONFIG COMPONENTS - # manager REQUIRED) - # - # find_package was not working properly for me in 1.0.9. So I was using - # bxdecay0-config. But in case Decay0 flag is enabled and we do not have a - # bxdecay0 installation we might run into problems - # + add_definitions(-DUSE_Decay0) # https://github.com/rest-for-physics/framework/issues/6 execute_process( COMMAND bxdecay0-config --version From e738399f97f78f24f61d6fc268a73e31116ede3c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 28 Sep 2024 12:44:20 +0000 Subject: [PATCH 13/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8e75e6..927c963 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,8 @@ set_library_version(LibraryVersion) add_definitions(-DLIBRARY_VERSION="${LibraryVersion}") if (${REST_DECAY0} MATCHES "ON") - add_definitions(-DUSE_Decay0) # https://github.com/rest-for-physics/framework/issues/6 + add_definitions(-DUSE_Decay0 + )# https://github.com/rest-for-physics/framework/issues/6 execute_process( COMMAND bxdecay0-config --version