CMS 3D CMS Logo

DDHGCalHEFileAlgo.cc
Go to the documentation of this file.
1 // File: DDHGCalHEFileAlgo.cc
3 // Description: Geometry factory class for HGCal (Mix) adopted for DD4HEP
5 
6 #include <cmath>
7 #include <memory>
8 #include <string>
9 #include <unordered_set>
10 #include <vector>
11 
17 #include "DD4hep/DetFactoryHelper.h"
21 
22 //#define EDM_ML_DEBUG
23 using namespace cms_units::operators;
24 
26  HGCalHEFileAlgo() { throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalHEFileAlgo"; }
28  cms::DDNamespace ns(ctxt, e, true);
30 
31 #ifdef EDM_ML_DEBUG
32  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: Creating an instance";
33 #endif
34 
35  static constexpr double tol1 = 0.01;
36  dd4hep::Volume mother = ns.volume(args.parentName());
37 
38  waferNames_ = args.value<std::vector<std::string>>("WaferNames");
39 #ifdef EDM_ML_DEBUG
40  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << waferNames_.size() << " wafers";
41  for (unsigned int i = 0; i < waferNames_.size(); ++i)
42  edm::LogVerbatim("HGCalGeom") << "Wafer[" << i << "] " << waferNames_[i];
43 #endif
44  materials_ = args.value<std::vector<std::string>>("MaterialNames");
45  volumeNames_ = args.value<std::vector<std::string>>("VolumeNames");
46  thickness_ = args.value<std::vector<double>>("Thickness");
47  copyNumber_.resize(materials_.size(), 1);
48 #ifdef EDM_ML_DEBUG
49  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << materials_.size() << " types of volumes";
50  for (unsigned int i = 0; i < volumeNames_.size(); ++i)
51  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << volumeNames_[i] << " of thickness " << thickness_[i]
52  << " filled with " << materials_[i] << " first copy number " << copyNumber_[i];
53 #endif
54  layerNumbers_ = args.value<std::vector<int>>("Layers");
55  layerThick_ = args.value<std::vector<double>>("LayerThick");
56  rMixLayer_ = args.value<std::vector<double>>("LayerRmix");
57 #ifdef EDM_ML_DEBUG
58  edm::LogVerbatim("HGCalGeom") << "There are " << layerNumbers_.size() << " blocks";
59  for (unsigned int i = 0; i < layerNumbers_.size(); ++i)
60  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << layerThick_[i] << " Rmid "
61  << rMixLayer_[i] << " with " << layerNumbers_[i] << " layers";
62 #endif
63  layerType_ = args.value<std::vector<int>>("LayerType");
64  layerSense_ = args.value<std::vector<int>>("LayerSense");
65  firstLayer_ = args.value<int>("FirstLayer");
66  absorbMode_ = args.value<int>("AbsorberMode");
67  sensitiveMode_ = args.value<int>("SensitiveMode");
68 #ifdef EDM_ML_DEBUG
69  edm::LogVerbatim("HGCalGeom") << "First Layer " << firstLayer_ << " and "
70  << "Absober:Sensitive mode " << absorbMode_ << ":" << sensitiveMode_;
71 #endif
72  layerCenter_ = args.value<std::vector<int>>("LayerCenter");
73 #ifdef EDM_ML_DEBUG
74  for (unsigned int i = 0; i < layerCenter_.size(); ++i)
75  edm::LogVerbatim("HGCalGeom") << "LayerCenter [" << i << "] " << layerCenter_[i];
76 #endif
77  if (firstLayer_ > 0) {
78  for (unsigned int i = 0; i < layerType_.size(); ++i) {
79  if (layerSense_[i] > 0) {
80  int ii = layerType_[i];
81  copyNumber_[ii] = firstLayer_;
82 #ifdef EDM_ML_DEBUG
83  edm::LogVerbatim("HGCalGeom") << "First copy number for layer type " << i << ":" << ii << " with "
84  << materials_[ii] << " changed to " << copyNumber_[ii];
85 #endif
86  break;
87  }
88  }
89  } else {
90  firstLayer_ = 1;
91  }
92 #ifdef EDM_ML_DEBUG
93  edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " layers";
94  for (unsigned int i = 0; i < layerType_.size(); ++i)
95  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType_[i] << " sensitive class "
96  << layerSense_[i];
97 #endif
98  materialsTop_ = args.value<std::vector<std::string>>("TopMaterialNames");
99  namesTop_ = args.value<std::vector<std::string>>("TopVolumeNames");
100  layerThickTop_ = args.value<std::vector<double>>("TopLayerThickness");
101  layerTypeTop_ = args.value<std::vector<int>>("TopLayerType");
102  copyNumberTop_.resize(materialsTop_.size(), 1);
103 #ifdef EDM_ML_DEBUG
104  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << materialsTop_.size()
105  << " types of volumes in the top part";
106  for (unsigned int i = 0; i < materialsTop_.size(); ++i)
107  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << namesTop_[i] << " of thickness " << layerThickTop_[i]
108  << " filled with " << materialsTop_[i] << " first copy number "
109  << copyNumberTop_[i];
110  edm::LogVerbatim("HGCalGeom") << "There are " << layerTypeTop_.size() << " layers in the top part";
111  for (unsigned int i = 0; i < layerTypeTop_.size(); ++i)
112  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerTypeTop_[i];
113 #endif
114  materialsBot_ = args.value<std::vector<std::string>>("BottomMaterialNames");
115  namesBot_ = args.value<std::vector<std::string>>("BottomVolumeNames");
116  layerTypeBot_ = args.value<std::vector<int>>("BottomLayerType");
117  layerSenseBot_ = args.value<std::vector<int>>("BottomLayerSense");
118  layerThickBot_ = args.value<std::vector<double>>("BottomLayerThickness");
119  copyNumberBot_.resize(materialsBot_.size(), 1);
120 #ifdef EDM_ML_DEBUG
121  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << materialsBot_.size()
122  << " types of volumes in the bottom part";
123  for (unsigned int i = 0; i < materialsBot_.size(); ++i)
124  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << namesBot_[i] << " of thickness " << layerThickBot_[i]
125  << " filled with " << materialsBot_[i] << " first copy number "
126  << copyNumberBot_[i];
127  edm::LogVerbatim("HGCalGeom") << "There are " << layerTypeBot_.size() << " layers in the bottom part";
128  for (unsigned int i = 0; i < layerTypeBot_.size(); ++i)
129  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerTypeBot_[i]
130  << " sensitive class " << layerSenseBot_[i];
131 #endif
132  zMinBlock_ = args.value<double>("zMinBlock");
133  rad100to200_ = args.value<std::vector<double>>("rad100to200");
134  rad200to300_ = args.value<std::vector<double>>("rad200to300");
135  zMinRadPar_ = args.value<double>("zMinForRadPar");
136  choiceType_ = args.value<int>("choiceType");
137  nCutRadPar_ = args.value<int>("nCornerCut");
138  fracAreaMin_ = args.value<double>("fracAreaMin");
139  waferSize_ = args.value<double>("waferSize");
140  waferSepar_ = args.value<double>("SensorSeparation");
141  sectors_ = args.value<int>("Sectors");
142  alpha_ = (1._pi) / sectors_;
143  cosAlpha_ = cos(alpha_);
144 #ifdef EDM_ML_DEBUG
145  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: zStart " << zMinBlock_
146  << " radius for wafer type separation uses " << rad100to200_.size()
147  << " parameters; zmin " << zMinRadPar_ << " cutoff " << choiceType_ << ":"
148  << nCutRadPar_ << ":" << fracAreaMin_ << " wafer width " << waferSize_
149  << " separations " << waferSepar_ << " sectors " << sectors_ << ":"
150  << convertRadToDeg(alpha_) << ":" << cosAlpha_;
151  for (unsigned int k = 0; k < rad100to200_.size(); ++k)
152  edm::LogVerbatim("HGCalGeom") << "[" << k << "] 100-200 " << rad100to200_[k] << " 200-300 " << rad200to300_[k];
153 #endif
154  waferIndex_ = args.value<std::vector<int>>("WaferIndex");
155  waferTypes_ = args.value<std::vector<int>>("WaferTypes");
156 #ifdef EDM_ML_DEBUG
157  edm::LogVerbatim("HGCalGeom") << "waferTypes with " << waferTypes_.size() << " entries";
158  for (unsigned int k = 0; k < waferTypes_.size(); ++k)
159  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << waferIndex_[k] << " ("
160  << HGCalWaferIndex::waferLayer(waferIndex_[k]) << ", "
161  << HGCalWaferIndex::waferU(waferIndex_[k]) << ", "
162  << HGCalWaferIndex::waferV(waferIndex_[k]) << ") : " << waferTypes_[k];
163 #endif
164  slopeB_ = args.value<std::vector<double>>("SlopeBottom");
165  zFrontB_ = args.value<std::vector<double>>("ZFrontBottom");
166  rMinFront_ = args.value<std::vector<double>>("RMinFront");
167  slopeT_ = args.value<std::vector<double>>("SlopeTop");
168  zFrontT_ = args.value<std::vector<double>>("ZFrontTop");
169  rMaxFront_ = args.value<std::vector<double>>("RMaxFront");
170 #ifdef EDM_ML_DEBUG
171  for (unsigned int i = 0; i < slopeB_.size(); ++i)
172  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] Zmin " << zFrontB_[i] << " Rmin " << rMinFront_[i]
173  << " Slope " << slopeB_[i];
174  for (unsigned int i = 0; i < slopeT_.size(); ++i)
175  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] Zmin " << zFrontT_[i] << " Rmax " << rMaxFront_[i]
176  << " Slope " << slopeT_[i];
177  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: NameSpace " << ns.name();
178 
179  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalHEFileAlgo...";
180  copies_.clear();
181 #endif
182 
183  double zi(zMinBlock_);
184  int laymin(0);
185  for (unsigned int i = 0; i < layerNumbers_.size(); i++) {
186  double zo = zi + layerThick_[i];
187  double routF = HGCalGeomTools::radius(zi, zFrontT_, rMaxFront_, slopeT_);
188  int laymax = laymin + layerNumbers_[i];
189  double zz = zi;
190  double thickTot(0);
191  for (int ly = laymin; ly < laymax; ++ly) {
192  int ii = layerType_[ly];
193  int copy = copyNumber_[ii];
194  double hthick = 0.5 * thickness_[ii];
195  double rinB = HGCalGeomTools::radius(zo, zFrontB_, rMinFront_, slopeB_);
196  zz += hthick;
197  thickTot += thickness_[ii];
198 
199  std::string name = volumeNames_[ii] + std::to_string(copy);
200 
201 #ifdef EDM_ML_DEBUG
202  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: Layer " << ly << ":" << ii << " Front " << zi << ", "
203  << routF << " Back " << zo << ", " << rinB << " superlayer thickness "
204  << layerThick_[i];
205 #endif
206 
207  dd4hep::Material matter = ns.material(materials_[ii]);
208  dd4hep::Volume glog;
209 
210  if (layerSense_[ly] < 1) {
211  std::vector<double> pgonZ, pgonRin, pgonRout;
212  if (layerSense_[ly] == 0 || absorbMode_ == 0) {
213  double rmax =
214  (std::min(routF, HGCalGeomTools::radius(zz + hthick, zFrontT_, rMaxFront_, slopeT_)) * cosAlpha_) -
215  tol1;
216  pgonZ.emplace_back(-hthick);
217  pgonZ.emplace_back(hthick);
218  pgonRin.emplace_back(rinB);
219  pgonRin.emplace_back(rinB);
220  pgonRout.emplace_back(rmax);
221  pgonRout.emplace_back(rmax);
222  } else {
223  HGCalGeomTools::radius(zz - hthick,
224  zz + hthick,
225  zFrontB_,
226  rMinFront_,
227  slopeB_,
228  zFrontT_,
229  rMaxFront_,
230  slopeT_,
231  -layerSense_[ly],
232  pgonZ,
233  pgonRin,
234  pgonRout);
235  for (unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
236  pgonZ[isec] -= zz;
237  pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1;
238  }
239  }
240 
241  dd4hep::Solid solid = dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
242  ns.addSolidNS(ns.prepend(name), solid);
243  glog = dd4hep::Volume(solid.name(), solid, matter);
244  ns.addVolumeNS(glog);
245 #ifdef EDM_ML_DEBUG
246  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << solid.name() << " polyhedra of " << sectors_
247  << " sectors covering " << convertRadToDeg(-alpha_) << ":"
248  << convertRadToDeg(-alpha_ + 2._pi) << " with " << pgonZ.size() << " sections";
249  for (unsigned int k = 0; k < pgonZ.size(); ++k)
250  edm::LogVerbatim("HGCalGeom")
251  << "[" << k << "] z " << pgonZ[k] << " R " << pgonRin[k] << ":" << pgonRout[k];
252 #endif
253  } else {
254  double rins =
255  (sensitiveMode_ < 1) ? rinB : HGCalGeomTools::radius(zz + hthick, zFrontB_, rMinFront_, slopeB_);
256  double routs =
257  (sensitiveMode_ < 1) ? routF : HGCalGeomTools::radius(zz - hthick, zFrontT_, rMaxFront_, slopeT_);
258  dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
259  ns.addSolidNS(ns.prepend(name), solid);
260  glog = dd4hep::Volume(solid.name(), solid, matter);
261  ns.addVolumeNS(glog);
262 
263 #ifdef EDM_ML_DEBUG
264  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << solid.name() << " Tubs made of " << matter.name()
265  << " of dimensions " << rinB << ":" << rins << ", " << routF << ":" << routs
266  << ", " << hthick << ", 0.0, 360.0 and positioned in: " << glog.name()
267  << " number " << copy;
268 #endif
269  positionMix(ctxt, e, glog, name, copy, thickness_[ii], matter, rins, rMixLayer_[i], routs, zz);
270  }
271 
272  dd4hep::Position r1(0, 0, zz);
273  mother.placeVolume(glog, copy, r1);
274  ++copyNumber_[ii];
275 #ifdef EDM_ML_DEBUG
276  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << glog.name() << " number " << copy << " positioned in "
277  << mother.name() << " at " << r1 << " with no rotation";
278 #endif
279  zz += hthick;
280  } // End of loop over layers in a block
281  zi = zo;
282  laymin = laymax;
283  if (std::abs(thickTot - layerThick_[i]) > tol2_) {
284  if (thickTot > layerThick_[i]) {
285  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " is smaller than "
286  << thickTot << ": thickness of all its components **** ERROR ****";
287  } else {
288  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " does not match with "
289  << thickTot << " of the components";
290  }
291  }
292  } // End of loop over blocks
293 
294 #ifdef EDM_ML_DEBUG
295  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << copies_.size() << " different wafer copy numbers";
296  int k(0);
297  for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++k) {
298  edm::LogVerbatim("HGCalGeom") << "Copy [" << k << "] : " << (*itr);
299  }
300  copies_.clear();
301  edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalHEFileAlgo construction...";
302 #endif
303  }
304 
306  xml_h e,
307  const dd4hep::Volume& glog,
308  const std::string& nameM,
309  int copyM,
310  double thick,
311  const dd4hep::Material& matter,
312  double rin,
313  double rmid,
314  double rout,
315  double zz) {
316  cms::DDNamespace ns(ctxt, e, true);
317 
318  dd4hep::Volume glog1;
319  for (unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
320  int ii = layerTypeTop_[ly];
321  copyNumberTop_[ii] = copyM;
322  }
323  for (unsigned int ly = 0; ly < layerTypeBot_.size(); ++ly) {
324  int ii = layerTypeBot_[ly];
325  copyNumberBot_[ii] = copyM;
326  }
327  double hthick = 0.5 * thick;
328  // Make the top part first
329  std::string name = nameM + "Top";
330 
331  dd4hep::Solid solid = dd4hep::Tube(rmid, rout, hthick, 0.0, 2._pi);
332  ns.addSolidNS(ns.prepend(name), solid);
333  glog1 = dd4hep::Volume(solid.name(), solid, matter);
334  ns.addVolumeNS(glog1);
335 #ifdef EDM_ML_DEBUG
336  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << solid.name() << " Tubs made of " << matter.name()
337  << " of dimensions " << rmid << ", " << rout << ", " << hthick << ", 0.0, 360.0";
338 #endif
339  glog.placeVolume(glog1, 1);
340 
341 #ifdef EDM_ML_DEBUG
342  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << glog1.name() << " number 1 positioned in " << glog.name()
343  << " at (0, 0, 0) with no rotation";
344 #endif
345  double thickTot(0), zpos(-hthick);
346  for (unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
347  int ii = layerTypeTop_[ly];
348  int copy = copyNumberTop_[ii];
349  double hthickl = 0.5 * layerThickTop_[ii];
350  thickTot += layerThickTop_[ii];
351  name = namesTop_[ii] + std::to_string(copy);
352 #ifdef EDM_ML_DEBUG
353  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: Layer " << ly << ":" << ii << " R " << rmid << ":" << rout
354  << " Thick " << layerThickTop_[ii];
355 #endif
356 
357  dd4hep::Material matter1 = ns.material(materialsTop_[ii]);
358  solid = dd4hep::Tube(rmid, rout, hthickl, 0.0, 2._pi);
359  ns.addSolidNS(ns.prepend(name), solid);
360  dd4hep::Volume glog2 = dd4hep::Volume(solid.name(), solid, matter1);
361  ns.addVolumeNS(glog2);
362 
363 #ifdef EDM_ML_DEBUG
364  double eta1 = -log(tan(0.5 * atan(rmid / zz)));
365  double eta2 = -log(tan(0.5 * atan(rout / zz)));
366  edm::LogVerbatim("HGCalGeom") << name << " z|rin|rout " << zz << ":" << rmid << ":" << rout << " eta " << eta1
367  << ":" << eta2;
368  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << solid.name() << " Tubs made of " << matter1.name()
369  << " of dimensions " << rmid << ", " << rout << ", " << hthickl << ", 0.0, 360.0";
370 #endif
371  zpos += hthickl;
372 
373  dd4hep::Position r1(0, 0, zpos);
374  glog1.placeVolume(glog2, copy, r1);
375 
376 #ifdef EDM_ML_DEBUG
377  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: Position " << glog2.name() << " number " << copy << " in "
378  << glog1.name() << " at " << r1 << " with no rotation";
379 #endif
380  ++copyNumberTop_[ii];
381  zpos += hthickl;
382  }
383  if (std::abs(thickTot - thick) > tol2_) {
384  if (thickTot > thick) {
385  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
386  << ": thickness of all its components in the top part **** ERROR ****";
387  } else {
388  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot
389  << " of the components in top part";
390  }
391  }
392 
393  // Make the bottom part next
394  name = nameM + "Bottom";
395 
396  solid = dd4hep::Tube(rin, rmid, hthick, 0.0, 2._pi);
397  ns.addSolidNS(ns.prepend(name), solid);
398  glog1 = dd4hep::Volume(solid.name(), solid, matter);
399  ns.addVolumeNS(glog1);
400 
401 #ifdef EDM_ML_DEBUG
402  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << solid.name() << " Tubs made of " << matter.name()
403  << " of dimensions " << rin << ", " << rmid << ", " << hthick << ", 0.0, 360.0";
404 #endif
405 
406  glog.placeVolume(glog1, 1);
407 #ifdef EDM_ML_DEBUG
408  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << glog1.name() << " number 1 positioned in " << glog.name()
409  << " at (0, 0, 0) with no rotation";
410 #endif
411  thickTot = 0;
412  zpos = -hthick;
413  for (unsigned int ly = 0; ly < layerTypeBot_.size(); ++ly) {
414  int ii = layerTypeBot_[ly];
415  int copy = copyNumberBot_[ii];
416  double hthickl = 0.5 * layerThickBot_[ii];
417  thickTot += layerThickBot_[ii];
418  name = namesBot_[ii] + std::to_string(copy);
419 #ifdef EDM_ML_DEBUG
420  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: Layer " << ly << ":" << ii << " R " << rin << ":" << rmid
421  << " Thick " << layerThickBot_[ii];
422 #endif
423 
424  dd4hep::Material matter1 = ns.material(materialsBot_[ii]);
425  solid = dd4hep::Tube(rin, rmid, hthickl, 0.0, 2._pi);
426  ns.addSolidNS(ns.prepend(name), solid);
427  dd4hep::Volume glog2 = dd4hep::Volume(solid.name(), solid, matter1);
428  ns.addVolumeNS(glog2);
429 
430 #ifdef EDM_ML_DEBUG
431  double eta1 = -log(tan(0.5 * atan(rin / zz)));
432  double eta2 = -log(tan(0.5 * atan(rmid / zz)));
433  edm::LogVerbatim("HGCalGeom") << name << " z|rin|rout " << zz << ":" << rin << ":" << rmid << " eta " << eta1
434  << ":" << eta2;
435  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << solid.name() << " Tubs made of " << matter1.name()
436  << " of dimensions " << rin << ", " << rmid << ", " << hthickl << ", 0.0, 360.0";
437 #endif
438  zpos += hthickl;
439 
440  dd4hep::Position r1(0, 0, zpos);
441  glog1.placeVolume(glog2, copy, r1);
442 #ifdef EDM_ML_DEBUG
443  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: Position " << glog2.name() << " number " << copy << " in "
444  << glog1.name() << " at " << r1 << " with no rotation";
445 #endif
446  if (layerSenseBot_[ly] != 0) {
447 #ifdef EDM_ML_DEBUG
448  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: z " << (zz + zpos) << " Center " << copy << ":"
449  << (copy - firstLayer_) << ":" << layerCenter_[copy - firstLayer_];
450 #endif
451  positionSensitive(ctxt, e, glog2, rin, rmid, zz + zpos, layerSenseBot_[ly], (copy - firstLayer_));
452  }
453  zpos += hthickl;
454  ++copyNumberBot_[ii];
455  }
456  if (std::abs(thickTot - thick) > tol2_) {
457  if (thickTot > thick) {
458  edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
459  << ": thickness of all its components in the top part **** ERROR ****";
460  } else {
461  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot
462  << " of the components in top part";
463  }
464  }
465  }
466 
468  xml_h e,
469  const dd4hep::Volume& glog,
470  double rin,
471  double rout,
472  double zpos,
473  int layertype,
474  int layer) {
475  cms::DDNamespace ns(ctxt, e, true);
476  int layercenter = layerCenter_[layer];
477  static const double sqrt3 = std::sqrt(3.0);
478  double r = 0.5 * (waferSize_ + waferSepar_);
479  double R = 2.0 * r / sqrt3;
480  double dy = 0.75 * R;
481  int N = (int)(0.5 * rout / r) + 2;
482  const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
483 #ifdef EDM_ML_DEBUG
484  int ium(0), ivm(0), iumAll(0), ivmAll(0), kount(0), ntot(0), nin(0);
485  std::vector<int> ntype(6, 0);
486  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << glog.name() << " rout " << rout << " N " << N
487  << " for maximum u, v Offset; Shift " << xyoff.first << ":" << xyoff.second
488  << " WaferSize " << (waferSize_ + waferSepar_);
489 #endif
490  for (int u = -N; u <= N; ++u) {
491  for (int v = -N; v <= N; ++v) {
492 #ifdef EDM_ML_DEBUG
493  int iu = std::abs(u);
494  int iv = std::abs(v);
495 #endif
496  int nr = 2 * v;
497  int nc = -2 * u + v;
498  double xpos = xyoff.first + nc * r;
499  double ypos = xyoff.second + nr * dy;
500  const auto& corner = HGCalGeomTools::waferCorner(xpos, ypos, r, R, rin, rout, false);
501 #ifdef EDM_ML_DEBUG
502  ++ntot;
503 #endif
504  int indx = HGCalWaferIndex::waferIndex((layer + firstLayer_), u, v, false);
505  int type = HGCalWaferType::getType(indx, waferIndex_, waferTypes_);
506  if (corner.first > 0 && type >= 0) {
507  int copy = HGCalTypes::packTypeUV(type, u, v);
508 #ifdef EDM_ML_DEBUG
509  edm::LogVerbatim("HGCalGeom") << " DDHGCalHEFileAlgo: " << waferNames_[type] << " number " << copy << " type "
510  << type << " layer:u:v:indx " << (layer + firstLayer_) << ":" << u << ":" << v
511  << ":" << indx;
512  if (iu > ium)
513  ium = iu;
514  if (iv > ivm)
515  ivm = iv;
516  kount++;
517  if (copies_.count(copy) == 0)
518  copies_.insert(copy);
519 #endif
520  if (corner.first == (int)(HGCalParameters::k_CornerSize)) {
521 #ifdef EDM_ML_DEBUG
522  if (iu > iumAll)
523  iumAll = iu;
524  if (iv > ivmAll)
525  ivmAll = iv;
526  ++nin;
527 #endif
528 
529  dd4hep::Position tran(xpos, ypos, 0.0);
530  if (layertype > 1)
531  type += 3;
532  glog.placeVolume(ns.volume(waferNames_[type]), copy, tran);
533 
534 #ifdef EDM_ML_DEBUG
535  ++ntype[type];
536  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: " << glog.name() << " number " << copy
537  << " positioned in " << glog.name() << " at " << tran << " with no rotation";
538 #endif
539  }
540  }
541  }
542  }
543 #ifdef EDM_ML_DEBUG
544  edm::LogVerbatim("HGCalGeom") << "DDHGCalHEFileAlgo: Maximum # of u " << ium << ":" << iumAll << " # of v " << ivm
545  << ":" << ivmAll << " and " << nin << ":" << kount << ":" << ntot << " wafers ("
546  << ntype[0] << ":" << ntype[1] << ":" << ntype[2] << ":" << ntype[3] << ":"
547  << ntype[4] << ":" << ntype[5] << ") for " << glog.name() << " R " << rin << ":"
548  << rout;
549 #endif
550  }
551 
552  //Required data members to cache the values from XML file
554  static constexpr double tol2_ = 0.00001;
555 
556  std::vector<std::string> waferNames_; // Wafer names
557  std::vector<std::string> materials_; // Materials
558  std::vector<std::string> volumeNames_; // Names
559  std::vector<double> thickness_; // Thickness of the material
560  std::vector<int> copyNumber_; // Initial copy numbers
561  std::vector<int> layerNumbers_; // Number of layers in a section
562  std::vector<double> layerThick_; // Thickness of each section
563  std::vector<double> rMixLayer_; // Partition between Si/Sci part
564  std::vector<int> layerType_; // Type of the layer
565  std::vector<int> layerSense_; // Content of a layer (sensitive?)
566  int firstLayer_; // Copy # of the first sensitive layer
567  int absorbMode_; // Absorber mode
568  int sensitiveMode_; // Sensitive mode
569  std::vector<std::string> materialsTop_; // Materials of top layers
570  std::vector<std::string> namesTop_; // Names of top layers
571  std::vector<double> layerThickTop_; // Thickness of the top sections
572  std::vector<int> layerTypeTop_; // Type of the Top layer
573  std::vector<int> copyNumberTop_; // Initial copy numbers (top section)
574  std::vector<std::string> materialsBot_; // Materials of bottom layers
575  std::vector<std::string> namesBot_; // Names of bottom layers
576  std::vector<double> layerThickBot_; // Thickness of the bottom sections
577  std::vector<int> layerTypeBot_; // Type of the bottom layers
578  std::vector<int> copyNumberBot_; // Initial copy numbers (bot section)
579  std::vector<int> layerSenseBot_; // Content of bottom layer (sensitive?)
580  std::vector<int> layerCenter_; // Centering of the wafers
581 
582  double zMinBlock_; // Starting z-value of the block
583  std::vector<double> rad100to200_; // Parameters for 120-200mum trans.
584  std::vector<double> rad200to300_; // Parameters for 200-300mum trans.
585  double zMinRadPar_; // Minimum z for radius parametriz.
586  int choiceType_; // Type of parametrization to be used
587  int nCutRadPar_; // Cut off threshold for corners
588  double fracAreaMin_; // Minimum fractional conatined area
589  double waferSize_; // Width of the wafer
590  double waferSepar_; // Sensor separation
591  int sectors_; // Sectors
592  std::vector<int> waferIndex_; // Wafer index for the types
593  std::vector<int> waferTypes_; // Wafer types
594  std::vector<double> slopeB_; // Slope at the lower R
595  std::vector<double> zFrontB_; // Starting Z values for the slopes
596  std::vector<double> rMinFront_; // Corresponding rMin's
597  std::vector<double> slopeT_; // Slopes at the larger R
598  std::vector<double> zFrontT_; // Starting Z values for the slopes
599  std::vector<double> rMaxFront_; // Corresponding rMax's
600  std::unordered_set<int> copies_; // List of copy #'s
601  double alpha_, cosAlpha_;
602 };
603 
604 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
605  HGCalHEFileAlgo healgo(ctxt, e);
606  return cms::s_executed;
607 }
608 
609 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalHEFileAlgo, algorithm)
HGCalHEFileAlgo::waferTypes_
std::vector< int > waferTypes_
Definition: DDHGCalHEFileAlgo.cc:593
writedatasetfile.args
args
Definition: writedatasetfile.py:18
HGCalWaferIndex::waferV
static int32_t waferV(const int32_t index)
Definition: HGCalWaferIndex.cc:42
HGCalGeomTools::waferCorner
static std::pair< int32_t, int32_t > waferCorner(double xpos, double ypos, double r, double R, double rMin, double rMax, bool oldBug=false)
Definition: HGCalGeomTools.cc:223
mps_fire.i
i
Definition: mps_fire.py:428
cms_units::operators
Definition: CMSUnits.h:13
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
HGCalHEFileAlgo::materials_
std::vector< std::string > materials_
Definition: DDHGCalHEFileAlgo.cc:557
g4SimHits_cfi.Material
Material
Definition: g4SimHits_cfi.py:560
MessageLogger.h
HGCalHEFileAlgo::nCutRadPar_
int nCutRadPar_
Definition: DDHGCalHEFileAlgo.cc:587
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
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
HGCalHEFileAlgo::zFrontT_
std::vector< double > zFrontT_
Definition: DDHGCalHEFileAlgo.cc:598
HGCalHEFileAlgo::thickness_
std::vector< double > thickness_
Definition: DDHGCalHEFileAlgo.cc:559
min
T min(T a, T b)
Definition: MathUtil.h:58
HGCalHEFileAlgo::rMaxFront_
std::vector< double > rMaxFront_
Definition: DDHGCalHEFileAlgo.cc:599
cms::DDParsingContext
Definition: DDParsingContext.h:13
HGCalHEFileAlgo::layerThickTop_
std::vector< double > layerThickTop_
Definition: DDHGCalHEFileAlgo.cc:571
angle_units::operators::convertRadToDeg
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
HGCalHEFileAlgo::layerSense_
std::vector< int > layerSense_
Definition: DDHGCalHEFileAlgo.cc:565
cms::DDNamespace
Definition: DDNamespace.h:16
HGCalHEFileAlgo::copyNumberTop_
std::vector< int > copyNumberTop_
Definition: DDHGCalHEFileAlgo.cc:573
HGCalHEFileAlgo::namesTop_
std::vector< std::string > namesTop_
Definition: DDHGCalHEFileAlgo.cc:570
HGCalHEFileAlgo::layerThick_
std::vector< double > layerThick_
Definition: DDHGCalHEFileAlgo.cc:562
HGCalParameters::k_CornerSize
static constexpr uint32_t k_CornerSize
Definition: HGCalParameters.h:38
HGCalHEFileAlgo::HGCalHEFileAlgo
HGCalHEFileAlgo()
Definition: DDHGCalHEFileAlgo.cc:26
distTCMET_cfi.corner
corner
Definition: distTCMET_cfi.py:38
nin
int nin
Definition: CascadeWrapper.h:114
HGCalHEFileAlgo::sectors_
int sectors_
Definition: DDHGCalHEFileAlgo.cc:591
HGCalHEFileAlgo::copyNumberBot_
std::vector< int > copyNumberBot_
Definition: DDHGCalHEFileAlgo.cc:578
HGCalHEFileAlgo::choiceType_
int choiceType_
Definition: DDHGCalHEFileAlgo.cc:586
findQualityFiles.v
v
Definition: findQualityFiles.py:179
HGCalHEFileAlgo
Definition: DDHGCalHEFileAlgo.cc:25
HGCalHEFileAlgo::firstLayer_
int firstLayer_
Definition: DDHGCalHEFileAlgo.cc:566
HGCalHEFileAlgo::absorbMode_
int absorbMode_
Definition: DDHGCalHEFileAlgo.cc:567
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
HGCalHEFileAlgo::zFrontB_
std::vector< double > zFrontB_
Definition: DDHGCalHEFileAlgo.cc:595
HGCalHEFileAlgo::positionSensitive
void positionSensitive(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, double rin, double rout, double zpos, int layertype, int layer)
Definition: DDHGCalHEFileAlgo.cc:467
HGCalHEFileAlgo::copies_
std::unordered_set< int > copies_
Definition: DDHGCalHEFileAlgo.cc:600
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
HGCalWaferIndex.h
HGCalHEFileAlgo::rad100to200_
std::vector< double > rad100to200_
Definition: DDHGCalHEFileAlgo.cc:583
HGCalHEFileAlgo::layerNumbers_
std::vector< int > layerNumbers_
Definition: DDHGCalHEFileAlgo.cc:561
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
HLT_FULL_cff.eta2
eta2
Definition: HLT_FULL_cff.py:9542
cms::DDNamespace::prepend
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:60
HGCalHEFileAlgo::materialsBot_
std::vector< std::string > materialsBot_
Definition: DDHGCalHEFileAlgo.cc:574
HGCalWaferType.h
HGCalHEFileAlgo::rad200to300_
std::vector< double > rad200to300_
Definition: DDHGCalHEFileAlgo.cc:584
N
#define N
Definition: blowfish.cc:9
HGCalHEFileAlgo::layerSenseBot_
std::vector< int > layerSenseBot_
Definition: DDHGCalHEFileAlgo.cc:579
HGCalWaferType::getType
int getType(double xpos, double ypos, double zpos)
Definition: HGCalWaferType.cc:35
PixelTestBeamValidation_cfi.Position
Position
Definition: PixelTestBeamValidation_cfi.py:75
dqmdumpme.k
k
Definition: dqmdumpme.py:60
HGCalHEFileAlgo::zMinRadPar_
double zMinRadPar_
Definition: DDHGCalHEFileAlgo.cc:585
HGCalHEFileAlgo::layerThickBot_
std::vector< double > layerThickBot_
Definition: DDHGCalHEFileAlgo.cc:576
HGCalHEFileAlgo::copyNumber_
std::vector< int > copyNumber_
Definition: DDHGCalHEFileAlgo.cc:560
HGCalHEFileAlgo::slopeT_
std::vector< double > slopeT_
Definition: DDHGCalHEFileAlgo.cc:597
HGCalWaferIndex::waferU
static int32_t waferU(const int32_t index)
Definition: HGCalWaferIndex.cc:37
HGCalTypes::packTypeUV
static int32_t packTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:3
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_FULL_cff.eta1
eta1
Definition: HLT_FULL_cff.py:9541
HGCalHEFileAlgo::layerType_
std::vector< int > layerType_
Definition: DDHGCalHEFileAlgo.cc:564
cms::Volume
dd4hep::Volume Volume
Definition: DDFilteredView.h:47
HGCalHEFileAlgo::rMixLayer_
std::vector< double > rMixLayer_
Definition: DDHGCalHEFileAlgo.cc:563
algorithm
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
Definition: DDHGCalHEFileAlgo.cc:604
HGCalHEFileAlgo::waferIndex_
std::vector< int > waferIndex_
Definition: DDHGCalHEFileAlgo.cc:592
HGCalHEFileAlgo::layerTypeBot_
std::vector< int > layerTypeBot_
Definition: DDHGCalHEFileAlgo.cc:577
HGCalHEFileAlgo::slopeB_
std::vector< double > slopeB_
Definition: DDHGCalHEFileAlgo.cc:594
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
HGCalHEFileAlgo::rMinFront_
std::vector< double > rMinFront_
Definition: DDHGCalHEFileAlgo.cc:596
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
HGCalHEFileAlgo::layerCenter_
std::vector< int > layerCenter_
Definition: DDHGCalHEFileAlgo.cc:580
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:39
HGCalHEFileAlgo::zMinBlock_
double zMinBlock_
Definition: DDHGCalHEFileAlgo.cc:582
DDPlugins.h
HGCalHEFileAlgo::positionMix
void positionMix(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, const std::string &nameM, int copyM, double thick, const dd4hep::Material &matter, double rin, double rmid, double rout, double zz)
Definition: DDHGCalHEFileAlgo.cc:305
HGCalHEFileAlgo::HGCalHEFileAlgo
HGCalHEFileAlgo(cms::DDParsingContext &ctxt, xml_h e)
Definition: DDHGCalHEFileAlgo.cc:27
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
createfilelist.int
int
Definition: createfilelist.py:10
HGCalGeomTools
Definition: HGCalGeomTools.h:8
cms::DDNamespace::addSolidNS
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:221
cms::DDAlgoArguments
Definition: DDAlgoArguments.h:28
PVValHelper::dy
Definition: PVValidationHelpers.h:49
HGCalHEFileAlgo::waferSize_
double waferSize_
Definition: DDHGCalHEFileAlgo.cc:589
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:29
cms::DDNamespace::addVolumeNS
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
Definition: DDNamespace.cc:145
cms::s_executed
static constexpr long s_executed
Definition: DDAlgoArguments.h:16
HGCalHEFileAlgo::volumeNames_
std::vector< std::string > volumeNames_
Definition: DDHGCalHEFileAlgo.cc:558
alignCSCRings.r
r
Definition: alignCSCRings.py:93
align::Detector
Definition: StructureType.h:86
HGCalHEFileAlgo::geomTools_
HGCalGeomTools geomTools_
Definition: DDHGCalHEFileAlgo.cc:553
HGCalGeomTools.h
HGCalGeomTools::radius
static void radius(double zf, double zb, std::vector< double > const &zFront1, std::vector< double > const &rFront1, std::vector< double > const &slope1, std::vector< double > const &zFront2, std::vector< double > const &rFront2, std::vector< double > const &slope2, int flag, std::vector< double > &zz, std::vector< double > &rin, std::vector< double > &rout)
Definition: HGCalGeomTools.cc:11
diffTwoXMLs.r1
r1
Definition: diffTwoXMLs.py:53
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
HGCalHEFileAlgo::namesBot_
std::vector< std::string > namesBot_
Definition: DDHGCalHEFileAlgo.cc:575
HGCalGeometryMode::Polyhedra
Definition: HGCalGeometryMode.h:35
Exception
Definition: hltDiff.cc:246
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
HGCalWaferIndex::waferIndex
static int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV, bool old=false)
Definition: HGCalWaferIndex.cc:17
CMSUnits.h
HGCalHEFileAlgo::layerTypeTop_
std::vector< int > layerTypeTop_
Definition: DDHGCalHEFileAlgo.cc:572
HGCalHEFileAlgo::cosAlpha_
double cosAlpha_
Definition: DDHGCalHEFileAlgo.cc:601
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
HGCalHEFileAlgo::waferSepar_
double waferSepar_
Definition: DDHGCalHEFileAlgo.cc:590
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HGCalHEFileAlgo::materialsTop_
std::vector< std::string > materialsTop_
Definition: DDHGCalHEFileAlgo.cc:569
HGCalTypes.h
edm::Log
Definition: MessageLogger.h:70
HGCalHEFileAlgo::sensitiveMode_
int sensitiveMode_
Definition: DDHGCalHEFileAlgo.cc:568
cms::DDNamespace::name
std::string_view name() const
Definition: DDNamespace.h:72
HGCalHEFileAlgo::waferNames_
std::vector< std::string > waferNames_
Definition: DDHGCalHEFileAlgo.cc:556
dttmaxenums::R
Definition: DTTMax.h:29
HGCalParameters.h
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
HGCalWaferIndex::waferLayer
static int32_t waferLayer(const int32_t index)
Definition: HGCalWaferIndex.cc:35
HGCalHEFileAlgo::fracAreaMin_
double fracAreaMin_
Definition: DDHGCalHEFileAlgo.cc:588
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37