1 #include "StEStructAutoFit.h"
6 #include "TDecompSVD.h"
13 using namespace TMath;
16 const int numIterations=500;
19 Double_t fun1(Double_t *x, Double_t *par) {
21 Double_t v1 = par[0] * (1- Cos(x[1]))/2.;
22 Double_t v2 = par[1] * Cos(2.*x[1]);
23 Double_t geta = par[2] * Exp(-pow((x[0]/par[3]), 2)/2.);
24 Double_t d1 = Exp(-pow(x[1]/par[4], 2)/2.);
25 Double_t d2 = Exp(-pow((x[1]-2.*Pi())/par[4], 2)/2.);
26 Double_t g1 = geta*(d1+d2);
27 Double_t g2 = par[5] * Exp(-pow((x[0]/par[6]), 2)/2.);
28 Double_t eg = par[8] * Exp(-Sqrt(pow(x[0]/par[9], 2)+pow(x[1]/par[10], 2))/2.);
30 return v1+v2+g1+g2+par[7]+eg;
34 Double_t fun2(Double_t *x, Double_t *par) {
36 Double_t v1 = par[0] * (1- Cos(x[1]))/2.;
37 Double_t v2 = par[1] * Cos(2.*x[1]);
38 Double_t geta = par[2] * Exp(-pow((x[0]/par[3]), 2)/2.);
39 Double_t d1 = Exp(-pow(x[1]/par[4], 2)/2.);
40 Double_t d2 = Exp(-pow((x[1]-2.*Pi())/par[4], 2)/2.);
41 Double_t g1 = geta*(d1+d2);
42 Double_t g2 = par[5] * Exp(-pow((x[0]/par[6]), 2)/2.);
44 return v1+v2+g1+g2+par[7];
47 Double_t fun2v3(Double_t *x, Double_t *par) {
49 Double_t v1 = par[0] * (1- Cos(x[1]))/2.;
50 Double_t v2 = par[1] * Cos(2.*x[1]);
51 Double_t v3 = par[8] * Cos(3.*x[1]);
52 Double_t geta = par[2] * Exp(-pow((x[0]/par[3]), 2)/2.);
53 Double_t d1 = Exp(-pow(x[1]/par[4], 2)/2.);
54 Double_t d2 = Exp(-pow((x[1]-2.*Pi())/par[4], 2)/2.);
55 Double_t g1 = geta*(d1+d2);
56 Double_t g2 = par[5] * Exp(-pow((x[0]/par[6]), 2)/2.);
58 return v1+v2+g1+g2+par[7]+v3;
60 Double_t fun3(Double_t *x, Double_t *par) {
62 Double_t v1 = par[0] * (1- Cos(x[1]))/2.;
63 Double_t v2 = par[1] * Cos(2.*x[1]);
64 Double_t geta = par[2] * Exp(-pow((x[0]/par[3]), 2)/2.);
65 Double_t d1 = Exp(-pow(x[1]/par[4], 2)/2.);
66 Double_t d2 = Exp(-pow((x[1]-2.*Pi())/par[4], 2)/2.);
67 Double_t g1 = geta*(d1+d2);
68 Double_t g2a = par[5] * Exp(-pow((x[0]/par[6]), 2)/2.);
69 Double_t g2b = par[7] * Exp(-pow((x[0]/par[8]), 2)/2.);
71 return v1+v2+g1+g2a+g2b+par[9];
73 Double_t fun4(Double_t *x, Double_t *par) {
75 Double_t v1 = par[0] * (1- Cos(x[1]))/2.;
76 Double_t v2 = par[1] * Cos(2.*x[1]);
77 Double_t geta = par[2] * Exp(-pow((x[0]/par[3]), 2)/2.);
78 Double_t d1 = Exp(-pow(x[1]/par[4], 2)/2.);
79 Double_t d2 = Exp(-pow((x[1]-2.*Pi())/par[4], 2)/2.);
80 Double_t g1 = geta*(d1+d2);
81 Double_t g2 = par[5] * Exp(-pow((x[0]/par[6]), 10)/10.);
83 return v1+v2+g1+g2+par[7];
87 Double_t fun5(Double_t *x, Double_t *par) {
88 Double_t v1 = par[0] * (Exp(-pow((x[1]-Pi())/par[8], 2)/2.)+Exp(-pow((x[1]+Pi())/par[8], 2)/2.));
89 Double_t v2 = par[1] * Cos(2.*x[1]);
90 Double_t geta = par[2] * Exp(-pow((x[0]/par[3]), 2)/2.);
91 Double_t d1 = Exp(-pow(x[1]/par[4], 2)/2.);
92 Double_t d2 = Exp(-pow((x[1]-2.*Pi())/par[4], 2)/2.);
93 Double_t g1 = geta*(d1+d2);
94 Double_t g2 = par[5] * Exp(-pow((x[0]/par[6]), 2)/2.);
96 return v1+v2+g1+g2+par[7];
100 Double_t fun6(Double_t *x, Double_t *par) {
101 Double_t v1 = par[0] * (Exp(-pow((x[1]-Pi())/par[8], 2)/2.)+Exp(-pow((x[1]+Pi())/par[8], 2)/2.));
102 Double_t v2 = par[1] * Cos(2.*x[1]);
103 Double_t geta = par[2] * Exp(-pow((x[0]/par[3]), 2)/2.);
104 Double_t d1 = Exp(-pow(x[1]/par[4], 2)/2.);
105 Double_t d2 = Exp(-pow((x[1]-2.*Pi())/par[4], 2)/2.);
106 Double_t g1 = geta*(d1+d2);
107 Double_t g2 = par[5] * Exp(-pow((x[0]/par[6]), 2)/2.);
108 Double_t eg = par[9] * Exp(-Sqrt(pow(x[0]/par[10], 2)+pow(x[1]/par[11], 2))/2.);
110 return v1+v2+g1+g2+par[7]+eg;
113 Double_t fun7(Double_t *x, Double_t *par) {
115 Double_t v1 = par[0] * (1- Cos(x[1]))/2.;
116 Double_t v2 = par[1] * Cos(2.*x[1]);
117 Double_t geta = par[2] * Exp(-pow((x[0]/par[3]), 2)/2.);
118 Double_t d1 = Exp(-pow(x[1]/par[4], 2)/2.);
119 Double_t d2 = Exp(-pow((x[1]-2.*Pi())/par[4], 2)/2.);
120 Double_t g1 = geta*(d1+d2);
121 Double_t g2 = par[5] * Exp(-pow((x[0]/par[6]), 2)/2.);
122 Double_t getab = par[8] * Exp(-pow((x[0]/par[9]), 2)/2.);
123 Double_t d1b = Exp(-pow(x[1]/par[10], 2)/2.);
124 Double_t d2b = Exp(-pow((x[1]-2.*Pi())/par[10], 2)/2.);
125 Double_t g1b = getab*(d1b+d2b);
127 return v1+v2+g1+g2+par[7]+g1b;
131 Double_t fun8(Double_t *x, Double_t *par) {
133 Double_t v1 = par[0] * (1- Cos(x[1]))/2.;
134 Double_t v2 = par[1] * Cos(2.*x[1]);
135 Double_t v3 = par[11] * Cos(3.*x[1]);
136 Double_t geta = par[2] * Exp(-pow((x[0]/par[3]), 2)/2.);
137 Double_t d1 = Exp(-pow(x[1]/par[4], 2)/2.);
138 Double_t d2 = Exp(-pow((x[1]-2.*Pi())/par[4], 2)/2.);
139 Double_t g1 = geta*(d1+d2);
140 Double_t g2 = par[5] * Exp(-pow((x[0]/par[6]), 2)/2.);
141 Double_t eg = par[8] * Exp(-Sqrt(pow(x[0]/par[9], 2)+pow(x[1]/par[10], 2))/2.);
143 return v1+v2+g1+g2+par[7]+eg+v3;
150 double* StEStructAutoFit::autofit8Par(
double* best, TH2D* plot,
int type,
double* allchisq) {
152 plot->SetBinError(13, 7, 1000.);
153 plot->SetBinError(12, 7, 1000.);
154 plot->SetBinError(11, 7, 1000.);
155 plot->SetBinError(14, 7, 1000.);
156 plot->SetBinError(15, 7, 1000.);
157 plot->SetBinError(13, 6, 1000.);
158 plot->SetBinError(13, 8, 1000.);
160 double amprange = plot->GetMaximum() - plot->GetMinimum();
164 for(
int i=1; i<=25; i++) {
165 for(
int k=1; k<=24; k++) {
166 mean += plot->GetBinContent(i, k);
169 mean *= 1./(25.*24.);
172 for(
int i=1; i<=25; i++) {
173 for(
int k=1; k<=24; k++) {
174 rms2 += pow(plot->GetBinContent(i, k)-mean, 2);
179 rms2 *= 1./(25.*24.);
182 cout <<
"\nmean=" << mean <<
"\trms=" << rms2 << endl;
192 double maxcos=amprange;
196 double maxv2=amprange;
200 double maxg2=amprange;
202 double ming1=-2.*rms2;
205 double maxg1=2.*rms2;
210 double minoffset=mean-3.*rms2;
211 double maxoffset=mean+rms2;
218 double bestchisq=999999;
221 for(
int i=0; i<numIterations; i++) {
222 double phi = rand2.Rndm()*(maxphi-minphi)+minphi;
223 double eta = rand2.Rndm()*(maxeta-mineta)+mineta;
224 double cosv = rand2.Rndm()*(maxcos-mincos)+mincos;
225 double v2 = rand2.Rndm()*(maxv2-minv2)+minv2;
226 double g2 = rand2.Rndm()*(maxg2-ming2)+ming2;
227 double g1 = rand2.Rndm()*(maxg1-ming1)+ming1;
228 double gw = rand2.Rndm()*(maxgw-mingw)+mingw;
229 double offset = rand2.Rndm()*(maxoffset-minoffset)+minoffset;
231 cout <<
"\nphi=" << phi <<
"\teta=" << eta <<
"\tcos=" << cosv <<
"\tv2=" << v2 <<
"\tg2=" << g2 <<
"\tg1=" << g1 <<
"\tgw=" << gw <<
"\toffset=" << offset << endl;
234 const Int_t npar = 8;
236 Double_t f2params[npar] = {cosv, v2, g2, eta, phi, g1, gw, offset};
238 TF2 *f2 =
new TF2(
"f2",fun2,-2,2,-Pi()/2.,3*Pi()/2, npar);
239 f2->SetParameters(f2params);
244 f2->SetParLimits(1, 0, 5);
245 f2->SetParLimits(2, 0, 5);
246 f2->SetParLimits(3, 0.1, 5);
247 f2->SetParLimits(4, 0.1, 2);
248 if(type == 1 || type == 2)
249 f2->SetParLimits(5, 0, 3);
250 f2->SetParLimits(6, 0.12, 7);
252 int fitStatus=plot->Fit(
"f2",
"N");
253 fitStatus=plot->Fit(
"f2",
"EN");
256 double chisq=f2->GetChisquare();
257 cout <<
"\n" << f2->GetParameter(2) << endl;
259 chisqsqsum+=chisq*chisq;
260 if(chisq<bestchisq) {
261 for(
int i=0; i<npar; i++) {
262 best[i*2]=f2->GetParameter(i);
263 best[i*2+1]=f2->GetParError(i);
267 if(chisq>worstchisq) {
271 if(allchisq!=NULL) {allchisq[i]=chisq;}
273 if(allchisq!=NULL) {allchisq[i]=0.;}
278 cout <<
"\nOut of " << numIterations <<
" attempts, " << numConverge <<
" actually converged." << endl;
279 cout <<
"\nThe best chisq is: " << bestchisq << endl;
280 cout <<
"\nThe worst chisq is: " << worstchisq << endl;
301 double* StEStructAutoFit::autofit8Parv3(
double* best, TH2D* plot,
int type,
double* allchisq) {
303 plot->SetBinError(13, 7, 1000.);
304 plot->SetBinError(12, 7, 1000.);
305 plot->SetBinError(11, 7, 1000.);
306 plot->SetBinError(14, 7, 1000.);
307 plot->SetBinError(15, 7, 1000.);
308 plot->SetBinError(13, 6, 1000.);
309 plot->SetBinError(13, 8, 1000.);
311 double amprange = plot->GetMaximum() - plot->GetMinimum();
315 for(
int i=1; i<=25; i++) {
316 for(
int k=1; k<=24; k++) {
317 mean += plot->GetBinContent(i, k);
320 mean *= 1./(25.*24.);
323 for(
int i=1; i<=25; i++) {
324 for(
int k=1; k<=24; k++) {
325 rms2 += pow(plot->GetBinContent(i, k)-mean, 2);
330 rms2 *= 1./(25.*24.);
333 cout <<
"\nmean=" << mean <<
"\trms=" << rms2 << endl;
343 double maxcos=amprange;
347 double maxv2=amprange;
351 double maxv3=amprange;
355 double maxg2=amprange;
357 double ming1=-2.*rms2;
360 double maxg1=2.*rms2;
365 double minoffset=mean-3.*rms2;
366 double maxoffset=mean+rms2;
373 double bestchisq=999999;
376 for(
int i=0; i<numIterations; i++) {
377 double phi = rand2.Rndm()*(maxphi-minphi)+minphi;
378 double eta = rand2.Rndm()*(maxeta-mineta)+mineta;
379 double cosv = rand2.Rndm()*(maxcos-mincos)+mincos;
380 double v2 = rand2.Rndm()*(maxv2-minv2)+minv2;
381 double v3 = rand2.Rndm()*(maxv3-minv3)+minv3;
382 double g2 = rand2.Rndm()*(maxg2-ming2)+ming2;
383 double g1 = rand2.Rndm()*(maxg1-ming1)+ming1;
384 double gw = rand2.Rndm()*(maxgw-mingw)+mingw;
385 double offset = rand2.Rndm()*(maxoffset-minoffset)+minoffset;
387 cout <<
"\nphi=" << phi <<
"\teta=" << eta <<
"\tcos=" << cosv <<
"\tv2=" << v2 <<
"\tg2=" << g2 <<
"\tg1=" << g1 <<
"\tgw=" << gw <<
"\toffset=" << offset << endl;
390 const Int_t npar = 9;
392 Double_t f2params[npar] = {cosv, v2, g2, eta, phi, g1, gw, offset, v3};
394 TF2 *f2 =
new TF2(
"f2",fun2v3,-2,2,-Pi()/2.,3*Pi()/2, npar);
395 f2->SetParameters(f2params);
400 f2->SetParLimits(1, 0, 5);
401 f2->SetParLimits(2, 0, 5);
402 f2->SetParLimits(3, 0.1, 5);
403 f2->SetParLimits(4, 0.1, 2);
404 if(type == 1 || type == 2)
405 f2->SetParLimits(5, 0, 3);
406 f2->SetParLimits(6, 0.01, 7);
408 int fitStatus=plot->Fit(
"f2",
"N");
409 fitStatus=plot->Fit(
"f2",
"EN");
412 double chisq=f2->GetChisquare();
413 cout <<
"\n" << f2->GetParameter(2) << endl;
415 chisqsqsum+=chisq*chisq;
416 if(chisq<bestchisq) {
417 for(
int i=0; i<npar; i++) {
418 best[i*2]=f2->GetParameter(i);
419 best[i*2+1]=f2->GetParError(i);
423 if(chisq>worstchisq) {
427 if(allchisq!=NULL) {allchisq[i]=chisq;}
429 if(allchisq!=NULL) {allchisq[i]=0.;}
434 cout <<
"\nOut of " << numIterations <<
" attempts, " << numConverge <<
" actually converged." << endl;
435 cout <<
"\nThe best chisq is: " << bestchisq << endl;
436 cout <<
"\nThe worst chisq is: " << worstchisq << endl;
456 double* StEStructAutoFit::autofit11Par(
double* best, TH2D* plot,
int type,
double* allchisq) {
458 double amprange = plot->GetMaximum() - plot->GetMinimum();
462 for(
int i=1; i<=25; i++) {
463 for(
int k=1; k<=24; k++) {
464 mean += plot->GetBinContent(i, k);
467 mean *= 1./(25.*24.);
470 for(
int i=1; i<=25; i++) {
471 for(
int k=1; k<=24; k++) {
472 rms2 += pow(plot->GetBinContent(i, k)-mean, 2);
477 rms2 *= 1./(25.*24.);
480 cout <<
"\nmean=" << mean <<
"\trms=" << rms2 << endl;
490 double maxcos=amprange;
494 double maxv2=amprange;
498 double maxg2=amprange;
500 double ming1=-2.*rms2;
503 double maxg1=2.*rms2;
508 double minoffset=mean-3.*rms2;
509 double maxoffset=mean+rms2;
512 double maxexp=10.*rms2;
522 double bestchisq=999999;
525 for(
int i=0; i<numIterations; i++) {
526 double phi = rand2.Rndm()*(maxphi-minphi)+minphi;
527 double eta = rand2.Rndm()*(maxeta-mineta)+mineta;
528 double cosv = rand2.Rndm()*(maxcos-mincos)+mincos;
529 double v2 = rand2.Rndm()*(maxv2-minv2)+minv2;
530 double g2 = rand2.Rndm()*(maxg2-ming2)+ming2;
531 double g1 = rand2.Rndm()*(maxg1-ming1)+ming1;
532 double gw = rand2.Rndm()*(maxgw-mingw)+mingw;
533 double offset = rand2.Rndm()*(maxoffset-minoffset)+minoffset;
534 double exp = rand2.Rndm()*(maxexp-minexp)+minexp;
535 double expwe = rand2.Rndm()*(maxew-minew)+minew;
536 double expwp = rand2.Rndm()*(maxew-minew)+minew;
538 cout <<
"\nphi=" << phi <<
"\teta=" << eta <<
"\tcos=" << cosv <<
"\tv2=" << v2 <<
"\tg2=" << g2 <<
"\tg1=" << g1 <<
"\tgw=" << gw <<
"\toffset=" << offset << endl;
541 const Int_t npar = 11;
543 Double_t f2params[npar] = {cosv, v2, g2, eta, phi, g1, gw, offset, exp, expwe, expwp};
545 TF2 *f2 =
new TF2(
"f2",fun1,-2,2,-Pi()/2.,3*Pi()/2, npar);
546 f2->SetParameters(f2params);
551 f2->SetParLimits(1, 0, 5);
552 f2->SetParLimits(2, 0, 5);
553 f2->SetParLimits(3, 0.1, 5);
554 f2->SetParLimits(4, 0.1, 1.2);
555 if(type == 1 || type == 2)
556 f2->SetParLimits(5, 0, 3);
557 f2->SetParLimits(6, 0.01, 7);
558 f2->SetParLimits(8, 0., 5);
559 f2->SetParLimits(9, 0.005, .9);
560 f2->SetParLimits(10, 0.005, .9);
562 int fitStatus=plot->Fit(
"f2",
"N");
563 fitStatus=plot->Fit(
"f2",
"EN");
566 double chisq=f2->GetChisquare();
567 cout <<
"\n" << f2->GetParameter(2) << endl;
569 chisqsqsum+=chisq*chisq;
570 if(chisq<bestchisq) {
571 for(
int i=0; i<npar; i++) {
572 best[i*2]=f2->GetParameter(i);
573 best[i*2+1]=f2->GetParError(i);
577 if(chisq>worstchisq) {
581 if(allchisq!=NULL) {allchisq[i]=chisq;}
583 if(allchisq!=NULL) {allchisq[i]=0.;}
588 cout <<
"\nOut of " << numIterations <<
" attempts, " << numConverge <<
" actually converged." << endl;
589 cout <<
"\nThe best chisq is: " << bestchisq << endl;
590 cout <<
"\nThe worst chisq is: " << worstchisq << endl;
597 double* StEStructAutoFit::autofit11Parv3(
double* best, TH2D* plot,
int type,
double* allchisq) {
599 double amprange = plot->GetMaximum() - plot->GetMinimum();
603 for(
int i=1; i<=25; i++) {
604 for(
int k=1; k<=24; k++) {
605 mean += plot->GetBinContent(i, k);
608 mean *= 1./(25.*24.);
611 for(
int i=1; i<=25; i++) {
612 for(
int k=1; k<=24; k++) {
613 rms2 += pow(plot->GetBinContent(i, k)-mean, 2);
618 rms2 *= 1./(25.*24.);
621 cout <<
"\nmean=" << mean <<
"\trms=" << rms2 << endl;
631 double maxcos=amprange;
635 double maxv2=amprange;
639 double maxv3=amprange;
643 double maxg2=amprange;
645 double ming1=-2.*rms2;
648 double maxg1=2.*rms2;
653 double minoffset=mean-3.*rms2;
654 double maxoffset=mean+rms2;
657 double maxexp=10.*rms2;
667 double bestchisq=999999;
670 for(
int i=0; i<numIterations; i++) {
671 double phi = rand2.Rndm()*(maxphi-minphi)+minphi;
672 double eta = rand2.Rndm()*(maxeta-mineta)+mineta;
673 double cosv = rand2.Rndm()*(maxcos-mincos)+mincos;
674 double v2 = rand2.Rndm()*(maxv2-minv2)+minv2;
675 double v3 = rand2.Rndm()*(maxv3-minv3)+minv3;
676 double g2 = rand2.Rndm()*(maxg2-ming2)+ming2;
677 double g1 = rand2.Rndm()*(maxg1-ming1)+ming1;
678 double gw = rand2.Rndm()*(maxgw-mingw)+mingw;
679 double offset = rand2.Rndm()*(maxoffset-minoffset)+minoffset;
680 double exp = rand2.Rndm()*(maxexp-minexp)+minexp;
681 double expwe = rand2.Rndm()*(maxew-minew)+minew;
682 double expwp = rand2.Rndm()*(maxew-minew)+minew;
684 cout <<
"\nphi=" << phi <<
"\teta=" << eta <<
"\tcos=" << cosv <<
"\tv2=" << v2 <<
"\tg2=" << g2 <<
"\tg1=" << g1 <<
"\tgw=" << gw <<
"\toffset=" << offset << endl;
687 const Int_t npar = 12;
689 Double_t f2params[npar] = {cosv, v2, g2, eta, phi, g1, gw, offset, exp, expwe, expwp, v3};
691 TF2 *f2 =
new TF2(
"f2",fun1,-2,2,-Pi()/2.,3*Pi()/2, npar);
692 f2->SetParameters(f2params);
697 f2->SetParLimits(1, 0, 5);
698 f2->SetParLimits(2, 0, 5);
699 f2->SetParLimits(3, 0.1, 5);
700 f2->SetParLimits(4, 0.1, 2);
701 if(type == 1 || type == 2)
702 f2->SetParLimits(5, 0, 3);
703 f2->SetParLimits(6, 0.01, 7);
704 f2->SetParLimits(8, 0., 5);
705 f2->SetParLimits(9, 0.005, 2);
706 f2->SetParLimits(10, 0.005, 2);
708 int fitStatus=plot->Fit(
"f2",
"N");
709 fitStatus=plot->Fit(
"f2",
"EN");
712 double chisq=f2->GetChisquare();
713 cout <<
"\n" << f2->GetParameter(2) << endl;
715 chisqsqsum+=chisq*chisq;
716 if(chisq<bestchisq) {
717 for(
int i=0; i<npar; i++) {
718 best[i*2]=f2->GetParameter(i);
719 best[i*2+1]=f2->GetParError(i);
723 if(chisq>worstchisq) {
727 if(allchisq!=NULL) {allchisq[i]=chisq;}
729 if(allchisq!=NULL) {allchisq[i]=0.;}
734 cout <<
"\nOut of " << numIterations <<
" attempts, " << numConverge <<
" actually converged." << endl;
735 cout <<
"\nThe best chisq is: " << bestchisq << endl;
736 cout <<
"\nThe worst chisq is: " << worstchisq << endl;
745 double* StEStructAutoFit::autofit9Par(
double* best, TH2D* plot,
int type,
double* allchisq) {
747 plot->SetBinError(13, 7, 1000.);
748 plot->SetBinError(12, 7, 1000.);
749 plot->SetBinError(11, 7, 1000.);
750 plot->SetBinError(14, 7, 1000.);
751 plot->SetBinError(15, 7, 1000.);
752 plot->SetBinError(13, 6, 1000.);
753 plot->SetBinError(13, 8, 1000.);
755 double amprange = plot->GetMaximum() - plot->GetMinimum();
759 for(
int i=1; i<=25; i++) {
760 for(
int k=1; k<=24; k++) {
761 mean += plot->GetBinContent(i, k);
764 mean *= 1./(25.*24.);
767 for(
int i=1; i<=25; i++) {
768 for(
int k=1; k<=24; k++) {
769 rms2 += pow(plot->GetBinContent(i, k)-mean, 2);
774 rms2 *= 1./(25.*24.);
777 cout <<
"\nmean=" << mean <<
"\trms=" << rms2 << endl;
787 double maxcos=amprange;
791 double maxv2=amprange;
795 double maxg2=amprange;
797 double ming1=-2.*rms2;
800 double maxg1=2.*rms2;
805 double minoffset=mean-3.*rms2;
806 double maxoffset=mean+rms2;
816 double bestchisq=999999;
819 for(
int i=0; i<numIterations; i++) {
820 double phi = rand2.Rndm()*(maxphi-minphi)+minphi;
821 double eta = rand2.Rndm()*(maxeta-mineta)+mineta;
822 double cosv = rand2.Rndm()*(maxcos-mincos)+mincos;
823 double v2 = rand2.Rndm()*(maxv2-minv2)+minv2;
824 double g2 = rand2.Rndm()*(maxg2-ming2)+ming2;
825 double g1 = rand2.Rndm()*(maxg1-ming1)+ming1;
826 double gw = rand2.Rndm()*(maxgw-mingw)+mingw;
827 double offset = rand2.Rndm()*(maxoffset-minoffset)+minoffset;
828 double agw = rand2.Rndm()*(maxagw-minagw)+minagw;
830 cout <<
"\nphi=" << phi <<
"\teta=" << eta <<
"\tcos=" << cosv <<
"\tv2=" << v2 <<
"\tg2=" << g2 <<
"\tg1=" << g1 <<
"\tgw=" << gw <<
"\toffset=" << offset << endl;
833 const Int_t npar = 9;
835 Double_t f2params[npar] = {cosv, v2, g2, eta, phi, g1, gw, offset, agw};
837 TF2 *f2 =
new TF2(
"f2",fun5,-2,2,-Pi()/2.,3*Pi()/2, npar);
838 f2->SetParameters(f2params);
843 f2->SetParLimits(1, 0, 5);
844 f2->SetParLimits(2, 0, 5);
845 f2->SetParLimits(3, 0.1, 5);
846 f2->SetParLimits(4, 0.1, 2);
847 if(type == 1 || type == 2)
848 f2->SetParLimits(5, 0, 3);
849 f2->SetParLimits(6, 0.01, 7);
850 f2->SetParLimits(8, 0.01, 5);
852 int fitStatus=plot->Fit(
"f2",
"N");
853 fitStatus=plot->Fit(
"f2",
"EN");
856 double chisq=f2->GetChisquare();
857 cout <<
"\n" << f2->GetParameter(2) << endl;
859 chisqsqsum+=chisq*chisq;
860 if(chisq<bestchisq) {
861 for(
int i=0; i<npar; i++) {
862 best[i*2]=f2->GetParameter(i);
863 best[i*2+1]=f2->GetParError(i);
867 if(chisq>worstchisq) {
871 if(allchisq!=NULL) {allchisq[i]=chisq;}
873 if(allchisq!=NULL) {allchisq[i]=0.;}
878 cout <<
"\nOut of " << numIterations <<
" attempts, " << numConverge <<
" actually converged." << endl;
879 cout <<
"\nThe best chisq is: " << bestchisq << endl;
880 cout <<
"\nThe worst chisq is: " << worstchisq << endl;
888 double* StEStructAutoFit::autofit12Par(
double* best, TH2D* plot,
int type,
double* allchisq) {
890 double amprange = plot->GetMaximum() - plot->GetMinimum();
894 for(
int i=1; i<=25; i++) {
895 for(
int k=1; k<=24; k++) {
896 mean += plot->GetBinContent(i, k);
899 mean *= 1./(25.*24.);
902 for(
int i=1; i<=25; i++) {
903 for(
int k=1; k<=24; k++) {
904 rms2 += pow(plot->GetBinContent(i, k)-mean, 2);
909 rms2 *= 1./(25.*24.);
912 cout <<
"\nmean=" << mean <<
"\trms=" << rms2 << endl;
922 double maxcos=amprange;
926 double maxv2=amprange;
930 double maxg2=amprange;
932 double ming1=-2.*rms2;
935 double maxg1=2.*rms2;
940 double minoffset=mean-3.*rms2;
941 double maxoffset=mean+rms2;
947 double maxexp=10.*rms2;
957 double bestchisq=999999;
960 for(
int i=0; i<numIterations; i++) {
961 double phi = rand2.Rndm()*(maxphi-minphi)+minphi;
962 double eta = rand2.Rndm()*(maxeta-mineta)+mineta;
963 double cosv = rand2.Rndm()*(maxcos-mincos)+mincos;
964 double v2 = rand2.Rndm()*(maxv2-minv2)+minv2;
965 double g2 = rand2.Rndm()*(maxg2-ming2)+ming2;
966 double g1 = rand2.Rndm()*(maxg1-ming1)+ming1;
967 double gw = rand2.Rndm()*(maxgw-mingw)+mingw;
968 double offset = rand2.Rndm()*(maxoffset-minoffset)+minoffset;
969 double agw = rand2.Rndm()*(maxagw-minagw)+minagw;
970 double exp = rand2.Rndm()*(maxexp-minexp)+minexp;
971 double expwe = rand2.Rndm()*(maxew-minew)+minew;
972 double expwp = rand2.Rndm()*(maxew-minew)+minew;
974 cout <<
"\nphi=" << phi <<
"\teta=" << eta <<
"\tcos=" << cosv <<
"\tv2=" << v2 <<
"\tg2=" << g2 <<
"\tg1=" << g1 <<
"\tgw=" << gw <<
"\toffset=" << offset << endl;
977 const Int_t npar = 12;
979 Double_t f2params[npar] = {cosv, v2, g2, eta, phi, g1, gw, offset, agw, exp, expwe, expwp};
981 TF2 *f2 =
new TF2(
"f2",fun6,-2,2,-Pi()/2.,3*Pi()/2, npar);
982 f2->SetParameters(f2params);
987 f2->SetParLimits(1, 0, 5);
988 f2->SetParLimits(2, 0, 5);
989 f2->SetParLimits(3, 0.1, 5);
990 f2->SetParLimits(4, 0.1, 2);
991 if(type == 1 || type == 2)
992 f2->SetParLimits(5, 0, 3);
993 f2->SetParLimits(6, 0.01, 7);
994 f2->SetParLimits(8, 0.01, 5);
995 f2->SetParLimits(9, 0., 5);
996 f2->SetParLimits(10, 0.005, 2);
997 f2->SetParLimits(11, 0.005, 2);
999 int fitStatus=plot->Fit(
"f2",
"N");
1000 fitStatus=plot->Fit(
"f2",
"EN");
1003 double chisq=f2->GetChisquare();
1004 cout <<
"\n" << f2->GetParameter(2) << endl;
1006 chisqsqsum+=chisq*chisq;
1007 if(chisq<bestchisq) {
1008 for(
int i=0; i<npar; i++) {
1009 best[i*2]=f2->GetParameter(i);
1010 best[i*2+1]=f2->GetParError(i);
1014 if(chisq>worstchisq) {
1018 if(allchisq!=NULL) {allchisq[i]=chisq;}
1020 if(allchisq!=NULL) {allchisq[i]=0.;}
1025 cout <<
"\nOut of " << numIterations <<
" attempts, " << numConverge <<
" actually converged." << endl;
1026 cout <<
"\nThe best chisq is: " << bestchisq << endl;
1027 cout <<
"\nThe worst chisq is: " << worstchisq << endl;
1033 double* StEStructAutoFit::autofit11Par2G(
double* best, TH2D* plot,
int type,
double yt,
double* allchisq) {
1035 plot->SetBinError(13, 7, 1000.);
1036 plot->SetBinError(12, 7, 1000.);
1037 plot->SetBinError(11, 7, 1000.);
1038 plot->SetBinError(14, 7, 1000.);
1039 plot->SetBinError(15, 7, 1000.);
1040 plot->SetBinError(13, 6, 1000.);
1041 plot->SetBinError(13, 8, 1000.);
1043 double amprange = plot->GetMaximum() - plot->GetMinimum();
1047 for(
int i=1; i<=25; i++) {
1048 for(
int k=1; k<=24; k++) {
1049 mean += plot->GetBinContent(i, k);
1052 mean *= 1./(25.*24.);
1055 for(
int i=1; i<=25; i++) {
1056 for(
int k=1; k<=24; k++) {
1057 rms2 += pow(plot->GetBinContent(i, k)-mean, 2);
1062 rms2 *= 1./(25.*24.);
1065 cout <<
"\nmean=" << mean <<
"\trms=" << rms2 << endl;
1075 double maxcos=amprange;
1079 double maxv2=amprange;
1083 double maxg2=amprange;
1087 double maxg2b=amprange;
1089 double ming1=-2.*rms2;
1092 double maxg1=2.*rms2;
1097 double minoffset=mean-3.*rms2;
1098 double maxoffset=mean+rms2;
1100 double eta2 = .9/sqrt(yt);
1101 double phi2 = 1.8/sqrt(3.*yt-2.);
1107 double chisqsqsum=0;
1108 double bestchisq=999999;
1109 double worstchisq=0;
1111 for(
int i=0; i<numIterations; i++) {
1112 double phi = rand2.Rndm()*(maxphi-minphi)+minphi;
1113 double eta = rand2.Rndm()*(maxeta-mineta)+mineta;
1114 double cosv = rand2.Rndm()*(maxcos-mincos)+mincos;
1115 double v2 = rand2.Rndm()*(maxv2-minv2)+minv2;
1116 double g2 = rand2.Rndm()*(maxg2-ming2)+ming2;
1117 double g1 = rand2.Rndm()*(maxg1-ming1)+ming1;
1118 double gw = rand2.Rndm()*(maxgw-mingw)+mingw;
1119 double offset = rand2.Rndm()*(maxoffset-minoffset)+minoffset;
1120 double g2b = rand2.Rndm()*(maxg2-ming2)+ming2;
1122 cout <<
"\nphi=" << phi <<
"\teta=" << eta <<
"\tcos=" << cosv <<
"\tv2=" << v2 <<
"\tg2=" << g2 <<
"\tg1=" << g1 <<
"\tgw=" << gw <<
"\toffset=" << offset << endl;
1125 const Int_t npar = 11;
1127 Double_t f2params[npar] = {cosv, v2, g2, eta, phi, g1, gw, offset, g2b, eta2, phi2};
1129 TF2 *f2 =
new TF2(
"f2",fun7,-2,2,-Pi()/2.,3*Pi()/2, npar);
1130 f2->SetParameters(f2params);
1135 f2->SetParLimits(1, 0, 5);
1136 f2->SetParLimits(2, 0, 5);
1138 f2->SetParLimits(3, 0.1, 5);
1139 f2->SetParLimits(4, 0.1, 2);
1140 if(type == 1 || type == 2)
1141 f2->SetParLimits(5, 0, 3);
1142 f2->SetParLimits(6, 0.01, 7);
1143 if(type == 1 || type == 2)
1144 f2->SetParLimits(8, 0, 3);
1145 f2->FixParameter(9, eta2);
1146 f2->FixParameter(10, phi2);
1148 int fitStatus=plot->Fit(
"f2",
"N");
1149 fitStatus=plot->Fit(
"f2",
"EN");
1152 double chisq=f2->GetChisquare();
1153 cout <<
"\n" << f2->GetParameter(2) << endl;
1155 chisqsqsum+=chisq*chisq;
1156 if(chisq<bestchisq) {
1157 for(
int i=0; i<npar; i++) {
1158 best[i*2]=f2->GetParameter(i);
1159 best[i*2+1]=f2->GetParError(i);
1163 if(chisq>worstchisq) {
1167 if(allchisq!=NULL) {allchisq[i]=chisq;}
1169 if(allchisq!=NULL) {allchisq[i]=0.;}
1174 cout <<
"\nOut of " << numIterations <<
" attempts, " << numConverge <<
" actually converged." << endl;
1175 cout <<
"\nThe best chisq is: " << bestchisq << endl;
1176 cout <<
"\nThe worst chisq is: " << worstchisq << endl;