From 7994dd9d949c85e0ab7dc207e666aacade6bdb1b Mon Sep 17 00:00:00 2001 From: Markus Frank Date: Thu, 18 Jan 2024 10:55:57 +0100 Subject: [PATCH] Update FiberTubeCalorimeter example --- .../compact/FiberTubeCalorimeter.xml | 15 +-- .../scripts/FiberTubeCalorimeter.py | 95 +++++++++++++++++++ .../src/FiberTubeCalorimeter_geo.cpp | 56 ++++++----- 3 files changed, 137 insertions(+), 29 deletions(-) create mode 100644 examples/ClientTests/scripts/FiberTubeCalorimeter.py diff --git a/examples/ClientTests/compact/FiberTubeCalorimeter.xml b/examples/ClientTests/compact/FiberTubeCalorimeter.xml index 41b322b38..94544908e 100644 --- a/examples/ClientTests/compact/FiberTubeCalorimeter.xml +++ b/examples/ClientTests/compact/FiberTubeCalorimeter.xml @@ -70,11 +70,12 @@ - + + @@ -92,18 +93,18 @@ zmin is where the dtector goes --> - - - - - + + + + + diff --git a/examples/ClientTests/scripts/FiberTubeCalorimeter.py b/examples/ClientTests/scripts/FiberTubeCalorimeter.py new file mode 100644 index 000000000..01e465bb7 --- /dev/null +++ b/examples/ClientTests/scripts/FiberTubeCalorimeter.py @@ -0,0 +1,95 @@ +# ========================================================================== +# 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/FiberTubeCalorimeter.xml")) + + DDG4.importConstants(kernel.detectorDescription(), debug=False) + geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction') + geant4.printDetectors() + # Configure UI + if args.macro: + ui = geant4.setupCshUI(macro=args.macro) + else: + ui = geant4.setupCshUI() + if args.batch: + ui.Commands = ['/run/beamOn ' + str(args.events), '/ddg4/UI/terminate'] + + # 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', 'FiberTubeCalorimeter_' + time.strftime('%Y-%m-%d_%H-%M')) + + # Setup particle gun + gun = geant4.setupGun("Gun", particle='e+', energy=20 * GeV, multiplicity=1, position=(0.0, 0.0, -369.0)) + 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.setupCalorimeter('FiberTubeCalorimeter') + + # Now build the physics list: + phys = geant4.setupPhysics('QGSP_BERT') + phys.dump() + geant4.execute() + + +if __name__ == "__main__": + run() diff --git a/examples/ClientTests/src/FiberTubeCalorimeter_geo.cpp b/examples/ClientTests/src/FiberTubeCalorimeter_geo.cpp index 99e50aacb..bca02b101 100644 --- a/examples/ClientTests/src/FiberTubeCalorimeter_geo.cpp +++ b/examples/ClientTests/src/FiberTubeCalorimeter_geo.cpp @@ -68,27 +68,17 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s // these refer to different fields in the xml file for this detector xml_comp_t fX_struct( x_det.child( _Unicode(structure) ) ); xml_comp_t fX_absorb( fX_struct.child( _Unicode(absorb) ) ); - xml_comp_t fX_core1( fX_struct.child( _Unicode(core1) ) ); - xml_comp_t fX_core2( fX_struct.child( _Unicode(core2) ) ); - xml_comp_t fX_hole( fX_struct.child( _Unicode(hole) ) ); + xml_comp_t fX_core1( fX_struct.child( _Unicode(core1) ) ); + xml_comp_t fX_core2( fX_struct.child( _Unicode(core2) ) ); + xml_comp_t fX_hole( fX_struct.child( _Unicode(hole) ) ); xml_comp_t fX_phdet1( fX_struct.child( _Unicode(phdet1) ) ); xml_comp_t fX_phdet2( fX_struct.child( _Unicode(phdet2) ) ); - - // detector element for entire detector. - DetElement sdet (det_name, det_id); - Volume motherVol = description.pickMotherVolume(sdet); - Box env_box ((2*Ncount+1)*(hthick+agap+tol),(2*Ncount+1)*(hthick+agap+tol), (hzlength+hzph+tol)); - Volume envelopeVol (det_name, env_box, air); - envelopeVol.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr()); Material mat; Transform3D trafo; PlacedVolume pv; Solid sol; - - pv = motherVol.placeVolume(envelopeVol, Position(0.,0.,azmin+hzlength+hzph+tol)); - pv.addPhysVolID("system", det_id); - sdet.setPlacement(pv); // associate the placed volume to the detector element + sens.setType("calorimeter"); // scint fiber @@ -182,24 +172,40 @@ static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector s } // setup the volumes with the shapes and properties in one horixontal layer - Volume tube_row_vol("layer", Box(hthick,hthick,hzlength+hzph), air); + double dx = 2*(Ncount + Ncount+1)/2e0 * (hthick+agap) + tol; + double dy = hthick + tol; + double dz = hzlength+hzph + tol; + Box tube_row_box(dx, dy, dz); + Volume tube_row_vol("layer", tube_row_box, air); tube_row_vol.setVisAttributes(description, x_det.visStr()); tube_row_vol.setSensitiveDetector(sens); - + cout << tube_row_vol.name() + << " dx: " << tube_row_box.x() + << " dy: " << tube_row_box.y() + << " dz: " << tube_row_box.z() << endl; + tube_row_vol.setVisAttributes(description, "layerVis"); + for (int ijk=-Ncount; ijk