Import Geant4 10.7.0 source tree

This commit is contained in:
Gabriele Cosmo
2020-12-04 12:30:43 +01:00
parent 67ba86d073
commit dab42d2018
3770 changed files with 226369 additions and 286486 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,175 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// Hadrontherapy advanced example for Geant4
// See more at: https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
#include "BESTPassiveProtonBeamLineMessenger.hh"
#include "BESTPassiveProtonBeamLine.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithAString.hh"
#include "G4SystemOfUnits.hh"
BESTPassiveProtonBeamLineMessenger::BESTPassiveProtonBeamLineMessenger(BESTPassiveProtonBeamLine* beamLine)
:passiveProton(beamLine)
{
changeTheBeamLineDir = new G4UIdirectory("/ChangeBeamLine/");
changeTheBeamLineDir -> SetGuidance("Command to change the transport beam line");
changeTheBeamLineNameCmd = new G4UIcmdWithAString("/ChangeBeamLine/beamLineName",this);
changeTheBeamLineNameCmd -> SetGuidance("Insert the name of the beam line you want simulate");
changeTheBeamLineNameCmd -> SetParameterName("List",false);
changeTheBeamLineNameCmd -> AvailableForStates(G4State_PreInit);
modulatorDir = new G4UIdirectory("/modulator/");
modulatorDir -> SetGuidance("Command to rotate the modulator wheel");
beamLineDir = new G4UIdirectory("/beamLine/");
beamLineDir -> SetGuidance("set specification of range shifter");
rangeShifterDir = new G4UIdirectory("/beamLine/BESTRangeShifter/");
rangeShifterDir -> SetGuidance("set specification of range shifter");
firstScatteringFoilDir = new G4UIdirectory("/beamLine/BESTScatteringFoil1/");
firstScatteringFoilDir -> SetGuidance("set specification of first scattering foil");
secondScatteringFoilDir = new G4UIdirectory("/beamLine/BESTScatteringFoil2/");
secondScatteringFoilDir -> SetGuidance("set specification of second scattering foil");
rangeStopperDir = new G4UIdirectory("/beamLine/BESTStopper/");
rangeStopperDir -> SetGuidance("set specification of stopper");
finalCollimatorDir = new G4UIdirectory("/beamLine/BESTFinalCollimator/");
finalCollimatorDir -> SetGuidance("set specification of final collimator");
modulatorAngleCmd = new G4UIcmdWithADoubleAndUnit("/modulator/angle",this);
modulatorAngleCmd -> SetGuidance("Set Modulator Angle");
modulatorAngleCmd -> SetParameterName("Size",false);
modulatorAngleCmd -> SetRange("Size>=0.");
modulatorAngleCmd -> SetUnitCategory("Angle");
modulatorAngleCmd -> AvailableForStates(G4State_Idle);
rangeShifterMatCmd = new G4UIcmdWithAString("/beamLine/BESTRangeShifter/RSMat",this);
rangeShifterMatCmd -> SetGuidance("Set material of range shifter");
rangeShifterMatCmd -> SetParameterName("choice",false);
rangeShifterMatCmd -> AvailableForStates(G4State_Idle);
rangeShifterXSizeCmd = new G4UIcmdWithADoubleAndUnit("/beamLine/BESTRangeShifter/thickness",this);
rangeShifterXSizeCmd -> SetGuidance("Set half of the thickness of range shifter along X axis");
rangeShifterXSizeCmd -> SetParameterName("Size",false);
rangeShifterXSizeCmd -> SetDefaultUnit("mm");
rangeShifterXSizeCmd -> SetUnitCandidates("mm cm m");
rangeShifterXSizeCmd -> AvailableForStates(G4State_Idle);
rangeShifterXPositionCmd = new G4UIcmdWithADoubleAndUnit("/beamLine/BESTRangeShifter/position",this);
rangeShifterXPositionCmd -> SetGuidance("Set position of range shifter");
rangeShifterXPositionCmd -> SetParameterName("Size",false);
rangeShifterXPositionCmd -> SetDefaultUnit("mm");
rangeShifterXPositionCmd -> SetUnitCandidates("mm cm m");
rangeShifterXPositionCmd -> AvailableForStates(G4State_Idle);
firstScatteringFoilXSizeCmd = new G4UIcmdWithADoubleAndUnit("/beamLine/BESTScatteringFoil1/thickness",this);
firstScatteringFoilXSizeCmd -> SetGuidance("Set half thickness of first scattering foil");
firstScatteringFoilXSizeCmd -> SetParameterName("Size",false);
firstScatteringFoilXSizeCmd -> SetDefaultUnit("mm");
firstScatteringFoilXSizeCmd -> SetUnitCandidates("mm cm m");
firstScatteringFoilXSizeCmd -> AvailableForStates(G4State_Idle);
secondScatteringFoilXSizeCmd = new G4UIcmdWithADoubleAndUnit("/beamLine/BESTScatteringFoil2/thickness",this);
secondScatteringFoilXSizeCmd -> SetGuidance("Set half thickness of second scattering foil");
secondScatteringFoilXSizeCmd -> SetParameterName("Size",false);
secondScatteringFoilXSizeCmd -> SetDefaultUnit("mm");
secondScatteringFoilXSizeCmd -> SetUnitCandidates("mm cm m");
secondScatteringFoilXSizeCmd -> AvailableForStates(G4State_Idle);
outerRadiusStopperCmd = new G4UIcmdWithADoubleAndUnit("/beamLine/BESTStopper/outRadius",this);
outerRadiusStopperCmd -> SetGuidance("Set size of outer radius");
outerRadiusStopperCmd -> SetParameterName("Size",false);
outerRadiusStopperCmd -> SetDefaultUnit("mm");
outerRadiusStopperCmd -> SetUnitCandidates("mm cm m");
outerRadiusStopperCmd -> AvailableForStates(G4State_Idle);
innerRadiusFinalCollimatorCmd = new G4UIcmdWithADoubleAndUnit("/beamLine/BESTFinalCollimator/halfInnerRad",this);
innerRadiusFinalCollimatorCmd -> SetGuidance("Set size of inner radius ( max 21.5 mm)");
innerRadiusFinalCollimatorCmd -> SetParameterName("Size",false);
innerRadiusFinalCollimatorCmd -> SetDefaultUnit("mm");
innerRadiusFinalCollimatorCmd -> SetUnitCandidates("mm cm m");
innerRadiusFinalCollimatorCmd -> AvailableForStates(G4State_Idle);
}
BESTPassiveProtonBeamLineMessenger::~BESTPassiveProtonBeamLineMessenger()
{
delete innerRadiusFinalCollimatorCmd;
delete outerRadiusStopperCmd;
delete secondScatteringFoilXSizeCmd;
delete firstScatteringFoilXSizeCmd;
delete rangeShifterXPositionCmd;
delete rangeShifterXSizeCmd;
delete rangeShifterMatCmd;
delete modulatorAngleCmd;
delete finalCollimatorDir;
delete rangeStopperDir;
delete secondScatteringFoilDir;
delete firstScatteringFoilDir;
delete rangeShifterDir;
delete beamLineDir;
delete modulatorDir;
}
void BESTPassiveProtonBeamLineMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
{
if( command == modulatorAngleCmd )
{ passiveProton -> SetModulatorAngle
(modulatorAngleCmd -> GetNewDoubleValue(newValue));}
else if( command == rangeShifterMatCmd )
{ passiveProton -> SetRSMaterial(newValue);}
else if( command == rangeShifterXSizeCmd )
{ passiveProton -> SetRangeShifterXSize
(rangeShifterXSizeCmd -> GetNewDoubleValue(newValue));}
else if( command == firstScatteringFoilXSizeCmd )
{ passiveProton -> SetFirstScatteringFoilXSize
(firstScatteringFoilXSizeCmd -> GetNewDoubleValue(newValue));}
else if( command == secondScatteringFoilXSizeCmd )
{ passiveProton -> SetSecondScatteringFoilXSize
(secondScatteringFoilXSizeCmd -> GetNewDoubleValue(newValue));}
else if( command == outerRadiusStopperCmd )
{ passiveProton -> SetOuterRadiusStopper(
outerRadiusStopperCmd -> GetNewDoubleValue(newValue));}
else if( command == innerRadiusFinalCollimatorCmd )
{ passiveProton -> SetInnerRadiusFinalCollimator
(innerRadiusFinalCollimatorCmd -> GetNewDoubleValue(newValue));}
}
@@ -52,7 +52,7 @@
#include "HadrontherapyMatrix.hh"
#include "HadrontherapyLet.hh"
#include "PassiveProtonBeamLine.hh"
#include "BESTPassiveProtonBeamLine.hh"
#include "HadrontherapyMatrix.hh"
#include "HadrontherapyRBE.hh"
@@ -231,8 +231,10 @@ G4bool HadrontherapyDetectorSD::ProcessHits(G4Step* aStep, G4TouchableHistory* )
G4Exception("HadrontherapyDetectorSD::ProcessHits", "NoAccumulable", FatalException, "Accumulable RBE not found.");
}
}
fRBEAccumulable->Accumulate(kineticEnergy / A, energyDeposit, DX, Z, i, j, k);
if (A>0) //protect against gammas, e- , etc
{
fRBEAccumulable->Accumulate(kineticEnergy / A, energyDeposit, DX, Z, i, j, k);
}
}
@@ -84,8 +84,8 @@ void HadrontherapyEventAction::EndOfEventAction(const G4Event* evt)
// Fill the matrix with the information: voxel and associated energy deposit
// in the detector at the end of the event
G4int HitCount = CHC -> entries();
for (G4int h=0; h<HitCount; h++)
size_t HitCount = CHC -> entries();
for (size_t h=0; h<HitCount; h++)
{
G4int i = ((*CHC)[h]) -> GetXID();
G4int j = ((*CHC)[h]) -> GetYID();
@@ -32,6 +32,7 @@
#include "HadrontherapyDetectorROGeometry.hh"
#include "HadrontherapyTIFPAPassiveProtonBeamLine.hh"
#include "PassiveProtonBeamLine.hh"
#include "BESTPassiveProtonBeamLine.hh"
#include "PassiveCarbonBeamLine.hh"
#include "LaserDrivenBeamLine.hh"
#include "G4RunManager.hh"
@@ -67,6 +68,11 @@ void HadrontherapyGeometryController::SetGeometry(G4String name)
{
registerGeometry(new TrentoPassiveProtonBeamLine());
}
else if(name == "BESTBeamLine")
{
registerGeometry(new BESTPassiveProtonBeamLine());
}
else
{
G4cout <<"Unknown geometry: " << name << ". Geometry not changed." << G4endl;
View File
@@ -52,81 +52,74 @@
/////////////////////////////////////////////////////////////////////////////
HadrontherapyPrimaryGeneratorAction::HadrontherapyPrimaryGeneratorAction()
HadrontherapyPrimaryGeneratorAction::HadrontherapyPrimaryGeneratorAction() :
fNewSource(false)
{
PrimaryGeneratorMessenger = new HadrontherapyPrimaryGeneratorMessenger(this);
SetDefaultPrimaryParticle();
particleGun = new G4GeneralParticleSource();
calculatedPhaseSpaceFileIN = "NULL";
}
/////////////////////////////////////////////////////////////////////////////
HadrontherapyPrimaryGeneratorAction::~HadrontherapyPrimaryGeneratorAction()
{
delete PrimaryGeneratorMessenger;
delete particleGun;
}
/////////////////////////////////////////////////////////////////////////////
void HadrontherapyPrimaryGeneratorAction::SetDefaultPrimaryParticle()
{
delete particleGun;
}
/////////////////////////////////////////////////////////////////////////////
void HadrontherapyPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
if(NewSource==true)
if(fNewSource==true)
{
std::ifstream in(calculatedPhaseSpaceFileIN);
G4double e, xpos, ypos, zpos,dirx,diry,dirz;
G4int PDG;
G4ThreeVector pos,dir;
if(in.eof())
std::ifstream in(calculatedPhaseSpaceFileIN);
G4double e, xpos, ypos, zpos,dirx,diry,dirz;
G4int PDG;
G4ThreeVector pos,dir;
if(in.eof())
{
G4Exception("HadrontherapyPrimaryGeneratorAction", "NoParticles", FatalException, "No more particles in the file");
G4Exception("HadrontherapyPrimaryGeneratorAction", "NoParticles", FatalException, "No more particles in the file");
}
while(!in.eof())
while(!in.eof())
{
in >> e >> xpos >> ypos >>zpos >>dirx>>diry>>dirz >> PDG;
dir= G4ThreeVector(dirx,diry,dirz);
particleGun->GetCurrentSource()->GetEneDist()->SetMonoEnergy(e);
particleGun->GetCurrentSource()->GetParticlePosition().setX(xpos);
particleGun->GetCurrentSource()->GetParticlePosition().setY(ypos);
particleGun->GetCurrentSource()->GetParticlePosition().setZ(zpos);
particleGun->GetCurrentSource()->GetAngDist()->SetParticleMomentumDirection(dir);
G4ParticleDefinition* particleDef = nullptr;
if (PDG > 1000000000)
in >> e >> xpos >> ypos >>zpos >>dirx>>diry>>dirz >> PDG;
dir= G4ThreeVector(dirx,diry,dirz);
particleGun->GetCurrentSource()->GetEneDist()->SetMonoEnergy(e);
particleGun->GetCurrentSource()->GetParticlePosition().setX(xpos);
particleGun->GetCurrentSource()->GetParticlePosition().setY(ypos);
particleGun->GetCurrentSource()->GetParticlePosition().setZ(zpos);
particleGun->GetCurrentSource()->GetAngDist()->SetParticleMomentumDirection(dir);
G4ParticleDefinition* particleDef = nullptr;
if (PDG > 1000000000)
{
int a=(PDG-1000000000)-(((PDG-1000000000)/10)*10);
if(a>0)
int a=(PDG-1000000000)-(((PDG-1000000000)/10)*10);
if(a>0)
{
PDG=PDG-a;
particleDef = G4IonTable::GetIonTable()->GetIon(PDG);
G4String Nome = particleDef->GetParticleName();
PDG=PDG-a;
particleDef = G4IonTable::GetIonTable()->GetIon(PDG);
G4String Nome = particleDef->GetParticleName();
}
else
else
{
particleDef = G4IonTable::GetIonTable()->GetIon(PDG);
G4String Nome = particleDef->GetParticleName();
particleDef = G4IonTable::GetIonTable()->GetIon(PDG);
G4String Nome = particleDef->GetParticleName();
}
}
else
else
{
particleDef = G4ParticleTable::GetParticleTable()->FindParticle(PDG);
particleDef = G4ParticleTable::GetParticleTable()->FindParticle(PDG);
}
particleGun->GetCurrentSource()->SetParticleDefinition(particleDef);
particleGun->GeneratePrimaryVertex(anEvent);
particleGun->GetCurrentSource()->SetParticleDefinition(particleDef);
particleGun->GeneratePrimaryVertex(anEvent);
}
in.close();
+22 -8
View File
@@ -172,7 +172,7 @@ void HadrontherapyRBE::LoadLEMTable(G4String path)
}
else
{
columnIndices[columnName] = distance(header.begin(), pos);
columnIndices[columnName] = (G4int) distance(header.begin(), pos);
}
}
@@ -332,7 +332,7 @@ std::tuple<G4double, G4double> HadrontherapyRBE::GetHitAlphaAndBeta(G4double E,
// Find the row in energy tables
const auto eLarger = upper_bound(begin(vecEnergy), end(vecEnergy), E);
const G4int lower = distance(begin(vecEnergy), eLarger) - 1;
const G4int lower = (G4int) distance(begin(vecEnergy), eLarger) - 1;
const G4int upper = lower + 1;
// Interpolation
@@ -358,11 +358,23 @@ void HadrontherapyRBE::ComputeAlphaAndBeta()
{
G4cout << "RBE: Computing alpha and beta..." << G4endl;
}
fAlpha = fAlphaNumerator / (fDenominator * gray);
fBeta = pow(fBetaNumerator / fDenominator * gray, 2.0);
//g4pow -> powN(fBetaNumerator / fDenominator * gray, 2)
//Re-inizialize the number of voxels
fAlpha.resize(fAlphaNumerator.size()); //Initialize with the same number of elements
fBeta.resize(fBetaNumerator.size()); //Initialize with the same number of elements
for (size_t ii=0; ii<fDenominator.size();ii++)
{
if (fDenominator[ii] > 0)
{
fAlpha[ii] = fAlphaNumerator[ii] / (fDenominator[ii] * gray);
fBeta[ii] = std::pow(fBetaNumerator[ii] / (fDenominator[ii] * gray), 2.0);
}
else
{
fAlpha[ii] = 0.;
fBeta[ii] = 0.;
}
}
}
void HadrontherapyRBE::ComputeRBE()
@@ -398,7 +410,9 @@ void HadrontherapyRBE::ComputeRBE()
fDoseX[i] = ( (-fLnS[i] + ln_Scut) / smax ) + fDoseCut;
}
}
fRBE = fDoseX / fDose;
fRBE.resize(fDoseX.size());
for (size_t ii=0;ii<fDose.size();ii++)
fRBE[ii] = (fDose[ii] > 0) ? fDoseX[ii] / fDose[ii] : 0.;
fSurvival = exp(fLnS);
}
+1 -1
View File
@@ -116,7 +116,7 @@ void HadrontherapyRBEAccumulable::Initialize()
fVoxelsAlongX = rbe->GetNumberOfVoxelsAlongX();
fVoxelsAlongY = rbe->GetNumberOfVoxelsAlongY();
fVoxelsAlongZ = rbe->GetNumberOfVoxelsAlongZ();
fVoxels = fVoxelsAlongX * fVoxelsAlongY * fVoxelsAlongZ;
fVoxels = (size_t) (fVoxelsAlongX * fVoxelsAlongY * fVoxelsAlongZ);
if (GetVerboseLevel() > 1)
{
@@ -55,7 +55,7 @@ HadrontherapyRunAction::HadrontherapyRunAction()
/////////////////////////////////////////////////////////////////////////////
HadrontherapyRunAction::~HadrontherapyRunAction()
{
//delete G4AnalysisManager::Instance();
delete G4AnalysisManager::Instance();
}
/////////////////////////////////////////////////////////////////////////////
@@ -108,9 +108,10 @@ void HadrontherapyRunAction::EndOfRunAction(const G4Run*)
rbe->StoreRBE();
}
analysisManager->Write();
analysisManager->CloseFile();
if (analysisManager->IsOpenFile()) {
analysisManager->Write();
analysisManager->CloseFile();
}
}
/////////////////////////////////////////////////////////////////////////////
void HadrontherapyRunAction::AddEMProcess()
View File
View File
View File
View File