Esempio n. 1
2
void simplePlotter(){

  const unsigned int n = 6;

  TFile* ftt[n];

  // diboson
  char* names[n] = {"BB-4p-0-500_100TEV_40PileUp",
		    "BB-4p-500-1500_100TEV_40PileUp",
		    "BB-4p-1500-3000_100TEV_40PileUp",
		    "BB-4p-3000-5500_100TEV_40PileUp",
		    "BB-4p-5500-9000_100TEV_40PileUp",
		    "BB-4p-9000-100000_100TEV_40PileUp"};


  char* labels[n] = {"S*_{T} < 1 TeV","S*_{T} 1-2 TeV","S*_{T} 2-3.5 TeV","S*_{T} 3.5-5.5 TeV","S*_{T} 5.5-8.5 TeV","S*_{T} > 8.5 TeV"};

  int   colors[n] = { 2 , 3 , 4 , 5 , 6 , 7 };

  TH1F* hst[n];

  THStack* htstack = new THStack();

  TLegend *leg = new TLegend(0.5,0.5,0.8,0.8);

  for( int i = 0 ; i < n ; i++ ){

    ftt[i] = TFile::Open(Form("output/%s.root",names[i]));
    hst[i] = (TH1F*) ftt[i]->Get("st");
    hst[i]->SetFillColor(colors[i]);

    cout << "Integral " << i << " " << hst[i]->Integral() << endl;

    hst[i]->GetXaxis()->SetTitle("S_{T} [GeV]");
    hst[i]->GetYaxis()->SetTitle("events");

    leg->AddEntry( hst[i] , labels[i] , "lf" );

    htstack->Add(hst[i]);

  }

  TCanvas *c2 = new TCanvas("c2","c2",1200,600);
  c2->cd();
  gStyle->SetOptStat(0);

  gPad->SetLogy();
  htstack->Draw();
  htstack->GetXaxis()->SetTitle("S_{T} [GeV]");
  htstack->GetYaxis()->SetTitle("events");

  TLatex *t = new TLatex();
  t->SetNDC();
  t->DrawLatex(0.5,0.85,"t#bar{t} events, 100 TeV, L = 1 pb^{-1}");

  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  leg->Draw();

}
Esempio n. 2
0
void Matching_Comp() {

  const int n_Signal = 1;
  const int n_Hist = 33;
  const int n_Category=5;

  const TString File_Name[n_Signal] = {"Tstar_M-1300"};

  int Color[n_Category] = { 628, 412,415,858, 868};//858,
  //EColor Color[n_Hist] = { kRed, kGreen, kBlue, 434,kCyan};

  const TString Hist_Name[n_Hist] = {"Discriminator_sum","Number of subjets gluon had","Number of subjets gluon lep","DeltaR_GluonGluon","DeltaR_TopTop","DeltaR_TopHad_BLep","Pt_Ratio_gluonhad_subjets","DeltaR_gluonhad_subjets","DeltaR_gluonlep_subjets","CSV_gluonLep","CSV_bLep","DeltaR_GluonTop_lep","DeltaR_GluonTop_had","DeltaR_GluonHad_TopLep","DeltaR_GluonLep_TopHad","M_TstarhadTstarlep_Diff_rel","Pt_Ratio_blep_toplep","Pt_Diff_gluonlep_toplep","Pt_Diff_gluonlep_gluonhad","Pt_Diff_gluon_top_lep","Pt_Diff_gluon_top_had","M_Tstarlep_rec","M_Tstarhad_rec","M_toplep","M_tophad","M_Tstar_comb","M_Tstar_ratio","Pt_Tstar_ratio","M_gluon_ratio","M_gluonhad","M_gluonlep","Pt_gluonhad","Pt_gluonlep"};

  const TString Hist_Label[n_Hist] = {"#Chi^{2}","Number of subjets gluon had","Number of subjets gluon lep","#Delta R Gluon Gluon","#Delta R Top Top","#Delta R Top_{Had} B_{Lep}","Pt Ratio gluonhad subjets","#Delta R gluon had subjets","#Delta R gluon had subjets","CSV_gluonLep","CSV bLep","#Delta R gluon top lep","#Delta R gluon top had","#Delta R gluon_{had} top_{lep}","#Delta R gluon_{lep} top_{had}","M_TstarhadTstarlep_Diff_rel","Pt Ratio b_{lep} top_{lep}","Pt Diff gluonlep toplep","Pt Diff gluonlep gluonhad","Pt Diff gluon top lep","Pt Diff gluon top had","T*  Mass, lep","T*  Mass, had","M top lep","M top had","M T* comb","M_Tstar_ratio","Pt_Tstar_ratio","M_gluon_ratio","M_gluonhad","M_gluonlep","Pt gluonhad","Pt gluonlep"};

  const TString Category_Name[n_Category] = {"chi2_gluon_nomatch__HypHists","chi2_gluon_switch__HypHists","chi2_gluonlep_semimatch__HypHists", "chi2_gluonhad_semimatch__HypHists","chi2_gluon_match__HypHists"};//"chi2_gluonhad_semimatch__HypHists",
  const TString Legend_Name[n_Category] = {"No Match","Switched","Semimatch, wrong gluon","Semimatch, gluon", "Match"}; //"Semimatch, gluon",

  TLegend* leg1 = new TLegend(0.67,0.65,0.87,0.87);
  leg1->SetBorderSize(0);

  for(int i = 0; i<n_Signal; i++){
    TFile *signal = new TFile("/nfs/dust/cms/user/multh/RunII_80X_v3/Selection/Nominal/03Feb2017_Relaunch_17Jan2018/Muons/Kinematic_Study/uhh2.AnalysisModuleRunner.MC."+File_Name[i]+".root");

    TH1F *h_signal[n_Hist][n_Category];

    for(int j= 0; j<n_Hist; j++){
      THStack *hs = new THStack("hs","");
      
      for(int k = 0; k<n_Category; k++){
	h_signal[j][k] = (TH1F*)signal->Get(Category_Name[k]+"/"+Hist_Name[j]);
	h_signal[j][k] ->SetFillColor(Color[k]);
	h_signal[j][k] -> SetLineColor(Color[k]);
	h_signal[j][k] ->SetLineWidth(2);
	if(j==0)leg1->AddEntry(h_signal[j][k],Legend_Name[k],"f");

      hs->Add(h_signal[j][k]);

    }    

    TCanvas *b1 = new TCanvas("b1","b1",800,600);
    gStyle->SetOptStat(0);
    hs->Draw("hist");
    hs->GetXaxis()->SetTitle(Hist_Label[j]);
    hs->GetXaxis()->SetTitleSize(0.05);
    leg1->Draw();
    b1->Modified();

    b1->SaveAs("/nfs/dust/cms/user/multh/CMSSW_8_0_26_patch2/src/UHH2/TstarSemiLeptonic/Plots/"+Hist_Name[j]+"_match.pdf");
    }
    
  }
}
Esempio n. 3
0
void DrawEmpirical(const char* filename="Empirical.root", 
		   Bool_t fmd=true)
{
  gStyle->SetOptTitle(0);

  TFile* file = TFile::Open(filename, "READ");
  if (!file) return;

  Double_t yr = 0.3;
  TCanvas* c  = new TCanvas("c","c", 1000,1000);
  TPad*    p1 = new TPad("p1","p1",0,0,1,yr);
  TPad*    p2 = new TPad("p2","p2",0,yr,1,1);
  c->cd(); p1->Draw();
  c->cd(); p2->Draw();
  
  gDirectory->cd("Forward");
  THStack* r = DrawOne(p1, yr, false, gDirectory, "ratios");  
  THStack* e = DrawOne(p2, yr, true, gDirectory, "empirical");

  r->SetMinimum(0.945);
  r->SetMaximum(1.055);
  r->GetXaxis()->SetTitle("#it{#eta}");
  r->GetYaxis()->SetTitle("Ratio to mean");
  e->SetMinimum(0.005);
  e->GetYaxis()->SetTitle("#it{E_{c}}(#it{#eta})");
  TIter nextE(e->GetHists());
  TIter nextR(r->GetHists());
  TH1*  hist = 0;
  Color_t cols[]  = { kRed+2, kGreen+2, kBlue+2, kMagenta+2, 0 };
  Color_t *ptr    = cols;
  Style_t stys[]  = { 20, 21, 22, 23 };
  Style_t* sty    = stys;
  while (*ptr) { 
    hist = static_cast<TH1*>(nextE()); 
    hist->SetMarkerColor(*ptr);
    hist->SetMarkerSize(2);
    hist->SetMarkerStyle(*sty);
    hist = static_cast<TH1*>(nextR()); 
    hist->SetMarkerColor(*ptr);
    hist->SetMarkerSize(2);
    hist->SetMarkerStyle(*sty);
    ptr++;
    sty++;
  }


  TLegend* l = p2->BuildLegend(0.35, .2, .65, .8);
  l->SetFillColor(0);
  l->SetFillStyle(0);
  l->SetBorderSize(0);

  c->Modified();
  c->Update();
  c->cd();
  c->Print("empirical.png");
  
}
Esempio n. 4
0
  // Do the loop here, so that we can use options like "errors"
  void Draw( const TString & xTitle = "", const TString & yTitle = "", const bool errors = false ) {

    // Create a new THStack so that it handle tha maximum
    // THStack stack(name_, title_);
    THStack * stack = new THStack(name_, title_);

    int colorIndex = 0;
    if( !(histoList_.empty()) ) {
      std::vector<TH1*>::iterator histoIter = histoList_.begin();
      for( ; histoIter != histoList_.end(); ++histoIter, ++colorIndex ) {
        TH1 * histo = *histoIter;
        if(errors) histo->Sumw2();
        // histo->SetNormFactor(1);
        if( colorIndex < 4 ) histo->SetLineColor(colors_[colorIndex]);
        else histo->SetLineColor(colorIndex);
        // Draw and get the maximum value
        TString normalizedHistoName(histo->GetName());
        TH1 * normalizedHisto = (TH1*)histo->Clone(normalizedHistoName+"clone");
        normalizedHisto->Scale(1/normalizedHisto->Integral());
        stack->Add(normalizedHisto);
      }
      // Take the maximum of all the drawed histograms
      // First we need to draw the histogram, or getAxis() will return 0... (see root code...)
      canvas_->Draw();
      canvas_->cd();
      stack->Draw("nostack");
      stack->GetYaxis()->SetTitleOffset(1.2);
      stack->GetYaxis()->SetTitle(yTitle);
      stack->GetXaxis()->SetTitle(xTitle);
      stack->GetXaxis()->SetTitleColor(kBlack);
      stack->Draw("nostack");
      legend_->Draw("same");

      canvas_->Update();
      canvas_->Draw();
      canvas_->ForceUpdate();
      //canvas_->Print("test.pdf");
      canvas_->Write();

    }
  }
Esempio n. 5
0
void superimposeHistos()
{
  TFile* bFile = TFile::Open("Electron_In_Jets_900GeV_bJets.root");
  TFile* cFile = TFile::Open("Electron_In_Jets_900GeV_cJets.root");
  TFile* udsgFile = TFile::Open("Electron_In_Jets_900GeV_udsgJets.root");
  
  TIter next(bFile->GetListOfKeys());
  TFile* newFile = new TFile("testFile.root", "RECREATE");
  while(TKey* key = (TKey*)next())
  {
    TH1F* bHist = (TH1F*)bFile->Get(key->GetName());
    bHist->SetFillColor(2);
    
    TH1F* cHist = (TH1F*)cFile->Get(key->GetName());
    cHist->SetFillColor(3);
    
    TH1F* udsgHist = (TH1F*)udsgFile->Get(key->GetName());
    udsgHist->SetFillColor(4);
    
    THStack* stack = new THStack(bHist->GetName(), bHist->GetTitle());
    stack->Add(udsgHist, "hist ][");
    stack->Add(cHist, "hist ][");
    stack->Add(bHist, "hist ][");
    
    TLegend* legend = new TLegend(0.5, 0.68, 0.88, 0.88);
    legend->AddEntry(bHist, "b-Jets");
    legend->AddEntry(cHist, "c-Jets");
    legend->AddEntry(udsgHist, "udsg-Jets");
    
    TCanvas* canvas = new TCanvas(bHist->GetName());
    stack->Draw();
    stack->GetXaxis()->SetTitle(bHist->GetXaxis()->GetTitle());
    legend->Draw();
    canvas->Write(canvas->GetName());
  }
  
  newFile->Close();
  bFile->Close();
  cFile->Close();
  udsgFile->Close();
}
Esempio n. 6
0
void BINcomb(){

  TFile *fqcd = new TFile("QCD.root");
  TFile *fsig = new TFile("SIG.root");
  TFile *fttb = new TFile("TTB.root");

  double xcqcd = 25.42*1000; 
  double xcttb = 831.76*1000; 
  double xcsig = 0.0624391*1000;
  
  double lumi = 5.0 ; 
  

  double nt_qcd = xcqcd*lumi; 
  double nt_sig = xcsig*lumi; 
  double nt_ttb = xcttb*lumi; 

  fqcd->cd();
  demo->cd();
  double scf_qcd = nt_qcd/(1.0*Ev0->GetEntries()); 

  TH1F *ak8ptq = ak8pt->Clone();
  TH1F *t31q = ak8t31->Clone();
  TH1F *ak8_phosubfq = ak8_phosubFrac->Clone();  
  TH1F *pm0q = ak8_prunnedM0->Clone(); 
  TH1F *pm1q = ak8_prunnedM1->Clone(); 
  TH1F *pm2q = ak8_prunnedM2->Clone(); 
  TH1F *pm3q = ak8_prunnedM3->Clone(); 
  TH1F *pm4q = ak8_prunnedM4->Clone(); 
  TH1F *pm5q = ak8_prunnedM5->Clone(); 
  TH1F *njt3q = NJT3->Clone();
  TH1F *njl3q = NJL3->Clone();
  TH1F *njt4q = NJT4->Clone();
  TH1F *njl4q = NJL4->Clone();
  TH1F *htaq = HTa->Clone();
  TH1F *ht3q = HT3->Clone();
  TH1F *ht4q = HT4->Clone();
  TH1F *ht4l1q = HT4L1->Clone();
  TH1F *ht4l2q = HT4L2->Clone();
  TH1F *ht4t1q = HT4T1->Clone();
  TH1F *ht4t2q = HT4T2->Clone();
  TH1F *ht3l1q = HT3L1->Clone();
  TH1F *ht3l2q = HT3L2->Clone();
  TH1F *ht3t1q = HT3T1->Clone();
  TH1F *ht3t2q = HT3T2->Clone();
  
  TH1F *Thotmassq = T2jet_4evmasspruned->Clone();
  TH1F *Lhotmassq = L3jet_4evmasspruned->Clone();
 

  fttb->cd();
  demo->cd();
  double scf_ttb = nt_ttb/(1.0*Ev0->GetEntries()); 



  TH1F *Thotmasst = T2jet_4evmasspruned->Clone();
  TH1F *Lhotmasst = L3jet_4evmasspruned->Clone();
 
 
  TH1F *ak8ptt = ak8pt->Clone();
  TH1F *t31t = ak8t31->Clone();
  TH1F *ak8_phosubft = ak8_phosubFrac->Clone();  
  TH1F *pm0t = ak8_prunnedM0->Clone(); 
  TH1F *pm1t = ak8_prunnedM1->Clone(); 
  TH1F *pm2t = ak8_prunnedM2->Clone(); 
  TH1F *pm3t = ak8_prunnedM3->Clone(); 
  TH1F *pm4t = ak8_prunnedM4->Clone(); 
  TH1F *pm5t = ak8_prunnedM5->Clone(); 
  TH1F *njt3t = NJT3->Clone();
  TH1F *njl3t = NJL3->Clone();
  TH1F *njt4t = NJT4->Clone();
  TH1F *njl4t = NJL4->Clone();
  TH1F *htat = HTa->Clone();
  TH1F *ht3t = HT3->Clone();
  TH1F *ht4t = HT4->Clone();
  TH1F *ht4l1t = HT4L1->Clone();
  TH1F *ht4l2t = HT4L2->Clone();
  TH1F *ht4t1t = HT4T1->Clone();
  TH1F *ht4t2t = HT4T2->Clone();
  TH1F *ht3l1t = HT3L1->Clone();
  TH1F *ht3l2t = HT3L2->Clone();
  TH1F *ht3t1t = HT3T1->Clone();
  TH1F *ht3t2t = HT3T2->Clone();


  fsig->cd();
  demo->cd();
  double scf_sig = nt_sig/(1.0*Ev0->GetEntries()); 

  TH1F *Thotmasss = T2jet_4evmasspruned->Clone();
  TH1F *Lhotmasss = L3jet_4evmasspruned->Clone();
 

  TH1F *ak8pts = ak8pt->Clone();
  TH1F *t31s = ak8t31->Clone();
  TH1F *ak8_phosubfs = ak8_phosubFrac->Clone();  
  TH1F *pm0s = ak8_prunnedM0->Clone(); 
  TH1F *pm1s = ak8_prunnedM1->Clone(); 
  TH1F *pm2s = ak8_prunnedM2->Clone(); 
  TH1F *pm3s = ak8_prunnedM3->Clone(); 
  TH1F *pm4s = ak8_prunnedM4->Clone(); 
  TH1F *pm5s = ak8_prunnedM5->Clone(); 
  TH1F *njt3s = NJT3->Clone();
  TH1F *njl3s = NJL3->Clone();
  TH1F *njt4s = NJT4->Clone();
  TH1F *njl4s = NJL4->Clone();
  TH1F *htas = HTa->Clone();
  TH1F *ht3s = HT3->Clone();
  TH1F *ht4s = HT4->Clone();
  TH1F *ht4l1s = HT4L1->Clone();
  TH1F *ht4l2s = HT4L2->Clone();
  TH1F *ht4t1s = HT4T1->Clone();
  TH1F *ht4t2s = HT4T2->Clone();
  TH1F *ht3l1s = HT3L1->Clone();
  TH1F *ht3l2s = HT3L2->Clone();
  TH1F *ht3t1s = HT3T1->Clone();
  TH1F *ht3t2s = HT3T2->Clone();


  //Scaling all the historgrams: 
  ak8pts->Scale(scf_sig);
  t31s->Scale(scf_sig);
  ak8_phosubfs->Scale(scf_sig);
  pm0s->Scale(scf_sig);
  pm1s->Scale(scf_sig);
  pm2s->Scale(scf_sig);
  pm3s->Scale(scf_sig);
  pm4s->Scale(scf_sig);
  pm5s->Scale(scf_sig);
  njt3s->Scale(scf_sig);
  njl3s->Scale(scf_sig);
  njt4s->Scale(scf_sig);
  njl4s->Scale(scf_sig);
  htas->Scale(scf_sig);
  ht3s->Scale(scf_sig);
  ht4s->Scale(scf_sig);
  ht4l1s->Scale(scf_sig);
  ht4l2s->Scale(scf_sig);
  ht4t1s->Scale(scf_sig);
  ht4t2s->Scale(scf_sig);
  ht3l1s->Scale(scf_sig);
  ht3l2s->Scale(scf_sig);
  ht3t1s->Scale(scf_sig);
  ht3t2s->Scale(scf_sig);
  Thotmasss->Scale(scf_sig);
  Lhotmasss->Scale(scf_sig);




 Thotmasss->SetFillColor(kRed);
 Lhotmasss->SetFillColor(kRed);
  ak8pts->SetFillColor(kRed);
  t31s->SetFillColor(kRed);

  
  ak8_phosubfs->SetFillColor(kRed);
  pm0s->SetFillColor(kRed);
  pm1s->SetFillColor(kRed);
  pm2s->SetFillColor(kRed);
  pm3s->SetFillColor(kRed);
  pm4s->SetFillColor(kRed);
  pm5s->SetFillColor(kRed);
  njt3s->SetFillColor(kRed);
  njl3s->SetFillColor(kRed);
  njt4s->SetFillColor(kRed);
  njl4s->SetFillColor(kRed);
  htas->SetFillColor(kRed);
  ht3s->SetFillColor(kRed);
  ht4s->SetFillColor(kRed);
  ht4l1s->SetFillColor(kRed);
  ht4l2s->SetFillColor(kRed);
  ht4t1s->SetFillColor(kRed);
  ht4t2s->SetFillColor(kRed);
  ht3l1s->SetFillColor(kRed);
  ht3l2s->SetFillColor(kRed);
  ht3t1s->SetFillColor(kRed);
  ht3t2s->SetFillColor(kRed);


  Thotmasss->SetLineColor(kRed);
  Lhotmasss->SetLineColor(kRed);
  
  ak8pts->SetLineColor(kRed);
  t31s->SetLineColor(kRed);
  ak8_phosubfs->SetLineColor(kRed);
  pm0s->SetLineColor(kRed);
  pm1s->SetLineColor(kRed);
  pm2s->SetLineColor(kRed);
  pm3s->SetLineColor(kRed);
  pm4s->SetLineColor(kRed);
  pm5s->SetLineColor(kRed);
  njt3s->SetLineColor(kRed);
  njl3s->SetLineColor(kRed);
  njt4s->SetLineColor(kRed);
  njl4s->SetLineColor(kRed);
  htas->SetLineColor(kRed);
  ht3s->SetLineColor(kRed);
  ht4s->SetLineColor(kRed);
  ht4l1s->SetLineColor(kRed);
  ht4l2s->SetLineColor(kRed);
  ht4t1s->SetLineColor(kRed);
  ht4t2s->SetLineColor(kRed);
  ht3l1s->SetLineColor(kRed);
  ht3l2s->SetLineColor(kRed);
  ht3t1s->SetLineColor(kRed);
  ht3t2s->SetLineColor(kRed);




  ak8ptq->Scale(scf_qcd);
  t31q->Scale(scf_qcd);
  ak8_phosubfq->Scale(scf_qcd);
  pm0q->Scale(scf_qcd);
  pm1q->Scale(scf_qcd);
  pm2q->Scale(scf_qcd);
  pm3q->Scale(scf_qcd);
  pm4q->Scale(scf_qcd);
  pm5q->Scale(scf_qcd);
  njt3q->Scale(scf_qcd);
  njl3q->Scale(scf_qcd);
  njt4q->Scale(scf_qcd);
  njl4q->Scale(scf_qcd);
  htaq->Scale(scf_qcd);
  ht3q->Scale(scf_qcd);
  ht4q->Scale(scf_qcd);
  ht4l1q->Scale(scf_qcd);
  ht4l2q->Scale(scf_qcd);
  ht4t1q->Scale(scf_qcd);
  ht4t2q->Scale(scf_qcd);
  ht3l1q->Scale(scf_qcd);
  ht3l2q->Scale(scf_qcd);
  ht3t1q->Scale(scf_qcd);
  ht3t2q->Scale(scf_qcd);

  Thotmassq->Scale(scf_qcd);
  Lhotmassq->Scale(scf_qcd);

  
  
  Thotmassq->SetFillColor(kGray+3);
  Lhotmassq->SetFillColor(kGray+3);

  ak8ptq->SetFillColor(kGray+3);
  t31q->SetFillColor(kGray+3);
  ak8_phosubfq->SetFillColor(kGray+3);
  pm0q->SetFillColor(kGray+3);
  pm1q->SetFillColor(kGray+3);
  pm2q->SetFillColor(kGray+3);
  pm3q->SetFillColor(kGray+3);
  pm4q->SetFillColor(kGray+3);
  pm5q->SetFillColor(kGray+3);
  njt3q->SetFillColor(kGray+3);
  njl3q->SetFillColor(kGray+3);
  njt4q->SetFillColor(kGray+3);
  njl4q->SetFillColor(kGray+3);
  htaq->SetFillColor(kGray+3);
  ht3q->SetFillColor(kGray+3);
  ht4q->SetFillColor(kGray+3);
  ht4l1q->SetFillColor(kGray+3);
  ht4l2q->SetFillColor(kGray+3);
  ht4t1q->SetFillColor(kGray+3);
  ht4t2q->SetFillColor(kGray+3);
  ht3l1q->SetFillColor(kGray+3);
  ht3l2q->SetFillColor(kGray+3);
  ht3t1q->SetFillColor(kGray+3);
  ht3t2q->SetFillColor(kGray+3);

  
  Thotmassq->SetLineColor(kGray+3);
  Lhotmassq->SetLineColor(kGray+3);

  ak8ptq->SetLineColor(kGray+3);
  t31q->SetLineColor(kGray+3);
  ak8_phosubfq->SetLineColor(kGray+3);
  pm0q->SetLineColor(kGray+3);
  pm1q->SetLineColor(kGray+3);
  pm2q->SetLineColor(kGray+3);
  pm3q->SetLineColor(kGray+3);
  pm4q->SetLineColor(kGray+3);
  pm5q->SetLineColor(kGray+3);
  njt3q->SetLineColor(kGray+3);
  njl3q->SetLineColor(kGray+3);
  njt4q->SetLineColor(kGray+3);
  njl4q->SetLineColor(kGray+3);
  htaq->SetLineColor(kGray+3);
  ht3q->SetLineColor(kGray+3);
  ht4q->SetLineColor(kGray+3);
  ht4l1q->SetLineColor(kGray+3);
  ht4l2q->SetLineColor(kGray+3);
  ht4t1q->SetLineColor(kGray+3);
  ht4t2q->SetLineColor(kGray+3);
  ht3l1q->SetLineColor(kGray+3);
  ht3l2q->SetLineColor(kGray+3);
  ht3t1q->SetLineColor(kGray+3);
  ht3t2q->SetLineColor(kGray+3);



 
  ak8ptt->Scale(scf_ttb);
  t31t->Scale(scf_ttb);
  ak8_phosubft->Scale(scf_ttb);
  pm0t->Scale(scf_ttb);
  pm1t->Scale(scf_ttb);
  pm2t->Scale(scf_ttb);
  pm3t->Scale(scf_ttb);
  pm4t->Scale(scf_ttb);
  pm5t->Scale(scf_ttb);
  njt3t->Scale(scf_ttb);
  njl3t->Scale(scf_ttb);
  njt4t->Scale(scf_ttb);
  njl4t->Scale(scf_ttb);
  htat->Scale(scf_ttb);
  ht3t->Scale(scf_ttb);
  ht4t->Scale(scf_ttb);
  ht4l1t->Scale(scf_ttb);
  ht4l2t->Scale(scf_ttb);
  ht4t1t->Scale(scf_ttb);
  ht4t2t->Scale(scf_ttb);
  ht3l1t->Scale(scf_ttb);
  ht3l2t->Scale(scf_ttb);
  ht3t1t->Scale(scf_ttb);
  ht3t2t->Scale(scf_ttb);


  Thotmasst->Scale(scf_ttb);
  Lhotmasst->Scale(scf_ttb);

  
  Thotmasst->SetFillColor(kMagenta);
  Lhotmasst->SetFillColor(kMagenta);
  
  ak8ptt->SetFillColor(kMagenta);
  t31t->SetFillColor(kMagenta);
  ak8_phosubft->SetFillColor(kMagenta);
  pm0t->SetFillColor(kMagenta);
  pm1t->SetFillColor(kMagenta);
  pm2t->SetFillColor(kMagenta);
  pm3t->SetFillColor(kMagenta);
  pm4t->SetFillColor(kMagenta);
  pm5t->SetFillColor(kMagenta);
  njt3t->SetFillColor(kMagenta);
  njl3t->SetFillColor(kMagenta);
  njt4t->SetFillColor(kMagenta);
  njl4t->SetFillColor(kMagenta);
  htat->SetFillColor(kMagenta);
  ht3t->SetFillColor(kMagenta);
  ht4t->SetFillColor(kMagenta);
  ht4l1t->SetFillColor(kMagenta);
  ht4l2t->SetFillColor(kMagenta);
  ht4t1t->SetFillColor(kMagenta);
  ht4t2t->SetFillColor(kMagenta);
  ht3l1t->SetFillColor(kMagenta);
  ht3l2t->SetFillColor(kMagenta);
  ht3t1t->SetFillColor(kMagenta);
  ht3t2t->SetFillColor(kMagenta);


  Thotmasst->SetLineColor(kMagenta);
  Lhotmasst->SetLineColor(kMagenta);
  
  ak8ptt->SetLineColor(kMagenta);
  t31t->SetLineColor(kMagenta);
  ak8_phosubft->SetLineColor(kMagenta);
  pm0t->SetLineColor(kMagenta);
  pm1t->SetLineColor(kMagenta);
  pm2t->SetLineColor(kMagenta);
  pm3t->SetLineColor(kMagenta);
  pm4t->SetLineColor(kMagenta);
  pm5t->SetLineColor(kMagenta);
  njt3t->SetLineColor(kMagenta);
  njl3t->SetLineColor(kMagenta);
  njt4t->SetLineColor(kMagenta);
  njl4t->SetLineColor(kMagenta);
  htat->SetLineColor(kMagenta);
  ht3t->SetLineColor(kMagenta);
  ht4t->SetLineColor(kMagenta);
  ht4l1t->SetLineColor(kMagenta);
  ht4l2t->SetLineColor(kMagenta);
  ht4t1t->SetLineColor(kMagenta);
  ht4t2t->SetLineColor(kMagenta);
  ht3l1t->SetLineColor(kMagenta);
  ht3l2t->SetLineColor(kMagenta);
  ht3t1t->SetLineColor(kMagenta);
  ht3t2t->SetLineColor(kMagenta);





  
  THStack *hpt     = new THStack("hpt","JetsPt");
  hpt->Add(ak8ptq);
  hpt->Add(ak8ptt);
  hpt->Add(ak8pts);


  THStack *ht31    = new THStack("ht31","JetsPt");
  ht31->Add(t31q);
  ht31->Add(t31t);
  ht31->Add(t31s);

  THStack *hphos   = new THStack("hphos","JetsPt");
  hphos->Add(ak8_phosubfq);
  hphos->Add(ak8_phosubft);
  hphos->Add(ak8_phosubfs);
  
  THStack *hhaspho = new THStack("hhaspho","JetsPt");
  //hhaspho->Add



  THStack *hm0 = new THStack("hm0","JetsPt");
  hm0->Add(pm0q);
  hm0->Add(pm0t);
  hm0->Add(pm0s);
  
  THStack *hm1 = new THStack("hm1","JetsPt");
  hm1->Add(pm1q);
  hm1->Add(pm1t);
  hm1->Add(pm1s);
 
  THStack *hm2 = new THStack("hm2","JetsPt");
  hm2->Add(pm2q);
  hm2->Add(pm2t);
  hm2->Add(pm2s);

  
  THStack *hm3 = new THStack("hm3","JetsPt");
  hm3->Add(pm3q);
  hm3->Add(pm3t);
  hm3->Add(pm3s);

  THStack *hm4 = new THStack("hm4","JetsPt");
  hm4->Add(pm4q);
  hm4->Add(pm4t);
  hm4->Add(pm4s);

  THStack *hm5 = new THStack("hm5","JetsPt");
  hm5->Add(pm5q);
  hm5->Add(pm5t);
  hm5->Add(pm5s);


  //************************


  THStack *nj3t = new THStack("nj3t","3 j Evs tight Jets");
  nj3t->Add(njt3q);
  nj3t->Add(njt3t);
  nj3t->Add(njt3s);

  THStack *nj3l = new THStack("nj3l","3 j Evs loose Jets");
  nj3l->Add(njl3q);
  nj3l->Add(njl3t);
  nj3l->Add(njl3s);

  THStack *nj4t = new THStack("nj4t","4 j Evs tight Jets");
  nj4t->Add(njt4q);
  nj4t->Add(njt4t);
  nj4t->Add(njt4s);

  THStack *nj4l = new THStack("nj4l","4 j Evs loose Jets");
  nj4l->Add(njl4q);
  nj4l->Add(njl4t);
  nj4l->Add(njl4s);

  //Rebinning the mass plots
  Lhotmassq->Rebin(2);
  Lhotmasst->Rebin(2);
  Lhotmasss->Rebin(2);
  Thotmassq->Rebin(2);
  Thotmasst->Rebin(2);
  Thotmasss->Rebin(2);



  THStack *nj4l2m = new THStack("nj4l2m","4 j mass Evs loose Jets");
  nj4l2m->Add(Lhotmassq);
  nj4l2m->Add(Lhotmasst);
  nj4l2m->Add(Lhotmasss);

  THStack *nj4T2m = new THStack("nj4T2m","4 j mass Evs Tight Jets");
  nj4T2m->Add(Thotmassq);
  nj4T2m->Add(Thotmasst);
  nj4T2m->Add(Thotmasss);


  
 


  TCanvas *c1 = new TCanvas("c1","step1",1200,600);
  c1->Divide(2,1); 
  c1->cd(1);
  hpt->Draw();
  hpt->GetXaxis()->SetTitle("Jet Pt GeVc^{-1}");
  
  c1->cd(2);
  hm1->Draw();
  hm1->GetXaxis()->SetTitle("Jet Prunned Mass GeVc^{-2}"); 
  c1->Update();
  c1->SaveAs("ptcut.png");
  
  TCanvas *c2 = new TCanvas("c2","step2",1200,600);
  c2->Divide(2,1); 
  c2->cd(1);
  ht31->Draw();
  ht31->GetXaxis()->SetTitle("#tau_3/#tau_1");

  c2->cd(2);
  hm2->Draw();
  hm2->GetXaxis()->SetTitle("Jet Prunned Mass GeVc^{-2}"); 
   c2->Update();
 
 c2->SaveAs("ht31.png");
  
  /* 
  TCanvas *c3 = new TCanvas("c3","step2",1200,600);
  c3->Divide(2,1); 
  c3->cd(1);
  hhasphos->Draw();
  hhasphos->GetXaxis()->SetTitle("Has Photon Pt > 20 GeVc^{-1}");
  
  c3->cd(2);
  hm3->Draw();
  hm3->GetXaxis()->SetTitle("Jet Prunned Mass GeVc^{-2}"); 
  c3->SaveAs("hasphos.png");
  */
  
  TCanvas *c4 = new TCanvas("c4","step2",1200,600);
  c4->Divide(2,1); 
  c4->cd(1);
  hphos->Draw();
  hphos->GetXaxis()->SetTitle("Pt_{#gamma}/Pt_{subjet}");
  
  c4->cd(2);
  hm4->Draw();
  hm4->GetXaxis()->SetTitle("Jet Prunned Mass GeVc^{-2}"); 
   c4->Update();
 
  c4->SaveAs("phos.png");
  
  
  TCanvas *c5 = new TCanvas("","",1200,800);
  c5->Divide(4,2);
  c5->cd(1);
  
  c5->cd(1);
  c5->cd(1);
  c5->cd(1);
  c5->cd(1);
  c5->cd(1);
  

  c5->SaveAs("HTplots.png");
  
  TCanvas *c6 = new TCanvas("c6","",1000,1000);
  c6->Divide(2,2);
  c6->cd(1)->SetLogy();
  nj3l->Draw();
  nj3l->GetXaxis()->SetTitle("Njets Loose per event"); 

  c6->cd(2)->SetLogy();
  nj3t->Draw();
  nj3t->GetXaxis()->SetTitle("Njets Tight per event"); 


  c6->cd(3)->SetLogy();
  nj4l->Draw();
  nj4l->GetXaxis()->SetTitle("Njets Loose per event"); 
 
 

  c6->cd(4)->SetLogy();
  nj4t->Draw();
  nj4t->GetXaxis()->SetTitle("Njets Tight per event"); 
 
  c6->Update();
  c6->SaveAs("NjTL.png");



  TCanvas *c7 = new TCanvas("c7","",1000,500);
  c7->Divide(2,1);
  c7->cd(1);
  nj4l2m->Draw();
  nj4l2m->GetXaxis()->SetTitle("Jet Prunned Mass GeVc^{-2}");

  c7->cd(2);
  nj4T2m->Draw();
  nj4T2m->GetXaxis()->SetTitle("Jet Prunned Mass GeVc^{-2}");


  c7->SaveAs("PrnM_sel.png");

 
 
  

}
Esempio n. 7
0
void doPlotsMuon(){
setTDRStyle();

//loop over variables
for(int i = 0; i<1; i++){
double MinX = MinXs[i];
double MaxX = MaxXs[i];
Variable = Variables[i];
TString Xtitle = XTitles[i];

//Data
TH1D* data = getSample("SingleMu", 1, Obj, Variable, Isolation, rebinFact, "central");

//MC
TH1D* tt = getSample("TTJet", lumi*225.2/6920475, Obj, Variable, Isolation, rebinFact, Systematic);

//ttbar individual
// TH1D* tt_semi = getSample("TTJet_SemiLept", lumi*225.2/6920475, Obj, Variable, Isolation, rebinFact, Systematic);
// TH1D* tt_lep = getSample("TTJet_FullLept", lumi*225.2/6920475, Obj, Variable, Isolation, rebinFact, Systematic);
// TH1D* tt_had = getSample("TTJet_Hadronic", lumi*225.2/6920475, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* wjets = getSample("W1Jet", lumi*37509/57708550, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w1jets = getSample("W1Jet", lumi*5400.0/23140779, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* zjets = getSample("DY1JetsToLL", lumi*5745.25/30457954, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z1jets = getSample("DY1JetsToLL", lumi*561.0/24042904, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* qcd = getSample("QCD_Pt-15to20_MuEnrichedPt5",     lumi*34679.3/8500505, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd1 = getSample("QCD_Pt-15to20_MuEnrichedPt5",   lumi*7.022e8 * 0.0039/1722678, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5",   lumi*2.87e8 * 0.0065/8486893, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5",   lumi*6.609e7 * 0.0122/8928999, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5",   lumi*8082000.0 * 0.0218/7256011, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5",  lumi*1024000.0 * 0.0395/9030624, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5",     lumi*0.774 * 0.1097/3807263, Obj, Variable, Isolation, rebinFact, Systematic);


TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948, Obj, Variable, Isolation, rebinFact, Systematic);

//make combined top and single top template
TH1D* sing_top = (TH1D*)top_t->Clone("top");
sing_top->Add(top_tw);sing_top->Add(top_s); sing_top->Add(tbar_t); sing_top->Add(tbar_tw);sing_top->Add(tbar_s);

  if(inclQ == true){
  qcd->Add(qcd);
  }else{
  qcd1->Add(qcd2);
  qcd1->Add(qcd3);
  qcd1->Add(qcd4);
  qcd1->Add(qcd5);
  qcd1->Add(qcd6);
  qcd1->Add(qcd7);
  qcd1->Add(qcd8);
  qcd1->Add(qcd9);
  qcd1->Add(qcd10);
  qcd1->Add(qcd11);
  }
  
TH1D* qcd_data = getQCD(Obj, Variable, rebinFact);
qcd_data->Scale(qcd1->Integral());

THStack *hs = new THStack("hs","test");
  if(inclQ == true){
  hs->Add(qcd_data);
  }else{
  hs->Add(qcd_data);
  }
    
  zjets->Add(z2jets);
  zjets->Add(z3jets);
  zjets->Add(z4jets);  

  wjets->Add(w2jets);
  wjets->Add(w3jets);
  wjets->Add(w4jets);
  
  hs->Add(zjets);
  hs->Add(wjets);
      
  hs->Add(top_t);
  hs->Add(top_tw);
  hs->Add(top_s);
  hs->Add(tbar_t);
  hs->Add(tbar_tw);
  hs->Add(tbar_s);
  
  hs->Add(tt);
  
  TH1D* allMC = (TH1D*)tt->Clone("allMC");
  allMC->Add(sing_top); allMC->Add(wjets); allMC->Add(zjets); allMC->Add(qcd1);
  
  cout << "tt: " << tt->Integral()  << " wjets: " << wjets->Integral() << " zjets: " << zjets->Integral() << " single top: " << sing_top->Integral() << " qcd: " << qcd1->Integral() << " all: " << allMC->Integral() << " data: " << data->Integral() << endl;
  	
  //draw histos to files
  TCanvas *c1 = new TCanvas("Plot","Plot",900, 600);

  hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3);

  hs->Draw();
  data->Draw("E same");
  data->SetMarkerStyle(20);
  
  hs->GetXaxis()->SetLimits(MinX, MaxX);
  hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05);
  hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);
  
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.6,0.6,0.8,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(data , "2012 data", "lpe");
	tleg2->AddEntry(tt , "t#bar{t} l+jets", "lf");
	//tleg2->AddEntry(tt_lep , "t#bar{t} di-lepton", "lf");
	tleg2->AddEntry(top_t, "single top", "lf");
	tleg2->AddEntry(wjets , "w+jets", "lf");
	tleg2->AddEntry(zjets , "z+jets", "lf");
	tleg2->AddEntry(qcd , "QCD", "lf");

	//tleg2->AddEntry(singtEff, "single-t"      , "l");
	//tleg2->AddEntry(singtwEff, "single-tW"      , "l");
 	tleg2->Draw("same");	

	TText* textPrelim = doPrelim(0.12,0.96);
	textPrelim->Draw();

  if(logPlot ==true){
  c1->SetLogy();
  }	
  
  TString plotName("plots/Control/Muon/");
  
  if(logPlot ==true){
    plotName += Variable+"Log";
    plotName += Nbtags+".pdf";
    
  }else{
    plotName += Variable;  
    plotName += Nbtags+".pdf";
  }
 
 
  c1->SaveAs(plotName);
  delete c1;
  
  }
  	
}
Esempio n. 8
0
double etaFit(TString bin, TString valReturn, TString dir){
setTDRStyle();

bool savePlots = false;


//these only need to be global is using constraints
double Nwjets, Nzjets, NQCD;

bool inclZ = false;
bool inclW = false;

if(dir == "Scale_up" || dir == "Scale_down" || dir == "Match_up" || dir == "Match_down"){
inclZ = true;
inclW = true;
}

//choose object
TString Obj = bin;
int rebinFact = 1;

double MinX = 0.;
double MaxX = 2.6;

TString Xtitle = "#left|#eta#right|_{#mu}";

//Data
data = getSample("SingleMu", 1, rebinFact, Obj, "central");

//MC
TH1D* tt = getSample("TTJet", lumi*225.2/6920475, rebinFact, Obj, dir);
TH1D* tt_tot = getSample("TTJet", lumi*225.2/6920475, rebinFact, "Muon", dir);

TH1D* wjets;
//TH1D* w1jets = getSample("W1Jet", lumi*5400.0/23140779, rebinFact, Obj, dir);
TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404, rebinFact, Obj, dir);
TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443, rebinFact, Obj, dir);
TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904, rebinFact, Obj, dir);

