示例#1
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));
  }  
示例#2
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;
}
示例#3
0
int runPFSortedJets(std::string fileName) {

    // Create file on which histogram(s) can be saved.
    TFile *inFile = new TFile(fileName.c_str(), "READ");
    THStack* partFracs = new THStack("particlestacks", "");

    // Read histograms.
    vector<TProfile*> fractionProfiles;
    for (int idx = 0; idx != 16; ++idx){
        std::stringstream tmpString("");
        tmpString << "a" << idx; 
        // a = all, g = gluonjets, q = quarkjets, lq = low pt quarks, hq = high pt quarks
        fractionProfiles.push_back( (TProfile*) inFile->Get( tmpString.str().c_str()) );
    }
    cout << fractionProfiles.size();

    vector<TH1D*> fractionHists;
    for (int idx = 0; idx != 16; ++idx){
        fractionHists.push_back( fractionProfiles[idx]->ProjectionX("","") );
    }
    vector<TH1D*> PFfracs;
    PFfracs.push_back( (TH1D*) fractionHists[0]->Clone("chf") );
    PFfracs[0]->Add( fractionHists[1] );
    PFfracs[0]->Add( fractionHists[3] );
    PFfracs[0]->Add( fractionHists[4] );
    PFfracs[0]->Add( fractionHists[7] );
    PFfracs[0]->Add( fractionHists[8] );
    PFfracs[0]->Add( fractionHists[13] );
    PFfracs.push_back( (TH1D*) fractionHists[2]->Clone("phf") );
    PFfracs[1]->Add( fractionHists[11] );
    PFfracs.push_back( (TH1D*) fractionHists[5]->Clone("nhf") );
    PFfracs[2]->Add( fractionHists[6] );
    PFfracs[2]->Add( fractionHists[9] );
    PFfracs[2]->Add( fractionHists[10] );
    PFfracs[2]->Add( fractionHists[12] );
    PFfracs.push_back( (TH1D*) fractionHists[14]->Clone("elf+muf") );
    PFfracs.push_back( (TH1D*) fractionHists[15]->Clone("others") );

    PFfracs[0]->SetFillColor(kRed);
    PFfracs[1]->SetFillColor(kBlue);
    PFfracs[2]->SetFillColor(kGreen);
    PFfracs[3]->SetFillColor(kYellow);
    PFfracs[4]->SetFillColor(kCyan);

    for (unsigned i = 0; i != PFfracs.size(); ++i){
        partFracs->Add( PFfracs[i] );
    }

    TCanvas *canv = tdrCanvas("c1",fractionHists[0],12,0,1);//new TCanvas("c1","c1",600,600);

    stackModify(fractionHists[0]);
    partFracs->SetHistogram( fractionHists[0] );
    partFracs->GetHistogram()->SetMaximum(1.01);
    partFracs->GetHistogram()->SetMinimum(-0.01);
    //partFracs->SetFillStyle(4000);

    TLegend *leg = tdrLeg(0.83,0.1,0.98,0.93);
    leg->AddEntry( PFfracs[4], "rest", "f" );
    leg->AddEntry( PFfracs[3], "elf+muf", "f" );
    leg->AddEntry( PFfracs[2], "nhf", "f" );
    leg->AddEntry( PFfracs[1], "phf", "f" );
    leg->AddEntry( PFfracs[0], "chf", "f" );
    leg->SetTextSize(0.045);

    TLatex latex;
    latex.SetNDC();
    latex.SetTextAngle(0);
    latex.SetTextColor(kBlack);

    latex.SetTextFont(42);
    latex.SetTextAlign(31);
    latex.SetTextSize(0.6*0.07);

    partFracs->Draw("same");
    latex.DrawLatex(0.77,0.85,"Pythia 6 Z2*");

    //fixOverlay();
    //canv->Print("efracs.pdf"); 
    // Done.
    return 0;
}
示例#4
0
void comparisonJetMCData(string plot,int rebin){
  string tmp;

  string dir="/gpfs/cms/data/2011/Observables/Approval/";
	
  if (isAngularAnalysis){
    mcfile=dir+"MC_zjets"+version;
    back_w=dir+"MC_wjets"+version;
    back_ttbar=dir+"MC_ttbar"+version;
    WW=dir+"MC_diW"+version;
    ZZ=dir+"MC_siZ"+version;
    WZ=dir+"MC_diWZ"+version;
    datafile=dir+"DATA"+version;
    mcfiletau=dir+"MC_zjetstau"+version;
  }
  // List of files

  TFile *dataf = TFile::Open(datafile.c_str()); //data file
  TFile *mcf = TFile::Open(mcfile.c_str()); //MC file
  TFile *mcftau = TFile::Open(mcfiletau.c_str()); //MC file
  TFile *ttbarf = TFile::Open(back_ttbar.c_str()); //MC background file
  TFile *wf = TFile::Open(back_w.c_str());


  TFile *qcd23emf = TFile::Open(qcd23em.c_str());
  TFile *qcd38emf = TFile::Open(qcd38em.c_str());
  TFile *qcd817emf = TFile::Open(qcd817em.c_str());

  TFile *qcd23bcf = TFile::Open(qcd23bc.c_str());
  TFile *qcd38bcf = TFile::Open(qcd38bc.c_str());
  TFile *qcd817bcf = TFile::Open(qcd817bc.c_str());

  TFile *WZf = TFile::Open(WZ.c_str());
  TFile *ZZf = TFile::Open(ZZ.c_str());
  TFile *WWf = TFile::Open(WW.c_str());


  // Canvas
  if (CanvPlot) delete CanvPlot;
  CanvPlot = new TCanvas("CanvPlot","CanvPlot",0,0,800,600);

  // Getting, defining ...
  dataf->cd("validationJEC");
  if (isMu && isAngularAnalysis) dataf->cd("validationJECmu");
	
  TObject * obj;
  gDirectory->GetObject(plot.c_str(),obj);

  TH1 *data;
  TH2F *data2; 
  TH1D *data3; 

  THStack *hs = new THStack("hs","Total MC");


  int flag=-1;
  if ((data = dynamic_cast<TH1F *>(obj)) ){
    flag=1;
    gROOT->Reset();
    gROOT->ForceStyle();
    gStyle->SetPadRightMargin(0.03);
    gPad->SetLogy(1);
    gPad->Modified();
    gPad->Update();
  }
  if ((data2 = dynamic_cast<TH2F *>(obj)) ){
    flag=2;
    gStyle->SetPalette(1);
    gStyle->SetPadRightMargin(0.15);
    gPad->Modified();
  }



  //===================
  // Dirty jobs :)
  if (flag==1){
    CanvPlot->cd();
    TPad *pad1 = new TPad("pad1","pad1",0.01,0.33,0.99,0.99);
    pad1->Draw();
    pad1->cd();
    pad1->SetTopMargin(0.1);
    pad1->SetBottomMargin(0.01);
    pad1->SetRightMargin(0.1);
    pad1->SetFillStyle(0);
    pad1->SetLogy(1);
    TString str=data->GetTitle();
    if (str.Contains("jet") && !str.Contains("zMass") && !str.Contains("Num") && !str.Contains("Eta") && !str.Contains("Phi") && !str.Contains("eld") && !str.Contains("meanPtZVsNjet")) {
      if (!isAngularAnalysis) rebin=1;
    }

    //======================
    // DATA
    Double_t dataint = data->Integral();
    data->SetLineColor(kBlack);
    data->Rebin(rebin);
    if(str.Contains("nJetVtx")) data->GetXaxis()->SetRangeUser(0,10);	
    if(str.Contains("zMass")) data->GetXaxis()->SetRangeUser(70,110);	
    data->SetMinimum(1.);
    data->Sumw2();

    //Canvas style copied from plotsHistsRatio.C
    data->SetLabelSize(0.0);
    data->GetXaxis()->SetTitleSize(0.00);
    data->GetYaxis()->SetLabelSize(0.07);
    data->GetYaxis()->SetTitleSize(0.08);
    data->GetYaxis()->SetTitleOffset(0.76);
    data->SetTitle("");
    gStyle->SetOptStat(0);

    data->GetYaxis()->SetLabelSize(0.06);
    data->GetYaxis()->SetTitleSize(0.06);
    data->GetYaxis()->SetTitleOffset(0.8);

    data->Draw("E1");


    TLegend* legend = new TLegend(0.725,0.27,0.85,0.72);
    legend->SetFillColor(0);
    legend->SetFillStyle(0);
    legend->SetBorderSize(0);
    legend->SetTextSize(0.060);
    legend->AddEntry(data,"data","p");

    // hack to calculate some yields in restricted regions...
    int num1=0, num2=0, num3=0, num4=0, num5=0;
    if(str.Contains("invMass") && !str.Contains("PF")){
      for(int j=1;j<=data->GetNbinsX();j++){
	num1 += data->GetBinContent(j); 		//conto quante Z ci sono tra 60 e 120 GeV
	if(j>10&&j<=50) num2 += data->GetBinContent(j); // ... tra 70 e 110
	if(j>15&&j<=45) num3 += data->GetBinContent(j); // ... tra 75 e 105
      }
      cout << "\n";
      cout << data->GetNbinsX() <<" Number of bins of the invmass histo\n";
      printf("Number of Z in 60-120 %i --- 70-110 %i --- 75-105 %i \n",num1,num2,num3);
      cout << "\n";
    }
    if(str.Contains("zYieldVsjets") && !str.Contains("Vtx")){
      for(int j=1;j<=data->GetNbinsX();j++){
	num1 += data->GetBinContent(j); 		//conto quante Z
	if(j>1) num2 += data->GetBinContent(j); // ... +1,2,3,4... jets
	if(j>2) num3 += data->GetBinContent(j); // ... +2,3,4... jets
	if(j>3) num4 += data->GetBinContent(j); // ..    if(str=="jet_pT"){
	if(j>4) num5 += data->GetBinContent(j); // ... +4... jets
      }
      cout << "\n";
      cout << data->GetNbinsX() <<" Number of bins of the zYieldVsjets histo\n";
      printf("Number of Z+n jet %i --- >1 %i --- >2 %i --- >3 %i --- >4 %i \n",num1,num2,num3,num4,num5);
      cout << "\n";
    }    

    //======================
    // Z + jets signal
    mcf->cd("validationJEC");
    if (isMu) mcf->cd("validationJECmu/");

    if (isAngularAnalysis) {
      mcf->cd("validationJEC/");
      if (isMu) mcf->cd("validationJECmu/");
    }

    TH1F* mc;
    gDirectory->GetObject(plot.c_str(),mc);
    TH1F * hsum;
    if(mc){
      hsum =  (TH1F*) mc->Clone();
      hsum->SetTitle("hsum");
      hsum->SetName("hsum");
      hsum->Reset();

      Double_t mcint = mc->Integral();
      mc->SetFillColor(kRed);
      mc->Sumw2();
      if(lumiweights==0) mc->Scale(dataint/mcint);
		
      // Blocco da propagare negli altri MC
      if(zNumEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) mc->Scale( dataLumi2011pix / (zNumEvents / zjetsXsect));
	    else mc->Scale( dataLumi2011 / (zNumEvents / zjetsXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) mc->Scale( dataLumi2011Apix / (zNumEvents / zjetsXsect));
	      else mc->Scale( dataLumi2011A / (zNumEvents / zjetsXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) mc->Scale( dataLumi2011Bpix / (zNumEvents / zjetsXsect));
	      else mc->Scale( dataLumi2011B / (zNumEvents / zjetsXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) mc->Scale(zjetsScale);
      }

      // fin qui
      if(lumiweights==1) mc->Scale(1./zwemean);  // perche' i Weights non fanno 1...
      mc->Rebin(rebin);
      if(lumiweights==0) mc->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      hsum->Add(mc);
      legend->AddEntry(mc,"Z+jets","f");
    }

    //======================
    // ttbar
    ttbarf->cd("validationJEC");
    if (isMu) ttbarf->cd("validationJECmu/");

    if (isAngularAnalysis) {
      ttbarf->cd("validationJEC/");
      if (isMu) ttbarf->cd("validationJECmu/");
    }

    TH1F* ttbar;
    gDirectory->GetObject(plot.c_str(),ttbar);
	
    if(ttbar){
      ttbar->SetFillColor(kBlue);
      ttbar->Sumw2();

      if(ttNumEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) ttbar->Scale( dataLumi2011pix / (ttNumEvents / ttbarXsect));
	    else ttbar->Scale( dataLumi2011 / (ttNumEvents / ttbarXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) ttbar->Scale( dataLumi2011Apix / (ttNumEvents / ttbarXsect));
	      else ttbar->Scale( dataLumi2011A / (ttNumEvents / ttbarXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) ttbar->Scale( dataLumi2011Bpix / (ttNumEvents / ttbarXsect));
	      else ttbar->Scale( dataLumi2011B / (ttNumEvents / ttbarXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) ttbar->Scale(ttwemean);
      }
      // fin qui
		
      if(lumiweights==1) ttbar->Scale(1./ttwemean);  // perche' i Weights non fanno 1...
      ttbar->Rebin(rebin);
      if(lumiweights==0) ttbar->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      hsum->Add(ttbar);
      if(lumiweights==1)legend->AddEntry(ttbar,"ttbar","f");

      //////////
      //Storing the bckgrounds!
      //////////
      cout<<str<<endl;
      if (isAngularAnalysis){
      if(str=="jet_pT") evaluateAndFillBackgrounds(ttbar,"jet_pT");
      if(str=="jet_pT2") evaluateAndFillBackgrounds(ttbar,"jet_pT2");
      if(str=="jet_pT3") evaluateAndFillBackgrounds(ttbar,"jet_pT3");
      if(str=="jet_pT4") evaluateAndFillBackgrounds(ttbar,"jet_pT4");
      if(str=="Jet_multi") evaluateAndFillBackgrounds(ttbar,"jet_Multiplicity");
      if(str=="jet_eta") evaluateAndFillBackgrounds(ttbar,"jet_eta");
      if(str=="jet_eta2") evaluateAndFillBackgrounds(ttbar,"jet_eta2");
      if(str=="jet_eta3") evaluateAndFillBackgrounds(ttbar,"jet_eta3");
      if(str=="jet_eta4") evaluateAndFillBackgrounds(ttbar,"jet_eta4");
      if(str=="HT") evaluateAndFillBackgrounds(ttbar,"HT");
      if(str=="HT_1j") evaluateAndFillBackgrounds(ttbar,"HT1");
      if(str=="HT_2j") evaluateAndFillBackgrounds(ttbar,"HT2");
      if(str=="HT_3j") evaluateAndFillBackgrounds(ttbar,"HT3");
      if(str=="HT_4j") evaluateAndFillBackgrounds(ttbar,"HT4");
      if(str=="Phi_star") evaluateAndFillBackgrounds(ttbar,"PhiStar");
      }
    }

    //======================
    // w+jets
    wf->cd("validationJEC");
    if (isMu) wf->cd("validationJECmu/");
    if (isAngularAnalysis) {
      wf->cd("validationJEC/");
      if (isMu) wf->cd("validationJECmu/");      
    }

    TH1F* w;
    gDirectory->GetObject(plot.c_str(),w);
    if(w){

      w->SetFillColor(kViolet+2);
      w->Sumw2();

      if(wNumEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) w->Scale( dataLumi2011pix / (wNumEvents / wjetsXsect));
	    else w->Scale( dataLumi2011 / (wNumEvents / wjetsXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) w->Scale( dataLumi2011Apix / (wNumEvents / wjetsXsect));
	      else w->Scale( dataLumi2011A / (wNumEvents / wjetsXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) w->Scale( dataLumi2011Bpix / (wNumEvents / wjetsXsect));
	      else w->Scale( dataLumi2011B / (wNumEvents / wjetsXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) w->Scale(wwemean);
      }
      // fin qui
		
      if(lumiweights==1) w->Scale(1./wwemean);  // perche' i Weights non fanno 1...
      w->Rebin(rebin);
      if(lumiweights==0) w->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      hsum->Add(w);
      if(lumiweights==1)legend->AddEntry(w,"W+jets","f");
    }

    //======================
    // wz+jets
    WZf->cd("validationJEC");
    if (isMu) WZf->cd("validationJECmu/");

    if (isAngularAnalysis) {
      WZf->cd("validationJEC/");
      if (isMu) WZf->cd("validationJECmu/");
    }

    TH1F* wz;
    gDirectory->GetObject(plot.c_str(),wz);
    if(wz){
      wz->SetFillColor(kYellow+2);
      wz->Sumw2();

      if(wzEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) wz->Scale( dataLumi2011pix / (wzEvents / WZXsect));
	    else wz->Scale( dataLumi2011 / (wzEvents / WZXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) wz->Scale( dataLumi2011Apix / (wzEvents / WZXsect));
	      else wz->Scale( dataLumi2011A / (wzEvents / WZXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) wz->Scale( dataLumi2011Bpix / (wzEvents / WZXsect));
	      else wz->Scale( dataLumi2011B / (wzEvents / WZXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) wz->Scale(wzjetsScale);
      }
      // fin qui
		
      if(lumiweights==1) wz->Scale(1./wzwemean);  // perche' i Weights non fanno 1...
      wz->Rebin(rebin);
      if(lumiweights==0) wz->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      hsum->Add(wz);
      legend->AddEntry(wz,"WZ+jets","f");


      //////////
      //Storing the bckgrounds!
      //////////
     if (isAngularAnalysis){
      if(str=="jet_pT") evaluateAndFillBackgrounds(wz,"jet_pT");
      if(str=="jet_pT2") evaluateAndFillBackgrounds(wz,"jet_pT2");
      if(str=="jet_pT3") evaluateAndFillBackgrounds(wz,"jet_pT3");
      if(str=="jet_pT4") evaluateAndFillBackgrounds(wz,"jet_pT4");
      if(str=="jet_eta") evaluateAndFillBackgrounds(wz,"jet_eta");
      if(str=="jet_eta2") evaluateAndFillBackgrounds(wz,"jet_eta2");
      if(str=="jet_eta3") evaluateAndFillBackgrounds(wz,"jet_eta3");
      if(str=="jet_eta4") evaluateAndFillBackgrounds(wz,"jet_eta4");
      if(str=="Jet_multi") evaluateAndFillBackgrounds(wz,"jet_Multiplicity");
      if(str=="HT") evaluateAndFillBackgrounds(wz,"HT");
      if(str=="HT_1j") evaluateAndFillBackgrounds(wz,"HT1");
      if(str=="HT_2j") evaluateAndFillBackgrounds(wz,"HT2");
      if(str=="HT_3j") evaluateAndFillBackgrounds(wz,"HT3");
      if(str=="HT_4j") evaluateAndFillBackgrounds(wz,"HT4");
      if(str=="Phi_star") evaluateAndFillBackgrounds(wz,"PhiStar");
     }
    }
    
		
    //======================
    // zz+jets
    ZZf->cd("validationJEC");
    if (isMu) ZZf->cd("validationJECmu/");

    if (isAngularAnalysis) {
      ZZf->cd("validationJEC/");
      if (isMu) ZZf->cd("validationJECmu/");
    }

    TH1F* zz;
    gDirectory->GetObject(plot.c_str(),zz);
    if(zz){
      zz->SetFillColor(kOrange+2);
      zz->Sumw2();

      if(zzEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) zz->Scale( dataLumi2011pix / (zzEvents / ZZXsect));
	    else zz->Scale( dataLumi2011 / (zzEvents / ZZXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) zz->Scale( dataLumi2011Apix / (zzEvents / ZZXsect));
	      else zz->Scale( dataLumi2011A / (zzEvents / ZZXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) zz->Scale( dataLumi2011Bpix / (zzEvents / ZZXsect));
	      else zz->Scale( dataLumi2011B / (zzEvents / ZZXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) zz->Scale(zzjetsScale);
      }
      // fin qui
		
      if(lumiweights==1) zz->Scale(1./zzwemean);  // perche' i Weights non fanno 1...
      zz->Rebin(rebin);
      if(lumiweights==0) zz->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      hsum->Add(zz);
      legend->AddEntry(zz,"ZZ+jets","f");

      //////////
      //Storing the bckgrounds!
      //////////
     if (isAngularAnalysis){
      if(str=="jet_pT") evaluateAndFillBackgrounds(zz,"jet_pT");
      if(str=="jet_pT2") evaluateAndFillBackgrounds(zz,"jet_pT2");
      if(str=="jet_pT3") evaluateAndFillBackgrounds(zz,"jet_pT3");
      if(str=="jet_pT4") evaluateAndFillBackgrounds(zz,"jet_pT4");
      if(str=="jet_eta") evaluateAndFillBackgrounds(zz,"jet_eta");
      if(str=="jet_eta2") evaluateAndFillBackgrounds(zz,"jet_eta2");
      if(str=="jet_eta3") evaluateAndFillBackgrounds(zz,"jet_eta3");
      if(str=="jet_eta4") evaluateAndFillBackgrounds(zz,"jet_eta4");
      if(str=="Jet_multi") evaluateAndFillBackgrounds(zz,"jet_Multiplicity");
      if(str=="HT") evaluateAndFillBackgrounds(zz,"HT");
      if(str=="HT_1j") evaluateAndFillBackgrounds(zz,"HT1");
      if(str=="HT_2j") evaluateAndFillBackgrounds(zz,"HT2");
      if(str=="HT_3j") evaluateAndFillBackgrounds(zz,"HT3");
      if(str=="HT_4j") evaluateAndFillBackgrounds(zz,"HT4");
      if(str=="Phi_star") evaluateAndFillBackgrounds(zz,"PhiStar");
     }  
    }
    
    //======================
    // ww+jets
    WWf->cd("validationJEC");
    if (isMu) WWf->cd("validationJECmu/");

    if (isAngularAnalysis) {
      WWf->cd("validationJEC/");
      if (isMu) WWf->cd("validationJECmu/");
    }

    TH1F* ww;
    gDirectory->GetObject(plot.c_str(),ww);
    if(ww){
      ww->SetFillColor(kBlack);
      ww->Sumw2();

      if(wwEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) ww->Scale( dataLumi2011pix / (wwEvents / WWXsect));
	    else ww->Scale( dataLumi2011 / (wwEvents / WWXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) ww->Scale( dataLumi2011Apix / (wwEvents / WWXsect));
	      else ww->Scale( dataLumi2011A / (wwEvents / WWXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) ww->Scale( dataLumi2011Bpix / (wwEvents / WWXsect));
	      else ww->Scale( dataLumi2011B / (wwEvents / WWXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) ww->Scale(wwjetsScale);
      }
      // fin qui
		
      if(lumiweights==1) ww->Scale(1./wwwemean);  // perche' i Weights non fanno 1...
      ww->Rebin(rebin);
      if(lumiweights==0) ww->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      hsum->Add(ww);
      legend->AddEntry(ww,"WW+jets","f");

      //////////
      //Storing the bckgrounds!
      //////////
     if (isAngularAnalysis){
      if(str=="jet_pT") evaluateAndFillBackgrounds(ww,"jet_pT");
      if(str=="jet_pT2") evaluateAndFillBackgrounds(ww,"jet_pT2");
      if(str=="jet_pT3") evaluateAndFillBackgrounds(ww,"jet_pT3");
      if(str=="jet_pT4") evaluateAndFillBackgrounds(ww,"jet_pT4");
      if(str=="jet_eta") evaluateAndFillBackgrounds(ww,"jet_eta");
      if(str=="jet_eta2") evaluateAndFillBackgrounds(ww,"jet_eta2");
      if(str=="jet_eta3") evaluateAndFillBackgrounds(ww,"jet_eta3");
      if(str=="jet_eta4") evaluateAndFillBackgrounds(ww,"jet_eta4");
      if(str=="Jet_multi") evaluateAndFillBackgrounds(ww,"jet_Multiplicity");
      if(str=="HT") evaluateAndFillBackgrounds(ww,"HT");
      if(str=="HT_1j") evaluateAndFillBackgrounds(ww,"HT1");
      if(str=="HT_2j") evaluateAndFillBackgrounds(ww,"HT2");
      if(str=="HT_3j") evaluateAndFillBackgrounds(ww,"HT3");
      if(str=="HT_4j") evaluateAndFillBackgrounds(ww,"HT4");
      if(str=="Phi_star") evaluateAndFillBackgrounds(ww,"PhiStar");
     }
    }

    /// Tau 

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

    mcftau->cd("validationJEC");
    if (isMu) mcftau->cd("validationJECmu/");

    if (isAngularAnalysis) {
      mcftau->cd("validationJEC/");
      if (isMu) mcftau->cd("validationJECmu/");
    }

    TH1F* tau;
    gDirectory->GetObject(plot.c_str(),tau);
    if(tau){
      tau->SetFillColor(kGreen);
      tau->Sumw2();

      if(zNumEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) tau->Scale( dataLumi2011pix / (zNumEvents / zjetsXsect));
	    else tau->Scale( dataLumi2011 / (zNumEvents / zjetsXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) tau->Scale( dataLumi2011Apix / (zNumEvents / zjetsXsect));
	      else tau->Scale( dataLumi2011A / (zNumEvents / zjetsXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) tau->Scale( dataLumi2011Bpix / (zNumEvents / zjetsXsect));
	      else tau->Scale( dataLumi2011B / (zNumEvents / zjetsXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) tau->Scale(zjetsScale);
      }
      // fin qui
		
      if(lumiweights==1) tau->Scale(1./zwemean);  // perche' i Weights non fanno 1...
      tau->Rebin(rebin);
      if(lumiweights==0) tau->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      tau->Scale(1./1000.); //aaaaaaa
      hsum->Add(tau);
      legend->AddEntry(tau,"#tau#tau+jets","f");

      //////////
      //Storing the bckgrounds!
      //////////
     if (isAngularAnalysis){
      if(str=="jet_pT") evaluateAndFillBackgrounds(tau,"jet_pT");
      if(str=="jet_pT2") evaluateAndFillBackgrounds(tau,"jet_pT2");
      if(str=="jet_pT3") evaluateAndFillBackgrounds(tau,"jet_pT3");
      if(str=="jet_pT4") evaluateAndFillBackgrounds(tau,"jet_pT4");
      if(str=="jet_eta") evaluateAndFillBackgrounds(tau,"jet_eta");
      if(str=="jet_eta2") evaluateAndFillBackgrounds(tau,"jet_eta2");
      if(str=="jet_eta3") evaluateAndFillBackgrounds(tau,"jet_eta3");
      if(str=="jet_eta4") evaluateAndFillBackgrounds(tau,"jet_eta4");
      if(str=="Jet_multi") evaluateAndFillBackgrounds(tau,"jet_Multiplicity");
      if(str=="HT") evaluateAndFillBackgrounds(tau,"HT");
      if(str=="HT_1j") evaluateAndFillBackgrounds(tau,"HT1");
      if(str=="HT_2j") evaluateAndFillBackgrounds(tau,"HT2");
      if(str=="HT_3j") evaluateAndFillBackgrounds(tau,"HT3");
      if(str=="HT_4j") evaluateAndFillBackgrounds(tau,"HT4");
      if(str=="Phi_star") evaluateAndFillBackgrounds(tau,"PhiStar");
     }
    }


    /////////
    // Print the bkg contributions
    ////////

    for(int j=0;j<bckg_leadingJetPt.size();j++){      
      cout<<bckg_leadingJetPt[j]<<endl;
    }	

    //======================
    // QCD EM enriched
    qcd23emf->cd("validationJEC");
    TH1F* qcd23emp;
    gDirectory->GetObject(plot.c_str(),qcd23emp);

    if(qcd23emp){
      TH1D * qcdTotEM =  (TH1D*) qcd23emp->Clone(); 
      qcdTotEM->SetTitle("qcd em");
      qcdTotEM->SetName("qcd em");
      qcdTotEM->Reset();
      qcdTotEM->Rebin(rebin);

      qcd38emf->cd("validationJEC");
      TH1F* qcd38emp;
      gDirectory->GetObject(plot.c_str(),qcd38emp);


      qcd817emf->cd("validationJEC");
      TH1F* qcd817emp;
      gDirectory->GetObject(plot.c_str(),qcd817emp);

      qcd23emp->Rebin(rebin);
      qcd23emp->Sumw2();
      qcd23emp->Scale(qcd23emScale); 
      qcd38emp->Rebin(rebin);
      qcd38emp->Sumw2();
      qcd38emp->Scale(qcd38emScale); 
      qcd817emp->Rebin(rebin);
      qcd817emp->Sumw2();
      qcd817emp->Scale(qcd817emScale); 

      qcdTotEM->SetFillColor(kOrange+1);
      qcdTotEM->Add(qcd23emp);
      qcdTotEM->Add(qcd38emp);
      qcdTotEM->Add(qcd817emp);

      hsum->Add(qcdTotEM);

      //if(lumiweights==1)legend->AddEntry(qcdTotEM,"QCD em","f");
    }

    //======================
    // QCD bc
    qcd23bcf->cd("validationJEC");
    TH1F* qcd23bcp;
    TH1D * qcdTotBC;
    bool  qcdbcempty=true;
    gDirectory->GetObject(plot.c_str(),qcd23bcp);

    if(qcd23bcp){
      qcdTotBC =  (TH1D*) qcd23bcp->Clone(); 
      qcdTotBC->SetTitle("qcd bc");
      qcdTotBC->SetName("qcd bc");
      qcdTotBC->Reset();
      qcdTotBC->Rebin(rebin);

      qcd38bcf->cd("validationJEC");
      TH1F* qcd38bcp;
      gDirectory->GetObject(plot.c_str(),qcd38bcp);

      qcd817bcf->cd("validationJEC");
      TH1F* qcd817bcp;
      gDirectory->GetObject(plot.c_str(),qcd817bcp);

      qcd23bcp->Rebin(rebin);
      qcd23bcp->Sumw2();
      qcd23bcp->Scale(qcd23bcScale); 
      qcd38bcp->Rebin(rebin);
      qcd38bcp->Sumw2();
      qcd38bcp->Scale(qcd38bcScale); 
      qcd817bcp->Rebin(rebin);
      qcd817bcp->Sumw2();
      qcd817bcp->Scale(qcd817bcScale); 

      qcdTotBC->SetFillColor(kGreen+2);
      qcdTotBC->Add(qcd23bcp);
      qcdTotBC->Add(qcd38bcp);
      qcdTotBC->Add(qcd817bcp);

      hsum->Add(qcdTotBC);
      if (qcdTotBC->GetEntries()>0) qcdbcempty=false; 

      //if(lumiweights==1)legend->AddEntry(qcdTotBC,"QCD bc","f");
    }

    //======================
    // Add here other backgrounds


    //======================
    // Stacked Histogram
    //if(qcd23em) 	hs->Add(qcdTotEM);
    if(!qcdbcempty) 	hs->Add(qcdTotBC);
    if(w)  	        hs->Add(w);
    if (ww)         hs->Add(ww);
    if(tau)		hs->Add(tau); //Z+Jets
    if (zz)         hs->Add(zz);
    if (wz)         hs->Add(wz);
    if (ttbar)	hs->Add(ttbar);
    if(mc)		hs->Add(mc); //Z+Jets

    // per avere le statistiche
    if(lumiweights==1) hsum->Draw("HISTO SAME");


    //======================
    // Setting the stats
    //pad1->Update(); // altrimenti non becchi la stat
    
    //TPaveStats *r2;
    //if(lumiweights==0) r2 = (TPaveStats*)mc->FindObject("stats");
    //if(lumiweights==1) r2 = (TPaveStats*)hsum->FindObject("stats");
    //r2->SetY1NDC(0.875);     //Uncomment if you wonna add your statistics in the top right corner
    //r2->SetY2NDC(0.75); 
    //r2->SetTextColor(kRed);
		
    if(lumiweights==1) hs->Draw("HISTO SAME");
    gPad->RedrawAxis();
    data->Draw("E1 SAME");
    //r2->Draw(); //here to reactivate the stats
    legend->Draw();
    TLegend* lumi = new TLegend(0.45,0.3,0.75,0.2);
    lumi->SetFillColor(0);
    lumi->SetFillStyle(0);
    lumi->SetBorderSize(0);
    //lumi->AddEntry((TObject*)0,"#int L dt =4.9 1/fb","");
    lumi->Draw();
    string channel;
    if (isMu) channel="Z#rightarrow#mu#mu";
    if (!isMu) channel="Z#rightarrow ee";
    TLatex *latexLabel=CMSPrel(4.890,channel,0.55,0.85); // make fancy label
    latexLabel->Draw("same");

    CanvPlot->Update();

	


    //===============//
    // RATIO DATA MC //
    //===============//
    CanvPlot->cd();
    TPad *pad2 = new TPad("pad2","pad2",0.01,0.01,0.99,0.32);
    pad2->Draw();
    pad2->cd();
    pad2->SetTopMargin(0.01);
    pad2->SetBottomMargin(0.3);
    pad2->SetRightMargin(0.1);
    pad2->SetFillStyle(0);

    TH1D * ratio =  (TH1D*) data->Clone();
    ratio->SetTitle("");
    ratio->SetName("ratio");
    ratio->Reset();

    ratio->Sumw2();
    //data->Sumw2();
    hsum->Sumw2(); // FIXME controlla che sia corretto questo... 
    ratio->SetMarkerSize(.5);
    ratio->SetLineColor(kBlack);
    ratio->SetMarkerColor(kBlack);
    //gStyle->SetOptStat("m");
    TH1F* sumMC;

    hs->Draw("nostack"); 
 
   sumMC=(TH1F*) hs->GetHistogram();
    cout<<sumMC->GetEntries()<<endl;
    ratio->Divide(data,hsum,1.,1.);
    ratio->GetYaxis()->SetRangeUser(0.5,1.5);
    ratio->SetMarkerSize(0.8);
    //pad2->SetTopMargin(1);

   //Canvas style copied from plotsHistsRatio.C
    ratio->GetYaxis()->SetNdivisions(5);
    ratio->GetXaxis()->SetTitleSize(0.14);
    ratio->GetXaxis()->SetLabelSize(0.14);
    ratio->GetYaxis()->SetLabelSize(0.11);
    ratio->GetYaxis()->SetTitleSize(0.11);
    ratio->GetYaxis()->SetTitleOffset(0.43);
    ratio->GetYaxis()->SetTitle("ratio data/MC");   

    ratio->Draw("E1");
		
    TLine *OLine = new TLine(ratio->GetXaxis()->GetXmin(),1.,ratio->GetXaxis()->GetXmax(),1.);
    OLine->SetLineColor(kBlack);
    OLine->SetLineStyle(2);
    OLine->Draw();
 
    TLegend* label = new TLegend(0.60,0.9,0.50,0.95);
    label->SetFillColor(0);
    label->SetFillStyle(0);
    label->SetBorderSize(0);
    //horrible mess
    double binContent = 0;
    double binSum = 0;
    double weightSum = 0;
    double binError = 1;
    double totalbins = ratio->GetSize() -2;
    for(unsigned int bin=1;bin<=totalbins;bin++){
      binContent = ratio->GetBinContent(bin);
      binError = ratio->GetBinError(bin);
      if(binError!=0){
	binSum += binContent/binError;
	weightSum += 1./binError;
      }
    }
    double ymean = binSum / weightSum;
    //double ymean = ratio->GetMean(2);
    stringstream sYmean;
    sYmean << ymean;
    string labeltext=sYmean.str()+" mean Y";
    //label->AddEntry((TObject*)0,labeltext.c_str(),""); // mean on Y
    //label->Draw();
		
    //TPaveStats *r3 = (TPaveStats*)ratio->FindObject("stats");
    //r3->SetX1NDC(0.01);
    //r3->SetX2NDC(0.10); 
    //r3->SetY1NDC(0.20);
    //r3->SetY2NDC(0.50); 
    //gStyle->SetOptStat("mr");
    //r3->SetTextColor(kWhite);
    //r3->SetLineColor(kWhite);
    //r3->Draw();
    CanvPlot->Update();

    tmp=plotpath+plot+".png";
    CanvPlot->Print(tmp.c_str());

  }
  else if (flag==2){
    //CanvPlot.Divide(2,1);
    //CanvPlot.cd(1);

    // data
    dataf->cd("validationJEC");
    if (isMu && isAngularAnalysis) dataf->cd("validationJECmu");

    gDirectory->GetObject(plot.c_str(),data2);
    data2->Draw("COLZ");

    gPad->Update(); // altrimenti non becchi la stat
    TPaveStats *r1 = (TPaveStats*)data2->FindObject("stats");
    //r1->SetX1NDC(0.70); Uncomment if you wonna draw your stat in the top right corner
    //r1->SetX2NDC(0.85); 
    //r1->Draw();
    CanvPlot->Update();

    tmp=plotpath+plot+"data.png";
    CanvPlot->Print(tmp.c_str());


    //CanvPlot.cd(2);
    // montecarlo
    mcf->cd("validationJEC");
    if (isMu) mcf->cd("validationJECmu/");

    if (isAngularAnalysis) {
      mcf->cd("validationJEC/");
      if (isMu) mcf->cd("validationJECmu/");
    }

    gDirectory->GetObject(plot.c_str(),data2);

    data2->SetMinimum(1);
    data2->Draw("COLZ");

    gPad->Update(); // altrimenti non becchi la stat
    //TPaveStats *r2 = (TPaveStats*)data2->FindObject("stats");
    //r2->SetX1NDC(0.70);
    //r2->SetX2NDC(0.85); 
    //r2->Draw();
    CanvPlot->Update();

    tmp=plotpath+plot+"mc.png";
    CanvPlot->Print(tmp.c_str());
  }
  //	else { cout << "You're getting an exception! Most likely there's no histogram here... \n"; }

  delete data;
  delete data2;
  delete hs;
  //delete CanvPlot;

  dataf->Close();
  mcf->Close();
  ttbarf->Close();
  wf->Close();
  qcd23emf->Close();
  qcd38emf->Close();
  qcd817emf->Close();
  qcd23bcf->Close();
  qcd38bcf->Close();
  qcd817bcf->Close();
  WZf->Close();
  ZZf->Close();
  
  if (isAngularAnalysis){
    if (bckg_leadingJetPt.size()>0 && bckg_2leadingJetPt.size()>0 && bckg_3leadingJetPt.size()>0 && bckg_4leadingJetPt.size()>0  && bckg_JetMultiplicity.size()>0 && bckg_HT.size()>0 && bckg_leadingJetEta.size()>0 && bckg_PhiStar.size()>0 && cold){
      fzj->cd();
      treeBKG_->Fill();
      treeBKG_->Write();
      TH1F *leadhisto=new TH1F("leadhisto","leading jet background contribution",bckg_leadingJetPt.size(),0,bckg_leadingJetPt.size());
      TH1F *leadhisto2=new TH1F("leadhisto2","subleading jet background contribution",bckg_leadingJetPt.size(),0,bckg_leadingJetPt.size());
      TH1F *leadhisto3=new TH1F("leadhisto3","subsubleading jet background contribution",bckg_leadingJetPt.size(),0,bckg_leadingJetPt.size());
      TH1F *leadhisto4=new TH1F("leadhisto4","subsubsubleading jet background contribution",bckg_leadingJetPt.size(),0,bckg_leadingJetPt.size());
      TH1F *multiphisto=new TH1F("multiphisto","jet multiplicity background contribution",bckg_JetMultiplicity.size(),0,bckg_JetMultiplicity.size());

      TH1F *HT=new TH1F("HT","HT background contribution",bckg_HT.size(),0,bckg_HT.size());
      TH1F *HT1=new TH1F("HT1","HT background contribution when >= 1 jet",bckg_HT1.size(),0,bckg_HT1.size());
      TH1F *HT2=new TH1F("HT2","HT background contribution when >= 2 jets",bckg_HT2.size(),0,bckg_HT2.size());
      TH1F *HT3=new TH1F("HT3","HT background contribution when >= 3 jets",bckg_HT3.size(),0,bckg_HT3.size());
      TH1F *HT4=new TH1F("HT4","HT background contribution when >= 4 jets",bckg_HT4.size(),0,bckg_HT4.size());

      TH1F *leadhistoeta=new TH1F("leadhistoeta","leading jet background contribution",bckg_leadingJetEta.size(),0,bckg_leadingJetEta.size());
      TH1F *leadhistoeta2=new TH1F("leadhistoeta2","subleading jet background contribution",bckg_leadingJetEta.size(),0,bckg_leadingJetEta.size());
      TH1F *leadhistoeta3=new TH1F("leadhistoeta3","subsubleading jet background contribution",bckg_leadingJetEta.size(),0,bckg_leadingJetEta.size());
      TH1F *leadhistoeta4=new TH1F("leadhistoeta4","subsubsubleading jet background contribution",bckg_leadingJetEta.size(),0,bckg_leadingJetEta.size());

      TH1F *PhiStar=new TH1F("PhiStar","PhiStar background contribution",bckg_PhiStar.size(),0,bckg_PhiStar.size());

      for (int i=0; i< bckg_leadingJetPt.size(); i++){
	leadhisto->Fill(i,bckg_leadingJetPt[i]);
	leadhisto2->Fill(i,bckg_2leadingJetPt[i]);
	leadhisto3->Fill(i,bckg_3leadingJetPt[i]);
	leadhisto4->Fill(i,bckg_4leadingJetPt[i]);
      }
      leadhisto->Write();
      leadhisto2->Write();
      leadhisto3->Write();
      leadhisto4->Write();

      for (int i=0; i< bckg_leadingJetEta.size(); i++){
	leadhistoeta->Fill(i,bckg_leadingJetEta[i]);
	leadhistoeta2->Fill(i,bckg_2leadingJetEta[i]);
	leadhistoeta3->Fill(i,bckg_3leadingJetEta[i]);
	leadhistoeta4->Fill(i,bckg_4leadingJetEta[i]);
      }
      leadhistoeta->Write();
      leadhistoeta2->Write();
      leadhistoeta3->Write();
      leadhistoeta4->Write();
      //fzj->Close();

      for (int i=0; i< bckg_JetMultiplicity.size(); i++){
	multiphisto->Fill(i,bckg_JetMultiplicity[i]);
      }
      multiphisto->Write();
      
      ///////////////

      for (int i=0; i< bckg_HT.size(); i++){
	HT->Fill(i,bckg_HT[i]);
      }
      HT->Write();
      
      for (int i=0; i< bckg_HT1.size(); i++){
	HT1->Fill(i,bckg_HT1[i]);
      }
      HT1->Write();
      
      for (int i=0; i< bckg_HT2.size(); i++){
	HT2->Fill(i,bckg_HT2[i]);
      }
      HT2->Write();
      
      for (int i=0; i< bckg_HT3.size(); i++){
	HT3->Fill(i,bckg_HT3[i]);
      }
      HT3->Write();
      
      for (int i=0; i< bckg_HT4.size(); i++){
	HT4->Fill(i,bckg_HT4[i]);
      }
      HT4->Write();

      //Phi star
      for (int i=0; i< bckg_PhiStar.size(); i++){
	PhiStar->Fill(i,bckg_PhiStar[i]);
      }
      PhiStar->Write();

    cold=false;
    }
  }
  return;
}
void plotCutFlow(  FileList fileList , float Lumi_ = 30, 
		   float pt1_ = 20., float pt2_ = 15, float DEta_ = 1.0, float Mjj_ = 300. , float jetVeto_ = 15,
		   float signalScale_ = 1.0) {
  
  for(int i = 0; i<fileList.size(); i++){
    (fileList[i].first)->Close();
    delete (fileList[i].first);
  }

  TFile* fVBF115 = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_VBFH115.root","READ");
  TFile* fVBF135 = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_VBFH135.root","READ");
  TFile* fDYJets = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_DYJets-madgraph-50-PU.root","READ");
  TFile* fTT     = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_TT-madgraph-PU.root","READ");
  TFile* fWJets  = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_WJets-madgraph-PU.root","READ");
  TFile* fT      = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_TToBLNu-tW-madhraph-PU.root","READ");
  TFile* fQCD    = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_QCD-pythia-PU.root","READ");

  FileList fileList_;
  fileList_.push_back( make_pair(fT,      make_pair("tW",        10.6      )  ));
  fileList_.push_back( make_pair(fTT,     make_pair("ttbar",    157.5      )  ));
  fileList_.push_back( make_pair(fDYJets, make_pair("Zjets",   3048.0      )  ));
  fileList_.push_back( make_pair(fWJets,  make_pair("Wjets",  31314.0      )  ));
  fileList_.push_back( make_pair(fQCD,    make_pair("QCD",   349988.0      )  ));
  fileList_.push_back( make_pair(fVBF115, make_pair("qqH115",       0.1012 )  ));
  fileList_.push_back( make_pair(fVBF135, make_pair("qqH135",       0.05049)  ));
 

  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);


  TPad* pad1 = new TPad("pad1CutFlowMass","",0.05,0.27,0.96,0.97);
  TPad* pad2 = new TPad("pad2CutFlowMass","",0.05,0.02,0.96,0.26);
  pad1->SetFillColor(0);
  pad2->SetFillColor(0);
  pad1->Draw();
  pad2->Draw();

  pad1->cd();
  pad1->SetLogy(1);

  TLegend* leg = new TLegend(0.60,0.47,0.90,0.85,NULL,"brNDC");
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetFillColor(10);
  leg->SetTextSize(0.04);
  leg->SetHeader( "Cut Flow" );
  
  THStack* aStack = new THStack("aStack",Form("CMS Preliminary 2010    #sqrt{s}=7 TeV L=%.0f pb^{-1}",Lumi_));
  TH1F* hqqH115 = new TH1F();
  TH1F* hqqH135 = new TH1F();
  TH1F* hSiml   = new TH1F();

  vector< pair<string,string> > cutList;
  cutList.push_back(make_pair("vertexScarpingFilter/totalEvents","good vertex"));
  cutList.push_back(make_pair("oneMuonFilter/totalEvents","one muon"));
  cutList.push_back(make_pair("noElecFilter/totalEvents","electron veto"));
  cutList.push_back(make_pair("muonLegFilter/totalEvents","#mu cuts"));
  cutList.push_back(make_pair("tauLegFilter/totalEvents","#tau cuts"));
  cutList.push_back(make_pair("atLeastOneDiTauFilter/totalEvents","OS + m_{T} cut"));
  vector<float> cutFlow; 

  float signalScale = 1;

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

    signalScale = 1;

    TFile* currentFile = (TFile*)fileList_[i].first ;
    if( currentFile->IsZombie() ) continue;
    TH1F* allEvents = (TH1F*)currentFile->Get("allEventsFilter/totalEvents");
    float totalEvents = allEvents->GetBinContent(1);

    cutFlow.clear();
    for(int m = 0; m<cutList.size(); m++){
      TH1F* tmph1 =  (TH1F*)currentFile->Get( (cutList[m].first).c_str() );
      if(tmph1!=0){
	cutFlow.push_back( tmph1->GetBinContent(1) );
	//cout << cutList[m].first << " ===> " << tmph1->GetBinContent(1) << endl;
      }
    }

    TTree* currentTree = (TTree*)currentFile->Get("muTauStreamAnalyzer/tree");
    string h1Name = "h1_"+(fileList_[i].second).first;
    TH1F* h1 = new TH1F( h1Name.c_str() ,"", (int)(cutFlow.size()+3) ,0 , cutFlow.size()+3);

    if( ((fileList_[i].second).first).find("Zjets")!=string::npos ) {
      h1->SetFillColor(kRed);
      leg->AddEntry(h1,"MadGraph Z+jets","F");
    }
    if( ((fileList_[i].second).first).find("ttbar")!=string::npos ) {
      h1->SetFillColor(kBlue);
      leg->AddEntry(h1,"MadGraph t#bar{t}+jets","F");
    }
    if( ((fileList_[i].second).first).find("Wjets")!=string::npos ) {
      h1->SetFillColor(kGreen);
      leg->AddEntry(h1,"MadGraph W+jets","F");
    }
    if( ((fileList_[i].second).first).find("tW")!=string::npos ){
      h1->SetFillColor( 44 );
      leg->AddEntry(h1,"MadGraph single-top","F");
    }
    if( ((fileList_[i].second).first).find("QCD")!=string::npos ) {
      h1->SetFillColor(11);
      leg->AddEntry(h1,"Pythia QCD","F");
    }
    if( ((fileList_[i].second).first).find("qqH115")!=string::npos ) {
      h1->SetLineColor(kBlack);
      h1->SetLineStyle(kDashed);
      h1->SetLineWidth(3.0);
      signalScale = signalScale_;
      leg->AddEntry(h1,Form("VBF H(115)#rightarrow#tau#tau X %.0f",signalScale),"l");
    }
    if( ((fileList_[i].second).first).find("qqH135")!=string::npos ) {
      h1->SetLineColor(kBlack);
      h1->SetLineStyle(kDotted);
      h1->SetLineWidth(3.0);
      signalScale = signalScale_;
      leg->AddEntry(h1,Form("VBF H(135)#rightarrow#tau#tau X %.0f",signalScale),"l");
    }

    h1->SetBinContent(1,totalEvents);
    h1->GetXaxis()->SetBinLabel(1,"#sigma*BR*#int L");  
    for(int m = 0; m<cutFlow.size(); m++){
      h1->SetBinContent(m+2,cutFlow[m]);
      h1->GetXaxis()->SetBinLabel(m+2, (cutList[m].second).c_str() ); 
    }
    h1->GetXaxis()->SetBinLabel(cutFlow.size()+2,"VBF 1%");
    h1->GetXaxis()->SetBinLabel(cutFlow.size()+3,"CJV (15 GeV)");
   
    int nEntries = currentTree->GetEntries() ;    
    
    std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* diTauSVfit3;
    std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* jets;
    
    currentTree->SetBranchAddress("diTauSVfit3P4",&diTauSVfit3);
    currentTree->SetBranchAddress("jetsIDP4",&jets);
    
    for (int n = 0; n < nEntries ; n++) {
      
      currentTree->GetEntry(n);
   

      if( diTauSVfit3->size() < 1) continue;
      bool vbfCut = false;
      bool jetVeto = false;
      if( jets->size()>1 && 
	  (*jets)[0].Et()>pt1_ && (*jets)[1].Et()>pt2_ && 
	  abs((*jets)[0].Eta()-(*jets)[1].Eta())>DEta_ && 
	  ((*jets)[0]+(*jets)[1]).M()>Mjj_ ) vbfCut = true;
      for(unsigned k=0; k < jets->size(); k++){
	if(k>1 && 
	   (  ((*jets)[k].Eta()>(*jets)[1].Eta()+0.5 &&  (*jets)[k].Eta()<(*jets)[0].Eta()-0.5) || 
	      ((*jets)[k].Eta()>(*jets)[0].Eta()+0.5 &&  (*jets)[k].Eta()<(*jets)[1].Eta()-0.5) ) &&
	   (*jets)[k].Et()>jetVeto_ ) jetVeto=true;  
      }
      
      if(vbfCut)  h1->Fill( cutFlow.size()+1.5 ) ;      
      if(vbfCut && !jetVeto)  h1->Fill( cutFlow.size()+2.5 ) ;      
    
    }
   

    h1->Scale( Lumi_ / (totalEvents/((fileList_[i].second).second * signalScale)) );

    if(((fileList_[i].second).first).find("qqH115")!=string::npos){
      hqqH115=(TH1F*)h1->Clone("hqqH115");
      hqqH115 = h1;
      hqqH115->Sumw2();
      continue;
    }
    if(((fileList_[i].second).first).find("qqH135")!=string::npos){
      hqqH135=(TH1F*)h1->Clone("hqqH135");
      hqqH135 = h1;
      hqqH135->Sumw2();
      continue;
    }

    if(i==0) hSiml=(TH1F*)h1->Clone("hSiml");
    else hSiml->Add(h1);

    aStack->Add(h1);

  }

  //float numData = hData->GetEntries();
  //float numSiml = hSiml->Integral();
  //float dataToSimlRatio = numData/numSiml;
  //cout << "data " << numData << "  ---  simul " << numSiml << endl;  

  aStack->Draw("HIST");
  hqqH115->Draw("HISTSAME");
  hqqH135->Draw("HISTSAME");
  TH1F* hStack = (TH1F*)aStack->GetHistogram();
  hStack->SetXTitle("");
  hStack->SetYTitle("Number of events");
  hStack->SetTitleSize(0.05,"X");
  hStack->SetTitleSize(0.05,"Y");
  hStack->SetTitleOffset(0.75,"Y");
  hStack->SetAxisRange(1,hSiml->GetMaximum()*1.1,"Y");

  leg->Draw();

  pad2->cd();
  TH1F* hRatio = new TH1F("hRatio", " ; ; purity",
			  hStack->GetNbinsX(), 
			  hStack->GetXaxis()->GetXmin(), hStack->GetXaxis()->GetXmax());
  hRatio->SetLineStyle(kDashed);
  hRatio->SetLineWidth(1.0);
  hRatio->SetLabelSize(0.12,"X");
  hRatio->SetLabelSize(0.10,"Y");
  hRatio->SetTitleSize(0.12,"Y");
  hRatio->SetTitleOffset(0.36,"Y");
  TH1F* hqqH115Clone = (TH1F*)hqqH115->Clone("hqqH115Clone");
  TH1F* hqqH135Clone = (TH1F*)hqqH135->Clone("hqqH135Clone");
  hqqH115Clone->Divide( hqqH115 ,hSiml,1./signalScale,1.0);
  hqqH135Clone->Divide( hqqH135 ,hSiml,1./signalScale,1.0);
  hRatio->SetAxisRange(0.,0.01,"Y");

  hRatio->Draw();
  hqqH115Clone->Draw("HISTSAME");
  hqqH135Clone->Draw("HISTSAME");

  if(SAVE) c1->SaveAs("Zmm_CutFlowMass.png");

}
void plotInclusiveMass(  FileList fileList  , float Lumi_ = 30) {

  for(int i = 0; i<fileList.size(); i++){
    (fileList[i].first)->Close();
    delete (fileList[i].first);
  }

  TFile* fVBF115 = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_VBFH115.root","READ");
  TFile* fVBF135 = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_VBFH135.root","READ");
  TFile* fDYJets = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_DYJets-madgraph-50-PU.root","READ");
  TFile* fTT     = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_TT-madgraph-PU.root","READ");
  TFile* fWJets  = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_WJets-madgraph-PU.root","READ");
  TFile* fT      = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_TToBLNu-tW-madhraph-PU.root","READ");
  TFile* fQCD    = new TFile("/data_CMS/cms/lbianchini/MuTauStream/treeMuTauStream_QCD-pythia-PU.root","READ");

  FileList fileList_;
  fileList_.push_back( make_pair(fT,      make_pair("tW",        10.6      )  ));
  fileList_.push_back( make_pair(fQCD,    make_pair("QCD",   349988.0      )  ));
  fileList_.push_back( make_pair(fWJets,  make_pair("Wjets",  31314.0      )  ));
  fileList_.push_back( make_pair(fTT,     make_pair("ttbar",    157.5      )  ));
  fileList_.push_back( make_pair(fDYJets, make_pair("Zjets",   3048.0      )  ));
  fileList_.push_back( make_pair(fVBF115, make_pair("qqH115",       0.1012 )  ));
  fileList_.push_back( make_pair(fVBF135, make_pair("qqH135",       0.05049)  ));
 

  TCanvas *c1 = new TCanvas("c1InclusiveMass","",5,30,650,600);
  c1->SetGrid(0,0);
  c1->SetFillStyle(4000);
  c1->SetFillColor(10);
  c1->SetTicky();
  c1->SetObjectStat(0);
  c1->SetLogy(1);


  TPad* pad1 = new TPad("pad1InclusiveMass","",0.05,0.27,0.96,0.97);
  TPad* pad2 = new TPad("pad2InclusiveMass","",0.05,0.02,0.96,0.26);
  pad1->SetFillColor(0);
  pad2->SetFillColor(0);
  pad1->Draw();
  pad2->Draw();

  pad1->cd();
  pad1->SetLogy(1);

  TLegend* leg = new TLegend(0.60,0.47,0.90,0.85,NULL,"brNDC");
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetFillColor(10);
  leg->SetTextSize(0.04);
  leg->SetHeader( "#mu+#tau Inclusive" );
  
  THStack* aStack = new THStack("aStack",Form("CMS Preliminary 2010    #sqrt{s}=7 TeV L=%.0f pb^{-1}",Lumi_));
  TH1F* hqqH115 = new TH1F();
  TH1F* hqqH135 = new TH1F();
  TH1F* hSiml   = new TH1F();

  float signalScale = 1;

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

    TFile* currentFile = (TFile*)fileList_[i].first ;
    if( currentFile->IsZombie() ) continue;
    TH1F* allEvents = (TH1F*)currentFile->Get("allEventsFilter/totalEvents");
    float totalEvents = allEvents->GetBinContent(1);

    TTree* currentTree = (TTree*)currentFile->Get("muTauStreamAnalyzer/tree");
    string h1Name = "h1_"+(fileList_[i].second).first;
    TH1F* h1 = new TH1F( h1Name.c_str() ,"", 28 , 20, 300);

    if( ((fileList_[i].second).first).find("Zjets")!=string::npos ) {
      h1->SetFillColor(kRed);
      leg->AddEntry(h1,"MadGraph Z+jets","F");
    }
    if( ((fileList_[i].second).first).find("ttbar")!=string::npos ) {
      h1->SetFillColor(kBlue);
      leg->AddEntry(h1,"MadGraph t#bar{t}+jets","F");
    }
    if( ((fileList_[i].second).first).find("Wjets")!=string::npos ) {
      h1->SetFillColor(kGreen);
      leg->AddEntry(h1,"MadGraph W+jets","F");
    }
    if( ((fileList_[i].second).first).find("tW")!=string::npos ){
      h1->SetFillColor( 44 );
      leg->AddEntry(h1,"MadGraph single-top","F");
    }
    if( ((fileList_[i].second).first).find("QCD")!=string::npos ) {
      h1->SetFillColor(11);
      leg->AddEntry(h1,"Pythia QCD","F");
    }
    if( ((fileList_[i].second).first).find("qqH115")!=string::npos ) {
      h1->SetLineColor(kBlack);
      h1->SetLineStyle(kDashed);
      h1->SetLineWidth(3.0);
      leg->AddEntry(h1,"VBF H(115)#rightarrow#tau#tau X 100","l");
      signalScale = 100;
    }
    if( ((fileList_[i].second).first).find("qqH135")!=string::npos ) {
      h1->SetLineColor(kBlack);
      h1->SetLineStyle(kDotted);
      h1->SetLineWidth(3.0);
      leg->AddEntry(h1,"VBF H(135)#rightarrow#tau#tau X 100","l");
      signalScale = 100;
    }

    int nEntries = currentTree->GetEntries() ;
    
    std::vector<ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > >* diTauSVfit3;
    currentTree->SetBranchAddress("diTauSVfit3P4",&diTauSVfit3);

    for (int n = 0; n < nEntries ; n++) {
      currentTree->GetEntry(n);
      if( diTauSVfit3->size() < 1) continue;
      h1->Fill( (*diTauSVfit3)[0].M() ) ;
    }

    h1->Scale( Lumi_ / (totalEvents/((fileList_[i].second).second * signalScale)) );

    if(((fileList_[i].second).first).find("qqH115")!=string::npos){
      hqqH115=(TH1F*)h1->Clone("hqqH115");
      hqqH115 = h1;
      hqqH115->Sumw2();
      continue;
    }
    if(((fileList_[i].second).first).find("qqH135")!=string::npos){
      hqqH135=(TH1F*)h1->Clone("hqqH135");
      hqqH135 = h1;
      hqqH135->Sumw2();
      continue;
    }

    if(i==0) hSiml=(TH1F*)h1->Clone("hSiml");
    else hSiml->Add(h1);

    aStack->Add(h1);

  }

  //float numData = hData->GetEntries();
  //float numSiml = hSiml->Integral();
  //float dataToSimlRatio = numData/numSiml;
  //cout << "data " << numData << "  ---  simul " << numSiml << endl;  

  aStack->Draw("HIST");
  hqqH115->Draw("HISTSAME");
  hqqH135->Draw("HISTSAME");
  TH1F* hStack = (TH1F*)aStack->GetHistogram();
  hStack->SetXTitle("SVfit #tau#tau mass");
  hStack->SetYTitle(Form("Number of events/%.0f GeV",hStack->GetBinWidth(1)));
  hStack->SetTitleSize(0.05,"X");
  hStack->SetTitleSize(0.05,"Y");
  hStack->SetTitleOffset(0.75,"Y");
  leg->Draw();

  pad2->cd();
  TH1F* hRatio = new TH1F("hRatio", " ; ; purity",
			  hStack->GetNbinsX(), 
			  hStack->GetXaxis()->GetXmin(), hStack->GetXaxis()->GetXmax());
  hRatio->SetLineStyle(kDashed);
  hRatio->SetLineWidth(1.0);
  hRatio->SetLabelSize(0.12,"X");
  hRatio->SetLabelSize(0.10,"Y");
  hRatio->SetTitleSize(0.12,"Y");
  hRatio->SetTitleOffset(0.36,"Y");
  TH1F* hqqH115Clone = (TH1F*)hqqH115->Clone("hqqH115Clone");
  TH1F* hqqH135Clone = (TH1F*)hqqH135->Clone("hqqH135Clone");
  hqqH115Clone->Divide( hqqH115 ,hSiml,1./signalScale,1.0);
  hqqH135Clone->Divide( hqqH135 ,hSiml,1./signalScale,1.0);
  hRatio->SetAxisRange(0.,0.001,"Y");

  hRatio->Draw();
  hqqH115Clone->Draw("HISTSAME");
  hqqH135Clone->Draw("HISTSAME");

  if(SAVE) c1->SaveAs("Zmm_InclusiveMass.png");

}
示例#7
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");
}
示例#8
0
        void Draw(const int &rebin=1) {

	  Color_t _sampleColor[nSamples];
            //_sampleColor[iHWW  ] = kRed+1;
            //_sampleColor[iWW   ] = kAzure-9;
            //_sampleColor[iZJets] = kGreen+2;
            //_sampleColor[iZTau]  = kGreen+2;
            //_sampleColor[iTop  ] = kYellow;
            //_sampleColor[iWZ   ] = kAzure-2;
            //_sampleColor[iWJets] = kGray+1;
            //_sampleColor[iWJets] = kViolet-9;
            //_sampleColor[iWJets] = kCyan;

	    _sampleColor[itH   ] = kRed;
            _sampleColor[iWZ   ] = kAzure-9;
            _sampleColor[iZZ   ] = kAzure-5;
            _sampleColor[iWW   ] = kAzure-1;
            _sampleColor[itt   ] = kGray;
            _sampleColor[ittw  ] = kOrange+7;
            _sampleColor[ittz  ] = kOrange+1;
            _sampleColor[iwww  ] = kSpring+9;
            _sampleColor[iwwz  ] = kSpring+3;
            _sampleColor[iwzz  ] = kSpring-7;
            _sampleColor[idyl  ] = kViolet-1;
            _sampleColor[idy   ] = kViolet-1;
	    
            //setUpStyle();
            if(!gPad) new TCanvas();

            THStack* hstack = new THStack();
            for (int i=0; i<nSamples; i++) {

                // in case the user doesn't set it
                if( !_hist[i] ) continue;

                _hist[i]->Rebin(rebin);
                _hist[i]->SetLineColor(_sampleColor[i]);

                // signal gets overlaid
                if (i == itH) continue;

                _hist[i]->SetFillColor(_sampleColor[i]);
                _hist[i]->SetFillStyle(1001);

                hstack->Add(_hist[i]);
            }

            if(_hist[itH]) _hist[itH]->SetLineWidth(3);
            if(_data) _data->Rebin(rebin);
            if(_data) _data->SetLineColor  (kBlack);
            if(_data) _data->SetMarkerStyle(kFullCircle);

            if(_nostack) {
              for(int ihist=0;ihist<(int)_hist.size();ihist++) {
                _hist[ihist]->SetFillStyle(0);
                _hist[ihist]->SetLineWidth(2);
              }
              hstack->Draw("hist,nostack");
              if(_hist[itH]) _hist[itH]->Draw("hist,same");
              if(_data) _data->Draw("ep,same");
            } else {
              hstack->Draw("hist");
              if(_hist[itH]) _hist[itH]->Draw("hist,same");
              if(_data) _data->Draw("ep,same");
            }
            //hstack->SetTitle("CMS preliminary");

            Float_t theMax = hstack->GetMaximum();
            Float_t theMin = hstack->GetMinimum();

	    theMax = 1.0;
            //Float_t theMin = hstack->GetMinimum();

            if (_hist[itH]) {
                if (_hist[itH]->GetMaximum() > theMax) theMax = _hist[itH]->GetMaximum();
                if (_hist[itH]->GetMinimum() < theMin) theMin = _hist[itH]->GetMinimum();
            }

            if (_data) {

                Float_t dataMax = GetMaximumIncludingErrors(_data);

                if (dataMax > theMax) theMax = dataMax;
            }

            if (gPad->GetLogy()) {
                hstack->SetMaximum(500 * theMax);
                hstack->SetMinimum(0.05);
            } else {
                hstack->SetMaximum(1.55 * theMax);
            }

            if(_breakdown) {
                THStackAxisFonts(hstack, "y", "entries");
                hstack->GetHistogram()->LabelsOption("v");
            } else {
                THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
                if(_units.Sizeof() == 1) {
                    THStackAxisFonts(hstack, "x", _xLabel.Data());
                    THStackAxisFonts(hstack, "y", "entries");
                } else {
                    THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
                    THStackAxisFonts(hstack, "y", TString::Format("entries / %.0f %s", _hist[iWZ]->GetBinWidth(0),_units.Data()));
                }
            }

            // total mess to get it nice, should be redone
            size_t j=0;
            TString higgsLabel = " tH x 100";
            //if(_mass != 0) higgsLabel.Form(" m_{H}=%d",_mass);

	    
            if(_data        ) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _data,         " data",    "lp"); j++; }
            if(_hist[itH   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[itH   ], higgsLabel, "l" ); j++; }
            if(_hist[iWZ   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iWZ   ], " WZ",      "f" ); j++; }
            if(_hist[iZZ   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iZZ   ], " ZZ",      "f" ); j++; }
            if(_hist[iWW   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iWW   ], " WW",      "f" ); j++; }
            if(_hist[itt   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[itt   ], " tt",      "f" ); j++; }
            if(_hist[ittw  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[ittw  ], " ttW",     "f" ); j++; }
            if(_hist[ittz  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[ittz  ], " ttZ",     "f" ); j++; }
            if(_hist[iwww  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwww  ], " WWW",     "f" ); j++; }
            if(_hist[iwwz  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwwz  ], " WWZ",     "f" ); j++; }
            if(_hist[iwzz  ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwzz  ], " WZZ",     "f" ); j++; }
            if(_hist[idy   ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[idy   ], " Drell-Yan","f" ); j++; }
	    

            //TLatex* luminosity = new TLatex(0.9, 0.815, TString::Format("L = %.1f fb^{-1}",_lumi));
            TLatex* luminosity = new TLatex(0.9, 0.95, TString::Format("CMS Preliminary \\sqrt{s} = 8 TeV, L = %.1f fb^{-1}",_lumi));
            luminosity->SetNDC();
            luminosity->SetTextAlign(32);
            luminosity->SetTextFont(42);
            luminosity->SetTextSize(_tsize);
            luminosity->Draw("same");
            // if(_extraLabel) _extraLabel->Draw("same");
            // return hstack->GetHistogram();
        }
//------------------------------------------------------------------------------
// PlotHiggsRes_LP
//------------------------------------------------------------------------------
void RunMakeRazorPlots ( string signalfile, string signalLabel,  vector<string> bkgfiles,vector<string> bkgLabels, int boxOption = 0, int option = -1, string label = "", string latexlabel = "") {

  //--------------------------------------------------------------------------------------------------------------
  // Settings 
  //============================================================================================================== 
  double intLumi = 2100; //in units of pb^-1
  string Label = "";
  if (label != "") Label = "_" + label;

  vector<string> inputfiles;
  vector<string> processLabels;

  bool hasSignal = false;
  if (signalfile != "") {
    hasSignal = true;
    inputfiles.push_back(signalfile);
    processLabels.push_back(signalLabel);
  }
  assert(bkgfiles.size() == bkgLabels.size());
  for (int i=0; i < bkgfiles.size(); ++i) {
     inputfiles.push_back(bkgfiles[i]);
     processLabels.push_back(bkgLabels[i]);
  }

  //*******************************************************************************************
  //Define Histograms
  //*******************************************************************************************
  vector<TH1F*> histUnrolled; 
  float MRBinLowEdges[] = {500, 600, 700, 900, 1200, 1600, 2500, 4000}; // Multijet Bins
  float RsqBinLowEdges[] = {0.25, 0.30, 0.41, 0.52, 0.64, 1.5}; // Multijet Bins

  const int nMRBins = 7;
  const int nRsqBins = 5;

  TH1F* histMRAllBkg =  new TH1F( "MRAllBkg",";M_{R} [GeV/c^{2}];Number of Events", nMRBins, MRBinLowEdges);
  TH1F* histRsqAllBkg =  new TH1F( "RsqAllBkg", ";R^{2};Number of Events", nRsqBins, RsqBinLowEdges);
  histMRAllBkg->SetStats(false);
  histRsqAllBkg->SetStats(false);  
  histRsqAllBkg->Sumw2();
  histMRAllBkg->Sumw2();

  TH1F* histMRQCD =  new TH1F( "MRQCD",";M_{R} [GeV/c^{2}];Number of Events", nMRBins, MRBinLowEdges);
  TH1F* histRsqQCD =  new TH1F( "RsqQCD", ";R^{2};Number of Events", nRsqBins, RsqBinLowEdges);
  histMRQCD->SetStats(false);
  histRsqQCD->SetStats(false);  
  histRsqQCD->Sumw2();
  histMRQCD->Sumw2();

  TH1F* histMRData =  new TH1F( "MRData",";M_{R} [GeV/c^{2}];Number of Events", nMRBins, MRBinLowEdges);
  TH1F* histRsqData =  new TH1F( "RsqData", ";R^{2};Number of Events", nRsqBins, RsqBinLowEdges);

  vector<TH1F*> histMR;
  vector<TH1F*> histRsq; 
  vector<TH2F*> histMRRsq;

  histMRQCD->SetFillColor(kAzure+4);
  histMRAllBkg->SetFillColor(kMagenta);
  histMRQCD->SetFillStyle(1001);
  histMRAllBkg->SetFillStyle(1001);

  histMRQCD->SetLineColor(kAzure+4);
  histMRAllBkg->SetLineColor(kMagenta);

  assert (inputfiles.size() == processLabels.size());
  for (int i=0; i < inputfiles.size(); ++i) {    
    histMRRsq.push_back( new TH2F( Form("MRRsq_%s",processLabels[i].c_str()), ";M_{R} [GeV/c^{2}]; R^{2}", nMRBins, MRBinLowEdges, nRsqBins, RsqBinLowEdges));
    if (!hasSignal || i != 0) histMRRsq[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histMRRsq[i]->SetLineWidth(3);
    histMRRsq[i]->SetLineColor(color[i]);
    histMRRsq[i]->SetStats(false);
    histMRRsq[i]->Sumw2();

    histUnrolled.push_back( new TH1F( Form("Unrolled_%s",processLabels[i].c_str()), ";Bin Number ;Number of Events", nMRBins*nRsqBins, 0, nMRBins*nRsqBins));
    if (!hasSignal || i != 0) histUnrolled[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histUnrolled[i]->SetLineWidth(3);
    histUnrolled[i]->SetLineColor(color[i]);
    histUnrolled[i]->SetStats(false);     
  }
  THStack *stackUnrolled = new THStack();

  //*******************************************************************************************
  //Define Counts
  //*******************************************************************************************


  //*******************************************************************************************
  //Read files
  //*******************************************************************************************
  for (uint i=0; i < inputfiles.size(); ++i) {

    TFile* inputFile = new TFile(inputfiles[i].c_str(),"READ");
    assert(inputFile);
    TTree* tree = 0;
    tree = (TTree*)inputFile->Get("RazorInclusive");
  // if (box == 0) {
    //   tree = (TTree*)inputFile->Get("MultiJet");
    // } else if (box == 1) {
    //   tree = (TTree*)inputFile->Get("LooseLeptonMultiJet");
    // } else if (box == 2) {
    //   tree = (TTree*)inputFile->Get("MuMultiJet");
    // } else if (box == 3) {
    //   tree = (TTree*)inputFile->Get("EleMultiJet");
    // }
 
    float weight = 0;
    int box = -1;
    int nBTaggedJets = 0;
    float dPhiRazor = 0;
    float MR = 0;
    float Rsq = 0;
    float mT = 0;

    tree->SetBranchAddress("weight",&weight);
    tree->SetBranchAddress("box",&box);
    tree->SetBranchAddress("nBTaggedJets",&nBTaggedJets);
    tree->SetBranchAddress("dPhiRazor",&dPhiRazor);
    tree->SetBranchAddress("MR",&MR);
    tree->SetBranchAddress("Rsq",&Rsq);
    tree->SetBranchAddress("mT",&mT);

    cout << "Process : " << processLabels[i] << " : Total Events: " << tree->GetEntries() << "\n";
    for (int n=0;n<tree->GetEntries();n++) { 
     // for (int n=0;n<1000;n++) { 
   
      tree->GetEntry(n);
      if (n % 1000000 == 0) cout << "Processing Event " << n << "\n";       


      // if (intLumi*weight > 100) continue;

      //Box Options
      if (option == 0 ) {
	if (nBTaggedJets != 0) continue;
      }
      if (option == 1 ) {
	if (nBTaggedJets != 1) continue;
      }
      if (option == 2 ) {
	if (nBTaggedJets != 2) continue;
      }
      if (option == 3 ) {
	if (nBTaggedJets < 3) continue;
      }
      if (option == 4 ) {
	if (nBTaggedJets < 0) continue; // all b-tag categories combined
      }

      if (boxOption == 0) { // Multijet Box for Jamboree
	if( !(box == 11 || box == 12) ) continue;
      } 
      if (boxOption == 1) { // LeptonJet Box for Jamboree
	if( !(box == 3 || box == 4 || box == 6 || box == 7) ) continue;
      } 
      if (boxOption == 2) { // Multijet Box for Jamboree
	if( !(box == 14) ) continue;
      } 

      //apply baseline cuts
      if (!(MR > 400 && Rsq > 0.25)) continue;

      // if (!(MR < 500 )) continue;
      // if (!(Rsq < 0.3)) continue;

      if (!(fabs(dPhiRazor) > 2.8)) continue;

      if (!hasSignal || i>1) {
	histMRAllBkg->Fill(MR, intLumi*weight);
	histRsqAllBkg->Fill(Rsq, intLumi*weight);
	histMRRsq[i]->Fill(MR, Rsq, intLumi*weight);
      }

      if(i==1){
	if (intLumi*weight > 30) continue;
	float qcdweight = 1.56841;
	histMRQCD->Fill(MR, intLumi*weight*qcdweight);
	histRsqQCD->Fill(Rsq, intLumi*weight*qcdweight);	
  	histMRRsq[i]->Fill(MR, Rsq, intLumi*weight*qcdweight);
    }

      if (hasSignal && i==0) {
	histMRData->Fill(MR);
	histRsqData->Fill(Rsq);	
	histMRRsq[i]->Fill(MR, Rsq);
      }
    }

    inputFile->Close();
    delete inputFile;
  
  }
  
  std::cout<<"Data: "<<histMRData->Integral()<<", All Backgrounds: "<<histMRAllBkg->Integral()<<" , QCD: "<<histMRQCD->Integral()<<", Data2 "<< histMRRsq[0]->Integral() <<" QCD2 "<<histMRRsq[1]->Integral() <<std::endl;


  //*******************************************************************************************
  //Draw Plots
  //*******************************************************************************************
 // fill out the unrolled histograms 
  std::cout<<"Rsq bins: "<<nRsqBins<<" "<<nMRBins<<std::endl;
  for (uint i=0; i < histMRRsq.size(); ++i) {
    
    int binN = 0;

    for(int ii = 0; ii<nMRBins; ii++)
      for (int jj = 0; jj<nRsqBins; jj++)      
  	{      
  	  float value = (histMRRsq[i]->GetBinContent(ii+1, jj+1) > 0) ? histMRRsq[i]->GetBinContent(ii+1, jj+1) : 0. ;
	  
	  float Xrange = histMRRsq[i]->GetXaxis()->GetBinLowEdge(jj+2) - histMRRsq[i]->GetXaxis()->GetBinLowEdge(jj+1);
	  float Yrange = histMRRsq[i]->GetYaxis()->GetBinLowEdge(ii+2) - histMRRsq[i]->GetYaxis()->GetBinLowEdge(ii+1);

	  float area =1.;
	  
	  if(density) area = Xrange*Yrange; //normalize each bin by its area

	  histUnrolled[i]->SetBinContent(binN+1, value/area);
  	  binN++;
  	}

    histUnrolled[i]->SetMinimum(0.00001);

    if ( histUnrolled[i]->Integral() > 0) {
      if( !hasSignal || i > 0 )
	stackUnrolled->Add(histUnrolled[i]);
    }

    cout << "Process : " << processLabels[i] << "\n";	  
  }

  TCanvas *cv = 0;
  TLegend *legend = 0;
  TLatex *tex = 0;
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.7,0.53,0.90,0.88);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);

  for (Int_t i = histMRRsq.size()-1 ; i >= 0; --i) {
    if (hasSignal && i==0) {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "L");
    } else {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "F");
    }
  }

  /// Unrolled plots in bins of R&MR
  TLatex t1(0.1,0.92, "CMS Preliminary");
  TLatex t2(0.6,0.92, "#sqrt{s}=13 TeV, L = 2.1 fb^{-1}");
  TLatex t3(0.4,0.92, Form("%s",latexlabel.c_str()) );
  t1.SetNDC();
  t2.SetNDC();
  t3.SetNDC();
  t1.SetTextSize(0.05);
  t2.SetTextSize(0.05);
  t3.SetTextSize(0.02);
  t1.SetTextFont(42);
  t2.SetTextFont(42);
  t3.SetTextFont(42);
  stackUnrolled->Draw();
  stackUnrolled->SetMinimum(0.01);
  stackUnrolled->SetMaximum(1000);
  cv->SetLogy();
  stackUnrolled->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackUnrolled->GetHists()->At(0)))->GetXaxis()->GetTitle());
  stackUnrolled->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackUnrolled->GetHists()->At(0)))->GetYaxis()->GetTitle());
  stackUnrolled->Draw();
  if(hasSignal) histUnrolled[0]->Draw("same PE");
  legend->Draw();
  t1.Draw();
  t2.Draw();
  t3.Draw();
  cv->SaveAs(Form("Unrolled_QCD%s.root",Label.c_str()));
  ////

  //*******************************************************************************************
  //MR
  //*******************************************************************************************
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.50,0.54,0.90,0.84);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);

  tex = new TLatex();
  tex->SetNDC();
  tex->SetTextSize(0.030);
  tex->SetTextFont(42);
  tex->SetTextColor(kBlack);
  tex->DrawLatex(0.2, 0.92, Form("CMS Simulation #sqrt{s} = 13 TeV, #int L = %d fb^{-1}, %s",int(intLumi/1000), latexlabel.c_str()));

  THStack *stackMR = new THStack("stackMR", "");
  THStack *stackRsq = new THStack();

  //*******************************************************************************************
  //MR Before and After DPhi Cut
  //*******************************************************************************************
  //////////////////
  stackMR->Add(histMRAllBkg);
  stackMR->Add(histMRQCD);
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.50,0.54,0.90,0.84);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);
  stackMR->Draw();
  stackMR->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackMR->GetHists()->At(0)))->GetXaxis()->GetTitle());
  stackMR->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackMR->GetHists()->At(0)))->GetYaxis()->GetTitle());
  stackMR->Draw("");
  histMRData->Draw("same PE");
  legend->Draw();
  cv->SetLogy();
  cv->SaveAs(Form("MRStack_QCD_%s.pdf",Label.c_str()));

  ///////////////////////
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.50,0.54,0.90,0.84);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);

  histMRAllBkg->SetLineColor(kRed);
  histMRAllBkg->GetYaxis()->SetTitle("Number of Events");
  histMRAllBkg->GetYaxis()->SetTitleOffset(1.2);
  histMRData->SetMarkerStyle(8);

  legend->AddEntry(histMRAllBkg, "All Backgrounds", "L");
  legend->AddEntry(histMRData, "Data", "L");

  histMRAllBkg->Add(histMRQCD, 1.0);

  histMRAllBkg->Draw("hist");
  histMRData->Draw("PE same");

  legend->Draw();
  cv->SetLogy();
  cv->SaveAs(Form("MR_QCD_%s.pdf",Label.c_str()));


  //////

  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.50,0.54,0.90,0.84);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);

  histRsqAllBkg->SetLineColor(kRed);
  histRsqAllBkg->GetYaxis()->SetTitle("Number of Events");
  histRsqAllBkg->GetYaxis()->SetTitleOffset(1.2);
  histRsqData->SetMarkerStyle(8);

  legend->AddEntry(histRsqAllBkg, "All Backgrounds", "L");
  legend->AddEntry(histRsqData, "Data", "L");

  histRsqAllBkg->Add(histRsqQCD, 1.0);

  histRsqAllBkg->Draw("hist");
  histRsqData->Draw("PE same");

  legend->Draw();
  cv->SetLogy();
  cv->SaveAs(Form("Rsq_QCD_%s.pdf",Label.c_str()));

  //////////////////
  histRsqQCD->SetFillColor(kAzure+4);
  histRsqAllBkg->SetFillColor(kMagenta);

  stackRsq->Add(histRsqAllBkg);
  stackRsq->Add(histRsqQCD);
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.50,0.54,0.90,0.84);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);
  stackRsq->Draw();
  stackRsq->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackRsq->GetHists()->At(0)))->GetXaxis()->GetTitle());
  stackRsq->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackRsq->GetHists()->At(0)))->GetYaxis()->GetTitle());
  stackRsq->Draw();
  histRsqData->Draw("same PE");
  legend->Draw();
  cv->SetLogy();
  cv->SaveAs(Form("RsqStack_QCD_%s.pdf",Label.c_str()));
 
   //--------------------------------------------------------------------------------------------------------------
  // Output
  //==============================================================================================================
  TFile *file = TFile::Open(("RazorPlots"+Label+".root").c_str(), "RECREATE");
  file->cd();

  for(int i=0; i<int(inputfiles.size()); i++) {
    file->WriteTObject(histMRRsq[i], Form("histMRRsq_%s",processLabels[i].c_str()), "WriteDelete");
    histUnrolled[i]->Write();  
  }
  
  stackUnrolled->Write();
 }
