CMS 3D CMS Logo

HGCalTBDDDConstants.cc
Go to the documentation of this file.
2 
10 
11 #include <algorithm>
12 #include <bitset>
13 #include <iterator>
14 #include <functional>
15 #include <numeric>
16 
17 //#define EDM_ML_DEBUG
18 using namespace geant_units::operators;
19 
21  : hgpar_(hp), sqrt3_(std::sqrt(3.0)), mode_(hgpar_->mode_) {
22 #ifdef EDM_ML_DEBUG
23  edm::LogVerbatim("HGCalGeom") << "HGCalTBDDDConstants::Mode " << mode_;
24 #endif
25  if (waferHexagon6()) {
28  hexside_ = 2.0 * rmax_ * tan30deg_;
29  hexsideT_ = 2.0 * rmaxT_ * tan30deg_;
30 #ifdef EDM_ML_DEBUG
31  edm::LogVerbatim("HGCalGeom") << "HGCalTBDDDConstants::rmax_ " << rmax_ << ":" << rmaxT_ << ":" << hexside_ << ":"
32  << hexsideT_ << " CellSize "
35 #endif
36  }
37  // init maps and constants
38  modHalf_ = 0;
40  for (int simreco = 0; simreco < 2; ++simreco) {
41  tot_layers_[simreco] = layersInit((bool)simreco);
42  max_modules_layer_[simreco].resize(tot_layers_[simreco] + 1);
43  for (unsigned int layer = 1; layer <= tot_layers_[simreco]; ++layer) {
44  max_modules_layer_[simreco][layer] = modulesInit(layer, (bool)simreco);
45  if (simreco == 1) {
46  modHalf_ += max_modules_layer_[simreco][layer];
48 #ifdef EDM_ML_DEBUG
49  edm::LogVerbatim("HGCalGeom") << "HGCalTBDDDConstants::Layer " << layer << " with "
50  << max_modules_layer_[simreco][layer] << ":" << modHalf_ << " modules in RECO";
51  } else {
52  edm::LogVerbatim("HGCalGeom") << "HGCalTBDDDConstants::Layer " << layer << " with "
53  << max_modules_layer_[simreco][layer] << " modules in SIM";
54 #endif
55  }
56  }
57 #ifdef EDM_ML_DEBUG
58  edm::LogVerbatim("HGCalGeom") << "HGCalTBDDDConstants::SimReco " << simreco << " with " << tot_layers_[simreco]
59  << " Layers";
60 #endif
61  }
62  tot_wafers_ = wafers();
63 
64 #ifdef EDM_ML_DEBUG
65  edm::LogVerbatim("HGCalGeom") << "HGCalTBDDDConstants initialized for " << name << " with " << layers(false) << ":"
66  << layers(true) << " layers, " << wafers() << ":" << 2 * modHalf_
67  << " wafers with maximum " << maxWafersPerLayer_ << " per layer and "
68  << "maximum of " << maxCells(false) << ":" << maxCells(true) << " cells";
69 #endif
70  if (waferHexagon6()) {
71  int wminT(9999999), wmaxT(-9999999), kount1(0), kount2(0);
72  for (unsigned int i = 0; i < getTrFormN(); ++i) {
73  int lay0 = getTrForm(i).lay;
74  int wmin(9999999), wmax(-9999999), kount(0);
75  for (int wafer = 0; wafer < sectors(); ++wafer) {
76  bool waferIn = waferInLayer(wafer, lay0, true);
77  if (waferIn) {
78  if (wafer < wmin)
79  wmin = wafer;
80  if (wafer > wmax)
81  wmax = wafer;
82  ++kount;
83  }
84  }
85  if (wminT > wmin)
86  wminT = wmin;
87  if (wmaxT < wmax)
88  wmaxT = wmax;
89  if (kount1 < kount)
90  kount1 = kount;
91  kount2 += kount;
92 #ifdef EDM_ML_DEBUG
93  int lay1 = getIndex(lay0, true).first;
94  edm::LogVerbatim("HGCalGeom") << "Index " << i << " Layer " << lay0 << ":" << lay1 << " Wafer " << wmin << ":"
95  << wmax << ":" << kount;
96 #endif
97  HGCWaferParam a1{{wmin, wmax, kount}};
98  waferLayer_[lay0] = a1;
99  }
100  waferMax_ = std::array<int, 4>{{wminT, wmaxT, kount1, kount2}};
101 #ifdef EDM_ML_DEBUG
102  edm::LogVerbatim("HGCalGeom") << "Overall wafer statistics: " << wminT << ":" << wmaxT << ":" << kount1 << ":"
103  << kount2;
104 #endif
105  }
106 }
107 
108 std::pair<int, int> HGCalTBDDDConstants::assignCell(float x, float y, int lay, int subSec, bool reco) const {
109  const auto& index = getIndex(lay, reco);
110  if (index.first < 0)
111  return std::make_pair(-1, -1);
112  if (waferHexagon6()) {
113  float xx = (reco) ? x : HGCalTBParameters::k_ScaleFromDDD * x;
114  float yy = (reco) ? y : HGCalTBParameters::k_ScaleFromDDD * y;
115 
116  // First the wafer
117  int wafer = cellHex(xx, yy, rmax_, hgpar_->waferPosX_, hgpar_->waferPosY_);
118  if (wafer < 0 || wafer >= static_cast<int>(hgpar_->waferTypeT_.size())) {
119  edm::LogWarning("HGCalGeom") << "Wafer no. out of bound for " << wafer << ":" << (hgpar_->waferTypeT_).size()
120  << ":" << (hgpar_->waferPosX_).size() << ":" << (hgpar_->waferPosY_).size()
121  << " ***** ERROR *****";
122  return std::make_pair(-1, -1);
123  } else {
124  // Now the cell
125  xx -= hgpar_->waferPosX_[wafer];
126  yy -= hgpar_->waferPosY_[wafer];
127  if (hgpar_->waferTypeT_[wafer] == 1)
128  return std::make_pair(wafer,
129  cellHex(xx,
130  yy,
133  hgpar_->cellFineY_));
134  else
135  return std::make_pair(wafer,
136  cellHex(xx,
137  yy,
140  hgpar_->cellCoarseY_));
141  }
142  } else {
143  return std::make_pair(-1, -1);
144  }
145 }
146 
148  int indx = (type == 1) ? 1 : 0;
149  double cell = 0.5 * HGCalTBParameters::k_ScaleFromDDD * hgpar_->cellSize_[indx];
150  return cell;
151 }
152 
153 double HGCalTBDDDConstants::cellThickness(int layer, int wafer) const {
154  double thick(-1);
155  int type = waferType(layer, wafer);
156  if (type >= 0)
157  thick = 100.0 * (type + 1); // type = 1,2,3 for 100,200,300 micron
158  return thick;
159 }
160 
161 double HGCalTBDDDConstants::distFromEdgeHex(double x, double y, double z) const {
162  // Assming the point is within a hexagonal plane of the wafer, calculate
163  // the shortest distance from the edge
164  if (z < 0)
165  x = -x;
166  double dist(0);
167  // Input x, y in Geant4 unit and transformed to CMSSW standard
170  int sizew = static_cast<int>(hgpar_->waferPosX_.size());
171  int wafer = sizew;
172  // Transform to the local coordinate frame of the wafer first
173  for (int k = 0; k < sizew; ++k) {
174  double dx = std::abs(xx - hgpar_->waferPosX_[k]);
175  double dy = std::abs(yy - hgpar_->waferPosY_[k]);
176  if ((dx <= rmax_) && (dy <= hexside_) && ((dy <= 0.5 * hexside_) || (dx * tan30deg_ <= (hexside_ - dy)))) {
177  wafer = k;
178  xx -= hgpar_->waferPosX_[k];
179  yy -= hgpar_->waferPosY_[k];
180  break;
181  }
182  }
183  // Look at only one quarter (both x,y are positive)
184  if (wafer < sizew) {
185  if (std::abs(yy) < 0.5 * hexside_) {
186  dist = rmax_ - std::abs(xx);
187  } else {
188  dist = 0.5 * ((rmax_ - std::abs(xx)) - sqrt3_ * (std::abs(yy) - 0.5 * hexside_));
189  }
190  } else {
191  dist = 0;
192  }
194 #ifdef EDM_ML_DEBUG
195  edm::LogVerbatim("HGCalGeom") << "DistFromEdgeHex: Local " << xx << ":" << yy << " wafer " << wafer << " flag "
196  << (wafer < sizew) << " Distance " << rmax_ << ":" << (rmax_ - std::abs(xx)) << ":"
197  << (std::abs(yy) - 0.5 * hexside_) << ":" << 0.5 * hexside_ << ":" << dist;
198 #endif
199  return dist;
200 }
201 
202 int HGCalTBDDDConstants::getLayer(double z, bool reco) const {
203  // Get the layer # from the gloabl z coordinate
204  unsigned int k = 0;
206  const auto& zLayerHex = hgpar_->zLayerHex_;
207  auto itr = std::find_if(zLayerHex.begin() + 1, zLayerHex.end(), [&k, &zz, &zLayerHex](double zLayer) {
208  ++k;
209  return zz < 0.5 * (zLayerHex[k - 1] + zLayerHex[k]);
210  });
211  int lay = (itr == zLayerHex.end()) ? static_cast<int>(zLayerHex.size()) : k;
212  if (waferHexagon6() && reco) {
213  int indx = layerIndex(lay, false);
214  if (indx >= 0)
215  lay = hgpar_->layerGroupO_[indx];
216  } else {
217  lay += (hgpar_->firstLayer_ - 1);
218  }
219  return lay;
220 }
221 
222 HGCalTBParameters::hgtrap HGCalTBDDDConstants::getModule(unsigned int indx, bool hexType, bool reco) const {
224  if (hexType) {
225  if (indx >= hgpar_->waferTypeL_.size())
226  edm::LogWarning("HGCalGeom") << "Wafer no. out bound for index " << indx << ":" << (hgpar_->waferTypeL_).size()
227  << ":" << (hgpar_->waferPosX_).size() << ":" << (hgpar_->waferPosY_).size()
228  << " ***** ERROR *****";
229  unsigned int type =
230  ((indx < hgpar_->waferTypeL_.size()) ? hgpar_->waferTypeL_[indx] - 1 : HGCalTBParameters::HGCalCoarseThick);
231  mytr = hgpar_->getModule(type, reco);
232  } else {
233  mytr = hgpar_->getModule(indx, reco);
234  }
235  return mytr;
236 }
237 
238 std::vector<HGCalTBParameters::hgtrap> HGCalTBDDDConstants::getModules() const {
239  std::vector<HGCalTBParameters::hgtrap> mytrs;
240  for (unsigned int k = 0; k < hgpar_->moduleLayR_.size(); ++k)
241  mytrs.emplace_back(hgpar_->getModule(k, true));
242  return mytrs;
243 }
244 
245 std::vector<HGCalTBParameters::hgtrform> HGCalTBDDDConstants::getTrForms() const {
246  std::vector<HGCalTBParameters::hgtrform> mytrs;
247  for (unsigned int k = 0; k < hgpar_->trformIndex_.size(); ++k)
248  mytrs.emplace_back(hgpar_->getTrForm(k));
249  return mytrs;
250 }
251 
252 bool HGCalTBDDDConstants::isHalfCell(int waferType, int cell) const {
253  if (waferType < 1 || cell < 0)
254  return false;
255  return waferType == 2 ? hgpar_->cellCoarseHalf_[cell] : hgpar_->cellFineHalf_[cell];
256 }
257 
258 bool HGCalTBDDDConstants::isValidHex(int lay, int mod, int cell, bool reco) const {
259  // Check validity for a layer|wafer|cell of pre-TDR version
260  bool result(false), resultMod(false);
261  int cellmax(0);
262  if (waferHexagon6()) {
263  int32_t copyNumber = hgpar_->waferCopy_[mod];
264  result = ((lay > 0 && lay <= static_cast<int>(layers(reco))));
265  if (result) {
266  const int32_t lay_idx = reco ? (lay - 1) * 3 + 1 : lay;
267  const auto& the_modules = hgpar_->copiesInLayers_[lay_idx];
268  auto moditr = the_modules.find(copyNumber);
269  result = resultMod = (moditr != the_modules.end());
270 #ifdef EDM_ML_DEBUG
271  if (!result)
272  edm::LogVerbatim("HGCalGeom") << "HGCalTBDDDConstants: Layer " << lay << ":" << lay_idx << " Copy "
273  << copyNumber << ":" << mod << " Flag " << result;
274 #endif
275  if (result) {
276  if (moditr->second >= 0) {
277  if (mod >= static_cast<int>(hgpar_->waferTypeT_.size()))
278  edm::LogWarning("HGCalGeom") << "Module no. out of bound for " << mod << " to be compared with "
279  << (hgpar_->waferTypeT_).size() << " ***** ERROR *****";
280  cellmax = ((hgpar_->waferTypeT_[mod] - 1 == HGCalTBParameters::HGCalFine)
281  ? static_cast<int>(hgpar_->cellFineX_.size())
282  : static_cast<int>(hgpar_->cellCoarseX_.size()));
283  result = (cell >= 0 && cell <= cellmax);
284  } else {
285  result = isValidCell(lay_idx, mod, cell);
286  }
287  }
288  }
289  }
290 
291 #ifdef EDM_ML_DEBUG
292  if (!result)
293  edm::LogVerbatim("HGCalGeom") << "HGCalTBDDDConstants: Layer " << lay << ":"
294  << (lay > 0 && (lay <= static_cast<int>(layers(reco)))) << " Module " << mod << ":"
295  << resultMod << " Cell " << cell << ":" << cellmax << ":"
296  << (cell >= 0 && cell <= cellmax) << ":" << maxCells(reco);
297 #endif
298  return result;
299 }
300 
302  return (hgpar_->firstLayer_ + tot_layers_[static_cast<int>(reco)] - 1);
303 }
304 
305 int HGCalTBDDDConstants::layerIndex(int lay, bool reco) const {
306  int ll = lay - hgpar_->firstLayer_;
307  if (ll < 0 || ll >= static_cast<int>(hgpar_->layerIndex_.size()))
308  return -1;
309  if (waferHexagon6()) {
310  if (reco && ll >= static_cast<int>(hgpar_->depthIndex_.size()))
311  return -1;
312  return (reco ? hgpar_->depthLayerF_[ll] : hgpar_->layerIndex_[ll]);
313  }
314  return -1;
315 }
316 
317 unsigned int HGCalTBDDDConstants::layers(bool reco) const { return tot_layers_[static_cast<int>(reco)]; }
318 
319 unsigned int HGCalTBDDDConstants::layersInit(bool reco) const {
320  return (reco ? hgpar_->depthIndex_.size() : hgpar_->layerIndex_.size());
321 }
322 
323 std::pair<float, float> HGCalTBDDDConstants::locateCell(int cell, int lay, int type, bool reco) const {
324  // type refers to wafer # for hexagon cell
325  float x(999999.), y(999999.);
326  const auto& index = getIndex(lay, reco);
327  int i = index.first;
328  if (i < 0)
329  return std::make_pair(x, y);
330  if (waferHexagon6()) {
331  x = hgpar_->waferPosX_[type];
332  y = hgpar_->waferPosY_[type];
333 #ifdef EDM_ML_DEBUG
334  float x0(x), y0(y);
335 #endif
337  x += hgpar_->cellFineX_[cell];
338  y += hgpar_->cellFineY_[cell];
339  } else {
340  x += hgpar_->cellCoarseX_[cell];
341  y += hgpar_->cellCoarseY_[cell];
342  }
343 #ifdef EDM_ML_DEBUG
344  edm::LogVerbatim("HGCalGeom") << "LocateCell (Wafer) " << x0 << ":" << y0 << " Final " << x << ":" << y;
345 #endif
346  if (!reco) {
349  }
350  }
351  return std::make_pair(x, y);
352 }
353 
354 std::pair<float, float> HGCalTBDDDConstants::locateCellHex(int cell, int wafer, bool reco) const {
355  float x(0), y(0);
356  if (hgpar_->waferTypeT_[wafer] - 1 == HGCalTBParameters::HGCalFine) {
357  x = hgpar_->cellFineX_[cell];
358  y = hgpar_->cellFineY_[cell];
359  } else {
360  x = hgpar_->cellCoarseX_[cell];
361  y = hgpar_->cellCoarseY_[cell];
362  }
363  if (!reco) {
366  }
367  return std::make_pair(x, y);
368 }
369 
371  int cells(0);
372  for (unsigned int i = 0; i < layers(reco); ++i) {
373  int lay = reco ? hgpar_->depth_[i] : hgpar_->layer_[i];
374  if (cells < maxCells(lay, reco))
375  cells = maxCells(lay, reco);
376  }
377  return cells;
378 }
379 
380 int HGCalTBDDDConstants::maxCells(int lay, bool reco) const {
381  const auto& index = getIndex(lay, reco);
382  if ((index.first < 0) || (!waferHexagon6()))
383  return 0;
384  unsigned int cells(0);
385  for (unsigned int k = 0; k < hgpar_->waferTypeT_.size(); ++k) {
386  if (waferInLayerTest(k, index.first)) {
387  unsigned int cell = (hgpar_->waferTypeT_[k] - 1 == HGCalTBParameters::HGCalFine) ? (hgpar_->cellFineX_.size())
388  : (hgpar_->cellCoarseX_.size());
389  if (cell > cells)
390  cells = cell;
391  }
392  }
393  return static_cast<int>(cells);
394 }
395 
396 int HGCalTBDDDConstants::maxRows(int lay, bool reco) const {
397  int kymax(0);
398  const auto& index = getIndex(lay, reco);
399  int i = index.first;
400  if ((i >= 0) && waferHexagon6()) {
401  for (unsigned int k = 0; k < hgpar_->waferCopy_.size(); ++k) {
402  if (waferInLayerTest(k, i)) {
403  int ky = ((hgpar_->waferCopy_[k]) / 100) % 100;
404  if (ky > kymax)
405  kymax = ky;
406  }
407  }
408  }
409  return kymax;
410 }
411 
412 int HGCalTBDDDConstants::modifyUV(int uv, int type1, int type2) const {
413  // Modify u/v for transition of type1 to type2
414  return (((type1 == type2) || (type1 * type2 != 0)) ? uv : ((type1 == 0) ? (2 * uv + 1) / 3 : (3 * uv) / 2));
415 }
416 
417 int HGCalTBDDDConstants::modules(int lay, bool reco) const {
418  if (getIndex(lay, reco).first < 0)
419  return 0;
420  else
421  return max_modules_layer_[static_cast<int>(reco)][lay];
422 }
423 
424 int HGCalTBDDDConstants::modulesInit(int lay, bool reco) const {
425  int nmod(0);
426  const auto& index = getIndex(lay, reco);
427  if (index.first < 0)
428  return nmod;
429  for (unsigned int k = 0; k < hgpar_->waferPosX_.size(); ++k) {
430  if (waferInLayerTest(k, index.first))
431  ++nmod;
432  }
433  return nmod;
434 }
435 
438 }
439 
441  int cells(0);
442  unsigned int nlayer = (reco) ? hgpar_->depth_.size() : hgpar_->layer_.size();
443  for (unsigned k = 0; k < nlayer; ++k) {
444  std::vector<int> ncells = numberCells(((reco) ? hgpar_->depth_[k] : hgpar_->layer_[k]), reco);
445  cells = std::accumulate(ncells.begin(), ncells.end(), cells);
446  }
447  return cells;
448 }
449 
450 std::vector<int> HGCalTBDDDConstants::numberCells(int lay, bool reco) const {
451  const auto& index = getIndex(lay, reco);
452  int i = index.first;
453  std::vector<int> ncell;
454  if ((i >= 0) && (waferHexagon6())) {
455  for (unsigned int k = 0; k < hgpar_->waferTypeT_.size(); ++k) {
456  if (waferInLayerTest(k, i)) {
457  unsigned int cell = (hgpar_->waferTypeT_[k] - 1 == HGCalTBParameters::HGCalFine)
458  ? (hgpar_->cellFineX_.size())
459  : (hgpar_->cellCoarseX_.size());
460  ncell.emplace_back(static_cast<int>(cell));
461  }
462  }
463  }
464  return ncell;
465 }
466 
468  if (wafer >= 0 && wafer < static_cast<int>(hgpar_->waferTypeT_.size())) {
469  if (hgpar_->waferTypeT_[wafer] - 1 == 0)
470  return static_cast<int>(hgpar_->cellFineX_.size());
471  else
472  return static_cast<int>(hgpar_->cellCoarseX_.size());
473  } else {
474  return 0;
475  }
476 }
477 
478 std::pair<double, double> HGCalTBDDDConstants::rangeR(double z, bool reco) const {
479  double rmin(0), rmax(0);
480  if (!reco) {
483  }
484 #ifdef EDM_ML_DEBUG
485  edm::LogVerbatim("HGCalGeom") << "HGCalTBDDDConstants:rangeR: " << z << ":0"
486  << " R " << rmin << ":" << rmax;
487 #endif
488  return std::make_pair(rmin, rmax);
489 }
490 
491 std::pair<double, double> HGCalTBDDDConstants::rangeRLayer(int lay, bool reco) const {
492  double rmin(0), rmax(0);
493  const auto& index = getIndex(lay, reco);
494  if (index.first >= 0 && index.first < static_cast<int>(hgpar_->rMinLayHex_.size())) {
495  rmin = hgpar_->rMinLayHex_[index.first];
496  rmax = hgpar_->rMaxLayHex_[index.first];
497  }
498  if (!reco) {
501  }
502 #ifdef EDM_ML_DEBUG
503  edm::LogVerbatim("HGCalGeom") << "HGCalTBDDDConstants:rangeR: " << lay << ":" << index.first << " R " << rmin << ":"
504  << rmax;
505 #endif
506  return std::make_pair(rmin, rmax);
507 }
508 
509 std::pair<double, double> HGCalTBDDDConstants::rangeZ(bool reco) const {
510  double zmin = (hgpar_->zLayerHex_[0] - hgpar_->waferThick_);
511  double zmax = (hgpar_->zLayerHex_[hgpar_->zLayerHex_.size() - 1] + hgpar_->waferThick_);
512 #ifdef EDM_ML_DEBUG
513  edm::LogVerbatim("HGCalGeom") << "HGCalTBDDDConstants:rangeZ: " << zmin << ":" << zmax << ":" << hgpar_->waferThick_;
514 #endif
515  if (!reco) {
518  }
519  return std::make_pair(zmin, zmax);
520 }
521 
522 std::pair<int, int> HGCalTBDDDConstants::rowColumnWafer(int wafer) const {
523  int row(0), col(0);
524  if (wafer < static_cast<int>(hgpar_->waferCopy_.size())) {
525  int copy = hgpar_->waferCopy_[wafer];
528  }
529  return std::make_pair(row, col);
530 }
531 
532 std::pair<int, int> HGCalTBDDDConstants::simToReco(int cell, int lay, int mod, bool half) const {
533  return std::make_pair(cell, lay);
534 }
535 
537  const int ncopies = hgpar_->waferCopy_.size();
538  int wafer(ncopies);
539  bool result(false);
540  for (int k = 0; k < ncopies; ++k) {
541  if (copy == hgpar_->waferCopy_[k]) {
542  wafer = k;
543  result = true;
544  break;
545  }
546  }
547  if (!result) {
548  wafer = -1;
549 #ifdef EDM_ML_DEBUG
550  edm::LogVerbatim("HGCalGeom") << "Cannot find " << copy << " in a list of " << ncopies << " members";
551  for (int k = 0; k < ncopies; ++k)
552  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << hgpar_->waferCopy_[k];
553 #endif
554  }
555 #ifdef EDM_ML_DEBUG
556  edm::LogVerbatim("HGCalGeom") << "WaferFromCopy " << copy << ":" << wafer << ":" << result;
557 #endif
558  return wafer;
559 }
560 
561 void HGCalTBDDDConstants::waferFromPosition(const double x, const double y, int& wafer, int& icell, int& celltyp) const {
562  // Input x, y in Geant4 unit and transformed to CMSSW standard
565  int size_ = static_cast<int>(hgpar_->waferCopy_.size());
566  wafer = size_;
567  for (int k = 0; k < size_; ++k) {
568  double dx = std::abs(xx - hgpar_->waferPosX_[k]);
569  double dy = std::abs(yy - hgpar_->waferPosY_[k]);
570  if (dx <= rmax_ && dy <= hexside_) {
571  if ((dy <= 0.5 * hexside_) || (dx * tan30deg_ <= (hexside_ - dy))) {
572  wafer = k;
573  celltyp = hgpar_->waferTypeT_[k];
574  xx -= hgpar_->waferPosX_[k];
575  yy -= hgpar_->waferPosY_[k];
576  break;
577  }
578  }
579  }
580  if (wafer < size_) {
581  if (celltyp - 1 == HGCalTBParameters::HGCalFine)
582  icell = cellHex(xx,
583  yy,
586  hgpar_->cellFineY_);
587  else
588  icell = cellHex(xx,
589  yy,
593  } else {
594  wafer = -1;
595 #ifdef EDM_ML_DEBUG
596  edm::LogWarning("HGCalGeom") << "Cannot get wafer type corresponding to " << x << ":" << y << " " << xx << ":"
597  << yy;
598 #endif
599  }
600 #ifdef EDM_ML_DEBUG
601  edm::LogVerbatim("HGCalGeom") << "Position " << x << ":" << y << " Wafer " << wafer << ":" << size_ << " XX " << xx
602  << ":" << yy << " Cell " << icell << " Type " << celltyp;
603 #endif
604 }
605 
606 bool HGCalTBDDDConstants::waferInLayer(int wafer, int lay, bool reco) const {
607  const auto& indx = getIndex(lay, reco);
608  if (indx.first < 0)
609  return false;
610  return waferInLayerTest(wafer, indx.first);
611 }
612 
613 bool HGCalTBDDDConstants::waferFullInLayer(int wafer, int lay, bool reco) const {
614  const auto& indx = getIndex(lay, reco);
615  if (indx.first < 0)
616  return false;
617  return waferInLayerTest(wafer, indx.first);
618 }
619 
620 std::pair<double, double> HGCalTBDDDConstants::waferParameters(bool reco) const {
621  if (reco)
622  return std::make_pair(rmax_, hexside_);
623  else
625 }
626 
627 std::pair<double, double> HGCalTBDDDConstants::waferPosition(int wafer, bool reco) const {
628  double xx(0), yy(0);
629  if (wafer >= 0 && wafer < static_cast<int>(hgpar_->waferPosX_.size())) {
630  xx = hgpar_->waferPosX_[wafer];
631  yy = hgpar_->waferPosY_[wafer];
632  }
633  if (!reco) {
636  }
637  return std::make_pair(xx, yy);
638 }
639 
640 int HGCalTBDDDConstants::wafers() const { return static_cast<int>(hgpar_->moduleLayR_.size()); }
641 
643  int wafer(0);
644  auto itr = waferLayer_.find(layer);
645  if (itr != waferLayer_.end()) {
646  unsigned ity = (type > 0 && type <= 2) ? type : 0;
647  wafer = (itr->second)[ity];
648  }
649  return wafer;
650 }
651 
652 int HGCalTBDDDConstants::waferType(DetId const& id) const {
653  return waferType(HGCalDetId(id).layer(), HGCalDetId(id).wafer());
654 }
655 
656 int HGCalTBDDDConstants::waferType(int layer, int wafer) const {
658  if ((wafer >= 0) && (wafer < static_cast<int>(hgpar_->waferTypeL_.size())))
659  type = (hgpar_->waferTypeL_[wafer] - 1);
660  return type;
661 }
662 
663 bool HGCalTBDDDConstants::waferVirtual(int layer, int wafer) const {
664  int wl = HGCalWaferIndex::waferIndex(layer, wafer, 0, true);
665  return (hgpar_->waferTypes_.find(wl) != hgpar_->waferTypes_.end());
666 }
667 
668 double HGCalTBDDDConstants::waferZ(int lay, bool reco) const {
669  const auto& index = getIndex(lay, reco);
670  if (index.first < 0)
671  return 0;
672  else
674 }
675 
677  double xx, double yy, const double& cellR, const std::vector<double>& posX, const std::vector<double>& posY) const {
678  int num(0);
679  const double tol(0.00001);
680  double cellY = 2.0 * cellR * tan30deg_;
681  for (unsigned int k = 0; k < posX.size(); ++k) {
682  double dx = std::abs(xx - posX[k]);
683  double dy = std::abs(yy - posY[k]);
684  if (dx <= (cellR + tol) && dy <= (cellY + tol)) {
685  double xmax = (dy <= 0.5 * cellY) ? cellR : (cellR - (dy - 0.5 * cellY) / tan30deg_);
686  if (dx <= (xmax + tol)) {
687  num = k;
688  break;
689  }
690  }
691  }
692  return num;
693 }
694 
695 std::pair<int, float> HGCalTBDDDConstants::getIndex(int lay, bool reco) const {
696  int indx = layerIndex(lay, reco);
697  if (indx < 0)
698  return std::make_pair(-1, 0);
699  float cell(0);
700  if (waferHexagon6()) {
701  cell = (reco ? hgpar_->moduleCellR_[0] : hgpar_->moduleCellS_[0]);
702  }
703  return std::make_pair(indx, cell);
704 }
705 
707  int ll(-1);
708  if (waferHexagon6() && reco) {
709  ll = static_cast<int>(std::find(hgpar_->depthLayerF_.begin(), hgpar_->depthLayerF_.end(), index) -
710  hgpar_->depthLayerF_.begin());
711  if (ll == static_cast<int>(hgpar_->depthLayerF_.size()))
712  ll = -1;
713  }
714 #ifdef EDM_ML_DEBUG
715  edm::LogVerbatim("HGCalGeom") << "LayerFromIndex for " << index << ":" << reco << ":" << waferHexagon6() << " is"
716  << ll << ":" << (ll + hgpar_->firstLayer_);
717 #endif
718  return ((ll < 0) ? ll : (ll + hgpar_->firstLayer_));
719 }
720 
721 bool HGCalTBDDDConstants::isValidCell(int lay, int wafer, int cell) const {
722  // Calculate the position of the cell
723  // Works for options HGCalHexagon/HGCalHexagonFull
724  double x = hgpar_->waferPosX_[wafer];
725  double y = hgpar_->waferPosY_[wafer];
726  if (hgpar_->waferTypeT_[wafer] - 1 == HGCalTBParameters::HGCalFine) {
727  x += hgpar_->cellFineX_[cell];
728  y += hgpar_->cellFineY_[cell];
729  } else {
730  x += hgpar_->cellCoarseX_[cell];
731  y += hgpar_->cellCoarseY_[cell];
732  }
733  double rr = sqrt(x * x + y * y);
734  bool result = ((rr >= hgpar_->rMinLayHex_[lay - 1]) && (rr <= hgpar_->rMaxLayHex_[lay - 1]) &&
735  (wafer < static_cast<int>(hgpar_->waferPosX_.size())));
736 #ifdef EDM_ML_DEBUG
737  if (!result)
738  edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << wafer << ":" << cell << " Position " << x << ":" << y
739  << ":" << rr << " Compare Limits " << hgpar_->rMinLayHex_[lay - 1] << ":"
740  << hgpar_->rMaxLayHex_[lay - 1] << " Flag " << result;
741 #endif
742  return result;
743 }
744 
745 int32_t HGCalTBDDDConstants::waferIndex(int wafer, int index) const {
746  int layer = layerFromIndex(index, true);
747  int indx = HGCalWaferIndex::waferIndex(layer, wafer, 0);
748 #ifdef EDM_ML_DEBUG
749  edm::LogVerbatim("HGCalGeom") << "WaferIndex for " << wafer << ":" << index << " (" << layer << ") " << indx;
750 #endif
751  return indx;
752 }
753 
755 
const HGCalGeometryMode::GeometryMode mode_
size
Write out results.
std::vector< double > moduleCellR_
Log< level::Info, true > LogVerbatim
std::vector< double > cellFineX_
std::pair< double, double > rangeZ(bool reco) const
std::vector< int > layer_
std::pair< int, int > assignCell(float x, float y, int lay, int subSec, bool reco) const
int32_t waferIndex(int wafer, int index) const
bool waferInLayer(int wafer, int lay, bool reco) const
std::vector< bool > cellCoarseHalf_
static int32_t getUnpackedU(int id)
Definition: HGCalTypes.cc:16
int lastLayer(bool reco) const
std::vector< int > waferCopy_
static constexpr double k_ScaleFromDDD
std::vector< double > rMaxLayHex_
std::vector< HGCalTBParameters::hgtrform > getTrForms() const
std::array< uint32_t, 2 > tot_layers_
int numberCellsHexagon(int wafer) const
double waferZ(int layer, bool reco) const
bool isHalfCell(int waferType, int cell) const
std::vector< int > waferTypeL_
std::pair< double, double > waferParameters(bool reco) const
static int32_t getUnpackedV(int id)
Definition: HGCalTypes.cc:22
std::vector< double > cellCoarseY_
bool waferVirtual(int layer, int wafer) const
std::vector< int > moduleLayR_
std::pair< float, float > locateCellHex(int cell, int wafer, bool reco) const
std::array< int, 4 > waferMax_
std::vector< HGCalTBParameters::hgtrap > getModules() const
const HGCalTBParameters * hgpar_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< int > layerIndex_
std::vector< double > cellCoarseX_
std::pair< float, float > locateCell(int cell, int lay, int type, bool reco) const
double mouseBite(bool reco) const
std::pair< int, float > getIndex(int lay, bool reco) const
float float float z
std::pair< double, double > rangeR(double z, bool reco) const
static constexpr double k_ScaleToDDD
std::vector< double > waferPosX_
hgtrform getTrForm(unsigned int k) const
unsigned int layersInit(bool reco) const
std::pair< double, double > rangeRLayer(int lay, bool reco) const
std::vector< int > depthIndex_
std::vector< double > zLayerHex_
int layerFromIndex(int index, bool reco) const
int maxRows(int lay, bool reco) const
std::vector< int > waferTypeT_
std::map< int, HGCWaferParam > waferLayer_
void waferFromPosition(const double x, const double y, int &wafer, int &icell, int &celltyp) const
T sqrt(T t)
Definition: SSEVec.h:23
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::array< int, 3 > HGCWaferParam
int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV, bool old=false)
std::pair< double, double > waferPosition(int wafer, bool reco) const
bool isValidCell(int layindex, int wafer, int cell) const
int layerIndex(int lay, bool reco) const
Definition: DetId.h:17
double cellThickness(int layer, int wafer) const
double cellSizeHex(int type) const
bool waferFullInLayer(int wafer, int lay, bool reco) const
unsigned int getTrFormN() const
HGCalTBParameters::hgtrap getModule(unsigned int k, bool hexType, bool reco) const
std::vector< double > rMinLayHex_
static constexpr double tan30deg_
std::vector< double > cellFineY_
std::vector< double > cellSize_
int cellHex(double xx, double yy, const double &cellR, const std::vector< double > &posX, const std::vector< double > &posY) const
std::pair< int, int > rowColumnWafer(const int wafer) const
double distFromEdgeHex(double x, double y, double z) const
int modifyUV(int uv, int type1, int type2) const
std::vector< int > depth_
std::vector< uint32_t > trformIndex_
fixed size matrix
unsigned int layers(bool reco) const
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:102
std::vector< int > depthLayerF_
col
Definition: cuy.py:1009
float x
std::vector< bool > cellFineHalf_
std::vector< int > layerGroupO_
int waferType(DetId const &id) const
bool isValidHex(int lay, int mod, int cell, bool reco) const
bool waferInLayerTest(int wafer, int lay) const
int maxCells(bool reco) const
Log< level::Warning, false > LogWarning
int modulesInit(int lay, bool reco) const
__host__ __device__ V wmin
int getLayer(double z, bool reco) const
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
int modules(int lay, bool reco) const
int waferFromCopy(int copy) const
HGCalTBParameters::hgtrform getTrForm(unsigned int k) const
std::vector< double > moduleCellS_
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
std::vector< double > waferPosY_
int numberCells(bool reco) const
HGCalTBDDDConstants(const HGCalTBParameters *hp, const std::string &name)
__host__ __device__ V V wmax
hgtrap getModule(unsigned int k, bool reco) const