Пример #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();

}
Пример #2
1
TH1* GetOne(UShort_t sNN, const TString& trigger)
{
  Long_t   p = gROOT->ProcessLine(Form("Drawer::GetStack(0, \"pp\", %d, "
				       "\"%s\", false, true)", 
				       sNN, trigger.Data()));
  THStack* s = (THStack*)p;
  TList*   l = s->GetHists();
  TH1*     h = 0;
  TIter    n(l);
  l->ls();
  while ((h = static_cast<TH1*>(n()))) {
    TString m(h->GetName());
    if (m.EqualTo("dndetaForward_all")) break;
  }

  if (h) {
    switch (sNN) { 
    case  900: h->SetTitle("900GeV");  h->SetMarkerColor(kRed+2);   break;
    case 2760: h->SetTitle("2.76TeV"); h->SetMarkerColor(kGreen+2); break;
    case 7000: h->SetTitle("7TeV");    h->SetMarkerColor(kBlue+2);  break;
    case 8000: h->SetTitle("8TeV");    h->SetMarkerColor(kBlack);   break;
    }
  }

  return h;
}
Пример #3
0
void multicolor(Int_t isStack=0) {
   TCanvas *c1 = new TCanvas;
   Int_t nbins = 20;
   TH2F *h1 = new TH2F("h1","h1",nbins,-4,4,nbins,-4,4);
   h1->SetFillColor(kBlue);
   TH2F *h2 = new TH2F("h2","h2",nbins,-4,4,nbins,-4,4);
   h2->SetFillColor(kRed);
   TH2F *h3 = new TH2F("h3","h3",nbins,-4,4,nbins,-4,4);
   h3->SetFillColor(kYellow);
   THStack *hs = new THStack("hs","three plots");
   hs->Add(h1);
   hs->Add(h2);
   hs->Add(h3);
   TRandom r;
   Int_t i;
   for (i=0;i<20000;i++) h1->Fill(r.Gaus(),r.Gaus());
   for (i=0;i<200;i++) {
      Int_t ix = (Int_t)r.Uniform(0,nbins);
      Int_t iy = (Int_t)r.Uniform(0,nbins);
      Int_t bin = h1->GetBin(ix,iy);
      Double_t val = h1->GetBinContent(bin);
      if (val <= 0) continue;
      if (!isStack) h1->SetBinContent(bin,0);
      if (r.Rndm() > 0.5) {
         if (!isStack) h2->SetBinContent(bin,0);
         h3->SetBinContent(bin,val);
      } else {
         if (!isStack) h3->SetBinContent(bin,0);
         h2->SetBinContent(bin,val);
      }
   }
   hs->Draw("lego1");
}
void stack_ring_contribs(const string& fFile, const string& fTitleExt, const string& fNameExt) {
                                
   string title = "<E> in i#eta Ring " + fTitleExt + ";i#eta;<E> [GeV]";
                                
   TFile file(fFile.c_str());   
   file.cd("offsetAnalysis");   
                                
   TH1D *p_AEEREB  = p_AvgEinEREB->ProjectionX();
   TH1D *p_AEEREE  = p_AvgEinEREE->ProjectionX();
   TH1D *p_AEERHB  = p_AvgEinERHB->ProjectionX();
   TH1D *p_AEERHE  = p_AvgEinERHE->ProjectionX();
   TH1D *p_AEERHFl = p_AvgEinERHFl->ProjectionX();
   TH1D *p_AEERHFs = p_AvgEinERHFs->ProjectionX();
   //TH1D *p_AEERHO  = p_AvgEinC5HO->ProjectionX();
         
   p_AEEREB->SetFillColor(50);
   p_AEEREE->SetFillColor(8);
   p_AEERHB->SetFillColor(4);
   p_AEERHE->SetFillColor(6);
   p_AEERHFl->SetFillColor(16);
   p_AEERHFs->SetFillColor(12);
   //p_AEERHO->SetFillColor(7);
   
   TCanvas *c = new TCanvas("c", "",1120,800);
   c->cd();
   
   THStack *hs = new THStack("hs",title.c_str());
   
   hs->Add(p_AEEREB);
   hs->Add(p_AEEREE);
   hs->Add(p_AEERHB);
   hs->Add(p_AEERHE);
   hs->Add(p_AEERHFl);
   hs->Add(p_AEERHFs);
   //hs->Add(p_AEERHO);
   hs->Draw("hist");
   
   TLegend *legend = new TLegend(.6,.55,.68,.85);
   legend->SetBorderSize(1);
   legend->SetFillColor(0);
   //legend->SetFillStyle(0);
   legend->SetTextFont(42);
   legend->AddEntry(p_AEEREB,"EB","f");
   legend->AddEntry(p_AEEREE,"EE","f");
   legend->AddEntry(p_AEERHB,"HB","f");
   legend->AddEntry(p_AEERHE,"HE","f");
   legend->AddEntry(p_AEERHFl,"HFl","f");
   legend->AddEntry(p_AEERHFs,"HFs","f");
   //legend->AddEntry(p_AEERHO,"HO","f");
   legend->Draw();
   
   string fileName = "p_AvgEinER_stacked__" + fNameExt + ".png";
   
   c->SetGridy();
   c->SaveAs(fileName.c_str());

   delete legend;
   delete hs;
   delete c;
}
Пример #5
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");
  
}
Пример #6
0
void PlotHistsNhitsPerModule(TFile* f, TTree* tr, TString strMillepedeRes, TString strOutdir)
{
  TString canvName="c_";
  canvName+=strMillepedeRes;
  canvName+="_";
  canvName+=StrPlotType(NHITS);
  canvName.ReplaceAll(".res","");


  //enum {PXB,PXF,TIB,TID,TOB,TEC};
  int colors[6]={1,2,3,4,6,7};
//  TString labels[6]={"PXB","PXF","TIB","TID","TOB","TEC"};

  f->cd();
  TCanvas* canv = new TCanvas(canvName,canvName,600,600);
  canv->SetLogx();
  canv->SetLogy();

  for (int ind=1; ind<=1; ind++){
    TString strHist = "hNhits_";
    strHist+=StrPar(ind);
    TString strCut="label<700000 && ((label%20-1)%9+1)==";
    strCut+=ind;
    TStyle style; 
    style.SetTitleFontSize(0.2);
    THStack *hSt = new THStack("hNhits","# of derivatives (~tracks or hits) per module");
    TLegend *leg = new TLegend(0.75,0.65,0.95,0.95);
    for (int inv=0; inv<6; inv++){
      std::cout<<"- - - - - -"<<std::endl;
      std::cout<<subdLabels[inv]<<":"<<std::endl;
      std::cout<<StrCutSubd(inv)<<": "<<tr->GetEntries(StrCutSubd(inv))<<" parameters"<<std::endl;
      TString strHist1=strHist;
      strHist1+=ind;
      strHist1+=inv;
      TH1F* hValInt = new TH1F(strHist1,strHist1,300,10,15000);  
      TString strCut1 = strCut+TString(" && ")+StrCutSubd(inv);
      tr->Draw(TString("Nhits>>")+strHist1,strCut1,"goff");
      std::cout<<"# hits = "<<(int)hValInt->GetMean()<<"+-"<<(int)hValInt->GetRMS()<<std::endl;
      hValInt->SetLineColor(1);
      hValInt->SetFillColor(colors[inv]);
      hValInt->SetLineWidth(2);
      hSt->Add(hValInt);
      leg->AddEntry(hValInt,subdLabels[inv],"f");
      leg->SetFillColor(0);
    }
    hSt->Draw();
    leg->Draw("same");
    
  }//end of loop over ind

  canvName+=".png";
  TString saveName=strOutdir+canvName;
  canv->SaveAs(saveName);
  saveName.ReplaceAll(".png",".pdf");
  canv->SaveAs(saveName);
}//end of PlotHistsNhitsPerModule
Пример #7
0
THStack *stack(TH1** hists, char *hsn = "histstack", char *htn = "stack o hists") {
  int goodcolors[] = { kRed+1, kGreen+1, kBlue, kYellow+1, kMagenta+1, kCyan+1, 9 };
  THStack *hs = new THStack(hsn,htn);
  for (int i = 0; i < 6; i++) {
    hists[i]->SetLineColor(goodcolors[i]);
    if (hists[i]->InheritsFrom("TH2")) hists[i]->SetOption("colz");
    hs->Add(hists[i]);
  }
  return hs;
}
Пример #8
0
THStack* CutFlow::buildStack(AllSamples samples, Variable variable){

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

	hs->Add(samples.qcd->histo);
	hs->Add(samples.vjets->histo);
	hs->Add(samples.single_t->histo);
	hs->Add(samples.ttbar->histo);

	return hs;
}
Пример #9
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");
    }
    
  }
}
Пример #10
0
void createInputs(int n = 2) 
{
   for(UInt_t i = 0; i < (UInt_t)n; ++i ) {
      TFile *file = TFile::Open(TString::Format("input%d.root",i),"RECREATE");
      TH1F * h = new TH1F("h1","",10,0,100);
      h->Fill(10.5); h->Fill(20.5);
 
      Int_t nbins[5];
      Double_t xmin[5];
      Double_t xmax[5];
      for(UInt_t j = 0; j < 5; ++j) {
         nbins[j] = 10; xmin[j] = 0; xmax[j] = 10;
      }
      THnSparseF *sparse = new THnSparseF("sparse", "sparse", 5, nbins, xmin, xmax);
      Double_t coord[5] = {0.5, 1.5, 2.5, 3.5, 4.5};
      sparse->Fill(coord);
      sparse->Write();
      
      THStack *stack = new THStack("stack","");
      h = new TH1F("hs_1","",10,0,100);
      h->Fill(10.5); h->Fill(20.5);
      h->SetDirectory(0);
      stack->Add(h);
      h = new TH1F("hs_2","",10,0,100);
      h->Fill(30.5); h->Fill(40.5);
      h->SetDirectory(0);
      stack->Add(h);
      stack->Write();

      TGraph *gr = new TGraph(3);
      gr->SetName("exgraph");
      gr->SetPoint(0,1,1);
      gr->SetPoint(1,2,2);
      gr->SetPoint(2,3,3);
      
      gr->Write();
      
      TTree *tree = new TTree("tree","simplistic tree");
      Int_t data = 0;
      tree->Branch("data",&data);
      for(Int_t l = 0; l < 2; ++l) {
         data = l;
         tree->Fill();
      }
      
      file->Write();
      delete file;
   }
}
Пример #11
0
void fit() {
  FILE *ofile;
  ofile = fopen("xsect-integrated-me.txt","w");
  TFile *_file0 = TFile::Open("h3maker-hn.root","update");
  _file0->Delete("*_f;*");
  TH2 *h2xsect = new TH2("hq2wXsect","Q^2:W",32,1.6,3.2,7,1.5,5.1);
  Double_t qbinedges[] = { 1.5, 1.6, 1.8, 2.1, 2.4, 2.76, 3.3, 5.1 };
  h2xsect->GetYaxis()->Set(7,qbinedges);
  TH3 *h3 = (TH3*)_file0->Get("hq2wmmp");
  int qbins = h3->GetZaxis()->GetNbins();
  int wbins = h3->GetYaxis()->GetNbins();
  fprintf(ofile, "W\tQ2\txsect\terror\tpol4p0\tpol4p1\tpol4p2\tpol4p3\tpol4p4\tgN\tgM\tgS\n");
  for (int iq = 0; iq < qbins; iq++) {
    TString hsn = TString::Format("hs%d",iq);
    THStack *hs = (THStack*)_file0->Get(hsn.Data());
    TIter next(hs->GetHists());
    //while (TObject *obj = next()) {
    //TH1 *h = (TH1*)obj;
    while (TH1 *h = (TH1*)next()) {
      float *wq = getwq(h);
      float wval = wq[0];
      float qval = wq[1];
      fitmmp(h);
      TH1 *htmp = (TH1*)h->Clone("hbgsubtracted");
      TF1 *fbg = (TF1*)h->GetListOfFunctions()->FindObject("fbg");
      htmp->Add(fbg,-1);
      double N = htmp->Integral(34,43);
      double qwidth = h3->GetZaxis()->GetBinWidth(iq+1);
      int wbin = h3->GetYaxis()->FindBin(wval);
      double wwidth = h3->GetYaxis()->GetBinWidth(wbin);
      double xsect = N/(0.891*wwidth*qwidth*19.844);
      double err2 = 0;
      for (int immp = 34; immp < 44; immp++) err2 += htmp->GetBinError(immp)*htmp->GetBinError(immp);
      //fprintf(ofile, "%.3f\t%.3f\t%.0f\t%.0f",wval,qval,xsect/(1e6), sqrt(err2)/(1e6));
      fprintf(ofile, "%.3f\t%.3f\t%.3e\t%.3e",wval,qval,xsect/(1e6), sqrt(err2)/(1e6));
      TF1 *ftmp = (TF1*)h->GetListOfFunctions()->At(0);
      int npar = ftmp->GetNpar();
      for (int ipar = 0; ipar < npar; ipar++) fprintf(ofile, "\t%.3e", ftmp->GetParameter(ipar));
      fprintf(ofile, "\n");
    }
    hsn.Append("_f");
    _file0->WriteObject(hs,hsn.Data());
    delete hs;
  }
  fclose(ofile);
  delete _file0;
}
Пример #12
0
THStack *getstack(TTree *nt, TString name, TString var, vector<TString> cuts,int bins = 100, float xmin = 0, float xmax = 200)
{
  THStack *hs = new THStack(name,name);
  int N = cuts.size();
  vector<TH1F *> vh(N);
  for (int i=0;i<N;i++) {
    vh[i] = geth(Form("%s%d",name.Data(),i),bins,xmin,xmax);

    vh[i]->SetFillColor(TColor::GetColorDark(i+2));
    vh[i]->SetFillStyle(1001);
    nt->Project(vh[i]->GetName(),var.Data(),Form("weight*(%s)",cuts[i].Data()),"");//,1000);
    hs->Add(vh[i],"hist");
    cout<<vh[i]->Integral()<<endl;
  }
  hs->SetMinimum(1E-2);

  return hs;
}
TH1F* GetHisto(TFile* fin, string region, string process, string varname, float& norm, bool do_norm, float input_norm)
{
    string cname = CHANNEL_NAME+string("/")+region+"/"+varname;
    TCanvas* c = (TCanvas*) fin->Get(cname.c_str());
    string hname = "v:"+varname+"|p:"+process+"|r:"+region+string("|c:")+CHANNEL_NAME+string("|t:1DEntries");
    TH1F* h = 0;
    if(VERBOSE>0){
 	 cerr<<"cname :"<<cname<<endl;
   	 cerr<<"histo name: "<<hname<<endl;
   	 cerr<<"pointer: "<<c<<endl;
    } 
    TList* l = c->GetListOfPrimitives();
    TPad* pad = (TPad*) l->At(0);
    THStack* stack = (THStack*) pad->GetPrimitive("");
    h = (TH1F*) stack->GetHists()->FindObject(hname.c_str());
    if(do_norm) h->Scale(input_norm/h->Integral());
    norm = h->Integral();
    return (TH1F*) h->Clone();
}
Пример #14
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();
}
Пример #15
0
  //____________________________________________________________________
  void Run(const char* newName,        const char* oldName,
	   const char* newTitle="New", const char* oldTitle="Old")
  {
    TFile* newFile = TFile::Open(newName,"READ");
    TFile* oldFile = TFile::Open(oldName,"READ");
    if (!newFile || !oldFile) return;

    TH1* newCent = GetH1(newFile, "realCent");
    TH1* oldCent = GetH1(oldFile, "realCent");
    if (!newCent || !oldCent) return;

    TString  t; t.Form("#it{R}=#frac{%s}{%s}", newTitle, oldTitle);
    TCanvas* c     = new TCanvas("c", t, 1200, 800);
    c->SetTopMargin(0.01);
    c->SetRightMargin(0.20);
    fLegend = new TLegend(1-c->GetRightMargin(),
			  c->GetBottomMargin(),
			  1, 1-c->GetTopMargin(),
			  t);
    fLegend->SetFillStyle(0);
    fLegend->SetBorderSize(0);
    THStack* stack = new THStack("ratios","");
			       
    fMin = +1e6;
    fMax = -1e6;
    TH1* one = 0;
    for (Int_t i = newCent->GetNbinsX(); i--;) {
      Double_t c1 = newCent->GetXaxis()->GetBinLowEdge(i+1);
      Double_t c2 = newCent->GetXaxis()->GetBinUpEdge(i+1);
      Info("", "c1=%f c2=%f", c1, c2);
      TH1*     r  = One(newFile, oldFile, c1, c2);    
      if (!r) continue;
      if (!one) {
	one = static_cast<TH1*>(r->Clone("one"));
	one->SetDirectory(0);
	one->Reset();
	for (Int_t j = 1; j <= one->GetNbinsX(); j++) {
	  one->SetBinContent(j,1);
	  one->SetBinError  (j,0);
	}
      }
      // r->Add(one, i-1);
      // r->Scale(TMath::Power(10,i));
      stack->Add(r);
    }
    stack->Draw("nostack");
    stack->SetMinimum(0.95*fMin);
    stack->SetMaximum(1.05*fMax);
    stack->GetHistogram()->SetXTitle("#eta");
    stack->GetHistogram()->SetYTitle("#it{R}");
    fLegend->Draw();
    c->Modified();
    c->Update();
    c->cd();
    c->SaveAs(Form("%sover%s.png", newTitle, oldTitle));
  }  
