CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
HGCalCellUV Class Reference

#include <HGCalCellUV.h>

Public Member Functions

std::pair< int32_t, int32_t > cellUVFromXY1 (double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug)
 
std::pair< int32_t, int32_t > cellUVFromXY2 (double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug)
 
std::pair< int32_t, int32_t > cellUVFromXY3 (double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug)
 
std::pair< int32_t, int32_t > cellUVFromXY4 (double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug)
 
 HGCalCellUV (double waferSize, double separation, int32_t nFine, int32_t nCoarse)
 

Private Member Functions

std::pair< int32_t, int32_t > cellUVFromXY4 (double xloc, double yloc, int ncell, double cellX, double cellY, double cellXTotal, double cellYTotal, std::map< std::pair< int, int >, std::pair< double, double > > &cellPos, bool extend, bool debug)
 

Private Attributes

std::map< std::pair< int32_t, int32_t >, std::pair< double, double > > cellPosCoarse_ [HGCalCell::cellPlacementTotal]
 
std::map< std::pair< int32_t, int32_t >, std::pair< double, double > > cellPosFine_ [HGCalCell::cellPlacementTotal]
 
double cellX_ [2]
 
double cellXTotal_ [2]
 
double cellY_ [2]
 
double cellYTotal_ [2]
 
int32_t ncell_ [2]
 
double waferSize
 

Static Private Attributes

static constexpr double cos60_ = 0.5
 
static constexpr double sin60_ = 0.5 * sqrt3_
 
static constexpr double sqrt3_ = 1.732050807568877
 

Detailed Description

Definition at line 9 of file HGCalCellUV.h.

Constructor & Destructor Documentation

◆ HGCalCellUV()

HGCalCellUV::HGCalCellUV ( double  waferSize,
double  separation,
int32_t  nFine,
int32_t  nCoarse 
)

Definition at line 8 of file HGCalCellUV.cc.

References cms::cuda::assert(), HGCalCell::cellPlacementExtra, HGCalCell::cellPlacementTotal, cellPosCoarse_, cellPosFine_, HGCalCell::cellUV2XY1(), cellX_, cellXTotal_, cellY_, gpuVertexFinder::iv, dqmdumpme::k, ncell_, sqrt3_, findQualityFiles::v, and waferSize.

8  {
9  HGCalCell hgcalcell(waferSize, nFine, nCoarse);
10  assert(nFine > 0 && nCoarse > 0);
11  ncell_[0] = nFine;
12  ncell_[1] = nCoarse;
13  for (int k = 0; k < 2; ++k) {
14  cellX_[k] = waferSize / (3 * ncell_[k]);
15  cellY_[k] = 0.5 * sqrt3_ * cellX_[k];
16  cellXTotal_[k] = (waferSize + separation) / (3 * ncell_[k]);
17  cellY_[k] = 0.5 * sqrt3_ * cellXTotal_[k];
18  }
19 
20  // Fill up the placement vectors
21  for (int placement = 0; placement < HGCalCell::cellPlacementTotal; ++placement) {
22  // Fine cells
23  for (int iu = 0; iu < 2 * ncell_[0]; ++iu) {
24  for (int iv = 0; iv < 2 * ncell_[0]; ++iv) {
25  int u = (placement < HGCalCell::cellPlacementExtra) ? iv : iu;
26  int v = (placement < HGCalCell::cellPlacementExtra) ? iu : iv;
27  if (((v - u) < ncell_[0]) && (u - v) <= ncell_[0]) {
28  cellPosFine_[placement][std::pair<int, int>(u, v)] = hgcalcell.cellUV2XY1(u, v, placement, 0);
29  }
30  }
31  }
32  // Coarse cells
33  for (int iu = 0; iu < 2 * ncell_[1]; ++iu) {
34  for (int iv = 0; iv < 2 * ncell_[1]; ++iv) {
35  int u = (placement < HGCalCell::cellPlacementExtra) ? iv : iu;
36  int v = (placement < HGCalCell::cellPlacementExtra) ? iu : iv;
37  if (((v - u) < ncell_[1]) && (u - v) <= ncell_[1]) {
38  cellPosCoarse_[placement][std::pair<int, int>(u, v)] = hgcalcell.cellUV2XY1(u, v, placement, 1);
39  }
40  }
41  }
42  }
43 }
double waferSize
Definition: HGCalCellUV.h:42
int32_t *__restrict__ iv
static constexpr double sqrt3_
Definition: HGCalCellUV.h:37
std::map< std::pair< int32_t, int32_t >, std::pair< double, double > > cellPosFine_[HGCalCell::cellPlacementTotal]
Definition: HGCalCellUV.h:44
static constexpr int32_t cellPlacementTotal
Definition: HGCalCell.h:26
double cellXTotal_[2]
Definition: HGCalCellUV.h:42
assert(be >=bs)
double cellY_[2]
Definition: HGCalCellUV.h:42
double cellX_[2]
Definition: HGCalCellUV.h:42
int32_t ncell_[2]
Definition: HGCalCellUV.h:41
std::map< std::pair< int32_t, int32_t >, std::pair< double, double > > cellPosCoarse_[HGCalCell::cellPlacementTotal]
Definition: HGCalCellUV.h:44
static constexpr int32_t cellPlacementExtra
Definition: HGCalCell.h:24

