TLegend* makeExpLegend(TGraph& sg_gr, TGraph& sgd_gr,TGraph& ch_gr,TGraph& sl_gr,TGraph& tev_sn,Double_t txtsz,Int_t tanbeta){

  //TLegend* legexp = new TLegend(0.61,0.65,0.91,0.9,NULL,"brNDC");
  //TLegend* legexp = new TLegend(0.70,0.70,0.91,0.9,NULL,"brNDC");
  TLegend* legexp = new TLegend(0.61,0.65,0.99,0.9,NULL,"brNDC");


  legexp->SetFillColor(0);
  legexp->SetShadowColor(0);
  legexp->SetTextSize(txtsz);
  legexp->SetBorderSize(0);

  sg_gr.SetLineColor(1);
  
  legexp->AddEntry(&sg_gr,"CDF  #tilde{#font[12]{g}}, #tilde{#font[12]{q}}, #scale[0.8]{tan#beta=5, #mu<0}","f"); 

  legexp->AddEntry(&sgd_gr,"D0   #tilde{#font[12]{g}}, #tilde{#font[12]{q}}, #scale[0.8]{tan#beta=3, #mu<0}","f");  

  ch_gr.SetLineColor(1);
  legexp->AddEntry(&ch_gr,"LEP2   #tilde{#chi}_{1}^{#pm}","f");  
  
  sl_gr.SetLineColor(1);
  if(tanbeta != 50) legexp->AddEntry(&sl_gr,"LEP2   #tilde{#font[12]{l}}^{#pm}","f"); 
  if(tanbeta == 3) legexp->AddEntry(&tev_sn,"D0  #chi^{#pm}_{1}, #chi^{0}_{2}","f");  
 

  return legexp;

}
void writeToCanvas(TCanvas& canvas, TH1D* hist1, TH1D* hist2, TLegend& legend)
{
  setCanvasOptions(canvas);
  hist1->Scale(1.0/hist1->Integral());
  hist2->Scale(1.0/hist2->Integral());
  hist1->SetLineColor(8);
  hist2->SetLineColor(9);
  hist1->SetLineWidth(2);
  hist2->SetLineWidth(2);
  hist1->SetFillStyle(0);
  hist2->SetFillStyle(0);
  string title(canvas.GetTitle());
  size_t slashPos = title.find('/');
  legend.AddEntry(hist1, title.substr(0, slashPos).c_str(), "L");
  legend.AddEntry(hist2, title.substr(slashPos + 1, string::npos).c_str(), "L");
  legend.SetTextFont(42);
  legend.SetTextSize(0.02);
  legend.SetShadowColor(0);
  legend.SetLineColor(0);
  legend.SetFillStyle(0);
  canvas.cd();
  hist1->Draw();
  hist2->Draw("SAME");
  legend.Draw();
}
Beispiel #3
0
void drawsingle(TString var, const int nHist, TH1F** hist, std::vector<TString> samples, std::vector<TString> legend, TString x_title)
{
  
  
  // make plots
  TCanvas *c1 = new TCanvas("c1","c1");
  c1->cd();  
  
  TLegend *leg = new TLegend(0.55, 0.78, 0.68, 0.92);
  leg->SetFillColor(0);
  leg->SetTextSize(0.035);
  leg->SetBorderSize(0);
  leg->SetFillStyle(0);
  leg->SetShadowColor(0);

  float yMax = 0;
  
  for(int i=0;i<nHist;i++) {
    hist[i]->Scale(1./hist[i]->Integral(0,1000));
    yMax = yMax > hist[i]->GetMaximum() ? yMax : hist[i]->GetMaximum();
    hist[i]->SetXTitle(x_title);
    hist[i]->SetLineWidth(2);
    Color_t color = kBlack;
    if ( samples[i].Contains("SMHiggs", TString::kExact) )       color = kBlue;
    if ( samples[i].Contains("PSHiggs", TString::kExact) )       color = kMagenta;
    if ( samples[i].Contains("THiggs", TString::kExact) )       color = kRed;
    if ( samples[i].Contains("T", TString::kExact) )       color = kRed;

    hist[i]->SetLineColor(color);
    leg->AddEntry(hist[i], legend[i], "l");
  }
  
  for ( int i=0; i<nHist;i++) {
    hist[i]->SetMaximum(yMax*1.2);
    hist[i]->SetMinimum(0.);
    if ( i == 0) 
      hist[i]->Draw("HIST");
    else 
      hist[i]->Draw("sameHIST");
  }
  leg->Draw("SAME"); 
  c1->Print(Form("epsfiles/nocut/%s_mH%i.eps", var.Data(), mH ));
  c1->Print(Form("pngfiles/nocut/%s_mH%i.png", var.Data(), mH ));
  //c1->Print(Form("epsfiles/wwselection/%s_mH%i.eps", var.Data(), mH ));
  //c1->Print(Form("pngfiles/wwselection/%s_mH%i.png", var.Data(), mH ));
  
	    
  // tidy up
  delete leg;  
  delete c1;
  
}
Beispiel #4
0
void qcd() {
   
  setTDRStyle();

  std::vector<double> bins;
  bins.push_back(275.);
  bins.push_back(325.);
  for ( int i = 0; i < 6; ++i ) { bins.push_back(375.+100.*i); }

  std::vector<double> widths;
  widths.push_back(25.);
  widths.push_back(25.);
  for ( int i = 0; i < 6; ++i ) { widths.push_back(50.); }

  std::vector<double> effs;
  effs.push_back(1.13);
  effs.push_back(0.83);
  effs.push_back(0.72);
  effs.resize(8,0.84);
//   effs.push_back(0.84);
//   effs.push_back(1.13);
//   effs.push_back(1.32);
//   effs.push_back(1.41);
//   effs.push_back(2.09);

  std::vector<double> errs;
  errs.push_back(0.34);
  errs.push_back(0.24);
  errs.push_back(0.19);
  errs.resize(8,0.14);
//   errs.push_back(0.14);
//   errs.push_back(0.24);
//   errs.push_back(0.35);
//   errs.push_back(0.50);
//   errs.push_back(0.80);

  std::vector<double> entries;
  entries.push_back(46272.);
  entries.push_back(43592.);
  entries.push_back(58746.);
  entries.push_back(78644.);
  entries.push_back(29516.);
  entries.push_back(11668.);
  entries.push_back(5416.);
  entries.push_back(5368.);

  std::vector<double> prescales;
  prescales.push_back(2000.);
  prescales.push_back(1000.);
  prescales.push_back(500.);
  prescales.push_back(125.);
  prescales.push_back(125.);
  prescales.push_back(125.);
  prescales.push_back(125.);
  prescales.push_back(125.);
  
  TCanvas* c = new TCanvas("tmp","tmp",900,600);
  
  TGraphAsymmErrors* gr1 = new TGraphAsymmErrors(8);
  gr1->SetName("Graph1");
  gr1->SetTitle("");
  gr1->SetFillColor(1);
  gr1->SetLineWidth(2);
  gr1->SetMarkerStyle(24);
  gr1->SetMarkerColor(1);
  gr1->SetMarkerSize(2.);

  TGraphAsymmErrors* gr2 = new TGraphAsymmErrors(8);
  gr2->SetName("Graph2");
  gr2->SetTitle("");
  gr2->SetFillColor(1);
  gr2->SetLineWidth(2);
  gr2->SetMarkerStyle(20);
  gr1->SetMarkerColor(1);
  gr2->SetMarkerSize(1.5);

  for ( int i = 0; i < bins.size(); ++i ) {
    double x = bins[i]+widths[i];
    double y = entries[i]*prescales[i];
    double ex = widths[i];
    double ey = sqrt(entries[i])*prescales[i];
    
    gr1->SetPoint(i+1,x,y);
    gr1->SetPointError(i+1,0.,0.,ey,ey);

    y = y / effs[i];
    ey = y * sqrt( (ey/y)*(ey/y) + (errs[i]/effs[i])*(errs[i]/effs[i]) );
    
    gr2->SetPoint(i+1,x,y);
    gr2->SetPointError(i+1,ex,ex,ey,ey);

    std::cout << " HT= " << bins[i] << " yield= " << y << " +/- " << ey << std::endl; 
 
  }
  
  TMultiGraph* mg = new TMultiGraph();
  mg->Add(gr1,"p");
  mg->Add(gr2,"p");
  mg->Draw("ap");
  mg->GetXaxis()->SetTitle("H_{T} (GeV)");
  mg->GetYaxis()->SetTitle("Bulk yields");
  mg->GetYaxis()->SetRangeUser(1.e5,1.e9);
  mg->GetXaxis()->SetRangeUser(275.,975.);

  TF1* fit = new TF1("fit","expo",275.,875.);
  gr2->Fit(fit,"R");
  fit->Draw("same");
  
  TLegend* leg = new TLegend( 0.45, 0.70, 0.85, 0.80 );
  leg->SetFillColor(0);
  leg->SetLineColor(0); 
  leg->SetShadowColor(0); 
  leg->SetTextSize(0.035);
  leg->AddEntry(gr1,"Raw counts weighted by prescales","p");
  leg->AddEntry(gr2,"Trigger efficiency corrected","p");
  leg->Draw("same");

  std::stringstream sss;
  sss << "CMS, 1.5 fb^{-1}, #sqrt{s} = 8 TeV";
  TLatex* tex = new TLatex(0.17,0.88,sss.str().c_str());
  tex->SetNDC();
  tex->SetTextSize(0.035);
  tex->Draw();

  c->SetLogy();

  return;
  
}
Beispiel #5
0
void fastEfficiencyNadir(unsigned int iEG, int iECAL1, int iColl1, int iECAL2, int iColl2,
			 TString dirIn="/home/llr/cms/ndaci/SKWork/macro/skEfficiency/tagAndProbe/EfficiencyStudy/SingEle-May10ReReco/UPDATE2/Tag80Probe95/", 
			 TString lumi="200 pb", int nCPU=4, 
			 int color1=kBlack, int style1=kFullCircle, int color2=kRed, int style2=kOpenSquare,
			 TString probe="WP80", TString tag="WP80", TString fileIn="tree_effi_TagProbe.root")
{
  // STYLE //
  gROOT->Reset();
  loadPresentationStyle();  
  gROOT->ForceStyle();

  // EG THRESHOLDS //
  const int nEG = 71;
  double thres[nEG];
  for(int i=0 ; i<nEG ; i++) thres[i]=i;

  TString names[nEG];
  ostringstream ossi;
  for(int i=0;i<(int)nEG;i++) {
    ossi.str("");
    ossi << thres[i] ;
    names[i] = ossi.str();
  }

  // NAMES //
  const int nECAL=2;
  const int nColl=2;

  TString name_leg_ecal[nECAL] = {"Barrel","Endcaps"};
  TString name_leg_coll[nColl] = {"Online","Emulation"};  

  TString name_ecal[nECAL] = {"_EB","_EE"};
  TString name_coll[nColl] = {"_N","_M"};

  TString dirResults = dirIn + "/turnons/EG"+names[iEG]+"/" ;
  TString name_image = 
    dirResults + "eff_EG"+names[iEG]+"_tag"+tag+"_probe"+probe+name_ecal[iECAL1]+name_coll[iColl1]+"_vs"+name_ecal[iECAL2]+name_coll[iColl2] ;

  // Output log //
  ofstream fichier(name_image+".txt", ios::out);


  // BINNING //
  const int nbins[nEG] = {29,29,29,29,21,21,21,22,22,21,22,21,22,18,19,18,18,18,18,20,20,20,20,19,20,20,20,20,21,21,
			  21,21,21,21,21,21,21,21,21,21, //EG30
			  22,22,22,22,22,22,22,22,22,22, //EG40
			  29,29,29,29,29,29,29,29,29,29, //EG50
			  29,29,29,29,29,29,29,29,29,29};//EG60

  Double_t bins_0[29] = {1,1.5,1.8,2,2.2,2.4,2.6,2.8, 3, 3.5, 4,4.2,4.5,4.7,5,5.5,6,6.5,7,7.5,8,8.5,9,10,12,15,20,50,150};// EG0
  Double_t bins_1[29] = {1,1.5,1.8,2,2.2,2.4,2.6,2.8, 3, 3.5, 4,4.2,4.5,4.7,5,5.5,6,6.5,7,7.5,8,8.5,9,10,12,15,20,50,150};// EG1
  Double_t bins_2[29] = {1,1.5,1.8,2,2.2,2.4,2.6,2.8, 3, 3.5, 4,4.2,4.5,4.7,5,5.5,6,6.5,7,7.5,8,8.5,9,10,12,15,20,50,150};// EG2 
  Double_t bins_3[29] = {1,1.5,1.8,2,2.2,2.4,2.6,2.8, 3, 3.5, 4,4.2,4.5,4.7,5,5.5,6,6.5,7,7.5,8,8.5,9,10,12,15,20,50,150};// EG3

  Double_t bins_4[21] = {1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 15, 17, 19, 21, 27, 32, 41, 50, 60, 70, 150}; // EG4
  Double_t bins_5[21] = {2, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 31, 40, 50, 60, 70, 150}; // EG5
  Double_t bins_6[21] = {3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 17, 19, 21, 23, 27, 32, 41, 50, 60, 70, 150}; // EG6

  Double_t bins_7[22] = {2, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 31, 40, 50, 60, 70, 150}; // EG7
  Double_t bins_8[22] = {3, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 21, 23, 25, 27, 32, 41, 50, 60, 70, 150}; // EG8
  Double_t bins_9[21] = {4, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 31, 40, 50, 60, 70, 150}; // EG9

  Double_t bins_10[22] = {5, 7, 8, 9, 10, 11, 12, 13, 15, 17, 19, 21, 23, 25, 27, 29, 32, 41, 50, 60, 70, 150}; // EG10
  Double_t bins_11[21] = {6, 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 26, 28, 31, 40, 50, 60, 70, 150}; // EG11
  Double_t bins_12[22] = {5, 7, 9, 10, 11, 12, 13, 14, 15, 17, 19, 21, 23, 25, 27, 29, 32, 41, 50, 60, 70, 150}; // EG12

  Double_t bins_13[18] = {5, 7, 9, 11, 12, 13, 14, 15, 17, 19, 22, 25, 29, 37, 50, 60, 70, 150}; // EG13
  Double_t bins_14[19] = {6, 8, 10, 12, 13, 14, 15, 16, 18, 20, 22, 25, 30, 35, 40, 50, 60, 70, 150}; // EG14
  Double_t bins_15[18] = {5, 7, 9, 11, 13, 14, 15, 16, 17, 19, 22, 25, 29, 37, 50, 60, 70, 150}; // EG15

  Double_t bins_16[18] = {8, 10, 12, 14, 16, 17, 18, 19, 20, 22, 25, 30, 35, 40, 50, 60, 70, 150}; // EG16
  Double_t bins_17[18] = {9, 11, 13, 15, 16, 17, 18, 19, 21, 23, 25, 30, 35, 40, 50, 60, 70, 150}; // EG17
  Double_t bins_18[18] = {8, 10, 12, 14, 16, 17, 18, 19, 20, 22, 25, 30, 35, 40, 50, 60, 70, 150}; // EG18

  Double_t bins_19[20] = {9, 11, 13, 15, 17, 18, 19, 20, 21, 23, 25, 27, 30, 35, 40, 45, 50, 60, 70, 150}; // EG19
  Double_t bins_20[20] = {8, 10, 12, 14, 16, 18, 19, 20, 21, 22, 24, 26, 30, 35, 40, 45, 50, 60, 70, 100}; // EG20
  Double_t bins_21[20] = {9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 25, 27, 30, 35, 40, 45, 50, 60, 70, 150}; // EG21

  Double_t bins_22[20] = {10, 12, 14, 16, 18, 20, 21, 22, 23, 24, 26, 28, 30, 35, 40, 45, 50, 60, 70, 150}; // EG22
  Double_t bins_23[19] = {11, 13, 15, 17, 19, 21, 22, 23, 24, 25, 27, 30, 35, 40, 45, 50, 60, 70, 150}; // EG23
  Double_t bins_24[20] = {10, 12, 14, 16, 18, 20, 22, 23, 24, 25, 26, 28, 30, 35, 40, 45, 50, 60, 70, 150}; // EG24

  Double_t bins_25[20] = {11, 13, 15, 17, 19, 21, 23, 24, 25, 26, 27, 29, 30, 35, 40, 45, 50, 60, 70, 150}; // EG25
  Double_t bins_26[20] = {10, 12, 14, 16, 18, 20, 22, 24, 25, 26, 27, 28, 30, 35, 40, 45, 50, 60, 70, 150}; // EG26
  Double_t bins_27[20] = {11, 13, 15, 17, 19, 21, 23, 25, 26, 27, 28, 29, 33, 35, 40, 45, 50, 60, 70, 150}; // EG27

  Double_t bins_28[21] = {10, 12, 14, 16, 18, 20, 22, 24, 26, 27, 28, 29, 30, 32, 35, 40, 45, 50, 60, 70, 150}; // EG28
  Double_t bins_29[21] = {11, 13, 15, 17, 19, 21, 23, 25, 27, 28, 29, 30, 31, 33, 35, 40, 45, 50, 60, 70, 150}; // EG29
  Double_t bins_30[21] = {10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 29, 30, 31, 32, 35, 40, 45, 50, 60, 70, 150}; // EG30

  Double_t bins_40[22] = {10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 38, 39, 40, 42, 45, 50, 60, 70, 150}; // EG40
  Double_t bins_50[29] = {10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 48, 50, 55, 60, 70, 90, 110, 130, 150, 170, 190}; // EG50
  Double_t bins_60[29] = {10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 48, 50, 55, 60, 70, 90, 110, 130, 150, 170, 190}; // EG60

  vector< Double_t* > bins;
  bins.push_back( bins_0 ); bins.push_back( bins_1 ); bins.push_back( bins_2 ); bins.push_back( bins_3 ); bins.push_back( bins_4 ); 
  bins.push_back( bins_5 ); bins.push_back( bins_6 ); bins.push_back( bins_7 ); bins.push_back( bins_8 ); bins.push_back( bins_9 ); 
  bins.push_back( bins_10 ); bins.push_back( bins_11 ); bins.push_back( bins_12 ); bins.push_back( bins_13 ); bins.push_back( bins_14 ); 
  bins.push_back( bins_15 ); bins.push_back( bins_16 ); bins.push_back( bins_17 ); bins.push_back( bins_18 ); bins.push_back( bins_19 ); 
  bins.push_back( bins_20 ); bins.push_back( bins_21 ); bins.push_back( bins_22 ); bins.push_back( bins_23 ); bins.push_back( bins_24 ); 
  bins.push_back( bins_25 ); bins.push_back( bins_26 ); bins.push_back( bins_27 ); bins.push_back( bins_28 ); bins.push_back( bins_29 ); 

  for(int iV=0 ; iV<10 ; iV++) bins.push_back( bins_30 );
  for(int iV=0 ; iV<10 ; iV++) bins.push_back( bins_40 );
  for(int iV=0 ; iV<10 ; iV++) bins.push_back( bins_50 );
  for(int iV=0 ; iV<10 ; iV++) bins.push_back( bins_60 );

  RooBinning binning = RooBinning(nbins[iEG]-1, bins[iEG], "binning");


  // INPUT DATA //
  TFile* f1 = TFile::Open(dirIn+"/"+fileIn);

  TTree* treenew;
  TTree* treenew_2;

  treenew = (TTree*) gDirectory->Get( "treenew"+name_ecal[iECAL1]+name_coll[iColl1] ) ;
  treenew_2 = (TTree*) gDirectory->Get( "treenew"+name_ecal[iECAL2]+name_coll[iColl2] ) ;

  TString name_scet[2], name_scdr[2], name_l1bin[2];
  name_scet[0] = "sc_et"+name_ecal[iECAL1]+name_coll[iColl1];
  name_scet[1] = "sc_et"+name_ecal[iECAL2]+name_coll[iColl2];
  name_scdr[0] = "sc_dr"+name_ecal[iECAL1]+name_coll[iColl1];
  name_scdr[1] = "sc_dr"+name_ecal[iECAL2]+name_coll[iColl2];
  
  name_l1bin[0] = "l1_"+names[iEG]+name_ecal[iECAL1]+name_coll[iColl1];
  name_l1bin[1] = "l1_"+names[iEG]+name_ecal[iECAL2]+name_coll[iColl2];

  RooRealVar et_plot(name_scet[0],name_scet[0],0,150) ;
  RooRealVar dr(name_scdr[0],name_scdr[0],0.5,1.5) ; 
  RooRealVar et_plot2(name_scet[1],name_scet[1],0,150) ;
  RooRealVar dr2(name_scdr[1],name_scdr[1],0.5,1.5) ;

  // Acceptance state cut (1 or 0)
  RooCategory cut(name_l1bin[0],name_l1bin[0]) ;
  cut.defineType("accept",1) ;
  cut.defineType("reject",0) ;
  RooCategory cut2(name_l1bin[1],name_l1bin[1]) ;
  cut2.defineType("accept",1) ;
  cut2.defineType("reject",0) ;
  
  // PARAMETRES ROOFIT CRYSTAL BALL
  RooRealVar norm("norm","N",1,0.6,1);
  RooRealVar alpha("alpha","#alpha",0.671034,0.01,8);
  RooRealVar n("n","n",4.07846,1.1,35);
  RooRealVar mean("mean","mean",20.8,0,100);
  //mean.setVal(thres[iEG]);
  RooRealVar sigma("sigma","#sigma",0.972825,0.01,5);
  //RooRealVar pedestal("pedestal","pedestal",0.01,0,0.4);

  RooRealVar norm2("norm2","N",0.999069,0.6,1);
  RooRealVar alpha2("alpha2","#alpha",0.492303,0.01,8);
  RooRealVar n2("n2","n",11.6694,1.1,35);
  RooRealVar mean2("mean2","mean",21.4582,0,100);
  //mean2.setVal(thres[iEG]);
  RooRealVar sigma2("sigma2","#sigma",1.19,0.01,5);
  //RooRealVar pedestal2("pedestal2","pedestal",0.01,0,0.4);

  FuncCB cb("cb","Crystal Ball Integree",et_plot,mean,sigma,alpha,n,norm) ;
  FuncCB cb2("cb2","Crystal Ball Integree",et_plot2,mean2,sigma2,alpha2,n2,norm2) ;
  
  // EFFICIENCY //
  RooEfficiency eff("eff","efficiency",cb,cut,"accept");
  RooEfficiency eff2("eff2","efficiency",cb2,cut2,"accept");

  // DATASETS //
  RooDataSet dataSet("data","data",RooArgSet(et_plot, cut,dr),Import(*treenew)); 
  RooDataSet dataSet2("data2","data2",RooArgSet(et_plot2, cut2,dr2),Import(*treenew_2));

  dataSet.Print();
  dataSet2.Print();
  
  // PLOT //
  RooPlot* frame = et_plot.frame(Bins(18000),Title("Fitted efficiency")) ;
  RooPlot* frame2 = et_plot2.frame(Bins(18000),Title("Fitted efficiency")) ;

  dataSet.plotOn(frame, Binning(binning), Efficiency(cut), MarkerColor(color1), LineColor(color1), MarkerStyle(style1) );
  dataSet2.plotOn(frame2, Binning(binning), Efficiency(cut2), MarkerColor(color2), LineColor(color2), MarkerStyle(style2) );


  /////////////////////// FITTING /////////////////////////////

  double fit_cuts_min = thres[iEG]-1.5 ;
  double fit_cuts_max = 150;

  et_plot.setRange("interesting",fit_cuts_min,fit_cuts_max);
  et_plot2.setRange("interesting",fit_cuts_min,fit_cuts_max);

  RooFitResult* roofitres1 = new RooFitResult("roofitres1","roofitres1");
  RooFitResult* roofitres2 = new RooFitResult("roofitres2","roofitres2");

  fichier << "Fit characteristics :"   << endl ;
  fichier << "EG "     << names[iEG] << endl ;
  fichier << "Fit Range , EB Coll : [" << fit_cuts_min << "," << fit_cuts_max << "]" << endl ;
  fichier << "Fit Range , EE Coll : [" << fit_cuts_min << "," << fit_cuts_max << "]" << endl ;
  fichier << "----------------------"  << endl ;

  // Fit #1 //
  roofitres1 = eff.fitTo(dataSet,ConditionalObservables(et_plot),Range("interesting"),Minos(kTRUE),Warnings(kFALSE),NumCPU(nCPU),Save(kTRUE));
  
  cb.plotOn(frame,LineColor(color1),LineWidth(2));

  double res_norm1  = norm.getVal();
  double err_norm1  = norm.getErrorLo();
  double res_mean1  = mean.getVal();
  double err_mean1  = mean.getError();
  double res_sigma1 = sigma.getVal();
  double err_sigma1 = sigma.getError();
  double res_n1     = n.getVal();
  double err_n1     = n.getError();
  double res_alpha1 = alpha.getVal();
  double err_alpha1 = alpha.getError();

  fichier << "<----------------- EB ----------------->" << endl
	  << "double res_mean="  << res_mean1  << "; "
	  << "double res_sigma=" << res_sigma1 << "; "
          << "double res_alpha=" << res_alpha1 << "; "
          << "double res_n="     << res_n1     << "; "
          << "double res_norm="  << res_norm1  << "; "
	  << endl
	  << "double err_mean="  << err_mean1  << "; "
	  << "double err_sigma=" << err_sigma1 << "; "
          << "double err_alpha=" << err_alpha1 << "; "
          << "double err_n="     << err_n1     << "; "
          << "double err_norm="  << err_norm1  << "; "
	  << endl;

  // Fit #2 //
  roofitres2 = eff2.fitTo(dataSet2,ConditionalObservables(et_plot2),Range("interesting"),Minos(kTRUE),Warnings(kFALSE),NumCPU(nCPU),Save(kTRUE));
 
  cb2.plotOn(frame2,LineColor(color2),LineWidth(2));

  double res_norm2  = norm2.getVal();
  double err_norm2  = norm2.getErrorLo();
  double res_mean2  = mean2.getVal();
  double err_mean2  = mean2.getError();
  double res_sigma2 = sigma2.getVal();
  double err_sigma2 = sigma2.getError();
  double res_n2     = n2.getVal();
  double err_n2     = n2.getError();
  double res_alpha2 = alpha2.getVal();
  double err_alpha2 = alpha2.getError();

  fichier << "<----------------- EE ----------------->" << endl
	  << "double res_mean="  << res_mean2  << "; "
	  << "double res_sigma=" << res_sigma2 << "; "
	  << "double res_alpha=" << res_alpha2 << "; "
	  << "double res_n="     << res_n2     << "; "
	  << "double res_norm="  << res_norm2  << "; "
	  << endl
	  << "double err_mean="  << err_mean2  << "; "
	  << "double err_sigma=" << err_sigma2 << "; "
	  << "double err_alpha=" << err_alpha2 << "; "
	  << "double err_n="     << err_n2     << "; "
	  << "double err_norm="  << err_norm2  << "; "
	  << endl;
    

  ////////////////////////////  DRAWING PLOTS AND LEGENDS /////////////////////////////////
  TCanvas* ca = new TCanvas("ca","Trigger Efficiency") ;

  ca->SetGridx();
  ca->SetGridy();
  ca->cd();
  
  gPad->SetLogx();
  gPad->SetObjectStat(1);

  frame->GetYaxis()->SetRangeUser(0,1.05);
  frame->GetXaxis()->SetRangeUser(1,100.);
  frame->GetYaxis()->SetTitle("Efficiency");
  frame->GetXaxis()->SetTitle("E_{T} [GeV]");
  frame->Draw() ;

  frame2->GetYaxis()->SetRangeUser(0,1.05);
  frame2->GetXaxis()->SetRangeUser(1,100.);
  frame2->GetYaxis()->SetTitle("Efficiency");
  frame2->GetXaxis()->SetTitle("E_{T} [GeV]");
  frame2->Draw("same") ;

  TH1F *SCeta1 = new TH1F("SCeta1","SCeta1",50,-2.5,2.5);
  TH1F *SCeta2 = new TH1F("SCeta2","SCeta2",50,-2.5,2.5);

  SCeta1->SetLineColor(color1) ;
  SCeta1->SetMarkerColor(color1);
  SCeta1->SetMarkerStyle(style1);

  SCeta2->SetLineColor(color2) ;
  SCeta2->SetMarkerColor(color2);
  SCeta2->SetMarkerStyle(style2);

  TLegend *leg = new TLegend(0.246,0.435,0.461,0.560,NULL,"brNDC"); // mid : x=353.5
  leg->SetLineColor(1);
  leg->SetTextColor(1);
  leg->SetTextFont(42);
  leg->SetTextSize(0.03);
  leg->SetShadowColor(kWhite);
  leg->SetFillColor(kWhite);
  leg->SetMargin(0.25);
  TLegendEntry *entry=leg->AddEntry("NULL","L1_SingleEG"+names[iEG],"h");
//   leg->AddEntry(SCeta1,name_leg_ecal[iECAL1]+" "+name_leg_coll[iColl1],"p");
//   leg->AddEntry(SCeta2,name_leg_ecal[iECAL2]+" "+name_leg_coll[iColl2],"p");
  leg->AddEntry(SCeta1,name_leg_ecal[iECAL1],"p");
  leg->AddEntry(SCeta2,name_leg_ecal[iECAL2],"p");
  leg->Draw();

  leg = new TLegend(0.16,0.725,0.58,0.905,NULL,"brNDC");
  leg->SetBorderSize(0);
  leg->SetTextFont(62);
  leg->SetTextSize(0.03);
  leg->SetLineColor(0);
  leg->SetLineStyle(1);
  leg->SetLineWidth(1);
  leg->SetFillColor(0);
  leg->SetFillStyle(0);
  leg->AddEntry("NULL","CMS Preliminary 2012 pp  #sqrt{s}=8 TeV","h");
  leg->AddEntry("NULL","#int L dt = "+lumi+"^{-1}","h");
  leg->AddEntry("NULL","Threshold : "+names[iEG]+" GeV","h");
  leg->Draw();

  TPaveText *pt2 = new TPaveText(0.220,0.605,0.487,0.685,"brNDC"); // mid : x=353.5                                          
  pt2->SetLineColor(1);
  pt2->SetTextColor(1);
  pt2->SetTextFont(42);
  pt2->SetTextSize(0.03);
  pt2->SetFillColor(kWhite);
  pt2->SetShadowColor(kWhite);
  pt2->AddText("L1 E/Gamma Trigger");
  pt2->AddText("Electrons from Z");
  pt2->Draw();
  
  //TString name_image="eff_EG20_2012_12fb";

  ca->Print(name_image+".cxx","cxx");
  ca->Print(name_image+".png","png");
  ca->Print(name_image+".gif","gif");
  ca->Print(name_image+".pdf","pdf");
  ca->Print(name_image+".ps","ps");
  ca->Print(name_image+".eps","eps");

  /////////////////////////////
  // SAVE THE ROO FIT RESULT //
  /////////////////////////////

  RooWorkspace *w = new RooWorkspace("workspace","workspace") ;

  w->import(dataSet);
  w->import(dataSet2);
  
  w->import(*roofitres1,"roofitres1");
  w->import(*roofitres2,"roofitres2");

  cout << "CREATES WORKSPACE : " << endl;
  w->Print();
  
  w->writeToFile(name_image+"_fitres.root") ;
  //gDirectory->Add(w) ;

  //f1->Close();
}
void plot_golfcourse_Asymptotic(bool unblind){

  bool useNewStyle=true;
  if(useNewStyle)  setFPStyle();

  TFile *fFREQ=new TFile("higgsCombineEXOZZ.Asymptotic.TOTAL.root","READ");

  TTree *t=(TTree*)fFREQ->Get("limit");

  double mh,limit;
  float quant;
  t->SetBranchAddress("mh",&mh);
  t->SetBranchAddress("limit",&limit);
  t->SetBranchAddress("quantileExpected",&quant);

  //1st loop on tree for preparing mH ordered list
  vector<double> v_mhTMP;
  for(int i=0;i<t->GetEntries();i++){
    t->GetEntry(i);
    if(quant>-1.01&&quant<-0.99){
      v_mhTMP.push_back(mh);
    }
  }
  std::sort(v_mhTMP.begin(),v_mhTMP.end());

  int nMH=v_mhTMP.size();
  int iMH=0;
  vector<double> v_mh, v_median,v_68l,v_68h,v_95l,v_95h, v_obs;
  while(iMH<nMH){
    double mhTMP=v_mhTMP.at(iMH);
    for(int i=0;i<t->GetEntries();i++){
      // int i=j;
      // if(j==t->GetEntries())i=0;
      t->GetEntry(i);
      //cout<<"i "<<i<<flush<<"  m = "<<mh<<endl;
      // if(mh==600)cout<<"$$$$$$$$$ TREE 600 $$$$$$$$$$$$$$"<<endl;

      if(mh!=mhTMP)continue;//follow exactly the order of v_mhTMP

      if(quant>-1.01&&quant<-0.99){
	v_obs.push_back(limit);
	v_mh.push_back(mh);
      }
      else if(quant>0.02&&quant<0.03)v_95l.push_back(limit);
      else if(quant>0.15&&quant<0.17)v_68l.push_back(limit);
      else if(quant>0.49&&quant<0.51)v_median.push_back(limit);
      else if(quant>0.83&&quant<0.85)v_68h.push_back(limit);
      else if(quant>0.965&&quant<0.98){
	//   cout<<"95% -> at M="<<mh<<" I found "<<limit<<endl;
	v_95h.push_back(limit);
      }

      else {cout<<"Error! Quantile =  "<<quant<<endl;}
    }
    iMH++;
  }//end while loop
  cout<<"Out of the loop !"<<endl;
  ////////////////////////////////////////
  ///
 //read in theoretical values from text files
  // bool   applyExtraTherUnc=true;
  string xsect_file_th="../../../data/xsect_BulkG_ZZ_c0p5_xsect_in_pb.txt";
  if(!isZZChannel)xsect_file_th="../../../data/xsect_BulkG_WW_c0p5_xsect_in_pb.txt";
  //  make_interpolated_xsect(xsect_file_th, xsect_file_interpol);
  // string xsect_file_interpol="./RSGravXSectTimesBRToZZ_AgasheHapola_c10_EXPOINTERP.txt";
 
  ifstream xsect_file(xsect_file_th.c_str(),ios::in);
  if (! xsect_file.is_open()){ cout<<"Failed to open file with xsections"<<endl;}
  float mH, CS;
 

  vector<float> v_mhxs, v_xs,  v_brzz2l2q,v_toterrh,v_toterrl;
  while(xsect_file.good()){
    xsect_file >> mH>> CS;
    if(mH==1200)cout<<"~~~~~ 1200 theor ~~~~~~~~~~~~~"<<endl;
    if(mH<600.0)continue;
    v_mhxs.push_back(mH);
    v_xs.push_back(CS);//*BRZZ2l2q (multyply by BRZZ2l2q only if exp rates in cards are for process X->ZZ->2l2q !)
   
    //unavailable theor errors for graviton   

    float tot_err_p=0.0;
    float tot_err_m=0.0;
 
    v_toterrh.push_back(1.0+(tot_err_p));
    v_toterrl.push_back(1.0-(tot_err_m));
  }
  cout<<"Size of theor "<<v_mhxs.size()<<endl;
  xsect_file.close();

  string xsect_file_interpol2="../../../data/xsect_BulkG_ZZ_c0p2_xsect_in_pb.txt";
  if(!isZZChannel)xsect_file_interpol2="../../../data/xsect_BulkG_WW_c0p2_xsect_in_pb.txt";
  ifstream xsect_file2(xsect_file_interpol2.c_str(),ios::in);
  if (! xsect_file2.is_open()){ cout<<"Failed to open file with xsections (c=0.10)"<<endl;}
  float mH2,CS10;
 
  vector<float>  v_xs10;
  while(xsect_file2.good()){
    xsect_file2 >> mH2>> CS10;
    if(mH2==975)cout<<"~~~~~ 975 theor ~~~~~~~~~~~~~"<<endl;
    if(mH2<600.0)continue;
    v_xs10.push_back(CS10);//*BRZZ2l2q
   
    //unavailable theor errors for graviton   
    float tot_err_p=0.0;
    float tot_err_m=0.0;
 
    //    v_toterrh.push_back(1.0+(tot_err_p));
    //  v_toterrl.push_back(1.0-(tot_err_m));
  }
  cout<<"Size of theor "<<v_xs10.size()<<endl;
  xsect_file2.close();
  //
  //END THEOR INPUT PART
  ///////////////

  const int nMass= v_mh.size();
  double mass[nMass],mass1[nMass],obs_lim_cls[nMass]; 
  double medianD[nMass];
  double up68err[nMass],down68err[nMass],up95err[nMass],down95err[nMass];
  double xs[nMass], xs_uperr[nMass], xs_downerr[nMass];
  double xs10[nMass], xs10_uperr[nMass], xs10_downerr[nMass];
  int nMassEff=0,nMassEff1=0;
  int nM95=0;
  double mass95[nMass],median95[nMass];
  int nexcluded=0;
  bool excl; 
  for(int im=0;im<nMass;im++){
    if( mass[nMassEff-1]>1600.) cout<<"Array "<<im<<flush<<"  m = "<<v_mh.at(im)<<endl;;
    //protection against messed up jobs
    excl=false;
    if(v_68h.at(im)>=v_95h.at(im) || v_68l.at(im)<=v_95l.at(im) ){
      cout<<"Point at M = "<<v_mh.at(im) <<" excluded: "<<v_95l.at(im)<<"  "<<v_68l.at(im)<<"  "<<v_median.at(im)<<"  "<<v_68h.at(im)<<"  "<<v_95h.at(im)<< endl;
      nexcluded++;
      // continue;
      excl=true; 
    }
    //    if(im%2==1)excl=true;//sample only one half of the points

    //search for right index in theor vectors
    bool found=false;
    int indtmp=0,ind=-1;
    while(!found){
      if(v_mhxs.at(indtmp)==v_mh.at(im)){found=true;ind=indtmp;}
      indtmp++;
      if(indtmp==v_mhxs.size()){
	cout<<"!!! m="<<flush<<v_mh.at(im)<<" NOT found in theor matrix."<<endl;
	break;
      }
    }//end while    
   
  

    if(!found){
      cout<<"(2) m="<<v_mh.at(im)<<" NOT found in theor matrix."<<endl;
      continue;
    }

  
    double fl_xs=double(v_xs.at(ind));//*1000.0
    double fl_xs10=double(v_xs10.at(ind));//*1000.0
   
    if(fl_xs<fl_xs10)cout<<"WARNING ABOUT XSECT! XS="<<fl_xs<<"  XS10="<<fl_xs10<<endl;

    mass[nMassEff]=v_mh.at(im);
    //if( mass[nMassEff]==600.0)cout<<"=============> 600 !!!"<<endl;
    obs_lim_cls[nMassEff]=v_obs.at(im)*fl_xs;
    nMassEff++;
    if(!excl){
      mass1[nMassEff1]=v_mh.at(im);
      medianD[nMassEff1]=v_median.at(im)*fl_xs;
      up68err[nMassEff1]=(v_68h.at(im)-v_median.at(im))*fl_xs;
      down68err[nMassEff1]=(v_median.at(im)-v_68l.at(im))*fl_xs;
      cout<<"M="<<mass1[nMassEff1]<<"  Median="<<medianD[nMassEff1]<<endl;
      
      //scale factor 100 for making the xsect visible
      xs[nMassEff1]=fl_xs;//*100.0;
      xs_uperr[nMassEff1]=double( v_toterrh.at(ind))*xs[nMassEff1]- xs[nMassEff1];
      xs_downerr[nMassEff1]=  xs[nMassEff1]- double( v_toterrl.at(ind))* xs[nMassEff1];

      xs10[nMassEff1]=fl_xs10;//*100.0;
      xs10_uperr[nMassEff1]=double( v_toterrh.at(ind))*xs10[nMassEff1]- xs10[nMassEff1];
      xs10_downerr[nMassEff1]=  xs10[nMassEff1]- double( v_toterrl.at(ind))* xs10[nMassEff1];
    
      //cout<<"Theor err on 4g for M="<<mass[nMassEff]<<"  "<< ggxs4g_downerr[nMassEff] << "  "<<ggxs4g_uperr[nMassEff]<<endl;
      nMassEff1++;
      

      bool skip95= false;//
      //     skip95=v_mh.at(im)==204||v_mh.at(im)==208||v_mh.at(im)==212||v_mh.at(im)==214|| v_mh.at(im)==232 || v_mh.at(im)==240  || v_mh.at(im)==240 || v_mh.at(im)==244 || v_mh.at(im)==252 || v_mh.at(im)==264 || v_mh.at(im)==272 || v_mh.at(im)==288 ;
      //  skip95=false;
      
      if(skip95 )continue;
      mass95[nM95]=v_mh.at(im);
      median95[nM95]=v_median.at(im)*fl_xs;
      up95err[nM95]=(v_95h.at(im)-v_median.at(im))*fl_xs;
      down95err[nM95]=(v_median.at(im)-v_95l.at(im))*fl_xs;
   
      //  cout<<"M95: "<< mass95[nM95]<<" "<<median95[nM95]<<" +"<<up95err[nM95]<<"   -"<< down95err[nM95]<<
      //	" ("<<v_95h.at(im) <<" - "<<v_median.at(im) <<")"<<endl;
      nM95++; 
    }//end if not excluded mass point
  }//end loop over im (mass points)
  cout<<"Excluded "<<nexcluded<<" sick mass points."<<endl;

  


  //  cout<<"Working on TGraph"<<endl;
  TGraphAsymmErrors *grobslim_cls=new TGraphAsymmErrors(nMassEff,mass,obs_lim_cls);
  grobslim_cls->SetName("LimitObservedCLs");
  TGraphAsymmErrors *grmedian_cls=new TGraphAsymmErrors(nMassEff1,mass1,medianD);
  grmedian_cls->SetName("LimitExpectedCLs");
  TGraphAsymmErrors *gr68_cls=new TGraphAsymmErrors(nMassEff1,mass1,medianD,0,0,down68err,up68err);
  gr68_cls->SetName("Limit68CLs");
  TGraphAsymmErrors *gr95_cls=new TGraphAsymmErrors(nM95,mass95,median95,0,0,down95err,up95err);
  gr95_cls->SetName("Limit95CLs");

  // TGraphAsymmErrors *grthSM=new TGraphAsymmErrors(nMassEff1,mass1,xs,0,0,0,0);//xs_downerr,xs_uperr);
  TGraph *grthSM=new TGraph(nMassEff1,mass1,xs);//xs_downerr,xs_uperr);
  grthSM->SetName("SMXSection");

  // TGraphAsymmErrors *grthSM10=new TGraphAsymmErrors(nMassEff1,mass1,xs10,0,0,0,0);
  TGraph *grthSM10=new TGraph(nMassEff1,mass1,xs10);
  grthSM10->SetName("SMXSection_2nd");
 
  // cout<<"Plotting"<<endl;
  double fr_left=590.0, fr_down=0.0005,fr_right=2020.0,fr_up=1.0;
  if(!isZZChannel){fr_left=1000.0, fr_down=0.0000005,fr_right=2500.0,fr_up=10.0;}
  TCanvas *cMCMC=new TCanvas("c_lim_Asymp","canvas with limits for Asymptotic CLs",630,600);
  cMCMC->cd();
  cMCMC->SetGridx(1);
  cMCMC->SetGridy(1);
  // draw a frame to define the range

  TH1F *hr = cMCMC->DrawFrame(fr_left,fr_down,fr_right,fr_up,"");
  TString VV = "ZZ";
  if(!isZZChannel)VV="WW";
  hr->SetXTitle("M_{1} [GeV]");
  hr->SetYTitle("#sigma_{95%} #times BR(G #rightarrow "+VV+") [pb]");// #rightarrow 2l2q
  // cMCMC->GetFrame()->SetFillColor(21);
  //cMCMC->GetFrame()->SetBorderSize(12);
  
  gr95_cls->SetFillColor(kYellow);
  gr95_cls->SetFillStyle(1001);//solid
  gr95_cls->SetLineStyle(kDashed);
  gr95_cls->SetLineWidth(3);
  gr95_cls->GetXaxis()->SetTitle("M_{1} [GeV]");
  gr95_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(G #rightarrow "+VV+") [pb]");// #rightarrow 2l2q
  gr95_cls->GetXaxis()->SetRangeUser(fr_left,fr_right);
  
  gr95_cls->Draw("3");
  
  gr68_cls->SetFillColor(kGreen);
  gr68_cls->SetFillStyle(1001);//solid
  gr68_cls->SetLineStyle(kDashed);
  gr68_cls->SetLineWidth(3);
  gr68_cls->Draw("3same");
  grmedian_cls->GetXaxis()->SetTitle("M_{1} [GeV]");
  grmedian_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(G #rightarrow "+VV+") [pb]");// #rightarrow 2l2q
  grmedian_cls->SetMarkerStyle(24);//25=hollow squre
  grmedian_cls->SetMarkerColor(kBlack);
  grmedian_cls->SetLineStyle(2);
  grmedian_cls->SetLineWidth(3);
  grmedian_cls->SetMinimum(0.0);
  grmedian_cls->SetMaximum(8.0);
 
  grobslim_cls->SetMarkerColor(kBlack);
  grobslim_cls->SetMarkerStyle(20);//24=hollow circle // 20 = solid circle
  grobslim_cls->SetMarkerSize(0.7);
  grobslim_cls->SetLineStyle(1);
  grobslim_cls->SetLineWidth(1);
  
  grthSM->SetLineColor(kRed);
  grthSM->SetLineWidth(2);
  grthSM->SetLineStyle(kSolid);
  grthSM->SetFillColor(kRed);
  grthSM->SetFillStyle(3344);

  grthSM10->SetLineColor(kRed);
  grthSM10->SetLineWidth(2);
  grthSM10->SetLineStyle(1);
  grthSM10->SetLineStyle(kDashed);
  grthSM10->SetFillColor(kRed);
  grthSM10->SetFillStyle(3344);

  grthSM->Draw("L3");
  grthSM10->Draw("L3");
  grmedian_cls->Draw("L");
  if(unblind)grobslim_cls->Draw("LP");

  /*
  TFile *fUnMPlus=new TFile("AsymptoticCLs_UnmatchedPlus_TGraph.root","READ");
  TGraph *grobs_ump=(TGraph*)fUnMPlus->Get("LimitObservedCLs");
  TGraph *grmedian_ump=(TGraph*)fUnMPlus->Get("LimitExpectedCLs");
  grobs_ump->SetName("LimitObs_UnmatchedPlus");
  grmedian_ump->SetName("LimitExp_UnmatchedPlus");
  grobs_ump->SetMarkerColor(kBlue);
  grobs_ump->SetLineColor(kBlue);
  grobs_ump->SetMarkerStyle(25);
  grmedian_ump->SetMarkerColor(kBlue);
  grmedian_ump->SetLineColor(kBlue);
  grmedian_ump->SetMarkerStyle(25);
  grobs_ump->Draw("P");
  grmedian_ump->Draw("L");
  */

 //draw grid on top of limits
  gStyle->SetOptStat(0);
  TH1D* postGrid = new TH1D("postGrid","",1,fr_left,fr_right);
  postGrid->GetYaxis()->SetRangeUser(fr_down,fr_up);
  postGrid->Draw("AXIGSAME");

  TLine *l1=new TLine();
  l1->SetLineStyle(1);
  l1->SetLineWidth(2.0);
  l1->SetLineColor(kRed);
  //  l1->DrawLine(200.0,1.0,600.0,1.0);
  //  cMCMC->Update();
  cMCMC->RedrawAxis("");
   gPad->RedrawAxis("");
  // hr->GetYaxis()->DrawClone();
   cMCMC->Update();
  


  //more graphics
  TLegend *leg = new TLegend(.46,.75,.94,.92);
  //   TLegend *leg = new TLegend(.35,.71,.90,.90);
   leg->SetFillColor(0);
   leg->SetShadowColor(0);
   leg->SetTextFont(42);
   leg->SetTextSize(0.025);
   //   leg->SetBorderMode(0);
   if(unblind)leg->AddEntry(grobslim_cls, "Asympt. CL_{S} Observed", "LP");
   leg->AddEntry(gr68_cls, "Asympt. CL_{S}  Expected #pm 1#sigma", "LF");
   leg->AddEntry(gr95_cls, "Asympt. CL_{S}  Expected #pm 2#sigma", "LF");
   leg->AddEntry(grthSM, "#sigma_{TH} x BR(G #rightarrow "+VV+"), #tilde{k}=0.50", "L" );// #rightarrow 2l2q
   leg->AddEntry(grthSM10, "#sigma_{TH} x BR(G #rightarrow "+VV+"), #tilde{k}=0.20", "L");// #rightarrow 2l2q
   leg->Draw();
   
 if(useNewStyle){
   TPaveText* cmslabel = new TPaveText( 0.145, 0.953, 0.6, 0.975, "brNDC");
   cmslabel->SetFillColor(kWhite);
   cmslabel->SetTextSize(0.038);
   cmslabel->SetTextAlign(11);
   cmslabel->SetTextFont(62);
   cmslabel->SetBorderSize(0);
   //   std::string leftText = "CMS Preliminary 2011";
   std::string leftText = "CMS";
   std::string units = "fb ^{-1}";
   char lumiText[300];
   sprintf( lumiText, "%.1f %s", intLumi, units.c_str());
   cmslabel->AddText(Form("%s,  #sqrt{s} = 8 TeV, %s", leftText.c_str(), lumiText));
   //cmslabel->Draw();

   TPaveText* label_sqrt = new TPaveText(0.4,0.953,0.96,0.975, "brNDC");
   label_sqrt->SetFillColor(kWhite);
   label_sqrt->SetBorderSize(0);
   label_sqrt->SetTextSize(0.038);
   label_sqrt->SetTextFont(62);   
   label_sqrt->SetTextAlign(31); // align right
   // label_sqrt->AddText("#sqrt{s} = 7 TeV");
   label_sqrt->AddText(Form("%s, L = %s at  #sqrt{s} = 8 TeV", leftText.c_str(), lumiText));
   label_sqrt->Draw();

   }
   else{

   TLatex * latex = new TLatex();
   latex->SetNDC();
   latex->SetTextSize(0.04);
   latex->SetTextAlign(31);
   latex->SetTextAlign(11); // align left 
   latex->DrawLatex(0.18, 0.96, "CMS preliminary 2012");
   latex->DrawLatex(0.60,0.96,Form("%.1f fb^{-1} at #sqrt{s} = 8 TeV",intLumi));
   
   }

   TLine *l1b=new TLine();
   l1b->SetLineStyle(1);
   l1b->SetLineWidth(2.0);
   l1b->SetLineColor(kRed);
   //l1b->DrawLine(200.0,1.0,600.0,1.0);
   cMCMC->Update();
   
   
   // cMCMC->RedrawAxis("");
   gPad->RedrawAxis("");
   // hr->GetYaxis()->DrawClone();
   cMCMC->Update();
   cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic.root");
   cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic.eps");
   cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic.png");
   gPad->SetLogy();
   cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic_log.eps");
   cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic_log.png");
   cMCMC->SaveAs("EXOZZ_2l2q_UL_Asymptotic_log.root");
  // cMCMC->SaveAs("ClsLimit_1fb.png");
   

   TFile *outfile=new TFile("AsymptoticCLs_TGraph.root","RECREATE");
   outfile->cd();
   if(unblind)grobslim_cls->Write();
   grmedian_cls->Write();
   outfile->Close();


}//end main
Beispiel #7
0
void Plot_1D_graphs(string filename){
 
  string varXname = "Test Pulse DAC";
  string varYname = "#bar{PDO}";

  int VMM = 4;

  vector<int> CH;
  CH.push_back(20);
  CH.push_back(22);
  CH.push_back(24);
  CH.push_back(26);
  CH.push_back(28);
  CH.push_back(30);
  
  vector<int> Value;
  vector<string> Label;

  Value.push_back(80);
  Label.push_back("Test Pulse DAC = 80");
  Value.push_back(100);
  Label.push_back("Test Pulse DAC = 100");
  Value.push_back(120);
  Label.push_back("Test Pulse DAC = 120");
  Value.push_back(140);
  Label.push_back("Test Pulse DAC = 140");
  Value.push_back(160);
  Label.push_back("Test Pulse DAC = 160");

  // Value.push_back(0);
  // Label.push_back("Delay Count = 0");
  // Value.push_back(1);
  // Label.push_back("Delay Count = 1");
  // Value.push_back(2);
  // Label.push_back("Delay Count = 2");
  // Value.push_back(3);
  // Label.push_back("Delay Count = 3");
  // Value.push_back(4);
  // Label.push_back("Delay Count = 4");

  ///////////////////////////////////////////////////////
  setstyle(0);
  
  TChain* tree = new TChain("MMFE8","MMFE8");

  tree->AddFile(filename.c_str());

  MMFE8Base* base = new MMFE8Base(tree);

  int N = tree->GetEntries();

  int Nval = Value.size();

  int Nch = CH.size();
  double Ntot[Nch][Nval];
  double X[Nval];
  double Xerr[Nval];
  double Y[Nch][Nval];
  double Yerr[Nch][Nval];
  
  for(int i = 0; i < Nval; i++){
    X[i] = Value[i];
    Xerr[i] = 0;
    for(int j = 0; j < Nch; j++){
      Ntot[j][i] = 0;
      Y[j][i] = 0;
      Yerr[j][i] = 0;
    }
  }

  for(int i = 0; i < N; i++){
    base->GetEntry(i);

    if(base->VMM != VMM)
      continue;
    
    for(int c = 0; c < Nch; c++){
      if(base->CHpulse != CH[c])
	continue;
      
      int ival = base->TPDAC;
      //int ival = base->Delay;
    
      for(int v = 0; v < Nval; v++){
	if(ival == Value[v]){
	  Ntot[c][v] += 1.;
	  Y[c][v] += base->PDO;
	  Yerr[c][v] += base->PDO*base->PDO;
	}
      }
    }
  }

  for(int c = 0; c < Nch; c++){
    for(int v = 0; v < Nval; v++){
      double mean  = Y[c][v] / max(Ntot[c][v],1.);
      double mean2 = Yerr[c][v] / max(Ntot[c][v],1.);

      Y[c][v] = mean;
      Yerr[c][v] = sqrt(mean2-mean*mean);
    }
  }

  vector<TGraphErrors*> gr;
  TMultiGraph *mg = new TMultiGraph();

  for(int c = 0; c < Nch; c++){
    gr.push_back(new TGraphErrors(Nval,X,Y[c],Xerr,Yerr[c]));
    gr[c]->SetMarkerStyle(21);
    gr[c]->SetMarkerSize(1);
    gr[c]->SetMarkerColor(1393+2*c);
    gr[c]->SetLineColor(1393+2*c);
    gr[c]->SetLineWidth(3);
    gr[c]->SetFillColor(kWhite);
    mg->Add(gr[c]);
  }
  
  TCanvas* can = new TCanvas("can","can",600,500);
  can->SetLeftMargin(0.15);
  can->SetRightMargin(0.04);
  can->SetBottomMargin(0.15);
  can->SetTopMargin(0.085);
  
  can->Draw();
  can->SetGridx();
  can->SetGridy();
  
  can->cd();

  mg->Draw("AEP");
  
  mg->Draw();
  mg->GetXaxis()->CenterTitle();
  mg->GetXaxis()->SetTitleFont(132);
  mg->GetXaxis()->SetTitleSize(0.06);
  mg->GetXaxis()->SetTitleOffset(1.06);
  mg->GetXaxis()->SetLabelFont(132);
  mg->GetXaxis()->SetLabelSize(0.05);
  mg->GetXaxis()->SetTitle(varXname.c_str());
  mg->GetYaxis()->CenterTitle();
  mg->GetYaxis()->SetTitleFont(132);
  mg->GetYaxis()->SetTitleSize(0.06);
  mg->GetYaxis()->SetTitleOffset(1.);
  mg->GetYaxis()->SetLabelFont(132);
  mg->GetYaxis()->SetLabelSize(0.05);
  mg->GetYaxis()->SetTitle(varYname.c_str());

  TLegend* leg = new TLegend(0.688,0.22,0.93,0.42);
  leg->SetTextFont(132);
  leg->SetTextSize(0.045);
  leg->SetFillColor(kWhite);
  leg->SetLineColor(kWhite);
  leg->SetShadowColor(kWhite);
  for(int i = 0; i < Nch; i++){
    string llabel = "CH = "+to_string(CH[i]);
    leg->AddEntry(gr[i],llabel.c_str());
  }
  leg->SetLineColor(kWhite);
  leg->SetFillColor(kWhite);
  leg->SetShadowColor(kWhite);
  leg->Draw("SAME");
  
  TLatex l;
  l.SetTextFont(132);
  l.SetNDC();
  l.SetTextSize(0.05);
  l.SetTextFont(132);
  l.DrawLatex(0.27,0.94,"MMFE8 Analysis");
  l.SetTextSize(0.04);
  l.SetTextFont(42);
  l.DrawLatex(0.02,0.943,"#bf{#it{ATLAS}} Internal");

  string label = "VMM # = "+to_string(VMM);
  l.SetTextSize(0.05);
  l.SetTextFont(132);
  l.DrawLatex(0.64,0.94, label.c_str());

 
}
Beispiel #8
0
void plotOFVZsub(TString var, int nb, float min, float max, bool norm, TString mycut, int njets, TString fs) {

  gROOT->Reset();
  gStyle->SetOptStat(0);

  TString dir = "/smurf/cerati/skims/Run2012_Summer12_SmurfV9_53X/test/skim_dy/";

  TChain *ph = new TChain("tree");
  ph->Add(dir+"./dyll.root");

  TFile *_da = TFile::Open(dir+"./data.root");
  TTree* da = (TTree*) _da->Get("tree");

  TFile *_zz = TFile::Open(dir+"./zz.root");
  TTree* zz = (TTree*) _zz->Get("tree");
  TFile *_wz = TFile::Open(dir+"./wz.root");
  TTree* wz = (TTree*) _wz->Get("tree");

  TFile *_hw = TFile::Open(dir+"./hww125.root");
  TTree* hw = (TTree*) _hw->Get("tree");

  TH1F* h_zz = new TH1F("h_zz","h_zz",nb,min,max);
  TH1F* h_wz = new TH1F("h_wz","h_wz",nb,min,max);
  TH1F* h_dy = new TH1F("h_dy","h_dy",nb,min,max);
  TH1F* h_da = new TH1F("h_da","h_da",nb,min,max);
  TH1F* h_of = new TH1F("h_of","h_of",nb,min,max);
  TH1F* h_hw = new TH1F("h_hw","h_hw",nb,min,max);

  h_dy->SetFillColor(kGreen);
  h_of->SetFillColor(kRed);
  h_zz->SetFillColor(kBlue);
  h_wz->SetFillColor(kBlue);

  h_da->SetMarkerStyle(20);
  h_da->SetLineWidth(2);

  h_hw->SetLineColor(kCyan);
  h_hw->SetLineWidth(2);

  float lumi = 11.9;
  float lumicorr = 1.04;
  float dysf = 1.0;
  float dyer = 1.0;
  if (njets==0) dysf = 10.75;
  if (njets==1) dysf =  7.68;
  if (njets==0) dyer = 0.11;
  if (njets==1) dyer = 0.11;

  TString Met20 = Form("((cuts & 4719111)==4719111)&&njets==%i&&lep1.pt()>20.&&lep2.pt()>10.&&(dstype!=0 || (cuts & 1073741824)==1073741824) && met>20  && dilep.mass()>12. && min(pmet,pTrackMet)>20. && mt>80. && dilep.pt()>45.",njets);

  TString cut = Met20;

  TString minmet = " && min(pmet,pTrackMet)>45.  && (jet1.pt()<15 || dPhiDiLepJet1<165.*TMath::Pi()/180. )"; 
  TString dymva = " && ((njets==0 && dymva>0.88) || (njets==1 && dymva>0.84))";

  if (mycut.Contains("Zp")) cut+="&& abs(dilep.mass()-91)<7.5";
  if (mycut.Contains("oZ")) cut+="&& abs(dilep.mass()-91)>15";

  if (mycut.Contains("ptll45")) {
    cut+="&& dilep.pt()>45.";
    Met20+="&& dilep.pt()>45.";
  }

  if (mycut.Contains("DyMva")) cut+=dymva;

  if (mycut.Contains("MetGt45")) cut+=minmet;
  if (mycut.Contains("MetLt45")) cut+="&& min(pmet,pTrackMet)<45.";

  if (mycut.Contains("mll70")) cut+="&& dilep.mass()<70.";

  if (mycut.Contains("metsig25")) cut+="&& met/sqrt(sumet)<2.5";

  if (mycut.Contains("Mva05")) cut+="&& dymva>0.5";
  if (mycut.Contains("Mva02")) cut+="&& dymva>0.2";

  if (mycut.Contains("HiPU")) cut+="&& nvtx>=10";
  if (mycut.Contains("LoPU")) cut+="&& nvtx<10";

  if (mycut.Contains("HWW125")) {
    cut+="&& lep1.pt()>23 &&  lep2.pt()>10 && dPhi<100.*TMath::Pi()/180. && mt>80 && mt<123"+dymva;
    if (njets==0) dysf = 8.40;
    if (njets==1) dysf = 1.0;
    if (njets==0) dyer = 2.87/8.40;
    if (njets==1) dyer = 1.0;
  }

  if (mycut.Contains("HWW145")) {
    cut+="&& lep1.pt()>25 &&  lep2.pt()>15 && dPhi<90.*TMath::Pi()/180. && mt>80 && mt<130"+dymva;
    if (njets==0) dysf = 7.42;
    if (njets==1) dysf = 3.1;
    if (njets==0) dyer = 1.71/7.42;
    if (njets==1) dyer = 0.5;
  }

  if (mycut.Contains("HWW150")) {
    cut+="&& lep1.pt()>27 &&  lep2.pt()>25 && dPhi<90.*TMath::Pi()/180. && mt>80 && mt<150"+dymva;
    if (njets==0) dysf = 15.78;
    if (njets==1) dysf = 2.8;
    if (njets==0) dyer = 4.20/15.78;
    if (njets==1) dyer = 0.5;
  }

  if (mycut.Contains("HWW160")) {
    cut+="&& lep1.pt()>30 &&  lep2.pt()>25 && dPhi<60.*TMath::Pi()/180. && mt>90 && mt<160"+dymva;
    if (njets==0) dysf = 11.85;
    if (njets==1) dysf = 3.3;
    if (njets==0) dyer = 4.65/11.85;
    if (njets==1) dyer = 0.4;
  }

  if (mycut.Contains("HWW170")) {
    cut+="&& lep1.pt()>34 &&  lep2.pt()>25 && dPhi<60.*TMath::Pi()/180. && mt>110 && mt<170"+dymva;
    if (njets==0) dysf = 5.50;
    if (njets==1) dysf = 3.8;
    if (njets==0) dyer = 3.62/5.50;
    if (njets==1) dyer = 0.4;
  }

  if (mycut.Contains("HWW180")) {
    cut+="&& lep1.pt()>36 &&  lep2.pt()>25 && dPhi<70.*TMath::Pi()/180. && mt>120 && mt<180"+dymva;
    if (njets==0) dysf = 1.0;
    if (njets==1) dysf = 5.0;
    if (njets==0) dyer = 1.0;
    if (njets==1) dyer = 0.4;
  }

  if (mycut.Contains("HWW190")) {
    cut+="&& lep1.pt()>38 &&  lep2.pt()>25 && dPhi<90.*TMath::Pi()/180. && mt>120 && mt<190"+dymva;
    if (njets==0) dysf = 11.78;
    if (njets==1) dysf = 5.2;
    if (njets==0) dyer = 4.12/11.78;
    if (njets==1) dyer = 0.4;
  }

  if (mycut.Contains("HWW200")) {
    cut+="&& lep1.pt()>40 &&  lep2.pt()>25 && dPhi<100.*TMath::Pi()/180. && mt>120 && mt<200"+dymva;
    if (njets==0) dysf = 10.18;
    if (njets==1) dysf = 4.9;
    if (njets==0) dyer = 3.10/10.18;
    if (njets==1) dyer = 0.4;
  }

  TString sf = "(type==0 || type==3)";
  TString of = "(type==1 || type==2)";
  if (fs=="mm") {
    sf = "type==0";
    of = "type==1";
  } else if (fs=="ee") {
    sf = "type==3";
    of = "type==2";
  }

  TString cutsf = "("+cut+"&&"+sf+")";
  TString cutof = "("+cut+"&&"+of+")";
  TString cutmc = "scale1fb*sfWeightPU*sfWeightTrig*sfWeightEff*"+cutsf;

  cout << cutmc << endl;

  TCanvas c1;
  //c1.SetLogy();

  zz->Draw(var+">>h_zz",cutmc); 
  wz->Draw(var+">>h_wz",cutmc); 
  ph->Draw(var+">>h_dy",cutmc); 
  da->Draw(var+">>h_da",cutsf); 
  da->Draw(var+">>h_of",cutof); 
  hw->Draw(var+">>h_hw","scale1fb*sfWeightPU*sfWeightTrig*sfWeightEff*("+Met20+"&&"+sf+")"); 

  cout << h_dy->GetEntries() << endl;

  //add
  h_wz->Scale(lumi);
  h_zz->Scale(lumi);
  h_dy->Scale(lumi*dysf);
  h_of->Scale(lumicorr);
  h_hw->Scale(lumi);

  THStack hs("hs","stack");
  hs.Add(h_of);
  hs.Add(h_zz);
  hs.Add(h_wz);
  hs.Add(h_dy);

  TH1F* herr = new TH1F("herr","herr",nb,min,max);
  for (int bin=1;bin<max+1;bin++) {
    herr->SetBinContent(bin, ((TH1*)(hs.GetStack()->Last()))->GetBinContent(bin) );
    herr->SetBinError(bin,sqrt( pow(0.15*h_wz->GetBinContent(bin),2) + pow(0.15*h_wz->GetBinContent(bin),2) + 
				h_of->GetBinContent(bin) + dyer*h_dy->GetBinContent(bin) ) );
  }
  TGraphErrors* gerr = new TGraphErrors(herr);
  gerr->SetFillColor(kBlack);
  gerr->SetFillStyle(3244);

  var.ReplaceAll(".","");
  var.ReplaceAll("(","");
  var.ReplaceAll(")","");

  h_da->GetYaxis()->SetRangeUser(0.05,1.2*TMath::Max(h_da->GetBinContent(h_da->GetMaximumBin()), 
					      ((TH1*)(hs.GetStack()->Last()))->GetBinContent(((TH1*)(hs.GetStack()->Last()))->GetMaximumBin()) ));//3*
  h_da->GetXaxis()->SetTitle(var);
  h_da->SetTitle("");

  if (!norm) {
    h_da->Draw("PE");
    hs.Draw("same");
    h_da->Draw("PE,same");
    //h_hw->Draw("same");
    gerr->Draw("2");
  } else {
    h_da->Sumw2();
    h_da->DrawNormalized("PE");
    hs.DrawNormalized("same");
    //h_hw->DrawNormalized("same");
  }

  TLegend* leg = new TLegend(0.1,0.91,0.9,0.96);
  /*if (var.Contains("dPhi")) {
    delete leg;
    leg = new TLegend(0.55,0.11,0.88,0.31);
    }*/
  leg->SetFillColor(kWhite);
  leg->SetNColumns(5);
  leg->SetLineWidth(0);
  leg->SetLineColor(kWhite);
  leg->SetShadowColor(kWhite);
  leg->AddEntry(h_da,"SF data","p");
  leg->AddEntry(h_dy,Form("%2.1f x DY MC",dysf),"f");
  leg->AddEntry(h_of,"OF data","f");
  leg->AddEntry(h_wz,"VZ MC","f");
  //leg->AddEntry(h_hw,"HWW120","l");
  leg->Draw();

  c1.RedrawAxis();

  if (var.Contains("/")) var.ReplaceAll("/","");
  var = var+Form("_%ij",njets);

  gSystem->Exec("mkdir -p "+mycut+Form("_%ij_",njets)+fs);
  if (!norm) c1.SaveAs(mycut+Form("_%ij_",njets)+fs+"/"+var+".png");
  else c1.SaveAs(mycut+Form("_%ij_",njets)+fs+"/"+var+"_norm.png");
}
void makePlots_csvSF_13TeV( TString inputFileName  = "infile.root", bool isHF = true, TString dirPostFix = "", bool compareIterations = false ) {

  TFile *histFile = TFile::Open(inputFileName);


  TString dirprefix = "Images/Images_2014_08_26_csvSF_13TeV" + dirPostFix + "/";

  struct stat st;
  if( stat(dirprefix.Data(),&st) != 0 )  mkdir(dirprefix.Data(),0777);

  // single jet specific plots
  int nPt = 6;
  int nEta = 1;
  TString flavor = "HF";
  if ( !isHF ){
    nPt = 4; nEta = 3;
    flavor = "LF";
  }

  //////
  TH1D* h_Data_jet_csv[nPt][nEta];
  TH1D* h_MC_b_jet_csv[nPt][nEta];
  TH1D* h_MC_nonb_jet_csv[nPt][nEta];

  /////
  int nCSVBins = 18; //Number of bins 
  double xBins_hf[19] = {-0.04, 0.0, 0.122, 0.244, 0.331, 0.418, 0.505, 0.592, 0.679, 0.7228, 0.7666, 0.8104, 0.8542, 0.898, 0.9184, 0.9388, 0.9592, 0.9796, 1.01};

  // int nCSVBins = 14;
  // double xBins_hf[15] = {-0.04, 0.0, 0.244, 0.418, 0.592, 0.679, 0.7666, 0.8104, 0.8542, 0.898, 0.9184, 0.9388, 0.9592, 0.9796, 1.01};


  if(!isHF) nCSVBins = 21;
  double xBins_lf[22] = {-0.04, 0.0, 0.04, 0.08, 0.12, 0.16, 0.2, 0.244, 0.331, 0.418, 0.505, 0.592, 0.679, 0.752, 0.825, 0.898, 0.915, 0.932, 0.949, 0.966, 0.983, 1.01};
  // if(!isHF) nCSVBins = 15;
  // double xBins_lf[16] = {-0.04, 0.0, 0.04, 0.08, 0.12, 0.16, 0.2, 0.244, 0.331, 0.418, 0.505, 0.592, 0.679, 0.825, 0.949, 1.01};


  //TCanvas* c1 = new TCanvas("c1","c1",600,600);
  TCanvas* c1 = new TCanvas("c1","c1",600,500);

  c1->SetTopMargin(0.08);
  c1->SetRightMargin(0.08);


  TString flavor_file = flavor;
  flavor_file.ToLower();

  TFile *fitFile_iter0 = TFile::Open("csv_rwt_fit_" + flavor_file + "_v0.root");
  TFile *fitFile_iter1 = TFile::Open("csv_rwt_fit_" + flavor_file + "_v1.root");
  TFile *fitFile_iter2 = TFile::Open("csv_rwt_fit_" + flavor_file + "_v2.root");



  TString plotName;

  int iHist = -1;
  for ( int iPt=0; iPt<nPt; iPt++){
    for ( int iEta=0; iEta<nEta; iEta++){
      iHist++;

      TString h_Data_Name = Form("csv_Data_Pt%i_Eta%i",iPt,iEta);
      TString h_b_Name = Form("csv_MC_bjets_Pt%i_Eta%i",iPt,iEta);
      TString h_nonb_Name = Form("csv_MC_nonbjets_Pt%i_Eta%i",iPt,iEta);

      
      h_Data_jet_csv[iPt][iEta] = (TH1D*)histFile->Get(h_Data_Name.Data());
      h_MC_b_jet_csv[iPt][iEta] = (TH1D*)histFile->Get(h_b_Name.Data());
      h_MC_nonb_jet_csv[iPt][iEta] = (TH1D*)histFile->Get(h_nonb_Name.Data());

      // rebin
      TH1D* h_csv_data = NULL;
      TH1D* h_csv_mc_b = NULL;
      TH1D* h_csv_mc_nonb = NULL;
      if( isHF ){
	h_csv_data = (TH1D*)h_Data_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_hf );
	h_csv_mc_b = (TH1D*)h_MC_b_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_hf );
	h_csv_mc_nonb = (TH1D*)h_MC_nonb_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_hf );
      }
      else{
	h_csv_data = (TH1D*)h_Data_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_lf );
	h_csv_mc_b = (TH1D*)h_MC_b_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_lf );
	h_csv_mc_nonb = (TH1D*)h_MC_nonb_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_lf );
      }

      h_csv_data->SetBinContent(1,h_Data_jet_csv[iPt][iEta]->GetBinContent(1));
      h_csv_data->SetBinError(1,h_Data_jet_csv[iPt][iEta]->GetBinError(1));

      h_csv_mc_b->SetBinContent(1,h_MC_b_jet_csv[iPt][iEta]->GetBinContent(1));
      h_csv_mc_b->SetBinError(1,h_MC_b_jet_csv[iPt][iEta]->GetBinError(1));

      h_csv_mc_nonb->SetBinContent(1,h_MC_nonb_jet_csv[iPt][iEta]->GetBinContent(1));
      h_csv_mc_nonb->SetBinError(1,h_MC_nonb_jet_csv[iPt][iEta]->GetBinError(1));

      h_csv_data->SetStats(0);
      //h_csv_data->GetXaxis()->SetRangeUser(0.0001, 1.001);

      h_csv_data->SetTitle(";CSV");

      h_csv_data->SetMarkerStyle(20);

      h_csv_mc_b->SetFillColor(kRed);
      h_csv_mc_nonb->SetFillColor(kGreen+1);

      h_csv_mc_b->SetLineColor(kRed);
      h_csv_mc_nonb->SetLineColor(kGreen+1);

      h_csv_data->SetLineWidth(2);
      h_csv_mc_b->SetLineWidth(2);
      h_csv_mc_nonb->SetLineWidth(2);


      TLegend *legend = new TLegend(0.14,0.93,0.9,0.98);

      legend->SetFillColor(kWhite);
      legend->SetLineColor(kWhite);
      legend->SetShadowColor(kWhite);
      legend->SetTextFont(42);
      legend->SetTextSize(0.05);

      legend->SetNColumns(3);

      legend->AddEntry(h_csv_data,"Data","pe");
      if( isHF ){
	legend->AddEntry(h_csv_mc_b,"b jets","l");
	legend->AddEntry(h_csv_mc_nonb,"non-b jets","l");
      }
      else{
	legend->AddEntry(h_csv_mc_b,"HF jets","l");
	legend->AddEntry(h_csv_mc_nonb,"LF jets","l");
      }

      TH1D* h_diff = (TH1D*) h_csv_data->Clone( Form("csv_diff_Pt%i_Eta%i",iPt,iEta) );

      THStack *hs = new THStack("hs","");
      if( isHF ){
	hs->Add(h_csv_mc_b);
	hs->Add(h_csv_mc_nonb);

	h_diff->Add(h_csv_mc_nonb,-1);
      }
      else{
	hs->Add(h_csv_mc_nonb);
	hs->Add(h_csv_mc_b);

	h_diff->Add(h_csv_mc_b,-1);
      }

      TH1D* h_ratio = (TH1D*) h_diff->Clone( Form("csv_ratio_Pt%i_Eta%i",iPt,iEta) );
      if( isHF ) h_ratio->Divide( h_csv_mc_b );
      else       h_ratio->Divide( h_csv_mc_nonb );
      

      TString title    = Form("%s SF Pt%i Eta%i",flavor.Data(),iPt,iEta);

      TLatex BinInfoLatex(0.6, 0.86, title.Data());
	
      BinInfoLatex.SetNDC();
      BinInfoLatex.SetTextFont(42);
      BinInfoLatex.SetTextSize(0.04);

      h_csv_data->Draw("pe1");
      hs->Draw("histsame");
      h_csv_data->Draw("pe1same");
      
      legend->Draw();
      BinInfoLatex.Draw();

      c1->RedrawAxis();

      plotName = dirprefix + Form("csv_%s_SF_Pt%i_Eta%i_astack",flavor.Data(),iPt,iEta) + ".png";

      c1->Print(plotName.Data());



      TLegend *legend_diff = new TLegend(0.14,0.93,0.9,0.98);

      legend_diff->SetFillColor(kWhite);
      legend_diff->SetLineColor(kWhite);
      legend_diff->SetShadowColor(kWhite);
      legend_diff->SetTextFont(42);
      legend_diff->SetTextSize(0.05);

      legend_diff->SetNColumns(2);

      if( isHF ){
	legend_diff->AddEntry(h_diff,"(Data - nonb)","pe");
	legend_diff->AddEntry(h_csv_mc_b,"b jets","l");
      }
      else{
	legend_diff->AddEntry(h_diff,"(Data - b)","pe");
	legend_diff->AddEntry(h_csv_mc_nonb,"LF jets","l");
      }



      h_diff->Draw("pe1");
      if( isHF ) h_csv_mc_b->Draw("pe1same");
      else       h_csv_mc_nonb->Draw("pe1same");
      h_diff->Draw("pe1same");

      legend_diff->Draw();
      BinInfoLatex.Draw();

      c1->RedrawAxis();

      plotName = dirprefix + Form("csv_%s_SF_Pt%i_Eta%i_bdiff",flavor.Data(),iPt,iEta) + ".png";

      c1->Print(plotName.Data());



      h_ratio->GetYaxis()->SetRangeUser(0.,2.);
      h_ratio->SetTitle(";CSV;Data/MC SF");
      h_ratio->Draw("pe1");

      BinInfoLatex.Draw();

      c1->RedrawAxis();

      plotName = dirprefix + Form("csv_%s_SF_Pt%i_Eta%i_cratio",flavor.Data(),iPt,iEta) + ".png";

      c1->Print(plotName.Data());


      if( compareIterations ){


	TString h_iter_Data_Name = Form("h_csv_Data_Pt%i_Eta%i",iPt,iEta);
	TString h_iter_b_Name = Form("h_csv_MC_bjets_Pt%i_Eta%i",iPt,iEta);
	TString h_iter_nonb_Name = Form("h_csv_MC_nonbjets_Pt%i_Eta%i",iPt,iEta);
	TString h_iter_csv_ratio_Name = Form("temp_csv_ratio_Pt%i_Eta%i",iPt,iEta);
 
	TH1D* h_iter_Data_jet_csv_iter0 = (TH1D*)fitFile_iter0->Get(h_iter_Data_Name.Data())->Clone(h_iter_Data_Name+"v0");
	TH1D* h_iter_MC_b_jet_csv_iter0 = (TH1D*)fitFile_iter0->Get(h_iter_b_Name.Data())->Clone(h_iter_b_Name+"v0");
	TH1D* h_iter_MC_nonb_jet_csv_iter0 = (TH1D*)fitFile_iter0->Get(h_iter_nonb_Name.Data())->Clone(h_iter_nonb_Name+"v0");
	
	TH1D* h_iter_Data_jet_csv_iter1 = (TH1D*)fitFile_iter1->Get(h_iter_Data_Name.Data())->Clone(h_iter_Data_Name+"v1");
	TH1D* h_iter_MC_b_jet_csv_iter1 = (TH1D*)fitFile_iter1->Get(h_iter_b_Name.Data())->Clone(h_iter_b_Name+"v1");
	TH1D* h_iter_MC_nonb_jet_csv_iter1 = (TH1D*)fitFile_iter1->Get(h_iter_nonb_Name.Data())->Clone(h_iter_nonb_Name+"v1");

	TH1D* h_iter_Data_jet_csv_iter2 = (TH1D*)fitFile_iter2->Get(h_iter_Data_Name.Data())->Clone(h_iter_Data_Name+"v2");
	TH1D* h_iter_MC_b_jet_csv_iter2 = (TH1D*)fitFile_iter2->Get(h_iter_b_Name.Data())->Clone(h_iter_b_Name+"v2");
	TH1D* h_iter_MC_nonb_jet_csv_iter2 = (TH1D*)fitFile_iter2->Get(h_iter_nonb_Name.Data())->Clone(h_iter_nonb_Name+"v2");

	TH1D* h_iter0 = (TH1D*)h_iter_Data_jet_csv_iter0->Clone(h_iter_csv_ratio_Name+"v0");
	TH1D* h_iter1 = (TH1D*)h_iter_Data_jet_csv_iter1->Clone(h_iter_csv_ratio_Name+"v1");
	TH1D* h_iter2 = (TH1D*)h_iter_Data_jet_csv_iter2->Clone(h_iter_csv_ratio_Name+"v2");
	if( isHF ){
	  h_iter0->Add(h_iter_MC_nonb_jet_csv_iter0, -1);
	  h_iter0->Divide(h_iter_MC_b_jet_csv_iter0);

	  h_iter1->Add(h_iter_MC_nonb_jet_csv_iter1, -1);
	  h_iter1->Divide(h_iter_MC_b_jet_csv_iter1);

	  h_iter2->Add(h_iter_MC_nonb_jet_csv_iter2, -1);
	  h_iter2->Divide(h_iter_MC_b_jet_csv_iter2);
	}
	else {
	  h_iter0->Add(h_iter_MC_b_jet_csv_iter0, -1);
	  h_iter0->Divide(h_iter_MC_nonb_jet_csv_iter0);

	  h_iter1->Add(h_iter_MC_b_jet_csv_iter1, -1);
	  h_iter1->Divide(h_iter_MC_nonb_jet_csv_iter1);

	  h_iter2->Add(h_iter_MC_b_jet_csv_iter2, -1);
	  h_iter2->Divide(h_iter_MC_nonb_jet_csv_iter2);
	}


	TString iter_fit_histo_name = Form("csv_ratio_Pt%d_Eta%d_final",iPt,iEta);

	//TString iter_histo_name = Form("h_csv_ratio_%d",iHist);
	TH1D* h_fit_iter0 = (TH1D*)fitFile_iter0->Get(iter_fit_histo_name)->Clone(iter_fit_histo_name+"v0");
	TH1D* h_fit_iter1 = (TH1D*)fitFile_iter1->Get(iter_fit_histo_name)->Clone(iter_fit_histo_name+"v1");
	TH1D* h_fit_iter2 = (TH1D*)fitFile_iter2->Get(iter_fit_histo_name)->Clone(iter_fit_histo_name+"v2");

	h_fit_iter0->SetLineColor(kRed);
	h_fit_iter1->SetLineColor(kGreen+1);
	h_fit_iter2->SetLineColor(kBlue);

	h_fit_iter0->SetLineWidth(2);
	h_fit_iter1->SetLineWidth(2);
	h_fit_iter2->SetLineWidth(2);

	h_iter0->SetLineColor(kRed);
	h_iter1->SetLineColor(kGreen+1);
	h_iter2->SetLineColor(kBlue);

	h_iter0->SetLineWidth(2);
	h_iter1->SetLineWidth(2);
	h_iter2->SetLineWidth(2);

	h_fit_iter0->SetStats(0);
	h_fit_iter0->GetYaxis()->SetRangeUser(0.,2.);

	h_fit_iter0->SetTitle(";CSV;Data/MC CSV SF");

	h_fit_iter0->Draw("hist");
	h_iter0->Draw("pe1same");
	h_fit_iter1->Draw("histsame");
	h_iter1->Draw("pe1same");
	h_fit_iter2->Draw("histsame");
	h_iter2->Draw("pe1same");

	c1->RedrawAxis();


	TLegend *legend_iter = new TLegend(0.14,0.93,0.9,0.98);

	legend_iter->SetFillColor(kWhite);
	legend_iter->SetLineColor(kWhite);
	legend_iter->SetShadowColor(kWhite);
	legend_iter->SetTextFont(42);
	legend_iter->SetTextSize(0.05);

	legend_iter->SetNColumns(3);

	legend_iter->AddEntry(h_iter0,"Iter0","l");
	legend_iter->AddEntry(h_iter1,"Iter1","l");
	legend_iter->AddEntry(h_iter2,"Iter2","l");

	legend_iter->Draw();
	BinInfoLatex.Draw();

	c1->RedrawAxis();

	plotName = dirprefix + Form("csv_%s_SF_Pt%i_Eta%i_diters",flavor.Data(),iPt,iEta) + ".png";

	c1->Print(plotName.Data());
      }
    }
  }



  std::cout << "Done." << std::endl;

}
Beispiel #10
0
void PlotOpt(){
  // fixed background uncertainty (%)
  g_deltaNbkg = 20.;
  // integrated luminosity (fb^-1)
  g_lumi = 10.;
  // minimum number of expected background events
  g_minBKG = 0.01;

  TFile* input = new TFile("test.root","READ");

  int ParentMass = 250;
  int LSPMass    = 77;

  double Sscale = 1.;
  double Bscale = 1.;

  string SignalModel = "TT";
  string plot_title = "#tilde{t} #tilde{t} #rightarrow (t #tilde{#chi})(t #tilde{#chi}); m_{#tilde{t}} = ";
  plot_title += to_string(ParentMass)+", m_{#tilde{#chi}} = "+to_string(LSPMass)+" GeV";
  
  TTree* tree  = (TTree*) input->Get("optimization");
  double Nsig, Nbkg;
  vector<double> VAR;
  TBranch *b_Nsig,*b_Nbkg;
  vector<TBranch*> b_VAR;
  //int Ncut = tree->GetNbranches()-2;
  int Ncut = 0;
  TObjArray* branches = tree->GetListOfBranches();
  int Nbranch = branches->GetEntries();
  for(int i = 0; i < Nbranch; i++)
    if(string(branches->At(i)->GetName()).find("var") != string::npos)
      Ncut++;
  tree->SetBranchStatus("*",0);
  string sname = "Nsig_"+SignalModel+"_"+to_string(ParentMass)+"_"+to_string(LSPMass);
  tree->SetBranchStatus(sname.c_str(),"1");
  tree->SetBranchAddress(sname.c_str(),&Nsig,&b_Nsig);
  tree->SetBranchStatus("Nbkg","1");
  tree->SetBranchAddress("Nbkg",&Nbkg,&b_Nbkg);
  for(int i = 0; i < Ncut; i++){
    VAR.push_back(0.);
    b_VAR.push_back(new TBranch());
  }
  for(int i = 0; i < Ncut; i++){
    tree->SetBranchStatus(("var"+to_string(i)).c_str(),"1");
    tree->SetBranchAddress(("var"+to_string(i)).c_str(),&(VAR[i]),&b_VAR[i]);
  }

  int Ncomb = tree->GetEntries();

  vector<vector<double> > VAR_cut;
  for(int i = 0; i < Ncut; i++)
    VAR_cut.push_back(vector<double>());

  // find max metric combination
  int c_max = -1;
  double metric_max = -1.;
  for(int c = 0; c < Ncomb; c++){
    tree->GetEntry(c);
    double metric = 0;
    if(Nsig > 0. && Nbkg > 0. && g_lumi*Nbkg*Bscale > g_minBKG)
       metric = EvaluateMetric(g_lumi*Nsig*Sscale,g_lumi*Nbkg*Bscale);
    if(metric > metric_max && g_lumi*Nbkg*Bscale > g_minBKG){
      metric_max = metric;
      c_max = c;
    }
    for(int i = 0; i < Ncut; i++){
      int N = VAR_cut[i].size();
      bool found = false;
      for(int j = 0; j < N; j++){
	if(VAR_cut[i][j] == VAR[i]){
	  found = true;
	  break;
	}
      }
      if(!found)
	VAR_cut[i].push_back(VAR[i]);
    }
  }
  
  vector<double> VAR_max;
  tree->GetEntry(c_max);
  cout << "Point: " << ParentMass << " " << LSPMass << endl;;
  cout << "Max significance of " << EvaluateMetric(g_lumi*Nsig*Sscale,g_lumi*Nbkg*Bscale);
  cout << " sigma with:" << endl;
  cout << "   Nsig = " << g_lumi*Nsig*Sscale << endl;
  cout << "   Nbkg = " << g_lumi*Nbkg*Bscale << endl;
  for(int i = 0; i < Ncut; i++){
    VAR_max.push_back(VAR[i]);
    cout << "var " << i << " " << VAR[i] << endl;
  }

  vector<vector<double> > VAR_max_fix;
  vector<vector<double> > VAR_max_float;
  for(int i = 0; i < Ncut; i++){
    VAR_max_fix.push_back(vector<double>());
    VAR_max_float.push_back(vector<double>());
    int N = VAR_cut[i].size();
    for(int j = 0; j < N; j++){
      VAR_max_fix[i].push_back(-1.);
      VAR_max_float[i].push_back(-1.);
    }
  }

  for(int c = 0; c < Ncomb; c++){
    tree->GetEntry(c);
    double metric = 0;
    if(Nsig > 0. && Nbkg > 0. && g_lumi*Nbkg*Bscale > g_minBKG)
       metric = EvaluateMetric(g_lumi*Nsig*Sscale,g_lumi*Nbkg*Bscale);
   
    for(int i = 0; i < Ncut; i++){
      int N = VAR_cut[i].size();
      int jcut = -1;
      for(int j = 0; j < N; j++)
	if(VAR[i] == VAR_cut[i][j])
	  jcut = j;
      if(metric > VAR_max_float[i][jcut])
	VAR_max_float[i][jcut] = metric;
      bool fix = true;
      for(int j = 0; j < Ncut; j++){
	if(i == j) continue;
	if(fabs(VAR[j]-VAR_max[j]) > 1e-10){
	  fix = false;
	  break;
	}
      }
      if(!fix)
	continue;
      if(metric > VAR_max_fix[i][jcut]){
	VAR_max_fix[i][jcut] = metric;
      }
    }
  }
  
  TGraph* gr_fix[Ncut];
  TGraph* gr_float[Ncut];
  TMultiGraph* mg[Ncut];
  TCanvas* can[Ncut];
  TLegend* leg;

  for(int icut = 0; icut < Ncut; icut++){
    int Nval = VAR_cut[icut].size();
    double x[Nval];
    double y[2][Nval];
    for(int i = 0; i < Nval; i++){
      x[i] = VAR_cut[icut][i];
      y[0][i] = VAR_max_fix[icut][i];
      y[1][i] = VAR_max_float[icut][i];
    }
    gr_fix[icut] = (TGraph*) new TGraph(Nval,x,y[0]);
    gr_float[icut] = (TGraph*) new TGraph(Nval,x,y[1]);
    gr_fix[icut]->SetLineWidth(4);
    gr_fix[icut]->SetLineColor(kBlue+2);
    gr_fix[icut]->SetFillColor(kWhite);
    gr_fix[icut]->SetMarkerSize(0);
    gr_float[icut]->SetLineWidth(4);
    gr_float[icut]->SetLineStyle(7);
    gr_float[icut]->SetLineColor(kGreen+3);
    gr_float[icut]->SetFillColor(kWhite);
    gr_float[icut]->SetMarkerSize(0);
    mg[icut] = (TMultiGraph*) new TMultiGraph();
    mg[icut]->Add(gr_fix[icut]);
    mg[icut]->Add(gr_float[icut]);

    string scan = "can_"+to_string(icut);
    can[icut] = (TCanvas*) new TCanvas(scan.c_str(),scan.c_str(),600.,500);
    can[icut]->SetLeftMargin(0.15);
    can[icut]->SetRightMargin(0.04);
    can[icut]->SetBottomMargin(0.15);
    can[icut]->SetGridx();
    can[icut]->SetGridy();
    can[icut]->Draw();
    can[icut]->cd();
    mg[icut]->Draw("AL");
    mg[icut]->GetXaxis()->CenterTitle();
    mg[icut]->GetXaxis()->SetTitleFont(132);
    mg[icut]->GetXaxis()->SetTitleSize(0.06);
    mg[icut]->GetXaxis()->SetTitleOffset(1.13);
    mg[icut]->GetXaxis()->SetLabelFont(132);
    mg[icut]->GetXaxis()->SetLabelSize(0.05);
    mg[icut]->GetXaxis()->SetTitle(("Var "+to_string(icut)).c_str());
    mg[icut]->GetYaxis()->CenterTitle();
    mg[icut]->GetYaxis()->SetTitleFont(132);
    mg[icut]->GetYaxis()->SetTitleSize(0.06);
    mg[icut]->GetYaxis()->SetTitleOffset(1.2);
    mg[icut]->GetYaxis()->SetLabelFont(132);
    mg[icut]->GetYaxis()->SetLabelSize(0.05);
    mg[icut]->GetYaxis()->SetTitle("Significance ( Z_{Bi} )");
    
    if(icut == 0){
      leg = (TLegend*) new TLegend(0.688,0.22,0.93,0.42);
      leg->SetTextFont(132);
      leg->SetTextSize(0.06);
      leg->AddEntry(gr_fix[icut],"#vec{c} |_{global max}");
      leg->AddEntry(gr_float[icut],"#vec{c} |_{local max}");
      leg->SetFillColor(kWhite);
      leg->SetLineColor(kWhite);
      leg->SetShadowColor(kWhite);
    } 
    leg->Draw("SAME");

    TLatex l;
    l.SetTextFont(132);	
    l.SetNDC();	
    l.SetTextSize(0.04);
    l.SetTextFont(132);
    l.DrawLatex(0.17,0.855,plot_title.c_str());
    l.SetTextSize(0.04);
    l.SetTextFont(42);
    l.DrawLatex(0.15,0.943,"#bf{#it{ATLAS}} Internal");
    l.SetTextSize(0.045);
    l.SetTextFont(132);
    string bla = "#scale[0.6]{#int} #it{L dt} = "+to_string(int(g_lumi))+" fb^{-1},  #Delta_{N#scale[0.8]{bkg}} = ";
    bla += to_string(int(g_deltaNbkg))+" %";
    l.DrawLatex(0.55,0.943,bla.c_str());
  }
  
}
void FinalPlot(bool analysisFake){  

  
        TString OutputFolder="";
	if(analysisFake)OutputFolder="Data_RunD_Ratio_AnalysisFake_217fb";
	else OutputFolder="Data_RunD_Ratio_ExtendedFake_217fb";
	
        int stat0;
        stat0 = mkdir(OutputFolder, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
	
	int xlow(0),xup(300);
	
	THStack *hs = new THStack("hs","QCD and EWK E_{T}^{miss} with candidate histograms");
	TFile *f = 0;
	if(analysisFake)f = new TFile("Data_RunD_All_AnalysisFake_217fb.root", "READ");
	else f = new TFile("Data_RunD_All_ExtendedFake_217fb.root", "READ");
	
	TFile *fsig1 = new TFile("/home/arka/arka/ggNtuples_Phys14/QCD_Closure/SignalAcceptanceNewestNtuples/SignalSampleNtuple/SignalPoint_mGlu_1400_mNeu_600.root", "READ");
	TFile *fsig2 = new TFile("/home/arka/arka/ggNtuples_Phys14/QCD_Closure/SignalAcceptanceNewestNtuples/SignalSampleNtuple/SignalPoint_mGlu_1600_mNeu_600.root", "READ");
	
	TH1F *h_DoublePhoton_Signal_MET1400 = (TH1F*)fsig1->Get("h_DoublePhoton_Signal_MET");
	h_DoublePhoton_Signal_MET1400 = getOverflow(h_DoublePhoton_Signal_MET1400);
	
	
	TH1F *h_DoublePhoton_Signal_MET1600 = (TH1F*)fsig2->Get("h_DoublePhoton_Signal_MET");
	h_DoublePhoton_Signal_MET1600 = getOverflow(h_DoublePhoton_Signal_MET1600);
	
        TH1F *h_DoublePhoton_MET    = (TH1F*)f->Get("h_DoublePhoton_MET");
	int lastBinData = h_DoublePhoton_MET->GetNbinsX();
	
	h_DoublePhoton_MET = getOverflow(h_DoublePhoton_MET);
	
	
	
	h_DoublePhoton_MET->Scale(1.0, "width");
	//cout << "Integral:" << h_DoublePhoton_Signal_MET1600->Integral(20,24) << endl;
	//cout << "Integral Last bin:" << h_DoublePhoton_Signal_MET1600->Integral(23,24) << endl;
	h_DoublePhoton_Signal_MET1400->Scale(1.0, "width");
	h_DoublePhoton_Signal_MET1600->Scale(1.0, "width");
	
	TFile *FQCD = new TFile(OutputFolder+"/QCD_Background.root", "READ");
	TH1F *h_met_QCD_error          = (TH1F*)FQCD->Get("h_DoubleElectron_MET_Reweighted_OnlyDiEMPt");
	
	TFile *FEWK = new TFile(OutputFolder+"/ErrorCorEWK_SymPt.root", "READ");
        TH1F *h_met_EWK_error          = (TH1F*)FEWK->Get("h_met_EWK_error");
	
	
        TH1F *h_met_error              = (TH1F*)h_DoublePhoton_MET->Clone("h_met_error");
	h_met_error->Reset();
	
	
        double toterr = 0;
	double totqcderr = 0;
	double totewkerr = 0;
	double totmet = 0;
	int bin100 = h_DoublePhoton_MET->FindBin(100);
	
        for(int k=0; k<h_DoublePhoton_MET->GetNbinsX(); ++k){
          double x  = h_met_QCD_error->GetBinContent(k+1);
          double x1 = h_met_QCD_error->GetBinError(k+1);
          double d  = h_met_EWK_error->GetBinContent(k+1);
          double d2 = h_met_EWK_error->GetBinError(k+1);
          double y  = x + d;
          double y1 = sqrt(x1*x1+d2*d2);
	  double cand = h_DoublePhoton_MET->GetBinContent(k+1);
	  if((k+1)>=bin100){
	    toterr += y1*y1;
	    totqcderr += x1*x1;
	    totewkerr += d2*d2;
	    totmet += y;
	  }
	  h_met_error->SetBinContent(k+1, y);
          h_met_error->SetBinError(k+1, y1); // only y1
        }
        cout << "total error after 100: " << sqrt(toterr) << endl;
	cout << "total ewk+qcd met >100: " << totmet << endl;
	cout << "total qcd error after 100: " << sqrt(totqcderr) << endl;
	cout << "total ewk error after 100: " << sqrt(totewkerr) << endl;
	
	TLatex *tex1, *tex2, *tex3;
	FinalTexMaker(tex1, tex2, tex3);
  
	h_met_EWK_error->SetFillColor(kAzure-2);
	h_met_EWK_error->SetLineColor(kAzure-2);
	hs->Add(h_met_EWK_error);

	h_met_QCD_error->SetFillColor(kRed+1);
	h_met_QCD_error->SetLineColor(kRed+1);
	hs->Add(h_met_QCD_error);

        h_met_error->SetFillColor(kOrange);
	h_met_error->SetLineColor(kOrange);
	h_met_error->SetFillStyle(3013);

        //hs.Add(h_met_QCD_plus_EWK);
	h_met_EWK_error->GetXaxis()->SetRangeUser(xlow, xup);
	h_met_EWK_error->GetYaxis()->SetTitleOffset(0.7);
        h_met_EWK_error->GetYaxis()->SetTitleSize(0.060);
	h_met_EWK_error->GetYaxis()->SetLabelSize(0.075);
	
        //h_met_QCD_subtract_error->SetFillColor(kRed);
	
	h_DoublePhoton_Signal_MET1400->SetMarkerStyle(kFullTriangleUp);
	h_DoublePhoton_Signal_MET1400->SetLineColor(kMagenta);
	h_DoublePhoton_Signal_MET1400->SetMarkerColor(kMagenta);
	
	h_DoublePhoton_Signal_MET1600->SetMarkerStyle(kFullDiamond);
	h_DoublePhoton_Signal_MET1600->SetLineColor(kCyan);
	h_DoublePhoton_Signal_MET1600->SetMarkerColor(kCyan);
	
	
	h_DoublePhoton_MET->SetMarkerStyle(kFullDotLarge);
	h_DoublePhoton_MET->SetLineColor(1);
	h_DoublePhoton_MET->GetXaxis()->SetRangeUser(xlow,xup);
	
	
	TCanvas *c1 = new TCanvas("c1","stacked hists",1200,900);
	
	TPad *pad1 = new TPad("pad1","pad1",0,0.3,1,1);
	
	
	pad1->Draw();
	pad1->cd();
	pad1->SetLogy();
	pad1->SetBottomMargin(0);
	gStyle->SetOptStat(0);
	
	h_met_EWK_error->SetTitle("");
	h_met_EWK_error->GetYaxis()->SetRangeUser(0.0002,1000);
	h_met_EWK_error->GetXaxis()->SetRangeUser(xlow, xup);
	h_met_EWK_error->GetYaxis()->SetTitle("Events/GeV");
	h_met_EWK_error->GetYaxis()->SetTitleOffset(0.78);
	h_met_EWK_error->GetYaxis()->SetTitleSize(0.08);
	h_met_EWK_error->Draw();
	hs->Draw("hist sames");
	h_met_error->Draw("e2 sames");
        //h_met_QCD_plus_EWK->Draw("hist sames");
	h_DoublePhoton_MET->Draw("sames");
	h_DoublePhoton_Signal_MET1400->Draw("sames");
	h_DoublePhoton_Signal_MET1600->Draw("sames");
	//h_met_signal_onepoint->Draw("sames");
	TLegend *leg = new TLegend(0.5,0.6,0.9,0.9); // cms wants 0.5,0.6,0.9,0.9
	leg->SetFillColor(kWhite);
	leg->SetTextFont(42); // cms wants 42
	leg->SetBorderSize(0);
	leg->SetShadowColor(kWhite);
	leg->SetFillStyle(0);
	leg->AddEntry(h_DoublePhoton_MET,"Data","lep");
	leg->AddEntry(h_met_QCD_error,"QCD","f");
	leg->AddEntry(h_met_EWK_error,"EWK","f");
        leg->AddEntry(h_met_error, "combined uncertainty","f");
	leg->AddEntry(h_DoublePhoton_Signal_MET1400, "T5gg, M_{#tilde{g}} = 1.4 TeV, M_{#chi_{2}^{0}} = 0.6 TeV","lep");
	leg->AddEntry(h_DoublePhoton_Signal_MET1600, "T5gg, M_{#tilde{g}} = 1.6 TeV, M_{#chi_{2}^{0}} = 0.6 TeV","lep");
	//leg->AddEntry(h_met_signal_onepoint, "signal E_{T}^{miss}","lep");
	leg->Draw();
	tex1->Draw();
	tex2->Draw();
	tex3->Draw();
	
	
	
	c1->cd();
	TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3);
	
	pad2->Draw();
	pad2->cd();
	pad2->SetTopMargin(0);
	pad2->SetBottomMargin(0.27);
	TH1F *h2 = (TH1F*)h_DoublePhoton_MET->Clone("h2");
	h2->Reset();
	h2->GetYaxis()->SetTitle("#gamma#gamma/bkg");
	h2->GetXaxis()->SetTitle("E_{T}^{miss} (GeV)");
	h2->GetXaxis()->SetTitleOffset(0.82);
	
	TH1F *h3 = (TH1F*)h_DoublePhoton_MET->Clone("h3");
	h3->Reset();
	h3->GetYaxis()->SetTitle("#gamma#gamma/bkg");
	h3->GetXaxis()->SetTitle("E_{T}^{miss} (GeV)");
	h3->GetXaxis()->SetTitleOffset(0.82);
	
	TH1F *h4 = (TH1F*)h_DoublePhoton_MET->Clone("h4");
	h4->Reset();
	h4->GetYaxis()->SetTitle("#gamma#gamma/bkg");
	h4->GetXaxis()->SetTitle("E_{T}^{miss} (GeV)");
	h4->GetXaxis()->SetTitleOffset(0.82);
	
	
	for(int i=0;i<h_DoublePhoton_MET->GetNbinsX();++i){
	  double y = h_DoublePhoton_MET->GetBinContent(i+1);
	  double erry = h_DoublePhoton_MET->GetBinError(i+1);
	  double y1  = h_met_QCD_error->GetBinContent(i+1);
	  double erry1 = h_met_QCD_error->GetBinError(i+1);
	  double z1  = h_met_EWK_error->GetBinContent(i+1);
	  double errz1  = h_met_EWK_error->GetBinError(i+1);
	  double central = y1+z1;
	  double r = y1+z1;
	  double errr = sqrt(erry1*erry1+errz1*errz1);
	  double sys = h_met_error->GetBinError(i+1)/(central);
	  h3->SetBinContent(i+1,1);
	  h3->SetBinError(i+1,sys);
	  if(r!=0)h2->SetBinContent(i+1,y/r);
	  
	  double erz(0), erstat(0);
	  if(y!=0 && r!=0)erz= (y/r)*sqrt((erry/y)*(erry/y)+(errr/r)*(errr/r));
	  if(i<11 && r!=0)h4->SetBinContent(i,y/r);
	  if(i<11)h4->SetBinError(i+1,erz);
	  if(r!=0)erstat= erry/r;
	  h2->SetBinError(i+1,erstat);
	}
	
	h3->GetXaxis()->SetRangeUser(xlow,xup);
	h3->GetXaxis()->SetLabelSize(0.15);
	h3->GetXaxis()->SetTitleSize(0.13);
	h3->GetXaxis()->SetTitle("E_{T}^{miss} (GeV)");
	h3->GetXaxis()->SetTitleOffset(0.97);
	h3->GetYaxis()->SetTitle("data/bkg");
	h3->GetYaxis()->SetRangeUser(0.2,2.5);
	h3->GetYaxis()->SetNdivisions(3);
	h3->GetYaxis()->SetLabelSize(0.16);
	h3->GetYaxis()->SetTitleOffset(0.25);
        h3->GetYaxis()->SetTitleSize(0.17);
	h3->SetTitle("");
	h3->GetYaxis()->CenterTitle();
	h3->SetFillStyle(1001);
        h3->SetFillColor(kGray);
	h3->SetLineColor(kGray);
	h3->SetMarkerColor(kGray);
// 	TLegend *leg2 = new TLegend(0.5,0.6,0.9,0.9); // cms wants 0.5,0.6,0.9,0.9
// 	leg2->SetFillColor(kWhite);
// 	leg2->SetTextFont(42); // cms wants 42
// 	leg2->SetBorderSize(0);
// 	leg2->SetShadowColor(kWhite);
// 	leg2->SetFillStyle(0);
// 	leg2->AddEntry(h3, "Systematic error", "F");
// 	leg2->AddEntry(h2, "Statistical error","lep");
// 	leg2->SetFillColor(0);
// 	leg2->SetTextSize(0.065);
	TLine *lin1 = new TLine(xlow,1,xup,1);
        lin1->SetLineStyle(2);
	h3->Draw("e2");
	h2->Draw("ep same");
	//leg2->Draw("same");
	lin1->Draw();
	
	
	c1->SaveAs(OutputFolder+"/Gamma_QCD_EWK_FinalMET.eps");
	c1->SaveAs(OutputFolder+"/Gamma_QCD_EWK_FinalMET.pdf");
	c1->SaveAs(OutputFolder+"/Gamma_QCD_EWK_FinalMET.png");
	c1->Update();
	
	TCanvas *R = new TCanvas("R","Ratio",600,450); //1200,900
	R->cd();
	gStyle->SetOptStat(0);
	
	TLegend *leg3 = new TLegend(0.9, 0.7, 0.9, 0.9); //0.9, 0.7, 0.7, 0.9
	leg3->AddEntry(h4, "Sys #oplus Stat", "lep");
	leg3->SetFillColor(kWhite);
	leg3->SetTextFont(42); // cms wants 42
	leg3->SetBorderSize(0);
	leg3->SetShadowColor(kWhite);
	leg3->SetFillStyle(0);
	leg3->SetTextSize(0.040);
	h4->GetYaxis()->SetRangeUser(0.2,2.0);
	h4->Draw("ep same");
	leg3->Draw("same");
	
	
	TCanvas *B = new TCanvas("B","EWK E_{T}^{miss}",600,450); //1200,900
	B->cd();
	B->SetLogy();
	h_met_EWK_error->Draw();
	tex1->Draw();
	tex2->Draw();
	B->SaveAs(OutputFolder+"/EWKBackground_Symmetric_NoErBar.eps");
	
	f->Close();
	FQCD->Close();
	FEWK->Close();
	
}
void makePlots_hltEleHT_TTcr( bool printPDF_ = false, int useSample_ = 0 ){

  TH1::SetDefaultSumw2();

  int NumSamples = 3;
  TFile* file[NumSamples];
  file[0] = new TFile("HistoFiles/hltEleHT_treeReader_TTcr_TT_13TeV_Spring15_Asympt25ns_histo.root");
  file[1] = new TFile("HistoFiles/hltEleHT_treeReader_TTcr_ttHTobb_M125_13TeV_powheg_pythia8_Spring15_Asympt25ns_histo.root");
  file[2] = new TFile("HistoFiles/hltEleHT_treeReader_TTcr_SingleElectron_Run2015D_PromptReco_254231_258158_histo.root");

  std::vector<TString> histLabels(NumSamples);
  histLabels[0] = "TTJets";
  histLabels[1] = "ttHTobb";
  histLabels[2] = "Data";

  Color_t color[5];
  color[0] = kBlack;
  color[1] = kBlue;
  color[2] = kRed;
  color[3] = kGreen+1;

  // color[2] = kBlack;
  // color[3] = kGreen+1;
  // color[4] = kMagenta+2;
  // color[5] = kRed+1;
  // color[6] = kGreen-5;
  // color[7] = kRed+3;

  std::vector<std::vector<int> > projection_start_bins;
  std::vector<std::vector<int> > projection_end_bins;
  std::vector<std::vector<TString> > projection_labels;

  // elePt
  std::vector<int> proj_elePt_start_bins;
  proj_elePt_start_bins.push_back(1);
  proj_elePt_start_bins.push_back(4);
  proj_elePt_start_bins.push_back(6);
  proj_elePt_start_bins.push_back(7);

  std::vector<int> proj_elePt_end_bins;
  proj_elePt_end_bins.push_back(12);
  proj_elePt_end_bins.push_back(5);
  proj_elePt_end_bins.push_back(8);
  proj_elePt_end_bins.push_back(12);

  std::vector<TString> proj_elePt_labels;
  proj_elePt_labels.push_back("elePt30toInf");
  proj_elePt_labels.push_back("elePt30to50");
  proj_elePt_labels.push_back("elePt50to80");
  proj_elePt_labels.push_back("elePt80toInf");

  // numJet
  std::vector<int> proj_numJet_start_bins;
  proj_numJet_start_bins.push_back(1);
  proj_numJet_start_bins.push_back(1);
  proj_numJet_start_bins.push_back(4);
  proj_numJet_start_bins.push_back(5);

  std::vector<int> proj_numJet_end_bins;
  proj_numJet_end_bins.push_back(8);
  proj_numJet_end_bins.push_back(3);
  proj_numJet_end_bins.push_back(4);
  proj_numJet_end_bins.push_back(8);

  std::vector<TString> proj_numJet_labels;
  proj_numJet_labels.push_back("numJet0toInf");
  proj_numJet_labels.push_back("numJet0to2");
  proj_numJet_labels.push_back("numJet3to3");
  proj_numJet_labels.push_back("numJet4toInf");


  projection_start_bins.push_back(proj_elePt_start_bins);
  projection_end_bins.push_back(proj_elePt_end_bins);
  projection_labels.push_back(proj_elePt_labels);

  projection_start_bins.push_back(proj_numJet_start_bins);
  projection_end_bins.push_back(proj_numJet_end_bins);
  projection_labels.push_back(proj_numJet_labels);

  projection_start_bins.push_back(proj_elePt_start_bins);
  projection_end_bins.push_back(proj_elePt_end_bins);
  projection_labels.push_back(proj_elePt_labels);

  projection_start_bins.push_back(proj_elePt_start_bins);
  projection_end_bins.push_back(proj_elePt_end_bins);
  projection_labels.push_back(proj_elePt_labels);

  std::vector<int> NumProjBins;
  NumProjBins.push_back( int(proj_elePt_labels.size()) );
  NumProjBins.push_back( int(proj_numJet_labels.size()) );
  NumProjBins.push_back( int(proj_elePt_labels.size()) );
  NumProjBins.push_back( int(proj_elePt_labels.size()) );



  TString dirprefix = "Images/Images_2015_10_13_hltEleHT_TTcr_" + histLabels[useSample_] + "/";

  struct stat st;
  if( stat(dirprefix.Data(),&st) != 0 )  mkdir(dirprefix.Data(),0777);


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

  std::vector<std::string> histoname1;
  std::vector<std::string> histoname2;
  std::vector<std::string> histoname3;

  histoname1.push_back("h_HT30");
  histoname1.push_back("h_HT30er");
  histoname1.push_back("h_HT30_4j");

  histoname2.push_back("elePt");
  histoname2.push_back("numJet");
  histoname2.push_back("eleEBPt");
  histoname2.push_back("eleEEPt");


  histoname3.push_back("h_event_selection");


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

  TGaxis::SetMaxDigits(3);

  TString lumiinfo = "553 pb^{-1} (13 TeV)";
  TLatex LumiInfoLatex(0.65, 0.94, lumiinfo);
  LumiInfoLatex.SetNDC(); LumiInfoLatex.SetTextFont(42);
  LumiInfoLatex.SetTextSize(0.04);

  //TString cmsinfo =   "CMS Preliminary";
  TString cmsinfo =   "CMS";
  TLatex CMSInfoLatex(0.13, 0.94, cmsinfo);
  CMSInfoLatex.SetNDC(); CMSInfoLatex.SetTextFont(42);
  CMSInfoLatex.SetTextFont(61);
  CMSInfoLatex.SetTextSize(0.055); //SBOUTLE

  std::string publishinfo =   "Preliminary"; //DPUIGH
  TLatex PublishInfoLatex(0.26, 0.94, publishinfo.c_str()); //SBOUTLE
  PublishInfoLatex.SetNDC();
  PublishInfoLatex.SetTextFont(52);
  PublishInfoLatex.SetTextSize(0.045); //SBOUTLE


  TString plotname;

  TCanvas* c1 = new TCanvas("c1", "c1", 600,700);


  TH2D* h_L1HTT_elePt = (TH2D*)file[useSample_]->Get("h_L1HTT_elePt");
  TH2D* h_HT30_HT30er = (TH2D*)file[useSample_]->Get("h_HT30_HT30er");
  TH2D* h_HT30_L1HTT = (TH2D*)file[useSample_]->Get("h_HT30_L1HTT");

  TProfile* p_L1HTT_elePt = (TProfile*)h_L1HTT_elePt->ProfileX("p_L1HTT_elePt");
  // TProfile* p_HT30_HT30er = (TProfile*)h_HT30_HT30er->ProfileX("p_HT30_HT30er");
  // TProfile* p_HT30_L1HTT = (TProfile*)h_HT30_L1HTT->ProfileX("p_HT30_L1HTT");

  p_L1HTT_elePt->SetMarkerStyle(20);

  h_L1HTT_elePt->Draw("colz");
  p_L1HTT_elePt->Draw("pe1same");
  plotname = dirprefix + "h_L1HTT_elePt" + "_2D_colz.png";
  c1->Print(plotname);

  h_HT30_HT30er->Draw("colz");
  //p_HT30_HT30er->Draw("pe1same");
  plotname = dirprefix + "h_HT30_HT30er" + "_2D_colz.png";
  c1->Print(plotname);

  h_HT30_L1HTT->Draw("colz");
  //p_HT30_L1HTT->Draw("pe1same");
  plotname = dirprefix + "h_HT30_L1HTT" + "_2D_colz.png";
  c1->Print(plotname);


  for( int i=0; i<int(histoname1.size()); i++ ){

    for( int j=0; j<int(histoname2.size()); j++ ){

      for( int k=0; k<2; k++ ){

	TString temp = histoname1[i];

	TString suffix = histoname2[j];

	TString l1suffix = ( k==0 ) ? "125" : "100";

	if( temp!="h_HT30" && suffix!="elePt" ) continue;

	TString temp_L1 = temp + "_L1HTT" + l1suffix + "_" + suffix;
	TString temp_HLT = temp + "_L1HTT" + l1suffix + "_passHLTEle27HT200_" + suffix;

	TString temp_mh = temp;
	temp_mh.ReplaceAll("h_","");


	temp = temp + "_" + suffix;

	//TLegend *legend = new TLegend(0.2,0.83,0.9,0.89);
	TLegend *legend = new TLegend(0.2,0.85,0.9,0.91);

	legend->SetFillColor(kWhite);
	legend->SetLineColor(kWhite);
	legend->SetShadowColor(kWhite);
	legend->SetTextFont(42);
	legend->SetTextSize(0.04);

	legend->SetNColumns(2);

	int rebin = ( useSample_==2 ) ? 25 : 10;


	TH2D* h_all = (TH2D*)file[useSample_]->Get(temp)->Clone(temp+"_"+suffix+"_"+l1suffix);
	TH2D* h_l1t = (TH2D*)file[useSample_]->Get(temp_L1)->Clone(temp_L1+"_"+suffix+"_"+l1suffix);
	TH2D* h_hlt = (TH2D*)file[useSample_]->Get(temp_HLT)->Clone(temp_HLT+"_"+suffix+"_"+l1suffix);


	TH2D* h_temp_hlt_all = (TH2D*)h_all->Clone("h_temp_hlt_all_"+suffix+"_"+l1suffix);
	TH2D* h_temp_l1t_all = (TH2D*)h_all->Clone("h_temp_l1t_all_"+suffix+"_"+l1suffix);
	TH2D* h_temp_hlt_l1t = (TH2D*)h_l1t->Clone("h_temp_hlt_l1t_"+suffix+"_"+l1suffix);

	TH2D* h_ratio_hlt_all = (TH2D*)h_hlt->Clone("h_ratio_hlt_all_"+suffix+"_"+l1suffix);
	TH2D* h_ratio_l1t_all = (TH2D*)h_l1t->Clone("h_ratio_l1t_all_"+suffix+"_"+l1suffix);
	TH2D* h_ratio_hlt_l1t = (TH2D*)h_hlt->Clone("h_ratio_hlt_l1t_"+suffix+"_"+l1suffix);

	h_temp_hlt_all->RebinY(rebin);
	h_temp_l1t_all->RebinY(rebin);
	h_temp_hlt_l1t->RebinY(rebin);

	h_ratio_hlt_all->RebinY(rebin);
	h_ratio_l1t_all->RebinY(rebin);
	h_ratio_hlt_l1t->RebinY(rebin);

	h_ratio_hlt_all->Divide(h_temp_hlt_all);
	h_ratio_l1t_all->Divide(h_temp_l1t_all);
	h_ratio_hlt_l1t->Divide(h_temp_hlt_l1t);


	TProfile* p_all = (TProfile*)h_all->ProfileX("p_all");
	TProfile* p_l1t = (TProfile*)h_l1t->ProfileX("p_l1t");
	TProfile* p_hlt = (TProfile*)h_hlt->ProfileX("p_hlt");

	p_all->SetMarkerStyle(20);
	p_l1t->SetMarkerStyle(20);
	p_hlt->SetMarkerStyle(20);

	h_all->Draw("colz");
	p_all->Draw("pe1same");
	plotname = dirprefix + temp + "_2D_colz.png";
	c1->Print(plotname);

	h_l1t->Draw("colz");
	p_l1t->Draw("pe1same");
	plotname = dirprefix + temp_L1 + "_2D_colz.png";
	c1->Print(plotname);

	h_hlt->Draw("colz");
	p_hlt->Draw("pe1same");
	plotname = dirprefix + temp_HLT + "_2D_colz.png";
	c1->Print(plotname);



	h_ratio_hlt_all->SetStats(0);
	h_ratio_hlt_all->GetYaxis()->SetRangeUser(0.,400.);
	h_ratio_hlt_all->Draw("colz");
	plotname = dirprefix + "h_ratio_hlt_all" + "_2D_colz.png";
	c1->Print(plotname);

	h_ratio_l1t_all->SetStats(0);
	h_ratio_l1t_all->GetYaxis()->SetRangeUser(0.,400.);
	h_ratio_l1t_all->Draw("colz");
	plotname = dirprefix + "h_ratio_l1t_all" + "_2D_colz.png";
	c1->Print(plotname);

	h_ratio_hlt_l1t->SetStats(0);
	h_ratio_hlt_l1t->GetYaxis()->SetRangeUser(0.,400.);
	h_ratio_hlt_l1t->Draw("colz");
	plotname = dirprefix + "h_ratio_hlt_l1t" + "_2D_colz.png";
	c1->Print(plotname);

	int numProjBin = NumProjBins[j];

	TH1D* h_py_all[numProjBin];
	TH1D* h_py_l1t[numProjBin];
	TH1D* h_py_hlt[numProjBin];

	TEfficiency* eff_hlt_all[numProjBin];
	TEfficiency* eff_l1t_all[numProjBin];
	TEfficiency* eff_hlt_l1t[numProjBin];

	for( int iBin=0; iBin<numProjBin; iBin++ ){

	  int bin_start = projection_start_bins[j][iBin];
	  int bin_end   = projection_end_bins[j][iBin];
	  h_py_all[iBin] = (TH1D*)h_all->ProjectionY(Form("h_py_all_%d",iBin),bin_start,bin_end);
	  h_py_l1t[iBin] = (TH1D*)h_l1t->ProjectionY(Form("h_py_l1t_%d",iBin),bin_start,bin_end);
	  h_py_hlt[iBin] = (TH1D*)h_hlt->ProjectionY(Form("h_py_hlt_%d",iBin),bin_start,bin_end);

	  h_py_all[iBin]->Rebin(rebin);
	  h_py_l1t[iBin]->Rebin(rebin);
	  h_py_hlt[iBin]->Rebin(rebin);

	  eff_l1t_all[iBin] = makeEfficiency(h_py_l1t[iBin], h_py_all[iBin]);
	  eff_hlt_l1t[iBin] = makeEfficiency(h_py_hlt[iBin], h_py_l1t[iBin]);
	  eff_hlt_all[iBin] = makeEfficiency(h_py_hlt[iBin], h_py_all[iBin]);

	  eff_l1t_all[iBin]->SetLineColor(color[iBin]);
	  eff_l1t_all[iBin]->SetMarkerColor(color[iBin]);
	  eff_l1t_all[iBin]->SetMarkerStyle(20);

	  eff_hlt_l1t[iBin]->SetLineColor(color[iBin]);
	  eff_hlt_l1t[iBin]->SetMarkerColor(color[iBin]);
	  eff_hlt_l1t[iBin]->SetMarkerStyle(20);

	  eff_hlt_all[iBin]->SetLineColor(color[iBin]);
	  eff_hlt_all[iBin]->SetMarkerColor(color[iBin]);
	  eff_hlt_all[iBin]->SetMarkerStyle(20);

	  legend->AddEntry(eff_l1t_all[iBin], projection_labels[j][iBin],"pe1");
	}



	h_py_all[0]->SetStats(0);
	h_py_all[0]->GetYaxis()->SetTitle("Efficiency");

	h_py_all[0]->GetYaxis()->SetRangeUser(0.,1.15);
	h_py_all[0]->GetXaxis()->SetRangeUser(0.,600.);
	// h_data_all->SetStats(0);

	c1->SetTopMargin(.07);
	c1->SetRightMargin(.05);

	// h_data_all->GetYaxis()->SetTitleOffset(1.0);
	// h_data_all->GetYaxis()->SetTitleSize(0.05);

	// h_data_all->GetYaxis()->SetRangeUser(0.,1.15);
	// if( temp.Contains("_pt") ){
	//   h_data_all->GetXaxis()->SetRangeUser(0.,150.);
	//   myRatio->GetXaxis()->SetRangeUser(0.,150.);
	// }


	//// l1t_all
	h_py_all[0]->Draw("axis");
	for( int iBin=0; iBin<numProjBin; iBin++ ) eff_l1t_all[iBin]->Draw("pe1same");
	legend->Draw();
	LumiInfoLatex.Draw();
	CMSInfoLatex.Draw();
	PublishInfoLatex.Draw();

	plotname = dirprefix + temp_mh + "_"+suffix+"_l1t" + l1suffix + "_all_lin.png";
	c1->Print(plotname);

	plotname = dirprefix + temp_mh + "_"+suffix+"_l1t" + l1suffix + "_all_lin.pdf";
	if( printPDF_ ) c1->Print(plotname);


	//// hlt_all
	h_py_all[0]->Draw("axis");
	for( int iBin=0; iBin<numProjBin; iBin++ ) eff_hlt_all[iBin]->Draw("pe1same");
	legend->Draw();
	LumiInfoLatex.Draw();
	CMSInfoLatex.Draw();
	PublishInfoLatex.Draw();

	plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_all_lin.png";
	c1->Print(plotname);

	plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_all_lin.pdf";
	if( printPDF_ ) c1->Print(plotname);


	//// hlt_l1t
	h_py_all[0]->Draw("axis");
	for( int iBin=0; iBin<numProjBin; iBin++ ) eff_hlt_l1t[iBin]->Draw("pe1same");
	legend->Draw();
	LumiInfoLatex.Draw();
	CMSInfoLatex.Draw();
	PublishInfoLatex.Draw();

	plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_lin.png";
	c1->Print(plotname);

	plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_lin.pdf";
	if( printPDF_ ) c1->Print(plotname);




	h_py_all[0]->GetYaxis()->SetRangeUser(0.85,1.15);



	//// l1t_all
	h_py_all[0]->Draw("axis");
	for( int iBin=0; iBin<numProjBin; iBin++ ) eff_l1t_all[iBin]->Draw("pe1same");
	legend->Draw();
	LumiInfoLatex.Draw();
	CMSInfoLatex.Draw();
	PublishInfoLatex.Draw();

	plotname = dirprefix + temp_mh + "_"+suffix+"_l1t" + l1suffix + "_all_lin_zoom.png";
	c1->Print(plotname);

	plotname = dirprefix + temp_mh + "_"+suffix+"_l1t" + l1suffix + "_all_lin_zoom.pdf";
	if( printPDF_ ) c1->Print(plotname);


	//// hlt_all
	h_py_all[0]->Draw("axis");
	for( int iBin=0; iBin<numProjBin; iBin++ ) eff_hlt_all[iBin]->Draw("pe1same");
	legend->Draw();
	LumiInfoLatex.Draw();
	CMSInfoLatex.Draw();
	PublishInfoLatex.Draw();

	plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_all_lin_zoom.png";
	c1->Print(plotname);

	plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_all_lin_zoom.png";
	if( printPDF_ ) c1->Print(plotname);


	//// hlt_l1t
	h_py_all[0]->Draw("axis");
	for( int iBin=0; iBin<numProjBin; iBin++ ) eff_hlt_l1t[iBin]->Draw("pe1same");
	legend->Draw();
	LumiInfoLatex.Draw();
	CMSInfoLatex.Draw();
	PublishInfoLatex.Draw();

	plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_lin_zoom.png";
	c1->Print(plotname);

	plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_lin_zoom.pdf";
	if( printPDF_ ) c1->Print(plotname);


	delete legend;
      } // end loop on hists
    }
  }


  if( true ){

    TString temp = "h_HT30";

    TString temp_L1 = temp + "_L1HTT125";
    TString temp_HLT = temp + "_L1HTT125_passHLTEle27HT200";

    TString temp_mh = temp;
    temp_mh.ReplaceAll("h_","");

    //TLegend *legend = new TLegend(0.2,0.83,0.9,0.89);
    TLegend *legend = new TLegend(0.2,0.87,0.85,0.91);

    legend->SetFillColor(kWhite);
    legend->SetLineColor(kWhite);
    legend->SetShadowColor(kWhite);
    legend->SetTextFont(42);
    legend->SetTextSize(0.04);

    legend->SetNColumns(3);

    int rebin = 25;

    TH1D* h_all[NumSamples];
    TH1D* h_l1t[NumSamples];
    TH1D* h_hlt[NumSamples];

    TEfficiency* eff_hlt_all[NumSamples];
    TEfficiency* eff_l1t_all[NumSamples];
    TEfficiency* eff_hlt_l1t[NumSamples];

    for( int iSample=0; iSample<NumSamples; iSample++ ){
      h_all[iSample] = (TH1D*)file[iSample]->Get(temp.Data())->Clone(Form("%s_%s",temp.Data(),histLabels[iSample].Data()));
      h_l1t[iSample] = (TH1D*)file[iSample]->Get(temp_L1.Data())->Clone(Form("%s_%s",temp.Data(),histLabels[iSample].Data()));
      h_hlt[iSample] = (TH1D*)file[iSample]->Get(temp_HLT.Data())->Clone(Form("%s_%s",temp.Data(),histLabels[iSample].Data()));

      h_all[iSample]->Rebin(rebin);
      h_l1t[iSample]->Rebin(rebin);
      h_hlt[iSample]->Rebin(rebin);

      eff_l1t_all[iSample] = makeEfficiency(h_l1t[iSample], h_all[iSample]);
      eff_hlt_l1t[iSample] = makeEfficiency(h_hlt[iSample], h_l1t[iSample]);
      eff_hlt_all[iSample] = makeEfficiency(h_hlt[iSample], h_all[iSample]);

      eff_l1t_all[iSample]->SetLineColor(color[iSample]);
      eff_l1t_all[iSample]->SetMarkerColor(color[iSample]);
      eff_l1t_all[iSample]->SetMarkerStyle(20);

      eff_hlt_l1t[iSample]->SetLineColor(color[iSample]);
      eff_hlt_l1t[iSample]->SetMarkerColor(color[iSample]);
      eff_hlt_l1t[iSample]->SetMarkerStyle(20);

      eff_hlt_all[iSample]->SetLineColor(color[iSample]);
      eff_hlt_all[iSample]->SetMarkerColor(color[iSample]);
      eff_hlt_all[iSample]->SetMarkerStyle(20);

      legend->AddEntry(eff_l1t_all[iSample], histLabels[iSample],"pl");
    }



    h_all[0]->SetStats(0);
    h_all[0]->GetYaxis()->SetTitle("Efficiency");

    h_all[0]->GetYaxis()->SetRangeUser(0.,1.15);
    h_all[0]->GetXaxis()->SetRangeUser(0.,600.);


    //// l1t_all
    h_all[0]->Draw("axis");
    for( int iSample=0; iSample<NumSamples; iSample++ ) eff_l1t_all[iSample]->Draw("pe1same");
    legend->Draw();
    LumiInfoLatex.Draw();
    CMSInfoLatex.Draw();
    PublishInfoLatex.Draw();

    plotname = dirprefix + temp_mh + "_compareSamples_l1t_all_lin.png";
    c1->Print(plotname);

    plotname = dirprefix + temp_mh + "_compareSamples_l1t_all_lin.pdf";
    if( printPDF_ ) c1->Print(plotname);


    //// hlt_all
    h_all[0]->Draw("axis");
    for( int iSample=0; iSample<NumSamples; iSample++ ) eff_hlt_all[iSample]->Draw("pe1same");
    legend->Draw();
    LumiInfoLatex.Draw();
    CMSInfoLatex.Draw();
    PublishInfoLatex.Draw();

    plotname = dirprefix + temp_mh + "_compareSamples_hlt_all_lin.png";
    c1->Print(plotname);

    plotname = dirprefix + temp_mh + "_compareSamples_hlt_all_lin.pdf";
    if( printPDF_ ) c1->Print(plotname);


    //// hlt_l1t
    h_all[0]->Draw("axis");
    for( int iSample=0; iSample<NumSamples; iSample++ ) eff_hlt_l1t[iSample]->Draw("pe1same");
    legend->Draw();
    LumiInfoLatex.Draw();
    CMSInfoLatex.Draw();
    PublishInfoLatex.Draw();

    plotname = dirprefix + temp_mh + "_compareSamples_hlt_l1t_lin.png";
    c1->Print(plotname);

    plotname = dirprefix + temp_mh + "_compareSamples_hlt_l1t_lin.pdf";
    if( printPDF_ ) c1->Print(plotname);




    h_all[0]->GetYaxis()->SetRangeUser(0.85,1.15);



    //// l1t_all
    h_all[0]->Draw("axis");
    for( int iSample=0; iSample<NumSamples; iSample++ ) eff_l1t_all[iSample]->Draw("pe1same");
    legend->Draw();
    LumiInfoLatex.Draw();
    CMSInfoLatex.Draw();
    PublishInfoLatex.Draw();

    plotname = dirprefix + temp_mh + "_compareSamples_l1t_all_lin_zoom.png";
    c1->Print(plotname);

    plotname = dirprefix + temp_mh + "_compareSamples_l1t_all_lin_zoom.pdf";
    if( printPDF_ ) c1->Print(plotname);


    //// hlt_all
    h_all[0]->Draw("axis");
    for( int iSample=0; iSample<NumSamples; iSample++ ) eff_hlt_all[iSample]->Draw("pe1same");
    legend->Draw();
    LumiInfoLatex.Draw();
    CMSInfoLatex.Draw();
    PublishInfoLatex.Draw();

    plotname = dirprefix + temp_mh + "_compareSamples_hlt_all_lin_zoom.png";
    c1->Print(plotname);

    plotname = dirprefix + temp_mh + "_compareSamples_hlt_all_lin_zoom.pdf";
    if( printPDF_ ) c1->Print(plotname);


    //// hlt_l1t
    h_all[0]->Draw("axis");
    for( int iSample=0; iSample<NumSamples; iSample++ ) eff_hlt_l1t[iSample]->Draw("pe1same");
    legend->Draw();
    LumiInfoLatex.Draw();
    CMSInfoLatex.Draw();
    PublishInfoLatex.Draw();

    plotname = dirprefix + temp_mh + "_compareSamples_hlt_l1t_lin_zoom.png";
    c1->Print(plotname);

    plotname = dirprefix + temp_mh + "_compareSamples_hlt_l1t_lin_zoom.pdf";
    if( printPDF_ ) c1->Print(plotname);


    delete legend;
  }


  if( true ){

    TString temp = "h_HT30";

    std::vector<TString> useL1Name;
    useL1Name.push_back(temp + "_L1HTT125");
    useL1Name.push_back(temp + "_L1HTT100");

    std::vector<TString> labelL1Name;
    labelL1Name.push_back("L1_HTT125");
    labelL1Name.push_back("L1_HTT100");

    std::vector<Color_t> useColor;
    useColor.push_back(kBlack);
    useColor.push_back(kRed);

    TString temp_mh = temp;
    temp_mh.ReplaceAll("h_","");

    //TLegend *legend = new TLegend(0.2,0.83,0.9,0.89);
    TLegend *legend = new TLegend(0.15,0.83,0.85,0.89);

    legend->SetFillColor(kWhite);
    legend->SetLineColor(kWhite);
    legend->SetShadowColor(kWhite);
    legend->SetTextFont(42);
    legend->SetTextSize(0.04);

    legend->SetNColumns(2);

    int rebin = 25;

    int NumL1Samples = int(useL1Name.size());

    TH1D* h_all[NumL1Samples];
    TH1D* h_l1t[NumL1Samples];

    TEfficiency* eff_l1t_all[NumL1Samples];

    for( int iSample=0; iSample<NumL1Samples; iSample++ ){
      h_all[iSample] = (TH1D*)file[useSample_]->Get(temp)->Clone(Form("%s_%s",temp.Data(),labelL1Name[iSample].Data()));
      h_l1t[iSample] = (TH1D*)file[useSample_]->Get(useL1Name[iSample])->Clone(Form("%s_%s",useL1Name[iSample].Data(),labelL1Name[iSample].Data()));

      h_all[iSample]->Rebin(rebin);
      h_l1t[iSample]->Rebin(rebin);

      eff_l1t_all[iSample] = makeEfficiency(h_l1t[iSample], h_all[iSample]);

      eff_l1t_all[iSample]->SetLineColor(useColor[iSample]);
      eff_l1t_all[iSample]->SetMarkerColor(useColor[iSample]);
      eff_l1t_all[iSample]->SetMarkerStyle(20);

      legend->AddEntry(eff_l1t_all[iSample], labelL1Name[iSample],"pl");
    }



    h_all[0]->SetStats(0);
    h_all[0]->GetYaxis()->SetTitle("Efficiency");

    h_all[0]->GetYaxis()->SetRangeUser(0.,1.15);
    h_all[0]->GetXaxis()->SetRangeUser(0.,600.);



    //// l1t_all
    h_all[0]->Draw("axis");
    for( int iSample=0; iSample<NumL1Samples; iSample++ ) eff_l1t_all[iSample]->Draw("pe1same");
    legend->Draw();
    LumiInfoLatex.Draw();
    CMSInfoLatex.Draw();
    PublishInfoLatex.Draw();

    plotname = dirprefix + temp_mh + "_compareL1_l1t_all_lin.png";
    c1->Print(plotname);

    plotname = dirprefix + temp_mh + "_compareL1_l1t_all_lin.pdf";
    if( printPDF_ ) c1->Print(plotname);



    h_all[0]->GetYaxis()->SetRangeUser(0.85,1.15);



    //// l1t_all
    h_all[0]->Draw("axis");
    for( int iSample=0; iSample<NumL1Samples; iSample++ ) eff_l1t_all[iSample]->Draw("pe1same");
    legend->Draw();
    LumiInfoLatex.Draw();
    CMSInfoLatex.Draw();
    PublishInfoLatex.Draw();

    plotname = dirprefix + temp_mh + "_compareL1_l1t_all_lin_zoom.png";
    c1->Print(plotname);

    plotname = dirprefix + temp_mh + "_compareL1_l1t_all_lin_zoom.pdf";
    if( printPDF_ ) c1->Print(plotname);


    delete legend;
  }




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

  TCanvas* myC1 = new TCanvas("myC1", "myC1", 600,700);
  gStyle->SetPadBorderMode(0);
  gStyle->SetFrameBorderMode(0);
  Float_t small = 1.e-5;
  myC1->Divide(1,2,small,small);
  const float padding=1e-5; const float ydivide=0.3;
  myC1->GetPad(1)->SetPad( padding, ydivide + padding , 1-padding, 1-padding);
  myC1->GetPad(2)->SetPad( padding, padding, 1-padding, ydivide-padding);
  myC1->GetPad(1)->SetLeftMargin(.11);
  myC1->GetPad(2)->SetLeftMargin(.11);
  myC1->GetPad(1)->SetRightMargin(.05);
  myC1->GetPad(2)->SetRightMargin(.05);
  myC1->GetPad(1)->SetBottomMargin(.3);
  myC1->GetPad(2)->SetBottomMargin(.3);
  myC1->GetPad(1)->Modified();
  myC1->GetPad(2)->Modified();
  myC1->cd(1);
  gPad->SetBottomMargin(small);
  gPad->Modified();


  for( int i=0; i<int(histoname3.size()); i++ ){

    TString temp = histoname3[i];
    
    TString temp_mh = temp;
    temp_mh.ReplaceAll("h_","");

    //TLegend *legend = new TLegend(0.1,0.91,0.9,0.99);
    TLegend *legend = new TLegend(0.2,0.83,0.88,0.89);

    legend->SetFillColor(kWhite);
    legend->SetLineColor(kWhite);
    legend->SetShadowColor(kWhite);
    legend->SetTextFont(42);
    legend->SetTextSize(0.04);

    legend->SetNColumns(2);

    int rebin = 1;

    if( temp.Contains("_mass") ) rebin = 2;
    if( temp.Contains("_L1HTT") ) rebin = 2;
    if( temp.Contains("_met") ) rebin = 5;
    if( temp.Contains("_jet_") && temp.Contains("_pt") ) rebin = 10;
    if( temp.Contains("_jet_") && temp.Contains("_eta") ) rebin = 4;
    if( temp.Contains("_jet_") && temp.Contains("_phi") ) rebin = 4;
    if( temp.Contains("_csv") ) rebin = 8;

    if( temp.Contains("_diele_mass_closestZmass") ) rebin = 5;


    TH1D* h_data = (TH1D*)file[2]->Get(temp.Data());
    TH1D* h_mc   = (TH1D*)file[0]->Get(temp.Data());

    h_data->Rebin(rebin);
    h_mc->Rebin(rebin);

    if( temp.Contains("_numPV") ){
      h_mc->Scale( h_data->Integral() / h_mc->Integral() );
    }


    h_data->SetLineColor(color[0]);
    h_mc->SetLineColor(color[2]);

    h_data->SetMarkerColor(color[0]);
    h_mc->SetMarkerColor(color[2]);

    h_data->SetMarkerStyle(20);
    h_mc->SetMarkerStyle(20);

    legend->AddEntry(h_data,histLabels[2],"p");
    legend->AddEntry(h_mc,histLabels[0],"p");

    //c3->SetTopMargin(.05);
    //c1->SetRightMargin(.05);

    double ratioMax = 1.6;
    double ratioMin = 0.5;

    int nbins = h_data->GetNbinsX();

    double xmin = h_data->GetBinLowEdge(1);
    double xmax = h_data->GetBinLowEdge(nbins) + h_data->GetBinWidth(nbins);

    TH1D* myRatio = new TH1D("ratio", "", nbins, xmin, xmax );

    myRatio->SetStats(0);
    myRatio->Sumw2();
    myRatio->SetLineColor(kBlack);
    myRatio->SetMarkerColor(kBlack);
    myRatio->Divide(h_data,h_mc);

    myRatio->SetMinimum(ratioMin);
    myRatio->SetMaximum(ratioMax);
    //myRatio->GetYaxis()->SetNdivisions(50000+404);
    myRatio->GetYaxis()->SetNdivisions(50000+204);
    myRatio->GetYaxis()->SetLabelSize(0.1); //make y label bigger
    myRatio->GetXaxis()->SetLabelSize(0.1); //make y label bigger
    myRatio->GetXaxis()->SetTitleOffset(1.1);
    myRatio->GetXaxis()->SetTitle(h_data->GetXaxis()->GetTitle()); //make y label bigger
    myRatio->GetXaxis()->SetLabelSize(0.12);
    myRatio->GetXaxis()->SetLabelOffset(0.04);
    myRatio->GetXaxis()->SetTitleSize(0.12);
    myRatio->GetYaxis()->SetTitle("Data/MC");
    myRatio->GetYaxis()->SetTitleSize(0.09);
    myRatio->GetYaxis()->SetTitleOffset(.55);
    myC1->cd(2);
    gPad->SetTopMargin(small);
    gPad->SetTickx();
    gPad->Modified();

    myRatio->GetYaxis()->CenterTitle(kTRUE);


    if( temp.Contains("_selection") ){
      for( int iBin=0; iBin<nbins; iBin++ ) myRatio->GetXaxis()->SetBinLabel(iBin+1,h_data->GetXaxis()->GetBinLabel(iBin+1));
      myC1->GetPad(2)->SetBottomMargin(.4);
      myC1->GetPad(1)->SetRightMargin(.10);
      myC1->GetPad(2)->SetRightMargin(.10);
      myRatio->GetXaxis()->SetTitle("");
    }
    else{
      myC1->GetPad(2)->SetBottomMargin(.3);
      myC1->GetPad(1)->SetRightMargin(.05);
      myC1->GetPad(2)->SetRightMargin(.05);
    }

    h_data->SetStats(0);

    h_data->GetYaxis()->SetTitleOffset(1.0);
    h_data->GetYaxis()->SetTitleSize(0.05);

    h_data->GetYaxis()->SetTitle("Number of Events");


    int max_bin_data = h_data->GetMaximumBin();
    double max_data = h_data->GetBinContent(max_bin_data) + h_data->GetBinError(max_bin_data);

    int max_bin_mc = h_mc->GetMaximumBin();
    double max_mc = h_mc->GetBinContent(max_bin_mc) + h_mc->GetBinError(max_bin_mc);

    double max_content = std::max(max_data, max_mc);

    h_data->GetYaxis()->SetRangeUser(0.,1.2 * max_content);

    if( temp.Contains("_mass") ){
      h_data->GetXaxis()->SetRangeUser(40.,140.);
      myRatio->GetXaxis()->SetRangeUser(40.,140.);
    }

    if( temp.Contains("_met") ){
      h_data->GetXaxis()->SetRangeUser(0.,150.);
      myRatio->GetXaxis()->SetRangeUser(0.,150.);
    }
    // if( temp.Contains("_eta") ) h_all->GetYaxis()->SetRangeUser(0.4,1.1);
    // if( temp.Contains("_numGenPVs") ) h_all->GetYaxis()->SetRangeUser(0.4,1.1);
    // if( temp.Contains("_numJets") ) h_all->GetYaxis()->SetRangeUser(0.4,1.1);


    TLine* myLine;
    if( temp.Contains("_mass") )     myLine = new TLine(40, 1, 140, 1);
    else if( temp.Contains("_met") ) myLine = new TLine(0, 1, 150, 1);
    else                             myLine = new TLine(h_data->GetXaxis()->GetXmin(), 1, h_data->GetXaxis()->GetXmax(), 1);


    // HLT
    myC1->cd(1);
    h_data->Draw("pe1");
    h_mc->Draw("pe1same");
    legend->Draw();
    LumiInfoLatex.Draw();
    CMSInfoLatex.Draw();
    PublishInfoLatex.Draw();

    myC1->cd(2);
    myRatio->SetLineWidth(2);
    myRatio->Draw("pe1");
    myLine->Draw();

    plotname = dirprefix + temp_mh + "_data2mc_lin.png";
    myC1->Print(plotname);

    plotname = dirprefix + temp_mh + "_data2mc_lin.pdf";
    if( printPDF_ ) myC1->Print(plotname);


    // log
    h_data->GetYaxis()->SetRangeUser(0.4,12 * max_content);
    if( temp.Contains("_selection") ){
      h_data->GetYaxis()->SetRangeUser(400,12 * max_content);
    }

    myC1->cd(1);
    gPad->SetLogy(1);

    plotname = dirprefix + temp_mh + "_data2mc_log.png";
    myC1->Print(plotname);

    plotname = dirprefix + temp_mh + "_data2mc_log.pdf";
    if( printPDF_ ) myC1->Print(plotname);

    gPad->SetLogy(0);



    delete myRatio;
    delete myLine;
    delete legend;
  } // end loop on hists

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


  // Close the file
  for( int iFile=0; iFile<NumSamples; iFile++ ) file[iFile]->Close();
  std::cout << " Done! " << std::endl;
}
void spike_summarize(TString dirOut="./HPU2012/Rebin/rebin3/", int factor=3, TString graph_style="A*") {
  
  loadPresentationStyle();
  /*
    gStyle->SetCanvasBorderMode(0);
    gStyle->SetCanvasColor(kWhite);
    gStyle->SetCanvasDefH(600); //Height of canvas                                                     
    gStyle->SetCanvasDefW(600); //Width of canvas                                                                   
    gStyle->SetCanvasDefX(0);   //POsition on screen                                                                 
    gStyle->SetCanvasDefY(0);

    gStyle->SetTitleFont(42);
    gStyle->SetTitleColor(1);
    gStyle->SetTitleTextColor(1);
  */
  //gStyle->SetTitleFillColor(10);
  /*
    gStyle->SetTitleFontSize(0.05);
    gStyle->SetTitleColor(1, "XYZ");
    gStyle->SetTitleFont(42, "XYZ");
  */
  gStyle->SetTitleSize(0.05, "XYZ");
  gStyle->SetTitleYOffset(1.2);
  /*
    gStyle->SetLabelColor(1, "XYZ");
    gStyle->SetLabelFont(42, "XYZ");
    gStyle->SetLabelOffset(0.007, "XYZ");
    gStyle->SetLabelSize(0.05, "XYZ");

    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);
  */
  //const int nSrc = 3; // 2011A, 2011B, highPU
  const int nSrc=5; // data 2011B, newkill 2011B, data highPU, emul highPU, 2012 online HPU
  const int nStrict = 2;
  const int nEG = 8;
  const int nVtx = 40;
  const int nVTX[nSrc]={40,40,40,40,60};
  const int nEG_g=4; // nEG for graph : EG12,15,20,30

  //TString src_name[nSrc]={"2011A","2011B","highPU"};
  TString src_name[nSrc]={"data_2011B","newsetting_2011B", "data_highPU", "d2012_HPU"};
  TString strict_name[nStrict] = {"large","strict"};

  TString trigname[nEG]={"2","5","8","10","12","15","20","30"};
  int trigthresh[nEG]={2,5,8,10,12,15,20,30};

  TH1F * h_evts_trigBy_any[nEG][nSrc];
  TH1F * h_evts_trigBy_spikes[nEG][nStrict][nSrc];

  cout << "objects declared and counters initialized" << endl;

  TString name_histo;

  for( int iSrc=0 ; iSrc<nSrc ; iSrc++ ) {
    for( int iEG=0 ; iEG<nEG ; iEG++ ) {
      name_histo = "h_evts_trigBy_any_EG"+trigname[iEG]+"_"+src_name[iSrc];
      h_evts_trigBy_any[iEG][iSrc] = new TH1F(name_histo,name_histo,nVTX[iSrc],0,nVTX[iSrc]);

      for( int iStrict=0 ; iStrict<nStrict ; iStrict++ ) {
	name_histo = "h_evts_trigBy_spikes_EG"+trigname[iEG]+"_"+strict_name[iStrict]+"_"+src_name[iSrc];
	h_evts_trigBy_spikes[iEG][iStrict][iSrc] = new TH1F(name_histo,name_histo,nVTX[iSrc],0,nVTX[iSrc]);
      }
    }
  }

  TString file[nSrc];

  // FILES : HLTEG12
  file[0]="/home/llr/cms/ndaci/SKWork/macro/skEfficiency/tagAndProbe/Spike2011A/Commi_2011B_HLTEG12_fromfilter/spike_plots_half_0_1.root";

  file[1]="/home/llr/cms/ndaci/SKWork/macro/skEfficiency/tagAndProbe/Spike2011A/CommiEmulReco_Run2011B/GetContamNewkill/spike_plots_half_0_1.root";

  file[2]="/home/llr/cms/ndaci/SKWork/macro/skEfficiency/tagAndProbe/Spike2011A/Commi_2011B_highPU_HLTEG_repro/spike_plots_half_0_1.root" ;

  file[3]="/home/llr/cms/ndaci/SKWork/macro/skEfficiency/Spikes/HighPuContamination/try2/spike_plots.root" ;

  file[4]="/home/llr/cms/ndaci/SKWork/macro/skEfficiency/Spikes2012/HPU/spike_plots_half_0_1.root" ;

  TFile * f;

  cout << "going to open files" << endl;

  for(int iSrc=0 ; iSrc<nSrc ; iSrc++) {

    if(iSrc==3) continue;

    f = TFile::Open(file[iSrc]);
    cout << "file #" << iSrc << " opened" << endl;
    for( int iEG=0 ; iEG<nEG ; iEG++ ) {
      name_histo = "h_evts_trigBy_any_EG"+trigname[iEG];
      h_evts_trigBy_any[iEG][iSrc] -> Add( (TH1F*)gDirectory->Get(name_histo) );
  
      if(iSrc==4) h_evts_trigBy_any[iEG][iSrc] -> Rebin(2);

      cout << " got histogram " + name_histo << endl;

      for( int iStrict=0 ; iStrict<nStrict ; iStrict++ ) {
        name_histo = "h_evts_trigBy_spikes_EG"+trigname[iEG]+"_"+strict_name[iStrict];
        h_evts_trigBy_spikes[iEG][iStrict][iSrc] -> Add( (TH1F*)gDirectory->Get(name_histo) );

	if(iSrc==4) h_evts_trigBy_spikes[iEG][iStrict][iSrc] -> Rebin(2);

	cout << "got histogram "+ name_histo <<endl;
      }
    }
    f->Close();
  } 
  
  // highPU emul is special case
  f = TFile::Open(file[3]);
  cout << "file #" << 3 << " opened" << endl;
  for( int iEG=0 ; iEG<nEG ; iEG++ ) {
    name_histo = "h_evts_trigBy_any_EG"+trigname[iEG]+"_M";
    h_evts_trigBy_any[iEG][3] -> Add( (TH1F*)gDirectory->Get(name_histo) );
    //
    name_histo = "h_evts_trigBy_spikes_EG"+trigname[iEG]+"_M";
    h_evts_trigBy_spikes[iEG][0][3] -> Add( (TH1F*)gDirectory->Get(name_histo) );
    h_evts_trigBy_spikes[iEG][1][3] -> Add( (TH1F*)gDirectory->Get(name_histo) );
  }

  const int nFr=2; // low/up frontier of iBin
  const int nBins_src[nSrc][nEG_g]={ {21,15,19,16} , {16,15,13,10} , {28,25,24,21} , {28,25,24,21} , {15,15,15,15}};

  int idxBinsFr[nSrc][nEG_g][nFr]={ { {2,22},{1,15},{2,20},{3,18} },
				    { {3,18},{1,15},{4,16},{5,14} }, 
				    { {12,39},{14,38},{14,37},{14,34} }, 
				    { {12,39},{14,38},{14,37},{14,34} },
				    { {30,60},{30,60},{30,60},{30,60} } };

  int fact[nSrc]={1,1,1,1,factor};

  vector< float > n_evts_trigBy_any[nEG][nSrc]; // double tableau de vecteurs de floats
  vector< float > n_evts_trigBy_spikes[nEG][nStrict][nSrc]; // triple 
  vector< float > n_contam[nEG][nStrict][nSrc]; 
  vector< float > err_contam[nEG][nStrict][nSrc];

  // --> chaque element du tableau est un vecteur contenant les valeurs des bins des histos

  for(int iEG=0 ; iEG<nEG_g ; iEG++) {
    for(int iSrc=0 ; iSrc<nSrc ; iSrc++) {

      const int nBins = nBins_src[iSrc][iEG] ;
	       
      for(int iBin=0 ; iBin<nBins ; iBin++) {
	n_evts_trigBy_any[iEG][iSrc].push_back( 
					       (float)( h_evts_trigBy_any[iEG+4][iSrc] -> GetBinContent(idxBinsFr[iSrc][iEG][0]/fact[iSrc]+iBin+1) ) );
	for(int iStrict=0 ; iStrict<nStrict ; iStrict++ ) {
	  n_evts_trigBy_spikes[iEG][iStrict][iSrc].push_back( 
							     (float)( h_evts_trigBy_spikes[iEG+4][iStrict][iSrc] 
								      -> GetBinContent(idxBinsFr[iSrc][iEG][0]/fact[iSrc]+iBin+1) ) );

	  if( n_evts_trigBy_any[iEG][iSrc][iBin] !=0 ) {
	    n_contam[iEG][iStrict][iSrc].push_back(
						   n_evts_trigBy_spikes[iEG][iStrict][iSrc][iBin]/n_evts_trigBy_any[iEG][iSrc][iBin]);
	    err_contam[iEG][iStrict][iSrc].push_back( 
						     errPoissCount( n_evts_trigBy_spikes[iEG][iStrict][iSrc][iBin], n_evts_trigBy_any[iEG][iSrc][iBin]) );
	  }

	  else {
	    n_contam[iEG][iStrict][iSrc].push_back(-0.01);
	    err_contam[iEG][iStrict][iSrc].push_back(0);
	  }
	} // loop over iStrict
      } // loop over iBin
    } // loop over iSrc
  } // loop over iEG

  for(int iEG=0 ; iEG<nEG_g ; iEG++) {
    for(int iSrc=0 ; iSrc<nSrc ; iSrc++) {
      int nBins = n_evts_trigBy_any[iEG][iSrc].size();
      cout << "EG" << trigname[iEG+4] << " src=" << src_name[iSrc] << endl;
      for(int iBin=0 ; iBin<nBins ; iBin++)
	cout << n_evts_trigBy_any[iEG][iSrc][iBin] << "   " ;
      cout << endl;
      
      for(int iStrict=0 ; iStrict<nStrict ; iStrict++ ) {
	cout << "strict="<< strict_name[iStrict]<< endl;

	int nBins_s = n_evts_trigBy_spikes[iEG][iStrict][iSrc].size();
	for(int iBin=0 ; iBin<nBins_s ; iBin++)
	  cout << n_evts_trigBy_spikes[iEG][iStrict][iSrc][iBin] << "   ";
	cout << endl;

	nBins_s = n_contam[iEG][iStrict][iSrc].size();
	for(int iBin=0 ; iBin<nBins_s ; iBin++)
	  cout << n_contam[iEG][iStrict][iSrc][iBin] << "   ";
	cout << endl;
      }
      cout << endl;
    }
    cout << endl;
  }

  //int mark_style[nSrc] = {22,20,21}; // kFullTriangleUp, kFullCircle, kFullSquare
  //int mark_col[nSrc] = {4,2,1}; // bleu, rouge, noir

  int mark_style[nSrc] = {22,22,21,21,20};
  //int mark_col[nSrc] = {4,2,4,2};
  int mark_col[nSrc] = {kRed,kGreen+2,kRed,kGreen+2,kBlue};

  TGraph * g_evt_contam[nEG][nStrict][nSrc];
  TGraphErrors * g_evt_contam_err[nEG][nStrict][nSrc];
				    
  for(int iSrc=0 ; iSrc<nSrc ; iSrc++) {
    for(int iStrict=0 ; iStrict<nStrict ; iStrict++) {
      for(int iEG=0 ; iEG<nEG_g ; iEG++) {

	const int nPts = nBins_src[iSrc][iEG];
	float x_vtx[nPts];
	float err_vtx[nPts];
	for(int iVtx=0 ; iVtx<nPts ; iVtx++) {
	  x_vtx[iVtx] = (float)( idxBinsFr[iSrc][iEG][0] + iVtx*fact[iSrc] ) ;
	  cout << x_vtx[iVtx] << " | " ;
	  err_vtx[iVtx] = 0.49*fact[iSrc];
	}
	cout << endl;

	const int nDots = n_contam[iEG][iStrict][iSrc].size();
	if( nDots != nPts ) {
	  cout << "ERROR : nDots != nPts ! exit..." << endl;
	  return;
	}

	float contam_vtx[nPts];
	float err_contam_vtx[nPts];

	for(int iVtx=0 ; iVtx<nPts ; iVtx++) {
	  contam_vtx[iVtx] = n_contam[iEG][iStrict][iSrc][iVtx];
	  cout << n_contam[iEG][iStrict][iSrc][iVtx] << " |||" ;
	  cout << contam_vtx[iVtx] << " || ";
	  err_contam_vtx[iVtx] = err_contam[iEG][iStrict][iSrc][iVtx];
	}
	cout << endl;

        g_evt_contam[iEG][iStrict][iSrc] = new TGraph( nPts, x_vtx, contam_vtx );
	g_evt_contam_err[iEG][iStrict][iSrc] = new TGraphErrors( nPts, x_vtx, contam_vtx, err_vtx, err_contam_vtx );

        g_evt_contam[iEG][iStrict][iSrc]->SetName(
						  "Event_"+strict_name[iStrict]+"_contamination_EG"+trigname[iEG+4]+"_"+src_name[iSrc] );
        g_evt_contam[iEG][iStrict][iSrc]->SetTitle(
						   "Event "+strict_name[iStrict]+" contamination (EG"+trigname[iEG+4]+") "+src_name[iSrc] );
	g_evt_contam[iEG][iStrict][iSrc]->SetMarkerStyle(mark_style[iSrc]);
	g_evt_contam[iEG][iStrict][iSrc]->SetMarkerColor(mark_col[iSrc]);
	g_evt_contam[iEG][iStrict][iSrc]->SetFillColor(kWhite);
	cout << "N POINTS = " << g_evt_contam[iEG][iStrict][iSrc]->GetN() << endl;

        g_evt_contam_err[iEG][iStrict][iSrc]->SetName(
						      "Event_"+strict_name[iStrict]+"_contamination_error_EG"+trigname[iEG+4]+"_"+src_name[iSrc] );
        g_evt_contam_err[iEG][iStrict][iSrc]->SetTitle(
						       "Event "+strict_name[iStrict]+" contamination (EG"+trigname[iEG+4]+") "+src_name[iSrc] );
        g_evt_contam_err[iEG][iStrict][iSrc]->SetMarkerStyle(mark_style[iSrc]);
        g_evt_contam_err[iEG][iStrict][iSrc]->SetMarkerColor(mark_col[iSrc]);
        g_evt_contam_err[iEG][iStrict][iSrc]->SetFillColor(kWhite);



      }
    }
  }
  cout << endl << endl;

  for(int iSrc=0 ; iSrc<nSrc ; iSrc++)
    for(int iStrict=0 ; iStrict<nStrict ; iStrict++)
      for(int iEG=0 ; iEG<nEG_g ; iEG++)
	cout << "N POINTS = " << g_evt_contam[iEG][iStrict][iSrc]->GetN() << endl;
  //for(int iVtx=0 ; iVtx<nPts ; iVtx++)
  //cout << n_contam[iEG][iStrict][iSrc][iVtx] << " || " <<
	    
  //////////////////////////////////////////////////////////
  // PLOTTING //////////////////////////////////////////////
  //////////////////////////////////////////////////////////

  TCanvas * c_evt_contam[nEG_g][nStrict];
  TCanvas * c_evt_contam_err[nEG_g][nStrict];

  float g_max[nEG_g] = {0.3,0.4,0.6,0.35};

  //for(int iEG=0 ; iEG<nEG_g ; iEG++) {
  /*
    for(int iEG=0 ; iEG<2 ; iEG++) {
    for(int iStrict=0 ; iStrict<nStrict ; iStrict++) {
      
    c_evt_contam[iEG][iStrict] = new TCanvas("c_evt_contam_EG"+trigname[iEG+4]+"_"+strict_name[iStrict],
    "Spike contamination "+strict_name[iStrict]+" (EG"+trigname[iEG+4]+")",
    0,0,800,600);
      
    c_evt_contam[iEG][iStrict]->SetFillColor(kWhite);
    c_evt_contam[iEG][iStrict]->GetFrame()->SetFillColor(kWhite);

    g_evt_contam[iEG][iStrict][0]->SetMinimum(0);
    g_evt_contam[iEG][iStrict][0]->SetMaximum(g_max[iEG]);      
    g_evt_contam[iEG][iStrict][0]->GetXaxis()->Set(40,0,40);
    g_evt_contam[iEG][iStrict][0]->GetXaxis()->SetTitle("Number of vertices");
    g_evt_contam[iEG][iStrict][0]->GetYaxis()->SetTitle("Fraction of EG events trig. by spikes");

    g_evt_contam[iEG][iStrict][0]->SetTitle( "Spike contamination (EG"+trigname[iEG+4]+")" );

    g_evt_contam[iEG][iStrict][0]->Draw("AP");
    g_evt_contam[iEG][iStrict][1]->Draw("P");
    g_evt_contam[iEG][iStrict][2]->Draw("P");
    g_evt_contam[iEG][iStrict][3]->Draw("P");

    TLegend * leg = new TLegend(0.5,0.70,0.885,0.90,"CMS Preliminary 2011 pp #sqrt{s}=7 TeV","brNDC"); 
    //(x1,y1),(x2,y2)->bottom left , top right
    leg->SetLineColor(1);
    leg->SetTextColor(1);
    leg->SetTextFont(42);
    leg->SetTextSize(0.03);
    leg->SetMargin(0.2);
    leg->SetShadowColor(kWhite);
    leg->SetFillColor(kWhite);
    //
    leg->AddEntry(g_evt_contam[iEG][iStrict][0],"Run 2011B Data","P");
    leg->AddEntry(g_evt_contam[iEG][iStrict][1],"Run 2011B Emul new setting (data)","P");
    leg->AddEntry(g_evt_contam[iEG][iStrict][2],"High PU runs Data","P");
    leg->AddEntry(g_evt_contam[iEG][iStrict][3],"High PU runs Emul new setting (data)","P");
    leg->Draw();

    c_evt_contam[iEG][iStrict]->Print(dirOut+"evt_contam_EG"+trigname[iEG+4]+"_"+strict_name[iStrict]+".C");
    c_evt_contam[iEG][iStrict]->Print(dirOut+"evt_contam_EG"+trigname[iEG+4]+"_"+strict_name[iStrict]+".gif");
    c_evt_contam[iEG][iStrict]->Print(dirOut+"evt_contam_EG"+trigname[iEG+4]+"_"+strict_name[iStrict]+".png");
    c_evt_contam[iEG][iStrict]->Print(dirOut+"evt_contam_EG"+trigname[iEG+4]+"_"+strict_name[iStrict]+".eps");
    c_evt_contam[iEG][iStrict]->Print(dirOut+"evt_contam_EG"+trigname[iEG+4]+"_"+strict_name[iStrict]+".ps");
    c_evt_contam[iEG][iStrict]->Print(dirOut+"evt_contam_EG"+trigname[iEG+4]+"_"+strict_name[iStrict]+".pdf");
    }
    }
  */
  cout << "<--- FINE UNTIL HERE --->" << endl;

  //for(int iEG=0 ; iEG<nEG_g ; iEG++) {
  for(int iEG=1 ; iEG<3 ; iEG++) {
    for(int iStrict=0 ; iStrict<nStrict ; iStrict++) {

      c_evt_contam_err[iEG][iStrict] = new TCanvas("c_evt_contam_err_EG"+trigname[iEG+4]+"_"+strict_name[iStrict],
						   "Spike contamination "+strict_name[iStrict]+" (EG"+trigname[iEG+4]+")",
						   0,0,800,600);

      c_evt_contam_err[iEG][iStrict]->SetFillColor(kWhite);
      c_evt_contam_err[iEG][iStrict]->GetFrame()->SetFillColor(kWhite);

      g_evt_contam_err[iEG][iStrict][0]->SetMinimum(0);
      g_evt_contam_err[iEG][iStrict][0]->SetMaximum(g_max[iEG]);
      g_evt_contam_err[iEG][iStrict][0]->GetXaxis()->Set(60,0,60);

      g_evt_contam_err[iEG][iStrict][0]->SetTitle( "Spike contamination (EG"+trigname[iEG+4]+")" );
      g_evt_contam_err[iEG][iStrict][0]->GetXaxis()->SetTitle("Number of vertices");
      g_evt_contam_err[iEG][iStrict][0]->GetYaxis()->SetTitle("Fraction of EG events trig. by spikes");

      g_evt_contam_err[iEG][iStrict][0]->Draw("AP");
      g_evt_contam_err[iEG][iStrict][1]->Draw("P");
      g_evt_contam_err[iEG][iStrict][2]->Draw("P");
      g_evt_contam_err[iEG][iStrict][3]->Draw("P");
      g_evt_contam_err[iEG][iStrict][4]->Draw("P");

      //TLegend * leg = new TLegend(0.17,0.695,0.58,0.90,"CMS Preliminary 2012 pp  #sqrt{s}=7+8 TeV","brNDC");
      TLegend * leg = new TLegend(0.17,0.675,0.58,0.88,"CMS Preliminary 2012 pp  #sqrt{s}=7+8 TeV","brNDC");
      //(x1,y1),(x2,y2)->bottom left , top right
      leg->SetMargin(0.15);
      leg->SetLineColor(1);
      leg->SetTextColor(1);
      leg->SetTextFont(42);
      leg->SetTextSize(0.03);
      leg->SetShadowColor(kWhite);
      leg->SetFillColor(kWhite);
      //
      leg->AddEntry(g_evt_contam[iEG][iStrict][0],"Run 2011B Data","P");
      leg->AddEntry(g_evt_contam[iEG][iStrict][1],"Run 2011B Emul new setting (data)","P");
      leg->AddEntry(g_evt_contam[iEG][iStrict][2],"High PU runs Data","P");
      leg->AddEntry(g_evt_contam[iEG][iStrict][3],"High PU runs Emul new setting (data)","P");
      leg->AddEntry(g_evt_contam[iEG][iStrict][4],"High PU runs 2012 (data)","P");
      leg->Draw();

      /*
	TLegend * leg2 = new TLegend(0.4,0.78,0.885,0.88,"","brNDC"); //(x1,y1),(x2,y2):bottom left,top right
	leg2->SetLineColor(1);
	leg2->SetTextColor(1);
	leg2->SetTextFont(42);
	leg2->SetTextSize(0.03);
	leg2->SetShadowColor(kWhite);
	leg2->SetFillColor(kWhite);
      
	leg2->AddEntry("NULL","Contamination = #frac{N(events triggered by a spike)}{N(events triggered by any object)}","h");
      
	leg2->Draw();
      */

      c_evt_contam_err[iEG][iStrict]->Print(dirOut+"evt_contam_err_EG"+trigname[iEG+4]+"_"+strict_name[iStrict]+".C");
      c_evt_contam_err[iEG][iStrict]->Print(dirOut+"evt_contam_err_EG"+trigname[iEG+4]+"_"+strict_name[iStrict]+".gif");
      c_evt_contam_err[iEG][iStrict]->Print(dirOut+"evt_contam_err_EG"+trigname[iEG+4]+"_"+strict_name[iStrict]+".png");
      c_evt_contam_err[iEG][iStrict]->Print(dirOut+"evt_contam_err_EG"+trigname[iEG+4]+"_"+strict_name[iStrict]+".eps");
      c_evt_contam_err[iEG][iStrict]->Print(dirOut+"evt_contam_err_EG"+trigname[iEG+4]+"_"+strict_name[iStrict]+".ps");
      c_evt_contam_err[iEG][iStrict]->Print(dirOut+"evt_contam_err_EG"+trigname[iEG+4]+"_"+strict_name[iStrict]+".pdf");

    }
  }

}
Beispiel #14
0
int binfit_ttree_genlvl_atlas() {
  gROOT->Reset();
  gErrorIgnoreLevel=kError;
  float scaledps,scalesps,scalenlo,siggg,siggu,sigug;
  float datamass[81]={0};
  int dpsmass[81]={0};
  int spsmass[81]={0};
  float nlomass[81]={0.0};
  int nloggmass[81]={0};
  int nlogumass[81]={0};
  int nlougmass[81]={0};
  //  float datapt[60],datady[20],datay[20];
  TChain dps("Events");
  TChain nlogg("Events");
  TChain sps("Events");

//  dps.Add("Modified_Input_To_Fit_2012DPS_TMTight_3MuL3Match.root");
  dps.Add("genevents/GENEventTree_dps_pu_old_1.root");
  dps.Add("genevents/GENEventTree_dps_pu_old_2.root");
  dps.Add("genevents/GENEventTree_dps_pu_old_3.root");
  nlogg.Add("genevents/GENEventTree_pythia8_PU_OffsetBS_fixp3_1.root");
  nlogg.Add("genevents/GENEventTree_pythia8_PU_OffsetBS_fixp3_2.root");
  nlogg.Add("genevents/GENEventTree_pythia8_PU_OffsetBS_fixp3_3.root");
  nlogg.Add("genevents/GENEventTree_pythia8_PU_OffsetBS_fixp3_4.root");
  nlogg.Add("genevents/GENEventTree_pythia8_PU_OffsetBS_fixp3_5.root");
  nlogg.Add("genevents/GENEventTree_pythia8_PU_OffsetBS_fixp3_6_1.root ");
  nlogg.Add("genevents/GENEventTree_pythia8_PU_OffsetBS_fixp3_6_2.root ");
  sps.Add("genevents/GENEventTree_SPSLO_xl21_1.root");
  sps.Add("genevents/GENEventTree_SPSLO_xl21_2.root");
  sps.Add("genevents/GENEventTree_SPSLO_xl22_1.root");
  sps.Add("genevents/GENEventTree_SPSLO_xl22_2.root");
  sps.Add("genevents/GENEventTree_SPSLO_xl23_1.root");
  sps.Add("genevents/GENEventTree_SPSLO_xl23_2.root");
  sps.Add("genevents/GENEventTree_SPSLO_xl26_1.root");
  sps.Add("genevents/GENEventTree_SPSLO_xl26_2.root");
  sps.Add("genevents/GENEventTree_SPSLO_xl27_1.root");
  sps.Add("genevents/GENEventTree_SPSLO_xl27_2.root");
  sps.Add("genevents/GENEventTree_SPSLO_xl28_1.root");
  sps.Add("genevents/GENEventTree_SPSLO_xl28_2.root");
  

  float massbins[]={6.2,7,9,11,14,18,25,30,60};
  //float ptbins[]={0.,7,12,16,20,25,50,80};
  float ptbins[]={0.,2.5,5.,7.5,10.,12.5,15.,17.5,20.,22.5,25.,27.5,30.,35.,40.,45.,50.,55.,60.,65.,70.};
  float dybins[]={0.,0.2,0.4,0.6,0.9,1.3,1.8,2.4,4.5};
  //float ybins[]={-2.2,-1.8,-1.6,-1.4,-1.2,-1.0,-0.8,-0.6,-0.4,-0.2,0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.2};
  float ybins[]={0.,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8};
  int nmbins = 8; 
  int nptbins = 20;
  int ndybins = 8;
  int nybins = 9;
  //float massbins[]={0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60};
  //float ptbins[]={0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80};
  //float dybins[]={0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4.0,4.1,4.2,4.3,4.4,4.5};
  //float ybins[]={0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8};
  //  int nmbins = 30;
  //  int nptbins = 40;
  //  int ndybins = 45;
  //  int nybins = 18;
  //int nybins = 20;
    int mbinerr = -99;
    int ptbinerr = -99;
    int dybinerr = -99;
    int ybinerr = -99;
  TH1F *mass_data = new TH1F("mass_data","mass_data",nmbins,massbins); 
  TH1F *mass_dps = new TH1F("mass_dps","mass_dps",nmbins,massbins); 
  TH1F *mass_nlogg = new TH1F("mass_nlogg","mass_nlogg",nmbins,massbins); 
  TH1F *mass_nlo = new TH1F("mass_nlo","mass_nlo",nmbins,massbins); 
  TH1F *mass_sps = new TH1F("mass_sps","mass_sps",nmbins,massbins); 
  TH1F *mass_width = new TH1F("mass_width","mass_width",nmbins,massbins); 
  TH1F *pt_data = new TH1F("pt_data","pt_data",nptbins,ptbins); 
  TH1F *pt_dps = new TH1F("pt_dps","pt_dps",nptbins,ptbins); 
  TH1F *pt_nlogg = new TH1F("pt_nlogg","pt_nlogg",nptbins,ptbins); 
  TH1F *pt_nlo = new TH1F("pt_nlo","pt_nlo",nptbins,ptbins); 
  TH1F *pt_sps = new TH1F("pt_sps","pt_sps",nptbins,ptbins); 
  TH1F *pt_width = new TH1F("pt_width","pt_width",nptbins,ptbins); 
  TH1F *dy_data = new TH1F("dy_data","dy_data",ndybins,dybins); 
  TH1F *dy_dps = new TH1F("dy_dps","dy_dps",ndybins,dybins); 
  TH1F *dy_nlogg = new TH1F("dy_nlogg","dy_nlogg",ndybins,dybins); 
  TH1F *dy_nlo = new TH1F("dy_nlo","dy_nlo",ndybins,dybins); 
  TH1F *dy_sps = new TH1F("dy_sps","dy_sps",ndybins,dybins); 
  TH1F *dy_width = new TH1F("dy_width","dy_width",ndybins,dybins); 
  TH1F *y_data = new TH1F("y_data","y_data",nybins,ybins); 
  TH1F *y_dps = new TH1F("y_dps","y_dps",nybins,ybins); 
  TH1F *y_nlogg = new TH1F("y_nlogg","y_nlogg",nybins,ybins); 
  TH1F *y_nlo = new TH1F("y_nlo","y_nlo",nybins,ybins); 
  TH1F *y_sps = new TH1F("y_sps","y_sps",nybins,ybins); 
  TH1F *y_width = new TH1F("y_width","y_width",nybins,ybins); 

  mass_data->SetBinContent(1,47.43199);
  mass_data->SetBinContent(2,22.88957);
  mass_data->SetBinContent(3,10.52912);
  mass_data->SetBinContent(4,7.297879);
  mass_data->SetBinContent(5,4.679995);
  mass_data->SetBinContent(6,2.752399);
  mass_data->SetBinContent(7,2.321633);
  mass_data->SetBinContent(8,0.4013286);
  mass_data->SetBinError(1,6.281534);
  mass_data->SetBinError(2,2.358319);
  mass_data->SetBinError(3,1.509835);
  mass_data->SetBinError(4,1.177612);
  mass_data->SetBinError(5,0.7126356);
  mass_data->SetBinError(6,0.3761612);
  mass_data->SetBinError(7,0.3408355);
  mass_data->SetBinError(8,0.05351048);


  pt_data->SetBinContent(1, 1.5 );
  pt_data->SetBinContent(2, 1.75);
  pt_data->SetBinContent(3, 1.85);
  pt_data->SetBinContent(4, 1.5);
  pt_data->SetBinContent(5, 0.35);
  pt_data->SetBinContent(6,0.61);
  pt_data->SetBinContent(7, 1.7);
  pt_data->SetBinContent(8, 2.05);
  pt_data->SetBinContent(9, 2.95);
  pt_data->SetBinContent(10,3.6);
  pt_data->SetBinContent(11,2.5);
  pt_data->SetBinContent(12,2.1);
  pt_data->SetBinContent(13,1.5);
  pt_data->SetBinContent(14,0.95);
  pt_data->SetBinContent(15,0.23);
  pt_data->SetBinContent(16,0.13);
  pt_data->SetBinContent(17,0.15);
  pt_data->SetBinContent(18,0.14);
  pt_data->SetBinContent(19,0.04);
  pt_data->SetBinContent(20,0.025);
  pt_data->SetBinError(1,0.25);
  pt_data->SetBinError(2, 0.25);
  pt_data->SetBinError(3,0.25);
  pt_data->SetBinError(4,0.25);
  pt_data->SetBinError(5,0.15);
  pt_data->SetBinError(6,0.15);
  pt_data->SetBinError(7,0.25);
  pt_data->SetBinError(8,0.25);
  pt_data->SetBinError(9,0.25);
  pt_data->SetBinError(10, 0.1);
  pt_data->SetBinError(11, 0.1);
  pt_data->SetBinError(12, 0.25);
  pt_data->SetBinError(13, 0.1);
  pt_data->SetBinError(14, 0.25);
  pt_data->SetBinError(15, 0.07);
  pt_data->SetBinError(16, 0.07);
  pt_data->SetBinError(17, 0.07);
  pt_data->SetBinError(18, 0.07);
  pt_data->SetBinError(19, 0.06);
  pt_data->SetBinError(20, 0.025);


  dy_data->SetBinContent(1,353.6836);
  dy_data->SetBinContent(2,208.9763);
  dy_data->SetBinContent(3,100.067);
  dy_data->SetBinContent(4,59.72152);
  dy_data->SetBinContent(5,39.28412);
  dy_data->SetBinContent(6,23.76292);
  dy_data->SetBinContent(7,22.76975);
  dy_data->SetBinContent(8,10.52381);
  dy_data->SetBinError(1,28.61261);
  dy_data->SetBinError(2,21.71715);
  dy_data->SetBinError(3,14.11659);
  dy_data->SetBinError(4,10.30196);
  dy_data->SetBinError(5,6.846661);
  dy_data->SetBinError(6,5.372485);
  dy_data->SetBinError(7,4.64503);
  dy_data->SetBinError(8,2.287784);
  y_data->SetBinContent(1,96.87107);
  y_data->SetBinContent(2,110.5371);
  y_data->SetBinContent(3,89.27422);
  y_data->SetBinContent(4,101.8527);
  y_data->SetBinContent(5,77.61348);
  y_data->SetBinContent(6,95.7653);
  y_data->SetBinContent(7,137.6607);
  y_data->SetBinContent(8,168.4277);
  y_data->SetBinContent(9,120.5354);
  y_data->SetBinError(1,14.97098);
  y_data->SetBinError(2,15.67618);
  y_data->SetBinError(3,12.3992);
  y_data->SetBinError(4,13.63791);
  y_data->SetBinError(5,10.98304);
  y_data->SetBinError(6,14.26707);
  y_data->SetBinError(7,17.44995);
  y_data->SetBinError(8,23.01054);
  y_data->SetBinError(9,22.7678);

  mass_width->SetBinContent(1,0.8);
  mass_width->SetBinContent(2,2.);
  mass_width->SetBinContent(3,2.);
  mass_width->SetBinContent(4,3.);
  mass_width->SetBinContent(5,4.);
  mass_width->SetBinContent(6,5.);
  mass_width->SetBinContent(7,5.);
  mass_width->SetBinContent(8,30.);


  pt_width->SetBinContent(1,2.5);
  pt_width->SetBinContent(2,2.5);
  pt_width->SetBinContent(3,2.5);
  pt_width->SetBinContent(4,2.5);
  pt_width->SetBinContent(5,2.5);
  pt_width->SetBinContent(6,2.5);
  pt_width->SetBinContent(7,2.5);
  pt_width->SetBinContent(8,2.5);
  pt_width->SetBinContent(9,2.5);
  pt_width->SetBinContent(10,2.5);
  pt_width->SetBinContent(11,2.5);
  pt_width->SetBinContent(12,2.5);
  pt_width->SetBinContent(13,5);
  pt_width->SetBinContent(14,5);
  pt_width->SetBinContent(15,5);
  pt_width->SetBinContent(16,5);
  pt_width->SetBinContent(17,5);
  pt_width->SetBinContent(18,5);
  pt_width->SetBinContent(19,5);
  pt_width->SetBinContent(20,5);


  dy_width->SetBinContent(1,0.2);
  dy_width->SetBinContent(2,0.2);
  dy_width->SetBinContent(3,0.2);
  dy_width->SetBinContent(4,0.3);
  dy_width->SetBinContent(5,0.4);
  dy_width->SetBinContent(6,0.5);
  dy_width->SetBinContent(7,0.6);
  dy_width->SetBinContent(8,2.1);
  y_width->SetBinContent(1,0.2);
  y_width->SetBinContent(2,0.2);
  y_width->SetBinContent(3,0.2);
  y_width->SetBinContent(4,0.2);
  y_width->SetBinContent(5,0.2);
  y_width->SetBinContent(6,0.2);
  y_width->SetBinContent(7,0.2);
  y_width->SetBinContent(8,0.2);
  y_width->SetBinContent(9,0.2);

  dps.Draw("FourMu_pT >> pt_dps","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
  nlogg.Draw("FourMu_pT >> pt_nlogg","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
  sps.Draw("FourMu_pT >> pt_sps","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
  pt_dps->Divide(pt_width);
  pt_nlogg->Divide(pt_width);
  pt_sps->Divide(pt_width);
  datamass[0]=pt_data->Integral("width");
  std::cout<<datamass[0]<<std::endl;
  dpsmass[0]=pt_dps->Integral("width");
  spsmass[0]=pt_sps->Integral("width");
  nloggmass[0]=pt_nlogg->Integral("width");
  nlomass[0]=nloggmass[0];

  scaledps = datamass[0]/ (float) dpsmass[0];
  scalesps= datamass[0]/ (float) spsmass[0];
  scalenlo= datamass[0]/ (float) nloggmass[0];
  float Chi2=0;
  float minchi2norm=99999999.9;
  float minchi2=9999999.9;
  float mina, minb, minc, minan, minbn, mincn;

  //   Chi2 = Chi2 + pow((datamass[1] - (0.00*scaledps*dpsmass[1] + 0.0*scalesps*spsmass[1] + 0.0*scalenlo*nlomass[1])),2)/sqrt(datamass[1]);
  //  std::cout<<"Scale: " <<datamass[0]<<" " << dpsmass[0]<<" "<<scaledps<<" "<<scalesps<<" "<<scalenlo<<" "<<std::endl;
  for(float a=0.0; a<1.0; a=a+0.01){
        dps.Draw("FourMu_Mass >> mass_dps","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
        nlogg.Draw("FourMu_Mass >> mass_nlogg","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
        sps.Draw("FourMu_Mass >> mass_sps","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
        dps.Draw("FourMu_pT >> pt_dps","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
        nlogg.Draw("FourMu_pT >> pt_nlogg","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
        sps.Draw("FourMu_pT >> pt_sps","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
        dps.Draw("Psi1To2_dY >> dy_dps","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
        nlogg.Draw("Psi1To2_dY >> dy_nlogg","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
        sps.Draw("Psi1To2_dY >> dy_sps","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
        dps.Draw("abs(FourMu_Rapidity)>> y_dps","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
        nlogg.Draw("abs(FourMu_Rapidity) >> y_nlogg","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
        sps.Draw("abs(FourMu_Rapidity) >> y_sps","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
  mass_dps->Divide(mass_width);
  mass_nlogg->Divide(mass_width);
  mass_sps->Divide(mass_width);
  pt_dps->Divide(pt_width);
  pt_nlogg->Divide(pt_width);
  pt_sps->Divide(pt_width);
  dy_dps->Divide(dy_width);
  dy_nlogg->Divide(dy_width);
  dy_sps->Divide(dy_width);
  y_dps->Divide(y_width);
  y_nlogg->Divide(y_width);
  y_sps->Divide(y_width);
//        for(int mbin=1; mbin<=nmbins; ++mbin){
//          if (mass_data->GetBinContent(mbin) == 0){
//            //mbinerr = 1.;
//            continue;
//          }
//          //else{mbinerr = sqrt(abs(mass_data->GetBinContent(mbin)));}
//          //Chi2=Chi2 + pow((mass_data->GetBinContent(mbin) - (a*scaledps*mass_dps->GetBinContent(mbin) + b*scalesps*mass_sps->GetBinContent(mbin) + c*scalenlo*mass_nlogg->GetBinContent(mbin))),2)/mbinerr;
////          Chi2=Chi2 + pow((mass_data->GetBinContent(mbin) - (a*scaledps*mass_dps->GetBinContent(mbin) + b*scalesps*mass_sps->GetBinContent(mbin) + c*scalenlo*mass_nlogg->GetBinContent(mbin)))/sqrt(abs(mass_data->GetBinContent(mbin))),2);
//          //           std::cout<<Chi2<<std::endl;
//        }
        for(int ptbin=1; ptbin<=nptbins; ++ptbin){
          Chi2=Chi2 + pow((pt_data->GetBinContent(ptbin) - (a*scaledps*pt_dps->GetBinContent(ptbin) + (1.-a)*scalenlo*pt_nlogg->GetBinContent(ptbin)))/pt_data->GetBinError(ptbin),2);
            //         std::cout<<pt_data->GetBinContent(ptbin)<<std::endl;
        }
//        for(int dybin=1; dybin<=ndybins; ++dybin){
//          if (dy_data->GetBinContent(dybin) == 0){
//            dybinerr = 1.;
//          }
//          else{dybinerr = dy_data->GetBinError(dybin);}
////          Chi2=Chi2 + pow((dy_data->GetBinContent(dybin) - (a*scaledps*dy_dps->GetBinContent(dybin) + b*scalesps*dy_sps->GetBinContent(dybin) + c*scalenlo*dy_nlogg->GetBinContent(dybin)))/dybinerr,2);
//          //           std::cout<<Chi2<<std::endl;
//        }
//        for(int ybin=1; ybin<=nybins; ++ybin){
//          Chi2=Chi2 + pow((y_data->GetBinContent(ybin) - (a*scaledps*y_dps->GetBinContent(ybin) + (1.-a)*scalenlo*y_nlogg->GetBinContent(ybin)))/y_data->GetBinError(ybin),2);
//          //           std::cout<<Chi2<<std::endl;
//        }
        //        std::cout<<"a, b, c: "<<a<<" "<<b<<" "<<c<<" Chi2: "<<Chi2<<std::endl;
        std::cout<<a<<" "<<Chi2<<std::endl;
        if (Chi2<=minchi2){
          minchi2=Chi2; minan = a; minbn = 0.; mincn=(1.-a); 
        }
        //        std::cout<<a<<" "<<b<<" "<<c<<" "<<Chi2<<std::endl;
        Chi2=0;
    }
    std::cout<<"Min Chi2: "<<minchi2<<" dps, sps, nlo: "<<minan<<" "<<minbn<<" "<<mincn<<std::endl;
    TCanvas* disp = new TCanvas("disp","disp",900,900);
    disp->Divide(2,2);
    TH1F *MassSum = new TH1F("MassSum","MassSum",nmbins,massbins);
    TH1F *MassBest = new TH1F("MassBest","MassBest",nmbins,massbins);
    TH1F *DpsBestM = new TH1F("DpsBestM","DpsBestM",nmbins,massbins);
    TH1F *SpsBestM = new TH1F("SpsBestM","SpsBestM",nmbins,massbins);
    TH1F *NloBestM = new TH1F("NloBestM","NloBestM",nmbins,massbins);
    TH1F *pTBest = new TH1F("pTBest","pTBest",nptbins,ptbins);
    TH1F *pTSum = new TH1F("pTSum","pTSum",nptbins,ptbins);
    TH1F *DpsBestpt = new TH1F("DpsBestpt","DpsBestpt",nptbins,ptbins);
    TH1F *NloBestpt = new TH1F("NloBestpt","NloBestpt",nptbins,ptbins);
    TH1F *SpsBestpt = new TH1F("SpsBestpt","SpsBestpt",nptbins,ptbins);
    TH1F *dyBest = new TH1F("dyBest","dyBest",ndybins,dybins);
    TH1F *dySum = new TH1F("dySum","dySum",ndybins,dybins);
    TH1F *DpsBestdy = new TH1F("DpsBestdy","DpsBestdy",ndybins,dybins);
    TH1F *NloBestdy = new TH1F("NloBestdy","NloBestdy",ndybins,dybins);
    TH1F *SpsBestdy = new TH1F("SpsBestdy","SpsBestdy",ndybins,dybins);
    TH1F *yBest = new TH1F("yBest","yBest",nybins,ybins);
    TH1F *ySum = new TH1F("ySum","ySum",nybins,ybins);
    TH1F *DpsBesty = new TH1F("DpsBesty","DpsBesty",nybins,ybins);
    TH1F *NloBesty = new TH1F("NloBesty","NloBesty",nybins,ybins);
    TH1F *SpsBesty = new TH1F("SpsBesty","SpsBesty",nybins,ybins);
    MassBest->SetMinimum(0);pTBest->SetMinimum(0);dyBest->SetMinimum(0);yBest->SetMinimum(0);
    mass_data->SetMinimum(0);pt_data->SetMinimum(0);dy_data->SetMinimum(0);y_data->SetMinimum(0);
    dps.Draw("FourMu_Mass>>DpsBestM","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
    nlogg.Draw("FourMu_Mass>>NloBestM","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
    sps.Draw("FourMu_Mass>>SpsBestM","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
    dps.Draw("FourMu_pT>>DpsBestpt","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
    nlogg.Draw("FourMu_pT>>NloBestpt","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
    sps.Draw("FourMu_pT>>SpsBestpt","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
    dps.Draw("Psi1To2_dY>>DpsBestdy","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
    nlogg.Draw("Psi1To2_dY>>NloBestdy","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
    sps.Draw("Psi1To2_dY>>SpsBestdy","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
    dps.Draw("abs(FourMu_Rapidity)>>DpsBesty","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
    nlogg.Draw("abs(FourMu_Rapidity)>>NloBesty","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
    sps.Draw("abs(FourMu_Rapidity)>>SpsBesty","Sum$(Psi_pT>8.5&&abs(Psi_y)<2.1&&Psi_Mass[]<3.35&&Psi_Mass>2.85)==2","goff");
  DpsBestM->Divide(mass_width);
  NloBestM->Divide(mass_width);
  SpsBestM->Divide(mass_width);
  DpsBestpt->Divide(pt_width);
  NloBestpt->Divide(pt_width);
  SpsBestpt->Divide(pt_width);
  DpsBestdy->Divide(dy_width);
  NloBestdy->Divide(dy_width);
  SpsBestdy->Divide(dy_width);
  DpsBesty->Divide(y_width);
  NloBesty->Divide(y_width);
  SpsBesty->Divide(y_width);
    //MassSum->Add(DpsBest,(float) mina);
    //MassSum->Add(SpsBest,minb);
    //MassSum->Add(NloBest,minc);
    mass_data->SetMinimum(0);
    mass_data->SetXTitle("Four Mu Mass (GeV)");
    pt_data->SetXTitle("Four Mu pT (GeV)");
    dy_data->SetXTitle("|#Delta Y| between J/#psi");
    y_data->SetXTitle("Four Mu Rapidity |Y|");
    mass_data->SetTitle("");
    pt_data->SetTitle("");
    dy_data->SetTitle("");
    y_data->SetTitle("");
    disp->cd(1);
    DpsBestM->SetLineColor(kRed);
    NloBestM->SetLineColor(kGreen);
    SpsBestM->SetLineColor(kBlue);
    DpsBestM->Scale(minan*scaledps);
    NloBestM->Scale(mincn*scalenlo);
    SpsBestM->Scale(minbn*scalesps);
    MassSum->Add(DpsBestM);
    MassSum->Add(NloBestM);
    MassSum->Add(SpsBestM);
    mass_data->Draw("E1");
    MassSum->Draw("same");
    DpsBestM->Draw("same");
    NloBestM->Draw("same");
    SpsBestM->Draw("same");
    TLegend *leg = new TLegend(0.6,0.7,0.90,0.9);
    leg->SetFillStyle(0);
    leg->SetBorderSize(0);
    leg->SetShadowColor(0);
    leg->AddEntry(DpsBestM,"DPS model","l");
    leg->AddEntry(NloBestM,"SPS NLO model","l");
    leg->AddEntry(MassSum,"MC model sum","l");
    leg->AddEntry(MassBest,"Data","lep");
    leg->Draw();
    disp->cd(2);
    DpsBestpt->SetLineColor(kRed);
    NloBestpt->SetLineColor(kGreen);
    SpsBestpt->SetLineColor(kBlue);
    DpsBestpt->Scale(minan*scaledps);
    NloBestpt->Scale(mincn*scalenlo);
    SpsBestpt->Scale(minbn*scalesps);
    pTSum->Add(DpsBestpt);
    pTSum->Add(NloBestpt);
    pTSum->Add(SpsBestpt);
    pt_data->Draw("e1");
    pTSum->Draw("same");
    DpsBestpt->Draw("same");
    NloBestpt->Draw("same");
    SpsBestpt->Draw("same");
    leg->Draw();
    disp->cd(3);
    DpsBestdy->SetLineColor(kRed);
    NloBestdy->SetLineColor(kGreen);
    SpsBestdy->SetLineColor(kBlue);
    DpsBestdy->Scale(minan*scaledps);
    NloBestdy->Scale(mincn*scalenlo);
    SpsBestdy->Scale(minbn*scalesps);
    dySum->Add(DpsBestdy);
    dySum->Add(NloBestdy);
    dySum->Add(SpsBestdy);
    dy_data->Draw("e1");
    dySum->Draw("same");
    DpsBestdy->Draw("same");
    NloBestdy->Draw("same");
    SpsBestdy->Draw("same");
    leg->Draw();
    disp->cd(4);
    DpsBesty->SetLineColor(kRed);
    NloBesty->SetLineColor(kGreen);
    SpsBesty->SetLineColor(kBlue);
    DpsBesty->Scale(minan*scaledps);
    NloBesty->Scale(mincn*scalenlo);
    SpsBesty->Scale(minbn*scalesps);
    ySum->Add(DpsBesty);
    ySum->Add(NloBesty);
    ySum->Add(SpsBesty);
    y_data->Draw("e1");
    ySum->Draw("same");
    DpsBesty->Draw("same");
    NloBesty->Draw("same");
    SpsBesty->Draw("same");
    leg->Draw();
  }
Beispiel #15
0
void plotpurity()
{

 Bool_t dolines = kFALSE;
 //Bool_t dolines = kTRUE;
 TString lines = "";

 TString xn = "";
 //TString xn = "_onlyQCD";
 //TString xn = "_onlyGJ";
 //TString xn = "_denominator";
 if(dolines){lines="/lines";}

 std::vector<TString> rebins;
 rebins.push_back("");
// rebins.push_back("rebin1");
// rebins.push_back("rebin2");
// rebins.push_back("rebin3");
// rebins.push_back("rebin4");
// rebins.push_back("rebin5");

 std::vector<TString> ptranges;
// ptranges.push_back("90to120");
// ptranges.push_back("120to155");
// ptranges.push_back("155to175");
 ptranges.push_back("175to190");
 ptranges.push_back("190to250");
 ptranges.push_back("250to400");
 ptranges.push_back("400to700");
 ptranges.push_back("700to1000");
 ptranges.push_back("175to1000");
 //ptranges.push_back("250to1000");
 //ptranges.push_back("400to1000");

 std::vector<TString> isovars;
 //isovars.push_back("wchiso");
 isovars.push_back("chiso");
// isovars.push_back("sieieF5x5");
// isovars.push_back("sieipF5x5");
// isovars.push_back("sipipF5x5");
// isovars.push_back("rho");
// isovars.push_back("nVtx");
// isovars.push_back("phoet");
// isovars.push_back("pfMET");

 std::vector<TString> cuts;
 cuts.push_back("a_idnc");
 cuts.push_back("b_idnc_mL30");
 cuts.push_back("c_idnc_trig");
 cuts.push_back("d_idnc_mL30_trig");
 cuts.push_back("e_idnc_t175");
 cuts.push_back("f_idnc_mL30_t175");
 cuts.push_back("g_idnc_t250");
 cuts.push_back("h_idnc_mL30_t250");
 cuts.push_back("i_idnc_mL30_allt");
// cuts.push_back("oldj");

 TString inpath = "/afs/hep.wisc.edu/cms/tperry/LoneG_slc6_491_CMSSW_7_4_14/src/LoneGamma/qcdStudy/gitignore/Lire/analyzed";
 TString outpath = "/afs/hep.wisc.edu/cms/tperry/LoneG_slc6_491_CMSSW_7_4_14/src/LoneGamma/qcdStudy/gitignore/Lire/plots";
 TString wwwpath = "/afs/hep.wisc.edu/home/tperry/www/MonoPhoton/qcdPlots/Lire/purity";

 TString inname_GJ  = inpath+"/purity_GJets_Merged.root";
 TString inname_QCD = inpath+"/purity_QCD_Merged.root";
// TString inname_GJ  = inpath+"/purity_mrg4bins_GJets.root";
// TString inname_QCD = inpath+"/purity_mrg4bins_QCD.root";
 //TString inname_GJ  = inpath+"/purity_mrg3bins_GJets.root";
 //TString inname_QCD = inpath+"/purity_mrg3bins_QCD.root";
 
 TFile *infile_GJ  = new TFile(inname_GJ);
 TFile *infile_QCD = new TFile(inname_QCD);
 
 ofstream log;
 ofstream log_latex;
 log.open (outpath+"/Purity_log"+xn+".txt");
 log_latex.open (outpath+"/Purity_log_latex"+xn+".txt");

 Int_t fillcolor = 3;
 gStyle->SetOptStat(0);
 gStyle->SetOptTitle(0);
 gStyle->SetFrameLineWidth(3);
 gStyle->SetLineWidth(2);

 TCanvas* canvas = new TCanvas("canvas","canvas",900,100,500,500);
 gStyle->SetOptStat(0);
 gPad->SetTickx();
 gPad->SetTicky();
 gStyle->SetLineWidth(3);


 TText* title = new TText(1,1,"") ;
 title->SetTextSize(0.07);
 title->SetTextColor(kBlack);
 title->SetTextAlign(13);
 title->SetTextFont(62);

 TText* extra = new TText(1,1,"") ;
 extra->SetTextSize(0.05);
 extra->SetTextColor(kBlack);
 extra->SetTextAlign(13);
 extra->SetTextFont(52);

 TText* lumi = new TText(1,1,"") ;
 lumi->SetTextSize(0.05);
 lumi->SetTextColor(kBlack);
 lumi->SetTextAlign(31);
 lumi->SetTextFont(42);

 int c_sig = 4;
 int c_bkg = 2;
 int c_den = 8;
 int ls_cmb = 1;
 int ls_gj  = 2;
 int ls_qcd = 3;

 //for(std::vector<TString>::iterator it = ptranges.begin(); it != ptranges.end(); ++it) {
 for(unsigned i=0; i<ptranges.size(); i++) {
  for(unsigned j=0; j<isovars.size(); j++) {
   for(unsigned k=0; k<cuts.size(); k++) {
    for(unsigned l=0; l<rebins.size(); l++) {

     TString ptrange = ptranges.at(i);
     TString isovar = isovars.at(j);
     TString cut = cuts.at(k);
     TString rebin = rebins.at(l);

     TString cutname;
     if(cut=="idnc"){cutname="ID";}
     if(cut=="idnc_mL30"){cutname="ID+MET";}
     if(cut=="idnc_trig"){cutname="ID+Trigger";}
     if(cut=="idnc_mL30_trig"){cutname="ID+MET+Trigger";}

     TString bwidth;
     if(rebin=="rebin1"){bwidth="width=0.5";}
     if(rebin=="rebin2"){bwidth="width=1.0";}
     if(rebin=="rebin3"){bwidth="width=1.5";}
     if(rebin=="rebin4"){bwidth="width=2.0";}
     if(rebin=="rebin5"){bwidth="width=2.5";}

     std::cout<<boost::format("%8s %15s %7s %7s ") % ptrange % cut % isovar % rebin<<std::endl;

     //Signal purity
     TH1F* h_Nsig_GJ  = (TH1F*)infile_GJ->Get("h_Nsig_"+isovar+"_"+ptrange+"_"+cut);
     TH1F* h_Nsig_QCD = (TH1F*)infile_QCD->Get("h_Nsig_"+isovar+"_"+ptrange+"_"+cut);
     h_Nsig_GJ->Rebin(3); h_Nsig_QCD->Rebin(3); //h_Nsig_GJ->Rebin(l+1); h_Nsig_QCD->Rebin(l+1);
             //TH1F* h_Nsig  = (TH1F*)h_Nsig_QCD->Clone("h_Nsig");
     TH1F* h_Nsig  = (TH1F*)h_Nsig_GJ->Clone("h_Nsig");
     h_Nsig->Add(h_Nsig_QCD);
     h_Nsig->SetLineColor(c_sig); h_Nsig_GJ->SetLineColor(c_sig); h_Nsig_QCD->SetLineColor(c_sig);
     h_Nsig->SetLineStyle(ls_cmb); h_Nsig_GJ->SetLineStyle(ls_gj); h_Nsig_QCD->SetLineStyle(ls_qcd);
     h_Nsig->SetLineWidth(2); h_Nsig_GJ->SetLineWidth(2); h_Nsig_QCD->SetLineWidth(2);
     //Background purity
     TH1F* h_Nbkg_GJ  = (TH1F*)infile_GJ->Get("h_Nbkg_"+isovar+"_"+ptrange+"_"+cut);
     TH1F* h_Nbkg_QCD = (TH1F*)infile_QCD->Get("h_Nbkg_"+isovar+"_"+ptrange+"_"+cut);
     h_Nbkg_GJ->Rebin(3); h_Nbkg_QCD->Rebin(3);
             //TH1F* h_Nbkg  = (TH1F*)h_Nbkg_QCD->Clone("h_Nbkg");
     TH1F* h_Nbkg  = (TH1F*)h_Nbkg_GJ->Clone("h_Nbkg");
     h_Nbkg->Add(h_Nbkg_QCD);
     h_Nbkg->SetLineColor(c_bkg); h_Nbkg_GJ->SetLineColor(c_bkg); h_Nbkg_QCD->SetLineColor(c_bkg);
     h_Nbkg->SetLineStyle(ls_cmb); h_Nbkg_GJ->SetLineStyle(ls_gj); h_Nbkg_QCD->SetLineStyle(ls_qcd);
     h_Nbkg->SetLineWidth(2); h_Nbkg_GJ->SetLineWidth(2); h_Nbkg_QCD->SetLineWidth(2);

     //Denominator
     TH1F* h_Deno_GJ  = (TH1F*)h_Nsig_GJ->Clone("h_Deno_GJ");
     h_Deno_GJ->Add(h_Nbkg_GJ);

     TH1F* h_Deno_QCD  = (TH1F*)h_Nsig_QCD->Clone("h_Deno_QCD");
     h_Deno_QCD->Add(h_Nbkg_QCD);

//     TH1F* h_Deno_GJ  = (TH1F*)infile_GJ->Get("h_Deno_"+isovar+"_"+ptrange+"_"+cut);
//     TH1F* h_Deno_QCD = (TH1F*)infile_QCD->Get("h_Deno_"+isovar+"_"+ptrange+"_"+cut);
//     h_Deno_GJ->Rebin(3); h_Deno_QCD->Rebin(3);
//             //TH1F* h_Deno  = (TH1F*)h_Deno_QCD->Clone("h_Deno");
     TH1F* h_Deno  = (TH1F*)h_Deno_GJ->Clone("h_Deno");
     h_Deno->Add(h_Deno_QCD);

     h_Deno->SetLineColor(c_den); h_Deno_GJ->SetLineColor(c_den); h_Deno_QCD->SetLineColor(c_den);
     h_Deno->SetLineStyle(ls_cmb); h_Deno_GJ->SetLineStyle(ls_gj); h_Deno_QCD->SetLineStyle(ls_qcd);
     h_Deno->SetLineWidth(1); h_Deno_GJ->SetLineWidth(1); h_Deno_QCD->SetLineWidth(1);

     // should probably add these as last bin..
     h_Nsig->ClearUnderflowAndOverflow();
     h_Nbkg->ClearUnderflowAndOverflow();
     h_Deno->ClearUnderflowAndOverflow();
     
     //Define purity
     TGraphAsymmErrors *purity_signal     = new TGraphAsymmErrors(h_Nsig,h_Deno,"n");
     purity_signal->SetLineWidth(2);
     purity_signal->SetLineColor(4);
     purity_signal->SetMarkerColor(4);
     purity_signal->SetMarkerStyle(20);
     
     TGraphAsymmErrors *purity_background = new TGraphAsymmErrors(h_Nbkg,h_Deno,"n");
     purity_background->SetLineWidth(2);
     purity_background->SetLineColor(2);
     purity_background->SetMarkerColor(2);
     purity_background->SetMarkerStyle(24);

     //-----------------------------------------------------
     // Calculations
     log<<boost::format("%8s %15s %7s %7s ") % ptrange % cut % isovar % rebin  ;

     // Start lower bound calculation
     Int_t nbins;
     nbins = purity_background->GetN();
     log<<boost::format("(%2i bins) \n") % nbins ; 

     std::vector<Double_t> thresholds, xsatthresh, ysatthresh, xsatqt, avgpur;
     std::vector<Int_t> batthresh, batqt;

     thresholds.clear(); // purity thresholds
     xsatthresh.clear(); // x st. f(x) > thresh
     ysatthresh.clear(); // y = f(x)x at thresh
     batthresh.clear();  // bin corresponding to x

     batqt.clear();      // bin at upper threshold
     xsatqt.clear();     // x value at upper thresh

     avgpur.clear();     // average purity over range

     thresholds.push_back(0.50);
     thresholds.push_back(0.55);
     thresholds.push_back(0.60);
     thresholds.push_back(0.65);
     thresholds.push_back(0.70);
     Int_t nthreshs;
     nthreshs = thresholds.size();

     // find purity lower bounds = x st. f(x)>thresh
     Double_t pointx, pointy;     
     for(int m=0; m<nbins; ++m){
      purity_background->GetPoint(m, pointx, pointy);
      //log<<boost::format(" %2i %2.2f %2.2f \n") % i % pointx % pointy;
      
      for(int n=0; n<nthreshs; ++n){
       if(pointy > thresholds.at(n) && ysatthresh.size()==n ){
        ysatthresh.push_back(pointy);
        xsatthresh.push_back(pointx);
        batthresh.push_back(h_Nsig->FindBin(pointx));
       }
      }
     }

     // for thresholds never reached, fill with content of xmax
     purity_background->GetPoint(nbins-1,pointx,pointy);
     Int_t nrnpassthresh = 0;
     nrnpassthresh = nthreshs - ysatthresh.size();
     for(int n=0; n<nrnpassthresh; ++n){
       ysatthresh.push_back(pointy);
       xsatthresh.push_back(pointx);
       batthresh.push_back(h_Nsig->FindBin(pointx));
     }

     //// dump lower bound threshold info
     //for(int n=0; n<nthreshs; ++n){
     // log<<boost::format("  Threshold: %.2f  %2i (%2.2f, %0.2f)\n")
     //  % thresholds.at(n) % batthresh.at(n) % xsatthresh.at(n) % ysatthresh.at(n) ;
     //}

     log<<boost::format("   Threshold bin (xx.x,yy.y) TotalSize   above|below\n");
     // Start upper bound calculation
     Double_t fullsize = h_Nbkg->Integral(0,-1);
     for(int n=0; n<nthreshs; ++n){
      Double_t sizedown = h_Nbkg->Integral(0,batthresh.at(n)-1);
      Double_t sizeup =   h_Nbkg->Integral(batthresh.at(n),-1);
      log<<boost::format("    %7.2f %3i (%2.1f,%1.2f)    %4.1f  %6.1f|%6.1f \n")
       % thresholds.at(n) % batthresh.at(n) % xsatthresh.at(n) % ysatthresh.at(n)    
       % fullsize % sizeup % sizedown ;
     }

     // upper bound calculation 
     // keep adding contents of bins starting at threshbin 
      // until sum > fraction (1/4) of full integral
     Double_t goalsize = fullsize / 4.;

     for(int n=0; n<nthreshs; ++n){
      Double_t thissize = 0.;
      int thisbin = batthresh.at(n);
      while( thisbin < nbins+1 ){
       thissize += h_Nbkg->GetBinContent(thisbin); 
       if(thissize > goalsize){
        break;
        }
       thisbin++;
      }
      batqt.push_back(thisbin);
      xsatqt.push_back(h_Nbkg->GetBinCenter(thisbin));
     }

    log<<"       Target Eventcount: "<<goalsize<<" = fullsize/4 = "<<fullsize<<"/4 \n";
     log<<boost::format("   Threshold blo bhi (xlo,xhi) Int(blo,bhi) Int(blo,bhi+1) Int(blo,bhi-1)\n");

    // find average purity over range
    // must weight each purity bin by nr. events in bin
    for(int n=0; n<nthreshs; ++n){
     int nbins = batqt.at(n) - batthresh.at(n);
     //std::cout<<nbins<<" "<<batthresh.at(n)<<" "<<batqt.at(n)<<std::endl;
     Double_t sumpurs, sumweights;
     sumpurs = 0.;
     sumweights = 0.;
     for(int o=0; o<nbins+1; ++o){
      int thisbin = batthresh.at(n) + o;
      int thispoint = thisbin - 1;  // bin nr = point nr + 1
      purity_background->GetPoint(thispoint, pointx,pointy);
      sumpurs += pointy*h_Nbkg->GetBinContent(thisbin);
      sumweights += h_Nbkg->GetBinContent(thisbin);
      //std::cout<<" "<<thispoint<<"|"<<pointy<<"|"<<h_Nbkg->GetBinContent(thisbin)<<" "<<std::endl;;
     }
     //std::cout<<std::endl;
     //std::cout<<sumpurs/sumweights<<std::endl<<std::endl;;
     avgpur.push_back( sumpurs/sumweights );
    }
     log_latex<<"\\begin{tabular}{r|r|r|r|r|r|r|r}\n";
     log_latex<<boost::format("\\multicolumn{2}{c|}{%8s} & \\multicolumn{2}{c|}{%15s} & \\multicolumn{2}{c|}{%7s} & \\multicolumn{2}{c|}{%7s} \\\\ \\hline \\hline  \n") % ptrange % cutname % isovar % bwidth  ;
     log_latex<<boost::format("   %10s & %5s & %5s & %10s & %5s & %8s & %15s & %10s  \\\\  \\hline \n")
      % "Threshold" 
      % "x lo" % "x hi" 
      % "avg purity"
      % "err \\%" 
      % "evts. tot." 
      % "evts. > x lo" 
      % "evts in rng." ;

     ///log_latex<<"\\begin{tabular}{r|r|r|r|r}\n";
     ///log_latex<<boost::format("%8s & \\multicolumn{2}{c}{%15s} & %7s & %7s \\\\  \n \\hline \\hline \n") % ptrange % cutname % isovar % bwidth  ;
     ///log_latex<<boost::format("   %10s & %5s & %5s & %10s & %5s \\\\ \n \\hline \n")
     /// % "Threshold" 
     /// % "x lo" % "x hi" 
     /// % "avg purity"
     /// % "err \\%" ;
    for(int n=0; n<nthreshs; ++n){
     log<<boost::format("    %7.2f %3i %3i (%2.1f,%1.2f) %10.2f %10.2f %10.2f  \n")
      % thresholds.at(n) % batthresh.at(n) %batqt.at(n)
      % xsatthresh.at(n) % xsatqt.at(n) 
      % h_Nbkg->Integral(batthresh.at(n),batqt.at(n))
      % h_Nbkg->Integral(batthresh.at(n),batqt.at(n)+1)
      % h_Nbkg->Integral(batthresh.at(n),batqt.at(n)-1) ;

     Double_t nrevents, errevents, pcterr;
     nrevents = h_Nbkg->IntegralAndError(batthresh.at(n),batqt.at(n),errevents);
     pcterr = errevents/nrevents;
     log_latex<<boost::format("   %10.2f & %5.2f & %5.2f & %10.4f &  %5.2f &  %8.1f & %15.1f & %10.1f  \\\\  \n")
      % thresholds.at(n) 
      % h_Nbkg->GetBinLowEdge(h_Nbkg->FindBin(xsatthresh.at(n))) % h_Nbkg->GetBinLowEdge(h_Nbkg->FindBin(xsatqt.at(n) ))
      //% xsatthresh.at(n) % xsatqt.at(n) 
      % avgpur.at(n)
      % (pcterr*100) 
      % fullsize 
      % h_Nbkg->Integral(batthresh.at(n),-1)
      % h_Nbkg->Integral(batthresh.at(n),batqt.at(n));

     ///log_latex<<boost::format("   %10.2f & %5.2f & %5.2f & %7.3f &  %5.2f  \\\\  \n")
     /// % thresholds.at(n) 
     /// % xsatthresh.at(n) % xsatqt.at(n) 
     /// % avgpur.at(n)
     /// % (pcterr*100) ;
    }
     log_latex<<"\\hline \n  \\end{tabular}\n";

     //-----------------------------------------------------
     // all set, now to start thinking about plotting
     //Make lower bound lines (purity)
     Double_t frac = 1./nthreshs;
     TLine *lgb_lo0 = new TLine(xsatthresh.at(0), 0*frac, xsatthresh.at(0), 1*frac);
     TLine *lgb_lo1 = new TLine(xsatthresh.at(1), 1*frac, xsatthresh.at(1), 2*frac);
     TLine *lgb_lo2 = new TLine(xsatthresh.at(2), 2*frac, xsatthresh.at(2), 3*frac);
     TLine *lgb_lo3 = new TLine(xsatthresh.at(3), 3*frac, xsatthresh.at(3), 4*frac);
     TLine *lgb_lo4 = new TLine(xsatthresh.at(4), 4*frac, xsatthresh.at(4), 5*frac);
     TLine *lgc_lo0 = new TLine(xsatthresh.at(0), 0*frac, xsatthresh.at(0), 1*frac);
     TLine *lgc_lo1 = new TLine(xsatthresh.at(1), 1*frac, xsatthresh.at(1), 2*frac);
     TLine *lgc_lo2 = new TLine(xsatthresh.at(2), 2*frac, xsatthresh.at(2), 3*frac);
     TLine *lgc_lo3 = new TLine(xsatthresh.at(3), 3*frac, xsatthresh.at(3), 4*frac);
     TLine *lgc_lo4 = new TLine(xsatthresh.at(4), 4*frac, xsatthresh.at(4), 5*frac);

     lgb_lo0->SetLineColor(1);
     lgb_lo1->SetLineColor(1);
     lgb_lo2->SetLineColor(1);
     lgb_lo3->SetLineColor(1);
     lgb_lo4->SetLineColor(1);
     lgc_lo0->SetLineColor(2);
     lgc_lo1->SetLineColor(3);
     lgc_lo2->SetLineColor(4);
     lgc_lo3->SetLineColor(5);
     lgc_lo4->SetLineColor(6);

     lgb_lo0->SetLineWidth(4);
     lgb_lo1->SetLineWidth(4);
     lgb_lo2->SetLineWidth(4);
     lgb_lo3->SetLineWidth(4);
     lgb_lo4->SetLineWidth(4);
     lgc_lo0->SetLineWidth(2);
     lgc_lo1->SetLineWidth(2);
     lgc_lo2->SetLineWidth(2);
     lgc_lo3->SetLineWidth(2);
     lgc_lo4->SetLineWidth(2);

     //Make upper bound lines (purity)
     TLine *lgb_hi0 = new TLine(xsatqt.at(0), 0*frac, xsatqt.at(0), 1*frac);
     TLine *lgb_hi1 = new TLine(xsatqt.at(1), 1*frac, xsatqt.at(1), 2*frac);
     TLine *lgb_hi2 = new TLine(xsatqt.at(2), 2*frac, xsatqt.at(2), 3*frac);
     TLine *lgb_hi3 = new TLine(xsatqt.at(3), 3*frac, xsatqt.at(3), 4*frac);
     TLine *lgb_hi4 = new TLine(xsatqt.at(4), 4*frac, xsatqt.at(4), 5*frac);
     TLine *lgc_hi0 = new TLine(xsatqt.at(0), 0*frac, xsatqt.at(0), 1*frac);
     TLine *lgc_hi1 = new TLine(xsatqt.at(1), 1*frac, xsatqt.at(1), 2*frac);
     TLine *lgc_hi2 = new TLine(xsatqt.at(2), 2*frac, xsatqt.at(2), 3*frac);
     TLine *lgc_hi3 = new TLine(xsatqt.at(3), 3*frac, xsatqt.at(3), 4*frac);
     TLine *lgc_hi4 = new TLine(xsatqt.at(4), 4*frac, xsatqt.at(4), 5*frac);

     lgb_hi0->SetLineColor(1);
     lgb_hi1->SetLineColor(1);
     lgb_hi2->SetLineColor(1);
     lgb_hi3->SetLineColor(1);
     lgb_hi4->SetLineColor(1);
     lgc_hi0->SetLineColor(2);
     lgc_hi1->SetLineColor(3);
     lgc_hi2->SetLineColor(4);
     lgc_hi3->SetLineColor(5);
     lgc_hi4->SetLineColor(6);

     lgb_hi0->SetLineWidth(4);
     lgb_hi1->SetLineWidth(4);
     lgb_hi2->SetLineWidth(4);
     lgb_hi3->SetLineWidth(4);
     lgb_hi4->SetLineWidth(4);
     lgc_hi0->SetLineWidth(2);
     lgc_hi1->SetLineWidth(2);
     lgc_hi2->SetLineWidth(2);
     lgc_hi3->SetLineWidth(2);
     lgc_hi4->SetLineWidth(2);

     lgc_hi0->SetLineStyle(2);
     lgc_hi1->SetLineStyle(2);
     lgc_hi2->SetLineStyle(2);
     lgc_hi3->SetLineStyle(2);
     lgc_hi4->SetLineStyle(2);

     //Make avg purity horizontal lines
     TLine *lgb_pur0 = new TLine(xsatthresh.at(0), avgpur.at(0), xsatqt.at(0), avgpur.at(0));
     TLine *lgb_pur1 = new TLine(xsatthresh.at(1), avgpur.at(1), xsatqt.at(1), avgpur.at(1));
     TLine *lgb_pur2 = new TLine(xsatthresh.at(2), avgpur.at(2), xsatqt.at(2), avgpur.at(2));
     TLine *lgb_pur3 = new TLine(xsatthresh.at(3), avgpur.at(3), xsatqt.at(3), avgpur.at(3));
     TLine *lgb_pur4 = new TLine(xsatthresh.at(4), avgpur.at(4), xsatqt.at(4), avgpur.at(4));
     TLine *lgc_pur0 = new TLine(xsatthresh.at(0), avgpur.at(0), xsatqt.at(0), avgpur.at(0));
     TLine *lgc_pur1 = new TLine(xsatthresh.at(1), avgpur.at(1), xsatqt.at(1), avgpur.at(1));
     TLine *lgc_pur2 = new TLine(xsatthresh.at(2), avgpur.at(2), xsatqt.at(2), avgpur.at(2));
     TLine *lgc_pur3 = new TLine(xsatthresh.at(3), avgpur.at(3), xsatqt.at(3), avgpur.at(3));
     TLine *lgc_pur4 = new TLine(xsatthresh.at(4), avgpur.at(4), xsatqt.at(4), avgpur.at(4));

     lgb_pur0->SetLineColor(1);
     lgb_pur1->SetLineColor(1);
     lgb_pur2->SetLineColor(1);
     lgb_pur3->SetLineColor(1);
     lgb_pur4->SetLineColor(1);
     //lgb_pur0->SetLineColor(2);
     //lgb_pur1->SetLineColor(3);
     //lgb_pur2->SetLineColor(4);
     //lgb_pur3->SetLineColor(5);
     //lgb_pur4->SetLineColor(6);
     lgc_pur0->SetLineColor(2);
     lgc_pur1->SetLineColor(3);
     lgc_pur2->SetLineColor(4);
     lgc_pur3->SetLineColor(5);
     lgc_pur4->SetLineColor(6);

     lgb_pur0->SetLineWidth(4);
     lgb_pur1->SetLineWidth(4);
     lgb_pur2->SetLineWidth(4);
     lgb_pur3->SetLineWidth(4);
     lgb_pur4->SetLineWidth(4);
     lgc_pur0->SetLineWidth(2);
     lgc_pur1->SetLineWidth(2);
     lgc_pur2->SetLineWidth(2);
     lgc_pur3->SetLineWidth(2);
     lgc_pur4->SetLineWidth(2);

     //lgc_pur0->SetLineStyle(2);
     //lgc_pur1->SetLineStyle(2);
     //lgc_pur2->SetLineStyle(2);
     //lgc_pur3->SetLineStyle(2);
     //lgc_pur4->SetLineStyle(2);

     //-----------------------------------------------------
     Double_t themax = 0 ;
     themax = std::max(themax, h_Nsig->GetMaximum());
     themax = std::max(themax, h_Nbkg->GetMaximum());
     themax = std::max(themax, h_Deno->GetMaximum());

     //Make lower bound lines (hist)
     Double_t logmax;
     Double_t logmin;
     logmax = std::log(themax);
     logmin = std::log(1);
     Double_t spacing = (logmax-logmin)/nthreshs;
     //std::cout<<spacing<<std::endl;

     //Double_t fifmax = themax/5.;
     TLine *lhb_lo0 = new TLine(xsatthresh.at(0), exp(logmin+0*spacing), xsatthresh.at(0), exp(logmin+1*spacing));
     TLine *lhb_lo1 = new TLine(xsatthresh.at(1), exp(logmin+1*spacing), xsatthresh.at(1), exp(logmin+2*spacing));
     TLine *lhb_lo2 = new TLine(xsatthresh.at(2), exp(logmin+2*spacing), xsatthresh.at(2), exp(logmin+3*spacing));
     TLine *lhb_lo3 = new TLine(xsatthresh.at(3), exp(logmin+3*spacing), xsatthresh.at(3), exp(logmin+4*spacing));
     TLine *lhb_lo4 = new TLine(xsatthresh.at(4), exp(logmin+4*spacing), xsatthresh.at(4), exp(logmin+5*spacing));
     TLine *lhc_lo0 = new TLine(xsatthresh.at(0), exp(logmin+0*spacing), xsatthresh.at(0), exp(logmin+1*spacing));
     TLine *lhc_lo1 = new TLine(xsatthresh.at(1), exp(logmin+1*spacing), xsatthresh.at(1), exp(logmin+2*spacing));
     TLine *lhc_lo2 = new TLine(xsatthresh.at(2), exp(logmin+2*spacing), xsatthresh.at(2), exp(logmin+3*spacing));
     TLine *lhc_lo3 = new TLine(xsatthresh.at(3), exp(logmin+3*spacing), xsatthresh.at(3), exp(logmin+4*spacing));
     TLine *lhc_lo4 = new TLine(xsatthresh.at(4), exp(logmin+4*spacing), xsatthresh.at(4), exp(logmin+5*spacing));

     lhb_lo0->SetLineColor(1);
     lhb_lo1->SetLineColor(1);
     lhb_lo2->SetLineColor(1);
     lhb_lo3->SetLineColor(1);
     lhb_lo4->SetLineColor(1);
     lhc_lo0->SetLineColor(2);
     lhc_lo1->SetLineColor(3);
     lhc_lo2->SetLineColor(4);
     lhc_lo3->SetLineColor(5);
     lhc_lo4->SetLineColor(6);

     lhb_lo0->SetLineWidth(4);
     lhb_lo1->SetLineWidth(4);
     lhb_lo2->SetLineWidth(4);
     lhb_lo3->SetLineWidth(4);
     lhb_lo4->SetLineWidth(4);
     lhc_lo0->SetLineWidth(2);
     lhc_lo1->SetLineWidth(2);
     lhc_lo2->SetLineWidth(2);
     lhc_lo3->SetLineWidth(2);
     lhc_lo4->SetLineWidth(2);

     //Make upper bound lines (hist)
     TLine *lhb_hi0 = new TLine(xsatqt.at(0), exp(logmin+0*spacing), xsatqt.at(0), exp(logmin+1*spacing));
     TLine *lhb_hi1 = new TLine(xsatqt.at(1), exp(logmin+1*spacing), xsatqt.at(1), exp(logmin+2*spacing));
     TLine *lhb_hi2 = new TLine(xsatqt.at(2), exp(logmin+2*spacing), xsatqt.at(2), exp(logmin+3*spacing));
     TLine *lhb_hi3 = new TLine(xsatqt.at(3), exp(logmin+3*spacing), xsatqt.at(3), exp(logmin+4*spacing));
     TLine *lhb_hi4 = new TLine(xsatqt.at(4), exp(logmin+4*spacing), xsatqt.at(4), exp(logmin+5*spacing));
     TLine *lhc_hi0 = new TLine(xsatqt.at(0), exp(logmin+0*spacing), xsatqt.at(0), exp(logmin+1*spacing));
     TLine *lhc_hi1 = new TLine(xsatqt.at(1), exp(logmin+1*spacing), xsatqt.at(1), exp(logmin+2*spacing));
     TLine *lhc_hi2 = new TLine(xsatqt.at(2), exp(logmin+2*spacing), xsatqt.at(2), exp(logmin+3*spacing));
     TLine *lhc_hi3 = new TLine(xsatqt.at(3), exp(logmin+3*spacing), xsatqt.at(3), exp(logmin+4*spacing));
     TLine *lhc_hi4 = new TLine(xsatqt.at(4), exp(logmin+4*spacing), xsatqt.at(4), exp(logmin+5*spacing));

     lhb_hi0->SetLineColor(1);
     lhb_hi1->SetLineColor(1);
     lhb_hi2->SetLineColor(1);
     lhb_hi3->SetLineColor(1);
     lhb_hi4->SetLineColor(1);
     lhc_hi0->SetLineColor(2);
     lhc_hi1->SetLineColor(3);
     lhc_hi2->SetLineColor(4);
     lhc_hi3->SetLineColor(5);
     lhc_hi4->SetLineColor(6);

     lhb_hi0->SetLineWidth(4);
     lhb_hi1->SetLineWidth(4);
     lhb_hi2->SetLineWidth(4);
     lhb_hi3->SetLineWidth(4);
     lhb_hi4->SetLineWidth(4);
     lhc_hi0->SetLineWidth(2);
     lhc_hi1->SetLineWidth(2);
     lhc_hi2->SetLineWidth(2);
     lhc_hi3->SetLineWidth(2);
     lhc_hi4->SetLineWidth(2);

     lhc_hi0->SetLineStyle(2);
     lhc_hi1->SetLineStyle(2);
     lhc_hi2->SetLineStyle(2);
     lhc_hi3->SetLineStyle(2);
     lhc_hi4->SetLineStyle(2);
     //-----------------------------------------------------


     //-----------------------------------------------------
     //Draw Histograms
     TLegend *meg = new TLegend(0.4,0.6,0.88,0.88);
     //meg->SetTextSize(0.04) ;
     meg->SetFillColor(0); meg->SetShadowColor(0);meg->SetBorderSize(2);
     meg->SetTextFont(22.);
     meg->AddEntry(h_Nsig,"Signal","l");
     meg->AddEntry(h_Nsig_GJ,"Signal (GJ MC)","l");
     meg->AddEntry(h_Nsig_QCD,"Signal (QCD MC)","l");
     meg->AddEntry(h_Nbkg,"Background","l");
     meg->AddEntry(h_Nbkg_GJ,"Background (GJ MC)","l");
     meg->AddEntry(h_Nbkg_QCD,"Background (QCD MC)","l");
     meg->AddEntry(h_Deno,"Denominator","l");
     meg->AddEntry(h_Deno_GJ,"Denominator (GJ MC)","l");
     meg->AddEntry(h_Deno_QCD,"Denominator (QCD MC)","l");
     
     TString leg_h0;  leg_h0.Form("Purity > %0.2f (%2.1f-%2.1f)", thresholds.at(0), xsatthresh.at(0), xsatqt.at(0));
     TString leg_h1;  leg_h1.Form("Purity > %0.2f (%2.1f-%2.1f)", thresholds.at(1), xsatthresh.at(1), xsatqt.at(1));
     TString leg_h2;  leg_h2.Form("Purity > %0.2f (%2.1f-%2.1f)", thresholds.at(2), xsatthresh.at(2), xsatqt.at(2));
     TString leg_h3;  leg_h3.Form("Purity > %0.2f (%2.1f-%2.1f)", thresholds.at(3), xsatthresh.at(3), xsatqt.at(3));
     TString leg_h4;  leg_h4.Form("Purity > %0.2f (%2.1f-%2.1f)", thresholds.at(4), xsatthresh.at(4), xsatqt.at(4));

     TLegend *neg = new TLegend(0.15,0.5,0.4,0.75);
     //meg->SetTextSize(0.04) ;
     neg->SetFillColor(0); neg->SetShadowColor(0);neg->SetBorderSize(2);
     neg->SetTextFont(22.);
     neg->AddEntry(lhc_lo0,leg_h0,"l");
     neg->AddEntry(lhc_lo1,leg_h1,"l");
     neg->AddEntry(lhc_lo2,leg_h2,"l");
     neg->AddEntry(lhc_lo3,leg_h3,"l");
     neg->AddEntry(lhc_lo4,leg_h4,"l");

     h_Nsig->SetTitle(cut);
     h_Nsig->SetXTitle(h_Nsig->GetTitle());
     h_Nsig->SetYTitle("Events ");
     h_Nsig->SetMaximum(1000*themax);
     h_Nsig->SetMinimum(1);

     h_Nsig->Draw("hist");
     h_Nsig_GJ->Draw("hist,same");
     h_Nsig_QCD->Draw("hist,same");
     h_Nbkg->Draw("hist,same");
     h_Nbkg_GJ->Draw("hist,same");
     h_Nbkg_QCD->Draw("hist,same");
     h_Deno->Draw("hist,same");
     h_Deno_GJ->Draw("hist,same");
     h_Deno_QCD->Draw("hist,same");

     meg->SetHeader("photon p_{T}: "+ptrange);
     meg->Draw();
     if(dolines){
      neg->Draw();
     }
     title->DrawTextNDC(0.17,0.87,"CMS");
     extra->DrawTextNDC(0.17,0.81,"Preliminary");
     lumi->DrawTextNDC(0.9,0.91,"2.32 /fb (13 TeV)");

     if(dolines){
      lhb_lo0->Draw();
      lhb_lo1->Draw();
      lhb_lo2->Draw();
      lhb_lo3->Draw();
      lhb_lo4->Draw();
      
      lhb_hi0->Draw();
      lhb_hi1->Draw();
      lhb_hi2->Draw();
      lhb_hi3->Draw();
      lhb_hi4->Draw();

      lhc_lo0->Draw();
      lhc_lo1->Draw();
      lhc_lo2->Draw();
      lhc_lo3->Draw();
      lhc_lo4->Draw();
      
      lhc_hi0->Draw();
      lhc_hi1->Draw();
      lhc_hi2->Draw();
      lhc_hi3->Draw();
      lhc_hi4->Draw();
     }

     gPad->SetLogy();

     canvas->SaveAs(outpath+"/Histos_"+isovar+"_"+ptrange+"_"+cut+rebin+xn+".pdf");
     canvas->SaveAs(wwwpath+"/pdf/"+ptrange+"/"+isovar+"/"+cut+lines+"/Histos_"+isovar+"_"+ptrange+"_"+cut+rebin+xn+".pdf");
     canvas->SaveAs(wwwpath+"/png/"+ptrange+"/"+isovar+"/"+cut+lines+"/Histos_"+isovar+"_"+ptrange+"_"+cut+rebin+xn+".png");
     canvas->Clear();
     gPad->SetLogy(kFALSE);
     //-----------------------------------------------------
     //-----------------------------------------------------
     //Draw Purity
     TLegend *leg = new TLegend(0.5,0.75,0.88,0.88);
     leg->SetTextSize(0.04) ;
     leg->SetFillColor(0); leg->SetShadowColor(0);leg->SetBorderSize(0);
     leg->SetTextFont(22.);
     leg->AddEntry(purity_signal,"Signal","lep");
     leg->AddEntry(purity_background,"Background","lep");

     float xmin ; //= 0.;
     float xmax ; //= 25.;
     xmin = h_Nsig->GetXaxis()->GetXmin();
     xmax = h_Nsig->GetXaxis()->GetXmax();
     TLine *lowline = new TLine(xmin,0,xmax,0);
     TLine *hiline = new TLine(xmin,1,xmax,1);
     lowline->SetLineWidth(1); lowline->SetLineColor(1); lowline->SetLineStyle(3);         
     hiline->SetLineWidth(1); hiline->SetLineColor(1); hiline->SetLineStyle(3);         

     TH1F *hframe = canvas->DrawFrame(xmin,-0.05,xmax,1.4,"");
     lowline->Draw();
     hiline->Draw();
     title->DrawTextNDC(0.17,0.87,"CMS");
     extra->DrawTextNDC(0.17,0.81,"Preliminary");
     lumi->DrawTextNDC(0.9,0.91,"2.32 /fb (13 TeV)");
     hframe->SetTitle(cut);
     hframe->SetXTitle(isovar);
     hframe->SetYTitle("Purity");
     
     // draw points
     purity_signal->Draw("P");
     purity_background->Draw("P");
     leg->SetHeader("photon p_{T}: "+ptrange);
     leg->Draw();

     //canvas->SaveAs(outpath+"/Purity_"+isovar+"_"+ptrange+"_"+cut+"_"+rebin+xn+".pdf");

     if(dolines){
      lgb_lo0->Draw();
      lgb_lo1->Draw();
      lgb_lo2->Draw();
      lgb_lo3->Draw();
      lgb_lo4->Draw();
      
      lgb_hi0->Draw();
      lgb_hi1->Draw();
      lgb_hi2->Draw();
      lgb_hi3->Draw();
      lgb_hi4->Draw();
      
      lgc_lo0->Draw();
      lgc_lo1->Draw();
      lgc_lo2->Draw();
      lgc_lo3->Draw();
      lgc_lo4->Draw();
      
      lgc_hi0->Draw();
      lgc_hi1->Draw();
      lgc_hi2->Draw();
      lgc_hi3->Draw();
      lgc_hi4->Draw();

      lgb_pur0->Draw();
      lgb_pur1->Draw();
      lgb_pur2->Draw();
      lgb_pur3->Draw();
      lgb_pur4->Draw();
      lgc_pur0->Draw();
      lgc_pur1->Draw();
      lgc_pur2->Draw();
      lgc_pur3->Draw();
      lgc_pur4->Draw();
     }
     
     canvas->SaveAs(outpath+"/Purity_"+isovar+"_"+ptrange+"_"+cut+rebin+xn+".pdf");
     canvas->SaveAs(wwwpath+"/pdf/"+ptrange+"/"+isovar+"/"+cut+lines+"/Purity_"+isovar+"_"+ptrange+"_"+cut+rebin+xn+".pdf");
     canvas->SaveAs(wwwpath+"/png/"+ptrange+"/"+isovar+"/"+cut+lines+"/Purity_"+isovar+"_"+ptrange+"_"+cut+rebin+xn+".png");

     canvas->Clear();
     //-----------------------------------------------------

     // clean your room!
     h_Nsig->Delete();
     h_Nsig_GJ->Delete();
     h_Nsig_QCD->Delete();
     h_Nbkg->Delete();
     h_Nbkg_GJ->Delete();
     h_Nbkg_QCD->Delete();
     h_Deno->Delete();
     h_Deno_GJ->Delete();
     h_Deno_QCD->Delete();
    }
   log<<"--------------------------------------\n";
   log_latex<<"--------------------------------------\n";
   }
  }
 }
 log.close();
 log_latex.close();
}
Beispiel #16
0
//void Plot(string observable = string ("NjetsNBjets_0_1.70"), string outname = string("TCHEL")){
void Plot2_main(string observable, string outname){
  
  /*
    gStyle->SetPadRightMargin(0.13);
    gStyle->SetPadLeftMargin(0.13);
    gStyle->SetPadBottomMargin(0.13);
  */
  
  
  float SF_trigger_error = 0.015;
  float SF_Lepton_error  = 0.010;
  float SF_MET_error     = 0.016;
  float SF_bag1_error     = 0.01;
  float SF_bag2_error     = 0.02;
 
  
  float systeError_VV     = 0.33;
  float systeError_stop   = 0.31;
  float systeError_ttbar  = 0.04;
  
  double frac_ee   = 0;
  double frac_mumu = 0;
  double frac_emu  = 0;
  
  
  float lumi_error=0.022;
  
  
  // For the canvas:
  gStyle->SetCanvasBorderMode(0);
  gStyle->SetCanvasColor(0); // must be kWhite but I dunno how to do that in PyROOT
  gStyle->SetCanvasDefH(600); //Height of canvas
  gStyle->SetCanvasDefW(600); //Width of canvas
  gStyle->SetCanvasDefX(0);   //POsition on screen
  gStyle->SetCanvasDefY(0);
  
  
  // For the Pad:
  gStyle->SetPadBorderMode(0);
  // ROOT . gStyle . SetPadBorderSize(Width_t size = 1);
  gStyle->SetPadColor(0); // kWhite
  gStyle->SetPadGridX(0); //false
  gStyle->SetPadGridY(0); //false
  gStyle->SetGridColor(0);
  gStyle->SetGridStyle(3);
  gStyle->SetGridWidth(1);
  
  // For the frame:
  gStyle->SetFrameBorderMode(0);
  gStyle->SetFrameBorderSize(1);
  gStyle->SetFrameFillColor(0);
  gStyle->SetFrameFillStyle(0);
  gStyle->SetFrameLineColor(1);
  gStyle->SetFrameLineStyle(1);
  gStyle->SetFrameLineWidth(1);
  
  // For the histo:
  // ROOT . gStyle . SetHistFillColor(1);
  // ROOT . gStyle . SetHistFillStyle(0);
  gStyle->SetHistLineColor(1);
  gStyle->SetHistLineStyle(0);
  gStyle->SetHistLineWidth(1);
  // ROOT . gStyle . SetLegoInnerR(Float_t rad = 0.5);
  // ROOT . gStyle . SetNumberContours(Int_t number = 20);
  
  gStyle->SetEndErrorSize(2);
  //ROOT . gStyle . SetErrorMarker(20);   /// I COMMENTED THIS OUT
  //ROOT . gStyle . SetErrorX(0.);
  
  //ROOT . gStyle . SetMarkerStyle(20);
  
  
  //For the fit/function:
  gStyle->SetOptFit(1011);
  gStyle->SetFitFormat("5.4g");
  gStyle->SetFuncColor(2);
  gStyle->SetFuncStyle(1);
  gStyle->SetFuncWidth(1);
  
  //For the date:
  gStyle->SetOptDate(0);
  // ROOT . gStyle . SetDateX(Float_t x = 0.01);
  // ROOT . gStyle . SetDateY(Float_t y = 0.01);
  
  // For the statistics box:
  gStyle->SetOptFile(0);
  gStyle->SetOptStat(0); // To display the mean and RMS:   SetOptStat("mr");
  gStyle->SetStatColor(0); // kWhite
  gStyle->SetStatFont(42);
  //ROOT . gStyle . SetStatFontSize(0.025);
  gStyle->SetStatFontSize(0.04);
  gStyle->SetStatTextColor(1);
  gStyle->SetStatFormat("6.4g");
  gStyle->SetStatBorderSize(1);
  gStyle->SetStatH(0.1);
  gStyle->SetStatW(0.15);
  // ROOT . gStyle . SetStatStyle(Style_t style = 1001);
  // ROOT . gStyle . SetStatX(Float_t x = 0);
  // ROOT . gStyle . SetStatY(Float_t y = 0);
  
  // Margins:
  gStyle->SetPadTopMargin(0.07);
  gStyle->SetPadBottomMargin(0.13);
  gStyle->SetPadLeftMargin(0.16);
  //ROOT . gStyle . SetPadRightMargin(0.12);
  gStyle->SetPadRightMargin(0.03);
  
  // For the Global title:
  
  gStyle->SetOptTitle(0);
  gStyle->SetTitleFont(42);
  gStyle->SetTitleColor(1);
  gStyle->SetTitleTextColor(1);
  gStyle->SetTitleFillColor(10);
  gStyle->SetTitleFontSize(0.05);
  // ROOT . gStyle . SetTitleH(0); // Set the height of the title box
  // ROOT . gStyle . SetTitleW(0); // Set the width of the title box
  // ROOT . gStyle . SetTitleX(0); // Set the position of the title box
  // ROOT . gStyle . SetTitleY(0.985); // Set the position of the title box
  // ROOT . gStyle . SetTitleStyle(Style_t style = 1001);
  // ROOT . gStyle . SetTitleBorderSize(2);
  
  // For the axis titles:
  
  gStyle->SetTitleColor(1, "XYZ");
  gStyle->SetTitleFont(42, "XYZ");
  gStyle->SetTitleSize(0.06, "XYZ");
  // ROOT . gStyle . SetTitleXSize(Float_t size = 0.02); // Another way to set the size?
  // ROOT . gStyle . SetTitleYSize(Float_t size = 0.02);
  gStyle->SetTitleXOffset(0.9);
  gStyle->SetTitleYOffset(1.25);
  // ROOT . gStyle . SetTitleOffset(1.1, "Y"); // Another way to set the Offset
  
  // For the axis labels:
  
  gStyle->SetLabelColor(1, "XYZ");
  gStyle->SetLabelFont(42, "XYZ");
  gStyle->SetLabelOffset(0.007, "XYZ");
  gStyle->SetLabelSize(0.05, "XYZ");
  
  // For the axis:
  
  gStyle->SetAxisColor(1, "XYZ");
  gStyle->SetStripDecimals(1); // 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);
  
  // Change for log plots:
  gStyle->SetOptLogx(0);
  gStyle->SetOptLogy(0);
  gStyle->SetOptLogz(0);
  
  // Postscript options:
  gStyle->SetPaperSize(20.,20.);
  // ROOT . gStyle . SetLineScalePS(Float_t scale = 3);
  // ROOT . gStyle . SetLineStyleString(Int_t i, const char* text);
  // ROOT . gStyle . SetHeaderPS(const char* header);
  // ROOT . gStyle . SetTitlePS(const char* pstitle);
  
  // ROOT . gStyle . SetBarOffset(Float_t baroff = 0.5);
  // ROOT . gStyle . SetBarWidth(Float_t barwidth = 0.5);
  // ROOT . gStyle . SetPaintTextFormat(const char* format = "g");
  // ROOT . gStyle . SetPalette(Int_t ncolors = 0, Int_t* colors = 0);
  // ROOT . gStyle . SetTimeOffset(Double_t toffset);
  // ROOT . gStyle . SetHistMinimumZero(kTRUE);
  






  //TFile * file = new TFile("templates_proof_with_Wjets.root","OPEN");
  TFile * file = new TFile("outfile_Template.root","OPEN");
  cout<<"toto"<<endl;
  vector<pair<string,int> > process;
  process.push_back(pair<string,int>(string("TTbarSig"),kRed+1));
  process.push_back(pair<string,int>(string("TTbarBkg"),kRed-7));
  process.push_back(pair<string,int>(string("Wjets"),kGreen-3));
  process.push_back(pair<string,int>(string("VV"),13));
  process.push_back(pair<string,int>(string("StW"),kMagenta));
  process.push_back(pair<string,int>(string("Zjets"),kAzure-2));
  process.push_back(pair<string,int>(string("Data"),1));
  
  cout<<"toto"<<endl;
  vector<string> channels;
  channels.push_back(string("ee"));
  channels.push_back(string("emu"));
  channels.push_back(string("mumu"));
  
  cout<<"toto"<<endl;
  
  //string observable ("NjetsNBjets_0_1.70");
  
  cout<<"toto"<<endl;
  /*
    TH2F* histoEmpty = new TH2F("emtpy","",10,0,10,0,500);
    histoEmpty->GetXaxis()->SetTitle("(N_{jets},N_{b-tagged jets})");
    histoEmpty->GetYaxis()->SetTitle("Events");
    histoEmpty->Draw("");
  */
  
  
  TCanvas *c1 = new TCanvas("c1","c1", 1000, 800);
  c1->SetBottomMargin(0.3);
  c1->cd();
  
  
  
  
  TH1D* histo1D_ttSig = new TH1D("histo_ttSig","",11, 0, 11);
  TH1D* histo1D_ttBkg = new TH1D("histo_ttBkg","",11, 0, 11);
  TH1D* histo1D_VV    = new TH1D("histo_VV",   "",11, 0, 11);
  TH1D* histo1D_tW    = new TH1D("histo_tW",   "",11, 0, 11);
  TH1D* histo1D_DY    = new TH1D("histo_DY",   "",11, 0, 11);
  TH1D* histo1D_Data  = new TH1D("histo_Data", "",11, 0, 11);
  
  
  
 
   
  
  //******************************
  //get histograms
  //******************************
  
  
  string name = "ee_NjetsNBjets_6_0.244_TTbarSig";
  TH2D* histo2D_ee_ttSig = (TH2D*) file->Get(name.c_str()); 
  name = "ee_NjetsNBjets_6_0.244_TTbarBkg"; 
  TH2D* histo2D_ee_ttBkg = (TH2D*) file->Get(name.c_str()); 
  name = "ee_NjetsNBjets_6_0.244_VV"; 
  TH2D* histo2D_ee_VV = (TH2D*) file->Get(name.c_str()); 
  name = "ee_NjetsNBjets_6_0.244_StW"; 
  TH2D* histo2D_ee_tW = (TH2D*) file->Get(name.c_str()); 
  name = "ee_NjetsNBjets_6_0.244_Zjets"; 
  TH2D* histo2D_ee_Zjets = (TH2D*) file->Get(name.c_str()); 
  name = "ee_NjetsNBjets_6_0.244_Data"; 
  TH2D* histo2D_ee_Data = (TH2D*) file->Get(name.c_str()); 
  
  
  name = "mumu_NjetsNBjets_6_0.244_TTbarSig";
  TH2D* histo2D_mumu_ttSig = (TH2D*) file->Get(name.c_str()); 
  name = "mumu_NjetsNBjets_6_0.244_TTbarBkg"; 
  TH2D* histo2D_mumu_ttBkg = (TH2D*) file->Get(name.c_str()); 
  name = "mumu_NjetsNBjets_6_0.244_VV"; 
  TH2D* histo2D_mumu_VV = (TH2D*) file->Get(name.c_str()); 
  name = "mumu_NjetsNBjets_6_0.244_StW"; 
  TH2D* histo2D_mumu_tW = (TH2D*) file->Get(name.c_str()); 
  name = "mumu_NjetsNBjets_6_0.244_Zjets"; 
  TH2D* histo2D_mumu_Zjets = (TH2D*) file->Get(name.c_str()); 
  name = "mumu_NjetsNBjets_6_0.244_Data"; 
  TH2D* histo2D_mumu_Data = (TH2D*) file->Get(name.c_str()); 
  
  
  name = "emu_NjetsNBjets_6_0.244_TTbarSig";
  TH2D* histo2D_emu_ttSig = (TH2D*) file->Get(name.c_str()); 
  name = "emu_NjetsNBjets_6_0.244_TTbarBkg"; 
  TH2D* histo2D_emu_ttBkg = (TH2D*) file->Get(name.c_str()); 
  name = "emu_NjetsNBjets_6_0.244_VV"; 
  TH2D* histo2D_emu_VV = (TH2D*) file->Get(name.c_str()); 
  name = "emu_NjetsNBjets_6_0.244_StW"; 
  TH2D* histo2D_emu_tW = (TH2D*) file->Get(name.c_str()); 
  name = "emu_NjetsNBjets_6_0.244_Zjets"; 
  TH2D* histo2D_emu_Zjets = (TH2D*) file->Get(name.c_str()); 
  name = "emu_NjetsNBjets_6_0.244_Data"; 
  TH2D* histo2D_emu_Data = (TH2D*) file->Get(name.c_str()); 
 
 
  
  
  histo2D_ee_Zjets->Scale(220./histo2D_ee_Zjets->Integral());
  histo2D_emu_Zjets->Scale(136./histo2D_emu_Zjets->Integral());
  histo2D_mumu_Zjets->Scale(217./histo2D_mumu_Zjets->Integral());


  histo2D_ee_ttBkg->Scale(9./histo2D_ee_ttBkg->Integral());
  histo2D_emu_ttBkg->Scale(86./histo2D_emu_ttBkg->Integral());
  histo2D_mumu_ttBkg->Scale(15./histo2D_mumu_ttBkg->Integral());
 
 
  histo2D_ee_ttSig->Scale(1.44);
  histo2D_ee_VV->Scale(1.044);
  histo2D_ee_tW->Scale(1.044);
 
  histo2D_emu_ttSig->Scale(1.044);
  histo2D_emu_VV->Scale(1.044);
  histo2D_emu_tW->Scale(1.044);
 
  histo2D_mumu_ttSig->Scale(1.044);
  histo2D_mumu_VV->Scale(1.044);
  histo2D_mumu_tW->Scale(1.044);
  
  
  frac_ee  += histo2D_ee_Zjets->Integral();
  frac_mumu+= histo2D_emu_Zjets->Integral(); 
  frac_emu += histo2D_mumu_Zjets->Integral();
  
  
  frac_ee   = frac_ee/(  frac_ee+frac_mumu+frac_emu);
  frac_mumu = frac_mumu/(frac_ee+frac_mumu+frac_emu);
  frac_emu  = frac_emu/( frac_ee+frac_mumu+frac_emu);
  
  
  
  
  histo2D_ee_ttSig->Add( histo2D_ee_ttSig, histo2D_mumu_ttSig, 1, 1);
  histo2D_ee_ttSig->Add( histo2D_ee_ttSig, histo2D_emu_ttSig, 1, 1);
  
  histo2D_ee_ttBkg->Add( histo2D_ee_ttBkg, histo2D_mumu_ttBkg, 1, 1);
  histo2D_ee_ttBkg->Add( histo2D_ee_ttBkg, histo2D_emu_ttBkg  , 1, 1);
  
  histo2D_ee_Zjets->Add( histo2D_ee_Zjets, histo2D_mumu_Zjets, 1, 1);
  histo2D_ee_Zjets->Add( histo2D_ee_Zjets, histo2D_emu_Zjets  , 1, 1);
  
  histo2D_ee_VV->Add( histo2D_ee_VV, histo2D_mumu_VV, 1, 1);
  histo2D_ee_VV->Add( histo2D_ee_VV, histo2D_emu_VV  , 1, 1);
  
  histo2D_ee_tW->Add( histo2D_ee_tW, histo2D_mumu_tW, 1, 1);
  histo2D_ee_tW->Add( histo2D_ee_tW, histo2D_emu_tW  , 1, 1);
  
  histo2D_ee_Data->Add( histo2D_ee_Data, histo2D_mumu_Data, 1, 1);
  histo2D_ee_Data->Add( histo2D_ee_Data, histo2D_emu_Data  , 1, 1);
  
  
  
  
  
  //******************************
  //create 1D histograms
  //******************************
  
  
  TH1D* histo1D = new TH1D("histo","",11,0,11);
  histo1D->GetXaxis()->SetBinLabel(1,string("(2,0)").c_str());
  histo1D->GetXaxis()->SetBinLabel(2,string("(2,1)").c_str());
  histo1D->GetXaxis()->SetBinLabel(3,string("(2,2)").c_str());
  histo1D->GetXaxis()->SetBinLabel(4,string("(3,0)").c_str());
  histo1D->GetXaxis()->SetBinLabel(5,string("(3,1)").c_str());
  histo1D->GetXaxis()->SetBinLabel(6,string("(3,2)").c_str());
  histo1D->GetXaxis()->SetBinLabel(7,string("(3,3)").c_str());
  histo1D->GetXaxis()->SetBinLabel(8,string("(#geq4,0)").c_str());
  histo1D->GetXaxis()->SetBinLabel(9,string("(#geq4,1)").c_str());
  histo1D->GetXaxis()->SetBinLabel(10,string("(#geq4,2)").c_str());
  histo1D->GetXaxis()->SetBinLabel(11,string("(#geq4,#geq3)").c_str());
  //histo1D->SetLineColor(0);
  histo1D->GetXaxis()->SetTitle("(N_{jets},N_{btagjets})");
  histo1D->GetYaxis()->SetTitle("Number of Events");
  histo1D->GetYaxis()->SetRangeUser(0.,2500.);
    
  histo1D_Data->GetXaxis()->SetBinLabel(1,string("(2,0)").c_str());
  histo1D_Data->GetXaxis()->SetBinLabel(2,string("(2,1)").c_str());
  histo1D_Data->GetXaxis()->SetBinLabel(3,string("(2,2)").c_str());
  histo1D_Data->GetXaxis()->SetBinLabel(4,string("(3,0)").c_str());
  histo1D_Data->GetXaxis()->SetBinLabel(5,string("(3,1)").c_str());
  histo1D_Data->GetXaxis()->SetBinLabel(6,string("(3,2)").c_str());
  histo1D_Data->GetXaxis()->SetBinLabel(7,string("(3,3)").c_str());
  histo1D_Data->GetXaxis()->SetBinLabel(8,string("(#geq4,0)").c_str());
  histo1D_Data->GetXaxis()->SetBinLabel(9,string("(#geq4,1)").c_str());
  histo1D_Data->GetXaxis()->SetBinLabel(10,string("(#geq4,2)").c_str());
  histo1D_Data->GetXaxis()->SetBinLabel(11,string("(#geq4,#geq3)").c_str());
  //histo1D->SetLineColor(0);
  histo1D_Data->GetXaxis()->SetTitle("(N_{jets},N_{btagjets})");
  histo1D_Data->GetYaxis()->SetTitle("Number of Events");
  histo1D_Data->GetYaxis()->SetRangeUser(0.,2500.);
    
    
    
  for(int ibin = 3; ibin <6; ibin++){
	int max = 4;
	if(ibin>3) max = 5;
	for(int jbin = 1; jbin<max;jbin++){
	  double bin1D = (ibin-3)*3+jbin;
	  histo1D_ttSig->SetBinContent(bin1D, histo2D_ee_ttSig->GetBinContent(ibin,jbin));
	  histo1D_ttBkg->SetBinContent(   bin1D, histo2D_ee_ttBkg->GetBinContent(ibin,jbin)   );
	  histo1D_VV->SetBinContent(      bin1D, histo2D_ee_VV->GetBinContent(ibin,jbin)      );
	  histo1D_tW->SetBinContent(      bin1D, histo2D_ee_tW->GetBinContent(ibin,jbin)      );
	  histo1D_DY->SetBinContent(      bin1D, histo2D_ee_Zjets->GetBinContent(ibin,jbin)   );
	  histo1D_Data->SetBinContent(    bin1D, histo2D_ee_Data->GetBinContent(ibin,jbin)    );
	}
   }
  
  
  //******************************
  //add histograms
  //******************************
  
  /*
  histo1D_ee_TTbarSig->Add(histo1D_ee_TTbarSig, histo1D_mumu_TTbarSig, 1, 1);
  histo1D_ee_TTbarSig->Add(histo1D_ee_TTbarSig, histo1D_emu_TTbarSig, 1, 1);
  
  histo1D_ee_ttBk->Add(histo1D_ee_ttBkg, histo1D_mumu_ttBkg, 1, 1);
  histo1D_ee_ttBk->Add(histo1D_ee_ttBkg, histo1D_emu_ttBkg, 1, 1);
  
  histo1D_ee_VV->Add(histo1D_ee_VV, histo1D_mumu_VV, 1, 1);
  histo1D_ee_VV->Add(histo1D_ee_VV, histo1D_emu_VV, 1, 1);
  
  histo1D_ee_tW->Add(histo1D_ee_tW, histo1D_mumu_tW, 1, 1);
  histo1D_ee_tW->Add(histo1D_ee_tW, histo1D_emu_tW, 1, 1);
  
  histo1D_ee_DY->Add(histo1D_ee_DY, histo1D_mumu_DY, 1, 1);
  histo1D_ee_DY->Add(histo1D_ee_DY, histo1D_emu_DY, 1, 1);
  
  histo1D_ee_Data->Add(histo1D_ee_Data, histo1D_mumu_Data, 1, 1);
  histo1D_ee_Data->Add(histo1D_ee_Data, histo1D_emu_Data, 1, 1);
  */
  
  TH1D* histo1D_mc = (TH1D*) histo1D_ttSig->Clone();
  histo1D_mc->Add(histo1D_mc, histo1D_ttBkg ,1, 1);
  histo1D_mc->Add(histo1D_mc, histo1D_VV ,1, 1);
  histo1D_mc->Add(histo1D_mc, histo1D_tW ,1, 1);
  histo1D_mc->Add(histo1D_mc, histo1D_DY ,1, 1);
  
  TH1F * lumiband = (TH1F*) histo1D_mc->Clone();
  
  for (int ilum=0; ilum<lumiband->GetNbinsX(); ilum++) {    
	  
	  
	  
	  
	  
	  double error_all = 
       pow( histo1D_ttSig->GetBinContent(ilum+1)*lumi_error, 2)+
       //*************************
       //uncertinty on trigger eff
       pow(histo1D_ttSig->GetBinContent(ilum+1)*SF_trigger_error, 2)+
       //*************************
       //uncertinty on lepton sel
       pow(histo1D_ttSig->GetBinContent(ilum+1)*SF_Lepton_error, 2)+
       //*************************
       //uncertinty on met sel
       pow( histo1D_ttSig->GetBinContent(ilum+1)*SF_MET_error, 2);
     
       error_all += pow(histo1D_ttSig->GetBinContent(ilum+1)*systeError_ttbar, 2);   
       if(ilum > 2) error_all += pow(histo1D_ttSig->GetBinContent(ilum+1)*0.01, 2);    
       if(ilum > 6) error_all += pow(histo1D_ttSig->GetBinContent(ilum+1)*0.02, 2);   
       error_all += pow(histo1D_VV->GetBinContent(ilum+1)*systeError_VV, 2);
       error_all += pow(histo1D_tW->GetBinContent(ilum+1)*systeError_stop, 2);
     
        
       //*************************
       //uncertinty on met sel
       if(ilum < 5) pow( histo1D_ttSig->GetBinContent(ilum+1)*0.02, 2);
       if(ilum >= 5 && ilum < 8) pow( histo1D_ttSig->GetBinContent(ilum+1)*0.03, 2);
       if(ilum >= 8)             pow( histo1D_ttSig->GetBinContent(ilum+1)*0.04, 2);
	  
	
	    
	    //frac_ee   = frac_ee/  (frac_ee+frac_mumu+frac_emu);
	    //frac_mumu = frac_mumu/(frac_ee+frac_mumu+frac_emu);
	    //frac_emu  = frac_emu/ (frac_ee+frac_mumu+frac_emu);
	    
	    //cout << "frac_ee   " << frac_ee << endl;
	    //cout << "frac_mumu " << frac_mumu << endl;
	    //cout << "frac_emu  " << frac_emu << endl;
	    
	   error_all += pow(histo1D_DY->GetBinContent(ilum+1)*((0.40/1.9281)*frac_ee + (0.37/1.82219)*frac_mumu+  (0.30/1.38872)*frac_emu), 2);
	   
     lumiband->SetBinError(ilum+1,sqrt(error_all));
     
     //modifications
     histo1D_mc->SetBinError(ilum+1,sqrt(error_all));
  }
  
  
  TGraphErrors *thegraph = new TGraphErrors(lumiband);
  thegraph->SetFillStyle(3005);
  thegraph->SetFillColor(1);
  
  histo1D_ttSig->SetFillStyle(1001);
  histo1D_ttBkg->SetFillStyle(1001);
  histo1D_DY->SetFillStyle(1001);
  histo1D_VV->SetFillStyle(1001);
  histo1D_tW->SetFillStyle(1001);
    
  histo1D_ttSig->SetFillColor(kRed+1);
  histo1D_ttBkg->SetFillColor(kRed-7);
  histo1D_DY->SetFillColor(kAzure-2);
  histo1D_VV->SetFillColor(13);
  histo1D_tW->SetFillColor(kMagenta);
  
  
  histo1D_ttSig->GetYaxis()->CenterTitle();
  histo1D_ttSig->GetYaxis()->SetTitle("");
  histo1D_ttSig->GetXaxis()->SetLabelSize(0);
  histo1D_ttSig->GetXaxis()->SetTitleSize(0);
  
  histo1D_ttBkg->GetYaxis()->CenterTitle();
  histo1D_ttBkg->GetYaxis()->SetTitle("");
  histo1D_ttBkg->GetXaxis()->SetLabelSize(0);
  histo1D_ttBkg->GetXaxis()->SetTitleSize(0);
  
  histo1D_VV->GetYaxis()->CenterTitle();
  histo1D_VV->GetYaxis()->SetTitle("");
  histo1D_VV->GetXaxis()->SetLabelSize(0);
  histo1D_VV->GetXaxis()->SetTitleSize(0);
  
  histo1D_tW->GetYaxis()->CenterTitle();
  histo1D_tW->GetYaxis()->SetTitle("");
  histo1D_tW->GetXaxis()->SetLabelSize(0);
  histo1D_tW->GetXaxis()->SetTitleSize(0);
  
  histo1D_DY->GetYaxis()->CenterTitle();
  histo1D_DY->GetYaxis()->SetTitle("");
  histo1D_DY->GetXaxis()->SetLabelSize(0);
  histo1D_DY->GetXaxis()->SetTitleSize(0);
  
  
  THStack* hs= new THStack();
  hs->Add(histo1D_ttSig);
  hs->Add(histo1D_ttBkg);
  //hs->Add(histo_Wjets);
  hs->Add(histo1D_VV);
  hs->Add(histo1D_tW);
  hs->Add(histo1D_DY);
  
  for (int ibin=0; ibin<lumiband->GetNbinsX(); ibin++) {    
    //hs->GetXaxis()->SetBinLabel(ibin+1, "");
  }
  
  //hs->GetXaxis()->SetLabelSize(0.);
      
  histo1D_Data->GetXaxis()->SetTitle("");
  histo1D_Data->GetYaxis()->SetTitle("");
  histo1D_Data->GetYaxis()->CenterTitle();
  histo1D_Data->GetYaxis()->SetTitle("");
  histo1D_Data->GetXaxis()->SetLabelSize(0);
  histo1D_Data->GetXaxis()->SetTitleSize(0);
  histo1D_Data->SetMarkerStyle(20);
  
  
  histo1D->SetMaximum(2000);
  histo1D->SetMinimum(0);
  
  hs->SetMaximum(2000);
  
  
  TH1D* histo_ratio = (TH1D*) histo1D_Data->Clone();
  
  
  histo1D_Data->GetYaxis()->CenterTitle();
  histo1D_Data->GetYaxis()->SetTitle("");
  histo1D_Data->GetXaxis()->SetLabelSize(0);
  histo1D_Data->GetXaxis()->SetTitleSize(0);
  
  
  
  /*histo1D_mc- >GetYaxis()->CenterTitle();
  histo1D_mc->GetYaxis()->SetTitle("");
  histo1D_mc->GetXaxis()->SetLabelSize(0);
  histo1D_mc->GetXaxis()->SetTitleSize(0);
  */
  histo1D->GetYaxis()->CenterTitle();
  histo1D->GetYaxis()->SetTitle("");
  histo1D->GetXaxis()->SetLabelSize(0);
  histo1D->GetXaxis()->SetTitleSize(0);
  
  
  histo_ratio->GetYaxis()->SetLabelSize(0.1);histo_ratio->GetYaxis()->SetLabelSize(0.1);
  
  histo1D->Draw();
  hs->Draw();
  
  for (int ibin=0; ibin<lumiband->GetNbinsX(); ibin++) {    
    hs->GetXaxis()->SetBinLabel(ibin+1, "");
  }
  
  hs->GetXaxis()->SetLabelSize(0.0);
  hs->GetYaxis()->SetLabelSize(0.04);
  
  
  histo_ratio->GetYaxis()->SetLabelSize(0.1);
  histo1D->Draw("epsame");
  histo1D_Data->SetMarkerSize(1.2);
  histo1D_Data->Draw("epsame");
  //histo1D_Data->Draw("");
  
  thegraph->Draw("e2same");
  histo1D->Draw("same");
  
  
  TLatex *latex = new TLatex();
  latex->SetNDC();
  latex->SetTextSize(0.04);
  latex->SetTextAlign(31); 
  latex->DrawLatex(0.45, 0.95, " ");
  
  
  
  TLatex *latex2 = new TLatex();
  latex2->SetNDC();
  latex2->SetTextSize(0.04);
  latex2->SetTextAlign(31); 
  latex2->DrawLatex(0.87, 0.95, "CMS 2.3 fb^{-1} at #sqrt{s} = 7 TeV");
  
  TString  info_data = "ee, #mu#mu, e#mu channels";
 
  TLatex* text2 = new TLatex(0.45,0.98, info_data);
  text2->SetNDC();
  text2->SetTextAlign(13);
  text2->SetX(0.18);
  text2->SetY(0.92);
  //text2->SetLineWidth(2);
  text2->SetTextFont(42);
  text2->SetTextSize(0.0610687);
  //    text2->SetTextSizePixels(24);// dflt=28
  text2->Draw();

  
  
  
  TLegend* qw = new TLegend(.80,.60,.95,.90);
  
  
  qw->SetShadowColor(0);
  qw->SetFillColor(0);
  qw->SetLineColor(0);
  
  
  //  qw->SetHeader("CMS Preliminary, 881.8 pb^{-1}");
  //  qw->AddEntry(histo_Data,         info_data,                "p");
  qw->AddEntry(histo1D_Data,         "Data" ,                "ep");
  qw->AddEntry(histo1D_DY,        "DY "                  ,"f");
  qw->AddEntry(histo1D_tW,  "tW "                  ,"f");
  qw->AddEntry(histo1D_VV,           "VV "                  ,"f");
  //qw->AddEntry(histo_Wjets,        "W  "                  ,"f");
  //qw->AddEntry(histo_TTbarBkg,     "t#bar{t} other  "     ,"f");
  qw->AddEntry(histo1D_ttBkg,     "non-prompt lepton  "     ,"f");
  qw->AddEntry(histo1D_ttSig,     "t#bar{t} signal "     ,"f");
  qw->SetFillColor(0);
  qw->SetTextFont(42);
  qw->Draw();

  
  
  
  
  
  TPad *canvas_2 = new TPad("canvas_2", "canvas_2", 0.0, 0.0, 1.0, 1.0);
    canvas_2->SetTopMargin(0.7);
    canvas_2->SetFillColor(0);
    canvas_2->SetFillStyle(0);
    canvas_2->SetGridy(1);
    canvas_2->Draw();
    canvas_2->cd(0);
    //gPad->SetBottomMargin(0.375);
    //gPad->SetGridy();
    
    //cout << " 721 histo_ratio->GetTitle()  " << histo_ratio->GetXaxis()->GetTitle() << endl;;
    
    //TH1D* histo_ratio = (TH1D*) histo1D_Data->Clone();
    histo_ratio->SetTitle("");
   
    histo_ratio->SetMarkerStyle(20);
    histo_ratio->SetMarkerSize(1.2);
    histo_ratio->SetMaximum( 1.5 );
    histo_ratio->SetMinimum(0.5);
    histo_ratio->GetYaxis()->SetTitle("");
    histo_ratio->GetXaxis()->SetLabelSize(0.04);
    histo_ratio->GetYaxis()->SetLabelSize(0.03);
    histo_ratio->GetYaxis()->SetNdivisions(6);
    
    histo_ratio->GetYaxis()->SetTitleSize(0.03);
    histo_ratio->SetMarkerSize(1.2);
    //histo_ratio->GetYaxis()->SetNdivisions(5);
    //ratio.Draw("e")
    
    histo_ratio->Divide(histo1D_mc);
    
    
    histo_ratio->SetMinimum(0.5);
    histo_ratio->SetMaximum(1.5);
    histo_ratio->Draw("E1X0");
    

    c1->cd();
   
  

}
Beispiel #17
0
void trigger() {

  gStyle->SetOptStat(1111111);
  
  std::vector<std::string> trig;
  trig.push_back("HLT_HT150_v2");
  trig.push_back("HLT_HT150_AlphaT0p60_v1");
  
  std::vector<std::string> his;
  his.push_back("ge2");
  his.push_back("eq2");
  his.push_back("eq3");
  his.push_back("ge4");
  
  TFile* f =  new TFile(std::string("../Trigger_HT_Run2011A_PromptReco_v1.root").c_str(),"READ");
  if ( f && !f->IsZombie() ) { 
    std::cout << "Opened file: " << f->GetName() << std::endl; 
  } else { 
    std::cout << "Could not find file " << std::endl; 
    //return; 
  }
	  
  TDirectory* d = (f==0?0:(TDirectory*)f->Get("Triggers"));
  if (d) { std::cout << "Opened dir: " << d->GetName() << std::endl; }
  else { 
    std::cout << "Could not find dir " << std::endl; 
    //return; 
  }
  
  TCanvas* c1 = new TCanvas(std::string("trigger").c_str(),
			    std::string("trigger").c_str(),
			    600,600);
  c1->Divide(1,2);

  TLegend* legend = new TLegend( 0.7, 0.6, 0.85, 0.7, NULL, "brNDC" );
  
  std::vector<TH1D*> h(trig.size(),0);
  std::vector<TH1D*> i(trig.size(),0);
  
  for ( int ii = 0; ii < trig.size(); ++ii ) {
    
    std::string str;
    str = trig[ii]+"_all";
//     if      ( his[jj] == "eq2" ) { str = trig[ii]+"_2"; }
//     else if ( his[jj] == "eq3" ) { str = trig[ii]+"_3"; }
//     else if ( his[jj] == "ge4" ) { str = trig[ii]+"_4"; }
//     else                         { str = trig[ii]+"_all"; }
    
    h[ii] = (d==0?0:(TH1D*)d->Get(str.c_str()));
    if (h[ii]) { std::cout << "Opened histo: " << h[ii]->GetName() << std::endl; }
    else { 
      std::cout << "Could not find histo " << std::endl; 
      //continue; 
    }
    
    i[ii] = (h[ii]==0?0:(TH1D*)h[ii]->Clone());
    if (i[ii]) calcIntegral(i[ii],true);
    
    legend->AddEntry( h[ii], trig[ii].c_str(), "pl" );
    
  }
  
//   TGraphAsymmErrors* gr1 = new TGraphAsymmErrors();
//   if ( h[0] && h[1] ) gr1->BayesDivide(h[0],h[1]);
  
//   TGraphAsymmErrors* gr2 = new TGraphAsymmErrors();
//   if ( i[0] && i[1] ) gr2->BayesDivide(i[0],i[1]);
	  
  c1->cd(1);
  if ( h[0] && h[1] ) { 
    h[0]->GetXaxis()->SetTitle("#alpha_{T}");
    h[0]->SetLineColor(kRed);
    h[0]->SetFillColor(kRed-10);
    h[0]->GetXaxis()->SetRangeUser(0.,1.);
    h[0]->Draw("");
    h[1]->GetXaxis()->SetTitle("#alpha_{T}");
    h[1]->GetXaxis()->SetRangeUser(0.,1.);
    h[1]->Draw("sameP");
    
    legend->SetTextSize(0.035);
    //legend->SetFillColor(0);
    //legend->SetLineColor(0); 
    //legend->SetShadowColor(0); 
    legend->Draw("same");
    
  }

  c1->cd(2);
  if ( i[0] && i[1] ) { 
    i[0]->GetXaxis()->SetTitle("#alpha_{T} > cut value");
    i[0]->GetXaxis()->SetRangeUser(0.,1.);
    i[0]->SetLineColor(kRed);
    i[0]->SetFillColor(kRed-10);
    i[0]->Draw("LF2");
    i[1]->GetXaxis()->SetTitle("#alpha_{T} > cut value");
    i[1]->GetXaxis()->SetRangeUser(0.,1.);
    i[1]->Draw("sameP");

    legend->SetTextSize(0.035);
    legend->SetFillColor(0);
    legend->SetLineColor(0); 
    legend->SetShadowColor(0); 
    legend->Draw("same");

  }
  
//   c1->cd(3);
//   if ( h[0] && h[1] ) { 
//     gr1->GetXaxis()->SetTitle("#alpha_{T}");
//     gr1->GetYaxis()->SetTitle("Differential Efficiency");
//     gr1->GetXaxis()->SetRangeUser(0.,1.);
//     gr1->Draw("alp");
//   }
  
//   c1->cd(4);
//   if ( i[0] && i[1] ) {
//     gr2->GetXaxis()->SetTitle("#alpha_{T} > cut value");
//     gr2->GetYaxis()->SetTitle("Cumulative Efficiency");
//     gr2->GetXaxis()->SetRangeUser(0.4,1.0);
//     gr2->GetYaxis()->SetRangeUser(0.9,1.);
//     gr2->Draw("alp");
//   }
  
  //c1->Update();
  c1->SaveAs(std::string("trigger.pdf").c_str());
  
}
//*************************************************************
void arrangeBiasCanvas(TCanvas *canv,TH1F* dxyPhiMeanTrend[100],TH1F* dzPhiMeanTrend[100],TH1F* dxyEtaMeanTrend[100],TH1F* dzEtaMeanTrend[100],Int_t nFiles, TString LegLabels[10]){
//*************************************************************

  TLegend *lego = new TLegend(0.19,0.70,0.79,0.92);
  lego-> SetNColumns(2);
  lego->SetFillColor(10);
  lego->SetTextSize(0.042);
  lego->SetTextFont(42);
  lego->SetFillColor(10);
  lego->SetLineColor(10);
  lego->SetShadowColor(10);

  TPaveText *pt = new TPaveText(0.13,0.95,0.89,0.97,"NDC");
  pt->SetFillColor(10);
  pt->SetTextColor(1);
  pt->SetTextFont(42);
  pt->SetTextAlign(11);
  TText *text1 = pt->AddText("CMS Preliminary 2015 - 3.8T collision data");
  text1->SetTextSize(0.05);
 
  TPaveText *pt2 = new TPaveText(0.70,0.75,0.89,0.92,"NDC");
  pt2->SetFillColor(10);
  pt2->SetTextColor(kBlue);
  pt2->SetTextFont(62);
  pt2->SetTextAlign(11);
  TText *text2 = pt2->AddText("run 247078");
  text2->SetTextSize(0.05);

  canv->SetFillColor(10);  
  canv->Divide(2,2);
 
  canv->cd(1)->SetBottomMargin(0.14);
  canv->cd(1)->SetLeftMargin(0.18);
  canv->cd(1)->SetRightMargin(0.01);
  canv->cd(1)->SetTopMargin(0.06);  

  canv->cd(2)->SetBottomMargin(0.14);
  canv->cd(2)->SetLeftMargin(0.18);
  canv->cd(2)->SetRightMargin(0.01);
  canv->cd(2)->SetTopMargin(0.06);  
  
  canv->cd(3)->SetBottomMargin(0.14);
  canv->cd(3)->SetLeftMargin(0.18);
  canv->cd(3)->SetRightMargin(0.01);
  canv->cd(3)->SetTopMargin(0.06);  

  canv->cd(4)->SetBottomMargin(0.14);
  canv->cd(4)->SetLeftMargin(0.18);
  canv->cd(4)->SetRightMargin(0.01);
  canv->cd(4)->SetTopMargin(0.06); 

  TH1F *dBiasTrend[4][nFiles]; 
  
  for(Int_t i=0;i<nFiles;i++){
    dBiasTrend[0][i] = dxyPhiMeanTrend[i];
    dBiasTrend[1][i] = dzPhiMeanTrend[i];
    dBiasTrend[2][i] = dxyEtaMeanTrend[i];
    dBiasTrend[3][i] = dzEtaMeanTrend[i];
  }

  Double_t absmin[4]={999.,999.,999.,999.};
  Double_t absmax[4]={-999.,-999.-999.,-999.};

  for(Int_t k=0; k<4; k++){

    canv->cd(k+1);
    
    for(Int_t i=0; i<nFiles; i++){
      if(dBiasTrend[k][i]->GetMaximum()>absmax[k]) absmax[k] = dBiasTrend[k][i]->GetMaximum();
      if(dBiasTrend[k][i]->GetMinimum()<absmin[k]) absmin[k] = dBiasTrend[k][i]->GetMinimum();
    }

   
    Double_t safeDelta=(absmax[k]-absmin[k])/8.;
    Double_t theExtreme=std::max(absmax[k],TMath::Abs(absmin[k]));

    for(Int_t i=0; i<nFiles; i++){
      if(i==0){
	//dBiasTrend[i]->GetYaxis()->SetRangeUser(absmin-safeDelta/2.,absmax+safeDelta);
	//std::cout<<"name is: "<< dBiasTrend[k][i]->GetName() <<std::endl;
	TString theTitle = dBiasTrend[k][i]->GetName();
	if( theTitle.Contains("Norm")){
	  dBiasTrend[k][i]->GetYaxis()->SetRangeUser(std::min(-0.48,absmin[k]-safeDelta/2.),std::max(0.48,absmax[k]+safeDelta/2.));
	} else {
	  //dBiasTrend[k][i]->GetYaxis()->SetRangeUser(std::min(-8.8,absmin[k]-safeDelta/2.),std::max(8.8,absmax[k]+safeDelta/2.));
	  dBiasTrend[k][i]->GetYaxis()->SetRangeUser(-theExtreme-(safeDelta/2.),theExtreme+(safeDelta/2.));
	  //dBiasTrend[k][i]->GetYaxis()->SetRangeUser(-theExtreme,theExtreme);
	} 
	dBiasTrend[k][i]->Draw("Le1");
      }
      else dBiasTrend[k][i]->Draw("Le1sames");
      if(k==0){
	lego->AddEntry(dBiasTrend[k][i],LegLabels[i]);
      } 
    }  
  
    lego->Draw();
    pt->Draw("same");
  }
  
}
void Plot_1D_norm_HF(){
  setstyle(0);

  //g_PlotTitle = "Baseline Selection";
  g_PlotTitle = "Base+p_{T}^{ ISR} > 450 GeV";

   int ihist = 0;

   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/Signal/TT_250_77.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("m_{#tilde{t}} = 250, m_{#tilde{#chi}} = 77");
   g_Bkg.push_back(false);
   ihist++;

   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/Signal/TT_300_127.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("m_{#tilde{t}} = 300, m_{#tilde{#chi}} = 127");
   g_Bkg.push_back(false);
   ihist++;

   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/Signal/TT_350_177.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("m_{#tilde{t}} = 350, m_{#tilde{#chi}} = 177");
   g_Bkg.push_back(false);
   ihist++;

   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/Signal/TT_350_150.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("m_{#tilde{t}} = 350, m_{#tilde{#chi}} = 150");
   g_Bkg.push_back(false);
   ihist++;

   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/Signal/TT_400_227.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("m_{#tilde{t}} = 400, m_{#tilde{#chi}} = 227");
   g_Bkg.push_back(false);
   ihist++;

   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/Signal/TT_500_327.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("m_{#tilde{t}} = 500, m_{#tilde{#chi}} = 327");
   g_Bkg.push_back(false);
   ihist++;

   /*
   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/Signal/TT_450_250.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("m_{#tilde{t}} = 450, m_{#tilde{#chi}} = 250");
   g_Bkg.push_back(false);
   ihist++;

   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/Signal/TT_500_300.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("m_{#tilde{t}} = 500, m_{#tilde{#chi}} = 300");
   g_Bkg.push_back(false);
   ihist++;
   */

   /*
   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/Top/ttbar.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("t #bar{t} nominal");
   g_Bkg.push_back(false);
   ihist++;

   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/SYS/PowhegPythiaEvtGen_P2012radHi_ttbar_hdamp345_down_nonallhad.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("t #bar{t} rad hi");
   g_Bkg.push_back(false);
   ihist++;
   
   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/SYS/PowhegPythiaEvtGen_P2012radLo_ttbar_hdamp172_up_nonallhad.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("t #bar{t} rad lo");
   g_Bkg.push_back(false);
   ihist++;

   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/SYS/aMcAtNloHerwigppEvtGen_ttbar_nonallhad.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("t #bar{t} aMC@NLO");
   g_Bkg.push_back(false);
   ihist++;

   g_File.push_back("/Users/crogan/Dropbox/SAMPLES/SussexNt/SYS/PowhegHerwigppEvtGen_UEEE5_ttbar_hdamp172p5_nonallhad.root");
   g_Tree.push_back("HFntupleNONE");
   g_Hist.push_back(ihist);
   g_Title.push_back("t #bar{t} Powheg + H++");
   g_Bkg.push_back(false);
   ihist++;
   */

  int Nsample = g_File.size();
  int Nhist = ihist;

  //g_Xname = "N_{jet}^{ V_{S}}";
  g_Xname = "pre-selection+p_{T}^{ ISR} > 500";
  g_Xmin = 0.0;
  g_Xmax = 1.;
  g_NX = 50;


  TH1D* hist[Nhist];
  for(int i = 0; i < Nhist; i++)
    hist[i] = new TH1D(("h"+to_string(i)).c_str(),
		       ("h"+to_string(i)).c_str(),
		       g_NX,g_Xmin,g_Xmax);

  for(int s = 0; s < Nsample; s++){
    TChain* chain = new TChain(g_Tree[s].c_str());
    chain->Add(g_File[s].c_str());

    SussexBase* base = new SussexBase(chain);

    int Nentry = base->fChain->GetEntries();

    cout << "Sample " << s << " | " << Nsample << endl;
    for(int e = 0; e < Nentry; e++){
      base->GetEntry(e);
      if(e%(max(1,Nentry/10)) == 0)
	cout << "event " << e << " | " << Nentry << endl;

       if(base->HLT_xe70_tc_lcw < 1)
       	continue;

      if(base->eT_miss < 200.)
       	continue;

      if(fabs(base->dPhi_met_trackmet) > acos(-1.)/3.)
	continue;

      if(fabs(base->dPhi_1jet) < 0.4 ||
	 fabs(base->dPhi_2jet) < 0.4)
      	continue;

      if(base->eT_miss_track < 30.)
      	continue;

      if(base->nMu_baseline > 0 ||
	 base->nEl_baseline > 0)
      	 continue;

      if(base->pT_2jet < 80.)
	continue;
      
      if(base->pT_4jet < 40.)
	continue;

      if(base->PTISR < 500.)
       	continue;

      // if(!base->LepVeto)
      //  	continue;

      // if(base->NbV < 1)
      // 	continue;

      // if(base->NjV < 4)
      // 	continue;

      // if(base->pTbV1 < 40.)
      // 	continue;

      // if(base->pTjV5 < 45.)
      // 	continue;

      // if(base->MS < 300)
      //  	 continue;

      // if(base->MS < 100)
      // 	 continue;

      // if(base->MV/base->MS > 0.6)
      // 	 continue;

      // if(base->dphiISRI < 3.0)
      // 	continue;

      double weight = base->XSecWeight*
	base->AnalysisWeight*
	base->btagSFCentral*1000.;
 
      hist[g_Hist[s]]->Fill(base->RISR, weight);

    }

    delete base;
    delete chain;
  }
  
  double max = -1.;
  int imax = -1;
  for(int i = 0; i < Nhist; i++){
    cout << hist[i]->Integral() << " bla" << endl;
    hist[i]->Scale(1./hist[i]->Integral());
    if(hist[i]->GetMaximum() > max){
      max = hist[i]->GetMaximum();
      imax = i;
    }
  }
  
  float width = hist[0]->GetBinWidth(1);
  char *yaxis = new char[100];
  sprintf(yaxis,"Events / %f", width);

  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(11111111);
    TCanvas* can = (TCanvas*) new TCanvas("can","can",600.,500);

    can->SetLeftMargin(0.13);
    can->SetRightMargin(0.04);
    can->SetBottomMargin(0.15);
    can->SetTopMargin(0.085);
    can->SetGridx();
    can->SetGridy();
    can->Draw();
    can->cd();
    hist[imax]->Draw();
    hist[imax]->GetXaxis()->CenterTitle();
    hist[imax]->GetXaxis()->SetTitleFont(132);
    hist[imax]->GetXaxis()->SetTitleSize(0.06);
    hist[imax]->GetXaxis()->SetTitleOffset(1.06);
    hist[imax]->GetXaxis()->SetLabelFont(132);
    hist[imax]->GetXaxis()->SetLabelSize(0.05);
    hist[imax]->GetXaxis()->SetTitle(g_Xname.c_str());
    hist[imax]->GetYaxis()->CenterTitle();
    hist[imax]->GetYaxis()->SetTitleFont(132);
    hist[imax]->GetYaxis()->SetTitleSize(0.06);
    hist[imax]->GetYaxis()->SetTitleOffset(1.);
    hist[imax]->GetYaxis()->SetLabelFont(132);
    hist[imax]->GetYaxis()->SetLabelSize(0.05);
    hist[imax]->GetYaxis()->SetTitle("a. u.");
    //hist[imax]->GetYaxis()->SetTitle(yaxis);
    //hist[imax]->GetYaxis()->SetTitle("N_{evt} / fb^{-1}");
    int Ntype[3];

    Ntype[0] = 0;
    for(int i = 0; i < Nhist; i++){
      hist[i]->SetLineColor(1393+2*Ntype[0]);
      hist[i]->SetLineWidth(3);
      hist[i]->SetMarkerColor(1393+2*Ntype[0]);
      hist[i]->SetMarkerSize(0);
      hist[i]->SetFillColor(kWhite);
      Ntype[0]++;
      hist[i]->Draw("SAME");
    }

    TLegend* leg = new TLegend(0.688,0.22,0.93,0.42);
    leg->SetTextFont(132);
    leg->SetTextSize(0.045);
    leg->SetFillColor(kWhite);
    leg->SetLineColor(kWhite);
    leg->SetShadowColor(kWhite);
    for(int i = 0; i < Nhist; i++)
	leg->AddEntry(hist[i],g_Title[i].c_str());
    leg->SetLineColor(kWhite);
    leg->SetFillColor(kWhite);
    leg->SetShadowColor(kWhite);
    leg->Draw("SAME");

    TLatex l;
    l.SetTextFont(132);
    l.SetNDC();
    l.SetTextSize(0.05);
    l.SetTextFont(132);
    // l.DrawLatex(0.17,0.855,g_PlotTitle.c_str());
    l.DrawLatex(0.65,0.943,g_PlotTitle.c_str());
    l.SetTextSize(0.04);
    l.SetTextFont(42);
    l.DrawLatex(0.15,0.943,"#bf{#it{ATLAS}} Internal 13 TeV Simulation");	

    // l.SetTextSize(0.045);
    // l.SetTextFont(132);
    // string bla = "#scale[0.6]{#int} #it{L dt} = "+to_string(int(g_lumi))+" fb^{-1},  #Delta_{N#scale[0.8]{bkg}} = ";
    // bla += to_string(int(g_deltaNbkg))+" %";
    // l.DrawLatex(0.61,0.943,bla.c_str());


}
void EleScaleClosureTest() {

  //--------------------------------------------------------------------------------------------------------------
  // Settings 
  //============================================================================================================== 
  
  // event category enumeration
  enum { eEleEle2HLT=1, eEleEle1HLT1L1, eEleEle1HLT, eEleEleNoSel, eEleSC };
  
  // Create output directory
  TString outputDir = "EleScaleClosureTestResults";
  TString pufname = "../Tools/pileup_weights_2015B.root";

  gSystem->mkdir(outputDir,kTRUE);
  
  vector<TString> infilenamev;
  infilenamev.push_back("/afs/cern.ch/work/c/cmedlock/public/wz-ntuples/Zee/ntuples/data_select.root");    // data
  infilenamev.push_back("/afs/cern.ch/work/c/cmedlock/public/wz-ntuples/Zee/ntuples/zee_select.raw.root"); // MC (raw)
  infilenamev.push_back("/afs/cern.ch/work/c/cmedlock/public/wz-ntuples/Zee/ntuples/zee_select.raw.root"); // MC2 (corrected)

  enum { eData=0, eMC, eMC2 };

  Float_t lumi=40.0;
  
  const Int_t    NBINS     = 40;
  const Double_t MASS_LOW  = 80;
  const Double_t MASS_HIGH = 100;
  const Double_t PT_CUT    = 25;
  const Double_t ETA_CUT   = 2.5;
  const Double_t ELE_MASS  = 0.000511;  
  
  vector<pair<Double_t,Double_t> > scEta_limits;
  scEta_limits.push_back(make_pair(0.0,0.4));
  scEta_limits.push_back(make_pair(0.4,0.8));
  scEta_limits.push_back(make_pair(0.8,1.4442));
  scEta_limits.push_back(make_pair(1.566,2.5));

  CPlot::sOutDir = outputDir;
  
  const TString format("png");

  TRandom3 *rnd = new TRandom3();  
  
  //--------------------------------------------------------------------------------------------------------------
  // Main analysis code 
  //==============================================================================================================  

  TFile *pufile = new TFile(pufname); assert(pufile);
  TH1D  *puWeights = (TH1D*)pufile->Get("npv_rw");
  
  TH1D* hData_Tot = new TH1D("hData_Tot","",NBINS,MASS_LOW,MASS_HIGH); hData_Tot->Sumw2();
  TH1D* hMC_Tot   = new TH1D("hMC_Tot","",NBINS,MASS_LOW,MASS_HIGH);   hMC_Tot->Sumw2();
  TH1D* hMC2_Tot  = new TH1D("hMC2_Tot","",NBINS,MASS_LOW,MASS_HIGH);  hMC2_Tot->Sumw2();
  
  char hname[100];
  vector<TH1D*> hMCv, hDatav, hMC2v;  
  for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) {
    for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) {
      sprintf(hname,"data_%i_%i",ibin,jbin);
      hDatav.push_back(new TH1D(hname,"",NBINS,MASS_LOW,MASS_HIGH));
      hDatav.back()->Sumw2();

      sprintf(hname,"mc_%i_%i",ibin,jbin);
      hMCv.push_back(new TH1D(hname,"",NBINS,MASS_LOW,MASS_HIGH));
      hMCv.back()->Sumw2();
      
      sprintf(hname,"mc2_%i_%i",ibin,jbin);
      hMC2v.push_back(new TH1D(hname,"",NBINS,MASS_LOW,MASS_HIGH));
      hMC2v.back()->Sumw2();
    }
  }
  
  //
  // Declare output ntuple variables
  //
  UInt_t  runNum, lumiSec, evtNum;
  UInt_t  matchGen;
  UInt_t  category;
  UInt_t  npv, npu;
  Int_t   q1, q2;
  Float_t scale1fb, puWeight;
  TLorentzVector *dilep=0, *lep1=0, *lep2=0;
  ///// electron specific /////
  TLorentzVector *sc1=0, *sc2=0;
  
  for(UInt_t ifile=0; ifile<infilenamev.size(); ifile++) {
    cout << "Processing " << infilenamev[ifile] << "..." << endl;
    TFile *infile = TFile::Open(infilenamev[ifile]); assert(infile);
    TTree *intree = (TTree*)infile->Get("Events"); assert(intree);
  
    intree->SetBranchAddress("runNum",   &runNum);    // event run number
    intree->SetBranchAddress("lumiSec",  &lumiSec);   // event lumi section
    intree->SetBranchAddress("evtNum",   &evtNum);    // event number
    intree->SetBranchAddress("scale1fb", &scale1fb);  // event weight
    intree->SetBranchAddress("puWeight", &puWeight);  // pileup reweighting
    intree->SetBranchAddress("matchGen", &matchGen);  // event has both leptons matched to MC Z->ll
    intree->SetBranchAddress("category", &category);  // dilepton category
    intree->SetBranchAddress("npv",      &npv);	      // number of primary vertices
    intree->SetBranchAddress("npu",      &npu);	      // number of in-time PU events (MC)
    intree->SetBranchAddress("q1",       &q1);	      // charge of lead lepton
    intree->SetBranchAddress("q2",       &q2);	      // charge of trail lepton
    intree->SetBranchAddress("dilep",    &dilep);     // dilepton 4-vector
    intree->SetBranchAddress("lep1",     &lep1);      // lead lepton 4-vector
    intree->SetBranchAddress("lep2",     &lep2);      // trail lepton 4-vector
    intree->SetBranchAddress("sc1",      &sc1);	      // lead Supercluster 4-vector
    intree->SetBranchAddress("sc2",      &sc2);	      // trail Supercluster 4-vector 
  
    for(UInt_t ientry=0; ientry<intree->GetEntries(); ientry++) {
      intree->GetEntry(ientry);
      
      Double_t weight = 1;
      if(ifile==eMC || ifile==eMC2)
        weight=scale1fb*lumi*puWeights->GetBinContent(npv+1);
      
      if((category!=eEleEle2HLT) && (category!=eEleEle1HLT) && (category!=eEleEle1HLT1L1)) continue;
      if(q1 == q2) continue;
      if(dilep->M()	  < MASS_LOW)  continue;
      if(dilep->M()	  > MASS_HIGH) continue;
      if(sc1->Pt()	  < PT_CUT)    continue;
      if(sc2->Pt()	  < PT_CUT)    continue;
      if(fabs(sc1->Eta()) > ETA_CUT)   continue;      
      if(fabs(sc2->Eta()) > ETA_CUT)   continue;

      TLorentzVector vLep1(0,0,0,0); 
      TLorentzVector vLep2(0,0,0,0); 
      if (ifile==eData) {
	vLep1.SetPtEtaPhiM(lep1->Pt(), lep1->Eta(), lep1->Phi(), ELE_MASS);
	vLep2.SetPtEtaPhiM(lep2->Pt(), lep2->Eta(), lep2->Phi(), ELE_MASS);
      }
      else if (ifile==eMC) {
	vLep1.SetPtEtaPhiM(lep1->Pt(), lep1->Eta(), lep1->Phi(), ELE_MASS);
	vLep2.SetPtEtaPhiM(lep2->Pt(), lep2->Eta(), lep2->Phi(), ELE_MASS);
      }
      else {
	vLep1.SetPtEtaPhiM(gRandom->Gaus(lep1->Pt()*getEleScaleCorr(lep1->Eta(),0),getEleResCorr(lep1->Eta(),0)), lep1->Eta(), lep1->Phi(), ELE_MASS);
	vLep2.SetPtEtaPhiM(gRandom->Gaus(lep2->Pt()*getEleScaleCorr(lep2->Eta(),0),getEleResCorr(lep2->Eta(),0)), lep2->Eta(), lep2->Phi(), ELE_MASS);
      }
      TLorentzVector vDilep = vLep1 + vLep2;
    
      Int_t bin1=-1, bin2=-1;
      for(UInt_t i=0; i<scEta_limits.size(); i++) {
        Double_t etalow  = scEta_limits.at(i).first;
        Double_t etahigh = scEta_limits.at(i).second;
        if(fabs(sc1->Eta())>=etalow && fabs(sc1->Eta())<=etahigh) bin1=i;
        if(fabs(sc2->Eta())>=etalow && fabs(sc2->Eta())<=etahigh) bin2=i;
      }
      assert(bin1>=0);
      assert(bin2>=0);
      Int_t ibin= (bin1<=bin2) ? bin1 : bin2;
      Int_t jbin= (bin1<=bin2) ? bin2 : bin1;

      if (ifile==eData) hData_Tot->Fill(vDilep.M(),weight);
      else if (ifile==eMC) hMC_Tot->Fill(vDilep.M(),weight);
      else if (ifile==eMC2) hMC2_Tot->Fill(vDilep.M(),weight);

      UInt_t n=jbin-ibin;
      for(Int_t k=0; k<ibin; k++)
        n+=(scEta_limits.size()-k);
      
      if(ifile==eData)
	hDatav[n]->Fill(vDilep.M(),weight);
      else if(ifile==eMC)
	hMCv[n]->Fill(vDilep.M(),weight);
      else if(ifile==eMC2)
	hMC2v[n]->Fill(vDilep.M(),weight);
    }  
    delete infile;
    infile=0, intree=0;
  }

  TCanvas *c1 = MakeCanvas("c1", "", 800, 800);
  char pname[100];

  c1->Divide(1,2,0,0);
  c1->cd(1)->SetPad(0,0.3,1.0,1.0);
  c1->cd(1)->SetTopMargin(0.1);
  c1->cd(1)->SetBottomMargin(0.01); //0.01
  c1->cd(1)->SetLeftMargin(0.15);
  c1->cd(1)->SetRightMargin(0.07);
  c1->cd(1)->SetTickx(1);
  c1->cd(1)->SetTicky(1);

  c1->cd(2)->SetPad(0,0,1.0,0.3);
  c1->cd(2)->SetTopMargin(0.05);
  c1->cd(2)->SetBottomMargin(0.45);//0.25
  c1->cd(2)->SetLeftMargin(0.15);
  c1->cd(2)->SetRightMargin(0.07);
  c1->cd(2)->SetTickx(1);
  c1->cd(2)->SetTicky(0);

  TGaxis::SetMaxDigits(3);

  for (UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) {
    for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) {
      UInt_t n=jbin-ibin;
      for(UInt_t k=0; k<ibin; k++)
        n+=(scEta_limits.size()-k);

      //hMCv[n]   ->Scale(1.0/hMCv[n]->Integral());
      //hDatav[n] ->Scale(1.0/hDatav[n]->Integral());
      //hMC2v[n]->Scale(1.0/hMC2v[n]->Integral());

      c1->cd(1);

      hMCv[n]->SetLineColor(kRed);
      hMCv[n]->GetYaxis()->SetTitleOffset(1.100);
      hMCv[n]->GetYaxis()->SetTitle("Events");
      hMCv[n]->GetYaxis()->SetRangeUser(0.01, 1.3*TMath::Max(hMCv[n]->GetMaximum(),hDatav[n]->GetMaximum()));
      hMCv[n]->Draw("hist");
      hDatav[n]->Draw("EX0 same");
      hMC2v[n]->SetLineColor(kBlue);
      hMC2v[n]->Draw("histsame");

      c1->cd(2);

      TH1D* hDiffMC = returnRelDiff(hMCv[n],hDatav[n],"foo");
      TH1D* hDiffMC2 = returnRelDiff(hMC2v[n],hDatav[n],"foo2");

      hDiffMC->GetYaxis()->SetRangeUser(-1.0,1.0);
      hDiffMC->GetXaxis()->SetTitle("m_{ee} [GeV]");
      hDiffMC->GetYaxis()->SetTitle("#chi");

      hDiffMC->GetYaxis()->SetTitleOffset(0.42);
      hDiffMC->GetYaxis()->SetTitleSize(0.13);
      hDiffMC->GetXaxis()->SetTitleSize(0.13);
      hDiffMC->GetYaxis()->SetLabelSize(0.12);
      hDiffMC->GetXaxis()->SetLabelSize(0.12);
      hDiffMC->GetYaxis()->SetNdivisions(102);
      hDiffMC->GetYaxis()->CenterTitle();
      hDiffMC->GetXaxis()->SetTitleOffset(1.2);
      hDiffMC->GetXaxis()->CenterTitle();

      hDiffMC->Draw("hist");
      TLine l(80,0.0,100,0.0);
      l.Draw();
      hDiffMC->Draw("histsame");

      hDiffMC2->SetMarkerColor(kBlue);
      hDiffMC2->SetMarkerSize(1);
      hDiffMC2->SetLineColor(kBlue);
      hDiffMC2->Draw("EX0 same");

      c1->cd(1);

      TLegend *leg = new TLegend(0.65, 0.55, 0.90, 0.80);
      leg->SetShadowColor(0); leg->SetLineColor(0);
      leg->AddEntry(hMCv[n],"Raw MC","l");
      leg->AddEntry(hDatav[n],"Data","l");
      leg->AddEntry(hMC2v[n],"Corr. MC","l");
      leg->Draw();

      // CMS label
      TPaveText tb1(0.65,0.92,0.95,0.99,"NDC");
      tb1.SetFillStyle(0);
      tb1.SetBorderSize(0);
      tb1.SetTextAlign(32);
      tb1.AddText("CMS Preliminary");
      tb1.Draw();

      char buffer[200];
      // lumi label
      sprintf(buffer,"%.1f pb^{-1}  at  #sqrt{s} = 13 TeV",lumi);
      TPaveText tb2(0.55,0.82,0.90,0.90,"NDC");
      tb2.SetFillStyle(0);
      tb2.SetBorderSize(0);
      tb2.SetTextAlign(32);
      tb2.AddText(buffer);
      tb2.Draw();

      char str1[200],str2[200];
      sprintf(str1,"[%.1f, %.1f]",scEta_limits.at(ibin).first,scEta_limits.at(ibin).second);
      sprintf(str2,"[%.1f, %.1f]",scEta_limits.at(jbin).first,scEta_limits.at(jbin).second);
      TPaveText *a = new TPaveText(0.16,0.75,0.40,0.82,"NDC");
      a->SetFillColor(0); a->SetShadowColor(0); a->SetLineColor(0);
      a->AddText(str1);
      TPaveText *b = new TPaveText(0.16,0.68,0.40,0.75,"NDC");
      b->SetFillColor(0); b->SetShadowColor(0); b->SetLineColor(0);
      b->AddText(str2);

      a->Draw();
      b->Draw();

      sprintf(pname,"ele_comp_%i_%i.png",ibin,jbin); 
      c1->SaveAs(outputDir+"/"+pname);

      delete hDiffMC; delete hDiffMC2;
    }
  }

  cout << endl;
  cout << hMC_Tot->Integral() << ", " << hData_Tot->Integral() << ", " << hMC2_Tot->Integral() << endl;

  c1->cd(1);

  hMC_Tot->SetLineColor(kRed); hMC_Tot->SetMarkerColor(kRed);
  hMC_Tot->GetYaxis()->SetTitleOffset(1.100);
  hMC_Tot->GetYaxis()->SetTitle("Events");
  hMC_Tot->GetYaxis()->SetRangeUser(0.01, 1.2*hMC_Tot->GetMaximum());
  hMC_Tot->Draw("hist");
  hData_Tot->Draw("EX0 same");
  hMC2_Tot->SetLineColor(kBlue); hMC2_Tot->SetMarkerColor(kBlue);
  hMC2_Tot->Draw("hist same");

  c1->cd(2);
  
  TH1D* hDiffMC = returnRelDiff(hMC_Tot,hData_Tot,"foo");
  TH1D* hDiffMC2 = returnRelDiff(hMC2_Tot,hData_Tot,"foo2");
  
  hDiffMC->GetYaxis()->SetRangeUser(-1.0,1.0);
  hDiffMC->GetXaxis()->SetTitle("m_{ee} [GeV]");
  hDiffMC->GetYaxis()->SetTitle("#chi");

  hDiffMC->GetYaxis()->SetTitleOffset(0.42);
  hDiffMC->GetYaxis()->SetTitleSize(0.13);
  hDiffMC->GetXaxis()->SetTitleSize(0.13);
  hDiffMC->GetYaxis()->SetLabelSize(0.12);
  hDiffMC->GetXaxis()->SetLabelSize(0.12);
  hDiffMC->GetYaxis()->SetNdivisions(102);
  hDiffMC->GetYaxis()->CenterTitle();
  hDiffMC->GetXaxis()->SetTitleOffset(1.2);
  hDiffMC->GetXaxis()->CenterTitle();

  hDiffMC->SetMarkerColor(kRed);
  hDiffMC->SetMarkerSize(1);
  hDiffMC->SetLineColor(kRed);
  hDiffMC->Draw("hist");
  TLine l(80,0.0,100,0.0);
  l.Draw();
  //hDiffMC->Draw("EX0 same");

  hDiffMC2->SetMarkerColor(kBlue);
  hDiffMC2->SetMarkerSize(1);
  hDiffMC2->SetLineColor(kBlue);
  hDiffMC2->Draw("EX0 same");

  c1->cd(1);

  TLegend *leg = new TLegend(0.65, 0.55, 0.90, 0.80);
  leg->SetShadowColor(0); leg->SetLineColor(0);
  leg->AddEntry(hMC_Tot,"Raw MC","l");
  leg->AddEntry(hData_Tot,"Data","l");
  leg->AddEntry(hMC2_Tot,"Corr. MC","l");
  leg->Draw();

  // CMS label
  TPaveText tb1(0.65,0.92,0.95,0.99,"NDC");
  tb1.SetFillStyle(0);
  tb1.SetBorderSize(0);
  tb1.SetTextAlign(32);
  tb1.AddText("CMS Preliminary");
  tb1.Draw();

  char buffer[200];
  // lumi label
  sprintf(buffer,"%.1f pb^{-1}  at  #sqrt{s} = 13 TeV",lumi);
  TPaveText tb2(0.55,0.82,0.90,0.90,"NDC");
  tb2.SetFillStyle(0);
  tb2.SetBorderSize(0);
  tb2.SetTextAlign(32);
  tb2.AddText(buffer);
  tb2.Draw();

  char str1[200],str2[200];
  sprintf(str1,"[%.1f, %.1f]",scEta_limits.at(0).first,scEta_limits.at(scEta_limits.size()-1).second);
  sprintf(str2,"[%.1f, %.1f]",scEta_limits.at(0).first,scEta_limits.at(scEta_limits.size()-1).second);
  TPaveText *a = new TPaveText(0.16,0.75,0.40,0.82,"NDC");
  a->SetFillColor(0); a->SetShadowColor(0); a->SetLineColor(0);
  a->AddText(str1);
  TPaveText *b = new TPaveText(0.16,0.68,0.40,0.75,"NDC");
  b->SetFillColor(0); b->SetShadowColor(0); b->SetLineColor(0);
  b->AddText(str2);
  
  a->Draw();
  b->Draw();

  sprintf(pname,"ele_comp_tot.png");
  c1->SaveAs(outputDir+"/"+pname);


}
Beispiel #21
0
void tauStudy(const TString conf="new.conf") {

  // tau decay modes
  enum { hadron=1, electron, muon };

  const Int_t nSamples=1;
  
  vector<TString> sampleNames;
  vector<TString> sampleTitles;
  vector<Int_t> sampleColors;

  confParse(conf, sampleNames, sampleTitles, sampleColors);

  TProfile *hEffPt[nSamples];
  TProfile *hEffEta[nSamples];

  TProfile *hJetResPt[nSamples];
  TProfile *hJetResEta[nSamples];

  TH1D *hPt[nSamples];

  char hname[100];

  // define kinematic/plotting constants
  const Float_t PT_MAX  = 300;
  const Float_t PT_MIN  = 0;
  const Int_t   PT_BIN  = 150;
  const Float_t ETA_MAX = 2.5;
  const Float_t ETA_MIN = -2.5;
  const Int_t   ETA_BIN = 16;

  Double_t jetCorr1Pt, jetCorr2Pt;

  for(UInt_t iSamp=0; iSamp<nSamples; iSamp++) {

    sprintf(hname, "hEffPt_%s", sampleTitles[iSamp].Data()); hEffPt[iSamp]= new TProfile(hname, hname, PT_BIN, PT_MIN, PT_MAX);
    sprintf(hname, "hEffEta_%s", sampleTitles[iSamp].Data()); hEffEta[iSamp]= new TProfile(hname, hname, ETA_BIN, ETA_MIN, ETA_MAX);

    sprintf(hname, "hJetResPt_%s", sampleTitles[iSamp].Data()); hJetResPt[iSamp] = new TProfile(hname, hname, PT_BIN, PT_MIN, PT_MAX);
    sprintf(hname, "hJetResEta_%s", sampleTitles[iSamp].Data()); hJetResEta[iSamp] = new TProfile(hname, hname, ETA_BIN, ETA_MIN, ETA_MAX);

    sprintf(hname, "hPt_%s", sampleTitles[iSamp].Data()); hPt[iSamp] = new TH1D(hname, hname, PT_BIN, PT_MIN, PT_MAX);

  }

  UInt_t eventNum;
  UInt_t bTag1, bTag2;
  UInt_t tauCat1, tauCat2;
  LorentzVector *genB1=0, *genB2=0, *recoB1=0, *recoB2=0;
  LorentzVector *genTau1=0, *genTau2=0, *genDecayTau1=0, *genDecayTau2=0, *recoTau1=0, *recoTau2=0;

  TFile *infile;
  TTree *intree;

  for (UInt_t iSamp=0; iSamp<nSamples; iSamp++) { // sample loop

    TString infilename = sampleNames[iSamp];
    cout << "Processing  " << infilename << " ..." << endl;
    infile = new TFile(infilename); assert(infile);
    intree = (TTree*) infile->Get("Events"); assert(intree);
 
    //intree->SetBranchAddress("eventNum",       &eventNum);
    intree->SetBranchAddress("bTag1",          &bTag1);
    intree->SetBranchAddress("bTag2",          &bTag2);
    intree->SetBranchAddress("genB1",          &genB1);
    intree->SetBranchAddress("genB2",          &genB2);
    intree->SetBranchAddress("recoB1",         &recoB1);
    intree->SetBranchAddress("recoB2",         &recoB2);
    intree->SetBranchAddress("tauCat1",        &tauCat1);
    intree->SetBranchAddress("tauCat2",        &tauCat2);
    intree->SetBranchAddress("genTau1",        &genTau1);
    intree->SetBranchAddress("genTau2",        &genTau2);
    intree->SetBranchAddress("genDecayTau1",   &genDecayTau1);
    intree->SetBranchAddress("genDecayTau2",   &genDecayTau2);
    intree->SetBranchAddress("recoTau1",       &recoTau1);
    intree->SetBranchAddress("recoTau2",       &recoTau2);

    for(UInt_t iEntry=0; iEntry<intree->GetEntries(); iEntry++) { // entry loop
      intree->GetEntry(iEntry);

      // jet resolution
      //cout << tauCat1 << " " << tauCat2 << endl;
      if ((recoTau1->Pt()!=999)) {

	//jetCorr1Pt = recoTau1->Pt()*getJetScaleFactor(recoTau1->Pt(), recoTau1->Eta());
	jetCorr1Pt=recoTau1->Pt();

	hPt[iSamp]->Fill(recoTau1->Pt());

	hJetResPt[iSamp]->Fill(genDecayTau1->Pt(),(recoTau1->Pt()-genDecayTau1->Pt())/genDecayTau1->Pt());
        hJetResEta[iSamp]->Fill(genDecayTau1->Eta(),(recoTau1->Pt()-genDecayTau1->Pt())/genDecayTau1->Pt());

      }

      if ((recoTau2->Pt()!=999)) {

	//jetCorr2Pt = recoTau2->Pt()*getJetScaleFactor(recoTau2->Pt(), recoTau2->Eta());
	jetCorr2Pt=recoTau2->Pt();

	hPt[iSamp]->Fill(recoTau2->Pt());

	hJetResPt[iSamp]->Fill(genDecayTau2->Pt(),(recoTau2->Pt()-genDecayTau2->Pt())/genDecayTau2->Pt());
        hJetResEta[iSamp]->Fill(genDecayTau2->Eta(),(recoTau2->Pt()-genDecayTau2->Pt())/genDecayTau2->Pt());

      }

      //tagging efficiency
      /*
      if ((tauDecayCat1==1) && (recoTau1->Pt()!=999)) {
	hEffPt[iSamp]->Fill(genDecayTau1->Pt(),1);
	hEffEta[iSamp]->Fill(genDecayTau1->Eta(),1);
      }
      else {
	hEffPt[iSamp]->Fill(genDecayTau1->Pt(),0);
	hEffEta[iSamp]->Fill(genDecayTau1->Eta(),0);
      }

      if ((tauDecayCat2==1) && (recoTau2->Pt()!=999)) {
	hEffPt[iSamp]->Fill(genDecayTau2->Pt(),1);
	hEffEta[iSamp]->Fill(genDecayTau2->Eta(),1);
      }
      else {
	hEffPt[iSamp]->Fill(genDecayTau2->Pt(),0);
	hEffEta[iSamp]->Fill(genDecayTau2->Eta(),0);
      }
      */
    } // end entry loop
    delete infile;
    infile=0, intree=0;

  } // end sample loop

  char pname[100];
  char xlabel[100];
  char ylabel[100];
  
  TCanvas *c = MakeCanvas("c", "c", 800, 600);
  TLegend *leg = new TLegend(0.7, 0.7, 0.9, 0.9);
  leg->SetShadowColor(0);
  leg->SetFillColor(0);

  // tau jet resolution as a function of pt (uncorrected)
  sprintf(xlabel, "generator level tau jet P_{T}");
  sprintf(ylabel, "(reco P_{T} - gen P_{T})/gen P_{T}");
  sprintf(pname, "tauJetResPt");

  for (UInt_t iSamp=0; iSamp<nSamples; iSamp++) {

    hJetResPt[iSamp]->SetLineColor(sampleColors[iSamp]);
    hJetResPt[iSamp]->SetMarkerColor(sampleColors[iSamp]);
    hJetResPt[iSamp]->SetMarkerSize(1);
    leg->AddEntry(hJetResPt[iSamp], sampleTitles[iSamp],"l");

    if (iSamp==0) {
      hJetResPt[iSamp]->GetXaxis()->SetTitle(xlabel);
      hJetResPt[iSamp]->GetYaxis()->SetTitle(ylabel);
      hJetResPt[iSamp]->SetTitle("");
      //hJetResPt[iSamp]->GetYaxis()->SetRangeUser(-0.5,3);
      hJetResPt[iSamp]->Draw();

    }
    else {
      hJetResPt[iSamp]->Draw("same");
    }
  }
  //leg->Draw();
  c->SaveAs(TString(pname)+TString(".png"));

  hPt[0]->GetXaxis()->SetTitle("p_{T}");
  hPt[0]->SetTitle("");
  hPt[0]->SetLineColor(sampleColors[0]);
  hPt[0]->SetMarkerColor(sampleColors[0]);
  hPt[0]->Draw("hist");
  c->SaveAs("pt.png");

  sprintf(xlabel, "generator level tau Eta");
  sprintf(ylabel, "(reco P_{T} - gen P_{T})/gen P_{T}");
  sprintf(pname, "tauJetResEta");
  leg->Clear();

  for (UInt_t iSamp=0; iSamp<nSamples; iSamp++) {

    hJetResEta[iSamp]->SetLineColor(sampleColors[iSamp]);
    hJetResEta[iSamp]->SetMarkerColor(sampleColors[iSamp]);
    hJetResEta[iSamp]->SetMarkerSize(1);
    leg->AddEntry(hJetResEta[iSamp], sampleTitles[iSamp],"l");

    if (iSamp==0) {
      hJetResEta[iSamp]->GetXaxis()->SetTitle(xlabel);
      hJetResEta[iSamp]->GetYaxis()->SetTitle(ylabel);
      hJetResEta[iSamp]->SetTitle("");
      //hJetResEta[iSamp]->GetYaxis()->SetRangeUser(-0.3,0.3);
      hJetResEta[iSamp]->Draw();
    }

    else {
      hJetResEta[iSamp]->Draw("same");
    }
  }

  //leg->Draw();
  c->SaveAs(TString(pname)+TString(".png"));
}
void makePlots_csvSF_13TeV( TString inputFileName  = "infile.root", bool isHF = true, bool isCSV = true, TString dirPostFix = "", bool compareIterations = false ) {
  compareIterations = true;

  TString taggerName = "CSVv2";
  if(!isCSV) taggerName = "cMVAv2";

  TH1::SetDefaultSumw2();

  TFile *histFile = TFile::Open(inputFileName);

  if( compareIterations ) dirPostFix = dirPostFix + "Comparison";
  TString dirprefix = taggerName +"_SFPlots_2016_7_8_13TeV" + dirPostFix + "/";

  struct stat st;
  if( stat(dirprefix.Data(),&st) != 0 )  mkdir(dirprefix.Data(),0777);

  // single jet specific plots
  int nPt = 5;//6;
  int nEta = 1;
  TString flavor = "HF";
  if ( !isHF ){
    nPt = 4; nEta = 3;
    flavor = "LF";
  }

  //////
  TH1D* h_Data_jet_csv[nPt][nEta];
  TH1D* h_MC_b_jet_csv[nPt][nEta];
  TH1D* h_MC_nonb_jet_csv[nPt][nEta];

  /////
  // int nCSVBins = 18; //Number of bins 
  // // double xBins_hf[19] = {-0.04, 0.0, 0.122, 0.244, 0.331, 0.418, 0.505, 0.592, 0.679, 0.7228, 0.7666, 0.8104, 0.8542, 0.898, 0.9184, 0.9388, 0.9592, 0.9796, 1.01};
  // double xBins_hf[19] = {-0.04, 0.0, 0.3025, 0.605, 0.662, 0.719, 0.776, 0.833, 0.890, 0.906, 0.922, 0.938, 0.954, 0.970, 0.976, 0.982, 0.988, 0.994, 1.01};

  int nCSVBins = 22; //Number of bins 
  // double xBins_hf[19] = {-10.0, 0.0, 0.122, 0.244, 0.331, 0.418, 0.505, 0.592, 0.679, 0.7228, 0.7666, 0.8104, 0.8542, 0.898, 0.9184, 0.9388, 0.9592, 0.9796, 1.01};
  double xBins_hf[23] = {-0.04, 0.0, 0.101, 0.202, 0.303, 0.404, 0.505, 0.605, 0.662, 0.719, 0.776, 0.833, 0.890, 0.906, 0.922, 0.938, 0.954, 0.970, 0.976, 0.982, 0.988, 0.994, 1.01};
  double xBins_hf_cMVA[23] = {-1.01, -0.9525, -0.905, -0.8575, -0.81, -0.7625, -0.715, -0.565, -0.415, -0.265, -0.115, 0.035, 0.185, 0.323, 0.461, 0.599, 0.737, 0.875, 0.902, 0.929, 0.956, 0.983, 1.01};

  if(!isHF) nCSVBins = 21;
  // double xBins_lf[22] = {-0.04, 0.0, 0.04, 0.08, 0.12, 0.16, 0.2, 0.244, 0.331, 0.418, 0.505, 0.592, 0.679, 0.752, 0.825, 0.898, 0.915, 0.932, 0.949, 0.966, 0.983, 1.01};
  double xBins_lf[22] = {-0.04, 0.0, 0.101, 0.202, 0.303, 0.404, 0.505, 0.605, 0.662, 0.719, 0.776, 0.833, 0.890, 0.917, 0.944, 0.970, 0.975, 0.980, 0.985, 0.990, 0.995, 1.01};
  double xBins_lf_cMVA[22] = {-1.01, -0.9525, -0.905, -0.8575, -0.81, -0.7625, -0.715, -0.565, -0.415, -0.265, -0.115, 0.035, 0.185, 0.415, 0.645, 0.875, 0.8975, 0.92, 0.9425, 0.965, 0.9875, 1.01};

  //TCanvas* c1 = new TCanvas("c1","c1",600,500);
  TCanvas* c1 = new TCanvas("c1","c1");

  c1->SetTopMargin(0.08);
  c1->SetRightMargin(0.08);

  // gPad->SetTickx(1);
  // gPad->SetTicky(1);

  TString flavor_file = flavor;
  flavor_file.ToLower();

  ///
  TString lumiinfo = "2.6 fb^{-1} (13 TeV, 25ns)";
  TLatex LumiInfoLatex(0.65, 0.93, lumiinfo);
  LumiInfoLatex.SetNDC(); LumiInfoLatex.SetTextFont(42);
  LumiInfoLatex.SetTextSize(0.04);

  //TString cmsinfo =   "CMS Preliminary";
  TString cmsinfo =   "CMS";
  // TLatex CMSInfoLatex(0.155, 0.93, cmsinfo);
  TLatex CMSInfoLatex(0.155, 0.85, cmsinfo);
  CMSInfoLatex.SetNDC(); CMSInfoLatex.SetTextFont(42);
  CMSInfoLatex.SetTextFont(61);
  CMSInfoLatex.SetTextSize(0.055); //SBOUTLE

  std::string publishinfo =   "Preliminary"; //DPUIGH
  // TLatex PublishInfoLatex(0.25, 0.93, publishinfo.c_str()); //SBOUTLE
  TLatex PublishInfoLatex(0.155, 0.80, publishinfo.c_str()); //SBOUTLE
  PublishInfoLatex.SetNDC();
  PublishInfoLatex.SetTextFont(52);
  PublishInfoLatex.SetTextSize(0.045); //SBOUTLE
  ///

  std::vector<TString> label_ptbin;
  std::vector<TString> label_etabin;

  TString plotName;

  int iHist = -1;
  int minPt = 1;
  for ( int iPt=minPt; iPt<nPt; iPt++){
    for ( int iEta=0; iEta<nEta; iEta++){
      iHist++;
      if(isHF){
	if( iPt==0 )      label_ptbin.push_back("20 < p_{T} < 30 GeV");
	else if( iPt==1 ) label_ptbin.push_back("30 < p_{T} < 40 GeV");
	else if( iPt==2 ) label_ptbin.push_back("40 < p_{T} < 60 GeV");
	else if( iPt==3 ) label_ptbin.push_back("60 < p_{T} < 100 GeV");
	else if( iPt==4 ) label_ptbin.push_back("p_{T} > 100 GeV");
	
	label_etabin.push_back("|#eta| < 2.4");
      }
      else{
	if( iPt==0 )      label_ptbin.push_back("20 < p_{T} < 30 GeV");
	else if( iPt==1 ) label_ptbin.push_back("30 < p_{T} < 40 GeV");
	else if( iPt==2 ) label_ptbin.push_back("40 < p_{T} < 60 GeV");
	else if( iPt==3 ) label_ptbin.push_back("p_{T} > 60 GeV");
	
	if( iEta==0 ) label_etabin.push_back("|#eta| < 0.8");
	else if( iEta==1 ) label_etabin.push_back("0.8 < |#eta| < 1.6");
	else if( iEta==2 ) label_etabin.push_back("1.6 < |#eta| < 2.4");
      }

    if(!compareIterations){
      TString h_Data_Name = Form("h_csv_Data_Pt%i_Eta%i",iPt,iEta);
      TString h_b_Name = Form("h_csv_MC_bjets_Pt%i_Eta%i",iPt,iEta);
      TString h_nonb_Name = Form("h_csv_MC_nonbjets_Pt%i_Eta%i",iPt,iEta);

      
      h_Data_jet_csv[iPt][iEta] = (TH1D*)histFile->Get(h_Data_Name.Data());
      h_MC_b_jet_csv[iPt][iEta] = (TH1D*)histFile->Get(h_b_Name.Data());
      h_MC_nonb_jet_csv[iPt][iEta] = (TH1D*)histFile->Get(h_nonb_Name.Data());

      // rebin
      TH1D* h_csv_data = NULL;
      TH1D* h_csv_mc_b = NULL;
      TH1D* h_csv_mc_nonb = NULL;

      h_csv_data = (TH1D*)h_Data_jet_csv[iPt][iEta];
      h_csv_mc_b = (TH1D*)h_MC_b_jet_csv[iPt][iEta];
      h_csv_mc_nonb = (TH1D*)h_MC_nonb_jet_csv[iPt][iEta];

      // if( isHF ){
      // 	h_csv_data = (TH1D*)h_Data_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_hf );
      // 	h_csv_mc_b = (TH1D*)h_MC_b_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_hf );
      // 	h_csv_mc_nonb = (TH1D*)h_MC_nonb_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_hf );
      // }
      // else{
      // 	h_csv_data = (TH1D*)h_Data_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_lf );
      // 	h_csv_mc_b = (TH1D*)h_MC_b_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_lf );
      // 	h_csv_mc_nonb = (TH1D*)h_MC_nonb_jet_csv[iPt][iEta]->Rebin( nCSVBins, Form("csv_Data_Pt%i_Eta%i_temp",iPt,iEta), xBins_lf );
      // }

      // //// first and last bin; underflow/overflow
      // h_csv_data->SetBinContent(1,h_Data_jet_csv[iPt][iEta]->GetBinContent(1));
      // h_csv_data->SetBinError(1,h_Data_jet_csv[iPt][iEta]->GetBinError(1));

      // h_csv_mc_b->SetBinContent(1,h_MC_b_jet_csv[iPt][iEta]->GetBinContent(1));
      // h_csv_mc_b->SetBinError(1,h_MC_b_jet_csv[iPt][iEta]->GetBinError(1));

      // h_csv_mc_nonb->SetBinContent(1,h_MC_nonb_jet_csv[iPt][iEta]->GetBinContent(1));
      // h_csv_mc_nonb->SetBinError(1,h_MC_nonb_jet_csv[iPt][iEta]->GetBinError(1));

      // h_csv_data->SetBinContent(nCSVBins,h_Data_jet_csv[iPt][iEta]->GetBinContent(nCSVBins) + h_Data_jet_csv[iPt][iEta]->GetBinContent(nCSVBins+1));
      // h_csv_data->SetBinError(nCSVBins,sqrt(pow(h_Data_jet_csv[iPt][iEta]->GetBinError(nCSVBins),2) + pow(h_Data_jet_csv[iPt][iEta]->GetBinError(nCSVBins+1),2)));

      // h_csv_mc_b->SetBinContent(nCSVBins,h_MC_b_jet_csv[iPt][iEta]->GetBinContent(nCSVBins) + h_MC_b_jet_csv[iPt][iEta]->GetBinContent(nCSVBins+1));
      // h_csv_mc_b->SetBinError(nCSVBins,sqrt(pow(h_MC_b_jet_csv[iPt][iEta]->GetBinError(nCSVBins),2) + pow(h_MC_b_jet_csv[iPt][iEta]->GetBinError(nCSVBins+1),2)));

      // h_csv_mc_nonb->SetBinContent(nCSVBins,h_MC_nonb_jet_csv[iPt][iEta]->GetBinContent(nCSVBins) + h_MC_nonb_jet_csv[iPt][iEta]->GetBinContent(nCSVBins+1));
      // h_csv_mc_nonb->SetBinError(nCSVBins,sqrt(pow(h_MC_nonb_jet_csv[iPt][iEta]->GetBinError(nCSVBins),2) + pow(h_MC_nonb_jet_csv[iPt][iEta]->GetBinError(nCSVBins+1),2)));

      // //// normalize MC to data
      // double norm_mc_b = h_csv_mc_b->Integral();
      // double norm_mc_nonb = h_csv_mc_nonb->Integral();
      // h_csv_mc_b->Scale(h_csv_data->Integral() / (norm_mc_b + norm_mc_nonb));
      // h_csv_mc_nonb->Scale(h_csv_data->Integral() / (norm_mc_b + norm_mc_nonb));

      ////
      h_csv_data->SetStats(0);
      //h_csv_data->GetXaxis()->SetRangeUser(0.0001, 1.001);

      h_csv_data->SetTitle(";"+taggerName+" Discriminator;Jets / bin");
      //      h_csv_data->SetTitle(";"+taggerName);

      h_csv_data->SetMarkerStyle(20);

      h_csv_mc_b->SetFillColor(kRed);
      h_csv_mc_nonb->SetFillColor(kBlue);
      // h_csv_mc_nonb->SetFillColor(kGreen+1);

      h_csv_mc_b->SetLineColor(kRed);
      h_csv_mc_nonb->SetLineColor(kBlue);
      // h_csv_mc_nonb->SetLineColor(kGreen+1);

      h_csv_data->SetLineWidth(2);
      h_csv_mc_b->SetLineWidth(2);
      h_csv_mc_nonb->SetLineWidth(2);


      ///
    TString ptselectioninfo = label_ptbin[iHist];

    TLatex PTSELECTIONInfoLatex(0.57, 0.85, ptselectioninfo);
    PTSELECTIONInfoLatex.SetNDC();
    PTSELECTIONInfoLatex.SetTextFont(42);
    PTSELECTIONInfoLatex.SetTextSize(0.04);

    TString etaselectioninfo = label_etabin[iHist];

    TLatex ETASELECTIONInfoLatex(0.57, 0.8, etaselectioninfo);
    ETASELECTIONInfoLatex.SetNDC();
    ETASELECTIONInfoLatex.SetTextFont(42);
    ETASELECTIONInfoLatex.SetTextSize(0.04);

      ///
      // TLegend *legend = new TLegend(0.14,0.85,0.9,0.9);
      TLegend *legend = new TLegend(0.57,0.57,0.87,0.77);

      legend->SetFillColor(kWhite);
      legend->SetLineColor(kWhite);
      legend->SetShadowColor(kWhite);
      legend->SetTextFont(42);
      legend->SetTextSize(0.05);

      legend->SetNColumns(1);

      legend->AddEntry(h_csv_data," Data","pe");
      if( isHF ){
	legend->AddEntry(h_csv_mc_b," b","f");
	legend->AddEntry(h_csv_mc_nonb," udsg + c","f");
      }
      else{
	legend->AddEntry(h_csv_mc_b," b + c","f");
	legend->AddEntry(h_csv_mc_nonb," udsg","f");
      }

      TH1D* h_diff = (TH1D*) h_csv_data->Clone( Form("csv_diff_Pt%i_Eta%i",iPt,iEta) );

      THStack *hs = new THStack("hs","");
      if( isHF ){
	hs->Add(h_csv_mc_b);
	hs->Add(h_csv_mc_nonb);

	h_diff->Add(h_csv_mc_nonb,-1);
      }
      else{
	hs->Add(h_csv_mc_nonb);
	hs->Add(h_csv_mc_b);

	h_diff->Add(h_csv_mc_b,-1);
      }

      TH1D* h_ratio = (TH1D*) h_diff->Clone( Form("csv_ratio_Pt%i_Eta%i",iPt,iEta) );
      if( isHF ) h_ratio->Divide( h_csv_mc_b );
      else       h_ratio->Divide( h_csv_mc_nonb );
      

      TString title    = Form("%s SF Pt%i Eta%i",flavor.Data(),iPt,iEta);

      TLatex BinInfoLatex(0.6, 0.81, title.Data());//(0.6, 0.86, title.Data());
	
      BinInfoLatex.SetNDC();
      BinInfoLatex.SetTextFont(42);
      BinInfoLatex.SetTextSize(0.04);

      h_csv_data->GetYaxis()->SetTitleOffset(1.2);
      // h_csv_data->GetXaxis()->SetRangeUser(-0.041,0.9489);
      h_csv_data->SetMaximum(1.3*TMath::Max(h_csv_data->GetMaximum(), hs->GetMaximum()));
      h_csv_data->Draw("pe1");
      hs->Draw("histsame");
      h_csv_data->Draw("pe1same");
      
      legend->Draw();
      //      BinInfoLatex.Draw();

      LumiInfoLatex.Draw();
      CMSInfoLatex.Draw();
      PublishInfoLatex.Draw();
      ETASELECTIONInfoLatex.Draw();
      PTSELECTIONInfoLatex.Draw();

      c1->RedrawAxis();

      plotName = dirprefix + Form("%s_%s_SF_Pt%i_Eta%i_astack",taggerName.Data(),flavor.Data(),iPt,iEta) + ".pdf";

      c1->Print(plotName.Data());



      // TLegend *legend_diff = new TLegend(0.14,0.85,0.9,0.9);//new TLegend(0.14,0.93,0.9,0.98);
      TLegend *legend_diff = new TLegend(0.57,0.57,0.87,0.77);
      legend_diff->SetFillColor(kWhite);
      legend_diff->SetLineColor(kWhite);
      legend_diff->SetShadowColor(kWhite);
      legend_diff->SetTextFont(42);
      legend_diff->SetTextSize(0.05);

      legend_diff->SetNColumns(1);

      if( isHF ){
	legend_diff->AddEntry(h_diff,"(Data - c, udsg)","pe");
	legend_diff->AddEntry(h_csv_mc_b,"b","l");
	h_diff->SetMaximum(1.3*TMath::Max(h_diff->GetMaximum(), h_csv_mc_b->GetMaximum()));
      }
      else{
	legend_diff->AddEntry(h_diff,"(Data - b, c)","pe");
	legend_diff->AddEntry(h_csv_mc_nonb,"udsg","l");
	h_diff->SetMaximum(1.3*TMath::Max(h_diff->GetMaximum(), h_csv_mc_nonb->GetMaximum()));
      }

      h_diff->GetYaxis()->SetTitleOffset(1.2);
      // h_diff->GetXaxis()->SetRangeUser(-0.041,0.9489);
      h_diff->Draw("pe1");
      if( isHF ) h_csv_mc_b->Draw("pe1same");
      else       h_csv_mc_nonb->Draw("pe1same");
      h_diff->Draw("pe1same");

      legend_diff->Draw();
      //      BinInfoLatex.Draw();

      c1->RedrawAxis();

      LumiInfoLatex.Draw();
      CMSInfoLatex.Draw();
      PublishInfoLatex.Draw();
      ETASELECTIONInfoLatex.Draw();
      PTSELECTIONInfoLatex.Draw();

      plotName = dirprefix + Form("%s_%s_SF_Pt%i_Eta%i_bdiff",taggerName.Data(),flavor.Data(),iPt,iEta) + ".pdf";

      c1->Print(plotName.Data());



      h_ratio->GetYaxis()->SetRangeUser(0.,2.);
      h_ratio->SetTitle(";"+taggerName+" Discriminator;Data/MC SF");
      h_ratio->Draw("pe1");

      //      BinInfoLatex.Draw();

      c1->RedrawAxis();

      LumiInfoLatex.Draw();
      CMSInfoLatex.Draw();
      PublishInfoLatex.Draw();
      ETASELECTIONInfoLatex.Draw();
      PTSELECTIONInfoLatex.Draw();

      plotName = dirprefix + Form("%s_%s_SF_Pt%i_Eta%i_cratio",taggerName.Data(),flavor.Data(),iPt,iEta) + ".png";

      c1->Print(plotName.Data());

    }
      if( compareIterations ){
	TFile *fitFile_iter0 = TFile::Open("../data/csvSFs/csv_rwt_fit_" + flavor_file + "_v2.root");
	TFile *fitFile_iter1 = TFile::Open("../data/csv_rwt_fit_" + flavor_file + "_v2.root");
	TFile *fitFile_iter2 = TFile::Open("../data/csvSFs/csv_rwt_fit_" + flavor_file + "_v2.root");



	TString h_iter_Data_Name = Form("h_csv_Data_Pt%i_Eta%i",iPt,iEta);
	TString h_iter_b_Name = Form("h_csv_MC_bjets_Pt%i_Eta%i",iPt,iEta);
	TString h_iter_nonb_Name = Form("h_csv_MC_nonbjets_Pt%i_Eta%i",iPt,iEta);
	TString h_iter_csv_ratio_Name = Form("temp_csv_ratio_Pt%i_Eta%i",iPt,iEta);
 
	TH1D* h_iter_Data_jet_csv_iter0 = (TH1D*)fitFile_iter0->Get(h_iter_Data_Name.Data())->Clone(h_iter_Data_Name+"v0");
	TH1D* h_iter_MC_b_jet_csv_iter0 = (TH1D*)fitFile_iter0->Get(h_iter_b_Name.Data())->Clone(h_iter_b_Name+"v0");
	TH1D* h_iter_MC_nonb_jet_csv_iter0 = (TH1D*)fitFile_iter0->Get(h_iter_nonb_Name.Data())->Clone(h_iter_nonb_Name+"v0");
	
	TH1D* h_iter_Data_jet_csv_iter1 = (TH1D*)fitFile_iter1->Get(h_iter_Data_Name.Data())->Clone(h_iter_Data_Name+"v1");
	TH1D* h_iter_MC_b_jet_csv_iter1 = (TH1D*)fitFile_iter1->Get(h_iter_b_Name.Data())->Clone(h_iter_b_Name+"v1");
	TH1D* h_iter_MC_nonb_jet_csv_iter1 = (TH1D*)fitFile_iter1->Get(h_iter_nonb_Name.Data())->Clone(h_iter_nonb_Name+"v1");

	TH1D* h_iter_Data_jet_csv_iter2 = (TH1D*)fitFile_iter2->Get(h_iter_Data_Name.Data())->Clone(h_iter_Data_Name+"v2");
	TH1D* h_iter_MC_b_jet_csv_iter2 = (TH1D*)fitFile_iter2->Get(h_iter_b_Name.Data())->Clone(h_iter_b_Name+"v2");
	TH1D* h_iter_MC_nonb_jet_csv_iter2 = (TH1D*)fitFile_iter2->Get(h_iter_nonb_Name.Data())->Clone(h_iter_nonb_Name+"v2");

	TH1D* h_iter0 = (TH1D*)h_iter_Data_jet_csv_iter0->Clone(h_iter_csv_ratio_Name+"v0");
	TH1D* h_iter1 = (TH1D*)h_iter_Data_jet_csv_iter1->Clone(h_iter_csv_ratio_Name+"v1");
	TH1D* h_iter2 = (TH1D*)h_iter_Data_jet_csv_iter2->Clone(h_iter_csv_ratio_Name+"v2");
	if( isHF ){
	  h_iter0->Add(h_iter_MC_nonb_jet_csv_iter0, -1);
	  h_iter0->Divide(h_iter_MC_b_jet_csv_iter0);

	  h_iter1->Add(h_iter_MC_nonb_jet_csv_iter1, -1);
	  h_iter1->Divide(h_iter_MC_b_jet_csv_iter1);

	  h_iter2->Add(h_iter_MC_nonb_jet_csv_iter2, -1);
	  h_iter2->Divide(h_iter_MC_b_jet_csv_iter2);
	}
	else {
	  h_iter0->Add(h_iter_MC_b_jet_csv_iter0, -1);
	  h_iter0->Divide(h_iter_MC_nonb_jet_csv_iter0);

	  h_iter1->Add(h_iter_MC_b_jet_csv_iter1, -1);
	  h_iter1->Divide(h_iter_MC_nonb_jet_csv_iter1);

	  h_iter2->Add(h_iter_MC_b_jet_csv_iter2, -1);
	  h_iter2->Divide(h_iter_MC_nonb_jet_csv_iter2);
	}


	TString iter_fit_histo_name = Form("csv_ratio_Pt%d_Eta%d_final",iPt,iEta);

	//TString iter_histo_name = Form("h_csv_ratio_%d",iHist);
	TH1D* h_fit_iter0 = (TH1D*)fitFile_iter0->Get(iter_fit_histo_name)->Clone(iter_fit_histo_name+"v0");
	TH1D* h_fit_iter1 = (TH1D*)fitFile_iter1->Get(iter_fit_histo_name)->Clone(iter_fit_histo_name+"v1");
	TH1D* h_fit_iter2 = (TH1D*)fitFile_iter2->Get(iter_fit_histo_name)->Clone(iter_fit_histo_name+"v2");

	h_fit_iter0->SetLineColor(kRed);
	h_fit_iter1->SetLineColor(kGreen+1);
	h_fit_iter2->SetLineColor(kBlue);

	h_fit_iter0->SetLineWidth(2);
	h_fit_iter1->SetLineWidth(2);
	h_fit_iter2->SetLineWidth(2);

	h_iter0->SetLineColor(kRed);
	h_iter1->SetLineColor(kGreen+1);
	h_iter2->SetLineColor(kBlue);

	h_iter0->SetLineWidth(2);
	h_iter1->SetLineWidth(2);
	h_iter2->SetLineWidth(2);

	h_fit_iter0->SetStats(0);
	h_fit_iter0->GetYaxis()->SetRangeUser(0.,2.);
	h_fit_iter0->GetXaxis()->SetRangeUser(-0.04,1.01); /// change HF range
	// h_fit_iter0->GetXaxis()->SetRangeUser(0.890,1.01); /// change HF range

	h_fit_iter0->SetTitle(";"+taggerName+";Data/MC SF");

	h_fit_iter0->Draw("hist");
	h_iter0->Draw("pe1same");
	h_fit_iter1->Draw("histsame");
	h_iter1->Draw("pe1same");
	// h_fit_iter2->Draw("histsame");
	// h_iter2->Draw("pe1same");

	c1->RedrawAxis();

	///-------
      TString title    = Form("%s SF Pt%i Eta%i",flavor.Data(),iPt,iEta);

      TLatex BinInfoLatex(0.6, 0.86, title.Data());
	
      BinInfoLatex.SetNDC();
      BinInfoLatex.SetTextFont(42);
      BinInfoLatex.SetTextSize(0.04);

	///-------

	TLegend *legend_iter = new TLegend(0.14,0.93,0.9,0.98);

	legend_iter->SetFillColor(kWhite);
	legend_iter->SetLineColor(kWhite);
	legend_iter->SetShadowColor(kWhite);
	legend_iter->SetTextFont(42);
	legend_iter->SetTextSize(0.05);

	legend_iter->SetNColumns(3);

	legend_iter->AddEntry(h_iter0,"jetPt20","f");
	legend_iter->AddEntry(h_iter1,"jetPt30","f");
	// legend_iter->AddEntry(h_iter2,"mumu","f");

	// legend_iter->AddEntry(h_iter0,"Iter0","f");
	// legend_iter->AddEntry(h_iter1,"Iter1","f");
	// legend_iter->AddEntry(h_iter2,"Iter2","f");

	legend_iter->Draw();
	BinInfoLatex.Draw();

	c1->RedrawAxis();

	plotName = dirprefix + Form("%s_%s_SF_Pt%i_Eta%i_diters",taggerName.Data(),flavor.Data(),iPt,iEta) + ".png";

	c1->Print(plotName.Data());
      }
    }
  }



  std::cout << "Done." << std::endl;

}
//*************************************************************
void arrangeCanvas(TCanvas *canv,TH1F* meanplots[100],TH1F* widthplots[100],Int_t nFiles, TString LegLabels[10], bool onlyBias){
//*************************************************************

  TPaveText *ali = new TPaveText(0.18,0.87,0.50,0.93,"NDC");  
  ali->SetFillColor(10);
  ali->SetTextColor(1);
  ali->SetTextFont(42);
  ali->SetMargin(0.);
  ali->SetLineColor(10);
  ali->SetShadowColor(10);
  // pt->SetTextAlign(11);
  TText *alitext = ali->AddText("Alignment: PCL"); //"Preliminary 2015 - 0T collision data");
  alitext->SetTextSize(0.04);

  TLegend *lego = new TLegend(0.18,0.80,0.78,0.92);
  lego-> SetNColumns(2);
  //TLegend *lego = new TLegend(0.18,0.77,0.50,0.86);
  lego->SetFillColor(10);
  lego->SetTextSize(0.04);
  lego->SetTextFont(42);
  lego->SetFillColor(10);
  lego->SetLineColor(10);
  lego->SetShadowColor(10);

  TPaveText *pt  = NULL;
  TPaveText *pt2 = NULL;
  TPaveText *pt3 = NULL;

  if(!onlyBias){ 
    pt =new TPaveText(0.179,0.955,0.260,0.985,"NDC");
  } else {
    pt =new TPaveText(0.179,0.955,0.260,0.985,"NDC");
  }

  pt->SetFillColor(10);
  pt->SetTextColor(1);
  pt->SetTextFont(61);
  // pt->SetTextAlign(11);
  TText *text1 = pt->AddText("CMS"); //"Preliminary 2015 - 0T collision data");
  text1->SetTextSize(0.05);
 
  float extraOverCmsTextSize  = 0.76;

  if(!onlyBias){ 
    pt2 =new TPaveText(0.3,0.95,0.503,0.98,"NDC");
  } else {
    pt2 =new TPaveText(0.3,0.95,0.503,0.98,"NDC");
  }

  pt2->SetFillColor(10);
  pt2->SetTextColor(1);
  pt2->SetTextFont(52);
  pt2->SetTextAlign(22);
  TText *text2 = pt2->AddText("work in progress");
  text2->SetTextSize(0.05*extraOverCmsTextSize);

  if(!onlyBias){ 
    pt3 =new TPaveText(0.6,0.95,0.98,0.98,"NDC");
  } else {
    pt3 =new TPaveText(0.6,0.95,0.98,0.98,"NDC");
  }

  pt3->SetFillColor(10);
  pt3->SetTextColor(1);
  pt3->SetTextFont(42);
  // pt2->SetTextAlign(11);
  TText *text3 = pt3->AddText("3.8T collision data 2015");
  text3->SetTextSize(0.05*extraOverCmsTextSize);

  canv->SetFillColor(10);  
  if(!onlyBias) {
    canv->Divide(2,1);
    
    canv->cd(1)->SetBottomMargin(0.12);
    canv->cd(1)->SetLeftMargin(0.17);
    canv->cd(1)->SetRightMargin(0.02);
    canv->cd(1)->SetTopMargin(0.06);  
    
    canv->cd(2)->SetBottomMargin(0.12);
    canv->cd(2)->SetLeftMargin(0.17);
    canv->cd(2)->SetRightMargin(0.02);
    canv->cd(2)->SetTopMargin(0.06);  
  
    canv->cd(1);
  } else {
    
    canv->cd()->SetBottomMargin(0.14);
    canv->cd()->SetLeftMargin(0.17);
    canv->cd()->SetRightMargin(0.02);
    canv->cd()->SetTopMargin(0.06);  
    canv->cd();

  }

  Double_t absmin(999.);
  Double_t absmax(-999.);

  for(Int_t i=0; i<nFiles; i++){
    if(meanplots[i]->GetMaximum()>absmax) absmax = meanplots[i]->GetMaximum();
    if(meanplots[i]->GetMinimum()<absmin) absmin = meanplots[i]->GetMinimum();
  }

  Double_t safeDelta=(absmax-absmin)/2.;
  Double_t theExtreme=std::max(absmax,TMath::Abs(absmin));

  for(Int_t i=0; i<nFiles; i++){

    TString myTitle = meanplots[i]->GetName();
    float axmin = -999;
    float axmax = 999.;
    int ndiv = 510;
    if(myTitle.Contains("eta")){
      axmin = -2.5;
      axmax = 2.5;
      ndiv = 505;
    } else if (myTitle.Contains("phi")){
      axmin = -TMath::Pi();
      axmax = TMath::Pi();
      ndiv = 510;
    } else  {
      std::cout<<"unrecongnized variable";
    }

    meanplots[i]->GetXaxis()->SetLabelOffset(999);
    meanplots[i]->GetXaxis()->SetTickLength(0);
    
    // Redraw the new axis 
    gPad->Update();
    TGaxis *newaxis =  new TGaxis(gPad->GetUxmin(),gPad->GetUymin(),
				  gPad->GetUxmax(),gPad->GetUymin(),
				  axmin,
				  axmax,
				  //meanplots[i]->GetXaxis()->GetXmin(),
				  //meanplots[i]->GetXaxis()->GetXmax(),
				  ndiv,"SDH");
    
    
    TGaxis *newaxisup =  new TGaxis(gPad->GetUxmin(),gPad->GetUymax(),
				    gPad->GetUxmax(),gPad->GetUymax(),
				    axmin,
				    axmax,
				    //meanplots[i]->GetXaxis()->GetXmin(),                                                                                                     
				    //meanplots[i]->GetXaxis()->GetXmax(),                                                                                                     
				    ndiv,"-SDH");
    
    newaxis->SetLabelOffset(0.02);
    newaxis->SetLabelFont(42);
    newaxis->SetLabelSize(.05);
    newaxis->Draw();

    newaxisup->SetLabelOffset(-0.02);
    newaxisup->SetLabelFont(42);
    newaxisup->SetLabelSize(0);
    newaxisup->Draw();
    
    if(i==0){
      //meanplots[i]->GetYaxis()->SetRangeUser(absmin-safeDelta/2.,absmax+safeDelta);
      std::cout<<"name is: "<< meanplots[i]->GetName() << " absmin:" <<absmin<<" absmax: "<<absmax<<" safeDelta: "<<safeDelta<<std::endl;
      TString theTitle = meanplots[i]->GetName();
      if( theTitle.Contains("Norm")){
	meanplots[i]->GetYaxis()->SetRangeUser(std::min(-0.48,absmin-safeDelta),std::max(0.48,absmax+safeDelta));
      } else {
	if(!onlyBias){
	  meanplots[i]->GetYaxis()->SetRangeUser(absmin-safeDelta,absmax+safeDelta);
	} else {
	  meanplots[i]->GetYaxis()->SetRangeUser(-theExtreme-(TMath::Abs(absmin)/10.),theExtreme+(TMath::Abs(absmax/10.)));
	}
	//meanplots[i]->GetYaxis()->SetRangeUser(-theExtreme,theExtreme);
      } 
      meanplots[i]->Draw("e1");

      if(onlyBias){
	Int_t nbins =  meanplots[i]->GetNbinsX();
	Double_t lowedge  = meanplots[i]->GetBinLowEdge(1);
	Double_t highedge = meanplots[i]->GetBinLowEdge(nbins+1);
	
	TH1F* hzero = DrawZero(meanplots[i],nbins,lowedge,highedge);
	hzero->Draw("PLsame");
      }

    }
    else meanplots[i]->Draw("e1sames");
    lego->AddEntry(meanplots[i],LegLabels[i]); 
  }  
  

  //ali->Draw();
  lego->Draw();
  pt->Draw("same");
  pt2->Draw("same");
  pt3->Draw("same");


  if(!onlyBias){

    canv->cd(2);
    Double_t absmax2(-999.);
    
    for(Int_t i=0; i<nFiles; i++){
      if(widthplots[i]->GetMaximum()>absmax2) absmax2 = widthplots[i]->GetMaximum();
    }
    
    Double_t safeDelta2=absmax2/3.;
    
    for(Int_t i=0; i<nFiles; i++){

      TString myTitle = widthplots[i]->GetName();
      float axmin = -999;
      float axmax = 999.;
      int ndiv = 510;
      if(myTitle.Contains("eta")){
	axmin = -2.5;
	axmax = 2.5;
	ndiv = 505;
      } else if (myTitle.Contains("phi")){
	axmin = -TMath::Pi();
	axmax = TMath::Pi();
	ndiv = 510;
      } else  {
	std::cout<<"unrecongnized variable";
      }
      
      widthplots[i]->GetXaxis()->SetLabelOffset(999);
      widthplots[i]->GetXaxis()->SetTickLength(0);
      
      // Redraw the new axis 
      gPad->Update();
      TGaxis *newaxis2 = new TGaxis(gPad->GetUxmin(),gPad->GetUymin(),
				    gPad->GetUxmax(),gPad->GetUymin(),
				    axmin,
				    axmax,
				    //widthplots[i]->GetXaxis()->GetXmin(),
				    //widthplots[i]->GetXaxis()->GetXmax(),
				    ndiv,"SDH");
      
      newaxis2->SetLabelOffset(0.02);
      newaxis2->SetLabelFont(42);
      newaxis2->SetLabelSize(.05);
      newaxis2->Draw();

      TGaxis *newaxis2up = new TGaxis(gPad->GetUxmin(),gPad->GetUymax(),
				      gPad->GetUxmax(),gPad->GetUymax(),
				      axmin,
				      axmax,
				      //widthplots[i]->GetXaxis()->GetXmin(),
				      //widthplots[i]->GetXaxis()->GetXmax(),
				      ndiv,"-SDH");
      
      newaxis2up->SetLabelOffset(-0.02);
      newaxis2up->SetLabelFont(42);
      newaxis2up->SetLabelSize(0.);
      newaxis2up->Draw();

      if(i==0) widthplots[i]->Draw("e1");
      else widthplots[i]->Draw("e1sames");
      widthplots[i]->SetMinimum(0.5);
      widthplots[i]->SetMaximum(absmax2+safeDelta2);
    }
    
    lego->Draw();
    pt->Draw("same");
    pt2->Draw("same");
    pt3->Draw("same");

  }
}
Beispiel #24
0
// -----------------------------------------------------------------------------
//
TCanvas* createPlot( TString path, 
		     TString canvas_name, 
		     TString name, 
		     TString dirmame, 
		     int rebin, 
		     bool norm, 
		     bool log,
		     TDirectory* file )
{

  // SetSomeStyles();

  float lumi = 250.0;// 15.04;//10.9;//6.8;
 
  // Create legend
  TLegend* legend = new TLegend(0.75, 0.6, 0.99, 0.99, "", "brNDC" );
  legend->SetFillColor(0);
  legend->SetLineColor(0); 
  legend->SetShadowColor(0);
  TLatex* prelim = new TLatex(0.6,0.54,"#scale[0.8]{CMS preliminary 2010}");
  prelim->SetNDC();
  TLatex* alumi = new TLatex(0.6,.45,"#scale[0.8]{#int L dt = 35 pb^{-1}, #sqrt{s} = 7 TeV}");
  alumi->SetNDC();

  // Create canvas 
  TCanvas* aCanvas = createCanvas( canvas_name, file, log );

  // Create histogram
  TString aname("nAll");
  // TH1D* data1    = getHisto( path+"S14datacleaned/Edward_Data_Skim/",name,"data.root",aname,rebin);
  // TH1D* data    = getHisto( path+"S14datacleaned/Edward_Data_Skim/",name,"data.root",dirmame,rebin);
 
  TH1D* data    = getHisto( path+"", name, "tt.root", dirmame, rebin );
  TH1D* qcd     = getHisto( path+"", name, "lm1.root", dirmame, rebin );
  TH1D* w_jets  = getHisto( path+"", name, "w.root", dirmame, rebin );
  TH1D* tt_jets = getHisto( path+"", name, "tt.root", dirmame, rebin );
  TH1D* z_jets  = getHisto( path+"", name, "z.root", dirmame, rebin );
  TH1D* lm3     = getHisto( path+"", name, "lm3.root", dirmame, rebin );
  TH1D* lm1     = getHisto( path+"", name, "lm1.root", dirmame, rebin );
  TH1D* lm6     = getHisto( path+"", name, "data.root", dirmame, rebin );
  TH1D* wm     = getHisto( path+"", name, "w.root", dirmame, rebin );
  data->Scale(lumi/100.);
  qcd->Scale(lumi/100.);
  tt_jets->Scale(lumi/100);
  w_jets->Scale(lumi/100);
  //  w_jets->Scale(10);
  //  z_inv->Scale(lumi/100);
  //  lm6->Scale(lumi/100);
  lm1->Scale(lumi/100);
  lm3->Scale(lumi/100);
  z_jets->Scale(lumi/100);
  wm->Scale(lumi/100);
  // Combine Z+jets and Z->inv
  // TH1D* z_all = z_inv->Clone(); 
  //  z_all->Add(z_jets,1);
  //z_jets->Add(z_inv,1);
  TH1D* total = tt_jets->Clone();
  total->Add(w_jets);
  total->Add(z_jets);

  // total->
 
  Int_t binMax =   total->GetNbinsX();
  Double_t& err = new Double_t(0.);
  total->IntegralAndError(10,binMax ,err);
  Double_t& errW = new Double_t(0.);
  w_jets->IntegralAndError(10,binMax ,errW);
  Double_t& errtt = new Double_t(0.);
  tt_jets->IntegralAndError(10,binMax ,errtt);
  Double_t& errZ = new Double_t(0.);
  z_jets->IntegralAndError(10,binMax ,errZ);
  Double_t& errQCD = new Double_t(0.);
  qcd->IntegralAndError(10,binMax ,errQCD );


  cout  <<endl;
  //  cout << "MC:" <<  total->IntegralAndError(11,binMax ,err) <<" && " <<  w_jets->Integral(11,binMax)<<" && "<<tt_jets->Integral(11,binMax) << "&&  "<<z_jets->Integral(11,binMax)<<" && "<< "\/\ /\hline"<<endl;
  //  cout << total->IntegralAndError(0,binMax ,err) <<" & " << lm1->Integral(0,binMax) <<" & " << lm3->Integral(0,binMax)<<" & " << lm6->Integral(0,binMax)   <<"\\\\ \\hline"<<endl;
  //  cout <<"270: " <<  total->IntegralAndError(27,binMax ,err) <<" & " << lm1->Integral(27,binMax) <<" & " << lm3->Integral(27,binMax)<<" & " << lm6->Integral(27,binMax)   <<"\\\\ \\hline"<<endl;


  cout <<"250& " <<  total->IntegralAndError(6,binMax ,err) <<" & " << lm1->Integral(6,binMax) <<" & " << lm3->Integral(6,binMax)<<" & " << lm6->Integral(6,binMax)   <<"\\\\ \\hline"<<endl;
 
  // cout << "300: " <<  total->IntegralAndError(7,binMax ,err) <<" & " << lm1->Integral(7,binMax) <<" & " << lm3->Integral(7,binMax)<<" &" << lm6->Integral(7,binMax)   <<"\\\\ \\hline"<<endl;

  cout <<"350& " <<  total->IntegralAndError(8,binMax ,err) <<" & " << lm1->Integral(8,binMax) <<" & " << lm3->Integral(8,binMax)<<" & " << lm6->Integral(8,binMax)    <<"\\\\ \\hline"<<endl;

  //   cout << "400: " <<  total->IntegralAndError(9,binMax ,err) <<" & " << lm1->Integral(9,binMax) <<" & " << lm3->Integral(9,binMax)<<" & " << lm6->Integral(9,binMax)    <<"\\\\ \\hline"<<endl;

cout << "450& " <<  total->IntegralAndError(10,binMax ,err) <<" & " << lm1->Integral(10,binMax) <<" & " << lm3->Integral(10,binMax)<<" & " << lm6->Integral(10,binMax)    <<"\\\\ \\hline"<<endl;

//cout << "500: " <<   total->IntegralAndError(11,binMax ,err) <<" & " << lm1->Integral(11,binMax) <<" & " << lm3->Integral(11,binMax)<<" & " << lm6->Integral(11,binMax)    <<"\\\\ \\hline"<<endl;

  cout <<"550& " <<  total->IntegralAndError(12,binMax ,err) <<" & " << lm1->Integral(12,binMax) <<" & " << lm3->Integral(12,binMax)<<" & " << lm6->Integral(12,binMax)    <<"\\\\ \\hline"<<endl;
  /*
 cout << "MC:" <<  total->IntegralAndError(7,binMax ,err) <<" && " << lm1->Integral(7,binMax) <<" && " << lm3->Integral(7,binMax)<<" && " << lm6->Integral(6,binMax)   <<"/\/\ /\hline"<<endl;
  cout << "MC:" <<  total->IntegralAndError(8,binMax ,err) <<" && " << lm1->Integral(8,binMax) <<" && " << lm3->Integral(8,binMax)<<" && " << lm6->Integral(7,binMax)   <<"/\/\ /\hline"<<endl;
  cout << "MC:" <<  total->IntegralAndError(10,binMax ,err) <<" && " << lm1->Integral(10,binMax) <<" && " << lm3->Integral(10,binMax)<<" && " << lm6->Integral(10,binMax)   <<"/\/\ /\hline"<<endl;
 cout << "MC:" <<  total->IntegralAndError(11,binMax ,err) <<" && " << lm1->Integral(11,binMax) <<" && " << lm3->Integral(11,binMax)<<" && " << lm6->Integral(11,binMax)   <<"/\/\ /\hline"<<endl;
 cout << "MC:" <<  total->IntegralAndError(12,binMax ,err) <<" && " << lm1->Integral(12,binMax) <<" && " << lm3->Integral(12,binMax)<<" && " << lm6->Integral(12,binMax)   <<"/\/\ /\hline"<<endl;
  // cout << "MC:" << err  <<", W: " << errW<<", tt: "<<errtt << ", Z: "<<errZ<<", QCD: "<<  errQCD<< endl;
  */

  //  cout << "data:" << data->Integral() << endl;


  TH1D* hcen = total->Clone();
  TH1D* herr = total->Clone();
  
  herr->SetLineColor(kTeal+3);
  herr->SetMarkerColor(kAzure+6);
  herr->SetFillColor(kAzure+6);
  herr->SetLineWidth(3);
  
  total->SetLineWidth(3);
  total->SetFillColor(kAzure+2);
  total->SetLineColor(kAzure+2);
  total->SetFillStyle(3245);
 
  hcen->SetFillStyle(0);
  hcen->SetMarkerColor(kTeal+3);
  hcen->SetLineColor(kTeal+3);
  hcen->SetLineWidth(3);

  // Merge Z+jets and Z->inv
  bool combine = false;
  
  // Line colour and fill
  qcd->SetLineColor(kPink+4);
  qcd->SetLineWidth(3);
  tt_jets->SetLineColor(kBlue+1);
  tt_jets->SetLineWidth(3);
  
  w_jets->SetLineColor(kPink+7);
  w_jets->SetLineWidth(3);

  z_jets->SetLineWidth(3);
  z_jets->SetLineColor(kTeal-7);
  
  if ( combine ) {
    z_all->SetLineColor(kBlack);
    z_all->SetLineStyle(3);
    z_all->SetLineWidth(1);
  } else {
    data->SetLineColor(1);
    data->SetLineStyle(1);
    data->SetLineWidth(3);
    data->SetMarkerStyle(20);
    data->SetFillColor(0);
  }
  //  lm0->SetLineColor(kRed);
  //  lm0->SetLineWidth(3);
  // lm1->SetLineColor(kRed+3);
  // lm1->SetLineWidth(3);

  // Populate legend
  // legend->AddEntry( data, "tt fully leptonic/", "LP" );
   legend->AddEntry( herr, "full SM", "LP" );
    legend->AddEntry( z_jets, " Z+jets ", "LP" );
    legend->AddEntry( w_jets, " W+jets", "LP" );
    legend->AddEntry( tt_jets, " t#bar{t}", "LP" );
    //  legend->AddEntry( lm3, " SUSY LM3", "LP" );
    //   legend->AddEntry( lm1, " SUSY LM1", "LP" );
    legend->AddEntry( lm6, " data", "LP" );
    // legend->AddEntry(wm,"W Mad","lp");
    
  // Calc maximum number of entries
  double aMax = 0.;
  if( data->GetMaximum()     > aMax ) { aMax = data->GetMaximum()+data->GetBinError(data->GetMaximumBin()); }
  if ( qcd->GetMaximum()     > aMax ) { aMax = qcd->GetMaximum(); }
  //  if ( lm0->GetMaximum()     > aMax ) { aMax = lm0->GetMaximum(); }
  //  if ( lm1->GetMaximum()     > aMax ) { aMax = lm1->GetMaximum(); }
  if ( tt_jets->GetMaximum() > aMax ) { aMax = tt_jets->GetMaximum(); }  
  if ( w_jets->GetMaximum()  > aMax ) { aMax = w_jets->GetMaximum(); }  
  if ( combine ) {
    if ( z_all->GetMaximum()  > aMax ) { aMax = z_all->GetMaximum(); }  
  } else {
    //   if ( data->GetMaximum()   > aMax ) { aMax = z_inv->GetMaximum(); }  
    if ( z_jets->GetMaximum()  > aMax ) { aMax = z_jets->GetMaximum(); }  
  }

  // Calc minimum number of entries
  double aMin = 1.e12;
  if ( qcd->GetMinimum(1.e-12)     < aMin ) { aMin = qcd->GetMinimum(1.e-12); }
  //  if ( lm0->GetMinimum(1.e-12)     < aMin ) { aMin = lm0->GetMinimum(1.e-12); }
  //  if ( lm1->GetMinimum(1.e-12)     < aMin ) { aMin = lm1->GetMinimum(1.e-12); }
  if ( tt_jets->GetMinimum(1.e-12) < aMin ) { aMin = tt_jets->GetMinimum(1.e-12); }  
  if ( w_jets->GetMinimum(1.e-12)  < aMin ) { aMin = w_jets->GetMinimum(1.e-12); }  
  if ( combine ) {
    if ( z_all->GetMinimum(1.e-12)   < aMin ) { aMin = z_all->GetMinimum(1.e-12); }  
  } else {
    // if ( data->GetMinimum(1.e-12)   < aMin ) { aMin = z_inv->GetMinimum(1.e-12); }  
    if ( z_jets->GetMinimum(1.e-12)  < aMin ) { aMin = z_jets->GetMinimum(1.e-12); }  
  }

  if ( qcd ) qcd->GetYaxis()->SetTitleOffset(1.43);
  if ( qcd ) qcd->GetYaxis()->SetTitleSize(0.06);
  if ( qcd ) qcd->GetXaxis()->SetTitleSize(0.06);
  if ( qcd ) qcd->GetXaxis()->SetTitleOffset(0.9);

 
  if ( log ) {
    if ( qcd ) herr->SetMaximum( aMax * 10. );
    //   if ( qcd ) herr->SetMinimum( aMin * 0.1 );
    if ( qcd ) herr->SetMinimum( 0.005);
  } else {
    if ( qcd ) herr->SetMaximum( aMax * 1.1 );
    //   if ( qcd ) herr->SetMinimum( aMin * 0.9 );
  if ( qcd ) herr->SetMinimum( 0.005);

  }

  /*  TPad* mainPad = new TPad("","",0.01,0.25,0.99,0.99);
  mainPad->SetNumber(1);
  mainPad->SetFillColor(0);
  // mainPad->Range(-288.2483,-2.138147,1344.235,6.918939);
  mainPad->SetFillColor(0);
  mainPad->SetBorderMode(0);
  mainPad->SetBorderSize(2);
  if ( log == true)mainPad->SetLogy();
   mainPad->SetLeftMargin(0.1765705);
  mainPad->SetRightMargin(0.05772496);
  mainPad->SetTopMargin(0.04778761);
  mainPad->SetBottomMargin(0.1256637);
  mainPad->SetFrameFillStyle(0);
  mainPad->SetFrameLineWidth(2);
  mainPad->SetFrameBorderMode(0);
  mainPad->SetFrameFillStyle(0);
  mainPad->SetFrameLineWidth(2);
  mainPad->SetFrameBorderMode(0);
  if ( log == true)mainPad->SetLogy();
  mainPad->Draw();
  TPad*  ratioPad = new TPad("","",0.01,0.01,0.99,0.25);
  ratioPad->SetNumber(2);
  ratioPad->SetFillColor(0);
  ratioPad->SetFillColor(0);
  ratioPad->SetBorderMode(0);
  ratioPad->SetBorderSize(2);
  // if ( log == true)ratioPad->SetLogy();
   ratioPad->SetLeftMargin(0.1765705);
  ratioPad->SetRightMargin(0.05772496);
  ratioPad->SetTopMargin(0.04778761);
  ratioPad->SetBottomMargin(0.1256637);
  ratioPad->SetFrameFillStyle(0);
  ratioPad->SetFrameLineWidth(2);
  ratioPad->SetFrameBorderMode(0);
  ratioPad->SetFrameFillStyle(0);
  ratioPad->SetFrameLineWidth(2);
  ratioPad->SetFrameBorderMode(0);
  //  if ( log == true)ratioPad->SetLogy();
  ratioPad->Draw();
 

  aCanvas->cd(1);
  */

  herr->GetYaxis()->SetTitle("events");


  if ( norm ) {
    if ( qcd ) qcd->DrawNormalized("Ehist");
    // if ( lm0->GetEntries() > 0. )     { lm0->DrawNormalized("hsame"); }
    if ( lm1->GetEntries() > 0. )     { lm1->DrawNormalized("hsame"); }
    if ( tt_jets->GetEntries() > 0. ) { tt_jets->DrawNormalized("hsame"); }
    if ( w_jets->GetEntries() > 0. )  { w_jets->DrawNormalized("hsame"); }
    if ( combine ) {
      if ( z_all->GetEntries() > 0. )   { z_all->DrawNormalized("hsame"); }
    } else {
      if ( data->GetEntries() > 0. )   { z_inv->DrawNormalized("hsame"); }
      if ( z_jets->GetEntries() > 0. )  { z_jets->DrawNormalized("hsame"); }
    }
  } else {
     herr->Draw("hist");
   
   
     // qcd->SetFillStyle(3240);
     // qcd->SetFillColor(kPink+4);
    // qcd->Draw("hist");
    w_jets->Draw("hSameh");
    z_jets->Draw("9Sameh");
    w_jets->Draw("9Sameh");
    tt_jets->Draw("9SAMEh");
    //data1->Draw("9SAMEh");
     //lm0->Draw("9SAMEh");
     lm1->SetLineColor(12);
     lm1->SetLineStyle(2);
     lm1->SetLineWidth(2);
     //     lm1->Draw("9SAMEh");
     lm3->SetLineColor(14);
     lm3->SetLineStyle(2);
     lm3->SetLineWidth(2);
     //  lm3->Draw("9SAMEh");
     lm6->Draw("9SAMEh");
     wm->SetLineStyle(2);
     wm->SetLineColor(kPink+7);
     // wm->Draw("9Sameh");

     // total->DrawNormalized("9E2same");
     //      data->Draw("SAMEh");
    //  tt_jets->Divide(data);
    //  tt_jets->Draw("h");
  //  data->SetLineColor(kRed);
  //  data->Draw("sameh");
     //     data1->SetLineColor(kRed);
     //  data1->Draw("9SAMEP");
  }
  
    legend->Draw();
  // prelim->Draw();
  // alumi->Draw();



  /*  TH1D* ratioBottom = total->Clone();
  TH1D* ratioTop = data->Clone();
  ratioTop->GetYaxis()->SetTitle("data / sim");
  ratioTop->Divide(ratioBottom);
  
  aCanvas->cd(1)->Update();
 
  aCanvas->cd(2);

  ratioTop->SetTitleSize(0.1, "XYZ");
  ratioTop->SetTitleOffset(0.55, "X");
  ratioTop->SetTitleOffset(0.3, "Y");
  ratioTop->SetLabelSize(0.06,"XY");
    
  // ratioTop->GetXaxis().SetRangeUser(MinX,MaxX);
  ratioTop->GetYaxis()->SetRangeUser(0.,2.0);
  ratioTop->Draw();*/
  /* TBox* unity = TBox(ratioTop->GetXaxis()->GetBinLowEdge(ratioTop->GetXaxis()->GetFirst()), 0.89,ratioTop->GetXaxis()->GetBinLowEdge(ratioTop->GetXaxis()->GetLast()), 1.11);
  unity->SetLineWidth(2);
   
  unity->SetLineColor(2);
  unity->SetFillColor(2);
  unity->SetFillStyle(3002);
  unity->Draw();

  */
  file->cd();
 
  aCanvas->SaveAs( std::string(canvas_name+".pdf").c_str() );
  aCanvas->Write();



  //   aCanvas->Print(".png");
 return aCanvas;

}
Beispiel #25
0
int BtagEfficiencies()
{
  // Define sample
  TFile* TTJets    = new TFile("TTJetsFall11.root" , "READ");
  TFile* WJetsHT   = new TFile("WJetsHT.root"      , "READ");
  TFile* SingleTop = new TFile("SingleTop.root"    , "READ");

  // addSample(TFile* sample, TString name)
  addSample(TTJets,    "t#bar{t}+Jets", kRed,     21, 0.9, 7);
  addSample(SingleTop, "single top",    kBlue,    20, 1.0, 7);
  addSample(WJetsHT,   "W+Jets",        kGreen+2, 23, 1.1, 7);
  //addSample(SingleTop, "single top",    kBlue,  24, 1,   7);
  //addSample(WJetsHT,   "W+Jets",        kGreen, 25, 1,   7);


  // addAlgorithm(TString name)
  addAlgorithm("TCHEM");

  // addSelectionStep(TString name, int lc, TString sn);
  addSelectionStep("", 8, "RA4b");

  // Flavors
  Flavors.push_back("B");
  Flavors.push_back("C");
  Flavors.push_back("L");

  // global settings
//   gStyle->SetCanvasColor(10);
//   gStyle->SetOptStat(0);
//   gStyle->SetPalette(1);
//   gStyle->SetTitleFillColor(0);

  setTDRStyle();

  // loop over algorithms
  for(int a=0; a<Algos.size(); ++a)
    {
      std::cout << Algos[a] << std::endl;
      
      // loop over flavor	  
      for(int flv=0; flv<(int)Flavors.size(); ++flv)
	{
	  // loop over selection steps
	  for(int s=0; s < Steps.size(); ++s)
	    {
	      std::cout << "Selection step " << Steps[s] <<  std::endl;
	       
	      // Define canvas and legend/afs/desy.de/user/n/npietsch
	      TCanvas *canvas =new TCanvas(SelectionNames[s]+"_"+Algos[a]+"_"+Flavors[flv]+"_Pt",SelectionNames[s]+"_"+Algos[a]+"_"+Flavors[flv]+"_Pt",1);

	      TLegend *leg = new TLegend(.64,.18,.91,.35);
	      leg->SetTextFont(42);
	      leg->SetFillColor(0);
	      leg->SetLineColor(1);
	      
	      TPaveText *label = new TPaveText(0.14,0.91,0.6,0.99,"NDC");
	      label->SetFillColor(0);
	      label->SetTextFont(42);
	      label->SetBorderSize(0);
	      TText *text=label->AddText("CMS Simulation, #sqrt{s}=7 TeV");
	      text->SetTextAlign(22);
	      
	      TPaveText *label2 = new TPaveText(0.33,0.23,0.53,0.33,"NDC");
	      label2->SetFillColor(0);
	      label2->SetTextFont(62);
	      label2->SetBorderSize(0);
	      TText *text2=label2->AddText("0 < |#eta| < 0.8");
	      text2->SetTextAlign(22);

	      // declare maximum and ybin
	      double Maximum=0;
	      double ybin=1;

	      // loop over files
	      for(int f=0; f<(int)Files.size(); ++f)
		{
		  TH2F* Pt_=(TH2F*)Files[f]->Get("bTagEffRA4bMu"+Algos[a]+Steps[s]+"/Num"+Flavors[flv]+"JetsPtEta");
		  TH2F* Pt2_=(TH2F*)Files[f]->Get("bTagEffRA4bEl"+Algos[a]+Steps[s]+"/Num"+Flavors[flv]+"JetsPtEta");
		  Pt_->Add(Pt2_);

		  TH2F* TaggedPt_=(TH2F*)Files[f]->Get("bTagEffRA4bMu"+Algos[a]+Steps[s]+"/Num"+Flavors[flv]+"JetsTaggedPtEta");
		  TH2F* TaggedPt2_=(TH2F*)Files[f]->Get("bTagEffRA4bEl"+Algos[a]+Steps[s]+"/Num"+Flavors[flv]+"JetsTaggedPtEta");
		  TaggedPt_->Add(TaggedPt2_);

		  TaggedPt_->Divide(Pt_);
		  
		  //--------------------------------------
		  // Draw x and y errors
		  //--------------------------------------
		  
		  // define shifts
		  double shift_=4*(f-1);
		  double shift2_=5*(f-1);
		  double shift3_=6*(f-1);
		  
		  // define array xbinsPt
		  Int_t nBins=TaggedPt_->GetNbinsX();
		  double xbinsPt[18];
		  double xbinsPtX[18];

		  // fill array xbinsPt
		  double xbin0=TaggedPt_->GetBinLowEdge(1);
		  xbinsPt[0]=xbin0;
		  xbinsPtX[0]=xbin0;
		  std::cout << xbin0 << std::endl;

		  //
		  double ibinX=0;
		  for(int xbin=1; xbin<TaggedPt_->GetNbinsX(); ++xbin)
		    {
		      ibinX=ibinX+TaggedPt_->GetXaxis()->GetBinWidth(xbin);
		      if(TaggedPt_->GetXaxis()->GetBinWidth(xbin)>20) shift_=shift3_;

		      xbinsPtX[xbin]=ibinX;
		      xbinsPt[xbin]=ibinX+shift_;
		    }
		  xbinsPt[TaggedPt_->GetNbinsX()]=TaggedPt_->GetBinLowEdge(TaggedPt_->GetNbinsX()+1)+shift_;
		  xbinsPtX[TaggedPt_->GetNbinsX()]=TaggedPt_->GetBinLowEdge(TaggedPt_->GetNbinsX()+1);

		  // define new histograms
		  char Tmp [70];
		  char Tmp2 [70];
		  sprintf(Tmp,"%i_%i_%i_%i_Pt", f, a, flv, s);
		  sprintf(Tmp2,"%i_%i_%i_%i_Pt2", f, a, flv, s);
		  TH1F* Tmp_=new TH1F(Tmp, Tmp, nBins, xbinsPt);
		  TH1F* Tmp2_=new TH1F(Tmp2, Tmp2, nBins, xbinsPtX);

		  // fill histogram Tmp_
		  for(int xbin=0; xbin<Tmp_->GetNbinsX()+1; ++xbin)
		    {
		      Tmp_->SetBinContent(xbin,TaggedPt_->GetBinContent(xbin, ybin));
		      Tmp_->SetBinError(xbin,TaggedPt_->GetBinError(xbin, ybin));
		      
		      Tmp2_->SetBinContent(xbin,TaggedPt_->GetBinContent(xbin, ybin));
		      Tmp2_->SetBinError(xbin,0.0000001);

		      if(TaggedPt_->GetBinContent(xbin, ybin)+TaggedPt_->GetBinError(xbin, ybin) > Maximum)
			{
			  Maximum=TaggedPt_->GetBinContent(xbin, ybin)+TaggedPt_->GetBinError(xbin, ybin);
			}
		    }

		  //--------------------------------------
		  // Draw histogram
		  //--------------------------------------

		  // draw histogram Tmp2_
		  if(Flavors[flv]=="B") Tmp2_->SetMaximum(1.05*0.947686);
		  if(Flavors[flv]=="C") Tmp2_->SetMaximum(1.05*0.388437);
		  if(Flavors[flv]=="L") Tmp2_->SetMaximum(1.05*0.0880499);
		  Tmp2_->SetMinimum(0);
		  Tmp2_->SetTitle("");
		  if(Flavors[flv]=="B") Tmp2_->GetXaxis()->SetTitle("b-jet p_{T} [GeV]");
		  if(Flavors[flv]=="C") Tmp2_->GetXaxis()->SetTitle("c-jet p_{T} [GeV]");
		  if(Flavors[flv]=="L") Tmp2_->GetXaxis()->SetTitle("light quark jet p_{T} [GeV]");
		  Tmp2_->GetXaxis()->SetTitleOffset(1.35);
		  //Tmp2_->GetXaxis()->CenterTitle();
		  Tmp2_->GetYaxis()->SetTitle("b-tag efficiency");
		  Tmp2_->GetYaxis()->SetTitleOffset(1.35);
		  //Tmp2_->GetYaxis()->CenterTitle();
		  Tmp2_->SetLineColor(SampleColors[f]);
		  Tmp2_->SetLineWidth(2);
		  if(f==0) Tmp2_->Draw("");
		  else Tmp2_->Draw("same");

// 		  TF1 *myfit1 = new TF1("myfit1","[0]+[1]*x", 40, 160);
// 		  myfit1->SetLineWidth(2);
// 		  myfit1->SetLineColor(SampleColors[f]);

// 		  Tmp2_->Fit("myfit1","0EMR"); // "0" = do NOT automatically draw "hist"
// 		  Tmp2_->GetFunction("myfit1")->ResetBit(1<<9); // make "fitname" visible

// 		  TF1 *myfit2 = new TF1("myfit2","[0]+[1]*x", 160, 670);
// 		  myfit2->SetLineWidth(2);
// 		  myfit2->SetLineColor(SampleColors[f]);

// 		  Tmp2_->Fit("myfit2","0EMR+"); // "0" = do NOT automatically draw "hist"
// 		  Tmp2_->GetFunction("myfit2")->ResetBit(1<<9); // make "fitname" visible
		  
		  // fit functions
// 		  Double_t par[6];

// 		  if(Flavors[flv] == "B")
// 		    {
// 		      TF1 *g1 = new TF1("g1","[1]+[2]*x+[3]*x**2",40,160);
// 		      g1->SetLineColor(SampleColors[f]);
// 		      Tmp2_->Fit(g1,"0EMR");
// 		      Tmp2_->GetFunction("g1")->ResetBit(1<<9);
		      
// 		      TF1 *g2 = new TF1("g2","[4]+[5]*x",160,670);
// 		      g2->SetLineColor(SampleColors[f]);
// 		      Tmp2_->Fit(g2,"0EMR+");
// 		      Tmp2_->GetFunction("g2")->ResetBit(1<<9);
// 		    }


// 		  if(Flavors[flv] == "C" || Flavors[flv] == "L")
// 		    {
// 		      TF1 *g1 = new TF1("g1","[1]+[2]*x+[3]*x**2",40,670);
// 		      g1->SetLineColor(SampleColors[f]);
// 		      g1->SetLineWidth(2);
// 		      Tmp2_->Fit(g1,"0EMR");
// 		      Tmp2_->GetFunction("g1")->ResetBit(1<<9);
// 		    }

// 		  TF1 *total = new TF1("total","[0]+[1]*x+[2]*x**2+[3]+[4]*x",40,670);
// 		  total->SetLineColor(SampleColors[f]);

// 		  g1->GetParameters(&par[0]);
// 		  g2->GetParameters(&par[3]);

// 		  total->SetParameters(par);
		  
// 		  Tmp2_->Fit("total","0EMR+"); // "0" = do NOT automatically draw "hist"
// 		  Tmp2_->GetFunction("total")->ResetBit(1<<9); // make "fitname" visible

		  // draw histogram Tmp_
		  Tmp_->SetLineColor(SampleColors[f]);
		  Tmp_->SetLineWidth(2);

		  Tmp_->SetMarkerStyle(MarkerStyles[f]);
		  Tmp_->SetMarkerColor(SampleColors[f]);
		  Tmp_->SetMarkerSize(MarkerSizes[f]);

		  Tmp_->Draw("same E x0");

		  leg->AddEntry(Tmp_,Names[f],"l P");
		  
		}
	      std::cout << "==============================" << std::endl;
	      std::cout << "Maximum: " << Maximum << std::endl;
	      std::cout << "==============================" << std::endl;

	      leg->SetShadowColor(0);
	      leg->Draw();
	      label->Draw();
	      label2->Draw();

	      canvas->SaveAs(Algos[a]+Steps[s]+"_"+Flavors[flv]+"jetsEff_MuPt_08.pdf");
	      
	    }
	}
    }
  std::cout << "" << std::endl;
  
  return 0;
}
Beispiel #26
0
int main(int argc, char** argv)
{

  std::string plot_type = argv[1];
    //"HVScan";
  //    std::string plot_type = "AngScanHigh";
  //  std::string plot_type = "scanX0_HVLow_50";
  //  std::string plot_type = "scanX0_HVLow_20";
  std::cout<<plot_type<<std::endl;

  TFile* inF_GaAsEm;
  //TFile* inF_GaAsEm_OFF;
  TFile* inF_MultiAlkEm;
  //TFile* inF_MultiAlkEm_OFF;
  TFile* inF_Double9090;
  TFile* inF_Double9040;
  TFile* inF_Double9090b;
  TFile* inF_Double9040b;

  TMultiGraph *mg = new TMultiGraph();

  TLegend *legC;

  if(plot_type == "HV12"){
    legC = new TLegend(0.12,0.62,0.30,0.87,NULL,"brNDC");

	//plot name MCPName_ScanType_HVScanScanType_MCPName
    inF_MultiAlkEm = TFile::Open("plots/efficiency_studies/MultiAlkEm_HV12_HVScan12_MultiAlkEm.root");
    inF_GaAsEm = TFile::Open("plots/efficiency_studies/GaAsEm_HV12_HVScan12_GaAsEm.root");
    //inF_GaAsEm_OFF = TFile::Open("plots/efficiency_studies/GaAsEm_HV_HVScan7.root");
    inF_Double9090 = TFile::Open("plots/efficiency_studies/Double9090_HV12_HVScan12_Double9090.root");
    inF_Double9040 = TFile::Open("plots/efficiency_studies/Double9040_HV12_HVScan12_Double9040.root");    
    TGraphErrors* eff_GaAsEm = (TGraphErrors*)inF_GaAsEm->Get("eff");
    TGraphErrors* eff_MultiAlkEm = (TGraphErrors*)inF_MultiAlkEm->Get("eff");
    TGraphErrors* eff_Double9040 = (TGraphErrors*)inF_Double9040->Get("eff");
    TGraphErrors* eff_Double9090 = (TGraphErrors*)inF_Double9090->Get("eff");

    //settings
    eff_GaAsEm->SetMarkerColor(kGreen+1);
    eff_GaAsEm->SetLineColor(kGreen+1);
    //eff_GaAsEm_OFF->SetMarkerColor(kGreen+1);
    //eff_GaAsEm_OFF->SetLineColor(kGreen+1);
    eff_Double9040->SetMarkerColor(kBlue);
    eff_Double9040->SetLineColor(kBlue);
    eff_Double9090->SetMarkerColor(kRed);
    eff_Double9090->SetLineColor(kRed);
    eff_MultiAlkEm->SetMarkerColor(1);
    eff_MultiAlkEm->SetLineColor(1);
  //
    eff_GaAsEm->SetMarkerStyle(20);
    eff_GaAsEm->SetLineWidth(2);
    eff_GaAsEm->SetMarkerSize(0.9);
//    eff_GaAsEm_OFF->SetMarkerStyle(22);
//    eff_GaAsEm_OFF->SetLineWidth(2);
    eff_Double9040->SetMarkerStyle(20);
    eff_Double9040->SetLineWidth(2);
    eff_Double9040->SetMarkerSize(0.9);
    eff_Double9090->SetMarkerStyle(20);
    eff_Double9090->SetLineWidth(2);
    eff_Double9090->SetMarkerSize(0.9);
    eff_MultiAlkEm->SetMarkerStyle(22);
    eff_MultiAlkEm->SetLineWidth(2);

    legC->SetTextFont(42);
    legC->SetTextSize(0.034);
    legC->SetFillColor(kWhite);
    legC->SetLineColor(kWhite);
    legC->SetShadowColor(kWhite);
    legC->AddEntry(eff_MultiAlkEm, "MultiAlk. emitt. ON: #DeltaV_{12} = 300 V", "p");
    legC->AddEntry(eff_GaAsEm, "GaAs emitt. ON: #DeltaV_{12} = 300 V", "p");
//    legC->AddEntry(eff_GaAsEm_OFF, "GaAs emitt. - iMCP mode", "p");
    legC->AddEntry(eff_Double9040, "Double9040 HV_{1} = HV_{2}", "p");
    legC->AddEntry(eff_Double9090, "Double9090 HV_{1} = HV_{2}", "p");
  
    mg->Add(eff_GaAsEm);
//    mg->Add(eff_GaAsEm_OFF);
    mg->Add(eff_Double9090);
    mg->Add(eff_Double9040);
    mg->Add(eff_MultiAlkEm);

    //    TCanvas* c = new TCanvas("cEff","cEff",400,800);
    TCanvas* c = new TCanvas();
    gPad->SetTicks();
    char plot_name[100];
    std::string command = "if [ ! -e final_plots/ ] ; then mkdir final_plots ; fi";
    system(command.c_str());
    sprintf(plot_name, "final_plots/efficiency_%s.pdf", plot_type.c_str());

    mg->Draw("APL");
    mg->SetTitle("Electron Beam 450 MeV");
    mg->GetXaxis()->SetRangeUser(1200,4000);
    mg->GetXaxis()->SetTitle("HV_{1} (V)");
    mg->GetXaxis()->SetTitleSize(0.05);
    mg->GetYaxis()->SetTitle("Efficiency");
    mg->GetYaxis()->SetTitleSize(0.05);
    mg->SetMaximum(1);
    mg->SetMinimum(0);
    mg->Draw("APL");  
    legC->Draw("same");
    banner4Plot();
    c->Update();

    c->Print(plot_name, "pdf");
    sprintf(plot_name, "final_plots/efficiency_%s.png", plot_type.c_str());
    c->Print(plot_name, "png");

    sprintf(plot_name, "final_plots/efficiency_%s.root", plot_type.c_str());
    c->SaveAs(plot_name, "root");
    sprintf(plot_name, "final_plots/efficiency_%s.C", plot_type.c_str());
    c->SaveAs(plot_name, "C");
  }

/////----------------------------------------------------------------------------//////////////

if(plot_type == "HV1"){
    legC = new TLegend(0.52,0.58,0.80,0.83,NULL,"brNDC");

	//plot name MCPName_ScanType_HVScanScanType_MCPName
    inF_GaAsEm = TFile::Open("plots/efficiency_studies/GaAsEm_HV1_HVScan1_GaAsEm.root");
    //inF_GaAsEm_OFF = TFile::Open("plots/efficiency_studies/GaAsEm_HV_HVScan7.root");
    inF_MultiAlkEm = TFile::Open("plots/efficiency_studies/MultiAlkEm_HV1_HVScan1_MultiAlkEm.root");
    inF_Double9090 = TFile::Open("plots/efficiency_studies/Double9090_HV1_HVScan1_Double9090.root");
    inF_Double9040 = TFile::Open("plots/efficiency_studies/Double9040_HV1_HVScan1_Double9040.root");    
    TGraphErrors* eff_GaAsEm = (TGraphErrors*)inF_GaAsEm->Get("eff");
    TGraphErrors* eff_Double9090 = (TGraphErrors*)inF_Double9090->Get("eff");
    TGraphErrors* eff_MultiAlkEm = (TGraphErrors*)inF_MultiAlkEm->Get("eff");
    TGraphErrors* eff_Double9040 = (TGraphErrors*)inF_Double9040->Get("eff");

    //settings
    eff_GaAsEm->SetMarkerColor(kGreen+1);
    eff_GaAsEm->SetLineColor(kGreen+1);
    //eff_GaAsEm_OFF->SetMarkerColor(kGreen+1);
    //eff_GaAsEm_OFF->SetLineColor(kGreen+1);
    eff_Double9040->SetMarkerColor(kBlue);
    eff_Double9040->SetLineColor(kBlue);
    eff_Double9090->SetMarkerColor(kRed);
    eff_Double9090->SetLineColor(kRed);
    eff_MultiAlkEm->SetMarkerColor(1);
    eff_MultiAlkEm->SetLineColor(1);
  //
    eff_GaAsEm->SetMarkerStyle(20);
    eff_GaAsEm->SetLineWidth(2);
    eff_GaAsEm->SetMarkerSize(0.9);
//    eff_GaAsEm_OFF->SetMarkerStyle(22);
//    eff_GaAsEm_OFF->SetLineWidth(2);
    eff_Double9040->SetMarkerStyle(20);
    eff_Double9040->SetLineWidth(2);
    eff_Double9040->SetMarkerSize(0.9);
    eff_Double9090->SetMarkerStyle(20);
    eff_Double9090->SetLineWidth(2);
    eff_Double9090->SetMarkerSize(0.9);
    eff_MultiAlkEm->SetMarkerStyle(22);
    eff_MultiAlkEm->SetLineWidth(2);

    legC->SetTextFont(42);
    legC->SetTextSize(0.034);
    legC->SetFillColor(kWhite);
    legC->SetLineColor(kWhite);
    legC->SetShadowColor(kWhite);
    legC->AddEntry(eff_MultiAlkEm, "MultiAlk emitt. HV_{2} = 3100 (V)", "p");
    legC->AddEntry(eff_GaAsEm, "GaAs emitt. HV_{2} = 3100 (V)", "p");
//    legC->AddEntry(eff_GaAsEm_OFF, "GaAs emitt. - iMCP mode", "p");
//    legC->AddEntry(eff_Double9040, "Double9040 HV_{2} = 2700 (V)", "p");
//    legC->AddEntry(eff_Double9090, "Double9090 HV_{2} = 2700 (V)", "p");
  
    mg->Add(eff_GaAsEm);
//    mg->Add(eff_GaAsEm_OFF);
    //  mg->Add(eff_Double9090);
    //    mg->Add(eff_Double9040);
    mg->Add(eff_MultiAlkEm);

    //    TCanvas* c = new TCanvas("cEff","cEff",400,800);
    TCanvas* c = new TCanvas();
    gPad->SetTicks();
    char plot_name[100];
    std::string command = "if [ ! -e final_plots/ ] ; then mkdir final_plots ; fi";
    system(command.c_str());
    sprintf(plot_name, "final_plots/efficiency_%s.pdf", plot_type.c_str());

    mg->Draw("APL");
    mg->SetTitle("Electron Beam 450 MeV");
    mg->GetXaxis()->SetRangeUser(1200,4000);
    mg->GetXaxis()->SetTitle("HV_{1} (V)");
    mg->GetXaxis()->SetTitleSize(0.05);
    mg->GetYaxis()->SetTitle("Efficiency");
    mg->GetYaxis()->SetTitleSize(0.05);
    mg->SetMaximum(1);
    mg->SetMinimum(0);
    mg->Draw("APL");  
    legC->Draw("same");
    banner4Plot();
    c->Update();

    c->Print(plot_name, "pdf");
    sprintf(plot_name, "final_plots/efficiency_%s.png", plot_type.c_str());
    c->Print(plot_name, "png");

    sprintf(plot_name, "final_plots/efficiency_%s.root", plot_type.c_str());
    c->SaveAs(plot_name, "root");
    sprintf(plot_name, "final_plots/efficiency_%s.C", plot_type.c_str());
    c->SaveAs(plot_name, "C");
  }

/////----------------------------------------------------------------------------//////////////

if(plot_type == "HV2"){
    legC = new TLegend(0.12,0.62,0.40,0.87,NULL,"brNDC");

	//plot name MCPName_ScanType_HVScanScanType_MCPName
    //    inF_GaAsEm = TFile::Open("plots/efficiency_studies/GaAsEm_HV1_HVScan1_GaAsEm.root");
    //inF_GaAsEm_OFF = TFile::Open("plots/efficiency_studies/GaAsEm_HV_HVScan7.root");
    //inF_MultiAlkEm = TFile::Open("plots/efficiency_studies/MultiAlkEm_HV1_HVScan1_MultiAlkEm.root");
    inF_Double9090 = TFile::Open("plots/efficiency_studies/Double9090_HV2_HVScan2_Double9090.root");
    inF_Double9040 = TFile::Open("plots/efficiency_studies/Double9040_HV2_HVScan2_Double9040.root");    
    inF_Double9090b = TFile::Open("plots/efficiency_studies/Double9090_HV1_HVScan1_Double9090.root");
    inF_Double9040b = TFile::Open("plots/efficiency_studies/Double9040_HV1_HVScan1_Double9040.root");    
    //TGraphErrors* eff_GaAsEm = (TGraphErrors*)inF_GaAsEm->Get("eff");
    TGraphErrors* eff_Double9090 = (TGraphErrors*)inF_Double9090->Get("eff");
    TGraphErrors* eff_Double9040 = (TGraphErrors*)inF_Double9040->Get("eff");
    TGraphErrors* eff_Double9090b = (TGraphErrors*)inF_Double9090b->Get("eff");
    TGraphErrors* eff_Double9040b = (TGraphErrors*)inF_Double9040b->Get("eff");

    //settings
    eff_Double9040->SetMarkerColor(kBlue);
    eff_Double9040->SetLineColor(kBlue);
    eff_Double9090->SetMarkerColor(kRed);
    eff_Double9090->SetLineColor(kRed);
  //
    eff_Double9040->SetMarkerStyle(20);
    eff_Double9040->SetLineWidth(2);
    eff_Double9040->SetMarkerSize(0.9);
    eff_Double9090->SetMarkerStyle(20);
    eff_Double9090->SetLineWidth(2);
    eff_Double9090->SetMarkerSize(0.9);


    eff_Double9040b->SetMarkerColor(kBlue);
    eff_Double9040b->SetLineColor(kBlue);
    eff_Double9090b->SetMarkerColor(kRed);
    eff_Double9090b->SetLineColor(kRed);
  //
    eff_Double9040b->SetMarkerStyle(22);
    eff_Double9040b->SetLineWidth(2);
    eff_Double9040b->SetMarkerSize(0.9);
    eff_Double9090b->SetMarkerStyle(22);
    eff_Double9090b->SetLineWidth(2);
    eff_Double9090b->SetMarkerSize(0.9);

    legC->SetTextFont(42);
    legC->SetTextSize(0.034);
    legC->SetFillColor(kWhite);
    legC->SetLineColor(kWhite);
    legC->SetShadowColor(kWhite);
    legC->AddEntry(eff_Double9040, "Double9040 HV_{1} = 2700 (V), scan on HV_{2}", "p");
    legC->AddEntry(eff_Double9090, "Double9090 HV_{1} = 2700 (V), scan on HV_{2}", "p");

    legC->AddEntry(eff_Double9040b, "Double9040 HV_{2} = 2700 (V), scan on HV_{1}", "p");
    legC->AddEntry(eff_Double9090b, "Double9090 HV_{2} = 2700 (V), scan on HV_{1}", "p");
  
    mg->Add(eff_Double9090);
    mg->Add(eff_Double9040);
    mg->Add(eff_Double9090b);
    mg->Add(eff_Double9040b);

    //    TCanvas* c = new TCanvas("cEff","cEff",400,800);
    TCanvas* c = new TCanvas();
    gPad->SetTicks();
    char plot_name[100];
    std::string command = "if [ ! -e final_plots/ ] ; then mkdir final_plots ; fi";
    system(command.c_str());
    sprintf(plot_name, "final_plots/efficiency_%s.pdf", plot_type.c_str());

    mg->Draw("APL");
    mg->SetTitle("Electron Beam 450 MeV");
    mg->GetXaxis()->SetRangeUser(1200,4000);
    mg->GetXaxis()->SetTitle("HV_{1} or HV_{2} (V)");
    mg->GetXaxis()->SetTitleSize(0.05);
    mg->GetYaxis()->SetTitle("Efficiency");
    mg->GetYaxis()->SetTitleSize(0.05);
    mg->SetMaximum(1);
    mg->SetMinimum(0);
    mg->Draw("APL");  
    legC->Draw("same");
    banner4Plot();
    c->Update();

    c->Print(plot_name, "pdf");
    sprintf(plot_name, "final_plots/efficiency_%s.png", plot_type.c_str());
    c->Print(plot_name, "png");

    sprintf(plot_name, "final_plots/efficiency_%s.root", plot_type.c_str());
    c->SaveAs(plot_name, "root");
    sprintf(plot_name, "final_plots/efficiency_%s.C", plot_type.c_str());
    c->SaveAs(plot_name, "C");
  }

/////----------------------------------------------------------------------------//////////////

if(plot_type == "Extreme"){
    legC = new TLegend(0.12,0.72,0.30,0.87,NULL,"brNDC");

	//plot name MCPName_ScanType_HVScanScanType_MCPName
    //    inF_GaAsEm = TFile::Open("plots/efficiency_studies/GaAsEm_HV1_HVScan1_GaAsEm.root");
    //inF_GaAsEm_OFF = TFile::Open("plots/efficiency_studies/GaAsEm_HV_HVScan7.root");
    //inF_MultiAlkEm = TFile::Open("plots/efficiency_studies/MultiAlkEm_HV1_HVScan1_MultiAlkEm.root");
    inF_Double9090 = TFile::Open("plots/efficiency_studies/Double9090_HV1_HVScanExt_Double9090.root");
    inF_Double9040 = TFile::Open("plots/efficiency_studies/Double9040_HV1_HVScanExt_Double9040.root");    
    //TGraphErrors* eff_GaAsEm = (TGraphErrors*)inF_GaAsEm->Get("eff");
    TGraphErrors* eff_Double9090 = (TGraphErrors*)inF_Double9090->Get("eff");
    //TGraphErrors* eff_MultiAlkEm = (TGraphErrors*)inF_MultiAlkEm->Get("eff");
    TGraphErrors* eff_Double9040 = (TGraphErrors*)inF_Double9040->Get("eff");

    //settings
    eff_Double9040->SetMarkerColor(kBlue);
    eff_Double9040->SetLineColor(kBlue);
    eff_Double9090->SetMarkerColor(kRed);
    eff_Double9090->SetLineColor(kRed);
  //
    eff_Double9040->SetMarkerStyle(20);
    eff_Double9040->SetLineWidth(2);
    eff_Double9040->SetMarkerSize(0.9);
    eff_Double9090->SetMarkerStyle(20);
    eff_Double9090->SetLineWidth(2);
    eff_Double9090->SetMarkerSize(0.9);

    legC->SetTextFont(42);
    legC->SetTextSize(0.034);
    legC->SetFillColor(kWhite);
    legC->SetLineColor(kWhite);
    legC->SetShadowColor(kWhite);
    legC->AddEntry(eff_Double9040, "Double9040 HV_{2} = 3000 (V)", "p");
    legC->AddEntry(eff_Double9090, "Double9090 HV_{2} = 3000 (V)", "p");
  
    mg->Add(eff_Double9090);
    mg->Add(eff_Double9040);

    //    TCanvas* c = new TCanvas("cEff","cEff",400,800);
    TCanvas* c = new TCanvas();
    gPad->SetTicks();
    char plot_name[100];
    std::string command = "if [ ! -e final_plots/ ] ; then mkdir final_plots ; fi";
    system(command.c_str());
    sprintf(plot_name, "final_plots/efficiency_%s.pdf", plot_type.c_str());

    mg->Draw("APL");
    mg->SetTitle("Electron Beam 450 MeV");
    mg->GetXaxis()->SetRangeUser(2200,4000);
    mg->GetXaxis()->SetTitle("HV_{1} (V)");
    mg->GetXaxis()->SetTitleSize(0.05);
    mg->GetYaxis()->SetTitle("Efficiency");
    mg->GetYaxis()->SetTitleSize(0.05);
    mg->SetMaximum(1);
    mg->SetMinimum(0);
    mg->Draw("APL");  
    legC->Draw("same");
    banner4Plot();
    c->Update();

    c->Print(plot_name, "pdf");
    sprintf(plot_name, "final_plots/efficiency_%s.png", plot_type.c_str());
    c->Print(plot_name, "png");

    sprintf(plot_name, "final_plots/efficiency_%s.root", plot_type.c_str());
    c->SaveAs(plot_name, "root");
    sprintf(plot_name, "final_plots/efficiency_%s.C", plot_type.c_str());
    c->SaveAs(plot_name, "C");
  }

/////----------------------------------------------------------------------------//////////////

if(plot_type == "Ang"){
    legC = new TLegend(0.12,0.62,0.40,0.87,NULL,"brNDC");

	//plot name MCPName_ScanType_HVScanScanType_MCPName
    inF_Double9040 = TFile::Open("plots/efficiency_studies/Double9040_Ang_AngScan_Double9040.root");    
    TGraphErrors* eff_Double9040 = (TGraphErrors*)inF_Double9040->Get("eff");

    //settings
    eff_Double9040->SetMarkerColor(kBlue);
    eff_Double9040->SetLineColor(kBlue);
  //
    eff_Double9040->SetMarkerStyle(20);
    eff_Double9040->SetLineWidth(2);
    eff_Double9040->SetMarkerSize(0.9);

    legC->SetTextFont(42);
    legC->SetTextSize(0.034);
    legC->SetFillColor(kWhite);
    legC->SetLineColor(kWhite);
    legC->SetShadowColor(kWhite);
    legC->AddEntry(eff_Double9040, "Double9040 HV_{1} = 2700 V, HV_{2} = 2700 V", "p");
  
    mg->Add(eff_Double9040);

    //    TCanvas* c = new TCanvas("cEff","cEff",400,800);
    TCanvas* c = new TCanvas();
    gPad->SetTicks();
    char plot_name[100];
    std::string command = "if [ ! -e final_plots/ ] ; then mkdir final_plots ; fi";
    system(command.c_str());
    sprintf(plot_name, "final_plots/efficiency_%s.pdf", plot_type.c_str());

    mg->Draw("APL");
    mg->SetTitle("Electron Beam 450 MeV");
    mg->GetXaxis()->SetRangeUser(-1,50);
    mg->GetXaxis()->SetTitle("Angle (degrees)");
    mg->GetXaxis()->SetTitleSize(0.05);
    mg->GetYaxis()->SetTitle("Efficiency");
    mg->GetYaxis()->SetTitleSize(0.05);
    mg->SetMaximum(0.9);
    mg->SetMinimum(0.5);
    mg->Draw("APL");  
    legC->Draw("same");
    banner4Plot();
    c->Update();

    c->Print(plot_name, "pdf");
    sprintf(plot_name, "final_plots/efficiency_%s.png", plot_type.c_str());
    c->Print(plot_name, "png");

    sprintf(plot_name, "final_plots/efficiency_%s.root", plot_type.c_str());
    c->SaveAs(plot_name, "root");
    sprintf(plot_name, "final_plots/efficiency_%s.C", plot_type.c_str());
    c->SaveAs(plot_name, "C");
  }

/////----------------------------------------------------------------------------//////////////


 if(plot_type == "X0_12"){
    legC = new TLegend(0.15,0.15,0.45,0.32,NULL,"brNDC");

    inF_GaAsEm = TFile::Open("plots/efficiency_studies/GaAsEm_X0_X0Scan12_GaAsEm.root");
    //inF_GaAsEm_OFF = TFile::Open("plots/efficiency_studies/GaAsEm_HV_HVScan7.root");
    inF_MultiAlkEm = TFile::Open("plots/efficiency_studies/MultiAlkEm_X0_X0Scan12_MultiAlkEm.root");
    inF_Double9090 = TFile::Open("plots/efficiency_studies/Double9090_X0_X0Scan12_Double9090.root");
    inF_Double9040 = TFile::Open("plots/efficiency_studies/Double9040_X0_X0Scan12_Double9040.root");    

    TGraphErrors* eff_GaAsEm;
    TGraphErrors* eff_MultiAlkEm;
    TGraphErrors* eff_Double9090;
    TGraphErrors* eff_Double9040;
    
    
    eff_GaAsEm = (TGraphErrors*)inF_GaAsEm->Get("eff");
    eff_MultiAlkEm = (TGraphErrors*)inF_MultiAlkEm->Get("eff");
    eff_Double9090 = (TGraphErrors*)inF_Double9090->Get("eff");
    eff_Double9040 = (TGraphErrors*)inF_Double9040->Get("eff");
    
    //settings
    eff_GaAsEm->SetMarkerColor(kGreen+1);
    eff_GaAsEm->SetLineColor(kGreen+1);
    eff_Double9040->SetMarkerColor(kBlue);
    eff_Double9040->SetLineColor(kBlue);
    eff_Double9090->SetMarkerColor(kRed);
    eff_Double9090->SetLineColor(kRed);
    eff_MultiAlkEm->SetMarkerColor(1);
    eff_MultiAlkEm->SetLineColor(1);
    eff_GaAsEm->SetMarkerStyle(20);
    eff_GaAsEm->SetLineWidth(2);
    eff_GaAsEm->SetMarkerSize(0.9);  
    eff_Double9040->SetMarkerStyle(20);
    eff_Double9040->SetLineWidth(2);
    eff_Double9040->SetMarkerSize(0.9);
    eff_Double9090->SetMarkerStyle(20);
    eff_Double9090->SetLineWidth(2);
    eff_Double9090->SetMarkerSize(0.9);
    eff_MultiAlkEm->SetMarkerStyle(20);
    eff_MultiAlkEm->SetLineWidth(2);
    eff_MultiAlkEm->SetMarkerSize(0.9);
    
    legC->SetTextFont(42);
    legC->SetTextSize(0.037);
    legC->SetFillColor(kWhite);
    legC->SetLineColor(kWhite);
    legC->SetShadowColor(kWhite);

    mg->Add(eff_GaAsEm);
    mg->Add(eff_Double9090);
    mg->Add(eff_MultiAlkEm);
    mg->Add(eff_Double9040);

    TCanvas* c = new TCanvas();
    gPad->SetTicks();
    char plot_name[100];
    std::string command = "if [ ! -e final_plots/ ] ; then mkdir final_plots ; fi";
    system(command.c_str());
    sprintf(plot_name, "final_plots/efficiency_%s.pdf", plot_type.c_str());

    mg->Draw("ALP");
    mg->SetTitle("Electron Beam 450 MeV");
    mg->GetXaxis()->SetRangeUser(-0.1,7.2);
    mg->GetXaxis()->SetTitle("Number of X_{0}");
    mg->GetXaxis()->SetTitleSize(0.046);
    mg->GetYaxis()->SetTitle("Efficiency");
    mg->GetYaxis()->SetTitleSize(0.046);
    mg->SetMaximum(1.05);
    mg->SetMinimum(0);
     
    legC->AddEntry(eff_MultiAlkEm, "MultiAlk emitt (ON) HV_{1} = -3800 HV_{2} = -3500 (V)", "p"); 
    legC->AddEntry(eff_GaAsEm, "GaAs emitt. (ON) HV_{1} = -3400 (V) HV_{2} = -3100 (V)", "p"); 
    //legC->AddEntry(eff_GaAsEm_OFF, "GaAs emitt. - iMCP mode", "p");
    legC->AddEntry(eff_Double9040, "Double9040 HV_{1} = -2700 (V), HV_{2} = 2700 (V)", "p");
    legC->AddEntry(eff_Double9090, "Double9090 HV_{1} = -2700 (V), HV_{2} = 2700 (V)", "p");

    mg->Draw("ALP");  
    legC->Draw("same");
    banner4Plot();
    c->Update();

    c->Print(plot_name, "pdf");
    sprintf(plot_name, "final_plots/efficiency_%s.png", plot_type.c_str());
    c->Print(plot_name, "png");

    sprintf(plot_name, "final_plots/efficiency_%s.root", plot_type.c_str());
    c->Print(plot_name, "root");
    sprintf(plot_name, "final_plots/efficiency_%s.C", plot_type.c_str());
    c->SaveAs(plot_name, "C");
 }


/////----------------------------------------------------------------------------//////////////


 if(plot_type == "X0_1"){
    legC = new TLegend(0.15,0.15,0.45,0.32,NULL,"brNDC");

    inF_GaAsEm = TFile::Open("plots/efficiency_studies/GaAsEm_X0_X0Scan1_GaAsEm.root");
    //inF_GaAsEm_OFF = TFile::Open("plots/efficiency_studies/GaAsEm_HV_HVScan7.root");
    inF_MultiAlkEm = TFile::Open("plots/efficiency_studies/MultiAlkEm_X0_X0Scan1_MultiAlkEm.root");
    inF_Double9090 = TFile::Open("plots/efficiency_studies/Double9090_X0_X0Scan1_Double9090.root");
    inF_Double9040 = TFile::Open("plots/efficiency_studies/Double9040_X0_X0Scan1_Double9040.root");    

    TGraphErrors* eff_GaAsEm;
    TGraphErrors* eff_MultiAlkEm;
    TGraphErrors* eff_Double9090;
    TGraphErrors* eff_Double9040;
    
    
    eff_GaAsEm = (TGraphErrors*)inF_GaAsEm->Get("eff");
    eff_MultiAlkEm = (TGraphErrors*)inF_MultiAlkEm->Get("eff");
    eff_Double9090 = (TGraphErrors*)inF_Double9090->Get("eff");
    eff_Double9040 = (TGraphErrors*)inF_Double9040->Get("eff");
    
    //settings
    eff_GaAsEm->SetMarkerColor(kGreen+1);
    eff_GaAsEm->SetLineColor(kGreen+1);
    eff_Double9040->SetMarkerColor(kBlue);
    eff_Double9040->SetLineColor(kBlue);
    eff_Double9090->SetMarkerColor(kRed);
    eff_Double9090->SetLineColor(kRed);
    eff_MultiAlkEm->SetMarkerColor(1);
    eff_MultiAlkEm->SetLineColor(1);
    eff_GaAsEm->SetMarkerStyle(20);
    eff_GaAsEm->SetLineWidth(2);
    eff_GaAsEm->SetMarkerSize(0.9);  
    eff_Double9040->SetMarkerStyle(20);
    eff_Double9040->SetLineWidth(2);
    eff_Double9040->SetMarkerSize(0.9);
    eff_Double9090->SetMarkerStyle(20);
    eff_Double9090->SetLineWidth(2);
    eff_Double9090->SetMarkerSize(0.9);
    eff_MultiAlkEm->SetMarkerStyle(20);
    eff_MultiAlkEm->SetLineWidth(2);
    eff_MultiAlkEm->SetMarkerSize(0.9);
    
    legC->SetTextFont(42);
    legC->SetTextSize(0.037);
    legC->SetFillColor(kWhite);
    legC->SetLineColor(kWhite);
    legC->SetShadowColor(kWhite);

    mg->Add(eff_GaAsEm);
    mg->Add(eff_Double9090);
    mg->Add(eff_MultiAlkEm);
    mg->Add(eff_Double9040);

    TCanvas* c = new TCanvas();
    gPad->SetTicks();
    char plot_name[100];
    std::string command = "if [ ! -e final_plots/ ] ; then mkdir final_plots ; fi";
    system(command.c_str());
    sprintf(plot_name, "final_plots/efficiency_%s.pdf", plot_type.c_str());

    mg->Draw("ALP");
    mg->SetTitle("Electron Beam 450 MeV");
    mg->GetXaxis()->SetRangeUser(-0.1,7.2);
    mg->GetXaxis()->SetTitle("Number of X_{0}");
    mg->GetXaxis()->SetTitleSize(0.046);
    mg->GetYaxis()->SetTitle("Efficiency");
    mg->GetYaxis()->SetTitleSize(0.046);
    mg->SetMaximum(1.05);
    mg->SetMinimum(0);
     
    legC->AddEntry(eff_MultiAlkEm, "MultiAlk emitt (OFF) HV_{1} = -3450 HV_{2} = -3500 (V)", "p"); 
    legC->AddEntry(eff_GaAsEm, "GaAs emitt. (OFF) HV_{1} = -3050 (V) HV_{2} = -3100 (V)", "p"); 
    //legC->AddEntry(eff_GaAsEm_OFF, "GaAs emitt. - iMCP mode", "p");
    legC->AddEntry(eff_Double9040, "Double9040 HV_{1} = -2400 (V), HV_{2} = 2700 (V)", "p");
    legC->AddEntry(eff_Double9090, "Double9090 HV_{1} = -2400 (V), HV_{2} = 2700 (V)", "p");

    mg->Draw("ALP");  
    legC->Draw("same");
    banner4Plot();
    c->Update();

    c->Print(plot_name, "pdf");
    sprintf(plot_name, "final_plots/efficiency_%s.png", plot_type.c_str());
    c->Print(plot_name, "png");

    sprintf(plot_name, "final_plots/efficiency_%s.root", plot_type.c_str());
    c->Print(plot_name, "root");
    sprintf(plot_name, "final_plots/efficiency_%s.C", plot_type.c_str());
    c->SaveAs(plot_name, "C");
 }


 /////----------------------------------------------------------------------------////////////// 

 if(plot_type == "multiplicity1"){
    legC = new TLegend(0.15,0.15,0.45,0.32,NULL,"brNDC");

    inF_GaAsEm = TFile::Open("plots/efficiency_studies/GaAsEm_multiplicity1_LongScan0X0_GaAsEm_1.root");
    //inF_GaAsEm_OFF = TFile::Open("plots/efficiency_studies/GaAsEm_HV_HVScan7.root");
    inF_MultiAlkEm = TFile::Open("plots/efficiency_studies/MultiAlkEm_multiplicity1_LongScan0X0_MultiAlkEm_1.root");
    inF_Double9090 = TFile::Open("plots/efficiency_studies/Double9090_multiplicity1_LongScan0X0_Double9090_1.root");
    inF_Double9040 = TFile::Open("plots/efficiency_studies/Double9040_multiplicity1_LongScan0X0_Double9040_1.root");    

    TGraphErrors* eff_GaAsEm;
    TGraphErrors* eff_MultiAlkEm;
    TGraphErrors* eff_Double9090;
    TGraphErrors* eff_Double9040;
    
    
    eff_GaAsEm = (TGraphErrors*)inF_GaAsEm->Get("eff");
    eff_MultiAlkEm = (TGraphErrors*)inF_MultiAlkEm->Get("eff");
    eff_Double9090 = (TGraphErrors*)inF_Double9090->Get("eff");
    eff_Double9040 = (TGraphErrors*)inF_Double9040->Get("eff");
    
    //settings
    eff_GaAsEm->SetMarkerColor(kGreen+1);
    eff_GaAsEm->SetLineColor(kGreen+1);
    eff_Double9040->SetMarkerColor(kBlue);
    eff_Double9040->SetLineColor(kBlue);
    eff_Double9090->SetMarkerColor(kRed);
    eff_Double9090->SetLineColor(kRed);
    eff_MultiAlkEm->SetMarkerColor(1);
    eff_MultiAlkEm->SetLineColor(1);
    eff_GaAsEm->SetMarkerStyle(20);
    eff_GaAsEm->SetLineWidth(2);
    eff_GaAsEm->SetMarkerSize(0.9);  
    eff_Double9040->SetMarkerStyle(20);
    eff_Double9040->SetLineWidth(2);
    eff_Double9040->SetMarkerSize(0.9);
    eff_Double9090->SetMarkerStyle(20);
    eff_Double9090->SetLineWidth(2);
    eff_Double9090->SetMarkerSize(0.9);
    eff_MultiAlkEm->SetMarkerStyle(20);
    eff_MultiAlkEm->SetLineWidth(2);
    eff_MultiAlkEm->SetMarkerSize(0.9);
    
    legC->SetTextFont(42);
    legC->SetTextSize(0.037);
    legC->SetFillColor(kWhite);
    legC->SetLineColor(kWhite);
    legC->SetShadowColor(kWhite);

    mg->Add(eff_GaAsEm);
    mg->Add(eff_Double9090);
    mg->Add(eff_MultiAlkEm);
    mg->Add(eff_Double9040);

    TCanvas* c = new TCanvas();
    gPad->SetTicks();
    char plot_name[100];
    std::string command = "if [ ! -e final_plots/ ] ; then mkdir final_plots ; fi";
    system(command.c_str());
    sprintf(plot_name, "final_plots/efficiency_%s.pdf", plot_type.c_str());

    mg->Draw("ALP");
    mg->SetTitle("Electron Beam 450 MeV");
    mg->GetXaxis()->SetRangeUser(-0.1,7.2);
    mg->GetXaxis()->SetTitle("multiplicity");
    mg->GetXaxis()->SetTitleSize(0.046);
    mg->GetYaxis()->SetTitle("Efficiency");
    mg->GetYaxis()->SetTitleSize(0.046);
    mg->SetMaximum(1.05);
    mg->SetMinimum(0);
     
    legC->AddEntry(eff_MultiAlkEm, "MultiAlk emitt (ON) HV_{1} = -3800 HV_{2} = -3500 (V)", "p"); 
    legC->AddEntry(eff_GaAsEm, "GaAs emitt. (ON) HV_{1} = -3400 (V) HV_{2} = -3100 (V)", "p"); 
    //legC->AddEntry(eff_GaAsEm_OFF, "GaAs emitt. - iMCP mode", "p");
    legC->AddEntry(eff_Double9040, "Double9040 HV_{1} = -2700 (V), HV_{2} = 2700 (V)", "p");
    legC->AddEntry(eff_Double9090, "Double9090 HV_{1} = -2700 (V), HV_{2} = 2700 (V)", "p");

    mg->Draw("ALP");  
    legC->Draw("same");
    banner4Plot();
    c->Update();

    c->Print(plot_name, "pdf");
    sprintf(plot_name, "final_plots/efficiency_%s.png", plot_type.c_str());
    c->Print(plot_name, "png");

    sprintf(plot_name, "final_plots/efficiency_%s.root", plot_type.c_str());
    c->Print(plot_name, "root");
    sprintf(plot_name, "final_plots/efficiency_%s.C", plot_type.c_str());
    c->SaveAs(plot_name, "C");
 }


/////----------------------------------------------------------------------------//////////////


 if(plot_type == "multiplicity2"){
    legC = new TLegend(0.15,0.15,0.45,0.32,NULL,"brNDC");

    inF_GaAsEm = TFile::Open("plots/efficiency_studies/GaAsEm_multiplicity2_LongScan0X0_GaAsEm_2.root");
    //inF_GaAsEm_OFF = TFile::Open("plots/efficiency_studies/GaAsEm_multiplicity2_HVScan7.root");
    inF_MultiAlkEm = TFile::Open("plots/efficiency_studies/MultiAlkEm_multiplicity2_LongScan0X0_MultiAlkEm_2.root");
    inF_Double9090 = TFile::Open("plots/efficiency_studies/Double9090_multiplicity2_LongScan0X0_Double9090_2.root");
    inF_Double9040 = TFile::Open("plots/efficiency_studies/Double9040_multiplicity2_LongScan0X0_Double9040_2.root");    

    TGraphErrors* eff_GaAsEm;
    TGraphErrors* eff_MultiAlkEm;
    TGraphErrors* eff_Double9090;
    TGraphErrors* eff_Double9040;
    
    
    eff_GaAsEm = (TGraphErrors*)inF_GaAsEm->Get("eff");
    eff_MultiAlkEm = (TGraphErrors*)inF_MultiAlkEm->Get("eff");
    eff_Double9090 = (TGraphErrors*)inF_Double9090->Get("eff");
    eff_Double9040 = (TGraphErrors*)inF_Double9040->Get("eff");
    
    //settings
    eff_GaAsEm->SetMarkerColor(kGreen+1);
    eff_GaAsEm->SetLineColor(kGreen+1);
    eff_Double9040->SetMarkerColor(kBlue);
    eff_Double9040->SetLineColor(kBlue);
    eff_Double9090->SetMarkerColor(kRed);
    eff_Double9090->SetLineColor(kRed);
    eff_MultiAlkEm->SetMarkerColor(1);
    eff_MultiAlkEm->SetLineColor(1);
    eff_GaAsEm->SetMarkerStyle(20);
    eff_GaAsEm->SetLineWidth(2);
    eff_GaAsEm->SetMarkerSize(0.9);  
    eff_Double9040->SetMarkerStyle(20);
    eff_Double9040->SetLineWidth(2);
    eff_Double9040->SetMarkerSize(0.9);
    eff_Double9090->SetMarkerStyle(20);
    eff_Double9090->SetLineWidth(2);
    eff_Double9090->SetMarkerSize(0.9);
    eff_MultiAlkEm->SetMarkerStyle(20);
    eff_MultiAlkEm->SetLineWidth(2);
    eff_MultiAlkEm->SetMarkerSize(0.9);
    
    legC->SetTextFont(42);
    legC->SetTextSize(0.037);
    legC->SetFillColor(kWhite);
    legC->SetLineColor(kWhite);
    legC->SetShadowColor(kWhite);

    mg->Add(eff_GaAsEm);
    mg->Add(eff_Double9090);
    mg->Add(eff_MultiAlkEm);
    mg->Add(eff_Double9040);

    TCanvas* c = new TCanvas();
    gPad->SetTicks();
    char plot_name[100];
    std::string command = "if [ ! -e final_plots/ ] ; then mkdir final_plots ; fi";
    system(command.c_str());
    sprintf(plot_name, "final_plots/efficiency_%s.pdf", plot_type.c_str());

    mg->Draw("ALP");
    mg->SetTitle("Electron Beam 450 MeV");
    mg->GetXaxis()->SetRangeUser(-0.1,7.2);
    mg->GetXaxis()->SetTitle("multiplicity");
    mg->GetXaxis()->SetTitleSize(0.046);
    mg->GetYaxis()->SetTitle("Efficiency");
    mg->GetYaxis()->SetTitleSize(0.046);
    mg->SetMaximum(1.05);
    mg->SetMinimum(0);

    legC->AddEntry(eff_MultiAlkEm, "MultiAlk emitt (OFF) HV_{1} = -3450 HV_{2} = -3500 (V)", "p"); 
    legC->AddEntry(eff_GaAsEm, "GaAs emitt. (OFF) HV_{1} = -3050 (V) HV_{2} = -3100 (V)", "p"); 
    //legC->AddEntry(eff_GaAsEm_OFF, "GaAs emitt. - iMCP mode", "p");
    legC->AddEntry(eff_Double9040, "Double9040 HV_{1} = -2400 (V), HV_{2} = 2700 (V)", "p");
    legC->AddEntry(eff_Double9090, "Double9090 HV_{1} = -2400 (V), HV_{2} = 2700 (V)", "p");

    mg->Draw("ALP");  
    legC->Draw("same");
    banner4Plot();
    c->Update();

    c->Print(plot_name, "pdf");
    sprintf(plot_name, "final_plots/efficiency_%s.png", plot_type.c_str());
    c->Print(plot_name, "png");

    sprintf(plot_name, "final_plots/efficiency_%s.root", plot_type.c_str());
    c->Print(plot_name, "root");
    sprintf(plot_name, "final_plots/efficiency_%s.C", plot_type.c_str());
    c->SaveAs(plot_name, "C");
 }


/////----------------------------------------------------------------------------//////////////
  
 if(plot_type == "LongScan2X0"){
    legC = new TLegend(0.15,0.15,0.45,0.32,NULL,"brNDC");

    inF_GaAsEm = TFile::Open("plots/efficiency_studies/GaAsEm_HV1_LongScan2X0_GaAsEm.root");
    //inF_GaAsEm_OFF = TFile::Open("plots/efficiency_studies/GaAsEm_multiplicity2_HVScan7.root");
    inF_MultiAlkEm = TFile::Open("plots/efficiency_studies/MultiAlkEm_HV1_LongScan2X0_MultiAlkEm.root");
    inF_Double9090 = TFile::Open("plots/efficiency_studies/Double9090_HV1_LongScan2X0_Double9090.root");
    inF_Double9040 = TFile::Open("plots/efficiency_studies/Double9040_HV1_LongScan2X0_Double9040.root");    

    TGraphErrors* eff_GaAsEm;
    TGraphErrors* eff_MultiAlkEm;
    TGraphErrors* eff_Double9090;
    TGraphErrors* eff_Double9040;
    
    
    eff_GaAsEm = (TGraphErrors*)inF_GaAsEm->Get("eff");
    eff_MultiAlkEm = (TGraphErrors*)inF_MultiAlkEm->Get("eff");
    eff_Double9090 = (TGraphErrors*)inF_Double9090->Get("eff");
    eff_Double9040 = (TGraphErrors*)inF_Double9040->Get("eff");
    
    //settings
    eff_GaAsEm->SetMarkerColor(kGreen+1);
    eff_GaAsEm->SetLineColor(kGreen+1);
    eff_Double9040->SetMarkerColor(kBlue);
    eff_Double9040->SetLineColor(kBlue);
    eff_Double9090->SetMarkerColor(kRed);
    eff_Double9090->SetLineColor(kRed);
    eff_MultiAlkEm->SetMarkerColor(1);
    eff_MultiAlkEm->SetLineColor(1);
    eff_GaAsEm->SetMarkerStyle(20);
    eff_GaAsEm->SetLineWidth(2);
    eff_GaAsEm->SetMarkerSize(0.9);  
    eff_Double9040->SetMarkerStyle(20);
    eff_Double9040->SetLineWidth(2);
    eff_Double9040->SetMarkerSize(0.9);
    eff_Double9090->SetMarkerStyle(20);
    eff_Double9090->SetLineWidth(2);
    eff_Double9090->SetMarkerSize(0.9);
    eff_MultiAlkEm->SetMarkerStyle(20);
    eff_MultiAlkEm->SetLineWidth(2);
    eff_MultiAlkEm->SetMarkerSize(0.9);
    
    legC->SetTextFont(42);
    legC->SetTextSize(0.037);
    legC->SetFillColor(kWhite);
    legC->SetLineColor(kWhite);
    legC->SetShadowColor(kWhite);

    mg->Add(eff_GaAsEm);
    mg->Add(eff_Double9090);
    mg->Add(eff_MultiAlkEm);
    mg->Add(eff_Double9040);

    TCanvas* c = new TCanvas();
    gPad->SetTicks();
    char plot_name[100];
    std::string command = "if [ ! -e final_plots/ ] ; then mkdir final_plots ; fi";
    system(command.c_str());
    sprintf(plot_name, "final_plots/efficiency_%s.pdf", plot_type.c_str());

    mg->Draw("ALP");
    mg->SetTitle("Electron Beam 450 MeV");
    mg->GetXaxis()->SetRangeUser(1400,3800);
    mg->GetXaxis()->SetTitle("HV_{2} (V)");
    mg->GetXaxis()->SetTitleSize(0.046);
    mg->GetYaxis()->SetTitle("Efficiency");
    mg->GetYaxis()->SetTitleSize(0.046);
    mg->SetMaximum(1.05);
    mg->SetMinimum(0);

    legC->AddEntry(eff_MultiAlkEm, "MultiAlk emitt. HV_{2} = 3500 (V)", "p");
    legC->AddEntry(eff_GaAsEm, "GaAs emitt. HV_{2} = 3100 (V)", "p");
//    legC->AddEntry(eff_GaAsEm_OFF, "GaAs emitt. - iMCP mode", "p");
    legC->AddEntry(eff_Double9040, "Double9040 HV_{2} = 2700 (V)", "p");
    legC->AddEntry(eff_Double9090, "Double9090 HV_{2} = 2700 (V)", "p");

    mg->Draw("ALP");  
    legC->Draw("same");
    banner4Plot();
    c->Update();

    c->Print(plot_name, "pdf");
    sprintf(plot_name, "final_plots/efficiency_%s.png", plot_type.c_str());
    c->Print(plot_name, "png");

    sprintf(plot_name, "final_plots/efficiency_%s.root", plot_type.c_str());
    c->Print(plot_name, "root");
    sprintf(plot_name, "final_plots/efficiency_%s.C", plot_type.c_str());
    c->SaveAs(plot_name, "C");
 }


 return 0;
}
//___________________________________________________________________________
Double_t* Ifit(int shift, Double_t& dataResult, Double_t& dataErr, std::string dataFile, 
	       TH1D* hsig, TH1D* hbkg, TH1D* hEGdata, Double_t* FitPar,
	       int ptbin=30, char EBEE[10]="EB", int fit_data=2)
{
  
  printf(" *** calling Ifit for %s , ptbin %d *** \n\n", EBEE,ptbin);

  cout << "The number of bins are: " << endl;
  cout << "hdata nbins = " << hEGdata->GetNbinsX() << endl;
  cout << "hsig nbins = " << hsig->GetNbinsX() << endl;
  cout << "hbkg nbins = " << hbkg->GetNbinsX() << endl;
  

  TCanvas *c1 = new TCanvas("HF1", "Histos1", 0, 0, 600, 600);
  gStyle->SetOptFit(0);

  if(fit_data != 3) dataColl.clear();
  sigColl.clear();
  bkgColl.clear();

  totalColl.clear();
  ctauColl.clear();
  Para.clear();
  Para_err.clear();

  info.clear();
  info_err.clear();

  float ptmax=0.;  
  if(ptbin== 21) ptmax= 23;
  if(ptbin== 23) ptmax= 26;
  if(ptbin== 26) ptmax= 30;
  if(ptbin== 30) ptmax= 35;
  if(ptbin== 35) ptmax= 40;
  if(ptbin== 40) ptmax= 45;
  if(ptbin== 45) ptmax= 50;
  if(ptbin== 50) ptmax= 60;
  if(ptbin== 60) ptmax= 85;
  if(ptbin== 85) ptmax= 120;
  if(ptbin== 120) ptmax= 300;
  if(ptbin== 300) ptmax= 500;



  Double_t* fitted = new Double_t[6];
  fitted[0] = 0.;    fitted[1] = 0.;    fitted[2] = 0.;    fitted[3] = 0.;
  fitted[4] = 0.;    fitted[5] = 0.;

  char hname[30];


  hsig->SetLineColor(1);
  hbkg->SetLineColor(1);
  hsig->SetNdivisions(505,"XY");
  hbkg->SetNdivisions(505,"XY");
  hsig->SetTitle("");
  hbkg->SetTitle("");
  hsig->SetXTitle("combined ISO (GeV)");
  hbkg->SetXTitle("combined ISO (GeV)");

  TH1F *hsum = (TH1F*)hsig->Clone();  
  hsum->Add(hbkg,1);
  float ntemplate = 1.;
  if (hsum->Integral()>1.) ntemplate = hsum->Integral();
  float sigfrac = hsig->Integral()/ntemplate*0.8;

  TH1F *hsum_norm = (TH1F*)hsum->Clone();  
  hsum_norm->Scale(1./hsum->Integral());

  TH1F *hdata = new TH1F();
  int ndata=0;
  if ( fit_data==1 ) {
    hdata = (TH1F*)hEGdata->Clone();
    ndata = (int)hdata->Integral();    
    for(int ibin=1; ibin<=hdata->GetNbinsX(); ibin++){
      for(int ipoint=0; ipoint<hdata->GetBinContent(ibin); ipoint++) {
	dataColl.push_back(hdata->GetBinCenter(ibin));
      }
    }
    ndata = dataColl.size();
  }else if (fit_data==2 ){
      hdata = (TH1F*)hEGdata->Clone();
    hdata -> Reset();
    dataColl.clear();
    FILE *infile =  fopen(dataFile.data(),"r");  
    float xdata, xdata1, xdata2; // combined isolation, pt, eta

    int flag = 1;
    while (flag!=-1){
      flag =fscanf(infile,"%f %f %f",&xdata, &xdata1, &xdata2);
      if( xdata1 >= ptbin && xdata1 < ptmax && xdata<20.) {
	if((strcmp(EBEE,"EB")==0 && TMath::Abs(xdata2)<1.45) ||
	   (strcmp(EBEE,"EE")==0 && TMath::Abs(xdata2)<2.5 && TMath::Abs(xdata2)>1.7) ) {
 	  dataColl.push_back(xdata);
	  hdata->Fill(xdata);
 	}
      } 
    }// keep reading files as long as text exists
    ndata = dataColl.size();

    printf("test print data 2 %2.3f \n", dataColl[2]);    
//     cout << "ndata in dataColl = " << ndata << endl;
    if ( ndata == 0 ) {
      printf(" no data to fit \n");
      return fitted;
    }
  }

  if(ndata==0) {
    printf(" ---  no events in the fit \n");
    return fitted;
  }
    
  //test fit the template and get PDFs
  TCanvas *c10 = new TCanvas("c10","c10",1000,500);
  c10->Divide(2,1);
  c10->cd(1);

  double par[20] = {hsig->GetMaximum(), 1., 0.6, 0.3,
		    hbkg->GetMaximum(), -.45, -0.05, 0.03, 1., 1., 1., 1.};

  if(strcmp(EBEE,"EE")==0) { par[2]=-0.1, par[3]=0.2; par[6]=-0.15; par[7]=0.02; };
  int fit_status;

  TF1 *f1 = new TF1("f1", exp_conv, -1., 20., 11);
  TF1 *fmcsigfit = new TF1("fmcsigfit", exp_conv, -1., 20., 11);
  fmcsigfit->SetLineColor(4);
  fmcsigfit->SetLineWidth(2);

  f1->SetNpx(10000);
  f1->SetParameters(par);
  f1->SetLineWidth(2);
  c10->cd(1);
  fit_status = hsig->Fit(f1,"","",-1., 5.);

  hsig->Draw();
  f1->Draw("same");
  if ( fit_status > 0 ) {
     printf("fit signal template failed. QUIT \n");
     return fitted;
  }
  if(para_index>0 && para_index<4){
    double tmppar = f1->GetParameter(para_index);
    f1->SetParameter(para_index, tmppar+para_sigma*f1->GetParError(para_index));
  }

  TF1 *fmcsig = (TF1*)f1->Clone();
  TF1 *fmcsigcorr = (TF1*)f1->Clone();
  fmcsig->SetNpx(10000);
  fmcsigcorr->SetNpx(10000);
  fmcsigfit->SetNpx(10000);
  
  TCanvas *c101 = new TCanvas("c101","c101",1000,500);
  c101->Divide(2,1);
  c101->cd(1);

  fmcsig->SetLineColor(1);
//   fmcsig->Draw();
//   f1->Draw("same");
  TH1F *htmp1 = (TH1F*)fmcsig->GetHistogram();
//   TH1F *htmp2 = (TH1F*)fmcsigcorr->GetHistogram();
  
  TH2F *htmp2 = new TH2F("htmp2","",210, -1., 20., 100, 0., htmp1->GetMaximum()*1.25);

  htmp2->SetNdivisions(505,"XY");
  htmp2->SetXTitle("Iso");
  htmp2->SetYTitle("A.U.");
  htmp2->SetLineColor(1);

//   htmp2->Draw();
//   htmp1->Draw("same");
//   htmp2->Add(htmp1,-1);
//   htmp2->Divide(htmp1);
  htmp2->GetXaxis()->SetRangeUser(-1., 10.);
  htmp2->SetMinimum(-1.);
  //htmp2->SetMaximum(1.5);
  htmp2->Draw();
  fmcsig->Draw("same");
//   fmcsigcorr->Draw("same");
  
  TLegend *tleg1 = new TLegend(0.5, 0.7, 0.93, 0.92);
  tleg1->SetHeader("");
  tleg1->SetFillColor(0);
  tleg1->SetShadowColor(0);
  tleg1->SetBorderSize(0);
  tleg1->AddEntry(fmcsig,"Zee data","l");
  //tleg1->AddEntry(fmcsigcorr,"corrected shape","l");
  tleg1->AddEntry(fmcsigfit,"shape from data","l");
  tleg1->Draw();

  //return fitted;
       
  SigPDFnorm = f1->Integral(-1.,20.);
  printf("status %d, sig area %3.3f \n", fit_status,f1->Integral(-1., 20.));


  f1->SetParameter(2,f1->GetParameter(2)+0.2);
  f1->SetParameter(3,f1->GetParameter(3)+0.1);

  Para.push_back(f1->GetParameter(0));
  Para.push_back(f1->GetParameter(1));
  Para.push_back(f1->GetParameter(2));
  Para.push_back(f1->GetParameter(3));

  Para_err.push_back(f1->GetParError(0));
  Para_err.push_back(f1->GetParError(1));
  Para_err.push_back(f1->GetParError(2));
  Para_err.push_back(f1->GetParError(3));

  c10->cd(2);
  TF1 *fbkgfit = new TF1("fbkgfit", expinv_power, -1., 20., 11);  

  TF1 *f3 = new TF1("f3", expinv_power, -1., 20., 11);
  fbkgfit->SetNpx(10000);  
  fbkgfit->SetLineColor(4);
  fbkgfit->SetLineWidth(2);

  f3->SetNpx(10000);
  f3->SetLineWidth(2);
  f3->SetParameters(f1->GetParameters());
    
  f3->SetParLimits(5,-5.,0.);
  f3->SetParLimits(6,-0.5,0.);
  f3->SetParLimits(7,0.001,0.2);
  f3->SetParLimits(8,0.5,5.);
  if ( strcmp(EBEE,"EB")==0 ){  
//     f3->FixParameter(8,1.);
//     f3->FixParameter(6,-0.1);
    f3->SetParLimits(8,1.,1.5);
  }

  float bkg_bend_power = 1.;
  if ( ptbin==21 ) bkg_bend_power = 4.5;
  if ( ptbin==23 ) bkg_bend_power = 4.;
  if ( ptbin==26 ) bkg_bend_power = 3.5;
  if ( ptbin==30 ) bkg_bend_power = 2.6;
  if ( ptbin==35 ) bkg_bend_power = 2.2;
  if ( ptbin==40 ) bkg_bend_power = 2.;
  if ( ptbin==45 ) bkg_bend_power = 2.;
  if ( ptbin==50 ) bkg_bend_power = 1.8;
  if ( ptbin==60 ) bkg_bend_power = 1.5;
  if ( ptbin==85 ) bkg_bend_power = 1.;
  if ( ptbin==120 ) bkg_bend_power = 1.;


  if ( strcmp(EBEE,"EE")==0 ){  
    f3->SetParameter(8,bkg_bend_power);
    f3->SetParLimits(8,bkg_bend_power-1., bkg_bend_power+1.);
  }

  f3->FixParameter(0,f3->GetParameter(0));
  f3->FixParameter(1,f3->GetParameter(1));
  f3->FixParameter(2,f3->GetParameter(2));
  f3->FixParameter(3,f3->GetParameter(3));

  hbkg->SetMaximum(hbkg->GetMaximum()*3.);
  fit_status = hbkg->Fit(f3,"b","",-1., 20.);
  hbkg->Draw();
  if ( fit_status > 0 ) {
    printf("fit background template failed. QUIT \n");    
    return fitted;
  }else {
    f3->Draw("same");
  }

  TF1 *fmcbkg = (TF1*)f3->Clone();
  fmcbkg->SetLineColor(1);
  c101->cd(2);

  htmp1 = (TH1F*)fmcbkg->GetHistogram();
  htmp2 = new TH2F("htmp2","",210, -1., 20., 100, 0., htmp1->GetMaximum()*1.25);

  htmp2->SetNdivisions(505,"XY");
  htmp2->SetXTitle("Iso");
  htmp2->SetYTitle("A.U.");
  htmp2->SetLineColor(1);

  htmp2->GetXaxis()->SetRangeUser(-1., 20.);
  htmp2->SetMinimum(-1.);
  htmp2->SetMaximum(1.5);
  htmp2->Draw();
  fmcbkg->Draw("same");

  TLegend *tleg2 = new TLegend(0.25, 0.2, 0.6, 0.42);
  tleg2->SetHeader("");
  tleg2->SetFillColor(0);
  tleg2->SetShadowColor(0);
  tleg2->SetBorderSize(0);
  if ( strcmp(EBEE,"EB")==0 ){  
    tleg2->AddEntry(fmcbkg,"MC shape","l");
  }else {
    tleg2->AddEntry(fmcbkg,"Data SB shape","l");
  }
  tleg2->AddEntry(fbkgfit,"shape from data","l");
  tleg2->Draw();
  
  if(para_index>4){
    double tmppar = f3->GetParameter(para_index);
    f3->SetParameter(para_index, tmppar+para_sigma*f3->GetParError(para_index));
  }

//   f3->SetParameter(5,-0.5);
//   f3->SetParameter(6,-0.05);
//   f3->SetParameter(7,0.02);
//   f3->SetParameter(8,1.);

  Para.push_back(f3->GetParameter(4));
  Para.push_back(f3->GetParameter(5));
  Para.push_back(f3->GetParameter(6));
  Para.push_back(f3->GetParameter(7)); 
  Para.push_back(f3->GetParameter(8)); 

  Para_err.push_back(f3->GetParError(4));
  Para_err.push_back(f3->GetParError(5));
  Para_err.push_back(f3->GetParError(6));
  Para_err.push_back(f3->GetParError(7));
  Para_err.push_back(f3->GetParError(8));

  BkgPDFnorm = f3->Integral(-1., 20.);
  printf("status %d, bkg area %3.3f \n", fit_status,f3->Integral(-1., 20.)/hdata->GetBinWidth(2));

  //test PDFs
  TCanvas *c11 = new TCanvas("c11","c11",1000,500);
  c11->Divide(2,1);
  c11->cd(1);
  TF1 *f11 = new TF1("f11",exp_conv_norm, -1., 20., 11);
  f11->SetNpx(10000);
  f11->SetParameters(f3->GetParameters());
  f11->Draw();
  printf(" SIG PDF area %2.3f \n", f11->Integral(-1., 20.));

  c11->cd(2);
  TF1 *f12 = new TF1("f12",expinv_power_norm, -1., 20., 11);
  f12->SetNpx(10000);
  f12->SetParameters(f3->GetParameters());
  f12->Draw();
  printf(" BKG PDF area %2.3f \n", f12->Integral(-1., 20.));

  //c1->cd();

  printf(" --------- before the fit ------------- \n");
  printf("Nsig %2.3f, Nbg %2.3f, Ntemplate %3.3f \n", hsig->Integral(), hbkg->Integral(), ntemplate);
  printf("Purity %2.3f, init size %4.3f,  fit sample size %4d\n", hsig->Integral()/hsum->Integral(), hsum->Integral(), ndata);
  printf(" -------------------------------------- \n");



  printf( " -----  Got %d, %d, %d events for fit ----- \n ", dataColl.size(),
	  sigColl.size(), bkgColl.size() );  

  //--------------------------------------------------
  //init parameters for fit
  Double_t vstart[11] = {1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.};
  vstart[0] = sigfrac*ndata;
  vstart[1] = (1-sigfrac)*ndata;
  for (int ii=0; ii<9; ii++) {    
    vstart[ii+2] = Para[ii]; //8 shape parameters
  }
  TMinuit *gMinuit = new TMinuit(NPAR);  
  gMinuit->Command("SET STR 1");
  gMinuit->SetFCN(fcn);
  Double_t arglist[11];
  Int_t ierflg = 0;
  
  arglist[0] = 1;
  gMinuit->mnexcm("SET ERR", arglist ,1,ierflg);
  arglist[0] = 1;
  gMinuit->mnexcm("SET PRINT", arglist ,1,ierflg);

  Double_t step[] = { 1.,1.,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.01,};

  for ( int ii=0; ii<9; ii++){
    printf(" para %d, %.5f, err %.5f \n", ii, Para[ii], Para_err[ii]);
  }

  float sigma = 3.;
  gMinuit->mnparm(0,  "Signal yield"  , vstart[0],  step[0], 0., ndata*2.  , ierflg);
  gMinuit->mnparm(1,  "background yield"  , vstart[1],  step[1], 0., ndata*2. , ierflg);

//   gMinuit->mnparm(2,  "constant"     , Para[0],  0.00,  Para[0], Para[0] , ierflg);
//   gMinuit->mnparm(3,  "exp tail"     , Para[1],  0.01,  Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg);
//   gMinuit->mnparm(4,  "exg mean"     , Para[2],  0.01,  Para[2]-sigma*Para_err[2], Para[2]+sigma*Para_err[2], ierflg);
//   gMinuit->mnparm(5,  "exg width"    , Para[3],  0.01,  Para[3]-sigma*Para_err[3], Para[3]+sigma*Para_err[3], ierflg);
//   gMinuit->mnparm(6,  "constant"     , Para[4],  0.00,  Para[4]                  , Para[4]                  , ierflg);
//   gMinuit->mnparm(7,  "bg exp turnon", Para[5],  0.01,  Para[5]-sigma*Para_err[5], Para[5]+sigma*Para_err[5], ierflg);
//   gMinuit->mnparm(8,  "bg x offset  ", Para[6],  0.01,  Para[6]-sigma*Para_err[6], Para[6]+sigma*Para_err[6], ierflg);
//   gMinuit->mnparm(9,  "bg bend slope", Para[7],  0.01,  0.001                    , 0.1                      , ierflg);
// //   gMinuit->mnparm(10, "bg bend power", Para[8],  0.01,  Para[8]-sigma*Para_err[8], Para[8]+sigma*Para_err[8], ierflg);
//   gMinuit->mnparm(10, "bg bend power", Para[8],  0.01,  0.5                       , 5.                       , ierflg);

//   gMinuit->mnparm(2,  "constant"     , Para[0], TMath::Abs(Para[0]*0.0) ,  Para[0], Para[0], ierflg);
//   gMinuit->mnparm(3,  "exp tail"     , Para[1], TMath::Abs(Para[1]*0.01) ,  Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); 
// //   gMinuit->mnparm(3,  "exp tail"     , Para[1], TMath::Abs(Para[1]*0.1) ,  0.8    , 1.3    , ierflg);
//   gMinuit->mnparm(4,  "exg mean"     , Para[2], TMath::Abs(Para[2]*0.1) ,  0.5    , 1.0    , ierflg);
//   gMinuit->mnparm(5,  "exg width"    , Para[3], TMath::Abs(Para[3]*0.1) ,  0.25   , 0.5    , ierflg);
//   gMinuit->mnparm(6,  "constant"     , Para[4], TMath::Abs(Para[4]*0.0) ,  Para[4], Para[4], ierflg);
//   gMinuit->mnparm(7,  "bg exp turnon", Para[5], TMath::Abs(Para[5]*0.1) ,  -0.7   , -0.3   , ierflg);
//   gMinuit->mnparm(8,  "bg x offset  ", Para[6], TMath::Abs(Para[6]*0.0) ,  -0.15  , -0.05  , ierflg);
//   gMinuit->mnparm(9,  "bg bend slope", Para[7], TMath::Abs(Para[7]*0.1) ,  0.01   , 0.05   , ierflg);
//   gMinuit->mnparm(10, "bg bend power", Para[8], TMath::Abs(Para[8]*0.1) ,  0.5    , 1.5    , ierflg);

  gMinuit->mnparm(2,  "constant"     , Para[0],  0.00,  Para[0], Para[0] , ierflg);
  gMinuit->mnparm(3,  "exp tail"     , Para[1],  0.00,  Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg);
  gMinuit->mnparm(4,  "exg mean"     , Para[2],  0.00,  Para[2]-sigma*Para_err[2], Para[2]+sigma*Para_err[2], ierflg);
  gMinuit->mnparm(5,  "exg width"    , Para[3],  0.00,  Para[3]-sigma*Para_err[3], Para[3]+sigma*Para_err[3], ierflg);
  gMinuit->mnparm(6,  "constant"     , Para[4],  0.00,  Para[4]                  , Para[4]                  , ierflg);
  gMinuit->mnparm(7,  "bg exp turnon", Para[5],  0.00,  Para[5]-sigma*Para_err[5], Para[5]+sigma*Para_err[5], ierflg);
  gMinuit->mnparm(8,  "bg x offset  ", Para[6],  0.00,  Para[6]-sigma*Para_err[6], Para[6]+sigma*Para_err[6], ierflg);
  gMinuit->mnparm(9,  "bg bend slope", Para[7],  0.00,  0.001                    , 0.1                      , ierflg);
  gMinuit->mnparm(10, "bg bend power", Para[8],  0.00,  Para[8]-sigma*Para_err[8], Para[8]+sigma*Para_err[8], ierflg);
  
  printf(" --------------------------------------------------------- \n");
  printf(" Now ready for minimization step \n --------------------------------------------------------- \n");
  
  arglist[0] = 500; // number of iteration
  gMinuit->mnexcm("MIGRAD", arglist,1,ierflg);
  //can do scan
//   arglist[0] = 0;
//   gMinuit->mnexcm("SCAN", arglist,1,ierflg);

  printf (" -------------------------------------------- \n");
  printf("Finished.  ierr = %d \n", ierflg);

  double para[NPAR+1],errpara[NPAR+1];

  double tmp_errpara[NPAR+1];

  for(int j=0; j<=NPAR-1;j++) { tmp_errpara[j]=0.1; }
  for(int j=2; j<=NPAR-1;j++) { 
    if(Para_err[j-2]!=0.) tmp_errpara[j]=TMath::Abs(Para_err[j-2]); 
  }
  
  int ni=6;       if ( strcmp(EBEE,"EE")==0 ) { ni=6; }//if(ptbin==21) ni=0;}
  
  if ( ierflg == 0 ) {
    for(int i=0; i<ni; i++) {
      float istep[10] = {0.,0.,0.,0.,0.,0.,0.};
      if (i<(ni-1)) {
	istep[i] = 0.001;
      }else {
	for (int j=0; j<ni-1; j++) {istep[j] = 0.001;}
      }

      for(int j=0; j<=NPAR-1;j++) {
	gMinuit->GetParameter(j, para[j], errpara[j]);
	if (errpara[j] != 0. ) {
	  tmp_errpara[j] = TMath::Abs(errpara[j]);
	}
      }

      if ( strcmp(EBEE,"EB")==0 ) {

	sigma = 10.;

 	if ( i==(ni-1) ) { sigma=5.;istep[1]=istep[4]=0.; }
	if ( ptbin==21 && i==1 ){ sigma=3.; }
 	if ( ptbin==21 && i==(ni-1) ){ sigma=20.; }
	if ( ptbin==23 && i==0 ){ para[7]=-0.5; }
	if ( ptbin==23 && i==1 ){ istep[1]=0.; istep[3]=0.01; }
 	if ( ptbin==23 && i==3 ){ istep[1]=0.01; istep[3]=0.0; }
	if ( ptbin==23 && i==(ni-1) ){ sigma=20.; }
 	if ( ptbin==26 && i==1 ){ sigma=5.; }	
	if ( ptbin==26 && i==(ni-1) ){ sigma=20.; }
	if ( ptbin==30 && i==(ni-1) ){ sigma=3.; }
 	if ( ptbin==35 && i==(ni-1) ) { sigma=10.; }
 	if ( ptbin==40 && i==(ni-1) ) { sigma=5.; istep[4]=0.01; }
 	if ( ptbin==45 && i==(ni-1) ) { sigma=10.; }
	if ( ptbin==60 && i==0 ) { para[3]=1.; para[4]=0.6; para[5]=0.32; para[7]=-0.45; para[9]=0.025; para[10] = 1.;}
 	if ( ptbin==60 && i==(ni-1) ) { sigma=5.; istep[4]=0.01;}
	if ( ptbin>=85 && i==(ni-1) ){ sigma=3.; }
	if ( ptbin==300 ) { istep[2]=istep[3]=istep[4]=0.; }// para[7] = -5.11907e-02; istep[1]=0.; }
	float tmp8=0.;
	
// 	if( i!= (ni-1) ) {
	  gMinuit->mnparm(0,  "Signal yield"  ,   para[0],  1., para[0]-100.*tmp_errpara[0], para[0]+100.*tmp_errpara[0], ierflg);
	  gMinuit->mnparm(1,  "background yield", para[1],  1., para[1]-100.*tmp_errpara[1], para[1]+100.*tmp_errpara[1], ierflg);
	  gMinuit->mnparm(2,  "constant"     , para[2],  0., para[2]-100.*tmp_errpara[2], para[2]+100.*tmp_errpara[2], ierflg);
	  gMinuit->mnparm(6,  "constant"     , para[6],  0., para[6]-100.*tmp_errpara[6], para[6]+100.*tmp_errpara[6], ierflg);
	  gMinuit->mnparm(3,  "exp tail"     , para[3],  istep[4],  para[3]-sigma*tmp_errpara[3], para[3]+sigma*tmp_errpara[3], ierflg);
	  gMinuit->mnparm(4,  "exg mean"     , para[4],  istep[3],  para[4]-sigma*tmp_errpara[4], para[4]+sigma*tmp_errpara[4], ierflg);
	  gMinuit->mnparm(5,  "exg width"    , para[5],  istep[2],  para[5]-sigma*tmp_errpara[5], para[5]+sigma*tmp_errpara[5], ierflg);
	  gMinuit->mnparm(7,  "bg exp turnon", para[7],  istep[1],  para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg);
	  gMinuit->mnparm(8,  "bg x offset  ", para[8],  tmp8    ,  para[8]-sigma*tmp_errpara[8], para[8]+sigma*tmp_errpara[8], ierflg);
	  gMinuit->mnparm(9,  "bg bend slope", para[9],  istep[0],  para[9]-sigma*tmp_errpara[9], para[9]+sigma*tmp_errpara[9], ierflg);      
	  float sigma10=5.;
	  if ( para[10]-sigma10*tmp_errpara[10] < 1. )// && i!=(ni-1))
	    gMinuit->mnparm(10, "bg bend power", para[10],  istep[0], 1.,  para[10]+sigma10*tmp_errpara[10], ierflg);      
	  else
	    gMinuit->mnparm(10, "bg bend power", para[10],  istep[0], para[10]-sigma10*tmp_errpara[10],  para[10]+sigma10*tmp_errpara[10], ierflg);      
// 	}else {
// 	  gMinuit->mnparm(2,  "constant"     , Para[0], TMath::Abs(Para[0]*0.0) ,  Para[0], Para[0], ierflg);
// 	  //gMinuit->mnparm(3,  "exp tail"     , Para[1], TMath::Abs(Para[1]*0.01) ,  Para[1]-sigma*Para_err[1], Para[1]+sigma*Para_err[1], ierflg); 
// 	  gMinuit->mnparm(3,  "exp tail"     , Para[1], TMath::Abs(Para[1]*0.0) ,  0.8    , 1.3    , ierflg);
// 	  gMinuit->mnparm(4,  "exg mean"     , Para[2], TMath::Abs(Para[2]*0.1) ,  0.5    , 1.0    , ierflg);
// 	  gMinuit->mnparm(5,  "exg width"    , Para[3], TMath::Abs(Para[3]*0.1) ,  0.25   , 0.5    , ierflg);
// 	  gMinuit->mnparm(6,  "constant"     , Para[4], TMath::Abs(Para[4]*0.0) ,  Para[4], Para[4], ierflg);
// 	  gMinuit->mnparm(7,  "bg exp turnon", Para[5], TMath::Abs(Para[5]*0.0) ,  -0.7   , -0.3   , ierflg);
// 	  gMinuit->mnparm(8,  "bg x offset  ", Para[6], TMath::Abs(Para[6]*0.0) ,  -0.15  , -0.05  , ierflg);
// 	  gMinuit->mnparm(9,  "bg bend slope", Para[7], TMath::Abs(Para[7]*0.1) ,  0.01   , 0.05   , ierflg);
// 	  gMinuit->mnparm(10, "bg bend power", Para[8], TMath::Abs(Para[8]*0.1) ,  0.5    , 1.5    , ierflg);
// 	}


	if( ptbin >=300 ) { 
	  gMinuit->mnparm(3,  "exp tail"  , 1.257281,  0.0,  para[1]-3.*tmp_errpara[1], para[1]+3.*tmp_errpara[1], ierflg);
	  gMinuit->mnparm(4,  "exg mean"  , 0.856906,  0.0,  para[2]-3.*tmp_errpara[2], para[2]+3.*tmp_errpara[2], ierflg);
	  gMinuit->mnparm(5,  "exg width" , 0.320847,  0.0,  para[3]-3.*tmp_errpara[3], para[3]+3.*tmp_errpara[3], ierflg);
	}      

    }else{	

	sigma=10.;
	if ( i==0 ) { para[10] = bkg_bend_power; tmp_errpara[10] = 0.3; }
 	if ( i==(ni-1) ) { sigma=3.;istep[1]=istep[4]=0.; } //test of not changing signal template
     	if ( i==(ni-1) ) { istep[4]=0.;}

   	if ( ptbin==21 && i==(ni-1) ) { sigma=20.;}
  	if ( ptbin==23 && i==0 ) { sigma=5.;}
  	if ( ptbin==23 && i==(ni-1) ) { sigma=10.;}
	if ( ptbin<30 && ptbin>21 && i==1 ){ istep[1]=0.; istep[3]=0.01; }
 	if ( ptbin<30 && ptbin>21 && i==3 ){ istep[1]=0.01; istep[3]=0.0; }
	if ( ptbin==26 && i==1 ) { para[7] = -0.8; }
	if ( ptbin==26 && i==(ni-1) ) { sigma=10.; }
  	if ( ptbin==30 && i==(ni-1) ) { sigma=10.; }
 	if ( ptbin==35) {para[7] = -0.75;}
 	if ( ptbin==40 && i==0) {para[7] = -0.65; para[10] = 2.;}
	if ( ptbin==45 && i==(ni-1) ) {sigma=5.;}
	if ( ptbin==85 && i==(ni-1) ) {sigma=10.; istep[4]=0.01;}
	if (ptbin >= 85 ) { para[10] = bkg_bend_power; tmp_errpara[10] = 1.; }

	if ( ptbin==120 ) { para[7] = -0.615255; istep[1]=0.;}

	
//     	if ( ptbin==120 && i==0 ) { 
// 	  para[3] = 1.446454; para[4]=-0.016373; para[5]=0.163238;
// 	  istep[2]=istep[3]=istep[4]=0.; sigma=5.; tmp_errpara[10]=0.2;
// 	}
//     	if ( ptbin==120 && i==(ni-1) ) { istep[2]=istep[3]=istep[4]=0.; sigma=5.;}

	gMinuit->mnparm(0,  "Signal yield"  ,   para[0],  1., para[0]-100.*tmp_errpara[0], para[0]+100.*tmp_errpara[0], ierflg);
	gMinuit->mnparm(1,  "background yield", para[1],  1., para[1]-100.*tmp_errpara[1], para[1]+100.*tmp_errpara[1], ierflg);
	gMinuit->mnparm(2,  "constant"     , para[2],  0.,  para[2], para[2] , ierflg);
	gMinuit->mnparm(6,  "constant"     , para[6],  0.,  para[6], para[6], ierflg);	
	gMinuit->mnparm(3,  "exp tail"     , para[3],  istep[4],  para[3]-sigma*tmp_errpara[3], para[3]+sigma*tmp_errpara[3], ierflg);
	gMinuit->mnparm(4,  "exg mean"     , para[4],  istep[3],  para[4]-sigma*tmp_errpara[4], para[4]+sigma*tmp_errpara[4], ierflg);
	gMinuit->mnparm(5,  "exg width"    , para[5],  istep[2],  para[5]-sigma*tmp_errpara[5], para[5]+sigma*tmp_errpara[5], ierflg);
	gMinuit->mnparm(7,  "bg exp turnon", para[7],  istep[1],  para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg);
	gMinuit->mnparm(8,  "bg x offset  ", para[8],  0.00,      para[8]-sigma*tmp_errpara[8], para[8]+sigma*tmp_errpara[8], ierflg);
	gMinuit->mnparm(9,  "bg bend slope", para[9],  istep[0],  para[9]-sigma*tmp_errpara[9], para[9]+sigma*tmp_errpara[9], ierflg);	
  
	float minerr=1.;
	//if ( tmp_errpara[10] > 0.5) tmp_errpara[10] = 0.5;
	float sigma10=5.;
	if ( para[10]-sigma10*tmp_errpara[10] < 1. ) 
	  gMinuit->mnparm(10, "bg bend power", para[10],  istep[0], minerr,  para[10]+sigma10*tmp_errpara[10], ierflg);
	else 
	  gMinuit->mnparm(10, "bg bend power", para[10],  istep[0], para[10]-sigma10*tmp_errpara[10],  para[10]+sigma10*tmp_errpara[10], ierflg);

      }
      printf(" ************ \n");
      printf("  do %d th fit  \n", i);
      if(i==5 && dataFile.find("toy")    != std::string::npos)
	{
	  cout << "dataResult = " << dataResult << "\t dataErr = " << dataErr << endl;
	  // fixed turn on at +- 1 sigma
	  gMinuit->mnparm(7,  "bg exp turnon", dataResult-(float)shift*dataErr,  0.00,  para[7]-sigma*tmp_errpara[7], para[7]+sigma*tmp_errpara[7], ierflg);

	}
      else if(dataFile.find("toy")    == std::string::npos)
	{
	  dataResult = para[7];
	  dataErr    = tmp_errpara[7];
	}
      arglist[0] = 500; // number of iteration
      gMinuit->mnexcm("MIGRAD", arglist ,1,ierflg);      
      if ( ierflg != 0 ) {
  	printf("fit failed at %d iteration \n", i);
  	c1->cd();	c1->Draw();  	hdata->Draw("phe");
  	return fitted;
      }
    }
  }
 
  Double_t amin,edm,errdef; 
  if ( ierflg == 0 ) {
    for(int j=0; j<=NPAR-1;j++) {
      gMinuit->GetParameter(j, para[j],errpara[j]);
      info.push_back(para[j]);
      info_err.push_back(errpara[j]);
      printf("Parameter  %d = %f +- %f\n",j,para[j],errpara[j]);	
    }
    para[NPAR] = dataColl.size();
    printf(" fitted yield %2.3f \n", (para[0]+para[1])/ndata );
    
    info.push_back(sigColl.size());
    
    for(int j=0; j<=NPAR-1;j++) {
      tmp_errpara[j] = errpara[j];
      if( tmp_errpara[j] == 0. ) tmp_errpara[j] = par[j]*.1;      
    }
    //do minos if fit sucessed.

  }
  if (ierflg != 0 )  {
    printf(" *********** Fit failed! ************\n");
    gMinuit->GetParameter(0, para[0],errpara[0]);
    gMinuit->GetParameter(1, para[1],errpara[1]);
    para[0]=0.; errpara[0]=0.;

    c1->cd();
    c1->Draw();  
    //gPad->SetLogy();
    hdata->SetNdivisions(505,"XY");
    hdata->SetXTitle("comb. ISO (GeV)");
    hdata->SetYTitle("Entries");
    hdata->SetTitle("");
    hdata->SetMarkerStyle(8);
    hdata->SetMinimum(0.);
    if ( hdata->GetMaximum()<10.) hdata->SetMaximum(15.);
    else hdata->SetMaximum(hdata->GetMaximum()*1.25);
    if ( strcmp(EBEE,"EE")==0 &&ptbin == 15 ) hdata->SetMaximum(hdata->GetMaximum()*1.25);
   
    hdata->Draw("phe");  

    return fitted;    
  }

  
  // Print results
//   Double_t amin,edm,errdef;
  Int_t nvpar,nparx,icstat;
  gMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat);
  gMinuit->mnprin(1,amin);  
  gMinuit->mnmatu(1);
  printf(" ========= happy ending !? =========================== \n");
  
  printf("FCN =  %3.3f \n", amin);

  //use new PDF form
  double tmppar[12];
  for(int ii=0; ii<9; ii++){
    tmppar[ii] = para[ii+2];
    fmcsigfit->SetParameter(ii,tmppar[ii]);
    fbkgfit->SetParameter(ii,tmppar[ii]);
  }

  c101->cd(1);
  
  //fmcsigfit->SetParameters(tmppar);
  //fmcsigfit->SetParameter(2,0.1);
  //fmcsigfit->SetLineStyle(2);

  fmcsigfit->Draw("same");
  c101->cd(2);

  fbkgfit->SetParameter(4,fbkgfit->GetParameter(4)*fmcbkg->Integral(-1., 20.)/fbkgfit->Integral(-1., 20.));
  fbkgfit->Draw("same");

  char fname[100];
  sprintf(fname,"plots/template_Ifit%s_%d.pdf",EBEE,ptbin);
  c101->SaveAs(fname);


  f11->SetParameters(tmppar);
  SigPDFnorm = f11->Integral(-1., 20.);
  f12->SetParameters(tmppar);
  BkgPDFnorm = f12->Integral(-1., 20.);


  // plot
  c1->cd();
  c1->Draw();  
  //gPad->SetLogy();
   hdata->SetNdivisions(505,"XY");
   hdata->SetXTitle("comb. ISO (GeV)");
   hdata->SetYTitle("Entries");
   hdata->SetTitle("");
   hdata->SetMarkerStyle(8);
   hdata->SetMinimum(0.);
   if ( hdata->GetMaximum()<10.) hdata->SetMaximum(15.);
   else hdata->SetMaximum(hdata->GetMaximum()*1.5);
   if ( strcmp(EBEE,"EE")==0 &&ptbin == 15 ) hdata->SetMaximum(hdata->GetMaximum()*1.2);

   hdata->Draw("p e ");

  f11->SetParameter(0, para[0]*f11->GetParameter(0)/f11->Integral(-1., 20.)*hdata->GetBinWidth(2));
//   f11->SetFillColor(5);
  f11->SetLineColor(4);
  //f11->SetFillColor(603);
  f11->SetLineWidth(2);
//   f11->SetFillStyle(3001);
  f11->Draw("same");

  f12->SetParameter(4, para[1]*f12->GetParameter(4)/f12->Integral(-1., 20.)*hdata->GetBinWidth(2));
//   f12->SetFillColor(8);
  f12->SetLineColor(2);
  //f12->SetFillColor(603);
  f12->SetLineWidth(2);
//   f12->SetFillStyle(3013);
  f12->Draw("same");

  TF1 *f13 = new TF1("f13",sum_norm, -1., 20 ,11);
  f13->SetNpx(10000);
  f13->SetParameters(f12->GetParameters());
  f13->SetParameter(0, para[0]*f11->GetParameter(0)/f11->Integral(-1., 20.)*hdata->GetBinWidth(2));
  f13->SetParameter(4, para[1]*f12->GetParameter(4)/f12->Integral(-1., 20.)*hdata->GetBinWidth(2));  
  f13->SetLineWidth(2);
  f13->SetLineColor(1);
  f13->Draw("same");
  f11->Draw("same");
  hdata->Draw("pe same");

//   cout << "The number of bins are: " << endl;
//   cout << "hdata nbins = " << hdata->GetNbinsX() << endl;
//   cout << "hsig nbins = " << hsig->GetNbinsX() << endl;
//   cout << "hbkg nbins = " << hbkg->GetNbinsX() << endl;

  // get chi2/NDF
  double chi2ForThisBin=0;
  int nbinForThisBin=0;
  chi2Nbins(f13, hdata, chi2ForThisBin, nbinForThisBin);
  for(int epar=0; epar < 11; epar++)
    {
//       cout << "f11 parameter " << epar << " = " << 
// 	f11->GetParameter(epar) << endl;
      FitPar[epar] = f11->GetParameter(epar);
    }

  for(int epar=0; epar < 11; epar++)
    {
//       cout << "f12 parameter " << epar << " = " << 
// 	f12->GetParameter(epar) << endl;
      FitPar[epar+11] = f12->GetParameter(epar);
    }

  for(int epar=0; epar < 11; epar++)
    {
//       cout << "f13 parameter " << epar << " = " << 
// 	f13->GetParameter(epar) << endl;
      FitPar[epar+22] = f13->GetParameter(epar);

    }

//   cout << "hdata integral = " << hdata->Integral() << endl;
//   cout << endl;

//   printf("fit area %3.2f; sig area %3.2f; bg area %3.2f\n", f13->Integral(-1., 20.)/hdata->GetBinWidth(2),  f11->Integral(-1., 20.)/hdata->GetBinWidth(2),f12->Integral(-1., 20.)/hdata->GetBinWidth(2));

//   for(int i=0; i<12; i++){
//     printf(" fit para %d = %4.3f \n", i, f13->GetParameter(i));
//   }

   TLegend *tleg = new TLegend(0.5, 0.7, 0.93, 0.92);
   char text[50];
   sprintf(text,"%s Pt %d ~ %.0f GeV",EBEE, ptbin, ptmax);
   tleg->SetHeader(text);
   tleg->SetFillColor(0);
   tleg->SetShadowColor(0);
   tleg->SetBorderSize(0);
   sprintf(text,"#chi^{2}/NDF = %.1f/%d",chi2ForThisBin,nbinForThisBin);
   tleg->AddEntry(hdata,text,"");
   sprintf(text,"Data %.1f events",hdata->Integral());
   tleg->AddEntry(hdata,text,"pl");
   sprintf(text,"Fitted %.1f events",para[0]+para[1]);//f13->Integral(-1., 20.)/hdata->GetBinWidth(2));
   tleg->AddEntry(f13,text,"l");
   sprintf(text,"SIG %.1f #pm %.1f events",para[0], errpara[0]);
   tleg->AddEntry(f11,text,"f");
   sprintf(text,"BKG %.1f #pm %.1f events",para[1], errpara[1]);
   tleg->AddEntry(f12,text,"f");
   tleg->Draw();


   gPad->RedrawAxis();

   printf("%s, ptbin %d, Data %.1f events \n",EBEE, ptbin, hdata->Integral());
   printf("Fitted %.1f (in 5GeV) %.1f events \n",para[0]+para[1],f13->Integral(-1.,5.));
   printf("SIG %.1f #pm %.1f events \n",para[0], errpara[0]);
   printf("SIG (in 5GeV) %.1f #pm %.1f events \n",f11->Integral(-1.,5.)/hdata->GetBinWidth(2), f11->Integral(-1.,5.)*errpara[0]/para[0]/hdata->GetBinWidth(2));
   printf("BKG %.1f #pm %.1f events \n",para[1], errpara[1]);
   printf("BKG (in 5GeV) %.1f #pm %.1f events \n",f12->Integral(-1.,5.)/hdata->GetBinWidth(2), f12->Integral(-1.,5.)*errpara[1]/para[1]/hdata->GetBinWidth(2));
   
   float purity = f11->Integral(-1.,5.)/hdata->GetBinWidth(2)/(f11->Integral(-1.,5.)/hdata->GetBinWidth(2)+f12->Integral(-1.,5.)/hdata->GetBinWidth(2));
   float purity_err = purity*errpara[0]/para[0];
   printf("Purity (in 5GeV) %.3f #pm %.3f  \n", purity, purity_err);


//   hsig->Scale(para[0]/hsig->Integral());
//   hbkg->Scale(para[1]/hbkg->Integral());
//   hbkg->Add(hsig);

//   hsig->SetLineColor(1);
//   hsig->SetFillColor(5);
//   hsig->SetFillStyle(3001);

//   hbkg->SetLineWidth(2);


//   hsig->Draw("same");
//   hbkg->Draw("same");


  sprintf(fname,"plots/unbinned_free_Ifit%s_%d.pdf",EBEE,ptbin);
  if (para_index>0) sprintf(fname,"plots/unbinned_Ifit%s_%d_para%d_sigma%1.0f.pdf",EBEE,ptbin,para_index,para_sigma);
  if(Opt_SavePDF == 1) {
    c1->SaveAs(fname);


  } else {

   c1->Close();
   c10->Close();
   c101->Close();
   c11->Close();

  }

  printf("----- fit results with signal projection   ----------- \n");

  fitted[0] = para[0];
  fitted[1] = errpara[0];
  fitted[2] = para[1];
  fitted[3] = errpara[1];
  fitted[4] = f11->Integral(-1.,5.)/hdata->GetBinWidth(2);
  fitted[5] = f11->Integral(-1.,5.)*errpara[0]/para[0]/hdata->GetBinWidth(2);

  return fitted;
}
Beispiel #28
0
void plot_golfcourse(){

  // TFile *fFREQ=new TFile("higgsCombineHZZ2L2Q_FREQ.20111127MMv2.root","READ");
 TFile *fFREQ=new TFile("higgsCombineHZZ2L2Q_FREQ.20111129MMv2.root","READ");

  TTree *t=(TTree*)fFREQ->Get("limit");

  double mh,limit;
  float quant;
  t->SetBranchAddress("mh",&mh);
  t->SetBranchAddress("limit",&limit);
  t->SetBranchAddress("quantileExpected",&quant);

  vector<double> v_mh, v_median,v_68l,v_68h,v_95l,v_95h, v_obs;

  for(int i=0;i<t->GetEntries();i++){
    t->GetEntry(i);
    //  cout<<"i "<<i<<flush<<"  m = "<<mh<<endl;
   
   
    // if(mh==600)cout<<"$$$$$$$$$ TREE 600 $$$$$$$$$$$$$$"<<endl;
    if(quant>-1.01&&quant<-0.99){
      v_obs.push_back(limit);
      v_mh.push_back(mh);
    }
    else if(quant>0.02&&quant<0.03)v_95l.push_back(limit);
    else if(quant>0.15&&quant<0.17)v_68l.push_back(limit);
    else if(quant>0.49&&quant<0.51)v_median.push_back(limit);
    else if(quant>0.83&&quant<0.85)v_68h.push_back(limit);
    else if(quant>0.965&&quant<0.98)v_95h.push_back(limit);
    else {cout<<"Error! Quantile =  "<<quant<<endl;}
  }
  cout<<"Out of the loop !"<<endl;

  //read in theoretical values from text files
  ifstream xsect_file("./xsect_higgs_173points_new.txt",ios::in);
  if (! xsect_file.is_open()){ cout<<"Failed to open file with xsections"<<endl;}
  float mHxs, CSgg, CSgg_p, CSgg_m, CSpdfgg_p,CSpdfgg_m,CSvbf, CSvbf_p, CSvbf_m,CSpdfvbf_p,CSpdfvbf_m, 
    Gamma, BRHZZ, BRZZ2l2q;

  vector<float> v_mhxs, v_ggxs,v_vbfxs, v_ggtoterrh,v_ggtoterrl,
                v_vbftoterrh,v_vbftoterrl, v_gamma, v_brhzz, v_brzz2l2q;
  while(xsect_file.good()){
    xsect_file >> mHxs>> CSgg>> CSgg_p >> CSgg_m >>  CSpdfgg_p>> CSpdfgg_m>> CSvbf >> CSvbf_p >> CSvbf_m >>  CSpdfvbf_p>>CSpdfvbf_m>>Gamma >> BRHZZ >> BRZZ2l2q;
    // if(mHxs==600)cout<<"~~~~~ 600 theor ~~~~~~~~~~~~~"<<endl;
    v_mhxs.push_back(mHxs);
    v_ggxs.push_back(CSgg*BRHZZ);//*BRZZ2l2q
    v_vbfxs.push_back(CSvbf);
    v_brhzz.push_back( BRHZZ);
    v_brzz2l2q.push_back(BRZZ2l2q);
    //sum up linearly theor errors    
    v_ggtoterrh.push_back(1.0+CSgg_p+CSpdfgg_p);
    v_ggtoterrl.push_back(1.0+CSgg_m+CSpdfgg_m);
  }
  cout<<"Size of theor "<<v_mhxs.size()<<flush;


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

  const int nMass= v_mh.size();
  cout<<"SIZE SIZE SIZE "<<nMass<<endl;
  double mass[nMass],mass1[nMass],obs_lim_cls[nMass]; 
  double medianD[nMass];
  double up68err[nMass],down68err[nMass],up95err[nMass],down95err[nMass];
  double ggxs[nMass], ggxs_uperr[nMass], ggxs_downerr[nMass];

  int nMassEff=0,nMassEff1=0;
  int nM95=0;
  double mass95[nMass],median95[nMass];
  int nexcluded=0;
  bool excl; 
 for(int im=0;im<nMass;im++){
    // cout<<"Array "<<im<<flush<<"  m = "<<v_mh.at(im)<<flush;
    //protection against messed up jobs

   excl=false;
   if(v_68h.at(im)>=v_95h.at(im) || v_68l.at(im)<=v_95l.at(im) ){
     cout<<"Point at M = "<<v_mh.at(im) <<" excluded"<<endl;
     nexcluded++;
     //      continue;
     excl=true; 
   }

   if(im%2==1)excl=true;

    //search for right index in theor vectors
    bool found=false;
    int indtmp=0,ind=-1;
    while(!found){
      if(v_mhxs.at(indtmp)==v_mh.at(im)){found=true;ind=indtmp;}
      indtmp++;
      if(indtmp==v_mhxs.size()){
	cout<<"m="<<v_mh.at(im)<<" NOT found in theor matrix."<<endl;
	break;
      }
    }//end while    

    // if(v_mh.at(im)<226.0)found=false;

    if(!found){
      //  cout<<"(2) m="<<v_mh.at(im)<<" NOT found in theor matrix."<<endl;
      continue;
    }

    //cout<<"  Found mass, xs=  "<<v_ggxs.at(ind)<<endl;
    double xs=double(v_ggxs.at(ind));

    mass[nMassEff]=v_mh.at(im);
    //if( mass[nMassEff]==600.0)cout<<"=============> 600 !!!"<<endl;
    obs_lim_cls[nMassEff]=v_obs.at(im);
    nMassEff++;
    if(!excl){
    mass1[nMassEff1]=v_mh.at(im);
    medianD[nMassEff1]=v_median.at(im);
    up68err[nMassEff1]=(v_68h.at(im)-v_median.at(im));
    down68err[nMassEff1]=(v_median.at(im)-v_68l.at(im));
   
    ggxs[nMassEff1]=xs;
    ggxs_uperr[nMassEff1]=double( v_ggtoterrh.at(ind))*xs -xs ;
    ggxs_downerr[nMassEff1]=xs - double( v_ggtoterrl.at(ind))*xs;
    nMassEff1++;
    

    

    bool skip95= false;//
    skip95=v_mh.at(im)==204||v_mh.at(im)==208||v_mh.at(im)==212||v_mh.at(im)==214|| v_mh.at(im)==232 || v_mh.at(im)==240  || v_mh.at(im)==240 || v_mh.at(im)==244 || v_mh.at(im)==252 || v_mh.at(im)==264 || v_mh.at(im)==272 || v_mh.at(im)==288 ;
    //  skip95=false;
    
    if(skip95 )continue;
    mass95[nM95]=v_mh.at(im);
    median95[nM95]=v_median.at(im);
    up95err[nM95]=(v_95h.at(im)-v_median.at(im));
    down95err[nM95]=(v_median.at(im)-v_95l.at(im));
    nM95++;
    }

  }
  cout<<"Excluded "<<nexcluded<<" sick mass points."<<endl;

 


  //  cout<<"Working on TGraph"<<endl;
  TGraph *grobslim_cls=new TGraphAsymmErrors(nMassEff,mass,obs_lim_cls);
  grobslim_cls->SetName("LimitObservedCLs");
  TGraph *grmedian_cls=new TGraphAsymmErrors(nMassEff1,mass1,medianD);
  grmedian_cls->SetName("LimitExpectedCLs");
  TGraphAsymmErrors *gr68_cls=new TGraphAsymmErrors(nMassEff1,mass1,medianD,0,0,down68err,up68err);
  gr68_cls->SetName("Limit68CLs");
  TGraphAsymmErrors *gr95_cls=new TGraphAsymmErrors(nM95,mass95,median95,0,0,down95err,up95err);
  gr95_cls->SetName("Limit95CLs");

  TGraphAsymmErrors *grthSM=new TGraphAsymmErrors(nMassEff,mass,ggxs,0,0,ggxs_downerr,ggxs_uperr);//ggxs_downerr,ggxs_uperr);
  grthSM->SetName("SMXSection");

  // cout<<"Plotting"<<endl;
  TCanvas *cMCMC=new TCanvas("c_lim_MCMC","canvas with limits for MCMC",800,800);
  cMCMC->cd();
  cMCMC->SetGridx(1);
  cMCMC->SetGridy(1);
  // draw a frame to define the range
  TH1F *hr = cMCMC->DrawFrame(190.0,0.0,610.0,6.0,"frame1");
  hr->SetXTitle("M_{H} [GeV]");
  hr->SetYTitle("#sigma_{95%} / #sigma_{SM}");// #rightarrow 2l2q
  // cMCMC->GetFrame()->SetFillColor(21);
  //cMCMC->GetFrame()->SetBorderSize(12);
  
  gr95_cls->SetFillColor(kYellow);
  gr95_cls->SetFillStyle(1001);//solid
  gr95_cls->GetXaxis()->SetTitle("M_{H} [GeV]");
  gr95_cls->GetYaxis()->SetTitle("#sigma_{95%} / #sigma_{SM}");// #rightarrow 2l2q
  gr95_cls->GetXaxis()->SetRangeUser(200.0,600.0);
  
  gr95_cls->Draw("3");
  
  gr68_cls->SetFillColor(kGreen);
  gr68_cls->SetFillStyle(1001);//solid
  gr68_cls->Draw("3same");
  grmedian_cls->GetXaxis()->SetTitle("M_{H} [GeV]");
  grmedian_cls->GetYaxis()->SetTitle("#sigma_{95%} / #sigma_{SM}");// #rightarrow 2l2q
  grmedian_cls->SetMarkerStyle(24);//25=hollow squre
  grmedian_cls->SetMarkerColor(kBlack);
  grmedian_cls->SetLineStyle(2);
  grmedian_cls->SetLineWidth(2);
  grmedian_cls->SetMinimum(0.0);
  grmedian_cls->SetMaximum(8.0);
 
  grobslim_cls->SetMarkerColor(kBlack);
  grobslim_cls->SetMarkerStyle(21);//24=hollow circle
  //  grobslim_cls->SetMarkerSize(1.5);
  grobslim_cls->SetLineStyle(1);
  grobslim_cls->SetLineWidth(2);

  
  grthSM->SetLineColor(kRed);
  grthSM->SetLineWidth(2);
  grthSM->SetFillColor(kRed);
  grthSM->SetFillStyle(3344);
  //  grthSM->Draw("L3same");

  grmedian_cls->Draw("L");
  grobslim_cls->Draw("LP");

  TLine *l1=new TLine();
  l1->SetLineStyle(1);
  l1->SetLineWidth(2.0);
  l1->SetLineColor(kRed);
  l1->DrawLine(210.0,1.0,610.0,1.0);
  cMCMC->Update();
  // cMCMC->RedrawAxis("");
  gPad->RedrawAxis("");
  // hr->GetYaxis()->DrawClone();
  cMCMC->Update();
  


  //more graphics
   TLegend *leg = new TLegend(.35,.71,.90,.90);

   leg->SetFillColor(0);
   leg->SetShadowColor(0);
   leg->SetTextFont(42);
   leg->SetTextSize(0.03);
   //   leg->SetBorderMode(0);
   leg->AddEntry(grobslim_cls, "CL_{S} Observed", "LP");
   leg->AddEntry(grmedian_cls, "CL_{S} Expected", "L");
   leg->AddEntry(gr68_cls, "CL_{S} Expected #pm 1#sigma", "LF");
   leg->AddEntry(gr95_cls, "CL_{S} Expected #pm 2#sigma", "LF");
   leg->AddEntry(grthSM, "SM", "L");// #rightarrow 2l2q
    leg->Draw();
   

   TLatex * latex = new TLatex();
   latex->SetNDC();
   latex->SetTextSize(0.04);
   latex->SetTextAlign(31);
   latex->SetTextAlign(11); // align left 
   latex->DrawLatex(0.18, 0.96, "CMS preliminary 2011");
   latex->DrawLatex(0.60,0.96,Form("%.1f fb^{-1} at #sqrt{s} = 7 TeV",intLumi));
   

 /*
 leg->SetFillColor(0);
 leg->SetShadowColor(0);
 leg->SetTextFont(42);
 leg->SetTextSize(0.05);
 */
   
   TLine *l1b=new TLine();
   l1b->SetLineStyle(1);
   l1b->SetLineWidth(2.0);
   l1b->SetLineColor(kRed);
   //l1b->DrawLine(200.0,1.0,600.0,1.0);
   cMCMC->Update();
   
   
   // cMCMC->RedrawAxis("");
   gPad->RedrawAxis("");
   // hr->GetYaxis()->DrawClone();
   cMCMC->Update();
   // cMCMC->SaveAs("ClsLimit_1fb.eps");
   // cMCMC->SaveAs("ClsLimit_1fb.png");
   
}//end main
Beispiel #29
0
//void plot_Asymptotic(string outputname)
//void plot_Asymptotic()
TGraphAsymmErrors *  plot_Asymptotic(TString dir_path ,TGraphAsymmErrors *grmedian_cls ) 
//void plot_Asymptotic( TGraphAsymmErrors *grmedian_cls )
{

string outputname = "counting";

  bool useNewStyle = true;
  if (useNewStyle)  setFPStyle();
//  gROOT->LoadMacro("CMS_lumi.C");

  TFile *fFREQ[nXm];
  TTree *t[nXm];
//  int Xmass[nXm]={800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000};  
  int Xmass[nXm]={800,1000,1200,1400,1600,1800,2000,2500,3000,3500,4000};
  //int Xmass[nXm]={800,900,1100,1400,1700,1900};  
  vector<double> v_mh, v_median, v_68l, v_68h, v_95l, v_95h, v_obs;
 

  for(int n=0;n<nXm;n++)
  {
    char limitfile[200];



//    if(outputname.find("counting")!= std::string::npos) sprintf(limitfile,"Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/higgsCombineTest.Asymptotic.mH%d.root",Xmass[n]);


    if(outputname.find("counting")!= std::string::npos) sprintf(limitfile,"higgsCombineTest.Asymptotic.mH%d.root",Xmass[n]);


//    const string dirLimitFile = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/";

    TString LimitFile = limitfile;
    LimitFile = dir_path  + LimitFile;
//    LimitFile = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/"  + LimitFile;
//    limitfile = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/"  + limitfile;

//    limitfile = dirLimitFile + limitfile;


//    fFREQ[n] = new TFile(limitfile, "READ");
    fFREQ[n] = new TFile( LimitFile , "READ");
    cout<<" Read limit file: "<<limitfile<<endl;
    t[n] = (TTree*)fFREQ[n]->Get("limit");
  
    double mh, limit;
    float quant;
    t[n]->SetBranchAddress("mh", &mh);
    t[n]->SetBranchAddress("limit", &limit);
    t[n]->SetBranchAddress("quantileExpected", &quant);
  
    
    
    //int iMH = 0;
    //while (iMH < n) {
 
      for (int i = 0; i < t[n]->GetEntries(); i++) {

        t[n]->GetEntry(i);

        cout<<" quant : "<<quant<<" limit : " <<limit<<endl;
        /// Map: mh --> observed, 95low, 68low, expected, 68hi, 95hi, xsec
        if (quant > -1.01 && quant < -0.99) {
        v_obs.push_back(limit);
        } 
        else if (quant > 0.02 && quant < 0.03) {
	v_95l.push_back(limit);
        }
        else if (quant > 0.15 && quant < 0.17) {
	v_68l.push_back(limit);
        }
        else if (quant > 0.49 && quant < 0.51) {
	v_median.push_back(limit);
        v_mh.push_back(mh);
        }
        else if (quant > 0.83 && quant < 0.85) {
	v_68h.push_back(limit);
        }
        else if (quant > 0.965 && quant < 0.98) {
	v_95h.push_back(limit);
        }
        else {
        cout << "Error! Quantile =  " << quant << endl;
        }
     }
      //   iMH++;
      // }//end while loop

  }//file loop

//  string xsect_file_th = dirXSect + "13TeV_xsec_Zhllbb.txt";
  string xsect_file_th = dirXSect + "13TeV_xsec_Zh.txt";

  ifstream xsect_file(xsect_file_th.c_str(), ios::in);
  if (! xsect_file.is_open()) {
    cout << "Failed to open file with xsections: " << xsect_file_th << endl;
  }

  float mH, CS;
  vector<float> v_mhxs, v_xs, v_toterrh, v_toterrl;
  while (xsect_file.good()) {
    xsect_file >> mH >> CS;
  
    v_mhxs.push_back(mH);
    v_xs.push_back(CS);//*BRZZ2l2q (multyply by BRZZ2l2q only if exp rates in cards are for process X->ZZ->2l2q !)

    //unavailable theory errors for graviton

    float tot_err_p = 0.0;
    float tot_err_m = 0.0;

    v_toterrh.push_back(1.0 + (tot_err_p));
    v_toterrl.push_back(1.0 - (tot_err_m));
  }
  cout << "Size of theory xsects vector" << v_mhxs.size() << endl;
  xsect_file.close();
  ///////////////////////////
  // END THEORY INPUT PART //
  ///////////////////////////


  /// Here we multiply the limits in terms of signal strength by the cross-section.
  /// There are also some hooks to exclude sick mass points.
  
  double mass[nXm], obs_lim_cls[nXm];
  double medianD[nXm];
  double up68err[nXm], down68err[nXm], up95err[nXm], down95err[nXm];
  double xs[nXm], xs_uperr[nXm], xs_downerr[nXm];
  double xs10[nXm], xs10_uperr[nXm], xs10_downerr[nXm];
  int nMassEff = 0;
  
  for (int im = 0; im < nXm; im++) {


    double fl_xs = double(v_xs.at(im)); //*1000.0
    double fl_xs10 = 0;//double(v_xs10.at(ind)); //*1000.0
    fl_xs = (fl_xs);
    fl_xs10 = (fl_xs10);

      mass[nMassEff] = Xmass[im];

    /// This is the part where we multiply the limits in terms of signal strength
    /// by the cross-section, in order to have limits in picobarns.
    //std::cerr << mass[nMassEff] << ":" << v_obs.at(im) << std::endl;
      obs_lim_cls[nMassEff] = v_obs.at(im) * fl_xs;
 
      
      medianD[nMassEff] = v_median.at(im) * fl_xs;
      up68err[nMassEff] = (v_68h.at(im) - v_median.at(im)) * fl_xs;
      down68err[nMassEff] = (v_median.at(im) - v_68l.at(im)) * fl_xs;

      //scale factor 100 for making the xsect visible
      xs[nMassEff] = fl_xs; //*100.0;
      xs_uperr[nMassEff] = double(v_toterrh.at(im)) * xs[nMassEff] - xs[nMassEff];
      xs_downerr[nMassEff] =  xs[nMassEff] - double(v_toterrl.at(im)) * xs[nMassEff];

      xs10[nMassEff] = fl_xs10; //*100.0;
      xs10_uperr[nMassEff] = double(v_toterrh.at(im)) * xs10[nMassEff] - xs10[nMassEff];
      xs10_downerr[nMassEff] =  xs10[nMassEff] - double(v_toterrl.at(im)) * xs10[nMassEff];
     
      up95err[nMassEff] = (v_95h.at(im) - v_median.at(im)) * fl_xs;
      down95err[nMassEff] = (v_median.at(im) - v_95l.at(im)) * fl_xs;
    
      cout<<"fl_xs:"<<fl_xs<<" v_obs"<<v_obs.at(im)<<" obs_lim_cls: "<<obs_lim_cls[nMassEff]  <<medianD[nMassEff] <<" mass: "<<mass[nMassEff]<<endl;
 
      nMassEff++;
    
    
  }//end loop over im (mass points)



  /// The TGraphs themselves.

  //cout<<"Working on TGraph"<<endl;
  TGraphAsymmErrors *grobslim_cls = new TGraphAsymmErrors(nMassEff, mass, obs_lim_cls);
  grobslim_cls->SetName("LimitObservedCLs");

//  TGraphAsymmErrors *grmedian_cls = new TGraphAsymmErrors(nMassEff, mass, medianD);
  grmedian_cls = new TGraphAsymmErrors(nMassEff, mass, medianD);
  grmedian_cls->SetName("LimitExpectedCLs");
  TGraphAsymmErrors *gr68_cls = new TGraphAsymmErrors(nMassEff, mass, medianD, 0, 0, down68err, up68err);
  gr68_cls->SetName("Limit68CLs");
  TGraphAsymmErrors *gr95_cls = new TGraphAsymmErrors(nMassEff, mass, medianD, 0, 0, down95err, up95err);
  gr95_cls->SetName("Limit95CLs");

  // TGraphAsymmErrors *grthSM=new TGraphAsymmErrors(nMassEff1,mass1,xs,0,0,0,0);//xs_downerr,xs_uperr);
  TGraph *grthSM=new TGraph(nMassEff,mass,xs);//xs_downerr,xs_uperr);

  /// For the time being we have to do it like this, given that
  /// the cards and the limits were made with the old, wrong xsects.
  // TGraph *grthSM10 = new TGraph(35);
//   grthSM10->SetPoint(0, 600, 7.1185E-03);
//   grthSM10->SetPoint(1, 650, 4.1893E-03);
//   grthSM10->SetPoint(2, 700, 2.5592E-03);
//   grthSM10->SetPoint(3, 750, 1.6182E-03);
//   grthSM10->SetPoint(4, 800, 1.0564E-03);
//   grthSM10->SetPoint(5, 850, 7.0295E-04);
//   grthSM10->SetPoint(6, 900, 4.7877E-04);
//   grthSM10->SetPoint(7, 950, 3.3017E-04);
//   grthSM10->SetPoint(8, 1000, 2.3212E-04);
//   grthSM10->SetPoint(9, 1050, 1.6574E-04);
//   grthSM10->SetPoint(10, 1100, 1.1917E-04);
//   grthSM10->SetPoint(11, 1150, 8.6629E-05);
//   grthSM10->SetPoint(12, 1200, 6.3987E-05);
//   grthSM10->SetPoint(13, 1250, 4.7353E-05);
//   grthSM10->SetPoint(14, 1300, 3.5511E-05);
//   grthSM10->SetPoint(15, 1350, 2.6631E-05);
//   grthSM10->SetPoint(16, 1400, 2.0199E-05);
//   grthSM10->SetPoint(17, 1450, 1.5333E-05);
//   grthSM10->SetPoint(18, 1500, 1.1758E-05);
//   grthSM10->SetPoint(19, 1550, 9.0363E-06);
//   grthSM10->SetPoint(20, 1600, 6.9870E-06);
//   grthSM10->SetPoint(21, 1650, 5.4316E-06);
//   grthSM10->SetPoint(22, 1700, 4.2252E-06);
//   grthSM10->SetPoint(23, 1750, 3.3172E-06);
//   grthSM10->SetPoint(24, 1800, 2.6083E-06);
//   grthSM10->SetPoint(25, 1850, 2.0499E-06);
//   grthSM10->SetPoint(26, 1900, 1.6186E-06);
//   grthSM10->SetPoint(27, 1950, 1.2799E-06);
//   grthSM10->SetPoint(28, 2000, 1.0205E-06);
//   grthSM10->SetPoint(29, 2050, 8.0867E-07);
//   grthSM10->SetPoint(30, 2100, 6.4555E-07);
//   grthSM10->SetPoint(31, 2150, 5.1755E-07);
//   grthSM10->SetPoint(32, 2200, 4.1408E-07);
//   grthSM10->SetPoint(33, 2250, 3.3170E-07);
//   grthSM10->SetPoint(34, 2300, 2.6637E-07);
//   grthSM10->SetPoint(35, 2350, 2.1366E-07);
//   grthSM10->SetPoint(36, 2400, 1.7285E-07);
//   grthSM10->SetPoint(37, 2450, 1.3896E-07);
//   grthSM10->SetPoint(38, 2500, 1.1238E-07);

//   if (!isZZChannel) {
//     grthSM10->SetPoint(0, 800, 2.0523E-03);
//     grthSM10->SetPoint(1, 850, 1.3726E-03);
//     grthSM10->SetPoint(2, 900, 9.3786E-04);
//     grthSM10->SetPoint(3, 950, 6.4928E-04);
//     grthSM10->SetPoint(4, 1000, 4.5618E-04);
//     grthSM10->SetPoint(5, 1050, 3.2571E-04);
//     grthSM10->SetPoint(6, 1100, 2.3543E-04);
//     grthSM10->SetPoint(7, 1150, 1.7157E-04);
//     grthSM10->SetPoint(8, 1200, 1.2611E-04);
//     grthSM10->SetPoint(9, 1250, 9.3461E-05);
//     grthSM10->SetPoint(10, 1300, 6.9899E-05);
//     grthSM10->SetPoint(11, 1350, 5.2749E-05);
//     grthSM10->SetPoint(12, 1400, 4.0048E-05);
//     grthSM10->SetPoint(13, 1450, 3.0363E-05);
//     grthSM10->SetPoint(14, 1500, 2.3324E-05);
//     grthSM10->SetPoint(15, 1550, 1.8008E-05);
//     grthSM10->SetPoint(16, 1600, 1.3876E-05);
//     grthSM10->SetPoint(17, 1650, 1.0812E-05);
//     grthSM10->SetPoint(18, 1700, 8.4385E-06);
//     grthSM10->SetPoint(19, 1750, 6.5972E-06);
//     grthSM10->SetPoint(20, 1800, 5.1608E-06);
//     grthSM10->SetPoint(21, 1850, 4.0824E-06);
//     grthSM10->SetPoint(22, 1900, 3.2292E-06);
//     grthSM10->SetPoint(23, 1950, 2.5502E-06);
//     grthSM10->SetPoint(24, 2000, 2.0281E-06);
//     grthSM10->SetPoint(25, 2050, 1.6179E-06);
//     grthSM10->SetPoint(26, 2100, 1.2893E-06);
//     grthSM10->SetPoint(27, 2150, 1.0313E-06);
//     grthSM10->SetPoint(28, 2200, 8.2293E-07);
//     grthSM10->SetPoint(29, 2250, 6.6187E-07);
//     grthSM10->SetPoint(30, 2300, 5.3108E-07);
//     grthSM10->SetPoint(31, 2350, 4.2755E-07);
//     grthSM10->SetPoint(32, 2400, 3.4315E-07);
//     grthSM10->SetPoint(33, 2450, 2.7803E-07);
//     grthSM10->SetPoint(34, 2500, 2.2432E-07);
//   }
  grthSM->SetName("SMXSection");


  // TGraphAsymmErrors *grthSM10=new TGraphAsymmErrors(nMassEff1,mass1,xs10,0,0,0,0);
  TGraph *grthSM10=new TGraph(nMassEff,mass,xs10);
  // TGraph *grthSM = new TGraph(35);
//   grthSM->SetPoint(0, 600, 4.4387E-02);
//   grthSM->SetPoint(1, 650, 2.6088E-02);
//   grthSM->SetPoint(2, 700, 1.5907E-02);
//   grthSM->SetPoint(3, 750, 1.0045E-02);
//   grthSM->SetPoint(4, 800, 6.5582E-03);
//   grthSM->SetPoint(5, 850, 4.3560E-03);
//   grthSM->SetPoint(6, 900, 2.9701E-03);
//   grthSM->SetPoint(7, 950, 2.0553E-03);
//   grthSM->SetPoint(8, 1000, 1.4410E-03);
//   grthSM->SetPoint(9, 1050, 1.0283E-03);
//   grthSM->SetPoint(10, 1100, 7.3979E-04);
//   grthSM->SetPoint(11, 1150, 5.4086E-04);
//   grthSM->SetPoint(12, 1200, 3.9717E-04);
//   grthSM->SetPoint(13, 1250, 2.9347E-04);
//   grthSM->SetPoint(14, 1300, 2.1957E-04);
//   grthSM->SetPoint(15, 1350, 1.6507E-04);
//   grthSM->SetPoint(16, 1400, 1.2514E-04);
//   grthSM->SetPoint(17, 1450, 9.5937E-05);
//   grthSM->SetPoint(18, 1500, 7.3300E-05);
//   grthSM->SetPoint(19, 1550, 5.6376E-05);
//   grthSM->SetPoint(20, 1600, 4.3715E-05);
//   grthSM->SetPoint(21, 1650, 3.3834E-05);
//   grthSM->SetPoint(22, 1700, 2.6389E-05);
//   grthSM->SetPoint(23, 1750, 2.0691E-05);
//   grthSM->SetPoint(24, 1800, 1.6259E-05);
//   grthSM->SetPoint(25, 1850, 1.2809E-05);
//   grthSM->SetPoint(26, 1900, 1.0131E-05);
//   grthSM->SetPoint(27, 1950, 8.0235E-06);
//   grthSM->SetPoint(28, 2000, 6.3711E-06);
//   grthSM->SetPoint(29, 2050, 5.0725E-06);
//   grthSM->SetPoint(30, 2100, 4.0513E-06);
//   grthSM->SetPoint(31, 2150, 3.2469E-06);
//   grthSM->SetPoint(32, 2200, 2.6006E-06);
//   grthSM->SetPoint(33, 2250, 2.0899E-06);
//   grthSM->SetPoint(34, 2300, 1.6810E-06);
//   grthSM->SetPoint(35, 2350, 1.3586E-06);
//   grthSM->SetPoint(36, 2400, 1.0964E-06);
//   grthSM->SetPoint(37, 2450, 8.8416E-07);
//   grthSM->SetPoint(38, 2500, 7.1662E-07);
//   if (!isZZChannel) {
//     grthSM->SetPoint(0, 800, 1.2713E-02);
//     grthSM->SetPoint(1, 850, 8.5015E-03);
//     grthSM->SetPoint(2, 900, 5.8030E-03);
//     grthSM->SetPoint(3, 950, 4.0261E-03);
//     grthSM->SetPoint(4, 1000, 2.8289E-03);
//     grthSM->SetPoint(5, 1050, 2.0214E-03);
//     grthSM->SetPoint(6, 1100, 1.4580E-03);
//     grthSM->SetPoint(7, 1150, 1.0625E-03);
//     grthSM->SetPoint(8, 1200, 7.8079E-04);
//     grthSM->SetPoint(9, 1250, 5.7987E-04);
//     grthSM->SetPoint(10, 1300, 4.3448E-04);
//     grthSM->SetPoint(11, 1350, 3.2719E-04);
//     grthSM->SetPoint(12, 1400, 2.4778E-04);
//     grthSM->SetPoint(13, 1450, 1.8896E-04);
//     grthSM->SetPoint(14, 1500, 1.4543E-04);
//     grthSM->SetPoint(15, 1550, 1.1200E-04);
//     grthSM->SetPoint(16, 1600, 8.6492E-05);
//     grthSM->SetPoint(17, 1650, 6.7405E-05);
//     grthSM->SetPoint(18, 1700, 5.2283E-05);
//     grthSM->SetPoint(19, 1750, 4.1121E-05);
//     grthSM->SetPoint(20, 1800, 3.2378E-05);
//     grthSM->SetPoint(21, 1850, 2.5507E-05);
//     grthSM->SetPoint(22, 1900, 2.0215E-05);
//     grthSM->SetPoint(23, 1950, 1.6020E-05);
//     grthSM->SetPoint(24, 2000, 1.2714E-05);
//     grthSM->SetPoint(25, 2050, 1.0133E-05);
//     grthSM->SetPoint(26, 2100, 8.0785E-06);
//     grthSM->SetPoint(27, 2150, 6.4583E-06);
//     grthSM->SetPoint(28, 2200, 5.1774E-06);
//     grthSM->SetPoint(29, 2250, 4.1620E-06);
//     grthSM->SetPoint(30, 2300, 3.3440E-06);
//     grthSM->SetPoint(31, 2350, 2.7018E-06);
//     grthSM->SetPoint(32, 2400, 2.1753E-06);
//     grthSM->SetPoint(33, 2450, 1.7626E-06);
//     grthSM->SetPoint(34, 2500, 1.4225E-06);
//   }
  grthSM10->SetName("SMXSection_2nd");

  // double fr_left = 590.0, fr_down = 1E-5, fr_right = 2000.0, fr_up = 0.5; 
//   double fr_left = 590.0, fr_down = 5E-5, fr_right = 2000.0, fr_up = 5;
   double fr_left = 500.0, fr_down = 5E-7, fr_right = 4500.0, fr_up = 5E-1;

  TCanvas *cMCMC = new TCanvas("c_lim_Asymptotic", "canvas with limits for Asymptotic CLs", 630, 600);
  cMCMC->cd();
  cMCMC->SetGridx(1);
  cMCMC->SetGridy(1);
  // draw a frame to define the range

  TH1F *hr = cMCMC->DrawFrame(fr_left, fr_down, fr_right, fr_up, "");
  TString VV = "ZH";
  
  hr->SetXTitle("M_{X} [GeV]");
  hr->SetYTitle("#sigma_{95%} [pb]"); // #rightarrow 2l2q
  

  gr95_cls->SetFillColor(kYellow);
  gr95_cls->SetFillStyle(1001);//solid
  gr95_cls->SetLineStyle(kDashed);
  gr95_cls->SetLineWidth(3);
  gr95_cls->GetXaxis()->SetTitle("M_{V'} [GeV]");
  gr95_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(V' #rightarrow " + VV + ") [pb]"); // #rightarrow 2l2q
  gr95_cls->GetXaxis()->SetRangeUser(fr_left, fr_right);

//  gr95_cls->Draw("3");

  gr68_cls->SetFillColor(kGreen);
  gr68_cls->SetFillStyle(1001);//solid
  gr68_cls->SetLineStyle(kDashed);
  gr68_cls->SetLineWidth(3);
//  gr68_cls->Draw("3same");
  grmedian_cls->GetXaxis()->SetTitle("M_{V'} [GeV]");
  grmedian_cls->GetYaxis()->SetTitle("#sigma_{95%} #times BR(V' #rightarrow " + VV + ") [pb]"); // #rightarrow 2l2q
  grmedian_cls->SetMarkerStyle(24);//25=hollow squre
  grmedian_cls->SetMarkerColor(kBlack);
  grmedian_cls->SetLineStyle(2);
  grmedian_cls->SetLineWidth(3);
  grmedian_cls->SetMinimum(0.0);
  grmedian_cls->SetMaximum(8.0);

  grobslim_cls->SetMarkerColor(kBlack);
  grobslim_cls->SetMarkerStyle(21);//24=hollow circle
  grobslim_cls->SetMarkerSize(1.0);
  grobslim_cls->SetLineStyle(1);
  grobslim_cls->SetLineWidth(3);

  grthSM->SetLineColor(kRed);
  grthSM->SetLineWidth(2);
  grthSM->SetLineStyle(kSolid);
  grthSM->SetFillColor(kRed);
  grthSM->SetFillStyle(3344);

  grthSM10->SetLineColor(kRed);
  grthSM10->SetLineWidth(2);
  grthSM10->SetLineStyle(1);
  grthSM10->SetLineStyle(kDashed);
  grthSM10->SetFillColor(kRed);
  grthSM10->SetFillStyle(3344);

//  grthSM->Draw("L3");
  grmedian_cls->Draw("L");
//  grobslim_cls->Draw("LP");

  /*
  TFile *fUnMPlus=new TFile("AsymptoticCLs_UnmatchedPlus_TGraph.root","READ");
  TGraph *grobs_ump=(TGraph*)fUnMPlus->Get("LimitObservedCLs");
  TGraph *grmedian_ump=(TGraph*)fUnMPlus->Get("LimitExpectedCLs");
  grobs_ump->SetName("LimitObs_UnmatchedPlus");
  grmedian_ump->SetName("LimitExp_UnmatchedPlus");
  grobs_ump->SetMarkerColor(kBlue);
  grobs_ump->SetLineColor(kBlue);
  grobs_ump->SetMarkerStyle(25);
  grmedian_ump->SetMarkerColor(kBlue);
  grmedian_ump->SetLineColor(kBlue);
  grmedian_ump->SetMarkerStyle(25);
  grobs_ump->Draw("P");
  grmedian_ump->Draw("L");
  */

  //draw grid on top of limits
  gStyle->SetOptStat(0);
  TH1D* postGrid = new TH1D("postGrid", "", 1, fr_left, fr_right);
  postGrid->GetYaxis()->SetRangeUser(fr_down, fr_up);
  postGrid->Draw("AXIGSAME");

  //more graphics

  TLegend *leg = new TLegend(.20, .2, .75, .35);
  //   TLegend *leg = new TLegend(.35,.71,.90,.90);
  leg->SetFillColor(0);
  leg->SetShadowColor(0);
  leg->SetTextFont(42);
  leg->SetTextSize(0.03);
  //   leg->SetBorderMode(0);
  leg->AddEntry(grmedian_cls, "CL_{S} Expected limit central value", "L");
//  leg->AddEntry(grobslim_cls, "Frequentist CL_{S} Observed", "LP");
//  leg->AddEntry(gr68_cls, "Frequentist CL_{S}  Expected #pm 1#sigma", "LF");
//  leg->AddEntry(gr95_cls, "Frequentist CL_{S}  Expected #pm 2#sigma", "LF");
//  leg->AddEntry(grthSM, "#sigma_{TH}", "L");
//    leg->AddEntry(grthSM, "#sigma_{TH} x BR(Z' #rightarrow " + VV + "), #tilde{k}=0.50", "L"); // #rightarrow 2l2q
//    leg->AddEntry(grthSM10, "#sigma_{TH} x BR(Z' #rightarrow " + VV + "), #tilde{k}=0.20", "L"); // #rightarrow 2l2q
  leg->Draw();

    TLatex * latex = new TLatex();
    latex->SetNDC();
    latex->SetTextSize(0.04);
    latex->SetTextAlign(31);
    latex->SetTextAlign(11); // align left
//    latex->DrawLatex(0.18, 0.96, "CMS preliminary 2012");
//    latex->DrawLatex(0.60, 0.96, Form("%.1f fb^{-1} at #sqrt{s} = 8 TeV", intLumi));
    latex->DrawLatex(0.18, 0.96, "CMS preliminary 2015");
    latex->DrawLatex(0.60, 0.96, Form("%.1f fb^{-1} at #sqrt{s} = 13 TeV", intLumi));
  

  // cMCMC->RedrawAxis("");
  gPad->RedrawAxis("");
  // hr->GetYaxis()->DrawClone();
  cMCMC->Update();
  char fnam[50];
  //string outputname="shape2d";
  //string outputname="shape1d";
  //string outputname="counting";

  sprintf(fnam, "XZHllbb_%s_Asymptotic.root",outputname.data() );
//  cMCMC->SaveAs(fnam);
  //sprintf(fnam, "XZHllbb_%s_Asymptotic.eps", outputname.data());
  //cMCMC->SaveAs(fnam);
    sprintf(fnam, "XZHllbb_%s_Asymptotic.png", outputname.data());
//    cMCMC->SaveAs(fnam);
    //sprintf(fnam, "XZHllbb_%s_Asymptotic.pdf", outputname.data());
    //cMCMC->SaveAs(fnam);
    gPad->SetLogy();
    //sprintf(fnam, "XZHllbb_%s_Asymptotic_log.eps", outputname.data());
    //cMCMC->SaveAs(fnam);
    sprintf(fnam, "XZHllbb_%s_Asymptotic_log.png", outputname.data());
//    cMCMC->SaveAs(fnam);
    //sprintf(fnam, "XZHllbb_%s_Asymptotic_log.pdf", outputname.data());
    //cMCMC->SaveAs(fnam);
 

  cMCMC->Draw();



return grmedian_cls;

}//end main
void Control_all_cut_limit_auto()
{

const float intLumi = 3.0;
const int n_cut_index =11; // 10

  TString variable_name = "Ele_1st_pt" ;
  cout<<"variable_name: " << variable_name << endl;

  // define cuts
  
  int cut_value[n_cut_index];
  double lowest_cut=435 ;
  double scan_width = 20;// 21

  for(int i=0;i<n_cut_index ;i++){
        cut_value[i] = lowest_cut + scan_width*i;
        cout<<"cut_value[i]: "<< cut_value[i] << endl;
  }
  //

//int cut_value[n_cut_index] = 
//{115,136,157,178,199,220,241,262,283,304};

  TGraphAsymmErrors *grmedian_cls;
  TGraphAsymmErrors *grmedian_cls_new[n_cut_index];

  const int nMassEff = 11;  // # of mass point
  double mass[nMassEff] = {0};
  double medianD[nMassEff] = {0};


  grmedian_cls = new TGraphAsymmErrors(nMassEff, mass, medianD);


//  TString dir_path = "Datacards_txt_files/YuHsiang_DY_h_ele_1st_pT_cut_115/";
  TString dir_path[n_cut_index] ;
  TString leg_name[n_cut_index] ;

  int nXm = nMassEff; 

  for(int i=0;i<n_cut_index;i++){
//  for(int i=0;i<5;i++){
  dir_path[i] = Form("YuHsiang_DY_Ele_1st_pt_cut_%d/",cut_value[i] ) ;
//  dir_path[i] = Form("YuHsiang_DY_h_ele_1st_pT_cut_%d/",cut_value[i] ) ;
  dir_path[i] = "Datacards_text_and_ROOT_files/" + dir_path[i];
//  dir_path[i] = "Datacards_txt_files/" + dir_path[i];

//  if(cut_value[i]==515) {nXm = 10;}
//  if(cut_value[i]==615) {nXm = 10;}// lost M800
//  if(cut_value[i]==715) {nXm = 10;}// lost M800
//  if(cut_value[i]==815) {nXm = 8;}
//  if(cut_value[i]==915) {nXm = 8;}
//  if(cut_value[i]==1015) {nXm = 8;}
  if(cut_value[i]==515 || cut_value[i]==535 || cut_value[i]==555) {nXm = 10;}// lost M800
  if(cut_value[i]==575 || cut_value[i]==595 || cut_value[i]==615) {nXm = 10;}// lost M800
  if(cut_value[i]==635 ) {nXm = 10;}// lost M800
  if(cut_value[i]==835) {nXm = 8;}// lost M800, M1000, M1200


  cout<<endl;
  cout<<"dir_path[i]: "<< dir_path[i] <<" cut_value[i]: "<< cut_value[i]<<" nXm: "<< nXm <<endl;
  cout<<endl;


  grmedian_cls_new[i] =  plot_Asymptotic( dir_path[i] ,grmedian_cls, nXm );

//  leg_name[i] = Form("CL_{S} Expected Limit for cut pt>%d",cut_value[i] ) ;
  leg_name[i] = Form("cut pt>%d",cut_value[i] ) ;
  }





  TCanvas *c1 = new TCanvas("c1", "canvas with limits for Asymptotic CLs", 630, 600);


  TLegend *leg = new TLegend(.75, .35, 1., .85);
  leg->SetFillColor(0);
  leg->SetShadowColor(0);
  leg->SetTextFont(42);
  leg->SetTextSize(0.03);

  c1->SetGridx(1);
  c1->SetGridy(1);
    gPad->SetLogy();


  
  c1->cd();

//   double fr_left = 500.0, fr_down = 5E-2, fr_right = 4500.0, fr_up = 3E2;
//   double fr_left = 500.0, fr_down = 2E-1, fr_right = 1500.0, fr_up = 7E-1;
//   double fr_left = 1800.0, fr_down = 1.1E-1, fr_right = 2200.0, fr_up = 1.5E-1;
   double fr_left = 2800.0, fr_down = 1E-1, fr_right = 3200.0, fr_up = 1.1E-1;
  TH1F *hr = c1->DrawFrame(fr_left, fr_down, fr_right, fr_up, "");

  int colorN = 1;

// loop

  for(int i=0;i<n_cut_index;i++){

        if (i==0){colorN = kRed;}
        if (i==2){colorN = kOrange;}
        if (i==4){colorN = kCyan;}
        if (i==6){colorN = kBlue;}
        if (i==8){colorN = kGreen;}
	
  	grmedian_cls_new[i]->SetLineColor(colorN);
        grmedian_cls_new[i]->SetLineStyle(1);
  	grmedian_cls_new[i]->Draw();

//  	leg->AddEntry(grmedian_cls_new[i], "CL_{S} Expected Limit", "L");
        leg->AddEntry(grmedian_cls_new[i],leg_name[i] , "L");
  	leg->Draw();

	colorN = colorN+2;
  }
// end loop

  hr->SetXTitle("M_{Z'} [GeV]");
  hr->SetYTitle("95% #sigma_{Z'}xBR(Z'->ZH) [pb]");

    TLatex * latex = new TLatex();
    latex->SetNDC();
    latex->SetTextSize(0.04);
    latex->SetTextAlign(31);
    latex->SetTextAlign(11);

    latex->DrawLatex(0.25, 0.91, "CL_{S} Expected Limit, cut electron leading pt");
    latex->DrawLatex(0.18, 0.96, "CMS preliminary 2015");
    latex->DrawLatex(0.60, 0.96, Form("%.1f fb^{-1} at #sqrt{s} = 13 TeV", intLumi));


  TString save_name = "expected_limit_cut_";
  save_name = save_name + variable_name ;

  TString png_name = save_name + ".png";
  TString pdf_name = save_name + ".pdf";

  c1->SaveAs(png_name);
  c1->SaveAs(pdf_name);


//TString path_to_save = "/afs/cern.ch/user/y/yuchang/www/set_limit_optimize_leading_pt/" ;
TString path_to_save = "/afs/cern.ch/user/y/yuchang/www/optimize_cut_with_limit_use_eleIsPassLoose/leading_pt/" ;
pdf_name = path_to_save + pdf_name;

c1->SaveAs( pdf_name );


}// end codes