ForwardPlaneTracker_geo.cpp
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
2 
3 #include "DDRec/Surface.h"
4 #include "DDRec/DetectorData.h"
5 #include <exception>
6 
7 using namespace dd4hep;
8 using namespace dd4hep::rec ;
9 //using namespace DDSurfaces ;
10 
27 static Ref_t create_element(Detector& lcdd, xml_h e, SensitiveDetector sens) {
28 
29  xml_det_t x_det = e;
30  std::string name = x_det.nameStr();
31 
32  Assembly assembly( name+"_assembly" );
33 
34  // The top level detector element that this function returns
35  DetElement tracker( name, x_det.id() ) ;
36 
37  //DDRec::ZPlanarData* zPlanarData = new DDRec::ZPlanarData ;
38  // Loop over layer elements in xml
39 
40  for(xml_coll_t c(e, _U(layer) ); c; ++c) {
41 
42  xml_comp_t alayer( c );
43 
44  // Parse the xml elements and get the required information
45 
46  // child elements: ladder and sensitive
47  xml_comp_t z_sensitive( alayer.child( _U(sensitive) ));
48  xml_comp_t z_module( alayer.child( _U(module) ));
49 
50  int layer_id = alayer.id();
51  double zoffset = alayer.attr<double>( _Unicode(z_offset) ) ;
52 
53  double supp_x_half = z_module.attr<double>( _Unicode(x_half) );
54  double supp_y_half = z_module.attr<double>( _Unicode(y_half));
55  double supp_thickness = z_module.attr<double>( _Unicode(thickness));
56  double sens_thickness = z_sensitive.attr<double>( _Unicode(thickness));
57 
58  double supp_gap_half_width = 1.5; //cm
59 
60  std::string supp_matS = z_module.materialStr() ;
61  std::string sens_matS = z_sensitive.materialStr() ;
62 
63  Material supp_mat = lcdd.material( supp_matS ) ;
64  Material sens_mat = lcdd.material( sens_matS ) ;
65 
66  std::cout << supp_matS << std::endl;
67  std::cout << sens_matS << std::endl;
68 
69  std::string layername = name + _toString(layer_id, "_layer%d");
70 
71  DetElement layerDE( tracker , _toString(layer_id, "layer_%d"), x_det.id() );
72 
73  //--------------------------------
74 
75  Box supp_box( supp_x_half, supp_y_half, supp_thickness/2.0 );
76  // There will be four sensitive elements for each layer
77  Box sens_box( supp_x_half/2.0-supp_gap_half_width, supp_y_half/2.0-supp_gap_half_width, sens_thickness/2.0 );
78 
79  Volume support_vol( layername+"_supp", supp_box, supp_mat );
80  Volume sensor_vol( layername+"_sens", sens_box, sens_mat );
81 
82  std::string supp_vis = z_module.visStr() ;
83  std::string sens_vis = z_sensitive.visStr() ;
84 
85  // -------- create a measurement plane for the tracking surface attched to the sensitive volume -----
86  Vector3D u( 1. , 0. , 0. ) ;
87  Vector3D v( 0. , 1. , 0. ) ;
88  Vector3D n( 0. , 0. , 1. ) ;
89  //Vector3D o( 0. , 0. , 0. ) ;
90 
91  // compute the inner and outer thicknesses that need to be assigned to the tracking surface
92  // depending on wether the support is above or below the sensor
93  // The tracking surface is used in reconstruction. It provides material thickness
94  // and radation lengths needed for various algorithms, routines, etc.
95  double inner_thickness = supp_thickness/2.0;
96  double outer_thickness = supp_thickness/2.0;
97 
98  SurfaceType type( SurfaceType::Sensitive ) ;
99  VolPlane surf( sensor_vol, type, inner_thickness , outer_thickness , u,v,n ) ; //,o ) ;
100 
101  //--------------------------------------------
102 
103  sens.setType("tracker");
104  sensor_vol.setSensitiveDetector(sens);
105 
106  sensor_vol.setAttributes( lcdd, x_det.regionStr(), x_det.limitsStr(), sens_vis );
107  support_vol.setAttributes( lcdd, x_det.regionStr(), x_det.limitsStr(), supp_vis );
108 
109 
110 
111  // /* pv = */layer_assembly.placeVolume(support_vol,Transform3D(rot, Position((radius+lthick/2.)*cos(phi) - offset*sin(phi),
112  // (radius+lthick/2.)*sin(phi) + offset*cos(phi),
113  // 0. ) ));
114 
115  // place the layer
116  PlacedVolume support_pv = assembly.placeVolume( support_vol, Position(0,0, zoffset) );
117  support_pv.addPhysVolID("layer", layer_id );
118  layerDE.setPlacement( support_pv ) ;
119 
120  for(int i_module=0; i_module<4; i_module++) {
121 
122  DetElement sensDE( layerDE , _toString(i_module, "module_%d"), i_module );
123  double xsign = (i_module%2==0 ? -1.0 : 1.0);
124  double ysign = (i_module/2==0 ? -1.0 : 1.0);
125  Position module_postion(xsign*supp_x_half/2.0, ysign*supp_y_half/2.0, 0.0);
126 
127  // Put the sensitve volume in the support volume
128  PlacedVolume pv = support_vol.placeVolume(sensor_vol, module_postion);
129  pv.addPhysVolID("module", i_module );
130  sensDE.setPlacement( pv );
131  for(const auto& id : pv.volIDs()){
132  std::cout << " id : " << id.second << std::endl;
133  }
134  }
135  }
136 
137  //tracker.addExtension< DDRec::ZPlanarData >( zPlanarData ) ;
138 
139  Volume mother = lcdd.pickMotherVolume( tracker ) ;
140  PlacedVolume mother_pv = mother.placeVolume(assembly);
141  mother_pv.addPhysVolID( "system", x_det.id() );
142  tracker.setPlacement(mother_pv);
143 
144  assembly->GetShape()->ComputeBBox() ;
145 
146  return tracker;
147 }
149 DECLARE_DETELEMENT(ForwardPlaneTracker,create_element)
Detector
Definition: DDG4.py:69
Namespace for the AIDA detector description toolkit.
static Ref_t create_element(Detector &lcdd, xml_h e, SensitiveDetector sens)