Member Function Documentation

◆ cellUVFromXY1()

std::pair< int32_t, int32_t > HGCalCellUV::cellUVFromXY1 ( double  xloc,
double  yloc,
int32_t  placement,
int32_t  type,
bool  extend,
bool  debug 
)

Definition at line 45 of file HGCalCellUV.cc.

References cellY_, cos60_, debug, gpuVertexFinder::iv, ncell_, makeMuonMisalignmentScenario::rot, sin60_, findQualityFiles::v, w(), x, and y.

46  {
47  //--- Reverse transform to placement=0, if placement index ≠ 6
48  double xloc1 = (placement >= 6) ? xloc : -xloc;
49  int rot = placement % 6;
50  static constexpr std::array<double, 6> fcos = {{1.0, cos60_, -cos60_, -1.0, -cos60_, cos60_}};
51  static constexpr std::array<double, 6> fsin = {{0.0, sin60_, sin60_, 0.0, -sin60_, -sin60_}};
52  double x = xloc1 * fcos[rot] - yloc * fsin[rot];
53  double y = xloc1 * fsin[rot] + yloc * fcos[rot];
54 
55  //--- Calculate coordinates in u,v,w system
56  double u = x * sin60_ + y * cos60_;
57  double v = -x * sin60_ + y * cos60_;
58  double w = y;
59 
60  //--- Rounding in u, v, w coordinates
61  int iu = std::floor(u / cellY_[type]) + 3 * (ncell_[type]) - 1;
62  int iv = std::floor(v / cellY_[type]) + 3 * (ncell_[type]);
63  int iw = std::floor(w / cellY_[type]) + 1;
64 
65  int isv = (iu + iw) / 3;
66  int isu = (iv + iw) / 3;
67 
68  //--- Taking care of extending cells
69  if ((iu + iw) < 0) {
70  isu = (iv + iw + 1) / 3;
71  isv = 0;
72  } else if (isv - isu > ncell_[type] - 1) {
73  isu = (iv + iw + 1) / 3;
74  isv = (iu + iw - 1) / 3;
75  } else if (isu > 2 * ncell_[type] - 1) {
76  isu = 2 * ncell_[type] - 1;
77  isv = (iu + iw - 1) / 3;
78  }
79  if (debug)
80  edm::LogVerbatim("HGCalGeom") << "cellUVFromXY1: Input " << xloc << ":" << yloc << ":" << extend << " Output "
81  << isu << ":" << isv;
82  return std::make_pair(isu, isv);
83 }
Log< level::Info, true > LogVerbatim
int32_t *__restrict__ iv
T w() const
double cellY_[2]
Definition: HGCalCellUV.h:42
static constexpr double cos60_
Definition: HGCalCellUV.h:39
#define debug
Definition: HDRShower.cc:19
int32_t ncell_[2]
Definition: HGCalCellUV.h:41
static constexpr double sin60_
Definition: HGCalCellUV.h:38

