Skip to content

Commit

Permalink
Merge pull request #232 from paolafer/very-last-desperate-attempt
Browse files Browse the repository at this point in the history
Cosmetics
  • Loading branch information
paolafer authored Jan 29, 2024
2 parents f6e22ef + 77cf9a4 commit 93a1f28
Show file tree
Hide file tree
Showing 36 changed files with 754 additions and 1,017 deletions.
12 changes: 6 additions & 6 deletions source/actions/MuonsEventAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ REGISTER_CLASS(MuonsEventAction, G4UserEventAction)
fG4AnalysisMan_ = G4AnalysisManager::Instance();

// Create histogram(s) for muons
fG4AnalysisMan_->CreateH1("Edepo","Energy_deposited",100,-1.0,3.4);
fG4AnalysisMan_->CreateH1("Zenith","Zenith generated",100,0.,pi);
fG4AnalysisMan_->CreateH1("Azimuth","Azimuth generated",100,0.,twopi);
fG4AnalysisMan_->CreateH1("Edepo", "Energy_deposited", 100, -1.0, 3.4);
fG4AnalysisMan_->CreateH1("Zenith", "Zenith generated", 100, 0., pi);
fG4AnalysisMan_->CreateH1("Azimuth", "Azimuth generated", 100, 0., twopi);

// Create Ntuple branches for muons
fG4AnalysisMan_->CreateNtuple("Tree nexus","Flat tree of muon zenith and azimuth");
fG4AnalysisMan_->CreateNtuple("Tree nexus", "Flat tree of muon zenith and azimuth");
fG4AnalysisMan_->CreateNtupleDColumn("tree_zenith");
fG4AnalysisMan_->CreateNtupleDColumn("tree_azimuth");
fG4AnalysisMan_->FinishNtuple();
Expand Down Expand Up @@ -122,8 +122,8 @@ REGISTER_CLASS(MuonsEventAction, G4UserEventAction)

// Retrieving muon generation information
G4PrimaryVertex* my_vertex = event->GetPrimaryVertex();
G4VUserPrimaryVertexInformation *getinfo2 = my_vertex->GetUserInformation();
AddUserInfoToPV *my_getinfo2 = dynamic_cast<AddUserInfoToPV*>(getinfo2);
G4VUserPrimaryVertexInformation* getinfo2 = my_vertex->GetUserInformation();
AddUserInfoToPV* my_getinfo2 = dynamic_cast<AddUserInfoToPV*>(getinfo2);

G4double my_zenith = my_getinfo2->GetZenith();
G4double my_azimuth = my_getinfo2->GetAzimuth();
Expand Down
10 changes: 4 additions & 6 deletions source/actions/SaveAllSteppingAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ kill_after_selection_(false)

msg_->DeclareMethod("select_particle",
&SaveAllSteppingAction::AddSelectedParticle,
"add a new particle to select");
"Add a new particle to select");

msg_->DeclareMethod("select_volume",
&SaveAllSteppingAction::AddSelectedVolume,
"add a new volume to select");
msg_->DeclareMethod("select_volume", &SaveAllSteppingAction::AddSelectedVolume,
"Add a new volume to select");

msg_->DeclareProperty("kill_after_selection",
kill_after_selection_,
msg_->DeclareProperty("kill_after_selection", kill_after_selection_,
"Whether to kill a particle after a step has been selected");

PersistencyManager* pm = dynamic_cast<PersistencyManager*>
Expand Down
6 changes: 2 additions & 4 deletions source/generators/ECECGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ ECECGenerator::ECECGenerator():
"Control commands of the ECEC primary generator.");

G4GenericMessenger::Command& atomic_number_cmd =
msg_->DeclareProperty("atomic_number", atomic_number_,
"Atomic number of the ion.");
msg_->DeclareProperty("atomic_number", atomic_number_, "Atomic number of the ion.");
atomic_number_cmd.SetParameterName("atomic_number", false);
atomic_number_cmd.SetRange("atomic_number > 0");

