Import Geant4 11.2.0 source tree

This commit is contained in:
Gabriele Cosmo
2023-12-08 10:43:34 +01:00
parent dd1f179cda
commit 860a2b92bf
3962 changed files with 139318 additions and 164259 deletions
@@ -0,0 +1,68 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
/// \file Pol01/src/ActionInitialization.cc
/// \brief Implementation of the ActionInitialization class
#include "ActionInitialization.hh"
#include "DetectorConstruction.hh"
#include "EventAction.hh"
#include "PrimaryGeneratorAction.hh"
#include "RunAction.hh"
#include "SteppingAction.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ActionInitialization::ActionInitialization(DetectorConstruction* det)
: G4VUserActionInitialization(), fDetector(det)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ActionInitialization::BuildForMaster() const
{
auto runAction = new RunAction(fDetector);
SetUserAction(runAction);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ActionInitialization::Build() const
{
PrimaryGeneratorAction* prim = new PrimaryGeneratorAction(fDetector);
SetUserAction(prim);
// set user action classes
RunAction* run = new RunAction(fDetector, prim);
SetUserAction(run);
SetUserAction(new EventAction(run));
SetUserAction(new SteppingAction(fDetector, prim, run));
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -38,6 +38,7 @@
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4RunManager.hh"
#include "G4GeometryManager.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4LogicalVolumeStore.hh"
@@ -58,29 +59,42 @@ DetectorConstruction::DetectorConstruction()
fBoxSizeXY = 50*mm;
fBoxSizeZ = 5*mm;
fWorldSize = 1.*m;
SetTargetMaterial("G4_Fe");
SetWorldMaterial("G4_Galactic");
ConstructMaterials();
fMessenger = new DetectorMessenger(this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::~DetectorConstruction()
{
{
delete fMessenger;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::ConstructMaterials()
{
auto nistManager = G4NistManager::Instance();
fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Fe");
if(fTargetMaterial == nullptr) {
G4cerr << "### ERROR - Material: <"
<< "G4_Fe" << "> not found" << G4endl;
}
fWorldMaterial = nistManager->FindOrBuildMaterial("G4_Galactic");
if(fWorldMaterial == nullptr) {
G4cerr << "### ERROR - Material: <"
<< "G4_Galactic" << "> not found" << G4endl;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4LogicalVolume* lBox;
G4VPhysicalVolume* DetectorConstruction::Construct()
{
// Cleanup old geometry
G4GeometryManager::GetInstance()->OpenGeometry();
G4PhysicalVolumeStore::GetInstance()->Clean();
G4LogicalVolumeStore::GetInstance()->Clean();
G4SolidStore::GetInstance()->Clean();
G4PolarizationManager::GetInstance()->Clean();
// G4PolarizationManager::GetInstance()->Clean();
// World
//
@@ -88,7 +102,7 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
sWorld = new G4Box("World", //name
fWorldSize/2,fWorldSize/2,fWorldSize/2); //dimensions
G4LogicalVolume*
G4LogicalVolume*
lWorld = new G4LogicalVolume(sWorld, //shape
fWorldMaterial, //material
"World"); //name
@@ -100,14 +114,14 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
0, //mother volume
false, //no boolean operation
0); //copy number
// Box
//
//
G4Box*
sBox = new G4Box("Container", //its name
fBoxSizeXY/2.,fBoxSizeXY/2.,fBoxSizeZ/2.);//its dimensions
G4LogicalVolume*
//G4LogicalVolume*
lBox = new G4LogicalVolume(sBox, //its shape
fTargetMaterial, //its material
"theBox"); //its name
@@ -120,12 +134,8 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
false, //no boolean operation
0); //copy number
// register logical Volume in PolarizationManager with zero polarization
G4PolarizationManager * polMgr = G4PolarizationManager::GetInstance();
polMgr->SetVolumePolarization(lBox,G4ThreeVector(0.,0.,0.));
PrintParameters();
//always return the root volume
//
return fWorld;
@@ -133,6 +143,15 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::ConstructSDandField()
{
// register logical Volume in PolarizationManager with zero polarization
G4PolarizationManager * polMgr = G4PolarizationManager::GetInstance();
polMgr->SetVolumePolarization(lBox,G4ThreeVector(0.,0.,0.));
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::PrintParameters()
{
G4cout << "\n The Box is " << G4BestUnit(fBoxSizeXY,"Length")
@@ -151,11 +170,12 @@ void DetectorConstruction::SetTargetMaterial(G4String materialChoice)
if (mat != fTargetMaterial) {
if(mat) {
fTargetMaterial = mat;
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
UpdateGeometry();
} else {
G4cout << "### Warning! Target material: <"
<< materialChoice << "> not found" << G4endl;
}
<< materialChoice << "> not found" << G4endl;
}
}
}
@@ -169,11 +189,12 @@ void DetectorConstruction::SetWorldMaterial(G4String materialChoice)
if (mat != fWorldMaterial) {
if(mat) {
fWorldMaterial = mat;
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
UpdateGeometry();
} else {
G4cout << "### Warning! World material: <"
<< materialChoice << "> not found" << G4endl;
}
<< materialChoice << "> not found" << G4endl;
}
}
}
@@ -181,14 +202,14 @@ void DetectorConstruction::SetWorldMaterial(G4String materialChoice)
void DetectorConstruction::SetSizeXY(G4double value)
{
fBoxSizeXY = value;
fBoxSizeXY = value;
if (fWorldSize<fBoxSizeXY) fWorldSize = 1.2*fBoxSizeXY;
UpdateGeometry();
}
void DetectorConstruction::SetSizeZ(G4double value)
{
fBoxSizeZ = value;
fBoxSizeZ = value;
if (fWorldSize<fBoxSizeZ) fWorldSize = 1.2*fBoxSizeZ;
UpdateGeometry();
}
@@ -199,8 +220,9 @@ void DetectorConstruction::SetSizeZ(G4double value)
void DetectorConstruction::UpdateGeometry()
{
if (fWorld)
G4RunManager::GetRunManager()->DefineWorldVolume(Construct());
// if (fWorld)
// G4RunManager::GetRunManager()->DefineWorldVolume(Construct());
G4RunManager::GetRunManager()->GeometryHasBeenModified();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,79 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
/// \file polarisation/Pol01/src/ProcessesCount.cc
/// \brief Implementation of the ProcessesCount class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ProcessesCount.hh"
#include <iomanip>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ProcessesCount::ProcessesCount(const G4String& name) : G4VAccumulable(name) {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ProcessesCount::Count(const G4String& procName)
{
if (const auto& [it, inserted] = fProcCounter.try_emplace(procName, 1); !inserted) {
it->second++; // Exists already
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ProcessesCount::Print()
{
G4int index = 0;
std::map<G4String, G4int>::iterator it;
for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
G4String procName = it->first;
G4int count = it->second;
G4cout << " " << std::setw(20) << procName << "=" << std::setw(7) << count
<< (++index % 3 == 0 ? "\n" : " ");
}
G4cout << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ProcessesCount::Merge(const G4VAccumulable& other)
{
auto worker = dynamic_cast<const ProcessesCount&>(other);
for (const auto& proc : worker.fProcCounter) {
const auto& [it, inserted] = fProcCounter.emplace(proc);
if (!inserted) {
it->second += proc.second; // proc exists already in master
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -26,7 +26,7 @@
/// \file polarisation/Pol01/src/RunAction.cc
/// \brief Implementation of the RunAction class
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -49,19 +49,32 @@
#include "G4PhysicalConstants.hh"
#include <iomanip>
#include "ProcessesCount.hh"
#include "G4AccumulableManager.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* prim)
: G4UserRunAction(),
fGamma(0), fElectron(0), fPositron(0),
fDetector(det), fPrimary(prim), fProcCounter(0), fAnalysisManager(0),
fTotalEventCount(0),
fPhotonStats(), fElectronStats(), fPositronStats()
: fDetector(det), fPrimary(prim), fAnalysisManager(0),
fTotalEventCount(0)
{
fGamma = G4Gamma::Gamma();
fElectron = G4Electron::Electron();
fPositron = G4Positron::Positron();
auto accumulableManager = G4AccumulableManager::Instance();
auto fPhotonStats = new ParticleStatistics("PhotonStats");
auto fElectronStats = new ParticleStatistics("ElectronStats");
auto fPositronStats = new ParticleStatistics("PositronStats");
auto fProcCounter = new ProcessesCount("ProcCounter");
accumulableManager->RegisterAccumulable(fPhotonStats);
accumulableManager->RegisterAccumulable(fElectronStats);
accumulableManager->RegisterAccumulable(fPositronStats);
accumulableManager->RegisterAccumulable(fProcCounter);
BookHisto();
}
@@ -73,38 +86,40 @@ RunAction::~RunAction()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::BeginOfRunAction(const G4Run* aRun)
{
{
G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
auto accumulableManager = G4AccumulableManager::Instance();
accumulableManager->Reset();
// save Rndm status
// G4RunManager::GetRunManager()->SetRandomNumberStore(false);
// CLHEP::HepRandom::showEngineStatus();
if (fProcCounter) delete fProcCounter;
fProcCounter = new ProcessesCount;
fTotalEventCount = 0;
fPhotonStats.Clear();
fElectronStats.Clear();
fPositronStats.Clear();
// Open file histogram file
fAnalysisManager->OpenFile();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::FillData(const G4ParticleDefinition* particle,
G4double kinEnergy, G4double costheta,
G4double kinEnergy, G4double costheta,
G4double phi,
G4double longitudinalPolarization)
{
auto accManager = G4AccumulableManager::Instance();
G4int id = -1;
if (particle == fGamma) {
fPhotonStats.FillData(kinEnergy, costheta, longitudinalPolarization);
if(fAnalysisManager) { id = 1; }
} else if (particle == fElectron) {
fElectronStats.FillData(kinEnergy, costheta, longitudinalPolarization);
if(fAnalysisManager) { id = 5; }
if (particle == fGamma) {
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("PhotonStats"))->FillData(kinEnergy, costheta, longitudinalPolarization);
if(fAnalysisManager) { id = 1; }
} else if (particle == fElectron) {
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("ElectronStats"))->FillData(kinEnergy, costheta, longitudinalPolarization);
if(fAnalysisManager) { id = 5; }
} else if (particle == fPositron) {
fPositronStats.FillData(kinEnergy, costheta, longitudinalPolarization);
if(fAnalysisManager) { id = 9; }
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("PositronStats"))->FillData(kinEnergy, costheta, longitudinalPolarization);
if(fAnalysisManager) { id = 9; }
}
if(id > 0) {
fAnalysisManager->FillH1(id,kinEnergy,1.0);
@@ -125,13 +140,14 @@ void RunAction::BookHisto()
fAnalysisManager->SetVerboseLevel(1);
// Open file histogram file
fAnalysisManager->OpenFile("pol01");
fAnalysisManager->SetFileName("pol01");
fAnalysisManager->SetFirstHistoId(1);
// Creating an 1-dimensional histograms in the root directory of the tree
const G4String id[] = { "h1", "h2", "h3", "h4", "h5",
const G4String id[] = { "h1", "h2", "h3", "h4", "h5",
"h6", "h7", "h8", "h9", "h10", "h11", "h12"};
const G4String title[] =
const G4String title[] =
{ "Gamma Energy distribution", //1
"Gamma Cos(Theta) distribution", //2
"Gamma Phi angular distribution", //3
@@ -163,96 +179,101 @@ void RunAction::BookHisto()
void RunAction::SaveHisto(G4int nevents)
{
if(fAnalysisManager) {
G4double norm = 1.0/G4double(nevents);
for(int i=0; i<12; ++i) {
fAnalysisManager->ScaleH1(i, norm);
if (IsMaster()) {
G4double norm = 1.0/G4double(nevents);
for(int i=0; i<12; ++i) {
fAnalysisManager->ScaleH1(i, norm);
}
}
fAnalysisManager->Write();
fAnalysisManager->CloseFile();
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::CountProcesses(G4String procName)
void RunAction::CountProcesses(G4String& procName)
{
// is the process already counted ?
// *AS* change to std::map?!
size_t nbProc = fProcCounter->size();
size_t i = 0;
while ((i<nbProc)&&((*fProcCounter)[i]->GetName()!=procName)) i++;
if (i == nbProc) fProcCounter->push_back( new ProcessCount(procName));
(*fProcCounter)[i]->Count();
auto accManager = G4AccumulableManager::Instance();
dynamic_cast<ProcessesCount*>(accManager->GetAccumulable("ProcCounter"))->Count(procName);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::EndOfRunAction(const G4Run* aRun)
{
G4int NbOfEvents = aRun->GetNumberOfEvent();
// Total number of events in run (all threads)
G4int NbOfEvents = aRun->GetNumberOfEventToBeProcessed();
// G4int NbOfEvents = aRun->GetNumberOfEvent();
if (NbOfEvents == 0) return;
G4int prec = G4cout.precision(5);
G4Material* material = fDetector->GetMaterial();
G4double density = material->GetDensity();
G4ParticleDefinition* particle =
fPrimary->GetParticleGun()->GetParticleDefinition();
G4String Particle = particle->GetParticleName();
G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();
G4cout << "\n The run consists of " << NbOfEvents << " "<< Particle << " of "
<< G4BestUnit(energy,"Energy") << " through "
<< G4BestUnit(fDetector->GetBoxSizeZ(),"Length") << " of "
<< material->GetName() << " (density: "
<< G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
//frequency of processes
G4cout << "\n Process calls frequency --->\n";
for (size_t i=0; i< fProcCounter->size();i++) {
G4String procName = (*fProcCounter)[i]->GetName();
G4int count = (*fProcCounter)[i]->GetCounter();
G4cout << "\t" << procName << " = " << count<<"\n";
}
if (fTotalEventCount == 0) return;
G4cout<<" Gamma: \n";
fPhotonStats.PrintResults(fTotalEventCount);
G4cout<<" Electron: \n";
fElectronStats.PrintResults(fTotalEventCount);
G4cout<<" Positron: \n";
fPositronStats.PrintResults(fTotalEventCount);
if (fPrimary != nullptr) {
G4ParticleDefinition* particle =
fPrimary->GetParticleGun()->GetParticleDefinition();
G4String Particle = particle->GetParticleName();
G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();
G4cout << "\n The run consists of " << fTotalEventCount << " "<< Particle << " of "
<< G4BestUnit(energy,"Energy") << " through "
<< G4BestUnit(fDetector->GetBoxSizeZ(),"Length") << " of "
<< material->GetName() << " (density: "
<< G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
}
//cross check from G4EmCalculator
// G4cout << "\n Verification from G4EmCalculator. \n";
// G4cout << "\n Verification from G4EmCalculator. \n";
// G4EmCalculator emCal;
//restore default format
G4cout.precision(prec);
auto accManager = G4AccumulableManager::Instance();
accManager->Merge();
// write out histograms
if (IsMaster()) {
//frequency of processes
G4cout << "\n Process calls frequency --->\n";
dynamic_cast<ProcessesCount*>(accManager->GetAccumulable("ProcCounter"))->Print();
G4cout<<" Gamma: \n";
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("PhotonStats"))->PrintResults(NbOfEvents);
G4cout<<" Electron: \n";
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("ElectronStats"))->PrintResults(NbOfEvents);
G4cout<<" Positron: \n";
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("PositronStats"))->PrintResults(NbOfEvents);
G4cout<<G4endl;
}
//restore default format
G4cout.precision(prec);
// write out histograms
SaveHisto(NbOfEvents);
if (IsMaster()) {
// show Rndm status
CLHEP::HepRandom::showEngineStatus();
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::EventFinished()
{
auto accManager = G4AccumulableManager::Instance();
++fTotalEventCount;
fPhotonStats.EventFinished();
fElectronStats.EventFinished();
fPositronStats.EventFinished();
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("PhotonStats"))->EventFinished();
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("ElectronStats"))->EventFinished();
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("PositronStats"))->EventFinished();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
RunAction::ParticleStatistics::ParticleStatistics()
: fCurrentNumber(0),
RunAction::ParticleStatistics::ParticleStatistics(const G4String& name)
: G4VAccumulable(name),fCurrentNumber(0),
fTotalNumber(0), fTotalNumber2(0),
fSumEnergy(0), fSumEnergy2(0),
fSumPolarization(0), fSumPolarization2(0),
@@ -274,7 +295,7 @@ void RunAction::ParticleStatistics::EventFinished()
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::ParticleStatistics:: FillData(G4double kinEnergy,
void RunAction::ParticleStatistics:: FillData(G4double kinEnergy,
G4double costheta,
G4double longitudinalPolarization)
{
@@ -307,7 +328,7 @@ void RunAction::ParticleStatistics::PrintResults(G4int totalNumberOfEvents)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::ParticleStatistics::Clear()
void RunAction::ParticleStatistics::Reset()
{
fCurrentNumber=0;
fTotalNumber=fTotalNumber2=0;
@@ -317,3 +338,20 @@ void RunAction::ParticleStatistics::Clear()
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::ParticleStatistics::Merge(const G4VAccumulable& other)
{
auto rstat = dynamic_cast<const RunAction::ParticleStatistics&>(other);
fCurrentNumber += rstat.fCurrentNumber;
fTotalNumber += rstat.fTotalNumber;
fTotalNumber2 += rstat.fTotalNumber2;
fSumEnergy += rstat.fSumEnergy;
fSumEnergy2 += rstat.fSumEnergy2;
fSumPolarization += rstat.fSumPolarization;
fSumPolarization2 += rstat.fSumPolarization2;
fSumCosTheta += rstat.fSumCosTheta;
fSumCosTheta2 += rstat.fSumCosTheta2;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......