CMS 3D CMS Logo

DDHCalTBCableAlgo.cc
Go to the documentation of this file.
4 #include "DD4hep/DetFactoryHelper.h"
5 
6 //#define EDM_ML_DEBUG
7 
8 using namespace geant_units::operators;
9 
10 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
11  cms::DDNamespace ns(ctxt, e, true);
13 
14  // Header section
15  // <---- Zout ---->
16  // | **************** |
17  // | * * Wstep
18  // W * ***** |
19  // | * *
20  // | ********************
21  // <------ Zin ------->
22  // <------ Zout ------> Zout = Full sector Z at position
23  // | ******************** Zin = Full sector Z at position
24  // | * *
25  // W * * Angle = Theta sector
26  // | * * )
27  // | ****************--------
28  // <------ Zin ------->
29  // <------ Zout ------> Zin(i)=Zout(i-1)
30  // | ******************** Zout(i)=Zin(i)+W(i)/tan(Theta(i))
31  // | * *
32  // W * * Theta
33  // | * *
34  // | ****************--------
35  // <--- Zin ------>
36  std::string genMat = args.value<std::string>("MaterialName"); //General material
37  int nsectors = args.value<int>("NSector"); //Number of potenital straight edges
38  int nsectortot = args.value<int>("NSectorTot"); //Number of straight edges (actual)
39  int nhalf = args.value<int>("NHalf"); //Number of half modules
40  double rin = args.value<double>("RIn"); //(see Figure of hcalbarrel)
41  std::vector<double> theta = args.value<std::vector<double> >("Theta"); // .... (in degrees)
42  std::vector<double> rmax = args.value<std::vector<double> >("RMax"); // ....
43  std::vector<double> zoff = args.value<std::vector<double> >("ZOff"); // ....
44  std::string absMat = args.value<std::string>("AbsMatName"); //Absorber material
45  double thick = args.value<double>("Thickness"); //Thickness of absorber
46  double width1 = args.value<double>("Width1"); //Width of absorber type 1
47  double length1 = args.value<double>("Length1"); //Length of absorber type 1
48  double width2 = args.value<double>("Width2"); //Width of absorber type 2
49  double length2 = args.value<double>("Length2"); //Length of absorber type 2
50  double gap2 = args.value<double>("Gap2"); //Gap between abosrbers of type 2
51  std::string idName = args.value<std::string>("MotherName"); //Name of the "parent" volume.
52 #ifdef EDM_ML_DEBUG
53  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: General material " << genMat << "\tSectors " << nsectors << ", "
54  << nsectortot << "\tHalves " << nhalf << "\tRin " << convertCmToMm(rin);
55  for (unsigned int i = 0; i < theta.size(); i++)
56  edm::LogVerbatim("HCalGeom") << "\t" << i << " Theta " << convertRadToDeg(theta[i]) << " rmax "
57  << convertCmToMm(rmax[i]) << " zoff " << convertCmToMm(zoff[i]);
58  edm::LogVerbatim("HCalGeom") << "\tCable mockup made of " << absMat << "\tThick " << convertCmToMm(thick)
59  << "\tLength and width " << convertCmToMm(length1) << ", " << convertCmToMm(width1)
60  << " and " << convertCmToMm(length2) << ", " << convertCmToMm(width2) << " Gap "
61  << convertCmToMm(gap2);
62  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Parent " << args.parentName() << " idName " << idName
63  << " NameSpace " << ns.name() << " for solids";
64 #endif
65 
66  double alpha = 1._pi / nsectors;
67  double dphi = nsectortot * 2._pi / nsectors;
68  double zstep0 = zoff[1] + rmax[1] * tan(theta[1]) + (rin - rmax[1]) * tan(theta[2]);
69  double zstep1 = zstep0 + thick / cos(theta[2]);
70  double zstep2 = zoff[3];
71  double rstep0 = rin + (zstep2 - zstep1) / tan(theta[2]);
72  double rstep1 = rin + (zstep1 - zstep0) / tan(theta[2]);
73 
74  std::vector<double> pgonZ = {zstep0, zstep1, zstep2, zstep2 + thick / cos(theta[2])};
75  std::vector<double> pgonRmin = {rin, rin, rstep0, rmax[2]};
76  std::vector<double> pgonRmax = {rin, rstep1, rmax[2], rmax[2]};
77 
78  dd4hep::Solid solid = dd4hep::Polyhedra(ns.prepend(idName), nsectortot, -alpha, dphi, pgonZ, pgonRmin, pgonRmax);
79  dd4hep::Material matter = ns.material(genMat);
80  dd4hep::Volume genlogic(solid.name(), solid, matter);
81 #ifdef EDM_ML_DEBUG
82  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Polyhedra made of " << genMat << " with "
83  << nsectortot << " sectors from " << convertRadToDeg(-alpha) << " to "
84  << convertRadToDeg(-alpha + dphi) << " and with " << pgonZ.size() << " sections";
85  for (unsigned int i = 0; i < pgonZ.size(); i++)
86  edm::LogVerbatim("HCalGeom") << "\t\tZ = " << convertCmToMm(pgonZ[i]) << "\tRmin = " << convertCmToMm(pgonRmin[i])
87  << "\tRmax = " << convertCmToMm(pgonRmax[i]);
88 #endif
89 
90  dd4hep::Volume parent = ns.volume(args.parentName());
91  dd4hep::Rotation3D rot;
92  parent.placeVolume(genlogic, 1);
93 #ifdef EDM_ML_DEBUG
94  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << genlogic.name() << " number 1 positioned in "
95  << parent.name() << " at (0, 0, 0) with no rotation";
96 #endif
97  if (nhalf != 1) {
98  rot = cms::makeRotation3D(90._deg, 180._deg, 90._deg, 90._deg, 180._deg, 0);
99  parent.placeVolume(genlogic, 2, rot);
100 #ifdef EDM_ML_DEBUG
101  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << genlogic.name() << " number 2 positioned in "
102  << parent.name() << " at (0, 0, 0) with rotation: " << rot;
103 #endif
104  }
105 
106  //Construct sector (from -alpha to +alpha)
107  std::string name = idName + "Module";
108  solid = dd4hep::Polyhedra(ns.prepend(name), 1, -alpha, 2 * alpha, pgonZ, pgonRmin, pgonRmax);
109  dd4hep::Volume seclogic(solid.name(), solid, matter);
110 #ifdef EDM_ML_DEBUG
111  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Polyhedra made of " << genMat
112  << " with 1 sector from " << convertRadToDeg(-alpha) << " to " << convertRadToDeg(alpha)
113  << " and with " << pgonZ.size() << " sections";
114  for (unsigned int i = 0; i < pgonZ.size(); i++)
115  edm::LogVerbatim("HCalGeom") << "\t\tZ = " << convertCmToMm(pgonZ[i]) << "\tRmin = " << convertCmToMm(pgonRmin[i])
116  << "\tRmax = " << convertCmToMm(pgonRmax[i]);
117 #endif
118 
119  for (int ii = 0; ii < nsectortot; ++ii) {
120  double phi = ii * 2 * alpha;
121  dd4hep::Rotation3D rotation;
122  if (phi != 0) {
123  rotation = dd4hep::RotationZ(phi);
124 #ifdef EDM_ML_DEBUG
125  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a new rotation "
126  << "\t90," << convertRadToDeg(phi) << ",90," << (90 + convertRadToDeg(phi))
127  << ", 0, 0";
128 #endif
129  }
130  genlogic.placeVolume(seclogic, ii + 1, rotation);
131 #ifdef EDM_ML_DEBUG
132  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << seclogic.name() << " number " << ii + 1
133  << " positioned in " << genlogic.name() << " at (0, 0, 0) with rotation: " << rotation;
134 #endif
135  }
136 
137  //Now a trapezoid of air
138  double rinl = pgonRmin[0] + thick * sin(theta[2]);
139  double routl = pgonRmax[2] - thick * sin(theta[2]);
140  double dx1 = rinl * tan(alpha);
141  double dx2 = 0.90 * routl * tan(alpha);
142  double dy = 0.50 * thick;
143  double dz = 0.50 * (routl - rinl);
144  name = idName + "Trap";
145  solid = dd4hep::Trap(ns.prepend(name), dz, 0, 0, dy, dx1, dx1, 0, dy, dx2, dx2, 0);
146  dd4hep::Volume glog(solid.name(), solid, matter);
147 #ifdef EDM_ML_DEBUG
148  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Trap made of " << genMat
149  << " of dimensions " << convertCmToMm(dz) << ", 0, 0, " << convertCmToMm(dy) << ", "
150  << convertCmToMm(dx1) << ", " << convertCmToMm(dx1) << ", 0, " << convertCmToMm(dy)
151  << ", " << convertCmToMm(dx2) << ", " << convertCmToMm(dx2) << ", 0";
152 #endif
153 
154  rot = cms::makeRotation3D(90._deg, 270._deg, (180._deg - theta[2]), 0, (90._deg - theta[2]), 0);
155 #ifdef EDM_ML_DEBUG
156  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation: \t90, 270, "
157  << (180 - convertRadToDeg(theta[2])) << ", 0, " << (90 - convertRadToDeg(theta[2]))
158  << ", 0";
159 #endif
160  dd4hep::Position r1(0.5 * (rinl + routl), 0, 0.5 * (pgonZ[1] + pgonZ[2]));
161  seclogic.placeVolume(glog, 1, dd4hep::Transform3D(rot, r1));
162 #ifdef EDM_ML_DEBUG
163  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << glog.name() << " number 1 positioned in " << seclogic.name()
164  << " at (" << convertCmToMm(0.5 * (rinl + routl)) << ", 0, "
165  << convertCmToMm(0.5 * (pgonZ[1] + pgonZ[2])) << " with rotation: " << rot;
166 #endif
167  //Now the cable of type 1
168  name = idName + "Cable1";
169  double phi = atan((dx2 - dx1) / (2 * dz));
170  double xmid = 0.5 * (dx1 + dx2) - 1.0;
171  solid = dd4hep::Box(ns.prepend(name), 0.5 * width1, 0.5 * thick, 0.5 * length1);
172  dd4hep::Material absmatter = ns.material(absMat);
173  dd4hep::Volume cablog1(solid.name(), solid, absmatter);
174 #ifdef EDM_ML_DEBUG
175  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Box made of " << absMat << " of dimension "
176  << convertCmToMm(0.5 * width1) << ", " << convertCmToMm(0.5 * thick) << ", "
177  << convertCmToMm(0.5 * length1);
178 #endif
179 
180  dd4hep::Rotation3D rot2 = cms::makeRotation3D((90._deg + phi), 0.0, 90._deg, 90._deg, phi, 0.0);
181 #ifdef EDM_ML_DEBUG
182  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation \t" << (90 + convertRadToDeg(phi))
183  << ", 0, 90, 90, " << convertRadToDeg(phi) << ", 0";
184 #endif
185  dd4hep::Position r2((xmid - 0.5 * width1 * cos(phi)), 0, 0);
186  glog.placeVolume(cablog1, 1, dd4hep::Transform3D(rot2, r2));
187 #ifdef EDM_ML_DEBUG
188  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog1.name() << " number 1 positioned in " << glog.name()
189  << " at (" << convertCmToMm(xmid - 0.5 * width1 * cos(phi))
190  << ", 0, 0) with rotation: " << rot2;
191 #endif
192  dd4hep::Rotation3D rot3 = cms::makeRotation3D((90._deg - phi), 0, 90._deg, 90._deg, -phi, 0);
193 #ifdef EDM_ML_DEBUG
194  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation \t" << (90 - convertRadToDeg(phi))
195  << ", 0, 90, 90, " << convertRadToDeg(-phi) << ", 0";
196 #endif
197  dd4hep::Position r3(-(xmid - 0.5 * width1 * cos(phi)), 0, 0);
198  glog.placeVolume(cablog1, 2, dd4hep::Transform3D(rot3, r3));
199 #ifdef EDM_ML_DEBUG
200  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog1.name() << " number 2 positioned in " << glog.name()
201  << " at (" << convertCmToMm(xmid - 0.5 * width1 * cos(phi))
202  << ", 0, 0) with rotation: " << rot3;
203 #endif
204  //Now the cable of type 2
205  name = idName + "Cable2";
206  solid = dd4hep::Box(ns.prepend(name), 0.5 * width2, 0.5 * thick, 0.5 * length2);
207  dd4hep::Volume cablog2(solid.name(), solid, absmatter);
208 #ifdef EDM_ML_DEBUG
209  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Box made of " << absMat << " of dimension "
210  << convertCmToMm(0.5 * width2) << ", " << convertCmToMm(0.5 * thick) << ", "
211  << convertCmToMm(0.5 * length2);
212 #endif
213 
214  glog.placeVolume(cablog2, 1, dd4hep::Position(0.5 * (width2 + gap2), 0, 0));
215 #ifdef EDM_ML_DEBUG
216  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog2.name() << " number 1 positioned in " << glog.name()
217  << " at (" << convertCmToMm(0.5 * (width2 + gap2)) << ", 0, 0) with no rotation";
218 #endif
219  glog.placeVolume(cablog2, 2, dd4hep::Position(-0.5 * (width2 + gap2), 0, 0));
220 #ifdef EDM_ML_DEBUG
221  edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog2.name() << " number 2 positioned in " << glog.name()
222  << " at " << convertCmToMm(-0.5 * (width2 + gap2)) << ", 0, 0) with no rotation";
223 
224  edm::LogVerbatim("HCalGeom") << "<<== End of DDHCalTBCableAlgo construction";
225 #endif
226 
227  return 1;
228 }
229 
230 // first argument is the type from the xml file
231 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalTBCableAlgo, algorithm);
writedatasetfile.args
args
Definition: writedatasetfile.py:18
mps_fire.i
i
Definition: mps_fire.py:428
g4SimHits_cfi.Material
Material
Definition: g4SimHits_cfi.py:560
MessageLogger.h
DECLARE_DDCMS_DETELEMENT
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
cms::DDNamespace::material
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:116
cms::DDParsingContext
Definition: DDParsingContext.h:13
zMuMuMuonUserData.alpha
alpha
zGenParticlesMatch = cms.InputTag(""),
Definition: zMuMuMuonUserData.py:9
angle_units::operators::convertRadToDeg
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
cms::DDNamespace
Definition: DDNamespace.h:16
cms::makeRotation3D
DDRotationMatrix makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
Definition: DDAlgoArguments.cc:20
versionedElectronIDProducer_cfi.idName
idName
Definition: versionedElectronIDProducer_cfi.py:11
geant_units::operators
Definition: GeantUnits.h:18
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
cms::DDNamespace::prepend
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:60
algorithm
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
Definition: DDHCalTBCableAlgo.cc:10
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
PixelTestBeamValidation_cfi.Position
Position
Definition: PixelTestBeamValidation_cfi.py:75
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cms::Volume
dd4hep::Volume Volume
Definition: DDFilteredView.h:47
idealTransformation.rotation
dictionary rotation
Definition: idealTransformation.py:1
geant_units::operators::convertCmToMm
constexpr NumType convertCmToMm(NumType centimeters)
Definition: GeantUnits.h:68
GeantUnits.h
DDPlugins.h
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
cms::DDAlgoArguments
Definition: DDAlgoArguments.h:28
PVValHelper::dy
Definition: PVValidationHelpers.h:49
align::Detector
Definition: StructureType.h:86
PVValHelper::dz
Definition: PVValidationHelpers.h:50
diffTwoXMLs.r1
r1
Definition: diffTwoXMLs.py:53
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
HGCalGeometryMode::Polyhedra
Definition: HGCalGeometryMode.h:35
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::Log
Definition: MessageLogger.h:70
cms::DDNamespace::name
std::string_view name() const
Definition: DDNamespace.h:72
class-composition.parent
parent
Definition: class-composition.py:88
cuy.ii
ii
Definition: cuy.py:590
cms::DDNamespace::volume
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:205
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37