12 #include "CLHEP/Units/GlobalPhysicalConstants.h"
13 #include "CLHEP/Units/GlobalSystemOfUnits.h"
26 for(
int simreco = 0; simreco < 2; ++simreco ) {
30 edm::LogInfo(
"HGCalGeom") <<
"HGCalDDDConstants initialized for " << name
32 <<
" layers, " <<
sectors() <<
" sectors and "
33 <<
"maximum of " <<
maxCells(
false) <<
":"
36 std::cout <<
"HGCalDDDConstants initialized for " << name <<
" with "
39 <<
":" <<
maxCells(
true) <<
" cells" << std::endl;
45 for(
int simreco = 0; simreco < 2; ++simreco ) {
48 for(
unsigned int layer = 1; layer <=
tot_layers_[simreco]; ++layer ) {
54 edm::LogInfo(
"HGCalGeom") <<
"HGCalDDDConstants initialized for " << name
56 <<
" layers, " <<
wafers() <<
" wafers and "
57 <<
"maximum of " <<
maxCells(
false) <<
":"
61 std::cout <<
"HGCalDDDConstants initialized for " << name <<
" with "
64 <<
":" <<
maxCells(
true) <<
" cells" << std::endl;
74 int subSec,
bool reco)
const {
76 std::pair<int,int> cellAssignment(-1,-1);
78 if (i < 0)
return cellAssignment;
88 return cellAssignment;
93 float tl,
float alpha,
94 float cellSize)
const {
96 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
97 float b = 2*h*bl/(tl-bl);
100 int phiSector = (x0 > 0) ? 1 : 0;
101 if (alpha < 0) {x0 -= 0.5*(tl+bl); phiSector = 0;}
102 else if (alpha > 0) {x0 += 0.5*(tl+bl); phiSector = 1;}
105 int ky = floor((y+h)/cellSize);
106 if (ky*cellSize> y+h) ky--;
107 if (ky<0)
return std::pair<int,int>(-1,-1);
108 if ((ky+1)*cellSize < (y+
h) ) ky++;
109 int max_ky_allowed=floor(2*h/cellSize);
110 if (ky>max_ky_allowed-1)
return std::pair<int,int>(-1,-1);
114 int kx = floor(fabs(x0)/cellSize);
115 if (kx*cellSize > fabs(x0) ) kx--;
116 if (kx<0)
return std::pair<int,int>(-1,-1);
117 if ((kx+1)*cellSize < fabs(x0)) kx++;
118 int max_kx_allowed=floor( ((ky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize) );
119 if (kx>max_kx_allowed-1)
return std::pair<int,int>(-1,-1);
124 for (
int iky=0; iky<ky; ++iky) {
125 int cellsInRow( floor( ((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize) ) );
131 return std::pair<int,int>(phiSector,icell);
147 return std::pair<int,int>(wafer,cell);
151 int indx = (type == 1) ? 0 : 1;
169 if (i < 0)
return std::pair<int,int>(-1,-1);
171 return std::pair<int,int>(-1,-1);
182 float cellSize)
const {
185 if(cell<0)
return std::pair<int,int>(-1,-1);
188 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
189 float b = 2*h*bl/(tl-bl);
191 int kymax( floor((2*h)/cellSize) );
193 for (
int iky=0; iky<kymax; ++iky) {
197 int cellsInRow(floor(((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize)));
198 if (testCell+cellsInRow > cell)
break;
199 testCell += cellsInRow;
204 return std::pair<int,int>(kx,ky);
226 std::vector<HGCalParameters::hgtrap> mytrs;
234 std::vector<HGCalParameters::hgtrform> mytrs;
243 int cellmax(0),
modmax(0);
247 ok = ((lay > 0 && lay <= (int)(
layers(reco))) &&
248 (mod > 0 && mod <=
modmax) &&
249 (cell >=0 && cell <= cellmax));
254 ok = ((lay > 0 && lay <= (int)(
layers(reco))));
256 const int32_t lay_idx = reco ? (lay-1)*3 + 1 : lay;
258 auto moditr = the_modules.find(copyNumber);
259 ok = (moditr != the_modules.end());
263 ok = (cell >=0 && cell <= cellmax);
269 if (!ok)
std::cout <<
"HGCalDDDConstants: Layer " << lay <<
":"
270 << (lay > 0 && (lay <= (int)(
layers(reco)))) <<
" Module "
271 << mod <<
":" << (mod > 0 && mod <= modmax) <<
" Cell "
272 << cell <<
":" << (cell >=0 && cell <= cellmax)
273 <<
":" <<
maxCells(reco) << std::endl;
281 float x(999999.),
y(999999.);
284 if (i < 0)
return std::pair<float,float>(
x,
y);
286 std::pair<int,int> kxy =
findCell(cell, lay, type, reco);
289 float cellSize = index.second;
290 x = (kxy.first+0.5)*cellSize;
291 if (alpha < 0) x -= 0.5*(tl+bl);
292 else if (alpha > 0) x -= 0.5*(tl+bl);
293 if (type != 1) x = -
x;
294 y = ((kxy.second+0.5)*cellSize-
h);
310 return std::pair<float,float>(
x,
y);
327 return std::pair<float,float>(
x,
y);
333 for (
unsigned int i = 0;
i<
layers(reco); ++
i) {
350 unsigned int cells(0);
355 if (cell > cells) cells = cell;
363 float alpha,
float cellSize)
const {
365 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
366 float b = 2*h*bl/(tl-bl);
370 int kymax = floor((2*h)/cellSize);
371 for (
int iky=0; iky<kymax; ++iky) {
372 int cellsInRow=floor(((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize));
373 ncells += cellsInRow;
384 if (i < 0)
return kymax;
387 kymax = floor((2*h)/index.second);
392 if (ky > kymax) kymax = ky;
407 if (index.first < 0)
return nmod;
415 int subsector,
int incrx,
416 int incry,
bool half)
const {
418 int subSec = half ? subsector : 0;
419 std::pair<int,int> kxy =
findCell(cell, layer, subSec,
true);
420 int kx = kxy.first + incrx;
421 int ky = kxy.second + incry;
422 if (ky < 0 || ky >
maxRows(layer,
true)) {
424 return std::pair<int,int>(cell,sector*subsector);
427 subsector =-subsector;
428 }
else if (kx >
maxCells(layer,
true)) {
431 subsector =-subsector;
435 cell =
newCell(kx, ky, layer, subSec);
436 return std::pair<int,int>(cell,sector*subsector);
440 int incrz,
bool half)
const {
442 int layer = lay + incrz;
443 if (layer <= 0 || layer > (
int)(
layers(
true)))
return std::pair<int,int>(cell,0);
444 int subSec = half ? subsector : 0;
445 std::pair<float,float>
xy =
locateCell(cell, lay, subSec,
true);
446 std::pair<int,int> kcell =
assignCell(xy.first, xy.second, layer, subSec,
448 return std::pair<int,int>(kcell.second,layer);
457 float cellSize = index.second;
458 float a = (alpha==0) ?
464 for (
int iky=0; iky<ky; ++iky)
473 std::vector<int> ncell;
484 ncell.push_back((
int)(cell));
493 float tl,
float alpha,
494 float cellSize)
const {
496 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
497 float b = 2*h*bl/(tl-bl);
498 int kymax = floor((2*h)/cellSize);
499 std::vector<int> ncell;
500 for (
int iky=0; iky<kymax; ++iky)
501 ncell.push_back(floor(((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize)));
522 if (i < 0)
return std::pair<int,int>(-1,-1);
523 int kx(-1),
depth(-1);
532 if (depth<0)
return std::pair<int,int>(-1,-1);
536 float a = (half) ? (h/(tl-bl)) : (2*h/(tl-bl));
537 float b = 2*h*bl/(tl-bl);
538 for (
int iky=0; iky<ky; ++iky)
541 std::cout <<
"simToReco: input " << cell <<
":" << lay <<
":" << half
542 <<
" kxy " << kxy.first <<
":" << kxy.second <<
" output "
543 << kx <<
":" << depth <<
" cell factor="
551 }
else if (type == 2) {
557 return std::pair<int,int>(kx,
depth);
563 for (
int k=0;
k<ncopies; ++
k) {
574 std::pair<int,float> indx =
getIndex(lay, reco);
575 if (indx.first < 0)
return false;
581 std::pair<double,double>
xy;
585 xy = std::pair<double,double>(0,0);
600 for (
unsigned int i = 0;
i<
layers(
true); ++
i) {
609 const std::vector<double>& posX,
610 const std::vector<double>& posY)
const {
612 const double tol(0.00001);
614 for (
unsigned int k=0;
k<posX.size(); ++
k) {
617 if (dx <= (cellR+tol) && dy <= (cellY+tol)) {
618 double xmax = (dy<=0.5*cellY) ? cellR : (cellR-(dy-0.5*cellY)/
tan30deg_);
619 if (dx <= (xmax+tol)) {
630 if (lay<1 || lay>(
int)(
hgpar_->
layerIndex_.size()))
return std::pair<int,float>(-1,0);
631 if (reco && lay>(
int)(
hgpar_->
depthIndex_.size()))
return std::pair<int,float>(-1,0);
641 return std::pair<int,float>(indx,cell);
645 float&
h,
float& bl,
float& tl,
646 float&
alpha)
const {
652 if ((subSec>0 && alpha<0) || (subSec<=0 && alpha>0)) alpha = -
alpha;
666 const double rpos =
std::sqrt(waferX*waferX+waferY*waferY);
std::vector< double > waferPosY_
std::vector< int > layer_
std::vector< int > depthLayerF_
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
int maxCellsSquare(float h, float bl, float tl, float alpha, float cellSize) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::array< uint32_t, 2 > tot_layers_
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
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_
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_
T x() const
Cartesian x coordinate.
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::vector< int > layerIndex_
std::vector< double > moduleAlphaR_
hgtrform getTrForm(unsigned int k) const
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)
hgtrap getModule(unsigned int k, bool reco) const
Abs< T >::type abs(const T &t)
std::vector< double > moduleBlR_
std::pair< double, double > waferPosition(int wafer) const
std::vector< double > rMinLayHex_
std::vector< double > moduleTlS_
std::vector< double > zLayerHex_
double waferZ(int layer, bool reco) const
#define TYPELOOKUP_DATA_REG(_dataclass_)
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_
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_
std::vector< double > moduleBlS_
std::vector< int > waferCopy_
std::vector< int > depthIndex_
std::pair< int, int > assignCell(float x, float y, int lay, int subSec, bool reco) const
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)
std::vector< double > moduleTlR_
std::vector< int > waferTypeL_
bool waferInLayer(int wafer, int lay, bool reco) const