output file

This commit is contained in:
Jan Kieseler
2023-10-13 09:09:02 +02:00
parent 69cc376c5f
commit 381aa6ea91
9 changed files with 42 additions and 9 deletions
+2 -1
View File
@@ -29,7 +29,8 @@ void makeG4System(M &m, std::string name)
{
py::class_<G4System>(m, name.data()).def(py::init())
.def("init", &G4System::init, py::arg("cw")).def("run_visualize", &G4System::run_visualize, py::arg("partSpecies"), py::arg("minEnergy_GeV"), py::arg("maxEnergy_GeV"))
.def("run_gui", &G4System::run_gui).def("run_batch", &G4System::run_batch, py::arg("nEvents"), py::arg("partSpecies"), py::arg("minEnergy_GeV"), py::arg("maxEnergy_GeV"))
.def("run_gui", &G4System::run_gui)
.def("run_batch", &G4System::run_batch, py::arg("nEvents"), py::arg("partSpecies"), py::arg("minEnergy_GeV"), py::arg("maxEnergy_GeV"), py::arg("filename")="_1234567890_Hits.root")
.def("applyUICommand", &G4System::applyUICommand, py::arg("command"))
.def("displayEvent", &G4System::displayEvent)
// .def("printMaterial", &G4System::printMaterial, py::arg("name"))
+10
View File
@@ -32,6 +32,7 @@
#include "G4VUserActionInitialization.hh"
#include "PrimaryGeneratorAction.hh"
#include "RunAction.hh"
namespace B4
{
@@ -66,12 +67,21 @@ class ActionInitialization : public G4VUserActionInitialization
fDetConstruction = det;
}
void setFileName(G4String fileName){
this->filename = fileName;
if(runact!=nullptr){
runact -> setFileName(fileName);
}
}
private:
B4::DetectorConstruction* fDetConstruction = nullptr;
mutable B4::PrimaryGeneratorAction * gen = nullptr;
mutable B4::RunAction * runact = nullptr;
G4double minEnergy=1000;
G4double maxEnergy=1000;
G4String partSpecies="e-";
G4String filename="";
};
}
+3 -1
View File
@@ -19,6 +19,7 @@
#include "Randomize.hh"
class G4System{
friend class GeometryDescriptor;
public:
G4System(bool Gui=false):gui(Gui){};
@@ -37,7 +38,8 @@ void init(GeometryDescriptor &cw);
void run_visualize(const std::string& partSpecies, double minEnergy_GeV, double maxEnergy_GeV);
//runs the whole gui if available
void run_gui();
void run_batch(int nEvents, const std::string& partSpecies, double minEnergy_GeV, double maxEnergy_GeV);
void run_batch(int nEvents, const std::string& partSpecies, double minEnergy_GeV,
double maxEnergy_GeV, std::string filename="_1234567890_Hits.root");
void applyUICommand(const std::string& command){
check();
+6 -3
View File
@@ -7,7 +7,7 @@
#include <string>
//#include "G4VPhysicalVolume.hh"
class G4VPhysicalVolume;
class G4System;
class Sensor{
public:
@@ -90,7 +90,7 @@ class GeometryDescriptor{
public:
GeometryDescriptor(double xy_width=50);
~GeometryDescriptor() {};
~GeometryDescriptor();
void addLayer(double thickness_cm, std::string material, bool isActive=true, int nx=1, int ny=-1);
@@ -134,10 +134,13 @@ public:
}
}
void setG4System(G4System* g4system){
this->g4system = g4system;
}
private:
double xywidth;
std::vector<Layer> layers;
G4System * g4system;
};
#endif
+6
View File
@@ -65,6 +65,10 @@ class RunAction : public G4UserRunAction
void BeginOfRunAction(const G4Run*) override;
void EndOfRunAction(const G4Run*) override;
void setFileName(G4String name){
filename = name;
}
//now this is dumb but the way this is setup it has to be done like this
//yeah mutable fine whatever
@@ -78,6 +82,8 @@ class RunAction : public G4UserRunAction
mutable std::vector<int> hitLayer;
mutable std::vector<int> hitCopyNumber;
mutable G4String filename;
};
}
+2 -1
View File
@@ -62,7 +62,8 @@ void ActionInitialization::Build() const
gen->setMaxPartEnergy(maxEnergy);
gen->setPartSpecies(partSpecies);
SetUserAction(gen);
auto runact = new RunAction;
runact = new RunAction;
runact -> setFileName(filename);
SetUserAction(runact);
auto eventAction = new EventAction;
eventAction->setRunAction(runact);
+4 -1
View File
@@ -19,6 +19,7 @@ void G4System::init(GeometryDescriptor &CW){
assigned_cw->unAssign();
}
assigned_cw = &CW;
CW.setG4System(this);//link both ways
char* argv[]={(char*)"dummy"};
@@ -156,7 +157,8 @@ void G4System::run_gui(){
}
}
void G4System::run_batch(int nEvents,const std::string& partSpecies, double minEnergy, double maxEnergy){
void G4System::run_batch(int nEvents,const std::string& partSpecies, double minEnergy,
double maxEnergy, std::string filename){
check();
@@ -165,6 +167,7 @@ void G4System::run_batch(int nEvents,const std::string& partSpecies, double minE
UImanager->ApplyCommand("/run/initialize");
UImanager->ApplyCommand("/vis/disable");
actionInitialization->setGeneratorProperties(minEnergy, maxEnergy, partSpec);
actionInitialization->setFileName(filename);
runManager->BeamOn(nEvents);
}
+8
View File
@@ -2,6 +2,7 @@
#include "GeometryDescriptor.hh"
#include "G4VPhysicalVolume.hh"
#include "G4System.hh"
Layer::Layer(){
thickness = 0;
@@ -40,6 +41,13 @@ GeometryDescriptor::GeometryDescriptor(double xy_width){
xywidth = xy_width;
}
GeometryDescriptor::~GeometryDescriptor() {
if(g4system != nullptr){
if(this == g4system->assigned_cw){ //unassign
g4system->assigned_cw = nullptr;}
}
};
void GeometryDescriptor::addLayer(double thickness, std::string material, bool isActive, int nx, int ny){
if(ny<0){
ny = nx;
+1 -2
View File
@@ -96,12 +96,11 @@ void RunAction::BeginOfRunAction(const G4Run* /*run*/)
// Open an output file
//
G4String fileName = "_1234567890_Hits.root";
// Other supported output types:
// G4String fileName = "B4.csv";
// G4String fileName = "B4.hdf5";
// G4String fileName = "B4.xml";
analysisManager->OpenFile(fileName);
analysisManager->OpenFile(filename);
G4cout << "Using " << analysisManager->GetType() << G4endl;
}