Skip to content

Commit

Permalink
DriftChamber example
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusFrankATcernch committed Dec 9, 2024
1 parent 74e7573 commit 69cb1b4
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 8 deletions.
11 changes: 5 additions & 6 deletions examples/ClientTests/compact/DriftChamber.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@
</includes>

<define>
<constant name="world_size" value="4*m"/>
<constant name="world_size" value="2*m"/>
<constant name="world_x" value="world_size"/>
<constant name="world_y" value="world_size"/>
<constant name="world_z" value="world_size"/>
<constant name="DriftChamber_rmin" value="30*cm"/>
<constant name="DriftChamber_rmax" value="100*cm"/>
<constant name="DriftChamber_zmax" value="300*cm"/>
<constant name="DriftChamber_zmax" value="100*cm"/>
</define>

<display>
<vis name="Invisible" showDaughters="false" visible="false"/>
<vis name="InvisibleWithChildren" showDaughters="true" visible="false"/>
<vis name="VisibleRed" r="1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/>
<vis name="VisibleBlue" alpha="0.3" r="0.0" g="0.0" b="1.0" showDaughters="false" visible="true"/>
<vis name="VisibleGreen" alpha="1.0" r="0.0" g="1.0" b="0.0" drawingStyle="solid" lineStyle="solid" showDaughters="true" visible="true"/>
<vis name="VisibleBlue" alpha="0.3" r="0.0" g="0.0" b="1.0" showDaughters="true" visible="true"/>
</display>

<detectors>
<detector id="1" name="DriftChamber" type="DD4hep_DriftChamber" readout="DriftChamberHits" vis="VisibleBlue">
<comment>A barrel hadronic calorimeter inspired on the ATLAS Tile hadronic calorimeter</comment>
<dimensions rmin="DriftChamber_rmin" rmax="DriftChamber_rmax" dz="DriftChamber_zmax" layers="200" />
<wire count="360" thickness="0.03*mm" material="Cu" vis="VisibleRed"/>
<dimensions rmin="DriftChamber_rmin" rmax="DriftChamber_rmax" dz="DriftChamber_zmax" layers="20" />
<wire count="60" thickness="3*mm" material="Cu" vis="VisibleRed"/>
</detector>
</detectors>

Expand Down
109 changes: 109 additions & 0 deletions examples/ClientTests/scripts/DriftChamber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# ==========================================================================
# AIDA Detector description implementation
# --------------------------------------------------------------------------
# Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
# All rights reserved.
#
# For the licensing terms see $DD4hepINSTALL/LICENSE.
# For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
#
# ==========================================================================
#
#
from __future__ import absolute_import, unicode_literals
import os
import time
import DDG4
from DDG4 import OutputLevel as Output
from g4units import GeV, MeV, m
#
#
"""
dd4hep simulation example setup using the python configuration
@author M.Frank
@version 1.0
"""


def run():
args = DDG4.CommandLine()
kernel = DDG4.Kernel()
install_dir = os.environ['DD4hepExamplesINSTALL']
kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/DriftChamber.xml"))

DDG4.importConstants(kernel.detectorDescription(), debug=False)
geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction')
geant4.registerInterruptHandler()
geant4.printDetectors()
# Configure UI
if args.macro:
ui = geant4.setupCshUI(macro=args.macro)
else:
ui = geant4.setupCshUI()

cmds = []
if args.verbose:
cmds.append('/run/verbose ' + str(args.verbose))
if args.events:
cmds.append('/run/beamOn ' + str(args.events))
cmds.append('/ddg4/UI/terminate')

if len(cmds) > 0:
ui.Commands = cmds

# Configure field
geant4.setupTrackingField(prt=True)
# Configure Event actions
prt = DDG4.EventAction(kernel, 'Geant4ParticlePrint/ParticlePrint')
prt.OutputLevel = Output.DEBUG
prt.OutputType = 3 # Print both: table and tree
kernel.eventAction().adopt(prt)

generator_output_level = Output.INFO

# Configure G4 geometry setup
seq, act = geant4.addDetectorConstruction("Geant4DetectorGeometryConstruction/ConstructGeo")
act.DebugMaterials = True
act.DebugElements = False
act.DebugVolumes = True
act.DebugShapes = True
seq, act = geant4.addDetectorConstruction("Geant4DetectorSensitivesConstruction/ConstructSD")

# Configure I/O
geant4.setupROOTOutput('RootOutput', 'DriftChamber_' + time.strftime('%Y-%m-%d_%H-%M'))

# Setup particle gun
gun = geant4.setupGun("Gun", particle='e+', energy=20 * GeV, multiplicity=1)
gun.OutputLevel = generator_output_level

# And handle the simulation particles.
part = DDG4.GeneratorAction(kernel, "Geant4ParticleHandler/ParticleHandler")
kernel.generatorAction().adopt(part)
part.SaveProcesses = ['Decay']
part.MinimalKineticEnergy = 100 * MeV
part.OutputLevel = Output.INFO # generator_output_level
part.enableUI()
user = DDG4.Action(kernel, "Geant4TCUserParticleHandler/UserParticleHandler")
user.TrackingVolume_Zmax = 3.0 * m
user.TrackingVolume_Rmax = 3.0 * m
user.enableUI()
part.adopt(user)

geant4.setupTracker('DriftChamber')

# Now build the physics list:
phys = geant4.setupPhysics('QGSP_BERT')
ph = DDG4.PhysicsList(kernel, str('Geant4PhysicsList/Myphysics'))
ph.addParticleConstructor(str('G4BosonConstructor'))
ph.enableUI()
phys.adopt(ph)
phys.dump()

geant4.execute()


if __name__ == "__main__":
run()
5 changes: 3 additions & 2 deletions examples/ClientTests/src/DriftChamber_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
double cyl_rmax = x_dim.rmax();
double cyl_dz = x_dim.dz();
double layer_cnt = x_dim.layers();

xml_comp_t x_wire = x_det.child(_Unicode(wire));
size_t wire_cnt = x_wire.count();
double wire_thick = x_wire.thickness();

double layer_thickness = (cyl_rmax - cyl_rmin)/double(layer_cnt+1);
double delta_phi = 2.0 * M_PI / double(wire_cnt);
double phi_start = 0e0;
Expand All @@ -57,7 +58,7 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s
sdet_vol.setAttributes(description, x_det.regionStr(), x_det.limitsStr(), x_det.visStr());

wire_vol.setSmartlessValue(2);
wire_vol.setVisAttributes(description.visAttributes(x_det.visStr()));
wire_vol.setVisAttributes(description.visAttributes(x_wire.visStr()));

for( std::size_t l=0; l<layer_cnt; ++l ) {
double radius = cyl_rmin + (0.5+double(l)) * layer_thickness;
Expand Down

0 comments on commit 69cb1b4

Please sign in to comment.