Пример #16
0
THStack* DrawOne(TVirtualPad* p, 
		 Double_t     yr,
		 Bool_t       top,
		 TDirectory*  dir, 
		 const char*  name)
{
  p->cd();
  p->SetFillColor(0);
  p->SetFillStyle(0);
  p->SetLineColor(0);
  p->SetRightMargin(0.01);
  p->SetLeftMargin(0.12);
  p->SetGridx();
  if (top) p->SetBottomMargin(0.001);
  else     p->SetBottomMargin(0.2);
  if (top) p->SetTopMargin(0.02);
  else     p->SetTopMargin(0.0001);
  
  
  THStack* s = static_cast<THStack*>(dir->Get(name));
  s->Draw("nostack");
  Double_t sc = (top ? 1-yr : yr);
  TAxis* ya = s->GetHistogram()->GetYaxis();
  ya->SetLabelSize(1/sc*ya->GetLabelSize());
  ya->SetTitleSize(1/sc*ya->GetTitleSize());
  ya->SetTitleOffset(sc*(ya->GetTitleOffset()+.5));
  ya->SetTitleFont(42);
  ya->SetLabelFont(42);
  TAxis* xa = s->GetHistogram()->GetXaxis();
  xa->SetLabelSize(!top ? 1/yr*xa->GetLabelSize() : 0);
  xa->SetTitleSize(!top ? 1/yr*xa->GetTitleSize() : 0);
  xa->SetTitleOffset(yr*(xa->GetTitleOffset()+2));
  xa->SetTitleFont(42);
  xa->SetLabelFont(42);

  p->Modified();
  p->Update();
  p->cd();

  return s;
}
Пример #17
0
void plotComparison(TFile **input, const string &title, const bool &reverse_order = false)
{
    TH1 *qcd = merge("htlep", input, 0, QCD_CHANNELS);
    TH1 *ttjets = get("htlep", input[TTJETS], TTJETS);
    TH1 *zjets = get("htlep", input[ZJETS], ZJETS);
    TH1 *wjets = get("htlep", input[WJETS], WJETS);
    TH1 *data = merge("htlep", input, RERECO, RERECO + DATA_CHANNELS);
    data->SetFillColor(0);
    
    THStack *stack = new THStack();
    stack->Add(qcd);
    stack->Add(ttjets);
    stack->Add(zjets);
    stack->Add(wjets);

    if (reverse_order)
    {
        stack->Draw("h");
        data->Draw("h same");
    }
    else
    {
        data->Draw("h");
        stack->Draw("h same");
    }

    TLegend *legend = createLegend(title.c_str());
    legend->Draw();
}
Пример #18
0
THStack * FromTH1FMakeTHStack(vector<TH1F*> * histo, TString stack_name, vector<TString> * h_description, bool order_size, bool nostack, TString x_axis, TString y_axis, TH1F * data){
 
  if((int) histo->size() != (int) h_description->size()){ Error("Histogram numbers and legend items do not match");}

  THStack * stack = new THStack("stack", stack_name);
  stack->SetTitle("");
  TLegend * legend = new TLegend(0.7,0.5,0.9,0.9);
  legend->SetFillColor(0);

  Int_t h_array_size = (int) histo->size();
  Int_t reorder[h_array_size];
  if(order_size){
    Float_t integral[h_array_size];
    for(int itr = 0; itr < h_array_size; itr++){
      integral[itr] = (*histo)[itr]->Integral();
    }
    for(int itr1 = 0; itr1 < h_array_size; itr1++){
      for(int itr2 = 0; itr2 < h_array_size; itr2++){
	if(itr1 == itr2) continue;
	if(integral[itr1] < integral[itr2]){
	  reorder[itr1] += 1;
	}
      }
    }
  }
  for(int itr = 0; itr < h_array_size; itr++){
    if( nostack ){ stack->Add((*histo)[reorder[itr]], "nostack"); }
    if(!nostack ){ stack->Add((*histo)[reorder[itr]]); }
    legend->AddEntry((*histo)[itr], (*h_description)[itr], "f");
  }
  if(data != NULL){ 
    stack->Add(data, "nostack");
    legend->AddEntry(data, "Data", "p");
  }

  return stack;

}
Пример #19
0
THStack * GetBkgStack(TFile *f, const char * name, const char * xtitle, TLegend * leg, int mode=0){
   char full_name[200];

   if (leg) {
      leg->SetFillStyle(0);
      leg->SetBorderSize(0);
      leg->SetTextSize(0.04);
   }

   sprintf(full_name, "stack_%s", name);
   THStack * stack = new THStack(full_name, "");

   TH1F * h_base = (TH1F *)f->Get(name);
   h_base->SetXTitle(xtitle);
   stack->SetHistogram(h_base);

   if (mode == 0)
   {
/*
      AddHist(stack, leg, f, name, "vbh_h_zz_4l",   "VV > H > ZZ > 4L",  FILL0, MYGREEN2);
      AddHist(stack, leg, f, name, "gg_zz_4l",      "gg > ZZ > 4L",      FILL0, MYORANGE1);
      AddHist(stack, leg, f, name, "gg_zz_2l2l",    "gg > ZZ > 2L2L",    FILL0, MYBLUE1);
      AddHist(stack, leg, f, name, "qq_zz_2e2mu",   "qq > ZZ > 2e2mu",   FILL0, MYCYAN2);
      AddHist(stack, leg, f, name, "gg_h_zz_4l",    "gg > H > ZZ > 4L",  FILL0, MYMAGENTA2);
      AddHist(stack, leg, f, name, "qq_zz_4e",      "qq > ZZ > 4e",      FILL0, MYGREEN1);   
      AddHist(stack, leg, f, name, "qq_zz_4mu",     "qq > ZZ > 4mu",     FILL0, MYORANGE2);  
      AddHist(stack, leg, f, name, "wh_zh_tth_hzz", "HW HW Htt, H > ZZ", FILL0, MYCYAN1);   
      AddHist(stack, leg, f, name, "wh_zh_tth_hww", "HW HZ Htt, H > WW", FILL0, MYMAGENTA1);
*/
      AddHist(stack, leg, f, name, "zh_hzz",  "HZ, H > ZZ",  FILL0, MYCYAN1);   
      AddHist(stack, leg, f, name, "zh_hww",  "HZ, H > WW",  FILL0, MYMAGENTA1);
      AddHist(stack, leg, f, name, "h_zz_4l", "H > ZZ > 4L", FILL0, MYGREEN2);
      AddHist(stack, leg, f, name, "zz_4l",   "ZZ > 4L",     FILL0, MYBLUE2);
   }
   return stack;
}
void plotasym(int top){
  if (setup("vm","","pol__")==kFALSE) return;

  THStack* hs = new THStack(TString::Format("asym_top%d",top), TString::Format("asym_top%d",top));

  int itop = top-1;
  TFile* fy = _fyexp[itop];
  TIter nextkey(fy->GetListOfKeys());
  TKey *key;
  while (key = (TKey*)nextkey()) {
    TString Q2Wdirname = key->GetName();
    if(Q2Wdirname.EqualTo("hYW_Dir") || Q2Wdirname.EqualTo("hYW"))continue;
    cout << "Q2Wdirname = " << Q2Wdirname << endl;
    TString hname = TString::Format("%s/hAsym/Varset1/hAsym_ACC_CORR_phi",Q2Wdirname.Data());
    cout << "hname = " << hname << endl;
    TH1D* h = (TH1D*)fy->Get(hname);
    if (h==NULL) cout << "histogram not found" << endl;
    //h->Draw();
    hs->Add(h,"e1");
  }
  TCanvas *c = new TCanvas(hs->GetName(),hs->GetTitle());
  hs->Draw("pads");

}
Пример #21
0
// Add a histogram to top of a stack
double addHistogram(const TString & fileName, const TString & histoName, const int color, THStack & hs,
    const TString & leg, TLegend *legend, const float lumi, int minIntegral=1, int maxIntegral=-1 )
{
  TFile * inputFile= new TFile (fileName, "READ");
  TH1F * histo = (TH1F*)inputFile->Get(histoName);
  TH1::SetDefaultSumw2();
  histo->Scale(lumi);

  histo->SetFillColor(color);
  hs.Add(histo);

  legend->AddEntry(histo, leg, "f");

  if ( maxIntegral==-1 ) maxIntegral=histo->GetNbinsX();

  return histo->Integral( minIntegral, maxIntegral );
}
Пример #22
0
void StackPlots( TFile* f1, vector<string> hist, vector<string> leg, vector<Color_t> color, string xtitle_, string ytitle_, string xunit, string savePath, bool ylog=0, int rebin=1){
	int Bins = 0;
	int x1 = 0;
	int x2 = 0;
	int size = hist.size();
	float binwidth = 0;
	char title[100], xtitle[100], ytitle[100];
	TH1F* h1[size];
	for(int i=0; i<size; i++){
		h1[i] = (TH1F*)f1->Get(hist[i].c_str());
		h1[i]->UseCurrentStyle();
		h1[i]->Rebin(rebin); 
		if( Bins != 0 ){ if( h1[i]->GetXaxis()->GetLast() != Bins ) { cout<<"Error: Exist different bin size( plot: "<<i<<")"<<endl; }}
		Bins = h1[i]->GetXaxis()->GetLast();
		binwidth = h1[i]->GetBinWidth(1);
		x1 = h1[i]->GetXaxis()->GetBinLowEdge(1);
		x2 = h1[i]->GetXaxis()->GetBinUpEdge(Bins);

		h1[i]->SetLineWidth(1);
		h1[i]->SetLineColor(color[i]);
		h1[i]->SetFillColor(color[i]);
	}

	sprintf(xtitle,"%s [%s]",xtitle_.c_str(),xunit.c_str());
	sprintf(ytitle,"%s / [%3.0f%s]",ytitle_.c_str(),binwidth,xunit.c_str());
	sprintf(title,";%s;%s",xtitle,ytitle);
	cout<<Bins<<" "<<x1<<" "<<x2<<endl;
	TH1F* hs_stack = new TH1F("hs_stack",title,Bins,x1,x2);
        THStack *hs = new THStack("hs","");

	TLegend* leg_ = new TLegend(0.65,0.65,0.85,0.85);
	TCanvas* c1 = new TCanvas("c1", "", 850, 700);
        c1->SetGridx();
        c1->SetGridy();
	gStyle->SetOptStat(0);
	gStyle->SetOptTitle(0);
	hs_stack->UseCurrentStyle();
	hs->SetHistogram(hs_stack);	
	for(int i=0; i<size; i++){
		hs->Add(h1[i]);
		leg_->AddEntry(h1[i],leg[i].c_str(),"f");
	}
        leg_->SetFillStyle(0);
        leg_->SetBorderSize(0);
        leg_->SetTextSize(0.042);
	if( ylog ) gPad->SetLogy();
	hs->SetMinimum(1);
	hs->SetMaximum(1e+13);
	hs->Draw();
	leg_->Draw();
	c1->SaveAs(savePath.c_str());
}
Пример #23
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();

    }
  }
