GenericRICH_geo.cpp
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
2 #include "DD4hep/Printout.h"
3 #include <XML/Helper.h>
4 #include "TMath.h"
5 #include "DDRec/Surface.h"
6 
7 #include "DD4hep/OpticalSurfaces.h"
8 #include "DDRec/DetectorData.h"
9 
10 using namespace std;
11 using namespace dd4hep;
12 using namespace dd4hep::rec;
13 
14 using namespace dd4hep;
15 
30 static Ref_t createDetector(Detector& desc, xml::Handle_t handle, SensitiveDetector sens) {
31  xml::DetElement detElem = handle;
32 
33  std::string detName = detElem.nameStr();
34  int detID = detElem.id();
35 
36  DetElement det(detName, detID);
37  xml::Component dims = detElem.dimensions();
38  double rInner1 = dims.rmin1();
39  double rInner2 = dims.rmin2();
40  double rOuter1 = dims.rmax1();
41  double rOuter2 = dims.rmax2();
42  double zMin = dims.zmin();
43  double zMax = dims.zmax();
44 
45  Material air = desc.air();
46  Material PyrexGlass = desc.material("PyrexGlass");
47  Material N2cherenkov = desc.material("N2cherenkov");
48 
49  Cone envShape(0.5 * (zMax - zMin), rInner1, rOuter1, rInner2, rOuter2);
50  Volume envVol(detName + "_envelope", envShape, N2cherenkov);
51 
52  // ---------------
53  // Mirror
54  DetElement mirror_DE(det,"Mirror_DE",0);
55  Tube mirrorShape(rInner1+1*cm, rOuter2-2*cm, 6*mm/2.0);
56  Volume mirrorVol("RICH_mirror_dummy", mirrorShape, PyrexGlass);
57  PlacedVolume mirrorPV = envVol.placeVolume(mirrorVol, Position(0, 0, 0.5*(zMax-zMin)-1*cm));
58  mirrorPV.addPhysVolID("layer", 2).addPhysVolID("module", 1);
59  mirror_DE.setPlacement(mirrorPV);
60  //sens.setType("photoncounter");
61  //mirrorVol.setSensitiveDetector(sens);
62 
63  // ---------------
64 
65  // ---------------
66  // Dummy PMT surface
67  //DetElement pmt_DE(det,"PMT_DE",1);
68  //Tube pmtShape(rInner1+1*cm, rOuter1-2*cm, 4*mm/2.0);
69  //Volume pmtVol("pmt_dummy_volume", pmtShape, N2cherenkov);
70  //PlacedVolume pmtPV = envVol.placeVolume(pmtVol, Position(0, 0, -0.5 * (zMax - zMin) + 1*cm));
71  //pmtPV.addPhysVolID("layer", 1).addPhysVolID("module", 1);
72  //pmt_DE.setPlacement(pmtPV);
73  //sens.setType("photoncounter");
74  //pmtVol.setSensitiveDetector(sens);
75 
76  // ---------------
77  // Fill the disc with a grid of MCP-PMTs (square)
78  // Start from the top of the disc
79  // theta for top left mcp starting point.
81  double a_side_mcp = 10.2 * cm;
82  double mcppmt_radius = (rOuter1 - a_side_mcp);
83  double theta_start = std::asin(2.0 * a_side_mcp / mcppmt_radius);
84  double first_y_disp = 2.0 * a_side_mcp / std::tan(theta_start);
85  int N_mcppmt = std::floor(mcppmt_radius / a_side_mcp);
86 
87  Box mcppmt_shape(10.0*cm/2.0, 10.0*cm/2.0, 1.0*cm/2.0);
88  Volume mcppmt_v("mcppmt_v", mcppmt_shape, N2cherenkov);
89  mcppmt_v.setVisAttributes(desc.visAttributes("BlueVis"));
90 
91  double x_PMTi = -N_mcppmt * a_side_mcp;
92  double y_PMTi = first_y_disp;
93  int ix = 1;
94  int iy = 1;
95  int in = 1;
96  while(y_PMTi > -mcppmt_radius) {
97  while(x_PMTi < mcppmt_radius) {
98  double r_PMTi = std::sqrt(x_PMTi*x_PMTi + y_PMTi*y_PMTi);
99  if ( (r_PMTi < mcppmt_radius) && (r_PMTi > (rInner1 + a_side_mcp )) ) {
100  PlacedVolume mcppmt_pv =
101  envVol.placeVolume(mcppmt_v, Position(x_PMTi, y_PMTi, -0.5 * (zMax - zMin) + 4 * cm));
102  DetElement mcppmt_DE(det,std::string("MCPPMT_DE")+std::to_string(in),in);
103  mcppmt_pv.addPhysVolID("layer", 3)
104  .addPhysVolID("module", 1)
105  .addPhysVolID("x", ix)
106  .addPhysVolID("y", iy);
107  sens.setType("photoncounter");
108  mcppmt_DE.setPlacement(mcppmt_pv);
109  mcppmt_v.setSensitiveDetector(sens);
110  in++;
111  ix++;
112  }
113  x_PMTi += a_side_mcp;
114  }
115  x_PMTi = -N_mcppmt*a_side_mcp;
116  y_PMTi -= a_side_mcp;
117  iy++;
118  }
119 
120 
121  envVol.setVisAttributes(desc.visAttributes(detElem.visStr()));
122 
123  Volume motherVol = desc.pickMotherVolume(det);
124  PlacedVolume envPV = motherVol.placeVolume(envVol, Position(0, 0, 0.5 * (zMin + zMax)));
125  envPV.addPhysVolID("system", detID);
126  det.setPlacement(envPV);
127 
128  OpticalSurfaceManager surfMgr = desc.surfaceManager();
129  OpticalSurface mirrorSurf = surfMgr.opticalSurface("MirrorOpticalSurface");
130  //OpticalSurface airSurf = surfMgr.opticalSurface("/world/"+det_name+"#AirSurface");
131  //BorderSurface mirrorBorder_Surf = BorderSurface(desc, det, "RICHmirror", mirrorSurf, mirrorPV, envPV);
132  SkinSurface mirrorBorder_Surf(desc,mirror_DE,"RICHmirror", mirrorSurf, mirrorVol);
133  //BorderSurface bubbleSurf = BorderSurface(description, sdet, "TankBubble", airSurf, bubblePlace, tankPlace);
134  mirrorBorder_Surf.isValid();
135  //tankSurf.isValid();
136 
137 
138  return det;
139 }
141 
142 // clang-format off
143 DECLARE_DETELEMENT(GenericRICH, createDetector)
Detector
Definition: DDG4.py:69
Namespace for the AIDA detector description toolkit.
static Ref_t createDetector(Detector &desc, xml::Handle_t handle, SensitiveDetector sens)