void vertex_distribution_dataMC() {

  bool print = false;

  TFile *file0 = TFile::Open("results/RecoRoutines_W-selection_WJetsMGZ238PU.root");
  TFile *file1 = TFile::Open("results/RecoRoutines_W-selection_dataskimnov4rereco_newJetColl.root");

  TCanvas * canvas = makeCanvas("vertexDistribution_dataMC");
  TH1D * mc = (TH1D*)file0->Get("RECO_PolPlots_50toinf/RECO_NumVerticesPerEvent");
  TH1D * data = (TH1D*)file1->Get("RECO_PolPlots_50toinf/RECO_NumVerticesPerEvent");

  mc->GetXaxis()->SetTitle("Vertex Multiplicity");
  mc->GetXaxis()->SetTitleSize(0.06);
  mc->GetXaxis()->SetLabelOffset(0.015);
  mc->GetXaxis()->SetTitleOffset(1.2);
  mc->GetXaxis()->SetRangeUser(0,10);
  mc->GetYaxis()->SetRangeUser(0,0.35);

  mc->GetYaxis()->SetTitle("Normalised");
  mc->GetYaxis()->SetTitleSize(0.06);
  mc->GetYaxis()->SetTitleOffset(0.85);

  mc->SetLineColor(kRed);
  data->SetLineColor(kBlack);

  mc->SetLineWidth(4);
  mc->SetLineStyle(2);
  data->SetLineWidth(4);
  data->SetLineStyle(1);

  leg = new TLegend(0.6426174,0.8074324,0.9010067,0.9273649,NULL,"brNDC");
  leg->AddEntry(mc,"MC","l");
  leg->AddEntry(data,"Data","l");
  leg->SetFillColor(kWhite);
  leg->SetBorderSize(0);
  leg->SetTextFont(62);

  canvas->cd();
  mc->DrawNormalized("h");
  data->DrawNormalized("sameh");
  leg->DrawClone();

  if(print) {
    canvas->Write();
  }

  file1->Close();
  file0->Close();
  return;
}
Beispiel #2
0
int main(int argc, char* argv[])
{
  TROOT rsession("test","test");
  rsession.SetBatch(0);
  TApplication theApp("App", &argc, argv);
  spectrum spec = spectrum();
  Int_t debin = 6;
  Double_t eoffset = -1.0;
  Double_t mass = 0.5;
  Double_t background = 0;
  Double_t scale = 0.9;
  Double_t t0 = 20E-6;

  Int_t datalen = 400;

  TH1D *inptg = new TH1D("inptg", "", datalen, 0, datalen);
  inptg->SetLineColor(2);
  TH1D *fitog = new TH1D("fitog", "", datalen, 0, datalen);
  fitog->SetLineStyle(2);

  spec.set_nbinsde(debin);
  spec.set_tmean(t0);
  spec.set_in_pars(scale, eoffset, mass*mass, background);
  spec.build_data_spectrum();
  spec.do_a_fit();
  datalen = spec.get_datalen();

  cout << "enter to exit" << endl;
  spec.~spectrum();
  cin.ignore();
  return 0;
}
Beispiel #3
0
void PrintHist(const char *filename = "test.root", const char *histname = "histname") {

  Init();

  TFile *f = new TFile(filename);
  TH1D *histo;

  histo = (TH1D*)(f->Get(histname));
  histo->GetXaxis()->SetTitleSize(0.055);
  histo->GetYaxis()->SetTitleSize(0.055);
  histo->GetXaxis()->SetLabelSize(0.04);
  histo->GetYaxis()->SetLabelSize(0.05);
  histo->GetXaxis()->SetTitleOffset(1.15);
  histo->GetYaxis()->SetTitleOffset(1.1);
  histo->SetTitle("");
  histo->SetLineStyle(1);
  histo->SetLineWidth(2);
//   histo->GetXaxis()->SetTitle("Vcal [low range DAC units]");
//   histo->GetYaxis()->SetTitle("PH [ADC units]");
     histo->GetXaxis()->SetTitle("par1");
     histo->GetYaxis()->SetTitle("# pixels");
//    histo->GetXaxis()->SetTitle("position resolution [#mum]");
//    histo->GetYaxis()->SetTitle("# pixels");
//     histo->GetXaxis()->SetTitle("Vana [DAC units]");
//     histo->GetYaxis()->SetTitle("par1");
//      histo->GetXaxis()->SetTitle("nChip");
//      histo->GetYaxis()->SetTitle("par1");


     histo->Draw();
     //histo->Draw("colz");

}
TH1D* returnRelDiff(TH1D* h, TH1D* b, TString name) {
  TH1D* hRelDiff = new TH1D(name, "", h->GetNbinsX(), h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax());
  hRelDiff->SetLineColor(h->GetLineColor());
  hRelDiff->SetLineStyle(h->GetLineStyle());
  hRelDiff->SetLineWidth(h->GetLineWidth());

  hRelDiff->GetYaxis()->SetTitleOffset(0.42);
  hRelDiff->GetYaxis()->SetTitleSize(0.13);
  hRelDiff->GetYaxis()->SetLabelSize(0.10);
  hRelDiff->GetXaxis()->SetTitleOffset(1.2);
  hRelDiff->GetXaxis()->SetTitleSize(0.13);
  hRelDiff->GetXaxis()->SetLabelSize(0.12);
  //hRelDiff->GetXaxis()->CenterTitle();                                                                                   
  hRelDiff->GetYaxis()->CenterTitle();
  hRelDiff->GetYaxis()->SetNdivisions(303,kTRUE);

  // (mc-data)/mc, uncertainty is √data
  for (Int_t i=1; i<h->GetNbinsX()+1; i++) {
    Double_t y = b->GetBinContent(i);
    Double_t val = h->GetBinContent(i) - y;
    if (y!=0) { hRelDiff->SetBinContent(i, val/h->GetBinContent(i)); hRelDiff->SetBinError(i,TMath::Sqrt(b->GetBinContent(i))/h->GetBinContent(i)); }
    else hRelDiff->SetBinContent(i, 0);
  }
  return hRelDiff;
}
Beispiel #5
0
void plotter::draw_projection(TH1D* proj_, TH1D* compare_, TString file_name ){
  TH1D* proj = (TH1D*) proj_->Clone("proj");
  TH1D* compare = (TH1D*) compare_->Clone("compare");

  // check if distribution agrees with Matrix projection
  // since there are some numerical effects involved in the projection,
  // the warning is only printed if both distributions do not agree within 1%
  int nbins = proj->GetSize() - 2;
  for(int i=1; i<= nbins; i++){
    double nproj = proj->GetBinContent(i);
    double ncomp = compare->GetBinContent(i);
    if(nproj < ncomp * 0.99 && nproj > ncomp * 1.01){
      std::cout << "Projection and Distribution in " << file_name << " do not agree in bin " << i << std::endl;
    }
  }

  TCanvas *c= new TCanvas("Projection Gen","",600,600);
  gPad->SetLeftMargin(0.15);
  proj->SetLineColor(kAzure+7);
  proj->Draw("HIST");
  compare->SetLineColor(kRed);
  compare->SetLineStyle(7);
  compare->Draw("HIST SAME");
  TLegend *l=new TLegend(0.55,0.65,0.85,0.8);
  l->SetBorderSize(0);
  l->SetFillStyle(0);
  l->AddEntry(proj,"Projection from matrix","l");
  l->AddEntry(compare,"MC Gen","pl");
  l->Draw();
  c->SaveAs(directory + file_name + ".pdf");
  delete c;
}
Beispiel #6
0
void plotRate(){
  //TFile * f_ttbar= new TFile("ttbar-output-2014-06-22.root");
  TFile * f= new TFile("./rateTest.root");
  std::vector<TString> jetnum;
  //jetnum.push_back("0");
  //jetnum.push_back("1");
  //jetnum.push_back("2");
  jetnum.push_back("3");
  std::vector<TString> truejetnum;
  //truejetnum.push_back("1");
//  truejetnum.push_back("2");
//  truejetnum.push_back("3");
  truejetnum.push_back("4");
  //jetType.push_back("calib_gct");
  int i = -1;
  for (iNum = jetnum.begin();iNum != jetnum.end(); iNum++)
  {
    i++;
    std::cout <<"jetNumber_"+*iNum+"/5400_calib_nopus_"+*iNum+"_Rate" << std::endl;
    TH1D* nopus = f->Get("jetNumber_"+*iNum+"/5400_calib_nopus_"+*iNum+"_Rate");
    TH1D* donutseed = f->Get("jetNumber_"+*iNum+"/5450_calib_donut_"+*iNum+"_Rate");
    TH1D* nopusseed = f->Get("jetNumber_"+*iNum+"/5450_calib_nopus_"+*iNum+"_Rate");
    TH1D* global = f->Get("jetNumber_"+*iNum+"/5400_calib_global_"+*iNum+"_Rate");
    TH1D* gct = f->Get("jetNumber_"+*iNum+"/gct_calib_gen_"+*iNum+"_Rate");


    TLegend* leg = new TLegend(0.55,0.55,0.85,0.85);
    leg->SetFillColor(0);
    TCanvas * c = new TCanvas("Turn on Curve "+*iNum+" (p_{T} ","",600,600);

    c->cd();
    nopus->GetXaxis()->SetTitle("Pt/GeV");
    nopus->SetTitle("");
    gStyle->SetOptStat(0);
    nopus->GetXaxis()->SetTitleOffset(1.4);
    nopus->GetYaxis()->SetTitle("Rate for jet "+truejetnum.at(i)+"/Hz");
    nopus->GetYaxis()->SetTitleOffset(1.4);
    nopus->SetLineColor(1);
    nopus->GetXaxis()->SetRangeUser(25,45);
    nopusseed->SetLineStyle(2);
    donutseed->SetLineColor(2);
    donutseed->SetMarkerColor(2);
    global->SetLineColor(4);
    gct->SetLineColor(8);
    global->SetMarkerColor(4);
    nopus->Draw();
    nopusseed->Draw("same");
    donutseed->Draw("same");
    global->Draw("same");
    gct->Draw("same");
    leg->AddEntry(nopus,"No PUS","l");
    leg->AddEntry(nopusseed,"No PUS (Seed 5)","l");
    leg->AddEntry(donutseed,"Donut Sub (Seed 5)","l");
    leg->AddEntry(global,"Global Sub","l");
    leg->AddEntry(gct,"GCT","l");
    leg->Draw("L");
    c->SaveAs("output/cmsweek/rate"+*iNum+".png");
  }
  return;
}
Beispiel #7
0
void plotter::draw_output_pseudo(TH1* output_, TH1D* pseudotruth_, TH1D* mctruth_, bool norm, TString file_name){

  TH1* output = (TH1*) output_->Clone("output");
  TH1D* pseudotruth = (TH1D*) pseudotruth_->Clone("pseudotruth");
  TH1D* mctruth = (TH1D*) mctruth_->Clone("mctruth");

  double ymax_temp = 0;
  if(pseudotruth->GetMaximum() > ymax_temp) ymax_temp = pseudotruth->GetMaximum();
  if(mctruth->GetMaximum() > ymax_temp) ymax_temp = mctruth->GetMaximum();
  if(output->GetMaximum() > ymax_temp) ymax_temp = output->GetMaximum();
  double ymax = 1.5 * ymax_temp;


  pseudotruth->SetTitle(" ");
  pseudotruth->GetYaxis()->SetRangeUser(0., ymax);
  pseudotruth->GetXaxis()->SetTitle("Leading-jet mass [GeV]");
  if(norm) pseudotruth->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dm_{jet}} [#frac{1}{GeV}]");
  else     pseudotruth->GetYaxis()->SetTitle("events");
  pseudotruth->GetYaxis()->SetTitleOffset(1.1);
  pseudotruth->GetXaxis()->SetTitleOffset(0.9);
  pseudotruth->GetYaxis()->SetTitleSize(0.05);
  pseudotruth->GetXaxis()->SetTitleSize(0.05);
  pseudotruth->GetYaxis()->SetNdivisions(505);

  pseudotruth->SetLineWidth(4);
  pseudotruth->SetLineColor(kRed);
  mctruth->SetLineWidth(3);
  mctruth->SetLineStyle(2);
  mctruth->SetLineColor(kBlue);

  output->SetLineColor(kBlack);
  output->SetMarkerColor(kBlack);
  output->SetMarkerStyle(8);
  output->SetMarkerSize(1);

  TCanvas *c= new TCanvas("Particle Level","",600,600);
  gPad->SetLeftMargin(0.15);
  TGaxis::SetMaxDigits(3);
  pseudotruth->Draw("HIST SAME");
  mctruth->Draw("HIST SAME");
  output->Draw("E1 SAME");
  TLegend *l;
  if(mctruth->GetSize() > 20) l=new TLegend(0.2,0.6,0.4,0.85);
  else                       l=new TLegend(0.55,0.6,0.85,0.85);
  l->SetBorderSize(0);
  l->SetFillStyle(0);
  l->AddEntry(output,"pseudo data","pl");
  l->AddEntry(pseudotruth,"pseudo data truth","pl");
  l->AddEntry(mctruth,"MC truth","pl");
  l->SetTextSize(0.04);

  l->Draw();
  gPad->RedrawAxis();
  c->SaveAs(directory + file_name + ".pdf");
  delete c;
}
Beispiel #8
0
void plotter::draw_output_stat(TH1* output_, TH1* stat_, TH1D* truth_, bool norm, TString file_name){
  // std::vector<double> sys = get_sys_errors();
  // TH1* output_sys = add_error_bar(output, sys);

  TH1* output = (TH1*) output_->Clone("output");
  TH1* stat = (TH1*) stat_->Clone("stat");
  TH1D* truth = (TH1D*) truth_->Clone("truth");

  TCanvas *c = new TCanvas("c","",600,600);
  double ymax;
  gPad->SetLeftMargin(0.15);

  if(truth->GetMaximum() > output->GetMaximum()) ymax = 1.5 * truth->GetMaximum();
  else ymax = 1.5 * output->GetMaximum();
  TGaxis::SetMaxDigits(3);
  output->SetTitle(" ");
  output->GetYaxis()->SetRangeUser(0., ymax);
  output->GetXaxis()->SetTitle("Leading-jet mass [GeV]");
  if(norm) output->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{d#sigma}{dm_{jet}} [#frac{1}{GeV}]");
  else output->GetYaxis()->SetTitle("events");
  output->GetYaxis()->SetTitleOffset(1.1);
  output->GetXaxis()->SetTitleOffset(0.9);
  output->GetYaxis()->SetTitleSize(0.05);
  output->GetXaxis()->SetTitleSize(0.05);
  output->GetYaxis()->SetNdivisions(505);
  output->SetLineColor(kBlack);
  output->SetMarkerColor(kBlack);
  output->SetMarkerStyle(8);
  output->SetMarkerSize(1);
  output->Draw("E1");
  stat->SetLineColor(kBlack);
  stat->SetMarkerColor(kBlack);
  stat->SetMarkerStyle(8);
  stat->SetMarkerSize(1);
  gStyle->SetEndErrorSize(5);
  truth->SetLineWidth(3);
  truth->SetLineColor(kRed);
  truth->SetLineStyle(2);
  truth->Draw("HIST SAME");
  stat->Draw("E1 SAME");
  output->Draw("E1 SAME");

  TLegend *l=new TLegend(0.5,0.65,0.85,0.85);
  l->SetBorderSize(0);
  l->SetFillStyle(0);
  l->AddEntry(output,"data unfolded","pl");
  l->AddEntry(truth,"MC particle level","pl");
  l->SetTextSize(0.04);
  l->Draw();
  c->SaveAs(directory + file_name + ".pdf");
  delete c;
}
Beispiel #9
0
void plotter::draw_output_smear(std::vector<TH1*> output_, TH1D* truth_, TString file_name){
  // std::vector<double> sys = get_sys_errors();
  // TH1* output_sys = add_error_bar(output, sys);

  std::vector<TH1*> outputs;
  for(int i=0; i<output_.size(); i++){
    TH1* hist = (TH1*) output_[i]->Clone();
    outputs.push_back(hist);
  }
  TH1D* truth = (TH1D*) truth_->Clone("truth");

  TCanvas *c = new TCanvas("c","",600,600);
  double ymax;
  gPad->SetLeftMargin(0.15);

  if(truth->GetMaximum() > outputs[0]->GetMaximum()) ymax = 1.5 * truth->GetMaximum();
  else ymax = 1.5 * outputs[0]->GetMaximum();
  TGaxis::SetMaxDigits(3);
  for(auto output: outputs){
    output->SetTitle(" ");
    output->GetYaxis()->SetRangeUser(0., ymax);
    output->GetXaxis()->SetTitle("Leading-jet mass [GeV]");
    output->GetYaxis()->SetTitle("events");
    output->GetYaxis()->SetTitleOffset(1.1);
    output->GetXaxis()->SetTitleOffset(0.9);
    output->GetYaxis()->SetTitleSize(0.05);
    output->GetXaxis()->SetTitleSize(0.05);
    output->GetYaxis()->SetNdivisions(505);
    output->SetLineColor(kBlack);
    output->SetMarkerColor(kBlack);
    output->SetMarkerStyle(8);
    output->SetMarkerSize(1);
    output->Draw("E1 SAME");
  }
  gStyle->SetEndErrorSize(5);
  truth->SetLineWidth(3);
  truth->SetLineColor(kRed);
  truth->SetLineStyle(2);
  truth->Draw("HIST SAME");
  TLegend *l;
  if(truth->GetSize() > 20) l=new TLegend(0.2,0.6,0.4,0.85);
  else                       l=new TLegend(0.5,0.6,0.85,0.85);
  l->SetBorderSize(0);
  l->SetFillStyle(0);
  l->AddEntry(outputs[0],"data unfolded","pl");
  l->AddEntry(truth,"MC particle level","pl");
  l->SetTextSize(0.04);
  l->Draw();
  c->SaveAs(directory + file_name + ".pdf");
  delete c;
}
void plot(TFile * measurement, const char * mname, TFile * mctruth, const char * mcname)
{
    TH1D * mHistogram = (TH1D*) measurement->Get(mname);
    TH1D * mcHistogram = (TH1D*) mctruth->Get(mcname);

    mHistogram->GetYaxis()->SetRangeUser(0., 1.2);
    mcHistogram->GetYaxis()->SetRangeUser(0., 1.2);

    mHistogram->SetLineWidth(2);
    mcHistogram->SetLineWidth(2);
    mcHistogram->SetLineStyle(2);
    mcHistogram->SetLineColor(kRed);

    mHistogram->Draw();
    mcHistogram->Draw("same");

    TLegend * legend = new TLegend(0.25, 0.77, 0.6, 0.92);
    legend->AddEntry(mHistogram, "Measure", "pl");
    legend->AddEntry(mcHistogram, "MCTruth", "l");
    legend->Draw();
}
Beispiel #11
0
void plotter::draw_rec(TH1D* data_, TH1D* sig_, TH1D* bgr_, TString file_name){
  TH1D* data = (TH1D*) data_->Clone("data");
  TH1D* sig = (TH1D*) sig_->Clone("sig");
  TH1D* bgr = (TH1D*) bgr_->Clone("bgr");

  TCanvas *c= new TCanvas("c","",1200,600);
  gPad->SetLeftMargin(0.15);
  sig->Add(bgr, 1.);
  sig->SetTitle(" ");
  sig->GetYaxis()->SetRangeUser(0., 250);
  sig->GetXaxis()->SetTitle("detector binning");
  sig->GetYaxis()->SetTitle("events");
  sig->GetYaxis()->SetTitleOffset(1.5);
  sig->GetYaxis()->SetNdivisions(505);
  sig->SetFillColor(810);
  sig->SetLineColor(810);
  sig->Draw("HIST");
  bgr->SetFillColor(kGray);
  bgr->SetLineColor(kBlack);
  bgr->SetFillStyle(1001);
  bgr->Draw("HIST SAME");
  data->SetLineColor(kBlack);
  data->SetLineColor(kBlack);
  data->SetLineStyle(1);
  data->SetMarkerColor(kBlack);
  data->SetMarkerStyle(20);
  data->Draw("E SAME");
  TLegend *l=new TLegend(0.2,0.7,0.4,0.88);
  l->SetBorderSize(0);
  l->SetFillStyle(0);
  l->AddEntry(data,"Data","pl");
  l->AddEntry(sig,"t#bar{t}","f");
  l->AddEntry(bgr,"Background","f");
  l->Draw();
  gPad->RedrawAxis();
  c->SaveAs(directory + file_name + ".pdf");
  delete c;
}
Beispiel #12
0
void apt_all(){
//=========Macro generated from canvas: MyCanvas/My Canvas
//=========  (Thu Dec  3 18:47:52 2009) by ROOT version5.25/04
   
   gROOT->Reset();
   gROOT->ProcessLine(".x rootlogon.C");

   gStyle->SetTitleYOffset(1.5);
   TCanvas *MyCanvas = new TCanvas("MyCanvas", "My Canvas",0,0,550,600);

   MyCanvas->SetLogx();

   double msize = 2;

   TH1D *hDist = new TH1D("hDist","hDist",20,9,10000);
   hDist->GetXaxis()->SetRange(1,20);
   hDist->SetMinimum(0.3);
   //hDist->SetMaximum(0.7);
   hDist->SetMaximum(0.6);  
   hDist->SetLineStyle(0);
   hDist->GetXaxis()->SetTitle("#sqrt{s} [GeV]");
   hDist->GetYaxis()->SetTitle("#LTp_{T}#GT [GeV/c]");
   hDist->GetXaxis()->CenterTitle();
   hDist->GetYaxis()->CenterTitle();
   hDist->GetYaxis()->SetNdivisions(510);
   hDist->Draw("");
   
   // Fit function                                                                                                                                 
   //TF1 *func = new TF1("func","0.426-0.0198*log(x^2)+0.00156*log(x^2)^2",18,100000); 
   //TF1 *func = new TF1("func","0.430-0.0207*log(x^2)+0.00161*log(x^2)^2",18,100000); 
   TF1 *func = new TF1("func","0.425-0.0197*log(x^2)+0.00156*log(x^2)^2",18,100000);
   func->SetLineColor(1);
   func->SetLineWidth(2.0);
   func->Draw("same");


   // ============================= ISR
   // OK, from http://www.slac.stanford.edu/spires/find/hep/www?j=NUPHA,B84,269

   TGraphErrors *gre = new TGraphErrors(4);
   gre->SetName("Graph");
   gre->SetTitle("Graph");

   gre->SetMarkerStyle(28);
   gre->SetMarkerSize(msize);

   gre->SetPoint(0,23.32,0.362);// plab = 289
   gre->SetPointError(0,0,0.004);  // errors are not verified! 
   gre->SetPoint(1,30.59,0.364);// plab = 498
   gre->SetPointError(1,0,0.00497238);
   gre->SetPoint(2,44.61,0.366); // plab = 1060
   gre->SetPointError(2,0,0.00478821);
   gre->SetPoint(3,53.06,0.368); // plab = 1500
   gre->SetPointError(3,0,0.00497238);

   
   TH1F *Graph1 = new TH1F("Graph1","Graph",100,19.03788,56.0634);
   Graph1->SetMinimum(0.3551011);
   Graph1->SetMaximum(0.374549);

   gre->SetHistogram(Graph1);
   gre->Draw("pz");

   TGraph* gre01 = gre->Clone("gre01");
   gre01->SetMarkerStyle(0);
   //   gre01->Draw("pzsame");

   // ============================= UA1  
   // OK, from  http://dx.doi.org/10.1016/0550-3213(90)90493-W

   gre = new TGraphErrors(7);
   gre->SetName("Graph");
   gre->SetTitle("Graph");

   gre->SetMarkerStyle(3);
   gre->SetMarkerSize(msize);
   gre->SetPoint(0,200,0.392);
   gre->SetPointError(0,0,0.003);
   gre->SetPoint(1,260,0.404);
   gre->SetPointError(1,0,0.004);
   gre->SetPoint(2,380,0.408);
   gre->SetPointError(2,0,0.004);
   gre->SetPoint(3,500,0.419);
   gre->SetPointError(3,0,0.004);
   gre->SetPoint(4,620,0.426);
   gre->SetPointError(4,0,0.004);
   gre->SetPoint(5,790,0.435);
   gre->SetPointError(5,0,0.004);
   gre->SetPoint(6,900,0.447);
   gre->SetPointError(6,0,0.003);
   
   TH1F *Graph2 = new TH1F("Graph2","Graph",100,131.4964,972.7974);
   Graph2->SetMinimum(0.3826521);
   Graph2->SetMaximum(0.4560221);

   gre->SetHistogram(Graph2);
   gre->Draw("pz");
   
   TGraph* gre02 = gre->Clone("gre02");
   gre02->SetMarkerStyle(0);
   //   gre02->Draw("pzsame");

   // ============================= E735?
   // OK, from https://twiki.cern.ch/twiki/pub/CMS/DNdEtaBib/e735numbers.pdf
   gre = new TGraphErrors(4);
   gre->SetName("Graph");
   gre->SetTitle("Graph");

   gre->SetMarkerStyle(22);
   gre->SetMarkerSize(msize);
   gre->SetPoint(0,300,0.393);
   gre->SetPointError(0,0,0.01);
   gre->SetPoint(1,540,0.430);
   gre->SetPointError(1,0,0.01);
   gre->SetPoint(2,900,0.448);
   gre->SetPointError(2,0,0.01);
   gre->SetPoint(3,1800,0.468);
   gre->SetPointError(3,0,0.01);

   TH1F *Graph3 = new TH1F("Graph3","Graph",100,148.0787,1967.778);
   Graph3->SetMinimum(0.3734073);
   Graph3->SetMaximum(0.4869985);

   gre->SetHistogram(Graph3);
   gre->Draw("pz");

   TGraph* gre03 = gre->Clone("gre03");
   gre03->SetMarkerStyle(0);
   gre03->Draw("pzsame");
   
   // ============================= CDF
   // OK, from http://www.slac.stanford.edu/spires/find/hep/www?j=PRLTA,61,1819

   gre = new TGraphErrors(2);
   gre->SetName("Graph");
   gre->SetTitle("Graph");

   gre->SetMarkerStyle(21);
   gre->SetMarkerSize(msize);

   gre->SetPoint(0,630,0.432);
   gre->SetPointError(0,0,0.004);
   gre->SetPoint(1,1800,0.495);
   gre->SetPointError(1,0,0.014);
   
   TH1F *Graph4 = new TH1F("Graph4","Graph",100,518.0436,1936.249);
   Graph4->SetMinimum(0.4196686);
   Graph4->SetMaximum(0.5173485);
   gre->SetHistogram(Graph4);
   
   gre->Draw("pz");
   
   TGraph* gre04 = gre->Clone("gre04");
   gre04->SetMarkerStyle(0);
   gre04->Draw("pzsame");

   // ============================= CMS?
   gre = new TGraphErrors(1);
   gre->SetName("Graph");
   gre->SetTitle("Graph");

   gre->SetMarkerStyle(20);
   gre->SetMarkerSize(msize);
   gre->SetMarkerColor(kRed+2);
   gre->SetLineColor(kRed+2);

   /*
   gre->SetPoint(0,900,0.44);
   gre->SetPointError(0,0,0.018);
   */
   
   //Now real measurement
   Float_t cmsSysError = 0.028;
   gre->SetPoint(0,900,0.46);
   //gre->SetPointError(0,0,0.46*cmsSysError);
   // updated to sqrt (0.01*0.01+0.46*0.46*0.028*0.028) , where 0.01 is stat err. 
   gre->SetPointError(0,0,0.0163); 
   gre->SetPoint(1,2360,0.50);
   //gre->SetPointError(1,0,0.50*cmsSysError);
   gre->SetPointError(1,0,0.0172);

   TGraph* greOnT = gre->Clone("greOnT");
   greOnT->SetMarkerStyle(0);
   greOnT->SetLineWidth(2);
   greOnT->Draw("PZsame");

   TGraph* greOnT2 = gre->Clone("cmsnsd05");
   gStyle->SetEndErrorSize(3);
   greOnT2->SetMarkerStyle(0);
   greOnT2->Draw("||");

   
   TH1F *Graph5 = new TH1F("Graph5","Graph",100,899.9,901.1);
   Graph5->SetMinimum(0.4184);
   Graph5->SetMaximum(0.4616);
   gre->SetHistogram(Graph5);
   gre->SetMarkerSize(msize*1.2);
   gre->Draw("pz");
   
   TGraph* gre05 = gre->Clone("gre05");
   gre05->SetMarkerStyle(0);
   //   gre05->Draw("pzsame");
   
   /*
   // Fit function
   //TF1 *func = new TF1("func","0.426-0.0198*log(x^2)+0.00156*log(x^2)^2",18,100000);
   //TF1 *func = new TF1("func","0.430-0.0207*log(x^2)+0.00161*log(x^2)^2",18,100000);  
   TF1 *func = new TF1("func","0.425-0.0197*log(x^2)+0.00156*log(x^2)^2",18,100000);  
   func->SetLineColor(1);
   func->SetLineWidth(1.5);
   func->Draw("same");
   */

   TLegend *leg = new TLegend(0.25,0.90-0.045*5,0.5,0.90,NULL,"brNDC");
   leg->SetBorderSize(0);
   leg->SetTextFont(62);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   leg->SetTextSize(0.03);

   TLegendEntry *entry=leg->AddEntry("Graph1","ISR inel.","P");
   entry->SetMarkerStyle(28);
   entry->SetMarkerSize(msize);
   entry=leg->AddEntry("Graph2","UA1 NSD","P");
   entry->SetMarkerStyle(3);   
   entry->SetMarkerSize(msize);   

   entry=leg->AddEntry("Graph3","E735 NSD","P");
   entry->SetMarkerStyle(22);   
   entry->SetMarkerSize(msize); 

   entry=leg->AddEntry("Graph4","CDF NSD","P");
   entry->SetMarkerStyle(21);    
   entry->SetMarkerSize(msize);    

   entry=leg->AddEntry("Graph5","CMS NSD (|#eta|<2.4)","P");
   entry->SetMarkerStyle(20);  
   entry->SetMarkerColor(kRed+2);
   entry->SetMarkerSize(msize*1.0);  
   leg->Draw();  

   TLegend *leg2 = new TLegend(0.35,0.20,0.91,0.26,NULL,"brNDC");
   //TLegend *leg2 = new TLegend(0.411,0.18,0.91,0.33,NULL,"brNDC");     
   leg2->SetBorderSize(0);
   leg2->SetTextFont(62);
   leg2->SetTextSize(0.035);
   leg2->SetLineColor(1);
   leg2->SetLineStyle(1);
   leg2->SetLineWidth(1);
   leg2->SetFillColor(0);
   leg2->SetFillStyle(0);
   leg2->SetMargin(0.15);
   leg2->SetTextSize(0.03);

   //   TLegendEntry *entry=leg2->AddEntry("func","0.40 - 0.015 #times ln(s) + 0.001325 #times ln^{2}(s)","l");
   //TLegendEntry *entry=leg2->AddEntry("func","0.40 - 0.015 ln(s) + 0.001325 ln^{2}(s)","l");
   TLegendEntry *entry=leg2->AddEntry("func","0.425 - 0.0197 ln(s) + 0.00156 ln^{2}(s)","l");
   //TLegendEntry *entry=leg2->AddEntry("func","0.430 - 0.0207 ln(s) + 0.00161 ln^{2}(s)","l");


   entry->SetTextSize(0.03);
   entry->SetMarkerSize(0);
   leg2->Draw();

   printFinalCanvases(MyCanvas,"apt_all");

}
Beispiel #13
0
GenVBosonPlot(TString name, int rebin,float min = -1,float max =0, bool log=false){

  //  TCanvas* aCan = new TCanvas(name,name,0.6,0.6,0.8,0.8);

  TCanvas* aCan = new TCanvas(name);
  aCan->Divide(2,1);
  aCan->cd(1);
  if(log) aCan->SetLogy();
  // int rebin= 10;
  TFile* W = new TFile("results5/IC5Calo_WJets_madgraph.root");
  //W->ls();
  TDirectory* Wdir = ( TDirectory*) W->Get("GenVBoson200");
  Wdir->ls();
  TH1D* Wh = (TH1D*) Wdir->Get(name);
  Wh->Rebin(rebin);
  Wh->SetLineWidth(2);
  Wh->SetLineStyle(2);
  //  Wh->
  if(min>-.2)  Wh->GetXaxis()->SetRangeUser(min,max);
 
  Wh->DrawNormalized();
  //cout << Wh->GetMaximum() <<endl;
  Wh->GetXaxis()->SetRangeUser(0.00001,1);

  //  Wh->SetMaximum( Wh->GetMaximum()*1.75);


  TFile* Z = new TFile("results5/IC5Calo_Zinvisible_jets.root");
  //Z->ls();
  TDirectory* Zdir = ( TDirectory*) Z->Get("GenVBoson200");
  //  Zdir->ls();
  TH1D* Zh = (TH1D*) Zdir->Get(name);
  Zh->SetLineColor(kRed);
  Zh->SetLineWidth(2);
  Zh->SetLineStyle(2);

  Zh->Rebin(rebin);
  Zh->DrawNormalized("same");

  TFile* Ph = new TFile("results5/photon.root");
  Ph->ls();
  TDirectory* Phdir = ( TDirectory*) Ph->Get("GenVBoson200");
  // Phdir->ls();
  TH1D* Phh = (TH1D*) Phdir->Get(name);
  Phh->SetLineColor(kBlue);
  Phh->SetLineWidth(2);
  Phh->Rebin(rebin);
  Phh->DrawNormalized("same"); 

  TLegend* leg = new TLegend(0.5,0.5,0.7,0.7);
  leg->AddEntry(Zh,"Z","l" );
  leg->AddEntry(Wh,"W","l" );
  leg->AddEntry(Phh,"#gamma","l" );
  leg->Draw("same");

  aCan->cd(1);

  TH1D*  DivPhh = Phh->Clone();
  DivPhh->Divide(Zh);
  TH1D*  DivWh = Wh->Clone();
  DivWh->Divide(Zh);
  DivPhh->Draw();
DivWh->Draw("same");

}
Beispiel #14
0
void TSVDUnfoldExample()
{
   gROOT->Reset();
   gROOT->SetStyle("Plain");
   gStyle->SetOptStat(0);

   TRandom3 R;

   const Double_t cutdummy= -99999.0;

   // --- Data/MC toy generation -----------------------------------

   // The MC input
   Int_t nbins = 40;
   TH1D *xini = new TH1D("xini", "MC truth", nbins, -10.0, 10.0);
   TH1D *bini = new TH1D("bini", "MC reco", nbins, -10.0, 10.0);
   TH2D *Adet = new TH2D("Adet", "detector response", nbins, -10.0, 10.0, nbins, -10.0, 10.0);

   // Data
   TH1D *data = new TH1D("data", "data", nbins, -10.0, 10.0);
   // Data "truth" distribution to test the unfolding
   TH1D *datatrue = new TH1D("datatrue", "data truth", nbins, -10.0, 10.0);
   // Statistical covariance matrix
   TH2D *statcov = new TH2D("statcov", "covariance matrix", nbins, -10.0, 10.0, nbins, -10.0, 10.0);

   // Fill the MC using a Breit-Wigner, mean 0.3 and width 2.5.
   for (Int_t i= 0; i<100000; i++) {
      Double_t xt = R.BreitWigner(0.3, 2.5);
      xini->Fill(xt);
      Double_t x = Reconstruct( xt, R );
      if (x != cutdummy) {
         Adet->Fill(x, xt);
         bini->Fill(x);
      }
   }

   // Fill the "data" with a Gaussian, mean 0 and width 2.
   for (Int_t i=0; i<10000; i++) {
      Double_t xt = R.Gaus(0.0, 2.0);
      datatrue->Fill(xt);
      Double_t x = Reconstruct( xt, R );
      if (x != cutdummy)
      data->Fill(x);
   }

   cout << "Created toy distributions and errors for: " << endl;
   cout << "... \"true MC\"   and \"reconstructed (smeared) MC\"" << endl;
   cout << "... \"true data\" and \"reconstructed (smeared) data\"" << endl;
   cout << "... the \"detector response matrix\"" << endl;

   // Fill the data covariance matrix
   for (int i=1; i<=data->GetNbinsX(); i++) {
       statcov->SetBinContent(i,i,data->GetBinError(i)*data->GetBinError(i));
   }

   // --- Here starts the actual unfolding -------------------------

   // Create TSVDUnfold object and initialise
   TSVDUnfold *tsvdunf = new TSVDUnfold( data, statcov, bini, xini, Adet );

   // It is possible to normalise unfolded spectrum to unit area
   tsvdunf->SetNormalize( kFALSE ); // no normalisation here

   // Perform the unfolding with regularisation parameter kreg = 13
   // - the larger kreg, the finer grained the unfolding, but the more fluctuations occur
   // - the smaller kreg, the stronger is the regularisation and the bias
   TH1D* unfres = tsvdunf->Unfold( 13 );

   // Get the distribution of the d to cross check the regularization
   // - choose kreg to be the point where |d_i| stop being statistically significantly >>1
   TH1D* ddist = tsvdunf->GetD();

   // Get the distribution of the singular values
   TH1D* svdist = tsvdunf->GetSV();

   // Compute the error matrix for the unfolded spectrum using toy MC
   // using the measured covariance matrix as input to generate the toys
   // 100 toys should usually be enough
   // The same method can be used for different covariance matrices separately.
   TH2D* ustatcov = tsvdunf->GetUnfoldCovMatrix( statcov, 100 );

   // Now compute the error matrix on the unfolded distribution originating
   // from the finite detector matrix statistics
   TH2D* uadetcov = tsvdunf->GetAdetCovMatrix( 100 );

   // Sum up the two (they are uncorrelated)
   ustatcov->Add( uadetcov );

   //Get the computed regularized covariance matrix (always corresponding to total uncertainty passed in constructor) and add uncertainties from finite MC statistics.
   TH2D* utaucov = tsvdunf->GetXtau();
   utaucov->Add( uadetcov );

   //Get the computed inverse of the covariance matrix
   TH2D* uinvcov = tsvdunf->GetXinv();


   // --- Only plotting stuff below ------------------------------

   for (int i=1; i<=unfres->GetNbinsX(); i++) {
      unfres->SetBinError(i, TMath::Sqrt(utaucov->GetBinContent(i,i)));
   }

   // Renormalize just to be able to plot on the same scale
   xini->Scale(0.7*datatrue->Integral()/xini->Integral());

   TLegend *leg = new TLegend(0.58,0.68,0.99,0.88);
   leg->SetBorderSize(0);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   leg->AddEntry(unfres,"Unfolded Data","p");
   leg->AddEntry(datatrue,"True Data","l");
   leg->AddEntry(data,"Reconstructed Data","l");
   leg->AddEntry(xini,"True MC","l");

   TCanvas *c1 = new TCanvas( "c1", "Unfolding toy example with TSVDUnfold", 900, 800 );

   // --- Style settings -----------------------------------------
   Int_t c_Canvas    = TColor::GetColor( "#f0f0f0" );
   Int_t c_FrameFill = TColor::GetColor( "#fffffd" );
   Int_t c_TitleBox  = TColor::GetColor( "#6D7B8D" );
   Int_t c_TitleText = TColor::GetColor( "#FFFFFF" );

   c1->SetFrameFillColor( c_FrameFill );
   c1->SetFillColor     ( c_Canvas    );
   c1->Divide(1,2);
   TVirtualPad * c11 = c1->cd(1);
   c11->SetFrameFillColor( c_FrameFill );
   c11->SetFillColor     ( c_Canvas    );

   gStyle->SetTitleFillColor( c_TitleBox  );
   gStyle->SetTitleTextColor( c_TitleText );
   gStyle->SetTitleBorderSize( 1 );
   gStyle->SetTitleH( 0.052 );
   gStyle->SetTitleX( c1->GetLeftMargin() );
   gStyle->SetTitleY( 1 - c1->GetTopMargin() + gStyle->GetTitleH() );
   gStyle->SetTitleW( 1 - c1->GetLeftMargin() - c1->GetRightMargin() );

   TH1D* frame = new TH1D( *unfres );
   frame->SetTitle( "Unfolding toy example with TSVDUnfold" );
   frame->GetXaxis()->SetTitle( "x variable" );
   frame->GetYaxis()->SetTitle( "Events" );
   frame->GetXaxis()->SetTitleOffset( 1.25 );
   frame->GetYaxis()->SetTitleOffset( 1.29 );
   frame->Draw();

   data->SetLineStyle(2);
   data->SetLineColor(4);
   data->SetLineWidth(2);
   unfres->SetMarkerStyle(20);
   datatrue->SetLineColor(2);
   datatrue->SetLineWidth(2);
   xini->SetLineStyle(2);
   xini->SetLineColor(8);
   xini->SetLineWidth(2);
   // ------------------------------------------------------------

   // add histograms
   unfres->Draw("same");
   datatrue->Draw("same");
   data->Draw("same");
   xini->Draw("same");

   leg->Draw();

   // covariance matrix
   gStyle->SetPalette(1,0);
   TVirtualPad * c12 = c1->cd(2);
   c12->Divide(2,1);
   TVirtualPad * c2 = c12->cd(1);
   c2->SetFrameFillColor( c_FrameFill );
   c2->SetFillColor     ( c_Canvas    );
   c2->SetRightMargin   ( 0.15         );

   TH2D* covframe = new TH2D( *ustatcov );
   covframe->SetTitle( "TSVDUnfold covariance matrix" );
   covframe->GetXaxis()->SetTitle( "x variable" );
   covframe->GetYaxis()->SetTitle( "x variable" );
   covframe->GetXaxis()->SetTitleOffset( 1.25 );
   covframe->GetYaxis()->SetTitleOffset( 1.29 );
   covframe->Draw();

   ustatcov->SetLineWidth( 2 );
   ustatcov->Draw( "colzsame" );

   // distribution of the d quantity
   TVirtualPad * c3 = c12->cd(2);
   c3->SetFrameFillColor( c_FrameFill );
   c3->SetFillColor     ( c_Canvas    );
   c3->SetLogy();

   TLine *line = new TLine( 0.,1.,40.,1. );
   line->SetLineStyle(2);

   TH1D* dframe = new TH1D( *ddist );
   dframe->SetTitle( "TSVDUnfold |d_{i}|" );
   dframe->GetXaxis()->SetTitle( "i" );
   dframe->GetYaxis()->SetTitle( "|d_{i}|" );
   dframe->GetXaxis()->SetTitleOffset( 1.25 );
   dframe->GetYaxis()->SetTitleOffset( 1.29 );
   dframe->SetMinimum( 0.001 );
   dframe->Draw();

   ddist->SetLineWidth( 2 );
   ddist->Draw( "same" );
   line->Draw();
}
Beispiel #15
0
void PlotAll(TString wsname)
{
	char* binLabels[19] = {"60","70","80","90","100","110","120","130","140","150","160","170","180","190","200","250","300","400","1000"};	

	//get the stuff from the workspace:
	
	TFile* file=TFile::Open(wsname);
	RooWorkspace* ws = (RooWorkspace*)file->Get("combined");
	ModelConfig  *mc = (ModelConfig*)ws->obj("ModelConfig");
	RooAbsData   *data = ws->data("obsData");
	RooSimultaneous* simPdf=(RooSimultaneous*)(mc->GetPdf());
	RooAbsReal* nll=simPdf->createNLL(*data);

	// FPT 0 **************************************	
	// EM channel
	
	RooCategory* chanCat = (RooCategory*) (&simPdf->indexCat());
        TIterator* iterat = chanCat->typeIterator() ;
        RooCatType* ttype = (RooCatType*)iterat->Next();

	RooAbsPdf  *pdf_stateEM  = simPdf->getPdf(ttype->GetName()) ;
	RooArgSet  *obstmpEM  = pdf_stateEM->getObservables( *mc->GetObservables() ) ;
	
	// get EM data
       	RooAbsData *dataEM = data->reduce(Form("%s==%s::%s",chanCat->GetName(),chanCat->GetName(),ttype->GetName()));
		
	RooRealVar *obsEM     = ((RooRealVar*) obstmpEM->first());
	TString chanName1(ttype->GetName());

	// create data histogram
	TH1* hdataEM = dataEM->createHistogram("Data "+chanName1,*obsEM);
	// set errors to gaussian
        for (int ib=0 ; ib<hdataEM->GetNbinsX()+1 ; ib++) hdataEM->SetBinError(ib, sqrt(hdataEM->GetBinContent(ib)));

	double EMnorm = pdf_stateEM->expectedEvents(*obsEM);
	
	//****************************
	// ME channel
	ttype = (RooCatType*)iterat->Next();
	RooAbsPdf* pdf_stateME  = simPdf->getPdf(ttype->GetName()) ;
        RooArgSet* obstmpME  = pdf_stateME->getObservables( *mc->GetObservables() ) ;

	// get ME data
	RooAbsData *dataME = data->reduce(Form("%s==%s::%s",chanCat->GetName(),chanCat->GetName(),ttype->GetName()));	
	RooRealVar* obsME = ((RooRealVar*) obstmpME->first());
	TString chanName2(ttype->GetName());

        // create data histogram
        TH1* hdataME = dataME->createHistogram("Data "+chanName2,*obsME);
        // set errors to gaussian
        for (int ib=0 ; ib<hdataME->GetNbinsX()+1 ; ib++) hdataME->SetBinError(ib, sqrt(hdataME->GetBinContent(ib)));
        
	
	// get initial BG histogram
	//TH1* h_initial_BG_EM = pdf_stateEM->createHistogram("initial_BG_EM",*obsEM);
	//TH1* h_initial_BG_ME = pdf_stateME->createHistogram("initial_BG_ME",*obsME);
	
	double MEnorm = pdf_stateME->expectedEvents(*obsME);
	cout << "EM expected events = " << EMnorm << ", ME expected events = " << MEnorm << "." << endl;
	//h_initial_BG_EM->Scale(EMnorm);
	//h_initial_BG_ME->Scale(MEnorm);	

	// get initial gammas
	int nbins = hdataEM->GetNbinsX();
        double InitGamma[nbins];
        for (int i=0; i<nbins; i++)
        {
               	TString varname = "gamma_B0_l1pt0_bin_"+NumberToString(i);
               	InitGamma[i] = ws->var(varname)->getVal();
               	cout << "initial gamma"+NumberToString(i)+" = " << InitGamma[i] << endl;
        }
        double InitFpt = ws->var("fl1pt_l1pt0")->getVal();
        cout << "initial fpt_l1pt0 = " << InitFpt <<  endl;


	// DO THE GLOBAL FIT
	
	minimize(nll);	
       
	// get final BG histograms
	TH1* h_final_BG_EM = pdf_stateEM->createHistogram("final_BG_EM",*obsEM);
        TH1* h_final_BG_ME = pdf_stateME->createHistogram("final_BG_ME",*obsME); 
	h_final_BG_EM->Scale(EMnorm);
	h_final_BG_ME->Scale(MEnorm);
	
	// uncertainty bands
	TH1D* BuncertaintyEM = new TH1D("BuncertaintyEM","BuncertaintyEM",nbins,0,nbins);
	TH1D* BuncertaintyME = new TH1D("BuncertaintyME","BuncertaintyME",nbins,0,nbins);
	for (int i=1; i<=nbins; i++){
		double sigbEM = h_final_BG_EM->GetBinError(i);
		double bEM = h_final_BG_EM->GetBinContent(i);
		BuncertaintyEM->SetBinError(i,sigbEM); BuncertaintyEM->SetBinContent(i,bEM);
		double sigbME = h_final_BG_ME->GetBinError(i);
                double bME = h_final_BG_ME->GetBinContent(i);
                BuncertaintyME->SetBinError(i,sigbME); BuncertaintyME->SetBinContent(i,bME);
	}
	//BuncertaintyEM->SetFillStyle(3004); 
	BuncertaintyEM->SetFillColor(kGreen-9);
	BuncertaintyEM->SetLineColor(kBlack); BuncertaintyEM->SetLineStyle(2);
	//BuncertaintyME->SetFillStyle(3004); 
	BuncertaintyME->SetFillColor(kBlue-9);
        BuncertaintyME->SetLineColor(kBlack); BuncertaintyME->SetLineStyle(2);

	// get gammas after fit
	double FinalGamma[nbins];
	//TH1* h_initBG_times_gamma = (TH1*)h_initial_BG_EM->Clone("initBGEM_times_gamma");
	for (int i=0; i<nbins; i++)
       	{
               	TString varname = "gamma_B0_l1pt0_bin_"+NumberToString(i);
               	FinalGamma[i] = ws->var(varname)->getVal();
               	cout << "Final gamma in bin "+NumberToString(i)+" = " << FinalGamma[i] << endl;
       	//	h_initBG_times_gamma->SetBinContent(i+1,h_initial_BG_EM->GetBinContent(i+1)*FinalGamma[i]);
	}
	//double FinalFpt = ws->var("fl1pt_l1pt0")->getVal();
	
	// get final alpha (pull)
	RooRealVar* alphaVar = ws->var("alpha_l1ptsys_l1pt0");
	double alpha, alphaErr;
	if (alphaVar != NULL) {
		alpha = ws->var("alpha_l1ptsys_l1pt0")->getVal();
		alphaErr = ws->var("alpha_l1ptsys_l1pt0")->getError();
	}

	//FOR UNCONSTRAINED FPT - get final fpts
	double FinalFpt[5];
	double FinalFptErr[5];
	for (int k=0; k<5; k++){
		TString varname = "fl1pt_l1pt"+NumberToString(k);
		FinalFpt[k] = ws->var(varname)->getVal();
		FinalFptErr[k] =  ws->var(varname)->getError();
		cout << varname << " = "  << FinalFpt[k] << " +- " << FinalFptErr[k] << endl;
	}
	
	// get POI value
	double mu = ws->var("mu_BR_htm")->getVal();
	double muErr = ws->var("mu_BR_htm")->getError();
	
	// Draw
	TCanvas* c1 = new TCanvas("BG and Data "+chanName1+" "+chanName2,"BG and Data "+chanName1+" "+chanName2,600,600);
	BuncertaintyEM->Draw("E3 sames"); BuncertaintyME->Draw("E3 sames");
	//h_initial_BG_EM->SetLineColor(kGreen+2); h_initial_BG_EM->SetLineStyle(2); h_initial_BG_EM->Draw("sames");
	hdataEM->SetLineColor(kGreen+2); hdataEM->SetMarkerStyle(20); hdataEM->SetMarkerColor(kGreen+2);
	hdataEM->Draw("e1 sames");
	//h_initial_BG_ME->SetLineColor(kBlue); h_initial_BG_ME->SetLineStyle(2); h_initial_BG_ME->Draw("sames");
        hdataME->SetLineColor(kBlue); hdataME->SetMarkerStyle(20);  hdataME->SetMarkerColor(kBlue);
	hdataME->Draw("e1 sames");

	h_final_BG_EM->SetLineColor(kGreen+2); h_final_BG_EM->SetLineWidth(2); h_final_BG_EM->Draw("sames");
	h_final_BG_ME->SetLineColor(kBlue); h_final_BG_ME->SetLineWidth(2); h_final_BG_ME->Draw("sames");

	TLegend* leg = new TLegend(0.5,0.45,0.85,0.65);
        leg->SetFillColor(kWhite); leg->SetBorderSize(1); leg->SetLineColor(0); //leg->SetTextFont(14);
        leg->SetTextSize(.03);

	leg->AddEntry(hdataME,"DATA #mue","lep");
	leg->AddEntry(hdataEM,"DATA e#mu","lep");
	//leg->AddEntry(h_initial_BG_ME,"Initial #mue PDF","l");
	//leg->AddEntry(h_initial_BG_EM,"Initial e#mu PDF","l");
	leg->AddEntry(h_final_BG_ME,"#mue PDF = #gamma_{i}B_{i} + #muS_{i}","l");
	leg->AddEntry(h_final_BG_EM,"e#mu PDF = f(1+#alpha#sigma)(#gamma_{i}B_{i}+#muW_{i})","l");
	leg->Draw();

	cout << " ********************* Fit Values **************************** " <<  endl;
	if (alphaVar != NULL){cout << "alpha = " << alpha << " +- " << alphaErr << endl;}
	cout << "mu    = " << mu << " +- " << muErr << endl;

	TString WriteDownAlphaValue;
	TString WriteDownMuValue;
	WriteDownAlphaValue = "Fpt0 = ";
	WriteDownMuValue = "#mu = ";
	WriteDownAlphaValue += Form("%4.4f",FinalFpt[0]);
	WriteDownAlphaValue += "#pm";
	WriteDownAlphaValue += Form("%4.4f",FinalFptErr[0]);
	WriteDownMuValue += Form("%4.4f",mu);
        WriteDownMuValue += "#pm";
        WriteDownMuValue += Form("%4.4f",muErr);

	TLatex *texl = new TLatex(12,25,WriteDownAlphaValue);
   	texl->SetTextAlign(22); texl->SetTextSize(0.03); 
   	TLatex *texl2 = new TLatex(12,23,WriteDownMuValue);
        texl2->SetTextAlign(22); texl2->SetTextSize(0.03);
	texl->Draw(); 
	texl2->Draw();



	//FPT 1 ***********************************
	ttype = (RooCatType*)iterat->Next();

        RooAbsPdf  *pdf_stateEM1  = simPdf->getPdf(ttype->GetName()) ;
        RooArgSet  *obstmpEM1  = pdf_stateEM1->getObservables( *mc->GetObservables() ) ;
	RooAbsData *dataEM1 = data->reduce(Form("%s==%s::%s",chanCat->GetName(),chanCat->GetName(),ttype->GetName()));

        RooRealVar *obsEM1     = ((RooRealVar*) obstmpEM1->first());
        TString chanName11(ttype->GetName());	
	TH1* hdataEM1 = dataEM1->createHistogram("Data "+chanName11,*obsEM1);
	for (int ib=0 ; ib<hdataEM1->GetNbinsX()+1 ; ib++) hdataEM1->SetBinError(ib, sqrt(hdataEM1->GetBinContent(ib)));

        double EMnorm1 = pdf_stateEM1->expectedEvents(*obsEM1);
	ttype = (RooCatType*)iterat->Next();
        RooAbsPdf* pdf_stateME1  = simPdf->getPdf(ttype->GetName()) ;
        RooArgSet* obstmpME1  = pdf_stateME1->getObservables( *mc->GetObservables() ) ;
	RooAbsData *dataME1 = data->reduce(Form("%s==%s::%s",chanCat->GetName(),chanCat->GetName(),ttype->GetName()));
        RooRealVar* obsME1 = ((RooRealVar*) obstmpME1->first());
        TString chanName21(ttype->GetName());
	TH1* hdataME1 = dataME1->createHistogram("Data "+chanName21,*obsME1);

	for (int ib=0 ; ib<hdataME1->GetNbinsX()+1 ; ib++) hdataME1->SetBinError(ib, sqrt(hdataME1->GetBinContent(ib)));
	double MEnorm1 = pdf_stateME1->expectedEvents(*obsME1);
	TH1* h_final_BG_EM1 = pdf_stateEM1->createHistogram("final_BG_EM1",*obsEM1);
        TH1* h_final_BG_ME1 = pdf_stateME1->createHistogram("final_BG_ME1",*obsME1);
        h_final_BG_EM1->Scale(EMnorm1);
        h_final_BG_ME1->Scale(MEnorm1);
	TH1D* BuncertaintyEM1 = new TH1D("BuncertaintyEM1","BuncertaintyEM1",nbins,0,nbins);
        TH1D* BuncertaintyME1 = new TH1D("BuncertaintyME1","BuncertaintyME1",nbins,0,nbins);
        for (int i=1; i<=nbins; i++){
                double sigbEM = h_final_BG_EM1->GetBinError(i);
                double bEM = h_final_BG_EM1->GetBinContent(i);
                BuncertaintyEM1->SetBinError(i,sigbEM); BuncertaintyEM1->SetBinContent(i,bEM);
                double sigbME = h_final_BG_ME1->GetBinError(i);
                double bME = h_final_BG_ME1->GetBinContent(i);
                BuncertaintyME1->SetBinError(i,sigbME); BuncertaintyME1->SetBinContent(i,bME);
        }
	BuncertaintyEM1->SetFillColor(kGreen-9);
        BuncertaintyEM1->SetLineColor(kBlack); BuncertaintyEM1->SetLineStyle(2);
	BuncertaintyME1->SetFillColor(kBlue-9);
        BuncertaintyME1->SetLineColor(kBlack); BuncertaintyME1->SetLineStyle(2);
	double FinalGamma1[nbins];
        for (int i=0; i<nbins; i++)
        {
                TString varname = "gamma_B0_l1pt1_bin_"+NumberToString(i);
                FinalGamma1[i] = ws->var(varname)->getVal();
                cout << "Final gamma in bin "+NumberToString(i)+" = " << FinalGamma1[i] << endl;
        }
	TCanvas* c2 = new TCanvas("BG and Data "+chanName11+" "+chanName21,"BG and Data "+chanName11+" "+chanName21,600,600);
        BuncertaintyEM1->Draw("E3 sames"); BuncertaintyME1->Draw("E3 sames");
        hdataEM1->SetLineColor(kGreen+2); hdataEM1->SetMarkerStyle(20); hdataEM1->SetMarkerColor(kGreen+2);
        hdataEM1->Draw("e1 sames");
        hdataME1->SetLineColor(kBlue); hdataME1->SetMarkerStyle(20);  hdataME1->SetMarkerColor(kBlue);
        hdataME1->Draw("e1 sames");

        h_final_BG_EM1->SetLineColor(kGreen+2); h_final_BG_EM1->SetLineWidth(2); h_final_BG_EM1->Draw("sames");
        h_final_BG_ME1->SetLineColor(kBlue); h_final_BG_ME1->SetLineWidth(2); h_final_BG_ME1->Draw("sames");

        leg->Draw();

        cout << " ********************* Fit Values **************************** " <<  endl;
        cout << "mu    = " << mu << " +- " << muErr << endl;
	TString WriteDownAlphaValue1;
        WriteDownAlphaValue1 = "Fpt1 = ";
        WriteDownAlphaValue1 += Form("%4.4f",FinalFpt[1]);
        WriteDownAlphaValue1 += "#pm";
        WriteDownAlphaValue1 += Form("%4.4f",FinalFptErr[1]);

        TLatex *texl11 = new TLatex(12,25,WriteDownAlphaValue1);
        texl11->SetTextAlign(22); texl11->SetTextSize(0.03);
        texl11->Draw(); 
        texl2->Draw();

}
Beispiel #16
0
void sysError(
    TString inFileName="jfh_HCPR_J50U_Cent30to100_Aj0to100_SubEtaRefl.root",
    Int_t compMode = 0, // Compare mode: 0 reco-genSig, 1 reco-genAll, 3 genAll-genSig, 4 calo_genp-allGen
    Int_t sysMode = 0, // Plot mode: 0 for simple plot, 1 for difference
    TString outdir = ".",
    TString title = "test"
    ) {
  // ===============================================
  // Inputs
  // ===============================================
  TFile *f = new TFile(inFileName);
  TString inFileNameStrip(inFileName); inFileNameStrip.ReplaceAll(".root","");
  TString inFileNameGen(inFileName);
  if (compMode==0) { 
    inFileNameGen.ReplaceAll("djcalo","djcalo_genp");
    inFileNameGen.ReplaceAll("HydjetAll","HydjetSig");
  }
  if (compMode==1) inFileNameGen.ReplaceAll("djcalo","djcalo_genp");
  else if (compMode==3) inFileNameGen.ReplaceAll("HydjetAll","HydjetSig");
  else if (compMode==5) inFileNameGen.ReplaceAll("djcalo_genp","djgen");
  TFile *fgen = new TFile(inFileNameGen);
  TString inFileNameStripGen(inFileNameGen); inFileNameStripGen.ReplaceAll(".root","");
  cout << "==========================================================" << endl;
  cout << "Compare: " << inFileName << endl
       << "         vs " << endl
       << "         " << inFileNameGen << endl;
  cout << "==========================================================" << endl;

  // ===============================================
  // Setup
  // ===============================================
  TString tag=Form("sysError_%s_%s_%d_%d",inFileNameStrip.Data(),title.Data(),compMode,sysMode);

  // ===============================================
  // Analyze
  // ===============================================
  TH2D * hPtPNDR = (TH2D*) f->Get("hPtPNDR");
  TH2D * hPtPADR = (TH2D*) f->Get("hPtPADR");
  TH2D * hPtPNDRBg = (TH2D*) f->Get("hPtPNDRBg");
  TH2D * hPtPADRBg = (TH2D*) f->Get("hPtPADRBg");
  TH2D * hPtPNDRSub = (TH2D*)hPtPNDR->Clone(tag+"hPtPNDRSub");
  TH2D * hPtPADRSub = (TH2D*)hPtPADR->Clone(tag+"hPtPADRSub");
  hPtPNDRSub->Add(hPtPNDR,hPtPNDRBg,1,-1);
  hPtPADRSub->Add(hPtPADR,hPtPADRBg,1,-1);

  TH2D * hPtPNDRGen = (TH2D*) fgen->Get("hPtPNDR");
  TH2D * hPtPADRGen = (TH2D*) fgen->Get("hPtPADR");
  TH2D * hPtPNDRBgGen = (TH2D*) fgen->Get("hPtPNDRBg");
  TH2D * hPtPADRBgGen = (TH2D*) fgen->Get("hPtPADRBg");
  TH2D * hPtPNDRSubGen = (TH2D*)hPtPNDRGen->Clone(tag+"hPtPNDRSub");
  TH2D * hPtPADRSubGen = (TH2D*)hPtPADRGen->Clone(tag+"hPtPADRSub");
  hPtPNDRSubGen->Add(hPtPNDRGen,hPtPNDRBgGen,1,-1);
  hPtPADRSubGen->Add(hPtPADRGen,hPtPADRBgGen,1,-1);

  // ===============================================
  // Draw
  // ===============================================
  // Get Pt info
  Int_t numPtBins=hPtPNDR->GetNbinsX();
  TH1D * hPt = (TH1D*)hPtPNDR->ProjectionX("hPt");
  /*
  cout << "Pt bins: " << numPtBins << endl;
  for (Int_t i=0; i<numPtBins+2; ++i) {
    cout << "Pt Bin " << i << " Low Edge: " << hPt->GetBinLowEdge(i) << endl;
  }
  */

  // What pt bins to draw
  const Int_t numPtBinsDraw=3;

  TCanvas * c6 = new TCanvas("c"+tag,"c"+tag,1400,500);
  c6->Divide(3,1);
  for (Int_t i=0; i<numPtBinsDraw; ++i) {
    Int_t iBeg,iEnd;
    if (i==0) { iBeg=2; iEnd=3;}
    if (i==1) { iBeg=4; iEnd=4;}
    if (i==2) { iBeg=5; iEnd=numPtBins;}
    cout << "Bin: " << iBeg <<  " to " << iEnd << endl;
    TH1D * hNr = (TH1D*)hPtPNDRSub->ProjectionY(tag+Form("hPNDRSub_%d_%d",iBeg,iEnd),iBeg,iEnd);
    TH1D * hAw = (TH1D*)hPtPADRSub->ProjectionY(tag+Form("hPADRSub_%d_%d",iBeg,iEnd),iBeg,iEnd);
    TH1D * hNrGen = (TH1D*)hPtPNDRSubGen->ProjectionY(tag+Form("hPNDRSubGen_%d_%d",iBeg,iEnd),iBeg,iEnd);
    TH1D * hAwGen = (TH1D*)hPtPADRSubGen->ProjectionY(tag+Form("hPADRSubGen_%d_%d",iBeg,iEnd),iBeg,iEnd);
    if (sysMode==1) {
      hNr->Add(hNrGen,-1);
      hAw->Add(hAwGen,-1);
    }
    if (sysMode==2) {
      hNr->Divide(hNrGen);
      hAw->Divide(hAwGen);
    }
    // Print
    cout << Form("%.1f < P_{T} < %.1f GeV: ",hPt->GetBinLowEdge(iBeg),hPt->GetBinLowEdge(iEnd+1))
      << " SigSubBkg Integral - Nr: " << hNr->Integral() << " Aw: " << hAw->Integral() << endl
      << " Gen - Nr: " << hNrGen->Integral() << " Aw: " << hAwGen->Integral() << endl;
    // Styles
    hNr->SetMarkerColor(kRed);
    hNr->SetLineColor(kRed);
    hAw->SetMarkerColor(kBlue);
    hAw->SetLineColor(kBlue);
    hAwGen->SetLineStyle(2);
    // Axis Range
    if (sysMode==0) {
      hNr->SetYTitle("Background Subtracted Signal (GeV/c)");
      hNr->SetAxisRange(-5,60,"Y");
    }
    if (sysMode==2) {
      hNr->SetAxisRange(-2,6,"Y");
    }
    // Axis Label
    if (compMode==0) {
      if (sysMode==1) {
	hNr->SetYTitle("(Reco Trk)-(Sig GenP) (GeV/c)");
	//hNr->SetAxisRange(-20,20,"Y");
      }
      if (sysMode==2) {
	hNr->SetYTitle("(Reco Trk)/(Sig GenP) (GeV/c)");
      }
    }
    if (compMode==3) {
      if (sysMode==1) {
	hNr->SetYTitle("All GenP - Sig GenP (GeV/c)");
	//hNr->SetAxisRange(-3,3,"Y");
      }
      if (sysMode==2) {
	hNr->SetYTitle("(All GenP)/(Sig GenP) (GeV/c)");
      }
    }
    hNr->SetXTitle("#Delta R");
    hNr->SetAxisRange(0,0.79999,"X");
    hNr->SetTitleOffset(1.5,"X");
    hNr->GetXaxis()->CenterTitle();
    hNr->GetYaxis()->CenterTitle();
    c6->cd(i+1);
    // Fit
    if (sysMode>0) {
      TF1 * f0 = new TF1("f0","pol0");
      f0->SetLineStyle(2);
      f0->SetLineWidth(1);
      hNr->Fit("f0");
      hAw->Fit("f0");
    }
    // Draw to Inspect
    hNr->Draw();
    hAw->Draw("same");
    if (sysMode==0) {
      hNrGen->Draw("hist same");
      hAwGen->Draw("hist same");
    }
    if (sysMode==0||sysMode==1) {
      TLine *l = new TLine(0,0,0.8,0);
      l->Draw();
    }
    if (sysMode==2) {
      TLine *l = new TLine(0,1,0.8,1);
      l->Draw();
    }
    
    TLegend *leg = new TLegend(0.35,0.7,0.85,0.94);
    leg->SetBorderSize(0);
    leg->SetFillStyle(0);
    leg->AddEntry(hNr,Form("%.1f < P_{T} < %.1f GeV",hPt->GetBinLowEdge(iBeg),hPt->GetBinLowEdge(iEnd+1)),"");
    if (sysMode==0) {
      if (compMode==0) {
	leg->AddEntry(hNr,"Leading (RecoTrk)","pl");
	leg->AddEntry(hNrGen,"Leading (Sig. GenP)","l");
	leg->AddEntry(hAw,"SubLeading (RecoTrk)","pl");
	leg->AddEntry(hAwGen,"SubLeading (Sig. GenP)","l");
      }
      if (compMode==1) {
	leg->AddEntry(hNr,"Leading (RecoTrk)","pl");
	leg->AddEntry(hNrGen,"Leading (All GenP)","l");
	leg->AddEntry(hAw,"SubLeading (RecoTrk)","pl");
	leg->AddEntry(hAwGen,"SubLeading (All GenP)","l");
      }
    }
    if (sysMode>0) {
      leg->AddEntry(hNr,"Leading","pl");
      leg->AddEntry(hAw,"SubLeading","pl");
    }
    leg->SetTextSize(0.05);
    leg->Draw();
  }

  // ===============================================
  // Save
  // ===============================================
  c6->Print(Form("%s/%s.gif",outdir.Data(),tag.Data()));
  c6->Print(Form("%s/%s.eps",outdir.Data(),tag.Data()));
  c6->Print(Form("%s/%s.C",outdir.Data(),tag.Data()));
}
Beispiel #17
0
void plotBalance(int cbin,
		 TString infname,
		 TString pythia,
		 TString mix,
		 bool drawXLabel,
		 bool drawLeg)
{

  bool showPbPb = 0;
  if(iPlot == 0 || iPlot == 3) showPbPb = 1;

  if(iPlot != 3) dijet = dijet&&deltaPhi;

  TCut centHF("");
  TCut centNtrk("");

  if(centMode == 0){
    cout<<"Obsolete centrality usage."<<endl;
    return;
    if(cbin==0) centHF = "bin>=20 && bin<26";
    if(cbin==1) centHF = "bin>=26 && bin<27";
    if(cbin==2) centHF = "bin>=27 && bin<28";
    if(cbin==3) centHF = "bin>=28 && bin<29";
    if(cbin==4) centHF = "bin>=29 && bin<31";
    if(cbin==5) centHF = "bin>=31";

    if(cbin==0) centNtrk = "ntrk >= 180";
    if(cbin==1) centNtrk = "150 <= ntrk && ntrk < 180";
    if(cbin==2) centNtrk = "110 <= ntrk && ntrk < 150";
    if(cbin==3) centNtrk = "90 <= ntrk && ntrk < 150";
    if(cbin==4) centNtrk = "60 <= ntrk && ntrk < 90";
    if(cbin==5) centNtrk = "ntrk < 60";
  }

  if(centMode == 1){
    centHF = hfPlusBins[cbin];
    centNtrk = centHF;
  }

  cout<<"plotting ntrk bin : "<<cbin<<endl;

  // open the data file

  if(iPlot > 100) entryMode = 1;

  string treeName = "ntdijet";
  string wName = "ntw";
  if(entryMode == 1){
    treeName = "ntjet";
    wName = "ntjetw";
  }

  if(entryMode == 2){
    treeName = "nttrk";
    wName = "nttrkw";
  }

  TFile *inf = new TFile(infname.Data());
  TTree *nt =(TTree*)inf->FindObjectAny(treeName.data());
  TTree *ntevt =(TTree*)inf->FindObjectAny("ntevt");
  if(entryMode < 1) nt->AddFriend(ntevt);

  // open the pythia (MC) file
  TFile *infReference = new TFile(pythia.Data());
  TTree *ntReference;
  TTree *ntevtReference;

  ntReference = (TTree*) infReference->FindObjectAny(treeName.data());
  ntevtReference = (TTree*) infReference->FindObjectAny("ntevt");
  if(entryMode < 1) ntReference->AddFriend(ntevtReference);
  
  // open the datamix file
  TFile *infMix = new TFile(mix.Data());
  TTree *ntMix =(TTree*)infMix->FindObjectAny(treeName.data());
  TTree *ntevtMix =(TTree*)infMix->FindObjectAny("ntevt");
  //  TFile *infW = new TFile("weights_hydjet.root");
  //  TTree *ntw =(TTree*)infW->FindObjectAny("ntw");

  TTree *ntw =(TTree*)infMix->FindObjectAny(wName.data());
  ntMix->AddFriend(ntw);
  if(entryMode < 1) ntMix->AddFriend(ntevtMix);

  int Nbin = 10;
  double max = 1.;
  double min = 0;

  if(iPlot == 1 || iPlot == 21 || iPlot == 22){
    Nbin = 20;
    max = 2;
    min = -2;
  };

  if(iPlot == 3){
    Nbin = 30;
    max = pi;
  };

  if(iPlot == 8){
    Nbin = 50;
    max = 25;
    min = -25;
  };

  if(iPlot == 9){
    Nbin = 50;
    max = 250;
  };

  if(iPlot == 11 || iPlot == 12){
    Nbin = 50;
    max = 25;
  };

  if(iPlot == 13 || iPlot == 14){
    Nbin = 75;
    max = 150;
  }

  if(iPlot == 101){
    Nbin = 20;
    max = 2;
    min = -2;
  }

  // projection histogram
  TH1D *h = new TH1D(Form("h",cbin),"",Nbin,min,max);
  TH1D *hReference = new TH1D(Form("hReference",cbin),"",Nbin,min,max);
  TH1D *hDataMix = new TH1D(Form("hDataMix",cbin),"",Nbin,min,max);

  TH1D *hB = new TH1D(Form("hB",cbin),"",Nbin,min,max);
  TH1D *hReferenceB = new TH1D(Form("hReferenceB",cbin),"",Nbin,min,max);
  TH1D *hDataMixB = new TH1D(Form("hDataMixB",cbin),"",Nbin,min,max);

  TH1D *hFull = new TH1D("hFull","",Nbin,min,max);
  TH1D *hReferenceFull = new TH1D("hReferenceFull","",Nbin,min,max);
  TH1D *hDataMixFull = new TH1D("hDataMixFull","",Nbin,min,max);

  TH1D* hNorm = new TH1D("hNorm","",1000,0,1000);
  TH1D* hNormReference = new TH1D("hNormReference","",1000,0,1000);
  TH1D* hNormDataMix = new TH1D("hNormDataMix","",1000,0,1000);

  hB->SetLineStyle(2);
  hReferenceB->SetLineStyle(2);
  hDataMixB->SetLineStyle(2);

  //  ntReference->SetAlias("pt1","et1");
  //  ntReference->SetAlias("pt2","et2");

  nt->SetAlias("pt1","jtpt1");
  nt->SetAlias("pt2","jtpt2");
  nt->SetAlias("eta1","jteta1");
  nt->SetAlias("eta2","jteta2");
  nt->SetAlias("phi1","jtphi1");
  nt->SetAlias("phi2","jtphi2");
  ntMix->SetAlias("pt1","jtpt1");
  ntMix->SetAlias("pt2","jtpt2");
  ntMix->SetAlias("eta1","jteta1");
  ntMix->SetAlias("eta2","jteta2");
  ntMix->SetAlias("phi1","jtphi1");
  ntMix->SetAlias("phi2","jtphi2");
  ntReference->SetAlias("pt1","jtpt1");
  ntReference->SetAlias("pt2","jtpt2");
  ntReference->SetAlias("eta1","jteta1");
  ntReference->SetAlias("eta2","jteta2");
  ntReference->SetAlias("phi1","jtphi1");
  ntReference->SetAlias("phi2","jtphi2");

  nt->SetAlias("cent","hfp");
  ntMix->SetAlias("cent","hfp");
  ntReference->SetAlias("cent","hfp");

  nt->SetAlias("dphi","acos(cos(phi1-phi2))");
  ntMix->SetAlias("dphi","acos(cos(phi1-phi2))");
  ntReference->SetAlias("dphi","acos(cos(phi1-phi2))");

  if(iPlot == 0){
    nt->SetAlias("var","pt2/pt1");
    ntReference->SetAlias("var","pt2/pt1");
    ntMix->SetAlias("var","pt2/pt1");
  }

  if(iPlot == 1){
    nt->SetAlias("var","(eta1+eta2)/2");
    ntReference->SetAlias("var","(eta1+eta2)/2");
    ntMix->SetAlias("var","(eta1+eta2)/2");
  }

  if(iPlot == 3){
    nt->SetAlias("var","acos(cos(phi1-phi2))");
    ntReference->SetAlias("var","acos(cos(phi1-phi2))");
    ntMix->SetAlias("var","acos(cos(phi1-phi2))");
  }

  if(iPlot == 8){
    nt->SetAlias("var","pu1-pu2");
    ntReference->SetAlias("var","pu1-pu2");
    ntMix->SetAlias("var","pu1-pu2");
  }

  if(iPlot == 11){
    nt->SetAlias("var","pu1");
    ntReference->SetAlias("var","pu1");
    ntMix->SetAlias("var","pu1");
  }

  if(iPlot == 12){
    nt->SetAlias("var","pu2");
    ntReference->SetAlias("var","pu2");
    ntMix->SetAlias("var","pu2");
  }

  if(iPlot == 13){
    nt->SetAlias("var","trkMax1");
    ntReference->SetAlias("var","trkMax1");
    ntMix->SetAlias("var","trkMax1");
  }

  if(iPlot == 14){
    nt->SetAlias("var","trkMax2");
    ntReference->SetAlias("var","trkMax2");
    ntMix->SetAlias("var","trkMax2");
  }

  if(iPlot == 9){
    nt->SetAlias("var","ntrk");
    ntReference->SetAlias("var","ntrk");
    ntMix->SetAlias("var","ntrk");
  }

  if(iPlot == 21){
    nt->SetAlias("var","eta1");
    ntReference->SetAlias("var","eta1");
    ntMix->SetAlias("var","eta1");
  }

  if(iPlot == 22){
    nt->SetAlias("var","eta2");
    ntReference->SetAlias("var","eta2");
    ntMix->SetAlias("var","eta2");
  }



  if(iPlot == 101){
    nt->SetAlias("var","eta");
    ntReference->SetAlias("var","eta");
    ntMix->SetAlias("var","eta");
  }

  if(iPlot == 51){
    nt->SetAlias("var","matchPt1/pt1");
    ntReference->SetAlias("var","matchPt1/pt1");
    ntMix->SetAlias("var","matchPt1/pt1");
  }

  if(iPlot == 52){
    nt->SetAlias("var","matchPt2/pt2");
    ntReference->SetAlias("var","matchPt2/pt2");
    ntMix->SetAlias("var","matchPt2/pt2");
  }


  nt->Draw("var>>hFull",dijet&&noise&&jetID&&centHF&&vtx); 
  nt->Draw("var>>hB",side&&noise&&jetID&&centHF&&vtx);
  nt->Draw("pt1>>hNorm",lead&&noise&&jetID&&centHF&&vtx);
   
  ntMix->Draw("var>>hDataMixFull",weight*(dijet&&jetID&&centHF&&vtx));
  ntMix->Draw("var>>hDataMixB",weight*(side&&jetID&&centHF&&vtx));
  ntMix->Draw("pt1>>hNormDataMix",weight*(lead&&jetID&&centHF&&vtx));
  
  ntReference->Draw("var>>hReferenceFull",dijet&&noise&&jetID&&centHF&&vtx);
  ntReference->Draw("var>>hReferenceB",side&&noise&&jetID&&centHF&&vtx);
  ntReference->Draw("pt1>>hNormReference",lead&&noise&&jetID&&centHF&&vtx);

  hDataMix->Add(hDataMixFull);
  h->Add(hFull);
  hReference->Add(hReferenceFull);

  if(subtract){
    hDataMix->Add(hDataMixB,-1);
    h->Add(hB,-1);
    hReference->Add(hReferenceB,-1);
  }

  hB->SetFillStyle(3005);
  hB->SetFillColor(15);

  // calculate the statistical error and normalize
  h->SetLineColor(dataColor);
  h->SetMarkerColor(dataColor);
  h->Sumw2();
  if(normLead){
    h->Scale(1./hNorm->Integral());
    hB->Scale(1./hNorm->Integral());
  }else{
    hB->Scale(1./h->Integral());
    h->Scale(1./h->Integral());
  }
  h->SetMarkerStyle(20);

  if(hReference->Integral() > 0){
    hReference->Scale(1./hNormReference->Integral());
  }

  hReference->SetLineColor(kBlue);
  hReference->SetFillColor(kAzure-8);
  hReference->SetFillStyle(3005);

  if(normLead){
    hDataMixB->Scale(1./hNormDataMix->Integral());
    hDataMix->Scale(1./hNormDataMix->Integral());
  }else{
    hDataMixB->Scale(1./hDataMix->Integral());
    hDataMix->Scale(1./hDataMix->Integral());
  }
  hDataMix->SetLineColor(mixColor);
  hDataMix->SetFillColor(mixColor);
  hDataMix->SetFillStyle(3004);
  
  hDataMix->SetMarkerSize(0);
  hDataMix->SetStats(0);

  hDataMix->GetXaxis()->SetLabelSize(22);
  hDataMix->GetXaxis()->SetLabelFont(43);
  hDataMix->GetXaxis()->SetTitleSize(28);
  hDataMix->GetXaxis()->SetTitleFont(43);
  hDataMix->GetXaxis()->SetTitleOffset(2.2);
  hDataMix->GetXaxis()->CenterTitle();
  
  
  hDataMix->GetYaxis()->SetLabelSize(22);
  hDataMix->GetYaxis()->SetLabelFont(43);
  hDataMix->GetYaxis()->SetTitleSize(28);
  hDataMix->GetYaxis()->SetTitleFont(43);
  hDataMix->GetYaxis()->SetTitleOffset(2.2);
  hDataMix->GetYaxis()->CenterTitle();
  
  if(drawXLabel) hDataMix->SetXTitle("A_{J} = (p_{T,1}-p_{T,2})/(p_{T,1}+p_{T,2})");  
  hDataMix->SetYTitle("Event Fraction");

  if(iPlot==1) hDataMix->SetXTitle("#eta_{dijet} = (#eta_{1}+#eta_{2})/2");
  if(iPlot==21) hDataMix->SetXTitle("#eta_{1}");
  if(iPlot==22) hDataMix->SetXTitle("#eta_{2}");

  if(iPlot==8) hDataMix->SetXTitle("p_{T,1}^{background}-p_{T,2}^{background}");
  if(iPlot==9) hDataMix->SetXTitle("N_{trk}^{offline}");

  if(iPlot==11) hDataMix->SetXTitle("p_{T,1}^{background}");
  if(iPlot==12) hDataMix->SetXTitle("p_{T,2}^{background}");

  if(iPlot==13) hDataMix->SetXTitle("p_{T} leading track in leading jet");
  if(iPlot==14) hDataMix->SetXTitle("p_{T} leading track in subleading jet");


  if(drawXLabel){
    if(iPlot==0) hDataMix->SetXTitle("p_{T,2}/p_{T,1}");
    if(iPlot==3) hDataMix->SetXTitle("#Delta #phi_{1,2}");
  }

  if(iPlot==0) hDataMix->SetMaximum(0.32);

  if(iPlot == 1 || iPlot==21 || iPlot==22){
    hDataMix->SetMaximum(0.3);
    hDataMix->SetMinimum(0);
  }


  if(iPlot==3){
    hDataMix->SetMaximum(2.52);
    hDataMix->SetMinimum(0.00004);
  }

  if(iPlot==8){
    hDataMix->SetMaximum(10);
    hDataMix->SetMinimum(0.00004);
  }

  if(iPlot==9){
    hDataMix->SetMaximum(0.15);
    hDataMix->SetMinimum(0.);
  }

  if(iPlot==11 || iPlot == 12){
    hDataMix->SetMaximum(10);
    hDataMix->SetMinimum(0.00004);
  }



  //hDataMix->GetXaxis()->SetNdivisions(905,true);
  hDataMix->GetYaxis()->SetNdivisions(505,true);

  hReference->SetMarkerColor(ppColor);
  hReference->SetLineColor(ppColor);
  hReference->SetMarkerStyle(25);

	hDataMix->Draw();//"hist");
	hDataMix->Draw("hist same");
	if(showPbPb) hReference->Draw("same");

	cout<<"PbPb ENTRIES : "<<endl;
	cout<<hReference->GetEntries()<<endl;

        cout<<"PbPb integral : "<<endl;
        cout<<hReference->Integral()<<endl;

	cout<<"pPb integral : "<<endl;
        cout<<h->Integral()<<endl;

	cout<<"Mix integral : "<<endl;
        cout<<hDataMix->Integral()<<endl;

	h->SetLineWidth(1);
	h->Draw("same");
	h->SetLineWidth(2);
	h->Draw("same");

	//	hDataMixB->Draw("same hist");
	//        hB->Draw("same hist");

	 cout<<" mean value of data "<<h->GetMean()<<endl;

  if(drawLeg){
    TLegend *t3=new TLegend(0.01,0.7,0.3,0.95);
    t3->AddEntry(h,"pPb #sqrt{s}=5.02 TeV","p");
    if(showPbPb) t3->AddEntry(hReference,"PbPb #sqrt{s}=2.76 TeV","p");
    t3->AddEntry(hDataMix,"PYTHIA+HIJING","lf");

    t3->SetFillColor(0);
    t3->SetBorderSize(0);
    t3->SetFillStyle(0);
    t3->SetTextFont(63);
    t3->SetTextSize(15);
    t3->Draw();
  }

}
Beispiel #18
0
void tight_loose_ratioplot()
{
  DEBUG("tight_loose_ratioplot() start");
  MakeCanvas(1,1);

  DEBUG("reading histograms");
  // "plot" histograms, i.e. read into memory
  cd(1);
  top();
  plot3("TightMuons");
  cd(2);
  top();
  plot3("LooseMuons");
  cd(1);

  TLegend * leg = new TLegend(0.53, 0.52, 0.77, 0.84);
  setopt(leg);
  Bool_t first = kTRUE;

  // get summed histograms
  vector<Int_t> entries;
  TH3D * hTightSum = 0;
  TH3D * hLooseSum = 0;
  for (Int_t i = 0; i < gMaxProcess; i++) {
    Int_t process = gOrder[0][i];
    // not existing
    TH3D * hTight3 = gHisto3[0][process];
    TH3D * hLoose3 = gHisto3[1][process];
    if (hTight3 == 0 || hLoose3 == 0) {
      ERROR("could not get histogram # " << i << " from memory");
      continue;
    }
    // if joined, it was already considered in previous iteration
    if (gProcess[process].join)
      continue;
    if (strncmp(gProcess[process].fname, "qcd", 3) &&
	strncmp(gProcess[process].fname, "dyll", 4) &&
	strncmp(gProcess[process].fname, "ttjets", 6) &&
	strncmp(gProcess[process].fname, "wjetstolnu", 10) &&
	strncmp(gProcess[process].fname, "data", 3))
      continue;
    DEBUG("Creating histos for process " << gProcess[process].fname);
    hTightSum = new TH3D(*hTight3);
    hLooseSum = new TH3D(*hLoose3);
    // check if histograms are joined -> we need to add statistics
    for (Int_t j = i+1; j < gMaxProcess; j++) {
      Int_t proc = gOrder[0][j];
      if (gOrder[1][j] != proc) {
	ERROR("wrong order - need to restart!");
	return;
      }
      // only add joined histograms
      if (!gProcess[proc].join)
	break;
      // not existing
      if (gHisto3[0][proc] == 0 || gHisto3[1][proc] == 0)
	continue;
      DEBUG("Adding histos for process " << gProcess[proc].fname);
      hTightSum->Add(gHisto3[0][proc], 1.);
      hLooseSum->Add(gHisto3[1][proc], 1.);
    }
    DEBUG("Getting ratio");
    TH1D * histo = get_1d_ratio(hTightSum, hLooseSum);
    if (histo == 0) {
      ERROR("Division failed");
      return;
    }
    check_1d_ratio_histogram(histo);
    setopt(histo);
    histo->SetLineColor(gProcess[process].lcolor);
    histo->SetLineStyle(gProcess[process].lstyle);
    DEBUG("Adding to legend");
    if (process != gMaxProcess-1) {
      leg->AddEntry(histo, gProcess[process].tname, "l");
    }
    else {
      leg->AddEntry(histo, gProcess[process].tname);
    }
    DEBUG("Draw");
    if (first) {
      histo->SetMaximum(1.);
      histo->SetMinimum(-0.1);
      histo->SetXTitle("p_{T}(#mu) [GeV]");
      histo->SetYTitle("T/L ratio");
      histo->Draw("ehisto");
      first = kFALSE;
    }
    else {
      if (process == gMaxProcess-1) {
	histo->SetMarkerStyle(gProcess[gMaxProcess-1].marker);
	histo->Draw("epsame");
      }
      else {
	histo->Draw("ehistosame");
      }
    }
  }
  // add subtracted data histogram
  TH1D * hdata_subtracted = get_subtracted_tight_loose_ratio(false, false);
  if (hdata_subtracted == 0)
    return;
  Double_t linemax = hdata_subtracted->GetXaxis()->GetXmax();
  Double_t linemin = hdata_subtracted->GetXaxis()->GetXmin();
  TLine * l = new TLine(linemin, 0, linemax, 0);
  l->SetLineStyle(kDotted);
  l->SetLineColor(kBlack);
  l->SetLineWidth(2);
  l->Draw();
  hdata_subtracted->SetMarkerColor(kBlue);
  hdata_subtracted->SetMarkerStyle(8);
  hdata_subtracted->Draw("epsame");
  leg->AddEntry(hdata_subtracted, "data subtr.", "ep");
  leg->Draw();
  gPad->Print("tlratio.pdf");
}
Beispiel #19
0
void validation()
{
	msglvl[DBG] = SILENT;
	msglvl[INF] = VISUAL;
	msglvl[WRN] = VISUAL;
	msglvl[ERR] = VISUAL;
	msglvl[FAT] = VISUAL;

	TDirectory* oldDir = gDirectory; // remember old directory

	style();

	Int_t g4bin = (ng4bins/g4max+1); //==> g^4=1 ==> SSM !
	
	TString suffix = "";
	if(doTruth) suffix = "_truth";
	
	TString mctype  = (isMC11c) ? "mc11c" : "mc11a";
	
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_overallEWkF_noInAmpSigEWkF_noHighMbins_wthOfficialZP_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_mc11c_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_wthOfficialZP_fixedBWwidth_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_mc11c_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_fixedBWwidth_treeLevelMass_Xmass2000.root";

	TLegend* legR = new TLegend(0.15,0.75,0.35,0.85,NULL,"brNDC");
	legR->SetFillStyle(4000); //will be transparent
	legR->SetFillColor(0);
	legR->SetTextFont(42);
	TH1D* hDummy = new TH1D("","",1,0.,1.);
	hDummy->SetMarkerStyle(20);
	hDummy->SetMarkerSize(0.8);
	hDummy->SetMarkerColor(kBlack);
	if(!doResiduals) legR->AddEntry(hDummy,"#frac{template}{official}","lep");
	else             legR->AddEntry(hDummy,"#frac{template - official}{#sqrt{#delta^{2}template + #delta^{2}official}}","lep");
	
	TPaveText* ptxt = new TPaveText(0.145,0.35,0.245,0.55,"NDC");
	TText* txt;
	ptxt->SetTextSize(0.03);
	ptxt->SetBorderSize(0);
	ptxt->SetFillStyle(4000); //will be transparent
	ptxt->SetFillColor(0);
	ptxt->SetTextAlign(12);
	txt = ptxt->AddText("This range");
	txt = ptxt->AddText("is chopped");
	txt = ptxt->AddText("before the");
	txt = ptxt->AddText("template is");
	txt = ptxt->AddText("handed to");
	txt = ptxt->AddText("BAT (limit).");
	
	oldDir->cd();

	TString fBGname = "plots/validation/ZP_2dtemplates_mc11c_33st_noKKtmplates_wthOfficialZP_treeLevelMass_Xmass2000.root";
	TFile* fD = new TFile(fBGname,"READ");
	TH1D* hDY = NULL;
	if(doTruth) hDY = (TH1D*)fD->Get("hMass_DYmumu_truth")->Clone();
	else        hDY = (TH1D*)fD->Get("hMass_DYmumu")->Clone();
	hDY->SetLineColor(kMagenta-5);
	hDY->SetMarkerColor(kMagenta-5);

	oldDir->cd();

	TFile* fDYrozmin    = new TFile("plots/mass_plot_tables_3st.root","READ");
	TH1D* hDYrozmin = (TH1D*)fDYrozmin->Get("mass_log_dy")->Clone();
	hDYrozmin = (TH1D*)hGeV2TeV(hDYrozmin)->Clone();
	hDYrozmin = (TH1D*)hChopper(hDYrozmin,bins2chop)->Clone();
	oldDir->cd();
	TFile* f1dTemplates = new TFile("plots/ZpSignal_MM_MC11c_5points.root","READ");
	TObjArray* toarr1d = new TObjArray();
	toarr1d->Read("template");
	TMapTSP2TH1D h1dBrandeisTmpltMap;
	double Nflat = 399948;
	double sigmaflat = 4.3988E+07*nb2fb;
	double Lmcflat = Nflat/sigmaflat;
	double scale = luminosity/Lmcflat;
	TH1D* h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(0/*22*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1000",(TH1D*)resetErrors(h1dTmp)->Clone("1000")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(1/*28*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1250",(TH1D*)resetErrors(h1dTmp)->Clone("1250")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(2/*34*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1500",(TH1D*)resetErrors(h1dTmp)->Clone("1500")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(3/*40*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1750",(TH1D*)resetErrors(h1dTmp)->Clone("1750")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(4/*47*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("2000",(TH1D*)resetErrors(h1dTmp)->Clone("2000")) );

	oldDir->cd();

	TMapTSP2TH1D h1Map;
	h1Map.insert( make_pair("1000o", (TH1D*)fD->Get("hMass_Zprime_SSM1000"+suffix)->Clone()) );
	h1Map.insert( make_pair("1000t", (TH1D*)fD->Get("hMass_Zprime_SSM1000_template"+suffix)->Clone()) );
	if(isMC11c)
	{
		h1Map.insert( make_pair("1250o", (TH1D*)fD->Get("hMass_Zprime_SSM1250"+suffix)->Clone()) );
		h1Map.insert( make_pair("1250t", (TH1D*)fD->Get("hMass_Zprime_SSM1250_template"+suffix)->Clone()) );
	}
	h1Map.insert( make_pair("1500o", (TH1D*)fD->Get("hMass_Zprime_SSM1500"+suffix)->Clone()) );
	h1Map.insert( make_pair("1500t", (TH1D*)fD->Get("hMass_Zprime_SSM1500_template"+suffix)->Clone()) );
	h1Map.insert( make_pair("1750o", (TH1D*)fD->Get("hMass_Zprime_SSM1750"+suffix)->Clone()) );
	h1Map.insert( make_pair("1750t", (TH1D*)fD->Get("hMass_Zprime_SSM1750_template"+suffix)->Clone()) );
	h1Map.insert( make_pair("2000o", (TH1D*)fD->Get("hMass_Zprime_SSM2000"+suffix)->Clone()) );
	h1Map.insert( make_pair("2000t", (TH1D*)fD->Get("hMass_Zprime_SSM2000_template"+suffix)->Clone()) );

	TMapTSP2TH1D h1rMap;
	h1rMap.insert( make_pair("1000", (TH1D*)fD->Get("hMass_Zprime_SSM1000"+suffix)->Clone()) );
	if(isMC11c) h1rMap.insert( make_pair("1250", (TH1D*)fD->Get("hMass_Zprime_SSM1250"+suffix)->Clone()) );
	h1rMap.insert( make_pair("1500", (TH1D*)fD->Get("hMass_Zprime_SSM1500"+suffix)->Clone()) );
	h1rMap.insert( make_pair("1750", (TH1D*)fD->Get("hMass_Zprime_SSM1750"+suffix)->Clone()) );
	h1rMap.insert( make_pair("2000", (TH1D*)fD->Get("hMass_Zprime_SSM2000"+suffix)->Clone()) );
	for(TMapTSP2TH1D::iterator it=h1rMap.begin() ; it!=h1rMap.end() ; ++it)
	{
		it->second->Reset();
		if(!doResiduals) it->second->Divide(h1Map[it->first+"o"],h1Map[it->first+"t"],1.,1.,"B");
		else             residuals(h1Map[it->first+"o"], h1Map[it->first+"t"], it->second);
		
		// for(Int_t i=0 ; i<=it->second->GetNbinsX()+1 ; i++) it->second->SetBinError(i,0);
		it->second->SetMarkerStyle(20);
		it->second->SetMarkerSize(0.5);
		it->second->GetXaxis()->SetLabelSize(0.073);
		it->second->GetYaxis()->SetLabelSize(0.073);
		it->second->GetXaxis()->SetTitleSize(0.073);
		it->second->GetYaxis()->SetTitleSize(0.073);
		it->second->SetTitleSize(0.075);
		it->second->GetYaxis()->SetTitleOffset(0.5);
		if(!doResiduals)
		{
			it->second->SetMinimum(0.2);
			it->second->SetMaximum(1.8);
		}
		else
		{
			it->second->SetMinimum(-5.);
			it->second->SetMaximum(+5.);
		}
		it->second->SetTitle("");
		if(!doResiduals) it->second->GetYaxis()->SetTitle("ratio");
		else             it->second->GetYaxis()->SetTitle("residuals");
	}

	TMapTSP2TGAE poissonGraphMap;
	TMapTSP2TLeg legMap;


	_INFO("");

	oldDir->cd();

	fD->cd();	
	TH1D* h1Template = (TH1D*)fD->Get("hMass_DYmumu"+suffix)->Clone();
	h1Template->Reset();
	TObjArray* toarr = new TObjArray();
	if(doTruth) toarr->Read("truth_template2d");
	else        toarr->Read("template2d");
	TH2D* h2SSM2000 = (TH2D*)((TObjArray*)toarr->At(0))->Clone("hMass"+suffix+"_Zprime_SSM2000_template2d");
	for(Int_t bin=1 ; bin<=h2SSM2000->GetNbinsX() ; bin++)
	{
		h1Template->SetBinContent(bin, h2SSM2000->GetBinContent(bin,g4bin));
		h1Template->SetBinError(bin, h2SSM2000->GetBinError(bin,g4bin));
	}
	h1Template->SetLineColor(kViolet);
	h1Template->SetLineWidth(1);
	h1Template->SetMarkerStyle(20);
	h1Template->SetMarkerSize(0.3);
	h1Template->SetMarkerColor(kViolet);
	// the functions
	h2Template = (TH2D*)h2SSM2000->Clone();
	vector<TF1*> vfunc;
	unsigned int nmllbins = h2Template->GetNbinsX();
	for(unsigned int mll=1 ; mll<=(nmllbins-bins2chop) ; mll++) // 1...(56-9 = 47)
	{
		TString mllname = (TString)_s(mll);
		TString mllval  = (TString)_s(h2Template->GetXaxis()->GetBinCenter(mll+bins2chop));
		
		TF1* f = new TF1("fNominal_mll"+mllname,fTH1toTF1,g4min,g4max,1);
		f->SetParameter(0,mll);
		f->SetParNames("mll");
		// f->SetLineColor(kBlue);
		// f->SetLineWidth(1);
		f->SetNpx(400);
		vfunc.push_back(f);
	}
	TGraph* graphDY = new TGraph();
	graphDY->SetMarkerStyle(25);
	graphDY->SetMarkerSize(0.6);
	graphDY->SetMarkerColor(kGreen+2);
	TGraph* graphSSM = new TGraph();
	graphSSM->SetMarkerStyle(24);
	graphSSM->SetMarkerSize(0.6);
	graphSSM->SetMarkerColor(kOrange+8);
	for(unsigned int i=0 ; i<vfunc.size() ; i++)
	{
		double DY = vfunc[i]->Eval(0.0);
		double SSM = vfunc[i]->Eval(1.0);
		graphDY->SetPoint(i,h2Template->GetXaxis()->GetBinCenter(bins2chop+i+1),DY);
		graphSSM->SetPoint(i,h2Template->GetXaxis()->GetBinCenter(bins2chop+i+1),SSM);
	}
	
	
	oldDir->cd();

	TObjArray* toarr1dTLV = new TObjArray();
	TMapTSP2TH1D h1dTlvTmpltMap;
	TFile* fT = NULL;
	TString fTname = "plots/validation/ZP_2dtemplates_mc11c_33st_noInterference_noKKtmplates_noOverallEWkF_wthOfficialZP_treeLevelMass_Xmass";
	
	fT = new TFile(fTname+"1000.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1000",(TH1D*)resetErrors(h1dTmp)->Clone("1000")) );
	fT = new TFile(fTname+"1250.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1250",(TH1D*)resetErrors(h1dTmp)->Clone("1250")) );
	fT = new TFile(fTname+"1500.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1500",(TH1D*)resetErrors(h1dTmp)->Clone("1500")) );
	fT = new TFile(fTname+"1750.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1750",(TH1D*)resetErrors(h1dTmp)->Clone("1750")) );
	fT = new TFile(fTname+"2000.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("2000",(TH1D*)resetErrors(h1dTmp)->Clone("2000")) );

	oldDir->cd();
	
	
	for(TMapTSP2TH1D::iterator it=h1Map.begin() ; it!=h1Map.end() ; ++it)
	{
		if(it->first.Contains("o"))
		{
			TString name = it->first;
			name.ReplaceAll("o","");
			it->second->SetFillColor(kAzure-9);
			if(doTruth) it->second->SetTitle("m_{Z'} = "+name+" GeV (truth)");
			else        it->second->SetTitle("m_{Z'} = "+name+" GeV");
		}
		if(it->first.Contains("t"))
		{
			//TGraphAsymmErrors* poisson(TH1D* h)
			it->second->SetLineColor(kBlue);
			it->second->SetMarkerStyle(20);
			it->second->SetMarkerSize(0.4);
			it->second->SetMarkerColor(kBlue);
			it->second->SetLineWidth(1);
			
			TString name = it->first;
			name.ReplaceAll("t","");
			poissonGraphMap.insert( make_pair(name, (TGraphAsymmErrors*)poisson(it->second)->Clone()) );
			poissonGraphMap[name]->SetMarkerStyle(20);
			poissonGraphMap[name]->SetMarkerSize(0.3);
			poissonGraphMap[name]->SetMarkerColor(kBlue);
			poissonGraphMap[name]->SetLineWidth(1);
			poissonGraphMap[name]->SetLineColor(kBlue);
		}
	}	

	Double_t yLine = (!doResiduals) ? 1. : 0.;

	TLine* line = new TLine(0.07,yLine,3.,yLine);	
	line->SetLineColor(kRed);
	line->SetLineWidth(2);
	
	TMapTSP2TCNV cnvMap;
	cnvMap.insert( make_pair("1000", new TCanvas("1000","1000",600,550)) );
	if(isMC11c) cnvMap.insert( make_pair("1250", new TCanvas("1250","1250",600,550)) );
	cnvMap.insert( make_pair("1500", new TCanvas("1500","1500",600,550)) );
	cnvMap.insert( make_pair("1750", new TCanvas("1750","1750",600,550)) );
	cnvMap.insert( make_pair("2000", new TCanvas("2000","2000",600,550)) );
	for(TMapTSP2TCNV::iterator it=cnvMap.begin() ; it!=cnvMap.end() ; ++it)
	{
		_INFO("starting "+(string)it->first);
		if(it->first=="2000") legMap.insert( make_pair(it->first, new TLegend(0.35,0.55,0.83,0.84,NULL,"brNDC")) );
		else                  legMap.insert( make_pair(it->first, new TLegend(0.35,0.60,0.83,0.84,NULL,"brNDC")) );
		legMap[it->first]->SetFillStyle(4000); //will be transparent
		legMap[it->first]->SetFillColor(0);
		legMap[it->first]->SetTextFont(42);
		legMap[it->first]->AddEntry(h1Map[it->first+"o"],"Official Z'_{SSM}","F");
		legMap[it->first]->AddEntry(hDY,"Official DY#mu#mu","lep");
		legMap[it->first]->AddEntry(h1Map[it->first+"t"],"ME^{2} method: Template w/o couplings scale","lep");
		if(it->first=="2000")
		{
			legMap[it->first]->AddEntry(h1Template,"ME^{2} method: Template histogram at  #it{g=1} (SSM)","lep");
			legMap[it->first]->AddEntry(graphSSM,  "ME^{2} method: Template function  at  #it{g=1} (SSM)","p");
			legMap[it->first]->AddEntry(graphDY,   "ME^{2} method: Template function  at  #it{g=0} (DY)","p");
		}
		if(!doTruth)
		{
			h1dTlvTmpltMap[it->first]->SetLineColor(kCyan+2);
			h1dTlvTmpltMap[it->first]->SetMarkerColor(kCyan+2);
			h1dTlvTmpltMap[it->first]->SetMarkerStyle(5);
			h1dTlvTmpltMap[it->first]->SetMarkerSize(0.5);
			legMap[it->first]->AddEntry(h1dTlvTmpltMap[it->first],"ME^{2} method: DY+Template (no interference)","p");
		
			h1dBrandeisTmpltMap[it->first]->SetLineColor(kRed);
			h1dBrandeisTmpltMap[it->first]->SetMarkerColor(kRed);
			h1dBrandeisTmpltMap[it->first]->SetMarkerStyle(27);
			h1dBrandeisTmpltMap[it->first]->SetMarkerSize(0.5);
			legMap[it->first]->AddEntry(h1dBrandeisTmpltMap[it->first],"Flat Z' method: DY+Template (no interference)","p");
		}

		it->second->Divide(1,2);
		TVirtualPad* ph = it->second->cd(1);
		TVirtualPad* pr = it->second->cd(2);	
		ph->SetPad(0.00, 0.35, 1.00, 1.00);
		pr->SetPad(0.00, 0.00, 1.00, 0.35);
		ph->SetBottomMargin(0.012);
		pr->SetBottomMargin(0.20);
		pr->SetTopMargin(0.012);
		
		ph->cd();
		ph->Draw();
		ph->SetTicks(1,1);
		ph->SetLogy();
		ph->SetLogx();
		// h1Map[it->first+"o"]->SetMaximum( h1Map[it->first+"t"]->GetMaximum()*1.5 );
		// h1Map[it->first+"o"]->Draw();
		TH1D* hTmpNoErr = (TH1D*)resetErrors(h1Map[it->first+"o"])->Clone();
		hTmpNoErr->SetMaximum( h1Map[it->first+"t"]->GetMaximum()*1.5 );
		hTmpNoErr->SetLineStyle(1);
		hTmpNoErr->SetLineColor(kBlack);
		hTmpNoErr->SetFillColor(kAzure-9);
		hTmpNoErr->Draw();
		TH1D* hTmpErr = (TH1D*)ShiftLog(h1Map[it->first+"o"],0.2)->Clone();
		hTmpErr->SetFillStyle(4000); //will be transparent
		hTmpErr->SetFillColor(0);
		hTmpErr->DrawCopy("epx0SAMES");
		hDY->Draw("SAMES");
		h1Map[it->first+"t"]->Draw("epSAMES");
		//poissonGraphMap[it->first]->Draw("pSAMES");
		if(it->first=="2000")
		{
			graphDY->Draw("SAMESp");
			graphSSM->Draw("SAMESp");
			h1Template->Draw("epSAMES");
		}
		_INFO("");
		h1dTlvTmpltMap[it->first]->Draw("SAMESp");
		h1dBrandeisTmpltMap[it->first]->Draw("SAMESp");
		
		TLine* chopline = new TLine(0.12805,getYmin(h1Map[it->first+"o"]),0.12805,7.e5);
		chopline->SetLineStyle(2);
		chopline->SetLineColor(kBlack);
		chopline->Draw("SAMES");
		ptxt->Draw("SAMES");
		
		legMap[it->first]->Draw("SAMES");
		ph->RedrawAxis();
		ph->Update();

		_INFO("");

		pr->cd();
		pr->Draw();
		pr->SetTicks(1,1);
		pr->SetGridy();
		pr->SetLogx();
		h1rMap[it->first]->Draw("ep");
		line->Draw("SAMES");
		h1rMap[it->first]->Draw("epSAMES");
		legR->Draw("SAMES");
		pr->RedrawAxis();
		pr->Update();

		unsigned int savestate = 1;
		if(it->first=="1000")      savestate = 0;
		else if(it->first=="2000") savestate = 2;
		else                       savestate = 1;
		TString testType = (doResiduals) ? "_residuals" : "_ratio";
		mutype   = (doTruth)     ? "_truth"     : "_recon";
		savemultipdf(it->second, "plots/validation/validation"+mutype+testType+"_"+mctype+"_all.pdf", savestate);
		saveas(it->second, "plots/validation/validation"+mutype+testType+"_"+mctype+"_"+it->first);
		
		TCanvas* c = new TCanvas(it->first,"",600,400);
		c->cd();
		c->Draw();
		c->SetTicks(1,1);
		c->SetLogy();
		c->SetLogx();
		hTmpNoErr->Draw();
		hTmpErr->DrawCopy("epx0SAMES");
		hDY->Draw("SAMES");
		h1Map[it->first+"t"]->Draw("epSAMES");
		//poissonGraphMap[it->first]->Draw("pSAMES");
		if(it->first=="2000")
		{
			graphDY->Draw("SAMESp");
			graphSSM->Draw("SAMESp");
			h1Template->Draw("epSAMES");
		}
		h1dTlvTmpltMap[it->first]->Draw("SAMESp");
		h1dBrandeisTmpltMap[it->first]->Draw("SAMESp");
		legMap[it->first]->Draw("SAMES");
		chopline->Draw("SAMES");
		ptxt->Draw("SAMES");
		c->RedrawAxis();
		c->Update();
		saveas(c,"plots/validation/validation_"+it->first+"_"+mutype+testType);
		
		_INFO("done "+(string)it->first);
	}
}
void advancedNoiseAnalysis( unsigned int runNumber, unsigned int loop = 1) {
  
  string inputFileName = "./histo/run00" + toString( runNumber ) + "-ped-histo.root";
  string outputFileName = "./histo/run00" + toString( runNumber ) + "-adv-noise.root";
  

  // before opening the input and the output files, try to see if they
  // are not opened yet and in case close them before continue   
  TList * listOfOpenedFile = (TList*) gROOT->GetListOfFiles();
  for ( int i = 0; i < listOfOpenedFile->GetSize() ; ++i ) {
    TFile * file = (TFile*) listOfOpenedFile->At( i ) ;
    TString fileName(file->GetName());
    TString inputFileName1( inputFileName.c_str() );
    TString outputFileName1( outputFileName.c_str() );

    if (  ( fileName.Contains( inputFileName1 ) ) ||
	  ( inputFileName1.Contains( fileName ) ) ||
	  ( fileName.Contains( outputFileName1 ) ) ||
	  ( outputFileName1.Contains( fileName ) ) ) {
      cout << "Closing " << fileName << " before reopen " << endl;
      file->Close();
    }
  }


  // close also all the previously opened canvas
  TList * listOfOpenedCanvas = (TList*) gROOT->GetListOfCanvases();
  for ( int i = 0 ; i < listOfOpenedCanvas->GetSize() ; ++i ) {
    TCanvas * canvas = (TCanvas*) listOfOpenedCanvas->At( i );
    TString canvasName2 = canvas->GetName();
    if ( canvasName2.Contains( "det" ) ) {
      canvas->Close();
    }
  }

	 
  // now safely open the file
  TFile * inputFile = TFile::Open( inputFileName.c_str() ) ;
  TFile * outputFile = TFile::Open( outputFileName.c_str(), "RECREATE") ;
  TList * outputHistoList = new TList;

  // look into the inputFile for a folder named
  string pedeProcessorFolderName = "PedestalAndNoiseCalculator";
  TDirectoryFile * pedeProcessorFolder = (TDirectoryFile*) inputFile->Get( pedeProcessorFolderName.c_str() );
  
  if ( pedeProcessorFolder == 0 ) { 
    cerr << "No pedestal processor folder found in file " << inputFileName << endl;
    return ;
  }

  // this folder should contain one folder for each loop.
  string loopFolderName = "loop-" + toString( loop );
  TDirectoryFile * loopFolder = (TDirectoryFile *) pedeProcessorFolder->Get( loopFolderName.c_str() );
  
  if ( loopFolder == 0 ) {
    cerr << "No " << loopFolderName << " found in file " << inputFileName << endl;
    return ;
  }

  // guess the number of sensors from the number of subfolder in the loopfolder
  size_t nDetector = loopFolder->GetListOfKeys()->GetSize();
  cout << "This file contains " << nDetector << " detectors" << endl;

  // prepare arrays to store the mean and the rms of the noise distribution
  if ( noiseMean == NULL ) {
    delete [] noiseMean;
    noiseMean = NULL;
  }
  if ( noiseRMS == NULL ) {
    delete [] noiseRMS;
    noiseRMS = NULL;
  }
  if ( channel == NULL ) {
    delete [] channel;
    channel = NULL;
  }

  noiseMean = new double[ nDetector * kNChan ];
  noiseRMS  = new double[ nDetector * kNChan ];
  channel   = new double[ kNChan ];

  string canvasName = "comparison";
  string canvasTitle = "Noise comparison";

  TCanvas * comparisonCanvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
  comparisonCanvas->Divide(1,2);
  
  TPad * topPad = (TPad*) comparisonCanvas->cd(1);
  topPad->Divide( nDetector );
  
  TPad * middlePad = (TPad *) comparisonCanvas->cd(2);
  middlePad->Divide( kNChan );


  // for each detector we have to get the noise map and to prepare 4
  // separe histos and maps
  for ( unsigned int iDetector = 0; iDetector < nDetector; iDetector++ ) {

    // get the noise map.
    string noiseMapName = "detector-" + toString( iDetector ) ;
    noiseMapName += "/NoiseMap-d" + toString( iDetector )  ;
    noiseMapName += "-l" + toString( loop ) ;
 
    TH2D * noiseMap = ( TH2D* ) loopFolder->Get( noiseMapName.c_str() ); 
    

    // create a folder in the output file
    TDirectory * subfolder = outputFile->mkdir( string( "detector_" + toString( iDetector ) ).c_str(),
						string( "detector_" + toString( iDetector ) ).c_str()
						);
    subfolder->cd();

    
    string canvasName = "det" + toString( iDetector );
    string canvasTitle = "Detector " + toString( iDetector );
    
    TCanvas * canvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
    canvas->Divide( kNChan, 2 );

    // ok now start the loop on channels
    for ( size_t iChan = 0 ; iChan < kNChan ; ++iChan ) { 
	
      if ( iDetector == 0 ) channel[iChan] = iChan - 0.5;

      string tempName = "NoiseMap_d" + toString( iDetector ) + "_l" + toString( loop )	+ "_ch" + toString( iChan ) ;
      string tempTitle = "NoiseMap Det. " + toString( iDetector ) + " - Ch. " + toString( iChan ) ;

      TH2D * noiseMapCh = new TH2D ( tempName.c_str() , tempTitle.c_str(), 
				     kXPixel / kNChan , -0.5 + xLimit[ iChan ] , -0.5 + xLimit[ iChan + 1 ],
				     kYPixel, -0.5, -0.5 + kYPixel );
      noiseMapCh->SetXTitle("X [pixel]");
      noiseMapCh->SetYTitle("Y [pixel]");
      noiseMapCh->SetZTitle("Noise [ADC]");
      noiseMapCh->SetStats( false );
      outputHistoList->Add( noiseMapCh ) ;

      tempName = "NoiseDist_d" + toString( iDetector ) + "_l" + toString( loop )	+ "_ch" + toString( iChan ) ;
      
      tempTitle = "NoiseDist Det. " + toString( iDetector ) + " - Ch. " + toString( iChan ) ; 

      TH1D * noiseDistCh = new TH1D( tempName.c_str(), tempTitle.c_str(), 50, 0., 10. );
      noiseDistCh->SetXTitle("Noise [ADC]");
      noiseDistCh->SetLineColor( kColor[iDetector]  );
      noiseDistCh->SetLineStyle( iChan + 2 );
      noiseDistCh->SetLineWidth( 2 );
      outputHistoList->Add( noiseDistCh );

      // let's start looping on pixels now
      for ( size_t yPixel = 1 ; yPixel <= kYPixel ; ++yPixel ) {
	for ( size_t xPixel = xLimit[ iChan ] + 1; xPixel <= xLimit[ iChan +1 ] ; ++xPixel ) {
	  double noise = noiseMap->GetBinContent( xPixel , yPixel );
	  noiseMapCh->Fill( xPixel - 1 , yPixel - 1, noise );
	  noiseDistCh->Fill( noise );
	  
	}
      }

      canvas->cd( iChan + 1 ) ;
      noiseMapCh->Draw("colz");
      canvas->cd( iChan + kNChan + 1  );
      noiseDistCh->Draw();
      
      topPad->cd( iDetector + 1 );
      if ( iChan == 0 ) {
	noiseDistCh->Draw();
      } else {
	noiseDistCh->Draw("same");
      }

      middlePad->cd( iChan + 1 );
      if ( iDetector == 0 ) {
	noiseDistCh->Draw();
      } else {
	noiseDistCh->Draw("same");
      }


      noiseMean[ kNChan * iDetector + iChan ] = noiseDistCh->GetMean();
      noiseRMS[ kNChan * iDetector  + iChan ] = noiseDistCh->GetRMS();
    }
    canvas->Write();

  }

  canvasName = "summary";
  canvasTitle = "Noise summary";

  TCanvas * summaryCanvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
  summaryCanvas->SetGridx(1);
  TLegend * legend = new TLegend(0.5, 4.8, 1.5, 4.3,"","br");;
  

  for ( size_t iDetector = 0 ; iDetector < nDetector ; ++iDetector ) {
    
    TGraphErrors * gr = new TGraphErrors( kNChan, channel, &noiseMean[ iDetector * kNChan ], NULL, &noiseRMS[ iDetector * kNChan ] );
    gr->SetName( string( "NoisePerChannel_d" + toString( iDetector )).c_str());
    gr->SetTitle(string("Detector " + toString( iDetector )).c_str());
    gr->GetXaxis()->SetTitle("Channel #");
    gr->GetYaxis()->SetTitle("Noise [ADC]");
    gr->GetXaxis()->SetNdivisions( 5 );
    gr->GetXaxis()->SetLabelSize( 0 );
    gr->SetMarkerStyle( iDetector + 1 );
    gr->SetMarkerColor( kColor[iDetector] );
    gr->SetLineColor( kColor[iDetector] );
    gr->SetLineWidth( 2 );

    
    legend->AddEntry( gr, string("Detector " + toString( iDetector )).c_str(), "LP");

    if ( iDetector == 0 ) {
      gr->Draw("ALP");
    } else {
      gr->Draw("LP");
    }
    

  }

  
  
  legend->Draw();

  for ( size_t iChan = 0 ; iChan < kNChan ; ++iChan ) {
    
    TPaveLabel * label = new TPaveLabel( iChan - 0.75 , 3.2 , iChan -0.25 , 3, string("Ch " + toString( iChan ) ).c_str());
    label->Draw();
  }


  summaryCanvas->Write();
  comparisonCanvas->Write();

  outputHistoList->Write();

  

 
} 
void NuclearModification(
  TString  particle,
  const int      nbins,
  Double_t xbins[],
  Double_t xhbins[],
  Double_t exl[],
  Double_t exl2[],
  Double_t exl0[],
  Double_t yPercSigmapPbSystTotHigh[],
  Double_t yPercSigmapPbSystTotLow[],
  Double_t commonErrorP,
  Double_t commonErrorN,
  Double_t FFsysterror,
  Double_t tagandprobcorrection[],
  TCanvas *canvasSigma,
  TCanvas *canvasRpA,
  int PadNum
){
  gROOT->SetStyle("Plain");
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  
  TFile*filePPReference=new TFile(Form("../../../fonll/output%s.root",particle.Data()));  
  //###TFile*filePPReference=new TFile(Form("../../fonll/output%s.root",particle.Data()));  
  TGraphAsymmErrors*gaeBplusReference=(TGraphAsymmErrors*)filePPReference->Get(Form("gaeSigmaDecay%s",particle.Data()));
  gaeBplusReference->SetName(Form("gae%sReference",particle.Data()));
  
  TFile*filepPb=new TFile(Form("../Results%s/Sigma%s.root",particle.Data(),particle.Data()));
  TH1F*hSigmapPbStat=(TH1F*)filepPb->Get("hPtSigma");  
  TH1F*hPt=(TH1F*)filepPb->Get("hPt");
  TH1F*hEff=(TH1F*)filepPb->Get("hEff");
  
  double scalingfactor=1e-6;
  double yvalue,xvalue,yerrorhigh,yerrorlow;
  
  for (int i=0;i<nbins;i++){
    hSigmapPbStat->SetBinContent(i+1,scalingfactor*hSigmapPbStat->GetBinContent(i+1));
    hSigmapPbStat->SetBinError(i+1,scalingfactor*hSigmapPbStat->GetBinError(i+1));
    
    yvalue=-1.;
    xvalue=-1.;
    yerrorhigh=-1.;
    yerrorlow=-1.;
    
    gaeBplusReference->GetPoint(i,xvalue,yvalue);
    yerrorhigh=gaeBplusReference->GetEYhigh()[i];
    yerrorlow=gaeBplusReference->GetEYlow()[i];
  
    gaeBplusReference->SetPoint(i,xvalue,yvalue*scalingfactor);
    gaeBplusReference->SetPointEYhigh(i,yerrorhigh*scalingfactor);
    gaeBplusReference->SetPointEYlow(i,yerrorlow*scalingfactor);

  } 
  
  
  for (int i=0;i<nbins;i++){
    hSigmapPbStat->SetBinContent(i+1,(1./tagandprobcorrection[i])*hSigmapPbStat->GetBinContent(i+1));
    hSigmapPbStat->SetBinError(i+1,(1./tagandprobcorrection[i])*hSigmapPbStat->GetBinError(i+1));
  
  } 
  Double_t yRefPP[nbins];                        //value y reference
  Double_t xRefPP[nbins];                        //value x reference
  Double_t yPPsystFONLLhigh[nbins];              //y err syst FONLL high
  Double_t yPPsystFONLLlow[nbins];               //y err syst FONLL low
  Double_t yPercPPsystFONLLhigh[nbins];          //y percentuale err syst FONLL high
  Double_t yPercPPsystFONLLlow[nbins];           //y percentuale err syst FONLL low
    
  Double_t ySigmapPb[nbins];                     //value y pPb 
  Double_t xSigmapPb[nbins];                     //value x pPb
  Double_t ySigmapPbStat[nbins];                 //y err stat pPb
  Double_t yPercSigmapPbStat[nbins];             //y err stat pPb
  
  Double_t yFONLL[nbins];                        //1
  Double_t yRpA[nbins];                          //value y RpA 
  Double_t yRpAStat[nbins];                      //y err stat RpA 
  Double_t yRpAsystFONLLhigh[nbins];             //y err syst FONLL RpA high
  Double_t yRpAsystFONLLlow[nbins];              //y err syst FONLL RpA lzow
  Double_t yPercRpAsystFONLLhigh[nbins];         //y percentuale err syst FONLL RpA high
  Double_t yPercRpAsystFONLLlow[nbins];          //y percentuale err syst FONLL RpA low
    
  Double_t ySigmapPbSystTotHigh[nbins];              //y percentuale err syst pPb TOT
  Double_t ySigmapPbSystTotLow[nbins];              //y percentuale err syst pPb TOT

  Double_t yPercRpPbSystTotHigh[nbins];          //y percentuale err syst RpPb TOT
  Double_t yPercRpPbSystTotLow[nbins];          //y percentuale err syst RpPb TOT
  
  Double_t yRpPbSystTotHigh[nbins];              //y percentuale err syst RpPb TOT
  Double_t yRpPbSystTotLow[nbins];              //y percentuale err syst RpPb TOT

  
  double x,y;
  for (Int_t i=0;i<nbins;i++) {
    gaeBplusReference->GetPoint(i,xRefPP[i],yRefPP[i]);
    yPPsystFONLLhigh[i]=gaeBplusReference->GetEYhigh()[i];
    yPPsystFONLLlow[i]=gaeBplusReference->GetEYlow()[i];
    yPercPPsystFONLLhigh[i]=yPPsystFONLLhigh[i]/yRefPP[i];
    yPercPPsystFONLLlow[i]=yPPsystFONLLlow[i]/yRefPP[i];
    yPercPPsystFONLLhigh[i]=TMath::Sqrt(yPercPPsystFONLLhigh[i]*yPercPPsystFONLLhigh[i]+FFsysterror*FFsysterror);
    yPercPPsystFONLLlow[i]=TMath::Sqrt(yPercPPsystFONLLlow[i]*yPercPPsystFONLLlow[i]+FFsysterror*FFsysterror);
    
  }
  
  for(Int_t i=0;i<nbins;i++) {
    ySigmapPb[i]=hSigmapPbStat->GetBinContent(i+1);
    ySigmapPbStat[i]=hSigmapPbStat->GetBinError(i+1);
    yPercSigmapPbStat[i]=ySigmapPbStat[i]/ySigmapPb[i];
    ySigmapPbSystTotHigh[i]=yPercSigmapPbSystTotHigh[i]*ySigmapPb[i];
    ySigmapPbSystTotLow[i]=yPercSigmapPbSystTotLow[i]*ySigmapPb[i];
  }
  
  for(Int_t i=0;i<nbins;i++) {
    yRpA[i]=ySigmapPb[i]/yRefPP[i];
    yRpAStat[i]=ySigmapPbStat[i]/yRefPP[i];
    yFONLL[i]=yRpA[i];
    yPercRpAsystFONLLhigh[i]=(yPercPPsystFONLLlow[i]/(1-yPercPPsystFONLLlow[i]));
    yPercRpAsystFONLLlow[i]=(yPercPPsystFONLLhigh[i]/(1+yPercPPsystFONLLhigh[i]));
    yRpAsystFONLLhigh[i]=yPercRpAsystFONLLhigh[i]*yRpA[i];
    yRpAsystFONLLlow[i]=yPercRpAsystFONLLlow[i]*yRpA[i];

    yRpPbSystTotHigh[i]=yPercSigmapPbSystTotHigh[i]*yRpA[i];
    yRpPbSystTotLow[i]=yPercSigmapPbSystTotLow[i]*yRpA[i];   

	std::cout << i << " , " << xbins[i] << " , " << ySigmapPb[i] << " , sta: " << ySigmapPbStat[i] << " , syslow: " << ySigmapPbSystTotLow[i] << " ,syshigh: " << ySigmapPbSystTotHigh[i] << std::endl;
	std::cout << "FONLL: " << yRefPP[i] << " - " << yPPsystFONLLlow[i] << " + " << yPPsystFONLLhigh[i] << std::endl;
	std::cout << i << " ####### " << xbins[i] << " , " << yRpA[i] << " , sta: " << yRpAStat[i] << " , syslow: " << yRpPbSystTotLow[i] << " ,syshigh: " << yRpPbSystTotHigh[i] << " ,FONLLlow: " << yRpAsystFONLLlow[i] << " , FONLLhigh: " << yRpAsystFONLLhigh[i] << std::endl;

  TGraphAsymmErrors *gRpAstat = new TGraphAsymmErrors(nbins,xbins,yRpA,exl0,exl0,yRpAStat,yRpAStat);
  TGraphAsymmErrors *gRpAsyst = new TGraphAsymmErrors(nbins,xbins,yRpA,exl,exl,yRpPbSystTotLow,yRpPbSystTotHigh);
  TGraphAsymmErrors *gRpAsystFONLL = new TGraphAsymmErrors(nbins,xbins,yFONLL,exl,exl,yRpAsystFONLLlow,yRpAsystFONLLhigh);
 

  }
  
  TGraphAsymmErrors *gSigmasyst = new TGraphAsymmErrors(nbins,xbins,ySigmapPb,exl2,exl2,ySigmapPbSystTotLow,ySigmapPbSystTotHigh);
  //###TGraphAsymmErrors *gSigmasyst = new TGraphAsymmErrors(nbins,xbins,ySigmapPb,exl,exl,ySigmapPbSystTotLow,ySigmapPbSystTotHigh);


  gSigmasyst->SetTitle("Sigma syst uncertainty from pPb");
  gSigmasyst->SetMarkerColor(1);
  gSigmasyst->SetLineColor(1);
  gSigmasyst->SetLineWidth(1);   
  gSigmasyst->SetMarkerStyle(21);
  gSigmasyst->SetMarkerColor(1);
  gSigmasyst->SetFillColor(kYellow-7);//5
  gSigmasyst->SetFillStyle(1001);
  TGraphAsymmErrors*gSigmasyst2=(TGraphAsymmErrors*)gSigmasyst->Clone();
  gSigmasyst2->SetMarkerColor(1);
  gSigmasyst2->SetMarkerStyle(25);
  gSigmasyst2->SetFillColor(0);
  gSigmasyst2->SetFillStyle(0);
  gSigmasyst2->SetLineColor(1);//5
  gSigmasyst2->SetLineStyle(1);
  gSigmasyst2->SetLineWidth(1);
 

  //###TGraphAsymmErrors *gSigmastat = new TGraphAsymmErrors(nbins,xbins,ySigmapPb,exl,exl,ySigmapPbStat,ySigmapPbStat);
  TGraphAsymmErrors *gSigmastat = new TGraphAsymmErrors(nbins,xbins,ySigmapPb,exl0,exl0,ySigmapPbStat,ySigmapPbStat);


  gSigmastat->SetTitle("Sigma stat uncertainty from pPb");
  gSigmastat->SetMarkerColor(1);
  gSigmastat->SetLineColor(1);
  gSigmastat->SetLineWidth(2);//###   
  gSigmastat->SetMarkerStyle(21);
  gSigmastat->SetMarkerColor(1);
  
  gSigmastat->SetFillColor(0);
  gSigmastat->SetFillStyle(0);
  gSigmastat->SetFillStyle(0);

  Double_t padcorrection;
  if (particle=="Bplus") padcorrection=Bp_padratio/Bp_padratio;
  else if (particle=="Bzero") padcorrection=Bp_padratio/B0_padratio;
  else if (particle=="Bs") padcorrection=Bp_padratio/Bs_padratio;
  std::cout << "padcorrection: " << padcorrection << std::endl;
  canvasSigma->cd(PadNum);
  //canvasSigma->Range(-1.989924,-0.2917772,25.49622,2.212202);
  canvasSigma->SetFillColor(0);
  canvasSigma->SetBorderMode(0);
  canvasSigma->SetBorderSize(2);
  //canvasSigma->SetLeftMargin(0.1451613);
  //canvasSigma->SetRightMargin(0.05443548);
  //canvasSigma->SetTopMargin(0.005);//0.08474576
  //canvasSigma->SetBottomMargin(0.1165254);
  canvasSigma->SetFrameBorderMode(0);
  canvasSigma->SetFrameBorderMode(0);
  canvasSigma->SetLogy();
  
  //###TH2F* hempty=new TH2F("hempty","", 10, 0.1, 65., 10., 0.1, 1e3);    
  TH2F* hempty=new TH2F("hempty","", 10, 0.1, 65., 10., 0.3, 1e3);    
  hempty->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  //if(particle=="Bplus") hempty->GetYaxis()->SetTitle("d#sigma / dp_{T} (B^{+}) (pb GeV^{-1}c)");
  //if(particle=="Bzero") hempty->GetYaxis()->SetTitle("d#sigma / dp_{T} (B^{0}) (pb GeV^{-1}c)");
  //if(particle=="Bs") hempty->GetYaxis()->SetTitle("d#sigma / dp_{T} (B_{s}) (pb GeV^{-1}c)");
  hempty->GetXaxis()->CenterTitle();
  hempty->GetYaxis()->CenterTitle();
  //###hempty->GetYaxis()->SetTitle("d#sigma / dp_{T}( #mub GeV^{-1}c)");
  hempty->GetYaxis()->SetTitle("d#sigma / dp_{T}(#mub/(GeV/c))");
  //###hempty->GetXaxis()->SetTitleOffset(1.0);//###1.0
  if (particle=="Bplus") hempty->GetXaxis()->SetTitleOffset(0.90);//###1.0
  else if (particle=="Bzero") hempty->GetXaxis()->SetTitleOffset(0.90);//###0.80
  else if (particle=="Bs") hempty->GetXaxis()->SetTitleOffset(0.90);//###0.85

  hempty->GetYaxis()->SetTitleOffset(1.0);//###1.3
  hempty->GetXaxis()->SetTitleSize(0.070*padcorrection);//###0.055
  hempty->GetYaxis()->SetTitleSize(0.070*padcorrection);//###0.055
  hempty->GetXaxis()->SetTitleFont(42);
  hempty->GetYaxis()->SetTitleFont(42);
  hempty->GetXaxis()->SetLabelFont(42);
  hempty->GetYaxis()->SetLabelFont(42);
  hempty->GetXaxis()->SetLabelSize(0.060*padcorrection);//###0.055
  hempty->GetYaxis()->SetLabelSize(0.060*padcorrection);//###0.055
  if (particle=="Bplus") hempty->GetXaxis()->SetLabelOffset(0.005);//###0.005
  else if (particle=="Bzero") hempty->GetXaxis()->SetLabelOffset(0.005);//###0.0001
  else if (particle=="Bs") hempty->GetXaxis()->SetLabelOffset(0.005);//###0.0005
  //###hempty->GetXaxis()->SetLabelOffset(0.005);//###0.005
  hempty->SetMaximum(2);
  hempty->SetMinimum(0.);
  hempty->Draw();
  
  gaeBplusReference->SetMarkerColor(1);
  gaeBplusReference->SetMarkerStyle(25);  
  gaeBplusReference->SetFillColor(kYellow-7);//5
  gaeBplusReference->SetFillStyle(1001);
  gaeBplusReference->SetLineColor(kAzure-3);
  gaeBplusReference->SetLineWidth(1);
  
  
  gSigmastat->SetMarkerColor(1);
  gSigmastat->SetLineColor(1);
  gSigmastat->SetLineWidth(2);   
  gSigmastat->SetMarkerStyle(21);
  gSigmastat->SetMarkerColor(1);

  // Histogram style
  TH1D* hBplusReference = new TH1D("hBplusReference","",nbins,xhbins);
  TH1D* hBplusReferenceEYhigh = new TH1D("hBplusReferenceEYhigh","",nbins,xhbins);
  TH1D* hBplusReferenceEYlow = new TH1D("hBplusReferenceEYlow","",nbins,xhbins);



  for (int i=0;i<nbins;i++){
	double xgae,ygae;
	gaeBplusReference->GetPoint(i,xgae,ygae);
	hBplusReference->SetBinContent(i+1,ygae);
	hBplusReferenceEYhigh->SetBinContent(i+1,ygae+gaeBplusReference->GetEYhigh()[i]);
	hBplusReferenceEYlow->SetBinContent(i+1,ygae-gaeBplusReference->GetEYlow()[i]);
	std::cout << "### FONLL (" << i << ") : " << ygae << " + " << gaeBplusReference->GetEYhigh()[i] << " - " << gaeBplusReference->GetEYlow()[i] << std::endl;
}

  //hBplusReference->SetMarkerColor(1);
  //hBplusReference->SetMarkerStyle(25);  
  //hBplusReference->SetFillColor(kYellow-7);//5
  //hBplusReference->SetFillStyle(1001);
  hBplusReference->SetLineColor(kAzure-3);
  hBplusReference->SetLineWidth(2);
  hBplusReferenceEYhigh->SetLineColor(kAzure-3);
  hBplusReferenceEYhigh->SetLineWidth(2);
  hBplusReferenceEYhigh->SetLineStyle(2);
  hBplusReferenceEYlow->SetLineColor(kAzure-3);
  hBplusReferenceEYlow->SetLineWidth(2);
  hBplusReferenceEYlow->SetLineStyle(2);


/*
  hBplusReference->Draw("][,same");

  hBplusReferenceEYhigh->Draw("][,same");
  hBplusReferenceEYlow->Draw("][,same");
*/


/*
  gaeBplusReference->Draw("2psame");//2same
  TGraphAsymmErrors*gaeBplusReference2=(TGraphAsymmErrors*)gaeBplusReference->Clone();
  gaeBplusReference2->SetMarkerColor(1);
  gaeBplusReference2->SetMarkerStyle(25);  
  gaeBplusReference2->SetFillColor(0);
  gaeBplusReference2->SetFillStyle(0);
  gaeBplusReference2->SetLineColor(kAzure-3);
  gaeBplusReference2->SetLineWidth(1);
  gaeBplusReference2->Draw("2psame");//2same
*/
 
  //coord.  for legend for sigma in the B+ pannel 
  //###TLegend *legendSigma=new TLegend(0.468298,0.7045614,0.7678185,0.8757895,"");
  //###TLegend *legendSigma=new TLegend(0.55,0.63,0.85,0.80,"");
  TLegend *legendSigma=new TLegend(0.38,0.67,0.68,0.84,"");


  legendSigma->SetBorderSize(0);
  legendSigma->SetLineColor(0);
  legendSigma->SetFillColor(0);
  legendSigma->SetFillStyle(1001);
  legendSigma->SetTextFont(42);
  legendSigma->SetTextSize(0.060);//###0.045
/* 
  TBox *c = new TBox(3,1-commonErrorN,7,1+commonErrorP);
  c->SetLineColor(5);
  c->SetFillColor(5);
  c->Draw();

  TBox *c2 = c->Clone();
  c2->SetLineColor(1);
  c2->SetFillStyle(0);
  c2->Draw();
*/  
  //TLegendEntry *ent_SigmapPb=legendSigma->AddEntry(gSigmastat,"pPb","pf");
  TLegendEntry *ent_SigmapPb=legendSigma->AddEntry(gSigmasyst,"pPb","pf");


/*
  ent_SigmapPb->SetTextFont(42);
  ent_SigmapPb->SetLineColor(1);
  ent_SigmapPb->SetMarkerColor(1);
  ent_SigmapPb->SetFillColor(0);
  ent_SigmapPb->SetFillStyle(0);
*/
  ent_SigmapPb->SetTextFont(42);
  ent_SigmapPb->SetMarkerColor(1);
  ent_SigmapPb->SetMarkerStyle(25);  
  //ent_SigmapPb->SetFillColor(kYellow-7);//5
  //ent_SigmapPb->SetFillStyle(1001);
  ent_SigmapPb->SetLineColor(1);
  ent_SigmapPb->SetLineWidth(0);
  ent_SigmapPb->SetLineStyle(0);
 

/*
  TLegendEntry *ent_Sigmapp=legendSigma->AddEntry(gaeBplusReference,"FONLL pp ref.","pf");
  ent_Sigmapp->SetTextFont(42);
  ent_Sigmapp->SetLineColor(kAzure-3);//5
  ent_Sigmapp->SetLineStyle(1);
  ent_Sigmapp->SetMarkerColor(1);
  ent_Sigmapp->SetMarkerStyle(21);
*/
  TLegendEntry *ent_Sigmapp=legendSigma->AddEntry(hBplusReference,"Scaled FONLL pp ref.","l");
  ent_Sigmapp->SetTextFont(42);
  ent_Sigmapp->SetLineColor(kAzure-3);//5
  ent_Sigmapp->SetLineStyle(1);
  ent_Sigmapp->SetMarkerColor(1);
  ent_Sigmapp->SetMarkerStyle(21);

  TLegendEntry *ent_Sigmapperr=legendSigma->AddEntry(hBplusReferenceEYhigh,"FONLL pp ref. uncert.","l");
  ent_Sigmapperr->SetTextFont(42);
  ent_Sigmapperr->SetLineColor(kAzure-3);//5
  ent_Sigmapperr->SetLineStyle(2);
  ent_Sigmapperr->SetMarkerColor(1);
  ent_Sigmapperr->SetMarkerStyle(21);


  //###gSigmasyst->SetFillColor(0);
  //###gSigmasyst->SetFillStyle(0);

for (int i=0;i<nbins;i++){
        double xgae,ygae;
        gSigmastat->GetPoint(i,xgae,ygae);
        std::cout << "### cross section (" << i << ") : " << ygae << " stat: " << gSigmastat->GetEYhigh()[i] << " syst: " << gSigmasyst->GetEYhigh()[i] << std::endl;
}

  gSigmasyst->Draw("2esame");//###2psame
  gSigmasyst2->Draw("2esame");

  hBplusReference->Draw("][,same");

  hBplusReferenceEYhigh->Draw("][,same");
  hBplusReferenceEYlow->Draw("][,same");

  gSigmastat->SetFillColor(0);
  gSigmastat->Draw("epsame");
/*  
  TBox *d = new TBox(0.1,1-commonErrorN,4,1+commonErrorP);
  d->SetLineColor(1);
  d->SetFillColor(0);
  d->Draw();
*/  
  //if(PadNum==0 || PadNum==1){
  if(PadNum==3 || PadNum==1 || PadNum==2){


    legendSigma->Draw("same");
    
    //TLatex * tlatex1=new TLatex(0.21,0.88801268,"CMS");
    TLatex * tlatex1=new TLatex(0.19,0.86,"CMS");
    tlatex1->SetNDC();
    tlatex1->SetTextColor(1);
    tlatex1->SetTextFont(62);//42
    tlatex1->SetTextSize(0.07);//0.045
    tlatex1->Draw();
/*
    TLatex * tlatex12=new TLatex(0.35,0.86,"Preliminary");
    tlatex12->SetNDC();
    tlatex12->SetTextColor(1);
    tlatex12->SetTextFont(52);//42
    tlatex12->SetTextSize(0.05);//0.045
    tlatex12->Draw();
*/   
    //TLatex * tlatexlumi=new TLatex(0.471371,0.88801268,"L = 34.8 nb^{-1} (pPb 5.02 TeV)");
    //TLatex * tlatexlumi=new TLatex(0.471371,0.88801268,"34.6 nb^{-1} (pPb 5.02 TeV)");
    TLatex * tlatexlumi;
//###TLatex * tlatexlumi=new TLatex(0.390,0.950,"34.6 nb^{-1} (pPb 5.02 TeV)");
   if (PadNum==1) tlatexlumi = new TLatex(0.41,0.94,"34.6 nb^{-1} (pPb 5.02 TeV)");
   else tlatexlumi = new TLatex(0.39,0.94,"34.6 nb^{-1} (pPb 5.02 TeV)");
    tlatexlumi->SetNDC();
    tlatexlumi->SetTextColor(1);
    tlatexlumi->SetTextFont(42);
    tlatexlumi->SetTextSize(0.06);//0.045
    tlatexlumi->Draw();
  }

   //if(PadNum==2){
    if(PadNum==3 || PadNum==1 || PadNum==2) {
    //TLatex * tlatex4=new TLatex(0.60,0.73,"|y_{lab}| < 2.4");
    TLatex * tlatex4=new TLatex(0.65,0.50,"|y_{lab}| < 2.4");


    tlatex4->SetNDC();
    tlatex4->SetTextColor(1);
    tlatex4->SetTextFont(42);//42
    tlatex4->SetTextSize(0.07);//0.045
    tlatex4->Draw();
	 }

	double GloUnc;
	double xtl5=0.54;

   if(PadNum==1) {GloUnc=Bp_commonErrorP*100;xtl5=0.54;}//###0.57
   if(PadNum==2) {GloUnc=B0_commonErrorP*100;xtl5=0.47;}
   if(PadNum==3) {GloUnc=Bs_commonErrorP*100;xtl5=0.42;}

	xtl5=0.54;


//TLegend *legendSigma=new TLegend(0.55,0.63,0.85,0.80,"");
   TLatex * tlatex5=new TLatex(xtl5,0.60,Form("Global uncert. %2.1f%%",GloUnc));
    tlatex5->SetNDC();
    tlatex5->SetTextColor(1);
    tlatex5->SetTextFont(42);//42
    tlatex5->SetTextSize(0.05*padcorrection);//0.045
    tlatex5->Draw();

  //###double xpos=0.8528226;
  //###double ypos=0.6849894;
  double xpos=0.90;//0.86
  double ypos=0.85;//0.86
  
  TString mypar;
  if(particle=="Bplus") mypar="B^{+}";
  if(particle=="Bzero") mypar="B^{0}";
  if(particle=="Bs") mypar="B_{s}^{0}";  

  double xlgap=0.04;
/*
  if(particle=="Bplus") xpos=(0.365816-xlgap)/0.365816;
  if(particle=="Bzero") xpos=1-xlgap/(0.673101-0.365816);
  if(particle=="Bs") xpos=0.94-xlgap/(1-0.673101);;  
*/
  TLatex * tlatex3=new TLatex(xpos,ypos,mypar.Data());
  tlatex3->SetNDC();
  tlatex3->SetTextColor(1);
  tlatex3->SetTextFont(42);
  tlatex3->SetTextSize(0.07*padcorrection);
  tlatex3->Draw();

  TGraphAsymmErrors *gRpAstat = new TGraphAsymmErrors(nbins,xbins,yRpA,exl0,exl0,yRpAStat,yRpAStat);
  gRpAstat->SetTitle("RpA stat uncertainty from pPb");
  gRpAstat->SetMarkerStyle(21);
  gRpAstat->SetMarkerColor(1);
  gRpAstat->SetLineColor(1);
  gRpAstat->SetLineWidth(2);  
  gRpAstat->SetFillColor(0);


  TGraphAsymmErrors *gRpAsyst = new TGraphAsymmErrors(nbins,xbins,yRpA,exl,exl,yRpPbSystTotLow,yRpPbSystTotHigh);
  gRpAsyst->SetTitle("RpA syst uncertainty from pPb");
  gRpAsyst->SetName("gRpAsyst");
/*
  gRpAsyst->SetFillColor(0);
  gRpAsyst->SetMarkerSize(0);
  gRpAsyst->SetLineColor(1);
  gRpAsyst->SetLineWidth(2);
  gRpAsyst->SetFillStyle(0);
*/
  gRpAsyst->SetFillColor(kYellow-7);//###0
  //gRpAsyst->SetMarkerSize(0);
  gRpAsyst->SetLineColor(1);
  gRpAsyst->SetLineWidth(2);
  gRpAsyst->SetFillStyle(1001);
  gRpAsyst->SetMarkerStyle(21);
  gRpAsyst->SetMarkerColor(1);
  TGraphAsymmErrors*gRpAsyst2=(TGraphAsymmErrors*)gRpAsyst->Clone();
  gRpAsyst2->SetMarkerColor(1);
  gRpAsyst2->SetMarkerStyle(25);
  gRpAsyst2->SetFillColor(0);
  gRpAsyst2->SetFillStyle(0);
  gRpAsyst2->SetLineColor(1);//5
  gRpAsyst2->SetLineStyle(1);
  gRpAsyst2->SetLineWidth(2);
  
  TGraphAsymmErrors *gRpAsystFONLL = new TGraphAsymmErrors(nbins,xbins,yFONLL,exl,exl,yRpAsystFONLLlow,yRpAsystFONLLhigh);
  gRpAsystFONLL->SetTitle("RpA syst uncertainty from FONLL reference");
/*
  gRpAsystFONLL->SetFillColor(kYellow-7);//5
  gRpAsystFONLL->SetLineColor(kAzure-3);//5
  gRpAsystFONLL->SetMarkerColor(4);//kAzure-3);

  TGraphAsymmErrors *gRpAsystFONLL2 = (TGraphAsymmErrors*)gRpAsystFONLL->Clone();
  gRpAsystFONLL2->SetFillStyle(0);
  gRpAsystFONLL2->SetLineColor(kAzure-3);//5
  gRpAsystFONLL2->SetMarkerColor(4);//kAzure-3);
*/
  gRpAsystFONLL->SetFillColor(0);//5,kYellow-7
  gRpAsystFONLL->SetLineColor(kAzure-3);//5
  gRpAsystFONLL->SetMarkerColor(4);//kAzure-3);
  gRpAsystFONLL->SetLineStyle(1);
  gRpAsystFONLL->SetLineWidth(2);

  TGraphAsymmErrors*gRpAsystFONLL2=(TGraphAsymmErrors*)gRpAsystFONLL->Clone();
  gRpAsystFONLL2->SetMarkerColor(1);
  gRpAsystFONLL2->SetMarkerStyle(25);
  gRpAsystFONLL2->SetFillColor(0);
  gRpAsystFONLL2->SetFillStyle(0);
  gRpAsystFONLL2->SetLineColor(kAzure-3);//5
  gRpAsystFONLL2->SetLineStyle(1);
  gRpAsystFONLL2->SetLineWidth(2);

  canvasRpA->cd(PadNum);
  //canvasRpA->Range(-1.989924,-0.2917772,25.49622,2.212202);
  canvasRpA->SetFillColor(0);
  canvasRpA->SetBorderMode(0);
  canvasRpA->SetBorderSize(2);
/*
  canvasRpA->SetLeftMargin(0.1451613);
  canvasRpA->SetRightMargin(0.05443548);
  canvasRpA->SetTopMargin(0.08474576);
  canvasRpA->SetBottomMargin(0.1165254);
*/
  canvasRpA->SetFrameBorderMode(0);
  canvasRpA->SetFrameBorderMode(0);
  
  hempty=new TH2F("hempty","",10,0.1, 62. ,30.,0.,3.0);  
  hempty->GetXaxis()->CenterTitle();
  hempty->GetYaxis()->CenterTitle();
  hempty->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  hempty->GetYaxis()->SetTitle("R^{FONLL}_{pA}");
  //###hempty->GetXaxis()->SetTitleOffset(1.0);//###1.3
  hempty->GetYaxis()->SetTitleOffset(1.0);//###1.1
  hempty->GetXaxis()->SetTitleSize(0.070*padcorrection);//###0.055
  hempty->GetYaxis()->SetTitleSize(0.070*padcorrection);//###0.055
  hempty->GetXaxis()->SetTitleFont(42);
  hempty->GetYaxis()->SetTitleFont(42);
  hempty->GetXaxis()->SetLabelFont(42);
  hempty->GetYaxis()->SetLabelFont(42);
  hempty->GetXaxis()->SetLabelSize(0.060*padcorrection);//###0.055
  hempty->GetYaxis()->SetLabelSize(0.060*padcorrection);//###0.055  
  if (particle=="Bplus") hempty->GetXaxis()->SetTitleOffset(0.90);//###1.0
  else if (particle=="Bzero") hempty->GetXaxis()->SetTitleOffset(0.90);//###0.80
  else if (particle=="Bs") hempty->GetXaxis()->SetTitleOffset(0.90);//###0.85
  if (particle=="Bplus") hempty->GetXaxis()->SetLabelOffset(0.005);//###0.005
  else if (particle=="Bzero") hempty->GetXaxis()->SetLabelOffset(0.005);//###0.0001
  else if (particle=="Bs") hempty->GetXaxis()->SetLabelOffset(0.005);//###0.0005
  //###hempty->SetMaximum(2);
  hempty->SetMaximum(3.0);
  hempty->SetMinimum(0.);

  hempty->Draw();
  
  TLine *l = new TLine(0,1, 65.,1);
  l->SetLineStyle(2);

  //TLine *line = new TLine(8.740882,1.017445,61,1.008586);
  //###TLine *line = new TLine(4.740882,1.017445,61,1.008586);
  TLine *line = new TLine(4.740882,1.00,61,1.00);


  line->SetLineColor(kRed);//###
  line->SetLineStyle(2);  
  line->SetLineWidth(2);
/*  
  gRpAsystFONLL->Draw("2same");
  gRpAsystFONLL2->Draw("2same");
  line->Draw();
  gRpAsyst->Draw("2esame");
  gRpAstat->Draw("psame");
*/
  gRpAstat->SetMarkerStyle(21);
  gRpAstat->SetLineColor(1);
  gRpAstat->SetMarkerColor(1);

for (int i=0;i<nbins;i++){
         double xgae,ygae;
         gRpAstat->GetPoint(i,xgae,ygae);
         std::cout << "####### RpA (" << i << ") : " << ygae << " stat: " << gRpAstat->GetEYhigh()[i] << " syst: " << gRpAsyst->GetEYhigh()[i] << std::endl;
	 std::cout << "########### FONLL (" << i << ") : " << " + " << gRpAsystFONLL->GetEYhigh()[i] << " - " << gRpAsystFONLL->GetEYlow()[i] << std::    endl;
}

  gRpAsystFONLL->Draw("2same");
  gRpAsystFONLL2->Draw("2same");
  //###line->Draw();

  gRpAsyst->Draw("2esame");
  gRpAsyst2->Draw("2esame");
  gRpAstat->Draw("psame");  
  line->Draw();

 
  TBox *a = new TBox(0.1,1-commonErrorN,4,1+commonErrorP);
  a->SetLineColor(1);
  a->SetFillColor(0);
  a->Draw();
  std::cout << "%%%%%%% RpA commonError " << " - " << commonErrorN << " + " << commonErrorP << std::endl;
  TBox *b = new TBox(0.1,1-commonErrorN,4,1+commonErrorP);
  b->SetLineColor(1);
  b->SetFillColor(kGray);
  b->Draw();
  TBox *b2 = (TBox*)b->Clone();
  b2->SetLineColor(1);
  b2->SetFillStyle(0);
  b2->Draw();

  TLegend *legendRpA=new TLegend(0.22,0.60,0.51,0.83,"");

  legendRpA->SetBorderSize(0);
  legendRpA->SetLineColor(0);
  legendRpA->SetFillColor(0);
  legendRpA->SetFillStyle(1001);
  legendRpA->SetTextFont(42);
  legendRpA->SetTextSize(0.060);//###0.045

  TLegendEntry *ent_RpAstat=legendRpA->AddEntry(gRpAstat,"R^{FONLL}_{pA}","p");
  //###TLegendEntry *ent_RpAstat=legendRpA->AddEntry(gRpAstat,"pPb data","pf");

/*
  ent_RpAstat->SetTextFont(42);
  ent_RpAstat->SetLineColor(2);
  ent_RpAstat->SetMarkerColor(2);
*/
  ent_RpAstat->SetTextFont(42);
  ent_RpAstat->SetMarkerColor(1);
  ent_RpAstat->SetMarkerStyle(25);
  //ent_RpAstat->SetFillColor(kYellow-7);//5
  //ent_RpAstat->SetFillStyle(1001);
  ent_RpAstat->SetLineColor(1);
  ent_RpAstat->SetLineWidth(2);
  ent_RpAstat->SetLineStyle(0);

  TLegendEntry *ent_RpAsyst=legendRpA->AddEntry(gRpAsyst,"Syst. pPb data","f");
  ent_RpAsyst->SetTextFont(42);
  ent_RpAsyst->SetMarkerColor(1);
  ent_RpAsyst->SetMarkerStyle(25);
  //ent_RpAsyst->SetFillColor(kYellow-7);//5
  //ent_RpAsyst->SetFillStyle(1001);
  ent_RpAsyst->SetLineColor(1);
  ent_RpAsyst->SetLineWidth(2);
  ent_RpAsyst->SetLineStyle(0);
  
  TLegendEntry *ent_RpAsystFONLL=legendRpA->AddEntry(gRpAsystFONLL,"Syst. FONLL pp ref.","f");
/*
  ent_RpAsystFONLL->SetTextFont(42);
  ent_RpAsystFONLL->SetLineColor(kAzure-3);//5
  ent_RpAsystFONLL->SetLineStyle(1);
  ent_RpAsystFONLL->SetLineWidth(1);
  ent_RpAsystFONLL->SetMarkerColor(kYellow-7);//5
*/

  ent_RpAsystFONLL->SetTextFont(42);
  ent_RpAsystFONLL->SetLineColor(2);//###5
  ent_RpAsystFONLL->SetLineStyle(1);
  ent_RpAsystFONLL->SetMarkerColor(kYellow-7);//5

   TLegendEntry *ent_RpAsystData=legendRpA->AddEntry(b,"Syst. int. lumi + B","f");
/*
  ent_RpAsystData->SetTextFont(42);
  ent_RpAsystData->SetLineColor(1);
  ent_RpAsystData->SetMarkerColor(2);
*/
  ent_RpAsystData->SetTextFont(42);
  ent_RpAsystData->SetLineColor(2);
  ent_RpAsystData->SetMarkerColor(2);
 
  //if(PadNum==1||PadNum==3){
    if(PadNum==3 || PadNum==1 || PadNum==2) {

    legendRpA->Draw();

    //TLatex * tlatex4=new TLatex(0.21,0.88801268,"CMS");
    TLatex * tlatex4=new TLatex(0.19,0.85,"CMS");

    tlatex4->SetNDC();
    tlatex4->SetTextColor(1);
    tlatex4->SetTextFont(62);//42
    tlatex4->SetTextSize(0.07);//0.045
    tlatex4->Draw();
/* 
    TLatex * tlatex42=new TLatex(0.35,0.86,"Preliminary");
    tlatex42->SetNDC();
    tlatex42->SetTextColor(1);
    tlatex42->SetTextFont(52);//42
    tlatex42->SetTextSize(0.05);//0.045
    tlatex42->Draw();
*/ 
    //TLatex * tlatex2=new TLatex(0.471371,0.88801268,"L = 34.8 nb^{-1} (pPb 5.02 TeV)");
    //TLatex * tlatex2=new TLatex(0.471371,0.88801268,"34.6 nb^{-1} (pPb 5.02 TeV)");
    //###TLatex * tlatex2=new TLatex(0.390,0.950,"34.6 nb^{-1} (pPb 5.02 TeV)");
    TLatex * tlatex2;

   if (PadNum==1) tlatex2 = new TLatex(0.41,0.94,"34.6 nb^{-1} (pPb 5.02 TeV)");
   else tlatex2 = new TLatex(0.39,0.94,"34.6 nb^{-1} (pPb 5.02 TeV)");

    tlatex2->SetNDC();
    tlatex2->SetTextColor(1);
    tlatex2->SetTextFont(42);
    tlatex2->SetTextSize(0.06);//0.045
   tlatex2->Draw();
  }
    //if(PadNum==2){
    if(PadNum==3 || PadNum==1 || PadNum==2) {

    TLatex * tlatex4=new TLatex(0.65,0.23,"|y_{lab}| < 2.4");
    tlatex4->SetNDC();
    tlatex4->SetTextColor(1);
    tlatex4->SetTextFont(42);//42
    tlatex4->SetTextSize(0.07);//0.045
    tlatex4->Draw();
	 }

  
  tlatex3->Draw();
  
  
  
  TFile *fout=new TFile(Form("../Results%s/fileRpA%s.root",particle.Data(),particle.Data()),"recreate");  
  fout->cd();
  gSigmasyst->SetName("gSigmasyst");
  gSigmasyst->Write();
  gaeBplusReference->Write();
  hSigmapPbStat->Write();
}
void makeNice(TString fileName, TString nice = "nicePlot"){

  TFile *f = TFile::Open(fileName);
  //  TFile *f = TFile::Open("out_Parameters_bkg1_3vtx.root");
  TGraphErrors * gRgre = (TGraphErrors*)f->Get("gR");
  TGraphErrors * gXgre = (TGraphErrors*)f->Get("gX");
  TGraphErrors * gYgre = (TGraphErrors*)f->Get("gY");

  TGraphErrors * rRgre = (TGraphErrors*)f->Get("rR");
  TGraphErrors * rXgre = (TGraphErrors*)f->Get("rX");
  TGraphErrors * rYgre = (TGraphErrors*)f->Get("rY");



//=========Macro generated from canvas: c1_n2/c1_n2
//=========  (Fri May 27 11:43:08 2011) by ROOT version5.27/06b
   TCanvas *c1_n2 = new TCanvas("c1_n2","c1_n2",700,1500);
   gStyle->SetOptFit(0);
   gStyle->SetOptStat(0);
   c1_n2->Range(0,0,1,1);
   c1_n2->SetFillColor(0);
   c1_n2->SetBorderMode(0);
   c1_n2->SetBorderSize(2);
   c1_n2->SetTickx(1);
   c1_n2->SetTicky(1);
   c1_n2->SetLeftMargin(0.13);
   c1_n2->SetRightMargin(0.05);
   c1_n2->SetTopMargin(0.05);
   c1_n2->SetBottomMargin(0.13);
   c1_n2->SetFrameFillStyle(0);
   c1_n2->SetFrameBorderMode(0);
  
// ------------>Primitives in pad: c1_n2_1
   TPad *c1_n2_1 = new TPad("c1_n2_1", "c1_n2_1",0.01,0.67,0.99,0.99);
   c1_n2_1->Draw();
   c1_n2_1->cd();
   c1_n2_1->Range(-52.68293,-0.03170732,44.87805,0.2121951);
   c1_n2_1->SetFillColor(0);
   c1_n2_1->SetBorderMode(0);
   c1_n2_1->SetBorderSize(2);
   c1_n2_1->SetTickx(1);
   c1_n2_1->SetTicky(1);
   c1_n2_1->SetLeftMargin(0.12);
   c1_n2_1->SetRightMargin(0.02);
   c1_n2_1->SetTopMargin(0.05);
   c1_n2_1->SetBottomMargin(0.2);
   c1_n2_1->SetFrameFillStyle(0);
   c1_n2_1->SetFrameBorderMode(0);
   c1_n2_1->SetFrameFillStyle(0);
   c1_n2_1->SetFrameBorderMode(0);
   
   TH1D *PLOTTERX = new TH1D("PLOTTERX","",1,-40,40);
   PLOTTERX->SetMinimum(-0.19);
   PLOTTERX->SetMaximum(+0.19);
   PLOTTERX->SetFillColor(63);
   PLOTTERX->SetLineStyle(0);
   PLOTTERX->SetMarkerStyle(20);
   PLOTTERX->GetXaxis()->SetLabelFont(42);
   PLOTTERX->GetXaxis()->SetLabelOffset(0.007);
   PLOTTERX->GetXaxis()->SetLabelSize(0.09);
   PLOTTERX->GetXaxis()->SetTitleSize(0.1);
   PLOTTERX->GetXaxis()->SetTitleOffset(0.9);
   PLOTTERX->GetXaxis()->SetTitleFont(42);
   PLOTTERX->GetXaxis()->SetTitle("z [cm]");
   PLOTTERX->GetYaxis()->SetNdivisions(505);
   PLOTTERX->GetYaxis()->SetTitle("x_{0} [cm] ");
   PLOTTERX->GetYaxis()->SetLabelFont(42);
   PLOTTERX->GetYaxis()->SetLabelOffset(0.007);
   PLOTTERX->GetYaxis()->SetLabelSize(0.09);
   PLOTTERX->GetYaxis()->SetTitleSize(0.1);
   PLOTTERX->GetYaxis()->SetTitleOffset(0.5);
   PLOTTERX->GetYaxis()->SetTitleFont(42);
   PLOTTERX->GetZaxis()->SetLabelFont(42);
   PLOTTERX->GetZaxis()->SetLabelOffset(0.007);
   PLOTTERX->GetZaxis()->SetLabelSize(0.05);
   PLOTTERX->GetZaxis()->SetTitleSize(0.06);
   PLOTTERX->GetZaxis()->SetTitleFont(42);
   PLOTTERX->Draw("");
   
   gXgre->SetFillColor(kBlack);
   gXgre->SetMarkerStyle(20);
   gXgre->SetMarkerColor(kBlack);
   gXgre->SetLineColor(kBlack);
   gXgre->GetListOfFunctions()->RemoveLast(); //to remove parameters panel...
   gXgre->GetListOfFunctions()->RemoveLast(); //...and old fit
   gXgre->SetLineWidth(2);
   gXgre->Draw("P");

   rXgre->SetFillColor(kBlue);
   rXgre->SetMarkerStyle(20);
   rXgre->SetMarkerColor(kBlue);
   rXgre->SetLineColor(kBlue);
   rXgre->GetListOfFunctions()->RemoveLast(); //to remove parameters panel...
   rXgre->GetListOfFunctions()->RemoveLast(); //...and old fit
   rXgre->SetLineWidth(2);
   rXgre->Draw("P");

   TLatex *CMSPrel = new TLatex(-37.0,PLOTTERX->GetMaximum()-0.025,"CMS Preliminary 2011");
   CMSPrel->SetTextSize(0.06);
   //   CMSPrel->Draw();
   c1_n2_1->Modified();
   c1_n2->cd();
  
// ------------>Primitives in pad: c1_n2_2
   TPad *c1_n2_2 = new TPad("c1_n2_1", "c1_n2_1",0.01,0.34,0.99,0.66);
   //   TPad *c1_n2_1 = new TPad("c1_n2_1", "c1_n2_1",0.01,0.01,0.99,0.33);
   c1_n2_2->Draw();
   c1_n2_2->cd();
   c1_n2_2->Range(-52.68293,-0.3317073,44.87805,-0.08780488);
   c1_n2_2->SetFillColor(0);
   c1_n2_2->SetBorderMode(0);
   c1_n2_2->SetBorderSize(2);
   c1_n2_2->SetTickx(1);
   c1_n2_2->SetTicky(1);
   c1_n2_2->SetLeftMargin(0.12);
   c1_n2_2->SetRightMargin(0.02);
   c1_n2_2->SetTopMargin(0.05);
   c1_n2_2->SetBottomMargin(0.2);
   c1_n2_2->SetFrameFillStyle(0);
   c1_n2_2->SetFrameBorderMode(0);
   c1_n2_2->SetFrameFillStyle(0);
   c1_n2_2->SetFrameBorderMode(0);
   
   TH1D *PLOTTERY = new TH1D("PLOTTERY","",1,-40,40);
   PLOTTERY->SetMinimum(-0.29);
   PLOTTERY->SetMaximum(+0.09);
   PLOTTERY->SetFillColor(63);
   PLOTTERY->SetLineStyle(0);
   PLOTTERY->SetMarkerStyle(20);
   PLOTTERY->GetXaxis()->SetLabelFont(42);
   PLOTTERY->GetXaxis()->SetLabelOffset(0.007);
   PLOTTERY->GetXaxis()->SetLabelSize(0.09);
   PLOTTERY->GetXaxis()->SetTitleSize(0.1);
   PLOTTERY->GetXaxis()->SetTitleFont(42);
   PLOTTERY->GetXaxis()->SetTitleOffset(0.9);
   PLOTTERY->GetXaxis()->SetTitle("z [cm]");
   PLOTTERY->GetYaxis()->SetNdivisions(505);
   PLOTTERY->GetYaxis()->SetTitle("y_{0} [cm] ");
   PLOTTERY->GetYaxis()->SetLabelFont(42);
   PLOTTERY->GetYaxis()->SetLabelOffset(0.007);
   PLOTTERY->GetYaxis()->SetLabelSize(0.09);
   PLOTTERY->GetYaxis()->SetTitleSize(0.1);
   PLOTTERY->GetYaxis()->SetTitleOffset(0.5);
   PLOTTERY->GetYaxis()->SetTitleFont(42);
   PLOTTERY->GetZaxis()->SetLabelFont(42);
   PLOTTERY->GetZaxis()->SetLabelOffset(0.007);
   PLOTTERY->GetZaxis()->SetLabelSize(0.05);
   PLOTTERY->GetZaxis()->SetTitleSize(0.06);
   PLOTTERY->GetZaxis()->SetTitleFont(42);
   PLOTTERY->Draw("");
   
   gYgre->SetFillColor(kBlack);
   gYgre->SetMarkerStyle(20);
   gYgre->SetMarkerColor(kBlack);
   gYgre->SetLineColor(kBlack);
   gYgre->GetListOfFunctions()->RemoveLast(); //to remove parameters panel...
   gYgre->GetListOfFunctions()->RemoveLast(); //...and old fit
   gYgre->SetLineWidth(2);
   gYgre->Draw("P");

   rYgre->SetFillColor(kBlue);
   rYgre->SetMarkerStyle(20);
   rYgre->SetMarkerColor(kBlue);
   rYgre->SetLineColor(kBlue);
   rYgre->GetListOfFunctions()->RemoveLast(); //to remove parameters panel...
   rYgre->GetListOfFunctions()->RemoveLast(); //...and old fit
   rYgre->SetLineWidth(2);
   rYgre->Draw("P");

   TLatex *CMSPrel = new TLatex(-37.0,PLOTTERY->GetMaximum()-0.025,"CMS Preliminary 2011");
   CMSPrel->SetTextSize(0.06);
   //   CMSPrel->Draw();
   c1_n2_2->Modified();
   c1_n2->cd();
  

// ------------>Primitives in pad: c1_n2_2
   TPad *c1_n2_3 = new TPad("c1_n2_1", "c1_n2_1",0.01,0.01,0.99,0.33);
   //   TPad *c1_n2_1 = new TPad("c1_n2_1", "c1_n2_1",0.01,0.01,0.99,0.33);
   c1_n2_3->Draw();
   c1_n2_3->cd();
   c1_n2_3->Range(-52.68293,-0.3317073,44.87805,-0.08780488);
   c1_n2_3->SetFillColor(0);
   c1_n2_3->SetBorderMode(0);
   c1_n2_3->SetBorderSize(2);
   c1_n2_3->SetTickx(1);
   c1_n2_3->SetTicky(1);
   c1_n2_3->SetLeftMargin(0.12);
   c1_n2_3->SetRightMargin(0.02);
   c1_n2_3->SetTopMargin(0.05);
   c1_n2_3->SetBottomMargin(0.2);
   c1_n2_3->SetFrameFillStyle(0);
   c1_n2_3->SetFrameBorderMode(0);
   c1_n2_3->SetFrameFillStyle(0);
   c1_n2_3->SetFrameBorderMode(0);
   
   TH1D *PLOTTERR = new TH1D("PLOTTERR","",1,-40,40);
   PLOTTERR->SetMinimum(2.87);
   PLOTTERR->SetMaximum(2.97);
   PLOTTERR->SetFillColor(63);
   PLOTTERR->SetLineStyle(0);
   PLOTTERR->SetMarkerStyle(20);
   PLOTTERR->GetXaxis()->SetLabelFont(42);
   PLOTTERR->GetXaxis()->SetLabelOffset(0.007);
   PLOTTERR->GetXaxis()->SetLabelSize(0.09);
   PLOTTERR->GetXaxis()->SetTitleSize(0.1);
   PLOTTERR->GetXaxis()->SetTitleFont(42);
   PLOTTERR->GetXaxis()->SetTitleOffset(0.9);
   PLOTTERR->GetXaxis()->SetTitle("z [cm]");
   PLOTTERR->GetYaxis()->SetNdivisions(505);
   PLOTTERR->GetYaxis()->SetTitle("R [cm] ");
   PLOTTERR->GetYaxis()->SetLabelFont(42);
   PLOTTERR->GetYaxis()->SetLabelOffset(0.007);
   PLOTTERR->GetYaxis()->SetLabelSize(0.09);
   PLOTTERR->GetYaxis()->SetTitleSize(0.1);
   PLOTTERR->GetYaxis()->SetTitleOffset(0.5);
   PLOTTERR->GetYaxis()->SetTitleFont(42);
   PLOTTERR->GetZaxis()->SetLabelFont(42);
   PLOTTERR->GetZaxis()->SetLabelOffset(0.007);
   PLOTTERR->GetZaxis()->SetLabelSize(0.05);
   PLOTTERR->GetZaxis()->SetTitleSize(0.06);
   PLOTTERR->GetZaxis()->SetTitleFont(42);
   PLOTTERR->Draw("");
   
   gRgre->SetFillColor(kBlack);
   gRgre->SetMarkerStyle(20);
   gRgre->SetMarkerColor(kBlack);
   gRgre->SetLineColor(kBlack);
   gRgre->GetListOfFunctions()->RemoveLast(); //to remove parameters panel...
   gRgre->GetListOfFunctions()->RemoveLast(); //...and old fit
   gRgre->SetLineWidth(2);
   gRgre->Draw("P");

   rRgre->SetFillColor(kBlue);
   rRgre->SetMarkerStyle(20);
   rRgre->SetMarkerColor(kBlue);
   rRgre->SetLineColor(kBlue);
   rRgre->GetListOfFunctions()->RemoveLast(); //to remove parameters panel...
   rRgre->GetListOfFunctions()->RemoveLast(); //...and old fit
   rRgre->SetLineWidth(2);
   rRgre->Draw("P");

   TLatex *CMSPrel = new TLatex(-37.0,PLOTTERR->GetMaximum()-0.025,"CMS Preliminary 2011");
   CMSPrel->SetTextSize(0.06);
   //   CMSPrel->Draw();
   c1_n2_3->Modified();
   c1_n2->cd();
 
   

   TF1* fX = new TF1("fX", "[0]+[1]*x", -35, 35); 
   TF1* fY = new TF1("fY", "[0]+[1]*x", -35, 35); 
   TF1* fR = new TF1("fR", "[0]+[1]*x", -35, 35); 

   fX->SetParameter(0, 0.1);
   fX->SetParameter(1, -0.0007);

   fY->SetParameter(0, -0.2);
   fY->SetParameter(1, +0.0007);

   fR->SetParameter(0, 2.94);
   fR->SetParameter(1, 0.0);

   gXgre->Fit(fX);
   gYgre->Fit(fY);
   gRgre->Fit(fR);

   //
   c1_n2->cd();
   c1_n2->Modified();
   c1_n2->cd();
   c1_n2->SetSelected(c1_n2);

   c1_n2->SaveAs(nice+".png"); //!Serve!!!!
   c1_n2->SaveAs(nice+".gif");
   c1_n2->SaveAs(nice+".png");


}
Beispiel #23
0
TH1D * drawQual(TFile * inf, TCanvas * c, Int_t ic, Float_t ymin, Float_t ymax, Int_t doLog)
{
  c->Divide(3,1);
  c->cd(1);
  if (doLog==1) gPad->SetLogy();
  TH1D * hQual_precut_mc = (TH1D*)inf->FindObjectAny(Form("hTrkQual%dPreCut_mc80",ic));
  TH1D * hQual_precut_data = (TH1D*)inf->FindObjectAny(Form("hTrkQual%dPreCut_dataj35",ic));
  TH1D * hQual_mc = (TH1D*)inf->FindObjectAny(Form("hTrkQual%dPostCut_mc80",ic));
  TH1D * hQual_data = (TH1D*)inf->FindObjectAny(Form("hTrkQual%dPostCut_dataj35",ic));
  if (!hQual_precut_mc) cout << Form("hTrkQual%dPreCut_mc80 not found",ic) << endl;
  if (!hQual_precut_data) cout << Form("hTrkQual%dPreCut_dataj35 not found",ic) << endl;
  hQual_precut_mc->Scale(1./hQual_precut_mc->GetEntries());
  hQual_precut_data->Scale(1./hQual_precut_data->GetEntries());
  hQual_mc->Scale(1./hQual_precut_mc->GetEntries());
  hQual_data->Scale(1./hQual_precut_data->GetEntries());

  hQual_precut_mc->SetAxisRange(ymin,ymax,"Y");
  hQual_precut_mc->SetLineColor(2);
  hQual_precut_mc->SetLineStyle(2);
  hQual_mc->SetMarkerStyle(kOpenCircle);
  hQual_mc->SetMarkerColor(2);
  hQual_mc->SetLineColor(2);
  hQual_precut_data->SetLineStyle(2);
  hQual_precut_mc->Draw("hist");
  hQual_precut_data->Draw("same hist");
  hQual_mc->Draw("same E");
  hQual_data->Draw("same E");

  c->cd(2);
  gPad->SetLogy();
  TH1D * hPPt_precut_mc = inf->FindObjectAny(Form("hPPt_cut%d_mc80",ic-1));
  TH1D * hPPt_precut_data = inf->FindObjectAny(Form("hPPt_cut%d_dataj35",ic-1));
  TH1D * hPPt_mc = inf->FindObjectAny(Form("hPPt_cut%d_mc80",ic));
  TH1D * hPPt_data = inf->FindObjectAny(Form("hPPt_cut%d_dataj35",ic));

  hPPt_precut_mc->SetAxisRange(5e-5,2,"Y");
  hPPt_precut_mc->SetMarkerColor(2);
  hPPt_precut_mc->SetLineColor(2);
  hPPt_precut_mc->SetLineStyle(2);
  hPPt_precut_data->SetLineStyle(2);
  hPPt_mc->SetMarkerStyle(kOpenCircle);
  hPPt_mc->SetLineColor(2);
  hPPt_mc->SetMarkerColor(2);
  hPPt_precut_mc->Draw("hist");
  hPPt_precut_data->Draw("samehist");
  hPPt_mc->Draw("sameE");
  hPPt_data->Draw("sameE");

  c->cd(3);
  TH1D * hRatMc = hPPt_mc->Clone(Form("%s_rat",hPPt_mc->GetName()));
  hRatMc->Divide(hPPt_precut_mc);
  TH1D * hRatData = hPPt_data->Clone(Form("%s_rat",hPPt_data->GetName()));
  hRatData->Divide(hPPt_precut_data);
  hRatMc->SetAxisRange(0,1.1,"Y");
  hRatMc->SetMarkerStyle(kOpenCircle);
  hRatMc->SetMarkerColor(2);
  hRatMc->SetLineColor(2);
	hRatMc->SetLineStyle(1);
  hRatData->SetLineStyle(1);
	hRatMc->SetYTitle("(After Cut)/(Before Cut)");
  hRatMc->Draw("E");
  hRatData->Draw("sameE");

  return hPPt_data;
}
Beispiel #24
0
void createDataVsMC(TString folderName,TString histoName,int rebin,double xMin,double xMax,TString xName, TString yName, vector<TString> MCFileNames, vector<TString> MCNames, vector<int> MCColors, vector<bool> AddToBkg,vector<TString> DataFileNames,vector<TString> dataNames,vector<int> dataColors,vector<TString> SystNames,vector<int> SystColors, TCanvas *cCanvas, int padNr, bool UseLog,GlobalParameterSet Parameters) {
					 
  // CREATE ALL HISTOGRAMS ========================================================

  TString lumi = "";
  lumi+=Parameters.intLumi;
  if(Parameters.GlobalLog) {
    UseLog = true;  
  }
       
  // SM background histo
  TH1D *hSM0=0; 
  // Create MC histos and add them SM0
  vector<TH1D*> MChistos;
  bool noneAdded = true;

  float eventsMC=0;
  if(Parameters.MuPred){
    for(unsigned int i =0;i<3;i++) {
      TFile* fhh = TFile::Open(MCFileNames[i],"READONLY");
      TH1D *hTemp = (TH1D*)fhh->Get(folderName+"/CounterCtrl_tot");
      eventsMC += hTemp->GetBinContent(1);
      cout << "eventsMC " <<eventsMC<< endl;
      //delete hTemp;
      // delete fhh;
    }
    
    TFile* fdata_test = TFile::Open(DataFileNames[0],"READONLY");
    TH1D *hTempddd = (TH1D*)fdata_test->Get(folderName+"/CounterCtrl_tot");
    cout << "eventsMC " << eventsMC<< " "<<hTempddd->GetBinContent(1) << endl;
    Parameters.intLumi =  100*hTempddd->GetBinContent(1)/eventsMC;
  }
  
  // delete fdata_test;
  // delete hTempddd;

  for(unsigned int i =0;i<MCFileNames.size();i++) {
    MChistos.push_back(plot1Dhisto(Parameters.intLumi,TFile::Open(MCFileNames[i],"READONLY"),folderName,histoName,MCColors[i],rebin,xMin,xMax,xName,yName,"MC",true));
    if(noneAdded&&AddToBkg[i]) {
      hSM0 = (TH1D *) MChistos[i]->Clone();
      noneAdded = false;
    }
    else {
      if(AddToBkg[i]) {
	hSM0->Add(MChistos[i],1);
      }	  
    }
  }
  hSM0->SetLineColor(2);
   
  // Create Histograms with the different systematics
  vector<TH1D*> SystHistos;
  if(Parameters.UseSystematics) {
    for(unsigned int i=0; i<SystNames.size(); i++) {
      noneAdded = true;
      for(unsigned int j=0; j<MCFileNames.size(); j++) {
	if(AddToBkg[j]) {
	  TString SystFileName = MCFileNames[j];
	  SystFileName.Insert(SystFileName.Last('/'),"_"+SystNames[i]);
	  TFile *SystMCFile = TFile::Open(SystFileName,"READONLY");
	  TH1D *SystHistoTemp = plot1Dhisto(Parameters.intLumi,SystMCFile,folderName,histoName,SystColors[i],rebin,xMin,xMax,xName,yName,"MC",true);
	  SystHistoTemp->SetLineStyle(2);
	  if(noneAdded) {
	    SystHistos.push_back((TH1D *) SystHistoTemp->Clone());
	    noneAdded = false;
	  }
	  else {
	    SystHistos.back()->Add(SystHistoTemp,1);
	  }
	}
      }
    }
  }

  // Create Histograms for error band
  TH1D* hSM0allErrors = (TH1D *) hSM0->Clone();
  TH1D* hSM0systErrors = (TH1D *) hSM0->Clone();
  if(Parameters.UseSystematics) {
    for(int j = hSM0->FindBin(xMin); j<=hSM0->FindBin(xMax); j++) {
      double downerror=0;
      double uperror=0;
      for(unsigned int i=0; i<SystHistos.size(); i++) {
	double diff = SystHistos[i]->GetBinContent(j) - hSM0->GetBinContent(j);
	if(diff>0)
	  uperror += diff*diff;
	else
	  downerror += diff*diff;
      }
      downerror = TMath::Sqrt(downerror);
      uperror = TMath::Sqrt(uperror);
      double maxerror = TMath::Max(downerror,uperror);
      double staterror = hSM0->GetBinError(j);
      hSM0systErrors->SetBinError(j,maxerror);
      hSM0allErrors->SetBinError(j,TMath::Sqrt(maxerror*maxerror+staterror*staterror));
      hSM0systErrors->SetFillColor(5);
      hSM0systErrors->SetLineColor(5);
      hSM0allErrors->SetLineColor(3);
      hSM0allErrors->SetFillColor(3);
    }
  }
  
  // Create Data Histograms
  vector<TH1D *> dataHistos; 
  for(unsigned int i=0; i<DataFileNames.size();i++) {
    dataHistos.push_back(plot1Dhisto(Parameters.intLumi,TFile::Open(DataFileNames[i],"READONLY"),folderName,histoName,dataColors[i],rebin,xMin,xMax,xName,yName,"Data",false));
    dataHistos[i]->SetMarkerSize(1.2); 
    dataHistos[i]->SetMarkerColor(dataColors[i]); 
    dataHistos[i]->SetMarkerStyle(20);
    // remove error manually  
    if(!Parameters.ShowStatErrorbars){
      NoError(dataHistos[i],xMin,xMax);
    }
    // y-axis range
    if (UseLog){ 
      dataHistos[i]->GetYaxis()->SetRangeUser(1.,3.5*(dataHistos[i]->GetBinContent(dataHistos[i]->GetMaximumBin()))); 
    }
    else{ 
      float maximum =  hSM0->GetMaximum();
      if(maximum<dataHistos[i]->GetMaximum())maximum=dataHistos[i]->GetMaximum();
      dataHistos[i]->GetYaxis()->SetRangeUser(0.,maximum*1.8);
    }

  }
  
  cCanvas->SetName(folderName+histoName);
  cCanvas->cd(2*padNr+1);  

  if(UseLog) {
    gPad->SetLogy(); 
  }
  dataHistos[0]->Draw("P E0");

  //DRAW ALL HISTOGRAMS =====================================================    
  
  if(Parameters.ShowMCComposition){
    for(unsigned int i=1; Parameters.StackMCComposition&&i<MChistos.size();i++) {
      MChistos[i]->Add(MChistos[i],MChistos[i-1]);
      MChistos[i]->SetFillColor(MCColors[i]);
      MChistos[i]->SetLineStyle(1);
      MChistos[i]->SetFillStyle(3004);
      MChistos[i-1]->SetFillStyle(3004);
      MChistos[i-1]->SetFillColor(MCColors[i-1]); 	  	  
      
    }  	
    for(int i=MChistos.size()-1;i>=0;i--) {
      if(Parameters.ShowMCStatErrorbars)
	MChistos[i]->Draw("HIST E0 same");
      else
	MChistos[i]->Draw("HIST same");
    }
  }
  
  hSM0->SetLineColor(kRed);

  if(Parameters.ShowErrorBand) {
    hSM0allErrors->Draw("E2 same");
    hSM0systErrors->Draw("E2 same");
  }

  if(!Parameters.ShowMCStatErrorbars&&!Parameters.StackMCComposition)
    hSM0->Draw("HIST same"); 
  	
  if(Parameters.ShowSystematicsDetails) {
    for(unsigned int i=0; i<SystHistos.size();i++) {
      SystHistos[i]->Draw("HIST same");
    }
  } 
  
  for(int i=dataHistos.size()-1;i>=0;i--) {
    dataHistos[i]->Draw("P E0 same");
  }
  if(Parameters.ShowMCStatErrorbars&&!Parameters.StackMCComposition) {
    hSM0->Draw("HIST same E0");
  }
  // Draw Legend
  TLegend *lSamples = legendRAW(0.77,0.58,0.95,0.89);
  if(!Parameters.StackMCComposition)
    lSamples->AddEntry(hSM0,"Total MC","FL");
  if(Parameters.ShowErrorBand) {
    lSamples->AddEntry(hSM0systErrors,"Systematic Error","FL");
    lSamples->AddEntry(hSM0allErrors,"MC Syst. #oplus Stat. Error","FL");
  }
  for(unsigned int i=0; i<dataHistos.size(); i++) { 
    lSamples->AddEntry(dataHistos[i],dataNames[i],"PL");
  }
  for(unsigned int i =0;i<MChistos.size()&&Parameters.ShowMCComposition;i++) {
    lSamples->AddEntry(MChistos[i],MCNames[i],"FL");
  }
  for(unsigned int i =0;i<SystHistos.size()&&Parameters.ShowSystematicsDetails;i++) {
    lSamples->AddEntry(SystHistos[i],SystNames[i],"FL");
  }
  
  lSamples->Draw("same");

  TLatex *lWhichLepton;
  if (Parameters.electrons) { lWhichLepton = new TLatex(0.73,0.9,"Electrons"); }
  else { lWhichLepton = new TLatex(0.73,0.9,"Muons"); }
  lWhichLepton->SetNDC();
  lWhichLepton->Draw("same");
  

  TLatex *lPreliminary = new TLatex(0.19,0.96,"CMS Preliminary 2011");

  //  TLatex *lIntLumi = new TLatex(0.15,0.89,"#scale[0.8]{#int L dt = "+lumi+" pb^{-1}, #sqrt{s} = 7 TeV}");
  TLatex *lIntLumi  = new TLatex(0.22,0.88,"#scale[1.]{4.7 fb^{-1}, #sqrt{s} = 7 TeV}");
  TLatex *lIntLumiB = new TLatex(0.22,0.79,"#scale[1.]{#sqrt{s} = 7 TeV}");
  lPreliminary->SetNDC();
  lIntLumi->SetNDC();
  lIntLumiB->SetNDC();
  lPreliminary->Draw("same");
  lIntLumi->Draw("same"); 
  gPad->SetFillColor(0);
  //  lIntLumiB->Draw("same"); 
  //  gPad->SetGridx(); 
  //  gPad->SetGridy();
  

  // --- create HT and STlep legends
  //"ANplots150_NOLPsecondD500" folderNames
  
  TString HT500 = "secondD500";
  TString HT750 = "secondD750";
  TString HT1000 = "secondD1000";
  
  TString ST150 = "plots150";
  TString ST250 = "plots250";
  TString ST350 = "plots350";
  TString ST450 = "plots450";

  TString tmpLegendHT, tmpLegendST;

  if (((folderName.SubString(HT500)).Length())>0)       { if (Parameters.htBins) { tmpLegendHT = "H_{T}#in[500,750]"; }  else { tmpLegendHT = "H_{T}>500";}  } 
  else if (((folderName.SubString(HT750)).Length())>0)  { if (Parameters.htBins) { tmpLegendHT = "H_{T}#in[750,1000]"; } else { tmpLegendHT = "H_{T}>750";}  } 
  else if (((folderName.SubString(HT1000)).Length())>0) { if (Parameters.htBins) { tmpLegendHT = "H_{T}>1000"; }         else { tmpLegendHT = "H_{T}>1000";} } 
  else { tmpLegendHT = "error"; }

  if (((folderName.SubString(ST150)).Length())>0)      { tmpLegendST = "S^{lep}_{T}#in[150,250]"; }
  else if (((folderName.SubString(ST250)).Length())>0) { tmpLegendST = "S^{lep}_{T}#in[250,350]"; }
  else if (((folderName.SubString(ST350)).Length())>0) { tmpLegendST = "S^{lep}_{T}#in[350,450]"; }
  else if (((folderName.SubString(ST450)).Length())>0) { tmpLegendST = "S^{lep}_{T}>450"; }
  else { tmpLegendST = "error"; }

  TString legendHTandST = tmpLegendHT+" , "+tmpLegendST; 
  TLatex *lHTandST = new TLatex(0.22,0.8,legendHTandST);
  lHTandST->SetNDC();
  //  lHTandST->Draw("same");
  
  TLatex *lHT = new TLatex(0.22,0.8,tmpLegendHT);
  lHT->SetNDC();
  lHT->Draw("same");

  TLatex *lST = new TLatex(0.22,0.7,tmpLegendST);
  lST->SetNDC();
  lST->Draw("same");



  // DRAW RATIO PLOTS ============================================================================
  if (Parameters.ratioplot)
    {
      vector<TH1D*> hRatio;
      for(unsigned int i=0; i<dataHistos.size()&&MChistos.size()>0; i++) {
	hRatio.push_back((TH1D*)dataHistos[i]->Clone(""));
	hRatio.back()->Divide(dataHistos[i],hSM0);
	hRatio.back()->GetYaxis()->SetTitle("Data / MC");
	hRatio.back()->GetYaxis()->SetTitleSize(0.16);
	hRatio.back()->GetXaxis()->SetTitle("");
	hRatio.back()->GetYaxis()->SetNdivisions(409);
	hRatio.back()->GetYaxis()->SetRangeUser(0.,2.);
	hRatio.back()->SetTitleSize(0.16, "XY");
	hRatio.back()->SetTitleOffset(0.5, "Y");
	hRatio.back()->SetLabelSize(0.165,"XY");
	
      }
      
      for(unsigned int i=0; Parameters.UseSystematics&&Parameters.ShowSystematicsDetails&&i<SystHistos.size(); i++) {
	hRatio.push_back((TH1D*)SystHistos[i]->Clone(""));
	hRatio.back()->Divide(SystHistos[i],hSM0);
	hRatio.back()->GetYaxis()->SetTitle("Data&Syst/MC");
	hRatio.back()->GetYaxis()->SetRangeUser(0.5,1.5);
	hRatio.back()->GetXaxis()->SetTitle("");
	hRatio.back()->SetTitleSize(0.06, "XY");
	hRatio.back()->SetTitleOffset(0.8, "Y");
	hRatio.back()->SetLabelSize(0.08,"XY");
	NoError(hRatio.back(),xMin,xMax);
      }
      
      cCanvas->cd(2*padNr+2);
      //  TBox *unity = new TBox(xMin-0.1,0.95,xMax+0.15, 1.05); // LP
      TBox *unity = new TBox(xMin-0.1,0.95,xMax+0.15, 1.05);
      
      unity->SetLineWidth(2);
      //unity.SetLineStyle(Root.kDashed);
      unity->SetLineColor(2);
      unity->SetFillColor(2);
      unity->SetFillStyle(3002);
      //  unity->Draw();
      //  gPad->SetGridx(); 
      //  gPad->SetGridy();
      for(unsigned int i=hRatio.size()-1; i<hRatio.size(); i--) {
	if(i==hRatio.size()-1) {
	  hRatio[i]->Draw();
	  //      unity->Draw("same");
	  hRatio[i]->Draw("same");
	}
	else
	  {
	    hRatio[i]->GetYaxis()->SetTitleSize(0.055);
	    hRatio[i]->Draw("same"); 
	  }
      }
    } // ratio stuff close

}
// Plotfunction
TH1D* Plotvariable::plot(Color_t color /*= kBlue*/, Style_t style/* = 1*/, std::string options/* = ""*/) {

    clock_t clocktime = clock();
    std::stringstream ss;
    int randnr = rand() % 100;
    ss << savename_ << "_" << clocktime << "_" << randnr;
    std::string histid;
    histid = ss.str();



    /*
    static int globalidnr = 0;
    std::string histid = "Plotvariablehist_" +  std::to_string(globalidnr);                              //Histogram needs ID => get it from globalidnr and increase globalid
    globalidnr += 1;
    */

    //Prepare strings so that branch can be read from TTree
    std::string str_nbins   = std::to_string(nbins_);
    std::string str_xlow    = std::to_string(xlow_);
    std::string str_xup     = std::to_string(xup_);  
    std::string cuts        = cuts_;

    std::string str_tree2hist = name_ + " >> " +histid+ "(" + str_nbins + "," + str_xlow + "," +str_xup+ ")";   //Add prepared strings together

    tree_->Draw(str_tree2hist.c_str(), cuts.c_str(), options.c_str());                                                //Write Branch from tree

    TH1D* htemp;                                                                                                    //Edit color and style of histogram
    htemp = (TH1D*)tree_->GetHistogram();
    std::string histtitel = title_;
    htemp->SetTitle(histtitel.c_str());
    htemp->SetLineColor(color);
    htemp->SetLineStyle(style);

    //Edit axis labels
    double binwidth = (xup_ - xlow_) / nbins_;
    std::ostringstream out;                               //Set precision of binwidth
    out << std::setprecision(2) << binwidth;
    std::string str_binwidth = out.str();
    
    std::string xlabel, ylabel;

    if(unit_ != "") {
        xlabel =  xlabel_ + " (" + unit_ + ")";
        ylabel = "Events / (" + str_binwidth + " " + unit_ + ")";
    }
    else {
        xlabel = xlabel_;
        ylabel = "Events / (" + str_binwidth + ")";
    }



    
    htemp -> GetXaxis() -> SetTitle(xlabel.c_str());
    htemp -> GetXaxis() -> SetTitleOffset(1.18);

    htemp -> GetYaxis() -> SetTitle(ylabel.c_str());
    htemp -> GetYaxis() -> SetTitleOffset(1.48);

    return htemp;
}
void plotFakeRate_eta(){

  TFile *f1= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_hadd.root"); 
  TFile *f2= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT100to200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");
  TFile *f3= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT200to300_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");
  TFile *f4= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT300to500_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");
  TFile *f5= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT500to700_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");
  TFile *f6= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT700to1000_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");
  TFile *f7= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT1000to1500_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");
  TFile *f8= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT1500to2000_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");

  TFile *g1= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-100To200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");
  TFile *g2= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-200To400_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");
  TFile *g3= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-400To600_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");
  TFile *g4= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-600To800_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");
  TFile *g5= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-800To1200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");
  TFile *g6= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-1200To2500_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");
  TFile *g7= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-2500ToInf_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root");

  TFile *h1= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds/nominal/DoubleMuon_Run2015C_16Dec2015_hadd.root");
  TFile *h2= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds/nominal/DoubleMuon_Run2015D_16Dec2015_hadd.root");
  TFile *h3= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds/nominal/DoubleEG_Run2015C_16Dec2015_hadd.root");
  TFile *h4= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds/nominal/DoubleEG_Run2015D_16Dec2015_hadd.root");

  TFile *h5= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/TT_TuneCUETP8M1_13TeV-powheg-pythia8_hadd.root");

  /*
   NTotalSLPassed = new TH1D("NTotalSLPassed","",3,0,3);
   NLooseTightEl = new TH1D("NLooseTightEl","",2,0,2);
   NLooseTightMu = new TH1D("NLooseTightMu","",2,0,2);
   NLooseEl_Pt = new TH1D("NLooseEl_Pt","",5,ptbins);
   NLooseMu_Pt = new TH1D("NLooseMu_Pt","",5,ptbins);
   NLooseEl_Eta = new TH1D("NLooseEl_Eta","",4,etabinsEl);
   NLooseMu_Eta = new TH1D("NLooseMu_Eta","",4,etabinsMu);
   NLooseEl_Eta = new TH1D("NLooseEl_Eta","",5,ptbins,4,etabinsEl);
   NLooseMu_Eta = new TH1D("NLooseMu_Eta","",5,ptbins,4,etabinsMu);
   NTightEl_Pt = new TH1D("NTightEl_Pt","",5,ptbins);
   NTightMu_Pt = new TH1D("NTightMu_Pt","",5,ptbins);
   NTightEl_Eta = new TH1D("NTightEl_Eta","",4,etabinsEl);
   NTightMu_Eta = new TH1D("NTightMu_Eta","",4,etabinsMu);
   NTightEl_Eta = new TH1D("NTightEl_Eta","",5,ptbins,4,etabinsEl);
   NTightMu_Eta = new TH1D("NTightMu_Eta","",5,ptbins,4,etabinsMu);
  */

  TH1D *NLEl_DY = (TH1D*)f1->Get("NLooseEl_Eta");
  TH1D *NLMu_DY = (TH1D*)f1->Get("NLooseMu_Eta");
  TH1D *NTEl_DY = (TH1D*)f1->Get("NTightEl_Eta");
  TH1D *NTMu_DY = (TH1D*)f1->Get("NTightMu_Eta");

  TH1D *NLEl_WJ100 = (TH1D*)g1->Get("NLooseEl_Eta");
  TH1D *NLMu_WJ100 = (TH1D*)g1->Get("NLooseMu_Eta");
  TH1D *NTEl_WJ100 = (TH1D*)g1->Get("NTightEl_Eta");
  TH1D *NTMu_WJ100 = (TH1D*)g1->Get("NTightMu_Eta");
  TH1D *NLEl_WJ200 = (TH1D*)g2->Get("NLooseEl_Eta");
  TH1D *NLMu_WJ200 = (TH1D*)g2->Get("NLooseMu_Eta");
  TH1D *NTEl_WJ200 = (TH1D*)g2->Get("NTightEl_Eta");
  TH1D *NTMu_WJ200 = (TH1D*)g2->Get("NTightMu_Eta");
  TH1D *NLEl_WJ400 = (TH1D*)g3->Get("NLooseEl_Eta");
  TH1D *NLMu_WJ400 = (TH1D*)g3->Get("NLooseMu_Eta");
  TH1D *NTEl_WJ400 = (TH1D*)g3->Get("NTightEl_Eta");
  TH1D *NTMu_WJ400 = (TH1D*)g3->Get("NTightMu_Eta");
  TH1D *NLEl_WJ600 = (TH1D*)g4->Get("NLooseEl_Eta");
  TH1D *NLMu_WJ600 = (TH1D*)g4->Get("NLooseMu_Eta");
  TH1D *NTEl_WJ600 = (TH1D*)g4->Get("NTightEl_Eta");
  TH1D *NTMu_WJ600 = (TH1D*)g4->Get("NTightMu_Eta");
  TH1D *NLEl_WJ800 = (TH1D*)g5->Get("NLooseEl_Eta");
  TH1D *NLMu_WJ800 = (TH1D*)g5->Get("NLooseMu_Eta");
  TH1D *NTEl_WJ800 = (TH1D*)g5->Get("NTightEl_Eta");
  TH1D *NTMu_WJ800 = (TH1D*)g5->Get("NTightMu_Eta");
  TH1D *NLEl_WJ1200 = (TH1D*)g6->Get("NLooseEl_Eta");
  TH1D *NLMu_WJ1200 = (TH1D*)g6->Get("NLooseMu_Eta");
  TH1D *NTEl_WJ1200 = (TH1D*)g6->Get("NTightEl_Eta");
  TH1D *NTMu_WJ1200 = (TH1D*)g6->Get("NTightMu_Eta");
  TH1D *NLEl_WJ2500 = (TH1D*)g7->Get("NLooseEl_Eta");
  TH1D *NLMu_WJ2500 = (TH1D*)g7->Get("NLooseMu_Eta");
  TH1D *NTEl_WJ2500 = (TH1D*)g7->Get("NTightEl_Eta");
  TH1D *NTMu_WJ2500 = (TH1D*)g7->Get("NTightMu_Eta");

  TH1D *NLEl_QCD100 = (TH1D*)f2->Get("NLooseEl_Eta");
  TH1D *NLMu_QCD100 = (TH1D*)f2->Get("NLooseMu_Eta");
  TH1D *NTEl_QCD100 = (TH1D*)f2->Get("NTightEl_Eta");
  TH1D *NTMu_QCD100 = (TH1D*)f2->Get("NTightMu_Eta");
  TH1D *NLEl_QCD200 = (TH1D*)f3->Get("NLooseEl_Eta");
  TH1D *NLMu_QCD200 = (TH1D*)f3->Get("NLooseMu_Eta");
  TH1D *NTEl_QCD200 = (TH1D*)f3->Get("NTightEl_Eta");
  TH1D *NTMu_QCD200 = (TH1D*)f3->Get("NTightMu_Eta");
  TH1D *NLEl_QCD300 = (TH1D*)f4->Get("NLooseEl_Eta");
  TH1D *NLMu_QCD300 = (TH1D*)f4->Get("NLooseMu_Eta");
  TH1D *NTEl_QCD300 = (TH1D*)f4->Get("NTightEl_Eta");
  TH1D *NTMu_QCD300 = (TH1D*)f4->Get("NTightMu_Eta");
  TH1D *NLEl_QCD500 = (TH1D*)f5->Get("NLooseEl_Eta");
  TH1D *NLMu_QCD500 = (TH1D*)f5->Get("NLooseMu_Eta");
  TH1D *NTEl_QCD500 = (TH1D*)f5->Get("NTightEl_Eta");
  TH1D *NTMu_QCD500 = (TH1D*)f5->Get("NTightMu_Eta");
  TH1D *NLEl_QCD700 = (TH1D*)f6->Get("NLooseEl_Eta");
  TH1D *NLMu_QCD700 = (TH1D*)f6->Get("NLooseMu_Eta");
  TH1D *NTEl_QCD700 = (TH1D*)f6->Get("NTightEl_Eta");
  TH1D *NTMu_QCD700 = (TH1D*)f6->Get("NTightMu_Eta");
  TH1D *NLEl_QCD1000 = (TH1D*)f7->Get("NLooseEl_Eta");
  TH1D *NLMu_QCD1000 = (TH1D*)f7->Get("NLooseMu_Eta");
  TH1D *NTEl_QCD1000 = (TH1D*)f7->Get("NTightEl_Eta");
  TH1D *NTMu_QCD1000 = (TH1D*)f7->Get("NTightMu_Eta");
  TH1D *NLEl_QCD1500 = (TH1D*)f8->Get("NLooseEl_Eta");
  TH1D *NLMu_QCD1500 = (TH1D*)f8->Get("NLooseMu_Eta");
  TH1D *NTEl_QCD1500 = (TH1D*)f8->Get("NTightEl_Eta");
  TH1D *NTMu_QCD1500 = (TH1D*)f8->Get("NTightMu_Eta");

  TH1D *NLEl_DMC = (TH1D*)h1->Get("NLooseEl_Eta");
  TH1D *NLMu_DMC = (TH1D*)h1->Get("NLooseMu_Eta");
  TH1D *NTEl_DMC = (TH1D*)h1->Get("NTightEl_Eta");
  TH1D *NTMu_DMC = (TH1D*)h1->Get("NTightMu_Eta");
  TH1D *NLEl_DMD = (TH1D*)h2->Get("NLooseEl_Eta");
  TH1D *NLMu_DMD = (TH1D*)h2->Get("NLooseMu_Eta");
  TH1D *NTEl_DMD = (TH1D*)h2->Get("NTightEl_Eta");
  TH1D *NTMu_DMD = (TH1D*)h2->Get("NTightMu_Eta");
  TH1D *NLEl_DEC = (TH1D*)h3->Get("NLooseEl_Eta");
  TH1D *NLMu_DEC = (TH1D*)h3->Get("NLooseMu_Eta");
  TH1D *NTEl_DEC = (TH1D*)h3->Get("NTightEl_Eta");
  TH1D *NTMu_DEC = (TH1D*)h3->Get("NTightMu_Eta");
  TH1D *NLEl_DED = (TH1D*)h4->Get("NLooseEl_Eta");
  TH1D *NLMu_DED = (TH1D*)h4->Get("NLooseMu_Eta");
  TH1D *NTEl_DED = (TH1D*)h4->Get("NTightEl_Eta");
  TH1D *NTMu_DED = (TH1D*)h4->Get("NTightMu_Eta");

  TH1D *NLEl_TT = (TH1D*)h5->Get("NLooseEl_Eta");
  TH1D *NLMu_TT = (TH1D*)h5->Get("NLooseMu_Eta");
  TH1D *NTEl_TT = (TH1D*)h5->Get("NTightEl_Eta");
  TH1D *NTMu_TT = (TH1D*)h5->Get("NTightMu_Eta");
  
  double scale_WJ100 = 201.4*1345.0*1.21/10205377.;
  double scale_WJ200 = 201.4*359.7*1.21/4949568.;
  double scale_WJ400 = 201.4*48.91*1.21/1943664.;
  double scale_WJ600 = 201.4*12.05*1.21/3767766.;
  double scale_WJ800 = 201.4*5.501*1.21/1568277.;
  double scale_WJ1200 = 201.4*1.329*1.21/246239.;
  double scale_WJ2500 = 201.4*0.03216*1.21/251982.;

  double scale_QCD100 = 201.4*27990000.0/82095800.;
  double scale_QCD200 = 201.4*1712000.0/18784379.;
  double scale_QCD300 = 201.4*347700.0/16909004.;
  double scale_QCD500 = 201.4*32100.0/19665695.;
  double scale_QCD700 = 201.4*6831.0/15547962.;
  double scale_QCD1000 = 201.4*1207.0/5049267.;
  double scale_QCD1500 = 201.4*119.9/3939077.;

  double scale_DY = 201.4*6025.2/81236727.;
  double scale_TT = 201.4*831.76/97994442;

  double ElCoeff = 46.8/201.4;

  NTEl_WJ100->Scale(ElCoeff*scale_WJ100);    NTMu_WJ100->Scale(scale_WJ100);  
  NTEl_WJ200->Scale(ElCoeff*scale_WJ200);    NTMu_WJ200->Scale(scale_WJ200);  
  NTEl_WJ400->Scale(ElCoeff*scale_WJ400);    NTMu_WJ400->Scale(scale_WJ400);  
  NTEl_WJ600->Scale(ElCoeff*scale_WJ600);    NTMu_WJ600->Scale(scale_WJ600);  
  NTEl_WJ800->Scale(ElCoeff*scale_WJ800);    NTMu_WJ800->Scale(scale_WJ800);  
  NTEl_WJ1200->Scale(ElCoeff*scale_WJ1200);  NTMu_WJ1200->Scale(scale_WJ1200);
  NTEl_WJ2500->Scale(ElCoeff*scale_WJ2500);  NTMu_WJ2500->Scale(scale_WJ2500);

  NLEl_WJ100->Scale(ElCoeff*scale_WJ100);    NLMu_WJ100->Scale(scale_WJ100);  
  NLEl_WJ200->Scale(ElCoeff*scale_WJ200);    NLMu_WJ200->Scale(scale_WJ200);  
  NLEl_WJ400->Scale(ElCoeff*scale_WJ400);    NLMu_WJ400->Scale(scale_WJ400);  
  NLEl_WJ600->Scale(ElCoeff*scale_WJ600);    NLMu_WJ600->Scale(scale_WJ600);  
  NLEl_WJ800->Scale(ElCoeff*scale_WJ800);    NLMu_WJ800->Scale(scale_WJ800);  
  NLEl_WJ1200->Scale(ElCoeff*scale_WJ1200);  NLMu_WJ1200->Scale(scale_WJ1200);
  NLEl_WJ2500->Scale(ElCoeff*scale_WJ2500);  NLMu_WJ2500->Scale(scale_WJ2500);
  
  NTEl_QCD100->Scale(ElCoeff*scale_QCD100);    NTMu_QCD100->Scale(scale_QCD100);  
  NTEl_QCD200->Scale(ElCoeff*scale_QCD200);    NTMu_QCD200->Scale(scale_QCD200);  
  NTEl_QCD300->Scale(ElCoeff*scale_QCD300);    NTMu_QCD300->Scale(scale_QCD300);  
  NTEl_QCD500->Scale(ElCoeff*scale_QCD500);    NTMu_QCD500->Scale(scale_QCD500);  
  NTEl_QCD700->Scale(ElCoeff*scale_QCD700);    NTMu_QCD700->Scale(scale_QCD700);  
  NTEl_QCD1000->Scale(ElCoeff*scale_QCD1000);  NTMu_QCD1000->Scale(scale_QCD1000);
  NTEl_QCD1500->Scale(ElCoeff*scale_QCD1500);  NTMu_QCD1500->Scale(scale_QCD1500);

  NLEl_QCD100->Scale(ElCoeff*scale_QCD100);    NLMu_QCD100->Scale(scale_QCD100);  
  NLEl_QCD200->Scale(ElCoeff*scale_QCD200);    NLMu_QCD200->Scale(scale_QCD200);  
  NLEl_QCD300->Scale(ElCoeff*scale_QCD300);    NLMu_QCD300->Scale(scale_QCD300);  
  NLEl_QCD500->Scale(ElCoeff*scale_QCD500);    NLMu_QCD500->Scale(scale_QCD500);  
  NLEl_QCD700->Scale(ElCoeff*scale_QCD700);    NLMu_QCD700->Scale(scale_QCD700);  
  NLEl_QCD1000->Scale(ElCoeff*scale_QCD1000);  NLMu_QCD1000->Scale(scale_QCD1000);
  NLEl_QCD1500->Scale(ElCoeff*scale_QCD1500);  NLMu_QCD1500->Scale(scale_QCD1500);
  
  NTEl_DY->Scale(ElCoeff*scale_DY);    NTEl_TT->Scale(ElCoeff*scale_TT);
  NLEl_DY->Scale(ElCoeff*scale_DY);    NLEl_TT->Scale(ElCoeff*scale_TT);
  NTMu_DY->Scale(scale_DY);    NTMu_TT->Scale(scale_TT);
  NLMu_DY->Scale(scale_DY);    NLMu_TT->Scale(scale_TT);

  NTEl_WJ100->Add(NTEl_WJ200);   NTMu_WJ100->Add(NTMu_WJ200); 
  NTEl_WJ100->Add(NTEl_WJ400);   NTMu_WJ100->Add(NTMu_WJ400); 
  NTEl_WJ100->Add(NTEl_WJ600);   NTMu_WJ100->Add(NTMu_WJ600); 
  NTEl_WJ100->Add(NTEl_WJ800);   NTMu_WJ100->Add(NTMu_WJ800); 
  NTEl_WJ100->Add(NTEl_WJ1200);  NTMu_WJ100->Add(NTMu_WJ1200);
  NTEl_WJ100->Add(NTEl_WJ2500);  NTMu_WJ100->Add(NTMu_WJ2500);

  NLEl_WJ100->Add(NLEl_WJ200);   NLMu_WJ100->Add(NLMu_WJ200); 
  NLEl_WJ100->Add(NLEl_WJ400);   NLMu_WJ100->Add(NLMu_WJ400); 
  NLEl_WJ100->Add(NLEl_WJ600);   NLMu_WJ100->Add(NLMu_WJ600); 
  NLEl_WJ100->Add(NLEl_WJ800);   NLMu_WJ100->Add(NLMu_WJ800); 
  NLEl_WJ100->Add(NLEl_WJ1200);  NLMu_WJ100->Add(NLMu_WJ1200);
  NLEl_WJ100->Add(NLEl_WJ2500);  NLMu_WJ100->Add(NLMu_WJ2500);

  NTEl_QCD100->Add(NTEl_QCD200);   NTMu_QCD100->Add(NTMu_QCD200); 
  NTEl_QCD100->Add(NTEl_QCD300);   NTMu_QCD100->Add(NTMu_QCD300); 
  NTEl_QCD100->Add(NTEl_QCD500);   NTMu_QCD100->Add(NTMu_QCD500); 
  NTEl_QCD100->Add(NTEl_QCD700);   NTMu_QCD100->Add(NTMu_QCD700); 
  NTEl_QCD100->Add(NTEl_QCD1000);  NTMu_QCD100->Add(NTMu_QCD1000);
  NTEl_QCD100->Add(NTEl_QCD1500);  NTMu_QCD100->Add(NTMu_QCD1500);

  NLEl_QCD100->Add(NLEl_QCD200);   NLMu_QCD100->Add(NLMu_QCD200); 
  NLEl_QCD100->Add(NLEl_QCD300);   NLMu_QCD100->Add(NLMu_QCD300); 
  NLEl_QCD100->Add(NLEl_QCD500);   NLMu_QCD100->Add(NLMu_QCD500); 
  NLEl_QCD100->Add(NLEl_QCD700);   NLMu_QCD100->Add(NLMu_QCD700); 
  NLEl_QCD100->Add(NLEl_QCD1000);  NLMu_QCD100->Add(NLMu_QCD1000);
  NLEl_QCD100->Add(NLEl_QCD1500);  NLMu_QCD100->Add(NLMu_QCD1500);

  NTEl_DEC->Add(NTEl_DED);  NTMu_DEC->Add(NTMu_DED);
  NTEl_DEC->Add(NTEl_DMC);  NTMu_DEC->Add(NTMu_DMC);
  NTEl_DEC->Add(NTEl_DMD);  NTMu_DEC->Add(NTMu_DMD);

  NLEl_DEC->Add(NLEl_DED);  NLMu_DEC->Add(NLMu_DED);
  NLEl_DEC->Add(NLEl_DMC);  NLMu_DEC->Add(NLMu_DMC);
  NLEl_DEC->Add(NLEl_DMD);  NLMu_DEC->Add(NLMu_DMD);

  TH1D *NREl_WJ100 = (TH1D*)NTEl_WJ100->Clone("NREl_WJ100");
  TH1D *NRMu_WJ100 = (TH1D*)NTMu_WJ100->Clone("NRMu_WJ100");
  TH1D *NREl_QCD100 = (TH1D*)NTEl_QCD100->Clone("NREl_QCD100");
  TH1D *NRMu_QCD100 = (TH1D*)NTMu_QCD100->Clone("NRMu_QCD100");
  TH1D *NREl_DY = (TH1D*)NTEl_DY->Clone("NREl_DY");
  TH1D *NRMu_DY = (TH1D*)NTMu_DY->Clone("NRMu_DY");
  TH1D *NREl_TT = (TH1D*)NTEl_TT->Clone("NREl_TT");
  TH1D *NRMu_TT = (TH1D*)NTMu_TT->Clone("NRMu_TT");
  TH1D *NREl_DEC = (TH1D*)NTEl_DEC->Clone("NREl_DEC");
  TH1D *NRMu_DEC = (TH1D*)NTMu_DEC->Clone("NRMu_DEC");

  NREl_WJ100->Divide(NLEl_WJ100);    NRMu_WJ100->Divide(NLMu_WJ100);  
  NREl_QCD100->Divide(NLEl_QCD100);  NRMu_QCD100->Divide(NLMu_QCD100);
  NREl_DY->Divide(NLEl_DY);       NRMu_DY->Divide(NLMu_DY);	   
  NREl_TT->Divide(NLEl_TT);       NRMu_TT->Divide(NLMu_TT);	   
  NREl_DEC->Divide(NLEl_DEC);    NRMu_DEC->Divide(NLMu_DEC);      

  TCanvas *c1 = new TCanvas("c1","c1",800,600);
  gStyle->SetPalette(1);

  NREl_WJ100->Draw("colz");  
  c1->SaveAs("FakeRatePlots/FakeRate_WJets_El_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_WJets_El_Eta.png");

  NRMu_WJ100->Draw("colz");
  c1->SaveAs("FakeRatePlots/FakeRate_WJets_Mu_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_WJets_Mu_Eta.png");

  NREl_QCD100->Draw("colz");  
  c1->SaveAs("FakeRatePlots/FakeRate_QCD_El_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_QCD_El_Eta.png");

  NRMu_QCD100->Draw("colz");
  c1->SaveAs("FakeRatePlots/FakeRate_QCD_Mu_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_QCD_Mu_Eta.png");

  NREl_DY->Draw("colz");  
  c1->SaveAs("FakeRatePlots/FakeRate_DY_El_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_DY_El_Eta.png");

  NRMu_DY->Draw("colz");
  c1->SaveAs("FakeRatePlots/FakeRate_DY_Mu_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_DY_Mu_Eta.png");

  NREl_TT->Draw("colz");  
  c1->SaveAs("FakeRatePlots/FakeRate_TT_El_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_TT_El_Eta.png");

  NRMu_TT->Draw("colz");
  c1->SaveAs("FakeRatePlots/FakeRate_TT_Mu_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_TT_Mu_Eta.png");

  NREl_DEC->Draw("colz");  
  c1->SaveAs("FakeRatePlots/FakeRate_Data_El_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_Data_El_Eta.png");

  NRMu_DEC->Draw("colz");
  c1->SaveAs("FakeRatePlots/FakeRate_Data_Mu_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_Data_Mu_Eta.png");

  TH1D *newtightEl = (TH1D*)NTEl_DEC->Clone("newtightEl");
  TH1D *newlooseEl = (TH1D*)NLEl_DEC->Clone("newlooseEl");
  newtightEl->Add(NTEl_WJ100,-1);
  newtightEl->Add(NTEl_DY,-1);
  newtightEl->Add(NTEl_TT,-1);
  //  newlooseEl->Add(NLEl_WJ100,-1);
  //  newlooseEl->Add(NLEl_DY,-1);
  //  newlooseEl->Add(NLEl_TT,-1);
  TH1D *newratioEl = (TH1D*)newtightEl->Clone("newratioEl");
  newratioEl->Divide(newlooseEl);

  TH1D *newtightMu = (TH1D*)NTMu_DEC->Clone("newtightMu");
  TH1D *newlooseMu = (TH1D*)NLMu_DEC->Clone("newlooseMu");
  newtightMu->Add(NTMu_WJ100,-1);
  newtightMu->Add(NTMu_DY,-1);
  newtightMu->Add(NTMu_TT,-1);
  //  newlooseMu->Add(NLMu_WJ100,-1);
  //  newlooseMu->Add(NLMu_DY,-1);
  //  newlooseMu->Add(NLMu_TT,-1);
  TH1D *newratioMu = (TH1D*)newtightMu->Clone("newratioMu");
  newratioMu->Divide(newlooseMu);

  TH1D *ratio_QCDdata_el = (TH1D*)newratioEl->Clone("ratio_QCDdata_el");
  ratio_QCDdata_el->Divide(NREl_QCD100);

  TH1D *ratio_QCDdata_mu = (TH1D*)newratioMu->Clone("ratio_QCDdata_mu");
  ratio_QCDdata_mu->Divide(NRMu_QCD100);

  newratioEl->Draw("colz");  
  c1->SaveAs("FakeRatePlots/FakeRate_Data_subtr_El_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_Data_subtr_El_Eta.png");

  newratioMu->Draw("colz");
  c1->SaveAs("FakeRatePlots/FakeRate_Data_subtr_Mu_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_Data_subtr_Mu_Eta.png");
  
  ratio_QCDdata_el->Draw();
  c1->SaveAs("FakeRatePlots/FakeRate_ratio_QCDData_subtr_El_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_ratio_QCDData_subtr_El_Eta.png");

  ratio_QCDdata_mu->Draw();
  c1->SaveAs("FakeRatePlots/FakeRate_ratio_QCDData_subtr_Mu_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_ratio_QCDData_subtr_Mu_Eta.png");

  NREl_TT->GetYaxis()->SetRangeUser(0,1);
  NREl_TT->SetLineColor(kBlue);
  NREl_WJ100->SetLineColor(kGreen);
  NREl_DY->SetLineColor(kViolet);
  NREl_QCD100->SetLineColor(kRed);
  NREl_DEC->SetLineColor(kBlack);
  newratioEl->SetLineColor(kBlack);
  newratioEl->SetLineStyle(5);

  leg_El = new TLegend(0.9-0.38,0.1+0.5,0.9,0.1+0.2+0.5);
  leg_El->AddEntry(NREl_TT,"top","lep");
  leg_El->AddEntry(NREl_WJ100,"W","lep");
  leg_El->AddEntry(NREl_DY,"DY","lep");
  leg_El->AddEntry(NREl_QCD100,"QCD","lep");
  leg_El->AddEntry(NREl_DEC,"Data","lep");
  leg_El->AddEntry(newratioEl,"Data (subtracted)","lep");

  NREl_TT->Draw();
  NREl_WJ100->Draw("same");
  NREl_DY->Draw("same");
  NREl_QCD100->Draw("same");
  NREl_DEC->Draw("same");
  newratioEl->Draw("same");
  leg_El->Draw("same");
  c1->SaveAs("FakeRatePlots/FakeRate_All_El_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_All_El_Eta.png");

  NRMu_TT->GetYaxis()->SetRangeUser(0,1);
  NRMu_TT->SetLineColor(kBlue);
  NRMu_WJ100->SetLineColor(kGreen);
  NRMu_DY->SetLineColor(kViolet);
  NRMu_QCD100->SetLineColor(kRed);
  NRMu_DEC->SetLineColor(kBlack);
  newratioMu->SetLineColor(kBlack);
  newratioMu->SetLineStyle(5);

  leg_Mu = new TLegend(0.9-0.38,0.1,0.9,0.1+0.2);
  leg_Mu->AddEntry(NREl_TT,"top","lep");
  leg_Mu->AddEntry(NREl_WJ100,"W","lep");
  leg_Mu->AddEntry(NREl_DY,"DY","lep");
  leg_Mu->AddEntry(NREl_QCD100,"QCD","lep");
  leg_Mu->AddEntry(NREl_DEC,"Data","lep");
  leg_Mu->AddEntry(newratioEl,"Data (subtracted)","lep");

  NRMu_TT->Draw();
  NRMu_WJ100->Draw("same");
  NRMu_DY->Draw("same");
  NRMu_QCD100->Draw("same");
  NRMu_DEC->Draw("same");
  newratioMu->Draw("same");
  leg_Mu->Draw("same");
  c1->SaveAs("FakeRatePlots/FakeRate_All_Mu_Eta.C");
  c1->SaveAs("FakeRatePlots/FakeRate_All_Mu_Eta.png");

  for(int i = 1; i < NREl_WJ100->GetNbinsX()+1; i++){
    for(int j = 1; j < NREl_WJ100->GetNbinsY()+1; j++){
      cout << "---------------------------------------------------------------" << endl;
      cout << "Pt = " << NREl_WJ100->GetXaxis()->GetBinLowEdge(i) << " - " 
	   << NREl_WJ100->GetXaxis()->GetBinLowEdge(i+1) << ", Eta = " 
	   << NREl_WJ100->GetYaxis()->GetBinLowEdge(j) << " - " 
	   << NREl_WJ100->GetYaxis()->GetBinLowEdge(j+1) << endl;    

      cout << "WJets El: FR = " << NREl_WJ100->GetBinContent(i,j) << " +/- " 
	   << NREl_WJ100->GetBinError(i,j) << ", NT = " << NTEl_WJ100->GetBinContent(i,j) 
	   << ", NL = " << NLEl_WJ100->GetBinContent(i,j) << endl;

      cout << "DY El: FR = " << NREl_DY->GetBinContent(i,j) << " +/- " << NREl_DY->GetBinError(i,j) 
	   << ", NT = " << NTEl_DY->GetBinContent(i,j) 
	   << ", NL = " << NLEl_DY->GetBinContent(i,j)<< endl;

      cout << "TT El: FR = " << NREl_TT->GetBinContent(i,j) << " +/- " << NREl_TT->GetBinError(i,j) 
	   << ", NT = " << NTEl_TT->GetBinContent(i,j) 
	   << ", NL = " << NLEl_TT->GetBinContent(i,j)<< endl;

      cout << "QCD El: FR = " 
	   << NREl_QCD100->GetBinContent(i,j) << " +/- " << NREl_QCD100->GetBinError(i,j)
	   << ", NT = " << NTEl_QCD100->GetBinContent(i,j) 
	   << ", NL = " << NLEl_QCD100->GetBinContent(i,j)<< endl;

      cout << "Data El: FR = " 
	   << NREl_DEC->GetBinContent(i,j) << " +/- " << NREl_DEC->GetBinError(i,j)
	   << ", NT = " << NTEl_DEC->GetBinContent(i,j) 
	   << ", NL = " << NLEl_DEC->GetBinContent(i,j)<< endl;

      cout << "Data El W/Z/T subtracted: FR = " << newratioEl->GetBinContent(i,j) << " +/- " << newratioEl->GetBinError(i,j)
	   << ", NT = " << newtightEl->GetBinContent(i,j) << ", NL = " << newlooseEl->GetBinContent(i,j) << endl;
      
    }
  }

  for(int i = 1; i < NRMu_WJ100->GetNbinsX()+1; i++){
    for(int j = 1; j < NRMu_WJ100->GetNbinsY()+1; j++){
      cout << "---------------------------------------------------------------" << endl;
      cout << "Pt = " << NRMu_WJ100->GetXaxis()->GetBinLowEdge(i) << " - " 
	   << NRMu_WJ100->GetXaxis()->GetBinLowEdge(i+1) << ", Eta = " 
	   << NRMu_WJ100->GetYaxis()->GetBinLowEdge(j) << " - " 
	   << NRMu_WJ100->GetYaxis()->GetBinLowEdge(j+1) << endl;
      cout << "WJets Mu: FR = " << NRMu_WJ100->GetBinContent(i,j) << " +/- " 
	   << NRMu_WJ100->GetBinError(i,j) << ", NT = " << NTMu_WJ100->GetBinContent(i,j) 
	   << ", NL = " << NLMu_WJ100->GetBinContent(i,j) << endl;

      cout << "DY Mu: FR = " << NRMu_DY->GetBinContent(i,j) << " +/- " << NRMu_DY->GetBinError(i,j) 
	   << ", NT = " << NTMu_DY->GetBinContent(i,j) 
	   << ", NL = " << NLMu_DY->GetBinContent(i,j)<< endl;

      cout << "TT Mu: FR = " << NRMu_TT->GetBinContent(i,j) << " +/- " << NRMu_TT->GetBinError(i,j) 
	   << ", NT = " << NTMu_TT->GetBinContent(i,j) 
	   << ", NL = " << NLMu_TT->GetBinContent(i,j)<< endl;

      cout << "QCD Mu: FR = " 
	   << NRMu_QCD100->GetBinContent(i,j) << " +/- " << NRMu_QCD100->GetBinError(i,j)
	   << ", NT = " << NTMu_QCD100->GetBinContent(i,j) 
	   << ", NL = " << NLMu_QCD100->GetBinContent(i,j)<< endl;

      cout << "Data Mu: FR = " 
	   << NRMu_DEC->GetBinContent(i,j) << " +/- " << NRMu_DEC->GetBinError(i,j)
	   << ", NT = " << NTMu_DEC->GetBinContent(i,j) 
	   << ", NL = " << NLMu_DEC->GetBinContent(i,j)<< endl;

      cout << "Data Mu W/Z/T subtracted: FR = " << newratioMu->GetBinContent(i,j) << " +/- " << newratioMu->GetBinError(i,j)
	   << ", NT = " << newtightMu->GetBinContent(i,j) << ", NL = " << newlooseMu->GetBinContent(i,j) << endl;
    }
  }

  cout << "DONE" << endl;

}
Beispiel #27
0
void compIsol(int varnum)
{
  TString varname, vartitle;
  if(varnum==1) {
    varname="hHEIsoPt";
    vartitle="H/E Isolation";
  }
  if(varnum==2) {
    varname="hHcalIsoPt";
    vartitle="HCAL Isolation";
  }
  if(varnum==3) {
    varname="hEcalIsoPt";
    vartitle="ECAL Isolation";
  }
  if(varnum==4) {
    varname="hTrkIsoPt";
    vartitle="Track Isolation";
  }
  if(varnum==5) {
    varname="hJetEt";
    vartitle="Jet E_{T} [GeV]";
  }
  if(varnum==6) {
    varname="hNJets";
    vartitle="Number of Jets";
  }
  
  
  TH1D* hBorn;
  TH1D* hADD;
  if(varnum<=4) {
    TH2D* hBorn2d = dynamic_cast<TH2D*>(GetPlot(1, varname));
    TH2D* hADD2d = dynamic_cast<TH2D*>(GetPlot(3, varname));
    hBorn = hBorn2d->ProjectionX(varname+"born");
    hADD = hADD2d->ProjectionX(varname+"add");
    cout << "asdf" << endl;
  } else {
    hBorn = dynamic_cast<TH1D*>(GetPlot(1, varname));
    hADD = dynamic_cast<TH1D*>(GetPlot(3, varname));
  }
  
  hBorn->Scale(1/hBorn->GetSumOfWeights());
  hADD->Scale(1/hADD->GetSumOfWeights());

  hBorn->SetLineColor(kBlue+2);
  hADD->SetLineColor(kCyan+4);
  hBorn->SetFillColor(0);
  hADD->SetFillColor(0);
  hBorn->SetLineStyle(1);
  hADD->SetLineStyle(2);
  
  //  hBorn->SetStats(0);
  //  hADD->SetStats(0);

  gPad->SetLogy(1);
  
  hBorn->GetXaxis()->SetTitle(vartitle);
  hBorn->GetYaxis()->SetTitle("Normalized Units");
  hBorn->SetTitle("Leading Photons in Pythia/Sherpa Samples");

  hBorn->Draw();
  hADD->Draw("sames");

  hBorn->SetMaximum(1);

  gPad->Update();
  TPaveStats *st1=(TPaveStats*)hBorn->GetListOfFunctions()->FindObject("stats");
  TPaveStats *st2=(TPaveStats*)hADD->GetListOfFunctions()->FindObject("stats");
  st1->SetName("Born");
  st2->SetName("ADD");
  st1->SetOptStat(101100);
  st2->SetOptStat(101100);
  st1->SetX1NDC(.25);
  st1->SetX2NDC(.55);
  st1->SetY1NDC(.56);
  st1->SetY2NDC(.80);
  st2->SetX1NDC(.56);
  st2->SetX2NDC(.86);
  st2->SetY1NDC(.56);
  st2->SetY2NDC(.80);

  TLegend* leg=new TLegend(.25,.78,.55,.85);
  leg->AddEntry(hBorn, "Pythia (Born)", "l");
  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  leg->SetTextSize(0.045);
  leg->Draw();

  TLegend* leg=new TLegend(.56,.78,.86,.85);
  leg->AddEntry(hADD, "Sherpa (ADD)", "l");
  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  leg->SetTextSize(0.045);
  leg->Draw();

  gPad->Update();
  

  return;
}
Beispiel #28
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;

}
void plotRatio(int cbin,
		 TString infname,
		 TString DataPF,
		 TString mix,
		 bool useWeight,
		 bool drawXLabel,
		 bool drawLeg)
{
  TString cut="et1>120&& et1<2000 && et2>50 && dphi>3.14159/3*2&&(et1-et2)/(et1+et2)<0.55 ";
  TString cut2="et1>120&& et1<2000 && et2>50 && dphi>3.14159/3*2&&(et1-et2)/(et1+et2)<0.55 ";
  TString cstring = "";
 
  if(cbin==0) {
    cstring = "0-10%";
    cut+=" && (bin>=0 && bin<4 || bin==-1)";
    cut2+=" &&(bin>=0 && bin<4 || bin==-1)";
  } else if (cbin==1) {
    cstring = "10-20%";
    cut+=" && (bin>=4 && bin<8  || bin==-1)";
    cut2+=" && (bin>=4 && bin<8 || bin==-1)";
  } else if (cbin==2) {
     cstring = "20-30%";
     cut+=" && (bin>=8 && bin<12  || bin==-1)";
     cut2+=" && (bin>=8 && bin<12 || bin==-1)";
  } else if (cbin==3) {
     cstring = "30-50%";
     cut+=" && (bin>=12  && bin<20  || bin==-1)";
     cut2+=" && (bin>=12 && bin<20 || bin==-1)";
  } else {
    cstring = "50-100%";
    cut+=" && (bin>=20 &&  bin<40 || bin==-1)";
    cut2+=" && (bin>=20 && bin<40 || bin==-1)";
  }

  // open the data file
  TFile *inf = new TFile(infname.Data());
  TTree *nt =(TTree*)inf->FindObjectAny("nt");

  // open the DataPF (MC) file
  TFile *infDataPF = new TFile(DataPF.Data());
  TTree *ntDataPF = (TTree*) infDataPF->FindObjectAny("nt");

  // open the datamix file
  TFile *infMix = new TFile(mix.Data());
  TTree *ntMix =(TTree*)infMix->FindObjectAny("nt");

  // Variable Aj
  char *aj = "(et1-et2)/(et1+et2)";

  const int nBin = 13;
  double bins[nBin+1]={0,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,1};
  // projection histogram
  TH1D *h = new TH1D("h","",nBin,bins);
  TH1D *hTmp = new TH1D("hTmp","",nBin,bins);
  TH1D *hEmbedded = new TH1D("hEmbedded","",nBin,bins);
  TH1D *hDataMix = new TH1D("hDataMix","",nBin,bins);
  nt->Draw(Form("%s>>h",aj),Form("(%s)*weight",cut2.Data())); 
   
  if (useWeight) {
    // use the weight value caluculated by Matt's analysis macro
    ntDataPF->Draw(Form("%s>>hEmbedded",aj),Form("(%s)",cut.Data())); 
    ntMix->Draw(Form("%s>>hDataMix",aj),Form("(%s)*weight",cut.Data())); 
  } else {
    // ignore centrality reweighting
    ntDataPF->Draw(Form("%s>>hEmbedded",aj),Form("(%s)",cut.Data()));
    ntMix->Draw(Form("%s>>hDataMix",aj),Form("(%s)",cut.Data()));  
  }

  // calculate the statistical error and normalize
  h->Sumw2();
  h->Scale(1./h->Integral(0,20));
  h->SetMarkerStyle(20);

  hEmbedded->Sumw2();
  hEmbedded->Scale(1./hEmbedded->Integral(0,20));
  hEmbedded->SetLineColor(kBlue);
  hEmbedded->SetFillColor(kAzure-8);
  hEmbedded->SetFillStyle(3005);

  hEmbedded->SetStats(0);

  if(drawXLabel) {
     hEmbedded->SetXTitle("A_{J} = (p_{T}^{j1}-p_{T}^{j2})/(p_{T}^{j1}+p_{T}^{j2})");
     h->SetXTitle("A_{J} = (p_{T}^{j1}-p_{T}^{j2})/(p_{T}^{j1}+p_{T}^{j2})");
  }
  h->GetXaxis()->SetLabelSize(20);
  h->GetXaxis()->SetLabelFont(43);
  h->GetXaxis()->SetTitleSize(22);
  h->GetXaxis()->SetTitleFont(43);
  h->GetXaxis()->SetTitleOffset(1.5);
  h->GetXaxis()->CenterTitle();
  h->GetXaxis()->SetNdivisions(905,true);

  h->GetYaxis()->SetLabelSize(20);
  h->GetYaxis()->SetLabelFont(43);
  h->GetYaxis()->SetTitleSize(20);
  h->GetYaxis()->SetTitleFont(43);
  h->GetYaxis()->SetTitleOffset(2.5);
  h->GetYaxis()->CenterTitle();
  

  h->SetAxisRange(0,0.3,"Y");
  h->SetMarkerColor(2);
  
  h->SetYTitle("Ratio");
  hEmbedded->SetYTitle("Ratio");



  hDataMix->Sumw2();
  hDataMix->Scale(1./hDataMix->Integral(0,20));
  hDataMix->SetLineColor(kRed);
  hDataMix->SetFillColor(kRed-9);
  hDataMix->SetFillStyle(3004);
  
  h->SetAxisRange(0,5,"Y");
  hEmbedded->SetAxisRange(0,10,"Y");
  h->Divide(hDataMix);
  hEmbedded->Divide(hDataMix);

  h->Draw("");

  TH1D *hErr = getErrorBand(h);


  double systematicErrorResolution[nBin] =
                  {0.06,0.05,0.04,0.04,0.04,0.06,0.1,0.18,0.3,0.5,0.5};

  double systematicErrorScale[nBin] =
                  {0.06,0.05,0.04,0.03,0.02,0.02,0.03,0.04,0.05,0.08,0.1};

  double systematicErrorEfficiency[nBin] =
                  {0.00,0.00,0.00,0.00,0.00,0.00,0.07,0.07,0.07,0.07,0.07};

  double systematicErrorBackground[nBin+1] =
                  {0.07,0.04,0.04,0.04,0.05,0.06,0.07,0.08,0.09,0.10,0.12,0.15};

  double systematicError[nBin];

  for (int b=0;b<nBin;b++)
  {
     double sum=0;
     //sum+= systematicErrorResolution[b]*systematicErrorResolution[b];
     //sum+= systematicErrorScale[b]*systematicErrorScale[b];
     //sum+= systematicErrorEfficiency[b]*systematicErrorEfficiency[b];
     sum+= systematicErrorBackground[b]*systematicErrorBackground[b];
     systematicError[b]=sqrt(sum);
     hTmp->SetBinContent(b,1);
  }


  TGraph *gErrorBand;

  if (cbin!=0) {
     gErrorBand = GetErrorBand(hTmp,systematicError,systematicError,0.025,12);
  } else {
     gErrorBand = GetErrorBand(hTmp,systematicError,systematicError,0.025,12);
  }
  gErrorBand->Draw("f");
  hEmbedded->SetMarkerStyle(4);
  hEmbedded->SetMarkerColor(4);
  hEmbedded->SetLineColor(4);
  hEmbedded->SetLineStyle(2);
  
  //hEmbedded->Draw("same");
  //h->Fit("pol1","","",0,1);
  h->Draw("same");
  TLine *l = new TLine(0,1,1,1);
  l->SetLineStyle(2);
  l->Draw();

  if(drawLeg){
    TLegend *t3=new TLegend(0.44,0.7,0.86,0.88); 
    t3->AddEntry(h,"PYTHIA + Data / PYTHIA","pl");
    //t3->AddEntry(hEmbedded,"Data PF / PYQUEN + Data","l");  
    //t3->AddEntry(hDataMix,"unquenched PYQUEN + Data","lf");
    t3->SetFillColor(0);
    t3->SetBorderSize(0);
    t3->SetFillStyle(0);
    t3->SetTextFont(63);
    t3->SetTextSize(15);
    t3->Draw();
  }

}
Beispiel #30
-1
void MCtoSTATerrors() {
  TLatex *tplus = labelLatex(0.1364943,0.8114407,"MC sample");

  TFile *file0 = TFile::Open("results/StandardCutflow/allmc.root");

  TCanvas *c1 = new TCanvas();
  //TCanvas *c2 = new TCanvas();
  TH1D * LPplus = (TH1D*)file0->Get("RECO_PolPlots_50toinf/RECO_ICVarPFPlus");
  TH1D * LPminus = (TH1D*)file0->Get("RECO_PolPlots_50toinf/RECO_ICVarPFMinus");

  LPplus->Rebin(20);
  LPminus->Rebin(20);

  LPplus->Scale(0.3);
  LPminus->Scale(0.3);

  TH1D * newLPplus = (TH1D*)LPplus->Clone();
  TH1D * newLPminus = (TH1D*)LPminus->Clone();

  for(unsigned int i=1; i < LPplus->GetXaxis()->GetNbins(); i++) {
    newLPplus->SetBinError(i, TMath::Sqrt(LPplus->GetBinContent(i)));
    newLPminus->SetBinError(i, TMath::Sqrt(LPminus->GetBinContent(i)));
  }

  c1->cd();
  newLPplus->GetYaxis()->SetTitle("Events / 300 nb^{-1}");
  //newLPplus->GetXaxis()->SetTitle("LP(#mu^{+})");
  newLPplus->GetXaxis()->SetTitle("LP(#mu)");
  newLPplus->GetXaxis()->SetRangeUser(-1.0,2.0);
  newLPplus->SetLineWidth(3);
  newLPplus->SetLineStyle(2);
  newLPplus->SetLineColor(kRed);
  newLPplus->DrawCopy();
  tplus->DrawClone("same");

//   c2->cd();
//   newLPminus->GetYaxis()->SetTitle("Events / 100 nb^{-1}");
//   newLPminus->GetXaxis()->SetTitle("LP(#mu^{-})");
  newLPminus->SetLineWidth(3);
  newLPminus->SetLineStyle(2);
  newLPminus->SetLineColor(kBlack);
  newLPminus->DrawCopy("same");
//   tplus->DrawClone("same");

  leg = new TLegend(0.762931,0.720339,0.8649425,0.8622881,NULL,"brNDC");
  leg->AddEntry(newLPplus,"#mu^{+}","l");
  leg->AddEntry(newLPminus,"#mu^{-}","l");

  leg->SetFillColor(kWhite);
  leg->SetBorderSize(0);
  leg->SetTextFont(62);
  leg->DrawClone();

  file0->Close();

  return;
}