CMS 3D CMS Logo

HGCalGeomTools.cc
Go to the documentation of this file.
5 
6 #include <string>
7 
8 //#define EDM_ML_DEBUG
9 HGCalGeomTools::HGCalGeomTools() : factor_(1.0 / std::sqrt(3.0)) {}
10 
11 void HGCalGeomTools::radius(double zf,
12  double zb,
13  std::vector<double> const& zFront1,
14  std::vector<double> const& rFront1,
15  std::vector<double> const& slope1,
16  std::vector<double> const& zFront2,
17  std::vector<double> const& rFront2,
18  std::vector<double> const& slope2,
19  int flag,
20  std::vector<double>& zz,
21  std::vector<double>& rin,
22  std::vector<double>& rout) {
23  double dz1(0), dz2(0);
24  auto zf1 = std::lower_bound(zFront1.begin(), zFront1.end(), zf);
25  if (zf1 != zFront1.begin())
26  --zf1;
27  if (((zf1 + 1) != zFront1.end()) && (std::abs(*(zf1 + 1) - zf) < tol_)) {
28  ++zf1;
29  dz1 = 2 * tol_;
30  }
31  auto zf2 = std::lower_bound(zFront2.begin(), zFront2.end(), zf);
32  if (zf2 != zFront2.begin())
33  --zf2;
34  auto zb1 = std::lower_bound(zFront1.begin(), zFront1.end(), zb);
35  if (zb1 != zFront1.begin())
36  --zb1;
37  if ((zb1 != zFront1.begin()) && (std::abs(*zb1 - zb) < tol_)) {
38  --zb1;
39  dz2 = -2 * tol_;
40  }
41  auto zb2 = std::lower_bound(zFront2.begin(), zFront2.end(), zb);
42  if (zb2 != zFront2.begin())
43  --zb2;
44 #ifdef EDM_ML_DEBUG
45  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::radius:zf " << zf << " : " << *zf1 << " : " << *zf2 << " zb " << zb
46  << " : " << *zb1 << " : " << *zb2 << " Flag " << flag;
47 #endif
48  if ((zf1 == zb1) && (zf2 == zb2)) {
49 #ifdef EDM_ML_DEBUG
50  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::radius:Try " << zf << ":" << zb << " dz " << dz1 << ":" << dz2;
51 #endif
52  zz.emplace_back(zf);
53  rin.emplace_back(radius(zf + dz1, zFront1, rFront1, slope1));
54  rout.emplace_back(radius(zf, zFront2, rFront2, slope2));
55  zz.emplace_back(zb);
56  rin.emplace_back(radius(zb + dz2, zFront1, rFront1, slope1));
57  rout.emplace_back(radius(zb, zFront2, rFront2, slope2));
58  } else if (zf1 == zb1) {
59 #ifdef EDM_ML_DEBUG
60  double z1 = std::max(*zf2, *zb2);
61  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::radius:Try " << zf << ":" << *zb2 << " (" << z1 << ") : " << zb;
62 #endif
63  zz.emplace_back(zf);
64  rin.emplace_back(radius(zf, zFront1, rFront1, slope1));
65  rout.emplace_back(radius(zf, zFront2, rFront2, slope2));
66  if (slope(*zb2, zFront2, slope2) < tol_) {
67  zz.emplace_back(*zb2);
68  rin.emplace_back(radius(*zb2, zFront1, rFront1, slope1));
69  rout.emplace_back(radius(*zb2 - tol_, zFront2, rFront2, slope2));
70  }
71  zz.emplace_back(*zb2);
72  rin.emplace_back(radius(*zb2, zFront1, rFront1, slope1));
73  rout.emplace_back(radius(*zb2, zFront2, rFront2, slope2));
74  zz.emplace_back(zb);
75  rin.emplace_back(radius(zb, zFront1, rFront1, slope1));
76  rout.emplace_back(radius(zb, zFront2, rFront2, slope2));
77  } else if (zf2 == zb2) {
78 #ifdef EDM_ML_DEBUG
79  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::radius:Try " << zf << ":" << *zb1 << ":" << zb;
80 #endif
81  zz.emplace_back(zf);
82  rin.emplace_back(radius(zf, zFront1, rFront1, slope1));
83  rout.emplace_back(radius(zf, zFront2, rFront2, slope2));
84  if (slope(*zb1, zFront1, slope1) < tol_) {
85  zz.emplace_back(*zb1);
86  rin.emplace_back(radius(*zb1 - tol_, zFront1, rFront1, slope1));
87  rout.emplace_back(radius(*zb1, zFront2, rFront2, slope2));
88  }
89  zz.emplace_back(*zb1);
90  rin.emplace_back(radius(*zb1, zFront1, rFront1, slope1));
91  rout.emplace_back(radius(*zb1, zFront2, rFront2, slope2));
92  zz.emplace_back(zb);
93  rin.emplace_back(radius(zb, zFront1, rFront1, slope1));
94  rout.emplace_back(radius(zb, zFront2, rFront2, slope2));
95  } else {
96  double z1 = std::min(*zf2, *zb1);
97  double z2 = std::max(*zf2, *zb1);
98 #ifdef EDM_ML_DEBUG
99  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::radius:Try " << zf << ":" << z1 << " : " << z2 << ":" << zb;
100 #endif
101  zz.emplace_back(zf);
102  rin.emplace_back(radius(zf, zFront1, rFront1, slope1));
103  rout.emplace_back(radius(zf, zFront2, rFront2, slope2));
104  zz.emplace_back(z1);
105  rin.emplace_back(radius(z1, zFront1, rFront1, slope1));
106  rout.emplace_back(radius(z1, zFront2, rFront2, slope2));
107  zz.emplace_back(z2);
108  rin.emplace_back(radius(z2, zFront1, rFront1, slope1));
109  rout.emplace_back(radius(z2, zFront2, rFront2, slope2));
110  zz.emplace_back(zb);
111  rin.emplace_back(radius(zb, zFront1, rFront1, slope1));
112  rout.emplace_back(radius(zb, zFront2, rFront2, slope2));
113  }
114  double rmin = *(std::min_element(rout.begin(), rout.end()));
115  if (flag > 1) {
116  for (auto& rr : rout)
117  rr = rmin;
118  }
119 #ifdef EDM_ML_DEBUG
120  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::radius has " << zz.size() << " sections: " << rmin;
121  for (unsigned int k = 0; k < zz.size(); ++k)
122  edm::LogVerbatim("HGCalGeom") << "[" << k << "] Z = " << zz[k] << " R = " << rin[k] << ":" << rout[k];
123 #endif
124 }
125 
126 double HGCalGeomTools::radius(double z,
127  std::vector<double> const& zFront,
128  std::vector<double> const& rFront,
129  std::vector<double> const& slope) {
130  auto itrz = std::lower_bound(zFront.begin(), zFront.end(), z);
131  if (itrz != zFront.begin())
132  --itrz;
133  unsigned int ik = static_cast<unsigned int>(itrz - zFront.begin());
134  if ((ik + 1) < zFront.size() && std::abs(z - zFront[ik + 1]) < tol_)
135  ++ik;
136  double r = rFront[ik] + (z - zFront[ik]) * slope[ik];
137 #ifdef EDM_ML_DEBUG
138  edm::LogVerbatim("HGCalGeom") << "DDHGCalGeomTools: Z " << z << " k " << ik << " R " << r;
139 #endif
140  return r;
141 }
142 
144  double z, int layer0, int layerf, std::vector<double> const& zFront, std::vector<double> const& rFront) {
145  double r = rFront[0];
146 #ifdef EDM_ML_DEBUG
147  unsigned int ik(0);
148 #endif
149  for (unsigned int k = 0; k < rFront.size(); ++k) {
150  int k1 = layerf - layer0 + (int)(k);
151  if (k1 < (int)(zFront.size())) {
152  r = rFront[k];
153 #ifdef EDM_ML_DEBUG
154  ik = k;
155 #endif
156  if (z < zFront[k1] + tol_)
157  break;
158  }
159  }
160 #ifdef EDM_ML_DEBUG
161  edm::LogVerbatim("HGCalGeom") << "DDHGCalGeomTools: Z " << z << ":" << ik << " R " << r;
162 #endif
163  return r;
164 }
165 
166 std::pair<double, double> HGCalGeomTools::shiftXY(int waferPosition, double waferSize) const {
167  double dx(0), dy(0);
168  switch (waferPosition) {
170  dy = factor_ * waferSize;
171  break;
172  }
174  dy = -factor_ * waferSize;
175  break;
176  }
178  dx = factor_ * waferSize;
179  break;
180  }
182  dx = -factor_ * waferSize;
183  break;
184  }
185  }
186 #ifdef EDM_ML_DEBUG
187  edm::LogVerbatim("HGCalGeom") << "Shift for " << waferPosition << " is (" << dx << ":" << dy << ")";
188 #endif
189  return std::make_pair(dx, dy);
190 }
191 
192 double HGCalGeomTools::slope(double z, std::vector<double> const& zFront, std::vector<double> const& slope) {
193  auto itrz = std::lower_bound(zFront.begin(), zFront.end(), z);
194  if (itrz != zFront.begin())
195  --itrz;
196  unsigned int ik = static_cast<unsigned int>(itrz - zFront.begin());
197  // if (ik < zFront.size() && std::abs(z-zFront[ik+1]) < tol_) ++ik;
198 #ifdef EDM_ML_DEBUG
199  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::slope:z " << z << " k " << ik << " Slope " << slope[ik];
200 #endif
201  return slope[ik];
202 }
203 
204 std::pair<double, double> HGCalGeomTools::zradius(double z1,
205  double z2,
206  std::vector<double> const& zF,
207  std::vector<double> const& rF) {
208  double z(-1), r(-1);
209  for (unsigned int k = 0; k < rF.size(); ++k) {
210  if ((z1 > zF[k] - tol_) && (z2 < zF[k] + tol_)) {
211  z = zF[k];
212  r = rF[k];
213  break;
214  }
215  }
216  return std::make_pair(z, r);
217 }
218 
219 std::pair<int32_t, int32_t> HGCalGeomTools::waferCorner(
220  double xpos, double ypos, double r, double R, double rMin, double rMax, bool oldBug) {
222  xc[0] = xpos;
223  yc[0] = ypos + R;
224  xc[1] = xpos - r;
225  yc[1] = ypos + 0.5 * R;
226  if (oldBug) {
227  xc[2] = xpos + r;
228  yc[2] = ypos - 0.5 * R;
229  } else {
230  xc[2] = xpos - r;
231  yc[2] = ypos - 0.5 * R;
232  }
233  xc[3] = xpos;
234  yc[3] = ypos - R;
235  xc[4] = xpos + r;
236  yc[4] = ypos - 0.5 * R;
237  xc[5] = xpos + r;
238  yc[5] = ypos + 0.5 * R;
239  int32_t nCorner(0), firstCorner(-1), firstMiss(-1);
240 #ifdef EDM_ML_DEBUG
241  std::vector<uint32_t> corners;
242 #endif
243  for (uint32_t k = 0; k < HGCalParameters::k_CornerSize; ++k) {
244  double rpos = sqrt(xc[k] * xc[k] + yc[k] * yc[k]);
245  if ((rpos <= rMax) && (rpos >= rMin)) {
246 #ifdef EDM_ML_DEBUG
247  corners.emplace_back(k);
248 #endif
249  if (firstCorner < 0)
250  firstCorner = k;
251  ++nCorner;
252  } else {
253  if (firstMiss < 0)
254  firstMiss = k;
255  }
256  }
257  if ((nCorner > 1) && (firstCorner == 0) && (firstMiss < nCorner)) {
258  firstCorner = firstMiss + HGCalParameters::k_CornerSize - nCorner;
259  }
260 #ifdef EDM_ML_DEBUG
261  edm::LogVerbatim("HGCalGeom") << "waferCorner:: R " << rMin << ":" << rMax << nCorner << " corners; first corner "
262  << firstCorner;
263  for (uint32_t k = 0; k < HGCalParameters::k_CornerSize; ++k) {
264  double rpos = std::sqrt(xc[k] * xc[k] + yc[k] * yc[k]);
265  std::string ok = (std::find(corners.begin(), corners.end(), k) != corners.end()) ? " In" : " Out";
266  edm::LogVerbatim("HGCalGeom") << "Corner[" << k << "] x " << xc[k] << " y " << yc[k] << " R " << rpos << ok;
267  }
268 #endif
269  return std::make_pair(nCorner, firstCorner);
270 }
photonAnalyzer_cfi.rMax
rMax
Definition: photonAnalyzer_cfi.py:91
HGCalGeomTools::waferCorner
static std::pair< int32_t, int32_t > waferCorner(double xpos, double ypos, double r, double R, double rMin, double rMax, bool oldBug=false)
Definition: HGCalGeomTools.cc:219
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
MessageLogger.h
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
HGCalGeomTools::slope
static double slope(double z, std::vector< double > const &zFront, std::vector< double > const &slope)
Definition: HGCalGeomTools.cc:192
HGCalTypes::CornerCenterXm
Definition: HGCalTypes.h:44
min
T min(T a, T b)
Definition: MathUtil.h:58
findQualityFiles.rr
string rr
Definition: findQualityFiles.py:185
HGCalGeomTools::factor_
double factor_
Definition: HGCalGeomTools.h:47
HGCalParameters::k_CornerSize
static constexpr uint32_t k_CornerSize
Definition: HGCalParameters.h:38
HGCalTypes::CornerCenterYm
Definition: HGCalTypes.h:42
HGCalGeomTools::shiftXY
std::pair< double, double > shiftXY(int waferPosition, double waferSize) const
Definition: HGCalGeomTools.cc:166
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
testProducerWithPsetDescEmpty_cfi.z2
z2
Definition: testProducerWithPsetDescEmpty_cfi.py:41
HGCalGeomTools::zradius
static std::pair< double, double > zradius(double z1, double z2, std::vector< double > const &zFront, std::vector< double > const &rFront)
Definition: HGCalGeomTools.cc:204
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DDAxes::z
dqmdumpme.k
k
Definition: dqmdumpme.py:60
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HGCalTypes::CornerCenterYp
Definition: HGCalTypes.h:41
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
createfilelist.int
int
Definition: createfilelist.py:10
edm::LogVerbatim
Definition: MessageLogger.h:297
PVValHelper::dy
Definition: PVValidationHelpers.h:49
alignCSCRings.r
r
Definition: alignCSCRings.py:93
HGCalGeomTools.h
HGCalGeomTools::radius
static void radius(double zf, double zb, std::vector< double > const &zFront1, std::vector< double > const &rFront1, std::vector< double > const &slope1, std::vector< double > const &zFront2, std::vector< double > const &rFront2, std::vector< double > const &slope2, int flag, std::vector< double > &zz, std::vector< double > &rin, std::vector< double > &rout)
Definition: HGCalGeomTools.cc:11
std
Definition: JetResolutionObject.h:76
HGCalGeomTools::HGCalGeomTools
HGCalGeomTools()
Definition: HGCalGeomTools.cc:9
HGCalTypes::CornerCenterXp
Definition: HGCalTypes.h:43
photonAnalyzer_cfi.rMin
rMin
Definition: photonAnalyzer_cfi.py:90
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
slope
static const double slope[3]
Definition: CastorTimeSlew.cc:6
HGCalTypes.h
dttmaxenums::R
Definition: DTTMax.h:29
HGCalParameters.h
HGCalGeomTools::tol_
static constexpr double tol_
Definition: HGCalGeomTools.h:46
PVValHelper::dx
Definition: PVValidationHelpers.h:48
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116