msg_->DeclareProperty("shell", shell_name_,
"Shell from which the electron is captured.");
msg_->DeclareProperty("shell", shell_name_, "Shell from which the electron is captured.");

msg_->DeclareProperty("region", region_,
"Region of the geometry where vertices will be generated.");
Expand Down
3 changes: 1 addition & 2 deletions source/generators/ELTableGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ ELTableGenerator::ELTableGenerator():
"Control commands of the EL lookup table primary generator.");

//G4GenericMessenger::Command& num_ie_cmd =
msg_->DeclareProperty("num_ie", num_ie_,
"Set number of ionization electrons to be generated.");
msg_->DeclareProperty("num_ie", num_ie_, "Set number of ionization electrons to be generated.");

// Retrieve pointer to detector geometry from the run manager
DetectorConstruction* detconst = (DetectorConstruction*) G4RunManager::GetRunManager()->GetUserDetectorConstruction();
Expand Down
11 changes: 5 additions & 6 deletions source/generators/ElecPositronPairGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,19 @@ geom_(0)
"Control commands of single-particle generator.");

G4GenericMessenger::Command& min_energy =
msg_->DeclareProperty("min_energy", energy_min_,
"Set minimum total kinetic energy of the two particles.");
msg_->DeclareProperty("min_energy", energy_min_, "Minimum total kinetic energy of the two particles.");
min_energy.SetUnitCategory("Energy");
min_energy.SetParameterName("min_energy", false);
min_energy.SetRange("min_energy>0.");

G4GenericMessenger::Command& max_energy =
msg_->DeclareProperty("max_energy", energy_max_,
"Set maximum total kinetic energy of the two particles.");
msg_->DeclareProperty("max_energy", energy_max_, "Maximum total kinetic energy of the two particles.");
max_energy.SetUnitCategory("Energy");
max_energy.SetParameterName("max_energy", false);
max_energy.SetRange("max_energy>0.");

msg_->DeclareProperty("region", region_,
"Set the region of the geometry where the vertex will be generated.");
"Region of the geometry where the vertex will be generated.");

DetectorConstruction* detconst = (DetectorConstruction*) G4RunManager::GetRunManager()->GetUserDetectorConstruction();
geom_ = detconst->GetGeometry();
Expand Down Expand Up @@ -128,4 +126,5 @@ void ElecPositronPairGenerator::GeneratePrimaryVertex(G4Event* event)
// Add particle to the vertex and this to the event
vertex->SetPrimary(particle2);
event->AddPrimaryVertex(vertex);
}
}

6 changes: 4 additions & 2 deletions source/generators/IonGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ IonGenerator::IonGenerator():
msg_(nullptr), geom_(nullptr)
{
msg_ = new G4GenericMessenger(this, "/Generator/IonGenerator/",
"Control commands of the ion gun primary generator.");
"Control commands of the ion gun "
"primary generator.");

G4GenericMessenger::Command& atomic_number_cmd =
msg_->DeclareProperty("atomic_number", atomic_number_, "Atomic number of the ion.");
atomic_number_cmd.SetParameterName("atomic_number", false);
atomic_number_cmd.SetRange("atomic_number > 0");

G4GenericMessenger::Command& mass_number_cmd =
msg_->DeclareProperty("mass_number", mass_number_, "Mass number of the ion.");
msg_->DeclareProperty("mass_number", mass_number_,
"Mass number of the ion.");
mass_number_cmd.SetParameterName("mass_number", false);
mass_number_cmd.SetRange("mass_number > 0");

