예제 #1
0
void FitterUtils::PlotShape2D(RooDataSet& originDataSet, RooDataSet& genDataSet, RooAbsPdf& shape, string plotsfile, string canvName, RooRealVar& B_plus_M, RooRealVar& misPT)
{
   //**************Prepare TFile to save the plots

   TFile f2(plotsfile.c_str(), "UPDATE");

   //**************Plot Signal Zero Gamma

   TH2F* th2fKey = (TH2F*)shape.createHistogram("th2Shape", B_plus_M, Binning(20), YVar(misPT, Binning(20)));
   cout<<genDataSet.sumEntries()<<endl;
   TH2F* th2fGen = (TH2F*)genDataSet.createHistogram("th2fGen", B_plus_M, Binning(20), YVar(misPT, Binning(20)));

   RooPlot* plotM = B_plus_M.frame();
   originDataSet.plotOn(plotM);
   shape.plotOn(plotM);

   RooPlot* plotMisPT = misPT.frame();
   originDataSet.plotOn(plotMisPT);
   shape.plotOn(plotMisPT);

   TCanvas canv(canvName.c_str(), canvName.c_str(), 800, 800);
   canv.Divide(2,2);
   canv.cd(1); th2fGen->Draw("lego");
   canv.cd(2); th2fKey->Draw("surf");
   canv.cd(3); plotM->Draw();
   canv.cd(4); plotMisPT->Draw();

   canv.Write();

   f2.Close();
}
예제 #2
0
void FitterUtils::PlotShape1D(RooDataSet& originDataSet, RooDataSet& genDataSet, RooAbsPdf& shape, string plotsfile, string canvName, RooRealVar& B_plus_M)
{
   TFile f2(plotsfile.c_str(), "UPDATE");

   RooPlot* plotGen = B_plus_M.frame(Binning(20));
   genDataSet.plotOn(plotGen);

   RooPlot* plotM = B_plus_M.frame();
   originDataSet.plotOn(plotM);
   shape.plotOn(plotM);

   TCanvas canv(canvName.c_str(), canvName.c_str(), 800, 800);
   canv.Divide(1,2);
   canv.cd(1); plotGen->Draw();
   canv.cd(2); plotM->Draw();

   canv.Write();

   f2.Close();
}
int main(int argc, char* argv[]) {
  Json::Value const js = ch::MergedJson(argc, argv);

  TH1::AddDirectory(0);
  ModTDRStyle();
  TCanvas canv(js.get("output", "scan").asCString(), "");
  std::vector<TPad*> pads = OnePad();
  std::vector<TLine *> lines;


  std::vector<Scan> scans;


  for (auto it = js["env"].begin(); it != js["env"].end(); ++it) {
    std::cout << (*it).asString() << "\n";
  }

  std::string xvar = js.get("xvar", "r").asString();
  std::string yvar = js.get("yvar", "2. * deltaNLL").asString();
  bool re_zero_graphs = js.get("rezero", true).asBool();
  double cross = js.get("crossing", 1.0).asFloat();
  int precision = js.get("precision", 2).asInt();

  std::set<std::string> draw;
  for (unsigned i = 0; i < js["draw"].size(); ++i) {
    draw.insert(js["draw"][i].asString());
  }


  for (unsigned i = 0; i < js["scans"].size(); ++i) {
    Json::Value const sc_js = js["scans"][i];
    if (!draw.count(sc_js["label"].asString())) continue;
    Scan scan;
    scan.file = sc_js["file"].asString();
    scan.tree = sc_js["tree"].asString();
    scan.color = sc_js["color"].asInt();
    scan.label = sc_js["legend"].asString();
    scans.push_back(scan);
  }
  if (scans.size() == 0) return 1;

  TLegend *leg =
      PositionedLegend(0.4, 0.15 * float(scans.size()) / 1.7, 2, 0.03);
  leg->SetTextSize(0.035);

  for (unsigned i = 0; i < scans.size(); ++i) {
    Scan & sc = scans[i];
    TFile f(sc.file.c_str());
    TTree *t = static_cast<TTree*>(f.Get(sc.tree.c_str()));
    sc.gr = new TGraph(TGraphFromTree(t, xvar, yvar));
    sc.gr->Sort();
    for (int j = 0; j < sc.gr->GetN(); ++j) {
      if (std::fabs(sc.gr->GetY()[j] - 0.) < 1E-5) sc.bestfit = sc.gr->GetX()[j];
    }
    if (re_zero_graphs) ReZeroTGraph(sc.gr);
    auto x1 = GetCrossings(*(sc.gr), 1.0);
    TString res;
    if (x1.size() == 2) {
      sc.uncert = (x1[1]-x1[0])/2.0;
      std::cout << "Best fit is: " << sc.bestfit << " +/- " << sc.uncert << "\n";
      lines.push_back(new TLine(x1[0], 0, x1[0], 1.0));
      lines.back()->SetLineColor(sc.color);
      lines.back()->SetLineWidth(2);
      lines.push_back(new TLine(x1[1], 0, x1[1], 1.0));
      lines.back()->SetLineColor(sc.color);
      lines.back()->SetLineWidth(2);
      res = TString::Format(
          TString::Format("%%.%if#pm%%.%if", precision, precision), sc.bestfit,
          sc.uncert);
      TString leg_text = "#splitline{"+sc.label+"}{"+res+"}";
      sc.gr->SetLineColor(sc.color);
      sc.gr->SetLineWidth(3);
      leg->AddEntry(sc.gr, leg_text, "L");
    }
  }


  TH1 *axis = CreateAxisHist(scans[0].gr, true);
  axis->GetXaxis()->SetTitle(js["x_axis_title"].asCString());
  axis->GetYaxis()->SetTitle(js["y_axis_title"].asCString());
  axis->Draw();

  for (unsigned i = 0; i < scans.size(); ++i) {
    Scan & sc = scans[i];
    sc.gr->Draw("LSAME");
  }

  leg->Draw();

  double xmin = axis->GetXaxis()->GetXmin();
  double xmax = axis->GetXaxis()->GetXmax();

  lines.push_back(new TLine(xmin, cross, xmax, cross));
  lines.back()->SetLineColor(2);
  for (auto l : lines) l->Draw();

  DrawCMSLogo(pads[0], "CMS", js["cms_label"].asString(), 0);
  DrawTitle(pads[0], js["title_right"].asString(), 3);

  canv.Update();
  canv.SaveAs(".pdf");
  canv.SaveAs(".png");
  return 0;
}
예제 #4
0
void PIDStudy::makeFigdEdxDistr()
{

	gStyle->SetOptStat(0);

	for (int multBin = 0; multBin < nMultiplicityBins; multBin++)
	{

   int mult1 = multiplicity_Ana(multBin, 0, nMultiplicityBins);
	int mult2 = multiplicity_Ana(multBin, 1, nMultiplicityBins);


		for (int PBin=0; PBin < nPBins_lin; PBin++)
		{	

			float p1 = PMin_lin + PBin*PBinWidth_lin;
			float p2 = PMin_lin + (PBin+1)*PBinWidth_lin;

			float p_avg = (p1+p2)/2.;

			// Bethe-Bloch cut values in this 'p' bin.
			float BB_Pion_mindEdxcut = pid->BB_Pion_mindEdxcut;
			float BB_Pion_hig = pid->BBcurve(&p_avg, pid->BB_Pion_hig_par);

			float BB_Kaon_low = pid->BBcurve(&p_avg, pid->BB_Kaon_low_par);
			float BB_Kaon_hig = pid->BBcurve(&p_avg, pid->BB_Kaon_hig_par);
			float BB_Kaon_mindEdxcut = pid->BB_Kaon_mindEdxcut;

			float BB_Prot_low = pid->BBcurve(&p_avg, pid->BB_Prot_low_par);
			float BB_Prot_hig = pid->BBcurve(&p_avg, pid->BB_Prot_hig_par);
			float BB_Prot_mindEdxcut = pid->BB_Prot_mindEdxcut;

			int BB_Pion_mindEdxcut_Bin = dEdxDistr_log[multBin][PBin]->GetXaxis()->FindBin( BB_Pion_mindEdxcut );
			int BB_Pion_hig_Bin 			= dEdxDistr_log[multBin][PBin]->GetXaxis()->FindBin( BB_Pion_hig );

			int BB_Kaon_mindEdxcut_Bin = dEdxDistr_log[multBin][PBin]->GetXaxis()->FindBin( BB_Kaon_mindEdxcut );
			int BB_Kaon_low_Bin 			= dEdxDistr_log[multBin][PBin]->GetXaxis()->FindBin( BB_Kaon_low );
			int BB_Kaon_hig_Bin 			= dEdxDistr_log[multBin][PBin]->GetXaxis()->FindBin( BB_Kaon_hig );

			int BB_Prot_mindEdxcut_Bin = dEdxDistr_log[multBin][PBin]->GetXaxis()->FindBin( BB_Prot_mindEdxcut );
			int BB_Prot_low_Bin 			= dEdxDistr_log[multBin][PBin]->GetXaxis()->FindBin( BB_Prot_low );
			int BB_Prot_hig_Bin 			= dEdxDistr_log[multBin][PBin]->GetXaxis()->FindBin( BB_Prot_hig );

			double Pion_Entries = dEdxDistr_log[multBin][PBin]->Integral(BB_Pion_mindEdxcut_Bin, BB_Pion_hig_Bin);
			double Kaon_Entries = dEdxDistr_log[multBin][PBin]->Integral(BB_Kaon_low_Bin, BB_Kaon_hig_Bin);
			double Prot_Entries = dEdxDistr_log[multBin][PBin]->Integral(BB_Prot_low_Bin, BB_Prot_hig_Bin);
			double Kaon_Entries_mindEdxcut = dEdxDistr_log[multBin][PBin]->Integral(BB_Kaon_mindEdxcut_Bin, BB_Kaon_hig_Bin);
			double Prot_Entries_mindEdxcut = dEdxDistr_log[multBin][PBin]->Integral(BB_Prot_mindEdxcut_Bin, BB_Prot_hig_Bin);

			double Prot2PionRatio = Prot_Entries/Pion_Entries;
			double Kaon2PionRatio = Kaon_Entries/Pion_Entries;
			double Prot2PionRatio_mindExcut = Prot_Entries_mindEdxcut/Pion_Entries;
			double Kaon2PionRatio_mindExcut = Kaon_Entries_mindEdxcut/Pion_Entries;

			double Prot2PionRatio_Err = Prot2PionRatio*sqrt(1/Prot_Entries+1/Pion_Entries);
			double Kaon2PionRatio_Err = Kaon2PionRatio*sqrt(1/Kaon_Entries+1/Pion_Entries);
			double Prot2PionRatio_mindExcut_Err = Prot2PionRatio_mindExcut*sqrt(1/Prot_Entries_mindEdxcut+1/Pion_Entries);
			double Kaon2PionRatio_mindExcut_Err = Kaon2PionRatio_mindExcut*sqrt(1/Kaon_Entries_mindEdxcut+1/Pion_Entries);



			/////////////////////////////////////////////////////////////////
			{
			TCanvas canv("dEdxvsDistr",";;", 1024, 768);

			canv.SetLeftMargin(0.15);

			double EntryStat_Pion_TLatex_posx = 0.4;
			double EntryStat_Pion_TLatex_posy = 0.6;
			double EntryStat_Kaon_TLatex_posx = 0.4;
			double EntryStat_Kaon_TLatex_posy = 0.55;
			double EntryStat_Prot_TLatex_posx = 0.4;
			double EntryStat_Prot_TLatex_posy = 0.50;


			double RatioStat_Kaon2Pion_TLatex_posx = 0.6;
			double RatioStat_Kaon2Pion_TLatex_posy = 0.6;
			double RatioStat_Prot2Pion_TLatex_posx = 0.6;
			double RatioStat_Prot2Pion_TLatex_posy = 0.55;

			// Drawing
			dEdxDistr_log[multBin][PBin]->SetLineColor(kBlack);
			dEdxDistr_log[multBin][PBin]->SetMarkerColor(kBlack);
			dEdxDistr_log[multBin][PBin]->SetTitle("");
			// Biwidth scaling
			dEdxDistr_log[multBin][PBin]->Scale(1, "width");
			dEdxDistr_log[multBin][PBin]->GetYaxis()->SetTitle("Entries/bw.");
			dEdxDistr_log[multBin][PBin]->GetYaxis()->SetTitleOffset(1.6);
			dEdxDistr_log[multBin][PBin]->Draw("");
			double maxval = dEdxDistr_log[multBin][PBin]->GetBinContent(dEdxDistr_log[multBin][PBin]->GetMaximumBin());

			TLatex *EntryStat_Pion_TLatex;
			TLatex *EntryStat_Kaon_TLatex;
			TLatex *EntryStat_Prot_TLatex;
			TLatex *RatioStat_Kaon2Pion_TLatex;
			TLatex *RatioStat_Prot2Pion_TLatex;

			double scale = 0.4;
			TLine BB_Pion_mindEdxcut_line (BB_Pion_mindEdxcut,0.0,BB_Pion_mindEdxcut,0.5*maxval);
			TLine BB_Pion_hig_line (BB_Pion_hig,0.0,BB_Pion_hig,scale*maxval);
			TLine BB_Kaon_low_line (BB_Kaon_low,0.0,BB_Kaon_low,scale*maxval);
			TLine BB_Kaon_hig_line (BB_Kaon_hig,0.0,BB_Kaon_hig,scale*maxval);
			TLine BB_Prot_low_line (BB_Prot_low,0.0,BB_Prot_low,scale*maxval);
			TLine BB_Prot_hig_line (BB_Prot_hig,0.0,BB_Prot_hig,scale*maxval);
			TLine BB_Kaon_mindEdxcut_line (BB_Kaon_mindEdxcut,0.0,BB_Kaon_mindEdxcut,scale*maxval);
			TLine BB_Prot_mindEdxcut_line (BB_Prot_mindEdxcut,0.0,BB_Prot_mindEdxcut,scale*maxval);

			TLatex BB_Pion_hig_TLatex (BB_Pion_hig,scale*maxval,"#pi_{high}");
			TLatex BB_Kaon_low_TLatex (BB_Kaon_low,scale*maxval,"K_{low}");
			TLatex BB_Kaon_hig_TLatex (BB_Kaon_hig,scale*maxval,"K_{high}");
			TLatex BB_Prot_low_TLatex (BB_Prot_low,scale*maxval,"p_{low}");
			TLatex BB_Prot_hig_TLatex (BB_Prot_hig,scale*maxval,"p_{high}");

			TLatex BB_Pion_mindEdxcut_TLatex (BB_Pion_mindEdxcut,scale*maxval,"#pi_{min dE/dx}");
			TLatex BB_Kaon_mindEdxcut_TLatex (BB_Kaon_mindEdxcut,scale*maxval,"K_{min dE/dx}");
			TLatex BB_Prot_mindEdxcut_TLatex (BB_Prot_mindEdxcut,scale*maxval,"p_{min dE/dx}");

			// Kaon
			if ( p2 < 0.9 )
			{
				BB_Kaon_hig_line.Draw();
				BB_Kaon_hig_TLatex.Draw();

				std::string EntryStat_Kaon_TLatex_Str;
				std::string RatioStat_Kaon2Pion_TLatex_Str;

				if ( BB_Kaon_low < BB_Kaon_mindEdxcut )
				{
					EntryStat_Kaon_TLatex_Str = Form("N_{K} = %f",   Kaon_Entries_mindEdxcut);
					RatioStat_Kaon2Pion_TLatex_Str = Form("N_{K}/N_{#pi} = %f #pm %f", Kaon2PionRatio_mindExcut, Kaon2PionRatio_mindExcut_Err);
					BB_Kaon_mindEdxcut_line.Draw();
					BB_Kaon_mindEdxcut_TLatex.Draw();
				}
				else
				{
					EntryStat_Kaon_TLatex_Str = Form("N_{K} = %f",   Kaon_Entries);
					RatioStat_Kaon2Pion_TLatex_Str = Form("N_{K}/N_{#pi} = %f #pm %f", Kaon2PionRatio, Kaon2PionRatio_Err);
					BB_Kaon_low_line.Draw();
					BB_Kaon_low_TLatex.Draw();
				}

				EntryStat_Kaon_TLatex = new TLatex(EntryStat_Kaon_TLatex_posx, EntryStat_Kaon_TLatex_posy, EntryStat_Kaon_TLatex_Str.c_str());
				EntryStat_Kaon_TLatex->SetTextSize(0.03);
				EntryStat_Kaon_TLatex->SetNDC(kTRUE);

				RatioStat_Kaon2Pion_TLatex = new TLatex (RatioStat_Kaon2Pion_TLatex_posx, RatioStat_Kaon2Pion_TLatex_posy, RatioStat_Kaon2Pion_TLatex_Str.c_str());
				RatioStat_Kaon2Pion_TLatex->SetTextSize(0.03);
				RatioStat_Kaon2Pion_TLatex->SetNDC(kTRUE);

				EntryStat_Kaon_TLatex->Draw();
				RatioStat_Kaon2Pion_TLatex->Draw();
			}

			// Pion
			if ( p2 < 1.0 )
			{
				std::string EntryStat_Pion_TLatex_Str = Form("N_{#pi} = %f", Pion_Entries);
				BB_Pion_hig_line.Draw();
				BB_Pion_hig_TLatex.Draw();
				BB_Pion_mindEdxcut_line.Draw();
				BB_Pion_mindEdxcut_TLatex.Draw();
				EntryStat_Pion_TLatex = new TLatex(EntryStat_Pion_TLatex_posx, EntryStat_Pion_TLatex_posy, EntryStat_Pion_TLatex_Str.c_str());
				EntryStat_Pion_TLatex->SetTextSize(0.03);
				EntryStat_Pion_TLatex->SetNDC(kTRUE);
				EntryStat_Pion_TLatex->Draw();

			}

			// Prot
			if ( p2 < 1.6 )
			{

				BB_Prot_hig_line.Draw();
				BB_Prot_hig_TLatex.Draw();

				std::string RatioStat_Prot2Pion_TLatex_Str;
				std::string EntryStat_Prot_TLatex_Str;

				if ( BB_Prot_low < BB_Prot_mindEdxcut )
				{
					RatioStat_Prot2Pion_TLatex_Str = Form("N_{p}/N_{#pi} = %f #pm %f", Prot2PionRatio_mindExcut, Prot2PionRatio_mindExcut_Err);
					EntryStat_Prot_TLatex_Str = Form("N_{p} = %f",   Prot_Entries_mindEdxcut);
					BB_Prot_mindEdxcut_line.Draw();
					BB_Prot_mindEdxcut_TLatex.Draw();
				}
				else
				{
					RatioStat_Prot2Pion_TLatex_Str = Form("N_{p}/N_{#pi} = %f #pm %f", Prot2PionRatio, Prot2PionRatio_Err);
					EntryStat_Prot_TLatex_Str = Form("N_{p} = %f",   Prot_Entries);
					BB_Prot_low_line.Draw();
					BB_Prot_low_TLatex.Draw();
				}

			EntryStat_Prot_TLatex = new TLatex (EntryStat_Prot_TLatex_posx, EntryStat_Prot_TLatex_posy, EntryStat_Prot_TLatex_Str.c_str());
			EntryStat_Prot_TLatex->SetTextSize(0.03);
			EntryStat_Prot_TLatex->SetNDC(kTRUE);

			RatioStat_Prot2Pion_TLatex = new TLatex (RatioStat_Prot2Pion_TLatex_posx, RatioStat_Prot2Pion_TLatex_posy, RatioStat_Prot2Pion_TLatex_Str.c_str());
			RatioStat_Prot2Pion_TLatex->SetTextSize(0.03);
			RatioStat_Prot2Pion_TLatex->SetNDC(kTRUE);

			EntryStat_Prot_TLatex->Draw();
			if ( p2 < 1.0)
			{RatioStat_Prot2Pion_TLatex->Draw();	}
	
			}

			BB_Pion_hig_line.SetLineColor(kRed);
			BB_Kaon_low_line.SetLineColor(kGreen);
			BB_Kaon_hig_line.SetLineColor(kGreen);
			BB_Prot_low_line.SetLineColor(kBlue);
			BB_Prot_hig_line.SetLineColor(kBlue);
			BB_Pion_mindEdxcut_line.SetLineColor(kRed);
			BB_Kaon_mindEdxcut_line.SetLineColor(kGreen);
			BB_Prot_mindEdxcut_line.SetLineColor(kBlue);

			BB_Pion_hig_TLatex.SetTextColor(kRed);
			BB_Kaon_low_TLatex.SetTextColor(kGreen);
			BB_Kaon_hig_TLatex.SetTextColor(kGreen);
			BB_Prot_low_TLatex.SetTextColor(kBlue);
			BB_Prot_hig_TLatex.SetTextColor(kBlue);
			BB_Pion_mindEdxcut_TLatex.SetTextColor(kRed);
			BB_Kaon_mindEdxcut_TLatex.SetTextColor(kGreen);
			BB_Prot_mindEdxcut_TLatex.SetTextColor(kBlue);

			BB_Pion_hig_TLatex.SetTextSize(0.02);
			BB_Kaon_low_TLatex.SetTextSize(0.02);
			BB_Kaon_hig_TLatex.SetTextSize(0.02);
			BB_Prot_low_TLatex.SetTextSize(0.02);
			BB_Prot_hig_TLatex.SetTextSize(0.02);
			BB_Pion_mindEdxcut_TLatex.SetTextSize(0.02);
			BB_Kaon_mindEdxcut_TLatex.SetTextSize(0.02);
			BB_Prot_mindEdxcut_TLatex.SetTextSize(0.02);

			BB_Pion_hig_line.SetLineStyle(8);
			BB_Kaon_low_line.SetLineStyle(8);
			BB_Kaon_hig_line.SetLineStyle(8);
			BB_Prot_low_line.SetLineStyle(8);
			BB_Prot_hig_line.SetLineStyle(8);
			BB_Pion_mindEdxcut_line.SetLineStyle(8);
			BB_Kaon_mindEdxcut_line.SetLineStyle(8);
			BB_Prot_mindEdxcut_line.SetLineStyle(8);

			BB_Pion_hig_line.SetLineWidth(3);
			BB_Kaon_low_line.SetLineWidth(3);
			BB_Kaon_hig_line.SetLineWidth(3);
			BB_Prot_low_line.SetLineWidth(3);
			BB_Prot_hig_line.SetLineWidth(3);
			BB_Pion_mindEdxcut_line.SetLineWidth(3);
			BB_Kaon_mindEdxcut_line.SetLineWidth(3);
			BB_Prot_mindEdxcut_line.SetLineWidth(3);

			// Fitting
			//dEdxDistr_log[multBin][PBin]->Fit( dEdxDistr_log_Fit[multBin][PBin]);
			//

			double BinStat_TLatex_posx = 0.5;
			double BinStat_TLatex_posy = 0.8;
			std::string BinStat_TLatex_Str = Form("#splitline{%d #leq N_{trk}^{off} #leq %d}{%.2f < p < %.2f GeV/c}", mult1, mult2 ,p1, p2);
			TLatex BinStat_TLatex (BinStat_TLatex_posx, BinStat_TLatex_posy, BinStat_TLatex_Str.c_str());
			BinStat_TLatex.SetTextSize(0.03);
			BinStat_TLatex.SetNDC(kTRUE);
			BinStat_TLatex.Draw();

			std::string FigBase = Form("dEdxDistr_log_mult_%03d-%03d_p_%.2f-%.2f", mult1, mult2, p1, p2);
 			std::string FigPNG = FigBase+".png";
 			std::string FigPDF = FigBase+".pdf";

			canv.SaveAs( FigPNG.c_str());
			canv.SaveAs( FigPDF.c_str());
			}

//			{
//			TCanvas canv("dEdxvsDistr",";;", 1024, 768);
//
//			dEdxDistr_lin[multBin][PBin]->Draw("");
//
//			std::string FigBase = Form("dEdxDistr_lin_mult_%03d-%03d_p_%.2f-%.2f", mult1, mult2, p1, p2);
// 			std::string FigPNG = FigBase+".png";
// 			std::string FigPDF = FigBase+".pdf";
//
//			canv.SaveAs( FigPNG.c_str());
//			canv.SaveAs( FigPDF.c_str());
//			}

		}

	}
}
예제 #5
0
int main(  int argc, char * argv[] )
{

  int returnStatus_( 0 );

  // Load libraries
  gSystem->Load( "libFWCoreFWLite" );
  AutoLibraryLoader::enable();

  // Adjust style
  gStyle->SetPalette( 1, 0 );
  gStyle->SetCanvasColor( kWhite );
  gStyle->SetPadColor( kWhite );
  gStyle->SetPadTickX( 1 );
  gStyle->SetPadTickY( 1 );
  gStyle->SetPadTopMargin( 0.05 );
  gStyle->SetPadRightMargin( 0.05 );
  gStyle->SetPadBottomMargin( 0.1 );
  gStyle->SetPadLeftMargin( 0.1 );
  gStyle->SetTitleSize( 0.06, "XYZ" );
  gStyle->SetTitleFillColor( kWhite );
  gStyle->SetTitleBorderSize( 1 );
  gStyle->SetStatColor( kWhite );
  gStyle->SetStatBorderSize( 1 );
  gStyle->SetOptStat( 0 );
  gStyle->SetOptFit( 0 );
  gStyle->SetOptTitle( 0 );
  gStyle->SetMarkerStyle( 8 );

  // Check configuration file
  if ( argc < 2 ) {
    std::cout << argv[ 0 ] << " --> Usage:" << std::endl
              << "    " << argv[ 0 ] << " [CONFIG_FILE.py]" << std::endl;
    returnStatus_ += 0x1;
    return returnStatus_;
  }
  if ( ! edm::readPSetsFrom( argv[ 1 ] )->existsAs< edm::ParameterSet >( "process" ) ) {
    std::cout << argv[ 0 ] << " --> ERROR:" << std::endl
              << "   cms.PSet 'process' missing in " << argv[ 1 ] << std::endl;
    returnStatus_ += 0x2;
    return returnStatus_;
  }

  // Get the configurations
  const edm::ParameterSet & process_( edm::readPSetsFrom( argv[ 1 ] )->getParameter< edm::ParameterSet >( "process" ) );
  const bool verbose_( process_.getParameter< bool >( "verbose" ) );
  const std::vector< std::string > objCats_( process_.getParameter< std::vector< std::string > >( "objectCategories" ) );   // object categories
  const bool overwrite_(  process_.getParameter< bool >( "overwrite" ));
  const bool usePileUp_( process_.getParameter< bool >( "usePileUp" ) );
  const bool useAlt_( process_.getParameter< bool >( "useAlt" ) );
  const bool useSymm_( process_.getParameter< bool >( "useSymm" ) );
  const bool refGen_( process_.getParameter< bool >( "refGen" ) );
  const bool refSel_( process_.getParameter< bool >( "refSel" ) );
  // Configuration for in- & output
  const edm::ParameterSet & io_( process_.getParameter< edm::ParameterSet >( "io" ) );
  const std::vector< std::string > inFiles_( io_.getParameter< std::vector< std::string > >( "inputFiles" ) );
  const std::string sample_( io_.getParameter< std::string >( "sample" ) );
  const std::string outFile_( io_.getParameter< std::string >( "outputFile" ) );
  const std::string plotPath_( io_.getParameter< std::string >( "plotPath" ) );
  // Configuration for plotting resolution functions
  const edm::ParameterSet & plot_( process_.getParameter< edm::ParameterSet >( "plot" ) );
  const bool onlyExisting_( plot_.getParameter< bool >( "onlyExisting" ) );
  const bool writeFiles_( plot_.getParameter< bool >( "writeFiles" ) && onlyExisting_ );
  const std::string plotCycle_( plot_.getParameter< std::string >( "plotCycle" ) );
  const bool plotNonRestr_( plot_.getParameter< bool >( "plotNonRestr" ) );
  const bool plotEtaPt_( plot_.getParameter< bool >( "plotEtaPt" ) );

  // Set constants
  std::string evtSel_( "analyzeHitFit" );
  if ( refSel_ ) evtSel_.append( "Reference" );
  const std::string nameDirClass( "TDirectoryFile" );
  const std::string nameFuncClass( "TF1" );
  const std::string fitFunc( plotCycle_ == "1" ? "Gaussian + log-normal" : "Gaussian" );
  const std::string bkgFunc( plotCycle_ == "1" ? "Log-normal" : "" );


  std::vector< TFile* > files_;
  TCanvas * canv( new TCanvas( "canv", "", 768, 512 ) );

  std::vector< std::vector< double > > etaBins;
  std::vector< std::vector< double > > ptBins;

  // Open input files

//   bool first( true );
  for ( unsigned uFile = 0; uFile < inFiles_.size(); ++uFile ) {
    const std::string inFile( inFiles_.at( uFile ) );
    TFile * file( TFile::Open( inFile.c_str(), "READ" ) );
    if ( ! file ) {
      std::cout << argv[ 0 ] << " --> ERROR:" << std::endl
                << "   input file '" << inFiles_.at( uFile ) << "' missing; trying next file" << std::endl;
      returnStatus_ += 0x10;
      continue;
    }
    files_.push_back( file );
  }  // loop: uFile

  if ( files_.empty() ) {
    std::cout << argv[ 0 ] << " --> ERROR:" << std::endl
              << "   no input files found" << std::endl;
    returnStatus_ += 0x20;
    return returnStatus_;
  }

  TFile * refFile( files_.at( 0 ) );
  TDirectory * dirSel_ = ( TDirectory* )( refFile->Get( evtSel_.c_str() ) );
  if ( ! dirSel_ ) {
    std::cout << argv[ 0 ] << " --> ERROR:" << std::endl
              << "   selection '" << evtSel_ << "' does not exist in reference file '" << refFile->GetName() << "'" << std::endl;
    returnStatus_ += 0x30;
    return returnStatus_;
  }

  // Loop over configured object categories
  for ( unsigned uCat = 0; uCat < objCats_.size(); ++uCat ) {
    const std::string objCat( objCats_.at( uCat ) );
    if ( objCat == "UdscJet" || objCat == "BJet" ) {
      TDirectory * dirCat_( ( TDirectory* )( dirSel_->Get( objCat.c_str() ) ) );
      if ( ! dirCat_ ) {
        std::cout << argv[ 0 ] << " --> WARNING:" << std::endl
                  << "   object category '" << objCat << "' does not exist in reference file '" << refFile->GetName() << "'" << std::endl;
        continue;
      }

      // Eta binning
      std::vector< double > etaBins;
      TH1D * histBinsEta( ( TH1D* )( dirCat_->Get( std::string( objCat + "_binsEta" ).c_str() ) ) );
      const bool objMetLike( histBinsEta->GetNbinsX() == 1 );
      if ( objMetLike ) {
        etaBins.push_back( histBinsEta->GetBinLowEdge( 1 ) );
      }
      else {
        for ( int iEta = 0; iEta < histBinsEta->GetNbinsX(); ++iEta ) {
          double edge( histBinsEta->GetBinLowEdge( iEta + 1 ) );
          if ( useSymm_  && edge < 0. ) continue;
          etaBins.push_back( edge );
        }
      }
      etaBins.push_back( histBinsEta->GetBinLowEdge( histBinsEta->GetNbinsX() ) + histBinsEta->GetBinWidth( histBinsEta->GetNbinsX() ) );
      const unsigned nEtaBins_( etaBins.size() - 1 );

      // Pt binning
      std::vector< double > ptBins;
      TH1D * histBinsPt( ( TH1D* )( dirCat_->Get( std::string( objCat + "_binsPt" ).c_str() ) ) );
      for ( int uPt = 0; uPt < histBinsPt->GetNbinsX(); ++uPt ) {
        ptBins.push_back( histBinsPt->GetBinLowEdge( uPt + 1 ) );
      }
      ptBins.push_back( histBinsPt->GetBinLowEdge( histBinsPt->GetNbinsX() ) + histBinsPt->GetBinWidth( histBinsPt->GetNbinsX() ) );
      const unsigned nPtBins_( ptBins.size() - 1 );

      TDirectory * dirPt_( ( TDirectory* )( dirCat_->Get( "Pt" ) ) );

      // Loop over fit versions
      TList * listProp( dirPt_->GetListOfKeys() );
      TIter nextInListProp( listProp );
      while ( TKey * keyFit = ( TKey* )nextInListProp() ) {
        if ( std::string( keyFit->GetClassName() ) != nameDirClass ) continue;
        const std::string subFit( keyFit->GetName() );
        if ( subFit.find( "Inv" ) != std::string::npos ) continue; // nothing to do for inverse
        // These are real switches: depending on configuration, only one setting combination can be run at a time
        if ( useAlt_  == ( subFit.find( "Alt" )  == std::string::npos ) ) continue;
        if ( useSymm_ == ( subFit.find( "Symm" ) == std::string::npos ) ) continue;
        if ( refGen_  == ( subFit.find( "Gen" )  == std::string::npos ) ) continue;
        TDirectory * dirFit_( ( TDirectory* )( dirPt_->Get( subFit.c_str() ) ) );

        const std::string name( objCat + "_Pt_" + subFit );
        const std::string titleLegend( objCat + ", p_{t}" );

        const std::string nameFracL5L7( name + "_FracL5L7" );
        const std::string nameFracL5L7Print( plotPath_ + "/" + evtSel_ + "_" + nameFracL5L7 + ".png" );
        TH1D * histFracL5L7( ( TH1D* )( dirFit_->Get( std::string( nameFracL5L7 + ";" + plotCycle_ ).c_str() ) ) );
        if ( plotNonRestr_ && histFracL5L7 != 0 ) {
          TLegend * legFracL5L7Fit( new TLegend( 0.1, 0.67, 0.9, 0.9, titleLegend.c_str() ) );
          legFracL5L7Fit->SetTextSize( 0.03 );
          legFracL5L7Fit->SetFillColor( kWhite );
          legFracL5L7Fit->SetFillStyle( 0 );
          legFracL5L7Fit->SetBorderSize( 0 );
          canv->cd();
          histFracL5L7->Draw();
          const std::string nameFracL5L7Fit( nameFracL5L7 + "_fit" );
          TF1 * fitFracL5L7( histFracL5L7->GetFunction( nameFracL5L7Fit.c_str() ) );
          if ( fitFracL5L7 != 0 ) legFracL5L7Fit->AddEntry( fitFracL5L7, fitFunc.c_str() );
          else                    legFracL5L7Fit->AddEntry( histFracL5L7, fitFunc.c_str() );
          const std::string nameFracL5L7Bkg( nameFracL5L7 + "_bkg" );
          TF1 * bkgFracL5L7(  ( TF1* )( dirFit_->Get( std::string( nameFracL5L7Bkg + ";" + plotCycle_ ).c_str() ) ));
          if ( bkgFracL5L7 != 0 ) {
            bkgFracL5L7->SetLineColor( kRed );
            bkgFracL5L7->Draw( "Same" );
            legFracL5L7Fit->AddEntry( bkgFracL5L7, bkgFunc.c_str() );
          }
          legFracL5L7Fit->Draw();
          canv->Print( nameFracL5L7Print.c_str() );
          delete legFracL5L7Fit;

        }

        const std::string nameFracL5L7Restr( nameFracL5L7 + "Restr" );
        const std::string nameFracL5L7RestrPrint( plotPath_ + "/" + evtSel_ + "_" + nameFracL5L7Restr + ".png" );
        TH1D * histFracL5L7Restr( ( TH1D* )( dirFit_->Get( std::string( nameFracL5L7Restr + ";" + plotCycle_ ).c_str() ) ) );
        std::cout << nameFracL5L7Restr << " " << histFracL5L7Restr << std::endl;
        if ( histFracL5L7Restr != 0 ) {
          TLegend * legFracL5L7RestrFit( new TLegend( 0.1, 0.67, 0.9, 0.9, titleLegend.c_str() ) );
          legFracL5L7RestrFit->SetTextSize( 0.03 );
          legFracL5L7RestrFit->SetFillColor( kWhite );
          legFracL5L7RestrFit->SetFillStyle( 0 );
          legFracL5L7RestrFit->SetBorderSize( 0 );
          canv->cd();
          histFracL5L7Restr->Draw();
          const std::string nameFracL5L7RestrFit( nameFracL5L7Restr + "_fit" );
          TF1 * fitFracL5L7Restr( histFracL5L7Restr->GetFunction( nameFracL5L7RestrFit.c_str() ) );
          if ( fitFracL5L7Restr != 0 ) legFracL5L7RestrFit->AddEntry( fitFracL5L7Restr, fitFunc.c_str() );
          else                         legFracL5L7RestrFit->AddEntry( histFracL5L7Restr, fitFunc.c_str() );
          const std::string nameFracL5L7RestrBkg( nameFracL5L7Restr + "_bkg" );
          TF1 * bkgFracL5L7Restr( ( TF1* )( dirFit_->Get( std::string( nameFracL5L7RestrBkg + ";" + plotCycle_ ).c_str() ) ) );
          if ( bkgFracL5L7Restr != 0 ) {
            bkgFracL5L7Restr->SetLineColor( kRed );
            bkgFracL5L7Restr->Draw( "Same" );
            legFracL5L7RestrFit->AddEntry( bkgFracL5L7Restr, bkgFunc.c_str() );
          }
          legFracL5L7RestrFit->Draw();
          canv->Print( nameFracL5L7RestrPrint.c_str() );
          delete legFracL5L7RestrFit;
        }

        // Loop over pt bins

        // Fit performance histograms
        if ( plotNonRestr_ ) {
          const std::string nameFracL5L7PtFitMeanMap( name + "_FracL5L7Pt_FitMeanMap" );
          const std::string nameFracL5L7PtFitMeanMapPrint( plotPath_ + "/" + evtSel_ + "_" + nameFracL5L7PtFitMeanMap + ".png" );
          TH1D * histFracL5L7PtFitMeanMap( ( TH1D* )( dirFit_->Get( std::string( nameFracL5L7PtFitMeanMap + ";" + plotCycle_ ).c_str() ) ) );
          if ( histFracL5L7PtFitMeanMap != 0 ) {
            canv->cd();
            histFracL5L7PtFitMeanMap->Draw();
            canv->Print( nameFracL5L7PtFitMeanMapPrint.c_str() );
          }
        }
        const std::string nameFracL5L7RestrPtFitMeanMap( name + "_FracL5L7RestrPt_FitMeanMap" );
        const std::string nameFracL5L7RestrPtFitMeanMapPrint( plotPath_ + "/" + evtSel_ + "_" + nameFracL5L7RestrPtFitMeanMap + ".png" );
        TH1D * histFracL5L7RestrPtFitMeanMap( ( TH1D* )( dirFit_->Get( std::string( nameFracL5L7RestrPtFitMeanMap + ";" + plotCycle_ ).c_str() ) ) );
        if ( histFracL5L7RestrPtFitMeanMap != 0 ) {
          canv->cd();
          histFracL5L7RestrPtFitMeanMap->Draw();
          canv->Print( nameFracL5L7RestrPtFitMeanMapPrint.c_str() );
        }

        for ( unsigned uPt = 0; uPt < nPtBins_; ++uPt ) {
          const std::string binPt( boost::lexical_cast< std::string >( uPt ) );
          const std::string namePt( name + "_Pt" + binPt );
          const std::string titleLegendPt( titleLegend + ", " + boost::lexical_cast< std::string >( ptBins.at( uPt ) ) + " GeV #leq p_{t} < " + boost::lexical_cast< std::string >( ptBins.at( uPt + 1 ) ) + " GeV" );

          const std::string namePtFracL5L7( namePt + "_FracL5L7" );
          const std::string namePtFracL5L7Print( plotPath_ + "/" + evtSel_ + "_" + namePtFracL5L7 + ".png" );
          TH1D * histPtFracL5L7( ( TH1D* )( dirFit_->Get( std::string( namePtFracL5L7 + ";" + plotCycle_ ).c_str() ) ) );
          if ( plotNonRestr_ && histPtFracL5L7 != 0 ) {
            TLegend * legPtFracL5L7Fit( new TLegend( 0.1, 0.67, 0.9, 0.9, titleLegendPt.c_str() ) );
            legPtFracL5L7Fit->SetTextSize( 0.03 );
            legPtFracL5L7Fit->SetFillColor( kWhite );
            legPtFracL5L7Fit->SetFillStyle( 0 );
            legPtFracL5L7Fit->SetBorderSize( 0 );
            canv->cd();
            histPtFracL5L7->Draw();
            const std::string namePtFracL5L7Fit( namePtFracL5L7 + "_fit" );
            TF1 * fitPtFracL5L7( histPtFracL5L7->GetFunction( namePtFracL5L7Fit.c_str() ) );
            if ( fitPtFracL5L7 != 0 ) legPtFracL5L7Fit->AddEntry( fitPtFracL5L7, fitFunc.c_str() );
            else                      legPtFracL5L7Fit->AddEntry( histPtFracL5L7, fitFunc.c_str() );
            const std::string namePtFracL5L7Bkg( namePtFracL5L7 + "_bkg" );
            TF1 * bkgPtFracL5L7( ( TF1* )( dirFit_->Get( std::string( namePtFracL5L7Bkg + ";" + plotCycle_ ).c_str() ) ) );
            if ( bkgPtFracL5L7 != 0 ) {
              bkgPtFracL5L7->SetLineColor( kRed );
              bkgPtFracL5L7->Draw( "Same" );
              legPtFracL5L7Fit->AddEntry( bkgPtFracL5L7, bkgFunc.c_str() );
            }
            legPtFracL5L7Fit->Draw();
            canv->Print( namePtFracL5L7Print.c_str() );
            delete legPtFracL5L7Fit;
          }

          const std::string namePtFracL5L7Restr( namePtFracL5L7 + "Restr" );
          const std::string namePtFracL5L7RestrPrint( plotPath_ + "/" + evtSel_ + "_" + namePtFracL5L7Restr + ".png" );
          TH1D * histPtFracL5L7Restr( ( TH1D* )( dirFit_->Get( std::string( namePtFracL5L7Restr + ";" + plotCycle_ ).c_str() ) ) );
          if ( histPtFracL5L7Restr != 0 ) {
            TLegend * legPtFracL5L7RestrFit( new TLegend( 0.1, 0.67, 0.9, 0.9, titleLegendPt.c_str() ) );
            legPtFracL5L7RestrFit->SetTextSize( 0.03 );
            legPtFracL5L7RestrFit->SetFillColor( kWhite );
            legPtFracL5L7RestrFit->SetFillStyle( 0 );
            legPtFracL5L7RestrFit->SetBorderSize( 0 );
            canv->cd();
            histPtFracL5L7Restr->Draw();
            const std::string namePtFracL5L7RestrFit( namePtFracL5L7Restr + "_fit" );
            TF1 * fitPtFracL5L7Restr( histPtFracL5L7Restr->GetFunction( namePtFracL5L7RestrFit.c_str() ) );
            if ( fitPtFracL5L7Restr != 0 ) legPtFracL5L7RestrFit->AddEntry( fitPtFracL5L7Restr, fitFunc.c_str() );
            else                           legPtFracL5L7RestrFit->AddEntry( histPtFracL5L7Restr, fitFunc.c_str() );
            const std::string namePtFracL5L7RestrBkg( namePtFracL5L7Restr + "_bkg" );
            TF1 * bkgPtFracL5L7Restr( ( TF1* )( dirFit_->Get( std::string( namePtFracL5L7RestrBkg + ";" + plotCycle_ ).c_str() ) ) );
            if ( bkgPtFracL5L7Restr != 0 ) {
              bkgPtFracL5L7Restr->SetLineColor( kRed );
              bkgPtFracL5L7Restr->Draw( "Same" );
              legPtFracL5L7RestrFit->AddEntry( bkgPtFracL5L7Restr, bkgFunc.c_str() );
            }
            legPtFracL5L7RestrFit->Draw();
            canv->Print( namePtFracL5L7RestrPrint.c_str() );
            delete legPtFracL5L7RestrFit;
          }

        } // loop: uPt < nPtBins_

        // Loop over eta bins

        // Fit performance histograms
        if ( plotNonRestr_ ) {
          const std::string nameFracL5L7EtaFitMeanMap( name + "_FracL5L7Eta_FitMeanMap" );
          const std::string nameFracL5L7EtaFitMeanMapPrint( plotPath_ + "/" + evtSel_ + "_" + nameFracL5L7EtaFitMeanMap + ".png" );
          TH1D * histFracL5L7EtaFitMeanMap( ( TH1D* )( dirFit_->Get( std::string( nameFracL5L7EtaFitMeanMap + ";" + plotCycle_ ).c_str() ) ) );
          if ( histFracL5L7EtaFitMeanMap != 0 ) {
            canv->cd();
            histFracL5L7EtaFitMeanMap->Draw();
            canv->Print( nameFracL5L7EtaFitMeanMapPrint.c_str() );
          }
          const std::string nameFracL5L7EtaPtFitMeanMap( name + "_FracL5L7EtaPt_FitMeanMap" );
          TH2D * histFracL5L7EtaPtFitMeanMap( ( TH2D* )( dirFit_->Get( nameFracL5L7EtaPtFitMeanMap.c_str() ) ) );
          const std::string nameFracL5L7EtaPtFitMean( name + "_FracL5L7EtaPt_FitMean" );
          TH1D * histFracL5L7EtaPtFitMean( ( TH1D* )( dirFit_->Get( nameFracL5L7EtaPtFitMean.c_str() ) ) );
          const std::string nameFracL5L7EtaPtFitSigma( name + "_FracL5L7EtaPt_FitSigma" );
          TH1D * histFracL5L7EtaPtFitSigma( ( TH1D* )( dirFit_->Get( nameFracL5L7EtaPtFitSigma.c_str() ) ) );
        }
        const std::string nameFracL5L7RestrEtaFitMeanMap( name + "_FracL5L7RestrEta_FitMeanMap" );
        const std::string nameFracL5L7RestrEtaFitMeanMapPrint( plotPath_ + "/" + evtSel_ + "_" + nameFracL5L7RestrEtaFitMeanMap + ".png" );
        TH1D * histFracL5L7RestrEtaFitMeanMap( ( TH1D* )( dirFit_->Get( std::string( nameFracL5L7RestrEtaFitMeanMap + ";" + plotCycle_ ).c_str() ) ) );
        if ( histFracL5L7RestrEtaFitMeanMap != 0 ) {
          canv->cd();
          histFracL5L7RestrEtaFitMeanMap->Draw();
          canv->Print( nameFracL5L7RestrEtaFitMeanMapPrint.c_str() );
        }
        const std::string nameFracL5L7RestrEtaPtFitMeanMap( name + "_FracL5L7RestrEtaPt_FitMeanMap" );
        TH2D * histFracL5L7RestrEtaPtFitMeanMap( ( TH2D* )( dirFit_->Get( nameFracL5L7RestrEtaPtFitMeanMap.c_str() ) ) );
        const std::string nameFracL5L7RestrEtaPtFitMean( name + "_FracL5L7RestrEtaPt_FitMean" );
        TH1D * histFracL5L7RestrEtaPtFitMean( ( TH1D* )( dirFit_->Get( nameFracL5L7RestrEtaPtFitMean.c_str() ) ) );
        const std::string nameFracL5L7RestrEtaPtFitSigma( name + "_FracL5L7RestrEtaPt_FitSigma" );
        TH1D * histFracL5L7RestrEtaPtFitSigma( ( TH1D* )( dirFit_->Get( nameFracL5L7RestrEtaPtFitSigma.c_str() ) ) );

        TList * listFit( dirFit_->GetListOfKeys() );
        TIter nextInListFit( listFit );
        while ( TKey * keyEta = ( TKey* )nextInListFit() ) {
          if ( std::string( keyEta->GetClassName() ) != nameDirClass ) continue;
          const std::string binEta( keyEta->GetName() );
          const unsigned uEta( std::atoi( binEta.substr( 3 ).data() ) );
          TDirectory * dirEta_( ( TDirectory* )( dirFit_->Get( binEta.c_str() ) ) );

          const std::string nameEta( name + "_" + binEta );
          const std::string strEta( useSymm_ ? " #leq |#eta| < " :  " #leq #eta < ");
          const std::string titleLegendEta( titleLegend + ", " + boost::lexical_cast< std::string >( etaBins.at( uEta ) ) + strEta + boost::lexical_cast< std::string >( etaBins.at( uEta + 1 ) ) );

          const std::string nameEtaFracL5L7( nameEta + "_FracL5L7" );
          const std::string nameEtaFracL5L7Print( plotPath_ + "/" + evtSel_ + "_" + nameEtaFracL5L7 + ".png" );
          TH1D * histEtaFracL5L7( ( TH1D* )( dirEta_->Get( std::string( nameEtaFracL5L7 + ";" + plotCycle_ ).c_str() ) ) );
          if ( plotNonRestr_ && histEtaFracL5L7 != 0 ) {
            TLegend * legEtaFracL5L7Fit( new TLegend( 0.1, 0.67, 0.9, 0.9, titleLegendEta.c_str() ) );
            legEtaFracL5L7Fit->SetTextSize( 0.03 );
            legEtaFracL5L7Fit->SetFillColor( kWhite );
            legEtaFracL5L7Fit->SetFillStyle( 0 );
            legEtaFracL5L7Fit->SetBorderSize( 0 );
            canv->cd();
            histEtaFracL5L7->Draw();
            const std::string nameEtaFracL5L7Fit( nameEtaFracL5L7 + "_fit" );
            TF1 * fitEtaFracL5L7( histEtaFracL5L7->GetFunction( nameEtaFracL5L7Fit.c_str() ) );
            if ( fitEtaFracL5L7 != 0 ) legEtaFracL5L7Fit->AddEntry( fitEtaFracL5L7, fitFunc.c_str() );
            else                      legEtaFracL5L7Fit->AddEntry( histEtaFracL5L7, fitFunc.c_str() );
            const std::string nameEtaFracL5L7Bkg( nameEtaFracL5L7 + "_bkg" );
            TF1 * bkgEtaFracL5L7( ( TF1* )( dirEta_->Get( std::string( nameEtaFracL5L7Bkg + ";" + plotCycle_ ).c_str() ) ) );
            if ( bkgEtaFracL5L7 != 0 ) {
              bkgEtaFracL5L7->SetLineColor( kRed );
              bkgEtaFracL5L7->Draw( "Same" );
              legEtaFracL5L7Fit->AddEntry( bkgEtaFracL5L7, bkgFunc.c_str() );
            }
            legEtaFracL5L7Fit->Draw();
            canv->Print( nameEtaFracL5L7Print.c_str() );
            delete legEtaFracL5L7Fit;
          }

          const std::string nameEtaFracL5L7Restr( nameEtaFracL5L7 + "Restr" );
          const std::string nameEtaFracL5L7RestrPrint( plotPath_ + "/" + evtSel_ + "_" + nameEtaFracL5L7Restr + ".png" );
          TH1D * histEtaFracL5L7Restr( ( TH1D* )( dirEta_->Get( std::string( nameEtaFracL5L7Restr + ";" + plotCycle_ ).c_str() ) ) );
          if ( histEtaFracL5L7Restr != 0 ) {
            TLegend * legEtaFracL5L7RestrFit( new TLegend( 0.1, 0.67, 0.9, 0.9, titleLegendEta.c_str() ) );
            legEtaFracL5L7RestrFit->SetTextSize( 0.03 );
            legEtaFracL5L7RestrFit->SetFillColor( kWhite );
            legEtaFracL5L7RestrFit->SetFillStyle( 0 );
            legEtaFracL5L7RestrFit->SetBorderSize( 0 );
            canv->cd();
            histEtaFracL5L7Restr->Draw();
            const std::string nameEtaFracL5L7RestrFit( nameEtaFracL5L7Restr + "_fit" );
            TF1 * fitEtaFracL5L7Restr( histEtaFracL5L7Restr->GetFunction( nameEtaFracL5L7RestrFit.c_str() ) );
            if ( fitEtaFracL5L7Restr != 0 ) legEtaFracL5L7RestrFit->AddEntry( fitEtaFracL5L7Restr, fitFunc.c_str() );
            else                           legEtaFracL5L7RestrFit->AddEntry( histEtaFracL5L7Restr, fitFunc.c_str() );
            const std::string nameEtaFracL5L7RestrBkg( nameEtaFracL5L7Restr + "_bkg" );
            TF1 * bkgEtaFracL5L7Restr( ( TF1* )( dirEta_->Get( std::string( nameEtaFracL5L7RestrBkg + ";" + plotCycle_ ).c_str() ) ) );
            if ( bkgEtaFracL5L7Restr != 0 ) {
              bkgEtaFracL5L7Restr->SetLineColor( kRed );
              bkgEtaFracL5L7Restr->Draw( "Same" );
              legEtaFracL5L7RestrFit->AddEntry( bkgEtaFracL5L7Restr, bkgFunc.c_str() );
            }
            legEtaFracL5L7RestrFit->Draw();
            canv->Print( nameEtaFracL5L7RestrPrint.c_str() );
            delete legEtaFracL5L7RestrFit;
          }

          // Loop over pt bins

          if ( plotEtaPt_ ) {

            // Fit performance histograms
            if ( plotNonRestr_ ) {
              const std::string nameEtaFracL5L7PtFitMeanMap( nameEta + "_FracL5L7Pt_FitMeanMap" );
              TH1D * histEtaFracL5L7PtFitMeanMap( ( TH1D* )( dirEta_->Get( nameEtaFracL5L7PtFitMeanMap.c_str() ) ) );
            }
            const std::string nameEtaFracL5L7RestrPtFitMeanMap( nameEta + "_FracL5L7RestrPt_FitMeanMap" );
            TH1D * histEtaFracL5L7RestrPtFitMeanMap( ( TH1D* )( dirEta_->Get( nameEtaFracL5L7RestrPtFitMeanMap.c_str() ) ) );

            for ( unsigned uPt = 0; uPt < nPtBins_; ++uPt ) {
              const std::string binPt( boost::lexical_cast< std::string >( uPt ) );
              const std::string nameEtaPt( nameEta + "_Pt" + binPt );
              const std::string titleLegendEtaPt( titleLegendEta + ", " + boost::lexical_cast< std::string >( ptBins.at( uPt ) ) + " GeV #leq p_{t} < " + boost::lexical_cast< std::string >( ptBins.at( uPt + 1 ) ) + " GeV" );

              const std::string nameEtaPtFracL5L7( nameEtaPt + "_FracL5L7" );
              const std::string nameEtaPtFracL5L7Print( plotPath_ + "/" + evtSel_ + "_" + nameEtaPtFracL5L7 + ".png" );
              TH1D * histEtaPtFracL5L7( ( TH1D* )( dirEta_->Get( std::string( nameEtaPtFracL5L7 + ";" + plotCycle_ ).c_str() ) ) );
              if ( plotNonRestr_ && histEtaPtFracL5L7 != 0 ) {
                TLegend * legEtaPtFracL5L7Fit( new TLegend( 0.1, 0.67, 0.9, 0.9, titleLegendEtaPt.c_str() ) );
                legEtaPtFracL5L7Fit->SetTextSize( 0.03 );
                legEtaPtFracL5L7Fit->SetFillColor( kWhite );
                legEtaPtFracL5L7Fit->SetFillStyle( 0 );
                legEtaPtFracL5L7Fit->SetBorderSize( 0 );
                canv->cd();
                histEtaPtFracL5L7->Draw();
                const std::string nameEtaPtFracL5L7Fit( nameEtaPtFracL5L7 + "_fit" );
                TF1 * fitEtaPtFracL5L7( histEtaPtFracL5L7->GetFunction( nameEtaPtFracL5L7Fit.c_str() ) );
                if ( fitEtaPtFracL5L7 != 0 ) legEtaPtFracL5L7Fit->AddEntry( fitEtaPtFracL5L7, fitFunc.c_str() );
                else                      legEtaPtFracL5L7Fit->AddEntry( histEtaPtFracL5L7, fitFunc.c_str() );
                const std::string nameEtaPtFracL5L7Bkg( nameEtaPtFracL5L7 + "_bkg" );
                TF1 * bkgEtaPtFracL5L7( ( TF1* )( dirEta_->Get( std::string( nameEtaPtFracL5L7Bkg + ";" + plotCycle_ ).c_str() ) ) );
                if ( bkgEtaPtFracL5L7 != 0 ) {
                  bkgEtaPtFracL5L7->SetLineColor( kRed );
                  bkgEtaPtFracL5L7->Draw( "Same" );
                  legEtaPtFracL5L7Fit->AddEntry( bkgEtaPtFracL5L7, bkgFunc.c_str() );
                }
                legEtaPtFracL5L7Fit->Draw();
                canv->Print( nameEtaPtFracL5L7Print.c_str() );
                delete legEtaPtFracL5L7Fit;
              }

              const std::string nameEtaPtFracL5L7Restr( nameEtaPtFracL5L7 + "Restr" );
              const std::string nameEtaPtFracL5L7RestrPrint( plotPath_ + "/" + evtSel_ + "_" + nameEtaPtFracL5L7Restr + ".png" );
              TH1D * histEtaPtFracL5L7Restr( ( TH1D* )( dirEta_->Get( std::string( nameEtaPtFracL5L7Restr + ";" + plotCycle_ ).c_str() ) ) );
              if ( histEtaPtFracL5L7Restr != 0 ) {
                TLegend * legEtaPtFracL5L7RestrFit( new TLegend( 0.1, 0.67, 0.9, 0.9, titleLegendEtaPt.c_str() ) );
                legEtaPtFracL5L7RestrFit->SetTextSize( 0.03 );
                legEtaPtFracL5L7RestrFit->SetFillColor( kWhite );
                legEtaPtFracL5L7RestrFit->SetFillStyle( 0 );
                legEtaPtFracL5L7RestrFit->SetBorderSize( 0 );
                canv->cd();
                histEtaPtFracL5L7Restr->Draw();
                const std::string nameEtaPtFracL5L7RestrFit( nameEtaPtFracL5L7Restr + "_fit" );
                TF1 * fitEtaPtFracL5L7Restr( histEtaPtFracL5L7Restr->GetFunction( nameEtaPtFracL5L7RestrFit.c_str() ) );
                if ( fitEtaPtFracL5L7Restr != 0 ) legEtaPtFracL5L7RestrFit->AddEntry( fitEtaPtFracL5L7Restr, fitFunc.c_str() );
                else                           legEtaPtFracL5L7RestrFit->AddEntry( histEtaPtFracL5L7Restr, fitFunc.c_str() );
                const std::string nameEtaPtFracL5L7RestrBkg( nameEtaPtFracL5L7Restr + "_bkg" );
                TF1 * bkgEtaPtFracL5L7Restr( ( TF1* )( dirEta_->Get( std::string( nameEtaPtFracL5L7RestrBkg + ";" + plotCycle_ ).c_str() ) ) );
                if ( bkgEtaPtFracL5L7Restr != 0 ) {
                  bkgEtaPtFracL5L7Restr->SetLineColor( kRed );
                  bkgEtaPtFracL5L7Restr->Draw( "Same" );
                  legEtaPtFracL5L7RestrFit->AddEntry( bkgEtaPtFracL5L7Restr, bkgFunc.c_str() );
                }
                legEtaPtFracL5L7RestrFit->Draw();
                canv->Print( nameEtaPtFracL5L7RestrPrint.c_str() );
                delete legEtaPtFracL5L7RestrFit;
              }

            } // loop: uPt < nPtBins_

          }

        } // loop: keyEta

      } // loop: keyFit

    }

  } // loop: uCat

  delete canv;

  // Close input files
  for ( unsigned uFile = 0; uFile < files_.size(); ++uFile ) files_.at( uFile )->Close();

  return returnStatus_;

}