TH1D* zjets;
//TH1D* z1jets = getSample("DY1JetsToLL", lumi*561.0/24042904, rebinFact, Obj, dir);
TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749, rebinFact, Obj, dir);
TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628, rebinFact, Obj, dir);
TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785, rebinFact, Obj, dir);

TH1D* qcd = getQCD(rebinFact);

TH1D* qcd_mc = getSample("QCD_Pt-15to20_MuEnrichedPt5",   lumi*7.022e8 * 0.0039/1722678, rebinFact, Obj, dir);
TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5",   lumi*2.87e8 * 0.0065/8486893, rebinFact, Obj, dir);
TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5",   lumi*6.609e7 * 0.0122/8928999, rebinFact, Obj, dir);
TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5",   lumi*8082000.0 * 0.0218/7256011, rebinFact, Obj, dir);
TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5",  lumi*1024000.0 * 0.0395/9030624, rebinFact, Obj, dir);
TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505, rebinFact, Obj, dir);
TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483, rebinFact, Obj, dir);
TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481, rebinFact, Obj, dir);
TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767, rebinFact, Obj, dir);
TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142, rebinFact, Obj, dir);
TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5",     lumi*0.774 * 0.1097/3807263, rebinFact, Obj, dir);

qcd_mc->Add(qcd2);
qcd_mc->Add(qcd3);
qcd_mc->Add(qcd4);
qcd_mc->Add(qcd5);
qcd_mc->Add(qcd6);
qcd_mc->Add(qcd7);
qcd_mc->Add(qcd8);
qcd_mc->Add(qcd9);
qcd_mc->Add(qcd10);
qcd_mc->Add(qcd11);

qcd->Scale(qcd_mc->Integral());
cout << "NQCD: " << qcd_mc->Integral() << endl;

TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707, rebinFact, Obj, dir);
TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395, rebinFact, Obj, dir);
TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516, rebinFact, Obj, dir);
TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817, rebinFact, Obj, dir);
TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239, rebinFact, Obj, dir);
TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948, rebinFact, Obj, dir);

//make combined top and single top template
TH1D* top = (TH1D*)tt->Clone("top");
top->Add(top_t); top->Add(top_tw);top->Add(top_s); top->Add(tbar_t); top->Add(tbar_tw);top->Add(tbar_s);

//sum single top into one
TH1D* single_top = (TH1D*)top_t->Clone("single top");
single_top->Add(top_tw);single_top->Add(top_s); single_top->Add(tbar_t); single_top->Add(tbar_tw);single_top->Add(tbar_s);

  
THStack *hs = new THStack("hs","test");

  hs->Add(qcd);
    
  if(inclZ == true){
  zjets = getSample("DYJetsToLL", lumi*5745.25/30457954, rebinFact, Obj, dir);

  }else{
  zjets  = getSample("DY1JetsToLL", lumi*561.0/24042904, rebinFact, Obj, dir);
  zjets->Add(z2jets);
  zjets->Add(z3jets);
  zjets->Add(z4jets);  
  }
  
  if(inclW == true){
  wjets = getSample("WJetsToLNu", lumi*37509/57708550, rebinFact, Obj, dir);
  }else{
  wjets = getSample("W1Jet", lumi*5400.0/23140779, rebinFact, Obj, dir); 
  wjets->Add(w2jets);
  wjets->Add(w3jets);
  wjets->Add(w4jets);
  }
  
  hs->Add(zjets);
  hs->Add(wjets);
      
  hs->Add(top_t);
  hs->Add(top_tw);
  hs->Add(top_s);
  hs->Add(tbar_t);
  hs->Add(tbar_tw);
  hs->Add(tbar_s);
  
  hs->Add(tt);

//combined histo for pseudo?
TH1D* allMC = (TH1D*)top->Clone("allMC");
allMC->Add(wjets); allMC->Add(zjets); allMC->Add(qcd);

if(savePlots ==true){

  //draw histos to files
  TCanvas *c1 = new TCanvas("Plot","Plot",900, 600);
		
  hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3);

  hs->Draw();
  data->Draw("E same");
  data->SetMarkerStyle(20);
  
  hs->GetXaxis()->SetLimits(MinX, MaxX);
  hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05);
  hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);
  
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.7,0.7,0.8,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(data , "2012 data", "lpe");
	tleg2->AddEntry(tt , "t#bar{t}", "lf");
	tleg2->AddEntry(top_t, "single top", "lf");
	tleg2->AddEntry(wjets , "w+jets", "lf");
	tleg2->AddEntry(zjets , "z+jets", "lf");
	tleg2->AddEntry(qcd , "QCD", "lf");
	
	//tleg2->AddEntry(singtEff, "single-t"      , "l");
	//tleg2->AddEntry(singtwEff, "single-tW"      , "l");
 	tleg2->Draw("same");	
	
	TText* textPrelim = doPrelim(0.17,0.96);
	textPrelim->Draw();

  
  TString plotName("plots/Control/Muon/");
  
    plotName += "absEta";  
    plotName += "_ge2btags.pdf";
  
//  c1->SaveAs(plotName);
  delete c1;
}

//clone and scale
top_fit = (TH1D*)top->Clone("top fit");
wjets_fit = (TH1D*)wjets->Clone("wjets fit");
zjets_fit = (TH1D*)zjets->Clone("zjets fit");
qcd_fit = (TH1D*)qcd->Clone("qcd fit");

bg_fit = (TH1D*)wjets_fit->Clone("bg fit");
bg_fit->Add(zjets_fit);
bg_fit->Add(qcd_fit);

top_fit->Scale(1./ top_fit->Integral());
wjets_fit->Scale(1./ wjets_fit->Integral()); 
zjets_fit->Scale(1./ zjets_fit->Integral()); 
qcd_fit->Scale(1./ qcd_fit->Integral());
bg_fit->Scale(1./ bg_fit->Integral());
  
  
  if(savePlots == true){
  //draw histos to files
  TCanvas *c2 = new TCanvas("Plot","Plot",900, 600);
  
  top_fit->SetFillColor(kWhite); wjets_fit->SetFillColor(kWhite); zjets_fit->SetFillColor(kWhite); qcd_fit->SetFillColor(kWhite); bg_fit->SetFillColor(kWhite); bg_fit->SetLineColor(kBlack);
  top_fit->Draw();
  bg_fit->Draw("same");
  wjets_fit->Draw("same");
  zjets_fit->Draw("same");
  qcd_fit->Draw("same");  
  
  top_fit->SetAxisRange(MinX, MaxX);
  top_fit->GetXaxis()->SetTitle(Xtitle); top_fit->GetXaxis()->SetTitleSize(0.05);
  top_fit->GetYaxis()->SetTitle("Normalised Events");top_fit->GetYaxis()->SetTitleSize(0.05);
    
  	TLegend *tleg3;
	tleg3 = new TLegend(0.65,0.7,0.8,0.9);
	tleg3->SetTextSize(0.04);
	tleg3->SetBorderSize(0);
	tleg3->SetFillColor(10);
	
	tleg3->AddEntry(top_fit , "signal", "l");
	tleg3->AddEntry(bg_fit , "background", "l");
	tleg3->AddEntry(wjets_fit , "w+jets", "l");
	tleg3->AddEntry(zjets_fit , "z+jets", "l");
	tleg3->AddEntry(qcd_fit , "QCD", "l");
 	tleg3->Draw("same");	
	
	TText* textPrelim2 = doPrelim(0.17,0.96);
	textPrelim2->Draw();
  c2->SaveAs("plots/Fits/"+bin+"_Template.pdf");
  delete c2;
 }
 
 
 
int Ntotal = data->Integral();
double Nsignal = top->Integral();
Nwjets = wjets->Integral();
Nzjets = zjets->Integral();
NQCD = qcd->Integral();

  // Initialize minuit, set initial values etc. of parameters.
  const int npar = 2;              // the number of parameters
  TMinuit minuit(npar);
  minuit.SetFCN(fcn);

  minuit.SetPrintLevel(-1);
  minuit.SetErrorDef(1.);
  
  
  int ierflg = 0;
  double Nbg=  wjets->Integral()+zjets->Integral()+qcd->Integral();
  string parName[npar] = {"ttbar+single-top", "background"}; //background parameters
  double par[npar] = {top->Integral(), Nbg};               //using the MC estimation as the start values 1fb
  
  cout << "total data events: " << Ntotal << endl;

  for(int i=0; i<npar; i++){

    //minuit.mnparm(i, parName[i], par[i],10., -1.e6, 1.e6, ierflg);
    minuit.mnparm(i, parName[i], par[i], 10., 0, Ntotal, ierflg);

  }
  
   //the following is copied from Fabian's fitting code to improve minimum, but you can comment it, it won't affect the fitting results.
  // 1 standard
  // 2 try to improve minimum (slower)
  double arglist[10];
  arglist[0]=2;
  minuit.mnexcm("SET STR",arglist,1,ierflg);
  minuit.Migrad();
  
  double outpar[npar], err[npar];
    
  for (int i=0; i<npar; i++){
    minuit.GetParameter(i,outpar[i],err[i]);
  }

  for (int i=0; i<top_fit->GetNbinsX() ; i++){
  
 	top_fit->SetBinContent(i+1, top_fit->GetBinContent(i+1)*outpar[0]);
	bg_fit->SetBinContent(i+1, wjets_fit->GetBinContent(i+1)*outpar[1]);
	//zjets_fit->SetBinContent(i+1, zjets_fit->GetBinContent(i+1)*outpar[2]);
	//qcd_fit->SetBinContent(i+1, qcd_fit->GetBinContent(i+1)*outpar[3]);
  
  }
  
  //print out the results for all templates
//   cout <<" \n Total number of events after the fit" << endl;
//   cout<<"   & ttbar+single top & w+jets & z+jets & qcd "<<endl;
//   cout <<  " & " << Nsignal <<  " & " << Nwjets << " & " <<  Nzjets << " & " <<  NQCD  <<endl;
//   cout<< " & "<<outpar[0]<<"+-"<<err[0]<<" & "<<outpar[1]<<"+-"<<err[1]<<" & "<<outpar[2]<<"+-"<<err[2]<<" & "<<outpar[3]<<"+-"<<err[3]<<endl;

  cout <<" \n Total number of events after the fit" << endl;
  cout<<"   & ttbar+single top & w+jets & z+jets & qcd "<<endl;
  cout <<  " & " << Nsignal <<  " & " << Nwjets + Nzjets + NQCD  <<endl;
  cout<< " & "<<outpar[0] << "+-" <<err[0] << " & " <<outpar[1]<<"+-"<<err[1] <<endl; 

  if(savePlots == true){
    TCanvas *c3 = new TCanvas("Plot","Plot",900, 600);
  
  THStack* sum_fit = new THStack("sum fit","stacked histograms"); //used for stack plot
  qcd_fit->SetFillColor(kYellow); zjets_fit->SetFillColor(kBlue);   wjets_fit->SetFillColor(kGreen);  top_fit->SetFillColor(kRed);
  //sum_fit->Add(qcd_fit); sum_fit->Add(zjets_fit);  sum_fit->Add(wjets_fit);  
  top_fit->SetLineColor(kBlack);
  
  bg_fit->SetFillColor(kGreen);
  sum_fit->Add(bg_fit);sum_fit->Add(top_fit);
 
  sum_fit->Draw();
  data->Draw("E same");
  
  sum_fit->GetXaxis()->SetLimits(MinX, MaxX);
  sum_fit->GetXaxis()->SetTitle(Xtitle); sum_fit->GetXaxis()->SetTitleSize(0.05);
  sum_fit->GetYaxis()->SetTitle("Number of Events");sum_fit->GetYaxis()->SetTitleSize(0.05);
    
  	TLegend *tleg4;
	tleg4 = new TLegend(0.65,0.7,0.8,0.9);
	tleg4->SetTextSize(0.04);
	tleg4->SetBorderSize(0);
	tleg4->SetFillColor(10);
	
	tleg4->AddEntry(top_fit , "signal", "ef");
	tleg4->AddEntry(bg_fit , "background", "ef");
 	tleg4->Draw("same");	
	
	TText* textPrelim3 = doPrelim(0.17,0.96);
	textPrelim3->Draw();
    c3->SaveAs("plots/Fits/"+bin+"_Fit.pdf");
    delete c3;

 }

//cout << "cross section is:  " <<  ((outpar[0]-single_top->Integral())/ tt_tot->Integral())*225.2 << endl;

if(valReturn == "measured"){
return outpar[0];
}else if(valReturn == "measuredErr"){
return err[0];
}else if(valReturn == "bgscale"){
return (outpar[1]/Nbg);

}