Expand Down
6 changes: 4 additions & 2 deletions source/generators/Kr83mGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace nexus {

using namespace CLHEP;

Kr83mGenerator::Kr83mGenerator() : geom_(0), energy_32_(32.1473*keV), energy_9_(9.396*keV),
Kr83mGenerator::Kr83mGenerator() : geom_(0), energy_32_(32.1473*keV),
energy_9_(9.396*keV),
probGamma_9_(0.0490), lifetime_9_(154.*ns)
{
// From the TORI /ENSDF data tables.
Expand Down Expand Up @@ -88,7 +89,8 @@ namespace nexus {
"Control commands of Kr83 generator.");

msg_->DeclareProperty("region", region_,
"Set the region of the geometry where the vertex will be generated.");
"Set the region of the geometry "
"where the vertex will be generated.");

// Set particle type searching in particle table by name
particle_defgamma_ = G4ParticleTable::GetParticleTable()->
Expand Down
13 changes: 5 additions & 8 deletions source/generators/LambertianGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,26 @@ costheta_min_(0), costheta_max_(1.)
"Set particle to be generated.");

G4GenericMessenger::Command& min_energy =
msg_->DeclareProperty("min_energy", energy_min_,
"Set minimum kinetic energy of the particle.");
msg_->DeclareProperty("min_energy", energy_min_, "Minimum kinetic energy of the particle.");
min_energy.SetUnitCategory("Energy");
min_energy.SetParameterName("min_energy", false);
min_energy.SetRange("min_energy>0.");

G4GenericMessenger::Command& max_energy =
msg_->DeclareProperty("max_energy", energy_max_,
"Set maximum kinetic energy of the particle");
msg_->DeclareProperty("max_energy", energy_max_, "Maximum kinetic energy of the particle");
max_energy.SetUnitCategory("Energy");
max_energy.SetParameterName("max_energy", false);
max_energy.SetRange("max_energy>0.");

msg_->DeclareProperty("region", region_,
"Set the region of the geometry where the vertex will be generated.");

"Region of the geometry where the vertex will be generated.");

msg_->DeclarePropertyWithUnit("momentum", "mm", momentum_, "Set particle 3-momentum.");

msg_->DeclareProperty("min_costheta", costheta_min_,
"Set minimum cosTheta for the direction of the particle.");
"Minimum cosTheta for the direction of the particle.");
msg_->DeclareProperty("max_costheta", costheta_max_,
"Set maximum cosTheta for the direction of the particle.");
"Maximum cosTheta for the direction of the particle.");

DetectorConstruction* detconst = (DetectorConstruction*) G4RunManager::GetRunManager()->GetUserDetectorConstruction();
geom_ = detconst->GetGeometry();
Expand Down
48 changes: 30 additions & 18 deletions source/generators/MuonGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ REGISTER_CLASS(MuonGenerator, G4VPrimaryGenerator)

MuonGenerator::MuonGenerator():
G4VPrimaryGenerator(), msg_(0), particle_definition_(0),
use_lsc_dist_(true), axis_rotation_(150), rPhi_(NULL), user_dir_{}, energy_min_(0.),
energy_max_(0.), dist_name_("za"), bInitialize_(false), geom_(0), geom_solid_(0),
gen_rad_(223.33*cm)
use_lsc_dist_(true), axis_rotation_(150), rPhi_(NULL), user_dir_{},
energy_min_(0.), energy_max_(0.), dist_name_("za"), bInitialize_(false),
geom_(0), geom_solid_(0), gen_rad_(223.33*cm)
{
msg_ = new G4GenericMessenger(this, "/Generator/MuonGenerator/",
"Control commands of muongenerator.");

G4GenericMessenger::Command& min_energy =
msg_->DeclareProperty("min_energy", energy_min_, "Set minimum kinetic energy of the particle.");
msg_->DeclareProperty("min_energy", energy_min_, "Minimum kinetic energy of the particle.");
min_energy.SetUnitCategory("Energy");
min_energy.SetParameterName("min_energy", false);
min_energy.SetRange("min_energy>0.");

G4GenericMessenger::Command& max_energy =
msg_->DeclareProperty("max_energy", energy_max_, "Set maximum kinetic energy of the particle");
msg_->DeclareProperty("max_energy", energy_max_, "Maximum kinetic energy of the particle");
max_energy.SetUnitCategory("Energy");
max_energy.SetParameterName("max_energy", false);
max_energy.SetRange("max_energy>0.");

msg_->DeclareProperty("region", region_,
"Set the region of the geometry where the vertex will be generated.");
"Region of the geometry where the vertex will be generated.");