示例#10
0
void plotMuTau( Int_t mH_ = 120,
		string selection_ = "inclusive",
		string analysis_  = "",		  
		TString variable_ = "diTauVisMass",
		TString XTitle_ = "full mass",
		TString Unities_ = "GeV",
		Int_t nBins_ = 100, Float_t xMin_=0, Float_t xMax_=400,
		Float_t magnifySgn_ = 1.0,
		Float_t hltEff_ = 0.9967*0.997*0.968, // muID*muIso*muHLT
		Int_t logy_ = 0 ) 
{   

  // input txt file with bins
  ifstream is;

  char* c = new char[10];
  is.open(Form("bins/bins_muTau_mH%d_%s_%s.txt",mH_,selection_.c_str(),variable_.Data())); 
  if(nBins_<0 &&  !is.good()){
    cout << "Bins file not found" << endl;
    return;
  }

  int nBinsFromFile = 0;
  while (is.good())     
    {
      is.getline(c,999,',');     
      if (is.good()){
	nBinsFromFile++;
	//cout << c << endl;
      }
    }

  // choose the number of bins
  int nBins =  nBins_>0 ? nBins_ : nBinsFromFile-1 ;
  Float_t bins[nBins+1];
  cout << "Making histograms with " << nBins << " bins:" << endl;

  is.close();
  is.open(Form("bins/bins_muTau_mH%d_%s_%s.txt",mH_,selection_.c_str(),variable_.Data())); 
  
  nBinsFromFile = 0;

  if(nBins_>0){
    for( ; nBinsFromFile <= nBins ; nBinsFromFile++){
      bins[nBinsFromFile] =  xMin_ + nBinsFromFile*(xMax_-xMin_)/nBins_;
    }
  }
  else{
    while (is.good())  
      {
	is.getline(c,999,',');     
	if (is.good() && nBinsFromFile<=nBins) {
	  bins[nBinsFromFile] = atof(c);
	  cout << bins[nBinsFromFile] << ", " ;
	}
	nBinsFromFile++;
      }
    cout << endl;
  }

  // Luminosity analyzed & parameters
  float Lumi                     = (159.+887.+361.7+531.5)*1.00;
  float WcorrectionFactorOS      = 0.97;  
  float WcorrectionFactorSS      = 1.19;  
  float MutoTauCorrectionFactor  = 1.00;
  float JtoTauCorrectionFactor   = 0.80;
  float VbfExtrapolationFactor   = 1.03;


  TCanvas *c1 = new TCanvas("c1","",5,30,650,600);
  c1->SetGrid(0,0);
  c1->SetFillStyle(4000);
  c1->SetFillColor(10);
  c1->SetTicky();
  c1->SetObjectStat(0);
  c1->SetLogy(logy_);

  TLegend* leg = new TLegend(0.55,0.42,0.85,0.85,NULL,"brNDC");
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetFillColor(10);
  leg->SetTextSize(0.03);
  leg->SetHeader(Form("#splitline{CMS Preliminary}{#splitline{%.1f fb^{-1} #sqrt{s}=7 TeV}{#tau_{#mu}#tau_{had}}}", Lumi/1000. ));

  THStack* aStack = new THStack("aStack","");

  TH1F* hSiml  = new TH1F( "hSiml" ,"all"               , nBins , bins);
  TH1F* hSgn   = new TH1F( "hSgn " ,"vbf+ggf"           , nBins , bins);
  TH1F* hSgn1  = new TH1F( "hSgn1" ,"vbf"               , nBins , bins);
  TH1F* hSgn2  = new TH1F( "hSgn2" ,"ggf"               , nBins , bins);
  TH1F* hData  = new TH1F( "hData" ,"Observed"          , nBins , bins);
  TH1F* hW     = new TH1F( "hW"    ,"W+jets"            , nBins , bins);
  TH1F* hEWK   = new TH1F( "hEWK"  ,"EWK"               , nBins , bins);
  TH1F* hZtt   = new TH1F( "hZtt"  ,"Ztautau"           , nBins , bins);
  TH1F* hZmm   = new TH1F( "hZmm"  ,"Z+jets, mu to tau" , nBins , bins);
  TH1F* hZmj   = new TH1F( "hZmj"  ,"Z+jets, jet to tau", nBins , bins);
  TH1F* hTTb   = new TH1F( "hTTb"  ,"ttbar"             , nBins , bins);
  TH1F* hQCD   = new TH1F( "hQCD"  ,"QCD"               , nBins , bins);
  TH1F* hVV    = new TH1F( "hVV"   ,"Diboson"           , nBins , bins);

  // pZeta OS, N pZ sideband OS, pZeta SS, N sideband SS, N QCD SS, OS/SS
  TH1F* hParameters   = new TH1F( "hParameters", "" , 7, 0,7);

  // Open the files
  TFile *fData              
    = new TFile("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleRun2011-Mu-All_run_Open_MuTauStream.root", "READ");  
  TFile *fSignalVBF         
    = new TFile(Form("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleVBFH%d-Mu-powheg-PUS4_run_Open_MuTauStream.root",mH_) ,"READ");  
  TFile *fSignalGGH         
    = new TFile(Form("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleGGFH%d-Mu-powheg-PUS4_run_Open_MuTauStream.root",mH_),"READ");  
  TFile *fBackgroundDY
    = new TFile("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleDYJets-Mu-50-madgraph-PUS4_run_Open_MuTauStream.root","READ"); 
  TFile *fBackgroundWJets   
    = new TFile("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleWJets-Mu-madgraph-PUS4_run_Open_MuTauStream.root","READ"); 
  TFile *fBackgroundTTbar  
    = new TFile("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleTTJets-Mu-madgraph-PUS4_run_Open_MuTauStream.root","READ"); 
  TFile *fBackgroundOthers  
    = new TFile("/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStreamSummer11_fAna//nTupleOthers-Mu-PUS4_run_Open_MuTauStream.root","READ"); 

  // choose the analysis: Nominal "", jet up/Down "JetUp/Down" , elec up/down "MuUp/Down" , tau up/down "TauUp/Down"
  TString tree = "outTreePtOrd"+analysis_;

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

  // split the DY->ll into l=e/mu and l=tau (MC level) ===> temporary, need fix !!!
  TFile* dummy1 = new TFile("dummy1.root","RECREATE");
  cout << "Now copying g/Z -> tau+ tau- " << endl;
  TTree *backgroundDYTauTau  = ((TTree*)fBackgroundDY->Get(tree))->CopyTree("abs(genDecay)==(23*15)");                   // g/Z -> tau+ tau-
  cout << "Now copying g/Z -> mu+mu- mu->tau" << endl;
  TTree *backgroundDYMutoTau = ((TTree*)fBackgroundDY->Get(tree))->CopyTree("abs(genDecay)!=(23*15) && diTauCharge==0"); // g/Z -> mu+mu- mu->tau
  cout << "Now copying g/Z -> mu+mu- jet->tau" << endl;
  TTree *backgroundDYJtoTau  = ((TTree*)fBackgroundDY->Get(tree))->CopyTree("abs(genDecay)!=(23*15) && diTauCharge!=0"); // g/Z -> mu+mu- jet->tau

  cout << backgroundDYTauTau->GetEntries()  << " come from DY->tautau"      << endl;
  cout << backgroundDYMutoTau->GetEntries() << " come from DY->mumu, mu->tau"  << endl;
  cout << backgroundDYJtoTau->GetEntries()  << " come from DY->mumu, jet->tau"<< endl;

  TTree *backgroundTTbar     = (TTree*)fBackgroundTTbar->Get(tree);
  TTree *backgroundWJets     = (TTree*)fBackgroundWJets->Get(tree);
  TTree *backgroundOthers    = (TTree*)fBackgroundOthers->Get(tree);
 

  TCut lpt("ptL1>15");
  TCut tpt("ptL2>21");
  TCut tiso("tightestHPSDBWP>0");
  TCut liso("combRelIsoLeg1DBeta<0.1");
  TCut lveto("muFlag==0");
  TCut SS("diTauCharge!=0");
  TCut OS("diTauCharge==0");
  TCut oneJet("pt1>30");
  TCut twoJets("pt1>30 && pt2>30");
  TCut vbf("pt1>30 && pt2>30 && eta1*eta2<0 && Mjj>350 && Deta>3.5 && ptVeto<30");
  TCut novbf("pt2<30 || (pt1>30 && pt2>30 && ptVeto<30 && !(eta1*eta2<0 && Mjj>350 && Deta>3.5))");
  TCut hltevent("HLTx==1");
  TCut hltmatch("HLTmatch==1");
  TCut bTag("pt2<30 && ((pt1>20 && jetsBtagHE1>3.3) || (pt2>20 && jetsBtagHE2>3.3))");
  TCut nobTag("pt2<30 && jetsBtagHE1<3.3 && jetsBtagHE2<3.3");
  TCut pZ("(pZetaCorr-1.5*pZetaVisCorr)>-20");
  TCut apZ("(pZetaCorr-1.5*pZetaVisCorr)<-40");

  TCut sbin; TCut sbinPZetaRel; TCut sbinSS; TCut sbinPZetaRelSS; TCut sbinPZetaRev; TCut sbinPZetaRevSS;

  if(selection_.find("inclusive")!=string::npos){
    sbin           =  lpt && tpt && tiso && liso && lveto && OS && pZ  && hltevent && hltmatch;
    sbinPZetaRel   =  lpt && tpt && tiso && liso && lveto && OS        && hltevent && hltmatch;
    sbinPZetaRev   =  lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch;
    sbinPZetaRevSS =  lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch;
    sbinSS         =  lpt && tpt && tiso && liso && lveto && SS && pZ  && hltevent && hltmatch;
    sbinPZetaRelSS =  lpt && tpt && tiso && liso && lveto && SS        && hltevent && hltmatch;
  }
  else if(selection_.find("oneJet")!=string::npos){
    sbin           =  lpt && tpt && tiso && liso && lveto && OS && pZ  && hltevent && hltmatch && oneJet;
    sbinPZetaRel   =  lpt && tpt && tiso && liso && lveto && OS        && hltevent && hltmatch && oneJet;
    sbinPZetaRev   =  lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch && oneJet;
    sbinPZetaRevSS =  lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch && oneJet;
    sbinSS         =  lpt && tpt && tiso && liso && lveto && SS && pZ  && hltevent && hltmatch && oneJet;
    sbinPZetaRelSS =  lpt && tpt && tiso && liso && lveto && SS        && hltevent && hltmatch && oneJet;
  }
  else if(selection_.find("twoJets")!=string::npos){
    sbin           =  lpt && tpt && tiso && liso && lveto && OS && pZ  && hltevent && hltmatch && twoJets;
    sbinPZetaRel   =  lpt && tpt && tiso && liso && lveto && OS        && hltevent && hltmatch && twoJets;
    sbinPZetaRev   =  lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch && twoJets;
    sbinPZetaRevSS =  lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch && twoJets;
    sbinSS         =  lpt && tpt && tiso && liso && lveto && SS && pZ  && hltevent && hltmatch && twoJets;
    sbinPZetaRelSS =  lpt && tpt && tiso && liso && lveto && SS        && hltevent && hltmatch && twoJets;
  }
  else if(selection_.find("vbf")!=string::npos && selection_.find("novbf")==string::npos){
    sbin           =  lpt && tpt && tiso && liso && lveto && OS && pZ  && hltevent && hltmatch && vbf;
    sbinPZetaRel   =  lpt && tpt && tiso && liso && lveto && OS        && hltevent && hltmatch && vbf;
    sbinPZetaRev   =  lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch && vbf;
    sbinPZetaRevSS =  lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch && vbf;
    sbinSS         =  lpt && tpt && tiso && liso && lveto && SS && pZ  && hltevent && hltmatch && vbf;
    sbinPZetaRelSS =  lpt && tpt && tiso && liso && lveto && SS        && hltevent && hltmatch && vbf;
  }
  else if(selection_.find("novbf")!=string::npos){
    sbin           =  lpt && tpt && tiso && liso && lveto && OS && pZ  && hltevent && hltmatch && novbf;
    sbinPZetaRev   =  lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch && novbf;
    sbinPZetaRel   =  lpt && tpt && tiso && liso && lveto && OS        && hltevent && hltmatch && novbf;
    sbinPZetaRevSS =  lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch && novbf;
    sbinSS         =  lpt && tpt && tiso && liso && lveto && SS && pZ  && hltevent && hltmatch && novbf;
    sbinPZetaRelSS =  lpt && tpt && tiso && liso && lveto && SS        && hltevent && hltmatch && novbf;
  }
  else if(selection_.find("bTag")!=string::npos && selection_.find("nobTag")==string::npos){
    sbin           =  lpt && tpt && tiso && liso && lveto && OS && pZ  && hltevent && hltmatch && bTag;
    sbinPZetaRel   =  lpt && tpt && tiso && liso && lveto && OS        && hltevent && hltmatch && bTag;
    sbinPZetaRev   =  lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch && bTag;
    sbinPZetaRevSS =  lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch && bTag;    
    sbinSS         =  lpt && tpt && tiso && liso && lveto && SS && pZ  && hltevent && hltmatch && bTag;
    sbinPZetaRelSS =  lpt && tpt && tiso && liso && lveto && SS        && hltevent && hltmatch && bTag;
  }
  else if(selection_.find("nobTag")!=string::npos){
    sbin           =  lpt && tpt && tiso && liso && lveto && OS && pZ  && hltevent && hltmatch && nobTag;
    sbinPZetaRel   =  lpt && tpt && tiso && liso && lveto && OS        && hltevent && hltmatch && nobTag;
    sbinPZetaRev   =  lpt && tpt && tiso && liso && lveto && OS && apZ && hltevent && hltmatch && nobTag;
    sbinPZetaRevSS =  lpt && tpt && tiso && liso && lveto && SS && apZ && hltevent && hltmatch && nobTag;
    sbinSS         =  lpt && tpt && tiso && liso && lveto && SS && pZ  && hltevent && hltmatch && nobTag;
    sbinPZetaRelSS =  lpt && tpt && tiso && liso && lveto && SS        && hltevent && hltmatch && nobTag;
  }

  // estimate the W+jets in the selection bin using pZeta extrapolation

  TH1F* hWMt = new TH1F("hWMt","",200,-200,200);
  cout << "Histogramming the pZeta variable every " << hWMt->GetBinWidth(1) << " GeV" << endl;

  ///////////////////////////////////////// Doing OS first...
  hWMt->Reset();
  backgroundWJets->Draw("(pZetaCorr-1.5*pZetaVisCorr)>>hWMt","(sampleWeight*puWeight*HLTweightTau)"*sbinPZetaRel);
  cout << "Using  " << hWMt->Integral() << " entries from the W+jets OS sample" << endl;
  float OSWinSignalRegionMC = hWMt->Integral(91,200)*Lumi*hltEff_/1000.;
  float scaleFactorOS = (hWMt->Integral(0,80))/(hWMt->Integral(91,200));
  cout << "Extrapolation factor for W OS : P(pZetaCorr<-40)/P(pZetaCorr>-20) ==> " << scaleFactorOS << endl;
 
  hWMt->Reset();
  cout << "Estimating cobtribution from ttbar and others in OS low pZeta tail..." << endl;
  backgroundTTbar->Draw("(pZetaCorr-1.5*pZetaVisCorr)>>hWMt","(sampleWeight*puWeight*HLTweightTau)"*sbinPZetaRel);
  hWMt->Scale(Lumi*hltEff_/1000.);
  float ttbarExtrOS = hWMt->Integral(0,80);
  cout << "Contribution from ttbar in OS is " << ttbarExtrOS << endl;
  hWMt->Reset();
  backgroundOthers->Draw("(pZetaCorr-1.5*pZetaVisCorr)>>hWMt","(sampleWeight*puWeight*HLTweightTau)"*sbinPZetaRel);
  hWMt->Scale(Lumi*hltEff_/1000.);
  float othersExtrOS = hWMt->Integral(0,80);
  cout << "Contribution from single-t and di-boson in OS is " << othersExtrOS << endl;
  float OSWinSignalRegionDATA = data->GetEntries(sbinPZetaRev);
  cout << "Selected events in data in low pZeta tail " << OSWinSignalRegionDATA << endl;
  OSWinSignalRegionDATA -= ttbarExtrOS;
  OSWinSignalRegionDATA -= othersExtrOS;
  OSWinSignalRegionDATA /= scaleFactorOS;
  cout << "W+jets in signal region is estimated to be "  
       << OSWinSignalRegionDATA*scaleFactorOS << "/" << scaleFactorOS << " = " 
       << OSWinSignalRegionDATA <<  " +/- " << sqrt(OSWinSignalRegionDATA/scaleFactorOS)/scaleFactorOS << endl;
  cout << "  ===> the MC prediction was " << OSWinSignalRegionMC << endl;

  hParameters->SetBinContent(1, 1./scaleFactorOS );
  hParameters->SetBinContent(2, OSWinSignalRegionDATA*scaleFactorOS );

  ///////////////////////////////////////// Doing SS last...
  hWMt->Reset();
  backgroundWJets->Draw("(pZetaCorr-1.5*pZetaVisCorr)>>hWMt","(sampleWeight*puWeight*HLTweightTau)"*sbinPZetaRelSS);
  cout << "Using  " << hWMt->Integral() << " entries from the SS W+jets sample" << endl;
  float SSWinSignalRegionMC = hWMt->Integral(91,200)*Lumi*hltEff_/1000.;
  float scaleFactorSS = (hWMt->Integral(0,80))/(hWMt->Integral(91,200));
  cout << "Extrapolation factor for W SS : P(pZetaCorr<-40)/P(pZetaCorr>-20) ==> " << scaleFactorSS << endl;

  hWMt->Reset();
  cout << "Estimating cobtribution from ttbar and others in SS low pZeta tail..." << endl;
  backgroundTTbar->Draw("(pZetaCorr-1.5*pZetaVisCorr)>>hWMt","(sampleWeight*puWeight*HLTweightTau)"*sbinPZetaRelSS);
  hWMt->Scale(Lumi*hltEff_/1000.);
  float ttbarExtrSS = hWMt->Integral(0,80);
  cout << "Contribution from ttbar in SS is " << ttbarExtrSS << endl;
  hWMt->Reset();
  backgroundOthers->Draw("(pZetaCorr-1.5*pZetaVisCorr)>>hWMt","(sampleWeight*puWeight*HLTweightTau)"*sbinPZetaRelSS);
  hWMt->Scale(Lumi*hltEff_/1000.);
  float othersExtrSS = hWMt->Integral(0,80);
  cout << "Contribution from single-t and di-boson in SS is " << othersExtrSS << endl;
  float SSWinSignalRegionDATA = data->GetEntries(sbinPZetaRevSS);
  cout << "Selected events in data in low pZeta tail " << SSWinSignalRegionDATA << endl;
  SSWinSignalRegionDATA -= ttbarExtrSS;
  SSWinSignalRegionDATA -= othersExtrSS;
  SSWinSignalRegionDATA /= scaleFactorSS;
  cout << "W+jets in SS signal region is estimated to be "  
       << SSWinSignalRegionDATA*scaleFactorSS << "/" << scaleFactorSS << " = " 
       << SSWinSignalRegionDATA <<  " +/- " << sqrt(SSWinSignalRegionDATA/scaleFactorSS)/scaleFactorSS << endl;
  cout << "  ===> the MC prediction was " << SSWinSignalRegionMC << endl;

  hParameters->SetBinContent(3, 1./scaleFactorSS );
  hParameters->SetBinContent(4, SSWinSignalRegionDATA*scaleFactorSS );


  // here I choose the order in the stack
  std::vector<string> samples;
  samples.push_back("Data");
  samples.push_back("ggH115");
  samples.push_back("qqH115");
  samples.push_back("Others");
  samples.push_back("TTbar");
  samples.push_back("SS");
  samples.push_back("WJets");
  samples.push_back("DYMutoTau");
  samples.push_back("DYJtoTau");
  samples.push_back("DYToTauTau");

  

  // 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["DYToTauTau"]= backgroundDYTauTau;
  tMap["DYMutoTau"] = backgroundDYMutoTau;
  tMap["DYJtoTau"]  = backgroundDYJtoTau;
  tMap["WJets"]     = backgroundWJets;
  tMap["Others"]    = backgroundOthers;
  tMap["TTbar"]     = backgroundTTbar;
  tMap["SS"]        = data;


  
  std::map<TString,Float_t> vMap;


  for( unsigned iter=0; iter<samples.size(); iter++){

    cout << "Dealing with sample " << samples[iter] << endl;
    
    std::map<std::string,TTree*>::iterator it = tMap.find(samples[iter]);

    TString h1Name = "h1_"+it->first;
    TH1F* h1 = new TH1F( h1Name ,"" , nBins , bins);

    TTree* currentTree = 0;
    
    if((it->first).find("SS")!=string::npos){
      
      cout << "Remove W contamination from SS data sample ... " << endl;
      currentTree = (it->second);

      float error2OnQCD = 0.0;
      
      TH1F* hHelp = (TH1F*)h1->Clone("hHelp");
      hHelp->Reset();
      currentTree->Draw(variable_+">>hHelp", sbinSS);
      int SSevents = hHelp->GetEntries();
      cout << "Selected SS events in data " << hHelp->GetEntries() << endl;
      h1->Add(hHelp,1);

      hHelp->Reset();
      backgroundWJets->Draw(variable_+">>hHelp", "(sampleWeight*puWeight*HLTweightTau)"*sbinSS);
      cout << "We expect " << hHelp->Integral()*Lumi/1000*hltEff_ << " SS events from W+jets (from " << hHelp->GetEntries() << " entries)" << endl;
      float sFWSS = ( selection_.find("novbf")!=string::npos || selection_.find("nobTag")!=string::npos ) ? SSWinSignalRegionDATA/SSWinSignalRegionMC : WcorrectionFactorSS; // from the extrapolation factor DATA/MC
      hHelp->Scale(sFWSS*Lumi/1000*hltEff_);
      cout << "We estimate " << hHelp->Integral() << " SS events from W+jets by extrapolating" << endl;
      cout << " ==> removing W+jets from SS...." << endl;
      h1->Add(hHelp, -1 );
      if(hHelp->GetEntries()>0) error2OnQCD +=  pow( hHelp->Integral()/hHelp->GetEntries(), 2)*hHelp->GetEntries(); // error on MC W+jets SS events
      error2OnQCD +=  pow(WcorrectionFactorSS*0.06,2)*pow(hHelp->GetEntries(),2);        // error on W+jets extrapolation factor ==> 6% according to Artur
      cout << sqrt(error2OnQCD) << " <==  W" << endl;      

      hHelp->Reset();
      backgroundTTbar->Draw(variable_+">>hHelp", "(sampleWeight*puWeight*HLTweightTau)"*sbinSS);
      cout << "We expect " << hHelp->Integral()*Lumi/1000*hltEff_ << " SS events from TTbar (from " << hHelp->GetEntries() << " entries)" << endl;
      hHelp->Scale(1.0*Lumi/1000*hltEff_);
      cout << "We estimate " << hHelp->Integral() << " SS events from TTbar" << endl;
      cout << " ==> removing TTbar from SS...." << endl;
      h1->Add(hHelp, -1 );
      if(hHelp->GetEntries()>0) error2OnQCD +=  pow(hHelp->Integral()/hHelp->GetEntries(),2)*hHelp->GetEntries();   // error on MC TTbar SS events
      cout << sqrt(error2OnQCD) << " <== W + TTb" << endl;      

      hHelp->Reset();
      backgroundDYMutoTau->Draw(variable_+">>hHelp", "(sampleWeight*puWeight*HLTweightTau)"*sbinSS);
      cout << "We expect " << hHelp->Integral()*Lumi/1000*hltEff_ << " SS events from DY->mumu, mu->jet" << endl;
      hHelp->Scale(MutoTauCorrectionFactor*Lumi/1000*hltEff_);
      cout << "We estimate " << hHelp->Integral() << " SS events from DY->mumu, mu->tau" << endl;
      cout << " ==> removing DY->mumu, mu->tau from SS...." << endl;
      h1->Add(hHelp, -1 );
      if(hHelp->GetEntries()>0) error2OnQCD +=  pow(hHelp->Integral()/hHelp->GetEntries(),2)*hHelp->GetEntries();   // error on MC DY->mumu, mu->tau events
      cout << sqrt(error2OnQCD) << " <== W + TTb + DY(1)" << endl;      

      hHelp->Reset();
      backgroundDYJtoTau->Draw(variable_+">>hHelp", "(sampleWeight*puWeight*HLTweightTau)"*sbinSS);
      cout << "We expect " << hHelp->Integral()*Lumi/1000*hltEff_ << " SS events from DY->mumu, jet->tau" << endl;
      hHelp->Scale(JtoTauCorrectionFactor*Lumi/1000*hltEff_);
      cout << "We estimate " << hHelp->Integral() << " SS events from DY->mumu, jet->tau" << endl;
      cout << " ==> removing DY->mumu, mu->jet from SS...." << endl;
      h1->Add(hHelp, -1 );
      if(hHelp->GetEntries()>0) error2OnQCD +=  pow(hHelp->Integral()/hHelp->GetEntries(),2)*hHelp->GetEntries();   // error on MC DY->mumu, jet->tau events
      cout << sqrt(error2OnQCD) << " <== W + TTb + DY(1,2)" << endl;      

      //  OS/SS ratio
      h1->Scale(1.06);
      cout << "After removing the expected contribution from W+jets and rescaling by 1.06 we expect " 
	   << h1->Integral() << " events from QCD processes" << endl;

      hParameters->SetBinContent(5, SSevents);
      hParameters->SetBinContent(6, h1->Integral()/SSevents);

      cout << "Total unceratinty from bkg subtraction in SS region is " << sqrt(error2OnQCD) << endl;
      float totalRelErrorOnQCD = 0.02 + sqrt(error2OnQCD)/h1->Integral(); //0.02 ==> uncertainty on OS/SS ratio
      hParameters->SetBinContent(7,totalRelErrorOnQCD);

    }
    else{

      currentTree = (it->second);
      if((it->first).find("DYJtoTau")==string::npos)
	currentTree->Draw(variable_+">>"+h1Name, "(sampleWeight*puWeight*HLTweightTau)"*sbin);
      else
	currentTree->Draw(variable_+">>"+h1Name, "(sampleWeight*puWeight*HLTweightTau)"*sbinSS);

      // scale by correction factors
      if((it->first).find("Data")==string::npos)
	h1->Scale(Lumi/1000*hltEff_);

      // if W+jets, scale by extrapolation
      float sFWOS = 
	( selection_.find("novbf")!=string::npos || selection_.find("nobTag")!=string::npos ) ? OSWinSignalRegionDATA/OSWinSignalRegionMC : WcorrectionFactorOS;
      if((it->first).find("WJets")!=string::npos){
	h1->Scale( sFWOS );
	hW->Add(h1,1.0);
      }

      // if DY->tautau, and vbf scale by ratio data/MC
      if((it->first).find("DYToTauTau")!=string::npos && selection_.find("vbf")!=string::npos && selection_.find("novbf")==string::npos){
	cout << "DY->tautau will be rescaled by 1.03 according to the Z->mumu+vbf/Z->mumu ratio" << endl;
	h1->Scale( VbfExtrapolationFactor );
      }

      // if DY->mumu, mu->tau, scale by fake-rate
      if((it->first).find("DYMutoTau")!=string::npos){
	float sF = MutoTauCorrectionFactor;
	if(selection_.find("vbf")!=string::npos && selection_.find("novbf")==string::npos) sF *= VbfExtrapolationFactor;
	h1->Scale(sF);
	hZmm->Add(h1,1.0);
      }

      // if DY->mumu, jet->tau, scale by fake-rate
      if((it->first).find("DYJtoTau")!=string::npos){
	float sF = JtoTauCorrectionFactor;
	if(selection_.find("vbf")!=string::npos && selection_.find("novbf")==string::npos) sF *= VbfExtrapolationFactor;
	h1->Scale(sF);
	hZmj->Add(h1,2.0); // x2
      }

    }
  
    /////////////////////////////////////////////////////////////////////////////////////

    // Legend
    if( (it->first).find("DYMutoTau")!=string::npos ||  
	(it->first).find("DYJtoTau")!=string::npos || 
	(it->first).find("WJets")!=string::npos || 
	(it->first).find("Others")!=string::npos ) {
      hEWK->SetFillColor(kBlue);
      hEWK->Add(h1,1.0);

      if( (it->first).find("Others")!=string::npos )
	hVV->Add(h1,1.0);
    }

    if( (it->first).find("DYToTauTau")!=string::npos ) {
      hZtt->Add(h1,1.0);
      hZtt->SetFillColor(kWhite);
    }
    if( (it->first).find("TTbar")!=string::npos ) {
      hTTb->Add(h1,1.0);
      hTTb->SetFillColor(kMagenta);     
    }
    if( (it->first).find("SS")!=string::npos ) {
      hQCD->Add(h1,1.0);
      hQCD->SetFillColor(42);
    }
    if((it->first).find("qqH115")!=string::npos){
      hSgn1->Add(h1,1.0);
      hSgn1->Scale(magnifySgn_);
      h1->Scale(magnifySgn_);
      hSgn1->SetLineWidth(2);
      h1->SetFillColor(kBlack);
      h1->SetFillStyle(3004);
      h1->SetLineColor(kBlack);
    }
    if((it->first).find("ggH115")!=string::npos){
      hSgn2->Add(h1,1.0);
      hSgn2->Scale(magnifySgn_);
      h1->Scale(magnifySgn_);
      hSgn2->SetLineWidth(2);
      h1->SetFillColor(kBlack);
      h1->SetFillStyle(3005);
      h1->SetLineColor(kBlack);
    }
    if((it->first).find("Data")!=string::npos){
      hData->Add(h1,1.0);
      hData->Sumw2();
      hData->SetMarkerStyle(20);
      hData->SetMarkerSize(1.2);
      hData->SetMarkerColor(kBlack);
      hData->SetLineColor(kBlack);
      hData->SetXTitle(XTitle_+" ("+Unities_+")");
      hData->SetYTitle(Form(" Events/(%.1f %s)", hData->GetBinWidth(1), Unities_.Data() ) );
      hData->SetTitleSize(0.04,"X");
      hData->SetTitleSize(0.05,"Y");
      hData->SetTitleOffset(0.95,"Y");
    }

    // adding alltogether
    hSiml->Add(h1,1.0);

    if(VERBOSE) cout<<(it->first) << " ==> " 
		    << h1->Integral() << " +/- " 
		    << TMath::Sqrt(h1->GetEntries())*(h1->Integral()/h1->GetEntries())
		    << endl;
  }

  // all signal summed together:
  hSgn->Add(hSgn1,hSgn2,1,1);
  hSgn->SetFillColor(kRed);
  hSgn->SetLineWidth(2);

  //Adding to the stack
  aStack->Add(hQCD);
  aStack->Add(hEWK);
  aStack->Add(hTTb);
  aStack->Add(hZtt);
  aStack->Add(hSgn);

  // legend
  leg->AddEntry(hData,"Observed","P");
  leg->AddEntry(hSgn,Form("(%.0fx) H#rightarrow#tau#tau m_{H}=%d",magnifySgn_,mH_),"F");
  leg->AddEntry(hZtt,"Z#rightarrow#tau#tau","F");
  leg->AddEntry(hTTb,"t#bar{t}","F");
  leg->AddEntry(hEWK,"Electroweak","F");
  leg->AddEntry(hQCD,"QCD","F");
  
  hData->Draw("P");
  aStack->Draw("HISTSAME");
  hData->Draw("PSAME");
  
  TH1F* hStack = (TH1F*)aStack->GetHistogram();
  hStack->SetXTitle(XTitle_+" ("+Unities_+")");
  hStack->SetYTitle(Form(" Events/(%.0f %s)", hStack->GetBinWidth(1), Unities_.Data() ) );
  hStack->SetTitleSize(0.04,"X");
  hStack->SetTitleSize(0.05,"Y");
  hStack->SetTitleOffset(0.95,"Y");

  leg->Draw();

  c1->SaveAs(Form("plots/plot_muTau_mH%d_%s_%s_%s.png",mH_,selection_.c_str(),analysis_.c_str(),variable_.Data()));

  // templates for fitting
  TFile* fout = new TFile(Form("histograms/muTau_mH%d_%s_%s_%s.root",mH_,selection_.c_str(),analysis_.c_str(),variable_.Data()),"RECREATE");
  fout->cd();
  hQCD->Write();
  hZmm->Write();
  hZmj->Write();
  hTTb->Write();
  hZtt->Write();
  hW->Write();
  hVV->Write();
  hSgn1->Write();
  hSgn2->Write();
  hData->Write();
  hParameters->Write();
  fout->Write();
  fout->Close();

}
示例#11
0
void makeTree(string sample = "DY", string selection = "", float Lumi = 1){

  vector<pair<string,float> > files;
  vector< TH1F* > histos;

  vector<string> directories;
  
  if(sample.find("DY")!=string::npos){
    files.push_back( make_pair("DY-madgraph-10to50.root",      (310*0.19*Lumi)  ) );
    files.push_back( make_pair("DY-madgraph-50.root",          (2289*0.56*Lumi)  ) );
  }
  
  if(sample.find("Wjets")!=string::npos){
    files.push_back( make_pair("W1Jets_ptW-0to100.root",       (3.693e+03*0.44*Lumi)  ) );
    files.push_back( make_pair("W1Jets_ptW-100to300.root",     (7.197e+01*0.58*Lumi)  ) );
    files.push_back( make_pair("W1Jets_ptW-300to800.root",     (5.658e-01*0.73*Lumi)  ) );
    files.push_back( make_pair("W2Jets_ptW-0to100.root",       (9.434e+02*0.46*Lumi)  ) );
    files.push_back( make_pair("W2Jets_ptW-100to300.root",     (6.718e+01*0.59*Lumi)  ) );
    files.push_back( make_pair("W2Jets_ptW-300to800.root",     (8.553e-01*0.75*Lumi)  ) );
    files.push_back( make_pair("W3Jets_ptW-0to100.root",       (2.087e+02*0.48*Lumi)  ) );
    files.push_back( make_pair("W3Jets_ptW-100to300.root",     (3.243e+01*0.60*Lumi)  ) );
    files.push_back( make_pair("W3Jets_ptW-300to800.root",     (6.229e-01*0.76*Lumi)  ) );
    files.push_back( make_pair("W4Jets_ptW-0to100.root",       (4.446e+01*0.50*Lumi)  ) );
    files.push_back( make_pair("W4Jets_ptW-100to300.root",     (1.138e+01*0.61*Lumi)  ) );
    files.push_back( make_pair("W4Jets_ptW-300to800.root",     (2.950e-01*0.77*Lumi)  ) );
    files.push_back( make_pair("W5Jets_ptW-0to100.root",       (1.111e+01*0.53*Lumi)  ) );
    files.push_back( make_pair("W5Jets_ptW-100to300.root",     (3.789e+00*0.65*Lumi)  ) );
    files.push_back( make_pair("W5Jets_ptW-300to800.root",     (1.565e-01*0.79*Lumi)  ) );
  }
  if(sample.find("TT")!=string::npos){
    files.push_back( make_pair("TT.root",                      (94*Lumi)  ) );
  }
  if(sample.find("QCD")!=string::npos){
    files.push_back( make_pair("QCD_Pt-0to5.root",             (4.84e+10*6.07E-07*Lumi)) );
    files.push_back( make_pair("QCD_Pt-5to15.root",            (3.68e+10*1.82E-06*Lumi)) );
    files.push_back( make_pair("QCD_Pt-15to30.root",           (8.16e+08*0.000113*Lumi)) );
    files.push_back( make_pair("QCD_Pt-30to50.root",           (5.31e+07*0.00388126*Lumi)) );
    files.push_back( make_pair("QCD_Pt-50to80.root",           (6.36e+06*0.02321727*Lumi)) );
    files.push_back( make_pair("QCD_Pt-80to120.root",          (7.84e+05*0.06100585*Lumi)) );
    files.push_back( make_pair("QCD_Pt-120to170.root",         (1.15e+05*0.11389810*Lumi)) );
    files.push_back( make_pair("QCD_Pt-170to300.root",         (2.43e+04*0.13732413*Lumi)) );
    files.push_back( make_pair("QCD_Pt-300to470.root",         (1.17e+03*0.317390358*Lumi)) );
    files.push_back( make_pair("QCD_Pt_470to600.root",         (7.02e+01*0.431763719*Lumi)) );
    files.push_back( make_pair("QCD_Pt_600to800.root",         (1.56e+01*0.508048972*Lumi)) );
    files.push_back( make_pair("QCD_Pt_800to1000.root",        (1.84e+00*0.385363968*Lumi)) );
    files.push_back( make_pair("QCD_Pt_1000to1400.root",       (3.32e-01*0.661857989*Lumi)) );
    //files.push_back( make_pair("QCD_Pt_1400to1800.root",       (1.09e-02*0.784767648*Lumi)) );
  }

  
  directories.push_back("etoTauMargLooseNoCracks80");
  directories.push_back("etoTauMargLooseNoCracks70");
  directories.push_back("etoTauMargLooseNoCracks60");
  directories.push_back("etoTauMargMediumNoCracks80");
  directories.push_back("etoTauMargMediumNoCracks70");
  directories.push_back("etoTauMargMediumNoCracks60");
  directories.push_back("etoTauMargTightNoCracks80");
  directories.push_back("etoTauMargTightNoCracks70");
  directories.push_back("etoTauMargTightNoCracks60");

  directories.push_back("etoTauSCMargNoCracks80");
  directories.push_back("etoTauSCMargNoCracks70");
  directories.push_back("etoTauSCMargNoCracks60");
    

  TFile *outFile = new TFile(("testNewWriteFromPAT_soup"+selection+".root").c_str(),"RECREATE");
  
  int numFiles = 0;

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

    numFiles = 0;

    histos.clear();

    for(unsigned int i = 0; i<files.size();i++){
      histos.push_back( new TH1F(Form("h_%d",i),Form("file %s",(files[i].first).c_str()),20,40,120) );
    }

    THStack* aStack = new THStack("aStack","");
    TLegend* leg = new TLegend(0.1331269,0.5926573,0.3622291,0.8671329,NULL,"brNDC");
    leg->SetFillStyle(4000);
    leg->SetBorderSize(0);
    leg->SetFillColor(10);
    leg->SetTextSize(0.03);

    cout << "Directory " <<  directories[j] << endl;

    TChain* outChain = new TChain((directories[j]+"/fitter_tree").c_str());

    int counter = 0;
    for(unsigned int i = 0; i<files.size();i++){

      TFile *file = new TFile(("/data_CMS/cms/lbianchini/35pb/testNewWriteFromPAT_"+files[i].first).c_str(),"READ");
      if(file->IsZombie()){
	cout << "No file " << files[i].first << " is found" << endl;
	continue;
      }

      file->cd("allEventsFilter");
      TH1F* totalEvents = (TH1F*)gDirectory->Get("totalEvents");
      float readEvents = totalEvents->GetBinContent(1);

      file->cd(directories[j].c_str());
      TTree *oldTree = (TTree*) gDirectory->Get("fitter_tree");

      float scaleToNNLO = 1.0;
      if((files[i].first).find("DY")!=string::npos)    scaleToNNLO = 1.33;
      if((files[i].first).find("W")!=string::npos)     scaleToNNLO = 1.23;
      if((files[i].first).find("TT")!=string::npos)    scaleToNNLO = 1.75;
     
      int entries = std::min( (int)oldTree->GetEntries(),  
			      (int)(((files[i].second*scaleToNNLO)/readEvents)*oldTree->GetEntries()) );

      TFile *newFile = new TFile( ("/data_CMS/cms/lbianchini/35pb/testNewWriteFromPAT_"+files[i].first+"new").c_str(), "RECREATE");
      TDirectory* dir = (TDirectory*) newFile->mkdir(directories[j].c_str());
      TTree *tree = oldTree->CloneTree( entries );

      // weight for the tree: 1 if you require less than the overall tree entries, otherwise set it to L*sigma/processed 
      //float weight = std::max((double)files[i].second,1.0);
      //tree->SetWeight( weight );
      double weight;
      tree->Branch("weight", &weight,"weight/D");
      weight = std::max((double)(files[i].second/readEvents),1.0);
      tree->Fill();

      TH1F* h = new TH1F("h","",20,40,120);
      tree->Draw("mass>>h",("weight*("+selection+")").c_str());
      histos[i]->Add(h,1);
      histos[i]->SetFillColor(i+1);
      histos[i]->SetLineColor(i+1);
      //setUpHisto(histos[i],Lumi, directories[j]);
      aStack->Add( histos[i] );
      leg->AddEntry( histos[i], (files[i].first).c_str(),"F");

      dir->cd();
      tree->Write();
      newFile->Write();

      counter+=entries;

      cout << files[i].first 
	   << " ==> total entries " << oldTree->GetEntries() 
	   << " --- Required " <<  (int)(files[i].second/readEvents*oldTree->GetEntries())
	   << " --- Provided " << entries
	   <<  endl;
      std::cout << "The tree will have weight: " << weight << std::endl; 
      //outTree->CopyEntries(tree,entries);

      if(entries>0){
	int isOK =  outChain->AddFile( ("/data_CMS/cms/lbianchini/35pb/testNewWriteFromPAT_"+files[i].first+"new").c_str());
	if( isOK == 0) cout << "No linked file" << endl;
	numFiles += isOK;
      }
      cout << " outChain has " << outChain->GetEntries() 
	   << " and attached files " << numFiles
	   << endl;

      file->Close();
      newFile->Close();
      //delete h;
      delete file;
      delete newFile;
    } // file

    //outFile->cd();
    TDirectory* dir = (TDirectory*) outFile->mkdir(directories[j].c_str());
    
    TTree* outTree = (TTree*) outChain->CopyTree("");
  
    //outTree->Draw("mass");

    cout<< "Total events copied in output directory " << outTree->GetEntries() << " from requested " << counter << endl;

    dir->cd();
    outTree->Write("", TObject::kOverwrite);

    TCanvas *c1 = new TCanvas("c1","stacked mass",10,30,650,600);
    c1->SetGrid(0,0);
    c1->SetFillStyle(4000);
    c1->SetFillColor(10);
    c1->SetTicky();
    c1->SetObjectStat(0);

    aStack->Draw("HIST");

    setUpHisto( (TH1F*)aStack->GetHistogram(), Lumi, directories[j] );
    leg->SetHeader(directories[j].c_str());
    leg->Draw(); 
    c1->Write();

    for(int i = 0; i<histos.size(); i++){
      delete histos[i];
    }
    delete aStack;
    delete leg;

  }//directories

  


  outFile->Write();
  outFile->Close();
  delete outFile;

}
示例#12
0
THStack* BasePlot::GetStack(bool isLog)  {
    THStack* hstack = new THStack();

    float binWidth = 0;
    for (int i=0; i<nSamples; i++) if( _hist[i] && i != iHWW) {

        _hist[i]->SetLineColor(sampleColor[i]);
        _hist[i]->SetFillColor(sampleColor[i]);
        _hist[i]->SetFillStyle(1001);
        binWidth = _hist[i]->GetBinWidth(1);

        hstack->Add(_hist[i]);
    }

    for (size_t i=0; i<_autreHists.size(); i++) {

        _autreHists[i].second->SetLineColor(autreColors[i]);
        _autreHists[i].second->SetFillColor(autreColors[i]);
        _autreHists[i].second->SetFillStyle(1001);

        hstack->Add(_autreHists[i].second);
    }


    hstack->Draw("GOFF");
    if(_prelim) hstack->SetTitle("CMS preliminary");
    else        hstack->SetTitle("CMS, #sqrt{s} = 7 TeV");

    Float_t theMax = hstack->GetMaximum();
    Float_t theMin = hstack->GetMinimum();

    if (_hist[iHWW]) {
        if (_hist[iHWW]->GetMaximum() > theMax) theMax = _hist[iHWW]->GetMaximum();
        if (_hist[iHWW]->GetMinimum() < theMin) theMin = _hist[iHWW]->GetMinimum();
    }

    if (_data) {
        Float_t dataMax = GetMaximumIncludingErrors(_data);
        if (dataMax > theMax) theMax = dataMax;
    }

    int sampCount = GetSampCount();
    float scaleBy = 1.35 + 0.2*(sampCount>6) + 0.2*(sampCount>10) + 0.2*(sampCount>14);

    // Min --- only need to change if log
    theMin = theMin==0?0.1:theMin/10;
    if(isLog) hstack->SetMinimum(theMin);

    // Max
    if (_myMax != -1) {
        hstack->SetMaximum(_myMax);
    } else if (isLog) {
        hstack->SetMaximum(pow(10,(log(theMax)/log(10)-log(theMin)/log(10)+1)*scaleBy+log(theMin)/log(10)-1));
    } else {
        hstack->SetMaximum(scaleBy * theMax);
    }


    if(_breakdown) {
        THStackAxisFonts(hstack, "y", "entries");
        hstack->GetHistogram()->LabelsOption("v");
    } else {
        THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data()));
        THStackAxisFonts(hstack, "y", TString::Format("entries / %.1f %s", binWidth,_units.Data()));
        if(_units.Sizeof() == 1) {
            THStackAxisFonts(hstack, "x", _xLabel.Data());
//            THStackAxisFonts(hstack, "y", "entries");
        }
    }
    return hstack;
}
示例#13
0
void fakeStudyMu( TCut Cuts_ = "ptL1>0",
		  TString variable_ = "MtLeg1",
		  TString XTitle_ = "M_{T}(#mu,MET)",
		  TString Unities_ = "GeV",
		  Int_t nBins_ = 12, Float_t xMin_=0, Float_t xMax_=120,
		  Float_t magnifySgn_ = 10,
		  Float_t hltEff_ = 1.0,
		  Int_t enableHLTmatching_ = 1,
		  Int_t logy_ = 0 ) 
{   
  
  float Lumi = 24.86+159.15;

  TCanvas *c1 = new TCanvas("c1","",5,30,650,600);
  c1->SetGrid(0,0);
  c1->SetFillStyle(4000);
  c1->SetFillColor(10);
  c1->SetTicky();
  c1->SetObjectStat(0);
  c1->SetLogy(logy_);

  TLegend* leg = new TLegend(0.60,0.50,0.85,0.85,NULL,"brNDC");
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetFillColor(10);
  leg->SetTextSize(0.04);
  leg->SetHeader("#mu+#tau_{had}");

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

  // OpenNTuples
  TString fDataName                = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleRun2011-Mu_Open_MuTauStream.root";
  TString fSignalNameVBF           = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleVBFH115-Mu-powheg-PUS1_Open_MuTauStream.root";
  TString fSignalNameGGH           = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleGGFH115-Mu-powheg-PUS1_Open_MuTauStream.root";
  TString fBackgroundNameDYTauTau  = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleDYJets-Mu-50-madgraph-PUS1_Open_MuTauStream.root";
  TString fBackgroundNameDYMuMu    = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleDYJets-Mu-50-madgraph-PUS1_Open_MuTauStream.root";
  TString fBackgroundNameWJets     = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleWJets-Mu-madgraph-PUS1_Open_MuTauStream.root";
  TString fBackgroundNameQCD       = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleQCDmu_Open_MuTauStream.root";
  TString fBackgroundNameTTbar     = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleTTJets-Mu-madgraph-PUS1_Open_MuTauStream.root";
  TString fBackgroundNameSingleTop = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/Inclusive/nTupleSingleTop-Mu_Open_MuTauStream.root";
  TString fBackgroundNameDiBoson   = "/data_CMS/cms/lbianchini/VbfJetsStudy/OpenNtuples/MuTauStream2011_iter2/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 *fBackgroundQCD(0);
  TFile *fBackgroundTTbar(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 ); 
  fBackgroundQCD      = TFile::Open( fBackgroundNameQCD ); 
  fBackgroundTTbar    = TFile::Open( fBackgroundNameTTbar );
  fBackgroundSingleTop= TFile::Open( fBackgroundNameSingleTop ); 
  fBackgroundDiBoson  = TFile::Open( fBackgroundNameDiBoson ); 

  if(!fSignalVBF || !fBackgroundDYTauTau || !fBackgroundWJets || !fBackgroundQCD || !fBackgroundTTbar || !fBackgroundSingleTop ||
     !fSignalGGH || !fBackgroundDYMuMu || !fBackgroundDiBoson || !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 *backgroundQCD       = (TTree*)fBackgroundQCD->Get(tree);
  TTree *backgroundTTbar     = (TTree*)fBackgroundTTbar->Get(tree);
  TTree *backgroundSingleTop = (TTree*)fBackgroundSingleTop->Get(tree);
  TTree *backgroundDiBoson   = (TTree*)fBackgroundDiBoson->Get(tree);
 
  // 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("SingleTop");
  samples.push_back("TTbar");
  samples.push_back("Wjets");
  samples.push_back("QCD");
  samples.push_back("ZfakeTau");
  samples.push_back("Ztautau");
  samples.push_back("Data");

  // 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["QCD"]=backgroundQCD;
  tMap["TTbar"]=backgroundTTbar;
  tMap["SingleTop"]=backgroundSingleTop;
  tMap["DiBoson"]=backgroundDiBoson;

  Float_t pt1, pt2, Deta, Mjj, eta1, eta2;
  Float_t diTauSVFitPt,diTauVisPt,diTauVisEta,diTauSVFitEta,diTauVisMass,diTauSVFitMass,ptL1,ptL2,etaL1,etaL2,diTauCharge,MtLeg1,numPV,combRelIsoLeg1DBeta,combRelIsoLeg1,pZetaCutVar, MEt, ptVeto, leadTrackPt, jetsBtagHE1, jetsBtagHE2;
  Float_t sampleWeight,puWeight;

  std::map<TString,Float_t> vMap;

  for( unsigned iter=0; iter<samples.size(); iter++){

    std::map<std::string,TTree*>::iterator it = tMap.find(samples[iter]);

    TString h1Name = "h1_"+it->first;
    TH1F* h1 = new TH1F( h1Name ,Form("CMS Preliminary 2011    #sqrt{s}=7 TeV L=%.0f pb^{-1}", Lumi) , nBins_ ,xMin_ , xMax_);

    TFile* dummy = new TFile("dummy.root","RECREATE");  
    TCut Cuts = Cuts_;
    TCut hlt = enableHLTmatching_ ? "( ((HLTmatch==2 && run<=163261) || (HLTmatch==1 && run>163261)) && ((HLTmu==1 && run<=163261) || (HLTx==1 && run>163261)) )" : "( ((HLTmu==1 && run<=163261) || (HLTx==1 && run>163261)) )";

    if((it->first).find("Data")!=string::npos) Cuts = Cuts_ && hlt;
    TTree* currentTree = (TTree*)(it->second)->CopyTree(Cuts);
    Int_t counter = 0;

    currentTree->SetBranchAddress( "pt1", &pt1 );
    currentTree->SetBranchAddress( "pt2", &pt2 );
    currentTree->SetBranchAddress( "Deta",&Deta );
    currentTree->SetBranchAddress( "Mjj", &Mjj );
    currentTree->SetBranchAddress( "diTauSVFitPt",&diTauSVFitPt);
    currentTree->SetBranchAddress( "diTauSVFitEta",&diTauSVFitEta);
    currentTree->SetBranchAddress( "diTauSVFitMass",&diTauSVFitMass);
    currentTree->SetBranchAddress( "diTauVisPt",&diTauVisPt);
    currentTree->SetBranchAddress( "diTauVisEta",&diTauVisEta);
    currentTree->SetBranchAddress( "diTauVisMass",&diTauVisMass);
    currentTree->SetBranchAddress( "ptL1",  &ptL1 );
    currentTree->SetBranchAddress( "ptL2",  &ptL2 );
    currentTree->SetBranchAddress( "etaL1", &etaL1 );
    currentTree->SetBranchAddress( "etaL2", &etaL2 );
    currentTree->SetBranchAddress( "combRelIsoLeg1DBeta",&combRelIsoLeg1DBeta);
    currentTree->SetBranchAddress( "combRelIsoLeg1",&combRelIsoLeg1);
    currentTree->SetBranchAddress( "diTauCharge",&diTauCharge);
    currentTree->SetBranchAddress( "MtLeg1",&MtLeg1);
    currentTree->SetBranchAddress( "pZetaCutVar",&pZetaCutVar);
    currentTree->SetBranchAddress( "numPV",&numPV);
    currentTree->SetBranchAddress( "sampleWeight",&sampleWeight);
    currentTree->SetBranchAddress( "puWeight",&puWeight);
    currentTree->SetBranchAddress( "ptVeto",&ptVeto);
    currentTree->SetBranchAddress( "MEt",&MEt);
    currentTree->SetBranchAddress( "leadTrackPt",&leadTrackPt);
    currentTree->SetBranchAddress( "jetsBtagHE1",&jetsBtagHE1);
    currentTree->SetBranchAddress( "jetsBtagHE2",&jetsBtagHE2);

    for (Long64_t ievt=0; ievt<currentTree->GetEntries();ievt++) {

      currentTree->GetEntry(ievt);

      if (ievt%10000 == 0){
	std::cout << (it->first) << " ---> processing event: " << ievt << " ..." <<std::endl;
      }

     
      vMap["diTauSVFitPt"]  = diTauSVFitPt;
      vMap["diTauSVFitEta"] = diTauSVFitEta;
      vMap["diTauSVFitMass"]= diTauSVFitMass;
      vMap["diTauVisPt"]    = diTauVisPt;
      vMap["diTauVisEta"]   = diTauVisEta;
      vMap["diTauVisMass"]  = diTauVisMass;
      vMap["ptL1"]  = ptL1;
      vMap["ptL2"]  = ptL2;
      vMap["etaL1"] = etaL1;
      vMap["etaL2"] = etaL2;
      vMap["diTauCharge"]= Float_t(diTauCharge);
      vMap["MtLeg1"]= MtLeg1;
      vMap["pZetaCutVar"] = pZetaCutVar;
      vMap["numPV"]= numPV;
      vMap["combRelIsoLeg1"]= combRelIsoLeg1;
      vMap["combRelIsoLeg1DBeta"]= combRelIsoLeg1DBeta;
      vMap["sampleWeight"]= sampleWeight;
      vMap["puWeight"]= puWeight;
      vMap["puWeight"]= puWeight;
      vMap["jetsBtagHE1"]= jetsBtagHE1;
      vMap["jetsBtagHE2"]= jetsBtagHE2;
      vMap["leadTrackPt"]= leadTrackPt;

      vMap["pt1"]= pt1;
      vMap["pt2"]= pt2;
      vMap["Deta"]= Deta;
      vMap["Mjj"]= Mjj;
      vMap["ptVeto"]= ptVeto;

      if((it->first).find("Data")==string::npos) sampleWeight*=(Lumi/1000*hltEff_*puWeight);

      counter++;
      h1->Fill( vMap[variable_], sampleWeight);
    
    }// end loop


    if( (it->first).find("ZfakeTau")!=string::npos ) {
      h1->SetFillColor(7);
      leg->AddEntry(h1,"Z+jets, fake-#tau","F");
    }
    if( (it->first).find("Ztautau")!=string::npos ) {
      h1->SetFillColor(kRed);
      leg->AddEntry(h1,"Z+jets, genuine-#tau","F");
    }
    if( (it->first).find("TTbar")!=string::npos ) {
      h1->SetFillColor(kBlue);
      leg->AddEntry(h1,"t#bar{t}+jets","F");
    }
    if( (it->first).find("SingleTop")!=string::npos ) {
      h1->SetFillColor(29);
      leg->AddEntry(h1,"single-t","F");
    }
    if( (it->first).find("Wjets")!=string::npos ) {
      h1->SetFillColor(kGreen);
      leg->AddEntry(h1,"W+jets","F");
    }
    if( (it->first).find("DiBoson")!=string::npos ) {
      h1->SetFillColor(38);
      leg->AddEntry(h1,"Di-Boson","F");
    }
    if( (it->first).find("QCD")!=string::npos ) {
      h1->SetFillColor(42);
      leg->AddEntry(h1,"QCD-multijets","F");
    }
    if((it->first).find("qqH115")!=string::npos){
      hSgn1 = (TH1F*)h1->Clone("hSgn1");
      hSgn1->Scale(magnifySgn_);
      hSgn1->SetLineWidth(2);
      h1->SetFillColor(kBlack);
      h1->SetFillStyle(3004);
      h1->SetLineColor(kBlack);
      leg->AddEntry(h1,Form("VBF H(115) X %.0f",magnifySgn_),"F");
    }
    if((it->first).find("ggH115")!=string::npos){
      hSgn2 = (TH1F*)h1->Clone("hSgn2");
      hSgn2->Scale(magnifySgn_);
      hSgn2->SetLineWidth(2);
      h1->SetFillColor(kBlack);
      h1->SetFillStyle(3005);
      h1->SetLineColor(kBlack);
      leg->AddEntry(h1,Form("GGF H(115) X %.0f",magnifySgn_),"F");
    }
    if((it->first).find("Data")!=string::npos){
      hData = (TH1F*)h1->Clone("hData");
      hData->Sumw2();
      hData->SetMarkerStyle(20);
      hData->SetMarkerSize(1.2);
      hData->SetMarkerColor(kBlack);
      hData->SetLineColor(kBlack);
      hData->SetXTitle(XTitle_+" ("+Unities_+")");
      hData->SetYTitle(Form(" Events/(%.0f %s)", hData->GetBinWidth(1), Unities_.Data() ) );
      hData->SetTitleSize(0.04,"X");
      hData->SetTitleSize(0.05,"Y");
      hData->SetTitleOffset(0.95,"Y");
      leg->AddEntry(hData,"DATA","P");
    }

    if(iter==0) hSiml=(TH1F*)h1->Clone("hSiml");
    else if((it->first).find("Data")==string::npos) hSiml->Add(h1);

    if((it->first).find("Data")==string::npos) aStack->Add(h1);

    if(VERBOSE) cout<<(it->first) << " ==> " 
		   << h1->Integral() << " +/- " 
		   << TMath::Sqrt(h1->GetEntries())*(h1->Integral()/h1->GetEntries())
		   << endl;
  }

  // all signal summed together:
  hSgn = (TH1F*)hSgn1->Clone("hSgn");
  hSgn->Add(hSgn1,hSgn2,1,1);

  if(VERBOSE) cout<< "S/sqrt(B) ==> " 
		  << hSgn->Integral()/ TMath::Sqrt(hSiml->Integral()) << " +/- " 
		  << (1./2)*TMath::Sqrt(hSiml->GetEntries())*(hSiml->GetSumOfWeights())/hSiml->Integral()*( hSgn->Integral()/ TMath::Sqrt(hSiml->Integral())  )
		  << endl;

  hData->SetXTitle(XTitle_+" ("+Unities_+")");
  hData->SetYTitle(Form(" Events/(%.1f %s)", hData->GetBinWidth(1), Unities_.Data() ) );
  hData->SetTitleSize(0.04,"X");
  hData->SetTitleSize(0.05,"Y");
  hData->SetTitleOffset(0.95,"Y");

  hData->Draw("P");
  aStack->Draw("HISTSAME");
  hData->Draw("PSAME");
  //hSgn1->Draw("HISTSAME");
  //hSgn2->Draw("HISTSAME");

  TH1F* hStack = (TH1F*)aStack->GetHistogram();
  hStack->SetXTitle(XTitle_+" ("+Unities_+")");
  hStack->SetYTitle(Form(" Events/(%.0f %s)", hStack->GetBinWidth(1), Unities_.Data() ) );
  hStack->SetTitleSize(0.04,"X");
  hStack->SetTitleSize(0.05,"Y");
  hStack->SetTitleOffset(0.95,"Y");
  //aStack->GetYaxis()->SetRangeUser(0.0,std::max(hData->GetMaximum(),hStack->GetMaximum())*1.1);
  leg->Draw();


}
示例#14
0
文件: BiasDiff.C 项目: vlambert/AIC
void BiasDiff () {
  vector<TH1F*> AIC;
  
  for (UInt_t i = 1 ; i <= 7; i++){
    AIC.push_back( new TH1F( Form("AIC_%d",i), " ", 9, 0,10 ));
    AIC[i-1]->GetXaxis()->SetBinLabel(1,"category 0");
    AIC[i-1]->GetXaxis()->SetBinLabel(2,"");
    AIC[i-1]->GetXaxis()->SetBinLabel(3,"category 1");
    AIC[i-1]->GetXaxis()->SetBinLabel(4,"");
    AIC[i-1]->GetXaxis()->SetBinLabel(5,"category 2");
    AIC[i-1]->GetXaxis()->SetBinLabel(6,"");
    AIC[i-1]->GetXaxis()->SetBinLabel(7,"category 3");
    AIC[i-1]->GetXaxis()->SetBinLabel(8,"");
    AIC[i-1]->GetXaxis()->SetBinLabel(9,"Inclusive");
    AIC[i-1]->SetFillColor(bkgColors[i-1]);
    AIC[i-1]->SetLineColor(bkgColors[i-1]);
  }
  
  AIC[0]->Fill(1.0,0.02);
  AIC[0]->Fill(3.0,0.3089);
  AIC[0]->Fill(5.0,0.62);
  AIC[0]->Fill(7.0,0.36);
  AIC[0]->Fill(9.0,0.03);
  
  AIC[1]->Fill(1.0,0.08);
  AIC[1]->Fill(3.0,0.21);
  AIC[1]->Fill(5.0,0.08);
  AIC[1]->Fill(7.0,0.16);
  AIC[1]->Fill(9.0,0.33);
  
  AIC[2]->Fill(1.0,0.01);
  AIC[2]->Fill(3.0,0.02);
  AIC[2]->Fill(5.0,0.01);
  AIC[2]->Fill(7.0,0.02);
  AIC[2]->Fill(9.0,0.04);
  
  AIC[3]->Fill(1.0,0.20);
  AIC[3]->Fill(3.0,0.38);
  AIC[3]->Fill(5.0,0.24);
  AIC[3]->Fill(7.0,0.451);
  AIC[3]->Fill(9.0,0.60);
  
  AIC[4]->Fill(1.0,0.03);
  AIC[4]->Fill(3.0,0.08);
  AIC[4]->Fill(5.0,0.017);
  AIC[4]->Fill(7.0,0.001);
  AIC[4]->Fill(9.0,0.0001);
  
  AIC[5]->Fill(1.0,0.58);
  AIC[5]->Fill(3.0,0.001);
  AIC[5]->Fill(5.0,0.03);
  AIC[5]->Fill(7.0,0.007);
  AIC[5]->Fill(9.0,0.000003);
  
  AIC[6]->Fill(1.0,0.08);
  AIC[6]->Fill(3.0,0.0001);
  AIC[6]->Fill(5.0,0.003);
  AIC[6]->Fill(7.0,0.001);
  AIC[6]->Fill(9.0,0.0000004);
  
  TCanvas *cv = 0;
  TLegend *legend = 0;
  bool firstdrawn = false;
  
  // ===================================
  //           AIC
  // ===================================
  
  cv = new TCanvas("cv","cv",800,600);
  legend = new TLegend(0.64,0.64,0.90,0.84);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);
  
  THStack *stackAIC = new THStack();
  for (Int_t i = AIC.size()-1; i>=0; i--) {
    if (AIC[i]->Integral()>0) {
      stackAIC->Add(AIC[i]);
      legend->AddEntry(AIC[i],modelLegendLabels[i].c_str(),"F");
    }
  }
  stackAIC->Draw();
  stackAIC->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackAIC->GetHists()->At(0)))->GetXaxis()->GetTitle());
  legend->Draw();
  cv->SaveAs("AICvalues.pdf");
  
  // =======================================================

  //double x[7] = {1.0,2.0,3.0,4.0,5.0,6.0,7.0};
  double x[4] = {1.0,2.0,3.0,4.0};
  double comps[4],singEs[4],doubEs[4],tripEs[4],modEs[4],polys[4],pows[4],dpows[4];

 //Composite  
  //comps[0]  = ( (0.0042-0.0033)/0.0033+(0.0007-0.0036)/0.0036+(0.0180-0.012)/0.012+(0.0090-0.0023)/0.0023+ (0.0033-0.0031)/0.0031 ) /5;
  comps[0] = ( (0.0045-0.0043)/0.0043 + (0.0035-0.0018)/0.0018 + (0.0074-0.0084)/0.0084 + (0.0053-0.0065)/0.0065 + (0.0016-0.0029)/0.0029 ) /5;

  //comps[2] = ( (0.0036-0.0049)/0.0049 + (0.0075-0.0029)/0.0029 + (0.0125-0.0126)/0.0126 + (0.0041-0.0031)/0.0031 + (0.0053-0.0027)/0.0027 )/ 5;

  comps[1] = ( (0.0088-0.0122)/0.0122  + (0.0072-0.0064)/0.0064 + (0.0064-0.0057)/0.0057 ) / 3;

  comps[2] = ( (0.0142-0.0254)/0.0254 + (0.0118-0.0120)/0.0120 + (0.0024-0.0105)/0.0105 + (0.0057-0.0102)/0.0102 ) / 4;

  //comps[5] = ((0.0047 - 0.0043)/0.0043 + (0.0091 - 0.0083)/0.0083 + (0.0062 - 0.0071)/0.0071 + (0.0129-0.0120)/0.0120 + (0.0035 - 0.0014)/0.0014  ) / 5;

  comps[3] = ( (0.0040 - 0.0059)/0.0059 + (0.004 - 0.0009)/0.0009 + (0.0088 - 0.0046)/0.0046 + (0.0026 - 0.0033)/0.0033 + (0.0014 - 0.0022)/0.0022 ) / 5;


 //singE  

  singEs[0] = ( (0.0221-0.0043)/0.0043 + (0.0079-0.0018)/0.0018 + (0.0084-0.0084)/0.0084 + (0.0033-0.0065)/0.0065 + (0.0082-0.0029)/0.0029 ) /5;
 
  singEs[1] = ( (0.0050-0.0122)/0.0122  + (0.0084-0.0064)/0.0064 + (0.0114-0.0057)/0.0057 ) / 3;

  singEs[2] = ( (0.0196-0.0254)/0.0254 + (0.0024-0.0120)/0.0120 + (0.0008-0.0105)/0.0105 + (0.0003-0.0102)/0.0102 ) / 4;

  //singEs[3] = ( (0.0126 - 0.0059)/0.0059 + (0.0174 - 0.0009)/0.0009 + (0.0129 - 0.0046)/0.0046 + (0.0193 - 0.0033)/0.0033 + (0.0181 - 0.0022)/0.0022 ) / 5;
  singEs[3] = 3.0;
 //doubE  

  doubEs[0] = 0;
 
  doubEs[1] =   ( (0.0079-0.0122)/0.0122  + (0.0084-0.0064)/0.0064 + (0.0073-0.0057)/0.0057 ) / 3;

  doubEs[2] =  ( (0.0069-0.0254)/0.0254 + (0.0002-0.0120)/0.0120 + (0.0016-0.0105)/0.0105 + (0.0093-0.0102)/0.0102 ) / 4;

  doubEs[3] =  ( (0.0035 - 0.0059)/0.0059 + (0.004 - 0.0009)/0.0009 + (0.0097 - 0.0046)/0.0046 + (0.0041 - 0.0033)/0.0033 + (0.0052 - 0.0022)/0.0022 ) / 5;

  //tripE  

  tripEs[0] = ( (0.0045-0.0043)/0.0043 + (0.0035-0.0018)/0.0018 + (0.0074-0.0084)/0.0084 + (0.0053-0.0065)/0.0065 + (0.0016-0.0029)/0.0029 ) /5;
 
  tripEs[1] = ( (0.0079-0.0122)/0.0122  + (0.0084-0.0064)/0.0064 + (0.0073-0.0057)/0.0057 ) / 3;

  tripEs[2] = ( (0.0069-0.0254)/0.0254 + (0.0004-0.0120)/0.0120 + (0.0017-0.0105)/0.0105 + (0.0027-0.0102)/0.0102 ) / 4;

  tripEs[3] = ( (0.0039 - 0.0059)/0.0059 + (0.0043 - 0.0009)/0.0009 + (0.0092 - 0.0046)/0.0046 + (0.0015 - 0.0033)/0.0033 + (0.0039 - 0.0022)/0.0022 ) / 5;

