6#include "CLHEP/Units/SystemOfUnits.h"
15constexpr double Binomial(
int n,
int k) {
17 if (n < 0 || k < 0 || n < k) {
18 return std::numeric_limits<double>::signaling_NaN();
20 if (k == 0 || n == k) {
24 int k1 = std::min(k, n - k);
27 for (
double i = k1;
i > 1.; --
i) {
33constexpr int PolyDegree = 20;
34constexpr int PolyNCoeff = PolyDegree + 1;
36constexpr std::array<double, PolyNCoeff> BinomialCache() {
37 constexpr double b0 = Binomial(20, 0);
38 constexpr double b1 = Binomial(20, 1);
39 constexpr double b2 = Binomial(20, 2);
40 constexpr double b3 = Binomial(20, 3);
41 constexpr double b4 = Binomial(20, 4);
42 constexpr double b5 = Binomial(20, 5);
43 constexpr double b6 = Binomial(20, 6);
44 constexpr double b7 = Binomial(20, 7);
45 constexpr double b8 = Binomial(20, 8);
46 constexpr double b9 = Binomial(20, 9);
47 constexpr double b10 = Binomial(20, 10);
49 std::array<double, PolyNCoeff>
res = {b0, b1, b2, b3, b4, b5, b6,
50 b7, b8, b9, b10, b9, b8, b7,
51 b6, b5, b4, b3, b2, b1, b0};
58constexpr std::array<double, PolyNCoeff> s_binomialCache = BinomialCache();
61double bernstein_grundpolynom(
const double t,
const int i) {
62 static_assert(s_binomialCache.size() > N,
63 " Binomial cache must be larger than N");
65 return s_binomialCache[
i] * std::pow(t, i) * std::pow(1. - t, N - i);
68double bernstein_bezier(
const double u,
const double v,
const float *
P) {
72 std::array<double,PolyNCoeff> bernstein_grundpolynomU{};
73 std::array<double,PolyNCoeff> bernstein_grundpolynomV{};
74 for (
int i = 0;
i < PolyNCoeff; ++
i) {
75 bernstein_grundpolynomU[
i] = bernstein_grundpolynom<PolyDegree>(u, i);
76 bernstein_grundpolynomV[
i] = bernstein_grundpolynom<PolyDegree>(v, i);
79 for (
int i = 0;
i < PolyNCoeff; ++
i) {
82 const double bernstein_grundpolynom_i = bernstein_grundpolynomU[
i];
84 for (
int j = 0; j < PolyNCoeff; ++j) {
86 const int k = (
i * (PolyDegree + 1)) + j;
92 const double bernstein_grundpolynom_j = bernstein_grundpolynomV[j];
93 r += bernstein_grundpolynom_i * bernstein_grundpolynom_j *
P[
k];
103 else distosize = 441;
109 std::vector<float>
map(distosize, 0.0);
121 double localphi = locpos[0];
122 double localeta = locpos[1];
124 const unsigned long long ull_id =
getId(hashID);
127 if (ull_id == 0 &&
m_version > 1) {
return nullCorrection; }
131 if (std::fabs(direction.z())<1.*CLHEP::micrometer) {
return nullCorrection; }
136 double invtanphi = direction.x()/direction.z();
137 double invtaneta = direction.y()/direction.z();
138 if (std::sqrt(invtanphi*invtanphi+invtaneta*invtaneta)>100.0) {
return nullCorrection; }
150 float modEtaSize, modPhiSize;
153 if (ull_id >= 0x200000000000000 && ull_id <= 0x20d980000000000) {
155 modEtaSize = 19.75 * CLHEP::millimeter;
156 modPhiSize = 16.75 * CLHEP::millimeter;
158 modEtaSize = 40.4 * CLHEP::millimeter;
159 modPhiSize = 16.8 * CLHEP::millimeter;
162 modEtaSize = 60.2 * CLHEP::millimeter;
163 modPhiSize = 16.44 * CLHEP::millimeter;
166 localZ =
getInSituZ(localeta, modEtaSize, localphi, modPhiSize,
map.data());
169 double localetaCor = -localZ * invtaneta;
170 double localphiCor = -localZ * invtanphi;
175 if (
getVersion()==0) { localphiCor = -localphiCor; }
182 newlocpos +=
correction(hashID, locpos, direction);
188 newlocpos -=
correction(hashID, locpos, direction);
194 double etaHalfRangeBB = eta_size * 10. / 21.;
195 double phiHalfRangeBB = phi_size * 10. / 21.;
196 double etaRangeBB = eta_size * 20. / 21.;
197 double phiRangeBB = phi_size * 20. / 21.;
202 if (std::abs(localeta) - etaHalfRangeBB > 0) {
204 eta = (localeta + etaHalfRangeBB) / etaRangeBB;
206 eta = 1. + (localeta - etaHalfRangeBB) / etaRangeBB;
208 eta = localeta / etaRangeBB + 0.5;
210 if (std::abs(localphi) - phiHalfRangeBB > 0) {
212 phi = (localphi + phiHalfRangeBB) / phiRangeBB;
214 phi = 1. + (localphi - phiHalfRangeBB) / phiRangeBB;
216 phi = localphi / phiRangeBB + 0.5;
218 return bernstein_bezier(
eta,
phi, disto);
223 const double xFE = 22.0 * CLHEP::millimeter;
224 const double yFE = 60.8 * CLHEP::millimeter;
226 double data0 = disto[0] / CLHEP::meter;
227 double data1 = disto[1] / CLHEP::meter;
228 double data2 = std::tan(0.5 * disto[2] * CLHEP::degree);
230 double twist1 = -data2;
231 double twist2 = data2;
232 double b1 = std::sqrt((1. + twist1*twist1) * (1. + twist1*twist1) * (1. + twist1*twist1));
233 double b2 = std::sqrt((1. + twist2*twist2) * (1. + twist2*twist2) * (1. + twist2*twist2));
234 double z1 = localeta * twist1 - 0.5 * b1 * localeta*localeta * data1;
235 double z2 = localeta * twist2 - 0.5 * b2 * localeta*localeta * data0;
236 double zoff1 = (b1 * yFE*yFE * data1) / 24.;
237 double zoff2 = (b2 * yFE*yFE * data0) / 24.;
241 return z1 + ((z2 - z1) / xFE) * (localphi + xFE / 2.);
247 if (ull_id < 0x240000000000000)
return false;
256 if (ull_id >= 0x200000000000000 && ull_id <= 0x200180000000000)
return true;
257 if (ull_id >= 0x200800000000000 && ull_id <= 0x200980000000000)
return true;
260 if (ull_id >= 0x201000000000000 && ull_id <= 0x201180000000000)
return true;
261 if (ull_id >= 0x201800000000000 && ull_id <= 0x201980000000000)
return true;
264 if (ull_id >= 0x202000000000000 && ull_id <= 0x202180000000000)
return true;
265 if (ull_id >= 0x202800000000000 && ull_id <= 0x202980000000000)
return true;
268 if (ull_id >= 0x203000000000000 && ull_id <= 0x203180000000000)
return true;
269 if (ull_id >= 0x203800000000000 && ull_id <= 0x203980000000000)
return true;
272 if (ull_id >= 0x204000000000000 && ull_id <= 0x204180000000000)
return true;
273 if (ull_id >= 0x204800000000000 && ull_id <= 0x204980000000000)
return true;
276 if (ull_id >= 0x205000000000000 && ull_id <= 0x205180000000000)
return true;
277 if (ull_id >= 0x205800000000000 && ull_id <= 0x205980000000000)
return true;
280 if (ull_id >= 0x206000000000000 && ull_id <= 0x206180000000000)
return true;
281 if (ull_id >= 0x206800000000000 && ull_id <= 0x206980000000000)
return true;
284 if (ull_id >= 0x207000000000000 && ull_id <= 0x207180000000000)
return true;
285 if (ull_id >= 0x207800000000000 && ull_id <= 0x207980000000000)
return true;
288 if (ull_id >= 0x208000000000000 && ull_id <= 0x208180000000000)
return true;
289 if (ull_id >= 0x208800000000000 && ull_id <= 0x208980000000000)
return true;
292 if (ull_id >= 0x209000000000000 && ull_id <= 0x209180000000000)
return true;
293 if (ull_id >= 0x209800000000000 && ull_id <= 0x209980000000000)
return true;
296 if (ull_id >= 0x20a000000000000 && ull_id <= 0x20a180000000000)
return true;
297 if (ull_id >= 0x20a800000000000 && ull_id <= 0x20a980000000000)
return true;
300 if (ull_id >= 0x20b000000000000 && ull_id <= 0x20b180000000000)
return true;
301 if (ull_id >= 0x20b800000000000 && ull_id <= 0x20b980000000000)
return true;
304 if (ull_id >= 0x20c000000000000 && ull_id <= 0x20c180000000000)
return true;
305 if (ull_id >= 0x20c800000000000 && ull_id <= 0x20c980000000000)
return true;
308 if (ull_id >= 0x20d000000000000 && ull_id <= 0x20d180000000000)
return true;
309 if (ull_id >= 0x20d800000000000 && ull_id <= 0x20d980000000000)
return true;
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
std::pair< std::vector< unsigned int >, bool > res
Hold pixel distortion data produced by PixelDistortionAlg.
Amg::Vector2D correction(uint32_t hashID, const Amg::Vector2D &locpos, const Amg::Vector3D &direction) const
std::unordered_map< uint32_t, unsigned long long > m_ids
Amg::Vector2D correctSimulation(uint32_t hashID, const Amg::Vector2D &locpos, const Amg::Vector3D &direction) const
static double getSurveyZ(const double localeta, const double localphi, const float *disto)
static double getInSituZ(const double localeta, const double eta_size, const double localphi, const double phi_size, const float *disto)
static bool isOldParam(const unsigned long long ull_id)
std::vector< float > getDistortionMap(uint32_t id) const
static bool isIBL3D(const unsigned long long ull_id)
Amg::Vector2D correctReconstruction(uint32_t hashID, const Amg::Vector2D &locpos, const Amg::Vector3D &direction) const
std::unordered_map< uint32_t, std::vector< float > > m_distortionMap
unsigned long long getId(uint32_t hashID) const
void search(TDirectory *td, const std::string &s, std::string cwd, node *n)
recursive directory search for TH1 and TH2 and TProfiles
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
Macro wrapping the nonstandard restrict keyword.