Import Geant4 11.4.0.beta source tree
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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 ActionInitialization.cc
|
||||
/// @brief Define action initialization
|
||||
|
||||
#include "ActionInitialization.hh"
|
||||
|
||||
#include "EventAction.hh"
|
||||
#include "MedicalBeam.hh"
|
||||
#include "RunAction.hh"
|
||||
#include "RunActionMaster.hh"
|
||||
|
||||
#include "G4Threading.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
ActionInitialization::ActionInitialization(G4bool useNtuple, G4bool mergeNtuple)
|
||||
: G4VUserActionInitialization(), fUseNtuple(useNtuple), fMergeNtuple(mergeNtuple)
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
ActionInitialization::~ActionInitialization() {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void ActionInitialization::BuildForMaster() const
|
||||
{
|
||||
SetUserAction(new RunActionMaster(fUseNtuple, fMergeNtuple));
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void ActionInitialization::Build() const
|
||||
{
|
||||
G4cout << "ActionInitialization::Build()" << G4endl;
|
||||
|
||||
SetUserAction(new MedicalBeam);
|
||||
SetUserAction(new EventAction);
|
||||
if (G4Threading::IsMultithreadedApplication())
|
||||
SetUserAction(new RunAction(fUseNtuple, fMergeNtuple));
|
||||
else
|
||||
SetUserAction(
|
||||
new RunActionMaster(fUseNtuple, fMergeNtuple)); // Use master version for sequential
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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 Analysis.cc
|
||||
/// @brief Define histograms and ntuples
|
||||
|
||||
#include "Analysis.hh"
|
||||
|
||||
#include "G4AutoDelete.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
|
||||
// Note: ntuple merging is supported only with Root format
|
||||
#ifndef G4MULTITHREADED
|
||||
# include "G4RootMpiAnalysisManager.hh"
|
||||
using G4AnalysisManager = G4RootMpiAnalysisManager;
|
||||
#else
|
||||
# include "G4RootAnalysisManager.hh"
|
||||
using G4AnalysisManager = G4RootAnalysisManager;
|
||||
#endif
|
||||
|
||||
G4ThreadLocal G4int Analysis::fincidentFlag = false;
|
||||
G4ThreadLocal Analysis* the_analysis = 0;
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
Analysis* Analysis::GetAnalysis()
|
||||
{
|
||||
if (!the_analysis) {
|
||||
the_analysis = new Analysis();
|
||||
G4AutoDelete::Register(the_analysis);
|
||||
}
|
||||
return the_analysis;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
Analysis::Analysis()
|
||||
: fUseNtuple(true),
|
||||
fMergeNtuple(true),
|
||||
fincident_x_hist(0),
|
||||
fincident_map(0),
|
||||
fdose_hist(0),
|
||||
fdose_map(0),
|
||||
fdose_prof(0),
|
||||
fdose_map_prof(0),
|
||||
fdose_map3d(0)
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void Analysis::Book()
|
||||
{
|
||||
G4cout << "Analysis::Book start, fUseNtuple: " << fUseNtuple << G4endl;
|
||||
|
||||
G4AnalysisManager* mgr = G4AnalysisManager::Instance();
|
||||
mgr->SetVerboseLevel(1);
|
||||
#ifdef G4MULTITHREADED
|
||||
// MT ntuple merging
|
||||
mgr->SetNtupleMerging(fMergeNtuple);
|
||||
#endif
|
||||
|
||||
fincident_x_hist = mgr->CreateH1("incident_x", "Incident X", 100, -5 * cm, 5 * cm, "cm");
|
||||
fincident_map = mgr->CreateH2("incident_map", "Incident Map", 50, -5 * cm, 5 * cm, 50, -5 * cm,
|
||||
5 * cm, "cm", "cm");
|
||||
fdose_hist = mgr->CreateH1("dose", "Dose distribution", 500, 0, 50 * cm, "cm");
|
||||
fdose_map = mgr->CreateH2("dose_map", "Dose distribution", 500, 0, 50 * cm, 200, -10 * cm,
|
||||
10 * cm, "cm", "cm");
|
||||
fdose_map3d = mgr->CreateH3("dose_map_3d", "Dose distribution", 30, 0, 50 * cm, 20, -10 * cm,
|
||||
10 * cm, 20, -10 * cm, 10 * cm, "cm", "cm", "cm");
|
||||
fdose_prof =
|
||||
mgr->CreateP1("dose_prof", "Dose distribution", 300, 0, 30 * cm, 0, 100 * MeV, "cm", "MeV");
|
||||
fdose_map_prof = mgr->CreateP2("dose_map_prof", "Dose distribution", 300, 0, 30 * cm, 80, -4 * cm,
|
||||
4 * cm, 0, 100 * MeV, "cm", "cm", "MeV");
|
||||
|
||||
if (fUseNtuple) {
|
||||
mgr->CreateNtuple("Dose", "Dose distribution"); // ntuple Id = 0
|
||||
mgr->CreateNtupleDColumn("pz");
|
||||
mgr->CreateNtupleDColumn("px");
|
||||
mgr->CreateNtupleDColumn("dose");
|
||||
mgr->FinishNtuple();
|
||||
}
|
||||
|
||||
G4cout << "Analysis::Book finished " << G4endl;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
Analysis::~Analysis() {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void Analysis::OpenFile(const G4String& fname)
|
||||
{
|
||||
G4AnalysisManager* mgr = G4AnalysisManager::Instance();
|
||||
mgr->OpenFile(fname.c_str());
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void Analysis::Save()
|
||||
{
|
||||
G4AnalysisManager* mgr = G4AnalysisManager::Instance();
|
||||
mgr->Write();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void Analysis::Close(G4bool reset)
|
||||
{
|
||||
G4AnalysisManager* mgr = G4AnalysisManager::Instance();
|
||||
mgr->CloseFile(reset);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void Analysis::FillIncident(const G4ThreeVector& p)
|
||||
{
|
||||
if (!fincidentFlag) {
|
||||
G4AnalysisManager* mgr = G4AnalysisManager::Instance();
|
||||
mgr->FillH2(fincident_map, p.x(), p.y());
|
||||
mgr->FillH1(fincident_x_hist, p.x());
|
||||
fincidentFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void Analysis::FillDose(const G4ThreeVector& p, G4double dedx)
|
||||
{
|
||||
const G4double dxy = 10. * mm;
|
||||
if (std::abs(p.y()) < dxy) {
|
||||
G4AnalysisManager* mgr = G4AnalysisManager::Instance();
|
||||
const G4double Z0 = 25. * cm;
|
||||
|
||||
mgr->FillH2(fdose_map, p.z() + Z0, p.x(), dedx / GeV);
|
||||
mgr->FillP2(fdose_map_prof, p.z() + Z0, p.x(), dedx);
|
||||
mgr->FillH3(fdose_map3d, p.z() + Z0, p.x(), p.y(), dedx / GeV);
|
||||
if (std::abs(p.x()) < dxy) {
|
||||
mgr->FillH1(fdose_hist, p.z() + Z0, dedx / GeV);
|
||||
mgr->FillP1(fdose_prof, p.z() + Z0, dedx);
|
||||
}
|
||||
|
||||
if (fUseNtuple) {
|
||||
// the same fill frequency as H2 "dose_map"
|
||||
mgr->FillNtupleDColumn(0, p.z() + Z0);
|
||||
mgr->FillNtupleDColumn(1, p.x());
|
||||
mgr->FillNtupleDColumn(2, dedx / GeV);
|
||||
mgr->AddNtupleRow();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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 DetectorConstruction.hh
|
||||
/// @brief Define geometry
|
||||
|
||||
#include "DetectorConstruction.hh"
|
||||
|
||||
#include "VoxelParam.hh"
|
||||
#include "VoxelSD.hh"
|
||||
|
||||
#include "G4Box.hh"
|
||||
#include "G4LogicalVolume.hh"
|
||||
#include "G4NistManager.hh"
|
||||
#include "G4PVParameterised.hh"
|
||||
#include "G4PVPlacement.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "G4VisAttributes.hh"
|
||||
|
||||
typedef G4LogicalVolume G4LV;
|
||||
typedef G4PVPlacement G4PVP;
|
||||
typedef G4VisAttributes G4VA;
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
DetectorConstruction::DetectorConstruction() : flv_voxel(NULL) {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
DetectorConstruction::~DetectorConstruction() {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
G4VPhysicalVolume* DetectorConstruction::Construct()
|
||||
{
|
||||
G4NistManager* nistManager = G4NistManager::Instance();
|
||||
G4VisAttributes* va;
|
||||
|
||||
// world volume
|
||||
const G4double DXYZ_WORLD = 200. * cm;
|
||||
G4Box* sld_world = new G4Box("world", DXYZ_WORLD / 2., DXYZ_WORLD / 2., DXYZ_WORLD / 2.);
|
||||
|
||||
G4Material* vacuum = nistManager->FindOrBuildMaterial("G4_Galactic");
|
||||
G4LV* lv_world = new G4LogicalVolume(sld_world, vacuum, "world");
|
||||
G4PVP* world = new G4PVPlacement(0, G4ThreeVector(), "AREA", lv_world, 0, false, 0);
|
||||
// vis. attributes
|
||||
va = new G4VA(G4Color(1., 1., 1.));
|
||||
va->SetVisibility(false);
|
||||
lv_world->SetVisAttributes(va);
|
||||
|
||||
// water phantom
|
||||
const G4double DXY_PHANTOM = 20. * cm;
|
||||
const G4double DZ_PHANTOM = 50. * cm;
|
||||
|
||||
G4Box* sld_phantom = new G4Box("phantom", DXY_PHANTOM / 2., DXY_PHANTOM / 2., DZ_PHANTOM / 2.);
|
||||
|
||||
G4Material* water = nistManager->FindOrBuildMaterial("G4_WATER");
|
||||
G4LV* lv_phantom = new G4LogicalVolume(sld_phantom, water, "phantom");
|
||||
|
||||
va = new G4VA(G4Color(0., 1., 1.));
|
||||
lv_phantom->SetVisAttributes(va);
|
||||
|
||||
new G4PVP(0, G4ThreeVector(), lv_phantom, "phantom", lv_world, false, 0);
|
||||
|
||||
// voxel planes
|
||||
const G4double DXY_VXP = 20. * cm;
|
||||
const G4double DZ_VXP = 1. * mm;
|
||||
|
||||
G4Box* sld_vxp = new G4Box("vxplane", DXY_VXP / 2., DXY_VXP / 2., DZ_VXP / 2.);
|
||||
G4LV* lv_vxp = new G4LV(sld_vxp, water, "vxplane");
|
||||
|
||||
va = new G4VA(G4Color(1., 0., 0.));
|
||||
va->SetVisibility(false);
|
||||
lv_vxp->SetVisAttributes(va);
|
||||
|
||||
for (G4int iz = 0; iz < 500; iz++) {
|
||||
G4double z0 = -DZ_PHANTOM / 2. + (iz + 0.5) * DZ_VXP;
|
||||
new G4PVP(0, G4ThreeVector(0., 0., z0), lv_vxp, "vxplane", lv_phantom, false, 1000 + iz);
|
||||
}
|
||||
|
||||
// voxel parameterized
|
||||
G4Box* sld_voxel = new G4Box("voxel", 1., 1., 1.); // dummy
|
||||
flv_voxel = new G4LV(sld_voxel, water, "voxel");
|
||||
|
||||
va = new G4VA(G4Color(0., 1., 1.));
|
||||
va->SetVisibility(false);
|
||||
flv_voxel->SetVisAttributes(va);
|
||||
|
||||
const G4int nvoxels = 100 * 100;
|
||||
new G4PVParameterised("voxle", flv_voxel, lv_vxp, kUndefined, nvoxels, new VoxelParam());
|
||||
|
||||
return world;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void DetectorConstruction::ConstructSDandField()
|
||||
{
|
||||
flv_voxel->SetSensitiveDetector(new VoxelSD("voxel"));
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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 EventAction.cc
|
||||
/// @brief Describe event actions
|
||||
|
||||
#include "EventAction.hh"
|
||||
|
||||
#include "Analysis.hh"
|
||||
|
||||
#include "G4Event.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
EventAction::EventAction() {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
EventAction::~EventAction() {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void EventAction::BeginOfEventAction(const G4Event*)
|
||||
{
|
||||
Analysis* myana = Analysis::GetAnalysis();
|
||||
myana->ClearIncidentFlag();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void EventAction::EndOfEventAction(const G4Event*) {}
|
||||
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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 MedicalBeam.cc
|
||||
/// @brief Define beam profile as primary generator
|
||||
|
||||
#include "MedicalBeam.hh"
|
||||
|
||||
#include "G4Event.hh"
|
||||
#include "G4ParticleTable.hh"
|
||||
#include "G4PrimaryVertex.hh"
|
||||
#include "Randomize.hh"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace CLHEP;
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
MedicalBeam::MedicalBeam()
|
||||
: fparticle(0),
|
||||
fkineticE(1. * MeV),
|
||||
fsourcePosition(G4ThreeVector()),
|
||||
fSSD(1. * m),
|
||||
ffieldShape(MedicalBeam::kSQUARE),
|
||||
ffieldR(10. * cm)
|
||||
{
|
||||
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
|
||||
fparticle = particleTable->FindParticle("proton");
|
||||
|
||||
fkineticE = 200. * MeV;
|
||||
fsourcePosition = G4ThreeVector(0., 0., -125. * cm);
|
||||
fSSD = 100. * cm;
|
||||
ffieldXY[0] = ffieldXY[1] = 5. * cm;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
MedicalBeam::~MedicalBeam() {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
G4ThreeVector MedicalBeam::GenerateBeamDirection() const
|
||||
{
|
||||
// uniform distribution in a limitted solid angle
|
||||
G4double dr;
|
||||
if (ffieldShape == MedicalBeam::kSQUARE) {
|
||||
dr = std::sqrt(sqr(ffieldXY[0] / 2.) + sqr(ffieldXY[1] / 2.));
|
||||
}
|
||||
else {
|
||||
dr = ffieldR;
|
||||
}
|
||||
|
||||
G4double sin0 = dr / fSSD;
|
||||
G4double cos0 = std::sqrt(1. - sqr(sin0));
|
||||
|
||||
G4double dcos = 0.;
|
||||
G4double dsin, dphi, z;
|
||||
|
||||
G4double x = DBL_MAX;
|
||||
G4double y = DBL_MAX;
|
||||
|
||||
G4double xmax, ymax;
|
||||
if (ffieldShape == MedicalBeam::kSQUARE) {
|
||||
xmax = ffieldXY[0] / 2. / fSSD;
|
||||
ymax = ffieldXY[1] / 2. / fSSD;
|
||||
}
|
||||
else {
|
||||
xmax = ymax = DBL_MAX - 1.;
|
||||
}
|
||||
|
||||
while (!(std::abs(x) < xmax && std::abs(y) < ymax)) {
|
||||
dcos = G4RandFlat::shoot(cos0, 1.);
|
||||
dsin = std::sqrt(1. - sqr(dcos));
|
||||
dphi = G4RandFlat::shoot(0., twopi);
|
||||
|
||||
x = std::cos(dphi) * dsin * dcos;
|
||||
y = std::sin(dphi) * dsin * dcos;
|
||||
}
|
||||
z = dcos;
|
||||
|
||||
return G4ThreeVector(x, y, z);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void MedicalBeam::GeneratePrimaries(G4Event* anEvent)
|
||||
{
|
||||
if (fparticle == NULL) return;
|
||||
|
||||
// create a new vertex
|
||||
G4PrimaryVertex* vertex = new G4PrimaryVertex(fsourcePosition, 0. * ns);
|
||||
|
||||
// momentum
|
||||
G4double mass = fparticle->GetPDGMass();
|
||||
G4double p = std::sqrt(sqr(mass + fkineticE) - sqr(mass));
|
||||
G4ThreeVector pmon = p * GenerateBeamDirection();
|
||||
G4PrimaryParticle* primary = new G4PrimaryParticle(fparticle, pmon.x(), pmon.y(), pmon.z());
|
||||
|
||||
// set primary to vertex
|
||||
vertex->SetPrimary(primary);
|
||||
|
||||
// set vertex to event
|
||||
anEvent->AddPrimaryVertex(vertex);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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 "Run.hh"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
namespace
|
||||
{
|
||||
std::atomic_int g_ctr(0);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
Run::Run()
|
||||
{
|
||||
fDummyCounter = g_ctr++;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void Run::Merge(const G4Run* other)
|
||||
{
|
||||
G4Run::Merge(other);
|
||||
fDummyCounter += static_cast<const Run*>(other)->fDummyCounter;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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 RunAction.cc
|
||||
/// @brief Describe run actions
|
||||
|
||||
#include "RunAction.hh"
|
||||
|
||||
#include "Analysis.hh"
|
||||
#include "Run.hh"
|
||||
#include "toolx/mpi/wrmpi"
|
||||
|
||||
#include "G4MPImanager.hh"
|
||||
#include "G4MPIscorerMerger.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <G4VUserMPIrunMerger.hh>
|
||||
#include <stdio.h>
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
RunAction::RunAction(G4bool useNtuple, G4bool mergeNtuple) : G4UserRunAction()
|
||||
{
|
||||
// Book analysis in ctor
|
||||
Analysis* myana = Analysis::GetAnalysis();
|
||||
myana->SetUseNtuple(useNtuple);
|
||||
myana->SetMergeNtuple(mergeNtuple);
|
||||
G4cout << "Book analysis on rank: " << G4MPImanager::GetManager()->GetRank() << G4endl;
|
||||
;
|
||||
myana->Book();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
RunAction::~RunAction() {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
G4Run* RunAction::GenerateRun()
|
||||
{
|
||||
return new Run;
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void RunAction::BeginOfRunAction(const G4Run*)
|
||||
{
|
||||
G4cout << "RunAction::BeginOfRunAction" << G4endl;
|
||||
|
||||
Analysis* myana = Analysis::GetAnalysis();
|
||||
|
||||
// ntuples will be written on each rank
|
||||
G4int rank = G4MPImanager::GetManager()->GetRank();
|
||||
std::ostringstream fname;
|
||||
fname << "dose-rank" << rank;
|
||||
myana->OpenFile(fname.str());
|
||||
// OpenFile triggeres creating collecting/sending ntuples objects;
|
||||
// must be called at BeginOfRunAction
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void RunAction::EndOfRunAction(const G4Run*)
|
||||
{
|
||||
G4cout << "RunAction::EndOfRunAction" << G4endl;
|
||||
|
||||
Analysis* myana = Analysis::GetAnalysis();
|
||||
myana->Save();
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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 RunActionMaster.cc
|
||||
/// @brief Describe run actions
|
||||
|
||||
#include "RunActionMaster.hh"
|
||||
|
||||
#include "Analysis.hh"
|
||||
#include "RunMerger.hh"
|
||||
|
||||
#include "G4MPImanager.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
#include <stdio.h>
|
||||
#ifndef G4MULTITHREADED
|
||||
# include "G4RootMpiAnalysisManager.hh"
|
||||
using G4AnalysisManager = G4RootMpiAnalysisManager;
|
||||
#else
|
||||
# include "G4RootAnalysisManager.hh"
|
||||
using G4AnalysisManager = G4RootAnalysisManager;
|
||||
#endif
|
||||
#include "Run.hh"
|
||||
|
||||
#include "G4Filesystem.hh"
|
||||
#include "G4MPIhistoMerger.hh"
|
||||
#include "G4MPIntupleMerger.hh"
|
||||
#include "G4MPIscorerMerger.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
RunActionMaster::RunActionMaster(G4bool useNtuple, G4bool mergeNtuple)
|
||||
: G4UserRunAction(), fMPIntupleMerger(nullptr)
|
||||
{
|
||||
#ifndef G4MULTITHREADED
|
||||
if (mergeNtuple && G4MPImanager::GetManager()->GetTotalSize() >= 2) {
|
||||
// Activate MPI ntuple merging
|
||||
// The merger must be created before creating G4AnalysisManager:
|
||||
// (= the first call to G4AnalysisManager::Instance())
|
||||
// and deleted only at the end of program
|
||||
G4int nofReducedNtupleFiles = 0;
|
||||
// Multiple reduced ntuple files are not yet supported
|
||||
G4bool rowWise = false;
|
||||
G4bool rowMode = true;
|
||||
fMPIntupleMerger = new G4MPIntupleMerger(nofReducedNtupleFiles, rowWise, rowMode);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Book analysis in ctor
|
||||
Analysis* myana = Analysis::GetAnalysis();
|
||||
myana->SetUseNtuple(useNtuple);
|
||||
myana->SetMergeNtuple(mergeNtuple);
|
||||
G4cout << "Book analysis on master on rank: " << G4MPImanager::GetManager()->GetRank() << G4endl;
|
||||
;
|
||||
myana->Book();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
G4Run* RunActionMaster::GenerateRun()
|
||||
{
|
||||
return new Run;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
RunActionMaster::~RunActionMaster()
|
||||
{
|
||||
delete fMPIntupleMerger;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void RunActionMaster::BeginOfRunAction(const G4Run*)
|
||||
{
|
||||
G4cout << "RunActionMaster::BeginOfRunAction" << G4endl;
|
||||
|
||||
Analysis* myana = Analysis::GetAnalysis();
|
||||
|
||||
G4int rank = G4MPImanager::GetManager()->GetRank();
|
||||
std::ostringstream fname;
|
||||
fname << "dose-rank" << rank;
|
||||
myana->OpenFile(fname.str());
|
||||
// OpenFile triggeres creating collecting/sending ntuples objects;
|
||||
// must be called at BeginOfRunAction
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void RunActionMaster::EndOfRunAction(const G4Run* arun)
|
||||
{
|
||||
G4cout << "RunActionMaster::EndOfRunAction" << G4endl;
|
||||
|
||||
// This is executed by master thread only. Worker threads have already
|
||||
// merged their results into this master threads.
|
||||
|
||||
// We are going to merge the results via MPI for:
|
||||
// 1. User-defined "Run" object
|
||||
// 2. Command line scorers, if exists
|
||||
// 3. G4Analysis objects
|
||||
|
||||
// For debugging purposes in the following we write out results twice:
|
||||
// BEFORE and AFTER the merging, so that rank 0 actually
|
||||
// writes two files, the one called "*rank000*" will contain the partial
|
||||
// results only from rank #0,
|
||||
// the file *merged* contains the reduction from all ranks.
|
||||
// It should be very easy to adapt this code
|
||||
|
||||
const G4int rank = G4MPImanager::GetManager()->GetRank();
|
||||
|
||||
G4cout << "=====================================================" << G4endl;
|
||||
G4cout << "Start EndOfRunAction for master thread in rank: " << rank << G4endl;
|
||||
G4cout << "=====================================================" << G4endl;
|
||||
|
||||
if (!G4MPImanager::GetManager()->IsExtraWorker()) {
|
||||
G4cout << "Go to merge on processing workers" << G4endl;
|
||||
|
||||
// Merging of G4Run object:
|
||||
// All ranks > 0 merge to rank #0
|
||||
RunMerger rm(static_cast<const Run*>(arun), G4MPImanager::kRANK_MASTER, 5);
|
||||
G4int ver = 0; // Use 4 for lots of info
|
||||
if (rank == 0 && ver == 0) ver = 1;
|
||||
|
||||
if (ver > 1) {
|
||||
G4cout << "Before merge the Run object has test counter value: "
|
||||
<< static_cast<const Run*>(arun)->GetCounter() << G4endl;
|
||||
}
|
||||
rm.SetVerbosity(ver);
|
||||
rm.Merge();
|
||||
if (ver > 1) {
|
||||
G4cout << "After merge the Run object has test counter value: "
|
||||
<< static_cast<const Run*>(arun)->GetCounter() << " (with 1 thread== number of ranks)"
|
||||
<< G4endl;
|
||||
}
|
||||
|
||||
// Merge of scorers
|
||||
ver = 0;
|
||||
if (G4ScoringManager::GetScoringManagerIfExist()) {
|
||||
const auto scor = G4ScoringManager::GetScoringManager();
|
||||
G4MPIscorerMerger sm(scor);
|
||||
sm.SetVerbosity(ver);
|
||||
// Debug!
|
||||
auto debugme = [&scor]() {
|
||||
for (size_t idx = 0; idx < scor->GetNumberOfMesh(); ++idx) {
|
||||
const auto m = scor->GetMesh(idx);
|
||||
const auto map = m->GetScoreMap();
|
||||
std::for_each(
|
||||
map.begin(), map.end(), [](const G4VScoringMesh::MeshScoreMap::value_type& e) {
|
||||
G4cout << e.first << "(" << e.second << "):" << G4endl;
|
||||
const auto data = e.second->GetMap();
|
||||
for (auto it = data->begin(); it != data->end(); ++it) {
|
||||
G4cout << it->first
|
||||
<< " => G4StatDouble(n,sum_w,sum_w2,sum_wx,sum_wx2): " << it->second->n()
|
||||
<< " " << it->second->sum_w() << " " << it->second->sum_w2() << " "
|
||||
<< it->second->sum_wx() << " " << it->second->sum_wx2() << G4endl;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
// Debug!
|
||||
if (ver > 4) {
|
||||
G4cout << "Before merging: Meshes dump" << G4endl;
|
||||
debugme();
|
||||
}
|
||||
// Write partial scorers from single ranks *before* merging
|
||||
// Do not rely on UI command to write out scorers, because rank-specific
|
||||
// files will have same file name: need to add rank # to file name
|
||||
if (true) {
|
||||
for (size_t idx = 0; idx < scor->GetNumberOfMesh(); ++idx) {
|
||||
const auto m = scor->GetMesh(idx);
|
||||
const auto& mn = m->GetWorldName();
|
||||
std::ostringstream fname;
|
||||
fname << "scorer-" << mn << "-rank" << rank << ".csv";
|
||||
scor->DumpAllQuantitiesToFile(mn, fname.str());
|
||||
}
|
||||
}
|
||||
|
||||
// Now reduce all scorers to rank #0
|
||||
sm.Merge();
|
||||
|
||||
// Debug!
|
||||
if (ver > 4) {
|
||||
G4cout << "After merging: Meshes dump" << G4endl;
|
||||
debugme();
|
||||
}
|
||||
// For rank #0 write out the merged files
|
||||
if (rank == 0) {
|
||||
for (size_t idx = 0; idx < scor->GetNumberOfMesh(); ++idx) {
|
||||
const auto m = scor->GetMesh(idx);
|
||||
const auto& mn = m->GetWorldName();
|
||||
std::ostringstream fname;
|
||||
fname << "scorer-" << mn << "-merged.csv";
|
||||
scor->DumpAllQuantitiesToFile(mn, fname.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save histograms *before* MPI merging for rank #0
|
||||
// Can be done only if MPI merging is not activated
|
||||
if (rank == 0 && (fMPIntupleMerger == nullptr)) {
|
||||
Analysis* myana = Analysis::GetAnalysis();
|
||||
myana->Save();
|
||||
myana->Close(false); // close without resetting histograms
|
||||
// Rename file in another file
|
||||
G4fs::rename("dose-rank0.root", "dose-rank0-part.root");
|
||||
}
|
||||
|
||||
// Merge of g4analysis objects
|
||||
G4cout << "Go to merge histograms " << G4endl;
|
||||
ver = 1;
|
||||
G4MPIhistoMerger hm(G4AnalysisManager::Instance());
|
||||
hm.SetVerbosity(ver);
|
||||
hm.Merge();
|
||||
G4cout << "Done merge histograms " << G4endl;
|
||||
}
|
||||
else {
|
||||
G4cout << "Skip merging on the extra worker" << G4endl;
|
||||
}
|
||||
|
||||
// Save g4analysis objects to a file
|
||||
Analysis* myana = Analysis::GetAnalysis();
|
||||
myana->OpenFile("dose-rank0.root");
|
||||
myana->Save();
|
||||
myana->Close();
|
||||
|
||||
if (rank == 0) {
|
||||
// Rename files
|
||||
G4fs::rename("dose-rank0.root", "dose-merged.root");
|
||||
if (fMPIntupleMerger == nullptr) {
|
||||
G4fs::rename("dose-rank0-part.root", "dose-rank0.root");
|
||||
}
|
||||
}
|
||||
|
||||
G4cout << "===================================================" << G4endl;
|
||||
G4cout << "End EndOfRunAction for master thread in rank: " << rank << G4endl;
|
||||
G4cout << "===================================================" << G4endl;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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 "RunMerger.hh"
|
||||
|
||||
#include "Run.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void RunMerger::Pack()
|
||||
{
|
||||
// Very imporant, here fMyRun is const!
|
||||
// Register a user-data in the user Run class with MPI merger
|
||||
InputUserData(const_cast<int*>(&(fMyRun->fDummyCounter)), MPI_INT, 1);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
G4Run* RunMerger::UnPack()
|
||||
{
|
||||
// Create a dummy user-Run, used to contain data received via MPI
|
||||
Run* aDummyRun = new Run;
|
||||
OutputUserData(&(aDummyRun->fDummyCounter), MPI_INT, 1);
|
||||
return aDummyRun;
|
||||
}
|
||||
@@ -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 VoxelParam.cc
|
||||
/// @brief Define voxel parameterization
|
||||
|
||||
#include "VoxelParam.hh"
|
||||
|
||||
#include "G4Box.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
#include "G4VPhysicalVolume.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
VoxelParam::VoxelParam() {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
VoxelParam::~VoxelParam() {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void VoxelParam::ComputeTransformation(const G4int id, G4VPhysicalVolume* vol) const
|
||||
{
|
||||
const G4int NX = 100;
|
||||
|
||||
G4int iy = id / NX;
|
||||
G4int ix = id % NX;
|
||||
|
||||
const G4double dxyz = 1. * mm;
|
||||
const G4double DXY = 10. * cm;
|
||||
|
||||
G4double x0 = -DXY / 2. + ix * dxyz;
|
||||
G4double y0 = -DXY / 2. + iy * dxyz;
|
||||
|
||||
vol->SetTranslation(G4ThreeVector(x0, y0, 0.));
|
||||
vol->SetRotation(0);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void VoxelParam::ComputeDimensions(G4Box& box, const G4int, const G4VPhysicalVolume*) const
|
||||
{
|
||||
const G4double dxyz = 0.5 * mm;
|
||||
|
||||
box.SetXHalfLength(dxyz);
|
||||
box.SetYHalfLength(dxyz);
|
||||
box.SetZHalfLength(dxyz);
|
||||
}
|
||||
@@ -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 VoxelSD.cc
|
||||
/// @brief Define detector sensitivity on voxels
|
||||
|
||||
// #include "G4MPImanager.hh"
|
||||
#include "VoxelSD.hh"
|
||||
|
||||
#include "Analysis.hh"
|
||||
|
||||
#include "G4SDManager.hh"
|
||||
#include "G4Step.hh"
|
||||
#include "G4TouchableHistory.hh"
|
||||
#include "G4Track.hh"
|
||||
#include "G4VTouchable.hh"
|
||||
#include "Randomize.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
VoxelSD::VoxelSD(const G4String& name) : G4VSensitiveDetector(name)
|
||||
{
|
||||
G4SDManager::GetSDMpointer()->AddNewDetector(this);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
VoxelSD::~VoxelSD() {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
G4bool VoxelSD::ProcessHits(G4Step* astep, G4TouchableHistory*)
|
||||
{
|
||||
G4ThreeVector x0 = astep->GetPreStepPoint()->GetPosition();
|
||||
G4ThreeVector x1 = astep->GetPostStepPoint()->GetPosition();
|
||||
|
||||
G4int tid = astep->GetTrack()->GetTrackID();
|
||||
G4int iz = astep->GetPreStepPoint()->GetTouchable()->GetReplicaNumber(1);
|
||||
|
||||
Analysis* myana = Analysis::GetAnalysis();
|
||||
|
||||
// incident position
|
||||
if (tid == 1 && iz == 1000) { // scored @ first layer
|
||||
myana->FillIncident(x0);
|
||||
}
|
||||
|
||||
// energy deposit
|
||||
G4ThreeVector p = G4UniformRand() * (x1 - x0) + x0; // position sampling
|
||||
G4double edep = astep->GetTotalEnergyDeposit();
|
||||
myana->FillDose(p, edep);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void VoxelSD::Initialize(G4HCofThisEvent*) {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
void VoxelSD::EndOfEvent(G4HCofThisEvent*) {}
|
||||
Reference in New Issue
Block a user