Import Geant4 11.3.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2024-06-28 13:08:51 +02:00
parent f7b23877ed
commit e58e650b32
5232 changed files with 239416 additions and 244360 deletions
@@ -28,9 +28,10 @@
/// \brief Implementation of the B1::ActionInitialization class
#include "ActionInitialization.hh"
#include "EventAction.hh"
#include "PrimaryGeneratorAction.hh"
#include "RunAction.hh"
#include "EventAction.hh"
#include "SteppingAction.hh"
namespace B1Con
@@ -61,4 +62,4 @@ void ActionInitialization::Build() const
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
}
} // namespace B1Con
@@ -29,16 +29,16 @@
#include "DetectorConstruction.hh"
#include "G4RunManager.hh"
#include "G4NistManager.hh"
#include "G4Box.hh"
#include "G4Cons.hh"
#include "G4Orb.hh"
#include "G4Sphere.hh"
#include "G4Trd.hh"
#include "G4LogicalVolume.hh"
#include "G4NistManager.hh"
#include "G4Orb.hh"
#include "G4PVPlacement.hh"
#include "G4RunManager.hh"
#include "G4Sphere.hh"
#include "G4SystemOfUnits.hh"
#include "G4Trd.hh"
namespace B1
{
@@ -52,7 +52,7 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
// Envelope parameters
//
G4double env_sizeXY = 20*cm, env_sizeZ = 30*cm;
G4double env_sizeXY = 20 * cm, env_sizeZ = 30 * cm;
G4Material* env_mat = nist->FindOrBuildMaterial("G4_WATER");
// Option to switch on/off checking of volumes overlaps
@@ -62,109 +62,111 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
//
// World
//
G4double world_sizeXY = 1.2*env_sizeXY;
G4double world_sizeZ = 1.2*env_sizeZ;
G4double world_sizeXY = 1.2 * env_sizeXY;
G4double world_sizeZ = 1.2 * env_sizeZ;
G4Material* world_mat = nist->FindOrBuildMaterial("G4_AIR");
auto solidWorld = new G4Box("World", // its name
0.5 * world_sizeXY, 0.5 * world_sizeXY, 0.5 * world_sizeZ); // its size
auto solidWorld =
new G4Box("World", // its name
0.5 * world_sizeXY, 0.5 * world_sizeXY, 0.5 * world_sizeZ); // its size
auto logicWorld = new G4LogicalVolume(solidWorld, // its solid
world_mat, // its material
"World"); // its name
world_mat, // its material
"World"); // its name
auto physWorld = new G4PVPlacement(nullptr, // no rotation
G4ThreeVector(), // at (0,0,0)
logicWorld, // its logical volume
"World", // its name
nullptr, // its mother volume
false, // no boolean operation
0, // copy number
checkOverlaps); // overlaps checking
G4ThreeVector(), // at (0,0,0)
logicWorld, // its logical volume
"World", // its name
nullptr, // its mother volume
false, // no boolean operation
0, // copy number
checkOverlaps); // overlaps checking
//
// Envelope
//
auto solidEnv = new G4Box("Envelope", // its name
0.5 * env_sizeXY, 0.5 * env_sizeXY, 0.5 * env_sizeZ); // its size
auto solidEnv = new G4Box("Envelope", // its name
0.5 * env_sizeXY, 0.5 * env_sizeXY, 0.5 * env_sizeZ); // its size
auto logicEnv = new G4LogicalVolume(solidEnv, // its solid
env_mat, // its material
"Envelope"); // its name
env_mat, // its material
"Envelope"); // its name
new G4PVPlacement(nullptr, // no rotation
G4ThreeVector(), // at (0,0,0)
logicEnv, // its logical volume
"Envelope", // its name
logicWorld, // its mother volume
false, // no boolean operation
0, // copy number
checkOverlaps); // overlaps checking
G4ThreeVector(), // at (0,0,0)
logicEnv, // its logical volume
"Envelope", // its name
logicWorld, // its mother volume
false, // no boolean operation
0, // copy number
checkOverlaps); // overlaps checking
//
// Shape 1
//
G4Material* shape1_mat = nist->FindOrBuildMaterial("G4_A-150_TISSUE");
G4ThreeVector pos1 = G4ThreeVector(0, 2*cm, -7*cm);
G4ThreeVector pos1 = G4ThreeVector(0, 2 * cm, -7 * cm);
// Conical section shape
G4double shape1_rmina = 0.*cm, shape1_rmaxa = 2.*cm;
G4double shape1_rminb = 0.*cm, shape1_rmaxb = 4.*cm;
G4double shape1_hz = 3.*cm;
G4double shape1_phimin = 0.*deg, shape1_phimax = 360.*deg;
G4double shape1_rmina = 0. * cm, shape1_rmaxa = 2. * cm;
G4double shape1_rminb = 0. * cm, shape1_rmaxb = 4. * cm;
G4double shape1_hz = 3. * cm;
G4double shape1_phimin = 0. * deg, shape1_phimax = 360. * deg;
auto solidShape1 = new G4Cons("Shape1", shape1_rmina, shape1_rmaxa, shape1_rminb, shape1_rmaxb,
shape1_hz, shape1_phimin, shape1_phimax);
shape1_hz, shape1_phimin, shape1_phimax);
auto logicShape1 = new G4LogicalVolume(solidShape1, // its solid
shape1_mat, // its material
"Shape1"); // its name
shape1_mat, // its material
"Shape1"); // its name
new G4PVPlacement(nullptr, // no rotation
pos1, // at position
logicShape1, // its logical volume
"Shape1", // its name
logicEnv, // its mother volume
false, // no boolean operation
0, // copy number
checkOverlaps); // overlaps checking
pos1, // at position
logicShape1, // its logical volume
"Shape1", // its name
logicEnv, // its mother volume
false, // no boolean operation
0, // copy number
checkOverlaps); // overlaps checking
//
// Shape 2
//
G4Material* shape2_mat = nist->FindOrBuildMaterial("G4_BONE_COMPACT_ICRU");
G4ThreeVector pos2 = G4ThreeVector(0, -1*cm, 7*cm);
G4ThreeVector pos2 = G4ThreeVector(0, -1 * cm, 7 * cm);
// Trapezoid shape
G4double shape2_dxa = 12*cm, shape2_dxb = 12*cm;
G4double shape2_dya = 10*cm, shape2_dyb = 16*cm;
G4double shape2_dz = 6*cm;
auto solidShape2 = new G4Trd("Shape2", // its name
0.5 * shape2_dxa, 0.5 * shape2_dxb, 0.5 * shape2_dya, 0.5 * shape2_dyb,
0.5 * shape2_dz); // its size
G4double shape2_dxa = 12 * cm, shape2_dxb = 12 * cm;
G4double shape2_dya = 10 * cm, shape2_dyb = 16 * cm;
G4double shape2_dz = 6 * cm;
auto solidShape2 =
new G4Trd("Shape2", // its name
0.5 * shape2_dxa, 0.5 * shape2_dxb, 0.5 * shape2_dya, 0.5 * shape2_dyb,
0.5 * shape2_dz); // its size
auto logicShape2 = new G4LogicalVolume(solidShape2, // its solid
shape2_mat, // its material
"Shape2"); // its name
shape2_mat, // its material
"Shape2"); // its name
new G4PVPlacement(nullptr, // no rotation
pos2, // at position
logicShape2, // its logical volume
"Shape2", // its name
logicEnv, // its mother volume
false, // no boolean operation
0, // copy number
checkOverlaps); // overlaps checking
pos2, // at position
logicShape2, // its logical volume
"Shape2", // its name
logicEnv, // its mother volume
false, // no boolean operation
0, // copy number
checkOverlaps); // overlaps checking
// Set Shape2 as scoring volume
//
fScoringVolume = logicShape2;
//
//always return the physical World
// always return the physical World
//
return physWorld;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
}
} // namespace B1
@@ -28,6 +28,7 @@
/// \brief Implementation of the B1::EventAction class
#include "EventAction.hh"
#include "RunAction.hh"
#include "G4Event.hh"
@@ -38,9 +39,7 @@ namespace B1
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
EventAction::EventAction(B1Con::RunAction* runAction)
: fRunAction(runAction)
{}
EventAction::EventAction(B1Con::RunAction* runAction) : fRunAction(runAction) {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -59,4 +58,4 @@ void EventAction::EndOfEventAction(const G4Event*)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
}
} // namespace B1
@@ -29,13 +29,13 @@
#include "PrimaryGeneratorAction.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "G4RunManager.hh"
#include "G4LogicalVolume.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4ParticleDefinition.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "G4RunManager.hh"
#include "G4SystemOfUnits.hh"
#include "Randomize.hh"
@@ -47,16 +47,15 @@ namespace B1
PrimaryGeneratorAction::PrimaryGeneratorAction()
{
G4int n_particle = 1;
fParticleGun = new G4ParticleGun(n_particle);
fParticleGun = new G4ParticleGun(n_particle);
// default particle kinematic
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4String particleName;
G4ParticleDefinition* particle
= particleTable->FindParticle(particleName="gamma");
G4ParticleDefinition* particle = particleTable->FindParticle(particleName = "gamma");
fParticleGun->SetParticleDefinition(particle);
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
fParticleGun->SetParticleEnergy(6.*MeV);
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.));
fParticleGun->SetParticleEnergy(6. * MeV);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -70,7 +69,7 @@ PrimaryGeneratorAction::~PrimaryGeneratorAction()
void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
//this function is called at the begining of ecah event
// this function is called at the begining of ecah event
//
// In order to avoid dependence of PrimaryGeneratorAction
@@ -80,38 +79,33 @@ void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
G4double envSizeXY = 0;
G4double envSizeZ = 0;
if (!fEnvelopeBox)
{
G4LogicalVolume* envLV
= G4LogicalVolumeStore::GetInstance()->GetVolume("Envelope");
if ( envLV ) fEnvelopeBox = dynamic_cast<G4Box*>(envLV->GetSolid());
if (!fEnvelopeBox) {
G4LogicalVolume* envLV = G4LogicalVolumeStore::GetInstance()->GetVolume("Envelope");
if (envLV) fEnvelopeBox = dynamic_cast<G4Box*>(envLV->GetSolid());
}
if ( fEnvelopeBox ) {
envSizeXY = fEnvelopeBox->GetXHalfLength()*2.;
envSizeZ = fEnvelopeBox->GetZHalfLength()*2.;
if (fEnvelopeBox) {
envSizeXY = fEnvelopeBox->GetXHalfLength() * 2.;
envSizeZ = fEnvelopeBox->GetZHalfLength() * 2.;
}
else {
else {
G4ExceptionDescription msg;
msg << "Envelope volume of box shape not found.\n";
msg << "Perhaps you have changed geometry.\n";
msg << "The gun will be place at the center.";
G4Exception("PrimaryGeneratorAction::GeneratePrimaries()",
"MyCode0002",JustWarning,msg);
G4Exception("PrimaryGeneratorAction::GeneratePrimaries()", "MyCode0002", JustWarning, msg);
}
G4double size = 0.8;
G4double x0 = size * envSizeXY * (G4UniformRand()-0.5);
G4double y0 = size * envSizeXY * (G4UniformRand()-0.5);
G4double x0 = size * envSizeXY * (G4UniformRand() - 0.5);
G4double y0 = size * envSizeXY * (G4UniformRand() - 0.5);
G4double z0 = -0.5 * envSizeZ;
fParticleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
fParticleGun->SetParticlePosition(G4ThreeVector(x0, y0, z0));
fParticleGun->GeneratePrimaryVertex(anEvent);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
}
} // namespace B1
@@ -28,16 +28,17 @@
/// \brief Implementation of the B1::RunAction class
#include "RunAction.hh"
#include "PrimaryGeneratorAction.hh"
#include "DetectorConstruction.hh"
#include "G4RunManager.hh"
#include "G4Run.hh"
#include "DetectorConstruction.hh"
#include "PrimaryGeneratorAction.hh"
#include "G4AccumulableManager.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4LogicalVolume.hh"
#include "G4UnitsTable.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4Run.hh"
#include "G4RunManager.hh"
#include "G4SystemOfUnits.hh"
#include "G4UnitsTable.hh"
namespace B1Con
{
@@ -48,15 +49,15 @@ RunAction::RunAction()
{
// add new units for dose
//
const G4double milligray = 1.e-3*gray;
const G4double microgray = 1.e-6*gray;
const G4double nanogray = 1.e-9*gray;
const G4double picogray = 1.e-12*gray;
const G4double milligray = 1.e-3 * gray;
const G4double microgray = 1.e-6 * gray;
const G4double nanogray = 1.e-9 * gray;
const G4double picogray = 1.e-12 * gray;
new G4UnitDefinition("milligray", "milliGy" , "Dose", milligray);
new G4UnitDefinition("microgray", "microGy" , "Dose", microgray);
new G4UnitDefinition("nanogray" , "nanoGy" , "Dose", nanogray);
new G4UnitDefinition("picogray" , "picoGy" , "Dose", picogray);
new G4UnitDefinition("milligray", "milliGy", "Dose", milligray);
new G4UnitDefinition("microgray", "microGy", "Dose", microgray);
new G4UnitDefinition("nanogray", "nanoGy", "Dose", nanogray);
new G4UnitDefinition("picogray", "picoGy", "Dose", picogray);
// Register accumulable to the accumulable manager
G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
@@ -77,8 +78,8 @@ void RunAction::BeginOfRunAction(const G4Run*)
accumulableManager->Reset();
if (IsMaster()) {
fDoseTally = new G4ConvergenceTester("DOSE_TALLY");
//fDoseTally = new G4ConvergenceTester();
fDoseTally = new G4ConvergenceTester("DOSE_TALLY");
// fDoseTally = new G4ConvergenceTester();
}
}
@@ -95,17 +96,20 @@ void RunAction::EndOfRunAction(const G4Run* run)
// Compute dose = total energy deposit in a run and its variance
//
G4double edep = fEdep.GetValue();
G4double edep = fEdep.GetValue();
G4double edep2 = fEdep2.GetValue();
G4double rms = edep2 - edep*edep/nofEvents;
if (rms > 0.) rms = std::sqrt(rms); else rms = 0.;
G4double rms = edep2 - edep * edep / nofEvents;
if (rms > 0.)
rms = std::sqrt(rms);
else
rms = 0.;
const auto detConstruction = static_cast<const B1::DetectorConstruction*>(
G4RunManager::GetRunManager()->GetUserDetectorConstruction());
G4double mass = detConstruction->GetScoringVolume()->GetMass();
G4double dose = edep/mass;
G4double rmsDose = rms/mass;
G4double dose = edep / mass;
G4double rmsDose = rms / mass;
// Run conditions
// note: There is no primary generator action object for "master"
@@ -113,59 +117,48 @@ void RunAction::EndOfRunAction(const G4Run* run)
const auto generatorAction = static_cast<const B1::PrimaryGeneratorAction*>(
G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
G4String runCondition;
if (generatorAction)
{
if (generatorAction) {
const G4ParticleGun* particleGun = generatorAction->GetParticleGun();
runCondition += particleGun->GetParticleDefinition()->GetParticleName();
runCondition += " of ";
G4double particleEnergy = particleGun->GetParticleEnergy();
runCondition += G4BestUnit(particleEnergy,"Energy");
runCondition += G4BestUnit(particleEnergy, "Energy");
}
// Print
//
if (IsMaster()) {
for (auto edepPerEvent : fEdepPerEvent.GetVector()) {
G4double dosePerEvent = edepPerEvent/mass/gray;
fDoseTally->AddScore(dosePerEvent);
}
for (auto edepPerEvent : fEdepPerEvent.GetVector()) {
G4double dosePerEvent = edepPerEvent / mass / gray;
fDoseTally->AddScore(dosePerEvent);
}
fDoseTally->ShowResult();
fDoseTally->ShowHistory();
delete fDoseTally;
fDoseTally = nullptr;
fDoseTally->ShowResult();
fDoseTally->ShowHistory();
delete fDoseTally;
fDoseTally = nullptr;
G4cout
<< G4endl
<< "--------------------End of Global Run-----------------------";
G4cout << G4endl << "--------------------End of Global Run-----------------------";
}
else {
G4cout
<< G4endl
<< "--------------------End of Local Run------------------------";
G4cout << G4endl << "--------------------End of Local Run------------------------";
}
G4cout
<< G4endl
<< " The run consists of " << nofEvents << " "<< runCondition
<< G4endl
<< " Cumulated dose per run, in scoring volume : "
<< G4BestUnit(dose,"Dose") << " rms = " << G4BestUnit(rmsDose,"Dose")
<< G4endl
<< "------------------------------------------------------------"
<< G4endl
<< G4endl;
G4cout << G4endl << " The run consists of " << nofEvents << " " << runCondition << G4endl
<< " Cumulated dose per run, in scoring volume : " << G4BestUnit(dose, "Dose")
<< " rms = " << G4BestUnit(rmsDose, "Dose") << G4endl
<< "------------------------------------------------------------" << G4endl << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::AddEdep(G4double edep)
{
fEdep += edep;
fEdep2 += edep*edep;
fEdep += edep;
fEdep2 += edep * edep;
fEdepPerEvent.AddValue(edep);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
}
} // namespace B1Con
@@ -28,22 +28,21 @@
/// \brief Implementation of the B1::SteppingAction class
#include "SteppingAction.hh"
#include "EventAction.hh"
#include "DetectorConstruction.hh"
#include "G4Step.hh"
#include "DetectorConstruction.hh"
#include "EventAction.hh"
#include "G4Event.hh"
#include "G4RunManager.hh"
#include "G4LogicalVolume.hh"
#include "G4RunManager.hh"
#include "G4Step.hh"
namespace B1
{
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
SteppingAction::SteppingAction(EventAction* eventAction)
: fEventAction(eventAction)
{}
SteppingAction::SteppingAction(EventAction* eventAction) : fEventAction(eventAction) {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -56,9 +55,8 @@ void SteppingAction::UserSteppingAction(const G4Step* step)
}
// get volume of the current step
G4LogicalVolume* volume
= step->GetPreStepPoint()->GetTouchableHandle()
->GetVolume()->GetLogicalVolume();
G4LogicalVolume* volume =
step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
// check if we are in scoring volume
if (volume != fScoringVolume) return;
@@ -70,4 +68,4 @@ void SteppingAction::UserSteppingAction(const G4Step* step)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
}
} // namespace B1