CMS 3D CMS Logo

HGCalDDDConstants.cc
Go to the documentation of this file.
2 
6 
7 #include "CLHEP/Units/GlobalPhysicalConstants.h"
8 #include "CLHEP/Units/GlobalSystemOfUnits.h"
9 
10 //#define EDM_ML_DEBUG
11 
14 
16  const std::string& name) : hgpar_(hp) {
17  mode_ = hgpar_->mode_;
19  rmax_ = 0;
20  modHalf_ = sectors()*layers(true);
21  for (int simreco = 0; simreco < 2; ++simreco ) {
22  tot_layers_[simreco] = layersInit((bool)simreco);
23  }
24 
25  edm::LogInfo("HGCalGeom") << "HGCalDDDConstants initialized for " << name
26  << " with " << layers(false) << ":"
27  << layers(true) << " layers, " << sectors()
28  << " sectors " << 2*modHalf_ << " modules and "
29  << "maximum of " << maxCells(false) << ":"
30  << maxCells(true) << " cells";
31 #ifdef EDM_ML_DEBUG
32  std::cout << "HGCalDDDConstants initialized for " << name << " with "
33  << layers(false) << ":" << layers(true) << " layers, "
34  << sectors() << " sectors and maximum of " << maxCells(false)
35  << ":" << maxCells(true) << " cells" << std::endl;
36 #endif
37  } else {
38  rmax_ = k_ScaleFromDDD * (hgpar_->waferR_) * std::cos(30.0*CLHEP::deg);
39  hexside_ = 2.0 * rmax_ * tan30deg_;
40 #ifdef EDM_ML_DEBUG
41  std::cout << "rmax_ " << rmax_ << ":" << hexside_ << " CellSize "
42  << 0.5*k_ScaleFromDDD*hgpar_->cellSize_[0] << ":"
43  << 0.5*k_ScaleFromDDD*hgpar_->cellSize_[1] << std::endl;
44 #endif
45  // init maps and constants
46  modHalf_ = 0;
47  for (int simreco = 0; simreco < 2; ++simreco) {
48  tot_layers_[simreco] = layersInit((bool)simreco);
49  max_modules_layer_[simreco].resize(tot_layers_[simreco]+1);
50  for (unsigned int layer=1; layer <= tot_layers_[simreco]; ++layer) {
51  max_modules_layer_[simreco][layer] = modulesInit(layer,(bool)simreco);
52  if (simreco == 1) {
53  modHalf_ += max_modules_layer_[simreco][layer];
54 #ifdef EDM_ML_DEBUG
55  std::cout << "Layer " << layer << " with " << max_modules_layer_[simreco][layer] << ":" << modHalf_ << " modules\n";
56 #endif
57  }
58  }
59  }
60  tot_wafers_ = wafers();
61 
62  edm::LogInfo("HGCalGeom") << "HGCalDDDConstants initialized for " << name
63  << " with " << layers(false) << ":"
64  << layers(true) << " layers, " << wafers()
65  << ":" << 2*modHalf_ << " wafers and "
66  << "maximum of " << maxCells(false) << ":"
67  << maxCells(true) << " cells";
68 
69 #ifdef EDM_ML_DEBUG
70  std::cout << "HGCalDDDConstants initialized for " << name << " with "
71  << layers(false) << ":" << layers(true) << " layers, "
72  << wafers() << " wafers and " << "maximum of " << maxCells(false)
73  << ":" << maxCells(true) << " cells" << std::endl;
74 #endif
75 
76  }
77 
78  int wminT(9999999), wmaxT(0), kount1(0), kount2(0);
79  for (unsigned int i=0; i<getTrFormN(); ++i) {
80  int lay0 = getTrForm(i).lay;
81  int wmin(9999999), wmax(0), kount(0);
82  for (int wafer=0; wafer<sectors(); ++wafer) {
83  if (waferInLayer(wafer,lay0,true)) {
84  if (wafer < wmin) wmin = wafer;
85  if (wafer > wmax) wmax = wafer;
86  ++kount;
87  }
88  }
89  if (wminT > wmin) wminT = wmin;
90  if (wmaxT < wmax) wmaxT = wmax;
91  if (kount1 < kount) kount1= kount;
92  kount2 += kount;
93 #ifdef EDM_ML_DEBUG
94  int lay1 = getIndex(lay0,true).first;
95  std::cout << "Index " << i << " Layer " << lay0 << ":" << lay1
96  << " Wafer " << wmin << ":" << wmax << ":" << kount << std::endl;
97 #endif
98  HGCWaferParam a1{ {wmin,wmax,kount} };
99  waferLayer_[lay0] = a1;
100  }
101  waferMax_ = std::array<int,4>{ {wminT,wmaxT,kount1,kount2} };
102 #ifdef EDM_ML_DEBUG
103  std::cout << "Overall wafer statistics: " << wminT << ":" << wmaxT << ":"
104  << kount1 << ":" << kount2 << std::endl;
105 #endif
106 }
107 
109 
110 std::pair<int,int> HGCalDDDConstants::assignCell(float x, float y, int lay,
111  int subSec, bool reco) const {
112  std::pair<int,float> index = getIndex(lay, reco);
113  std::pair<int,int> cellAssignment(-1,-1);
114  int i = index.first;
115  if (i < 0) return cellAssignment;
117  float alpha, h, bl, tl;
118  getParameterSquare(i,subSec,reco,h,bl,tl,alpha);
119  cellAssignment = assignCellSquare(x, y, h, bl, tl, alpha, index.second);
120  } else {
121  float xx = (reco) ? x : k_ScaleFromDDD*x;
122  float yy = (reco) ? y : k_ScaleFromDDD*y;
123  cellAssignment = assignCellHexagon(xx,yy);
124  }
125  return cellAssignment;
126 }
127 
128 std::pair<int,int> HGCalDDDConstants::assignCellSquare(float x, float y,
129  float h, float bl,
130  float tl, float alpha,
131  float cellSize) const {
132 
133  float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
134  float b = 2*h*bl/(tl-bl);
135 
136  float x0(x);
137  int phiSector = (x0 > 0) ? 1 : 0;
138  if (alpha < 0) {x0 -= 0.5*(tl+bl); phiSector = 0;}
139  else if (alpha > 0) {x0 += 0.5*(tl+bl); phiSector = 1;}
140 
141  //determine the i-y
142  int ky = floor((y+h)/cellSize);
143  if (ky*cellSize> y+h) ky--;
144  if (ky<0) return std::pair<int,int>(-1,-1);
145  if ((ky+1)*cellSize < (y+h) ) ky++;
146  int max_ky_allowed=floor(2*h/cellSize);
147  if (ky>max_ky_allowed-1) return std::pair<int,int>(-1,-1);
148 
149  //determine the i-x
150  //notice we substitute y by the top of the candidate cell to reduce the dead zones
151  int kx = floor(fabs(x0)/cellSize);
152  if (kx*cellSize > fabs(x0) ) kx--;
153  if (kx<0) return std::pair<int,int>(-1,-1);
154  if ((kx+1)*cellSize < fabs(x0)) kx++;
155  int max_kx_allowed=floor( ((ky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize) );
156  if (kx>max_kx_allowed-1) return std::pair<int,int>(-1,-1);
157 
158  //count cells summing in rows until required height
159  //notice the bottom of the cell must be used
160  int icell(0);
161  for (int iky=0; iky<ky; ++iky) {
162  int cellsInRow( floor( ((iky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize) ) );
163  icell += cellsInRow;
164  }
165  icell += kx;
166 
167  //return result
168  return std::pair<int,int>(phiSector,icell);
169 }
170 
171 std::pair<int,int> HGCalDDDConstants::assignCellHexagon(float x,
172  float y) const {
173  double xx(x), yy(y);
174  //First the wafer
175  int wafer = cellHex(xx, yy, rmax_, hgpar_->waferPosX_, hgpar_->waferPosY_);
176  // Now the cell
177  xx -= hgpar_->waferPosX_[wafer];
178  yy -= hgpar_->waferPosY_[wafer];
179  int cell(0);
180  if (hgpar_->waferTypeT_[wafer] == 1)
182  else
184  return std::pair<int,int>(wafer,cell);
185 }
186 
188  int indx = (type == 1) ? 0 : 1;
189  double cell = (0.5*k_ScaleFromDDD*hgpar_->cellSize_[indx]);
190  return cell;
191 }
192 
193 std::pair<int,int> HGCalDDDConstants::findCell(int cell, int lay, int subSec,
194  bool reco) const {
195 
196  std::pair<int,float> index = getIndex(lay, reco);
197  int i = index.first;
198  if (i < 0) return std::pair<int,int>(-1,-1);
200  return std::pair<int,int>(-1,-1);
201  } else {
202  float alpha, h, bl, tl;
203  getParameterSquare(i,subSec,reco,h,bl,tl,alpha);
204  return findCellSquare(cell, h, bl, tl, alpha, index.second);
205  }
206 }
207 
208 std::pair<int,int> HGCalDDDConstants::findCellSquare(int cell, float h,
209  float bl, float tl,
210  float alpha,
211  float cellSize) const {
212 
213  //check if cell number is meaningful
214  if(cell<0) return std::pair<int,int>(-1,-1);
215 
216  //parameterization of the boundary of the trapezoid
217  float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
218  float b = 2*h*bl/(tl-bl);
219  int kx(cell), ky(0);
220  int kymax( floor((2*h)/cellSize) );
221  int testCell(0);
222  for (int iky=0; iky<kymax; ++iky) {
223 
224  //check if adding all the cells in this row is above the required cell
225  //notice the top of the cell is used to maximize space
226  int cellsInRow(floor(((iky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize)));
227  if (testCell+cellsInRow > cell) break;
228  testCell += cellsInRow;
229  ky++;
230  kx -= cellsInRow;
231  }
232 
233  return std::pair<int,int>(kx,ky);
234 }
235 
237  bool hexType,
238  bool reco) const {
239 
241  if (hexType) {
242  unsigned int type = (indx < hgpar_->waferTypeL_.size()) ?
243  hgpar_->waferTypeL_[indx] : 3;
244  if (type > 0) --type;
245  mytr = hgpar_->getModule(type, true);
246  } else {
247  if (reco) mytr = hgpar_->getModule(indx,true);
248  else mytr = hgpar_->getModule(indx,false);
249  }
250  return mytr;
251 }
252 
253 std::vector<HGCalParameters::hgtrap> HGCalDDDConstants::getModules() const {
254 
255  std::vector<HGCalParameters::hgtrap> mytrs;
256  for (unsigned int k=0; k<hgpar_->moduleLayR_.size(); ++k)
257  mytrs.emplace_back(hgpar_->getModule(k,true));
258  return mytrs;
259 }
260 
261 std::vector<HGCalParameters::hgtrform> HGCalDDDConstants::getTrForms() const {
262 
263  std::vector<HGCalParameters::hgtrform> mytrs;
264  for (unsigned int k=0; k<hgpar_->trformIndex_.size(); ++k)
265  mytrs.emplace_back(hgpar_->getTrForm(k));
266  return mytrs;
267 }
268 
269 bool HGCalDDDConstants::isValid(int lay, int mod, int cell, bool reco) const {
270 
271  bool ok(false);
272  int cellmax(0), modmax(0);
274  cellmax = maxCells(lay,reco);
275  modmax = sectors();
276  ok = ((lay > 0 && lay <= (int)(layers(reco))) &&
277  (mod > 0 && mod <= modmax) &&
278  (cell >=0 && cell <= cellmax));
279  } else {
280  int32_t copyNumber = hgpar_->waferCopy_[mod];
281  ok = ((lay > 0 && lay <= (int)(layers(reco))));
282  if (ok) {
283  const int32_t lay_idx = reco ? (lay-1)*3 + 1 : lay;
284  const auto& the_modules = hgpar_->copiesInLayers_[lay_idx];
285  auto moditr = the_modules.find(copyNumber);
286  ok = (moditr != the_modules.end());
287 #ifdef EDM_ML_DEBUG
288  if (!ok) std::cout << "HGCalDDDConstants: Layer " << lay << ":"
289  << lay_idx << " Copy " << copyNumber << ":" << mod
290  << " Flag " << ok << std::endl;
291 #endif
292  if (ok) {
293  if (moditr->second >= 0) {
294  cellmax = (hgpar_->waferTypeT_[mod]==1) ?
295  (int)(hgpar_->cellFineX_.size()) : (int)(hgpar_->cellCoarseX_.size());
296  ok = (cell >=0 && cell <= cellmax);
297  } else {
298  ok = isValidCell(lay_idx, mod, cell);
299  }
300  }
301  }
302  }
303 
304 #ifdef EDM_ML_DEBUG
305  if (!ok) std::cout << "HGCalDDDConstants: Layer " << lay << ":"
306  << (lay > 0 && (lay <= (int)(layers(reco)))) << " Module "
307  << mod << ":" << modmax << ":"
308  << (mod > 0 && mod <= modmax) << " Cell " << cell << ":"
309  << cellmax << ":" << (cell >=0 && cell <= cellmax)
310  << ":" << maxCells(reco) << std::endl;
311 #endif
312  return ok;
313 }
314 
315 bool HGCalDDDConstants::isValidCell(int lay, int wafer, int cell) const {
316 
317  // Calculate the position of the cell
318  double x = hgpar_->waferPosX_[wafer];
319  double y = hgpar_->waferPosY_[wafer];
320  if (hgpar_->waferTypeT_[wafer] == 1) {
321  x += hgpar_->cellFineX_[cell];
322  y += hgpar_->cellFineY_[cell];
323  } else {
324  x += hgpar_->cellCoarseX_[cell];
325  y += hgpar_->cellCoarseY_[cell];
326  }
327  double rr = sqrt(x*x+y*y);
328  bool ok = ((rr >= hgpar_->rMinLayHex_[lay-1]) &
329  (rr <= hgpar_->rMaxLayHex_[lay-1]));
330 #ifdef EDM_ML_DEBUG
331  if (!ok)
332  std::cout << "Input " << lay << ":" << wafer << ":" << cell << " Position "
333  << x << ":" << y << ":" << rr << " Compare Limits "
334  << hgpar_->rMinLayHex_[lay-1] << ":" <<hgpar_->rMaxLayHex_[lay-1]
335  << " Flag " << ok << std::endl;
336 #endif
337  return ok;
338 }
339 
340 unsigned int HGCalDDDConstants::layers(bool reco) const {
341  return tot_layers_[(int)reco];
342 }
343 
344 unsigned int HGCalDDDConstants::layersInit(bool reco) const {
345  return (reco ? hgpar_->depthIndex_.size() : hgpar_->layerIndex_.size());
346 }
347 
348 std::pair<float,float> HGCalDDDConstants::locateCell(int cell, int lay,
349  int type, bool reco) const {
350  // type refers to subsector # for square cell and wafer # for hexagon cell
351  float x(999999.), y(999999.);
352  std::pair<int,float> index = getIndex(lay, reco);
353  int i = index.first;
354  if (i < 0) return std::pair<float,float>(x,y);
356  std::pair<int,int> kxy = findCell(cell, lay, type, reco);
357  float alpha, h, bl, tl;
358  getParameterSquare(i,type,reco,h,bl,tl,alpha);
359  float cellSize = index.second;
360  x = (kxy.first+0.5)*cellSize;
361  if (alpha < 0) x -= 0.5*(tl+bl);
362  else if (alpha > 0) x -= 0.5*(tl+bl);
363  if (type != 1) x = -x;
364  y = ((kxy.second+0.5)*cellSize-h);
365  } else {
366  x = hgpar_->waferPosX_[type];
367  y = hgpar_->waferPosY_[type];
368  if (hgpar_->waferTypeT_[type] == 1) {
369  x += hgpar_->cellFineX_[cell];
370  y += hgpar_->cellFineY_[cell];
371  } else {
372  x += hgpar_->cellCoarseX_[cell];
373  y += hgpar_->cellCoarseY_[cell];
374  }
375  if (!reco) {
376  x /= k_ScaleFromDDD;
377  y /= k_ScaleFromDDD;
378  }
379  }
380  return std::pair<float,float>(x,y);
381 }
382 
383 std::pair<float,float> HGCalDDDConstants::locateCellHex(int cell, int wafer,
384  bool reco) const {
385  float x(0), y(0);
386  if (hgpar_->waferTypeT_[wafer] == 1) {
387  x = hgpar_->cellFineX_[cell];
388  y = hgpar_->cellFineY_[cell];
389  } else {
390  x = hgpar_->cellCoarseX_[cell];
391  y = hgpar_->cellCoarseY_[cell];
392  }
393  if (!reco) {
394  x /= k_ScaleFromDDD;
395  y /= k_ScaleFromDDD;
396  }
397  return std::pair<float,float>(x,y);
398 }
399 
401 
402  int cells(0);
403  for (unsigned int i = 0; i<layers(reco); ++i) {
404  int lay = reco ? hgpar_->depth_[i] : hgpar_->layer_[i];
405  if (cells < maxCells(lay, reco)) cells = maxCells(lay, reco);
406  }
407  return cells;
408 }
409 
410 int HGCalDDDConstants::maxCells(int lay, bool reco) const {
411 
412  std::pair<int,float> index = getIndex(lay, reco);
413  int i = index.first;
414  if (i < 0) return 0;
416  float h, bl, tl, alpha;
417  getParameterSquare(i,0,reco,h,bl,tl,alpha);
418  return maxCellsSquare(h, bl, tl, alpha, index.second);
419  } else {
420  unsigned int cells(0);
421  for (unsigned int k=0; k<hgpar_->waferTypeT_.size(); ++k) {
422  if (waferInLayer(k,index.first)) {
423  unsigned int cell = (hgpar_->waferTypeT_[k]==1) ?
424  (hgpar_->cellFineX_.size()) : (hgpar_->cellCoarseX_.size());
425  if (cell > cells) cells = cell;
426  }
427  }
428  return (int)(cells);
429  }
430 }
431 
432 int HGCalDDDConstants::maxCellsSquare(float h, float bl, float tl,
433  float alpha, float cellSize) const {
434 
435  float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
436  float b = 2*h*bl/(tl-bl);
437 
438  int ncells(0);
439  //always use the top of the cell to maximize space
440  int kymax = floor((2*h)/cellSize);
441  for (int iky=0; iky<kymax; ++iky) {
442  int cellsInRow=floor(((iky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize));
443  ncells += cellsInRow;
444  }
445 
446  return ncells;
447 }
448 
449 int HGCalDDDConstants::maxRows(int lay, bool reco) const {
450 
451  int kymax(0);
452  std::pair<int,float> index = getIndex(lay, reco);
453  int i = index.first;
454  if (i < 0) return kymax;
456  float h = (reco) ? hgpar_->moduleHR_[i] : hgpar_->moduleHS_[i];
457  kymax = floor((2*h)/index.second);
458  } else {
459  for (unsigned int k=0; k<hgpar_->waferCopy_.size(); ++k) {
460  if (waferInLayer(k,i)) {
461  int ky = ((hgpar_->waferCopy_[k])/100)%100;
462  if (ky > kymax) kymax = ky;
463  }
464  }
465  }
466  return kymax;
467 }
468 
469 int HGCalDDDConstants::modules(int lay, bool reco) const {
470  if( getIndex(lay,reco).first < 0 ) return 0;
471  return max_modules_layer_[(int)reco][lay];
472 }
473 
474 int HGCalDDDConstants::modulesInit(int lay, bool reco) const {
475  int nmod(0);
476  std::pair<int,float> index = getIndex(lay, reco);
477  if (index.first < 0) return nmod;
478  for (unsigned int k=0; k<hgpar_->waferPosX_.size(); ++k) {
479  if (waferInLayer(k,index.first)) ++nmod;
480  }
481  return nmod;
482 }
483 
484 std::pair<int,int> HGCalDDDConstants::newCell(int cell, int layer, int sector,
485  int subsector, int incrx,
486  int incry, bool half) const {
487 
488  int subSec = half ? subsector : 0;
489  std::pair<int,int> kxy = findCell(cell, layer, subSec, true);
490  int kx = kxy.first + incrx;
491  int ky = kxy.second + incry;
492  if (ky < 0 || ky > maxRows(layer, true)) {
493  cell = maxCells(true);
494  return std::pair<int,int>(cell,sector*subsector);
495  } else if (kx < 0) {
496  kx =-kx;
497  subsector =-subsector;
498  } else if (kx > maxCells(layer, true)) {
499  kx -= maxCells(layer, true);
500  sector += subsector;
501  subsector =-subsector;
502  if (sector < 1) sector = hgpar_->nSectors_;
503  else if (sector > hgpar_->nSectors_) sector = 1;
504  }
505  cell = newCell(kx, ky, layer, subSec);
506  return std::pair<int,int>(cell,sector*subsector);
507 }
508 
509 std::pair<int,int> HGCalDDDConstants::newCell(int cell, int lay, int subsector,
510  int incrz, bool half) const {
511 
512  int layer = lay + incrz;
513  if (layer <= 0 || layer > (int)(layers(true))) return std::pair<int,int>(cell,0);
514  int subSec = half ? subsector : 0;
515  std::pair<float,float> xy = locateCell(cell, lay, subSec, true);
516  std::pair<int,int> kcell = assignCell(xy.first, xy.second, layer, subSec,
517  true);
518  return std::pair<int,int>(kcell.second,layer);
519 }
520 
521 int HGCalDDDConstants::newCell(int kx, int ky, int lay, int subSec) const {
522 
523  std::pair<int,float> index = getIndex(lay, true);
524  int i = index.first;
525  if (i < 0) return maxCells(true);
526  float alpha = (subSec == 0) ? hgpar_->moduleAlphaS_[i] : subSec;
527  float cellSize = index.second;
528  float a = (alpha==0) ?
531  float b = 2*hgpar_->moduleHR_[i]*hgpar_->moduleBlR_[i]/
533  int icell(kx);
534  for (int iky=0; iky<ky; ++iky)
535  icell += floor(((iky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize));
536  return icell;
537 }
538 
539 std::vector<int> HGCalDDDConstants::numberCells(int lay, bool reco) const {
540 
541  std::pair<int,float> index = getIndex(lay, reco);
542  int i = index.first;
543  std::vector<int> ncell;
544  if (i >= 0) {
546  float h, bl, tl, alpha;
547  getParameterSquare(i,0,reco,h,bl,tl,alpha);
548  return numberCellsSquare(h, bl, tl, alpha, index.second);
549  } else {
550  for (unsigned int k=0; k<hgpar_->waferTypeT_.size(); ++k) {
551  if (waferInLayer(k,i)) {
552  unsigned int cell = (hgpar_->waferTypeT_[k]==1) ?
553  (hgpar_->cellFineX_.size()) : (hgpar_->cellCoarseX_.size());
554  ncell.emplace_back((int)(cell));
555  }
556  }
557  }
558  }
559  return ncell;
560 }
561 
562 std::vector<int> HGCalDDDConstants::numberCellsSquare(float h, float bl,
563  float tl, float alpha,
564  float cellSize) const {
565 
566  float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
567  float b = 2*h*bl/(tl-bl);
568  int kymax = floor((2*h)/cellSize);
569  std::vector<int> ncell;
570  for (int iky=0; iky<kymax; ++iky)
571  ncell.emplace_back(floor(((iky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize)));
572  return ncell;
573 }
574 
576 
577  int ncell(0);
578  if (wafer >= 0 && wafer < (int)(hgpar_->waferTypeT_.size())) {
579  if (hgpar_->waferTypeT_[wafer]==1)
580  ncell = (int)(hgpar_->cellFineX_.size());
581  else
582  ncell = (int)(hgpar_->cellCoarseX_.size());
583  }
584  return ncell;
585 }
586 
587 std::pair<int,int> HGCalDDDConstants::rowColumnWafer(int wafer) const {
588  int row(0), col(0);
589  if (wafer < (int)(hgpar_->waferCopy_.size())) {
590  int copy = hgpar_->waferCopy_[wafer];
591  col = copy%100;
592  if ((copy/10000)%10 != 0) col = -col;
593  row = (copy/100)%100;
594  if ((copy/100000)%10 != 0) row = -row;
595  }
596  return std::pair<int,int>(row,col);
597 }
598 
599 std::pair<int,int> HGCalDDDConstants::simToReco(int cell, int lay, int mod,
600  bool half) const {
601 
602  std::pair<int,float> index = getIndex(lay, false);
603  int i = index.first;
604  if (i < 0) {
605  return std::pair<int,int>(-1,-1);
606  }
607  int kx(-1), depth(-1);
609  float h = hgpar_->moduleHS_[i];
610  float bl = hgpar_->moduleBlS_[i];
611  float tl = hgpar_->moduleTlS_[i];
612  float cellSize = hgpar_->cellFactor_[i]*index.second;
613 
614  std::pair<int,int> kxy = findCellSquare(cell, h, bl, tl, hgpar_->moduleAlphaS_[i], index.second);
615  depth = hgpar_->layerGroup_[i];
616  if (depth<0) return std::pair<int,int>(-1,-1);
617  kx = kxy.first/hgpar_->cellFactor_[i];
618  int ky = kxy.second/hgpar_->cellFactor_[i];
619 
620  float a = (half) ? (h/(tl-bl)) : (2*h/(tl-bl));
621  float b = 2*h*bl/(tl-bl);
622  for (int iky=0; iky<ky; ++iky)
623  kx += floor(((iky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize));
624 #ifdef EDM_ML_DEBUG
625  std::cout << "simToReco: input " << cell << ":" << lay << ":" << half
626  << " kxy " << kxy.first << ":" << kxy.second << " output "
627  << kx << ":" << depth << " cell factor="
628  << hgpar_->cellFactor_[i] << std::endl;
629 #endif
630  } else {
631  kx = cell;
632  int type = hgpar_->waferTypeL_[mod];
633  if (type == 1) {
634  depth = hgpar_->layerGroup_[i];
635  } else if (type == 2) {
636  depth = hgpar_->layerGroupM_[i];
637  } else {
638  depth = hgpar_->layerGroupO_[i];
639  }
640  }
641  return std::pair<int,int>(kx,depth);
642 }
643 
645  const int ncopies = hgpar_->waferCopy_.size();
646  int wafer(ncopies);
647 #ifdef EDM_ML_DEBUG
648  bool ok(false);
649 #endif
650  for (int k=0; k<ncopies; ++k) {
651  if (copy == hgpar_->waferCopy_[k]) {
652  wafer = k;
653 #ifdef EDM_ML_DEBUG
654  ok = true;
655 #endif
656  break;
657  }
658  }
659 #ifdef EDM_ML_DEBUG
660  if (!ok) {
661  std::cout << "Cannot find " << copy << " in a list of " << ncopies << "\n";
662  for (int k=0; k<ncopies; ++k) std::cout << " " << hgpar_->waferCopy_[k];
663  std::cout << std::endl;
664  }
665 #endif
666  return wafer;
667 }
668 
669 void HGCalDDDConstants::waferFromPosition(const double x, const double y,
670  int& wafer, int& icell,
671  int& celltyp) const {
672 
673  double xx(k_ScaleFromDDD*x), yy(k_ScaleFromDDD*y);
674  int size_ = (int)(hgpar_->waferCopy_.size());
675  wafer = size_;
676  for (int k=0; k<size_; ++k) {
677  double dx = std::abs(xx-hgpar_->waferPosX_[k]);
678  double dy = std::abs(yy-hgpar_->waferPosY_[k]);
679  if (dx <= rmax_ && dy <= hexside_) {
680  if ((dy <= 0.5*hexside_) || (dx <= (2.*rmax_-dy/tan30deg_))) {
681  wafer = k;
682  celltyp = hgpar_->waferTypeT_[k];
683  xx -= hgpar_->waferPosX_[k];
684  yy -= hgpar_->waferPosY_[k];
685  break;
686  }
687  }
688  }
689  if (wafer < size_) {
690  if (celltyp == 1)
691  icell = cellHex(xx, yy, 0.5*k_ScaleFromDDD*hgpar_->cellSize_[0],
693  else
694  icell = cellHex(xx, yy, 0.5*k_ScaleFromDDD*hgpar_->cellSize_[1],
696  }
697 #ifdef EDM_ML_DEBUG
698  std::cout << "Position " << x << ":" << y << " Wafer " << wafer << ":"
699  << size_ << " XX " << xx << ":" << yy << " Cell " << icell
700  << " Type " << celltyp << std::endl;
701 #endif
702 }
703 
704 bool HGCalDDDConstants::waferInLayer(int wafer, int lay, bool reco) const {
705 
706  std::pair<int,float> indx = getIndex(lay, reco);
707  if (indx.first < 0) return false;
708  return waferInLayer(wafer,indx.first);
709 }
710 
711 std::pair<double,double> HGCalDDDConstants::waferPosition(int wafer,
712  bool reco) const {
713 
714  double xx(0), yy(0);
715  if (wafer >= 0 && wafer < (int)(hgpar_->waferPosX_.size())) {
716  xx = hgpar_->waferPosX_[wafer];
717  yy = hgpar_->waferPosY_[wafer];
718  }
719  if (!reco) {
720  xx /= k_ScaleFromDDD;
721  yy /= k_ScaleFromDDD;
722  }
723  std::pair<double,double> xy(xx,yy);
724  return xy;
725 }
726 
727 double HGCalDDDConstants::waferZ(int lay, bool reco) const {
728  std::pair<int,float> index = getIndex(lay, reco);
729  int i = index.first;
730  if (i < 0) return 0;
731  else return hgpar_->zLayerHex_[i];
732 }
733 
735 
736  int wafer(0);
737  for (unsigned int i = 0; i<layers(true); ++i) {
738  int lay = hgpar_->depth_[i];
739  wafer += modules(lay, true);
740  }
741  return wafer;
742 }
743 
744 int HGCalDDDConstants::wafers(int layer, int type) const {
745 
746  int wafer(0);
747  auto itr = waferLayer_.find(layer);
748  if (itr != waferLayer_.end()) {
749  unsigned ity = (type > 0 && type <= 2) ? type : 0;
750  wafer = (itr->second)[ity];
751  }
752  return wafer;
753 }
754 
755 bool HGCalDDDConstants::isHalfCell(int waferType, int cell) const {
756  if( waferType < 1 || cell < 0) return false;
757  return waferType == 2 ? hgpar_->cellCoarseHalf_[cell] : hgpar_->cellFineHalf_[cell];
758 }
759 
760 int HGCalDDDConstants::cellHex(double xx, double yy,
761  const double& cellR,
762  const std::vector<double>& posX,
763  const std::vector<double>& posY) const {
764  int num(0);
765  const double tol(0.00001);
766  double cellY = 2.0*cellR*tan30deg_;
767  for (unsigned int k=0; k<posX.size(); ++k) {
768  double dx = std::abs(xx - posX[k]);
769  double dy = std::abs(yy - posY[k]);
770  if (dx <= (cellR+tol) && dy <= (cellY+tol)) {
771  double xmax = (dy<=0.5*cellY) ? cellR : (cellR-(dy-0.5*cellY)/tan30deg_);
772  if (dx <= (xmax+tol)) {
773  num = k;
774  break;
775  }
776  }
777  }
778  return num;
779 }
780 
781 std::pair<int,float> HGCalDDDConstants::getIndex(int lay, bool reco) const {
782 
783  if (lay<1 || lay>(int)(hgpar_->layerIndex_.size())) return std::pair<int,float>(-1,0);
784  if (reco && lay>(int)(hgpar_->depthIndex_.size())) return std::pair<int,float>(-1,0);
785  int indx(0);
786  float cell(0);
788  indx = (reco ? hgpar_->depthIndex_[lay-1] : hgpar_->layerIndex_[lay-1]);
789  cell = (reco ? hgpar_->moduleCellR_[indx] : hgpar_->moduleCellS_[indx]);
790  } else {
791  indx = (reco ? hgpar_->depthLayerF_[lay-1] : hgpar_->layerIndex_[lay-1]);
792  cell = (reco ? hgpar_->moduleCellR_[0] : hgpar_->moduleCellS_[0]);
793  }
794  return std::pair<int,float>(indx,cell);
795 }
796 
797 void HGCalDDDConstants::getParameterSquare(int lay, int subSec, bool reco,
798  float& h, float& bl, float& tl,
799  float& alpha) const {
800  if (reco) {
801  h = hgpar_->moduleHR_[lay];
802  bl = hgpar_->moduleBlR_[lay];
803  tl = hgpar_->moduleTlR_[lay];
804  alpha= hgpar_->moduleAlphaR_[lay];
805  if ((subSec>0 && alpha<0) || (subSec<=0 && alpha>0)) alpha = -alpha;
806  } else {
807  h = hgpar_->moduleHS_[lay];
808  bl = hgpar_->moduleBlS_[lay];
809  tl = hgpar_->moduleTlS_[lay];
810  alpha= hgpar_->moduleAlphaS_[lay];
811  }
812 }
813 
814 bool HGCalDDDConstants::waferInLayer(int wafer, int lay) const {
815 
816  const double rr = 2*rmax_*tan30deg_;
817  const double waferX = hgpar_->waferPosX_[wafer];
818  const double waferY = hgpar_->waferPosY_[wafer];
819  double xc[6], yc[6];
820  xc[0] = waferX+rmax_; yc[0] = waferY-0.5*rr;
821  xc[1] = waferX+rmax_; yc[1] = waferY+0.5*rr;
822  xc[2] = waferX; yc[2] = waferY+rr;
823  xc[3] = waferX-rmax_; yc[3] = waferY+0.5*rr;
824  xc[4] = waferX+rmax_; yc[4] = waferY-0.5*rr;
825  xc[5] = waferX; yc[5] = waferY-rr;
826  bool cornerOne(false), cornerAll(true);
827  for (int k=0; k<6; ++k) {
828  double rpos = std::sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
829  if ((rpos >= hgpar_->rMinLayHex_[lay]) &&
830  (rpos <= hgpar_->rMaxLayHex_[lay])) cornerOne = true;
831  else cornerAll = false;
832  }
833  bool in(false);
835  in = cornerAll;
837  in = cornerOne;
838  return in;
839 }
840 
842 
bool isHalfCell(int waferType, int cell) const
std::vector< double > waferPosY_
type
Definition: HCALResponse.h:21
std::vector< int > layer_
double k_horizontalShift
std::vector< int > depthLayerF_
float alpha
Definition: AMPTWrapper.h:95
std::vector< int > depth_
std::vector< double > moduleCellR_
std::vector< double > moduleHR_
bool isValid(int lay, int mod, int cell, bool reco) const
layer_map copiesInLayers_
std::vector< int > numberCellsSquare(float h, float bl, float tl, float alpha, float cellSize) const
std::vector< HGCalParameters::hgtrap > getModules() const
std::vector< bool > cellCoarseHalf_
int maxCellsSquare(float h, float bl, float tl, float alpha, float cellSize) const
std::vector< bool > cellFineHalf_
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::array< uint32_t, 2 > tot_layers_
std::map< int, HGCWaferParam > waferLayer_
void waferFromPosition(const double x, const double y, int &wafer, int &icell, int &celltyp) const
std::vector< int > moduleLayR_
double cellSizeHex(int type) const
HGCalParameters::hgtrform getTrForm(unsigned int k) const
Simrecovecs max_modules_layer_
unsigned int layersInit(bool reco) const
std::vector< double > moduleHS_
std::array< int, 4 > waferMax_
int maxRows(int lay, bool reco) const
std::vector< int > numberCells(int lay, bool reco) const
std::vector< double > cellFineY_
std::pair< int, int > findCellSquare(int cell, float h, float bl, float tl, float alpha, float cellSize) const
static const int modmax
Definition: herwig.h:133
std::pair< int, int > assignCellSquare(float x, float y, float h, float bl, float tl, float alpha, float cellSize) 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_
std::vector< int > layerGroupM_
HGCalGeometryMode::GeometryMode mode_
HGCalGeometryMode::GeometryMode mode_
#define constexpr
std::vector< int > cellFactor_
int cellHex(double xx, double yy, const double &cellR, const std::vector< double > &posX, const std::vector< double > &posY) const
std::pair< float, float > locateCellHex(int cell, int wafer, bool reco) const
std::vector< double > cellCoarseX_
int modules(int lay, bool reco) const
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
unsigned int getTrFormN() const
unsigned int layers(bool reco) const
int numberCellsHexagon(int wafer) const
std::vector< double > cellSize_
std::vector< HGCalParameters::hgtrform > getTrForms() const
std::pair< int, int > assignCellHexagon(float x, float y) const
std::pair< double, double > waferPosition(int wafer, bool reco=true) const
std::vector< int > layerIndex_
std::vector< double > moduleAlphaR_
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
hgtrform getTrForm(unsigned int k) const
T sqrt(T t)
Definition: SSEVec.h:18
std::pair< int, int > findCell(int cell, int lay, int subSec, bool reco) const
std::pair< int, float > getIndex(int lay, bool reco) const
HGCalDDDConstants(const HGCalParameters *hp, const std::string &name)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
hgtrap getModule(unsigned int k, bool reco) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< double > moduleBlR_
bool isValidCell(int layindex, int wafer, int cell) const
int sectors() const
std::vector< double > rMinLayHex_
std::vector< double > moduleTlS_
std::pair< int, int > rowColumnWafer(const int wafer) const
std::vector< double > zLayerHex_
double waferZ(int layer, bool reco) const
int k[5][pyjets_maxn]
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:96
std::vector< double > rMaxLayHex_
int waferFromCopy(int copy) const
void getParameterSquare(int lay, int subSec, bool reco, float &h, float &bl, float &tl, float &alpha) const
std::vector< int > layerGroup_
std::vector< double > moduleCellS_
double b
Definition: hdecay.h:120
std::vector< double > cellFineX_
std::pair< int, int > newCell(int cell, int layer, int sector, int subsector, int incrx, int incry, bool half) const
std::vector< double > moduleAlphaS_
std::vector< int > layerGroupO_
fixed size matrix
std::vector< double > moduleBlS_
if(dp >Float(M_PI)) dp-
double a
Definition: hdecay.h:121
std::vector< int > waferCopy_
col
Definition: cuy.py:1008
std::vector< int > depthIndex_
std::pair< int, int > assignCell(float x, float y, int lay, int subSec, bool reco) const
double k_ScaleFromDDD
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< double > moduleTlR_
std::vector< int > waferTypeL_
static double tan30deg_
std::array< int, 3 > HGCWaferParam
bool waferInLayer(int wafer, int lay, bool reco) const