return 0;

}
Esempio n. 9
0
void crossXmass(int k=4){

  gSystem->Load("libFWCoreFWLite.so");
  gROOT->LoadMacro("tdrstyle.C");
  setTDRStyle();

  //gStyle->SetOptStat(0000);
  gStyle->SetOptFit(0011);

  TFile * file = new TFile("preUnfolding.root");
  TFile * file_unfolded = new TFile("unfolded.root");
  TFile * file_acceptance = new TFile("acceptance.root");
  TFile * file_truthFinal = new TFile("truthFinal.root");
  TFile * file_zprimeM1000W1 = new TFile("zprime/ZPrimeM1000W1.root");
  TFile * file_zprimeM2000W1 = new TFile("zprime/ZPrimeM2000W1.root");

  //truth level after reconstruction level selection
  TH1F * hGenDistMADGRAPH = (TH1F*) file->Get("hTruth_MadGraph");
  TH1F * hGenDistPOWHEG = (TH1F*) file->Get("hTruth_Powheg");
  //unfolded plot
  TH1F * h_unfold = (TH1F*) file_unfolded->Get("unfolded");
  //acceptance 
  TH1F * hAcceptDist = (TH1F*) file_acceptance->Get("hAccept_vsum");
  TH1F * hAcceptDistFull = (TH1F*) file_acceptance->Get("hAccept_vsum_Full");
  //truth level for final
  TH1D * hGenMADGRAPH = (TH1D*) file_truthFinal->Get("hTruthFinalMADGRAPH");
  TH1D * hGenPOWHEG = (TH1D*) file_truthFinal->Get("hTruthFinalPOWHEG");
  TH1D * hGenMADGRAPH_Full = (TH1D*) file_truthFinal->Get("hTruthFinalMADGRAPH_Full");
  TH1D * hGenPOWHEG_Full = (TH1D*) file_truthFinal->Get("hTruthFinalPOWHEG_Full");

  double lumi = 1143.22;
  bool printX = true; //print cross section

  bool norm = false;
  TH1F* hSigmaData = getMeasuredCrossSection(h_unfold, hAcceptDistFull,lumi,norm, true, "unfolded",false);   
  TH1F* hSigmaTruthHisto = getTruthCrossSection(hGenDistMADGRAPH, hGenMADGRAPH_Full, lumi, norm, false, 1, printX);
  TH1F* hSigmazprimeM1000W1 = getTruthCrossSection(file_zprimeM1000W1, ZXsectionW1[7], "M1000W1");
  TH1F* hSigmazprimeM2000W1 = getTruthCrossSection(file_zprimeM2000W1, ZXsectionW1[18], "M2000W1");
  TH1F* hSigmazprime = hSigmazprimeM1000W1;

  TCanvas * c_Xmass = new TCanvas("c_Xmass","c_Xmass",1);
  c_Xmass->SetLogy();

  TH1F* h_Xmass = (TH1F*)h_unfold->Clone("hSigmaData");     
  TH1F* h_Xmass_ttbar = (TH1F*)h_unfold->Clone("hSigmaData");     
  TH1F* h_Xmass_zprime = (TH1F*) h_unfold->Clone("hSigmaData");     

  h_Xmass->Reset();
  h_Xmass_ttbar->Reset();
  h_Xmass_zprime->Reset();
  
  int nbins = h_unfold->GetNbinsX();
  double total = 0;
  double total_ttbar = 0;
  double total_zprime = 0;

  for(int i=nbins; i >= 1 ;i--){
    double sigma = hSigmaData->GetBinContent(i)*hSigmaData->GetBinWidth(i);
    double sigma_ttbar = hSigmaTruthHisto->GetBinContent(i)*hSigmaTruthHisto->GetBinWidth(i);
    double sigma_zprime = hSigmazprime->GetBinContent(i)*hSigmazprime->GetBinWidth(i);
    total += sigma;
    total_ttbar += sigma_ttbar;
    total_zprime += sigma_zprime;
    cout << hSigmazprime->GetBinContent(i)*hSigmazprime->GetBinWidth(i) << endl;
    h_Xmass->SetBinContent(i, total);
    h_Xmass_ttbar->SetBinContent(i, total_ttbar);
    h_Xmass_zprime->SetBinContent(i, total_zprime);
  }

  THStack *hs = new THStack("hs","zprime plus ttbar");
  h_Xmass_ttbar->SetFillColor(2);
  h_Xmass_zprime->SetLineColor(4);
  h_Xmass_zprime->SetLineWidth(2);
  hs->Add(h_Xmass_ttbar);
  hs->Add(h_Xmass_zprime);
  hs->Draw();
  hs->GetYaxis()->SetTitle("#int_{x}^{#infty} d#sigma/dm_{t#bar{t}} dm_{t#bar{t}}");
  hs->GetXaxis()->SetTitle(" m_{t#bar{t}}");
  h_Xmass->Draw("p same");

  TLegend *l= new TLegend();
  l->AddEntry(h_Xmass, "Data" ,"p");
  l->AddEntry(h_Xmass_ttbar, "t#bar{t}" ,"F");
  l->AddEntry(h_Xmass_zprime, "zprime" ,"L");
  SetLegendStyle(l,true);
  l->Draw("same");

}
Esempio n. 10
0
void draw_from_trees(TString var, TCut other_cuts,
		     TString weights, TString title, int nbinsx, 
		     double xlow, double xup,
		     TString options="plotSig:plotLog:plotData",
		     double cut_low=-1, double cut_high=-1,
		     TString plot_title="default")
{

  bool plotSig = options.Contains("plotSig") && (!options.Contains("!plotSig"));
  bool plotLog = options.Contains("plotLog") && (!options.Contains("!plotLog"));
  bool plotData = options.Contains("plotData") && (!options.Contains("!plotData"));
  bool sigStack = options.Contains("sigStack") && (!options.Contains("!sigStack"));

  // Book histograms
  TH1D * httbar = new TH1D("ttbar" , title, nbinsx, xlow, xup);
  TH1D * hqcd = new TH1D("qcd" , title, nbinsx, xlow, xup);
  TH1D * hznn = new TH1D("znn" , title, nbinsx, xlow, xup);
  TH1D * hwjets = new TH1D("wjets" , title, nbinsx, xlow, xup);
  TH1D * hother = new TH1D("other" , title, nbinsx, xlow, xup);
  TH1D * hmc_exp = new TH1D("mc_exp" , title, nbinsx, xlow, xup);
  TH1D * hsingle_top = new TH1D("single_top" , title, nbinsx, xlow, xup);  
  TH1D * ht1bbbb_1500_100 = new TH1D("t1bbbb_1500_100" , title, nbinsx, xlow, xup);
  TH1D * ht1bbbb_1000_900 = new TH1D("t1bbbb_1000_900" , title, nbinsx, xlow, xup);
  TH1D * ht1tttt_1500_100 = new TH1D("t1tttt_1500_100" , title, nbinsx, xlow, xup);
  TH1D * ht1tttt_1200_800 = new TH1D("t1tttt_1200_800" , title, nbinsx, xlow, xup);
  TH1D * ht1qqqq_1400_100 = new TH1D("t1qqqq_1400_100" , title, nbinsx, xlow, xup);
  TH1D * ht1qqqq_1000_800 = new TH1D("t1qqqq_1000_800" , title, nbinsx, xlow, xup);

  // Format cuts
  TCut cut(other_cuts);

  // TCut ttbar_weight("(weightppb*4000)/top_pt_weight_official");

  TCut ttbar_weight("(3.17760399999999981e-05*4000)");

  cout << "Filling histograms for " << var.Data() << endl;
  ttbar_ch->Project("ttbar",var,(cut)*ttbar_weight);
  qcd_ch->Project("qcd",var,cut*weights);
  znn_ch->Project("znn",var,cut*weights);
  wjets_ch->Project("wjets",var,(cut)*weights);
  other_ch->Project("other",var,cut*weights);
  single_top_ch->Project("single_top",var,cut*weights);
  t1bbbb_1500_100_ch->Project("t1bbbb_1500_100",var,(cut)*weights);
  t1bbbb_1000_900_ch->Project("t1bbbb_1000_900",var,(cut)*weights);
  t1tttt_1500_100_ch->Project("t1tttt_1500_100",var,(cut)*weights);
  t1tttt_1200_800_ch->Project("t1tttt_1200_800",var,(cut)*weights);
  t1qqqq_1400_100_ch->Project("t1qqqq_1400_100",var,(cut)*weights);
  t1qqqq_1000_800_ch->Project("t1qqqq_1000_800",var,(cut)*weights);


  bool addOverflow(true);
  Double_t e_overflow(0.), i_overflow(0.);
  if (addOverflow) {
    i_overflow=httbar->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    httbar->SetBinContent(nbinsx, i_overflow);
    httbar->SetBinError(nbinsx, e_overflow);
    i_overflow=hqcd->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    hqcd->SetBinContent(nbinsx, i_overflow);
    hqcd->SetBinError(nbinsx, e_overflow);
    i_overflow=hznn->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    hznn->SetBinContent(nbinsx, i_overflow);
    hznn->SetBinError(nbinsx, e_overflow);
    i_overflow=hwjets->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    hwjets->SetBinContent(nbinsx, i_overflow);
    hwjets->SetBinError(nbinsx, e_overflow);
    i_overflow=hsingle_top->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    hsingle_top->SetBinContent(nbinsx, i_overflow);
    hsingle_top->SetBinError(nbinsx, e_overflow);
    i_overflow=hother->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    hother->SetBinContent(nbinsx, i_overflow);
    hother->SetBinError(nbinsx, e_overflow);
    i_overflow=ht1bbbb_1500_100->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    ht1bbbb_1500_100->SetBinContent(nbinsx, i_overflow);
    ht1bbbb_1500_100->SetBinError(nbinsx, e_overflow);
    i_overflow=ht1bbbb_1000_900->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    ht1bbbb_1000_900->SetBinContent(nbinsx, i_overflow);
    ht1bbbb_1000_900->SetBinError(nbinsx, e_overflow);
    i_overflow=ht1tttt_1500_100->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    ht1tttt_1500_100->SetBinContent(nbinsx, i_overflow);
    ht1tttt_1500_100->SetBinError(nbinsx, e_overflow);
    i_overflow=ht1tttt_1200_800->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    ht1tttt_1200_800->SetBinContent(nbinsx, i_overflow);
    ht1tttt_1200_800->SetBinError(nbinsx, e_overflow);
    i_overflow=ht1qqqq_1400_100->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    ht1qqqq_1400_100->SetBinContent(nbinsx, i_overflow);
    ht1qqqq_1400_100->SetBinError(nbinsx, e_overflow);
    i_overflow=ht1qqqq_1000_800->IntegralAndError(nbinsx,nbinsx+1,e_overflow);
    ht1qqqq_1000_800->SetBinContent(nbinsx, i_overflow);
    ht1qqqq_1000_800->SetBinError(nbinsx, e_overflow);
  }

  
  // Add up MC histograms
  hmc_exp->Add(httbar);
  hmc_exp->Add(hqcd);
  hmc_exp->Add(hznn);
  hmc_exp->Add(hwjets);
  hmc_exp->Add(hsingle_top);
  hmc_exp->Add(hother);


  double binwidth = (xup - xlow) / nbinsx;
  TString ytitle = Form("Events / %.3f", binwidth);
  hmc_exp->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle());
  hmc_exp->GetYaxis()->SetTitle(ytitle);
  cout << "... DONE: add all backgrounds to mc_exp." << endl;
  
  Double_t ttbar_e(0.), qcd_e(0.), znn_e(0.), wjets_e(0.), other_e(0.), single_top_e(0.), bg_tot_e(0.), t1tttt_1500_100_e(0.);
  double ttbar_n(httbar->IntegralAndError(0,nbinsx+1, ttbar_e));
  double qcd_n(hqcd->IntegralAndError(0,nbinsx+1, qcd_e));
  double znn_n(hznn->IntegralAndError(0,nbinsx+1, znn_e));
  double wjets_n(hwjets->IntegralAndError(0,nbinsx+1, wjets_e));
  double other_n(hother->IntegralAndError(0,nbinsx+1, other_e));
  double single_top_n(hsingle_top->IntegralAndError(0,nbinsx+1, single_top_e));
  double bg_tot(hmc_exp->IntegralAndError(0,nbinsx+1, bg_tot_e));
  double t1tttt_1500_100_n(ht1tttt_1500_100->IntegralAndError(0,nbinsx+1, t1tttt_1500_100_e));


  printf("Counts before cut: %s\n",var.Data());
  printf("&ttbar&qcd&znn&wjets&single top&other&t1bbbb_1500_100\\\\ \n");
  printf("%s & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f & %3.2f+-%3.2f \\\\\n",
	 var.Data(),
	 ttbar_n,ttbar_e,
	 qcd_n,qcd_e,
	 znn_n,znn_e,
	 wjets_n,wjets_e,
	 single_top_n,single_top_e,
	 other_n,other_e,
	 //	 hmc_exp->GetBinContent(1), hmc_exp->GetBinError(1),
	 bg_tot,bg_tot_e,
	 t1tttt_1500_100_n,t1tttt_1500_100_e);


  cout << "... DONE: filled histograms." << endl;
 
  if (sigStack) {
    for (int bin(0); bin<nbinsx; bin++) {
      ht1bbbb_1500_100->SetBinContent(bin+1, hmc_exp->GetBinContent(bin+1));
      ht1bbbb_1000_900->SetBinContent(bin+1, hmc_exp->GetBinContent(bin+1));
      ht1tttt_1500_100->SetBinContent(bin+1, hmc_exp->GetBinContent(bin+1));
      ht1tttt_1200_800->SetBinContent(bin+1, hmc_exp->GetBinContent(bin+1));
    }
  }
 
  THStack * hs = new THStack("hs", "");
  hs->Add(hother); 
  hs->Add(hsingle_top);
  hs->Add(hwjets);
  hs->Add(hznn);
  if (httbar->Integral()>hqcd->Integral()) {
    hs->Add(hqcd);
    hs->Add(httbar);
  } else {
    hs->Add(httbar);
    hs->Add(hqcd);
  }


  //hs->GetYaxis()->SetTitle("Events / 5 fb^{-1}");
  //hs->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle());

  // Setup histogram styles
  set_style(httbar, "ttbar");
  set_style(hqcd, "qcd");
  set_style(hznn, "znn");
  set_style(hwjets, "wjets");
  set_style(hother, "other");
  set_style(hsingle_top, "single_top");

  // Setup auxiliary histograms (ratios, errors, etc)
  TH1D * staterr = (TH1D *) hmc_exp->Clone("staterr");
  staterr->Sumw2();
  //staterr->SetFillColor(kRed);
  staterr->SetFillColor(kGray+3);
  staterr->SetMarkerSize(0);
  staterr->SetFillStyle(3013);

 
  // Setup legends
  TLegend * leg1 = new TLegend(0.48, 0.6, 0.72, 0.92);
  set_style(leg1,0.025);
  if (plotData) leg1->AddEntry(hsingle_top, "Data", "pel");
  if (plotSig) {
    leg1->AddEntry(ht1bbbb_1500_100, "#splitline{T1bbbb}{(1500,100) GeV}", "l");
    leg1->AddEntry(ht1bbbb_1000_900, "#splitline{T1bbbb}{(1000,900) GeV}", "l");
    leg1->AddEntry(ht1tttt_1500_100, "#splitline{T1tttt}{(1500,100) GeV}", "l");
    leg1->AddEntry(ht1tttt_1200_800, "#splitline{T1tttt}{(1200,800) GeV}", "l");
    leg1->AddEntry(ht1qqqq_1400_100, "#splitline{T1qqqq}{(1400,100) GeV}", "l");
    leg1->AddEntry(ht1qqqq_1000_800, "#splitline{T1qqqq}{(1000,800) GeV}", "l");
  }
 

  TLegend * leg2 = new TLegend(0.72, 0.6, 0.94, 0.92);
  set_style(leg2,0.025);
  if (httbar->Integral()>hqcd->Integral()) {
    leg2->AddEntry(httbar, "t#bar{t}", "f");
    leg2->AddEntry(hqcd, "QCD", "f");
  } else {
    leg2->AddEntry(hqcd, "QCD", "f");
    leg2->AddEntry(httbar, "t#bar{t}", "f");
  }
  leg2->AddEntry(hznn, "Z+jets", "f");
  leg2->AddEntry(hwjets, "W+jets", "f");
  leg2->AddEntry(hsingle_top, "Single Top", "f");
  leg2->AddEntry(hother, "Other", "f");
  leg2->AddEntry(staterr, "MC uncert.", "f");
    
  double ymax = hs->GetMaximum();
  if (ht1tttt_1500_100->GetMaximum()>ymax) ymax=ht1tttt_1500_100->GetMaximum();
  if (ht1bbbb_1500_100->GetMaximum()>ymax) ymax=ht1bbbb_1500_100->GetMaximum();
  if (ht1qqqq_1400_100->GetMaximum()>ymax) ymax=ht1qqqq_1400_100->GetMaximum();


  if(plotLog) {
    hs->SetMaximum(200*ymax);
    hs->SetMinimum(0.1);
  }
  else {
    hs->SetMaximum(2*ymax);
    if (plot_title.Contains("baseline")) hs->SetMaximum(1.3*ymax);
  }
  // Vertical lines for cuts
  TLine* line_low = new TLine(cut_low,0,cut_low,1.5*ymax);
  TLine* line_high = new TLine(cut_high,0,cut_high,1.5*ymax);
  set_style(line_low);
  set_style(line_high);

  // Setup canvas and pads  
  TCanvas * c1 = new TCanvas("c1", "c1", 700, 700);
  TPad * pad1 = new TPad("pad1", "top pad" , 0.0, 0.3, 1.0, 1.0);
  TPad * pad2 = new TPad("pad2", "bottom pad", 0.0, 0.0, 1.0, 0.3);
  if(plotData) {
    pad1->SetBottomMargin(0.0);
    pad1->Draw();
    pad2->SetTopMargin(0.0);
    pad2->SetBottomMargin(0.35);
    pad2->Draw();
    pad1->cd();
    pad1->SetLogy(plotLog);
  }
  else {
    c1->cd();
    c1->SetLogy(plotLog);
  }
  // Draw hists
  hs->Draw("hist");
  hs->SetTitle(hmc_exp->GetTitle());
  hs->GetXaxis()->SetTitle(httbar->GetXaxis()->GetTitle());
  hs->GetYaxis()->SetTitle(ytitle);
  hs->GetXaxis()->SetLabelSize(0.03);
  hs->GetYaxis()->SetLabelSize(0.03);
  if (plotData) 
    {
      //  hsingle_top->Draw("e1 same");
      hs->GetXaxis()->SetLabelSize(0);
    }
  staterr->Draw("e2 same");
  if (plotSig) {
    ht1bbbb_1500_100->SetLineColor(2);
    ht1bbbb_1500_100->SetLineWidth(4);
    ht1bbbb_1500_100->SetFillColor(0);
    ht1bbbb_1000_900->SetLineColor(2);
    ht1bbbb_1000_900->SetLineWidth(4);
    ht1bbbb_1000_900->SetLineStyle(7);
    ht1bbbb_1000_900->SetFillColor(0);
    ht1tttt_1500_100->SetLineColor(kGreen);
    ht1tttt_1500_100->SetLineWidth(4);
    ht1tttt_1500_100->SetFillColor(0);
    ht1tttt_1200_800->SetLineColor(kGreen);
    ht1tttt_1200_800->SetLineStyle(7);
    ht1tttt_1200_800->SetLineWidth(4);
    ht1tttt_1200_800->SetFillColor(0);
    ht1qqqq_1400_100->SetLineColor(1006);
    ht1qqqq_1400_100->SetLineWidth(4);
    ht1qqqq_1400_100->SetFillColor(0);
    ht1qqqq_1000_800->SetLineColor(1006);
    ht1qqqq_1000_800->SetLineWidth(4);
    ht1qqqq_1000_800->SetLineStyle(7);
    ht1qqqq_1000_800->SetFillColor(0);
    ht1bbbb_1500_100->Draw("hist same");
    ht1bbbb_1000_900->Draw("hist same");
    ht1tttt_1500_100->Draw("hist same");
    ht1tttt_1200_800->Draw("hist same");
    ht1qqqq_1400_100->Draw("hist same");
    ht1qqqq_1000_800->Draw("hist same");
  }
  if (cut_low>0) line_low->Draw("same");
  if (cut_high>0) line_high->Draw("same");


  // Draw legends
  leg1->Draw();
  leg2->Draw();
  TLatex * latex = new TLatex();
  latex->SetNDC();
  latex->SetTextAlign(12);
  latex->SetTextFont(62);
  latex->SetTextSize(0.042);
  latex->DrawLatex(0.19, 0.89, "CMS Simulation");
  latex->SetTextSize(0.03);
  latex->DrawLatex(0.19, 0.84, "#sqrt{s} = 13 TeV, L = 4 fb^{-1}");
  
  // Print
  cout << "MakePlots(): Printing..." << endl;

  c1->cd();
  if (plot_title.EqualTo("default")) plot_title=plotdir+var;
  gPad->Print(plotdir+plot_title+".pdf");


  // Clean up
  delete staterr;
  delete leg1;
  delete leg2;
  delete latex;
  // delete pave;
  delete hs;
  delete pad1;
  delete pad2;
  delete c1;

  delete httbar;
  delete hqcd;
  delete hznn;
  delete hwjets;
  delete hsingle_top;
  delete hother;
  delete hmc_exp;

  delete ht1bbbb_1500_100;
  delete ht1bbbb_1000_900;
  delete ht1tttt_1500_100;
  delete ht1tttt_1200_800;
  delete ht1qqqq_1400_100;
  delete ht1qqqq_1000_800;

  cout << "MakePlots(): DONE!" << endl;

  return;
}
Esempio n. 11
0
void sanityChecker_babies(){

  int rebin = 1 ;
  char* version = (char*) "V00-00-11";

  //-------------------------------
  // choose config/PU scenario
  //-------------------------------

  //  char* phase = (char*) "PhaseI";
  char* phase = (char*) "PhaseII";

  //  char* config = (char*) "Configuration0";
  //  char* config = (char*) "Conf4";
  char* config = (char*) "";

  //  char* PU = (char*) "NoPileUp";
  //char* PU = (char*) "40PileUp";
  //  char* PU = (char*) "140PileUp";
  char* PU = (char*) "140PU";

  // //-------------------------------
  // // diboson filenames and labels
  // //-------------------------------

  // const unsigned int n = 5;

  // char* names[n] = {Form("BB-4p-0-300-v1510_14TEV_%s_%s_%s"       , phase , config , PU ) ,
  // 		    Form("BB-4p-300-700-v1510_14TEV_%s_%s_%s"     , phase , config , PU ) ,
  // 		    Form("BB-4p-700-1300-v1510_14TEV_%s_%s_%s"    , phase , config , PU ) ,
  // 		    Form("BB-4p-1300-2100-v1510_14TEV_%s_%s_%s"   , phase , config , PU ) ,
  // 		    Form("BB-4p-2100-100000_14TEV_%s_%s_%s"       , phase , config , PU )  
  // };

  // char* labels[n] = {"S*_{T} < 0.3 TeV",
  // 		     "S*_{T} 0.3-0.7 TeV",
  // 		     "S*_{T} 0.7-1.3 TeV",
  // 		     "S*_{T} 1.3-2.1 TeV",
  // 		     "S*_{T} > 2.1 TeV"};

  // char* filename = "plots/BB-ST.pdf";


  //  -------------------------------
  //  boson+jets filenames and labels
  //  -------------------------------

  const unsigned int n = 7;

  char* names[n] = {Form("Bj-4p-0-300-v1510_14TEV_%s_%s_%s"       , phase , config , PU ) ,
  		    Form("Bj-4p-300-600-v1510_14TEV_%s_%s_%s"     , phase , config , PU ) ,
  		    Form("Bj-4p-600-1100-v1510_14TEV_%s_%s_%s"    , phase , config , PU ) ,
  		    Form("Bj-4p-1100-1800-v1510_14TEV_%s_%s_%s"   , phase , config , PU ) ,
  		    Form("Bj-4p-1800-2700-v1510_14TEV_%s_%s_%s"   , phase , config , PU ) ,
  		    Form("Bj-4p-2700-3700-v1510_14TEV_%s_%s_%s"   , phase , config , PU ) ,
  		    Form("Bj-4p-3700-100000-v1510_14TEV_%s_%s_%s" , phase , config , PU ) 
  };
 
  char* labels[n] = {"S*_{T} < 0.3 TeV",
  		     "S*_{T} 0.3-0.6 TeV",
  		     "S*_{T} 0.6-1.1 TeV",
  		     "S*_{T} 1.1-1.8 TeV",
  		     "S*_{T} 1.8-2.7 TeV",
  		     "S*_{T} 2.7-3.7 TeV",
  		     "S*_{T} > 3.7 TeV"};

  char* filename = "plots/Bj-ST.pdf";


  // //-------------------------------
  // // ttbar filenames and labels
  // //-------------------------------

  // const unsigned int n = 5;

  // char* names[n] = {Form("tt-4p-0-600-v1510_14TEV_%s_%s_%s"       , phase , config , PU ) ,
  // 		    Form("tt-4p-600-1100-v1510_14TEV_%s_%s_%s"    , phase , config , PU ) ,
  // 		    Form("tt-4p-1100-1700-v1510_14TEV_%s_%s_%s"   , phase , config , PU ) ,
  // 		    Form("tt-4p-1700-2500-v1510_14TEV_%s_%s_%s"   , phase , config , PU ) ,
  // 		    Form("tt-4p-2500-100000-v1510_14TEV_%s_%s_%s" , phase , config , PU )
  // };

  // char* labels[n] = {"S*_{T} < 0.6 TeV",
  // 		     "S*_{T} 0.6-1.1 TeV",
  // 		     "S*_{T} 1.1-1.7 TeV",
  // 		     "S*_{T} 1.7-2.5 TeV",
  // 		     "S*_{T} > 2.5 TeV"
  // };

  // char* filename = "plots/tt-ST.pdf";


  // //-------------------------------
  // // single top filenames and labels
  // //-------------------------------

  // const unsigned int n = 5;

  // char* names[n] = {Form("tj-4p-0-500-v1510_14TEV_%s_%s_%s"       , phase , config , PU ) ,
  // 		    Form("tj-4p-500-1000-v1510_14TEV_%s_%s_%s"    , phase , config , PU ) ,
  // 		    Form("tj-4p-1000-1600-v1510_14TEV_%s_%s_%s"   , phase , config , PU ) ,
  // 		    Form("tj-4p-1600-2400-v1510_14TEV_%s_%s_%s"   , phase , config , PU ) ,
  // 		    Form("tj-4p-2400-100000-v1510_14TEV_%s_%s_%s" , phase , config , PU )  
  // };

  // char* labels[n] = {"S*_{T} < 0.5 TeV",
  // 		     "S*_{T} 0.5-1.0 TeV",
  // 		     "S*_{T} 1.0-1.6 TeV",
  // 		     "S*_{T} 1.6-2.4 TeV",
  // 		     "S*_{T} > 2.4 TeV"
  // };

  // char* filename = "plots/tj-ST.pdf";

  // //-------------------------------
  // // tW filenames and labels
  // //-------------------------------

  // const unsigned int n = 5;

  // char* names[n] = {Form("tB-4p-0-500-v1510_14TEV_%s_%s_%s"       , phase , config , PU ) ,
  // 		    Form("tB-4p-500-900-v1510_14TEV_%s_%s_%s"     , phase , config , PU ) ,
  // 		    Form("tB-4p-900-1500-v1510_14TEV_%s_%s_%s"    , phase , config , PU ) ,
  // 		    Form("tB-4p-1500-2200-v1510_14TEV_%s_%s_%s"   , phase , config , PU ) ,
  // 		    Form("tB-4p-2200-100000-v1510_14TEV_%s_%s_%s" , phase , config , PU )  
  // };

  // char* labels[n] = {"S*_{T} < 0.5 TeV",
  // 		     "S*_{T} 0.5-0.9 TeV",
  // 		     "S*_{T} 0.9-1.5 TeV",
  // 		     "S*_{T} 1.5-2.2 TeV",
  // 		     "S*_{T} > 2.2 TeV"
  // };

  // char* filename = "plots/tB-ST.pdf";

  //--------------------------------------------
  // NO NEED TO MODIFY ANYTHING BELOW HERE
  //--------------------------------------------

  TChain* chains[n];
  //TFile* files[n];

  int   colors[7] = { 2 , 3 , 4 , 5 , 6 , 7 , 8 };

  // need double precision here for largest samples!! 
  TH1D* hst[n];
  TH1D* hstlo[n];

  THStack* htstack = new THStack();

  TLegend *leg = new TLegend(0.5,0.5,0.8,0.8);

  cout << endl << endl;
  cout << "Printing out yields in 1/fb using cross sections from:" << endl;
  cout << "https://twiki.cern.ch/twiki/bin/viewauth/CMS/HiggsWG/Phase2UpgradeStudies#Background_samples" << endl;
  cout << "The unweighted yields should match the cross sections on this page (X1000)." << endl;
  cout << "The weighted yields have the additional Event.Weight applied." << endl;

  for( int i = 0 ; i < n ; i++ ){

    chains[i] = new TChain("t");
    chains[i]->Add(Form("output/%s/%s_baby.root",version,names[i]));

    hst[i]   = new TH1D("hst"  ,"weighted S_{T} [GeV]",100,0,10000);
    hstlo[i] = new TH1D("hstlo","unweighted S_{T} [GeV]",100,0,10000);

    chains[i]->Draw("st>>hst"  ,"weight*genweight");
    chains[i]->Draw("st>>hstlo","weight");

    hst[i]->SetFillColor(colors[i]);
    hst[i]->Rebin(rebin);
    hst[i]->SetMinimum(1);

    cout << endl;
    cout << "1 pb yields for sample " << names[i] << endl;
    cout << "Unweighted yield  " << hstlo[i]->Integral() << endl;
    cout << "Weighted yield    " << hst[i]->Integral() << endl;

    hst[i]->GetXaxis()->SetTitle("S_{T} [GeV]");
    hst[i]->GetYaxis()->SetTitle("events");

    leg->AddEntry( hst[i] , labels[i] , "lf" );

    htstack->Add(hst[i]);
  }

  TCanvas *c2 = new TCanvas("c2","c2",1200,600);
  c2->cd();
  gStyle->SetOptStat(0);

  gPad->SetLogy();
  htstack->Draw();
  htstack->GetXaxis()->SetTitle("S_{T} [GeV]");
  htstack->GetYaxis()->SetTitle("events");

  TLatex *t = new TLatex();
  t->SetNDC();
  t->DrawLatex(0.5,0.85,"14 TeV, L = 1 pb^{-1}");

  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  leg->Draw();

}
void MFVFlatNtupleReader::genHists(std::string target)
{
  //   In a ROOT session, you can do:
  //      Root > .L MFVFlatNtupleReader.C
  //      Root > MFVFlatNtupleReader t
  //      Root > t.GetEntry(12); // Fill t data members with entry number 12
  //      Root > t.Show();       // Show values of entry 12
  //      Root > t.Show(16);     // Read and show values of entry 16
  //      Root > t.Loop();       // Loop on all entries
  //

  //     This is the loop skeleton where:
  //    jentry is the global entry number in the chain
  //    ientry is the entry number in the current Tree
  //  Note that the argument to GetEntry must be:
  //    jentry for TChain::GetEntry
  //    ientry for TTree::GetEntry and TBranch::GetEntry
  //
  //       To read only selected branches, Insert statements like:
  // METHOD1:
  //    fChain->SetBranchStatus("*",0);  // disable all branches
  //    fChain->SetBranchStatus("branchname",1);  // activate branchname
  // METHOD2: replace line
  //    fChain->GetEntry(jentry);       //read all branches
  //by  b_branchname->GetEntry(ientry); //read only this branch
  if (fChain == 0) return;
  
  //set up the program for a specific target
  std::vector<unsigned char> *loc;
  loc = 0;
  if (target == "vtx_ntracks") fChain->SetBranchAddress("vtx_ntracks", &loc, &b_vtx_ntracks);
  else if (target == "vtx_ntracksptgt3") fChain->SetBranchAddress("vtx_ntracksptgt3",&loc,&b_vtx_ntracksptgt3);
  else if (target == "vtx_ntracksptgt5") fChain->SetBranchAddress("vtx_ntracksptgt5",&loc,&b_vtx_ntracksptgt5);
  else if (target == "vtx_ntracksptgt10") fChain->SetBranchAddress("vtx_ntracksptgt10",&loc,&b_vtx_ntracksptgt10);
  else if (target == "vtx_sumnhitsbehind") fChain->SetBranchAddress("vtx_sumnhitsbehind",&loc,&b_vtx_sumnhitsbehind);
  else if (target == "vtx_njets") fChain->SetBranchAddress("vtx_njets",&loc,&b_vtx_njets);
  else if (target == "vtx_nmu") fChain->SetBranchAddress("vtx_nmu",&loc,&b_vtx_nmu);
  else if (target == "vtx_nel") fChain->SetBranchAddress("vtx_nel",&loc,&b_vtx_nel);
  else if (target == "vtx_maxnhitsbehind") fChain->SetBranchAddress("vtx_maxnhitsbehind",&loc,&b_vtx_sumnhitsbehind);

  //set up the histograms to desired specifications
  int nbins = 26;
  h_tot = new TH1F("h_tot"," After Cut (Total)",nbins,-0.5,nbins-0.5);
  h_back = new TH1F("h_back"," After Cut (Background)",nbins,-0.5,nbins-0.5);
  h_sig = new TH1F("h_sig"," After Cut (Signal)",nbins,-0.5,nbins-0.5);
  
  enum {
    s_start = -3,
    s_mfv_neutralino_tau0100um_M0400 = -3,
    s_mfv_neutralino_tau1000um_M0400,
    s_mfv_neutralino_tau0300um_M0400,
    s_mfv_neutralino_tau9900um_M0400,
    s_ttbarhadronic,
    s_ttbarsemilep,
    s_ttbardilep,
    s_qcdht0100,
    s_qcdht0250,
    s_qcdht0500,
    s_qcdht1000,
    s_end
  };

  std::map<int, std::string> sample_names;
  sample_names[s_mfv_neutralino_tau0100um_M0400] = "mfv_neutralino_tau0100um_M0400";
  sample_names[s_mfv_neutralino_tau0300um_M0400] = "mfv_neutralino_tau0300um_M0400";
  sample_names[s_mfv_neutralino_tau1000um_M0400] = "mfv_neutralino_tau1000um_M0400";
  sample_names[s_mfv_neutralino_tau9900um_M0400] = "mfv_neutralino_tau9900um_M0400";
  sample_names[s_ttbarhadronic] = "ttbarhadronic";
  sample_names[s_ttbarsemilep] = "ttbarsemilep";
  sample_names[s_ttbardilep] = "ttbardilep";
  sample_names[s_qcdht0100] = "qcdht0100";
  sample_names[s_qcdht0250] = "qcdht0250";
  sample_names[s_qcdht0500] = "qcdht0500";
  sample_names[s_qcdht1000] = "qcdht1000";

  std::map<int, int> sample_nevents_read;
  
    
  Long64_t nentries = fChain->GetEntries();
  for (Long64_t jentry=0; jentry<nentries;jentry++) {
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    fChain->GetEntry(jentry);

    if (jentry % 1000 == 0) {
      printf("\r%lli/%lli events read", jentry, nentries);
      fflush(stdout);
    }
    //std::cout << std::endl << b_vtx_sumnhitsbehind->GetEntry(jentry) << std::endl;
    
    int numverts = nvertices;
    int numgoodverts = 0;
        //std::cout << "numverts = " << numverts  << std::endl;
    for (int i = 0; i < numverts; ++i) {
      if (MFVFlatNtupleReader::goodVertex(i)) {
	++(numgoodverts);
	//std::cout << "good vertex detected" << std::endl;
      }
    }
    
    //std::cout << numgoodverts << std::endl;
    if (numgoodverts >= 1) {
      ++sample_nevents_read[sample];
      for (int i = 0; i < nvertices; ++i) { //fill with everything
	h_tot->Fill((int)(*loc)[i]);
	  }
      if (sample >= 0) { //fill with background
	for (int i = 0; i < nvertices; ++i) {
	  h_back->Fill((int)(*loc)[i]);
	}                                                       //ERRORS TO BE FIXED HERE: MAP STRINGS AND POINTERS!!!
      }
      else { //fill with signal
	for (int i = 0; i < nvertices; ++i) {
	  h_sig->Fill((int)(*loc)[i]);
	  }
      }
    }
  }

  printf("\r%80s\rdone!\n", "");

  for (int s = s_start; s < s_end; ++s)
    printf("sample %30s events read: %10i\n", sample_names[s].c_str(), sample_nevents_read[s]);

  gStyle->SetCanvasPreferGL(1);
  //now we set up the canvas and histogram details so we can draw them
  string title_str = target + " of Lepton-Producing Events";
  const char * title = new char[sizeof title_str];
  title = title_str.c_str();
  const char * xaxis = target.c_str();

  TCanvas *c1 = new TCanvas("c1",title,900,600);
  c1->SetBorderMode(0);
  c1->SetFillColor(kWhite);
  //c1->SetLogy();
  
  THStack *hs = new THStack("hs",title);
  h_tot->SetLineColor(kGreen);
  h_tot->SetFillStyle(4050);
  h_tot->SetLineWidth(2);
  hs->Add(h_tot);

  h_back->SetLineColor(kBlue);
  h_back->SetFillStyle(4050);
  h_back->SetLineWidth(2);
  hs->Add(h_back);

  h_sig->SetLineColor(kRed);
  h_sig->SetFillStyle(4010);
  h_sig->SetLineWidth(2);
  hs->Add(h_sig);
  
  //h_tot->Draw();
  //h_back->Draw("same");
  //h_sig->Draw("same");
  hs->Draw("nostack");
  hs->GetXaxis()->SetTitle(xaxis);
  hs->GetYaxis()->SetTitle("number of vertices");
  hs->GetYaxis()->SetTitleOffset(1.4);
  
  TLegend *leg = new TLegend(0.7,0.7,0.9,0.9);
  leg->SetHeader("Type of Data");
  leg->AddEntry(h_tot,"Total");
  leg->AddEntry(h_back,"Background");
  leg->AddEntry(h_sig,"Signal");
  leg->Draw();

  c1->Modified();
  
  //data to be printed to the command line
  vector<int> entries_in_bins_tot;
  vector<int> entries_in_bins_back;
  vector<int> entries_in_bins_sig;
  for (int i = 1; i <= nbins; ++i)  {
    entries_in_bins_tot.push_back(h_tot->GetBinContent(i));
    entries_in_bins_back.push_back(h_back->GetBinContent(i));
    entries_in_bins_sig.push_back(h_sig->GetBinContent(i));
  }
  
  std::cout << std::endl << "Total: " << std::endl;
  for (int i = 0; i < nbins; ++i) {
    std::cout << "bin " << i+1 <<  ": " << entries_in_bins_tot[i] << " entries" << std::endl;
  }

  std::cout << std::endl << "Background: " << std::endl;
  for (int i = 0; i < nbins; ++i) {
    std::cout << "bin " << i+1 << ": " << entries_in_bins_back[i] << " entries" << std::endl;
  }

  std::cout << std::endl << "Signal: " << std::endl;
  for (int i = 0; i < nbins; ++i) {
    std::cout << "bin " << i+1 << ": " << entries_in_bins_sig[i] <<  " entries" << std::endl;
  }
  std::cout << std::endl;
}
Esempio n. 13
0
void browseStacks( bool makePictures=false, bool wait=true , bool addHistName = false, Double_t maxYScaleF = 1., 
                  bool logScale = false, bool setMinZero = true) {


  gStyle->SetOptTitle(0);

  bool keep2D=false;

  //fix the hNJet histos
  TList *list = gDirectory->GetList();
  TIterator *iter = list->MakeIterator();
  TObject *obj = 0;
  while(obj = iter->Next()) {
  
    if(TString(obj->GetName()).Contains("hnJet") && obj->InheritsFrom(TH1::Class())) {
      
      int nbins = ((TH1F*)obj)->GetNbinsX();
      float overflow = ((TH1F*)obj)->GetBinContent(nbins+1);
      float lastbinval = ((TH1F*)obj)->GetBinContent(nbins);
      ((TH1F*)obj)->SetBinContent(nbins, overflow+lastbinval);
      ((TH1F*)obj)->GetXaxis()->SetBinLabel(nbins, "#geq4");
    }
  }
  
    
    
    
  // Find out what the names of the existing histograms are
  // The histogram names are XX_YY_ZZ, where XX is the sample,
  // eg, "tt", YY is the actual name, ZZ is the final state, eg, "ee"
  TObjArray* myNames = getMyHistosNames("ttdil","ee",keep2D);
    

  // Now loop over histograms, and make stacks
  TCanvas *c = new TCanvas();
  c->Divide(2,2);
  char* suffix[4];
  suffix[0] = "ee";
  suffix[1] = "mm";
  suffix[2] = "em";
  suffix[3] = "all";
  if (makePictures) c->Print("out/stacks.ps[");
  for (int i=0; i<myNames->GetEntries(); i++) {
     
    for (int sample=0; sample<4; sample++) {
       
       
      hist::stack(Form("st_%s_%s",myNames->At(i)->GetName(),suffix[sample]),
		  Form("%s_%s$",myNames->At(i)->GetName(), suffix[sample]));
      THStack* thisStack = (THStack*) gROOT->FindObjectAny(
							   Form("st_%s_%s", myNames->At(i)->GetName(), suffix[sample]));
       
      thisStack->SetMaximum(thisStack->GetMaximum()*maxYScaleF);
      if(TString(myNames->At(i)->GetName()).Contains("hnJet")) {
	TList* histolist = thisStack->GetHists();
	int hatchcount = 0;
	// 	for(int j = 0; j<histolist->GetSize();j++) {
	// 	  if(TString(histolist->At(j)->GetName()).Contains("tt") ||
	// 	     TString(histolist->At(j)->GetName()).Contains("tautau") ||
	// 	     TString(histolist->At(j)->GetName()).Contains("ww") ) continue;
	// 	  hatch(histolist->At(j)->GetName(), FavoriteHatches[hatchcount]);
	// 	  hatchcount++;
	// 	}
      }
	 
	 
      TLegend* thisLeg = hist::legend(thisStack, "lpf", 0, 0, 0.75, 0.65, 0.99, 0.99);
      c->cd(sample+1);
      if (logScale) gPad->SetLogy(); else gPad->SetLogy(0);
      double stackMax = ((TH1*)thisStack->GetHists()->At(0))->GetMaximum();
      double stackMin = ((TH1*)thisStack->GetHists()->At(0))->GetMinimum();
      thisStack->SetMinimum(stackMin);
      if (setMinZero) thisStack->SetMinimum(0);
      if (logScale && stackMin <=0) thisStack->SetMinimum(1e-2*stackMax);
      if (logScale && stackMax == 0) thisStack->SetMinimum(1e-12); 
      thisStack->Draw("hist");
      string xtitle( ((TH1*)gROOT->FindObjectAny(Form("ttdil_%s_%s", myNames->At(i)->GetName(), suffix[sample])))->GetXaxis()->GetTitle());
      string ytitle( ((TH1*)gROOT->FindObjectAny(Form("ttdil_%s_%s", myNames->At(i)->GetName(), suffix[sample])))->GetYaxis()->GetTitle());
      thisStack->GetXaxis()->SetTitle(xtitle.c_str());
      thisStack->GetYaxis()->SetTitle(ytitle.c_str());
      TString hname = thisStack->GetName();
      if(hname.Contains("hnJet")) {
	thisStack->GetXaxis()->SetLabelSize(0.075);
	thisStack->GetYaxis()->SetLabelSize(0.05);
	thisStack->GetXaxis()->SetTitle("N_{jets}");
      }
      thisLeg->Draw();
	
      TPaveText *pt1 = new TPaveText(0.1, 0.95, 0.4, 0.999, "brNDC");
      pt1->SetName("pt1name");
      pt1->SetBorderSize(0);
      pt1->SetFillStyle(0);
	
      TText *blah;
      if (addHistName) blah = pt1->AddText(hname);
      else blah = pt1->AddText("CMS Preliminary");
      blah->SetTextSize(0.05);
      pt1->Draw();
      c->Modified();
	
      c->Update();
    }
    if (makePictures) {
      c->Print("out/stacks.ps");
      //       c->Print(Form("out/stacks_%d.png",i+1));
      //c->Print(Form("out/stacks_%s.png",myNames->At(i)->GetName()));
      c->Print(Form("out/stacks_%s.eps",myNames->At(i)->GetName()));
    }
    if (wait) {
      cout << "Enter carriage return for the next set of plots....q to quit" << endl;
      char in = getchar();
      if (in == 'q') break;
    }
  }
  if (makePictures) c->Print("out/stacks.ps]");
}
Esempio n. 14
0
TH1D *H1DConvolution( TH1D *htf , TH1D *htct , Double_t Cend , int tid) { 
      
   //------------>Both input histograms should have the same bin width<-----------------
   
   //Here you can apply an extra LPFiltering
   //if (Cend!=0) htct = LPFilter( htct , Cend ); 

   //Convolute (commutative)
   //C(t) = Int[ tct(x) transferfunction(t-x) dx ]
   Double_t bw = htct->GetBinCenter(2) - htct->GetBinCenter(1);
   //Double_t bw = htct->GetXaxis()->GetBinCenter(2) - htct->GetXaxis()->GetBinCenter(1);
   //TF1 *f1 = new TF1("f1","abs(sin(x)/x)*sqrt(x)",0,10);
   //   float r = f1->GetRandom();
    TString tftit, tfname;
    tftit.Form("hConv_%d_%d", tid, count);
    tfname.Form("conv_%d_%d", tid, count);
   TH1D *hConv = new TH1D(tftit,tfname,2*htct->GetNbinsX(),-htct->GetNbinsX()*bw,htct->GetNbinsX()*bw);
   
   
   //The convoluted response to the TCT signal is going to be another histogram sized similar to htct
   Int_t Ntf = htf->GetNbinsX() , Ntct = htct->GetNbinsX();
   
   //Create the reverse histogram of the transfer function
   TH1D *hinv = (TH1D *) htf->Clone(); hinv->Reset();
   for (Int_t j=1; j<= Ntf ; j++) hinv->SetBinContent( j , htf->GetBinContent(Ntf-j+1) );  
  // std::basic_string<char> t= std::to_string(tid);
   TH1D *hg = (TH1D *) htct->Clone(); 
   
   hinv->Draw();
   #if CTRLPLOT == 1
   gPad->Print( "hgcontrol.pdf[" ) ; gPad->Print( "hgcontrol.pdf" );
   #endif
   
   for ( Int_t i=1 ; i<=2*Ntct ; i++ ) { 
          
     //Create a shifted histogram version of the inverse
     hg->Reset();
     //for (Int_t j=TMath::Nint(-0.5*Ntf); j<= TMath::Nint(0.5*Ntf) ; j++) hg->SetBinContent( i-j , hinv->GetBinContent( j+TMath::Nint(0.5*Ntf) ) );  
     if ( i<=Ntf ) {
       //Histogram is shifting in from the left
       for (Int_t j=1; j<=i ; j++) hg->SetBinContent( j , hinv->GetBinContent( Ntf-i+j ) );
     } else {
       //Histogram is shifting out. Leaving from the right
       Int_t cont=1 ;
       for (Int_t j=i-Ntf+1; j<=2*Ntf ; j++) {
         hg->SetBinContent( j , hinv->GetBinContent( cont ) );
	 cont++;
       }
  
     }
     
     
     //Multiply f(tau)*g(t-tau)
     hg->Multiply( htct );
     
     //Double_t fxg = hg->Integral("width");
     Double_t fxg = hg->Integral();
     
     hConv->SetBinContent(i,fxg);
     
     #if CTRLPLOT==1
       THStack *hst=new THStack("hst","conv");
       hConv->SetLineColor(2);hConv->SetLineWidth(2);
       hst->Add(hg) ; hst->Add(hConv);
       hst->Draw("nostack");
       if   (i==2*Ntct) { 
         gPad->Print( "hgcontrol.pdf" )  ; gPad->Print( "hgcontrol.pdf]" ) ; 
       } else if (i%10==0)  gPad->Print( "hgcontrol.pdf" )  ;
     #endif

   }

   gStyle->SetOptStat(0);
   gStyle->SetHistLineWidth(2);
   //hConv->SetLineColor(kRed) ;htct->SetLineColor(kBlack) ;htf->SetLineColor(kBlue) ;
   
   THStack *hs = new THStack();
   //hs->Add(htf);
   hs->Add(htct);
   hs->Add(hConv);
   TCanvas *c1=new TCanvas(); c1->cd();
   hs->Draw("nostack");
   //hs->GetXaxis()->SetRangeUser(-2.,10.);
   hs->GetXaxis()->SetTitle("Time [ns]") ;

   c1->SetGrid(1);

   TLegend* legend = c1->BuildLegend();
   legend->Draw();
   c1->Update();
   //   NOPDF for the moment
//   c1->Print( "convolution.pdf" );
 //too many files...
/*
    tftit.Form("conv_%d_%d.root", tid, count);
   TFile *f=new TFile(tftit,"UPDATE");
   hConv->Write();
   //f->Close();
   delete f;

   #if EXE==1
      tftit.Form("convolution_%d_%d.root", tid, count);
      TFile *fout=new TFile(tftit,"UPDATE");
      htct->Write();
      hConv->Write();
      //fout->Close();
      delete fout;
   #endif
  count++; //for naming purposes
*/

   return hConv;  

}
Esempio n. 15
0
int Plot_tauPt_Stage1_DD() {

  double totalMC =0.0;
  double lumi= 35.865; //20.011 ;  // B->5.882  // C->2.646   D->4.353 ;  // E->4.049 ; F->3.16 ;  G->7.554;  H->5.942  //--inv fb--//

  unsigned long long evt_DYJetsToLL_M50=1;
  unsigned long long evt_DYJetsToLL_M5to50=1;
  unsigned long long evt_TT=1;
 
  TFile *file_DYJetsToLL_M50  = new TFile("../python/crab_projects_March3/crab_DYJetsToLL_M-50_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");             
  double xs_DYJetsToLL_M50=4895000;  //--fb--//                                                                                                                    

  TFile *file_DYJetsToLL_M5to50  = new TFile("../python/crab_projects_March3/crab_DYJetsToLL_M-10to50_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");    
  double xs_DYJetsToLL_M5to50=7160000;  //--fb--//                                                                                                                    

  TFile *file_TT              = new TFile("../python/crab_projects_March3/crab_TT_TuneCUETP8M2T4_13TeV-powheg-pythia8/results/hist.root");
  double xs_TT=730000; //--fb--//
  double kfact_TT= 1.139;

  TFile *file_TT_Mtt_700to1000      = new TFile("../python/crab_projects_March3/crab_TT_Mtt-700to1000_TuneCUETP8M1_13TeV-powheg-pythia8/results/hist.root");
  double xs_TT_Mtt_700to1000=730000; //--fb--//
  double kfact_TT_Mtt_700to1000= 0.0921;

  TFile *file_TT_Mtt_1000toInf              = new TFile("../python/crab_projects_March3/crab_TT_Mtt-1000toInf_TuneCUETP8M1_13TeV-powheg-pythia8/results/hist.root");
  double xs_TT_Mtt_1000toInf=730000; //--fb--//
  double kfact_TT_Mtt_1000toInf= 0.02474;


  //TFile *file_WJetsToLNu      = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/results/hist.root");
  //double xs_WJetsToLNu=60290000; //--fb--//

  TFile *file_WJetsToLNu      = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu= 50690000; //--fb--//
  //
  TFile *file_WToTauNu_M100  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-100_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M100 = 165000; //--fb--//
  double kfact_WToTauNu_M100 = 1.0 ; 
  //
  TFile *file_WToTauNu_M200  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-200_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M200 = 6370; //--fb--//
  double kfact_WToTauNu_M200 = 1.0 ; 
  //
  TFile *file_WToTauNu_M500  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-500_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M500 = 224.0; //--fb--//
  double kfact_WToTauNu_M500 = 1.0 ; 
  //
  TFile *file_WToTauNu_M1000  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-1000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M1000 = 13.7; //--fb--//
  double kfact_WToTauNu_M1000 = 1.0 ; 
  //
  TFile *file_WToTauNu_M2000  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-2000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M2000 = 0.437; //--fb--//
  double kfact_WToTauNu_M2000 = 1.0 ; 
  //
  TFile *file_WToTauNu_M3000  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-3000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M3000 = 0.0342; //--fb--//
  double kfact_WToTauNu_M3000 = 1.0 ; 
  //
  TFile *file_WToTauNu_M4000  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-4000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M4000 = 0.00292; //--fb--//
  double kfact_WToTauNu_M4000 = 1.0 ; 
  //
  TFile *file_WToTauNu_M5000  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-5000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M5000 = 0.000233; //--fb--//
  double kfact_WToTauNu_M5000 = 1.0 ; 
  //
  TFile *file_WToTauNu_M6000  = new TFile("../python/crab_projects_March3/crab_WToTauNu_M-6000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_WToTauNu_M6000 = 0.000015; //--fb--//
  double kfact_WToTauNu_M6000 = 1.0 ; 
  //
  TFile *file_WJetsToLNu_HT100To200  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-100To200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT100To200 = 1345000 ; //--fb--//
  double kfact_WJetsToLNu_HT100To200 = 1.0 ; 

  TFile *file_WJetsToLNu_HT200To400  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-200To400_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT200To400 = 359700 ; //--fb--//
  double kfact_WJetsToLNu_HT200To400 = 1.0 ;

  TFile *file_WJetsToLNu_HT400To600  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-400To600_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT400To600 = 48910 ; //--fb--//
  double kfact_WJetsToLNu_HT400To600 = 1.0 ;

  TFile *file_WJetsToLNu_HT600To800  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-600To800_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT600To800 = 12050 ; //--fb--//
  double kfact_WJetsToLNu_HT600To800 = 1.0 ;

  TFile *file_WJetsToLNu_HT800To1200  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-800To1200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT800To1200 = 5501 ; //--fb--//
  double kfact_WJetsToLNu_HT800To1200 = 1.0 ;

  TFile *file_WJetsToLNu_HT1200To2500  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-1200To2500_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT1200To2500 = 1329 ; //--fb--//
  double kfact_WJetsToLNu_HT1200To2500 = 1.0 ;

  TFile *file_WJetsToLNu_HT2500ToInf  = new TFile("../python/crab_projects_March3/crab_WJetsToLNu_HT-2500ToInf_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/results/hist.root");
  double xs_WJetsToLNu_HT2500ToInf = 32.16  ; //--fb--//
  double kfact_WJetsToLNu_HT2500ToInf = 1.0 ;

  TFile *file_ST_tchannel_antitop=new TFile("../python/crab_projects_March3/crab_ST_t-channel_antitop_4f_inclusiveDecays_TuneCUETP8M2T4_13TeV-powhegV2-madspin/results/hist.root");
  double xs_ST_tchannel_antitop = 80950; //--fb--//
  double kfact_ST_tchannel_antitop = 1.0; //0.326;
  //
  TFile *file_ST_tchannel_top=new TFile("../python/crab_projects_March3/crab_ST_t-channel_top_4f_inclusiveDecays_TuneCUETP8M2T4_13TeV-powhegV2-madspin/results/hist.root");
  double xs_ST_tchannel_top =136020; //103200; //--fb--//
  double kfact_ST_tchannel_top = 1.0; //0.43;
  //
  TFile *file_ST_tW_antitop=new TFile("../python/crab_projects_March3/crab_ST_tW_antitop_5f_inclusiveDecays_13TeV-powheg-pythia8_TuneCUETP8M2T4/results/hist.root");
  double xs_ST_tW_antitop = 38090; //--fb--//
  double kfact_ST_tW_antitop =1.0; // 0.94;
  //
  TFile *file_ST_tW_top=new TFile("../python/crab_projects_March3/crab_ST_tW_top_5f_inclusiveDecays_13TeV-powheg-pythia8_TuneCUETP8M2T4/results/hist.root");
  double xs_ST_tW_top = 38090; //--fb--//
  double kfact_ST_tW_top = 1.0; //0.94;
  //
  TFile *file_WW=new TFile("../python/crab_projects_March3/crab_WW_TuneCUETP8M1_13TeV-pythia8/results/hist.root");
  double xs_WW = 63210; //--fb--//
  //
  TFile *file_WZ=new TFile("../python/crab_projects_March3/crab_WZ_TuneCUETP8M1_13TeV-pythia8/results/hist.root");
  double xs_WZ = 22820; //--fb--//
  double kfact_WZ = 2.06; // 47.13/22.82
  //
  TFile *file_ZZ=new TFile("../python/crab_projects_March3/crab_ZZ_TuneCUETP8M1_13TeV-pythia8/results/hist.root");
  double xs_ZZ = 10320; //--fb--//
  double kfact_ZZ = 1.60 ; //16523/10320
  //
  std::cout << "get datadriven root file" << std::endl;
  TFile *file_Datadriven  = new TFile("/net/scratch_cms3a/materok/wprime/qcd/dataDrivenTree15_pt_base_Mar7_fromData.root");


  /// DATA ///
  TFile *file_Tau_Run2016B = new TFile("../python/crab_projects_March3/crab_Tau_Run2016B/results/hist.root");
  TFile *file_Tau_Run2016C = new TFile("../python/crab_projects_March3/crab_Tau_Run2016C/results/hist.root");
  TFile *file_Tau_Run2016D = new TFile("../python/crab_projects_March3/crab_Tau_Run2016D/results/hist.root");
  TFile *file_Tau_Run2016E = new TFile("../python/crab_projects_March3/crab_Tau_Run2016E/results/hist.root");
  TFile *file_Tau_Run2016F = new TFile("../python/crab_projects_March3/crab_Tau_Run2016F/results/hist.root");
  TFile *file_Tau_Run2016G = new TFile("../python/crab_projects_March3/crab_Tau_Run2016G/results/hist.root");
  TFile *file_Tau_Run2016H_v2 = new TFile("../python/crab_projects_March3/crab_Tau_Run2016H_1/results/hist.root");
  TFile *file_Tau_Run2016H_v3 = new TFile("../python/crab_projects_March3/crab_Tau_Run2016H_2/results/hist.root");


  /// Signal ///
  TFile *file_Wprime_M4000 = new TFile("../python/crab_projects_March3/crab_WprimeToTauNu_M-4000_TuneCUETP8M1_13TeV-pythia8-tauola/results/hist.root");
  double xs_Wprime_M4000= 2.04; // --fb-- //

  //--//
  TH1D* h1_evt_DYJetsToLL_M50 = (TH1D*)file_DYJetsToLL_M50->Get("demo/histoDir/eventCount");
  evt_DYJetsToLL_M50 = h1_evt_DYJetsToLL_M50->GetEntries(); // Integral();
  double wt_DYJetsToLL_M50 = (xs_DYJetsToLL_M50*lumi)/evt_DYJetsToLL_M50 ;
  TH1D* tauPt_Stage1_DYJetsToLL_M50 = (TH1D*)file_DYJetsToLL_M50->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_DYJetsToLL_M50->Scale(wt_DYJetsToLL_M50);
  std::cout << "DYJetsToLL_M50 weighted nevt=" << tauPt_Stage1_DYJetsToLL_M50->Integral() << std::endl;
  totalMC += tauPt_Stage1_DYJetsToLL_M50->Integral();

  TH1D* h1_evt_DYJetsToLL_M5to50 = (TH1D*)file_DYJetsToLL_M5to50->Get("demo/histoDir/eventCount");
  evt_DYJetsToLL_M5to50 = h1_evt_DYJetsToLL_M5to50->GetEntries(); // Integral();
  double wt_DYJetsToLL_M5to50 = (xs_DYJetsToLL_M5to50*lumi)/evt_DYJetsToLL_M5to50 ;
  TH1D* tauPt_Stage1_DYJetsToLL_M5to50 = (TH1D*)file_DYJetsToLL_M5to50->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_DYJetsToLL_M5to50->Scale(wt_DYJetsToLL_M5to50);
  std::cout << "DYJetsToLL_M5to50 weighted nevt=" << tauPt_Stage1_DYJetsToLL_M5to50->Integral() << std::endl;
  totalMC += tauPt_Stage1_DYJetsToLL_M5to50->Integral() ;
  //
  TH1D* total_DY = (TH1D*)tauPt_Stage1_DYJetsToLL_M50->Clone(); 
  total_DY->Add(tauPt_Stage1_DYJetsToLL_M5to50);
  total_DY->SetFillColorAlpha(kRed,0.5);
  total_DY->SetLineColor(kBlack);
  total_DY->Rebin(10);
  //

  TH1D* h1_evt_TT = (TH1D*)file_TT->Get("demo/histoDir/eventCount");
  evt_TT = h1_evt_TT->GetEntries(); // Integral();
  double wt_TT = (xs_TT*lumi)/evt_TT ;
  TH1D* tauPt_Stage1_TT  = (TH1D*)file_TT->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_TT->Scale(wt_TT);
  tauPt_Stage1_TT->Scale(kfact_TT);
  std::cout << "TTbar weighted nevt=" << tauPt_Stage1_TT->Integral() << std::endl;
  totalMC += tauPt_Stage1_TT->Integral();

  //file_TT_Mtt_700to1000
  TH1D* h1_evt_TT_Mtt_700to1000 = (TH1D*)file_TT_Mtt_700to1000->Get("demo/histoDir/eventCount");
  evt_TT_Mtt_700to1000 = h1_evt_TT_Mtt_700to1000->GetEntries(); // Integral();
  double wt_TT_Mtt_700to1000 = (xs_TT_Mtt_700to1000*lumi)/evt_TT_Mtt_700to1000 ;
  TH1D* tauPt_Stage1_TT_Mtt_700to1000  = (TH1D*)file_TT_Mtt_700to1000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_TT_Mtt_700to1000->Scale(wt_TT_Mtt_700to1000);
  tauPt_Stage1_TT_Mtt_700to1000->Scale(kfact_TT_Mtt_700to1000);
  std::cout << "TT_Mtt_700to1000bar weighted nevt=" << tauPt_Stage1_TT_Mtt_700to1000->Integral() << std::endl;
  totalMC += tauPt_Stage1_TT_Mtt_700to1000->Integral() ;

  //file_TT_Mtt_1000toInf
  TH1D* h1_evt_TT_Mtt_1000toInf = (TH1D*)file_TT_Mtt_1000toInf->Get("demo/histoDir/eventCount");
  evt_TT_Mtt_1000toInf = h1_evt_TT_Mtt_1000toInf->GetEntries(); // Integral();
  double wt_TT_Mtt_1000toInf = (xs_TT_Mtt_1000toInf*lumi)/evt_TT_Mtt_1000toInf ;
  TH1D* tauPt_Stage1_TT_Mtt_1000toInf  = (TH1D*)file_TT_Mtt_1000toInf->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_TT_Mtt_1000toInf->Scale(wt_TT_Mtt_1000toInf);
  tauPt_Stage1_TT_Mtt_1000toInf->Scale(kfact_TT_Mtt_1000toInf);
  std::cout << "TT_Mtt_1000toInfbar weighted nevt=" << tauPt_Stage1_TT_Mtt_1000toInf->Integral() << std::endl;
  totalMC += tauPt_Stage1_TT_Mtt_1000toInf->Integral() ;

  TH1D* total_TT = (TH1D*)tauPt_Stage1_TT->Clone(); 
  total_TT->Add(tauPt_Stage1_TT_Mtt_700to1000);
  total_TT->Add(tauPt_Stage1_TT_Mtt_1000toInf);
  total_TT->SetFillColor(kBlue-7);
  total_TT->SetLineColor(kBlack);
  total_TT->Rebin(10);


  /*
  TH1D* h1_evt_WJetsToLNu = (TH1D*)file_WJetsToLNu->Get("demo/histoDir/eventCount");
  evt_WJetsToLNu = h1_evt_WJetsToLNu->GetEntries(); //Integral();
  std::cout << "evt_WJetsToLNu = " << evt_WJetsToLNu << std::endl;
  double wt_WJetsToLNu = (xs_WJetsToLNu*lumi)/evt_WJetsToLNu ;
  TH1D* tauPt_Stage1_WJetsToLNu  = (TH1D*)file_WJetsToLNu->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //
  tauPt_Stage1_WJetsToLNu->Sumw2(kFALSE);
  tauPt_Stage1_WJetsToLNu->SetBinErrorOption(TH1::kPoisson);
  std::cout << "**WJets** unweighted nevt=" << tauPt_Stage1_WJetsToLNu->Integral() << std::endl;
  std::cout << "wt_WJetsToLNu = " << wt_WJetsToLNu << std::endl;
  tauPt_Stage1_WJetsToLNu->Scale(wt_WJetsToLNu);
  tauPt_Stage1_WJetsToLNu->SetFillColorAlpha(kGreen-7,0.5);
  tauPt_Stage1_WJetsToLNu->SetLineColor(kGreen-7);
  tauPt_Stage1_WJetsToLNu->Rebin(40);
  std::cout << "**WJets** weighted nevt=" << tauPt_Stage1_WJetsToLNu->Integral() << std::endl;
  */

  //file_ST_tchannel_antitop
  TH1D* h1_evt_ST_tchannel_antitop = (TH1D*)file_ST_tchannel_antitop->Get("demo/histoDir/eventCount");
  unsigned long long evt_ST_tchannel_antitop = h1_evt_ST_tchannel_antitop->GetEntries(); //Integral();
  double wt_ST_tchannel_antitop = (xs_ST_tchannel_antitop*lumi)/evt_ST_tchannel_antitop ;
  TH1D* tauPt_Stage1_ST_tchannel_antitop  = (TH1D*)file_ST_tchannel_antitop->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_ST_tchannel_antitop->Scale(wt_ST_tchannel_antitop);
  tauPt_Stage1_ST_tchannel_antitop->Scale(kfact_ST_tchannel_antitop);
  std::cout << "ST_tchannel_antitop weighted nevt=" << tauPt_Stage1_ST_tchannel_antitop->Integral() << std::endl;
  totalMC += tauPt_Stage1_ST_tchannel_antitop->Integral();

  //file_ST_tchannel_top
  TH1D* h1_evt_ST_tchannel_top = (TH1D*)file_ST_tchannel_top->Get("demo/histoDir/eventCount");
  unsigned long long evt_ST_tchannel_top = h1_evt_ST_tchannel_top->GetEntries(); //Integral();
  double wt_ST_tchannel_top = (xs_ST_tchannel_top*lumi)/evt_ST_tchannel_top ;
  TH1D* tauPt_Stage1_ST_tchannel_top  = (TH1D*)file_ST_tchannel_top->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_ST_tchannel_top->Scale(wt_ST_tchannel_top);
  tauPt_Stage1_ST_tchannel_top->Scale(kfact_ST_tchannel_top);
  std::cout << "ST_tchannel_top weighted nevt=" << tauPt_Stage1_ST_tchannel_top->Integral() << std::endl;
  totalMC += tauPt_Stage1_ST_tchannel_top->Integral() ;

  //file_ST_tW_antitop
  TH1D* h1_evt_ST_tW_antitop = (TH1D*)file_ST_tW_antitop->Get("demo/histoDir/eventCount");
  unsigned long long evt_ST_tW_antitop = h1_evt_ST_tW_antitop->GetEntries(); //Integral();
  double wt_ST_tW_antitop = (xs_ST_tW_antitop*lumi)/evt_ST_tW_antitop ;
  TH1D* tauPt_Stage1_ST_tW_antitop  = (TH1D*)file_ST_tW_antitop->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_ST_tW_antitop->Scale(wt_ST_tW_antitop);
  tauPt_Stage1_ST_tW_antitop->Scale(kfact_ST_tW_antitop);
  std::cout << "ST_tW_antitop weighted nevt=" << tauPt_Stage1_ST_tW_antitop->Integral() << std::endl;
  totalMC += tauPt_Stage1_ST_tW_antitop->Integral();

  //file_ST_tW_top
  TH1D* h1_evt_ST_tW_top = (TH1D*)file_ST_tW_top->Get("demo/histoDir/eventCount");
  unsigned long long evt_ST_tW_top = h1_evt_ST_tW_top->GetEntries(); //Integral();
  double wt_ST_tW_top = (xs_ST_tW_top*lumi)/evt_ST_tW_top ;
  TH1D* tauPt_Stage1_ST_tW_top  = (TH1D*)file_ST_tW_top->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_ST_tW_top->Scale(wt_ST_tW_top);
  tauPt_Stage1_ST_tW_top->Scale(kfact_ST_tW_top);
  std::cout << "ST_tW_top weighted nevt=" << tauPt_Stage1_ST_tW_top->Integral() << std::endl;
  totalMC += tauPt_Stage1_ST_tW_top->Integral() ;

  TH1D* total_ST = (TH1D*)tauPt_Stage1_ST_tchannel_antitop->Clone(); 
  total_ST->Add(tauPt_Stage1_ST_tchannel_top);
  total_ST->Add(tauPt_Stage1_ST_tW_antitop);
  total_ST->Add(tauPt_Stage1_ST_tW_top);
  total_ST->SetFillColorAlpha(kCyan,0.5);
  total_ST->SetLineColor(kBlack);
  total_ST->Rebin(10);

  //file_WJetsToLNu_HT100To200
  TH1D* h1_evt_WJetsToLNu_HT100To200 = (TH1D*)file_WJetsToLNu_HT100To200->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT100To200 = h1_evt_WJetsToLNu_HT100To200->GetEntries(); //Integral();                                                                 
  double wt_WJetsToLNu_HT100To200 = (xs_WJetsToLNu_HT100To200*lumi)/evt_WJetsToLNu_HT100To200 ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT100To200  = (TH1D*)file_WJetsToLNu_HT100To200->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                           
  //  tauPt_Stage1_WJetsToLNu_HT100To200->Sumw2(kFALSE);
  //tauPt_Stage1_WJetsToLNu_HT100To200->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT100To200->Scale(wt_WJetsToLNu_HT100To200);
  std::cout << "WJetsToLNu_HT100To200 weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT100To200->Integral() << std::endl;
  totalMC += tauPt_Stage1_WJetsToLNu_HT100To200->Integral();
  //tauPt_Stage1_WJetsToLNu_HT100To200->Scale(kfact_WJetsToLNu_HT100To200);
  //  std::cout << tauPt_Stage1_WJetsToLNu_HT100To200->GetBinError(300) << std::endl;

  //file_WJetsToLNu_HT200To400
  TH1D* h1_evt_WJetsToLNu_HT200To400 = (TH1D*)file_WJetsToLNu_HT200To400->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT200To400 = h1_evt_WJetsToLNu_HT200To400->GetEntries(); //Integral();                                                                 
  double wt_WJetsToLNu_HT200To400 = (xs_WJetsToLNu_HT200To400*lumi)/evt_WJetsToLNu_HT200To400 ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT200To400  = (TH1D*)file_WJetsToLNu_HT200To400->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                                                                                                                                                      
  // tauPt_Stage1_WJetsToLNu_HT200To400->Sumw2(kFALSE);
  //tauPt_Stage1_WJetsToLNu_HT200To400->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT200To400->Scale(wt_WJetsToLNu_HT200To400);
 std::cout << "WJetsToLNu_HT200To400 weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT200To400->Integral() << std::endl;
 totalMC += tauPt_Stage1_WJetsToLNu_HT200To400->Integral();
  //tauPt_Stage1_WJetsToLNu_HT200To400->Scale(kfact_WJetsToLNu_HT200To400);
  //std::cout << tauPt_Stage1_WJetsToLNu_HT200To400->GetBinError(300) << std::endl;

  //file_WJetsToLNu_HT400To600
  TH1D* h1_evt_WJetsToLNu_HT400To600 = (TH1D*)file_WJetsToLNu_HT400To600->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT400To600 = h1_evt_WJetsToLNu_HT400To600->GetEntries(); //Integral();                                                                 
  double wt_WJetsToLNu_HT400To600 = (xs_WJetsToLNu_HT400To600*lumi)/evt_WJetsToLNu_HT400To600 ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT400To600  = (TH1D*)file_WJetsToLNu_HT400To600->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                                                                                                                                                      
  // tauPt_Stage1_WJetsToLNu_HT400To600->Sumw2(kFALSE);
  //tauPt_Stage1_WJetsToLNu_HT400To600->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT400To600->Scale(wt_WJetsToLNu_HT400To600);
  std::cout << "WJetsToLNu_HT400To600 weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT400To600->Integral() << std::endl;
  totalMC += tauPt_Stage1_WJetsToLNu_HT400To600->Integral();
  // tauPt_Stage1_WJetsToLNu_HT400To600->Scale(kfact_WJetsToLNu_HT400To600);
  // std::cout << tauPt_Stage1_WJetsToLNu_HT400To600->GetBinError(300) << std::endl;

  //file_WJetsToLNu_HT600To800
  TH1D* h1_evt_WJetsToLNu_HT600To800 = (TH1D*)file_WJetsToLNu_HT600To800->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT600To800 = h1_evt_WJetsToLNu_HT600To800->GetEntries(); //Integral();                                                                 
  double wt_WJetsToLNu_HT600To800 = (xs_WJetsToLNu_HT600To800*lumi)/evt_WJetsToLNu_HT600To800 ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT600To800  = (TH1D*)file_WJetsToLNu_HT600To800->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                                                                                                                                                      
  //  tauPt_Stage1_WJetsToLNu_HT600To800->Sumw2(kFALSE);
  // tauPt_Stage1_WJetsToLNu_HT600To800->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT600To800->Scale(wt_WJetsToLNu_HT600To800);
  std::cout << "WJetsToLNu_HT600To800 weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT600To800->Integral() << std::endl;
  totalMC +=  tauPt_Stage1_WJetsToLNu_HT600To800->Integral();
  // tauPt_Stage1_WJetsToLNu_HT600To800->Scale(kfact_WJetsToLNu_HT600To800);
  // std::cout << tauPt_Stage1_WJetsToLNu_HT600To800->GetBinError(300) << std::endl;

  //file_WJetsToLNu_HT800To1200
  TH1D* h1_evt_WJetsToLNu_HT800To1200 = (TH1D*)file_WJetsToLNu_HT800To1200->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT800To1200 = h1_evt_WJetsToLNu_HT800To1200->GetEntries(); //Integral();                                                                 
  double wt_WJetsToLNu_HT800To1200 = (xs_WJetsToLNu_HT800To1200*lumi)/evt_WJetsToLNu_HT800To1200 ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT800To1200  = (TH1D*)file_WJetsToLNu_HT800To1200->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                                                                                                                                                      
  // tauPt_Stage1_WJetsToLNu_HT800To1200->Sumw2(kFALSE);
  //tauPt_Stage1_WJetsToLNu_HT800To1200->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT800To1200->Scale(wt_WJetsToLNu_HT800To1200);
 std::cout << "WJetsToLNu_HT800To1200 weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT800To1200->Integral() << std::endl;
 totalMC += tauPt_Stage1_WJetsToLNu_HT800To1200->Integral();
  //tauPt_Stage1_WJetsToLNu_HT800To1200->Scale(kfact_WJetsToLNu_HT800To1200);
  // std::cout << tauPt_Stage1_WJetsToLNu_HT800To1200->GetBinError(300) << std::endl;

  //file_WJetsToLNu_HT1200To2500
  TH1D* h1_evt_WJetsToLNu_HT1200To2500 = (TH1D*)file_WJetsToLNu_HT1200To2500->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT1200To2500 = h1_evt_WJetsToLNu_HT1200To2500->GetEntries(); //Integral();                                                             
  double wt_WJetsToLNu_HT1200To2500 = (xs_WJetsToLNu_HT1200To2500*lumi)/evt_WJetsToLNu_HT1200To2500 ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT1200To2500  = (TH1D*)file_WJetsToLNu_HT1200To2500->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                                                                                                                                                      
  // tauPt_Stage1_WJetsToLNu_HT1200To2500->Sumw2(kFALSE);
  //tauPt_Stage1_WJetsToLNu_HT1200To2500->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT1200To2500->Scale(wt_WJetsToLNu_HT1200To2500);
 std::cout << "WJetsToLNu_HT1200To2500 weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT1200To2500->Integral() << std::endl;
 totalMC += tauPt_Stage1_WJetsToLNu_HT1200To2500->Integral();
  // tauPt_Stage1_WJetsToLNu_HT1200To2500->Scale(kfact_WJetsToLNu_HT1200To2500);
  //std::cout << tauPt_Stage1_WJetsToLNu_HT1200To2500->GetBinError(300) << std::endl;

  //file_WJetsToLNu_HT2500ToInf
  TH1D* h1_evt_WJetsToLNu_HT2500ToInf = (TH1D*)file_WJetsToLNu_HT2500ToInf->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu_HT2500ToInf = h1_evt_WJetsToLNu_HT2500ToInf->GetEntries(); //Integral();                                                             
  double wt_WJetsToLNu_HT2500ToInf = (xs_WJetsToLNu_HT2500ToInf*lumi)/evt_WJetsToLNu_HT2500ToInf ;
  TH1D* tauPt_Stage1_WJetsToLNu_HT2500ToInf  = (TH1D*)file_WJetsToLNu_HT2500ToInf->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //                                                                                                                                                      
  //tauPt_Stage1_WJetsToLNu_HT2500ToInf->Sumw2(kFALSE);
  //tauPt_Stage1_WJetsToLNu_HT2500ToInf->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WJetsToLNu_HT2500ToInf->Scale(wt_WJetsToLNu_HT2500ToInf);
 std::cout << "WJetsToLNu_HT2500ToInf weighted nevt=" << tauPt_Stage1_WJetsToLNu_HT2500ToInf->Integral() << std::endl;
 totalMC += tauPt_Stage1_WJetsToLNu_HT2500ToInf->Integral();
  //tauPt_Stage1_WJetsToLNu_HT2500ToInf->Scale(kfact_WJetsToLNu_HT2500ToInf);
  ///std::cout << tauPt_Stage1_WJetsToLNu_HT2500ToInf->GetBinError(300) << std::endl;

  //file_WToTauNu_M100
  TH1D* h1_evt_WToTauNu_M100 = (TH1D*)file_WToTauNu_M100->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M100 = h1_evt_WToTauNu_M100->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M100 = (xs_WToTauNu_M100*lumi)/evt_WToTauNu_M100 ;
  TH1D* tauPt_Stage1_WToTauNu_M100  = (TH1D*)file_WToTauNu_M100->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M100->Scale(wt_WToTauNu_M100);
 std::cout << "WToTauNu_M100 weighted nevt=" << tauPt_Stage1_WToTauNu_M100->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M100->Integral() ;

  //file_WToTauNu_M200
  TH1D* h1_evt_WToTauNu_M200 = (TH1D*)file_WToTauNu_M200->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M200 = h1_evt_WToTauNu_M200->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M200 = (xs_WToTauNu_M200*lumi)/evt_WToTauNu_M200 ;
  TH1D* tauPt_Stage1_WToTauNu_M200  = (TH1D*)file_WToTauNu_M200->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M200->Scale(wt_WToTauNu_M200);
 std::cout << "WToTauNu_M200 weighted nevt=" << tauPt_Stage1_WToTauNu_M200->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M200->Integral();

  //file_WToTauNu_M500
  TH1D* h1_evt_WToTauNu_M500 = (TH1D*)file_WToTauNu_M500->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M500 = h1_evt_WToTauNu_M500->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M500 = (xs_WToTauNu_M500*lumi)/evt_WToTauNu_M500 ;
  TH1D* tauPt_Stage1_WToTauNu_M500  = (TH1D*)file_WToTauNu_M500->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M500->Scale(wt_WToTauNu_M500);
 std::cout << "WToTauNu_M500 weighted nevt=" << tauPt_Stage1_WToTauNu_M500->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M500->Integral() ;

  //file_WToTauNu_M1000
  TH1D* h1_evt_WToTauNu_M1000 = (TH1D*)file_WToTauNu_M1000->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M1000 = h1_evt_WToTauNu_M1000->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M1000 = (xs_WToTauNu_M1000*lumi)/evt_WToTauNu_M1000 ;
  TH1D* tauPt_Stage1_WToTauNu_M1000  = (TH1D*)file_WToTauNu_M1000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M1000->Scale(wt_WToTauNu_M1000);
 std::cout << "WToTauNu_M1000 weighted nevt=" << tauPt_Stage1_WToTauNu_M1000->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M1000->Integral();

  //file_WToTauNu_M2000
  TH1D* h1_evt_WToTauNu_M2000 = (TH1D*)file_WToTauNu_M2000->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M2000 = h1_evt_WToTauNu_M2000->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M2000 = (xs_WToTauNu_M2000*lumi)/evt_WToTauNu_M2000 ;
  TH1D* tauPt_Stage1_WToTauNu_M2000  = (TH1D*)file_WToTauNu_M2000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M2000->Scale(wt_WToTauNu_M2000);
 std::cout << "WToTauNu_M2000 weighted nevt=" << tauPt_Stage1_WToTauNu_M2000->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M2000->Integral();

  //file_WToTauNu_M3000
  TH1D* h1_evt_WToTauNu_M3000 = (TH1D*)file_WToTauNu_M3000->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M3000 = h1_evt_WToTauNu_M3000->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M3000 = (xs_WToTauNu_M3000*lumi)/evt_WToTauNu_M3000 ;
  TH1D* tauPt_Stage1_WToTauNu_M3000  = (TH1D*)file_WToTauNu_M3000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M3000->Scale(wt_WToTauNu_M3000);
 std::cout << "WToTauNu_M3000 weighted nevt=" << tauPt_Stage1_WToTauNu_M3000->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M3000->Integral();

  //file_WToTauNu_M4000
  TH1D* h1_evt_WToTauNu_M4000 = (TH1D*)file_WToTauNu_M4000->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M4000 = h1_evt_WToTauNu_M4000->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M4000 = (xs_WToTauNu_M4000*lumi)/evt_WToTauNu_M4000 ;
  TH1D* tauPt_Stage1_WToTauNu_M4000  = (TH1D*)file_WToTauNu_M4000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M4000->Scale(wt_WToTauNu_M4000);
 std::cout << "WToTauNu_M4000 weighted nevt=" << tauPt_Stage1_WToTauNu_M4000->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M4000->Integral();

  //file_WToTauNu_M5000
  TH1D* h1_evt_WToTauNu_M5000 = (TH1D*)file_WToTauNu_M5000->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M5000 = h1_evt_WToTauNu_M5000->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M5000 = (xs_WToTauNu_M5000*lumi)/evt_WToTauNu_M5000 ;
  TH1D* tauPt_Stage1_WToTauNu_M5000  = (TH1D*)file_WToTauNu_M5000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M5000->Scale(wt_WToTauNu_M5000);
 std::cout << "WToTauNu_M5000 weighted nevt=" << tauPt_Stage1_WToTauNu_M5000->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M5000->Integral();

  //file_WToTauNu_M6000
  TH1D* h1_evt_WToTauNu_M6000 = (TH1D*)file_WToTauNu_M6000->Get("demo/histoDir/eventCount");
  unsigned long long evt_WToTauNu_M6000 = h1_evt_WToTauNu_M6000->GetEntries(); //Integral();                                                             
  double wt_WToTauNu_M6000 = (xs_WToTauNu_M6000*lumi)/evt_WToTauNu_M6000 ;
  TH1D* tauPt_Stage1_WToTauNu_M6000  = (TH1D*)file_WToTauNu_M6000->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WToTauNu_M6000->Scale(wt_WToTauNu_M6000);
 std::cout << "WToTauNu_M6000 weighted nevt=" << tauPt_Stage1_WToTauNu_M6000->Integral() << std::endl;
 totalMC += tauPt_Stage1_WToTauNu_M6000->Integral();

  //file_WJetsToLNu
  TH1D* h1_evt_WJetsToLNu = (TH1D*)file_WJetsToLNu->Get("demo/histoDir/eventCount");
  unsigned long long evt_WJetsToLNu = h1_evt_WJetsToLNu->GetEntries(); //Integral();                                                             
  double wt_WJetsToLNu = (xs_WJetsToLNu*lumi)/evt_WJetsToLNu ;
  TH1D* tauPt_Stage1_WJetsToLNu  = (TH1D*)file_WJetsToLNu->Get("demo/histoDir/tauPt_Stage1");
  tauPt_Stage1_WJetsToLNu->Scale(wt_WJetsToLNu);
 std::cout << "WJetsToLNu weighted nevt=" << tauPt_Stage1_WJetsToLNu->Integral() << std::endl;
 totalMC += tauPt_Stage1_WJetsToLNu->Integral();

  TH1D* total_WJets = (TH1D*)tauPt_Stage1_WJetsToLNu_HT100To200->Clone();
  total_WJets->Add(tauPt_Stage1_WJetsToLNu_HT200To400);
  total_WJets->Add(tauPt_Stage1_WJetsToLNu_HT400To600);
  total_WJets->Add(tauPt_Stage1_WJetsToLNu_HT600To800);
  total_WJets->Add(tauPt_Stage1_WJetsToLNu_HT800To1200);
  total_WJets->Add(tauPt_Stage1_WJetsToLNu_HT1200To2500);
  total_WJets->Add(tauPt_Stage1_WJetsToLNu_HT2500ToInf);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M100);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M200);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M500);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M1000);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M2000);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M3000);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M4000);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M5000);
  total_WJets->Add(tauPt_Stage1_WToTauNu_M6000);
  total_WJets->Add(tauPt_Stage1_WJetsToLNu);
  total_WJets->SetFillColorAlpha(kGreen-8,0.5);
  total_WJets->SetLineColor(kBlack);
  //std::cout << "Wjets " << total_WJets->GetBinError(300) << std::endl;

  total_WJets->Rebin(10);


  //file_WW
  TH1D* h1_evt_WW = (TH1D*)file_WW->Get("demo/histoDir/eventCount");
  unsigned long long evt_WW = h1_evt_WW->GetEntries(); //Integral();                                                                         
  double wt_WW = (xs_WW*lumi)/evt_WW ;
  TH1D* tauPt_Stage1_WW  = (TH1D*)file_WW->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //
  //tauPt_Stage1_WW->Sumw2(kFALSE);
  //tauPt_Stage1_WW->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WW->Scale(wt_WW);
 std::cout << "WW weighted nevt=" << tauPt_Stage1_WW->Integral() << std::endl;
 totalMC +=tauPt_Stage1_WW->Integral() ;

  //file_WZ
  TH1D* h1_evt_WZ = (TH1D*)file_WZ->Get("demo/histoDir/eventCount");
  unsigned long long evt_WZ = h1_evt_WZ->GetEntries(); //Integral();                                                                         
  double wt_WZ = (xs_WZ*lumi)/evt_WZ ;
  TH1D* tauPt_Stage1_WZ  = (TH1D*)file_WZ->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //
  //tauPt_Stage1_WZ->Sumw2(kFALSE);
  // tauPt_Stage1_WZ->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_WZ->Scale(wt_WZ);
  tauPt_Stage1_WZ->Scale(kfact_WZ);
 std::cout << "WZ weighted nevt=" << tauPt_Stage1_WZ->Integral() << std::endl;
 totalMC +=  tauPt_Stage1_WZ->Integral();

  //file_ZZ
  TH1D* h1_evt_ZZ = (TH1D*)file_ZZ->Get("demo/histoDir/eventCount");
  unsigned long long evt_ZZ = h1_evt_ZZ->GetEntries(); //Integral();                                                                         
  double wt_ZZ = (xs_ZZ*lumi)/evt_ZZ ;
  TH1D* tauPt_Stage1_ZZ  = (TH1D*)file_ZZ->Get("demo/histoDir/tauPt_Stage1");
  // Poisson error //
  //tauPt_Stage1_ZZ->Sumw2(kFALSE);
  //tauPt_Stage1_ZZ->SetBinErrorOption(TH1::kPoisson);
  tauPt_Stage1_ZZ->Scale(wt_ZZ);
  tauPt_Stage1_ZZ->Scale(kfact_ZZ);
 std::cout << "ZZ weighted nevt=" << tauPt_Stage1_ZZ->Integral() << std::endl;
 totalMC += tauPt_Stage1_ZZ->Integral();

  TH1D* total_diboson = (TH1D*)tauPt_Stage1_WW->Clone();
  total_diboson->Add(tauPt_Stage1_WZ);
  total_diboson->Add(tauPt_Stage1_ZZ);
  total_diboson->SetFillColorAlpha(kOrange+2,0.5);
  total_diboson->SetLineColor(kBlack);
  total_diboson->Rebin(10);


  //datadriven                                                                                                                                                                                                           
  //  double wt_Datadriven = (lumi/33.507) ;                                                                                                                                                                             
  TH1D* total_QCD = (TH1D*)file_Datadriven->Get("demo/histoDir/tauPt_Stage1");
  total_QCD->SetFillStyle(3001);
  total_QCD->SetFillColor(kPink+1);
  total_QCD->SetLineColor(kBlack);
  total_QCD->Rebin(10);  //datadriven                                                                                                                                                                                  

  std::cout << "totalMC(w/o DD) =" << totalMC << std::endl;

   std::cout << "will do data" << std::endl;
  
  //--Data--//
   TH1D* tauPt_Stage1_Run2016F  =  (TH1D*)file_Tau_Run2016F->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016E  =  (TH1D*)file_Tau_Run2016E->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016D  =  (TH1D*)file_Tau_Run2016D->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016C  =  (TH1D*)file_Tau_Run2016C->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016B  =  (TH1D*)file_Tau_Run2016B->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016G  =  (TH1D*)file_Tau_Run2016G->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016H_v2  = (TH1D*)file_Tau_Run2016H_v2->Get("demo/histoDir/tauPt_Stage1");
   TH1D* tauPt_Stage1_Run2016H_v3  = (TH1D*)file_Tau_Run2016H_v3->Get("demo/histoDir/tauPt_Stage1");
   
   /*
  std::cout << "Will Clone B" << std::endl;
  TH1D* tauPt_Stage1_Run2016BCD = (TH1D*)tauPt_Stage1_Run2016B->Clone();
 
  std::cout << "Will add C" << std::endl;
  tauPt_Stage1_Run2016BCD->Add(tauPt_Stage1_Run2016C);

  std::cout << "Will add D" << std::endl;
  tauPt_Stage1_Run2016BCD->Add(tauPt_Stage1_Run2016D);

  //  std::cout << "Will add E" << std::endl;
  // tauPt_Stage1_Run2016BCDEF->Add(tauPt_Stage1_Run2016E);

  // std::cout << "Will add F" << std::endl;
  //  tauPt_Stage1_Run2016BCDEF->Add(tauPt_Stage1_Run2016F);
  */

  TH1D* tauPt_Stage1_Run2016all = (TH1D*)tauPt_Stage1_Run2016B->Clone();
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016C);
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016D);
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016E);
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016F);
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016G);
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016H_v2);
  tauPt_Stage1_Run2016all->Add(tauPt_Stage1_Run2016H_v3);
                                                                                                                                    
  tauPt_Stage1_Run2016all->SetMarkerStyle(20);
  tauPt_Stage1_Run2016all->SetMarkerColor(kBlack);
  tauPt_Stage1_Run2016all->SetLineColor(kBlack);
  tauPt_Stage1_Run2016all->Rebin(10);
  
  std::cout << "will do signal " << std::endl;
  //--Signal--//
  TH1D* h1_evt_Wprime_M4000 = (TH1D*)file_Wprime_M4000->Get("demo/histoDir/eventCount");
  unsigned long long evt_Wprime_M4000 = h1_evt_Wprime_M4000->GetEntries(); //Integral();                                                                          
  // std::cout << "evt_Wprime_M4000 = " << evt_Wprime_M4000 << std::endl;
  double wt_Wprime_M4000 = (xs_Wprime_M4000*lumi)/evt_Wprime_M4000 ;
  TH1D* tauPt_Stage1_Wprime_M4000  = (TH1D*)file_Wprime_M4000->Get("demo/histoDir/tauPt_Stage1");
  std::cout << "Sig Eff W' M4000 : " << ( tauPt_Stage1_Wprime_M4000->GetEntries() / evt_Wprime_M4000 ) << std::endl;
  tauPt_Stage1_Wprime_M4000->Scale(wt_Wprime_M4000);
  //  tauPt_Stage1_Wprime_M4000->SetFillColorAlpha(kGreen-7,0.5);
  tauPt_Stage1_Wprime_M4000->SetLineColor(kMagenta);
  tauPt_Stage1_Wprime_M4000->SetLineWidth(2);
  tauPt_Stage1_Wprime_M4000->SetLineStyle(5);
  tauPt_Stage1_Wprime_M4000->Rebin(10) ;
 
  //--Plotting Styles//
  gStyle->SetPadLeftMargin(0.15);
  gStyle->SetPadRightMargin(0.05);
  gStyle->SetPadBottomMargin(0.12);  
  gStyle->SetPadTopMargin(0.05);   
  gStyle->SetTitleXSize(0.05);
  gStyle->SetTitleXOffset(1.05);
  gStyle->SetTitleYSize(0.05);
  gStyle->SetTitleYOffset(1.05);

  //////// Output File /////////
  TFile* outputFile = new TFile("Out_tauPt_Stage1.root","RECREATE");
  outputFile->cd();

  //--//
  THStack *hs = new THStack("hs","");
  // hs->Add(tauPt_Stage1_WJetsToLNu);
  hs->Add(total_diboson);
  hs->Add(total_DY);
  hs->Add(total_ST);
  hs->Add(total_TT);
  //  hs->Add(tauPt_Stage1_DYJetsToLL_M50);
  hs->Add(total_QCD);
  //  hs->Add(total_ZJets);
  hs->Add(total_WJets);
  //tauPt_Stage1_->SetTitle("");
    /*
  eff1->GetYaxis()->SetTitle("Events");
  //eff1->SetMarkerStyle(0);
  //eff1->SetMarkerColor(kBlack);
  eff1->SetLineColor(kBlack);
  eff1->SetLineWidth(2);
  */
  TCanvas* my_canvas = new TCanvas("canvas","canvas",800,600);
  my_canvas->cd();
  //  hs->Draw();
  gPad->SetLogy();
  hs->Draw("HIST");                                                                                                                                        
  hs->SetMaximum(100000);
  hs->SetMinimum(0.1);
  hs->GetXaxis()->SetRangeUser(0, 1000);
  //  hs->GetXaxis()->SetLimits(40, 3200);
  hs->GetXaxis()->SetTitle("#tau pT [GeV]");
  hs->GetYaxis()->SetTitle("Events");

  TH1F* total =  (TH1F*)hs->GetStack()->Last()->Clone();
  // total->SetFillStyle(3004);                                                                                                                                      
  // total->SetFillColor(kGray+1); 
  //  total->SetMarkerColor(0);
  // total->Draw("SAME E2");
  //hs->GetStack()->Last()->Draw("same E");
  // hs->Draw("SAME HIST");

  //  tauPt_Stage1_Run2016E->Draw("SAME E0");
  tauPt_Stage1_Run2016all->Draw("SAME E0");
  TH1F* mydata =  (TH1F*)tauPt_Stage1_Run2016all->Clone();

  //tauPt_Stage1_Run2016C->Draw("SAME E0");
  //tauPt_Stage1_Run2016CDE->Draw("SAME E0");
  //
  tauPt_Stage1_Wprime_M4000->Draw("SAME HIST");
  //  hs->SetOption("HIST L");
  
  TLatex* CMS_text = new TLatex(0.20,0.90,"CMS");
  CMS_text->SetNDC();
  CMS_text->SetTextSize(0.05);
  CMS_text->SetTextAngle(0);
  CMS_text->Draw("same");
  TLatex* CMS_text_2 = new TLatex(0.20,0.85,"Preliminary");
  CMS_text_2->SetNDC();
  CMS_text_2->SetTextFont(42);
  CMS_text_2->SetTextSize(0.05);
  CMS_text_2->SetTextAngle(0);
  CMS_text_2->Draw("same");    

  TLatex* lumiText = new TLatex(0.92,0.975,"35.9 fb^{-1} (13 TeV)");
  lumiText->SetNDC();
  lumiText->SetTextFont(42);
  lumiText->SetTextSize(0.04);
  lumiText->SetTextAlign(32);
  lumiText->Draw("same");     

  TLegend *leg_example = new TLegend(0.75,0.50,0.94,0.94);
  leg_example->SetFillColor(0);
  leg_example->SetTextFont(42);
  leg_example->SetBorderSize(0);
  leg_example->AddEntry(total_WJets, "Wjets","f");
  leg_example->AddEntry(total_DY, "DY","f");
  leg_example->AddEntry(total_TT, "TT","f");
  //leg_example->AddEntry(tauPt_Stage1_WJetsToLNu, "Wjets","f");
  leg_example->AddEntry(total_ST, "Single Top", "f");
  leg_example->AddEntry(total_diboson, "Diboson", "f");
  leg_example->AddEntry(total_QCD, "QCD datadriven", "f");
  // leg_example->AddEntry(total_ZJets, "Z", "f");
  leg_example->AddEntry(tauPt_Stage1_Wprime_M4000, "SSM W' 4 TeV", "l");
  leg_example->AddEntry(tauPt_Stage1_Run2016all, "Data", "pl" );
  // leg_example->AddEntry(tauPt_Stage1_Run2016E, "Data", "pl" );
  // leg_example->AddEntry(tauPt_Stage1_Run2016D, "Data", "pl" );
  leg_example->Draw("same");
  
  my_canvas->Write();
  my_canvas->Print("tauPt_Stage1_DD.pdf");


  /*

  TCanvas* my_canvas2 = new TCanvas("canvas2","canvas2");
  my_canvas2->cd();
  gPad->SetLogy();
  total->SetMaximum(1000);
  total->SetMarkerStyle(20);
  total->Draw("E");
  my_canvas2->Write();
  */
  TCanvas* ratio_c = new TCanvas("ratio","ratio_canvas",800,700);
  ratio_c->SetTopMargin(0.); 
  ratio_c->SetBottomMargin(0.); 
  ratio_c->Update();
  ratio_c->Divide(1, 2);
  ratio_c->cd(1);

  gPad->SetPad(.005, .30, .995, .995);
  TPad* pad1 = (TPad*)ratio_c->GetPad(1); 
  pad1->SetTopMargin(0.05);
  pad1->SetBottomMargin(0.05); 
  
  ratio_c->Update();
  gPad->SetLogy();
  
  hs->Draw("HIST");                                                                                                                                        
  hs->SetMaximum(100000);
  hs->SetMinimum(0.01);
  //  hs->GetXaxis()->SetLimits(40, 3200);
  hs->GetXaxis()->SetRangeUser(0, 1000);
  hs->GetXaxis()->SetTitle("");
  // total->Draw("SAME E2");
  mydata->Draw("SAME E1");
  tauPt_Stage1_Wprime_M4000->Draw("SAME HIST");
  CMS_text->Draw("same");
  CMS_text_2->Draw("same");
  lumiText->Draw("same");
  leg_example->Draw("same");
  ratio_c->cd(2);

  gPad->SetPad(.005, .08, .995, .28); 
  gStyle->SetOptStat(false);
  ratio_c->Update();
  TPad* pad2 = (TPad*)ratio_c->GetPad(2);
  pad2->SetTopMargin(0.04); 
  pad2->SetBottomMargin(0.30); 
  pad2->SetGridx();
  pad2->SetGridy();

  std::cout << "data bins = " << mydata->GetNbinsX() << " width=" << mydata->GetBinWidth(2);
  std::cout << " MC bins = " << total->GetNbinsX() << " width=" << total->GetBinWidth(2) << std::endl;

  int nbin=mydata->GetNbinsX() ;
  float width=mydata->GetBinWidth(2);
  TH1F *data_by_MC = new TH1F("h1", "ratio", nbin, 0, 4000);
  std::cout << "before D/MC bins=" << data_by_MC->GetNbinsX() << " width=" << data_by_MC->GetBinWidth(2) << std::endl;

  for (int i=0; i<nbin; i++) {
    float data = mydata->GetBinContent(i);
    float MC = total->GetBinContent(i);
    float ratio=0;
    if (MC>0) ratio=data/MC ;
    data_by_MC->SetBinContent(i,ratio);
    if (data>0) {
      float stat_err = sqrt(data)/data ;  
      data_by_MC->SetBinError(i,stat_err);
    }

    // data_by_MC->SetBinWidth(i,width);  
  }

  //  TH1F* data_by_MC = (TH1F*)mydata->Clone();
  // data_by_MC->Divide(total);
  data_by_MC->SetMarkerStyle(20);
  data_by_MC->Draw("E");
  data_by_MC->GetXaxis()->SetTitle("#tau pT [GeV]");
  data_by_MC->GetYaxis()->SetTitle("#frac{DATA}{MC}");
  data_by_MC->GetYaxis()->SetLabelSize(0.12);
  data_by_MC->GetXaxis()->SetLabelSize(0.12);
  data_by_MC->GetYaxis()->SetTitleSize(0.18);
  data_by_MC->GetXaxis()->SetTitleSize(0.18);
  data_by_MC->GetYaxis()->SetTitleOffset(0.20);
  data_by_MC->GetXaxis()->SetTitleOffset(0.75);
  data_by_MC->SetTitle("");
  data_by_MC->GetXaxis()->SetRangeUser(0, 1000);
  data_by_MC->SetMaximum(4);
  data_by_MC->SetMinimum(0);
  data_by_MC->GetYaxis()->SetNdivisions(4);



  TLine *l=new TLine(0,1,1000,1);
  l->SetLineColor(kRed);
  l->Draw("same");

  std::cout << "D/MC bins=" << data_by_MC->GetNbinsX() << " width=" << data_by_MC->GetBinWidth(2) << std::endl;
  ratio_c->Write();
  ratio_c->Print("tauPt_Stage1_ratio_DD.pdf");

 
  return 0;

}
Esempio n. 16
0
void view()
{
  TFile* f = TFile::Open("result.root");

  int signalColorTable[20], backgroundColorTable[20];

  for ( int i=0; i<20; ++i )
  {
    signalColorTable[i] = kAzure+10-i;
    backgroundColorTable[i] = kOrange+10-i;
  }

  TList* signalPlots = makePlots((TDirectory*)f->Get("MC_Signal_EMEM"), signalColorTable);
  TList* backgroundPlots = makePlots((TDirectory*)f->Get("MC_Background_EMEM"), backgroundColorTable, true);

  if ( signalPlots == 0 || backgroundPlots == 0 ) return;

  const int nPlots = signalPlots->GetSize();
  for ( int i=0; i<nPlots; ++i )
  {
    THStack* hSignal = (THStack*)signalPlots->At(i);
    THStack* hBackground = (THStack*)backgroundPlots->At(i);

    TString histName = hSignal->GetName();
    bool doLog = histName.Contains("Pt");// || histName.Contains("RelIso");

    TCanvas* c = new TCanvas(TString("c")+hSignal->GetName(), hSignal->GetTitle(), 1200, 600);
    TPad* pad;

    c->Divide(2,1);

    TString xTitle, yTitle;

    pad = (TPad*)c->cd(1);
    if ( doLog ) pad->SetLogy();
    pad->SetBorderSize(0);
    pad->SetBorderMode(0);
    hBackground->Draw();

    xTitle = ((TH1*)hBackground->GetHists()->At(0))->GetXaxis()->GetTitle();
    yTitle = ((TH1*)hBackground->GetHists()->At(0))->GetYaxis()->GetTitle();
    hBackground->GetXaxis()->SetTitle(xTitle);
    hBackground->GetYaxis()->SetTitle(yTitle);

    pad->BuildLegend(0.6, 0.6, 0.98, 0.98);

    pad = (TPad*)c->cd(2);
    if ( doLog ) pad->SetLogy();
    pad->SetBorderSize(0);
    pad->SetBorderMode(0);
    hSignal->Draw("nostack");

    xTitle = ((TH1*)hSignal->GetHists()->At(0))->GetXaxis()->GetTitle();
    yTitle = ((TH1*)hSignal->GetHists()->At(0))->GetYaxis()->GetTitle();
    hSignal->GetXaxis()->SetTitle(xTitle);
    hSignal->GetYaxis()->SetTitle(yTitle);

    pad->BuildLegend(0.6, 0.7, 0.98, 0.98);

    c->Print(TString(c->GetName())+".png");
  }
}
void distribution(const string folderNameWithRootFiles = "", const Int_t signalRegion0_controlRegion1 = 0, const Int_t mumu0_ee1 = 0, const Int_t data0_noData1 = 0, const string var = "met", const Int_t yAxisLog_flag = 0, const Int_t MCpoissonUncertainty_flag = 0, const Double_t xAxisMin = 0, const Double_t xAxisMax = -1, const Double_t yAxisMin = 0, const Double_t yAxisMax = -1, const Int_t binDensity_flag = 0, const Int_t MCnormalizedToData_flag = 0) {

  // if signalRegion0_controlRegion1 == 0 (default), will do met distribution in the monojet signal region, else it will do the control region

  // mumu0_ee1 is for lepton flavour in CS (not used in SR)

  // data0_noData1 is to use or not a data file to compared with MC

  // yAxisLog_flag is to choose whether or not to use log scale in Y axis (default is 0, that is, normal scale)
  // xAxisMin and xAxisMax are the ranges for x Axis. Default values are used if xAxisMin > xAxisMax (otherwise user values are used)

  TH1::SetDefaultSumw2();            //all the following histograms will automatically call TH1::Sumw2() 

  gROOT->SetStyle("Plain");  // to have white legend (on my pc it's already white, but in tier2 it appears grey)
  gStyle->SetFillColor(10);

  string filenameExtension = ".root";
  // string fileDirectoryPath = "spring15_25ns_rootfiles/";
  string fileDirectoryPath = "/cmshome/ciprianim/CMSSW721/output/" + folderNameWithRootFiles + "/";

  string plotDirectoryPath = fileDirectoryPath;
  // string plotDirectoryPath = "/cmshome/ciprianim/CMSSW721/pdfsFromAnalysis/plots/monojet/met_distribution/";
  //string plotDirectoryPath = "./distributions/";
  string plotFileExtension = ".pdf";
  string suffix;

  if (mumu0_ee1 == 0) suffix = "_mumu";
  else if (mumu0_ee1 == 1) suffix = "_ee";
  else {
    cout << "Error: mumu0_ee1 must be 0 or 1. End of programme." << endl;
    exit(EXIT_FAILURE);
  }

  TH1D* hvar = NULL;   // to get histogram from file
  string hvarName;          // name of histogram to take from file
  string xAxisName;        // name of X axis when plotting distribution. It is a tex string (with ROOT standard), e.g. "#slash{E}_{T} [GeV]" for MET

  // ===== TO BE MODIFIED =====

  // hvarName = "HmetNoLepDistribution";
  // xAxisName = "#slash{E}_{T} [GeV]";

  setDistribution(signalRegion0_controlRegion1, mumu0_ee1, var, hvarName, xAxisName);
    
  // =====================

  vector<TH1D*> hMC;
  TH1D* hdata = NULL;

  vector<string> sampleName;
  vector<string> MC_TexLabel;
  if (data0_noData1 == 1) setSampleName(signalRegion0_controlRegion1, sampleName, MC_TexLabel, mumu0_ee1);
  else setSampleName2lepSkim(signalRegion0_controlRegion1, sampleName, MC_TexLabel, mumu0_ee1);

  string data_TexLabel = "data";

  Int_t nFiles = (Int_t) sampleName.size();

  vector<Int_t> histColor;
   setHistColor(histColor, nFiles);

   string filenameBase;
   string canvasName;

   if (signalRegion0_controlRegion1 == 0) {

     filenameBase = "monojet_SR_spring15_25ns_";
     canvasName = var + "_monojetSR_";

   } else {

     canvasName = var + "_zjetsCS" + suffix;

     if (mumu0_ee1 == 0) filenameBase = "zmumujets_CS_spring15_25ns_";
     else if (mumu0_ee1 == 1) filenameBase = "zeejets_CS_spring15_25ns_";

   }
 

  vector<string> MCfileName;
  for (Int_t i = 0; i < nFiles; i++) {
    MCfileName.push_back(fileDirectoryPath + filenameBase + sampleName[i] + filenameExtension);
  }

  for(Int_t i = 0; i < nFiles; i++) {

    cout<<"fileName : "<<MCfileName[i]<<endl;

    TFile* f = TFile::Open(MCfileName[i].c_str(),"READ");
    if (!f || !f->IsOpen()) {
      cout<<"*******************************"<<endl;
      cout<<"Error opening file \""<<MCfileName[i]<<"\".\nApplication will be terminated."<<endl;
      cout<<"*******************************"<<endl;
      exit(EXIT_FAILURE);
    }

    //cout << "check 1 " << endl;    

    hvar = (TH1D*)f->Get(hvarName.c_str());
    if (!hvar) {
      cout << "Error: histogram not found in file ' " << MCfileName[i] << "'. End of programme." << endl;
      exit(EXIT_FAILURE);
    }
    hMC.push_back( (TH1D*)hvar->Clone() );

  } 

  // ==== FILE NAME WILL HAVE TO BE MODIFIED, NOW IT IS JUST A TEST =====

  string datafileName = fileDirectoryPath;

  if (data0_noData1 == 0) {

    if (signalRegion0_controlRegion1 == 0) {

      datafileName += "monojet_SR_spring15_25ns_DATA.root";

    } else {

      if (mumu0_ee1 == 0) datafileName += "zmumujets_CS_spring15_25ns_DATA.root";
      else if (mumu0_ee1 == 1) datafileName += "zeejets_CS_spring15_25ns_DATA.root";

    }

  }

  // ==== opening data file ======

  if (data0_noData1 == 0) {

    cout<<"fileName : "<<datafileName<<endl;

    TFile* f = TFile::Open(datafileName.c_str(),"READ");
    if (!f || !f->IsOpen()) {
      cout<<"*******************************"<<endl;
      cout<<"Error opening file \""<<datafileName<<"\".\nApplication will be terminated."<<endl;
      cout<<"*******************************"<<endl;
      exit(EXIT_FAILURE);
    }

    hvar = (TH1D*)f->Get(hvarName.c_str());

    if (!hvar) {
      cout << "Error: histogram not found in file ' " << datafileName << "'. End of programme." << endl;
      exit(EXIT_FAILURE);
    }
    hdata = (TH1D*)hvar->Clone();

  }

  // ===============================

  THStack* hMCstack = new THStack("hMCstack","");
  Double_t stackNorm = 0.0;

  for (Int_t j = 0; j < nFiles; j++) {

    for (Int_t i = 1; i <= hMC[j]->GetNbinsX(); i++) {

      if (MCpoissonUncertainty_flag == 1) {

	hMC[j]->SetBinError(i,sqrt(hMC[j]->GetBinContent(i)));
	
      }

    }

    hMC[j]->SetFillColor(histColor[j]);
    stackNorm += hMC[j]->Integral();

  }

  // loop again on MC histograms to scale them and then fill the thstack

  for (Int_t j = 0; j < nFiles; j++) {

    if (data0_noData1 == 0 && MCnormalizedToData_flag != 0) {

      Double_t dataNorm = hdata->Integral();

      if (binDensity_flag != 0) hMC[j]->Scale(dataNorm/stackNorm,"width");
      else hMC[j]->Scale(dataNorm/stackNorm);

    } else if (binDensity_flag != 0) hMC[j]->Scale(1.0,"width");  // option width divides by bin width and manages the correct error setting

    hMCstack->Add(hMC[j]);

  }

  if (data0_noData1 == 0) {

    cout << "Events in data: " << hdata->Integral() << endl;
    cout << "Events in MC   : " << ((TH1D*) hMCstack->GetStack()->Last())->Integral() << endl;

  }
  
  if (data0_noData1 == 0 && binDensity_flag != 0) hdata->Scale(1.0,"width");
  //if (data0_noData1 == 0 && MCnormalizedToData_flag != 0)

  // now here we go with the canvas

  TH1D * ratioplot = NULL; // will use it for the ratio plots

  TPad *subpad_1 = NULL;  // will use it to access specific subpad in canvas
  TPad *subpad_2 = NULL; 

  TCanvas *c;
  if (data0_noData1 == 0) c = new TCanvas(canvasName.c_str(), (var + " distribution").c_str(), 700, 700);
  else c = new TCanvas(canvasName.c_str(), (var + " distribution").c_str());
  TLegend *leg = new TLegend(0.7,0.6,0.99,0.94);  

  // if there are data, split canvas to draw the dta/MC ratio plot

  if (data0_noData1 == 0) {

    subpad_1 = new TPad("pad_1","",0.0,0.28,1.0,1.0);
    if (yAxisLog_flag) subpad_1->SetLogy();
    //subpad_1->SetBottomMargin(0);
    subpad_2 = new TPad("pad_2","",0.0,0.0,1.0,0.32);
    subpad_2->SetGridy();
    //subpad_2->SetTopMargin(0);
    subpad_2->SetBottomMargin(0.3);
    subpad_1->Draw();
    subpad_2->Draw();

    subpad_1->cd();

  } else if (yAxisLog_flag) c->SetLogy();

  
  hMCstack->Draw("HIST");
  //if (yAxisMin > 0) hMCstack->SetMinimum(yAxisMin);

  if (yAxisMin < yAxisMax) {
    if (data0_noData1 == 0) subpad_1->Update();  // to be done after Draw() to access pad parameters such as default axis range
    else c->Update();  
    hMCstack->GetYaxis()->SetRangeUser(yAxisMin,yAxisMax);
  }

  // if (data0_noData1 == 0) {

  //   if (yAxisMin > 0) hMCstack->GetYaxis()->SetRangeUser(yAxisMin, subpad_1->GetY2());
  //   else hMCstack->GetYaxis()->SetRangeUser(yAxisMin, c->GetY2());

  // }

  //hMCstack->SetMaximum(4000.0);
  TH1D* stackCopy = (TH1D*)(((TH1D*)hMCstack->GetStack()->Last())->DrawCopy("E2 SAME"));
  stackCopy->SetFillColor(kBlack);
  stackCopy->SetFillStyle(3144);

  if (data0_noData1 == 1) {    //  when using data ( == 0) the x axis will not have labels (they will only be below in the ratio plot
    hMCstack->GetXaxis()->SetTitle(xAxisName.c_str());
    hMCstack->GetXaxis()->SetTitleSize(0.06);
    hMCstack->GetXaxis()->SetTitleOffset(0.6);
  }

  if (xAxisMin < xAxisMax) {
    if (data0_noData1 == 0) subpad_1->Update();  // to be done after Draw() to access pad parameters such as default axis range
    else c->Update();  
    hMCstack->GetXaxis()->SetRangeUser(xAxisMin,xAxisMax);
  }

  if (binDensity_flag == 0) hMCstack->GetYaxis()->SetTitle("events");
  else hMCstack->GetYaxis()->SetTitle("events / GeV");
  hMCstack->GetYaxis()->SetTitleSize(0.06);
  hMCstack->GetYaxis()->SetTitleOffset(0.8);
  hMCstack->GetYaxis()->CenterTitle();
  for (Int_t j = (nFiles-1); j >= 0; j--) {
    leg->AddEntry(hMC[j],Form("%s",MC_TexLabel[j].c_str()),"lf");
  }

  if (data0_noData1 == 0) {    
    hdata->SetMarkerStyle(8); // large dot
    hdata->Draw("EX0 SAME"); //X0 doesn't draw x error
    leg->AddEntry(hdata,Form("%s",data_TexLabel.c_str()),"p");
  }

  gStyle->SetStatStyle(0);
  leg->Draw(); 
  leg->SetMargin(0.3); 
  leg->SetBorderSize(0);

  if (data0_noData1 == 0) { // if using data, draw the ratio plot

    subpad_2->cd();
    ratioplot = new TH1D(*hdata);
    ratioplot->Divide(stackCopy);
    ratioplot->SetStats(0);
    ratioplot->SetTitle("");
    ratioplot->GetXaxis()->SetLabelSize(0.10);
    ratioplot->GetXaxis()->SetTitle(xAxisName.c_str());
    ratioplot->GetXaxis()->SetTitleSize(0.14);
    ratioplot->GetXaxis()->SetTitleOffset(0.8);
    ratioplot->GetYaxis()->SetLabelSize(0.10);
    ratioplot->GetYaxis()->SetTitle("data / MC");
    ratioplot->GetYaxis()->SetTitleSize(0.15);
    ratioplot->GetYaxis()->SetTitleOffset(0.3);
    ratioplot->GetYaxis()->CenterTitle();
    ratioplot->GetYaxis()->SetRangeUser(0.5,1.5);
    ratioplot->GetYaxis()->SetNdivisions(011);
    if (xAxisMin < xAxisMax) {
      //subpad_2->Update();  // to be done after Draw() to access pad parameters such as default axis range  
      ratioplot->GetXaxis()->SetRangeUser(xAxisMin,xAxisMax);
    }
    ratioplot->SetMarkerStyle(8);  //medium dot
    ratioplot->DrawCopy("E");  

  }

  c->SaveAs( (plotDirectoryPath + c->GetName() + plotFileExtension).c_str() );

}
Esempio n. 18
0
void HistogramPlotter::makePlot(std::map<std::string, TH1F*> plotMap, std::string plotName, std::string subLabel, std::vector<std::string> xAxisLabels){
  std::cerr << "Making a plot called: " << plotName << std::endl;
  //Make the legend. This is clearly the first thing I should do.
  TLegend legend_ = TLegend(0.7,0.7,0.94,0.94);
  legend_.SetFillStyle(1001);
  legend_.SetBorderSize(1);
  legend_.SetFillColor(kWhite);
  for (std::vector<std::string>::iterator leg_iter = legOrder_.begin(); leg_iter != legOrder_.end(); leg_iter++){
    legend_.AddEntry(plotMap[*leg_iter], dsetMap_[*leg_iter].legLabel.c_str(), dsetMap_[*leg_iter].legType.c_str());
  }
    
  //Initialise the stack
  THStack mcStack = THStack(plotName.c_str(),plotName.c_str());
  //Do a few colour changing things and add MC to the stack.
  for (std::vector<std::string>::reverse_iterator plot_iter = plotOrder_.rbegin(); plot_iter != plotOrder_.rend(); plot_iter++){
    plotMap[*plot_iter]->SetFillColor(dsetMap_[*plot_iter].colour);
    plotMap[*plot_iter]->SetLineColor(kBlack);
    plotMap[*plot_iter]->SetLineWidth(1);
    if( *plot_iter == "data"){
      plotMap["data"]->SetMarkerStyle(20);
      plotMap["data"]->SetMarkerSize(1.2);
      plotMap["data"]->SetMarkerColor(kBlack);
      continue;
    }
    mcStack.Add(plotMap[*plot_iter]);
  }
  TCanvas * canvy = new TCanvas((plotName + subLabel + postfix_).c_str(), (plotName + subLabel + postfix_).c_str());
  canvy->cd();

  mcStack.Draw("");

  if (xAxisLabels.size() > 0){
    for (unsigned int i = 1; i <= xAxisLabels.size(); i++){
      mcStack.GetXaxis()->SetBinLabel(i,xAxisLabels[i-1].c_str());
    }
  }
  

  setLabelThree(subLabel);
  //labelThree_->Draw();
  //  labelTwo_->Draw();
  //  labelOne_->Draw();

  float max = mcStack.GetMaximum();
  if (plotMap.find("data") != plotMap.end()){
    max = TMath::Max(mcStack.GetMaximum(),plotMap["data"]->GetMaximum());
    plotMap["data"]->Draw("e x0, same");
  }

  mcStack.SetMaximum(max*1.3);
      
  legend_.Draw();

  // Save the plots.
  for (unsigned int ext_it = 0; ext_it < extensions_.size(); ext_it++){
    canvy->SaveAs((outputFolder_ + plotName + subLabel + postfix_ + extensions_[ext_it]).c_str());
  }

  //Make log plots
  canvy->SetLogy();
  mcStack.SetMaximum(max*10);

  //Save the log plots
  for (unsigned int ext_it = 0; ext_it < extensions_.size(); ext_it++){
    canvy->SaveAs((outputFolder_ + plotName + subLabel + postfix_ + "_log" + extensions_[ext_it]).c_str());
  }
  
  delete canvy;
}
void plotSuperMelaProjections(TString drawString="(p0plus_VAJHU*p0plus_m4l)/((p0plus_VAJHU*p0plus_m4l)+(bkg_VAMCFMNorm*bkg_m4l))",
			      TString cutString="ZZMass>106.&&ZZMass<141."){

  gROOT->ProcessLine(".L ~/tdrstyle.C");
  setTDRStyle();

  TCanvas* can = new TCanvas("can","can",500,500);

  gStyle->SetOptStat(0);

  TChain* qqZZ_8 = new TChain("SelectedTree");
  qqZZ_8->Add(inputDir+"PRODFSR_8TeV/4mu/HZZ4lTree_ZZTo*.root");
  qqZZ_8->Add(inputDir+"PRODFSR_8TeV/4e/HZZ4lTree_ZZTo*.root");
  qqZZ_8->Add(inputDir+"PRODFSR_8TeV/2mu2e/HZZ4lTree_ZZTo*.root");
  TChain* qqZZ_7 = new TChain("SelectedTree");
  qqZZ_7->Add(inputDir+"PRODFSR/4mu/HZZ4lTree_ZZTo*.root");
  qqZZ_7->Add(inputDir+"PRODFSR/4e/HZZ4lTree_ZZTo*.root");
  qqZZ_7->Add(inputDir+"PRODFSR/2mu2e/HZZ4lTree_ZZTo*.root");

  TChain* SM_8 = new TChain("SelectedTree");
  SM_8->Add(inputDir+"PRODFSR_8TeV/4mu/HZZ4lTree_H126.root");
  SM_8->Add(inputDir+"PRODFSR_8TeV/4e/HZZ4lTree_H126.root");
  SM_8->Add(inputDir+"PRODFSR_8TeV/2mu2e/HZZ4lTree_H126.root");
  TChain* SM_7 = new TChain("SelectedTree");
  SM_7->Add(inputDir+"PRODFSR/4mu/HZZ4lTree_H126.root");
  SM_7->Add(inputDir+"PRODFSR/4e/HZZ4lTree_H126.root");
  SM_7->Add(inputDir+"PRODFSR/2mu2e/HZZ4lTree_H126.root");

  //TChain* ZX = new TChain("SelectedTree");

  TChain* data = new TChain("SelectedTree");
  data->Add(inputDir+"PRODFSR_8TeV/data/HZZ4lTree_DoubleEle.root");
  data->Add(inputDir+"PRODFSR_8TeV/data/HZZ4lTree_DoubleMu.root");
  data->Add(inputDir+"PRODFSR_8TeV/data/HZZ4lTree_DoubleOr.root");
  data->Add(inputDir+"PRODFSR/data/HZZ4lTree_DoubleEle.root");
  data->Add(inputDir+"PRODFSR/data/HZZ4lTree_DoubleMu.root");
  data->Add(inputDir+"PRODFSR/data/HZZ4lTree_DoubleOr.root");

  data->Draw(drawString+">>datahisto(30,0,1)",cutString);
  TH1F* datahisto = (TH1F*) gDirectory->Get("datahisto");

  TChain* PS_8 = new TChain("SelectedTree");
  PS_8->Add(JHUinputDir+"JHU_8TeV/4mu/HZZ4lTree_jhuGenV2PseH126.root");
  PS_8->Add(JHUinputDir+"JHU_8TeV/4e/HZZ4lTree_jhuGenV2PseH126.root");
  PS_8->Add(JHUinputDir+"JHU_8TeV/2mu2e/HZZ4lTree_jhuGenV2PseH126.root");
  TChain* PS_7 = new TChain("SelectedTree");
  PS_7->Add(JHUinputDir+"JHU/4mu/HZZ4lTree_jhuGenV2PseH126.root");
  PS_7->Add(JHUinputDir+"JHU/4e/HZZ4lTree_jhuGenV2PseH126.root");
  PS_7->Add(JHUinputDir+"JHU/2mu2e/HZZ4lTree_jhuGenV2PseH126.root");
  
  qqZZ_7->Draw(drawString+">>qqZZ_7histo(30,0,1)","5.051*MC_weight*("+cutString+")");
  TH1F* qqZZ_7histo = (TH1F*) gDirectory->Get("qqZZ_7histo");

  qqZZ_8->Draw(drawString+">>qqZZ_8histo(30,0,1)","19.6*MC_weight*("+cutString+")");
  TH1F* qqZZ_8histo = (TH1F*) gDirectory->Get("qqZZ_8histo");

  SM_7->Draw(drawString+">>SM_7histo(30,0,1)","5.051*MC_weight*("+cutString+")");
  TH1F* SM_7histo = (TH1F*) gDirectory->Get("SM_7histo");

  SM_8->Draw(drawString+">>SM_8histo(30,0,1)","19.6*MC_weight*("+cutString+")");
  TH1F* SM_8histo = (TH1F*) gDirectory->Get("SM_8histo");

  PS_8->Draw(drawString+">>PS_8histo(30,0,1)","19.6*MC_weight*("+cutString+")");
  TH1F* PS_8histo = (TH1F*) gDirectory->Get("PS_8histo");

  PS_7->Draw(drawString+">>PS_7histo(30,0,1)","5.051*MC_weight*("+cutString+")");
  TH1F* PS_7histo = (TH1F*) gDirectory->Get("PS_7histo");
 
  //=========================
	
  //datahisto->SetBinErrorOption(TH1::kPoisson);
  datahisto->SetMarkerStyle(20);
  datahisto->SetMarkerSize(1.1);
	
  TH1F* qqZZhisto = new TH1F(*qqZZ_7histo);
  qqZZhisto->Add(qqZZ_8histo);
  cout<<qqZZhisto->Integral()<<endl;
  qqZZhisto->SetLineColor(1);
  qqZZhisto->SetLineWidth(2);
  qqZZhisto->SetFillColor(kAzure-9);

  TH1F* ZXhisto = new TH1F(*qqZZhisto);
  ZXhisto->Scale(ZXnorm/ZXhisto->Integral());
  ZXhisto->SetLineColor(1);
  ZXhisto->SetLineWidth(2);
  ZXhisto->SetFillColor(kGreen-5);

  TH1F* SMhisto = new TH1F(*SM_7histo);
  SMhisto->Add(SM_8histo);
  SMhisto->SetLineColor(kOrange+10);
  SMhisto->SetLineWidth(2);
  SMhisto->SetFillColor(0);

  TH1F* PShisto = new TH1F(*PS_7histo);
  PShisto->Add(PS_8histo);
  PShisto->SetLineColor(kRed+1);
  PShisto->SetLineWidth(2);
  PShisto->SetFillColor(0);
  //==========================

  datahisto->GetXaxis()->SetTitle("#it{D}_{bkg}");
  datahisto->GetYaxis()->SetTitle("Events");

  THStack* stack = new THStack("stack","stack");
  stack->Add(ZXhisto);
  stack->Add(qqZZhisto);
  stack->Add(SMhisto);
  stack->Draw("");
  stack->GetXaxis()->SetTitle("#it{D}_{bkg}");
  stack->GetYaxis()->SetTitle("Events");  

  if(plotData){
    datahisto->SetMaximum(20);
    datahisto->Draw("E1");
    stack->Draw("SAME");
    datahisto->Draw("E1same");
    datahisto->Draw("SAMEp");
  }else{
    stack->Draw();
  }

  // --------------- legend ----------------

  TLegend* leg = new TLegend(.3,.65,.65,.9);
  leg->SetFillColor(0);
  leg->SetBorderSize(0);

  if(plotData) leg->AddEntry(datahisto,"data","p");
  leg->AddEntry(SMhisto,"0^{+}, m_{H}=126 GeV","l");
  leg->AddEntry(qqZZhisto,"ZZ/Z#gamma^{*}","f");
  leg->AddEntry(ZXhisto,"Z+X","f");

  leg->Draw();

  if(plotData) datahisto->Draw("E1same");
  gPad->RedrawAxis();

  // -------- plot header --------------

  TPaveText *pt = new TPaveText(0.1577181,0.9562937,0.9580537,0.9947552,"brNDC");
  pt->SetBorderSize(0);
  pt->SetTextAlign(12);
  pt->SetFillStyle(0);
  pt->SetTextFont(42);
  pt->SetTextSize(0.03);
  TText *text = pt->AddText(0.01,0.5,"CMS preliminary");
  text = pt->AddText(0.3,0.6,"#sqrt{s} = 7 TeV, L = 5.1 fb^{-1}  #sqrt{s} = 8 TeV, L = 19.6 fb^{-1}");
  pt->Draw();   

  // ---------- save ----------
  
  can->SaveAs("superMELAproj.png");
  can->SaveAs("superMELAproj.eps");
  can->SaveAs("superMELAproj.root");
  
}
Esempio n. 20
0
void allCutFlow(){
setTDRStyle();

//loop over variables
for(int i = 0; i<1; i++){
double MinX = MinXs[i];
double MaxX = MaxXs[i];
Variable = Variables[i];
TString Xtitle = XTitles[i];

//Data
TH1D* data = getSample("SingleMu", 1);

//MC
TH1D* tt = getSample("TTJet", lumi*225.2/6920475);

//TH1D* wjets = getSample("W1Jet", lumi*37509/57708550);
TH1D* wjets = getSample("W1Jet", lumi*5400.0/23140779);
TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404);
TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443);
TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904);

