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 zside, 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, zside, 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  int zside = (z > 0) ? 1 : -1;
187  double xx = (reco) ? (zside * x) : (zside * HGCalParameters::k_ScaleFromDDD * 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];
192  double phi = (((yy == 0.0) && (xx == 0.0)) ? 0. : std::atan2(yy, xx));
193  if (phi < 0)
194  phi += (2.0 * M_PI);
195  if (indx.second != 0)
196  iphi = (1 + static_cast<int>(phi / indx.second)) % hgpar_->scintCells(layer);
197  if (iphi == 0)
201  auto cshift = hgcassette_.getShift(layer, -1, cassette);
202 #ifdef EDM_ML_DEBUG
203  edm::LogVerbatim("HGCalGeomT") << "Cassette " << cassette << " Shift " << cshift.first << ":" << cshift.second<< " Original " << xx << ":"
204  << yy;
205 #endif
206  xx += (zside * cshift.first);
207  yy -= cshift.second;
208  }
210  double r = std::sqrt(xx * xx + yy * yy);
211  auto ir = std::lower_bound(hgpar_->radiusLayer_[type].begin(), hgpar_->radiusLayer_[type].end(), r);
212  irad = static_cast<int>(ir - hgpar_->radiusLayer_[type].begin());
213  irad = std::clamp(irad, hgpar_->iradMinBH_[indx.first], hgpar_->iradMaxBH_[indx.first]);
214 #ifdef EDM_ML_DEBUG
215  edm::LogVerbatim("HGCalGeomT") << "assignCellTrap Input " << x << ":" << y << ":" << z << ":" << layer << ":" << reco
216  << " x|y|r " << xx << ":" << yy << ":" << r << " phi " << phi << ":"
217  << convertRadToDeg(phi) << " o/p " << irad << ":" << iphi << ":" << type;
218 #endif
219  if (!tileExist(zside, layer, irad, iphi)) {
220  if (tileRingEdge(r, layer, irad)) {
221  if (std::abs(r - hgpar_->radiusLayer_[type][irad - 1]) < tol_) {
222  --irad;
223  if (irad <= hgpar_->iradMinBH_[indx.first])
224  irad = hgpar_->iradMinBH_[indx.first];
225  } else {
226  ++irad;
227  if (irad > hgpar_->iradMaxBH_[indx.first])
228  irad = hgpar_->iradMaxBH_[indx.first];
229  }
230 #ifdef EDM_ML_DEBUG
231  edm::LogVerbatim("HGCalGeomT") << "assignCellTrap: ring # modified to " << irad << ":"
232  << hgpar_->iradMinBH_[indx.first] << ":" << hgpar_->iradMaxBH_[indx.first];
233  ;
234 #endif
235  } else if (tilePhiEdge(phi, layer, iphi)) {
236  if (std::abs(phi - hgpar_->scintCellSize(layer) * (iphi - 1)) < tol_) {
237  --iphi;
238  if (iphi <= 0)
239  iphi = 1;
240  } else {
241  ++iphi;
242  if (iphi > hgpar_->scintCells(layer))
243  iphi = 1;
244  }
245 #ifdef EDM_ML_DEBUG
246  edm::LogVerbatim("HGCalGeomT") << "assignCellTrap: iphi # modified to " << iphi << ":"
247  << hgpar_->scintCells(layer);
248 #endif
249  }
250  }
251  return std::array<int, 3>{{irad, iphi, type}};
252 }
253 
255  bool shift(false);
258  auto ktr = hgpar_->waferInfoMap_.find(indx);
259  if (ktr != hgpar_->waferInfoMap_.end()) {
260  auto cshift = hgcassette_.getShift(layer, 1, (ktr->second).cassette);
261  if ((cshift.first != 0) || (cshift.second != 0))
262  shift = true;
263  }
264  }
265  return shift;
266 }
267 
269  bool shift(false);
271  auto cshift = hgcassette_.getShift(layer, 1, cassetteTile(iphi));
272  if ((cshift.first != 0) || (cshift.second != 0))
273  shift = true;
274  }
275  return shift;
276 }
277 
278 std::pair<double, double> HGCalDDDConstants::cellEtaPhiTrap(int type, int irad) const {
279  double dr(0), df(0);
280  if (tileTrapezoid()) {
281  double r = 0.5 * ((hgpar_->radiusLayer_[type][irad - 1] + hgpar_->radiusLayer_[type][irad]));
282  dr = (hgpar_->radiusLayer_[type][irad] - hgpar_->radiusLayer_[type][irad - 1]);
283  df = r * hgpar_->cellSize_[type];
284  }
285  return std::make_pair(dr, df);
286 }
287 
288 bool HGCalDDDConstants::cellInLayer(int waferU, int waferV, int cellU, int cellV, int lay, int zside, bool reco) const {
289  const auto& indx = getIndex(lay, true);
290  if (indx.first >= 0) {
292  int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
293  auto ktr = hgpar_->waferInfoMap_.find(indx);
294  int part = (ktr != hgpar_->waferInfoMap_.end()) ? (ktr->second).part : HGCalTypes::WaferFull;
295  return HGCalWaferMask::goodCell(cellU, cellV, part);
297  int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
298  auto ktr = hgpar_->waferInfoMap_.find(indx);
300  if (ktr != hgpar_->waferInfoMap_.end()) {
301  thck = (ktr->second).type;
302  part = (ktr->second).part;
303  rotn = (ktr->second).orient;
304  }
306  return HGCalWaferMask::goodCell(cellU, cellV, ncell, part, rotn);
307  } else if (waferHexagon8() || waferHexagon6()) {
308  const auto& xy =
309  ((waferHexagon8()) ? locateCell(zside, lay, waferU, waferV, cellU, cellV, reco, true, false, false)
310  : locateCell(cellU, lay, waferU, reco));
311  double rpos = sqrt(xy.first * xy.first + xy.second * xy.second);
312  return ((rpos >= hgpar_->rMinLayHex_[indx.first]) && (rpos <= hgpar_->rMaxLayHex_[indx.first]));
313  } else {
314  return true;
315  }
316  } else {
317  return false;
318  }
319 }
320 
322  double thick(-1);
323  int type = waferType(layer, waferU, waferV, false);
324  if (type >= 0) {
325  if (waferHexagon8()) {
326  thick = 10000.0 * hgpar_->cellThickness_[type]; // cm to micron
327  } else if (waferHexagon6()) {
328  thick = 100.0 * (type + 1); // type = 1,2,3 for 100,200,300 micron
329  }
330  }
331  return thick;
332 }
333 
335  int indx = ((waferHexagon8()) ? ((type >= 1) ? 1 : 0) : ((type == 1) ? 1 : 0));
336  double cell = (tileTrapezoid() ? 0.5 * hgpar_->cellSize_[indx]
338  return cell;
339 }
340 
341 int32_t HGCalDDDConstants::cellType(int type, int cellU, int cellV, int iz, int fwdBack, int orient) const {
342  int placement = (orient < 0) ? HGCalCell::cellPlacementOld : HGCalCell::cellPlacementIndex(iz, fwdBack, orient);
343  int ncell = (type == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
344  auto cellType = HGCalCell::cellType(cellU, cellV, ncell, placement);
345  return cellType.first;
346 }
347 
348 double HGCalDDDConstants::distFromEdgeHex(double x, double y, double z) const {
349  // Assming the point is within a hexagonal plane of the wafer, calculate
350  // the shortest distance from the edge
351  if (z < 0)
352  x = -x;
353  double dist(0);
354  // Input x, y in Geant4 unit and transformed to CMSSW standard
357  if (waferHexagon8()) {
358  int ll = layerIndex(getLayer(z, false), false);
359  xx -= hgpar_->xLayerHex_[ll];
360  yy -= hgpar_->yLayerHex_[ll];
361  }
362  int sizew = static_cast<int>(hgpar_->waferPosX_.size());
363  int wafer = sizew;
364  // Transform to the local coordinate frame of the wafer first
365  for (int k = 0; k < sizew; ++k) {
366  double dx = std::abs(xx - hgpar_->waferPosX_[k]);
367  double dy = std::abs(yy - hgpar_->waferPosY_[k]);
368  if ((dx <= rmax_) && (dy <= hexside_) && ((dy <= 0.5 * hexside_) || (dx * tan30deg_ <= (hexside_ - dy)))) {
369  wafer = k;
370  xx -= hgpar_->waferPosX_[k];
371  yy -= hgpar_->waferPosY_[k];
372  break;
373  }
374  }
375  // Look at only one quarter (both x,y are positive)
376  if (wafer < sizew) {
377  if (std::abs(yy) < 0.5 * hexside_) {
378  dist = rmax_ - std::abs(xx);
379  } else {
380  dist = 0.5 * ((rmax_ - std::abs(xx)) - sqrt3_ * (std::abs(yy) - 0.5 * hexside_));
381  }
382  } else {
383  dist = 0;
384  }
386 #ifdef EDM_ML_DEBUG
387  edm::LogVerbatim("HGCalGeom") << "DistFromEdgeHex: Local " << xx << ":" << yy << " wafer " << wafer << " flag "
388  << (wafer < sizew) << " Distance " << rmax_ << ":" << (rmax_ - std::abs(xx)) << ":"
389  << (std::abs(yy) - 0.5 * hexside_) << ":" << 0.5 * hexside_ << ":" << dist;
390 #endif
391  return dist;
392 }
393 
394 double HGCalDDDConstants::distFromEdgeTrap(double x, double y, double z) const {
395  // Assming the point is within the eta-phi plane of the scintillator tile,
396  // calculate the shortest distance from the edge
397  int lay = getLayer(z, false);
398  double xx = (z < 0) ? -x : x;
399  int indx = layerIndex(lay, false);
400  double r = HGCalParameters::k_ScaleFromDDD * std::sqrt(x * x + y * y);
401  double phi = (r == 0. ? 0. : std::atan2(y, xx));
402  if (phi < 0)
403  phi += (2.0 * M_PI);
404  int type = hgpar_->scintType(lay);
405  double cell = hgpar_->scintCellSize(lay);
406  // Compare with the center of the tile find distances along R and also phi
407  // Take the smaller value
408  auto ir = std::lower_bound(hgpar_->radiusLayer_[type].begin(), hgpar_->radiusLayer_[type].end(), r);
409  int irad = static_cast<int>(ir - hgpar_->radiusLayer_[type].begin());
410  irad = std::clamp(irad, hgpar_->iradMinBH_[indx], hgpar_->iradMaxBH_[indx]);
411  int iphi = 1 + static_cast<int>(phi / cell);
412  double dphi = std::max(0.0, (0.5 * cell - std::abs(phi - (iphi - 0.5) * cell)));
413  double dist = std::min((r - hgpar_->radiusLayer_[type][irad - 1]), (hgpar_->radiusLayer_[type][irad] - r));
414 #ifdef EDM_ML_DEBUG
415  edm::LogVerbatim("HGCalGeom") << "DistFromEdgeTrap: Global " << x << ":" << y << ":" << z << " Layer " << lay
416  << " Index " << indx << ":" << type << " xx " << xx << " R " << r << ":" << irad << ":"
417  << hgpar_->radiusLayer_[type][irad - 1] << ":" << hgpar_->radiusLayer_[type][irad]
418  << " Phi " << phi << ":" << iphi << ":" << (iphi - 0.5) * cell << " cell " << cell
419  << " Dphi " << dphi << " Dist " << dist << ":" << r * dphi;
420 #endif
421  return HGCalParameters::k_ScaleToDDD * std::min(r * dphi, dist);
422 }
423 
424 int HGCalDDDConstants::getLayer(double z, bool reco) const {
425  // Get the layer # from the gloabl z coordinate
426  unsigned int k = 0;
428  const auto& zLayerHex = hgpar_->zLayerHex_;
429  auto itr = std::find_if(zLayerHex.begin() + 1, zLayerHex.end(), [&k, &zz, &zLayerHex](double zLayer) {
430  ++k;
431  return zz < 0.5 * (zLayerHex[k - 1] + zLayerHex[k]);
432  });
433  int lay = (itr == zLayerHex.end()) ? static_cast<int>(zLayerHex.size()) : k;
434  if (waferHexagon6() && reco) {
435  int indx = layerIndex(lay, false);
436  if (indx >= 0)
437  lay = hgpar_->layerGroupO_[indx];
438  } else {
439  lay += (hgpar_->firstLayer_ - 1);
440  }
441  return lay;
442 }
443 
444 HGCalParameters::hgtrap HGCalDDDConstants::getModule(unsigned int indx, bool hexType, bool reco) const {
446  if (hexType) {
447  if (indx >= hgpar_->waferTypeL_.size())
448  edm::LogWarning("HGCalGeom") << "Wafer no. out bound for index " << indx << ":" << (hgpar_->waferTypeL_).size()
449  << ":" << (hgpar_->waferPosX_).size() << ":" << (hgpar_->waferPosY_).size()
450  << " ***** ERROR *****";
451  unsigned int type =
452  ((indx < hgpar_->waferTypeL_.size()) ? hgpar_->waferTypeL_[indx] - 1 : HGCSiliconDetId::HGCalCoarseThick);
453  mytr = hgpar_->getModule(type, reco);
454  } else {
455  mytr = hgpar_->getModule(indx, reco);
456  }
457  return mytr;
458 }
459 
460 std::vector<HGCalParameters::hgtrap> HGCalDDDConstants::getModules() const {
461  std::vector<HGCalParameters::hgtrap> mytrs;
462  for (unsigned int k = 0; k < hgpar_->moduleLayR_.size(); ++k)
463  mytrs.emplace_back(hgpar_->getModule(k, true));
464  return mytrs;
465 }
466 
467 int HGCalDDDConstants::getPhiBins(int lay) const { return (tileTrapezoid() ? hgpar_->scintCells(lay) : 0); }
468 
469 std::pair<double, double> HGCalDDDConstants::getRangeR(int lay, bool reco) const {
470  int indx = layerIndex(lay, false);
471  if ((indx >= 0) && (indx < static_cast<int>(hgpar_->rMinLayHex_.size())))
472  return std::make_pair(hgpar_->rMinLayHex_[indx], hgpar_->rMaxLayHex_[indx]);
473  else
474  return std::make_pair(0, -1.);
475 }
476 
477 std::pair<int, int> HGCalDDDConstants::getREtaRange(int lay) const {
478  int irmin(0), irmax(0);
479  if (tileTrapezoid()) {
480  int indx = layerIndex(lay, false);
481  if ((indx >= 0) && (indx < static_cast<int>(hgpar_->iradMinBH_.size()))) {
482  irmin = hgpar_->iradMinBH_[indx];
483  irmax = hgpar_->iradMaxBH_[indx];
484  }
485  }
486  return std::make_pair(irmin, irmax);
487 }
488 
489 std::vector<HGCalParameters::hgtrform> HGCalDDDConstants::getTrForms() const {
490  std::vector<HGCalParameters::hgtrform> mytrs;
491  for (unsigned int k = 0; k < hgpar_->trformIndex_.size(); ++k)
492  mytrs.emplace_back(hgpar_->getTrForm(k));
493  return mytrs;
494 }
495 
497  // Get the module type for scinitllator
498  if (tileTrapezoid()) {
499  return hgpar_->scintType(layer);
500  } else {
501  return -1;
502  }
503 }
504 
506  // Get the module type for a silicon wafer
507  if (waferHexagon8()) {
509  return ((itr == hgpar_->typesInLayers_.end() ? 2 : hgpar_->waferTypeL_[itr->second]));
510  } else {
511  return -1;
512  }
513 }
514 
515 std::pair<double, double> HGCalDDDConstants::getXY(int layer, double x, double y, bool forwd) const {
516  int ll = layer - hgpar_->firstLayer_;
517  double x0(x), y0(y);
518  if ((!hgpar_->layerType_.empty()) && (ll < static_cast<int>(hgpar_->layerRotV_.size()))) {
519  if (forwd) {
520  x0 = x * hgpar_->layerRotV_[ll].first + y * hgpar_->layerRotV_[ll].second;
521  y0 = y * hgpar_->layerRotV_[ll].first - x * hgpar_->layerRotV_[ll].second;
522  } else {
523  x0 = x * hgpar_->layerRotV_[ll].first - y * hgpar_->layerRotV_[ll].second;
524  y0 = y * hgpar_->layerRotV_[ll].first + x * hgpar_->layerRotV_[ll].second;
525  }
526  }
527 #ifdef EDM_ML_DEBUG
528  double x1(x0), y1(y0);
529  if (ll < static_cast<int>(hgpar_->layerRotV_.size())) {
530  if (forwd) {
531  x1 = x0 * hgpar_->layerRotV_[ll].first - y0 * hgpar_->layerRotV_[ll].second;
532  y1 = y0 * hgpar_->layerRotV_[ll].first + x0 * hgpar_->layerRotV_[ll].second;
533  } else {
534  x1 = x0 * hgpar_->layerRotV_[ll].first + y0 * hgpar_->layerRotV_[ll].second;
535  y1 = y0 * hgpar_->layerRotV_[ll].first - x0 * hgpar_->layerRotV_[ll].second;
536  }
537  }
538  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants: Layer " << layer << ":" << ll << " mode " << forwd << " x " << x
539  << ":" << x0 << ":" << x1 << " y " << y << ":" << y0 << ":" << y1;
540 #endif
541  return std::make_pair(x0, y0);
542 }
543 
544 bool HGCalDDDConstants::isHalfCell(int waferType, int cell) const {
545  if (waferType < 1 || cell < 0)
546  return false;
547  return waferType == 2 ? hgpar_->cellCoarseHalf_[cell] : hgpar_->cellFineHalf_[cell];
548 }
549 
550 bool HGCalDDDConstants::isValidHex(int lay, int mod, int cell, bool reco) const {
551  // Check validity for a layer|wafer|cell of pre-TDR version
552  bool result(false), resultMod(false);
553  int cellmax(0);
554  if (waferHexagon6()) {
555  int32_t copyNumber = hgpar_->waferCopy_[mod];
556  result = ((lay > 0 && lay <= static_cast<int>(layers(reco))));
557  if (result) {
558  const int32_t lay_idx = reco ? (lay - 1) * 3 + 1 : lay;
559  const auto& the_modules = hgpar_->copiesInLayers_[lay_idx];
560  auto moditr = the_modules.find(copyNumber);
561  result = resultMod = (moditr != the_modules.end());
562 #ifdef EDM_ML_DEBUG
563  if (!result)
564  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants: Layer " << lay << ":" << lay_idx << " Copy " << copyNumber
565  << ":" << mod << " Flag " << result;
566 #endif
567  if (result) {
568  if (moditr->second >= 0) {
569  if (mod >= static_cast<int>(hgpar_->waferTypeT_.size()))
570  edm::LogWarning("HGCalGeom") << "Module no. out of bound for " << mod << " to be compared with "
571  << (hgpar_->waferTypeT_).size() << " ***** ERROR *****";
572  cellmax = ((hgpar_->waferTypeT_[mod] - 1 == HGCSiliconDetId::HGCalFine)
573  ? static_cast<int>(hgpar_->cellFineX_.size())
574  : static_cast<int>(hgpar_->cellCoarseX_.size()));
575  result = (cell >= 0 && cell <= cellmax);
576  } else {
577  result = isValidCell(lay_idx, mod, cell);
578  }
579  }
580  }
581  }
582 
583 #ifdef EDM_ML_DEBUG
584  if (!result)
585  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants: Layer " << lay << ":"
586  << (lay > 0 && (lay <= static_cast<int>(layers(reco)))) << " Module " << mod << ":"
587  << resultMod << " Cell " << cell << ":" << cellmax << ":"
588  << (cell >= 0 && cell <= cellmax) << ":" << maxCells(reco);
589 #endif
590  return result;
591 }
592 
593 bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, bool fullAndPart) const {
594  // Check validity for a layer|wafer|cell of post-TDR version
595  int indx = HGCalWaferIndex::waferIndex(layer, modU, modV);
596  auto itr = hgpar_->typesInLayers_.find(indx);
597 #ifdef EDM_ML_DEBUG
598  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants::isValidHex8:WaferType " << layer << ":" << modU << ":" << modV
599  << ":" << indx << " Test " << (itr != hgpar_->typesInLayers_.end());
600 #endif
601  if (itr == hgpar_->typesInLayers_.end()) {
602 #ifdef EDM_ML_DEBUG
603  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
604  << " in wadferIndex";
605 #endif
606  return false;
607  }
608 
609  if (fullAndPart_) {
610  auto ktr = hgpar_->waferInfoMap_.find(indx);
611 #ifdef EDM_ML_DEBUG
612  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants::isValidHex8:WaferInfoMap " << layer << ":" << modU << ":"
613  << modV << ":" << indx << " Test " << (ktr != hgpar_->waferInfoMap_.end());
614 #endif
615  if (ktr == hgpar_->waferInfoMap_.end()) {
616 #ifdef EDM_ML_DEBUG
617  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
618  << " in wadferInfoMap";
619 #endif
620  return false;
621  }
622  } else {
623  auto jtr = waferIn_.find(indx);
624 #ifdef EDM_ML_DEBUG
625  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants::isValidHex8:WaferIn " << jtr->first << ":" << jtr->second;
626 #endif
627  if (!(jtr->second)) {
628 #ifdef EDM_ML_DEBUG
629  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
630  << " in wadferIn";
631 #endif
632  return false;
633  }
634  }
635 
636  if (fullAndPart || fullAndPart_) {
637  auto ktr = hgpar_->waferTypes_.find(indx);
638  if (ktr != hgpar_->waferTypes_.end()) {
639  if (hgpar_->waferMaskMode_ > 0) {
640  if (ktr->second.first == HGCalTypes::WaferOut) {
641 #ifdef EDM_ML_DEBUG
642  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
643  << " due to WaferOut";
644 #endif
645  return false;
646  }
647  } else {
648  if (ktr->second.first < HGCalTypes::WaferCornerMin) {
649 #ifdef EDM_ML_DEBUG
650  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot find " << layer << ":" << modU << ":" << modV
651  << " due to WaferCornerMin";
652 #endif
653  return false;
654  }
655  }
656  }
657  }
658  return true;
659 }
660 
661 bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, int cellU, int cellV, bool fullAndPart) const {
662  // First check validity for a layer|wafer| of post TDR version
663 #ifdef EDM_ML_DEBUG
664  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: layer|wafer " << layer << ":" << modU << ":" << modV << ":"
665  << fullAndPart << " Valid " << isValidHex8(layer, modU, modV, fullAndPart);
666 #endif
667  if (!isValidHex8(layer, modU, modV, fullAndPart))
668  return false;
669  int indx = HGCalWaferIndex::waferIndex(layer, modU, modV);
670  auto itr = hgpar_->typesInLayers_.find(indx);
671  int type = hgpar_->waferTypeL_[itr->second];
672  int N = ((hgpar_->waferTypeL_[itr->second] == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_);
673 #ifdef EDM_ML_DEBUG
674  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants::isValidHex8:Cell " << cellU << ":" << cellV << ":" << N
675  << " Tests " << (cellU >= 0) << ":" << (cellU < 2 * N) << ":" << (cellV >= 0) << ":"
676  << (cellV < 2 * N) << ":" << ((cellV - cellU) < N) << ":" << ((cellU - cellV) <= N);
677 #endif
678  if ((cellU < 0) || (cellU >= 2 * N) || (cellV < 0) || (cellV >= 2 * N)) {
679 #ifdef EDM_ML_DEBUG
680  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot statisfy Cell 1 condition " << cellU << ":" << cellV
681  << ":" << N;
682 #endif
683  return false;
684  }
685  if (((cellV - cellU) >= N) || ((cellU - cellV) > N)) {
686 #ifdef EDM_ML_DEBUG
687  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:: Cannot statisfy Cell 2 condition " << cellU << ":" << cellV
688  << ":" << N;
689 #endif
690  return false;
691  }
692  return isValidCell8(layer, modU, modV, cellU, cellV, type);
693 }
694 
695 bool HGCalDDDConstants::isValidTrap(int zside, int layer, int irad, int iphi) const {
696  // Check validity for a layer|eta|phi of scintillator
697  const auto& indx = getIndex(layer, true);
698  if (indx.first < 0)
699  return false;
700  bool ok = ((irad >= hgpar_->iradMinBH_[indx.first]) && (irad <= (hgpar_->iradMaxBH_[indx.first] + 1)) && (iphi > 0) &&
701  (iphi <= hgpar_->scintCells(layer)));
702  bool valid = ((ok && trapezoidFile()) ? tileExist(zside, layer, irad, iphi) : ok);
703 #ifdef EDM_ML_DEBUG
704  bool tileEx = trapezoidFile() ? tileExist(zside, layer, irad, iphi) : true;
705  edm::LogVerbatim("HGCalGeomT") << "HGCalDDDConstants::isValidityTrap: Input " << zside << ":" << layer << ":" << irad
706  << ":" << iphi << " Range on Ring " << hgpar_->iradMinBH_[indx.first] << ":"
707  << (hgpar_->iradMaxBH_[indx.first] + 1)
708  << " Range on phi 0:" << hgpar_->scintCells(layer) << " tileExist " << tileEx
709  << " Valid " << ok << ":" << valid;
710 #endif
711  return valid;
712 }
713 
715  return (hgpar_->firstLayer_ + tot_layers_[static_cast<int>(reco)] - 1);
716 }
717 
718 unsigned int HGCalDDDConstants::layers(bool reco) const { return tot_layers_[static_cast<int>(reco)]; }
719 
720 int HGCalDDDConstants::layerIndex(int lay, bool reco) const {
721  int ll = lay - hgpar_->firstLayer_;
722  if (ll < 0 || ll >= static_cast<int>(hgpar_->layerIndex_.size()))
723  return -1;
724  if (waferHexagon6()) {
725  if (reco && ll >= static_cast<int>(hgpar_->depthIndex_.size()))
726  return -1;
727  return (reco ? hgpar_->depthLayerF_[ll] : hgpar_->layerIndex_[ll]);
728  } else {
729  return (hgpar_->layerIndex_[ll]);
730  }
731 }
732 
733 unsigned int HGCalDDDConstants::layersInit(bool reco) const {
734  return (reco ? hgpar_->depthIndex_.size() : hgpar_->layerIndex_.size());
735 }
736 
737 std::pair<float, float> HGCalDDDConstants::localToGlobal8(
738  int zside, int lay, int waferU, int waferV, double localX, double localY, bool reco, bool debug) const {
739  double x(localX), y(localY);
740  bool rotx =
742  if (debug)
743  edm::LogVerbatim("HGCalGeom") << "LocalToGlobal8 " << lay << ":" << (lay - hgpar_->firstLayer_) << ":" << rotx
744  << " Local (" << x << ":" << y << ") Reco " << reco;
745  if (!reco) {
748  }
749  const auto& xy = waferPositionNoRot(lay, waferU, waferV, reco, debug);
750  x += xy.first;
751  y += xy.second;
752  int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
753  auto ktr = hgpar_->waferInfoMap_.find(indx);
754  if ((mode_ == HGCalGeometryMode::Hexagon8Cassette) && (ktr != hgpar_->waferInfoMap_.end())) {
755  auto cshift = hgcassette_.getShift(lay, -zside, (ktr->second).cassette);
756  if (debug)
757  edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << -(zside * cshift.first)
758  << ":" << cshift.second;
759  if (!reco) {
760  x -= ((HGCalParameters::k_ScaleToDDD)*zside * cshift.first);
761  y += ((HGCalParameters::k_ScaleToDDD)*cshift.second);
762  } else {
763  x -= (zside * cshift.first);
764  y += cshift.second;
765  }
766  }
767  if (debug)
768  edm::LogVerbatim("HGCalGeom") << "With wafer " << x << ":" << y << " by adding " << xy.first << ":" << xy.second;
769  return (rotx ? getXY(lay, x, y, false) : std::make_pair(x, y));
770 }
771 
772 std::pair<float, float> HGCalDDDConstants::locateCell(int cell, int lay, int type, bool reco) const {
773  // type refers to wafer # for hexagon cell
774  float x(999999.), y(999999.);
775  const auto& index = getIndex(lay, reco);
776  int i = index.first;
777  if (i < 0)
778  return std::make_pair(x, y);
779  if (waferHexagon6()) {
780  x = hgpar_->waferPosX_[type];
781  y = hgpar_->waferPosY_[type];
782 #ifdef EDM_ML_DEBUG
783  float x0(x), y0(y);
784 #endif
786  x += hgpar_->cellFineX_[cell];
787  y += hgpar_->cellFineY_[cell];
788  } else {
789  x += hgpar_->cellCoarseX_[cell];
790  y += hgpar_->cellCoarseY_[cell];
791  }
792 #ifdef EDM_ML_DEBUG
793  edm::LogVerbatim("HGCalGeom") << "LocateCell (Wafer) " << x0 << ":" << y0 << " Final " << x << ":" << y;
794 #endif
795  if (!reco) {
798  }
799  }
800  return std::make_pair(x, y);
801 }
802 
803 std::pair<float, float> HGCalDDDConstants::locateCell(
804  int zside, int lay, int waferU, int waferV, int cellU, int cellV, bool reco, bool all, bool norot, bool debug)
805  const {
806  double x(0), y(0);
807  int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
808  auto itr = hgpar_->typesInLayers_.find(indx);
809  int type = ((itr == hgpar_->typesInLayers_.end()) ? 2 : hgpar_->waferTypeL_[itr->second]);
810  int layertype = layerType(lay);
811  bool rotx = (norot) ? false : (layertype == HGCalTypes::WaferCenterR);
812  if (debug) {
813  edm::LogVerbatim("HGCalGeom") << "LocateCell " << lay << ":" << (lay - hgpar_->firstLayer_) << ":" << layertype
814  << ":" << rotx << ":" << waferU << ":" << waferV << ":" << indx << ":"
815  << (itr == hgpar_->typesInLayers_.end()) << ":" << type << " Flags " << reco << ":"
816  << all;
817  }
818  auto ktr = hgpar_->waferInfoMap_.end();
819  int place(HGCalCell::cellPlacementOld);
820  if (waferHexagon8File()) {
822  ktr = hgpar_->waferInfoMap_.find(indx);
823  if (ktr != hgpar_->waferInfoMap_.end())
824  place = HGCalCell::cellPlacementIndex(1, HGCalTypes::layerFrontBack(layertype), (ktr->second).orient);
825  }
826  auto xy = hgcell_->cellUV2XY2(cellU, cellV, place, type);
827  x = xy.first;
828  y = xy.second;
829  if (debug)
830  edm::LogVerbatim("HGCalGeom") << "Type " << type << " Place " << place << " Cell " << cellU << ":" << cellV
831  << " Position " << x << ":" << y;
832  } else {
833  int kndx = cellV * 100 + cellU;
834  if (type == 0) {
835  auto jtr = hgpar_->cellFineIndex_.find(kndx);
836  if (jtr != hgpar_->cellFineIndex_.end()) {
837  x = hgpar_->cellFineX_[jtr->second];
838  y = hgpar_->cellFineY_[jtr->second];
839  }
840  if (debug)
841  edm::LogVerbatim("HGCalGeom") << "Fine " << cellU << ":" << cellV << ":" << kndx << ":" << x << ":" << y << ":"
842  << (jtr != hgpar_->cellFineIndex_.end());
843  } else {
844  auto jtr = hgpar_->cellCoarseIndex_.find(kndx);
845  if (jtr != hgpar_->cellCoarseIndex_.end()) {
846  x = hgpar_->cellCoarseX_[jtr->second];
847  y = hgpar_->cellCoarseY_[jtr->second];
848  }
849  if (debug)
850  edm::LogVerbatim("HGCalGeom") << "Coarse " << cellU << ":" << cellV << ":" << kndx << ":" << x << ":" << y
851  << ":" << (jtr != hgpar_->cellCoarseIndex_.end());
852  }
853  }
854  if (!reco) {
857  }
858  if (all) {
859  const auto& xy = waferPositionNoRot(lay, waferU, waferV, reco, debug);
860  x += xy.first;
861  y += xy.second;
862  if ((mode_ == HGCalGeometryMode::Hexagon8Cassette) && (ktr != hgpar_->waferInfoMap_.end())) {
863  auto cshift = hgcassette_.getShift(lay, -zside, (ktr->second).cassette);
864  if (debug)
865  edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << -(zside * cshift.first)
866  << ":" << cshift.second;
867  if (!reco) {
868  x -= ((HGCalParameters::k_ScaleToDDD)*zside * cshift.first);
869  y += ((HGCalParameters::k_ScaleToDDD)*cshift.second);
870  } else {
871  x -= (zside * cshift.first);
872  y += cshift.second;
873  }
874  }
875  if (debug)
876  edm::LogVerbatim("HGCalGeom") << "With wafer " << x << ":" << y << " by adding " << xy.first << ":" << xy.second;
877  }
878  return (rotx ? getXY(lay, x, y, false) : std::make_pair(x, y));
879 }
880 
881 std::pair<float, float> HGCalDDDConstants::locateCell(const HGCSiliconDetId& id, bool debug) const {
882  return locateCell(id.zside(), id.layer(), id.waferU(), id.waferV(), id.cellU(), id.cellV(), true, true, false, debug);
883 }
884 
885 std::pair<float, float> HGCalDDDConstants::locateCell(const HGCScintillatorDetId& id, bool debug) const {
886  return locateCellTrap(id.zside(), id.layer(), id.iradius(), id.iphi(), true, debug);
887 }
888 
889 std::pair<float, float> HGCalDDDConstants::locateCellHex(int cell, int wafer, bool reco) const {
890  float x(0), y(0);
891  if (hgpar_->waferTypeT_[wafer] - 1 == HGCSiliconDetId::HGCalFine) {
892  x = hgpar_->cellFineX_[cell];
893  y = hgpar_->cellFineY_[cell];
894  } else {
895  x = hgpar_->cellCoarseX_[cell];
896  y = hgpar_->cellCoarseY_[cell];
897  }
898  if (!reco) {
901  }
902  return std::make_pair(x, y);
903 }
904 
905 std::pair<float, float> HGCalDDDConstants::locateCellTrap(
906  int zside, int lay, int irad, int iphi, bool reco, bool debug) const {
907  float x(0), y(0);
908  const auto& indx = getIndex(lay, reco);
909  if (indx.first >= 0) {
910  int ir = std::abs(irad);
911  int type = hgpar_->scintType(lay);
912  double phi = (iphi - 0.5) * indx.second;
913  double z = hgpar_->zLayerHex_[indx.first];
914  double r = 0.5 * (hgpar_->radiusLayer_[type][ir - 1] + hgpar_->radiusLayer_[type][ir]);
915  std::pair<double, double> range = rangeR(z, true);
916  if (debug)
917  edm::LogVerbatim("HGCalGeom") << "locateCellTrap:: Input " << lay << ":" << irad << ":" << iphi << ":" << reco
918  << " IR " << ir << ":" << hgpar_->iradMinBH_[indx.first] << ":"
919  << hgpar_->iradMaxBH_[indx.first] << " Type " << type << " Z " << indx.first << ":"
920  << z << " phi " << phi << ":" << convertRadToDeg(phi) << " R " << r << ":"
921  << range.first << ":" << range.second;
924  r = std::max(range.first, std::min(r, range.second));
925  x = r * std::cos(phi);
926  y = r * std::sin(phi);
927  int ll = lay - hgpar_->firstLayer_;
928  x += hgpar_->xLayerHex_[ll];
929  y += hgpar_->yLayerHex_[ll];
930  if (irad < 0)
931  x = -x;
934  auto cshift = hgcassette_.getShift(lay, -1, cassette);
935  if (debug)
936  edm::LogVerbatim("HGCalGeom") << "Cassette " << cassette << " Shift " << -(zside * cshift.first) << ":"
937  << cshift.second;
938  x -= cshift.first;
939  y += cshift.second;
940  }
941  }
942  if (!reco) {
945  }
946  return std::make_pair(x, y);
947 }
948 
949 bool HGCalDDDConstants::maskCell(const DetId& detId, int corners) const {
950  bool mask(false);
951  if (corners > 2 && corners <= static_cast<int>(HGCalParameters::k_CornerSize)) {
952  if (waferHexagon8()) {
953  int N(0), layer(0), waferU(0), waferV(0), u(0), v(0);
954  if (detId.det() == DetId::Forward) {
955  HFNoseDetId id(detId);
956  N = getUVMax(id.type());
957  layer = id.layer();
958  waferU = id.waferU();
959  waferV = id.waferV();
960  u = id.cellU();
961  v = id.cellV();
962  } else {
963  HGCSiliconDetId id(detId);
964  N = getUVMax(id.type());
965  layer = id.layer();
966  waferU = id.waferU();
967  waferV = id.waferV();
968  u = id.cellU();
969  v = id.cellV();
970  }
972  auto itr = hgpar_->waferTypes_.find(wl);
973  auto ktr = hgpar_->waferInfoMap_.find(wl);
974 #ifdef EDM_ML_DEBUG
975  edm::LogVerbatim("HGCalGeom") << "MaskCell: Layer " << layer << " Wafer " << waferU << ":" << waferV << " Index "
976  << wl << ":" << (itr != hgpar_->waferTypes_.end()) << ":"
977  << (ktr != hgpar_->waferInfoMap_.end());
978 #endif
980  int part = (ktr != hgpar_->waferInfoMap_.end()) ? (ktr->second).part : HGCalTypes::WaferFull;
982  } else if (itr != hgpar_->waferTypes_.end()) {
983  if ((itr->second).second <= HGCalTypes::k_OffsetRotation)
984  mask = HGCalWaferMask::maskCell(u, v, N, (itr->second).first, (itr->second).second, corners);
985  else
987  u, v, N, (itr->second).first, ((itr->second).second - HGCalTypes::k_OffsetRotation)));
988  }
989  }
990  }
991  return mask;
992 }
993 
995  int cells(0);
996  for (unsigned int i = 0; i < layers(reco); ++i) {
997  int lay = reco ? hgpar_->depth_[i] : hgpar_->layer_[i];
998  if (cells < maxCells(lay, reco))
999  cells = maxCells(lay, reco);
1000  }
1001  return cells;
1002 }
1003 
1004 int HGCalDDDConstants::maxCells(int lay, bool reco) const {
1005  const auto& index = getIndex(lay, reco);
1006  if (index.first < 0)
1007  return 0;
1008  if (waferHexagon6()) {
1009  unsigned int cells(0);
1010  for (unsigned int k = 0; k < hgpar_->waferTypeT_.size(); ++k) {
1011  if (waferInLayerTest(k, index.first, hgpar_->defineFull_)) {
1012  unsigned int cell = (hgpar_->waferTypeT_[k] - 1 == HGCSiliconDetId::HGCalFine) ? (hgpar_->cellFineX_.size())
1013  : (hgpar_->cellCoarseX_.size());
1014  if (cell > cells)
1015  cells = cell;
1016  }
1017  }
1018  return static_cast<int>(cells);
1019  } else if (waferHexagon8()) {
1020  int cells(0);
1021  for (unsigned int k = 0; k < hgpar_->waferCopy_.size(); ++k) {
1022  if (waferInLayerTest(k, index.first, hgpar_->defineFull_)) {
1026  : hgpar_->waferTypeL_[itr->second]);
1028  cells = std::max(cells, 3 * N * N);
1029  }
1030  }
1031  return cells;
1032  } else if (tileTrapezoid()) {
1033  return hgpar_->scintCells(index.first + hgpar_->firstLayer_);
1034  } else {
1035  return 0;
1036  }
1037 }
1038 
1039 int HGCalDDDConstants::maxRows(int lay, bool reco) const {
1040  int kymax(0);
1041  const auto& index = getIndex(lay, reco);
1042  int i = index.first;
1043  if (i < 0)
1044  return kymax;
1045  if (waferHexagon6()) {
1046  for (unsigned int k = 0; k < hgpar_->waferCopy_.size(); ++k) {
1048  int ky = ((hgpar_->waferCopy_[k]) / 100) % 100;
1049  if (ky > kymax)
1050  kymax = ky;
1051  }
1052  }
1053  } else if (waferHexagon8()) {
1054  kymax = 1 + 2 * hgpar_->waferUVMaxLayer_[index.first];
1055  }
1056  return kymax;
1057 }
1058 
1059 int HGCalDDDConstants::modifyUV(int uv, int type1, int type2) const {
1060  // Modify u/v for transition of type1 to type2
1061  return (((type1 == type2) || (type1 * type2 != 0)) ? uv : ((type1 == 0) ? (2 * uv + 1) / 3 : (3 * uv) / 2));
1062 }
1063 
1064 int HGCalDDDConstants::modules(int lay, bool reco) const {
1065  if (getIndex(lay, reco).first < 0)
1066  return 0;
1067  else
1068  return max_modules_layer_[static_cast<int>(reco)][lay];
1069 }
1070 
1071 int HGCalDDDConstants::modulesInit(int lay, bool reco) const {
1072  int nmod(0);
1073  const auto& index = getIndex(lay, reco);
1074  if (index.first < 0)
1075  return nmod;
1076  if (!tileTrapezoid()) {
1077  for (unsigned int k = 0; k < hgpar_->waferPosX_.size(); ++k) {
1078  if (waferInLayerTest(k, index.first, hgpar_->defineFull_))
1079  ++nmod;
1080  }
1081  } else {
1082  nmod = 1 + hgpar_->lastModule_[index.first] - hgpar_->firstModule_[index.first];
1083  }
1084  return nmod;
1085 }
1086 
1089 }
1090 
1094  ? tileCount(0, -1)
1095  : 0;
1096  if (cells == 0) {
1097  unsigned int nlayer = (reco) ? hgpar_->depth_.size() : hgpar_->layer_.size();
1098  for (unsigned k = 0; k < nlayer; ++k) {
1099  std::vector<int> ncells = numberCells(((reco) ? hgpar_->depth_[k] : hgpar_->layer_[k]), reco);
1100  cells = std::accumulate(ncells.begin(), ncells.end(), cells);
1101  }
1102  }
1103  return cells;
1104 }
1105 
1106 std::vector<int> HGCalDDDConstants::numberCells(int lay, bool reco) const {
1107  const auto& index = getIndex(lay, reco);
1108  int i = index.first;
1109  std::vector<int> ncell;
1110  if (i >= 0) {
1111  if (waferHexagon6()) {
1112  for (unsigned int k = 0; k < hgpar_->waferTypeT_.size(); ++k) {
1114  unsigned int cell = (hgpar_->waferTypeT_[k] - 1 == HGCSiliconDetId::HGCalFine)
1115  ? (hgpar_->cellFineX_.size())
1116  : (hgpar_->cellCoarseX_.size());
1117  ncell.emplace_back(static_cast<int>(cell));
1118  }
1119  }
1120  } else if (tileTrapezoid()) {
1121  int nphi = hgpar_->scintCells(lay);
1122  for (int k = hgpar_->firstModule_[i]; k <= hgpar_->lastModule_[i]; ++k)
1123  ncell.emplace_back(nphi);
1124  } else {
1125  for (unsigned int k = 0; k < hgpar_->waferCopy_.size(); ++k) {
1126  if (waferInLayerTest(k, index.first, hgpar_->defineFull_)) {
1127  int cell = numberCellsHexagon(lay,
1130  true);
1131  ncell.emplace_back(cell);
1132  }
1133  }
1134  }
1135  }
1136  return ncell;
1137 }
1138 
1140  if (wafer >= 0 && wafer < static_cast<int>(hgpar_->waferTypeT_.size())) {
1141  if (hgpar_->waferTypeT_[wafer] - 1 == HGCSiliconDetId::HGCalFine)
1142  return static_cast<int>(hgpar_->cellFineX_.size());
1143  else
1144  return static_cast<int>(hgpar_->cellCoarseX_.size());
1145  } else {
1146  return 0;
1147  }
1148 }
1149 
1150 int HGCalDDDConstants::numberCellsHexagon(int lay, int waferU, int waferV, bool flag) const {
1152  int type =
1153  ((itr == hgpar_->typesInLayers_.end()) ? HGCSiliconDetId::HGCalCoarseThick : hgpar_->waferTypeL_[itr->second]);
1154  int N = (type == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
1155  if (flag)
1156  return (3 * N * N);
1157  else
1158  return N;
1159 }
1160 
1161 std::pair<double, double> HGCalDDDConstants::rangeR(double z, bool reco) const {
1162  double rmin(0), rmax(0), zz(0);
1163  if (hgpar_->detectorType_ > 0) {
1165  if (hgpar_->detectorType_ <= 2) {
1167  } else {
1168  rmin = HGCalGeomTools::radius(
1170  }
1171  if ((hgpar_->detectorType_ == 2) && (zz >= hgpar_->zLayerHex_[hgpar_->firstMixedLayer_ - 1])) {
1172  rmax = HGCalGeomTools::radius(
1174  } else {
1176  }
1177  }
1178  if (!reco) {
1181  }
1182 #ifdef EDM_ML_DEBUG
1183  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:rangeR: " << z << ":" << zz << " R " << rmin << ":" << rmax;
1184 #endif
1185  return std::make_pair(rmin, rmax);
1186 }
1187 
1188 std::pair<double, double> HGCalDDDConstants::rangeRLayer(int lay, bool reco) const {
1189  double rmin(0), rmax(0);
1190  const auto& index = getIndex(lay, reco);
1191  if (index.first >= 0 && index.first < static_cast<int>(hgpar_->rMinLayHex_.size())) {
1192  rmin = hgpar_->rMinLayHex_[index.first];
1193  rmax = hgpar_->rMaxLayHex_[index.first];
1194  }
1195  if (!reco) {
1198  }
1199 #ifdef EDM_ML_DEBUG
1200  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:rangeR: " << lay << ":" << index.first << " R " << rmin << ":"
1201  << rmax;
1202 #endif
1203  return std::make_pair(rmin, rmax);
1204 }
1205 
1206 std::pair<double, double> HGCalDDDConstants::rangeZ(bool reco) const {
1207  double zmin = (hgpar_->zLayerHex_[0] - hgpar_->waferThick_);
1208  double zmax = (hgpar_->zLayerHex_[hgpar_->zLayerHex_.size() - 1] + hgpar_->waferThick_);
1209 #ifdef EDM_ML_DEBUG
1210  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants:rangeZ: " << zmin << ":" << zmax << ":" << hgpar_->waferThick_;
1211 #endif
1212  if (!reco) {
1215  }
1216  return std::make_pair(zmin, zmax);
1217 }
1218 
1219 std::pair<int, int> HGCalDDDConstants::rowColumnWafer(int wafer) const {
1220  int row(0), col(0);
1221  if (wafer < static_cast<int>(hgpar_->waferCopy_.size())) {
1222  int copy = hgpar_->waferCopy_[wafer];
1225  ;
1226  }
1227  return std::make_pair(row, col);
1228 }
1229 
1230 std::pair<int, int> HGCalDDDConstants::simToReco(int cell, int lay, int mod, bool half) const {
1231  if (!waferHexagon6()) {
1232  return std::make_pair(cell, lay);
1233  } else {
1234  const auto& index = getIndex(lay, false);
1235  int i = index.first;
1236  if (i < 0) {
1237  edm::LogWarning("HGCalGeom") << "Wrong Layer # " << lay << " not in the list ***** ERROR *****";
1238  return std::make_pair(-1, -1);
1239  }
1240  if (mod >= static_cast<int>(hgpar_->waferTypeL_.size())) {
1241  edm::LogWarning("HGCalGeom") << "Invalid Wafer # " << mod << "should be < " << (hgpar_->waferTypeL_).size()
1242  << " ***** ERROR *****";
1243  return std::make_pair(-1, -1);
1244  }
1245  int depth(-1);
1246  int kx = cell;
1247  int type = hgpar_->waferTypeL_[mod];
1248  if (type == 1) {
1249  depth = hgpar_->layerGroup_[i];
1250  } else if (type == 2) {
1251  depth = hgpar_->layerGroupM_[i];
1252  } else {
1253  depth = hgpar_->layerGroupO_[i];
1254  }
1255  return std::make_pair(kx, depth);
1256  }
1257 }
1258 
1260  int laymin(layer), laymax(layer), ringmin(ring), ringmax(ring), kount(0);
1261  if (layer == 0) {
1262  laymin = hgpar_->firstLayer_;
1263  laymax = lastLayer(true);
1264  }
1265 #ifdef EDM_ML_DEBUG
1266  edm::LogVerbatim("HGCalGeom") << "tileCount: layer " << layer << " ring " << ring << " layerMin/Max " << laymin << ":"
1267  << laymax;
1268 #endif
1269  for (int lay = laymin; lay <= laymax; ++lay) {
1270  if (ring < 0) {
1271  int ll = lay - hgpar_->firstLayer_;
1272  ringmin = hgpar_->tileRingRange_[ll].first;
1273  ringmax = hgpar_->tileRingRange_[ll].second;
1274  }
1275 #ifdef EDM_ML_DEBUG
1276  edm::LogVerbatim("HGCalGeom") << "tileCount: lay " << lay << ":" << (lay - hgpar_->firstLayer_) << " rings "
1277  << ringmin << ":" << ringmax;
1278 #endif
1279  for (int rin = ringmin; rin <= ringmax; ++rin) {
1280  int indx = HGCalTileIndex::tileIndex(lay, rin + 1, 0);
1281  auto itr = hgpar_->tileInfoMap_.find(indx);
1282 #ifdef EDM_ML_DEBUG
1283  edm::LogVerbatim("HGCalGeom") << "tileCount: rin " << rin << " indx " << indx << " itr "
1284  << (itr != hgpar_->tileInfoMap_.end());
1285 #endif
1286  if (itr != hgpar_->tileInfoMap_.end()) {
1287  for (int k = 0; k < 4; ++k) {
1288  std::bitset<24> b(itr->second.hex[k]);
1289  kount += b.count();
1290  }
1291  }
1292 #ifdef EDM_ML_DEBUG
1293  edm::LogVerbatim("HGCalGeom") << "tileCount: lay|rin " << lay << ":" << rin << " kount " << kount;
1294 #endif
1295  }
1296  }
1297  return (3 * kount);
1298 }
1299 
1300 bool HGCalDDDConstants::tileExist(int zside, int layer, int ring, int phi) const {
1301  int indx = HGCalTileIndex::tileIndex(layer, ring, 0);
1302  auto itr = hgpar_->tileInfoMap_.find(indx);
1303  bool ok = (itr == hgpar_->tileInfoMap_.end()) ? false : HGCalTileIndex::tileExist(itr->second.hex, zside, phi);
1304  return ok;
1305 }
1306 
1308  int indx = HGCalTileIndex::tileIndex(layer, ring, 0);
1309  auto itr = hgpar_->tileInfoMap_.find(indx);
1310  return ((itr == hgpar_->tileInfoMap_.end()) ? HGCalParameters::tileInfo() : itr->second);
1311 }
1312 
1313 bool HGCalDDDConstants::tilePhiEdge(double phi, int layer, int iphi) const {
1314  double dif1 = std::abs(phi - hgpar_->scintCellSize(layer) * (iphi - 1));
1315  double dif2 = std::abs(phi - hgpar_->scintCellSize(layer) * iphi);
1316 #ifdef EDM_ML_DEBUG
1317  edm::LogVerbatim("HGCalGeomT") << "HGCalDDDConstants::tilePhiEdge:: input: " << phi << ":" << layer << ":" << iphi
1318  << " Differences " << dif1 << ":" << dif2;
1319 #endif
1320  return ((dif1 < tol_) || (dif2 < tol_));
1321 }
1322 
1323 bool HGCalDDDConstants::tileRingEdge(double r, int layer, int ring) const {
1324  int type = hgpar_->scintType(layer);
1325  double dif1 = std::abs(r - hgpar_->radiusLayer_[type][ring - 1]);
1326  double dif2 = std::abs(r - hgpar_->radiusLayer_[type][ring]);
1327 #ifdef EDM_ML_DEBUG
1328  edm::LogVerbatim("HGCalGeomT") << "HGCalDDDConstants::tileRingEdge:: input: " << r << ":" << layer << ":" << ring
1329  << " Differences " << dif1 << ":" << dif2;
1330 #endif
1331  return ((dif1 < tol_) || (dif2 < tol_));
1332 }
1333 std::pair<int, int> HGCalDDDConstants::tileRings(int layer) const {
1336  int ll = layer - hgpar_->firstLayer_;
1337  if (ll >= 0 && ll < static_cast<int>(hgpar_->tileRingRange_.size()))
1338  return hgpar_->tileRingRange_[ll];
1339  }
1340  return std::make_pair(0, 0);
1341 }
1342 
1343 std::pair<int, int> HGCalDDDConstants::tileType(int layer, int ring, int phi) const {
1344  int indx = HGCalTileIndex::tileIndex(layer, ring, phi);
1345  int type(-1), sipm(-1);
1346  auto itr = hgpar_->tileInfoMap_.find(indx);
1347  if (itr != hgpar_->tileInfoMap_.end()) {
1348  type = 1 + (itr->second).type;
1349  sipm = ((itr->second).sipm == HGCalTypes::SiPMLarge) ? 0 : 1;
1350  }
1351  return std::make_pair(type, sipm);
1352 }
1353 
1355  const int ncopies = hgpar_->waferCopy_.size();
1356  int wafer(ncopies);
1357  bool result(false);
1358  for (int k = 0; k < ncopies; ++k) {
1359  if (copy == hgpar_->waferCopy_[k]) {
1360  wafer = k;
1361  result = true;
1362  break;
1363  }
1364  }
1365  if (!result) {
1366  wafer = -1;
1367 #ifdef EDM_ML_DEBUG
1368  edm::LogVerbatim("HGCalGeom") << "Cannot find " << copy << " in a list of " << ncopies << " members";
1369  for (int k = 0; k < ncopies; ++k)
1370  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << hgpar_->waferCopy_[k];
1371 #endif
1372  }
1373 #ifdef EDM_ML_DEBUG
1374  edm::LogVerbatim("HGCalGeom") << "WaferFromCopy " << copy << ":" << wafer << ":" << result;
1375 #endif
1376  return wafer;
1377 }
1378 
1379 void HGCalDDDConstants::waferFromPosition(const double x, const double y, int& wafer, int& icell, int& celltyp) const {
1380  // Input x, y in Geant4 unit and transformed to CMSSW standard
1383  int size_ = static_cast<int>(hgpar_->waferCopy_.size());
1384  wafer = size_;
1385  for (int k = 0; k < size_; ++k) {
1386  double dx = std::abs(xx - hgpar_->waferPosX_[k]);
1387  double dy = std::abs(yy - hgpar_->waferPosY_[k]);
1388  if (dx <= rmax_ && dy <= hexside_) {
1389  if ((dy <= 0.5 * hexside_) || (dx * tan30deg_ <= (hexside_ - dy))) {
1390  wafer = k;
1391  celltyp = hgpar_->waferTypeT_[k];
1392  xx -= hgpar_->waferPosX_[k];
1393  yy -= hgpar_->waferPosY_[k];
1394  break;
1395  }
1396  }
1397  }
1398  if (wafer < size_) {
1399  if (celltyp - 1 == HGCSiliconDetId::HGCalFine)
1400  icell = cellHex(
1402  else
1403  icell = cellHex(xx,
1404  yy,
1407  hgpar_->cellCoarseY_);
1408  } else {
1409  wafer = -1;
1410 #ifdef EDM_ML_DEBUG
1411  edm::LogWarning("HGCalGeom") << "Cannot get wafer type corresponding to " << x << ":" << y << " " << xx << ":"
1412  << yy;
1413 #endif
1414  }
1415 #ifdef EDM_ML_DEBUG
1416  edm::LogVerbatim("HGCalGeom") << "Position " << x << ":" << y << " Wafer " << wafer << ":" << size_ << " XX " << xx
1417  << ":" << yy << " Cell " << icell << " Type " << celltyp;
1418 #endif
1419 }
1420 
1422  const double y,
1423  const int zside,
1424  const int layer,
1425  int& waferU,
1426  int& waferV,
1427  int& cellU,
1428  int& cellV,
1429  int& celltype,
1430  double& wt,
1431  bool extend,
1432  bool debug) const {
1433  // Expect x, y as in SIM step
1434  waferU = waferV = 1 + hgpar_->waferUVMax_;
1435  cellU = cellV = celltype = 0;
1436  if ((hgpar_->xLayerHex_.empty()) || (hgpar_->yLayerHex_.empty()))
1437  return;
1438  int ll = layer - hgpar_->firstLayer_;
1439  int layertype = layerType(layer);
1440  bool rotx = ((!hgpar_->layerType_.empty()) && (layertype == HGCalTypes::WaferCenterR));
1441  double xx(0), yy(0);
1442  if (rotx) {
1443  std::pair<double, double> xy =
1445  xx = xy.first - hgpar_->xLayerHex_[ll];
1446  yy = xy.second - hgpar_->yLayerHex_[ll];
1447  } else {
1450  }
1451 #ifdef EDM_ML_DEBUG
1452  if (debug)
1453  edm::LogVerbatim("HGCalGeom") << "waferFromPosition:: Layer " << layer << ":" << ll << " Rot " << rotx << " X " << x
1454  << ":" << xx << " Y " << y << ":" << yy;
1455 #endif
1456  double rmax = extend ? rmaxT_ : rmax_;
1457  double hexside = extend ? hexsideT_ : hexside_;
1458  for (unsigned int k = 0; k < hgpar_->waferPosX_.size(); ++k) {
1459  double dx0(0), dy0(0);
1464  auto ktr = hgpar_->waferInfoMap_.find(indx);
1465  if (ktr != hgpar_->waferInfoMap_.end()) {
1466  auto cshift = hgcassette_.getShift(layer, -zside, (ktr->second).cassette);
1467 #ifdef EDM_ML_DEBUG
1468  if (debug)
1469  edm::LogVerbatim("HGCalGeom") << "Cassette " << (ktr->second).cassette << " Shift " << -(zside * cshift.first)
1470  << ":" << cshift.second;
1471 #endif
1472  dx0 = -(zside * cshift.first);
1473  dy0 = cshift.second;
1474  }
1475  }
1476  double dx = std::abs(xx - dx0 - hgpar_->waferPosX_[k]);
1477  double dy = std::abs(yy - dy0 - hgpar_->waferPosY_[k]);
1478  if (dx <= rmax && dy <= hexside) {
1479  if ((dy <= 0.5 * hexside) || (dx * tan30deg_ <= (hexside - dy))) {
1480  if (waferHexagon8File()) {
1483 #ifdef EDM_ML_DEBUG
1484  if (debug)
1485  edm::LogVerbatim("HGCalGeom") << "Position (" << x << ", " << y << ") Wafer type:partial:orient:cassette "
1486  << celltype << ":" << HGCalWaferType::getPartial(index, hgpar_->waferInfoMap_)
1489 #endif
1490  } else {
1492  celltype = ((itr == hgpar_->typesInLayers_.end()) ? HGCSiliconDetId::HGCalCoarseThick
1493  : hgpar_->waferTypeL_[itr->second]);
1494  }
1495 #ifdef EDM_ML_DEBUG
1496  if (debug)
1497  edm::LogVerbatim("HGCalGeom") << "WaferFromPosition:: Input " << layer << ":" << ll << ":"
1498  << hgpar_->firstLayer_ << ":" << rotx << ":" << x << ":" << y << ":"
1499  << hgpar_->xLayerHex_[ll] << ":" << hgpar_->yLayerHex_[ll] << ":" << xx << ":"
1500  << yy << " compared with " << hgpar_->waferPosX_[k] << ":"
1501  << hgpar_->waferPosY_[k] << " difference " << dx << ":" << dy << ":"
1502  << dx * tan30deg_ << ":" << (hexside_ - dy) << " comparator " << rmax_ << ":"
1503  << rmaxT_ << ":" << hexside_ << ":" << hexsideT_ << " wafer " << waferU << ":"
1504  << waferV << ":" << celltype;
1505 #endif
1506  xx -= (dx0 + hgpar_->waferPosX_[k]);
1507  yy -= (dy0 + hgpar_->waferPosY_[k]);
1508  break;
1509  }
1510  }
1511  }
1512  if ((std::abs(waferU) <= hgpar_->waferUVMax_) && (celltype >= 0)) {
1516  auto ktr = hgpar_->waferInfoMap_.find(indx);
1517  if (ktr != hgpar_->waferInfoMap_.end()) {
1518  place = HGCalCell::cellPlacementIndex(1, HGCalTypes::layerFrontBack(layertype), (ktr->second).orient);
1519  part = (ktr->second).part;
1520 #ifdef EDM_ML_DEBUG
1521  if (debug)
1522  edm::LogVerbatim("HGCalGeom") << "waferFromPosition: frontback " << layertype << ":"
1523  << HGCalTypes::layerFrontBack(layertype) << " Orient " << (ktr->second).orient
1524  << " place " << place << " part " << part;
1525 #endif
1526  }
1527  }
1528  cellHex(xx, yy, celltype, place, part, cellU, cellV, extend, debug);
1529  wt = (((celltype < 2) && (hgpar_->useSimWt_ > 0)) ? (hgpar_->cellThickness_[celltype] / hgpar_->waferThick_) : 1.0);
1530  } else {
1531  cellU = cellV = 2 * hgpar_->nCellsFine_;
1532  wt = 1.0;
1533  celltype = -1;
1534  }
1535  if ((celltype < 0) && debug) {
1536  double x1(xx);
1537  double y1(yy);
1538  edm::LogVerbatim("HGCalGeom") << "waferfFromPosition: Bad type for X " << x << ":" << x1 << ":" << xx << " Y " << y
1539  << ":" << y1 << ":" << yy << " Wafer " << waferU << ":" << waferV << " Cell " << cellU
1540  << ":" << cellV;
1541  for (unsigned int k = 0; k < hgpar_->waferPosX_.size(); ++k) {
1542  double dx = std::abs(x1 - hgpar_->waferPosX_[k]);
1543  double dy = std::abs(y1 - hgpar_->waferPosY_[k]);
1544  edm::LogVerbatim("HGCalGeom") << "Wafer [" << k << "] Position (" << hgpar_->waferPosX_[k] << ", "
1545  << hgpar_->waferPosY_[k] << ") difference " << dx << ":" << dy << ":"
1546  << dx * tan30deg_ << ":" << hexside - dy << " Paramerers " << rmax << ":"
1547  << hexside;
1548  }
1549  }
1550  edm::LogVerbatim("HGCalGeomX") << "Input x:y:layer " << x << ":" << y << ":" << layer << " Wafer " << waferU << ":"
1551  << waferV << " Cell " << cellU << ":" << cellV << ":" << celltype << " wt " << wt;
1552 }
1553 
1554 bool HGCalDDDConstants::waferInLayer(int wafer, int lay, bool reco) const {
1555  const auto& indx = getIndex(lay, reco);
1556  if (indx.first < 0)
1557  return false;
1558  return waferInLayerTest(wafer, indx.first, hgpar_->defineFull_);
1559 }
1560 
1561 bool HGCalDDDConstants::waferFullInLayer(int wafer, int lay, bool reco) const {
1562  const auto& indx = getIndex(lay, reco);
1563  if (indx.first < 0)
1564  return false;
1565  return waferInLayerTest(wafer, indx.first, false);
1566 }
1567 
1569  int indx = HGCalWaferIndex::waferIndex(lay, waferU, waferV);
1570  auto itr = hgpar_->waferInfoMap_.find(indx);
1571  return ((itr == hgpar_->waferInfoMap_.end()) ? HGCalParameters::waferInfo() : itr->second);
1572 }
1573 
1574 std::pair<double, double> HGCalDDDConstants::waferParameters(bool reco) const {
1575  if (reco)
1576  return std::make_pair(rmax_, hexside_);
1577  else
1579 }
1580 
1581 std::pair<double, double> HGCalDDDConstants::waferPosition(int wafer, bool reco) const {
1582  double xx(0), yy(0);
1583  if (wafer >= 0 && wafer < static_cast<int>(hgpar_->waferPosX_.size())) {
1584  xx = hgpar_->waferPosX_[wafer];
1585  yy = hgpar_->waferPosY_[wafer];
1586  }
1587  if (!reco) {
1590  }
1591  return std::make_pair(xx, yy);
1592 }
1593 
1594 std::pair<double, double> HGCalDDDConstants::waferPosition(
1595  int lay, int waferU, int waferV, bool reco, bool debug) const {
1596  int ll = lay - hgpar_->firstLayer_;
1597  bool rotx = ((!hgpar_->layerType_.empty()) && (hgpar_->layerType_[ll] == HGCalTypes::WaferCenterR));
1598 #ifdef EDM_ML_DEBUG
1599  if (debug)
1600  edm::LogVerbatim("HGCalGeom") << "Layer " << lay << ":" << ll << " Rotation " << rotx << " U:V " << waferU << ":"
1601  << waferV;
1602 #endif
1603  auto xy = waferPositionNoRot(lay, waferU, waferV, reco, debug);
1604  std::pair<double, double> xy0 = (rotx) ? getXY(lay, xy.first, xy.second, false) : xy;
1605 #ifdef EDM_ML_DEBUG
1606  if (debug)
1607  edm::LogVerbatim("HGCalGeom") << "Without and with rotation " << xy.first << ":" << xy.second << ":" << xy0.first
1608  << ":" << xy0.second;
1609 #endif
1610  return xy0;
1611 }
1612 
1613 int HGCalDDDConstants::waferFileIndex(unsigned int kk) const {
1614  if (kk < hgpar_->waferInfoMap_.size()) {
1615  auto itr = hgpar_->waferInfoMap_.begin();
1616  std::advance(itr, kk);
1617  return itr->first;
1618  } else
1619  return 0;
1620 }
1621 
1622 std::tuple<int, int, int> HGCalDDDConstants::waferFileInfo(unsigned int kk) const {
1623  if (kk < hgpar_->waferInfoMap_.size()) {
1624  auto itr = hgpar_->waferInfoMap_.begin();
1625  std::advance(itr, kk);
1626  return std::make_tuple(itr->second.type, itr->second.part, itr->second.orient);
1627  } else
1628  return std::make_tuple(0, 0, 0);
1629 }
1630 
1631 std::tuple<int, int, int> HGCalDDDConstants::waferFileInfoFromIndex(int kk) const {
1632  auto itr = hgpar_->waferInfoMap_.find(kk);
1633  if (itr != hgpar_->waferInfoMap_.end()) {
1634  return std::make_tuple(itr->second.type, itr->second.part, itr->second.orient);
1635  } else
1636  return std::make_tuple(0, 0, 0);
1637 }
1638 
1640  HepGeom::Point3D<float>& loc, const DetId& id, bool useWafer, bool reco, bool debug) const {
1641  HGCSiliconDetId detid(id);
1642  double x(0), y(0);
1643  if (useWafer) {
1644  auto xyw = waferPositionNoRot(detid.layer(), detid.waferU(), detid.waferV(), reco, debug);
1645  x = xyw.first;
1646  y = xyw.second;
1647  }
1648  auto xy = getXY(detid.layer(), (x + loc.x()), (y + loc.y()), false);
1649  double zz = (detid.zside() < 0) ? -(loc.z() + waferZ(detid.layer(), reco)) : (loc.z() + waferZ(detid.layer(), reco));
1650  double xx = (detid.zside() < 0) ? -xy.first : xy.first;
1651  return GlobalPoint(xx, xy.second, zz);
1652 }
1653 
1655  int wafer(0);
1656  if (!tileTrapezoid()) {
1657  for (unsigned int i = 0; i < layers(true); ++i) {
1658  int lay = hgpar_->depth_[i];
1659  wafer += modules(lay, true);
1660  }
1661  } else {
1662  wafer = static_cast<int>(hgpar_->moduleLayR_.size());
1663  }
1664  return wafer;
1665 }
1666 
1667 int HGCalDDDConstants::wafers(int layer, int type) const {
1668  int wafer(0);
1669  if (!tileTrapezoid()) {
1670  auto itr = waferLayer_.find(layer);
1671  if (itr != waferLayer_.end()) {
1672  unsigned ity = (type > 0 && type <= 2) ? type : 0;
1673  wafer = (itr->second)[ity];
1674  }
1675  } else {
1676  const auto& index = getIndex(layer, true);
1677  wafer = 1 + hgpar_->lastModule_[index.first] - hgpar_->firstModule_[index.first];
1678  }
1679  return wafer;
1680 }
1681 
1682 int HGCalDDDConstants::waferType(DetId const& id, bool fromFile) const {
1683  int type(1);
1684  if (waferHexagon8()) {
1685  if (fromFile && (waferFileSize() > 0)) {
1686  int layer(0), waferU(0), waferV(0);
1687  if (id.det() != DetId::Forward) {
1688  HGCSiliconDetId hid(id);
1689  layer = hid.layer();
1690  waferU = hid.waferU();
1691  waferV = hid.waferV();
1692  } else {
1693  HFNoseDetId hid(id);
1694  layer = hid.layer();
1695  waferU = hid.waferU();
1696  waferV = hid.waferV();
1697  }
1699  if (itr != hgpar_->waferInfoMap_.end())
1700  type = (itr->second).type;
1701  } else {
1702  type = ((id.det() != DetId::Forward) ? HGCSiliconDetId(id).type() : HFNoseDetId(id).type());
1703  }
1704  } else if (waferHexagon6()) {
1705  type = waferTypeL(HGCalDetId(id).wafer()) - 1;
1706  }
1707  return type;
1708 }
1709 
1710 int HGCalDDDConstants::waferType(int layer, int waferU, int waferV, bool fromFile) const {
1712  if (waferHexagon8()) {
1713  if (fromFile && (waferFileSize() > 0)) {
1715  if (itr != hgpar_->waferInfoMap_.end())
1716  type = (itr->second).type;
1717  } else {
1719  if (itr != hgpar_->typesInLayers_.end())
1720  type = hgpar_->waferTypeL_[itr->second];
1721  }
1722  } else if (waferHexagon6()) {
1723  if ((waferU >= 0) && (waferU < static_cast<int>(hgpar_->waferTypeL_.size())))
1724  type = (hgpar_->waferTypeL_[waferU] - 1);
1725  }
1726  return type;
1727 }
1728 
1729 std::tuple<int, int, int> HGCalDDDConstants::waferType(HGCSiliconDetId const& id, bool fromFile) const {
1730  const auto& index = HGCalWaferIndex::waferIndex(id.layer(), id.waferU(), id.waferV());
1731  int type(-1), part(-1), orient(-1);
1732  if (fromFile && (waferFileSize() > 0)) {
1733  auto itr = hgpar_->waferInfoMap_.find(index);
1734  if (itr != hgpar_->waferInfoMap_.end()) {
1735  type = (itr->second).type;
1736  part = (itr->second).part;
1737  orient = (itr->second).orient;
1738  }
1739  } else {
1740  auto ktr = hgpar_->typesInLayers_.find(index);
1741  if (ktr != hgpar_->typesInLayers_.end())
1742  type = hgpar_->waferTypeL_[ktr->second];
1743  auto itr = hgpar_->waferTypes_.find(index);
1744  if (itr != hgpar_->waferTypes_.end()) {
1745  if ((itr->second).second < HGCalTypes::k_OffsetRotation) {
1746  orient = (itr->second).second;
1747  if ((itr->second).first == HGCalGeomTools::k_allCorners) {
1749  } else if ((itr->second).first == HGCalGeomTools::k_fiveCorners) {
1751  } else if ((itr->second).first == HGCalGeomTools::k_fourCorners) {
1753  } else if ((itr->second).first == HGCalGeomTools::k_threeCorners) {
1755  }
1756  } else {
1757  part = (itr->second).first;
1758  orient = ((itr->second).second - HGCalTypes::k_OffsetRotation);
1759  }
1760  } else {
1762  orient = 0;
1763  }
1764  }
1765  return std::make_tuple(type, part, orient);
1766 }
1767 
1769  int layer, int waferU, int waferV, bool fromFile, bool debug) const {
1770  int type(HGCalTypes::WaferOut), rotn(0);
1772  bool withinList(true);
1773  if (fromFile && (waferFileSize() > 0)) {
1774  auto itr = hgpar_->waferInfoMap_.find(wl);
1775  withinList = (itr != hgpar_->waferInfoMap_.end());
1776  if (withinList) {
1777  type = (itr->second).part;
1778  rotn = (itr->second).orient;
1779  }
1780  } else {
1781  auto itr = hgpar_->waferTypes_.find(wl);
1782  if (waferHexagon8()) {
1783  withinList = (itr != hgpar_->waferTypes_.end());
1784  if (withinList) {
1785  if ((itr->second).second < HGCalTypes::k_OffsetRotation) {
1786  rotn = (itr->second).second;
1787  if ((itr->second).first == HGCalGeomTools::k_allCorners) {
1789  } else if ((itr->second).first == HGCalGeomTools::k_fiveCorners) {
1791  } else if ((itr->second).first == HGCalGeomTools::k_fourCorners) {
1793  } else if ((itr->second).first == HGCalGeomTools::k_threeCorners) {
1795  }
1796  } else {
1797  type = (itr->second).first;
1798  rotn = ((itr->second).second - HGCalTypes::k_OffsetRotation);
1799  }
1800  } else {
1802  rotn = HGCalTypes::WaferCorner0;
1803  }
1804  }
1805  }
1806 #ifdef EDM_ML_DEBUG
1807  if (debug)
1808  edm::LogVerbatim("HGCalGeom") << "waferTypeRotation: Layer " << layer << " Wafer " << waferU << ":" << waferV
1809  << " Index " << std::hex << wl << std::dec << ":" << withinList << " Type " << type
1810  << " Rotation " << rotn;
1811 #endif
1812  return std::make_pair(type, rotn);
1813 }
1814 
1816  bool type(false);
1817  if (waferHexagon8()) {
1819  type = (hgpar_->waferTypes_.find(wl) != hgpar_->waferTypes_.end());
1820  } else if (waferHexagon6()) {
1821  int wl = HGCalWaferIndex::waferIndex(layer, waferU, 0, true);
1822  type = (hgpar_->waferTypes_.find(wl) != hgpar_->waferTypes_.end());
1823  }
1824  return type;
1825 }
1826 
1827 double HGCalDDDConstants::waferZ(int lay, bool reco) const {
1828  const auto& index = getIndex(lay, reco);
1829  if (index.first < 0)
1830  return 0;
1831  else
1833 }
1834 
1836  double xx, double yy, const double& cellR, const std::vector<double>& posX, const std::vector<double>& posY) const {
1837  int num(0);
1838  const double tol(0.00001);
1839  double cellY = 2.0 * cellR * tan30deg_;
1840  for (unsigned int k = 0; k < posX.size(); ++k) {
1841  double dx = std::abs(xx - posX[k]);
1842  double dy = std::abs(yy - posY[k]);
1843  if (dx <= (cellR + tol) && dy <= (cellY + tol)) {
1844  double xmax = (dy <= 0.5 * cellY) ? cellR : (cellR - (dy - 0.5 * cellY) / tan30deg_);
1845  if (dx <= (xmax + tol)) {
1846  num = k;
1847  break;
1848  }
1849  }
1850  }
1851  return num;
1852 }
1853 
1855  double xloc, double yloc, int cellType, int place, int part, int& cellU, int& cellV, bool extend, bool debug) const {
1857  auto uv = (part == HGCalTypes::WaferFull)
1858  ? hgcellUV_->cellUVFromXY3(xloc, yloc, place, cellType, true, debug)
1859  : hgcellUV_->cellUVFromXY1(xloc, yloc, place, cellType, part, true, debug);
1860  cellU = uv.first;
1861  cellV = uv.second;
1862  } else if (waferHexagon8File()) {
1863  auto uv = hgcellUV_->cellUVFromXY3(xloc, yloc, place, cellType, extend, debug);
1864  cellU = uv.first;
1865  cellV = uv.second;
1866  } else {
1867  int ncell = (cellType == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
1868  double delY = 2 * rmax_ / (3 * ncell);
1869  double delX = 0.5 * delY * sqrt3_;
1870  double delYT = (extend) ? (2 * rmaxT_ / (3 * ncell)) : delY;
1871  double delXT = 0.5 * delYT * sqrt3_;
1872  double v0 = ((xloc / delY - 1.0) / 1.5);
1873  int cv0 = (v0 > 0) ? (ncell + static_cast<int>(v0 + 0.5)) : (ncell - static_cast<int>(-v0 + 0.5));
1874  double u0 = (0.5 * yloc / delX + 0.5 * cv0);
1875  int cu0 = (u0 > 0) ? (ncell / 2 + static_cast<int>(u0 + 0.5)) : (ncell / 2 - static_cast<int>(-u0 + 0.5));
1876  cu0 = std::max(0, std::min(cu0, 2 * ncell - 1));
1877  cv0 = std::max(0, std::min(cv0, 2 * ncell - 1));
1878  if (cv0 - cu0 >= ncell)
1879  cv0 = cu0 + ncell - 1;
1880  if (debug)
1881  edm::LogVerbatim("HGCalGeom") << "cellHex: input " << xloc << ":" << yloc << ":" << cellType << " parameter "
1882  << delX << ":" << delY << " u0 " << u0 << ":" << cu0 << " v0 " << v0 << ":" << cv0;
1883  bool found(false);
1884  static constexpr int shift[3] = {0, 1, -1};
1885  for (int i1 = 0; i1 < 3; ++i1) {
1886  cellU = cu0 + shift[i1];
1887  for (int i2 = 0; i2 < 3; ++i2) {
1888  cellV = cv0 + shift[i2];
1889  if (((cellV - cellU) < ncell) && ((cellU - cellV) <= ncell) && (cellU >= 0) && (cellV >= 0) &&
1890  (cellU < 2 * ncell) && (cellV < 2 * ncell)) {
1891  double xc = (1.5 * (cellV - ncell) + 1.0) * delY;
1892  double yc = (2 * cellU - cellV - ncell) * delX;
1893  if ((std::abs(yloc - yc) <= delXT) && (std::abs(xloc - xc) <= delYT) &&
1894  ((std::abs(xloc - xc) <= 0.5 * delYT) ||
1895  (std::abs(yloc - yc) <= sqrt3_ * (delYT - std::abs(xloc - xc))))) {
1896  if (debug)
1897  edm::LogVerbatim("HGCalGeom")
1898  << "cellHex: local " << xc << ":" << yc << " difference " << std::abs(xloc - xc) << ":"
1899  << std::abs(yloc - yc) << ":" << sqrt3_ * (delY - std::abs(yloc - yc)) << " comparator " << delX
1900  << ":" << delY << " (u,v) = (" << cellU << "," << cellV << ")";
1901  found = true;
1902  break;
1903  }
1904  }
1905  }
1906  if (found)
1907  break;
1908  }
1909  if (!found) {
1910  cellU = cu0;
1911  cellV = cv0;
1912  }
1913  }
1914 }
1915 
1916 std::pair<int, float> HGCalDDDConstants::getIndex(int lay, bool reco) const {
1917  int indx = layerIndex(lay, reco);
1918  if (indx < 0)
1919  return std::make_pair(-1, 0);
1920  float cell(0);
1921  if (waferHexagon6()) {
1922  cell = (reco ? hgpar_->moduleCellR_[0] : hgpar_->moduleCellS_[0]);
1923  } else {
1924  if (waferHexagon8()) {
1925  cell = (reco ? hgpar_->moduleCellR_[0] : hgpar_->moduleCellS_[0]);
1926  } else {
1927  cell = hgpar_->scintCellSize(lay);
1928  }
1929  }
1930  return std::make_pair(indx, cell);
1931 }
1932 
1934  int ll(-1);
1935  if (waferHexagon6() && reco) {
1936  ll = static_cast<int>(std::find(hgpar_->depthLayerF_.begin(), hgpar_->depthLayerF_.end(), index) -
1937  hgpar_->depthLayerF_.begin());
1938  if (ll == static_cast<int>(hgpar_->depthLayerF_.size()))
1939  ll = -1;
1940  } else {
1941  ll = static_cast<int>(std::find(hgpar_->layerIndex_.begin(), hgpar_->layerIndex_.end(), index) -
1942  hgpar_->layerIndex_.begin());
1943  if (ll == static_cast<int>(hgpar_->layerIndex_.size()))
1944  ll = -1;
1945  }
1946 #ifdef EDM_ML_DEBUG
1947  edm::LogVerbatim("HGCalGeom") << "LayerFromIndex for " << index << ":" << reco << ":" << waferHexagon6() << " is"
1948  << ll << ":" << (ll + hgpar_->firstLayer_);
1949 #endif
1950  return ((ll < 0) ? ll : (ll + hgpar_->firstLayer_));
1951 }
1952 
1953 bool HGCalDDDConstants::isValidCell(int lay, int wafer, int cell) const {
1954  // Calculate the position of the cell
1955  // Works for options HGCalHexagon/HGCalHexagonFull
1956  double x = hgpar_->waferPosX_[wafer];
1957  double y = hgpar_->waferPosY_[wafer];
1958  if (hgpar_->waferTypeT_[wafer] - 1 == HGCSiliconDetId::HGCalFine) {
1959  x += hgpar_->cellFineX_[cell];
1960  y += hgpar_->cellFineY_[cell];
1961  } else {
1962  x += hgpar_->cellCoarseX_[cell];
1963  y += hgpar_->cellCoarseY_[cell];
1964  }
1965  double rr = sqrt(x * x + y * y);
1966  bool result = ((rr >= hgpar_->rMinLayHex_[lay - 1]) && (rr <= hgpar_->rMaxLayHex_[lay - 1]) &&
1967  (wafer < static_cast<int>(hgpar_->waferPosX_.size())));
1968 #ifdef EDM_ML_DEBUG
1969  if (!result)
1970  edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << wafer << ":" << cell << " Position " << x << ":" << y
1971  << ":" << rr << " Compare Limits " << hgpar_->rMinLayHex_[lay - 1] << ":"
1972  << hgpar_->rMaxLayHex_[lay - 1] << " Flag " << result;
1973 #endif
1974  return result;
1975 }
1976 
1977 bool HGCalDDDConstants::isValidCell8(int lay, int waferU, int waferV, int cellU, int cellV, int type) const {
1978  bool result(false);
1979  auto partn = waferTypeRotation(lay, waferU, waferV, false, false);
1980 #ifdef EDM_ML_DEBUG
1981  edm::LogVerbatim("HGCalGeom") << "waferHexagon8 " << waferHexagon8File() << ":" << mode_ << ":"
1982  << HGCalGeometryMode::Hexagon8Cassette << " part " << partn.first << ":"
1983  << partn.second;
1984 #endif
1986  result = HGCalWaferMask::goodCell(cellU, cellV, partn.first);
1987 #ifdef EDM_ML_DEBUG
1988  edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << waferU << ":" << waferV << ":" << cellU << ":" << cellV
1989  << " Result " << result << " from goodCell";
1990 #endif
1991  } else {
1992  float x(0), y(0);
1993  int kndx = cellV * 100 + cellU;
1994  if (type == 0) {
1995  auto ktr = hgpar_->cellFineIndex_.find(kndx);
1996  if (ktr != hgpar_->cellFineIndex_.end()) {
1997  x = hgpar_->cellFineX_[ktr->second];
1998  y = hgpar_->cellFineY_[ktr->second];
1999  }
2000 #ifdef EDM_ML_DEBUG
2001  edm::LogVerbatim("HGCalGeom") << "Fine " << cellU << ":" << cellV << ":" << kndx << ":" << x << ":" << y << ":"
2002  << (ktr != hgpar_->cellFineIndex_.end());
2003 #endif
2004  } else {
2005  auto ktr = hgpar_->cellCoarseIndex_.find(kndx);
2006  if (ktr != hgpar_->cellCoarseIndex_.end()) {
2007  x = hgpar_->cellCoarseX_[ktr->second];
2008  y = hgpar_->cellCoarseY_[ktr->second];
2009  }
2010 #ifdef EDM_ML_DEBUG
2011  edm::LogVerbatim("HGCalGeom") << "Coarse " << cellU << ":" << cellV << ":" << kndx << ":" << x << ":" << y << ":"
2012  << (ktr != hgpar_->cellCoarseIndex_.end());
2013 #endif
2014  }
2015  const auto& xy = waferPositionNoRot(lay, waferU, waferV, true, false);
2016  x += xy.first;
2017  y += xy.second;
2018 #ifdef EDM_ML_DEBUG
2019  edm::LogVerbatim("HGCalGeom") << "With wafer (" << waferU << "," << waferV << ") " << x << ":" << y;
2020 #endif
2021  double rr = sqrt(x * x + y * y);
2022  int ll = lay - hgpar_->firstLayer_;
2023  double tol = waferHexagon8File() ? 0.5 : 0.0;
2024  result = (((rr + tol) >= hgpar_->rMinLayHex_[ll]) && (rr <= hgpar_->rMaxLayHex_[ll]));
2025 #ifdef EDM_ML_DEBUG
2026  edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << ll << ":" << waferU << ":" << waferV << ":" << cellU
2027  << ":" << cellV << " Position " << x << ":" << y << ":" << rr << " Compare Limits "
2028  << hgpar_->rMinLayHex_[ll] << ":" << hgpar_->rMaxLayHex_[ll] << " Flag " << result
2029  << " from Radius Limits";
2030 #endif
2031  if (result && waferHexagon8File()) {
2032  int N = (type == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
2033  result = HGCalWaferMask::goodCell(cellU, cellV, N, partn.first, partn.second);
2034 #ifdef EDM_ML_DEBUG
2035  edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << waferU << ":" << waferV << ":" << cellU << ":" << cellV
2036  << " N " << N << " part " << partn.first << ":" << partn.second << " Result "
2037  << result << " from goodCell";
2038 #endif
2039  }
2040  }
2041  return result;
2042 }
2043 
2044 int32_t HGCalDDDConstants::waferIndex(int wafer, int index) const {
2045  int layer = layerFromIndex(index, true);
2049 #ifdef EDM_ML_DEBUG
2050  edm::LogVerbatim("HGCalGeom") << "WaferIndex for " << wafer << ":" << index << " (" << layer << ":" << waferU << ":"
2051  << waferV << ") " << indx;
2052 #endif
2053  return indx;
2054 }
2055 
2056 bool HGCalDDDConstants::waferInLayerTest(int wafer, int lay, bool full) const {
2057  bool in = (waferHexagon6()) ? true : false;
2058  if (!in) {
2059  double xpos = hgpar_->waferPosX_[wafer] + hgpar_->xLayerHex_[lay];
2060  double ypos = hgpar_->waferPosY_[wafer] + hgpar_->yLayerHex_[lay];
2061  std::pair<int, int> corner = HGCalGeomTools::waferCorner(
2062  xpos, ypos, rmax_, hexside_, hgpar_->rMinLayHex_[lay], hgpar_->rMaxLayHex_[lay], in);
2063  in = (full ? (corner.first > 0) : (corner.first == static_cast<int>(HGCalParameters::k_CornerSize)));
2064  if (in && fullAndPart_) {
2065  int indx = waferIndex(wafer, lay);
2066  in = (hgpar_->waferInfoMap_.find(indx) != hgpar_->waferInfoMap_.end());
2067 #ifdef EDM_ML_DEBUG
2068  if (!in)
2069  edm::LogVerbatim("HGCalGeom") << "WaferInLayerTest: Layer " << lay << " wafer " << wafer << " index " << indx
2070  << "( " << HGCalWaferIndex::waferLayer(indx) << ", "
2071  << HGCalWaferIndex::waferU(indx) << ", " << HGCalWaferIndex::waferV(indx)
2072  << ") in " << in;
2073 #endif
2074  }
2075 #ifdef EDM_ML_DEBUG
2076  edm::LogVerbatim("HGCalGeom") << "WaferInLayerTest: Layer " << lay << " wafer " << wafer << " R-limits "
2077  << hgpar_->rMinLayHex_[lay] << ":" << hgpar_->rMaxLayHex_[lay] << " Corners "
2078  << corner.first << ":" << corner.second << " In " << in;
2079 #endif
2080  }
2081  return in;
2082 }
2083 
2084 std::pair<double, double> HGCalDDDConstants::waferPositionNoRot(
2085  int lay, int waferU, int waferV, bool reco, bool debug) const {
2086  int ll = lay - hgpar_->firstLayer_;
2087  double x = hgpar_->xLayerHex_[ll];
2088  double y = hgpar_->yLayerHex_[ll];
2089 #ifdef EDM_ML_DEBUG
2090  if (debug)
2091  edm::LogVerbatim("HGCalGeom") << "Layer " << lay << ":" << ll << " Shift " << hgpar_->xLayerHex_[ll] << ":"
2092  << hgpar_->yLayerHex_[ll] << " U:V " << waferU << ":" << waferV;
2093 #endif
2094  if (!reco) {
2097  }
2098  const auto& xy = waferPosition(waferU, waferV, reco);
2099  x += xy.first;
2100  y += xy.second;
2101 #ifdef EDM_ML_DEBUG
2102  if (debug)
2103  edm::LogVerbatim("HGCalGeom") << "With wafer " << x << ":" << y << ":" << xy.first << ":" << xy.second;
2104 #endif
2105  return std::make_pair(x, y);
2106 }
2107 
2108 std::pair<double, double> HGCalDDDConstants::waferPosition(int waferU, int waferV, bool reco) const {
2109  double xx(0), yy(0);
2110  int indx = HGCalWaferIndex::waferIndex(0, waferU, waferV);
2111  auto itr = hgpar_->wafersInLayers_.find(indx);
2112  if (itr != hgpar_->wafersInLayers_.end()) {
2113  xx = hgpar_->waferPosX_[itr->second];
2114  yy = hgpar_->waferPosY_[itr->second];
2115  }
2116  if (!reco) {
2119  }
2120  return std::make_pair(xx, yy);
2121 }
2122 
2124 
std::vector< int > iradMaxBH_
bool maskCell(const DetId &id, int corners) 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
bool cassetteShiftScintillator(int layer, int iphi) const
static int32_t cellPlacementIndex(int32_t iz, int32_t frontBack, int32_t orient)
Definition: HGCalCell.cc:233
static constexpr double tol_
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:245
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
bool tileRingEdge(double rho, int layer, int ring) const
static bool goodCell(int u, int v, int N, int type, int rotn)
static constexpr int32_t WaferOut
Definition: HGCalTypes.h:56
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
std::pair< int, int > waferTypeRotation(int layer, int waferU, int waferV, bool fromFile, bool debug) 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
bool isValidHex8(int lay, int waferU, int waferV, bool fullAndPart) 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:26
hgtrform getTrForm(unsigned int k) const
static constexpr uint32_t k_CornerSize
std::pair< double, double > getRangeR(int, bool reco) const
static int getOrient(int index, const HGCalParameters::waferInfo_map &wafers)
wafer_map wafersInLayers_
bool waferInLayer(int wafer, int lay, bool reco) const
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
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
dif1
Definition: cuy.py:893
bool isHalfCell(int waferType, int cell) const
int maxCells(bool reco) const
std::vector< double > cellSize_
std::vector< int > waferUVMaxLayer_
std::array< int, 5 > assignCellHex(float x, float y, int zside, int lay, bool reco, bool extend, bool debug) const
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
bool cassetteShiftSilicon(int layer, int waferU, int waferV) const
std::vector< double > rMaxFront_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Definition: GenABIO.cc:168
bool cellInLayer(int waferU, int waferV, int cellU, int cellV, int lay, int zside, bool reco) 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
bool tilePhiEdge(double phi, int layer, int iphi) const
std::pair< float, float > locateCellTrap(int zside, int lay, int ieta, int iphi, bool reco, bool debug) 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
dif2
Definition: cuy.py:895
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_
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
#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_
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
int waferType(DetId const &id, bool fromFile) const
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
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_
int cassetteTile(int iphi) 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
std::pair< float, float > localToGlobal8(int zside, int lay, int waferU, int waferV, double localX, double localY, bool reco, bool debug) const
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_
std::pair< double, double > waferPositionNoRot(int lay, int waferU, int waferV, bool reco, bool debug) const
static int32_t layerFrontBack(int32_t layerOrient)
Definition: HGCalTypes.h:125
void setParameter(int cassette, const std::vector< double > &shifts)
Definition: HGCalCassette.cc:8
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)