Import Geant4 11.4.0 source tree

This commit is contained in:
Gabriele Cosmo
2025-12-05 08:54:02 +01:00
parent a499fb82e9
commit b4a16de652
6484 changed files with 232674 additions and 221097 deletions
@@ -25,8 +25,6 @@
//
/// \file ActionInitialization.cc
/// \brief Implementation of the ActionInitialization class
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ActionInitialization.hh"
#include "PrimaryGeneratorAction.hh"
@@ -25,8 +25,6 @@
//
/// \file DetectorConstruction.cc
/// \brief Implementation of the DetectorConstruction class
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "DetectorConstruction.hh"
@@ -71,8 +69,13 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
G4Material* world_mat = nist->FindOrBuildMaterial("G4_Galactic");
G4Material* silicon = nist->FindOrBuildMaterial("G4_Si");
//to use a diamond crystal
G4Element* elC = nist->FindOrBuildElement("C");
G4Material* diamond = new G4Material("G4_Diamond", 3.520*CLHEP::g/CLHEP::cm3, 1);
diamond->AddElement(elC, 1);
//World
G4Box* solidWorld = new G4Box("World", 0.2*CLHEP::m, 0.2*CLHEP::m, 10.*CLHEP::m);
G4Box* solidWorld = new G4Box("World", 0.2*CLHEP::m, 0.2*CLHEP::m, 30.*CLHEP::m);
G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, world_mat, "World");
G4VPhysicalVolume* physWorld = new G4PVPlacement
(0, // no rotation
@@ -135,6 +138,7 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
G4cout << "Crystal size: " << fCrystalSize.x()/CLHEP::mm
<< "x" << fCrystalSize.y()/CLHEP::mm
<< "x" << fCrystalSize.z()/CLHEP::mm << " mm3" << G4endl;
if (fActivateChannelingModel)
{
G4cout << "G4ChannelingFastSimModel activated" << G4endl;
@@ -144,18 +148,36 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
G4cout << "Crystal angleY: " << fAngleY << " rad" << G4endl;
G4cout << "ActivateRadiationModel: " << fActivateRadiationModel << G4endl;
if (fCrystallineUndulatorAmplitude > DBL_EPSILON &&
fCrystallineUndulatorPeriod > DBL_EPSILON) {
G4cout << "Crystalline undulator activated: " << G4endl;
G4cout << "undulator amplitude: "
<< fCrystallineUndulatorAmplitude/CLHEP::nm
<< " nm" << G4endl;
G4cout << "undulator period: "
<< fCrystallineUndulatorPeriod/CLHEP::mm
<< " mm" << G4endl;
G4cout << "undulator phase: "
<< fCrystallineUndulatorPhase
<< " rad" << G4endl;
if(fVirtualCollimatorHalfSize<CLHEP::halfpi)
{
G4cout << "Setting virtual collimator angular radius: "
<< fVirtualCollimatorHalfSize/CLHEP::mrad << " mrad" << G4endl;
}
else
{
G4cout << "No virtual collimator set." << G4endl;
}
if(fCrystalInternalGeometryPath != "")
{
G4cout << "Reading crystal internal geometry activated: " << G4endl;
G4cout << "reading from the file: " << fCrystalInternalGeometryPath << G4endl;
}
else
{
if (fCrystallineUndulatorAmplitude > DBL_EPSILON &&
fCrystallineUndulatorPeriod > DBL_EPSILON) {
G4cout << "Crystalline undulator activated: " << G4endl;
G4cout << "undulator amplitude: "
<< fCrystallineUndulatorAmplitude/CLHEP::nm
<< " nm" << G4endl;
G4cout << "undulator period: "
<< fCrystallineUndulatorPeriod/CLHEP::mm
<< " mm" << G4endl;
G4cout << "undulator phase: "
<< fCrystallineUndulatorPhase
<< " rad" << G4endl;
}
}
G4cout << G4endl;
@@ -218,16 +240,26 @@ void DetectorConstruction::ConstructSDandField()
//setting bending angle of the crystal planes (default is 0)
channelingModel->GetCrystalData()->SetBendingAngle(fBendingAngle, fLogicCrystal);
//setting crystalline undulator parameters
//NOTE: they are incompatible with a bent crystal
if (fCrystallineUndulatorAmplitude > DBL_EPSILON &&
fCrystallineUndulatorPeriod > DBL_EPSILON)
//reading internal crystal geometry from file has a priority vs its setup from parameters;
//it is used to setup a realistic undulator, but may be used also for a bent crystal geometry
if(fCrystalInternalGeometryPath != "")
{
channelingModel->GetCrystalData()->SetCrystallineUndulatorParameters(
fCrystallineUndulatorAmplitude,
fCrystallineUndulatorPeriod,
fCrystallineUndulatorPhase,
fLogicCrystal);
channelingModel->GetCrystalData()->
SetCrystallineUndulatorParameters(fLogicCrystal,fCrystalInternalGeometryPath);
}
else
{
//setting crystalline undulator parameters
//NOTE: they are incompatible with a bent crystal
if (fCrystallineUndulatorAmplitude > DBL_EPSILON &&
fCrystallineUndulatorPeriod > DBL_EPSILON)
{
channelingModel->GetCrystalData()->SetCrystallineUndulatorParameters(
fCrystallineUndulatorAmplitude,
fCrystallineUndulatorPeriod,
fCrystallineUndulatorPhase,
fLogicCrystal);
}
}
/*
@@ -336,6 +368,35 @@ void DetectorConstruction::ConstructSDandField()
*/
channelingModel->GetRadiationModel()->SetMinPhotonEnergy(fMinPhotonEnergy);
/*
Set the maximal energy in the spectrum to be written into the output file.
Note: the minimal energy written is equal to fMinPhotonEnergy.
Note: unlike the minimal energy, the maximal one is just a scoring parameter,
it does not modify the simulations.
*/
if(fMaxPhotonEnergySpectrum > fMinPhotonEnergy + DBL_EPSILON)
{
channelingModel->GetRadiationModel()->SetMaxPhotonEnergy(fMaxPhotonEnergySpectrum);
}
else
{
G4cout << "Warning: the maximal energy in BK spectrum <= the minimal energy." << G4endl;
G4cout << "The maximal energy is default now." << G4endl;
G4cout << " "<< G4endl;
}
/*
Set the maximal energy in the spectrum to be written into the output file
*/
channelingModel->GetRadiationModel()->SetNBinsSpectrum(fNBinsSpectrum);
/*
Set the angular size of virtual round collimator to accumulate the spectrum the output file
to be written into the output file. Default is infinite => no collimator.
*/
channelingModel->GetRadiationModel()->
SetRoundVirtualCollimator(fVirtualCollimatorHalfSize,-fAngleX,fAngleY);
/*
Set the number of trajectory steps after which the radiation probability
check (whether the probability is below or above of the threshold) is performed;
@@ -24,11 +24,7 @@
// ********************************************************************
//
/// \file DetectorConstructionMessenger.cc
/// \brief Implementation of the DetectorConstruction messenger class
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
/// \brief Implementation of the DetectorConstructionMessenger class
#include "DetectorConstructionMessenger.hh"
#include "DetectorConstruction.hh"
@@ -141,6 +137,14 @@ fDetector(det)
fPotentialPathCmd->SetParameterName("channelingDataPath",false);
fPotentialPathCmd->SetDefaultValue("");
fCrystalInternalGeometryPathCmd =
new G4UIcmdWithAString("/crystal/setCrystalInternalGeometryPath",this);
fCrystalInternalGeometryPathCmd->
SetGuidance("Set the path where to find the available data "
"for the crystal internal geometry");
fCrystalInternalGeometryPathCmd->SetParameterName("CrystalInternalGeometryPath",false);
fCrystalInternalGeometryPathCmd->SetDefaultValue("");
fChannelingModelCmd = new G4UIcmdWithABool("/crystal/setChannelingModel", this);
fChannelingModelCmd->SetGuidance("Activate/deactivate G4ChannelingFastSimModel");
fChannelingModelCmd->SetParameterName("ChannelingModel",true);
@@ -151,6 +155,14 @@ fDetector(det)
fRadModelCmd->SetParameterName("ActivateRadiationModel",true);
fRadModelCmd->SetDefaultValue(false);
fVirtualCollimatorHalfSize =
new G4UIcmdWithADoubleAndUnit("/crystal/setVirtualCollimatorHalfSize",this);
fVirtualCollimatorHalfSize->SetGuidance("Set virtual collimator angular half size");
fVirtualCollimatorHalfSize->SetUnitCategory("Angle");
fVirtualCollimatorHalfSize->SetRange("VirtualCollimatorHalfSize > 0");
fVirtualCollimatorHalfSize->SetParameterName("VirtualCollimatorHalfSize",false);
fVirtualCollimatorHalfSize->AvailableForStates(G4State_PreInit,G4State_Idle);
fMinPhotonEnergyCmd =
new G4UIcmdWithADoubleAndUnit("/crystal/setMinPhotonEnergy",this);
fMinPhotonEnergyCmd->
@@ -160,7 +172,29 @@ fDetector(det)
fMinPhotonEnergyCmd->SetUnitCategory("Energy");
fMinPhotonEnergyCmd->SetRange("MinPhotonEnergy > 0");
fMinPhotonEnergyCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
fMaxPhotonEnergySpectrumCmd =
new G4UIcmdWithADoubleAndUnit("/crystal/MaxBKPhotonEnergyInSpectrum",this);
fMaxPhotonEnergySpectrumCmd->
SetGuidance("Set the high energy threshold for the spectrum of"
"Baier-Katkov pseudophotons to be scored "
"(only scoring, does not influence simulations)");
fMaxPhotonEnergySpectrumCmd->SetParameterName("MaxBKPhotonEnergyInSpectrum",false);
fMaxPhotonEnergySpectrumCmd->SetUnitCategory("Energy");
fMaxPhotonEnergySpectrumCmd->SetRange("MaxBKPhotonEnergyInSpectrum > 0");
fMaxPhotonEnergySpectrumCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
fNBinsSpectrumCmd =
new G4UIcmdWithAnInteger("/crystal/NBinsInSpectrum",this);
fNBinsSpectrumCmd->
SetGuidance("Set the number of bins written in the spectrum of"
"Baier-Katkov pseudophotons to be scored "
"(only scoring, does not influence simulations)."
"Note: the bins are not equidistant.");
fNBinsSpectrumCmd->SetParameterName("NBinsInSpectrum",false);
fNBinsSpectrumCmd->SetRange("NBinsInSpectrum>1");
fNBinsSpectrumCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
fSamplingPhotonsNumberCmd =
new G4UIcmdWithAnInteger("/crystal/setSamplingPhotonsNumber",this);
fSamplingPhotonsNumberCmd->
@@ -401,8 +435,12 @@ DetectorConstructionMessenger::~DetectorConstructionMessenger()
delete fDetectorFrontPosZCmd;
delete fPotentialPathCmd;
delete fCrystalInternalGeometryPathCmd;
delete fVirtualCollimatorHalfSize;
delete fMinPhotonEnergyCmd;
delete fMaxPhotonEnergySpectrumCmd;
delete fNBinsSpectrumCmd;
delete fSamplingPhotonsNumberCmd;
delete fNSmallTrajectoryStepsCmd;
delete fRadiationAngleFactorCmd;
@@ -471,10 +509,21 @@ void DetectorConstructionMessenger::SetNewValue(G4UIcommand* command, G4String n
if (command == fPotentialPathCmd)
{fDetector->SetPotentialPath(newValue);}
if (command == fCrystalInternalGeometryPathCmd)
{fDetector->SetCrystalInternalGeometryPath(newValue);}
if (command == fVirtualCollimatorHalfSize)
{fDetector->SetVirtualCollimatorHalfSize(
fVirtualCollimatorHalfSize->GetNewDoubleValue(newValue));}
if (command == fMinPhotonEnergyCmd)
{fDetector->SetMinPhotonEnergy(
fMinPhotonEnergyCmd->GetNewDoubleValue(newValue));}
if (command == fMaxPhotonEnergySpectrumCmd)
{fDetector->SetMaxBKPhotonEnergyInSpectrum(
fMaxPhotonEnergySpectrumCmd->GetNewDoubleValue(newValue));}
if (command == fNBinsSpectrumCmd)
{fDetector->SetNBinsSpectrum(
fNBinsSpectrumCmd->GetNewIntValue(newValue));}
if (command == fSamplingPhotonsNumberCmd)
{fDetector->SetSamplingPhotonsNumber(
fSamplingPhotonsNumberCmd->GetNewIntValue(newValue));}
@@ -25,8 +25,6 @@
//
/// \file PrimaryGeneratorAction.cc
/// \brief Implementation of the PrimaryGeneratorAction class
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "PrimaryGeneratorAction.hh"
#include "G4Event.hh"
@@ -23,12 +23,15 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
/// \file RunAction.cc
/// \brief Implementation of the RunAction class
#include "RunAction.hh"
#include "G4AnalysisManager.hh"
#include "G4RegionStore.hh"
#include "G4FastSimulationManager.hh"
#include "G4ChannelingFastSimModel.hh"
#include "G4Threading.hh"
#include "G4RunManager.hh"
#include "G4Run.hh"
@@ -47,12 +50,21 @@ RunAction::RunAction()
analysisManager->SetNtupleMerging(false);
#endif
//Creating the ntuple to score the deflection of particles and
//the emitted radiation
//Creating the ntuple to score the particles and the emitted radiation
G4String nTupleName[3] =
{"crystal", "detector", "detector_photons"};
for(G4int i=0; i<3; i++)
//ALL "detector_primaries" ENTER THE CRYSTAL; "detector_photons", "detector_secondaries"
//are their daughters.
//CAUTION: if a primary did not cross the crystal,
//this primary and its daughters are written ONLY in missed_crystal
G4String nTupleName[5] =
{"crystal",
"detector_primaries",
"detector_photons",
"detector_secondaries",
"missed_crystal"};
for(G4int i=0; i<5; i++)
{
analysisManager->CreateNtuple(nTupleName[i],nTupleName[i]);
analysisManager->CreateNtupleIColumn("eventID");
@@ -66,6 +78,14 @@ RunAction::RunAction()
analysisManager->CreateNtupleIColumn("particleID");
analysisManager->CreateNtupleIColumn("parentID");
if(i==1)
{
analysisManager->CreateNtupleDColumn("incoming_angle_x");
analysisManager->CreateNtupleDColumn("deflection_angle_x");
analysisManager->CreateNtupleDColumn("incoming_angle_y");
analysisManager->CreateNtupleDColumn("deflection_angle_y");
}
analysisManager->FinishNtuple();
}
}
@@ -78,6 +98,10 @@ void RunAction::BeginOfRunAction(const G4Run*)
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
G4String fileName = "results.root";
analysisManager->OpenFile(fileName);
//delete the spectrum temporary files if they exist
std::string filename = "Spectrum_"+std::to_string(G4Threading::G4GetThreadId())+".dat";
std::remove(filename.c_str());
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -87,6 +111,36 @@ void RunAction::EndOfRunAction(const G4Run*)
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
analysisManager->Write();
analysisManager->CloseFile();
//getting internal data of G4ChannelingFastSimModel
G4RegionStore* regionStore = G4RegionStore::GetInstance();
G4Region* regionCh = regionStore->GetRegion("Crystal");
G4bool someflag=false;
G4ChannelingFastSimModel* channeling =
static_cast<G4ChannelingFastSimModel*>
(regionCh->GetFastSimulationManager()->GetFastSimulationModel("ChannelingModel",
0,someflag));
if (!IsMaster() && channeling->GetIfRadiationModelActive())
{
std::vector<G4double> photonEnergyInSpectrum =
channeling->GetRadiationModel()->GetPhotonEnergyInSpectrum();
std::vector<G4double> spectrum =
channeling->GetRadiationModel()->GetTotalSpectrum();
G4int threadID = G4Threading::G4GetThreadId();
std::ofstream file1;
file1.open("Spectrum_"+std::to_string(threadID)+".dat");
file1 << std::setprecision(16);
for(std::size_t i = 0; i<spectrum.size(); i++)
{file1 << photonEnergyInSpectrum[i] << " " << spectrum[i] << G4endl;}
file1.close();
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -23,7 +23,6 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
/// \file SteppingAction.cc
/// \brief Implementation of the SteppingAction class
@@ -104,19 +103,43 @@ void SteppingAction::UserSteppingAction(const G4Step* step)
if(volumeName=="Crystal")
{
iTuple = 0;
//remember values for output at the detector ONLY FOR PRIMARIES
if(particleID == 1)
{
eventID_in = eventID;
angle_x_in = angle_x;
angle_y_in = angle_y;
}
}
else if(volumeName=="Detector")
{
if(particleName=="gamma")
if(eventID_in == eventID) //FOR THE EVENTS WHERE PRIMARIES PASS THE CRYSTAL
{
iTuple = 2;
if(particleName=="gamma")
{
iTuple = 2;
}
else if(particleID == 1) //primaries
{
iTuple = 1;
}
else //secondaries
{
iTuple = 3;
}
}
else
{
iTuple = 1;
iTuple = 4;
}
}
//ALL "detector_primaries" ENTER THE CRYSTAL; "detector_photons", "detector_secondaries"
//are their daughters.
//CAUTION: if a primary did not cross the crystal,
//this primary and its daughters are written ONLY in missed_crystal
//saving result to root
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
analysisManager->FillNtupleIColumn(iTuple,0,eventID);
@@ -129,6 +152,16 @@ void SteppingAction::UserSteppingAction(const G4Step* step)
analysisManager->FillNtupleSColumn(iTuple,7,particleName);
analysisManager->FillNtupleIColumn(iTuple,8,particleID);
analysisManager->FillNtupleIColumn(iTuple,9,parentID);
//ONLY FOR PRIMARIES PASSED THROUGH THE CRYSTAL
if(iTuple == 1)
{
analysisManager->FillNtupleDColumn(iTuple,10,angle_x_in);
analysisManager->FillNtupleDColumn(iTuple,11,angle_x-angle_x_in);
analysisManager->FillNtupleDColumn(iTuple,12,angle_y_in);
analysisManager->FillNtupleDColumn(iTuple,13,angle_y-angle_y_in);
}
analysisManager->AddNtupleRow(iTuple);
}
}