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  if (((zb1 + 1) != zFront1.end()) && (std::abs(*(zb1 + 1) - zb) < tol_)) {
42  dz2 = -2 * tol_;
43  }
44  auto zb2 = std::lower_bound(zFront2.begin(), zFront2.end(), zb);
45  if (zb2 != zFront2.begin())
46  --zb2;
47 #ifdef EDM_ML_DEBUG
48  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::radius:zf " << zf << " : "
49  << static_cast<int>(zf1 - zFront1.begin()) << ":" << *zf1 << " : "
50  << static_cast<int>(zf2 - zFront2.begin()) << ":" << *zf2 << " zb " << zb << ":"
51  << static_cast<int>(zb1 - zFront1.begin()) << " : " << *zb1 << " : "
52  << static_cast<int>(zb2 - zFront2.begin()) << ":" << *zb2 << " Flag " << flag;
53 #endif
54  if ((zf1 == zb1) && (zf2 == zb2)) {
55 #ifdef EDM_ML_DEBUG
56  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::radius:Try 1: " << zf << ":" << zb << " dz " << dz1 << ":" << dz2;
57 #endif
58  zz.emplace_back(zf);
59  rin.emplace_back(radius(zf + dz1, zFront1, rFront1, slope1));
60  rout.emplace_back(radius(zf, zFront2, rFront2, slope2));
61  zz.emplace_back(zb);
62  rin.emplace_back(radius(zb + dz2, zFront1, rFront1, slope1));
63  rout.emplace_back(radius(zb, zFront2, rFront2, slope2));
64  } else if (zf1 == zb1) {
65 #ifdef EDM_ML_DEBUG
66  double z1 = std::max(*zf2, *zb2);
67  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::radius:Try 2:" << zf << ":" << *zb2 << " (" << z1 << ") : " << zb;
68 #endif
69  zz.emplace_back(zf);
70  rin.emplace_back(radius(zf, zFront1, rFront1, slope1));
71  rout.emplace_back(radius(zf, zFront2, rFront2, slope2));
72  if (slope(*zb2, zFront2, slope2) < tol_) {
73  zz.emplace_back(*zb2);
74  rin.emplace_back(radius(*zb2, zFront1, rFront1, slope1));
75  rout.emplace_back(radius(*zb2 - tol_, zFront2, rFront2, slope2));
76  }
77  if ((std::abs(*zb2 - zb) > tol_) && (std::abs(*zb2 - zf) > tol_)) {
78  zz.emplace_back(*zb2);
79  rin.emplace_back(radius(*zb2, zFront1, rFront1, slope1));
80  rout.emplace_back(radius(*zb2, zFront2, rFront2, slope2));
81  }
82  zz.emplace_back(zb);
83  rin.emplace_back(radius(zb, zFront1, rFront1, slope1));
84  rout.emplace_back(radius(zb, zFront2, rFront2, slope2));
85  } else if (zf2 == zb2) {
86 #ifdef EDM_ML_DEBUG
87  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::radius:Try 3: " << zf << ":" << *zb1 << ":" << zb;
88 #endif
89  zz.emplace_back(zf);
90  rin.emplace_back(radius(zf, zFront1, rFront1, slope1));
91  rout.emplace_back(radius(zf, zFront2, rFront2, slope2));
92  if (slope(*zb1, zFront1, slope1) < tol_) {
93  zz.emplace_back(*zb1);
94  rin.emplace_back(radius(*zb1 - tol_, zFront1, rFront1, slope1));
95  rout.emplace_back(radius(*zb1, zFront2, rFront2, slope2));
96  }
97  if ((std::abs(*zb1 - zb) > tol_) && (std::abs(*zb1 - zf) > tol_)) {
98  zz.emplace_back(*zb1);
99  rin.emplace_back(radius(*zb1, zFront1, rFront1, slope1));
100  rout.emplace_back(radius(*zb1, zFront2, rFront2, slope2));
101  }
102  zz.emplace_back(zb);
103  rin.emplace_back(radius(zb, zFront1, rFront1, slope1));
104  rout.emplace_back(radius(zb, zFront2, rFront2, slope2));
105  } else {
106  double z1 = std::min(*zf2, *zb1);
107  double z2 = std::max(*zf2, *zb1);
108 #ifdef EDM_ML_DEBUG
109  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::radius:Try 4: " << zf << ":" << z1 << " : " << z2 << ":" << zb;
110 #endif
111  zz.emplace_back(zf);
112  rin.emplace_back(radius(zf, zFront1, rFront1, slope1));
113  rout.emplace_back(radius(zf, zFront2, rFront2, slope2));
114  zz.emplace_back(z1);
115  rin.emplace_back(radius(z1, zFront1, rFront1, slope1));
116  rout.emplace_back(radius(z1, zFront2, rFront2, slope2));
117  zz.emplace_back(z2);
118  rin.emplace_back(radius(z2, zFront1, rFront1, slope1));
119  rout.emplace_back(radius(z2, zFront2, rFront2, slope2));
120  zz.emplace_back(zb);
121  rin.emplace_back(radius(zb, zFront1, rFront1, slope1));
122  rout.emplace_back(radius(zb, zFront2, rFront2, slope2));
123  }
124  double rmin = *(std::min_element(rout.begin(), rout.end()));
125  if (flag > 1) {
126  for (auto& rr : rout)
127  rr = rmin;
128  }
129 #ifdef EDM_ML_DEBUG
130  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::radius has " << zz.size() << " sections: " << rmin;
131  for (unsigned int k = 0; k < zz.size(); ++k)
132  edm::LogVerbatim("HGCalGeom") << "[" << k << "] Z = " << zz[k] << " R = " << rin[k] << ":" << rout[k];
133 #endif
134 }
135 
136 double HGCalGeomTools::radius(double z,
137  std::vector<double> const& zFront,
138  std::vector<double> const& rFront,
139  std::vector<double> const& slope) {
140  auto itrz = std::lower_bound(zFront.begin(), zFront.end(), z);
141  if (itrz != zFront.begin())
142  --itrz;
143  unsigned int ik = static_cast<unsigned int>(itrz - zFront.begin());
144  if ((ik + 1) < zFront.size() && std::abs(z - zFront[ik + 1]) < tol_)
145  ++ik;
146  double r = rFront[ik] + (z - zFront[ik]) * slope[ik];
147 #ifdef EDM_ML_DEBUG
148  edm::LogVerbatim("HGCalGeom") << "DDHGCalGeomTools: Z " << z << " k " << ik << " R " << r;
149 #endif
150  return r;
151 }
152 
154  double z, int layer0, int layerf, std::vector<double> const& zFront, std::vector<double> const& rFront) {
155  double r = rFront[0];
156 #ifdef EDM_ML_DEBUG
157  unsigned int ik(0);
158 #endif
159  for (unsigned int k = 0; k < rFront.size(); ++k) {
160  int k1 = layerf - layer0 + (int)(k);
161  if (k1 < (int)(zFront.size())) {
162  r = rFront[k];
163 #ifdef EDM_ML_DEBUG
164  ik = k;
165 #endif
166  if (z < zFront[k1] + tol_)
167  break;
168  }
169  }
170 #ifdef EDM_ML_DEBUG
171  edm::LogVerbatim("HGCalGeom") << "DDHGCalGeomTools: Z " << z << ":" << ik << " R " << r;
172 #endif
173  return r;
174 }
175 
176 std::pair<double, double> HGCalGeomTools::shiftXY(int waferPosition, double waferSize) const {
177  double dx(0), dy(0);
178  switch (waferPosition) {
180  dy = factor_ * waferSize;
181  break;
182  }
184  dy = -factor_ * waferSize;
185  break;
186  }
188  dx = factor_ * waferSize;
189  break;
190  }
192  dx = -factor_ * waferSize;
193  break;
194  }
195  }
196 #ifdef EDM_ML_DEBUG
197  edm::LogVerbatim("HGCalGeom") << "Shift for " << waferPosition << " is (" << dx << ":" << dy << ")";
198 #endif
199  return std::make_pair(dx, dy);
200 }
201 
202 double HGCalGeomTools::slope(double z, std::vector<double> const& zFront, std::vector<double> const& slope) {
203  auto itrz = std::lower_bound(zFront.begin(), zFront.end(), z);
204  if (itrz != zFront.begin())
205  --itrz;
206  unsigned int ik = static_cast<unsigned int>(itrz - zFront.begin());
207  // if (ik < zFront.size() && std::abs(z-zFront[ik+1]) < tol_) ++ik;
208 #ifdef EDM_ML_DEBUG
209  edm::LogVerbatim("HGCalGeom") << "HGCalGeomTools::slope:z " << z << " k " << ik << " Slope " << slope[ik];
210 #endif
211  return slope[ik];
212 }
213 
214 std::pair<double, double> HGCalGeomTools::zradius(double z1,
215  double z2,
216  std::vector<double> const& zF,
217  std::vector<double> const& rF) {
218  double z(-1), r(-1);
219  for (unsigned int k = 0; k < rF.size(); ++k) {
220  if ((z1 > zF[k] - tol_) && (z2 < zF[k] + tol_)) {
221  z = zF[k];
222  r = rF[k];
223  break;
224  }
225  }
226  return std::make_pair(z, r);
227 }
228 
229 std::pair<int32_t, int32_t> HGCalGeomTools::waferCorner(
230  double xpos, double ypos, double r, double R, double rMin, double rMax, bool oldBug) {
232  xc[0] = xpos;
233  yc[0] = ypos + R;
234  xc[1] = xpos - r;
235  yc[1] = ypos + 0.5 * R;
236  if (oldBug) {
237  xc[2] = xpos + r;
238  yc[2] = ypos - 0.5 * R;
239  } else {
240  xc[2] = xpos - r;
241  yc[2] = ypos - 0.5 * R;
242  }
243  xc[3] = xpos;
244  yc[3] = ypos - R;
245  xc[4] = xpos + r;
246  yc[4] = ypos - 0.5 * R;
247  xc[5] = xpos + r;
248  yc[5] = ypos + 0.5 * R;
249  int32_t nCorner(0), firstCorner(-1), firstMiss(-1);
250 #ifdef EDM_ML_DEBUG
251  std::vector<uint32_t> corners;
252 #endif
253  for (uint32_t k = 0; k < HGCalParameters::k_CornerSize; ++k) {
254  double rpos = sqrt(xc[k] * xc[k] + yc[k] * yc[k]);
255  if ((rpos <= rMax) && (rpos >= rMin)) {
256 #ifdef EDM_ML_DEBUG
257  corners.emplace_back(k);
258 #endif
259  if (firstCorner < 0)
260  firstCorner = k;
261  ++nCorner;
262  } else {
263  if (firstMiss < 0)
264  firstMiss = k;
265  }
266  }
267  if ((nCorner > 1) && (firstCorner == 0) && (firstMiss < nCorner)) {
268  firstCorner = firstMiss + HGCalParameters::k_CornerSize - nCorner;
269  }
270 #ifdef EDM_ML_DEBUG
271  edm::LogVerbatim("HGCalGeom") << "waferCorner:: R " << rMin << ":" << rMax << nCorner << " corners; first corner "
272  << firstCorner;
273  for (uint32_t k = 0; k < HGCalParameters::k_CornerSize; ++k) {
274  double rpos = std::sqrt(xc[k] * xc[k] + yc[k] * yc[k]);
275  std::string ok = (std::find(corners.begin(), corners.end(), k) != corners.end()) ? " In" : " Out";
276  edm::LogVerbatim("HGCalGeom") << "Corner[" << k << "] x " << xc[k] << " y " << yc[k] << " R " << rpos << ok;
277  }
278 #endif
279  return std::make_pair(nCorner, firstCorner);
280 }
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:229
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:202
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:44
HGCalTypes::CornerCenterYm
Definition: HGCalTypes.h:42
HGCalGeomTools::shiftXY
std::pair< double, double > shiftXY(int waferPosition, double waferSize) const
Definition: HGCalGeomTools.cc:176
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:214
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DDAxes::z
dqmdumpme.k
k
Definition: dqmdumpme.py:60
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HGCalTypes::CornerCenterYp
Definition: HGCalTypes.h:41
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
createfilelist.int
int
Definition: createfilelist.py:10
PVValHelper::dy
Definition: PVValidationHelpers.h:50
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
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
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
edm::Log
Definition: MessageLogger.h:70
dttmaxenums::R
Definition: DTTMax.h:29
HGCalParameters.h
HGCalGeomTools::tol_
static constexpr double tol_
Definition: HGCalGeomTools.h:46
PVValHelper::dx
Definition: PVValidationHelpers.h:49
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116