15# if defined(__EXTENSIONS__)
18# define __EXTENSIONS__
22#elif defined(__GNUC__)
23# if defined(_XOPEN_SOURCE)
60 for (
unsigned i = 0; i < _n; i++) {
62 double tmp = p.y() - (_a * p.x() + _b);
65 double siga = sqrt(chisq / _det);
69 double f1 = rofunc(
t, a1);
70 double a2 = _a + copysign(3.0 * siga,
f1);
71 double f2 = rofunc(
t, a2);
74 if(
f1 * f2 > 0. && fabs(f2) > fabs(
f1) ){
75 a2 = _a - copysign(3.0 * siga,
f1);
80 while (
f1 * f2 > 0. ) {
87 if(
f1 * f2 > 0. && ( fabs(f2) > fabs(
f1) || fabs(f2-
f1)<0.01 ) ){
89 if(backwardSearch==2){
101 if(backwardSearch==2){
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);
119 if ( fabs(
f) <= fabs(
f1) && fabs(
f) <= fabs(f2)) {
120 if( fabs(
f-
f1) > fabs(
f-f2) ){
127 }
else if( fabs(
f) <= fabs(
f1) ){
130 }
else if ( fabs(
f) <= fabs(f2) ){
134 if( fabs(f2) > fabs(
f1) ){
142 if (fabs(a2-a1) >= a21)
break;
147 if(backwardSearch<=1){
152 double a21(fabs(a2-a1));
154 _a = 0.5 * (a1 + a2);
155 if (_a == a1 || _a == a2)
break;
156 double f = rofunc(
t, _a);
165 if (fabs(a2-a1) >= a21)
break;
170 _det = _det / double(_n);
172 if (
t.objectType() ==
Line)
173 ((
TMLine &)
t).property(_a, _b, _det);
179TRobustLineFitter::rofunc(
const TTrackBase &
t,
double a)
const {
180 double * arr = (
double *) malloc(_n *
sizeof(
double));
181 for (
unsigned i = 0; i < _n; i++)
182 arr[i] =
t.links()[i]->position().y()
183 -
a *
t.links()[i]->position().x();
185 _b = select((_n + 1) >> 1, _n, arr);
188 unsigned j = _n >> 1;
189 _b = 0.5 * (select(j, _n, arr) + select(j + 1, _n, arr));
194 for (
unsigned i = 0; i < _n; i++) {
195 double x =
t.links()[i]->position().x();
196 double y =
t.links()[i]->position().y();
197 double d =
y - (
a *
x + _b);
199 if (
y != 0.) d /= fabs(
y);
200 if (fabs(d) > 1.0e-7) sum += d > 0.0 ?
x : -
x;
206#define SWAP(a,b) tmp=(a);(a)=(b);(b)=tmp;
209TRobustLineFitter::select(
unsigned k,
unsigned n,
double * arr)
const {
216 if (ir == l + 1 && arr[ir] < arr[l]) {
217 SWAP(arr[l],arr[ir]);
227 unsigned mid = (l + ir) >> 1;
228 SWAP(arr[mid],arr[l+1]);
229 if (arr[l + 1] > arr[ir]) {
230 SWAP(arr[l+1],arr[ir]);
232 if (arr[l] > arr[ir]) {
233 SWAP(arr[l],arr[ir]);
235 if (arr[l + 1] > arr[l]) {
236 SWAP(arr[l+1],arr[l]);
246 while (arr[++i] <
a);
247 while (arr[--j] >
a);
253 if (j >= k) ir = j - 1;
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
A class to fit a TTrackBase object to a line.
virtual int fit(TTrackBase &) const
void fitDone(TTrackBase &) const
sets the fitted flag. (Bad implementation)
A class to represent a track in tracking.
TRobustLineFitter(const std::string &name)
Constructor.
virtual int fit(TTrackBase &) const
virtual ~TRobustLineFitter()
Destructor.
A virtual class for a track class in tracking.