fit subset of the hits.
25 {
28 log << MSG::DEBUG <<
"New seg: " <<
endmsg;
29 }
30
31 int N = seg.mdtHitsOnTrack();
32
33 if (N < 2) { return false; }
34
38 } else {
39 int used(0);
40 for (
int i = 0;
i <
N; ++
i) {
42 }
43 if (used < 2) {
45 log << MSG::WARNING <<
"TO FEW HITS SELECTED" <<
endmsg;
46 return false;
47 }
48 }
49
52
53 double S(0), Sz(0), Sy(0);
55
56 std::vector<double>
y(N),
z(N),
r(N),
w(N);
57 {
58 int ii(0);
60 const MdtCalibHitBase&
h = *hit_ptr;
61
62 y[ii] =
getY(
h.localPosition());
63 z[ii] =
getZ(
h.localPosition());
64 r[ii] = std::abs(
h.driftRadius());
65 if (
h.sigma2DriftRadius() > 0)
66 w[ii] = 1. / (
h.sigma2DriftRadius());
67 else
72 log << MSG::WARNING <<
"<Negative r> " <<
r[ii] <<
endmsg;
73 }
76 log << MSG::DEBUG <<
"DC: (" <<
y[ii] <<
"," <<
z[ii] <<
") R = " <<
r[ii] <<
" W " <<
w[ii] <<
endmsg;
77 }
78
80 ++ii;
81 continue;
82 }
86 ++ii;
87 }
88 }
91 log << MSG::ERROR <<
"Divisor is zero" <<
endmsg;
92 return false;
93 }
96
99 log << MSG::DEBUG <<
"Yc " << Yc <<
" Zc " <<
Zc <<
endmsg;
100 }
101
102
103
104 Sy = 0;
105 Sz = 0;
106 double Szz(0), Syy(0), Szy(0), Syyzz(0);
107 std::vector<double> rw(N);
108 std::vector<double> ryw(N);
109 std::vector<double> rzw(N);
110
111 for (
int i = 0;
i <
N; ++
i) {
114
116
118 ryw[
i] = rw[
i] *
y[
i];
119 rzw[
i] = rw[
i] *
z[
i];
120
121 Szz +=
z[
i] *
z[
i] *
w[
i];
122 Syy +=
y[
i] *
y[
i] *
w[
i];
123 Szy +=
y[
i] *
z[
i] *
w[
i];
124 Syyzz += (
y[
i] -
z[
i]) * (
y[i] +
z[i]) *
w[
i];
125 }
126
129 log << MSG::DEBUG <<
" Szz " << Szz <<
" Syy " << Syy <<
" Szy " << Szy <<
" Syyzz " << Syyzz <<
endmsg;
130 }
131
133 double R(0), Ry(0), Rz(0);
134 double Att(0);
136 double Bt(0);
137 double Bd(0);
138 double Stt(0);
139 double Sd(0);
140
141 double cosin =
getZ(dir) /
dir.mag();
142 double sinus =
getY(dir) /
dir.mag();
143
146 log << MSG::DEBUG <<
"cos " << cosin <<
" sin " << sinus <<
endmsg;
147 }
148
149
150 if (sinus < 0.0) {
153 log << MSG::DEBUG <<
"sinus=" << sinus <<
endmsg;
154 }
155 sinus = -sinus;
156 cosin = -cosin;
157 } else if (sinus == 0.0 && cosin < 0.0) {
160 log << MSG::DEBUG <<
"sinus == 0.0 && cosin < 0.0" <<
endmsg;
161 }
162 cosin = -cosin;
163 }
164
165
166
167 double d = -(
getZ(pos) -
Zc) * sinus + (
getY(pos) - Yc) * cosin;
168 double theta = std::acos(cosin);
171 log << MSG::DEBUG <<
"____________INITIAL VALUES________________" <<
count <<
endmsg;
173 }
174
175 while (
count < 100) {
178 log << MSG::DEBUG <<
"____________NEW ITERATION________________" <<
count <<
endmsg;
179 }
181 Ry = 0;
182 Rz = 0;
183 for (
int i = 0;
i <
N; ++
i) {
185
186 double dist =
y[
i] * cosin -
z[
i] * sinus;
187 if (dist > d) {
193 log << MSG::DEBUG <<
" < - > " << dist -
d <<
" r " <<
r[
i] <<
endmsg;
194 }
195 } else {
201 log << MSG::DEBUG <<
" < + > " << dist -
d <<
" r " <<
r[
i] <<
endmsg;
202 }
203 }
204 }
205 Att = Syy + cosin * (2 * sinus * Szy - cosin * Syyzz);
206 Bt = -Szy + cosin * (sinus * Syyzz + 2 * cosin * Szy + Rz) + sinus * Ry;
208 if (Att == 0) {
210 log << MSG::WARNING <<
"NewtonSLDCFitter ZERO Determinant" <<
endmsg;
211 return false;
212 }
216 cosin = std::cos(
theta);
217 sinus = std::sqrt(1 - cosin * cosin);
221 log << MSG::DEBUG <<
"R " <<
R <<
" Ry " << Ry <<
" Rz " << Rz <<
endmsg;
222 log << MSG::DEBUG <<
"Att " << Att <<
" Add " << Add <<
" Bt " << Bt <<
" Bd " << Bd <<
endmsg;
223 log << MSG::DEBUG <<
"dTheta " << Bt / Att <<
" dD " << Bd / Add <<
endmsg;
224 }
225 if (std::abs(Bt / Att) < 0.001 && std::abs(Bd / Add) < 0.001) {
226 Stt = std::sqrt(1 / Att);
227 Sd = std::sqrt(1 / Add);
228
231 log << MSG::DEBUG <<
"Fit converged after " <<
count <<
" iterations " <<
endmsg;
233 log << MSG::DEBUG <<
"Errors: theta " << Stt <<
" d " << Sd <<
endmsg;
234 }
235
236 seg.setErrors(Sd, Stt);
237
238 break;
239 }
241 }
244 log << MSG::DEBUG <<
"Calculating chi2" <<
endmsg;
245 }
246
247 std::vector<double> yl(N);
248 std::vector<double> dyl(N);
249 std::vector<double>
res(N);
253 log << MSG::DEBUG <<
"contributions to chi2: " <<
endmsg;
254 }
255
256
257 for (
int i = 0;
i <
N; ++
i) {
258 yl[
i] = cosin *
y[
i] - sinus *
z[
i] -
d;
259 double dth = -(sinus *
y[
i] + cosin *
z[
i]) * Stt;
260 dyl[
i] = std::hypot(dth, Sd);
261 res[
i] = std::abs(yl[i]) -
r[
i];
264 log << MSG::DEBUG <<
" r_track " << yl[
i] <<
" dr " << dyl[
i] <<
" r_rt " <<
r[
i] <<
" res " <<
res[
i] <<
" pull "
266 }
267
269
271 }
272
275 log << MSG::DEBUG <<
"Fit complete: Chi2 tof " <<
chi2 / (
N - 2) <<
" " << !(
chi2 / (N - 2) > 5) <<
endmsg;
276 }
277 if (
chi2 / (N - 2) > 5) {
280 log << MSG::DEBUG <<
"_______NOT GOOD " <<
endmsg;
281 }
282 }
283
286 log << MSG::DEBUG <<
"Transforming back to real world" <<
endmsg;
287 }
288
291
294 log << MSG::DEBUG <<
"New line: position " << npos <<
" direction " << ndir <<
endmsg;
295 }
296
297 seg.set(
chi2 / (N - 2), npos, ndir);
298
301 mdt_hit->setDistanceToTrack(yl[i], dyl[i]);
303 }
304
307 log << MSG::DEBUG <<
"fit done" <<
endmsg;
308 }
309
310 return (std::isfinite(ndir.y()) && std::isfinite(ndir.z()) && std::isfinite(npos.y()) && std::isfinite(npos.z()));
311 }
Scalar theta() const
theta method
std::pair< std::vector< unsigned int >, bool > res
double getY(const Amg::Vector3D &p) const
double getZ(const Amg::Vector3D &p) const
Amg::Vector3D getVec(double x, double y, double z) const
std::shared_ptr< MdtCalibHitBase > MdtHitPtr
typedef for a collection of MdtCalibHitBase s
double chi2(TH1 *h0, TH1 *h1)
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
Eigen::Matrix< double, 3, 1 > Vector3D
double R(const INavigable4Momentum *p1, const double v_eta, const double v_phi)
IMessageSvc * getMessageSvc(bool quiet=false)
@ Zc
Z -> cc, nC = 1 (partial containment).