fixed vis and sensor position
This commit is contained in:
+8
-5
@@ -33,7 +33,7 @@ class __G4System(_G4System):
|
||||
df = index_out_of_bounds_workaround(ttree["Hits;1"])
|
||||
return df
|
||||
|
||||
def displayEvent(self):
|
||||
def displayEvent(self, renderer=None):
|
||||
# for loop over all layers
|
||||
to_plot = []
|
||||
material_dict = {}
|
||||
@@ -52,14 +52,14 @@ class __G4System(_G4System):
|
||||
# loop over materials
|
||||
for layer in self.getGeometryDescriptor().getLayers():
|
||||
|
||||
layer_width = layer.nx * layer.sens_xwidth
|
||||
layer_width = layer.nx * layer.sens_xwidth * 10. # in mm
|
||||
|
||||
#
|
||||
# plot layers
|
||||
#
|
||||
layer_hx = layer_width / 2.
|
||||
layer_hy = layer_width / 2.
|
||||
layer_z = layer.thickness
|
||||
layer_z = layer.thickness * 10. # in mm
|
||||
layer_material = layer.material
|
||||
|
||||
# add material to materials if it is not already in there
|
||||
@@ -91,7 +91,7 @@ class __G4System(_G4System):
|
||||
# if there are sensors in the current layer, add them
|
||||
if layer.sensors != []:
|
||||
z = layer.sensors[0].getdz()
|
||||
corr = layer.sensors[0].getX() - layer.sensors[0].getdx()/2. + layer_width/2.
|
||||
corr = 0. #layer.sensors[0].getX() - layer.sensors[0].getdx()/2. + layer_width/2.
|
||||
# loop over all sensors in current layer and add them to plot
|
||||
for sensor in layer.sensors:
|
||||
x_center = sensor.getX() - corr
|
||||
@@ -194,7 +194,10 @@ class __G4System(_G4System):
|
||||
])
|
||||
fig.update_layout(legend=dict(x=0))
|
||||
# add legend
|
||||
fig.show()
|
||||
if renderer is not None:
|
||||
fig.show(renderer=renderer)
|
||||
else:
|
||||
fig.show()
|
||||
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -8,4 +8,5 @@ cw.addLayer(10,"G4_Si",True, 3) #10 cm of Silicon, active, 3x3 segmentation
|
||||
|
||||
#directly use G4System as a global singleton
|
||||
G4System.init(cw)
|
||||
G4System.run_batch(100, "gamma", 1, 5) #100 events, photons, 1000 MeV to 5000 MeV
|
||||
|
||||
G4System.displayEvent()
|
||||
+1
-1
@@ -21,7 +21,7 @@
|
||||
class G4System{
|
||||
public:
|
||||
|
||||
G4System(bool Gui=true):gui(Gui){};
|
||||
G4System(bool Gui=false):gui(Gui){};
|
||||
~G4System(){
|
||||
if(visManager != nullptr){
|
||||
delete visManager;
|
||||
|
||||
@@ -72,7 +72,11 @@ public:
|
||||
~LayerParametrisation() = default;
|
||||
|
||||
void ComputeTransformation(const G4int copyNo, G4VPhysicalVolume* physVol) const{
|
||||
G4double x = 0;
|
||||
physVol->SetTranslation(ComputePosition(copyNo));
|
||||
}
|
||||
|
||||
G4ThreeVector ComputePosition(const G4int copyNo)const{
|
||||
G4double x = 0;
|
||||
G4double y = 0;
|
||||
G4double z = 0;
|
||||
if(layer.nx > 1){
|
||||
@@ -85,7 +89,7 @@ public:
|
||||
// G4ThreeVector(layer.sens_xwidth * (i % layer.nx) - layer.sens_xwidth * ((float)layer.nx-1) / 2.*cm, //from sensor position below
|
||||
origin -= G4ThreeVector(layer.sens_xwidth * ((float)layer.nx-1) / 2.*cm, layer.sens_ywidth * ((float)layer.ny-1) / 2.*cm, 0);
|
||||
origin += G4ThreeVector(0., 0., position);
|
||||
physVol->SetTranslation(origin);
|
||||
return origin;
|
||||
}
|
||||
|
||||
void ComputeDimensions(G4Box& box, const G4int copyNo, const G4VPhysicalVolume* physVol) const{
|
||||
@@ -250,10 +254,12 @@ G4VPhysicalVolume* DetectorConstruction::DefineVolumes()
|
||||
|
||||
//needs RepeatPlacement for xy granularity
|
||||
//use G4PVParameterised to create a grid of sensitive detectors
|
||||
|
||||
auto parametrisation = new LayerParametrisation(layer, 0);
|
||||
auto ppv = new G4PVParameterised(layer.name,
|
||||
sensorLV,
|
||||
layerLV, kUndefined,
|
||||
layer.nx*layer.ny, new LayerParametrisation(layer,0.));
|
||||
layer.nx*layer.ny, parametrisation);
|
||||
|
||||
auto pv = new G4PVPlacement(nullptr, // no rotation
|
||||
G4ThreeVector(0,0,position), // at (0,0,0)
|
||||
@@ -269,11 +275,12 @@ G4VPhysicalVolume* DetectorConstruction::DefineVolumes()
|
||||
// assign sensors to layer by copyNumber; access the copyNumber of the volumes
|
||||
|
||||
if(layer.isActive){
|
||||
for(int i = 0; i < layer.nx*layer.ny; i++){
|
||||
for(int i = 0; i < layer.nx * layer.ny; i++){
|
||||
Sensor sensor;
|
||||
sensor.position = G4ThreeVector(layer.sens_xwidth * (i % layer.nx) - layer.sens_xwidth * ((float)layer.nx-1) / 2.*cm, // FIX!!!!
|
||||
layer.sens_ywidth * (i / layer.nx) - layer.sens_ywidth * ((float)layer.ny-1) / 2.*cm, position);
|
||||
sensor.size = G4ThreeVector(layer.sens_xwidth, layer.sens_ywidth, layer.thickness);
|
||||
sensor.position = parametrisation->ComputePosition(i);
|
||||
//G4ThreeVector(layer.sens_xwidth * (i % layer.nx) - layer.sens_xwidth * ((float)layer.nx-1) / 2.*cm, // FIX!!!!
|
||||
//layer.sens_ywidth * (i / layer.nx) - layer.sens_ywidth * ((float)layer.ny-1) / 2.*cm, position);
|
||||
sensor.size = G4ThreeVector(layer.sens_xwidth *cm, layer.sens_ywidth*cm, layer.thickness*cm);
|
||||
sensor.energy = 0;
|
||||
layer.sensors.push_back(sensor);//this should now be aligned with copy number
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user