fixed a few little things
This commit is contained in:
+4
-2
@@ -10,7 +10,7 @@ import uproot
|
||||
from IPython.display import Image, display
|
||||
|
||||
|
||||
class G4System(_G4System):
|
||||
class __G4System(_G4System):
|
||||
def run_visualize(
|
||||
self, particleSpec: str, minEnergy_GeV: float, maxEnergy_GeV: float = -1.0
|
||||
):
|
||||
@@ -47,7 +47,7 @@ class G4System(_G4System):
|
||||
|
||||
z0=0
|
||||
# loop over materials
|
||||
for layer_i, layer in enumerate(self.cw.getLayers()):
|
||||
for layer_i, layer in enumerate(self.getConstructionWrapper().getLayers()):
|
||||
#layer_i = len(self.cw.getLayers()) - layer_i -1
|
||||
print(layer_i)
|
||||
|
||||
@@ -242,3 +242,5 @@ col_dict = {
|
||||
"G4_Cu": 'dimgray',
|
||||
"G4_BRASS": 'slategrey',
|
||||
}
|
||||
|
||||
G4System = __G4System()#singleton instance
|
||||
+4
-3
@@ -18,6 +18,7 @@ void makeConstructionWrapper(M & m, std::string name){
|
||||
// bind overloaded getLayers function
|
||||
.def("getLayers", (std::vector<Layer> & (ConstructionWrapper::*)()) &ConstructionWrapper::getLayers)
|
||||
.def("getLayers", (const std::vector<Layer> & (ConstructionWrapper::*)() const) &ConstructionWrapper::getLayers)
|
||||
.def("isAssigned", &ConstructionWrapper::isAssigned)
|
||||
.def("getNSensors", &ConstructionWrapper::getNSensors);
|
||||
|
||||
}
|
||||
@@ -31,9 +32,9 @@ void makeG4System(M &m, std::string name)
|
||||
.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("applyUICommand", &G4System::applyUICommand, py::arg("command"))
|
||||
.def("displayEvent", &G4System::displayEvent)
|
||||
.def("printMaterial", &G4System::printMaterial, py::arg("name"))
|
||||
.def("check", &G4System::check)
|
||||
.def_readwrite("cw", &G4System::cw);
|
||||
// .def("printMaterial", &G4System::printMaterial, py::arg("name"))
|
||||
//.def("check", &G4System::check)
|
||||
.def("getConstructionWrapper", &G4System::getConstructionWrapper);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -6,9 +6,9 @@ cw.addLayer(10,"G4_Si",True) #10 cm of Silicon, active
|
||||
cw.addLayer(1,"G4_Pb",False) #1 cm of Lead, passive
|
||||
cw.addLayer(10,"G4_Si",True, 3) #10 cm of Silicon, active, 3x3 segmentation
|
||||
|
||||
G4s = G4System()
|
||||
G4s.init(cw)
|
||||
G4s.run_batch(100, "gamma", 1, 5) #100 events, photons, 1000 MeV to 5000 MeV
|
||||
G4System = G4System
|
||||
G4System.init(cw)
|
||||
G4System.run_batch(100, "gamma", 1, 5) #100 events, photons, 1000 MeV to 5000 MeV
|
||||
|
||||
#G4s.run_visualize("gamma", 1, 5)
|
||||
G4s.printMaterial("G4_Pb")
|
||||
G4System.printMaterial("G4_Pb")
|
||||
@@ -43,6 +43,11 @@ public:
|
||||
void setIsActive(bool isActive);
|
||||
void assignPhysicalVolume(G4VPhysicalVolume* physicalVolume);
|
||||
|
||||
void unAssign(){
|
||||
physicalVolume = nullptr;
|
||||
sensors.clear();
|
||||
}
|
||||
|
||||
double thickness;
|
||||
double sens_xwidth;
|
||||
double sens_ywidth;
|
||||
@@ -99,6 +104,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void unAssign(){
|
||||
for(auto& layer: layers){
|
||||
layer.unAssign();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
double xywidth;
|
||||
|
||||
+10
-2
@@ -28,6 +28,7 @@ G4System(bool Gui=false):gui(Gui){};
|
||||
delete runManager;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -43,15 +44,22 @@ void applyUICommand(const std::string& command){
|
||||
UImanager->ApplyCommand(command);
|
||||
}
|
||||
|
||||
ConstructionWrapper cw;
|
||||
|
||||
void displayEvent()const{}; //just a placeholder, this will be implemented in python
|
||||
|
||||
void printMaterial(const std::string& name)const;
|
||||
|
||||
ConstructionWrapper& getConstructionWrapper(){
|
||||
check();
|
||||
if ( assigned_cw == nullptr ){
|
||||
throw std::runtime_error("ConstructionWrapper not assigned");
|
||||
}
|
||||
return *assigned_cw;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void check()const;
|
||||
ConstructionWrapper * assigned_cw=nullptr;
|
||||
|
||||
bool gui;
|
||||
|
||||
|
||||
+5
-4
@@ -9,6 +9,11 @@ void G4System::init(ConstructionWrapper &CW){
|
||||
if(CW.isAssigned()){
|
||||
throw std::runtime_error("ConstructionWrapper already assigned");
|
||||
}
|
||||
if(assigned_cw != nullptr){
|
||||
//reassign
|
||||
assigned_cw->unAssign();
|
||||
}
|
||||
assigned_cw = &CW;
|
||||
|
||||
char* argv[]={(char*)"dummy"};
|
||||
|
||||
@@ -33,10 +38,6 @@ void G4System::init(ConstructionWrapper &CW){
|
||||
//delete actionInitialization;
|
||||
}
|
||||
|
||||
// save layers of CW to G4System class
|
||||
G4System::cw = CW;
|
||||
|
||||
|
||||
G4String session;
|
||||
ui = nullptr;
|
||||
if ( gui ) {
|
||||
|
||||
Reference in New Issue
Block a user