45 {
46
48 if (err) return err;
49
50
52 _n = links.length();
53 if (_n < 3) return 0;
54
55
59 double chisq = 0.;
60 for (unsigned i = 0; i < _n; i++) {
62 double tmp = p.y() - (_a * p.x() + _b);
63 chisq += tmp * tmp;
64 }
65 double siga = sqrt(chisq / _det);
66
67
68 double a1 = _a;
69 double f1 = rofunc(
t, a1);
70 double a2 = _a + copysign(3.0 * siga,
f1);
71 double f2 = rofunc(
t, a2);
72
73
74 if(
f1 * f2 > 0. && fabs(f2) > fabs(
f1) ){
75 a2 = _a - copysign(3.0 * siga,
f1);
77 }
78
79 int backwardSearch=0;
80 while (
f1 * f2 > 0. ) {
81 _a = 2.0 * a2 - a1;
82 a1 = a2;
84 a2 = _a;
86
87 if(
f1 * f2 > 0. && ( fabs(f2) > fabs(
f1) || fabs(f2-
f1)<0.01 ) ){
88 backwardSearch++;
89 if(backwardSearch==2){
90 break;
91 }
92
94 a2 = a1;
96 a1 = _a;
98 }
99 }
100
101 if(backwardSearch==2){
102
103
104
105 double siga1 = 0.01 * siga;
106 double a21(fabs(a2-a1));
107 while (a21 > siga1) {
108 _a = 0.5 * (a1 + a2);
109 if (_a == a1 || _a == a2) break;
110 double f = rofunc(
t, _a);
111
114 a1=_a;
115 backwardSearch--;
116 break;
117 }
118
119 if ( fabs(
f) <= fabs(
f1) && fabs(
f) <= fabs(f2)) {
120 if( fabs(
f-
f1) > fabs(
f-f2) ){
122 a1 = _a;
123 }else{
125 a2 = _a;
126 }
127 }
else if( fabs(
f) <= fabs(
f1) ){
129 a1 = _a;
130 }
else if ( fabs(
f) <= fabs(f2) ){
132 a2 = _a;
133 }else{
134 if( fabs(f2) > fabs(
f1) ){
136 a1 = _a;
137 }else{
139 a2 = _a;
140 }
141 }
142 if (fabs(a2-a1) >= a21) break;
143 a21 = fabs(a2-a1);
144 }
145 }
146
147 if(backwardSearch<=1){
148
149
150 siga = 0.01 * siga;
151
152 double a21(fabs(a2-a1));
153 while (a21 > siga) {
154 _a = 0.5 * (a1 + a2);
155 if (_a == a1 || _a == a2) break;
156 double f = rofunc(
t, _a);
159 a1 = _a;
160 }
161 else {
163 a2 = _a;
164 }
165 if (fabs(a2-a1) >= a21) break;
166 a21 = fabs(a2-a1);
167 }
168 }
169
170 _det = _det / double(_n);
171
172 if (
t.objectType() ==
Line)
173 ((
TMLine &)
t).property(_a, _b, _det);
175 return 0;
176}
virtual int fit(TTrackBase &) const
void fitDone(TTrackBase &) const
sets the fitted flag. (Bad implementation)
A class to represent a track in tracking.
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")