CylindricalEndcapCalorimeter_geo.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 //
15 // Specialized generic detector constructor
16 //
17 //==========================================================================
18 #include "DD4hep/DetFactoryHelper.h"
19 #include "DD4hep/Printout.h"
20 #include "XML/Layering.h"
21 
22 using namespace std;
23 using namespace dd4hep;
24 
25 static Ref_t create_detector(Detector& lcdd, xml_h e, SensitiveDetector sens) {
26  xml_det_t x_det = e;
27  xml_dim_t dim = x_det.dimensions();
28  Material air = lcdd.air();
29  string det_name = x_det.nameStr();
30  bool reflect = x_det.reflect();
31  double zmin = dim.inner_z();
32  double rmin = dim.inner_r();
33  double rmax = dim.outer_r();
34  double totWidth = Layering(x_det).totalThickness();
35  double z = zmin;
36  Tube envelope (rmin,rmax,totWidth/2);
37  Volume envelopeVol(det_name+"_envelope",envelope,air);
38  int layer_num = 1;
39  PlacedVolume pv;
40 
41  // Set attributes of slice
42  for(xml_coll_t c(x_det,_U(layer)); c; ++c) {
43  xml_comp_t x_layer = c;
44  double layerWidth = 0;
45  for(xml_coll_t l(x_layer,_U(slice)); l; ++l)
46  layerWidth += xml_comp_t(l).thickness();
47  for(int i=0, m=0, repeat=x_layer.repeat(); i<repeat; ++i) {
48  double zlayer = z;
49  string layer_name = det_name + _toString(layer_num,"_layer%d");
50  Volume layer_vol(layer_name,Tube(rmin,rmax,layerWidth),air);
51 
52  for(xml_coll_t l(x_layer,_U(slice)); l; ++l, ++m) {
53  xml_comp_t x_slice = l;
54  double w = x_slice.thickness();
55  string slice_name = layer_name + _toString(m+1,"slice%d");
56  Material slice_mat = lcdd.material(x_slice.materialStr());
57  Volume slice_vol (slice_name,Tube(rmin,rmax,w),slice_mat);
58 
59  if ( x_slice.isSensitive() ) {
60  sens.setType("calorimeter");
61  slice_vol.setSensitiveDetector(sens);
62  }
63  slice_vol.setAttributes(lcdd,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
64  pv = layer_vol.placeVolume(slice_vol,Position(0,0,z-zlayer-layerWidth/2+w/2));
65  pv.addPhysVolID("slice",m+1);
66  z += w;
67  }
68  layer_vol.setVisAttributes(lcdd,x_layer.visStr());
69 
70  Position layer_pos(0,0,zlayer-zmin-totWidth/2+layerWidth/2);
71  pv = envelopeVol.placeVolume(layer_vol,layer_pos);
72  pv.addPhysVolID("layer",layer_num);
73  printout(DEBUG,"Calo","CylindricalEndcapCalorimeter: built layer %d -> %s",layer_num,layer_name.c_str());
74  ++layer_num;
75  }
76  }
77  envelope.setDimensions(rmin,rmax,totWidth/2);
78  // Set attributes of slice
79  envelopeVol.setAttributes(lcdd,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
80 
81  DetElement sdet(det_name,x_det.id());
82  Assembly assembly(det_name+"_assembly");
83  Volume motherVol = lcdd.pickMotherVolume(sdet);
84  PlacedVolume phv = motherVol.placeVolume(assembly);
85  phv.addPhysVolID("system",sdet.id());
86  sdet.setPlacement(phv);
87 
88  DetElement sdetA(sdet,det_name+(reflect ? "_A" : ""),x_det.id());
89  phv = assembly.placeVolume(envelopeVol,Position(0,0,zmin+totWidth/2));
90  phv.addPhysVolID("barrel",1);
91  sdetA.setPlacement(phv);
92 
93  if ( reflect ) {
94  phv=assembly.placeVolume(envelopeVol,Transform3D(RotationZ(M_PI),Position(0,0,-zmin-totWidth/2)));
95  phv.addPhysVolID("barrel",2);
97  DetElement sdetB(sdet,det_name+"_B",x_det.id());
98  sdetB.setPlacement(phv);
99  }
100  return sdet;
101 }
102 
103 DECLARE_DETELEMENT(DD4hep_CylindricalEndcapCalorimeter,create_detector)
Detector
Definition: DDG4.py:69
Namespace for the AIDA detector description toolkit.
static Ref_t create_detector(Detector &lcdd, xml_h e, SensitiveDetector sens)