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) {
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  << " wafers, " << 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 }
79 
81 
82 std::pair<int,int> HGCalDDDConstants::assignCell(float x, float y, int lay,
83  int subSec, bool reco) const {
84  std::pair<int,float> index = getIndex(lay, reco);
85  std::pair<int,int> cellAssignment(-1,-1);
86  int i = index.first;
87  if (i < 0) return cellAssignment;
89  float alpha, h, bl, tl;
90  getParameterSquare(i,subSec,reco,h,bl,tl,alpha);
91  cellAssignment = assignCellSquare(x, y, h, bl, tl, alpha, index.second);
92  } else {
93  float xx = (reco) ? x : k_ScaleFromDDD*x;
94  float yy = (reco) ? y : k_ScaleFromDDD*y;
95  cellAssignment = assignCellHexagon(xx,yy);
96  }
97  return cellAssignment;
98 }
99 
100 std::pair<int,int> HGCalDDDConstants::assignCellSquare(float x, float y,
101  float h, float bl,
102  float tl, float alpha,
103  float cellSize) const {
104 
105  float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
106  float b = 2*h*bl/(tl-bl);
107 
108  float x0(x);
109  int phiSector = (x0 > 0) ? 1 : 0;
110  if (alpha < 0) {x0 -= 0.5*(tl+bl); phiSector = 0;}
111  else if (alpha > 0) {x0 += 0.5*(tl+bl); phiSector = 1;}
112 
113  //determine the i-y
114  int ky = floor((y+h)/cellSize);
115  if (ky*cellSize> y+h) ky--;
116  if (ky<0) return std::pair<int,int>(-1,-1);
117  if ((ky+1)*cellSize < (y+h) ) ky++;
118  int max_ky_allowed=floor(2*h/cellSize);
119  if (ky>max_ky_allowed-1) return std::pair<int,int>(-1,-1);
120 
121  //determine the i-x
122  //notice we substitute y by the top of the candidate cell to reduce the dead zones
123  int kx = floor(fabs(x0)/cellSize);
124  if (kx*cellSize > fabs(x0) ) kx--;
125  if (kx<0) return std::pair<int,int>(-1,-1);
126  if ((kx+1)*cellSize < fabs(x0)) kx++;
127  int max_kx_allowed=floor( ((ky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize) );
128  if (kx>max_kx_allowed-1) return std::pair<int,int>(-1,-1);
129 
130  //count cells summing in rows until required height
131  //notice the bottom of the cell must be used
132  int icell(0);
133  for (int iky=0; iky<ky; ++iky) {
134  int cellsInRow( floor( ((iky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize) ) );
135  icell += cellsInRow;
136  }
137  icell += kx;
138 
139  //return result
140  return std::pair<int,int>(phiSector,icell);
141 }
142 
143 std::pair<int,int> HGCalDDDConstants::assignCellHexagon(float x,
144  float y) const {
145  double xx(x), yy(y);
146  //First the wafer
147  int wafer = cellHex(xx, yy, rmax_, hgpar_->waferPosX_, hgpar_->waferPosY_);
148  // Now the cell
149  xx -= hgpar_->waferPosX_[wafer];
150  yy -= hgpar_->waferPosY_[wafer];
151  int cell(0);
152  if (hgpar_->waferTypeT_[wafer] == 1)
154  else
156  return std::pair<int,int>(wafer,cell);
157 }
158 
160  int indx = (type == 1) ? 0 : 1;
161  double cell = (0.5*k_ScaleFromDDD*hgpar_->cellSize_[indx]);
162  return cell;
163 }
164 
165 unsigned int HGCalDDDConstants::layers(bool reco) const {
166  return tot_layers_[(int)reco];
167 }
168 
169 unsigned int HGCalDDDConstants::layersInit(bool reco) const {
170  return (reco ? hgpar_->depthIndex_.size() : hgpar_->layerIndex_.size());
171 }
172 
173 std::pair<int,int> HGCalDDDConstants::findCell(int cell, int lay, int subSec,
174  bool reco) const {
175 
176  std::pair<int,float> index = getIndex(lay, reco);
177  int i = index.first;
178  if (i < 0) return std::pair<int,int>(-1,-1);
180  return std::pair<int,int>(-1,-1);
181  } else {
182  float alpha, h, bl, tl;
183  getParameterSquare(i,subSec,reco,h,bl,tl,alpha);
184  return findCellSquare(cell, h, bl, tl, alpha, index.second);
185  }
186 }
187 
188 std::pair<int,int> HGCalDDDConstants::findCellSquare(int cell, float h,
189  float bl, float tl,
190  float alpha,
191  float cellSize) const {
192 
193  //check if cell number is meaningful
194  if(cell<0) return std::pair<int,int>(-1,-1);
195 
196  //parameterization of the boundary of the trapezoid
197  float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
198  float b = 2*h*bl/(tl-bl);
199  int kx(cell), ky(0);
200  int kymax( floor((2*h)/cellSize) );
201  int testCell(0);
202  for (int iky=0; iky<kymax; ++iky) {
203 
204  //check if adding all the cells in this row is above the required cell
205  //notice the top of the cell is used to maximize space
206  int cellsInRow(floor(((iky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize)));
207  if (testCell+cellsInRow > cell) break;
208  testCell += cellsInRow;
209  ky++;
210  kx -= cellsInRow;
211  }
212 
213  return std::pair<int,int>(kx,ky);
214 }
215 
217  bool hexType,
218  bool reco) const {
219 
221  if (hexType) {
222  unsigned int type = (indx < hgpar_->waferTypeL_.size()) ?
223  hgpar_->waferTypeL_[indx] : 3;
224  if (type > 0) --type;
225  mytr = hgpar_->getModule(type, true);
226  } else {
227  if (reco) mytr = hgpar_->getModule(indx,true);
228  else mytr = hgpar_->getModule(indx,false);
229  }
230  return mytr;
231 }
232 
233 std::vector<HGCalParameters::hgtrap> HGCalDDDConstants::getModules() const {
234 
235  std::vector<HGCalParameters::hgtrap> mytrs;
236  for (unsigned int k=0; k<hgpar_->moduleLayR_.size(); ++k)
237  mytrs.push_back(hgpar_->getModule(k,true));
238  return mytrs;
239 }
240 
241 std::vector<HGCalParameters::hgtrform> HGCalDDDConstants::getTrForms() const {
242 
243  std::vector<HGCalParameters::hgtrform> mytrs;
244  for (unsigned int k=0; k<hgpar_->trformIndex_.size(); ++k)
245  mytrs.push_back(hgpar_->getTrForm(k));
246  return mytrs;
247 }
248 
249 bool HGCalDDDConstants::isValid(int lay, int mod, int cell, bool reco) const {
250 
251  bool ok(false);
252  int cellmax(0), modmax(0);
254  cellmax = maxCells(lay,reco);
255  modmax = sectors();
256  ok = ((lay > 0 && lay <= (int)(layers(reco))) &&
257  (mod > 0 && mod <= modmax) &&
258  (cell >=0 && cell <= cellmax));
259  } else {
260  int32_t copyNumber = hgpar_->waferCopy_[mod];
261  ok = ((lay > 0 && lay <= (int)(layers(reco))));
262  if (ok) {
263  const int32_t lay_idx = reco ? (lay-1)*3 + 1 : lay;
264  const auto& the_modules = hgpar_->copiesInLayers_[lay_idx];
265  auto moditr = the_modules.find(copyNumber);
266  ok = (moditr != the_modules.end());
267 #ifdef EDM_ML_DEBUG
268  if (!ok) std::cout << "HGCalDDDConstants: Layer " << lay << ":"
269  << lay_idx << " Copy " << copyNumber << ":" << mod
270  << " Flag " << ok << std::endl;
271 #endif
272  if (ok) {
273  if (moditr->second >= 0) {
274  cellmax = (hgpar_->waferTypeT_[mod]==1) ?
275  (int)(hgpar_->cellFineX_.size()) : (int)(hgpar_->cellCoarseX_.size());
276  ok = (cell >=0 && cell <= cellmax);
277  } else {
278  ok = isValidCell(lay_idx, mod, cell);
279  }
280  }
281  }
282  }
283 
284 #ifdef EDM_ML_DEBUG
285  if (!ok) std::cout << "HGCalDDDConstants: Layer " << lay << ":"
286  << (lay > 0 && (lay <= (int)(layers(reco)))) << " Module "
287  << mod << ":" << modmax << ":"
288  << (mod > 0 && mod <= modmax) << " Cell " << cell << ":"
289  << cellmax << ":" << (cell >=0 && cell <= cellmax)
290  << ":" << maxCells(reco) << std::endl;
291 #endif
292  return ok;
293 }
294 
295 bool HGCalDDDConstants::isValidCell(int lay, int wafer, int cell) const {
296 
297  // Calculate the position of the cell
298  double x = hgpar_->waferPosX_[wafer];
299  double y = hgpar_->waferPosY_[wafer];
300  if (hgpar_->waferTypeT_[wafer] == 1) {
301  x += hgpar_->cellFineX_[cell];
302  y += hgpar_->cellFineY_[cell];
303  } else {
304  x += hgpar_->cellCoarseX_[cell];
305  y += hgpar_->cellCoarseY_[cell];
306  }
307  double rr = sqrt(x*x+y*y);
308  bool ok = ((rr >= hgpar_->rMinLayHex_[lay-1]) &
309  (rr <= hgpar_->rMaxLayHex_[lay-1]));
310 #ifdef EDM_ML_DEBUG
311  if (!ok)
312  std::cout << "Input " << lay << ":" << wafer << ":" << cell << " Position "
313  << x << ":" << y << ":" << rr << " Compare Limits "
314  << hgpar_->rMinLayHex_[lay-1] << ":" <<hgpar_->rMaxLayHex_[lay-1]
315  << " Flag " << ok << std::endl;
316 #endif
317  return ok;
318 }
319 
320 std::pair<float,float> HGCalDDDConstants::locateCell(int cell, int lay,
321  int type, bool reco) const {
322  // type refers to subsector # for square cell and wafer # for hexagon cell
323  float x(999999.), y(999999.);
324  std::pair<int,float> index = getIndex(lay, reco);
325  int i = index.first;
326  if (i < 0) return std::pair<float,float>(x,y);
328  std::pair<int,int> kxy = findCell(cell, lay, type, reco);
329  float alpha, h, bl, tl;
330  getParameterSquare(i,type,reco,h,bl,tl,alpha);
331  float cellSize = index.second;
332  x = (kxy.first+0.5)*cellSize;
333  if (alpha < 0) x -= 0.5*(tl+bl);
334  else if (alpha > 0) x -= 0.5*(tl+bl);
335  if (type != 1) x = -x;
336  y = ((kxy.second+0.5)*cellSize-h);
337  } else {
338  x = hgpar_->waferPosX_[type];
339  y = hgpar_->waferPosY_[type];
340  if (hgpar_->waferTypeT_[type] == 1) {
341  x += hgpar_->cellFineX_[cell];
342  y += hgpar_->cellFineY_[cell];
343  } else {
344  x += hgpar_->cellCoarseX_[cell];
345  y += hgpar_->cellCoarseY_[cell];
346  }
347  if (!reco) {
348  x /= k_ScaleFromDDD;
349  y /= k_ScaleFromDDD;
350  }
351  }
352  return std::pair<float,float>(x,y);
353 }
354 
355 std::pair<float,float> HGCalDDDConstants::locateCellHex(int cell, int wafer,
356  bool reco) const {
357  float x(0), y(0);
358  if (hgpar_->waferTypeT_[wafer] == 1) {
359  x = hgpar_->cellFineX_[cell];
360  y = hgpar_->cellFineY_[cell];
361  } else {
362  x = hgpar_->cellCoarseX_[cell];
363  y = hgpar_->cellCoarseY_[cell];
364  }
365  if (!reco) {
366  x /= k_ScaleFromDDD;
367  y /= k_ScaleFromDDD;
368  }
369  return std::pair<float,float>(x,y);
370 }
371 
373 
374  int cells(0);
375  for (unsigned int i = 0; i<layers(reco); ++i) {
376  int lay = reco ? hgpar_->depth_[i] : hgpar_->layer_[i];
377  if (cells < maxCells(lay, reco)) cells = maxCells(lay, reco);
378  }
379  return cells;
380 }
381 
382 int HGCalDDDConstants::maxCells(int lay, bool reco) const {
383 
384  std::pair<int,float> index = getIndex(lay, reco);
385  int i = index.first;
386  if (i < 0) return 0;
388  float h, bl, tl, alpha;
389  getParameterSquare(i,0,reco,h,bl,tl,alpha);
390  return maxCellsSquare(h, bl, tl, alpha, index.second);
391  } else {
392  unsigned int cells(0);
393  for (unsigned int k=0; k<hgpar_->waferTypeT_.size(); ++k) {
394  if (waferInLayer(k,index.first)) {
395  unsigned int cell = (hgpar_->waferTypeT_[k]==1) ?
396  (hgpar_->cellFineX_.size()) : (hgpar_->cellCoarseX_.size());
397  if (cell > cells) cells = cell;
398  }
399  }
400  return (int)(cells);
401  }
402 }
403 
404 int HGCalDDDConstants::maxCellsSquare(float h, float bl, float tl,
405  float alpha, float cellSize) const {
406 
407  float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
408  float b = 2*h*bl/(tl-bl);
409 
410  int ncells(0);
411  //always use the top of the cell to maximize space
412  int kymax = floor((2*h)/cellSize);
413  for (int iky=0; iky<kymax; ++iky) {
414  int cellsInRow=floor(((iky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize));
415  ncells += cellsInRow;
416  }
417 
418  return ncells;
419 }
420 
421 int HGCalDDDConstants::maxRows(int lay, bool reco) const {
422 
423  int kymax(0);
424  std::pair<int,float> index = getIndex(lay, reco);
425  int i = index.first;
426  if (i < 0) return kymax;
428  float h = (reco) ? hgpar_->moduleHR_[i] : hgpar_->moduleHS_[i];
429  kymax = floor((2*h)/index.second);
430  } else {
431  for (unsigned int k=0; k<hgpar_->waferCopy_.size(); ++k) {
432  if (waferInLayer(k,i)) {
433  int ky = ((hgpar_->waferCopy_[k])/100)%100;
434  if (ky > kymax) kymax = ky;
435  }
436  }
437  }
438  return kymax;
439 }
440 
441 int HGCalDDDConstants::modules(int lay, bool reco) const {
442  if( getIndex(lay,reco).first < 0 ) return 0;
443  return max_modules_layer_[(int)reco][lay];
444 }
445 
446 int HGCalDDDConstants::modulesInit(int lay, bool reco) const {
447  int nmod(0);
448  std::pair<int,float> index = getIndex(lay, reco);
449  if (index.first < 0) return nmod;
450  for (unsigned int k=0; k<hgpar_->waferPosX_.size(); ++k) {
451  if (waferInLayer(k,index.first)) ++nmod;
452  }
453  return nmod;
454 }
455 
456 std::pair<int,int> HGCalDDDConstants::newCell(int cell, int layer, int sector,
457  int subsector, int incrx,
458  int incry, bool half) const {
459 
460  int subSec = half ? subsector : 0;
461  std::pair<int,int> kxy = findCell(cell, layer, subSec, true);
462  int kx = kxy.first + incrx;
463  int ky = kxy.second + incry;
464  if (ky < 0 || ky > maxRows(layer, true)) {
465  cell = maxCells(true);
466  return std::pair<int,int>(cell,sector*subsector);
467  } else if (kx < 0) {
468  kx =-kx;
469  subsector =-subsector;
470  } else if (kx > maxCells(layer, true)) {
471  kx -= maxCells(layer, true);
472  sector += subsector;
473  subsector =-subsector;
474  if (sector < 1) sector = hgpar_->nSectors_;
475  else if (sector > hgpar_->nSectors_) sector = 1;
476  }
477  cell = newCell(kx, ky, layer, subSec);
478  return std::pair<int,int>(cell,sector*subsector);
479 }
480 
481 std::pair<int,int> HGCalDDDConstants::newCell(int cell, int lay, int subsector,
482  int incrz, bool half) const {
483 
484  int layer = lay + incrz;
485  if (layer <= 0 || layer > (int)(layers(true))) return std::pair<int,int>(cell,0);
486  int subSec = half ? subsector : 0;
487  std::pair<float,float> xy = locateCell(cell, lay, subSec, true);
488  std::pair<int,int> kcell = assignCell(xy.first, xy.second, layer, subSec,
489  true);
490  return std::pair<int,int>(kcell.second,layer);
491 }
492 
493 int HGCalDDDConstants::newCell(int kx, int ky, int lay, int subSec) const {
494 
495  std::pair<int,float> index = getIndex(lay, true);
496  int i = index.first;
497  if (i < 0) return maxCells(true);
498  float alpha = (subSec == 0) ? hgpar_->moduleAlphaS_[i] : subSec;
499  float cellSize = index.second;
500  float a = (alpha==0) ?
503  float b = 2*hgpar_->moduleHR_[i]*hgpar_->moduleBlR_[i]/
505  int icell(kx);
506  for (int iky=0; iky<ky; ++iky)
507  icell += floor(((iky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize));
508  return icell;
509 }
510 
511 std::vector<int> HGCalDDDConstants::numberCells(int lay, bool reco) const {
512 
513  std::pair<int,float> index = getIndex(lay, reco);
514  int i = index.first;
515  std::vector<int> ncell;
516  if (i >= 0) {
518  float h, bl, tl, alpha;
519  getParameterSquare(i,0,reco,h,bl,tl,alpha);
520  return numberCellsSquare(h, bl, tl, alpha, index.second);
521  } else {
522  for (unsigned int k=0; k<hgpar_->waferTypeT_.size(); ++k) {
523  if (waferInLayer(k,i)) {
524  unsigned int cell = (hgpar_->waferTypeT_[k]==1) ?
525  (hgpar_->cellFineX_.size()) : (hgpar_->cellCoarseX_.size());
526  ncell.push_back((int)(cell));
527  }
528  }
529  }
530  }
531  return ncell;
532 }
533 
534 std::vector<int> HGCalDDDConstants::numberCellsSquare(float h, float bl,
535  float tl, float alpha,
536  float cellSize) const {
537 
538  float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
539  float b = 2*h*bl/(tl-bl);
540  int kymax = floor((2*h)/cellSize);
541  std::vector<int> ncell;
542  for (int iky=0; iky<kymax; ++iky)
543  ncell.push_back(floor(((iky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize)));
544  return ncell;
545 }
546 
548 
549  int ncell(0);
550  if (wafer >= 0 && wafer < (int)(hgpar_->waferTypeT_.size())) {
551  if (hgpar_->waferTypeT_[wafer]==1)
552  ncell = (int)(hgpar_->cellFineX_.size());
553  else
554  ncell = (int)(hgpar_->cellCoarseX_.size());
555  }
556  return ncell;
557 }
558 
559 std::pair<int,int> HGCalDDDConstants::rowColumnWafer(int wafer) const {
560  int row(0), col(0);
561  if (wafer < (int)(hgpar_->waferCopy_.size())) {
562  int copy = hgpar_->waferCopy_[wafer];
563  col = copy%100;
564  if ((copy/10000)%10 != 0) col = -col;
565  row = (copy/100)%100;
566  if ((copy/100000)%10 != 0) row = -row;
567  }
568  return std::pair<int,int>(row,col);
569 }
570 
571 std::pair<int,int> HGCalDDDConstants::simToReco(int cell, int lay, int mod,
572  bool half) const {
573 
574  std::pair<int,float> index = getIndex(lay, false);
575  int i = index.first;
576  if (i < 0) {
577  return std::pair<int,int>(-1,-1);
578  }
579  int kx(-1), depth(-1);
581  float h = hgpar_->moduleHS_[i];
582  float bl = hgpar_->moduleBlS_[i];
583  float tl = hgpar_->moduleTlS_[i];
584  float cellSize = hgpar_->cellFactor_[i]*index.second;
585 
586  std::pair<int,int> kxy = findCellSquare(cell, h, bl, tl, hgpar_->moduleAlphaS_[i], index.second);
587  depth = hgpar_->layerGroup_[i];
588  if (depth<0) return std::pair<int,int>(-1,-1);
589  kx = kxy.first/hgpar_->cellFactor_[i];
590  int ky = kxy.second/hgpar_->cellFactor_[i];
591 
592  float a = (half) ? (h/(tl-bl)) : (2*h/(tl-bl));
593  float b = 2*h*bl/(tl-bl);
594  for (int iky=0; iky<ky; ++iky)
595  kx += floor(((iky+1)*cellSize+b+k_horizontalShift*cellSize)/(a*cellSize));
596 #ifdef EDM_ML_DEBUG
597  std::cout << "simToReco: input " << cell << ":" << lay << ":" << half
598  << " kxy " << kxy.first << ":" << kxy.second << " output "
599  << kx << ":" << depth << " cell factor="
600  << hgpar_->cellFactor_[i] << std::endl;
601 #endif
602  } else {
603  kx = cell;
604  int type = hgpar_->waferTypeL_[mod];
605  if (type == 1) {
606  depth = hgpar_->layerGroup_[i];
607  } else if (type == 2) {
608  depth = hgpar_->layerGroupM_[i];
609  } else {
610  depth = hgpar_->layerGroupO_[i];
611  }
612  }
613  return std::pair<int,int>(kx,depth);
614 }
615 
617  const int ncopies = hgpar_->waferCopy_.size();
618  int wafer(ncopies);
619 #ifdef EDM_ML_DEBUG
620  bool ok(false);
621 #endif
622  for (int k=0; k<ncopies; ++k) {
623  if (copy == hgpar_->waferCopy_[k]) {
624  wafer = k;
625 #ifdef EDM_ML_DEBUG
626  ok = true;
627 #endif
628  break;
629  }
630  }
631 #ifdef EDM_ML_DEBUG
632  if (!ok) {
633  std::cout << "Cannot find " << copy << " in a list of " << ncopies << "\n";
634  for (int k=0; k<ncopies; ++k) std::cout << " " << hgpar_->waferCopy_[k];
635  std::cout << std::endl;
636  }
637 #endif
638  return wafer;
639 }
640 
641 void HGCalDDDConstants::waferFromPosition(const double x, const double y,
642  int& wafer, int& icell,
643  int& celltyp) const {
644 
645  double xx(k_ScaleFromDDD*x), yy(k_ScaleFromDDD*y);
646  int size_ = (int)(hgpar_->waferCopy_.size());
647  wafer = size_;
648  for (int k=0; k<size_; ++k) {
649  double dx = std::abs(xx-hgpar_->waferPosX_[k]);
650  double dy = std::abs(yy-hgpar_->waferPosY_[k]);
651  if (dx <= rmax_ && dy <= hexside_) {
652  if ((dy <= 0.5*hexside_) || (dx <= (2.*rmax_-dy/tan30deg_))) {
653  wafer = k;
654  celltyp = hgpar_->waferTypeT_[k];
655  xx -= hgpar_->waferPosX_[k];
656  yy -= hgpar_->waferPosY_[k];
657  break;
658  }
659  }
660  }
661  if (wafer < size_) {
662  if (celltyp == 1)
663  icell = cellHex(xx, yy, 0.5*k_ScaleFromDDD*hgpar_->cellSize_[0],
665  else
666  icell = cellHex(xx, yy, 0.5*k_ScaleFromDDD*hgpar_->cellSize_[1],
668  }
669 #ifdef EDM_ML_DEBUG
670  std::cout << "Position " << x << ":" << y << " Wafer " << wafer << ":"
671  << size_ << " XX " << xx << ":" << yy << " Cell " << icell
672  << " Type " << celltyp << std::endl;
673 #endif
674 }
675 
676 bool HGCalDDDConstants::waferInLayer(int wafer, int lay, bool reco) const {
677 
678  std::pair<int,float> indx = getIndex(lay, reco);
679  if (indx.first < 0) return false;
680  return waferInLayer(wafer,indx.first);
681 }
682 
683 std::pair<double,double> HGCalDDDConstants::waferPosition(int wafer,
684  bool reco) const {
685 
686  double xx(0), yy(0);
687  if (wafer >= 0 && wafer < (int)(hgpar_->waferPosX_.size())) {
688  xx = hgpar_->waferPosX_[wafer];
689  yy = hgpar_->waferPosY_[wafer];
690  }
691  if (!reco) {
692  xx /= k_ScaleFromDDD;
693  yy /= k_ScaleFromDDD;
694  }
695  std::pair<double,double> xy(xx,yy);
696  return xy;
697 }
698 
699 double HGCalDDDConstants::waferZ(int lay, bool reco) const {
700  std::pair<int,float> index = getIndex(lay, reco);
701  int i = index.first;
702  if (i < 0) return 0;
703  else return hgpar_->zLayerHex_[i];
704 }
705 
707 
708  int wafer(0);
709  for (unsigned int i = 0; i<layers(true); ++i) {
710  int lay = hgpar_->depth_[i];
711  wafer += modules(lay, true);
712  }
713  return wafer;
714 }
715 
716 bool HGCalDDDConstants::isHalfCell(int waferType, int cell) const {
717  if( waferType < 1 || cell < 0) return false;
718  return waferType == 2 ? hgpar_->cellCoarseHalf_[cell] : hgpar_->cellFineHalf_[cell];
719 }
720 
721 int HGCalDDDConstants::cellHex(double xx, double yy,
722  const double& cellR,
723  const std::vector<double>& posX,
724  const std::vector<double>& posY) const {
725  int num(0);
726  const double tol(0.00001);
727  double cellY = 2.0*cellR*tan30deg_;
728  for (unsigned int k=0; k<posX.size(); ++k) {
729  double dx = std::abs(xx - posX[k]);
730  double dy = std::abs(yy - posY[k]);
731  if (dx <= (cellR+tol) && dy <= (cellY+tol)) {
732  double xmax = (dy<=0.5*cellY) ? cellR : (cellR-(dy-0.5*cellY)/tan30deg_);
733  if (dx <= (xmax+tol)) {
734  num = k;
735  break;
736  }
737  }
738  }
739  return num;
740 }
741 
742 std::pair<int,float> HGCalDDDConstants::getIndex(int lay, bool reco) const {
743 
744  if (lay<1 || lay>(int)(hgpar_->layerIndex_.size())) return std::pair<int,float>(-1,0);
745  if (reco && lay>(int)(hgpar_->depthIndex_.size())) return std::pair<int,float>(-1,0);
746  int indx(0);
747  float cell(0);
749  indx = (reco ? hgpar_->depthIndex_[lay-1] : hgpar_->layerIndex_[lay-1]);
750  cell = (reco ? hgpar_->moduleCellR_[indx] : hgpar_->moduleCellS_[indx]);
751  } else {
752  indx = (reco ? hgpar_->depthLayerF_[lay-1] : hgpar_->layerIndex_[lay-1]);
753  cell = (reco ? hgpar_->moduleCellR_[0] : hgpar_->moduleCellS_[0]);
754  }
755  return std::pair<int,float>(indx,cell);
756 }
757 
758 void HGCalDDDConstants::getParameterSquare(int lay, int subSec, bool reco,
759  float& h, float& bl, float& tl,
760  float& alpha) const {
761  if (reco) {
762  h = hgpar_->moduleHR_[lay];
763  bl = hgpar_->moduleBlR_[lay];
764  tl = hgpar_->moduleTlR_[lay];
765  alpha= hgpar_->moduleAlphaR_[lay];
766  if ((subSec>0 && alpha<0) || (subSec<=0 && alpha>0)) alpha = -alpha;
767  } else {
768  h = hgpar_->moduleHS_[lay];
769  bl = hgpar_->moduleBlS_[lay];
770  tl = hgpar_->moduleTlS_[lay];
771  alpha= hgpar_->moduleAlphaS_[lay];
772  }
773 }
774 
775 bool HGCalDDDConstants::waferInLayer(int wafer, int lay) const {
776 
777  const double rr = 2*rmax_*tan30deg_;
778  const double waferX = hgpar_->waferPosX_[wafer];
779  const double waferY = hgpar_->waferPosY_[wafer];
780  double xc[6], yc[6];
781  xc[0] = waferX+rmax_; yc[0] = waferY-0.5*rr;
782  xc[1] = waferX+rmax_; yc[1] = waferY+0.5*rr;
783  xc[2] = waferX; yc[2] = waferY+rr;
784  xc[3] = waferX-rmax_; yc[3] = waferY+0.5*rr;
785  xc[4] = waferX+rmax_; yc[4] = waferY-0.5*rr;
786  xc[5] = waferX; yc[5] = waferY-rr;
787  bool cornerOne(false), cornerAll(true);
788  for (int k=0; k<6; ++k) {
789  double rpos = std::sqrt(xc[k]*xc[k]+yc[k]*yc[k]);
790  if ((rpos >= hgpar_->rMinLayHex_[lay]) &&
791  (rpos <= hgpar_->rMaxLayHex_[lay])) cornerOne = true;
792  else cornerAll = false;
793  }
794  bool in(false);
795  if (hgpar_->mode_ == static_cast<int> (HGCalGeometryMode::Hexagon))
796  in = cornerAll;
797  else if (hgpar_->mode_ == static_cast<int> (HGCalGeometryMode::HexagonFull))
798  in = cornerOne;
799  return in;
800 }
801 
803 
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_
void waferFromPosition(const double x, const double y, int &wafer, int &icell, int &celltyp) const
std::vector< int > moduleLayR_
double cellSizeHex(int type) const
unsigned int layersInit(bool reco) const
std::vector< double > moduleHS_
HGCalDDDConstants(const HGCalParameters *hp, const std::string name)
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_
#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 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
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_
HGCalGeometryMode
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
HGCalGeometryMode mode_
std::vector< double > cellFineX_
std::pair< int, int > newCell(int cell, int layer, int sector, int subsector, int incrx, int incry, bool half) const
simrecovecs max_modules_layer_
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_
bool waferInLayer(int wafer, int lay, bool reco) const