Skip to content

Commit

Permalink
Have real straws (thin tubes filled with gas) for BoxOfStraws examples
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusFrankATcernch committed Jul 4, 2024
1 parent 31eccc3 commit eb5dcc3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
18 changes: 18 additions & 0 deletions DDCore/python/dd4hep_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,21 @@ def __init__(self, name):

def setPrintLevel(self, level):
"Adjust printout level of dd4hep"
if isinstance(level, str):
if level == 'VERBOSE':
level = OutputLevel.VERBOSE
elif level == 'DEBUG':
level = OutputLevel.DEBUG
elif level == 'INFO':
level = OutputLevel.INFO
elif level == 'WARNING':
level = OutputLevel.WARNING
elif level == 'ERROR':
level = OutputLevel.ERROR
elif level == 'FATAL':
level = OutputLevel.FATAL
else:
level = int(level)
dd4hep.setPrintLevel(level)

def always(self, msg):
Expand Down Expand Up @@ -407,6 +422,9 @@ def __init__(self, help=None): # noqa: A002
have_help = True
if have_help and help_call:
help_call()
if self.data.get('print_level'):
log = Logger('CommandLine')
log.setPrintLevel(self.data.get('print_level'))

def __getattr__(self, attr):
if self.data.get(attr):
Expand Down
4 changes: 2 additions & 2 deletions examples/ClientTests/compact/BoxOfStraws.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
<detectors>
<detector id="1" name="BoxOfStrawsDet" type="DD4hep_BoxOfStraws" readout="BoxOfStrawsHits" vis="VisibleGreen" region="StrawRegion" limits="BoxOfStrawsLimitSet">
<box x="1*m" y="1*m" z="1000*mm" limits="BoxOfStrawsLimitSet" vis="VisibleRed"/>
<straw rmax="1*mm" y="1*m" vis="VisibleBlue">
<material name="Iron"/>
<straw rmax="2*mm" y="1*m" thickness="0.5*mm" vis="VisibleBlue">
<material name="Argon"/>
<non_sensitive/>
</straw>
<position x="0*m" y="0*m" z="0*m"/>
Expand Down
12 changes: 5 additions & 7 deletions examples/ClientTests/scripts/BoxOfStraws.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ def run():
args = DDG4.CommandLine()
kernel = DDG4.Kernel()
logger = DDG4.Logger('BoxOfStraws')
install_dir = os.environ['DD4hepExamplesINSTALL']
kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/BoxOfStraws.xml"))
kernel.loadGeometry(str("file:" + os.environ['DD4hepExamplesINSTALL'] + "/examples/ClientTests/compact/BoxOfStraws.xml"))

DDG4.importConstants(kernel.detectorDescription(), debug=False)
geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
geant4 = DDG4.Geant4(kernel)
geant4.printDetectors()
# Configure UI
if args.macro:
Expand All @@ -45,8 +44,6 @@ def run():
ui = geant4.setupCshUI()
if args.batch:
ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate']
if args.print:
logger.setPrintLevel(int(args.print))
#
# Configure field
geant4.setupTrackingField(prt=True)
Expand All @@ -62,13 +59,14 @@ def run():
seq, act = geant4.addDetectorConstruction("Geant4RegexSensitivesConstruction/ConstructSDRegEx")
act.Detector = 'BoxOfStrawsDet'
act.OutputLevel = Output.ALWAYS
act.Regex = '/world_volume_(.*)/BoxOfStrawsDet_(.*)/row_(.*)/straw_(.*)'
act.Regex = '/world_volume_(.*)/BoxOfStrawsDet_(.*)/layer_(.*)/straw_(.*)/gas_(.*)'
act.Regex = '/world_volume_(.*)/BoxOfStrawsDet_(.*)/layer_(.*)/straw_(.*)'
#
# Configure I/O
geant4.setupROOTOutput('RootOutput', 'BoxOfStraws_' + time.strftime('%Y-%m-%d_%H-%M'))
#
# Setup particle gun
gun = geant4.setupGun("Gun", particle='e+', energy=10 * GeV, multiplicity=1)
gun = geant4.setupGun("Gun", particle='pi+', energy=100 * GeV, multiplicity=1)
gun.enableUI()
#
# And handle the simulation particles.
Expand Down
12 changes: 8 additions & 4 deletions examples/ClientTests/src/BoxOfStraws_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,26 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
xml_dim_t x_pos = x_det.child(_U(position));
xml_det_t x_straw = x_det.child(_Unicode(straw));
std::string nam = x_det.nameStr();
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);

// Have box like straws: voxelization should be more efficient and for our test it does not matter.
Tube straw(0., x_straw.rmax()-tol, x_straw.y()-tol);
//Box straw(x_straw.rmax()-tol, x_straw.rmax()-tol, x_straw.y()-tol);
Volume straw_vol("straw", straw, description.material(x_straw.materialStr()));
Volume straw_vol("straw", straw, description.material("Iron"));

Tube straw_gas(0., x_straw.rmax()-tol-thick, x_straw.y()-tol-thick);
Volume straw_gas_vol("gas", straw_gas, description.material(x_straw.materialStr()));

straw_vol.setAttributes(description, x_straw.regionStr(), x_straw.limitsStr(), x_straw.visStr());
straw_vol.placeVolume(straw_gas_vol);

printout(INFO, "BoxOfStraws", "%s: Straw: rmax: %7.3f y: %7.3f mat: %s vis: %s solid: %s",
nam.c_str(), x_straw.rmax(), x_straw.y(), x_straw.materialStr().c_str(),
x_straw.visStr().c_str(), straw.type());
if ( x_straw.hasChild(_U(sensitive)) ) {
sens.setType("tracker");
straw_vol.setSensitiveDetector(sens);
straw_gas_vol.setSensitiveDetector(sens);
}

Box box(x_box.x(), x_box.y(), x_box.z());
Expand Down

0 comments on commit eb5dcc3

Please sign in to comment.