//modE

  modEs[0] = ( (0.0076-0.0043)/0.0043 + (0.0022-0.0018)/0.0018 + (0.0022-0.0084)/0.0084 + (0.0071-0.0065)/0.0065 + (0.0008-0.0029)/0.0029 ) /5;

  modEs[1] = 0;
 
  modEs[2] = ( (0.0051-0.0254)/0.0254 + (0.001-0.0120)/0.0120 + (0.0017-0.0105)/0.0105 + (0.0041-0.0102)/0.0102 ) / 4;

  modEs[3] =  ( (0.0026 - 0.0059)/0.0059 + (0.0037 - 0.0009)/0.0009 + (0.0088 - 0.0046)/0.0046 + (0.0072 - 0.0033)/0.0033 + (0.0049 - 0.0022)/0.0022 ) / 5;


//poly  ****

  polys[0] = ( (0.0094-0.0043)/0.0043 + (0.0041-0.0018)/0.0018 + (0.0178-0.0084)/0.0084 + (0.0019-0.0065)/0.0065 + (0.0036-0.0029)/0.0029 ) /5;
 
  polys[1] = ( (0.0088-0.0122)/0.0122  + (0.0050-0.0064)/0.0064 + (0.0544-0.0057)/0.0057 ) / 3;

  polys[2] = 0;

  polys[3] = ( (0.0111 - 0.0059)/0.0059 + (0.0070 - 0.0009)/0.0009 + (0.0091 - 0.0046)/0.0046 + (0.0055 - 0.0033)/0.0033 + (0.0099 - 0.0022)/0.0022 ) / 5;

  //pow  

  pows[0] = ( (0.0042-0.0043)/0.0043 + (0.0093-0.0018)/0.0018 + (0.026-0.0084)/0.0084 + (0.0183-0.0065)/0.0065 + (0.0082-0.0029)/0.0029 ) /5;
 
  pows[1] = ( (0.0022-0.0122)/0.0122  + (0.0031-0.0064)/0.0064 + (0.0052-0.0057)/0.0057 ) / 3;

  pows[2] = ( (0.0018-0.0254)/0.0254 + (0.0153-0.0120)/0.0120 + (0.0194-0.0105)/0.0105 + (0.0149-0.0102)/0.0102 ) / 4;

  pows[3] = ( (0.0058 - 0.0059)/0.0059 + (0.0009 - 0.0009)/0.0009 + (0.0045 - 0.0046)/0.0046 + (0.0047 - 0.0033)/0.0033 + (0.0021 - 0.0022)/0.0022 ) / 5;

  //dpow   ****

  dpows[0] = ( (0.0005-0.0043)/0.0043 + (0.0093-0.0018)/0.0018 + (0.0261-0.0084)/0.0084 + (0.0183-0.0065)/0.0065 + (0.0082-0.0029)/0.0029 ) /5;
 
  dpows[1] = ( (0.0022-0.0122)/0.0122  + (0.0030-0.0064)/0.0064 + (0.0052-0.0057)/0.0057 ) / 3;

  dpows[2] = ( (0.0018-0.0254)/0.0254 + (0.0153-0.0120)/0.0120 + (0.0194-0.0105)/0.0105 + (0.0097-0.0102)/0.0102 ) / 4;

  dpows[3] = 0;

  TMultiGraph *mg = new TMultiGraph();

  TGraph *comp = new TGraph(4, x,comps);
  TGraph *singE = new TGraph(4,x,singEs);
  TGraph *doubE = new TGraph(4,x,doubEs);
  TGraph *tripE = new TGraph(4,x,tripEs);
  TGraph *modE = new TGraph(4,x,modEs);
  TGraph *poly = new TGraph(4,x,polys);
  TGraph *pow = new TGraph(4,x,pows);
  TGraph *dpow = new TGraph(4,x,dpows);
  legend = new TLegend(0.64,0.64,0.92,0.94);
  
  //comp->GetXaxis()->SetBinLabel(1,"Single Exp.");
  dpow->GetXaxis()->SetBinLabel(1,"Double Exp.");
  //comp->GetXaxis()->SetBinLabel(3,"Triple Exp.");
  dpow->GetXaxis()->SetBinLabel(2,"Modified Exp.");
  dpow->GetXaxis()->SetBinLabel(3,"Polynomial");
  //comp->GetXaxis()->SetBinLabel(6,"Single Power");
  dpow->GetXaxis()->SetBinLabel(4,"Double Power");
  singE->SetMarkerColor(bkgColors[0]);
  doubE->SetMarkerColor(bkgColors[1]);
  tripE->SetMarkerColor(bkgColors[2]);
  modE->SetMarkerColor(bkgColors[3]);
  poly->SetMarkerColor(bkgColors[4]);
  pow->SetMarkerColor(bkgColors[5]);
  dpow->SetMarkerColor(bkgColors[6]);
  comp->SetMarkerColor(28);

  singE->SetLineColor(bkgColors[0]);
  doubE->SetLineColor(bkgColors[1]);
  tripE->SetLineColor(bkgColors[2]);
  modE->SetLineColor(bkgColors[3]);
  poly->SetLineColor(bkgColors[4]);
  pow->SetLineColor(bkgColors[5]);
  dpow->SetLineColor(bkgColors[6]);
  comp->SetLineColor(28);

  legend->AddEntry(comp,"Composite","p");
  legend->AddEntry(singE,"Single Exponential","p");
  legend->AddEntry(doubE,"Double Exponential","p");
  legend->AddEntry(tripE,"Triple Exponential","p");
  legend->AddEntry(modE,"Modified Exponential","p");
  legend->AddEntry(poly,"Polynomial","p");
  legend->AddEntry(pow,"Power Law","p");
  legend->AddEntry(dpow,"Double Power Law","p");

  mg->Add(comp);
  mg->Add(singE);
  mg->Add(doubE);
  mg->Add(tripE);
  mg->Add(modE);
  mg->Add(poly);
  mg->Add(pow);
  mg->Add(dpow);





  //mg->GetYaxis()->SetRangeUser(-1,3);



  cv = new TCanvas("cv","cv",800,600);
  mg->Draw("apl");
  legend->Draw();
  cv->Update();
  cv->SaveAs("BiasAverages.pdf");
}
示例#15
0
        void Draw(TCanvas *c1, const int &rebin=1, const bool &showErr=true) {

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

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

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

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


            TH1F *summed = GetSummedMCHist();

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

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

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

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

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

        }
