diff --git a/Detector/DetCRD/CMakeLists.txt b/Detector/DetCRD/CMakeLists.txt index f735b3d189c294a1307da7795f063988c104523f..e99d07895d773098002bf810c9f402f91e28561a 100644 --- a/Detector/DetCRD/CMakeLists.txt +++ b/Detector/DetCRD/CMakeLists.txt @@ -21,6 +21,8 @@ gaudi_add_module(DetCRD src/Calorimeter/RotatedPolyhedraBarrelCalorimeter_v01_geo.cpp src/Calorimeter/RotatedCrystalCalorimeter_v01_geo.cpp src/Other/CRDBeamPipe_v01_geo.cpp + src/Muon/Muon_Barrel_v01.cpp + src/Muon/Muon_Endcap_v01.cpp src/Tracker/SiTrackerSkewRing_v01_geo.cpp src/Tracker/SiTrackerStaggeredLadder_v01_geo.cpp diff --git a/Detector/DetCRD/compact/CRD_common_v01/Muon_Barrel_v01.xml b/Detector/DetCRD/compact/CRD_common_v01/Muon_Barrel_v01.xml new file mode 100644 index 0000000000000000000000000000000000000000..d392b47abecfd0df1e66f3e995a11b3cd972b2f8 --- /dev/null +++ b/Detector/DetCRD/compact/CRD_common_v01/Muon_Barrel_v01.xml @@ -0,0 +1,110 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lccdd> + + <info name="Muon_Barrel" + title="Test with A Single Muon Barrel" + author="Zibing Bai" + url="http://cepcgit.ihep.ac.cn" + status="development" + version="v01"> + <comment>Test with A Single Muon Barrel</comment> + </info> + <define> + <constant name="env_num" value="2"/> + <constant name="Fe_num" value="12"/> + <constant name="superlayer_num" value="6"/> + <constant name="strip_num_0" value="40"/> + <constant name="strip_num_1" value="48"/> + <constant name="strip_num_2" value="62"/> + <constant name="strip_num_3" value="74"/> + <constant name="strip_num_4" value="84"/> + <constant name="strip_num_5" value="96"/> + <constant name="strip_num" value="100"/> + + <constant name="Fe_y" value="strip_z+2*surf+Fe_gap"/> + <constant name="Fe_z" value="Fe_x1"/> + <constant name="Fe_posx" value="-1*Fe_x1"/> + + <constant name="env_y" value="Fe_y"/> + <constant name="env_posy" value="0.5*env_y"/> + + <constant name="layer_init" value="-21.5*cm"/> + <constant name="layer_gap" value="12.5*cm"/> + <constant name="superlayer_air" value="0.1*cm"/> + <constant name="superlayer_Al" value="0.5*superlayer_air"/> + + <constant name="superlayer_y" value="2*strip_y+2*superlayer_air"/> + <constant name="superlayer_z" value="strip_z+2*surf+2*superlayer_air"/> + + <constant name="Al_posx" value="0"/> + <constant name="Al_posy" value="0"/> + <constant name="Al_posz" value="0"/> + + </define> + + <detectors> + <detector id="0" name="Muon_Barrel_v01" type="Muon_Barrel_v01" readout="MuonBarrelCollection" vis="VisibleBlank_Muon" material="Air"> + <material name="Air"/> + <position x="0" y="0" z="0"/> + <dimensions dx="0.5*world_x" dy="0.5*world_y" dz="0.5*world_z"/> + <module id="Fe_num" name="env" type="env" vis="InvisibleWithChildren_Muon" material="Air"> + <position x="0" y="env_posy" z="0"/> + <dimensions dy="0.5*env_y"/> + <module id="0" name="Fe" type="Fe" vis="VisibleMental_Muon" material="Iron"> + <material name="Iron"/> + <position x="Fe_posx" y="0"/> + <dimensions x1="0.5*Fe_x1" y1="0.5*Fe_y" y2="0.5*Fe_y" dz="0.5*Fe_z"/> + <module id="superlayer_num" name="Superlayer" type="Superlayer" vis="VisibleBlank_Muon" material="Air"> + <module id="0" name="Layer_Al" type="Layer_Al" vis="VisibleMental_Muon" material="Aluminum"> + <material name="Aluminum"/> + <position x="0" y="0" z="0"/> + <module id="0" name="Stripe" type="Stripe" vis="VisibleBlank_Muon" material="Air"> + <material name="Air"/> + <dimensions dx="0.5*strip_x" dy="0.5*strip_y" dz="0.5*strip_z+SiPM_z"/> + <module id="0" type="surface" name="surface" vis="VisibleGreen_Muon" material="BC420"> + <position x="0" y="0" z="0"/> + <dimensions dx="0.5*surface_x" dy="0.5*surface_y" dz="0.5*surface_z"/> + <section name="cut1" vis="VisibleBlank_Muon" material="Air"> + <position x="cut1_posx" y="cut1_posy" z="cut1_posz"/> + <dimensions dx="0.5*cut1_x" dy="0.5*cut1_y" dz="0.5*cut1_z"/> + </section> + </module> + <module id="1" type="BC420" name="BC420" vis="VisibleGreen_Muon" material="BC420"> + <position x="0" y="0" z="0"/> + <dimensions dx="0.5*BC420_x" dy="0.5*BC420_y" dz="0.5*BC420_z"/> + <section name="cut3" vis="VisibleBlank_Muon" material="Air"> + <position x="cut3_posx" y="cut3_posy" z="cut3_posz"/> + <dimensions rmin="0" rmax="cut3_rmax" dz="0.5*cut3_z"/> + <section name="cut2" vis="VisibleBlank_Muon" material="Air"> + <position x="cut2_posx" y="cut2_posy" z="cut2_posz"/> + <dimensions dx="0.5*cut2_x" dy="0.5*cut2_y" dz="0.5*cut2_z"/> + </section> + </section> + </module> + <section id="0" type="cladding" name="cladding" vis="VisibleBlue_Muon" material="Pethylene1"> + <position x="0" y="0" z="0"/> + <dimensions rmin="cladding_rmin" rmax="cladding_rmax" dz="0.5*cladding_z"/> + </section> + <section id="1" type="core" name="core" vis="VisibleRed_Muon" material="Pethylene2"> + <position x="0" y="0" z="0"/> + <dimensions rmin="0" rmax="core_rmax" dz="0.5*core_z"/> + </section> + <module id="2" type="SiPM" name="SiPM" vis="VisibleBlue_Muon" material="Air"> + <position x="SiPM_posx" y="SiPM_posy" z="SiPM_posz"/> + <dimensions dx="0.5*SiPM_x" dy="0.5*SiPM_y" dz="0.5*SiPM_z"/> + </module> + </module> + </module> + </module> + </module> + </module> + </detector> + </detectors> + + <readouts> + <readout name="MuonBarrelCollection"> + <id>Env:2,Fe:2,Superlayer:2,Layer:2,Stripe:10:3,SiPM:2</id> + </readout> + </readouts> + +</lccdd> diff --git a/Detector/DetCRD/compact/CRD_common_v01/Muon_Endcap_v01.xml b/Detector/DetCRD/compact/CRD_common_v01/Muon_Endcap_v01.xml new file mode 100644 index 0000000000000000000000000000000000000000..71e396de8205b487de320e6ef80cdd9bb73a2eef --- /dev/null +++ b/Detector/DetCRD/compact/CRD_common_v01/Muon_Endcap_v01.xml @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lccdd> + + <info name="Muon_Endcap" + title="Test with Two Single Muon Endcaps" + author="Zibing Bai" + url="http://cepcgit.ihep.ac.cn" + status="development" + version="v01"> + <comment>Test with Two Single Muon Endcaps</comment> + </info> + <define> + <constant name="env_num_endcap" value="4"/> + <constant name="layer_num" value="2"/> + <constant name="strip_num_endcap" value="146"/> + <constant name="strip_num_cut" value="13"/> + <constant name="env_rmin" value="52*cm"/> + <constant name="env_z" value="3*cm"/> + <constant name="multiple" value="1.05"/> + + <constant name="envelope_halfZ" value="strip_z+2*surf+Fe_gap+env_z"/> + <constant name="env_posy_endcap" value="strip_z+2*surf+Fe_gap+0.5*env_z"/> + </define> + + <detectors> + <detector id="2" name="Muon_Endcap_v01" type="Muon_Endcap_v01" readout="MuonEndcapCollection" vis="VisibleMental_Muon" material="Iron"> + <material name="Iron"/> + <position x="0" y="env_posy_endcap" z="0"/> + <dimensions rmin="env_rmin" dz="0.5*env_z"/> + <module id="0" name="Stripe" type="Stripe" vis="VisibleBlank_Muon" material="Air"> + <material name="Air"/> + <dimensions dx="0.5*strip_x" dy="0.5*strip_y" dz="0.5*strip_z+SiPM_z"/> + <module id="0" type="surface" name="surface" vis="VisibleGreen_Muon" material="BC420"> + <position x="0" y="0" z="0"/> + <dimensions dx="0.5*surface_x" dy="0.5*surface_y" dz="0.5*surface_z"/> + <section name="cut1" vis="VisibleBlank_Muon" material="Air"> + <position x="cut1_posx" y="cut1_posy" z="cut1_posz"/> + <dimensions dx="0.5*cut1_x" dy="0.5*cut1_y" dz="0.5*cut1_z"/> + </section> + </module> + <module id="1" type="BC420" name="BC420" vis="VisibleGreen_Muon" material="BC420"> + <position x="0" y="0" z="0"/> + <dimensions dx="0.5*BC420_x" dy="0.5*BC420_y" dz="0.5*BC420_z"/> + <section name="cut3" vis="VisibleBlank_Muon" material="Air"> + <position x="cut3_posx" y="cut3_posy" z="cut3_posz"/> + <dimensions rmin="0" rmax="cut3_rmax" dz="0.5*cut3_z"/> + <section name="cut2" vis="VisibleBlank_Muon" material="Air"> + <position x="cut2_posx" y="cut2_posy" z="cut2_posz"/> + <dimensions dx="0.5*cut2_x" dy="0.5*cut2_y" dz="0.5*cut2_z"/> + </section> + </section> + </module> + <section id="0" type="cladding" name="cladding" vis="VisibleBlue_Muon" material="Pethylene1"> + <position x="0" y="0" z="0"/> + <dimensions rmin="cladding_rmin" rmax="cladding_rmax" dz="0.5*cladding_z"/> + </section> + <section id="1" type="core" name="core" vis="VisibleRed_Muon" material="Pethylene2"> + <position x="0" y="0" z="0"/> + <dimensions rmin="0" rmax="core_rmax" dz="0.5*core_z"/> + </section> + <module id="2" type="SiPM" name="SiPM" vis="VisibleBlue_Muon" material="Air"> + <position x="SiPM_posx" y="SiPM_posy" z="SiPM_posz"/> + <dimensions dx="0.5*SiPM_x" dy="0.5*SiPM_y" dz="0.5*SiPM_z"/> + </module> + </module> + </detector> + </detectors> + + <readouts> + <readout name="MuonEndcapCollection"> + <id>Endcap:2,Env:2,Layer:2,Stripe:8:3,SiPM:2</id> + </readout> + </readouts> + +</lccdd> diff --git a/Detector/DetCRD/compact/CRD_o1_v01/CRD_o1_v01.xml b/Detector/DetCRD/compact/CRD_o1_v01/CRD_o1_v01.xml index cf923ffbc67b73ed8fcbf3df7a222df598890dda..16ca01fb7e18f3be951a66c1452e784e39052c89 100644 --- a/Detector/DetCRD/compact/CRD_o1_v01/CRD_o1_v01.xml +++ b/Detector/DetCRD/compact/CRD_o1_v01/CRD_o1_v01.xml @@ -38,7 +38,9 @@ <include ref="../CRD_common_v01/Coil_Simple_v01_01.xml"/> <include ref="../CRD_common_v01/Hcal_Rpc_Barrel_v01_01.xml"/> <include ref="../CRD_common_v01/Hcal_Rpc_Endcaps_v01_01.xml"/> - <include ref="../CRD_common_v01/Yoke_Barrel_v01_01.xml"/> + <!--include ref="../CRD_common_v01/Muon_Barrel_v01.xml"/--> + <!--include ref="../CRD_common_v01/Muon_Endcap_v01.xml"/--> + <include ref="../CRD_common_v01/Yoke_Barrel_v01_01.xml"/--> <include ref="../CRD_common_v01/Yoke_Endcaps_v01_01.xml"/> <!--include ref="../CRD_common_v01/Lcal_v01_01.xml"/--> diff --git a/Detector/DetCRD/compact/README.md b/Detector/DetCRD/compact/README.md index 8cd6fd645daccb41d79c43b376aa8905e0b6c08b..7d876e625a911aec8dc769bbdb66ad77c6c3cc35 100644 --- a/Detector/DetCRD/compact/README.md +++ b/Detector/DetCRD/compact/README.md @@ -1,3 +1,17 @@ + +# CRD detector models - Overview + +The following CRD detector models are available in CEPCSW + +| Model | Description | MainTracker | Ecal | Hcal | Muon | Status | +| ------------- | -----------------------------|------------ |---------|------|-------|----------------| +| CRD_o1_v01 | coil inside simulation model | SIT+DC+SET | crystal | RPC | Scint | developing | +| CRD_o1_v02 | strip SET | SIT+DC+SET | crystal | RPC | Scint | developing | +| CRD_o1_v03 | MOST2 vertex | SIT+DC+SET | crystal | RPC | Scint | developing | +| CRD_o1_v04 | smaller center beam pipe | SIT+DC+SET | crystal | RPC | Scint | developing | +| CRD_o1_v05 | Use Ref-Det ECAL and HCAL | SIT+TPC+SET | crystal | Glass| Scint | developing | +| ------------- | -----------------------------|-------------|---------|------|-------|----------------| + # CRD detector models - Overview The following CRD detector models are available in CEPCSW diff --git a/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01-onlyMuon.xml b/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01-onlyMuon.xml new file mode 100644 index 0000000000000000000000000000000000000000..45f6c350052ffd0a19e9d784563701ba0a6cdead --- /dev/null +++ b/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01-onlyMuon.xml @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd"> + <info name="TDR_o1_v01" + title="CepC reference detctor with coil inside Hcal, pixel SIT/SET" + author="C.D.Fu, " + url="http://cepc.ihep.ac.cn" + status="developing" + version="v01"> + <comment>CepC reference detector simulation models used for detector study </comment> + </info> + + <includes> + <gdmlFile ref="${DD4hepINSTALL}/DDDetectors/compact/elements.xml"/> + <gdmlFile ref="../materials_muon.xml"/> + </includes> + + + <define> + <constant name="world_size" value="25*m"/> + <constant name="world_x" value="world_size"/> + <constant name="world_y" value="world_size"/> + <constant name="world_z" value="world_size"/> + + <constant name="strip_x" value="4*cm"/> + <constant name="strip_y" value="1*cm"/> + <constant name="strip_z" value="4*m"/> + <constant name="surf" value="1*mm"/> + + <constant name="Fe_gap" value="2.5*cm"/> + <constant name="Fe_x1" value="105*cm"/> + + <constant name="surface_x" value="strip_x"/> + <constant name="surface_y" value="strip_y"/> + <constant name="surface_z" value="strip_z"/> + + <constant name="BC420_x" value="strip_x-2*surf"/> + <constant name="BC420_y" value="strip_y-2*surf"/> + <constant name="BC420_z" value="strip_z"/> + + <constant name="SiPM_x" value="6*mm"/> + <constant name="SiPM_y" value="6*mm"/> + <constant name="SiPM_z" value="surf"/> + <constant name="SiPM_posx" value="0"/> + <constant name="SiPM_posy" value="0"/> + <constant name="SiPM_posz" value="0.5*strip_z+0.5*SiPM_z"/> + + <constant name="core_rmax" value="0.95*mm"/> + <constant name="core_z" value="strip_z"/> + + <constant name="cladding_rmin" value="core_rmax"/> + <constant name="cladding_rmax" value="1*mm"/> + <constant name="cladding_z" value="strip_z"/> + + <constant name="deviation" value="0.1*mm"/> + <constant name="cut3_rmax" value="cladding_rmax+deviation"/> + <constant name="cut3_z" value="strip_z"/> + <constant name="cut3_posx" value="0"/> + <constant name="cut3_posy" value="cut3_rmax-cladding_rmax"/> + <constant name="cut3_posz" value="0"/> + + <constant name="cut1_x" value="2*cut3_rmax"/> + <constant name="cut1_y" value="surf"/> + <constant name="cut1_z" value="strip_z"/> + <constant name="cut1_posx" value="0"/> + <constant name="cut1_posy" value="0.5*strip_y-0.5*cut1_y"/> + <constant name="cut1_posz" value="0"/> + + <constant name="cut2_x" value="cut1_x"/> + <constant name="cut2_y" value="0.5*BC420_y-cut3_rmax+cladding_rmax"/> + <constant name="cut2_z" value="strip_z"/> + <constant name="cut2_posx" value="0"/> + <constant name="cut2_posy" value="0.5*BC420_y-0.5*cut2_y"/> + <constant name="cut2_posz" value="0"/> + + <include ref="${DD4hepINSTALL}/DDDetectors/compact/detector_types.xml"/> + </define> + + <display> + <vis name="Invisible_Muon" showDaughters="false" visible="false"/> + <vis name="InvisibleWithChildren_Muon" showDaughters="true" visible="false"/> + <vis name="VisibleRed_Muon" r="1.0" g="0.0" b="0.0" showDaughters="true" visible="true"/> + <vis name="VisibleBlue_Muon" alpha="0.5" r="0.0" g="0.0" b="1.0" showDaughters="false" visible="true"/> + <vis name="VisibleGreen_Muon" alpha="0.3" r="0.0" g="1.0" b="0.0" drawingStyle="solid" lineStyle="solid" showDaughters="true" visible="true"/> + <vis name="VisibleMental_Muon" alpha="0.1" r="0.5" g="0.5" b="0.5" showDaughters="true" visible="true"/> + <vis name="VisibleBlank_Muon" alpha="0.0" r="0.0" g="0.0" b="0.0" showDaughters="true" visible="true"/> + </display> + + <include ref="./TDR_Dimensions_v01_01.xml"/> + + <!--include ref="../CRD_common_v01/Beampipe_v01_01.xml"/--> + <!--include ref="../CRD_common_v01/VXD_v01_01.xml"/--> + <!--include ref="../CRD_common_v01/FTD_SkewRing_v01_01.xml"/--> + <!--include ref="../CRD_common_v01/SIT_SimplePixel_v01_01.xml"/--> + <!--include ref="../CRD_common_v01/DC_Simple_v01_05.xml"/--> + <!--include ref="../CRD_common_v01/SET_SimplePixel_v01_01.xml"/--> + <!--include ref="../CRD_common_v01/Ecal_Crystal_Barrel_v01_01.xml"/--> + <!--include ref="../CRD_common_v01/Ecal_Crystal_Endcap_v01_01.xml"/--> + <include ref="../CRD_common_v01/Muon_Endcap_v01.xml"/> + <include ref="../CRD_common_v01/Muon_Barrel_v01.xml"/> + + <fields> + <field name="InnerSolenoid" type="solenoid" + inner_field="Field_nominal_value" + outer_field="0" + zmax="SolenoidCoil_half_length" + inner_radius="SolenoidCoil_center_radius" + outer_radius="Solenoid_outer_radius"> + </field> + <field name="OuterSolenoid" type="solenoid" + inner_field="0" + outer_field="Field_outer_nominal_value" + zmax="SolenoidCoil_half_length" + inner_radius="Solenoid_outer_radius" + outer_radius="Yoke_barrel_inner_radius"> + </field> + </fields> + +</lccdd> diff --git a/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01.xml b/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01.xml index b78b74341aee898779fd8ff66f462cc854976486..71f251c685105bd29f7cc5f21ba20132427a4396 100644 --- a/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01.xml +++ b/Detector/DetCRD/compact/TDR_o1_v01/TDR_o1_v01.xml @@ -46,7 +46,11 @@ <!--preliminary Muon, to update/--> <include ref="../CRD_common_v02/Yoke_Polyhedra_Barrel_v01_01.xml"/> <include ref="../CRD_common_v02/Yoke_Polyhedra_Endcaps_v01_01.xml"/> - + + <!--muon detector/--> + <!--include ref="../CRD_common_v01/Muon_Barrel_v01.xml"/--> + <!--include ref="../CRD_common_v01/Muon_Endcap_v01.xml"/--> + <fields> <field name="InnerSolenoid" type="solenoid" inner_field="Field_nominal_value" diff --git a/Detector/DetCRD/compact/materials_muon.xml b/Detector/DetCRD/compact/materials_muon.xml new file mode 100644 index 0000000000000000000000000000000000000000..34c657294e08b9b3328a58eafdbc3819c7b948a2 --- /dev/null +++ b/Detector/DetCRD/compact/materials_muon.xml @@ -0,0 +1,127 @@ +<?xml version="1.0" encoding="UTF-8"?> +<lccdd> + <properties> + + <matrix name="RINDEX__Air" coldim="2" values=" + 1.0*eV 1.00029 + 5.1*eV 1.00029 + "/> + <matrix name="RINDEX__BC420" coldim="2" values=" + 2.38*eV 1.58 + 2.88*eV 1.58 + 3.45*eV 1.58 + "/> + <matrix name="ABSLENGTH__BC420" coldim="2" values=" + 2.38*eV 10*cm + 2.88*eV 10*cm + 3.45*eV 10*cm + "/> + <matrix name="WLSCOMPONENT__BC420" coldim="2" values=" + 2.38*eV 0. + 2.88*eV 1. + 3.45*eV 0. + "/> + <matrix name="SCINTILLATIONCOMPONENT__BC420" coldim="2" values=" + 2.38*eV 1.0 + 2.88*eV 1.0 + 3.45*eV 1.0 + "/> + <matrix name="RINDEX__Pethylene1" coldim="2" values=" + 2.0*eV 1.49 + 2.87*eV 1.49 + 2.90*eV 1.49 + 3.47*eV 1.49 + "/> + <matrix name="ABSLENGTH__Pethylene1" coldim="2" values=" + 2.0*eV 3.0*m + 2.87*eV 3.0*m + 2.90*eV 3.0*m + 3.47*eV 3.0*m + "/> + <matrix name="RINDEX__Pethylene2" coldim="2" values=" + 2.0*eV 1.60 + 2.87*eV 1.60 + 2.90*eV 1.60 + 3.47*eV 1.60 + "/> + <matrix name="WLSABSLENGTH__Pethylene2" coldim="2" values=" + 2.0*eV 3.0*m + 2.87*eV 3.0*m + 2.90*eV 0.1*mm + 3.47*eV 0.1*mm + "/> + <matrix name="WLSCOMPONENT__Pethylene2" coldim="2" values=" + 2.0*eV 1.0 + 2.87*eV 1.0 + 2.90*eV 0. + 3.47*eV 0. + "/> + </properties> + + <materials> + + <material name="Air"> + <D type="density" unit="g/cm3" value="0.0012"/> + <fraction n="0.754" ref="N"/> + <fraction n="0.234" ref="O"/> + <fraction n="0.012" ref="Ar"/> + <property name="RINDEX" ref="RINDEX__Air"/> + </material> + + <material name="Vacuum"> + <D type="density" unit="g/cm3" value="0.0000000001" /> + <fraction n="0.754" ref="N"/> + <fraction n="0.234" ref="O"/> + <fraction n="0.012" ref="Ar"/> + </material> + + <material name="Steel235"> + <D value="7.85" unit="g/cm3"/> + <fraction n="0.998" ref="Fe"/> + <fraction n=".002" ref="C"/> + </material> + + <material name="BC420"> + <D type="density" value="1.032" unit="g/cm3"/> + <composite n="10" ref="C"/> + <composite n="11" ref="H"/> + <property name="RINDEX" ref="RINDEX__BC420"/> + <property name="ABSLENGTH" ref="ABSLENGTH__BC420"/> + <property name="WLSCOMPONENT" ref="WLSCOMPONENT__BC420"/> + <property name="SCINTILLATIONCOMPONENT1" ref="SCINTILLATIONCOMPONENT__BC420"/> + <property name="SCINTILLATIONCOMPONENT2" ref="SCINTILLATIONCOMPONENT__BC420"/> + <constant name="SCINTILLATIONYIELD" value="10240./MeV"/> + <constant name="RESOLUTIONSCALE" value="2.5"/> + <constant name="SCINTILLATIONTIMECONSTANT1" value="0.9*ns"/> + <constant name="SCINTILLATIONTIMECONSTANT2" value="2.1*ns"/> + <constant name="SCINTILLATIONYIELD1" value="1.0"/> + <constant name="SCINTILLATIONYIELD2" value="0."/> + <constant name="BirksConstant" value="0.126*mm/MeV"/> + </material> + + <material name="Pethylene1"> + <D type="density" value="1200" unit="kg/m3"/> + <composite n="2" ref="C"/> + <composite n="4" ref="H"/> + <property name="RINDEX" ref="RINDEX__Pethylene1"/> + <property name="ABSLENGTH" ref="ABSLENGTH__Pethylene1"/> + </material> + + <material name="Pethylene2"> + <D type="density" value="1190" unit="kg/m3"/> + <composite n="5" ref="C"/> + <composite n="8" ref="H"/> + <composite n="2" ref="O"/> + <property name="RINDEX" ref="RINDEX__Pethylene2"/> + <property name="WLSABSLENGTH" ref="WLSABSLENGTH__Pethylene2"/> + <property name="WLSCOMPONENT" ref="WLSCOMPONENT__Pethylene2"/> + <constant name="WLSTIMECONSTANT" value="0.5*ns"/> + </material> + + </materials> + + <surfaces> + <opticalsurface name="Surf__stripe" model="glisur" finish="polished" type="dielectric_metal"/> + <opticalsurface name="Surf__fiber" model="glisur" finish="polished" type="dielectric_metal"/> + </surfaces> +</lccdd> diff --git a/Detector/DetCRD/src/Muon/Muon_Barrel_v01.cpp b/Detector/DetCRD/src/Muon/Muon_Barrel_v01.cpp new file mode 100644 index 0000000000000000000000000000000000000000..69f985ab340cb6a0f0fa034bfdd09d23e78a1d08 --- /dev/null +++ b/Detector/DetCRD/src/Muon/Muon_Barrel_v01.cpp @@ -0,0 +1,332 @@ +//==================================================================== +// Detector description implementation for Chunxiu Liu's EcalMatrix +//-------------------------------------------------------------------- +// +// Author : Tao Lin +// Examples from lcgeo +// lcgeo/detector/calorimeter/ +// +//==================================================================== +#include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/OpticalSurfaces.h" +#include "XML/Utilities.h" +#include "DDRec/DetectorData.h" +#include "DDSegmentation/Segmentation.h" +#include <cmath> + +#define MYDEBUG(x) std::cout << __FILE__ << ":" << __LINE__ << ": " << x << std::endl; +#define MYDEBUGVAL(x) std::cout << __FILE__ << ":" << __LINE__ << ": " << #x << ": " << x << std::endl; + +using dd4hep::rec::LayeredCalorimeterData; +static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector, + xml_h e, + dd4hep::SensitiveDetector sens) { + + xml_det_t x_det = e; + + std::string det_name = x_det.nameStr(); + std::string det_type = x_det.typeStr(); + MYDEBUGVAL(det_name); + MYDEBUGVAL(det_type); + xml_dim_t pos (x_det.child(_U(position))); + xml_dim_t dim (x_det.child(_U(dimensions))); + + dd4hep::Material det_mat(theDetector.material(x_det.materialStr())); + + dd4hep::DetElement sdet(det_name, x_det.id()); + + dd4hep::Volume envelope(det_name,dd4hep::Box(dim.dx(),dim.dy(),dim.dz()),det_mat); + + dd4hep::xml::setDetectorTypeFlag( e, sdet ) ; + + dd4hep::Volume motherVol = theDetector.pickMotherVolume(sdet); + + sens.setType("muonbarrel"); + +// dd4hep::Readout readout = sens.readout(); +// dd4hep::Segmentation seg = readout.segmentation(); + xml_coll_t dcEnv(x_det,_U(module)); + xml_comp_t x_env = dcEnv; + for(int i0 = 0; i0 < theDetector.constant<int>("env_num"); i0++) + { + for(int i1 = 0; i1 < x_env.id(); i1++ ) + { + std::string env_name = x_env.nameStr() + dd4hep::_toString(i1,"_%d"); + dd4hep::Material env_mat(theDetector.material(x_env.materialStr())); + xml_dim_t env_pos(x_env.child(_U(position))); + xml_dim_t env_dim(x_env.child(_U(dimensions))); + + xml_coll_t dcFe(x_env,_U(module)); + xml_comp_t x_Fe = dcFe; + std::string Fe_name = x_Fe.nameStr() + dd4hep::_toString(i1,"_%d"); + dd4hep::Material Fe_mat(theDetector.material(x_Fe.materialStr())); + xml_dim_t Fe_pos(x_Fe.child(_U(position))); + xml_dim_t Fe_dim(x_Fe.child(_U(dimensions))); + + double Fe_halfX2 = theDetector.constant<double>("Fe_x1") * ( 0.5 + std::sqrt(3)); + double Fe_posZ = -1 * theDetector.constant<double>("Fe_x1") * ( 2.5 + 1.5 * std::sqrt(3) ); + double env_halfX = 2 * theDetector.constant<double>("Fe_x1") * ( 1 + std::sqrt(3) ); + double env_halfZ = 2 * theDetector.constant<double>("Fe_x1") * ( 3 + 1.5 * std::sqrt(3) ); + dd4hep::Box env_solid(env_halfX,env_dim.dy(),env_halfZ); + dd4hep::Volume env_vol(env_name, env_solid, env_mat); + env_vol.setVisAttributes(theDetector.visAttributes(x_env.visStr())); + double env_rot = i1 * 360 * dd4hep::degree / x_env.id(); + dd4hep::Transform3D env_transform(dd4hep::Rotation3D(dd4hep::RotationY(env_rot)),dd4hep::Position(env_pos.x(), ( 2 * i0 - 1 ) * env_pos.y(),env_pos.z())); + + dd4hep::Trd2 Fe_solid(Fe_dim.x1(),Fe_halfX2,Fe_dim.y1(),Fe_dim.y2(),Fe_dim.dz()); + dd4hep::Volume Fe_vol(Fe_name, Fe_solid, Fe_mat); + Fe_vol.setVisAttributes(theDetector.visAttributes(x_Fe.visStr())); + dd4hep::Transform3D Fe_transform(dd4hep::Rotation3D(),dd4hep::Position(Fe_pos.x(),Fe_pos.y(),Fe_posZ)); + + xml_coll_t dcSuperlayer(x_Fe,_U(module)); + xml_comp_t x_superlayer = dcSuperlayer; + for(int i2 = 0; i2 < x_superlayer.id(); i2++) + { + std::string superlayer_name = x_superlayer.nameStr() + dd4hep::_toString(i2,"_%d"); + std::string num_name = "strip_num" + dd4hep::_toString(i2,"_%d"); + + int strip_num = theDetector.constant<int>(num_name); + double superlayer_halfX = 0.5 * strip_num * theDetector.constant<double>("strip_x") + theDetector.constant<double>("superlayer_air"); + double superlayer_halfY = 0.5 * theDetector.constant<double>("superlayer_y"); + double superlayer_halfZ = 0.5 * theDetector.constant<double>("superlayer_z"); + + double superlayer_posZ = i2 * theDetector.constant<double>("layer_gap") + theDetector.constant<double>("layer_init"); + + dd4hep::Material superlayer_mat(theDetector.material(x_superlayer.materialStr())); + dd4hep::Box superlayer_solid(superlayer_halfX, superlayer_halfY, superlayer_halfZ); + dd4hep::Volume superlayer_vol(superlayer_name, superlayer_solid, superlayer_mat); + superlayer_vol.setVisAttributes(theDetector.visAttributes(x_superlayer.visStr())); + dd4hep::Transform3D superlayer_transform(dd4hep::Rotation3D(dd4hep::RotationX(90*dd4hep::degree)),dd4hep::Position(0, 0, superlayer_posZ)); + + xml_coll_t dcAl(x_superlayer,_U(module)); + xml_comp_t x_Al = dcAl; + std::string Al_name = x_Al.nameStr(); + dd4hep::Material Al_mat(theDetector.material(x_Al.materialStr())); + xml_dim_t Al_pos(x_Al.child(_U(position))); + + double Al_halfX = superlayer_halfX - theDetector.constant<double>("superlayer_Al"); + double Al_halfY = superlayer_halfY - theDetector.constant<double>("superlayer_Al"); + double Al_halfZ = superlayer_halfZ - theDetector.constant<double>("superlayer_Al"); + dd4hep::Box Al_solid(Al_halfX, Al_halfY, Al_halfZ); + dd4hep::Volume Al_vol(Al_name, Al_solid, Al_mat); + Al_vol.setVisAttributes(theDetector.visAttributes(x_Al.visStr())); + dd4hep::Transform3D Al_transform(dd4hep::Rotation3D(),dd4hep::Position(Al_pos.x(),Al_pos.y(),Al_pos.z())); + for (int i3 = 0; i3 < 2; i3++ ) + { + int num; + if ( i3 == 0 ) + { + num = strip_num; + } + if ( i3 == 1 ) + { + num = theDetector.constant<int>("strip_num"); + } + for ( int i4 = 0; i4 < num; i4++ ) + { + double strip_halfZ, strip_posX, strip_posY, strip_posZ; + dd4hep::Rotation3D strip_rot; + if ( i3 == 0 ) + { + strip_halfZ = 0.5 * theDetector.constant<double>("strip_z") + theDetector.constant<double>("surf"); + strip_posX = theDetector.constant<double>("strip_x") * ( i4 + 0.5 * (1 - strip_num)); + strip_posY = 0.5 * theDetector.constant<double>("strip_y"); + strip_posZ = 0; + } + if ( i3 == 1 ) + { + strip_rot = dd4hep::Rotation3D(dd4hep::RotationY( 90 * dd4hep::degree )); + strip_halfZ = 0.5 * strip_num * theDetector.constant<double>("strip_x") + theDetector.constant<double>("surf"); + strip_posX = 0; + strip_posY = -0.5 * theDetector.constant<double>("strip_y"); + strip_posZ = theDetector.constant<double>("strip_x") * ( i4 + 0.5 ) - 0.5 * theDetector.constant<double>("strip_z"); + } + double surface_halfZ, BC420_halfZ, fiber_halfZ, cut_halfZ; + double SiPM_posZ = strip_halfZ + theDetector.constant<double>("surf"); + surface_halfZ = BC420_halfZ = fiber_halfZ = cut_halfZ = strip_halfZ - theDetector.constant<double>("surf"); + xml_coll_t dcStrip(x_Al,_U(module)); + xml_comp_t x_strip = dcStrip; + std::string strip_name = x_strip.nameStr() + dd4hep::_toString(i0,"_%d") + dd4hep::_toString(i1,"_%d") + dd4hep::_toString(i2,"_%d") + dd4hep::_toString(i3,"_%d") + dd4hep::_toString(i4,"_%d"); + dd4hep::Material strip_mat(theDetector.material(x_strip.materialStr())); + xml_dim_t strip_dim(x_strip.child(_U(dimensions))); + + dd4hep::Box strip_solid(strip_dim.dx(),strip_dim.dy(),strip_halfZ); + dd4hep::Volume strip_vol(strip_name,strip_solid,strip_mat); + strip_vol.setVisAttributes(theDetector.visAttributes(x_strip.visStr())); + dd4hep::Transform3D strip_transform(strip_rot,dd4hep::Position(strip_posX,strip_posY,strip_posZ)); + + std::string surface_name, BC420_name, cut1_name, cut2_name, cut3_name, SiPM_name; + std::string surface_vis, BC420_vis, cut1_vis, cut2_vis, cut3_vis, SiPM_vis; + dd4hep::Material surface_mat, BC420_mat, cut1_mat, cut2_mat, cut3_mat, SiPM_mat; + xml_dim_t surface_pos, cut1_pos, BC420_pos, cut3_pos, cut2_pos, SiPM_pos; + xml_dim_t surface_dim, cut1_dim, BC420_dim, cut3_dim, cut2_dim, SiPM_dim; + for(xml_coll_t dcModule(x_strip,_U(module)); dcModule; dcModule++) + { + xml_comp_t x_module = dcModule; + + xml_dim_t module_pos(x_module.child(_U(position))); + xml_dim_t module_dim(x_module.child(_U(dimensions))); + + dd4hep::Box module_solid(module_dim.dx(),module_dim.dy(),module_dim.dz()); + if(x_module.id()==0) + { + surface_name = x_module.nameStr(); + surface_vis = x_module.visStr(); + surface_mat = theDetector.material(x_module.materialStr()); + xml_dim_t s_pos(x_module.child(_U(position))); + xml_dim_t s_dim(x_module.child(_U(dimensions))); + surface_pos = s_pos; + surface_dim = s_dim; + + xml_coll_t dcCut1(x_module,_U(section)); + xml_comp_t x_cut1 = dcCut1; + cut1_name = x_cut1.nameStr(); + cut1_vis = x_cut1.visStr(); + cut1_mat = theDetector.material(x_cut1.materialStr()); + xml_dim_t c1_pos(x_cut1.child(_U(position))); + xml_dim_t c1_dim(x_cut1.child(_U(dimensions))); + cut1_pos = c1_pos; + cut1_dim = c1_dim; + } + if(x_module.id()==1) + { + BC420_name = x_module.nameStr(); + BC420_vis = x_module.visStr(); + BC420_mat = theDetector.material(x_module.materialStr()); + xml_dim_t b_pos(x_module.child(_U(position))); + xml_dim_t b_dim(x_module.child(_U(dimensions))); + BC420_pos = b_pos; + BC420_dim = b_dim; + + xml_coll_t dcCut3(x_module,_U(section)); + xml_comp_t x_cut3 = dcCut3; + cut3_name = x_cut3.nameStr(); + cut3_vis = x_cut3.visStr(); + cut3_mat = theDetector.material(x_cut3.materialStr()); + xml_dim_t c3_pos(x_cut3.child(_U(position))); + xml_dim_t c3_dim(x_cut3.child(_U(dimensions))); + cut3_pos = c3_pos; + cut3_dim = c3_dim; + + xml_coll_t dcCut2(x_cut3,_U(section)); + xml_comp_t x_cut2 = dcCut2; + cut2_name = x_cut2.nameStr(); + cut2_vis = x_cut2.visStr(); + cut2_mat = theDetector.material(x_cut2.materialStr()); + xml_dim_t c2_pos(x_cut2.child(_U(position))); + xml_dim_t c2_dim(x_cut2.child(_U(dimensions))); + cut2_pos = c2_pos; + cut2_dim = c2_dim; + } + if(x_module.id()==2) + { + SiPM_name = x_module.nameStr(); + SiPM_vis = x_module.visStr(); + SiPM_mat = theDetector.material(x_module.materialStr()); + xml_dim_t S_pos(x_module.child(_U(position))); + xml_dim_t S_dim(x_module.child(_U(dimensions))); + SiPM_pos = S_pos; + SiPM_dim = S_dim; + } + } + dd4hep::Box surface_solid(surface_dim.dx(),surface_dim.dy(),surface_halfZ); + dd4hep::Box cut1_solid(cut1_dim.dx(),cut1_dim.dy(),cut_halfZ); + dd4hep::Box BC420_solid(BC420_dim.dx(),BC420_dim.dy(),BC420_halfZ); + dd4hep::Tube cut3_solid(cut3_dim.rmin(),cut3_dim.rmax(),cut_halfZ); + dd4hep::Box cut2_solid(cut2_dim.dx(),cut2_dim.dy(),cut_halfZ); + dd4hep::Box SiPM_solid(SiPM_dim.dx(),SiPM_dim.dy(),SiPM_dim.dz()); + + dd4hep::Transform3D surface_transform(dd4hep::Rotation3D(),dd4hep::Position(surface_pos.x(),surface_pos.y(),surface_pos.z())); + dd4hep::Transform3D cut1_transform(dd4hep::Rotation3D(),dd4hep::Position(cut1_pos.x(),cut1_pos.y(),cut1_pos.z())); + dd4hep::Transform3D BC420_transform(dd4hep::Rotation3D(),dd4hep::Position(BC420_pos.x(),BC420_pos.y(),BC420_pos.z())); + dd4hep::Transform3D cut2_transform(dd4hep::Rotation3D(),dd4hep::Position(cut2_pos.x(),cut2_pos.y(),cut2_pos.z())); + dd4hep::Transform3D cut3_transform(dd4hep::Rotation3D(),dd4hep::Position(cut3_pos.x(),cut3_pos.y(),cut3_pos.z())); + dd4hep::Transform3D SiPM_transform0(dd4hep::Rotation3D(),dd4hep::Position(SiPM_pos.x(),SiPM_pos.y(),SiPM_posZ)); + dd4hep::Transform3D SiPM_transform1(dd4hep::Rotation3D(),dd4hep::Position(SiPM_pos.x(),SiPM_pos.y(), -1 * SiPM_posZ)); + + dd4hep::Volume surface_vol(surface_name, surface_solid, surface_mat); + surface_vol.setVisAttributes(theDetector.visAttributes(surface_vis)); + surface_vol.setSensitiveDetector(sens); + + dd4hep::Volume cut1_vol(cut1_name, cut1_solid, cut1_mat); + cut1_vol.setVisAttributes(theDetector.visAttributes(cut1_vis)); + + dd4hep::Volume cut2_vol(cut2_name, cut2_solid, cut2_mat); + cut2_vol.setVisAttributes(theDetector.visAttributes(cut2_vis)); + + dd4hep::Volume cut3_vol(cut3_name, cut3_solid, cut3_mat); + cut3_vol.setVisAttributes(theDetector.visAttributes(cut3_vis)); + + dd4hep::Volume BC420_vol(BC420_name,BC420_solid,BC420_mat); + BC420_vol.setVisAttributes(theDetector.visAttributes(BC420_vis)); + + dd4hep::Volume SiPM_vol(SiPM_name, SiPM_solid, SiPM_mat); + SiPM_vol.setVisAttributes(theDetector.visAttributes(SiPM_vis)); + SiPM_vol.setSensitiveDetector(sens); + + BC420_vol.placeVolume(cut2_vol,cut2_transform); + BC420_vol.placeVolume(cut3_vol,cut3_transform); + dd4hep::PlacedVolume cladding_place, core_place; + for(xml_coll_t dcSection(x_strip,_U(section)); dcSection; dcSection++) + { + xml_comp_t x_section = dcSection; + std::string section_name = x_section.nameStr(); + dd4hep::Material section_mat = theDetector.material(x_section.materialStr()); + + xml_dim_t section_pos(x_section.child(_U(position))); + xml_dim_t section_dim(x_section.child(_U(dimensions))); + + dd4hep::Tube section_solid(section_dim.rmin(),section_dim.rmax(),fiber_halfZ); + dd4hep::Volume section_vol(section_name,section_solid,section_mat); + section_vol.setVisAttributes(theDetector.visAttributes(x_section.visStr())); + + dd4hep::Transform3D section_transform(dd4hep::Rotation3D(),dd4hep::Position(section_pos.x(),section_pos.y(),section_pos.z())); + if (x_section.id() == 0) + { + cladding_place = BC420_vol.placeVolume(section_vol,section_transform); + } + if (x_section.id() == 1) + { + core_place = BC420_vol.placeVolume(section_vol,section_transform); + } + } + surface_vol.placeVolume(cut1_vol,cut1_transform); + dd4hep::PlacedVolume BC420_place = surface_vol.placeVolume(BC420_vol,BC420_transform); + BC420_place.addPhysVolID("Stripe",i4+1); + dd4hep::PlacedVolume surf_place = strip_vol.placeVolume(surface_vol,surface_transform); + surf_place.addPhysVolID("Layer",i3+1); + surf_place.addPhysVolID("SiPM",0); + dd4hep::PlacedVolume SiPM_place0 = strip_vol.placeVolume(SiPM_vol,SiPM_transform0); + SiPM_place0.addPhysVolID("SiPM",1); + + dd4hep::PlacedVolume SiPM_place1 = strip_vol.placeVolume(SiPM_vol,SiPM_transform1); + SiPM_place1.addPhysVolID("SiPM",2); + Al_vol.placeVolume(strip_vol,strip_transform); + dd4hep::OpticalSurfaceManager surfMgr = theDetector.surfaceManager(); + std::string optical_surf = strip_name + "_surf"; + std::string optical_fiber = strip_name + "_fiber"; + dd4hep::OpticalSurface Surf_stripe = surfMgr.opticalSurface("Surf__stripe"); + dd4hep::OpticalSurface Surf_fiber = surfMgr.opticalSurface("Surf__fiber"); + dd4hep::BorderSurface surface_stripe( theDetector, sdet, optical_surf, Surf_stripe, BC420_place, surf_place); + dd4hep::BorderSurface surface_fiber( theDetector, sdet, optical_fiber, Surf_fiber, core_place, cladding_place); + } + } + dd4hep::PlacedVolume Al_place = superlayer_vol.placeVolume(Al_vol,Al_transform); + Al_place.addPhysVolID("Superlayer",i2+1); + Fe_vol.placeVolume(superlayer_vol,superlayer_transform); + } + dd4hep::PlacedVolume Fe_place = env_vol.placeVolume(Fe_vol,Fe_transform); + Fe_place.addPhysVolID("Fe",i1+1); + dd4hep::PlacedVolume env_place = envelope.placeVolume(env_vol,env_transform); + env_place.addPhysVolID("Env",i0+1); + } + } + dd4hep::Transform3D pv(dd4hep::Rotation3D(),dd4hep::Position(0,0,0)); + dd4hep::PlacedVolume phv = motherVol.placeVolume(envelope,pv); + sdet.setPlacement(phv); + + MYDEBUG("create_detector DONE. "); + return sdet; +} + +DECLARE_DETELEMENT(Muon_Barrel_v01, create_detector) diff --git a/Detector/DetCRD/src/Muon/Muon_Endcap_v01.cpp b/Detector/DetCRD/src/Muon/Muon_Endcap_v01.cpp new file mode 100644 index 0000000000000000000000000000000000000000..797dca0b5b93c8301068419ecec33486ff4ad898 --- /dev/null +++ b/Detector/DetCRD/src/Muon/Muon_Endcap_v01.cpp @@ -0,0 +1,294 @@ +//==================================================================== +// Detector description implementation for Chunxiu Liu's EcalMatrix +//-------------------------------------------------------------------- +// +// Author : Tao Lin +// Examples from lcgeo +// lcgeo/detector/calorimeter/ +// +//==================================================================== +#include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/OpticalSurfaces.h" +#include "XML/Utilities.h" +#include "DDRec/DetectorData.h" +#include "DDSegmentation/Segmentation.h" +#include <cmath> + +#define MYDEBUG(x) std::cout << __FILE__ << ":" << __LINE__ << ": " << x << std::endl; +#define MYDEBUGVAL(x) std::cout << __FILE__ << ":" << __LINE__ << ": " << #x << ": " << x << std::endl; + +using dd4hep::rec::LayeredCalorimeterData; +static dd4hep::Ref_t create_detector(dd4hep::Detector& theDetector, + xml_h e, + dd4hep::SensitiveDetector sens) { + + xml_det_t x_det = e; + + std::string det_name = x_det.nameStr(); + std::string det_type = x_det.typeStr(); + MYDEBUGVAL(det_name); + MYDEBUGVAL(det_type); + xml_dim_t pos (x_det.child(_U(position))); + xml_dim_t dim (x_det.child(_U(dimensions))); + + double env_rmax = theDetector.constant<double>("Fe_x1") * std::sqrt( ( 1.5 * 1.5 + ( 3 + 1.5 * std::sqrt(3) ) * ( 3 + 1.5 * std::sqrt(3) ) ) ); + + dd4hep::Material det_mat(theDetector.material(x_det.materialStr())); + + dd4hep::Assembly assembly(det_name); + + dd4hep::DetElement sdet("envelope", 1); + + dd4hep::Volume envelope( "envelope", dd4hep::Tube( dim.rmin(), theDetector.constant<double>( "multiple" ) * env_rmax, dim.dz() ), det_mat); + envelope.setVisAttributes(theDetector.visAttributes(x_det.visStr())); + + sens.setType("muonendcap"); + +// dd4hep::Readout readout = sens.readout(); +// dd4hep::Segmentation seg = readout.segmentation(); + for (int i0 = 0; i0 < theDetector.constant<int>("env_num_endcap"); i0++) + { + std::string env_name = "part" + dd4hep::_toString(i0,"_%d"); + dd4hep::Tube env_solid( dim.rmin(), theDetector.constant<double>( "multiple" ) * env_rmax, dim.dz(), 0, 90 * dd4hep::degree); + dd4hep::Volume env_vol( env_name, env_solid, det_mat); + env_vol.setVisAttributes(theDetector.visAttributes(x_det.visStr())); + dd4hep::Transform3D env_transform(dd4hep::Rotation3D(dd4hep::RotationZ(i0 * 90 * dd4hep::degree)),dd4hep::Position()); + for (int i1 = 0; i1 < theDetector.constant<int>("layer_num"); i1++ ) + { + for ( int i2 = 0; i2 < theDetector.constant<int>("strip_num_endcap"); i2++) + { + double strip_posX, strip_posY, strip_posZ; + double strip_sizeZ, surface_halfZ, BC420_halfZ, fiber_halfZ, cut_halfZ; + dd4hep::Rotation3D strip_rot; + if ( i1 == 1 ) + { + strip_rot = dd4hep::Rotation3D( dd4hep::RotationX( 90 * dd4hep::degree ) ); + strip_posX = theDetector.constant<double>("strip_x") * ( i2 + 0.5 ); + strip_posZ = 0.5 * ( 1 - 2 * ( i0 % 2 ) ) * theDetector.constant<double>("strip_y"); + if ( i2 < theDetector.constant<int>("strip_num_cut") ) + { + strip_sizeZ = std::sqrt( env_rmax * env_rmax - i2 * theDetector.constant<double>("strip_x") * i2 * theDetector.constant<double>("strip_x") ) - std::sqrt( dim.rmin() * dim.rmin() - i2 * theDetector.constant<double>("strip_x") * i2 * theDetector.constant<double>("strip_x") ); + strip_posY = std::sqrt( env_rmax * env_rmax - i2 * theDetector.constant<double>("strip_x") * i2 * theDetector.constant<double>("strip_x") ) - 0.5 * strip_sizeZ; + } + if ( i2 >= theDetector.constant<int>("strip_num_cut") ) + { + strip_sizeZ = std::sqrt( env_rmax * env_rmax - i2 * theDetector.constant<double>("strip_x") * i2 * theDetector.constant<double>("strip_x") ); + strip_posY = 0.5 * strip_sizeZ; + } + } + if ( i1 == 0 ) + { + strip_rot = dd4hep::Rotation3D( dd4hep::RotationX( 90 * dd4hep::degree ) * dd4hep::RotationY( 90 * dd4hep::degree ) ); + strip_posY = theDetector.constant<double>("strip_x") * ( i2 + 0.5 ); + strip_posZ = 0.5 * ( 2 * ( i0 % 2 ) - 1 ) * theDetector.constant<double>("strip_y"); + if ( i2 < theDetector.constant<int>("strip_num_cut") ) + { + strip_sizeZ = std::sqrt( env_rmax * env_rmax - i2 * theDetector.constant<double>("strip_x") * i2 * theDetector.constant<double>("strip_x") ) - std::sqrt( dim.rmin() * dim.rmin() - i2 * theDetector.constant<double>("strip_x") * i2 * theDetector.constant<double>("strip_x") ); + strip_posX = std::sqrt( env_rmax * env_rmax - i2 * theDetector.constant<double>("strip_x") * i2 * theDetector.constant<double>("strip_x") ) - 0.5 * strip_sizeZ; + } + if ( i2 >= theDetector.constant<int>("strip_num_cut") ) + { + strip_sizeZ = std::sqrt( env_rmax * env_rmax - i2 * theDetector.constant<double>("strip_x") * i2 * theDetector.constant<double>("strip_x") ); + strip_posX = 0.5 * strip_sizeZ; + } + } + double strip_halfZ = 0.5 * strip_sizeZ; + double SiPM_posZ = strip_halfZ + theDetector.constant<double>("surf"); + surface_halfZ = BC420_halfZ = fiber_halfZ = cut_halfZ = strip_halfZ - theDetector.constant<double>("surf"); + xml_coll_t dcStrip(x_det,_U(module)); + xml_comp_t x_strip = dcStrip; + std::string strip_name = x_strip.nameStr() + dd4hep::_toString(i0,"_%d") + dd4hep::_toString(i1,"_%d") + dd4hep::_toString(i2,"_%d"); + dd4hep::Material strip_mat(theDetector.material(x_strip.materialStr())); + xml_dim_t strip_dim(x_strip.child(_U(dimensions))); + + dd4hep::Box strip_solid(strip_dim.dx(),strip_dim.dy(),strip_halfZ); + dd4hep::Volume strip_vol(strip_name,strip_solid,strip_mat); + strip_vol.setVisAttributes(theDetector.visAttributes(x_strip.visStr())); + dd4hep::Transform3D strip_transform(strip_rot,dd4hep::Position(strip_posX,strip_posY,strip_posZ)); + + std::string surface_name, BC420_name, cut1_name, cut2_name, cut3_name, SiPM_name; + std::string surface_vis, BC420_vis, cut1_vis, cut2_vis, cut3_vis, SiPM_vis; + dd4hep::Material surface_mat, BC420_mat, cut1_mat, cut2_mat, cut3_mat, SiPM_mat; + xml_dim_t surface_pos, cut1_pos, BC420_pos, cut3_pos, cut2_pos, SiPM_pos; + xml_dim_t surface_dim, cut1_dim, BC420_dim, cut3_dim, cut2_dim, SiPM_dim; + for(xml_coll_t dcModule(x_strip,_U(module)); dcModule; dcModule++) + { + xml_comp_t x_module = dcModule; + + xml_dim_t module_pos(x_module.child(_U(position))); + xml_dim_t module_dim(x_module.child(_U(dimensions))); + + dd4hep::Box module_solid(module_dim.dx(),module_dim.dy(),module_dim.dz()); + if(x_module.id()==0) + { + surface_name = x_module.nameStr(); + surface_vis = x_module.visStr(); + surface_mat = theDetector.material(x_module.materialStr()); + xml_dim_t s_pos(x_module.child(_U(position))); + xml_dim_t s_dim(x_module.child(_U(dimensions))); + surface_pos = s_pos; + surface_dim = s_dim; + + xml_coll_t dcCut1(x_module,_U(section)); + xml_comp_t x_cut1 = dcCut1; + cut1_name = x_cut1.nameStr(); + cut1_vis = x_cut1.visStr(); + cut1_mat = theDetector.material(x_cut1.materialStr()); + xml_dim_t c1_pos(x_cut1.child(_U(position))); + xml_dim_t c1_dim(x_cut1.child(_U(dimensions))); + cut1_pos = c1_pos; + cut1_dim = c1_dim; + } + if(x_module.id()==1) + { + BC420_name = x_module.nameStr(); + BC420_vis = x_module.visStr(); + BC420_mat = theDetector.material(x_module.materialStr()); + xml_dim_t b_pos(x_module.child(_U(position))); + xml_dim_t b_dim(x_module.child(_U(dimensions))); + BC420_pos = b_pos; + BC420_dim = b_dim; + + xml_coll_t dcCut3(x_module,_U(section)); + xml_comp_t x_cut3 = dcCut3; + cut3_name = x_cut3.nameStr(); + cut3_vis = x_cut3.visStr(); + cut3_mat = theDetector.material(x_cut3.materialStr()); + xml_dim_t c3_pos(x_cut3.child(_U(position))); + xml_dim_t c3_dim(x_cut3.child(_U(dimensions))); + cut3_pos = c3_pos; + cut3_dim = c3_dim; + + xml_coll_t dcCut2(x_cut3,_U(section)); + xml_comp_t x_cut2 = dcCut2; + cut2_name = x_cut2.nameStr(); + cut2_vis = x_cut2.visStr(); + cut2_mat = theDetector.material(x_cut2.materialStr()); + xml_dim_t c2_pos(x_cut2.child(_U(position))); + xml_dim_t c2_dim(x_cut2.child(_U(dimensions))); + cut2_pos = c2_pos; + cut2_dim = c2_dim; + } + if(x_module.id()==2) + { + SiPM_name = x_module.nameStr(); + SiPM_vis = x_module.visStr(); + SiPM_mat = theDetector.material(x_module.materialStr()); + xml_dim_t S_pos(x_module.child(_U(position))); + xml_dim_t S_dim(x_module.child(_U(dimensions))); + SiPM_pos = S_pos; + SiPM_dim = S_dim; + } + } + dd4hep::Box surface_solid(surface_dim.dx(),surface_dim.dy(),surface_halfZ); + dd4hep::Box cut1_solid(cut1_dim.dx(),cut1_dim.dy(),cut_halfZ); + dd4hep::Box BC420_solid(BC420_dim.dx(),BC420_dim.dy(),BC420_halfZ); + dd4hep::Tube cut3_solid(cut3_dim.rmin(),cut3_dim.rmax(),cut_halfZ); + dd4hep::Box cut2_solid(cut2_dim.dx(),cut2_dim.dy(),cut_halfZ); + dd4hep::Box SiPM_solid(SiPM_dim.dx(),SiPM_dim.dy(),SiPM_dim.dz()); + + dd4hep::Transform3D surface_transform(dd4hep::Rotation3D(),dd4hep::Position(surface_pos.x(),surface_pos.y(),surface_pos.z())); + dd4hep::Transform3D cut1_transform(dd4hep::Rotation3D(),dd4hep::Position(cut1_pos.x(),cut1_pos.y(),cut1_pos.z())); + dd4hep::Transform3D BC420_transform(dd4hep::Rotation3D(),dd4hep::Position(BC420_pos.x(),BC420_pos.y(),BC420_pos.z())); + dd4hep::Transform3D cut2_transform(dd4hep::Rotation3D(),dd4hep::Position(cut2_pos.x(),cut2_pos.y(),cut2_pos.z())); + dd4hep::Transform3D cut3_transform(dd4hep::Rotation3D(),dd4hep::Position(cut3_pos.x(),cut3_pos.y(),cut3_pos.z())); + dd4hep::Transform3D SiPM_transform1(dd4hep::Rotation3D(),dd4hep::Position(SiPM_pos.x(),SiPM_pos.y(),SiPM_posZ)); + dd4hep::Transform3D SiPM_transform2(dd4hep::Rotation3D(),dd4hep::Position(SiPM_pos.x(),SiPM_pos.y(), -1 * SiPM_posZ)); + + dd4hep::Volume surface_vol(surface_name, surface_solid, surface_mat); + surface_vol.setVisAttributes(theDetector.visAttributes(surface_vis)); + surface_vol.setSensitiveDetector(sens); + + dd4hep::Volume cut1_vol(cut1_name, cut1_solid, cut1_mat); + cut1_vol.setVisAttributes(theDetector.visAttributes(cut1_vis)); + + dd4hep::Volume cut2_vol(cut2_name, cut2_solid, cut2_mat); + cut2_vol.setVisAttributes(theDetector.visAttributes(cut2_vis)); + + dd4hep::Volume cut3_vol(cut3_name, cut3_solid, cut3_mat); + cut3_vol.setVisAttributes(theDetector.visAttributes(cut3_vis)); + + dd4hep::Volume BC420_vol(BC420_name,BC420_solid,BC420_mat); + BC420_vol.setVisAttributes(theDetector.visAttributes(BC420_vis)); + + dd4hep::Volume SiPM_vol(SiPM_name, SiPM_solid, SiPM_mat); + SiPM_vol.setVisAttributes(theDetector.visAttributes(SiPM_vis)); + SiPM_vol.setSensitiveDetector(sens); + + BC420_vol.placeVolume(cut2_vol,cut2_transform); + BC420_vol.placeVolume(cut3_vol,cut3_transform); + dd4hep::PlacedVolume cladding_place, core_place; + for(xml_coll_t dcSection(x_strip,_U(section)); dcSection; dcSection++) + { + xml_comp_t x_section = dcSection; + std::string section_name = x_section.nameStr(); + dd4hep::Material section_mat = theDetector.material(x_section.materialStr()); + + xml_dim_t section_pos(x_section.child(_U(position))); + xml_dim_t section_dim(x_section.child(_U(dimensions))); + + dd4hep::Tube section_solid(section_dim.rmin(),section_dim.rmax(),fiber_halfZ); + dd4hep::Volume section_vol(section_name,section_solid,section_mat); + section_vol.setVisAttributes(theDetector.visAttributes(x_section.visStr())); + + dd4hep::Transform3D section_transform(dd4hep::Rotation3D(),dd4hep::Position(section_pos.x(),section_pos.y(),section_pos.z())); + if (x_section.id() == 0) + { + cladding_place = BC420_vol.placeVolume(section_vol,section_transform); + } + if (x_section.id() == 1) + { + core_place = BC420_vol.placeVolume(section_vol,section_transform); + } + } + surface_vol.placeVolume(cut1_vol,cut1_transform); + dd4hep::PlacedVolume BC420_place = surface_vol.placeVolume(BC420_vol,BC420_transform); + BC420_place.addPhysVolID("Stripe",i2+1); + dd4hep::PlacedVolume surf_place = strip_vol.placeVolume(surface_vol,surface_transform); + int lnum = ( ( 2 * ( i0 % 2 ) - 1 ) * ( 2 * i1 - 1 ) + 1 ) / 2; + surf_place.addPhysVolID("Layer", lnum+1); + surf_place.addPhysVolID("SiPM",0); + dd4hep::PlacedVolume SiPM_place1 = strip_vol.placeVolume(SiPM_vol,SiPM_transform1); + SiPM_place1.addPhysVolID("SiPM",1); + dd4hep::PlacedVolume SiPM_place2 = strip_vol.placeVolume(SiPM_vol,SiPM_transform2); + SiPM_place2.addPhysVolID("SiPM",2); + env_vol.placeVolume(strip_vol,strip_transform); + dd4hep::OpticalSurfaceManager surfMgr = theDetector.surfaceManager(); + std::string optical_surf = strip_name + "_surf"; + std::string optical_fiber = strip_name + "_fiber"; + dd4hep::OpticalSurface Surf_stripe = surfMgr.opticalSurface("Surf__stripe"); + dd4hep::OpticalSurface Surf_fiber = surfMgr.opticalSurface("Surf__fiber"); + dd4hep::BorderSurface surface_stripe( theDetector, sdet, optical_surf, Surf_stripe, BC420_place, surf_place); + dd4hep::BorderSurface surface_fiber( theDetector, sdet, optical_fiber, Surf_fiber, core_place, cladding_place); + } + } + dd4hep::PlacedVolume env_place = envelope.placeVolume(env_vol,env_transform); + env_place.addPhysVolID("Env",i0+1); + } + dd4hep::PlacedVolume pv; + dd4hep::DetElement both_endcaps(det_name,0); + dd4hep::Volume motherVol = theDetector.pickMotherVolume(both_endcaps); + dd4hep::DetElement sdetA = sdet; + dd4hep::Ref_t(sdetA)->SetName((det_name+"_A").c_str()); + dd4hep::DetElement sdetB = sdet.clone(det_name+"_B",3); + pv = assembly.placeVolume(envelope,dd4hep::Transform3D(dd4hep::Rotation3D(dd4hep::RotationX(90*dd4hep::degree)),dd4hep::Position(0,pos.y(),0))); + pv.addPhysVolID("Endcap",1); + + sdetA.setPlacement(pv); + + pv = assembly.placeVolume(envelope,dd4hep::Transform3D(dd4hep::Rotation3D(dd4hep::RotationX(90*dd4hep::degree)),dd4hep::Position(0,-1*pos.y(),0))); + pv.addPhysVolID("Endcap",2); + + sdetB.setPlacement(pv); + + pv = motherVol.placeVolume(assembly); +// pv.addPhysVolID("system",x_det.id()); + both_endcaps.setPlacement(pv); + both_endcaps.add(sdetA); + both_endcaps.add(sdetB); + + MYDEBUG("create_detector DONE. "); + return both_endcaps; +} + +DECLARE_DETELEMENT(Muon_Endcap_v01, create_detector) diff --git a/Examples/options/dumpid.py b/Examples/options/dumpid.py index ef9a45ce18c6fbb86fb1dc8ed2dc79f4cf32dc88..f4111bc1cb14914bce220c5bfa0d552fe784b79f 100644 --- a/Examples/options/dumpid.py +++ b/Examples/options/dumpid.py @@ -28,7 +28,7 @@ geosvc.compact = geometry_path ############################################################################## from Configurables import k4DataSvc -dsvc = k4DataSvc("EventDataSvc", input="test-detsim10.root") +dsvc = k4DataSvc("EventDataSvc", input="CRD-o1-v01-SimRec00.root") ############################################################################## # NTuple Svc diff --git a/Simulation/DetSimGeom/src/AnExampleDetElemTool.cpp b/Simulation/DetSimGeom/src/AnExampleDetElemTool.cpp index 00c84c75eaebcedad22265694d9c08ca6d081988..bfcf35c54186a15d50cac039ec572516e7c2f98c 100644 --- a/Simulation/DetSimGeom/src/AnExampleDetElemTool.cpp +++ b/Simulation/DetSimGeom/src/AnExampleDetElemTool.cpp @@ -149,6 +149,22 @@ AnExampleDetElemTool::ConstructSDandField() { } } } + if (typ=="muonbarrel") { + m_muonbarrel_sdtool = ToolHandle<ISensDetTool>("MuonBarrelSensDetTool"); + if (m_muonbarrel_sdtool) { + info() << "Find the MuonBarrelSensDetTool." << endmsg; + g4sd = m_muonbarrel_sdtool->createSD(nam); + info() << "create g4SD: " << g4sd << endmsg; + } + } + if (typ=="muonendcap") { + m_muonendcap_sdtool = ToolHandle<ISensDetTool>("MuonEndcapSensDetTool"); + if (m_muonendcap_sdtool) { + info() << "Find the MuonEndcapSensDetTool." << endmsg; + g4sd = m_muonendcap_sdtool->createSD(nam); + info() << "create g4SD: " << g4sd << endmsg; + } + } } if (!g4sd) { @@ -229,6 +245,8 @@ AnExampleDetElemTool::initialize() { m_calo_sdtool = ToolHandle<ISensDetTool>("CalorimeterSensDetTool"); m_driftchamber_sdtool = ToolHandle<ISensDetTool>("DriftChamberSensDetTool"); m_tpc_sdtool = ToolHandle<ISensDetTool>("TimeProjectionChamberSensDetTool"); + m_muonbarrel_sdtool = ToolHandle<ISensDetTool>("MuonBarrelSensDetTool"); + m_muonendcap_sdtool = ToolHandle<ISensDetTool>("MuonEndcapSensDetTool"); return sc; } diff --git a/Simulation/DetSimGeom/src/AnExampleDetElemTool.h b/Simulation/DetSimGeom/src/AnExampleDetElemTool.h index 1b3a923f1f317a3c5e35b9d5d54eb30c84a0b097..74442d777db44de4c7d8b2a0a9063034f09eee5d 100644 --- a/Simulation/DetSimGeom/src/AnExampleDetElemTool.h +++ b/Simulation/DetSimGeom/src/AnExampleDetElemTool.h @@ -38,6 +38,8 @@ private: ToolHandle<ISensDetTool> m_driftchamber_sdtool; ToolHandle<ISensDetTool> m_tpc_sdtool; ToolHandle<ISensDetTool> m_tracker_sdtool; + ToolHandle<ISensDetTool> m_muonbarrel_sdtool; + ToolHandle<ISensDetTool> m_muonendcap_sdtool; }; #endif diff --git a/Simulation/DetSimSD/src/MuonBarrelSensDetTool.cpp b/Simulation/DetSimSD/src/MuonBarrelSensDetTool.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c8425500154fad4bb82ab99b5f294bc77ea4f7f8 --- /dev/null +++ b/Simulation/DetSimSD/src/MuonBarrelSensDetTool.cpp @@ -0,0 +1,47 @@ +#include "MuonBarrelSensDetTool.h" + +#include "G4VSensitiveDetector.hh" + +#include "DD4hep/Detector.h" + +#include "MuonBarrelSensitiveDetector.h" +#include "TrackerCombineSensitiveDetector.h" + +#include "CLHEP/Units/SystemOfUnits.h" + +DECLARE_COMPONENT(MuonBarrelSensDetTool) + +StatusCode MuonBarrelSensDetTool::initialize() { + StatusCode sc; + debug() << "initialize() " << endmsg; + + m_geosvc = service<IGeomSvc>("GeomSvc"); + if (!m_geosvc) { + error() << "Failed to find GeomSvc." << endmsg; + return StatusCode::FAILURE; + } + + return AlgTool::initialize(); +} + +StatusCode MuonBarrelSensDetTool::finalize() { + StatusCode sc; + + return sc; +} + +G4VSensitiveDetector* MuonBarrelSensDetTool::createSD(const std::string& name) { + debug() << "createSD for " << name << endmsg; + + dd4hep::Detector* dd4hep_geo = m_geosvc->lcdd(); + auto sens = dd4hep_geo->sensitiveDetector(name); + G4VSensitiveDetector* sd = nullptr; + if(sens.combineHits()){ + sd = new TrackerCombineSensitiveDetector(name, *dd4hep_geo); + } + else{ + sd = new MuonBarrelSensitiveDetector(name, *dd4hep_geo); + } + + return sd; +} diff --git a/Simulation/DetSimSD/src/MuonBarrelSensDetTool.h b/Simulation/DetSimSD/src/MuonBarrelSensDetTool.h new file mode 100644 index 0000000000000000000000000000000000000000..137fe9754fe91faff55d18de5d02f5f09b9df3ae --- /dev/null +++ b/Simulation/DetSimSD/src/MuonBarrelSensDetTool.h @@ -0,0 +1,32 @@ +#ifndef MuonBarrelSensDetTool_h +#define MuonBarrelSensDetTool_h + + +#include "GaudiKernel/AlgTool.h" +#include "GaudiKernel/ToolHandle.h" +#include "DetSimInterface/ISensDetTool.h" +#include "DetInterface/IGeomSvc.h" + +#include "DD4hep/DD4hepUnits.h" + +class MuonBarrelSensDetTool: public extends<AlgTool, ISensDetTool> { + + public: + + using extends::extends; + + /// Overriding initialize and finalize + StatusCode initialize() override; + StatusCode finalize() override; + + /// Override ISensDetTool + virtual G4VSensitiveDetector* createSD(const std::string& name) override; + +private: + + // in order to initialize SD, we need to get the lcdd() + SmartIF<IGeomSvc> m_geosvc; + +}; + +#endif diff --git a/Simulation/DetSimSD/src/MuonBarrelSensitiveDetector.cpp b/Simulation/DetSimSD/src/MuonBarrelSensitiveDetector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..56a2606152af8fda56dce14d317e4c3db025c20b --- /dev/null +++ b/Simulation/DetSimSD/src/MuonBarrelSensitiveDetector.cpp @@ -0,0 +1,86 @@ +#include "MuonBarrelSensitiveDetector.h" + +#include "G4Step.hh" +#include "G4VProcess.hh" +//#include "G4SteppingManager.hh" +#include "G4SDManager.hh" +//#include "UserTrackInformation.hh" +#include "DD4hep/DD4hepUnits.h" + +MuonBarrelSensitiveDetector::MuonBarrelSensitiveDetector(const std::string& name, + dd4hep::Detector& description) + : DDG4SensitiveDetector(name, description), + m_hc(nullptr){ + + G4String CollName=name+"Collection"; + collectionName.insert(CollName); +} + +void MuonBarrelSensitiveDetector::Initialize(G4HCofThisEvent* HCE){ + m_hc = new HitCollection(GetName(), collectionName[0]); + int HCID = G4SDManager::GetSDMpointer()->GetCollectionID(m_hc); + HCE->AddHitsCollection( HCID, m_hc ); +} + +G4bool MuonBarrelSensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*){ + G4TouchableHandle touchPost = step->GetPostStepPoint()->GetTouchableHandle(); + G4TouchableHandle touchPre = step->GetPreStepPoint()->GetTouchableHandle(); + auto currentTrack = step->GetTrack(); + auto pname = currentTrack->GetParticleDefinition()->GetParticleName(); + auto touchable = step->GetPreStepPoint()->GetTouchable(); + auto physical = touchable->GetVolume(); + if ( physical->GetName() == "surface" ) + { + if ( pname == "opticalphoton" ) + { + G4double random = G4UniformRand(); + if(random < 0.1) + { + currentTrack->SetTrackStatus(fStopAndKill); + } + } + } + dd4hep::sim::Geant4StepHandler h(step); + if (fabs(h.trackDef()->GetPDGCharge()) < 0.01) return true; + + dd4hep::Position prePos = h.prePos(); + dd4hep::Position postPos = h.postPos(); + dd4hep::Position direction = postPos - prePos; + dd4hep::Position position = mean_direction(prePos,postPos); + double hit_len = direction.R(); + if (hit_len < 1E-9) return true; + if (hit_len > 0) { + double new_len = mean_length(h.preMom(),h.postMom())/hit_len; + direction *= new_len/hit_len; + } + + dd4hep::sim::Geant4TrackerHit* hit = nullptr; + hit = new dd4hep::sim::Geant4TrackerHit(h.track->GetTrackID(), + h.track->GetDefinition()->GetPDGEncoding(), + step->GetTotalEnergyDeposit(), + h.track->GetGlobalTime()); + + if ( hit ) { + int i = 0; + if ( pname == "opticalphoton" && physical->GetName() == "SiPM") + { + i = 1; + } + hit->cellID = i * getCellID( step ) ; + hit->energyDeposit = step->GetTotalEnergyDeposit(); + hit->position = position; + hit->momentum = direction; + hit->length = hit_len; + m_hc->insert(hit); + if ( physical->GetName() == "SiPM" ) + { + currentTrack->SetTrackStatus(fStopAndKill); + } + return true; + } + throw std::runtime_error("new() failed: Cannot allocate hit object"); + return false; +} + +void MuonBarrelSensitiveDetector::EndOfEvent(G4HCofThisEvent* HCE){ +} diff --git a/Simulation/DetSimSD/src/MuonBarrelSensitiveDetector.h b/Simulation/DetSimSD/src/MuonBarrelSensitiveDetector.h new file mode 100644 index 0000000000000000000000000000000000000000..0974e8b641a1999dccf1840f63f798d90d7fa36f --- /dev/null +++ b/Simulation/DetSimSD/src/MuonBarrelSensitiveDetector.h @@ -0,0 +1,21 @@ + +#ifndef MuonBarrelSensitiveDetector_h +#define MuonBarrelSensitiveDetector_h + +#include "DetSimSD/DDG4SensitiveDetector.h" +#include "DDG4/Defs.h" + +class MuonBarrelSensitiveDetector: public DDG4SensitiveDetector { + public: + MuonBarrelSensitiveDetector(const std::string& name, dd4hep::Detector& description); + + void Initialize(G4HCofThisEvent* HCE); + G4bool ProcessHits(G4Step* step, G4TouchableHistory* history); + void EndOfEvent(G4HCofThisEvent* HCE); + + protected: + + HitCollection* m_hc = nullptr; + +}; +#endif diff --git a/Simulation/DetSimSD/src/MuonEndcapSensDetTool.cpp b/Simulation/DetSimSD/src/MuonEndcapSensDetTool.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ca89e8d6bebe28b06823834aac4b5a73fbbea708 --- /dev/null +++ b/Simulation/DetSimSD/src/MuonEndcapSensDetTool.cpp @@ -0,0 +1,47 @@ +#include "MuonEndcapSensDetTool.h" + +#include "G4VSensitiveDetector.hh" + +#include "DD4hep/Detector.h" + +#include "MuonEndcapSensitiveDetector.h" +#include "TrackerCombineSensitiveDetector.h" + +#include "CLHEP/Units/SystemOfUnits.h" + +DECLARE_COMPONENT(MuonEndcapSensDetTool) + +StatusCode MuonEndcapSensDetTool::initialize() { + StatusCode sc; + debug() << "initialize() " << endmsg; + + m_geosvc = service<IGeomSvc>("GeomSvc"); + if (!m_geosvc) { + error() << "Failed to find GeomSvc." << endmsg; + return StatusCode::FAILURE; + } + + return AlgTool::initialize(); +} + +StatusCode MuonEndcapSensDetTool::finalize() { + StatusCode sc; + + return sc; +} + +G4VSensitiveDetector* MuonEndcapSensDetTool::createSD(const std::string& name) { + debug() << "createSD for " << name << endmsg; + + dd4hep::Detector* dd4hep_geo = m_geosvc->lcdd(); + auto sens = dd4hep_geo->sensitiveDetector(name); + G4VSensitiveDetector* sd = nullptr; + if(sens.combineHits()){ + sd = new TrackerCombineSensitiveDetector(name, *dd4hep_geo); + } + else{ + sd = new MuonEndcapSensitiveDetector(name, *dd4hep_geo); + } + + return sd; +} diff --git a/Simulation/DetSimSD/src/MuonEndcapSensDetTool.h b/Simulation/DetSimSD/src/MuonEndcapSensDetTool.h new file mode 100644 index 0000000000000000000000000000000000000000..4d1bfdad4231ed6ed75c3b4885ab1962815eb4ab --- /dev/null +++ b/Simulation/DetSimSD/src/MuonEndcapSensDetTool.h @@ -0,0 +1,32 @@ +#ifndef MuonEndcapSensDetTool_h +#define MuonEndcapSensDetTool_h + + +#include "GaudiKernel/AlgTool.h" +#include "GaudiKernel/ToolHandle.h" +#include "DetSimInterface/ISensDetTool.h" +#include "DetInterface/IGeomSvc.h" + +#include "DD4hep/DD4hepUnits.h" + +class MuonEndcapSensDetTool: public extends<AlgTool, ISensDetTool> { + + public: + + using extends::extends; + + /// Overriding initialize and finalize + StatusCode initialize() override; + StatusCode finalize() override; + + /// Override ISensDetTool + virtual G4VSensitiveDetector* createSD(const std::string& name) override; + +private: + + // in order to initialize SD, we need to get the lcdd() + SmartIF<IGeomSvc> m_geosvc; + +}; + +#endif diff --git a/Simulation/DetSimSD/src/MuonEndcapSensitiveDetector.cpp b/Simulation/DetSimSD/src/MuonEndcapSensitiveDetector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0efa231f13b23b03ddbb208699c9093c4880615b --- /dev/null +++ b/Simulation/DetSimSD/src/MuonEndcapSensitiveDetector.cpp @@ -0,0 +1,86 @@ +#include "MuonEndcapSensitiveDetector.h" + +#include "G4Step.hh" +#include "G4VProcess.hh" +//#include "G4SteppingManager.hh" +#include "G4SDManager.hh" +//#include "UserTrackInformation.hh" +#include "DD4hep/DD4hepUnits.h" + +MuonEndcapSensitiveDetector::MuonEndcapSensitiveDetector(const std::string& name, + dd4hep::Detector& description) + : DDG4SensitiveDetector(name, description), + m_hc(nullptr){ + + G4String CollName=name+"Collection"; + collectionName.insert(CollName); +} + +void MuonEndcapSensitiveDetector::Initialize(G4HCofThisEvent* HCE){ + m_hc = new HitCollection(GetName(), collectionName[0]); + int HCID = G4SDManager::GetSDMpointer()->GetCollectionID(m_hc); + HCE->AddHitsCollection( HCID, m_hc ); +} + +G4bool MuonEndcapSensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*){ + G4TouchableHandle touchPost = step->GetPostStepPoint()->GetTouchableHandle(); + G4TouchableHandle touchPre = step->GetPreStepPoint()->GetTouchableHandle(); + auto currentTrack = step->GetTrack(); + auto pname = currentTrack->GetParticleDefinition()->GetParticleName(); + auto touchable = step->GetPreStepPoint()->GetTouchable(); + auto physical = touchable->GetVolume(); + if ( physical->GetName() == "surface" ) + { + if ( pname == "opticalphoton" ) + { + G4double random = G4UniformRand(); + if(random < 0.1) + { + currentTrack->SetTrackStatus(fStopAndKill); + } + } + } + dd4hep::sim::Geant4StepHandler h(step); + if (fabs(h.trackDef()->GetPDGCharge()) < 0.01) return true; + + dd4hep::Position prePos = h.prePos(); + dd4hep::Position postPos = h.postPos(); + dd4hep::Position direction = postPos - prePos; + dd4hep::Position position = mean_direction(prePos,postPos); + double hit_len = direction.R(); + if (hit_len < 1E-9) return true; + if (hit_len > 0) { + double new_len = mean_length(h.preMom(),h.postMom())/hit_len; + direction *= new_len/hit_len; + } + + dd4hep::sim::Geant4TrackerHit* hit = nullptr; + hit = new dd4hep::sim::Geant4TrackerHit(h.track->GetTrackID(), + h.track->GetDefinition()->GetPDGEncoding(), + step->GetTotalEnergyDeposit(), + h.track->GetGlobalTime()); + + if ( hit ) { + int i = 0; + if ( pname == "opticalphoton" && physical->GetName() == "SiPM") + { + i = 1; + } + hit->cellID = i * getCellID( step ) ; + hit->energyDeposit = step->GetTotalEnergyDeposit(); + hit->position = position; + hit->momentum = direction; + hit->length = hit_len; + m_hc->insert(hit); + if ( physical->GetName() == "SiPM" ) + { + currentTrack->SetTrackStatus(fStopAndKill); + } + return true; + } + throw std::runtime_error("new() failed: Cannot allocate hit object"); + return false; +} + +void MuonEndcapSensitiveDetector::EndOfEvent(G4HCofThisEvent* HCE){ +} diff --git a/Simulation/DetSimSD/src/MuonEndcapSensitiveDetector.h b/Simulation/DetSimSD/src/MuonEndcapSensitiveDetector.h new file mode 100644 index 0000000000000000000000000000000000000000..a19d3eaaaa47606836680ab2e9be22d503491eb4 --- /dev/null +++ b/Simulation/DetSimSD/src/MuonEndcapSensitiveDetector.h @@ -0,0 +1,21 @@ + +#ifndef MuonEndcapSensitiveDetector_h +#define MuonEndcapSensitiveDetector_h + +#include "DetSimSD/DDG4SensitiveDetector.h" +#include "DDG4/Defs.h" + +class MuonEndcapSensitiveDetector: public DDG4SensitiveDetector { + public: + MuonEndcapSensitiveDetector(const std::string& name, dd4hep::Detector& description); + + void Initialize(G4HCofThisEvent* HCE); + G4bool ProcessHits(G4Step* step, G4TouchableHistory* history); + void EndOfEvent(G4HCofThisEvent* HCE); + + protected: + + HitCollection* m_hc = nullptr; + +}; +#endif