From 1845c59bb0db3902394a29f0f3812e441e68d9c9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Nov 2023 05:49:12 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- include/PrimaryGeneratorAction.h | 1 - src/PrimaryGeneratorAction.cxx | 109 +++++++++++++++---------------- 2 files changed, 54 insertions(+), 56 deletions(-) diff --git a/include/PrimaryGeneratorAction.h b/include/PrimaryGeneratorAction.h index 689d56d5..48882751 100644 --- a/include/PrimaryGeneratorAction.h +++ b/include/PrimaryGeneratorAction.h @@ -17,7 +17,6 @@ #include "DetectorConstruction.h" - class G4Event; class SimulationManager; diff --git a/src/PrimaryGeneratorAction.cxx b/src/PrimaryGeneratorAction.cxx index 1ef1adca..4a32a087 100644 --- a/src/PrimaryGeneratorAction.cxx +++ b/src/PrimaryGeneratorAction.cxx @@ -178,7 +178,6 @@ PrimaryGeneratorAction::PrimaryGeneratorAction(SimulationManager* simulationMana << endl; exit(1); } - } PrimaryGeneratorAction::~PrimaryGeneratorAction() = default; @@ -232,60 +231,60 @@ void PrimaryGeneratorAction::SetGeneratorSpatialDensity(TString str) { } void PrimaryGeneratorAction::GeneratePrimaries(G4Event* event) { - auto simulationManager = fSimulationManager; - TRestGeant4Metadata* restG4Metadata = simulationManager->GetRestMetadata(); - - if (restG4Metadata->GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) { - cout << "DEBUG: Primary generation" << endl; - } - // We have to initialize here and not in start of the event because - // GeneratePrimaries is called first, and we want to store event origin and position inside - // we should have already written the information from previous event to disk (in endOfEventAction) - - for (int i = 0; i < restG4Metadata->GetNumberOfSources(); i++) { - restG4Metadata->GetParticleSource(i)->Update(); - } - - const auto& primaryGeneratorInfo = restG4Metadata->GetGeant4PrimaryGeneratorInfo(); - const string& spatialGeneratorTypeName = primaryGeneratorInfo.GetSpatialGeneratorType().Data(); - const auto spatialGeneratorTypeEnum = StringToSpatialGeneratorTypes(spatialGeneratorTypeName); - // Apparently not used. I comment to avoid compilation warning - // Int_t nParticles = restG4Metadata->GetNumberOfSources(); - - if (spatialGeneratorTypeEnum == SpatialGeneratorTypes::COSMIC) { - if (fCosmicCircumscribedSphereRadius == 0.) { - // radius in mm - fCosmicCircumscribedSphereRadius = fSimulationManager->GetRestMetadata() - ->GetGeant4PrimaryGeneratorInfo() - .GetSpatialGeneratorCosmicRadius(); - } - - // This generator has correlated position / direction, so we need to use a different approach - if (restG4Metadata->GetNumberOfSources() != 1) { - cout << "PrimaryGeneratorAction - ERROR: cosmic generator only supports one source" << endl; - exit(1); - } - } - // Set the particle(s)' position, multiple particles generated from multiple sources shall always have a - // same origin - SetParticlePosition(); - - for (int i = 0; i < restG4Metadata->GetNumberOfSources(); i++) { - vector particles = restG4Metadata->GetParticleSource(i)->GetParticles(); - for (const auto& p : particles) { - // ParticleDefinition should be always declared first (after position). - SetParticleDefinition(i, p); - SetParticleEnergyAndDirection(i, p); - - if (spatialGeneratorTypeEnum == SpatialGeneratorTypes::COSMIC) { - const auto position = ComputeCosmicPosition(fParticleGun.GetParticleMomentumDirection(), - fCosmicCircumscribedSphereRadius); - fParticleGun.SetParticlePosition(position); - } - - fParticleGun.GeneratePrimaryVertex(event); - } - } + auto simulationManager = fSimulationManager; + TRestGeant4Metadata* restG4Metadata = simulationManager->GetRestMetadata(); + + if (restG4Metadata->GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) { + cout << "DEBUG: Primary generation" << endl; + } + // We have to initialize here and not in start of the event because + // GeneratePrimaries is called first, and we want to store event origin and position inside + // we should have already written the information from previous event to disk (in endOfEventAction) + + for (int i = 0; i < restG4Metadata->GetNumberOfSources(); i++) { + restG4Metadata->GetParticleSource(i)->Update(); + } + + const auto& primaryGeneratorInfo = restG4Metadata->GetGeant4PrimaryGeneratorInfo(); + const string& spatialGeneratorTypeName = primaryGeneratorInfo.GetSpatialGeneratorType().Data(); + const auto spatialGeneratorTypeEnum = StringToSpatialGeneratorTypes(spatialGeneratorTypeName); + // Apparently not used. I comment to avoid compilation warning + // Int_t nParticles = restG4Metadata->GetNumberOfSources(); + + if (spatialGeneratorTypeEnum == SpatialGeneratorTypes::COSMIC) { + if (fCosmicCircumscribedSphereRadius == 0.) { + // radius in mm + fCosmicCircumscribedSphereRadius = fSimulationManager->GetRestMetadata() + ->GetGeant4PrimaryGeneratorInfo() + .GetSpatialGeneratorCosmicRadius(); + } + + // This generator has correlated position / direction, so we need to use a different approach + if (restG4Metadata->GetNumberOfSources() != 1) { + cout << "PrimaryGeneratorAction - ERROR: cosmic generator only supports one source" << endl; + exit(1); + } + } + // Set the particle(s)' position, multiple particles generated from multiple sources shall always have a + // same origin + SetParticlePosition(); + + for (int i = 0; i < restG4Metadata->GetNumberOfSources(); i++) { + vector particles = restG4Metadata->GetParticleSource(i)->GetParticles(); + for (const auto& p : particles) { + // ParticleDefinition should be always declared first (after position). + SetParticleDefinition(i, p); + SetParticleEnergyAndDirection(i, p); + + if (spatialGeneratorTypeEnum == SpatialGeneratorTypes::COSMIC) { + const auto position = ComputeCosmicPosition(fParticleGun.GetParticleMomentumDirection(), + fCosmicCircumscribedSphereRadius); + fParticleGun.SetParticlePosition(position); + } + + fParticleGun.GeneratePrimaryVertex(event); + } + } } G4ParticleDefinition* PrimaryGeneratorAction::SetParticleDefinition(Int_t particleSourceIndex,