GenericShape_geo.cpp
Go to the documentation of this file.
1 //==========================================================================
2 //
3 // Generic Tube Creator. Will not support sensitive segments.
4 //
5 // Control via .xml file as follows:
6 // <lcdd> <detectors>
7 // #Must contain a detector child element,
8 // <detector name ="DetName" type="GenericShape" >
9 // #Must define at least one layer,
10 // <layer id="#(int)" inner_r="#(double)" outer_z="#(double)" >
11 // #Must define at least one slice,
12 // <slice material="string" thickness="#(double)" >
13 // #Close layer, detector,
14 // </layer>
15 // </detector>
16 // </lcdd>
17 //==========================================================================
18 #include "DD4hep/DetFactoryHelper.h"
19 #include "DD4hep/Printout.h"
20 #include "TMath.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  string det_name = x_det.nameStr();
28  Material air = lcdd.air();
29  DetElement sdet (det_name,x_det.id());
30  Assembly assembly (det_name+"_assembly");
31 
32  PlacedVolume pv;
33 
34  int n = 0;
35 
36  std::cout << " TESTING ...\n";
37 
38  for(xml_coll_t i(x_det,_U(layer)); i; ++i, ++n) {
39  xml_comp_t x_layer = i;
40  string l_name = det_name+_toString(n,"_layer%d");
41  double z = x_layer.outer_z();
42  double rmin = x_layer.inner_r();
43  double z_offset = 0.0;
44  if(x_layer.hasAttr(_Unicode(z_offset))) {
45  z_offset = x_layer.z_offset();
46  }
47  double r = rmin;
48  DetElement layer(sdet,_toString(n,"layer%d"),x_layer.id());
49  int m = 0;
50 
51  printout(INFO, "GenericShapeJLEIC", "Creating a Generic Layer");
52  for(xml_coll_t j(x_layer,_U(slice)); j; ++j, ++m) {
53  xml_comp_t x_slice = j;
54  Material mat = lcdd.material(x_slice.materialStr());
55  string s_name= l_name+_toString(m,"_slice%d");
56  double thickness = x_slice.thickness();
57  Tube s_tub(r, r+thickness,z);//,2.0*TMath::Pi()+0.01);
58  Volume s_vol(s_name, s_tub, mat);
59 
60  r += thickness;
61  s_vol.setVisAttributes(lcdd,x_det.visStr());
62  pv = assembly.placeVolume(s_vol,Position(0, 0, z_offset));
63  // Slices have no extra id. Take the ID of the layer!
64  pv.addPhysVolID("slice",m);
65  printout(INFO, "GenericShapeJLEIC", "Creating Generic Slice");
66  }
67  //cout << l_name << " " << rmin << " " << r << " " << z << endl;
68 
69  }
70 
71  pv = lcdd.pickMotherVolume(sdet).placeVolume(assembly);
72  pv.addPhysVolID("system",sdet.id()).addPhysVolID("barrel",0);
73  sdet.setPlacement(pv);
74  return sdet;
75 }
76 
77 DECLARE_DETELEMENT(GenericShapeJLEIC,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.