diff --git a/JetTrgNorm.C b/JetTrgNorm.C new file mode 100644 index 0000000..fa59bc7 --- /dev/null +++ b/JetTrgNorm.C @@ -0,0 +1,207 @@ + +#include +#include +#include "TFile.h" +#include "TTree.h" +#include "TH1D.h" +#include "TCanvas.h" +#include "TLegend.h" +#include "TStyle.h" +#include "TChain.h" + +using namespace std; + +void JetTrgNorm(){ + + gStyle->SetPadLeftMargin(0.2); + + TFile *fin = new TFile("histos/ppdata_ppReco_ak3PF_DinkoXchk_jetTrig_noIPupperCut.root"); + //TChain *nt = new TChain("hltanalysis/HltTree"); + //TChain *jt = new TChain("ak3PFJetAnalyzer/t"); + //nt->Add("/mnt/hadoop/store/user/kjung/pPb_BForest/hiForestTree_1*"); + //jt->Add("/mnt/hadoop/store/user/kjung/pPb_BForest/hiForestTree_1*"); + //nt->AddFriend(jt); + TTree *nt = (TTree*)fin->Get("nt"); + if(!nt){ cout << "Can't get tree!" << endl; exit(0); } + + TH1D *jetHist[6]; + TH1D *jetNorm[6]; + + jetHist[0] = new TH1D("jet20","",50,30,250); + jetHist[1] = new TH1D("jet40","",50,30,250); + jetHist[2] = new TH1D("jet60","",50,30,250); + jetHist[3] = new TH1D("jet80","",50,30,250); + jetHist[4] = new TH1D("jet100","",50,30,250); + jetHist[5] = new TH1D("jet120","",50,30,250); + + jetNorm[0] = new TH1D("jet20Comb","",50,30,250); + jetNorm[1] = new TH1D("jet40Comb","",50,30,250); + jetNorm[2] = new TH1D("jet60Comb","",50,30,250); + jetNorm[3] = new TH1D("jet80Comb","",50,30,250); + jetNorm[4] = new TH1D("jet100Comb","",50,30,250); //Not used since ps(Jet80)=1. Only here for completeness. + jetNorm[5] = new TH1D("jet120Comb","",50,30,250); + + for(int i=0; i<6; i++){ + jetHist[i]->Sumw2(); + jetNorm[i]->Sumw2(); + } + + Int_t JetTrg20, JetTrg40, JetTrg60, JetTrg80, JetTrg100, JetTrg120; + Double_t jtpt; + Double_t jteta; + + nt->SetBranchAddress("HLT_Jet20_noJetID_v1",&JetTrg20); + nt->SetBranchAddress("HLT_Jet40_noJetID_v1",&JetTrg40); + nt->SetBranchAddress("HLT_Jet60_noJetID_v1",&JetTrg60); + nt->SetBranchAddress("HLT_Jet80_noJetID_v1",&JetTrg80); + nt->SetBranchAddress("HLT_Jet100_noJetID_v1",&JetTrg100); + nt->SetBranchAddress("HLT_Jet120_noJetID_v1",&JetTrg120); + nt->SetBranchAddress("jtpt",&jtpt); + nt->SetBranchAddress("jteta",&jteta); + + double ov1 = nt->GetEntries("HLT_Jet20_noJetID_v1 && HLT_Jet80_noJetID_v1"); + cout <<"ov1: "<< ov1 << endl; + double ov2 = nt->GetEntries("HLT_Jet40_noJetID_v1 && HLT_Jet80_noJetID_v1"); + cout <<"ov2: "<< ov2 << endl; + double ov3 = nt->GetEntries("HLT_Jet60_noJetID_v1 && HLT_Jet80_noJetID_v1"); + cout <<"ov3: "<< ov3 << endl; + double ov4 = nt->GetEntries("HLT_Jet80_noJetID_v1 && HLT_Jet80_noJetID_v1"); + cout <<"ov4: "<< ov4 << endl; + double ov5 = nt->GetEntries("HLT_Jet100_noJetID_v1 && HLT_Jet80_noJetID_v1"); + cout <<"ov5: "<< ov5 << endl; + double ov6 = nt->GetEntries("HLT_Jet80_noJetID_v1"); + cout <<"ov6: "<< ov6 << endl; + + double ps1 = ov6/ov1; + double ps2 = ov6/ov2; + double ps3 = ov6/ov3; + double ps4 = ov6/ov4; + double ps5 = ov6/ov5; + + for(int i=0; iGetEntries(); i++){ + nt->GetEntry(i); + + if(fabs(jteta)<3){ + //Fill Trigger Combination Spectra + //if(JetTrg20 && !JetTrg40 && !JetTrg60 && !JetTrg80) jetNorm[0]->Fill(jtpt, 1./(1./ps1)); + if(JetTrg40 && !JetTrg60 && !JetTrg80 /*&& !JetTrg100 && !JetTrg120*/) jetNorm[1]->Fill(jtpt,(1./(1./ps2))); + if(JetTrg60 && !JetTrg80 /*&& !JetTrg100 && !JetTrg120*/) jetNorm[2]->Fill(jtpt);//, 1./(1./ps2 + 1./ps3 - (1./(ps2*ps3)))); + if(JetTrg80 /*&& !JetTrg100 && !JetTrg120*/) jetNorm[3]->Fill(jtpt);//, 1./(1./ps2 + 1./ps3 + 1./ps4 - (1./(ps2*ps3)) - (1./(ps3*ps4)) - (1./(ps2*ps4)) + 1./(ps2*ps3*ps4))); + //if(JetTrg100 && !JetTrg120) jetNorm[4]->Fill(jtpt, 1./(1./ps2 + 1./ps3 + 1./ps4 + 1./ps5 - (1./(ps2*ps3)) - (1./(ps2*ps4)) - 1./(ps2*ps5) - 1./(ps3*ps4) - 1./(ps3*ps5) - 1./(ps4*ps5) + 1./(ps2*ps3*ps4) + 1./(ps2*ps3*ps5) + 1./(ps2*ps4*ps5) + 1./(ps3*ps4*ps5) - 1./(ps2*ps3*ps4*ps5))); + //if(JetTrg120) jetNorm[5]->Fill(jtpt); + + //Fill Trigger Normalization cross-check spectra + if(JetTrg20) jetHist[0]->Fill(jtpt); + if(JetTrg40) jetHist[1]->Fill(jtpt); + if(JetTrg60) jetHist[2]->Fill(jtpt); + if(JetTrg80) jetHist[3]->Fill(jtpt); + if(JetTrg100) jetHist[4]->Fill(jtpt); + } + } + + TH1D *jetCln = (TH1D*)jetNorm[5]->Clone("jetCln"); + for(int i=1; i<4; i++){ + jetNorm[4]->Add(jetNorm[i]); + } + + jetHist[0]->Scale(1/ov1); + jetHist[1]->Scale(1/ov2); + jetHist[2]->Scale(1/ov3); + jetHist[3]->Scale(1/ov4); + jetHist[4]->Scale(1/ov5); + jetHist[5]->Scale(1/ov6); + + //Scale by bin width to get dN/dpt + /* for(int i=1; i<5; i++){ + for(int j=1; j<=jetHist[i]->GetNbinsX(); j++){ + jetHist[i]->SetBinContent(j, jetHist[i]->GetBinContent(j)/jetHist[i]->GetBinWidth(j)); + jetHist[i]->SetBinError(j, jetHist[i]->GetBinError(j)/jetHist[i]->GetBinWidth(j)); + } + }*/ + + for(int i=1; i<6; i++){ + jetHist[i]->SetLineColor(pow(2,i)); + jetHist[i]->SetMarkerColor(pow(2,i)); + } + jetHist[4]->SetMarkerColor(5); + + TCanvas *c1 = new TCanvas("c1","",800,600); + c1->Divide(1,2); + c1->cd(1); + gPad->SetLogy(); + + jetHist[0]->SetYTitle("1/N_{Jet80Trg} dN/dp_{T}"); + jetHist[0]->SetXTitle("Jet p_{T}"); + jetHist[0]->Draw(); + for(int i=1; i<4; i++){ + jetHist[i]->Draw("same"); + } + TLegend *leg = new TLegend(0.6,0.5,0.9,0.9); + leg->SetFillColor(0); + //leg->AddEntry(jetHist[0],"Jet20 Trg"); + leg->AddEntry(jetHist[1],"Jet40 Trg"); + leg->AddEntry(jetHist[2],"Jet60 Trg"); + leg->AddEntry(jetHist[3],"Jet80 Trg"); + //leg->AddEntry(jetHist[4],"Jet100 Trg"); + //leg->AddEntry(jetHist[5],"Jet120 Trg"); + leg->Draw(); + + c1->cd(2); + TH1D *cln[5]; + char* histoname = new char[20]; + for(int i=1; i<6; i++){ + sprintf(histoname,"%s%d","clone_",i); + cln[i] = (TH1D*)jetHist[i]->Clone(histoname); + cln[i]->Divide(jetHist[i-1]); + } + + cln[1]->SetXTitle("Jet p_{T}"); + cln[1]->SetYTitle("Efficiency"); + cln[1]->Draw(); + for(int i=1; i<5; i++){ + cln[i]->Draw("same"); + } + + TCanvas *c2 = new TCanvas("c2","",800,600); + c2->cd(); + c2->SetLogy(); + //c2->SetLogx(); + jetNorm[4]->SetMinimum(10); + jetNorm[4]->SetMaximum(1E8); + jetNorm[4]->SetXTitle("Jet p_{T} (GeV/c)"); + jetNorm[4]->SetYTitle("dN/dp_{T} (GeV/c)^{-1}"); + //jetNorm[5]->Scale(1./12.); + //double tempInt = jetNorm[4]->Integral(); + //jetNorm[4]->Scale(1./jetNorm[4]->Integral()); + jetNorm[4]->Draw(); + jetNorm[3]->SetMarkerColor(2); + jetNorm[3]->SetLineColor(2); + jetNorm[2]->SetMarkerColor(4); + jetNorm[2]->SetLineColor(4); + jetNorm[1]->SetMarkerColor(8); + jetNorm[1]->SetLineColor(8); + for(int i=1; i<4; i++){ + //jetNorm[i]->SetMarkerColor(2+(i*2)); + //jetNorm[i]->SetLineColor(2+(i*2)); + //jetNorm[i]->Scale(1./12.); + //jetNorm[i]->Scale(1./tempInt); + jetNorm[i]->Draw("same"); + + } + jetCln->SetMarkerColor(kGreen-2); + jetCln->SetLineColor(kGreen-2); + //jetCln->Draw("same"); + jetNorm[4]->Draw("same"); + //jetHist[1]->Draw("same"); + + TLegend *leg1 = new TLegend(0.577,0.613,0.888,0.914); + leg1->SetFillColor(0); + leg1->AddEntry(jetNorm[4], "Combined"); + //leg1->AddEntry(jetNorm[0], "Jet20_NoID Trg"); + leg1->AddEntry(jetNorm[3], "ppJet80"); + leg1->AddEntry(jetNorm[2], "ppJet60"); + leg1->AddEntry(jetNorm[1], "ppJet40"); + //leg1->AddEntry(jetNorm[4], "Jet100 Trigger"); + //leg1->AddEntry(jetCln, "Jet120 Trigger"); + leg1->Draw(); +} diff --git a/PUeffect.C b/PUeffect.C new file mode 100644 index 0000000..4ed7a34 --- /dev/null +++ b/PUeffect.C @@ -0,0 +1,42 @@ + +#include "TTree.h" +#include "TH1D.h" +#include "TFile.h" +#include "TCanvas.h" +#include "TLegend.h" + +void PUeffect(){ + + TFile *f1 = new TFile("histos/ppMC_ppReco_ak3PF_QCDjetTrig_noIPupperCut.root"); + //TFile *f1 = new TFile("histos/ppdata_ppReco_ak3PF_jetTrig_noIPupperCut.root"); + TTree *nt = (TTree*)f1->Get("nt"); + + TH1D *h_QCDpu = new TH1D("h_QCDpu","",50,0,600); h_QCDpu->Sumw2(); + TH1D *h_QCDnoPU = new TH1D("h_QCDnoPU","",50,0,600); h_QCDnoPU->Sumw2(); + TH1D *h_Bpu = new TH1D("h_Bpu","",50,0,600); h_Bpu->Sumw2(); + TH1D *h_BnoPU = new TH1D("h_BnoPU","",50,0,600); h_BnoPU->Sumw2(); + + nt->Draw("jtpt>>h_QCDpu","weight*(pVertexFilterCutGplusUpsPP)"); + nt->Draw("jtpt>>h_QCDnoPU","weight*(1)"); + nt->Draw("jtpt>>h_Bpu","weight*(pVertexFilterCutGplusUpsPP && discr_ssvHighEff>2 )"); + nt->Draw("jtpt>>h_BnoPU","weight*(discr_ssvHighEff>2)"); + + h_QCDpu->Divide(h_QCDpu,h_QCDnoPU,1,1,"B"); + h_Bpu->Divide(h_Bpu,h_BnoPU,1,1,"B"); + + TCanvas *c1 = new TCanvas("c1","",800,600); + c1->cd(); + h_QCDpu->SetXTitle("reco p_{T}"); + h_QCDpu->SetYTitle("PU Filter / No PU Filter [MC]"); + h_QCDpu->SetMaximum(1.3); + h_QCDpu->SetMinimum(0.4); + h_QCDpu->Draw(); + h_Bpu->SetMarkerColor(2); + h_Bpu->SetLineColor(2); + h_Bpu->Draw("same"); + + TLegend *l1 = new TLegend(0.5,0.5,0.8,0.8); + l1->AddEntry(h_QCDpu,"QCD Jets"); + l1->AddEntry(h_Bpu,"B Jets"); + l1->Draw(); +} diff --git a/README b/README index e69de29..6a8e20a 100644 --- a/README +++ b/README @@ -0,0 +1,17 @@ +~~~ PP WORKFLOW ~~~ + +From the HiForest: +(1) Create the BJet Trees +run analyzeTrees.C -> be sure to set fout to include or not include the gsp designations, depending on whether you want to run or not run the gsp code. The weights are taken care of automatically - no reweighting code required. + +(2) Run the fits +pp fits run via bfractionVsJetPtPP.C. This should run out of the box. Be sure to create two folders: PDFS and MACROS if you want to save the fits output. Svtxm fits will be saved here. + +(3) Plot systematics +pp systematics plots are run via plotSystematicComponents.C. You'll need all the output files that I've put in the "data" directory. You can also choose to run the gen->reco jet pt matrix via the createReco2GenMatrix.C code, else you can use the exisiting code. + +(4) To remake the compareDataMC plots, just run the compareDataMC.C code. The data output you might need is here: /afs/cern.ch/user/k/kjung/public and the MC output is here: /mnt/hadoop/cms/store/user/kjung/HIN-12-003-MC_backup + +(5) To make the efficiency plots, you can run the plotEfficiencyNew.C code. The input files you need should be in "data". All JP and SV taggers for pPb, PbPb, and pp are available - you can just comment in or out what you want to plot. + + diff --git a/TTreeCreator.C b/TTreeCreator.C new file mode 100644 index 0000000..8a524de --- /dev/null +++ b/TTreeCreator.C @@ -0,0 +1,170 @@ + + +#include "TTree.h" +#include "TFile.h" +#include "TH1.h" + +#include +#include + +void TTreeCreator(){ + + + //for some reason if you don't make your outfile before your ttree, root hates it + TFile *fout = new TFile("treeCreator.root","recreate"); + + //Declare your temporary storage variables + Double_t t_jtpt, t_jteta, t_jtphi, t_rawpt, t_refpt, t_refparton_flavorForB, t_discr_prob, t_discr_ssvHighEff, t_discr_ssvHighPur, t_discr_csvSimple, t_svtxm; + Double_t t_pthat, t_bin, t_nMCentries, t_weight; + Int_t t_HLT_Jet20, t_HLT_Jet40, t_HLT_Jet60, t_HLT_Jet80, t_HLT_Jet100; + + //Create TTree + TTree *nt = new TTree("nt",""); + //Tell the tree what branches you want and where to look to fill those branches + nt->Branch("jtpt",&t_jtpt); + nt->Branch("jteta",&t_jteta); + nt->Branch("jtphi",&t_jtphi); + nt->Branch("rawpt",&t_rawpt); + nt->Branch("refpt",&t_refpt); + nt->Branch("refparton_flavorForB",&t_refparton_flavorForB); + nt->Branch("discr_prob",&t_discr_prob); + nt->Branch("discr_ssvHighEff",&t_discr_ssvHighEff); + nt->Branch("discr_ssvHighPur",&t_discr_ssvHighPur); + nt->Branch("discr_csvSimple",&t_discr_csvSimple); + nt->Branch("svtxm",&t_svtxm); + nt->Branch("HLT_Jet20_noJetID_v1",&t_HLT_Jet20,"HLT_Jet20_noJetID_v1/I"); + nt->Branch("HLT_Jet40_noJetID_v1",&t_HLT_Jet40,"HLT_Jet40_noJetID_v1/I"); + nt->Branch("HLT_Jet60_noJetID_v1",&t_HLT_Jet60,"HLT_Jet60_noJetID_v1/I"); + nt->Branch("HLT_Jet80_noJetID_v1",&t_HLT_Jet80,"HLT_Jet80_noJetID_v1/I"); + nt->Branch("HLT_Jet100_noJetID_v1",&t_HLT_Jet100,"HLT_Jet100_noJetID_v1/I"); + nt->Branch("pthat",&t_pthat,"pthat/D"); + + + //Now declare a bunch of variables that will get filled by the incoming Forest file + //Essentially, these guys will get reset and refilled by root on each new event from the Forest. + //The arrays are there because the branches in the Forest are arrays of jets. 1000 is just a big number so we don't overload the array. There's never going to be 1000 jets in an event. + Int_t evt; + Float_t vz; + Int_t nref; + Float_t rawpt[1000]; + Float_t jtpt[1000]; + Float_t jteta[1000]; + Float_t jty[1000]; + Float_t jtphi[1000]; + Float_t jtpu[1000]; + Float_t discr_ssvHighEff[1000]; + Float_t discr_ssvHighPur[1000]; + Float_t discr_csvMva[1000]; + Float_t discr_csvSimple[1000]; + Float_t discr_muByIp3[1000]; + Float_t discr_muByPt[1000]; + Float_t discr_prob[1000]; + Float_t discr_probb[1000]; + Float_t discr_tcHighEff[1000]; + Float_t discr_tcHighPur[1000]; + Int_t nsvtx[1000]; + Float_t mue[1000]; + Float_t mupt[1000]; + Float_t mueta[1000]; + Float_t muphi[1000]; + Float_t mudr[1000]; + Float_t muptrel[1000]; + Int_t muchg[1000]; + Float_t pthat; + Float_t refparton_pt[1000]; + Int_t refparton_flavor[1000]; + Int_t refparton_flavorForB[1000]; + Int_t HLT_PAJet20_NoJetID_v1; + Int_t HLT_PAJet40_NoJetID_v1; + Int_t HLT_PAJet60_NoJetID_v1; + Int_t HLT_PAJet80_NoJetID_v1; + Int_t HLT_PAJet100_NoJetID_v1; + + //Now lets loop over our filelist + TFile *fin; + std::string infile = "ppNewJEC_BForest.txt"; //txt list of files + + std::ifstream instr(infile.c_str(), std::ifstream::in); + std::string filename; + for(int ifile=0; ifile> filename; + std::cout << "File: " << filename << std::endl; + fin = TFile::Open(filename.c_str()); + + //Load in the trees from the file + + TTree *t = (TTree*) fin->Get("akPu3PFJetAnalyzer/t"); + TTree *tSkim = (TTree*) fin->Get("skimanalysis/HltTree"); + TTree *tEvt = (TTree*) fin->Get("hiEvtAnalyzer/HiTree"); + if(!t || !tSkim || !tEvt){ cout << "Warning! Can't find one of the trees!" << endl; exit(0);} + + if(tEvt) t->AddFriend("hiEvtAnalyzer/HiTree"); + t->AddFriend("hltanalysis/HltTree"); + + //And now tell ROOT where you want to store all the tree branches for each event (i.e. at the variables we just declared above) + t->SetBranchAddress("evt",&evt); + t->SetBranchAddress("vz",&vz); + t->SetBranchAddress("nref",&nref); + t->SetBranchAddress("HLT_PAJet20_NoJetID_v1",&HLT_PAJet20_NoJetID_v1); + t->SetBranchAddress("HLT_PAJet40_NoJetID_v1",&HLT_PAJet40_NoJetID_v1); + t->SetBranchAddress("HLT_PAJet60_NoJetID_v1",&HLT_PAJet60_NoJetID_v1); + t->SetBranchAddress("HLT_PAJet80_NoJetID_v1",&HLT_PAJet80_NoJetID_v1); + t->SetBranchAddress("HLT_PAJet100_NoJetID_v1",&HLT_PAJet100_NoJetID_v1); + t->SetBranchAddress("rawpt",rawpt); + t->SetBranchAddress("jtpt",jtpt); + t->SetBranchAddress("jteta",jteta); + t->SetBranchAddress("jtphi",jtphi); + t->SetBranchAddress("jty",jty); + t->SetBranchAddress("jtphi",jtphi); + t->SetBranchAddress("jtpu",jtpu); + t->SetBranchAddress("discr_ssvHighEff",discr_ssvHighEff); + t->SetBranchAddress("discr_ssvHighPur",discr_ssvHighPur); + t->SetBranchAddress("discr_csvSimple",discr_csvSimple); + t->SetBranchAddress("discr_muByPt",discr_muByPt); + t->SetBranchAddress("discr_prob",discr_prob); + t->SetBranchAddress("discr_probb",discr_probb); + t->SetBranchAddress("discr_tcHighEff",discr_tcHighEff); + t->SetBranchAddress("discr_tcHighPur",discr_tcHighPur); + t->SetBranchAddress("nsvtx",nsvtx); + + t->SetBranchAddress("mue",mue); + t->SetBranchAddress("mupt",mupt); + t->SetBranchAddress("mueta",mueta); + t->SetBranchAddress("muphi",muphi); + t->SetBranchAddress("mudr",mudr); + t->SetBranchAddress("muptrel",muptrel); + t->SetBranchAddress("muchg",muchg); + + if(isMC){ + t->SetBranchAddress("pthat",&pthat); + t->SetBranchAddress("refparton_pt",refparton_pt); + t->SetBranchAddress("refparton_flavor",refparton_flavor); + t->SetBranchAddress("refparton_flavorForB",refparton_flavorForB); + } + + Long64_t nentries = t->GetEntries(); + cout << "entries: "<< nentries << endl; + + for (Long64_t i=0; iGetEntries(); i++) { + if (i%100000==0) std::cout<<" i = "<GetEntries()<<" ("<<(int)(100*(float)i/(float)t->GetEntries())<<"%)"<GetEntry(i); + + //Here's the space where you could fill a histogram, for example + //Or, even better, set your temporary variables (declared at the beginning) + + //Now fill the information in our temporary trees to one line in the new TTree + nt->Fill(); + //close entries loop + } + + //close file loop + } + + //Write your TTree to your output file + fout->cd(); + nt->Write(); +} + diff --git a/analyzeDijets.C b/analyzeDijets.C index 38490a5..a87ab55 100644 --- a/analyzeDijets.C +++ b/analyzeDijets.C @@ -16,35 +16,9 @@ using namespace std; -//********************************************************** -// Count the MC events to appropriately weight the pthat bins -//********************************************************** - -int *countMCevents(std::string infile, int nFiles, bool usePUsub){ - - TChain *ch = NULL; - if(usePUsub) ch = new TChain("akPu3PFJetAnalyzer/t"); - else ch = new TChain("ak3PFJetAnalyzer/t"); - std::ifstream instr(infile.c_str(), std::ifstream::in); - std::string filename; - for(int ifile=0; ifile> filename; - ch->Add(filename.c_str()); - } - int *MCentries = new int[11]; - MCentries[0] = ch->GetEntries("pthat<30"); - MCentries[1] = ch->GetEntries("pthat>=30 && pthat<50"); - MCentries[2] = ch->GetEntries("pthat>=50 && pthat<80"); - MCentries[3] = ch->GetEntries("pthat>=80 && pthat<120"); - MCentries[4] = ch->GetEntries("pthat>=120 && pthat<170"); - MCentries[5] = ch->GetEntries("pthat>=170 && pthat<220"); - MCentries[6] = ch->GetEntries("pthat>=220 && pthat<280"); - MCentries[7] = ch->GetEntries("pthat>=280 && pthat<370"); - MCentries[8] = ch->GetEntries("pthat>=370 && pthat<460"); - MCentries[9] = ch->GetEntries("pthat>=460 && pthat<540"); - MCentries[10] = ch->GetEntries("pthat>=540 && pthat<10000"); - return MCentries; -} +const int QCDpthatBins = 11; +const int HFpthatBins = 5; +const int dataFiles = 10; //********************************************************** // Do the pthat weighting for the Heavy Flavor Jets @@ -52,9 +26,9 @@ int *countMCevents(std::string infile, int nFiles, bool usePUsub){ double *heavyJetWeighting(std::string HFfile, std::string QCDfile, int HFnfiles, int QCDnfiles, char flavor, bool usePUsub){ - const int nDivisions = 6; + const int nDivisions = 11; double *HFweights = new double[nDivisions]; - const int weightBlocks[nDivisions+1] = {0,30,50,80,120,170,220}; + const int weightBlocks[nDivisions+1] = {15,30,50,80,120,170,220,280,370,460,540,1200}; TChain *chH = NULL; TChain *chQCD = NULL; @@ -82,21 +56,115 @@ double *heavyJetWeighting(std::string HFfile, std::string QCDfile, int HFnfiles, if(flavor=='b') parton_flavor=5; if(flavor=='c') parton_flavor=4; - char* cutname = new char[100]; - char* cutfull = new char[100]; + char* cutname = new char[200]; + char* cutfull = new char[200]; + TH1D *bjetEntr = new TH1D("bjetEntr","",1,0,1200); + TH1D *QCDjetEntr = new TH1D("QCDjetEntr","",1,0,1200); + + TH1D *bjetEntrFULL = new TH1D("bjetEntrFULL","",1,0,1200); + TH1D *QCDjetEntrFULL = new TH1D("QCDjetEntrFULL","",1,0,1200); if(parton_flavor==5 || parton_flavor==4){ for(int i=0; i%d&&pthat<%d&&refpt>0&&abs(jteta)<2&&abs(refparton_flavorForB)==%d",weightBlocks[i],weightBlocks[i+1],parton_flavor); - sprintf(cutfull,"pthat>%d&&pthat<%d&&refpt>0&&abs(jteta)<2",weightBlocks[i],weightBlocks[i+1]); - double qcd1 = (double)chQCD->GetEntries(cutname)/(double)chQCD->GetEntries(cutfull); - double h1 = (double)chH->GetEntries(cutname)/(double)chH->GetEntries(cutfull); - //cout << "between pthat " << weightBlocks[i] << " and " << weightBlocks[i+1] << " has " << qcd1/h1 << " norm, or " << qcd1 << " qcd bjets and " << h1 << " hf jets" << endl; - HFweights[i] = qcd1/h1; + sprintf(cutfull,"pthat>%d&&pthat<%d",weightBlocks[i],weightBlocks[i+1]); + cout << "jet cut: "<< cutname << endl; + cout << "evt cut: "<< cutfull << endl; + chQCD->Draw("jtpt>>QCDjetEntr",cutname); + chH->Draw("jtpt>>bjetEntr",cutname); + double qcd1 = (double)QCDjetEntr->Integral()/(double)chQCD->GetEntries(cutfull); + double h1 = (double)bjetEntr->Integral()/(double)chH->GetEntries(cutfull); + cout << "between pthat " << weightBlocks[i] << " and " << weightBlocks[i+1] << " has " << qcd1/h1 << " norm, or " << qcd1 << " qcd bjets and " << h1 << " hf jets" << endl; + if(qcd1!=qcd1 || h1!=h1) HFweights[i]=0; //check on NaN via IEEE recommended method + else{ + cout << "QCD bjet per event, pthat " << i << ": " << qcd1 << endl; + cout << "HF bjet per event, pthat " << i << ": " << h1 << endl; + HFweights[i] = h1/qcd1; + } + bjetEntr->Reset(); + QCDjetEntr->Reset(); } } + delete bjetEntr; + delete QCDjetEntr; return HFweights; } +//********************************************************** +// Count the MC events to appropriately weight the pthat bins +//********************************************************** + +int *countMCevents(std::string infile, std::string HFfile, bool usePUsub, int isMC){ + + TChain *ch = NULL; + if(usePUsub) ch = new TChain("akPu3PFJetAnalyzer/t"); + else ch = new TChain("ak3PFJetAnalyzer/t"); + std::ifstream instr(infile.c_str(), std::ifstream::in); + std::ifstream HFstr(HFfile.c_str(), std::ifstream::in); + std::string filename; + for(int ifile=0; ifile> filename; + ch->Add(filename.c_str()); + } + int *MCentries = new int[12]; + MCentries[0] = ch->GetEntries("pthat<15"); + MCentries[1] = ch->GetEntries("pthat>=15 && pthat<30"); + MCentries[2] = ch->GetEntries("pthat>=30 && pthat<50"); + MCentries[3] = ch->GetEntries("pthat>=50 && pthat<80"); + MCentries[4] = ch->GetEntries("pthat>=80 && pthat<120"); + MCentries[5] = ch->GetEntries("pthat>=120 && pthat<170"); + MCentries[6] = ch->GetEntries("pthat>=170 && pthat<220"); + MCentries[7] = ch->GetEntries("pthat>=220 && pthat<280"); + MCentries[8] = ch->GetEntries("pthat>=280 && pthat<370"); + MCentries[9] = ch->GetEntries("pthat>=370 && pthat<460"); + MCentries[10] = ch->GetEntries("pthat>=460 && pthat<540"); + MCentries[11] = ch->GetEntries("pthat>=540 && pthat<1200"); + + for(int i=0; i<12; i++){ + cout << "QCD MCentries[" << i << "]: " << MCentries[i] << endl; + } + + if(isMC>1){ + TChain *HFch = NULL; + if(usePUsub) HFch = new TChain("akPu3PFJetAnalyzer/t"); + else HFch = new TChain("ak3PFJetAnalyzer/t"); + for(int ifile=0; ifile> filename; + HFch->Add(filename.c_str()); + } + double *HFweight = NULL; + if(isMC==2) HFweight = heavyJetWeighting(HFfile,infile,HFpthatBins,QCDpthatBins,'b',usePUsub); + if(isMC==3) HFweight = heavyJetWeighting(HFfile,infile,HFpthatBins,QCDpthatBins,'c',usePUsub); + for(int i=0; i<11; i++){ + cout << "HFweight[" << i << "]: " << HFweight[i] << endl; + } + + double tempEntr[12] = {0,0,0,0,0,0,0,0,0,0,0,0}; + + tempEntr[0] = HFch->GetEntries("pthat<15"); + tempEntr[1] = HFch->GetEntries("pthat>=15 && pthat<30"); + tempEntr[2] = HFch->GetEntries("pthat>=30 && pthat<50"); + tempEntr[3] = HFch->GetEntries("pthat>=50 && pthat<80"); + tempEntr[4] = HFch->GetEntries("pthat>=80 && pthat<120"); + tempEntr[5] = HFch->GetEntries("pthat>=120 && pthat<170"); + tempEntr[6] = HFch->GetEntries("pthat>=170 && pthat<220"); + tempEntr[7] = HFch->GetEntries("pthat>=220 && pthat<280"); + tempEntr[8] = HFch->GetEntries("pthat>=280 && pthat<370"); + tempEntr[9] = HFch->GetEntries("pthat>=370 && pthat<460"); + tempEntr[10] = HFch->GetEntries("pthat>=460 && pthat<540"); + tempEntr[11] = HFch->GetEntries("pthat>=540 && pthat<1200"); + + for(int i=1; i<12; i++){ + cout << "HF entries[" << i << "]: " << tempEntr[i] << endl; + MCentries[i] += tempEntr[i]*HFweight[i-1]; + } + for(int i=0; i<12; i++){ + cout << "Effective MCentries[" << i << "]: " << MCentries[i] << endl; + } + } + + return MCentries; +} + //********************************************************** // Trigger-Combine the data in order to unfold properly later //********************************************************** @@ -104,9 +172,9 @@ double *heavyJetWeighting(std::string HFfile, std::string QCDfile, int HFnfiles, //[0] = Jet20, [1] = Jet40, [2] = Jet60, [3] = Jet80 double trigComb(bool *triggerDecision, double *pscl){ double weight=0; - if(triggerDecision[0] && !triggerDecision[1] && !triggerDecision[2] && !triggerDecision[3]) weight = 1./(1./pscl[0]); - if(triggerDecision[1] && !triggerDecision[2] && !triggerDecision[3]) weight = 1./(1./pscl[0] + 1./pscl[1] - (1./(pscl[0]*pscl[1]))); - if(triggerDecision[2] && !triggerDecision[3]) weight = 1./((1./pscl[0] + 1./pscl[1] + 1./pscl[2] - (1./(pscl[0]*pscl[1])) - (1./(pscl[1]*pscl[2])) - (1./(pscl[0]*pscl[2])) + (1./(pscl[0]*pscl[1]*pscl[2])))); + // if(triggerDecision[0] && !triggerDecision[1] && !triggerDecision[2] && !triggerDecision[3]) weight = 1./(1./pscl[0]); //Removing finnicky Jet20 sample + if(triggerDecision[1] && !triggerDecision[2] && !triggerDecision[3]) weight = 1./(1./pscl[1]); + if(triggerDecision[2] && !triggerDecision[3]) weight = 1./(1./pscl[1] + 1./pscl[2] - (1./(pscl[1]*pscl[2]))); if(triggerDecision[3]) weight = 1.; return weight; } @@ -175,22 +243,19 @@ bool DataSort(const JetObject &data1 , const JetObject &data2){ //* ~~ MAIN SEQUENCE ~~ * //********************************************************** -void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, int isMC=0, int doNtuples=1, int doJets=1, int doTracks=1, int updateJEC=0, int jetTrig=0, int cbin=-1, bool ExpandedTree=false, bool usePUsub=0) +void analyzeDijets(int isRecopp=1, int ppPbPb=0, int isMuTrig=0, int isMC=0, int doNtuples=1, int doJets=1, int doTracks=1, int updateJEC=0, int jetTrig=0, int cbin=-1, bool ExpandedTree=false, bool usePUsub=0) { - const int QCDpthatBins = 10; - const int HFpthatBins = 5; - int pthatbin[QCDpthatBins+1] = {30,50,80,120,170,220,280,370,460,540,10000}; - int nPthatEntries[QCDpthatBins+1] = {0,0,0,0,0,0,0,0,0,0,0}; + int pthatbin[QCDpthatBins+1] = {15,30,50,80,120,170,220,280,370,460,540,10000}; + int nPthatEntries[QCDpthatBins+1] = {0,0,0,0,0,0,0,0,0,0,0,0}; double w = 1.; double wght[QCDpthatBins+1]={0.2034, 1.075E-02, 1.025E-03, 9.865E-05, 1.129E-05, 1.465E-06, 2.837E-07, 5.323E-08, 5.934E-09, 8.125E-10, 1.467E-10}; double *pscls = NULL; - double *HFweight = NULL; int useWeight=1; // isMC=0 --> Real data, ==1 --> QCD, ==2 --> cJet, ==3 --> bJet - Float_t minJetPt=80; + Float_t minJetPt=15; //if(!ppPbPb) minJetPt=65; if (isMuTrig) minJetPt=30; Float_t maxJetEta=3; @@ -203,6 +268,7 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, if(!ppPbPb) cbin=-1; std::string infile; + std::string HFfile; TFile *fin = NULL; //PbPb File load if(ppPbPb){ @@ -219,14 +285,14 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, if(!isMC){ infile = "ppBForestList.txt"; } - else if(isMC==1){ + else if(isMC){ infile = "pythiaMCfilelist.txt"; - } - else if(isMC==2){ - infile = "pythiaBJetMClist.txt"; - } - else if(isMC==3){ - infile = "pythiaCJetMClist.txt"; + if(isMC==2){ + HFfile = "pythiaBJetMClist.txt"; + } + else if(isMC==3){ + HFfile = "pythiaCJetMClist.txt"; + } } else{ cout << "I don't understand this MC number!" << endl; @@ -234,7 +300,7 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, } } if(!isMC && !ppPbPb){ - pscls = getPscls(infile,nFiles,usePUsub); + pscls = getPscls(infile,QCDpthatBins,usePUsub); } int *MCentr = NULL; @@ -245,6 +311,7 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, //Declaration of leaves types Int_t evt; + Int_t lumi; Int_t bin; Float_t hf; Int_t run; @@ -644,7 +711,6 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, Double_t t_jtpt[3], t_jteta[3], t_jtphi[3], t_rawpt[3], t_refpt[3], t_refparton_flavorForB[3], t_discr_prob[3], t_discr_ssvHighEff[3], t_discr_ssvHighPur[3], t_discr_csvSimple[3], t_svtxm[3]; Double_t t_pthat, t_bin, t_weight; - Int_t t_HLT_Jet20, t_HLT_Jet40, t_HLT_Jet60, t_HLT_Jet80, t_HLT_Jet100; Int_t t_nIP[3]; Double_t t_ipPt[3][100], t_ipProb0[3][100]; @@ -704,11 +770,11 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, nt->Branch("ipJetIndex3",t_ipJetIndex[2],"ipJetIndex3[nIP3]/I"); } if(!ppPbPb){ - nt->Branch("HLT_Jet20_noJetID_v1",&t_HLT_Jet20,"HLT_Jet20_noJetID_v1/I"); - nt->Branch("HLT_Jet40_noJetID_v1",&t_HLT_Jet40,"HLT_Jet40_noJetID_v1/I"); - nt->Branch("HLT_Jet60_noJetID_v1",&t_HLT_Jet60,"HLT_Jet60_noJetID_v1/I"); - nt->Branch("HLT_Jet80_noJetID_v1",&t_HLT_Jet80,"HLT_Jet80_noJetID_v1/I"); - nt->Branch("HLT_Jet100_noJetID_v1",&t_HLT_Jet100,"HLT_Jet100_noJetID_v1/I"); + nt->Branch("HLT_Jet20_noJetID_v1",&HLT_PAJet20_NoJetID_v1,"HLT_Jet20_noJetID_v1/I"); + nt->Branch("HLT_Jet40_noJetID_v1",&HLT_PAJet40_NoJetID_v1,"HLT_Jet40_noJetID_v1/I"); + nt->Branch("HLT_Jet60_noJetID_v1",&HLT_PAJet60_NoJetID_v1,"HLT_Jet60_noJetID_v1/I"); + nt->Branch("HLT_Jet80_noJetID_v1",&HLT_PAJet80_NoJetID_v1,"HLT_Jet80_noJetID_v1/I"); + nt->Branch("HLT_Jet100_noJetID_v1",&HLT_PAJet100_NoJetID_v1,"HLT_Jet100_noJetID_v1/I"); nt->Branch("pVertexFilterCutGplusUpsPP",&pVertexFilterCutGplusUpsPP,"pVertexFilterCutGplusUpsPP/I"); } nt->Branch("pthat",&t_pthat,"pthat/D"); @@ -742,25 +808,50 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, } std::ifstream instr(infile.c_str(), std::ifstream::in); + std::ifstream HFstr; + if(isMC>1) HFstr.open(HFfile.c_str(), std::ifstream::in); std::string filename; + int nFiles=0; + if(ppPbPb) nFiles=1; + else if(isMC){ + nFiles=QCDpthatBins; + if(isMC>1) nFiles+=HFpthatBins; + } + else{ + nFiles=dataFiles; + } for(int ifile=0; ifile> filename; - std::cout << "File: " << filename << std::endl; - fin = TFile::Open(filename.c_str()); - - TTree *t = (TTree*) fin->Get("akPu3PFJetAnalyzer/t"); - //TTree *t = (TTree*) fin->Get("ak5PFJetAnalyzer/t"); //for ppReco_jetTrig + + //Add b/c statistics to the HF statistics + if(!ppPbPb){ + if((isMC && ifile> filename; + } + else if(isMC && ifile>=QCDpthatBins){ + HFstr >> filename; + } + std::cout << "File: " << filename << std::endl; + fin = TFile::Open(filename.c_str()); + } + TTree *t; + if(usePUsub) t = (TTree*) fin->Get("akPu3PFJetAnalyzer/t"); + else t = (TTree*) fin->Get("ak3PFJetAnalyzer/t"); TTree *tSkim = (TTree*) fin->Get("skimanalysis/HltTree"); - TTree *tEvt = (TTree*) fin->Get("hiEvtAnalyzer/HiTree"); + TTree *tEvt = NULL; + if(!ppPbPb) tEvt = (TTree*) fin->Get("hiEvtAnalyzer/HiTree"); + TTree *tHlt = NULL; + if(!ppPbPb) tHlt = (TTree*) fin->Get("hltanalysis/HltTree"); TTree *tmu = (TTree*) fin->Get("muonTree/HLTMuTree"); - if(!t || !tSkim || !tEvt){ cout << "Warning! Can't find one of the trees!" << endl; exit(0);} - + if(!t || !tSkim || (!tEvt&&!ppPbPb) || (!tHlt&&!ppPbPb)){ cout << "Error! Can't find one of the trees!" << endl; exit(0);} + if(tEvt) t->AddFriend("hiEvtAnalyzer/HiTree"); - t->AddFriend("hltanalysis/HltTree"); + if(tHlt) t->AddFriend("hltanalysis/HltTree"); + if(tSkim) t->AddFriend("skimanalysis/HltTree"); t->SetBranchAddress("evt",&evt); - if(cbin != -1) t->SetBranchAddress("bin",&bin); + t->SetBranchAddress("lumi",&lumi); + if(cbin != -1 || ppPbPb) t->SetBranchAddress("bin",&bin); + if(!isMC) t->SetBranchAddress("run",&run); t->SetBranchAddress("vz",&vz); t->SetBranchAddress("nref",&nref); if(ppPbPb) t->SetBranchAddress("hf",&hf); @@ -838,14 +929,15 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, } } if(!ppPbPb && !useWeight && ifile==0){ - MCentr = countMCevents(infile, nFiles, usePUsub); - if(isMC>1){ - for(int lm=HFpthatBins+1; lm1){ + // for(int lm=HFpthatBins+2; lmSetBranchAddress("Run",&run); + if(ppPbPb && !isMC) tmu->SetBranchAddress("Run",&run); + if(!ppPbPb) t->SetBranchAddress("pVertexFilterCutGplusUpsPP",&pVertexFilterCutGplusUpsPP); if(ppPbPb){ t->SetBranchAddress("nHLTBit",&nHLTBit); @@ -874,16 +967,10 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, t->SetBranchAddress("HLT_PAJet60_NoJetID_v1",&HLT_PAJet60_NoJetID_v1); t->SetBranchAddress("HLT_PAJet80_NoJetID_v1",&HLT_PAJet80_NoJetID_v1); t->SetBranchAddress("HLT_PAJet100_NoJetID_v1",&HLT_PAJet100_NoJetID_v1); - t->SetBranchAddress("pVertexFilterCutGplusUpsPP",&pVertexFilterCutGplusUpsPP); t->SetBranchAddress("pPAcollisionEventSelectionPA",&pPAcollisionEventSelectionPA); t->SetBranchAddress("pHBHENoiseFilter",&pHBHENoiseFilter); t->SetBranchAddress("pprimaryvertexFilter",&pprimaryvertexFilter); } - - if(tSkim && ppPbPb) tSkim->SetBranchAddress("pvSel",&pvSel); - if(tSkim && !ppPbPb) tSkim->SetBranchAddress("pHBHENoiseFilter",&hbheNoiseSel); - if(tSkim && ppPbPb) tSkim->SetBranchAddress("spikeSel",&spikeSel); - if(tSkim && ppPbPb) tSkim->SetBranchAddress("collSell",&collSell); Long64_t nentries = t->GetEntries(); cout << "entries: "<< nentries << endl; @@ -891,7 +978,7 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, for (Long64_t i=0; iGetEntries(); i++) { if (i%100000==0) std::cout<<" i = "<GetEntries()<<" ("<<(int)(100*(float)i/(float)t->GetEntries())<<"%)"<GetEntry(i); + if(ppPbPb) tSkim->GetEntry(i); t->GetEntry(i); if(ppPbPb && isMC){ // temporarily remove cuts from MC @@ -905,6 +992,15 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, continue; } } + + //cout << "entry " << i << endl; + //cout << "temp1" << endl; + + //Cut to remove events that correspond to the twiki "good events" but not the golden lumi filter + if(!isMC){ + if(((int)run==211821 && lumi>=57 && lumi<370) || ((int)run==211821 && lumi>420)) continue; + } + if(!ppPbPb){ if(!isMC){ if(!pHBHENoiseFilter || !pprimaryvertexFilter || !pPAcollisionEventSelectionPA) continue; @@ -914,6 +1010,8 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, } } + if(!HLT_PAJet40_NoJetID_v1 && !HLT_PAJet60_NoJetID_v1 && !HLT_PAJet80_NoJetID_v1) continue; + if(ppPbPb){ if(cbin==-1){ // do nothing @@ -932,6 +1030,10 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, return; } } + if(ppPbPb) t_bin=bin; + else t_bin=39; + + //cout << "temp2" << endl; if(isMC&&!ppPbPb){ if(beamId1==2112 || beamId2==2112) continue; @@ -966,6 +1068,9 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, for(int ij=0;ij65.&&fabs(jteta[ij])<2.)cout<<" # associated tracks = "<GetEntry(i); @@ -1011,6 +1116,8 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, if(foundEvt) continue; } + // cout << "temp4" << endl; + //trigger weighting in PbPb (pthat weighting already done in PbPb) if(useWeight){ if(isMC)w=weight; @@ -1023,21 +1130,15 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, } //trigger weighting in pp data if(!ppPbPb && !isMC){ - bool trgDec[4] = {(bool)t_HLT_Jet20, (bool)t_HLT_Jet40, (bool)t_HLT_Jet60, (bool)t_HLT_Jet80}; + bool trgDec[4] = {(bool)HLT_PAJet20_NoJetID_v1, (bool)HLT_PAJet40_NoJetID_v1, (bool)HLT_PAJet60_NoJetID_v1, (bool)HLT_PAJet80_NoJetID_v1}; w = trigComb(trgDec, pscls); } //pthat weighting in MC - if(isMC && !useWeight){ + if(isMC){ t_pthat=pthat; int j=0; while(pthat>pthatbin[j] && j10) cout << "uh oh" << endl; - if(isMC>1){ - int k = (j<=HFpthatBins ? j : HFpthatBins); - w = (wght[k]/MCentr[k]); - w *= HFweight[k]; //do HF reweighting for b/c samples - } - else w = (wght[j]/MCentr[j]); + w = (wght[j-1]/MCentr[j]); //wght[0] = pthat>15, MCentr[0] = pthat<15. I know it's dumb - bear with me. } t_weight=w; @@ -1048,22 +1149,16 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, else trigIndex=0; } + // cout << "temp5" << endl; + int useEvent=0; int trackPosition =0; - - //Set Event-level variables - if(ppPbPb) t_bin=bin; - else t_bin=39; - t_HLT_Jet20=HLT_PAJet20_NoJetID_v1; - t_HLT_Jet40=HLT_PAJet40_NoJetID_v1; - t_HLT_Jet60=HLT_PAJet60_NoJetID_v1; - t_HLT_Jet80=HLT_PAJet80_NoJetID_v1; - t_HLT_Jet100=HLT_PAJet100_NoJetID_v1; //Now deal with jet-level variables for(int ij=0;ijminJetPt && fabs(jteta[ij])Fill(ip2d1MostSig,w); @@ -1510,6 +1611,9 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, } } //end jet loop + + // cout <<"exit jet loop "<< endl; + // cout <<"temp10" << endl; //Finally fill TTree from vector of jet objects if(doNtuples){ @@ -1542,6 +1646,7 @@ void analyzeDijets(int nFiles=10, int isRecopp=1, int ppPbPb=0, int isMuTrig=0, Jetvector.clear(); } } + //cout << "temp11" << endl; if(ppPbPb && useEvent){ if(isMC){ diff --git a/analyzeTrees.C b/analyzeTrees.C index 3234275..4a489e2 100644 --- a/analyzeTrees.C +++ b/analyzeTrees.C @@ -10,7 +10,6 @@ #include "TNtuple.h" #include "TROOT.h" #include "TChain.h" -#include "TMath.h" //These includes cause some complications in CMSSW_5_3_8_HI_patchX. Commented out for pp. //If you want to recalculate the JECs on the fly again, just uncomment everything in the updateJEC blocks @@ -226,7 +225,7 @@ double* getPscls(std::string infile, int nFiles, bool usePUsub){ // ~~~ MAIN PROGRAM ~~~ //********************************************************** -void analyzeTrees(int isRecopp=1, int ppPbPb=0, int isMuTrig=0, int isMC=0, int doNtuples=1, int doJets=1, int doTracks=1, int updateJEC=0, int cbin=-1, int useGSP=0, int jetTrig=0, bool ExpandedTree=false, bool usePUsub=0) +void analyzeTrees(int isRecopp=1, int ppPbPb=0, int isMuTrig=0, int isMC=1, int doNtuples=1, int doJets=1, int doTracks=1, int updateJEC=0, int cbin=-1,int useGSP=2, int jetTrig=0, bool ExpandedTree=false, bool usePUsub=0) { // isMC=0 --> Real data, ==1 --> QCD, ==2 --> bJet, ==3 --> cJet Float_t minJetPt=15.; @@ -243,7 +242,7 @@ void analyzeTrees(int isRecopp=1, int ppPbPb=0, int isMuTrig=0, int isMC=0, int int useWeight=1; //Get vz weight histograms for MC if needed - TH1D *hMCvz[2], *hDatavz; + TH1D *hMCvz[2], hDatavz; TFile *fMCvz, *fDatavz, *fBvz; if(isMC){ fMCvz = new TFile("MCvzDistr.root"); @@ -825,7 +824,6 @@ void analyzeTrees(int isRecopp=1, int ppPbPb=0, int isMuTrig=0, int isMC=0, int std::ifstream HFstr(HFfile.c_str(), std::ifstream::in); std::string filename; int nFiles=0; - int vzReject=0, vzPass=0; if(ppPbPb) nFiles=1; else if(isMC){ nFiles=QCDpthatBins; @@ -1069,11 +1067,7 @@ void analyzeTrees(int isRecopp=1, int ppPbPb=0, int isMuTrig=0, int isMC=0, int if(jetTrig==2&&!hltBit[9]) continue; } - if(fabs(vz)>15.){ - vzReject++; - continue; - } - else vzPass++; + if(fabs(vz)>15.) continue; // pileup rejection if(ppPbPb && hf>150000.){ @@ -1171,6 +1165,7 @@ void analyzeTrees(int isRecopp=1, int ppPbPb=0, int isMuTrig=0, int isMC=0, int if(isMC){ bool isFiltered=0; if(isMC>1) isFiltered=1; + double vzWeight=0; int vzbin = (int) TMath::Ceil(vz+15.+0.4); // 0.4 is the pixel detector shift if(vzbin>0&&vzbin<=30)vzWeight = hDatavz->GetBinContent(vzbin)/hMCvz[isFiltered]->GetBinContent(vzbin); t_weight=w*vzWeight; @@ -1655,9 +1650,6 @@ void analyzeTrees(int isRecopp=1, int ppPbPb=0, int isMuTrig=0, int isMC=0, int } } - cout << "vz Pass: " << vzPass << endl; - cout << "vz Fail: " << vzReject << endl; - cout << "vzEff: "<< (double)vzPass/((double)vzPass+(double)vzReject) << endl; fout->cd(); hbin->Write(); hbinw->Write(); hvz->Write(); hvzw->Write(); diff --git a/bfractionVsJetPtPP.C b/bfractionVsJetPtPP.C index 576f469..51c2630 100644 --- a/bfractionVsJetPtPP.C +++ b/bfractionVsJetPtPP.C @@ -133,10 +133,9 @@ TFile *fQCDMC, *fBMC, *fCMC, *fdata; TTree *tQCDMC, *tBMC, *tCMC, *tdata; // declare counter histos -TH1D *hTaggedLJetsMC,*hTaggedCJetsMC, *hTaggedBJetsMC, *hTaggedJetsMC, *hUntaggedLJetsMC, *hUntaggedCJetsMC, *hUntaggedBJetsMC, *hUntaggedJetsMC, *hBjetsWithJPinfoMC, *hBjetsWithCSVinfoMC, *hTaggedJetsData, *hUntaggedJetsData; - -RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, double minXdiscr, double maxXdiscr, std::string comment, double maxYaxis, bool toyMC, bool verbose); +TH1D *hTaggedLJetsMC,*hTaggedCJetsMC, *hTaggedBJetsMC, *hTaggedJetsMC, *hUntaggedLJetsMC, *hUntaggedCJetsMC, *hUntaggedBJetsMC, *hUntaggedgJetsMC, *hBjetsWithJPinfoMC, *hBjetsWithCSVinfoMC, *hTaggedJetsData, *hUntaggedJetsData, *hUntaggedJetsMC; +RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, double minXdiscr, double maxXdiscr, std::string comment, double maxYaxis, bool toyMC, bool useDataBGtemplate, bool verbose); void fillCounterHistos(std::string discr, double workingPoint, int cbinlo, int cbinhi, float etalo, float etahi); @@ -145,13 +144,15 @@ Enumerations count(double ptMin, double ptMax); const int nBins = 7; double ptBin[nBins+1] = {60,70,80,90,110,130,170,250}; //const int nBins = 4; -//double ptBin[nBins+1] = {80,100,120,150,200}; +//double ptBin[nBins+1] = {80,100,130,170,250}; //const int nBins = 1; -//double ptBin[nBins+1] = {60,70}; +//double ptBin[nBins+1] = {110,250}; ///XXXX -void bfractionVsJetPtPP(std::string tagger="discr_ssvHighEff", double workingPoint=2.0, int fixCL=1, std::string taggerName="SSVHE", int cbinlo=0, int cbinhi=40, float etalo=0., float etahi=2., bool verbose = true) { +void bfractionVsJetPtPP(std::string tagger="discr_ssvHighEff", double workingPoint=2.0, int fixCL=0, std::string taggerName="SSVHE", int cbinlo=0, int cbinhi=40, float etalo=0., float etahi=2., bool useDataBGtemplate = false, bool verbose = true) { + + if(useDataBGtemplate) fixCL=1; parameters p; p.fixCL = fixCL; @@ -181,10 +182,10 @@ void bfractionVsJetPtPP(std::string tagger="discr_ssvHighEff", double workingPoi gStyle->SetTitleOffset(1.5,"xy"); */ - fQCDMC = new TFile("histos/ppMC_ppReco_ak3PF_QCDjetTrig_noIPupperCut.root"); - fBMC = new TFile("histos/ppMC_ppReco_ak3PF_BjetTrig_noIPupperCut.root"); - fCMC = new TFile("histos/ppMC_ppReco_ak3PF_CjetTrig_noIPupperCut.root"); - fdata = new TFile("histos/ppdata_ppReco_ak3PF_jetTrig_noIPupperCut.root"); + fQCDMC = new TFile("histos/ppMC_ppReco_ak3PF_gsp3_QCDjetTrig_noIPupperCut.root"); + fBMC = new TFile("histos/ppMC_ppReco_ak3PF_gsp3_BjetTrig_noIPupperCut.root"); + fCMC = new TFile("histos/ppMC_ppReco_ak3PF_gsp3_CjetTrig_noIPupperCut.root"); + fdata = new TFile("histos/ppdata_ppReco_ak3PF_DinkoXchk_gsp3_jetTrig_noIPupperCut.root"); tQCDMC = (TTree*) fQCDMC->Get("nt"); tBMC = (TTree*) fBMC->Get("nt"); @@ -256,7 +257,7 @@ void bfractionVsJetPtPP(std::string tagger="discr_ssvHighEff", double workingPoi c1->cd(n+1); p.ptMin = ptBin[n]; p.ptMax = ptBin[n+1]; - RooRealVar *fitSvtxmTag = bfractionFit(p,"svtxm",tagger,workingPoint,6,"b-tagged sample (SSVHE > 2)",9e3,doToyCalc,verbose); + RooRealVar *fitSvtxmTag = bfractionFit(p,"svtxm",tagger,workingPoint,6,"b-tagged sample (SSVHE > 2)",9e3,doToyCalc, useDataBGtemplate, verbose); //c2->cd(n+1); //c2->GetPad(n+1)->SetLogy(); @@ -269,14 +270,14 @@ void bfractionVsJetPtPP(std::string tagger="discr_ssvHighEff", double workingPoi if (doLTJP) { c3->cd(n+1); //c3->GetPad(n+1)->SetLogy(); - fitJpBeforetag = bfractionFit(p,"discr_prob","discr_prob",0,3.,"jets with JP info",4e5,doToyCalc,verbose); + fitJpBeforetag = bfractionFit(p,"discr_prob","discr_prob",0.,6.,"jets with JP info",4e5,doToyCalc,false,verbose); c4->cd(n+1); //c4->GetPad(n+1)->SetLogy(); - fitJpTag = bfractionFit(p,"discr_prob",tagger,workingPoint,6,"b-tagged sample (SSVHE > 2)",4e5,doToyCalc,verbose); + fitJpTag = bfractionFit(p,"discr_prob",tagger,workingPoint,6,"b-tagged sample (SSVHE > 2)",4e5,doToyCalc,false,verbose); } if (doLTCSV) { - fitCsvBeforetag = bfractionFit(p,"discr_csvSimple",tagger,-2,10,"jets with CSV info",4e5,doToyCalc,verbose); - fitCsvTag = bfractionFit(p,"discr_csvSimple",tagger,workingPoint,10,Form("b-tagged sample (%s > %.1f)",taggerName.c_str(),workingPoint),4e5,doToyCalc,verbose); + fitCsvBeforetag = bfractionFit(p,"discr_csvSimple",tagger,-2,10,"jets with CSV info",4e5,doToyCalc,false,verbose); + fitCsvTag = bfractionFit(p,"discr_csvSimple",tagger,workingPoint,10,Form("b-tagged sample (%s > %.1f)",taggerName.c_str(),workingPoint),4e5,doToyCalc,false,verbose); } taggedFracData = numbers.nTaggedJetsData / numbers.nJetsData; @@ -315,7 +316,8 @@ void bfractionVsJetPtPP(std::string tagger="discr_ssvHighEff", double workingPoi hBEfficiencyMC->SetBinError(n+1,bEffMCError); if (doLTJP) { - bEffDataLTJP = taggedFracData * numbers.cbForJP * fitJpTag->getVal() / fitJpBeforetag->getVal(); + //bEffDataLTJP = taggedFracData * numbers.cbForJP * fitJpTag->getVal() / fitJpBeforetag->getVal(); + bEffDataLTJP = taggedFracData * fitJpTag->getVal() / fitJpBeforetag->getVal(); bEffDataLTJPError = prodError(taggedFracData,fitJpTag->getVal(),taggedFracDataError,fitJpTag->getError()) * numbers.cbForJP / fitJpBeforetag->getVal(); hBEfficiencyDataLTJP->SetBinContent(n+1,bEffDataLTJP); hBEfficiencyDataLTJP->SetBinError(n+1,bEffDataLTJPError); @@ -389,6 +391,7 @@ void bfractionVsJetPtPP(std::string tagger="discr_ssvHighEff", double workingPoi cout<<"bFracDataLTJP "<getVal()<Draw(); //cBFraction->SaveAs("ssvheFracpp.pdf"); - - TFile *fout = new TFile(Form("output/NewFormatV5_bFractionMCTemplate_pppp1_%sat%.1fFixCL%d_bin_%d_%d_eta_%d_%d.root",taggerName.c_str(),workingPoint,fixCL,cbinlo,cbinhi,(int)etalo,(int)etahi),"recreate"); + string mcDataString = "MC"; + if(useDataBGtemplate) mcDataString = "Data"; + + TFile *fout = new TFile(Form("output/NewFormatV5_bFraction%sTemplate_pppp1_gspDown_jetcut30_dinkoXchk_%sat%.1fFixCL%d_bin_%d_%d_eta_%d_%d.root",mcDataString.c_str(),taggerName.c_str(),workingPoint,fixCL,cbinlo,cbinhi,(int)etalo,(int)etahi),"recreate"); hBFractionMC->Write(); hBFractionData->Write(); @@ -543,7 +548,7 @@ void fixEmpty(TH1 *h){ } } -RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, double minXdiscr, double maxXdiscr, std::string comment, double maxYaxis, bool toyMC, bool verbose) +RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, double minXdiscr, double maxXdiscr, std::string comment, double maxYaxis, bool toyMC, bool useDataBGtemplate, bool verbose) { bool fixCL = p.fixCL; int cbinlo = p.cbinlo; @@ -578,39 +583,30 @@ RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, doubl TH1D *hB = new TH1D("hB","hB",nhistBins,minXvar,maxXvar); hB->Sumw2(); - tBMC->Draw(Form("%s>>hB",var.c_str()),Form("weight*(abs(refparton_flavorForB)==5&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&pthat>%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,cbinlo,cbinhi,etalo,etahi,ptHatMin)); - //tBMC->Draw(Form("%s>>hB",var),Form("weight*(abs(refparton_flavorForB)==5&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr,cbinlo,cbinhi,etalo,etahi)); - + tBMC->Draw(Form("%s>>hB",var.c_str()),Form("weight*(abs(refparton_flavorForB)==5&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&pthat>%f&&refpt>30)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,cbinlo,cbinhi,etalo,etahi,ptHatMin)); fixEmpty(hB); TH1D *hC = new TH1D("hC","hC",nhistBins,minXvar,maxXvar); hC->Sumw2(); - tCMC->Draw(Form("%s>>hC",var.c_str()),Form("weight*(abs(refparton_flavorForB)==4&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&pthat>%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,cbinlo,cbinhi,etalo,etahi,ptHatMin)); - //tCMC->Draw(Form("%s>>hC",var),Form("weight*(abs(refparton_flavorForB)==4&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr,cbinlo,cbinhi,etalo,etahi)); + tCMC->Draw(Form("%s>>hC",var.c_str()),Form("weight*(abs(refparton_flavorForB)==4&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&pthat>%f&&refpt>30)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,cbinlo,cbinhi,etalo,etahi,ptHatMin)); fixEmpty(hC); TH1D *hL = new TH1D("hL","hL",nhistBins,minXvar,maxXvar); hL->Sumw2(); - tQCDMC->Draw(Form("%s>>hL",var.c_str()),Form("weight*(abs(refparton_flavorForB)!=5&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)<99&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&pthat>%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,cbinlo,cbinhi,etalo,etahi,ptHatMin)); - //tQCDMC->Draw(Form("%s>>hL",var),Form("weight*(abs(refparton_flavorForB)!=5&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)<99&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr,cbinlo,cbinhi,etalo,etahi)); + tQCDMC->Draw(Form("%s>>hL",var.c_str()),Form("weight*(abs(refparton_flavorForB)!=5&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)<99&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&pthat>%f&&refpt>30)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,cbinlo,cbinhi,etalo,etahi,ptHatMin)); fixEmpty(hL); - /* - TH1D *hCaux = new TH1D("hCaux","",nhistBins,minXvar,maxXvar); - hCaux->Sumw2(); - tQCDMC->Draw(Form("%s>>hCaux",var),Form("weight*(abs(refparton_flavorForB)==4&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr,cbinlo,cbinhi,etalo,etahi)); - fixEmpty(hCaux); - */ - /* - TH1D *hCL = new TH1D("hCL","",nhistBins,minXvar,maxXvar); - hCL->Sumw2(); - tQCDMC->Draw(Form("%s>>hCL",var),Form("weight*(abs(refparton_flavorForB)!=5&&abs(refparton_flavorForB)<99&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr,cbinlo,cbinhi,etalo,etahi)); - fixEmpty(hCL); - //*/ - //* - TH1D *hCL = (TH1D*) hL->Clone(); - //Double_t cCoef = hCaux->Integral()/hC->Integral(); - hCL->Add(hC); + TH1D *hCL = NULL; + if(useDataBGtemplate){ + hCL = new TH1D("hCL","hCL",nhistBins,minXvar,maxXvar); + hCL->Sumw2(); + tdata->Draw(Form("%s>>hCL",var.c_str()),Form("weight*(discr_prob<0.5&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>=%f&&abs(jteta)<%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,cbinlo,cbinhi,etalo,etahi)); + } + else{ + hCL = (TH1D*) hL->Clone(); + hCL->Add(hC); + } + fixEmpty(hCL); //*/ @@ -645,12 +641,12 @@ RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, doubl //Double_t bInitFrac = hB->Integral()/(hB->Integral()+hCL->Integral()); //Double_t cInitFrac = hC->Integral()/(hB->Integral()+hCL->Integral()); - double fracGuess=0.3; - if(var != "svmtx") fracGuess =0.01; + double fracGuess=0.03; + if(var != "svtxm") fracGuess =0.01; /* double bGuess = 0.03; double cGuess = 0.1; - if(var != "svmtx"){ + if(var != "svtxm"){ bGuess =0.01; cGuess =0.05; } @@ -762,9 +758,9 @@ RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, doubl hData[counter]->Sumw2(); hMCL[counter]->Sumw2(); hMCB[counter]->Sumw2(); hMCC[counter]->Sumw2(); hMCLC[counter]->Sumw2(); - tBMC->Draw(Form("%s>>hMCB_%d",var.c_str(),counter),Form("weight*(abs(refparton_flavorForB)==5&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&pthat>%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,ptHatMin),"goff"); - tCMC->Draw(Form("%s>>hMCC_%d",var.c_str(),counter),Form("weight*(abs(refparton_flavorForB)==4&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&pthat>%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,ptHatMin),"goff"); - tQCDMC->Draw(Form("%s>>hMCL_%d",var.c_str(),counter),Form("weight*(abs(refparton_flavorForB)!=5&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)<99&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&pthat>%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,ptHatMin),"goff"); + tBMC->Draw(Form("%s>>hMCB_%d",var.c_str(),counter),Form("weight*(abs(refparton_flavorForB)==5&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&pthat>%f&&refpt>30)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,ptHatMin),"goff"); + tCMC->Draw(Form("%s>>hMCC_%d",var.c_str(),counter),Form("weight*(abs(refparton_flavorForB)==4&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&pthat>%f&&refpt>30)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,ptHatMin),"goff"); + tQCDMC->Draw(Form("%s>>hMCL_%d",var.c_str(),counter),Form("weight*(abs(refparton_flavorForB)!=5&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)<99&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&pthat>%f&&refpt>30)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,ptHatMin),"goff"); /* tBMC->Draw(Form("%s>>hMCB_%d",var,counter),Form("weight*(abs(refparton_flavorForB)==5&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f)",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr),"goff"); @@ -805,6 +801,7 @@ RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, doubl hData[counter]->GetXaxis()->CenterTitle(); hData[counter]->GetYaxis()->CenterTitle(); hData[counter]->GetYaxis()->SetTitle(yTitle); + hData[counter]->SetTitleOffset(1.3); hData[counter]->GetXaxis()->SetTitle(xTitle); hData[counter]->SetMarkerStyle(8); hData[counter]->SetMarkerSize(1.5); @@ -915,7 +912,7 @@ RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, doubl Double_t chi2 = hData[counter]->Chi2Test(MCTotal[counter],"WW CHI2 P"); Double_t chi2NDF = hData[counter]->Chi2Test(MCTotal[counter],"WW CHI2/NDF P"); MCTotal[counter]->Draw("same,e"); - MCSumGreen[counter]->Draw("same,e"); + // MCSumGreen[counter]->Draw("same,e"); // TH1F *hTaggedJetsMC = (TH1F*)hTaggedLJetsMC->Clone("hTaggedJetsMC"); @@ -932,6 +929,7 @@ RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, doubl } hData[counter]->Draw("same"); can1[counter]->GetFrame()->SetLineWidth(4); + can1[counter]->RedrawAxis(); TLegend *hleg = new TLegend(0.63,fixCL?0.70:0.75,0.883,fixCL?0.92:0.92); hleg->SetBorderSize(0); @@ -949,21 +947,21 @@ RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, doubl } hleg->Draw("same"); - drawText(Form("%2.0f < p_{T} < %2.0f GeV/c",ptMin,ptMax),0.63,0.684); + drawText(Form("%2.0f < p_{T} < %2.0f GeV/c",ptMin,ptMax),0.60,0.684); //if(fixCL)drawText(Form("%2.0f < p_{T} < %2.0f GeV/c",ptMin,ptMax),0.50,0.66); //drawText(Form("#chi^{2}/NDF = %3.1f / %d",chi2NDF,nXbins-1),0.53,0.55); - drawText(Form("#chi^{2}/NDF = %3.1f / %d",chi2,(int)(chi2/chi2NDF)),0.632,0.615); - drawText("CMS Preliminary",0.15,0.965); - drawText("#sqrt{s_{NN}} = 2.76 TeV",0.60,0.969); - drawText("|#eta| < 2.0",0.18,0.88); + //drawText(Form("#chi^{2}/NDF = %3.1f / %d",chi2,(int)(chi2/chi2NDF)),0.632,0.615); + drawText("CMS",0.17,0.965); + drawText("#sqrt{s_{NN}} = 2.76 TeV",0.70,0.965); + drawText("|#eta| < 2.0",0.2,0.88); if(comment!="b-tagged sample (SSVHE > 2)") drawText(comment,0.18,0.80); if(comment=="b-tagged sample (SSVHE > 2)"){ - drawText("b-tagged sample",0.18,0.80); + //drawText("b-tagged sample",0.18,0.80); //drawText("(SSVHE > 2)",0.18,0.75); } - bool printEach=false; + bool printEach=true; // --- Print results --- //cout <<"b jet fraction in MC = "<Print(Form("PDFS/fitpp_fixcl_%s_%f%s_%s.pdf",varLabel.c_str(),minXdiscr,fixCLlabel.c_str(),ptLabel.c_str()),"pdf"); - if (printEach) can1[counter]->Print(Form("MACROS/fitpp_%s_%f%s_%s.C",varLabel.c_str(),minXdiscr,fixCLlabel.c_str(),ptLabel.c_str()),"cxx"); + if (printEach) can1[counter]->Print(Form("PDFS/fitpp_forpPb_%s_%f%s_%s.pdf",varLabel.c_str(),minXdiscr,fixCLlabel.c_str(),ptLabel.c_str()),"pdf"); + if (printEach) can1[counter]->Print(Form("MACROS/fitpp_forpPb_%s_%f%s_%s.C",varLabel.c_str(),minXdiscr,fixCLlabel.c_str(),ptLabel.c_str()),"cxx"); } if(!fixCL){ if (!printEach){ - if (counterPrint("PDFS/bTagStackedHistos_nofixCL_NewFormatV5.pdf(","pdf"); - if (counter==nBins*3-1) can1[counter]->Print("PDFS/bTagStackedHistos_nofixCL_NewFormatV5.pdf)","pdf"); + if (counterPrint("PDFS/bTagStackedHistos_nofixCL_forpPb_NewFormatV5.pdf(","pdf"); + if (counter==nBins*3-1) can1[counter]->Print("PDFS/bTagStackedHistos_nofixCL_forpPb_NewFormatV5.pdf)","pdf"); } } if(fixCL){ if (!printEach){ - if (counterPrint("PDFS/bTagStackedHistos_fixCL_NewFormatV5.pdf(","pdf"); - if (counter==nBins*3-1) can1[counter]->Print("PDFS/bTagStackedHistos_fixCL_NewFormatV5.pdf)","pdf"); + if (counterPrint("PDFS/bTagStackedHistos_fixCL_forpPb_NewFormatV5.pdf(","pdf"); + if (counter==nBins*3-1) can1[counter]->Print("PDFS/bTagStackedHistos_fixCL_forpPb_NewFormatV5.pdf)","pdf"); } } counter++; @@ -1018,7 +1016,7 @@ RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, doubl // --- Save canvas --- - TString path = Form("gifs/%s_jtpt%.0fto%.0f_%s%.2fto%.2f_%s.gif",var.c_str(),ptMin,ptMax,discr.c_str(),minXdiscr,maxXdiscr,fixCL?"CLfixed":"CLfree"); + TString path = Form("gifs/%s_forpPb_jtpt%.0fto%.0f_%s%.2fto%.2f_%s.gif",var.c_str(),ptMin,ptMax,discr.c_str(),minXdiscr,maxXdiscr,fixCL?"CLfixed":"CLfree"); //cROOFIT->SaveAs(path); // ========== Toy check on MC template ========== @@ -1094,21 +1092,22 @@ void format1D(TH1& h1, TCanvas& c1 ){ } void fillCounterHistos(std::string discr, double workingPoint, int cbinlo, int cbinhi, float etalo, float etahi) { + + cout << "diagnostics: "<< endl; + cout << "discr: "<< discr << endl; + cout << "working point: "<< workingPoint << endl; hTaggedLJetsMC = new TH1D("hTaggedLJetsMC","hTaggedLJetsMC",nBins,ptBin); hTaggedLJetsMC->Sumw2(); - tQCDMC->Draw("jtpt>>hTaggedLJetsMC",Form("weight*(%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)!=5)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); - //tQCDMC->Draw("jtpt>>hTaggedLJetsMC",Form("weight*(%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)!=5)",discr,workingPoint,cbinlo,cbinhi,etalo,etahi)); + tQCDMC->Draw("jtpt>>hTaggedLJetsMC",Form("weight*(%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)!=5&&refpt>30)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); hTaggedCJetsMC = new TH1D("hTaggedCJetsMC","hTaggedCJetsMC",nBins,ptBin); hTaggedCJetsMC->Sumw2(); - tCMC->Draw("jtpt>>hTaggedCJetsMC",Form("weight*(%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==4)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); - //tCMC->Draw("jtpt>>hTaggedCJetsMC",Form("weight*(%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==4)",discr,workingPoint,cbinlo,cbinhi,etalo,etahi)); + tCMC->Draw("jtpt>>hTaggedCJetsMC",Form("weight*(%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==4&&refpt>30)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); hTaggedBJetsMC = new TH1D("hTaggedBJetsMC","hTaggedBJetsMC",nBins,ptBin); hTaggedBJetsMC->Sumw2(); - tBMC->Draw("jtpt>>hTaggedBJetsMC",Form("weight*(%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==5)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); - //tBMC->Draw("jtpt>>hTaggedBJetsMC",Form("weight*(%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==5)",discr,workingPoint,cbinlo,cbinhi,etalo,etahi)); + tBMC->Draw("jtpt>>hTaggedBJetsMC",Form("weight*(%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==5&&refpt>30)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); hTaggedJetsMC = (TH1D*)hTaggedLJetsMC->Clone("hTaggedJetsMC"); @@ -1118,18 +1117,15 @@ void fillCounterHistos(std::string discr, double workingPoint, int cbinlo, int c hUntaggedLJetsMC = new TH1D("hUntaggedLJetsMC","hUntaggedLJetsMC",nBins,ptBin); hUntaggedLJetsMC->Sumw2(); - tQCDMC->Draw("jtpt>>hUntaggedLJetsMC",Form("weight*(%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)!=5&&refpt>0)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); - //tQCDMC->Draw("jtpt>>hUntaggedLJetsMC",Form("weight*(%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)!=5)",discr,workingPoint,cbinlo,cbinhi,etalo,etahi)); + tQCDMC->Draw("jtpt>>hUntaggedLJetsMC",Form("weight*(%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)!=5&&refpt>30)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); hUntaggedCJetsMC = new TH1D("hUntaggedCJetsMC","hUntaggedCJetsMC",nBins,ptBin); hUntaggedCJetsMC->Sumw2(); - tCMC->Draw("jtpt>>hUntaggedCJetsMC",Form("weight*(%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==4&&refpt>0)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); - //tCMC->Draw("jtpt>>hUntaggedCJetsMC",Form("weight*(%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==4)",discr,workingPoint,cbinlo,cbinhi,etalo,etahi)); + tCMC->Draw("jtpt>>hUntaggedCJetsMC",Form("weight*(%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==4&&refpt>30)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); hUntaggedBJetsMC = new TH1D("hUntaggedBJetsMC","hUntaggedBJetsMC",nBins,ptBin); hUntaggedBJetsMC->Sumw2(); - tBMC->Draw("jtpt>>hUntaggedBJetsMC",Form("weight*(%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==5&&refpt>0)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); - //tBMC->Draw("jtpt>>hUntaggedBJetsMC",Form("weight*(%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==5)",discr,workingPoint,cbinlo,cbinhi,etalo,etahi)); + tBMC->Draw("jtpt>>hUntaggedBJetsMC",Form("weight*(%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==5&&refpt>30)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); hUntaggedJetsMC = (TH1D*)hUntaggedLJetsMC->Clone("hUntaggedJetsMC"); @@ -1138,23 +1134,34 @@ void fillCounterHistos(std::string discr, double workingPoint, int cbinlo, int c hBjetsWithJPinfoMC = new TH1D("hBjetsWithJPinfoMC","",nBins,ptBin); hBjetsWithJPinfoMC->Sumw2(); - tBMC->Draw("jtpt>>hBjetsWithJPinfoMC",Form("weight*(abs(refparton_flavorForB)==5&&discr_prob>0&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&refpt>0)",cbinlo,cbinhi,etalo,etahi)); - //tBMC->Draw("jtpt>>hBjetsWithJPinfoMC",Form("weight*(abs(refparton_flavorForB)==5&&discr_prob>0&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",cbinlo,cbinhi,etalo,etahi)); + tBMC->Draw("jtpt>>hBjetsWithJPinfoMC",Form("weight*(abs(refparton_flavorForB)==5&&discr_prob>0&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&refpt>30)",cbinlo,cbinhi,etalo,etahi)); hBjetsWithCSVinfoMC = new TH1D("hBjetsWithCSVinfoMC","",nBins,ptBin); hBjetsWithCSVinfoMC->Sumw2(); - tBMC->Draw("jtpt>>hBjetsWithCSVinfoMC",Form("weight*(abs(refparton_flavorForB)==5&&discr_prob>0&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&refpt>0)",cbinlo,cbinhi,etalo,etahi)); - //tBMC->Draw("jtpt>>hBjetsWithCSVinfoMC",Form("weight*(abs(refparton_flavorForB)==5&&discr_prob>0&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",cbinlo,cbinhi,etalo,etahi)); + tBMC->Draw("jtpt>>hBjetsWithCSVinfoMC",Form("weight*(abs(refparton_flavorForB)==5&&discr_csvSimple>0&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&refpt>30)",cbinlo,cbinhi,etalo,etahi)); hTaggedJetsData = new TH1D("hTaggedJetsData","",nBins,ptBin); hTaggedJetsData->Sumw2(); tdata->Draw("jtpt>>hTaggedJetsData",Form("weight*(%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); - //tdata->Draw("jtpt>>hTaggedJetsData",Form("(%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",discr,workingPoint,cbinlo,cbinhi,etalo,etahi)); hUntaggedJetsData = new TH1D("hUntaggedJetsData","",nBins,ptBin); hUntaggedJetsData->Sumw2(); tdata->Draw("jtpt>>hUntaggedJetsData",Form("weight*(%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); - //tdata->Draw("jtpt>>hUntaggedJetsData",Form("(%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",discr,workingPoint,cbinlo,cbinhi,etalo,etahi)); + + cout << endl << "Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z" << endl; + cout << "hTaggedLJetsMC: " << hTaggedLJetsMC->GetBinContent(1) << endl; + cout << "hTaggedCJetsMC: " << hTaggedCJetsMC->GetBinContent(1) << endl; + cout << "hTaggedBJetsMC: " << hTaggedBJetsMC->GetBinContent(1) << endl; + cout << "hTaggedJetsMC: " << hTaggedJetsMC->GetBinContent(1) << endl; + cout << "hUntaggedLJetsMC: " << hUntaggedLJetsMC->GetBinContent(1) << endl; + cout << "hUntaggedCJetsMC: " << hUntaggedCJetsMC->GetBinContent(1) << endl; + cout << "hUntaggedBJetsMC: " << hUntaggedBJetsMC->GetBinContent(1) << endl; + cout << "hUntaggedJetsMC: " << hUntaggedJetsMC->GetBinContent(1) << endl; + cout << "hBjetsWithJPinfoMC: "<< hBjetsWithJPinfoMC->GetBinContent(1) << endl; + cout << "hBjetsWithCSVinfoMC: "<GetBinContent(1)<< endl; + cout << "hTaggedJetsData: "<< hTaggedJetsData->GetBinContent(1)<< endl; + cout << "hUntaggedJetsData: "<< hUntaggedJetsData->GetBinContent(1) << endl; + cout << "Z*Z*Z*Z*Z*Z*Z*Z*Z*Z*Z" << endl << endl; } Enumerations count(double ptMin, double ptMax) { diff --git a/bfractionVsJetPtPPgPlus.C b/bfractionVsJetPtPPgPlus.C new file mode 100644 index 0000000..96271fc --- /dev/null +++ b/bfractionVsJetPtPPgPlus.C @@ -0,0 +1,1185 @@ +#include +#include "TMath.h" +#include "TFile.h" +#include "TH1.h" +#include "TF1.h" +#include "TCanvas.h" +#include "TLegend.h" +#include "TStyle.h" +#include "TROOT.h" +#include "TPad.h" +#include "TRandom.h" +#include "THStack.h" +#include "TH2.h" +#include "TLatex.h" +#include "TTree.h" +#include "TPaveText.h" +#include "TFrame.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace RooFit; + +// Numbers +struct Enumerations { + + Double_t nTaggedJetsMC; + Double_t nUntaggedJetsMC; + Double_t nJetsMC; + Double_t nTaggedBjetsMC; + Double_t nUntaggedBjetsMC; + Double_t nBjetsMC; + Double_t nNonBjetsMC; + Double_t nTaggedNonBjetsMC; + + Double_t nTaggedJetsData; + Double_t nUntaggedJetsData; + + Double_t cbForJP; + Double_t cbForCSV; + + Double_t nTaggedJetsMCError; + Double_t nUntaggedJetsMCError; + Double_t nJetsMCError; + Double_t nTaggedBjetsMCError; + Double_t nUntaggedBjetsMCError; + Double_t nBjetsMCError; + Double_t nNonBjetsMCError; + Double_t nTaggedNonBjetsMCError; + + Double_t nTaggedJetsDataError; + Double_t nUntaggedJetsDataError; + + Double_t nJetsData; + Double_t nJetsDataError; + +}; + +int counter(0); +TCanvas* can1[24]; +TH1D* hData[24]; +TH1D* hMCC[24]; +TH1D* hMCB[24]; +TH1D* hMCL[24]; +TH1D* hMCLC[24]; +TH1D* MCTotal[24]; +TH1D* MCSumGreen[24]; +TH1D* hMCB_copy[24]; +THStack* hs[24]; +THStack* ghosths[24]; +TH1D* fixCL_MCC[24]; +TH1D* fixCL_MCL[24]; +TH1D *fluctuateHist(TH1D* h) +{ + TH1D *hToy = (TH1D*)h->Clone(Form("hToy_%s",h->GetName())); + for (int j=1;j<=hToy->GetNbinsX();j++) { + double value = gRandom->Poisson(h->GetBinContent(j)); + hToy->SetBinContent(j,value); + } + return hToy; +} + + +Double_t addError(Double_t aErr, Double_t bErr) { + // if a,b are independent + return sqrt(aErr*aErr + bErr*bErr); +} +Double_t substractError(Double_t aErr, Double_t bErr) { + // if b is a subset of a + return sqrt(aErr*aErr - bErr*bErr); +} +Double_t prodError(Double_t a, Double_t b, Double_t aErr, Double_t bErr) { + // if a,b are independent + return sqrt(a*a*bErr*bErr + b*b*aErr*aErr); +} +Double_t fracError(Double_t a, Double_t b, Double_t aErr, Double_t bErr) { + // error on a/(a+b) + // if a,b are independent + // and aErr,bErr can be given by sqrt(sum of squares of weights) + Double_t c=a+b; + return sqrt( aErr*aErr * b*b/(c*c*c*c) + +bErr*bErr * a*a/(c*c*c*c) ) ; +} + +Double_t binomError(Double_t a, Double_t b, Double_t aErr, Double_t bErr) { + // error on a/b, where a+b=const + Double_t w = a/b; + return sqrt(fabs( ( (1.-2.*w)*aErr*aErr + w*w*bErr*bErr )/(b*b) )); +} + +void drawText(const std::string text, float xp, float yp); +void format1D(TH1& h1, TCanvas& c1); + +class parameters{ + public: + int fixCL; + int cbinlo; + int cbinhi; + float etalo; + float etahi; + float ptMax; + float ptMin; +}; + + +TFile *fQCDMC, *fBMC, *fCMC, *fdata; +TTree *tQCDMC, *tBMC, *tCMC, *tdata; + +// declare counter histos +TH1D *hTaggedLJetsMC,*hTaggedCJetsMC, *hTaggedBJetsMC, *hTaggedJetsMC, *hUntaggedLJetsMC, *hUntaggedCJetsMC, *hUntaggedBJetsMC, *hUntaggedgJetsMC, *hBjetsWithJPinfoMC, *hBjetsWithCSVinfoMC, *hTaggedJetsData, *hUntaggedJetsData, *hUntaggedJetsMC; + +RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, double minXdiscr, double maxXdiscr, std::string comment, double maxYaxis, bool toyMC, bool useDataBGtemplate, bool verbose); + +void fillCounterHistos(std::string discr, double workingPoint, int cbinlo, int cbinhi, float etalo, float etahi); + +Enumerations count(double ptMin, double ptMax); + +const int nBins = 7; +double ptBin[nBins+1] = {60,70,80,90,110,130,170,250}; +//const int nBins = 4; +//double ptBin[nBins+1] = {80,100,120,150,200}; +//const int nBins = 1; +//double ptBin[nBins+1] = {60,70}; + + +///XXXX +void bfractionVsJetPtPPgPlus(std::string tagger="discr_ssvHighEff", double workingPoint=2.0, int fixCL=0, std::string taggerName="SSVHE", int cbinlo=0, int cbinhi=40, float etalo=0., float etahi=2., bool useDataBGtemplate = false, bool verbose = true) { + + if(useDataBGtemplate) fixCL=1; + + parameters p; + p.fixCL = fixCL; + p.cbinlo = cbinlo; + p.cbinhi = cbinhi; + p.etalo = etalo; + p.etahi = etahi; + + gStyle->SetOptStat(0); + gStyle->SetOptTitle(0); + + gStyle->SetTextFont(42); + gStyle->SetLabelFont(43,"xyz"); + gStyle->SetLabelSize(28,"xyz"); + gStyle->SetTitleFont(43,"xyz"); + gStyle->SetTitleSize(28,"xyz"); + gStyle->SetTitleOffset(1.0,"x"); + gStyle->SetNdivisions(510,"xy"); + + gROOT->ForceStyle(1); + + /* + gStyle->SetLabelFont(43,"xyz"); + gStyle->SetLabelSize(14,"xyz"); + gStyle->SetTitleFont(43,"xyz"); + gStyle->SetTitleSize(16,"xyz"); + gStyle->SetTitleOffset(1.5,"xy"); + */ + + fQCDMC = new TFile("histos/ppMC_ppReco_ak3PF_QCDjetTrig_noIPupperCut_9-15.root"); + fBMC = new TFile("histos/ppMC_ppReco_ak3PF_BjetTrig_noIPupperCut_9-15.root"); + fCMC = new TFile("histos/ppMC_ppReco_ak3PF_CjetTrig_noIPupperCut_9-15.root"); + fdata = new TFile("histos/ppdata_ppReco_ak3PF_DinkoXchk_jetTrig_noIPupperCut.root"); + + tQCDMC = (TTree*) fQCDMC->Get("nt"); + tBMC = (TTree*) fBMC->Get("nt"); + tCMC = (TTree*) fCMC->Get("nt"); + tdata = (TTree*) fdata->Get("nt"); + + fillCounterHistos(tagger.c_str(), workingPoint, cbinlo, cbinhi, etalo, etahi); + + int doLTJP=1; + int doLTCSV=0; + + Double_t bPurMC, bPurData, bEffMC, bEffDataLTJP, bEffDataLTCSV=0, taggedFracData, bFracMC, bFracData, bFracDataLTJP, bFracDataLTCSV=0, bFracJPdirect; + Double_t bPurMCError, bPurDataError, bEffMCError, bEffDataLTJPError, bEffDataLTCSVError, taggedFracDataError, bFracMCError, bFracDataError, bFracDataLTJPError, bFracDataLTCSVError, bFracJPdirectError; + Enumerations numbers; + + TH1D *hBPurityData = new TH1D("hBPurityData","hBPurityData;Jet p_{T} (GeV/c);b-Tagging purity",nBins,ptBin); + TH1D *hBPurityMC = new TH1D("hBPurityMC","hBPurityMC;Jet p_{T} (GeV/c);b-Tagging purity",nBins,ptBin); + TH1D *hRawBData = new TH1D("hRawBData","hRawBData;Jet p_{T} (GeV/c);raw b-jets",nBins,ptBin); + TH1D *hRawBMC = new TH1D("hRawBMC","hRawBMC;Jet p_{T} (GeV/c);raw b-jets",nBins,ptBin); + + TH1D *hBEfficiencyMC = new TH1D("hBEfficiencyMC","hBEfficiencyMC;Jet p_{T} (GeV/c);b-Tagging efficiency",nBins,ptBin); + TH1D *hBEfficiencyDataLTJP = new TH1D("hBEfficiencyDataLTJP","hBEfficiencyDataLTJP;Jet p_{T} (GeV/c);b-Tagging efficiency",nBins,ptBin); + TH1D *hBEfficiencyDataLTCSV = new TH1D("hBEfficiencyDataLTCSV","hBEfficiencyDataLTCSV;Jet p_{T} (GeV/c);b-Tagging efficiency",nBins,ptBin); + + TH1D *hBFractionMC = new TH1D("hBFractionMC","hBFractionMC;Jet p_{T} (GeV/c);b-jet fraction",nBins,ptBin); + TH1D *hBFractionData = new TH1D("hBFractionData","hBFractionData;Jet p_{T} (GeV/c);b-jet fraction",nBins,ptBin); + TH1D *hBFractionDataLTJP = new TH1D("hBFractionDataLTJP","hBFractionDataLTJP;Jet p_{T} (GeV/c);b-jet fraction",nBins,ptBin); + TH1D *hBFractionDataLTCSV = new TH1D("hBFractionDataLTCSV","hBFractionDataLTCSV;Jet p_{T} (GeV/c);b-jet fraction",nBins,ptBin); + TH1D *hBFractionJPdirect = new TH1D("hBFractionJPdirect","hBFractionJPdirect;Jet p_{T} (GeV/c);b-jet fraction",nBins,ptBin); + + TH1D *hIncJetsMC = new TH1D("hIncJetsMC","hIncJetsMC;Jet p_{T} (GeV/c); inclusive jets in MC",nBins,ptBin); + TH1D *hIncJetsData = new TH1D("hIncJetsData","hIncJetsData;Jet p_{T} (GeV/c); inclusive jets in Data",nBins,ptBin); + + int ncol=nBins; + int nrow=1; + + if(nBins==3||nBins==2){ + ncol=nBins; + } + + if(nBins==4){ + ncol=nBins/2; + nrow=nBins/2; + } + if(nBins==6){ + ncol=3; + nrow=2; + } + + TCanvas *c1=new TCanvas("c1","c1",1200,600); + c1->Divide(ncol,nrow); + + //TCanvas *c2=new TCanvas("c2","c2",1200,600); + //c2->Divide(ncol,nrow); + + TCanvas *c3=new TCanvas("c3","c3",1200,600); + c3->Divide(ncol,nrow); + + TCanvas *c4=new TCanvas("c4","c4",1200,600); + c4->Divide(ncol,nrow); + + TCanvas *cCount = new TCanvas("cCount","cCount",600,600); + bool doToyCalc = false; + for (int n=0;ncd(); + numbers = count(ptBin[n],ptBin[n+1]); + c1->cd(n+1); + p.ptMin = ptBin[n]; + p.ptMax = ptBin[n+1]; + RooRealVar *fitSvtxmTag = bfractionFit(p,"svtxm",tagger,workingPoint,6,"b-tagged sample (SSVHE > 2)",9e3,doToyCalc, useDataBGtemplate, verbose); + + //c2->cd(n+1); + //c2->GetPad(n+1)->SetLogy(); + //RooRealVar *fitJpDirect = bfractionFit(p,"discr_prob","discr_prob",0.,3.,"inclusive sample",4e5,doToyCalc); + + RooRealVar *fitJpTag=NULL; + RooRealVar *fitJpBeforetag=NULL; + RooRealVar *fitCsvTag=NULL; + RooRealVar *fitCsvBeforetag=NULL; + if (doLTJP) { + c3->cd(n+1); + //c3->GetPad(n+1)->SetLogy(); + fitJpBeforetag = bfractionFit(p,"discr_prob","discr_prob",0,3.,"jets with JP info",4e5,doToyCalc,false,verbose); + c4->cd(n+1); + //c4->GetPad(n+1)->SetLogy(); + fitJpTag = bfractionFit(p,"discr_prob",tagger,workingPoint,6,"b-tagged sample (SSVHE > 2)",4e5,doToyCalc,false,verbose); + } + if (doLTCSV) { + fitCsvBeforetag = bfractionFit(p,"discr_csvSimple",tagger,-2,10,"jets with CSV info",4e5,doToyCalc,false,verbose); + fitCsvTag = bfractionFit(p,"discr_csvSimple",tagger,workingPoint,10,Form("b-tagged sample (%s > %.1f)",taggerName.c_str(),workingPoint),4e5,doToyCalc,false,verbose); + } + + taggedFracData = numbers.nTaggedJetsData / numbers.nJetsData; + taggedFracDataError = binomError(numbers.nTaggedJetsData,numbers.nJetsData,numbers.nTaggedJetsDataError,numbers.nJetsDataError); + + //* --- b-tagging purity --- + + bPurMC = numbers.nTaggedBjetsMC / numbers.nTaggedJetsMC; + cout<<" bPurMC "<getVal(); + bPurDataError = fitSvtxmTag->getError(); + + hBPurityMC->SetBinContent(n+1,bPurMC); + hBPurityMC->SetBinError(n+1,bPurMCError); + hBPurityData->SetBinContent(n+1,bPurData); + hBPurityData->SetBinError(n+1,bPurDataError); + + hRawBData->SetBinContent(n+1,bPurData*numbers.nTaggedJetsData); + hRawBData->SetBinError(n+1,bPurDataError*numbers.nTaggedJetsData); + hRawBMC->SetBinContent(n+1,bPurMC*numbers.nTaggedJetsData); + hRawBMC->SetBinError(n+1,bPurMCError*numbers.nTaggedJetsData); + hIncJetsData->SetBinContent(n+1,numbers.nJetsData); + hIncJetsData->SetBinError(n+1,numbers.nJetsDataError); + hIncJetsMC->SetBinContent(n+1,numbers.nJetsMC); + hIncJetsMC->SetBinError(n+1,numbers.nJetsMCError); + + + //*/ + + //* --- b-tagging efficiency --- + + bEffMC = numbers.nTaggedBjetsMC / numbers.nBjetsMC; + bEffMCError = binomError(numbers.nTaggedBjetsMC,numbers.nBjetsMC,numbers.nTaggedBjetsMCError,numbers.nBjetsMCError); + hBEfficiencyMC->SetBinContent(n+1,bEffMC); + hBEfficiencyMC->SetBinError(n+1,bEffMCError); + + if (doLTJP) { + bEffDataLTJP = taggedFracData * numbers.cbForJP * fitJpTag->getVal() / fitJpBeforetag->getVal(); + bEffDataLTJPError = prodError(taggedFracData,fitJpTag->getVal(),taggedFracDataError,fitJpTag->getError()) * numbers.cbForJP / fitJpBeforetag->getVal(); + hBEfficiencyDataLTJP->SetBinContent(n+1,bEffDataLTJP); + hBEfficiencyDataLTJP->SetBinError(n+1,bEffDataLTJPError); + } + + if (doLTCSV) { + bEffDataLTCSV = taggedFracData * numbers.cbForCSV * fitCsvTag->getVal() / fitCsvBeforetag->getVal(); + bEffDataLTCSVError = prodError(taggedFracData,fitCsvTag->getVal(),taggedFracDataError,fitCsvTag->getError()) * numbers.cbForCSV / fitCsvBeforetag->getVal(); + hBEfficiencyDataLTCSV->SetBinContent(n+1,bEffDataLTCSV); + hBEfficiencyDataLTCSV->SetBinError(n+1,bEffDataLTCSVError); + } + + //* --- b fraction --- + + bFracMC = numbers.nBjetsMC / numbers.nJetsMC; + bFracMC = numbers.nTaggedJetsMC * bPurMC / (bEffMC * numbers.nJetsMC); // for check : same as previous + bFracMCError = binomError(numbers.nBjetsMC,numbers.nJetsMC,numbers.nBjetsMCError,numbers.nJetsMCError); + hBFractionMC->SetBinContent(n+1,bFracMC); + hBFractionMC->SetBinError(n+1,bFracMCError); + + + bFracData = taggedFracData * bPurData / bEffMC; // efficiency from MC + bFracDataError = prodError(taggedFracData,bPurData,taggedFracDataError,bPurDataError) / bEffMC; // stat.error from purity and tagged-fraction (assumed independent) + bFracDataError = bFracData * bPurDataError / bPurData; // stat.error only from purity + hBFractionData->SetBinContent(n+1,bFracData); + hBFractionData->SetBinError(n+1,bFracDataError); + + if (doLTJP) { + bFracDataLTJP = taggedFracData * bPurData / bEffDataLTJP ; // efficiency from LTJP method + bFracDataLTJPError = prodError(taggedFracData,bPurData,taggedFracDataError,bPurDataError) / bEffDataLTJP; // stat.error from purity and tagged-fraction (assumed independent) + bFracDataLTJPError = bFracDataLTJP * bPurDataError / bPurData; // stat.error only from purity + hBFractionDataLTJP->SetBinContent(n+1,bFracDataLTJP); + hBFractionDataLTJP->SetBinError(n+1,bFracDataLTJPError); + } + + if (doLTCSV) { + bFracDataLTCSV = taggedFracData * bPurData / bEffDataLTCSV; // efficiency from LTCSV method + bFracDataLTCSVError = prodError(taggedFracData,bPurData,taggedFracDataError,bPurDataError) / bEffDataLTCSV; // stat.error from purity and tagged-fraction (assumed independent) + bFracDataLTCSVError = bFracDataLTCSV * bPurDataError / bPurData; // stat.error only from purity + hBFractionDataLTCSV->SetBinContent(n+1,bFracDataLTCSV); + hBFractionDataLTCSV->SetBinError(n+1,bFracDataLTCSVError); + } + + bFracJPdirect = fitJpBeforetag->getVal(); + bFracJPdirectError = fitJpBeforetag->getError(); + hBFractionJPdirect->SetBinContent(n+1,bFracJPdirect); + hBFractionJPdirect->SetBinError(n+1,bFracJPdirectError); + //*/ + + //* + if(verbose){ + cout<<"nTaggedJetsMC "< %.1f)",taggerName.c_str(),workingPoint)); + legPur->SetBorderSize(0); + //legPur->SetFillColor(kGray); + legPur->SetFillStyle(0); + legPur->AddEntry(hBPurityMC,"MC Input","pl"); + legPur->AddEntry(hBPurityData,"Data","pl"); + //legPur->SetTextSize(0.030); + TCanvas *cBPurity = new TCanvas("cBPurity","b purity",700,600); + cBPurity->cd(); + hBPurityMC->SetAxisRange(0,1,"Y"); + hBPurityMC->SetTitleOffset(1.3,"Y"); + hBPurityMC->SetLineColor(2); + hBPurityMC->SetMarkerColor(2); + hBPurityMC->SetMarkerStyle(21); + hBPurityMC->SetMarkerSize(1.41); + format1D(*hBPurityMC,*cBPurity); + hBPurityMC->Draw(); + drawText("CMS Preliminary",0.15,0.965); + drawText("#sqrt{s_{NN}} = 2.76 TeV",0.55,0.965); + hBPurityData->SetLineColor(1); + hBPurityData->SetMarkerColor(1); + hBPurityData->SetMarkerStyle(20); + hBPurityData->SetMarkerSize(1.41); + hBPurityData->Draw("same"); + legPur->Draw(); + //cBPurity->SaveAs("ssvhePurpp.pdf"); + + TLegend *legEff = new TLegend(0.2,0.6,0.9,0.90,Form("Efficiency for tagging b-jets (%s > %.1f)",taggerName.c_str(),workingPoint)); + legEff->SetBorderSize(0); + //legEff->SetFillColor(kGray); + legEff->SetFillStyle(0); + legEff->AddEntry(hBEfficiencyMC,"Simulation","pl"); + //legEff->SetTextSize(0.030); + if (doLTJP) legEff->AddEntry(hBEfficiencyDataLTJP,"Reference Tagger","pl"); + if (doLTCSV) legEff->AddEntry(hBEfficiencyDataLTCSV,"LT method (CSV)","pl"); + TCanvas *cBEfficiency = new TCanvas("cBEfficiency","b-Tagging efficiency",700,600); + cBEfficiency->cd(); + hBEfficiencyMC->SetAxisRange(0,1,"Y"); + hBEfficiencyMC->SetTitleOffset(1.3,"Y"); + hBEfficiencyMC->SetLineColor(2); + hBEfficiencyMC->SetMarkerColor(2); + hBEfficiencyMC->SetMarkerStyle(21); + hBEfficiencyMC->SetMarkerSize(1.41); + format1D(*hBEfficiencyMC,*cBEfficiency); + hBEfficiencyMC->Draw(); + drawText("CMS Preliminary",0.15,0.965); + drawText("#sqrt{s_{NN}} = 2.76 TeV",0.55,0.965); + if (doLTJP) { + hBEfficiencyDataLTJP->SetLineColor(kGreen+2); + hBEfficiencyDataLTJP->SetMarkerColor(kGreen+2); + hBEfficiencyDataLTJP->SetMarkerStyle(20); + hBEfficiencyDataLTJP->SetMarkerSize(1.41); + hBEfficiencyDataLTJP->Draw("same"); + } + if (doLTCSV) { + hBEfficiencyDataLTCSV->SetLineColor(7); + hBEfficiencyDataLTCSV->SetMarkerColor(7); + hBEfficiencyDataLTCSV->SetMarkerStyle(20); + hBEfficiencyDataLTCSV->SetMarkerSize(1.41); + hBEfficiencyDataLTCSV->Draw("same"); + } + legEff->Draw(); + //cBEfficiency->SaveAs("ssvheEffpp.pdf"); + + + TLegend *legFrac = new TLegend(0.15,0.15,0.85,0.35); + legFrac->SetBorderSize(0); + //legFrac->SetFillColor(kGray); + legFrac->SetFillStyle(0); + legFrac->AddEntry(hBFractionMC,"MC Input","pl"); + //legFrac->SetTextSize(0.022); + legFrac->AddEntry(hBFractionData,Form("%s > %.1f + pur. from SV mass + eff. from MC",taggerName.c_str(),workingPoint),"pl"); + if (doLTJP) legFrac->AddEntry(hBFractionDataLTJP,Form("%s > %.1f + pur. from SV mass + eff. from LT (JP)",taggerName.c_str(),workingPoint),"pl"); + if (doLTCSV) legFrac->AddEntry(hBFractionDataLTCSV,Form("%s > %.1f + pur. from SV mass + eff. from LT (CSV)",taggerName.c_str(),workingPoint),"pl"); + legFrac->AddEntry(hBFractionJPdirect,"Direct fit to JP","pl"); + TCanvas *cBFraction = new TCanvas("cBFraction","b-jet fraction",700,600); + cBFraction->cd(); + hBFractionMC->SetAxisRange(0,0.03,"Y"); + hBFractionMC->SetTitleOffset(1.45,"Y"); + hBFractionMC->SetLineColor(2); + hBFractionMC->SetMarkerColor(2); + hBFractionMC->SetMarkerStyle(21); + hBFractionMC->SetMarkerSize(1.41); + format1D(*hBFractionMC,*cBFraction); + hBFractionMC->Draw(); + drawText("CMS Preliminary",0.15,0.965); + drawText("#sqrt{s_{NN}} = 2.76 TeV",0.55,0.965); + hBFractionData->SetLineColor(1); + hBFractionData->SetMarkerColor(1); + hBFractionData->SetMarkerStyle(20); + hBFractionData->SetMarkerSize(1.41); + hBFractionData->Draw("same"); + if (doLTJP) { + hBFractionDataLTJP->SetLineColor(kGreen+2); + hBFractionDataLTJP->SetMarkerColor(kGreen+2); + hBFractionDataLTJP->SetMarkerStyle(20); + hBFractionDataLTJP->SetMarkerSize(1.41); + hBFractionDataLTJP->Draw("same"); + } + if (doLTCSV) { + hBFractionDataLTCSV->SetLineColor(7); + hBFractionDataLTCSV->SetMarkerColor(7); + hBFractionDataLTCSV->SetMarkerStyle(20); + hBFractionDataLTCSV->SetMarkerSize(1.41); + hBFractionDataLTCSV->Draw("same"); + } + hBFractionJPdirect->SetLineColor(4); + hBFractionJPdirect->SetMarkerColor(4); + hBFractionJPdirect->SetMarkerStyle(20); + hBFractionJPdirect->SetMarkerSize(1.41); + hBFractionJPdirect->Draw("same"); + legFrac->Draw(); + //cBFraction->SaveAs("ssvheFracpp.pdf"); + + string mcDataString = "MC"; + if(useDataBGtemplate) mcDataString = "Data"; + + TFile *fout = new TFile(Form("output/NewFormatV5_bFraction%sTemplate_pppp1_jetcut30_dinkoXchk_gPlusFilter_%sat%.1fFixCL%d_bin_%d_%d_eta_%d_%d.root",mcDataString.c_str(),taggerName.c_str(),workingPoint,fixCL,cbinlo,cbinhi,(int)etalo,(int)etahi),"recreate"); + + hBFractionMC->Write(); + hBFractionData->Write(); + if (doLTJP) hBFractionDataLTJP->Write(); + if (doLTCSV) hBFractionDataLTCSV->Write(); + hBFractionJPdirect->Write(); + hBPurityMC->Write(); + hBPurityData->Write(); + hRawBMC->Write(); + hRawBData->Write(); + hBEfficiencyMC->Write(); + hBEfficiencyDataLTJP->Write(); + hIncJetsMC->Write(); + hIncJetsData->Write(); + fout->Close(); + + c1->SaveAs(Form("gifs/svtxMassFit_%s.gif",fixCL?"CLfixed":"CLfree")); + //c2->SaveAs(Form("gifs/jpDirectFit_%s.gif",fixCL?"CLfixed":"CLfree")); + c3->SaveAs(Form("gifs/jpBeforeTag_%s.gif",fixCL?"CLfixed":"CLfree")); + c4->SaveAs(Form("gifs/jpAfterTag_%s.gif",fixCL?"CLfixed":"CLfree")); + +} + + + + + +void fixEmpty(TH1 *h){ + for (int i=1;i<=h->GetNbinsX();i++){ + if (h->GetBinContent(i)==0) h->SetBinContent(i,1e-20); + } +} + +RooRealVar *bfractionFit(parameters p, std::string var, std::string discr, double minXdiscr, double maxXdiscr, std::string comment, double maxYaxis, bool toyMC, bool useDataBGtemplate, bool verbose) +{ + bool fixCL = p.fixCL; + int cbinlo = p.cbinlo; + int cbinhi = p.cbinhi; + float etalo = p.etalo; + float etahi = p.etahi; + float ptMax = p.ptMax; + float ptMin = p.ptMin; + double minXvar=0.; + double maxXvar=6.; + + if (var == "discr_prob") { + maxXvar = 3; + } else if (var == "discr_probb") { + maxXvar = 1; + } + + // discr_prob : from (0) 0 to 3, operating point : 0.6 (1%), 0.7 + // discr_ssvHighEff : from (-1) 1 to 6, operating point : 2 ? + // discr_ssvHighPur : from (-1) 1 to 6, operating point : 2 ? + // discr_csvSimple : from (-10,-1) 0 to 1, operating point : 0.9 + // svtxm : from (0) 0 to 7 + // muptrel : from (0) 0 to 5 + + int nhistBins=30; + if(var=="svtxm") nhistBins=24; + + double ptHatMin = 0.; + if(ptMin>=80.&&ptMin<120.) ptHatMin = 50.; + else if(ptMin>=120.&&ptMin<150.) ptHatMin = 65.; + else if(ptMin>=150.&&ptMin<200.) ptHatMin = 80.; + + TH1D *hB = new TH1D("hB","hB",nhistBins,minXvar,maxXvar); + hB->Sumw2(); + tBMC->Draw(Form("%s>>hB",var.c_str()),Form("weight*(abs(refparton_flavorForB)==5&&pVertexFilterCutGplusUpsPP&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&pthat>%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,cbinlo,cbinhi,etalo,etahi,ptHatMin)); + fixEmpty(hB); + + TH1D *hC = new TH1D("hC","hC",nhistBins,minXvar,maxXvar); + hC->Sumw2(); + tCMC->Draw(Form("%s>>hC",var.c_str()),Form("weight*(abs(refparton_flavorForB)==4&&pVertexFilterCutGplusUpsPP&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&pthat>%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,cbinlo,cbinhi,etalo,etahi,ptHatMin)); + fixEmpty(hC); + + TH1D *hL = new TH1D("hL","hL",nhistBins,minXvar,maxXvar); + hL->Sumw2(); + tQCDMC->Draw(Form("%s>>hL",var.c_str()),Form("weight*(abs(refparton_flavorForB)!=5&&pVertexFilterCutGplusUpsPP&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)<99&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&pthat>%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,cbinlo,cbinhi,etalo,etahi,ptHatMin)); + fixEmpty(hL); + + TH1D *hCL = NULL; + if(useDataBGtemplate){ + hCL = new TH1D("hCL","hCL",nhistBins,minXvar,maxXvar); + hCL->Sumw2(); + tdata->Draw(Form("%s>>hCL",var.c_str()),Form("weight*(discr_prob<0.5&&pVertexFilterCutGplusUpsPP&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>=%f&&abs(jteta)<%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,cbinlo,cbinhi,etalo,etahi)); + } + else{ + hCL = (TH1D*) hL->Clone(); + hCL->Add(hC); + } + fixEmpty(hCL); + + //*/ + + + // --- Observable --- + RooRealVar s(var.c_str(),var.c_str(),0,minXvar,maxXvar); + RooRealVar jtpt("jtpt","jtpt",0,ptMin,ptMax); + RooRealVar discriminator(discr.c_str(),discr.c_str(),0,minXdiscr,maxXdiscr); + RooRealVar bin("bin","bin",0,0,40); + RooRealVar jteta("jteta","jteta",0,-2,2); + RooRealVar weight("weight","weight",0,0,1e6); + RooRealVar pVertexFilterCutGplusUpsPP("pVertexFilterCutGplusUpsPP","pVertexFilterCutGplusUpsPP",0,0,1); + + // --- Build Histogram PDF --- + RooDataHist xB("xB","xB",s,hB); + RooHistPdf bottom("bottom","bottom PDF",s,xB); + RooDataHist xC("xC","xC",s,hC); + RooHistPdf charm("charm","charm PDF",s,xC); + RooDataHist xL("xL","xL",s,hL); + RooHistPdf light("light","light PDF",s,xL); + RooDataHist xCL("xCL","xCL",s,hCL); + RooHistPdf charmlight("charmlight","charmlight PDF",s,xCL); + + /* + cout<<"hB "<Integral()<Integral()<Integral()<Integral()<Integral()/(hB->Integral()+hCL->Integral()); + //Double_t cInitFrac = hC->Integral()/(hB->Integral()+hCL->Integral()); + + double fracGuess=0.3; + if(var != "svmtx") fracGuess =0.01; + /* + double bGuess = 0.03; + double cGuess = 0.1; + if(var != "svmtx"){ + bGuess =0.01; + cGuess =0.05; + } + */ + RooRealVar *Bfraction = new RooRealVar("Bfraction","#signal events",fracGuess,0.,1); + RooRealVar *Cfraction = new RooRealVar("Cfraction","#background events",fracGuess,0.,1); + RooAddPdf *model; + if(fixCL) model = new RooAddPdf("model","",bottom,charmlight,*Bfraction); + else model=new RooAddPdf("model","",RooArgList(bottom,charm,light),RooArgList(*Bfraction,*Cfraction)); + //RooAddPdf model=RooAddPdf("model","",RooArgList(bottom,charm,light),RooArgList(*Bfraction,*Cfraction)); + + // --- Data sample --- + RooDataSet *data = NULL; + if(var == discr) data = new RooDataSet("data","data",tdata,RooArgSet(s,jtpt,jteta,bin,weight,pVertexFilterCutGplusUpsPP),Form("pVertexFilterCutGplusUpsPP&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&abs(jteta)>%f&&abs(jteta)<%f&&bin>=%d&&bin<%d",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,etalo,etahi,cbinlo,cbinhi),"weight"); + else data = new RooDataSet("data","data",tdata,RooArgSet(s,jtpt,jteta,bin,discriminator,weight,pVertexFilterCutGplusUpsPP),Form("pVertexFilterCutGplusUpsPP&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&abs(jteta)>%f&&abs(jteta)<%f&&bin>=%d&&bin<%d",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,etalo,etahi,cbinlo,cbinhi),"weight"); + //RooDataSet *data = new RooDataSet("data","data",tdata,RooArgSet(s,jtpt,jteta,bin,discriminator),Form("jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&abs(jteta)>%f&&abs(jteta)<%f&&bin>=%d&&bin<%d",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr,etalo,etahi,cbinlo,cbinhi)); + + + /* + // --- Construct signal+background PDF --- + //Double_t bInitFrac = hB->Integral()/(hB->Integral()+hCL->Integral()); + //Double_t cInitFrac = hC->Integral()/(hB->Integral()+hCL->Integral()); + RooRealVar Bfraction("Bfraction","#light events",0.3,0.,1); + RooRealVar Cfraction("Cfraction","#background events",0.3,0.,1); hIncJetsMC + if(fixCL) RooAddPdf model("model","",bottom,charmlight,Bfraction); + else RooAddPdf model("model","",RooArgList(bottom,charm,light),RooArgList(Bfraction,Cfraction)); + + // --- Data sample --- + //RooDataSet *data = new RooDataSet("data","data",tdata,RooArgSet(s,jtpt,discriminator),Form("jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr)); + //RooDataSet *data = new RooDataSet("data","data",tdata,RooArgSet(s,jtpt,discriminator),Form("jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&bin>=%d&&bin<%d&&fabs(jteta)>%f&&fabs(jteta)<%f",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr,cbinlo,cbinhi,etalo,etahi)); + RooDataSet *data = new RooDataSet("data","data",tdata,RooArgSet(s,jtpt,jteta,bin,discriminator),Form("jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&abs(jteta)>%f&&abs(jteta)<%f&&bin>=%d&&bin<%d",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr,etalo,etahi,cbinlo,cbinhi)); + */ + // unfucked? + + + TPaveText *header = new TPaveText(0.05,0.9,0.95,0.99); + header->AddText(Form("%s - ROOFIT ML unbinned fit of %s",var.c_str(),fixCL?"2 components : bottom and (charm + light)":"3 components : bottom, charm and light")); + header->AddText(Form("Pb-Pb data - %s",comment.c_str())); + header->AddText(Form("%s%.0f <= jet pT < %.0f",(var=="muptrel")?"deltaR < 0.5 ; muon pT > 5 ; ":"",ptMin,ptMax)); + //header->SetTextSize(0.027); + header->SetTextSize(20); + header->SetTextAlign(12); + header->SetBorderSize(0); + header->SetFillStyle(0); + //header->Draw(); + + + //RooPlot* sframe = s.frame(); + TH2D *htemp = new TH2D(Form("%s%.0f%.0f",var.c_str(),ptMin,ptMax),Form("%s%.0f%.0f",var.c_str(),ptMin,ptMax),100,minXvar,maxXvar,100,0.5,maxYaxis) ; + //htemp->SetXTitle(Form("%s %.0f < p_{T} < %.0f GeV/c",var,ptMin,ptMax)); + if(var=="svtxm")htemp->SetXTitle("SV mass (GeV/c^{2})"); + else htemp->SetXTitle("JP Disc."); + htemp->SetYTitle("Entries"); + + + // --- Perform extended ML fit of composite PDF to data --- + RooFitResult *fitresult = model->fitTo(*data,SumW2Error(kTRUE),Save(),PrintLevel(-1)); + //RooFitResult *fitresult = model->fitTo(*data,Save()); + + + RooPlot* sframe = s.frame(); + // sframe = s.frame(); + + htemp->Draw(); + if(var=="svtxm")data->plotOn(sframe,Binning(24)); + else data->plotOn(sframe,Binning(30)); + + if(fixCL) { + model->plotOn(sframe,Components(charmlight),LineStyle(kDashed),LineColor(30),LineWidth(2)); + } else { + model->plotOn(sframe,Components(light),LineStyle(kDashed),LineColor(kBlue),LineWidth(2)); + model->plotOn(sframe,Components(charm),LineStyle(kDashed),LineColor(kGreen),LineWidth(2)); + model->plotOn(sframe,Components(RooArgSet(charm,light)),LineStyle(kDashed),LineColor(30),LineWidth(2)); + } + model->plotOn(sframe,Components(bottom),LineStyle(kDashed),LineColor(kRed),LineWidth(2),FillColor(kRed),FillStyle(1)); + model->plotOn(sframe,LineWidth(2),VisualizeError(*fitresult),FillColor(17)); + model->plotOn(sframe,LineWidth(2),LineColor(13)); + if(var=="svtxm")data->plotOn(sframe,Binning(24)); + else data->plotOn(sframe,Binning(30)); + + model->paramOn(sframe,Layout(0.4,0.9,0.9),Format("NEU",FixedPrecision(3))); + sframe->Draw("same"); +// TLegend *leg = new TLegend(0.61,fixCL?0.60:0.50,0.98,fixCL?0.78:0.75); +// leg->SetBorderSize(0); +// leg->SetFillStyle(0); +// leg->AddEntry("h_data","PbPb data","p"); +// leg->AddEntry(Form("model_Norm[%s]_Comp[bottom]",var),"b","l"); +// if(fixCL) { +// leg->AddEntry(Form("model_Norm[%s]_Comp[charmlight]",var),"c + udsg","l"); +// } else { +// leg->AddEntry(Form("model_Norm[%s]_Comp[charm]",var),"c","l"); +// leg->AddEntry(Form("model_Norm[%s]_Comp[light]",var),"udsg","l"); +// leg->AddEntry(Form("model_Norm[%s]_Comp[charm,light]",var),"c + udsg","l"); +// } +// leg->AddEntry(Form("model_Norm[%s]",var),"b + c + udsg","l"); +// leg->Draw("same"); + + ////////////////////////////////////////////////////////// + //Plot Stacked histos + ////////////////////////////////////////////////////////// + int nXbins = 12; + bool doLog = true; + + hMCB[counter] = new TH1D(Form("hMCB_%d",counter),Form("hMCB_%d",counter),nXbins,minXvar,maxXvar); + hMCC[counter] = new TH1D(Form("hMCC_%d",counter),Form("hMCC_%d",counter),nXbins,minXvar,maxXvar); + hMCL[counter] = new TH1D(Form("hMCL_%d",counter),Form("hMCL_%d",counter),nXbins,minXvar,maxXvar); + hMCLC[counter] = new TH1D(Form("hMCLC_%d",counter),Form("hMCLC_%d",counter),nXbins,minXvar,maxXvar); + hData[counter] = new TH1D(Form("hData_%d",counter),Form("hData_%d",counter),nXbins,minXvar,maxXvar); + hData[counter]->Sumw2(); + hMCL[counter]->Sumw2(); hMCB[counter]->Sumw2(); hMCC[counter]->Sumw2(); hMCLC[counter]->Sumw2(); + + tBMC->Draw(Form("%s>>hMCB_%d",var.c_str(),counter),Form("weight*(abs(refparton_flavorForB)==5&&pVertexFilterCutGplusUpsPP&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&pthat>%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,ptHatMin),"goff"); + tCMC->Draw(Form("%s>>hMCC_%d",var.c_str(),counter),Form("weight*(abs(refparton_flavorForB)==4&&pVertexFilterCutGplusUpsPP&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&pthat>%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,ptHatMin),"goff"); + tQCDMC->Draw(Form("%s>>hMCL_%d",var.c_str(),counter),Form("weight*(abs(refparton_flavorForB)!=5&&pVertexFilterCutGplusUpsPP&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)<99&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f&&pthat>%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr,ptHatMin),"goff"); + + /* + tBMC->Draw(Form("%s>>hMCB_%d",var,counter),Form("weight*(abs(refparton_flavorForB)==5&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f)",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr),"goff"); + tCMC->Draw(Form("%s>>hMCC_%d",var,counter),Form("weight*(abs(refparton_flavorForB)==4&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f)",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr),"goff"); + tQCDMC->Draw(Form("%s>>hMCL_%d",var,counter),Form("weight*(abs(refparton_flavorForB)!=5&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)<99&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f)",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr),"goff"); + */ + tdata->Draw(Form("%s>>hData_%d",var.c_str(),counter),Form("weight*(pVertexFilterCutGplusUpsPP&&jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f)",ptMin,ptMax,discr.c_str(),minXdiscr,discr.c_str(),maxXdiscr),"goff"); + //tdata->Draw(Form("%s>>hData_%d",var,counter),Form("(jtpt>=%f&&jtpt<%f&&%s>=%f&&%s<%f)",ptMin,ptMax,discr,minXdiscr,discr,maxXdiscr),"goff"); + hMCLC[counter]->Add( hMCL[counter]); + hMCLC[counter]->Add( hMCC[counter]); + fixEmpty(hMCB[counter]); fixEmpty(hMCC[counter]); fixEmpty(hMCL[counter]); fixEmpty(hMCLC[counter]); fixEmpty(hData[counter]); + + + can1[counter] = new TCanvas(Form("can1_%d",counter),Form("can1_%d",counter),700,600); + hs[counter] = new THStack(Form("hs_%d",counter),"le stack of MC histos"); + ghosths[counter] = new THStack(Form("ghosths_%d",counter),"le fake stack of MC histos"); + + can1[counter]->cd(); + if (doLog) can1[counter]->cd()->SetLogy(); + + + if (doLog){ + hData[counter]->SetMaximum(hData[counter]->GetMaximum()*50); + hData[counter]->SetMinimum(2); + } + if (!doLog){ + hData[counter]->SetMaximum(hData[counter]->GetMaximum()*1.5); + hData[counter]->SetMinimum(0.0); + } + const char* yTitle = NULL; + const char* xTitle = NULL; + if (var=="svtxm") xTitle = Form("Secondary vertex mass (GeV/c^{2})"); + if (var=="discr_prob") xTitle = Form("Jet probability"); + //if (var=="svtxm") yTitle = (Form("Number of Jets / %3.2f GeV",(maxXvar-minXvar)/nXbins)); + //if (var=="discr_prob") yTitle = (Form("Numbers of Jets / %3.2f",(maxXvar-minXvar)/nXbins)); + if (var=="svtxm") yTitle = ("Number of jets"); + if (var=="discr_prob") yTitle = ("Number of jets"); + hData[counter]->GetXaxis()->CenterTitle(); + hData[counter]->GetYaxis()->CenterTitle(); + hData[counter]->GetYaxis()->SetTitle(yTitle); + hData[counter]->GetXaxis()->SetTitle(xTitle); + hData[counter]->SetMarkerStyle(8); + hData[counter]->SetMarkerSize(1.5); + //hData[counter]->SetMinismum(2); + hData[counter]->Draw(); + + + double Bnorm=0, Cnorm=0, Lnorm=0, LCnorm=0; + Double_t Bfrac =Bfraction->getVal(); + Double_t Cfrac =Cfraction->getVal(); + + //Normalize Histograms + if(!fixCL) Lnorm = (hData[counter]->Integral(1,nXbins)/ hMCL[counter]->Integral(1,nXbins))*(1.-Cfrac-Bfrac); + if(!fixCL) Cnorm = (hData[counter]->Integral(1,nXbins)/ hMCC[counter]->Integral(1,nXbins))*(Cfrac); + if(!fixCL) Bnorm = (hData[counter]->Integral(1,nXbins)/ hMCB[counter]->Integral(1,nXbins))*(Bfrac); + if(fixCL) LCnorm = (hData[counter]->Integral(1,nXbins)/hMCLC[counter]->Integral(1,nXbins))*(1.-Bfrac); + if(fixCL) Bnorm = (hData[counter]->Integral(1,nXbins)/ hMCB[counter]->Integral(1,nXbins))*(Bfrac); + + hMCB[counter]->SetFillColor(kRed-3); + hMCL[counter]->SetFillColor(kBlue-3); + hMCC[counter]->SetFillColor(kGreen-3); + hMCLC[counter]->SetFillColor(kBlue-3); +// hMCB[counter]->SetLineColor(kRed-4); +// hMCL[counter]->SetLineColor(kBlue-3); +// hMCC[counter]->SetLineColor(kGreen-3); +// hMCLC[counter]->SetLineColor(kBlue-3); + hMCB[counter]->SetMarkerSize(0); + hMCC[counter]->SetMarkerSize(0); + hMCL[counter]->SetMarkerSize(0); + hMCLC[counter]->SetMarkerSize(0); + //hMCB[counter]->Scale(Bnorm); + //hMCC[counter]->Scale(Cnorm); + //hMCL[counter]->Scale(Lnorm); + //hMCLC[counter]->Scale(LCnorm); + if (!fixCL){ + hMCB[counter]->Scale(Bnorm); + hMCC[counter]->Scale(Cnorm); + hMCL[counter]->Scale(Lnorm); + hs[counter]->Add(hMCB[counter]); + hs[counter]->Add(hMCC[counter]); + hs[counter]->Add(hMCL[counter]); + } + if (fixCL){ + hMCB[counter]->Scale(Bnorm); + hMCLC[counter]->Scale(LCnorm); + hs[counter]->Add(hMCB[counter]); + hs[counter]->Add(hMCLC[counter]); + } + + if(!fixCL)hs[counter]->Draw("same h e"); + hData[counter]->Draw("same"); + + + //This is a fake THstack to also plot the constribution from the charm, + //even though it is supposed to be merged with the Light contribution + //so first we will need to keep the b constribution, AS-IS + //then, find the relative ratio of the c to Light jets with the already-found + //fraction (1-Bfraction) + if(fixCL){ + ghosths[counter]->Add(hMCB[counter]); + double relC2LCfrac =(hMCC[counter]->Integral(1,nXbins))/(hMCC[counter]->Integral(1,nXbins) + hMCL[counter]->Integral(1,nXbins)); + double relL2LCfrac =(hMCL[counter]->Integral(1,nXbins))/(hMCC[counter]->Integral(1,nXbins) + hMCL[counter]->Integral(1,nXbins)); + fixCL_MCL[counter] = (TH1D*)hMCLC[counter]->Clone(Form("fixCL_MCL_%d",counter)); + fixCL_MCL[counter]->Scale(relL2LCfrac); + fixCL_MCC[counter] = (TH1D*)hMCLC[counter]->Clone(Form("fixCL_MCC_%d",counter)); + fixCL_MCC[counter]->Scale(relC2LCfrac); + fixCL_MCC[counter]->SetFillColor(kGreen-3); + fixCL_MCL[counter]->SetFillColor(kBlue-3); + fixCL_MCC[counter]->SetMarkerSize(0); + fixCL_MCL[counter]->SetMarkerSize(0); + ghosths[counter]->Add(fixCL_MCC[counter]); + ghosths[counter]->Add(fixCL_MCL[counter]); + ghosths[counter]->Draw("same h e"); + } + //To obtain the overall sum histogram of the MC counts + MCTotal[counter] = new TH1D(Form("MCTotal_%d",counter),Form("MCTotal_%d",counter),nXbins,minXvar,maxXvar); + MCTotal[counter]->Sumw2(); + if (!fixCL){ + MCTotal[counter]->Add(hMCB[counter]); + MCTotal[counter]->Add(hMCC[counter]); + MCTotal[counter]->Add(hMCL[counter]); + } + if (fixCL){ + MCTotal[counter]->Add(hMCB[counter]); + MCTotal[counter]->Add(hMCLC[counter]); + } + MCTotal[counter]->SetLineWidth(3); + MCTotal[counter]->SetMarkerSize(0); + MCTotal[counter]->SetMarkerColor(kGray+2); + MCTotal[counter]->SetLineColor(kBlue-9); + + MCSumGreen[counter] = new TH1D(Form("MCSumGreen_%d",counter),Form("MCSumGreen_%d",counter),nXbins,minXvar,maxXvar); + MCSumGreen[counter]->Sumw2(); + if (fixCL){ + MCSumGreen[counter]->Add(hMCB[counter]); + MCSumGreen[counter]->Add(fixCL_MCC[counter]); + } + MCSumGreen[counter]->SetLineWidth(3); + MCSumGreen[counter]->SetMarkerSize(0); + MCSumGreen[counter]->SetMarkerColor(kGreen-7); + MCSumGreen[counter]->SetLineColor(kGreen-7); + + + + //http://root.cern.ch/root/htmldoc/TH1.html#TH1:Chi2Test + //Double_t chi2 = hData[counter]->Chi2Test(MCTotal[counter],"UW CHI2 P"); + //Double_t chi2NDF = hData[counter]->Chi2Test(MCTotal[counter],"UW CHI2/NDF P"); + Double_t chi2 = hData[counter]->Chi2Test(MCTotal[counter],"WW CHI2 P"); + Double_t chi2NDF = hData[counter]->Chi2Test(MCTotal[counter],"WW CHI2/NDF P"); + MCTotal[counter]->Draw("same,e"); + MCSumGreen[counter]->Draw("same,e"); + + + // TH1F *hTaggedJetsMC = (TH1F*)hTaggedLJetsMC->Clone("hTaggedJetsMC"); + //Redraw some partial histograms to show error bars in between + if(fixCL){ + hMCB_copy[counter] = new TH1D(Form("hMCB_copy_%d",counter),Form("hMCB_copy_%d",counter),nXbins,minXvar,maxXvar); + hMCB_copy[counter]->Sumw2(); + hMCB_copy[counter] = (TH1D*)hMCB[counter]->Clone(Form("hMCB_copy_%d",counter)); + hMCB_copy[counter]->SetMarkerSize(0); + hMCB_copy[counter]->SetLineWidth(3); + hMCB_copy[counter]->SetLineColor(kRed-7); + hMCB_copy[counter]->SetMarkerColor(kRed-7); + hMCB_copy[counter]->Draw("same,e"); + } + hData[counter]->Draw("same"); + can1[counter]->GetFrame()->SetLineWidth(4); + can1[counter]->RedrawAxis(); + TLegend *hleg = new TLegend(0.63,fixCL?0.70:0.75,0.883,fixCL?0.92:0.92); + hleg->SetBorderSize(0); + hleg->SetFillStyle(0); + //hleg->SetTextSize(30); + hleg->AddEntry(hData[counter],"pp data","lp"); + hleg->AddEntry(hMCB[counter],"b","f"); + if(!fixCL){ + hleg->AddEntry(hMCC[counter],"c","f"); + hleg->AddEntry(hMCL[counter],"udsg","f"); + } + if(fixCL){ + hleg->AddEntry(fixCL_MCC[counter],"c","f"); + hleg->AddEntry(fixCL_MCL[counter],"usdg","f"); + } + hleg->Draw("same"); + + drawText(Form("%2.0f < p_{T} < %2.0f GeV/c",ptMin,ptMax),0.63,0.684); + //if(fixCL)drawText(Form("%2.0f < p_{T} < %2.0f GeV/c",ptMin,ptMax),0.50,0.66); + //drawText(Form("#chi^{2}/NDF = %3.1f / %d",chi2NDF,nXbins-1),0.53,0.55); + drawText(Form("#chi^{2}/NDF = %3.1f / %d",chi2,(int)(chi2/chi2NDF)),0.632,0.615); + drawText("CMS Preliminary",0.15,0.965); + drawText("#sqrt{s_{NN}} = 2.76 TeV",0.60,0.969); + drawText("|#eta| < 2.0",0.18,0.88); + if(comment!="b-tagged sample (SSVHE > 2)") drawText(comment,0.18,0.80); + if(comment=="b-tagged sample (SSVHE > 2)"){ + drawText("b-tagged sample",0.18,0.80); + //drawText("(SSVHE > 2)",0.18,0.75); + } + + + bool printEach=false; + // --- Print results --- + //cout <<"b jet fraction in MC = "<Print(Form("PDFS/fitpp_fixcl_%s_%f%s_%s.pdf",varLabel.c_str(),minXdiscr,fixCLlabel.c_str(),ptLabel.c_str()),"pdf"); + if (printEach) can1[counter]->Print(Form("MACROS/fitpp_%s_%f%s_%s.C",varLabel.c_str(),minXdiscr,fixCLlabel.c_str(),ptLabel.c_str()),"cxx"); + } + + if(!fixCL){ + if (!printEach){ + if (counterPrint("PDFS/bTagStackedHistos_nofixCL_NewFormatV5.pdf(","pdf"); + if (counter==nBins*3-1) can1[counter]->Print("PDFS/bTagStackedHistos_nofixCL_NewFormatV5.pdf)","pdf"); + } + + } + if(fixCL){ + if (!printEach){ + if (counterPrint("PDFS/bTagStackedHistos_fixCL_NewFormatV5.pdf(","pdf"); + if (counter==nBins*3-1) can1[counter]->Print("PDFS/bTagStackedHistos_fixCL_NewFormatV5.pdf)","pdf"); + } + } + counter++; + + + + // --- Save canvas --- + TString path = Form("gifs/%s_jtpt%.0fto%.0f_%s%.2fto%.2f_%s.gif",var.c_str(),ptMin,ptMax,discr.c_str(),minXdiscr,maxXdiscr,fixCL?"CLfixed":"CLfree"); + //cROOFIT->SaveAs(path); + + // ========== Toy check on MC template ========== + if (toyMC) { + TH1F *hToyResult = new TH1F("hToyResult","",200,0,Bfraction->getVal()*2); + char *pathToy = Form("toyMC/jtpt%.0fto%.0f_%s%.2fto%.2f_%s",ptMin,ptMax,discr.c_str(),minXdiscr,maxXdiscr,fixCL?"CLfixed":"CLfree"); + TCanvas *cToy = new TCanvas("cToy",pathToy,700,600); + int nExp = 100; + for (int iExp=0;iExpFill(BfractionToy->getVal()); + delete hBToy; + delete hCToy; + delete hLToy; + delete hCLToy; + } + hToyResult->Draw(); + cToy->SaveAs(Form("toyMC/jtpt_cent_%.0f-%.0f_%.0fto%.0f_%s%.2fto%.2f_%s.gif",cbinlo*2.5,cbinhi*2.5,ptMin,ptMax,discr.c_str(),minXdiscr,maxXdiscr,fixCL?"CLfixed":"CLfree")); + cToy->SaveAs(Form("toyMC/jtpt_cent_%.0f-%.0f_%.0fto%.0f_%s%.2fto%.2f_%s.C",cbinlo*2.5,cbinhi*2.5,ptMin,ptMax,discr.c_str(),minXdiscr,maxXdiscr,fixCL?"CLfixed":"CLfree")); + delete hToyResult; + delete cToy; + } + /* + delete fdata; + delete fQCDMC; + delete fBMC; + delete fCMC; + */ + + delete hB; + delete hC; + delete hL; + delete hCL; + + return Bfraction; + +} + +void drawText(const std::string text, float xp, float yp){ + TLatex *tex = new TLatex(xp,yp,text.c_str()); + tex->SetTextFont(43); + tex->SetTextSize(23); + tex->SetTextColor(kBlack); + tex->SetLineWidth(1); + tex->SetNDC(); + tex->Draw(); +} +void format1D(TH1& h1, TCanvas& c1 ){ + h1.GetXaxis()->CenterTitle(); + h1.GetYaxis()->CenterTitle(); + c1.cd(); + c1.RedrawAxis(); + return; +} + +void fillCounterHistos(std::string discr, double workingPoint, int cbinlo, int cbinhi, float etalo, float etahi) { + + hTaggedLJetsMC = new TH1D("hTaggedLJetsMC","hTaggedLJetsMC",nBins,ptBin); + hTaggedLJetsMC->Sumw2(); + tQCDMC->Draw("jtpt>>hTaggedLJetsMC",Form("weight*(pVertexFilterCutGplusUpsPP&&%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)!=5)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); + + hTaggedCJetsMC = new TH1D("hTaggedCJetsMC","hTaggedCJetsMC",nBins,ptBin); + hTaggedCJetsMC->Sumw2(); + tCMC->Draw("jtpt>>hTaggedCJetsMC",Form("weight*(pVertexFilterCutGplusUpsPP&&%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==4)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); + + hTaggedBJetsMC = new TH1D("hTaggedBJetsMC","hTaggedBJetsMC",nBins,ptBin); + hTaggedBJetsMC->Sumw2(); + tBMC->Draw("jtpt>>hTaggedBJetsMC",Form("weight*(pVertexFilterCutGplusUpsPP&&%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==5)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); + + hTaggedJetsMC = (TH1D*)hTaggedLJetsMC->Clone("hTaggedJetsMC"); + + hTaggedJetsMC->Add(hTaggedCJetsMC); + hTaggedJetsMC->Add(hTaggedBJetsMC); + + + hUntaggedLJetsMC = new TH1D("hUntaggedLJetsMC","hUntaggedLJetsMC",nBins,ptBin); + hUntaggedLJetsMC->Sumw2(); + tQCDMC->Draw("jtpt>>hUntaggedLJetsMC",Form("weight*(pVertexFilterCutGplusUpsPP&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)!=4&&abs(refparton_flavorForB)!=5&&refpt>0)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); + + hUntaggedCJetsMC = new TH1D("hUntaggedCJetsMC","hUntaggedCJetsMC",nBins,ptBin); + hUntaggedCJetsMC->Sumw2(); + tCMC->Draw("jtpt>>hUntaggedCJetsMC",Form("weight*(pVertexFilterCutGplusUpsPP&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==4&&refpt>0)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); + + hUntaggedBJetsMC = new TH1D("hUntaggedBJetsMC","hUntaggedBJetsMC",nBins,ptBin); + hUntaggedBJetsMC->Sumw2(); + tBMC->Draw("jtpt>>hUntaggedBJetsMC",Form("weight*(pVertexFilterCutGplusUpsPP&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&abs(refparton_flavorForB)==5&&refpt>0)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); + + hUntaggedJetsMC = (TH1D*)hUntaggedLJetsMC->Clone("hUntaggedJetsMC"); + + hUntaggedJetsMC->Add(hUntaggedCJetsMC); + hUntaggedJetsMC->Add(hUntaggedBJetsMC); + + hBjetsWithJPinfoMC = new TH1D("hBjetsWithJPinfoMC","",nBins,ptBin); + hBjetsWithJPinfoMC->Sumw2(); + tBMC->Draw("jtpt>>hBjetsWithJPinfoMC",Form("weight*(pVertexFilterCutGplusUpsPP&&abs(refparton_flavorForB)==5&&discr_prob>0&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&refpt>0)",cbinlo,cbinhi,etalo,etahi)); + + hBjetsWithCSVinfoMC = new TH1D("hBjetsWithCSVinfoMC","",nBins,ptBin); + hBjetsWithCSVinfoMC->Sumw2(); + tBMC->Draw("jtpt>>hBjetsWithCSVinfoMC",Form("weight*(pVertexFilterCutGplusUpsPP&&abs(refparton_flavorForB)==5&&discr_prob>0&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f&&refpt>0)",cbinlo,cbinhi,etalo,etahi)); + + hTaggedJetsData = new TH1D("hTaggedJetsData","",nBins,ptBin); + hTaggedJetsData->Sumw2(); + tdata->Draw("jtpt>>hTaggedJetsData",Form("weight*(pVertexFilterCutGplusUpsPP&&%s>=%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); + + hUntaggedJetsData = new TH1D("hUntaggedJetsData","",nBins,ptBin); + hUntaggedJetsData->Sumw2(); + tdata->Draw("jtpt>>hUntaggedJetsData",Form("weight*(pVertexFilterCutGplusUpsPP&&%s<%f&&bin>=%d&&bin<%d&&abs(jteta)>%f&&abs(jteta)<%f)",discr.c_str(),workingPoint,cbinlo,cbinhi,etalo,etahi)); +} + +Enumerations count(double ptMin, double ptMax) { + + Enumerations res; + int currentBin = hTaggedJetsMC->FindBin(ptMin+1.); + if(hTaggedJetsMC->FindBin(ptMax-1.) != currentBin) cout<<" BINNING PROBLEM "<GetBinContent(currentBin); + res.nUntaggedJetsMC = hUntaggedJetsMC->GetBinContent(currentBin); + res.nJetsMC = res.nTaggedJetsMC + res.nUntaggedJetsMC; + res.nTaggedBjetsMC = hTaggedBJetsMC->GetBinContent(currentBin); + res.nUntaggedBjetsMC = hUntaggedBJetsMC->GetBinContent(currentBin); + res.nBjetsMC = res.nTaggedBjetsMC + res.nUntaggedBjetsMC; + res.nNonBjetsMC = res.nJetsMC - res.nBjetsMC; + res.nTaggedNonBjetsMC = res.nTaggedJetsMC - res.nTaggedBjetsMC; + + res.nTaggedJetsData = hTaggedJetsData->GetBinContent(currentBin); + res.nUntaggedJetsData = hUntaggedJetsData->GetBinContent(currentBin); + + res.cbForJP = hBjetsWithJPinfoMC->GetBinContent(currentBin) / res.nBjetsMC; + res.cbForCSV = hBjetsWithCSVinfoMC->GetBinContent(currentBin) / res.nBjetsMC; + + res.nTaggedJetsMCError = hTaggedJetsMC->GetBinError(currentBin); + res.nUntaggedJetsMCError = hUntaggedJetsMC->GetBinError(currentBin); + res.nJetsMCError = addError(res.nTaggedJetsMCError,res.nUntaggedJetsMCError); + res.nTaggedBjetsMCError = hTaggedBJetsMC->GetBinError(currentBin); + res.nUntaggedBjetsMCError = hUntaggedBJetsMC->GetBinError(currentBin); + res.nBjetsMCError = addError(res.nTaggedBjetsMCError,res.nUntaggedBjetsMCError); + res.nNonBjetsMCError = substractError(res.nJetsMCError,res.nBjetsMCError); + res.nTaggedNonBjetsMCError = substractError(res.nTaggedJetsMCError,res.nTaggedBjetsMCError); + + res.nTaggedJetsDataError = hTaggedJetsData->GetBinError(currentBin); + res.nUntaggedJetsDataError = hUntaggedJetsData->GetBinError(currentBin); + + res.nJetsData = res.nTaggedJetsData + res.nUntaggedJetsData; + res.nJetsDataError = addError(res.nTaggedJetsDataError,res.nUntaggedJetsDataError); + + return res; +} + diff --git a/compareDataMC.C b/compareDataMC.C index a992563..a0bce78 100644 --- a/compareDataMC.C +++ b/compareDataMC.C @@ -6,9 +6,9 @@ void formatHisto(TH1F *h, char *title){ } void setFillColor(TH1F *h[3]){ - h[0]->SetFillColor(kred); - h[1]->SetFillColor(kgreen); - h[2]->SetFillColor(kblue); + h[0]->SetFillColor(kRed); + h[1]->SetFillColor(kGreen); + h[2]->SetFillColor(kBlue); } void formatCanvas(TCanvas *c){ @@ -31,6 +31,9 @@ void formatRatioHist(TH1F *h){ } void stackHistos(TH1F *hArray[3]){ + hArray[0]->SetMarkerSize(0); + hArray[1]->SetMarkerSize(0); + hArray[2]->SetMarkerSize(0); hArray[1]->Add(hArray[0]); hArray[2]->Add(hArray[1]); } @@ -41,7 +44,7 @@ void scaleHistos(TH1F *hdata, TH1F *hArray[3]){ } -void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1) { +void compareDataMC(int ppPbPb=0, int plotSV=1, int plotTracks=1, int savePlots=1) { gStyle->SetOptStat(0); gStyle->SetOptTitle(0); @@ -57,16 +60,16 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 TFile *fMC[3], *fdata; if(ppPbPb){ - fMC[0] = new TFile("./histos/PbPbBMC.root"); - fMC[1] = new TFile("./histos/PbPbCMC.root"); - fMC[2] = new TFile("./histos/PbPbQCDMC.root"); - fdata = new TFile("./histos/PbPbdata.root"); + fMC[0] = new TFile("./histos/PbPbBMC_pt30by3_ipHICalibCentWeight.root"); + fMC[1] = new TFile("./histos/PbPbCMC_pt30by3_ipHICalibCentWeight.root"); + fMC[2] = new TFile("./histos/PbPbQCDMC_pt30by3_ipHICalibCentWeight.root"); + fdata = new TFile("./histos/PbPbdata_pt30by3_jpHICalibRepass_withDup.root"); } else{ - fMC[0] = new TFile("./histos/ppMC_hiReco_jetTrig_highPurity.root"); - fMC[1] = new TFile("./histos/ppMC_hiReco_jetTrig_highPurity.root"); - fMC[2] = new TFile("./histos/ppMC_hiReco_jetTrig_highPurity.root"); - fdata = new TFile("./histos/ppdata_hiReco_jetTrig_highPurity.root"); + fMC[0] = new TFile("./histos/ppMC_ppReco_ak3PF_BjetTrig_noIPupperCut_9-15.root"); + fMC[1] = new TFile("./histos/ppMC_ppReco_ak3PF_CjetTrig_noIPupperCut_9-15.root"); + fMC[2] = new TFile("./histos/ppMC_ppReco_ak3PF_QCDjetTrig_noIPupperCut_9-15.root"); + fdata = new TFile("./histos/ppdata_ppReco_ak3PF_jetTrig_noIPupperCut_9-15.root"); } // declare histos TH1F *hjtpt, *hrawpt, *hjteta, *hjtphi, *hnsvtx, *hsvtxntrk, *hsvtxdl, *hsvtxdls, *hsvtxm, *hsvtxmSV3, *hsvtxpt, *hsvtxptSV3, *hnIPtrk, *hnselIPtrk, *hdiscr_csvSimple, *hdiscr_prob, *hdiscr_ssvHighEff, *hdiscr_ssvHighPur, *hmuptrel, *hmuptrelSV2, *hmuptrelSV3, *hipPt, *hipProb0, *hipProb1, *hip2d, *hip2dSig, *hip3d, *hip3dSig, *hip2d1, *hip2dSig, *hip3d1, *hip3dSig1, *hip2d2, *hip2dSig2, *hip3d2, *hip3dSig2, *hip2d3, *hip2dSig3, *hip3d3, *hip3dSig3, *hipDist2Jet, *hipDist2JetSig, *hipClosest2Jet; @@ -494,14 +497,14 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 setFillColor(hipDist2JetSigMC); setFillColor(hipClosest2JetMC); - TLegend *leg = new TLegend(0.15,0.55,0.45,0.85); + TLegend *leg = new TLegend(0.699,0.62,0.89,0.92); leg->SetBorderSize(0); leg->SetFillStyle(0); if(ppPbPb)leg->AddEntry(hjtpt,"PbPb data, 0-100%","p"); - else leg->AddEntry(hjtpt,"pp data, 2.76 TeV","p"); - leg->AddEntry(hjtptMC[0],"b","f"); - leg->AddEntry(hjtptMC[1],"c","f"); - leg->AddEntry(hjtptMC[2],"udsg","f"); + else leg->AddEntry(hjtpt,"pp data","p"); + leg->AddEntry(hjtptMC[0],"b-jet","f"); + leg->AddEntry(hjtptMC[1],"c-jet","f"); + leg->AddEntry(hjtptMC[2],"udsg-jet","f"); // draw em @@ -526,6 +529,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRjtpt); hRjtpt->Divide(hjtptMC[2]); hRjtpt->Draw(); + c0->SaveAs("plotsNewpp/jetPt.pdf"); char *title = "Jet raw p_{T} (GeV/c)"; TCanvas *c0bis=new TCanvas("c0bis",title,200,10,600,480); @@ -542,6 +546,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRrawpt); hRrawpt->Divide(hrawptMC[2]); hRrawpt->Draw(); + c0bis->SaveAs("plotsNewpp/jetRawPt.pdf"); char *title = "Jet #eta"; TCanvas *c0a=new TCanvas("c0a",title,200,10,600,480); @@ -560,7 +565,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRjteta); hRjteta->Divide(hjtetaMC[2]); hRjteta->Draw(); - c0a->SaveAs(Form("plotsPbPb/%s.gif",title)); + c0a->SaveAs(Form("plotsNewpp/%s.pdf",title)); char *title = "Jet #phi"; TCanvas *c0b=new TCanvas("c0b",title,200,10,600,480); @@ -579,7 +584,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRjtphi); hRjtphi->Divide(hjtphiMC[2]); hRjtphi->Draw(); - if(savePlots)c0b->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c0b->SaveAs(Form("plotsNewpp/%s.pdf",title)); if(plotSV){ title = "# of secondary vertices"; @@ -597,7 +602,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRnsvtx); hRnsvtx->Divide(hnsvtxMC[2]); hRnsvtx->Draw(); - if(savePlots)c1->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c1->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "tracks per SV"; TCanvas *c2=new TCanvas("c2",title,200,10,600,480); @@ -614,7 +619,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRsvtxntrk); hRsvtxntrk->Divide(hsvtxntrkMC[2]); hRsvtxntrk->Draw(); - if(savePlots)c2->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c2->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "flight distance"; TCanvas *c3=new TCanvas("c3",title,200,10,600,480); @@ -631,7 +636,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRsvtxdl); hRsvtxdl->Divide(hsvtxdlMC[2]); hRsvtxdl->Draw(); - if(savePlots)c3->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c3->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "flight distance significance"; TCanvas *c4=new TCanvas("c4",title,200,10,600,480); @@ -648,7 +653,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRsvtxdls); hRsvtxdls->Divide(hsvtxdlsMC[2]); hRsvtxdls->Draw(); - if(savePlots)c4->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c4->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "SV mass"; TCanvas *c5=new TCanvas("c5",title,200,10,600,480); @@ -665,7 +670,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRsvtxm); hRsvtxm->Divide(hsvtxmMC[2]); hRsvtxm->Draw(); - if(savePlots)c5->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c5->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "3 track SV mass"; TCanvas *c5b=new TCanvas("c5b",title,200,10,600,480); @@ -682,7 +687,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRsvtxmSV3); hRsvtxmSV3->Divide(hsvtxmSV3MC[2]); hRsvtxmSV3->Draw(); - if(savePlots)c5b->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c5b->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "SV pT"; TCanvas *c6=new TCanvas("c6",title,200,10,600,480); @@ -699,7 +704,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRsvtxpt); hRsvtxpt->Divide(hsvtxptMC[2]); hRsvtxpt->Draw(); - if(savePlots)c6->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c6->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "3 track SV pT"; TCanvas *c6b=new TCanvas("c6b",title,200,10,600,480); @@ -716,7 +721,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRsvtxptSV3); hRsvtxptSV3->Divide(hsvtxptSV3MC[2]); hRsvtxptSV3->Draw(); - if(savePlots)c6b->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c6b->SaveAs(Form("plotsNewpp/%s.pdf",title)); } if(plotTracks){ @@ -738,7 +743,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 hRnIPtrk->Divide(hnIPtrkMC[2]); hRnIPtrk->GetXaxis()->SetRangeUser(0,60); hRnIPtrk->Draw(); - if(savePlots)c7->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c7->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "# of selected IP tracks"; TCanvas *c8=new TCanvas("c8",title,200,10,600,480); @@ -758,7 +763,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 hRnselIPtrk->Divide(hnselIPtrkMC[2]); hRnselIPtrk->GetXaxis()->SetRangeUser(0,60); hRnselIPtrk->Draw(); - if(savePlots)c8->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c8->SaveAs(Form("plotsNewpp/%s.pdf",title)); } if(plotSV){ @@ -777,7 +782,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRdiscr_csvSimple); hRdiscr_csvSimple->Divide(hdiscr_csvSimpleMC[2]); hRdiscr_csvSimple->Draw(); - if(savePlots)c9->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c9->SaveAs(Form("plotsNewpp/%s.pdf",title)); } if(plotTracks){ @@ -796,7 +801,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRdiscr_prob); hRdiscr_prob->Divide(hdiscr_probMC[2]); hRdiscr_prob->Draw(); - if(savePlots)c10->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c10->SaveAs(Form("plotsNewpp/%s.pdf",title)); } if(plotSV){ @@ -815,7 +820,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRdiscr_ssvHighEff); hRdiscr_ssvHighEff->Divide(hdiscr_ssvHighEffMC[2]); hRdiscr_ssvHighEff->Draw(); - if(savePlots)c10a->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c10a->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "SSVHP"; TCanvas *c10b=new TCanvas("c10b",title,200,10,600,480); @@ -832,7 +837,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRdiscr_ssvHighPur); hRdiscr_ssvHighPur->Divide(hdiscr_ssvHighPurMC[2]); hRdiscr_ssvHighPur->Draw(); - if(savePlots)c10b->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c10b->SaveAs(Form("plotsNewpp/%s.pdf",title)); } if(plotTracks){ @@ -851,7 +856,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRipPt); hRipPt->Divide(hipPtMC[2]); hRipPt->Draw(); - if(savePlots)c11->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c11->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "hipProb0"; TCanvas *c12=new TCanvas("c12",title,200,10,600,480); @@ -868,7 +873,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRipProb0); hRipProb0->Divide(hipProb0MC[2]); hRipProb0->Draw(); - if(savePlots)c12->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c12->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "hipProb1"; TCanvas *c13=new TCanvas("c13",title,200,10,600,480); @@ -885,7 +890,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRipProb1); hRipProb1->Divide(hipProb1MC[2]); hRipProb1->Draw(); - if(savePlots)c13->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c13->SaveAs(Form("plotsNewpp/%s.pdf",title)); /* // doing it track by track instead title = "2D IP"; TCanvas *c14=new TCanvas("c14",title,200,10,600,480); @@ -902,7 +907,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip2d); hRip2d->Divide(hip2dMC[2]); hRip2d->Draw(); - if(savePlots)c14->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c14->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "2D IP Significance"; TCanvas *c15=new TCanvas("c15",title,200,10,600,480); @@ -919,7 +924,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip2dSig); hRip2dSig->Divide(hip2dSigMC[2]); hRip2dSig->Draw(); - if(savePlots)c15->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c15->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "3D IP"; TCanvas *c16=new TCanvas("c16",title,200,10,600,480); @@ -936,7 +941,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip3d); hRip3d->Divide(hip3dMC[2]); hRip3d->Draw(); - if(savePlots)c16->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c16->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "3D IP Significance"; TCanvas *c17=new TCanvas("c17",title,200,10,600,480); @@ -953,7 +958,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip3dSig); hRip3dSig->Divide(hip3dSigMC[2]); hRip3dSig->Draw(); - if(savePlots)c17->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c17->SaveAs(Form("plotsNewpp/%s.pdf",title)); */ title = "2D IP 1st track"; @@ -971,7 +976,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip2d1); hRip2d1->Divide(hip2d1MC[2]); hRip2d1->Draw(); - if(savePlots)c14a->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c14a->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "2D IP Significance 1st track"; TCanvas *c15a=new TCanvas("c15a",title,200,10,600,480); @@ -988,7 +993,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip2dSig1); hRip2dSig1->Divide(hip2dSig1MC[2]); hRip2dSig1->Draw(); - if(savePlots)c15a->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c15a->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "3D1 IP 1st track"; TCanvas *c16a=new TCanvas("c16a",title,200,10,600,480); @@ -1005,7 +1010,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip3d1); hRip3d1->Divide(hip3d1MC[2]); hRip3d1->Draw(); - if(savePlots)c16a->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c16a->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "3D IP Significance 1st track"; TCanvas *c17a=new TCanvas("c17a",title,200,10,600,480); @@ -1022,7 +1027,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip3dSig1); hRip3dSig1->Divide(hip3dSig1MC[2]); hRip3dSig1->Draw(); - if(savePlots)c17a->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c17a->SaveAs(Form("plotsNewpp/%s.pdf",title)); @@ -1041,7 +1046,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip2d2); hRip2d2->Divide(hip2d2MC[2]); hRip2d2->Draw(); - if(savePlots)c14b->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c14b->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "2D IP Significance 2nd track"; TCanvas *c15b=new TCanvas("c15b",title,200,10,600,480); @@ -1058,7 +1063,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip2dSig2); hRip2dSig2->Divide(hip2dSig2MC[2]); hRip2dSig2->Draw(); - if(savePlots)c15b->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c15b->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "3D IP 2nd track"; TCanvas *c16b=new TCanvas("c16b",title,200,10,600,480); @@ -1075,7 +1080,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip3d2); hRip3d2->Divide(hip3d2MC[2]); hRip3d2->Draw(); - if(savePlots)c16b->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c16b->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "3D IP Significance 2nd track"; TCanvas *c17b=new TCanvas("c17b",title,200,10,600,480); @@ -1092,7 +1097,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip3dSig2); hRip3dSig2->Divide(hip3dSig2MC[2]); hRip3dSig2->Draw(); - if(savePlots)c17b->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c17b->SaveAs(Form("plotsNewpp/%s.pdf",title)); @@ -1111,7 +1116,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip2d3); hRip2d3->Divide(hip2d3MC[2]); hRip2d3->Draw(); - if(savePlots)c14c->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c14c->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "2D IP Significance 3rd track"; TCanvas *c15c=new TCanvas("c15c",title,200,10,600,480); @@ -1128,7 +1133,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip2dSig3); hRip2dSig3->Divide(hip2dSig3MC[2]); hRip2dSig3->Draw(); - if(savePlots)c15c->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c15c->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "3D IP 3rd track"; TCanvas *c16c=new TCanvas("c16c",title,200,10,600,480); @@ -1145,7 +1150,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip3d3); hRip3d3->Divide(hip3d3MC[2]); hRip3d3->Draw(); - if(savePlots)c16c->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c16c->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "3D IP Significance 3rd track"; TCanvas *c17c=new TCanvas("c17c",title,200,10,600,480); @@ -1162,7 +1167,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRip3dSig3); hRip3dSig3->Divide(hip3dSig3MC[2]); hRip3dSig3->Draw(); - if(savePlots)c17c->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c17c->SaveAs(Form("plotsNewpp/%s.pdf",title)); @@ -1181,7 +1186,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRipDist2Jet); hRipDist2Jet->Divide(hipDist2JetMC[2]); hRipDist2Jet->Draw(); - if(savePlots)c18->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c18->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "hipDist2JetSig"; TCanvas *c19=new TCanvas("c19",title,200,10,600,480); @@ -1198,7 +1203,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRipDist2JetSig); hRipDist2JetSig->Divide(hipDist2JetSigMC[2]); hRipDist2JetSig->Draw(); - if(savePlots)c19->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c19->SaveAs(Form("plotsNewpp/%s.pdf",title)); title = "Decay length"; TCanvas *c20=new TCanvas("c20",title,200,10,600,480); @@ -1215,7 +1220,7 @@ void compareDataMC(int ppPbPb=1, int plotSV=0, int plotTracks=1, int savePlots=1 formatRatioHist(hRipClosest2Jet); hRipClosest2Jet->Divide(hipClosest2JetMC[2]); hRipClosest2Jet->Draw(); - if(savePlots)c20->SaveAs(Form("plotsPbPb/%s.gif",title)); + if(savePlots)c20->SaveAs(Form("plotsNewpp/%s.pdf",title)); } /* title = "muon pTrel"; diff --git a/createReco2GenMatrix.C b/createReco2GenMatrix.C index 8e5228d..f2b62d3 100644 --- a/createReco2GenMatrix.C +++ b/createReco2GenMatrix.C @@ -3,51 +3,63 @@ #include "TTree.h" #include "TH2.h" -void createReco2GenMatrix(){ +void createReco2GenMatrix(int ppPbPb=0){ - - TFile *fin = new TFile("~/bTagging442p5/CMSSW_4_4_2_patch5/src/UserCode/kjung/bTaggerCode/histos/PbPbBMC_pt30by3_ipHICalibCentWeight_noTrig.root"); + gStyle->SetOptStat(0); + gStyle->SetOptTitle(0); + + TFile *fin = NULL; + if(ppPbPb) fin = new TFile("histos/PbPbBMC_pt30by3_ipHICalibCentWeight_noTrig.root"); + else fin = new TFile("histos/ppMC_ppReco_ak3PF_jetptcut30_BjetTrig_noIPupperCut.root"); TTree *t=(TTree*) fin->Get("nt"); - double binBounds[7] = {55,65,80,100,120,150,200}; + //double binBounds[7] = {55,65,80,100,120,150,200}; + const int nBins=7; + double binBounds[nBins+1] = {60,70,80,90,110,130,170,250}; - TH2F *hRecoVsGen = new TH2F("hRecoVsGen","hRecoVsGen;genJet p_{T} (GeV/c);recoJet p_{T} (GeV/c)",6,binBounds,6,binBounds); + TH2F *hRecoVsGen = new TH2F("hRecoVsGen","hRecoVsGen;genJet p_{T} (GeV/c);recoJet p_{T} (GeV/c)",nBins,binBounds,nBins,binBounds); hRecoVsGen->Sumw2(); double jtpt, jteta, refpt, discr_ssvHighEff, pthat, weight; - int refparton_flavorForB, bin, trigIndex; + int refparton_flavorForB, bin, isTrig; - t->SetBranchAddress("jtpt",&jtpt); + if(ppPbPb)t->SetBranchAddress("jtptB",&jtpt); + else t->SetBranchAddress("jtpt",&jtpt); t->SetBranchAddress("jteta",&jteta); t->SetBranchAddress("refpt",&refpt); t->SetBranchAddress("discr_ssvHighEff",&discr_ssvHighEff); t->SetBranchAddress("pthat",&pthat); t->SetBranchAddress("refparton_flavorForB",&refparton_flavorForB); - t->SetBranchAddress("bin",&bin); - t->SetBranchAddress("trigIndex",&trigIndex); + //t->SetBranchAddress("bin",&bin); + if(ppPbPb) t->SetBranchAddress("jet65",&isTrig); + else t->SetBranchAddress("HLT_Jet40_noJetID_v1",&isTrig); t->SetBranchAddress("weight",&weight); for(int i=0;iGetEntries();i++){ t->GetEntry(i); - if(trigIndex<2) continue; + //if(!isTrig) continue; if(abs(refparton_flavorForB)!=5) continue; - if(discr_ssvHighEff<2)continue; + //if(discr_ssvHighEff<2)continue; if(abs(jteta)>2) continue; - - - // cutoffs to keep stat errors under control - if(jtpt>100&&pthat<50) continue; - if(jtpt>120&&pthat<65) continue; - if(jtpt>150&&pthat<80) continue; - + if(jtpt<60) continue; + /* + if(ppPbPb){ + // cutoffs to keep stat errors under control -- still needed? + if(jtpt>100&&pthat<50) continue; + if(jtpt>120&&pthat<65) continue; + if(jtpt>150&&pthat<80) continue; + } + */ hRecoVsGen->Fill(refpt,jtpt,weight); } - TFile *fout=new TFile("temp.root","recreate"); + TFile *fout=NULL; + if(ppPbPb) fout=new TFile("outputTowardsFinal/reco2GenMatrix.root","recreate"); + else fout=new TFile("output/reco2GenMatrix_pp.root","recreate"); hRecoVsGen->Write(); diff --git a/data/NewFormatV5_bFractionDataTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.0FixCL1_bin_0_40_eta_0_2.root b/data/NewFormatV5_bFractionDataTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.0FixCL1_bin_0_40_eta_0_2.root new file mode 100644 index 0000000..40deaa7 Binary files /dev/null and b/data/NewFormatV5_bFractionDataTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.0FixCL1_bin_0_40_eta_0_2.root differ diff --git a/data/NewFormatV5_bFractionMCTemplate_pppp1_gspDown_jetcut30_dinkoXchk_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root b/data/NewFormatV5_bFractionMCTemplate_pppp1_gspDown_jetcut30_dinkoXchk_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root new file mode 100644 index 0000000..eb1cb4e Binary files /dev/null and b/data/NewFormatV5_bFractionMCTemplate_pppp1_gspDown_jetcut30_dinkoXchk_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root differ diff --git a/data/NewFormatV5_bFractionMCTemplate_pppp1_gspUp_jetcut30_dinkoXchk_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root b/data/NewFormatV5_bFractionMCTemplate_pppp1_gspUp_jetcut30_dinkoXchk_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root new file mode 100644 index 0000000..fb99d10 Binary files /dev/null and b/data/NewFormatV5_bFractionMCTemplate_pppp1_gspUp_jetcut30_dinkoXchk_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root differ diff --git a/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat1.8FixCL0_bin_0_40_eta_0_2.root b/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat1.8FixCL0_bin_0_40_eta_0_2.root new file mode 100644 index 0000000..cc3fbba Binary files /dev/null and b/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat1.8FixCL0_bin_0_40_eta_0_2.root differ diff --git a/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root b/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root new file mode 100644 index 0000000..fc6ae57 Binary files /dev/null and b/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root differ diff --git a/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.0FixCL1_bin_0_40_eta_0_2.root b/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.0FixCL1_bin_0_40_eta_0_2.root new file mode 100644 index 0000000..8829f84 Binary files /dev/null and b/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.0FixCL1_bin_0_40_eta_0_2.root differ diff --git a/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.5FixCL0_bin_0_40_eta_0_2.root b/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.5FixCL0_bin_0_40_eta_0_2.root new file mode 100644 index 0000000..736eb4c Binary files /dev/null and b/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.5FixCL0_bin_0_40_eta_0_2.root differ diff --git a/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_gPlusFilter_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root b/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_gPlusFilter_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root new file mode 100644 index 0000000..4e4da9a Binary files /dev/null and b/data/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_gPlusFilter_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root differ diff --git a/data/hist_PbPb_Bottom.root b/data/hist_PbPb_Bottom.root new file mode 100644 index 0000000..80597ac Binary files /dev/null and b/data/hist_PbPb_Bottom.root differ diff --git a/data/hist_PbPb_Charm.root b/data/hist_PbPb_Charm.root new file mode 100644 index 0000000..80db08d Binary files /dev/null and b/data/hist_PbPb_Charm.root differ diff --git a/data/hist_PbPb_Light.root b/data/hist_PbPb_Light.root new file mode 100644 index 0000000..5fea60e Binary files /dev/null and b/data/hist_PbPb_Light.root differ diff --git a/data/hist_pPb_Bottom.root b/data/hist_pPb_Bottom.root new file mode 100644 index 0000000..fea2a4b Binary files /dev/null and b/data/hist_pPb_Bottom.root differ diff --git a/data/hist_pPb_Charm.root b/data/hist_pPb_Charm.root new file mode 100644 index 0000000..2fa9e4f Binary files /dev/null and b/data/hist_pPb_Charm.root differ diff --git a/data/hist_pPb_Light.root b/data/hist_pPb_Light.root new file mode 100644 index 0000000..40de976 Binary files /dev/null and b/data/hist_pPb_Light.root differ diff --git a/data/hist_pp.root b/data/hist_pp.root new file mode 100644 index 0000000..f40d39d Binary files /dev/null and b/data/hist_pp.root differ diff --git a/data/hist_pp_Bottom.root b/data/hist_pp_Bottom.root new file mode 100644 index 0000000..942ebf6 Binary files /dev/null and b/data/hist_pp_Bottom.root differ diff --git a/data/hist_pp_Charm.root b/data/hist_pp_Charm.root new file mode 100644 index 0000000..eb622c0 Binary files /dev/null and b/data/hist_pp_Charm.root differ diff --git a/data/hist_pp_Light.root b/data/hist_pp_Light.root new file mode 100644 index 0000000..e29b630 Binary files /dev/null and b/data/hist_pp_Light.root differ diff --git a/data/reco2GenMatrix_pp.root b/data/reco2GenMatrix_pp.root new file mode 100644 index 0000000..b7b6b85 Binary files /dev/null and b/data/reco2GenMatrix_pp.root differ diff --git a/deriveScaleCorr.C b/deriveScaleCorr.C index cceacec..57b9e8d 100644 --- a/deriveScaleCorr.C +++ b/deriveScaleCorr.C @@ -1,58 +1,89 @@ -#include "TF1.h" -#include "TH1.h" -#include "TRandom.h" -#include "TCanvas.h" - -void deriveScaleCorr(long ntries=100000000){ - - - TF1 *dndpt = new TF1("dndpt","pow(x,-5.95)",40,250); - TF1 *bscaleCorr = new TF1("bscaleCorr","[0]+[1]*log(x)+[2]*log(x)*log(x)",40,250); - bscaleCorr->SetParameters(5.23359e-01,1.15226e-01,-7.96949e-03); - - TH1F *hBdndpt = new TH1F("hBdndpt","hBdndpt",210,40,200); - TH1F *hBdndptNew = new TH1F("hBdndptNew","hBdndptNew",210,40,200); - //bscaleCorr->Draw(); - - - TRandom *trand=new TRandom(); - for(int i=0;iRndm()+40.; - double newpt = pt*bscaleCorr->Eval(pt); - hBdndpt->Fill(pt,dndpt->Eval(pt)); - hBdndptNew->Fill(newpt,dndpt->Eval(pt)); - } - - hBdndpt->Draw(); - hBdndptNew->SetLineColor(2); - hBdndptNew->Draw("same"); - - TCanvas *c2=new TCanvas("c2","c2",1); - TH1F *hratio = (TH1F*)hBdndpt->Clone("hratio"); - hratio->Divide(hBdndptNew); - hratio->Draw(); - - - cout<<" pp bins "<SetParameters(10.,-6.); - //hBdndpt->Fit(outfit,"R"); - -} +#include "TF1.h" +#include "TH1.h" +#include "TRandom.h" +#include "TCanvas.h" + +void deriveScaleCorr(long ntries=10000000, int cbin=0){ + + //cbin=-1 --> pp, cbin =0 --> 0-100%, cbin =1 --> 0-20%, cbin =2 --> 20-50%, cbin =3 --> 50-100% + + TF1 *dndpt = new TF1("dndpt","pow(x,-5.8)",40,250); + + + TF1 *bscaleCorr = new TF1("bscaleCorr","[0]+[1]*log(x)+[2]*log(x)*log(x)",40,250); + + //Kurt new parameters + //bscaleCorr->SetParameters(2.72415,-6.80458e-01, 6.39201e-02); + bscaleCorr->SetParameters(3.481,-0.9844,0.09367); + + //old + //bscaleCorr->SetParameters(5.23359e-01,1.15226e-01,-7.96949e-03); + //pp + //bscaleCorr->SetParameters(4.06636e-01,1.55713e-01,-1.14631e-02); + //PbPb 0-100% + //bscaleCorr->SetParameters(4.71366e-01,1.23344e-01,-8.27763e-03); + //PbPb 0-20% + //bscaleCorr->SetParameters(5.70469e-01,8.11248e-02,-3.87193e-03); + //PbPb 20-50% + //bscaleCorr->SetParameters(3.72120e-01,1.64570e-01,-1.24645e-02); + //PbPb 50-100% + //bscaleCorr->SetParameters(3.78601e-01,1.66229e-01,-1.29044e-02); + // PbPb 30-100% + //bscaleCorr->SetParameters(4.10748e-01,1.47307e-01,-1.04621e-02); + + TH1F *hBdndpt = new TH1F("hBdndpt","hBdndpt",210,40,200); + TH1F *hBdndptNew = new TH1F("hBdndptNew","hBdndptNew",210,40,200); + //bscaleCorr->Draw(); + + + double slope=0.; + /* + if(cbin==0)slope=0.00272238; + if(cbin==1)slope=0.00304461; + if(cbin==2)slope=0.00223193; + if(cbin==3)slope=0.00154643; + */ + + TRandom *trand=new TRandom(); + for(int i=0;iRndm()+40.; + double newpt = pt*bscaleCorr->Eval(pt); + hBdndpt->Fill(pt,dndpt->Eval(pt)*(slope*pt+100.)); + // y-int of 1 added so that normalization unchanged for slope=0 + hBdndptNew->Fill(newpt,dndpt->Eval(pt)*(slope*pt+100.)); + } + + hBdndpt->Draw(); + hBdndptNew->SetLineColor(2); + hBdndptNew->Draw("same"); + + TCanvas *c2=new TCanvas("c2","c2",1); + TH1F *hratio = (TH1F*)hBdndpt->Clone("hratio"); + hratio->Divide(hBdndptNew); + hratio->Draw(); + + + cout<<" pp bins "<SetParameters(10.,-6.); + //hBdndpt->Fit(outfit,"R"); + +} diff --git a/drawBJets.C b/drawBJets.C new file mode 100644 index 0000000..223c1de --- /dev/null +++ b/drawBJets.C @@ -0,0 +1,398 @@ + +#include +#include "TFile.h" +#include "TTree.h" +#include "TH1D.h" +#include "TCanvas.h" +#include "TLegend.h" + +using namespace std; + +void stackHistogram(TH1D **thist, int nHist){ + thist[0]->SetFillColor(6); + thist[0]->SetLineColor(6); + thist[1]->SetFillColor(2); + thist[1]->SetLineColor(2); + thist[2]->SetFillColor(3); + thist[2]->SetLineColor(3); + thist[3]->SetFillColor(8); + thist[3]->SetLineColor(8); + thist[4]->SetFillColor(4); + thist[4]->SetLineColor(4); + + for(int i=0; iSetMarkerStyle(1); + //thist[i]->Scale(1./thist[i]->Integral()); + } + for(int i=0; iAdd(thist[j]); + j++; + } + } +} + +void drawBJets(int leadjet=65, int subleadjet=30){ + + TFile *f1 = new TFile("histos/ppMC_ppReco_jetTrig_Dijet_noIPupperCut.root"); + TTree *nt = (TTree*)f1->Get("nt"); + TFile *f2 = new TFile("histos/ppdata_ppReco_jetTrig_Dijet_noIPupperCut.root"); + TTree *data = (TTree*)f2->Get("nt"); + + char* histoname = new char[40]; + // [0] = b-bbar, [1] = b+X, [2] = c-cbar, [3] = c+X, [4] = udsg jets, [5] = data + TH1D *X_all[6]; + TH1D *dphi_all[6]; + TH1D *X_leadB[6]; + TH1D *dphi_leadB[6]; + TH1D *X_subleadB[6]; + TH1D *dphi_subleadB[6]; + TH1D *X_doubleB[6]; + TH1D *dphi_doubleB[6]; + + for(int i=0; i<6; i++){ + sprintf(histoname,"%s%d","X_all_",i); + X_all[i] = new TH1D(histoname,"",10,0,1); + X_all[i]->Sumw2(); + sprintf(histoname,"%s%d","dphi_all_",i); + dphi_all[i] = new TH1D(histoname,"",30,0,3.14); + dphi_all[i]->Sumw2(); + sprintf(histoname,"%s%d","X_leadB_",i); + X_leadB[i] = new TH1D(histoname,"",10,0,1); + X_leadB[i]->Sumw2(); + sprintf(histoname,"%s%d","dphi_leadB_",i); + dphi_leadB[i] = new TH1D(histoname,"",30,0,3.14); + dphi_leadB[i]->Sumw2(); + sprintf(histoname,"%s%d","X_subleadB_",i); + X_subleadB[i] = new TH1D(histoname,"",10,0,1); + X_subleadB[i]->Sumw2(); + sprintf(histoname,"%s%d","dphi_subleadB_",i); + dphi_subleadB[i] = new TH1D(histoname,"",30,0,3.14); + dphi_subleadB[i]->Sumw2(); + sprintf(histoname,"%s%d","X_doubleB_",i); + X_doubleB[i] = new TH1D(histoname,"",10,0,1); + X_doubleB[i]->Sumw2(); + sprintf(histoname,"%s%d","dphi_doubleB_",i); + dphi_doubleB[i] = new TH1D(histoname,"",30,0,3.14); + dphi_doubleB[i]->Sumw2(); + } + + double jtpt1, jtpt2, jtphi1, jtphi2, refparton_flavorForB1, refparton_flavorForB2, discr_prob1, discr_prob2, weight; + double djtpt1, djtpt2, djtphi1, djtphi2, drefparton_flavorForB1, drefparton_flavorForB2, ddiscr_prob1, ddiscr_prob2; + + nt->SetBranchAddress("jtpt1",&jtpt1); + nt->SetBranchAddress("jtpt2",&jtpt2); + nt->SetBranchAddress("jtphi1",&jtphi1); + nt->SetBranchAddress("jtphi2",&jtphi2); + nt->SetBranchAddress("refparton_flavorForB1",&refparton_flavorForB1); + nt->SetBranchAddress("refparton_flavorForB2",&refparton_flavorForB2); + nt->SetBranchAddress("discr_prob1",&discr_prob1); + nt->SetBranchAddress("discr_prob2",&discr_prob2); + nt->SetBranchAddress("weight",&weight); + + data->SetBranchAddress("jtpt1",&djtpt1); + data->SetBranchAddress("jtpt2",&djtpt2); + data->SetBranchAddress("jtphi1",&djtphi1); + data->SetBranchAddress("jtphi2",&djtphi2); + data->SetBranchAddress("refparton_flavorForB1",&drefparton_flavorForB1); + data->SetBranchAddress("refparton_flavorForB2",&drefparton_flavorForB2); + data->SetBranchAddress("discr_prob1",&ddiscr_prob1); + data->SetBranchAddress("discr_prob2",&ddiscr_prob2); + + cout << "Starting data..." << endl; + for(int ientry=0; ientryGetEntries(); ientry++){ + data->GetEntry(ientry); + + //Logic tree for Data + if(djtpt1>leadjet && djtpt2>subleadjet){ + dphi_all[5]->Fill(acos(cos(djtphi1-djtphi2))); + if(acos(cos(djtphi1-djtphi2))>2.0944) X_all[5]->Fill(djtpt2/djtpt1); + + if(ddiscr_prob1 > 0.6){ + dphi_leadB[5]->Fill(acos(cos(djtphi1-djtphi2))); + if(acos(cos(djtphi1-djtphi2))>2.0944) X_leadB[5]->Fill(djtpt2/djtpt1); + } + if(ddiscr_prob2 > 0.6){ + dphi_subleadB[5]->Fill(acos(cos(djtphi1-djtphi2))); + if(acos(cos(djtphi1-djtphi2))>2.0944) X_subleadB[5]->Fill(djtpt2/djtpt1); + } + if(ddiscr_prob1 > 0.6 && ddiscr_prob2 > 0.6){ + dphi_doubleB[5]->Fill(acos(cos(djtphi1-djtphi2))); + if(acos(cos(djtphi1-djtphi2))>2.0944) X_doubleB[5]->Fill(djtpt2/djtpt1); + } + } + } + + cout << "Starting MC..." << endl; + for(int ientry=0; ientryGetEntries(); ientry++){ + nt->GetEntry(ientry); + + //Logic tree for All Jets + if(jtpt1>leadjet && jtpt2>subleadjet){ + if(fabs(refparton_flavorForB1)==5){ + if(fabs(refparton_flavorForB2)==5){ + dphi_all[0]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_all[0]->Fill(jtpt2/jtpt1, weight); + } + else{ + dphi_all[1]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_all[1]->Fill(jtpt2/jtpt1, weight); + } + } + else if(fabs(refparton_flavorForB1)==4){ + if(fabs(refparton_flavorForB2)==5){ + dphi_all[1]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_all[1]->Fill(jtpt2/jtpt1, weight); + } + else if(fabs(refparton_flavorForB2)==4){ + dphi_all[2]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_all[2]->Fill(jtpt2/jtpt1, weight); + } + else{ + dphi_all[3]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_all[3]->Fill(jtpt2/jtpt1, weight); + } + } + else{ + if(fabs(refparton_flavorForB1)==4){ + dphi_all[3]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_all[3]->Fill(jtpt2/jtpt1, weight); + } + else{ + dphi_all[4]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_all[4]->Fill(jtpt2/jtpt1, weight); + } + } + } + + //Logic tree for Leading B-tagged Jet + if(jtpt1>leadjet && jtpt2>subleadjet && discr_prob1 > 0.6){ + if(fabs(refparton_flavorForB1)==5){ + if(fabs(refparton_flavorForB2)==5){ + dphi_leadB[0]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_leadB[0]->Fill(jtpt2/jtpt1, weight); + } + else{ + dphi_leadB[1]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_leadB[1]->Fill(jtpt2/jtpt1, weight); + } + } + else if(fabs(refparton_flavorForB1)==4){ + if(fabs(refparton_flavorForB2)==5){ + dphi_leadB[1]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_leadB[1]->Fill(jtpt2/jtpt1, weight); + } + else if(fabs(refparton_flavorForB2)==4){ + dphi_leadB[2]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_leadB[2]->Fill(jtpt2/jtpt1, weight); + } + else{ + dphi_leadB[3]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_leadB[3]->Fill(jtpt2/jtpt1, weight); + } + } + else{ + if(fabs(refparton_flavorForB1)==4){ + dphi_leadB[3]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_leadB[3]->Fill(jtpt2/jtpt1, weight); + } + else{ + dphi_leadB[4]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_leadB[4]->Fill(jtpt2/jtpt1, weight); + } + } + } + + //Logic tree for Subleading B-tagged Jet + if(jtpt1>leadjet && jtpt2>subleadjet && discr_prob2 > 0.6){ + if(fabs(refparton_flavorForB1)==5){ + if(fabs(refparton_flavorForB2)==5){ + dphi_subleadB[0]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_subleadB[0]->Fill(jtpt2/jtpt1, weight); + } + else{ + dphi_subleadB[1]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_subleadB[1]->Fill(jtpt2/jtpt1, weight); + } + } + else if(fabs(refparton_flavorForB1)==4){ + if(fabs(refparton_flavorForB2)==5){ + dphi_subleadB[1]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_subleadB[1]->Fill(jtpt2/jtpt1, weight); + } + else if(fabs(refparton_flavorForB2)==4){ + dphi_subleadB[2]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_subleadB[2]->Fill(jtpt2/jtpt1, weight); + } + else{ + dphi_subleadB[3]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_subleadB[3]->Fill(jtpt2/jtpt1, weight); + } + } + else{ + if(fabs(refparton_flavorForB1)==4){ + dphi_subleadB[3]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_subleadB[3]->Fill(jtpt2/jtpt1, weight); + } + else{ + dphi_subleadB[4]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_subleadB[4]->Fill(jtpt2/jtpt1, weight); + } + } + } + + //Logic tree for Double B-tagged Jet + if(jtpt1>leadjet && jtpt2>subleadjet && discr_prob1 > 0.6 && discr_prob2 > 0.6){ + if(fabs(refparton_flavorForB1)==5){ + if(fabs(refparton_flavorForB2)==5){ + dphi_doubleB[0]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_doubleB[0]->Fill(jtpt2/jtpt1, weight); + } + else{ + dphi_doubleB[1]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_doubleB[1]->Fill(jtpt2/jtpt1, weight); + } + } + else if(fabs(refparton_flavorForB1)==4){ + if(fabs(refparton_flavorForB2)==5){ + dphi_doubleB[1]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_doubleB[1]->Fill(jtpt2/jtpt1, weight); + } + else if(fabs(refparton_flavorForB2)==4){ + dphi_doubleB[2]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_doubleB[2]->Fill(jtpt2/jtpt1, weight); + } + else{ + dphi_doubleB[3]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_doubleB[3]->Fill(jtpt2/jtpt1, weight); + } + } + else{ + if(fabs(refparton_flavorForB1)==4){ + dphi_doubleB[3]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_doubleB[3]->Fill(jtpt2/jtpt1, weight); + } + else{ + dphi_doubleB[4]->Fill(acos(cos(jtphi1-jtphi2)), weight); + if(acos(cos(jtphi1-jtphi2))>2.0944) X_doubleB[4]->Fill(jtpt2/jtpt1, weight); + } + } + } + } + + stackHistogram(X_all,5); + stackHistogram(dphi_all,5); + stackHistogram(X_leadB,5); + stackHistogram(dphi_leadB,5); + stackHistogram(X_subleadB,5); + stackHistogram(dphi_subleadB,5); + stackHistogram(X_doubleB,5); + stackHistogram(dphi_doubleB,5); + + for(int i=4; i>=0; i--){ + X_all[i]->Scale(1./X_all[0]->Integral()); + dphi_all[i]->Scale(1./dphi_all[0]->Integral()); + X_leadB[i]->Scale(1./X_leadB[0]->Integral()); + dphi_leadB[i]->Scale(1./dphi_leadB[0]->Integral()); + X_subleadB[i]->Scale(1./X_subleadB[0]->Integral()); + dphi_subleadB[i]->Scale(1./dphi_subleadB[0]->Integral()); + X_doubleB[i]->Scale(1./X_doubleB[0]->Integral()); + dphi_doubleB[i]->Scale(1./dphi_doubleB[0]->Integral()); + } + + X_all[5]->Scale(1./X_all[5]->Integral()); + dphi_all[5]->Scale(1./dphi_all[5]->Integral()); + X_leadB[5]->Scale(1./X_leadB[5]->Integral()); + dphi_leadB[5]->Scale(1./dphi_leadB[5]->Integral()); + X_subleadB[5]->Scale(1./X_subleadB[5]->Integral()); + dphi_subleadB[5]->Scale(1./dphi_subleadB[5]->Integral()); + X_doubleB[5]->Scale(1./X_doubleB[5]->Integral()); + dphi_doubleB[5]->Scale(1./dphi_doubleB[5]->Integral()); + + TLegend *leg = new TLegend(0.2, 0.5, 0.467, 0.9); + leg->SetFillColor(0); + leg->AddEntry(X_all[5], "Data"); + leg->AddEntry(X_all[0], "b-bbar"); + leg->AddEntry(X_all[1], "b(bbar)+X"); + leg->AddEntry(X_all[2], "c-cbar"); + leg->AddEntry(X_all[3], "c(cbar)+light"); + leg->AddEntry(X_all[4], "udsg jets"); + + TCanvas *c1 = new TCanvas("c1","",1200,600); + c1->Divide(2,1); + c1->cd(1); + X_all[0]->SetTitle("No B-Jet Cut"); + X_all[0]->SetXTitle("p_{T,2}/p_{T,1}"); + X_all[0]->Draw("h"); + for(int i=1; i<6; i++){ + X_all[i]->Draw("same,h"); + } + leg->Draw(); + + c1->cd(2); + gPad->SetLogy(); + dphi_all[0]->SetXTitle("#Delta#phi_{1,2}"); + dphi_all[0]->Draw("h"); + for(int i=1; i<6; i++){ + dphi_all[i]->Draw("same,h"); + } + + TCanvas *c2 = new TCanvas("c2","",1200,600); + c2->Divide(2,1); + c2->cd(1); + X_leadB[0]->SetTitle("Leading B-Jet"); + X_leadB[0]->SetXTitle("p_{T,2}/p_{T,1}"); + X_leadB[0]->Draw("h"); + for(int i=1; i<6; i++){ + X_leadB[i]->Draw("same,h"); + } + leg->Draw(); + + c2->cd(2); + gPad->SetLogy(); + dphi_leadB[0]->SetXTitle("#Delta#phi_{1,2}"); + dphi_leadB[0]->Draw("h"); + for(int i=1; i<6; i++){ + dphi_leadB[i]->Draw("same,h"); + } + + TCanvas *c3 = new TCanvas("c3","",1200,600); + c3->Divide(2,1); + c3->cd(1); + X_subleadB[0]->SetTitle("Subleading B-Jet"); + X_subleadB[0]->SetXTitle("p_{T,2}/p_{T,1}"); + X_subleadB[0]->Draw("h"); + for(int i=1; i<6; i++){ + X_subleadB[i]->Draw("same,h"); + } + leg->Draw(); + + c3->cd(2); + gPad->SetLogy(); + dphi_subleadB[0]->SetXTitle("#Delta#phi_{1,2}"); + dphi_subleadB[0]->Draw("h"); + for(int i=1; i<6; i++){ + dphi_subleadB[i]->Draw("same,h"); + } + + TCanvas *c4 = new TCanvas("c4","",1200,600); + c4->Divide(2,1); + c4->cd(1); + X_doubleB[0]->SetTitle("Double B-Jet"); + X_doubleB[0]->SetXTitle("p_{T,2}/p_{T,1}"); + X_doubleB[0]->Draw("h"); + for(int i=1; i<6; i++){ + X_doubleB[i]->Draw("same,h"); + } + leg->Draw(); + + c4->cd(2); + gPad->SetLogy(); + dphi_doubleB[0]->SetXTitle("#Delta#phi_{1,2}"); + dphi_doubleB[0]->Draw("h"); + for(int i=1; i<6; i++){ + dphi_doubleB[i]->Draw("same,h"); + } + +} diff --git a/drawBjetSpectrum.C b/drawBjetSpectrum.C new file mode 100644 index 0000000..9b1a3fc --- /dev/null +++ b/drawBjetSpectrum.C @@ -0,0 +1,76 @@ +void drawBjetSpectrum(int ppPbPb=1){ + + + gStyle->SetOptTitle(0); + + if(!ppPbPb) { + cout<<" find Kurt :-) "<Get("hRawBData"); + TH1F *hRawBData = (TH1F *)fin->Get("hIncJetsData"); + + // divide out the bin-width + for(int i=0;iGetNbinsX();i++){ + float val = hRawBData->GetBinContent(i+1); + float err = hRawBData->GetBinError(i+1); + float width = hRawBData->GetBinWidth(i+1); + hRawBData->SetBinContent(i+1,val/width); + hRawBData->SetBinError(i+1,err/width); + } + + TH1F *hBEfficiency = (TH1F *)fin->Get("hBEfficiencyMC"); + for(int i=0;iGetNbinsX();i++){ + float val = hRawBData->GetBinContent(i+1); + float err = hRawBData->GetBinError(i+1); + float eff = hBEfficiency->GetBinContent(i+1); + float effErr = hBEfficiency->GetBinError(i+1); + + //hRawBData->SetBinContent(i+1,val/eff); + //hRawBData->SetBinError(i+1, val/eff *sqrt(effErr*effErr/eff/eff + err*err/val/val)); + } + + + + + TCanvas *c1=new TCanvas("c1","c1",1); + c1->SetLogy(); + + hRawBData->SetMarkerStyle(8); + hRawBData->SetYTitle("dN/dp_{T} (GeV/c)^{-1}"); + hRawBData->Draw(); + + + TF1 *fpow = new TF1("fpow","[0]*pow(x,[1])",55,250); + + TH1F *hRawBDataOrig=hRawBData->Clone("hRawBDataOrig"); + + for(int iter=0;iter<4;iter++){ + + cout<<" iteration # "<Fit(fpow); + + for(int i=0;iGetNbinsX();i++){ + float meanVal = fpow->Integral(hRawBData->GetBinLowEdge(i+1),hRawBData->GetBinLowEdge(i+1)+hRawBData->GetBinWidth(i+1))/hRawBData->GetBinWidth(i+1); + float centVal = fpow->Eval(hRawBData->GetBinCenter(i+1)); + float binShiftCorr = centVal/meanVal; + cout<<" i "<GetBinContent(i+1); + float err = hRawBDataOrig->GetBinError(i+1); + + hRawBData->SetBinContent(i+1,val*binShiftCorr); + hRawBData->SetBinError(i+1,err*binShiftCorr); + + } + } + TFile *fout = new TFile("raa_inclJet_pPb_numberator.root","recreate"); + fout->cd(); + hRawBData->Scale(1./3.093E7); //scale by luminosity (5.3 pb^-1 (pp), 30.93 nb^-1 ) + hRawBData->Write(); + +} diff --git a/drawRAA.C b/drawRAA.C new file mode 100644 index 0000000..704379e --- /dev/null +++ b/drawRAA.C @@ -0,0 +1,31 @@ +{ + + TH1D *h = new TH1D(); + TH1D *h_den = new TH1D(); + h->Sumw2(); + h_den->Sumw2(); + + TFile *f1 = new TFile("raa_inclJet_pPb_numberator.root","OLD"); + f1->cd(); + //h = (TH1D*)(f1->Get("hRawBData")); + h = (TH1D*)(f1->Get("hIncJetsData")); + h->Scale(1E-4./0.096); //TpA from http://arxiv.org/pdf/nucl-ex/0302016v3.pdf + + TFile *f2 = new TFile("raa_inclJet_pp_denomForpA.root","OLD"); + f2->cd(); + //h_den = (TH1D*)(f2->Get("hRawBData")); + h_den = (TH1D*)(f2->Get("hIncJetsData")); + + h->Draw(); + h->SetTitle(""); + //h_den->SetMarkerColor(2); + //h_den->Draw("same"); + h->Divide(h_den); + h->SetMaximum(3); + h->SetMinimum(0); + h->SetStats(0); + h->SetYTitle("#frac{1}{} #frac{d#sigma_{pA}/dp_{T}}{d#sigma_{pp}/dp_{T}}"); + h->SetTitle("Inclusive Jet R_{pA}"); + h->Draw("p"); + +} diff --git a/evalTagEff.C b/evalTagEff.C new file mode 100644 index 0000000..1b638c9 --- /dev/null +++ b/evalTagEff.C @@ -0,0 +1,159 @@ +void evalTagEff(int RecOrGen=0, float discCut=0.6) +{ + + gStyle->SetOptStat(0); + gStyle->SetOptTitle(0); + + TFile *fB = new TFile("histos/ppMC_ppReco_ak3PF_BjetTrig_noIPupperCut_9-15.root"); + + TNtuple *ntB = (TNtuple *) fB->Get("nt"); + + TH1F *hPt1B=new TH1F("hPt1B","hPt1B",54,30.,300.); + TH1F *hPt1BTag=new TH1F("hPt1BTag","hPt1BTag",54,30.,300.); + TH1F *hPt2B=new TH1F("hPt2B","hPt2B",54,30.,300.); + TH1F *hPt2BTag=new TH1F("hPt2BTag","hPt2BTag",54,30.,300.); + TH1F *hPt3B=new TH1F("hPt3B","hPt3B",54,30.,300.); + TH1F *hPt3BTag=new TH1F("hPt3BTag","hPt3BTag",54,30.,300.); + + TH1F *hPt2SubB=new TH1F("hPt2SubB","hPt2SubB",54,30.,300.); + TH1F *hPt2SubBTag=new TH1F("hPt2SubBTag","hPt2SubBTag",54,30.,300.); + + TH1F *hPt1IncB=new TH1F("hPt1IncB","hPt1IncB",54,30.,300.); + TH1F *hPt1IncBTag=new TH1F("hPt1IncBTag","hPt1IncBTag",54,30.,300.); + TH1F *hPt2IncB=new TH1F("hPt2IncB","hPt2IncB",54,30.,300.); + TH1F *hPt2IncBTag=new TH1F("hPt2IncBTag","hPt2IncBTag",54,30.,300.); + TH1F *hPt3IncB=new TH1F("hPt3IncB","hPt3IncB",54,30.,300.); + TH1F *hPt3IncBTag=new TH1F("hPt3IncBTag","hPt3IncBTag",54,30.,300.); + + hPt1B->Sumw2(); + hPt2B->Sumw2(); + hPt3B->Sumw2(); + hPt2SubB->Sumw2(); + hPt1IncB->Sumw2(); + hPt2IncB->Sumw2(); + hPt3IncB->Sumw2(); + + hPt1BTag->Sumw2(); + hPt2BTag->Sumw2(); + hPt3BTag->Sumw2(); + hPt2SubBTag->Sumw2(); + hPt1IncBTag->Sumw2(); + hPt2IncBTag->Sumw2(); + hPt3IncBTag->Sumw2(); + + if(RecOrGen){ + ntB->Draw("refpt1>>hPt1B","weight*(jtpt1>80&&abs(refparton_flavorForB1)==5)"); + ntB->Draw("refpt1>>hPt1BTag",Form("weight*(jtpt1>80&&abs(refparton_flavorForB1)==5&&discr_prob1>=%f)",discCut)); + ntB->Draw("refpt2>>hPt2B","weight*(jtpt1>80&&abs(refparton_flavorForB2)==5)"); + ntB->Draw("refpt2>>hPt2BTag",Form("weight*(jtpt1>80&&abs(refparton_flavorForB2)==5&&discr_prob2>=%f)",discCut)); + ntB->Draw("refpt3>>hPt3B","weight*(jtpt1>80&&abs(refparton_flavorForB3)==5)"); + ntB->Draw("refpt3>>hPt3BTag",Form("weight*(jtpt1>80&&abs(refparton_flavorForB3)==5&&discr_prob3>=%f)",discCut)); + ntB->Draw("refpt2>>hPt2SubB","weight*(abs(refparton_flavorForB2)==5&&jtpt1>80&&jtpt2>30&&acos(cos(jtphi1-jtphi2))>2./3.*acos(-1.))"); + ntB->Draw("refpt2>>hPt2SubBTag",Form("weight*(abs(refparton_flavorForB2)==5&&jtpt1>80&&jtpt2>30&&acos(cos(jtphi1-jtphi2))>2./3.*acos(-1.)&&discr_prob2>=%f)",discCut)); + + ntB->Draw("refpt1>>hPt1IncB","weight*(abs(refparton_flavorForB1)==5)"); + ntB->Draw("refpt1>>hPt1IncBTag",Form("weight*(abs(refparton_flavorForB1)==5&&discr_prob1>=%f)",discCut)); + ntB->Draw("refpt2>>hPt2IncB","weight*(abs(refparton_flavorForB2)==5)"); + ntB->Draw("refpt2>>hPt2IncBTag",Form("weight*(abs(refparton_flavorForB2)==5&&discr_prob2>=%f)",discCut)); + ntB->Draw("refpt3>>hPt3IncB","weight*(abs(refparton_flavorForB3)==5)"); + ntB->Draw("refpt3>>hPt3IncBTag",Form("weight*(abs(refparton_flavorForB3)==5&&discr_prob3>=%f)",discCut)); + + } + else{ + ntB->Draw("jtpt1>>hPt1B","weight*(jtpt1>80&&abs(refparton_flavorForB1)==5)"); + ntB->Draw("jtpt1>>hPt1BTag",Form("weight*(jtpt1>80&&abs(refparton_flavorForB1)==5&&discr_prob1>=%f)",discCut)); + ntB->Draw("jtpt2>>hPt2B","weight*(jtpt1>80&&abs(refparton_flavorForB2)==5)"); + ntB->Draw("jtpt2>>hPt2BTag",Form("weight*(jtpt1>80&&abs(refparton_flavorForB2)==5&&discr_prob2>=%f)",discCut)); + ntB->Draw("jtpt3>>hPt3B","weight*(jtpt1>80&&abs(refparton_flavorForB3)==5)"); + ntB->Draw("jtpt3>>hPt3BTag",Form("weight*(jtpt1>80&&abs(refparton_flavorForB3)==5&&discr_prob3>=%f)",discCut)); + ntB->Draw("jtpt2>>hPt2SubB","weight*(jtpt1>80&&abs(refparton_flavorForB2)==5&&jtpt1>80&&jtpt2>30&&acos(cos(jtphi1-jtphi2))>2./3.*acos(-1.))"); + ntB->Draw("jtpt2>>hPt2SubBTag",Form("weight*(jtpt1>80&&abs(refparton_flavorForB2)==5&&jtpt1>80&&jtpt2>30&&acos(cos(jtphi1-jtphi2))>2./3.*acos(-1.)&&discr_prob2>=%f)",discCut)); + + ntB->Draw("jtpt1>>hPt1IncB","weight*(abs(refparton_flavorForB1)==5)"); + ntB->Draw("jtpt1>>hPt1IncBTag",Form("weight*(abs(refparton_flavorForB1)==5&&discr_prob1>=%f)",discCut)); + ntB->Draw("jtpt2>>hPt2IncB","weight*(abs(refparton_flavorForB2)==5)"); + ntB->Draw("jtpt2>>hPt2IncBTag",Form("weight*(abs(refparton_flavorForB2)==5&&discr_prob2>=%f)",discCut)); + ntB->Draw("jtpt3>>hPt3IncB","weight*(abs(refparton_flavorForB3)==5)"); + ntB->Draw("jtpt3>>hPt3IncBTag",Form("weight*(abs(refparton_flavorForB3)==5&&discr_prob3>=%f)",discCut)); + + } + TH1F *hNum=(TH1F*)hPt1BTag->Clone("hNum"); + hNum->Add(hPt2BTag); + hNum->Add(hPt3BTag); + + TH1F *hDen=(TH1F*)hPt1B->Clone("hDen"); + hDen->Add(hPt2B); + hDen->Add(hPt3B); + + + + TCanvas *c1=new TCanvas("c1","c1",600,600); + + TH1F *hEff = (TH1F*)hNum->Clone("hEff"); + hEff->Reset(); + hEff->Divide(hNum,hDen,1,1,"B"); + hEff->SetMinimum(0.); + hEff->SetMarkerStyle(8); + if(RecOrGen)hEff->SetXTitle("Gen jet p_{T} (GeV/c)"); + else hEff->SetXTitle("Reco jet p_{T} (GeV/c)"); + hEff->SetYTitle("Efficiency"); + hEff->Draw(); + + + + + //TF1 *fitf = new TF1("fitf","[0]+[1]*log(x*[2])+[3]*log(x*[4])*log(x*[4])",30,300); + //fitf->SetParameters(0.005,0.1,0.5,0.1,0.5); + if(!RecOrGen){ + TF1 *fitf = new TF1("fitf","[0]+[1]*pow(log(x*[2]),2)",30,300); + fitf->SetParameters(1.,0.1,0.008); + fitf->SetLineColor(1); + hEff->Fit(fitf,"","",30,300); + } + + TH1F *hNumInc=(TH1F*)hPt1IncBTag->Clone("hNumInc"); + hNumInc->Add(hPt2IncBTag); + hNumInc->Add(hPt3IncBTag); + + TH1F *hDenInc=(TH1F*)hPt1IncB->Clone("hDenInc"); + hDenInc->Add(hPt2IncB); + hDenInc->Add(hPt3IncB); + + TH1F *hEffInc = (TH1F*)hNumInc->Clone("hEffInc"); + hEffInc->Reset(); + hEffInc->Divide(hNumInc,hDenInc,1,1,"B"); + hEffInc->SetMinimum(0.); + hEffInc->SetMarkerStyle(4); + hEffInc->SetMarkerColor(kGreen-2); + hEffInc->SetLineColor(kGreen-2); + hEffInc->Draw("same"); + + if(!RecOrGen){ + TF1 *fitf2 = new TF1("fitf2","[0]+[1]*pow(log(x*[2]),2)",30,300); + fitf2->SetParameters(1.,0.1,0.1); + hEffInc->Fit(fitf2,"N","",30,300); + fitf2->SetLineWidth(2); + fitf2->SetLineColor(kGreen-2); + fitf2->Draw("same"); + } + + + TH1F *hNumSub=(TH1F*)hPt2SubBTag->Clone("hNumSub"); + TH1F *hDenSub=(TH1F*)hPt2SubB->Clone("hDenSub"); + + TH1F *hEffSub = (TH1F*)hNumSub->Clone("hEffSub"); + hEffSub->Reset(); + hEffSub->Divide(hNumSub,hDenSub,1,1,"B"); + hEffSub->SetLineColor(2); + hEffSub->SetMarkerColor(2); + hEffSub->SetMarkerStyle(4); + hEffSub->Draw("same"); + + TLegend *leg=new TLegend(0.3,0.3,0.6,0.5); + leg->SetBorderSize(0); + leg->SetFillStyle(0); + leg->AddEntry(hEff,"Jet(40||60||80) && p_{T,1}>80 GeV/c","p"); + leg->AddEntry(hEffSub,"+ Sub-leading","p"); + leg->AddEntry(hEffInc,"Inclusive","p"); + leg->Draw(); +} diff --git a/fitBjetJES.C b/fitBjetJES.C index 5d0e240..b6b4bd2 100644 --- a/fitBjetJES.C +++ b/fitBjetJES.C @@ -20,11 +20,11 @@ void fitBjetJES(int ppPbPb=1, int cbinlo=12, int cbinhi=40){ TFile *fL; if(!ppPbPb)fL=new TFile("histos/ppMC_hiReco_jetTrig_highPurity_JEC.root"); - else fL=new TFile("histos/PbPbQCDMC_JEC.root"); + else fL=new TFile("histos/PbPbQCDMC_pt30by3_ipHICalibCentWeight.root"); // these are dummy files for pp - TFile *fB=new TFile("histos/PbPbBMC_JEC.root"); - TFile *fC=new TFile("histos/PbPbCMC_JEC.root"); + TFile *fB=new TFile("histos/PbPbBMC_pt30by3_ipHICalibCentWeight.root"); + TFile *fC=new TFile("histos/PbPbCMC_pt30by3_ipHICalibCentWeight.root"); TNtuple *tL = (TNtuple*) fL->Get("nt"); diff --git a/plotBDijets.C b/plotBDijets.C new file mode 100644 index 0000000..941bbb5 --- /dev/null +++ b/plotBDijets.C @@ -0,0 +1,257 @@ +#include +#include "TTree.h" +#include "TH1D.h" +#include "TFile.h" +#include "TCanvas.h" +#include "TLegend.h" + +const double PI=3.14159265; + +void setAllColor(TH1D *input, int color){ + input->SetFillColor(color); + input->SetLineColor(color); + input->SetMarkerColor(color); +} + +void stackHistogram(TH1D **input){ + + double intg = 0; + for(int i=0; i<5; i++){ + for(int j=i+1; j<5; j++){ + input[i]->Add(input[j]); + } + if(i==0) intg = input[0]->Integral(); + input[i]->Scale(1./intg); + } + setAllColor(input[0], 6); + setAllColor(input[1], 2); + setAllColor(input[2], 3); + setAllColor(input[3], 8); + setAllColor(input[4], 4); +} + + +void plotBDijets(){ + + TFile *fdata = new TFile("histos/ppdata_ppReco_Dijet_jetTrig.root"); + TFile *fQCD = new TFile("histos/ppMC_ppReco_Dijet_QCDjetTrig.root"); + TFile *fB = new TFile("histos/ppMC_ppReco_Dijet_BjetTrig.root"); + + // 1st D = ptRatio, dphi; 2nd D = B+B, B+C, B+L, C+L, L+L + TH1D *QCDjetData[2]; + TH1D *BjetData[2]; + TH1D *QCDjetMC[2][5]; + TH1D *BjetMC[2][5]; + QCDjetData[0] = new TH1D("QCDjetData_0","",10,0,1); QCDjetData[0]->Sumw2(); + QCDjetData[1] = new TH1D("QCDjetData_1","",30,0,PI); QCDjetData[1]->Sumw2(); + BjetData[0] = new TH1D("BjetData_0","",10,0,1); BjetData[0]->Sumw2(); + BjetData[1] = new TH1D("BjetData_1","",30,0,PI); BjetData[1]->Sumw2(); + char* histoname = new char[100]; + for(int i=0; i<5; i++){ + sprintf(histoname,"%s%d","QCDjetMC_0_",i); + QCDjetMC[0][i] = new TH1D(histoname,"",10,0,1); + QCDjetMC[0][i]->Sumw2(); + sprintf(histoname,"%s%d","QCDjetMC_1_",i); + QCDjetMC[1][i] = new TH1D(histoname,"",30,0,PI); + QCDjetMC[1][i]->Sumw2(); + sprintf(histoname,"%s%d","BjetMC_0_",i); + BjetMC[0][i] = new TH1D(histoname,"",10,0,1); + BjetMC[0][i]->Sumw2(); + sprintf(histoname,"%s%d","BjetMC_1_",i); + BjetMC[1][i] = new TH1D(histoname,"",30,0,PI); + BjetMC[1][i]->Sumw2(); + } + + TTree *dnt = (TTree*)fdata->Get("nt"); + TTree *QCDnt = (TTree*)fQCD->Get("nt"); + TTree *Bnt = (TTree*)fB->Get("nt"); + + //**********************************************************// + + dnt->Draw("(jtpt1-jtpt2)/(jtpt1+jtpt2)>>QCDjetData_0","(jtpt1>80 && jtpt2>40 && pVertexFilterCutGplusUpsPP)"); + dnt->Draw("acos(cos(jtphi1-jtphi2))>>QCDjetData_1","(jtpt1>80 && jtpt2>40 && pVertexFilterCutGplusUpsPP)"); + dnt->Draw("(jtpt1-jtpt2)/(jtpt1+jtpt2)>>BjetData_0","(jtpt1>80 && jtpt2>40 && pVertexFilterCutGplusUpsPP && (discr_ssvHighEff1>2 && discr_ssvHighEff2>2))"); + dnt->Draw("acos(cos(jtphi1-jtphi2))>>BjetData_1","(jtpt1>80 && jtpt2>40 && pVertexFilterCutGplusUpsPP && (discr_ssvHighEff1>2 && discr_ssvHighEff2>2))"); + + std::cout << "Finished Data" << std::endl; + + //**********************************************************// + double jtpt1, jtpt2, jtphi1, jtphi2, refpt1, refpt2, refparton_flavorForB1, refparton_flavorForB2, weight; + int pVertexFilterCutGplusUpsPP; + QCDnt->SetBranchAddress("jtpt1",&jtpt1); + QCDnt->SetBranchAddress("jtpt2",&jtpt2); + QCDnt->SetBranchAddress("refpt1",&refpt1); + QCDnt->SetBranchAddress("refpt2",&refpt2); + QCDnt->SetBranchAddress("jtphi1",&jtphi1); + QCDnt->SetBranchAddress("jtphi2",&jtphi2); + QCDnt->SetBranchAddress("pVertexFilterCutGplusUpsPP",&pVertexFilterCutGplusUpsPP); + QCDnt->SetBranchAddress("refparton_flavorForB1",&refparton_flavorForB1); + QCDnt->SetBranchAddress("refparton_flavorForB2",&refparton_flavorForB2); + QCDnt->SetBranchAddress("weight",&weight); + + for(int ie=0; ieGetEntries(); ie++){ + QCDnt->GetEntry(ie); + + if(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP){ + if(fabs(refparton_flavorForB1)==5 && fabs(refparton_flavorForB2)==5){ + QCDjetMC[0][0]->Fill((jtpt1-jtpt2)/(jtpt1+jtpt2), weight); + QCDjetMC[1][0]->Fill(acos(cos(jtphi1-jtphi2)), weight); + } + else if(fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5){ + QCDjetMC[0][1]->Fill((jtpt1-jtpt2)/(jtpt1+jtpt2), weight); + QCDjetMC[1][1]->Fill(acos(cos(jtphi1-jtphi2)), weight); + } + else if(fabs(refparton_flavorForB1)==4 && fabs(refparton_flavorForB2)==4){ + QCDjetMC[0][2]->Fill((jtpt1-jtpt2)/(jtpt1+jtpt2), weight); + QCDjetMC[1][2]->Fill(acos(cos(jtphi1-jtphi2)), weight); + } + else if(fabs(refparton_flavorForB1)==4 || fabs(refparton_flavorForB2)==4){ + QCDjetMC[0][3]->Fill((jtpt1-jtpt2)/(jtpt1+jtpt2), weight); + QCDjetMC[1][3]->Fill(acos(cos(jtphi1-jtphi2)), weight); + } + else{ + QCDjetMC[0][4]->Fill((jtpt1-jtpt2)/(jtpt1+jtpt2), weight); + QCDjetMC[1][4]->Fill(acos(cos(jtphi1-jtphi2)), weight); + } + } + } + /*QCDnt->Draw("(jtpt1-jtpt2)/(jtpt1+jtpt2)>>QCDjetMC_0_0","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && fabs(refparton_flavorForB1)==5 && fabs(refparton_flavorForB2)==5)"); + QCDnt->Draw("(jtpt1-jtpt2)/(jtpt1+jtpt2)>>QCDjetMC_0_1","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && (fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5) && !(fabs(refparton_flavorForB1)==5 && fabs(refparton_flavorForB2)==5))"); + QCDnt->Draw("(jtpt1-jtpt2)/(jtpt1+jtpt2)>>QCDjetMC_0_2","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && fabs(refparton_flavorForB1)==4 && fabs(refparton_flavorForB2)==4)"); + QCDnt->Draw("(jtpt1-jtpt2)/(jtpt1+jtpt2)>>QCDjetMC_0_3","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && (fabs(refparton_flavorForB1)==4 || fabs(refparton_flavorForB2)==4) && !(fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5) && !(fabs(refparton_flavorForB1)==4 && fabs(refparton_flavorForB2)==4))"); + QCDnt->Draw("(jtpt1-jtpt2)/(jtpt1+jtpt2)>>QCDjetMC_0_4","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && !(fabs(refparton_flavorForB1)==4 || fabs(refparton_flavorForB2)==4) && !(fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5))"); + + QCDnt->Draw("acos(cos(jtphi1-jtphi2))>>QCDjetMC_1_0","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && fabs(refparton_flavorForB1)==5 && fabs(refparton_flavorForB2)==5)"); + QCDnt->Draw("acos(cos(jtphi1-jtphi2))>>QCDjetMC_1_1","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && (fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5) && !(fabs(refparton_flavorForB1)==5 && fabs(refparton_flavorForB2)==5))"); + QCDnt->Draw("acos(cos(jtphi1-jtphi2))>>QCDjetMC_1_2","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && fabs(refparton_flavorForB1)==4 && fabs(refparton_flavorForB2)==4)"); + QCDnt->Draw("acos(cos(jtphi1-jtphi2))>>QCDjetMC_1_3","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && (fabs(refparton_flavorForB1)==4 || fabs(refparton_flavorForB2)==4) && !(fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5) && && !(fabs(refparton_flavorForB1)==4 && fabs(refparton_flavorForB2)==4))"); + QCDnt->Draw("acos(cos(jtphi1-jtphi2))>>QCDjetMC_1_4","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && !(fabs(refparton_flavorForB1)==4 || fabs(refparton_flavorForB2)==4) && !(fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5))"); + */ + std::cout << "Finished QCD MC" << std::endl; + + //**********************************************************// + + double refparton_flavorForB3, discr_ssvHighEff1, discr_ssvHighEff2; + Bnt->SetBranchAddress("jtpt1",&jtpt1); + Bnt->SetBranchAddress("jtpt2",&jtpt2); + Bnt->SetBranchAddress("refpt1",&refpt1); + Bnt->SetBranchAddress("refpt2",&refpt2); + Bnt->SetBranchAddress("jtphi1",&jtphi1); + Bnt->SetBranchAddress("jtphi2",&jtphi2); + Bnt->SetBranchAddress("pVertexFilterCutGplusUpsPP",&pVertexFilterCutGplusUpsPP); + Bnt->SetBranchAddress("refparton_flavorForB1",&refparton_flavorForB1); + Bnt->SetBranchAddress("refparton_flavorForB2",&refparton_flavorForB2); + Bnt->SetBranchAddress("refparton_flavorForB3",&refparton_flavorForB3); + Bnt->SetBranchAddress("weight",&weight); + Bnt->SetBranchAddress("discr_ssvHighEff1",&discr_ssvHighEff1); + Bnt->SetBranchAddress("discr_ssvHighEff2",&discr_ssvHighEff2); + + for(int ie=0; ieGetEntries(); ie++){ + Bnt->GetEntry(ie); + + if(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && discr_ssvHighEff1>2 && discr_ssvHighEff2>2){ + if(fabs(refparton_flavorForB1)==5 && fabs(refparton_flavorForB2)==5){ + BjetMC[0][0]->Fill((jtpt1-jtpt2)/(jtpt1+jtpt2), weight); + BjetMC[1][0]->Fill(acos(cos(jtphi1-jtphi2)), weight); + } + else if(fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5){ + BjetMC[0][1]->Fill((jtpt1-jtpt2)/(jtpt1+jtpt2), weight); + BjetMC[1][1]->Fill(acos(cos(jtphi1-jtphi2)), weight); + } + else if(fabs(refparton_flavorForB1)==4 && fabs(refparton_flavorForB2)==4){ + BjetMC[0][2]->Fill((jtpt1-jtpt2)/(jtpt1+jtpt2), weight); + BjetMC[1][2]->Fill(acos(cos(jtphi1-jtphi2)), weight); + } + else if(fabs(refparton_flavorForB1)==4 || fabs(refparton_flavorForB2)==4){ + BjetMC[0][3]->Fill((jtpt1-jtpt2)/(jtpt1+jtpt2), weight); + BjetMC[1][3]->Fill(acos(cos(jtphi1-jtphi2)), weight); + } + else{ + BjetMC[0][4]->Fill((jtpt1-jtpt2)/(jtpt1+jtpt2), weight); + BjetMC[1][4]->Fill(acos(cos(jtphi1-jtphi2)), weight); + } + } + } + /* + Bnt->Draw("(jtpt1-jtpt2)/(jtpt1+jtpt2)>>BjetMC_0_0","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && fabs(refparton_flavorForB1)==5 && fabs(refparton_flavorForB2)==5)"); + Bnt->Draw("(jtpt1-jtpt2)/(jtpt1+jtpt2)>>BjetMC_0_1","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && (fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5) && !(fabs(refparton_flavorForB1)==5 && fabs(refparton_flavorForB2)==5))"); + Bnt->Draw("(jtpt1-jtpt2)/(jtpt1+jtpt2)>>BjetMC_0_2","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && fabs(refparton_flavorForB1)==4 && fabs(refparton_flavorForB2)==4)"); + Bnt->Draw("(jtpt1-jtpt2)/(jtpt1+jtpt2)>>BjetMC_0_3","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && (fabs(refparton_flavorForB1)==4 || fabs(refparton_flavorForB2)==4) && !(fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5) && !(fabs(refparton_flavorForB1)==4 && fabs(refparton_flavorForB2)==4))"); + Bnt->Draw("(jtpt1-jtpt2)/(jtpt1+jtpt2)>>BjetMC_0_4","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && !(fabs(refparton_flavorForB1)==4 || fabs(refparton_flavorForB2)==4) && !(fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5))"); + + Bnt->Draw("acos(cos(jtphi1-jtphi2))>>BjetMC_1_0","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && fabs(refparton_flavorForB1)==5 && fabs(refparton_flavorForB2)==5)"); + Bnt->Draw("acos(cos(jtphi1-jtphi2))>>BjetMC_1_1","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && (fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5) && !(fabs(refparton_flavorForB1)==5 && fabs(refparton_flavorForB2)==5))"); + Bnt->Draw("acos(cos(jtphi1-jtphi2))>>BjetMC_1_2","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && fabs(refparton_flavorForB1)==4 && fabs(refparton_flavorForB2)==4)"); + Bnt->Draw("acos(cos(jtphi1-jtphi2))>>BjetMC_1_3","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && (fabs(refparton_flavorForB1)==4 || fabs(refparton_flavorForB2)==4) && !(fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5) && !(fabs(refparton_flavorForB1)==4 && fabs(refparton_flavorForB2)==4))"); + Bnt->Draw("acos(cos(jtphi1-jtphi2))>>BjetMC_1_4","weight*(jtpt1>80 && jtpt2>40 && refpt1>30 && refpt2>25 && pVertexFilterCutGplusUpsPP && !(fabs(refparton_flavorForB1)==4 || fabs(refparton_flavorForB2)==4) && !(fabs(refparton_flavorForB1)==5 || fabs(refparton_flavorForB2)==5))"); + */ + std::cout << "Finished BJet MC" << std::endl; + + stackHistogram(BjetMC[0]); + stackHistogram(BjetMC[1]); + stackHistogram(QCDjetMC[0]); + stackHistogram(QCDjetMC[1]); + + TCanvas *c10 = new TCanvas("c10","",1000,500); + c10->SetTitle("Inclusive Jets"); + c10->Divide(2,1); + c10->cd(1); + QCDjetMC[0][0]->SetXTitle("A_{J}"); + QCDjetMC[0][0]->SetYTitle("evt. norm"); + for(int i=0; i<5; i++){ + if(i==0) QCDjetMC[0][0]->Draw("h"); + else QCDjetMC[0][i]->Draw("same,h"); + } + QCDjetData[0]->Scale(1./QCDjetData[0]->Integral()); + QCDjetData[0]->Draw("same"); + TLegend *l1 = new TLegend(0.6,0.6,0.91,0.95); + l1->AddEntry(QCDjetData[0],"pp Data"); + l1->AddEntry(QCDjetMC[0][0], "B+B"); + l1->AddEntry(QCDjetMC[0][1], "B+(C or L)"); + l1->AddEntry(QCDjetMC[0][2], "C+C"); + l1->AddEntry(QCDjetMC[0][3], "C+L"); + l1->AddEntry(QCDjetMC[0][4], "L+L"); + l1->Draw(); + + c10->cd(2); + QCDjetMC[1][0]->SetXTitle("#Delta#phi"); + QCDjetMC[1][0]->SetYTitle("evt. norm"); + for(int i=0; i<5; i++){ + if(i==0) QCDjetMC[1][0]->Draw("h"); + else QCDjetMC[1][i]->Draw("same,h"); + } + QCDjetData[1]->Scale(1./QCDjetData[1]->Integral()); + QCDjetData[1]->Draw("same"); + + TCanvas *c11 = new TCanvas("c11","",1000,500); + c11->SetTitle("B-Tagged Jets"); + c11->Divide(2,1); + c11->cd(1); + BjetMC[0][0]->SetXTitle("A_{J}"); + BjetMC[0][0]->SetYTitle("evt. norm"); + for(int i=0; i<5; i++){ + if(i==0) BjetMC[0][0]->Draw("h"); + else BjetMC[0][i]->Draw("same,h"); + } + BjetData[0]->Scale(1./BjetData[0]->Integral()); + BjetData[0]->Draw("same"); + TLegend *l2 = new TLegend(0.6,0.6,0.91,0.95); + l2->AddEntry(BjetData[0],"pp Data"); + l2->AddEntry(BjetMC[0][0], "B+B"); + l2->AddEntry(BjetMC[0][1], "B+(C or L)"); + l2->AddEntry(BjetMC[0][2], "C+C"); + l2->AddEntry(BjetMC[0][3], "C+L"); + l2->AddEntry(BjetMC[0][4], "L+L"); + l2->Draw(); + + c11->cd(2); + BjetMC[1][0]->SetXTitle("#Delta#phi"); + BjetMC[1][0]->SetYTitle("evt. norm"); + for(int i=0; i<5; i++){ + if(i==0) BjetMC[1][0]->Draw("h"); + else BjetMC[1][i]->Draw("same,h"); + } + BjetData[1]->Scale(1./BjetData[1]->Integral()); + BjetData[1]->Draw("same"); + +} diff --git a/plotDijetAsymm.C b/plotDijetAsymm.C new file mode 100644 index 0000000..1778dea --- /dev/null +++ b/plotDijetAsymm.C @@ -0,0 +1,369 @@ +#include +#include "TFile.h" +#include "TH1.h" +#include "TNtuple.h" +#include "TLegend.h" +#include "TStyle.h" +#include "TROOT.h" +#include "TPad.h" +#include "TPaveStats.h" +#include "TCanvas.h" +#include "TString.h" + +void plotDijetAsymm(int pt1norm=1, string disc = "discr_prob", float discCut1=0.6, float discCut2=0.6, int applyEffCorr=1, int drawStats=1, int plotPtRatio=0, int doSub=1, bool ppB=1){ + + int tagLead = 0; + int tagSub = 0; + + if(discCut1>0.0) tagLead=1; + if(discCut2>0.0) tagSub=1; + + cout<<"cutting on "< "<Reset(); + gStyle->SetOptTitle(0); + if(drawStats) gStyle->SetOptStat(1002210); + else gStyle->SetOptTitle(0); + gStyle->SetNdivisions(505,"x"); + //gROOT->ForceStyle(1); + + TFile *fB = new TFile("histos/ppMC_ppReco_Dijet_BjetTrig.root"); + TFile *fC = new TFile("histos/ppMC_ppReco_Dijet_CjetTrig.root"); + TFile *fQCD = new TFile("histos/ppMC_ppReco_Dijet_QCDjetTrig.root"); + TFile *fdata = new TFile("histos/ppdata_ppReco_Dijet_jetTrig.root"); + + TNtuple *ntB = (TNtuple *) fB->Get("nt"); + TNtuple *ntC = (TNtuple *) fC->Get("nt"); + TNtuple *ntQCD = (TNtuple *) fQCD->Get("nt"); + TNtuple *ntdata = (TNtuple *) fdata->Get("nt"); + + TH1F *hPt1B=new TH1F("hPt1B","hPt1B",120,65.,200.); + TH1F *hPt1C=new TH1F("hPt1C","hPt1C",120,65.,200.); + TH1F *hPt1QCD=new TH1F("hPt1QCD","hPt1QCD",120,65.,200.); + TH1F *hPt1Data=new TH1F("hPt1Data","hPt1Data",120,65.,200.); + + + + float a, b, c; + float d, e, f; + if(disc=="ssvHE"){ + a = 4.67356e-01; + b = -9.90006e-02; + c = 9.44735e-03; + } + else if(disc=="jetProb"){ + a = 4.82642e-01; + b = -2.29807e-01; + c = 7.32250e-03; + // test inclusive corrections + d = 4.42378e-01; + e = -1.06758e-01; + f = 7.02023e-03; + } + else if(ppB){ + a = 6.66338e-01; + b = -1.37254e-01; + c = 7.96509e-03; + d = 6.67839e-01; + e = -1.20443e-01; + f = 8.42849e-03; + } + else cout<<" no disc "<Draw(Form("%s>>hPt1B",pt1Choice),Form("weight/(%s)*(pthat>50&&%s>70&&%s<200&&abs(refparton_flavorForB1)==5&&%s1>=%f&&refpt1>0)",effCorr1,pt1Choice,pt1Choice,disc.c_str(),discCut1)); + ntC->Draw(Form("%s>>hPt1C",pt1Choice),Form("weight/(%s)*(pthat>50&&%s>70&&%s<200&&abs(refparton_flavorForB1)==4&&%s1>=%f&&refpt1>0)",effCorr1,pt1Choice,pt1Choice,disc.c_str(),discCut1)); + ntQCD->Draw(Form("%s>>hPt1QCD",pt1Choice),Form("weight/(%s)*(pthat>50&&%s>70&&%s<200&&abs(refparton_flavorForB1)!=5&&abs(refparton_flavorForB1)!=4&&%s1>=%f&&refpt1>0)",effCorr1,pt1Choice,pt1Choice,disc.c_str(),discCut1)); + //ntdata->Draw(Form("%s>>hPt1Data",pt1Choice),Form("1./(%s)*(pthat>50&&%s>70&&%s<200&&%s1>=%f)",effCorr1,pt1Choice,pt1Choice,disc.c_str(),discCut1)); + ntdata->Draw(Form("%s>>hPt1Data",pt1Choice),Form("weight/(%s)*(%s>70&&%s<200&&%s1>=%f)",effCorr1,pt1Choice,pt1Choice,disc.c_str(),discCut1)); + } + + TH1F *hPt1MC = (TH1F*)hPt1B->Clone("hPt1MC"); + hPt1MC->Add(hPt1C); + hPt1MC->Add(hPt1QCD); + + + + cout<Sumw2(); + + TH1F *hBgBBar=new TH1F("hBgBBar","hBgBBar",10,0,1); + TH1F *hBgBX=new TH1F("hBgBX","hBgBX",10,0,1); + TH1F *hBgCCbar=new TH1F("hBgCCbar","hBgCCbar",10,0,1); + TH1F *hBgCX=new TH1F("hBgCX","hBgCX",10,0,1); + TH1F *hBgQCD=new TH1F("hBgQCD","hBgQCD",10,0,1); + TH1F *hBgData=new TH1F("hBgData","hBgData",10,0,1); + hBgData->Sumw2(); + + + string ptVar; + if(plotPtRatio) ptVar = Form("%s/%s",pt2Choice,pt1Choice); + else ptVar = Form("(%s-%s)/(%s+%s)",pt1Choice,pt2Choice,pt1Choice,pt2Choice); + + cout<<" ptVar "<50&&%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))>2./3.*acos(-1.)&%s1>=%f&&%s2>=%f",effCorr1,effCorr2,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2)); + + cout<<" weightString "<>hBBar",ptVar.c_str()); + sprintf(drawBBar2,"%s*(pthat>50&&%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))>2./3.*acos(-1.)&&abs(refparton_flavorForB1)==5&&abs(refparton_flavorForB2)==5&&%s1>=%f&&%s2>=%f&&refpt1>0&&refpt2>0)",weightString,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2); + + sprintf(drawBX1,"%s>>hBX",ptVar.c_str()); + sprintf(drawBX2,"%s*(pthat>50&&%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))>2./3.*acos(-1.)&&(!(abs(refparton_flavorForB1)==5&&abs(refparton_flavorForB2)==5))&&(abs(refparton_flavorForB1)==5||abs(refparton_flavorForB2)==5)&&%s1>=%f&&%s2>=%f&&refpt1>0&&refpt2>0)",weightString,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2); + + sprintf(drawCCbar1,"%s>>hCCbar",ptVar.c_str()); + sprintf(drawCCbar2,"%s*(pthat>50&&%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))>2./3.*acos(-1.)&&abs(refparton_flavorForB1)==4&&abs(refparton_flavorForB2)==4&&%s1>=%f&&%s2>=%f&&refpt1>0&&refpt2>0)",weightString,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2); + + sprintf(drawCX1,"%s>>hCX",ptVar.c_str()); + sprintf(drawCX2,"%s*(pthat>50&&%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))>2./3.*acos(-1.)&&abs(refparton_flavorForB1)!=5&&abs(refparton_flavorForB2)!=5&&(abs(refparton_flavorForB1)==4||abs(refparton_flavorForB2)==4)&&(!(abs(refparton_flavorForB1)==4&&abs(refparton_flavorForB2)==4))&&%s1>=%f&&%s2>=%f&&refpt1>0&&refpt2>0)",weightString,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2); + + sprintf(drawQCD1,"%s>>hQCD",ptVar.c_str()); + sprintf(drawQCD2,"%s*(pthat>50&&%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))>2./3.*acos(-1.)&&abs(refparton_flavorForB1)!=5&&abs(refparton_flavorForB2)!=5&&abs(refparton_flavorForB1)!=4&&abs(refparton_flavorForB2)!=4&&%s1>=%f&&%s2>=%f&&refpt1>0&&refpt2>0)",weightString,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2); + + sprintf(drawData1,"%s>>hData",ptVar.c_str()); + sprintf(drawData2,"%s*(%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))>2./3.*acos(-1.)&&%s1>=%f&&%s2>=%f)",weightString,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2); + + ntB->Draw(drawBBar1,drawBBar2); + ntB->Draw(drawBX1,drawBX2,"same"); + ntC->Draw(drawCCbar1,drawCCbar2,"same"); + ntC->Draw(drawCX1,drawCX2,"same"); + ntQCD->Draw(drawQCD1,drawQCD2,"same"); + ntdata->Draw(drawData1,drawData2,"sames"); + + if(doSub){ + + sprintf(drawBBar1,"%s>>hBgBBar",ptVar.c_str()); + sprintf(drawBBar2,"%s*(pthat>50&&%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))<1./3.*acos(-1.)&&abs(refparton_flavorForB1)==5&&abs(refparton_flavorForB2)==5&&%s1>=%f&&%s2>=%f&&refpt1>0&&refpt2>0)",weightString,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2); + + sprintf(drawBX1,"%s>>hBgBX",ptVar.c_str()); + sprintf(drawBX2,"%s*(pthat>50&&%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))<1./3.*acos(-1.)&&(!(abs(refparton_flavorForB1)==5&&abs(refparton_flavorForB2)==5))&&(abs(refparton_flavorForB1)==5||abs(refparton_flavorForB2)==5)&&%s1>=%f&&%s2>=%f&&refpt1>0&&refpt2>0)",weightString,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2); + + sprintf(drawCCbar1,"%s>>hBgCCbar",ptVar.c_str()); + sprintf(drawCCbar2,"%s*(pthat>50&&%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))<1./3.*acos(-1.)&&abs(refparton_flavorForB1)==4&&abs(refparton_flavorForB2)==4&&%s1>=%f&&%s2>=%f&&refpt1>0&&refpt2>0)",weightString,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2); + + sprintf(drawCX1,"%s>>hBgCX",ptVar.c_str()); + sprintf(drawCX2,"%s*(pthat>50&&%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))<1./3.*acos(-1.)&&abs(refparton_flavorForB1)!=5&&abs(refparton_flavorForB2)!=5&&(abs(refparton_flavorForB1)==4||abs(refparton_flavorForB2)==4)&&(!(abs(refparton_flavorForB1)==4&&abs(refparton_flavorForB2)==4))&&%s1>=%f&&%s2>=%f&&refpt1>0&&refpt2>0)",weightString,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2); + + sprintf(drawQCD1,"%s>>hBgQCD",ptVar.c_str()); + sprintf(drawQCD2,"%s*(pthat>50&&%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))<1./3.*acos(-1.)&&abs(refparton_flavorForB1)!=5&&abs(refparton_flavorForB2)!=5&&abs(refparton_flavorForB1)!=4&&abs(refparton_flavorForB2)!=4&&%s1>=%f&&%s2>=%f&&refpt1>0&&refpt2>0)",weightString,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2); + + sprintf(drawData1,"%s>>hBgData",ptVar.c_str()); + sprintf(drawData2,"%s*(%s>70&&%s<200&&%s>40&&%s<200&&acos(cos(jtphi1-jtphi2))<1./3.*acos(-1.)&&%s1>=%f&&%s2>=%f)",weightString,pt1Choice,pt1Choice,pt2Choice,pt2Choice,disc.c_str(),discCut1,disc.c_str(),discCut2); + + ntB->Draw(drawBBar1,drawBBar2); + ntB->Draw(drawBX1,drawBX2,"same"); + ntC->Draw(drawCCbar1,drawCCbar2,"same"); + ntC->Draw(drawCX1,drawCX2,"same"); + ntQCD->Draw(drawQCD1,drawQCD2,"same"); + ntdata->Draw(drawData1,drawData2,"sames"); + + hBBar->Add(hBgBBar,-1); + hBX->Add(hBgBX,-1); + hCCbar->Add(hBgCCbar,-1); + hCX->Add(hBgCX,-1); + hQCD->Add(hBgQCD,-1); + hData->Add(hBgData,-1); + } + + hData->SetMarkerStyle(8); + + hBBar->SetLineColor(1); + hBX->SetLineColor(1); + hCCbar->SetLineColor(1); + hCX->SetLineColor(1); + hQCD->SetLineColor(1); + + hBBar->SetFillColor(kMagenta); + hBX->SetFillColor(kRed); + hCCbar->SetFillColor(kGreen); + hCX->SetFillColor(kGreen-2); + hQCD->SetFillColor(kAzure); + + hCX->Add(hQCD); + hCCbar->Add(hCX); + hBX->Add(hCCbar); + hBBar->Add(hBX); + + float norm=0.; + + if(pt1norm){ + norm=hPt1MC->Integral(1,121); + cout<<" MC: fraction of leading jets w/ dijet = "<Integral()/hPt1MC->Integral()<Integral(); + + hBBar->Scale(1./norm); + hBX->Scale(1./norm); + hCCbar->Scale(1./norm); + hCX->Scale(1./norm); + hQCD->Scale(1./norm); + + + if(pt1norm){ + cout<<" Data: fraction of leading jets w/ dijet = "<Integral()/hPt1Data->Integral()<Scale(1./hPt1Data->Integral(1,121)); + } + else hData->Scale(1./hData->Integral()); + + TCanvas *c1=new TCanvas("c1","c1",600,600); + c1->cd(); + + hBX->SetStats(0); + hCCbar->SetStats(0); + hCX->SetStats(0); + hQCD->SetStats(0); + + hBBar->Draw(); + hBX->Draw("same"); + hCCbar->Draw("same"); + hCX->Draw("same"); + hQCD->Draw("same"); + hQCD->Draw("sameaxis"); + hData->Draw("sames"); + if(plotPtRatio){ + hBBar->SetXTitle("p_{T,2} / p_{T,1}"); + if(pt1norm)hBBar->SetYTitle("1/n_{leading} dN/d(p_{T,2}/p_{T,1})"); + else hBBar->SetYTitle("unit norm."); + } + else{ + hBBar->SetXTitle("A_{J}"); + if(pt1norm)hBBar->SetYTitle("1/n_{leading} dN/dA_{J}"); + else hBBar->SetYTitle("unit norm."); + } + //hBBar->GetYaxis()->SetTitleOffset(1.2); + //hBBar->GetXaxis()->SetNdivisions(505); + + hBBar->SetFillStyle(1001); + hBX->SetFillStyle(1001); + hCCbar->SetFillStyle(1001); + hCX->SetFillStyle(1001); + hQCD->SetFillStyle(1001); + + if(drawStats){ + gPad->Update(); + TPaveStats *stat1 = (TPaveStats*) hData->FindObject("stats"); + stat1->SetLabel("Data"); + if(plotPtRatio){ + stat1->SetY1NDC(stat1->GetY1NDC()+0.05); + stat1->SetY2NDC(stat1->GetY2NDC()-0.07); + stat1->SetX1NDC(stat1->GetX1NDC()-0.58); + stat1->SetX2NDC(stat1->GetX2NDC()-0.58); + } + else{ + stat1->SetY1NDC(stat1->GetY1NDC()+0.03); + stat1->SetY2NDC(stat1->GetY2NDC()-0.07); + stat1->SetX1NDC(stat1->GetX1NDC()-0.275); + stat1->SetX2NDC(stat1->GetX2NDC()-0.175); + } + stat1->Draw(); + + TPaveStats *stat2 = (TPaveStats*) hBBar->FindObject("stats"); + stat2->SetLabel("MC"); + if(plotPtRatio){ + stat2->SetY1NDC(stat1->GetY1NDC()-0.28); + stat2->SetY2NDC(stat1->GetY2NDC()-0.28); + stat2->SetX1NDC(stat2->GetX1NDC()-0.58); + stat2->SetX2NDC(stat2->GetX2NDC()-0.58); + } + else{ + stat2->SetY1NDC(stat1->GetY1NDC()-0.3); + stat2->SetY2NDC(stat1->GetY2NDC()-0.3); + stat2->SetX1NDC(stat2->GetX1NDC()-0.275); + stat2->SetX2NDC(stat2->GetX2NDC()-0.175); + } + + stat2->Draw(); + } + + + + + hQCD->SetLineColor(1); + + TLegend *leg = NULL; + if(plotPtRatio){ + if(drawStats) leg = new TLegend(0.5,0.2,0.8,0.5); + else leg = new TLegend(0.19,0.655,0.49,0.955); + } + else{ + if(drawStats) leg = new TLegend(0.2,0.175,0.5,0.475); + else leg = new TLegend(0.5,0.6,0.8,0.9); + } + leg->SetBorderSize(0.); + leg->SetFillStyle(0.); + leg->AddEntry(hData,"Data","pl"); + leg->AddEntry(hBBar,"b-#bar{b}","f"); + leg->AddEntry(hBX,"b(#bar{b})+X","f"); + leg->AddEntry(hCCbar,"c-#bar{c}","f"); + leg->AddEntry(hCX,"c(#bar{c})+light","f"); + leg->AddEntry(hQCD,"light jets","f"); + leg->Draw(); + +} diff --git a/plotSystematicComponents.C b/plotSystematicComponents.C index 58cf287..842d332 100644 --- a/plotSystematicComponents.C +++ b/plotSystematicComponents.C @@ -25,10 +25,11 @@ TH1F *zeroErrors(TH1F *h){ for(int i=0;iGetNbinsX();i++) h->SetBinError(i+1,0); } -void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmetrized=1) +void plotSystematicComponents(bool doTransform=1, bool ppPbPb=0, bool plotSymmetrized=1) { - gStyle->SetErrorX(0); + gStyle->SetHistLineWidth(2); + gROOT->ForceStyle(1); // TFile *fMatrix = NULL; TH2F *xNorm=NULL; @@ -61,14 +62,19 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet } else{ // Default parameters and LTJP systematic - f0 = new TFile("output/NewFormatV5_bFractionMCTemplate_pppp1_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root"); + f0 = new TFile("output/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root"); // Working point variation - f1a = new TFile("output/NewFormatV5_bFractionMCTemplate_pppp1_SSVHEat2.5FixCL0_bin_0_40_eta_0_2.root"); - f1b = new TFile("output/NewFormatV5_bFractionMCTemplate_pppp1_SSVHEat1.8FixCL0_bin_0_40_eta_0_2.root"); + f1a = new TFile("output/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.5FixCL0_bin_0_40_eta_0_2.root"); + f1b = new TFile("output/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat1.8FixCL0_bin_0_40_eta_0_2.root"); // Data-driven template - f2 = new TFile("output/NewFormatV5_bFractionDataTemplate_pppp1_SSVHEat2.0FixCL1_bin_0_40_eta_0_2.root"); + f2 = new TFile("output/NewFormatV5_bFractionDataTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.0FixCL1_bin_0_40_eta_0_2.root"); // fix charm - f3 = new TFile("output/NewFormatV5_bFractionMCTemplate_pppp1_SSVHEat2.0FixCL1_bin_0_40_eta_0_2.root"); + f3 = new TFile("output/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_SSVHEat2.0FixCL1_bin_0_40_eta_0_2.root"); + //gsp up and down + f4a = new TFile("output/NewFormatV5_bFractionMCTemplate_pppp1_gspDown_jetcut30_dinkoXchk_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root"); + f4b = new TFile("output/NewFormatV5_bFractionMCTemplate_pppp1_gspDown_jetcut30_dinkoXchk_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root"); + //Eric's Gplus PU filter + f5 = new TFile("output/NewFormatV5_bFractionMCTemplate_pppp1_jetcut30_dinkoXchk_gPlusFilter_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root"); } // Divide by efficiency @@ -124,20 +130,30 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet if(doTransform) hCharm = transformReco2Gen(hCharm, xNorm); // gluon systematics - TH1F *hRawSpec4a = (TH1F*)f4a->Get("hRawBData"); - TH1F *hEff4a = (TH1F*)f4a->Get("hBEfficiencyMC"); - - TH1F *hGlueUp = hRawSpec4a->Clone("hGlueUp"); - hGlueUp->Divide(hEff4a); - - TH1F *hRawSpec4b = (TH1F*)f4b->Get("hRawBData"); - TH1F *hEff4b = (TH1F*)f4b->Get("hBEfficiencyMC"); - - TH1F *hGlueDown = hRawSpec4b->Clone("hGlueDown"); - hGlueDown->Divide(hEff4b); + TH1F *hRawSpec4a = (TH1F*)f4a->Get("hRawBData"); + TH1F *hEff4a = (TH1F*)f4a->Get("hBEfficiencyMC"); + + TH1F *hGlueUp = hRawSpec4a->Clone("hGlueUp"); + hGlueUp->Divide(hEff4a); + + TH1F *hRawSpec4b = (TH1F*)f4b->Get("hRawBData"); + TH1F *hEff4b = (TH1F*)f4b->Get("hBEfficiencyMC"); + + TH1F *hGlueDown = hRawSpec4b->Clone("hGlueDown"); + hGlueDown->Divide(hEff4b); + + if(doTransform) hGlueUp = transformReco2Gen(hGlueUp, xNorm); + if(doTransform) hGlueDown = transformReco2Gen(hGlueDown, xNorm); - if(doTransform) hGlueUp = transformReco2Gen(hGlueUp, xNorm); - if(doTransform) hGlueDown = transformReco2Gen(hGlueDown, xNorm); + // pu systematics + TH1F *hRawSpec5 = (TH1F*)f5->Get("hRawBData"); + TH1F *hEff5 = (TH1F*)f5->Get("hBEfficiencyMC"); + + TH1F *hPU = hRawSpec5->Clone("hPU"); + hPU->Scale(1./7.54082720175149213e-01); //adjustment in luminosity for PU rejection + hPU->Divide(hEff5); + + if(doTransform) hPU = transformReco2Gen(hPU, xNorm); //plotting style stuff @@ -148,6 +164,7 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet hCharm->SetMarkerColor(kCyan+2); hGlueUp->SetMarkerColor(kYellow+2); hGlueDown->SetMarkerColor(kOrange+2); + hPU->SetMarkerColor(kBlue-1); hLTJP->SetLineColor(kRed+2); hWorkingPointUp->SetLineColor(kSpring+2); @@ -156,7 +173,8 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet hCharm->SetLineColor(kCyan+2); hGlueUp->SetLineColor(kYellow+2); hGlueDown->SetLineColor(kOrange+2); - + hPU->SetLineColor(kBlue-1); + if(!plotSymmetrized){ hLTJP->SetMarkerStyle(24); hWorkingPointUp->SetMarkerStyle(26); @@ -165,6 +183,7 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet hCharm->SetMarkerStyle(4); hGlueUp->SetMarkerStyle(2); hGlueDown->SetMarkerStyle(5); + hPU->SetMarkerStyle(28); hLTJP->SetLineStyle(7); hWorkingPointUp->SetLineStyle(6); @@ -173,6 +192,7 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet hCharm->SetLineStyle(4); hGlueUp->SetLineStyle(2); hGlueDown->SetLineStyle(5); + hPU->SetLineStyle(10); hLTJP->SetLineWidth(3); hWorkingPointUp->SetLineWidth(3); @@ -181,7 +201,8 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet hCharm->SetLineWidth(3); hGlueUp->SetLineWidth(3); hGlueDown->SetLineWidth(3); - + hPU->SetLineWidth(3); + } @@ -195,6 +216,7 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet hCharm->Draw("same"); hGlueUp->Draw("same"); hGlueDown->Draw("same"); + hPU->Draw("same"); // Now take fractional systematics @@ -209,6 +231,7 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet TH1F *hFracCharm = hCharm->Clone("hFracCharm"); TH1F *hFracGlueUp = hGlueUp->Clone("hFracGlueUp"); TH1F *hFracGlueDown = hGlueDown->Clone("hFracGlueDown"); + TH1F *hFracPU = hPU->Clone("hFracPU"); hFracTotal->Reset(); hFracLTJP->Reset(); @@ -218,6 +241,7 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet hFracCharm->Reset(); hFracGlueUp->Reset(); hFracGlueDown->Reset(); + hFracPU->Reset(); TH1F *hFracWorkingPoint = hWorkingPointUp->Clone("hFracWorkingPoint"); TH1F *hFracGlue = hGlueUp->Clone("hFracGlue"); @@ -228,6 +252,7 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet TH1F *hFracDataDrivenInv = (TH1F*)hFracDataDriven->Clone("hFracDataDrivenInv"); TH1F *hFracCharmInv = (TH1F*)hFracCharm->Clone("hFracCharmInv"); TH1F *hFracGlueInv = (TH1F*)hFracGlue->Clone("hFracGlueInv"); + TH1F *hFracPUInv = (TH1F*)hFracPU->Clone("hFracPUInv"); for(int i =0;i < hDefault->GetNbinsX(); i++){ @@ -240,6 +265,7 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet float fracCharm = hCharm->GetBinContent(i+1)/valDefault-1.; float fracGlueUp = hGlueUp->GetBinContent(i+1)/valDefault-1.; float fracGlueDown = hGlueDown->GetBinContent(i+1)/valDefault-1.; + float fracPU = hPU->GetBinContent(i+1)/valDefault-1.; hFracLTJP->SetBinContent(i+1,fracLTJP); hFracWorkingPointUp->SetBinContent(i+1,fracWorkingPointUp); @@ -248,6 +274,7 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet hFracCharm->SetBinContent(i+1,fracCharm); hFracGlueUp->SetBinContent(i+1,fracGlueUp); hFracGlueDown->SetBinContent(i+1,fracGlueDown); + hFracPU->SetBinContent(i+1, fracPU); float fracWorkingPoint = TMath::Max(fabs(fracWorkingPointUp),fabs(fracWorkingPointDown)); float fracGlue = TMath::Max(fabs(fracGlueUp),fabs(fracGlueDown)); @@ -260,12 +287,14 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet hFracDataDrivenInv->SetBinContent(i+1,-1.*fracDataDriven); hFracCharmInv->SetBinContent(i+1,-1.*fracCharm); hFracGlueInv->SetBinContent(i+1,-1.*fracGlue); + hFracPUInv->SetBinContent(i+1, -1.*fracPU); float fracTotal = sqrt(fracLTJP*fracLTJP+ fracWorkingPoint*fracWorkingPoint+ fracDataDriven*fracDataDriven+ fracCharm*fracCharm+ + fracPU*fracPU+ fracGlue*fracGlue ); @@ -301,85 +330,99 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet } - hFracLTJP->GetYaxis()->SetTitle("Relative Error"); - hFracLTJP->GetXaxis()->SetNdivisions(505); + hFracTotal->GetYaxis()->SetTitle("Relative Error"); + hFracTotal->SetTitle(""); + hFracTotal->GetYaxis()->SetTitleOffset(1.3); + hFracTotal->GetXaxis()->SetNdivisions(505); + + hFracTotal->SetMaximum(0.6); + hFracTotal->SetMinimum(-0.4); + + hFracTotal->SetFillStyle(1001); + hFracTotalInv->SetFillStyle(1001); + hFracTotal->SetFillColor(kGray); + hFracTotalInv->SetFillColor(kGray); + + hFracTotal->Draw("h"); + hFracTotalInv->Draw("h,same"); - hFracLTJP->SetMaximum(0.6); - hFracLTJP->SetMinimum(-0.4); - hFracLTJP->SetFillColor(hFracLTJP->GetMarkerColor()-2); - if(plotSymmetrized)hFracLTJP->SetFillStyle(3003); - hFracLTJP->Draw(""); + // hFracLTJP->SetFillColor(hFracLTJP->GetMarkerColor()-2); + // if(plotSymmetrized)hFracLTJP->SetFillStyle(3003); + hFracLTJP->Draw("same"); hFracLTJPInv->SetMaximum(0.5); hFracLTJPInv->SetMinimum(-0.5); - hFracLTJPInv->SetFillColor(hFracLTJP->GetMarkerColor()-2); - if(plotSymmetrized)hFracLTJPInv->SetFillStyle(3003); - if(plotSymmetrized)hFracLTJPInv->Draw("h,same"); + //hFracLTJPInv->SetFillColor(hFracLTJP->GetMarkerColor()-2); + //if(plotSymmetrized)hFracLTJPInv->SetFillStyle(3003); + if(plotSymmetrized)hFracLTJPInv->Draw("same"); - hFracWorkingPointUp->SetFillColor(hFracWorkingPointUp->GetMarkerColor()-2); - if(plotSymmetrized)hFracWorkingPointUp->SetFillStyle(3006); - if(!plotSymmetrized)hFracWorkingPointUp->Draw("h,same"); - hFracWorkingPointDown->SetFillColor(hFracWorkingPointDown->GetMarkerColor()-2); - if(plotSymmetrized)hFracWorkingPointDown->SetFillStyle(3006); - if(!plotSymmetrized)hFracWorkingPointDown->Draw("h,same"); + // hFracWorkingPointUp->SetFillColor(hFracWorkingPointUp->GetMarkerColor()-2); + // if(plotSymmetrized)hFracWorkingPointUp->SetFillStyle(3006); + if(!plotSymmetrized)hFracWorkingPointUp->Draw("same"); + //hFracWorkingPointDown->SetFillColor(hFracWorkingPointDown->GetMarkerColor()-2); + //if(plotSymmetrized)hFracWorkingPointDown->SetFillStyle(3006); + if(!plotSymmetrized)hFracWorkingPointDown->Draw("same"); hFracWorkingPoint = zeroErrors(hFracWorkingPoint); hFracWorkingPointInv = zeroErrors(hFracWorkingPointInv); hFracWorkingPoint = zeroErrors(hFracWorkingPoint); - hFracWorkingPoint->SetFillColor(hFracWorkingPoint->GetMarkerColor()-2); - if(plotSymmetrized)hFracWorkingPoint->SetFillStyle(3007); - if(plotSymmetrized)hFracWorkingPoint->Draw("h,same"); - hFracWorkingPointInv->SetFillColor(hFracWorkingPoint->GetMarkerColor()-2); - if(plotSymmetrized)hFracWorkingPointInv->SetFillStyle(3007); - if(plotSymmetrized)hFracWorkingPointInv->Draw("h,same"); + // hFracWorkingPoint->SetFillColor(hFracWorkingPoint->GetMarkerColor()-2); + // if(plotSymmetrized)hFracWorkingPoint->SetFillStyle(3007); + if(plotSymmetrized)hFracWorkingPoint->Draw("same"); + // hFracWorkingPointInv->SetFillColor(hFracWorkingPoint->GetMarkerColor()-2); + // if(plotSymmetrized)hFracWorkingPointInv->SetFillStyle(3007); + if(plotSymmetrized)hFracWorkingPointInv->Draw("same"); - hFracDataDriven->SetFillColor(hFracDataDriven->GetMarkerColor()-2); - if(plotSymmetrized)hFracDataDriven->SetFillStyle(3004); - hFracDataDriven->Draw("h,same"); - hFracDataDrivenInv->SetFillColor(hFracDataDriven->GetMarkerColor()-2); - if(plotSymmetrized)hFracDataDrivenInv->SetFillStyle(3004); - if(plotSymmetrized)hFracDataDrivenInv->Draw("h,same"); + //hFracDataDriven->SetFillColor(hFracDataDriven->GetMarkerColor()-2); + // if(plotSymmetrized)hFracDataDriven->SetFillStyle(3004); + hFracDataDriven->Draw("same"); + // hFracDataDrivenInv->SetFillColor(hFracDataDriven->GetMarkerColor()-2); + // if(plotSymmetrized)hFracDataDrivenInv->SetFillStyle(3004); + if(plotSymmetrized)hFracDataDrivenInv->Draw("same"); - hFracCharm->SetFillColor(hFracCharm->GetMarkerColor()-2); - if(plotSymmetrized)hFracCharm->SetFillStyle(3005); - hFracCharm->Draw("h,same"); - hFracCharmInv->SetFillColor(hFracCharm->GetMarkerColor()-2); - if(plotSymmetrized)hFracCharmInv->SetFillStyle(3005); - if(plotSymmetrized)hFracCharmInv->Draw("h,same"); + // hFracCharm->SetFillColor(hFracCharm->GetMarkerColor()-2); + // if(plotSymmetrized)hFracCharm->SetFillStyle(3005); + hFracCharm->Draw("same"); + // hFracCharmInv->SetFillColor(hFracCharm->GetMarkerColor()-2); + // if(plotSymmetrized)hFracCharmInv->SetFillStyle(3005); + if(plotSymmetrized)hFracCharmInv->Draw("same"); hFracGlue = zeroErrors(hFracGlue); hFracGlueInv = zeroErrors(hFracGlueInv); - hFracGlueUp->SetFillColor(hFracGlueUp->GetMarkerColor()-2); - if(plotSymmetrized)hFracGlueUp->SetFillStyle(3007); - if(!plotSymmetrized)hFracGlueUp->Draw("h,same"); - hFracGlueDown->SetFillColor(hFracGlue->GetMarkerColor()-2); - if(plotSymmetrized)hFracGlueDown->SetFillStyle(3007); - if(!plotSymmetrized)hFracGlueDown->Draw("h,same"); - - hFracGlue->SetFillColor(hFracGlue->GetMarkerColor()-2); - if(plotSymmetrized)hFracGlue->SetFillStyle(3007); - if(plotSymmetrized)hFracGlue->Draw("h,same"); - hFracGlueInv->SetFillColor(hFracGlue->GetMarkerColor()-2); - if(plotSymmetrized)hFracGlueInv->SetFillStyle(3007); - if(plotSymmetrized)hFracGlueInv->Draw("h,same"); - - - hFracTotal->Draw("h,same"); - hFracTotalInv->Draw("h,same"); + // hFracGlueUp->SetFillColor(hFracGlueUp->GetMarkerColor()-2); + //if(plotSymmetrized)hFracGlueUp->SetFillStyle(3007); + if(!plotSymmetrized)hFracGlueUp->Draw("same"); + // hFracGlueDown->SetFillColor(hFracGlue->GetMarkerColor()-2); + // if(plotSymmetrized)hFracGlueDown->SetFillStyle(3007); + if(!plotSymmetrized)hFracGlueDown->Draw("same"); + + //hFracGlue->SetFillColor(hFracGlue->GetMarkerColor()-2); + // if(plotSymmetrized)hFracGlue->SetFillStyle(3007); + if(plotSymmetrized)hFracGlue->Draw("same"); + //hFracGlueInv->SetFillColor(hFracGlue->GetMarkerColor()-2); + // if(plotSymmetrized)hFracGlueInv->SetFillStyle(3007); + if(plotSymmetrized)hFracGlueInv->Draw("same"); + + // hFracPU->SetFillColor(hFracPU->GetMarkerColor()-2); + // if(plotSymmetrized)hFracPU->SetFillStyle(3008); + hFracPU->Draw("same"); + // hFracPUInv->SetFillColor(hFracPU->GetMarkerColor()-2); + // if(plotSymmetrized)hFracPUInv->SetFillStyle(3008); + if(plotSymmetrized)hFracPUInv->Draw("same"); string legStyle = "l"; - if(plotSymmetrized) legStyle="f"; + //if(plotSymmetrized) legStyle="f"; - TLegend *leg=new TLegend(0.4,0.7,0.8,0.95); + TLegend *leg=new TLegend(0.225,0.6555,0.624,0.905); leg->SetBorderSize(0); leg->SetFillStyle(0); - leg->AddEntry(hFracTotal,"Total","l"); + leg->AddEntry(hFracTotal,"Total","lf"); leg->AddEntry(hFracLTJP,"Reference Tagger",legStyle.c_str()); if(plotSymmetrized)leg->AddEntry(hFracWorkingPoint,"Working point",legStyle.c_str()); else{ @@ -394,9 +437,15 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet leg->AddEntry(hFracGlueUp,"Glue up",legStyle.c_str()); leg->AddEntry(hFracGlueDown,"Glue down",legStyle.c_str()); } + leg->AddEntry(hFracPU,"GPlus PU Filter",legStyle.c_str()); leg->Draw(); - + TLatex *lt1 = new TLatex(183.5,0.455,"#sqrt{s} = 2.76 TeV"); + lt1->SetTextSize(0.042); + lt1->Draw(); + TLatex *lt2 = new TLatex(217,0.52,"CMS"); + lt2->SetTextSize(0.05); + lt2->Draw(); TFile *fout=NULL; if(ppPbPb)fout = new TFile("systematics_components_PbPb.root","recreate"); @@ -410,11 +459,13 @@ void plotSystematicComponents(bool doTransform=1, bool ppPbPb=1, bool plotSymmet hFracGlue->Write(); hFracGlueUp->Write(); hFracGlueDown->Write(); + hFracPU->Write(); hFracLTJPInv->Write(); hFracWorkingPointInv->Write(); hFracDataDrivenInv->Write(); hFracCharmInv->Write(); + hFracPUInv->Write(); fout->Close(); diff --git a/weightPtHatBinsBC.C b/weightPtHatBinsBC.C index 992c3d8..12f87d8 100644 --- a/weightPtHatBinsBC.C +++ b/weightPtHatBinsBC.C @@ -7,7 +7,7 @@ #include "TH1.h" #include "TMath.h" -void weightPtHatBinsBC(int LCB=2, int useGSP=1, int useQCD=1){ +void weightPtHatBinsBC(int LCB=1, int useGSP=1, int useQCD=1){ // LCB = // 0: Light jets @@ -25,12 +25,12 @@ void weightPtHatBinsBC(int LCB=2, int useGSP=1, int useQCD=1){ TFile *fin = NULL; if(LCB==0) fin = new TFile("/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_oldHydjet_restrictMixTripletA_ipHICalibCentWeight_qcd.root"); else if(LCB==1){ - if(useQCD) fin = new TFile("/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_restrictMixTripletA_ipHICalibCentWeight_cJetPlusQCD.root"); - else fin = new TFile("/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_restrictMixTripletA_ipHICalibCentWeight_cJet.root"); + if(useQCD) fin = new TFile("/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_newHydjet_restrictMixTripletA_ipHICalibCentWeight_cJetPlusQCD.root"); + else fin = new TFile("/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_newHydjet_restrictMixTripletA_ipHICalibCentWeight_cJet.root"); } else if(LCB==2){ - if(useQCD) fin = new TFile("/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_restrictMixTripletA_ipHICalibCentWeight_bJetPlusQCD.root"); - else fin = new TFile("/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_restrictMixTripletA_ipHICalibCentWeight_bJet.root"); + if(useQCD) fin = new TFile("/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_newHydjet_restrictMixTripletA_ipHICalibCentWeight_bJetPlusQCD.root"); + else fin = new TFile("/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_newHydjet_restrictMixTripletA_ipHICalibCentWeight_bJet.root"); } else { cout<<" You suck at picking input files "<SetParameters(14781.9,-1641.19,127.245,-8.87318,0.41423,-0.011089,0.000154744,-8.76427e-07); @@ -143,10 +139,10 @@ void weightPtHatBinsBC(int LCB=2, int useGSP=1, int useQCD=1){ // preliminary //TFile *fMC = new TFile("/grid_mnt/vol__vol1__u/llr/cms/mnguyen/bTagging442p5/CMSSW_4_4_2_patch5/src/bTaggingMacros/histos/PbPbQCDMC.root"); //TFile *fMC = new TFile("/grid_mnt/vol__vol1__u/llr/cms/mnguyen/bTagging442p5/CMSSW_4_4_2_patch5/src/bTaggingMacros/histos/PbPbQCDMC_regPFforJets.root"); - TFile *fMCQCD=new TFile("/grid_mnt/vol__vol1__u/llr/cms/mnguyen/bTagging442p5/CMSSW_4_4_2_patch5/src/UserCode/kjung/bTaggerCode/histos//PbPbQCDMC_pt30by3_ipHICalibCentWeight_noTrig.root"); + TFile *fMCQCD=new TFile("/grid_mnt/vol__vol1__u/llr/cms/mnguyen/bTagging442p5/CMSSW_4_4_2_patch5/src/bTaggingMacros/histos/PbPbQCDMC_pt30by3_ipHICalibCentWeight.root"); TFile *fMCBorC = NULL; - if(LCB==1) fMCBorC=new TFile("/grid_mnt/vol__vol1__u/llr/cms/mnguyen/bTagging442p5/CMSSW_4_4_2_patch5/src/UserCode/kjung/bTaggerCode/histos/PbPbCMC_pt30by3_ipHICalibCentWeight_cOnly.root"); - if(LCB==2) fMCBorC=new TFile("/grid_mnt/vol__vol1__u/llr/cms/mnguyen/bTagging442p5/CMSSW_4_4_2_patch5/src/UserCode/kjung/bTaggerCode/histos/PbPbBMC_pt30by3_ipHICalibCentWeight_bOnly.root"); + if(LCB==1) fMCBorC=new TFile("/grid_mnt/vol__vol1__u/llr/cms/mnguyen/bTagging442p5/CMSSW_4_4_2_patch5/src/bTaggingMacros/histos/PbPbCMC_pt30by3_ipHICalibCentWeight.root"); + if(LCB==2) fMCBorC=new TFile("/grid_mnt/vol__vol1__u/llr/cms/mnguyen/bTagging442p5/CMSSW_4_4_2_patch5/src/bTaggingMacros/histos/PbPbBMC_pt30by3_ipHICalibCentWeight.root"); TH1F *hMCVz[2], *hMCCent[2]; @@ -166,7 +162,7 @@ void weightPtHatBinsBC(int LCB=2, int useGSP=1, int useQCD=1){ hMCCent[1]->Scale(1./hMCCent[1]->Integral()); } - //char filename[500] = "merged_bjetAnalyzers_hiReco_offPV_pt30by3_restrictMixTripletA_ipHICalibCentWeight"; + //char filename[500] = "merged_bjetAnalyzers_hiReco_offPV_pt30by3_newHydjet_restrictMixTripletA_ipHICalibCentWeight"; Double_t weight, xSecWeight, centWeight, vzWeight; Double_t xSecWeights[8]; @@ -197,8 +193,8 @@ void weightPtHatBinsBC(int LCB=2, int useGSP=1, int useQCD=1){ cout<<" determining b or c normaliztion "<Get("akPu3PFJetAnalyzer/t"); for (Int_t it=start; itSetBranchAddress("ipClosest2Jet",ipClosest2Jet); tr_in->SetBranchAddress("mue",mue); tr_in->SetBranchAddress("mupt",mupt); - tr_in->SetBranchAddress("muptPF",muptPF); tr_in->SetBranchAddress("mueta",mueta); tr_in->SetBranchAddress("muphi",muphi); tr_in->SetBranchAddress("mudr",mudr); @@ -472,13 +461,7 @@ void weightPtHatBinsBC(int LCB=2, int useGSP=1, int useQCD=1){ tr_in->SetBranchAddress("muSum", muSum); tr_in->SetBranchAddress("muN", muN); - tr_in->SetBranchAddress("trackMax", trackMax); - tr_in->SetBranchAddress("trackSum", trackSum); - tr_in->SetBranchAddress("trackN", trackN); - tr_in->SetBranchAddress("trackHardSum", trackHardSum); - tr_in->SetBranchAddress("trackHardN", trackHardN); - - + // Set branch addresses. tr_in_skim->SetBranchAddress("pvSel",&pvSel); tr_in_skim->SetBranchAddress("hbheNoiseSel",&hbheNoiseSel); @@ -489,15 +472,15 @@ void weightPtHatBinsBC(int LCB=2, int useGSP=1, int useQCD=1){ char outfile[500]; if(LCB==0) sprintf(outfile,"/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_oldHydjet_restrictMixTripletA_ipHICalibCentWeight_weighted_qcd.root"); else if(LCB==1){ - if(useQCD)sprintf(outfile,"/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_restrictMixTripletA_ipHICalibCentWeight\ + if(useQCD)sprintf(outfile,"/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_newHydjet_restrictMixTripletA_ipHICalibCentWeight\ _weighted_cJetPlusQCD.root"); - else sprintf(outfile,"/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_restrictMixTripletA_ipHICalibCentWeight\ + else sprintf(outfile,"/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_newHydjet_restrictMixTripletA_ipHICalibCentWeight\ _weighted_cJet.root"); } else if(LCB==2){ - if(useQCD)sprintf(outfile,"/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_restrictMixTripletA_ipHICalibCentWeight\ + if(useQCD)sprintf(outfile,"/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_newHydjet_restrictMixTripletA_ipHICalibCentWeight\ _weighted_bJetPlusQCD.root"); - else sprintf(outfile,"/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_restrictMixTripletA_ipHICalibCentWeight\ + else sprintf(outfile,"/data_CMS/cms/mnguyen/bTaggingOutput/hydjetEmbedded/merged_bjetAnalyzers_hiReco_offPV_pt30by3_newHydjet_restrictMixTripletA_ipHICalibCentWeight\ _weighted_bJet.root"); } @@ -556,11 +539,10 @@ _weighted_bJet.root"); tr_out->Branch("ipClosest2Jet",ipClosest2Jet,"ipClosest2Jet[nIP]/F"); tr_out->Branch("mue",mue,"mue[nref]/F"); tr_out->Branch("mupt",mupt,"mupt[nref]/F"); - tr_out->Branch("muptPF",muptPF,"muptPF[nref]/F"); tr_out->Branch("mueta",mueta,"mueta[nref]/F"); tr_out->Branch("muphi",muphi,"muphi[nref]/F"); tr_out->Branch("mudr",mudr,"mudr[nref]/F"); - tr_out->Branch("muptrel",muptrel,"muptrel[nref]/F"); + tr_out->Branch("muptrel",muptrel,"muptre[nref]/F"); tr_out->Branch("muchg",muchg,"muchg[nref]/I"); tr_out->Branch("pthat",&pthat,"pthat/F"); tr_out->Branch("beamId1",&beamId1,"beamId1/I"); @@ -619,12 +601,6 @@ _weighted_bJet.root"); tr_out->Branch("muSum", muSum,"muSum[nref]/F"); tr_out->Branch("muN", muN,"muN[nref]/I"); - tr_out->Branch("trackMax", trackMax,"trackMax[nref]/F"); - tr_out->Branch("trackSum", trackSum,"trackSum[nref]/F"); - tr_out->Branch("trackN", trackN,"trackN[nref]/I"); - tr_out->Branch("trackHardSum", trackHardSum,"trackHardSum[nref]/F"); - tr_out->Branch("trackHardN", trackHardN,"trackHardN[nref]/I"); - // Set output branch addresses. tr_out_skim->Branch("pvSel",&pvSel,"pvSel/I"); tr_out_skim->Branch("hbheNoiseSel",&hbheNoiseSel,"hbheNoiseSel/I"); @@ -674,26 +650,25 @@ _weighted_bJet.root"); // cout<<" centWeightData "<0&&vzbin<=30)vzWeight = hDataVz->GetBinContent(vzbin)/hMCVz[isFiltered]->GetBinContent(vzbin); - else vzWeight=0.; - - xSecWeight = xSecWeights[ibin]; - - //fudge factor for vertex/x-sec non-factorization - /* - if(LCB>0&&isFiltered){ - if(LCB==1) xSecWeight/=0.93022; - if(LCB==2) xSecWeight/=0.989157; - } - */ - /* // for testing - vzWeight = centWeightData; - xSecWeight = centWeightMC; - */ - weight=xSecWeight*centWeight*vzWeight; - - + int vzbin = (int) TMath::Ceil(vz+15.); + if(vzbin>0&&vzbin<=30)vzWeight = hDataVz->GetBinContent(vzbin)/hMCVz[isFiltered]->GetBinContent(vzbin); + else vzWeight=0.; + + xSecWeight = xSecWeights[ibin]; + + //fudge factor for vertex/x-sec non-factorization + if(LCB>0&&isFiltered){ + if(LCB==1) xSecWeight/=0.93022; + if(LCB==2) xSecWeight/=0.989157; + } + + /* // for testing + vzWeight = centWeightData; + xSecWeight = centWeightMC; + */ + weight=xSecWeight*centWeight*vzWeight; + + tr_out->Fill(); tr_out_skim->Fill(); diff --git a/xformTaggingEfficiency.C b/xformTaggingEfficiency.C index 0ddc5ea..b5f887a 100644 --- a/xformTaggingEfficiency.C +++ b/xformTaggingEfficiency.C @@ -1,8 +1,8 @@ void xformTaggingEfficiency(){ - TFile *fMatrix = new TFile("outputTowardsFinal/reco2GenMatrix.root"); - TFile *fin = new TFile("outputTowardsFinal/NewFormatV3_bFractionMCTemplate_ppPbPb1_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root"); + TFile *fMatrix = new TFile("output/reco2GenMatrix.root"); + TFile *fin = new TFile("output/NewFormatV5_bFractionMCTemplate_pppp1_SSVHEat2.0FixCL0_bin_0_40_eta_0_2.root"); // reco 2 gen matrix TH2F *hXform = (TH2F*)fMatrix->Get("hRecoVsGenNorm");