diff --git a/examples/ClientTests/compact/Issue_786.xml b/examples/ClientTests/compact/Issue_786.xml new file mode 100644 index 0000000000000000000000000000000000000000..7a5f4d730b0f080a2d48fac0cdf5df50266e3a80 --- /dev/null +++ b/examples/ClientTests/compact/Issue_786.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lccdd> +<!-- #========================================================================== + # 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. + # + #========================================================================== +--> + + <includes> + <gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/elements.xml"/> + <gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/materials.xml"/> + </includes> + + <define> + <constant name="world_size" value="30*m"/> + <constant name="world_x" value="world_size"/> + <constant name="world_y" value="world_size"/> + <constant name="world_z" value="world_size"/> + </define> + + <display> + <vis name="Shape0_vis" alpha="0.75" r="0" g="1" b="1" showDaughters="true" visible="true"/> + <vis name="Shape1_vis" alpha="0.75" r="1" g="0" b="0" showDaughters="true" visible="true"/> + <vis name="Shape2_vis" alpha="0.75" r="0" g="1" b="0" showDaughters="true" visible="true"/> + <vis name="Shape3_vis" alpha="0.75" r="0" g="0" b="1" showDaughters="true" visible="true"/> + <vis name="Shape4_vis" alpha="0.75" r="1" g="1" b="0" showDaughters="true" visible="true"/> + <vis name="Shape5_vis" alpha="0.75" r="1" g="0" b="1" showDaughters="true" visible="true"/> + <vis name="Shape_grey" alpha="0.5" r="0.0" g="0.4" b="0.4" showDaughters="true" visible="true"/> + </display> + + <detectors> + <detector id="1" name="Issue" type="Issue_786" readout="IssueHits" vis="Shape_grey"/> + </detectors> + + <readouts> + <readout name="IssueHits"> + <id>system:8,node:3,parent:3,container:4,child:2</id> + </readout> + </readouts> + + <fields> + <field name="GlobalSolenoid" type="solenoid" + inner_field="5.0*tesla" + outer_field="-1.5*tesla" + zmax="2*m" + outer_radius="3*m"> + </field> + </fields> + +</lccdd> diff --git a/examples/ClientTests/scripts/Issue_786.py b/examples/ClientTests/scripts/Issue_786.py new file mode 100644 index 0000000000000000000000000000000000000000..52e89ddacfa58010cdbe57cbf898c52f143be803 --- /dev/null +++ b/examples/ClientTests/scripts/Issue_786.py @@ -0,0 +1,98 @@ +# ========================================================================== +# 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 sys +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(): + kernel = DDG4.Kernel() + install_dir = os.environ['DD4hepExamplesINSTALL'] + kernel.loadGeometry(str("file:" + install_dir + "/examples/ClientTests/compact/Issue_786.xml")) + DDG4.importConstants(kernel.detectorDescription(), debug=False) + geant4 = DDG4.Geant4(kernel, tracker='Geant4TrackerCombineAction') + geant4.printDetectors() + # Configure UI + if len(sys.argv) > 1: + geant4.setupCshUI(macro=sys.argv[1]) + else: + geant4.setupCshUI() + + # 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 = False + act.DebugElements = False + act.DebugVolumes = True + act.DebugShapes = True + act.DebugPlacements = True + + # Configure I/O + geant4.setupROOTOutput('RootOutput', 'Issue_' + time.strftime('%Y-%m-%d_%H-%M')) + + # Setup particle gun + gun = geant4.setupGun("Gun", particle='mu-', 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('Issue') + + # Now build the physics list: + phys = geant4.setupPhysics('QGSP_BERT') + ph = DDG4.PhysicsList(kernel, str('Geant4PhysicsList/Myphysics')) + ph.addParticleConstructor(str('G4Geantino')) + ph.addParticleConstructor(str('G4BosonConstructor')) + ph.enableUI() + phys.adopt(ph) + phys.dump() + + geant4.execute() + + +if __name__ == "__main__": + run() diff --git a/examples/ClientTests/src/Issue_786_geo.cpp b/examples/ClientTests/src/Issue_786_geo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7d843aa49ace868d8059c19bbcb49a5d670433c1 --- /dev/null +++ b/examples/ClientTests/src/Issue_786_geo.cpp @@ -0,0 +1,66 @@ +//========================================================================== +// 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. +// +// Author : M.Frank +// +//========================================================================== + +// Framework includes +#include "DD4hep/DetFactoryHelper.h" + +using namespace dd4hep; +using namespace dd4hep::detail; + +static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens) { + xml_dim_t x_det = e; + DetElement det(x_det.nameStr(),x_det.id()); + + Volume node( "node", Box(170, 70, 70), description.air()); + Volume otherParent("otherparent", Box( 50, 50, 50), description.air()); + Volume otherNode( "othernode", Box(100, 50, 50), description.material("Iron")); + Volume parent( "parent", Box(90, 40, 40), description.material("Iron")); + Volume container( "container", Box(30, 30, 30), description.air()); + Volume child( "child", Box(20, 20, 20), description.material("Iron")); + + sens.setType("tracker"); + + node.setVisAttributes( description, x_det.visStr()); + otherParent.setVisAttributes( description, "Shape0_vis"); + otherNode.setVisAttributes( description, "Shape1_vis"); + parent.setVisAttributes( description, "Shape2_vis"); + container.setVisAttributes( description, "Shape3_vis"); + child.setVisAttributes( description, "Shape4_vis"); + child.setSensitiveDetector(sens); + + auto pv = container.placeVolume( child ); + pv.addPhysVolID( "child", 0); + pv = parent.placeVolume( container, Position( 45, 0, 0) ); + pv.addPhysVolID( "container", 0); + pv = parent.placeVolume( container, Position(-45, 0, 0) ); + pv.addPhysVolID( "container", 1); + pv = otherNode.placeVolume( parent ); + pv.addPhysVolID( "parent", 0); + pv = node.placeVolume( otherNode, Position( 60, 0, 0) ); + pv.addPhysVolID( "node", 0); + + pv = otherParent.placeVolume( container ); + pv.addPhysVolID( "container",3); + pv.addPhysVolID( "parent", 1); + pv = node.placeVolume( otherParent, Position(-110, 0, 0) ); + pv.addPhysVolID( "node", 1); + + // Place the calo inside the world + auto mother = description.pickMotherVolume(det); + pv = mother.placeVolume(node); + pv.addPhysVolID( "system",x_det.id() ); + det.setPlacement(pv); + return det; +} + +DECLARE_DETELEMENT(Issue_786,create_detector)