◆ cellUVFromXY2()

std::pair< int32_t, int32_t > HGCalCellUV::cellUVFromXY2 ( double  xloc,
double  yloc,
int32_t  placement,
int32_t  type,
bool  extend,
bool  debug 
)

Definition at line 85 of file HGCalCellUV.cc.

References alignmentValidation::c1, reco::ceil(), cellY_, cos60_, debug, ncell_, alignCSCRings::r, makeMuonMisalignmentScenario::rot, sin60_, sqrt3_, testProducerWithPsetDescEmpty_cfi::u1, MetAnalyzer::u2, testProducerWithPsetDescEmpty_cfi::u3, interactiveExample::ui, findQualityFiles::v, x, and y.

86  {
87  //--- Using multiple inequalities to find (u, v)
88  //--- Reverse transform to placement=0, if placement index ≠ 7
89  double xloc1 = (placement >= 6) ? xloc : -1 * xloc;
90  int rot = placement % 6;
91  static constexpr std::array<double, 6> fcos = {{cos60_, 1.0, cos60_, -cos60_, -1.0, -cos60_}};
92  static constexpr std::array<double, 6> fsin = {{-sin60_, 0.0, sin60_, sin60_, 0.0, -sin60_}};
93  double x = xloc1 * fcos[rot] - yloc * fsin[rot];
94  double y = xloc1 * fsin[rot] + yloc * fcos[rot];
95 
96  int32_t u(-100), v(-100);
97  int ncell = (type != 0) ? ncell_[1] : ncell_[0];
98  double r = (type != 0) ? cellY_[1] : cellY_[0];
99  double l1 = (y / r) + ncell - 1.0;
100  int l2 = std::floor((0.5 * y + 0.5 * x / sqrt3_) / r + ncell - 4.0 / 3.0);
101  int l3 = std::floor((x / sqrt3_) / r + ncell - 4.0 / 3.0);
102  double l4 = (y + sqrt3_ * x) / (2 * r) + 2 * ncell - 2;
103  double l5 = (y - sqrt3_ * x) / (2 * r) - ncell;
104  double u1 = (y / r) + ncell + 1.0;
105  int u2 = std::ceil((0.5 * y + 0.5 * x / sqrt3_) / r + ncell + 2.0 / 3.0);
106  int u3 = std::ceil((x / sqrt3_) / r + ncell);
107  double u4 = l4 + 2;
108  double u5 = l5 + 2;
109 
110  for (int ui = l2 + 1; ui < u2; ui++) {
111  for (int vi = l3 + 1; vi < u3; vi++) {
112  int c1 = 2 * ui - vi;
113  int c4 = ui + vi;
114  int c5 = ui - 2 * vi;
115  if ((c1 < u1) && (c1 > l1) && (c4 < u4) && (c4 > l4) && (c5 < u5) && (c5 > l5)) {
116  u = ui;
117  v = vi;
118  }
119  }
120  }
121 
122  //--- Taking care of extending cells
123  if (v == -1) {
124  if (y < (2 * u - v - ncell) * r) {
125  v += 1;
126  } else {
127  u += 1;
128  v += 1;
129  }
130  }
131  if (v - u == ncell) {
132  if ((y + sqrt3_ * x) < ((u + v - 2 * ncell + 1) * 2 * r)) {
133  v += -1;
134  } else {
135  u += 1;
136  }
137  }
138  if (u == 2 * ncell) {
139  if ((y - sqrt3_ * x) < ((u - 2 * v + ncell - 1) * 2 * r)) {
140  u += -1;
141  } else {
142  u += -1;
143  v += -1;
144  }
145  }
146  if (debug)
147  edm::LogVerbatim("HGCalGeom") << "cellUVFromXY2: Input " << xloc << ":" << yloc << ":" << extend << " Output " << u
148  << ":" << v;
149  return std::make_pair(u, v);
150 }
Log< level::Info, true > LogVerbatim
constexpr int32_t ceil(float num)
static constexpr double sqrt3_
Definition: HGCalCellUV.h:37
double cellY_[2]
Definition: HGCalCellUV.h:42
static constexpr double cos60_
Definition: HGCalCellUV.h:39
#define debug
Definition: HDRShower.cc:19
int32_t ncell_[2]
Definition: HGCalCellUV.h:41
static constexpr double sin60_
Definition: HGCalCellUV.h:38

