SiliconTrackerBarrel_geo.cpp
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
2 #include "DD4hep/Printout.h"
3 #include "TMath.h"
4 #include "DDRec/Surface.h"
5 #include "DDRec/DetectorData.h"
6 
7 using namespace std;
8 using namespace dd4hep;
9 using namespace dd4hep::rec;
10 //using namespace dd4hep::Geometry;
11 //using namespace DD4hep::DDRec;
12 //using namespace DDSurfaces;
13 
14 static Ref_t create_detector(Detector& lcdd, xml_h e, SensitiveDetector sens)
15 {
16  typedef vector<PlacedVolume> Placements;
17 
18  xml_det_t x_det = e;
19  Material air = lcdd.air();
20  Material carbon = lcdd.material("CarbonFiber");
21  Material silicon = lcdd.material("SiliconOxide");
22  int det_id = x_det.id();
23  string det_name = x_det.nameStr();
24  PlacedVolume pv;
25 
26  double inner_r = x_det.attr<double>( _Unicode(inner_r) ) ;
27  DetElement sdet(det_name, det_id);
28  Assembly assembly(det_name+"_assembly");
29  //printout(INFO, "SiTrackerBarrelJLEIC", "In the Create Detector Function");
30 
31  sens.setType("tracker");
32  string module_name = "VtxBarrelModule";
33 
34  double init_layer_radius = inner_r;//380.0*dd4hep::mm;
35 
36  // Critical parameters
37  int N_layers = 3; // Total number of layers
38  std::vector<int> N_z_modules = { 1, 1, 1 };//, 1 }; // Number of modules in Z
39  std::vector<int> N_phi_modules = { 8, 14, 20 };//, 20 }; // Number of modules in Z
40 
41  double extra_module_width = 0.2*dd4hep::cm;
42  double module_x = (2.0*TMath::Pi()*init_layer_radius)/(N_phi_modules.at(0)*2.0);
43  double module_y = 100.0*dd4hep::cm/2.0;
44  double module_z = 2.0*dd4hep::mm;
45 
46  Position offset{ 0.0, 0.0, 1.0*dd4hep::m };
47 
48  // For each layer, calculate the delta_phi covered by each module
49  std::vector<double> delta_phi_layer;
50  std::for_each(N_phi_modules.begin(), N_phi_modules.end(),
51  [&](auto const& n){ delta_phi_layer.push_back( TMath::Pi()/double(n) ); });
52 
53  // Calculate the radius for each layer
54  std::vector<double> layer_radius;
55  std::for_each(delta_phi_layer.begin(), delta_phi_layer.end(),
56  [&](auto const& p){ layer_radius.push_back( module_x/p ); });
57 
58  Volume module_vol(module_name, Box(module_x+extra_module_width, module_y-1.0*dd4hep::cm, module_z), carbon);
59  Volume sense_vol("sense_volume", Box(module_x+extra_module_width-1.0*dd4hep::mm, module_y-2.0*dd4hep::cm, 0.5*dd4hep::mm), silicon);
60 
61  PlacedVolume sensitive_pv = module_vol.placeVolume( sense_vol );
62  sensitive_pv.addPhysVolID( "sensor", 1 );
63 
64  // -------- create a measurement plane for the tracking surface attched to the sensitive volume -----
65  Vector3D u( 1. , 0. , 0. ) ;
66  Vector3D v( 0. , 1. , 0. ) ;
67  Vector3D n( 0. , 0. , 1. ) ;
68  Vector3D o( 0. , 0. , 0. ) ;
69 
70  // compute the inner and outer thicknesses that need to be assigned to the tracking surface
71  // depending on wether the support is above or below the sensor
72  // The tracking surface is used in reconstruction. It provides material thickness
73  // and radation lengths needed for various algorithms, routines, etc.
74  double inner_thickness = module_z/2.0;
75  double outer_thickness = module_z/2.0;
76 
77  SurfaceType type( SurfaceType::Sensitive ) ;
78  VolPlane surf( sense_vol, type, inner_thickness , outer_thickness , u,v,n,o ) ;
79 
80  //--------------------------------------------
81 
82  sens.setType("tracker");
83  sense_vol.setSensitiveDetector(sens);
84 
85  ROOT::Math::RotationX Rx( TMath::Pi()/2.0 );
86  ROOT::Math::RotationZ Rz( TMath::Pi()/2.0 );
87 
88  for(int i_layer=0; i_layer<N_layers; i_layer++){
89 
90  int layer_id = i_layer + 1;
91  string layer_name = std::string("layer") + std::to_string(layer_id) ;
92  double phi0 = 0;
93  double phi_tilt = 180.0*dd4hep::degree/(double(N_phi_modules.at(i_layer))+3.0);
94 
95  std::cout << "Radius of layer " << layer_id << " is " << layer_radius.at(i_layer) << endl;
96  DetElement layer_DE( sdet, _toString(layer_id,"layer%d"), layer_id );
97  Assembly layer_assembly( layer_name+"_assembly" );
98  pv = assembly.placeVolume( layer_assembly );
99  pv.addPhysVolID( "layer", layer_id );
100  layer_DE.setPlacement(pv);
101  layer_DE.setAttributes(lcdd, layer_assembly, "", "", "SiVertexLayerVis");
102 
103  // Loop over the number of modules in phi.
104  for (int i_phi = 0; i_phi < N_phi_modules.at(i_layer); i_phi++){
105 
106  double phi = phi0 + i_phi*2.0*delta_phi_layer.at(i_layer);
107 
108  // The radial displacement of the module
109  ROOT::Math::Polar3DVector rho_module( layer_radius.at(i_layer), TMath::Pi()/2.0, phi );
110 
111  double z0 = -1.0*module_y*double(N_z_modules.at(i_layer)) + module_y;
112  double dz = 2.0*module_y;
113 
114  // Loop over the number of modules in z.
115  for (int i_Z = 0; i_Z < N_z_modules.at(i_layer); i_Z++){
116 
117  ROOT::Math::XYZVector z_displacement(0.0, 0.0, z0 + double(i_Z)*dz);
118 
119  int i_module = 1 + i_Z + i_phi*N_z_modules.at(i_layer);
120  string a_module_name = _toString(i_module, "module%d");
121 
122  Transform3D tr( RotationZ(phi_tilt)*RotationZ(phi)*Rx, Rz*rho_module + z_displacement);
123 
124  DetElement module_DE(layer_DE, a_module_name, i_module);
125  module_vol.setVisAttributes(lcdd, x_det.visStr());
126  pv = layer_assembly.placeVolume( module_vol, tr );
127  pv.addPhysVolID( "module", i_module );
128  module_DE.setPlacement(pv);
129 
130  DetElement module_sense_DE( module_DE, std::string("sense_DE")+std::to_string(i_module), i_module );
131  module_sense_DE.setPlacement( sensitive_pv );
132 
133  }
134  }
135  }
136 
137  sdet.setAttributes(lcdd, assembly,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
138  assembly.setVisAttributes(lcdd.invisible());
139 
140  pv = lcdd.pickMotherVolume(sdet).placeVolume(assembly);
141  pv.addPhysVolID("system", det_id); // Set the subdetector system ID.
142  pv.addPhysVolID("barrel", 1); // Flag this as a barrel subdetector.
143  sdet.setPlacement(pv);
144 
145  assembly->GetShape()->ComputeBBox() ;
146 
147  return sdet;
148 }
149 
150 DECLARE_DETELEMENT(SiliconTrackerBarrel, create_detector)
static Ref_t create_detector(Detector &lcdd, xml_h e, SensitiveDetector sens)
Detector
Definition: DDG4.py:69
Namespace for the AIDA detector description toolkit.