Example #1
0
void SignfificanceT2tt(bool pval, int exp=0){


    TFile *f = TFile::Open("Significances2DHistograms_T2tt.root");
    TH2F *h;
    if(pval){
        if(exp==0) h = (TH2F*)f->Get("hpObs");
        else if(exp==1) h = (TH2F*)f->Get("hpExpPosteriori");
        else if(exp==2) h = (TH2F*)f->Get("hpExpPriori");
    }
    else {
        if(exp==0) h = (TH2F*)f->Get("hObs");
        else if(exp==1) h = (TH2F*)f->Get("hExpPosteriori");
        else if(exp==2) h = (TH2F*)f->Get("hExpPriori");
    }
    h->GetXaxis()->SetTitle("m_{#tilde{t}} [GeV]");
    h->GetXaxis()->SetLabelFont(42);
    h->GetXaxis()->SetLabelSize(0.035);
    h->GetXaxis()->SetTitleSize(0.05);
    h->GetXaxis()->SetTitleOffset(1.2);
    h->GetXaxis()->SetTitleFont(42);
    h->GetYaxis()->SetTitle("m_{#tilde{#chi}_{1}^{0}} [GeV]");
    h->GetYaxis()->SetLabelFont(42);
    h->GetYaxis()->SetLabelSize(0.035);
    h->GetYaxis()->SetTitleSize(0.05);
    h->GetYaxis()->SetTitleOffset(1.35);
    h->GetYaxis()->SetTitleFont(42);
    double maximum = h->GetMaximum();
    double minimum = h->GetMinimum();
    double sigmin = 99; int sigminx=-1; int sigminy=-1; if(pval) sigmin = -99;
    h->GetZaxis()->SetRangeUser(minimum,maximum);
    for(int x = 1; x<=h->GetNbinsX();++x){
        for(int y = 1; y<=h->GetNbinsX();++y){
            if(!pval&&h->GetBinContent(x,y)<sigmin){ sigmin =h->GetBinContent(x,y); sigminx = x; sigminy = y; }
            if( pval&&h->GetBinContent(x,y)>sigmin){ sigmin =h->GetBinContent(x,y); sigminx = x; sigminy = y; }
            if(!pval&&h->GetXaxis()->GetBinLowEdge(x)<h->GetYaxis()->GetBinLowEdge(y)+75) h->SetBinContent(x,y,-999);
            if(h->GetXaxis()->GetBinLowEdge(x)<374) continue;
            if(h->GetXaxis()->GetBinLowEdge(x)>424) continue;
            if(h->GetYaxis()->GetBinLowEdge(y)<199) continue;
            if(h->GetYaxis()->GetBinLowEdge(y)>249) continue;
            if(!pval&&h->GetBinContent(x,y)>0.3) h->SetBinContent(x,y,0.05);
        }
    }
    h->GetZaxis()->SetRangeUser(minimum,maximum);
    if(!pval) cout << "minimal significance " << sigmin << " at " << h->GetXaxis()->GetBinLowEdge(sigminx) << "-" << h->GetYaxis()->GetBinLowEdge(sigminy) << endl;
    else cout << "maximal p- value " << sigmin << " at " << h->GetXaxis()->GetBinLowEdge(sigminx) << "-" << h->GetYaxis()->GetBinLowEdge(sigminy) << endl;
    
   TCanvas *c1 = new TCanvas("c1", "c1",50,50,600,600);
   gStyle->SetOptFit(1);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);
   gStyle->SetErrorX(0.5); 
   //c1->Range(-6.311689,-1.891383,28.75325,4.56342);
   c1->SetFillColor(0);
   c1->SetBorderMode(0);
   c1->SetBorderSize(2);
   //c1->SetLogy();
   c1->SetTickx(1);
   c1->SetTicky(1);
   c1->SetLeftMargin(0.15);
//   c1->SetRightMargin(0.05);
    c1->SetRightMargin(0.15);
   c1->SetTopMargin(0.07);
   c1->SetBottomMargin(0.15);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
   gStyle->SetHatchesLineWidth(0);

   TH1F *hSum = new TH1F("hSum","",10,100,900);
   hSum->SetMinimum(0.);
   hSum->SetMaximum(550);
   hSum->SetDirectory(0);
   hSum->SetStats(0);
    hSum->Draw();
    hSum->GetYaxis()->SetRangeUser(0,500);
    hSum->GetXaxis()->SetRangeUser(100,900);

   Int_t ci;   // for color index setting
   ci = TColor::GetColor("#000099");
   hSum->SetLineColor(ci);
   hSum->SetLineStyle(0);
   hSum->SetMarkerStyle(20);
   hSum->GetXaxis()->SetTitle("m_{#tilde{t}} [GeV]");
   //hSum->GetXaxis()->SetBit(TAxis::kLabelsVert);
   hSum->GetXaxis()->SetLabelFont(42);
   //hSum->GetXaxis()->SetLabelOffset(0.005);
   hSum->GetXaxis()->SetLabelSize(0.035);
   hSum->GetXaxis()->SetTitleSize(0.06);
   hSum->GetXaxis()->SetTitleOffset(1.2);
   hSum->GetXaxis()->SetTitleFont(42);
   hSum->GetYaxis()->SetTitle("m_{#tilde{#chi}}_{1}^{0} [GeV]");
   hSum->GetYaxis()->SetLabelFont(42);
   //hSum->GetYaxis()->SetLabelOffset(0.007);
   hSum->GetYaxis()->SetLabelSize(0.035);
   hSum->GetYaxis()->SetTitleSize(0.05);
   hSum->GetYaxis()->SetTitleOffset(1.3);
   hSum->GetYaxis()->SetTitleFont(42);
    
   /*
    TLegend *legO = new TLegend(0.175,0.675,0.50,0.855,NULL,"brNDC");
    //legO-> SetNColumns(2);
    legO->SetBorderSize(0);
    legO->SetTextSize(0.04);
    legO->SetTextFont(42);
    legO->SetLineColor(1);
    legO->SetLineStyle(1);
    legO->SetLineWidth(2);
    legO->SetFillColor(0);
    legO->SetFillStyle(1001);
    legO->SetHeader("Observed");
    legO->AddEntry(gObs, "unpolarized","l");
    legO->AddEntry(gObsR, "right-handed","l");
    legO->AddEntry(gObsL, "left-handed","l");
    */
    
    TGraph* graphWhite = new TGraph(5);
    graphWhite->SetName("white");
    graphWhite->SetTitle("white");
    graphWhite->SetFillColor(kWhite);
    graphWhite->SetFillStyle(1001);
    graphWhite->SetLineColor(kBlack);
    graphWhite->SetLineStyle(1);
    graphWhite->SetLineWidth(3);
    graphWhite->SetPoint(0,100, 500);
    graphWhite->SetPoint(1,900, 500);
    graphWhite->SetPoint(2,900, 500*0.75);
    graphWhite->SetPoint(3,100, 500*0.75);
    graphWhite->SetPoint(4,100, 500);
    
    Float_t diagX[4] = {175.+25.,175.+25.+5000,175.-25.+5000,175.-25.};
    Float_t diagY[4] = {0,5000,5000,0};
    TGraph *gdiagonal = new TGraph(4, diagX, diagY);
    gdiagonal->SetName("MtopDiagonal");
    gdiagonal->SetFillColor(kWhite);
    //#gdiagonal->SetFillColor(18);
    TLine* ldiagonal = new TLine(175,0.,650-25.,450);
    //TLine* ldiagonal = new TLine(175.,25,175+500,500);
    ldiagonal->SetLineColor(kGray);
    ldiagonal->SetLineStyle(2);
    TLatex* tdiagonal = new TLatex(400-2.5, 400-172.5,"m_{#tilde{t}} = m_{t} + m_{#tilde{#chi}_{1}^{0}}");
    //tdiagonal->SetTextAngle(TMath::RadToDeg()*TMath::ATan(float(800)/float(500)));
    tdiagonal->SetTextAngle(56.31);
    tdiagonal->SetTextColor(kGray+2);
    tdiagonal->SetTextAlign(11);
    tdiagonal->SetTextSize(0.025);

    TLine* l2 = new TLine(150,75,585,500);
    l2->SetLineColor(kGray);
    l2->SetLineStyle(2);
//    if(killlowdiag){
//        l2->SetX1(200); l2->SetY1(0); l2->SetX2(600); l2->SetY2(400);
//    }
    TLatex *t2 = new TLatex(300, 300-72.5,"m_{#tilde{t}} = m_{W} + m_{#tilde{#chi}_{1}^{0}}");
    //t2->SetTextAngle(TMath::RadToDeg()*TMath::ATan(float(800)/float(500)));
    t2->SetTextAngle(56.31);
    t2->SetTextColor(kGray+2);
    t2->SetTextAlign(11);
    t2->SetTextSize(0.025);
    
    


    hSum->Draw("axis");
    h->Draw("COLZsame");

    gdiagonal->Draw("FSAME");
    ldiagonal->Draw("LSAME");
    l2->Draw();
//    if(!killlowdiag) t2->Draw();
    tdiagonal->Draw("SAME");
    graphWhite->Draw("FSAME");
    graphWhite->Draw("LSAME");

    string textstring = "observed";
    if(exp!=0) textstring = "expected";
    TLatex* textOE= new TLatex(0.175,0.715,textstring.c_str() );
    textOE->SetNDC();
    textOE->SetTextAlign(13);
    textOE->SetTextFont(42);
    textOE->SetTextSize(0.042);
    textOE->Draw();
    

    TLatex* textModelLabel= new TLatex(0.175,0.92,"pp #rightarrow #tilde{t} #tilde{t}*, #tilde{t} #rightarrow t #tilde{#chi}^{0}_{1}");
    //TLatex* textModelLabel= new TLatex(0.175,0.92,"pp #rightarrow #tilde{t} #tilde{t}*, #tilde{t} #rightarrow t #tilde{#chi}^{0}_{1}");
    //TLatex* textModelLabel= new TLatex(0.175,0.92,"#tilde{#chi} ");
    textModelLabel->SetNDC();
    textModelLabel->SetTextAlign(13);
    textModelLabel->SetTextFont(42);
    textModelLabel->SetTextSize(0.042);
    textModelLabel->Draw();
    TLatex* textlLabel= new TLatex(0.175,0.85,"NLO+NLL significance");
    textlLabel->SetNDC();
    textlLabel->SetTextAlign(13);
    textlLabel->SetTextFont(42);
    textlLabel->SetTextSize(0.042);
    textlLabel->Draw();
    
    string psig = "significance [#sigma]";
    if(pval) psig = "p-value";
    TLatex * ztex = new TLatex(0.985,0.92,psig.c_str() );
    ztex->SetNDC();
    ztex->SetTextAlign(31);
    ztex->SetTextFont(42);
    ztex->SetTextSize(0.045);
    ztex->SetTextAngle(90);
    ztex->SetLineWidth(2);
    ztex->Draw();
    
    //final CMS style
    TLatex *tLumi = new TLatex(0.81,0.944,"2.3 fb^{-1} (13 TeV)");
    tLumi->SetNDC();
    tLumi->SetTextAlign(31);
    tLumi->SetTextFont(42);
    tLumi->SetTextSize(0.042);
    tLumi->SetLineWidth(2);
    tLumi->Draw();
    TLatex *tCMS = new TLatex(0.152,0.944,"CMS");
    tCMS->SetNDC();
    tCMS->SetTextAlign(11);
    tCMS->SetTextFont(61);
    tCMS->SetTextSize(0.0525);
    tCMS->SetLineWidth(2);
    tCMS->Draw();
    TLatex *tPrel = new TLatex(0.265,0.944,"Preliminary");
    tPrel->SetNDC();
    tPrel->SetTextAlign(11);
    tPrel->SetTextFont(52);
    tPrel->SetTextSize(0.042);
    tPrel->SetLineWidth(2);
    tPrel->Draw();
    
   c1->Modified();
   c1->cd();
    c1->Update();
   c1->SetSelected(c1);

}
Example #2
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// drawFigure6
//
//    logy = 0
//    logy = 1
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void drawFigure6(Int_t logy = 0)
{
  gInterpreter->ExecuteMacro("WZPaperStyle.C");

  gSystem->mkdir("pdf", kTRUE);
  gSystem->mkdir("png", kTRUE);


  // Read the input file
  //----------------------------------------------------------------------------
  TString name = "WZ_PtZ_plot_allCh_largeATGC";

  TFile* file = new TFile("rootfiles/" + name + ".root", "read");

  TCanvas* c1 = (TCanvas*)file->Get("c1_allCh");

  TH1F* data     = (TH1F*)c1->FindObject("histo_data_3e");
  TH1F* aTGC_dk  = (TH1F*)c1->FindObject("histo_aTGC_dk_3e");
  TH1F* aTGC_lam = (TH1F*)c1->FindObject("histo_aTGC_lam_3e");
  TH1F* aTGC_dg  = (TH1F*)c1->FindObject("histo_aTGC_dg_3e");
  TH1F* WZ       = (TH1F*)c1->FindObject("histo_SM_3e");
  TH1F* fakes    = (TH1F*)c1->FindObject("fake_0");
  TH1F* ZZ       = (TH1F*)c1->FindObject("total_bkg_rebined_ZZ_0");
  TH1F* Zgamma   = (TH1F*)c1->FindObject("total_bkg_rebined_Zgamma_0");
  TH1F* WV       = (TH1F*)c1->FindObject("total_bkg_rebined_WV_0");
  TH1F* VVV      = (TH1F*)c1->FindObject("total_bkg_rebined_VVV_0");

  WZ->SetFillColor(kOrange-2);
  WZ->SetLineColor(kOrange-2);

  Zgamma->SetFillColor(kRed+1);
  Zgamma->SetLineColor(kRed+1);

  ZZ->SetFillColor(kRed+1);
  ZZ->SetLineColor(kRed+1);

  fakes->SetFillColor(kGray+1);
  fakes->SetLineColor(kGray+1);

  WV->SetFillColor(kRed+1);
  WV->SetLineColor(kRed+1);

  VVV->SetFillColor(kRed+1);
  VVV->SetLineColor(kRed+1);


  // Draw
  //----------------------------------------------------------------------------
  TCanvas* canvas = new TCanvas("canvas", "canvas");

  canvas->SetLogy(logy);

  data->Draw("ep");


  // Axis labels
  //----------------------------------------------------------------------------
  TAxis* xaxis = data->GetXaxis();
  TAxis* yaxis = data->GetYaxis();
  
  xaxis->SetLabelFont  (  42);
  xaxis->SetLabelOffset(0.01);
  xaxis->SetLabelSize  (0.05);
  xaxis->SetNdivisions ( 505);
  xaxis->SetTitleFont  (  42);
  xaxis->SetTitleOffset( 1.2);
  xaxis->SetTitleSize  (0.05);

  yaxis->SetLabelFont  (  42);
  yaxis->SetLabelOffset(0.01);
  yaxis->SetLabelSize  (0.05);
  yaxis->SetNdivisions ( 505);
  yaxis->SetTitleFont  (  42);
  yaxis->SetTitleOffset( 1.6);
  yaxis->SetTitleSize  (0.05);

  xaxis->SetTitle("p_{T}^{Z} (GeV)");
  yaxis->SetTitle(Form("Events /  %.0f GeV", data->GetBinWidth(0)));


  // Adjust scale
  //----------------------------------------------------------------------------
  Float_t theMax   = GetMaximumIncludingErrors(data);
  Float_t theMaxMC = GetMaximumIncludingErrors(aTGC_dk);

  if (theMaxMC > theMax) theMax = theMaxMC;

  if (canvas->GetLogy()) {
    data->SetMaximum(15 * theMax);
    data->SetMinimum(1);
  } else {
    data->SetMaximum(1.2 * theMax);
  }


  // Legend
  //----------------------------------------------------------------------------
  Double_t x0;
  Double_t y0;

  if (logy)
    {
      x0 = 0.630;
      y0 = 0.765;

      DrawTLegend(x0 - 0.37, y0 + 2.*(_yoffset+0.001), data,     " Data",                              "ep");
      DrawTLegend(x0 - 0.37, y0 + 1.*(_yoffset+0.001), aTGC_dk,  " WZ aTGC (#Delta#kappa^{Z} = 0.6)",  "l");
      DrawTLegend(x0 - 0.37, y0,                       aTGC_dg,  " WZ aTGC (#Deltag^{Z}_{1} = -0.06)", "l");
      DrawTLegend(x0 - 0.37, y0 - 1.*(_yoffset+0.001), aTGC_lam, " WZ aTGC (#lambda = 0.04)",          "l");
      DrawTLegend(x0,        y0 + 2.*(_yoffset+0.001), WZ,       " WZ",                                "f");
      DrawTLegend(x0,        y0 + 1.*(_yoffset+0.001), fakes,    " Non-prompt leptons",                "f");
      DrawTLegend(x0,        y0,                       ZZ,       " MC background",                     "f");
    }
  else
    {
      x0 = 0.570;
      y0 = 0.755;

      DrawTLegend(x0, y0 + 2.*(_yoffset+0.001), data,     " Data",                              "ep");
      DrawTLegend(x0, y0 + 1.*(_yoffset+0.001), aTGC_dk,  " WZ aTGC (#Delta#kappa^{Z} = 0.6)",  "l");
      DrawTLegend(x0, y0,                       aTGC_dg,  " WZ aTGC (#Deltag^{Z}_{1} = -0.06)", "l");
      DrawTLegend(x0, y0 - 1.*(_yoffset+0.001), aTGC_lam, " WZ aTGC (#lambda = 0.04)",          "l");
      DrawTLegend(x0, y0 - 2.*(_yoffset+0.001), WZ,       " WZ",                                "f");
      DrawTLegend(x0, y0 - 3.*(_yoffset+0.001), fakes,    " Non-prompt leptons",                "f");
      DrawTLegend(x0, y0 - 4.*(_yoffset+0.001), ZZ,       " MC background",                     "f");
    }


  // Finish it
  //----------------------------------------------------------------------------
  data->SetTitle("");

  if (logy)
    {
      DrawTLatex(_cmsTextFont,   0.190, 0.94, 0.055, 11, "CMS");
      //      DrawTLatex(_extraTextFont, 0.315, 0.94, 0.030, 11, "Preliminary");
    }
  else
    {
      DrawTLatex(_cmsTextFont,   0.215, 0.891, 0.055, 13, "CMS");
      //      DrawTLatex(_extraTextFont, 0.215, 0.837, 0.030, 13, "Preliminary");
    }

  DrawTLatex(_lumiTextFont, 0.940, 0.94, 0.040, 31, "19.6 fb^{-1} (8 TeV)");

  WZ      ->Draw("hist,same");
  aTGC_dk ->Draw("hist,same");
  aTGC_lam->Draw("hist,same");
  aTGC_dg ->Draw("hist,same");
  fakes   ->Draw("hist,same");
  ZZ      ->Draw("hist,same");
  Zgamma  ->Draw("hist,same");
  WV      ->Draw("hist,same");
  VVV     ->Draw("hist,same");
  data    ->Draw("ep,same");

  canvas->GetFrame()->DrawClone();
  canvas->RedrawAxis();
  canvas->Update();
  
  TString cname = name;

  if (logy) cname += "_log_range";

  canvas->SaveAs("pdf/" + cname + ".pdf");
  canvas->SaveAs("png/" + cname + ".png");
}
void plotTreeNorms(TTree *tree_, std::string selectString, bool do7TeV){

	// Create a map for plotting the pullsummaries:
	std::map < const char*, std::pair <double,double> > pullSummaryMap;
	int nPulls=0;

	TObjArray *l_branches = tree_->GetListOfBranches();
	int nBranches = l_branches->GetEntries();

	gStyle->SetPadTopMargin(0.01);

	TCanvas *c = new TCanvas("c","",960,800);

	std::string treename = tree_->GetName();
	c->SaveAs(Form("%s_normresiduals.pdf[",treename.c_str()));
	// File to store plots in 
	TFile *fOut = new TFile(Form("%s_normresiduals.root",treename.c_str()),"RECREATE");

        TH1F *bHd = new TH1F("bHd","",50,-1.0,1.0);
        TH1F *bHfd = new TH1F("bHfd","",50,-1.0,1.0);

	for (int iobj=0;iobj<nBranches;iobj++){

		TBranch *br =(TBranch*) l_branches->At(iobj);

		// Draw the normal histogram
		const char* name = br->GetName();

                // select only the normalizations
                string namestr(name);
                if(namestr.find("n_exp")==string::npos) continue;

                bool fitPull=true;
                bool fitPullf=true;

		double p_mean =0;

		int nToysInTree = tree_->GetEntries();
		// Find out if paramter is fitted value or constraint term.
                bool isFitted = true;
			
                p_mean = prenorms_[name].first;	// toy initial parameters from the datacards
                std::cout << "******* "<< name << " *******"<<std::endl;
                std::cout << p_mean << std::endl;
                std::cout << "******************************" <<std::endl;

                TH1F* bH = (TH1F*)bHd->Clone(Form("%s",name));
                TH1F* bHf = (TH1F*)bHfd->Clone(Form("%s_fail",name));
                
                const char* drawInput = Form("(%s-%f)/%f",name,p_mean,p_mean);
                tree_->Draw(Form("%s>>%s",drawInput,name),"");
                tree_->Draw(Form("%s>>%s_fail",drawInput,name),selectString.c_str(),"same");
                fitPull  = true;
                fitPullf = true;
                  
		bHf->SetLineColor(2);
		bH->GetXaxis()->SetTitle(bH->GetTitle());
		bH->GetYaxis()->SetTitle(Form("no toys (%d total)",nToysInTree));
		bH->GetYaxis()->SetTitleOffset(1.05);
		bH->GetXaxis()->SetTitleOffset(0.9);
		bH->GetYaxis()->SetTitleSize(0.05);
		bH->GetXaxis()->SetTitleSize(0.05);
		bH->GetXaxis()->SetTitle(Form("%s",name));
                
		
		bH->SetTitle("");	

		if ( bH->Integral() <=0 )  fitPull = false;
		if (fitPull) {bH->Fit("gaus"); bH->GetFunction("gaus")->SetLineColor(4);}
		
		if ( bHf->Integral() <=0 )  fitPullf = false;
		if (fitPullf) {bHf->Fit("gaus"); bHf->GetFunction("gaus")->SetLineColor(2);}

		c->Clear();
		
 		TPad pad1("t1","",0.01,0.01,0.66,0.95);
 		TPad pad2("t2","",0.70,0.20,0.98,0.80);

		pad1.SetNumber(1); pad2.SetNumber(2);

                if ( isFitted ) {pad2.Draw();}

		pad1.Draw();
		pad1.SetGrid(true);


		TLatex *titletext = new TLatex();titletext->SetNDC();

		
		c->cd(1); bH->Draw(); bHf->Draw("same");
		TLegend *legend = new TLegend(0.6,0.8,0.9,0.89);
		legend->SetFillColor(0);
		legend->AddEntry(bH,"All Toys","L");
		legend->AddEntry(bHf,selectString.c_str(),"L");
		legend->Draw();

		if (fitPull){
			c->cd(2);
			double gap;
			TLatex *tlatex = new TLatex(); tlatex->SetNDC(); 
			if (fitPullf) {tlatex->SetTextSize(0.09); gap=0.12;}
			else  {tlatex->SetTextSize(0.11);gap=0.14;}

			tlatex->SetTextColor(4);
			tlatex->DrawLatex(0.11,0.80,Form("Mean    : %.3f #pm %.3f",bH->GetFunction("gaus")->GetParameter(1),bH->GetFunction("gaus")->GetParError(1)));
			tlatex->DrawLatex(0.11,0.80-gap,Form("Sigma   : %.3f #pm %.3f",bH->GetFunction("gaus")->GetParameter(2),bH->GetFunction("gaus")->GetParError(2)));

			if (fitPullf){ 
				tlatex->SetTextColor(2);
				tlatex->DrawLatex(0.11,0.60,Form("Mean    : %.3f #pm %.3f",bHf->GetFunction("gaus")->GetParameter(1),bHf->GetFunction("gaus")->GetParError(1)));
				tlatex->DrawLatex(0.11,0.60-gap,Form("Sigma   : %.3f #pm %.3f",bHf->GetFunction("gaus")->GetParameter(2),bHf->GetFunction("gaus")->GetParError(2)));
			}

			tlatex->SetTextSize(0.10);
			tlatex->SetTextColor(1);
				
                        tlatex->DrawLatex(0.11,0.33,Form("Pre-fit: %.3f",p_mean));
			
			pullSummaryMap[name]=std::make_pair<double,double>(bH->GetFunction("gaus")->GetParameter(1),bH->GetFunction("gaus")->GetParameter(2));
			nPulls++;

		}

		// double titleSize = isFitted ? 0.1 : 0.028;
		//titletext->SetTextSize(titleSize);titletext->SetTextAlign(21); titletext->DrawLatex(0.55,0.92,name);
		c->SaveAs(Form("%s_normresiduals_%s.pdf",treename.c_str(),(do7TeV ? "7TeV": "8TeV")));
                c->SaveAs(Form("mlfit/%s_residual_%s_%s.pdf",name,treename.c_str(),(do7TeV ? "7TeV": "8TeV")));
		fOut->WriteObject(c,Form("%s_%s",treename.c_str(),name));
	}
	
	if (nPulls>0){
	  
	    std::cout << "Generating Pull Summaries" <<std::endl; 
	    int nRemainingPulls = nPulls;
	    TCanvas *hc = new TCanvas("hc","",3000,2000); hc->SetGrid(0);
	    std::map < const char*, std::pair <double,double> >::iterator pull_it = pullSummaryMap.begin();
	    std::map < const char*, std::pair <double,double> >::iterator pull_end = pullSummaryMap.end();

	    int pullPlots = 1;
	    while (nRemainingPulls > 0){

		int nThisPulls = min(maxPullsPerPlot,nRemainingPulls);

		TH1F pullSummaryHist("pullSummary","",nThisPulls,0,nThisPulls);
		for (int pi=1;pull_it!=pull_end && pi<=nThisPulls ;pull_it++,pi++){
			pullSummaryHist.GetXaxis()->SetBinLabel(pi,(*pull_it).first);
			pullSummaryHist.SetBinContent(pi,((*pull_it).second).first);
			pullSummaryHist.SetBinError(pi,((*pull_it).second).second);
			nRemainingPulls--;
		}		

		pullSummaryHist.SetMarkerStyle(21);pullSummaryHist.SetMarkerSize(1.5);pullSummaryHist.SetMarkerColor(2);pullSummaryHist.SetLabelSize(pullLabelSize);
		pullSummaryHist.GetYaxis()->SetRangeUser(-1,1);pullSummaryHist.GetYaxis()->SetTitle("residual summary (relative)");pullSummaryHist.Draw("E1");
		hc->SaveAs(Form("%s_normresiduals_%s.pdf",treename.c_str(),(do7TeV ? "7TeV": "8TeV")));
                hc->SaveAs(Form("mlfit/residual_summary_%d_%s_%s.pdf",pullPlots,treename.c_str(),(do7TeV ? "7TeV": "8TeV")));
		fOut->WriteObject(hc,Form("comb_pulls_%s_%d",treename.c_str(),pullPlots));
	//	hc->SaveAs(Form("comb_pulls_%s_%d.pdf",treename.c_str(),pullPlots));
		pullPlots++;
	   }

	    delete hc;
	}

	c->SaveAs(Form("%s_normresiduals_%s.pdf]",treename.c_str(),(do7TeV ? "7TeV": "8TeV")));
	fOut->Close();
	delete c;
	return;


}
Example #4
0
void analyzer_stack() {

//int main(){

    const int nfiles  = 8;
    const int nhistos = 46;
    const int ndiscr = 5;
    TString leg_names[nfiles] = {/*"powheg, m(H) = 130 GeV","[email protected], m(H) = 125 GeV",*/"powheg, m(H) = 125 GeV" ,"QCD, H_{T}=100-200 GeV","QCD, H_{T}=200-300 GeV","QCD, H_{T}=300-500 GeV","QCD, H_{T}=500-700 GeV","QCD, H_{T}=700-1000 GeV","QCD, H_{T}=1500-2000 GeV","QCD, H_{T}=2000-Inf GeV"};
    TString file_names[nfiles] = {/*"Spring15_powheg_M130","Spring15_amcatnlo_M125",*/"Spring15_powheg_M125","Spring15_QCD_HT100to200","Spring15_QCD_HT200to300","Spring15_QCD_HT300to500","Spring15_QCD_HT500to700","Spring15_QCD_HT700to1000","Spring15_QCD_HT1500to2000","Spring15_QCD_HT2000toInf"};
    for (int i=0; i<nfiles; i++) {
//	file_names[i].Prepend("SingleBtag_");
        file_names[i].Prepend("../data40pb/tree");
        file_names[i].Append(".root");
    }
    TString trigger = "DoubleBtag_";
//TString trigger = "SingleBtag_";
//TString dir_name= "plots_powheg_130/";
    TString dir_name= "plots_powheg_125/";
//TString dir_name = "plots_amc/";


    Double_t xsec[nfiles] = {  /* 1.96, 2.16,*/2.16, 2.75E07,  6.52E03,  3.67E05, 2.94E04, 2.54E01,  1.74E06, 121.5 };


    TLegend *leg = new TLegend(0.35,0.58,0.75,0.88);
    leg->SetBorderSize(0);
    leg->SetTextSize(0.04);

    TString hist_names[nhistos]= {"hJet1_pt","hJet2_pt","hJet3_pt","hJet4_pt","hJet1_eta","hJet2_eta","hJet3_eta","hJet4_eta","hJet1_phi","hJet2_phi","hJet3_phi","hJet4_phi","hMqq", "hEtaQQ", "hPhiBB", "hEtaSoftJets", "hPtSoftJets","hMassSoftJets","hHTsoft","hSoft_n2","hSoft_n5","hSoft_n10","hMbb","hqgl","hbtag","hqgl2","hbtag2","hPtSoftJets2","hPtSoftJets3","hcosOqqbb","hEtaQB1", "hEtaQB2", "hPhiQB1", "hPhiQB2","hx1","hx2","hVB1_mass","hVB2_mass","hEtot","hPxtot","hPytot","hPztot","hJet5_pt","hPtqqbb","hEtaqqbb","hPhiqqbb"};
    std::string hist_names_sort[nhistos];
    for (int i=0; i<nhistos; i++) {
        hist_names_sort[i] = hist_names[i];
    }
    Float_t discriminators[nhistos];
    TString stacks_names[nhistos];
    for (int i=0; i<nhistos; i++) {
        stacks_names[i] = hist_names[i];
        stacks_names[i].Prepend("s");
    }
    TString output_names[nhistos];
    for (int i=0; i<nhistos; i++) {
        output_names[i] = hist_names[i];
        output_names[i].Prepend(dir_name);
        output_names[i].Prepend(trigger);
        output_names[i].Append(".png");
    }
    const char *xaxis_names[100] = {"1^{st} Jet p_{T} (GeV)","2^{nd} Jet p_{T} (GeV)","3^{rd} Jet p_{T} (GeV)","4^{th} Jet p_{T} (GeV)","1^{st} Jet #eta", "2^{nd} Jet #eta", "3^{rd} Jet #eta", "4^{th} Jet #eta", "1^{st} Jet #phi", "2^{nd} Jet #phi", "3^{rd} Jet #phi", "4^{th} Jet #phi","m_{qq} (GeV)","|#Delta#eta_{qq}|","|#Delta#phi_{bb}|","#eta^{soft}","1^{st} Soft jet p_{T} (GeV)","m^{soft} (GeV)","H_{T}^{soft} (GeV)","N^{soft}","m_{bb} (GeV)", "QGL of the first quark jet candidate","CSV of 1^{st} b-jet","QGL of the second quark jet candidate","CSV of 2^{nd} b-jet","2^{nd} Soft jet p_{T} (GeV)","3^{rd} Soft jet p_{T} (GeV)","H_{T}^{soft 3 jets} (GeV)","cos#theta_{qqbb}","#Delta#eta_{qb}^{forward}","#Delta#eta_{qb}^{backward}","|#Delta#phi_{qb}^{forward}|","|#Delta#phi_{qb}^{backward}|","x_{1}","x_{2}","M_{W'_{1}} (GeV)","M_{W'_{2}} (GeV)","E^{tot} (GeV)","p_{x}^{tot} (GeV)","p_{y}^{tot} (GeV)","p_{z}^{tot} (GeV)", "5^{th} Jet p_{T} (GeV)"};

    TH1F *signal_histos[100];
    TH1F *discr_histos[100];//Mqq,delta eta, delta phi, qgl, btag //12,13,14,21,22
    int discr_index[100] = {12,13,14,21,22};//not used now
    int files=0;
    THStack *stacks[100];
    for (int i=0; i<nhistos; ++i) {
        stacks[i] = new THStack(stacks_names[i],"");
    }
    Double_t totalBG=0.;
    ofstream out_efficiency;
    ofstream out_discrimination;
    out_efficiency.open(trigger+dir_name+"efficiency.txt");
    do {

        TFile *file_initial = new TFile(file_names[files]);
        file_initial->ls();

        TString temp_number;
        temp_number.Form("%d",files);
        TH1F *histos[100];
        for (int hist=0; hist<nhistos; ++hist) {
            histos[hist] = (TH1F*)file_initial->Get(hist_names[hist]);
            histos[hist]->Sumw2(kFALSE);
//		histos[hist]->Scale(40.);
            if (files==0) signal_histos[hist] = (TH1F*)file_initial->Get(hist_names[hist]);
//		signal_histos[hist]->Scale(40.);
            //	histos[hist]->SetLineColor(1+files);
            //	histos[hist]->SetFillColor(1+files);
            if (files==1) {
                histos[hist]->SetFillColor(kBlue-10);
                histos[hist]->SetLineColor(kBlue-10);
            }
            if (files==2) {
                histos[hist]->SetFillColor(kBlue);
                histos[hist]->SetLineColor(kBlue);
            }
            if (files==3) {
                histos[hist]->SetFillColor(kOrange);
                histos[hist]->SetLineColor(kOrange);
            }
            if (files==4) {
                histos[hist]->SetFillColor(kRed);
                histos[hist]->SetLineColor(kRed);
            }
            if (files==5) {
                histos[hist]->SetFillColor(kAzure+10);
                histos[hist]->SetLineColor(kAzure+10);
            }
            if (files==6) {
                histos[hist]->SetFillColor(kGreen+2);
                histos[hist]->SetLineColor(kGreen+2);
            }
            if (files==7) {
                histos[hist]->SetFillColor(kPink+9);
                histos[hist]->SetLineColor(kPink+9);
            }
            if (files==0) {
                histos[hist]->SetFillStyle(3324);
                histos[hist]->SetFillColor(1);
                histos[hist]->SetLineColor(1);
                signal_histos[hist]->SetFillStyle(3324);
                signal_histos[hist]->SetLineColor(1);
                signal_histos[hist]->SetFillColor(1);
            }
            if (files>=0)stacks[hist]->Add(histos[hist]);
            if (hist==0) leg->AddEntry(histos[hist],leg_names[files],"F");
            if (files==1) {
                discr_histos[hist] = (TH1F*)file_initial->Get(hist_names[hist]);
            }
            if ((files>1)) {
                discr_histos[hist]->Add(histos[hist]);
            }
        }
        if (files!=0) totalBG+=histos[4]->Integral();
        if (files==0) out_efficiency<<"Sample & \t\t\t yield(per $fb^{-1}$)& \t efficiency"<<endl;
        if (files==0) out_efficiency<<leg_names[files]<<"&\t \t \t"<<histos[5]->Integral()*1000. <<"&\t"<< histos[5]->Integral()/xsec[files] <<endl;
        else out_efficiency<<leg_names[files]<<"&\t  "<<histos[4]->Integral()*1000. <<"&\t"<< histos[4]->Integral()/xsec[files] <<endl;
        if (files==nfiles-1) out_efficiency<<"Total BG"<<"&\t \t \t  "<<totalBG*1000.<< endl;
        files++;
    } while (files<nfiles);
    out_efficiency.close();

    for (int d=0; d<nhistos; d++) {
        discriminators[d] = Discr(discr_histos[d],signal_histos[d]);
    }

    bubblesort(discriminators, hist_names_sort,nhistos);

    out_discrimination.open(trigger+dir_name+"discrimination.txt");
    for (int d=0; d<nhistos; d++) {
        if (d==0) out_discrimination<<"Variable &\t d"<<endl;
        out_discrimination<<"$"<<hist_names_sort[d]<<"$"<<" & \t "<< std::setprecision(2)<< discriminators[d]<<endl;
    }
    out_discrimination.close();
    TLatex* tex = new TLatex(0.90,0.92,"13 TeV, PU = 20, bx = 25 ns, 1 pb^{-1}");
    tex->SetNDC();
    tex->SetTextAlign(35);
    tex->SetTextFont(42);
    tex->SetTextSize(0.04);
    tex->SetLineWidth(2);
    TLatex *tex1 = new TLatex(0.13,0.83,"CMS");
    tex1->SetNDC();
    tex1->SetTextAlign(20);
    tex1->SetTextFont(61);
    tex1->SetTextSize(0.06);
    tex1->SetLineWidth(2);
    TLatex* tex2 = new TLatex(0.22,0.77,"Work in progress");
    tex2->SetNDC();
    tex2->SetTextAlign(20);
    tex2->SetTextFont(52);
    tex2->SetTextSize(0.04);
    tex2->SetLineWidth(2);
    TLatex* tex_file = new TLatex(0.35,0.92,"Spring15, DoubleBtag");
    //	TLatex* tex_file = new TLatex(0.35,0.92,"Spring15, SingleBtag");
    tex_file->SetNDC();
    tex_file->SetTextAlign(35);
    tex_file->SetTextFont(42);
    tex_file->SetTextSize(0.04);
    tex_file->SetLineWidth(2);
    for (int i=0; i<nhistos; i++) {
        TString temp_str;
        temp_str.Form("%2.2f",Discr(discr_histos[i],signal_histos[i]));
        TString disc_value = temp_str.Prepend(", d = ");
        TLatex *disc_value_text = new TLatex(0.86,0.853,disc_value);
        disc_value_text->SetNDC();
        disc_value_text->SetTextAlign(35);
        disc_value_text->SetTextFont(42);
        disc_value_text->SetTextSize(0.04);
        disc_value_text->SetLineWidth(2);

        TCanvas *c1 = new TCanvas();
        c1->SetBottomMargin(.12);
        c1->cd();
        c1->SetLogy();
        Double_t xmin = signal_histos[i]->GetBinCenter(0);
        Double_t xmax = signal_histos[i]->GetBinCenter(signal_histos[i]->GetNbinsX());
        TH1F *frame = new TH1F("frame","",1,xmin,xmax);
        frame->SetMinimum(1e-4);
        frame->SetMaximum(1e10);
        frame->GetYaxis()->SetTitleOffset(0.9);
        frame->GetXaxis()->SetTitleOffset(0.91);
        frame->SetStats(0);
        frame->SetTitleFont(42,"x");
        frame->SetTitleFont(42,"y");
        frame->SetTitleSize(0.05, "XYZ");
        frame->SetXTitle(signal_histos[i]->GetXaxis()->GetTitle());

        if ((i<4))frame->SetYTitle("Events  /  20 GeV");
        else if (i==37)frame->SetYTitle("Events  /  20 GeV");
        else if (i==41)frame->SetYTitle("Events  /  20 GeV");
        else if ((i>=4) && (i<8)) frame->SetYTitle("Events  /  0.5");
        else if (i==15) frame->SetYTitle("Events  /  0.5");
        else if ((i>=8) && (i<12)) frame->SetYTitle("Events  /  0.2");
        else if (i==40) frame->SetYTitle("Events / 100 GeV");
        else if ((i==10)||(i==12)||(i==16)||(i==17)||(i==18) || (i==20) || (i==25) || (i==26) || (i==27) || (i==35) || (i==36) ||(i==38) || (i==39)) frame->SetYTitle("Events / 10 GeV");
        else if ((i==13)||(i==14)) frame->SetYTitle("Events / 0.1");
        else if ((i==21)||(i==22)) frame->SetYTitle("Events / 0.05");
        else if ((i==23)||(i==24)) frame->SetYTitle("Events / 0.01");
        else if (i==28) frame->SetYTitle("Events / 0.02");
        else if ((i==29) || (i==30) || (i==31) || (i==32) )frame->SetYTitle("Events / 0.1");
        else if ((i==33) || (i==33))frame->SetYTitle("Events / 0.01");
        else frame->SetYTitle("Events");
        frame->Draw();
        tex->Draw();
        tex1->Draw();
        tex2->Draw();
        tex_file->Draw();
        stacks[i]->Draw("nostacksame");
        leg->Draw("same");
        signal_histos[i]->Draw("same");
        disc_value_text->Draw();
        c1->Print(output_names[i]);
        c1->Delete();
    }

}
int
TrackParametrization( TString csvfile="fitslices_out.csv" )
{

  /* Read data from input file */
  TTree *tres = new TTree();
  tres->ReadFile( csvfile, "ptrue:etatrue:psig:psig_err:pmean:pmean_err:norm", ',' );

  /* Print read-in tree */
  tres->Print();

  /* colors array */
  unsigned colors[8] = {1,2,3,4,6,7,14,16};

  /* Create vector of theta values to include for visualization*/
  vector< double > etas_vis;
  etas_vis.push_back(-2.75);
  etas_vis.push_back(-2.25);
  etas_vis.push_back(-1.75);
  etas_vis.push_back(-0.25);
  etas_vis.push_back( 0.25);
  etas_vis.push_back( 1.75);
  etas_vis.push_back( 2.25);

//  etas_vis.push_back(-3.25);
//  etas_vis.push_back(-2.25);
//  etas_vis.push_back(-1.25);
//  etas_vis.push_back(-0.25);
//  etas_vis.push_back( 0.25);
//  etas_vis.push_back( 1.25);
//  etas_vis.push_back( 2.25);
//  etas_vis.push_back( 3.25);

  /* Create vector of theta values to include for fitting*/
  vector< double > etas_fit;
  for ( double eta = -4.45; eta < 4.5; eta += 0.1 )
    etas_fit.push_back( eta );

  /* Create fit function */
  TF1* f_momres = new TF1("f_momres", "sqrt( [0]*[0] + [1]*[1]*x*x )" );

  cout << "\nFit function: " << f_momres->GetTitle() << "\n" << endl;

  /* Create scratch canvas */
  TCanvas *cscratch = new TCanvas("cscratch");

  /* Create framehistogram */
  TH1F* hframe = new TH1F("hframe","",100,0,40);
  hframe->GetYaxis()->SetRangeUser(0,0.15);
  hframe->GetYaxis()->SetNdivisions(505);
  hframe->GetXaxis()->SetTitle("Momentum (GeV/c)");
  hframe->GetYaxis()->SetTitle("#sigma_{p}/p");

  /* create combined canvas plot */
  TCanvas *c1 = new TCanvas();
  hframe->Draw();

  /* Create legend */
  TLegend* leg_eta = new TLegend( 0.2, 0.6, 0.5, 0.9);
  leg_eta->SetNColumns(2);

  /* Create ofstream to write fit parameter results */
  ofstream ofsfit("track_momres_new.csv");
  ofsfit<<"eta,par1,par1err,par2,par2err"<<endl;

  /* Create resolution-vs-momentum plot with fits for each selected theta value */
  for ( int i = 0; i < etas_fit.size(); i++ )
    {
      /* Switch to scratch canvas */
      cscratch->cd();

      double eta = etas_fit.at(i);

      /* No tracking outside -4 < eta < 4 */
      if ( eta < -4 || eta > 4 )
	continue;

      cout << "\n***Eta = " << eta << endl;

      /* Define range of theta because float comparison with fixed value doesn't work
	 too well for cuts in ROOT trees */
      double eta_min = eta * 0.999;
      double eta_max = eta * 1.001;

      /* Cut for tree */
      TCut cutx( Form("ptrue > 1 && ( (etatrue > 0 && (etatrue > %f && etatrue < %f)) || (etatrue < 0 && (etatrue < %f && etatrue > %f)) )", eta_min, eta_max, eta_min, eta_max) );

      /* "Draw" tree on scratch canvas to fill V1...V4 arrays */
      tres->Draw("psig:ptrue:psig_err:0", cutx );

      /* Create TGraphErrors with selected data from tree */
      TGraphErrors *gres = new TGraphErrors( tres->GetEntries(cutx),
					     &(tres->GetV2())[0],
					     &(tres->GetV1())[0],
					     &(tres->GetV4())[0],
					     &(tres->GetV3())[0] );

      /* reset function parameters before fit */
      f_momres->SetParameter(0,0.1);
      f_momres->SetParameter(1,0.1);

      /* Only plot pseudorapidities listed on etas_vis; if not plotting, still do the fit */
      bool vis = false;
      int vi = 0;

      for ( vi = 0; vi < etas_vis.size(); vi++ )
	{
	  if ( abs( etas_vis.at(vi) - eta ) < 0.001 )
	    {
	      vis = true;
	      break;
	    }
	}

      if ( vis )
	{
	  /* Add graph to legend */
	  leg_eta->AddEntry(gres, Form("#eta = %.1f", eta), "P");

	  /* Add graph to plot */
	  c1->cd();
	  gres->SetMarkerColor(colors[vi]);
	  gres->Draw("Psame");
	  f_momres->SetLineColor(colors[vi]);
	  gres->Fit(f_momres);
	}
      else
	{
	  gres->Fit(f_momres);
	}

      /* Write fir results to file */
      double par1 = f_momres->GetParameter(0);
      double par1err = f_momres->GetParError(0);
      double par2 = f_momres->GetParameter(1);
      double par2err = f_momres->GetParError(1);
      ofsfit << eta << "," << par1 << "," << par1err << "," << par2 << "," << par2err << endl;

    }

  /* Draw legend */
  c1->cd();
  //TCanvas *c2 = new TCanvas();
  //hframe->Draw();
  leg_eta->Draw();

  /* Print plots */
  c1->Print("track_momres_vareta.eps");
  //c2->Print("track_momres_vareta_legend.eps");

  /* Close output stream */
  ofsfit.close();

  return 0;
}
Example #6
0
void AccTimesEff::Loop()
{
   TStopwatch timer;
   timer.Start();
   // parameters /////////////////////////////////////////////////////////////
   vector<TString> files;
   files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-500_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9999ev.root");
   files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-750_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_10000ev.root");
   files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-1000_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9998ev.root");
   files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-1250_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9998ev.root");
   files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-1500_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9997ev.root");
   files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-1750_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9997ev.root");
   files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-2000_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9999ev.root");
   files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-2500_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9999ev.root");
   files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-3000_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_10000ev.root");
   files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-3500_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9898ev.root");
   files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-4000_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9998ev.root");
   files.push_back("file:////user/treis/mcsamples/ZprimeToEMu_M-5000_noAccCuts_TuneZ2star_8TeV_madgraph_treis-Summer12_DR53X_PU_S10_START53_V7C1-v1_9966ev.root");
   string outfileName = "accTimesEffHistos";

   // output file formats
   const bool saveSpec = 0;
   const bool saveAsPdf = 0;
   const bool saveAsPng = 1;
   const bool saveAsRoot = 0;
   TString plotDir = "./plots/";

   int font = 42; //62
   // selection cuts /////////////////////////////////////////////////////////
   float elePtCut = 35.;
   float muPtCut = 35.;
   float minInvMass = 0.;

   TH1::SetDefaultSumw2(kTRUE);

   ///////////////////////////////////////////////////////////////////////////

   ///////////////////////////////////////////////////////////////////////////

   TH1F *hGenEvts = new TH1F("hGenEvts", "hGenEvts", 145, 0., 5010.);
   hGenEvts->GetXaxis()->SetTitle("M_{Z'}^{truth}");
   hGenEvts->GetXaxis()->SetTitleFont(font);
   hGenEvts->GetXaxis()->SetLabelFont(font);
   hGenEvts->GetYaxis()->SetTitle("Events");
   hGenEvts->GetYaxis()->SetTitleFont(font);
   hGenEvts->GetYaxis()->SetLabelFont(font);
   hGenEvts->GetYaxis()->SetTitleOffset(1.2);
   hGenEvts->SetLineColor(kBlack);
   hGenEvts->SetLineWidth(2);
   hGenEvts->SetMarkerStyle(20);
   hGenEvts->SetMarkerColor(kBlack);
   TH1F *hGenEvtsEleInAcc = (TH1F*)hGenEvts->Clone("hGenEvtsEleInAcc");
   TH1F *hGenEvtsEleInAccEB = (TH1F*)hGenEvts->Clone("hGenEvtsEleInAccEB");
   TH1F *hGenEvtsEleInAccEE = (TH1F*)hGenEvts->Clone("hGenEvtsEleInAccEE");
   TH1F *hGenEvtsMuInAcc = (TH1F*)hGenEvts->Clone("hGenEvtsMuInAcc");
   TH1F *hGenEvtsInAcc = (TH1F*)hGenEvts->Clone("hGenEvtsInAcc");
   TH1F *hTrgEvts = (TH1F*)hGenEvts->Clone("hTrgEvts");
   hTrgEvts->SetTitle("hTrgEvts");
   TH1F *hRecoEvts = (TH1F*)hGenEvts->Clone("hRecoEvts");
   hRecoEvts->SetTitle("hRecoEvts");
   TH1F *hRecoEvtsEB = (TH1F*)hRecoEvts->Clone("hRecoEvtsEB");
   TH1F *hRecoEvtsEE = (TH1F*)hRecoEvts->Clone("hRecoEvtsEE");
   TH1F *hRecoEleEvts = (TH1F*)hRecoEvts->Clone("hRecoEleEvts");
   TH1F *hRecoEleEvtsEB = (TH1F*)hRecoEvts->Clone("hRecoEleEvtsEB");
   TH1F *hRecoEleEvtsEE = (TH1F*)hRecoEvts->Clone("hRecoEleEvtsEE");
   TH1F *hRecoMuEvts = (TH1F*)hRecoEvts->Clone("hRecoMuEvts");
   TH1F *hRecoNoTrgEvts = (TH1F*)hGenEvts->Clone("hRecoNoTrgEvts");
   hRecoNoTrgEvts->SetTitle("hRecoNoTrgEvts");
   TH1F *hRecoNoTrgEvtsEB = (TH1F*)hRecoNoTrgEvts->Clone("hRecoNoTrgEvtsEB");
   TH1F *hRecoNoTrgEvtsEE = (TH1F*)hRecoNoTrgEvts->Clone("hRecoNoTrgEvtsEE");
   TH1F *hRecoNoTrgEleEvts = (TH1F*)hRecoNoTrgEvts->Clone("hRecoNoTrgEleEvts");
   TH1F *hRecoNoTrgEleEvtsEB = (TH1F*)hRecoNoTrgEvts->Clone("hRecoNoTrgEleEvtsEB");
   TH1F *hRecoNoTrgEleEvtsEE = (TH1F*)hRecoNoTrgEvts->Clone("hRecoNoTrgEleEvtsEE");
   TH1F *hRecoNoTrgMuEvts = (TH1F*)hRecoNoTrgEvts->Clone("hRecoNoTrgMuEvts");
   TH1F* hAcc;
   TH1F* hAccEle;
   TH1F* hAccEleEB;
   TH1F* hAccEleEE;
   TH1F* hAccMu;
   TH1F* hAccTimesTrgEff;
   TH1F* hTrgEff;
   TH1F* hAccTimesEff;
   TH1F* hAccTimesEffEB;
   TH1F* hAccTimesEffEE;
   TH1F* hAccTimesEffEle;
   TH1F* hAccTimesEffEleEB;
   TH1F* hAccTimesEffEleEE;
   TH1F* hAccTimesEffMu;
   TH1F* hAccTimesEffNoTrg;
   //TH1F* hAccTimesEffNoTrgEB;
   //TH1F* hAccTimesEffNoTrgEE;
   TH1F* hAccTimesEffNoTrgEle;
   TH1F* hAccTimesEffNoTrgEleEB;
   TH1F* hAccTimesEffNoTrgEleEE;
   TH1F* hAccTimesEffNoTrgMu;
   TH1F* hEffAftTrg;
   TH1F* hEffAftTrgEle;
   TH1F* hEffAftTrgEleEB;
   TH1F* hEffAftTrgEleEE;
   TH1F* hEffAftTrgMu;
   TH1F* hTrgRecoVsReco;
   //TH1F* hTrgRecoVsRecoEB;
   //TH1F* hTrgRecoVsRecoEE;
   TH1F* hTrgRecoVsRecoEle;
   TH1F* hTrgRecoVsRecoEleEB;
   TH1F* hTrgRecoVsRecoEleEE;
   TH1F* hTrgRecoVsRecoMu;

   // output file
   stringstream ssOutfile;
   ssOutfile << outfileName << ".root";
   TFile *output = new TFile(ssOutfile.str().c_str(), "recreate");

   ///////////////////////////////////////////////////////////////////////////
   //LOOP OVER FILES 
   ///////////////////////////////////////////////////////////////////////////
   for (unsigned int p = 0; p < files.size(); ++p) {
      TFile* input = new TFile(files[p]);
      TTree *thetree = (TTree*)input->Get("gsfcheckerjob/tree");
      Init(thetree);
      Long64_t nentries = fChain->GetEntriesFast();
      cout << nentries << " events" << endl;

      unsigned int evCounter = 0;
      /////////////////////////////////////////////////////////////////////////////////////////////
      //LOOP OVER EVENTS
      /////////////////////////////////////////////////////////////////////////////////////////////
      //nentries = 10000;
      for (Long64_t jentry = 0; jentry < nentries; ++jentry) {
         Long64_t ientry = LoadTree(jentry);
         if (ientry < 0) break;
         fChain->GetEntry(jentry);
         // if (Cut(ientry) < 0) continue;
         //if (jentry % 50000 == 0) cout << "Processing event " << jentry << endl;
         thetree->GetEntry(jentry);

         // fill the gen histograms
         hGenEvts->Fill(genelemom_mass[0]);

         // fill the acc histograms
         if (hardGenEle_pt[0] > elePtCut) {
            if (fabs(hardGenEle_eta[0]) < 1.442) {
               hGenEvtsEleInAcc->Fill(genelemom_mass[0]);
               hGenEvtsEleInAccEB->Fill(genelemom_mass[0]);
            }
            else if (fabs(hardGenEle_eta[0]) > 1.56 && fabs(hardGenEle_eta[0]) < 2.5) {
               hGenEvtsEleInAcc->Fill(genelemom_mass[0]);
               hGenEvtsEleInAccEE->Fill(genelemom_mass[0]);
            }
         }
         if (hardGenMu_pt[0] > muPtCut && fabs(hardGenMu_eta[0]) < 2.4) {
            hGenEvtsMuInAcc->Fill(genelemom_mass[0]);
            if (fabs(hardGenEle_eta[0]) < 1.442 || (fabs(hardGenEle_eta[0]) > 1.56 && fabs(hardGenEle_eta[0]) < 2.5)) {
               if (hardGenEle_pt[0] > elePtCut) hGenEvtsInAcc->Fill(genelemom_mass[0]);
            }
         }

         // trigger?
         if (HLT_Mu22_Photon22_CaloIdL) hTrgEvts->Fill(genelemom_mass[0]);

         // at least one gsf electron and one muon above the threshold
         if (gsf_size < 1 || muon_size < 1) continue;

         vector<int> GSF_passHEEP;
         vector<int> MU_passGOOD;
         /////////////////////////////////////////////////////////////////////////////////////////////
         //loop over electrons
         for (int j = 0; j < gsf_size; ++j) {
            //cleaning: fake electrons from muons
            bool fakeEle = false;
            for (int k = 0; k < muon_size; ++k) {
               float DeltaR = deltaR(gsf_eta[j], gsf_phi[j], muon_eta[k], muon_phi[k]);
               if (DeltaR < 0.1) {
                  fakeEle = true;
                  break;
               }
            }
            if (fakeEle) continue;

            if (PassHEEP(j)) GSF_passHEEP.push_back(j);
         }

         //loop over muons
         for (int j = 0; j < muon_size; ++j) {
            if (PassHighPtMu(j)) MU_passGOOD.push_back(j);
         }

         if (GSF_passHEEP.size() == 1) {
            if (HLT_Mu22_Photon22_CaloIdL) {
               hRecoEleEvts->Fill(genelemom_mass[0]);
               if (fabs(gsfsc_eta[GSF_passHEEP[0]]) < 1.5) hRecoEleEvtsEB->Fill(genelemom_mass[0]);
               if (fabs(gsfsc_eta[GSF_passHEEP[0]]) > 1.5) hRecoEleEvtsEE->Fill(genelemom_mass[0]);
            }
            hRecoNoTrgEleEvts->Fill(genelemom_mass[0]);
            if (fabs(gsfsc_eta[GSF_passHEEP[0]]) < 1.5) hRecoNoTrgEleEvtsEB->Fill(genelemom_mass[0]);
            if (fabs(gsfsc_eta[GSF_passHEEP[0]]) > 1.5) hRecoNoTrgEleEvtsEE->Fill(genelemom_mass[0]);
         } 
         if (MU_passGOOD.size() == 1) {
            if (HLT_Mu22_Photon22_CaloIdL) hRecoMuEvts->Fill(genelemom_mass[0]);
            hRecoNoTrgMuEvts->Fill(genelemom_mass[0]);
         }

         // veto when there are more than one good candidates
         if (GSF_passHEEP.size() != 1 || MU_passGOOD.size() != 1) continue;

         //HEEP ele + GOOD muon
         TLorentzVector ele1;
         TLorentzVector mu1;

         ele1.SetPtEtaPhiM(gsf_gsfet[GSF_passHEEP[0]], gsf_eta[GSF_passHEEP[0]], gsf_phi[GSF_passHEEP[0]], 0.000511);
         mu1.SetPtEtaPhiM(muon_pt[MU_passGOOD[0]], muon_eta[MU_passGOOD[0]], muon_phi[MU_passGOOD[0]], 0.10566);

         double invMass = (ele1 + mu1).M();

         //MASS CUT
         if (invMass < minInvMass) continue;

         if (HLT_Mu22_Photon22_CaloIdL) {
            hRecoEvts->Fill(genelemom_mass[0]);
            if (fabs(gsfsc_eta[GSF_passHEEP[0]]) < 1.5) hRecoEvtsEB->Fill(genelemom_mass[0]);
            if (fabs(gsfsc_eta[GSF_passHEEP[0]]) > 1.5) hRecoEvtsEE->Fill(genelemom_mass[0]);
         }
         hRecoNoTrgEvts->Fill(genelemom_mass[0]);
         if (fabs(gsfsc_eta[GSF_passHEEP[0]]) < 1.5) hRecoNoTrgEvtsEB->Fill(genelemom_mass[0]);
         if (fabs(gsfsc_eta[GSF_passHEEP[0]]) > 1.5) hRecoNoTrgEvtsEE->Fill(genelemom_mass[0]);
         ++evCounter;
        ///////////////////////////////////////////////////////////////////////
      } //END LOOP OVER EVENTS
        //////////////////////////////////////////////////////////////////////

     //////////////////////////////////////////////////////////////////////////
   } //END LOOP OVER FILES
     //////////////////////////////////////////////////////////////////////////
   hAcc = (TH1F*)hGenEvtsInAcc->Clone("hAcc");
   hAccEle = (TH1F*)hGenEvtsEleInAcc->Clone("hAccEle");
   hAccEleEB = (TH1F*)hGenEvtsEleInAccEB->Clone("hAccEleEB");
   hAccEleEE = (TH1F*)hGenEvtsEleInAccEE->Clone("hAccEleEE");
   hAccMu = (TH1F*)hGenEvtsMuInAcc->Clone("hAccMu");
   hAccTimesTrgEff = (TH1F*)hTrgEvts->Clone("hAccTimesTrgEff");
   hTrgEff = (TH1F*)hTrgEvts->Clone("hTrgEff");
   hAccTimesEff = (TH1F*)hRecoEvts->Clone("hAccTimesEff");
   hAccTimesEffEB = (TH1F*)hRecoEvtsEB->Clone("hAccTimesEffEB");
   hAccTimesEffEE = (TH1F*)hRecoEvtsEE->Clone("hAccTimesEffEE");
   hAccTimesEffEle = (TH1F*)hRecoEleEvts->Clone("hAccTimesEffEle");
   hAccTimesEffEleEB = (TH1F*)hRecoEleEvtsEB->Clone("hAccTimesEffEleEB");
   hAccTimesEffEleEE = (TH1F*)hRecoEleEvtsEE->Clone("hAccTimesEffEleEE");
   hAccTimesEffMu = (TH1F*)hRecoMuEvts->Clone("hAccTimesEffMu");
   hAccTimesEffNoTrg = (TH1F*)hRecoNoTrgEvts->Clone("hAccTimesEffNoTrg");
   //hAccTimesEffNoTrgEB = (TH1F*)hRecoNoTrgEvtsEB->Clone("hAccTimesEffNoTrgEB");
   //hAccTimesEffNoTrgEE = (TH1F*)hRecoNoTrgEvtsEE->Clone("hAccTimesEffNoTrgEE");
   hAccTimesEffNoTrgEle = (TH1F*)hRecoNoTrgEleEvts->Clone("hAccTimesEffNoTrgEle");
   hAccTimesEffNoTrgEleEB = (TH1F*)hRecoNoTrgEleEvtsEB->Clone("hAccTimesEffNoTrgEleEB");
   hAccTimesEffNoTrgEleEE = (TH1F*)hRecoNoTrgEleEvtsEE->Clone("hAccTimesEffNoTrgEleEE");
   hAccTimesEffNoTrgMu = (TH1F*)hRecoNoTrgMuEvts->Clone("hAccTimesEffNoTrgMu");
   hEffAftTrg = (TH1F*)hRecoEvts->Clone("hAccTimesEff");
   hEffAftTrgEle = (TH1F*)hRecoEleEvts->Clone("hAccTimesEffEle");
   hEffAftTrgEleEB = (TH1F*)hRecoEleEvtsEB->Clone("hAccTimesEffEleEB");
   hEffAftTrgEleEE = (TH1F*)hRecoEleEvtsEE->Clone("hAccTimesEffEleEE");
   hEffAftTrgMu = (TH1F*)hRecoMuEvts->Clone("hAccTimesEffMu");
   hTrgRecoVsReco = (TH1F*)hRecoEvts->Clone("hTrgRecoVsReco");
   //hTrgRecoVsRecoEB = (TH1F*)hRecoEvtsEB->Clone("hTrgRecoVsRecoEB");
   //hTrgRecoVsRecoEE = (TH1F*)hRecoEvtsEE->Clone("hTrgRecoVsRecoEE");
   hTrgRecoVsRecoEle = (TH1F*)hRecoEleEvts->Clone("hTrgRecoVsRecoEle");
   hTrgRecoVsRecoEleEB = (TH1F*)hRecoEleEvtsEB->Clone("hTrgRecoVsRecoEleEB");
   hTrgRecoVsRecoEleEE = (TH1F*)hRecoEleEvtsEE->Clone("hTrgRecoVsRecoEleEE");
   hTrgRecoVsRecoMu = (TH1F*)hRecoMuEvts->Clone("hTrgRecoVsRecoMu");
   hAcc->Divide(hGenEvts);
   hAccEle->Divide(hGenEvts);
   hAccEleEB->Divide(hGenEvts);
   hAccEleEE->Divide(hGenEvts);
   hAccMu->Divide(hGenEvts);
   hAccTimesTrgEff->Divide(hGenEvts);
   hTrgEff->Divide(hGenEvtsInAcc);
   hAccTimesEff->Divide(hGenEvts);
   hAccTimesEffEB->Divide(hGenEvts);
   hAccTimesEffEE->Divide(hGenEvts);
   hAccTimesEffEle->Divide(hGenEvts);
   hAccTimesEffEleEB->Divide(hGenEvts);
   hAccTimesEffEleEE->Divide(hGenEvts);
   hAccTimesEffMu->Divide(hGenEvts);
   hAccTimesEffNoTrg->Divide(hGenEvts);
   //hAccTimesEffNoTrgEB->Divide(hGenEvts);
   //hAccTimesEffNoTrgEE->Divide(hGenEvts);
   hAccTimesEffNoTrgEle->Divide(hGenEvts);
   hAccTimesEffNoTrgEleEB->Divide(hGenEvts);
   hAccTimesEffNoTrgEleEE->Divide(hGenEvts);
   hAccTimesEffNoTrgMu->Divide(hGenEvts);
   hEffAftTrg->Divide(hTrgEvts);
   hEffAftTrgEle->Divide(hTrgEvts);
   hEffAftTrgEleEB->Divide(hTrgEvts);
   hEffAftTrgEleEE->Divide(hTrgEvts);
   hEffAftTrgMu->Divide(hTrgEvts);
   hTrgRecoVsReco->Divide(hRecoNoTrgEvts);
   //hTrgRecoVsRecoEB->Divide(hRecoNoTrgEvtsEB);
   //hTrgRecoVsRecoEE->Divide(hRecoNoTrgEvtsEE);
   hTrgRecoVsRecoEle->Divide(hRecoNoTrgEleEvts);
   hTrgRecoVsRecoEleEB->Divide(hRecoNoTrgEleEvtsEB);
   hTrgRecoVsRecoEleEE->Divide(hRecoNoTrgEleEvtsEE);
   hTrgRecoVsRecoMu->Divide(hRecoNoTrgMuEvts);

   // plot
   TCanvas *accTimesEffPlot = new TCanvas("accTimesEffPlot", "acc x eff", 100, 100, 600, 600);
   TPad *accTimesEffPad = new TPad("accTimesEffPad", "acc x eff pad", 0., 0., 1., 1.);
   accTimesEffPad->SetBottomMargin(0.12);
   accTimesEffPad->SetBorderMode(0);
   accTimesEffPad->SetBorderSize(2);
   accTimesEffPad->SetFrameBorderMode(0);
   accTimesEffPad->SetFillColor(0);
   accTimesEffPad->SetFrameFillColor(0);
   accTimesEffPad->SetLeftMargin(0.11);
   accTimesEffPad->SetRightMargin(0.09);
   accTimesEffPad->SetTopMargin(0.08);
   accTimesEffPad->SetTickx(1);
   accTimesEffPad->SetTicky(1);
   accTimesEffPad->Draw();
   accTimesEffPad->cd();

   gStyle->SetTitleFont(font);
   gStyle->SetLabelFont(font);
   gStyle->SetLegendFont(font);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);
   gStyle->SetOptFit(1111);
   gStyle->SetTitleXOffset(1.);
   gStyle->SetTitleYOffset(1.3);
   gPad->SetTicks(1, 1);
   gPad->SetGrid(1, 1);

   TH1F* hAccTimesEff2 = (TH1F*)hAccTimesEff->Clone("hAccTimesEff2");

   TF1 *fitFunc = new TF1("fitFunc", "[0] + [1]/ (x + [2]) + [3]*x", 10., 5010.);
   //TF1 *fitFuncEB = new TF1("fitFuncEB", "[0] + [1]/ (x + [2])", 10., 5010.);
   TF1 *fitFuncEB = new TF1("fitFuncEB", "[0] + [1]/ (x + [2]) + [3]*x", 10., 5010.);
   TF1 *fitFuncEE = new TF1("fitFuncEE", "[0] + [1]/ (x*x + [2])", 10., 5010.);
   fitFunc->SetLineColor(kBlue);
   fitFuncEB->SetLineColor(kBlue);
   fitFuncEE->SetLineColor(kBlue);
   hAccTimesEff->Fit("fitFunc", "", "", 480., 5010.);
   hAccTimesEffEB->Fit("fitFuncEB", "", "", 480., 5010.);
   hAccTimesEffEE->Fit("fitFuncEE", "", "", 480., 5010.);
   cout << "Chi^2 / NDF: " << fitFunc->GetChisquare() << " / " << fitFunc->GetNDF() << ", prob: " << fitFunc->GetProb() << endl;
   cout << "Chi^2 / NDF EB: " << fitFuncEB->GetChisquare() << " / " << fitFuncEB->GetNDF() << ", prob: " << fitFuncEB->GetProb() << endl;
   cout << "Chi^2 / NDF EE: " << fitFuncEE->GetChisquare() << " / " << fitFuncEE->GetNDF() << ", prob: " << fitFuncEE->GetProb() << endl;

   hAccTimesEff->GetYaxis()->SetTitle("acc x eff");
   hAccTimesEff->GetYaxis()->SetRangeUser(0., 1.);
   hAccTimesEff->Draw();
   TLatex *tex = new TLatex(0.22, 0.21, "P(M|p0,p1,p2,p3) = p0 + #frac{p1}{M+p2} + p3*M");
   tex->SetNDC();
   tex->SetTextFont(font);
   tex->SetLineWidth(2);
   tex->SetTextSize(0.03);
   tex->Draw();
   tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV");
   tex->DrawLatex(0.17, 0.85, "trg + electron + muon");

   TCanvas *accTimesEffPlotEB = new TCanvas("accTimesEffPlotEB", "acc x eff, barrel electron + muon", 100, 100, 600, 600);
   TPad *accTimesEffPadEB = (TPad*)accTimesEffPad->Clone("accTimesEffPadEB");
   accTimesEffPadEB->Draw(); 
   accTimesEffPadEB->cd();
   hAccTimesEffEB->GetYaxis()->SetTitle("acc x eff");
   hAccTimesEffEB->GetYaxis()->SetRangeUser(0., 1.);
   hAccTimesEffEB->Draw();
   tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV");
   //tex->DrawLatex(0.46, 0.21, "P(M|p0,p1,p2) = p0 + #frac{p1}{M+p2}");
   tex->DrawLatex(0.22, 0.21, "P(M|p0,p1,p2,p3) = p0 + #frac{p1}{M+p2} + p3*M");
   tex->DrawLatex(0.17, 0.85, "trg + barrel electron + muon");

   TCanvas *accTimesEffPlotEE = new TCanvas("accTimesEffPlotEE", "acc x eff, endcap electron + muon", 100, 100, 600, 600);
   TPad *accTimesEffPadEE = (TPad*)accTimesEffPad->Clone("accTimesEffPadEE");
   accTimesEffPadEE->Draw(); 
   accTimesEffPadEE->cd();
   hAccTimesEffEE->GetYaxis()->SetTitle("acc x eff");
   hAccTimesEffEE->GetYaxis()->SetRangeUser(0., 1.);
   hAccTimesEffEE->Draw();
   tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV");
   tex->DrawLatex(0.45, 0.38, "P(M|p0,p1,p2) = p0 + #frac{p1}{M^{2}+p2}");
   tex->DrawLatex(0.17, 0.85, "trg + endcap electron + muon");

   TCanvas *accTimesEffObjPlot = new TCanvas("accTimesEffObjPlot", "acc x eff, objects", 100, 100, 600, 600);
   TPad *accTimesEffObjPad = (TPad*)accTimesEffPad->Clone("accTimesEffObjPad");
   accTimesEffObjPad->Draw(); 
   accTimesEffObjPad->cd();
   hAccTimesEffEle->GetYaxis()->SetTitle("acc x eff");
   hAccTimesEffEle->GetYaxis()->SetRangeUser(0., 1.);
   hAccTimesEffEle->SetMarkerStyle(kFullSquare);
   hAccTimesEffEle->SetMarkerColor(kViolet);
   hAccTimesEffEle->SetLineColor(kViolet);
   hAccTimesEffEle->Draw();
   hAccTimesEffEleEB->SetMarkerStyle(kFullTriangleUp);
   hAccTimesEffEleEB->SetMarkerColor(kRed);
   hAccTimesEffEleEB->SetLineColor(kRed);
   hAccTimesEffEleEB->Draw("same");
   hAccTimesEffEleEE->SetMarkerStyle(kFullTriangleDown);
   hAccTimesEffEleEE->SetMarkerColor(kBlue);
   hAccTimesEffEleEE->SetLineColor(kBlue);
   hAccTimesEffEleEE->Draw("same");
   hAccTimesEffMu->SetMarkerStyle(34);
   hAccTimesEffMu->SetMarkerColor(kGreen+1);
   hAccTimesEffMu->SetLineColor(kGreen+1);
   hAccTimesEffMu->Draw("same");
   hAccTimesEff2->Draw("same");
   TLegend* legend = new TLegend(0.592, 0.279, 0.881, 0.467);
   legend->SetTextFont(font);
   legend->SetTextSize(0.03);
   legend->SetBorderSize(0);
   legend->SetLineColor(1);
   legend->SetLineStyle(1);
   legend->SetLineWidth(1);
   legend->SetFillColor(19);
   legend->SetFillStyle(0);
   legend->AddEntry(hAccTimesEff, "total acc x eff");
   legend->AddEntry(hAccTimesEffMu, "muons");
   legend->AddEntry(hAccTimesEffEle, "all electrons");
   legend->AddEntry(hAccTimesEffEleEB, "barrel electrons");
   legend->AddEntry(hAccTimesEffEleEE, "endcap electrons");
   legend->Draw("same");
   tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV");
   tex->DrawLatex(0.17, 0.85, "trg: HLT_Mu22_Photon22_CaloIdL");

   // acc x eff with no trg applied
   TCanvas *accTimesEffNoTrgObjPlot = new TCanvas("accTimesEffNoTrgObjPlot", "acc x eff, no trigger, objects", 100, 100, 600, 600);
   TPad *accTimesEffNoTrgObjPad = (TPad*)accTimesEffPad->Clone("accTimesEffNoTrgObjPad");
   accTimesEffNoTrgObjPad->Draw(); 
   accTimesEffNoTrgObjPad->cd();
   hAccTimesEffNoTrgEle->GetYaxis()->SetTitle("acc x eff");
   hAccTimesEffNoTrgEle->GetYaxis()->SetRangeUser(0., 1.);
   hAccTimesEffNoTrgEle->SetMarkerStyle(kFullSquare);
   hAccTimesEffNoTrgEle->SetMarkerColor(kViolet);
   hAccTimesEffNoTrgEle->SetLineColor(kViolet);
   hAccTimesEffNoTrgEle->Draw();
   hAccTimesEffNoTrgEleEB->SetMarkerStyle(kFullTriangleUp);
   hAccTimesEffNoTrgEleEB->SetMarkerColor(kRed);
   hAccTimesEffNoTrgEleEB->SetLineColor(kRed);
   hAccTimesEffNoTrgEleEB->Draw("same");
   hAccTimesEffNoTrgEleEE->SetMarkerStyle(kFullTriangleDown);
   hAccTimesEffNoTrgEleEE->SetMarkerColor(kBlue);
   hAccTimesEffNoTrgEleEE->SetLineColor(kBlue);
   hAccTimesEffNoTrgEleEE->Draw("same");
   hAccTimesEffNoTrgMu->SetMarkerStyle(34);
   hAccTimesEffNoTrgMu->SetMarkerColor(kGreen+1);
   hAccTimesEffNoTrgMu->SetLineColor(kGreen+1);
   hAccTimesEffNoTrgMu->Draw("same");
   hAccTimesEffNoTrg->Draw("same");
   TLegend* accXeffNoTrg = (TLegend*)legend->Clone("effAftTrgLegend");
   accXeffNoTrg->Clear();
   accXeffNoTrg->AddEntry(hAccTimesEffNoTrg, "total acc x eff");
   accXeffNoTrg->AddEntry(hAccTimesEffNoTrgMu, "muons");
   accXeffNoTrg->AddEntry(hAccTimesEffNoTrgEle, "all electrons");
   accXeffNoTrg->AddEntry(hAccTimesEffNoTrgEleEB, "barrel electrons");
   accXeffNoTrg->AddEntry(hAccTimesEffNoTrgEleEE, "endcap electrons");
   accXeffNoTrg->Draw("same");
   tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV");
   tex->DrawLatex(0.17, 0.85, "trg: none");

   // efficiency on triggered events
   TCanvas *effAftTrgPlot = new TCanvas("effAftTrgPlot", "efficiency after trigger", 100, 100, 600, 600);
   TPad *effAftTrgPad = (TPad*)accTimesEffPad->Clone("effAftTrgPad");
   effAftTrgPad->Draw(); 
   effAftTrgPad->cd();
   hEffAftTrgEle->GetYaxis()->SetTitle("eff");
   hEffAftTrgEle->GetYaxis()->SetRangeUser(0., 1.);
   hEffAftTrgEle->SetMarkerStyle(kFullSquare);
   hEffAftTrgEle->SetMarkerColor(kViolet);
   hEffAftTrgEle->SetLineColor(kViolet);
   hEffAftTrgEle->Draw();
   hEffAftTrgEleEB->SetMarkerStyle(kFullTriangleUp);
   hEffAftTrgEleEB->SetMarkerColor(kRed);
   hEffAftTrgEleEB->SetLineColor(kRed);
   hEffAftTrgEleEB->Draw("same");
   hEffAftTrgEleEE->SetMarkerStyle(kFullTriangleDown);
   hEffAftTrgEleEE->SetMarkerColor(kBlue);
   hEffAftTrgEleEE->SetLineColor(kBlue);
   hEffAftTrgEleEE->Draw("same");
   hEffAftTrgMu->SetMarkerStyle(34);
   hEffAftTrgMu->SetMarkerColor(kGreen+1);
   hEffAftTrgMu->SetLineColor(kGreen+1);
   hEffAftTrgMu->Draw("same");
   hEffAftTrg->Draw("same");
   TLegend* effAftTrgLegend = (TLegend*)legend->Clone("effAftTrgLegend");
   effAftTrgLegend->Clear();
   effAftTrgLegend->AddEntry(hEffAftTrg, "total eff after trigger");
   effAftTrgLegend->AddEntry(hEffAftTrgMu, "muons");
   effAftTrgLegend->AddEntry(hEffAftTrgEle, "all electrons");
   effAftTrgLegend->AddEntry(hEffAftTrgEleEB, "barrel electrons");
   effAftTrgLegend->AddEntry(hEffAftTrgEleEE, "endcap electrons");
   effAftTrgLegend->Draw("same");
   tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV");
   tex->DrawLatex(0.14, 0.15, "trg: HLT_Mu22_Photon22_CaloIdL");

   // acceptance
   TCanvas *accPlot = new TCanvas("accPlot", "acc", 100, 100, 600, 600);
   TPad *accPad = (TPad*)accTimesEffPad->Clone("accPad");
   accPad->Draw(); 
   accPad->cd();
   hAcc->GetYaxis()->SetTitle("acc");
   hAcc->GetYaxis()->SetRangeUser(0., 1.);
   hAccEle->SetMarkerStyle(kFullSquare);
   hAccEle->SetMarkerColor(kViolet);
   hAccEle->SetLineColor(kViolet);
   hAccEle->Draw();
   hAccEleEB->SetMarkerStyle(kFullTriangleUp);
   hAccEleEB->SetMarkerColor(kRed);
   hAccEleEB->SetLineColor(kRed);
   hAccEleEB->Draw("same");
   hAccEleEE->SetMarkerStyle(kFullTriangleDown);
   hAccEleEE->SetMarkerColor(kBlue);
   hAccEleEE->SetLineColor(kBlue);
   hAccEleEE->Draw("same");
   hAccMu->SetMarkerStyle(34);
   hAccMu->SetMarkerColor(kGreen+1);
   hAccMu->SetLineColor(kGreen+1);
   hAccMu->Draw("same");
   hAcc->Draw("same");
   TLegend* accLegend = (TLegend*)legend->Clone("accLegend");
   accLegend->Clear();
   accLegend->AddEntry(hAcc, "total acceptance");
   accLegend->AddEntry(hAccMu, "muons");
   accLegend->AddEntry(hAccEle, "all electrons");
   accLegend->AddEntry(hAccEleEB, "barrel electrons");
   accLegend->AddEntry(hAccEleEE, "endcap electrons");
   accLegend->Draw("same");
   tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV");

   // reco with trg vs. reco
   TCanvas *trgRecoVsRecoPlot = new TCanvas("trgRecoVsRecoPlot", "reco with trg vs. reco", 100, 100, 600, 600);
   TPad *trgRecoVsRecoPad = (TPad*)accTimesEffPad->Clone("trgRecoVsRecoPad");
   trgRecoVsRecoPad->Draw(); 
   trgRecoVsRecoPad->cd();
   hTrgRecoVsRecoEle->GetYaxis()->SetTitle("eff");
   hTrgRecoVsRecoEle->GetYaxis()->SetRangeUser(0., 1.);
   hTrgRecoVsRecoEle->SetMarkerStyle(kFullSquare);
   hTrgRecoVsRecoEle->SetMarkerColor(kViolet);
   hTrgRecoVsRecoEle->SetLineColor(kViolet);
   hTrgRecoVsRecoEle->Draw();
   //hTrgRecoVsRecoEleEB->SetMarkerStyle(kFullTriangleUp);
   //hTrgRecoVsRecoEleEB->SetMarkerColor(kRed);
   //hTrgRecoVsRecoEleEB->SetLineColor(kRed);
   //hTrgRecoVsRecoEleEB->Draw("same");
   //hTrgRecoVsRecoEleEE->SetMarkerStyle(kFullTriangleDown);
   //hTrgRecoVsRecoEleEE->SetMarkerColor(kBlue);
   //hTrgRecoVsRecoEleEE->SetLineColor(kBlue);
   //hTrgRecoVsRecoEleEE->Draw("same");
   hTrgRecoVsRecoMu->SetMarkerStyle(34);
   hTrgRecoVsRecoMu->SetMarkerColor(kGreen+1);
   hTrgRecoVsRecoMu->SetLineColor(kGreen+1);
   hTrgRecoVsRecoMu->Draw("same");
   hTrgRecoVsReco->Draw("same");
   TLegend* trgRecoVsRecoLegend = (TLegend*)legend->Clone("trgRecoVsRecoLegend");
   trgRecoVsRecoLegend->Clear();
   trgRecoVsRecoLegend->AddEntry(hTrgRecoVsReco, "total");
   trgRecoVsRecoLegend->AddEntry(hTrgRecoVsRecoMu, "muons");
   trgRecoVsRecoLegend->AddEntry(hTrgRecoVsRecoEle, "electrons");
   //trgRecoVsRecoLegend->AddEntry(hTrgRecoVsRecoEleEB, "barrel electrons");
   //trgRecoVsRecoLegend->AddEntry(hTrgRecoVsRecoEleEE, "endcap electrons");
   trgRecoVsRecoLegend->Draw("same");
   tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV");

   TCanvas *accTimesTrgEffPlot = new TCanvas("accTimesTrgEffPlot", "acc x trigger eff", 100, 100, 600, 600);
   TPad *accTimesTrgEffPad = (TPad*)accTimesEffPad->Clone("accTimesTrgEffPad");
   accTimesTrgEffPad->Draw(); 
   accTimesTrgEffPad->cd();
   hAccTimesTrgEff->GetYaxis()->SetTitle("acc x trg eff");
   hAccTimesTrgEff->GetYaxis()->SetRangeUser(0., 1.);
   hAccTimesTrgEff->SetMarkerStyle(20);
   hAccTimesTrgEff->SetMarkerColor(kCyan);
   hAccTimesTrgEff->SetLineColor(kCyan);
   hAccTimesTrgEff->Draw();
   hTrgEff->SetMarkerStyle(21);
   hTrgEff->SetMarkerColor(kMagenta);
   hTrgEff->SetLineColor(kMagenta);
   hTrgEff->Draw("same");
   TLegend* trgLegend = (TLegend*)legend->Clone("trgLegend");
   trgLegend->Clear();
   trgLegend->AddEntry(hTrgEff, "trigger eff in acc");
   trgLegend->AddEntry(hAccTimesTrgEff, "acc x trigger eff");
   trgLegend->Draw("same");
   tex->DrawLatex(0.109, 0.935, "CMS Simulation, 8 TeV");

   // safe in various file formats
   if (saveSpec) {
     if (saveAsPdf) {
        accTimesTrgEffPlot->Print(plotDir + accTimesTrgEffPlot->GetName() + ".pdf", "pdf");
        accTimesEffPlot->Print(plotDir + accTimesEffPlot->GetName() + ".pdf", "pdf");
        accTimesEffPlotEB->Print(plotDir + accTimesEffPlotEB->GetName() + ".pdf", "pdf");
        accTimesEffPlotEE->Print(plotDir + accTimesEffPlotEE->GetName() + ".pdf", "pdf");
        accTimesEffObjPlot->Print(plotDir + accTimesEffObjPlot->GetName() + ".pdf", "pdf");
        accTimesEffNoTrgObjPlot->Print(plotDir + accTimesEffNoTrgObjPlot->GetName() + ".pdf", "pdf");
        effAftTrgPlot->Print(plotDir + effAftTrgPlot->GetName() + ".pdf", "pdf");
        trgRecoVsRecoPlot->Print(plotDir + trgRecoVsRecoPlot->GetName() + ".pdf", "pdf");
        accPlot->Print(plotDir + accPlot->GetName() + ".pdf", "pdf");
     }
     if (saveAsPng) {
        accTimesTrgEffPlot->Print(plotDir + accTimesTrgEffPlot->GetName() + ".png", "png");
        accTimesEffPlot->Print(plotDir + accTimesEffPlot->GetName() + ".png", "png");
        accTimesEffPlotEB->Print(plotDir + accTimesEffPlotEB->GetName() + ".png", "png");
        accTimesEffPlotEE->Print(plotDir + accTimesEffPlotEE->GetName() + ".png", "png");
        accTimesEffObjPlot->Print(plotDir + accTimesEffObjPlot->GetName() + ".png", "png");
        accTimesEffNoTrgObjPlot->Print(plotDir + accTimesEffNoTrgObjPlot->GetName() + ".png", "png");
        effAftTrgPlot->Print(plotDir + effAftTrgPlot->GetName() + ".png", "png");
        trgRecoVsRecoPlot->Print(plotDir + trgRecoVsRecoPlot->GetName() + ".png", "png");
        accPlot->Print(plotDir + accPlot->GetName() + ".png", "png");
     }
     if (saveAsRoot) {
        accTimesTrgEffPlot->Print(plotDir + accTimesTrgEffPlot->GetName() + ".root", "root");
        accTimesEffPlot->Print(plotDir + accTimesEffPlot->GetName() + ".root", "root");
        accTimesEffPlotEB->Print(plotDir + accTimesEffPlotEB->GetName() + ".root", "root");
        accTimesEffPlotEE->Print(plotDir + accTimesEffPlotEE->GetName() + ".root", "root");
        accTimesEffObjPlot->Print(plotDir + accTimesEffObjPlot->GetName() + ".root", "root");
        accTimesEffNoTrgObjPlot->Print(plotDir + accTimesEffNoTrgObjPlot->GetName() + ".root", "root");
        effAftTrgPlot->Print(plotDir + effAftTrgPlot->GetName() + ".root", "root");
        trgRecoVsRecoPlot->Print(plotDir + trgRecoVsRecoPlot->GetName() + ".root", "root");
        accPlot->Print(plotDir + accPlot->GetName() + ".root", "root");
     }
   }

   // write histos to file
   output->cd();
   hGenEvts->Write();
   hGenEvtsEleInAcc->Write();
   hGenEvtsEleInAccEB->Write();
   hGenEvtsEleInAccEE->Write();
   hGenEvtsMuInAcc->Write();
   hGenEvtsInAcc->Write();
   hTrgEvts->Write();
   hRecoEvts->Write();
   hRecoEvtsEB->Write();
   hRecoEvtsEE->Write();
   hRecoEleEvts->Write();
   hRecoEleEvtsEB->Write();
   hRecoEleEvtsEE->Write();
   hRecoMuEvts->Write();
   hAccEle->Write();
   hAccEleEB->Write();
   hAccEleEE->Write();
   hAccMu->Write();
   hAccTimesTrgEff->Write();
   hTrgEff->Write();
   hAccTimesEff->Write();
   hAccTimesEffEB->Write();
   hAccTimesEffEE->Write();
   hAccTimesEffEle->Write();
   hAccTimesEffEleEB->Write();
   hAccTimesEffEleEE->Write();
   hAccTimesEffMu->Write();
   hEffAftTrg->Write();
   hEffAftTrgEle->Write();
   hEffAftTrgEleEB->Write();
   hEffAftTrgEleEE->Write();
   hEffAftTrgMu->Write();
   fitFunc->Write();
   fitFuncEB->Write();
   fitFuncEE->Write();

   output->Close();
   timer.Stop();
   timer.Print();
}
void plotter(const char* datafilename, const char* mcfilename, const char *idmvaCorrectionFile = NULL) {

  // READ Transformations
  std::vector<TGraph*> graphs;
  if (idmvaCorrectionFile != NULL) readTransformations(graphs);
    //readTransformations(graphs, idmvaCorrectionFile);

  //std::vector<TGraph*> graphs;
  //readTransformations(graphs);
  
  // READ SAMPLES
  ifstream myReadFile;
  myReadFile.open("inputfiles.dat");
  char output[100];
  int itype = -1;
  if (myReadFile.is_open()) {
    while (!myReadFile.eof()) {
      float xsec;
      myReadFile >> output >> xsec >> itype;
      std::string init(output);
      if (init.substr(0,1) != "#") {
	samples.push_back(std::pair<std::string, int>(output, itype));
	//std::cout << output << " " << itype << std::endl;
      }
    }
  }
  myReadFile.close();
  std::cout<< "Debug level 1" << std::endl; 
  
  //std::string weight = "weight";
  
  for (int sampletype=0; sampletype<2; sampletype++) {
    
    TChain* chain = new TChain("PhotonToRECO/fitter_tree");
    if (sampletype == 0)
      chain->Add(datafilename);
    else
      chain->Add(mcfilename);
    
    TBranchesI branchesI;
    TBranchesF branchesF;
    TBranchesD branchesD;
    TBranchesUI branchesUI;
    TBranchesUC branchesUC;

    auto leafList = chain->GetListOfLeaves();
    for (auto leaf : *leafList) {
      std::string name =((TLeaf*)leaf)->GetName();
      std::string type = ((TLeaf*)leaf)->GetTypeName();
      
      std::cout << name << type << endl;
            if (type == "Int_t") {
	Int_t a = 0;
	branchesI[name] = a;
	chain->SetBranchAddress(name.c_str(), &(branchesI[name]));
      } else if (type == "Float_t") {
	Float_t a = 0;
	branchesF[name] = a;
	chain->SetBranchAddress(name.c_str(), &(branchesF[name]));
      } else if (type == "Double_t") {
	Double_t a = 0;
	branchesD[name] = a;
	chain->SetBranchAddress(name.c_str(), &(branchesD[name]));
      } else if (type == "UInt_t") {
	UInt_t a = 0;
	branchesUI[name] = a;
	chain->SetBranchAddress(name.c_str(), &(branchesUI[name]));
      } else if (type == "UChar_t") {
	UChar_t a = 0;
	branchesUC[name] = a;
	chain->SetBranchAddress(name.c_str(), &(branchesUC[name]));
	}
	    //std::cout<< "Debug level 1.1" << std::endl; 
    }
    //std::cout<< "Debug level 2" << std::endl; 
    
    std::map<int, std::vector<TTreeFormula*> > categories;
    std::cout << "Reading categories...." << std::endl;
    myReadFile.open("probeCategories.dat");
    std::string line;
    int cat;
    while(!myReadFile.eof()) {
      myReadFile >> cat >> line;
      char a[100];
      if (categories.find(cat) == categories.end() ) {
	sprintf(a, "cat%d_%d", cat, 0);
	std::cout << a << " " << line << std::endl;
	categories[cat].push_back(new TTreeFormula(a, line.c_str(), chain));
      } else {
	sprintf(a, "cat%d_%zu", cat, categories[cat].size());
	std::cout << a << " " << line << std::endl;
	categories[cat].push_back(new TTreeFormula(a, line.c_str(), chain));
      }
    }
    myReadFile.close();
    //std::cout<< "Debug level 3" << std::endl; 

    
    std::vector<HistoDefinition> histoDef;
    // READING PLOT DEFINITION
    std::cout << "Reading plots..." << std::endl;
    myReadFile.open("probesvar.dat");
    std::map<int, HistoContainer> histos;
    histos[samples[sampletype].second] = HistoContainer();
    
    while(!myReadFile.eof()) {
      // type ncat==1 xbin ybins xmin xmax ymin ymax name xaxis yaxis var cat????
      HistoDefinition temp;
      myReadFile >> temp.type >> temp.log >> temp.ncat >> temp.xbins >> temp.ybins >> temp.xmin >> temp.xmax
		 >> temp.ymin >> temp.ymax >> temp.name >> temp.xaxis >> temp.yaxis >> temp.var;
      histoDef.push_back(temp);
      
      TH1F* h = new TH1F("h", "", temp.xbins, temp.xmin, temp.xmax);
      h->GetXaxis()->SetTitle(temp.xaxis.c_str());
      h->GetYaxis()->SetTitle(temp.yaxis.c_str());
      
      int ncats = categories[temp.ncat].size();
      for (int c=0; c<ncats; c++) {
	
	std::ostringstream convert; 
	convert << c;
	std::string name = temp.name + "_cat"+ convert.str() + "_" + samples[sampletype].first;  
	std::cout << c << " " << name << std::endl;
	histos[samples[sampletype].second].histoF[temp.name].push_back(*((TH1F*)h->Clone(name.c_str())));
      }
      delete h;
    }
    myReadFile.close();
    // std::cout<< "Debug level 4 " << chain->GetEntries() << std::endl; 

    for (int z=0; z<chain->GetEntries(); z++) {
      if (z%10000 == 0)
	std::cout << z << std::endl;
      
      chain->GetEntry(z);

      float mass = branchesF["mass"];
      if ((mass > 70 && mass < 110) && ((abs(branchesF["probe_sc_eta"]) < 1.5 && branchesF["probe_Pho_sieie"] < 0.0105) || (abs(branchesF["probe_sc_eta"]) > 1.5 && branchesF["probe_Pho_sieie"] < 0.028))) {
	double weight = 1.0; 
	if (sampletype == 1 && isfinite(branchesF["totWeight"])) {
	  weight = branchesF["totWeight"];
	  // std::cout << "weight in the loop: " << weight << "and:  " << branchesD["totWeight"] << std::endl; 
	}  
	// cout << "mass: " << mass << " - " << "tag_Pho_mva" << branchesF["tag_Pho_mva"] << " - " << "probe_Pho_mva" << branchesF["probe_Pho_mva"] << endl;
	for (unsigned int s=0; s<samples.size(); s++) {
	  for (unsigned int h=0; h<histoDef.size(); h++) {
	    // std::cout << histoDef[h].name << " " << histoDef[h].var << " " << histoDef[h].ncat << std::endl;
	    std::string name = histoDef[h].name;
	    std::string var = histoDef[h].var;
	    int category = histoDef[h].ncat;
	    
	    double final_weight = weight;
	    // std::cout << "final_weight: " << final_weight << std::endl;
	    for (unsigned int cat=0; cat<categories[category].size(); cat++) {
	      categories[category][cat]->UpdateFormulaLeaves();
	      // std::cout<< "Going to draw histogram " << name <<std::endl;
	      
	      if (categories[category][cat]->EvalInstance()) {
		if (name == "idmvaup1" || name == "idmvaup2")
 		  histos[samples[sampletype].second].histoF[name][cat].Fill(branchesF[var]+idmvaShift, final_weight);
		else if (name == "idmvadown1" || name == "idmvadown2")  
 		  histos[samples[sampletype].second].histoF[name][cat].Fill(branchesF[var]-idmvaShift, final_weight);
		else if (name == "idmvatop1" || name == "idmvatop2")
		  {
		  if (idmvaCorrectionFile != NULL)
		    {

		      if(cat == 0 || cat == 1){ histos[samples[sampletype].second].histoF[name][cat].Fill(graphs[cat+2]->Eval(branchesF[var]), final_weight*graphs[cat+2]->Eval(9999));}
		    }
		  }
		else if (name == "idmvabottom1" || name == "idmvabottom2")
		  {
		    if (idmvaCorrectionFile != NULL)
		      {
			if(cat == 0 || cat == 1){ histos[samples[sampletype].second].histoF[name][cat].Fill(graphs[cat]->Eval(branchesF[var]), final_weight*graphs[cat]->Eval(9999));}
		      }

		  }
		else if (name == "sigmaEoEup1" || name == "sigmaEoEup2")
 		  histos[samples[sampletype].second].histoF[name][cat].Fill(branchesF[var]*(1+sigmaEScale), final_weight);
		else if (name == "sigmaEoEdown1" || name == "sigmaEoEdown2")  
 		  histos[samples[sampletype].second].histoF[name][cat].Fill(branchesF[var]*(1-sigmaEScale), final_weight);
		else if (branchesF.find(var) != branchesF.end())
		  histos[samples[sampletype].second].histoF[name][cat].Fill(branchesF[var], final_weight);
		else if (branchesI.find(var) != branchesI.end())
		  histos[samples[sampletype].second].histoF[name][cat].Fill(branchesI[var], final_weight);
	      }	    
	      // std::cout<< "histo " << name << " drawn" << std::endl;
	      // std::cout<< "Debug level 5 " << z << " " << s << " " << h << " " << " " << cat << std::endl; 
	    }
	    // std::cout << "Debug level 6" << std::endl;
	  }
	  // std::cout << "Debug level 7" << std::endl;
	  break;
	}
	// std::cout << "Debug level 8" << std::endl;	
      }
      // std::cout << "Debug level 9" << std::endl;
      // if(sampletype==0 && z>=10000) break ;
      if(sampletype==1 && z>0) break ;
    }
    
    std::cout << sampletype << std::endl;
    std::string rootOutputFile = "tnp_data_2017.root";  
    if (sampletype == 1)
      rootOutputFile = "tnp_tmp.root";
    
    TFile* out = new TFile(rootOutputFile.c_str(), "recreate");
    
    for (unsigned int h=0; h<histoDef.size(); h++) {
      std::string var = histoDef[h].name;
      int cat = categories[histoDef[h].ncat].size();
      for (int c=0; c<cat; c++) {
	histos[samples[sampletype].second].histoF[var][c].Write();
      }
      //std::cout << "Wrote histo successfully" << var << std::endl; 
    }
    out->Close();
  }
}
Example #8
0
void compareDataMC( vector<TChain*> chmc , vector<char*> labels , TChain* chdata , char* var , 
		    TCut sel , TCut weight , int nbins ,  float xmin , float xmax ,  
		    char* xtitle , bool overlayData , bool residual , bool drawLegend , bool log , char* flavor ){

  TPad* fullpad = new TPad();
  TPad* plotpad = new TPad();
  TPad* respad  = new TPad();

  if( residual ){
    fullpad = new TPad("fullpad","fullpad",0,0,1,1);
    fullpad->Draw();
    fullpad->cd();

    plotpad = new TPad("plotpad","plotpad",0,0,1,0.8);
    plotpad->Draw();
    plotpad->cd();
    if( log ) plotpad->SetLogy();
  }
  else{
    if( log ) gPad->SetLogy();
  }

  TString tvar(var);
  tvar.ReplaceAll("()","");
  tvar.ReplaceAll(".","");
  const char* myvar = tvar;

  cout << "Plotting var " << myvar << " flavor " << flavor << endl;

  int colors[]={6,2,7,4,5,8,9,15,12};
  int sigcolors[]={4,1,7,4,5,8,9,15,12};
  int isigmc = 0;

  assert( chmc.size() == labels.size() );
  const unsigned int nmc = chmc.size();

  THStack* mcstack = new THStack("mcstack","mcstack");
  TH1F*    mctothist = new TH1F();
  TH1F*    smtothist = new TH1F();
  TH1F*    mchist[nmc];
  TH1F*    datahist = new TH1F(Form("%s_datahist_%s",myvar,flavor),Form("%s_datahist_%s",myvar,flavor),nbins,xmin,xmax);

  vector<TH1F*> sighist;

  float trigeff = 1.0;
  //if     ( TString(flavor).Contains("ee")  ) trigeff = 1.00;
  //else if( TString(flavor).Contains("mm")  ) trigeff = 0.90;
  //else if( TString(flavor).Contains("em")  ) trigeff = 0.95;
  //else if( TString(flavor).Contains("all") ) trigeff = 0.95;

  TCut trigweight(Form("%.2f",trigeff));

  for( unsigned int imc = 0 ; imc < nmc ; imc++ ){
  //for( int imc = nmc-1 ; imc > -1 ; imc-- ){

    bool isSignal = TString( labels.at(imc) ).Contains("T2");

    mchist[imc] = new TH1F(Form("%s_mc_%i_%s",myvar,imc,flavor),Form("%s_mc_%i_%s",myvar,imc,flavor),nbins,xmin,xmax);
    mchist[imc]->Sumw2();

    chmc.at(imc)->Draw(Form("TMath::Min(%s,%f)>>%s_mc_%i_%s",var,xmax-0.01,myvar,imc,flavor),sel*weight*trigweight);

    if( isSignal ){
      mchist[imc]->SetFillColor( 0 );
      //mchist[imc]->SetLineStyle(2);
      mchist[imc]->SetLineWidth(2);
      mchist[imc]->SetLineColor( sigcolors[isigmc++] );
      if( TString( labels.at(imc) ).Contains("X5") ){
	mchist[imc]->Scale(5);
	cout << "Scaling signal MC by 5" << endl;
      }
      if( TString( labels.at(imc) ).Contains("X6") ){
	mchist[imc]->Scale(6);
	cout << "Scaling signal MC by 6" << endl;
      }
      if( TString( labels.at(imc) ).Contains("X10") ){
	mchist[imc]->Scale(10);
	cout << "Scaling signal MC by 10" << endl;
      }
    }else{
      mchist[imc]->SetLineWidth(1);
      mchist[imc]->SetFillColor( colors[imc] );
      mchist[imc]->SetLineColor( 1 );
    }

    //mcstack->Add( mchist[imc] );

    if( !isSignal ){
      mcstack->Add( mchist[imc] );

      if( imc == 0 ){
	mctothist = (TH1F*) mchist[imc]->Clone();
	smtothist = (TH1F*) mchist[imc]->Clone();
      }
      else{
	mctothist->Add(mchist[imc]);
	smtothist->Add(mchist[imc]);
      }
    }
    else{
      mctothist->Add(mchist[imc]);
      sighist.push_back( mchist[imc] );
    }

    cout << "MC yield " << labels[imc] << " " << Form("%.2f",mchist[imc]->Integral()) << endl;
  }

  chdata->Draw(Form("TMath::Min(%s,%f)>>%s_datahist_%s",var,xmax-0.01,myvar,flavor),sel);

  if( overlayData ){

    float max = datahist->GetMaximum() + datahist->GetBinError(datahist->GetMaximumBin());
    if( mctothist->GetMaximum() > max ) max = mctothist->GetMaximum();
    if( log ) datahist->SetMaximum( 15 * max );
    else      datahist->SetMaximum( 1.4 * max );

    datahist->GetXaxis()->SetTitle(xtitle);
    datahist->Draw("E1");
    mcstack->Draw("samehist");
    
    for( unsigned int isig = 0 ; isig < sighist.size() ; isig++ ){
      sighist.at(isig)->Add(smtothist);
      sighist.at(isig)->Draw("samehist");
    } 

    datahist->Draw("sameE1");
    datahist->Draw("sameaxis");

    if(!log) datahist->GetYaxis()->SetRangeUser(0.,1.4*max);
    
  }
  else{
    float max = mctothist->GetMaximum();
    if( log ) mctothist->SetMaximum( 15 * max );
    else      mctothist->SetMaximum( 1.4 * max );

    mctothist->SetLineColor(0);
    mctothist->SetFillColor(0);

    mctothist->GetXaxis()->SetTitle(xtitle);
    mctothist->Draw("hist");
    mcstack->Draw("samehist");

    for( unsigned int isig = 0 ; isig < sighist.size() ; isig++ ){
      sighist.at(isig)->Add(smtothist);
      sighist.at(isig)->Draw("samehist");
    } 

    mctothist->Draw("sameaxis");
  }

  if( drawLegend ){
    TLegend* myleg = getLegend( chmc , labels , overlayData );
    myleg->Draw();
  }

  TLatex *text = new TLatex();
  text->SetNDC();
  text->SetTextSize(0.04);
  text->DrawLatex(0.2,0.88,"CMS Preliminary");
  //text->DrawLatex(0.2,0.83,"0.98 fb^{-1} at #sqrt{s} = 7 TeV");
  text->DrawLatex(0.2,0.83,"#sqrt{s} = 7 TeV, #scale[0.6]{#int}Ldt = 1.0 fb^{-1}");

  if     ( TString(flavor).Contains("e")  )  text->DrawLatex(0.2,0.78,"e-channel");
  else if( TString(flavor).Contains("m")  )  text->DrawLatex(0.2,0.78,"#mu-channel");
  else if( TString(flavor).Contains("all") ) text->DrawLatex(0.2,0.78,"e/#mu-channel");

  if( residual ){
    fullpad->cd();

    respad = new TPad("respad","respad",0,0.8,1,1);
    respad->Draw();
    respad->cd();

    //gPad->SetGridy();

    TH1F* ratio = (TH1F*) datahist->Clone(Form("%s_ratio",datahist->GetName()));
    ratio->Divide(smtothist);

    ratio->GetYaxis()->SetTitleOffset(0.3);
    ratio->GetYaxis()->SetTitleSize(0.2);
    ratio->GetYaxis()->SetNdivisions(5);
    ratio->GetYaxis()->SetLabelSize(0.2);
    ratio->GetYaxis()->SetRangeUser(0.5,1.5);
    ratio->GetYaxis()->SetTitle("data/SM  ");
    ratio->GetXaxis()->SetLabelSize(0);
    ratio->GetXaxis()->SetTitleSize(0);
    ratio->SetMarkerSize(1);
    ratio->Draw();

    TLine line;
    line.SetLineWidth(1);
    line.DrawLine(datahist->GetXaxis()->GetXmin(),1,datahist->GetXaxis()->GetXmax(),1);

  }






}
void plot_eff_vs_general_var_grand_pas(Bool_t rebin=false, Bool_t range=false){

   //-------------------------------------------------------------------------------------
   // variable: 1 - eta, 2 - pt, 3 - jet 
   //-------------------------------------------------------------------------------------
   

   int variable = 2;
   rebin = false;
   range = true;
   
   bool MBonly = false;
   bool effonly = true;
   bool fakonly = false;
   bool lowerhalf = false;
   int logX = 1;

   double minpt = 5.0;
   double maxpt = 200;

   double minjet = 0;
   double maxjet = 0;
   
   double minjet2 = 130;
   double maxjet2 = 170;



   double maxeta = 1.0;

   Char_t VARIABLE[100];


   if(variable==1){
      TH1F *dum = new TH1F("dum","",100,-2.5,2.5);
      dum->GetXaxis()->SetTitle("#eta");
      sprintf(VARIABLE,"ETA_%1.1f",maxeta);
      if(lowerhalf) dum->SetMaximum(0.5);
   }else if(variable==2){
      TH1F *dum = new TH1F("dum","",100,0.5,320);
      //if(range) dum->SetAxisRange(0,160);
      dum->GetXaxis()->SetTitle("p_{T} [GeV/c]");
      dum->GetXaxis()->CenterTitle();
      dum->GetYaxis()->SetDecimals();
      sprintf(VARIABLE,"PT_minpt_%1.1f_%1.1f_%1.1f",minpt,minjet,maxjet);
   }else if(variable==3){
      TH1F *dum = new TH1F("dum","",100,0,1200);
      dum->GetXaxis()->SetTitle("Corrected leading jet E_{T} (GeV)");
      sprintf(VARIABLE,"JETET_minpt_%1.1f",minpt);
   }   


   dum->SetMinimum(-0.05);
   dum->SetMaximum(1.0);
   dum->SetStats(0);
   //dum->GetYaxis()->SetTitle("Fractional efficiency");
   dum->GetYaxis()->SetTitle("A #times #epsilon_{TR}");
   dum->GetXaxis()->SetTitleSize(0.05);
   dum->GetYaxis()->SetTitleSize(0.05);
   dum->GetYaxis()->SetTitleOffset(1.5);
   dum->GetYaxis()->SetNdivisions(911);
   
   //gROOT->LoadMacro("trkeffanalyzer_hist_jet.C");      
   gROOT->LoadMacro("trkeffanalyzer_hist_general_variable.C");
   
   Char_t fileName1[100];
   Char_t fileName2[100];
   Char_t fileName3[100];
   Char_t fileName4[100];
   Char_t fileName5[100];
   Char_t fileName6[100];

   
   Char_t fileString1[200];
   Char_t fileString2[200];
   Char_t fileString3[200];
   Char_t fileString4[200];
   Char_t fileString5[200];
   Char_t fileString6[200];


   //sprintf(fileName1,"TrkHistMC_QCD_10M.root");
   //sprintf(fileName1,"TrkHistMC_july09v2_qcdMBD6TdJuly09V3_div2.root");
   //sprintf(fileString1,"/Users/andreyoon/Research/ana/spectra/pp_spectra/7TeV/root_files/%s",fileName1);

   sprintf(fileName1,"TrkHistGEN_oct06_qcdMBD6TV1.root");
   sprintf(fileString1,"/Users/andreyoon/Research/pp7TeV/root_files_postApp/mc/%s",fileName1);
   cout<<"input file 1 is "<<fileString1<<endl;
   
   //sprintf(fileName2,"TrkHistMC_QCD_Pt15.root");
   //sprintf(fileName2,"TrkHistMC_july09v2_qcdPt15dJuly09_div2.root");
   //sprintf(fileString2,"/Users/andreyoon/Research/ana/spectra/pp_spectra/7TeV/root_files/%s",fileName2);

   sprintf(fileName2,"TrkHistGEN_oct01_qcdPt15V1.root");
   sprintf(fileString2,"/Users/andreyoon/Research/pp7TeV/root_files_postApp/mc/%s",fileName2);
   cout<<"input file 2 is "<<fileString2<<endl;
   
   //sprintf(fileName3,"TrkHistMC_QCD_Pt30v2.root");
   //sprintf(fileName3,"TrkHistMC_july09v2_qcdPt30dJuly09V2_div2.root");
   //sprintf(fileString3,"/Users/andreyoon/Research/ana/spectra/pp_spectra/7TeV/root_files/%s",fileName3);

   sprintf(fileName3,"TrkHistGEN_oct01_qcdPt30V2.root");
   sprintf(fileString3,"/Users/andreyoon/Research/pp7TeV/root_files_postApp/mc/%s",fileName3);
   cout<<"input file 3 is "<<fileString3<<endl;
   
   //sprintf(fileName4,"TrkHistMC_QCD_Pt80v2.root");
   //sprintf(fileName4,"TrkHistMC_july09v2_qcdPt80dJuly09V2_div2.root");
   //sprintf(fileString4,"/Users/andreyoon/Research/ana/spectra/pp_spectra/7TeV/root_files/%s",fileName4);

   sprintf(fileName4,"TrkHistGEN_oct01_qcdPt80V2.root");
   sprintf(fileString4,"/Users/andreyoon/Research/pp7TeV/root_files_postApp/mc/%s",fileName4);
   cout<<"input file 4 is "<<fileString4<<endl;
   
   //sprintf(fileName5,"TrkHistMC_QCD_Pt170_V2_1st.root");  
   //sprintf(fileName5,"TrkHistMC_july09v2_qcdPt170dJuly09_div2.root");
   //sprintf(fileString5,"/Users/andreyoon/Research/ana/spectra/pp_spectra/7TeV/root_files/%s",fileName5);

   sprintf(fileName5,"TrkHistGEN_oct01_qcdPt170V1.root");
   sprintf(fileString5,"/Users/andreyoon/Research/pp7TeV/root_files_postApp/mc/%s",fileName5);
   cout<<"input file 5 is "<<fileString5<<endl;

   //sprintf(fileName6,"TrkHistMC_QCD_Pt470_V2_1st.root"); 
   //sprintf(fileName6,"TrkHistMC_july09v2_dec14_qcdPt300dJuly09V2.root");
   //sprintf(fileString6,"/Users/andreyoon/Research/ana/spectra/pp_spectra/7TeV/root_files/%s",fileName6);

   sprintf(fileName6,"TrkHistGEN_oct01_qcdPt300V1.root");
   sprintf(fileString6,"/Users/andreyoon/Research/pp7TeV/root_files_postApp/mc/%s",fileName6);
   cout<<"input file 6 is "<<fileString6<<endl;

   char jetrange1[100], jetrange2[100], jetrange3[100], jetrange4[100], jetrange5[100], jetrange6[100];
   char jetrange7[100], jetrange8[100], jetrange9[100], jetrange10[100], jetrange11[100], jetrange12[100];

   // 0-20  MB

   minjet = 0, maxjet = 20;
   sprintf(jetrange1," %1.0f<E_{T}<%1.0f",minjet,maxjet);

   trkeffanalyzer_hist_data d1 = trkeffanalyzer_hist_graph(fileString1,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt);

   TGraphAsymmErrors *Eff1 = d1.gEfficiency;
   TGraphAsymmErrors *FR1  = d1.gFakerate;

   TGraphAsymmErrors *Eff1Skm = removeLastPoint(Eff1,1);
   TGraphAsymmErrors *FR1Skm = removeLastPoint(FR1,1);

   // 20-40 MB, Pt15
   minjet = 20, maxjet =40;
   sprintf(jetrange2," %1.0f<E_{T}<%1.0f",minjet,maxjet);
   
   trkeffanalyzer_hist_data d2 = trkeffanalyzer_hist_graph(fileString1,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt);

   TGraphAsymmErrors *Eff2 = d2.gEfficiency;
   TGraphAsymmErrors *FR2  = d2.gFakerate;

   TGraphAsymmErrors *Eff2Skm = removeLastPoint(Eff2,1);
   TGraphAsymmErrors *FR2Skm = removeLastPoint(FR2,1);

   //TGraphAsymmErrors *Eff2Skm = removeLastPoint(Eff2,0);
   //TGraphAsymmErrors *FR2Skm = removeLastPoint(FR2,0);

   trkeffanalyzer_hist_data d3 = trkeffanalyzer_hist_graph(fileString2,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt);

   TGraphAsymmErrors *Eff3 = d3.gEfficiency;
   TGraphAsymmErrors *FR3  = d3.gFakerate;

   TGraphAsymmErrors *Eff3Skm = removeLastPoint(Eff3,1);
   TGraphAsymmErrors *FR13km = removeLastPoint(FR3,1);

   //TGraphAsymmErrors *Eff3Skm = removeLastPoint(Eff3,0);
   //TGraphAsymmErrors *FR13km = removeLastPoint(FR3,0);

   // 40-60 Pt15, Pt30
   minjet = 40, maxjet =60;
   sprintf(jetrange3," %1.0f<E_{T}<%1.0f ",minjet,maxjet);

   trkeffanalyzer_hist_data d4 = trkeffanalyzer_hist_graph(fileString2,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt);

   TGraphAsymmErrors *Eff4 = d4.gEfficiency;
   TGraphAsymmErrors *FR4  = d4.gFakerate;

   TGraphAsymmErrors *Eff4Skm = removeLastPoint(Eff4,2);
   TGraphAsymmErrors *FR4Skm = removeLastPoint(FR4,2);

   //TGraphAsymmErrors *Eff4Skm = removeLastPoint(Eff4,0);
   //TGraphAsymmErrors *FR4Skm = removeLastPoint(FR4,0);

   trkeffanalyzer_hist_data d5 = trkeffanalyzer_hist_graph(fileString3,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt);

   TGraphAsymmErrors *Eff5 = d5.gEfficiency;
   TGraphAsymmErrors *FR5 = d5.gFakerate;
 
   TGraphAsymmErrors *Eff5Skm = removeLastPoint(Eff5,2);
   TGraphAsymmErrors *FR5Skm = removeLastPoint(FR5,2);

   //TGraphAsymmErrors *Eff5Skm = removeLastPoint(Eff5,0);
   //TGraphAsymmErrors *FR5Skm = removeLastPoint(FR5,0);

   // 60-80 Pt30 
   minjet = 60, maxjet =80;
   sprintf(jetrange4," %1.0f<E_{T}<%1.0f",minjet,maxjet);

   trkeffanalyzer_hist_data d6 = trkeffanalyzer_hist_graph(fileString3,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt);

   TGraphAsymmErrors *Eff6 = d6.gEfficiency;
   TGraphAsymmErrors *FR6 = d6.gFakerate;

   TGraphAsymmErrors *Eff6Skm = removeLastPoint(Eff6,3);
   TGraphAsymmErrors *FR6Skm = removeLastPoint(FR6,3);


   // 80-100 Pt80 -> Pt30
   minjet = 80, maxjet =100;
   sprintf(jetrange5," %1.0f<E_{T}<%1.0f",minjet,maxjet);

   //trkeffanalyzer_hist_data d7 = trkeffanalyzer_hist_graph(fileString4,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt);
   trkeffanalyzer_hist_data d7 = trkeffanalyzer_hist_graph(fileString3,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt); 
   
   TGraphAsymmErrors *Eff7 = d7.gEfficiency;
   TGraphAsymmErrors *FR7 = d7.gFakerate;
   
   TGraphAsymmErrors *Eff7Skm = removeLastPoint(Eff7,2);
   TGraphAsymmErrors *FR7Skm = removeLastPoint(FR7,2);

   //TGraphAsymmErrors *Eff7Skm = removeLastPoint(Eff7,0);
   //TGraphAsymmErrors *FR7Skm = removeLastPoint(FR7,0);

 
   // 100-120 Pt80
   minjet = 100, maxjet =120;
   sprintf(jetrange6," %1.0f<E_{T}<%1.0f",minjet,maxjet);

   trkeffanalyzer_hist_data d8 = trkeffanalyzer_hist_graph(fileString4,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt);

   TGraphAsymmErrors *Eff8 = d8.gEfficiency;
   TGraphAsymmErrors *FR8 = d8.gFakerate;

   TGraphAsymmErrors *Eff8Skm = removeLastPoint(Eff8,3);
   TGraphAsymmErrors *FR8Skm = removeLastPoint(FR8,3);

   //TGraphAsymmErrors *Eff8Skm = removeLastPoint(Eff8,0);
   //TGraphAsymmErrors *FR8Skm = removeLastPoint(FR8,0);


   // 120-140
   
   // 140-160

   // 160-180

   // 180-200 Pt80, Pt170
   minjet = 180, maxjet =200;
   sprintf(jetrange7," %1.0f<E_{T}<%1.0f",minjet,maxjet);

   trkeffanalyzer_hist_data d9 = trkeffanalyzer_hist_graph(fileString4,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt);

   TGraphAsymmErrors *Eff9 = d9.gEfficiency;
   TGraphAsymmErrors *FR9 = d9.gFakerate;
   
   TGraphAsymmErrors *Eff9Skm = removeLastPoint(Eff9,1);
   TGraphAsymmErrors *FR9Skm = removeLastPoint(FR9,1);

   //TGraphAsymmErrors *Eff9Skm = removeLastPoint(Eff9,0);
   //TGraphAsymmErrors *FR9Skm = removeLastPoint(FR9,0);


   trkeffanalyzer_hist_data d10 = trkeffanalyzer_hist_graph(fileString5,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt);

   TGraphAsymmErrors *Eff10 = d10.gEfficiency;
   TGraphAsymmErrors *FR10 = d10.gFakerate;
   
   TGraphAsymmErrors *Eff10Skm = removeLastPoint(Eff10,2);
   TGraphAsymmErrors *FR10Skm = removeLastPoint(FR10,2);

   //TGraphAsymmErrors *Eff10Skm = removeLastPoint(Eff10,0);
   //TGraphAsymmErrors *FR10Skm = removeLastPoint(FR10,0);

   //250 -300 
   minjet = 250, maxjet =300;
   sprintf(jetrange8," %1.0f<E_{T}<%1.0f",minjet,maxjet);

   trkeffanalyzer_hist_data d11 = trkeffanalyzer_hist_graph(fileString4,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt);

   TGraphAsymmErrors *Eff11 = d11.gEfficiency;
   TGraphAsymmErrors *FR11 = d11.gFakerate;

   TGraphAsymmErrors *Eff11Skm = removeLastPoint(Eff11,1);
   TGraphAsymmErrors *FR11Skm = removeLastPoint(FR11,1);

   //TGraphAsymmErrors *Eff11Skm = removeLastPoint(Eff11,0);
   //TGraphAsymmErrors *FR11Skm = removeLastPoint(FR11,0);
   

   //500 - 2400
   minjet = 500, maxjet =2400;
   sprintf(jetrange9," %1.0f<E_{T}<%1.0f",minjet,maxjet);

   trkeffanalyzer_hist_data d12 = trkeffanalyzer_hist_graph(fileString6,rebin,range,variable,0.0,maxeta,minjet,maxjet,minpt,maxpt);

   TGraphAsymmErrors *Eff12 = d12.gEfficiency;
   TGraphAsymmErrors *FR12 = d12.gFakerate;

   TGraphAsymmErrors *Eff12Skm = removeLastPoint(Eff12,0);
   TGraphAsymmErrors *FR12Skm = removeLastPoint(FR12,0);


   

   Char_t xTitle[100],yTitle[100];
   sprintf(xTitle,"p_{T} [GeV/c]");
   sprintf(yTitle,"Ratio");
   
   TCanvas *call = new TCanvas("call","call",500,550);
   call->SetGridx(),call->SetGridy();
   //if(logX) call->SetLogx();
   call->cd();
   dum->Draw();
   
   float binsize = 1.3;
   float binsize2 = binsize*0.86;
   

   int color=0;
   color = 15;
   int dopt=4;

   th1Style1(Eff1Skm,color,20,binsize,color,1,1,dopt);       
   th1Style1(FR1Skm,color,21,binsize,color,1,1,dopt);

   color = 16;
   th1Style1(Eff2Skm,color,20,binsize,color,1,1,dopt);
   th1Style1(FR2Skm,color,21,binsize,color,1,1,dopt);

   //th1Style1(Eff3Skm,color,24,binsize,color,1,1,dopt);
   //th1Style1(FR3Skm,color,25,binsize,color,1,1,dopt);

   color = 17; 
   th1Style1(Eff4Skm,color,20,binsize,color,1,1,dopt);
   th1Style1(FR4Skm,color,21,binsize,color,1,1,dopt);

   //th1Style1(Eff5,color,24,binsize,color,1,1,1);
   //th1Style1(FR5,color,25,binsize,color,1,1,1);

   color = 18;
   th1Style1(Eff6Skm,color,20,binsize,color,1,1,dopt);
   th1Style1(FR6Skm,color,21,binsize,color,1,1,dopt);

   color = 19;
   th1Style1(Eff7Skm,color,20,binsize,color,1,1,dopt);
   th1Style1(FR7Skm,color,21,binsize,color,1,1,dopt);

   color = 20;
   th1Style1(Eff8Skm,color,20,binsize,color,1,1,dopt);
   th1Style1(FR8Skm,color,21,binsize,color,1,1,dopt);

   color = 21;
   //th1Style1(Eff9,color,20,binsize,color,1,1,1);
   //th1Style1(FR9,color,21,binsize,color,1,1,1);

   th1Style1(Eff10Skm,color,20,binsize,color,1,1,dopt);
   th1Style1(FR10Skm,color,21,binsize,color,1,1,dopt);

   color = 22;
   //th1Style1(Eff11Skm,color,20,binsize,color,1,1,dopt);
   //th1Style1(FR11Skm,color,21,binsize,color,1,1,dopt);

   th1Style1(Eff12Skm,color,20,binsize,color,1,1,dopt);
   th1Style1(FR12Skm,color,21,binsize,color,1,1,dopt);

   

   /*
   th1Style1(FR3,15,4,binsize,15,1,1,1);
   TGraphAsymmErrors* FR3_dum = FR3->Clone("FR3_dum");
   th1Style1(FR3_dum,10,20,binsize2,15,1,1,1);

   if(!MBonly){
   th1Style1(Eff4,16,20,binsize,16,1,1,1);
   
   th1Style1(FR4,16,4,binsize,16,1,1,1);
   TGraphAsymmErrors* FR4_dum = FR4->Clone("FR4_dum");
   th1Style1(FR4_dum,10,20,binsize2,16,1,1,1);
   
   
   th1Style1(Eff5,17,20,binsize,17,1,1,1);
   th1Style1(FR5,17,4,binsize,17,1,1,1);
   TGraphAsymmErrors* FR5_dum = FR5->Clone("FR5_dum");
   th1Style1(FR5_dum,10,20,binsize2,17,1,1,1);
   
   
   th1Style1(Eff6,15,24,binsize,15,1,1,1);
   th1Style1(FR6,18,4,binsize,18,1,1,1);
   TGraphAsymmErrors* FR6_dum = FR6->Clone("FR6_dum");
   th1Style1(FR6_dum,10,20,binsize2,18,1,1,1);

   th1Style1(Eff7,16,24,binsize,16,1,1,1);
   th1Style1(FR7,19,4,binsize,19,1,1,1);
   TGraphAsymmErrors* FR7_dum = FR7->Clone("FR7_dum");
   th1Style1(FR7_dum,10,20,binsize2,19,1,1,1);

   th1Style1(Eff8,17,24,binsize,17,1,1,1);
   th1Style1(FR8,20,4,binsize,20,1,1,1);
   TGraphAsymmErrors* FR8_dum = FR7->Clone("FR8_dum");
   th1Style1(FR8_dum,10,20,binsize2,19,1,1,1);
   }
   */


   if(!MBonly){
      //TLegend *leg = new TLegend(0.54,0.4,0.89,0.62);
      //TLegend *leg = new TLegend(0.54,0.36,0.89,0.62);      
      //TLegend *leg = new TLegend(0.19,0.37,0.93,0.63); 
      //TLegend *leg = new TLegend(0.19,0.4,0.65,0.63);     
     //TLegend *leg = new TLegend(0.23,0.3,0.69,0.52);  
     TLegend *leg = new TLegend(0.23,0.25,0.69,0.47);   
      leg->SetBorderSize(1);
      leg->SetFillColor(kWhite);
      //leg->SetFillStyle(0);       
      leg->SetTextSize(0.031);
      leg->SetMargin(0.55);
      //leg->SetMargin(0.5);   
      /*
      char jetrange1[100];
      sprintf(jetrange1," %1.0f<E_{T}<%1.0f",minjet,maxjet); 
      char jetrange2[100];
      sprintf(jetrange2," %1.0f<E_{T}<%1.0f",minjet2,maxjet2);
      char header[100];
      sprintf(header,"    p_{T}^{hat}>15   p_{T}^{hat}>30   p_{T}^{hat}>80");
      leg->SetHeader(header); 
      */
      leg->SetNColumns(2);
      leg->SetColumnSeparation(0.000);

      leg->AddEntry(Eff1Skm,jetrange1,"lp");
      leg->AddEntry(dum,"MB   ","");

      leg->AddEntry(Eff2Skm,jetrange2,"lp");
      leg->AddEntry(dum,"MB   ","");

      leg->AddEntry(Eff4Skm,jetrange3,"lp");
      leg->AddEntry(dum,"Pt15  ","");

      leg->AddEntry(Eff6Skm,jetrange4,"lp");
      leg->AddEntry(dum,"Pt30  ","");

      leg->AddEntry(Eff7Skm,jetrange5,"lp");
      leg->AddEntry(dum,"Pt30  ","");

      leg->AddEntry(Eff8Skm,jetrange6,"lp");
      leg->AddEntry(dum,"Pt80  ","");

      leg->AddEntry(Eff10Skm,jetrange7,"lp");
      leg->AddEntry(dum,"Pt170  ","");
      
      leg->AddEntry(Eff12Skm,jetrange9,"lp");
      leg->AddEntry(dum,"Pt300  ","");

   }else{
     TLegend *leg = new TLegend(0.54,0.4,0.89,0.62);
     leg->SetBorderSize(1);
     leg->SetFillColor(kWhite);
     leg->SetTextSize(0.031);
     leg->SetMargin(0.35);
     //leg->SetHeader("  0 < Jet E_{T}< 20 ");
     leg->AddEntry(Eff3,"PYTHIA 7 TeV","lp");
   }
   leg->Draw();
   

   TLatex *tex = new TLatex(0.19,0.20,"Fake rate");
   tex->SetTextSize(0.04);
   tex->SetLineWidth(2);
   tex->SetNDC();
   //tex->Draw();


   
     Char_t outName1[100];
     //sprintf(outName1,"Eff_FR_GRAND_%s",VARIABLE);
     sprintf(outName1,"Eff_FR_GRAND_wider_v2");
     Char_t outName2[100];
     //sprintf(outName2,"Eff_FR_GRAND_logx_%s",VARIABLE);
     sprintf(outName2,"Eff_FR_GRAND_logx_wider_v2");


     tex->Draw();
     dum->SetMaximum(0.91);
     //dum->SetMinimum(0.65);
     dum->SetMinimum(0.50);
     printCanvases(call,outName1,0);

     dum->SetMinimum(-0.05);
     dum->SetMaximum(1.0);
     printCanvases(call,outName2,1);

}
Example #10
0
void plotLimit(TString outputDir="./", TString inputs="", TString inputXSec="", bool strengthLimit=true, bool blind=false, double energy=7, double luminosity=5.035, TString legendName="ee and #mu#mu channels")
{
  //style options
  gStyle->SetCanvasBorderMode(0);
  gStyle->SetCanvasColor(kWhite);
  gStyle->SetFrameBorderMode(0);
  gStyle->SetFrameBorderSize(1);
  gStyle->SetFrameFillColor(0);
  gStyle->SetFrameFillStyle(0);
  gStyle->SetFrameLineColor(1);
  gStyle->SetFrameLineStyle(1);
  gStyle->SetFrameLineWidth(1);
  gStyle->SetOptFit(1);
  gStyle->SetFitFormat("5.4g");
  gStyle->SetFuncColor(2);
  gStyle->SetOptFile(0);
  //gStyle->SetOptStat(0);
  gStyle->SetOptStat("mr");
  gStyle->SetStatColor(kWhite);
  gStyle->SetStatFont(42);
  gStyle->SetStatFontSize(0.04);
  gStyle->SetStatTextColor(1);
  gStyle->SetStatFormat("6.4g");
  gStyle->SetStatBorderSize(1);
  gStyle->SetStatH(0.1);
  gStyle->SetStatW(0.2);
  gStyle->SetPadTopMargin(0.05);
  gStyle->SetPadBottomMargin(0.13);
  gStyle->SetPadLeftMargin(0.16);
  gStyle->SetPadRightMargin(0.02);
  gStyle->SetOptTitle(0);
  gStyle->SetTitleFont(42);
  gStyle->SetTitleColor(1);
  gStyle->SetTitleTextColor(1);
  gStyle->SetTitleFillColor(10);
  gStyle->SetTitleFontSize(0.05);
  gStyle->SetAxisColor(1, "XYZ");
  gStyle->SetStripDecimals(kTRUE);
  gStyle->SetTickLength(0.03, "XYZ");
  gStyle->SetNdivisions(510, "XYZ");
  gStyle->SetPadTickX(1);  // To get tick marks on the opposite side of the frame
  gStyle->SetPadTickY(1);
  gStyle->SetEndErrorSize(2);
  gStyle->SetErrorX(0.);
  gStyle->SetMarkerStyle(20); 
  gROOT->ForceStyle();
  gStyle->SetPadTopMargin   (0.06);
  gStyle->SetPadBottomMargin(0.12);
  gStyle->SetPadRightMargin (0.06);
  gStyle->SetPadLeftMargin  (0.14);
  gStyle->SetTitleSize(0.04, "XYZ");
  gStyle->SetTitleXOffset(1.1);
  gStyle->SetTitleYOffset(1.45);
  gStyle->SetPalette(1);
  gStyle->SetNdivisions(505);


  string suffix = string(outputDir.Data());
  double cprime=1.0; double  brnew=0.0;
  double XSecScaleFactor = 1.0;
  if(suffix.find("_cp")!=string::npos){
     sscanf(suffix.c_str()+suffix.find("_cp"), "_cp%lf_brn%lf", &cprime, &brnew);
     XSecScaleFactor = pow(cprime,2) * (1-brnew);
  }
 
  //get xsec * br from summary file
  getXSecXBR(inputXSec); 
  //get the limits from the tree
  TFile* file = TFile::Open(inputs);
  printf("Looping on %s\n",inputs.Data());
  if(!file) return;
  if(file->IsZombie()) return;
  TTree* tree = (TTree*)file->Get("limit");
  tree->GetBranch("mh"              )->SetAddress(&Tmh      );
  tree->GetBranch("limit"           )->SetAddress(&Tlimit   );
  tree->GetBranch("limitErr"        )->SetAddress(&TlimitErr);
  tree->GetBranch("quantileExpected")->SetAddress(&TquantExp);
  int N = tree->GetEntriesFast() / 6 ;// 6Limits per mass point (observed, meand , +-1sigma, +-2sigma)
  double* MassAxis   = new double[N];
  double* ObsLimit   = new double[N];  fillLimitArray(tree,-1   ,ObsLimit,MassAxis);  if(!strengthLimit)scaleLimitsByXSecXBR(N, MassAxis, ObsLimit);
  double* ExpLimitm2 = new double[N];  fillLimitArray(tree,0.025,ExpLimitm2);         if(!strengthLimit)scaleLimitsByXSecXBR(N, MassAxis, ExpLimitm2);
  double* ExpLimitm1 = new double[N];  fillLimitArray(tree,0.160,ExpLimitm1);         if(!strengthLimit)scaleLimitsByXSecXBR(N, MassAxis, ExpLimitm1);
  double* ExpLimit   = new double[N];  fillLimitArray(tree,0.500,ExpLimit  );         if(!strengthLimit)scaleLimitsByXSecXBR(N, MassAxis, ExpLimit);
  double* ExpLimitp1 = new double[N];  fillLimitArray(tree,0.840,ExpLimitp1);         if(!strengthLimit)scaleLimitsByXSecXBR(N, MassAxis, ExpLimitp1);
  double* ExpLimitp2 = new double[N];  fillLimitArray(tree,0.975,ExpLimitp2);         if(!strengthLimit)scaleLimitsByXSecXBR(N, MassAxis, ExpLimitp2);
  file->Close();

  //make TH Cross-sections
  double* ThXSec   = new double[N]; for(unsigned int i=0;i<N;i++){ThXSec[i] = xsecXbr[MassAxis[i]];} 

  //scale TH cross-section and limits according to scale factor 
  //this only apply to NarrowResonnance case
  for(unsigned int i=0;i<N;i++){
    if(strengthLimit){
    ObsLimit[i]  /= XSecScaleFactor;
    ExpLimitm2[i]/= XSecScaleFactor;
    ExpLimitm1[i]/= XSecScaleFactor;
    ExpLimit  [i]/= XSecScaleFactor;
    ExpLimitp1[i]/= XSecScaleFactor;
    ExpLimitp2[i]/= XSecScaleFactor;
    }
    ThXSec[i]    *= XSecScaleFactor;
  }

    
  //limits in terms of signal strength
  TCanvas* c = new TCanvas("c", "c",600,600);
  TH1F* framework = new TH1F("Graph","Graph",1,90,160);
  framework->SetStats(false);
  framework->SetTitle("");
  framework->GetXaxis()->SetTitle("Higgs boson mass [GeV]");
  framework->GetYaxis()->SetTitleOffset(1.70);
  if(strengthLimit){
  framework->GetYaxis()->SetTitle("#mu = #sigma_{95%} / #sigma_{th}");
  framework->GetYaxis()->SetRangeUser(9E-1,1E3);
  c->SetLogy(true);
  }else{
  framework->GetYaxis()->SetTitle("#sigma_{95%} (fb)");
  framework->GetYaxis()->SetRangeUser(1E-1,1E3);
  c->SetLogy(true);
  }
  framework->Draw();

  TGraph* TGObsLimit   = new TGraph(N,MassAxis,ObsLimit);  TGObsLimit->SetLineWidth(2);
  TGraph* TGExpLimit   = new TGraph(N,MassAxis,ExpLimit);  TGExpLimit->SetLineWidth(2); TGExpLimit->SetLineStyle(2);
  TCutG* TGExpLimit1S  = GetErrorBand("1S", N, MassAxis, ExpLimitm1, ExpLimitp1);  
  TCutG* TGExpLimit2S  = GetErrorBand("2S", N, MassAxis, ExpLimitm2, ExpLimitp2);  TGExpLimit2S->SetFillColor(5);
  TGraph* THXSec        = new TGraph(N,MassAxis,ThXSec); THXSec->SetLineWidth(2); THXSec->SetLineStyle(1); THXSec->SetLineColor(4);


  TGExpLimit->SetLineColor(2);  TGExpLimit->SetLineStyle(1);
  TGObsLimit->SetLineWidth(2);  TGObsLimit->SetMarkerStyle(20);
  TGExpLimit2S->Draw("fc same");
  TGExpLimit1S->Draw("fc same");
  if(!blind) TGObsLimit->Draw("same CP");
  TGExpLimit->Draw("same C");

  if(strengthLimit){
     TLine* SMLine = new TLine(framework->GetXaxis()->GetXmin(),1.0,framework->GetXaxis()->GetXmax(),1.0);
     SMLine->SetLineWidth(2); SMLine->SetLineStyle(1); SMLine->SetLineColor(4);      
     SMLine->Draw("same C");
  }else{
     THXSec->Draw("same C");
  }


  TPaveText *pave = new TPaveText(0.1,0.96,0.99,0.99,"NDC");
  char LumiLabel[1024];
  if(energy<9){  sprintf(LumiLabel,"CMS preliminary,  #sqrt{s}=%.0f TeV, #scale[0.5]{#int} L=%6.1ffb^{-1} - %20s",energy, luminosity,legendName.Data());
  }else{         sprintf(LumiLabel,"CMS preliminary,  #sqrt{s}=%.0f TeV #scale[0.5]{#int} L=%6.1ffb^{-1}, #sqrt{s}=%.0f TeV #scale[0.5]{#int} L=%6.1ffb^{-1}",7.0,5.0,8.0,19.7);
  }
  pave->SetBorderSize(0);
  pave->SetFillStyle(0);
  pave->SetTextFont(42);
  TObjArray* tokens = (TString(LumiLabel)).Tokenize("\\\\");
  int nt = tokens->GetEntries();
  for(int it=0; it<nt; ++it){
    TObjString * t = (TObjString *)tokens->At(it);
    pave->AddText(t->GetString());
  }
  pave->Draw("same");


  TLegend* LEG = new TLegend(0.55,0.75,0.85,0.95);
  LEG->SetHeader("");
  LEG->SetFillColor(0);
  LEG->SetFillStyle(0);
  LEG->SetTextFont(42);
  LEG->SetBorderSize(0);
  LEG->AddEntry(THXSec  , "SM prediction"  ,"L");
  LEG->AddEntry(TGExpLimit  , "median expected"  ,"L");
  LEG->AddEntry(TGExpLimit1S  , "expected #pm 1#sigma"  ,"F");
  LEG->AddEntry(TGExpLimit2S  , "expected #pm 2#sigma"  ,"F");
  if(!blind) LEG->AddEntry(TGObsLimit  , "observed"  ,"LP");
  LEG->Draw();
  c->RedrawAxis();
  c->SaveAs(outputDir+"Limit.png");
  c->SaveAs(outputDir+"Limit.C");
  c->SaveAs(outputDir+"Limit.pdf"); 


  //save a summary of the limits
  FILE* pFileSum = fopen((outputDir+"LimitSummary").Data(),"w");
  for(int i=0;i<N;i++){
    fprintf(pFileSum, "$%8.6E$ & $%8.6E$ & $[%8.6E,%8.6E]$ & $[%8.6E,%8.6E]$ & $%8.6E$ & Th=$%8.6E$\\\\\\hline\n",MassAxis[i], ExpLimit[i], ExpLimitm1[i], ExpLimitp1[i], ExpLimitm2[i],  ExpLimitp2[i], ObsLimit[i], ThXSec[i]);
    if(int(MassAxis[i])%50!=0)continue; printf("%f ",ObsLimit[i]);
  }printf("\n");
  fclose(pFileSum);

  pFileSum = fopen((outputDir+"LimitRange").Data(),"w");
  fprintf(pFileSum, "EXPECTED LIMIT --> ");                   printLimits(pFileSum,TGExpLimit, MassAxis[0], MassAxis[N-1]);
  if(!blind) fprintf(pFileSum, "OBSERVED LIMIT --> ");        printLimits(pFileSum,TGObsLimit, MassAxis[0], MassAxis[N-1]);
  fprintf(pFileSum, "Exp Limits for Model are: ");              for(int i=0;i<N;i++){if(int(MassAxis[i])%50!=0)continue; fprintf(pFileSum, "%f+-%f ",ExpLimit[i], (ExpLimitp1[i]-ExpLimitm1[i]))/2.0;}fprintf(pFileSum,"\n");
  if(!blind) { fprintf(pFileSum, "Obs Limits for Model are: "); for(int i=0;i<N;i++){if(int(MassAxis[i])%50!=0)continue; fprintf(pFileSum, "%f ",ObsLimit[i]);}fprintf(pFileSum,"\n"); }
  fclose(pFileSum);
}
Example #11
0
void finalLimitPlot(){
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);
  //   setTDRStyle();
   gStyle->SetPadTopMargin   (0.04);
   gStyle->SetPadBottomMargin(0.12);
   gStyle->SetPadRightMargin (0.05);
   gStyle->SetPadLeftMargin  (0.12);
   gStyle->SetTitleSize(0.04, "XYZ");
   gStyle->SetTitleXOffset(1.1);
   gStyle->SetTitleYOffset(1.45);
   gStyle->SetPalette(1);
   gStyle->SetNdivisions(505);

   TCanvas* c1;
   TH1F* framework;
   TH2F* framework2d;
   TLegend* LEG, *LEGTH;
   TGraph* Ref;


   string Directories[]={"cards_CC8TeV_GG", "cards_SB8TeV_GG", "cards_CC8TeV_QQ", "cards_SB8TeV_QQ",  "cards_CC7TeV_GG", "cards_SB7TeV_GG", "cards_CC7TeV_QQ", "cards_SB7TeV_QQ"};
   for(unsigned int D=0;D<sizeof(Directories)/sizeof(string);D++){
      string Dir = Directories[D];
      for(int observed=0;observed<=1;observed++){


         c1 = new TCanvas("c", "c",600,600);
         c1->SetLogy(true);
         framework = new TH1F("Graph","Graph",1,150,1050);
         framework->SetStats(false);
         framework->SetTitle("");
         framework->GetXaxis()->SetTitle("M_{H} [GeV/c^{2}]");
         framework->GetYaxis()->SetTitle("#sigma_{95%} (fb)");
         framework->GetYaxis()->SetTitleOffset(1.40);
         framework->GetYaxis()->SetRangeUser(1.0,100);
         framework->Draw();

         LEG = new TLegend(0.70,0.70,0.95,0.94);
         LEG->SetFillStyle(0);
         LEG->SetBorderSize(0);
         LEG->SetHeader(observed==0?"Expected @95% CL":"Observed @95% CL");

         LEGTH = new TLegend(0.45,0.70,0.70,0.94);
         LEGTH->SetFillStyle(0);
         LEGTH->SetBorderSize(0);
         LEGTH->SetHeader("Theoretical");


         getGraph("SM"                         , 1, 1, 2, LEGTH, NULL, 0, Dir+               "/XSec_LimitSummary")->Draw("C same");
         getGraph("C'=1.0"                     , 2, 1, 2, LEGTH, NULL, 0, Dir+"_cp1.00_brn0.00/XSec_LimitSummary")->Draw("C same");
         getGraph("C'=0.8"                     , 3, 1, 2, LEGTH, NULL, 0, Dir+"_cp0.80_brn0.00/XSec_LimitSummary")->Draw("C same");
         getGraph("C'=0.6"                     , 4, 1, 2, LEGTH, NULL, 0, Dir+"_cp0.60_brn0.00/XSec_LimitSummary")->Draw("C same");
//       getGraph("C'=0.5"                     , 6, 1, 2, LEGTH, NULL, 0, Dir+"_cp0.50_brn0.00/XSec_LimitSummary")->Draw("C same");
         getGraph("C'=0.4"                     , 6, 1, 2, LEGTH, NULL, 0, Dir+"_cp0.40_brn0.00/XSec_LimitSummary")->Draw("C same");
//       getGraph("C'=0.3"                     , 6, 1, 2, LEGTH, NULL, 0, Dir+"_cp0.30_brn0.00/XSec_LimitSummary")->Draw("C same");
         getGraph("C'=0.2"                     , 8, 1, 2, LEGTH, NULL, 0, Dir+"_cp0.20_brn0.00/XSec_LimitSummary")->Draw("C same");
   //      getGraph("C'=0.1"                     , 8, 1, 2, LEGTH, NULL, 0, Dir+"_cp0.10_brn0.00/XSec_LimitSummary")->Draw("C same");

         getGraph("SM"                         , 1, 2, 1, LEG  , NULL, 1+observed, Dir+               "/XSec_LimitSummary")->Draw("C same");
         getGraph("C'=1.0"                     , 2, 2, 1, LEG  , NULL, 1+observed, Dir+"_cp1.00_brn0.00/XSec_LimitSummary")->Draw("C same");
         getGraph("C'=0.8"                     , 3, 2, 1, LEG  , NULL, 1+observed, Dir+"_cp0.80_brn0.00/XSec_LimitSummary")->Draw("C same");
         getGraph("C'=0.6"                     , 4, 2, 1, LEG  , NULL, 1+observed, Dir+"_cp0.60_brn0.00/XSec_LimitSummary")->Draw("C same");
//         getGraph("C'=0.5"                     , 4, 2, 1, LEG  , NULL, 1+observed, Dir+"_cp0.50_brn0.00/XSec_LimitSummary")->Draw("C same");
         getGraph("C'=0.4"                     , 6, 2, 1, LEG  , NULL, 1+observed, Dir+"_cp0.40_brn0.00/XSec_LimitSummary")->Draw("C same");
//         getGraph("C'=0.3"                     , 4, 2, 1, LEG  , NULL, 1+observed, Dir+"_cp0.30_brn0.00/XSec_LimitSummary")->Draw("C same");
         getGraph("C'=0.2"                     , 8, 2, 1, LEG  , NULL, 1+observed, Dir+"_cp0.20_brn0.00/XSec_LimitSummary")->Draw("C same");
   //      getGraph("C'=0.1"                     , 8, 2, 1, LEG  , NULL, 1+observed, Dir+"_cp0.10_brn0.00/XSec_LimitSummary")->Draw("C same");

         LEGTH->Draw("same");
         LEG  ->Draw("same");

         char LumiLabel[1024];
         if(Dir.find("7TeV")!=string::npos)sprintf(LumiLabel,"CMS preliminary,  #sqrt{s}=7 TeV, #int L=%6.1ffb^{-1}",5.035);
         if(Dir.find("8TeV")!=string::npos)sprintf(LumiLabel,"CMS preliminary,  #sqrt{s}=8 TeV, #int L=%6.1ffb^{-1}",19.6);
         if(Dir.find("Comb")!=string::npos)sprintf(LumiLabel,"CMS preliminary,  #sqrt{s}=%.0f TeV #scale[0.5]{#int} L=%6.1ffb^{-1}, #sqrt{s}=%.0f TeV #scale[0.5]{#int} L=%6.1ffb^{-1}",7.0,5.0,8.0,19.7);
         TPaveText *pave = new TPaveText(0.1,0.96,0.94,0.99,"NDC");
         pave->SetBorderSize(0);
         pave->SetFillStyle(0);
         pave->SetTextAlign(32);
         pave->SetTextFont(42);
         pave->AddText(LumiLabel);
         pave->Draw("same");

         //system("mkdir -p LimitPlots");
         if(observed==0){
            c1->SaveAs((Dir+"/XSec_FinalPlot.png").c_str());
            c1->SaveAs((Dir+"/XSec_FinalPlot.pdf").c_str());
            c1->SaveAs((Dir+"/XSec_FinalPlot.C"  ).c_str());
         }else{
            c1->SaveAs((Dir+"/XSec_FinalPlot_Obs.png").c_str());
            c1->SaveAs((Dir+"/XSec_FinalPlot_Obs.pdf").c_str());
            c1->SaveAs((Dir+"/XSec_FinalPlot_Obs.C"  ).c_str());
         }
      }
   }

//      string Directories2[]={"cards_CC7TeV", "cards_SB7TeV", "cards_CC7TeV_GG", "cards_SB7TeV_GG", "cards_CC7TeV_QQ", "cards_SB7TeV_QQ",    "cards_CC8TeV", "cards_SB8TeV", "cards_CC8TeV_GG", "cards_SB8TeV_GG", "cards_CC8TeV_QQ", "cards_SB8TeV_QQ",  "cards_CCComb", "cards_SBComb", "cards_CCComb_GG", "cards_SBComb_GG", "cards_CCComb_QQ", "cards_SBComb_QQ"};
   string Directories2[]={"cards_CC7TeV", "cards_SB7TeV", "cards_CC7TeV_GG", "cards_SB7TeV_GG", "cards_CC7TeV_QQ", "cards_SB7TeV_QQ",    "cards_CC8TeV", "cards_SB8TeV", "cards_CC8TeV_GG", "cards_SB8TeV_GG", "cards_CC8TeV_QQ", "cards_SB8TeV_QQ",  "cards_CCComb", "cards_SBComb"};
   for(unsigned int D=0;D<sizeof(Directories2)/sizeof(string);D++){
      string Dir = Directories2[D];
      TGraph* gMvsCp[7];

      LEG = new TLegend(0.70,0.70,0.95,0.94);
      LEG->SetFillStyle(0);
      LEG->SetBorderSize(0);
      TGraph** gSM=getGraphs("SM"                         , 1, 2, LEG  , NULL, Dir+               "/Stength_LimitSummary");
      TGraph** g10=getGraphs("C'=1.0"                     , 2, 2, LEG  , NULL, Dir+"_cp1.00_brn0.00/Stength_LimitSummary");
      TGraph** g08=getGraphs("C'=0.8"                     , 3, 2, LEG  , NULL, Dir+"_cp0.80_brn0.00/Stength_LimitSummary");
      TGraph** g06=getGraphs("C'=0.6"                     , 4, 2, LEG  , NULL, Dir+"_cp0.60_brn0.00/Stength_LimitSummary");
      TGraph** g05=getGraphs("C'=0.5"                     , 6, 2, NULL , NULL, Dir+"_cp0.50_brn0.00/Stength_LimitSummary");
      TGraph** g04=getGraphs("C'=0.4"                     , 6, 2, LEG  , NULL, Dir+"_cp0.40_brn0.00/Stength_LimitSummary");
      TGraph** g03=getGraphs("C'=0.3"                     , 6, 2, NULL , NULL, Dir+"_cp0.30_brn0.00/Stength_LimitSummary");
      TGraph** g02=getGraphs("C'=0.2"                     , 8, 2, LEG  , NULL, Dir+"_cp0.20_brn0.00/Stength_LimitSummary");
      TGraph** g01=getGraphs("C'=0.1"                     , 8, 2, NULL , NULL, Dir+"_cp0.10_brn0.00/Stength_LimitSummary");

      char LumiLabel[1024];
      if(Dir.find("7TeV")!=string::npos)sprintf(LumiLabel,"CMS preliminary,  #sqrt{s}=7 TeV, #int L=%6.1ffb^{-1}",5.035);
      if(Dir.find("8TeV")!=string::npos)sprintf(LumiLabel,"CMS preliminary,  #sqrt{s}=8 TeV, #int L=%6.1ffb^{-1}",19.6);
      if(Dir.find("Comb")!=string::npos)sprintf(LumiLabel,"CMS preliminary,  #sqrt{s}=%.0f TeV #scale[0.5]{#int} L=%6.1ffb^{-1}, #sqrt{s}=%.0f TeV #scale[0.5]{#int} L=%6.1ffb^{-1}",7.0,5.0,8.0,19.7);
      TPaveText *pave = new TPaveText(0.1,0.96,0.94,0.99,"NDC");
      pave->SetBorderSize(0);
      pave->SetFillStyle(0);
      pave->SetTextAlign(32);
      pave->SetTextFont(42);
      pave->AddText(LumiLabel);
      pave->Draw("same");


      for(int observed=0;observed<=1;observed++){
         c1 = new TCanvas("c", "c",600,600);
         c1->SetLogy(true);
         framework = new TH1F("Graph","Graph",1,150,1050);
         framework->SetStats(false);
         framework->SetTitle("");
         framework->GetXaxis()->SetTitle("M_{H} [GeV/c^{2}]");
         framework->GetYaxis()->SetTitle("#sigma_{95%} / #sigma_{TH}");
         framework->GetYaxis()->SetTitleOffset(1.40);
         framework->GetYaxis()->SetRangeUser(0.1,500);
   //      framework->GetYaxis()->SetRangeUser(0.1,10);
         framework->Draw();


         gSM[1+observed]->SetLineStyle(1);
         g10[1+observed]->SetLineStyle(1);
         g08[1+observed]->SetLineStyle(1);
         g06[1+observed]->SetLineStyle(1);
         g04[1+observed]->SetLineStyle(1);
         g02[1+observed]->SetLineStyle(1);

         gSM[1+observed]->Draw("C same");
         g10[1+observed]->Draw("C same");
         g08[1+observed]->Draw("C same");
         g06[1+observed]->Draw("C same");
         g04[1+observed]->Draw("C same");
         g02[1+observed]->Draw("C same");
         //g01[1+observed]->Draw("C same");

         LEG  ->Draw("same");
         LEG->SetHeader(observed==0?"Expected @95% CL":"Observed @95% CL");


         TLine* SMLine = new TLine(framework->GetXaxis()->GetXmin(),1.0,framework->GetXaxis()->GetXmax(),1.0);
         SMLine->SetLineWidth(2); SMLine->SetLineStyle(2); SMLine->SetLineColor(1);
         SMLine->Draw("same C");

         //system("mkdir -p LimitPlots");
         if(observed==0){
            c1->SaveAs((Dir+"/Stength_FinalPlot.png").c_str());
            c1->SaveAs((Dir+"/Stength_FinalPlot.pdf").c_str());
            c1->SaveAs((Dir+"/Stength_FinalPlot.C"  ).c_str());
         }else{
            c1->SaveAs((Dir+"/Stength_FinalPlot_Obs.png").c_str());
            c1->SaveAs((Dir+"/Stength_FinalPlot_Obs.pdf").c_str());
            c1->SaveAs((Dir+"/Stength_FinalPlot_Obs.C"  ).c_str());
         }
     }


          ///////////////////////////////////////////////
          //Mass Versus Cprime limits
          ///////////////////////////////////////////////

      for(int type=1;type<7;type++){
            if(type==0)continue;
            TGraph* g1dV[] = {g10[type], g08[type], g06[type], g05[type], g04[type], g03[type], g02[type], g01[type]};
            double* Masses = g1dV[0]->GetX();  
            int NMasses = g1dV[0]->GetN();
            double    cp[] = {1.0, 0.8, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1};
           
            gMvsCp[type] = (TGraph*)g1dV[0]->Clone();
 
            for(int Mi=0;Mi<NMasses;Mi++){
               TGraph* g1d = new TGraph( (sizeof(cp)/sizeof(double)) );
               for(unsigned int C=0;C<(sizeof(g1dV)/sizeof(TGraph*));C++){
                  g1d->SetPoint(C, cp[C], g1dV[C]->Eval(Masses[Mi]));
//                  if(Masses[Mi]==400.0)printf("xxx %f --> %f\n",cp[C], g1dV[C]->Eval(Masses[Mi]));
               }

               //find C' value that is excluded
               double cpExcluded = 2.0;  double cpPrev=-1;  double limitPrev=-1;
               for(double cp=1.0; cp>0.0;cp-=0.01){
//                  if(Masses[Mi]==400.0) printf("c=%f --> %f (compared to  %f)\n", cp, g1d->Eval(cp), limitPrev);

                  if(limitPrev!=-1 && limitPrev<=1.0 && g1d->Eval(cp)>=1.0){cpExcluded=cpPrev;break;}
                  limitPrev=g1d->Eval(cp);  cpPrev=cp;
               }
               gMvsCp[type]->SetPoint(Mi, Masses[Mi], pow(cpExcluded,2));
//               gMvsCp[type]->SetPoint(Mi, Masses[Mi], cpExcluded);
//               printf("%i Mass = %f -> cpexcluded = %f\n", type, Masses[Mi], cpExcluded);
            }
      }

         if(true){
            c1 = new TCanvas("c", "c",600,600);
            framework = new TH1F("Graph","Graph",1,150,1050);
            framework->SetStats(false);
            framework->SetTitle("");
            framework->GetXaxis()->SetTitle("M_{H} [GeV/c^{2}]");
            framework->GetYaxis()->SetTitle("C'^{2}_{95%}");
            framework->GetYaxis()->SetTitleOffset(1.40);
            framework->GetYaxis()->SetRangeUser(0.0,1.0);
            framework->Draw();

            pave->Draw("same");

            //expected bands
            TCutG* TGExpLimit1S  = GetErrorBand("1S", gMvsCp[3]->GetN(), gMvsCp[3]->GetX(), gMvsCp[3]->GetY(), gMvsCp[4]->GetY());  
            TCutG* TGExpLimit2S  = GetErrorBand("2S", gMvsCp[3]->GetN(), gMvsCp[3]->GetX(), gMvsCp[5]->GetY(), gMvsCp[6]->GetY());  TGExpLimit2S->SetFillColor(5);
            TGExpLimit2S->Draw("f same");
            TGExpLimit1S->Draw("f same");

            //expected
            gMvsCp[1]->SetLineColor(1);
            gMvsCp[1]->SetLineWidth(1);
            gMvsCp[1]->SetLineStyle(2);
            gMvsCp[1]->Draw("same");

            //observed
            gMvsCp[2]->SetLineColor(1);
            gMvsCp[2]->SetLineWidth(2);
            gMvsCp[2]->SetLineStyle(1);
            gMvsCp[2]->Draw("same");


//for(int i=3;i<7;i++){
//            gMvsCp[i]->SetLineColor(4);
//            gMvsCp[i]->SetLineWidth(1);
//            gMvsCp[i]->SetLineStyle(2);
//            gMvsCp[i]->Draw("C same");
//}

            LEG = new TLegend(0.50,0.20,0.95,0.44);
            LEG->SetFillStyle(0);
            LEG->SetBorderSize(0);
            LEG->SetHeader(NULL);
            LEG->AddEntry(gMvsCp[1],"Expected @95% CL", "L");
            LEG->AddEntry(gMvsCp[2],"Observed @95% CL", "L");
            LEG->Draw();

            c1->SaveAs((Dir+"/Stength_FinalPlot_Cprime.png").c_str());
            c1->SaveAs((Dir+"/Stength_FinalPlot_Cprime.pdf").c_str());
            c1->SaveAs((Dir+"/Stength_FinalPlot_Cprime.C"  ).c_str());
        }

          ///////////////////////////////////////////////
          //Mass Versus Cprime limits
          ///////////////////////////////////////////////

      for(int observed=0;observed<=1;observed++){

         for(int mode=0; mode<=1; mode++){
            //mode=0 --> CPrime versus BRNew
            //mode=1 --> width  versus BRNew
////
            double Masses[] = {200,400,600,800};
            for(int Mi=0;Mi<sizeof(Masses)/sizeof(double);Mi++){
               double Mass = Masses[Mi];
               TGraph* g1dV[] = {g10[1+observed], g08[1+observed], g06[1+observed], g05[1+observed], g04[1+observed], g03[1+observed], g02[1+observed], g01[1+observed]};
               double    cp[] = {1.0, 0.8, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1};
               TGraph*   g1d  = new TGraph  ( (sizeof(g1dV)/sizeof(TGraph*)) );
               for(unsigned int C=0;C<(sizeof(g1dV)/sizeof(TGraph*));C++){
                  g1d->SetPoint(C, cp[C], g1dV[C]->Eval(Mass));
               }

               int I=0;      
//               double   cp2[] = {1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.3, 0.2, 0.1, 0.0};
//               double  brn[] = {0.995, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0};
               double   cp2[] = {1.0, 0.975, 0.95, 0.925, 0.9, 0.875, 0.85, 0.825, 0.8, 0.775, 0.75, 0.725, 0.7, 0.675, 0.65, 0.625, 0.6, 0.575, 0.55, 0.525, 0.5, 0.475, 0.45, 0.425, 0.4, 0.375, 0.35, 0.325, 0.3, 0.275, 0.25, 0.225, 0.2, 0.175, 0.15, 0.125, 0.1, 0.075, 0.05, 0.025, 0.0};
               double  brn[] = {0.995, 0.975, 0.95, 0.925, 0.9, 0.875, 0.85, 0.825, 0.8, 0.775, 0.75, 0.725, 0.7, 0.675, 0.65, 0.625, 0.6, 0.575, 0.55, 0.525, 0.5, 0.475, 0.45, 0.425, 0.4, 0.375, 0.35, 0.325, 0.3, 0.275, 0.25, 0.225, 0.2, 0.175, 0.15, 0.125, 0.1, 0.075, 0.05, 0.025, 0.0};
               TGraph2D* g2d = new TGraph2D( (sizeof(cp2)/sizeof(double)) * (sizeof(brn)/sizeof(double))  );
               for(unsigned int C=0;C<(sizeof( cp2)/sizeof(double));C++){
               for(unsigned int B=0;B<(sizeof(brn)/sizeof(double));B++){
                  double BR = brn[B];
                  double sl = g1d->Eval(sqrt(cp2[C]));

                  //move from br=0 --> br=BR
                  double cp2_true = cp2[C]*(1-BR);
                  double sl_true = sl/(1-BR);
                  if(mode==0){        g2d->SetPoint(I, cp2_true, BR, sl_true);
                  }else if(mode==1){  g2d->SetPoint(I, sqrt(cp2[C]), BR, sl_true);
   //               }else if(mode==1){  g2d->SetPoint(I, cp2[C]*(1-BR), BR, sl_true);
                  }
                  I++;
               }}g2d->Set(I);

               c1 = new TCanvas("c", "c",600,600);
               c1->SetLogz(true);      
               c1->SetRightMargin(0.17);

               framework2d = new TH2F("Graph","Graph",1,mode==0?0.0:0.3,1, 1,0,1);
               framework2d->SetStats(false);
               framework2d->SetTitle("");
               framework2d->GetXaxis()->SetTitle(mode==0?"c'^{2}":"#Gamma/#Gamma_{SM}");
               framework2d->GetYaxis()->SetTitle("BR_{new}");
               framework2d->GetYaxis()->SetTitleOffset(1.40);
               framework2d->GetYaxis()->SetRangeUser(0, 1);
               framework2d->Draw("");
               pave->Draw("same");

               TH2D* h2d = g2d->GetHistogram();
               h2d->SetMaximum(10);
               h2d->SetMinimum(1E-1);
               h2d->GetZaxis()->SetTitle(observed==0?"Expected #sigma_{95%} / #sigma_{TH}":"Observed #sigma_{95%} / #sigma_{TH}");
               h2d->GetZaxis()->SetTitleOffset(1.33);
               h2d->Draw("COLZ same");

               TH1D* h2dLimit = new TH1D("ExcludedArea", "ExcludedArea", h2d->GetNbinsX(), 0.0, 1.0);  
               for(int x=0;x<=h2d->GetNbinsX();x++){
               double limit = -1;
               for(int y=0;y<=h2d->GetNbinsY()+1;y++){
                     double bin = h2d->GetBinContent(x,y);
                     if(x==15)printf("Dir=%s Mass=%f: Mode=%i cprime2 = %f  brnew=%f  limit=%f\n", Dir.c_str(), Mass, mode, h2d->GetXaxis()->GetBinCenter(x), h2d->GetYaxis()->GetBinCenter(y), bin );
                     if(mode==0 && (bin>=1 || h2d->GetYaxis()->GetBinCenter(y)>=1-h2d->GetXaxis()->GetBinCenter(x))){limit = std::max(0.0, h2d->GetYaxis()->GetBinLowEdge(y) ); break;}
                     if(mode==1 &&  bin<=1 && y<h2d->GetNbinsY()){limit = std::max(0.0, h2d->GetYaxis()->GetBinUpEdge(y) );}
                  }
                  h2dLimit->SetBinContent(x,limit);
               } 
               h2dLimit->SetLineColor(1);
               h2dLimit->SetLineWidth(1);
               h2dLimit->SetFillStyle(3654);
               h2dLimit->SetFillColor(1);
               h2dLimit->Draw("HIST same");

               
               if(mode==0){
                  TLine* W50 = new TLine(0.0, 1.0, 1.0, 0.8);
                  W50->SetLineWidth(1); W50->SetLineStyle(3); W50->SetLineColor(1);    W50->Draw("same C");

                  TLine* W10 = new TLine(0.0, 1.00, 1.0, 0.0);
                  W10->SetLineWidth(1); W10->SetLineStyle(3); W10->SetLineColor(1);    W10->Draw("same C");

                  TLine* W05 = new TLine(0.0, 1.0, 0.5, 0.0);
                  W05->SetLineWidth(1); W05->SetLineStyle(3); W05->SetLineColor(1);    W05->Draw("same C");

                  TLine* W01 = new TLine(0.0, 1.0, 0.1, 0.0);
                  W01->SetLineWidth(1); W01->SetLineStyle(3); W01->SetLineColor(1);    W01->Draw("same C");
               }

               //add marker on the plots
               for(unsigned int C=0;C<(sizeof( cp2)/sizeof(double));C++){
               for(unsigned int B=0;B<(sizeof(brn)/sizeof(double));B++){
                  double BR = brn[B];
                  double sl = g1d->Eval(sqrt(cp2[C]));

                  //move from br=0 --> br=BR
                  double cp2_true = cp2[C]*(1-BR);
                  double sl_true = sl/(1-BR);
                  //TMarker* m = new TMarker(mode==0?cp2_true:sqrt(cp2[C]), BR, 20); m->SetMarkerSize(1.0); m->SetMarkerColor(1);      m->Draw("same");
               }}



               char massStr[512]; sprintf(massStr, "%04.0f", Mass);
               if(mode>0)sprintf(massStr, "%s_Width", massStr);
               if(observed!=0)sprintf(massStr, "%s_Obs", massStr);
               c1->SaveAs((Dir+"/Stength_FinalPlot2D_"+massStr+".png").c_str());
               c1->SaveAs((Dir+"/Stength_FinalPlot2D_"+massStr+".pdf").c_str());
               c1->SaveAs((Dir+"/Stength_FinalPlot2D_"+massStr+".C").c_str());
            }
////
         }
      }
   }
}
Example #12
0
void coupling_measurement(TString sel="prova", bool sideband=true, float min=0, float max=2)
{	
  if(sel=="prova") return;
	
  gROOT->Reset();
  gStyle->SetCanvasColor(0);
  gStyle->SetFrameBorderMode(0);
  gStyle->SetMarkerStyle(22);
  gStyle->SetOptStat(0);
	
  TCanvas *c1 = new TCanvas("coupling","coupling",30,30,800,600);
  c1->SetGrid();
	
  // draw a frame to define the range
  TH1F *hr = c1->DrawFrame(-5,0,7,65);
  //hr->SetXTitle("p_t");
  hr->GetYaxis()->SetTitleOffset(1.0);
  hr->SetYTitle("MET cut");
  hr->SetXTitle("#sigma on rV measurement");
  hr->GetYaxis()->SetTitleSize(0.045);
  hr->GetXaxis()->SetTitleSize(0.045);
  hr->GetYaxis()->SetLabelSize(0.045);
  hr->GetXaxis()->SetLabelSize(0.040);
  hr->GetYaxis()->SetNdivisions(015);
  const Int_t n = 20;
	
  //LOW MET CUT
  Double_t y_centr[n] = {-1.0,-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9};
  Double_t y_erlow[n] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  Double_t y_erhig[n] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  Double_t x_centr[n] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
	
  //                           -1      -0.9    -0.8    -0.7    -0.6   -0.5     -0.4      -0.3    -0.2    -0.1    0.0     0.1      0.2    0.3     0.4     0.5     0.6     0.7     0.8  
  if(!sideband){  
    //MC BKG
    //VHlep1
    if(sel=="VHlep1") {
      Double_t x_erlow[n] = {0.865345,0.844741,0.826624,0.814634,0.804645,0.802949,0.804242,0.809796,201,201,201,201,201,201,201,201,201,201,201,201};
      Double_t x_erhig[n] = {1.57891,1.56241,1.54981,1.54917,1.54998,1.57084,1.59965,1.64251,1.19334,1.22874,1.26373,1.3193,1.39003,1.47625,1.59185,1.75099,1.98393,2.33453,2.90948,4.68023};
    }
    //VHlep2
    if(sel=="VHlep2") {
      Double_t x_erlow[n] = {2.56557,2.38531,2.22304,2.09321,2.00704,1.98628,1.981,1.98794,2.01623,2.05354,2.08783,201,201,201,201,201,201,201,201,201};
      Double_t x_erhig[n] = {3.43476,3.29173,3.16909,3.08308,3.05138,3.11495,3.20622,3.32696,3.50211,3.72148,3.97364,2.97657,3.2132,3.55633,4.08556,4.90006,6.3567,8.29943,30.5657,128.278};
    }
    //VHmetT
    if(sel=="VHmetT") {
      Double_t x_erlow[n] = {2.8874,2.56138,2.26013,2.01522,1.85125,1.71143,1.59633,1.4957,1.41358,1.35894,1.30951,1.2762,1.23767,1.21275,1.19742,1.20805,1.23355,201,201,201};
      Double_t x_erhig[n] = {3.18255,2.91988,2.67321,2.47263,2.34945,2.24189,2.15582,2.08163,2.02718,2.00829,1.99598,2.00913,2.0161,2.05034,2.11062,2.24004,2.43898,1.94345,2.26239,3.36364};
    }
    //ttHhad
    if(sel=="ttHhad") {
      Double_t x_erlow[n] = {3.84643,3.23125,2.96495,2.82116,2.70509,2.596,2.49624,2.40113,2.31831,2.28309,2.19436,2.09837,2.00986,201,201,201,201,201,201,201};
      Double_t x_erhig[n] = {4.58439,4.0736,3.86196,3.75742,3.68325,3.62087,3.57653,3.54561,3.54225,3.62824,3.651,3.68787,3.77815,2.76994,2.82907,2.93495,3.24079,3.61888,4.50953,7.14343};
    }
    //VHhadB
    if(sel=="VHhadB") {
      Double_t x_erlow[n] = {5.35001,5.09173,4.84396,4.64062,4.43147,4.20828,3.9993,3.79365,3.625,3.48895,3.39049,3.24834,3.17256,3.11595,2.99101,2.80766,2.85888,3.11851,201,201};
      Double_t x_erhig[n] = {5.66319,5.45352,5.25341,5.09811,4.93559,4.75593,4.5908,4.42958,4.31223,4.23727,4.21498,4.15067,4.18357,4.26287,4.27935,4.24169,4.62244,5.53665,5.1091,22.3609};
    }
    //VHhad0
    if(sel=="VHhad0") {
      Double_t x_erlow[n] = {2.67097,2.58138,2.49218,2.4054,2.31249,2.21792,2.12431,2.07219,1.98572,1.8808,1.78948,1.70381,1.66196,1.58922,1.55664,1.53952,1.58572,201,201,201};
      Double_t x_erhig[n] = {3.29995,3.22518,3.1511,3.08043,3.00298,2.92372,2.84768,2.82851,2.7679,2.68509,2.62409,2.57511,2.59963,2.58517,2.65137,2.77153,3.07152,2.4114,3.14665,8.34286};
    }
  }
	
  if(sideband){
    //SIDEBAND
    //VHlep1
    if(sel=="VHlep1") {
      Double_t x_erlow[n] = {1.21869,1.15681,1.10054,1.05793,1.02142,1.00191,0.988866,0.983631,0.979968,0.983412,201,201,201,201,201,201,201,201,201,201};
      Double_t x_erhig[n] = {1.91116,1.85891,1.81291,1.78525,1.76234,1.7673,1.78322,1.81641,1.85603,1.91849,1.40949,1.46047,1.52805,1.61182,1.72804,1.89225,2.13811,2.51264,3.12966,5.10852};
    }
    //VHlep2
    if(sel=="VHlep2") {
      Double_t x_erlow[n] = {3.11548,2.87988,2.66834,2.49813,2.38352,2.35112,2.33867,2.34185,2.37193,2.41362,2.45208,2.4729,201,201,201,201,201,201,201,201};
      Double_t x_erhig[n] = {3.90609,3.71908,3.55668,3.43838,3.38426,3.43987,3.52696,3.64649,3.82548,4.05123,4.30982,4.58501,3.57694,3.9542,4.54303,5.45666,7.10646,9.3052,32.0946,133.269};
    }
    //VHmetT
    if(sel=="VHmetT") {
      Double_t x_erlow[n] = {3.03829,2.69084,2.36918,2.10777,1.93241,1.78255,1.65984,1.55225,1.4643,1.40533,1.35191,1.31545,1.27356,1.24594,1.22833,1.23785,1.26274,201,201,201};
      Double_t x_erhig[n] = {3.30609,3.02607,2.76347,2.54997,2.4179,2.30279,2.21046,2.13076,2.07169,2.0494,2.03395,2.04464,2.04893,2.08101,2.13949,2.26815,2.46687,1.97301,2.29484,3.4136};
    }
    //ttHhad
    if(sel=="ttHhad") {
      Double_t x_erlow[n] = {3.32048,2.81115,2.59078,2.47157,2.376,2.2863,2.20459,2.12683,2.0596,2.03317,1.96088,1.8825,201,201,201,201,201,201,201,201};
      Double_t x_erhig[n] = {4.14027,3.71348,3.53826,3.45367,3.39573,3.3487,3.31856,3.3013,3.31007,3.40212,3.43787,3.48884,2.54189,2.59388,2.66517,2.78245,3.08706,3.46504,4.32835,6.84114};
    }
    //VHhadB
    if(sel=="VHhadB") {
      Double_t x_erlow[n] = {3.89188,3.71798,3.55106,3.41527,3.27502,3.12374,2.9822,2.84268,2.72989,2.64161,2.58054,2.48755,2.44351,2.41267,2.33155,2.20676,2.25397,201,201,201};
      Double_t x_erhig[n] = {4.46581,4.3219,4.18483,4.08197,3.9728,3.84949,3.73721,3.62792,3.55392,3.5148,3.5197,3.49253,3.54717,3.64371,3.69268,3.7009,4.07076,3.44509,4.33376,20.209};
    }
    //VHhad0
    if(sel=="VHhad0") {
      Double_t x_erlow[n] = {2.09522,2.0317,1.96848,1.90712,1.84121,1.77369,1.70736,1.67273,1.61226,1.53798,1.47428,1.41515,1.38975,1.34111,1.32351,1.31815,201,201,201,201};
      Double_t x_erhig[n] = {2.80897,2.75498,2.70162,2.6512,2.59535,2.53825,2.48422,2.47853,2.43882,2.38101,2.34246,2.31508,2.35232,2.35753,2.43535,2.56426,1.98796,2.19105,2.85189,7.29571};
    }
  }
	
  TGraphAsymmErrors *h1 = new TGraphAsymmErrors(n,x_centr,y_centr,x_erlow,x_erhig,y_erlow,y_erhig);
	
  h1->SetMarkerColor(2);
  h1->SetMarkerStyle(20);
  h1->SetMarkerSize(1.0);
  h1->SetFillColor(2);
  h1->SetLineColor(1);
  h1->SetLineWidth(2);
  h1->Draw("P");
  hr->GetXaxis()->SetTitleOffset(0.5);
  hr->GetXaxis()->SetNdivisions(000);
	
  TH1D *DEN  = new TH1D("","",20,-1-0.05,1-0.05);
  for(int i=0; i<18; i++){
    S=(x_erlow[i]+x_erhig[i])/2;
    DEN->SetBinContent(i+1,S);
    DEN->SetBinError(i+1,0.001);
  }
  DEN->SetMarkerColor(2);
  DEN->SetMarkerStyle(20);
  DEN->SetMarkerSize(1.0);
  DEN->SetFillColor(2);
  DEN->SetLineColor(1);
  DEN->SetLineWidth(2);
  DEN->GetYaxis()->SetRangeUser(min,max);
  DEN->GetXaxis()->SetRangeUser(-1,1);
  DEN->SetXTitle("diphoton MVA cut");
  DEN->SetYTitle("#sigma on rV measurement");
  DEN->GetYaxis()->SetTitleOffset(1.1);
  DEN->GetYaxis()->SetTitleSize(0.045);
  DEN->GetXaxis()->SetTitleSize(0.045);
  DEN->GetYaxis()->SetLabelSize(0.045);
  DEN->GetXaxis()->SetLabelSize(0.025);
  DEN->GetXaxis()->SetNdivisions(0030);
  DEN->GetYaxis()->SetNdivisions(515);
  DEN->Draw("E");
	
  c1->SaveAs("coupling_"+sel+".png");
}
void makeRisetimeDistributionT9(string filename, string plotname, string plotTitle,
			      double ampCutOnMCP, double ampCutOnLYSO, double ampCutOnTrigger,
			    double beamXMin, double beamXMax, double beamYMin, double beamYMax,
			    int nbins, double xmin, double xmax, double fitmin, double fitmax) {


  TFile *inputfile = TFile::Open(filename.c_str(),"READ");
  
  TTree *tree = (TTree*)inputfile->Get("t1065");

  // get the variables from the ntuple
  float amp[36];
  float risetime[36];
  float gauspeak[36];
  float linearTime30[36];
  float beamX;
  float beamY;

  tree->SetBranchStatus("*",0);
  tree->SetBranchStatus("gauspeak",1);
  tree->SetBranchStatus("amp",1);
  tree->SetBranchStatus("risetime",1);
  tree->SetBranchStatus("linearTime30",1);
  tree->SetBranchStatus("TDCx",1);
  tree->SetBranchStatus("TDCy",1);
  tree->SetBranchAddress("gauspeak",gauspeak);
  tree->SetBranchAddress("amp",amp);
  tree->SetBranchAddress("risetime",risetime);
  tree->SetBranchAddress("linearTime30",linearTime30);
  tree->SetBranchAddress("TDCx",&beamX);
  tree->SetBranchAddress("TDCy",&beamY);

  //create histograms
  TH1F *histRisetime;
  histRisetime = new TH1F("histRisetime","; Integrated Charge [pC];Number of Events", nbins, xmin, xmax);

  
  //read all entries and fill the histograms
  Long64_t nentries = tree->GetEntries();

  std::cout<<"Number of events in Sample: "<<nentries<<std::endl;  
  for (Long64_t iEntry=0;iEntry<nentries;iEntry++) {
    if (iEntry %1000 == 0) 
      cout << "Processing Event " << iEntry << "\n";
    tree->GetEntry(iEntry);    
    // cout << "here1\n";
    float MCPTimeGauss = gauspeak[0];
    float CdTeTime = linearTime30[1];
    float MCPAmp = amp[0];
    float LYSOAmp = amp[2];
    float TriggerAmp = amp[3];
    float CherenkovAmp = amp[7];
    float CdTeAmp = amp[1]*(1.0/63.0957);
    float CdTeRisetime = risetime[1];
    // cout << "here2\n";
       
    //use MCP amplitude cut for electron ID
    //cout << "test: " << MCPAmp << " " << siliconIntegral << "\n";
    if( !(MCPAmp > ampCutOnMCP)) continue;
    if( !(TriggerAmp > ampCutOnTrigger)) continue;
    if( !(LYSOAmp > ampCutOnLYSO)) continue;
    if(!(beamX > beamXMin && beamX < beamXMax)) continue;
    if(!(beamY > beamYMin && beamY < beamYMax)) continue;
     // cout << "here3\n";

    //don't fill overflow bins
    //if (1000* siliconIntegral * attenuationFactor / amplificationFactor > xmax) continue;
    
    histRisetime->Fill( CdTeRisetime );

    //cout << CdTeRisetime << " " << beamX << " " << beamY << " " << CdTeAmp << "\n";

    //cout << 1000* amp[21] << " : " << amplificationFactor << " : " << siliconIntegral * attenuationFactor / amplificationFactor << "\n";
 
  }


  TCanvas * c = 0;


  //Energy plot
  c = new TCanvas("c","c",600,600);  
  c->SetRightMargin(0.05);
  c->SetLeftMargin(0.17);
  histRisetime->SetAxisRange(xmin,xmax,"X");
  histRisetime->SetTitle("");
  histRisetime->GetXaxis()->SetTitle("Risetime [ns]");
  histRisetime->GetXaxis()->SetTitleSize(0.045);
  histRisetime->GetXaxis()->SetLabelSize(0.045);
  histRisetime->GetYaxis()->SetTitle("Number of Events");
  histRisetime->GetYaxis()->SetTitleOffset(1.3);
  histRisetime->GetYaxis()->SetTitleSize(0.05);
  histRisetime->GetYaxis()->SetLabelSize(0.045);
  histRisetime->GetYaxis()->SetLabelOffset(0.015);
  histRisetime->GetYaxis()->SetTitleOffset(1.7);
  histRisetime->SetMaximum(1.2*histRisetime->GetMaximum());
  histRisetime->Draw();
  histRisetime->SetStats(0);
  histRisetime->Fit("gaus","","",fitmin,fitmax);
  TVirtualFitter * fitter = TVirtualFitter::GetFitter();
  
  TLatex *tex = new TLatex();
  tex->SetNDC();
  tex->SetTextSize(0.050);
  tex->SetTextFont(42);
  tex->SetTextColor(kBlack);
  tex->DrawLatex(0.45, 0.85, Form("Mean = %.2f %s",fitter->GetParameter(1),"ns"));
  tex->DrawLatex(0.45, 0.80, Form("#sigma = %.2f %s",fitter->GetParameter(2),"ns"));

  tex->DrawLatex(0.18, 0.93, Form("%s", plotTitle.c_str()));

  c->SaveAs( Form("%s_risetime.gif", plotname.c_str()) );
  c->SaveAs( Form("%s_risetime.pdf", plotname.c_str()) );
 

}
////////////////////////////////////////////////////////////////////////////////////////
// Draw and save the canvas
// This bit shouldn't need to be updated except the region and channel labels
// As of Jan 10,2013 - the known issues are:
// ++ Error bands don't show correctly
// ++ Data histogram needs to be converted to TGraphAsymmErrors and 
//    plotted w/ poisson errors
// ++ Ratio plot needs to divide the Data TGraphAsymmErrors and
//    TGraphAsymmErrors for the total SM (by turning off the errors since they are
//    shown explicitly)
////////////////////////////////////////////////////////////////////////////////////////
void PlotUnifier(
                  TH1F* histos[9],                   // Array of pointers to histograms
                  TGraphAsymmErrors* smErrorBand,    // Error band for the top pad
                  TGraphAsymmErrors* ratioErrorBand  // Error band for the bottom pad
                )
{
  ////////////////////////////////////////////////////////////////////////////////////////
  // Set Histogram Properties, build the stack and make the ratio plot
  histos[0]->SetMarkerStyle(20)     ; histos[0]->SetMarkerSize(1.2); 
  histos[1]->SetFillColor(kOrange-2); histos[4]->SetLineWidth (2);
  histos[2]->SetFillColor(kAzure-9 ); histos[1]->SetLineWidth (2);
  histos[3]->SetFillColor(kSpring+1); histos[2]->SetLineWidth (2);
  histos[4]->SetFillColor(kAzure+4 ); histos[3]->SetLineWidth (2);
  histos[5]->SetFillColor(kGray    ); histos[5]->SetLineWidth (2);
  histos[6]->SetFillColor(kYellow-9); histos[6]->SetLineWidth (2);
  histos[7]->SetLineColor(kMagenta ); histos[7]->SetLineWidth (3); histos[7]->SetLineStyle(2);
  histos[8]->SetLineColor(kGreen+1 ); histos[8]->SetLineWidth (3); histos[8]->SetLineStyle(2);
  
  ////////////////////////////////////////////////////////////////////////////////////////
  // Here comes the stack 
  THStack* sm = new THStack("sm","sm");
  sm->Add(histos[6]);
  sm->Add(histos[5]);
  sm->Add(histos[4]);
  sm->Add(histos[3]);
  sm->Add(histos[2]);
  sm->Add(histos[1]);

  ////////////////////////////////////////////////////////////////////////////////////////
  // Define the legend and fill in the stack order
  TLegend* legendA        = new TLegend(0.49,0.65,0.74,0.85);
  TLegend* legendB        = new TLegend(0.62,0.65,0.87,0.85);
  legendA->SetTextFont(42);    
  legendB->SetTextFont(42);    
  legendA->SetTextSize(0.03);
  legendB->SetTextSize(0.03);
  legendA->SetBorderSize(0);
  legendB->SetBorderSize(0);
  legendA->SetFillColor(0);
  legendB->SetFillColor(0);
  legendA->AddEntry(histos[0],"Data"               ,"p");
  legendA->AddEntry(histos[1],"Z+jets"             ,"f");
  legendA->AddEntry(histos[2],"WW"                 ,"f");
  legendA->AddEntry(histos[3],"t#bar{t}+Wt"        ,"f");
  legendA->AddEntry(histos[4],"ZV"                 ,"f");
  legendB->AddEntry(histos[5],"Non-prompt leptons" ,"f");
  legendB->AddEntry(histos[6],"Higgs"              ,"f");
  TH1F* histoError = new TH1F("histoError"         ,"histoError",1,0,1);
  histoError->SetFillStyle(3004);
  histoError->SetFillColor(kBlack);
  legendB->AddEntry(histoError,"Bkg. Uncert."      ,"f");
  legendB->AddEntry(histos[7],"Signal 1"           ,"l");
  legendB->AddEntry(histos[8],"Signal 2"           ,"l");

  ////////////////////////////////////////////////////////////////////////////////////////
  // Ratio plot 
  TH1F* ratio      = (TH1F*) histos[0]->Clone(); ratio->Reset(); 
  TH1F* stackHisto = (TH1F*) sm->GetStack()->Last();
  ratio->Divide(histos[0],stackHisto);
  ratio->SetMarkerSize(1.2);
  ratio->SetMarkerStyle(20);
  ratio->SetLineColor(kBlack);
  ratio->SetLineWidth(2);

  ratio->GetXaxis()->SetTitle("Observable");
  ratio->GetYaxis()->SetTitle("Data/SM");
  ratio->GetXaxis()->SetLabelSize(0.13);
  ratio->GetXaxis()->SetLabelOffset(0.02);
  ratio->GetXaxis()->SetTitleSize(0.14);
  ratio->GetXaxis()->SetTitleOffset(1.2);

  ratio->GetYaxis()->SetRangeUser(0,2);
  ratio->GetYaxis()->SetLabelSize(0.13);
  ratio->GetYaxis()->SetLabelOffset(0.0125);
  ratio->GetYaxis()->SetTitleSize(0.14);
  ratio->GetYaxis()->SetTitleOffset(0.5);
  ratio->GetYaxis()->SetNdivisions(5);

  ////////////////////////////////////////////////////////////////////////////////////////
  // Error bands
  smErrorBand->SetMarkerSize(0); 
  smErrorBand->SetFillStyle(3004);
  smErrorBand->SetFillColor(kBlack);
  ratioErrorBand->SetMarkerSize(0); 
  ratioErrorBand->SetFillStyle(3004);
  ratioErrorBand->SetFillColor(kBlack);
 
  ////////////////////////////////////////////////////////////////////////////////////////
  // Draw and save the canvas
  TCanvas* canvas = new TCanvas("canvas","canvas",500,500);
  TPad*    topPad = new TPad("pTop","pTop",0,0.2,1,1);
  TPad*    botPad = new TPad("pBot","pBot",0,0.0,1,0.3);
  topPad->Draw();
  botPad->Draw();

  ////////////////////////////////////////////////////////////////////////////////////////
  // Data is special since I use it to draw the axis labels etc.
  histos[0]->GetXaxis()->SetTitle("Observable"); 
  histos[0]->GetYaxis()->SetTitle("Events / Bin"); 
  histos[0]->GetXaxis()->SetLabelOffset(1.2); 
  histos[0]->GetXaxis()->SetLabelSize(0.03);
  histos[0]->GetYaxis()->SetRangeUser(1.e-2,1.e5);
  histos[0]->GetYaxis()->SetTitleSize(0.055);
  histos[0]->GetYaxis()->SetTitleOffset(1.28);
  histos[0]->GetYaxis()->SetLabelSize(0.05);
  histos[0]->GetYaxis()->SetLabelOffset(0.01);

  ////////////////////////////////////////////////////////////////////////////////////////
  // Top Pad
  topPad      ->cd();
  topPad      ->SetBottomMargin(0.15);
  histos[0]   ->Draw("p && e && x0");
  sm          ->Draw("same && hists");
  smErrorBand ->Draw("same && E2");
  histos[0]   ->Draw("same && p && e && x0");
  histos[7]   ->Draw("same && hist");
  histos[8]   ->Draw("same && hist");
  legendA     ->Draw();
  legendB     ->Draw();
  gPad        ->RedrawAxis();
  gPad        ->SetLogy(1);

  ////////////////////////////////////////////////////////////////////////////////////////
  // Decoration
  char annoyingLabel1[100] = "#bf{#it{ATLAS}}, #sqrt{s} = 8 TeV, 20.3 fb^{-1}";
  char annoyingLabel2[100] = "SF/DF channel"; 
  char annoyingLabel3[100] = "- Top CR for SR-#scale[0.9]{m_{T2}} and SR-WWb/c";
  myText(0.53,0.880,kBlack,annoyingLabel1);
  myText(0.17,0.965,kBlack,annoyingLabel2);
  myText(0.37,0.965,kBlack,annoyingLabel3);

  ////////////////////////////////////////////////////////////////////////////////////////
  // Bottom Pad
  botPad ->cd();
  botPad ->SetBottomMargin(0.4);
  
  ////////////////////////////////////////////////////////////////////////////////////////
  // 1 Line
  TLine* line = new TLine(histos[0]->GetXaxis()->GetXmin(),1,histos[0]->GetXaxis()->GetXmax(),1);
  line   ->SetLineColor(kRed);
  line   ->SetLineStyle(7);

  ////////////////////////////////////////////////////////////////////////////////////////
  // Draw
  ratio          ->Draw("p && e && x0");
  ratioErrorBand ->Draw("same && E2");
  line           ->Draw("same");
  ratio          ->Draw("same && p && e && x0");
  gPad           ->SetGridy(1);

  ////////////////////////////////////////////////////////////////////////////////////////
  // Save
  canvas ->SaveAs("Test_v3.eps");

} 
Example #15
0
void plotPPBalanceAll(){

  bool isPF = true;

  TString data_tag;
  TString mc_tag;
  TString jetfinder, jetfinder_tag;

  if(!isPF){
    data_tag = "hdata_ak5calo_DijetBalance";
    mc_tag = "hmc_ak5calo_DijetBalance_histonly";
    jetfinder_tag = "calo";
  }else{
    data_tag = "hdata_ak5pf_DijetBalance";
    mc_tag = "hmc_ak5pf_DijetBalance_histonly";
    jetfinder_tag ="pf";
  }

  TFile *fDATA = new TFile(Form("./%s.root",data_tag.Data()));
  TFile *fMC = new TFile(Form("./%s.root",mc_tag.Data()));

  TH1F *hDijetBal_data = (TH1F*) fDATA->Get("hDataDijetBalance");
  TH1F *hDijetBal_mc = (TH1F*) fMC->Get("hQCDDijetBalance");


  // normalization should be matched with what's in ANA
  hDijetBal_data->Scale(1./hDijetBal_data->Integral());
  hDijetBal_data->Rebin(2);

  hDijetBal_mc->Scale(1./hDijetBal_mc->Integral());
  hDijetBal_mc->Rebin(2);

  cout<<"Bin Width = "<<hDijetBal_data->GetBinWidth(1)<<endl;


  // canvas setting ---
  TCanvas *c1 = new TCanvas("c1","",560,620);

  // dum styling ----
  TH1F *hDum = new TH1F("hDum","",10,0,1.0);
  hDum->SetLineColor(kBlue);
  hDum->SetFillColor(kAzure-8);
  hDum->SetFillStyle(3005);

  hDum->SetStats(0);
  hDum->SetXTitle("A_{J} = (p_{T}^{j1}-p_{T}^{j2})/(p_{T}^{j1}+p_{T}^{j2})");
  hDum->SetYTitle("Event Fraction");

  hDum->GetXaxis()->SetLabelSize(30);
  hDum->GetXaxis()->SetLabelFont(43);
  hDum->GetXaxis()->SetTitleSize(30);
  hDum->GetXaxis()->SetTitleFont(43);
  hDum->GetXaxis()->SetTitleOffset(1.4);
  hDum->GetXaxis()->CenterTitle();

  hDum->GetXaxis()->SetNdivisions(905,true);
  
  hDum->GetYaxis()->SetLabelSize(30);
  hDum->GetYaxis()->SetLabelFont(43);
  hDum->GetYaxis()->SetTitleSize(30);
  hDum->GetYaxis()->SetTitleFont(43);
  hDum->GetYaxis()->SetTitleOffset(1.8);
  hDum->GetYaxis()->CenterTitle();

  hDum->SetAxisRange(0,0.25,"Y");


  // data, mc styling
  hDijetBal_mc->SetLineColor(kBlue);
  hDijetBal_mc->SetFillColor(kAzure-8);
  hDijetBal_mc->SetFillStyle(3352);
// 3352
  hDum->Draw("hist");
  
  hDijetBal_mc->SetMarkerSize(2.0);
  hDijetBal_mc->Draw("histsame");
  hDijetBal_data->SetMarkerSize(2.0);
  hDijetBal_data->Draw("pzsame");


  // Legend
  TLegend *t3=new TLegend(0.53,0.57,0.91,0.82);
  //t3->SetHeader("ant-k_{T} (R=0.5) CaloJets");
  t3->AddEntry(hDijetBal_data,"p + p  #sqrt{s}=7.0 TeV","pl");
  t3->AddEntry(hDijetBal_mc,"PYTHIA","lf");
  t3->SetFillColor(0);
  t3->SetBorderSize(0);
  t3->SetFillStyle(0);
  t3->SetTextFont(63);
  t3->SetTextSize(20);
  t3->Draw();


  // other labeling
  TLatex *cms = new TLatex(0.20,0.23,"CMS");
  cms->SetTextFont(63);
  cms->SetTextSize(20);
  cms->Draw();

  TLatex *lumi = new TLatex(0.35,0.23,"#intL dt = 35.1 pb^{-1}");
  lumi->SetTextFont(63);
  lumi->SetTextSize(18);
  lumi->Draw();

  
  TLatex *jetf;
  if(!isPF) jetf = new TLatex(0.46,0.21,"anti-k_{T} (R=0.5) CaloJets");
  else jetf = new TLatex(0.46,0.21,"anti-k_{T} (R=0.5) PFJets");
  jetf->SetTextFont(63);
  jetf->SetTextSize(20);
  jetf->Draw();

  c1->Print(Form("./fig/%s_%s_v1.gif",data_tag.Data(),jetfinder_tag.Data()));
  c1->Print(Form("./fig/%s_%s_v1.pdf",data_tag.Data(),jetfinder_tag.Data()));
  c1->Print(Form("./fig/%s_%s_v1.eps",data_tag.Data(),jetfinder_tag.Data()));
}
Example #16
0
        void Draw(TCanvas *c1, const int &rebin=1, const bool &showErr=true) {

            gStyle->SetOptStat(0);
            c1->cd();
            c1->Clear();

            TPad *pad1;
            pad1 = new TPad("pad1","pad1",0,1-0.614609572,1,1);
            pad1->SetTopMargin(0.0983606557);
            pad1->SetBottomMargin(0.025);
            pad1->Draw();
            pad1->cd();

            RebinHists(rebin);
            THStack *hstack = GetStack(c1->GetLogy());
            TH1F *signal = GetSignalHist();
            TH1F *data   = GetDataHist();

            if(c1->GetLogy()) gPad->SetLogy();
            hstack->GetHistogram()->SetLabelSize(0.00,"X");
            hstack->GetHistogram()->SetLabelSize(0.06,"Y");
            hstack->GetHistogram()->SetTitleSize(0.06,"XY");
            hstack->Draw("hist");
            if(signal && ! _stackSignal) signal->Draw("hist,same");
            if(data)     data->Draw("ep,same");
            DrawLabels();
            pad1->GetFrame()->DrawClone();


            TH1F *summed = GetSummedMCHist();

            TH1F *rdat = (TH1F*)data->Clone("rdat");   
            if(gROOT->FindObject("rref")) gROOT->FindObject("rref")->Delete();
            TH1F *rref = new TH1F("rref","rref",
                summed->GetNbinsX(),
                summed->GetBinLowEdge(1),
                summed->GetBinLowEdge(summed->GetNbinsX()+1)
            );
            for (int i = 1, n = rref->GetNbinsX(); i <= n+1; ++i) {
                rref->SetBinContent(i,summed->GetBinContent(i));
                rref->SetBinError(i,summed->GetBinError(i));
            }
            rref->SetTitle("");
            rref->SetLineWidth(0);
            rref->SetFillColor(kGray+1);
            rref->SetFillStyle(1001);
            double absmax = 0;
            for (int i = 0, n = rdat->GetNbinsX(); i <= n+1; ++i) {
                double scale = rref->GetBinContent(i);
                if (scale == 0) {
                    rdat->SetBinContent(i, 0);
                    rref->SetBinContent(i, 10000);
                    rdat->SetBinError(i, 0);
                    rref->SetBinError(i, 0);
                } else {
                    rdat->SetBinContent(i, rdat->GetBinContent(i)/scale);
                    rref->SetBinContent(i, rref->GetBinContent(i)/scale);
                    rdat->SetBinError(i, rdat->GetBinError(i)/scale);
                    rref->SetBinError(i, rref->GetBinError(i)/scale);
                    double mymax = TMath::Max(1.2*fabs(rdat->GetBinContent(i)-1)+1.4*rdat->GetBinError(i), 2.0*rref->GetBinError(i));
                    absmax = TMath::Max(mymax, absmax);
                }
            }

            c1->cd();
            TPad *pad2 = new TPad("pad2","pad2",0,0,1,1-0.614609572);
            pad2->SetTopMargin(0.0261437908);
            pad2->SetBottomMargin(0.392156863);
            pad2->Draw();
            pad2->cd();

            TLine *line = new TLine(rref->GetXaxis()->GetXmin(), 1.0, rref->GetXaxis()->GetXmax(), 1.0);
            line->SetLineColor(kBlack);
            line->SetLineWidth(1);
            line->SetLineStyle(1);

            if(showErr) {
                rref->GetYaxis()->SetRangeUser(TMath::Max(-1.,1.-absmax), TMath::Min(3.,absmax+1.));
                AxisFonts(rref->GetXaxis(), "x", hstack->GetXaxis()->GetTitle());
                rref->GetYaxis()->SetTitle("data/mc");
                rref->GetYaxis()->SetLabelSize(0.10);
                rref->GetYaxis()->SetTitleSize(0.10);
                rref->GetYaxis()->SetTitleOffset(0.85);
                rref->GetXaxis()->SetLabelSize(0.10);
                rref->GetXaxis()->SetTitleSize(0.10);
                rref->GetXaxis()->SetTitleOffset(1.5);
                rref->Draw("E2"); 
                rdat->SetMarkerStyle(20);
                rdat->Draw("E SAME p");
                line->Draw("SAME"); 
                c1->Update();
                pad2->GetFrame()->DrawClone();

            } else {
                rdat->GetYaxis()->SetRangeUser(TMath::Max(-1.,1.-absmax), TMath::Min(3.,absmax+1.));
                rdat->GetYaxis()->SetTitle("data/mc");
                rdat->GetYaxis()->SetLabelSize(0.10);
                rdat->GetYaxis()->SetTitleSize(0.10);
                rdat->GetYaxis()->SetTitleOffset(0.85);
                AxisFonts(rdat->GetXaxis(), "x", hstack->GetXaxis()->GetTitle());
                rdat->GetXaxis()->SetLabelSize(0.10);
                rdat->GetXaxis()->SetTitleSize(0.10);
                rdat->GetXaxis()->SetTitleOffset(1.5);
                rdat->SetTitle("");
                rdat->SetMarkerStyle(20);
                rdat->Draw("E p");
                line->Draw("SAME"); 
                c1->Update();
                pad2->GetFrame()->DrawClone();
            }

        }
Example #17
0
//TString inputsel = "&&nTaggableJetsPt20MatchedTagged>1";
void plotHhhTop(){
  gROOT->ProcessLine(".L tdrstyle.C");
  setTDRStyle();
  gROOT->SetBatch();

  //std::vector
  double binning_[]={0.,10.,20.,30.,40.,50.,60.,70.,80.,90.,100.,110.,120.,130.,140.,150.,160.,170.,180.,190.,200.,225.,250.,275.,300.,325.,350.,400.,500.,700.,1000.,1500.};

  TFile *HhhFile    = new TFile("/scratch/ojalvo/HhhGenStudies/Hhhttbb300.root");
  TFile *TOPFile = new TFile("/scratch/ojalvo/LTau_103/TOP2.root");
  TFile *MTEMFile = new TFile("/scratch/ojalvo/LTau_103/MTEM.root");

  TString selection="pt1>20&&pt2>20"+inputsel;//
  //TString selection="pt1>20&&pt2>20&&vertices>0&&diLeptons==0&&lPFIsoDB<0.1&&tauIso<1.5&&tightElectrons==0&&tightMuons<=1&&mt1<30&&J1Pt>20&&J2Pt>20";//

  TCanvas *Tcan= new TCanvas("Tcan","",100,20,600,800); Tcan->cd();  Tcan->SetFillColor(0); 

  TPad* pad1 = new TPad("pad1","The pad",0,0.2,1,1);
  TPad* pad2 = new TPad("pad2","the other pad",0,0,1,0.2);
  pad1->SetFillColor(0);
  //pad1->SetLogy();
  pad1->Draw();  pad1->cd();  pad1->SetLeftMargin(0.2);  pad1->SetBottomMargin(0.13);

  TLegend *leg = new TLegend(0.55,0.75,0.99,0.99);//  Leg = new TLegend(0.74,0.65,0.99,0.95);
  leg->SetFillColor(0);
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetHeader("");
  leg->SetShadowColor(0);

  TTree* HhhTree = (TTree*)HhhFile->Get("muTauEventTreeFinal/eventTree");

  //TH1F* Shape = new TH1F("hist1","hist1",31,&binning_[0]);
  TH1F* Shape = new TH1F("hist1","hist1",bins,lo,hi);
  HhhTree->Draw(var+">>+hist1","("+selection+")");
  Shape->SetLineColor(kBlue);  Shape->SetFillColor(kBlue);
  Shape->SetFillStyle(3002);
  Shape->SetLineWidth(4);
  //Shape->Sumw2();

  
  TTree* TOPTree = (TTree*)TOPFile->Get("muTauEventTreeFinal/eventTree");
  TH1F* Shape1 = new TH1F("hist2","hist2",bins,lo,hi);
  TOPTree->Draw(+var+">>+hist2","("+selection+")","same");

  Shape1->SetLineColor(kRed);
  Shape1->SetFillColor(kRed);
  Shape1->SetFillStyle(3002);
  Shape1->SetLineWidth(4);
  Shape1->Scale(Shape->Integral()/Shape1->Integral());

  //Shape1->Sumw2();

  TTree* MTEMTree = (TTree*)MTEMFile->Get("muTauEventTree/eventTree");
  TH1F* Shape2 = new TH1F("hist1","hist1",bins,lo,hi);
  MTEMTree->Draw(var+">>+hist1","("+selection+")","same");
  Shape2->SetLineColor(kBlack);
  Shape2->SetLineStyle(2);
  Shape2->SetLineWidth(4);
  Shape2->Scale(Shape->Integral()/Shape2->Integral());
  

  Shape->GetXaxis()->SetTitle(var);
  Shape->GetYaxis()->SetTitle("A.U.");
  Shape1->Draw("same");
  Shape->Draw("same");

  ///////////stupid thing to sent max bin
  float max, max1, max2 = 0;
  max = Shape->GetBinContent(Shape->GetMaximumBin());
  max1 = Shape1->GetBinContent(Shape1->GetMaximumBin());
  max2 = Shape2->GetBinContent(Shape2->GetMaximumBin());

  if(max>max1&&max>max2)
    Shape->SetMaximum(max*1.1);
  else if(max1>max&&max1>max2)
    Shape->SetMaximum(max1*1.1);
  else 
    Shape->SetMaximum(max2*1.1);

  ///
  leg->AddEntry(Shape,"300GeV H Signal","l");
  leg->AddEntry(Shape1,"t#bar{t}","l");
  leg->AddEntry(Shape2,"Z #rightarrow #tau#tau","l");
  //leg->AddEntry(Shape2,"Embedded 50 GeV<M(#mu#mu)<250 GeV","l");

  leg->Draw();

  
  Tcan->cd();
  /*
  pad2->Draw();
  pad2->cd();   
  pad2->SetBottomMargin(0.1);
  pad2->SetTopMargin(0.1);
  pad2->SetLeftMargin(0.2); 

  TH1F *Den = new TH1F("Den","hist",bins,lo,hi);
  TH1F *Num = new TH1F("Num","hist",bins,lo,hi);
  //Shape->Sumw2();
  TH1F *Eff = (TH1F*)Shape1->Clone();
  Eff->SetLineColor(kBlue);
  Eff->Sumw2();
  TH1F *Eff1 = (TH1F*)Shape->Clone();
  Eff1->SetLineColor(kMagenta);
  TH1F *Div = (TH1F*)Shape2->Clone();
  Div->Sumw2();
  Eff->Divide(Div);
  //Eff1->Divide(Shape3);
  //Eff2->Divide(Shape4);
  Eff->GetYaxis()->SetRangeUser(0.5,1.5);
  Eff->GetYaxis()->SetNdivisions(3);
  Eff->GetYaxis()->SetLabelSize(0.1);
  Eff->GetYaxis()->SetTitleSize(0.1);
  Eff->GetYaxis()->SetTitleOffset(0.1);
  //Eff->GetYaxis()->SetTitle(myGroup + " / " + group);                                                                                                                                                                                                  
  Eff->GetYaxis()->SetTitle("Ratio");
  Eff->GetXaxis()->SetNdivisions(-1);
  Eff->GetXaxis()->SetTitle("");
  Eff->GetXaxis()->SetLabelSize(0.0001);
  Eff->SetMarkerColor(kBlack);
  Eff->Draw("histp");
  TLine line;
  line.DrawLine(Eff->GetXaxis()->GetXmin(),1,Eff->GetXaxis()->GetXmax(),1);

  TLine lineUp;
  lineUp.DrawLine(Eff->GetXaxis()->GetXmin(),0.75,Eff->GetXaxis()->GetXmax(),0.75);

  TLine lineDown;
  lineDown.DrawLine(Eff->GetXaxis()->GetXmin(),1.25,Eff->GetXaxis()->GetXmax(),1.25);

  TF1 *f2 = new TF1("f2","x",0.5,1.5);

  TGaxis *newyaxis = new TGaxis(lo,0.5,lo,1.5,"f2");
  newyaxis->SetNdivisions(4);
  newyaxis->SetLabelSize(0.12);


  pad2->cd();
  TLine *center = new TLine(lo,1,hi,1);
  center->SetLineStyle(2);
  Eff->Draw("ap");
  //Eff1->Draw("apsame");
  //Eff2->Draw("apsame");

  center->Draw();
  line.Draw();
  lineDown.SetLineColor(kBlue);
  lineDown.Draw();
  lineUp.SetLineColor(kBlue);
  lineUp.SetLineStyle(2);
  lineUp.Draw();
  newyaxis->Draw();

  */  
  Tcan->SaveAs("~/www/htt/GenStudies/"+var+"Top.png");

  float eventsTotal=Shape1->Integral();
  TH1F* Shape5 = new TH1F("hist5","hist5",bins,lo,hi);
  HhhTree->Draw(var+">>+hist5","("+selection+"&&mJJ==mJJCSVSort)");
  std::cout<< " Fraction of Events with mJJ matched "<< Shape5->Integral()/eventsTotal  <<std::endl;
  /*
  TCanvas *Tcan2= new TCanvas("Tcan2","",100,20,600,600); Tcan2->cd();  Tcan2->SetFillColor(0); 
  gStyle->SetPalette(1);
  TH2D* Shape2D = new TH2D("hist2D","hist2D",50,0,350,50,0,300);
  MTEMTree->Draw("svMass:mJJCSVSort>>hist2D",selection+"&&mJJCSVSort<300&&svMass<300","COLZ");
  Shape2D->GetXaxis()->SetTitle("mJJ");
  Shape2D->GetYaxis()->SetTitle("M(#tau#tau)");
  Shape2D->Smooth();
  Tcan2->SaveAs("~/www/htt/GenStudies/"+var+"2DMTEM.png");
  */
}
Example #18
0
theoryPlot1Srap(){
  gROOT->LoadMacro("../xsection/setTDRStyle_modified.C");
  setTDRStyle();
  enum enuth {_data=0,_pythia,_cem,_cascade};
  int grcolor[4] = {1,4, 2,8};
  for(int i=0;i<4;i++) grcolor[i]=1; //remove color
  TFile cmsFile("xsection_1s_y0.root");
  TGraphAsymmErrors* cmsdata = ((TMultiGraph*)cmsFile.Get("mg1"))->GetListOfGraphs()->At(0);
  TCanvas *c2 = new TCanvas();//"c1","title",800,600);
  TH1F *frame = gPad->DrawFrame(0,0.1,2,50);
  //TH2F * frame = new TH2F("frame","", 1000,0.,30., 0, 0.001,10);
  frame->SetStats(0);

  frame->GetXaxis()->SetTitle("|y^{#Upsilon}|");
  TString ytitle = TString::Format("d#sigma/d|y|* BR(#Upsilon(1S)#rightarrow#mu#mu)  (nb/(GeV/c))");
  frame->GetYaxis()->SetTitle(ytitle);

  frame->GetYaxis()->SetTitleOffset(0.95);
  c2->cd();
  c2->SetLeftMargin(0.15);
  c2->SetLogy();
  frame->Draw();

  cmsdata->SetLineWidth(3);
  cmsdata->SetLineColor(grcolor[_data]);

  TFile* fp = new TFile("../GenCrossSection/genXSupsilon1Srap.root"); // open the file
  TH1F* hist1 = (TH1F*)gDirectory->Get("genY"); // get the hist
  hist1  ->SetLineColor(grcolor[_pythia]);
  hist1->SetLineWidth(2);
  hist1->SetLineStyle(1);

///////////////////////////////////////////////
  ////// Color octet Pierre
  ///////////////////////////////////////////////
  /*
  ifstream in;
  if(opt==1){
  in.open("DirectJpsi_CMSfullrap_clean.dat");
  } 
  if(opt==2){
    in.open("DirectJpsi_CMSrap_0_1.4_clean.dat");
  }
  if(opt==3){
    in.open("DirectJpsi_CMSrap_1.4_2.4_clean.dat");
  }
  Float_t pt[200], xscen[200], xsmin[200], xsmax[200], xserrlow[200], xserrhigh[200],pterr[200], xscen_corr[200], xserrlow_corr[200], xserrhigh_corr[200];
  for(int i=0; i<39; i++){
    in >> pt[i] >> xscen[i] >> xserrlow[i] >> xserrhigh[i]; 
    cout << "pt[i]= " << pt[i] << " xscen[i]= "<< xscen[i] <<"+" << xserrlow[i]<<  "-" << xserrhigh[i]<<  endl;
    xserrlow[i]=fabs(xserrhigh[i]);
    xserrhigh[i]=xserrlow[i];
    pterr[i]=0;
    Float_t factor=1000*0.0598;
    xscen_corr[i]=xscen[i]*factor;
    xserrlow_corr[i]=xserrlow[i]*factor;
    xserrhigh_corr[i]=xserrhigh[i]*factor;
  }
  
  TGraphAsymmErrors* gr;
  gr= new TGraphAsymmErrors(39,pt,xscen_corr,pterr,pterr, xserrlow_corr,xserrhigh_corr);
  gr->SetFillColor(7);
  gr->SetLineColor(7);
  TGraph * grline;
  grline= new TGraph(39,pt,xscen_corr);
  grline->SetLineWidth(5);
  grline->SetLineColor(7);
  */

  ///////////////////////////////////////////
  ///// CASCADE
  ///////////////////////////////////////////
/*
  TFile* f1 = new TFile("cascade-pp-7000-upsilon.root"); // open the file
  f1->cd("BPH10_003");
  TH1F* hh=(TH1F*)gDirectory->Get("h101");
  TFile* f2 = new TFile("cascade-pp-7000-chi_b.root"); // open the file
  f2->cd("BPH10_003");
  TH1F* gg=(TH1F*)gDirectory->Get("h101");
  gg->Add(hh);
  gg->SetLineWidth(2);
  gg->SetLineColor(8);
*/
  ////////////////////////
  /// CEM
  ////////////////////////
/*
  TH1F* histcem = new TH1F("htot1","dsigma/dptjpsi*BR(jpsi->mumu) (pb/GeV) vs ptjpsi ",98,1.,50.);
  ifstream in;
  in.open("upsilon_cem.dat");

  Float_t pt[200], pterr[200], xscen[200];
  for(int i=1; i<97; i++){
    Float_t cem;
    in >> pt[i] >> cem;
    // from Ramona Vogt
    xscen[i]=cem*2*3.14*pt[i]*0.0248;
//    cout << "CEM: pt[i]= " << pt[i] << " xscen[i]= "<< xscen[i]<<  endl;
    pterr[i]=0; // not known
  }
  for(int i=1; i<97; i++){
    histcem->SetBinContent(i, xscen[i]);
  }
  histcem->SetLineWidth(2);
  histcem->SetLineColor(2);

*/
  ////////////////////////////
  /// NOW ALL TOGETHER!
  ////////////////////////////
  ///// pierre
  //gr->Draw("E4");
  ///// cascade 
  //gg->Draw("sameHIST");
  ///// cem
  //histcem->Draw("sameHIST");
  //// /pyt
  hist1->Draw("sameHIST");
  cmsdata->Draw("P");
  //cmsdata1->Draw("Psame");

  TLatex latex3;
  latex3.DrawLatex(0.2,0.2 , "#sqrt{s}=7 TeV, L= 3 pb^{-1}");

  TLegend *leg = new TLegend(0.55,0.75,0.89,0.90);
  leg->SetBorderSize(0);
  leg->SetFillColor(10);

  leg->AddEntry(cmsdata, "CMS preliminary", "PML");
  
  //leg->AddEntry(gr, "Direct #Upsilon, LO NRQCD, Artoisenet", "FL");
  leg->AddEntry(hist1,"PYTHIA", "L");
  //leg->AddEntry(histcem, "CEM", "L");
  //leg->AddEntry(gg, "CASCADE", "L");

  leg->Draw();
  c2->Print("theoryPlot1Srap.gif");
  c2->Print("theoryPlot1Srap.eps");
  c2->Print("theoryPlot1Srap.pdf");

  hist1->Scale(7.52/15.17);
  hist1->Draw("sameHIST");
  c2->Print("theoryPlot1SrapScaled.gif");
  c2->Print("theoryPlot1SrapScaled.eps");
  c2->Print("theoryPlot1SrapScaled.pdf");
}
Example #19
0
void makeFitPlotSFJVF()
{
   gROOT->SetBatch();
   gROOT->SetStyle("Plain");
   
   gStyle->SetOptStat(0);

   gROOT->ProcessLine(".x def.C");
   gROOT->ProcessLine(".x common.C");

   bool doSubPlot = 0;

   std::string sel = "MV160";
   std::string var = "Sd0t1";

   const int nf = 2;
   std::string fv[nf] = {"","_JVF0"};

   double sf[100][100];
   double sferr[100][100];
   double sfX[100];
   double sfXerr[100];
   
   TCanvas *c1 = new TCanvas("c1","c1",0,0,600,500);
   c1->Draw();
   c1->cd();

   TPad *c1_1;
   if( doSubPlot )
     {	
	c1->Range(0,0,1,1);
	c1_1 = new TPad("c1_1","main",0.01,0.30,0.99,0.99);
	c1_1->Draw();
	c1_1->cd();
     }   
   
   gStyle->SetHistTopMargin(0);

   TLegend *leg = new TLegend(0.70,0.90,0.90,0.70);
   leg->SetFillColor(253);
   leg->SetBorderSize(0);

   int nbins = 0;
   int im = 0;

   TH1F *hc;

   TH1F *hsf[nf];
   
   for(int f=0;f<nf;f++)
     {
	std::string fname = "results/sfoverlay/fit_EFF_beauty_"+var+"_"+sel+fv[f]+".root";
	TFile *file = new TFile(fname.c_str());
	TH1F *h = (TH1F*)file->Get("h1c");
	
	nbins = h->GetXaxis()->GetNbins();
	for(int ib=1;ib<nbins+1;ib++)
	  {
	     double cont = h->GetBinContent(ib);
	     double err = h->GetBinError(ib);
	     sfXerr[ib-1] = h->GetBinWidth(ib)/2.0;
	     sfX[ib-1] = h->GetBinLowEdge(ib) + sfXerr[ib-1];
	     sf[ib-1][im] = cont;
	     sferr[ib-1][im] = err;
	  }	     
	
	if( f == 0 ) {h->SetMarkerStyle(20);h->SetMarkerColor(kRed);h->SetLineColor(kRed);}
	if( f == 1 ) {h->SetMarkerStyle(25);h->SetMarkerColor(kBlack);h->SetLineColor(kBlack);}
	if( f == 2 ) {h->SetMarkerStyle(22);h->SetMarkerColor(kBlue);h->SetLineColor(kBlue);}
	if( f == 3 ) {h->SetMarkerStyle(23);h->SetMarkerColor(kMagenta);h->SetLineColor(kMagenta);}
	
	std::string tit = "";
	if( f == 0 ) tit = "JVF > 0.5";
	if( f == 1 ) tit = "JVF > 0";
	if( f == 2 ) tit = "S_{d_{0}}(t_{3})";
	if( f == 3 ) tit = "S_{d_{0}}(#mu)";
	leg->AddEntry(h,tit.c_str(),"lep");

	if( f == 0 ) h->Draw("e1");
	else h->Draw("e1 same");

	ATLASLabel(0.20,0.85,"Internal",1);
	
	h->GetYaxis()->SetRangeUser(0.3,1.6);
	h->GetXaxis()->SetRangeUser(0.0,0.04);
	
	im++;
	
	std::string hname = "hsf"+std::string(Form("%d",f));
	hsf[f] = (TH1F*)h->Clone(hname.c_str());
     }   

   leg->Draw();
   
   gPad->RedrawAxis("g");
      
/*   if( doSubPlot )
     {
	std::string foutStr = "results/fit_EFF_beauty_SFOVERLAY_"+sel+".root";
	TFile *fout = new TFile(foutStr.c_str(),"RECREATE");
	
	int inb = hsf[0]->GetXaxis()->GetNbins();
	const int nb = inb;
	double av[nb];
	double errSum[nb];
	double absv[nb];
	
	for(int ib=1;ib<=nb;ib++)
	  {
	     av[ib-1] = 0.;
	     absv[ib-1] = 0.;
	     errSum[ib-1] = 0.;
	  }	
	
	for(int ih=0;ih<nf;ih++)
	  {
	     for(int ib=1;ib<=nb;ib++)
	       {		  
		  double err = hsf[ih]->GetBinError(ib);
//		  av[ib-1] += (err > 0) ? hsf[ih]->GetBinContent(ib)/pow(err,2) : 0.;
		  av[ib-1] += hsf[ih]->GetBinContent(ib)/float(nf);
		  errSum[ib-1] += (err > 0) ? 1./pow(err,2) : 0.;
	       }	     
	  }	

	for(int ih=0;ih<nf;ih++)
	  {
	     for(int ib=1;ib<=nb;ib++)
	       {	
		  double err = hsf[ih]->GetBinError(ib);
		  absv[ib-1] += pow(err,2);
	       }	     
	  }	
	
	for(int ib=1;ib<=nb;ib++)
	  {
//	     av[ib-1] /= errSum[ib-1];
	  }	

	for(int ib=1;ib<=nb;ib++)
	  {		  
	     absv[ib-1] = sqrt(absv[ib-1])/float(nf);
//	     absv[ib-1] = 1./sqrt(errSum[ib-1]);
	     std::cout << av[ib-1] << " +- " << absv[ib-1] << std::endl;
	  }	     
	
	c1->cd();
	TPad *c1_2 = new TPad("c1_2", "ratio",0.01,0.01,0.99,0.37);
	c1_2->Draw();
	c1_2->cd();  
	c1_2->SetBottomMargin(0.37);
	c1_2->SetGrid(0,1);

	TH1F *h1c = (TH1F*)hsf[0]->Clone("h1c");
	
	for(int ib=1;ib<=nb;ib++)
	  {	
	     h1c->SetBinContent(ib,av[ib-1]);
	     h1c->SetBinError(ib,absv[ib-1]);
	  }	     	
	
	h1c->SetMarkerStyle(20);
	h1c->SetMarkerSize(0.8);
	h1c->GetYaxis()->SetNdivisions(5);
	h1c->GetYaxis()->SetTitle("Data/MC");
	
	h1c->GetYaxis()->SetTitleSize((h1c->GetYaxis()->GetTitleSize())*2);
	h1c->GetYaxis()->SetTitleOffset(h1c->GetYaxis()->GetTitleOffset()/2);
	h1c->GetXaxis()->SetTitleSize((h1c->GetXaxis()->GetTitleSize())*2);
	h1c->GetXaxis()->SetTitleOffset(h1c->GetXaxis()->GetTitleOffset()+0.2);
	
	h1c->GetYaxis()->SetLabelSize((h1c->GetYaxis()->GetLabelSize())*2);
	h1c->GetXaxis()->SetLabelSize((h1c->GetXaxis()->GetLabelSize())*2);
	
	h1c->GetXaxis()->SetTitle(h1c->GetXaxis()->GetTitle());
	
	h1c->SetLineColor(kBlack);
	h1c->SetMarkerColor(kBlack);
	
	h1c->Draw("e1");
	
	h1c->GetYaxis()->SetRangeUser(0.5,1.5);
	
	c1->Update();

	for(int ih=0;ih<nf;ih++)
	  {	     
	     hsf[ih]->Write();
	  }	
	
	fout->Write();
	fout->Close();
     }*/

   std::string fsave = "pics/fit_SFJVF_"+sel+".eps";
   c1->Print(fsave.c_str());
   
   gApplication->Terminate();
}
void drawTimingMaps(std::string inputfile, std::string outputDir, std::string datasetInfo){
  
  // Read the specified input file
  TFile *_file1 = new TFile(inputfile.c_str());
  // Take care of making the output diretory (if it doesn't already exist)
  gSystem->mkdir((outputDir).c_str(),true);
  gSystem->mkdir((outputDir+"/OutlierTimingPlot").c_str(),true);
  TCanvas *c1 = new TCanvas("c1","c1",800,600);
 
  gStyle->SetPalette(kTemperatureMap); 
  // create some TProfile and 2-d plots
  TProfile2D **hChTiming     = new TProfile2D*[3];
  TProfile2D **hRatios       = new TProfile2D*[3];
  
  TH2D       **hChOccupy     = new TH2D*[3];
  TH2D       **hRMS          = new TH2D*[3];
  TH2D       **hErr          = new TH2D*[3];
  TH1D       **hRMSHist      = new TH1D*[3];
  TH1D       **hTimeHist     = new TH1D*[3];
  TH1D       **hTimeHistHB   = new TH1D*[3];
  TH1D       **hTimeHistHE   = new TH1D*[3];
  
  TH2F *hCorrTiming66to67P = new TH2F("hCorrTiming66to67P","hCorrTiming66to67P",100,-25,75,100,-25,75);
  hCorrTiming66to67P = (TH2F*)_file1->Get("timingMaps/hCorrTiming66to67P");
  TH2F *hCorrTimingPhi67Plus = new TH2F("hCorrTimingPhi67Plus","hCorrTimingPhi67Plus",100,-25,75,100,-25,75);
  hCorrTimingPhi67Plus = (TH2F*)_file1->Get("timingMaps/hCorrTimingPhi67Plus");
  
  TH1F *hEnergyIT = new TH1F("hEnergyIT","hEnergyIT",500,0,1000);
  TH1F *hEnergyOOT1 = new TH1F("hEnergyOOT1","hEnergyOOT1",500,0,1000);
  TH1F *hEnergyOOT2 = new TH1F("hEnergyOOT2","hEnergyOOT2",500,0,1000);
  
  hEnergyIT = (TH1F*)_file1->Get("timingMaps/hCheckEnergyIT");
  hEnergyOOT1 = (TH1F*)_file1->Get("timingMaps/hCheckEnergyOOT1");
  hEnergyOOT2 = (TH1F*)_file1->Get("timingMaps/hCheckEnergyOOT2");
  
  TH1F *hEnergyITip51 = new TH1F("hEnergyITip51","hEnergyITip51",250,0,500);
  TH1F *hEnergyOOT1ip51 = new TH1F("hEnergyOOT1ip51","hEnergyOOT1ip51",250,0,500);
  TH1F *hEnergyOOT2ip51 = new TH1F("hEnergyOOT2ip51","hEnergyOOT2ip51",250,0,500);
  
  hEnergyITip51 = (TH1F*)_file1->Get("timingMaps/hCheckEnergyITip51");
  hEnergyOOT1ip51 = (TH1F*)_file1->Get("timingMaps/hCheckEnergyOOT1ip51");
  hEnergyOOT2ip51 = (TH1F*)_file1->Get("timingMaps/hCheckEnergyOOT2ip51");
  
  // make a loop to book the histograms
  for(int it = 0; it < 3; ++it){
    hChTiming[it]     = new TProfile2D(("hTimeDepth"+int2string(it+1)).c_str(),("hTimeDepth"+int2string(it+1)).c_str(),59,-29.5,29.5,72,0.5,72.5, -37.5, 37.5,"s");
    hChOccupy[it]     = new TH2D(("hOccDepth"+int2string(it+1)).c_str(),("hOccDepth"+int2string(it+1)).c_str(),59,-29.5,29.5,72,0.5,72.5);
    hRMS[it]          = new TH2D(("hRMS_Depth"+int2string(it+1)).c_str(),("hRMS_Depth"+int2string(it+1)).c_str(),59,-29.5,29.5,72,0.5,72.5);
    hErr[it]          = new TH2D(("hErr_Depth"+int2string(it+1)).c_str(),("hErr_Depth"+int2string(it+1)).c_str(),59,-29.5,29.5,72,0.5,72.5);
    
    hRMSHist[it] = new TH1D(("hRMS_Part"+int2string(it+1)).c_str(),("hRMS_Part"+int2string(it+1)).c_str(),50, 0, 25);
    hTimeHist[it] = new TH1D(("hTime_Part"+int2string(it+1)).c_str(),("hTime_Part"+int2string(it+1)).c_str(),50, -10, 10);
    hTimeHistHE[it] = new TH1D(("hTimeHE_Part"+int2string(it+1)).c_str(),("hTimeHE_Part"+int2string(it+1)).c_str(),50, -10, 10);
    hTimeHistHB[it] = new TH1D(("hTimeHB_Part"+int2string(it+1)).c_str(),("hTimeHB_Part"+int2string(it+1)).c_str(),50, -10, 10);
  }
  
  
  // make a bunch of histograms
  TH1F *hTimeAll   = new TH1F("hTimeAll"  ,"hTimeAll"  ,50, -15, 15);  
  
  TH1F *hAllRechitTimeHB = new TH1F("hAllRechitTimeHB","hAllRechitTimeHB", 60, -15.0, 15.0);
  TH1F *hAllRechitTimeHE = new TH1F("hAllRechitTimeHE","hAllRechitTimeHE", 60, -15.0, 15.0);
  
  
  // get the plots from the root file
  for(int j = 0; j < 3; ++j){
    hChTiming[j]     = (TProfile2D*)_file1->Get(("timingMaps/hHBHETiming_Depth"+int2string(j+1)).c_str());
    hChOccupy[j]     = (TH2D*)_file1->Get(("timingMaps/occupancy_d"+int2string(j+1)).c_str());
  }
  

  
  for(int d = 0; d < 3; ++d){ // loop over all 3 depths
    for(int y=1; y < hChTiming[d]->GetNbinsY()+1; ++y){ // loop through iphi
      for(int x=1; x < hChTiming[d]->GetNbinsX()+1; ++x){ // loop through ieta
        int ieta = (int)hChTiming[d]->GetXaxis()->GetBinCenter(x); // get ieta value corresponding to x
        int iphi = (int)hChTiming[d]->GetYaxis()->GetBinCenter(y); // get iphi value corresponding to y
        // ---  skip channels which don't exist at each depth  --- 
        if(ieta == 0) continue;
        if((d+1==1) && fabs(ieta)>20 && (iphi%2==0)) continue;
        if((d+1==2) && ((fabs(ieta)<16 || fabs(ieta)==17) || (fabs(ieta)>20 && (iphi%2)==0))) continue;
        if((d+1==3) && ((fabs(ieta) < 16 ||( fabs(ieta) > 16 && fabs(ieta) < 27)) || (fabs(ieta) > 26 && iphi%2==0) || (fabs(ieta) > 28))) continue;
        // ------------ now proceed to do stuff --------------
        // get the time, rms, etc per channel
        double time = hChTiming[d]->GetBinContent(x,y);
        double RMS  = hChTiming[d]->GetBinError(x,y);
        double Evts = hChOccupy[d]->GetBinContent(x,y);
        hRMS[d]->SetBinContent(x,y,RMS);
        if(Evts > 0) hErr[d]->SetBinContent(x,y,RMS/sqrt(Evts));
        
        if(time ==0) continue;
        hTimeAll->Fill(time);
        
        // fill by partitions
        if(y >= 3  && y <  27) {
          hTimeHist[0]->Fill(time);
          if(fabs(ieta >=17)) hTimeHistHE[0]->Fill(time);
          if(fabs(ieta <=16)) hTimeHistHB[0]->Fill(time);
          hRMSHist[0]->Fill(RMS);
        }
        if(y >= 27 && y <  51) {
          hTimeHist[1]->Fill(time);
          if(fabs(ieta >=17)) hTimeHistHE[1]->Fill(time);
          if(fabs(ieta <=16)) hTimeHistHB[1]->Fill(time);
          hRMSHist[1]->Fill(RMS);
        }
        if((y <  3  || y >= 51) ) {
          if(fabs(ieta >=17)) hTimeHistHE[2]->Fill(time);
          if(fabs(ieta <=16)) hTimeHistHB[2]->Fill(time);
          hTimeHist[2]->Fill(time);
          hRMSHist[2]->Fill(RMS);
        }
        
        if(((iphi==67||iphi==66||iphi==22||iphi==60)&&ieta > 0 && ieta < 16)||((iphi==51||iphi==54)&&ieta<0&&ieta>-16)){
//           if(((iphi==51||iphi==52)&&ieta > 0 && ieta < 16)||((iphi<=58&&iphi>=55)&&ieta<-16)){
//         std::cout << "iphi = " << iphi << " ieta = " << ieta << " time = " << time << " RMS = " << RMS << std::endl;
//         }
//         print histograms for any channels which seem to be big outliers
//         if(fabs(time) >5.0 || (RMS>5)) {
          
          TH1F *hTemp = new TH1F(("OT_D"+int2string(d+1)+"_ieta"+int2string(ieta)+"_iphi"+int2string(iphi)).c_str(),("OT_D"+int2string(d+1)+"_ieta"+int2string(ieta)+"_iphi"+int2string(iphi)).c_str(),75,-37.5,37.5);
          hTemp = (TH1F*)_file1->Get(("timingMaps/Depth"+int2string(d+1)+"_ieta"+int2string(ieta)+"_iphi"+int2string(iphi)).c_str());
          c1->cd();
          hTemp->SetStats(kFALSE);
          stringstream ss;
          ss << datasetInfo<<" Depth="<<int2string(d+1)<<" ieta="<<int2string(ieta)<<" iphi="<<int2string(iphi)<<"  avg.time="<<time;
//           hTemp->SetTitle((datasetInfo+" Depth="+int2string(d+1)+" ieta="+int2string(ieta)+" iphi="+int2string(iphi)+"  avg.time="+int2string((int)time)).c_str());
          hTemp->SetTitle(ss.str().c_str());
          hTemp->Draw();
          c1->Print((outputDir+"/"+"OutlierTimingPlot"+"/Outlier_"+datasetInfo+"_Depth"+int2string(d+1)+"_ieta"+int2string(ieta)+"_iphi"+int2string(iphi)+".png").c_str());
          c1->Clear();
          delete hTemp;
        }
      } // End loop through ieta
    } // End loop through iphi
  } // End loop over depths
  // fill the depth 2 rms map
  
  
  // ================================================================================
  // ~~~~~~~~~~~~          Print plots                           ~~~~~~~~~~~~~~~~~~~~
  // --------------------------------------------------------------------------------
  
  TCanvas *canv = new TCanvas("canv","canv",800,600);
  canv->cd();
  
  
  hCorrTiming66to67P->SetStats(kFALSE);
  hCorrTiming66to67P->GetXaxis()->SetTitle("Hit Time in iphi=67 [ns]");
  hCorrTiming66to67P->GetYaxis()->SetTitle("Hit Time in iphi=66 [ns]");
  hCorrTiming66to67P->SetTitle("Timing correlation between rechits in an event");
  hCorrTiming66to67P->Draw("colz");
  canv->Print((outputDir+"/"+datasetInfo+"_hCorrTiming66to67P.png").c_str());
  canv->Clear();
  
  hCorrTimingPhi67Plus->SetStats(kFALSE);
  hCorrTimingPhi67Plus->SetStats(kFALSE);
  hCorrTimingPhi67Plus->GetXaxis()->SetTitle("Hit Time in iphi=67 [ns]");
  hCorrTimingPhi67Plus->GetYaxis()->SetTitle("Hit Time in iphi=67 [ns]");
  hCorrTimingPhi67Plus->SetTitle("Timing correlation between rechits in an event, same iphi");
  hCorrTimingPhi67Plus->Draw("colz");
  canv->Print((outputDir+"/"+datasetInfo+"hCorrTimingPhi67Plus.png").c_str());
  canv->Clear();
  
  
  // Loop over all three depths
  // one plot of each quantity per HBHE depth
  // here we just set up the axis labels, histogram title, and stuff like that
  // also print the histograms to .png file
  for(int depth = 0; depth < 3; ++depth){
    
    canv->SetLogz(kTRUE);
    hChOccupy[depth]->SetStats(kFALSE);
    hChOccupy[depth]->GetXaxis()->SetTitle("ieta");
    hChOccupy[depth]->GetYaxis()->SetTitle("iphi");
    hChOccupy[depth]->SetTitle(("Occupancy, Depth "+int2string(depth+1)).c_str());
    hChOccupy[depth]->Draw("colz");
    canv->Print((outputDir+"/"+datasetInfo+"_Depth"+int2string(depth+1)+"_occupancy.png").c_str());
    canv->Clear();
    canv->SetLogz(kFALSE);
    // Set some of the axes labels before drawing 
    hChTiming[depth]->SetStats(kFALSE);
    hChTiming[depth]->GetXaxis()->SetTitle("ieta");
    hChTiming[depth]->GetYaxis()->SetTitle("iphi");
    hChTiming[depth]->GetZaxis()->SetRangeUser(-6.0, 6.0);
    hChTiming[depth]->SetTitle(("HBHE Average Channel Timing, Depth "+int2string(depth+1) ).c_str());
    hChTiming[depth]->Draw("colz");
    canv->Print((outputDir+"/"+datasetInfo+"_Depth"+int2string(depth+1)+"_AverageTime.png").c_str());
    canv->Clear();    
    
    hRMS[depth]->SetStats(kFALSE);
    hRMS[depth]->GetXaxis()->SetTitle("ieta");
    hRMS[depth]->GetYaxis()->SetTitle("iphi");
    hRMS[depth]->GetZaxis()->SetRangeUser(0.0, 7.0);
    hRMS[depth]->SetTitle(("HBHE Time RMS, Depth "+int2string(depth+1)).c_str());
    hRMS[depth]->Draw("colz");
    canv->Print((outputDir+"/"+datasetInfo+"_Depth"+int2string(depth+1)+"_RMS.png").c_str());
    canv->Clear();
    
    hErr[depth]->SetStats(kFALSE);
    hErr[depth]->GetXaxis()->SetTitle("ieta");
    hErr[depth]->GetYaxis()->SetTitle("iphi");
    hErr[depth]->GetZaxis()->SetRangeUser(0.0, 0.4);
    hErr[depth]->SetTitle(("HBHE Time RMS/sqrt(N), Depth "+int2string(depth+1)).c_str());
    hErr[depth]->Draw("colz");
    canv->Print((outputDir+"/"+datasetInfo+"_Depth"+int2string(depth+1)+"_Err.png").c_str());
    canv->Clear();
    
    hRMSHist[depth]->SetStats(kTRUE);
    hRMSHist[depth]->GetXaxis()->SetTitle("RMS");
    hRMSHist[depth]->GetYaxis()->SetTitle("Number of Channels");
    hRMSHist[depth]->GetZaxis()->SetRangeUser(0.0, 10.0);
    if(depth == 0) hRMSHist[depth]->SetTitle("Channels with iphi 3-26");
    if(depth == 1) hRMSHist[depth]->SetTitle("Channels with iphi 27-50");
    if(depth == 2) hRMSHist[depth]->SetTitle("Channels with iphi 51-72, 1-2");
    hRMSHist[depth]->Draw("colz");
    canv->Print((outputDir+"/"+datasetInfo+"_RMS_Partition"+int2string(depth+1)+".png").c_str());
    canv->Clear();
    
    hTimeHist[depth]->SetStats(kTRUE);
    hTimeHist[depth]->GetXaxis()->SetTitle("Average Time [ns]");
    hTimeHist[depth]->GetYaxis()->SetTitle("Number of Channels");
    hTimeHist[depth]->GetZaxis()->SetRangeUser(0.0, 25.0);
    if(depth == 0) hTimeHist[depth]->SetTitle("Channels with iphi 3-26");
    if(depth == 1) hTimeHist[depth]->SetTitle("Channels with iphi 27-50");
    if(depth == 2) hTimeHist[depth]->SetTitle("Channels with iphi 51-72, 1-2");
    hTimeHist[depth]->Draw();
    canv->Print((outputDir+"/"+datasetInfo+"_AverageTime_Partition"+int2string(depth+1)+".png").c_str());
    canv->Clear();
    
    hTimeHistHB[depth]->SetStats(kTRUE);
    hTimeHistHB[depth]->GetXaxis()->SetTitle("Average Time HB [ns]");
    hTimeHistHB[depth]->GetYaxis()->SetTitle("Number of Channels");
    hTimeHistHB[depth]->GetZaxis()->SetRangeUser(0.0, 25.0);
    if(depth == 0) hTimeHistHB[depth]->SetTitle("Channels with iphi 3-26");
    if(depth == 1) hTimeHistHB[depth]->SetTitle("Channels with iphi 27-50");
    if(depth == 2) hTimeHistHB[depth]->SetTitle("Channels with iphi 51-72, 1-2");
    hTimeHistHB[depth]->Draw();
    canv->Print((outputDir+"/"+datasetInfo+"_AverageTimeHB_Partition"+int2string(depth+1)+".png").c_str());
    canv->Clear();
    
    hTimeHistHE[depth]->SetStats(kTRUE);
    hTimeHistHE[depth]->GetXaxis()->SetTitle("Average Time HE [ns]");
    hTimeHistHE[depth]->GetYaxis()->SetTitle("Number of Channels");
    hTimeHistHE[depth]->GetZaxis()->SetRangeUser(0.0, 25.0);
    if(depth == 0) hTimeHistHE[depth]->SetTitle("Channels with iphi 3-26");
    if(depth == 1) hTimeHistHE[depth]->SetTitle("Channels with iphi 27-50");
    if(depth == 2) hTimeHistHE[depth]->SetTitle("Channels with iphi 51-72, 1-2");
    hTimeHistHE[depth]->Draw();
    canv->Print((outputDir+"/"+datasetInfo+"_AverageTimeHE_Partition"+int2string(depth+1)+".png").c_str());
    canv->Clear();
    
  }

  canv->SetLogy(kTRUE);
  hTimeAll->SetStats(kFALSE);
  hTimeAll->GetXaxis()->SetTitle("Average time per channel [ns]");
  hTimeAll->GetYaxis()->SetTitle("Number of channels");
  hTimeAll->SetTitle("Average Time of Individual HBHE Channels");
  hTimeAll->Draw("colz");
  canv->Print((outputDir+"/"+datasetInfo+"_timeHist_All.png").c_str());

  // done
  return;
}
Example #21
0
void msquared() {

  double yPos, xPos, theta, energy = 0.;  // NOTE: theta comes in degrees
  int numHit, pID = 0;


  // Initialize histograms
  double nEnergyMin = 10; // MeV
  double nEnergyMax = 510; // MeV
  int nEnergyBins = 50;
  double dEnergyBinSize = (double)(nEnergyMax - nEnergyMin) / (double)nEnergyBins;

  double nThetaMin = 34; // mrad
  double nThetaMax = 88; // mrad
  int nThetaBins = 50;
  double dThetaBinSize = (nThetaMax - nThetaMin) / nThetaBins;

  double nM2Min = -5000; // MeV
  double nM2Max = 5000; // MeV
  int nM2Bins = 100;
  double dM2BinSize = (nM2Max - nM2Min)/nM2Bins;


  THStack *hs = new THStack("hs","Stacked M^2");

  TFile* file = new TFile("e+e-2yyGUN.root");

  TTree* Hits_Info = (TTree *)file->Get("Signal");

  Hits_Info->SetBranchAddress("numHits", &numHit);
  Hits_Info->SetBranchAddress("energyTot", &energy);
  Hits_Info->SetBranchAddress("XPosition", &xPos);
  Hits_Info->SetBranchAddress("YPosition", &yPos);
  Hits_Info->SetBranchAddress("Particle_ID", &pID);
  Hits_Info->SetBranchAddress("Theta", &theta);

  TH1D* hmyy = new TH1D("M_{A'}^{2}" ,             // plot label
                       "e+e- > yy",    // title
                       nM2Bins,                   // x number of bins
                       nM2Min,                    // x lower bound
                       nM2Max);                   // x upper bound

  // go through all entries and fill the histograms
  int nentries = Hits_Info->GetEntries();
  for (int i=0; i<nentries; i++) {
    Hits_Info->GetEntry(i);
    if (pID == 22) { // gammas only
      theta*= TMath::Pi()/180; //radians
      cout << "M^2 is: " << mSquared(energy, theta) << endl;
      cout << "Energy is: " << energy << endl;
           
      hmyy->Fill(mSquared(energy, theta), XSECyy * BINNING_WEIGHT / dM2BinSize);
    }
  }
  cout << "DM2binsize is:" << dM2BinSize << endl;




  hmyy->SetFillColor(kBlue);
  hmyy->SetFillStyle(3001);
  hmyy->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})");
  hmyy->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})");
  hmyy->GetXaxis()->CenterTitle();
  hmyy->GetYaxis()->CenterTitle();


  TFile* fileyyy = new TFile("e+e-2yyyGUN.root");
  TTree* Hits_Infoyyy = (TTree *)fileyyy->Get("Signal");

  Hits_Infoyyy->SetBranchAddress("numHits", &numHit);
  Hits_Infoyyy->SetBranchAddress("energyTot", &energy);
  Hits_Infoyyy->SetBranchAddress("XPosition", &xPos);
  Hits_Infoyyy->SetBranchAddress("YPosition", &yPos);
  Hits_Infoyyy->SetBranchAddress("Particle_ID", &pID);
  Hits_Infoyyy->SetBranchAddress("Theta", &theta);

  TH1D* hmyyy = new TH1D("M_{A'}^{2}" ,             // plot label
                       "e+e- > yyy",    // title
                       nM2Bins,                   // x number of bins
                       nM2Min,                    // x lower bound
                       nM2Max);                   // x upper bound
  // go through all entries and fill the histograms
  nentries = Hits_Infoyyy->GetEntries();
  for (int i=0; i<nentries; i++) {
    Hits_Infoyyy->GetEntry(i);
    if (pID == 22) { // gammas only
      theta*= TMath::Pi()/180; //radians
      cout << "M^2 is: " << mSquared(energy, theta) << endl;
      cout << "Energy is: " << energy << endl;
           
      hmyyy->Fill(mSquared(energy, theta), XSECyyy * BINNING_WEIGHT / dM2BinSize);
    }
  }
  cout << "DM2binsize is:" << dM2BinSize << endl;


  hmyyy->SetFillColor(kRed);
  hmyyy->SetFillStyle(3001);
  hmyyy->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})");
  hmyyy->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})");
  hmyyy->GetXaxis()->CenterTitle();
  hmyyy->GetYaxis()->CenterTitle();



  
  TFile* fileepluseminusy = new TFile("e+e-2e+e-yECUT0.3NOPT_2_5_1000000.root");
  //This is 1000000 events so DOWNEIGHT IT:
  XSECepluseminusy = 0.1 * XSECepluseminusy;
  TTree* Hits_Infoepluseminusy = (TTree *)fileepluseminusy->Get("Signal");

  Hits_Infoepluseminusy->SetBranchAddress("numHits", &numHit);
  Hits_Infoepluseminusy->SetBranchAddress("energyTot", &energy);
  Hits_Infoepluseminusy->SetBranchAddress("XPosition", &xPos);
  Hits_Infoepluseminusy->SetBranchAddress("YPosition", &yPos);
  Hits_Infoepluseminusy->SetBranchAddress("Particle_ID", &pID);
  Hits_Infoepluseminusy->SetBranchAddress("Theta", &theta);

  TH1D* hmepluseminusy = new TH1D("M_{A'}^{2}" ,             // plot label
                       "e+e- > e+e-y (only registering gammas)",    // title
                       nM2Bins,                   // x number of bins
                       nM2Min,                    // x lower bound
                       nM2Max);                   // x upper bound
  // go through all entries and fill the histograms
  nentries = Hits_Infoepluseminusy->GetEntries();
  for (int i=0; i<nentries; i++) {
    Hits_Infoepluseminusy->GetEntry(i);
    if (pID == 22) { // gammas only
      theta*= TMath::Pi()/180; //radians
      cout << "M^2 is: " << mSquared(energy, theta) << endl;
      cout << "Energy is: " << energy << endl;
           
      hmepluseminusy->Fill(mSquared(energy, theta), XSECepluseminusy * BINNING_WEIGHT / dM2BinSize);
    }
  }
  cout << "DM2binsize is:" << dM2BinSize << endl;


  hmepluseminusy->SetFillColor(7);
  hmepluseminusy->SetFillStyle(3001);
  hmepluseminusy->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})");
  hmepluseminusy->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})");
  hmepluseminusy->GetXaxis()->CenterTitle();
  hmepluseminusy->GetYaxis()->CenterTitle();


  

  

  //ADD YIMIN'S PLOT

  TFile *f = new TFile("YIMINPLOTBREM.root"); 

  f->ls(); 
  
  TH1F * hYIMIN = (TH1F*)f->Get("M^2"); 
  hYIMIN->SetFillColor(kOrange);
  hYIMIN->SetTitle("Bremsstrahlung");
  hYIMIN->SetFillStyle(3001);
  hYIMIN->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})");
  hYIMIN->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})");
  hYIMIN->GetXaxis()->CenterTitle();
  hYIMIN->GetYaxis()->CenterTitle();




  /**********************
      ADD BRIANS PLOT
    ********************/

  NUM_TOT_POSITRONS = 1e+07; 
  BIAS = 1e+04; 
  BINNING_WEIGHT = POSITRONS_PER_SEC/(BIAS*NUM_TOT_POSITRONS);
  B = pow(1-pow(GAMMA_PLUS, -2.), .5);

  TFile* fileinelastic = new TFile("brian_1e7_pos_1e4_bias.root");
  TTree* Hits_Infoinelastic = (TTree *)fileinelastic->Get("Signal");

  Hits_Infoinelastic->SetBranchAddress("numHits", &numHit);
  Hits_Infoinelastic->SetBranchAddress("energyTot", &energy);
  Hits_Infoinelastic->SetBranchAddress("XPosition", &xPos);
  Hits_Infoinelastic->SetBranchAddress("YPosition", &yPos);
  Hits_Infoinelastic->SetBranchAddress("Particle_ID", &pID);
  Hits_Infoinelastic->SetBranchAddress("Theta", &theta);

  TH1D* hminelastic = new TH1D("M_{A'}^{2}" ,             // plot label
                       "Inelastic (only registering gammas)",    // title
                       nM2Bins,                   // x number of bins
                       nM2Min,                    // x lower bound
                       nM2Max);                   // x upper bound
  // go through all entries and fill the histograms
  nentries = Hits_Infoinelastic->GetEntries();
  for (int i=0; i<nentries; i++) {
    Hits_Infoinelastic->GetEntry(i);
    if (pID == 22) { // gammas only
      theta*= TMath::Pi()/180; //radians
      cout << "M^2 is: " << mSquared(energy, theta) << endl;
      cout << "Energy is: " << energy << endl;
           
      hminelastic->Fill(mSquared(energy, theta), BINNING_WEIGHT / dM2BinSize);
    }
  }
  cout << "DM2binsize is:" << dM2BinSize << endl;


  hminelastic->SetFillColor(kGreen);
  hminelastic->SetFillStyle(3001);
  hminelastic->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})");
  hminelastic->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})");
  hminelastic->GetXaxis()->CenterTitle();
  hminelastic->GetYaxis()->CenterTitle();



 hs->Add(hminelastic);
  hs->Add(hYIMIN);
      hs->Add(hmyyy);
  hs->Add(hmepluseminusy);
    hs->Add(hmyy);



  // create canvas and draw histogram
  TCanvas* canvas = new TCanvas("canvas", "canvas", 700, 700);
  canvas->Divide(3,2);
  TPad* p;

  p = (TPad*)canvas->cd(1);
  //p->SetGrid();
  p->SetLogy();

 


  hs->Draw();

    hs->GetXaxis()->SetTitle("M_{A'}^{2} (MeV^{2})");
  hs->GetYaxis()->SetTitle("Photons per MeV^{2} per Second (MeV^{-2} s^{-1})");
  hs->GetXaxis()->CenterTitle();
  hs->GetYaxis()->CenterTitle();
  
  p = (TPad*)canvas->cd(4);
  hmepluseminusy->Draw();
  
  p = (TPad*)canvas->cd(3);
  hmyyy->Draw();
  p = (TPad*)canvas->cd(2);
  hmyy->Draw();

  p = (TPad*)canvas->cd(5);
  hYIMIN->Draw();

  p = (TPad*)canvas->cd(6);
  hminelastic->Draw();

/*
  p = (TPad*)canvas->cd(4);
  p->SetLogy();
  p->SetGrid();
  hm2->Draw();*/


}
int main() {
	Int_t nbins = 800, count = 0;
    Double_t integral;
	TFile *input = new TFile("FilterRMSComparison.root");
    TFile *templatefile = new TFile("/home/marko/Desktop/H4Analysis/ntuples/Templates_APDs.old.root");
	TTree *MyTree = (TTree*) input->Get("RMS");
    TCanvas *can1 = new TCanvas("can1", "canvas", 1200,900);
    TCanvas *can2 = new TCanvas("can2", "canvas", 1200,1200);
    TCanvas *can3 = new TCanvas("can3", "canvas", 1200,1200);
    can1->Divide(1,3);
    can2->Divide(1,2);
    can3->Divide(1,2);
    MyTree->SetEntryList(0);
    TString listcut = "abs(unfilteredbslope)<6 && unfilteredampfit>700";
    MyTree->Draw(">>myList", listcut, "entrylist");
    TEntryList *myList = (TEntryList*) gDirectory->Get("myList");
    MyTree->SetEntryList(myList);
    Int_t nevents = myList->GetN();
	MyTree->Draw("unfilteredevent", "abs(unfilteredbslope)<6 && unfilteredampfit>700", "goff");
    Double_t *vTemp = MyTree->GetV1();
    Int_t *vEvent = new Int_t[nevents];
    for (int iEntry = 0; iEntry<nevents; iEntry++) {
        vEvent[iEntry] = vTemp[iEntry];
    }
	TString plot, plot2, cut;
	char name[50];
    TH1F *histoave = new TH1F("histoave","Wave Pulse Average", nbins, -40, 120);
    TH1F *histoavefft = new TH1F("histoavefft","Wave Pulse Average FFT", nbins, 0, 5);
    TH1F *histoaveph = new TH1F("histoaveph","Wave Pulse Average Phase", nbins, 0, 800);
    TH1F *originaltemplate = (TH1F*) templatefile->Get("APD2_E50_G50_prof");
    originaltemplate->Rebin(16);
    TH1F *templatehisto = new TH1F("templatehisto", "Template = Green, Average = Red", nbins, -40, 120); 
    TH1F *difference = new TH1F("difference","Template vs. Average Difference", nbins, -40, 120);
    TH1F *percentdifference = new TH1F("percentdifference","Template vs. Average Percent Difference", nbins, -40, 120);
    for (Int_t i=0;i<nbins;i++) {
        templatehisto->SetBinContent(i+1, originaltemplate->GetBinContent(i+1));
    }
    templatehisto->SetLineColor(kGreen+3);
    templatehisto->SetLineWidth(4);
    can2->cd(2);
    histoave->GetYaxis()->SetRangeUser(-.120,1.2);
    //templatehisto->Draw();
    histoave->SetStats(0);
    histoave->Draw();
	for (Int_t i=0;i<nevents;i++) {
    //for (Int_t i=0;i<10;i++) {
        if (vEvent[i]==513) continue; //event for which electronics die out for a bit halfway through
		TString histoname = "TempHisto_";
        histoname += i;
        TString histoname2 = "TempHisto2_";
        histoname2 += i;
        TH2F* TempHisto = new TH2F (histoname, "Temp Histo", nbins, -40, 120, 1000, -120, 800); //nanoseconds
        TH2F* TempHisto2 = new TH2F (histoname2, "Temp Histo", nbins, -40, 120, 1000, -120, 800); //nanoseconds
        TString h1name = "h1001_";
        h1name += i;
        TString h1name2 = "h1002_";
        h1name2 += i;
        TString h1name2fft = "h1002fft_";
        h1name2 += i;
        TString h1name2ph = "h1002ph_";
        h1name2 += i;
        TString h1name3 = "h1003_";
        h1name3 += i;
        TString h1name4 = "h1004_";
        h1name4 += i;
        TH1F *h1001 = new TH1F(h1name,"Red = Unfiltered, Blue = Filtered", nbins, -40, 120);
        TH1F *h1002 = new TH1F(h1name2,"h1002", nbins, -40, 120);
        TH1F *h1002fft = new TH1F(h1name2fft,"h1002fft", nbins, 0, 5);
        TH1F *h1002ph = new TH1F(h1name2ph,"h1002ph", nbins, 0, 800);
        TH1F *h1003 = new TH1F(h1name3,"Filtered WF - Unfiltered WF", nbins, -40, 120);
        TH1F *h1004 = new TH1F(h1name4,"Percent Change in Filtered WF - Unfiltered WF", nbins, -40, 120);
        plot = "unfilteredwfval:(unfilteredwftime-unfilteredtimeref)>>";
        plot += histoname;
        plot2 = "filteredwfval:(filteredwftime-filteredtimeref)>>";
        plot2 += histoname2;
        cut = "abs(unfilteredbslope)<6 && unfilteredampfit>700 && unfilteredevent==";
        cut += vEvent[i];
        MyTree->Draw(plot, cut, "goff");
        TempHisto = (TH2F*) gDirectory->Get(histoname);
        h1001 = transform2Dto1D(TempHisto);
        MyTree->Draw(plot2, cut, "goff");
        TempHisto2 = (TH2F*) gDirectory->Get(histoname2);
        h1002 = transform2Dto1D(TempHisto2);
        if (h1002->GetBinCenter(h1002->GetMaximumBin()) < 30) continue;
        sprintf(name, "Good Events/Event%d", vEvent[i]);
        strcat(name, ".png");
        h1001->SetLineColor(kRed);
        h1002->SetLineColor(kBlue);
        h1001->SetStats(0);
        h1002->SetStats(0);
        //can1->cd(1);
        can1->cd();
        h1001->GetXaxis()->SetTitle("Time (ns)");
        h1001->GetYaxis()->SetTitle("Amplitude");
        h1001->Draw();
        h1002->Draw("same");
        //for (Int_t i=0;i<nbins;i++) {
        //    h1003->SetBinContent(i+1, (h1002->GetBinContent(i+1))-(h1001->GetBinContent(i+1)));
        //    if (h1001->GetBinContent(i+1) != 0) h1004->SetBinContent(i+1, ((h1002->GetBinContent(i+1))-(h1001->GetBinContent(i+1)))/(h1001->GetBinContent(i+1)));
        //    else h1004->SetBinContent(i+1, 0);
        //}
        //can1->cd(2);
        //h1003->Draw();
        //can1->cd(3);
        //h1004->Draw();
        //h1004->GetYaxis()->SetRangeUser(-0.1,0.1);
        //gPad->SetGrid();
        can1->SaveAs(name);
        //h1002->FFT(h1002fft, "MAG");
        //h1002->FFT(h1002ph, "PH");
        //histoavefft->Add(histoavefft, h1002fft);
        //histoaveph->Add(histoaveph, h1002ph);
        histoave->Add(histoave, h1002);
        can2->cd(2);
        h1002->Scale(1./(h1002->GetMaximum()));
        h1002->Draw("same");
        count++;
        delete TempHisto, TempHisto2, h1001, h1002, h1003, h1004, histoname, histoname2, h1name, h1name2, h1name3, h1name4;
        gDirectory->Clear();
	}
    can2->cd(1);
    //histoavefft->Scale(1./count);
    //histoaveph->Scale(1./count);
    histoave->Scale(1./count);
    
    //Double_t *re_full = new Double_t[nbins];
    //Double_t *im_full = new Double_t[nbins];
    //TH1 *Throwaway = 0;
    //TH1F *invhistoave = new TH1F(invhistoave, "Average Pulse", nbins, -40, 120);
    //TVirtualFFT *invFFT = TVirtualFFT::FFT(1, &nbins, "C2R M K");
    //for (Int_t n=0; n<nbins; n++) {
    //    (re_full)[n]=(histoavefft->GetBinContent(n+1)*cos(histoaveph->GetBinContent(n+1)));
    //    (im_full)[n]=(histoavefft->GetBinContent(n+1)*sin(histoaveph->GetBinContent(n+1)));
    //}
    //invFFT->SetPointsComplex(re_full, im_full);
    //invFFT->Transform();
    //Throwaway = TH1::TransformHisto(invFFT, Throwaway, "Re");
    //for (Int_t p=0; p<nbins; p++) {
    //    histoave->SetBinContent(p+1, Throwaway->GetBinContent(p+1)/nbins);
    //}
    histoave->Scale(1./(histoave->GetMaximum()));
    histoave->SetLineColor(kRed);
    histoave->SetLineWidth(4);
    integral = templatehisto->Integral();
    templatehisto->Scale(1./integral);
    templatehisto->SetStats(0);
    templatehisto->Draw();
    integral = histoave->Integral();
    histoave->Scale(1./integral);
    histoave->DrawClone("same");
    histoave->Scale(integral);
    can2->cd(2);
    histoave->GetXaxis()->SetTitle("Time (ns)");
    histoave->GetYaxis()->SetTitle("Normalized Amplitude");
    histoave->DrawClone("same");
    can2->SaveAs("AmpSpread.png");
    can2->SaveAs("AmpSpreadRoot.root");
    TFile *output = new TFile("Alignment.root", "recreate");
    output->cd();
    originaltemplate->Write();
    histoave->Write();
    templatehisto->Write();
    output->Close();
    can3->cd(1);
    histoave->Scale(1./integral);
    for (int i=0;i<nbins;i++) {
        difference->SetBinContent(i+1, histoave->GetBinContent(i+1) - templatehisto->GetBinContent(i+1));
        if (templatehisto->GetBinContent(i+1) != 0) percentdifference->SetBinContent(i+1, (histoave->GetBinContent(i+1) - templatehisto->GetBinContent(i+1))/templatehisto->GetBinContent(i+1));
        else percentdifference->SetBinContent(i+1, 0);
    }
    difference->GetXaxis()->SetTitle("Time (ns)");
    difference->GetYaxis()->SetTitle("Average - Template");
    difference->SetStats(0);
    difference->Draw();
    can3->cd(2);
    percentdifference->GetXaxis()->SetTitle("Time (ns)");
    percentdifference->GetYaxis()->SetTitle("Percent Difference Average - Template");
    percentdifference->SetStats(0);
    percentdifference->Draw();
    percentdifference->GetYaxis()->SetRangeUser(-0.1,0.1);
    gPad->SetGrid();
    can3->SaveAs("Difference.png");
    can3->SaveAs("Difference.root");
}
Example #23
0
void plotvn(){
    gStyle->SetOptStat(kFALSE);
    int icent = 0;
    int n = 3;
    int color[6] = {1,2,4,7,8,5};
    int style[12] = {20,21,24,25,26,27,29,30,31,32,33,34};
    TGraphErrors *gr[nsub][3][2];
    TGraphErrors *grraw[nsub][3][2];
    TString CNTEP, dire;
    for(int isub=0;isub<nsub;isub++){
    for(int idire=0;idire<3;idire++){
    for(int iCNTEP=0;iCNTEP<1;iCNTEP++){
        if(iCNTEP==0) CNTEP = "NoUseCNTEP";
        if(iCNTEP==1) CNTEP = "UseCNTEP";
        if(idire==0) dire = "";
        if(idire==1) dire = "_east";
        if(idire==2) dire = "_west";
        TString str = choosesub(isub);
        if(str=="ABORT") continue;
        gr[isub][idire][iCNTEP] = new TGraphErrors(Form("Result/%s/v%d_00_%d%s_%s.dat",CNTEP.Data(),n,icent,dire.Data(),str.Data()),"%lg %lg %lg");
        grraw[isub][idire][iCNTEP] = new TGraphErrors(Form("Result/%s/v%draw_00_%d%s_%s.dat",CNTEP.Data(),n,icent,dire.Data(),str.Data()),"%lg %lg %lg");
        SetStyle(*gr[isub][idire][iCNTEP], 1.2, color[idire+3*iCNTEP],style[isub]);
        SetStyle(*grraw[isub][idire][iCNTEP], 1.2, color[idire+3*iCNTEP],style[isub]);
    }
    }
    }
TH1F* h = new TH1F("h","",50,0,5);
h->GetXaxis()->SetRangeUser(0,3.2);
/*
TCanvas *c1 = new TCanvas("c1","c1",800,450);
iCNTEP = 0;
idire = 0;
c1->Divide(2);
c1->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
h->GetXaxis()->SetRangeUser(0,3.2);
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
for(int ilay = 0;ilay<4;ilay++){
leg->AddEntry(gr[ilay+8][idire][iCNTEP],Form("FVTX layer %d",ilay));
gr[ilay+8][idire][iCNTEP]->Draw("Psame");
}
gr[6][0][1]->Draw("Psame");
leg->AddEntry(gr[6][idire][iCNTEP],Form("FVTX -3.0<#eta<-1.0"));
leg->Draw("Psame");

c1->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio");
h->DrawCopy();
for(int ilay = 0;ilay<4;ilay++){
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[ilay+8][idire][iCNTEP],gr[6][idire][iCNTEP]);
SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[ilay+8]);
grr->Draw("Psame");
}
*/
TCanvas *c2 = new TCanvas("c2","c2",450,450);
iCNTEP = 0;
idire = 0;
//c2->Divide(2);
c2->cd(1);
if(n==1){
h->SetMinimum(-0.05);
h->SetMaximum(0.);
}
else if(n==2){
isub=5;
h->SetMinimum(0);
h->SetMaximum(0.3);
}
else if(n==3){
isub=6;
h->SetMinimum(-0.05);
h->SetMaximum(0.2);
}
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
SetTitle(*h,"p_{T} (GeV/c)",Form("v_{%d}",n),"");
c2->SetLeftMargin(0.12);
h->GetXaxis()->CenterTitle();
h->GetYaxis()->CenterTitle();
h->GetYaxis()->SetTitleSize(0.06);
h->DrawCopy();
TLatex t;
t.SetNDC();
t.DrawLatex(0.6,0.82,"d+Au 62GeV");
TLegend *leg = new TLegend(0.2,0.7,0.5,0.88);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.04);
SetStyle(*gr[4][idire][iCNTEP], 1.2, 2,style[6]);
SetStyle(*gr[isub][idire][iCNTEP], 1.2, 4,style[6]);
gr[4][idire][iCNTEP]->Draw("Psame");
gr[isub][idire][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[4][idire][iCNTEP],Form("BBCs"),"P");
leg->AddEntry(gr[isub][idire][iCNTEP],Form("FVTXs 1+2+3L -3.0<#eta<-1.0"),"P");
leg->Draw("Psame");
/*
c2->cd(2);
if(n==2){
h->SetMinimum(0.8);
h->SetMaximum(1.2);
}
if(n==3){
h->SetMinimum(0);
h->SetMaximum(2);
}
SetTitle(h,"","p_{T}","v_{2} ratio BBCs/FVTXs");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[4][idire][iCNTEP],gr[5][idire][iCNTEP]);
//SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[2]);
grr->Draw("Psame");
*/
c2->Print(Form("v%d.png",n));
/*
TCanvas *c3 = new TCanvas("c3","c3",800,450);
idire = 0;
isub=5;
c3->Divide(2);
c3->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
gr[isub][idire][1]->Draw("Psame");
gr[isub][idire][0]->Draw("Psame");
leg->AddEntry(gr[isub][idire][1],Form("FVTXs -3.0<#eta<-1.0"));
leg->AddEntry(gr[isub][idire][1],Form("Using Psi EP"),"P");
leg->AddEntry(gr[isub][idire][0],Form("Using phi EP"),"P");
leg->Draw("Psame");

c3->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio FVTXs using phi EP/using Psi EP");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][idire][0],gr[isub][idire][1]);
SetStyle(*grr,1.2,color[idire+3*0],style[isub]);
grr->Draw("Psame");
*/
TCanvas *c4 = new TCanvas("c4","c4",800,450);
isub=5;
iCNTEP = 0;
c4->Divide(2);
c4->cd(1);
if(n==1){
h->SetMinimum(-0.05);
h->SetMaximum(0.);
}
else if(n==2){
h->SetMinimum(0);
h->SetMaximum(0.3);
}
else if(n==3){
h->SetMinimum(-0.05);
h->SetMaximum(0.1);
}
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.88);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.04);
gr[isub][0][iCNTEP]->Draw("Psame");
gr[isub][1][iCNTEP]->Draw("Psame");
gr[isub][2][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs -3.0<#eta<-1.0"),"P");
leg->AddEntry(gr[isub][0][iCNTEP],Form("inclusive"),"P");
leg->AddEntry(gr[isub][1][iCNTEP],Form("East"),"P");
leg->AddEntry(gr[isub][2][iCNTEP],Form("West"),"P");
leg->Draw("Psame");

c4->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio FVTXs");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]);
//SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]);
//SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]);
grr->Draw("Psame");
c4->Print(Form("v%dEWFVTX.png",n));

TCanvas *c5 = new TCanvas("c5","c5",800,450);
isub=4;
iCNTEP = 0;
c5->Divide(2);
c5->cd(1);
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
if(n==1){
h->SetMinimum(-0.05);
h->SetMaximum(0.);
}
else if(n==2){
h->SetMinimum(0);
h->SetMaximum(0.3);
}
else if(n==3){
h->SetMinimum(-0.05);
h->SetMaximum(0.1);
}
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetTextSize(0.05);
leg->SetFillColor(0);
leg->SetBorderSize(0);
gr[isub][0][iCNTEP]->Draw("Psame");
gr[isub][1][iCNTEP]->Draw("Psame");
gr[isub][2][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[isub][0][iCNTEP],Form("Using BBC event plane"),"");
leg->AddEntry(gr[isub][0][iCNTEP],Form("inclusive"),"P");
leg->AddEntry(gr[isub][1][iCNTEP],Form("East"),"P");
leg->AddEntry(gr[isub][2][iCNTEP],Form("West"),"P");
leg->Draw("Psame");

c5->cd(2);
h->SetMinimum(0);
h->SetMaximum(2.);
SetTitle(h,"","p_{T}","v_{2} ratio");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]);
//SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]);
//SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]);
grr->Draw("Psame");
c5->Print(Form("v%dEWBBC.png",n));

TCanvas *c6 = new TCanvas("c6","c6",800,450);
iCNTEP = 0;
c6->Divide(2);
c6->cd(1);
if(n==1){
h->SetMinimum(-0.05);
h->SetMaximum(0.);
}
else if(n==2){
h->SetMinimum(0);
h->SetMaximum(0.3);
}
else if(n==3){
h->SetMinimum(-0.05);
h->SetMaximum(0.1);
}
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.5,0.75,0.8,0.85);
leg->SetFillColor(0);
leg->SetBorderSize(0);
gr[0][0][iCNTEP]->Draw("Psame");
gr[1][0][iCNTEP]->Draw("Psame");
gr[2][0][iCNTEP]->Draw("Psame");
gr[3][0][iCNTEP]->Draw("Psame");
SetStyle(*gr[0][0][iCNTEP],1.2,color[0],style[0]);
SetStyle(*gr[0][1][iCNTEP],1.2,color[1],style[1]);
SetStyle(*gr[0][2][iCNTEP],1.2,color[2],style[2]);
SetStyle(*gr[0][3][iCNTEP],1.2,color[3],style[3]);
leg->AddEntry(gr[0][0][iCNTEP],Form("FVTX 1LS"),"P");
leg->AddEntry(gr[1][0][iCNTEP],Form("FVTX 2LS"),"P");
leg->AddEntry(gr[2][0][iCNTEP],Form("FVTX 3LS"),"P");
leg->AddEntry(gr[3][0][iCNTEP],Form("FVTX 4LS"),"P");
leg->Draw("same");

c6->cd(2);
if(n==2){
h->SetMinimum(0);
h->SetMaximum(2);
}
SetTitle(h,"","p_{T}","v_{2} ratio");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[0][0][iCNTEP],gr[5][0][iCNTEP]);
//SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[0]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[1][0][iCNTEP],gr[5][0][iCNTEP]);
//SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[1]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[2][0][iCNTEP],gr[5][0][iCNTEP]);
//SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[2]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[3][0][iCNTEP],gr[5][0][iCNTEP]);
//SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[3]);
grr->Draw("Psame");
c6->Print(Form("v%dLayers.png",n));
}
Example #24
0
void gen5() {
  gROOT->SetStyle("HALLA");
  TCanvas *cn = new TCanvas("cn");
  cn->Draw();
  cn->UseCurrentStyle();
  TH1F *frm = new TH1F("frm","",100,0.,10.);
  frm->GetXaxis()->SetTitle("Q^{2}  [GeV^{2}]");
  frm->GetYaxis()->SetTitle("G_{E}^{n}/Gd");
  frm->SetMinimum(-.1);
  frm->SetMaximum(1.);
  frm->UseCurrentStyle();
  frm->Draw();
  frm->SetAxisRange(0.,5.,"X");

  TF1* galstergd = new TF1("galstergd",
			 "(1.+x/.71)*(1.+x/.71)*x/(4.*0.938*.938)*1.91/(1.+x/.71)^2/(1.+5.6*x/(4.*.938*.938))",
			 0.,4.);
  galstergd->SetLineColor(6);
  galstergd->SetLineStyle(3);
  galstergd->SetLineWidth(2);


  TF1 *genf = new TF1("genf",genff,1.,10.,1);
  genf->SetLineColor(2);
  genf->SetLineStyle(2);
  genf->SetParameter(0,1.);
  // match to Madey point just below 1.5
  // genf->SetParameter(0,.0411/genf->Eval(1.45));
  genf->SetParameter(0,-0.558645);

  TF1 *bbba05 = new TF1("BBBA05",gen_bbba05,0.,10.,0);
  bbba05->SetLineColor(7);
  bbba05->SetLineStyle(3);

 
  TMultiGraph* mgrDta = new TMultiGraph("Data","G_{E}^{n}/Gd");
  TLegend *legDta = new TLegend(.54,.6,.875,.90,"","brNDC");

  TMultiGraph* wgr = mgrDta;
  TLegend *wlg = legDta;

   // the data
  legDta->SetBorderSize(0); // turn off border
  legDta->SetFillStyle(0);
  
  datafile_t *f = datafiles;
  TGraph* gr=0;
  TGraph* ogr=0;
  while ( f && f->filename ) {
    ogr=OneGraph(f);
    if (ogr) {
      gr=fromGEntoGEnGd(ogr);
      if (f->lnpt) {
	mgrDta->Add(gr,f->lnpt);
	legDta->AddEntry(gr,f->label,f->lnpt);
      }
      else if (gr->GetMarkerStyle()>=20) {
	mgrDta->Add(gr,"p");
	legDta->AddEntry(gr,f->label,"p");
      }	
      else {
	mgrDta->Add(gr,"l");
	legDta->AddEntry(gr,f->label,"l");
      }
    }
    f++;
  }
    

  mgrDta->Draw("p");
  //  legDta->Draw();   don't draw the data legend
  
  TMultiGraph* mgrThry = new TMultiGraph("Theory","G_{E}^{n}/Gd");
  TLegend *legThry = new TLegend(.54,.6,.875,.9,"","brNDC");

  wgr = mgrThry;
  wlg = legThry;

  // the theory
  wlg->SetBorderSize(0); // turn off border
  wlg->SetFillStyle(0);
  
  f = theoryfiles1;
  ogr=0;
  gr=0;
  while ( f && f->filename ) {
    ogr=OneGraph(f);
    if (ogr) {
      gr=fromGEntoGEnGd(ogr);
      TGraphAsymmErrors *egr = dynamic_cast<TGraphAsymmErrors*>(gr);
      if (egr && egr->GetN()>1 && egr->GetEYhigh() && egr->GetEYhigh()[1]>0) {
	gr = toerror_band(egr);
	gr->SetFillStyle(3000+f->style);
      }
      if (f->lnpt) {
	wgr->Add(gr,f->lnpt);
	wlg->AddEntry(gr,f->label,f->lnpt);
      }
      else if (gr->GetMarkerStyle()>=20) {
	wgr->Add(gr,"p");
	wlg->AddEntry(gr,f->label,"p");
      }	
      else {
	wgr->Add(gr,"l");
	wlg->AddEntry(gr,f->label,"l");
      }
    }
    f++;
  }

  genf->Draw("same");
  mgrThry->Draw("c");
  galstergd->Draw("same");
  bbba05->Draw("same");
  legThry->AddEntry(genf,"F_{2}/F_{1} #propto ln^{2}(Q^{2}/#Lambda^{2})/Q^{2}","l");
  legThry->AddEntry(galstergd,"Galster fit","l");
  legThry->AddEntry(bbba05,"BBBA05","l");
  legThry->Draw();
  legDta->Draw();
  
  // draw a line at 1
  cn->Modified();

  cn->Update();
  cn->SaveAs(Form("%s.eps",psfile));
  cn->SaveAs(Form("%s.root",psfile));
  gSystem->Exec(Form("./replace_symbols.pl %s.eps",psfile));

  return;  // LEAVING HERE
}
Example #25
0
void DrawBoosted(TString VAR, float XMIN, float XMAX, int REBIN, TString XTITLE)
{
  gROOT->ForceStyle();
  const int N = 7;
  float XSEC[N] = {1.74e+6,3.67e+5,2.94e+4,6.524e+03,1.064e+03,121.5,2.542e+01};

  TString SAMPLE[N] = {
    "QCD_HT200to300",
    "QCD_HT300to500",
    "QCD_HT500to700", 
    "QCD_HT700to1000",
    "QCD_HT1000to1500",
    "QCD_HT1500to2000",
    "QCD_HT2000toInf" 
  };
 
  TFile *inf[N];
  TH1F  *h0[N],*h1[N];
  TH1F  *hQCD0,*hQCD1; 

  TCanvas *can = new TCanvas("Boosted","Boosted",900,600);
  can->cd(1);
  can->SetBottomMargin(0.3);
  //can->SetRightMargin(0.15);
  for(int k=0;k<N;k++) {
    inf[k] = TFile::Open("Histo_"+SAMPLE[k]+".root");
    h0[k]  = (TH1F*)inf[k]->Get("hadtopBoost/h_"+VAR+"_Cut_ctl");
    h0[k]->Sumw2();
    h0[k]->Rebin(REBIN);
    h1[k]  = (TH1F*)inf[k]->Get("hadtopBoost/h_"+VAR+"_Cut_sig");
    h1[k]->Sumw2();
    h1[k]->Rebin(REBIN);
    h0[k]->Scale(XSEC[k]/((TH1F*)inf[k]->Get("hadtopBoost/TriggerPass"))->GetBinContent(1));
    h1[k]->Scale(XSEC[k]/((TH1F*)inf[k]->Get("hadtopBoost/TriggerPass"))->GetBinContent(1)); 
    cout<<SAMPLE[k]<<": "<<h0[k]->GetEntries()<<" "<<h0[k]->Integral()<<endl;
    if (k == 0) {
      hQCD0 = (TH1F*)h0[k]->Clone();
      hQCD1 = (TH1F*)h1[k]->Clone();
    }
    if (k > 0) {
      hQCD0->Add(h0[k]);
      hQCD1->Add(h1[k]);
    }
  } 
  hQCD0->Scale(1/hQCD0->Integral());
  hQCD1->Scale(1/hQCD1->Integral());
  double max1 = TMath::Max(hQCD0->GetBinContent(hQCD0->GetMaximumBin()),hQCD1->GetBinContent(hQCD1->GetMaximumBin()));
  hQCD0->SetMaximum(1.2*max1);
  hQCD0->SetMinimum(1e-4);
  hQCD0->GetXaxis()->SetLabelSize(0.0);
  hQCD0->GetXaxis()->SetRangeUser(XMIN,XMAX); 
  hQCD0->Draw("HIST");
  hQCD1->Draw("sameE");

  TLegend *leg = new TLegend(0.6,0.7,0.9,0.9);
  leg->SetHeader("QCD Closure");
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetTextSize(0.05);
  leg->AddEntry(hQCD1,"Signal sample","P");
  leg->AddEntry(hQCD0,"Control sample","F");
  leg->Draw();

  TH1F *hRatio = (TH1F*)hQCD1->Clone("Ratio");
  hRatio->Divide(hQCD0);

  hRatio->SetLineColor(kBlack);
  hRatio->SetMarkerColor(kBlack);

  TPad* pad = new TPad("pad", "pad", 0., 0., 1., 1.);
  pad->SetTopMargin(0.7);
  //pad->SetRightMargin(0.15);
  pad->SetFillColor(0);
  pad->SetFillStyle(0);
  pad->Draw();
  pad->cd(0);
  gPad->SetGridy();
  hRatio->GetXaxis()->SetTitle(XTITLE);
  hRatio->GetXaxis()->SetRangeUser(XMIN,XMAX); 
  hRatio->GetYaxis()->SetNdivisions(505);
  hRatio->GetYaxis()->SetRangeUser(0,2);
  hRatio->GetYaxis()->SetLabelSize(0.04);
  hRatio->Draw();
  hRatio->Draw("same");
}
Example #26
0
void compareplots(){
  vector<TFile*> files; 
  files.push_back(new TFile("/storage/9/schweiger/analyseFxFx/pythia8/100kEvents/mergingscale_100/ttbar2JetLO8TeVMECut50GeVCTEQ6M-extracted.root"));   
  files.push_back(new TFile("/storage/9/schweiger/analyseFxFx/pythia8/100kEvents/mergingscale_100/ttbarMergedMS100GeVMCCut50GeV8TeVCTEQ6M-extracted.root"));

  



  vector<TString> names;
  names.push_back("ttbar+2 Jets, in LO");
  names.push_back("ttbar+1 Jet, FxFx-Merged");

  
  vector<TString> titles;
  titles.push_back("Gen-Jet p_{T}  with pos weights (GeV)");
  titles.push_back("Gen-Jet p_{T} with neg weights (GeV)");
  titles.push_back("Gen-Jet p_{T} (GeV)");
  titles.push_back("Gen_Jet #phi with pos. weights");
  titles.push_back("Gen_Jet #phi with neg. weights");
  titles.push_back("Gen_Jet #phi");
  titles.push_back("Gen Jet #theta with pos weights");
  titles.push_back("Gen Jet #theta with neg weights");
  titles.push_back("Gen Jet #theta");
  titles.push_back("Gen Jet Energy with pos weights (GeV) ");
  titles.push_back("Gen Jet Energy with neg weights (GeV)");
  titles.push_back("Gen Jet Energy (GeV)");
  titles.push_back("p_{T} of hardest Gen-Jet with pos weights (GeV)");
  titles.push_back("p_{T} of hardest Gen-Jet with neg weights (GeV)");
  titles.push_back("p_{T} of hardest Gen-Jet (GeV)");
  titles.push_back("p_{T} of 2nd hardest Gen-Jet with pos weights (GeV)");
  titles.push_back("p_{T} of 2nd hardest Gen-Jet with neg weights (GeV)");
  titles.push_back("p_{T} of 2nd hardest Gen-Jet (GeV)");
  titles.push_back("#eta of hardest Gen-Jets with pos weights");
  titles.push_back("#eta of hardest Gen-Jets with neg weights");
  titles.push_back("#eta of hardest Gen-Jets");
  titles.push_back("Number of Gen-Jets with pos. weights");
  titles.push_back("Number of Gen-Jets with neg. weights");
  titles.push_back("Number of Gen-Jets");


  TFile *vergleich = new TFile("vergleich_ttbar_Fx_vs_noFx.root","RECREATE");


// Show no statistics box
gStyle->SetOptStat(0);

TH1::SetDefaultSumw2();

// Main program part
  TIter nextkey(files.at(0)->GetListOfKeys());
  TKey *key;
  bool first=true;
  TCanvas* c = new TCanvas();
  c->Print("plots.pdf[");

  // Save also as pictures
  int pictureNumber = 0;

  int run = 0;
  while (key = (TKey*)nextkey()) {
    pictureNumber++;
    TString pictureName = TString::Format("%d.png",pictureNumber);


    vector<TH1F*> histos;
    histos.push_back((TH1F*)key->ReadObj());
    for(size_t i=1;i<files.size();i++){
      histos.push_back((TH1F*)files.at(i)->Get(histos.at(0)->GetName()));
    }
		       
    for(size_t i=0;i<histos.size();i++){
      if(i == 0){
	histos.at(i)->SetLineColor(kBlack);
      }
      if(i == 1){
	histos.at(i)->SetLineColor(kRed);
      }
      if(i == 2){
	histos.at(i)->SetLineColor(kBlue);
      }
      if(i == 3){
	histos.at(i)->SetLineColor(kGreen+2);
      }
      if(i == 4){
	histos.at(i)->SetLineColor(kMagenta-7);
      }
      if(i == 5){
	histos.at(i)->SetLineColor(kOrange+7);
      }
    }
    
    for(size_t i=0;i<histos.size();i++){
      histos.at(i)->Sumw2();
      histos.at(i)->Scale(1./histos.at(i)->Integral(),"width");
    }

// Set axis title
histos.at(0)->GetYaxis()->SetTitle("Normalized units"); 
std::string const histogramName = histos.at(0)->GetName();
histos.at(0)->GetXaxis()->SetLabelSize(0.06);
histos.at(0)->GetXaxis()->SetLabelOffset(0.006);
histos.at(0)->GetYaxis()->SetLabelSize(0.06);
histos.at(0)->GetYaxis()->SetLabelOffset(0.006);
histos.at(0)->GetXaxis()->SetTitleSize(0.06);
histos.at(0)->GetXaxis()->SetTitleOffset(1.1);
histos.at(0)->GetYaxis()->SetTitleSize(0.06);
histos.at(0)->GetYaxis()->SetTitleOffset(1.08);



histos.at(0)->GetXaxis()->SetTitle(titles.at(run));
run = run+1;
 if(run == (3*8)){
   run = 0;
 }
// If only two histograms per plot make a ratio plot
if(histos.size() == 2)
{

//create main pad  
                                                                                                                                                          
           TPad *mainPad = new TPad("","",0.0,0.3,1.0,1.0);
           mainPad->SetNumber(1);
           mainPad->SetBottomMargin(0.0);
           mainPad->SetRightMargin(0.04);
	   mainPad->SetLeftMargin(0.13);
           mainPad->Draw();

           //create ratio pad                                                                                                                                                           
           TPad *ratioPad = new TPad("","",0.0,0.0,1.0,0.3);
           ratioPad->SetTopMargin(0.0);
           ratioPad->SetBottomMargin(0.4);
           ratioPad->SetLeftMargin(0.13);                                                                                                                                             
           ratioPad->SetRightMargin(0.04);
           gStyle->SetOptTitle(0);
           ratioPad->SetFillColor(0);
           ratioPad->SetNumber(2);
           ratioPad->SetGridy();                                                                                                                                                      
           ratioPad->Draw();

// Draw both histograms first
c->cd(1);

histos.at(0)->Draw("histo E");
histos.at(1)->Draw("histo same E");

// Show legend and statistical tests in first pad
    for(size_t i=0;i<histos.size()-1;i=i+2){

      double ksresult = histos.at(i)->KolmogorovTest(histos.at(i+1));
      ksresult=floor(ksresult*1000+0.5)/1000;
      double chi2result =histos.at(i)->Chi2Test(histos.at(i+1),"WW");
      chi2result=floor(chi2result*1000+0.5)/1000;

      stringstream ss;
      ss << "     KS: " <<std::setprecision(3) << ksresult << " chi2: " <<std::setprecision(3) << chi2result << " Private Work"; 
      const char * ch = & ss.str().c_str();;
      TLatex * ks = new TLatex(0.1, 0.9-0.03*i, ch );
      ks->SetTextColor(histos.at(i)->GetLineColor());
      ks->SetNDC();
      ks->Draw("");      

    }

    TLegend* l = new TLegend(0.55,0.9,0.69,0.99);
    // Options for legend
    l->SetBorderSize(0);
    l->SetLineStyle(0);
    l->SetTextSize(0.049);
    l->SetFillStyle(0);
    for(size_t i=0;i<names.size();i++){
      l->AddEntry(histos.at(i),names.at(i),"L");
    }
    l->Draw("same");


// Clone histograms and draw ratio plot
c->cd(2);
 TH1F* ratioHisto = (TH1F*)histos.at(0)->Clone();
ratioHisto->Divide(histos.at(1));
ratioHisto->SetLineColor(kBlue);
ratioHisto->SetStats(false);
ratioHisto->GetYaxis()->SetTitle("Ratio #frac{noFxFx}{FxFx}");
// Same Size like in histogram
ratioHisto->SetLabelSize(histos.at(0)->GetLabelSize() * 0.7 / 0.3);
ratioHisto->SetTitleOffset((histos.at(0)->GetTitleOffset("Y") * 0.3 / 0.7), "Y");
ratioHisto->SetTitleSize((histos.at(0)->GetTitleSize("Y") * 0.7 / 0.3), "Y");
ratioHisto->SetTitleOffset((histos.at(0)->GetTitleOffset("X")), "X");
ratioHisto->SetTitleSize((histos.at(0)->GetTitleSize("X") * 0.7 / 0.3), "X");
// Use nicer range
ratioHisto->GetYaxis()->SetRangeUser(0, 2.2);
ratioHisto->GetYaxis()->SetNdivisions(503);
ratioHisto->GetYaxis()->SetLabelSize(0.06 * 0.7 / 0.3);
ratioHisto->Draw();
}
else
{

    histos.at(0)->Draw("histo E");
    for(size_t i=0;i<histos.size();i++){
      histos.at(i)->Draw("histo same E");
    }


    for(size_t i=0;i<histos.size()-1;i=i+2){

      double ksresult = histos.at(i)->KolmogorovTest(histos.at(i+1));
      ksresult=floor(ksresult*1000+0.5)/1000;
      double chi2result =histos.at(i)->Chi2Test(histos.at(i+1),"WW");
      chi2result=floor(chi2result*1000+0.5)/1000;

      stringstream ss;
      ss << "KS: " <<std::setprecision(3) << ksresult << " chi2: " <<std::setprecision(3) << chi2result; 
      const char * ch = & ss.str().c_str();;
      TText * ks = new TText(0.1, 0.9-0.03*i, ch );
      ks->SetTextColor(histos.at(i)->GetLineColor());
      ks->SetNDC();
      ks->Draw("");      

    }

    TLegend* l = new TLegend(0.65,0.5,0.9,0.7);
    l->SetBorderSize(0);
    l->SetLineStyle(0);
    //    l->SetTextSize(0.039);
    l->SetFillStyle(0);
    for(size_t i=0;i<names.size();i++){
      l->AddEntry(histos.at(i),names.at(i),"L");
    }
    l->Draw("same");
}

    c->Print("plots.pdf");
    c->SaveAs(pictureName);
    vergleich->WriteTObject(c);

}
  c->Print("plots.pdf]");


}
void plotTree(TTree *tree_, std::string whichfit, std::string selectString){

	// Create a map for plotting the pullsummaries:
	std::map < const char*, std::pair <double,double> > pullSummaryMap;
	int nPulls=0;

	TObjArray *l_branches = tree_->GetListOfBranches();
	int nBranches = l_branches->GetEntries();

	gStyle->SetPadTopMargin(0.01);

	TCanvas *c = new TCanvas("c","",960,800);

	std::string treename = tree_->GetName();
	c->SaveAs(Form("%s.pdf[",treename.c_str()));
	// File to store plots in 
	TFile *fOut = new TFile(Form("%s.root",treename.c_str()),"RECREATE");

	for (int iobj=0;iobj<nBranches;iobj++){

		TBranch *br =(TBranch*) l_branches->At(iobj);

		// Draw the normal histogram
		const char* name = br->GetName();

                // names with - are not allowed
                string namestr(name);
                if(namestr.find("-")!=string::npos) {
                  std::cout << "Variable " << name << " contains a bad character: -. Skipping. " << std::endl;
                  continue;
                }
		bool fitPull=false;
		bool fitPullf=false;

		bool plotLH=false;

		TGraph *gr=NULL;
		double p_mean =0;
		double p_err  =0;

		int nToysInTree = tree_->GetEntries();
		// Find out if paramter is fitted value or constraint term
		bool isFitted = findNuisancePre(name);
		if (doPull && isFitted){
			
			p_mean = bfvals_[name].first;	// toy constrainits thrown about best fit to data
			if(namestr.find("n_exp")==string::npos) p_err  = prevals_[name].second; // uncertainties taken from card
			std::cout << "******* "<< name << " *******"<<std::endl;
			std::cout << p_mean <<  " " << p_err << std::endl;
			std::cout << "******************************" <<std::endl;

			const char* drawInput;
                        // if the parameter is a normalization, the error is not available. Do the residual instead of the pull
                        if(namestr.find("n_exp")!=string::npos) drawInput = Form("(%s-%f)/%f",name,p_mean,p_mean);
                        else drawInput = Form("(%s-%f)/%f",name,p_mean,p_err);
			tree_->Draw(Form("%s>>%s",drawInput,name),"");
			tree_->Draw(Form("%s>>%s_fail",drawInput,name),selectString.c_str(),"same");
			fitPull  = true;
			fitPullf = true;
			if (doLH) {
			  gr = graphLH(name,p_err,whichfit);
			  if (gr) plotLH=true;
			}
			
		}

		else{
			tree_->Draw(Form("%s>>%s",name,name),"");
			tree_->Draw(Form("%s>>%s_fail",name,name),selectString.c_str(),"same");
		}
		

		TH1F* bH  = (TH1F*) gROOT->FindObject(Form("%s",name))->Clone();
		TH1F* bHf = (TH1F*) gROOT->FindObject(Form("%s_fail",name))->Clone();
		bHf->SetLineColor(2);
		bH->GetXaxis()->SetTitle(bH->GetTitle());
		bH->GetYaxis()->SetTitle(Form("no toys (%d total)",nToysInTree));
		bH->GetYaxis()->SetTitleOffset(1.05);
		bH->GetXaxis()->SetTitleOffset(0.9);
		bH->GetYaxis()->SetTitleSize(0.05);
		bH->GetXaxis()->SetTitleSize(0.05);
		if (isFitted) {bH->GetXaxis()->SetTitle(Form("(%s-#theta_{B})/#sigma_{#theta}",name));}
		else {bH->GetXaxis()->SetTitle(Form("%s",name));}
		
		bH->SetTitle("");	

		if ( bH->Integral() <=0 )  fitPull = false;
		if (fitPull) {bH->Fit("gaus"); bH->GetFunction("gaus")->SetLineColor(4);}
		
		if ( bHf->Integral() <=0 )  fitPullf = false;
		if (fitPullf) {bHf->Fit("gaus"); bHf->GetFunction("gaus")->SetLineColor(2);}

		c->Clear();
		//TPad pad1("t1","",0.01,0.02,0.59,0.98);
		// Pad 1 sizes depend on the parameter type ...
		double pad1_x1,pad1_x2,pad1_y1,pad1_y2;
		if ( !isFitted ) {
			 pad1_x1 = 0.01; 
			 pad1_x2 = 0.98; 
			 pad1_y1 = 0.045; 
			 pad1_y2 = 0.98; 
		} else {
			 pad1_x1 = 0.01; 
			 pad1_x2 = 0.59; 
			 pad1_y1 = 0.56; 
			 pad1_y2 = 0.98; 
		}
		
		TPad pad1("t1","",pad1_x1,pad1_y1,pad1_x2,pad1_y2);
		TPad pad1a("t1a","",0.01,0.045,0.59,0.522);
		TPad pad2("t2","",0.59,0.04,0.98,0.62);
		TPad pad3("t3","",0.55,0.64,0.96,0.95);

		pad1.SetNumber(1); pad2.SetNumber(2); pad3.SetNumber(3); pad1a.SetNumber(4);

		if ( isFitted ) {pad1a.Draw();pad2.Draw();pad3.Draw();}

		pad1.Draw();
		pad2.SetGrid(true);


		TLatex *titletext = new TLatex();titletext->SetNDC();

		if ( isFitted ){
			c->cd(4); 
			tree_->Draw(Form("%s:%s_In>>%s_%s_2d",name,name,name,tree_->GetName()),""); 
			//TH2D *h2d_corr = (TH2D*)gROOT->FindObject(Form("%s_2d",name));
			//h2d_corr->SetMarkerColor(4);
			//h2d_corr->SetTitle("");
			//h2d_corr->GetXaxis()->SetTitle(Form("%s_In",name));
			//h2d_corr->GetYaxis()->SetTitle(Form("%s",name));
			titletext->SetTextAlign(11);
			titletext->SetTextSize(0.05);
			titletext->DrawLatex(0.05,0.02,Form("%s_In",name));
			titletext->SetTextAngle(90);
			titletext->DrawLatex(0.04,0.06,Form("%s",name));
			titletext->SetTextAngle(0);
		}

		
		c->cd(1); bH->Draw(); bHf->Draw("same");
		TLegend *legend = new TLegend(0.6,0.8,0.9,0.89);
		legend->SetFillColor(0);
		legend->AddEntry(bH,"All Toys","L");
		legend->AddEntry(bHf,selectString.c_str(),"L");
		legend->Draw();

		if (doPull && plotLH) {
			c->cd(2); gr->Draw("ALP");
		}

		if (fitPull){
			c->cd(3);
			double gap;
			TLatex *tlatex = new TLatex(); tlatex->SetNDC(); 
			if (fitPullf) {tlatex->SetTextSize(0.09); gap=0.12;}
			else  {tlatex->SetTextSize(0.11);gap=0.14;}

			tlatex->SetTextColor(4);
			tlatex->DrawLatex(0.11,0.80,Form("Mean    : %.3f #pm %.3f",bH->GetFunction("gaus")->GetParameter(1),bH->GetFunction("gaus")->GetParError(1)));
			tlatex->DrawLatex(0.11,0.80-gap,Form("Sigma   : %.3f #pm %.3f",bH->GetFunction("gaus")->GetParameter(2),bH->GetFunction("gaus")->GetParError(2)));

			if (fitPullf){ 
				tlatex->SetTextColor(2);
				tlatex->DrawLatex(0.11,0.60,Form("Mean    : %.3f #pm %.3f",bHf->GetFunction("gaus")->GetParameter(1),bHf->GetFunction("gaus")->GetParError(1)));
				tlatex->DrawLatex(0.11,0.60-gap,Form("Sigma   : %.3f #pm %.3f",bHf->GetFunction("gaus")->GetParameter(2),bHf->GetFunction("gaus")->GetParError(2)));
			}

			tlatex->SetTextSize(0.10);
			tlatex->SetTextColor(1);
				
                        if(namestr.find("n_exp")!=string::npos) tlatex->DrawLatex(0.11,0.33,Form("Pre-fit: %.3f",prevals_[name].first));
			else tlatex->DrawLatex(0.11,0.33,Form("Pre-fit #pm #sigma_{#theta}: %.3f #pm %.3f",prevals_[name].first, p_err));
			tlatex->DrawLatex(0.11,0.18,Form("Best-fit (#theta_{B})  : %.3f ",p_mean));
			tlatex->DrawLatex(0.11,0.03,Form("Best-fit (#theta_{S+B}): %.3f ",bfvals_sb_[name].first));
			
			pullSummaryMap[name]=std::make_pair<double,double>(bH->GetFunction("gaus")->GetParameter(1),bH->GetFunction("gaus")->GetParameter(2));
			nPulls++;

		}

		double titleSize = isFitted ? 0.1 : 0.028;
		titletext->SetTextSize(titleSize);titletext->SetTextAlign(21); titletext->DrawLatex(0.55,0.92,name);
		c->SaveAs(Form("%s.pdf",treename.c_str()));
		fOut->WriteObject(c,Form("%s_%s",treename.c_str(),name));
		//c->SaveAs(Form("%s_%s.pdf",treename.c_str(),name));
	}
	
	if (doPull && nPulls>0){
	  
	    std::cout << "Generating Pull Summaries" <<std::endl; 
	    int nRemainingPulls = nPulls;
	    TCanvas *hc = new TCanvas("hc","",3000,2000); hc->SetGrid(0);
	    std::map < const char*, std::pair <double,double> >::iterator pull_it = pullSummaryMap.begin();
	    std::map < const char*, std::pair <double,double> >::iterator pull_end = pullSummaryMap.end();

	    int pullPlots = 1;
	    while (nRemainingPulls > 0){

		int nThisPulls = min(maxPullsPerPlot,nRemainingPulls);

		TH1F pullSummaryHist("pullSummary","",nThisPulls,0,nThisPulls);
		for (int pi=1;pull_it!=pull_end && pi<=nThisPulls ;pull_it++,pi++){
			pullSummaryHist.GetXaxis()->SetBinLabel(pi,(*pull_it).first);
			pullSummaryHist.SetBinContent(pi,((*pull_it).second).first);
			pullSummaryHist.SetBinError(pi,((*pull_it).second).second);
			nRemainingPulls--;
		}		

		pullSummaryHist.SetMarkerStyle(21);pullSummaryHist.SetMarkerSize(1.5);pullSummaryHist.SetMarkerColor(2);pullSummaryHist.SetLabelSize(pullLabelSize);
		pullSummaryHist.GetYaxis()->SetRangeUser(-3,3);pullSummaryHist.GetYaxis()->SetTitle("pull summary (n#sigma)");pullSummaryHist.Draw("E1");
		hc->SaveAs(Form("%s.pdf",treename.c_str()));
		fOut->WriteObject(hc,Form("comb_pulls_%s_%d",treename.c_str(),pullPlots));
	//	hc->SaveAs(Form("comb_pulls_%s_%d.pdf",treename.c_str(),pullPlots));
		pullPlots++;
	   }

	    delete hc;
	}

	c->SaveAs(Form("%s.pdf]",treename.c_str()));
	fOut->Close();
	delete c;
	return;


}
void myControlPlots(const char *cuttablefilename,
		    const char *qcdcuttablefilename,
		    const char *samplefilename,
		    const plotVar_t plotvars[])
{
  //gROOT->ProcessLine(".L tdrstyle.C");

  TString unwtcutstring, qcdcutstring;

  loadCutString(cuttablefilename, unwtcutstring);
  if (strlen(qcdcuttablefilename))
    loadCutString(qcdcuttablefilename, qcdcutstring);

  //  const char* the_cut = "1";
  //  double BINWIDTH = ((MAXRange-MINRange)/NBINS);

 // Get the input trees:

  vector<Sample *> samples;

  loadSamples(samplefilename,samples);

 // Data

  Sample *sdata = samples[0];
  cout << "ndata =" << sdata->Tree()->GetEntries() <<endl;

  TFile f("plotvar_histo.root", "RECREATE");

  //============================================================
  //  VARIABLE LOOP
  //============================================================

  for (int ivar=0; ; ivar++) {

    plotVar_t pv = plotvars[ivar];
 
    if ( !pv.plotvar.Length() ) break;

    cout << pv.plotvar << "\t"<<pv.MINRange<<"\t" << pv.MAXRange<<"\t" << pv.NBINS<<"\tTHE CUT " << endl;

    if ( sdata->Tree()->Draw(pv.plotvar,"","goff",1) == -1 ) { // check if the variable exists in the tree
      cout << "\t...can't be plotted!" << endl;
      continue;
    }

    TCut the_cut(TString("effwt*puwt*")+unwtcutstring);
    TCut the_cutE(TString("effwt*puwt*puwt*")+unwtcutstring);
    TCut qcd_cut;
    if (qcdcutstring.Length())
      qcd_cut = TCut(TString("effwt*puwt*")+qcdcutstring);

    TCut nullcut("");

    const double BINWIDTH = ((pv.MAXRange-pv.MINRange)/pv.NBINS);

    map<TString, TH1 *> m_histos;
    map<TString, bool> m_stacked;

    double totevents = 0.;
    TH1 * th1qcd = NULL;
    double qcdfrac = 0.;

    //============================================================
    // DRAW THE VARIABLE FOR ALL SAMPLES, CREATE HISTOS
    //============================================================

    for (size_t isamp=0; isamp<samples.size(); isamp++) {
      Sample *s = samples[isamp];

      m_stacked[s->name()] = false;

      TH1 *h;

      if (s->name().EqualTo("data"))            h = s->Draw(pv, the_cut, nullcut); // effwt*puwt==1 for data!
      else if (s->filename().Contains("QCD")) { h = s->Draw(pv, qcd_cut, nullcut);
	th1qcd = h;
	qcdfrac = s->otherscale();
      } else {                                  h = s->Draw(pv, the_cut, the_cutE);
	if (s->stackit()) {
	  totevents += h->Integral();
	}
      }

      map<TString, TH1 *>::iterator mit = m_histos.find(s->name());
      if (mit == m_histos.end()) {
	if (s->stackit()) {
	  h->SetFillColor(s->colorcode());
	  h->SetLineColor(s->colorcode());
	  h->SetLineWidth(0);
	}
	m_histos[s->name()] = h;
      } else {
	mit->second->Add(h);
      }
    }

    //============================================================
    // COUNT EVENTS, RENORM TO DATA, CONSTRUCT THE TSTACK & LEGEND
    //============================================================

    TH1 *th1data = m_histos["data"];

    assert(th1data);

    double ndata = th1data->Integral();

    if (th1qcd) {
      // QCD = qcdfrac * data, QCD + Sum(MC) = data, ergo...
      //th1qcd->Scale(qcdfrac*totevents/((1-qcdfrac)*th1qcd->Integral()));

      th1qcd->Scale(qcdfrac*ndata/th1qcd->Integral()); // matches previous script

      totevents += th1qcd->Integral();
    }

    double renorm = ndata/totevents;

    cout << "den = " << totevents << endl;
    cout << "data = " << ndata  <<endl;
    cout  << "data/den = " << renorm << endl;


    // Setup the stack and total
    THStack* hs = new THStack("hs","MC contribution");
    TH1D *th1tot = new TH1D("th1tot", "th1tot", pv.NBINS, pv.MINRange, pv.MAXRange);

    // Set up the legend

    float  legX0=0.65, legX1=0.99, legY0=0.4, legY1=0.88;
    // float  legX0=0.35, legX1=0.85, legY0=0.4, legY1=0.88;
    // float  legX0=0.18, legX1=0.52, legY0=0.4, legY1=0.88;
    TLegend * Leg = new TLegend( legX0, legY0, legX1, legY1);
    Leg->SetFillColor(0);
    Leg->SetFillStyle(0);
    Leg->SetTextSize(0.04);

    if (TString(cuttablefilename).Contains("Mu"))
      Leg->AddEntry(th1data,  "Muon Data",  "PLE");
    else
      Leg->AddEntry(th1data,  "Electron Data",  "PLE");

    vector<double> binErrSQ(pv.NBINS,0.);

    vector<pair<TString, TH1 *> > v_legentries;

    for (size_t isamp=1; isamp<samples.size(); isamp++) {
      Sample *s = samples[isamp];
      if (m_stacked[s->name()]) continue;

      map<TString, TH1 *>::iterator mit = m_histos.find(s->name());
      TH1 *h = mit->second;
      h->Scale(renorm);

      cout << s->name() << " = " << h->Integral() << endl;

      if(s->stackit()) {
	hs->Add(h);
	th1tot->Add(h);
	m_stacked[s->name()] = true;
	v_legentries.push_back(*mit);
	for (int ibin=1; ibin <= pv.NBINS; ibin++)
	  binErrSQ[ibin-1] += h->GetBinError(ibin)*h->GetBinError(ibin);
      }
    }

    // Reverse the order for the legend
    for (vector<pair<TString, TH1 *> >::reverse_iterator
	   rit = v_legentries.rbegin();
	 rit != v_legentries.rend();
	 rit++)
      Leg->AddEntry(rit->second, rit->first, "F");

    TH1D* th1totClone = ( TH1D*) th1tot->Clone("th1totClone");
    th1totClone->SetMarkerStyle(0);
    th1totClone->SetFillStyle(3003);
    th1totClone->SetFillColor(11);
    th1totClone->SetLineColor(0);

    for(int ibin=1; ibin<=th1totClone->GetNbinsX(); ++ibin) {
      th1totClone->SetBinError(ibin, sqrt(binErrSQ[ibin-1]));
    }

    //============================================================
    // SETUP THE CANVAS
    //============================================================

//    gROOT->ProcessLine(".L tdrstyle.C");
    setTDRStyle();
    tdrStyle->SetErrorX(0.5);
    tdrStyle->SetPadRightMargin(0.05);

    tdrStyle->SetLegendBorderSize(0);

    TCanvas* c1 = new TCanvas(pv.plotvar,pv.plotvar,10,10, 800, 800);
    TPad *d1, *d2;

    c1->Divide(1,2,0,0);
    d1 = (TPad*)c1->GetPad(1);
    d1->SetPad(0.01,0.30,0.95,0.99);
    d2 = (TPad*)c1->GetPad(2);
    d2->SetPad(0.01,0.02,0.95,0.30);

    // Compose the stack

    d1->cd();
    gPad->SetBottomMargin(0.0);
    gPad->SetTopMargin(0.1);
    gPad->SetRightMargin(0.05);
    gPad->SetLeftMargin(0.14);

    Leg->AddEntry(th1tot,  "MC Uncertainty",  "f");

    Leg->SetFillColor(0);

    TH1* th1totempty = new TH1D("th1totempty", "th1totempty", pv.ANBINS, pv.AMINRange, pv.AMAXRange);
    th1data->SetMarkerStyle(20);
    th1data->SetMarkerSize(1.25);
    th1data->SetLineWidth(2);

    th1tot->SetFillStyle(3001);
    th1tot->SetFillColor(1);
    th1tot->SetLineColor(1);
    th1tot->SetMarkerStyle(0);

    char tmpc[100];    sprintf(tmpc,"Events / %.1f GeV",BINWIDTH);
    if (pv.slog==1)    sprintf(tmpc,"Events/ %.1f",BINWIDTH);
    if (pv.slog==2)    sprintf(tmpc,"Events/ %.2f",BINWIDTH);
    if (pv.slog==3)    sprintf(tmpc,"Events/ %.0f GeV",BINWIDTH);
    if (pv.slog==6)    sprintf(tmpc,"Events/ %.1f rad",BINWIDTH);
    th1totempty->SetYTitle(tmpc);
    //  th1totempty->GetYaxis()->SetTitleSize(0.1);
    th1totempty->GetYaxis()->SetTitleOffset(1.2);
    th1totempty->GetYaxis()->SetLabelOffset(0.01);
    //  th1totempty->GetYaxis()->CenterTitle(true);
    th1totempty->GetYaxis()->SetLabelSize(0.04);
    // th1totClone->Draw("e3");   

    th1tot->SetMinimum(0.01);
    int maxbin = th1data->GetMaximumBin();
    float maxval = th1data->GetBinContent(maxbin);
    cout << "maxval " <<maxval <<endl;
//    th1totempty->SetMaximum(2.5*maxval);
    th1totempty->SetMaximum(1.6*maxval);
    th1totempty->SetMinimum(0.01);
    if(pv.slog==1) th1totempty->SetMaximum(1.6*maxval);
    th1data->SetMinimum(0.01);

    // Draw it all

    th1totempty->Draw();
    //th1tot->Draw("e2same");
    th1data->Draw("esame");
    hs->Draw("samehist");

    th1tot->Draw("e2same");

    th1data->Draw("esame");
    cmspre(intLUMIinvpb/1000.0);    
    if (pv.drawleg ==1)  Leg->Draw();  
    // th1data->Draw("Axissame");
    gPad->RedrawAxis();
    d2->cd();

    TH1F    * hhratio    = (TH1F*) th1data->Clone("hhratio")  ;
    hhratio->Sumw2();
    hhratio->SetStats(0);

    gPad->SetLeftMargin(0.14);
    gPad->SetTopMargin(0);
    gPad->SetRightMargin(0.05);
    gPad->SetFrameBorderSize(0);
    gPad->SetBottomMargin(0.3);
    gPad->SetTickx();

    hhratio->SetMarkerSize(1.25);
    //  hhratio->GetYaxis()->SetRangeUser(0.48,1.52);
    hhratio->GetYaxis()->SetRangeUser(0.3,1.7);
    hhratio->GetXaxis()->SetTitle(pv.xlabel);
    hhratio->GetXaxis()->SetTitleOffset(0.9);
    hhratio->GetXaxis()->SetTitleSize(0.15);
    hhratio->GetXaxis()->SetLabelSize(0.15);
    hhratio->GetYaxis()->SetTitleSize(0.1);
    hhratio->GetYaxis()->SetTitleOffset(0.5);
    hhratio->GetYaxis()->CenterTitle(true);
    hhratio->GetYaxis()->SetLabelSize(0.1);
    cout << hhratio->GetNbinsX() << endl;
    cout << th1tot->GetNbinsX() << endl;
    hhratio->Divide(th1tot);
    double binError(0.0), mcbinentry(0.0), mcerror(0.0);
    for(int i=0; i<hhratio->GetNbinsX(); ++i) {
      binError = hhratio->GetBinError(i);
      mcerror = th1tot->GetBinError(i);
      mcbinentry = th1tot->GetBinContent(i);
      if(mcbinentry>0.) mcerror /= mcbinentry;
      else mcerror = 0.0;
      binError = sqrt(binError*binError + mcerror*mcerror);
      hhratio->SetBinError(i, binError);
    }
    TH1D *th1emptyclone = new TH1D("th1emptyclone", "th1emptyclone", pv.ANBINS, pv.AMINRange, pv.AMAXRange);
    th1emptyclone->GetYaxis()->SetRangeUser(0.6,1.3999);
    th1emptyclone->GetXaxis()->SetTitle(pv.xlabel);
    th1emptyclone->GetXaxis()->SetTitleOffset(0.9);
    th1emptyclone->GetXaxis()->SetTitleSize(0.15);
    th1emptyclone->GetXaxis()->SetLabelSize(0.15);
    th1emptyclone->SetYTitle("Ratio Data/MC");
    th1emptyclone->GetYaxis()->SetTitleSize(0.1);
    th1emptyclone->GetXaxis()->SetNdivisions(505);
    th1emptyclone->GetYaxis()->SetNdivisions(505);
    th1emptyclone->GetYaxis()->SetTitleOffset(0.5);
    th1emptyclone->GetYaxis()->CenterTitle(true);
    th1emptyclone->GetYaxis()->SetLabelSize(0.1);
    th1emptyclone->Draw();

    TBox *errbox = new TBox(pv.AMINRange,0.974,pv.AMAXRange,1.026); // lumi systematic uncertainty
    errbox->SetFillColor(kGray);
    errbox->Draw();

#if 0
 	TF1 *f1 = new TF1("f1", "pol1",  pv.AMINRange, pv.AMAXRange);
	//f1->SetParameters(1.0,0.0);
       // f1->SetParameters(1,0.0);
	f1->FixParameter(0,1);
	f1->FixParameter(1,0);
	//cout<<" par1   "f1->GetParameter(0)<<endl;
	//cout<<" par2   "f1->GetParameter(1)<<endl;

        TFitResultPtr r =  hhratio->Fit("f1", "RBS");
	//TFitResultPtr r = hhratio->Fit(myFunc,"S");
       	    r->Print("V");     // print full information of fit including covariance matrix
#endif

    hhratio->Draw("esame");
    TLine *line; line = new TLine(pv.AMINRange,1.0,pv.AMAXRange,1.0);
    line->SetLineStyle(1);
    line->SetLineWidth(1);
    line->SetLineColor(1);
    line->Draw();

    TString outfile = TString("OutDir/")+TString(gSystem->BaseName(cuttablefilename)).ReplaceAll(".txt","")+TString("_")+pv.outfile;

    c1->Print(outfile+".png");
    c1->Print(outfile+".C");
    //gPad->WaitPrimitive();
    c1->Modified();
    c1->Update();
    c1->SaveAs(outfile+".pdf"); 

  } // var loop

  f.Write();

}                                                                // myControlPlots
void compare_ATLAS_pp_fitBoth(Int_t nfit=6, Int_t FitStart=50, Int_t FitEnd=450) {

//=========Macro generated from canvas: cATLAS_pp/
//=========  (Wed Jul 22 23:01:26 2015) by ROOT version5.32/00
    TCanvas *cATLAS_pp = new TCanvas("cATLAS_pp", "",0,0,1200,1000);
    TH1::SetDefaultSumw2();
    gStyle->SetOptFit(1);
    gStyle->SetOptStat(0);
    cATLAS_pp->Range(-3.725291e-06,-5.878322,500,3.279288);
    cATLAS_pp->SetFillColor(0);
    cATLAS_pp->SetBorderMode(0);
    cATLAS_pp->SetBorderSize(2);
    cATLAS_pp->SetLogy();
    cATLAS_pp->SetFrameBorderMode(0);
    cATLAS_pp->SetFrameBorderMode(0);
    TF1 *fitppATLAS = new TF1("fitppATLAS","[0]*pow(x+[2],[1])"); //create function
    fitppATLAS->SetParameters(1e10,-5,0);
    fitppATLAS->SetLineColor(kRed);
    TF1 *fitppCMS = new TF1("fitppCMS","[0]*pow(x+[2],[1])"); //create function
    fitppCMS->SetParameters(1e10,-5,0);
    fitppCMS->SetLineColor(kBlue);

    TGraphAsymmErrors *grae = new TGraphAsymmErrors(12);
    grae->SetName("/HepData/8719/d2x1y1");
    grae->SetTitle(" ");
    grae->SetFillColor(1);
    grae->SetMarkerStyle(33);
    grae->SetPoint(0,35,180);
    grae->SetPointError(0,4,4,29.95905,29.95905);
    grae->SetPoint(1,44.5,55.7);
    grae->SetPointError(1,5.5,5.5,7.828377,7.828377);
    grae->SetPoint(2,56.5,16.9);
    grae->SetPointError(2,6.5,6.5,2.625436,2.625436);
    grae->SetPoint(3,71,4.85);
    grae->SetPointError(3,8,8,0.6276957,0.6276957);
    grae->SetPoint(4,89.5,1.42);
    grae->SetPointError(4,10.5,10.5,0.1878054,0.1878054);
    grae->SetPoint(5,112.5,0.364);
    grae->SetPointError(5,12.5,12.5,0.04772427,0.04772427);
    grae->SetPoint(6,141.5,0.0882);
    grae->SetPointError(6,16.5,16.5,0.01103805,0.01103805);
    grae->SetPoint(7,178.5,0.0197);
    grae->SetPointError(7,20.5,20.5,0.002292152,0.002292152);
    grae->SetPoint(8,225,0.00406);
    grae->SetPointError(8,26,26,0.0004822521,0.0004822521);
    grae->SetPoint(9,283.5,0.000735);
    grae->SetPointError(9,32.5,32.5,8.981748e-05,8.981748e-05);
    grae->SetPoint(10,357,0.000114);
    grae->SetPointError(10,41,41,1.442494e-05,1.442494e-05);
    grae->SetPoint(11,449.5,1.41e-05);
    grae->SetPointError(11,51.5,51.5,1.98855e-06,1.98855e-06);

    TH1F *hATLASpp = new TH1F("hATLASpp"," ",100,50,450);
    hATLASpp->SetMinimum(1.090031e-05);
    hATLASpp->SetMaximum(230.955);
    hATLASpp->SetDirectory(0);
    hATLASpp->SetStats(0);

    Int_t ci;   // for color index setting
    ci = TColor::GetColor("#000099");
    hATLASpp->SetLineColor(ci);
    hATLASpp->GetXaxis()->SetTitle("ak R=0.4 Jet p_{T} (GeV/c)");
    hATLASpp->GetXaxis()->SetLabelFont(42);
    hATLASpp->GetXaxis()->SetLabelSize(0.035);
    hATLASpp->GetXaxis()->SetTitleSize(0.035);
    hATLASpp->GetXaxis()->SetTitleFont(42);
    hATLASpp->GetYaxis()->SetTitle("#frac{d^{2}#sigma}{dp_{T} d#eta} nb");
    hATLASpp->GetYaxis()->SetLabelFont(42);
    hATLASpp->GetYaxis()->SetLabelSize(0.035);
    hATLASpp->GetYaxis()->SetTitleSize(0.035);
    hATLASpp->GetYaxis()->SetTitleFont(42);
    hATLASpp->GetZaxis()->SetLabelFont(42);
    hATLASpp->GetZaxis()->SetLabelSize(0.035);
    hATLASpp->GetZaxis()->SetTitleSize(0.035);
    hATLASpp->GetZaxis()->SetTitleFont(42);
    grae->SetHistogram(hATLASpp);
    hATLASpp->Draw();
    grae->Draw("ap,same");

    for(int i=0; i<nfit; ++i) {
        grae->Fit("fitppATLAS","I","",FitStart,FitEnd); //fit function
    }

    Double_t xAxis2086[101] = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, 420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540, 550, 560, 570, 580, 590, 600, 610, 620, 630, 640, 650, 660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1000};

    TH1F *uPP_R4_SVD = new TH1F("uPP_R4_SVD","Unfold Matrix refpt jtpt from trigger addition R4 20_eta_20 ",100, xAxis2086);
    uPP_R4_SVD->SetBinContent(1,15.44572);
    uPP_R4_SVD->SetBinContent(2,81.73347);
    uPP_R4_SVD->SetBinContent(3,85.49986);
    uPP_R4_SVD->SetBinContent(4,90.07588);
    uPP_R4_SVD->SetBinContent(5,47.67952);
    uPP_R4_SVD->SetBinContent(6,18.31659);
    uPP_R4_SVD->SetBinContent(7,7.348095);
    uPP_R4_SVD->SetBinContent(8,3.295203);
    uPP_R4_SVD->SetBinContent(9,1.60486);
    uPP_R4_SVD->SetBinContent(10,0.8393627);
    uPP_R4_SVD->SetBinContent(11,0.4622419);
    uPP_R4_SVD->SetBinContent(12,0.265131);
    uPP_R4_SVD->SetBinContent(13,0.1587068);
    uPP_R4_SVD->SetBinContent(14,0.09774788);
    uPP_R4_SVD->SetBinContent(15,0.06153403);
    uPP_R4_SVD->SetBinContent(16,0.03981187);
    uPP_R4_SVD->SetBinContent(17,0.02620752);
    uPP_R4_SVD->SetBinContent(18,0.01766706);
    uPP_R4_SVD->SetBinContent(19,0.01206758);
    uPP_R4_SVD->SetBinContent(20,0.008403017);
    uPP_R4_SVD->SetBinContent(21,0.005956108);
    uPP_R4_SVD->SetBinContent(22,0.004267026);
    uPP_R4_SVD->SetBinContent(23,0.003102345);
    uPP_R4_SVD->SetBinContent(24,0.002273482);
    uPP_R4_SVD->SetBinContent(25,0.001699103);
    uPP_R4_SVD->SetBinContent(26,0.001281323);
    uPP_R4_SVD->SetBinContent(27,0.000971557);
    uPP_R4_SVD->SetBinContent(28,0.0007444665);
    uPP_R4_SVD->SetBinContent(29,0.0005746992);
    uPP_R4_SVD->SetBinContent(30,0.0004462709);
    uPP_R4_SVD->SetBinContent(31,0.0003483805);
    uPP_R4_SVD->SetBinContent(32,0.0002725941);
    uPP_R4_SVD->SetBinContent(33,0.0002141152);
    uPP_R4_SVD->SetBinContent(34,0.0001705039);
    uPP_R4_SVD->SetBinContent(35,0.0001352845);
    uPP_R4_SVD->SetBinContent(36,0.0001073623);
    uPP_R4_SVD->SetBinContent(37,8.559958e-05);
    uPP_R4_SVD->SetBinContent(38,6.847693e-05);
    uPP_R4_SVD->SetBinContent(39,5.506579e-05);
    uPP_R4_SVD->SetBinContent(40,4.404838e-05);
    uPP_R4_SVD->SetBinContent(41,3.566817e-05);
    uPP_R4_SVD->SetBinContent(42,2.88001e-05);
    uPP_R4_SVD->SetBinContent(43,2.33088e-05);
    uPP_R4_SVD->SetBinContent(44,1.897322e-05);
    uPP_R4_SVD->SetBinContent(45,1.546483e-05);
    uPP_R4_SVD->SetBinContent(46,1.251424e-05);
    uPP_R4_SVD->SetBinContent(47,1.020799e-05);
    uPP_R4_SVD->SetBinContent(48,8.267746e-06);
    uPP_R4_SVD->SetBinContent(49,6.760333e-06);
    uPP_R4_SVD->SetBinContent(50,5.504337e-06);
    uPP_R4_SVD->SetBinContent(51,4.514429e-06);
    uPP_R4_SVD->SetBinContent(52,3.665816e-06);
    uPP_R4_SVD->SetBinContent(53,3.010496e-06);
    uPP_R4_SVD->SetBinContent(54,2.463812e-06);
    uPP_R4_SVD->SetBinContent(55,2.01082e-06);
    uPP_R4_SVD->SetBinContent(56,1.624154e-06);
    uPP_R4_SVD->SetBinContent(57,1.334625e-06);
    uPP_R4_SVD->SetBinContent(58,1.088798e-06);
    uPP_R4_SVD->SetBinContent(59,8.896167e-07);
    uPP_R4_SVD->SetBinContent(60,7.305952e-07);
    uPP_R4_SVD->SetBinContent(61,5.930196e-07);
    uPP_R4_SVD->SetBinContent(62,4.863888e-07);
    uPP_R4_SVD->SetBinContent(63,3.941485e-07);
    uPP_R4_SVD->SetBinContent(64,3.221651e-07);
    uPP_R4_SVD->SetBinContent(65,2.636797e-07);
    uPP_R4_SVD->SetBinContent(66,2.146457e-07);
    uPP_R4_SVD->SetBinContent(67,1.742243e-07);
    uPP_R4_SVD->SetBinContent(68,1.409108e-07);
    uPP_R4_SVD->SetBinContent(69,1.142703e-07);
    uPP_R4_SVD->SetBinContent(70,9.293402e-08);
    uPP_R4_SVD->SetBinContent(71,7.511816e-08);
    uPP_R4_SVD->SetBinContent(72,6.013509e-08);
    uPP_R4_SVD->SetBinContent(73,4.927971e-08);
    uPP_R4_SVD->SetBinContent(74,3.992714e-08);
    uPP_R4_SVD->SetBinContent(75,3.176246e-08);
    uPP_R4_SVD->SetBinContent(76,2.560933e-08);
    uPP_R4_SVD->SetBinContent(77,2.039975e-08);
    uPP_R4_SVD->SetBinContent(78,1.627726e-08);
    uPP_R4_SVD->SetBinContent(79,1.272043e-08);
    uPP_R4_SVD->SetBinContent(80,1.022684e-08);
    uPP_R4_SVD->SetBinContent(81,8.172451e-09);
    uPP_R4_SVD->SetBinContent(82,6.570082e-09);
    uPP_R4_SVD->SetBinContent(83,5.205766e-09);
    uPP_R4_SVD->SetBinContent(84,4.075393e-09);
    uPP_R4_SVD->SetBinContent(85,3.265506e-09);
    uPP_R4_SVD->SetBinContent(86,2.62088e-09);
    uPP_R4_SVD->SetBinContent(87,2.003114e-09);
    uPP_R4_SVD->SetBinContent(88,1.535628e-09);
    uPP_R4_SVD->SetBinContent(89,1.063791e-09);
    uPP_R4_SVD->SetBinContent(90,9.092138e-10);
    uPP_R4_SVD->SetBinContent(91,6.803265e-10);
    uPP_R4_SVD->SetBinContent(92,4.778346e-10);
    uPP_R4_SVD->SetBinContent(93,3.988072e-10);
    uPP_R4_SVD->SetBinContent(94,2.474126e-10);
    uPP_R4_SVD->SetBinContent(95,2.140924e-10);
    uPP_R4_SVD->SetBinContent(96,1.623732e-10);
    uPP_R4_SVD->SetBinContent(97,1.45067e-10);
    uPP_R4_SVD->SetBinContent(98,9.186947e-11);
    uPP_R4_SVD->SetBinContent(99,6.040857e-11);
    uPP_R4_SVD->SetBinContent(100,6.157141e-11);
    uPP_R4_SVD->SetBinError(1,0.1237595);
    uPP_R4_SVD->SetBinError(2,0.6234048);
    uPP_R4_SVD->SetBinError(3,0.586929);
    uPP_R4_SVD->SetBinError(4,0.5173901);
    uPP_R4_SVD->SetBinError(5,0.2055361);
    uPP_R4_SVD->SetBinError(6,0.04990473);
    uPP_R4_SVD->SetBinError(7,0.01308245);
    uPP_R4_SVD->SetBinError(8,0.006804987);
    uPP_R4_SVD->SetBinError(9,0.003260532);
    uPP_R4_SVD->SetBinError(10,0.001534405);
    uPP_R4_SVD->SetBinError(11,0.001026545);
    uPP_R4_SVD->SetBinError(12,0.000705749);
    uPP_R4_SVD->SetBinError(13,0.0004784051);
    uPP_R4_SVD->SetBinError(14,0.0003483983);
    uPP_R4_SVD->SetBinError(15,0.0002598719);
    uPP_R4_SVD->SetBinError(16,0.0001903908);
    uPP_R4_SVD->SetBinError(17,0.0001387089);
    uPP_R4_SVD->SetBinError(18,0.0001040173);
    uPP_R4_SVD->SetBinError(19,7.981541e-05);
    uPP_R4_SVD->SetBinError(20,6.24475e-05);
    uPP_R4_SVD->SetBinError(21,4.937991e-05);
    uPP_R4_SVD->SetBinError(22,3.947987e-05);
    uPP_R4_SVD->SetBinError(23,3.254473e-05);
    uPP_R4_SVD->SetBinError(24,2.764293e-05);
    uPP_R4_SVD->SetBinError(25,2.429597e-05);
    uPP_R4_SVD->SetBinError(26,2.159774e-05);
    uPP_R4_SVD->SetBinError(27,1.917051e-05);
    uPP_R4_SVD->SetBinError(28,1.6997e-05);
    uPP_R4_SVD->SetBinError(29,1.498669e-05);
    uPP_R4_SVD->SetBinError(30,1.312744e-05);
    uPP_R4_SVD->SetBinError(31,1.142902e-05);
    uPP_R4_SVD->SetBinError(32,9.871913e-06);
    uPP_R4_SVD->SetBinError(33,8.480939e-06);
    uPP_R4_SVD->SetBinError(34,7.324674e-06);
    uPP_R4_SVD->SetBinError(35,6.255272e-06);
    uPP_R4_SVD->SetBinError(36,5.306614e-06);
    uPP_R4_SVD->SetBinError(37,4.495288e-06);
    uPP_R4_SVD->SetBinError(38,3.800242e-06);
    uPP_R4_SVD->SetBinError(39,3.214166e-06);
    uPP_R4_SVD->SetBinError(40,2.692884e-06);
    uPP_R4_SVD->SetBinError(41,2.275421e-06);
    uPP_R4_SVD->SetBinError(42,1.910914e-06);
    uPP_R4_SVD->SetBinError(43,1.60384e-06);
    uPP_R4_SVD->SetBinError(44,1.350324e-06);
    uPP_R4_SVD->SetBinError(45,1.135728e-06);
    uPP_R4_SVD->SetBinError(46,9.463317e-07);
    uPP_R4_SVD->SetBinError(47,7.933288e-07);
    uPP_R4_SVD->SetBinError(48,6.591956e-07);
    uPP_R4_SVD->SetBinError(49,5.520988e-07);
    uPP_R4_SVD->SetBinError(50,4.597711e-07);
    uPP_R4_SVD->SetBinError(51,3.851643e-07);
    uPP_R4_SVD->SetBinError(52,3.190695e-07);
    uPP_R4_SVD->SetBinError(53,2.670117e-07);
    uPP_R4_SVD->SetBinError(54,2.22444e-07);
    uPP_R4_SVD->SetBinError(55,1.84622e-07);
    uPP_R4_SVD->SetBinError(56,1.515098e-07);
    uPP_R4_SVD->SetBinError(57,1.263889e-07);
    uPP_R4_SVD->SetBinError(58,1.045901e-07);
    uPP_R4_SVD->SetBinError(59,8.662012e-08);
    uPP_R4_SVD->SetBinError(60,7.20551e-08);
    uPP_R4_SVD->SetBinError(61,5.920339e-08);
    uPP_R4_SVD->SetBinError(62,4.912298e-08);
    uPP_R4_SVD->SetBinError(63,4.024705e-08);
    uPP_R4_SVD->SetBinError(64,3.324212e-08);
    uPP_R4_SVD->SetBinError(65,2.747888e-08);
    uPP_R4_SVD->SetBinError(66,2.258106e-08);
    uPP_R4_SVD->SetBinError(67,1.849393e-08);
    uPP_R4_SVD->SetBinError(68,1.50859e-08);
    uPP_R4_SVD->SetBinError(69,1.233344e-08);
    uPP_R4_SVD->SetBinError(70,1.010825e-08);
    uPP_R4_SVD->SetBinError(71,8.230567e-09);
    uPP_R4_SVD->SetBinError(72,6.634947e-09);
    uPP_R4_SVD->SetBinError(73,5.473309e-09);
    uPP_R4_SVD->SetBinError(74,4.462479e-09);
    uPP_R4_SVD->SetBinError(75,3.571148e-09);
    uPP_R4_SVD->SetBinError(76,2.895626e-09);
    uPP_R4_SVD->SetBinError(77,2.318939e-09);
    uPP_R4_SVD->SetBinError(78,1.859689e-09);
    uPP_R4_SVD->SetBinError(79,1.460273e-09);
    uPP_R4_SVD->SetBinError(80,1.179314e-09);
    uPP_R4_SVD->SetBinError(81,9.46416e-10);
    uPP_R4_SVD->SetBinError(82,7.638915e-10);
    uPP_R4_SVD->SetBinError(83,6.075323e-10);
    uPP_R4_SVD->SetBinError(84,4.772801e-10);
    uPP_R4_SVD->SetBinError(85,3.836821e-10);
    uPP_R4_SVD->SetBinError(86,3.088773e-10);
    uPP_R4_SVD->SetBinError(87,2.367363e-10);
    uPP_R4_SVD->SetBinError(88,1.819577e-10);
    uPP_R4_SVD->SetBinError(89,1.263493e-10);
    uPP_R4_SVD->SetBinError(90,1.082238e-10);
    uPP_R4_SVD->SetBinError(91,8.113796e-11);
    uPP_R4_SVD->SetBinError(92,5.70881e-11);
    uPP_R4_SVD->SetBinError(93,4.772047e-11);
    uPP_R4_SVD->SetBinError(94,2.964495e-11);
    uPP_R4_SVD->SetBinError(95,2.568217e-11);
    uPP_R4_SVD->SetBinError(96,1.949672e-11);
    uPP_R4_SVD->SetBinError(97,1.743206e-11);
    uPP_R4_SVD->SetBinError(98,1.104588e-11);
    uPP_R4_SVD->SetBinError(99,7.265969e-12);
    uPP_R4_SVD->SetBinError(100,7.407249e-12);
    uPP_R4_SVD->SetEntries(100);
    uPP_R4_SVD->SetStats(0);

    ci = TColor::GetColor("#000099");
    uPP_R4_SVD->SetLineColor(ci);

//    ci = TColor::GetColor("#0000ff");
//    uPP_R4_SVD->SetMarkerColor(ci);
//    uPP_R4_SVD->SetMarkerStyle(24);
//    uPP_R4_SVD->GetXaxis()->CenterTitle(true);
//    uPP_R4_SVD->GetXaxis()->SetLabelFont(42);
//    uPP_R4_SVD->GetXaxis()->SetLabelSize(0.035);
//    uPP_R4_SVD->GetXaxis()->SetTitleSize(0.035);
//    uPP_R4_SVD->GetXaxis()->SetTitleFont(42);
//    uPP_R4_SVD->GetYaxis()->CenterTitle(true);
//    uPP_R4_SVD->GetYaxis()->SetLabelFont(42);
//    uPP_R4_SVD->GetYaxis()->SetLabelSize(0.035);
//    uPP_R4_SVD->GetYaxis()->SetTitleSize(0.035);
//    uPP_R4_SVD->GetYaxis()->SetTitleFont(42);
//    uPP_R4_SVD->GetZaxis()->SetLabelFont(42);
//    uPP_R4_SVD->GetZaxis()->SetLabelSize(0.035);
//    uPP_R4_SVD->GetZaxis()->SetTitleSize(0.035);
//    uPP_R4_SVD->GetZaxis()->SetTitleFont(42);
//    uPP_R4_SVD->Draw("same E1");
//    TBox *box = new TBox(60,7.108492,70,7.587699);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();
//    box = new TBox(70,3.186674,80,3.403731);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();
//    box = new TBox(80,1.551541,90,1.658179);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();
//    box = new TBox(90,0.8111346,100,0.8675909);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();
//    box = new TBox(100,0.4464541,110,0.4780297);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();
//    box = new TBox(110,0.2045159,130,0.2193219);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();
//    box = new TBox(130,0.07677678,150,0.08250514);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();
//    box = new TBox(150,0.03180206,170,0.03421734);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();
//    box = new TBox(170,0.01431415,190,0.01542048);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();
//    box = new TBox(190,0.006909775,210,0.007449351);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();
//    box = new TBox(210,0.003092187,240,0.003336382);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();
//    box = new TBox(240,0.001266417,270,0.001368238);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();
//    box = new TBox(270,0.00056544,300,0.0006115177);
//    box->SetFillColor(2);
//    box->SetFillStyle(0);
//    box->SetLineColor(2);
//    box->Draw();

    TLegend *leg = new TLegend(0.4,0.65,0.6,0.85,NULL,"BRNDC");
    leg->SetBorderSize(0);
    leg->SetTextSize(0.04);
    leg->SetLineColor(1);
    leg->SetLineStyle(1);
    leg->SetLineWidth(1);
    leg->SetFillColor(10);
    leg->SetFillStyle(1001);
    TLegendEntry *entry=leg->AddEntry("NULL","","h");
    entry->SetLineColor(1);
    entry->SetLineStyle(1);
    entry->SetLineWidth(1);
    entry->SetMarkerColor(1);
    entry->SetMarkerStyle(21);
    entry->SetMarkerSize(1);
    entry->SetTextFont(62);
    entry=leg->AddEntry("/HepData/8719/d2x1y1","ATLAS pp","p");
    entry->SetLineColor(1);
    entry->SetLineStyle(1);
    entry->SetLineWidth(1);
    entry->SetMarkerColor(1);
    entry->SetMarkerStyle(33);
    entry->SetMarkerSize(1);
    entry=leg->AddEntry("uPP_R4_SVD","CMS pp","p");
    entry->SetLineColor(1);
    entry->SetLineStyle(1);
    entry->SetLineWidth(1);

    ci = TColor::GetColor("#0000ff");
    entry->SetMarkerColor(ci);
    entry->SetMarkerStyle(24);
    entry->SetMarkerSize(1);
    leg->Draw();

    TPaveText *pt = new TPaveText(0.4845652,0.94,0.5154348,0.995,"blNDC");
    pt->SetName("title");
    pt->SetBorderSize(0);
    pt->SetFillColor(0);
    pt->SetFillStyle(0);
    pt->SetTextFont(42);
    TText *text = pt->AddText(" ");
    pt->Draw();
    cATLAS_pp->Modified();
    cATLAS_pp->cd();
    cATLAS_pp->SetSelected(cATLAS_pp);

    for(int ic=0; ic<nfit; ic++) {
        uPP_R4_SVD->Fit("fitppCMS","IL","",60,FitEnd); //fit function
//      uPP_R4_SVD->Fit("fitppCMS","IL","",50,300); //fit function
    }

    hATLASpp->Draw();
    grae->Draw("ap,same");
    uPP_R4_SVD->Draw("same E1");
    leg->Draw();
    cATLAS_pp->SaveAs("Plots/CMSfit_ATLASfit_spectra_pp.pdf");


    TCanvas *cCMS_pp = new TCanvas("cCMS_pp", "",0,0,1200,1000);
    cCMS_pp->Range(-3.725291e-06,-5.878322,500,3.279288);
    cCMS_pp->SetFillColor(0);
    cCMS_pp->SetBorderMode(0);
    cCMS_pp->SetBorderSize(2);
    cCMS_pp->SetLogy();
    cCMS_pp->SetLogx();
    cCMS_pp->SetFrameBorderMode(0);
    cCMS_pp->SetFrameBorderMode(0);
    uPP_R4_SVD->GetXaxis()->SetTitle("ak R=0.4 Jet p_{T} (GeV/c)");
    uPP_R4_SVD->GetXaxis()->SetLabelFont(42);
    uPP_R4_SVD->GetXaxis()->SetLabelSize(0.035);
    uPP_R4_SVD->GetXaxis()->SetTitleSize(0.035);
    uPP_R4_SVD->GetXaxis()->SetTitleFont(42);
    uPP_R4_SVD->GetXaxis()->SetRangeUser(50,450);
    uPP_R4_SVD->GetYaxis()->SetTitle("#frac{d^{2}#sigma}{dp_{T} d#eta} nb");
    uPP_R4_SVD->GetYaxis()->SetLabelFont(42);
    uPP_R4_SVD->GetYaxis()->SetLabelSize(0.035);
    uPP_R4_SVD->GetYaxis()->SetTitleSize(0.035);
    uPP_R4_SVD->GetYaxis()->SetTitleFont(42);
    uPP_R4_SVD->GetZaxis()->SetLabelFont(42);
    uPP_R4_SVD->GetZaxis()->SetLabelSize(0.035);
    uPP_R4_SVD->GetZaxis()->SetTitleSize(0.035);
    uPP_R4_SVD->GetZaxis()->SetTitleFont(42);

    uPP_R4_SVD->Draw();

    TLegend *leg = new TLegend(0.4,0.65,0.6,0.85,NULL,"BRNDC");
    leg->SetBorderSize(0);
    leg->SetTextSize(0.04);
    leg->SetLineColor(1);
    leg->SetLineStyle(1);
    leg->SetLineWidth(1);
    leg->SetFillColor(10);
    leg->SetFillStyle(1001);
    TLegendEntry *entry=leg->AddEntry("NULL","","h");
    entry->SetLineColor(1);
    entry->SetLineStyle(1);
    entry->SetLineWidth(1);
    entry->SetMarkerColor(1);
    entry->SetMarkerStyle(33);
    entry->SetMarkerSize(1);
    entry=leg->AddEntry("uPP_R4_SVD","CMS pp","p");
    entry->SetLineColor(1);
    entry->SetLineStyle(1);
    entry->SetLineWidth(1);

    ci = TColor::GetColor("#0000ff");
    entry->SetMarkerColor(ci);
    entry->SetMarkerStyle(24);
    entry->SetMarkerSize(1);
    leg->Draw();

    TPaveText *pt = new TPaveText(0.4845652,0.94,0.5154348,0.995,"blNDC");
    pt->SetName("title");
    pt->SetBorderSize(0);
    pt->SetFillColor(0);
    pt->SetFillStyle(0);
    pt->SetTextFont(42);
    TText *text = pt->AddText(" ");
    pt->Draw();
    cCMS_pp->Modified();
    cCMS_pp->cd();
    cCMS_pp->SetSelected(cCMS_pp);
    cCMS_pp->SaveAs("Plots/CMSfit_spectra_pp.pdf");

    TCanvas *cATLAS_lin_pp = new TCanvas("cATLAS_lin_pp", "",0,0,1200,1000);
    cATLAS_lin_pp->Range(-3.725291e-06,-5.878322,500,3.279288);
    cATLAS_lin_pp->SetFillColor(0);
    cATLAS_lin_pp->SetBorderMode(0);
    cATLAS_lin_pp->SetBorderSize(2);
    cATLAS_lin_pp->SetFrameBorderMode(0);
    cATLAS_lin_pp->SetFrameBorderMode(0);
    cATLAS_lin_pp->SetLogy();
    cATLAS_lin_pp->SetLogx();
    hATLASpp->Draw();
    grae->Draw("ap,same");
    TLegend *leg = new TLegend(0.4,0.65,0.6,0.85,NULL,"BRNDC");
    leg->SetBorderSize(0);
    leg->SetTextSize(0.04);
    leg->SetLineColor(1);
    leg->SetLineStyle(1);
    leg->SetLineWidth(1);
    leg->SetFillColor(10);
    leg->SetFillStyle(1001);
    TLegendEntry *entry=leg->AddEntry("NULL","","h");
    entry->SetLineColor(1);
    entry->SetLineStyle(1);
    entry->SetLineWidth(1);
    entry->SetMarkerColor(1);
    entry->SetMarkerStyle(21);
    entry->SetMarkerSize(1);
    entry->SetTextFont(62);
    entry=leg->AddEntry("/HepData/8719/d2x1y1","ATLAS pp","p");
    entry->SetLineColor(1);
    entry->SetLineStyle(1);
    entry->SetLineWidth(1);
    entry->SetMarkerColor(1);
    entry->SetMarkerStyle(33);
    entry->SetMarkerSize(1);
    entry=leg->AddEntry("uPP_R4_SVD","CMS pp","p");
    entry->SetLineColor(1);
    entry->SetLineStyle(1);
    entry->SetLineWidth(1);

    ci = TColor::GetColor("#0000ff");
    entry->SetMarkerColor(ci);
    entry->SetMarkerStyle(24);
    entry->SetMarkerSize(1);
    leg->Draw();

    TPaveText *pt = new TPaveText(0.4845652,0.94,0.5154348,0.995,"blNDC");
    pt->SetName("title");
    pt->SetBorderSize(0);
    pt->SetFillColor(0);
    pt->SetFillStyle(0);
    pt->SetTextFont(42);
    TText *text = pt->AddText(" ");
    pt->Draw();
    cATLAS_lin_pp->Modified();
    cATLAS_lin_pp->cd();
    cATLAS_lin_pp->SetSelected(cATLAS_lin_pp);

    for(int ic=0; ic<nfit; ic++) {
        uPP_R4_SVD->Fit("fitppCMS","IL","",60,FitEnd); //fit function
//      uPP_R4_SVD->Fit("fitppCMS","IL","",50,300); //fit function
    }

    hATLASpp->Draw();
    grae->Draw("ap,same");
    uPP_R4_SVD->Draw("same E1");
    leg->Draw();
    cATLAS_lin_pp->SaveAs("Plots/CMSfit_ATLASfit_spectra_loglog_pp.pdf");

    fitppCMS->SetBit(TF1::kNotDraw);
    fitppCMS->SetLineColor(0);
    uPP_R4_SVD->SetBit(TF1::kNotDraw);

    TH1F *hFitRatioATLAS = (TH1F*)functionHist(fitppCMS,uPP_R4_SVD,"hFitRatioATLAS"); //clone fitRatioATLAS from fitppCMS
//   hFitRatioATLAS->SetLineColor(0);
    TH1F *hRatioATLAS = (TH1F*)uPP_R4_SVD->Clone("hRatioATLAS"); //clone histogram hRatio from h

    TH1F *hfunctionATLAS = (TH1F*)functionHist(fitppATLAS,uPP_R4_SVD,"hfunctionATLAS");
    hFitRatioATLAS->Divide(hfunctionATLAS);
    hFitRatioATLAS->SetMarkerColor(kRed);
    hFitRatioATLAS->SetMarkerStyle(21);
    hFitRatioATLAS->SetMarkerSize(1.2);
    hFitRatioATLAS->SetLineColor(0);
//   hfunctionATLAS->Draw();
//   hATLASpp->Draw();
    hRatioATLAS->Divide(hfunctionATLAS);
    TCanvas *cRatio_pp = new TCanvas("cRatio_pp", "",0,0,1200,1000);
    gStyle->SetOptFit(1);
    gStyle->SetOptStat(0);
    gStyle->SetOptTitle(0);
    cRatio_pp->Range(-50.00001,-6.302699,538.2353,2.631555);
    cRatio_pp->SetFillColor(0);
    cRatio_pp->SetBorderMode(0);
    cRatio_pp->SetBorderSize(0);
    cRatio_pp->SetTickx(1);
    cRatio_pp->SetTicky(1);
    cRatio_pp->SetLeftMargin(0.17);
    cRatio_pp->SetRightMargin(0.15);
    cRatio_pp->SetTopMargin(0.03);
    cRatio_pp->SetBottomMargin(0.15);
    cRatio_pp->SetFrameLineColor(0);
    cRatio_pp->SetFrameBorderMode(0);
    cRatio_pp->SetFrameLineColor(0);
    cRatio_pp->SetFrameBorderMode(0);
    TH1F *hRatioBlank = new TH1F("hRatioBlank"," ",100,50,300);
    hRatioBlank->SetMinimum(0);
    hRatioBlank->SetMaximum(1.2);
    hRatioBlank->SetDirectory(0);
    hRatioBlank->SetStats(0);
    hRatioBlank->SetFillColor(1);
    hRatioBlank->SetFillStyle(0);
    hRatioBlank->SetLineStyle(0);
    hRatioBlank->SetMarkerStyle(20);
    hRatioBlank->SetMarkerSize(1.2);
    hRatioBlank->GetXaxis()->SetTitle("ak R=0.4 Jet p_{T} (GeV/c)");
    hRatioBlank->GetXaxis()->SetLabelFont(42);
    hRatioBlank->GetXaxis()->SetLabelOffset(0.01);
    hRatioBlank->GetXaxis()->SetLabelSize(0.045);
    hRatioBlank->GetXaxis()->SetTitleSize(0.055);
    hRatioBlank->GetXaxis()->SetTitleFont(42);
    hRatioBlank->GetYaxis()->SetTitle("CMS/ATLAS #frac{d^{2}#sigma}{dp_{T} d#eta} nb");
    hRatioBlank->GetYaxis()->SetLabelFont(42);
    hRatioBlank->GetYaxis()->SetLabelOffset(0.01);
    hRatioBlank->GetYaxis()->SetLabelSize(0.045);
    hRatioBlank->GetYaxis()->SetTitleSize(0.055);
    hRatioBlank->GetYaxis()->SetTitleOffset(1.5);
    hRatioBlank->GetYaxis()->SetTitleFont(42);
    hRatioBlank->GetZaxis()->SetLabelFont(42);
    hRatioBlank->GetZaxis()->SetLabelSize(0.045);
    hRatioBlank->GetZaxis()->SetTitleSize(0.035);
    hRatioBlank->GetZaxis()->SetTitleFont(42);
    hRatioBlank->Draw();
//   hRatioATLAS->Scale(5.3/4);
//   hFitRatioATLAS->Scale(5.3/4);
    hFitRatioATLAS->Draw("ap,same");
    hRatioATLAS->Draw("ap,same");

    cRatio_pp->SaveAs("Plots/CMSfit_ATLASfit_ratio_pp.pdf");



}
Example #30
0
void DrawQCDClosure(TString VAR,TString XTITLE)
{
  gROOT->ForceStyle();
  TString FileName[7] = {"QCD_HT200to300","QCD_HT300to500","QCD_HT500to700","QCD_HT700to1000","QCD_HT1000to1500","QCD_HT1500to2000","QCD_HT2000toInf"};
  float XSEC[7]       = {1.74e+6,3.67e+5,2.94e+4,6.524e+03,1.064e+03,121.5,2.542e+01};
  TFile *inf[7];
  TH1F  *h[7],*h1[7];

  TCanvas *can = new TCanvas("can_QCDClosure_"+VAR,"can_QCDClosure_"+VAR,900,600);
  can->cd(1);
  can->SetBottomMargin(0.3);
  can->SetRightMargin(0.15);

  for(int i=0;i<7;i++) {
    inf[i] = TFile::Open("Histo_"+FileName[i]+".root");
    TH1F *hTriggerPass = (TH1F*)inf[i]->Get("hadtopL/TriggerPass");
    h[i]   = (TH1F*)inf[i]->Get("hadtopL/h_"+VAR);
    h1[i]   = (TH1F*)inf[i]->Get("hadtop/h_"+VAR);
    h[i]->Sumw2();
    h1[i]->Sumw2();
    h[i]->Rebin(5);
    h1[i]->Rebin(5);
    h[i]->Scale(XSEC[i]/hTriggerPass->GetBinContent(1));
    h1[i]->Scale(XSEC[i]/hTriggerPass->GetBinContent(1));
    cout<<hTriggerPass->GetBinContent(1)<<endl;
  }

  TH1F *hQCD  = (TH1F*)h[0]->Clone("hQCD");
  TH1F *hQCD1 = (TH1F*)h1[0]->Clone("hQCD1");
  for(int i=0;i<7;i++) {
    hQCD->Add(h[i]);
    hQCD1->Add(h1[i]);
  } 
  hQCD->SetFillColor(kGray);

  hQCD->Scale(1./hQCD->Integral());
  hQCD1->Scale(1./hQCD1->Integral());
  hQCD->GetXaxis()->SetLabelSize(0.0);
  double max = 1.1*TMath::Max(hQCD->GetBinContent(hQCD->GetMaximumBin()),hQCD1->GetBinContent(hQCD1->GetMaximumBin()));
  hQCD->SetMinimum(1e-5);
  hQCD->SetMaximum(max);
  hQCD->Draw("hist");
  hQCD1->Draw("sameE");
  gPad->RedrawAxis();

  TLegend *leg = new TLegend(0.86,0.65,0.99,0.9);
  leg->SetFillColor(0);
  leg->SetTextFont(42);
  leg->SetTextSize(0.03);
  leg->AddEntry(hQCD,"Control","F");
  leg->AddEntry(hQCD1,"Signal","LP");
  leg->Draw();

  TH1F *hRatio = (TH1F*)hQCD1->Clone("Ratio");
  hRatio->Divide(hQCD);

  TPad* pad = new TPad("pad", "pad", 0., 0., 1., 1.);
  pad->SetTopMargin(0.7);
  pad->SetRightMargin(0.15);
  pad->SetFillColor(0);
  pad->SetFillStyle(0);
  pad->Draw();
  pad->cd(0);
  gPad->SetGridy();
  hRatio->GetXaxis()->SetTitle(XTITLE);
  hRatio->GetYaxis()->SetNdivisions(505);
  hRatio->GetYaxis()->SetRangeUser(0,2);
  hRatio->GetYaxis()->SetLabelSize(0.04);
  hRatio->Draw();
}