//TH1D* zjets = getSample("DY1JetsToLL", lumi*5745.25/30457954);
TH1D* zjets = getSample("DY1JetsToLL", lumi*561.0/24042904);
TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749);
TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628);
TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785);

//TH1D* qcd = getSample("QCD_Pt-15to20_MuEnrichedPt5",     lumi*34679.3/8500505);
TH1D* qcd = getSample("QCD_Pt-15to20_MuEnrichedPt5",   lumi*7.022e8 * 0.0039/1722678);
TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5",   lumi*2.87e8 * 0.0065/8486893);
TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5",   lumi*6.609e7 * 0.0122/8928999);
TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5",   lumi*8082000.0 * 0.0218/7256011);
TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5",  lumi*1024000.0 * 0.0395/9030624);
TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505);
TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483);
TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481);
TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767);
TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142);
TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5",     lumi*0.774 * 0.1097/3807263);

TH1D* single_t = getSample("T_t-channel", lumi*56.4/3757707);
TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707);
TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395);
TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516);
TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817);
TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239);
TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948);

TH1D* all_MC = getSample("TTJet", lumi*225.2/6920475);

THStack *hs = new THStack("hs","test");

  qcd->Add(qcd2);
  qcd->Add(qcd3);
  qcd->Add(qcd4);
  qcd->Add(qcd5);
  qcd->Add(qcd6);
  qcd->Add(qcd7);
  qcd->Add(qcd8);
  qcd->Add(qcd9);
  qcd->Add(qcd10);
  qcd->Add(qcd11);

  hs->Add(qcd);  

  zjets->Add(z2jets);
  zjets->Add(z3jets);
  zjets->Add(z4jets);  
    
  hs->Add(zjets);


  wjets->Add(w2jets);
  wjets->Add(w3jets);
  wjets->Add(w4jets);  

  hs->Add(wjets);
      
  hs->Add(top_t);
  hs->Add(top_tw);
  hs->Add(top_s);
  hs->Add(tbar_t);
  hs->Add(tbar_tw);
  hs->Add(tbar_s);
  
  single_t->Add(top_tw);
  single_t->Add(top_s);
  single_t->Add(tbar_t);
  single_t->Add(tbar_tw);
  single_t->Add(tbar_s);
  
  hs->Add(tt);

