Import Geant4 11.1.0 source tree

This commit is contained in:
Gabriele Cosmo
2022-12-09 14:43:28 +01:00
parent c07cea1fe0
commit 9f34590941
3810 changed files with 200490 additions and 182326 deletions
@@ -37,22 +37,20 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ActionInitialization::ActionInitialization(DetectorConstruction* detector)
: G4VUserActionInitialization(),
fDetector(detector)
: fDetector(detector)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ActionInitialization::~ActionInitialization()
{}
ActionInitialization::~ActionInitialization() = default;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ActionInitialization::BuildForMaster() const
{
// Histo manager
HistoManager* histo = new HistoManager();
auto histo = new HistoManager();
// Actions
SetUserAction(new RunAction(histo));
}
@@ -62,20 +60,20 @@ void ActionInitialization::BuildForMaster() const
void ActionInitialization::Build() const
{
// Histo manager
HistoManager* histo = new HistoManager();
auto histo = new HistoManager();
// Actions
//
SetUserAction(new PrimaryGeneratorAction(fDetector));
RunAction* runAction = new RunAction(histo);
auto runAction = new RunAction(histo);
SetUserAction(runAction);
EventAction* eventAction = new EventAction(runAction, histo);
auto eventAction = new EventAction(runAction, histo);
SetUserAction(eventAction);
SteppingAction* steppingAction = new SteppingAction(fDetector, eventAction);
auto steppingAction = new SteppingAction(fDetector, eventAction);
SetUserAction(steppingAction);
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -25,10 +25,6 @@
//
/// \file DetectorConstruction.cc
/// \brief Implementation of the DetectorConstruction class
//
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -58,27 +54,14 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::DetectorConstruction()
:G4VUserDetectorConstruction(),
fAbsorberMaterial(0),fGapMaterial(0),fDefaultMaterial(0),
fSolidWorld(0),fLogicWorld(0),fPhysiWorld(0),
fSolidCalor(0),fLogicCalor(0),fPhysiCalor(0),
fSolidLayer(0),fLogicLayer(0),fPhysiLayer(0),
fSolidAbsorber(0),fLogicAbsorber(0),fPhysiAbsorber(0),
fSolidGap (0),fLogicGap (0),fPhysiGap (0),
fDetectorMessenger(0)
{
// default parameter values of the calorimeter
fAbsorberThickness = 10.*mm;
fGapThickness = 5.*mm;
fNbOfLayers = 10;
fCalorSizeYZ = 10.*cm;
ComputeCalorParameters();
// materials
DefineMaterials();
SetAbsorberMaterial("G4_Pb");
SetGapMaterial("G4_lAr");
// create commands for interactive definition of the calorimeter
fDetectorMessenger = new DetectorMessenger(this);
}
@@ -86,7 +69,9 @@ DetectorConstruction::DetectorConstruction()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::~DetectorConstruction()
{ delete fDetectorMessenger;}
{
delete fDetectorMessenger;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -98,24 +83,23 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::DefineMaterials()
{
// use G4-NIST materials data base
//
G4NistManager* man = G4NistManager::Instance();
fDefaultMaterial = man->FindOrBuildMaterial("G4_Galactic");
man->FindOrBuildMaterial("G4_Pb");
man->FindOrBuildMaterial("G4_lAr");
{
// use G4-NIST materials data base
//
G4NistManager* man = G4NistManager::Instance();
fDefaultMaterial = man->FindOrBuildMaterial("G4_Galactic");
man->FindOrBuildMaterial("G4_Pb");
man->FindOrBuildMaterial("G4_lAr");
// print table
//
G4cout << *(G4Material::GetMaterialTable()) << G4endl;
// print table
//
G4cout << *(G4Material::GetMaterialTable()) << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* DetectorConstruction::ConstructCalorimeter()
{
// Clean old geometry, if any
//
G4GeometryManager::GetInstance()->OpenGeometry();
@@ -125,126 +109,128 @@ G4VPhysicalVolume* DetectorConstruction::ConstructCalorimeter()
// complete the Calor parameters definition
ComputeCalorParameters();
//
//
// World
//
fSolidWorld = new G4Box("World", //its name
fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //its size
fSolidWorld = new G4Box("World", //its name
fWorldSizeX/2,fWorldSizeYZ/2,fWorldSizeYZ/2); //its size
fLogicWorld = new G4LogicalVolume(fSolidWorld, //its solid
fDefaultMaterial, //its material
"World"); //its name
fPhysiWorld = new G4PVPlacement(0, //no rotation
fPhysiWorld = new G4PVPlacement(nullptr, //no rotation
G4ThreeVector(), //at (0,0,0)
fLogicWorld, //its logical volume
fLogicWorld, //its logical volume
"World", //its name
0, //its mother volume
false, //no boolean operation
nullptr, //its mother volume
false, //no boolean operation
0); //copy number
//
// Calorimeter
//
fSolidCalor=0; fLogicCalor=0; fPhysiCalor=0;
fSolidLayer=0; fLogicLayer=0; fPhysiLayer=0;
if (fCalorThickness > 0.)
{ fSolidCalor = new G4Box("Calorimeter", //its name
fCalorThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2);//size
fLogicCalor = new G4LogicalVolume(fSolidCalor, //its solid
fDefaultMaterial, //its material
"Calorimeter"); //its name
fPhysiCalor = new G4PVPlacement(0, //no rotation
G4ThreeVector(), //at (0,0,0)
fLogicCalor, //its logical volume
"Calorimeter", //its name
fLogicWorld, //its mother volume
false, //no boolean operation
0); //copy number
//
// Layer
//
// Calorimeter
//
fSolidCalor = nullptr; fLogicCalor = nullptr; fPhysiCalor = nullptr;
fSolidLayer = nullptr; fLogicLayer = nullptr; fPhysiLayer = nullptr;
if (fCalorThickness > 0.) {
fSolidCalor = new G4Box("Calorimeter", //its name
fCalorThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2); //size
fLogicCalor = new G4LogicalVolume(fSolidCalor, //its solid
fDefaultMaterial, //its material
"Calorimeter"); //its name
fPhysiCalor = new G4PVPlacement(nullptr, //no rotation
G4ThreeVector(), //at (0,0,0)
fLogicCalor, //its logical volume
"Calorimeter", //its name
fLogicWorld, //its mother volume
false, //no boolean operation
0); //copy number
//
// Layer
//
fSolidLayer = new G4Box("Layer", //its name
fLayerThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2); //size
fLogicLayer = new G4LogicalVolume(fSolidLayer, //its solid
fDefaultMaterial, //its material
"Layer"); //its name
if (fNbOfLayers > 1) {
fPhysiLayer = new G4PVReplica("Layer", //its name
fLogicLayer, //its logical volume
fLogicCalor, //its mother
kXAxis, //axis of replication
fNbOfLayers, //number of replica
fLayerThickness); //witdth of replica
}
else {
fPhysiLayer = new G4PVPlacement(nullptr, //no rotation
G4ThreeVector(), //at (0,0,0)
fLogicLayer, //its logical volume
"Layer", //its name
fLogicCalor, //its mother volume
false, //no boolean operation
0); //copy number
}
}
//
fSolidLayer = new G4Box("Layer", //its name
fLayerThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2); //size
fLogicLayer = new G4LogicalVolume(fSolidLayer, //its solid
fDefaultMaterial, //its material
"Layer"); //its name
if (fNbOfLayers > 1)
fPhysiLayer = new G4PVReplica("Layer", //its name
fLogicLayer, //its logical volume
fLogicCalor, //its mother
kXAxis, //axis of replication
fNbOfLayers, //number of replica
fLayerThickness); //witdth of replica
else
fPhysiLayer = new G4PVPlacement(0, //no rotation
G4ThreeVector(), //at (0,0,0)
fLogicLayer, //its logical volume
"Layer", //its name
fLogicCalor, //its mother volume
false, //no boolean operation
0); //copy number
}
//
// Absorber
//
fSolidAbsorber=0; fLogicAbsorber=0; fPhysiAbsorber=0;
if (fAbsorberThickness > 0.)
{ fSolidAbsorber = new G4Box("Absorber", //its name
fAbsorberThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2);
fLogicAbsorber = new G4LogicalVolume(fSolidAbsorber, //its solid
fAbsorberMaterial, //its material
fAbsorberMaterial->GetName());//name
fPhysiAbsorber = new G4PVPlacement(0, //no rotation
G4ThreeVector(-fGapThickness/2,0.,0.), //its position
fLogicAbsorber, //its logical volume
fAbsorberMaterial->GetName(), //its name
fLogicLayer, //its mother
false, //no boulean operat
0); //copy number
}
//
fSolidAbsorber = nullptr; fLogicAbsorber = nullptr; fPhysiAbsorber = nullptr;
if (fAbsorberThickness > 0.) {
fSolidAbsorber = new G4Box("Absorber", //its name
fAbsorberThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2); //size
fLogicAbsorber = new G4LogicalVolume(fSolidAbsorber, //its solid
fAbsorberMaterial, //its material
fAbsorberMaterial->GetName()); //name
fPhysiAbsorber = new G4PVPlacement(nullptr, //no rotation
G4ThreeVector(-fGapThickness/2,0.,0.), //its position
fLogicAbsorber, //its logical volume
fAbsorberMaterial->GetName(), //its name
fLogicLayer, //its mother
false, //no boulean operat
0); //copy number
}
//
// Gap
//
fSolidGap=0; fLogicGap=0; fPhysiGap=0;
if (fGapThickness > 0.)
{ fSolidGap = new G4Box("Gap",
fGapThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2);
fLogicGap = new G4LogicalVolume(fSolidGap,
fGapMaterial,
fGapMaterial->GetName());
fPhysiGap = new G4PVPlacement(0, //no rotation
G4ThreeVector(fAbsorberThickness/2,0.,0.), //its position
fLogicGap, //its logical volume
fGapMaterial->GetName(), //its name
fLogicLayer, //its mother
false, //no boulean operat
0); //copy number
}
PrintCalorParameters();
//
fSolidGap = nullptr; fLogicGap = nullptr; fPhysiGap = nullptr;
if (fGapThickness > 0.) {
fSolidGap = new G4Box("Gap",
fGapThickness/2,fCalorSizeYZ/2,fCalorSizeYZ/2);
fLogicGap = new G4LogicalVolume(fSolidGap,
fGapMaterial,
fGapMaterial->GetName());
fPhysiGap = new G4PVPlacement(nullptr, //no rotation
G4ThreeVector(fAbsorberThickness/2,0.,0.), //its position
fLogicGap, //its logical volume
fGapMaterial->GetName(), //its name
fLogicLayer, //its mother
false, //no boulean operat
0); //copy number
}
PrintCalorParameters();
//
// Visualization attributes
//
fLogicWorld->SetVisAttributes (G4VisAttributes::GetInvisible());
G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
auto simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
simpleBoxVisAtt->SetVisibility(true);
fLogicCalor->SetVisAttributes(simpleBoxVisAtt);
@@ -260,54 +246,47 @@ void DetectorConstruction::PrintCalorParameters()
{
G4cout << "\n------------------------------------------------------------"
<< "\n---> The calorimeter is " << fNbOfLayers << " layers of: [ "
<< fAbsorberThickness/mm << "mm of " << fAbsorberMaterial->GetName()
<< fAbsorberThickness/mm << "mm of " << fAbsorberMaterial->GetName()
<< " + "
<< fGapThickness/mm << "mm of " << fGapMaterial->GetName() << " ] "
<< fGapThickness/mm << "mm of " << fGapMaterial->GetName() << " ] "
<< "\n------------------------------------------------------------\n";
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetAbsorberMaterial(G4String materialChoice)
{
// search the material by its name
G4Material* pttoMaterial =
G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
if (pttoMaterial)
{
fAbsorberMaterial = pttoMaterial;
if ( fLogicAbsorber )
{
fLogicAbsorber->SetMaterial(fAbsorberMaterial);
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetGapMaterial(G4String materialChoice)
void DetectorConstruction::SetAbsorberMaterial(const G4String& materialChoice)
{
// search the material by its name
G4Material* pttoMaterial =
G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
if (pttoMaterial)
{
fGapMaterial = pttoMaterial;
if ( fLogicGap )
{
fLogicGap->SetMaterial(fGapMaterial);
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
}
auto material = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
if (material != nullptr) {
fAbsorberMaterial = material;
if (fLogicAbsorber != nullptr) {
fLogicAbsorber->SetMaterial(fAbsorberMaterial);
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetAbsorberThickness(G4double val)
void DetectorConstruction::SetGapMaterial(const G4String& materialChoice)
{
auto material = G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
if (material != nullptr) {
fGapMaterial = material;
if ( fLogicGap != nullptr) {
fLogicGap->SetMaterial(fGapMaterial);
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetAbsorberThickness(G4double value)
{
// change Absorber thickness and recompute the calorimeter parameters
fAbsorberThickness = val;
fAbsorberThickness = value;
if ( G4StateManager::GetStateManager()->GetCurrentState() != G4State_PreInit ) {
G4RunManager::GetRunManager()->ReinitializeGeometry();
}
@@ -315,10 +294,10 @@ void DetectorConstruction::SetAbsorberThickness(G4double val)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetGapThickness(G4double val)
void DetectorConstruction::SetGapThickness(G4double value)
{
// change Gap thickness and recompute the calorimeter parameters
fGapThickness = val;
fGapThickness = value;
if ( G4StateManager::GetStateManager()->GetCurrentState() != G4State_PreInit ) {
G4RunManager::GetRunManager()->ReinitializeGeometry();
}
@@ -326,10 +305,10 @@ void DetectorConstruction::SetGapThickness(G4double val)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetCalorSizeYZ(G4double val)
void DetectorConstruction::SetCalorSizeYZ(G4double value)
{
// change the transverse size and recompute the calorimeter parameters
fCalorSizeYZ = val;
fCalorSizeYZ = value;
if ( G4StateManager::GetStateManager()->GetCurrentState() != G4State_PreInit ) {
G4RunManager::GetRunManager()->ReinitializeGeometry();
}
@@ -337,9 +316,9 @@ void DetectorConstruction::SetCalorSizeYZ(G4double val)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetNbOfLayers(G4int val)
void DetectorConstruction::SetNbOfLayers(G4int value)
{
fNbOfLayers = val;
fNbOfLayers = value;
if ( G4StateManager::GetStateManager()->GetCurrentState() != G4State_PreInit ) {
G4RunManager::GetRunManager()->ReinitializeGeometry();
}
@@ -25,10 +25,6 @@
//
/// \file DetectorMessenger.cc
/// \brief Implementation of the DetectorMessenger class
//
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -45,57 +41,48 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorMessenger::DetectorMessenger( DetectorConstruction* Det)
: G4UImessenger(),
fDetector(Det),
fDetDir(0),
fAbsMaterCmd(0),
fGapMaterCmd(0),
fAbsThickCmd(0),
fGapThickCmd(0),
fSizeYZCmd(0),
fNbLayersCmd(0)
{
: fDetector(Det)
{
G4bool broadcast = false;
fDetDir = new G4UIdirectory("/det/",broadcast);
fDetDir->SetGuidance("Detector control");
fAbsMaterCmd = new G4UIcmdWithAString("/det/setAbsMat",this);
fAbsMaterCmd->SetGuidance("Select Material of the Absorber.");
fAbsMaterCmd->SetParameterName("choice",false);
fAbsMaterCmd->SetParameterName("AbsMat",false);
fAbsMaterCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
fGapMaterCmd = new G4UIcmdWithAString("/det/setGapMat",this);
fGapMaterCmd->SetGuidance("Select Material of the Gap.");
fGapMaterCmd->SetParameterName("choice",false);
fGapMaterCmd->SetParameterName("GapMat",false);
fGapMaterCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
fAbsThickCmd = new G4UIcmdWithADoubleAndUnit("/det/setAbsThick",this);
fAbsThickCmd->SetGuidance("Set Thickness of the Absorber");
fAbsThickCmd->SetParameterName("Size",false);
fAbsThickCmd->SetRange("Size>=0.");
fAbsThickCmd->SetParameterName("AbsThick",false);
fAbsThickCmd->SetRange("AbsThick>=0.");
fAbsThickCmd->SetUnitCategory("Length");
fAbsThickCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
fGapThickCmd = new G4UIcmdWithADoubleAndUnit("/det/setGapThick",this);
fGapThickCmd->SetGuidance("Set Thickness of the Gap");
fGapThickCmd->SetParameterName("Size",false);
fGapThickCmd->SetRange("Size>=0.");
fGapThickCmd->SetUnitCategory("Length");
fGapThickCmd->SetParameterName("GapThick",false);
fGapThickCmd->SetRange("GapThick>=0.");
fGapThickCmd->SetUnitCategory("Length");
fGapThickCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/det/setSizeYZ",this);
fSizeYZCmd->SetGuidance("Set tranverse size of the calorimeter");
fSizeYZCmd->SetParameterName("Size",false);
fSizeYZCmd->SetRange("Size>0.");
fSizeYZCmd->SetUnitCategory("Length");
fSizeYZCmd->SetParameterName("SizeYZ",false);
fSizeYZCmd->SetRange("SizeYZ>0.");
fSizeYZCmd->SetUnitCategory("Length");
fSizeYZCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
fNbLayersCmd = new G4UIcmdWithAnInteger("/det/setNbOfLayers",this);
fNbLayersCmd->SetGuidance("Set number of layers.");
fNbLayersCmd->SetParameterName("NbLayers",false);
fNbLayersCmd->SetRange("NbLayers>0 && NbLayers<500");
fNbLayersCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -103,34 +90,46 @@ DetectorMessenger::DetectorMessenger( DetectorConstruction* Det)
DetectorMessenger::~DetectorMessenger()
{
delete fNbLayersCmd;
delete fAbsMaterCmd; delete fGapMaterCmd;
delete fAbsThickCmd; delete fGapThickCmd;
delete fSizeYZCmd;
delete fAbsMaterCmd;
delete fGapMaterCmd;
delete fAbsThickCmd;
delete fGapThickCmd;
delete fSizeYZCmd;
delete fDetDir;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
{
if( command == fAbsMaterCmd ) {
void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
{
if( command == fAbsMaterCmd ) {
fDetector->SetAbsorberMaterial(newValue);
}
else if( command == fGapMaterCmd ) {
return;
}
if( command == fGapMaterCmd ) {
fDetector->SetGapMaterial(newValue);
return;
}
else if( command == fAbsThickCmd ) {
fDetector
->SetAbsorberThickness(fAbsThickCmd->GetNewDoubleValue(newValue));
}
else if( command == fGapThickCmd ) {
if( command == fAbsThickCmd ) {
fDetector->SetAbsorberThickness(fAbsThickCmd->GetNewDoubleValue(newValue));
return;
}
if( command == fGapThickCmd ) {
fDetector->SetGapThickness(fGapThickCmd->GetNewDoubleValue(newValue));
return;
}
else if( command == fSizeYZCmd ) {
if( command == fSizeYZCmd ) {
fDetector->SetCalorSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));
}
else if( command == fNbLayersCmd ) {
return;
}
if( command == fNbLayersCmd ) {
fDetector->SetNbOfLayers(fNbLayersCmd->GetNewIntValue(newValue));
return;
}
}
@@ -28,7 +28,7 @@
//
//
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -43,30 +43,25 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
EventAction::EventAction(RunAction* run, HistoManager* histo)
:G4UserEventAction(),
fRunAct(run),fHistoManager(histo),
fEnergyAbs(0.), fEnergyGap(0.),
fTrackLAbs(0.), fTrackLGap(0.),
fPrintModulo(0)
{
fPrintModulo = 100; }
: fRunAct(run),fHistoManager(histo)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
EventAction::~EventAction()
{ }
EventAction::~EventAction() = default;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void EventAction::BeginOfEventAction(const G4Event* evt)
{
{
G4int evtNb = evt->GetEventID();
if (evtNb%fPrintModulo == 0)
if (evtNb%fPrintModulo == 0) {
G4cout << "\n---> Begin of event: " << evtNb << G4endl;
// initialisation per event
fEnergyAbs = fEnergyGap = 0.;
fTrackLAbs = fTrackLGap = 0.;
}
// initialisation per event
fEnergyAbs = fEnergyGap = 0.;
fTrackLAbs = fTrackLGap = 0.;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -76,17 +71,17 @@ void EventAction::EndOfEventAction(const G4Event*)
//accumulates statistic
//
fRunAct->FillPerEvent(fEnergyAbs, fEnergyGap, fTrackLAbs, fTrackLGap);
//fill histograms
//
fHistoManager->FillHisto(0, fEnergyAbs);
fHistoManager->FillHisto(1, fEnergyGap);
fHistoManager->FillHisto(2, fTrackLAbs);
fHistoManager->FillHisto(3, fTrackLGap);
//fill ntuple
//
fHistoManager->FillNtuple(fEnergyAbs, fEnergyGap, fTrackLAbs, fTrackLGap);
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -25,10 +25,7 @@
//
/// \file PrimaryGeneratorAction.cc
/// \brief Implementation of the PrimaryGeneratorAction class
//
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -44,10 +41,8 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* DC)
: G4VUserPrimaryGeneratorAction(),
fParticleGun(0),
fDetector(DC)
PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* dc)
: fDetector(dc)
{
G4int n_particle = 1;
fParticleGun = new G4ParticleGun(n_particle);
@@ -56,8 +51,7 @@ PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* DC)
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4String particleName;
G4ParticleDefinition* particle
= particleTable->FindParticle(particleName="e-");
G4ParticleDefinition* particle = particleTable->FindParticle(particleName="e-");
fParticleGun->SetParticleDefinition(particle);
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.));
fParticleGun->SetParticleEnergy(500.*MeV);
@@ -78,7 +72,7 @@ PrimaryGeneratorAction::~PrimaryGeneratorAction()
void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
//this function is called at the begining of event
//
//
fParticleGun->GeneratePrimaryVertex(anEvent);
}
@@ -36,101 +36,136 @@
#include "G4Run.hh"
#include "G4RunManager.hh"
#include "G4AccumulableManager.hh"
#include "G4UnitsTable.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
RunAction::RunAction(HistoManager* histo)
: G4UserRunAction(),
fHistoManager(histo),
fSumEAbs(0.), fSum2EAbs(0.),
fSumEGap(0.), fSum2EGap(0.),
fSumLAbs(0.), fSum2LAbs(0.),
fSumLGap(0.), fSum2LGap(0.)
{}
: fHistoManager(histo)
{
// Register accumulable to the accumulable manager
G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
accumulableManager->RegisterAccumulable(fSumEAbs);
accumulableManager->RegisterAccumulable(fSum2EAbs);
accumulableManager->RegisterAccumulable(fSumEGap);
accumulableManager->RegisterAccumulable(fSum2EGap);
accumulableManager->RegisterAccumulable(fSumLAbs);
accumulableManager->RegisterAccumulable(fSum2LAbs);
accumulableManager->RegisterAccumulable(fSumLGap);
accumulableManager->RegisterAccumulable(fSum2LGap);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
RunAction::~RunAction()
{}
RunAction::~RunAction() = default;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::BeginOfRunAction(const G4Run* aRun)
{
{
G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
//initialize cumulative quantities
//
fSumEAbs = fSum2EAbs =fSumEGap = fSum2EGap = 0.;
fSumLAbs = fSum2LAbs =fSumLGap = fSum2LGap = 0.;
// reset accumulables to their initial values
G4AccumulableManager::Instance()->Reset();
//histograms
//
fHistoManager->Book();
fHistoManager->Book();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::FillPerEvent(G4double EAbs, G4double EGap,
G4double LAbs, G4double LGap)
G4double LAbs, G4double LGap)
{
//accumulate statistic
//
fSumEAbs += EAbs; fSum2EAbs += EAbs*EAbs;
fSumEGap += EGap; fSum2EGap += EGap*EGap;
fSumLAbs += LAbs; fSum2LAbs += LAbs*LAbs;
fSumLGap += LGap; fSum2LGap += LGap*LGap;
fSumLGap += LGap; fSum2LGap += LGap*LGap;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::EndOfRunAction(const G4Run* aRun)
{
G4int NbOfEvents = aRun->GetNumberOfEvent();
if (NbOfEvents == 0) return;
// Merge accumulables
G4AccumulableManager::Instance()->Merge();
G4int nofEvents = aRun->GetNumberOfEvent();
if (nofEvents == 0) {
// close open files
fHistoManager->Save();
return;
}
//compute statistics: mean and rms
//
fSumEAbs /= NbOfEvents; fSum2EAbs /= NbOfEvents;
G4double rmsEAbs = fSum2EAbs - fSumEAbs*fSumEAbs;
if (rmsEAbs >0.) rmsEAbs = std::sqrt(rmsEAbs); else rmsEAbs = 0.;
fSumEGap /= NbOfEvents; fSum2EGap /= NbOfEvents;
G4double rmsEGap = fSum2EGap - fSumEGap*fSumEGap;
if (rmsEGap >0.) rmsEGap = std::sqrt(rmsEGap); else rmsEGap = 0.;
fSumLAbs /= NbOfEvents; fSum2LAbs /= NbOfEvents;
G4double rmsLAbs = fSum2LAbs - fSumLAbs*fSumLAbs;
if (rmsLAbs >0.) rmsLAbs = std::sqrt(rmsLAbs); else rmsLAbs = 0.;
fSumLGap /= NbOfEvents; fSum2LGap /= NbOfEvents;
G4double rmsLGap = fSum2LGap - fSumLGap*fSumLGap;
if (rmsLGap >0.) rmsLGap = std::sqrt(rmsLGap); else rmsLGap = 0.;
auto sumEAbs = fSumEAbs.GetValue();
auto sum2EAbs = fSum2EAbs.GetValue();
sumEAbs /= nofEvents; sum2EAbs /= nofEvents;
auto rmsEAbs = sum2EAbs - sumEAbs*sumEAbs;
if (rmsEAbs >0.) {
rmsEAbs = std::sqrt(rmsEAbs);
} else {
rmsEAbs = 0.;
}
auto sumEGap = fSumEGap.GetValue();
auto sum2EGap = fSum2EGap.GetValue();
sumEGap /= nofEvents; sum2EGap /= nofEvents;
auto rmsEGap = sum2EGap - sumEGap*sumEGap;
if (rmsEGap >0.) {
rmsEGap = std::sqrt(rmsEGap);
} else {
rmsEGap = 0.;
}
auto sumLAbs = fSumLAbs.GetValue();
auto sum2LAbs = fSum2LAbs.GetValue();
sumLAbs /= nofEvents; sum2LAbs /= nofEvents;
auto rmsLAbs = sum2LAbs - sumLAbs*sumLAbs;
if (rmsLAbs >0.) {
rmsLAbs = std::sqrt(rmsLAbs);
} else {
rmsLAbs = 0.;
}
auto sumLGap = fSumLGap.GetValue();
auto sum2LGap = fSum2LGap.GetValue();
sumLGap /= nofEvents; sum2LGap /= nofEvents;
G4double rmsLGap = sum2LGap - sumLGap*sumLGap;
if (rmsLGap >0.) {
rmsLGap = std::sqrt(rmsLGap);
} else {
rmsLGap = 0.;
}
//print
//
G4cout
<< "\n--------------------End of Run------------------------------\n"
<< "\n mean Energy in Absorber : " << G4BestUnit(fSumEAbs,"Energy")
<< " +- " << G4BestUnit(rmsEAbs,"Energy")
<< "\n mean Energy in Gap : " << G4BestUnit(fSumEGap,"Energy")
<< "\n mean Energy in Absorber : " << G4BestUnit(sumEAbs,"Energy")
<< " +- " << G4BestUnit(rmsEAbs,"Energy")
<< "\n mean Energy in Gap : " << G4BestUnit(sumEGap,"Energy")
<< " +- " << G4BestUnit(rmsEGap,"Energy")
<< G4endl;
G4cout
<< "\n mean trackLength in Absorber : " << G4BestUnit(fSumLAbs,"Length")
<< " +- " << G4BestUnit(rmsLAbs,"Length")
<< "\n mean trackLength in Gap : " << G4BestUnit(fSumLGap,"Length")
<< "\n mean trackLength in Absorber : " << G4BestUnit(sumLAbs,"Length")
<< " +- " << G4BestUnit(rmsLAbs,"Length")
<< "\n mean trackLength in Gap : " << G4BestUnit(sumLGap,"Length")
<< " +- " << G4BestUnit(rmsLGap,"Length")
<< "\n------------------------------------------------------------\n"
<< G4endl;
//save histograms
//
fHistoManager->PrintStatistic();
fHistoManager->Save();
fHistoManager->Save();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -25,10 +25,7 @@
//
/// \file SteppingAction.cc
/// \brief Implementation of the SteppingAction class
//
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -41,34 +38,32 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
SteppingAction::SteppingAction(DetectorConstruction* det,
EventAction* evt)
: G4UserSteppingAction(),
fDetector(det), fEventAction(evt)
{ }
SteppingAction::SteppingAction(DetectorConstruction* det, EventAction* evt)
: fDetector(det), fEventAction(evt)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
SteppingAction::~SteppingAction()
{ }
SteppingAction::~SteppingAction() = default;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SteppingAction::UserSteppingAction(const G4Step* aStep)
{
// get volume of the current step
G4VPhysicalVolume* volume
= aStep->GetPreStepPoint()->GetTouchableHandle()->GetVolume();
G4VPhysicalVolume* volume =
aStep->GetPreStepPoint()->GetTouchableHandle()->GetVolume();
// collect energy and track length step by step
G4double edep = aStep->GetTotalEnergyDeposit();
G4double stepl = 0.;
if (aStep->GetTrack()->GetDefinition()->GetPDGCharge() != 0.)
if (aStep->GetTrack()->GetDefinition()->GetPDGCharge() != 0.) {
stepl = aStep->GetStepLength();
if (volume == fDetector->GetAbsorber()) fEventAction->AddAbs(edep,stepl);
if (volume == fDetector->GetGap()) fEventAction->AddGap(edep,stepl);
}
if (volume == fDetector->GetAbsorber()) { fEventAction->AddAbs(edep,stepl); }
if (volume == fDetector->GetGap()) { fEventAction->AddGap(edep,stepl); }
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......