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 <<
":" << 2*
modHalf_ <<
" wafers and " 66 <<
"maximum of " <<
maxCells(
false) <<
":" 70 std::cout <<
"HGCalDDDConstants initialized for " << name <<
" with " 73 <<
":" <<
maxCells(
true) <<
" cells" << std::endl;
80 int wmin(9999999), wmax(0), kount(0);
81 for (
int wafer=0; wafer<
sectors(); ++wafer) {
83 if (wafer < wmin) wmin = wafer;
84 if (wafer > wmax) wmax = wafer;
89 int lay1 =
getIndex(lay0,
true).first;
90 std::cout <<
"Index " <<
i <<
" Layer " << lay0 <<
":" << lay1
91 <<
" Wafer " << wmin <<
":" << wmax <<
":" << kount << std::endl;
101 int subSec,
bool reco)
const {
103 std::pair<int,int> cellAssignment(-1,-1);
105 if (i < 0)
return cellAssignment;
115 return cellAssignment;
120 float tl,
float alpha,
121 float cellSize)
const {
123 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
124 float b = 2*h*bl/(tl-bl);
127 int phiSector = (x0 > 0) ? 1 : 0;
128 if (alpha < 0) {x0 -= 0.5*(tl+bl); phiSector = 0;}
129 else if (alpha > 0) {x0 += 0.5*(tl+bl); phiSector = 1;}
132 int ky = floor((y+h)/cellSize);
133 if (ky*cellSize> y+h) ky--;
134 if (ky<0)
return std::pair<int,int>(-1,-1);
135 if ((ky+1)*cellSize < (y+
h) ) ky++;
136 int max_ky_allowed=floor(2*h/cellSize);
137 if (ky>max_ky_allowed-1)
return std::pair<int,int>(-1,-1);
141 int kx = floor(fabs(x0)/cellSize);
142 if (kx*cellSize > fabs(x0) ) kx--;
143 if (kx<0)
return std::pair<int,int>(-1,-1);
144 if ((kx+1)*cellSize < fabs(x0)) kx++;
145 int max_kx_allowed=floor( ((ky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize) );
146 if (kx>max_kx_allowed-1)
return std::pair<int,int>(-1,-1);
151 for (
int iky=0; iky<ky; ++iky) {
152 int cellsInRow( floor( ((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize) ) );
158 return std::pair<int,int>(phiSector,icell);
174 return std::pair<int,int>(wafer,cell);
178 int indx = (type == 1) ? 0 : 1;
188 if (i < 0)
return std::pair<int,int>(-1,-1);
190 return std::pair<int,int>(-1,-1);
201 float cellSize)
const {
204 if(cell<0)
return std::pair<int,int>(-1,-1);
207 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
208 float b = 2*h*bl/(tl-bl);
210 int kymax( floor((2*h)/cellSize) );
212 for (
int iky=0; iky<kymax; ++iky) {
216 int cellsInRow(floor(((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize)));
217 if (testCell+cellsInRow > cell)
break;
218 testCell += cellsInRow;
223 return std::pair<int,int>(kx,ky);
245 std::vector<HGCalParameters::hgtrap> mytrs;
253 std::vector<HGCalParameters::hgtrform> mytrs;
262 int cellmax(0),
modmax(0);
266 ok = ((lay > 0 && lay <= (
int)(
layers(reco))) &&
267 (mod > 0 && mod <=
modmax) &&
268 (cell >=0 && cell <= cellmax));
271 ok = ((lay > 0 && lay <= (
int)(
layers(reco))));
273 const int32_t lay_idx = reco ? (lay-1)*3 + 1 : lay;
275 auto moditr = the_modules.find(copyNumber);
276 ok = (moditr != the_modules.end());
278 if (!ok)
std::cout <<
"HGCalDDDConstants: Layer " << lay <<
":" 279 << lay_idx <<
" Copy " << copyNumber <<
":" << mod
280 <<
" Flag " << ok << std::endl;
283 if (moditr->second >= 0) {
286 ok = (cell >=0 && cell <= cellmax);
295 if (!ok)
std::cout <<
"HGCalDDDConstants: Layer " << lay <<
":" 296 << (lay > 0 && (lay <= (
int)(
layers(reco)))) <<
" Module " 297 << mod <<
":" << modmax <<
":" 298 << (mod > 0 && mod <= modmax) <<
" Cell " << cell <<
":" 299 << cellmax <<
":" << (cell >=0 && cell <= cellmax)
300 <<
":" <<
maxCells(reco) << std::endl;
317 double rr =
sqrt(x*x+y*y);
319 (rr <= hgpar_->rMaxLayHex_[lay-1]));
322 std::cout <<
"Input " << lay <<
":" << wafer <<
":" << cell <<
" Position " 323 << x <<
":" << y <<
":" << rr <<
" Compare Limits " 325 <<
" Flag " << ok << std::endl;
341 float x(999999.),
y(999999.);
344 if (i < 0)
return std::pair<float,float>(
x,
y);
346 std::pair<int,int> kxy =
findCell(cell, lay, type, reco);
349 float cellSize = index.second;
350 x = (kxy.first+0.5)*cellSize;
351 if (alpha < 0) x -= 0.5*(tl+bl);
352 else if (alpha > 0) x -= 0.5*(tl+bl);
353 if (type != 1) x = -
x;
354 y = ((kxy.second+0.5)*cellSize-
h);
370 return std::pair<float,float>(
x,
y);
387 return std::pair<float,float>(
x,
y);
393 for (
unsigned int i = 0;
i<
layers(reco); ++
i) {
410 unsigned int cells(0);
415 if (cell > cells) cells = cell;
423 float alpha,
float cellSize)
const {
425 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
426 float b = 2*h*bl/(tl-bl);
430 int kymax = floor((2*h)/cellSize);
431 for (
int iky=0; iky<kymax; ++iky) {
432 int cellsInRow=floor(((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize));
433 ncells += cellsInRow;
444 if (i < 0)
return kymax;
447 kymax = floor((2*h)/index.second);
452 if (ky > kymax) kymax = ky;
467 if (index.first < 0)
return nmod;
475 int subsector,
int incrx,
476 int incry,
bool half)
const {
478 int subSec = half ? subsector : 0;
479 std::pair<int,int> kxy =
findCell(cell, layer, subSec,
true);
480 int kx = kxy.first + incrx;
481 int ky = kxy.second + incry;
482 if (ky < 0 || ky >
maxRows(layer,
true)) {
484 return std::pair<int,int>(cell,sector*subsector);
487 subsector =-subsector;
488 }
else if (kx >
maxCells(layer,
true)) {
491 subsector =-subsector;
495 cell =
newCell(kx, ky, layer, subSec);
496 return std::pair<int,int>(cell,sector*subsector);
500 int incrz,
bool half)
const {
502 int layer = lay + incrz;
503 if (layer <= 0 || layer > (
int)(
layers(
true)))
return std::pair<int,int>(cell,0);
504 int subSec = half ? subsector : 0;
505 std::pair<float,float>
xy =
locateCell(cell, lay, subSec,
true);
506 std::pair<int,int> kcell =
assignCell(xy.first, xy.second, layer, subSec,
508 return std::pair<int,int>(kcell.second,layer);
517 float cellSize = index.second;
518 float a = (alpha==0) ?
524 for (
int iky=0; iky<ky; ++iky)
533 std::vector<int> ncell;
544 ncell.push_back((
int)(cell));
553 float tl,
float alpha,
554 float cellSize)
const {
556 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
557 float b = 2*h*bl/(tl-bl);
558 int kymax = floor((2*h)/cellSize);
559 std::vector<int> ncell;
560 for (
int iky=0; iky<kymax; ++iky)
561 ncell.push_back(floor(((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize)));
582 if ((copy/10000)%10 != 0) col = -col;
583 row = (copy/100)%100;
584 if ((copy/100000)%10 != 0) row = -row;
586 return std::pair<int,int>(row,
col);
595 return std::pair<int,int>(-1,-1);
597 int kx(-1),
depth(-1);
606 if (depth<0)
return std::pair<int,int>(-1,-1);
610 float a = (half) ? (h/(tl-bl)) : (2*h/(tl-bl));
611 float b = 2*h*bl/(tl-bl);
612 for (
int iky=0; iky<ky; ++iky)
615 std::cout <<
"simToReco: input " << cell <<
":" << lay <<
":" << half
616 <<
" kxy " << kxy.first <<
":" << kxy.second <<
" output " 617 << kx <<
":" << depth <<
" cell factor=" 625 }
else if (type == 2) {
631 return std::pair<int,int>(kx,
depth);
640 for (
int k=0;
k<ncopies; ++
k) {
651 std::cout <<
"Cannot find " << copy <<
" in a list of " << ncopies <<
"\n";
660 int& wafer,
int& icell,
661 int& celltyp)
const {
666 for (
int k=0;
k<size_; ++
k) {
688 std::cout <<
"Position " << x <<
":" << y <<
" Wafer " << wafer <<
":" 689 << size_ <<
" XX " <<
xx <<
":" << yy <<
" Cell " << icell
690 <<
" Type " << celltyp << std::endl;
696 std::pair<int,float> indx =
getIndex(lay, reco);
697 if (indx.first < 0)
return false;
713 std::pair<double,double>
xy(
xx,yy);
727 for (
unsigned int i = 0;
i<
layers(
true); ++
i) {
739 unsigned ity = (type > 0 && type <= 2) ? type : 0;
740 wafer = (itr->second)[ity];
746 if( waferType < 1 || cell < 0)
return false;
752 const std::vector<double>&
posX,
753 const std::vector<double>&
posY)
const {
755 const double tol(0.00001);
757 for (
unsigned int k=0;
k<posX.size(); ++
k) {
760 if (dx <= (cellR+tol) && dy <= (cellY+tol)) {
761 double xmax = (dy<=0.5*cellY) ? cellR : (cellR-(dy-0.5*cellY)/
tan30deg_);
762 if (dx <= (xmax+tol)) {
773 if (lay<1 || lay>(
int)(
hgpar_->
layerIndex_.size()))
return std::pair<int,float>(-1,0);
774 if (reco && lay>(
int)(
hgpar_->
depthIndex_.size()))
return std::pair<int,float>(-1,0);
784 return std::pair<int,float>(indx,cell);
788 float&
h,
float& bl,
float& tl,
789 float&
alpha)
const {
795 if ((subSec>0 && alpha<0) || (subSec<=0 && alpha>0)) alpha = -
alpha;
810 xc[0] = waferX+
rmax_; yc[0] = waferY-0.5*
rr;
811 xc[1] = waferX+
rmax_; yc[1] = waferY+0.5*
rr;
812 xc[2] = waferX; yc[2] = waferY+
rr;
813 xc[3] = waferX-
rmax_; yc[3] = waferY+0.5*
rr;
814 xc[4] = waferX+
rmax_; yc[4] = waferY-0.5*
rr;
815 xc[5] = waferX; yc[5] = waferY-
rr;
816 bool cornerOne(
false), cornerAll(
true);
817 for (
int k=0;
k<6; ++
k) {
820 (rpos <= hgpar_->rMaxLayHex_[lay])) cornerOne =
true;
821 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_
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_
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_
HGCalGeometryMode::GeometryMode mode_
HGCalGeometryMode::GeometryMode mode_
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_
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::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
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_
std::array< int, 3 > HGCWaferParam
bool waferInLayer(int wafer, int lay, bool reco) const