TH1D * allMC = (TH1D*) tt->Clone("all");
allMC->Add(wjets);allMC->Add(zjets);allMC->Add(single_t);allMC->Add(qcd);

TH1D* dataEff = new TH1D("cut eff","cut eff",10,0,10);
TH1D* mcEff = new TH1D("cut eff","cut eff",10,0,10);


 TString step[11] = {"Skim" ,"Cleaning and HLT","one isolated #mu", "loose #mu veto", "loose e veto", "#geq 1 jets", "#geq 2 jets","#geq 3 jets", "#geq 4 jets", "#geq1 CSV b-tag", "#geq2 CSV b-tag" };
 		
dataEff->Sumw2();
for(int i =1; i<11; i++){
mcEff->GetXaxis()->SetBinLabel(i, step[i]);
dataEff->SetBinContent(i, data->GetBinContent(i+1)/data->GetBinContent(i));
dataEff->SetBinError(i, sqrt(pow(data->GetBinContent(i+1),2)+pow(data->GetBinContent(i),2)));
mcEff->SetBinContent(i, allMC->GetBinContent(i+1)/allMC->GetBinContent(i));

}  

	
	TCanvas *c2 = new TCanvas("cutflow eff","cutflow eff",600, 500);
  	
	mcEff->SetLineColor(kRed);
	mcEff->Draw();
	dataEff->Draw("Esame");
	
	TLegend *tleg3;
	tleg3 = new TLegend(0.7,0.7,0.8,0.9);
	tleg3->SetTextSize(0.04);
	tleg3->SetBorderSize(0);
	tleg3->SetFillColor(10);
	tleg3->AddEntry(dataEff , "data", "l");
	tleg3->AddEntry(mcEff , "mc", "l");
	
	tleg3->Draw("same");
	
	c2->SaveAs("plots/cutFlow/cutEff_data.png");
	delete c2;

  //draw histos to files
  TCanvas *c1 = new TCanvas("cutflow","cutflow",900, 600);

  hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3);
  
  if(logPlot ==true)
  hs->SetMinimum(10000.);

  hs->Draw();
  for(int i =0; i<tt->GetNbinsX(); i++)
  hs->GetXaxis()->SetBinLabel(i+1, step[i]);
  
  data->Draw("E same");
  data->SetMarkerStyle(20);
  
