CMS 3D CMS Logo

HGCalDDDConstants.cc
Go to the documentation of this file.
2 
15 
16 #include <algorithm>
17 #include <bitset>
18 #include <iterator>
19 #include <functional>
20 #include <numeric>
21 
22 //#define EDM_ML_DEBUG
23 using namespace geant_units::operators;
24 
26  : hgpar_(hp), sqrt3_(std::sqrt(3.0)), mode_(hgpar_->mode_), fullAndPart_(waferHexagon8File()) {
27 #ifdef EDM_ML_DEBUG
28  edm::LogVerbatim("HGCalGeom") << "Mode " << mode_ << " FullAndPart " << fullAndPart_;
29 #endif
30  if (waferHexagon6() || waferHexagon8()) {
33  hexside_ = 2.0 * rmax_ * tan30deg_;
34  hexsideT_ = 2.0 * rmaxT_ * tan30deg_;
35  hgcell_ = std::make_unique<HGCalCell>(2.0 * rmaxT_, hgpar_->nCellsFine_, hgpar_->nCellsCoarse_);
36  hgcellUV_ = std::make_unique<HGCalCellUV>(
38 #ifdef EDM_ML_DEBUG
39  edm::LogVerbatim("HGCalGeom") << "rmax_ " << rmax_ << ":" << rmaxT_ << ":" << hexside_ << ":" << hexsideT_
40  << " CellSize " << 0.5 * HGCalParameters::k_ScaleFromDDD * hgpar_->cellSize_[0] << ":"
42 #endif
43  }
46 #ifdef EDM_ML_DEBUG
47  edm::LogVerbatim("HGCalGeom") << "Setup HGCalCassette for " << hgpar_->cassettes_ << " cassettes";
48 #endif
49  }
50  // init maps and constants
51  modHalf_ = 0;
53  for (int simreco = 0; simreco < 2; ++simreco) {
54  tot_layers_[simreco] = layersInit((bool)simreco);
55  max_modules_layer_[simreco].resize(tot_layers_[simreco] + 1);
56  for (unsigned int layer = 1; layer <= tot_layers_[simreco]; ++layer) {
57  max_modules_layer_[simreco][layer] = modulesInit(layer, (bool)simreco);
58  if (simreco == 1) {
59  modHalf_ += max_modules_layer_[simreco][layer];
61 #ifdef EDM_ML_DEBUG
62  edm::LogVerbatim("HGCalGeom") << "Layer " << layer << " with " << max_modules_layer_[simreco][layer] << ":"
63  << modHalf_ << " modules in RECO";
64  } else {
65  edm::LogVerbatim("HGCalGeom") << "Layer " << layer << " with " << max_modules_layer_[simreco][layer]
66  << " modules in SIM";
67 #endif
68  }
69  }
70 #ifdef EDM_ML_DEBUG
71  edm::LogVerbatim("HGCalGeom") << "SimReco " << simreco << " with " << tot_layers_[simreco] << " Layers";
72 #endif
73  }
74  tot_wafers_ = wafers();
75 
76 #ifdef EDM_ML_DEBUG
77  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants initialized for " << name << " with " << layers(false) << ":"
78  << layers(true) << " layers, " << wafers() << ":" << 2 * modHalf_
79  << " wafers with maximum " << maxWafersPerLayer_ << " per layer and "
80  << "maximum of " << maxCells(false) << ":" << maxCells(true) << " cells";
81 #endif
82  if (waferHexagon6() || waferHexagon8()) {
83  int wminT(9999999), wmaxT(-9999999), kount1(0), kount2(0);
84  for (unsigned int i = 0; i < getTrFormN(); ++i) {
85  int lay0 = getTrForm(i).lay;
86  int wmin(9999999), wmax(-9999999), kount(0);
87  for (int wafer = 0; wafer < sectors(); ++wafer) {
88  bool waferIn = waferInLayer(wafer, lay0, true);
89  if (waferHexagon8()) {
90  int kndx = HGCalWaferIndex::waferIndex(lay0,
93  waferIn_[kndx] = waferIn;
94  }
95  if (waferIn) {
96  int waferU = ((waferHexagon6()) ? wafer : HGCalWaferIndex::waferU(hgpar_->waferCopy_[wafer]));
97  if (waferU < wmin)
98  wmin = waferU;
99  if (waferU > wmax)
100  wmax = waferU;
101  ++kount;
102  }
103  }
104  if (wminT > wmin)
105  wminT = wmin;
106  if (wmaxT < wmax)
107  wmaxT = wmax;
108  if (kount1 < kount)
109  kount1 = kount;
110  kount2 += kount;
111 #ifdef EDM_ML_DEBUG
112  int lay1 = getIndex(lay0, true).first;
113  edm::LogVerbatim("HGCalGeom") << "Index " << i << " Layer " << lay0 << ":" << lay1 << " Wafer " << wmin << ":"
114  << wmax << ":" << kount;
115 #endif
116  HGCWaferParam a1{{wmin, wmax, kount}};
117  waferLayer_[lay0] = a1;
118  }
119  waferMax_ = std::array<int, 4>{{wminT, wmaxT, kount1, kount2}};
120 #ifdef EDM_ML_DEBUG
121  edm::LogVerbatim("HGCalGeom") << "Overall wafer statistics: " << wminT << ":" << wmaxT << ":" << kount1 << ":"
122  << kount2;
123 #endif
124  }
125 }
126 
127 std::pair<int, int> HGCalDDDConstants::assignCell(float x, float y, int lay, int subSec, bool reco) const {
128  const auto& index = getIndex(lay, reco);
129  if (index.first < 0)
130  return std::make_pair(-1, -1);
131  if (waferHexagon6()) {
132  float xx = (reco) ? x : HGCalParameters::k_ScaleFromDDD * x;
133  float yy = (reco) ? y : HGCalParameters::k_ScaleFromDDD * y;
134 
135  // First the wafer
136  int wafer = cellHex(xx, yy, rmax_, hgpar_->waferPosX_, hgpar_->waferPosY_);
137  if (wafer < 0 || wafer >= static_cast<int>(hgpar_->waferTypeT_.size())) {
138  edm::LogWarning("HGCalGeom") << "Wafer no. out of bound for " << wafer << ":" << (hgpar_->waferTypeT_).size()
139  << ":" << (hgpar_->waferPosX_).size() << ":" << (hgpar_->waferPosY_).size()
140  << " ***** ERROR *****";
141  return std::make_pair(-1, -1);
142  } else {
143  // Now the cell
144  xx -= hgpar_->waferPosX_[wafer];
145  yy -= hgpar_->waferPosY_[wafer];
146  if (hgpar_->waferTypeT_[wafer] == 1)
147  return std::make_pair(wafer,
148  cellHex(xx,
149  yy,
152  hgpar_->cellFineY_));
153  else
154  return std::make_pair(wafer,
155  cellHex(xx,
156  yy,
159  hgpar_->cellCoarseY_));
160  }
161  } else {
162  return std::make_pair(-1, -1);
163  }
164 }
165 
167  float x, float y, int lay, bool reco, bool extend, bool debug) const {
168  int waferU(0), waferV(0), waferType(-1), cellU(0), cellV(0);
169  if (waferHexagon8()) {
170  double xx = (reco) ? HGCalParameters::k_ScaleToDDD * x : x;
171  double yy = (reco) ? HGCalParameters::k_ScaleToDDD * y : y;
172  double wt(1.0);
173 #ifdef EDM_ML_DEBUG
174  edm::LogVerbatim("HGCalGeom") << "assignCellHex x " << x << ":" << xx << " y " << y << ":" << yy << " Lay " << lay;
175 #endif
176  waferFromPosition(xx, yy, lay, waferU, waferV, cellU, cellV, waferType, wt, extend, debug);
177  }
178  return std::array<int, 5>{{waferU, waferV, waferType, cellU, cellV}};
179 }
180 
181 std::array<int, 3> HGCalDDDConstants::assignCellTrap(float x, float y, float z, int layer, bool reco) const {
182  int irad(-1), iphi(-1), type(-1);
183  const auto& indx = getIndex(layer, reco);
184  if (indx.first < 0)
185  return std::array<int, 3>{{irad, iphi, type}};
186  double xx = (reco) ? ((z > 0) ? x : -x)
188  double yy = (reco) ? y : HGCalParameters::k_ScaleFromDDD * y;
189  int ll = layer - hgpar_->firstLayer_;
190  xx -= hgpar_->xLayerHex_[ll];
191  yy -= hgpar_->yLayerHex_[ll];
194  auto cshift = hgcassette_.getShift(layer, 1, cassette);
195 #ifdef EDM_ML_DEBUG
196  edm::LogVerbatim("HGCalGeom") << "Cassette " << cassette << " Shift " << cshift.first << ":" << cshift.second;
197 #endif
198  xx -= cshift.first;
199  yy -= cshift.second;
200  }
201  double phi = (((yy == 0.0) && (xx == 0.0)) ? 0. : std::atan2(yy, xx));
202  if (phi < 0)
203  phi += (2.0 * M_PI);
204  if (indx.second != 0)
205  iphi = 1 + static_cast<int>(phi / indx.second);
207  double r = std::sqrt(xx * xx + yy * yy);
208  auto ir = std::lower_bound(hgpar_->radiusLayer_[type].begin(), hgpar_->radiusLayer_[type].end(), r);
209  irad = static_cast<int>(ir - hgpar_->radiusLayer_[type].begin());
210  irad = std::clamp(irad, hgpar_->iradMinBH_[indx.first], hgpar_->iradMaxBH_[indx.first]);
211 #ifdef EDM_ML_DEBUG
212  edm::LogVerbatim("HGCalGeom") << "assignCellTrap Input " << x << ":" << y << ":" << z << ":" << layer << ":" << reco
213  << " x|y|r " << xx << ":" << yy << ":" << r << " phi " << phi << ":"
214  << convertRadToDeg(phi) << " o/p " << irad << ":" << iphi << ":" << type;
215 #endif
216  return std::array<int, 3>{{irad, iphi, type}};
217 }
218 
219 std::pair<double, double> HGCalDDDConstants::cellEtaPhiTrap(int type, int irad) const {
220  double dr(0), df(0);
221  if (tileTrapezoid()) {
222  double r = 0.5 * ((hgpar_->radiusLayer_[type][irad - 1] + hgpar_->radiusLayer_[type][irad]));
223  dr = (hgpar_->radiusLayer_[type][irad] - hgpar_->radiusLayer_[type][irad - 1]);
224  df = r * hgpar_->cellSize_[type];
225  }
226  return std::make_pair(dr, df);
227 }
228 
229 bool HGCalDDDConstants::cellInLayer(int waferU, int waferV, int cellU, int cellV, int lay, bool reco) const {
230  const auto& indx = getIndex(lay, true);
231  if (indx.first >= 0) {
233  int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
234  auto ktr = hgpar_->waferInfoMap_.find(indx);
235  int part = (ktr != hgpar_->waferInfoMap_.end()) ? (ktr->second).part : HGCalTypes::WaferFull;
236  return HGCalWaferMask::goodCell(cellU, cellV, part);
238  int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
239  auto ktr = hgpar_->waferInfoMap_.find(indx);
241  if (ktr != hgpar_->waferInfoMap_.end()) {
242  thck = (ktr->second).type;
243  part = (ktr->second).part;
244  rotn = (ktr->second).orient;
245  }
247  return HGCalWaferMask::goodCell(cellU, cellV, ncell, part, rotn);
248  } else if (waferHexagon8() || waferHexagon6()) {
249  const auto& xy = ((waferHexagon8()) ? locateCell(lay, waferU, waferV, cellU, cellV, reco, true, false, false)
250  : locateCell(cellU, lay, waferU, reco));
251  double rpos = sqrt(xy.first * xy.first + xy.second * xy.second);
252  return ((rpos >= hgpar_->rMinLayHex_[indx.first]) && (rpos <= hgpar_->rMaxLayHex_[indx.first]));
253  } else {
254  return true;
255  }
256  } else {
257  return false;
258  }
259 }
260 
262  double thick(-1);
263  int type = waferType(layer, waferU, waferV, false);
264  if (type >= 0) {
265  if (waferHexagon8()) {
266  thick = 10000.0 * hgpar_->cellThickness_[type]; // cm to micron
267  } else if (waferHexagon6()) {
268  thick = 100.0 * (type + 1); // type = 1,2,3 for 100,200,300 micron
269  }
270  }
271  return thick;
272 }
273 
275  int indx = ((waferHexagon8()) ? ((type >= 1) ? 1 : 0) : ((type == 1) ? 1 : 0));
276  double cell = (tileTrapezoid() ? 0.5 * hgpar_->cellSize_[indx]
278  return cell;
279 }
280 
281 int32_t HGCalDDDConstants::cellType(int type, int cellU, int cellV, int iz, int fwdBack, int orient) const {
282  int placement = (orient < 0) ? HGCalCell::cellPlacementOld : HGCalCell::cellPlacementIndex(iz, fwdBack, orient);
283  int ncell = (type == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
284  auto cellType = HGCalCell::cellType(cellU, cellV, ncell, placement);
285  return cellType.first;
286 }
287 
288 double HGCalDDDConstants::distFromEdgeHex(double x, double y, double z) const {
289  // Assming the point is within a hexagonal plane of the wafer, calculate
290  // the shortest distance from the edge
291  if (z < 0)
292  x = -x;
293  double dist(0);
294  // Input x, y in Geant4 unit and transformed to CMSSW standard
297  if (waferHexagon8()) {
298  int ll = layerIndex(getLayer(z, false), false);
299  xx -= hgpar_->xLayerHex_[ll];
300  yy -= hgpar_->yLayerHex_[ll];
301  }
302  int sizew = static_cast<int>(hgpar_->waferPosX_.size());
303  int wafer = sizew;
304  // Transform to the local coordinate frame of the wafer first
305  for (int k = 0; k < sizew; ++k) {
306  double dx = std::abs(xx - hgpar_->waferPosX_[k]);
307  double dy = std::abs(yy - hgpar_->waferPosY_[k]);
308  if ((dx <= rmax_) && (dy <= hexside_) && ((dy <= 0.5 * hexside_) || (dx * tan30deg_ <= (hexside_ - dy)))) {
309  wafer = k;
310  xx -= hgpar_->waferPosX_[k];
311  yy -= hgpar_->waferPosY_[k];
312  break;
313  }
314  }
315  // Look at only one quarter (both x,y are positive)
316  if (wafer < sizew) {
317  if (std::abs(yy) < 0.5 * hexside_) {
318  dist = rmax_ - std::abs(xx);
319  } else {
320  dist = 0.5 * ((rmax_ - std::abs(xx)) - sqrt3_ * (std::abs(yy) - 0.5 * hexside_));
321  }
322  } else {
323  dist = 0;
324  }
326 #ifdef EDM_ML_DEBUG
327  edm::LogVerbatim("HGCalGeom") << "DistFromEdgeHex: Local " << xx << ":" << yy << " wafer " << wafer << " flag "
328  << (wafer < sizew) << " Distance " << rmax_ << ":" << (rmax_ - std::abs(xx)) << ":"
329  << (std::abs(yy) - 0.5 * hexside_) << ":" << 0.5 * hexside_ << ":" << dist;
330 #endif
331  return dist;
332 }
333 
334 double HGCalDDDConstants::distFromEdgeTrap(double x, double y, double z) const {
335  // Assming the point is within the eta-phi plane of the scintillator tile,
336  // calculate the shortest distance from the edge
337  int lay = getLayer(z, false);
338  double xx = (z < 0) ? -x : x;
339  int indx = layerIndex(lay, false);
340  double r = HGCalParameters::k_ScaleFromDDD * std::sqrt(x * x + y * y);
341  double phi = (r == 0. ? 0. : std::atan2(y, xx));
342  if (phi < 0)
343  phi += (2.0 * M_PI);
344  int type = hgpar_->scintType(lay);
345  double cell = hgpar_->scintCellSize(lay);
346  // Compare with the center of the tile find distances along R and also phi
347  // Take the smaller value
348  auto ir = std::lower_bound(hgpar_->radiusLayer_[type].begin(), hgpar_->radiusLayer_[type].end(), r);
349  int irad = static_cast<int>(ir - hgpar_->radiusLayer_[type].begin());
350  irad = std::clamp(irad, hgpar_->iradMinBH_[indx], hgpar_->iradMaxBH_[indx]);
351  int iphi = 1 + static_cast<int>(phi / cell);
352  double dphi = std::max(0.0, (0.5 * cell - std::abs(phi - (iphi - 0.5) * cell)));
353  double dist = std::min((r - hgpar_->radiusLayer_[type][irad - 1]), (hgpar_->radiusLayer_[type][irad] - r));
354 #ifdef EDM_ML_DEBUG
355  edm::LogVerbatim("HGCalGeom") << "DistFromEdgeTrap: Global " << x << ":" << y << ":" << z << " Layer " << lay
356  << " Index " << indx << ":" << type << " xx " << xx << " R " << r << ":" << irad << ":"
357  << hgpar_->radiusLayer_[type][irad - 1] << ":" << hgpar_->radiusLayer_[type][irad]
358  << " Phi " << phi << ":" << iphi << ":" << (iphi - 0.5) * cell << " cell " << cell
359  << " Dphi " << dphi << " Dist " << dist << ":" << r * dphi;
360 #endif
361  return HGCalParameters::k_ScaleToDDD * std::min(r * dphi, dist);
362 }
363 
364 int HGCalDDDConstants::getLayer(double z, bool reco) const {
365  // Get the layer # from the gloabl z coordinate
366  unsigned int k = 0;
368  const auto& zLayerHex = hgpar_->zLayerHex_;
369  auto itr = std::find_if(zLayerHex.begin() + 1, zLayerHex.end(), [&k, &zz, &zLayerHex](double zLayer) {
370  ++k;
371  return zz < 0.5 * (zLayerHex[k - 1] + zLayerHex[k]);
372  });
373  int lay = (itr == zLayerHex.end()) ? static_cast<int>(zLayerHex.size()) : k;
374  if (waferHexagon6() && reco) {
375  int indx = layerIndex(lay, false);
376  if (indx >= 0)
377  lay = hgpar_->layerGroupO_[indx];
378  } else {
379  lay += (hgpar_->firstLayer_ - 1);
380  }
381  return lay;
382 }
383 
384 HGCalParameters::hgtrap HGCalDDDConstants::getModule(unsigned int indx, bool hexType, bool reco) const {
386  if (hexType) {
387  if (indx >= hgpar_->waferTypeL_.size())
388  edm::LogWarning("HGCalGeom") << "Wafer no. out bound for index " << indx << ":" << (hgpar_->waferTypeL_).size()
389  << ":" << (hgpar_->waferPosX_).size() << ":" << (hgpar_->waferPosY_).size()
390  << " ***** ERROR *****";
391  unsigned int type =
392  ((indx < hgpar_->waferTypeL_.size()) ? hgpar_->waferTypeL_[indx] - 1 : HGCSiliconDetId::HGCalCoarseThick);
393  mytr = hgpar_->getModule(type, reco);
394  } else {
395  mytr = hgpar_->getModule(indx, reco);
396  }
397  return mytr;
398 }
399 
400 std::vector<HGCalParameters::hgtrap> HGCalDDDConstants::getModules() const {
401  std::vector<HGCalParameters::hgtrap> mytrs;
402  for (unsigned int k = 0; k < hgpar_->moduleLayR_.size(); ++k)
403  mytrs.emplace_back(hgpar_->getModule(k, true));
404  return mytrs;
405 }
406 
407 int HGCalDDDConstants::getPhiBins(int lay) const { return (tileTrapezoid() ? hgpar_->scintCells(lay) : 0); }
408 
409 std::pair<int, int> HGCalDDDConstants::getREtaRange(int lay) const {
410  int irmin(0), irmax(0);
411  if (tileTrapezoid()) {
412  int indx = layerIndex(lay, false);
413  if ((indx >= 0) && (indx < static_cast<int>(hgpar_->iradMinBH_.size()))) {
414  irmin = hgpar_->iradMinBH_[indx];
415  irmax = hgpar_->iradMaxBH_[indx];
416  }
417  }
418  return std::make_pair(irmin, irmax);
419 }
420 
421 std::vector<HGCalParameters::hgtrform> HGCalDDDConstants::getTrForms() const {
422  std::vector<HGCalParameters::hgtrform> mytrs;
423  for (unsigned int k = 0; k < hgpar_->trformIndex_.size(); ++k)
424  mytrs.emplace_back(hgpar_->getTrForm(k));
425  return mytrs;
426 }
427 
429  // Get the module type for scinitllator
430  if (tileTrapezoid()) {
431  return hgpar_->scintType(layer);
432  } else {
433  return -1;
434  }
435 }
436 
438  // Get the module type for a silicon wafer
439  if (waferHexagon8()) {
441  return ((itr == hgpar_->typesInLayers_.end() ? 2 : hgpar_->waferTypeL_[itr->second]));
442  } else {
443  return -1;
444  }
445 }
446 
447 std::pair<double, double> HGCalDDDConstants::getXY(int layer, double x, double y, bool forwd) const {
448  int ll = layer - hgpar_->firstLayer_;
449  double x0(x), y0(y);
450  if ((!hgpar_->layerType_.empty()) && (ll < static_cast<int>(hgpar_->layerRotV_.size()))) {
451  if (forwd) {
452  x0 = x * hgpar_->layerRotV_[ll].first + y * hgpar_->layerRotV_[ll].second;
453  y0 = y * hgpar_->layerRotV_[ll].first - x * hgpar_->layerRotV_[ll].second;
454  } else {
455  x0 = x * hgpar_->layerRotV_[ll].first - y * hgpar_->layerRotV_[ll].second;
456  y0 = y * hgpar_->layerRotV_[ll].first + x * hgpar_->layerRotV_[ll].second;
457  }
458  }
459 #ifdef EDM_ML_DEBUG
460  double x1(x0), y1(y0);
461  if (ll < static_cast<int>(hgpar_->layerRotV_.size())) {
462  if (forwd) {
463  x1 = x0 * hgpar_->layerRotV_[ll].first - y0 * hgpar_->layerRotV_[ll].second;
464  y1 = y0 * hgpar_->layerRotV_[ll].first + x0 * hgpar_->layerRotV_[ll].second;
465  } else {
466  x1 = x0 * hgpar_->layerRotV_[ll].first + y0 * hgpar_->layerRotV_[ll].second;
467  y1 = y0 * hgpar_->layerRotV_[ll].first - x0 * hgpar_->layerRotV_[ll].second;
468  }
469  }
470  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants: Layer " << layer << ":" << ll << " mode " << forwd << " x " << x
471  << ":" << x0 << ":" << x1 << " y " << y << ":" << y0 << ":" << y1;
472 #endif
473  return std::make_pair(x0, y0);
474 }
475 
476 bool HGCalDDDConstants::isHalfCell(int waferType, int cell) const {
477  if (waferType < 1 || cell < 0)
478  return false;
479  return waferType == 2 ? hgpar_->cellCoarseHalf_[cell] : hgpar_->cellFineHalf_[cell];
480 }
481 
482 bool HGCalDDDConstants::isValidHex(int lay, int mod, int cell, bool reco) const {
483  // Check validity for a layer|wafer|cell of pre-TDR version
484  bool result(false), resultMod(false);
485  int cellmax(0);
486  if (waferHexagon6()) {
487  int32_t copyNumber = hgpar_->waferCopy_[mod];
488  result = ((lay > 0 && lay <= static_cast<int>(layers(reco))));
489  if (result) {
490  const int32_t lay_idx = reco ? (lay - 1) * 3 + 1 : lay;
491  const auto& the_modules = hgpar_->copiesInLayers_[lay_idx];
492  auto moditr = the_modules.find(copyNumber);
493  result = resultMod = (moditr != the_modules.end());
494 #ifdef EDM_ML_DEBUG
495  if (!result)
496  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants: Layer " << lay << ":" << lay_idx << " Copy " << copyNumber
497  << ":" << mod << " Flag " << result;
498 #endif
499  if (result) {
500  if (moditr->second >= 0) {
501  if (mod >= static_cast<int>(hgpar_->waferTypeT_.size()))
502  edm::LogWarning("HGCalGeom") << "Module no. out of bound for " << mod << " to be compared with "
503  << (hgpar_->waferTypeT_).size() << " ***** ERROR *****";
504  cellmax = ((hgpar_->waferTypeT_[mod] - 1 == HGCSiliconDetId::HGCalFine)
505  ? static_cast<int>(hgpar_->cellFineX_.size())
506  : static_cast<int>(hgpar_->cellCoarseX_.size()));
507  result = (cell >= 0 && cell <= cellmax);
508  } else {
509  result = isValidCell(lay_idx, mod, cell);
510  }
511  }
512  }
513  }
514 
515 #ifdef EDM_ML_DEBUG
516  if (!result)
517  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants: Layer " << lay << ":"
518  << (lay > 0 && (lay <= static_cast<int>(layers(reco)))) << " Module " << mod << ":"
519  << resultMod << " Cell " << cell << ":" << cellmax << ":"
520  << (cell >= 0 && cell <= cellmax) << ":" << maxCells(reco);
521 #endif
522  return result;
523 }
524 
525 bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, bool fullAndPart) const {
526  // Check validity for a layer|wafer|cell of post-TDR version
527  int indx = HGCalWaferIndex::waferIndex(layer, modU, modV);
528  auto itr = hgpar_->typesInLayers_.find(indx);
529 #ifdef EDM_ML_DEBUG
530  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants::isValidHex8:WaferType " << layer << ":" << modU << ":" << modV
531  << ":" << indx << " Test " << (itr != hgpar_->typesInLayers_.end());
532 #endif
533  if (itr == hgpar_->typesInLayers_.end()) {
534 #ifdef EDM_ML_DEBUG
535  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
536  << " in wadferIndex";
537 #endif
538  return false;
539  }
540 
541  if (fullAndPart_) {
542  auto ktr = hgpar_->waferInfoMap_.find(indx);
543 #ifdef EDM_ML_DEBUG
544  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants::isValidHex8:WaferInfoMap " << layer << ":" << modU << ":"
545  << modV << ":" << indx << " Test " << (ktr != hgpar_->waferInfoMap_.end());
546 #endif
547  if (ktr == hgpar_->waferInfoMap_.end()) {
548 #ifdef EDM_ML_DEBUG
549  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
550  << " in wadferInfoMap";
551 #endif
552  return false;
553  }
554  } else {
555  auto jtr = waferIn_.find(indx);
556 #ifdef EDM_ML_DEBUG
557  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants::isValidHex8:WaferIn " << jtr->first << ":" << jtr->second;
558 #endif
559  if (!(jtr->second)) {
560 #ifdef EDM_ML_DEBUG
561  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
562  << " in wadferIn";
563 #endif
564  return false;
565  }
566  }
567 
568  if (fullAndPart || fullAndPart_) {
569  auto ktr = hgpar_->waferTypes_.find(indx);
570  if (ktr != hgpar_->waferTypes_.end()) {
571  if (hgpar_->waferMaskMode_ > 0) {
572  if (ktr->second.first == HGCalTypes::WaferOut) {
573 #ifdef EDM_ML_DEBUG
574  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
575  << " due to WaferOut";
576 #endif
577  return false;
578  }
579  } else {
580  if (ktr->second.first < HGCalTypes::WaferCornerMin) {
581 #ifdef EDM_ML_DEBUG
582  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
583  << " due to WaferCornerMin";
584 #endif
585  return false;
586  }
587  }
588  }
589  }
590  return true;
591 }
592 
593 bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, int cellU, int cellV, bool fullAndPart) const {
594  // First check validity for a layer|wafer| of post TDR version
595 #ifdef EDM_ML_DEBUG
596  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: layer|wafer " << layer << ":" << modU << ":" << modV << ":"
597  << fullAndPart << " Valid " << isValidHex8(layer, modU, modV, fullAndPart);
598 #endif
599  if (!isValidHex8(layer, modU, modV, fullAndPart))
600  return false;
601  int indx = HGCalWaferIndex::waferIndex(layer, modU, modV);
602  auto itr = hgpar_->typesInLayers_.find(indx);
603  int type = hgpar_->waferTypeL_[itr->second];
604  int N = ((hgpar_->waferTypeL_[itr->second] == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_);
605 #ifdef EDM_ML_DEBUG
606  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants::isValidHex8:Cell " << cellU << ":" << cellV << ":" << N
607  << " Tests " << (cellU >= 0) << ":" << (cellU < 2 * N) << ":" << (cellV >= 0) << ":"
608  << (cellV < 2 * N) << ":" << ((cellV - cellU) < N) << ":" << ((cellU - cellV) <= N);
609 #endif
611  if ((cellU < 0) || (cellU >= 2 * N) || (cellV < 0) || (cellV >= 2 * N)) {
612 #ifdef EDM_ML_DEBUG
613  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot statisfy Cell 1 condition " << cellU << ":" << cellV
614  << ":" << N;
615 #endif
616  return false;
617  }
618  if (((cellV - cellU) >= N) || ((cellU - cellV) > N)) {
619 #ifdef EDM_ML_DEBUG
620  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot statisfy Cell 2 condition " << cellU << ":" << cellV
621  << ":" << N;
622 #endif
623  return false;
624  }
625  }
626  return isValidCell8(layer, modU, modV, cellU, cellV, type);
627 }
628 
629 bool HGCalDDDConstants::isValidTrap(int zside, int layer, int irad, int iphi) const {
630  // Check validity for a layer|eta|phi of scintillator
631  const auto& indx = getIndex(layer, true);
632  if (indx.first < 0)
633  return false;
634  bool ok = ((irad >= hgpar_->iradMinBH_[indx.first]) && (irad <= (hgpar_->iradMaxBH_[indx.first] + 1)) && (iphi > 0) &&
635  (iphi <= hgpar_->scintCells(layer)));
636  return ((ok && trapezoidFile()) ? tileExist(zside, layer, irad, iphi) : ok);
637 }
638 
640  return (hgpar_->firstLayer_ + tot_layers_[static_cast<int>(reco)] - 1);
641 }
642 
643 unsigned int HGCalDDDConstants::layers(bool reco) const { return tot_layers_[static_cast<int>(reco)]; }
644 
645 int HGCalDDDConstants::layerIndex(int lay, bool reco) const {
646  int ll = lay - hgpar_->firstLayer_;
647  if (ll < 0 || ll >= static_cast<int>(hgpar_->layerIndex_.size()))
648  return -1;
649  if (waferHexagon6()) {
650  if (reco && ll >= static_cast<int>(hgpar_->depthIndex_.size()))
651  return -1;
652  return (reco ? hgpar_->depthLayerF_[ll] : hgpar_->layerIndex_[ll]);
653  } else {
654  return (hgpar_->layerIndex_[ll]);
655  }
656 }
657 
658 unsigned int HGCalDDDConstants::layersInit(bool reco) const {
659  return (reco ? hgpar_->depthIndex_.size() : hgpar_->layerIndex_.size());
660 }
661 
662 std::pair<float, float> HGCalDDDConstants::localToGlobal8(
663  int lay, int waferU, int waferV, double localX, double localY, bool reco, bool debug) const {
664  double x(localX), y(localY);
665  bool rotx =
667  if (debug)
668  edm::LogVerbatim("HGCalGeom") << "LocalToGlobal8 " << lay << ":" << (lay - hgpar_->firstLayer_) << ":" << rotx
669  << " Local (" << x << ":" << y << ") Reco " << reco;
670  if (!reco) {
673  }
674  const auto& xy = waferPositionNoRot(lay, waferU, waferV, reco, debug);
675  x += xy.first;
676  y += xy.second;
677  int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
678  auto ktr = hgpar_->waferInfoMap_.find(indx);
679  if ((mode_ == HGCalGeometryMode::Hexagon8Cassette) && (ktr != hgpar_->waferInfoMap_.end())) {
680  auto cshift = hgcassette_.getShift(lay, 1, (ktr->second).cassette);
681  if (debug)
682  edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << cshift.first << ":"
683  << cshift.second;
684  if (!reco) {
685  x += (HGCalParameters::k_ScaleToDDD)*cshift.first;
686  y += (HGCalParameters::k_ScaleToDDD)*cshift.second;
687  } else {
688  x += cshift.first;
689  y += cshift.second;
690  }
691  }
692  if (debug)
693  edm::LogVerbatim("HGCalGeom") << "With wafer " << x << ":" << y << " by adding " << xy.first << ":" << xy.second;
694  return (rotx ? getXY(lay, x, y, false) : std::make_pair(x, y));
695 }
696 
697 std::pair<float, float> HGCalDDDConstants::locateCell(int cell, int lay, int type, bool reco) const {
698  // type refers to wafer # for hexagon cell
699  float x(999999.), y(999999.);
700  const auto& index = getIndex(lay, reco);
701  int i = index.first;
702  if (i < 0)
703  return std::make_pair(x, y);
704  if (waferHexagon6()) {
705  x = hgpar_->waferPosX_[type];
706  y = hgpar_->waferPosY_[type];
707 #ifdef EDM_ML_DEBUG
708  float x0(x), y0(y);
709 #endif
711  x += hgpar_->cellFineX_[cell];
712  y += hgpar_->cellFineY_[cell];
713  } else {
714  x += hgpar_->cellCoarseX_[cell];
715  y += hgpar_->cellCoarseY_[cell];
716  }
717 #ifdef EDM_ML_DEBUG
718  edm::LogVerbatim("HGCalGeom") << "LocateCell (Wafer) " << x0 << ":" << y0 << " Final " << x << ":" << y;
719 #endif
720  if (!reco) {
723  }
724  }
725  return std::make_pair(x, y);
726 }
727 
728 std::pair<float, float> HGCalDDDConstants::locateCell(
729  int lay, int waferU, int waferV, int cellU, int cellV, bool reco, bool all, bool norot, bool debug) const {
730  double x(0), y(0);
731  int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
732  auto itr = hgpar_->typesInLayers_.find(indx);
733  int type = ((itr == hgpar_->typesInLayers_.end()) ? 2 : hgpar_->waferTypeL_[itr->second]);
734  int layertype = layerType(lay);
735  bool rotx = (norot) ? false : (layertype == HGCalTypes::WaferCenterR);
736  if (debug) {
737  edm::LogVerbatim("HGCalGeom") << "LocateCell " << lay << ":" << (lay - hgpar_->firstLayer_) << ":" << layertype
738  << ":" << rotx << ":" << waferU << ":" << waferV << ":" << indx << ":"
739  << (itr == hgpar_->typesInLayers_.end()) << ":" << type << " Flags " << reco << ":"
740  << all;
741  }
742  auto ktr = hgpar_->waferInfoMap_.end();
743  int place(HGCalCell::cellPlacementOld);
744  if (waferHexagon8File()) {
746  ktr = hgpar_->waferInfoMap_.find(indx);
747  if (ktr != hgpar_->waferInfoMap_.end())
748  place = HGCalCell::cellPlacementIndex(1, HGCalTypes::layerFrontBack(layertype), (ktr->second).orient);
749  }
750  auto xy = hgcell_->cellUV2XY2(cellU, cellV, place, type);
751  x = xy.first;
752  y = xy.second;
753  if (debug)
754  edm::LogVerbatim("HGCalGeom") << "Type " << type << " Place " << place << " Cell " << cellU << ":" << cellV
755  << " Position " << x << ":" << y;
756  } else {
757  int kndx = cellV * 100 + cellU;
758  if (type == 0) {
759  auto jtr = hgpar_->cellFineIndex_.find(kndx);
760  if (jtr != hgpar_->cellFineIndex_.end()) {
761  x = hgpar_->cellFineX_[jtr->second];
762  y = hgpar_->cellFineY_[jtr->second];
763  }
764  if (debug)
765  edm::LogVerbatim("HGCalGeom") << "Fine " << cellU << ":" << cellV << ":" << kndx << ":" << x << ":" << y << ":"
766  << (jtr != hgpar_->cellFineIndex_.end());
767  } else {
768  auto jtr = hgpar_->cellCoarseIndex_.find(kndx);
769  if (jtr != hgpar_->cellCoarseIndex_.end()) {
770  x = hgpar_->cellCoarseX_[jtr->second];
771  y = hgpar_->cellCoarseY_[jtr->second];
772  }
773  if (debug)
774  edm::LogVerbatim("HGCalGeom") << "Coarse " << cellU << ":" << cellV << ":" << kndx << ":" << x << ":" << y
775  << ":" << (jtr != hgpar_->cellCoarseIndex_.end());
776  }
777  }
778  if (!reco) {
781  }
782  if (all) {
783  const auto& xy = waferPositionNoRot(lay, waferU, waferV, reco, debug);
784  x += xy.first;
785  y += xy.second;
786  if ((mode_ == HGCalGeometryMode::Hexagon8Cassette) && (ktr != hgpar_->waferInfoMap_.end())) {
787  auto cshift = hgcassette_.getShift(lay, 1, (ktr->second).cassette);
788  if (debug)
789  edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << cshift.first << ":"
790  << cshift.second;
791  if (!reco) {
792  x += (HGCalParameters::k_ScaleToDDD)*cshift.first;
793  y += (HGCalParameters::k_ScaleToDDD)*cshift.second;
794  } else {
795  x += cshift.first;
796  y += cshift.second;
797  }
798  }
799  if (debug)
800  edm::LogVerbatim("HGCalGeom") << "With wafer " << x << ":" << y << " by adding " << xy.first << ":" << xy.second;
801  }
802  return (rotx ? getXY(lay, x, y, false) : std::make_pair(x, y));
803 }
804 
805 std::pair<float, float> HGCalDDDConstants::locateCell(const HGCSiliconDetId& id, bool debug) const {
806  return locateCell(id.layer(), id.waferU(), id.waferV(), id.cellU(), id.cellV(), true, true, false, debug);
807 }
808 
809 std::pair<float, float> HGCalDDDConstants::locateCell(const HGCScintillatorDetId& id, bool debug) const {
810  return locateCellTrap(id.layer(), id.iradius(), id.iphi(), true, debug);
811 }
812 
813 std::pair<float, float> HGCalDDDConstants::locateCellHex(int cell, int wafer, bool reco) const {
814  float x(0), y(0);
815  if (hgpar_->waferTypeT_[wafer] - 1 == HGCSiliconDetId::HGCalFine) {
816  x = hgpar_->cellFineX_[cell];
817  y = hgpar_->cellFineY_[cell];
818  } else {
819  x = hgpar_->cellCoarseX_[cell];
820  y = hgpar_->cellCoarseY_[cell];
821  }
822  if (!reco) {
825  }
826  return std::make_pair(x, y);
827 }
828 
829 std::pair<float, float> HGCalDDDConstants::locateCellTrap(int lay, int irad, int iphi, bool reco, bool debug) const {
830  float x(0), y(0);
831  const auto& indx = getIndex(lay, reco);
832  if (indx.first >= 0) {
833  int ir = std::abs(irad);
834  int type = hgpar_->scintType(lay);
835  double phi = (iphi - 0.5) * indx.second;
836  double z = hgpar_->zLayerHex_[indx.first];
837  double r = 0.5 * (hgpar_->radiusLayer_[type][ir - 1] + hgpar_->radiusLayer_[type][ir]);
838  std::pair<double, double> range = rangeR(z, true);
839  if (debug)
840  edm::LogVerbatim("HGCalGeom") << "locateCellTrap:: Input " << lay << ":" << irad << ":" << iphi << ":" << reco
841  << " IR " << ir << ":" << hgpar_->iradMinBH_[indx.first] << ":"
842  << hgpar_->iradMaxBH_[indx.first] << " Type " << type << " Z " << indx.first << ":"
843  << z << " phi " << phi << ":" << convertRadToDeg(phi) << " R " << r << ":"
844  << range.first << ":" << range.second;
847  r = std::max(range.first, std::min(r, range.second));
848  x = r * std::cos(phi);
849  y = r * std::sin(phi);
850  int ll = lay - hgpar_->firstLayer_;
851  x += hgpar_->xLayerHex_[ll];
852  y += hgpar_->yLayerHex_[ll];
855  auto cshift = hgcassette_.getShift(lay, 1, cassette);
856  if (debug)
857  edm::LogVerbatim("HGCalGeom") << "Cassette " << cassette << " Shift " << cshift.first << ":" << cshift.second;
858  x += cshift.first;
859  y += cshift.second;
860  }
861  if (irad < 0)
862  x = -x;
863  }
864  if (!reco) {
867  }
868  return std::make_pair(x, y);
869 }
870 
871 bool HGCalDDDConstants::maskCell(const DetId& detId, int corners) const {
872  bool mask(false);
873  if (corners > 2 && corners <= static_cast<int>(HGCalParameters::k_CornerSize)) {
874  if (waferHexagon8()) {
875  int N(0), layer(0), waferU(0), waferV(0), u(0), v(0);
876  if (detId.det() == DetId::Forward) {
877  HFNoseDetId id(detId);
878  N = getUVMax(id.type());
879  layer = id.layer();
880  waferU = id.waferU();
881  waferV = id.waferV();
882  u = id.cellU();
883  v = id.cellV();
884  } else {
885  HGCSiliconDetId id(detId);
886  N = getUVMax(id.type());
887  layer = id.layer();
888  waferU = id.waferU();
889  waferV = id.waferV();
890  u = id.cellU();
891  v = id.cellV();
892  }
894  auto itr = hgpar_->waferTypes_.find(wl);
895  auto ktr = hgpar_->waferInfoMap_.find(wl);
896 #ifdef EDM_ML_DEBUG
897  edm::LogVerbatim("HGCalGeom") << "MaskCell: Layer " << layer << " Wafer " << waferU << ":" << waferV << " Index "
898  << wl << ":" << (itr != hgpar_->waferTypes_.end()) << ":"
899  << (ktr != hgpar_->waferInfoMap_.end());
900 #endif
902  int part = (ktr != hgpar_->waferInfoMap_.end()) ? (ktr->second).part : HGCalTypes::WaferFull;
904  } else if (itr != hgpar_->waferTypes_.end()) {
905  if ((itr->second).second <= HGCalTypes::k_OffsetRotation)
906  mask = HGCalWaferMask::maskCell(u, v, N, (itr->second).first, (itr->second).second, corners);
907  else
909  u, v, N, (itr->second).first, ((itr->second).second - HGCalTypes::k_OffsetRotation)));
910  }
911  }
912  }
913  return mask;
914 }
915 
917  int cells(0);
918  for (unsigned int i = 0; i < layers(reco); ++i) {
919  int lay = reco ? hgpar_->depth_[i] : hgpar_->layer_[i];
920  if (cells < maxCells(lay, reco))
921  cells = maxCells(lay, reco);
922  }
923  return cells;
924 }
925 
926 int HGCalDDDConstants::maxCells(int lay, bool reco) const {
927  const auto& index = getIndex(lay, reco);
928  if (index.first < 0)
929  return 0;
930  if (waferHexagon6()) {
931  unsigned int cells(0);
932  for (unsigned int k = 0; k < hgpar_->waferTypeT_.size(); ++k) {
933  if (waferInLayerTest(k, index.first, hgpar_->defineFull_)) {
934  unsigned int cell = (hgpar_->waferTypeT_[k] - 1 == HGCSiliconDetId::HGCalFine) ? (hgpar_->cellFineX_.size())
935  : (hgpar_->cellCoarseX_.size());
936  if (cell > cells)
937  cells = cell;
938  }
939  }
940  return static_cast<int>(cells);
941  } else if (waferHexagon8()) {
942  int cells(0);
943  for (unsigned int k = 0; k < hgpar_->waferCopy_.size(); ++k) {
944  if (waferInLayerTest(k, index.first, hgpar_->defineFull_)) {
948  : hgpar_->waferTypeL_[itr->second]);
950  cells = std::max(cells, 3 * N * N);
951  }
952  }
953  return cells;
954  } else if (tileTrapezoid()) {
955  return hgpar_->scintCells(index.first + hgpar_->firstLayer_);
956  } else {
957  return 0;
958  }
959 }
960 
961 int HGCalDDDConstants::maxRows(int lay, bool reco) const {
962  int kymax(0);
963  const auto& index = getIndex(lay, reco);
964  int i = index.first;
965  if (i < 0)
966  return kymax;
967  if (waferHexagon6()) {
968  for (unsigned int k = 0; k < hgpar_->waferCopy_.size(); ++k) {
970  int ky = ((hgpar_->waferCopy_[k]) / 100) % 100;
971  if (ky > kymax)
972  kymax = ky;
973  }
974  }
975  } else if (waferHexagon8()) {
976  kymax = 1 + 2 * hgpar_->waferUVMaxLayer_[index.first];
977  }
978  return kymax;
979 }
980 
981 int HGCalDDDConstants::modifyUV(int uv, int type1, int type2) const {
982  // Modify u/v for transition of type1 to type2
983  return (((type1 == type2) || (type1 * type2 != 0)) ? uv : ((type1 == 0) ? (2 * uv + 1) / 3 : (3 * uv) / 2));
984 }
985 
986 int HGCalDDDConstants::modules(int lay, bool reco) const {
987  if (getIndex(lay, reco).first < 0)
988  return 0;
989  else
990  return max_modules_layer_[static_cast<int>(reco)][lay];
991 }
992 
993 int HGCalDDDConstants::modulesInit(int lay, bool reco) const {
994  int nmod(0);
995  const auto& index = getIndex(lay, reco);
996  if (index.first < 0)
997  return nmod;
998  if (!tileTrapezoid()) {
999  for (unsigned int k = 0; k < hgpar_->waferPosX_.size(); ++k) {
1000  if (waferInLayerTest(k, index.first, hgpar_->defineFull_))
1001  ++nmod;
1002  }
1003  } else {
1004  nmod = 1 + hgpar_->lastModule_[index.first] - hgpar_->firstModule_[index.first];
1005  }
1006  return nmod;
1007 }
1008 
1011 }
1012 
1016  ? tileCount(0, -1)
1017  : 0;
1018  if (cells == 0) {
1019  unsigned int nlayer = (reco) ? hgpar_->depth_.size() : hgpar_->layer_.size();
1020  for (unsigned k = 0; k < nlayer; ++k) {
1021  std::vector<int> ncells = numberCells(((reco) ? hgpar_->depth_[k] : hgpar_->layer_[k]), reco);
1022  cells = std::accumulate(ncells.begin(), ncells.end(), cells);
1023  }
1024  }
1025  return cells;
1026 }
1027 
1028 std::vector<int> HGCalDDDConstants::numberCells(int lay, bool reco) const {
1029  const auto& index = getIndex(lay, reco);
1030  int i = index.first;
1031  std::vector<int> ncell;
1032  if (i >= 0) {
1033  if (waferHexagon6()) {
1034  for (unsigned int k = 0; k < hgpar_->waferTypeT_.size(); ++k) {
1036  unsigned int cell = (hgpar_->waferTypeT_[k] - 1 == HGCSiliconDetId::HGCalFine)
1037  ? (hgpar_->cellFineX_.size())
1038  : (hgpar_->cellCoarseX_.size());
1039  ncell.emplace_back(static_cast<int>(cell));
1040  }
1041  }
1042  } else if (tileTrapezoid()) {
1043  int nphi = hgpar_->scintCells(lay);
1044  for (int k = hgpar_->firstModule_[i]; k <= hgpar_->lastModule_[i]; ++k)
1045  ncell.emplace_back(nphi);
1046  } else {
1047  for (unsigned int k = 0; k < hgpar_->waferCopy_.size(); ++k) {
1048  if (waferInLayerTest(k, index.first, hgpar_->defineFull_)) {
1049  int cell = numberCellsHexagon(lay,
1052  true);
1053  ncell.emplace_back(cell);
1054  }
1055  }
1056  }
1057  }
1058  return ncell;
1059 }
1060 
1062  if (wafer >= 0 && wafer < static_cast<int>(hgpar_->waferTypeT_.size())) {
1063  if (hgpar_->waferTypeT_[wafer] - 1 == HGCSiliconDetId::HGCalFine)
1064  return static_cast<int>(hgpar_->cellFineX_.size());
1065  else
1066  return static_cast<int>(hgpar_->cellCoarseX_.size());
1067  } else {
1068  return 0;
1069  }
1070 }
1071 
1072 int HGCalDDDConstants::numberCellsHexagon(int lay, int waferU, int waferV, bool flag) const {
1074  int type =
1075  ((itr == hgpar_->typesInLayers_.end()) ? HGCSiliconDetId::HGCalCoarseThick : hgpar_->waferTypeL_[itr->second]);
1076  int N = (type == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
1077  if (flag)
1078  return (3 * N * N);
1079  else
1080  return N;
1081 }
1082 
1083 std::pair<double, double> HGCalDDDConstants::rangeR(double z, bool reco) const {
1084  double rmin(0), rmax(0), zz(0);
1085  if (hgpar_->detectorType_ > 0) {
1087  if (hgpar_->detectorType_ <= 2) {
1089  } else {
1090  rmin = HGCalGeomTools::radius(
1092  }
1093  if ((hgpar_->detectorType_ == 2) && (zz >= hgpar_->zLayerHex_[hgpar_->firstMixedLayer_ - 1])) {
1094  rmax = HGCalGeomTools::radius(
1096  } else {
1098  }
1099  }
1100  if (!reco) {
1103  }
1104 #ifdef EDM_ML_DEBUG
1105  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:rangeR: " << z << ":" << zz << " R " << rmin << ":" << rmax;
1106 #endif
1107  return std::make_pair(rmin, rmax);
1108 }
1109 
1110 std::pair<double, double> HGCalDDDConstants::rangeRLayer(int lay, bool reco) const {
1111  double rmin(0), rmax(0);
1112  const auto& index = getIndex(lay, reco);
1113  if (index.first >= 0 && index.first < static_cast<int>(hgpar_->rMinLayHex_.size())) {
1114  rmin = hgpar_->rMinLayHex_[index.first];
1115  rmax = hgpar_->rMaxLayHex_[index.first];
1116  }
1117  if (!reco) {
1120  }
1121 #ifdef EDM_ML_DEBUG
1122  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:rangeR: " << lay << ":" << index.first << " R " << rmin << ":"
1123  << rmax;
1124 #endif
1125  return std::make_pair(rmin, rmax);
1126 }
1127 
1128 std::pair<double, double> HGCalDDDConstants::rangeZ(bool reco) const {
1129  double zmin = (hgpar_->zLayerHex_[0] - hgpar_->waferThick_);
1130  double zmax = (hgpar_->zLayerHex_[hgpar_->zLayerHex_.size() - 1] + hgpar_->waferThick_);
1131 #ifdef EDM_ML_DEBUG
1132  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:rangeZ: " << zmin << ":" << zmax << ":" << hgpar_->waferThick_;
1133 #endif
1134  if (!reco) {
1137  }
1138  return std::make_pair(zmin, zmax);
1139 }
1140 
1141 std::pair<int, int> HGCalDDDConstants::rowColumnWafer(int wafer) const {
1142  int row(0), col(0);
1143  if (wafer < static_cast<int>(hgpar_->waferCopy_.size())) {
1144  int copy = hgpar_->waferCopy_[wafer];
1147  ;
1148  }
1149  return std::make_pair(row, col);
1150 }
1151 
1152 std::pair<int, int> HGCalDDDConstants::simToReco(int cell, int lay, int mod, bool half) const {
1153  if (!waferHexagon6()) {
1154  return std::make_pair(cell, lay);
1155  } else {
1156  const auto& index = getIndex(lay, false);
1157  int i = index.first;
1158  if (i < 0) {
1159  edm::LogWarning("HGCalGeom") << "Wrong Layer # " << lay << " not in the list ***** ERROR *****";
1160  return std::make_pair(-1, -1);
1161  }
1162  if (mod >= static_cast<int>(hgpar_->waferTypeL_.size())) {
1163  edm::LogWarning("HGCalGeom") << "Invalid Wafer # " << mod << "should be < " << (hgpar_->waferTypeL_).size()
1164  << " ***** ERROR *****";
1165  return std::make_pair(-1, -1);
1166  }
1167  int depth(-1);
1168  int kx = cell;
1169  int type = hgpar_->waferTypeL_[mod];
1170  if (type == 1) {
1171  depth = hgpar_->layerGroup_[i];
1172  } else if (type == 2) {
1173  depth = hgpar_->layerGroupM_[i];
1174  } else {
1175  depth = hgpar_->layerGroupO_[i];
1176  }
1177  return std::make_pair(kx, depth);
1178  }
1179 }
1180 
1182  int laymin(layer), laymax(layer), ringmin(ring), ringmax(ring), kount(0);
1183  if (layer == 0) {
1184  laymin = hgpar_->firstLayer_;
1185  laymax = lastLayer(true);
1186  }
1187 #ifdef EDM_ML_DEBUG
1188  edm::LogVerbatim("HGCalGeom") << "tileCount: layer " << layer << " ring " << ring << " layerMin/Max " << laymin << ":"
1189  << laymax;
1190 #endif
1191  for (int lay = laymin; lay <= laymax; ++lay) {
1192  if (ring < 0) {
1193  int ll = lay - hgpar_->firstLayer_;
1194  ringmin = hgpar_->tileRingRange_[ll].first;
1195  ringmax = hgpar_->tileRingRange_[ll].second;
1196  }
1197 #ifdef EDM_ML_DEBUG
1198  edm::LogVerbatim("HGCalGeom") << "tileCount: lay " << lay << ":" << (lay - hgpar_->firstLayer_) << " rings "
1199  << ringmin << ":" << ringmax;
1200 #endif
1201  for (int rin = ringmin; rin <= ringmax; ++rin) {
1202  int indx = HGCalTileIndex::tileIndex(lay, rin + 1, 0);
1203  auto itr = hgpar_->tileInfoMap_.find(indx);
1204 #ifdef EDM_ML_DEBUG
1205  edm::LogVerbatim("HGCalGeom") << "tileCount: rin " << rin << " indx " << indx << " itr "
1206  << (itr != hgpar_->tileInfoMap_.end());
1207 #endif
1208  if (itr != hgpar_->tileInfoMap_.end()) {
1209  for (int k = 0; k < 4; ++k) {
1210  std::bitset<24> b(itr->second.hex[k]);
1211  kount += b.count();
1212  }
1213  }
1214 #ifdef EDM_ML_DEBUG
1215  edm::LogVerbatim("HGCalGeom") << "tileCount: lay|rin " << lay << ":" << rin << " kount " << kount;
1216 #endif
1217  }
1218  }
1219  return (3 * kount);
1220 }
1221 
1222 bool HGCalDDDConstants::tileExist(int zside, int layer, int ring, int phi) const {
1223  int indx = HGCalTileIndex::tileIndex(layer, ring, 0);
1224  auto itr = hgpar_->tileInfoMap_.find(indx);
1225  bool ok = (itr == hgpar_->tileInfoMap_.end()) ? false : HGCalTileIndex::tileExist(itr->second.hex, zside, phi);
1226  return ok;
1227 }
1228 
1230  int indx = HGCalTileIndex::tileIndex(layer, ring, 0);
1231  auto itr = hgpar_->tileInfoMap_.find(indx);
1232  return ((itr == hgpar_->tileInfoMap_.end()) ? HGCalParameters::tileInfo() : itr->second);
1233 }
1234 
1235 std::pair<int, int> HGCalDDDConstants::tileRings(int layer) const {
1238  int ll = layer - hgpar_->firstLayer_;
1239  if (ll >= 0 && ll < static_cast<int>(hgpar_->tileRingRange_.size()))
1240  return hgpar_->tileRingRange_[ll];
1241  }
1242  return std::make_pair(0, 0);
1243 }
1244 
1245 std::pair<int, int> HGCalDDDConstants::tileType(int layer, int ring, int phi) const {
1246  int indx = HGCalTileIndex::tileIndex(layer, ring, phi);
1247  int type(-1), sipm(-1);
1248  auto itr = hgpar_->tileInfoMap_.find(indx);
1249  if (itr != hgpar_->tileInfoMap_.end()) {
1250  type = 1 + (itr->second).type;
1251  sipm = ((itr->second).sipm == HGCalTypes::SiPMLarge) ? 0 : 1;
1252  }
1253  return std::make_pair(type, sipm);
1254 }
1255 
1257  const int ncopies = hgpar_->waferCopy_.size();
1258  int wafer(ncopies);
1259  bool result(false);
1260  for (int k = 0; k < ncopies; ++k) {
1261  if (copy == hgpar_->waferCopy_[k]) {
1262  wafer = k;
1263  result = true;
1264  break;
1265  }
1266  }
1267  if (!result) {
1268  wafer = -1;
1269 #ifdef EDM_ML_DEBUG
1270  edm::LogVerbatim("HGCalGeom") << "Cannot find " << copy << " in a list of " << ncopies << " members";
1271  for (int k = 0; k < ncopies; ++k)
1272  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << hgpar_->waferCopy_[k];
1273 #endif
1274  }
1275 #ifdef EDM_ML_DEBUG
1276  edm::LogVerbatim("HGCalGeom") << "WaferFromCopy " << copy << ":" << wafer << ":" << result;
1277 #endif
1278  return wafer;
1279 }
1280 
1281 void HGCalDDDConstants::waferFromPosition(const double x, const double y, int& wafer, int& icell, int& celltyp) const {
1282  // Input x, y in Geant4 unit and transformed to CMSSW standard
1285  int size_ = static_cast<int>(hgpar_->waferCopy_.size());
1286  wafer = size_;
1287  for (int k = 0; k < size_; ++k) {
1288  double dx = std::abs(xx - hgpar_->waferPosX_[k]);
1289  double dy = std::abs(yy - hgpar_->waferPosY_[k]);
1290  if (dx <= rmax_ && dy <= hexside_) {
1291  if ((dy <= 0.5 * hexside_) || (dx * tan30deg_ <= (hexside_ - dy))) {
1292  wafer = k;
1293  celltyp = hgpar_->waferTypeT_[k];
1294  xx -= hgpar_->waferPosX_[k];
1295  yy -= hgpar_->waferPosY_[k];
1296  break;
1297  }
1298  }
1299  }
1300  if (wafer < size_) {
1301  if (celltyp - 1 == HGCSiliconDetId::HGCalFine)
1302  icell = cellHex(
1304  else
1305  icell = cellHex(xx,
1306  yy,
1309  hgpar_->cellCoarseY_);
1310  } else {
1311  wafer = -1;
1312 #ifdef EDM_ML_DEBUG
1313  edm::LogWarning("HGCalGeom") << "Cannot get wafer type corresponding to " << x << ":" << y << " " << xx << ":"
1314  << yy;
1315 #endif
1316  }
1317 #ifdef EDM_ML_DEBUG
1318  edm::LogVerbatim("HGCalGeom") << "Position " << x << ":" << y << " Wafer " << wafer << ":" << size_ << " XX " << xx
1319  << ":" << yy << " Cell " << icell << " Type " << celltyp;
1320 #endif
1321 }
1322 
1324  const double y,
1325  const int layer,
1326  int& waferU,
1327  int& waferV,
1328  int& cellU,
1329  int& cellV,
1330  int& celltype,
1331  double& wt,
1332  bool extend,
1333  bool debug) const {
1334  // Expect x, y as in SIM step
1335  waferU = waferV = 1 + hgpar_->waferUVMax_;
1336  cellU = cellV = celltype = 0;
1337  if ((hgpar_->xLayerHex_.empty()) || (hgpar_->yLayerHex_.empty()))
1338  return;
1339  int ll = layer - hgpar_->firstLayer_;
1340  int layertype = layerType(layer);
1341  bool rotx = ((!hgpar_->layerType_.empty()) && (layertype == HGCalTypes::WaferCenterR));
1342  double xx(0), yy(0);
1343  if (rotx) {
1344  std::pair<double, double> xy =
1346  xx = xy.first - hgpar_->xLayerHex_[ll];
1347  yy = xy.second - hgpar_->yLayerHex_[ll];
1348  } else {
1351  }
1352 #ifdef EDM_ML_DEBUG
1353  if (debug)
1354  edm::LogVerbatim("HGCalGeom") << "waferFromPosition:: Layer " << layer << ":" << ll << " Rot " << rotx << " X " << x
1355  << ":" << xx << " Y " << y << ":" << yy;
1356 #endif
1357  double rmax = extend ? rmaxT_ : rmax_;
1358  double hexside = extend ? hexsideT_ : hexside_;
1359  for (unsigned int k = 0; k < hgpar_->waferPosX_.size(); ++k) {
1360  double dx0(0), dy0(0);
1365  auto ktr = hgpar_->waferInfoMap_.find(indx);
1366  if (ktr != hgpar_->waferInfoMap_.end()) {
1367  auto cshift = hgcassette_.getShift(layer, 1, (ktr->second).cassette);
1368 #ifdef EDM_ML_DEBUG
1369  if (debug)
1370  edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << cshift.first << ":"
1371  << cshift.second;
1372 #endif
1373  dx0 = cshift.first;
1374  dy0 = cshift.second;
1375  }
1376  }
1377  double dx = std::abs(xx - dx0 - hgpar_->waferPosX_[k]);
1378  double dy = std::abs(yy - dy0 - hgpar_->waferPosY_[k]);
1379  if (dx <= rmax && dy <= hexside) {
1380  if ((dy <= 0.5 * hexside) || (dx * tan30deg_ <= (hexside - dy))) {
1381  if (waferHexagon8File()) {
1384 #ifdef EDM_ML_DEBUG
1385  if (debug)
1386  edm::LogVerbatim("HGCalGeom") << "Position (" << x << ", " << y << ") Wafer type:partial:orient:cassette "
1387  << celltype << ":" << HGCalWaferType::getPartial(index, hgpar_->waferInfoMap_)
1390 #endif
1391  } else {
1393  celltype = ((itr == hgpar_->typesInLayers_.end()) ? HGCSiliconDetId::HGCalCoarseThick
1394  : hgpar_->waferTypeL_[itr->second]);
1395  }
1396 #ifdef EDM_ML_DEBUG
1397  if (debug)
1398  edm::LogVerbatim("HGCalGeom") << "WaferFromPosition:: Input " << layer << ":" << ll << ":"
1399  << hgpar_->firstLayer_ << ":" << rotx << ":" << x << ":" << y << ":"
1400  << hgpar_->xLayerHex_[ll] << ":" << hgpar_->yLayerHex_[ll] << ":" << xx << ":"
1401  << yy << " compared with " << hgpar_->waferPosX_[k] << ":"
1402  << hgpar_->waferPosY_[k] << " difference " << dx << ":" << dy << ":"
1403  << dx * tan30deg_ << ":" << (hexside_ - dy) << " comparator " << rmax_ << ":"
1404  << rmaxT_ << ":" << hexside_ << ":" << hexsideT_ << " wafer " << waferU << ":"
1405  << waferV << ":" << celltype;
1406 #endif
1407  xx -= (dx0 + hgpar_->waferPosX_[k]);
1408  yy -= (dy0 + hgpar_->waferPosY_[k]);
1409  break;
1410  }
1411  }
1412  }
1413  if ((std::abs(waferU) <= hgpar_->waferUVMax_) && (celltype >= 0)) {
1417  auto ktr = hgpar_->waferInfoMap_.find(indx);
1418  if (ktr != hgpar_->waferInfoMap_.end()) {
1419  place = HGCalCell::cellPlacementIndex(1, HGCalTypes::layerFrontBack(layertype), (ktr->second).orient);
1420  part = (ktr->second).part;
1421 #ifdef EDM_ML_DEBUG
1422  if (debug)
1423  edm::LogVerbatim("HGCalGeom") << "waferFromPosition: frontback " << layertype << ":"
1424  << HGCalTypes::layerFrontBack(layertype) << " Orient " << (ktr->second).orient
1425  << " place " << place << " part " << part;
1426 #endif
1427  }
1428  }
1429  cellHex(xx, yy, celltype, place, part, cellU, cellV, extend, debug);
1430  wt = (((celltype < 2) && (hgpar_->useSimWt_ > 0)) ? (hgpar_->cellThickness_[celltype] / hgpar_->waferThick_) : 1.0);
1431  } else {
1432  cellU = cellV = 2 * hgpar_->nCellsFine_;
1433  wt = 1.0;
1434  celltype = -1;
1435  }
1436  if ((celltype < 0) && debug) {
1437  double x1(xx);
1438  double y1(yy);
1439  edm::LogVerbatim("HGCalGeom") << "waferfFromPosition: Bad type for X " << x << ":" << x1 << ":" << xx << " Y " << y
1440  << ":" << y1 << ":" << yy << " Wafer " << waferU << ":" << waferV << " Cell " << cellU
1441  << ":" << cellV;
1442  for (unsigned int k = 0; k < hgpar_->waferPosX_.size(); ++k) {
1443  double dx = std::abs(x1 - hgpar_->waferPosX_[k]);
1444  double dy = std::abs(y1 - hgpar_->waferPosY_[k]);
1445  edm::LogVerbatim("HGCalGeom") << "Wafer [" << k << "] Position (" << hgpar_->waferPosX_[k] << ", "
1446  << hgpar_->waferPosY_[k] << ") difference " << dx << ":" << dy << ":"
1447  << dx * tan30deg_ << ":" << hexside - dy << " Paramerers " << rmax << ":"
1448  << hexside;
1449  }
1450  }
1451  edm::LogVerbatim("HGCalGeomX") << "Input x:y:layer " << x << ":" << y << ":" << layer << " Wafer " << waferU << ":"
1452  << waferV << " Cell " << cellU << ":" << cellV << ":" << celltype << " wt " << wt;
1453 }
1454 
1455 bool HGCalDDDConstants::waferInLayer(int wafer, int lay, bool reco) const {
1456  const auto& indx = getIndex(lay, reco);
1457  if (indx.first < 0)
1458  return false;
1459  return waferInLayerTest(wafer, indx.first, hgpar_->defineFull_);
1460 }
1461 
1462 bool HGCalDDDConstants::waferFullInLayer(int wafer, int lay, bool reco) const {
1463  const auto& indx = getIndex(lay, reco);
1464  if (indx.first < 0)
1465  return false;
1466  return waferInLayerTest(wafer, indx.first, false);
1467 }
1468 
1470  int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
1471  auto itr = hgpar_->waferInfoMap_.find(indx);
1472  return ((itr == hgpar_->waferInfoMap_.end()) ? HGCalParameters::waferInfo() : itr->second);
1473 }
1474 
1475 std::pair<double, double> HGCalDDDConstants::waferParameters(bool reco) const {
1476  if (reco)
1477  return std::make_pair(rmax_, hexside_);
1478  else
1480 }
1481 
1482 std::pair<double, double> HGCalDDDConstants::waferPosition(int wafer, bool reco) const {
1483  double xx(0), yy(0);
1484  if (wafer >= 0 && wafer < static_cast<int>(hgpar_->waferPosX_.size())) {
1485  xx = hgpar_->waferPosX_[wafer];
1486  yy = hgpar_->waferPosY_[wafer];
1487  }
1488  if (!reco) {
1491  }
1492  return std::make_pair(xx, yy);
1493 }
1494 
1495 std::pair<double, double> HGCalDDDConstants::waferPosition(
1496  int lay, int waferU, int waferV, bool reco, bool debug) const {
1497  int ll = lay - hgpar_->firstLayer_;
1498  bool rotx = ((!hgpar_->layerType_.empty()) && (hgpar_->layerType_[ll] == HGCalTypes::WaferCenterR));
1499 #ifdef EDM_ML_DEBUG
1500  if (debug)
1501  edm::LogVerbatim("HGCalGeom") << "Layer " << lay << ":" << ll << " Rotation " << rotx << " U:V " << waferU << ":"
1502  << waferV;
1503 #endif
1504  auto xy = waferPositionNoRot(lay, waferU, waferV, reco, debug);
1505  std::pair<double, double> xy0 = (rotx) ? getXY(lay, xy.first, xy.second, false) : xy;
1506 #ifdef EDM_ML_DEBUG
1507  if (debug)
1508  edm::LogVerbatim("HGCalGeom") << "Without and with rotation " << xy.first << ":" << xy.second << ":" << xy0.first
1509  << ":" << xy0.second;
1510 #endif
1511  return xy0;
1512 }
1513 
1514 int HGCalDDDConstants::waferFileIndex(unsigned int kk) const {
1515  if (kk < hgpar_->waferInfoMap_.size()) {
1516  auto itr = hgpar_->waferInfoMap_.begin();
1517  std::advance(itr, kk);
1518  return itr->first;
1519  } else
1520  return 0;
1521 }
1522 
1523 std::tuple<int, int, int> HGCalDDDConstants::waferFileInfo(unsigned int kk) const {
1524  if (kk < hgpar_->waferInfoMap_.size()) {
1525  auto itr = hgpar_->waferInfoMap_.begin();
1526  std::advance(itr, kk);
1527  return std::make_tuple(itr->second.type, itr->second.part, itr->second.orient);
1528  } else
1529  return std::make_tuple(0, 0, 0);
1530 }
1531 
1532 std::tuple<int, int, int> HGCalDDDConstants::waferFileInfoFromIndex(int kk) const {
1533  auto itr = hgpar_->waferInfoMap_.find(kk);
1534  if (itr != hgpar_->waferInfoMap_.end()) {
1535  return std::make_tuple(itr->second.type, itr->second.part, itr->second.orient);
1536  } else
1537  return std::make_tuple(0, 0, 0);
1538 }
1539 
1541  HepGeom::Point3D<float>& loc, const DetId& id, bool useWafer, bool reco, bool debug) const {
1542  HGCSiliconDetId detid(id);
1543  double x(0), y(0);
1544  if (useWafer) {
1545  auto xyw = waferPositionNoRot(detid.layer(), detid.waferU(), detid.waferV(), reco, debug);
1546  x = xyw.first;
1547  y = xyw.second;
1548  }
1549  auto xy = getXY(detid.layer(), (x + loc.x()), (y + loc.y()), false);
1550  double zz = (detid.zside() < 0) ? -(loc.z() + waferZ(detid.layer(), reco)) : (loc.z() + waferZ(detid.layer(), reco));
1551  double xx = (detid.zside() < 0) ? -xy.first : xy.first;
1552  return GlobalPoint(xx, xy.second, zz);
1553 }
1554 
1556  int wafer(0);
1557  if (!tileTrapezoid()) {
1558  for (unsigned int i = 0; i < layers(true); ++i) {
1559  int lay = hgpar_->depth_[i];
1560  wafer += modules(lay, true);
1561  }
1562  } else {
1563  wafer = static_cast<int>(hgpar_->moduleLayR_.size());
1564  }
1565  return wafer;
1566 }
1567 
1568 int HGCalDDDConstants::wafers(int layer, int type) const {
1569  int wafer(0);
1570  if (!tileTrapezoid()) {
1571  auto itr = waferLayer_.find(layer);
1572  if (itr != waferLayer_.end()) {
1573  unsigned ity = (type > 0 && type <= 2) ? type : 0;
1574  wafer = (itr->second)[ity];
1575  }
1576  } else {
1577  const auto& index = getIndex(layer, true);
1578  wafer = 1 + hgpar_->lastModule_[index.first] - hgpar_->firstModule_[index.first];
1579  }
1580  return wafer;
1581 }
1582 
1583 int HGCalDDDConstants::waferType(DetId const& id, bool fromFile) const {
1584  int type(1);
1585  if (waferHexagon8()) {
1586  if (fromFile && (waferFileSize() > 0)) {
1587  int layer(0), waferU(0), waferV(0);
1588  if (id.det() != DetId::Forward) {
1589  HGCSiliconDetId hid(id);
1590  layer = hid.layer();
1591  waferU = hid.waferU();
1592  waferV = hid.waferV();
1593  } else {
1594  HFNoseDetId hid(id);
1595  layer = hid.layer();
1596  waferU = hid.waferU();
1597  waferV = hid.waferV();
1598  }
1600  if (itr != hgpar_->waferInfoMap_.end())
1601  type = (itr->second).type;
1602  } else {
1603  type = ((id.det() != DetId::Forward) ? HGCSiliconDetId(id).type() : HFNoseDetId(id).type());
1604  }
1605  } else if (waferHexagon6()) {
1606  type = waferTypeL(HGCalDetId(id).wafer()) - 1;
1607  }
1608  return type;
1609 }
1610 
1611 int HGCalDDDConstants::waferType(int layer, int waferU, int waferV, bool fromFile) const {
1613  if (waferHexagon8()) {
1614  if (fromFile && (waferFileSize() > 0)) {
1616  if (itr != hgpar_->waferInfoMap_.end())
1617  type = (itr->second).type;
1618  } else {
1620  if (itr != hgpar_->typesInLayers_.end())
1621  type = hgpar_->waferTypeL_[itr->second];
1622  }
1623  } else if (waferHexagon6()) {
1624  if ((waferU >= 0) && (waferU < static_cast<int>(hgpar_->waferTypeL_.size())))
1625  type = (hgpar_->waferTypeL_[waferU] - 1);
1626  }
1627  return type;
1628 }
1629 
1630 std::tuple<int, int, int> HGCalDDDConstants::waferType(HGCSiliconDetId const& id, bool fromFile) const {
1631  const auto& index = HGCalWaferIndex::waferIndex(id.layer(), id.waferU(), id.waferV());
1632  int type(-1), part(-1), orient(-1);
1633  if (fromFile && (waferFileSize() > 0)) {
1634  auto itr = hgpar_->waferInfoMap_.find(index);
1635  if (itr != hgpar_->waferInfoMap_.end()) {
1636  type = (itr->second).type;
1637  part = (itr->second).part;
1638  orient = (itr->second).orient;
1639  }
1640  } else {
1641  auto ktr = hgpar_->typesInLayers_.find(index);
1642  if (ktr != hgpar_->typesInLayers_.end())
1643  type = hgpar_->waferTypeL_[ktr->second];
1644  auto itr = hgpar_->waferTypes_.find(index);
1645  if (itr != hgpar_->waferTypes_.end()) {
1646  if ((itr->second).second < HGCalTypes::k_OffsetRotation) {
1647  orient = (itr->second).second;
1648  if ((itr->second).first == HGCalGeomTools::k_allCorners) {
1650  } else if ((itr->second).first == HGCalGeomTools::k_fiveCorners) {
1652  } else if ((itr->second).first == HGCalGeomTools::k_fourCorners) {
1654  } else if ((itr->second).first == HGCalGeomTools::k_threeCorners) {
1656  }
1657  } else {
1658  part = (itr->second).first;
1659  orient = ((itr->second).second - HGCalTypes::k_OffsetRotation);
1660  }
1661  } else {
1663  orient = 0;
1664  }
1665  }
1666  return std::make_tuple(type, part, orient);
1667 }
1668 
1670  int layer, int waferU, int waferV, bool fromFile, bool debug) const {
1671  int type(HGCalTypes::WaferOut), rotn(0);
1673  bool withinList(true);
1674  if (fromFile && (waferFileSize() > 0)) {
1675  auto itr = hgpar_->waferInfoMap_.find(wl);
1676  withinList = (itr != hgpar_->waferInfoMap_.end());
1677  if (withinList) {
1678  type = (itr->second).part;
1679  rotn = (itr->second).orient;
1680  }
1681  } else {
1682  auto itr = hgpar_->waferTypes_.find(wl);
1683  if (waferHexagon8()) {
1684  withinList = (itr != hgpar_->waferTypes_.end());
1685  if (withinList) {
1686  if ((itr->second).second < HGCalTypes::k_OffsetRotation) {
1687  rotn = (itr->second).second;
1688  if ((itr->second).first == HGCalGeomTools::k_allCorners) {
1690  } else if ((itr->second).first == HGCalGeomTools::k_fiveCorners) {
1692  } else if ((itr->second).first == HGCalGeomTools::k_fourCorners) {
1694  } else if ((itr->second).first == HGCalGeomTools::k_threeCorners) {
1696  }
1697  } else {
1698  type = (itr->second).first;
1699  rotn = ((itr->second).second - HGCalTypes::k_OffsetRotation);
1700  }
1701  } else {
1703  rotn = HGCalTypes::WaferCorner0;
1704  }
1705  }
1706  }
1707 #ifdef EDM_ML_DEBUG
1708  if (debug)
1709  edm::LogVerbatim("HGCalGeom") << "waferTypeRotation: Layer " << layer << " Wafer " << waferU << ":" << waferV
1710  << " Index " << std::hex << wl << std::dec << ":" << withinList << " Type " << type
1711  << " Rotation " << rotn;
1712 #endif
1713  return std::make_pair(type, rotn);
1714 }
1715 
1717  bool type(false);
1718  if (waferHexagon8()) {
1720  type = (hgpar_->waferTypes_.find(wl) != hgpar_->waferTypes_.end());
1721  } else if (waferHexagon6()) {
1722  int wl = HGCalWaferIndex::waferIndex(layer, waferU, 0, true);
1723  type = (hgpar_->waferTypes_.find(wl) != hgpar_->waferTypes_.end());
1724  }
1725  return type;
1726 }
1727 
1728 double HGCalDDDConstants::waferZ(int lay, bool reco) const {
1729  const auto& index = getIndex(lay, reco);
1730  if (index.first < 0)
1731  return 0;
1732  else
1734 }
1735 
1737  double xx, double yy, const double& cellR, const std::vector<double>& posX, const std::vector<double>& posY) const {
1738  int num(0);
1739  const double tol(0.00001);
1740  double cellY = 2.0 * cellR * tan30deg_;
1741  for (unsigned int k = 0; k < posX.size(); ++k) {
1742  double dx = std::abs(xx - posX[k]);
1743  double dy = std::abs(yy - posY[k]);
1744  if (dx <= (cellR + tol) && dy <= (cellY + tol)) {
1745  double xmax = (dy <= 0.5 * cellY) ? cellR : (cellR - (dy - 0.5 * cellY) / tan30deg_);
1746  if (dx <= (xmax + tol)) {
1747  num = k;
1748  break;
1749  }
1750  }
1751  }
1752  return num;
1753 }
1754 
1756  double xloc, double yloc, int cellType, int place, int part, int& cellU, int& cellV, bool extend, bool debug) const {
1758  auto uv = (part == HGCalTypes::WaferFull)
1759  ? hgcellUV_->cellUVFromXY3(xloc, yloc, place, cellType, true, debug)
1760  : hgcellUV_->cellUVFromXY1(xloc, yloc, place, cellType, part, true, debug);
1761  cellU = uv.first;
1762  cellV = uv.second;
1763  } else if (waferHexagon8File()) {
1764  auto uv = hgcellUV_->cellUVFromXY3(xloc, yloc, place, cellType, extend, debug);
1765  cellU = uv.first;
1766  cellV = uv.second;
1767  } else {
1768  int ncell = (cellType == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
1769  double delY = 2 * rmax_ / (3 * ncell);
1770  double delX = 0.5 * delY * sqrt3_;
1771  double delYT = (extend) ? (2 * rmaxT_ / (3 * ncell)) : delY;
1772  double delXT = 0.5 * delYT * sqrt3_;
1773  double v0 = ((xloc / delY - 1.0) / 1.5);
1774  int cv0 = (v0 > 0) ? (ncell + static_cast<int>(v0 + 0.5)) : (ncell - static_cast<int>(-v0 + 0.5));
1775  double u0 = (0.5 * yloc / delX + 0.5 * cv0);
1776  int cu0 = (u0 > 0) ? (ncell / 2 + static_cast<int>(u0 + 0.5)) : (ncell / 2 - static_cast<int>(-u0 + 0.5));
1777  cu0 = std::max(0, std::min(cu0, 2 * ncell - 1));
1778  cv0 = std::max(0, std::min(cv0, 2 * ncell - 1));
1779  if (cv0 - cu0 >= ncell)
1780  cv0 = cu0 + ncell - 1;
1781  if (debug)
1782  edm::LogVerbatim("HGCalGeom") << "cellHex: input " << xloc << ":" << yloc << ":" << cellType << " parameter "
1783  << delX << ":" << delY << " u0 " << u0 << ":" << cu0 << " v0 " << v0 << ":" << cv0;
1784  bool found(false);
1785  static constexpr int shift[3] = {0, 1, -1};
1786  for (int i1 = 0; i1 < 3; ++i1) {
1787  cellU = cu0 + shift[i1];
1788  for (int i2 = 0; i2 < 3; ++i2) {
1789  cellV = cv0 + shift[i2];
1790  if (((cellV - cellU) < ncell) && ((cellU - cellV) <= ncell) && (cellU >= 0) && (cellV >= 0) &&
1791  (cellU < 2 * ncell) && (cellV < 2 * ncell)) {
1792  double xc = (1.5 * (cellV - ncell) + 1.0) * delY;
1793  double yc = (2 * cellU - cellV - ncell) * delX;
1794  if ((std::abs(yloc - yc) <= delXT) && (std::abs(xloc - xc) <= delYT) &&
1795  ((std::abs(xloc - xc) <= 0.5 * delYT) ||
1796  (std::abs(yloc - yc) <= sqrt3_ * (delYT - std::abs(xloc - xc))))) {
1797  if (debug)
1798  edm::LogVerbatim("HGCalGeom")
1799  << "cellHex: local " << xc << ":" << yc << " difference " << std::abs(xloc - xc) << ":"
1800  << std::abs(yloc - yc) << ":" << sqrt3_ * (delY - std::abs(yloc - yc)) << " comparator " << delX
1801  << ":" << delY << " (u,v) = (" << cellU << "," << cellV << ")";
1802  found = true;
1803  break;
1804  }
1805  }
1806  }
1807  if (found)
1808  break;
1809  }
1810  if (!found) {
1811  cellU = cu0;
1812  cellV = cv0;
1813  }
1814  }
1815 }
1816 
1817 std::pair<int, float> HGCalDDDConstants::getIndex(int lay, bool reco) const {
1818  int indx = layerIndex(lay, reco);
1819  if (indx < 0)
1820  return std::make_pair(-1, 0);
1821  float cell(0);
1822  if (waferHexagon6()) {
1823  cell = (reco ? hgpar_->moduleCellR_[0] : hgpar_->moduleCellS_[0]);
1824  } else {
1825  if (waferHexagon8()) {
1826  cell = (reco ? hgpar_->moduleCellR_[0] : hgpar_->moduleCellS_[0]);
1827  } else {
1828  cell = hgpar_->scintCellSize(lay);
1829  }
1830  }
1831  return std::make_pair(indx, cell);
1832 }
1833 
1835  int ll(-1);
1836  if (waferHexagon6() && reco) {
1837  ll = static_cast<int>(std::find(hgpar_->depthLayerF_.begin(), hgpar_->depthLayerF_.end(), index) -
1838  hgpar_->depthLayerF_.begin());
1839  if (ll == static_cast<int>(hgpar_->depthLayerF_.size()))
1840  ll = -1;
1841  } else {
1842  ll = static_cast<int>(std::find(hgpar_->layerIndex_.begin(), hgpar_->layerIndex_.end(), index) -
1843  hgpar_->layerIndex_.begin());
1844  if (ll == static_cast<int>(hgpar_->layerIndex_.size()))
1845  ll = -1;
1846  }
1847 #ifdef EDM_ML_DEBUG
1848  edm::LogVerbatim("HGCalGeom") << "LayerFromIndex for " << index << ":" << reco << ":" << waferHexagon6() << " is"
1849  << ll << ":" << (ll + hgpar_->firstLayer_);
1850 #endif
1851  return ((ll < 0) ? ll : (ll + hgpar_->firstLayer_));
1852 }
1853 
1854 bool HGCalDDDConstants::isValidCell(int lay, int wafer, int cell) const {
1855  // Calculate the position of the cell
1856  // Works for options HGCalHexagon/HGCalHexagonFull
1857  double x = hgpar_->waferPosX_[wafer];
1858  double y = hgpar_->waferPosY_[wafer];
1859  if (hgpar_->waferTypeT_[wafer] - 1 == HGCSiliconDetId::HGCalFine) {
1860  x += hgpar_->cellFineX_[cell];
1861  y += hgpar_->cellFineY_[cell];
1862  } else {
1863  x += hgpar_->cellCoarseX_[cell];
1864  y += hgpar_->cellCoarseY_[cell];
1865  }
1866  double rr = sqrt(x * x + y * y);
1867  bool result = ((rr >= hgpar_->rMinLayHex_[lay - 1]) && (rr <= hgpar_->rMaxLayHex_[lay - 1]) &&
1868  (wafer < static_cast<int>(hgpar_->waferPosX_.size())));
1869 #ifdef EDM_ML_DEBUG
1870  if (!result)
1871  edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << wafer << ":" << cell << " Position " << x << ":" << y
1872  << ":" << rr << " Compare Limits " << hgpar_->rMinLayHex_[lay - 1] << ":"
1873  << hgpar_->rMaxLayHex_[lay - 1] << " Flag " << result;
1874 #endif
1875  return result;
1876 }
1877 
1878 bool HGCalDDDConstants::isValidCell8(int lay, int waferU, int waferV, int cellU, int cellV, int type) const {
1879  bool result(false);
1880  auto partn = waferTypeRotation(lay, waferU, waferV, false, false);
1881 #ifdef EDM_ML_DEBUG
1882  edm::LogVerbatim("HGCalGeom") << "waferHexagon8 " << waferHexagon8File() << ":" << mode_ << ":"
1883  << HGCalGeometryMode::Hexagon8Cassette << " part " << partn.first << ":"
1884  << partn.second;
1885 #endif
1887  result = HGCalWaferMask::goodCell(cellU, cellV, partn.first);
1888 #ifdef EDM_ML_DEBUG
1889  edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << waferU << ":" << waferV << ":" << cellU << ":" << cellV
1890  << " Result " << result << " from goodCell";
1891 #endif
1892  } else {
1893  float x(0), y(0);
1894  int kndx = cellV * 100 + cellU;
1895  if (type == 0) {
1896  auto ktr = hgpar_->cellFineIndex_.find(kndx);
1897  if (ktr != hgpar_->cellFineIndex_.end()) {
1898  x = hgpar_->cellFineX_[ktr->second];
1899  y = hgpar_->cellFineY_[ktr->second];
1900  }
1901 #ifdef EDM_ML_DEBUG
1902  edm::LogVerbatim("HGCalGeom") << "Fine " << cellU << ":" << cellV << ":" << kndx << ":" << x << ":" << y << ":"
1903  << (ktr != hgpar_->cellFineIndex_.end());
1904 #endif
1905  } else {
1906  auto ktr = hgpar_->cellCoarseIndex_.find(kndx);
1907  if (ktr != hgpar_->cellCoarseIndex_.end()) {
1908  x = hgpar_->cellCoarseX_[ktr->second];
1909  y = hgpar_->cellCoarseY_[ktr->second];
1910  }
1911 #ifdef EDM_ML_DEBUG
1912  edm::LogVerbatim("HGCalGeom") << "Coarse " << cellU << ":" << cellV << ":" << kndx << ":" << x << ":" << y << ":"
1913  << (ktr != hgpar_->cellCoarseIndex_.end());
1914 #endif
1915  }
1916  const auto& xy = waferPositionNoRot(lay, waferU, waferV, true, false);
1917  x += xy.first;
1918  y += xy.second;
1919 #ifdef EDM_ML_DEBUG
1920  edm::LogVerbatim("HGCalGeom") << "With wafer (" << waferU << "," << waferV << ") " << x << ":" << y;
1921 #endif
1922  double rr = sqrt(x * x + y * y);
1923  int ll = lay - hgpar_->firstLayer_;
1924  double tol = waferHexagon8File() ? 0.5 : 0.0;
1925  result = (((rr + tol) >= hgpar_->rMinLayHex_[ll]) && (rr <= hgpar_->rMaxLayHex_[ll]));
1926 #ifdef EDM_ML_DEBUG
1927  edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << ll << ":" << waferU << ":" << waferV << ":" << cellU
1928  << ":" << cellV << " Position " << x << ":" << y << ":" << rr << " Compare Limits "
1929  << hgpar_->rMinLayHex_[ll] << ":" << hgpar_->rMaxLayHex_[ll] << " Flag " << result
1930  << " from Radius Limits";
1931 #endif
1932  if (result && waferHexagon8File()) {
1933  int N = (type == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
1934  result = HGCalWaferMask::goodCell(cellU, cellV, N, partn.first, partn.second);
1935 #ifdef EDM_ML_DEBUG
1936  edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << waferU << ":" << waferV << ":" << cellU << ":" << cellV
1937  << " N " << N << " part " << partn.first << ":" << partn.second << " Result "
1938  << result << " from goodCell";
1939 #endif
1940  }
1941  }
1942  return result;
1943 }
1944 
1945 int32_t HGCalDDDConstants::waferIndex(int wafer, int index) const {
1946  int layer = layerFromIndex(index, true);
1950 #ifdef EDM_ML_DEBUG
1951  edm::LogVerbatim("HGCalGeom") << "WaferIndex for " << wafer << ":" << index << " (" << layer << ":" << waferU << ":"
1952  << waferV << ") " << indx;
1953 #endif
1954  return indx;
1955 }
1956 
1957 bool HGCalDDDConstants::waferInLayerTest(int wafer, int lay, bool full) const {
1958  bool in = (waferHexagon6()) ? true : false;
1959  if (!in) {
1960  double xpos = hgpar_->waferPosX_[wafer] + hgpar_->xLayerHex_[lay];
1961  double ypos = hgpar_->waferPosY_[wafer] + hgpar_->yLayerHex_[lay];
1962  std::pair<int, int> corner = HGCalGeomTools::waferCorner(
1963  xpos, ypos, rmax_, hexside_, hgpar_->rMinLayHex_[lay], hgpar_->rMaxLayHex_[lay], in);
1964  in = (full ? (corner.first > 0) : (corner.first == static_cast<int>(HGCalParameters::k_CornerSize)));
1965  if (in && fullAndPart_) {
1966  int indx = waferIndex(wafer, lay);
1967  in = (hgpar_->waferInfoMap_.find(indx) != hgpar_->waferInfoMap_.end());
1968 #ifdef EDM_ML_DEBUG
1969  if (!in)
1970  edm::LogVerbatim("HGCalGeom") << "WaferInLayerTest: Layer " << lay << " wafer " << wafer << " index " << indx
1971  << "( " << HGCalWaferIndex::waferLayer(indx) << ", "
1972  << HGCalWaferIndex::waferU(indx) << ", " << HGCalWaferIndex::waferV(indx)
1973  << ") in " << in;
1974 #endif
1975  }
1976 #ifdef EDM_ML_DEBUG
1977  edm::LogVerbatim("HGCalGeom") << "WaferInLayerTest: Layer " << lay << " wafer " << wafer << " R-limits "
1978  << hgpar_->rMinLayHex_[lay] << ":" << hgpar_->rMaxLayHex_[lay] << " Corners "
1979  << corner.first << ":" << corner.second << " In " << in;
1980 #endif
1981  }
1982  return in;
1983 }
1984 
1985 std::pair<double, double> HGCalDDDConstants::waferPositionNoRot(
1986  int lay, int waferU, int waferV, bool reco, bool debug) const {
1987  int ll = lay - hgpar_->firstLayer_;
1988  double x = hgpar_->xLayerHex_[ll];
1989  double y = hgpar_->yLayerHex_[ll];
1990 #ifdef EDM_ML_DEBUG
1991  if (debug)
1992  edm::LogVerbatim("HGCalGeom") << "Layer " << lay << ":" << ll << " Shift " << hgpar_->xLayerHex_[ll] << ":"
1993  << hgpar_->yLayerHex_[ll] << " U:V " << waferU << ":" << waferV;
1994 #endif
1995  if (!reco) {
1998  }
1999  const auto& xy = waferPosition(waferU, waferV, reco);
2000  x += xy.first;
2001  y += xy.second;
2002 #ifdef EDM_ML_DEBUG
2003  if (debug)
2004  edm::LogVerbatim("HGCalGeom") << "With wafer " << x << ":" << y << ":" << xy.first << ":" << xy.second;
2005 #endif
2006  return std::make_pair(x, y);
2007 }
2008 
2009 std::pair<double, double> HGCalDDDConstants::waferPosition(int waferU, int waferV, bool reco) const {
2010  double xx(0), yy(0);
2011  int indx = HGCalWaferIndex::waferIndex(0, waferU, waferV);
2012  auto itr = hgpar_->wafersInLayers_.find(indx);
2013  if (itr != hgpar_->wafersInLayers_.end()) {
2014  xx = hgpar_->waferPosX_[itr->second];
2015  yy = hgpar_->waferPosY_[itr->second];
2016  }
2017  if (!reco) {
2020  }
2021  return std::make_pair(xx, yy);
2022 }
2023 
2025 
std::vector< int > iradMaxBH_
bool maskCell(const DetId &id, int corners) const
std::pair< float, float > locateCellTrap(int lay, int ieta, int iphi, bool reco, bool debug=false) const
size
Write out results.
std::pair< double, double > rangeRLayer(int lay, bool reco) const
double waferZ(int layer, bool reco) const
std::vector< double > waferPosY_
Log< level::Info, true > LogVerbatim
std::vector< int > layer_
static constexpr int scintillatorCassette
const int nphi
static int32_t cellPlacementIndex(int32_t iz, int32_t frontBack, int32_t orient)
Definition: HGCalCell.cc:230
void waferFromPosition(const double x, const double y, int &wafer, int &icell, int &celltyp) const
std::pair< double, double > rangeZ(bool reco) const
std::vector< int > depthLayerF_
std::vector< int > depth_
std::vector< double > zFrontMin_
std::vector< double > moduleCellR_
std::pair< int, int > tileRings(int layer) const
unsigned int layersInit(bool reco) const
hgtrap getModule(unsigned int k, bool reco) const
static constexpr int32_t cellPlacementOld
Definition: HGCalCell.h:25
bool isValidCell(int layindex, int wafer, int cell) const
static int getType(int index, const HGCalParameters::waferInfo_map &wafers)
wafer_map cellFineIndex_
layer_map copiesInLayers_
static void radius(double zf, double zb, std::vector< double > const &zFront1, std::vector< double > const &rFront1, std::vector< double > const &slope1, std::vector< double > const &zFront2, std::vector< double > const &rFront2, std::vector< double > const &slope2, int flag, std::vector< double > &zz, std::vector< double > &rin, std::vector< double > &rout)
static constexpr int k_OffsetRotation
Definition: HGCalTypes.h:91
std::tuple< int, int, int > waferFileInfoFromIndex(int kk) const
std::vector< std::pair< double, double > > layerRotV_
int getPhiBins(int lay) const
HGCalCassette hgcassette_
int layer() const
get the layer #
Definition: HFNoseDetId.h:57
std::pair< double, double > cellEtaPhiTrap(int type, int irad) const
std::vector< bool > cellCoarseHalf_
int scintType(const int layer) const
std::vector< bool > cellFineHalf_
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
static std::pair< int32_t, int32_t > cellType(int32_t u, int32_t v, int32_t ncell, int32_t placementIndex)
Definition: HGCalCell.cc:242
std::pair< double, double > waferParameters(bool reco) const
bool waferInLayerTest(int wafer, int lay, bool full) const
static int32_t getUnpackedU(int id)
Definition: HGCalTypes.cc:16
std::vector< int > moduleLayR_
static constexpr int k_fourCorners
bool waferFullInLayer(int wafer, int lay, bool reco) const
double distFromEdgeTrap(double x, double y, double z) const
std::unique_ptr< HGCalCellUV > hgcellUV_
Simrecovecs max_modules_layer_
HGCalParameters::hgtrap getModule(unsigned int k, bool hexType, bool reco) const
int32_t waferU(const int32_t index)
HGCalParameters::waferInfo waferInfo(int lay, int waferU, int waferV) const
int32_t waferLayer(const int32_t index)
bool trapezoidFile() const
int waferU() const
Definition: HFNoseDetId.h:76
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
bool isValidHex(int lay, int mod, int cell, bool reco) const
static bool goodCell(int u, int v, int N, int type, int rotn)
bool isValidHex8(int lay, int waferU, int waferV, bool fullAndPart=false) const
static constexpr int32_t WaferOut
Definition: HGCalTypes.h:56
std::pair< int, int > waferTypeRotation(int layer, int waferU, int waferV, bool fromFile=false, bool debug=false) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
static constexpr int32_t WaferThree
Definition: HGCalTypes.h:42
std::pair< double, double > getShift(int layer, int zside, int cassette) const
std::vector< double > cellFineY_
std::pair< int, int > getREtaRange(int lay) const
int lastLayer(bool reco) const
static int getPartial(int index, const HGCalParameters::waferInfo_map &wafers)
static int32_t getUnpackedV(int id)
Definition: HGCalTypes.cc:22
std::pair< double, double > getXY(int layer, double x, double y, bool forwd) const
bool waferHexagon8() const
int modulesInit(int lay, bool reco) const
std::unordered_map< int32_t, bool > waferIn_
int zside(DetId const &)
int layerFromIndex(int index, bool reco) const
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:19
int32_t cellType(int type, int waferU, int waferV, int iz, int fwdBack, int orient) const
std::vector< int > layerGroupM_
bool waferHexagon6() const
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
float float float z
constexpr uint32_t mask
Definition: gpuClustering.h:24
hgtrform getTrForm(unsigned int k) const
static constexpr uint32_t k_CornerSize
constexpr std::array< uint8_t, layerIndexSize > layer
static int getOrient(int index, const HGCalParameters::waferInfo_map &wafers)
wafer_map wafersInLayers_
bool waferInLayer(int wafer, int lay, bool reco) const
U second(std::pair< T, U > const &p)
double scintCellSize(const int layer) const
HGCalParameters::tileInfo tileInfo(int zside, int layer, int ring) const
std::vector< double > cellCoarseX_
static constexpr int scintillatorFile
std::map< int, HGCWaferParam > waferLayer_
int32_t tileIndex(int32_t layer, int32_t ring, int32_t phi)
std::vector< std::pair< int, int > > tileRingRange_
int layer() const
get the layer #
static constexpr int32_t WaferFull
Definition: HGCalTypes.h:35
static std::pair< int32_t, int32_t > waferCorner(double xpos, double ypos, double r, double R, double rMin, double rMax, bool oldBug=false)
std::vector< int > firstModule_
unsigned int waferFileSize() const
std::unique_ptr< HGCalCell > hgcell_
int getTypeHex(int layer, int waferU, int waferV) const
static constexpr int32_t WaferHalf
Definition: HGCalTypes.h:39
bool isHalfCell(int waferType, int cell) const
int maxCells(bool reco) const
std::vector< double > cellSize_
std::vector< int > waferUVMaxLayer_
int waferFileIndex(unsigned int kk) const
std::vector< int > layerIndex_
std::vector< double > yLayerHex_
T sqrt(T t)
Definition: SSEVec.h:19
HGCalDDDConstants(const HGCalParameters *hp, const std::string &name)
int layerIndex(int lay, bool reco) const
std::pair< float, float > localToGlobal8(int lay, int waferU, int waferV, double localX, double localY, bool reco, bool debug) const
std::vector< double > rMaxFront_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Definition: GenABIO.cc:168
int waferType(DetId const &id, bool fromFile=false) const
static constexpr int32_t WaferOrient0
Definition: HGCalTypes.h:61
int getUVMax(int type) const
bool isValidCell8(int lay, int waferU, int waferV, int cellU, int cellV, int type) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
std::pair< int, float > getIndex(int lay, bool reco) const
static int getCassette(int index, const HGCalParameters::waferInfo_map &wafers)
bool isValidTrap(int zside, int lay, int ieta, int iphi) const
int waferU() const
bool waferVirtual(int layer, int waferU, int waferV) const
int tileCount(int layer, int ring) const
std::pair< int, int > assignCell(float x, float y, int lay, int subSec, bool reco) const
std::vector< double > slopeTop_
std::vector< HGCalParameters::hgtrap > getModules() const
double mouseBite(bool reco) const
unsigned int layers(bool reco) const
static constexpr int32_t WaferCorner0
Definition: HGCalTypes.h:13
bool tileTrapezoid() const
std::pair< int, int > tileType(int layer, int ring, int phi) const
std::vector< double > rMinLayHex_
int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV, bool old=false)
int getTypeTrap(int layer) const
int32_t tileCassette(int32_t, int32_t, int32_t, int32_t)
int type() const
get the type
Definition: HFNoseDetId.h:51
double cellSizeHex(int type) const
std::vector< double > zLayerHex_
std::vector< int > layerType_
#define M_PI
waferT_map waferTypes_
std::pair< double, double > rangeR(double z, bool reco) const
std::pair< double, double > waferPosition(int wafer, bool reco) const
std::vector< double > rMaxLayHex_
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ cells
std::vector< double > slopeMin_
static constexpr int32_t WaferCenterR
Definition: HGCalTypes.h:27
Definition: DetId.h:17
std::vector< int > lastModule_
std::array< int, 4 > waferMax_
static constexpr double k_ScaleToDDD
int numberCellsHexagon(int wafer) const
std::vector< double > radiusMixBoundary_
std::array< int, 3 > assignCellTrap(float x, float y, float z, int lay, bool reco) const
#define debug
Definition: HDRShower.cc:19
std::tuple< int, int, int > waferFileInfo(unsigned int kk) const
bool tileExist(int zside, int layer, int ring, int phi) const
bool cellInLayer(int waferU, int waferV, int cellU, int cellV, int lay, bool reco) const
#define N
Definition: blowfish.cc:9
std::vector< double > cellThickness_
int waferV() const
static constexpr int k_fiveCorners
GlobalPoint waferLocal2Global(HepGeom::Point3D< float > &loc, const DetId &id, bool useWafer, bool reco, bool debug) const
std::vector< int > layerGroup_
constexpr uint16_t localX(uint16_t px)
int numberCells(bool reco) const
part
Definition: HCALResponse.h:20
std::vector< double > moduleCellS_
int zside() const
get the z-side of the cell (1/-1)
std::pair< float, float > locateCellHex(int cell, int wafer, bool reco) const
double cellThickness(int layer, int waferU, int waferV) const
constexpr uint16_t localY(uint16_t py, uint16_t n)
double b
Definition: hdecay.h:118
wafer_map cellCoarseIndex_
std::pair< int, int > rowColumnWafer(const int wafer) const
int waferV() const
Definition: HFNoseDetId.h:79
unsigned int getTrFormN() const
HGCalParameters::hgtrform getTrForm(unsigned int k) const
std::vector< double > rMinFront_
std::pair< float, float > locateCell(int cell, int lay, int type, bool reco) const
std::vector< int > iradMinBH_
bool waferHexagon8File() const
std::vector< double > cellFineX_
int maxRows(int lay, bool reco) const
wafer_map typesInLayers_
const HGCalGeometryMode::GeometryMode mode_
int32_t waferIndex(int wafer, int index) const
std::array< int, 5 > assignCellHex(float x, float y, int lay, bool reco, bool extend=false, bool debug=false) const
static constexpr double k_ScaleFromDDD
std::vector< HGCalParameters::hgtrform > getTrForms() const
std::vector< int > layerGroupO_
fixed size matrix
int getLayer(double z, bool reco) const
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:102
static constexpr int k_threeCorners
std::array< int, 3 > HGCWaferParam
int32_t waferV(const int32_t index)
int waferTypeL(int wafer) const
std::vector< int > waferCopy_
col
Definition: cuy.py:1009
std::vector< double > cassetteShift_
bool tileExist(const int32_t *hex, int32_t zside, int32_t phi)
static unsigned int const shift
float x
std::vector< int > depthIndex_
static constexpr double tan30deg_
std::pair< double, double > waferPositionNoRot(int lay, int waferU, int waferV, bool reco, bool debug=false) const
std::vector< double > zFrontTop_
std::vector< double > radiusLayer_[2]
std::array< uint32_t, 2 > tot_layers_
static constexpr int32_t WaferFive
Definition: HGCalTypes.h:36
std::vector< int > waferTypeT_
int modules(int lay, bool reco) const
static constexpr int32_t WaferCornerMin
Definition: HGCalTypes.h:74
int modifyUV(int uv, int type1, int type2) const
std::vector< double > cellCoarseY_
int type() const
get the type
Log< level::Warning, false > LogWarning
static constexpr int32_t WaferFineThin
Definition: HGCalTypes.h:30
waferInfo_map waferInfoMap_
__host__ __device__ V wmin
const HGCalParameters * hgpar_
std::vector< double > waferPosX_
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
int scintCells(const int layer) const
tileInfo_map tileInfoMap_
static constexpr int k_allCorners
int cellHex(double xx, double yy, const double &cellR, const std::vector< double > &posX, const std::vector< double > &posY) const
std::vector< int > waferTypeL_
std::vector< double > xLayerHex_
static int32_t layerFrontBack(int32_t layerOrient)
Definition: HGCalTypes.h:125
void setParameter(int cassette, const std::vector< double > &shifts)
Definition: HGCalCassette.cc:7
double distFromEdgeHex(double x, double y, double z) const
int layerType(int lay) const
int waferFromCopy(int copy) const
__host__ __device__ V V wmax
static bool maskCell(int u, int v, int N, int ncor, int fcor, int corners)