msg_->DeclareProperty("use_lsc_dist", use_lsc_dist_,
"Distribute muon directions according to file?");
Expand Down Expand Up @@ -102,31 +102,36 @@ void MuonGenerator::LoadMuonDistribution()
// Only angle option, but energy specified
if (dist_name_ == "za")
G4Exception("[MuonGenerator]", "LoadMuonDistribution()",
FatalException, " Angular + Energy file specified with angle_dist=za option selected, use angle_dist=zae ");
FatalException, " Angular + Energy file specified "
"with angle_dist=za option selected, use angle_dist=zae ");
}
// File name does not contain the word Energy
else {
if (dist_name_ == "zae")
G4Exception("[MuonGenerator]", "LoadMuonDistribution()",
FatalException, " Angular file specified with angle_dist=zae option selected, use angle_dist=za ");
FatalException, " Angular file specified "
"with angle_dist=zae option selected, use angle_dist=za ");
}

// Load in the data from csv file depending on 2D histogram sampling or 3D
if (dist_name_ == "za")
LoadHistData2D(ang_file_, flux_, azimuths_, zeniths_, azimuth_smear_, zenith_smear_);

if (dist_name_ == "zae"){
LoadHistData3D(ang_file_, flux_, azimuths_, zeniths_, energies_, azimuth_smear_, zenith_smear_, energy_smear_);
LoadHistData3D(ang_file_, flux_, azimuths_, zeniths_, energies_,
azimuth_smear_, zenith_smear_, energy_smear_);

// Check if the energy is in the desired range permitted by the binning range in the data file
// Check if the energy is in the desired range permitted
// by the binning range in the data file
CheckVarBounds(ang_file_, energy_min_/GeV, energy_max_/GeV, "energy");

}

// Convert flux vector to arr
auto arr_flux = flux_.data();

// Initialise the Random Number Generator based on the flux distribution (in bin index)
// Initialise the Random Number Generator based on the flux distribution
// (in bin index)
fRandomGeneral_ = new G4RandGeneral( arr_flux, flux_.size() );

}
Expand Down Expand Up @@ -170,22 +175,27 @@ void MuonGenerator::GeneratePrimaryVertex(G4Event* event)
std::cout << "[MuonGenerator]: Generating muons using lsc distribution loaded from file" << std::endl;
LoadMuonDistribution();

// Throw exception if a user dir given and also the use_lsc_dist_ is set to true
// Throw exception if a user dir given
// and also the use_lsc_dist_ is set to true
if (user_dir_ != G4ThreeVector{})
G4Exception("[MuonGenerator]", "GeneratePrimaryVertex()",
FatalException, " Fixed user direction specified with use_lsc_dist set to true. Set use_lsc_dist to false or remove user_dir in the config");
FatalException, " Fixed user direction specified with "
"use_lsc_dist set to true. Set use_lsc_dist to "
"false or remove user_dir in the config");

}

// Initalise a cos^2 distribution to sample the zenith
if (!use_lsc_dist_ && (user_dir_ == G4ThreeVector{})){
std::cout << "[MuonGenerator]: Generating muons with uniform azimuth and cos^2 distribution for zenith " << std::endl;
std::cout << "[MuonGenerator]: Generating muons with uniform azimuth "
"and cos^2 distribution for zenith " << std::endl;
InitMuonZenithDist();
}