Пример #24
0
void plot_example(){
 THStack *hs = new THStack("hs","");
   TH1F *h1 = new TH1F("h1","test hstack",10,-4,4);
   h1->FillRandom("gaus",20000);
   h1->SetFillColor(kRed);
   hs->Add(h1);
   TH1F *h2 = new TH1F("h2","test hstack",10,-4,4);
   h2->FillRandom("gaus",15000);
   h2->SetFillColor(kBlue);
   hs->Add(h2);
   TH1F *h3 = new TH1F("h3","test hstack",10,-4,4);
   h3->FillRandom("gaus",10000);
   h3->SetFillColor(kGreen);
   hs->Add(h3);
   TCanvas *cs = new TCanvas("cs","cs",10,10,700,900);
   TText T; T.SetTextFont(42); T.SetTextAlign(21);
   cs->Divide(2,2);
   cs->cd(1); hs->Draw(); T.DrawTextNDC(.5,.95,"Default drawing option");
   cs->cd(2); hs->Draw("nostack"); T.DrawTextNDC(.5,.95,"Option \"nostack\"");
   cs->cd(3); hs->Draw("nostackb"); T.DrawTextNDC(.5,.95,"Option \"nostackb\"");
   cs->cd(4); hs->Draw("lego1"); T.DrawTextNDC(.5,.95,"Option \"lego1\"");
}
Пример #25
0
void DrawTree::Draw(Double_t ymin_,Double_t ymax_,char* xtitle,char* ytitle) {
    bool first=true;

    if ( _VPar.size() > 0 && !_VPar[0]._1D ) {
        double xmin_ = _VPar[0]._TH->GetXaxis()->GetXmin();
        double xmax_ = _VPar[0]._TH->GetXaxis()->GetXmax()+3;
        _TH = gPad->DrawFrame(xmin_, ymin_, xmax_, ymax_);
        _TH->GetXaxis()->SetTitle(xtitle);
        _TH->GetYaxis()->SetTitle(ytitle);
    }

    for (size_t i=0; i<_VPar.size(); i++) {
        if (_VPar[i]._1D) {
            _stack.Draw("nostack");
            break;
        } else {
            if (!first)
                _VPar[i]._legend.append("same");

            if (_TH != NULL && first) {
                _VPar[i]._legend.append("same");
                _TH->Draw();
            }

// 	  if (first){
// 	    _VPar[i]._TH->GetXaxis()->SetTitle(xtitle.c_str());
// 	    _VPar[i]._TH->GetYaxis()->SetTitle(ytitle.c_str());

// 	  }

            _VPar[i]._TH->SetTitle("");
            _VPar[i]._TH->SetStats(0);

            if (_VPar[i]._TH->GetEntries()) {
                _VPar[i]._TH->Draw(_VPar[i]._legend.c_str());
                first=false;
            }
        }
    }
    _legend->Draw();
}
Пример #26
0
// Called within makePlot when making the pu plot
// Basically adds in the +/- 5% systematic error bars
TGraphAsymmErrors makePUPlot( THStack stack, TString anaType, const float lumi ) {

  // Got the stack, now sum the =/- 5% histograms and make two new stacks
  // Make dummy legend etc.
  THStack p5Stack("Background MC p5","");
  THStack m5Stack("Background MC m5","");
  TLegend *legend= new TLegend(0.1,0.1,0.1,0.1);

  addBackgroundHistos( anaType, "nRecoPV_p5", p5Stack, legend, lumi );
  addBackgroundHistos( anaType, "nRecoPV_m5", m5Stack, legend, lumi );

  // Get last histogram in stacks i.e. sum of all backgrounds
  TH1F * hist = new TH1F( *(TH1F*)(stack.GetStack()->Last()) );
  TH1F * p5Hist = new TH1F( *(TH1F*)p5Stack.GetStack()->Last() );
  TH1F * m5Hist = new TH1F( *(TH1F*)m5Stack.GetStack()->Last() );

  // Create structures to make TGraphAssymErrors
  Int_t n=p5Hist->GetNbinsX();
  Double_t x[n]; // x values
  Double_t y[n]; // y values
  Double_t exl[n]; // low x error
  Double_t eyl[n]; // low y error
  Double_t exh[n]; // high x error
  Double_t eyh[n]; // high y error

  // Loop over histos and get values
  for ( int bin=1; bin < n+1; bin++ ) {
    x[bin-1]=hist->GetBinCenter( bin );
    y[bin-1]=hist->GetBinContent( bin );
    exl[bin-1]=hist->GetBinWidth( bin )/2;
    eyl[bin-1]=p5Hist->GetBinContent( bin )-y[bin-1];
    exh[bin-1]=hist->GetBinWidth( bin )/2;
    eyh[bin-1]=y[bin-1]-m5Hist->GetBinContent( bin );
  }


  // Make TGraphAssymErrors
  TGraphAsymmErrors gr(n,x,y,exl,exh,eyl,eyh);

  return gr;
}
void CalcQCDNormFactor() {
  //TFile *f = TFile::Open("results/Plotter_out_2016_05_29_22h19m32.root"); // 76X Silver JSON
  TFile *f = TFile::Open("results/Plotter_out_2016_06_21_15h27m59.root"); // 76X Golden JSON
  TCanvas *c = (TCanvas*)f->Get("NJet/PlotSamples_Pass5Cuts_PassHLT");
  THStack *s = (THStack*)c->GetListOfPrimitives()->At(1);
  TH1D *data = (TH1D*)c->GetListOfPrimitives()->At(3);
  double MC_integral = 0;
  double QCD_count = 0;
  for (int i=s->GetHists()->GetEntries()-1; i>=0; --i) {
    TH1D* h = (TH1D*)s->GetHists()->At(i);
    if (i==s->GetHists()->GetEntries()-1) QCD_count = h->Integral();
    std::cout<<h->GetName()<<" "<<h->Integral()<<std::endl;
    MC_integral += h->Integral();
  }
  double data_QCD_estimate = data->Integral()- (MC_integral-QCD_count);
  double QCD_scale = data_QCD_estimate/QCD_count;
  std::cout<<"MC:                  "<<MC_integral<<std::endl;
  std::cout<<"Data:                "<<data->Integral()<<std::endl;
  std::cout<<"MC   (QCD only):     "<<QCD_count<<std::endl;
  std::cout<<"Data (QCD only est): "<<data_QCD_estimate<<std::endl;
  std::cout<<"QCD Scale: "<<QCD_scale<<std::endl;

  TH1D* qcd = (TH1D*)s->GetHists()->At(s->GetHists()->GetEntries()-1);
  qcd->Scale(QCD_scale);
  c->Draw();
  
  //TCanvas *c = (TCanvas*)f->Get("NJet/PlotSamples_Pass5Cuts_PassHLT_Ratio");
  //
  //TH1D* ratio = (TH1D*)((TVirtualPad*)c->cd(2))->GetListOfPrimitives()->At(0);
  //TF1* fit = new TF1("fit","pol1", 400, 2000);
  //ratio->Fit("fit","RBQ0");
  //fit->SetLineColor(2);
  //fit->SetLineWidth(1);
  //TF1* fit_up   = (TF1*)fit->Clone("fit_up");
  //TF1* fit_down = (TF1*)fit->Clone("fit_down");
  //fit_up  ->SetParameter(0,fit->GetParameter(0)+fit->GetParError(0)*1);
  //fit_down->SetParameter(0,fit->GetParameter(0)-fit->GetParError(0)*1);
  //fit_up  ->SetParameter(1,fit->GetParameter(1)+fit->GetParError(1)*1);
  //fit_down->SetParameter(1,fit->GetParameter(1)-fit->GetParError(1)*1);
  //fit_up  ->SetLineColor(4); fit_up  ->Draw("SAME");
  //fit_down->SetLineColor(4); fit_down->Draw("SAME");
  //fit->Draw("SAME");
  //
  //std::cout<<"Fit result:"<<std::endl;
  //std::cout<<"p0: "<<fit->GetParameter(0)<<" +- "<<fit->GetParError(0)*1<<std::endl;
  //std::cout<<"p1: "<<fit->GetParameter(1)<<" +- "<<fit->GetParError(1)*1<<std::endl;
  //f->Close();  
}
Пример #28
0
void DrawTree::Project(Params& A) {

    char name[128];
    sprintf(name,"drawTree%d_%d",fN,_countAdd++);
    A._Hname=name;
    _tree->Project(name,A._varexp.c_str(),A._selection.c_str(),A._option.c_str(),A._nentries,A._firstentry);

    TH1* h = (TH1*)gDirectory->Get(A._Hname.c_str());

    h->SetMarkerStyle(_MarkerStyle+(_MarkerCount0++));
    h->SetMarkerColor(_MarkerColor+(_MarkerCount1++));

    A._TH=h;
    _stack.Add(h);
    cout << A._legend.c_str() << endl;
    _legend->AddEntry(h,A._legend.c_str(),"P");

    float axmin=h->GetXaxis()->GetXmin();
    float axmax=h->GetXaxis()->GetXmax();

    if (xmin>axmin)
        xmin=axmin;
    if (xmax<axmax)
        xmax=axmax;

    if (A._varexp.find(":") != string::npos) {
        A._1D=false;
        float aymin=h->GetYaxis()->GetXmin();
        float aymax=h->GetYaxis()->GetXmax();

        if (ymin>aymin)
            ymin=aymin;
        if (ymax<aymax)
            ymax=aymax;

    }
}
Пример #29
0
void cutFlowStudyMu( Double_t hltEff_=0.94, Int_t applyHLTData_ = 1, Int_t applyHLTMC_ = 1 , Float_t hMass_ = 115) 
{
  
  
  ofstream out(Form("cutFlow_MuTauStream_iter3_%.0f.txt",hMass_)); 
  out.precision(4);

  TCut hltData("((HLTmu==1 && run<=163261) || (HLTx==1 && run>163261))");
  TCut hltMC("HLTx==1");
 
  TFile *fFullData                = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011_iter3/treeMuTauStream_Run2011-Mu.root","READ"); 
  TFile *fFullSignalVBF           = new TFile(Form("/data_CMS/cms/lbianchini//MuTauStream2011_iter3/treeMuTauStream_VBFH%.0f-Mu-powheg-PUS1.root",hMass_),"READ"); 

  float equivalentGGMass = 115;
  float scaleGGH = 1.0;
    if(hMass_ == 125){
      equivalentGGMass = 120;
      scaleGGH = 0.821;
    }
  if(hMass_ == 135){
    equivalentGGMass = 130;
    scaleGGH = 0.757;
  }

  TFile *fFullSignalGGH           = new TFile(Form("/data_CMS/cms/lbianchini//MuTauStream2011_iter3/treeMuTauStream_GGFH%.0f-Mu-powheg-PUS1.root",equivalentGGMass),"READ");  
  TFile *fFullBackgroundDYTauTau  = new TFile("/data_CMS/cms/lbianchini/MuTauStream2011_iter3/treeMuTauStream_DYJets-Mu-50-madgraph-PUS1.root","READ"); 
  TFile *fFullBackgroundDYMuMu    = new TFile("/data_CMS/cms/lbianchini/MuTauStream2011_iter3/treeMuTauStream_DYJets-Mu-50-madgraph-PUS1.root","READ"); 
  //TFile *fFullBackgroundWJets     = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011_iter3/treeMuTauStream_WJets-Mu-madgraph-PUS1.root","READ"); 
  TFile *fFullBackgroundEWK       = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011_iter3/treeMuTauStream_ElectroWeak.root","READ"); 
  TFile *fFullBackgroundQCD       = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011_iter3/treeMuTauStream_QCDmu-pythia-20-15-PUS1.root","READ"); 
  //TFile *fFullBackgroundTTbar     = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011_iter3/treeMuTauStream_TTJets-Mu-madgraph-PUS1.root","READ"); 
  //TFile *fFullBackgroundSingleTop = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011_iter3/treeMuTauStream_SingleTop-Mu.root","READ"); 
  //TFile *fFullBackgroundDiBoson   = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011_iter3/treeMuTauStream_DiBoson-Mu.root","READ"); 
  TFile *fFullBackgroundTop   = new TFile("/data_CMS/cms/lbianchini//MuTauStream2011_iter3/treeMuTauStream_Top.root","READ"); 

  // OpenNTuples
  TString fDataName                = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter3/Inclusive/nTupleRun2011-Mu_Open_MuTauStream.root";
  TString fSignalNameVBF           = Form("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter3/Inclusive/nTupleVBFH%.0f-Mu-powheg-PUS1_Open_MuTauStream.root",hMass_);
  TString fSignalNameGGH           = Form("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter3/Inclusive/nTupleGGFH%.0f-Mu-powheg-PUS1_Open_MuTauStream.root",equivalentGGMass);
  TString fBackgroundNameDYTauTau  = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter3/Inclusive/nTupleDYJets-Mu-50-madgraph-PUS1_Open_MuTauStream.root";
  TString fBackgroundNameDYMuMu    = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter3/Inclusive/nTupleDYJets-Mu-50-madgraph-PUS1_Open_MuTauStream.root";
  TString fBackgroundNameWJets     = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter3/Inclusive/nTupleWJets-Mu-madgraph-PUS1_Open_MuTauStream.root";
  TString fBackgroundNameEWK       = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter3/Inclusive/nTupleElectroWeak_Open_MuTauStream.root";
  TString fBackgroundNameQCD       = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter3/Inclusive/nTupleQCDmu-pythia-20-15-PUS1_Open_MuTauStream.root";
  TString fBackgroundNameTTbar     = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter3/Inclusive/nTupleTTJets-Mu-madgraph-PUS1_Open_MuTauStream.root";
  TString fBackgroundNameTop       = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter3/Inclusive/nTupleTop_Open_MuTauStream.root";
  TString fBackgroundNameSingleTop = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter3/Inclusive/nTupleSingleTop-Mu_Open_MuTauStream.root";
  TString fBackgroundNameDiBoson   = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter3/Inclusive/nTupleDiBoson-Mu_Open_MuTauStream.root";

  TFile *fData(0); 
  TFile *fSignalVBF(0); 
  TFile *fSignalGGH(0); 
  TFile *fBackgroundDYTauTau(0);
  TFile *fBackgroundDYMuMu(0);
  TFile *fBackgroundWJets(0);
  TFile *fBackgroundEWK(0);
  TFile *fBackgroundQCD(0);
  TFile *fBackgroundTTbar(0);
  TFile *fBackgroundTop(0);
  TFile *fBackgroundSingleTop(0);
  TFile *fBackgroundDiBoson(0);
 
  fData               = TFile::Open( fDataName ); 
  fSignalVBF          = TFile::Open( fSignalNameVBF ); 
  fSignalGGH          = TFile::Open( fSignalNameGGH ); 
  fBackgroundDYTauTau = TFile::Open( fBackgroundNameDYTauTau ); 
  fBackgroundDYMuMu   = TFile::Open( fBackgroundNameDYMuMu ); 
  //fBackgroundWJets    = TFile::Open( fBackgroundNameWJets ); 
  fBackgroundEWK      = TFile::Open( fBackgroundNameEWK ); 
  fBackgroundQCD      = TFile::Open( fBackgroundNameQCD ); 
  //fBackgroundTTbar    = TFile::Open( fBackgroundNameTTbar ); 
  fBackgroundTop      = TFile::Open( fBackgroundNameTop ); 
  //fBackgroundSingleTop= TFile::Open( fBackgroundNameSingleTop ); 
  //fBackgroundDiBoson  = TFile::Open( fBackgroundNameDiBoson ); 

  if(!fSignalVBF || !fBackgroundDYTauTau || /*!fBackgroundWJets ||*/ !fBackgroundQCD  /* || !fBackgroundTTbar || !fBackgroundSingleTop*/ ||
     !fSignalGGH || !fBackgroundDYMuMu || /*!fBackgroundDiBoson ||*/ !fBackgroundTop || !fBackgroundEWK || !fData){
    std::cout << "ERROR: could not open files" << std::endl;
    exit(1);
  }

  TString tree = "outTreePtOrd";

  TTree *data                = (TTree*)fData->Get(tree);
  TTree *signalVBF           = (TTree*)fSignalVBF->Get(tree);
  TTree *signalGGH           = (TTree*)fSignalGGH->Get(tree);

  TFile* dummy1 = new TFile("dummy1.root","RECREATE");
  TTree *backgroundDYTauTau  = ((TTree*)fBackgroundDYTauTau->Get(tree))->CopyTree("isTauLegMatched>0.5");
  TTree *backgroundDYMuMu    = ((TTree*)fBackgroundDYMuMu->Get(tree))->CopyTree("isTauLegMatched<0.5");
  cout <<backgroundDYTauTau->GetEntries() << " -- " << backgroundDYMuMu->GetEntries() << endl;

  //TTree *backgroundWJets     = (TTree*)fBackgroundWJets->Get(tree);
  TTree *backgroundEWK       = (TTree*)fBackgroundEWK->Get(tree);
  TTree *backgroundQCD       = (TTree*)fBackgroundQCD->Get(tree);
  //TTree *backgroundTTbar     = (TTree*)fBackgroundTTbar->Get(tree);
  TTree *backgroundTop       = (TTree*)fBackgroundTop->Get(tree);
  //TTree *backgroundSingleTop = (TTree*)fBackgroundSingleTop->Get(tree);
  //TTree *backgroundDiBoson   = (TTree*)fBackgroundDiBoson->Get(tree);

  // here I define the map between a sample name and its tree
  std::map<std::string,TTree*> tMap;
  tMap["Data"]=data;
  tMap["ggH115"]=signalGGH;
  tMap["qqH115"]=signalVBF;
  tMap["Ztautau"]=backgroundDYTauTau;
  tMap["ZfakeTau"]=backgroundDYMuMu;
  //tMap["Wjets"]=backgroundWJets;
  tMap["EWK"]=backgroundEWK;
  tMap["QCD"]=backgroundQCD;
  //tMap["TTbar"]=backgroundTTbar;
  tMap["Top"]=backgroundTop;
  //tMap["SingleTop"]=backgroundSingleTop;
  //tMap["DiBoson"]=backgroundDiBoson;

  std::map<std::string,TTree*>::iterator jt;

  
  // here I choose the order in the stack
  std::vector<string> samples;
  samples.push_back("ggH115");
  samples.push_back("qqH115");
  //samples.push_back("DiBoson");
  samples.push_back("Top");
  //samples.push_back("SingleTop");
  //samples.push_back("TTbar");
  //samples.push_back("Wjets");
  samples.push_back("EWK");
  samples.push_back("QCD");
  samples.push_back("ZfakeTau");
  samples.push_back("Ztautau");
  samples.push_back("Data");

  float kFactorQCD=1.0;
  std::map<std::string,float> crossSec;
  crossSec["ggH115"]=( 7.65e-02 * 18.13 * scaleGGH);
  crossSec["qqH115"]=( 0.1012);
  //crossSec["DiBoson"]=( -1  );
  //crossSec["TTbar"]=( 157.5 );
  //crossSec["SingleTop"]=( -1 );
  //crossSec["Wjets"]=( 31314.0);
  crossSec["EWK"]= (-1);
  crossSec["Top"]= (-1);
  crossSec["ZfakeTau"]=( 3048  );
  crossSec["Ztautau"]=( 3048  );
  crossSec["QCD"]=( 296600000*0.0002855 * kFactorQCD); //K-factor from fit in signal region 1.7
  crossSec["Data"]=( 0 );

  float Lumi = 191.;

  // here I choose the order in the stack
  std::vector<string> filters;
  filters.push_back("total");
  filters.push_back("vertex");
  filters.push_back("at least 1 mu-tau");
  filters.push_back("mu pt-eta");
  filters.push_back("mu-ID");
  filters.push_back("tau pt-eta");
  filters.push_back("tau-ID");
  filters.push_back("tau against-mu");
  filters.push_back("tau against-e");
  filters.push_back("tau-iso");
  filters.push_back("mu-iso");
  filters.push_back("di-mu veto");
  filters.push_back("Mt");
  filters.push_back("OS");
  filters.push_back("2-jets");
  filters.push_back("2-tag jets");
  filters.push_back("VBF cuts");
  filters.push_back("jet-veto");
  filters.push_back("Mass Window");
  //filters.push_back("Mass Window");
  //filters.push_back("HLT-matching");

  // here I define the map between a sample name and its file ptr
  std::map<std::string,TFile*> fullMap;
  fullMap["Data"]     = fFullData;
  fullMap["ggH115"]   = fFullSignalGGH;
  fullMap["qqH115"]   = fFullSignalVBF;
  fullMap["Ztautau"]  = fFullBackgroundDYTauTau;
  fullMap["ZfakeTau"] = fFullBackgroundDYMuMu;
  //fullMap["Wjets"]    = fFullBackgroundWJets;
  fullMap["EWK"]    = fFullBackgroundEWK;
  fullMap["QCD"]      = fFullBackgroundQCD;
  //fullMap["TTbar"]    = fFullBackgroundTTbar;
  fullMap["Top"]    = fFullBackgroundTop;
  //fullMap["SingleTop"]= fFullBackgroundSingleTop;
  //fullMap["DiBoson"]  = fFullBackgroundDiBoson;

  std::map<std::string,TFile*>::iterator it;

  std::map<std::string,float> cutMap_allEventsFilter;
  std::map<std::string,float> cutMap_allEventsFilterE;

  std::map<std::string,float> cutMap_vertexScrapingFilter;
  std::map<std::string,float> cutMap_vertexScrapingFilterE;

  std::map<std::string,float> cutMap_atLeastOneMuTauFilter;
  std::map<std::string,float> cutMap_atLeastOneMuTauFilterE;

  std::map<std::string,float> cutMap_muPtEtaFilter;
  std::map<std::string,float> cutMap_muPtEtaFilterE;

  std::map<std::string,float> cutMap_muPtEtaIDFilter;
  std::map<std::string,float> cutMap_muPtEtaIDFilterE;

  std::map<std::string,float> cutMap_tauPtEtaFilter;
  std::map<std::string,float> cutMap_tauPtEtaFilterE;

  std::map<std::string,float> cutMap_tauPtEtaIDFilter;
  std::map<std::string,float> cutMap_tauPtEtaIDFilterE;

  std::map<std::string,float> cutMap_tauPtEtaIDAgMuFilter;
  std::map<std::string,float> cutMap_tauPtEtaIDAgMuFilterE;

  std::map<std::string,float> cutMap_tauPtEtaIDAgMuAgElecFilter;
  std::map<std::string,float> cutMap_tauPtEtaIDAgMuAgElecFilterE;

  std::map<std::string,float> cutMap_TauIso;
  std::map<std::string,float> cutMap_TauIsoE;

  std::map<std::string,float> cutMap_MuIso;
  std::map<std::string,float> cutMap_MuIsoE;

  std::map<std::string,float> cutMap_DiMuVeto;
  std::map<std::string,float> cutMap_DiMuVetoE;

  std::map<std::string,float> cutMap_Mt;
  std::map<std::string,float> cutMap_MtE;

  std::map<std::string,float> cutMap_OS;
  std::map<std::string,float> cutMap_OSE;

  std::map<std::string,float> cutMap_2jets;
  std::map<std::string,float> cutMap_2jetsE;

  std::map<std::string,float> cutMap_VBFPre;
  std::map<std::string,float> cutMap_VBFPreE;

  std::map<std::string,float> cutMap_VBF;
  std::map<std::string,float> cutMap_VBFE;

  std::map<std::string,float> cutMap_JetVeto;
  std::map<std::string,float> cutMap_JetVetoE;

  std::map<std::string,float> cutMap_antiBtag;
  std::map<std::string,float> cutMap_antiBtagE;

  std::map<std::string,float> cutMap_MassWindow;
  std::map<std::string,float> cutMap_MassWindowE;

  std::map<std::string,float> cutMap_HLT;
  std::map<std::string,float> cutMap_HLTE;

  std::vector< std::map<std::string,float> > allFilters;
  allFilters.push_back(cutMap_allEventsFilter);
  allFilters.push_back(cutMap_vertexScrapingFilter);
  allFilters.push_back(cutMap_atLeastOneMuTauFilter);
  allFilters.push_back(cutMap_muPtEtaFilter);
  allFilters.push_back(cutMap_muPtEtaIDFilter);
  allFilters.push_back(cutMap_tauPtEtaFilter);
  allFilters.push_back(cutMap_tauPtEtaIDFilter);
  allFilters.push_back(cutMap_tauPtEtaIDAgMuFilter);
  allFilters.push_back(cutMap_tauPtEtaIDAgMuAgElecFilter);
 

  std::vector< std::map<std::string,float> > allFiltersE;
  allFiltersE.push_back(cutMap_allEventsFilterE);
  allFiltersE.push_back(cutMap_vertexScrapingFilterE);
  allFiltersE.push_back(cutMap_atLeastOneMuTauFilterE);
  allFiltersE.push_back(cutMap_muPtEtaFilterE);
  allFiltersE.push_back(cutMap_muPtEtaIDFilterE);
  allFiltersE.push_back(cutMap_tauPtEtaFilterE);
  allFiltersE.push_back(cutMap_tauPtEtaIDFilterE);
  allFiltersE.push_back(cutMap_tauPtEtaIDAgMuFilterE);
  allFiltersE.push_back(cutMap_tauPtEtaIDAgMuAgElecFilterE);
 
  std::vector< std::map<std::string,float> > offlineFilters;
  offlineFilters.push_back(cutMap_TauIso);
  offlineFilters.push_back(cutMap_MuIso);
  offlineFilters.push_back(cutMap_DiMuVeto);
  offlineFilters.push_back(cutMap_Mt);
  offlineFilters.push_back(cutMap_OS);
  offlineFilters.push_back(cutMap_2jets);
  offlineFilters.push_back(cutMap_VBFPre);
  offlineFilters.push_back(cutMap_VBF);
  offlineFilters.push_back(cutMap_JetVeto);
  offlineFilters.push_back(cutMap_MassWindow);
  //offlineFilters.push_back(cutMap_HLT);

  std::vector< std::map<std::string,float> > offlineFiltersE;
  offlineFiltersE.push_back(cutMap_TauIsoE);
  offlineFiltersE.push_back(cutMap_MuIsoE);
  offlineFiltersE.push_back(cutMap_DiMuVetoE);
  offlineFiltersE.push_back(cutMap_MtE);
  offlineFiltersE.push_back(cutMap_OSE);
  offlineFiltersE.push_back(cutMap_2jetsE);
  offlineFiltersE.push_back(cutMap_VBFPreE);
  offlineFiltersE.push_back(cutMap_VBFE);
  offlineFiltersE.push_back(cutMap_JetVetoE);
  offlineFiltersE.push_back(cutMap_MassWindowE);
  //offlineFiltersE.push_back(cutMap_HLTE);

  std::vector< string > offlineCuts;
  offlineCuts.push_back("combIsoLeg2<2");
  offlineCuts.push_back("combRelIsoLeg1DBeta<0.10");
  offlineCuts.push_back("muFlag==0");
  offlineCuts.push_back("(pZeta-1.5*pZetaVis>-20)");
  offlineCuts.push_back("diTauCharge==0");
  offlineCuts.push_back("pt1>30 && pt2>30");
  offlineCuts.push_back("eta1*eta2<0");
  offlineCuts.push_back("Deta>3.5 && Mjj>350");
  offlineCuts.push_back("ptVeto<30");
  offlineCuts.push_back("diTauSVFitMass>85 && diTauSVFitMass<145");

  std::vector< string > filtersByName;
  filtersByName.push_back("allEventsFilter");
  filtersByName.push_back("vertexScrapingFilter");
  filtersByName.push_back("atLeastOneMuTauFilter");
  filtersByName.push_back("muPtEtaFilter");
  filtersByName.push_back("muPtEtaIDFilter");
  filtersByName.push_back("tauPtEtaFilter");
  filtersByName.push_back("tauPtEtaIDFilter");
  filtersByName.push_back("tauPtEtaIDAgMuFilter");
  filtersByName.push_back("tauPtEtaIDAgMuAgElecFilter");
  
  for(unsigned int k = 0 ; k <filtersByName.size() ; k++){

    for(it = fullMap.begin(); it != fullMap.end(); it++){
      TH1F* allEvents = (TH1F*)(it->second)->Get("allEventsFilter/totalEvents");
      float totalEvents = allEvents->GetBinContent(1);
      allEvents = (TH1F*)(it->second)->Get( (filtersByName[k]+"/totalEvents").c_str() );
      float tot =  allEvents->GetBinContent(1);
      float totalEquivalentEvents = allEvents->GetEffectiveEntries();
      if(crossSec[it->first]>0){
	tot *= (Lumi/ (totalEvents/crossSec[it->first]) * hltEff_  ) ;
      } else if (crossSec[it->first]<0) tot *= Lumi/1000*hltEff_;
      (allFilters[k])[it->first]  = tot;
      (allFiltersE[k])[it->first] = totalEquivalentEvents>0 ? sqrt(totalEquivalentEvents)*(tot/totalEquivalentEvents) : 0;
    }
  }

  for(unsigned int k =0; k < offlineFilters.size(); k++){
    
    for(jt = tMap.begin(); jt != tMap.end(); jt++){
      cout<<jt->first<<endl;
      TH1F* h1 = new TH1F("h1","",1,-10,10);
      string tmp_cut = "tightestHPSWP>-1";
      for(unsigned v = 0; v <=k ; v++){
        tmp_cut = tmp_cut + " && "+offlineCuts[v];
      }
      if((jt->first).find("Data")!=string::npos && applyHLTData_) tmp_cut = tmp_cut+" && ((HLTmu==1 && run<=163261) || (HLTx==1 && run\
>163261))";
      if((jt->first).find("Data")==string::npos && applyHLTMC_)   tmp_cut = tmp_cut+" && HLTmu==1";
      tmp_cut = "sampleWeight*puWeight*("+tmp_cut+")";
      cout << tmp_cut << endl;
      TCut cut(tmp_cut.c_str());

      jt->second->Draw("etaL1>>h1",cut);
      if((jt->first).find("Data")==string::npos) h1->Scale(Lumi/1000*hltEff_);
      if((jt->first).find("QCD")!=string::npos) h1->Scale(kFactorQCD);
      float tot = h1->Integral();
      cout << tot << endl;
      float totalEquivalentEvents = h1->GetEffectiveEntries();
      (offlineFilters[k])[jt->first] = tot;
      (offlineFiltersE[k])[jt->first] = totalEquivalentEvents>0 ? sqrt(totalEquivalentEvents)*(tot/totalEquivalentEvents) : 0;
      delete h1;
    }

  }

  for(unsigned k = 0; k<offlineFilters.size() ; k++) allFilters.push_back(offlineFilters[k]);
  for(unsigned k = 0; k<offlineFilters.size() ; k++) allFiltersE.push_back(offlineFiltersE[k]);


  std::vector<std::pair<float,float> > SMsums;

  for(unsigned int i = 0; i < allFilters.size(); i++){
    float SM=0,SME2=0;
    int helper = 0;
    for(int k = 0 ; k < samples.size()-1; k++){
      if( !(samples[k].find("Z")!=string::npos && i<9 && helper!=0) ) 
	SM+=(allFilters[i].find(samples[k]))->second;
      if( !(samples[k].find("Z")!=string::npos && i<9 && helper!=0) ) 
	SME2+=(allFiltersE[i].find(samples[k]))->second*(allFiltersE[i].find(samples[k]))->second;
      if( samples[k].find("Z")!=string::npos ) helper++;
    }
    SMsums.push_back( make_pair(SM,SME2 ));
  }


  //out<<"\\begin{center}"<<endl;
  out<<"\\begin{tabular}[!htbp]{|c";
  for(int k = 0 ; k < samples.size(); k++) out<<"|c";
  out<<"|c|} \\hline"<<endl;
  out<< "Cut & ";
  for(int k = 0 ; k < samples.size(); k++){
    out << (fullMap.find(samples[k]))->first;
    if(k!=samples.size()-1) out <<" & " ;
    else out << " & $\\Sigma$ SM \\\\ " << endl;
  }
  out <<  " \\hline" << endl;

  
  for(int i = 0; i < allFilters.size(); i++){
    out << filters[i] << " & ";
    for(int k = 0 ; k < samples.size(); k++){
      if(samples[k].find("Data")==string::npos) 
	out << (allFilters[i].find(samples[k]))->second << " $\\pm$ " << (allFiltersE[i].find(samples[k]))->second;
      else
	out << (allFilters[i].find(samples[k]))->second;
      if(k!=samples.size()-1) out <<" & " ;
      else out << " & " << SMsums[i].first << "$\\pm$" <<  sqrt(SMsums[i].second) << " \\\\ " << endl;
    }
    out <<  " \\hline" << endl;

  }
  
  out<<"\\end{tabular}"<<endl;
  //out<<"\\end{center}"<<endl;

  ///////////////////////////////////////////////////////////////////////////////////////////////
  TCanvas *c1 = new TCanvas("c1CutFlowMass","",5,30,650,600);
  c1->SetGrid(0,0);
  c1->SetFillStyle(4000);
  c1->SetFillColor(10);
  c1->SetTicky();
  c1->SetObjectStat(0);
  c1->SetLogy(1);
 
  TLegend* leg = new TLegend(0.55,0.55,0.80,0.88,NULL,"brNDC");
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetFillColor(10);
  leg->SetTextSize(0.04);
  leg->SetHeader( "#mu+#tau" );

  THStack* aStack = new THStack("aStack",Form("CMS Preliminary 2011    #sqrt{s}=7 TeV L=%.0f pb^{-1}",Lumi));

  std::vector<TH1F*> histos;
  for(unsigned int k = 0 ; k < samples.size(); k++){
    TH1F* h1 = new TH1F( ("h1_"+samples[k]).c_str(), Form("CMS Preliminary 2011    #sqrt{s}=7 TeV L=%.0f pb^{-1} ; ; Events",Lumi) , filters.size(), 0, filters.size());

    if( (samples[k]).find("ZfakeTau")!=string::npos ) {
      h1->SetFillColor(7);
      leg->AddEntry(h1,"Z+jets, fake-#tau","F");
    }
    if( (samples[k]).find("Ztautau")!=string::npos ) {
      h1->SetFillColor(kRed);
      leg->AddEntry(h1,"Z+jets, genuine #tau","F");
    }
    if( (samples[k]).find("TTbar")!=string::npos ) {
      h1->SetFillColor(kBlue);
      leg->AddEntry(h1,"t#bar{t}+jets","F");
    }
    if( (samples[k]).find("SingleTop")!=string::npos ) {
      h1->SetFillColor(kMagenta);
      leg->AddEntry(h1,"single-t","F");
    }
    if( (samples[k]).find("Top")!=string::npos ) {
      h1->SetFillColor(kMagenta);
      leg->AddEntry(h1,"Top","F");
    }
    if( (samples[k]).find("Wjets")!=string::npos ) {
      h1->SetFillColor(kGreen);
      leg->AddEntry(h1,"W+jets","F");
    }
    if( (samples[k]).find("EWK")!=string::npos ) {
      h1->SetFillColor(kGreen);
      leg->AddEntry(h1,"W+Others","F");
    }
    if( (samples[k]).find("DiBoson")!=string::npos ) {
      h1->SetFillColor(38);
      leg->AddEntry(h1,"Di-Boson","F");
    }
    if( (samples[k]).find("QCD")!=string::npos ) {
      h1->SetFillColor(42);
      leg->AddEntry(h1,"QCD-multijets","F");
    }
    if((samples[k]).find("qqH115")!=string::npos){
      h1->SetLineWidth(2);
      h1->SetLineColor(kBlack);
      h1->SetFillColor(kBlack);     
      h1->SetFillStyle(3004);
      leg->AddEntry(h1,"qqH(115)","F");
    }
    if((samples[k]).find("ggH115")!=string::npos){
      h1->SetLineWidth(2);
      h1->SetLineColor(kBlack);  
      h1->SetFillColor(kBlack);     
      h1->SetFillStyle(3005);
      leg->AddEntry(h1,"ggH(115)","F");
    }
    

    //h1->SetLineWidth(1.4);
    for(int v = 0; v < filters.size(); v++){
      h1->GetXaxis()->SetBinLabel(v+1,filters[v].c_str());
      h1->SetBinContent(v+1, (allFilters[v].find(samples[k]))->second );
    }
    if(samples[k].find("Data")!=string::npos){
      h1->Sumw2();
      h1->SetMarkerStyle(20);
      h1->SetMarkerSize(1.2);
      h1->SetMarkerColor(kBlack);
      h1->SetLineColor(kBlack);
      leg->AddEntry(h1,"DATA","P");
    }
    //else leg->AddEntry(h1,samples[k].c_str(),"L");
    histos.push_back(h1);
  }

  for(unsigned int k = 0 ; k < histos.size(); k++){
    string histoName =  std::string( histos[k]->GetName() );
    if( histoName.find("Data")== string::npos) aStack->Add(histos[k]);
  }
  aStack->Draw("HIST");
  TH1F* hStack = (TH1F*)aStack->GetHistogram();
  aStack->GetYaxis()->SetRangeUser(0.01,10000000);

  for(unsigned int k = 0 ; k < histos.size(); k++){
    string histoName =  std::string( histos[k]->GetName() );
    if( histoName.find("Data")!= string::npos){
      histos[k]->Sumw2();
      histos[k]->Draw("PSAME");
    }
  }

  leg->Draw();

  return;

}
Пример #30
0
/** 
 * Draw final plot for QM2011
 * 
 * @param max 
 * 
 * @ingroup pwglf_forward_scripts
 */
