9 #include "UtilBeamLine3D.h"
12 int twoLineDca3D(
double& lambda,
double& kappa,TVector3& V, TVector3& U, TVector3& R,TVector3& P);
16 const char* comAlgo =
"MIGRAD";
23 int main(
int argc,
char *argv[]) {
24 printf(
"MAIN: %s(%s) nPar=%d\n",argv[0],comAlgo, argc-1);
26 if(argc<2) { printf(
"Abort, expected: %s coreName [x=doChi2plot] \n",argv[0]);
return 1;}
28 TRandom3* rnd =
new TRandom3(0);
32 Double_t amin,edm,errdef;
33 Int_t nvpar,nparx,icstat;
34 double pval[mxPar],perr[mxPar],plo[mxPar],phi[mxPar];
35 TString paraName[mxPar];
37 const char *core = argv[1]; assert(strlen(core)>5);
40 util.initHisto(&HList);
42 pval[0] = (rnd->Rndm()-0.5)*2.;
43 pval[1] = (rnd->Rndm()-0.5)*2.;
44 pval[2] = (rnd->Rndm()-0.5)/25.;
45 pval[3] = (rnd->Rndm()-0.5)/25.;
47 printf(
"rand # starting point = %f , %f , %f , %f \n",pval[0],pval[1],pval[2],pval[3]);
48 printf(
"main fit 3D beamline to %s start...\n",core);
50 TString inpFile=Form(
"inp/globTr_%s.txt",core);
51 util.readTracks(inpFile);
54 int nOkTr=util.qaTracks();
58 TMinuit *gMinuit =
new TMinuit(4);
60 gMinuit->SetFCN(beamLineLike3D);
65 gMinuit->mnexcm(
"SET ERR",arglist,1,error_flag);
70 gMinuit->mnparm(0,
"X0 (cm)",pval[0],0.01,-2,2,error_flag);
71 gMinuit->mnparm(1,
"Y0 (cm)",pval[1],0.01,-2,2,error_flag);
72 gMinuit->mnparm(2,
"Ux",pval[3],0.001,-0.1,0.1,error_flag);
73 gMinuit->mnparm(3,
"Uy",pval[3],0.001,-0.1,0.1,error_flag);
84 gMinuit->mnexcm(comAlgo,arglist,2,error_flag);
86 gMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat);
87 gMinuit->mnprin(3,amin);
94 for(
int ip=0;ip<mxPar;ip++) {
95 gMinuit->mnpout(ip,paraName[ip],pval[ip],perr[ip],plo[ip],phi[ip],istat);
96 TString tt=paraName[ip];
float val=pval[ip], err=perr[ip];
97 if(ip>1) { tt=
"30x "+tt; val*=30.; err*=30.;}
98 util.hA[19]->Fill(tt,val);
99 util.hA[19]->SetBinError(ip+1,err);
101 util.hA[19]->GetXaxis()->SetTitle(core);
103 printf(
"\n#beamLine for %s Xcm,Ycm,Ux,Uy = %.3f %.3f %.5f %.5f nOkTr= %d\n",core,pval[0],pval[1],pval[2],pval[3], nOkTr);
104 printf(
"#beamLineWerr for %s Xcm,Ycm,Ux,Uy = %.3f %.2e %.3f %.2e %.5f %.2e %.5f %.2e nOkTr= %d\n",core,pval[0],perr[0],pval[1],perr[1],pval[2],perr[2],pval[3],perr[3], nOkTr );
107 printf(
"\n ***done!***, scan Chi2 around solution\n");
108 util.evalSolution(pval);
111 util.scanChi2(pval,0);
112 util.scanChi2(pval,1);
113 util.scanChi2(pval,2);
115 printf(
"skip generation of 2D chi2 plots\n");
121 TString outName=
"out/3D_beam_"; outName+=core;outName+=
".hist.root";
122 TFile f( outName,
"recreate");
124 printf(
"%d histos are written to '%s' ...\n",HList.GetEntries(),outName.Data());