◆ cellUVFromXY3()

std::pair< int32_t, int32_t > HGCalCellUV::cellUVFromXY3 ( double  xloc,
double  yloc,
int32_t  placement,
int32_t  type,
bool  extend,
bool  debug 
)

Definition at line 152 of file HGCalCellUV.cc.

References funct::abs(), reco::ceil(), cellX_, cellY_, cos60_, cuy::cv, debug, HLT_2022v11_cff::distance, mps_fire::i, gpuVertexFinder::iv, ncell_, makeMuonMisalignmentScenario::rot, sin60_, sqrt3_, findQualityFiles::v, x, and y.

153  {
154  //--- Using Cube coordinates to find the (u, v)
155  //--- Reverse transform to placement=0, if placement index ≠ 6
156  double xloc1 = (placement >= 6) ? xloc : -xloc;
157  int rot = placement % 6;
158  static constexpr std::array<double, 6> fcos = {{1.0, cos60_, -cos60_, -1.0, -cos60_, cos60_}};
159  static constexpr std::array<double, 6> fsin = {{0.0, sin60_, sin60_, 0.0, -sin60_, -sin60_}};
160  double xprime = xloc1 * fcos[rot] - yloc * fsin[rot];
161  double yprime = xloc1 * fsin[rot] + yloc * fcos[rot];
162  double x = xprime + cellX_[type];
163  double y = yprime;
164 
165  x = x / cellX_[type];
166  y = y / cellY_[type];
167 
168  double cu = 2 * x / 3;
169  double cv = -x / 3 + y / 2;
170  double cw = -x / 3 - y / 2;
171 
172  int iu = std::round(cu);
173  int iv = std::round(cv);
174  int iw = std::round(cw);
175 
176  if (iu + iv + iw != 0) {
177  double arr[] = {std::abs(cu - iu), std::abs(cv - iv), std::abs(cw - iw)};
178  int i = std::distance(arr, std::max_element(arr, arr + 3));
179 
180  if (i == 1)
181  iv = (std::round(cv) == std::floor(cv)) ? std::ceil(cv) : std::floor(cv);
182  else if (i == 2)
183  iw = (std::round(cw) == std::floor(cw)) ? std::ceil(cw) : std::floor(cw);
184  }
185 
186  //--- Taking care of extending cells
187  int u(ncell_[type] + iv), v(ncell_[type] - 1 - iw);
188  double xcell = (1.5 * (v - u) + 0.5) * cellX_[type];
189  double ycell = (v + u - 2 * ncell_[type] + 1) * cellY_[type];
190  if (v == -1) {
191  if ((yprime - sqrt3_ * xprime) < (ycell - sqrt3_ * xcell)) {
192  v += 1;
193  } else {
194  u += 1;
195  v += 1;
196  }
197  }
198  if (v - u == ncell_[type]) {
199  if (yprime < ycell) {
200  v += -1;
201  } else {
202  u += 1;
203  }
204  }
205  if (u == 2 * ncell_[type]) {
206  if ((yprime + sqrt3_ * xprime) > (ycell + sqrt3_ * xcell)) {
207  u += -1;
208  } else {
209  u += -1;
210  v += -1;
211  }
212  }
213 
214  if (debug)
215  edm::LogVerbatim("HGCalGeom") << "cellUVFromXY3: Input " << xloc << ":" << yloc << ":" << extend << " Output " << u
216  << ":" << v;
217  return std::make_pair(u, v);
218 }
Log< level::Info, true > LogVerbatim
constexpr int32_t ceil(float num)
int32_t *__restrict__ iv
static constexpr double sqrt3_
Definition: HGCalCellUV.h:37
cv
Definition: cuy.py:363
double cellY_[2]
Definition: HGCalCellUV.h:42
double cellX_[2]
Definition: HGCalCellUV.h:42
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static constexpr double cos60_
Definition: HGCalCellUV.h:39
#define debug
Definition: HDRShower.cc:19
int32_t ncell_[2]
Definition: HGCalCellUV.h:41
static constexpr double sin60_
Definition: HGCalCellUV.h:38