void
dndeta_final(Double_t max=6)
{
  gStyle->SetOptTitle(0);
  gStyle->SetOptFit(0);
  gStyle->SetTitleFont(132, "xyz");
  gStyle->SetTitleSize(0.1, "xyz");
  gStyle->SetTitleOffset(0.4, "y");
  gStyle->SetTitleOffset(0.8, "x");
  gStyle->SetLabelFont(132, "xyz");
  gStyle->SetLabelSize(0.08, "xyz");
  gStyle->SetNdivisions(212, "x");
  gStyle->SetNdivisions(208, "y");
  gStyle->SetTextFont(132);
  gStyle->SetPadColor(0);
  gStyle->SetPadBorderMode(0);
  // gStyle->SetFillColor(0);
  // gStyle->SetFillStyle(0);
  
  TCanvas* c = new TCanvas("c", "c", 900, 900);
  c->SetFillColor(0);
  c->SetFillStyle(0);
  c->SetBorderSize(0);
  c->SetBorderMode(0);
  c->SetRightMargin(0.02);
  c->SetTopMargin(0.02);
  c->SetBottomMargin(0.15);
  c->Divide(1,3,0,0);
  
  // --- INEL --------------------------------------------------------
  TVirtualPad* p = c->cd(1);
  p->SetGridx();
  p->SetRightMargin(.01);
  THStack* inel     = new THStack("inel", "INEL");
  TLatex*  inelT    = new TLatex(1-p->GetRightMargin()-.01, 
				 1-p->GetTopMargin()-.01, 
				 "INEL");
  inelT->SetNDC();
  inelT->SetTextAlign(33);
  inelT->SetTextSize(0.12);
  TLegend* inelL    = new TLegend(.3, .02, .8, .4);
  inelL->SetBorderSize(0);
  inelL->SetNColumns(2);
  inelL->SetFillColor(0);
  inelL->SetFillStyle(0);
  TLegendEntry* e = inelL->AddEntry("d1", "Forward", "lp");
  e->SetMarkerColor(kRed+2);
  e->SetMarkerStyle(29);
  e = inelL->AddEntry("d2", "Central", "lp");
  e->SetMarkerColor(kMagenta+2);    
  e->SetMarkerStyle(29);
  e = inelL->AddEntry("d3", "Data", "lp");
  e->SetMarkerStyle(29);
  e = inelL->AddEntry("d4", "Mirrored data", "lp");
  e->SetMarkerStyle(30);
  e = inelL->AddEntry("d5", "Systematic error", "f");
  e->SetFillColor(kGray); 
  e->SetLineColor(kGray);
  e->SetLineWidth(0);
  e->SetFillStyle(3001);
  
  gROOT->LoadMacro("export_pp_0900GeV_INEL_m10p10cm_000100000ev.C");
  export_pp_0900GeV_INEL_m10p10cm_000100000ev(inel, inelL, 20);
  export_pp_0900GeV_INEL_m10p10cm_000100000ev(inel, inelL, 21);
  export_pp_0900GeV_INEL_m10p10cm_000100000ev(inel, inelL, 22);
  inel->Draw("nostack e1");
  inel->GetHistogram()->SetYTitle("#frac{1}{N}#frac{dN_{ch}}{d#eta}");
  inel->GetHistogram()->SetXTitle("#eta");
  inel->GetHistogram()->GetYaxis()->SetDecimals();
  inelL->Draw();
  inelT->Draw();

  // --- INEL>0 ------------------------------------------------------
  p = c->cd(2);
  p->SetGridx();
  p->SetRightMargin(.01);
  THStack* inelgt0     = new THStack("inelgt0", "INEL>0");
  TLatex*  inelgt0T    = new TLatex(1-p->GetRightMargin()-.01, 
				    1-p->GetTopMargin()-.01, 
				    "INEL>0");
  inelgt0T->SetNDC();
  inelgt0T->SetTextAlign(33);
  inelgt0T->SetTextSize(0.12);
  gROOT->LoadMacro("export_pp_0900GeV_INEL_m10p10cm_000100000ev.C");
  export_pp_0900GeV_INEL_m10p10cm_000100000ev(inelgt0, 0, 20);
  export_pp_0900GeV_INEL_m10p10cm_000100000ev(inelgt0, 0, 21);
  export_pp_0900GeV_INEL_m10p10cm_000100000ev(inelgt0, 0, 22);
  inelgt0->Draw("nostack e1");
  inelgt0->GetHistogram()->SetXTitle("#eta");
  inelgt0->GetHistogram()->GetYaxis()->SetDecimals();
  inelgt0T->Draw();

  // --- NSD ---------------------------------------------------------
  p = c->cd(3);
  p->SetGridx();
  p->SetRightMargin(.01);
  THStack* nsd     = new THStack("nsd", "NSD");
  TLatex*  nsdT    = new TLatex(1-p->GetRightMargin()-.01, 
				1-p->GetTopMargin()-.01, 
				"NSD");
  nsdT->SetNDC();
  nsdT->SetTextAlign(33);
  nsdT->SetTextSize(0.12);
  gROOT->LoadMacro("export_pp_0900GeV_NSD_m10p10cm_000100000ev.C");
  export_pp_0900GeV_NSD_m10p10cm_000100000ev(nsd, 0, 20);
  export_pp_0900GeV_NSD_m10p10cm_000100000ev(nsd, 0, 21);
  export_pp_0900GeV_NSD_m10p10cm_000100000ev(nsd, 0, 22);
  nsd->Draw("nostack e1");
  nsd->GetHistogram()->SetXTitle("#eta");
  nsd->GetHistogram()->GetYaxis()->SetDecimals();
  nsdT->Draw();

  c->cd();
  c->SaveAs("dndeta_final.png");
}