CMS 3D CMS Logo

HGCalDDDConstants.cc
Go to the documentation of this file.
2 
12 
13 #include "CLHEP/Units/GlobalPhysicalConstants.h"
14 #include "CLHEP/Units/GlobalSystemOfUnits.h"
15 
16 #include <algorithm>
17 #include <functional>
18 #include <numeric>
19 
20 //#define EDM_ML_DEBUG
21 
22 static const int maxType = 2;
23 static const int minType = 0;
24 
26  const std::string& name) : hgpar_(hp),
27  sqrt3_(std::sqrt(3.0)) {
28  mode_ = hgpar_->mode_;
34  std::cos(30.0*CLHEP::deg));
35  hexside_ = 2.0 * rmax_ * tan30deg_;
36 #ifdef EDM_ML_DEBUG
37  edm::LogVerbatim("HGCalGeom") << "rmax_ " << rmax_ << ":" << hexside_
38  << " CellSize " << 0.5*HGCalParameters::k_ScaleFromDDD*hgpar_->cellSize_[0]
40 #endif
41  }
42  // init maps and constants
43  modHalf_ = 0;
45  for (int simreco = 0; simreco < 2; ++simreco) {
46  tot_layers_[simreco] = layersInit((bool)simreco);
47  max_modules_layer_[simreco].resize(tot_layers_[simreco]+1);
48  for (unsigned int layer=1; layer <= tot_layers_[simreco]; ++layer) {
49  max_modules_layer_[simreco][layer] = modulesInit(layer,(bool)simreco);
50  if (simreco == 1) {
51  modHalf_ += max_modules_layer_[simreco][layer];
53  max_modules_layer_[simreco][layer]);
54 #ifdef EDM_ML_DEBUG
55  edm::LogVerbatim("HGCalGeom") << "Layer " << layer << " with "
56  << max_modules_layer_[simreco][layer]
57  << ":" << modHalf_ << " modules";
58 #endif
59  }
60  }
61  }
62  tot_wafers_ = wafers();
63 
64 #ifdef EDM_ML_DEBUG
65  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants initialized for "
66  << name << " with " << layers(false) << ":"
67  << layers(true) << " layers, " << wafers()
68  << ":" << 2*modHalf_ << " wafers with maximum "
69  << maxWafersPerLayer_ << " per layer and "
70  << "maximum of " << maxCells(false) << ":"
71  << maxCells(true) << " cells";
72 #endif
77  int wminT(9999999), wmaxT(-9999999), kount1(0), kount2(0);
78  for (unsigned int i=0; i<getTrFormN(); ++i) {
79  int lay0 = getTrForm(i).lay;
80  int wmin(9999999), wmax(-9999999), kount(0);
81  for (int wafer=0; wafer<sectors(); ++wafer) {
82  bool waferIn = waferInLayer(wafer,lay0,true);
86  waferIn_[kndx] = waferIn;
87  }
88  if (waferIn) {
89  int waferU = (((mode_ == HGCalGeometryMode::Hexagon) ||
92  if (waferU < wmin) wmin = waferU;
93  if (waferU > wmax) wmax = waferU;
94  ++kount;
95  }
96  }
97  if (wminT > wmin) wminT = wmin;
98  if (wmaxT < wmax) wmaxT = wmax;
99  if (kount1 < kount) kount1= kount;
100  kount2 += kount;
101 #ifdef EDM_ML_DEBUG
102  int lay1 = getIndex(lay0,true).first;
103  edm::LogVerbatim("HGCalGeom") << "Index " << i << " Layer " << lay0
104  << ":" << lay1 << " Wafer " << wmin
105  << ":" << wmax << ":" << kount;
106 #endif
107  HGCWaferParam a1{ {wmin,wmax,kount} };
108  waferLayer_[lay0] = a1;
109  }
110  waferMax_ = std::array<int,4>{ {wminT,wmaxT,kount1,kount2} };
111 #ifdef EDM_ML_DEBUG
112  edm::LogVerbatim("HGCalGeom") << "Overall wafer statistics: " << wminT
113  << ":" << wmaxT << ":" << kount1 << ":"
114  << kount2;
115 #endif
116  }
117 }
118 
120 
121 std::pair<int,int> HGCalDDDConstants::assignCell(float x, float y, int lay,
122  int subSec, bool reco) const {
123  const auto & index = getIndex(lay, reco);
124  if (index.first < 0) return std::make_pair(-1,-1);
127  float xx = (reco) ? x : HGCalParameters::k_ScaleFromDDD*x;
128  float yy = (reco) ? y : HGCalParameters::k_ScaleFromDDD*y;
129 
130  //First the wafer
131  int wafer = cellHex(xx, yy, rmax_, hgpar_->waferPosX_, hgpar_->waferPosY_);
132  if (wafer < 0 || wafer >= (int)(hgpar_->waferTypeT_.size())) {
133  edm::LogWarning("HGCalGeom") << "Wafer no. out of bound for " << wafer
134  << ":" << (hgpar_->waferTypeT_).size()
135  << ":" << (hgpar_->waferPosX_).size()
136  << ":" << (hgpar_->waferPosY_).size()
137  << " ***** ERROR *****";
138  return std::make_pair(-1,-1);
139  } else {
140  // Now the cell
141  xx -= hgpar_->waferPosX_[wafer];
142  yy -= hgpar_->waferPosY_[wafer];
143  if (hgpar_->waferTypeT_[wafer] == 1)
144  return std::make_pair(wafer,cellHex(xx, yy,
147  else
148  return std::make_pair(wafer,cellHex(xx, yy,
151  }
152  } else {
153  return std::make_pair(-1,-1);
154  }
155 }
156 
157 std::array<int,5> HGCalDDDConstants::assignCellHex(float x, float y, int lay,
158  bool reco) const {
159  int waferU(0), waferV(0), waferType(-1), cellU(0), cellV(0);
162  double xx = (reco) ? HGCalParameters::k_ScaleToDDD*x : x;
163  double yy = (reco) ? HGCalParameters::k_ScaleToDDD*y : y;
164  double wt(1.0);
165  waferFromPosition(xx,yy,lay,waferU,waferV,cellU,cellV,waferType,wt);
166  }
167  return std::array<int,5>{ {waferU,waferV,waferType,cellU,cellV} };
168 }
169 
170 std::array<int,3> HGCalDDDConstants::assignCellTrap(float x, float y,
171  float z, int layer,
172  bool reco) const {
173 
174  int irad(-1), iphi(-1), type(-1);
175  const auto & indx = getIndex(layer,reco);
176  if (indx.first < 0) return std::array<int,3>{ {irad,iphi,type} };
177  double xx = (z > 0) ? x : -x;
178  double r = (reco ? std::sqrt(x*x+y*y) :
180  double phi = (r == 0. ? 0. : std::atan2(y,xx));
181  if (phi < 0) phi += (2.0*M_PI);
182  type = hgpar_->scintType(layer);
183  auto ir = std::lower_bound(hgpar_->radiusLayer_[type].begin(),
184  hgpar_->radiusLayer_[type].end(), r);
185  irad = (int)(ir - hgpar_->radiusLayer_[type].begin());
186  irad = std::min(std::max(irad,hgpar_->iradMinBH_[indx.first]),
187  hgpar_->iradMaxBH_[indx.first]);
188  iphi = 1 + (int)(phi/indx.second);
189 #ifdef EDM_ML_DEBUG
190  edm::LogVerbatim("HGCalGeom") << "assignCellTrap Input " << x << ":" << y
191  << ":" << z << ":" << layer << ":" << reco
192  << " x|r " << xx << ":" << r << " phi "
193  << phi << " o/p " << irad << ":" << iphi
194  << ":" << type;
195 #endif
196  return std::array<int,3>{ {irad,iphi,type} };
197 }
198 
199 bool HGCalDDDConstants::cellInLayer(int waferU, int waferV, int cellU,
200  int cellV, int lay, bool reco) const {
201  const auto & indx = getIndex(lay,true);
202  if (indx.first >= 0) {
207  const auto & xy = ((mode_ == HGCalGeometryMode::Hexagon8) ||
209  locateCell(lay, waferU, waferV, cellU, cellV, reco, true, false) :
210  locateCell(cellU, lay, waferU, reco);
211  double rpos = sqrt(xy.first*xy.first + xy.second*xy.second);
212  return ((rpos >= hgpar_->rMinLayHex_[indx.first]) &&
213  (rpos <= hgpar_->rMaxLayHex_[indx.first]));
214  } else {
215  return true;
216  }
217  } else {
218  return false;
219  }
220 }
221 
222 double HGCalDDDConstants::cellThickness(int layer, int waferU,
223  int waferV) const {
224 
225  double thick(-1);
228  auto itr = hgpar_->typesInLayers_.find(HGCalWaferIndex::waferIndex(layer,waferU,waferV));
229  int type = ((itr == hgpar_->typesInLayers_.end() ? maxType :
230  hgpar_->waferTypeL_[itr->second]));
231  thick = 10000.0*hgpar_->cellThickness_[type];
232  } else if ((mode_ == HGCalGeometryMode::Hexagon) ||
234  int type = (((waferU>=0)&&(waferU<(int)(hgpar_->waferTypeL_.size()))) ?
235  hgpar_->waferTypeL_[waferU] : minType);
236  thick = 100.0*type;
237  }
238  return thick;
239 }
240 
242  int indx = (((mode_ == HGCalGeometryMode::Hexagon8) ||
244  ((type >= 1) ? 1 : 0) : ((type == 1) ? 0 : 1));
245  double cell = (0.5*HGCalParameters::k_ScaleFromDDD*hgpar_->cellSize_[indx]);
246  return cell;
247 }
248 
249 double HGCalDDDConstants::distFromEdgeHex(double x, double y, double z) const {
250 
251  //Assming the point is within a hexagonal plane of the wafer, calculate
252  //the shortest distance from the edge
253  if (z < 0) x = -x;
254  double dist(0);
255  //Input x, y in Geant4 unit and transformed to CMSSW standard
258  int sizew = (int)(hgpar_->waferPosX_.size());
259  int wafer = sizew;
260  //Transform to the local coordinate frame of the wafer first
261  for (int k=0; k<sizew; ++k) {
262  double dx = std::abs(xx-hgpar_->waferPosX_[k]);
263  double dy = std::abs(yy-hgpar_->waferPosY_[k]);
264  if (dx <= rmax_ && dy <= hexside_ &&
265  ((dy <= 0.5*hexside_) || (dx*tan30deg_ <= (hexside_-dy)))) {
266  wafer = k;
267  xx -= hgpar_->waferPosX_[k];
268  yy -= hgpar_->waferPosY_[k];
269  break;
270  }
271  }
272  //Look at only one quarter (both x,y are positive)
273  if (wafer < sizew) {
274  if (std::abs(yy) < 0.5*hexside_) {
275  dist = rmax_ - std::abs(xx);
276  } else {
277  dist = 0.5*((rmax_-std::abs(xx))-sqrt3_*(std::abs(yy)-0.5*hexside_));
278  }
279  } else {
280  dist = 0;
281  }
283 #ifdef EDM_ML_DEBUG
284  edm::LogVerbatim("HGCalGeom") << "DistFromEdgeHex: Local " << xx << ":"
285  << yy << " wafer " << wafer << " flag "
286  << (wafer < sizew) << " Distance " << rmax_
287  << ":" << (rmax_-std::abs(xx)) << ":"
288  << (std::abs(yy)-0.5*hexside_) << ":"
289  << 0.5*hexside_ << ":" << dist;
290 #endif
291  return dist;
292 }
293 
294 double HGCalDDDConstants::distFromEdgeTrap(double x, double y, double z) const {
295 
296  //Assming the point is within the eta-phi plane of the scintillator tile,
297  //calculate the shortest distance from the edge
298  int lay = getLayer(z,false);
299  double xx = (z < 0) ? -x : x;
300  int indx = layerIndex(lay,false);
301  double r = HGCalParameters::k_ScaleFromDDD*std::sqrt(x*x+y*y);
302  double phi = (r == 0. ? 0. : std::atan2(y,xx));
303  if (phi < 0) phi += (2.0*M_PI);
304  int type = hgpar_->scintType(lay);
305  double cell = hgpar_->scintCellSize(lay);
306  //Compare with the center of the tile find distances along R and also phi
307  //Take the smaller value
308  auto ir = std::lower_bound(hgpar_->radiusLayer_[type].begin(),
309  hgpar_->radiusLayer_[type].end(), r);
310  int irad = (int)(ir-hgpar_->radiusLayer_[type].begin());
311  if (irad < hgpar_->iradMinBH_[indx]) irad = hgpar_->iradMinBH_[indx];
312  else if (irad > hgpar_->iradMaxBH_[indx]) irad = hgpar_->iradMaxBH_[indx];
313  int iphi = 1 + (int)(phi/cell);
314  double dphi = std::max(0.0,(0.5*cell-std::abs(phi-(iphi-0.5)*cell)));
315  double dist = std::min((r-hgpar_->radiusLayer_[type][irad-1]),
316  (hgpar_->radiusLayer_[type][irad]-r));
317 #ifdef EDM_ML_DEBUG
318  edm::LogVerbatim("HGCalGeom") << "DistFromEdgeTrap: Global " << x << ":"
319  << y << ":" << z << " Layer " << lay
320  << " Index " << indx << ":" << type << " xx "
321  << xx << " R " << r << ":" << irad << ":"
322  << hgpar_->radiusLayer_[type][irad-1] << ":"
323  << hgpar_->radiusLayer_[type][irad]
324  << " Phi " << phi << ":" << iphi << ":"
325  << (iphi-0.5)*cell << " cell " << cell
326  << " Dphi " << dphi << " Dist " << dist
327  << ":" << r*dphi;
328 #endif
329  return HGCalParameters::k_ScaleToDDD*std::min(r*dphi,dist);
330 }
331 
332 int HGCalDDDConstants::getLayer(double z, bool reco) const {
333 
334  //Get the layer # from the gloabl z coordinate
335  unsigned int k = 0;
336  double zz = (reco ? std::abs(z) :
338  const auto& zLayerHex = hgpar_->zLayerHex_;
339  std::find_if(zLayerHex.begin()+1,zLayerHex.end(),[&k,&zz,&zLayerHex](double zLayer){ ++k; return zz < 0.5*(zLayerHex[k-1]+zLayerHex[k]);});
340  int lay = k;
341  if (((mode_ == HGCalGeometryMode::Hexagon) ||
343  int indx = layerIndex(lay,false);
344  if (indx >= 0) lay = hgpar_->layerGroup_[indx];
345  } else {
346  lay += (hgpar_->firstLayer_ - 1);
347  }
348  return lay;
349 }
350 
352  bool hexType,
353  bool reco) const {
354 
356  if (hexType) {
357  if (indx >= hgpar_->waferTypeL_.size())
358  edm::LogWarning("HGCalGeom") << "Wafer no. out bound for index " << indx
359  << ":" << (hgpar_->waferTypeL_).size()
360  << ":" << (hgpar_->waferPosX_).size()
361  << ":" << (hgpar_->waferPosY_).size()
362  << " ***** ERROR *****";
363  unsigned int type = (indx < hgpar_->waferTypeL_.size()) ?
364  hgpar_->waferTypeL_[indx] : 3;
365  if (type > 0) --type;
366  mytr = hgpar_->getModule(type, reco);
367  } else {
368  mytr = hgpar_->getModule(indx,reco);
369  }
370  return mytr;
371 }
372 
373 std::vector<HGCalParameters::hgtrap> HGCalDDDConstants::getModules() const {
374 
375  std::vector<HGCalParameters::hgtrap> mytrs;
376  for (unsigned int k=0; k<hgpar_->moduleLayR_.size(); ++k)
377  mytrs.emplace_back(hgpar_->getModule(k,true));
378  return mytrs;
379 }
380 
381 std::vector<HGCalParameters::hgtrform> HGCalDDDConstants::getTrForms() const {
382 
383  std::vector<HGCalParameters::hgtrform> mytrs;
384  for (unsigned int k=0; k<hgpar_->trformIndex_.size(); ++k)
385  mytrs.emplace_back(hgpar_->getTrForm(k));
386  return mytrs;
387 }
388 
389 int HGCalDDDConstants::getTypeTrap(int layer) const {
390  //Get the module type for scinitllator
392  return hgpar_->scintType(layer);
393  } else {
394  return -1;
395  }
396 }
397 
398 int HGCalDDDConstants::getTypeHex(int layer, int waferU, int waferV) const {
399  //Get the module type for a silicon wafer
402  auto itr = hgpar_->typesInLayers_.find(HGCalWaferIndex::waferIndex(layer,waferU,waferV));
403  return ((itr == hgpar_->typesInLayers_.end() ? 2 :
404  hgpar_->waferTypeL_[itr->second]));
405  } else {
406  return -1;
407  }
408 }
409 
410 bool HGCalDDDConstants::isHalfCell(int waferType, int cell) const {
411  if (waferType < 1 || cell < 0) return false;
412  return waferType == 2 ? hgpar_->cellCoarseHalf_[cell] : hgpar_->cellFineHalf_[cell];
413 }
414 
415 bool HGCalDDDConstants::isValidHex(int lay, int mod, int cell,
416  bool reco) const {
417  //Check validity for a layer|wafer|cell of pre-TDR version
418  bool result(false), resultMod(false);
419  int cellmax(0);
422  int32_t copyNumber = hgpar_->waferCopy_[mod];
423  result = ((lay > 0 && lay <= (int)(layers(reco))));
424  if (result) {
425  const int32_t lay_idx = reco ? (lay-1)*3 + 1 : lay;
426  const auto& the_modules = hgpar_->copiesInLayers_[lay_idx];
427  auto moditr = the_modules.find(copyNumber);
428  result = resultMod = (moditr != the_modules.end());
429 #ifdef EDM_ML_DEBUG
430  if (!result)
431  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants: Layer " << lay
432  << ":" << lay_idx << " Copy "
433  << copyNumber << ":" << mod
434  << " Flag " << result;
435 #endif
436  if (result) {
437  if (moditr->second >= 0) {
438  if (mod >= (int)(hgpar_->waferTypeT_.size()))
439  edm::LogWarning("HGCalGeom") << "Module no. out of bound for "
440  << mod << " to be compared with "
441  << (hgpar_->waferTypeT_).size()
442  << " ***** ERROR *****";
443  cellmax = (hgpar_->waferTypeT_[mod]==1) ?
444  (int)(hgpar_->cellFineX_.size()) : (int)(hgpar_->cellCoarseX_.size());
445  result = (cell >=0 && cell <= cellmax);
446  } else {
447  result = isValidCell(lay_idx, mod, cell);
448  }
449  }
450  }
451  }
452 
453 #ifdef EDM_ML_DEBUG
454  if (!result)
455  edm::LogVerbatim("HGCalGeom") << "HGCalDDDConstants: Layer " << lay << ":"
456  << (lay > 0 && (lay <= (int)(layers(reco))))
457  << " Module " << mod << ":" << resultMod
458  << " Cell " << cell << ":" << cellmax << ":"
459  << (cell >=0 && cell <= cellmax)
460  << ":" << maxCells(reco);
461 #endif
462  return result;
463 }
464 
465 bool HGCalDDDConstants::isValidHex8(int layer, int modU, int modV, int cellU,
466  int cellV) const {
467  //Check validity for a layer|wafer|cell of post-TDR version
468  int indx = HGCalWaferIndex::waferIndex(layer,modU,modV);
469  auto itr = hgpar_->typesInLayers_.find(indx);
470  if (itr == hgpar_->typesInLayers_.end()) return false;
471  auto jtr = waferIn_.find(indx);
472  if (!(jtr->second)) return false;
473  int N = ((hgpar_->waferTypeL_[itr->second] == 0) ? hgpar_->nCellsFine_ :
475  if ((cellU >= 0) && (cellU < 2*N) && (cellV >= 0) && (cellV < 2*N)) {
476  return (((cellV-cellU) < N) && ((cellU-cellV) <= N));
477  } else {
478  return false;
479  }
480 }
481 
482 bool HGCalDDDConstants::isValidTrap(int layer, int irad, int iphi) const {
483  //Check validity for a layer|eta|phi of scintillator
484  const auto & indx = getIndex(layer,true);
485  if (indx.first < 0) return false;
486  return ((irad >= hgpar_->iradMinBH_[indx.first]) &&
487  (irad <= hgpar_->iradMaxBH_[indx.first]) &&
488  (iphi > 0) && (iphi <= hgpar_->scintCells(layer)));
489 }
490 
491 unsigned int HGCalDDDConstants::layers(bool reco) const {
492  return tot_layers_[(int)reco];
493 }
494 
495 int HGCalDDDConstants::layerIndex(int lay, bool reco) const {
496  int ll = lay - hgpar_->firstLayer_;
497  if (ll<0 || ll>=(int)(hgpar_->layerIndex_.size())) return -1;
500  if (reco && ll>=(int)(hgpar_->depthIndex_.size())) return -1;
501  return (reco ? hgpar_->depthLayerF_[ll] : hgpar_->layerIndex_[ll]);
502  } else {
503  return (hgpar_->layerIndex_[ll]);
504  }
505 }
506 
507 unsigned int HGCalDDDConstants::layersInit(bool reco) const {
508  return (reco ? hgpar_->depthIndex_.size() : hgpar_->layerIndex_.size());
509 }
510 
511 std::pair<float,float> HGCalDDDConstants::locateCell(int cell, int lay,
512  int type, bool reco) const {
513  // type refers to wafer # for hexagon cell
514  float x(999999.), y(999999.);
515  const auto & index = getIndex(lay, reco);
516  int i = index.first;
517  if (i < 0) return std::make_pair(x,y);
520  x = hgpar_->waferPosX_[type];
521  y = hgpar_->waferPosY_[type];
522  if (hgpar_->waferTypeT_[type] == 1) {
523  x += hgpar_->cellFineX_[cell];
524  y += hgpar_->cellFineY_[cell];
525  } else {
526  x += hgpar_->cellCoarseX_[cell];
527  y += hgpar_->cellCoarseY_[cell];
528  }
529  if (!reco) {
532  }
533  }
534  return std::make_pair(x,y);
535 }
536 
537 std::pair<float,float> HGCalDDDConstants::locateCell(int lay, int waferU,
538  int waferV, int cellU,
539  int cellV, bool reco,
540  bool all, bool
541 #ifdef EDM_ML_DEBUG
542  debug
543 #endif
544  ) const {
545 
546  float x(0), y(0);
547  int indx = HGCalWaferIndex::waferIndex(lay,waferU,waferV);
548  auto itr = hgpar_->typesInLayers_.find(indx);
549  int type = ((itr == hgpar_->typesInLayers_.end()) ? 2 :
550  hgpar_->waferTypeL_[itr->second]);
551 #ifdef EDM_ML_DEBUG
552  if (debug)
553  edm::LogVerbatim("HGCalGeom") << "LocateCell " << lay << ":" << waferU
554  << ":" << waferV << ":" << indx << ":"
555  << (itr == hgpar_->typesInLayers_.end())
556  << ":" << type;
557 #endif
558  int kndx = cellV*100 + cellU;
559  if (type == 0) {
560  auto ktr = hgpar_->cellFineIndex_.find(kndx);
561  if (ktr != hgpar_->cellFineIndex_.end()) {
562  x = hgpar_->cellFineX_[ktr->second];
563  y = hgpar_->cellFineY_[ktr->second];
564  }
565 #ifdef EDM_ML_DEBUG
566  if (debug)
567  edm::LogVerbatim("HGCalGeom") << "Fine " << cellU << ":" << cellV << ":"
568  << kndx << ":" << x << ":" << y << ":"
569  << (ktr != hgpar_->cellFineIndex_.end());
570 #endif
571  } else {
572  auto ktr = hgpar_->cellCoarseIndex_.find(kndx);
573  if (ktr != hgpar_->cellCoarseIndex_.end()) {
574  x = hgpar_->cellCoarseX_[ktr->second];
575  y = hgpar_->cellCoarseY_[ktr->second];
576  }
577 #ifdef EDM_ML_DEBUG
578  if (debug)
579  edm::LogVerbatim("HGCalGeom") << "Coarse " << cellU << ":" << cellV <<":"
580  << kndx << ":" << x << ":" << y << ":"
581  << (ktr != hgpar_->cellCoarseIndex_.end());
582 #endif
583  }
584  if (!reco) {
587  }
588  if (all) {
589  const auto & xy = waferPosition(waferU, waferV, reco);
590  x += xy.first;
591  y += xy.second;
592 #ifdef EDM_ML_DEBUG
593  if (debug)
594  edm::LogVerbatim("HGCalGeom") << "With wafer " << x << ":" << y << ":"
595  << xy.first << ":" << xy.second;
596 #endif
597  }
598  return std::make_pair(x,y);
599 }
600 
601 std::pair<float,float> HGCalDDDConstants::locateCellHex(int cell, int wafer,
602  bool reco) const {
603  float x(0), y(0);
604  if (hgpar_->waferTypeT_[wafer] == 1) {
605  x = hgpar_->cellFineX_[cell];
606  y = hgpar_->cellFineY_[cell];
607  } else {
608  x = hgpar_->cellCoarseX_[cell];
609  y = hgpar_->cellCoarseY_[cell];
610  }
611  if (!reco) {
614  }
615  return std::make_pair(x,y);
616 }
617 
618 std::pair<float,float> HGCalDDDConstants::locateCellTrap(int lay, int irad,
619  int iphi, bool reco) const {
620 
621  float x(0), y(0);
622  const auto & indx = getIndex(lay,reco);
623  if (indx.first >= 0) {
624  int ir = std::abs(irad);
625  int type = hgpar_->scintType(lay);
626  double phi = (iphi-0.5)*indx.second;
627  double z = hgpar_->zLayerHex_[indx.first];
628  double r = 0.5*(hgpar_->radiusLayer_[type][ir-1] +
629  hgpar_->radiusLayer_[type][ir]);
630  std::pair<double,double> range = rangeR(z,true);
631  r = std::max(range.first, std::min(r,range.second));
632  x = r*std::cos(phi);
633  y = r*std::sin(phi);
634  if (irad < 0) x =-x;
635  }
636  if (!reco) {
639  }
640  return std::make_pair(x,y);
641 }
642 
644 
645  int cells(0);
646  for (unsigned int i = 0; i<layers(reco); ++i) {
647  int lay = reco ? hgpar_->depth_[i] : hgpar_->layer_[i];
648  if (cells < maxCells(lay, reco)) cells = maxCells(lay, reco);
649  }
650  return cells;
651 }
652 
653 int HGCalDDDConstants::maxCells(int lay, bool reco) const {
654 
655  const auto & index = getIndex(lay, reco);
656  if (index.first < 0) return 0;
659  unsigned int cells(0);
660  for (unsigned int k=0; k<hgpar_->waferTypeT_.size(); ++k) {
661  if (waferInLayerTest(k,index.first,hgpar_->defineFull_)) {
662  unsigned int cell = (hgpar_->waferTypeT_[k]==1) ?
663  (hgpar_->cellFineX_.size()) : (hgpar_->cellCoarseX_.size());
664  if (cell > cells) cells = cell;
665  }
666  }
667  return (int)(cells);
668  } else if ((mode_ == HGCalGeometryMode::Hexagon8) ||
670  int cells(0);
671  for (unsigned int k=0; k<hgpar_->waferCopy_.size(); ++k) {
672  if (waferInLayerTest(k,index.first,hgpar_->defineFull_)) {
674  int type = ((itr == hgpar_->typesInLayers_.end()) ? 2 :
675  hgpar_->waferTypeL_[itr->second]);
676  int N = (type == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
677  cells = std::max(cells,3*N*N);
678  }
679  }
680  return cells;
681  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
682  return hgpar_->scintCells(index.first+hgpar_->firstLayer_);
683  } else {
684  return 0;
685  }
686 }
687 
688 int HGCalDDDConstants::maxRows(int lay, bool reco) const {
689 
690  int kymax(0);
691  const auto & index = getIndex(lay, reco);
692  int i = index.first;
693  if (i < 0) return kymax;
696  for (unsigned int k=0; k<hgpar_->waferCopy_.size(); ++k) {
698  int ky = ((hgpar_->waferCopy_[k])/100)%100;
699  if (ky > kymax) kymax = ky;
700  }
701  }
702  } else if ((mode_ == HGCalGeometryMode::Hexagon8) ||
704  kymax = 1+2*hgpar_->waferUVMaxLayer_[index.first];
705  }
706  return kymax;
707 }
708 
709 int HGCalDDDConstants::modules(int lay, bool reco) const {
710  if (getIndex(lay,reco).first < 0) return 0;
711  else return max_modules_layer_[(int)reco][lay];
712 }
713 
714 int HGCalDDDConstants::modulesInit(int lay, bool reco) const {
715  int nmod(0);
716  const auto & index = getIndex(lay, reco);
717  if (index.first < 0) return nmod;
719  for (unsigned int k=0; k<hgpar_->waferPosX_.size(); ++k) {
720  if (waferInLayerTest(k,index.first,hgpar_->defineFull_)) ++nmod;
721  }
722  } else {
723  nmod = 1+hgpar_->lastModule_[index.first]-hgpar_->firstModule_[index.first];
724  }
725  return nmod;
726 }
727 
728 double HGCalDDDConstants::mouseBite(bool reco) const {
729 
731 }
732 
734 
735  int cells(0);
736  unsigned int nlayer = (reco) ? hgpar_->depth_.size() : hgpar_->layer_.size();
737  for (unsigned k=0; k<nlayer; ++k) {
738  std::vector<int> ncells = numberCells(((reco) ? hgpar_->depth_[k] : hgpar_->layer_[k]), reco);
739  cells = std::accumulate(ncells.begin(),ncells.end(),cells);
740  }
741  return cells;
742 }
743 
744 std::vector<int> HGCalDDDConstants::numberCells(int lay, bool reco) const {
745 
746  const auto & index = getIndex(lay, reco);
747  int i = index.first;
748  std::vector<int> ncell;
749  if (i >= 0) {
752  for (unsigned int k=0; k<hgpar_->waferTypeT_.size(); ++k) {
754  unsigned int cell = (hgpar_->waferTypeT_[k]==1) ?
755  (hgpar_->cellFineX_.size()) : (hgpar_->cellCoarseX_.size());
756  ncell.emplace_back((int)(cell));
757  }
758  }
759  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
760  int nphi = hgpar_->scintCells(lay);
761  for (int k=hgpar_->firstModule_[i]; k<=hgpar_->lastModule_[i]; ++k)
762  ncell.emplace_back(nphi);
763  } else {
764  for (unsigned int k=0; k<hgpar_->waferCopy_.size(); ++k) {
765  if (waferInLayerTest(k,index.first,hgpar_->defineFull_)) {
766  int cell = numberCellsHexagon(lay,
769  true);
770  ncell.emplace_back(cell);
771  }
772  }
773  }
774  }
775  return ncell;
776 }
777 
779 
780  if (wafer >= 0 && wafer < (int)(hgpar_->waferTypeT_.size())) {
781  if (hgpar_->waferTypeT_[wafer]==1)
782  return (int)(hgpar_->cellFineX_.size());
783  else
784  return (int)(hgpar_->cellCoarseX_.size());
785  } else {
786  return 0;
787  }
788 }
789 
790 int HGCalDDDConstants::numberCellsHexagon(int lay, int waferU, int waferV,
791  bool flag) const {
792  auto itr = hgpar_->typesInLayers_.find(HGCalWaferIndex::waferIndex(lay,waferU,waferV));
793  int type = ((itr == hgpar_->typesInLayers_.end()) ? 2 :
794  hgpar_->waferTypeL_[itr->second]);
795  int N = (type == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
796  if (flag) return (3*N*N);
797  else return N;
798 }
799 
800 std::pair<double,double> HGCalDDDConstants::rangeR(double z, bool reco) const {
801  double rmin(0), rmax(0), zz(0);
802  if (hgpar_->detectorType_ > 0) {
803  zz = (reco ? std::abs(z) : HGCalParameters::k_ScaleFromDDD*std::abs(z));
804  if (hgpar_->detectorType_ <= 2) {
807  } else {
812  }
813  if ((hgpar_->detectorType_ == 2) &&
814  (zz >= hgpar_->zLayerHex_[hgpar_->firstMixedLayer_ - 1])) {
819  } else {
822  }
823  }
824  if (!reco) {
827  }
828 #ifdef EDM_ML_DEBUG
829  edm::LogVerbatim("HGCalGeom") << "DDHGCalEEAlgo:rangeR: " << z << ":" << zz
830  << " R " << rmin << ":" << rmax;
831 #endif
832  return std::pair<double,double>(rmin,rmax);
833 }
834 
835 std::pair<double,double> HGCalDDDConstants::rangeZ(bool reco) const {
836  double zmin = (hgpar_->zLayerHex_[0] - hgpar_->waferThick_);
837  double zmax = (hgpar_->zLayerHex_[hgpar_->zLayerHex_.size()-1] +
839 #ifdef EDM_ML_DEBUG
840  edm::LogVerbatim("HGCalGeom") << "DDHGCalEEAlgo:rangeZ: " << zmin << ":"
841  << zmax << ":" << hgpar_->waferThick_;
842 #endif
843  if (!reco) {
846  }
847  return std::pair<double,double>(zmin,zmax);
848 }
849 
850 std::pair<int,int> HGCalDDDConstants::rowColumnWafer(int wafer) const {
851  int row(0), col(0);
852  if (wafer < (int)(hgpar_->waferCopy_.size())) {
853  int copy = hgpar_->waferCopy_[wafer];
854  col = copy%100;
855  if ((copy/10000)%10 != 0) col = -col;
856  row = (copy/100)%100;
857  if ((copy/100000)%10 != 0) row = -row;
858  }
859  return std::make_pair(row,col);
860 }
861 
862 std::pair<int,int> HGCalDDDConstants::simToReco(int cell, int lay, int mod,
863  bool half) const {
864 
867  return std::make_pair(cell,lay);
868  } else {
869  const auto & index = getIndex(lay, false);
870  int i = index.first;
871  if (i < 0) {
872  edm::LogWarning("HGCalGeom") << "Wrong Layer # " << lay
873  << " not in the list ***** ERROR *****";
874  return std::make_pair(-1,-1);
875  }
876  if (mod >= (int)(hgpar_->waferTypeL_).size()) {
877  edm::LogWarning("HGCalGeom") << "Invalid Wafer # " << mod
878  << "should be < "
879  << (hgpar_->waferTypeL_).size()
880  << " ***** ERROR *****";
881  return std::make_pair(-1,-1);
882  }
883  int depth(-1);
884  int kx = cell;
885  int type = hgpar_->waferTypeL_[mod];
886  if (type == 1) {
887  depth = hgpar_->layerGroup_[i];
888  } else if (type == 2) {
889  depth = hgpar_->layerGroupM_[i];
890  } else {
891  depth = hgpar_->layerGroupO_[i];
892  }
893  return std::make_pair(kx,depth);
894  }
895 }
896 
898  const int ncopies = hgpar_->waferCopy_.size();
899  int wafer(ncopies);
900  bool result(false);
901  for (int k=0; k<ncopies; ++k) {
902  if (copy == hgpar_->waferCopy_[k]) {
903  wafer = k;
904  result = true;
905  break;
906  }
907  }
908  if (!result) {
909  wafer = -1;
910 #ifdef EDM_ML_DEBUG
911  edm::LogVerbatim("HGCalGeom") << "Cannot find " << copy << " in a list of "
912  << ncopies << " members";
913  for (int k=0; k<ncopies; ++k)
914  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << hgpar_->waferCopy_[k];
915 #endif
916  }
917  return wafer;
918 }
919 
920 void HGCalDDDConstants::waferFromPosition(const double x, const double y,
921  int& wafer, int& icell,
922  int& celltyp) const {
923  //Input x, y in Geant4 unit and transformed to CMSSW standard
926  int size_ = (int)(hgpar_->waferCopy_.size());
927  wafer = size_;
928  for (int k=0; k<size_; ++k) {
929  double dx = std::abs(xx-hgpar_->waferPosX_[k]);
930  double dy = std::abs(yy-hgpar_->waferPosY_[k]);
931  if (dx <= rmax_ && dy <= hexside_) {
932  if ((dy <= 0.5*hexside_) || (dx*tan30deg_ <= (hexside_-dy))) {
933  wafer = k;
934  celltyp = hgpar_->waferTypeT_[k];
935  xx -= hgpar_->waferPosX_[k];
936  yy -= hgpar_->waferPosY_[k];
937  break;
938  }
939  }
940  }
941  if (wafer < size_) {
942  if (celltyp == 1)
943  icell = cellHex(xx, yy, 0.5*HGCalParameters::k_ScaleFromDDD*hgpar_->cellSize_[0],
945  else
948  } else {
949  wafer = -1;
950 #ifdef EDM_ML_DEBUG
951  edm::LogWarning("HGCalGeom") << "Cannot get wafer type corresponding to "
952  << x << ":" << y << " " << xx << ":" << yy;
953 #endif
954  }
955 #ifdef EDM_ML_DEBUG
956  edm::LogVerbatim("HGCalGeom") << "Position " << x << ":" << y << " Wafer "
957  << wafer << ":" << size_ << " XX " << xx << ":"
958  << yy << " Cell " << icell << " Type " << celltyp;
959 #endif
960 }
961 
962 void HGCalDDDConstants::waferFromPosition(const double x, const double y,
963  const int layer, int& waferU,
964  int& waferV, int& cellU, int& cellV,
965  int& celltype, double& wt, bool
966 #ifdef EDM_ML_DEBUG
967  debug
968 #endif
969  ) const {
970 
973  waferU = waferV = 1+hgpar_->waferUVMax_;
974  for (unsigned int k=0; k<hgpar_->waferPosX_.size(); ++k) {
975  double dx = std::abs(xx-hgpar_->waferPosX_[k]);
976  double dy = std::abs(yy-hgpar_->waferPosY_[k]);
977  if (dx <= rmax_ && dy <= hexside_) {
978  if ((dy <= 0.5*hexside_) || (dx*tan30deg_ <= (hexside_-dy))) {
981  auto itr = hgpar_->typesInLayers_.find(HGCalWaferIndex::waferIndex(layer,waferU,waferV));
982  celltype = ((itr == hgpar_->typesInLayers_.end()) ? 2 :
983  hgpar_->waferTypeL_[itr->second]);
984 #ifdef EDM_ML_DEBUG
985  if (debug)
986  edm::LogVerbatim("HGCalGeom") << "WaferFromPosition:: Input " << xx
987  << ":" << yy << " compared with "
988  << hgpar_->waferPosX_[k] << ":"
989  << hgpar_->waferPosY_[k]
990  << " difference " << dx << ":" << dy
991  << ":" << dx*tan30deg_ << ":"
992  << (hexside_-dy) << " comparator "
993  << rmax_ << ":" << hexside_ <<" wafer "
994  << waferU << ":" << waferV << ":"
995  << celltype;
996 #endif
997  xx -= hgpar_->waferPosX_[k];
998  yy -= hgpar_->waferPosY_[k];
999  break;
1000  }
1001  }
1002  }
1003  if (std::abs(waferU) <= hgpar_->waferUVMax_) {
1004  cellHex(xx, yy, celltype, cellU, cellV
1005 #ifdef EDM_ML_DEBUG
1006  , debug
1007 #endif
1008  );
1009  wt = ((celltype < 2) ?
1010  (hgpar_->cellThickness_[celltype]/hgpar_->waferThick_) : 1.0);
1011  } else {
1012  cellU = cellV = 2*hgpar_->nCellsFine_;
1013  wt = 1.0;
1014  celltype =-1;
1015  }
1016 #ifdef EDM_ML_DEBUG
1017  if (celltype < 0) {
1019  double y1(HGCalParameters::k_ScaleFromDDD*y);
1020  edm::LogVerbatim("HGCalGeom") << "waferFromPosition: Bad type for X "
1021  << x << ":" << x1 << ":" << xx << " Y " << y
1022  << ":" << y1 << ":" << yy << " Wafer "
1023  << waferU << ":" << waferV << " Cell "
1024  << cellU << ":" << cellV;
1025  for (unsigned int k=0; k<hgpar_->waferPosX_.size(); ++k) {
1026  double dx = std::abs(x1-hgpar_->waferPosX_[k]);
1027  double dy = std::abs(y1-hgpar_->waferPosY_[k]);
1028  edm::LogVerbatim("HGCalGeom") << "Wafer [" << k << "] Position ("
1029  << hgpar_->waferPosX_[k] << ", "
1030  << hgpar_->waferPosY_[k] << ") difference "
1031  << dx << ":" << dy << ":" << dx*tan30deg_
1032  << ":" << hexside_-dy << " Paramerers "
1033  << rmax_ << ":" << hexside_;
1034  }
1035  }
1036 #endif
1037 }
1038 
1039 bool HGCalDDDConstants::waferInLayer(int wafer, int lay, bool reco) const {
1040 
1041  const auto & indx = getIndex(lay, reco);
1042  if (indx.first < 0) return false;
1043  return waferInLayerTest(wafer,indx.first,hgpar_->defineFull_);
1044 }
1045 
1046 bool HGCalDDDConstants::waferFullInLayer(int wafer, int lay, bool reco) const {
1047  const auto & indx = getIndex(lay, reco);
1048  if (indx.first < 0) return false;
1049  return waferInLayerTest(wafer,indx.first,false);
1050 }
1051 
1052 std::pair<double,double> HGCalDDDConstants::waferPosition(int wafer,
1053  bool reco) const {
1054 
1055  double xx(0), yy(0);
1056  if (wafer >= 0 && wafer < (int)(hgpar_->waferPosX_.size())) {
1057  xx = hgpar_->waferPosX_[wafer];
1058  yy = hgpar_->waferPosY_[wafer];
1059  }
1060  if (!reco) {
1063  }
1064  return std::make_pair(xx,yy);
1065 }
1066 
1067 std::pair<double,double> HGCalDDDConstants::waferPosition(int waferU,
1068  int waferV,
1069  bool reco) const {
1070 
1071  double xx(0), yy(0);
1072  int indx = HGCalWaferIndex::waferIndex(0,waferU,waferV);
1073  auto itr = hgpar_->wafersInLayers_.find(indx);
1074  if (itr != hgpar_->wafersInLayers_.end()) {
1075  xx = hgpar_->waferPosX_[itr->second];
1076  yy = hgpar_->waferPosY_[itr->second];
1077  }
1078  if (!reco) {
1081  }
1082  return std::make_pair(xx,yy);
1083 }
1084 
1085 int HGCalDDDConstants::waferType(DetId const& id) const {
1086 
1087  int type(1);
1090  type = ((id.det() != DetId::Forward) ? (1 + HGCSiliconDetId(id).type()) :
1091  (1 + HFNoseDetId(id).type()));
1092  } else if ((mode_ == HGCalGeometryMode::Hexagon) ||
1094  type = waferTypeL(HGCalDetId(id).wafer());
1095  }
1096  return type;
1097 }
1098 
1099 double HGCalDDDConstants::waferZ(int lay, bool reco) const {
1100  const auto & index = getIndex(lay, reco);
1101  if (index.first < 0) return 0;
1102  else return (reco ? hgpar_->zLayerHex_[index.first] :
1104 }
1105 
1107 
1108  int wafer(0);
1110  for (unsigned int i = 0; i<layers(true); ++i) {
1111  int lay = hgpar_->depth_[i];
1112  wafer += modules(lay, true);
1113  }
1114  } else {
1115  wafer = (int)(hgpar_->moduleLayR_.size());
1116  }
1117  return wafer;
1118 }
1119 
1120 int HGCalDDDConstants::wafers(int layer, int type) const {
1121 
1122  int wafer(0);
1124  auto itr = waferLayer_.find(layer);
1125  if (itr != waferLayer_.end()) {
1126  unsigned ity = (type > 0 && type <= 2) ? type : 0;
1127  wafer = (itr->second)[ity];
1128  }
1129  } else {
1130  const auto & index = getIndex(layer, true);
1131  wafer = 1+hgpar_->lastModule_[index.first]-hgpar_->firstModule_[index.first];
1132  }
1133  return wafer;
1134 }
1135 
1136 int HGCalDDDConstants::cellHex(double xx, double yy,
1137  const double& cellR,
1138  const std::vector<double>& posX,
1139  const std::vector<double>& posY) const {
1140  int num(0);
1141  const double tol(0.00001);
1142  double cellY = 2.0*cellR*tan30deg_;
1143  for (unsigned int k=0; k<posX.size(); ++k) {
1144  double dx = std::abs(xx - posX[k]);
1145  double dy = std::abs(yy - posY[k]);
1146  if (dx <= (cellR+tol) && dy <= (cellY+tol)) {
1147  double xmax = (dy<=0.5*cellY) ? cellR : (cellR-(dy-0.5*cellY)/tan30deg_);
1148  if (dx <= (xmax+tol)) {
1149  num = k;
1150  break;
1151  }
1152  }
1153  }
1154  return num;
1155 }
1156 
1157 void HGCalDDDConstants::cellHex(double xloc, double yloc, int cellType,
1158  int& cellU, int& cellV, bool
1159 #ifdef EDM_ML_DEBUG
1160  debug
1161 #endif
1162  ) const {
1163  int N = (cellType == 0) ? hgpar_->nCellsFine_ : hgpar_->nCellsCoarse_;
1164  double Rc = 2*rmax_/(3*N);
1165  double rc = 0.5*Rc*sqrt3_;
1166  double v0 = ((xloc/Rc -1.0)/1.5);
1167  int cv0 = (v0 > 0) ? (N + (int)(v0+0.5)) : (N - (int)(-v0+0.5));
1168  double u0 = (0.5*yloc/rc+0.5*cv0);
1169  int cu0 = (u0 > 0) ? (N/2 + (int)(u0+0.5)) : (N/2 - (int)(-u0+0.5));
1170  cu0 = std::max(0,std::min(cu0,2*N-1));
1171  cv0 = std::max(0,std::min(cv0,2*N-1));
1172  if (cv0-cu0 >= N) cv0 = cu0+N-1;
1173 #ifdef EDM_ML_DEBUG
1174  if (debug)
1175  edm::LogVerbatim("HGCalGeom") << "cellHex: input " << xloc << ":"
1176  << yloc << ":" << cellType << " parameter "
1177  << rc << ":" << Rc << " u0 " << u0 << ":"
1178  << cu0 << " v0 " << v0 << ":" << cv0;
1179 #endif
1180  bool found(false);
1181  static const int shift[3] = {0,1,-1};
1182  for (int i1=0; i1<3; ++i1) {
1183  cellU = cu0 + shift[i1];
1184  for (int i2=0; i2<3; ++i2) {
1185  cellV = cv0 + shift[i2];
1186  if (((cellV-cellU) < N) && ((cellU-cellV) <= N) && (cellU >= 0) &&
1187  (cellV >= 0) && (cellU < 2*N) && (cellV < 2*N)) {
1188  double xc = (1.5*(cellV-N)+1.0)*Rc;
1189  double yc = (2*cellU-cellV-N)*rc;
1190  if ((std::abs(yloc-yc) <= rc) && (std::abs(xloc-xc) <= Rc) &&
1191  ((std::abs(xloc-xc) <= 0.5*Rc) ||
1192  (std::abs(yloc-yc) <= sqrt3_*(Rc-std::abs(xloc-xc))))) {
1193 #ifdef EDM_ML_DEBUG
1194  if (debug)
1195  edm::LogVerbatim("HGCalGeom") << "cellHex: local " << xc << ":"
1196  << yc << " difference "
1197  << std::abs(xloc-xc) << ":"
1198  << std::abs(yloc-yc) << ":"
1199  << sqrt3_*(Rc-std::abs(yloc-yc))
1200  << " comparator " << rc << ":" << Rc
1201  << " (u,v) = (" << cellU << ","
1202  << cellV << ")";
1203 #endif
1204  found = true; break;
1205  }
1206  }
1207  }
1208  if (found) break;
1209  }
1210  if (!found) { cellU = cu0; cellV = cv0; }
1211 }
1212 
1213 std::pair<int,float> HGCalDDDConstants::getIndex(int lay, bool reco) const {
1214 
1215  int indx = layerIndex(lay,reco);
1216  if (indx<0) return std::make_pair(-1,0);
1217  float cell(0);
1218  if ((mode_ == HGCalGeometryMode::Hexagon) ||
1220  cell = (reco ? hgpar_->moduleCellR_[0] : hgpar_->moduleCellS_[0]);
1221  } else {
1224  cell = (reco ? hgpar_->moduleCellR_[0] : hgpar_->moduleCellS_[0]);
1225  } else {
1226  cell = hgpar_->scintCellSize(lay);
1227  }
1228  }
1229  return std::make_pair(indx,cell);
1230 }
1231 
1232 bool HGCalDDDConstants::isValidCell(int lay, int wafer, int cell) const {
1233 
1234  // Calculate the position of the cell
1235  // Works for options HGCalHexagon/HGCalHexagonFull
1236  double x = hgpar_->waferPosX_[wafer];
1237  double y = hgpar_->waferPosY_[wafer];
1238  if (hgpar_->waferTypeT_[wafer] == 1) {
1239  x += hgpar_->cellFineX_[cell];
1240  y += hgpar_->cellFineY_[cell];
1241  } else {
1242  x += hgpar_->cellCoarseX_[cell];
1243  y += hgpar_->cellCoarseY_[cell];
1244  }
1245  double rr = sqrt(x*x+y*y);
1246  bool result = ((rr >= hgpar_->rMinLayHex_[lay-1]) &&
1247  (rr <= hgpar_->rMaxLayHex_[lay-1]) &&
1248  (wafer < (int)(hgpar_->waferPosX_.size())));
1249 #ifdef EDM_ML_DEBUG
1250  if (!result)
1251  edm::LogVerbatim("HGCalGeom") << "Input " << lay << ":" << wafer << ":"
1252  << cell << " Position " << x << ":" << y
1253  << ":" << rr << " Compare Limits "
1254  << hgpar_->rMinLayHex_[lay-1] << ":"
1255  << hgpar_->rMaxLayHex_[lay-1]
1256  << " Flag " << result;
1257 #endif
1258  return result;
1259 }
1260 
1261 bool HGCalDDDConstants::waferInLayerTest(int wafer, int lay, bool full) const {
1262 
1263  const double waferX = hgpar_->waferPosX_[wafer];
1264  const double waferY = hgpar_->waferPosY_[wafer];
1266  xc[0] = waferX+rmax_; yc[0] = waferY-0.5*hexside_;
1267  xc[1] = waferX+rmax_; yc[1] = waferY+0.5*hexside_;
1268  xc[2] = waferX; yc[2] = waferY+hexside_;
1269  xc[3] = waferX-rmax_; yc[3] = waferY+0.5*hexside_;
1270  xc[4] = waferX+rmax_; yc[4] = waferY-0.5*hexside_;
1271  xc[5] = waferX; yc[5] = waferY-hexside_;
1272  bool cornerOne(false), cornerAll(true);
1273  for (unsigned int k=0; k<HGCalParameters::k_CornerSize; ++k) {
1274  double rpos = std::sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
1275  if ((rpos >= hgpar_->rMinLayHex_[lay]) &&
1276  (rpos <= hgpar_->rMaxLayHex_[lay])) cornerOne = true;
1277  else cornerAll = false;
1278  }
1279  bool in = full ? cornerOne : cornerAll;
1280 #ifdef EDM_ML_DEBUG
1281  edm::LogVerbatim("HGCalGeom") << "WaferInLayerTest: Layer " << lay
1282  << " wafer " << wafer << " R-limits "
1283  << hgpar_->rMinLayHex_[lay] << ":"
1284  << hgpar_->rMaxLayHex_[lay] << " Corners "
1285  << cornerOne << ":" << cornerAll << " In "
1286  << in;
1287 #endif
1288  return in;
1289 }
1290 
1292 
std::vector< int > iradMaxBH_
size
Write out results.
bool isHalfCell(int waferType, int cell) const
std::vector< double > waferPosY_
type
Definition: HCALResponse.h:21
std::vector< int > layer_
std::vector< int > depthLayerF_
bool isValidTrap(int lay, int ieta, int iphi) const
std::vector< int > depth_
std::vector< double > zFrontMin_
std::vector< double > moduleCellR_
int getTypeTrap(int layer) const
wafer_map cellFineIndex_
layer_map copiesInLayers_
int getLayer(double z, bool reco) const
std::vector< HGCalParameters::hgtrap > getModules() const
std::vector< bool > cellCoarseHalf_
std::vector< bool > cellFineHalf_
std::array< uint32_t, 2 > tot_layers_
def copy(args, dbName)
int scintType(const int layer) const
std::map< int, HGCWaferParam > waferLayer_
void waferFromPosition(const double x, const double y, int &wafer, int &icell, int &celltyp) const
int type() const
get the type
Definition: HFNoseDetId.h:52
std::vector< int > moduleLayR_
double cellSizeHex(int type) const
HGCalParameters::hgtrform getTrForm(unsigned int k) const
Simrecovecs max_modules_layer_
double cellThickness(int layer, int waferU, int waferV) const
static double radius(double z, std::vector< double > const &zFront, std::vector< double > const &rFront, std::vector< double > const &slope)
unsigned int layersInit(bool reco) const
static int32_t waferV(const int32_t index)
static int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV)
std::array< int, 4 > waferMax_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
bool cellInLayer(int waferU, int waferV, int cellU, int cellV, int lay, bool reco) const
int maxRows(int lay, bool reco) const
int getTypeHex(int layer, int waferU, int waferV) const
std::vector< double > cellFineY_
bool waferInLayerTest(int wafer, int lay, bool full) const
int modulesInit(int lay, bool reco) const
std::pair< float, float > locateCell(int cell, int lay, int type, bool reco) const
std::vector< uint32_t > trformIndex_
bool isValidHex(int lay, int mod, int cell, bool reco) const
std::vector< int > layerGroupM_
HGCalGeometryMode::GeometryMode mode_
HGCalGeometryMode::GeometryMode mode_
double scintCellSize(const int layer) const
int cellHex(double xx, double yy, const double &cellR, const std::vector< double > &posX, const std::vector< double > &posY) const
int layerIndex(int lay, bool reco) const
wafer_map wafersInLayers_
std::pair< float, float > locateCellHex(int cell, int wafer, bool reco) const
std::vector< double > cellCoarseX_
std::pair< double, double > rangeR(double z, bool reco) const
int modules(int lay, bool reco) const
std::vector< int > firstModule_
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
unsigned int getTrFormN() const
double distFromEdgeTrap(double x, double y, double z) const
std::pair< double, double > rangeZ(bool reco) const
unsigned int layers(bool reco) const
bool isValidHex8(int lay, int modU, int modV, int cellU, int cellV) const
int numberCellsHexagon(int wafer) const
std::vector< double > cellSize_
std::vector< int > waferUVMaxLayer_
std::vector< HGCalParameters::hgtrform > getTrForms() const
std::vector< int > layerIndex_
double mouseBite(bool reco) const
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
hgtrform getTrForm(unsigned int k) const
int type() const
get the type
T sqrt(T t)
Definition: SSEVec.h:18
std::pair< int, float > getIndex(int lay, bool reco) const
static double k_ScaleFromDDD
HGCalDDDConstants(const HGCalParameters *hp, const std::string &name)
std::pair< float, float > locateCellTrap(int lay, int ieta, int iphi, bool reco) const
std::vector< double > rMaxFront_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Definition: GenABIO.cc:180
int scintCells(const int layer) const
hgtrap getModule(unsigned int k, bool reco) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unordered_map< int32_t, bool > waferIn_
std::vector< double > slopeTop_
static int32_t waferU(const int32_t index)
bool isValidCell(int layindex, int wafer, int cell) const
int waferTypeL(int wafer) const
T min(T a, T b)
Definition: MathUtil.h:58
int sectors() const
std::vector< double > rMinLayHex_
std::pair< int, int > rowColumnWafer(const int wafer) const
std::vector< double > zLayerHex_
double waferZ(int layer, bool reco) const
#define M_PI
int k[5][pyjets_maxn]
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
int waferType(DetId const &id) const
static const int maxType
std::vector< double > rMaxLayHex_
static uint32_t k_CornerSize
std::vector< double > slopeMin_
Definition: DetId.h:18
std::vector< int > lastModule_
int waferFromCopy(int copy) const
std::vector< double > radiusMixBoundary_
#define debug
Definition: HDRShower.cc:19
#define N
Definition: blowfish.cc:9
std::vector< double > cellThickness_
std::vector< int > layerGroup_
std::vector< double > moduleCellS_
static double k_ScaleToDDD
int numberCells(bool reco) const
wafer_map cellCoarseIndex_
bool waferFullInLayer(int wafer, int lay, bool reco) const
std::vector< double > rMinFront_
std::vector< int > iradMinBH_
std::vector< double > cellFineX_
wafer_map typesInLayers_
std::vector< int > layerGroupO_
static const int minType
fixed size matrix
std::array< int, 5 > assignCellHex(float x, float y, int lay, bool reco) const
std::vector< int > waferCopy_
col
Definition: cuy.py:1010
#define EDM_ML_DEBUG
static unsigned int const shift
std::vector< int > depthIndex_
std::pair< double, double > waferPosition(int wafer, bool reco) const
std::pair< int, int > assignCell(float x, float y, int lay, int subSec, bool reco) const
std::array< int, 3 > assignCellTrap(float x, float y, float z, int lay, bool reco) const
std::vector< double > zFrontTop_
std::vector< double > radiusLayer_[2]
std::vector< int > waferTypeT_
std::vector< double > cellCoarseY_
HGCalParameters::hgtrap getModule(unsigned int k, bool hexType, bool reco) const
const HGCalParameters * hgpar_
int maxCells(bool reco) const
std::vector< double > waferPosX_
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
std::vector< int > waferTypeL_
static double tan30deg_
double distFromEdgeHex(double x, double y, double z) const
std::array< int, 3 > HGCWaferParam
bool waferInLayer(int wafer, int lay, bool reco) const