53 #include "TGraphErrors.h"
54 #include "TMultiGraph.h"
58 #include "Math/Minimizer.h"
59 #include "Math/Factory.h"
61 #include "reportingUtils.hpp"
65 #include "TStopwatch.h"
66 #include "libconfig.h++"
68 #define MASSSCALE 0.001
72 using namespace libconfig;
73 using namespace ROOT::Math;
79 const int errCode = 0)
81 cerr <<
"usage:" << endl
83 <<
" -c configfile -i inputfile [-o outfile -l # -u #"
84 <<
" -M minimizer [-m algorithm] -t # -q -h -P -C] [-S fitResultFiles]" << endl
86 <<
" -c file path to config File" << endl
87 <<
" -i file path to input file" << endl
88 <<
" -o file path to output file (default: 'mDep.result.root')" << endl
90 <<
" -l # -u # lower and upper mass range used for fit" << endl
91 <<
" -M name minimizer (default: Minuit2)" << endl
92 <<
" -m name minimization algorithm (optional, default: Migrad)" << endl
93 <<
" available minimizers: Minuit: Migrad, Simplex, Minimize, Migrad_imp" << endl
94 <<
" Minuit2: Migrad, Simplex, Combined, Scan, Fumili" << endl
95 <<
" GSLMultiMin: ConjugateFR, ConjugatePR, BFGS, BFGS2, SteepestDescent" << endl
96 <<
" GSLMultiFit: -" << endl
97 <<
" GSLSimAn: -" << endl
98 <<
" Linear: Robust" << endl
99 <<
" Fumili: -" << endl
100 <<
" -t # minimizer tolerance (default: 1e-10)" << endl
101 <<
" -q run quietly (default: false)" << endl
102 <<
" -h print help" << endl
103 <<
" -P plotting only - no fit" << endl
104 <<
" -C switch OFF covariances between real and imag part" << endl
105 <<
" -S files Systematic error plotting. give list of files" << endl
115 unsigned int n=tree->GetEntries();
116 TGraph* graph=
new TGraph(n);
118 tree->SetBranchAddress(
"fitResult_v2",&res);
119 for(
unsigned int i=0;
i<
n; ++
i){
125 graph->SetPoint(
i,m,ps);
138 const vector<string>& anchorwave_reso,
139 const vector<string>& anchorwave_channel,
142 unsigned int npar=minimizer->NDim();
144 for(
unsigned int i=0;
i<npar;++
i)par[
i]=minimizer->X()[
i];
147 unsigned int parcount=0;
148 for(
unsigned int ic=0;
ic<compset.
n();++
ic){
150 TString name(comp.
name());
151 double mmin,mmax,gmin,gmax;
153 if(comp.
fixM() || level==0)minimizer->SetFixedVariable(parcount,
156 else minimizer->SetLimitedVariable(parcount,
161 if(level==0 && !comp.
fixM()) printInfo << minimizer->VariableName(parcount)
162 <<
" fixed to " << par[parcount] << endl;
164 if(comp.
fixGamma() || level < 2)minimizer->SetFixedVariable(parcount,
165 (name+
"_Gamma").Data() ,
167 else minimizer->SetLimitedVariable(parcount,
168 (name+
"_Gamma").Data(),
172 if(level<2 && !comp.
fixGamma()) printInfo << minimizer->VariableName(parcount)
173 <<
" fixed to " << par[parcount] << endl;
176 std::map<std::string,pwachannel >::const_iterator it=comp.
channels().begin();
178 minimizer->SetVariable(parcount,(name +
"_ReC" + it->first).Data() , par[parcount], 10.0);
181 if(find(anchorwave_reso.begin(),anchorwave_reso.end(),name)!=anchorwave_reso.end() && find(anchorwave_channel.begin(),anchorwave_channel.end(),it->first)!=anchorwave_channel.end()){
182 minimizer->SetFixedVariable(parcount,(name +
"_ImC" + it->first).Data() , 0.0);
184 else {minimizer->SetVariable(parcount,(name +
"_ImC" + it->first).Data() , par[parcount], 0.10);}
191 for(
unsigned int ifreePS=0;ifreePS<nfreePS;++ifreePS){
192 double val,lower,upper;
195 TString name(
"PSP_"); name+=+ifreePS;
196 minimizer->SetLimitedVariable(parcount,
198 val, 0.0001 ,lower,upper);
203 const unsigned int nfree=minimizer->NFree();
204 printInfo << nfree <<
" Free Parameters in fit" << endl;
217 const string valTreeName =
"pwa";
218 const string valBranchName =
"fitResult_v2";
222 const unsigned int maxNmbOfIterations = 20000;
223 const bool runHesse =
true;
224 const bool runMinos =
false;
225 bool onlyPlotting =
false;
226 bool sysPlotting =
false;
232 const string progName = argv[0];
233 double massBinMin = 0;
234 double massBinMax = 5000;
236 string inFileName =
"fitresult.root";
237 string outFileName =
"mDep.result.root";
239 string minimizerType[2] = {
"Minuit2",
"Migrad"};
240 double minimizerTolerance = 1e-10;
249 while ((ca = getopt(argc, argv,
"c:i:o:u:l:M:m:t:qhPCS")) != -1)
255 outFileName = optarg;
261 minimizerType[0] = optarg;
264 minimizerType[1] = optarg;
267 minimizerTolerance = atof(optarg);
270 massBinMin = atof(optarg);
273 massBinMax = atof(optarg);
294 TFile* infile=TFile::Open(inFileName.c_str());
296 cerr <<
"Input file " << inFileName <<
" not found."<< endl;
299 TTree* tree=(TTree*)infile->Get(valTreeName.c_str());
301 cerr <<
"Input tree " << valTreeName <<
" not found."<< endl;
306 vector<TTree*> sysTrees;
309 sysTrees.push_back(tree);
311 for(
int i=optind;
i<argc;++
i){
313 TFile* infile=TFile::Open(argv[
i]);
315 cerr <<
"Systematics Input file " << inFileName <<
" not found."<< endl;
318 TTree* systree=(TTree*)infile->Get(valTreeName.c_str());
320 cerr <<
"Input tree " << valTreeName <<
" not found."<< endl;
323 sysTrees.push_back(systree);
325 printInfo << sysTrees.size() <<
" files for systematics found " << endl;
328 printInfo <<
"creating and setting up likelihood function" << endl;
329 printInfo <<
"doCovariances = " << doCov << endl;
336 Conf.readFile(configFile.c_str());
337 const Setting&
root = Conf.getRoot();
344 if(Conf.exists(
"ps")){
345 const Setting &pss = root[
"ps"];
346 check&=pss.lookupValue(
"formfactor",gps);
347 check&=pss.lookupValue(
"lower",pslower);
348 check&=pss.lookupValue(
"upper",psupper);
352 TF1* fPS=
new TF1(
"fps",
"[1] * ((x-[0])/1000.)^5*(1.+((x-[0])/1000.)*[2])*exp(-[3]* ((x-[0])/1000.)^2)",900,3000);
353 fPS->SetParameter(0,698);
354 fPS->SetParLimits(0,698,698);
355 fPS->SetParameter(1,308.7E-6);
356 fPS->SetParLimits(1,308.7E-6,308.7E-6);
357 fPS->SetParameter(2,4.859);
358 fPS->SetParLimits(2,4.859,4.859);
359 fPS->SetParameter(3,gps);
360 fPS->SetParLimits(3,pslower,psupper);
366 if(Conf.exists(
"components.resonances")){
367 const Setting &bws = root[
"components"][
"resonances"];
369 int nbw=bws.getLength();
370 printInfo <<
"found " << nbw <<
" Resonances in config" << endl;
371 for(
int ibw = 0; ibw < nbw; ++ibw) {
372 const Setting &bw = bws[ibw];
375 double mass=-1;
double ml,mu;
int mfix;
376 double width=-1;
double wl,wu;
int wfix;
int wdyn;
378 check&=bw.lookupValue(
"name", name);
379 check&=bw.lookupValue(
"jpc", jpc);
380 const Setting &massSet = bw[
"mass"];
381 check&=massSet.lookupValue(
"val", mass);
382 check&=massSet.lookupValue(
"lower", ml);
383 check&=massSet.lookupValue(
"upper", mu);
384 check&=massSet.lookupValue(
"fix", mfix);
385 const Setting &widthSet = bw[
"width"];
386 check&=widthSet.lookupValue(
"val", width);
387 check&=widthSet.lookupValue(
"lower", wl);
388 check&=widthSet.lookupValue(
"upper", wu);
389 check&=widthSet.lookupValue(
"fix", wfix);
390 bool checkdyn=widthSet.lookupValue(
"dyn", wdyn);
392 cout <<
"---------------------------------------------------------------------" << endl;
393 cout << name <<
" JPC = " << jpc << endl;
394 cout <<
"mass(limits) = " << mass <<
" ("<<ml<<
","<<mu<<
") MeV/c^2";
395 if(mfix==1)cout<<
" -- FIXED";
397 cout <<
"width(limits) = " << width <<
" ("<<wl<<
","<<wu<<
") MeV/c^2";
398 if(wfix==1)cout<<
" -- FIXED";
399 if(wdyn!=0)cout<<
" -- DYNAMIC WIDTH";
400 else cout<<
" -- CONST WIDTH";
402 const Setting &channelSet = bw[
"decaychannels"];
403 unsigned int nCh=channelSet.getLength();
404 cout <<
"Decaychannels (coupling):" << endl;
405 std::map<std::string,pwachannel > channels;
406 for(
unsigned int iCh=0;iCh<nCh;++iCh){
407 const Setting &ch = channelSet[iCh];
411 check&=ch.lookupValue(
"amp",amp);
412 check&=ch.lookupValue(
"coupling_Re",cRe);
413 check&=ch.lookupValue(
"coupling_Im",cIm);
414 complex<double> C(cRe,cIm);
415 cout <<
" " << amp <<
" " << C << endl;
419 printErr <<
"Bad config value lookup! Check your config file!" << endl;
423 cerr <<
"created component" << endl;
428 cout <<
"CHECK val(m0)="<< comp1->
val(mass) << endl;
433 if(Conf.exists(
"components.background")){
434 const Setting &bws = root[
"components"][
"background"];
436 int nbw=bws.getLength();
437 printInfo <<
"found " << nbw <<
" Background components in config" << endl;
438 for(
int ibw = 0; ibw < nbw; ++ibw) {
439 const Setting &bw = bws[ibw];
441 double mass=-1;
double ml,mu;
int mfix;
442 double width=-1;
double wl,wu;
int wfix;
444 check&=bw.lookupValue(
"name", name);
445 const Setting &massSet = bw[
"m0"];
446 check&=massSet.lookupValue(
"val", mass);
447 check&=massSet.lookupValue(
"lower", ml);
448 check&=massSet.lookupValue(
"upper", mu);
449 check&=massSet.lookupValue(
"fix", mfix);
450 const Setting &widthSet = bw[
"g"];
451 check&=widthSet.lookupValue(
"val", width);
452 check&=widthSet.lookupValue(
"lower", wl);
453 check&=widthSet.lookupValue(
"upper", wu);
454 check&=widthSet.lookupValue(
"fix", wfix);
455 cout <<
"---------------------------------------------------------------------" << endl;
456 cout << name << endl;
457 cout <<
"mass-offset(limits) = " << mass <<
" ("<<ml<<
","<<mu<<
") MeV/c^2";
458 if(mfix==1)cout<<
" -- FIXED";
460 cout <<
"g(limits) = " << width <<
" ("<<wl<<
","<<wu<<
") MeV/c^2";
461 if(wfix==1)cout<<
" -- FIXED";
463 std::map<std::string,pwachannel > channels;
469 check&=bw.lookupValue(
"amp",amp);
470 check&=bw.lookupValue(
"coupling_Re",cRe);
471 check&=bw.lookupValue(
"coupling_Im",cIm);
472 check&=bw.lookupValue(
"mIsobar1",mIso1);
473 check&=bw.lookupValue(
"mIsobar2",mIso2);
474 complex<double> C(cRe,cIm);
475 cout <<
"Decaychannel (coupling):" << endl;
476 cout <<
" " << amp <<
" " << C << endl;
477 cout <<
" Isobar masses: " << mIso1<<
" "<< mIso2<< endl;
481 printErr <<
"Bad config value lookup! Check your config file!" << endl;
493 cout <<
"---------------------------------------------------------------------" << endl << endl;
498 cout <<
"---------------------------------------------------------------------" << endl << endl;
501 vector<string> anchorwave_channel;
502 vector<string> anchorwave_reso;
503 if(Conf.exists(
"components.anchorwave")){
504 const Setting &anc = root[
"components"][
"anchorwave"];
506 unsigned int nanc=anc.getLength();
507 for(
unsigned int ianc=0;ianc<nanc;++ianc){
509 const Setting &anco = anc[ianc];
510 anco.lookupValue(
"channel",ch);
511 anco.lookupValue(
"resonance",re);
512 cout <<
"Ancorwave: "<< endl;
513 cout <<
" " << re << endl;
514 cout <<
" " << ch << endl;
515 anchorwave_channel.push_back(ch);
516 anchorwave_reso.push_back(re);
521 cout <<
"---------------------------------------------------------------------" << endl << endl;
526 L.
init(tree,fPS,&compset,massBinMin,massBinMax,doCov);
528 const unsigned int nmbPar = L.
NDim();
540 printInfo << nmbPar <<
" Parameters in fit" << endl;
544 printInfo <<
"creating and setting up minimizer " << minimizerType[0] <<
" using algorithm " << minimizerType[1] << endl;
545 Minimizer* minimizer = Factory::CreateMinimizer(minimizerType[0], minimizerType[1]);
547 printErr <<
"could not create minimizer! exiting!" << endl;
550 minimizer->SetFunction(L);
551 minimizer->SetPrintLevel((quiet) ? 0 : 3);
556 unsigned int parcount=0;
557 for(
unsigned int ic=0;
ic<compset.
n();++
ic){
559 TString name(comp.
name());
560 double mmin,mmax,gmin,gmax;
562 if(comp.
fixM())minimizer->SetFixedVariable(parcount++,
565 else minimizer->SetLimitedVariable(parcount++,
570 if(comp.
fixGamma())minimizer->SetFixedVariable(parcount++,
571 (name+
"_Gamma").Data() ,
573 else minimizer->SetLimitedVariable(parcount++,
574 (name+
"_Gamma").Data(),
578 std::map<std::string,pwachannel >::const_iterator it=comp.
channels().begin();
580 minimizer->SetVariable(parcount++,(name +
"_ReC" + it->first).Data() , it->second.C().real(), 0.10);
583 if(find(anchorwave_reso.begin(),anchorwave_reso.end(),name)!=anchorwave_reso.end() && find(anchorwave_channel.begin(),anchorwave_channel.end(),it->first)!=anchorwave_channel.end()){
584 minimizer->SetFixedVariable(parcount++,(name +
"_ImC" + it->first).Data() , 0.0);
586 else {minimizer->SetVariable(parcount++,(name +
"_ImC" + it->first).Data() , it->second.C().imag(), 0.10);}
593 for(
unsigned int ifreePS=0;ifreePS<nfreePS;++ifreePS){
594 double val,lower,upper;
597 TString name(
"PSP_"); name+=+ifreePS;
598 minimizer->SetLimitedVariable(parcount++,
600 val, 0.0001 ,lower,upper);
605 const unsigned int nfree=minimizer->NFree();
606 printInfo << nfree <<
" Free Parameters in fit" << endl;
611 if(onlyPlotting) printInfo <<
"Plotting mode, skipping minimzation!" << endl;
613 printInfo <<
"performing minimization. MASSES AND WIDTHS FIXED" << endl;
615 minimizer->SetMaxIterations(maxNmbOfIterations);
616 minimizer->SetMaxFunctionCalls(maxNmbOfIterations*5);
617 minimizer->SetTolerance (minimizerTolerance);
621 bool success = minimizer->Minimize();
622 if(!success)printWarn <<
"minimization failed." << endl;
623 else printInfo <<
"minimization successful." << endl;
624 printInfo <<
"Minimization took " << maxPrecisionAlign(fitW.CpuTime()) <<
" s" << endl;
626 releasePars(minimizer,compset,anchorwave_reso,anchorwave_channel,1);
627 printInfo <<
"performing minimization. MASSES RELEASED" << endl;
629 success &= minimizer->Minimize();
630 if(!success)printWarn <<
"minimization failed." << endl;
631 else printInfo <<
"minimization successful." << endl;
632 printInfo <<
"Minimization took " << maxPrecisionAlign(fitW.CpuTime()) <<
" s" << endl;
634 releasePars(minimizer,compset,anchorwave_reso,anchorwave_channel,2);
635 printInfo <<
"performing minimization. ALL RELEASED" << endl;
637 success &= minimizer->Minimize();
638 printInfo <<
"Minimization took " << maxPrecisionAlign(fitW.CpuTime()) <<
" s" << endl;
640 const double* par=minimizer->X();
642 cerr << compset << endl;
644 printInfo <<
"minimization finished successfully." << endl;
645 chi2=minimizer->MinValue();
648 printWarn <<
"minimization failed." << endl;
650 printInfo <<
"calculating Hessian matrix." << endl;
651 success = minimizer->Hesse();
653 printWarn <<
"calculation of Hessian matrix failed." << endl;
656 printInfo <<
"minimization stopped after " << minimizer->NCalls() <<
" function calls. minimizer status summary:" << endl
657 <<
" total number of parameters .......................... " << minimizer->NDim() << endl
658 <<
" number of free parameters ........................... " << minimizer->NFree() << endl
659 <<
" maximum allowed number of iterations ................ " << minimizer->MaxIterations() << endl
660 <<
" maximum allowed number of function calls ............ " << minimizer->MaxFunctionCalls() << endl
661 <<
" minimizer status .................................... " << minimizer->Status() << endl
662 <<
" minimizer provides error and error matrix ........... " << minimizer->ProvidesError() << endl
663 <<
" minimizer has performed detailed error validation ... " << minimizer->IsValidError() << endl
664 <<
" estimated distance to minimum ....................... " << minimizer->Edm() << endl
665 <<
" statistical scale used for error calculation ........ " << minimizer->ErrorDef() << endl
666 <<
" minimizer strategy .................................. " << minimizer->Strategy() << endl
667 <<
" absolute tolerance .................................. " << minimizer->Tolerance() << endl;
673 printInfo <<
"minimization result:" << endl;
674 for (
unsigned int i = 0;
i< nmbPar; ++
i) {
675 cout <<
" parameter [" << setw(3) <<
i <<
"] ";
676 cout << minimizer->VariableName(i) <<
" " ;
681 cout << setw(12) << maxPrecisionAlign(minimizer->X()[
i]) <<
" +- "
682 << setw(12) << maxPrecisionAlign(minimizer->Errors()[
i]);
686 if (runMinos && (i == 156)) {
687 double minosErrLow = 0;
688 double minosErrUp = 0;
689 const bool success = minimizer->GetMinosError(i, minosErrLow, minosErrUp);
691 cout <<
" Minos: " <<
"[" << minosErrLow <<
", +" << minosErrUp <<
"]" << endl;
696 cout <<
"---------------------------------------------------------------------" << endl;
699 printInfo << chi2 <<
" chi2" << endl;
702 unsigned int numDOF=numdata-nfree;
703 printInfo << numDOF <<
" degrees of freedom" << endl;
704 double redChi2 = chi2/(double)numDOF;
705 printInfo << redChi2 <<
" chi2/nDF" << endl;
706 cout <<
"---------------------------------------------------------------------" << endl;
711 const Setting& fitqualS= root[
"fitquality"];
712 Setting& chi2S=fitqualS[
"chi2"];
714 Setting& ndfS=fitqualS[
"ndf"];
716 Setting& redchi2S=fitqualS[
"redchi2"];
718 const Setting& psS= root[
"ps"];
719 Setting& ffS=psS[
"formfactor"];
720 ffS=(double)fPS->GetParameter(3);
723 Setting& ffeS=psS[
"error"];
724 ffeS=minimizer->Errors()[minimizer->VariableIndex(
"PSP_0")];
728 const Setting& bws= root[
"components"][
"resonances"];
729 const Setting& bkgs= root[
"components"][
"background"];
730 unsigned int nbws=bws.getLength();
731 unsigned int nbkgs=bkgs.getLength();
733 unsigned int nc=compset.
n();
734 for(
unsigned int ic=0;
ic<nc;++
ic){
736 string name=comp->
name();
741 for(
unsigned int is=0;is<nbws;++is){
742 const Setting& bw = bws[is];
743 bw.lookupValue(
"name", sname);
747 Setting& sm = bw[
"mass"];
748 Setting& smval = sm[
"val"];
750 Setting& smerr = sm[
"error"];
751 TString merrname=name+
"_M";
752 smerr=minimizer->Errors()[minimizer->VariableIndex(merrname.Data())];
754 Setting& sw = bw[
"width"];
755 Setting& swval = sw[
"val"];
756 swval = comp->
gamma();
758 Setting& swerr = sw[
"error"];
759 TString werrname=name+
"_Gamma";
760 swerr=minimizer->Errors()[minimizer->VariableIndex(werrname.Data())];
763 <<
" mass="<<double(smval)<<
" +- "<<double(smerr)
764 <<
" width="<<double(swval)<<
" +- "<<double(swerr)<< endl;
767 const Setting& sChn=bw[
"decaychannels"];
768 unsigned int nCh=sChn.getLength();
769 const std::map<std::string,pwachannel >& ch=comp->
channels();
770 std::map<std::string,pwachannel>::const_iterator it=ch.begin();
771 for(;it!=ch.end();++it){
772 std::complex<double> c= it->second.C();
773 string ampname=it->first;
775 for(
unsigned int isc=0;isc<nCh;++isc){
776 Setting& sCh=sChn[isc];
777 string amp; sCh.lookupValue(
"amp",amp);
779 Setting& sRe=sCh[
"coupling_Re"];
781 Setting& sIm=sCh[
"coupling_Im"];
795 for(
unsigned int is=0;is<nbkgs;++is){
796 const Setting& bw = bkgs[is];
797 bw.lookupValue(
"name", sname);
799 Setting& sm = bw[
"m0"];
800 Setting& smval = sm[
"val"];
802 Setting& sw = bw[
"g"];
803 Setting& swval = sw[
"val"];
804 swval = comp->
gamma();
807 std::complex<double> c=ch.
C();
808 Setting& sRe=bw[
"coupling_Re"];
810 Setting& sIm=bw[
"coupling_Im"];
946 string outconfig(outFileName);
947 outconfig.append(
".conf");
948 Conf.writeFile(outconfig.c_str());
950 cerr <<
"Fitting finished... Start building graphs ... " << endl;
952 int syscolor=kAzure-9;
954 std::vector<std::string> wl=compset.
wavelist();
955 std::map<std::string, unsigned int> wmap;
956 unsigned int ndatabins=tree->GetEntries();
958 std::vector<TGraphErrors*> datagraphs;
959 std::vector<TGraphErrors*> intenssysgraphs;
961 std::vector<TMultiGraph*> graphs;
963 for(
unsigned int iw=0; iw<wl.size();++iw){
965 graphs.push_back(
new TMultiGraph);
967 intenssysgraphs.push_back(
new TGraphErrors(ndatabins));
968 string name=(
"sys_");name.append(wl[iw]);
969 intenssysgraphs[iw]->SetName(name.c_str());
970 intenssysgraphs[iw]->SetTitle(name.c_str());
971 intenssysgraphs[iw]->SetLineColor(syscolor);
972 intenssysgraphs[iw]->SetFillColor(syscolor);
973 intenssysgraphs[iw]->SetDrawOption(
"2");
974 graphs[iw]->Add(intenssysgraphs[iw],
"2");
978 graphs[iw]->SetName(wl[iw].c_str());
979 graphs[iw]->SetTitle(wl[iw].c_str());
980 graphs[iw]->SetDrawOption(
"AP");
981 datagraphs.push_back(
new TGraphErrors(ndatabins));
982 name=
"data_";name.append(wl[iw]);
983 datagraphs[iw]->SetName(name.c_str());
984 datagraphs[iw]->SetTitle(name.c_str());
985 datagraphs[iw]->SetDrawOption(
"AP");
989 graphs[iw]->Add(datagraphs[iw],
"P");
996 unsigned int nbins=ndatabins;
999 std::vector<TGraph*> fitgraphs;
1000 std::vector<TGraph*> absphasegraphs;
1003 for(
unsigned int iw=0; iw<wl.size();++iw){
1004 fitgraphs.push_back(
new TGraph(nbins));
1005 string name(
"fit_");name.append(wl[iw]);
1006 fitgraphs[iw]->SetName(name.c_str());
1007 fitgraphs[iw]->SetTitle(name.c_str());
1008 fitgraphs[iw]->SetLineColor(kRed);
1009 fitgraphs[iw]->SetLineWidth(2);
1010 fitgraphs[iw]->SetMarkerColor(kRed);
1011 fitgraphs[iw]->SetDrawOption(
"AP");
1013 graphs[iw]->Add(fitgraphs[iw],
"cp");
1016 absphasegraphs.push_back(
new TGraph(nbins));
1017 name=
"absphase_";name.append(wl[iw]);
1018 absphasegraphs[iw]->SetName(name.c_str());
1019 absphasegraphs[iw]->SetTitle(name.c_str());
1020 absphasegraphs[iw]->SetLineColor(kRed);
1021 absphasegraphs[iw]->SetLineWidth(2);
1022 absphasegraphs[iw]->SetMarkerColor(kRed);
1023 absphasegraphs[iw]->SetDrawOption(
"AP");
1029 std::vector<TGraph*> compgraphs;
1031 for(
unsigned int ic=0;
ic<compset.
n();++
ic){
1033 std::map<std::string,pwachannel >::const_iterator it=c->
channels().begin();
1035 string name=c->
name();name.append(
"__");
1036 name.append(it->first);
1037 TGraph* gcomp=
new TGraph(nbins);
1038 gcomp->SetName(name.c_str());
1039 gcomp->SetTitle(name.c_str());
1040 unsigned int color=kBlue;
1041 if(dynamic_cast<const pwabkg*>(c)!=NULL)color=kMagenta;
1042 gcomp->SetLineColor(color);
1043 gcomp->SetMarkerColor(color);
1045 compgraphs.push_back(gcomp);
1046 graphs[wmap[it->first]]->Add(gcomp,
"cp");
1053 std::vector<TGraphErrors*> phasedatagraphs;
1054 std::vector<TGraphErrors*> phasesysgraphs;
1057 std::vector<TGraphErrors*> realdatagraphs;
1058 std::vector<TGraphErrors*> realsysgraphs;
1059 std::vector<TGraphErrors*> imagdatagraphs;
1060 std::vector<TGraphErrors*> imagsysgraphs;
1062 std::vector<TGraph*> realfitgraphs;
1063 std::vector<TGraph*> imagfitgraphs;
1065 std::vector<TMultiGraph*> phasegraphs;
1066 std::vector<TMultiGraph*> overlapRegraphs;
1067 std::vector<TMultiGraph*> overlapImgraphs;
1069 std::vector<TGraph*> phasefitgraphs;
1073 for(
unsigned int iw=0; iw<wl.size();++iw){
1074 for(
unsigned int iw2=iw+1; iw2<wl.size();++iw2){
1078 phasegraphs.push_back(
new TMultiGraph);
1079 overlapImgraphs.push_back(
new TMultiGraph);
1080 overlapRegraphs.push_back(
new TMultiGraph);
1081 string name(
"dPhi_");name.append(wl[iw]);
1082 name.append(
"---");name.append(wl[iw2]);
1083 phasegraphs[c]->SetName(name.c_str());
1084 phasegraphs[c]->SetTitle(name.c_str());
1085 name=
"Re_";name.append(wl[iw]);
1086 name.append(
"---");name.append(wl[iw2]);
1087 overlapRegraphs[c]->SetName(name.c_str());
1088 overlapRegraphs[c]->SetTitle(name.c_str());
1089 name=
"Im_";name.append(wl[iw]);
1090 name.append(
"---");name.append(wl[iw2]);
1091 overlapImgraphs[c]->SetName(name.c_str());
1092 overlapImgraphs[c]->SetTitle(name.c_str());
1094 phasesysgraphs.push_back(
new TGraphErrors(nbins));
1095 name=(
"dPhi_sys_");name.append(wl[iw]);
1096 name.append(
"---");name.append(wl[iw2]);
1097 phasesysgraphs[c]->SetName(name.c_str());
1098 phasesysgraphs[c]->SetTitle(name.c_str());
1099 phasesysgraphs[c]->SetLineColor(syscolor);
1100 phasesysgraphs[c]->SetFillColor(syscolor);
1101 phasesysgraphs[c]->SetDrawOption(
"2");
1105 phasegraphs[c]->Add(phasesysgraphs[c],
"2");
1108 phasedatagraphs.push_back(
new TGraphErrors(nbins));
1109 name=(
"dPhi_data_");name.append(wl[iw]);
1110 name.append(
"---");name.append(wl[iw2]);
1111 phasedatagraphs[c]->SetName(name.c_str());
1112 phasedatagraphs[c]->SetTitle(name.c_str());
1113 phasegraphs[c]->Add(phasedatagraphs[c],
"p");
1116 realsysgraphs.push_back(
new TGraphErrors(nbins));
1117 name=(
"RE_sys_");name.append(wl[iw]);
1118 name.append(
"---");name.append(wl[iw2]);
1119 realsysgraphs[c]->SetName(name.c_str());
1120 realsysgraphs[c]->SetTitle(name.c_str());
1121 realsysgraphs[c]->SetLineColor(syscolor);
1122 realsysgraphs[c]->SetFillColor(syscolor);
1123 realsysgraphs[c]->SetDrawOption(
"2");
1124 overlapRegraphs[c]->Add(realsysgraphs[c],
"2");
1126 imagsysgraphs.push_back(
new TGraphErrors(nbins));
1127 name=(
"IM_sys_");name.append(wl[iw]);
1128 name.append(
"---");name.append(wl[iw2]);
1129 imagsysgraphs[c]->SetName(name.c_str());
1130 imagsysgraphs[c]->SetTitle(name.c_str());
1131 imagsysgraphs[c]->SetLineColor(syscolor);
1132 imagsysgraphs[c]->SetFillColor(syscolor);
1133 imagsysgraphs[c]->SetDrawOption(
"2");
1134 overlapImgraphs[c]->Add(imagsysgraphs[c],
"2");
1137 realdatagraphs.push_back(
new TGraphErrors(nbins));
1138 name=(
"RE_data_");name.append(wl[iw]);
1139 name.append(
"---");name.append(wl[iw2]);
1140 realdatagraphs[c]->SetName(name.c_str());
1141 realdatagraphs[c]->SetTitle(name.c_str());
1142 overlapRegraphs[c]->Add(realdatagraphs[c],
"p");
1144 imagdatagraphs.push_back(
new TGraphErrors(nbins));
1145 name=(
"IM_data_");name.append(wl[iw]);
1146 name.append(
"---");name.append(wl[iw2]);
1147 imagdatagraphs[c]->SetName(name.c_str());
1148 imagdatagraphs[c]->SetTitle(name.c_str());
1150 overlapImgraphs[c]->Add(imagdatagraphs[c],
"p");
1157 for(
unsigned int iw=0; iw<wl.size();++iw){
1158 for(
unsigned int iw2=iw+1; iw2<wl.size();++iw2){
1159 phasefitgraphs.push_back(
new TGraph(nbins));
1160 string name(
"dPhi_fit_");name.append(wl[iw]);
1161 name.append(
"---");name.append(wl[iw2]);
1162 phasefitgraphs[c]->SetName(name.c_str());
1163 phasefitgraphs[c]->SetTitle(name.c_str());
1164 phasefitgraphs[c]->SetLineColor(kRed);
1165 phasefitgraphs[c]->SetMarkerColor(kRed);
1166 phasefitgraphs[c]->SetDrawOption(
"P");
1167 phasefitgraphs[c]->SetMarkerStyle(24);
1168 phasefitgraphs[c]->SetMarkerSize(0.2);
1169 phasegraphs[c]->Add(phasefitgraphs[c],
"cp");
1171 realfitgraphs.push_back(
new TGraph(nbins));
1172 name=(
"Re_fit_");name.append(wl[iw]);
1173 name.append(
"---");name.append(wl[iw2]);
1174 realfitgraphs[c]->SetName(name.c_str());
1175 realfitgraphs[c]->SetTitle(name.c_str());
1176 realfitgraphs[c]->SetLineColor(kRed);
1177 realfitgraphs[c]->SetMarkerColor(kRed);
1178 realfitgraphs[c]->SetDrawOption(
"AP");
1179 realfitgraphs[c]->SetMarkerStyle(24);
1180 realfitgraphs[c]->SetMarkerSize(0.2);
1181 overlapRegraphs[c]->Add(realfitgraphs[c],
"cp");
1183 imagfitgraphs.push_back(
new TGraph(nbins));
1184 name=(
"Im_fit_");name.append(wl[iw]);
1185 name.append(
"---");name.append(wl[iw2]);
1186 imagfitgraphs[c]->SetName(name.c_str());
1187 imagfitgraphs[c]->SetTitle(name.c_str());
1188 imagfitgraphs[c]->SetLineColor(kRed);
1190 imagfitgraphs[c]->SetMarkerColor(kRed);
1191 imagfitgraphs[c]->SetDrawOption(
"AP");
1192 imagfitgraphs[c]->SetMarkerStyle(24);
1193 imagfitgraphs[c]->SetMarkerSize(0.2);
1194 overlapImgraphs[c]->Add(imagfitgraphs[c],
"cp");
1200 std::vector<TGraph2D*> phase2d;
1202 for(
unsigned int iw=0; iw<wl.size();++iw){
1203 for(
unsigned int iw2=iw+1; iw2<wl.size();++iw2){
1204 phase2d.push_back(
new TGraph2D(nbins));
1205 string name(
"dPhi_2d_");name.append(wl[iw]);
1206 name.append(
"---");name.append(wl[iw2]);
1207 phase2d[c]->SetName(name.c_str());
1208 phase2d[c]->SetTitle(name.c_str());
1209 phase2d[c]->SetLineColor(kRed);
1210 phase2d[c]->SetMarkerColor(kRed);
1223 tree->SetBranchAddress(valBranchName.c_str(),&
rho);
1224 vector<double> prevps(wl.size());
1226 vector<double> prevphase(wl.size());
1229 for(
unsigned int i=0;
i<ndatabins;++
i){
1236 for(
unsigned int iw=0; iw<wl.size();++iw){
1242 datagraphs[iw]->SetPoint(
i,mScaled,rho->
intensity(wl[iw].c_str()));
1243 datagraphs[iw]->SetPointError(
i,binwidth,rho->
intensityErr(wl[iw].c_str()));
1244 fitgraphs[iw]->SetPoint(
i,mScaled,compset.
intensity(wl[iw],m));
1245 double absphase=compset.
phase(wl[iw],m)*TMath::RadToDeg();
1247 double absp=absphase+360;
1248 double absm=absphase-360;
1249 if(fabs(absphase-prevphase[iw])>fabs(absp-prevphase[iw])){
1252 else if(fabs(absphase-prevphase[iw])>fabs(absm-prevphase[iw])){
1256 prevphase[iw]=absphase;
1257 absphasegraphs[iw]->SetPoint(
i,mScaled,absphase);
1259 double maxIntens=-10000000;
1260 double minIntens=10000000;
1261 for(
unsigned int iSys=0;iSys<sysTrees.size();++iSys){
1264 if(iSys==0)rhoSys=
rho;
1266 sysTrees[iSys]->SetBranchAddress(valBranchName.c_str(),&rhoSys);
1267 sysTrees[iSys]->GetEntry(
i);
1270 string mywave1=wl[iw];
1273 if(mywave1==
"1-1++0+pi-_01_rho1700=pi-+_10_pi1300=pi+-_00_sigma.amp" && iSys>0)mywave1=
"1-1++0+pi-_01_eta11600=pi-+_10_pi1300=pi+-_00_sigma.amp";
1280 double myI=rhoSys->
intensity(mywave1.c_str());
1281 if(maxIntens<myI)maxIntens=myI;
1282 if(minIntens>myI)minIntens=myI;
1283 if(iSys>0)
delete rhoSys;
1286 intenssysgraphs[iw]->SetPoint(
i,mScaled,(maxIntens+minIntens)*0.5);
1287 intenssysgraphs[iw]->SetPointError(
i,binwidth,(maxIntens-minIntens)*0.5);
1293 unsigned int wi1=rho->
waveIndex(wl[iw].c_str());
1295 for(
unsigned int iw2=iw+1; iw2<wl.size();++iw2){
1298 unsigned int wi2=rho->
waveIndex(wl[iw2].c_str());
1302 realdatagraphs[c]->SetPoint(
i,
1305 realdatagraphs[c]->SetPointError(
i,
1308 imagdatagraphs[c]->SetPoint(
i,
1312 imagdatagraphs[c]->SetPointError(
i,
1317 double dataphi=rho->
phase(wl[iw].c_str(),wl[iw2].c_str());
1319 phasedatagraphs[c]->SetPoint(
i,mScaled,dataphi);
1321 TVector2 v;v.SetMagPhi(1,rho->
phase(wl[iw].c_str(),
1322 wl[iw2].c_str())/TMath::RadToDeg());
1323 phase2d[c]->SetPoint(
i,v.X(),v.Y(),mScaled);
1325 phasedatagraphs[c]->SetPointError(
i,binwidth,
1328 double fitphase=compset.
phase(wl[iw],wl[iw2],m)*TMath::RadToDeg();
1333 double maxPhase=-10000;
1334 double minPhase=10000;
1335 double maxRe=-10000000;
1336 double minRe=10000000;
1337 double maxIm=-10000000;
1338 double minIm=10000000;
1340 for(
unsigned int iSys=0;iSys<sysTrees.size();++iSys){
1344 if(iSys==0)rhoSys=
rho;
1346 sysTrees[iSys]->SetBranchAddress(valBranchName.c_str(),&rhoSys);
1347 if(
i<sysTrees[iSys]->GetEntries()) sysTrees[iSys]->GetEntry(
i);
1354 string mywave1=wl[iw];
1355 string mywave2=wl[iw2];
1357 if(mywave1==
"1-1++0+pi-_01_rho1700=pi-+_10_pi1300=pi+-_00_sigma.amp" && iSys>0)mywave1=
"1-1++0+pi-_01_eta11600=pi-+_10_pi1300=pi+-_00_sigma.amp";
1358 if(mywave2==
"1-1++0+pi-_01_rho1700=pi-+_10_pi1300=pi+-_00_sigma.amp" && iSys>0)mywave2=
"1-1++0+pi-_01_eta11600=pi-+_10_pi1300=pi+-_00_sigma.amp";
1361 if(rhoSys==NULL || rhoSys->
waveIndex(mywave1.c_str())==-1 || rhoSys->
waveIndex(mywave2.c_str()) ==-1){
1366 unsigned int wi1Sys=rhoSys->
waveIndex(mywave1.c_str());
1367 unsigned int wi2Sys=rhoSys->
waveIndex(mywave2.c_str());
1369 double myphi=rhoSys->
phase(mywave1.c_str(),mywave2.c_str());
1370 double myphiplus=myphi+360;
1371 double myphiminus=myphi-360;
1373 if(fabs(myphiplus-dataphi)<fabs(myphi-dataphi)){
1377 if(fabs(myphiminus-dataphi)<fabs(myphi-dataphi)){
1382 if(myphi>maxPhase)maxPhase=myphi;
1383 if(myphi<minPhase)minPhase=myphi;
1387 if(maxRe<r.real())maxRe=r.real();
1388 if(minRe>r.real())minRe=r.real();
1389 if(maxIm<r.imag())maxIm=r.imag();
1390 if(minIm>r.imag())minIm=r.imag();
1391 if(iSys>0)
delete rhoSys;
1396 phasesysgraphs[c]->SetPoint(
i,mScaled,(maxPhase+minPhase)*0.5);
1397 phasesysgraphs[c]->SetPointError(
i,binwidth,(maxPhase-minPhase)*0.5);
1399 realsysgraphs[c]->SetPoint(
i,mScaled,(maxRe+minRe)*0.5);
1400 realsysgraphs[c]->SetPointError(
i,binwidth,(maxRe-minRe)*0.5);
1401 imagsysgraphs[c]->SetPoint(
i,mScaled,(maxIm+minIm)*0.5);
1402 imagsysgraphs[c]->SetPointError(
i,binwidth,(maxIm-minIm)*0.5);
1408 phasefitgraphs[c]->SetPoint(
i,mScaled,fitphase);
1410 complex<double> fitval=compset.
overlap(wl[iw],wl[iw2],m);
1412 realfitgraphs[c]->SetPoint(
i,mScaled,fitval.real());
1413 imagfitgraphs[c]->SetPoint(
i,mScaled,fitval.imag());
1425 unsigned int compcount=0;
1426 for(
unsigned int ic=0;
ic<compset.
n();++
ic){
1428 std::map<std::string,pwachannel >::const_iterator it=c->
channels().begin();
1430 double I=norm(c->
val(m)*it->second.C())*it->second.ps(m)*compset.
ps(m);
1431 compgraphs[compcount]->SetPoint(
i,mScaled,I);
1437 cerr <<
"Finished plotting mass-bin " << m << endl;
1440 cerr <<
"Finished Loop Over DataBins" << endl;
1458 TFile* outfile=TFile::Open(outFileName.c_str(),
"RECREATE");
1459 for(
unsigned int iw=0; iw<wl.size();++iw){
1460 TGraph* g=(TGraph*)graphs[iw]->GetListOfGraphs()->At(3);
1461 for(
unsigned int ib=0;ib<nbins;++ib){
1462 double m,
ps;g->GetPoint(ib,m,ps);
1463 g->SetPoint(ib,m,ps*500.);
1466 graphs[iw]->Write();
1471 for(
unsigned int iw=0; iw<phasegraphs.size();++iw){
1475 unsigned int refbin=6;
1478 phasedatagraphs[iw]->GetPoint(refbin,m,predph);
1480 phasefitgraphs[iw]->GetPoint(refbin,m,prefph);
1481 for(
unsigned int ib=refbin+1;ib<nbins;++ib){
1482 double dph; phasedatagraphs[iw]->GetPoint(ib,m,dph);
1483 double fph; phasefitgraphs[iw]->GetPoint(ib,m,fph);
1484 double dp,dm;dp=dph+360;dm=dph-360;
1485 double fp,fm;fp=fph+360;fm=fph-360;
1487 if(fabs(fp-prefph)<fabs(fph-prefph) && fabs(fp-prefph)<fabs(fm-prefph))
1488 phasefitgraphs[iw]->SetPoint(ib,m,fp);
1489 else if(fabs(fm-prefph)<fabs(fph-prefph) && fabs(fm-prefph)<fabs(fp-prefph))
1490 phasefitgraphs[iw]->SetPoint(ib,m,fm);
1491 phasefitgraphs[iw]->GetPoint(ib,m,prefph);
1493 if(fabs(dp-prefph)<fabs(dph-prefph) && fabs(dp-prefph)<fabs(dm-prefph))
1494 phasedatagraphs[iw]->SetPoint(ib,m,dp);
1495 else if(fabs(dm-prefph)<fabs(dph-prefph) && fabs(dm-prefph)<fabs(dp-prefph))
1496 phasedatagraphs[iw]->SetPoint(ib,m,dm);
1500 phasedatagraphs[iw]->GetPoint(ib,m,predph);
1505 double sph; phasesysgraphs[iw]->GetPoint(ib,m,sph);
1506 double sp,sm;sp=sph+360;sm=sph-360;
1507 if(fabs(sp-prefph)<fabs(sph-prefph) && fabs(sp-prefph)<fabs(sm-prefph))
1508 phasesysgraphs[iw]->SetPoint(ib,m,sp);
1509 else if(fabs(sm-prefph)<fabs(sph-prefph) && fabs(sm-prefph)<fabs(sp-prefph))
1510 phasesysgraphs[iw]->SetPoint(ib,m,sm);
1516 phasedatagraphs[iw]->GetPoint(refbin,m,predph);
1517 phasefitgraphs[iw]->GetPoint(refbin,m,prefph);
1518 for(
unsigned int i=0;
i<refbin;++
i){
1519 unsigned int ib=refbin-
i-1;
1520 double dph; phasedatagraphs[iw]->GetPoint(ib,m,dph);
1521 double fph; phasefitgraphs[iw]->GetPoint(ib,m,fph);
1522 double dp,dm;dp=dph+360;dm=dph-360;
1523 double fp,fm;fp=fph+360;fm=fph-360;
1526 if(fabs(fp-prefph)<fabs(fph-prefph) && fabs(fp-prefph)<fabs(fm-prefph)){
1527 phasefitgraphs[iw]->SetPoint(ib,m,fp);
1530 else if(fabs(fm-prefph)<fabs(fph-prefph) && fabs(fm-prefph)<fabs(fp-prefph)){
1531 phasefitgraphs[iw]->SetPoint(ib,m,fm);
1535 phasefitgraphs[iw]->GetPoint(ib,m,prefph);
1539 if(fabs(dp-prefph)<fabs(dph-prefph) && fabs(dp-prefph)<fabs(dm-prefph)){
1540 phasedatagraphs[iw]->SetPoint(ib,m,dp);
1543 else if(fabs(dm-prefph)<fabs(dph-prefph) && fabs(dm-prefph)<fabs(dp-prefph)){
1544 phasedatagraphs[iw]->SetPoint(ib,m,dm);
1547 phasedatagraphs[iw]->GetPoint(ib,m,predph);
1551 double sph; phasesysgraphs[iw]->GetPoint(ib,m,sph);
1552 double sp,sm;sp=sph+360;sm=sph-360;
1553 if(fabs(sp-predph)<fabs(sph-predph) && fabs(sp-predph)<fabs(sm-predph))
1554 phasesysgraphs[iw]->SetPoint(ib,m,sp);
1555 else if(fabs(sm-predph)<fabs(sph-predph) && fabs(sm-predph)<fabs(sp-predph))
1556 phasesysgraphs[iw]->SetPoint(ib,m,sm);
1563 phasegraphs[iw]->Write();
1564 phasesysgraphs[iw]->Write();
1565 overlapRegraphs[iw]->Write();
1566 overlapImgraphs[iw]->Write();