示例#16
0
文件: DrawKs.C 项目: ktf/AliPhysics
TCanvas* DrawKs(const char* filename)
{

  TFile* file = TFile::Open(filename, "READ");
  if (!file) {
    Warning("DrawKs", "File %s couldn't be opened", filename);
    return 0;
  }

  TH1* cent = static_cast<TH1*>(file->Get("cent"));
  if (!cent) {
    Warning("DrawKs", "Failed to find cent in %s", file->GetName());
    return 0;
  }

  TString t(filename);
  t.ReplaceAll("results/", "");
  t.ReplaceAll("combine_","");
  t.ReplaceAll("_0x3.root", "");
  TString nm(filename);
  nm.ReplaceAll(".root", "");
  nm.ReplaceAll("results/", "plots/");
  nm.ReplaceAll("combine", "ks");
  if (t.Contains("none")) 
    t.ReplaceAll("none", "No weights");
  else
    t.Append(" weights");
  
  Int_t cW = 1200;
  Int_t cH =  800;
  TCanvas* c = new TCanvas(nm,t,cW, cH);
  c->SetTopMargin(0.07);
  c->SetRightMargin(0.20);
  c->SetTicks();
  
  TLegend* l = new TLegend(1-c->GetRightMargin(),
			   c->GetBottomMargin(), 
			   .99,
			   1-c->GetTopMargin());
  l->SetFillStyle(0);
  l->SetBorderSize(0);
  
  THStack* s = new THStack("ks", "");
  Int_t nCent = cent->GetXaxis()->GetNbins();
  for (Int_t i = 1; i <= nCent; i++) {
    Double_t c1 = cent->GetXaxis()->GetBinLowEdge(i);
    Double_t c2 = cent->GetXaxis()->GetBinUpEdge(i);

    TH1*     h  = GetCentK(file, c1, c2, nCent-i+1-2, l);
    if (!h) continue;

    s->Add(h);
  }
  s->Draw("nostack");
  TH1* f = s->GetHistogram();
  if (f) {
    f->SetXTitle("#eta");
    f->SetYTitle("#it{k}(#eta)");
  }
  
  TLatex* tit = new TLatex(0.55, 0.99, t);
  tit->SetTextFont(42);
  tit->SetTextAlign(23);
  tit->SetTextSize(0.03);
  tit->SetNDC();
  tit->Draw();
  l->SetBorderSize(0);
  l->Draw();

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

  return c;
}
//------------------------------------------------------------------------------
// PlotHiggsRes_LP
//------------------------------------------------------------------------------
void RunMakeRazorPlots ( string signalfile, string signalLabel,  vector<string> bkgfiles,vector<string> bkgLabels, int boxOption = 0, int option = -1, string label = "", string latexlabel = "") {

  //--------------------------------------------------------------------------------------------------------------
  // Settings 
  //============================================================================================================== 
  double intLumi = 2000; //in units of pb^-1
  string Label = "";
  if (label != "") Label = "_" + label;

  vector<string> inputfiles;
  vector<string> processLabels;

  bool hasSignal = false;
  if (signalfile != "") {
    hasSignal = true;
    inputfiles.push_back(signalfile);
    processLabels.push_back(signalLabel);
  }
  assert(bkgfiles.size() == bkgLabels.size());
  for (int i=0; i < bkgfiles.size(); ++i) {
     inputfiles.push_back(bkgfiles[i]);
     processLabels.push_back(bkgLabels[i]);
  }

  //*******************************************************************************************
  //Define Histograms
  //*******************************************************************************************
  TH1F* histMRAllBkg =  new TH1F( "MRAllBkg",";M_{R} [GeV/c^{2}];Number of Events", 100, 400, 2400);
  TH1F* histRsqAllBkg =  new TH1F( "RsqAllBkg", ";R^{2};Number of Events", 24, 0.25, 1.45);
  histMRAllBkg->SetStats(false);
  histRsqAllBkg->SetStats(false);
  
  vector<TH1F*> histMR;
  vector<TH1F*> histRsq; 

  vector<TH2F*> histMRRsq;
  vector<TH1F*> histUnrolled; 
  vector<TH1F*> histUnrolled2bins; 
  vector<TH1F*> histUnrolledPercentage; 
  vector<TH1F*> histUnrolledPercentage2bins; 

  //  float MRBinLowEdges[] = {500, 600, 700, 900, 1200, 1600, 2500, 4000};
  //  float RsqBinLowEdges[] = {0.25, 0.30, 0.41, 0.52, 0.64, 1.5};

  // float MRBinLowEdges[] = {500, 600, 700, 900, 1200, 1600, 2500, 4000}; // Multijet Bins
  // float RsqBinLowEdges[] = {0.25, 0.30, 0.41, 0.52, 0.64, 1.5}; // Multijet Bins

  float MRBinLowEdges[] = {400, 500, 600, 700, 900, 1200, 1600, 2500, 4000}; // Lepton boxes
  float RsqBinLowEdges[] = {0.15, 0.20, 0.25, 0.30, 0.41, 0.52, 0.64, 1.5};  // Lepton boxes


  const int nMRBins = sizeof(MRBinLowEdges)/sizeof(float)-1;
  const int nRsqBins = sizeof(RsqBinLowEdges)/sizeof(float)-1;

  std::cout<<"AAAAAAA "<<nMRBins<<" "<<nRsqBins<<std::endl;

  assert (inputfiles.size() == processLabels.size());

  for (int i=0; i < inputfiles.size(); ++i) {    
    // histMR.push_back( new TH1F( Form("MR_%s",processLabels[i].c_str()), ";M_{R} [GeV/c^{2}];Number of Events", 100, 400, 2400));
    histMR.push_back( new TH1F( Form("MR_%s",processLabels[i].c_str()), ";M_{R} [GeV/c^{2}];Number of Events", nMRBins, MRBinLowEdges));
    if (!hasSignal || i != 0) histMR[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histMR[i]->SetLineWidth(3);
    histMR[i]->SetLineColor(color[i]);    
    histMR[i]->SetStats(false);    
    histMR[i]->Sumw2();

    // histRsq.push_back( new TH1F( Form("Rsq_%s",processLabels[i].c_str()), ";R^{2} ;Number of Events", 24, 0.25, 1.45));
    histRsq.push_back( new TH1F( Form("Rsq_%s",processLabels[i].c_str()), ";R^{2} ;Number of Events", nRsqBins, RsqBinLowEdges));
    if (!hasSignal || i != 0) histRsq[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histRsq[i]->SetLineWidth(3);
    histRsq[i]->SetLineColor(color[i]);
    histRsq[i]->SetStats(false);

    histMRRsq.push_back( new TH2F( Form("MRRsq_%s",processLabels[i].c_str()), ";M_{R} [GeV/c^{2}]; R^{2}", nMRBins, MRBinLowEdges, nRsqBins, RsqBinLowEdges));
    if (!hasSignal || i != 0) histMRRsq[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histMRRsq[i]->SetLineWidth(3);
    histMRRsq[i]->SetLineColor(color[i]);
    histMRRsq[i]->SetStats(false);
    histMRRsq[i]->Sumw2();

    histUnrolled.push_back( new TH1F( Form("Unrolled_%s",processLabels[i].c_str()), ";Bin Number ;Number of Events", nMRBins*nRsqBins, 0, nMRBins*nRsqBins));
    if (!hasSignal || i != 0) histUnrolled[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histUnrolled[i]->SetLineWidth(3);
    histUnrolled[i]->SetLineColor(color[i]);
    histUnrolled[i]->SetStats(false);     

    histUnrolled2bins.push_back( new TH1F( Form("Unrolled2bins_%s",processLabels[i].c_str()), ";Bin Number ;Event Density", 3, 0, 3));
    if (!hasSignal || i != 0) histUnrolled2bins[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histUnrolled2bins[i]->SetLineWidth(3);
    histUnrolled2bins[i]->SetLineColor(color[i]);
    histUnrolled2bins[i]->SetStats(false);     

    histUnrolledPercentage2bins.push_back( new TH1F( Form("UnrolledPercentage2bins_%s",processLabels[i].c_str()), ";;Event Density", 3, 0, 3));
    if (!hasSignal || i != 0) histUnrolledPercentage2bins[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histUnrolledPercentage2bins[i]->SetLineWidth(3);
    histUnrolledPercentage2bins[i]->SetLineColor(color[i]);
    histUnrolled2bins[i]->SetStats(false);     

    histUnrolledPercentage.push_back( new TH1F( Form("UnrolledPercentage_%s",processLabels[i].c_str()), ";Bin Number ; Fraction of total", nMRBins*nRsqBins, 0, nMRBins*nRsqBins));
    if (!hasSignal || i != 0) histUnrolledPercentage[i]->SetFillColor(color[i]);
    if (hasSignal && i==0) histUnrolledPercentage[i]->SetLineWidth(3);
    histUnrolledPercentage[i]->SetLineColor(color[i]);
    histUnrolledPercentage[i]->SetStats(false);     
}

  //*******************************************************************************************
  //Define Counts
  //*******************************************************************************************


  //*******************************************************************************************
  //Read files
  //*******************************************************************************************
  for (uint i=0; i < inputfiles.size(); ++i) {

    TFile* inputFile = new TFile(inputfiles[i].c_str(),"READ");
    assert(inputFile);
    TTree* tree = 0;
    tree = (TTree*)inputFile->Get("RazorInclusive");
 
    float weight = 0;
    int box = -1;
    int nBTaggedJets = 0;
    float dPhiRazor = 0;
    float MR = 0;
    float Rsq = 0;
    float mT = 0;
    int nGenMuons = 0;
    int nGenElectrons = 0;
    int nGenTaus = 0;

    // bool Flag_HBHENoiseFilter = false;
    // bool Flag_goodVertices    = false;
    // bool Flag_eeBadScFilter   = false;
    // bool Flag_EcalDeadCellTriggerPrimitiveFilter = false;


    tree->SetBranchAddress("weight",&weight);
    tree->SetBranchAddress("box",&box);
    tree->SetBranchAddress("nBTaggedJets",&nBTaggedJets);
    tree->SetBranchAddress("dPhiRazor",&dPhiRazor);
    tree->SetBranchAddress("MR",&MR);
    tree->SetBranchAddress("Rsq",&Rsq);
    tree->SetBranchAddress("mT",&mT);
    tree->SetBranchAddress("nGenMuons",&nGenMuons);
    tree->SetBranchAddress("nGenElectrons",&nGenElectrons);
    tree->SetBranchAddress("nGenTaus",&nGenTaus);
    // tree->SetBranchAddress("Flag_HBHENoiseFilter",&Flag_HBHENoiseFilter);
    // tree->SetBranchAddress("Flag_goodVertices",&Flag_goodVertices);
    // tree->SetBranchAddress("Flag_eeBadScFilter",&Flag_eeBadScFilter);
    // tree->SetBranchAddress("Flag_EcalDeadCellTriggerPrimitiveFilter",&Flag_EcalDeadCellTriggerPrimitiveFilter);
 

    cout << "Process : " << processLabels[i] << " : Total Events: " << tree->GetEntries() << "\n";
    for (int n=0;n<tree->GetEntries();n++) { 
    // for (int n=0;n<10000;n++) { 
    
      tree->GetEntry(n);
      if (n % 1000000 == 0) cout << "Processing Event " << n << "\n";       

      // if (intLumi*weight > 100) continue;

      //Box Options
      if (option == 0 ) {
	if (nBTaggedJets != 0) continue; 
      }
      if (option == 1 ) {
	if (nBTaggedJets != 1) continue;
      }
      if (option == 2 ) {
	if (nBTaggedJets != 2) continue;
      }
      if (option == 3 ) {
	if (nBTaggedJets < 3) continue;
      }
      if (option == 4 ) {
	if (nBTaggedJets < 0) continue; // all b-tag categories combined
      }

     //Box Options
      if (boxOption == 0) { // Multijet Box for Jamboree
	if( !(box == 11 || box == 12) ) continue;
      }
      if (boxOption == 1) { // MuonMultijet Box for Jamboree
	if( !(box == 3 || box == 4) ) continue;
      } 
      if (boxOption == 2) { // EleMultijet Box for Jamboree
	if( !(box == 6 || box == 7) ) continue;
      }

      // LeptonMultijet Box for Jamboree
      if(boxOption == 1 || boxOption == 2)
	if(mT<120) continue;

      // Multijet Box for Jamboree
      if (boxOption == 0)
	if(fabs(dPhiRazor) > 2.8) continue;

      //apply baseline cuts
      if(boxOption == 1 || boxOption == 2) 
	if (!(MR > 400 && Rsq > 0.15)) continue;
      
      if(boxOption == 0) 
	if (!(MR > 500 && Rsq > 0.25)) continue;

      // if(!Flag_HBHENoiseFilter) continue;
      // if(!Flag_goodVertices) continue;
      // if(!Flag_EcalDeadCellTriggerPrimitiveFilter) continue;
      // if(!Flag_eeBadScFilter) continue;
      
      // fill the histos
      if (!hasSignal || i>0) {
	histMRAllBkg->Fill(MR, intLumi*weight);
	histRsqAllBkg->Fill(Rsq, intLumi*weight);
      }
            
      if(strstr(processLabels[i].c_str(), "TTJets")==NULL && strstr(processLabels[i].c_str(), "T1bbbb")==NULL)
      	histMRRsq[i]->Fill(MR, Rsq, intLumi*weight);
      
      // if(strstr(processLabels[i].c_str(), "T1bbbb")!=NULL)
      // 	histMRRsq[i]->Fill(MR, Rsq, intLumi*weight*2.69506e-07);
      
      histMR[i]->Fill(MR, intLumi*weight);
      histRsq[i]->Fill(Rsq, intLumi*weight);
      
      // separate by number of gen leptons for lepton boxes
      if(boxOption==1 || boxOption==2)
	{
	  if(strstr(processLabels[i].c_str(), "TTJets")!=NULL && strstr(bkgLabels[i].c_str(), "2L")!=NULL) {
	    if(nGenMuons+nGenElectrons>=2)
	      histMRRsq[i]->Fill(MR, Rsq, intLumi*weight);
	  }
	  else if(strstr(processLabels[i].c_str(), "TTJets")!=NULL && strstr(bkgLabels[i].c_str(), "Tau")!=NULL) {
	    if((nGenMuons+nGenElectrons+nGenTaus>=2) && !(nGenMuons+nGenElectrons>=2))
	      histMRRsq[i]->Fill(MR, Rsq, intLumi*weight);
	  }
	  else if(strstr(processLabels[i].c_str(), "TTJets")!=NULL && strstr(bkgLabels[i].c_str(), "1L")!=NULL) {
	    if(!(nGenMuons+nGenElectrons>=2) && !(nGenMuons+nGenElectrons+nGenTaus>=2))
	      histMRRsq[i]->Fill(MR, Rsq, intLumi*weight);
	  }
	}
      
	// Multijet box top
      	if(boxOption==0)
	  if(strstr(processLabels[i].c_str(), "TTJets")!=NULL) {
	    histMRRsq[i]->Fill(MR, Rsq, intLumi*weight);
	  }
      }

    inputFile->Close();
    delete inputFile;
  }
  
  //*******************************************************************************************
  //Draw Plots
  //*******************************************************************************************
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.7,0.53,0.90,0.88);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetFillStyle(0);

  for (Int_t i = histMRRsq.size()-1 ; i >= 0; --i) {
    if (hasSignal && i==0) {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "L");
    } else {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "F");
    }
  }

  THStack *stackUnrolled = new THStack();
  THStack *stackUnrolled2bins = new THStack();
  THStack *stackUnrolledPercentage = new THStack();
  THStack *stackUnrolledPercentage2bins = new THStack();

  float bintotal[nMRBins*nRsqBins] = {0.};

  // fill out the unrolled histograms 
  for (uint i=0; i < histMRRsq.size(); ++i) {
    
    int binN = 0;
    float total_SB = 0.;
    float total_SR = 0.;

    for(int ii = 0; ii<nMRBins; ii++)
      for (int jj = 0; jj<nRsqBins; jj++)      
  	{      
  	  float value = (histMRRsq[i]->GetBinContent(ii+1, jj+1) > 0) ? histMRRsq[i]->GetBinContent(ii+1, jj+1) : 0. ;
	  
	  float Xrange = histMRRsq[i]->GetXaxis()->GetBinLowEdge(ii+2) - histMRRsq[i]->GetXaxis()->GetBinLowEdge(ii+1);
	  float Yrange = histMRRsq[i]->GetYaxis()->GetBinLowEdge(jj+2) - histMRRsq[i]->GetYaxis()->GetBinLowEdge(jj+1);

	  float area =1.;
	  
	  if(density) area = Xrange*Yrange; //normalize each bin by its area

	  histUnrolled[i]->SetBinContent(binN+1, value/area);

	  if(!hasSignal || i>0)
	    bintotal[binN+1] += value/area;	 
	  
	  if(ii<1 || jj<1)
	    total_SB += value/area;
	  else
	    total_SR += value/area;
	  	  
  	  binN++;
  	}

    histUnrolled2bins[i]->SetBinContent(1, total_SB);
    histUnrolled2bins[i]->SetBinContent(2, total_SR);

    histUnrolled[i]->SetMinimum(0.00001);

    if ( histUnrolled[i]->Integral() > 0) {
      if( !hasSignal || i > 0 )
	stackUnrolled->Add(histUnrolled[i]);
    }

    if ( histUnrolled[i]->Integral() > 0) {
      if( !hasSignal || i > 0 )
	stackUnrolled2bins->Add(histUnrolled2bins[i]);
    }

    cout << "Process : " << processLabels[i] << "\n";	  
  }


  // Unroll into two bins for fractions
  float AllBkg_SB = 0;
  float AllBkg_SR = 0;

  for (uint i=0; i < histMRRsq.size(); ++i) {
    if( !hasSignal || i > 0 ){
      AllBkg_SB += histUnrolled2bins[i]->GetBinContent(1);
      AllBkg_SR += histUnrolled2bins[i]->GetBinContent(2);
    }
  }

  for (uint i=0; i < histMRRsq.size(); ++i) {
    if( !hasSignal || i > 0 ){
      histUnrolledPercentage2bins[i]->SetBinContent(1, histUnrolled2bins[i]->GetBinContent(1)/AllBkg_SB);
      histUnrolledPercentage2bins[i]->SetBinContent(2, histUnrolled2bins[i]->GetBinContent(2)/AllBkg_SR);
    }
    
    if ( histUnrolled2bins[i]->Integral() > 0) {
      if( !hasSignal || i > 0 )
	stackUnrolledPercentage2bins->Add(histUnrolledPercentage2bins[i]);
    }
  }
  
  ///
  // fill out the unrolled percentage histograms 
  for (uint i=0; i < histMRRsq.size(); ++i) {
    if( hasSignal && i == 0 ) continue;
      
    int binN = 0;

    for(int ii = 0; ii<nMRBins; ii++)
      for (int jj = 0; jj<nRsqBins; jj++)      
  	{      
  	  float value = (histMRRsq[i]->GetBinContent(ii+1, jj+1) > 0) ? histMRRsq[i]->GetBinContent(ii+1, jj+1) : 0. ;
	  
	  float Xrange = histMRRsq[i]->GetXaxis()->GetBinLowEdge(ii+2) - histMRRsq[i]->GetXaxis()->GetBinLowEdge(ii+1);
	  float Yrange = histMRRsq[i]->GetYaxis()->GetBinLowEdge(jj+2) - histMRRsq[i]->GetYaxis()->GetBinLowEdge(jj+1);

	  float area =1.;
	  
	  if(density) area = Xrange*Yrange; //normalize each bin by its area

	  if(bintotal[binN+1]>0)
	    histUnrolledPercentage[i]->SetBinContent(binN+1, (value/area)/bintotal[binN+1]);

	  binN++;
	}
		
    if ( histUnrolled[i]->Integral() > 0) {
	stackUnrolledPercentage->Add(histUnrolledPercentage[i]);
    }

    cout << "Unrolling Percentage for Process : " << processLabels[i] << "\n";	  
  }

  /// Unrolled plots in bins of R&MR
  TLatex t1(0.1,0.92, "CMS Preliminary");
  TLatex t2(0.6,0.92, "#sqrt{s}=13 TeV, L = 2 fb^{-1}");
  TLatex t3(0.4,0.92, Form("%s",latexlabel.c_str()) );
  t1.SetNDC();
  t2.SetNDC();
  t3.SetNDC();
  t1.SetTextSize(0.05);
  t2.SetTextSize(0.05);
  t3.SetTextSize(0.02);
  t1.SetTextFont(42);
  t2.SetTextFont(42);
  t3.SetTextFont(42);

  stackUnrolled->Draw();
  stackUnrolled->SetMinimum(0.0001);
  // stackUnrolled->SetMaximum(1000);
  cv->SetLogy();
  stackUnrolled->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackUnrolled->GetHists()->At(0)))->GetXaxis()->GetTitle());
  stackUnrolled->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackUnrolled->GetHists()->At(0)))->GetYaxis()->GetTitle());
  stackUnrolled->Draw();
  if(hasSignal) histUnrolled[0]->Draw("same hist");
  legend->Draw();
  t1.Draw();
  t2.Draw();
  t3.Draw();
  cv->SaveAs(Form("Unrolled%s.pdf",Label.c_str()));

  // Unrolled plots in percentages
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.85,0.20,0.95,0.80);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);

  for (Int_t i = histMRRsq.size()-1 ; i >= 0; --i) {
    if (hasSignal && i==0) {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "L");
    } else {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "F");
    }
  }
  stackUnrolledPercentage->Draw();
  stackUnrolledPercentage->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackUnrolledPercentage->GetHists()->At(0)))->GetXaxis()->GetTitle());
  // stackUnrolledPercentage->GetHistogram()->GetXaxis()->SetRangeUser(0, 35);
  stackUnrolledPercentage->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackUnrolledPercentage->GetHists()->At(0)))->GetYaxis()->GetTitle());
  if(hasSignal) histUnrolledPercentage[0]->Draw("same hist"); 
  legend->Draw();
  t1.Draw();
  t2.Draw();
  t3.Draw();
  cv->SaveAs(Form("UnrolledPercentage%s.pdf",Label.c_str()));

  // Unrolled plots in sideband vs signal box
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.85,0.20,0.95,0.80);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);

  for (Int_t i = histMRRsq.size()-1 ; i >= 0; --i) {
    if (hasSignal && i==0) {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "L");
    } else {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "F");
    }
  }
  stackUnrolled2bins->Draw();
  stackUnrolled2bins->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackUnrolled2bins->GetHists()->At(0)))->GetXaxis()->GetTitle());
  stackUnrolled2bins->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackUnrolled2bins->GetHists()->At(0)))->GetYaxis()->GetTitle());
  if(hasSignal) histUnrolled2bins[0]->Draw("same hist");
  legend->Draw();
  t1.Draw();
  t2.Draw();
  t3.Draw();
  cv->SaveAs(Form("Unrolled2bins%s.pdf",Label.c_str()));

  // Unrolled plots in sideband vs signal box in fractions
  cv = new TCanvas("cv","cv", 800,600);
  legend = new TLegend(0.7,0.23,0.90,0.88);
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);

  for (Int_t i = histMRRsq.size()-1 ; i >= 0; --i) {
    if (hasSignal && i==0) {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "L");
    } else {
      legend->AddEntry(histMRRsq[i],processLabels[i].c_str(), "F");
    }
  }

  stackUnrolledPercentage2bins->Draw();
  stackUnrolledPercentage2bins->GetHistogram()->GetXaxis()->SetTitle(((TH1F*)(stackUnrolledPercentage2bins->GetHists()->At(0)))->GetXaxis()->GetTitle());
  stackUnrolledPercentage2bins->GetHistogram()->GetYaxis()->SetTitle(((TH1F*)(stackUnrolledPercentage2bins->GetHists()->At(0)))->GetYaxis()->GetTitle());
  stackUnrolledPercentage2bins->GetHistogram()->GetXaxis()->SetBinLabel(1, "Sideband");
  stackUnrolledPercentage2bins->GetHistogram()->GetXaxis()->SetBinLabel(2, "Signal Sensitive Region");
  if(hasSignal) histUnrolledPercentage2bins[0]->Draw("same hist");
  legend->Draw();
  t1.Draw();
  t2.Draw();
  t3.Draw();
  cv->SaveAs(Form("UnrolledPercentage2bins%s.pdf",Label.c_str()));


   //--------------------------------------------------------------------------------------------------------------
  // Output
  //==============================================================================================================
  TFile *file = TFile::Open(("RazorPlots"+Label+".root").c_str(), "RECREATE");
  file->cd();

  for(int i=0; i<int(inputfiles.size()); i++) {
    file->WriteTObject(histMR[i], Form("histMR_%s",processLabels[i].c_str()), "WriteDelete");
    file->WriteTObject(histRsq[i], Form("histRsq_%s",processLabels[i].c_str()), "WriteDelete");
    file->WriteTObject(histMRRsq[i], Form("histMRRsq_%s",processLabels[i].c_str()), "WriteDelete");
    histUnrolled[i]->Write();  
    histUnrolled2bins[i]->Write();  
    histUnrolledPercentage[i]->Write();  
    histUnrolledPercentage2bins[i]->Write();  
  }
  
  stackUnrolled->Write();
  stackUnrolled2bins->Write();
  stackUnrolledPercentage->Write();
  stackUnrolledPercentage2bins->Write();
 }
