PolyhedraEndcapCalorimeter2_geo.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 //
14 // Specialized generic detector constructor
15 //
16 //==========================================================================
17 #include "DD4hep/DetFactoryHelper.h"
18 #include "XML/Layering.h"
19 
20 using namespace std;
21 using namespace dd4hep;
22 using namespace dd4hep::detail;
23 
24 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens) {
25  xml_det_t x_det = e;
26  xml_dim_t dim = x_det.dimensions();
27  int det_id = x_det.id();
28  bool reflect = x_det.reflect(true);
29  string det_name = x_det.nameStr();
30  Material air = description.air();
31  int numsides = dim.numsides();
32  double rmin = dim.rmin();
33  double rmax = dim.rmax()*std::cos(M_PI/numsides);
34  double zmin = dim.zmin();
35  Layering layering(x_det);
36  double totalThickness = layering.totalThickness();
37  Volume endcapVol("endcap",PolyhedraRegular(numsides,rmin,rmax,totalThickness),air);
38  DetElement endcap("endcap",det_id);
39 
40  int l_num = 1;
41  int layerType = 0;
42  double layerZ = -totalThickness/2;
43 
44  endcapVol.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
45 
46  for(xml_coll_t xc(x_det,_U(layer)); xc; ++xc) {
47  xml_comp_t x_layer = xc;
48  double l_thick = layering.layer(l_num-1)->thickness();
49  string l_name = _toString(layerType,"layer%d");
50  int l_repeat = x_layer.repeat();
51  Volume l_vol(l_name,PolyhedraRegular(numsides,rmin,rmax,l_thick),air);
52  vector<PlacedVolume> sensitives;
53 
54  int s_num = 1;
55  double sliceZ = -l_thick/2;
56  for(xml_coll_t xs(x_layer,_U(slice)); xs; ++xs) {
57  xml_comp_t x_slice = xs;
58  string s_name = _toString(s_num,"slice%d");
59  double s_thick = x_slice.thickness();
60  Material s_mat = description.material(x_slice.materialStr());
61  Volume s_vol(s_name,PolyhedraRegular(numsides,rmin,rmax,s_thick),s_mat);
62 
63  s_vol.setVisAttributes(description.visAttributes(x_slice.visStr()));
64  sliceZ += s_thick/2;
65  PlacedVolume s_phv = l_vol.placeVolume(s_vol,Position(0,0,sliceZ));
66  s_phv.addPhysVolID("slice",s_num);
67  if ( x_slice.isSensitive() ) {
68  sens.setType("calorimeter");
69  s_vol.setSensitiveDetector(sens);
70  sensitives.push_back(s_phv);
71  }
72  sliceZ += s_thick/2;
73  s_num++;
74  }
75  l_vol.setVisAttributes(description.visAttributes(x_layer.visStr()));
76  if ( l_repeat <= 0 ) throw std::runtime_error(x_det.nameStr()+"> Invalid repeat value");
77  for(int j=0; j<l_repeat; ++j) {
78  string phys_lay = _toString(l_num,"layer%d");
79  layerZ += l_thick/2;
80  DetElement layer_elt(endcap, phys_lay, l_num);
81  PlacedVolume pv = endcapVol.placeVolume(l_vol,Position(0,0,layerZ));
82  pv.addPhysVolID("layer", l_num);
83  layer_elt.setPlacement(pv);
84  for(size_t ic=0; ic<sensitives.size(); ++ic) {
85  PlacedVolume sens_pv = sensitives[ic];
86  DetElement comp_elt(layer_elt,sens_pv.volume().name(),l_num);
87  comp_elt.setPlacement(sens_pv);
88  }
89  layerZ += l_thick/2;
90  ++l_num;
91  }
92  ++layerType;
93  }
94 
95  double z_pos = zmin+totalThickness/2;
96  PlacedVolume pv;
97  // Reflect it.
98  if ( reflect ) {
99  Assembly assembly(det_name);
100  DetElement both_endcaps(det_name,det_id);
101  Volume motherVol = description.pickMotherVolume(both_endcaps);
102  DetElement sdetA = endcap;
103  Ref_t(sdetA)->SetName((det_name+"_A").c_str());
104  DetElement sdetB = endcap.clone(det_name+"_B",x_det.id());
105 
106  pv = assembly.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,0,0),
107  Position(0,0,z_pos)));
108  pv.addPhysVolID("barrel", 1);
109  sdetA.setPlacement(pv);
110 
111  pv = assembly.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,M_PI,0),
112  Position(0,0,-z_pos)));
113  pv.addPhysVolID("barrel", 2);
114  sdetB.setPlacement(pv);
115 
116  pv = motherVol.placeVolume(assembly);
117  pv.addPhysVolID("system", det_id);
118  both_endcaps.setPlacement(pv);
119  both_endcaps.add(sdetA);
120  both_endcaps.add(sdetB);
121  return both_endcaps;
122  }
123  Volume motherVol = description.pickMotherVolume(endcap);
124  pv = motherVol.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,0,0),
125  Position(0,0,z_pos)));
126  pv.addPhysVolID("system", det_id);
127  pv.addPhysVolID("barrel", 1);
128  endcap.setPlacement(pv);
129  Ref_t(endcap)->SetName(det_name.c_str());
130  return endcap;
131 }
132 
133 DECLARE_DETELEMENT(DD4hep_PolyhedraEndcapCalorimeter2,create_detector)
134 DECLARE_DEPRECATED_DETELEMENT(PolyhedraEndcapCalorimeter2,create_detector)
static Ref_t create_detector(Detector &description, xml_h e, SensitiveDetector sens)
Detector
Definition: DDG4.py:69
Namespace for the AIDA detector description toolkit.