1 #include "DD4hep/DetFactoryHelper.h"
2 #include "DD4hep/Printout.h"
4 #include "DDRec/Surface.h"
5 #include "DDRec/DetectorData.h"
11 using namespace dd4hep::rec;
30 typedef vector<PlacedVolume> Placements;
33 Material air = lcdd.air();
34 Material carbon = lcdd.material(
"CarbonFiber");
35 Material silicon = lcdd.material(
"SiliconOxide");
36 int det_id = x_det.id();
37 string det_name = x_det.nameStr();
40 double inner_r = x_det.attr<
double>( _Unicode(inner_r) ) ;
41 DetElement sdet(det_name, det_id);
42 Assembly assembly(det_name+
"_assembly");
45 sens.setType(
"tracker");
46 string module_name =
"VtxBarrelModule";
48 double init_layer_radius = inner_r;
52 std::vector<int> N_z_modules = { 1, 1, 1 };
53 std::vector<int> N_phi_modules = { 8, 14, 20 };
55 double extra_module_width = 0.2*dd4hep::cm;
56 double module_x = (2.0*TMath::Pi()*init_layer_radius)/(N_phi_modules.at(0)*2.0);
57 double module_y = 100.0*dd4hep::cm/2.0;
58 double module_z = 2.0*dd4hep::mm;
60 Position offset{ 0.0, 0.0, 1.0*dd4hep::m };
63 std::vector<double> delta_phi_layer;
64 std::for_each(N_phi_modules.begin(), N_phi_modules.end(),
65 [&](
auto const& n){ delta_phi_layer.push_back( TMath::Pi()/double(n) ); });
68 std::vector<double> layer_radius;
69 std::for_each(delta_phi_layer.begin(), delta_phi_layer.end(),
70 [&](
auto const& p){ layer_radius.push_back( module_x/p ); });
72 Volume module_vol(module_name, Box(module_x+extra_module_width, module_y-1.0*dd4hep::cm, module_z), carbon);
73 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);
75 PlacedVolume sensitive_pv = module_vol.placeVolume( sense_vol );
76 sensitive_pv.addPhysVolID(
"sensor", 1 );
79 Vector3D u( 1. , 0. , 0. ) ;
80 Vector3D v( 0. , 1. , 0. ) ;
81 Vector3D n( 0. , 0. , 1. ) ;
82 Vector3D o( 0. , 0. , 0. ) ;
88 double inner_thickness = module_z/2.0;
89 double outer_thickness = module_z/2.0;
91 SurfaceType type( SurfaceType::Sensitive ) ;
92 VolPlane surf( sense_vol, type, inner_thickness , outer_thickness , u,v,n,o ) ;
96 sens.setType(
"tracker");
97 sense_vol.setSensitiveDetector(sens);
99 ROOT::Math::RotationX Rx( TMath::Pi()/2.0 );
100 ROOT::Math::RotationZ Rz( TMath::Pi()/2.0 );
102 for(
int i_layer=0; i_layer<N_layers; i_layer++){
104 int layer_id = i_layer + 1;
105 string layer_name = std::string(
"layer") + std::to_string(layer_id) ;
107 double phi_tilt = 180.0*dd4hep::degree/(double(N_phi_modules.at(i_layer))+3.0);
109 std::cout <<
"Radius of layer " << layer_id <<
" is " << layer_radius.at(i_layer) << endl;
110 DetElement layer_DE( sdet, _toString(layer_id,
"layer%d"), layer_id );
111 Assembly layer_assembly( layer_name+
"_assembly" );
112 pv = assembly.placeVolume( layer_assembly );
113 pv.addPhysVolID(
"layer", layer_id );
114 layer_DE.setPlacement(pv);
115 layer_DE.setAttributes(lcdd, layer_assembly,
"",
"",
"SiVertexLayerVis");
118 for (
int i_phi = 0; i_phi < N_phi_modules.at(i_layer); i_phi++){
120 double phi = phi0 + i_phi*2.0*delta_phi_layer.at(i_layer);
123 ROOT::Math::Polar3DVector rho_module( layer_radius.at(i_layer), TMath::Pi()/2.0, phi );
125 double z0 = -1.0*module_y*double(N_z_modules.at(i_layer)) + module_y;
126 double dz = 2.0*module_y;
129 for (
int i_Z = 0; i_Z < N_z_modules.at(i_layer); i_Z++){
131 ROOT::Math::XYZVector z_displacement(0.0, 0.0, z0 +
double(i_Z)*dz);
133 int i_module = 1 + i_Z + i_phi*N_z_modules.at(i_layer);
134 string a_module_name = _toString(i_module,
"module%d");
136 Transform3D tr( RotationZ(phi_tilt)*RotationZ(phi)*Rx, Rz*rho_module + z_displacement);
138 DetElement module_DE(layer_DE, a_module_name, i_module);
139 module_vol.setVisAttributes(lcdd, x_det.visStr());
140 pv = layer_assembly.placeVolume( module_vol, tr );
141 pv.addPhysVolID(
"module", i_module );
142 module_DE.setPlacement(pv);
144 DetElement module_sense_DE( module_DE, std::string(
"sense_DE")+std::to_string(i_module), i_module );
145 module_sense_DE.setPlacement( sensitive_pv );
151 sdet.setAttributes(lcdd, assembly,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
152 assembly.setVisAttributes(lcdd.invisible());
154 pv = lcdd.pickMotherVolume(sdet).placeVolume(assembly);
155 pv.addPhysVolID(
"system", det_id);
156 pv.addPhysVolID(
"barrel", 1);
157 sdet.setPlacement(pv);
159 assembly->GetShape()->ComputeBBox() ;