seems to work with different geometries

This commit is contained in:
Jan Kieseler
2023-09-21 09:06:20 +02:00
parent cee740716c
commit 8d2302b5dc
8 changed files with 58 additions and 38 deletions
+1 -2
View File
@@ -65,11 +65,10 @@ void ActionInitialization::Build() const
auto runact = new RunAction;
SetUserAction(runact);
auto eventAction = new EventAction;
eventAction->setConstructionWrapper(fDetConstruction->getConstructionWrapper());
eventAction->setRunAction(runact);
eventAction->setPrimaryGeneratorAction(gen);
SetUserAction(eventAction);
auto steppingAction = new SteppingAction(fDetConstruction,eventAction);
auto steppingAction = new SteppingAction(eventAction);
SetUserAction(steppingAction);
}
+16 -1
View File
@@ -53,9 +53,15 @@
#include "G4PVParameterised.hh"
#include "G4VPVParameterisation.hh"
#include "G4GeometryManager.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4SolidStore.hh"
namespace B4
{
DetectorConstruction* DetectorConstruction::_global_detector_construction=nullptr;
//helper
class LayerParametrisation: public G4VPVParameterisation{
@@ -129,6 +135,13 @@ nistManager->FindOrBuildMaterial("G4_AIR");
G4VPhysicalVolume* DetectorConstruction::DefineVolumes()
{
G4GeometryManager::GetInstance()->OpenGeometry();
G4PhysicalVolumeStore::GetInstance()->Clean();
G4LogicalVolumeStore::GetInstance()->Clean();
G4SolidStore::GetInstance()->Clean();
// Geometry parameters
auto & cwLayers = cw->getLayers();
G4int nofLayers = cwLayers.size();
@@ -201,6 +214,8 @@ G4VPhysicalVolume* DetectorConstruction::DefineVolumes()
layer.name = "Layer_"+std::to_string(layerNumber);
layerNumber++;
G4cout << "building layer " << layer.name << G4endl;
position += layer.thickness / 2 *cm;
auto layerS
= new G4Box(layer.name, // its name
+3 -1
View File
@@ -40,6 +40,7 @@
#include "Randomize.hh"
#include <iomanip>
#include "DetectorConstruction.hh"
namespace B4a
{
@@ -48,6 +49,7 @@ namespace B4a
void EventAction::BeginOfEventAction(const G4Event* /*event*/)
{
auto cw = B4::DetectorConstruction::getDetectorConstruction()->getConstructionWrapper();
// initialisation per event
if(cw == nullptr){
G4cout << "ConstructionWrapper not found" << G4endl;
@@ -82,7 +84,7 @@ void EventAction::EndOfEventAction(const G4Event* event)
// get analysis manager
auto analysisManager = G4AnalysisManager::Instance();
auto cw = B4::DetectorConstruction::getDetectorConstruction()->getConstructionWrapper();
//cw->printSensorEnergies();//DEBUG
+19 -15
View File
@@ -11,16 +11,19 @@ void G4System::init(ConstructionWrapper &CW){
bool first_init=true;
if(runManager == nullptr){
// Construct the default run manager
//
runManager =
G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
runManager->SetNumberOfThreads(20);//more doesn't make sense
runManager->SetVerboseLevel(0);
}
else{
// Abort the current run
G4RunManager::GetRunManager()->AbortRun(true);
//G4RunManager::GetRunManager()->AbortRun(true);
first_init = false;
//delete actionInitialization;
//delete detConstruction;
@@ -28,6 +31,7 @@ void G4System::init(ConstructionWrapper &CW){
}
G4String session;
ui = nullptr;
if ( gui ) {
@@ -36,10 +40,11 @@ void G4System::init(ConstructionWrapper &CW){
// Set mandatory initialization classes
//
detConstruction = new B4::DetectorConstruction(&CW);
if(first_init){
detConstruction = new B4::DetectorConstruction(&CW);
runManager->SetUserInitialization(detConstruction);
auto physicsList = new FTFP_BERT;
runManager->SetUserInitialization(physicsList);
@@ -47,26 +52,25 @@ void G4System::init(ConstructionWrapper &CW){
runManager->SetUserInitialization(actionInitialization);
}
else{
actionInitialization->setDetectorConstruction(detConstruction);
G4RunManager::GetRunManager()->GeometryHasBeenModified();
G4RunManager::GetRunManager()->ReinitializeGeometry(true);
//runManager->SetUserInitialization(detConstruction);
detConstruction->setConstructionWrapper(&CW);
runManager->ReinitializeGeometry(true);
}
if(visManager == nullptr){
// Initialize visualization
//
visManager = new G4VisExecutive;
// G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
// G4VisManager* visManager = new G4VisExecutive("Quiet");
visManager->Initialize();
// Initialize visualization
//
visManager = new G4VisExecutive;
// G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
// G4VisManager* visManager = new G4VisExecutive("Quiet");
visManager->Initialize();
}
// Get the pointer to the User Interface manager
UImanager = G4UImanager::GetUIpointer();
runManager->Initialize();
// Process macro or start UI session
//
}
+4 -6
View File
@@ -41,10 +41,8 @@ namespace B4a
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
SteppingAction::SteppingAction(const DetectorConstruction* detConstruction,
EventAction* eventAction)
: fDetConstruction(detConstruction),
fEventAction(eventAction)
SteppingAction::SteppingAction(EventAction* eventAction)
: fEventAction(eventAction)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -62,14 +60,14 @@ void SteppingAction::UserSteppingAction(const G4Step* step)
//return;
//find the layer through the constructionwrapper that corresponds to the volume
auto cw = fDetConstruction->getConstructionWrapper();
auto cw = DetectorConstruction::getDetectorConstruction()->getConstructionWrapper();
if(cw == nullptr){
G4cout << "ConstructionWrapper not found" << G4endl;
throw std::runtime_error("ConstructionWrapper not found");
}
auto sensor = fDetConstruction->getConstructionWrapper()->getSensorByVolume(volume);
auto sensor = DetectorConstruction::getDetectorConstruction()->getConstructionWrapper()->getSensorByVolume(volume);
if(sensor == nullptr){
//can simply be not an active volume, so no need to throw an error
//G4cout << "Sensor not found in" << volume->GetName() << G4endl; //DEBUG