◆ cellUVFromXY4() [1/2]

std::pair< int, int > HGCalCellUV::cellUVFromXY4 ( double  xloc,
double  yloc,
int32_t  placement,
int32_t  type,
bool  extend,
bool  debug 
)

Definition at line 220 of file HGCalCellUV.cc.

References cellPosCoarse_, cellPosFine_, cellX_, cellXTotal_, cellY_, debug, and ncell_.

221  {
222  if (type != 0)
223  return cellUVFromXY4(
224  xloc, yloc, ncell_[1], cellX_[1], cellY_[1], cellXTotal_[1], cellY_[1], cellPosCoarse_[placement], extend, debug);
225  else
226  return cellUVFromXY4(
227  xloc, yloc, ncell_[0], cellX_[0], cellY_[0], cellXTotal_[0], cellY_[0], cellPosFine_[placement], extend, debug);
228 }
std::map< std::pair< int32_t, int32_t >, std::pair< double, double > > cellPosFine_[HGCalCell::cellPlacementTotal]
Definition: HGCalCellUV.h:44
double cellXTotal_[2]
Definition: HGCalCellUV.h:42
double cellY_[2]
Definition: HGCalCellUV.h:42
double cellX_[2]
Definition: HGCalCellUV.h:42
#define debug
Definition: HDRShower.cc:19
int32_t ncell_[2]
Definition: HGCalCellUV.h:41
std::map< std::pair< int32_t, int32_t >, std::pair< double, double > > cellPosCoarse_[HGCalCell::cellPlacementTotal]
Definition: HGCalCellUV.h:44
std::pair< int32_t, int32_t > cellUVFromXY4(double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug)
Definition: HGCalCellUV.cc:220

◆ cellUVFromXY4() [2/2]

std::pair< int, int > HGCalCellUV::cellUVFromXY4 ( double  xloc,
double  yloc,
int  ncell,
double  cellX,
double  cellY,
double  cellXTotal,
double  cellYTotal,
std::map< std::pair< int, int >, std::pair< double, double > > &  cellPos,
bool  extend,
bool  debug 
)
private

Definition at line 230 of file HGCalCellUV.cc.

References funct::abs(), debug, and sqrt3_.

