Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 4, 2023
1 parent df01599 commit 1845c59
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 56 deletions.
1 change: 0 additions & 1 deletion include/PrimaryGeneratorAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "DetectorConstruction.h"


class G4Event;
class SimulationManager;

Expand Down
109 changes: 54 additions & 55 deletions src/PrimaryGeneratorAction.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ PrimaryGeneratorAction::PrimaryGeneratorAction(SimulationManager* simulationMana
<< endl;
exit(1);
}

}

PrimaryGeneratorAction::~PrimaryGeneratorAction() = default;
Expand Down Expand Up @@ -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<TRestGeant4Particle> 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<TRestGeant4Particle> 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,
Expand Down

0 comments on commit 1845c59

Please sign in to comment.