Import Geant4 11.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2024-12-06 11:11:40 +01:00
parent e58e650b32
commit 32390e802b
1984 changed files with 98713 additions and 83996 deletions
@@ -67,24 +67,30 @@
#include "G4VisAttributes.hh"
#include "FlashDetectorMessenger.hh"
#include "FlashSensitiveDetector.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
FlashDetectorConstruction::FlashDetectorConstruction()
: G4VUserDetectorConstruction(), physicalTreatmentRoom(0),logicTreatmentRoom(0), Collimator(0), fPhantom(0),
fPhantomLogicalVolume(0),fPhant_phys(0),
fCheckOverlaps(true) {
fCheckOverlaps(true),
fActivateDet(false)
{
DefineMaterials();
fDetectorMessenger = new FlashDetectorMessenger(this);
SetPhantomSize(30. *cm, 30. *cm, 30. *cm);
SetAirGap(0*cm); // Set the air gap between the water phantom and the end of the applicator
SetDetectorThickness(10*um);
SetDetectorThickness(10*um); //Set the SiC detector thickness
SetDetector_subThickness(370*um);
SetDetectorWidth(5*mm);
SetAirGap_water_detector(0*cm); // Set the air gap between the end of the water phantom and the entrance of the detector
SetDetectorWidth(2*mm); //Set the SiC detector width
SetDetectorPosition(13*mm); // Position of the single detector and of the SiC array within the water phantom
// Change the following parameters to change the number of detectors and center to center distance of the SiC array
nDet = 40;
fDet_ctc = 3 * mm;
}
@@ -154,10 +160,10 @@ FlashDetectorConstruction::ConstructPhantom(G4double CollPos) {
return fPhant_phys;
}
G4VPhysicalVolume *
FlashDetectorConstruction::ConstructDetector(){
//Detector
void FlashDetectorConstruction::ConstructDetector(){
//Detector
G4double fDensity_SiC=3.22*g/cm3;
@@ -168,25 +174,68 @@ FlashDetectorConstruction::ConstructDetector(){
fDetectorMaterial=SiC;
fDetectorPosition=fPhantom_coordinateX+fAirGap+fPhantomSizeX/2+fDet_thickness/2+fAirGap_phantom_det;
fDet_box = new G4Box("Detector",fDet_thickness/2,fDet_width/2,fDet_width/2);
// Definition of the logical volume of the Detector
fDetLogicalVolume =
new G4LogicalVolume(fDet_box, fDetectorMaterial, "DetectorLog", 0, 0, 0);
fDet_phys = new G4PVPlacement(0,G4ThreeVector(fDetectorPosition, 0. * mm, 0. * mm), "DetPhys",fDetLogicalVolume,physicalTreatmentRoom,false, 0, fCheckOverlaps);
fDet_sub = new G4Box("Det_sub",fDet_sub_thickness/2,fDet_width/2,fDet_width/2);
// Definition of the logical volume of the Detector
fDet_sub_LogicalVolume =
new G4LogicalVolume(fDet_sub, fDetectorMaterial, "Det_sub_Log", 0, 0, 0);
fDet_sub_phys = new G4PVPlacement(0,G4ThreeVector(fDetectorPosition+fDet_thickness+fDet_sub_thickness/2, 0. * mm, 0. * mm), "Det_sub_Phys",fDet_sub_LogicalVolume,physicalTreatmentRoom,false, 0, fCheckOverlaps);
// Definition of the logical volume of the Detector substrate
fDet_sub_LogicalVolume =
new G4LogicalVolume(fDet_sub, fDetectorMaterial, "Det_sub_Log", 0, 0, 0);
G4double posInit = (nDet - 1) * fDet_ctc / 2;
return fDet_phys;
if (fActivateDet) {
// Placement physical volumes of the detector array
for (int i = 0; i < nDet; i++){
std::ostringstream os;
os << "Det_Phys_";
if (i < 10)
{
os << "00";
} else if (i < 100){
os << "0";
}
os << i ;
G4String name = os.str();
G4cout << "Position: " << -posInit + fDet_ctc * i << G4endl;
fDet_phys.push_back(new G4PVPlacement(
0,
// G4ThreeVector(fDetectorPosition, 0, -posInit + fDet_ctc * i),
G4ThreeVector(-fPhantomSizeX/2+fDetectorPosition, 0, -posInit + fDet_ctc * i),
name,
fDetLogicalVolume,
fPhant_phys,
false,
i,
fCheckOverlaps
));
fDet_sub_phys.push_back (new G4PVPlacement
(0,
G4ThreeVector(-fPhantomSizeX/2+fDetectorPosition+fDet_thickness/2+fDet_sub_thickness/2, 0. * mm, -posInit + fDet_ctc * i),
"Det_sub_Phys",
fDet_sub_LogicalVolume,
fPhant_phys,
false,
i,
fCheckOverlaps));
}
}
}
@@ -228,16 +277,28 @@ G4VPhysicalVolume *FlashDetectorConstruction::Construct() {
fPhantom_physical =
ConstructPhantom(Collimator->fFinalApplicatorXPositionFlash +
Collimator->fHightFinalApplicatorFlash+fAirGap);
ConstructDetector();
ConstructDetector();
return physicalTreatmentRoom;
}
void FlashDetectorConstruction::ConstructSDandField() {
//modify this function if you want to insert a sensitive detector
if (fActivateDet){
G4SDManager * SDman = G4SDManager::GetSDMpointer();
// Sensitive detector
FlashSensitiveDetector *fSensDet = new FlashSensitiveDetector("fSensitiveDetector");
SDman->AddNewDetector(fSensDet);
fDetLogicalVolume->SetSensitiveDetector(fSensDet);
}
}
@@ -335,18 +396,12 @@ void FlashDetectorConstruction::SetDetector_subThickness(G4double thickness_sub)
}
void FlashDetectorConstruction::SetAirGap_water_detector(G4double spost)
{
fAirGap_phantom_det=spost;
}
void FlashDetectorConstruction::SetDetectorPosition(G4double position)
{
fDetectorPosition=position;
}
void FlashDetectorConstruction::ActivateDetArray(G4bool fbool){
fActivateDet = fbool;
}
@@ -33,6 +33,9 @@
#include "G4UIcmdWithoutParameter.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithABool.hh"
#include "G4SystemOfUnits.hh"
/////////////////////////////////////////////////////////////////////////////
FlashDetectorMessenger::FlashDetectorMessenger(FlashDetectorConstruction* detector)
@@ -49,20 +52,16 @@ FlashDetectorMessenger::FlashDetectorMessenger(FlashDetectorConstruction* detect
fChangeThePhantomMaterialCmd -> SetDefaultValue("G4_WATER");
fChangeThePhantomMaterialCmd -> AvailableForStates(G4State_Idle);
// fChange Detector size
fChangeTheDetectorDir = new G4UIdirectory("/changeDetector/");
fChangeTheDetectorDir -> SetGuidance("Command to fChange the Detector Size");
// fChange Detector material
// fChange Detector material
fChangeTheDetectorMaterialCmd = new G4UIcmdWithAString("/changeDetector/material", this);
fChangeTheDetectorMaterialCmd -> SetGuidance("fChange the Phantom and the detector material");
fChangeTheDetectorMaterialCmd -> SetParameterName("PhantomMaterial", false);
fChangeTheDetectorMaterialCmd -> AvailableForStates(G4State_Idle);
fUpdateCmd = new G4UIcmdWithoutParameter("/changePhantom/update",this);
fUpdateCmd->SetGuidance("Update Phantom/Detector geometry.");
@@ -75,9 +74,12 @@ FlashDetectorMessenger::FlashDetectorMessenger(FlashDetectorConstruction* detect
fUpdateCmd_d->SetGuidance("This command MUST be applied before \"beamOn\" ");
fUpdateCmd_d->SetGuidance("if you fChanged geometrical value(s).");
fUpdateCmd_d->AvailableForStates(G4State_Idle);
fActivateDetArrayCmd = new G4UIcmdWithABool("/changeDetector/activateArray", this);
fActivateDetArrayCmd -> SetParameterName("true/false", true);
fActivateDetArrayCmd -> SetGuidance("Activate detector array.");
fActivateDetArrayCmd -> SetGuidance("This command must be applied before /run/initialize");
fActivateDetArrayCmd -> AvailableForStates(G4State_PreInit);
}
/////////////////////////////////////////////////////////////////////////////
@@ -90,6 +92,8 @@ FlashDetectorMessenger::~FlashDetectorMessenger()
delete fChangeThePhantomMaterialCmd;
delete fChangeTheDetectorMaterialCmd;
delete fActivateDetArrayCmd;
}
@@ -107,7 +111,10 @@ void FlashDetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
{
flashDetector -> SetDetectorMaterial(newValue);
}
else if (command == fActivateDetArrayCmd){
G4bool fbool = fActivateDetArrayCmd -> GetNewBoolValue(newValue);
flashDetector -> ActivateDetArray(fbool);
}
}
@@ -30,17 +30,33 @@
#include "FlashRunAction.hh"
#include "FlashPrimaryGeneratorAction.hh"
#include "G4Accumulable.hh"
#include "G4AccumulableManager.hh"
#include "G4LogicalVolume.hh"
#include "G4Run.hh"
#include "G4RunManager.hh"
#include "G4SystemOfUnits.hh"
#include "G4UnitsTable.hh"
#include "G4AnalysisManager.hh"
FlashRunAction::FlashRunAction() : G4UserRunAction()
{
// Create analysis manager
G4AnalysisManager* fAnalysisManager = G4AnalysisManager::Instance();
// Merging ntuples from multiple root files due to multithreading
// fAnalysisManager->SetNtupleMerging(true);
// Creation of ntuple
fAnalysisManager->CreateNtuple("fSensitiveDetector", "fSensitiveDetector");
fAnalysisManager->CreateNtupleDColumn("fX");
fAnalysisManager->CreateNtupleDColumn("fY");
fAnalysisManager->CreateNtupleDColumn("fZ");
fAnalysisManager->CreateNtupleDColumn("fDose");
fAnalysisManager->CreateNtupleDColumn("fEdep");
fAnalysisManager->CreateNtupleIColumn("fEventID");
fAnalysisManager->CreateNtupleIColumn("fParentID");
fAnalysisManager->CreateNtupleSColumn("fParticle");
fAnalysisManager->FinishNtuple(0);
}
@@ -50,6 +66,17 @@ FlashRunAction::~FlashRunAction() {}
void FlashRunAction::BeginOfRunAction(const G4Run *run) {
G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
// Create analysis manager
G4AnalysisManager* fAnalysisManager = G4AnalysisManager::Instance();
// Merging ntuples from multiple root files due to multithreading
//fAnalysisManager->SetNtupleMerging(true); // uncomment this only for root files
// Open an output file
G4int runID = run -> GetRunID();
std::stringstream strRunID;
strRunID << runID;
fAnalysisManager->OpenFile("output_"+strRunID.str()+".csv");
G4RunManager::GetRunManager()->SetRandomNumberStore(false);
@@ -60,7 +87,10 @@ void FlashRunAction::EndOfRunAction(const G4Run *run) {
if (nofEvents == 0)
return;
// close the output file
G4AnalysisManager* fAnalysisManager = G4AnalysisManager::Instance();
fAnalysisManager->Write();
fAnalysisManager->CloseFile();
if (IsMaster()) {
@@ -0,0 +1,76 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
#include "FlashSensitiveDetector.hh"
#include "G4HCofThisEvent.hh"
#include "G4SDManager.hh"
FlashSensitiveDetector::FlashSensitiveDetector(const G4String& name) : G4VSensitiveDetector(name)
{
}
FlashSensitiveDetector::~FlashSensitiveDetector()
{
}
G4bool FlashSensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*)
{
G4double edep = step -> GetTotalEnergyDeposit();
if (edep == 0) return false;
const G4VTouchable *touchable = step -> GetPreStepPoint() -> GetTouchable();
G4VPhysicalVolume *physVol = touchable -> GetVolume();
G4ThreeVector posDetector = physVol -> GetTranslation(); // get the position
G4Track *track = step -> GetTrack();
auto material = track -> GetMaterial();
auto density = material -> GetDensity();
G4double cavityVolume = (track->GetVolume()->GetLogicalVolume()->GetSolid()->GetCubicVolume());
G4double massOfCavity = cavityVolume * density;
G4double dose = edep / massOfCavity / gray;
edep = edep / MeV;
G4AnalysisManager *fAnalysisManager = G4AnalysisManager::Instance();
fAnalysisManager -> FillNtupleDColumn(0, 0, posDetector[0]);
fAnalysisManager -> FillNtupleDColumn(0, 1, posDetector[1]);
fAnalysisManager -> FillNtupleDColumn(0, 2, posDetector[2]);
fAnalysisManager -> FillNtupleDColumn(0, 3, dose);
fAnalysisManager -> FillNtupleDColumn(0, 4, edep);
fAnalysisManager -> FillNtupleIColumn(0, 5, G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID());
fAnalysisManager -> FillNtupleIColumn(0, 6, track->GetParentID());
fAnalysisManager -> FillNtupleSColumn(0, 7, track->GetDynamicParticle()->GetDefinition()->GetParticleName());
fAnalysisManager -> AddNtupleRow(0);
return true;
}