ATLAS Offline Software
T2TrackBSLLPoly.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2019, 2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <cmath>
6 #include <cstdint>
7 
8 #include "T2TrackBSLLPoly.h"
9 
10 using namespace PESA;
11 
12 namespace {
13 
14 // Ordering of the monomials in Bx, By, tx, ty powers,
15 // array indices correspond to power of those variables
16 const std::int8_t g_order[3][3][3][3] = {
17 
18 {
19  {{ 0, 1, 2 }, // Bx**0, By**0, tx**0, ty**0..ty**2
20  { 3, 4, -1 }, // Bx**0, By**0, tx**1, ty**0..ty**2
21  { 5, -1, -1 }}, // Bx**0, By**0, tx**2, ty**0..ty**2
22 
23  {{ 6, 7, -1 }, // Bx**0, By**1, tx**0, ty**0..ty**2
24  { 8, -1, -1 }, // Bx**0, By**1, tx**1, ty**0..ty**2
25  { -1, -1, -1 }}, // Bx**0, By**1, tx**2, ty**0..ty**2
26 
27  {{ 9, -1, -1 }, // Bx**0, By**2, tx**0, ty**0..ty**2
28  { -1, -1, -1 }, // Bx**0, By**2, tx**1, ty**0..ty**2
29  { -1, -1, -1 }}, // Bx**0, By**2, tx**2, ty**0..ty**2
30 },
31 
32 {
33  {{ 10, 11, -1 }, // Bx**1, By**0, tx**0, ty**0..ty**2
34  { 12, -1, -1 }, // Bx**1, By**0, tx**1, ty**0..ty**2
35  { -1, -1, -1 }}, // Bx**1, By**0, tx**2, ty**0..ty**2
36 
37  {{ 13, -1, -1 }, // Bx**1, By**1, tx**0, ty**0..ty**2
38  { -1, -1, -1 }, // Bx**1, By**1, tx**1, ty**0..ty**2
39  { -1, -1, -1 }}, // Bx**1, By**1, tx**2, ty**0..ty**2
40 
41  {{ -1, -1, -1 }, // Bx**1, By**2, tx**0, ty**0..ty**2
42  { -1, -1, -1 }, // Bx**1, By**2, tx**1, ty**0..ty**2
43  { -1, -1, -1 }}, // Bx**1, By**2, tx**2, ty**0..ty**2
44 },
45 
46 {
47  {{ 14, -1, -1 }, // Bx**2, By**0, tx**0, ty**0..ty**2
48  { -1, -1, -1 }, // Bx**2, By**0, tx**1, ty**0..ty**2
49  { -1, -1, -1 }}, // Bx**2, By**0, tx**2, ty**0..ty**2
50 
51  {{ -1, -1, -1 }, // Bx**2, By**1, tx**0, ty**0..ty**2
52  { -1, -1, -1 }, // Bx**2, By**1, tx**1, ty**0..ty**2
53  { -1, -1, -1 }}, // Bx**2, By**1, tx**2, ty**0..ty**2
54 
55  {{ -1, -1, -1 }, // Bx**2, By**2, tx**0, ty**0..ty**2
56  { -1, -1, -1 }, // Bx**2, By**2, tx**1, ty**0..ty**2
57  { -1, -1, -1 }}, // Bx**2, By**2, tx**2, ty**0..ty**2
58 }
59 };
60 
61 // number of possible combinations of all powers,
62 // 15 is for squares, 1 for log
63 const unsigned g_size = 15 + 1;
64 
65 // Ordering of the monomials in omegax, omegay powers,
66 // array indices correspond to power of those variables
67 const std::int8_t g_order2[3][3] = {
68  { 0, 1, 2 }, // Bx**0, By**0, tx**0, ty**0..ty**2
69  { 3, 4, -1 }, // Bx**0, By**0, tx**1, ty**0..ty**2
70  { 5, -1, -1 }, // Bx**0, By**0, tx**2, ty**0..ty**2
71 };
72 
73 // number of possible combinations of omega powers
74 const unsigned g_size2 = 6;
75 
76 } // namespace
77 
78 unsigned
80 {
81  // two extra bins to count number of tracks and beam_size*n_tracks
82  return
83  g_size*g_size2 // all polynomial coefficients
84  + 1 // Sum(z0)
85  + 1 // Sum(z0**2)
86  + 1 // Sum(1)
87  + 1 // Sum(beam_size)
88  ;
89 }
90 
91 int
92 T2TrackBSLLPoly::idx(unsigned power_Bx, unsigned power_By,
93  unsigned power_tx, unsigned power_ty,
94  unsigned power_omegax, unsigned power_omegay)
95 {
96  if (power_Bx > 2 or power_By > 2
97  or power_tx > 2 or power_ty > 2
98  or power_omegax > 2 or power_omegay > 2) {
99  return -1;
100  }
101 
102  int idx = g_order[power_Bx][power_By][power_tx][power_ty];
103  if (idx < 0) return -1;
104 
105  int idx2 = g_order2[power_omegax][power_omegay];
106  if (idx2 < 0) return -1;
107 
108  return idx*g_size2 + idx2;
109 }
110 
111 void
112 T2TrackBSLLPoly::update(double z_0, double d_0, double phi, double var_d0, std::vector<double>& coeff)
113 {
114  if (coeff.empty()) {
115  coeff.resize(nbins(), 0.);
116  }
117 
118  double cos_phi = std::cos(phi);
119  double sin_phi = std::sin(phi);
120  double var_b = m_beam_size*m_beam_size;
121  double var_bd = var_d0 + var_b;
122 
123  // z-0 and its square
124  coeff[g_size*g_size2] += z_0;
125  coeff[g_size*g_size2+1] += z_0*z_0;
126 
127  // store number of tracks and beam_size*n_tracks in last two bins
128  coeff[g_size*g_size2+2] += 1;
129  coeff[g_size*g_size2+3] += m_beam_size;
130 
131  // this code is generated by notebook, no point in changing it here
132  using std::pow;
133  coeff[idx(0, 0, 0, 0, 0, 0)] += -pow(d_0, 2)/(2*var_bd);
134  coeff[idx(0, 0, 0, 0, 0, 1)] += pow(cos_phi, 2)*pow(d_0, 2)/(2*pow(var_bd, 2));
135  coeff[idx(0, 0, 0, 0, 0, 2)] += -pow(cos_phi, 4)*pow(d_0, 2)/(2*pow(var_bd, 3));
136  coeff[idx(0, 0, 0, 0, 1, 0)] += pow(d_0, 2)*pow(sin_phi, 2)/(2*pow(var_bd, 2));
137  coeff[idx(0, 0, 0, 0, 1, 1)] += -pow(cos_phi, 2)*pow(d_0, 2)*pow(sin_phi, 2)/pow(var_bd, 3);
138  coeff[idx(0, 0, 0, 0, 2, 0)] += -pow(d_0, 2)*pow(sin_phi, 4)/(2*pow(var_bd, 3));
139  coeff[idx(0, 0, 0, 1, 0, 0)] += cos_phi*d_0*z_0/var_bd;
140  coeff[idx(0, 0, 0, 1, 0, 1)] += -pow(cos_phi, 3)*d_0*z_0/pow(var_bd, 2);
141  coeff[idx(0, 0, 0, 1, 0, 2)] += pow(cos_phi, 5)*d_0*z_0/pow(var_bd, 3);
142  coeff[idx(0, 0, 0, 1, 1, 0)] += -cos_phi*d_0*pow(sin_phi, 2)*z_0/pow(var_bd, 2);
143  coeff[idx(0, 0, 0, 1, 1, 1)] += 2*pow(cos_phi, 3)*d_0*pow(sin_phi, 2)*z_0/pow(var_bd, 3);
144  coeff[idx(0, 0, 0, 1, 2, 0)] += cos_phi*d_0*pow(sin_phi, 4)*z_0/pow(var_bd, 3);
145  coeff[idx(0, 0, 0, 2, 0, 0)] += -pow(cos_phi, 2)*pow(z_0, 2)/(2*var_bd);
146  coeff[idx(0, 0, 0, 2, 0, 1)] += pow(cos_phi, 4)*pow(z_0, 2)/(2*pow(var_bd, 2));
147  coeff[idx(0, 0, 0, 2, 0, 2)] += -pow(cos_phi, 6)*pow(z_0, 2)/(2*pow(var_bd, 3));
148  coeff[idx(0, 0, 0, 2, 1, 0)] += pow(cos_phi, 2)*pow(sin_phi, 2)*pow(z_0, 2)/(2*pow(var_bd, 2));
149  coeff[idx(0, 0, 0, 2, 1, 1)] += -pow(cos_phi, 4)*pow(sin_phi, 2)*pow(z_0, 2)/pow(var_bd, 3);
150  coeff[idx(0, 0, 0, 2, 2, 0)] += -pow(cos_phi, 2)*pow(sin_phi, 4)*pow(z_0, 2)/(2*pow(var_bd, 3));
151  coeff[idx(0, 0, 1, 0, 0, 0)] += -d_0*sin_phi*z_0/var_bd;
152  coeff[idx(0, 0, 1, 0, 0, 1)] += pow(cos_phi, 2)*d_0*sin_phi*z_0/pow(var_bd, 2);
153  coeff[idx(0, 0, 1, 0, 0, 2)] += -pow(cos_phi, 4)*d_0*sin_phi*z_0/pow(var_bd, 3);
154  coeff[idx(0, 0, 1, 0, 1, 0)] += d_0*pow(sin_phi, 3)*z_0/pow(var_bd, 2);
155  coeff[idx(0, 0, 1, 0, 1, 1)] += -2*pow(cos_phi, 2)*d_0*pow(sin_phi, 3)*z_0/pow(var_bd, 3);
156  coeff[idx(0, 0, 1, 0, 2, 0)] += -d_0*pow(sin_phi, 5)*z_0/pow(var_bd, 3);
157  coeff[idx(0, 0, 1, 1, 0, 0)] += cos_phi*sin_phi*pow(z_0, 2)/var_bd;
158  coeff[idx(0, 0, 1, 1, 0, 1)] += -pow(cos_phi, 3)*sin_phi*pow(z_0, 2)/pow(var_bd, 2);
159  coeff[idx(0, 0, 1, 1, 0, 2)] += pow(cos_phi, 5)*sin_phi*pow(z_0, 2)/pow(var_bd, 3);
160  coeff[idx(0, 0, 1, 1, 1, 0)] += -cos_phi*pow(sin_phi, 3)*pow(z_0, 2)/pow(var_bd, 2);
161  coeff[idx(0, 0, 1, 1, 1, 1)] += 2*pow(cos_phi, 3)*pow(sin_phi, 3)*pow(z_0, 2)/pow(var_bd, 3);
162  coeff[idx(0, 0, 1, 1, 2, 0)] += cos_phi*pow(sin_phi, 5)*pow(z_0, 2)/pow(var_bd, 3);
163  coeff[idx(0, 0, 2, 0, 0, 0)] += -pow(sin_phi, 2)*pow(z_0, 2)/(2*var_bd);
164  coeff[idx(0, 0, 2, 0, 0, 1)] += pow(cos_phi, 2)*pow(sin_phi, 2)*pow(z_0, 2)/(2*pow(var_bd, 2));
165  coeff[idx(0, 0, 2, 0, 0, 2)] += -pow(cos_phi, 4)*pow(sin_phi, 2)*pow(z_0, 2)/(2*pow(var_bd, 3));
166  coeff[idx(0, 0, 2, 0, 1, 0)] += pow(sin_phi, 4)*pow(z_0, 2)/(2*pow(var_bd, 2));
167  coeff[idx(0, 0, 2, 0, 1, 1)] += -pow(cos_phi, 2)*pow(sin_phi, 4)*pow(z_0, 2)/pow(var_bd, 3);
168  coeff[idx(0, 0, 2, 0, 2, 0)] += -pow(sin_phi, 6)*pow(z_0, 2)/(2*pow(var_bd, 3));
169  coeff[idx(0, 1, 0, 0, 0, 0)] += cos_phi*d_0/var_bd;
170  coeff[idx(0, 1, 0, 0, 0, 1)] += -pow(cos_phi, 3)*d_0/pow(var_bd, 2);
171  coeff[idx(0, 1, 0, 0, 0, 2)] += pow(cos_phi, 5)*d_0/pow(var_bd, 3);
172  coeff[idx(0, 1, 0, 0, 1, 0)] += -cos_phi*d_0*pow(sin_phi, 2)/pow(var_bd, 2);
173  coeff[idx(0, 1, 0, 0, 1, 1)] += 2*pow(cos_phi, 3)*d_0*pow(sin_phi, 2)/pow(var_bd, 3);
174  coeff[idx(0, 1, 0, 0, 2, 0)] += cos_phi*d_0*pow(sin_phi, 4)/pow(var_bd, 3);
175  coeff[idx(0, 1, 0, 1, 0, 0)] += -pow(cos_phi, 2)*z_0/var_bd;
176  coeff[idx(0, 1, 0, 1, 0, 1)] += pow(cos_phi, 4)*z_0/pow(var_bd, 2);
177  coeff[idx(0, 1, 0, 1, 0, 2)] += -pow(cos_phi, 6)*z_0/pow(var_bd, 3);
178  coeff[idx(0, 1, 0, 1, 1, 0)] += pow(cos_phi, 2)*pow(sin_phi, 2)*z_0/pow(var_bd, 2);
179  coeff[idx(0, 1, 0, 1, 1, 1)] += -2*pow(cos_phi, 4)*pow(sin_phi, 2)*z_0/pow(var_bd, 3);
180  coeff[idx(0, 1, 0, 1, 2, 0)] += -pow(cos_phi, 2)*pow(sin_phi, 4)*z_0/pow(var_bd, 3);
181  coeff[idx(0, 1, 1, 0, 0, 0)] += cos_phi*sin_phi*z_0/var_bd;
182  coeff[idx(0, 1, 1, 0, 0, 1)] += -pow(cos_phi, 3)*sin_phi*z_0/pow(var_bd, 2);
183  coeff[idx(0, 1, 1, 0, 0, 2)] += pow(cos_phi, 5)*sin_phi*z_0/pow(var_bd, 3);
184  coeff[idx(0, 1, 1, 0, 1, 0)] += -cos_phi*pow(sin_phi, 3)*z_0/pow(var_bd, 2);
185  coeff[idx(0, 1, 1, 0, 1, 1)] += 2*pow(cos_phi, 3)*pow(sin_phi, 3)*z_0/pow(var_bd, 3);
186  coeff[idx(0, 1, 1, 0, 2, 0)] += cos_phi*pow(sin_phi, 5)*z_0/pow(var_bd, 3);
187  coeff[idx(0, 2, 0, 0, 0, 0)] += -pow(cos_phi, 2)/(2*var_bd);
188  coeff[idx(0, 2, 0, 0, 0, 1)] += pow(cos_phi, 4)/(2*pow(var_bd, 2));
189  coeff[idx(0, 2, 0, 0, 0, 2)] += -pow(cos_phi, 6)/(2*pow(var_bd, 3));
190  coeff[idx(0, 2, 0, 0, 1, 0)] += pow(cos_phi, 2)*pow(sin_phi, 2)/(2*pow(var_bd, 2));
191  coeff[idx(0, 2, 0, 0, 1, 1)] += -pow(cos_phi, 4)*pow(sin_phi, 2)/pow(var_bd, 3);
192  coeff[idx(0, 2, 0, 0, 2, 0)] += -pow(cos_phi, 2)*pow(sin_phi, 4)/(2*pow(var_bd, 3));
193  coeff[idx(1, 0, 0, 0, 0, 0)] += -d_0*sin_phi/var_bd;
194  coeff[idx(1, 0, 0, 0, 0, 1)] += pow(cos_phi, 2)*d_0*sin_phi/pow(var_bd, 2);
195  coeff[idx(1, 0, 0, 0, 0, 2)] += -pow(cos_phi, 4)*d_0*sin_phi/pow(var_bd, 3);
196  coeff[idx(1, 0, 0, 0, 1, 0)] += d_0*pow(sin_phi, 3)/pow(var_bd, 2);
197  coeff[idx(1, 0, 0, 0, 1, 1)] += -2*pow(cos_phi, 2)*d_0*pow(sin_phi, 3)/pow(var_bd, 3);
198  coeff[idx(1, 0, 0, 0, 2, 0)] += -d_0*pow(sin_phi, 5)/pow(var_bd, 3);
199  coeff[idx(1, 0, 0, 1, 0, 0)] += cos_phi*sin_phi*z_0/var_bd;
200  coeff[idx(1, 0, 0, 1, 0, 1)] += -pow(cos_phi, 3)*sin_phi*z_0/pow(var_bd, 2);
201  coeff[idx(1, 0, 0, 1, 0, 2)] += pow(cos_phi, 5)*sin_phi*z_0/pow(var_bd, 3);
202  coeff[idx(1, 0, 0, 1, 1, 0)] += -cos_phi*pow(sin_phi, 3)*z_0/pow(var_bd, 2);
203  coeff[idx(1, 0, 0, 1, 1, 1)] += 2*pow(cos_phi, 3)*pow(sin_phi, 3)*z_0/pow(var_bd, 3);
204  coeff[idx(1, 0, 0, 1, 2, 0)] += cos_phi*pow(sin_phi, 5)*z_0/pow(var_bd, 3);
205  coeff[idx(1, 0, 1, 0, 0, 0)] += -pow(sin_phi, 2)*z_0/var_bd;
206  coeff[idx(1, 0, 1, 0, 0, 1)] += pow(cos_phi, 2)*pow(sin_phi, 2)*z_0/pow(var_bd, 2);
207  coeff[idx(1, 0, 1, 0, 0, 2)] += -pow(cos_phi, 4)*pow(sin_phi, 2)*z_0/pow(var_bd, 3);
208  coeff[idx(1, 0, 1, 0, 1, 0)] += pow(sin_phi, 4)*z_0/pow(var_bd, 2);
209  coeff[idx(1, 0, 1, 0, 1, 1)] += -2*pow(cos_phi, 2)*pow(sin_phi, 4)*z_0/pow(var_bd, 3);
210  coeff[idx(1, 0, 1, 0, 2, 0)] += -pow(sin_phi, 6)*z_0/pow(var_bd, 3);
211  coeff[idx(1, 1, 0, 0, 0, 0)] += cos_phi*sin_phi/var_bd;
212  coeff[idx(1, 1, 0, 0, 0, 1)] += -pow(cos_phi, 3)*sin_phi/pow(var_bd, 2);
213  coeff[idx(1, 1, 0, 0, 0, 2)] += pow(cos_phi, 5)*sin_phi/pow(var_bd, 3);
214  coeff[idx(1, 1, 0, 0, 1, 0)] += -cos_phi*pow(sin_phi, 3)/pow(var_bd, 2);
215  coeff[idx(1, 1, 0, 0, 1, 1)] += 2*pow(cos_phi, 3)*pow(sin_phi, 3)/pow(var_bd, 3);
216  coeff[idx(1, 1, 0, 0, 2, 0)] += cos_phi*pow(sin_phi, 5)/pow(var_bd, 3);
217  coeff[idx(2, 0, 0, 0, 0, 0)] += -pow(sin_phi, 2)/(2*var_bd);
218  coeff[idx(2, 0, 0, 0, 0, 1)] += pow(cos_phi, 2)*pow(sin_phi, 2)/(2*pow(var_bd, 2));
219  coeff[idx(2, 0, 0, 0, 0, 2)] += -pow(cos_phi, 4)*pow(sin_phi, 2)/(2*pow(var_bd, 3));
220  coeff[idx(2, 0, 0, 0, 1, 0)] += pow(sin_phi, 4)/(2*pow(var_bd, 2));
221  coeff[idx(2, 0, 0, 0, 1, 1)] += -pow(cos_phi, 2)*pow(sin_phi, 4)/pow(var_bd, 3);
222  coeff[idx(2, 0, 0, 0, 2, 0)] += -pow(sin_phi, 6)/(2*pow(var_bd, 3));
223  coeff[idx(0, 0, 0, 0, 0, 0)+90] += -log(var_bd)/2;
224  coeff[idx(0, 0, 0, 0, 0, 1)+90] += -pow(cos_phi, 2)/(2*var_bd);
225  coeff[idx(0, 0, 0, 0, 0, 2)+90] += pow(cos_phi, 4)/(4*pow(var_bd, 2));
226  coeff[idx(0, 0, 0, 0, 1, 0)+90] += -pow(sin_phi, 2)/(2*var_bd);
227  coeff[idx(0, 0, 0, 0, 1, 1)+90] += pow(cos_phi, 2)*pow(sin_phi, 2)/(2*pow(var_bd, 2));
228  coeff[idx(0, 0, 0, 0, 2, 0)+90] += pow(sin_phi, 4)/(4*pow(var_bd, 2));
229 }
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
T2TrackBSLLPoly.h
PESA::T2TrackBSLLPoly::update
void update(double z0, double d0, double phi0, double d0_var, std::vector< double > &coeff)
Update polynomial coefficients with track data.
Definition: T2TrackBSLLPoly.cxx:112
PESA
Local tools.
Definition: T2BeamSpot.cxx:13
PESA::T2TrackBSLLPoly::idx
static int idx(unsigned power_Bx, unsigned power_By, unsigned power_tx, unsigned power_ty, unsigned power_omegax, unsigned power_omegay)
Return bin number (0-based) for a monomial coefficient given the powers of the variables in a monomia...
Definition: T2TrackBSLLPoly.cxx:92
PESA::T2TrackBSLLPoly::nbins
static unsigned nbins()
Return number of bins in the histogram for all plynomial coefficients (and few other numbers).
Definition: T2TrackBSLLPoly.cxx:79
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
PESA::T2TrackBSLLPoly::m_beam_size
double m_beam_size
Definition: T2TrackBSLLPoly.h:88