CMS 3D CMS Logo

HGCalGeomParameters.cc
Go to the documentation of this file.
2 
5 
18 #include "CLHEP/Units/GlobalPhysicalConstants.h"
19 #include "CLHEP/Units/GlobalSystemOfUnits.h"
20 
21 #include <algorithm>
22 #include <unordered_set>
23 
24 //#define EDM_ML_DEBUG
25 
26 const double tolerance = 0.001;
27 
29 #ifdef EDM_ML_DEBUG
30  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters::HGCalGeomParameters "
31  << "constructor";
32 #endif
33 }
34 
36 #ifdef EDM_ML_DEBUG
37  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters::destructed!!!";
38 #endif
39 }
40 
42  HGCalParameters& php,
43  const std::string & sdTag1,
44  const DDCompactView* cpv,
45  const std::string & sdTag2,
46  const std::string & sdTag3,
48 
49  DDFilteredView fv = _fv;
50  bool dodet(true);
51  std::map<int,HGCalGeomParameters::layerParameters> layers;
52  std::vector<HGCalParameters::hgtrform> trforms;
53  std::vector<bool> trformUse;
54 
55  while (dodet) {
56  const DDSolid & sol = fv.logicalPart().solid();
57  // Layers first
58  std::vector<int> copy = fv.copyNumbers();
59  int nsiz = (int)(copy.size());
60  int lay = (nsiz > 0) ? copy[nsiz-1] : 0;
61  int zp = (nsiz > 2) ? copy[nsiz-3] : -1;
62  if (zp != 1) zp = -1;
63  if (lay == 0) {
64  throw cms::Exception("DDException") << "Funny layer # " << lay << " zp "
65  << zp << " in " << nsiz
66  << " components";
67  } else {
68  if (std::find(php.layer_.begin(),php.layer_.end(),lay) ==
69  php.layer_.end()) php.layer_.emplace_back(lay);
70  auto itr = layers.find(lay);
71  if (itr == layers.end()) {
72  const DDTubs & tube = static_cast<DDTubs>(sol);
73  double rin = HGCalParameters::k_ScaleFromDDD*tube.rIn();
74  double rout= HGCalParameters::k_ScaleFromDDD*tube.rOut();
75  double zp = HGCalParameters::k_ScaleFromDDD*fv.translation().Z();
76  HGCalGeomParameters::layerParameters laypar(rin,rout,zp);
77  layers[lay] = laypar;
78  }
79  DD3Vector x, y, z;
80  fv.rotation().GetComponents( x, y, z ) ;
81  const CLHEP::HepRep3x3 rotation ( x.X(), y.X(), z.X(),
82  x.Y(), y.Y(), z.Y(),
83  x.Z(), y.Z(), z.Z() );
84  const CLHEP::HepRotation hr ( rotation );
86  if (std::abs(xx) < tolerance) xx = 0;
88  if (std::abs(yy) < tolerance) yy = 0;
89  const CLHEP::Hep3Vector h3v ( xx, yy, fv.translation().Z() );
91  mytrf.zp = zp;
92  mytrf.lay = lay;
93  mytrf.sec = 0;
94  mytrf.subsec= 0;
95  mytrf.h3v = h3v;
96  mytrf.hr = hr;
97  trforms.emplace_back(mytrf);
98  trformUse.emplace_back(false);
99  }
100  dodet = fv.next();
101  }
102 
103  // Then wafers
104  // This assumes layers are build starting from 1 (which on 25 Jan 2016, they were)
105  // to ensure that new copy numbers are always added
106  // to the end of the list.
107  std::unordered_map<int32_t,int32_t> copies;
108  HGCalParameters::layer_map copiesInLayers(layers.size()+1);
109  std::vector<int32_t> wafer2copy;
110  std::vector<HGCalGeomParameters::cellParameters> wafers;
111  std::string attribute = "Volume";
112  DDValue val1(attribute, sdTag2, 0.0);
113  DDSpecificsMatchesValueFilter filter1{val1};
114  DDFilteredView fv1(*cpv,filter1);
115  bool ok = fv1.firstChild();
116  if (!ok) {
117  edm::LogError("HGCalGeom") << " Attribute " << val1
118  << " not found but needed.";
119  throw cms::Exception("DDException") << "Attribute " << val1
120  << " not found but needed.";
121  } else {
122  dodet = true;
123  std::unordered_set<std::string> names;
124  while (dodet) {
125  const DDSolid & sol = fv1.logicalPart().solid();
126  const std::string & name = fv1.logicalPart().name().name();
127  std::vector<int> copy = fv1.copyNumbers();
128  int nsiz = (int)(copy.size());
129  int wafer = (nsiz > 0) ? copy[nsiz-1] : 0;
130  int layer = (nsiz > 1) ? copy[nsiz-2] : 0;
131  if (nsiz < 2) {
132  edm::LogError("HGCalGeom") << "Funny wafer # " << wafer << " in "
133  << nsiz << " components";
134  throw cms::Exception("DDException") << "Funny wafer # " << wafer;
135  } else {
136  auto itr = copies.find(wafer);
137  auto cpy = copiesInLayers[layer].find(wafer);
138  if (itr != copies.end() && cpy == copiesInLayers[layer].end()) {
139  copiesInLayers[layer][wafer] = itr->second;
140  }
141  if (itr == copies.end()) {
142  copies[wafer] = wafer2copy.size();
143  copiesInLayers[layer][wafer] = wafer2copy.size();
145  if (std::abs(xx) < tolerance) xx = 0;
147  if (std::abs(yy) < tolerance) yy = 0;
148  wafer2copy.emplace_back(wafer);
150  HGCalGeomParameters::cellParameters cell(false,wafer,p);
151  wafers.emplace_back(cell);
152  if ( names.count(name) == 0 ) {
153  std::vector<double> zv, rv;
154  if (mode == HGCalGeometryMode::Polyhedra) {
155  const DDPolyhedra & polyhedra = static_cast<DDPolyhedra>(sol);
156  zv = polyhedra.zVec();
157  rv = polyhedra.rMaxVec();
158  } else {
159  const DDExtrudedPolygon & polygon = static_cast<DDExtrudedPolygon>(sol);
160  zv = polygon.zVec();
161  rv = polygon.xVec();
162  }
163  php.waferR_ = rv[0]/std::cos(30.0*CLHEP::deg);
165  double dz = 0.5*(zv[1]-zv[0]);
166 #ifdef EDM_ML_DEBUG
167  edm::LogVerbatim("HGCalGeom") << "Mode " << mode << " R "
168  << php.waferSize_ << ":"
169  << php.waferR_ << " z " << dz;
170 #endif
172  mytr.lay = 1; mytr.bl = php.waferR_;
173  mytr.tl = php.waferR_; mytr.h = php.waferR_;
174  mytr.dz = dz; mytr.alpha = 0.0;
175  mytr.cellSize = waferSize_;
176  php.fillModule(mytr,false);
177  names.insert(name);
178  }
179  }
180  }
181  dodet = fv1.next();
182  }
183  }
184 
185  // Finally the cells
186  std::map<int,int> wafertype;
187  std::map<int,HGCalGeomParameters::cellParameters> cellsf, cellsc;
188  DDValue val2(attribute, sdTag3, 0.0);
189  DDSpecificsMatchesValueFilter filter2{val2};
190  DDFilteredView fv2(*cpv,filter2);
191  ok = fv2.firstChild();
192  if (!ok) {
193  edm::LogError("HGCalGeom") << " Attribute " << val2
194  << " not found but needed.";
195  throw cms::Exception("DDException") << "Attribute " << val2
196  << " not found but needed.";
197  } else {
198  dodet = true;
199  while (dodet) {
200  const DDSolid & sol = fv2.logicalPart().solid();
201  const std::string & name = sol.name().name();
202  std::vector<int> copy = fv2.copyNumbers();
203  int nsiz = (int)(copy.size());
204  int cellx= (nsiz > 0) ? copy[nsiz-1] : 0;
205  int wafer= (nsiz > 1) ? copy[nsiz-2] : 0;
206  int cell = cellx%1000;
207  int type = cellx/1000;
208  if (type != 1 && type != 2) {
209  edm::LogError("HGCalGeom") << "Funny cell # " << cell << " type "
210  << type << " in " << nsiz << " components";
211  throw cms::Exception("DDException") << "Funny cell # " << cell;
212  } else {
213  auto ktr = wafertype.find(wafer);
214  if (ktr == wafertype.end()) wafertype[wafer] = type;
215  bool newc(false);
216  std::map<int,HGCalGeomParameters::cellParameters>::iterator itr;
217  double cellsize = php.cellSize_[0];
218  if (type == 1) {
219  itr = cellsf.find(cell);
220  newc= (itr == cellsf.end());
221  } else {
222  itr = cellsc.find(cell);
223  newc= (itr == cellsc.end());
224  cellsize = php.cellSize_[1];
225  }
226  if (newc) {
227  bool half = (name.find("Half") != std::string::npos);
230  if (half) {
231  math::XYZPointD p1(-2.0*cellsize/9.0,0,0);
232  math::XYZPointD p2 = fv2.rotation()(p1);
233  xx += (HGCalParameters::k_ScaleFromDDD*(p2.X()));
234  yy += (HGCalParameters::k_ScaleFromDDD*(p2.Y()));
235 #ifdef EDM_ML_DEBUG
236  edm::LogVerbatim("HGCalGeom") << "Type " << type << " Cell "
237  << cellx << " local " << xx << ":"
238  << yy << " new " << p1 << ":"<< p2;
239 #endif
240  }
242  if (type == 1) {
243  cellsf[cell] = cp;
244  } else {
245  cellsc[cell] = cp;
246  }
247  }
248  }
249  dodet = fv2.next();
250  }
251  }
252 
253  if (((cellsf.size()+cellsc.size())==0) || (wafers.empty()) ||
254  (layers.empty())) {
255  edm::LogError("HGCalGeom") << "HGCalGeomParameters : number of cells "
256  << cellsf.size() << ":" << cellsc.size()
257  << " wafers " << wafers.size() << " layers "
258  << layers.size() << " illegal";
259  throw cms::Exception("DDException")
260  << "HGCalGeomParameters: mismatch between geometry and specpar: cells "
261  << cellsf.size() << ":" << cellsc.size() << " wafers " << wafers.size()
262  << " layers " << layers.size();
263  }
264 
265  for (unsigned int i=0; i<layers.size(); ++i) {
266  for (auto & layer : layers) {
267  if (layer.first == (int)(i+php.firstLayer_)) {
268  php.layerIndex_.emplace_back(i);
269  php.rMinLayHex_.emplace_back(layer.second.rmin);
270  php.rMaxLayHex_.emplace_back(layer.second.rmax);
271  php.zLayerHex_.emplace_back(layer.second.zpos);
272  break;
273  }
274  }
275  }
276  for (unsigned int i=0; i<php.layer_.size(); ++i) {
277  for (unsigned int i1=0; i1<trforms.size(); ++i1) {
278  if (!trformUse[i1] && php.layerGroup_[trforms[i1].lay-1] ==
279  (int)(i+1)) {
280  trforms[i1].h3v *= HGCalParameters::k_ScaleFromDDD;
281  trforms[i1].lay = (i+1);
282  trformUse[i1] = true;
283  php.fillTrForm(trforms[i1]);
284  int nz(1);
285  for (unsigned int i2=i1+1; i2<trforms.size(); ++i2) {
286  if (!trformUse[i2] && trforms[i2].zp == trforms[i1].zp &&
287  php.layerGroup_[trforms[i2].lay-1] == (int)(i+1)) {
288  php.addTrForm(HGCalParameters::k_ScaleFromDDD*trforms[i2].h3v);
289  nz++;
290  trformUse[i2] = true;
291  }
292  }
293  if (nz > 0) {
294  php.scaleTrForm(double(1.0/nz));
295  }
296  }
297  }
298  }
299 
300  double rmin = HGCalParameters::k_ScaleFromDDD*php.waferR_;
301  for (unsigned i = 0; i < wafer2copy.size(); ++i ) {
302  php.waferCopy_.emplace_back(wafer2copy[i]);
303  php.waferPosX_.emplace_back(wafers[i].xyz.x());
304  php.waferPosY_.emplace_back(wafers[i].xyz.y());
305  auto ktr = wafertype.find(wafer2copy[i]);
306  int typet = (ktr == wafertype.end()) ? 0 : (ktr->second);
307  php.waferTypeT_.emplace_back(typet);
308  double r = wafers[i].xyz.perp();
309  int type(3);
310  for (int k=1; k<4; ++k) {
311  if ((r+rmin)<=php.boundR_[k]) {
312  type = k; break;
313  }
314  }
315  php.waferTypeL_.emplace_back(type);
316  }
317  php.copiesInLayers_ = copiesInLayers;
318  php.nSectors_ = (int)(php.waferCopy_.size());
319 
320  std::vector<HGCalGeomParameters::cellParameters>::const_iterator itrf = wafers.end();
321  for (unsigned int i=0; i<cellsf.size(); ++i) {
322  auto itr = cellsf.find(i);
323  if (itr == cellsf.end()) {
324  edm::LogError("HGCalGeom") << "HGCalGeomParameters: missing info for"
325  << " fine cell number " << i;
326  throw cms::Exception("DDException")
327  << "HGCalGeomParameters: missing info for fine cell number " << i;
328  } else {
329  double xx = (itr->second).xyz.x();
330  double yy = (itr->second).xyz.y();
331  int waf= (itr->second).wafer;
332  std::pair<double,double> xy = cellPosition(wafers,itrf,waf,xx,yy);
333  php.cellFineX_.emplace_back(xy.first);
334  php.cellFineY_.emplace_back(xy.second);
335  php.cellFineHalf_.emplace_back((itr->second).half);
336  }
337  }
338  itrf = wafers.end();
339  for (unsigned int i=0; i<cellsc.size(); ++i) {
340  auto itr = cellsc.find(i);
341  if (itr == cellsc.end()) {
342  edm::LogError("HGCalGeom") << "HGCalGeomParameters: missing info for"
343  << " coarse cell number " << i;
344  throw cms::Exception("DDException")
345  << "HGCalGeomParameters: missing info for coarse cell number " << i;
346  } else {
347  double xx = (itr->second).xyz.x();
348  double yy = (itr->second).xyz.y();
349  int waf= (itr->second).wafer;
350  std::pair<double,double> xy = cellPosition(wafers,itrf,waf,xx,yy);
351  php.cellCoarseX_.emplace_back(xy.first);
352  php.cellCoarseY_.emplace_back(xy.second);
353  php.cellCoarseHalf_.emplace_back((itr->second).half);
354  }
355  }
356  int depth(0);
357  for (unsigned int i=0; i<php.layerGroup_.size(); ++i) {
358  bool first(true);
359  for (unsigned int k=0; k<php.layerGroup_.size(); ++k) {
360  if (php.layerGroup_[k] == (int)(i+1)) {
361  if (first) {
362  php.depth_.emplace_back(i+1);
363  php.depthIndex_.emplace_back(depth);
364  php.depthLayerF_.emplace_back(k);
365  ++depth;
366  first = false;
367  }
368  }
369  }
370  }
371  HGCalParameters::hgtrap mytr = php.getModule(0, false);
377  double dz = mytr.dz;
378  php.fillModule(mytr, true);
379  mytr.dz = 2*dz;
380  php.fillModule(mytr, true);
381  mytr.dz = 3*dz;
382  php.fillModule(mytr, true);
383 #ifdef EDM_ML_DEBUG
384  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters finds "
385  << php.zLayerHex_.size() << " layers";
386  for (unsigned int i=0; i<php.zLayerHex_.size(); ++i) {
387  int k = php.layerIndex_[i];
388  edm::LogVerbatim("HGCalGeom") << "Layer[" << i << ":" << k << ":"
389  << php.layer_[k] << "] with r = "
390  << php.rMinLayHex_[i] << ":"
391  << php.rMaxLayHex_[i] << " at z = "
392  << php.zLayerHex_[i];
393  }
394  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters has "
395  << php.depthIndex_.size() << " depths";
396  for (unsigned int i=0; i<php.depthIndex_.size(); ++i) {
397  int k = php.depthIndex_[i];
398  edm::LogVerbatim("HGCalGeom") << "Reco Layer[" << i << ":" << k
399  << "] First Layer " << php.depthLayerF_[i]
400  << " Depth " << php.depth_[k];
401  }
402  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters finds "
403  << php.nSectors_ << " wafers";
404  for (unsigned int i=0; i<php.waferCopy_.size(); ++i)
405  edm::LogVerbatim("HGCalGeom") << "Wafer[" << i << ": " <<php.waferCopy_[i]
406  << "] type " << php.waferTypeL_[i] << ":"
407  << php.waferTypeT_[i] << " at ("
408  << php.waferPosX_[i] << ","
409  << php.waferPosY_[i] << ",0)";
410  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: wafer radius "
411  << php.waferR_ << " and dimensions of the "
412  << "wafers:";
413  edm::LogVerbatim("HGCalGeom") << "Sim[0] " << php.moduleLayS_[0] << " dx "
414  << php.moduleBlS_[0] << ":"
415  << php.moduleTlS_[0] << " dy "
416  << php.moduleHS_[0] << " dz "
417  << php.moduleDzS_[0] << " alpha "
418  << php.moduleAlphaS_[0];
419  for (unsigned int k=0; k<php.moduleLayR_.size(); ++k)
420  edm::LogVerbatim("HGCalGeom") << "Rec[" << k << "] " << php.moduleLayR_[k]
421  << " dx " << php.moduleBlR_[k] << ":"
422  << php.moduleTlR_[k] << " dy "
423  << php.moduleHR_[k] << " dz "
424  << php.moduleDzR_[k] << " alpha "
425  << php.moduleAlphaR_[k];
426  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters finds "
427  << php.cellFineX_.size()
428  << " fine cells in a wafer";
429  for (unsigned int i=0; i<php.cellFineX_.size(); ++i)
430  edm::LogVerbatim("HGCalGeom") << "Fine Cell[" << i << "] at ("
431  << php.cellFineX_[i] << ","
432  << php.cellFineY_[i] << ",0)";
433  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters finds "
434  << php.cellCoarseX_.size()
435  << " coarse cells in a wafer";
436  for (unsigned int i=0; i<php.cellCoarseX_.size(); ++i)
437  edm::LogVerbatim("HGCalGeom") << "Coarse Cell[" << i << "] at ("
438  << php.cellCoarseX_[i]
439  << "," << php.cellCoarseY_[i] << ",0)";
440  edm::LogVerbatim("HGCalGeom") << "Obtained " << php.trformIndex_.size()
441  << " transformation matrices";
442  for (unsigned int k=0; k<php.trformIndex_.size(); ++k) {
443  edm::LogVerbatim("HGCalGeom") << "Matrix[" << k << "] (" << std::hex
444  << php.trformIndex_[k]
445  << std::dec << ") Translation ("
446  << php.trformTranX_[k] << ", "
447  << php.trformTranY_[k] << ", "
448  << php.trformTranZ_[k] << " Rotation ("
449  << php.trformRotXX_[k] << ", "
450  << php.trformRotYX_[k] << ", "
451  << php.trformRotZX_[k] << ", "
452  << php.trformRotXY_[k] << ", "
453  << php.trformRotYY_[k] << ", "
454  << php.trformRotZY_[k] << ", "
455  << php.trformRotXZ_[k] << ", "
456  << php.trformRotYZ_[k] << ", "
457  << php.trformRotZZ_[k] << ")";
458  }
459  edm::LogVerbatim("HGCalGeom") << "Dump copiesInLayers for "
460  << php.copiesInLayers_.size()
461  << " layers";
462  for (unsigned int k=0; k<php.copiesInLayers_.size(); ++k) {
463  const auto& theModules = php.copiesInLayers_[k];
464  edm::LogVerbatim("HGCalGeom") << "Layer " << k << ":" <<theModules.size();
465  int k2(0);
466  for (std::unordered_map<int, int>::const_iterator itr=theModules.begin();
467  itr != theModules.end(); ++itr, ++k2) {
468  edm::LogVerbatim("HGCalGeom") << "[" << k2 << "] " << itr->first << ":"
469  << itr->second;
470  }
471  }
472 #endif
473 }
474 
476  HGCalParameters& php,
477  int firstLayer) {
478 
479  DDFilteredView fv = _fv;
480  bool dodet(true);
481  std::map<int,HGCalGeomParameters::layerParameters> layers;
482  std::map<std::pair<int,int>,HGCalParameters::hgtrform> trforms;
483  int levelTop = 3+std::max(php.levelT_[0],php.levelT_[1]);
484  while (dodet) {
485  const DDSolid & sol = fv.logicalPart().solid();
486  // Layers first
487  std::vector<int> copy = fv.copyNumbers();
488  int nsiz = (int)(copy.size());
489  int lay = (nsiz > levelTop) ? copy[nsiz-4] : copy[nsiz-1];
490  int zside= (nsiz > php.levelZSide_) ? copy[php.levelZSide_] : -1;
491  if (zside != 1) zside = -1;
492  if (lay == 0) {
493  edm::LogError("HGCalGeom") << "Funny layer # " << lay << " zp "
494  << zside << " in " << nsiz << " components";
495  throw cms::Exception("DDException") << "Funny layer # " << lay;
496  } else {
497  if (std::find(php.layer_.begin(),php.layer_.end(),lay) ==
498  php.layer_.end()) php.layer_.emplace_back(lay);
499  auto itr = layers.find(lay);
500  if (itr == layers.end()) {
501  const DDTubs & tube = static_cast<DDTubs>(sol);
502  double rin = HGCalParameters::k_ScaleFromDDD*tube.rIn();
503  double rout= HGCalParameters::k_ScaleFromDDD*tube.rOut();
504  double zp = HGCalParameters::k_ScaleFromDDD*fv.translation().Z();
505  HGCalGeomParameters::layerParameters laypar(rin,rout,zp);
506  layers[lay] = laypar;
507  }
508  if (trforms.find(std::make_pair(lay,zside)) == trforms.end()) {
509  DD3Vector x, y, z;
510  fv.rotation().GetComponents( x, y, z ) ;
511  const CLHEP::HepRep3x3 rotation ( x.X(), y.X(), z.X(),
512  x.Y(), y.Y(), z.Y(),
513  x.Z(), y.Z(), z.Z() );
514  const CLHEP::HepRotation hr ( rotation );
515  double xx = ((std::abs(fv.translation().X()) < tolerance) ? 0 :
516  fv.translation().X());
517  double yy = ((std::abs(fv.translation().Y()) < tolerance) ? 0 :
518  fv.translation().Y());
519  const CLHEP::Hep3Vector h3v (xx, yy, fv.translation().Z());
521  mytrf.zp = zside;
522  mytrf.lay = lay;
523  mytrf.sec = 0;
524  mytrf.subsec= 0;
525  mytrf.h3v = h3v;
526  mytrf.hr = hr;
527  trforms[std::make_pair(lay,zside)] = mytrf;
528  }
529  }
530  dodet = fv.next();
531  }
532 
533  double rmin(0), rmax(0);
534  for (unsigned int i=0; i<layers.size(); ++i) {
535  for (auto & layer : layers) {
536  if (layer.first == (int)(i+firstLayer)) {
537  php.layerIndex_.emplace_back(i);
538  php.rMinLayHex_.emplace_back(layer.second.rmin);
539  php.rMaxLayHex_.emplace_back(layer.second.rmax);
540  php.zLayerHex_.emplace_back(layer.second.zpos);
541  if (i == 0) {
542  rmin = layer.second.rmin; rmax = layer.second.rmax;
543  } else {
544  if (rmin > layer.second.rmin) rmin = layer.second.rmin;
545  if (rmax < layer.second.rmax) rmax = layer.second.rmax;
546  }
547  break;
548  }
549  }
550  }
551  php.rLimit_.emplace_back(rmin);
552  php.rLimit_.emplace_back(rmax);
553  php.depth_ = php.layer_;
554  php.depthIndex_ = php.layerIndex_;
555  php.depthLayerF_= php.layerIndex_;
556 
557  for (unsigned int i=0; i<php.layer_.size(); ++i) {
558  for (auto & trform : trforms) {
559  if (trform.first.first == (int)(i+firstLayer)) {
560  trform.second.h3v *= HGCalParameters::k_ScaleFromDDD;
561  php.fillTrForm(trform.second);
562  }
563  }
564  }
565 #ifdef EDM_ML_DEBUG
566  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: Minimum/maximum R "
567  << php.rLimit_[0] << ":" << php.rLimit_[1];
568  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters finds "
569  << php.zLayerHex_.size() << " layers";
570  for (unsigned int i=0; i<php.zLayerHex_.size(); ++i) {
571  int k = php.layerIndex_[i];
572  edm::LogVerbatim("HGCalGeom") << "Layer[" << i << ":" << k << ":"
573  << php.layer_[k] << "] with r = "
574  << php.rMinLayHex_[i] << ":"
575  << php.rMaxLayHex_[i] << " at z = "
576  << php.zLayerHex_[i];
577  }
578  edm::LogVerbatim("HGCalGeom") << "Obtained " << php.trformIndex_.size()
579  << " transformation matrices";
580  for (unsigned int k=0; k<php.trformIndex_.size(); ++k) {
581  edm::LogVerbatim("HGCalGeom") << "Matrix[" << k << "] (" << std::hex
582  << php.trformIndex_[k]
583  << std::dec << ") Translation ("
584  << php.trformTranX_[k] << ", "
585  << php.trformTranY_[k] << ", "
586  << php.trformTranZ_[k] << " Rotation ("
587  << php.trformRotXX_[k] << ", "
588  << php.trformRotYX_[k] << ", "
589  << php.trformRotZX_[k] << ", "
590  << php.trformRotXY_[k] << ", "
591  << php.trformRotYY_[k] << ", "
592  << php.trformRotZY_[k] << ", "
593  << php.trformRotXZ_[k] << ", "
594  << php.trformRotYZ_[k] << ", "
595  << php.trformRotZZ_[k] << ")";
596  }
597 #endif
598 }
599 
601  HGCalParameters& php,
602  const DDCompactView* cpv,
603  const std::string & sdTag1,
604  const std::string & sdTag2) {
605 
607  php.boundR_ = getDDDArray("RadiusBound",sv,4);
608  std::for_each(php.boundR_.begin(), php.boundR_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
609 #ifdef EDM_ML_DEBUG
610  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: wafer radius ranges"
611  << " for cell grouping " << php.boundR_[0]
612  << ":" << php.boundR_[1] << ":"
613  << php.boundR_[2] << ":" << php.boundR_[3];
614 #endif
615  php.rLimit_ = getDDDArray("RadiusLimits",sv,2);
616  std::for_each(php.rLimit_.begin(), php.rLimit_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
617 #ifdef EDM_ML_DEBUG
618  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: Minimum/maximum R "
619  << php.rLimit_[0] << ":" << php.rLimit_[1];
620 #endif
621  php.levelT_ = dbl_to_int(getDDDArray("LevelTop",sv,0));
622 #ifdef EDM_ML_DEBUG
623  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: LevelTop "
624  << php.levelT_[0];
625 #endif
626 
627  //Grouping of layers
628  php.layerGroup_ = dbl_to_int(getDDDArray("GroupingZFine",sv,0));
629  php.layerGroupM_ = dbl_to_int(getDDDArray("GroupingZMid",sv,0));
630  php.layerGroupO_ = dbl_to_int(getDDDArray("GroupingZOut",sv,0));
631  php.slopeMin_ = getDDDArray("Slope",sv,1);
632 #ifdef EDM_ML_DEBUG
633  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: minimum slope "
634  << php.slopeMin_[0] << " and layer groupings "
635  << "for the 3 ranges:";
636  for (unsigned int k=0; k<php.layerGroup_.size(); ++k)
637  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << php.layerGroup_[k]
638  << ":" << php.layerGroupM_[k] << ":"
639  << php.layerGroupO_[k];
640 #endif
641 
642  //Wafer size
643  std::string attribute = "Volume";
644  DDSpecificsMatchesValueFilter filter1{DDValue(attribute, sdTag1, 0.0)};
645  DDFilteredView fv1(*cpv,filter1);
646  if (fv1.firstChild()) {
648  const auto & dummy = getDDDArray("WaferSize",sv,0);
649  waferSize_ = dummy[0];
650  }
651 #ifdef EDM_ML_DEBUG
652  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: Wafer Size: "
653  << waferSize_;
654 #endif
655 
656  //Cell size
657  DDSpecificsMatchesValueFilter filter2{DDValue(attribute, sdTag2, 0.0)};
658  DDFilteredView fv2(*cpv,filter2);
659  if (fv2.firstChild()) {
661  php.cellSize_ = getDDDArray("CellSize",sv,0);
662  }
663 #ifdef EDM_ML_DEBUG
664  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: "
665  << php.cellSize_.size() << " cells of sizes:";
666  for (unsigned int k=0; k<php.cellSize_.size(); ++k)
667  edm::LogVerbatim("HGCalGeom") << " [" << k << "] " << php.cellSize_[k];
668 #endif
669 
670 }
671 
673  HGCalParameters& php) {
674 
676  php.cellThickness_ = getDDDArray("CellThickness",sv,3);
677  std::for_each(php.cellThickness_.begin(), php.cellThickness_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
678 #ifdef EDM_ML_DEBUG
679  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: cell Thickness "
680  << php.cellThickness_[0] << ":"
681  << php.cellThickness_[1] << ":"
682  << php.cellThickness_[2];
683 #endif
684  php.radius100to200_ = getDDDArray("Radius100to200",sv,5);
685 #ifdef EDM_ML_DEBUG
686  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: Polynomial "
687  << "parameters for 120 to 200 micron "
688  << "transition " << php.radius100to200_[0]
689  << ":" << php.radius100to200_[1] << ":"
690  << php.radius100to200_[2] << ":"
691  << php.radius100to200_[3] << ":"
692  << php.radius100to200_[4];
693 #endif
694  php.radius200to300_ = getDDDArray("Radius200to300",sv,5);
695 #ifdef EDM_ML_DEBUG
696  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: Polynomial "
697  << "parameters for 200 to 300 micron "
698  << "transition " << php.radius200to300_[0]
699  << ":" << php.radius200to300_[1] << ":"
700  << php.radius200to300_[2] << ":"
701  << php.radius200to300_[3] << ":"
702  << php.radius200to300_[4];
703 #endif
704  const auto & dummy = getDDDArray("RadiusCuts",sv,4);
705  php.choiceType_ = (int)(dummy[0]);
706  php.nCornerCut_ = (int)(dummy[1]);
707  php.fracAreaMin_= dummy[2];
709 #ifdef EDM_ML_DEBUG
710  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: Parameters for the"
711  << " transition " << php.choiceType_ << ":"
712  << php.nCornerCut_ << ":" << php.fracAreaMin_
713  << ":" << php.zMinForRad_;
714 #endif
715  php.radiusMixBoundary_ = DDVectorGetter::get("RadiusMixBoundary");
716  std::for_each(php.radiusMixBoundary_.begin(), php.radiusMixBoundary_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
717 #ifdef EDM_ML_DEBUG
718  for (unsigned int k = 0; k < php.radiusMixBoundary_.size(); ++k)
719  edm::LogVerbatim("HGCalGeom") << "HGCalParameters: Mix[" << k << "] R = "
720  << php.radiusMixBoundary_[k];
721 #endif
722  php.slopeMin_ = getDDDArray("SlopeBottom",sv,0);
723  php.zFrontMin_ = getDDDArray("ZFrontBottom",sv,0);
724  std::for_each(php.zFrontMin_.begin(), php.zFrontMin_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
725  php.rMinFront_ = getDDDArray("RMinFront",sv,0);
726  std::for_each(php.rMinFront_.begin(), php.rMinFront_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
727 #ifdef EDM_ML_DEBUG
728  for (unsigned int k = 0; k < php.zFrontMin_.size(); ++k)
729  edm::LogVerbatim("HGCalGeom") << "HGCalParameters: Boundary[" << k
730  << "] Bottom Z = " << php.zFrontMin_[k]
731  << " Slope = " << php.slopeMin_[k]
732  << " rMax = " << php.rMinFront_[k];
733 #endif
734  php.slopeTop_ = getDDDArray("SlopeTop",sv,0);
735  php.zFrontTop_ = getDDDArray("ZFrontTop",sv,0);
736  std::for_each(php.zFrontTop_.begin(), php.zFrontTop_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
737  php.rMaxFront_ = getDDDArray("RMaxFront",sv,0);
738  std::for_each(php.rMaxFront_.begin(), php.rMaxFront_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
739 #ifdef EDM_ML_DEBUG
740  for (unsigned int k = 0; k < php.zFrontTop_.size(); ++k)
741  edm::LogVerbatim("HGCalGeom") << "HGCalParameters: Boundary[" << k
742  << "] Top Z = " << php.zFrontTop_[k]
743  << " Slope = " << php.slopeTop_[k]
744  << " rMax = " << php.rMaxFront_[k];
745 #endif
746  php.zRanges_ = DDVectorGetter::get("ZRanges");
747  std::for_each(php.zRanges_.begin(), php.zRanges_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
748 #ifdef EDM_ML_DEBUG
749  edm::LogVerbatim("HGCalGeom") << "HGCalParameters: Z-Boundary "
750  << php.zRanges_[0] << ":" << php.zRanges_[1]
751  << ":" << php.zRanges_[2] << ":"
752  << php.zRanges_[3];
753 #endif
754 }
755 
757  HGCalParameters& php) {
758 
760  php.radiusMixBoundary_ = DDVectorGetter::get("RadiusMixBoundary");
761  std::for_each(php.radiusMixBoundary_.begin(), php.radiusMixBoundary_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
762  php.nPhiBinBH_ = dbl_to_int(getDDDArray("NPhiBinBH",sv,0));
763  php.layerFrontBH_ = dbl_to_int(getDDDArray("LayerFrontBH",sv,0));
764  php.rMinLayerBH_ = getDDDArray("RMinLayerBH",sv,0);
765  std::for_each(php.rMinLayerBH_.begin(), php.rMinLayerBH_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
766  php.nCellsFine_ = php.nPhiBinBH_[0];
767  php.nCellsCoarse_ = php.nPhiBinBH_[1];
768  php.cellSize_.emplace_back(2.0*M_PI/php.nCellsFine_);
769  php.cellSize_.emplace_back(2.0*M_PI/php.nCellsCoarse_);
770 #ifdef EDM_ML_DEBUG
771  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters:nCells "
772  << php.nCellsFine_ << ":" << php.nCellsCoarse_
773  << " cellSize: " << php.cellSize_[0] << ":"
774  << php.cellSize_[1];
775  for (unsigned int k=0; k<php.layerFrontBH_.size(); ++k)
776  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: Type[" << k
777  << "] Front Layer = " << php.layerFrontBH_[k]
778  << " rMin = " << php.rMinLayerBH_[k];
779  for (unsigned int k = 0; k < php.radiusMixBoundary_.size(); ++k) {
780  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: Mix[" << k
781  << "] R = " << php.radiusMixBoundary_[k]
782  << " Nphi = " << php.scintCells(k+php.firstLayer_)
783  << " dPhi = " << php.scintCellSize(k+php.firstLayer_);
784  }
785 #endif
786  php.slopeMin_ = getDDDArray("SlopeBottom",sv,0);
787  php.zFrontMin_ = getDDDArray("ZFrontBottom",sv,0);
788  std::for_each(php.zFrontMin_.begin(), php.zFrontMin_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
789  php.rMinFront_ = getDDDArray("RMinFront",sv,0);
790  std::for_each(php.rMinFront_.begin(), php.rMinFront_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
791 #ifdef EDM_ML_DEBUG
792  for (unsigned int k = 0; k < php.zFrontMin_.size(); ++k)
793  edm::LogVerbatim("HGCalGeom") << "HGCalParameters: Boundary[" << k
794  << "] Bottom Z = " << php.zFrontMin_[k]
795  << " Slope = " << php.slopeMin_[k]
796  << " rMax = " << php.rMinFront_[k];
797 #endif
798  php.slopeTop_ = getDDDArray("SlopeTop",sv,0);
799  php.zFrontTop_ = getDDDArray("ZFrontTop",sv,0);
800  std::for_each(php.zFrontTop_.begin(), php.zFrontTop_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
801  php.rMaxFront_ = getDDDArray("RMaxFront",sv,0);
802  std::for_each(php.rMaxFront_.begin(), php.rMaxFront_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
803 #ifdef EDM_ML_DEBUG
804  for (unsigned int k = 0; k < php.zFrontTop_.size(); ++k)
805  edm::LogVerbatim("HGCalGeom") << "HGCalParameters: Boundary[" << k
806  << "] Top Z = " << php.zFrontTop_[k]
807  << " Slope = " << php.slopeTop_[k]
808  << " rMax = " << php.rMaxFront_[k];
809 #endif
810  php.zRanges_ = DDVectorGetter::get("ZRanges");
811  std::for_each(php.zRanges_.begin(), php.zRanges_.end(), [](double &n){ n*=HGCalParameters::k_ScaleFromDDD; });
812 #ifdef EDM_ML_DEBUG
813  edm::LogVerbatim("HGCalGeom") << "HGCalParameters: Z-Boundary "
814  << php.zRanges_[0] << ":" << php.zRanges_[1]
815  << ":" << php.zRanges_[2] << ":"
816  << php.zRanges_[3];
817 #endif
818 }
819 
821 
823  double rin(php.rLimit_[0]), rout(php.rLimit_[1]), rMaxFine(php.boundR_[1]);
824 #ifdef EDM_ML_DEBUG
825  edm::LogVerbatim("HGCalGeom") << "Input waferWidth " << waferW << ":"
826  << rmin << " R Limits: " << rin << ":"
827  << rout << " Fine " << rMaxFine;
828 #endif
829  // Clear the vectors
830  php.waferCopy_.clear();
831  php.waferTypeL_.clear();
832  php.waferTypeT_.clear();
833  php.waferPosX_.clear();
834  php.waferPosY_.clear();
835  double dx = 0.5*waferW;
836  double dy = 3.0*dx*tan(30.0*CLHEP::deg);
837  double rr = 2.0*dx*tan(30.0*CLHEP::deg);
838  int ncol = (int)(2.0*rout/waferW) + 1;
839  int nrow = (int)(rout/(waferW*tan(30.0*CLHEP::deg))) + 1;
840  int incm(0), inrm(0), kount(0), ntot(0);
842  HGCalParameters::layer_map copiesInLayers(php.layer_.size()+1);
843 #ifdef EDM_ML_DEBUG
844  edm::LogVerbatim("HGCalGeom") << "Row " << nrow << " Column " << ncol;
845 #endif
846  for (int nr=-nrow; nr <= nrow; ++nr) {
847  int inr = (nr >= 0) ? nr : -nr;
848  for (int nc=-ncol; nc <= ncol; ++nc) {
849  int inc = (nc >= 0) ? nc : -nc;
850  if (inr%2 == inc%2) {
851  double xpos = nc*dx;
852  double ypos = nr*dy;
853  xc[0] = xpos+dx; yc[0] = ypos-0.5*rr;
854  xc[1] = xpos+dx; yc[1] = ypos+0.5*rr;
855  xc[2] = xpos; yc[2] = ypos+rr;
856  xc[3] = xpos-dx; yc[3] = ypos+0.5*rr;
857  xc[4] = xpos+dx; yc[4] = ypos-0.5*rr;
858  xc[5] = xpos; yc[5] = ypos-rr;
859  bool cornerOne(false);
860  for (unsigned int k=0; k<HGCalParameters::k_CornerSize; ++k) {
861  double rpos = std::sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
862  if (rpos >= rin && rpos <= rout) cornerOne = true;
863  }
864  double rpos = std::sqrt(xpos*xpos+ypos*ypos);
865  int typet = (rpos < rMaxFine) ? 1 : 2;
866  int typel(3);
867  for (int k=1; k<4; ++k) {
868  if ((rpos+rmin)<=php.boundR_[k]) {
869  typel = k; break;
870  }
871  }
872  ++ntot;
873  if (cornerOne) {
874  int copy = inr*100 + inc;
875  if (nc < 0) copy += 10000;
876  if (nr < 0) copy += 100000;
877  if (inc > incm) incm = inc;
878  if (inr > inrm) inrm = inr;
879  kount++;
880 #ifdef EDM_ML_DEBUG
881  edm::LogVerbatim("HGCalGeom") << kount << ":" << ntot << " Copy "
882  << copy << " Type " << typel << ":"
883  << typet << " Location " << cornerOne
884  << " Position " << xpos << ":" << ypos
885  << " Layers " << php.layer_.size();
886 #endif
887  php.waferCopy_.emplace_back(copy);
888  php.waferTypeL_.emplace_back(typel);
889  php.waferTypeT_.emplace_back(typet);
890  php.waferPosX_.emplace_back(xpos);
891  php.waferPosY_.emplace_back(ypos);
892  for (unsigned int il=0; il<php.layer_.size(); ++il) {
893  bool corner(false), cornerAll(true);
894  for (unsigned int k=0; k<HGCalParameters::k_CornerSize; ++k) {
895  double rpos = std::sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
896  if (rpos >= php.rMinLayHex_[il] &&
897  rpos <= php.rMaxLayHex_[il]) corner = true;
898  else cornerAll = false;
899  }
900  if (corner) {
901  auto cpy = copiesInLayers[php.layer_[il]].find(copy);
902  if (cpy == copiesInLayers[php.layer_[il]].end())
903  copiesInLayers[php.layer_[il]][copy] = cornerAll ? php.waferCopy_.size() : -1;
904  }
905  }
906  }
907  }
908  }
909  }
910  php.copiesInLayers_ = copiesInLayers;
911  php.nSectors_ = (int)(php.waferCopy_.size());
912  php.waferUVMax_ = 0;
913 #ifdef EDM_ML_DEBUG
914  edm::LogVerbatim("HGCalGeom") << "HGCalWaferHexagon: # of columns "
915  << incm << " # of rows " << inrm << " and "
916  << kount << ":" << ntot << " wafers; R "
917  << rin << ":" << rout;
918  edm::LogVerbatim("HGCalGeom") << "Dump copiesInLayers for "
919  << php.copiesInLayers_.size() << " layers";
920  for (unsigned int k=0; k<copiesInLayers.size(); ++k) {
921  const auto& theModules = copiesInLayers[k];
922  edm::LogVerbatim("HGCalGeom") << "Layer " << k << ":" <<theModules.size();
923  int k2(0);
924  for (std::unordered_map<int, int>::const_iterator itr=theModules.begin();
925  itr != theModules.end(); ++itr,++k2) {
926  edm::LogVerbatim("HGCalGeom") << "[" << k2 << "] " << itr->first << ":"
927  << itr->second;
928  }
929  }
930 #endif
931 }
932 
934 
935  double waferW(php.waferSize_);
936  double waferS(php.sensorSeparation_);
937  auto wType = std::make_unique<HGCalWaferType>(php.radius100to200_,
938  php.radius200to300_,
939  HGCalParameters::k_ScaleToDDD*(waferW+waferS),
941  php.choiceType_,
942  php.nCornerCut_,
943  php.fracAreaMin_);
944 
945  double rout(php.rLimit_[1]);
946 #ifdef EDM_ML_DEBUG
947  edm::LogVerbatim("HGCalGeom") << "Input waferWidth " << waferW << ":"
948  << waferS << " R Max: " << rout;
949 #endif
950  // Clear the vectors
951  php.waferCopy_.clear();
952  php.waferTypeL_.clear();
953  php.waferTypeT_.clear();
954  php.waferPosX_.clear();
955  php.waferPosY_.clear();
956  double r = 0.5*(waferW+waferS);
957  double R = 2.0*r/sqrt3_;
958  double dy = 0.75*R;
959  int N = (r == 0) ? 3 : ((int)(0.5*rout/r) + 3);
960  int ns1 = (2*N+1)*(2*N+1);
961  int ns2 = ns1*php.zLayerHex_.size();
962 #ifdef EDM_ML_DEBUG
963  edm::LogVerbatim("HGCalGeom") << "r " << r << " dy " << dy << " N " << N
964  << " sizes " << ns1 << ":" << ns2;
965  std::vector<int> indtypes(ns1+1);
966  indtypes.clear();
967 #endif
968  HGCalParameters::wafer_map wafersInLayers(ns1+1);
969  HGCalParameters::wafer_map typesInLayers(ns2+1);
970  int ipos(0), lpos(0), uvmax(0);
971  std::vector<int> uvmx(php.zLayerHex_.size(),0);
973  for (int v = -N; v <= N; ++v) {
974  for (int u = -N; u <= N; ++u) {
975  int nr = 2*v;
976  int nc =-2*u+v;
977  double xpos = nc*r;
978  double ypos = nr*dy;
979  int indx = HGCalWaferIndex::waferIndex(0,u,v);
980  php.waferCopy_.emplace_back(indx);
981  php.waferPosX_.emplace_back(xpos);
982  php.waferPosY_.emplace_back(ypos);
983  wafersInLayers[indx] = ipos;
984  ++ipos;
985  xc[0] = xpos+r; yc[0] = ypos+0.5*R;
986  xc[1] = xpos; yc[1] = ypos+R;
987  xc[2] = xpos-r; yc[2] = ypos+0.5*R;
988  xc[3] = xpos-r; yc[3] = ypos-0.5*R;
989  xc[4] = xpos; yc[4] = ypos-R;
990  xc[5] = xpos+r; yc[5] = ypos-0.5*R;
991  bool cornerOne(false), cornerAll(true);
992  for (unsigned int k=0; k<HGCalParameters::k_CornerSize; ++k) {
993  double rpos = sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
994  if (rpos <= rout) cornerOne = true;
995  else cornerAll = false;
996  }
997  if ((cornerAll) || (cornerOne && php.defineFull_)) {
998  uvmax = std::max(uvmax,std::max(std::abs(u),std::abs(v)));
999  }
1000  for (unsigned int i=0; i<php.zLayerHex_.size(); ++i) {
1001  int lay = php.layer_[php.layerIndex_[i]];
1002  double zpos = php.zLayerHex_[i];
1004  php.waferTypeL_.emplace_back(type);
1005  int kndx = HGCalWaferIndex::waferIndex(lay,u,v);
1006  typesInLayers[kndx] = lpos;
1007  ++lpos;
1008 #ifdef EDM_ML_DEBUG
1009  indtypes.emplace_back(kndx);
1010 #endif
1011  bool cornerOne(false), cornerAll(true);
1012  for (unsigned int k=0; k<HGCalParameters::k_CornerSize; ++k) {
1013  double rpos = sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
1014  if (rpos <= php.rMaxLayHex_[i]) cornerOne = true;
1015  else cornerAll = false;
1016  }
1017  if ((cornerAll) || (cornerOne && php.defineFull_)) {
1018  uvmx[i] = std::max(uvmx[i],std::max(std::abs(u),std::abs(v)));
1019  }
1020  }
1021  }
1022  }
1023  php.waferUVMax_ = uvmax;
1024  php.waferUVMaxLayer_= uvmx;
1025  php.wafersInLayers_ = wafersInLayers;
1026  php.typesInLayers_ = typesInLayers;
1027  php.nSectors_ = (int)(php.waferCopy_.size());
1029  mytr.lay = 1; mytr.bl = php.waferR_;
1030  mytr.tl = php.waferR_; mytr.h = php.waferR_;
1031  mytr.alpha = 0.0; mytr.cellSize = HGCalParameters::k_ScaleToDDD*php.waferSize_;
1032  for (auto const & dz : php.cellThickness_) {
1033  mytr.dz = 0.5*HGCalParameters::k_ScaleToDDD*dz;
1034  php.fillModule(mytr,false);
1035  }
1036  for (unsigned k=0; k<php.cellThickness_.size(); ++k) {
1037  HGCalParameters::hgtrap mytr = php.getModule(k, false);
1043  php.fillModule(mytr, true);
1044  }
1045 #ifdef EDM_ML_DEBUG
1046  edm::LogVerbatim("HGCalGeom") << "HGCalGeomParameters: Total of "
1047  << php.waferCopy_.size() << " wafers";
1048  for (unsigned int k=0; k<php.waferCopy_.size(); ++k) {
1049  int id = php.waferCopy_[k];
1050  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << std::hex << id
1051  << std::dec << ":" << HGCalWaferIndex::waferLayer(id)
1052  << ":" << HGCalWaferIndex::waferU(id) << ":"
1053  << HGCalWaferIndex::waferV(id) << " x "
1054  << php.waferPosX_[k] << " y "
1055  << php.waferPosY_[k] << " index "
1056  << php.wafersInLayers_[id];
1057  }
1058  edm::LogVerbatim("HGCalGeom") << "HGCalParameters: Total of "
1059  << php.waferTypeL_.size() << " wafer types";
1060  for (unsigned int k=0; k<php.waferTypeL_.size(); ++k) {
1061  int id = indtypes[k];
1062  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << php.typesInLayers_[id]
1063  << ":" << php.waferTypeL_[k]
1064  << " ID " << std::hex << id << std::dec
1065  << ":" << HGCalWaferIndex::waferLayer(id) << ":"
1066  << HGCalWaferIndex::waferU(id) << ":"
1067  << HGCalWaferIndex::waferV(id);
1068  }
1069 #endif
1070 }
1071 
1073  HGCalParameters& php) {
1074 
1075  //Special parameters for cell parameters
1076  std::string attribute = "OnlyForHGCalNumbering";
1077  DDSpecificsHasNamedValueFilter filter1{attribute};
1078  DDFilteredView fv1(*cpv,filter1);
1079  bool ok = fv1.firstChild();
1080 
1081  if (ok) {
1082  php.cellFine_ = dbl_to_int(DDVectorGetter::get("waferFine"));
1083  php.cellCoarse_ = dbl_to_int(DDVectorGetter::get("waferCoarse"));
1084  }
1085 
1086 #ifdef EDM_ML_DEBUG
1087  edm::LogVerbatim("HGCalGeom") << "HGCalLoadCellPars: "
1088  << php.cellFine_.size()
1089  << " rows for fine cells";
1090  for (unsigned int k=0; k<php.cellFine_.size(); ++k)
1091  edm::LogVerbatim("HGCalGeom") << "[" << k << "]: " << php.cellFine_[k];
1092  edm::LogVerbatim("HGCalGeom") << "HGCalLoadCellPars: "
1093  << php.cellCoarse_.size()
1094  << " rows for coarse cells";
1095  for (unsigned int k=0; k<php.cellCoarse_.size(); ++k)
1096  edm::LogVerbatim("HGCalGeom") << "[" << k << "]: " << php.cellCoarse_[k];
1097 #endif
1098 }
1099 
1101  // Find the radius of each eta-partitions
1102  for (unsigned k=0; k<2; ++k) {
1103  double rmax = ((k == 0) ?
1104  (php.rMaxLayHex_[php.layerFrontBH_[1]-php.firstLayer_]-1) :
1105  (php.rMaxLayHex_[php.rMaxLayHex_.size()-1]));
1106  double rv = php.rMinLayerBH_[k];
1107  double zv = ((k == 0) ?
1108  (php.zLayerHex_[php.layerFrontBH_[1]-php.firstLayer_]) :
1109  (php.zLayerHex_[php.zLayerHex_.size()-1]));
1110  php.radiusLayer_[k].emplace_back(rv);
1111 #ifdef EDM_ML_DEBUG
1112  double eta =-(std::log(std::tan(0.5*std::atan(rv/zv))));
1113  edm::LogVerbatim("HGCalGeom") << "[" << k << "] rmax " << rmax << " Z = "
1114  << zv << " dEta = " << php.cellSize_[k]
1115  << "\n[0] new R = " << rv << " Eta = "
1116  << eta;
1117  int kount(1);
1118 #endif
1119  while (rv < rmax) {
1120  double eta =-(php.cellSize_[k]+std::log(std::tan(0.5*std::atan(rv/zv))));
1121  rv = zv*std::tan(2.0*std::atan(std::exp(-eta)));
1122  php.radiusLayer_[k].emplace_back(rv);
1123 #ifdef EDM_ML_DEBUG
1124  edm::LogVerbatim("HGCalGeom") << "[" << kount << "] new R = " << rv
1125  << " Eta = " << eta;
1126  ++kount;
1127 #endif
1128  }
1129  }
1130 
1131  // Find minimum and maximum radius index for each layer
1132  for (unsigned k=0; k<php.zLayerHex_.size(); ++k) {
1133  int kk = php.scintType(php.firstLayer_+(int)(k));
1134  std::vector<double>::iterator low, high;
1135  low = std::lower_bound(php.radiusLayer_[kk].begin(),
1136  php.radiusLayer_[kk].end(),
1137  php.rMinLayHex_[k]);
1138 #ifdef EDM_ML_DEBUG
1139  edm::LogVerbatim("HGCalGeom") << "[" << k << "] RLow = "
1140  << php.rMinLayHex_[k] << " pos "
1141  << (int)(low-php.radiusLayer_[kk].begin());
1142 #endif
1143  if (low == php.radiusLayer_[kk].begin()) ++low;
1144  int irlow = (int)(low-php.radiusLayer_[kk].begin());
1145  double drlow = php.radiusLayer_[kk][irlow] - php.rMinLayHex_[k];
1146 #ifdef EDM_ML_DEBUG
1147  edm::LogVerbatim("HGCalGeom") << "irlow " << irlow << " dr " << drlow
1148  << " min " << php.minTileSize_;
1149 #endif
1150  if (drlow < php.minTileSize_) {
1151  ++irlow;
1152 #ifdef EDM_ML_DEBUG
1153  drlow = php.radiusLayer_[kk][irlow] - php.rMinLayHex_[k];
1154  edm::LogVerbatim("HGCalGeom") << "Modified irlow " << irlow << " dr "
1155  << drlow;
1156 #endif
1157  }
1158  high = std::lower_bound(php.radiusLayer_[kk].begin(),
1159  php.radiusLayer_[kk].end(),
1160  php.rMaxLayHex_[k]);
1161 #ifdef EDM_ML_DEBUG
1162  edm::LogVerbatim("HGCalGeom") << "[" << k << "] RHigh = "
1163  << php.rMaxLayHex_[k] << " pos "
1164  << (int)(high-php.radiusLayer_[kk].begin());
1165 #endif
1166  if (high == php.radiusLayer_[kk].end()) --high;
1167  int irhigh = (int)(high-php.radiusLayer_[kk].begin());
1168  double drhigh = php.rMaxLayHex_[k] - php.radiusLayer_[kk][irhigh-1];
1169 #ifdef EDM_ML_DEBUG
1170  edm::LogVerbatim("HGCalGeom") << "irhigh " << irhigh << " dr " << drhigh
1171  << " min " << php.minTileSize_;
1172 #endif
1173  if (drhigh < php.minTileSize_) {
1174  --irhigh;
1175 #ifdef EDM_ML_DEBUG
1176  drhigh = php.rMaxLayHex_[k] - php.radiusLayer_[kk][irhigh-1];
1177  edm::LogVerbatim("HGCalGeom") << "Modified irhigh " << irhigh << " dr "
1178  << drhigh;
1179 #endif
1180  }
1181  php.iradMinBH_.emplace_back(irlow);
1182  php.iradMaxBH_.emplace_back(irhigh);
1183 #ifdef EDM_ML_DEBUG
1184  edm::LogVerbatim("HGcalGeom") << "Layer " << k << " Type " << kk
1185  << " Low edge " << irlow << ":" << drlow
1186  << " Top edge " << irhigh << ":" << drhigh;
1187 #endif
1188  }
1189 
1190  // Now define the volumes
1191  int im(0);
1192  php.waferUVMax_ = 0;
1194  mytr.alpha = 0.0;
1195  for (unsigned int k=0; k<php.zLayerHex_.size(); ++k) {
1196  if (php.iradMaxBH_[k] > php.waferUVMax_) php.waferUVMax_ = php.iradMaxBH_[k];
1197  int kk = ((php.firstLayer_+(int)(k)) < php.layerFrontBH_[1]) ? 0 : 1;
1198 #ifdef EDM_ML_DEBUG
1199  edm::LogVerbatim("HGCalGeom") << "Layer " << php.firstLayer_+k << ":"
1200  << kk << " Radius range "
1201  << php.iradMinBH_[k] << ":"
1202  << php.iradMaxBH_[k];
1203 #endif
1204  mytr.lay = php.firstLayer_ + k;
1205  for (int irad=php.iradMinBH_[k]; irad<=php.iradMaxBH_[k]; ++irad) {
1206  double rmin = php.radiusLayer_[kk][irad-1];
1207  double rmax = php.radiusLayer_[kk][irad];
1208  mytr.bl = 0.5*rmin*php.scintCellSize(mytr.lay);
1209  mytr.tl = 0.5*rmax*php.scintCellSize(mytr.lay);
1210  mytr.h = 0.5*(rmax-rmin);
1211  mytr.dz = 0.5*php.waferThick_;
1212  mytr.cellSize = 0.5*(rmax+rmin)*php.scintCellSize(mytr.lay);
1213  php.fillModule(mytr,true);
1219  php.fillModule(mytr, false);
1220  if (irad == php.iradMinBH_[k]) php.firstModule_.emplace_back(im);
1221  ++im;
1222  if (irad == php.iradMaxBH_[k]-1) php.lastModule_.emplace_back(im);
1223  }
1224  }
1225  php.nSectors_ = php.waferUVMax_;
1226 #ifdef EDM_ML_DEBUG
1227  edm::LogVerbatim("HGCalGeom") << "Maximum radius index " << php.waferUVMax_;
1228  for (unsigned int k=0; k< php.firstModule_.size(); ++k)
1229  edm::LogVerbatim("HGCalGeom") << "Layer " << k+php.firstLayer_
1230  << " Modules " << php.firstModule_[k]
1231  << ":" << php.lastModule_[k];
1232 #endif
1233 }
1234 
1235 std::vector<double> HGCalGeomParameters::getDDDArray(const std::string & str,
1236  const DDsvalues_type & sv,
1237  const int nmin) {
1238  DDValue value(str);
1239  if (DDfetch(&sv,value)) {
1240  const std::vector<double> & fvec = value.doubles();
1241  int nval = fvec.size();
1242  if (nmin > 0) {
1243  if (nval < nmin) {
1244  edm::LogError("HGCalGeom") << "HGCalGeomParameters : # of " << str
1245  << " bins " << nval << " < " << nmin
1246  << " ==> illegal";
1247  throw cms::Exception("DDException") << "HGCalGeomParameters: cannot get array " << str;
1248  }
1249  } else {
1250  if (nval < 1 && nmin == 0) {
1251  edm::LogError("HGCalGeom") << "HGCalGeomParameters : # of " << str
1252  << " bins " << nval << " < 1 ==> illegal"
1253  << " (nmin=" << nmin << ")";
1254  throw cms::Exception("DDException") << "HGCalGeomParameters: cannot get array " << str;
1255  }
1256  }
1257  return fvec;
1258  } else {
1259  if (nmin >= 0) {
1260  edm::LogError("HGCalGeom") << "HGCalGeomParameters: cannot get array "
1261  << str;
1262  throw cms::Exception("DDException") << "HGCalGeomParameters: cannot get array " << str;
1263  }
1264  std::vector<double> fvec;
1265  return fvec;
1266  }
1267 }
1268 
1269 std::pair<double,double>
1270 HGCalGeomParameters::cellPosition(const std::vector<HGCalGeomParameters::cellParameters>& wafers,
1271  std::vector<HGCalGeomParameters::cellParameters>::const_iterator& itrf,
1272  int wafer, double xx, double yy) {
1273 
1274  if (itrf == wafers.end()) {
1275  for (std::vector<HGCalGeomParameters::cellParameters>::const_iterator itr = wafers.begin();
1276  itr != wafers.end(); ++itr) {
1277  if (itr->wafer == wafer) {
1278  itrf = itr;
1279  break;
1280  }
1281  }
1282  }
1283  double dx(0), dy(0);
1284  if (itrf != wafers.end()) {
1285  dx = (xx - itrf->xyz.x());
1286  if (std::abs(dx) < tolerance) dx = 0;
1287  dy = (yy - itrf->xyz.y());
1288  if (std::abs(dy) < tolerance) dy = 0;
1289  }
1290  return std::pair<double,double>(dx,dy);
1291 }
std::vector< int > iradMaxBH_
std::vector< double > waferPosY_
type
Definition: HCALResponse.h:21
std::vector< int > layer_
std::vector< double > moduleDzR_
std::vector< int > depthLayerF_
std::vector< int > depth_
std::vector< double > zFrontMin_
std::vector< double > moduleHR_
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:140
layer_map copiesInLayers_
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
const N & name() const
Definition: DDBase.h:74
std::vector< bool > cellCoarseHalf_
std::vector< bool > cellFineHalf_
std::vector< double > rMaxVec(void) const
Definition: DDSolid.cc:430
def copy(args, dbName)
int scintType(const int layer) const
std::vector< int > moduleLayR_
nav_type copyNumbers() const
return the stack of copy numbers
void loadSpecParsHexagon(const DDFilteredView &, HGCalParameters &, const DDCompactView *, const std::string &, const std::string &)
std::vector< int > cellFine_
static int32_t waferV(const int32_t index)
const double tolerance
std::vector< double > moduleHS_
static int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV)
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
std::vector< double > trformTranY_
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< double > cellFineY_
std::vector< double > trformRotZY_
int zside(DetId const &)
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
std::vector< uint32_t > trformIndex_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::vector< int > layerGroupM_
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:81
const std::string names[nVars_]
double scintCellSize(const int layer) const
std::vector< double > trformRotXX_
std::vector< int > nPhiBinBH_
void loadSpecParsHexagon8(const DDFilteredView &, HGCalParameters &)
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
void fillTrForm(const hgtrform &mytr)
wafer_map wafersInLayers_
std::vector< double > rMinLayerBH_
std::vector< double > trformRotZX_
std::vector< double > xVec(void) const
Definition: DDSolid.cc:473
std::vector< int > dbl_to_int(const std::vector< double > &vecdbl)
Converts a std::vector of doubles to a std::vector of int.
Definition: DDutils.h:7
std::vector< double > cellCoarseX_
std::vector< int > firstModule_
std::vector< int > cellCoarse_
std::vector< double > trformRotYZ_
void loadCellTrapezoid(HGCalParameters &php)
std::pair< double, double > cellPosition(const std::vector< cellParameters > &wafers, std::vector< cellParameters >::const_iterator &itrf, int wafer, double xx, double yy)
std::vector< double > boundR_
std::vector< double > cellSize_
std::vector< int > waferUVMaxLayer_
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
std::vector< double > moduleDzS_
bool next()
set current node to the next node in the filtered tree
std::vector< int > layerIndex_
std::vector< double > moduleAlphaR_
void loadCellParsHexagon(const DDCompactView *cpv, HGCalParameters &php)
T sqrt(T t)
Definition: SSEVec.h:18
susybsm::HSCParticleRef hr
Definition: classes.h:26
static double k_ScaleFromDDD
std::vector< double > trformRotXY_
std::vector< double > rMaxFront_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< double > trformRotYX_
int scintCells(const int layer) const
hgtrap getModule(unsigned int k, bool reco) const
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< std::unordered_map< int32_t, int32_t > > layer_map
std::vector< double > slopeTop_
static int32_t waferU(const int32_t index)
std::vector< double > moduleBlR_
void loadSpecParsTrapezoid(const DDFilteredView &, HGCalParameters &)
std::vector< double > rMinLayHex_
void loadGeometryHexagon8(const DDFilteredView &, HGCalParameters &, int)
void fillModule(const hgtrap &mytr, bool reco)
std::vector< double > getDDDArray(const std::string &, const DDsvalues_type &, const int)
double p2[4]
Definition: TauolaWrapper.h:90
std::vector< double > moduleTlS_
double rOut(void) const
Definition: DDSolid.cc:584
static int32_t waferLayer(const int32_t index)
std::vector< double > zLayerHex_
std::vector< double > get(const std::string &)
#define M_PI
void loadWaferHexagon(HGCalParameters &php)
int k[5][pyjets_maxn]
std::vector< double > rMaxLayHex_
static uint32_t k_CornerSize
std::vector< double > trformTranX_
std::vector< double > zRanges_
std::vector< double > slopeMin_
std::vector< int > lastModule_
std::vector< double > zVec(void) const
Definition: DDSolid.cc:487
std::vector< double > radiusMixBoundary_
#define N
Definition: blowfish.cc:9
std::vector< double > cellThickness_
std::vector< double > trformRotXZ_
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double > > XYZPointD
point in space with cartesian internal representation
Definition: Point3D.h:8
std::vector< double > zVec(void) const
Definition: DDSolid.cc:414
void scaleTrForm(double)
std::vector< int > layerGroup_
std::unordered_map< int32_t, int32_t > wafer_map
static double k_ScaleToDDD
std::vector< double > radius200to300_
std::vector< double > radius100to200_
DDsvalues_type mergedSpecifics() const
std::vector< double > rMinFront_
std::vector< int > iradMinBH_
std::vector< double > trformRotYY_
std::vector< double > cellFineX_
wafer_map typesInLayers_
std::vector< double > trformRotZZ_
std::vector< double > moduleAlphaS_
std::vector< int > layerGroupO_
std::vector< double > moduleBlS_
double p1[4]
Definition: TauolaWrapper.h:89
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
bool firstChild()
set the current node to the first child ...
std::vector< int > waferCopy_
std::vector< int > depthIndex_
std::vector< int > layerFrontBH_
std::vector< double > rLimit_
std::vector< double > zFrontTop_
std::vector< double > radiusLayer_[2]
std::vector< int > waferTypeT_
const DDTranslation & translation() const
The absolute translation of the current node.
std::vector< int > levelT_
std::vector< double > cellCoarseY_
std::vector< int > moduleLayS_
std::vector< double > trformTranZ_
double rIn(void) const
Definition: DDSolid.cc:581
#define str(s)
std::vector< double > waferPosX_
void addTrForm(const CLHEP::Hep3Vector &h3v)
std::vector< double > moduleTlR_
std::vector< int > waferTypeL_
const std::string & name() const
Returns the name.
Definition: DDName.cc:53
void loadWaferHexagon8(HGCalParameters &php)
void loadGeometryHexagon(const DDFilteredView &, HGCalParameters &, const std::string &, const DDCompactView *, const std::string &, const std::string &, HGCalGeometryMode::WaferMode)