Hi,
I’m trying to make a loop in the main file like this:
G4UImanager* UImanager = G4UImanager::GetUIpointer();
G4TScoreNtupleWriter<G4AnalysisManager> scoreNtupleWriter;
scoreNtupleWriter.SetVerboseLevel(1);
if ( ! ui ) {
// batch mode
UImanager->ApplyCommand("/control/execute init_vis.mac");
for (lambda_fotone = 250; lambda_fotone < 251; lambda_fotone++){
G4cout << "######################################" << G4endl;
G4cout << "# È in corso il run a " << 1240/lambda_fotone << " eV a " << lambda_fotone << " nm." << G4endl;
G4cout << "######################################" << G4endl;
UImanager->ApplyCommand("/gun/energy 1240/i eV");
UImanager->ApplyCommand("/run/beamOn 1000000");
}
}
where the global definition of lambda_fotone
is inside the DetectorConstruction.hh class:
class DetectorConstruction : public G4VUserDetectorConstruction
{
public:
DetectorConstruction();
~DetectorConstruction() override;
G4int lambda_fotone = 250; //Wavelengh in nm
G4double Energia_fotone = 1240/lambda_fotone; //Energy in eV
public:
G4VPhysicalVolume* Construct() override;
void ConstructSDandField() override;
private:
void DefineMaterials();
Then, the variable lambda_fotone
is also called in the source file DetectorConstruction.cc in order to set reflectivity
and transmission
that depend on that parameter:
if ( lambda_fotone >= 250 && lambda_fotone < 260 ) { /*see Dicken - Accelerated UV weathering device based on integrating sphere technology*/
std::vector<G4double> reflectivity = {0.955};
std::vector<G4double> trasmittance = {0.045};
std::vector<G4double> rindex_teflon = {1.30};
std::vector<G4double> absorption = {1*um}; //il dato è errato, ma ai fini della simulazione non interessa
TEFLON_MPT->AddProperty("RINDEX", energy, rindex_teflon);
TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption);
TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity);
TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, reflectivity);
G4cout << "************************************************************************************" << G4endl;
G4cout << "Sono stati settati i seguenti parametri. R_Index: " << rindex_teflon[0] <<
" [u.a] Absorption Lenght " << absorption[0] <<
" [c.m.] Reflectivity " << reflectivity[0] <<
" [u.a.] Trasmittance " << trasmittance[0] << G4endl;
G4cout << "************************************************************************************" << G4endl;
} else if ( lambda_fotone >= 260 && lambda_fotone < 270 ) {
std::vector<G4double> reflectivity = {0.965};
std::vector<G4double> trasmittance = {0.035};
std::vector<G4double> rindex_teflon = {1.30};
std::vector<G4double> absorption = {1*um}; //il dato è errato, ma ai fini della simulazione non interessa
TEFLON_MPT->AddProperty("RINDEX", energy, rindex_teflon);
TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption);
TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity);
TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, reflectivity);
G4cout << "************************************************************************************" << G4endl;
G4cout << "Sono stati settati i seguenti parametri. R_Index: " << rindex_teflon[0] <<
" [u.a] Absorption Lenght " << absorption[0] <<
" [c.m.] Reflectivity " << reflectivity[0] <<
" [u.a.] Trasmittance " << trasmittance[0] << G4endl;
G4cout << "************************************************************************************" << G4endl;
} else if ( lambda_fotone >= 270 && lambda_fotone < 280 ) {
std::vector<G4double> reflectivity = {0.975};
std::vector<G4double> trasmittance = {0.025};
std::vector<G4double> rindex_teflon = {1.30};
std::vector<G4double> absorption = {1*um}; //il dato è errato, ma ai fini della simulazione non interessa
TEFLON_MPT->AddProperty("RINDEX", energy, rindex_teflon);
TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption);
TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity);
TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, reflectivity);
G4cout << "************************************************************************************" << G4endl;
G4cout << "Sono stati settati i seguenti parametri. R_Index: " << rindex_teflon[0] <<
" [u.a] Absorption Lenght " << absorption[0] <<
" [c.m.] Reflectivity " << reflectivity[0] <<
" [u.a.] Trasmittance " << trasmittance[0] << G4endl;
G4cout << "************************************************************************************" << G4endl;
} else if ( lambda_fotone >= 280 && lambda_fotone < 290 ) {
std::vector<G4double> reflectivity = {0.985};
std::vector<G4double> trasmittance = {0.025};
std::vector<G4double> rindex_teflon = {1.30};
std::vector<G4double> absorption = {1*um}; //il dato è errato, ma ai fini della simulazione non interessa
TEFLON_MPT->AddProperty("RINDEX", energy, rindex_teflon);
TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption);
TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity);
TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, reflectivity);
G4cout << "************************************************************************************" << G4endl;
G4cout << "Sono stati settati i seguenti parametri. R_Index: " << rindex_teflon[0] <<
" [u.a] Absorption Lenght " << absorption[0] <<
" [c.m.] Reflectivity " << reflectivity[0] <<
" [u.a.] Trasmittance " << trasmittance[0] << G4endl;
G4cout << "************************************************************************************" << G4endl;
} else {
std::vector<G4double> reflectivity = {0.99};
std::vector<G4double> trasmittance = {0.01}; //se vuoi vedere la geometria della sorgente metti a 1
std::vector<G4double> rindex_teflon = {1.30};
std::vector<G4double> absorption = {1*um}; //il dato è errato, ma ai fini della simulazione non interessa
TEFLON_MPT->AddProperty("RINDEX", energy, rindex_teflon);
TEFLON_MPT->AddProperty("ABSLENGTH", energy, absorption);
TEFLON_MPT->AddProperty("REFLECTIVITY", energy, reflectivity);
TEFLON_MPT->AddProperty("TRANSMITTANCE", energy, reflectivity);
G4cout << "************************************************************************************" << G4endl;
G4cout << "Sono stati settati i seguenti parametri. R_Index: " << rindex_teflon[0] <<
" [u.a] Absorption Lenght " << absorption[0] <<
" [c.m.] Reflectivity " << reflectivity[0] <<
" [u.a.] Trasmittance " << trasmittance[0] << G4endl;
G4cout << "************************************************************************************" << G4endl;
}
Running the simulation i saw two problems:
- The value of
lamba_fotone
setted in main loop is overwritten to the value setted in the DetectorConstruction.hh; - The energy setted in main loop is casted to an int. This creates major errors in setting the correct reflection and transmission values and fixing the energy of the emitted particles.
My goal is to execute n
run with n
different energy.
why do I get these errors?