239  {
240  std::pair<int, int> uv = std::make_pair(-1, -1);
241  std::map<std::pair<int, int>, std::pair<double, double> >::const_iterator itr;
242  for (itr = cellPos.begin(); itr != cellPos.end(); ++itr) {
243  double delX = std::abs(xloc - (itr->second).first);
244  double delY = std::abs(yloc - (itr->second).second);
245  if ((delX < cellX) && (delY < cellY)) {
246  if ((delX < (0.5 * cellX)) || (delY < (2.0 * cellY - sqrt3_ * delX))) {
247  uv = itr->first;
248  break;
249  }
250  }
251  }
252  if ((uv.first < 0) && extend) {
253  for (itr = cellPos.begin(); itr != cellPos.end(); ++itr) {
254  double delX = std::abs(xloc - (itr->second).first);
255  double delY = std::abs(yloc - (itr->second).second);
256  if ((delX < cellXTotal) && (delY < cellYTotal)) {
257  if ((delX < (0.5 * cellXTotal)) || (delY < (2.0 * cellYTotal - sqrt3_ * delX))) {
258  uv = itr->first;
259  break;
260  }
261  }
262  }
263  }
264  if (debug)
265  edm::LogVerbatim("HGCalGeom") << "cellUVFromXY4: Input " << xloc << ":" << yloc << ":" << extend << " Output "
266  << uv.first << ":" << uv.second;
267  return uv;
268 }
Log< level::Info, true > LogVerbatim
static constexpr double sqrt3_
Definition: HGCalCellUV.h:37
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define debug
Definition: HDRShower.cc:19

Member Data Documentation

◆ cellPosCoarse_

std::map<std::pair<int32_t, int32_t>, std::pair<double, double> > HGCalCellUV::cellPosCoarse_[HGCalCell::cellPlacementTotal]
private

Definition at line 44 of file HGCalCellUV.h.

Referenced by cellUVFromXY4(), and HGCalCellUV().

◆ cellPosFine_

std::map<std::pair<int32_t, int32_t>, std::pair<double, double> > HGCalCellUV::cellPosFine_[HGCalCell::cellPlacementTotal]
private

Definition at line 44 of file HGCalCellUV.h.

Referenced by cellUVFromXY4(), and HGCalCellUV().

◆ cellX_

double HGCalCellUV::cellX_[2]
private

Definition at line 42 of file HGCalCellUV.h.

Referenced by cellUVFromXY3(), cellUVFromXY4(), and HGCalCellUV().

◆ cellXTotal_

double HGCalCellUV::cellXTotal_[2]
private

Definition at line 42 of file HGCalCellUV.h.

Referenced by cellUVFromXY4(), and HGCalCellUV().

◆ cellY_

double HGCalCellUV::cellY_[2]
private

Definition at line 42 of file HGCalCellUV.h.

Referenced by cellUVFromXY1(), cellUVFromXY2(), cellUVFromXY3(), cellUVFromXY4(), and HGCalCellUV().

◆ cellYTotal_

double HGCalCellUV::cellYTotal_[2]
private

Definition at line 42 of file HGCalCellUV.h.

◆ cos60_

constexpr double HGCalCellUV::cos60_ = 0.5
staticprivate

Definition at line 39 of file HGCalCellUV.h.

Referenced by cellUVFromXY1(), cellUVFromXY2(), and cellUVFromXY3().

◆ ncell_

int32_t HGCalCellUV::ncell_[2]
private

Definition at line 41 of file HGCalCellUV.h.

Referenced by cellUVFromXY1(), cellUVFromXY2(), cellUVFromXY3(), cellUVFromXY4(), and HGCalCellUV().

◆ sin60_

constexpr double HGCalCellUV::sin60_ = 0.5 * sqrt3_
staticprivate

Definition at line 38 of file HGCalCellUV.h.

Referenced by cellUVFromXY1(), cellUVFromXY2(), and cellUVFromXY3().

◆ sqrt3_

constexpr double HGCalCellUV::sqrt3_ = 1.732050807568877
staticprivate

Definition at line 37 of file HGCalCellUV.h.

Referenced by cellUVFromXY2(), cellUVFromXY3(), cellUVFromXY4(), and HGCalCellUV().

◆ waferSize

double HGCalCellUV::waferSize
private

Definition at line 42 of file HGCalCellUV.h.

Referenced by HGCalCellUV().