// User specified muon direction
if (!use_lsc_dist_ && (user_dir_ != G4ThreeVector{})){
std::cout << "[MuonGenerator]: Generating muons with user specified direction " << std::endl;
std::cout << "[MuonGenerator]: Generating muons with user specified "
"direction " << std::endl;
}

// Set Initialisation
Expand Down Expand Up @@ -269,7 +279,8 @@ void MuonGenerator::GeneratePrimaryVertex(G4Event* event)
G4PrimaryParticle* particle =
new G4PrimaryParticle(particle_definition_, px, py, pz);

// Add info to PrimaryVertex to be accessed from EventAction type class to make histos of variables generated here.
// Add info to PrimaryVertex to be accessed from EventAction type class
// to make histos of variables generated here.
AddUserInfoToPV *info = new AddUserInfoToPV(zenith, azimuth);

vertex->SetUserInformation(info);
Expand Down Expand Up @@ -297,8 +308,9 @@ G4String MuonGenerator::MuonCharge() const
}


void MuonGenerator::GetDirection(G4ThreeVector& dir, G4double& zenith, G4double& azimuth,
G4double& energy, G4double& kinetic_energy, G4double mass)
void MuonGenerator::GetDirection(G4ThreeVector& dir, G4double& zenith,
G4double& azimuth, G4double& energy,
G4double& kinetic_energy, G4double mass)
{

// Bool to check if zenith has a valid value. If not then resample
Expand Down
4 changes: 2 additions & 2 deletions source/generators/Na22Generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ namespace nexus {

Na22Generator::Na22Generator() : geom_(0)
{
/// For the moment, only random direction are allowed. To be fixes if needed
/// For the moment, only random direction are allowed. To be fixed if needed
msg_ = new G4GenericMessenger(this, "/Generator/Na22Generator/",
"Control commands of Na22 generator.");

msg_->DeclareProperty("region", region_,
"Set the region of the geometry where the vertex will be generated.");
"Region of the geometry where the vertex will be generated.");


DetectorConstruction* detconst = (DetectorConstruction*)
Expand Down
15 changes: 8 additions & 7 deletions source/generators/ScintillationGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ ScintillationGenerator::ScintillationGenerator() :
"Control commands of scintillation generator.");

msg_->DeclareProperty("region", region_,
"Set the region of the geometry where the vertex will be generated.");
"Region of the geometry where the vertex will be generated.");

msg_->DeclareProperty("nphotons", nphotons_, "Set number of photons");
msg_->DeclareProperty("nphotons", nphotons_, "Number of photons");

geom_navigator_ =
G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
Expand Down Expand Up @@ -71,16 +71,17 @@ void ScintillationGenerator::GeneratePrimaryVertex(G4Event* event)
G4MaterialPropertiesTable* mpt = mat->GetMaterialPropertiesTable();

if (!mpt) {
G4Exception("[ScintillationGenerator]", "GeneratePrimaryVertex()", FatalException,
"Material properties not defined for this material!");
G4Exception("[ScintillationGenerator]", "GeneratePrimaryVertex()",
FatalException, "Material properties not defined for this material!");
}
// Using fast or slow component here is irrelevant, since we're not using time
// and they're are the same in energy.
G4MaterialPropertyVector* spectrum = mpt->GetProperty("SCINTILLATIONCOMPONENT1");
G4MaterialPropertyVector* spectrum =
mpt->GetProperty("SCINTILLATIONCOMPONENT1");

if (!spectrum) {
G4Exception("[ScintillationGenerator]", "GeneratePrimaryVertex()", FatalException,
"Fast time decay constant not defined for this material!");
G4Exception("[ScintillationGenerator]", "GeneratePrimaryVertex()",
FatalException, "Fast time decay constant not defined for this material!");
}

G4PhysicsOrderedFreeVector* spectrum_integral =
Expand Down
Loading

0 comments on commit 93a1f28

Please sign in to comment.