//  hs->GetXaxis()->SetLimits(MinX, MaxX);
  hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05);
  hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);
  
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.7,0.7,0.8,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(data , "2012 data", "lpe");
	tleg2->AddEntry(tt , "t#bar{t}", "lf");
	tleg2->AddEntry(top_t, "single top", "lf");
	tleg2->AddEntry(wjets , "w+jets", "lf");
	tleg2->AddEntry(zjets , "z+jets", "lf");
	tleg2->AddEntry(qcd , "QCD", "lf");
	
	//tleg2->AddEntry(singtEff, "single-t"      , "l");
	//tleg2->AddEntry(singtwEff, "single-tW"      , "l");
 	tleg2->Draw("same");	
	
	TText* textPrelim = doPrelim(0.17,0.96);
	textPrelim->Draw();
	
  if(logPlot ==true){
  c1->SetLogy();
  }	
  
  TString plotName("plots/cutFlow/");
  
  if(logPlot ==true){
    plotName += Variable+"_Log";
    plotName += Nbtags+".png";
    
  }else{
    plotName += Variable+"";  
    plotName += Nbtags+".png";
  }
 
 
  c1->SaveAs(plotName);
  delete c1;
 
 //print out
 
    std::cout.setf(std::ios::fixed);
    std::cout.precision(0);

 cout << " & ttbar & wjets & zjets & single-t & qcd & all MC & data " << endl; 
 
 for(int i = 0; i < tt->GetNbinsX(); i++){
 cout << step[i] << " & " << tt->GetBinContent(i+1) << " $\\pm$ " << tt->GetBinError(i+1)  << " & " << wjets->GetBinContent(i+1) << " $\\pm$ " << wjets->GetBinError(i+1)  << " & " << zjets->GetBinContent(i+1) << " $\\pm$ " << zjets->GetBinError(i+1)  << " & " << single_t->GetBinContent(i+1) << " $\\pm$ " << single_t->GetBinError(i+1)  << " & " << qcd->GetBinContent(i+1) << " $\\pm$ " << qcd->GetBinError(i+1)  << " & " << allMC->GetBinContent(i+1) << " $\\pm$ " << allMC->GetBinError(i+1)  << " & " << data->GetBinContent(i+1) << " $\\pm$ " << data->GetBinError(i+1)  << endl;
 
 }
 
  
  }
  	
}
Esempio n. 21
0
File: fake.C Progetto: kskovpen/bTag
void fake()
{
   gROOT->SetBatch();
   gROOT->SetStyle("Plain");
   
   gStyle->SetOptStat(0);

   SetStyle();
   
   TCanvas *c1 = new TCanvas("c1","c1",0,0,600,500);
   c1->Draw();
   c1->cd();

   TPad *c1_1;
   
   gStyle->SetHistTopMargin(0);

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

   std::string fpath = "histTEST_MERGED/QCD_Pt_170to300_TuneCUETP8M1_13TeV_pythia8/data.root";

//   std::string histnameFake = "h_muFake_pt";
//   std::string histnameReal = "h_muReal_pt";

//   std::string histnameFake = "h_muFake_trackerLayersWithMeasurement";
//   std::string histnameReal = "h_muReal_trackerLayersWithMeasurement";

//   std::string histnameFake = "h_muFake_numberOfValidMuonHits";
//   std::string histnameReal = "h_muReal_numberOfValidMuonHits";

//   std::string histnameFake = "h_muFake_numberOfMatches";
//   std::string histnameReal = "h_muReal_numberOfMatches";

//   std::string histnameFake = "h_muFake_numberOfMatchedStations";
//   std::string histnameReal = "h_muReal_numberOfMatchedStations";

//   std::string histnameFake = "h_muFake_numberOfValidHits";
//   std::string histnameReal = "h_muReal_numberOfValidHits";

//   std::string histnameFake = "h_muFake_numberOfValidPixelHits";
//   std::string histnameReal = "h_muReal_numberOfValidPixelHits";

   std::string histnameFake = "h_muFake_numberOfHits";
   std::string histnameReal = "h_muReal_numberOfHits";

//   std::string histnameFake = "h_muFake_normalizedChi2GlobalTrack";
//   std::string histnameReal = "h_muReal_normalizedChi2GlobalTrack";

//   std::string histnameFake = "h_muFake_normalizedChi2InnerTrack";
//   std::string histnameReal = "h_muReal_normalizedChi2InnerTrack";
   
   TFile *f;

   TH1D *hFake;
   TH1D *hReal;
   
   f = TFile::Open(fpath.c_str());
   
     {	
	TH1D *hFake_c = (TH1D*)f->Get(histnameFake.c_str());
	hFake_c->SetMarkerSize(0.0);

	TH1D *hReal_c = (TH1D*)f->Get(histnameReal.c_str());
	hReal_c->SetMarkerSize(0.0);

	hFake = (TH1D*)hFake_c->Clone("hFake");
	hReal = (TH1D*)hReal_c->Clone("hReal");
     }
   
   addbin(hFake);
   addbin(hReal);
   
   std::cout << hReal->Integral() << std::endl;
   std::cout << hFake->Integral() << std::endl;
   
   double iFake = hFake->Integral();
   double iReal = hReal->Integral();
//   double iAll = iFake+iReal;
   
//   hFake->Scale(1./iAll);
//   hReal->Scale(1./iAll);
   
   hFake->SetLineColor(9);
   hFake->SetFillColor(9);
   hReal->SetLineColor(46);
   hReal->SetFillColor(46);
   
   THStack *hst = new THStack();
   hst->Add(hReal);
   hst->Add(hFake);
   
   hst->Draw("hist e1");

   float max = hst->GetMaximum();
   
   hst->SetMaximum(1.3*max);
   hst->SetMinimum(0.);

   if( histnameFake == "h_muFake_pt" ) hst->GetXaxis()->SetTitle("p_{T} [GeV]");
   
   hst->GetYaxis()->SetTitle("Number of muons");
   
   leg->AddEntry(hFake,"Fake","f");
   leg->AddEntry(hReal,"Real","f");
   
   leg->Draw();
   
   c1->Print("pics/fake.eps");
   c1->Clear();

   TH1F *hRealScaled = (TH1F*)hReal->Clone("hRealScaled");
   hRealScaled->Scale(1./iReal);

   TH1F *hFakeScaled = (TH1F*)hFake->Clone("hFakeScaled");
   hFakeScaled->Scale(1./iFake);

   hFakeScaled->SetLineColor(9);
   hFakeScaled->SetFillColor(0);
   hRealScaled->SetLineColor(46);
   hRealScaled->SetFillColor(0);
   
   hRealScaled->Draw("hist e1");
   hFakeScaled->Draw("hist e1 same");

   float max1 = hRealScaled->GetMaximum();
   float max2 = hFakeScaled->GetMaximum();
   max = (max1 > max2) ? max1 : max2;
   
   hRealScaled->SetMaximum(1.3*max);
   hRealScaled->SetMinimum(0.);

   if( histnameFake == "h_muFake_pt" ) hRealScaled->GetXaxis()->SetTitle("p_{T} [GeV]");
   if( histnameFake == "h_muFake_trackerLayersWithMeasurement" ) hRealScaled->GetXaxis()->SetTitle("trackerLayersWithMeasurement");
   if( histnameFake == "h_muFake_numberOfValidMuonHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidMuonHits");
   if( histnameFake == "h_muFake_numberOfMatches" ) hRealScaled->GetXaxis()->SetTitle("numberOfMatches");
   if( histnameFake == "h_muFake_numberOfMatchedStations" ) hRealScaled->GetXaxis()->SetTitle("numberOfMatchedStations");
   if( histnameFake == "h_muFake_numberOfValidHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidHits");
   if( histnameFake == "h_muFake_numberOfValidPixelHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfValidPixelHits");
   if( histnameFake == "h_muFake_numberOfHits" ) hRealScaled->GetXaxis()->SetTitle("numberOfHits");
   if( histnameFake == "h_muFake_normalizedChi2GlobalTrack" ) hRealScaled->GetXaxis()->SetTitle("normalizedChi2GlobalTrack");
   if( histnameFake == "h_muFake_normalizedChi2InnerTrack" ) hRealScaled->GetXaxis()->SetTitle("normalizedChi2InnerTrack");
   
   hRealScaled->GetYaxis()->SetTitle("Normalized to unity");
   
   leg->Draw();
   
   c1->Print("pics/fakeComp.eps");
   c1->Clear();
   
   gApplication->Terminate();
}
Esempio n. 22
0
//void VHPlotter(string title="", int plot=0) {
void VHPlotter(string title="", int plot=0,   TCanvas* c1=0 ) {


    string subdir="0";
    string postfix="";
    string dirbSel="";

    double norm11 = ((Lumi2016_ele * Xsec_dy_amc1) / Ngen_dy_amc1);
    double norm12 = ((Lumi2016_ele * Xsec_dy_amc2) / Ngen_dy_amc2);
    double norm13 = ((Lumi2016_ele * Xsec_dy_amc3) / Ngen_dy_amc3);
    double norm14 = ((Lumi2016_ele * Xsec_dy_amc4) / Ngen_dy_amc4);

    double norm2 = ((Lumi2016_ele * Xsec_tt) / Ngen_tt);
    double norm3 = ((Lumi2016_ele * Xsec_zz) / Ngen_zz);
    double norm4 = ((Lumi2016_ele * Xsec_wz) / Ngen_wz);
    double norm6 = ((Lumi2016_ele * Xsec_ww) / Ngen_ww);
    double norm7 = ((Lumi2016_ele * Xsec_zhm) / Ngen_zhm);
    double norm8 = ((Lumi2016_ele * Xsec_zhp) / Ngen_zhp);

//if (ilepton==1) Lumi2016 = Lumi2016_ele;

    /*double enorm1 = ((Lumi2012 * eXsec_dy) / Ngen_dy);
    double enorm1_amc = ((Lumi2012 * eXsec_dy_amc) / Ngen_dy_amc);
    double enorm1_1 = ((Lumi2012 * eXsec_dy_1) / Ngen_dy_1);
    double enorm1_2=0;
    double enorm2 = ((Lumi2012 * eXsec_tt) / Ngen_tt);
    double enorm4 = ((Lumi2012 * eXsec_wz) / Ngen_wz);
    double enorm5 = ((Lumi2012 * eXsec_qcd) / Ngen_qcd);
    double enorm6 = ((Lumi2012 * eXsec_ww) / Ngen_ww);
    double enorm7 = ((Lumi2012 * eXsec_wj) / Ngen_wj);
    double enorm8 = ((Lumi2012 * eXsec_tS) / Ngen_tS);
    double enorm9 = ((Lumi2012 * eXsec_tT) / Ngen_tT);
    double enorm10 = ((Lumi2012 * eXsec_tW) / Ngen_tW);
    double enorm11 = ((Lumi2012 * eXsec_tSb) / Ngen_tSb);
    double enorm12 = ((Lumi2012 * eXsec_tTb) / Ngen_tTb);
    double enorm13 = ((Lumi2012 * eXsec_tWb) / Ngen_tWb);
    */

    TFile* mc11 = TFile::Open((path + "DYJetsToLL_M-50_HT-100to200_13TeV.root").c_str());
    TH1F* h_mc11 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc12 = TFile::Open((path + "DYJetsToLL_M-50_HT-200to400_13TeV.root").c_str());
    TH1F* h_mc12 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc13 = TFile::Open((path + "DYJetsToLL_M-50_HT-400to600_13TeV.root").c_str());
    TH1F* h_mc13 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc14 = TFile::Open((path + "DYJetsToLL_M-50_HT-600toInf_13TeV.root").c_str());
    TH1F* h_mc14 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc2 = TFile::Open((path + "TT_TuneCUETP8M1_13TeV.root").c_str());
    TH1F* h_mc2 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc3 = TFile::Open((path + "ZZ_TuneCUETP8M1_13TeV.root").c_str());
    TH1F* h_mc3 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc4 = TFile::Open((path + "WZ_TuneCUETP8M1_13TeV.root").c_str());
    TH1F* h_mc4 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc6 = TFile::Open((path + "WW_TuneCUETP8M1_13TeV.root").c_str());
    TH1F* h_mc6 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc7 = TFile::Open((path + "ZH_HToBB_ZToLL_M125_13TeV_amcatnlo.root").c_str());
    TH1F* h_mc7 = (TH1F*)gDirectory->Get(title.c_str());
    TFile* mc8 = TFile::Open((path + "ZH_HToBB_ZToLL_M125_13TeV_powheg.root").c_str());
    TH1F* h_mc8 = (TH1F*)gDirectory->Get(title.c_str());

//TFile* data = TFile::Open((path + "SingleElectron-Run2016B-v2.root").c_str());;
//TH1F* h_data = (TH1F*)gDirectory->Get(title.c_str());

    TFile* data_runB = TFile::Open((path + "SingleElectron-Run2016B-v2.root").c_str());
    TH1F* h_data_runB = (TH1F*)gDirectory->Get(title.c_str());

    TFile* data_runC = TFile::Open((path + "SingleElectron-Run2016C-v2.root").c_str());
    TH1F* h_data_runC = (TH1F*)gDirectory->Get(title.c_str());

    TFile* data_runD = TFile::Open((path + "SingleElectron-Run2016D-v2.root").c_str());
    TH1F* h_data_runD = (TH1F*)gDirectory->Get(title.c_str());

    TH1F* h_data = (TH1F*)h_data_runB ->Clone("h_data");
    h_data->Reset();
    h_data->Add( h_data_runB );
    h_data->Add( h_data_runC );
    h_data->Add( h_data_runD );

    h_mc2 -> SetLineColor(kBlack);
    h_mc2 -> SetFillColor(kBlue);
//h_mc2 -> SetFillStyle(3004);

    h_mc3 -> SetLineColor(kBlack);
    h_mc3 -> SetFillColor(kGray+2);
//h_mc3 -> SetFillStyle(3004);

//h_mc4 -> SetLineColor(kBlack);
//h_mc4 -> SetFillColor(kGray+3);
//h_mc4 -> SetFillStyle(3004);

//h_mc6 -> SetLineColor(kBlack);
//h_mc6 -> SetFillColor(kRed+2);
//h_mc6 -> SetFillStyle(3004);

    h_mc7 -> SetLineColor(kBlack);
    h_mc7 -> SetFillColor(kMagenta);
//h_mc7 -> SetFillStyle(3004);

    h_mc8 -> SetLineColor(kGreen);
//h_mc8 -> SetLineColor(kBlack);
//h_mc8 -> SetFillColor(kPink);
//h_mc8 -> SetFillStyle(3004);
    h_mc8 ->SetLineWidth(3);

    h_mc11->Scale(norm11);
    h_mc12->Scale(norm12);
    h_mc13->Scale(norm13);
    h_mc14->Scale(norm14);
    h_mc2->Scale(norm2);
    h_mc3->Scale(norm3);
    h_mc4->Scale(norm4);
    h_mc6->Scale(norm6);
    h_mc7->Scale(norm7);
    h_mc8->Scale(norm8);

    TH1F* h_mcDY = (TH1F*)h_mc11->Clone("h_mcDY");
    h_mcDY->Reset();
    h_mcDY->Add(h_mc14);
    h_mcDY->Add(h_mc13);
    h_mcDY->Add(h_mc12);
    h_mcDY->Add(h_mc11);

    h_mcDY -> SetLineColor(kBlack);
    h_mcDY -> SetFillColor(kYellow-4);
//h_mcDY -> SetFillStyle(3004);

    TH1F* h_mcDiboson = (TH1F*)h_mc3->Clone("h_mcDiboson");
    h_mcDiboson->Reset();
    h_mcDiboson->Add(h_mc3);
    h_mcDiboson->Add(h_mc4);
    h_mcDiboson->Add(h_mc6);


    TH1F *ht = (TH1F*)h_mcDY->Clone("ht");
    ht->Reset();
//ht->Add(h_mc8);
    ht->Add(h_mc7);
//ht->Add(h_mc6);
//ht->Add(h_mc4);
//ht->Add(h_mc3);
    ht->Add(h_mcDiboson);
    ht->Add(h_mc2);
    ht->Add(h_mcDY);

    THStack *hs = new THStack("hs","");
//hs->Add(h_mc8); // ZH powheg
    hs->Add(h_mc7);   // ZH madgraph
//hs->Add(h_mc6);
//hs->Add(h_mc4);
//hs->Add(h_mc3);
    hs->Add(h_mcDiboson);
    hs->Add(h_mc2);
    hs->Add(h_mcDY);

//TCanvas* c1 = 0;
//c1 = new TCanvas("c","c",10,10,800,600);
    c1->cd();

    TPad *pad1 = new TPad("pad1","pad1",0.0,0.3,1.0,1.0);
    pad1->SetBottomMargin(0.001);
    pad1->Draw();
    pad1->cd();

    if( title=="FATjetSDmass" || title=="FATjetSDmassCorr" || title=="FATjetPRmass" || title=="FATjetPRmassCorr" || title=="FATnSubjet" || title=="ZHmass" )
    {
        pad1->SetLogy();
    }

    hs->Draw("HIST");
    hs->GetYaxis()->SetTitle("Events");
    hs->GetYaxis()->SetTitleSize(0.05);
    hs->GetYaxis()->SetLabelSize(0.045);
    hs->GetYaxis()->SetTitleOffset(1.0);// 0.7
//hs->SetMinimum(8);
    hs->SetMinimum(0.1);
    hs->SetMaximum(1.2*hs->GetMaximum());
    if (title=="ZHmass") {
        hs->GetXaxis()->SetRangeUser(0, 3000);
    }

    h_mc8->Draw("same hist");


    h_data->Draw("EPX0SAMES");
    h_data->SetMarkerColor(kBlack);
    h_data->SetMarkerStyle(20);
    h_data->SetMarkerSize (1.0);
    h_data->SetStats(0);

    TLegend *leg;

    if (title=="FATjetTau2dvTau1") {
        leg = new TLegend(0.15, 0.547, 0.41, 0.88);
    }
    else {
        leg = new TLegend(0.65, 0.547, 0.91, 0.88);
    }
//leg = new TLegend(0.65, 0.547, 0.91, 0.88);
    leg->SetBorderSize(0);
    leg->SetEntrySeparation(0.01);
    leg->SetFillColor(0);
    leg->SetFillStyle(0);

    leg->AddEntry(h_data,"Data","p");
    leg->AddEntry(h_mcDY,"DY","f");
    leg->AddEntry(h_mc2,"t#bar{t}","f");
//leg->AddEntry(h_mc3,"ZZ","f");
//leg->AddEntry(h_mc4,"WZ","f");
//leg->AddEntry(h_mc6,"WW","f");
    leg->AddEntry(h_mcDiboson,"Diboson","f");
    leg->AddEntry(h_mc7,"ZH madgraph","f");
    leg->AddEntry(h_mc8,"ZH powheg (not in stack)","f");

    leg->Draw();

    TLatex *lar = new TLatex();
    lar->SetNDC(kTRUE);
    lar->SetTextSize(0.04);
    lar->SetLineWidth(5);
    lar->DrawLatex(0.14, 0.94, "CMS #it{#bf{2016}}");
    lar->DrawLatex(0.60, 0.94, "L = 12.7 fb^{-1} at #sqrt{s} = 13 TeV");

    pad1->Update();
    c1->Update();

    c1->cd();

    TH1F *h_ratio = (TH1F*)h_data->Clone("h_ratio");

    TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.3);// 0.3
    pad2->SetTopMargin(0);
    pad2->SetBottomMargin(0.3);
    pad2->Draw();
    pad2->cd();
    h_ratio->SetTitle("");
    h_ratio->SetStats(0);

    if (title=="Zpt") {
        h_ratio->GetXaxis ()->SetTitle("p_{T}(Z) [GeV/c]");
    } else if (title=="Zmass") {
        h_ratio->GetXaxis ()->SetTitle("M(Z) [GeV/c^{2}]");//
    } else if (title=="ZRapidity") {
        h_ratio->GetXaxis ()->SetTitle("y(Z)");
    } else if (title=="Zeta") {
        h_ratio->GetXaxis ()->SetTitle("#eta(Z)");
    } else if (title=="nVtx") {
        h_ratio->GetXaxis ()->SetTitle("Number of Vertices");
    } else if (title=="leadElePt") {
        h_ratio->GetXaxis ()->SetTitle("Leading Electron p_{T} [GeV/c]");
    } else if (title=="subleadElePt") {
        h_ratio->GetXaxis ()->SetTitle("Sub-Leading Electron p_{T} [GeV/c]");
    } else if (title=="leadEleEta") {
        h_ratio->GetXaxis ()->SetTitle("Leading Electron #eta");
    } else if (title=="subleadEleEta") {
        h_ratio->GetXaxis ()->SetTitle("Sub-Leading Electron #eta");
    } else if (title=="FATjetPt") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet p_{T} [GeV/c]");
    } else if (title=="FATjetEta") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet #eta");
    } else if (title=="FATjetCISVV2") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet CSVv2");
    } else if (title=="FATjetSDmass") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet Soft Drop Mass [GeV/c^{2}]");
    } else if (title=="FATjetSDmassCorr") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet Corrected Soft Drop Mass [GeV/c^{2}]");
    }   else if (title=="FATjetPRmass") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet Pruned Mass [GeV/c^{2}]");
    } else if (title=="FATjetPRmassCorr") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet L2L3 Corrected Pruned Mass [GeV/c^{2}]");
    } else if (title=="FATjetTau1") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet #tau_{1}");
    } else if (title=="FATjetTau2") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet #tau_{2}");
    } else if (title=="FATjetTau2dvTau1") {
        h_ratio->GetXaxis ()->SetTitle("FAT Jet #tau_{21}");
    } else if (title=="FATnSubjet") {
        h_ratio->GetXaxis ()->SetTitle("Number of Subjets");
    } else if (title=="FATsubjetLeadingPt") {
        h_ratio->GetXaxis ()->SetTitle("Leading SubJet p_{T} [GeV/c]");
    } else if (title=="FATsubjetLeadingEta") {
        h_ratio->GetXaxis ()->SetTitle("Leading SubJet #eta");
    } else if (title=="FATsubjetLeadingSDCSV") {
        h_ratio->GetXaxis ()->SetTitle("Leading SubJet Soft Drop CSV");
    } else if (title=="FATsubjetSubLeadingPt") {
        h_ratio->GetXaxis ()->SetTitle("Sub-Leading SubJet p_{T} [GeV/c]");
    } else if (title=="FATsubjetSubLeadingEta") {
        h_ratio->GetXaxis ()->SetTitle("Sub-Leading SubJet #eta");
    } else if (title=="FATsubjetSubLeadingSDCSV") {
        h_ratio->GetXaxis ()->SetTitle("Sub-Leading SubJet Soft Drop CSV");
    } else if (title=="ADDjet_DoubleSV") {
        h_ratio->GetXaxis ()->SetTitle("ADDjet double b-tagger discriminator");
    }  else if (title=="ZHmass") {
        h_ratio->GetXaxis ()->SetTitle("ZH invariant mass [GeV/c^{2}]");
    }

    if (title=="ZHmass") {
        h_ratio->GetXaxis()->SetRangeUser(0, 3000);
    }
    h_ratio->GetXaxis()->SetTitleSize(0.11);
    h_ratio->GetXaxis()->SetLabelFont(42);
    h_ratio->GetXaxis()->SetLabelSize(0.10);
    h_ratio->GetXaxis()->SetTitleFont(42);
    h_ratio->GetYaxis()->SetTitle("Data/MC");
    h_ratio->GetYaxis()->SetNdivisions(505);
    h_ratio->GetYaxis()->SetTitleSize(0.11);
    h_ratio->GetYaxis()->SetLabelSize(0.10);
    h_ratio->GetYaxis()->SetRangeUser(0.2, 2);
    h_ratio->GetYaxis()->SetTitleOffset(0.33);

    h_ratio->Divide(ht);
    h_ratio->SetMarkerStyle(20);
    h_ratio->Draw("E0PX0");

    TLine *OLine = new TLine(h_ratio->GetXaxis()->GetXmin(),1.,h_ratio->GetXaxis()->GetXmax(),1.);
    OLine->SetLineColor(kRed);
    OLine->SetLineWidth(2);
    OLine->Draw();

    /*
    TLatex *lar = new TLatex();
    lar->SetNDC(kTRUE);
    lar->SetTextSize(0.04);
    lar->SetLineWidth(5);
    lar->DrawLatex(0.14, 0.94, "CMS #it{#bf{2016}}");
    lar->DrawLatex(0.60, 0.94, "L = 4.327 fb^{-1} at #sqrt{s} = 13 TeV");
    */

    c1->cd();
