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;
78 int wminT(9999999), wmaxT(0), kount1(0), kount2(0);
81 int wmin(9999999), wmax(0), kount(0);
82 for (
int wafer=0; wafer<
sectors(); ++wafer) {
84 if (wafer < wmin) wmin = wafer;
85 if (wafer > wmax) wmax = wafer;
89 if (wminT > wmin) wminT = wmin;
90 if (wmaxT < wmax) wmaxT = wmax;
91 if (kount1 < kount) kount1= kount;
94 int lay1 =
getIndex(lay0,
true).first;
95 std::cout <<
"Index " <<
i <<
" Layer " << lay0 <<
":" << lay1
96 <<
" Wafer " << wmin <<
":" << wmax <<
":" << kount << std::endl;
101 waferMax_ = std::array<int,4>{ {wminT,wmaxT,kount1,kount2} };
103 std::cout <<
"Overall wafer statistics: " << wminT <<
":" << wmaxT <<
":" 104 << kount1 <<
":" << kount2 << std::endl;
111 int subSec,
bool reco)
const {
113 std::pair<int,int> cellAssignment(-1,-1);
115 if (i < 0)
return cellAssignment;
125 return cellAssignment;
130 float tl,
float alpha,
131 float cellSize)
const {
133 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
134 float b = 2*h*bl/(tl-bl);
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;}
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);
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);
161 for (
int iky=0; iky<ky; ++iky) {
162 int cellsInRow( floor( ((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize) ) );
168 return std::pair<int,int>(phiSector,icell);
184 return std::pair<int,int>(wafer,cell);
188 int indx = (type == 1) ? 0 : 1;
198 if (i < 0)
return std::pair<int,int>(-1,-1);
200 return std::pair<int,int>(-1,-1);
211 float cellSize)
const {
214 if(cell<0)
return std::pair<int,int>(-1,-1);
217 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
218 float b = 2*h*bl/(tl-bl);
220 int kymax( floor((2*h)/cellSize) );
222 for (
int iky=0; iky<kymax; ++iky) {
226 int cellsInRow(floor(((iky+1)*cellSize+b+
k_horizontalShift*cellSize)/(a*cellSize)));
227 if (testCell+cellsInRow > cell)
break;
228 testCell += cellsInRow;
233 return std::pair<int,int>(kx,ky);
255 std::vector<HGCalParameters::hgtrap> mytrs;
263 std::vector<HGCalParameters::hgtrform> mytrs;
272 int cellmax(0),
modmax(0);
276 ok = ((lay > 0 && lay <= (
int)(
layers(reco))) &&
277 (mod > 0 && mod <=
modmax) &&
278 (cell >=0 && cell <= cellmax));
281 ok = ((lay > 0 && lay <= (
int)(
layers(reco))));
283 const int32_t lay_idx = reco ? (lay-1)*3 + 1 : lay;
285 auto moditr = the_modules.find(copyNumber);
286 ok = (moditr != the_modules.end());
288 if (!ok)
std::cout <<
"HGCalDDDConstants: Layer " << lay <<
":" 289 << lay_idx <<
" Copy " << copyNumber <<
":" << mod
290 <<
" Flag " << ok << std::endl;
293 if (moditr->second >= 0) {
296 ok = (cell >=0 && cell <= cellmax);
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;
327 double rr =
sqrt(x*x+y*y);
329 (rr <= hgpar_->rMaxLayHex_[lay-1]));
332 std::cout <<
"Input " << lay <<
":" << wafer <<
":" << cell <<
" Position " 333 << x <<
":" << y <<
":" << rr <<
" Compare Limits " 335 <<
" Flag " << ok << std::endl;
351 float x(999999.),
y(999999.);
354 if (i < 0)
return std::pair<float,float>(
x,
y);
356 std::pair<int,int> kxy =
findCell(cell, lay, type, reco);
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);
380 return std::pair<float,float>(
x,
y);
397 return std::pair<float,float>(
x,
y);
403 for (
unsigned int i = 0;
i<
layers(reco); ++
i) {
420 unsigned int cells(0);
425 if (cell > cells) cells = cell;
433 float alpha,
float cellSize)
const {
435 float a = (alpha==0) ? (2*h/(tl-bl)) : (h/(tl-bl));
436 float b = 2*h*bl/(tl-bl);
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;
454 if (i < 0)
return kymax;
457 kymax = floor((2*h)/index.second);
462 if (ky > kymax) kymax = ky;
477 if (index.first < 0)
return nmod;
485 int subsector,
int incrx,
486 int incry,
bool half)
const {
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)) {
494 return std::pair<int,int>(cell,sector*subsector);
497 subsector =-subsector;
498 }
else if (kx >
maxCells(layer,
true)) {
501 subsector =-subsector;
505 cell =
newCell(kx, ky, layer, subSec);
506 return std::pair<int,int>(cell,sector*subsector);
510 int incrz,
bool half)
const {
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,
518 return std::pair<int,int>(kcell.second,layer);
527 float cellSize = index.second;
528 float a = (alpha==0) ?
534 for (
int iky=0; iky<ky; ++iky)
543 std::vector<int> ncell;
554 ncell.emplace_back((
int)(cell));
563 float tl,
float alpha,
564 float cellSize)
const {
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)));
592 if ((copy/10000)%10 != 0) col = -col;
593 row = (copy/100)%100;
594 if ((copy/100000)%10 != 0) row = -row;
596 return std::pair<int,int>(row,
col);
605 return std::pair<int,int>(-1,-1);
607 int kx(-1),
depth(-1);
616 if (depth<0)
return std::pair<int,int>(-1,-1);
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)
625 std::cout <<
"simToReco: input " << cell <<
":" << lay <<
":" << half
626 <<
" kxy " << kxy.first <<
":" << kxy.second <<
" output " 627 << kx <<
":" << depth <<
" cell factor=" 635 }
else if (type == 2) {
641 return std::pair<int,int>(kx,
depth);
650 for (
int k=0;
k<ncopies; ++
k) {
661 std::cout <<
"Cannot find " << copy <<
" in a list of " << ncopies <<
"\n";
670 int& wafer,
int& icell,
671 int& celltyp)
const {
676 for (
int k=0;
k<size_; ++
k) {
698 std::cout <<
"Position " << x <<
":" << y <<
" Wafer " << wafer <<
":" 699 << size_ <<
" XX " <<
xx <<
":" << yy <<
" Cell " << icell
700 <<
" Type " << celltyp << std::endl;
706 std::pair<int,float> indx =
getIndex(lay, reco);
707 if (indx.first < 0)
return false;
723 std::pair<double,double>
xy(
xx,yy);
737 for (
unsigned int i = 0;
i<
layers(
true); ++
i) {
749 unsigned ity = (type > 0 && type <= 2) ? type : 0;
750 wafer = (itr->second)[ity];
756 if( waferType < 1 || cell < 0)
return false;
762 const std::vector<double>&
posX,
763 const std::vector<double>&
posY)
const {
765 const double tol(0.00001);
767 for (
unsigned int k=0;
k<posX.size(); ++
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)) {
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);
794 return std::pair<int,float>(indx,cell);
798 float&
h,
float& bl,
float& tl,
799 float&
alpha)
const {
805 if ((subSec>0 && alpha<0) || (subSec<=0 && alpha>0)) alpha = -
alpha;
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) {
830 (rpos <= hgpar_->rMaxLayHex_[lay])) cornerOne =
true;
831 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_
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
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
HGCalDDDConstants(const HGCalParameters *hp, const std::string &name)
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