Skip to content

Commit

Permalink
Fix BoxOfStraws: Now layers with correct orientation. Thanks Andre!
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusFrankATcernch committed Jul 5, 2024
1 parent 372bd9d commit 85e5670
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
5 changes: 3 additions & 2 deletions examples/ClientTests/compact/BoxOfStraws.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@
<vis name="VisibleRed" alpha="0.4" r="1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/>
<vis name="VisibleBlue" alpha="1.0" r="0.0" g="0.0" b="1.0" showDaughters="true" visible="true"/>
<vis name="VisibleGreen" alpha="1.0" r="0.0" g="1.0" b="0.0" showDaughters="false" visible="true"/>
<vis name="VisibleGray" alpha="0.5" r="0.5" g="0.5" b="0.5" showDaughters="true" visible="true"/>
</display>

<limits>
<limitset name="BoxOfStrawsLimitSet">
<limit name="step_length_max" particles="*" value="1.0" unit="mm" />
<limit name="step_length_max" particles="*" value="5.0" unit="mm" />
<limit name="track_length_max" particles="*" value="1.0" unit="mm" />
</limitset>
</limits>

<regions>
<region name="StrawRegion" eunit="MeV" lunit="mm" cut="0.001" threshold="0.001">
<region name="StrawRegion" eunit="MeV" lunit="mm" cut="0.01" threshold="0.01">
<limitsetref name="BoxOfStrawsLimitSet"/>
</region>
</regions>
Expand Down
13 changes: 12 additions & 1 deletion examples/ClientTests/scripts/BoxOfStraws.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def run():
# Configure field
geant4.setupTrackingField(prt=True)
#
prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
prt.OutputLevel = Output.DEBUG
prt.OutputType = 3 # Print both: table and tree
kernel.eventAction().adopt(prt)
#
# Configure G4 geometry setup
seq, act = geant4.addDetectorConstruction('Geant4DetectorGeometryConstruction/ConstructGeo')
act.DebugVolumes = True
Expand All @@ -67,7 +72,8 @@ def run():
geant4.setupROOTOutput('RootOutput', 'BoxOfStraws_' + time.strftime('%Y-%m-%d_%H-%M'))
#
# Setup particle gun
gun = geant4.setupGun('Gun', particle='pi+', energy=100 * GeV, multiplicity=1)
gun = geant4.setupGun('Gun', particle='pi+', energy=10 * GeV, multiplicity=1)
gun.OutputLevel = Output.INFO
gun.enableUI()
#
# And handle the simulation particles.
Expand All @@ -83,7 +89,12 @@ def run():
# Map sensitive detectors of type 'BoxOfStraws' to Geant4CalorimeterAction
sd = geant4.description.sensitiveDetector(str('BoxOfStrawsDet'))
logger.info(f'+++ BoxOfStraws: SD type: {str(sd.type())}')
filter = DDG4.Filter(kernel, 'EnergyDepositMinimumCut')
filter.Cut = 1.0 * MeV
filter.enableUI()
kernel.registerGlobalFilter(filter)
seq, act = geant4.setupDetector(name='BoxOfStrawsDet', action='MyTrackerSDAction')
seq.adopt(filter)
act.HaveCellID = False
#
# Now build the physics list:
Expand Down
20 changes: 10 additions & 10 deletions examples/ClientTests/src/BoxOfStraws_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
const double thick = x_straw.thickness();
const double delta = 2e0*x_straw.rmax();
const int num_x = int(2e0*x_box.x() / delta);
const int num_z = int(2e0*x_box.z() / delta);
const int num_z = int(2e0*x_box.z() / (delta+2*tol));

Tube straw(0., x_straw.rmax()-tol, x_straw.y()-tol);
Volume straw_vol("straw", straw, description.material(x_straw.materialStr()));
Expand All @@ -54,26 +54,26 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
straw_gas_vol.setSensitiveDetector(sens);
}

Box box(x_box.x(), x_box.y(), x_box.z());
// Envelope: make envelope box 'tol' bigger on each side, so that the straws
Box box(x_box.x()+tol, x_box.y()+tol, x_box.z()+tol);
Volume box_vol(nam, box, description.air());
box_vol.setAttributes(description, x_box.regionStr(), x_box.limitsStr(), x_box.visStr());

Box layer(x_box.x(), x_box.y(), x_straw.rmax());
Volume layer_vol("layer", layer, description.air());
layer_vol.setVisAttributes(description.visAttributes("InvisibleWithChildren"));
layer_vol.setVisAttributes(description.visAttributes("VisibleGray"));

printout(INFO, "BoxOfStraws", "%s: Layer: nx: %7d nz: %7d delta: %7.3f", nam.c_str(), num_x, num_z, delta);
Rotation3D rot(RotationZYX(0e0, 0e0, M_PI/2e0));
for( int ix=0; ix < num_x; ++ix ) {
double x = -box.x() + (double(ix)+0.5) * delta;
PlacedVolume pv = layer_vol.placeVolume(straw_vol, Position(x, 0e0, 0e0));
double x = -box.x() + (double(ix)+0.5) * (delta + 2e0*tol);
PlacedVolume pv = layer_vol.placeVolume(straw_vol, Transform3D(rot,Position(x, 0e0, 0e0)));
pv.addPhysVolID("straw", ix);
}

// Not terribly clever: better would be to place layers instead of single straws....
Rotation3D rot(RotationZYX(0e0, 0e0, M_PI/2e0));
for( int iz=0; iz < num_z; ++iz ) {
double z = -box.z() + (double(iz)+0.5) * delta;
PlacedVolume pv = box_vol.placeVolume(layer_vol, Transform3D(rot, Position(0e0, 0e0, z)));
// leave 'tol' space between the layers
double z = -box.z() + (double(iz)+0.5) * (2.0*tol + delta);
PlacedVolume pv = box_vol.placeVolume(layer_vol, Position(0e0, 0e0, z));
pv.addPhysVolID("layer", iz);
}
printout(INFO, "BoxOfStraws", "%s: Created %d layers of %d straws each.", nam.c_str(), num_z, num_x);
Expand Down

0 comments on commit 85e5670

Please sign in to comment.