//c1->SaveAs((path + title + ".pdf").c_str());

}
Esempio n. 23
0
void Plotter::Plot(std::string filename) {

	gROOT->Reset();
	//gROOT->SetStyle("Plain");

	TStyle *MyStyle = new TStyle("MyStyle","My Root Styles");
  MyStyle->SetPaperSize(20,24);
	MyStyle->SetStatColor(0);
	MyStyle->SetCanvasColor(0);
	MyStyle->SetPadColor(0);
	MyStyle->SetPadBorderMode(0);
	MyStyle->SetCanvasBorderMode(0);
	MyStyle->SetFrameBorderMode(0);
	MyStyle->SetOptStat(0);
	MyStyle->SetStatBorderSize(2);
	MyStyle->SetOptTitle(0);
	MyStyle->SetPadTickX(1);
	MyStyle->SetPadTickY(1);
	MyStyle->SetPadBorderSize(2);
	MyStyle->SetPalette(51, 0);
	MyStyle->SetPadBottomMargin(0.15);
	MyStyle->SetPadTopMargin(0.05);
	MyStyle->SetPadLeftMargin(0.15);
	MyStyle->SetPadRightMargin(0.25);
	MyStyle->SetTitleColor(1);
	MyStyle->SetTitleFillColor(0);
	MyStyle->SetTitleFontSize(0.05);
	MyStyle->SetTitleBorderSize(0);
	MyStyle->SetLineWidth(1);
	MyStyle->SetHistLineWidth(3);
	MyStyle->SetLegendBorderSize(0);
	MyStyle->SetNdivisions(502, "x");
	MyStyle->SetMarkerSize(0.8);
	MyStyle->SetTickLength(0.03);
	MyStyle->SetTitleOffset(1.5, "x");
	MyStyle->SetTitleOffset(1.5, "y");
	MyStyle->SetTitleOffset(1.0, "z");
	MyStyle->SetLabelSize(0.05, "x");
	MyStyle->SetLabelSize(0.05, "y");
	MyStyle->SetLabelSize(0.05, "z");
	MyStyle->SetLabelOffset(0.03, "x");
	MyStyle->SetLabelOffset(0.03, "y");
	MyStyle->SetLabelOffset(0.03, "z");
	MyStyle->SetTitleSize(0.05, "x");
	MyStyle->SetTitleSize(0.05, "y");
	MyStyle->SetTitleSize(0.05, "z");
	gROOT->SetStyle("MyStyle");

	//gROOT->ForceStyle();

	bool DrawLog = false;

	for (int i = 0; i < N_histos; ++i) {

		THStack *hs;
		TLegend *l;

    int Nset = data.size() + bg.size() + signal.size();
    if (Nset > 20)
       Nset = 20.;
    l = new TLegend(0.76, 0.95 - 0.8 * Nset / 20., 1.0, 0.95);
    l->SetFillStyle(1001);
    l->SetFillColor(kWhite);
    l->SetLineColor(kWhite);
    l->SetLineWidth(2);

		if (bg.size() > 0) {

			hs = new THStack("hs", bg.at(0).at(i)->GetName());
			int j = 0;
			for (std::vector<std::vector<TH1F*> >::const_iterator it = bg.begin(); it != bg.end(); ++it) {

        TH1F *histogram = it->at(i);

				switch (j) {
               case 0:
                  histogram->SetFillColor(kRed);
                  break;
               case 1:
                  histogram->SetFillColor(kOrange);
                  break;
               case 2:
                  histogram->SetFillColor(kYellow);
                  break;
               case 3:
                  histogram->SetFillColor(kGreen);
                  break;
               case 4:
                  histogram->SetFillColor(kCyan);
                  break;
               case 5:
                  histogram->SetFillColor(kBlue);
                  break;
               case 6:
                  histogram->SetFillColor(kMagenta);
                  break;
               case 7:
                  histogram->SetFillColor(kGray);
                  break;
               case 8:
                  histogram->SetFillColor(kGray + 2);
                  break;
               default:
                  histogram->SetFillColor(kBlack);
                  break;
				}
				hs->Add(histogram);
				l->AddEntry(histogram, bg_names.at(j).c_str(), "f");
				++j;
			}
		}
		TCanvas *c = new TCanvas("c", "c", 800, 600);
		c->SetLogy(DrawLog);
    std::string plotname;

		if (data.size() > 0) {
      plotname = std::string(data.at(0).at(i)->GetName());
			data.at(0).at(i)->SetMaximum(1.5 * data.at(0).at(i)->GetMaximum());
			data.at(0).at(i)->GetXaxis()->SetTitleOffset(1.3);
			data.at(0).at(i)->GetYaxis()->SetTitleOffset(1.3);
			data.at(0).at(i)->GetYaxis()->SetTitle("Events");
			data.at(0).at(i)->GetXaxis()->SetNdivisions(505);
			data.at(0).at(i)->Draw("");
			l->AddEntry(data.at(0).at(i), data_names.at(0).c_str(), "p");

      if (bg.size() > 0)
        hs->Draw("histsame");

      data.at(0).at(i)->SetMarkerStyle(20);
      data.at(0).at(i)->Draw("psame");
      l->Draw("same");
		}

		if (data.size() == 0 && bg.size() > 0) {
      plotname = std::string(bg.at(0).at(i)->GetName());
			hs->Draw("hist");
      hs->GetXaxis()->SetTitleOffset(1.3);
      hs->GetXaxis()->SetNdivisions(505);
      hs->GetYaxis()->SetTitleOffset(1.3);

      if (bg.size() > 0)
        hs->GetXaxis()->SetTitle(bg.at(0).at(i)->GetXaxis()->GetTitle());

      hs->GetYaxis()->SetTitle("Events");
      l->Draw("same");
		}

    // if (i==2) {
    //   TLine *line = new TLine(2, 500*1000 , 2, 0);
    //   line->SetLineColor(kBlack);
    //   line->Draw("histsame");
    // }

    // if (i==4) {
    //   TLine *line = new TLine(1, 35000 , 1, 0);
    //   line->SetLineColor(kBlack);
    //   line->Draw("histsame");
    // }

    // if (i==6) {
    //   TLine *line = new TLine(1, 900 , 1, 0);
    //   line->SetLineColor(kBlack);
    //   line->Draw("histsame");
    // }

//      c->Print((filename+std::string("_")+plotname+std::string(".pdf")).c_str());
		if (i == 0 && N_histos > 1) {
			c->Print((filename+std::string("(")).c_str());
		} else if (i > 0 && i == N_histos - 1)
			c->Print((filename+std::string(")")).c_str());
		else
			c->Print(filename.c_str());

	}

}
Esempio n. 24
0
void doPlotsBtag_Log(bool logPlot){
setTDRStyle();

double lumi = 5800;
//stuff to choose
//bool logPlot = false; //true for log plot
int rebinFact = 1;

//isolation selection
//TString Isolation = "QCD No Iso/";
TString Isolation = "Ref selection/";
//TString Isolation = "QCD mu+jets PFRelIso/";
//TString Isolation = "QCD non iso mu+jets/";

TString Systematic = "central";

// number of btags
TString Nbtags = "2btags";  //standard  "2btags" , qcd "0btag"

//choose object
TString Obj = "";
//TString Obj = "MET/";

//muon variables
const int N = 2;
TString Variable;
TString Variables[N] = {"N_BJets", "N_BJets_reweighted"};
double MinXs[N] = {-0.5,-0.5};
double MaxXs[N] = {7.5,7.5};
TString XTitles[N] = {"B-tag Multiplicity", "B-tag Multiplicity"};



//loop over variables
for(int i = 0; i<2; i++){
double MinX = MinXs[i];
double MaxX = MaxXs[i];
Variable = Variables[i];
TString Xtitle = XTitles[i];

//Data
TH1D* data = getSample("SingleMu", 1, Obj, Variable, Isolation, rebinFact, "central");

//MC
TH1D* tt = getSample("TTJet", lumi*225.2/6920475, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* wjets = getSample("W1Jet", lumi*37509/57708550, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* zjets = getSample("DY1JetsToLL", lumi*5745.25/30457954, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* qcd = getSample("QCD_Pt-15to20_MuEnrichedPt5",     lumi*34679.3/8500505, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5",   lumi*2.87e8 * 0.0065/8486893, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5",   lumi*6.609e7 * 0.0122/8928999, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5",   lumi*8082000.0 * 0.0218/7256011, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5",  lumi*1024000.0 * 0.0395/9030624, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5",     lumi*0.774 * 0.1097/3807263, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948, Obj, Variable, Isolation, rebinFact, Systematic);

//make combined top and single top template
TH1D* sing_top = (TH1D*)top_t->Clone("top");
sing_top->Add(top_tw);sing_top->Add(top_s); sing_top->Add(tbar_t); sing_top->Add(tbar_tw);sing_top->Add(tbar_s);

zjets->Add(z2jets);
zjets->Add(z3jets);
zjets->Add(z4jets);  

wjets->Add(w2jets);
wjets->Add(w3jets);
wjets->Add(w4jets);

//make combined top and single top template
TH1D* qcd_all = (TH1D*)qcd->Clone("qcd_all");
qcd_all->Add(qcd2);
qcd_all->Add(qcd3);
qcd_all->Add(qcd4);
qcd_all->Add(qcd5);
qcd_all->Add(qcd6);
qcd_all->Add(qcd7);
qcd_all->Add(qcd8);
qcd_all->Add(qcd9);
qcd_all->Add(qcd10);
qcd_all->Add(qcd11);
  
THStack *hs = new THStack("hs","test");

qcd_all->SetLineColor(kBlack);
zjets->SetLineColor(kBlack);
wjets->SetLineColor(kBlack);	
sing_top->SetLineColor(kBlack);
tt->SetLineColor(kBlack);	

  hs->Add(qcd_all);
  hs->Add(zjets);
  hs->Add(wjets);
  hs->Add(sing_top);
  hs->Add(tt);

  //draw histos to files
  TCanvas *c1 = new TCanvas("Plot","Plot",900, 600);
		
  hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.2);
  hs->SetMinimum(1.);
  
  hs->Draw();
  data->Draw("E same");
  data->SetMarkerStyle(20);

//events:
cout << "ttbar: " << tt->Integral() << endl;
cout << "data: " << data->Integral() << endl;
  
  if(logPlot == true){
  hs->GetXaxis()->SetLimits(MinX, MaxX);
  }else{
  hs->GetXaxis()->SetLimits(MinX, 4.5);
  }
  
  hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05);
  hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);
  
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.7,0.7,0.8,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(data , "2012 data", "lpe");
	tleg2->AddEntry(tt , "t#bar{t}", "f");
	tleg2->AddEntry(sing_top, "single top", "f");
	tleg2->AddEntry(wjets , "w+jets", "f");
	tleg2->AddEntry(zjets , "z+jets", "f");
	tleg2->AddEntry(qcd_all , "QCD", "f");
	
	//tleg2->AddEntry(singtEff, "single-t"      , "l");
	//tleg2->AddEntry(singtwEff, "single-tW"      , "l");
 	tleg2->Draw("same");	
	
	if(logPlot == true){
  	TText* textPrelim = doPrelim(0.12,0.96, "#geq 0 btags");
	textPrelim->Draw();
  	}else{
	TText* textPrelim = doPrelim(0.2,0.96, "");
	textPrelim->Draw();
	}
	
  if(logPlot ==true){
  c1->SetLogy();
  }	
  
  TString plotName("Plots/TTbarPlusVarAnalysis/Nbtags/");
  
  if(logPlot ==true){
    plotName += Variable+"_Log";  
  }else{
    plotName += Variable;  
  }
 
 
  c1->SaveAs(plotName+".pdf");
  c1->SaveAs(plotName+".png");
  delete c1;
  
  }
  	
}
Esempio n. 25
0
void makeStack(TString myVar, TString myCut, TString myName, TString myAxisNameX, TString myAxisNameY, 
               vector<const Sample*>& listOfSignals, vector<const Sample*>& listOfSamples, vector<const Sample*> listOfDatasets, 
               TString inFileName,
               bool isBlind, bool isLog, bool drawSignal, bool drawLegend,
               int nBins, float xLow, float xHigh,
               float* xlowVec)
{
  // prepare the input file
  TFile* infile = new TFile(inFileName, "READ"); 
  infile -> cd();
  
  // prepare the stack
  THStack *hs = new THStack("hs","");
  // prepare the histos pointers
  TH1F*   hist[20];
  // prepare the tree pointers
  TTree*  tree[20];
  // prepare the legend
  TLegend* leg = new TLegend(.7485,.7225,.9597,.9604);
  leg->SetFillColor(0);
  // prepare the colors
  Int_t col[20] = {46,2,12,5,3,4,9,7,47,49,49,50,51,52,53,54,55,56,57,58};
  // prepare the cut
  if (isBlind) myCut += "*(phoMetDeltaPhi < 2.9)";        
  // prepare the Y axis lable
  if (xlowVec != 0) myAxisNameY = "Events/" + myAxisNameY;
  else {
    float binWidth = (xHigh-xLow)/nBins;
    TString tempString;
    tempString.Form("%.2f ",binWidth); 
    myAxisNameY = "Events/" + tempString + myAxisNameY;
  }
  // prepare the legend strings
  vector<TString> theLegends;
  
  // loop through the datasets and produce the plots
  TH1F* hdata;
  TH1F* hsignal;
  //prepare data and signal histos
  if (xlowVec != 0) hdata   = new TH1F("hdata","",nBins,xlowVec);
  else hdata = new TH1F("hdata","",nBins,xLow,xHigh);
  if (xlowVec != 0) hsignal = new TH1F("hsignal","",nBins,xlowVec);
  else hsignal = new TH1F("hsignal","",nBins,xLow,xHigh);

  TTree*  treedata[20];
  for (UInt_t iDatas=0; iDatas < listOfDatasets.size(); iDatas++) {
    //get the tree
    treedata[iDatas] = (TTree*) infile -> Get(listOfDatasets.at(iDatas)->Name()->Data());

    //fill the histogram
    if ( iDatas == 0 ) treedata[iDatas] -> Draw(myVar + " >> hdata","evt_weight*kf_weight*pu_weight" + myCut);
    else treedata[iDatas] -> Draw(myVar + " >>+ hdata","evt_weight*kf_weight*pu_weight" + myCut);
    
    if ( isBlind && iDatas == 0 ) leg -> AddEntry(hdata, "DATA (19.8 fb^{-1})", "pl");    
    
  }//end loop on datasets
  if (xlowVec != 0) {
    for (int iBin = 1; iBin <= nBins; iBin++) hdata->SetBinError  (iBin,hdata->GetBinError(iBin)/hdata->GetBinWidth(iBin));
    for (int iBin = 1; iBin <= nBins; iBin++) hdata->SetBinContent(iBin,hdata->GetBinContent(iBin)/hdata->GetBinWidth(iBin));
  }

  TTree*  treesignal[20];
  for (UInt_t iSignal=0; iSignal < listOfSignals.size(); iSignal++) {
    //get the tree
    treesignal[iSignal] = (TTree*) infile -> Get(listOfSignals.at(iSignal)->Name()->Data());

    //fill the histogram
    TString thisScale = Form("%f *", *(listOfSignals.at(iSignal)->Scale()));
    if ( iSignal == 0 ) treesignal[iSignal] -> Draw(myVar + " >> hsignal",thisScale + "evt_weight*kf_weight*pu_weight" + myCut);
    else treesignal[iSignal] -> Draw(myVar + " >>+ hsignal",thisScale + "evt_weight*kf_weight*pu_weight" + myCut);
    
    if ( drawSignal && iSignal == 0 ) leg -> AddEntry(hsignal, "Signal", "l");    
    
  }//end loop on signals
  if (xlowVec != 0) {
    for (int iBin = 1; iBin <= nBins; iBin++) hsignal->SetBinError  (iBin,hsignal->GetBinError(iBin)/hsignal->GetBinWidth(iBin));
    for (int iBin = 1; iBin <= nBins; iBin++) hsignal->SetBinContent(iBin,hsignal->GetBinContent(iBin)/hsignal->GetBinWidth(iBin));
  }
  hsignal -> SetLineColor(49);
  hsignal -> SetLineWidth(4.0);
       
  int theHistCounter = 0;
  // loop through the samples and produce the plots
  for (UInt_t iSample=0; iSample < listOfSamples.size(); iSample++) {

    //determine if the histo is first of the series
    bool isFirstOfSerie = (*listOfSamples.at(iSample)->Legend()).CompareTo(" ");
    bool isLastOfSerie = false;
    if (iSample == listOfSamples.size() - 1) isLastOfSerie = true;
    if (iSample < listOfSamples.size() - 1 && (*listOfSamples.at(iSample+1)->Legend()).CompareTo(" ") != 0) isLastOfSerie = true;
    
    //get the tree
    tree[iSample] = (TTree*) infile -> Get(listOfSamples.at(iSample)->Name()->Data());
    //if sample first of the list create a new histogram
    if (isFirstOfSerie) {
       TString thisHistName = "h_" + *(listOfSamples.at(iSample)->Name());
       //variable bin histo
       if (xlowVec != 0) hist[theHistCounter] = new TH1F(thisHistName,thisHistName,nBins,xlowVec);
       //fixed bin histo
       else hist[theHistCounter] = new TH1F(thisHistName,thisHistName,nBins,xLow,xHigh);
       hist[theHistCounter] -> Sumw2();
       hist[theHistCounter] -> SetFillColor(col[theHistCounter]);
       hist[theHistCounter] -> SetFillStyle(1001);
       theLegends.push_back(*listOfSamples.at(iSample)->Legend());
    }

    //fill the histogram
    TString thisScale = Form("%f *", *(listOfSamples.at(iSample)->Scale()));
    if (isFirstOfSerie) tree[iSample] -> Draw(myVar + " >> " + TString(hist[theHistCounter] -> GetName()),thisScale + "evt_weight*kf_weight*pu_weight" + myCut);
    else tree[iSample] -> Draw(myVar + " >>+ " + TString(hist[theHistCounter] -> GetName()),thisScale + "evt_weight*kf_weight*pu_weight" + myCut);
    
    //add the histogram to the stack if the last of the series:
    //either last sample or ~ sample followed by non ~ sample
    if (isLastOfSerie) {
       if (xlowVec != 0) {
         for (int iBin = 1; iBin <= nBins; iBin++) hist[theHistCounter]->SetBinError  (iBin,hist[theHistCounter]->GetBinError(iBin)/hist[theHistCounter]->GetBinWidth(iBin));
         for (int iBin = 1; iBin <= nBins; iBin++) hist[theHistCounter]->SetBinContent(iBin,hist[theHistCounter]->GetBinContent(iBin)/hist[theHistCounter]->GetBinWidth(iBin));
       }
       hs -> Add(hist[theHistCounter]);
       theHistCounter++;
    }
    
  }//end loop on samples

  //Fix the legend
  for (int iHisto = theHistCounter-1; iHisto >= 0; iHisto--) {
    leg -> AddEntry(hist[iHisto], theLegends[iHisto], "f");   
  }
  
  //get the maximum to properly set the frame
  float theMax = hdata -> GetBinContent(hdata -> GetMaximumBin()) + hdata -> GetBinError(hdata -> GetMaximumBin());
  TH1* theMCSum = (TH1*) hs->GetStack()->Last();
  float theMaxMC = theMCSum->GetBinContent(theMCSum->GetMaximumBin()) + theMCSum->GetBinError(theMCSum->GetMaximumBin());
  if (theMaxMC > theMax) theMax = theMaxMC;
  
  //prepare the ratio band and plot
  TH1* theMCRatioBand = makeRatioBand(theMCSum);
  TH1* theRatioPlot = makeRatioPlot(hdata,theMCSum);
    
  TCanvas* can = new TCanvas();
  can -> SetLogy(isLog);
  
  TPad *pad1 = new TPad("pad1","top pad",0,0.30,1,1);
  pad1->SetBottomMargin(0.02);
  pad1->SetLeftMargin(0.13);
  pad1->Draw();
  TPad *pad2 = new TPad("pad2","bottom pad",0,0.0,1,0.30);
  pad2->SetTopMargin(0.02);
  pad2->SetLeftMargin(0.13);
  pad2->SetBottomMargin(0.4);
  pad2->SetGridy();
  pad2->Draw();
  
  pad1->cd();
  hs->Draw("hist");
  hdata->Draw("same,pe");
  if (drawSignal) hsignal->Draw("same,hist");
  if (drawLegend) leg->Draw("same");
  //hs->GetXaxis()->SetTitle(myAxisNameX);
  hs->GetYaxis()->SetTitle(myAxisNameY);
  hs->GetXaxis()->SetLabelSize(0.04);
  hs->GetYaxis()->SetLabelSize(0.04);
  hs->GetXaxis()->SetLabelOffset(0.025);
  hs->GetYaxis()->SetLabelOffset(0.035);
  //hs->GetXaxis()->SetTitleOffset(1.1);
  hs->GetYaxis()->SetTitleOffset(1.1);
  hs->SetMaximum(theMax);
  if (isLog) hs->SetMinimum(0.01);
  
  pad2->cd();
  theMCRatioBand->GetXaxis()->SetTitle(myAxisNameX);
  theMCRatioBand->GetXaxis()->SetTitleSize(0.16);
  theMCRatioBand->GetXaxis()->SetTitleOffset(1.1);
  theMCRatioBand->GetXaxis()->SetLabelSize(0.12);
  theMCRatioBand->GetXaxis()->SetLabelOffset(0.07);
  theMCRatioBand->GetYaxis()->SetTitle("Data/MC");
  theMCRatioBand->GetYaxis()->SetTitleSize(0.10);
  theMCRatioBand->GetYaxis()->SetTitleOffset(0.6);
  theMCRatioBand->GetYaxis()->SetLabelSize(0.06);
  theMCRatioBand->GetYaxis()->SetLabelOffset(0.03);
  theMCRatioBand->SetFillStyle(3001);
  theMCRatioBand->SetFillColor(kBlue);
  theMCRatioBand->SetLineWidth(1);
  theMCRatioBand->SetLineColor(kBlack);
  theMCRatioBand->SetMarkerSize(0.1);
  theMCRatioBand->SetMaximum(4.);
  theMCRatioBand->SetMinimum(0.);
  theMCRatioBand->Draw("E2");
  TLine *line = new TLine(xLow,1,xHigh,1);
  line->SetLineColor(kBlack);
  line->Draw("same");
  theRatioPlot->Draw("same,pe");
  
  can->cd();
  can->Modified();
  can -> SaveAs(myName + ".pdf","pdf");
  
  //cleanup the memory allocation
  delete theMCSum;
  delete hs;
  delete leg;
  delete hdata;
  delete pad1;
  delete pad2;
  delete can;
  delete theMCRatioBand;
  delete theRatioPlot;
  infile -> Close();
  delete infile;
  
  return;
}
Esempio n. 26
0
void doPlotsBtag(){
setTDRStyle();

//loop over variables
for(int i = 0; i<2; i++){
double MinX = MinXs[i];
double MaxX = MaxXs[i];
Variable = Variables[i];
TString Xtitle = XTitles[i];

//Data
TH1D* data = getSample("SingleMu", 1);

//MC
TH1D* tt = getSample("TTJet", lumi*225.2/6920475);

TH1D* wjets = getSample("W1Jet", lumi*37509/57708550);
TH1D* w1jets = getSample("W1Jet", lumi*5400.0/23140779);
TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404);
TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443);
TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904);

TH1D* zjets = getSample("DY1JetsToLL", lumi*5745.25/30457954);
TH1D* z1jets = getSample("DY1JetsToLL", lumi*561.0/24042904);
TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749);
TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628);
TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785);

