28#include "AIDA/IHistogram1D.h"
29#include "AIDA/IHistogram2D.h"
37void MdcxFittedHel::basics()
40 bailout=1; chidofbail=1200.0; niter=10;
89 bailout=1; chidofbail=1200.0; niter=10;
108 bailout=1; chidofbail=1200.0; niter=10;
109 int kkk=0;
while (ListOAdds[kkk]){ListOAdds[kkk]->SetUsedOnHel(0); kkk++;}
113 kkk=0;
while (ListOAdds[kkk]){
115 spull = ListOAdds[kkk]->pull(*temp)/
sfac;
116 chisq += spull*spull;
134 return xHitList[i]->residual(*
this);
143 if(
prob < Probmin)
return 1303;
165 if(6 ==
debug) std::cout<<
"IterateFit niter="<<niter<< std::endl;
167 float prevchisq = 0.0;
168 for (
int i = 0; i < niter; i++) {
173 cout <<
" iteration number= " << i <<
" chisq= " <<
chisq;
174 cout <<
" nhits= " <<
nhits <<
" " <<
" fail= " << ftemp << endl;
178 if (ftemp != 0)
break;
179 if(6 ==
debug)std::cout<<
"in MdcxFittedHel::IterateFit() chisq="<<
chisq<<
" prechi2="<<prevchisq<<std::endl;
184 float prevchisq = 0.0;
187 while ((fabs(
chisq-prevchisq) > 0.01) && (
iter++ < 1000)) {
190 if (ftemp != 0)
break;
203 double m_2pi = 2.0 *
M_PI;
207 std::cout <<
"in MdcxFittedHel::DoFit() nfree = " <<
nfree
208 <<
" nhits = " <<
nhits << std::endl;
212 double A[10][10] = {{0.}}, B[10] = {0.}, D[10] = {0.}, det;
216 std::cout <<
"xHitList.length " <<
xHitList.length() <<
" ";
217 for (
int ii = 0; ii <
xHitList.length(); ii++) {
220 std::cout << std::endl <<
"sfac = " <<
sfac << std::endl;
223 for (
int i = 0; i <
nhits; i++) {
224 std::vector<float> derivs =
xHitList[i]->derivatives(*
this);
226 cout <<
"derivs " << i<<
" ";
227 for (
unsigned int ii = 0; ii < derivs.size(); ii++) {
228 cout << setw(15)<< derivs[ii];
230 std::cout << std::endl;
233 for(
unsigned int ipar = 0; ipar < derivs.size(); ipar++) {
234 derivs[ipar] /=
sfac;
235 if(6 ==
debug) cout <<
" derivs[" << ipar <<
"] = " << derivs[ipar];
237 if(6 ==
debug) std::cout << std::endl;
239 chisq += derivs[0] * derivs[0];
241 for (
int ipar = 0; ipar < norder; ipar++) {
242 D[ipar] += derivs[0] * derivs[ipar+1];
244 for(
int jpar = 0; jpar < norder; jpar++) {
245 A[ipar][jpar] += derivs[ipar+1] * derivs[jpar+1];
249 if (6 ==
debug) cout <<
"chisq = " <<
chisq << endl;
255 for (
int ii = 0; ii < norder; ii++) {
256 cout <<
"D["<< ii <<
"]: " << D[ii] <<
" A:";
257 for (
int jj = 0; jj < norder; jj++) cout <<
" " << A[ii][jj];
268 cout <<
"chisq " <<
chisq <<
" ndof " << ndof
269 <<
" chiperdof " <<
chisq/ndof
270 <<
" >?chidofbail " << chidofbail << endl;
272 float chiperdof =
chisq/ndof;
273 if(chiperdof > chidofbail)
return ftemp;
276 cout <<
" ndof <=0 : chisq " <<
chisq
277 <<
" >? chidofbail/2.5 " << chidofbail/2.5 << endl;
279 if (
chisq > chidofbail/2.5)
return ftemp;
284 if (6 ==
debug) cout <<
"ierr = " << ierr << endl;
286 for(
int ii = 0; ii < norder; ii++)
287 for(
int jj = 0; jj < norder; jj++)
288 B[ii] += A[ii][jj] * D[jj];
290 for (
int ii = 0; ii < norder; ii++) {
291 cout <<
"B[" << ii <<
"]: " << B[ii] <<
" A:";
292 for (
int jj = 0; jj < norder; jj++) cout <<
" " << A[ii][jj];
297 if (
qd0)
d0 -= B[++bump];
308 if (
qz0)
z0 -= B[++bump];
310 if (
qt0)
t0 -= B[++bump];
315 if ( fabs(
omega) > 10.0 ) ftemp = 1306;
323int MdcxFittedHel::OriginIncluded() {
336 cout <<
" d0 " <<
d0;
337 cout <<
" phi0 " <<
phi0;
338 cout <<
" omega " <<
omega;
339 cout <<
" z0 " <<
z0;
340 cout <<
" tanl " <<
tanl << endl;
341 cout <<
" fail " <<
fail;
342 cout <<
" chisq " <<
chisq;
343 cout <<
" iter to fit " <<
itofit;
344 cout <<
" sfac " <<
sfac;
345 cout <<
" rcs " <<
rcs;
346 cout <<
" prob " <<
prob;
347 cout <<
" fittime " <<
fittime << endl;
348 cout <<
" nhits= " <<
nhits <<
" xHitList.length " <<
xHitList.length() << endl;
349 for (
int ii = 0; ii <
xHitList.length(); ii++) {
358 double m_2pi=2.0*
M_PI;
360 if (difphi0>
M_PI)difphi0-=m_2pi;
if (difphi0<-
M_PI)difphi0+=m_2pi;
361 cout <<
" difphi0= " << difphi0 << endl;
362 cout <<
" difomega= " <<
omega-hel.
Omega() << endl;
363 cout <<
" difz0= " <<
z0-hel.
Z0() << endl;
364 cout <<
" diftanl= " <<
tanl-hel.
Tanl() << endl;
367 o <<
"rcs " <<
rcs <<
" prob " <<
prob <<endl;
373 if(hitno >=
nhits)
return 0;
379 if(hitno >=
nhits) {
return 0; }
380 if(hitno < 0) {
return 0; }
381 return xHitList[hitno]->SuperLayer();
double sin(const BesAngle a)
double cos(const BesAngle a)
int Mdcxmatinv(double *array, int *norder, double *det)
float Mdcxprobab(int &ndof, float &chisq)
int Layer(int hitno=0) const
HepAList< MdcxHit > xHitList
const HepAList< MdcxHit > & XHitList() const
int SuperLayer(int hitno=0) const
MdcxFittedHel & operator=(const MdcxHel &)
int Fail(float Probmin=0.0) const
MdcxFittedHel & Grow(const MdcxFittedHel &, const HepAList< MdcxHit > &)
void copy(const MdcxHel &hel)
static const double maxMdcRadius
MDC Geometry.