diff --git a/DDCore/src/plugins/Compact2Objects.cpp b/DDCore/src/plugins/Compact2Objects.cpp index 6f2acaaa2a4fc6a36d1cb6a4d1383aa3dd907063..009f81a9e129392b58bc5348f0e9458be7350203 100644 --- a/DDCore/src/plugins/Compact2Objects.cpp +++ b/DDCore/src/plugins/Compact2Objects.cpp @@ -646,7 +646,7 @@ template <> void Converter<CartesianField>::operator()(xml_h e) const { lcdd.field().properties() = prp; } } - printout(ALWAYS, "Compact", "++ Converted field: Successfully %s field %s [%s]", msg.c_str(), name.c_str(), type.c_str()); + printout(INFO, "Compact", "++ Converted field: Successfully %s field %s [%s]", msg.c_str(), name.c_str(), type.c_str()); } /** Update sensitive detectors from group tags. diff --git a/DDG4/examples/CLICSidXML.C b/DDG4/examples/CLICSidXML.C index c9bce6c5ad3aa7c5c46e288ab04323a520e059e0..c9803c453a375f3baee5199f25209a2a81e5fa38 100644 --- a/DDG4/examples/CLICSidXML.C +++ b/DDG4/examples/CLICSidXML.C @@ -25,12 +25,12 @@ using namespace DD4hep::Simulation::Setup; void setupG4_XML() { - std::string prefix = "file:../DD4hep.trunk"; + std::string prefix = "file:../DD4hep"; Kernel& kernel = Kernel::instance(Kernel::LCDD::getInstance()); - kernel.loadGeometry((prefix+"/DDExamples/CLICSiD/compact/compact.xml").c_str()); - kernel.loadXML((prefix+"/DDG4/examples/DDG4_field.xml").c_str()); - kernel.loadXML((prefix+"/DDG4/examples/sequences.xml").c_str()); - kernel.loadXML((prefix+"/DDG4/examples/physics.xml").c_str()); + kernel.loadGeometry((prefix+"/examples/CLICSiD/compact/compact.xml").c_str()); + kernel.loadXML((prefix+"/examples/DDG4/examples/DDG4_field.xml").c_str()); + kernel.loadXML((prefix+"/examples/DDG4/examples/sequences.xml").c_str()); + kernel.loadXML((prefix+"/examples/DDG4/examples/physics.xml").c_str()); kernel.property("UI") = "UI"; kernel.configure(); kernel.initialize(); diff --git a/DDG4/examples/xmlAClick.C b/DDG4/examples/xmlAClick.C index 8fd6e188cbe36914a7f24458c6f92164ee39cc3e..d5be709131c4664c561a354456810316e9857d0f 100644 --- a/DDG4/examples/xmlAClick.C +++ b/DDG4/examples/xmlAClick.C @@ -25,12 +25,12 @@ using namespace DD4hep::Simulation::Setup; void setupG4_XML() { - std::string prefix = "file:../DD4hep.trunk"; + std::string prefix = "file:../DD4hep"; Kernel& kernel = Kernel::instance(Kernel::LCDD::getInstance()); - kernel.loadGeometry((prefix+"/DDExamples/CLICSiD/compact/compact.xml").c_str()); - kernel.loadXML((prefix+"/DDG4/examples/DDG4_field.xml").c_str()); - kernel.loadXML((prefix+"/DDG4/examples/sequences.xml").c_str()); - kernel.loadXML((prefix+"/DDG4/examples/physics.xml").c_str()); + kernel.loadGeometry((prefix+"/examples/CLICSiD/compact/compact.xml").c_str()); + kernel.loadXML((prefix+"/examples/DDG4/examples/DDG4_field.xml").c_str()); + kernel.loadXML((prefix+"/examples/DDG4/examples/sequences.xml").c_str()); + kernel.loadXML((prefix+"/examples/DDG4/examples/physics.xml").c_str()); kernel.property("UI") = "UI"; kernel.configure(); kernel.initialize(); diff --git a/DDG4/plugins/Geant4XMLSetup.cpp b/DDG4/plugins/Geant4XMLSetup.cpp index 25244b52bf5db7280be938530b3ed96b02b23bec..dd95a2262955a9b72de16958cd0476cf49630c91 100644 --- a/DDG4/plugins/Geant4XMLSetup.cpp +++ b/DDG4/plugins/Geant4XMLSetup.cpp @@ -24,6 +24,7 @@ namespace DD4hep { typedef DD4hep::Geometry::LCDD lcdd_t; typedef DD4hep::Geometry::DetElement DetElement; + typedef DD4hep::Geometry::SensitiveDetector SensitiveDetector; /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit namespace Simulation { @@ -284,7 +285,16 @@ namespace DD4hep { Kernel& kernel = Kernel::access(lcdd); if ( seq.hasAttr(_U(sd)) ) { - seqNam = seq.attr<string>(_U(type))+"/"+seq.attr<string>(_U(sd)); + string sd_nam = seq.attr<string>(_U(sd)); + SensitiveDetector sensitive = lcdd.sensitiveDetector(sd_nam); + seqNam = seq.attr<string>(_U(type))+"/"+sd_nam; + if ( !sensitive.isValid() ) { + printout(ALWAYS,"Geant4Setup","+++ ActionSequence %s is defined, " + "but no sensitive detector present.",seqNam.c_str()); + printout(ALWAYS,"Geant4Setup","+++ ---> Sequence for detector %s IGNORED on popular request!", + sd_nam.c_str()); + return; + } seqType = TypeName::split(seqNam); sdSeq = SensitiveSeq(kernel,seqNam); what = SENSITIVE; diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index 1099750fbc4699b7a4bf8f3d3deec89bfdd26a97..c30437a3a7dfde3c534efe184cff98f3cea71b60 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -286,16 +286,18 @@ class Simple: self.kernel.generatorAction().add(gun) return gun - def setupUI(self,typ='csh',vis=False,ui=True): + def setupUI(self,typ='csh',vis=False,ui=True,macro=None): # Configure UI ui_action = Action(self.kernel,"Geant4UIManager/UI") ui_action.HaveVIS = vis ui_action.HaveUI = ui ui_action.SessionType = typ + if macro is not None: + ui_action.SetupUI = macro self.kernel.registerGlobalAction(ui_action) - def setupCshUI(self,typ='csh',vis=False,ui=True): - self.setupUI(typ='csh',vis=vis,ui=ui) + def setupCshUI(self,typ='csh',vis=False,ui=True,macro=None): + self.setupUI(typ='csh',vis=vis,ui=ui,macro=macro) def setupROOTOutput(self,name,output): evt_root = EventAction(self.kernel,'Geant4Output2ROOT/'+name) diff --git a/UtilityApps/CMakeLists.txt b/UtilityApps/CMakeLists.txt index 510e2547697447872c1fe0efeb395eab536668d6..9a50c9bcc0257e99551846696477a3b776ebc36c 100644 --- a/UtilityApps/CMakeLists.txt +++ b/UtilityApps/CMakeLists.txt @@ -21,6 +21,9 @@ target_link_libraries(geoPluginRun DD4hepCore) add_executable( print_materials src/print_materials.cpp) target_link_libraries(print_materials DD4hepCore DD4hepRec) #----------------------------------------------------------------------------------- +add_executable( materialScan src/materialScan.cpp) +target_link_libraries(materialScan DD4hepCore DD4hepRec) +#----------------------------------------------------------------------------------- root_generate_dictionary( G__teve src/EvNavHandler.h LINKDEF src/LinkDef.h) @@ -35,7 +38,7 @@ target_link_libraries( teveDisplay DD4hepCore ${ROOT_EVE_LIBRARIES} DD4hepRec ${ #--- install target------------------------------------- -install(TARGETS geoDisplay geoConverter geoPluginRun teveDisplay print_materials +install(TARGETS geoDisplay geoConverter geoPluginRun teveDisplay print_materials materialScan RUNTIME DESTINATION bin LIBRARY DESTINATION lib ) diff --git a/UtilityApps/src/materialScan.cpp b/UtilityApps/src/materialScan.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f62feecbf759ddba2edc4c845e8e85981ab6328b --- /dev/null +++ b/UtilityApps/src/materialScan.cpp @@ -0,0 +1,93 @@ +// $Id:$ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Simple program to print all the materials in a detector on +// a straight line between two given points +// +// Author : F.Gaede, DESY +// Author : M.Frank, CERN +// +//==================================================================== +#include "TError.h" +#include "DD4hep/LCDD.h" +#include "DD4hep/Printout.h" +#include "DDRec/MaterialManager.h" + +using namespace DD4hep; +using namespace DDRec; +using DDSurfaces::Vector3D; + +int main(int argc, char** argv) { + struct Handler { + Handler() { SetErrorHandler(Handler::print); } + static void print(int level, Bool_t abort, const char *location, const char *msg) { + if ( level > kInfo || abort ) ::printf("%s: %s\n", location, msg); + } + static void usage() { + std::cout << " usage: materialScan compact.xml x0 y0 z0 x1 y1 z1 " << std::endl + << " -> prints the materials on a straight line between the two given points ( unit is cm) " + << std::endl; + exit(1); + } + } _handler; + + if( argc != 8 ) Handler::usage(); + + Vector3D p0, p1, end, direction; + std::string inFile = argv[1]; + std::stringstream sstr; + sstr << argv[2] << " " << argv[3] << " " << argv[4] << " " << argv[5] << " " << argv[6] << " " << argv[7] << " " << "NONE"; + sstr >> p0.array()[0] >> p0.array()[1] >> p0.array()[2]; + sstr >> p1.array()[0] >> p1.array()[1] >> p1.array()[2]; + if ( !sstr.good() ) Handler::usage(); + + setPrintLevel(WARNING); + Geometry::LCDD& lcdd = Geometry::LCDD::getInstance(); + lcdd.fromCompact(inFile); + direction = (p1-p0).unit(); + + MaterialManager matMgr; + const MaterialVec& materials = matMgr.materialsBetween(p0, p1); + double sum_x0 = 0; + double sum_lambda = 0; + double path_length = 0; + const char* fmt1 = " | %5d %-20s %3.0f %8.3f %8.4f %11.4f %11.4f %10.3f %8.2f %11.6f %11.6f (%7.2f,%7.2f,%7.2f)\n"; + const char* fmt2 = " | %5d %-20s %3.0f %8.3f %8.4f %11.6g %11.6g %10.3f %8.2f %11.6f %11.6f (%7.2f,%7.2f,%7.2f)\n"; + const char* line = " +--------------------------------------------------------------------------------------------------------------------------------------------------\n"; + + ::printf("%s + Material scan between: x_0 = (%7.2f,%7.2f,%7.2f) [cm] and x_1 = (%7.2f,%7.2f,%7.2f) [cm] : \n%s", + line,p0[0],p0[1],p0[2],p1[0],p1[1],p1[2],line); + ::printf(" | \\ %-11s Atomic Radiation Interaction Path Integrated Integrated Material\n","Material"); + ::printf(" | Num. \\ %-11s Number/Z Mass/A Density Length Length Thickness Length X0 Lambda Endpoint \n","Name"); + ::printf(" | Layer \\ %-11s [g/mole] [g/cm3] [cm] [cm] [cm] [cm] [cm] [cm] ( cm, cm, cm)\n",""); + ::printf("%s",line); + + for( unsigned i=0,n=materials.size();i<n;++i){ + TGeoMaterial* mat = materials[i].first->GetMaterial(); + double length = materials[i].second ; + double nx0 = length / mat->GetRadLen() ; + sum_x0 += nx0; + double nLambda = length / mat->GetIntLen() ; + sum_lambda += nLambda; + path_length += length; + end = path_length * direction; + const char* fmt = mat->GetRadLen() >= 1e5 ? fmt2 : fmt1; + ::printf(fmt, i+1, mat->GetName(), mat->GetZ(), mat->GetA(), + mat->GetDensity(), mat->GetRadLen(), mat->GetIntLen(), + length, path_length, sum_x0, sum_lambda, end[0], end[1], end[2]); + } + printf("%s",line); + const MaterialData& avg = matMgr.createAveragedMaterial(materials); + const char* fmt = avg.radiationLength() >= 1e5 ? fmt2 : fmt1; + end = path_length * direction; + ::printf(fmt,0,"Average Material",avg.Z(),avg.A(),avg.density(), + avg.radiationLength(), avg.interactionLength(), + path_length, path_length, + path_length/avg.radiationLength(), + path_length/avg.interactionLength(), + end[0], end[1], end[2]); + printf("%s",line); + return 0; +} diff --git a/examples/CLICSiD/compact/compact.xml b/examples/CLICSiD/compact/compact.xml index d02b2bcd9895c6cc0f0136848f3e0d9b5d1ab02a..c5c42a665c6b42972cd8a26e56965a0a4751d62f 100644 --- a/examples/CLICSiD/compact/compact.xml +++ b/examples/CLICSiD/compact/compact.xml @@ -271,7 +271,7 @@ <detectors> - +<!-- <comment>Trackers</comment> <detector id="1" name="SiVertexBarrel" type="DD4hep_SiTrackerBarrel" readout="SiVertexBarrelHits" insideTrackingVolume="true"> <comment>Vertex Detector Barrel</comment> @@ -663,7 +663,7 @@ <slice material = "Air" thickness = "0.033*cm" /> </layer> </detector> - +--> <detector id="7" name="EcalEndcap" type="DD4hep_PolyhedraEndcapCalorimeter2" reflect="true" readout="EcalEndcapHits" vis="EcalEndcapVis" calorimeterType="EM_ENDCAP"> <comment>EM Calorimeter Endcaps</comment> <dimensions numsides="(int) CaloSides" zmin="EcalEndcap_zmin" rmin="EcalEndcap_rmin" rmax="EcalEndcap_rmax" /> diff --git a/examples/ClientTests/compact/SiliconBlock.lcdd b/examples/ClientTests/compact/SiliconBlock.lcdd new file mode 100644 index 0000000000000000000000000000000000000000..8bada85c315d690d7cef7b44906446ab3c0b546b --- /dev/null +++ b/examples/ClientTests/compact/SiliconBlock.lcdd @@ -0,0 +1,138 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> +<lcdd xmlns:lcdd="http://www.lcsim.org/schemas/lcdd/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/lcdd/1.0/lcdd.xsd"> + + <!-- + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + ++++ Linear collider detector description LCDD in C++ ++++ + ++++ DD4hep Detector description generator. ++++ + ++++ ++++ + ++++ Parser: Apache Xerces-C DOM Parser ++++ + ++++ ++++ + ++++ M.Frank CERN/LHCb ++++ + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + --> + + <header> + <detector name="SiliconBlock"/> + <generator checksum="0" file="http://www.cern.ch/lhcb" name="LCDDConverter" version="$Id: compact.xml 513 2013-04-05 14:31:53Z gaede $"/> + <author name="Markus Frank"/> + <comment>Alignment test with 2 simple boxes</comment> + </header> + + <iddict> + <idspec length="0" name="SiliconUpperHits"> + <idfield label="system" length="8" signed="false" start="0"/> + </idspec> + <idspec length="0" name="SiliconDownHits"> + <idfield label="system" length="8" signed="false" start="0"/> + </idspec> + </iddict> + + <sensitive_detectors> + <tracker ecut="0.00000000e+00" eunit="MeV" hits_collection="SiliconUpperHits" name="SiliconBlockUpper" verbose="0"> + <idspecref ref="SiliconUpperHits"/> + </tracker> + <tracker ecut="0.00000000e+00" eunit="MeV" hits_collection="SiliconDownHits" name="SiliconBlockDown" verbose="0"> + <idspecref ref="SiliconDownHits"/> + </tracker> + </sensitive_detectors> + + <limits> + <limitset name="SiRegionLimitSet"> + <limit name="track_length_max" particles="*" unit="mm" value="1.00000000e-01"/> + <limit name="step_length_max" particles="*" unit="mm" value="5.00000000e-01"/> + </limitset> + </limits> + + <regions> + <region cut="1.00000000e-04" eunit="GeV" lunit="cm" name="SiRegion" store_secondaries="false"/> + </regions> + + <display> + <vis drawing_style="solid" line_style="unbroken" name="VisibleGreen" show_daughters="true" visible="true"> + <color B="0.00000000e+00" G="1.00000000e+00" R="0.00000000e+00" alpha="1.00000000e+00"/> + </vis> + <vis drawing_style="solid" line_style="unbroken" name="VisibleRed" show_daughters="true" visible="true"> + <color B="0.00000000e+00" G="0.00000000e+00" R="1.00000000e+00" alpha="1.00000001e-01"/> + </vis> + </display> + + <gdml> + <define> + <position name="SiliconBlockUpper_vol_0_0xa70d1c0_pos" unit="mm" x="4.00000000e+01" y="0.00000000e+00" z="0.00000000e+00"/> + <rotation name="identity_rot" unit="rad" x="0" y="0" z="0"/> + <position name="SiliconBlockDown_vol_1_0xa70d9e0_pos" unit="mm" x="-4.00000000e+01" y="0.00000000e+00" z="0.00000000e+00"/> + </define> + <materials> + <element Z="7" formula="N" name="N"> + <atom type="A" unit="g/mol" value="1.40067400e+01"/> + </element> + <element Z="8" formula="O" name="O"> + <atom type="A" unit="g/mol" value="1.59994000e+01"/> + </element> + <element Z="18" formula="AR" name="AR"> + <atom type="A" unit="g/mol" value="3.99480000e+01"/> + </element> + <material name="Air"> + <D type="density" unit="g/cm3" value="1.20000000e-03"/> + <fraction n="7.54000000e-01" ref="N"/> + <fraction n="2.34000000e-01" ref="O"/> + <fraction n="1.20000000e-02" ref="AR"/> + </material> + <element Z="14" formula="SI" name="SI"> + <atom type="A" unit="g/mol" value="2.80855000e+01"/> + </element> + <material name="Silicon"> + <D type="density" unit="g/cm3" value="2.33000000e+00"/> + <fraction n="1.00000000e+00" ref="SI"/> + </material> + </materials> + <solids> + <box lunit="mm" name="world_volume_shape" x="6.00000000e+04" y="6.00000000e+04" z="6.00000000e+04"/> + <box lunit="mm" name="SiliconBlockUpper_vol_shape" x="4.00000000e+01" y="4.00000000e+02" z="4.00000000e+02"/> + <box lunit="mm" name="SiliconBlockDown_vol_shape" x="4.00000000e+01" y="4.00000000e+02" z="4.00000000e+02"/> + </solids> + <structure> + <volume name="SiliconBlockUpper_vol"> + <materialref ref="Silicon"/> + <solidref ref="SiliconBlockUpper_vol_shape"/> + <sdref ref="SiliconBlockUpper"/> + <regionref ref="SiRegion"/> + <limitsetref ref="SiRegionLimitSet"/> + <visref ref="VisibleGreen"/> + </volume> + <volume name="SiliconBlockDown_vol"> + <materialref ref="Silicon"/> + <solidref ref="SiliconBlockDown_vol_shape"/> + <sdref ref="SiliconBlockDown"/> + <regionref ref="SiRegion"/> + <limitsetref ref="SiRegionLimitSet"/> + <visref ref="VisibleRed"/> + </volume> + <volume name="world_volume"> + <materialref ref="Air"/> + <solidref ref="world_volume_shape"/> + <physvol> + <volumeref ref="SiliconBlockUpper_vol"/> + <positionref ref="SiliconBlockUpper_vol_0_0xa70d1c0_pos"/> + <rotationref ref="identity_rot"/> + <physvolid field_name="system" value="1"/> + </physvol> + <physvol> + <volumeref ref="SiliconBlockDown_vol"/> + <positionref ref="SiliconBlockDown_vol_1_0xa70d9e0_pos"/> + <rotationref ref="identity_rot"/> + <physvolid field_name="system" value="2"/> + </physvol> + </volume> + </structure> + <setup name="Default" version="1.0"> + <world ref="world_volume"/> + </setup> + </gdml> + + <fields> + <solenoid funit="tesla" inner_field="5.00000000e+00" inner_radius="3.00000000e+03" lunit="mm" name="GlobalSolenoid" outer_field="-1.50000000e+00" outer_radius="3.00000000e+04" zmax="2.00000000e+02" zmin="-2.00000000e+02"/> + </fields> + +</lcdd> diff --git a/examples/ClientTests/compact/SiliconBlock.xml b/examples/ClientTests/compact/SiliconBlock.xml index 994d6c05085bf1845c960ae38b3e22e9f2e823ea..d9edaaa642e71f9e6b9ee1f436870dfba39581a1 100644 --- a/examples/ClientTests/compact/SiliconBlock.xml +++ b/examples/ClientTests/compact/SiliconBlock.xml @@ -32,15 +32,28 @@ <vis name="VisibleGreen" alpha="1.0" r="0.0" g="1.0" b="0.0" drawingStyle="solid" lineStyle="solid" showDaughters="true" visible="true"/> </display> + <limits> + <limitset name="SiRegionLimitSet"> + <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="SiRegion" eunit="MeV" lunit="mm" cut="0.001" threshold="0.001"> + <limitsetref name="SiRegionLimitSet"/> + </region> + </regions> + <detectors> - <detector id="1" name="SiliconBlockUpper" type="DD4hep_BoxSegment" readout="SiliconUpperHits" vis="VisibleGreen" sensitive="true"> + <detector id="1" name="SiliconBlockUpper" type="DD4hep_BoxSegment" readout="SiliconUpperHits" vis="VisibleGreen" sensitive="true" region="SiRegion" limits="SiRegionLimitSet"> <material name="Silicon"/> <sensitive type="tracker"/> <box x="20*mm" y="20*cm" z="20*cm"/> <position x="4*cm" y="0" z="0"/> <rotation x="0" y="0" z="0"/> </detector> - <detector id="2" name="SiliconBlockDown" type="DD4hep_BoxSegment" readout="SiliconDownHits" vis="VisibleRed" sensitive="true"> + <detector id="2" name="SiliconBlockDown" type="DD4hep_BoxSegment" readout="SiliconDownHits" vis="VisibleRed" sensitive="true" region="SiRegion" limits="SiRegionLimitSet"> <material name="Silicon"/> <sensitive type="tracker"/> <box x="20*mm" y="20*cm" z="20*cm"/> diff --git a/examples/ClientTests/scripts/SiliconBlock.py b/examples/ClientTests/scripts/SiliconBlock.py index 1f5e7d8caec6f9675dc816e5b6bc6269120ffcf7..a89b937fe84dec1cca2e9d3d49a95110c531954e 100644 --- a/examples/ClientTests/scripts/SiliconBlock.py +++ b/examples/ClientTests/scripts/SiliconBlock.py @@ -1,6 +1,6 @@ # # -import os, time, DDG4 +import os, sys, time, DDG4 from DDG4 import OutputLevel as Output from SystemOfUnits import * # @@ -24,7 +24,10 @@ def run(): simple = DDG4.Simple(kernel,tracker='Geant4TrackerCombineAction') simple.printDetectors() # Configure UI - simple.setupCshUI() + if len(sys.argv)>1: + simple.setupCshUI(macro=sys.argv[1]) + else: + simple.setupCshUI() # Configure Event actions prt = DDG4.EventAction(kernel,'Geant4ParticlePrint/ParticlePrint') diff --git a/examples/ClientTests/scripts/SiliconBlock_MatScan.mac b/examples/ClientTests/scripts/SiliconBlock_MatScan.mac new file mode 100644 index 0000000000000000000000000000000000000000..d943412901385b1510c3e50bbddeea89e55d8d2f --- /dev/null +++ b/examples/ClientTests/scripts/SiliconBlock_MatScan.mac @@ -0,0 +1,5 @@ +/control/matScan/region SiRegion +/control/matScan/theta 1 0 0 +/control/matScan/phi 360 0 359 +/control/matScan/scan +exit