TH1D* qcd = getSample("QCD_Pt-15to20_MuEnrichedPt5",     lumi*34679.3/8500505);
TH1D* qcd1 = getSample("QCD_Pt-15to20_MuEnrichedPt5",   lumi*7.022e8 * 0.0039/1722678);
TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5",   lumi*2.87e8 * 0.0065/8486893);
TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5",   lumi*6.609e7 * 0.0122/8928999);
TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5",   lumi*8082000.0 * 0.0218/7256011);
TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5",  lumi*1024000.0 * 0.0395/9030624);
TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505);
TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483);
TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481);
TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767);
TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142);
TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5",     lumi*0.774 * 0.1097/3807263);

TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707);
TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395);
TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516);
TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817);
TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239);
TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948);

THStack *hs = new THStack("hs","test");
  if(inclQ == true){
  hs->Add(qcd);
  }else{
  hs->Add(qcd1);
  hs->Add(qcd2);
  hs->Add(qcd3);
  hs->Add(qcd4);
  hs->Add(qcd5);
  hs->Add(qcd6);
  hs->Add(qcd7);
  hs->Add(qcd8);
  hs->Add(qcd9);
  hs->Add(qcd10);
  hs->Add(qcd11);
  }
  
  
  if(inclZ == true){
  hs->Add(zjets);
  }else{
  hs->Add(z1jets);
  hs->Add(z2jets);
  hs->Add(z3jets);
  hs->Add(z4jets);  
  }
  
  if(inclW == true){
  hs->Add(wjets);
  }else{
  hs->Add(w1jets);
  hs->Add(w2jets);
  hs->Add(w3jets);
  hs->Add(w4jets);  
  }
      
  hs->Add(top_t);
  hs->Add(top_tw);
  hs->Add(top_s);
  hs->Add(tbar_t);
  hs->Add(tbar_tw);
  hs->Add(tbar_s);
  
  hs->Add(tt);

  //draw histos to files
  TCanvas *c1 = new TCanvas("Plot","Plot",900, 600);
		
  hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.2);

  hs->Draw();
  data->Draw("E same");
  data->SetMarkerStyle(20);

//events:
cout << "ttbar: " << tt->Integral() << endl;
cout << "data: " << data->Integral() << endl;
  
  hs->GetXaxis()->SetLimits(MinX, MaxX);
  hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05);
  hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);
  
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.7,0.7,0.8,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(data , "2012 data", "lpe");
	tleg2->AddEntry(tt , "t#bar{t}", "lf");
	tleg2->AddEntry(top_t, "single top", "lf");
	tleg2->AddEntry(wjets , "w+jets", "lf");
	tleg2->AddEntry(zjets , "z+jets", "lf");
	tleg2->AddEntry(qcd , "QCD", "lf");
	
	//tleg2->AddEntry(singtEff, "single-t"      , "l");
	//tleg2->AddEntry(singtwEff, "single-tW"      , "l");
 	tleg2->Draw("same");	
	
	TText* textPrelim = doPrelim(0.17,0.96);
	textPrelim->Draw();
	
  if(logPlot ==true){
  c1->SetLogy();
  }	
  
  TString plotName("plots/Control/Btags/");
  
  if(logPlot ==true){
    plotName += Variable+"Test_Log";
    plotName += ".pdf";
    
  }else{
    plotName += Variable;  
    plotName += ".pdf";
  }
 
 
  c1->SaveAs(plotName);
  delete c1;
  
  }
  	
}
Esempio n. 27
0
void doStackGen() {

  TStyle *simpleStyle = new TStyle("simpleStyle","");
  simpleStyle->SetCanvasColor(0);
  simpleStyle->SetFrameFillColor(0);
  simpleStyle->SetStatColor(0);
  simpleStyle->SetOptStat(0);
  simpleStyle->SetTitleFillColor(0);
  simpleStyle->SetCanvasBorderMode(0);
  simpleStyle->SetPadBorderMode(0);
  simpleStyle->SetFrameBorderMode(0);
  simpleStyle->cd();

  TFile* inFile = TFile::Open("RxGenOutputFile.root");



  TH1D* h1_RchGen_vs_eta = (TH1D*)inFile->Get("RchGen_vs_eta");
  TH1D* h1_RgammaGen_vs_eta = (TH1D*)inFile->Get("RgammaGen_vs_eta");
  TH1D* h1_RnhGen_vs_eta = (TH1D*)inFile->Get("RnhGen_vs_eta");
//  TH1D* h1_RmuGen_vs_eta = (TH1D*)inFile->Get("RmuGen_vs_eta_PFItCone5");

  int nBinsX_RchGen = h1_RchGen_vs_eta->GetNbinsX();
  int nBinsX_RgammaGen = h1_RgammaGen_vs_eta->GetNbinsX();
  int nBinsX_RnhGen = h1_RnhGen_vs_eta->GetNbinsX();
//  int nBinsX_RmuGen = h1_RmuGen_vs_eta->GetNbinsX();

  double minX_RchGen = h1_RchGen_vs_eta->GetXaxis()->GetXmin();
  double maxX_RchGen = h1_RchGen_vs_eta->GetXaxis()->GetXmax();

  double minX_RgammaGen = h1_RgammaGen_vs_eta->GetXaxis()->GetXmin();
  double maxX_RgammaGen = h1_RgammaGen_vs_eta->GetXaxis()->GetXmax();

  double minX_RnhGen = h1_RnhGen_vs_eta->GetXaxis()->GetXmin();
  double maxX_RnhGen = h1_RnhGen_vs_eta->GetXaxis()->GetXmax();

//  double minX_RmuGen = h1_RmuGen_vs_eta->GetXaxis()->GetXmin();
//  double maxX_RmuGen = h1_RmuGen_vs_eta->GetXaxis()->GetXmax();

  TH1D* h1_RchGen_vs_eta_stack = new TH1D("RchGen_vs_eta_stack", "", nBinsX_RchGen, minX_RchGen, maxX_RchGen);
  h1_RchGen_vs_eta_stack->SetFillColor(kRed);
  h1_RchGen_vs_eta_stack->SetXTitle("#eta^{GEN}");
 
  TH1D* h1_RgammaGen_vs_eta_stack = new TH1D("RgammaGen_vs_eta_stack", "", nBinsX_RgammaGen, minX_RgammaGen, maxX_RgammaGen);
  h1_RgammaGen_vs_eta_stack->SetFillColor(kGreen);
  h1_RgammaGen_vs_eta_stack->SetXTitle("#eta^{GEN}");

  TH1D* h1_RnhGen_vs_eta_stack = new TH1D("RnhGen_vs_eta_stack", "", nBinsX_RnhGen, minX_RnhGen, maxX_RnhGen);
  h1_RnhGen_vs_eta_stack->SetFillColor(kBlue);
  h1_RnhGen_vs_eta_stack->SetXTitle("#eta^{GEN}");

//  TH1D* h1_RmuGen_vs_eta_stack = new TH1D("RmuGen_vs_eta", "", nBinsX_RmuGen, minX_RmuGen, maxX_RmuGen);
//  h1_RmuGen_vs_eta_stack->SetFillColor(kYellow);
 // h1_RmuGen_vs_eta_stack->SetXTitle("#eta^{GEN}");

  for(int i=1; i<101; ++i) {
    h1_RchGen_vs_eta_stack->SetBinContent( i, h1_RchGen_vs_eta->GetBinContent(i) );
    h1_RgammaGen_vs_eta_stack->SetBinContent( i, h1_RgammaGen_vs_eta->GetBinContent(i) );
    h1_RnhGen_vs_eta_stack->SetBinContent( i, h1_RnhGen_vs_eta->GetBinContent(i) );
//    h1_RmuGen_vs_eta_stack->SetBinContent( i, h1_RmuGen_vs_eta->GetBinContent(i) );
  }


  THStack* stack = new THStack("stack", "");
  stack->Add(h1_RchGen_vs_eta_stack);
  stack->Add(h1_RgammaGen_vs_eta_stack);
  stack->Add(h1_RnhGen_vs_eta_stack);
//  stack->Add(h1_RmuGen_vs_eta_stack);
  stack->Draw();
  stack->GetXaxis()->SetTitle("#eta^{GEN}");
  stack->GetYaxis()->SetTitle("% of Jet Energy");

  TCanvas* c1 = new TCanvas("c1", "c1", 800, 600);
  c1->cd();
  stack->Draw();
  c1->SaveAs("Plots/genstack_vs_eta.eps");

  TH1D* h1_Rnh_neutron_vs_eta = (TH1D*)inFile->Get("Rnh_neutron_vs_eta");
  TH1D* h1_Rnh_K0L_vs_eta = (TH1D*)inFile->Get("Rnh_K0L_vs_eta");
  TH1D* h1_Rnh_K0S_vs_eta = (TH1D*)inFile->Get("Rnh_K0S_vs_eta");
  TH1D* h1_Rnh_lambda_vs_eta = (TH1D*)inFile->Get("Rnh_lambda_vs_eta");
  TH1D* h1_Rnh_csi_vs_eta = (TH1D*)inFile->Get("Rnh_csi_vs_eta");

  int nBinsX_Rnh_neutron = h1_Rnh_neutron_vs_eta->GetNbinsX();
  int nBinsX_Rnh_K0L = h1_Rnh_K0L_vs_eta->GetNbinsX();
  int nBinsX_Rnh_K0S = h1_Rnh_K0S_vs_eta->GetNbinsX();
  int nBinsX_Rnh_lambda = h1_Rnh_lambda_vs_eta->GetNbinsX();
  int nBinsX_Rnh_csi = h1_Rnh_csi_vs_eta->GetNbinsX();

  double minX_Rnh_neutron = h1_Rnh_neutron_vs_eta->GetXaxis()->GetXmin();
  double maxX_Rnh_neutron = h1_Rnh_neutron_vs_eta->GetXaxis()->GetXmax();

  double minX_Rnh_K0L = h1_Rnh_K0L_vs_eta->GetXaxis()->GetXmin();
  double maxX_Rnh_K0L = h1_Rnh_K0L_vs_eta->GetXaxis()->GetXmax();

  double minX_Rnh_K0S = h1_Rnh_K0S_vs_eta->GetXaxis()->GetXmin();
  double maxX_Rnh_K0S = h1_Rnh_K0S_vs_eta->GetXaxis()->GetXmax();

  double minX_Rnh_lambda = h1_Rnh_lambda_vs_eta->GetXaxis()->GetXmin();
  double maxX_Rnh_lambda = h1_Rnh_lambda_vs_eta->GetXaxis()->GetXmax();

  double minX_Rnh_csi = h1_Rnh_csi_vs_eta->GetXaxis()->GetXmin();
  double maxX_Rnh_csi = h1_Rnh_csi_vs_eta->GetXaxis()->GetXmax();


  TH1D* h1_Rnh_neutron_vs_eta_stack = new TH1D("Rnh_neutron_vs_eta_stack", "", nBinsX_Rnh_neutron, minX_Rnh_neutron, maxX_Rnh_neutron);
  h1_Rnh_neutron_vs_eta_stack->SetFillColor(kBlue+4);
  h1_Rnh_neutron_vs_eta_stack->SetXTitle("#eta^{GEN}");

  TH1D* h1_Rnh_K0L_vs_eta_stack = new TH1D("Rnh_K0L_vs_eta_stack", "", nBinsX_Rnh_K0L, minX_Rnh_K0L, maxX_Rnh_K0L);
  h1_Rnh_K0L_vs_eta_stack->SetFillColor(kBlue);
  h1_Rnh_K0L_vs_eta_stack->SetXTitle("#eta^{GEN}");

  TH1D* h1_Rnh_K0S_vs_eta_stack = new TH1D("Rnh_K0S_vs_eta_stack", "", nBinsX_Rnh_K0S, minX_Rnh_K0S, maxX_Rnh_K0S);
  h1_Rnh_K0S_vs_eta_stack->SetFillColor(kCyan);
  h1_Rnh_K0S_vs_eta_stack->SetXTitle("#eta^{GEN}");

  TH1D* h1_Rnh_lambda_vs_eta_stack = new TH1D("Rnh_lambda_vs_eta_stack", "", nBinsX_Rnh_lambda, minX_Rnh_lambda, maxX_Rnh_lambda);
  h1_Rnh_lambda_vs_eta_stack->SetFillColor(kCyan+2);
  h1_Rnh_lambda_vs_eta_stack->SetXTitle("#eta^{GEN}");

  TH1D* h1_Rnh_csi_vs_eta_stack = new TH1D("Rnh_csi_vs_eta_stack", "", nBinsX_Rnh_csi, minX_Rnh_csi, maxX_Rnh_csi);
  h1_Rnh_csi_vs_eta_stack->SetFillColor(kCyan+4);
  h1_Rnh_csi_vs_eta_stack->SetXTitle("#eta^{GEN}");

  for(int i=1; i<101; ++i) {
    h1_Rnh_neutron_vs_eta_stack->SetBinContent( i, h1_Rnh_neutron_vs_eta->GetBinContent(i) );
    h1_Rnh_K0L_vs_eta_stack->SetBinContent( i, h1_Rnh_K0L_vs_eta->GetBinContent(i) );
    h1_Rnh_K0S_vs_eta_stack->SetBinContent( i, h1_Rnh_K0S_vs_eta->GetBinContent(i) );
    h1_Rnh_lambda_vs_eta_stack->SetBinContent( i, h1_Rnh_lambda_vs_eta->GetBinContent(i) );
    h1_Rnh_csi_vs_eta_stack->SetBinContent( i, h1_Rnh_csi_vs_eta->GetBinContent(i) );
  }


  THStack* stackNH = new THStack("stackNH", "");
  stackNH->Add(h1_Rnh_neutron_vs_eta_stack);
  stackNH->Add(h1_Rnh_K0L_vs_eta_stack);
  stackNH->Add(h1_Rnh_K0S_vs_eta_stack);
  stackNH->Add(h1_Rnh_lambda_vs_eta_stack);
  stackNH->Add(h1_Rnh_csi_vs_eta_stack);
  stackNH->Draw();
  stackNH->GetXaxis()->SetTitle("#eta^{GEN}");
  stackNH->GetYaxis()->SetTitle("% of Jet Neutral Hadron Energy");

  TCanvas* c3 = new TCanvas("c3", "c3", 800, 600);
  c3->cd();
  stackNH->Draw();
  c3->SaveAs("Plots/genstackNH_vs_eta.eps");

/*
  int nBins = 21;
  Double_t Lower[nBins];
    
  for(int iLower=0; iLower<11; ++iLower)
    Lower[iLower] = iLower*10.; 
  
  Lower[11] = 120.;
  Lower[12] = 140.;
  Lower[13] = 160.;
  Lower[14] = 180.;
  Lower[15] = 200.;
  Lower[16] = 250.;
  Lower[17] = 300.;
  Lower[18] = 400.;
  Lower[19] = 500.;
  Lower[20] = 600.;


  TH1D* h1_RchGen_vs_pt = (TH1D*)inFile->Get("RchGen_vs_pt_PFItCone5");
  TH1D* h1_RgammaGen_vs_pt = (TH1D*)inFile->Get("RgammaGen_vs_pt_PFItCone5");
  TH1D* h1_RnhGen_vs_pt = (TH1D*)inFile->Get("RnhGen_vs_pt_PFItCone5");
//  TH1D* h1_RmuGen_vs_pt = (TH1D*)inFile->Get("RmuGen_vs_pt_PFItCone5");

  TH1D* h1_RchGen_vs_pt_stack = new TH1D("RchGen_vs_pt", "", nBins-2, Lower);
  h1_RchGen_vs_pt_stack->SetFillColor(kRed);
  h1_RchGen_vs_pt_stack->SetXTitle("p_{T}^{GEN}");
 
  TH1D* h1_RgammaGen_vs_pt_stack = new TH1D("RgammaGen_vs_pt", "", nBins-2, Lower);
  h1_RgammaGen_vs_pt_stack->SetFillColor(kGreen);
  h1_RgammaGen_vs_pt_stack->SetXTitle("p_{T}^{GEN}");

  TH1D* h1_RnhGen_vs_pt_stack = new TH1D("RnhGen_vs_pt", "", nBins-2, Lower);
  h1_RnhGen_vs_pt_stack->SetFillColor(kBlue);
  h1_RnhGen_vs_pt_stack->SetXTitle("p_{T}^{GEN}");

//  TH1D* h1_RmuGen_vs_pt_stack = new TH1D("RmuGen_vs_pt", "", nBins-2, Lower);
//  h1_RmuGen_vs_pt_stack->SetFillColor(kYellow);
//  h1_RmuGen_vs_pt_stack->SetXTitle("p_{T}^{GEN}");

  for(int i=1; i<21; ++i) {
    h1_RchGen_vs_pt_stack->SetBinContent( i, h1_RchGen_vs_pt->GetBinContent(i) );
    h1_RgammaGen_vs_pt_stack->SetBinContent( i, h1_RgammaGen_vs_pt->GetBinContent(i) );
    h1_RnhGen_vs_pt_stack->SetBinContent( i, h1_RnhGen_vs_pt->GetBinContent(i) );
//    h1_RmuGen_vs_pt_stack->SetBinContent( i, h1_RmuGen_vs_pt->GetBinContent(i) );
  }


  THStack* stack2 = new THStack("stack2", "");
  stack2->Add(h1_RchGen_vs_pt_stack);
  stack2->Add(h1_RgammaGen_vs_pt_stack);
  stack2->Add(h1_RnhGen_vs_pt_stack);
//  stack2->Add(h1_RmuGen_vs_pt_stack);
  stack2->Draw();
  stack2->GetXaxis()->SetTitle("p_{T}^{GEN} [GeV/c]");
  stack2->GetYaxis()->SetTitle("% of Jet Energy");

  TCanvas* c2 = new TCanvas("c2", "c2", 800, 600);
  c2->cd();
  stack2->Draw();
  c2->SaveAs("Plots/genstack_vs_pt.eps");


  TH1D* h1_RchGen_vs_pt_barrel = (TH1D*)inFile->Get("RchGen_vs_pt_barrel_PFItCone5");
  TH1D* h1_RgammaGen_vs_pt_barrel = (TH1D*)inFile->Get("RgammaGen_vs_pt_barrel_PFItCone5");
  TH1D* h1_RnhGen_vs_pt_barrel = (TH1D*)inFile->Get("RnhGen_vs_pt_barrel_PFItCone5");
//  TH1D* h1_RmuGen_vs_pt_barrel = (TH1D*)inFile->Get("RmuGen_vs_pt_barrel_PFItCone5");

  TH1D* h1_RchGen_vs_pt_barrel_stack = new TH1D("RchGen_vs_pt_barrel", "", nBins-2, Lower);
  h1_RchGen_vs_pt_barrel_stack->SetFillColor(kRed);
  h1_RchGen_vs_pt_barrel_stack->SetXTitle("p_{T}^{GEN}");
 
  TH1D* h1_RgammaGen_vs_pt_barrel_stack = new TH1D("RgammaGen_vs_pt_barrel", "", nBins-2, Lower);
  h1_RgammaGen_vs_pt_barrel_stack->SetFillColor(kGreen);
  h1_RgammaGen_vs_pt_barrel_stack->SetXTitle("p_{T}^{GEN}");

  TH1D* h1_RnhGen_vs_pt_barrel_stack = new TH1D("RnhGen_vs_pt_barrel", "", nBins-2, Lower);
  h1_RnhGen_vs_pt_barrel_stack->SetFillColor(kBlue);
  h1_RnhGen_vs_pt_barrel_stack->SetXTitle("p_{T}^{GEN}");

//  TH1D* h1_RmuGen_vs_pt_barrel_stack = new TH1D("RmuGen_vs_pt_barrel", "", nBins-2, Lower);
//  h1_RmuGen_vs_pt_barrel_stack->SetFillColor(kYellow);
//  h1_RmuGen_vs_pt_barrel_stack->SetXTitle("p_{T}^{GEN}");

  for(int i=1; i<21; ++i) {
    h1_RchGen_vs_pt_barrel_stack->SetBinContent( i, h1_RchGen_vs_pt_barrel->GetBinContent(i) );
    h1_RgammaGen_vs_pt_barrel_stack->SetBinContent( i, h1_RgammaGen_vs_pt_barrel->GetBinContent(i) );
    h1_RnhGen_vs_pt_barrel_stack->SetBinContent( i, h1_RnhGen_vs_pt_barrel->GetBinContent(i) );
 //   h1_RmuGen_vs_pt_barrel_stack->SetBinContent( i, h1_RmuGen_vs_pt_barrel->GetBinContent(i) );
  }


  THStack* stack3 = new THStack("stack3", "");
  stack3->Add(h1_RchGen_vs_pt_barrel_stack);
  stack3->Add(h1_RgammaGen_vs_pt_barrel_stack);
  stack3->Add(h1_RnhGen_vs_pt_barrel_stack);
//  stack3->Add(h1_RmuGen_vs_pt_barrel_stack);
  stack3->Draw();
  stack3->GetXaxis()->SetTitle("p_{T}^{GEN} [GeV/c]");
  stack3->GetYaxis()->SetTitle("% of Jet Energy");

  c2->cd();
  stack3->Draw();
  c2->SaveAs("Plots/genstack_vs_pt_barrel.eps");


  TH1D* h1_RchGen_vs_pt_endcap = (TH1D*)inFile->Get("RchGen_vs_pt_endcap_PFItCone5");
  TH1D* h1_RgammaGen_vs_pt_endcap = (TH1D*)inFile->Get("RgammaGen_vs_pt_endcap_PFItCone5");
  TH1D* h1_RnhGen_vs_pt_endcap = (TH1D*)inFile->Get("RnhGen_vs_pt_endcap_PFItCone5");
//  TH1D* h1_RmuGen_vs_pt_endcap = (TH1D*)inFile->Get("RmuGen_vs_pt_endcap_PFItCone5");

  TH1D* h1_RchGen_vs_pt_endcap_stack = new TH1D("RchGen_vs_pt_endcap", "", nBins-2, Lower);
  h1_RchGen_vs_pt_endcap_stack->SetFillColor(kRed);
  h1_RchGen_vs_pt_endcap_stack->SetXTitle("p_{T}^{GEN}");

  TH1D* h1_RgammaGen_vs_pt_endcap_stack = new TH1D("RgammaGen_vs_pt_endcap", "", nBins-2, Lower);
  h1_RgammaGen_vs_pt_endcap_stack->SetFillColor(kGreen);
  h1_RgammaGen_vs_pt_endcap_stack->SetXTitle("p_{T}^{GEN}");

  TH1D* h1_RnhGen_vs_pt_endcap_stack = new TH1D("RnhGen_vs_pt_endcap", "", nBins-2, Lower);
  h1_RnhGen_vs_pt_endcap_stack->SetFillColor(kBlue);
  h1_RnhGen_vs_pt_endcap_stack->SetXTitle("p_{T}^{GEN}");

//  TH1D* h1_RmuGen_vs_pt_endcap_stack = new TH1D("RmuGen_vs_pt_endcap", "", nBins-2, Lower);
//  h1_RmuGen_vs_pt_endcap_stack->SetFillColor(kYellow);
//  h1_RmuGen_vs_pt_endcap_stack->SetXTitle("p_{T}^{GEN}");

  for(int i=1; i<21; ++i) {
    h1_RchGen_vs_pt_endcap_stack->SetBinContent( i, h1_RchGen_vs_pt_endcap->GetBinContent(i) );
    h1_RgammaGen_vs_pt_endcap_stack->SetBinContent( i, h1_RgammaGen_vs_pt_endcap->GetBinContent(i) );
    h1_RnhGen_vs_pt_endcap_stack->SetBinContent( i, h1_RnhGen_vs_pt_endcap->GetBinContent(i) );
    //h1_RmuGen_vs_pt_endcap_stack->SetBinContent( i, h1_RmuGen_vs_pt_endcap->GetBinContent(i) );
  }


  THStack* stack4 = new THStack("stack4", "");
  stack4->Add(h1_RchGen_vs_pt_endcap_stack);
  stack4->Add(h1_RgammaGen_vs_pt_endcap_stack);
  stack4->Add(h1_RnhGen_vs_pt_endcap_stack);
//  stack4->Add(h1_RmuGen_vs_pt_endcap_stack);
  stack4->Draw();
  stack4->GetXaxis()->SetTitle("p_{T}^{GEN} [GeV/c]");
  stack4->GetYaxis()->SetTitle("% of Jet Energy");

  c2->cd();
  stack4->Draw();
  c2->SaveAs("Plots/genstack_vs_pt_endcap.eps");
*/
} 
void doControlPlotsMuons(){
setTDRStyle();

//loop over variables
for(int i = 0; i<N; i++){
//double MinX = MinXs[i];
//double MaxX = MaxXs[i];
RebinFact = RebinFacts[i];
Variable = Variables[i];
TString Xtitle = XTitles[i];

//Data
TH1D* data = getSample("DoubleMu", 1, Obj, Next, Variable, RebinFact, Systematic);

std::cout << data->Integral() << std::endl;

//MC
TH1D* tt = getSample("TTJet", 1, Obj, Next, Variable, RebinFact, Systematic);
TH1D* wjets = getSample("WJetsToLNu", 1, Obj, Next, Variable, RebinFact, Systematic);
TH1D* DY1 = getSample("DYJetsToLL_M-10To50", 1, Obj, Next, Variable, RebinFact, Systematic);
TH1D* DY2 = getSample("DYJetsToLL_M-50", 1, Obj, Next, Variable, RebinFact, Systematic);
TH1D* T_tW = getSample("T_tW-channel", 1, Obj, Next, Variable, RebinFact, Systematic);
TH1D* Tbar_tW = getSample("Tbar_tW-channel",1, Obj, Next, Variable, RebinFact, Systematic);

THStack *hs = new THStack("hs","test");

  hs->Add(wjets);
  hs->Add(DY1);
  hs->Add(DY2);
  hs->Add(T_tW); 
  hs->Add(Tbar_tW);
  hs->Add(tt); 
  
  //draw histos to files
  TCanvas *c1 = new TCanvas("Plot","Plot",900, 600);
		
  hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3);

  hs->Draw();
  data->Draw("E same");
  data->SetMarkerStyle(20);
  
//  hs->GetXaxis()->SetLimits(MinX, MaxX);
  hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05);
  hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);
   
   
  if(logPlot == true){
  c1->SetLogy();
  }	
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.6,0.7,0.8,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(data , "2012 data", "lpe");
	tleg2->AddEntry(tt , "t#bar{t}", "lf");
	tleg2->AddEntry(T_tW, "single-t", "lf");
	tleg2->AddEntry(Tbar_tW, "single-#bar{t}", "lf");	
	tleg2->AddEntry(DY1 , "DYJetsToLL-10To50", "lf");
	tleg2->AddEntry(DY2 , "DYJetsToLL-50", "lf");
	tleg2->AddEntry(wjets , "W+jets", "lf");
	
 	tleg2->Draw("same");	

  TString plotName("plots/Control/PassesCutsUpTo1Btag/Muons/");
  
  if(logPlot == true){
    plotName += Variable+"Log.pdf";
//    plotName += Nbtags+".pdf";
    
  }else{
    plotName += Variable+".pdf";  
//    plotName += Nbtags+".pdf";
  }
 
  TText* textPrelim = doPrelim(0.16,0.96); 
  textPrelim->Draw();
  
  c1->SaveAs(plotName);
  delete c1;
  
  }
  	
}
Esempio n. 29
0
  void drawpdgstack(std::string const & which_pdg,
		    std::string const & cname,
		    std::string const & dr,
		    std::string const & binning,
		    std::string const & we = "",
		    std::string const & op = "",
		    std::string const & title = "",
		    std::string const & xtitle = "",
		    std::string const & ytitle = "",
		    bool const pdg_sign = true) {

    ofile->cd();
    
    TH1F * hist = getpdgs(which_pdg.c_str(), we);
    if(!hist) {
      std::cout << "drawpdgstack: Empty pdg hist for \"" << which_pdg << "\" with selection \"" << we << "\"\n";
      return;
    }    

    THStack * stack = new THStack("stack", "");
    TLegend * legend = new TLegend(0.6, 0.9, 0.9, 0.6);

    double sig_evtsppot = 0;

    if(tree2) {

      TString draw_str = "";
      draw_str += dr;
      draw_str += ">>h_sig";
      draw_str += binning;

      TCanvas * canvas_pdg_temp = new TCanvas("temp");
      tree2->Draw(draw_str.Data(),
		  we.c_str(),
		  op.c_str());
      delete canvas_pdg_temp;
      TH1F * hist_sig = (TH1F*)gDirectory->Get("h_sig");
      hist_sig->SetLineColor(1);
      hist_sig->SetFillColor(kRed+3);
      hist_sig->Scale(1. / signal_pot * run_pot);

      stack->Add(hist_sig);
      legend->AddEntry(hist_sig, ("Signal: "+to_string_with_precision(hist_sig->Integral())).c_str());
      
      sig_evtsppot = hist_sig->Integral();

    }

    legend->SetHeader(("Total: "+to_string_with_precision((hist->Integral()/background_pot*run_pot + sig_evtsppot))).c_str());
    ((TLegendEntry*)legend->GetListOfPrimitives()->First())->SetTextAlign(22);

    std::vector<int> pdg_vec;
    for(int i = 1; i <= hist->GetNbinsX(); ++i) {

      if(hist->GetBinContent(i) == 0) continue;      
      int const pdg = i+hist->GetBinLowEdge(0);

      if(!pdg_sign) {
	if(std::find(pdg_vec.begin(), pdg_vec.end(), abs(pdg)) != pdg_vec.end())
	  continue;
	pdg_vec.push_back(abs(pdg));
      }
  
      TString hname = "";
      hname += "h_";
      hname += pdg;
      
      TString draw_str = "";
      draw_str += dr;
      draw_str += ">>h_";
      draw_str += pdg;
      draw_str += binning;
      
      TString weight_str = "";
      weight_str += we;
      weight_str += "&&(";
      weight_str += which_pdg;
      weight_str += "==";
      weight_str += pdg;
      if(!pdg_sign && pdg < 0) {
	weight_str += "||";
	weight_str += which_pdg;
	weight_str += "==";
	weight_str += abs(pdg);
      }
      weight_str += ")";
      
      TCanvas * canvas_pdg_temp = new TCanvas("temp");
      tree->Draw(draw_str.Data(),
		 weight_str.Data(),
		 op.c_str());
      delete canvas_pdg_temp;

      int pdg_temp = pdg;
      if(!pdg_sign) pdg_temp = abs(pdg);
      pdg_stuff const & pdg_s = get_pdg_stuff(pdg_temp, pdg_sign);

      TH1F * hist_pdg = (TH1F*)gDirectory->Get(hname.Data());
      hist_pdg->SetLineColor(1);
      hist_pdg->SetFillColor(pdg_s._color);
      hist_pdg->Scale(1. / background_pot * run_pot);
      stack->Add(hist_pdg);
      legend->AddEntry(hist_pdg, (pdg_s._particle_name+": "+to_string_with_precision(hist_pdg->Integral())).c_str());
      
    }
    
    TCanvas * canvas = new TCanvas(cname.c_str());
    stack->Draw();
    stack->SetTitle(title.c_str());
    stack->GetXaxis()->SetTitle(xtitle.c_str());
    stack->GetXaxis()->CenterTitle(); 
    stack->GetYaxis()->SetTitle(ytitle.c_str());
    stack->GetYaxis()->CenterTitle();
    legend->Draw();
    canvas->Write();
    delete stack;
    delete legend;
    delete canvas;
    delete hist;
    
  }
Esempio n. 30
0
void stackPlotter::plotStack(const TString& key, legendposition legpos) {
	if(debug)
		std::cout << "stackPlotter::plotStack" << std::endl;

	std::vector<std::pair<Int_t,TH1*> > legEntries = stacksLegEntries_[key];
	if(legEntries.size()<1) return;

	TCanvas *c = new TCanvas(key,key,800,600);
	TLegend *leg = new TLegend(0.75,0.75,0.95,0.95); //will be overwritten by style!
	THStack *stack = new THStack();

	//determine legend position TBI (add all histos, look at mean and max values etc)
	//float max=stack->GetMaximum(); //unfortunately no mean function also not filled, yet.
	//needs another loop on histos
	TH1 * h=(TH1 *) legEntries.at(0).second->Clone();
	for(size_t i=1;i<legEntries.size();i++){
		h->Add(legEntries.at(i).second);
	}
//	int maxbin=h->GetMaximumBin();
	//int minbin=h->GetMinimumBin();
//	float ymax=h->GetBinContent(maxbin);
	//float ymin=h->GetBinContent(minbin);
	//pass this to the style functions
	delete h;

	//gStyle->SetOptTitle(0);//no title


	for(size_t i=0; i < legEntries.size(); i++) {
		TString legName = legEntries.at(i).second->GetName();
		if(legName == "") continue;

		applyStyleToTH1(legEntries.at(i).second,legpos);

		stack->Add(legEntries.at(i).second,"HIST");
		stack->SetTitle("");//legEntries.at(i).second->GetTitle());
		stack->SetName(legEntries.at(i).second->GetTitle());

		//mirror entry for legend
		leg->AddEntry(legEntries.at(legEntries.size()-1-i).second,
				legEntries.at(legEntries.size()-1-i).second->GetName(),
				"F");
	}

	// draw plot and legend

	c->cd();

	applyStyleToCanvas(c,legpos);

	stack->Draw();
	stack->GetXaxis()->SetTitle(legEntries.at(0).second->GetXaxis()->GetTitle());
	stack->GetYaxis()->SetTitle(legEntries.at(0).second->GetYaxis()->GetTitle());

	applyStyleToAxis(stack,legpos);
	applyStyleToLegend(leg,legpos);
	stack->Draw();
	leg->Draw();
    //c->BuildLegend();


	// save and exit
	if(saveplots_) {
		c->SaveAs(outdir_+"/"+key+".pdf");
		c->SaveAs(outdir_+"/"+key+".png");
	}

	if(savecanvases_ && outfile_) {
		outfile_->cd();
		c->Write();
	}

	delete stack;
	delete leg;
	delete c;

}