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);
54 double Zc(0), Yc(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
94 log << MSG::DEBUG <<
"Yc " << Yc <<
" Zc " << Zc <<
endmsg;
95 }
96
97
98
99 Sy = 0;
100 Sz = 0;
101 double Szz(0), Syy(0), Szy(0), Syyzz(0);
102 std::vector<double> rw(N);
103 std::vector<double> ryw(N);
104 std::vector<double> rzw(N);
105
106 for (
int i = 0;
i <
N; ++
i) {
109
111
113 ryw[
i] = rw[
i] *
y[
i];
114 rzw[
i] = rw[
i] *
z[
i];
115
116 Szz +=
z[
i] *
z[
i] *
w[
i];
117 Syy +=
y[
i] *
y[
i] *
w[
i];
118 Szy +=
y[
i] *
z[
i] *
w[
i];
119 Syyzz += (
y[
i] -
z[
i]) * (
y[i] +
z[i]) *
w[
i];
120 }
121
124 log << MSG::DEBUG <<
" Szz " << Szz <<
" Syy " << Syy <<
" Szy " << Szy <<
" Syyzz " << Syyzz <<
endmsg;
125 }
126
128 double R(0), Ry(0), Rz(0);
129 double Att(0);
131 double Bt(0);
132 double Bd(0);
133 double Stt(0);
134 double Sd(0);
135
136 double cosin =
getZ(dir) /
dir.mag();
137 double sinus =
getY(dir) /
dir.mag();
138
141 log << MSG::DEBUG <<
"cos " << cosin <<
" sin " << sinus <<
endmsg;
142 }
143
144
145 if (sinus < 0.0) {
148 log << MSG::DEBUG <<
"sinus=" << sinus <<
endmsg;
149 }
150 sinus = -sinus;
151 cosin = -cosin;
152 } else if (sinus == 0.0 && cosin < 0.0) {
155 log << MSG::DEBUG <<
"sinus == 0.0 && cosin < 0.0" <<
endmsg;
156 }
157 cosin = -cosin;
158 }
159
160
161
162 double d = -(
getZ(pos) - Zc) * sinus + (
getY(pos) - Yc) * cosin;
163 double theta = std::acos(cosin);
166 log << MSG::DEBUG <<
"____________INITIAL VALUES________________" <<
count <<
endmsg;
168 }
169
170 while (
count < 100) {
173 log << MSG::DEBUG <<
"____________NEW ITERATION________________" <<
count <<
endmsg;
174 }
176 Ry = 0;
177 Rz = 0;
178 for (
int i = 0;
i <
N; ++
i) {
180
181 double dist =
y[
i] * cosin -
z[
i] * sinus;
182 if (dist > d) {
188 log << MSG::DEBUG <<
" < - > " << dist -
d <<
" r " <<
r[
i] <<
endmsg;
189 }
190 } else {
196 log << MSG::DEBUG <<
" < + > " << dist -
d <<
" r " <<
r[
i] <<
endmsg;
197 }
198 }
199 }
200 Att = Syy + cosin * (2 * sinus * Szy - cosin * Syyzz);
201 Bt = -Szy + cosin * (sinus * Syyzz + 2 * cosin * Szy + Rz) + sinus * Ry;
203 if (Att == 0) {
205 log << MSG::WARNING <<
"NewtonSLDCFitter ZERO Determinant" <<
endmsg;
206 return false;
207 }
211 cosin = std::cos(
theta);
212 sinus = std::sqrt(1 - cosin * cosin);
216 log << MSG::DEBUG <<
"R " <<
R <<
" Ry " << Ry <<
" Rz " << Rz <<
endmsg;
217 log << MSG::DEBUG <<
"Att " << Att <<
" Add " << Add <<
" Bt " << Bt <<
" Bd " << Bd <<
endmsg;
218 log << MSG::DEBUG <<
"dTheta " << Bt / Att <<
" dD " << Bd / Add <<
endmsg;
219 }
220 if (std::abs(Bt / Att) < 0.001 && std::abs(Bd / Add) < 0.001) {
221 Stt = std::sqrt(1 / Att);
222 Sd = std::sqrt(1 / Add);
223
226 log << MSG::DEBUG <<
"Fit converged after " <<
count <<
" iterations " <<
endmsg;
228 log << MSG::DEBUG <<
"Errors: theta " << Stt <<
" d " << Sd <<
endmsg;
229 }
230
231 seg.setErrors(Sd, Stt);
232
233 break;
234 }
236 }
239 log << MSG::DEBUG <<
"Calculating chi2" <<
endmsg;
240 }
241
242 std::vector<double> yl(N);
243 std::vector<double> dyl(N);
244 std::vector<double>
res(N);
248 log << MSG::DEBUG <<
"contributions to chi2: " <<
endmsg;
249 }
250
251
252 for (
int i = 0;
i <
N; ++
i) {
253 yl[
i] = cosin *
y[
i] - sinus *
z[
i] -
d;
254 double dth = -(sinus *
y[
i] + cosin *
z[
i]) * Stt;
255 dyl[
i] = std::hypot(dth, Sd);
256 res[
i] = std::abs(yl[i]) -
r[
i];
259 log << MSG::DEBUG <<
" r_track " << yl[
i] <<
" dr " << dyl[
i] <<
" r_rt " <<
r[
i] <<
" res " <<
res[
i] <<
" pull "
261 }
262
264
266 }
267
270 log << MSG::DEBUG <<
"Fit complete: Chi2 tof " <<
chi2 / (
N - 2) <<
" " << !(
chi2 / (N - 2) > 5) <<
endmsg;
271 }
272 if (
chi2 / (N - 2) > 5) {
275 log << MSG::DEBUG <<
"_______NOT GOOD " <<
endmsg;
276 }
277 }
278
281 log << MSG::DEBUG <<
"Transforming back to real world" <<
endmsg;
282 }
283
286
289 log << MSG::DEBUG <<
"New line: position " << npos <<
" direction " << ndir <<
endmsg;
290 }
291
292 seg.set(
chi2 / (N - 2), npos, ndir);
293
296 mdt_hit->setDistanceToTrack(yl[i], dyl[i]);
298 }
299
302 log << MSG::DEBUG <<
"fit done" <<
endmsg;
303 }
304
305 return (std::isfinite(ndir.y()) && std::isfinite(ndir.z()) && std::isfinite(npos.y()) && std::isfinite(npos.z()));
306 }
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)