diff --git a/Detector/DetCRD/CMakeLists.txt b/Detector/DetCRD/CMakeLists.txt index d3f0b06954b5d3a547cb13495dfb52201ebf0818..de22c5023717faaafc4938d5bc6876b780cf8261 100644 --- a/Detector/DetCRD/CMakeLists.txt +++ b/Detector/DetCRD/CMakeLists.txt @@ -21,6 +21,7 @@ gaudi_add_module(DetCRD src/Calorimeter/RotatedCrystalCalorimeter_v01_geo.cpp src/Other/CRDBeamPipe_v01_geo.cpp src/Tracker/SiTrackerSkewRing_v01_geo.cpp + src/Tracker/SiTrackerStaggeredLadder_v01_geo.cpp LINK ${DD4hep_COMPONENT_LIBRARIES} ) diff --git a/Detector/DetCRD/compact/CRD_common_v01/VXD_StaggeredLadder_v01_01.xml b/Detector/DetCRD/compact/CRD_common_v01/VXD_StaggeredLadder_v01_01.xml new file mode 100644 index 0000000000000000000000000000000000000000..dde9f4808f438affd76e9fb752438b987492e6e5 --- /dev/null +++ b/Detector/DetCRD/compact/CRD_common_v01/VXD_StaggeredLadder_v01_01.xml @@ -0,0 +1,98 @@ +<lccdd> + <info name="VXD_StaggeredLadder_v01_01" + title="CepC VXD with staggered ladders" + author="H.Zeng, " + url="http://cepc.ihep.ac.cn" + status="developing" + version="v01"> + <comment>CepC vertex detector based on MOST2 project </comment> + </info> + <define> + <constant name="VXD_inner_radius" value="Vertex_inner_radius"/> + <constant name="VXD_outer_radius" value="Vertex_outer_radius"/> + <constant name="VXD_half_length" value="Vertex_half_length"/> + <constant name="VXDLayer1_half_length" value="90*mm" /> + <constant name="VXDLayer2_half_length" value="90*mm" /> + <constant name="VXDLayer3_half_length" value="90*mm" /> + <constant name="VXD_sensor_length" value="30*mm" /> + </define> + + <detectors> + <detector id="DetID_VXD" name="VXD" type="SiTrackerStaggeredLadder_v01" vis="VXDVis" readout="VXDCollection" insideTrackingVolume="true"> + <envelope> + <shape type="Tube" rmin="VXD_inner_radius" rmax="VXD_outer_radius" dz="VXD_half_length" material="Air"/> + </envelope> + + <type_flags type="DetType_TRACKER + DetType_BARREL + DetType_PIXEL "/> + + <global sensitive_thickness="VXD_sensitive_thickness" support_thickness="VXD_support_thickness" sensor_length="VXD_sensor_length" + sensitive_mat="G4_Si" support_mat="G4_C" sensitive_threshold_KeV="64*keV" /> + <display ladder="SeeThrough" support="VXDSupportVis" flex="VXDFlexVis" sens_env="SeeThrough" sens="GrayVis" deadsensor="GreenVis" deadwire="RedVis"/> + + <layer layer_id="0" ladder_radius="17.4*mm" ladder_offset="(8.4-1.5)*mm" n_sensors_per_side="VXDLayer1_half_length*2/VXD_sensor_length" + n_ladders="10" > + <ladder isDoubleSided="true"> + <ladderSupport height="2*mm" length="200*mm" thickness="350*um" width="16.8*mm" mat="CarbonFiber"/> + <flex n_slices="3"> + <slice length="200*mm" thickness="60*um" width="16.8*mm" mat="Epoxy"/> + <slice length="200*mm" thickness="74*um" width="16.8*mm" mat="Kapton"/> + <slice length="200*mm" thickness="26.8*um" width="16.8*mm" mat="G4_Al"/> + </flex> + <sensor n_sensors="7" gap="0.1*mm" thickness="50*um" active_length="25.6*mm" active_width="12.8*mm" dead_width="2*mm" sensor_mat="G4_Si" + deadwire_length="(7*(25.6+0.1)-0.1)*mm" deadwire_width="2*mm" deadwire_thickness="(50/10)*um" deadwire_mat="G4_Al"/> + </ladder> + </layer> + <layer layer_id="1" ladder_radius="36.9*mm" ladder_offset="(8.4+5.0)*mm" n_sensors_per_side="VXDLayer2_half_length*2/VXD_sensor_length" + n_ladders="22" > + <ladder isDoubleSided="true"> + <ladderSupport height="2*mm" length="200*mm" thickness="350*um" width="16.8*mm" mat="CarbonFiber"/> + <flex n_slices="3"> + <slice length="200*mm" thickness="60*um" width="16.8*mm" mat="Epoxy"/> + <slice length="200*mm" thickness="74*um" width="16.8*mm" mat="Kapton"/> + <slice length="200*mm" thickness="26.8*um" width="16.8*mm" mat="G4_Al"/> + <!-- <slice length="200*mm" thickness="15*um" width="16.8*mm" mat="Epoxy"/> --> + <!-- <slice length="200*mm" thickness="12*um" width="16.8*mm" mat="Kapton"/> --> + <!-- <slice length="200*mm" thickness="15*um" width="16.8*mm" mat="Epoxy"/> --> + <!-- <slice length="200*mm" thickness="13.4*um" width="16.8*mm" mat="G4_Al"/> --> + <!-- <slice length="200*mm" thickness="50*um" width="16.8*mm" mat="Kapton"/> --> + <!-- <slice length="200*mm" thickness="13.4*um" width="16.8*mm" mat="G4_Al"/> --> + <!-- <slice length="200*mm" thickness="15*um" width="16.8*mm" mat="Epoxy"/> --> + <!-- <slice length="200*mm" thickness="12*um" width="16.8*mm" mat="Kapton"/> --> + <!-- <slice length="200*mm" thickness="15*um" width="14.8*mm" mat="Epoxy"/> --> + </flex> + <sensor n_sensors="7" gap="0.1*mm" thickness="50*um" active_length="25.6*mm" active_width="12.8*mm" dead_width="2*mm" sensor_mat="G4_Si" + deadwire_length="(7*(25.6+0.1)-0.1)*mm" deadwire_width="2*mm" deadwire_thickness="(50/10)*um" deadwire_mat="G4_Al"/> + </ladder> + </layer> + <layer layer_id="2" ladder_radius="57.7*mm" ladder_offset="(8.4+9.6)*mm" n_sensors_per_side="VXDLayer3_half_length*2/VXD_sensor_length" + n_ladders="32" > + <ladder isDoubleSided="true"> + <ladderSupport height="2*mm" length="200*mm" thickness="350*um" width="16.8*mm" mat="CarbonFiber"/> + <flex n_slices="3"> + <slice length="200*mm" thickness="60*um" width="16.8*mm" mat="Epoxy"/> + <slice length="200*mm" thickness="74*um" width="16.8*mm" mat="Kapton"/> + <slice length="200*mm" thickness="26.8*um" width="16.8*mm" mat="G4_Al"/> + <!-- <slice length="200*mm" thickness="15*um" width="16.8*mm" mat="Epoxy"/> + <slice length="200*mm" thickness="12*um" width="16.8*mm" mat="Kapton"/> + <slice length="200*mm" thickness="15*um" width="16.8*mm" mat="Epoxy"/> + <slice length="200*mm" thickness="13.4*um" width="16.8*mm" mat="G4_Al"/> + <slice length="200*mm" thickness="50*um" width="16.8*mm" mat="Kapton"/> + <slice length="200*mm" thickness="13.4*um" width="16.8*mm" mat="G4_Al"/> + <slice length="200*mm" thickness="15*um" width="16.8*mm" mat="Epoxy"/> + <slice length="200*mm" thickness="12*um" width="16.8*mm" mat="Kapton"/> + <slice length="200*mm" thickness="15*um" width="14.8*mm" mat="Epoxy"/> --> + </flex> + <sensor n_sensors="7" gap="0.1*mm" thickness="50*um" active_length="25.6*mm" active_width="12.8*mm" dead_width="2*mm" sensor_mat="G4_Si" + deadwire_length="(7*(25.6+0.1)-0.1)*mm" deadwire_width="2*mm" deadwire_thickness="(50/10)*um" deadwire_mat="G4_Al"/> + </ladder> + </layer> + </detector> + + </detectors> + + <readouts> + <readout name="VXDCollection"> + <id>system:5,side:-2,layer:9,module:8,sensor:8,barrelside:-2</id> + </readout> + </readouts> +</lccdd> diff --git a/Detector/DetCRD/compact/CRD_o1_v03/CRD_o1_v03-onlyVXD.xml b/Detector/DetCRD/compact/CRD_o1_v03/CRD_o1_v03-onlyVXD.xml new file mode 100644 index 0000000000000000000000000000000000000000..44eb691c033035b07cf8d0a435fe8defdeac4014 --- /dev/null +++ b/Detector/DetCRD/compact/CRD_o1_v03/CRD_o1_v03-onlyVXD.xml @@ -0,0 +1,50 @@ +<?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="CRD_o1_v02" + title="CepC reference detctor with coil inside Hcal, pixel SIT and strip SET" + author="Hao Zeng" + 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="../CRD_common_v01/materials.xml"/> + <gdmlFile ref="../materials.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"/> + + <include ref="${DD4hepINSTALL}/DDDetectors/compact/detector_types.xml"/> + </define> + + <include ref="../CRD_o1_v02/CRD_Dimensions_v01_02.xml"/> + + <include ref="../CRD_common_v01/VXD_StaggeredLadder_v01_01.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/scripts/CRD_VXD_MOST2-sim.py b/Detector/DetCRD/scripts/CRD_VXD_MOST2-sim.py new file mode 100644 index 0000000000000000000000000000000000000000..5d595621af36d9284d9ac4e1f78adf85c0838f5d --- /dev/null +++ b/Detector/DetCRD/scripts/CRD_VXD_MOST2-sim.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python +from Gaudi.Configuration import * + +from Configurables import k4DataSvc +dsvc = k4DataSvc("EventDataSvc") + +from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_ + +seed = [10] +# rndmengine = HepRndm__Engine_CLHEP__RanluxEngine_() # The default engine in Gaudi +rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_("RndmGenSvc.Engine") # The default engine in Geant4 +rndmengine.SetSingleton = True +rndmengine.Seeds = seed + +rndmgensvc = RndmGenSvc("RndmGenSvc") +rndmgensvc.Engine = rndmengine.name() + +#geometry_option = "CRD_o1_v01/CRD_o1_v01.xml" +geometry_option = "CRD_o1_v03/CRD_o1_v03-onlyVXD.xml" +#... + +if not os.getenv("DETCRDROOT"): + print("Can't find the geometry. Please setup envvar DETCRDROOT." ) + sys.exit(-1) + +geometry_path = os.path.join(os.getenv("DETCRDROOT"), "compact", geometry_option) +if not os.path.exists(geometry_path): + print("Can't find the compact geometry file: %s"%geometry_path) + sys.exit(-1) + +from Configurables import GeomSvc +geosvc = GeomSvc("GeomSvc") +geosvc.compact = geometry_path + +############################################################################## +# Physics Generator +############################################################################## +from Configurables import GenAlgo +from Configurables import GtGunTool +from Configurables import StdHepRdr +from Configurables import SLCIORdr +from Configurables import HepMCRdr +from Configurables import GenPrinter +gun = GtGunTool("GtGunTool") +gun.Particles = ["mu-"] +#gun.Particles = ["nu_e"] +#gun.PositionXs = [0] +#gun.PositionYs = [0] +#gun.PositionZs = [0] +gun.EnergyMins = [100.] # GeV +gun.EnergyMaxs = [100.] # GeV +gun.ThetaMins = [0] # deg +gun.ThetaMaxs = [180] # deg +gun.PhiMins = [0] # deg +gun.PhiMaxs = [360] # deg +# stdheprdr = StdHepRdr("StdHepRdr") +# stdheprdr.Input = "/cefs/data/stdhep/CEPC250/2fermions/E250.Pbhabha.e0.p0.whizard195/bhabha.e0.p0.00001.stdhep" +# lciordr = SLCIORdr("SLCIORdr") +# lciordr.Input = "/cefs/data/stdhep/lcio250/signal/Higgs/E250.Pbbh.whizard195/E250.Pbbh_X.e0.p0.whizard195/Pbbh_X.e0.p0.00001.slcio" +# hepmcrdr = HepMCRdr("HepMCRdr") +# hepmcrdr.Input = "example_UsingIterators.txt" + +genprinter = GenPrinter("GenPrinter") + +genalg = GenAlgo("GenAlgo") +genalg.GenTools = ["GtGunTool"] +#genalg.GenTools = ["StdHepRdr"] +# genalg.GenTools = ["StdHepRdr", "GenPrinter"] +# genalg.GenTools = ["SLCIORdr", "GenPrinter"] +# genalg.GenTools = ["HepMCRdr", "GenPrinter"] + +############################################################################## +# Detector Simulation +############################################################################## +from Configurables import DetSimSvc +detsimsvc = DetSimSvc("DetSimSvc") + +from Configurables import DetSimAlg +detsimalg = DetSimAlg("DetSimAlg") +detsimalg.RandomSeeds = seed +# detsimalg.VisMacs = ["vis.mac"] +detsimalg.RunCmds = [ +# "/tracking/verbose 1", +] +detsimalg.AnaElems = [ + # example_anatool.name() +# "ExampleAnaElemTool", + "Edm4hepWriterAnaElemTool" +] +detsimalg.RootDetElem = "WorldDetElemTool" + +# output +from Configurables import PodioOutput +out = PodioOutput("outputalg") +out.filename = "CRD-skewVXD-Sim-100.root" +out.outputCommands = ["keep *"] + +# ApplicationMgr +from Configurables import ApplicationMgr +ApplicationMgr( + TopAlg = [genalg, detsimalg, out], + EvtSel = 'NONE', + EvtMax = 500, + ExtSvc = [rndmengine, rndmgensvc, dsvc, geosvc], + OutputLevel=INFO +) diff --git a/Detector/DetCRD/src/Tracker/SiTrackerStaggeredLadder_v01_geo.cpp b/Detector/DetCRD/src/Tracker/SiTrackerStaggeredLadder_v01_geo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..120bbab25b83cce80d98b0345faaa566220910c9 --- /dev/null +++ b/Detector/DetCRD/src/Tracker/SiTrackerStaggeredLadder_v01_geo.cpp @@ -0,0 +1,402 @@ +//==================================================================== +// cepcvxdgeo - CEPC vertex detector models in DD4hep +//-------------------------------------------------------------------- +// Hao Zeng, IHEP +// email: zenghao@ihep.ac.cn +// $Id$ +//==================================================================== +#include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/DD4hepUnits.h" +#include "DD4hep/DetType.h" +#include "DDRec/Surface.h" +#include "DDRec/DetectorData.h" +#include "XML/Utilities.h" +#include <cmath> + +using namespace std; + +using dd4hep::Box; +using dd4hep::DetElement; +using dd4hep::Material; +using dd4hep::Position; +using dd4hep::RotationY; +using dd4hep::RotationZYX; +using dd4hep::Transform3D; +using dd4hep::Rotation3D; +using dd4hep::Volume; +using dd4hep::_toString; +using dd4hep::rec::volSurfaceList; +using dd4hep::rec::ZPlanarData; +using dd4hep::mm; + +/** helper struct */ +struct VXD_Layer { + int n_ladders; + int n_sensors_per_ladder; + double sensor_length; + double half_z; + double sensitive_inner_radius ; + double support_inner_radius ; + double ladder_width ; + double ladder_dphi ; +}; + +//std::vector<VXD_Layer> _VXD_Layers; + +// /** helper struct */ +// struct extended_reconstruction_parameters { +// double sensor_length_mm; +// double strip_width_mm; +// double strip_length_mm; +// double strip_pitch_mm; +// double strip_angle_deg; +// }; + +//extended_reconstruction_parameters _e_r_p; + + +/** Construction of the VXD detector, ported from Mokka driver SIT_Simple_Pixel.cc + * + * Mokka History: + * Feb 7th 2011, Steve Aplin - original version + * F.Gaede, DESY, Jan 2014 - dd4hep SIT pixel + + * @author Hao Zeng, IHEP, July 2021 + */ +static dd4hep::Ref_t create_element(dd4hep::Detector& theDetector, xml_h e, dd4hep::SensitiveDetector sens) { + + xml_det_t x_det = e; + Material air = theDetector.air(); + int det_id = x_det.id(); + string name = x_det.nameStr(); + DetElement vxd(name, det_id); + + Volume envelope = dd4hep::xml::createPlacedEnvelope(theDetector, e, vxd); + dd4hep::xml::setDetectorTypeFlag(e, vxd) ; + if(theDetector.buildType()==dd4hep::BUILD_ENVELOPE) return vxd; + envelope.setVisAttributes(theDetector.visAttributes("SeeThrough")); + + sens.setType("tracker"); + std::cout << " ** building SiTrackerSkewBarrel_v01 ..." << std::endl ; + + dd4hep::rec::ZPlanarData* zPlanarData = new dd4hep::rec::ZPlanarData; + + // fetch the global parameters + + //fetch the display parameters + xml_comp_t x_display(x_det.child(_Unicode(display))); + std::string ladderVis = x_display.attr<string>(_Unicode(ladder)); + std::string supportVis = x_display.attr<string>(_Unicode(support)); + std::string flexVis = x_display.attr<string>(_Unicode(flex)); + std::string sensEnvVis = x_display.attr<string>(_Unicode(sens_env)); + std::string sensVis = x_display.attr<string>(_Unicode(sens)); + std::string deadsensVis = x_display.attr<string>(_Unicode(deadsensor)); + std::string deadwireVis = x_display.attr<string>(_Unicode(deadwire)); + + + for(xml_coll_t layer_i(x_det,_U(layer)); layer_i; ++layer_i){ + xml_comp_t x_layer(layer_i); + + dd4hep::PlacedVolume pv; + int layer_id = x_layer.attr<int>(_Unicode(layer_id)); + + std::cout << "layer_id: " << layer_id << endl; + + double sensitive_radius = x_layer.attr<double>(_Unicode(ladder_radius)); + int n_sensors_per_ladder = x_layer.attr<int>(_Unicode(n_sensors_per_side)); + int n_ladders = x_layer.attr<int>(_Unicode(n_ladders)) ; + double ladder_offset = x_layer.attr<double>(_Unicode(ladder_offset)); + double ladder_radius = sqrt(ladder_offset*ladder_offset + sensitive_radius*sensitive_radius); + double ladder_phi0 = -atan(ladder_offset/sensitive_radius); + std::cout << "ladder_radius: " << ladder_radius/mm <<" mm" << endl; + + std::cout << "sensitive_radius: " << sensitive_radius/mm << " mm" << endl; + std::cout << "n_sensors_per_ladder: " << n_sensors_per_ladder << endl; + + std::string layerName = dd4hep::_toString( layer_id , "layer_%d" ); + dd4hep::Assembly layer_assembly( layerName ) ; + pv = envelope.placeVolume( layer_assembly ) ; + dd4hep::DetElement layerDE( vxd , layerName , x_det.id() ); + layerDE.setPlacement( pv ) ; + + const double ladder_dphi = ( dd4hep::twopi / n_ladders ) ; + std::cout << "ladder_dphi: " << ladder_dphi << endl; + + //fetch the ladder parameters + xml_comp_t x_ladder(x_layer.child(_Unicode(ladder))); + // db = XMLHandlerDB(x_ladder); + + //fetch the ladder support parameters + xml_comp_t x_ladder_support(x_ladder.child(_Unicode(ladderSupport))); + double support_length = x_ladder_support.attr<double>(_Unicode(length)); + double support_thickness = x_ladder_support.attr<double>(_Unicode(thickness)); + double support_height = x_ladder_support.attr<double>(_Unicode(height)); + double support_width = x_ladder_support.attr<double>(_Unicode(width)); + Material support_mat; + if(x_ladder_support.hasAttr(_Unicode(mat))) + { + support_mat = theDetector.material(x_ladder_support.attr<string>(_Unicode(mat))); + } + else + { + support_mat = theDetector.material(x_ladder_support.materialStr()); + } + std::cout << "support_length: " << support_length/mm << " mm" << endl; + std::cout << "support_thickness: " << support_thickness/mm << " mm" << endl; + std::cout << "support_width: " << support_width/mm << " mm" << endl; + + //fetch the flex parameters + double flex_thickness(0); + double flex_width(0); + double flex_length(0); + xml_comp_t x_flex(x_ladder.child(_Unicode(flex))); + for(xml_coll_t flex_i(x_flex,_U(slice)); flex_i; ++flex_i){ + xml_comp_t x_flex_slice(flex_i); + double x_flex_slice_thickness = x_flex_slice.attr<double>(_Unicode(thickness)); + double x_flex_slice_width = x_flex_slice.attr<double>(_Unicode(width)); + double x_flex_slice_length = x_flex_slice.attr<double>(_Unicode(length)); + flex_thickness += x_flex_slice_thickness; + if (x_flex_slice_width > flex_width) flex_width = x_flex_slice_width; + if (x_flex_slice_length > flex_length) flex_length = x_flex_slice_length; + std::cout << "x_flex_slice_thickness: " << x_flex_slice_thickness/mm << " mm" << endl; + } + std::cout << "flex_thickness: " << flex_thickness/mm << " mm" << endl; + std::cout << "flex_width: " << flex_width/mm << " mm" << endl; + std::cout << "flex_length: " << flex_length/mm << " mm" << endl; + + //fetch the sensor parameters + xml_comp_t x_sensor(x_ladder.child(_Unicode(sensor))); + int n_sensors_per_side = x_sensor.attr<int>(_Unicode(n_sensors)); + double dead_gap = x_sensor.attr<double>(_Unicode(gap)); + double sensor_thickness = x_sensor.attr<double>(_Unicode(thickness)); + double sensor_active_len = x_sensor.attr<double>(_Unicode(active_length)); + double sensor_active_width = x_sensor.attr<double>(_Unicode(active_width)); + double sensor_dead_width = x_sensor.attr<double>(_Unicode(dead_width)); + double sensor_deadwire_length = x_sensor.attr<double>(_Unicode(deadwire_length)); + double sensor_deadwire_width = x_sensor.attr<double>(_Unicode(deadwire_width)); + double sensor_deadwire_thickness = x_sensor.attr<double>(_Unicode(deadwire_thickness)); + Material sensor_mat = theDetector.material(x_sensor.attr<string>(_Unicode(sensor_mat))); + Material sensor_deadwire_mat = theDetector.material(x_sensor.attr<string>(_Unicode(deadwire_mat))); + + std::cout << "n_sensors_per_side: " << n_sensors_per_side << endl; + std::cout << "dead_gap: " << dead_gap/mm << " mm" << endl; + std::cout << "sensor_thickness: " << sensor_thickness/mm << " mm" << endl; + std::cout << "sensor_active_len: " << sensor_active_len/mm << " mm" << endl; + std::cout << "sensor_active_width: " << sensor_active_width/mm << " mm" << endl; + std::cout << "sensor_dead_width: " << sensor_dead_width/mm << " mm" << endl; + + //create ladder logical volume + Box LadderSolid((support_height+2*sensor_thickness+2*flex_thickness)/2.0, + support_width / 2.0, support_length / 2.0); + Volume LadderLogical(name + dd4hep::_toString( layer_id, "_LadderLogical_%02d"), + LadderSolid, air); + // create flex envelope logical volume + Box FlexEnvelopeSolid(flex_thickness / 2.0, flex_width / 2.0, flex_length / 2.0); + Volume FlexEnvelopeLogical(name + dd4hep::_toString( layer_id, "_FlexEnvelopeLogical_%02d"), FlexEnvelopeSolid, air); + FlexEnvelopeLogical.setVisAttributes(theDetector.visAttributes("SeeThrough")); + //vxd.setVisAttributes(theDetector, flexVis, FlexEnvelopeLogical); + + //create the flex layers inside the flex envelope + double flex_start_height(-flex_thickness/2.); + int index = 0; + for(xml_coll_t flex_i(x_flex,_U(slice)); flex_i; ++flex_i){ + xml_comp_t x_flex_slice(flex_i); + double x_flex_slice_thickness = x_flex_slice.attr<double>(_Unicode(thickness)); + double x_flex_slice_width = x_flex_slice.attr<double>(_Unicode(width)); + double x_flex_slice_length = x_flex_slice.attr<double>(_Unicode(length)); + Material x_flex_slice_mat; + if(x_flex_slice.hasAttr(_Unicode(mat))) + { + x_flex_slice_mat = theDetector.material(x_flex_slice.attr<string>(_Unicode(mat))); + } + else + { + x_flex_slice_mat = theDetector.material(x_flex_slice.materialStr()); + } + // Material x_flex_slice_mat = theDetector.material(x_flex_slice.attr<string>(_Unicode(mat))); + Box FlexLayerSolid(x_flex_slice_thickness/2.0, x_flex_slice_width/2.0, x_flex_slice_length/2.0); + Volume FlexLayerLogical(name + dd4hep::_toString( layer_id, "_FlexLayerLogical_%02d") + dd4hep::_toString( index, "index_%02d"), FlexLayerSolid, x_flex_slice_mat); + FlexLayerLogical.setVisAttributes(theDetector.visAttributes(flexVis)); + double flex_slice_height = flex_start_height + x_flex_slice_thickness/2.; + pv = FlexEnvelopeLogical.placeVolume(FlexLayerLogical, Position(flex_slice_height, 0., 0.)); + std::cout << "flex thickness = " << x_flex_slice_thickness << std::endl; + std::cout << "flex width = " << x_flex_slice_width << std::endl; + std::cout << "flex length = " << x_flex_slice_length << std::endl; + // std::cout << "flex material: " << x_flex_slice_mat << std::endl; + flex_start_height += x_flex_slice_thickness; + index++; + } + + //place the flex envelope inside the ladder envelope + pv = LadderLogical.placeVolume(FlexEnvelopeLogical, Position((support_height + flex_thickness) / 2.0, 0., 0.)); //top side + //define the transformation3D(only need a combination of translation and rotation) + Transform3D tran_mirro(RotationZYX(0., dd4hep::twopi/2.0, 0.), Position(-(support_height + flex_thickness) / 2.0, 0., 0.)); + pv = LadderLogical.placeVolume(FlexEnvelopeLogical, tran_mirro); //bottom side + + //create sensor envelope logical volume + Box SensorTopEnvelopeSolid(sensor_thickness / 2.0, support_width / 2.0, support_length / 2.0); + Volume SensorTopEnvelopeLogical(name + dd4hep::_toString( layer_id, "_SensorEnvelopeLogical_%02d"), SensorTopEnvelopeSolid, air); + Box SensorBottomEnvelopeSolid(sensor_thickness / 2.0, support_width / 2.0, support_length / 2.0); + Volume SensorBottomEnvelopeLogical(name + dd4hep::_toString( layer_id, "_SensorEnvelopeLogical_%02d"), SensorBottomEnvelopeSolid, air); + SensorTopEnvelopeLogical.setVisAttributes(theDetector.visAttributes(sensEnvVis)); + + //create sensor logical volume + Box SensorSolid(sensor_thickness / 2.0, sensor_active_width / 2.0, sensor_active_len / 2.0); + Volume SensorLogical(name + dd4hep::_toString( layer_id, "_SensorLogical_%02d"), SensorSolid, sensor_mat); + SensorLogical.setSensitiveDetector(sens); + //vxd.setVisAttributes(theDetector, deadsensVis, SensorDeadLogical); + SensorLogical.setVisAttributes(theDetector.visAttributes(sensVis)); + + //create dead sensor logical volume + Box SensorDeadSolid(sensor_thickness / 2.0, sensor_dead_width / 2.0, sensor_active_len / 2.0); + Volume SensorDeadLogical(name + dd4hep::_toString( layer_id, "_SensorDeadLogical_%02d"), SensorDeadSolid, sensor_mat); + SensorDeadLogical.setVisAttributes(theDetector.visAttributes(deadsensVis)); + + //create dead wire logical volume + Box SensorDeadWireSolid(sensor_deadwire_thickness / 2.0, sensor_deadwire_width / 2.0, sensor_deadwire_length / 2.0); + Volume SensorDeadWireLogical(name + dd4hep::_toString( layer_id, "_SensorDeadWireLogical_%02d"), SensorDeadWireSolid, sensor_deadwire_mat); + SensorDeadWireLogical.setVisAttributes(theDetector.visAttributes(deadwireVis)); + + //place the dead wire in the sensor envelope + // pv = SensorTopEnvelopeLogical.placeVolume(SensorDeadWireLogical, Position(0.0, (sensor_active_width-support_width/2.0) + sensor_dead_width/2.0 + sensor_deadwire_width/2.0, 0.0)); + // pv = SensorBottomEnvelopeLogical.placeVolume(SensorDeadWireLogical, Position(0.0, (sensor_active_width-support_width/2.0) + sensor_dead_width/2.0 + sensor_deadwire_width/2.0, 0.0)); + pv = SensorTopEnvelopeLogical.placeVolume(SensorDeadWireLogical, Position(0.0, (-support_width/2.0) + (sensor_deadwire_width/2.0), 0.0)); + pv = SensorBottomEnvelopeLogical.placeVolume(SensorDeadWireLogical, Position(0.0, (-support_width/2.0) + (sensor_deadwire_width/2.0), 0.0)); + + // place the active sensor and dead sensor inside the sensor envelope + std::vector<dd4hep::PlacedVolume> TopSensor_pv; + std::vector<dd4hep::PlacedVolume> BottomSensor_pv; + for(int isensor=0; isensor < n_sensors_per_side; ++isensor){ + double sensor_total_z = n_sensors_per_side*sensor_active_len + dead_gap*(n_sensors_per_side-1); + double xpos = 0.0; + double ypos_active = (support_width/2.0) - (sensor_active_width/2.0); + double ypos_dead = (-support_width/2.0) + sensor_deadwire_width + (sensor_dead_width/2.0); + double zpos = -sensor_total_z/2.0 + sensor_active_len/2.0 + isensor*(sensor_active_len + dead_gap); + pv = SensorTopEnvelopeLogical.placeVolume(SensorLogical, Position(xpos,ypos_active,zpos)); + //pv.addPhysVolID("topsensor", isensor ) ; + pv.addPhysVolID("sensor", isensor ).addPhysVolID("barrelside", 1) ; + TopSensor_pv.push_back(pv); + pv = SensorBottomEnvelopeLogical.placeVolume(SensorLogical, Position(xpos,ypos_active,zpos)); + //pv.addPhysVolID("bottomsensor", isensor ) ; + pv.addPhysVolID("sensor", isensor ).addPhysVolID("barrelside", -1) ; + BottomSensor_pv.push_back(pv); + pv = SensorTopEnvelopeLogical.placeVolume(SensorDeadLogical, Position(xpos,ypos_dead,zpos)); + pv = SensorBottomEnvelopeLogical.placeVolume(SensorDeadLogical, Position(xpos,ypos_dead,zpos)); + + } + //place the sensor envelope inside the ladder envelope + pv = LadderLogical.placeVolume(SensorTopEnvelopeLogical, + Position(support_height/2.0 + flex_thickness + sensor_thickness/2.0, 0., 0.));//top-side sensors + Transform3D tran_sen(RotationZYX(0., dd4hep::twopi/2.0, 0.), Position(-(support_height/2.0 + flex_thickness + sensor_thickness/2.0), 0., 0.)); + pv = LadderLogical.placeVolume(SensorBottomEnvelopeLogical,tran_sen);//bottom-side sensors + + //create the ladder support envelope + Box LadderSupportEnvelopeSolid(support_height/2.0, support_width/2.0, support_length/2.0); + Volume LadderSupportEnvelopeLogical(name + _toString( layer_id,"_SupEnvLogical_%02d"), LadderSupportEnvelopeSolid, air); + vxd.setVisAttributes(theDetector, "seeThrough", LadderSupportEnvelopeLogical); + + //create ladder support volume + Box LadderSupportSolid(support_thickness / 2.0 , support_width / 2.0 , support_length / 2.0); + Volume LadderSupportLogical(name + _toString( layer_id,"_SupLogical_%02d"), LadderSupportSolid, support_mat); + LadderSupportLogical.setVisAttributes(theDetector.visAttributes(supportVis)); + + //vxd.setVisAttributes(theDetector, sensVis, SensorLogical); + // vxd.setVisAttributes(theDetector, sensEnvVis, SensorBottomEnvelopeLogical); + // vxd.setVisAttributes(theDetector, ladderVis, LadderLogical); + + pv = LadderSupportEnvelopeLogical.placeVolume(LadderSupportLogical); + pv = LadderLogical.placeVolume(LadderSupportEnvelopeLogical); + + for(int i = 0; i < n_ladders; i++){ + std::stringstream ladder_enum; + ladder_enum << "vxt_ladder_" << layer_id << "_" << i; + DetElement ladderDE(layerDE, ladder_enum.str(), x_det.id()); + std::cout << "start building " << ladder_enum.str() << ":" << endl; + + //====== create the meassurement surface =================== + dd4hep::rec::Vector3D o(0,0,0); + dd4hep::rec::Vector3D u( 0., 0., 1.); + dd4hep::rec::Vector3D v( 0., 1., 0.); + dd4hep::rec::Vector3D n( 1., 0., 0.); + double inner_thick_top = sensor_thickness/2.0; + double outer_thick_top = support_height/2.0 + flex_thickness + sensor_thickness/2.0; + double inner_thick_bottom = support_height/2.0 + flex_thickness + sensor_thickness/2.0; + double outer_thick_bottom = sensor_thickness/2.0; + dd4hep::rec::VolPlane surfTop( SensorLogical , + dd4hep::rec::SurfaceType(dd4hep::rec::SurfaceType::Sensitive), + inner_thick_top, outer_thick_top , u,v,n,o ) ; + dd4hep::rec::VolPlane surfBottom( SensorLogical , + dd4hep::rec::SurfaceType(dd4hep::rec::SurfaceType::Sensitive), + inner_thick_bottom, outer_thick_bottom, u,v,n,o ) ; + + + for(int isensor=0; isensor < n_sensors_per_side; ++isensor){ + std::stringstream topsensor_str; + std::stringstream bottomsensor_str; + topsensor_str << ladder_enum.str() << "_top_" << isensor; + // std::cout << "\tstart building " << topsensor_str.str() << ":" << endl; + bottomsensor_str << ladder_enum.str() << "_bottom_" << isensor; + // std::cout << "\tstart building " << bottomsensor_str.str() << ":" << endl; + DetElement topsensorDE(ladderDE, topsensor_str.str(), x_det.id()); + DetElement bottomsensorDE(ladderDE, bottomsensor_str.str(), x_det.id()); + topsensorDE.setPlacement(TopSensor_pv[isensor]); + volSurfaceList(topsensorDE)->push_back(surfTop); + // std::cout << "\t" << topsensor_str.str() << " done." << endl; + bottomsensorDE.setPlacement(BottomSensor_pv[isensor]); + // std::cout << "\t" << bottomsensor_str.str() << " done." << endl; + volSurfaceList(bottomsensorDE)->push_back(surfBottom); + } + Transform3D tr (RotationZYX(ladder_dphi*i,0.,0.),Position(ladder_radius*cos(ladder_phi0+ladder_dphi*i), ladder_radius*sin(ladder_phi0+ladder_dphi*i), 0.)); + pv = layer_assembly.placeVolume(LadderLogical,tr); + pv.addPhysVolID("layer", layer_id ).addPhysVolID("module", i ) ; + ladderDE.setPlacement(pv); + std::cout << ladder_enum.str() << " done." << endl; + + } + + // package the reconstruction data + dd4hep::rec::ZPlanarData::LayerLayout topLayer; + dd4hep::rec::ZPlanarData::LayerLayout bottomLayer; + + topLayer.ladderNumber = n_ladders; + topLayer.phi0 = 0.; + topLayer.sensorsPerLadder = n_sensors_per_side; + topLayer.lengthSensor = sensor_active_len; + topLayer.distanceSupport = sensitive_radius; + topLayer.thicknessSupport = support_thickness / 2.0; + topLayer.offsetSupport = ladder_offset; + topLayer.widthSupport = support_width; + topLayer.zHalfSupport = support_length / 2.0; + topLayer.distanceSensitive = sensitive_radius + support_thickness / 2.0; + topLayer.thicknessSensitive = sensor_thickness; + topLayer.offsetSensitive = ladder_offset; + topLayer.widthSensitive = sensor_active_width; + topLayer.zHalfSensitive = (n_sensors_per_side*(sensor_active_len + dead_gap) - dead_gap) / 2.0; + + bottomLayer.ladderNumber = n_ladders; + bottomLayer.phi0 = 0.; + bottomLayer.sensorsPerLadder = n_sensors_per_side; + bottomLayer.lengthSensor = sensor_active_len; + bottomLayer.distanceSupport = sensitive_radius - support_thickness / 2.0; + bottomLayer.thicknessSupport = support_thickness / 2.0; + bottomLayer.offsetSupport = ladder_offset; + bottomLayer.widthSupport = support_width; + bottomLayer.zHalfSupport = support_length / 2.0; + bottomLayer.distanceSensitive = sensitive_radius - support_thickness / 2.0 - sensor_thickness; + bottomLayer.thicknessSensitive = sensor_thickness; + bottomLayer.offsetSensitive = ladder_offset; + bottomLayer.widthSensitive = sensor_active_width; + bottomLayer.zHalfSensitive = (n_sensors_per_side*(sensor_active_len + dead_gap) - dead_gap) / 2.0; + + zPlanarData->layers.push_back(topLayer); + zPlanarData->layers.push_back(bottomLayer); + } + std::cout << (*zPlanarData) << endl; + vxd.addExtension< ZPlanarData >(zPlanarData); + if ( x_det.hasAttr(_U(combineHits)) ) { + vxd.setCombineHits(x_det.attr<bool>(_U(combineHits)),sens); + } + std::cout << "vxd done." << endl; + return vxd; +} +DECLARE_DETELEMENT(SiTrackerStaggeredLadder_v01,create_element)