void drawData( RooWorkspace *w ) {

  w->var("B_s0_DTF_B_s0_M")->setBins(100);

  TH1 *Data              = w->data("Data")->createHistogram( "Data", *w->var("B_s0_DTF_B_s0_M") );
  Data->SetLineWidth(2);
  Data->SetLineColor(kBlack);

  TH1 *Data2011          = w->data("Data2011")->createHistogram( "Data2011", *w->var("B_s0_DTF_B_s0_M") );
  Data2011->SetLineWidth(4);
  Data2011->SetLineColor(kBlue);
  Data2011->SetFillColor(0);
  Data2011->SetFillStyle(0);

  TH1 *Data2012          = w->data("Data2012")->createHistogram( "Data2012", *w->var("B_s0_DTF_B_s0_M") );
  Data2012->SetLineWidth(4);
  Data2012->SetLineColor(kRed);
  Data2012->SetFillColor(0);
  Data2012->SetFillStyle(0);

  int col1 = TColor::GetColor( "#b2e2e2" );
  int col2 = TColor::GetColor( "#66c2a4" );
  int col3 = TColor::GetColor( "#2ca25f" );
  int col4 = TColor::GetColor( "#006d2c" );

  TH1 *Data2011HadronTOS = w->data("Data2011HadronTOS")->createHistogram( "Data2011HadronTOS", *w->var("B_s0_DTF_B_s0_M") );
  Data2011HadronTOS->SetLineColor(col1);
  Data2011HadronTOS->SetFillColor(col1);

  TH1 *Data2011GlobalTIS = w->data("Data2011GlobalTIS")->createHistogram( "Data2011GlobalTIS", *w->var("B_s0_DTF_B_s0_M") );
  Data2011GlobalTIS->SetLineColor(col2);
  Data2011GlobalTIS->SetFillColor(col2);

  TH1 *Data2012HadronTOS = w->data("Data2012HadronTOS")->createHistogram( "Data2012HadronTOS", *w->var("B_s0_DTF_B_s0_M") );
  Data2012HadronTOS->SetLineColor(col3);
  Data2012HadronTOS->SetFillColor(col3);

  TH1 *Data2012GlobalTIS = w->data("Data2012GlobalTIS")->createHistogram( "Data2012GlobalTIS", *w->var("B_s0_DTF_B_s0_M") );
  Data2012GlobalTIS->SetLineColor(col4);
  Data2012GlobalTIS->SetFillColor(col4);


  THStack *hsData = new THStack("DataHs","");
  hsData->Add( Data2011HadronTOS );
  hsData->Add( Data2011GlobalTIS );
  hsData->Add( Data2012HadronTOS );
  hsData->Add( Data2012GlobalTIS );

  TH1 *DataYears = (TH1*)Data2011->Clone("DataYears");
  DataYears->Add( Data2012 );
  DataYears->SetLineColor(kRed);
  DataYears->SetLineWidth(4);

  TLegend *leg = new TLegend(0.6,0.4,0.89,0.89);
  leg->SetFillColor(0);
  leg->AddEntry( Data2011HadronTOS, "2011 Hadron TOS", "F" );
  leg->AddEntry( Data2011GlobalTIS, "2011 Global TIS", "F" );
  leg->AddEntry( Data2012HadronTOS, "2012 Hadron TOS", "F" );
  leg->AddEntry( Data2012GlobalTIS, "2012 Global TIS", "F" );
  leg->AddEntry( Data2011, "2011" , "L" );
  leg->AddEntry( DataYears, "2012" , "L" );
  leg->AddEntry( Data, "All", "L" );

  TCanvas *c = new TCanvas();
  hsData->Draw("HISTF");
  DataYears->Draw("HISTsame");
  Data2011->Draw("HISTsame");
  Data->Draw("HISTsame");
  leg->Draw("same");

  hsData->GetHistogram()->GetXaxis()->SetTitle("m(K^{+}#pi^{-}K^{-}#pi^{+}) [MeV]");
  hsData->GetHistogram()->GetYaxis()->SetTitle("Events / ( 8 MeV )");
  hsData->GetHistogram()->GetXaxis()->SetTitleOffset(0.8);
  hsData->GetHistogram()->GetYaxis()->SetTitleOffset(0.9);
  hsData->GetHistogram()->GetXaxis()->SetTitleSize(0.08);
  hsData->GetHistogram()->GetYaxis()->SetTitleSize(0.08);

  c->Update();
  c->Modified();
  c->Print("plots/DataSets.pdf");
}
//------------------------------------------------------------------------------
void PlotAlignmentValidation::plotSS( const std::string& options, const std::string& residType )
{
  if (residType == "") {
    plotSS( options, "ResXvsXProfile");
    plotSS( options, "ResXvsYProfile");
    return;
  }

  int plotLayerN = 0;
  //  int plotRingN  = 0;
  //  bool plotPlain = false;
  bool plotLayers = false;  // overrides plotLayerN
  //  bool plotRings  = false;  // Todo: implement this?
  bool plotSplits = false;
  int plotSubDetN = 0;     // if zero, plot all

  TRegexp layer_re("layer=[0-9]+");
  Ssiz_t index, len;
  if (options.find("split") != std::string::npos) { plotSplits = true; }
  if (options.find("layers") != std::string::npos) { plotLayers = true; }
  if ((index = layer_re.Index(options, &len)) != -1) {
    if (plotLayers) {
      std::cerr << "Warning: option 'layers' overrides 'layer=N'" << std::endl;
    } else {
      std::string substr = options.substr(index+6, len-6);
      plotLayerN = atoi(substr.c_str());
    }
  }

  TRegexp subdet_re("subdet=[1-6]+");
  if ((index = subdet_re.Index(options, &len)) != -1) {
    std::string substr = options.substr(index+7, len-7);
    plotSubDetN = atoi(substr.c_str());
  }

  // If layers are plotted, these are the numbers of layers for each subdetector
  static int numberOfLayers[6] = { 3, 2, 4, 3, 6, 9 };

  setNiceStyle(); 
  gStyle->SetOptStat(0);
  
  TCanvas c("canv", "canv", 600, 600);
  setCanvasStyle( c );

  // todo: title, min/max, nbins?

  // Loop over detectors
  for (int iSubDet=1; iSubDet<=6; ++iSubDet) {

    // TEC requires special care since rings 1-4 and 5-7 are plotted separately
    bool isTEC = (iSubDet==6);

    // if subdet is specified, skip other subdets
    if (plotSubDetN!=0 && iSubDet!=plotSubDetN)
      continue;

    // Skips plotting too high layers
    if (plotLayerN > numberOfLayers[iSubDet-1]) {
      continue;
    }

    int minlayer = plotLayers ? 1 : plotLayerN;
    int maxlayer = plotLayers ? numberOfLayers[iSubDet-1] : plotLayerN;
    
    for (int layer = minlayer; layer <= maxlayer; layer++) {

      // two plots for TEC, skip first 
      for (int iTEC = 0; iTEC<2; iTEC++) {
	if (!isTEC && iTEC==0) continue;
	
	char  selection[1000];
	if (!isTEC){
	  if (layer==0)
	    sprintf(selection,"subDetId==%d",iSubDet); 
	  else
	    sprintf(selection,"subDetId==%d && layer == %d",iSubDet,layer); 
	}
	else{	  // TEC
	  if (iTEC==0)  // rings 
	    sprintf(selection,"subDetId==%d && ring <= 4",iSubDet); 
	  else
	    sprintf(selection,"subDetId==%d && ring > 4",iSubDet); 
	}


	// Title for plot and name for the file

	TString subDetName;
	switch (iSubDet) {
	case 1: subDetName = "BPIX"; break;
	case 2: subDetName = "FPIX"; break;
	case 3: subDetName = "TIB"; break;
	case 4: subDetName = "TID"; break;
	case 5: subDetName = "TOB"; break;
	case 6: subDetName = "TEC"; break;
	}

	TString myTitle = "Surface Shape, ";
	myTitle += subDetName;
	if (layer!=0) {
	  myTitle += TString(", layer ");
	  myTitle += Form("%d",layer); 
	}
	if (isTEC && iTEC==0)
	  myTitle += TString(" R1-4");
	if (isTEC && iTEC>0)
	  myTitle += TString(" R5-7");

	// Save plot to file
	std::ostringstream plotName;
	plotName << outputDir << "/SurfaceShape_" << subDetName << "_";
	plotName << residType; 
	if (layer!=0)
	  plotName << "_" << "layer" << layer;
	if (isTEC && iTEC==0)
	  plotName << "_" << "R1-4";
	if (isTEC && iTEC>0)
	  plotName << "_" << "R5-7";
	plotName << ".eps";

	// Generate histograms with selection
	THStack *hs = addHists(selection, residType);
	if (!hs || hs->GetHists()==0 || hs->GetHists()->GetSize()==0) {
	  std::cout << "No histogram for " << subDetName << ", perhaps not enough data?" << std::endl; 
	  continue; 
	}
	hs->SetTitle( myTitle ); 
	hs->Draw("nostack PE");  

	// Adjust Labels
	TH1* firstHisto = (TH1*) hs->GetHists()->First();
	TString xName = firstHisto->GetXaxis()->GetTitle();
	TString yName = firstHisto->GetYaxis()->GetTitle();
	hs->GetHistogram()->GetXaxis()->SetTitleColor( kBlack ); 
	hs->GetHistogram()->GetXaxis()->SetTitle( xName ); 
	hs->GetHistogram()->GetYaxis()->SetTitleColor( kBlack ); 
	hs->GetHistogram()->GetYaxis()->SetTitle( yName ); 

	// Save to file
	c.Update(); 
	c.Print(plotName.str().c_str());
      }
    }
  }

  return;
}
示例#20
0
/////////////////
// MAIN SCRIPT //
/////////////////
void paperConvert() {
    gStyle->SetHistLineWidth(2);
    gStyle->SetOptStat("");
    TH1::SetDefaultSumw2();
    TCanvas *c1 = new TCanvas("c1", "c1",10,32,700,500);
    gStyle->SetOptStat(0);

    // For centralised hist with no title, legend inside plot
    c1->Range(-1.705566,0.8486743,10.78995,1.08077);
    c1->SetFillColor(0);
    c1->SetBorderMode(0);
    c1->SetBorderSize(2);
    c1->SetTickx(1);
    c1->SetTicky(1);
    c1->SetLeftMargin(0.1364942);
    c1->SetRightMargin(0.06321839);
    c1->SetTopMargin(0.07415254);
    c1->SetBottomMargin(0.1271186);
    c1->SetFrameBorderMode(0);
    c1->SetFrameBorderMode(0);

    TFile *f_sig_main1 = TFile::Open("Signal_1prong_HLT_bare/output_main_bare_sig_muRand_HLT_dR1.root", "READ");
    TFile *f_sig_main2 = TFile::Open("Signal_1prong_HLT_bare/output_main_bare_sig_muRand_HLT_dR2.root", "READ");
    TFile *f_sig_mass1 = TFile::Open("Signal_1prong_HLT_bare/output_bare_sig_muRand_HLT_dR1.root", "READ");
    TFile *f_sig_mass2 = TFile::Open("Signal_1prong_HLT_bare/output_bare_sig_muRand_HLT_dR2.root", "READ");
    TFile *f_bg_main1 = TFile::Open("QCDb_HLT_bare/output_main_bare_bg_muRand_HLT_dR1.root", "READ");
    // TFile *f_bg_main2 = TFile::Open("QCDb_HLT_bare/output_main_bare_bg_muRand_HLT_dR2.root", "READ");
    TFile *f_bg_main2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_noDz_dR2.root", "READ");

    // TFile *f_bg_mass1 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_dR1.root", "READ");
    // TFile *f_bg_mass1 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_1912_dR1.root", "READ");
    TFile *f_bg_mass1 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_1912IPopt2_dR1.root", "READ");
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_dR2.root", "READ"); //normal
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_looseIsoAndTau_dR2.root", "READ");
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_IPiso0p5_dR2.root", "READ");
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_1912_dR2.root", "READ");
    TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_1912IPopt2_dR2.root", "READ");
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_noDz_dR2.root", "READ");
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_IPopt2_dR2.root", "READ");
    // TFile *f_bg_mass2 = TFile::Open("QCDb_HLT_bare/output_bare_bg_muRand_HLT_IPopt3_dR2.root", "READ");

    TFile *f_scatter_main1 = TFile::Open("QCDbcScatter_HLT_bare/output_main_bare_bg_muRand_HLT_dR1.root", "READ");
    TFile *f_scatter_main2 = TFile::Open("QCDbcScatter_HLT_bare/output_main_bare_bg_muRand_HLT_dR2.root", "READ");
    TFile *f_scatter_mass1 = TFile::Open("QCDbcScatter_HLT_bare/output_bare_bg_muRand_HLT_dR1.root", "READ");
    TFile *f_scatter_mass2 = TFile::Open("QCDbcScatter_HLT_bare/output_bare_bg_muRand_HLT_dR2.root", "READ");

    // TString dir("normal");
    // TString dir("looseIsolooseTau");
    // TString dir("IPiso0p5");
    // TString dir("1912");
    TString dir("1912IPopt2");
    // TString dir("IPopt2");
    // TString dir("noDz");

    ///////////////////
    // 1D MASS PLOTS //
    ///////////////////

    ////////////////
    // Signal region plots
    ////////////////
    std::vector<TFile*> filesdR2;
    filesdR2.push_back(f_bg_mass2);
    filesdR2.push_back(f_scatter_mass2);

    TPaveText* t_signal = new TPaveText(0.6, 0.47, 0.85, 0.58, "NDC");
    t_signal->AddText("Signal region");
    t_signal->SetFillColor(kWhite);
    t_signal->SetBorderSize(0);
    
    TPaveText* t_side = new TPaveText(0.6, 0.47, 0.84, 0.57, "NDC");
    t_side->AddText("Control region B");
    t_side->SetFillColor(kWhite);
    t_side->SetBorderSize(0);

    // bbbar only
    TH1D* hM1_bare_bg_muRand_HLT_dR2 = (TH1D*) f_bg_mass2->Get("hM1");
    TH1D* hM2_bare_bg_muRand_HLT_dR2 = (TH1D*) f_bg_mass2->Get("hM2");
    TH1D* hM_bare_bg_muRand_HLT_dR2 = (TH1D*)hM1_bare_bg_muRand_HLT_dR2->Clone();
    hM_bare_bg_muRand_HLT_dR2->Add(hM2_bare_bg_muRand_HLT_dR2);
    normaliseHist(hM_bare_bg_muRand_HLT_dR2); // as we added m1 + m2
    setMassAUTitles(hM_bare_bg_muRand_HLT_dR2);
    doBGHist(hM_bare_bg_muRand_HLT_dR2);
    setAltTitleLabelSizes(hM_bare_bg_muRand_HLT_dR2);
    hM_bare_bg_muRand_HLT_dR2->Draw("HISTE");
    t_signal->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_bare_bg_muRand_HLT_dR2.pdf");

    std::vector<double> scalingFactors;
    scalingFactors.push_back(1.7649);
    scalingFactors.push_back(2.6577);

    // // bbbar + scatter
    TH1D* hM1_bg_dR2 = combineRebin10bins(filesdR2, "hM1_unnormalised", scalingFactors);
    TH1D* hM2_bg_dR2 = combineRebin10bins(filesdR2, "hM2_unnormalised", scalingFactors);
    TH1D* hM_bg_dR2 = (TH1D*) hM1_bg_dR2->Clone() ;
    hM_bg_dR2->Add(hM2_bg_dR2);
    normaliseHist(hM_bg_dR2);
    setMassAUTitles(hM_bg_dR2);
    doBGHist(hM_bg_dR2);
    setAltTitleLabelSizes(hM_bg_dR2);
    hM_bg_dR2->Draw("HISTE");
    t_signal->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_bare_bg_both_muRand_HLT_dR2.pdf");

    // signal
    TH1D* hM1_bare_sig_muRand_HLT_dR2 = (TH1D*) f_sig_mass2->Get("hM1");
    TH1D* hM2_bare_sig_muRand_HLT_dR2 = (TH1D*) f_sig_mass2->Get("hM2");
    TH1D* hM_bare_sig_muRand_HLT_dR2 = (TH1D*)hM1_bare_sig_muRand_HLT_dR2->Clone();
    hM_bare_sig_muRand_HLT_dR2->Add(hM2_bare_sig_muRand_HLT_dR2);
    normaliseHist(hM_bare_sig_muRand_HLT_dR2);
    setMassAUTitles(hM_bare_sig_muRand_HLT_dR2);
    doSignalHist(hM_bare_sig_muRand_HLT_dR2);
    setAltTitleLabelSizes(hM_bare_sig_muRand_HLT_dR2);
    hM_bare_sig_muRand_HLT_dR2->Draw("HISTE");
    t_signal->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_bare_sig_muRand_HLT_dR2.pdf");


    // bbbar + signal
    THStack* st = new THStack("st","");
    st->Add(hM_bare_bg_muRand_HLT_dR2);
    st->Add(hM_bare_sig_muRand_HLT_dR2);
    TLegend* l = new TLegend(0.67, 0.67, 0.88, 0.88);
    l->AddEntry(hM_bare_bg_muRand_HLT_dR2, "QCD b#bar{b} MC", "lp");
    l->AddEntry(hM_bare_sig_muRand_HLT_dR2, "#splitline{Signal MC}{m_{#phi} = 8 GeV}", "lp");
    doStandardLegend(l);
    st->Draw("NOSTACK HISTE");
    setMassAUTitles(st->GetHistogram());
    setAltTitleLabelSizes(st->GetHistogram());    
    l->Draw();
    t_signal->Draw();

    c1->SaveAs("Combined/"+dir+"/M_10bins_bare_both_muRand_HLT_dR2.pdf");

    // bbbar + scatter + signal
    THStack* st_all = new THStack("st_all","");
    st_all->Add(hM_bg_dR2);
    st_all->Add(hM_bare_sig_muRand_HLT_dR2);
    TLegend* l_all = new TLegend(0.52,0.62,0.86,0.89);
    l_all->AddEntry(hM_bg_dR2,"Gen. level QCD MC","lp");
    l_all->AddEntry((TObject*)0,"(b#bar{b} + q-g scatter,",""); //null pointers for blank entries
    l_all->AddEntry((TObject*)0,"q = b, #bar{b}, c, #bar{c})","");
    l_all->AddEntry(hM_bare_sig_muRand_HLT_dR2, "Signal MC", "lp");
    l_all->AddEntry((TObject*)0,"m_{#phi} = 8 GeV", "");
    doStandardLegend(l_all);
    st_all->Draw("NOSTACKHISTE");
    setMassAUTitles(st_all->GetHistogram());
    setAltTitleLabelSizes(st_all->GetHistogram());    
    l_all->Draw();
    t_signal->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_bare_allMC_muRand_HLT_dR2.pdf");

    
    ////////////
    // sideband plots
    ////////////
    
    std::vector<TFile*> filesdR1;
    filesdR1.push_back(f_bg_mass1);
    filesdR1.push_back(f_scatter_mass1);

    // bbbar
    TH1D* hM1_side_bg_muRand_HLT_dR1 = (TH1D*) f_bg_mass1->Get("hM1_side_1to2p5");
    hM1_side_bg_muRand_HLT_dR1->Rebin(5);
    TH1D* hM2_side_bg_muRand_HLT_dR1 = (TH1D*) f_bg_mass1->Get("hM2_side_1to2p5");
    hM2_side_bg_muRand_HLT_dR1->Rebin(5);
    TH1D* hM_side_bg_muRand_HLT_dR1 = (TH1D*)hM1_side_bg_muRand_HLT_dR1->Clone();
    hM_side_bg_muRand_HLT_dR1->Add(hM2_side_bg_muRand_HLT_dR1);
    normaliseHist(hM_side_bg_muRand_HLT_dR1);
    setMassAUTitles(hM_side_bg_muRand_HLT_dR1);
    doBGHist(hM_side_bg_muRand_HLT_dR1);
    setAltTitleLabelSizes(hM_side_bg_muRand_HLT_dR1);
    hM_side_bg_muRand_HLT_dR1->Draw("HISTE");
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_side_bg_muRand_HLT_dR1.pdf");

    // // bbbar + scatter
    TH1D* hM1_side_bg_dR1 = combineRebin10bins(filesdR1, "hM1_side_1to2p5_unnormalised", scalingFactors);
    TH1D* hM2_side_bg_dR1 = combineRebin10bins(filesdR1, "hM1_side_1to2p5_unnormalised", scalingFactors);
    TH1D* hM_side_bg_dR1 = (TH1D*) hM1_side_bg_dR1->Clone();
    hM_side_bg_dR1->Add(hM2_side_bg_dR1);
    normaliseHist(hM_side_bg_dR1);
    setMassAUTitles(hM_side_bg_dR1);
    doBGHist(hM_side_bg_dR1);
    setAltTitleLabelSizes(hM_side_bg_dR1);
    hM_side_bg_dR1->Draw("HISTE");
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_side_bg_both_muRand_HLT_dR1.pdf");

    // signal
    TH1D* hM1_side_sig_muRand_HLT_dR1 = (TH1D*) f_sig_mass1->Get("hM1_side_1to2p5");
    hM1_side_sig_muRand_HLT_dR1->Rebin(5);
    TH1D* hM2_side_sig_muRand_HLT_dR1 = (TH1D*) f_sig_mass1->Get("hM2_side_1to2p5");
    hM2_side_sig_muRand_HLT_dR1->Rebin(5);
    TH1D* hM_side_sig_muRand_HLT_dR1 = (TH1D*)hM1_side_sig_muRand_HLT_dR1->Clone();
    hM_side_sig_muRand_HLT_dR1->Add(hM2_side_sig_muRand_HLT_dR1);
    normaliseHist(hM_side_sig_muRand_HLT_dR1);
    setMassAUTitles(hM_side_sig_muRand_HLT_dR1);
    doSignalHist(hM_side_sig_muRand_HLT_dR1);
    setAltTitleLabelSizes(hM_side_sig_muRand_HLT_dR1);
    hM_side_sig_muRand_HLT_dR1->Draw("HISTE");
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_side_sig_muRand_HLT_dR1.pdf");

    // bbar + signal
    THStack* st_side = new THStack("st_side","");
    st_side->Add(hM_side_bg_muRand_HLT_dR1);
    st_side->Add(hM_side_sig_muRand_HLT_dR1);
    st_side->Draw("NOSTACK HISTE");
    setMassAUTitles(st_side->GetHistogram());
    setAltTitleLabelSizes(st_side->GetHistogram());    
    l->Draw();
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_side_both_muRand_HLT_dR1.pdf");
    
    // bbar + scatter + signal
    THStack* st_side_all = new THStack("st_side_all","");
    st_side_all->Add(hM_side_bg_dR1);
    st_side_all->Add(hM_side_sig_muRand_HLT_dR1);
    st_side_all->Draw("NOSTACK HISTE");
    setMassAUTitles(st_side_all->GetHistogram());
    setAltTitleLabelSizes(st_side_all->GetHistogram());    
    l_all->Draw();
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/M_10bins_side_allMC_muRand_HLT_dR1.pdf");


    ///////////////////////
    // CORRELATION PLOTS //
    ///////////////////////
    //signal mc
    TH1D* hCorr_bare_sig = (TH1D*) f_sig_mass2->Get("hCorr1D");
    TH1D* hCorr_side_sig = (TH1D*) f_sig_mass1->Get("hCorr1D_side_1to2p5");
    //bbbar
    TH1D* hCorr_bare_b = (TH1D*) f_bg_mass2->Get("hCorr1D");
    // TH1D* hCorr_bare_b = (TH1D*) f_bg_mass2->Get("hCorr1D_loosetau");
    TH1D* hCorr_side_b = (TH1D*) f_bg_mass1->Get("hCorr1D_side_1to2p5");
    
    TH1D* hM1D_bare_b_unnormalised = (TH1D*) f_bg_mass2->Get("hM_unnormalised"); // signal region
    TH2D* hM2D_bare_b_unnormalised = (TH2D*) f_bg_mass2->Get("hM1vsM2_unnormalised");
    
    TH1D* hM1D_side_b_unnormalised = (TH1D*) f_bg_mass1->Get("hM_side_1to2p5_unnormalised"); //sideband
    TH2D* hM2D_side_b_unnormalised = (TH2D*) f_bg_mass1->Get("hM1vsM2_side_1to2p5_unnormalised");
    
    // scatter
    TH1D* hCorr_bare_scatter = (TH1D*) f_scatter_mass2->Get("hCorr1D");
    TH1D* hCorr_side_scatter = (TH1D*) f_scatter_mass1->Get("hCorr1D_side_1to2p5");
    
    TH1D* hM1D_bare_scatter_unnormalised = (TH1D*) f_scatter_mass2->Get("hM_unnormalised"); //signal region
    TH2D* hM2D_bare_scatter_unnormalised = (TH2D*) f_scatter_mass2->Get("hM1vsM2_unnormalised");
    
    TH1D* hM1D_side_scatter_unnormalised = (TH1D*) f_scatter_mass1->Get("hM_side_1to2p5_unnormalised"); //sideband
    TH2D* hM2D_side_scatter_unnormalised = (TH2D*) f_scatter_mass1->Get("hM1vsM2_side_1to2p5_unnormalised");
    
    t_signal = new TPaveText(0.15, 0.7, 0.4, 0.8, "NDC");
    t_signal->AddText("Signal region");
    t_signal->SetFillColor(kWhite);
    t_signal->SetBorderSize(0);

    t_side = new TPaveText(0.15, 0.7, 0.4, 0.8, "NDC");
    t_side->AddText("Control region B");
    t_side->SetFillColor(kWhite);
    t_side->SetBorderSize(0);

    // set title sizes, titles, max, min, etc
    setTitleLabelSizes(hCorr_bare_sig);
    doSignalHist(hCorr_bare_sig);
    setCorrTitlesMaxMin(hCorr_bare_sig);
    
    setTitleLabelSizes(hCorr_side_sig);
    doSignalHist(hCorr_side_sig);
    setCorrTitlesMaxMin(hCorr_side_sig);

    setTitleLabelSizes(hCorr_bare_b);
    doBGHist(hCorr_bare_b);
    setCorrTitlesMaxMin(hCorr_bare_b);

    setTitleLabelSizes(hCorr_side_b);
    doBGHist(hCorr_side_b);
    setCorrTitlesMaxMin(hCorr_side_b);

    setTitleLabelSizes(hCorr_bare_scatter);
    doAltBGHist(hCorr_bare_scatter);
    setCorrTitlesMaxMin(hCorr_bare_scatter);
    
    setTitleLabelSizes(hCorr_side_scatter);
    doAltBGHist(hCorr_side_scatter);
    setCorrTitlesMaxMin(hCorr_side_scatter);
    
    TLine line(0,1,10,1);
    line.SetLineStyle(2);
    line.SetLineColor(12);
    line.SetLineWidth(2);

    c1->SetTicks(1,1);
    
    TLegend* l_bonly = new TLegend(0.6, 0.82, 0.88, 0.88);
    l_bonly->AddEntry(hCorr_bare_b, "QCD b#bar{b} MC", "lp");
    doStandardLegend(l_bonly);
    
    ///////////////////
    // signal region //
    ///////////////////

    // signal MC by itself
    hCorr_bare_sig->Draw();
    line.Draw();
    t_signal->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_bare_sig.pdf");
    
    // bbbar qcd by itself
    std::cout << "bbbar QCD MC in signal region:" << std::endl;
    printBinContents(hCorr_bare_b);
    hCorr_bare_b->Draw();
    line.Draw();
    t_signal->Draw();
    l_bonly->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_bare_b.pdf");
    c1->SaveAs("Combined/"+dir+"/Corr_bare_b.png");
    
    // bbbar + signal
    hCorr_bare_b->Draw();
    hCorr_bare_sig->Draw("SAME");
    line.Draw();
    l->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_bare_b_sig.pdf");


    // make combined corr plot for both qcd
    std::vector<TH1D*> bare_bg_hists1D;
    bare_bg_hists1D.push_back(hM1D_bare_b_unnormalised);
    bare_bg_hists1D.push_back(hM1D_bare_scatter_unnormalised);
    TH1D* hM1D_bare_bg = combineScale(bare_bg_hists1D, scalingFactors);
    
    std::vector<TH2D*> bare_bg_hists2D;
    bare_bg_hists2D.push_back(hM2D_bare_b_unnormalised);
    bare_bg_hists2D.push_back(hM2D_bare_scatter_unnormalised);
    TH2D* hM2D_bare_bg = combineScale(bare_bg_hists2D, scalingFactors);
    TH1D* hCorr_bare_bg = createCorrelationPlot(hM2D_bare_bg, hM1D_bare_bg);

    // both QCD summed together
    doBGHist(hCorr_bare_bg);
    setTitleLabelSizes(hCorr_bare_bg);
    setCorrTitlesMaxMin(hCorr_bare_bg);
    hCorr_bare_bg->Draw();
    line.Draw();
    t_signal->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_bare_bg.pdf");
    
    // all qcd + signal mc
    hCorr_bare_sig->Draw("SAME");
    l_all->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_bare_bg_sig.pdf");

    //////////////////////
    // control region B //
    //////////////////////

    // signal MC by itself
    hCorr_side_sig->Draw();
    line.Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_sig.pdf");
    
    // bbbar qcd by itself
    std::cout << "bbbar QCD MC in control region:" << std::endl;
    printBinContents(hCorr_side_b);
    hCorr_side_b->Draw();
    line.Draw();
    l_bonly->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_b.pdf");
    c1->SaveAs("Combined/"+dir+"/Corr_side_b.png");

    // signal + bbbar together
    hCorr_side_sig->Draw();
    hCorr_side_b->Draw("SAME");
    line.Draw();
    l->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_b_sig.pdf");

    // make combined corr plot for both qcd
    std::vector<TH1D*> side_bg_hists1D;
    side_bg_hists1D.push_back(hM1D_side_b_unnormalised);
    side_bg_hists1D.push_back(hM1D_side_scatter_unnormalised);
    TH1D* hM1D_side_bg = combineScale(side_bg_hists1D, scalingFactors);
    
    std::vector<TH2D*> side_bg_hists2D;
    side_bg_hists2D.push_back(hM2D_side_b_unnormalised);
    side_bg_hists2D.push_back(hM2D_side_scatter_unnormalised);
    TH2D* hM2D_side_bg = combineScale(side_bg_hists2D, scalingFactors);
    TH1D* hCorr_side_bg = createCorrelationPlot(hM2D_side_bg, hM1D_side_bg);

    // both QCD summed together
    doBGHist(hCorr_side_bg);
    setTitleLabelSizes(hCorr_side_bg);
    setCorrTitlesMaxMin(hCorr_side_bg);
    hCorr_side_bg->Draw();
    line.Draw();
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_bg.pdf");
    
    // signal + both QCD
    hCorr_side_sig->Draw("SAME");
    l_all->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_all_MC.pdf");

    // QCD + data
    hCorr_side_bg->Draw();
    TH1D* hCorr_side_data = dataCorr_side();
    doDataHist(hCorr_side_data);
    setCorrTitlesMaxMin(hCorr_side_data);
    hCorr_side_data->Draw("SAME");
    line.Draw();
    
    TLegend* l_all_data = new TLegend(0.52,0.65,0.86,0.89);
    l_all_data->AddEntry(hM_bg_dR2,"Gen. level QCD MC","lp");
    l_all_data->AddEntry((TObject*)0,"(b#bar{b} + q-g scatter,",""); //null pointers for blank entries
    l_all_data->AddEntry((TObject*)0,"q = b, #bar{b}, c, #bar{c})","");
    l_all_data->AddEntry(hCorr_side_data, "Data", "lp");
    doStandardLegend(l_all_data);
    l_all_data->Draw();
    
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_bg_data.pdf");
    // c1->SaveAs("Combined/"+dir+"/Corr_side_bg_data.png");

    // bbar + data
    hCorr_side_b->Draw();
    hCorr_side_data->Draw("SAME");
    TLegend* l_b_data = new TLegend(0.6,0.7,0.86,0.89);
    l_b_data->AddEntry(hM_bg_dR2,"QCD b#bar{b} MC","lp");
    l_b_data->AddEntry(hCorr_side_data, "Data", "lp");
    doStandardLegend(l_b_data);
    l_b_data->Draw();
    line.Draw();
    t_side->Draw();
    c1->SaveAs("Combined/"+dir+"/Corr_side_b_data.pdf");
    c1->SaveAs("Combined/"+dir+"/Corr_side_b_data.png");


    /////////////////////////
    // TRACK DISTRIBUTIONS //
    /////////////////////////
    // combineHists(f_sig_main2, f_bg_main2, f_scatter_main2, "hNTracks1", "HISTE", "Combined/combined_NTrack1_muRand.pdf", scalingFactors, "Tracks with p_{T} > 2.5 GeV");
    // combineHists(f_sig_main2, f_bg_main2, f_scatter_main2, "hNTracksAbs1", "HISTE", "Combined/combined_NTrackAbs1_muRand.pdf", scalingFactors, "Tracks with p_{T} > 2.5 GeV", "Average number of tracks per #mu_{1} / bin");
    // combineHists(f_sig_main2, f_bg_main2, f_scatter_main2, "hNTracksAll1", "HISTE", "Combined/combined_NTrackAll1_muRand.pdf", scalingFactors, "Tracks with p_{T} > 1 GeV");
    // combineHists(f_sig_main2, f_bg_main2, f_scatter_main2, "hNTracksAllAbs1", "HISTE", "Combined/combined_NTrackAllAbs1_muRand.pdf", scalingFactors, "Tracks with p_{T} > 1 GeV", "Average number of tracks per #mu_{1} / bin");
    // combineHists(f_sig_main2, f_bg_main2, f_scatter_main2, "hNSoftTracks1", "HISTE", "Combined/combined_NSoftTrack1_muRand.pdf", scalingFactors, "Tracks with 1 < p_{T} < 2.5 GeV");
    // combineHists(f_sig_main2, f_bg_main2, f_scatter_main2, "hNSoftTracksAbs1", "HISTE", "Combined/combined_NSoftTrackAbs1_muRand.pdf", scalingFactors, "Tracks with 1 < p_{T} < 2.5 GeV", "Average number of tracks per #mu_{1} / bin");


    ////////////////////////////////////////////
    // mass shape as fn of # tracks about mu2 //
    ////////////////////////////////////////////
    THStack* st_Ntk2_234 = new THStack("","");
    TH1D* histM1_Ntk2_2 = (TH1D*) f_bg_mass2->Get("hM1_Ntk2_2");
    TH1D* histM1_Ntk2_3 = (TH1D*) f_bg_mass2->Get("hM1_Ntk2_3");
    TH1D* histM1_Ntk2_4 = (TH1D*) f_bg_mass2->Get("hM1_Ntk2_4");
    doStandardHist(hM1_bare_bg_muRand_HLT_dR2);
    // hM1_bare_bg_muRand_HLT_dR2->SetMarkerStyle();
    doCustomHist(histM1_Ntk2_2, kRed, 21);
    doCustomHist(histM1_Ntk2_3, kBlack, 22);
    doCustomHist(histM1_Ntk2_4, kGreen+3, 23);
    st_Ntk2_234->Add(hM1_bare_bg_muRand_HLT_dR2);
    st_Ntk2_234->Add(histM1_Ntk2_2);
    st_Ntk2_234->Add(histM1_Ntk2_3);
    st_Ntk2_234->Add(histM1_Ntk2_4);
    st_Ntk2_234->Draw("NOSTACK E");
    setMassAUTitles(st_Ntk2_234->GetHistogram());
    st_Ntk2_234->GetHistogram()->SetXTitle("m_{1}(#mu-tk) [GeV]");
    setAltTitleLabelSizes(st_Ntk2_234->GetHistogram());
    TLegend* l_Ntk2_234 = new TLegend(0.56, 0.6, 0.88, 0.88);
    l_Ntk2_234->AddEntry((TObject*)0, "Gen. level QCD b#bar{b} MC", "");
    l_Ntk2_234->AddEntry(hM1_bare_bg_muRand_HLT_dR2, "N_{tk,2} = 1", "lp");
    l_Ntk2_234->AddEntry(histM1_Ntk2_2, "N_{tk,2} = 2", "lp");
    l_Ntk2_234->AddEntry(histM1_Ntk2_3, "N_{tk,2} = 3", "lp");
    l_Ntk2_234->AddEntry(histM1_Ntk2_4, "N_{tk,2} = 4", "lp");
    doStandardLegend(l_Ntk2_234);
    l_Ntk2_234->Draw();
    c1->SaveAs("Combined/"+dir+"/M1_Ntk2.pdf");

    THStack* st_Ntk2_2or3 = new THStack("","");
    TH1D* histM1_Ntk2_2or3 = (TH1D*) f_bg_mass2->Get("hM1_Ntk2_2or3");
    doCustomHist(histM1_Ntk2_2or3, kRed, 22);
    // st_Ntk2_2or3->Add(hM1_bare_bg_muRand_HLT_dR2);
    st_Ntk2_2or3->Add(hM_bare_bg_muRand_HLT_dR2);
    st_Ntk2_2or3->Add(histM1_Ntk2_2or3);
    st_Ntk2_2or3->Draw("NOSTACK E");
    setMassAUTitles(st_Ntk2_2or3->GetHistogram());
    st_Ntk2_2or3->GetHistogram()->SetXTitle("m_{ i }(#mu-trk) [GeV]");
    setAltTitleLabelSizes(st_Ntk2_2or3->GetHistogram());
    TLegend* l_Ntk2_2or3 = new TLegend(0.55, 0.56, 0.88, 0.88);
    l_Ntk2_2or3->AddEntry((TObject*)0, "Gen. level QCD b#bar{b} MC", "");
    // l_Ntk2_2or3->AddEntry(hM1_bare_bg_muRand_HLT_dR2, "N_{trk,2} = 1", "lp");
    l_Ntk2_2or3->AddEntry(hM_bare_bg_muRand_HLT_dR2, "N_{trk, j} = 1", "lp");
    l_Ntk2_2or3->AddEntry(histM1_Ntk2_2or3, "N_{trk, j} = 2, 3", "lp");
    doStandardLegend(l_Ntk2_2or3);
    l_Ntk2_2or3->Draw();
    c1->SaveAs("Combined/"+dir+"/M_Ntk2_2or3.pdf");
    c1->SaveAs("Combined/"+dir+"/M_Ntk2_2or3.png");

    histM1_Ntk2_2or3->SetMinimum(0.001); // Stop SetLogy complainng
    // hM1_bare_bg_muRand_HLT_dR2->SetMinimum(0.001); // Stop SetLogy complainng
    hM_bare_bg_muRand_HLT_dR2->SetMinimum(0.001); // Stop SetLogy complainng
    setAltTitleLabelSizes(st_Ntk2_2or3->GetHistogram());
    c1->SetLogy();
    c1->SaveAs("Combined/"+dir+"/M_Ntk2_2or3_log.pdf");
    c1->SaveAs("Combined/"+dir+"/M_Ntk2_2or3_log.png");


    // cleanup
    f_sig_main1->Close();
    f_sig_main2->Close();
    f_sig_mass2->Close();
    f_sig_mass2->Close();
    f_bg_main1->Close();
    f_bg_main2->Close();
    f_bg_mass1->Close();
    f_bg_mass2->Close();
    f_scatter_main1->Close();
    f_scatter_main2->Close();
    f_scatter_mass1->Close();
    f_scatter_mass2->Close();

}
示例#21
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;

}
示例#22
0
void Interpolate(const TString& trigger="INEL")
{
  if (gSystem->Getenv("FWD"))
    fwd = gSystem->Getenv("FWD");
  else 
    fwd = gSystem->ExpandPathName("$ALICE_PHYSICS/PWGLF/FORWARD/analysis2");
  gROOT->SetMacroPath(Form("%s/dndeta:%s", gROOT->GetMacroPath(),fwd));

  if (!gROOT->GetClass("Drawer"))  gROOT->LoadMacro("Drawer.C+");

  TH1* h0900 = GetOne( 900, trigger);
  TH1* h2760 = GetOne(2760, trigger);
  TH1* h7000 = GetOne(7000, trigger);
  TH1* h8000 = GetOne(8000, trigger);
  Info("","900: %p 2760: %p 7000: %p 8000: %p", 
       h0900, h2760, h7000, h8000);
  Double_t e8000 = (trigger.EqualTo("INEL") ? 0.852 : 0.93);
  h8000->Scale(e8000);

  TFile* out = TFile::Open("trends.root", "RECREATE");
  THStack* sOrig = new THStack("orig", Form("pp - %s", trigger.Data()));
  sOrig->Add(h8000);
  sOrig->Add(h7000);
  sOrig->Add(h2760);
  sOrig->Add(h0900);

  TCanvas* cOrig = new TCanvas("cOrig", "Original", 1200, 1200);
  cOrig->SetTopMargin(0.01);
  cOrig->SetRightMargin(0.01);
  sOrig->Draw("nostack");
  sOrig->GetHistogram()->SetYTitle("1/#it{N} d#it{N}_{ch}/d#it{#eta}");
  sOrig->GetHistogram()->SetXTitle("#it{#eta}");
  sOrig->DrawClone("nostack");
  sOrig->Write();
  
  TLegend* l = cOrig->BuildLegend(.35, .2, .55, .6, "#sqrt{s}");
  l->SetFillColor(0);
  l->SetFillStyle(0);
  l->SetBorderSize(0);

  cOrig->Modified();
  cOrig->Update();
  cOrig->cd();
  cOrig->Write();
  Info("", "Wrote original"); 

  TCanvas* cG = new TCanvas("cG", "one", 1200, 1200);
  cG->SetTopMargin(0.01);
  cG->SetRightMargin(0.01);
  
  Info("","Creating tuple");
  TNtuple* tuple = new TNtuple("tuple", "Tuple", 
			       "eta:deta:"
			       "v0900:e0900:v2760:e2760:"
			       "v7000:e7000:v8000:e8000");
  TMultiGraph* mg = new TMultiGraph;
  Int_t n = h0900->GetNbinsX();
  Info("","Loop over bins %d", n);

  for (Int_t i = 1; i <= n; i++) {
    Info("", "Getting one bin %d,%p,%p,%p,%p,%p,%p",
	 i, h0900,h2760,h7000,h8000,mg,tuple);
    OneBin(i, h0900, h2760, h7000, h8000, mg, tuple);
  }
  mg->Draw("alp");

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

  TPrincipal* p =tuple->Principal("v0900:v2760:v7000:v8000","eta<0", "npdhc");
}