added multi particles

This commit is contained in:
Jan Kieseler
2024-10-09 13:05:18 +02:00
parent b7946e2e37
commit 7410049a72
7 changed files with 184 additions and 125 deletions
+13 -3
View File
@@ -53,15 +53,25 @@ class ActionInitialization : public G4VUserActionInitialization
void BuildForMaster() const override;
void Build() const override;
void setGeneratorProperties(G4double minEnergy, G4double maxEnergy, G4String partSpecies){
void setGeneratorProperties(G4double minEnergy, G4double maxEnergy, const std::vector<std::string>& partSpecies){
if(gen==nullptr){
throw std::runtime_error("PrimaryGeneratorAction not found");
}
gen->setMinPartEnergy(minEnergy);
gen->setMaxPartEnergy(maxEnergy);
gen->setPartSpecies(partSpecies);
G4cout << "ActionInitialization: Setting particle species to " << partSpecies << G4endl;
G4cout << "ActionInitialization: Setting particle species to " ;
for(const auto& p : partSpecies){
G4cout << p << " ";
}
G4cout << G4endl;
}
void setGeneratorProperties(G4double minEnergy, G4double maxEnergy, const std::string& partSpecies){
setGeneratorProperties(minEnergy, maxEnergy, std::vector<std::string>{partSpecies});
}
void setDetectorConstruction(B4::DetectorConstruction* det){
fDetConstruction = det;
@@ -80,7 +90,7 @@ class ActionInitialization : public G4VUserActionInitialization
mutable B4::RunAction * runact = nullptr;
G4double minEnergy=1000;
G4double maxEnergy=1000;
G4String partSpecies="e-";
std::vector<std::string> partSpecies;
G4String filename="";
};
+2 -1
View File
@@ -17,6 +17,7 @@
#include "FTFP_BERT.hh"
#include "Randomize.hh"
#include <vector>
class G4System{
friend class GeometryDescriptor;
@@ -39,7 +40,7 @@ void init(GeometryDescriptor &cw, int seed=0);
void run_visualize(const std::string& partSpecies, double minEnergy_GeV, double maxEnergy_GeV);
//runs the whole gui if available
void run_gui();
void run_batch(int nEvents, const std::string& partSpecies, double minEnergy_GeV,
void run_batch(int nEvents, const std::vector<std::string>& partSpecies, double minEnergy_GeV,
double maxEnergy_GeV, std::string filename="_1234567890_Hits.root");
void applyUICommand(const std::string& command){
+30 -27
View File
@@ -59,32 +59,35 @@ public:
G4double getPartEnergy() const{return partEnergy;}
void setMinPartEnergy(G4double value){minPartEnergy = value;}
void setMaxPartEnergy(G4double value){maxPartEnergy = value;}
void setPartSpecies(G4String value){
partSpecies = value;
if(partSpecies == "e-"){
G4cout << "Particle species set to electron" << G4endl;
}
else if(partSpecies == "e+"){
G4cout << "Particle species set to positron" << G4endl;
}
else if(partSpecies == "gamma"){
G4cout << "Particle species set to gamma" << G4endl;
}
else if(partSpecies == "proton"){
G4cout << "Particle species set to proton" << G4endl;
}
else if(partSpecies == "neutron"){
G4cout << "Particle species set to neutron" << G4endl;
}
else if(partSpecies == "pi+"){
G4cout << "Particle species set to charged pion" << G4endl;
}
else if(partSpecies == "pi-"){
G4cout << "Particle species set to charged pion" << G4endl;
}
else{
G4cout << "Particle species "<< partSpecies << " not recognized" << G4endl;
throw std::invalid_argument("Particle species not recognized");
void setPartSpecies(const std::vector<std::string>& values){
partSpecies = values;
for(const auto value : values){
G4String val = value;
if(val == "e-"){
G4cout << "Particle species set to electron" << G4endl;
}
else if(val == "e+"){
G4cout << "Particle species set to positron" << G4endl;
}
else if(val == "gamma"){
G4cout << "Particle species set to gamma" << G4endl;
}
else if(val == "proton"){
G4cout << "Particle species set to proton" << G4endl;
}
else if(val == "neutron"){
G4cout << "Particle species set to neutron" << G4endl;
}
else if(val == "pi+"){
G4cout << "Particle species set to charged pion" << G4endl;
}
else if(val == "pi-"){
G4cout << "Particle species set to charged pion" << G4endl;
}
else{
G4cout << "Particle species "<< val << " not recognized" << G4endl;
throw std::invalid_argument("Particle species not recognized");
}
}
}
private:
@@ -92,7 +95,7 @@ private:
G4double partEnergy;
G4double minPartEnergy=100; //MeV
G4double maxPartEnergy=100;
G4String partSpecies="e-";
std::vector<std::string> partSpecies;
};