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
+13 -1
View File
@@ -40,6 +40,7 @@ class ConstructionWrapper;
namespace B4
{
/// Detector construction class to define materials and geometry.
/// The calorimeter is a box made of a given number of layers. A layer consists
/// of an absorber plate and of a detection gap. The layer is replicated.
@@ -59,13 +60,24 @@ namespace B4
class DetectorConstruction : public G4VUserDetectorConstruction
{
public:
DetectorConstruction( ConstructionWrapper* Cw): G4VUserDetectorConstruction(), cw(Cw){}
static DetectorConstruction* _global_detector_construction;
static DetectorConstruction* getDetectorConstruction(){
return _global_detector_construction;
}
DetectorConstruction( ConstructionWrapper* Cw): G4VUserDetectorConstruction(), cw(Cw){
_global_detector_construction=this;
}
~DetectorConstruction() override = default;
public:
G4VPhysicalVolume* Construct() override;
void ConstructSDandField() override;
void setConstructionWrapper(ConstructionWrapper* Cw){
this->cw = Cw;
}
ConstructionWrapper* getConstructionWrapper(){
return cw;
-4
View File
@@ -56,9 +56,6 @@ class EventAction : public G4UserEventAction
void BeginOfEventAction(const G4Event* event) override;
void EndOfEventAction(const G4Event* event) override;
void setConstructionWrapper(const ConstructionWrapper * Cw){
this->cw = Cw;
}
void setPrimaryGeneratorAction(const B4::PrimaryGeneratorAction * Gen){
this->gen = Gen;
}
@@ -67,7 +64,6 @@ class EventAction : public G4UserEventAction
}
private:
const ConstructionWrapper * cw=nullptr;
const B4::PrimaryGeneratorAction * gen=nullptr;
const B4::RunAction * run=nullptr;
};
+2 -8
View File
@@ -32,11 +32,8 @@
#include "G4UserSteppingAction.hh"
#include "ConstructionWrapper.hh"
#include "DetectorConstruction.hh"
namespace B4
{
class DetectorConstruction;
}
namespace B4a
{
@@ -52,15 +49,12 @@ class EventAction;
class SteppingAction : public G4UserSteppingAction
{
public:
SteppingAction(const B4::DetectorConstruction* detConstruction,
EventAction* eventAction);
SteppingAction(EventAction* eventAction);
~SteppingAction() override = default;
void UserSteppingAction(const G4Step* step) override;
private:
const B4::DetectorConstruction* fDetConstruction = nullptr;
EventAction* fEventAction = nullptr;
};
+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