7 #include "CLHEP/Units/GlobalPhysicalConstants.h"
8 #include "CLHEP/Units/GlobalSystemOfUnits.h"
21 for (
int simreco = 0; simreco < 2; ++simreco ) {
25 edm::LogInfo(
"HGCalGeom") <<
"HGCalDDDConstants initialized for " << name
26 <<
" with " <<
layers(
false) <<
":"
28 <<
" sectors " << 2*
modHalf_ <<
" modules and "
29 <<
"maximum of " <<
maxCells(
false) <<
":"
32 std::cout <<
"HGCalDDDConstants initialized for " << name <<
" with "
35 <<
":" <<
maxCells(
true) <<
" cells" << std::endl;
47 for (
int simreco = 0; simreco < 2; ++simreco) {
50 for (
unsigned int layer=1; layer <=
tot_layers_[simreco]; ++layer) {
62 edm::LogInfo(
"HGCalGeom") <<
"HGCalDDDConstants initialized for " << name
63 <<
" with " <<
layers(
false) <<
":"
65 <<
" wafers, " << 2*
modHalf_ <<
" wafers and "
66 <<
"maximum of " <<
maxCells(
false) <<
":"
70 std::cout <<
"HGCalDDDConstants initialized for " << name <<
" with "
73 <<
":" <<
maxCells(
true) <<
" cells" << std::endl;
83 int subSec,
bool reco)
const {
85 std::pair<int,int> cellAssignment(-1,-1);
87 if (i < 0)
return cellAssignment;
97 return cellAssignment;
102 float tl,
float alpha,
103 float cellSize)
const {
105 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
106 float b = 2*h*bl/(tl-bl);
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;}
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);
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);
133 for (
int iky=0; iky<ky; ++iky) {
134 int cellsInRow( floor( ((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize) ) );
140 return std::pair<int,int>(phiSector,icell);
156 return std::pair<int,int>(wafer,cell);
160 int indx = (type == 1) ? 0 : 1;
178 if (i < 0)
return std::pair<int,int>(-1,-1);
180 return std::pair<int,int>(-1,-1);
191 float cellSize)
const {
194 if(cell<0)
return std::pair<int,int>(-1,-1);
197 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
198 float b = 2*h*bl/(tl-bl);
200 int kymax( floor((2*h)/cellSize) );
202 for (
int iky=0; iky<kymax; ++iky) {
206 int cellsInRow(floor(((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize)));
207 if (testCell+cellsInRow > cell)
break;
208 testCell += cellsInRow;
213 return std::pair<int,int>(kx,ky);
235 std::vector<HGCalParameters::hgtrap> mytrs;
243 std::vector<HGCalParameters::hgtrform> mytrs;
252 int cellmax(0),
modmax(0);
256 ok = ((lay > 0 && lay <= (int)(
layers(reco))) &&
257 (mod > 0 && mod <=
modmax) &&
258 (cell >=0 && cell <= cellmax));
261 ok = ((lay > 0 && lay <= (int)(
layers(reco))));
263 const int32_t lay_idx = reco ? (lay-1)*3 + 1 : lay;
265 auto moditr = the_modules.find(copyNumber);
266 ok = (moditr != the_modules.end());
268 if (moditr->second >= 0) {
271 ok = (cell >=0 && cell <= cellmax);
280 if (!ok)
std::cout <<
"HGCalDDDConstants: Layer " << lay <<
":"
281 << (lay > 0 && (lay <= (int)(
layers(reco)))) <<
" Module "
282 << mod <<
":" << (mod > 0 && mod <= modmax) <<
" Cell "
283 << cell <<
":" << (cell >=0 && cell <= cellmax)
284 <<
":" <<
maxCells(reco) << std::endl;
301 double rr =
sqrt(x*x+y*y);
303 (rr <= hgpar_->rMaxLayHex_[lay-1]));
305 std::cout <<
"Input " << lay <<
":" << wafer <<
":" << cell <<
" Position "
306 << x <<
":" << y <<
":" << rr <<
" Compare Limits "
308 <<
" Flag " << ok << std::endl;
316 float x(999999.),
y(999999.);
319 if (i < 0)
return std::pair<float,float>(
x,
y);
321 std::pair<int,int> kxy =
findCell(cell, lay, type, reco);
324 float cellSize = index.second;
325 x = (kxy.first+0.5)*cellSize;
326 if (alpha < 0) x -= 0.5*(tl+bl);
327 else if (alpha > 0) x -= 0.5*(tl+bl);
328 if (type != 1) x = -
x;
329 y = ((kxy.second+0.5)*cellSize-
h);
345 return std::pair<float,float>(
x,
y);
362 return std::pair<float,float>(
x,
y);
368 for (
unsigned int i = 0;
i<
layers(reco); ++
i) {
385 unsigned int cells(0);
390 if (cell > cells) cells = cell;
398 float alpha,
float cellSize)
const {
400 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
401 float b = 2*h*bl/(tl-bl);
405 int kymax = floor((2*h)/cellSize);
406 for (
int iky=0; iky<kymax; ++iky) {
407 int cellsInRow=floor(((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize));
408 ncells += cellsInRow;
419 if (i < 0)
return kymax;
422 kymax = floor((2*h)/index.second);
427 if (ky > kymax) kymax = ky;
442 if (index.first < 0)
return nmod;
450 int subsector,
int incrx,
451 int incry,
bool half)
const {
453 int subSec = half ? subsector : 0;
454 std::pair<int,int> kxy =
findCell(cell, layer, subSec,
true);
455 int kx = kxy.first + incrx;
456 int ky = kxy.second + incry;
457 if (ky < 0 || ky >
maxRows(layer,
true)) {
459 return std::pair<int,int>(cell,sector*subsector);
462 subsector =-subsector;
463 }
else if (kx >
maxCells(layer,
true)) {
466 subsector =-subsector;
470 cell =
newCell(kx, ky, layer, subSec);
471 return std::pair<int,int>(cell,sector*subsector);
475 int incrz,
bool half)
const {
477 int layer = lay + incrz;
478 if (layer <= 0 || layer > (
int)(
layers(
true)))
return std::pair<int,int>(cell,0);
479 int subSec = half ? subsector : 0;
480 std::pair<float,float>
xy =
locateCell(cell, lay, subSec,
true);
481 std::pair<int,int> kcell =
assignCell(xy.first, xy.second, layer, subSec,
483 return std::pair<int,int>(kcell.second,layer);
492 float cellSize = index.second;
493 float a = (alpha==0) ?
499 for (
int iky=0; iky<ky; ++iky)
508 std::vector<int> ncell;
519 ncell.push_back((
int)(cell));
528 float tl,
float alpha,
529 float cellSize)
const {
531 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
532 float b = 2*h*bl/(tl-bl);
533 int kymax = floor((2*h)/cellSize);
534 std::vector<int> ncell;
535 for (
int iky=0; iky<kymax; ++iky)
536 ncell.push_back(floor(((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize)));
557 if ((copy/10000)%10 != 0) col = -col;
558 row = (copy/100)%100;
559 if ((copy/100000)%10 != 0) row = -row;
561 return std::pair<int,int>(row,
col);
570 return std::pair<int,int>(-1,-1);
572 int kx(-1),
depth(-1);
581 if (depth<0)
return std::pair<int,int>(-1,-1);
585 float a = (half) ? (h/(tl-bl)) : (2*h/(tl-bl));
586 float b = 2*h*bl/(tl-bl);
587 for (
int iky=0; iky<ky; ++iky)
590 std::cout <<
"simToReco: input " << cell <<
":" << lay <<
":" << half
591 <<
" kxy " << kxy.first <<
":" << kxy.second <<
" output "
592 << kx <<
":" << depth <<
" cell factor="
600 }
else if (type == 2) {
606 return std::pair<int,int>(kx,
depth);
612 for (
int k=0;
k<ncopies; ++
k) {
622 int& wafer,
int& icell,
623 int& celltyp)
const {
650 std::cout <<
"Position " << x <<
":" << y <<
" Wafer " << wafer <<
":"
651 << size_ <<
" XX " << xx <<
":" << yy <<
" Cell " << icell
652 <<
" Type " << celltyp << std::endl;
658 std::pair<int,float> indx =
getIndex(lay, reco);
659 if (indx.first < 0)
return false;
665 std::pair<double,double>
xy;
669 xy = std::pair<double,double>(0,0);
684 for (
unsigned int i = 0;
i<
layers(
true); ++
i) {
692 if( waferType < 1 || cell < 0)
return false;
698 const std::vector<double>& posX,
699 const std::vector<double>& posY)
const {
701 const double tol(0.00001);
703 for (
unsigned int k=0;
k<posX.size(); ++
k) {
706 if (dx <= (cellR+tol) && dy <= (cellY+tol)) {
707 double xmax = (dy<=0.5*cellY) ? cellR : (cellR-(dy-0.5*cellY)/
tan30deg_);
708 if (dx <= (xmax+tol)) {
719 if (lay<1 || lay>(
int)(
hgpar_->
layerIndex_.size()))
return std::pair<int,float>(-1,0);
720 if (reco && lay>(
int)(
hgpar_->
depthIndex_.size()))
return std::pair<int,float>(-1,0);
730 return std::pair<int,float>(indx,cell);
734 float&
h,
float& bl,
float& tl,
735 float&
alpha)
const {
741 if ((subSec>0 && alpha<0) || (subSec<=0 && alpha>0)) alpha = -
alpha;
756 xc[0] = waferX+
rmax_; yc[0] = waferY-0.5*
rr;
757 xc[1] = waferX+
rmax_; yc[1] = waferY+0.5*
rr;
758 xc[2] = waferX; yc[2] = waferY+
rr;
759 xc[3] = waferX-
rmax_; yc[3] = waferY+0.5*
rr;
760 xc[4] = waferX+
rmax_; yc[4] = waferY-0.5*
rr;
761 xc[5] = waferX; yc[5] = waferY-
rr;
762 bool cornerOne(
false), cornerAll(
true);
763 for (
int k=0;
k<6; ++
k) {
766 (rpos <= hgpar_->rMaxLayHex_[lay])) cornerOne =
true;
767 else cornerAll =
false;
bool isHalfCell(int waferType, int cell) const
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
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
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_
bool isValidCell(int layindex, int wafer, int cell) const
std::pair< double, double > waferPosition(int wafer) 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
#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