7 #include <TMatrixDfwd.h> 9 #include <TMatrixTSym.h> 17 #include <TGraphErrors.h> 23 #include <TGraph2DErrors.h> 38 std::map < std::string, std::vector<double> >
read_input_table2(std::string filename,
int ncol ) {
39 std::map < std::string, std::vector<double> > ret;
40 std::vector<std::string> cols;
42 std::ifstream istrm(filename.c_str(), std::ios::binary);
43 if (!istrm.is_open()) {
44 std::cout <<
"failed to open " << filename << std::endl;
47 for (
int c=0 ; c<ncol ; c++ ) {
50 ret[colname] = vector<double>();
51 cols.push_back(colname);
53 while ( istrm.good()) {
55 for (
int c=0 ; c<ncol ; c++ ) {
57 if ( !istrm.good() )
break;
58 std::string colname = cols[c];
59 ret[colname].push_back(value);
62 cout<<
"Info. [read_input_table] Read "<<ret.size()<<
" rows."<<endl;
75 TGraphErrors*
MakeTGraph(
const Eigen::VectorXd& xvalues,
int ibin,
const Eigen::MatrixXd& Y,
76 const std::map<std::string,Eigen::MatrixXd >& VSysY = {}
79 TGraphErrors* graph =
new TGraphErrors();
80 for (
int i = 0 ; i<xvalues.size() ; i++ ) {
81 double yvalue = Y(ibin,i);
82 graph->SetPoint(i,xvalues(i),yvalue);
84 for (
auto [name,Vy] : VSysY ) {
85 ey2 += pow(Vy(ibin,i),2);
87 graph->SetPointError(i,0,sqrt(ey2));
100 TGraph2DErrors*
MakeTGraph2D(
const Eigen::VectorXd& xvalues,
const Eigen::VectorXd& yvalues,
101 int ibin,
const Eigen::MatrixXd& Y,
102 const std::map<std::string,Eigen::MatrixXd >& VSysY = {}
105 TGraph2DErrors* graph =
new TGraph2DErrors();
106 for (
int i = 0 ; i<xvalues.size() ; i++ ) {
107 double zvalue = Y(ibin,i);
108 graph->SetPoint(i,xvalues(i),yvalues(i),zvalue);
110 for (
auto [name,Vy] : VSysY ) {
111 ey2 += pow(Vy(ibin,i),2);
113 graph->SetPointError(i,0,0,sqrt(ey2));
127 TH1D*
MakeHistogram(
int nEvents,
int seed,
double mean,
double sigma, vector<double> bins ) {
130 TH1D* hist =
new TH1D(
"hist",
"hist",bins.size()-1, &bins[0]);
132 for (
int i=0 ; i<nEvents; i++ ) {
133 hist->Fill( rn.Gaus(mean,sigma), 1 );
148 TH1D*
MakeHistogram(
const Eigen::VectorXd& values, vector<double> bins ={},
const std::vector<std::pair<std::string,Eigen::MatrixXd > >& V = {} ) {
149 TH1D* hist = bins.empty() ?
150 new TH1D(
"hist",
"hist",values.size(),0,values.size() ) :
151 new TH1D(
"hist",
"hist",bins.size()-1, &bins[0]);
152 if ( bins.size() && values.size() != bins.size()-1 ) {cout<<
"ERROR! binning and number of entries does not fit!"<<endl;exit(1);}
153 for (
size_t i = 0 ;i<bins.size()-1; i++ ) {
154 hist->SetBinContent(i+1, values(i));
157 for (
auto apair : V ) {
158 e2 += apair.second(i,i);
160 hist->SetBinError(i+1, sqrt(e2) );
178 const string& yaxistitle =
"value [unit]",
179 const string& referencename =
"Reference value (#alpha) [unit]",
180 const string& observablename =
"Observable [unit]" 182 gStyle->SetOptStat(0);
183 gSystem->mkdir(
"plots");
187 if ( M.cols() != 2 ) {cout<<
"Error! only 1-dim plotting implemented."<<endl;exit(1);}
188 Eigen::VectorXd reference_values = M.col(1);
191 map<double,TH1D*> templates;
192 for (
int iref = 0 ; iref<reference_values.size() ; iref++ ) {
194 templates[iref] = MakeHistogram(fit.
Y.col(iref),bins);
197 TH1D* data = MakeHistogram(fit.
Dt,bins,fit.
Vs);
198 TH1D* TheoFit = MakeHistogram(fit.
TheoFit,bins);
200 TCanvas c1(
"c1",
"LTF plots",800,800);
201 c1.SetRightMargin(0.05);
202 c1.SetLeftMargin(0.15);
203 c1.SetTopMargin(0.08);
209 c1.Print( (
string(ps_name)+
"[").c_str() );
214 for (
int iref = 0 ; iref<reference_values.size() ; iref++ ) {
215 templates[iref]->SetLineWidth(2);
217 templates[0]->SetTitle((
"Linear Template Fit;"+observablename+
";"+yaxistitle).c_str());
218 templates[0]->SetLineColor(kRed+1);
219 if ( templates[0]->GetMaximum()>0 )templates[0]->SetMinimum(0);
221 templates[0]->SetMaximum(templates[0]->GetMaximum()*1.7);
224 templates[0]->SetLineWidth(3);
225 templates[0]->DrawClone(
"hist");
227 else if ( iref==reference_values.size()-1) {
228 if ( templates[0]->GetMaximum()>0 ) templates[iref]->SetFillColorAlpha(kBlue,0.15);
229 templates[iref]->SetLineColor(kBlue+2);
230 templates[iref]->SetLineWidth(3);
231 templates[iref]->Draw(
"histsame");
234 templates[iref]->SetLineColor(iref+2);
235 templates[iref]->SetLineWidth(2);
236 templates[iref]->Draw(
"histsame");
239 if ( templates[0]->GetMaximum()>0 )templates[0]->SetFillColorAlpha(kRed,0.15);
240 templates[0]->Draw(
"histsame");
242 data->SetMarkerStyle(20);
243 data->SetMarkerSize(1.4);
244 data->SetLineColor(kBlack);
245 data->Draw(
"e0same");
247 TheoFit->SetLineColor(923);
248 TheoFit->SetLineWidth(4);
249 TheoFit->SetLineStyle(2);
250 TheoFit->Draw(
"histsame");
252 TLegend legend(0.18,0.70,0.94,0.92,
"",
"NDC");
253 legend.SetNColumns(3);
254 legend.SetFillStyle(0);
255 legend.SetBorderSize(0);
256 legend.AddEntry(data,
"Data",
"E0P");
257 for (
int iref = 0 ; iref<reference_values.size() ; iref++ ) {
258 legend.AddEntry(templates[iref],Form(
"Template #alpha=%6.2f",reference_values[iref]),
"FL");
260 legend.AddEntry(TheoFit,
"Estimated best model",
"L");
264 c1.Print(
"plots/LTF_plot.pdf");
271 c1.SetRightMargin(0.02);
272 c1.SetTopMargin(0.02);
273 c1.SetLeftMargin(0.16);
274 c1.SetBottomMargin(0.16);
278 gStyle->SetLabelSize(0.05,
"XYZ");
279 gStyle->SetTitleSize(0.05,
"XYZ");
280 gStyle->SetTitleOffset(1.1,
"X");
281 gStyle->SetTitleOffset(1.6,
"Y");
282 gStyle->SetMarkerSize(2);
285 map < string, vector<double> > input_table = read_input_table2(
"data/CMS_data.txt",32);
287 for (
int ibin = 0 ; ibin<fit.
Dt.size() ; ibin++ ) {
291 TGraphErrors* gdata =
new TGraphErrors();
292 gdata->SetPoint(0,fit.
ahat(0),fit.
Dt(ibin));
293 gdata->SetPointError(0,0,data->GetBinError(ibin+1));
294 gdata->SetMarkerStyle(20);
296 TGraphErrors* graph = MakeTGraph(fit.
M.col(1),ibin,fit.
Y,fit.
SysY);
297 graph->Fit(
"pol1",
"Q");
298 TF1* pol1w = (TF1*)graph->GetFunction(
"pol1")->Clone(
"pol1w");
299 pol1w->SetLineColor(922);
300 pol1w->SetLineStyle(3);
301 pol1w->SetLineWidth(2);
303 TF1* f2=
new TF1(
"f2",
"[0]+[1]*pow(x,2)", -FLT_MIN,FLT_MAX );
305 TF1* f1=
new TF1(
"f1",
"[0]+[1]*pow(x,[2])", -FLT_MIN,FLT_MAX );
308 graph->Fit(
"pol1",
"QW");
309 bool UseLTFOutput =
true;
310 if ( UseLTFOutput ) {
311 Eigen::VectorXd ltfpol1param =(fit.
Y*fit.
Mc().transpose()).row(ibin);
313 graph->GetFunction(
"pol1")->SetParameter(0,ltfpol1param(0));
314 graph->GetFunction(
"pol1")->SetParameter(1,ltfpol1param(1));
315 f1->SetParameter(0,ltfpol1param(0));
316 f1->SetParameter(1,ltfpol1param(1));
317 f1->SetParameter(2,fit.
Gamma[0]);
319 if ( fit.
Gamma[0]!=1 ) cout<<
"Warning! Plotting with gamma factor !=1 not correctly implmeneted!"<<endl;
321 graph->GetFunction(
"pol1")->SetLineWidth(3);
323 graph->Fit(
"pol2",
"QW");
324 graph->GetFunction(
"pol2")->SetLineWidth(83);
326 graph->SetMarkerStyle(47);
327 graph->SetMarkerColor(kRed+2);
328 graph->SetLineColor(kRed+2);
330 graph->SetTitle((
";"+referencename+
";log("+yaxistitle+
")").c_str());
332 graph->SetTitle((
";"+referencename+
";"+yaxistitle).c_str());
338 f1log =
new TF1(
"pol1log",
"log([0]+[1]*pow(x,1))", -FLT_MIN,FLT_MAX );
340 TGraph* gexp =
new TGraph();
341 for (
int i = 0 ; i<graph->GetN() ; i++ )
342 gexp->SetPoint(i,graph->GetX()[i], exp(graph->GetY()[i]));
343 gexp->Fit(
"pol1",
"QW");
345 Eigen::VectorXd ltfpol1param =(fit.
Y*fit.
Mc().transpose()).row(ibin);
346 graph->GetFunction(
"pol1")->SetParameter(0,ltfpol1param(0));
348 f1log->SetParameter(0, gexp->GetFunction(
"pol1")->GetParameter(0));
349 f1log->SetParameter(1, gexp->GetFunction(
"pol1")->GetParameter(1));
350 if ( fit.
Gamma[0]!=1 ) cout<<
"Warning! Plotting with gamma factor !=1 not correctly implmeneted!"<<endl;
354 f1log->SetLineColor(kBlue+1);
355 f1log->SetLineStyle(7);
356 f1log->SetLineWidth(2);
360 if ( gdata->GetY()[0] > 0 )
361 graph->SetMinimum(0);
363 graph->SetMaximum( max(gdata->GetY()[0],max(graph->GetY()[0],graph->GetY()[graph->GetN()-1]))*1.2);
367 f1log->Draw(
"Lsame");
369 pol1w->Draw(
"Lsame");
371 if ( reference_values.size()+1<= 6 )
372 graph->GetHistogram()->GetXaxis()->SetNdivisions(graph->GetN()+1);
374 graph->GetHistogram()->GetXaxis()->SetNdivisions(
int(graph->GetN()/2)+1+200);
381 TLegend legend(xmin,0.19,0.96,0.47,
"",
"NDC");
383 legend.SetFillStyle(0);
384 legend.SetBorderSize(0);
385 legend.SetTextSize(0.05);
386 legend.AddEntry(data,
"Data",
"E0P");
387 legend.AddEntry(graph,
"Templates",
"PE0");
389 legend.AddEntry(graph->GetFunction(
"pol1"),
"Linear log(model)",
"L");
390 legend.AddEntry(f1log,
"#scale[0.9]{Linearized model #scale[0.7]{(unused)}}",
"L");
393 legend.AddEntry(graph->GetFunction(
"pol1"),
"Linearized model",
"L");
394 legend.AddEntry(pol1w,
"Weighted fit #scale[0.7]{(unused)}",
"L");
401 text.SetTextFont(42);
402 text.SetTextAlign(11);
403 text.SetTextSize(0.05);
410 text.SetTextSize(0.04);
411 text.DrawLatex(0.20,0.93,Form(
"%3.1f_{ }<_{ }|y|_{ }<_{ }%3.1f",input_table[
"ylow"][ibin],input_table[
"yhigh"][ibin]));
412 text.DrawLatex(0.20,0.88,Form(
"%3.0f_{ }<_{ }p_{T}_{ }<_{ }%3.0f_{ }GeV",input_table[
"ptlow"][ibin],input_table[
"pthigh"][ibin]));
414 cout<<input_table[
"ylow"][ibin]<<
"\t" 415 <<input_table[
"yhigh"][ibin]<<
"\t" 416 <<input_table[
"ptlow"][ibin]<<
"\t" 417 <<input_table[
"pthigh"][ibin]<<endl;
421 c1.Print( Form(
"plots/LTFlog_bin_%02d.pdf",ibin));
423 c1.Print( Form(
"plots/LTF_bin_%02d.pdf",ibin));
431 TGraph* gChi2 =
new TGraph();
432 int ndf = (fit.
Dt.rows()-(fit.
M.cols()-1));
433 for (
int itmpl = 0 ; itmpl<fit.
chisq_y.size() ; itmpl++ ) {
434 gChi2->SetPoint(itmpl, reference_values[itmpl], fit.
chisq_y(itmpl)/ndf);
436 gChi2->Fit(
"pol2",
"QW");
437 gChi2->SetMarkerStyle(20);
439 TGraph* gChi2LTF =
new TGraph();
440 gChi2LTF->SetPoint(0, fit.
ahat(0), fit.
chisq/ndf);
441 gChi2LTF->SetMarkerStyle(29);
442 gChi2LTF->SetMarkerSize(3.1);
443 gChi2LTF->SetMarkerColor(kViolet+2);
445 TGraph* gChi2chk =
new TGraph();
447 gChi2chk->SetMarkerSize(2.2);
448 gChi2chk->SetMarkerStyle(24);
449 gChi2chk->SetMarkerColor(kRed);
454 gChi2->SetTitle((
";"+referencename+
";#chi^{2}/ndf").c_str());
455 gChi2->SetMinimum(0.75);
456 gChi2->SetMaximum(1.2);
458 if ( reference_values.size()+1<= 6 )
459 gChi2->GetHistogram()->SetNdivisions(reference_values.size()+1+500,
"X");
461 gChi2->GetHistogram()->SetNdivisions(
int(reference_values.size()/2)+1+500,
"X");
464 line.SetLineColor(920);
465 line.SetLineStyle(3);
467 gChi2->GetHistogram()->GetXaxis()->GetXmin(),1.,
468 gChi2->GetHistogram()->GetXaxis()->GetXmax(), 1);
474 gChi2chk->Draw(
"Psame");
475 gChi2LTF->Draw(
"Psame");
478 TLegend legend(0.18,0.70,0.66,0.97,
"",
"NDC");
480 legend.SetFillStyle(0);
481 legend.SetBorderSize(0);
482 legend.SetTextSize(0.045);
483 legend.AddEntry(gChi2LTF,
"#hat#chi^{2} of the linear template fit",
"P");
484 legend.AddEntry(gChi2,
"#chi^{2}_{#font[12]{j}} of the individual templates",
"P");
485 legend.AddEntry(gChi2->GetFunction(
"pol2"),
"Parabola",
"L");
486 legend.AddEntry(gChi2chk,
"Minimum of #chi^{2} parabola #scale[0.8]{(#check#chi^{2})}",
"P");
491 c1.Print(
"plots/LTF_chi2.pdf");
493 c1.Print( (
string(ps_name)+
"]").c_str() );
510 if ( M.cols() != 3 ) {cout<<
"Error! only 2-dim plotting implemented."<<endl;exit(1);}
511 Eigen::VectorXd reference_values1 = M.col(1);
512 Eigen::VectorXd reference_values2 = M.col(2);
514 map<double,TH1D*> templates;
516 for (
int iref = 0 ; iref<reference_values1.size() ; iref++ ) {
518 templates[iref] = MakeHistogram(fit.
Y.col(iref),bins);
519 r1.insert(reference_values1(iref));
520 r2.insert(reference_values2(iref));
523 if ( r1.size()<=1 ) {
524 cout<<
"ERROR! at least two distinct reference points for dimension 1 must be given"<<endl;
527 if ( r2.size()<=1 ) {
528 cout<<
"ERROR! at least two distinct reference points for dimension 2 must be given"<<endl;
532 double xmin = 2.* (*r1.begin()) - (*(++r1.begin()))*0.9999;
533 double xmax = 2.* (*r1.rbegin()) - (*(++r1.rbegin()))*1.00001;
534 double ymin = 2.* (*r2.begin()) - (*(++r2.begin()))*0.9999;
535 double ymax = 2.* (*r2.rbegin()) - (*(++r2.rbegin()))*1.00001;
537 TH1D* data = MakeHistogram(fit.
Dt,bins,fit.
Vs);
538 TH1D* TheoFit = MakeHistogram(fit.
TheoFit,bins);
540 TCanvas c1(
"c1",
"LTF plots",800,800);
541 c1.SetRightMargin(0.05);
542 c1.SetLeftMargin(0.15);
543 c1.SetTopMargin(0.08);
546 const char* ps_name =
"LTF2D_plots.ps";
547 c1.Print( (
string(ps_name)+
"[").c_str() );
552 for (
int iref = 0 ; iref<reference_values1.size() ; iref++ ) {
553 templates[iref]->SetLineWidth(2);
555 templates[0]->SetTitle(
"Linear Template Fit;Observable [unit]; Value [unit]");
556 templates[0]->SetLineColor(kRed+2);
557 templates[0]->SetMinimum(0);
558 templates[0]->SetMaximum(templates[0]->GetMaximum()*1.7);
559 templates[0]->SetLineWidth(3);
560 templates[0]->DrawClone(
"hist");
562 else if ( iref==reference_values1.size()-1) {
563 templates[iref]->SetFillColorAlpha(kBlue,0.15);
564 templates[iref]->SetLineColor(kBlue+2);
565 templates[iref]->SetLineWidth(3);
566 templates[iref]->Draw(
"histsame");
570 if (color >= 10 ) color=(color-10)*2+28;
571 templates[iref]->SetLineColor(color);
573 templates[iref]->Draw(
"histsame");
576 templates[0]->SetFillColorAlpha(kRed,0.15);
577 templates[0]->Draw(
"histsame");
579 data->SetMarkerStyle(20);
580 data->SetMarkerSize(1.4);
581 data->SetLineColor(kBlack);
582 data->Draw(
"e0same");
584 TheoFit->SetLineColor(923);
585 TheoFit->SetLineWidth(4);
586 TheoFit->SetLineStyle(2);
587 TheoFit->Draw(
"histsame");
589 TLegend legend(0.18,0.70,0.94,0.92,
"",
"NDC");
590 legend.SetNColumns(3);
591 legend.SetFillStyle(0);
592 legend.SetBorderSize(0);
593 legend.AddEntry(data,
"Data",
"E0P");
594 for (
int iref = 0 ; iref<reference_values1.size() ; iref++ ) {
595 legend.AddEntry(templates[iref],Form(
"Tpl. #alpha_{0}=%5.1f, #alpha_{1}=%3.1f",reference_values1[iref],reference_values2[iref]),
"FL");
597 legend.AddEntry(TheoFit,
"Estimated best model",
"L");
601 c1.Print(
"plots/LTF2D_plot.pdf");
608 c1.SetRightMargin(0.02);
609 c1.SetTopMargin(0.02);
611 c1.SetLeftMargin(0.12);
612 c1.SetBottomMargin(0.12);
614 for (
int ibin = 0 ; ibin<fit.
Dt.size() ; ibin++ ) {
616 TGraph2DErrors* gdata =
new TGraph2DErrors();
617 gdata->SetPoint(0, fit.
ahat(0), fit.
ahat(1), fit.
Dt(ibin));
618 gdata->SetPointError(0,0,0,data->GetBinError(ibin+1));
619 gdata->SetMarkerStyle(20);
620 gdata->SetMarkerSize(2);
623 TGraph2DErrors* graph = MakeTGraph2D(fit.
M.col(1),fit.
M.col(2),ibin,fit.
Y,fit.
SysY);
624 TF2* f2 =
new TF2(Form(
"Linear Template Fit (2-dim., bin %d)",ibin),
"[0]+[1]*x+[2]*y",
631 TGraph2D* gtheo =
new TGraph2D();
632 gtheo->SetPoint(0, fit.
ahat(0), fit.
ahat(1), f2->Eval(fit.
ahat(0), fit.
ahat(1)));
633 gtheo->SetMarkerStyle(20);
634 gtheo->SetMarkerSize(0.4);
635 gtheo->SetMarkerColor(kBlack);
636 for (
int it = 0 ; it<fit.
M.col(1).size(); it++ ) {
637 gtheo->SetPoint(it+1, reference_values1(it), reference_values2(it),
638 f2->Eval(reference_values1(it), reference_values2(it)));
641 f2->SetLineColor(922);
646 f2->GetHistogram()->GetXaxis()->SetNdivisions(r1.size()+1);
647 f2->GetHistogram()->GetYaxis()->SetNdivisions(r2.size()+1);
648 f2->GetHistogram()->GetXaxis()->SetTitleOffset(2.2);
649 f2->GetHistogram()->GetYaxis()->SetTitleOffset(2.2);
650 f2->GetHistogram()->GetZaxis()->SetTitleOffset(1.8);
651 f2->GetHistogram()->SetTitle(
";Reference value 0 (#alpha_{0}) [unit] ;Reference value 1 (#alpha_{1}) [unit];Value [unit]");
653 graph->SetMarkerStyle(25);
655 graph->SetMarkerColor(kRed+2);
656 graph->SetLineColor(kRed+2);
657 graph->SetTitle(
";Reference value (#alpha) [unit];Value [unit]");
667 gtheo->Draw(
"P0 same");
668 graph->Draw(
"err p0 same");
669 gdata->Draw(
"err P0 same");
672 TF2* f2leg = (TF2*)f2->Clone(
"f2leg");
673 f2leg->SetLineWidth(3);
674 gtheo->SetMarkerStyle(24);
675 gtheo->SetMarkerSize(0.4);
676 gdata->SetMarkerStyle(24);
677 graph->SetMarkerStyle(24);
679 TLegend legend(0.42,0.18,0.80,0.43,
"",
"NDC");
681 legend.SetFillStyle(0);
682 legend.SetBorderSize(0);
683 legend.SetTextSize(0.03);
684 legend.AddEntry(graph,
"Templates",
"PE0");
685 legend.AddEntry(f2leg,
"Linearized model",
"L");
686 legend.AddEntry(gtheo,
"Projections onto model",
"P");
687 legend.AddEntry(gdata,
"Data",
"E0P");
693 text.SetTextFont(42);
694 text.SetTextAlign(13);
695 text.SetTextSize(0.05);
697 text.DrawLatex(0.02,0.97,Form(
"Bin %d",ibin));
700 c1.Print( Form(
"plots/LTF2D_bin_%02d.pdf",ibin));
704 c1.Print( (
string(ps_name)+
"]").c_str() );
723 const string& yaxistitle =
"value [unit]",
724 const string& referencename =
"Reference value (#alpha) [unit]",
725 const string& observablename =
"Observable [unit]" 727 gStyle->SetOptStat(0);
728 gSystem->mkdir(
"plots");
732 if ( M.cols() != 2 ) {cout<<
"Error! only 1-dim plotting implemented."<<endl;exit(1);}
733 Eigen::VectorXd reference_values = M.col(1);
736 map<double,TH1D*> templates;
737 for (
int iref = 0 ; iref<reference_values.size() ; iref++ ) {
739 templates[iref] = MakeHistogram(fit.
Y.col(iref),bins);
742 TH1D* data = MakeHistogram(fit.
Dt,bins,fit.
Vs);
743 TH1D* TheoFit = MakeHistogram(fit.
TheoFit,bins);
745 TCanvas c1(
"c1",
"LTF plots",800,800);
746 c1.SetRightMargin(0.05);
747 c1.SetLeftMargin(0.15);
748 c1.SetTopMargin(0.08);
754 c1.Print( (
string(ps_name)+
"[").c_str() );
759 for (
int iref = 0 ; iref<reference_values.size() ; iref++ ) {
760 templates[iref]->SetLineWidth(2);
762 templates[0]->SetTitle((
"Linear Template Fit;"+observablename+
";"+yaxistitle).c_str());
763 templates[0]->SetLineColor(kRed+1);
764 if ( templates[0]->GetMaximum()>0 )templates[0]->SetMinimum(0);
766 templates[0]->SetMaximum(templates[0]->GetMaximum()*1.7);
769 templates[0]->SetLineWidth(3);
770 templates[0]->DrawClone(
"hist");
772 else if ( iref==reference_values.size()-1) {
773 if ( templates[0]->GetMaximum()>0 ) templates[iref]->SetFillColorAlpha(kBlue,0.15);
774 templates[iref]->SetLineColor(kBlue+2);
775 templates[iref]->SetLineWidth(3);
776 templates[iref]->Draw(
"histsame");
779 templates[iref]->SetLineColor(iref+2);
780 templates[iref]->SetLineWidth(2);
781 templates[iref]->Draw(
"histsame");
784 if ( templates[0]->GetMaximum()>0 )templates[0]->SetFillColorAlpha(kRed,0.15);
785 templates[0]->Draw(
"histsame");
787 data->SetMarkerStyle(20);
788 data->SetMarkerSize(1.4);
789 data->SetLineColor(kBlack);
790 data->Draw(
"e0same");
792 TheoFit->SetLineColor(923);
793 TheoFit->SetLineWidth(4);
794 TheoFit->SetLineStyle(2);
795 TheoFit->Draw(
"histsame");
797 TLegend legend(0.18,0.70,0.94,0.92,
"",
"NDC");
798 legend.SetNColumns(3);
799 legend.SetFillStyle(0);
800 legend.SetBorderSize(0);
801 legend.AddEntry(data,
"Data",
"E0P");
802 for (
int iref = 0 ; iref<reference_values.size() ; iref++ ) {
803 legend.AddEntry(templates[iref],Form(
"Template #alpha=%6.2f",reference_values[iref]),
"FL");
805 legend.AddEntry(TheoFit,
"Estimated best model",
"L");
809 c1.Print(
"plots/LTF_plot.pdf");
816 c1.SetRightMargin(0.02);
817 c1.SetTopMargin(0.02);
818 c1.SetLeftMargin(0.16);
819 c1.SetBottomMargin(0.16);
823 gStyle->SetLabelSize(0.05,
"XYZ");
824 gStyle->SetTitleSize(0.05,
"XYZ");
825 gStyle->SetTitleOffset(1.1,
"X");
826 gStyle->SetTitleOffset(1.6,
"Y");
827 gStyle->SetMarkerSize(2);
830 map < string, vector<double> > input_table = read_input_table2(
"data/CMS_data.txt",32);
832 for (
int ibin = 0 ; ibin<fit.
Dt.size() ; ibin++ ) {
836 TGraphErrors* gdata =
new TGraphErrors();
837 gdata->SetPoint(0,fit.
ahat(0),fit.
Dt(ibin));
838 gdata->SetPointError(0,0,data->GetBinError(ibin+1));
839 gdata->SetMarkerStyle(20);
841 TGraphErrors* graph = MakeTGraph(fit.
M.col(1),ibin,fit.
Y,fit.
SysY);
842 graph->Fit(
"pol1",
"QW");
843 TF1* pol1 = (TF1*)graph->GetFunction(
"pol1")->Clone(
"pol1");
844 pol1->SetLineColor(kRed);
846 pol1->SetLineWidth(2);
848 TF1* f2=
new TF1(
"f2",
"[0]+[1]*pow(x,2)", -FLT_MIN,FLT_MAX );
850 TF1* f1=
new TF1(
"f1",
"[0]+[1]*pow(x,[2])", -FLT_MIN,FLT_MAX );
853 graph->Fit(
"pol1",
"QW");
854 bool UseLTFOutput =
true;
855 if ( UseLTFOutput ) {
856 Eigen::VectorXd ltfpol1param =(fit.
Y*fit.
Mc().transpose()).row(ibin);
858 graph->GetFunction(
"pol1")->SetParameter(0,ltfpol1param(0));
859 graph->GetFunction(
"pol1")->SetParameter(1,ltfpol1param(1));
860 f1->SetParameter(0,ltfpol1param(0));
861 f1->SetParameter(1,ltfpol1param(1));
862 f1->SetParameter(2,fit.
Gamma[0]);
864 if ( fit.
Gamma[0]!=1 ) cout<<
"Warning! Plotting with gamma factor !=1 not correctly implmeneted!"<<endl;
866 graph->GetFunction(
"pol1")->SetLineWidth(3);
868 graph->Fit(
"pol2",
"QW");
869 graph->GetFunction(
"pol2")->SetLineWidth(83);
871 graph->SetMarkerStyle(47);
872 graph->SetMarkerColor(kRed+2);
873 graph->SetLineColor(kRed+2);
875 graph->SetTitle((
";"+referencename+
";log("+yaxistitle+
")").c_str());
877 graph->SetTitle((
";"+referencename+
";"+yaxistitle).c_str());
883 f1log =
new TF1(
"pol1log",
"log([0]+[1]*pow(x,1))", -FLT_MIN,FLT_MAX );
885 TGraph* gexp =
new TGraph();
886 for (
int i = 0 ; i<graph->GetN() ; i++ )
887 gexp->SetPoint(i,graph->GetX()[i], exp(graph->GetY()[i]));
888 gexp->Fit(
"pol1",
"QW");
890 Eigen::VectorXd ltfpol1param =(fit.
Y*fit.
Mc().transpose()).row(ibin);
891 graph->GetFunction(
"pol1")->SetParameter(0,ltfpol1param(0));
893 f1log->SetParameter(0, gexp->GetFunction(
"pol1")->GetParameter(0));
894 f1log->SetParameter(1, gexp->GetFunction(
"pol1")->GetParameter(1));
895 if ( fit.
Gamma[0]!=1 ) cout<<
"Warning! Plotting with gamma factor !=1 not correctly implmeneted!"<<endl;
899 f1log->SetLineColor(kBlue+1);
900 f1log->SetLineStyle(7);
901 f1log->SetLineWidth(2);
905 if ( gdata->GetY()[0] > 0 )
906 graph->SetMinimum(0);
908 graph->SetMaximum( max(gdata->GetY()[0],max(graph->GetY()[0],graph->GetY()[graph->GetN()-1]))*1.2);
909 graph->Fit(
"pol2",
"QW");
910 graph->GetFunction(
"pol2")->SetLineColor(kBlue);;
912 TF1* tang =
new TF1(
"tang",
"[0]+[1]*x", -FLT_MIN,FLT_MAX );
913 double f0 = graph->GetFunction(
"pol2")->Eval(gdata->GetX()[0]);
914 double fp0 = graph->GetFunction(
"pol2")->GetParameter(1) + 2.*graph->GetFunction(
"pol2")->GetParameter(2)*gdata->GetX()[0];
915 tang->SetParameter(0, f0 - fp0*gdata->GetX()[0] );
916 tang->SetParameter(1, fp0);
917 tang->SetLineWidth(2);
918 tang->SetLineColor(kTeal+4);
919 tang->SetLineStyle(7);
921 pol1->SetLineStyle(3);
924 f1log->Draw(
"Lsame");
928 if ( reference_values.size()+1<= 8 )
929 graph->GetHistogram()->GetXaxis()->SetNdivisions(graph->GetN()+1);
931 graph->GetHistogram()->GetXaxis()->SetNdivisions(
int(graph->GetN()/2)+1+200);
940 TLegend legend(0.19,0.19,0.56,0.47,
"",
"NDC");
942 legend.SetFillStyle(0);
943 legend.SetBorderSize(0);
944 legend.SetTextSize(0.045);
945 legend.AddEntry(data,
"Data",
"E0P");
946 legend.AddEntry(graph,
"Templates",
"PE0");
948 legend.AddEntry(graph->GetFunction(
"pol1"),
"Linear log(model)",
"L");
949 legend.AddEntry(f1log,
"#scale[0.9]{Linearized model #scale[0.7]{(unused)}}",
"L");
952 legend.AddEntry(graph->GetFunction(
"pol2"),
"Second-order model",
"L");
953 legend.AddEntry(tang,
"Linear model",
"L");
954 legend.AddEntry(pol1,
"Linear Template Fit",
"L");
961 text.SetTextFont(42);
962 text.SetTextAlign(11);
963 text.SetTextSize(0.045);
966 text.SetTextAlign(31);
967 text.DrawLatex(0.955,0.20,Form(
"Bin %d",ibin));
978 cout<<input_table[
"ylow"][ibin]<<
"\t" 979 <<input_table[
"yhigh"][ibin]<<
"\t" 980 <<input_table[
"ptlow"][ibin]<<
"\t" 981 <<input_table[
"pthigh"][ibin]<<endl;
985 c1.Print( Form(
"plots/LTFlog_bin_%02d.pdf",ibin));
987 c1.Print( Form(
"plots/LTF_bin_%02d.pdf",ibin));
995 TGraph* gChi2 =
new TGraph();
996 int ndf = (fit.
Dt.rows()-(fit.
M.cols()-1));
997 for (
int itmpl = 0 ; itmpl<fit.
chisq_y.size() ; itmpl++ ) {
998 gChi2->SetPoint(itmpl, reference_values[itmpl], fit.
chisq_y(itmpl)/ndf);
1000 gChi2->Fit(
"pol2",
"QW");
1001 gChi2->SetMarkerStyle(20);
1003 TGraph* gChi2LTF =
new TGraph();
1004 gChi2LTF->SetPoint(0, fit.
ahat(0), fit.
chisq/ndf);
1005 gChi2LTF->SetMarkerStyle(29);
1006 gChi2LTF->SetMarkerSize(3.1);
1007 gChi2LTF->SetMarkerColor(kViolet+2);
1009 TGraph* gChi2chk =
new TGraph();
1011 gChi2chk->SetMarkerSize(2.2);
1012 gChi2chk->SetMarkerStyle(24);
1013 gChi2chk->SetMarkerColor(kRed);
1018 gChi2->SetTitle((
";"+referencename+
";#chi^{2}/ndf").c_str());
1019 gChi2->SetMinimum(0.);
1020 gChi2->SetMaximum(20.2);
1022 if ( reference_values.size()+1<= 8 )
1023 gChi2->GetHistogram()->SetNdivisions(reference_values.size()+1+500,
"X");
1025 gChi2->GetHistogram()->SetNdivisions(
int(reference_values.size()/2)+1+500,
"X");
1028 line.SetLineColor(920);
1029 line.SetLineStyle(3);
1031 gChi2->GetHistogram()->GetXaxis()->GetXmin(),1.,
1032 gChi2->GetHistogram()->GetXaxis()->GetXmax(), 1);
1038 gChi2chk->Draw(
"Psame");
1039 gChi2LTF->Draw(
"Psame");
1042 TLegend legend(0.18,0.75,0.56,0.97,
"",
"NDC");
1044 legend.SetFillStyle(0);
1045 legend.SetBorderSize(0);
1046 legend.SetTextSize(0.045);
1047 legend.AddEntry(gChi2LTF,
"#hat#chi^{2} of the iterative template fit",
"P");
1048 legend.AddEntry(gChi2,
"#chi^{2}_{#font[12]{j}} of the individual templates",
"PL");
1049 legend.AddEntry(gChi2->GetFunction(
"pol2"),
"Parabola",
"L");
1055 c1.Print(
"plots/LTF_chi2.pdf");
1057 c1.Print( (
string(ps_name)+
"]").c_str() );
Eigen::MatrixXd Mc(int nPow=1, int nInfrc=0) const
calculated matrix M^+ from matrix M
Definition: LTF.cxx:389
Eigen::MatrixXd Y
Matrix Y (templates)
Definition: LTF.h:83
Eigen::VectorXd Dt
data distribution
Definition: LTF.h:81
double achk_chisq
chisq_min from polynomial fit to chi2's of templates
Definition: LTF.h:123
Eigen::MatrixXd M
Matrix M (reference values)
Definition: LTF.h:82
Eigen::VectorXd achk
result from polynomial fit to chi2's of templates
Definition: LTF.h:121
bool GetLogNormal() const
return boolean if fit was performed with relative uncertainties
Definition: LTF.h:140
Eigen::VectorXd ahat
results (a0, a1, ..., epsilon1, epsilon2,...)
Definition: LTF.h:107
Small helper class to collect all results, All input parameters are set by class LTF The user can acc...
Definition: LTF.h:65
std::map< std::string, Eigen::MatrixXd > SysY
uncertainty of the templates
Definition: LTF.h:91
std::vector< std::pair< std::string, Eigen::MatrixXd > > Vs
(uncor./Cov) uncertainties
Definition: LTF.h:86
Eigen::VectorXd chisq_y
chi^2 for each template
Definition: LTF.h:105
Eigen::VectorXd TheoFit
best-fit theory predictions
Definition: LTF.h:112
vector< double > Gamma
Use non-linear Gamma-factor.
Definition: LTF.h:94
double chisq
chi^2
Definition: LTF.h:102