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