double* fitHist(TCanvas *iC, bool iDoMu,int iPlot, std::string iName,TH1D *iData,TH1D *iW,TH1D *iEWK,TH1D *iAntiData,TH1D *iAntiW,TH1D *iAntiEWK,const Double_t METMAX,const Int_t NBINS,const Double_t lumi,const Int_t Ecm,int iAltQCD) { // // Declare fit parameters for signal and background yields // Note: W signal and EWK+top PDFs are constrained to the ratio described in MC // RooRealVar nSig(("nSig"+iName).c_str(),("nSig"+iName).c_str(),0.7*(iData->Integral()),0,iData->Integral()); RooRealVar nQCD(("nQCD"+iName).c_str(),("nQCD"+iName).c_str(),0.3*(iData->Integral()),0,iData->Integral()); RooRealVar cewk(("cewk"+iName).c_str(),("cewk"+iName).c_str(),0.1,0,5) ; cewk.setVal(iEWK->Integral()/iW->Integral()); cewk.setConstant(kTRUE); RooFormulaVar nEWK(("nEWK"+iName).c_str(),("nEWK"+iName).c_str(),("cewk"+iName+"*nSig"+iName).c_str(),RooArgList(nSig,cewk)); RooRealVar nAntiSig(("nAntiSig"+iName).c_str(),("nAntiSig"+iName).c_str(),0.05*(iAntiData->Integral()),0,iAntiData->Integral()); RooRealVar nAntiQCD(("nAntiQCD"+iName).c_str(),("nAntiQCD"+iName).c_str(),0.9 *(iAntiData->Integral()),0,iAntiData->Integral()); RooRealVar dewk (("dewk" +iName).c_str(),("dewk" +iName).c_str(),0.1,0,5) ; dewk.setVal(iAntiEWK->Integral()/iAntiW->Integral()); dewk.setConstant(kTRUE); RooFormulaVar nAntiEWK(("nAntiEWK"+iName).c_str(),("nAntiEWK"+iName).c_str(),("dewk"+iName+"*nAntiSig"+iName).c_str(),RooArgList(nAntiSig,dewk)); // // Construct PDFs for fitting // RooRealVar pfmet(("pfmet"+iName).c_str(),("pfmet"+iName).c_str(),0,METMAX); pfmet.setBins(NBINS); // Signal PDFs RooDataHist wMet (("wMET" +iName).c_str(), ("wMET" +iName).c_str(), RooArgSet(pfmet),iW); RooHistPdf pdfW(( "w"+iName).c_str(), ( "w"+iName).c_str(), pfmet, wMet, 1); RooDataHist awMet (("awMET"+iName).c_str(), ("awMET"+iName).c_str(), RooArgSet(pfmet),iAntiW); RooHistPdf apdfW(("aw"+iName).c_str(), ("aw"+iName).c_str(), pfmet,awMet, 1); // EWK+top PDFs RooDataHist ewkMet (("ewkMET" +iName).c_str(),( "ewkMET"+iName).c_str(), RooArgSet(pfmet),iEWK); RooHistPdf pdfEWK (( "ewk"+iName).c_str(),( "ewk"+iName).c_str(), pfmet,ewkMet, 1); RooDataHist aewkMet(("aewkMET"+iName).c_str(),("aewkMET"+iName).c_str(), RooArgSet(pfmet),iAntiEWK); RooHistPdf apdfEWK (("aewk"+iName).c_str(),("aewk"+iName).c_str(), pfmet,aewkMet, 1); // QCD Pdfs CPepeModel0 qcd0 (("qcd0" +iName).c_str(),pfmet); CPepeModel1 qcd1 (("qcd1" +iName).c_str(),pfmet); CPepeModel2 qcd2 (("qcd2" +iName).c_str(),pfmet); CPepeModel0 aqcd0(("aqcd0"+iName).c_str(),pfmet); CPepeModel1 aqcd1(("aqcd1"+iName).c_str(),pfmet,qcd1.sigma); CPepeModel2 aqcd2(("aqcd2"+iName).c_str(),pfmet); RooGenericPdf *lQCD = qcd0.model; RooGenericPdf *lAQCD = aqcd0.model; if(iDoMu) lQCD = qcd1.model; if(iDoMu) lAQCD = aqcd1.model; if(iAltQCD == 0) lQCD = qcd0.model; if(iAltQCD == 1) lQCD = qcd1.model; if(iAltQCD == 2) lQCD = qcd2.model; if(iAltQCD == 0) lAQCD = aqcd0.model; if(iAltQCD == 1) lAQCD = aqcd1.model; if(iAltQCD == 2) lAQCD = aqcd2.model; // Signal + Background PDFs RooAddPdf pdfMet (("pdfMet"+iName).c_str(), ("pdfMet" +iName).c_str(), RooArgList(pdfW ,pdfEWK ,*lQCD), RooArgList(nSig,nEWK,nQCD)); RooAddPdf apdfMet(("apdfMet"+iName).c_str(),("apdfMet"+iName).c_str(), RooArgList(apdfW,apdfEWK,*lAQCD), RooArgList(nAntiSig,nAntiEWK,nAntiQCD)); // PDF for simultaneous fit RooCategory rooCat("rooCat","rooCat"); rooCat.defineType("Select"); rooCat.defineType("Anti"); RooSimultaneous pdfTotal("pdfTotal","pdfTotal",rooCat); pdfTotal.addPdf(pdfMet, "Select"); if(iDoMu) pdfTotal.addPdf(apdfMet,"Anti"); // Perform fits RooDataHist dataMet (("dataMet"+iName).c_str(),("dataMet"+iName).c_str(), RooArgSet(pfmet),iData); RooDataHist antiMet (("antiMet"+iName).c_str(),("antiMet"+iName).c_str(), RooArgSet(pfmet),iAntiData); RooDataHist dataTotal(("data" +iName).c_str(),("data" +iName).c_str(), RooArgList(pfmet), Index(rooCat), Import("Select", dataMet), Import("Anti", antiMet)); RooFitResult *fitRes = 0; bool runMinos = kTRUE; if(iPlot == 0 || iPlot == 3) runMinos = kFALSE; //Remove Minos when running toys (too damn slow) if(!iDoMu) fitRes = pdfMet .fitTo(dataMet ,Extended(),Minos(runMinos),Save(kTRUE)); if( iDoMu) fitRes = pdfTotal.fitTo(dataTotal,Extended(),Minos(runMinos),Save(kTRUE)); double *lResults = new double[16]; lResults[0] = nSig.getVal(); lResults[1] = nEWK.getVal(); lResults[2] = nQCD.getVal(); lResults[3] = nAntiSig.getVal(); lResults[4] = nAntiEWK.getVal(); lResults[5] = nAntiQCD.getVal(); if(!iDoMu) lResults[6] = double(qcd0.sigma->getVal()); if( iDoMu) lResults[6] = double(qcd1.sigma->getVal()); lResults[7] = 0.; if(!iDoMu) lResults[7] = qcd1.a1->getVal(); lResults[8] = nSig .getPropagatedError(*fitRes); lResults[9] = nEWK .getPropagatedError(*fitRes); lResults[10] = nQCD .getPropagatedError(*fitRes); lResults[11] = nAntiSig.getPropagatedError(*fitRes); lResults[12] = nAntiEWK.getPropagatedError(*fitRes); lResults[13] = nAntiQCD.getPropagatedError(*fitRes); if( iDoMu) lResults[14] = qcd0.sigma->getError(); if(!iDoMu) lResults[14] = qcd1.sigma->getError(); if( iDoMu) lResults[15] = 0; if(!iDoMu) lResults[15] = qcd1.a1 ->getError(); if(iPlot == 0 ) return lResults; // // Use histogram version of fitted PDFs to make ratio plots // (Will also use PDF histograms later for Chi^2 and KS tests) // TH1D *hPdfMet = (TH1D*)(pdfMet.createHistogram(("hPdfMet"+iName).c_str(), pfmet)); hPdfMet->Scale((nSig.getVal()+nEWK.getVal()+nQCD.getVal())/hPdfMet->Integral()); TH1D *hMetDiff = makeDiffHist(iData,hPdfMet,"hMetDiff"+iName); hMetDiff->SetMarkerStyle(kFullCircle); hMetDiff->SetMarkerSize(0.9); TH1D *hPdfAntiMet = (TH1D*)(apdfMet.createHistogram(("hPdfAntiMet"+iName).c_str(), pfmet)); hPdfAntiMet->Scale((nAntiSig.getVal()+nAntiEWK.getVal()+nAntiQCD.getVal())/hPdfAntiMet->Integral()); TH1D *hAntiMetDiff = makeDiffHist(iAntiData,hPdfAntiMet,"hAntiMetDiff"+iName); hAntiMetDiff->SetMarkerStyle(kFullCircle); hAntiMetDiff->SetMarkerSize(0.9); if(iPlot == 3 ) { //Build best fit QCD with default W and EWK Shap TH1D *hPdfMetQCD = (TH1D*)(lQCD ->createHistogram(("hPdfMetQCD" +iName).c_str(), pfmet)); TH1D *hPdfAMetQCD = (TH1D*)(lAQCD->createHistogram(("hPdfAntiMetQCD"+iName).c_str(), pfmet)); hPdfMetQCD ->Scale(nQCD .getVal()/hPdfMetQCD ->Integral()); hPdfAMetQCD->Scale(nAntiQCD.getVal()/hPdfAMetQCD->Integral()); TH1D *pW = (TH1D*) iW ->Clone("WForToys"); pW ->Scale(nSig .getVal()/pW ->Integral()); TH1D *pEWK = (TH1D*) iEWK ->Clone("EWKForToys"); pEWK ->Scale(nEWK .getVal()/pEWK ->Integral()); TH1D *pAW = (TH1D*) iAntiW ->Clone("AWForToys"); pAW ->Scale(nAntiSig.getVal()/pAW ->Integral()); TH1D *pAEWK = (TH1D*) iAntiEWK->Clone("AEWKForToys"); pAEWK->Scale(nAntiEWK.getVal()/pAEWK->Integral()); hPdfMetQCD ->Add(pW); hPdfMetQCD ->Add(pEWK); hPdfAMetQCD->Add(pAW); hPdfAMetQCD->Add(pAEWK); fBestFit = hPdfMetQCD; fAntiBestFit = hPdfAMetQCD; return lResults; } //-------------------------------------------------------------------------------------------------------------- // Make plots //============================================================================================================== char ylabel[100]; // string buffer for y-axis label // file format for output plots const TString format("png"); // label for lumi char lumitext[100]; if(lumi<0.1) sprintf(lumitext,"%.1f pb^{-1} at #sqrt{s} = %i TeV",lumi*1000.,Ecm); else sprintf(lumitext,"%.2f fb^{-1} at #sqrt{s} = %i TeV",lumi ,Ecm); // plot colors Int_t linecolorW = kOrange-3; Int_t fillcolorW = kOrange-2; Int_t linecolorEWK = kOrange+10; Int_t fillcolorEWK = kOrange+7; Int_t linecolorQCD = kViolet+2; Int_t fillcolorQCD = kViolet-5; Int_t ratioColor = kGray+2; // // Dummy histograms for TLegend // (Nobody can figure out how to properly pass RooFit objects...) // TH1D *hDummyData = new TH1D("hDummyData","",0,0,10); hDummyData->SetMarkerStyle(kFullCircle); hDummyData->SetMarkerSize(0.9); TH1D *hDummyW = new TH1D("hDummyW","",0,0,10); hDummyW->SetLineColor(linecolorW); hDummyW->SetFillColor(fillcolorW); hDummyW->SetFillStyle(1001); TH1D *hDummyEWK = new TH1D("hDummyEWK","",0,0,10); hDummyEWK->SetLineColor(linecolorEWK); hDummyEWK->SetFillColor(fillcolorEWK); hDummyEWK->SetFillStyle(1001); TH1D *hDummyQCD = new TH1D("hDummyQCD","",0,0,10); hDummyQCD->SetLineColor(linecolorQCD); hDummyQCD->SetFillColor(fillcolorQCD); hDummyQCD->SetFillStyle(1001); // // W MET plot // RooPlot *wmframe = pfmet.frame(Bins(NBINS)); dataMet.plotOn(wmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); pdfMet.plotOn(wmframe,FillColor(fillcolorW),DrawOption("F")); pdfMet.plotOn(wmframe,LineColor(linecolorW)); pdfMet.plotOn(wmframe,Components(RooArgSet(pdfEWK,*lQCD)),FillColor(fillcolorEWK),DrawOption("F")); pdfMet.plotOn(wmframe,Components(RooArgSet(pdfEWK,*lQCD)),LineColor(linecolorEWK)); pdfMet.plotOn(wmframe,Components(RooArgSet(*lQCD)),FillColor(fillcolorQCD),DrawOption("F")); pdfMet.plotOn(wmframe,Components(RooArgSet(*lQCD)),LineColor(linecolorQCD)); pdfMet.plotOn(wmframe,Components(RooArgSet(pdfW)),LineColor(linecolorW),LineStyle(2)); dataMet.plotOn(wmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); sprintf(ylabel,"Events / %.1f GeV",iData->GetBinWidth(1)); CPlot plotMet(("fitmet"+iName).c_str(),wmframe,"","",ylabel); plotMet.SetLegend(0.68,0.57,0.93,0.77); plotMet.GetLegend()->AddEntry(hDummyData,"data","PL"); plotMet.GetLegend()->AddEntry(hDummyW,"W#rightarrow#mu#nu","F"); plotMet.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F"); plotMet.GetLegend()->AddEntry(hDummyQCD,"QCD","F"); plotMet.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0); plotMet.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0); plotMet.SetYRange(0.1,1.1*(iData->GetMaximum())); plotMet.Draw(iC,kFALSE,format,1); CPlot plotMetDiff(("fitmet"+iName).c_str(),"","#slash{E}_{T} [GeV]","#chi"); plotMetDiff.AddHist1D(hMetDiff,"EX0",ratioColor); plotMetDiff.SetYRange(-8,8); plotMetDiff.AddLine(0, 0,METMAX, 0,kBlack,1); plotMetDiff.AddLine(0, 5,METMAX, 5,kBlack,3); plotMetDiff.AddLine(0,-5,METMAX,-5,kBlack,3); plotMetDiff.Draw(iC,kTRUE,format,2); plotMet.Draw(iC,kTRUE,format,1); plotMet.SetName(("fitmetlog"+iName).c_str()); plotMet.SetLogy(); plotMet.SetYRange(1e-3*(iData->GetMaximum()),10*(iData->GetMaximum())); plotMet.Draw(iC,kTRUE,format,1); if(iDoMu) { RooPlot *awmframe = pfmet.frame(Bins(NBINS)); antiMet.plotOn(awmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); apdfMet.plotOn(awmframe,FillColor(fillcolorW),DrawOption("F")); apdfMet.plotOn(awmframe,LineColor(linecolorW)); apdfMet.plotOn(awmframe,Components(RooArgSet(apdfEWK,*lQCD)),FillColor(fillcolorEWK),DrawOption("F")); apdfMet.plotOn(awmframe,Components(RooArgSet(apdfEWK,*lQCD)),LineColor(linecolorEWK)); apdfMet.plotOn(awmframe,Components(RooArgSet(*lQCD)),FillColor(fillcolorQCD),DrawOption("F")); apdfMet.plotOn(awmframe,Components(RooArgSet(*lQCD)),LineColor(linecolorQCD)); apdfMet.plotOn(awmframe,Components(RooArgSet(apdfW)),LineColor(linecolorW),LineStyle(2)); antiMet.plotOn(awmframe,MarkerStyle(kFullCircle),MarkerSize(0.9),DrawOption("ZP")); sprintf(ylabel,"Events / %.1f GeV",iAntiData->GetBinWidth(1)); CPlot plotAntiMet(("fitantimet"+iName).c_str(),awmframe,"","",ylabel); plotAntiMet.SetLegend(0.68,0.57,0.93,0.77); plotAntiMet.GetLegend()->AddEntry(hDummyData,"data","PL"); plotAntiMet.GetLegend()->AddEntry(hDummyW,"W#rightarrow#mu#nu","F"); plotAntiMet.GetLegend()->AddEntry(hDummyEWK,"EWK+t#bar{t}","F"); plotAntiMet.GetLegend()->AddEntry(hDummyQCD,"QCD","F"); plotAntiMet.AddTextBox(lumitext,0.55,0.80,0.90,0.86,0); plotAntiMet.AddTextBox("CMS Preliminary",0.63,0.92,0.95,0.99,0); plotAntiMet.SetYRange(0.1,1.1*(iAntiData->GetMaximum())); plotAntiMet.Draw(iC,kFALSE,format,1); CPlot plotAntiMetDiff(("fitantimet"+iName).c_str(),"","#slash{E}_{T} [GeV]","#chi"); plotAntiMetDiff.AddHist1D(hMetDiff,"EX0",ratioColor); plotAntiMetDiff.SetYRange(-8,8); plotAntiMetDiff.AddLine(0, 0,METMAX, 0,kBlack,1); plotAntiMetDiff.AddLine(0, 5,METMAX, 5,kBlack,3); plotAntiMetDiff.AddLine(0,-5,METMAX,-5,kBlack,3); plotAntiMetDiff.Draw(iC,kTRUE,format,2); plotAntiMet.SetName(("fitantimetlog"+iName).c_str()); plotAntiMet.SetLogy(); plotAntiMet.SetYRange(1e-3*(iAntiData->GetMaximum()),10*(iAntiData->GetMaximum())); plotAntiMet.Draw(iC,kTRUE,format,1); } if(iPlot == 1) return lResults; ofstream txtfile; std::string txtfName = "fitres"+iName; if( iDoMu) txtfName + "Mu.txt"; if(!iDoMu) txtfName + "Mu.txt"; ios_base::fmtflags flags; cout << " --- test " << iData->Integral() << " -- " << hPdfMet->Integral() << endl; Double_t chi2prob = iData->Chi2Test(hPdfMet,"PUW"); Double_t chi2ndf = iData->Chi2Test(hPdfMet,"CHI2/NDFUW"); Double_t ksprob = iData->KolmogorovTest(hPdfMet); Double_t ksprobpe = 1;//iData->KolmogorovTest(hPdfMet,"DX"); txtfile.open(txtfName.c_str()); assert(txtfile.is_open()); flags = txtfile.flags(); txtfile << setprecision(10); txtfile << " *** Yields *** " << endl; txtfile << "Selected: " << iData->Integral() << endl; txtfile << " Signal: " << nSig.getVal() << " +/- " << nSig.getPropagatedError(*fitRes) << endl; txtfile << " QCD: " << nQCD.getVal() << " +/- " << nQCD.getPropagatedError(*fitRes) << endl; txtfile << " Other: " << nEWK.getVal() << " +/- " << nEWK.getPropagatedError(*fitRes) << endl; txtfile << endl; txtfile.flags(flags); fitRes->printStream(txtfile,RooPrintable::kValue,RooPrintable::kVerbose); txtfile << endl; printCorrelations(txtfile, fitRes); txtfile << endl; printChi2AndKSResults(txtfile, chi2prob, chi2ndf, ksprob, ksprobpe); txtfile.close(); return lResults; }
void Draw3paneleff() { gStyle->SetOptStat(kFALSE); TString outG="G1.root"; TCanvas *c1 = new TCanvas("","",1000,400); c1->Divide(3); gStyle->SetErrorX(0); double hfbin[]= {0,1,2,3,4,6,8,10,13,16,20,25,30,40,55,70,90}; int nhfbin = 16; TString name, dirname; TFile *fDSeff = TFile::Open("/scratch/xuq7/Centrality/pPbHijing_EffCorr_forNBD.root"); TFile *ftreff = TFile::Open("/scratch/xuq7/Centrality/pPbHist_Hijing_TrandEs.root"); TH1D* hbef = (TH1D*)ftreff->Get("hHFEnergy4"); TH1D* rehbef = (TH1D*)hbef->Rebin(nhfbin,"rehHFEnergy4",hfbin); TH1D* haft = (TH1D*)ftreff->Get("hHFEnergy4_tr"); TH1D* rehaft = (TH1D*)haft->Rebin(nhfbin,"rehHFEnergy4_tr",hfbin); TGraphAsymmErrors *gtreff = new TGraphAsymmErrors(); gtreff->BayesDivide(rehaft,rehbef); TGraphAsymmErrors *geff = (TGraphAsymmErrors*)fDSeff->Get("regEffHF4"); for(int i=0; i<geff->GetN(); i++) { geff->SetPointEXlow(i,0); geff->SetPointEXhigh(i,0); gtreff->SetPointEXlow(i,0); gtreff->SetPointEXhigh(i,0); } geff->SetTitle(""); geff->SetMarkerStyle(33); geff->SetMarkerColor(5); geff->SetMarkerSize(1.3); gtreff->SetTitle(""); gtreff->SetMarkerStyle(21); gtreff->SetMarkerColor(6); gtreff->SetMarkerSize(1.3); for(int cenvar=0; cenvar<3; cenvar++) { TFile *f = TFile::Open(Form("%s/%s",cenvardir[cenvar].Data(),outG.Data())); c1->cd(cenvar+1); TObjString* dataname = (TObjString*)f->Get(Form("dataname")); TObjString* histoname = (TObjString*)f->Get(Form("histoname")); TFile *fdata = TFile::Open(dataname->GetString()); TH1D *histo_obs = (TH1D*)fdata->Get(histoname->GetString()); histo_obs->Sumw2(); TH1D* hFrame = histo_obs->Clone(); hFrame->Reset(); hFrame->SetTitle(""); hFrame->SetMaximum(1.2); hFrame->SetMinimum(0); if(cenvar==0)hFrame->GetYaxis()->SetTitle("ratio"); else hFrame->GetYaxis()->SetTitle(""); hFrame->GetXaxis()->SetRangeUser(0,100); hFrame->GetXaxis()->CenterTitle(0); hFrame->GetYaxis()->CenterTitle(1); hFrame->GetYaxis()->SetTitleOffset(1.1); hFrame->GetXaxis()->SetTitleOffset(1.1); hFrame->GetXaxis()->SetTitleSize(0.056); hFrame->GetYaxis()->SetTitleSize(0.056); hFrame->GetXaxis()->SetLabelSize(0.05); hFrame->GetYaxis()->SetLabelSize(0.05); int binnum = histo_obs->GetNbinsX(); double Minx = histo_obs->GetXaxis()->GetXmin(); double Maxx = histo_obs->GetXaxis()->GetXmax(); double binsize = (Double_t)(Maxx-Minx)/binnum; hFrame->Draw(); TLegend *leg = new TLegend(0.40, 0.2, 0.65, 0.4); for(int sth=0; sth<3; sth++) { int Gth=0; if(sth==0) { dirname = "std"; } else if(sth==1) { dirname ="Gri055"; } else { dirname ="Gri101"; } hFrame->GetXaxis()->SetTitle(cenvariable[cenvar]); if(Gth==0) name = "G0"; else if(Gth<nGlau) name = Form("Glau_%d",Gth); else name = Form("bin_%d",Gth-nGlau+1); TObjString* Glaubername = (TObjString*)f->Get(Form("%s/%s/Glaubername",dirname.Data(),name.Data())); TVectorD* xmin = (TVectorD*)f->Get(Form("%s/%s/xmin",dirname.Data(),name.Data())); TVectorD* xmax = (TVectorD*)f->Get(Form("%s/%s/xmax",dirname.Data(),name.Data())); TVectorD* mubest = (TVectorD*)f->Get(Form("%s/%s/mubest",dirname.Data(),name.Data())); TVectorD* kbest = (TVectorD*)f->Get(Form("%s/%s/kbest",dirname.Data(),name.Data())); TVectorD* Ndf = (TVectorD*)f->Get(Form("%s/%s/Ndf",dirname.Data(),name.Data())); TVectorD* chis = (TVectorD*)f->Get(Form("%s/%s/chis",dirname.Data(),name.Data())); TVectorD *kpoint = (TVectorD*)f->Get(Form("%s/%s/kpoint",dirname.Data(),name.Data())); int xbinmin=(int)(((*xmin)[0]-Minx)/binsize); int xbinmax=(int)(((*xmax)[0]-Minx)/binsize); TFile *fGlauber = TFile::Open(Glaubername->GetString()); TH1D *histo_exp = new TH1D("histo_exp","Simulated distribution;Multiplicity;Event Fraction",binnum,Minx,Maxx); histo_exp->Sumw2(); Int_t ibin; TH1D *histo_obs_norm = (TH1D*)histo_obs->Clone(); histo_obs_norm->Scale(1/histo_obs->Integral(xbinmin,xbinmax)); TF1 *NBD_fun = new TF1("NBD_fun","[0]*TMath::Gamma(x+[1])/(TMath::Gamma(x+1)*TMath::Gamma([1]))*TMath::Power([2]/[1],x)/TMath::Power([2]/[1]+1,x+[1])",0,100); NBD_fun->SetParameter(0,1); //[0]: Normalized constant NBD_fun->SetParameter(1,(*kbest)[0]); //[1]: k value NBD_fun->SetParameter(2,(*mubest)[0]); //[2]: mu value TTree *t = (TTree*) fGlauber->Get("nt_p_Pb"); Long_t Nevent; Nevent = (Long_t) t->GetEntries(); Long_t Ev; Int_t Bino; Double_t Para, Bi_Para, Mult; Float_t Ncoll; t->SetBranchAddress("Ncoll",&Ncoll); for(Ev=0; Ev<Nevent; Ev++) { if(Ev%100000==0) cout<<"Have run "<<Ev<<" events"<<endl; t->GetEntry(Ev); Para = 0; //make sure that Para doesn't accumulate through loops for(Bino=0; Bino<Ncoll; Bino++) { Bi_Para = NBD_fun->GetRandom(); Para += Bi_Para; } histo_exp->Fill(Para); } Double_t SumEvent, scale; SumEvent = histo_exp->Integral(xbinmin,xbinmax); scale = 1/SumEvent; TH1D *histo_exp_norm = (TH1D*) histo_exp->Clone(); histo_exp_norm->Scale(scale); rehisto_obs_norm = (TH1D*)histo_obs_norm->Rebin(nhfbin,"rehisto_obs_norm",hfbin); normalizeByBinWidth(rehisto_obs_norm); rehisto_exp_norm = (TH1D*)histo_exp_norm->Rebin(nhfbin,"rehisto_exp_norm",hfbin); normalizeByBinWidth(rehisto_exp_norm); TH1D* ratio = (TH1D*)rehisto_obs_norm->Clone("ratio"); ratio->Divide(rehisto_exp_norm); ratio->SetTitle(""); ratio->SetLineColor(1); ratio->SetMarkerStyle(20); ratio->SetMarkerColor(color_[sth]); ratio->SetMarkerSize(1.3); ratio->Draw("Psame"); geff->Draw("Psame"); gtreff->Draw("Psame"); leg->AddEntry(ratio,Form("data/fit %s",Grilist[sth].Data()),"p"); } leg->SetFillColor(10); leg->SetFillStyle(0); leg->SetBorderSize(0.035); leg->SetTextFont(42); leg->SetTextSize(0.045); leg->AddEntry(geff,"DS efficiency","p"); leg->AddEntry(gtreff,"Event selection efficiency","p"); if(cenvar==2) leg->Draw("same"); TLine *l = new TLine(0,1,90,1); l->SetLineStyle(2); l->Draw("same"); } c1->SaveAs(Form("ratiovseff.png")); c1->SaveAs(Form("ratiovseff.pdf")); }
void plotFakeRate_eta(){ TFile *f1= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_hadd.root"); TFile *f2= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT100to200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *f3= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT200to300_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *f4= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT300to500_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *f5= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT500to700_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *f6= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT700to1000_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *f7= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT1000to1500_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *f8= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/QCD_HT1500to2000_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *g1= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-100To200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *g2= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-200To400_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *g3= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-400To600_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *g4= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-600To800_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *g5= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-800To1200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *g6= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-1200To2500_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *g7= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/WJetsToLNu_HT-2500ToInf_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_hadd.root"); TFile *h1= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds/nominal/DoubleMuon_Run2015C_16Dec2015_hadd.root"); TFile *h2= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds/nominal/DoubleMuon_Run2015D_16Dec2015_hadd.root"); TFile *h3= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds/nominal/DoubleEG_Run2015C_16Dec2015_hadd.root"); TFile *h4= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds/nominal/DoubleEG_Run2015D_16Dec2015_hadd.root"); TFile *h5= TFile::Open("root://cmseos.fnal.gov//store/user/lpcljm/LJMet_FakeRateTest_step1PtEtahadds_rizki/nominal/TT_TuneCUETP8M1_13TeV-powheg-pythia8_hadd.root"); /* NTotalSLPassed = new TH1D("NTotalSLPassed","",3,0,3); NLooseTightEl = new TH1D("NLooseTightEl","",2,0,2); NLooseTightMu = new TH1D("NLooseTightMu","",2,0,2); NLooseEl_Pt = new TH1D("NLooseEl_Pt","",5,ptbins); NLooseMu_Pt = new TH1D("NLooseMu_Pt","",5,ptbins); NLooseEl_Eta = new TH1D("NLooseEl_Eta","",4,etabinsEl); NLooseMu_Eta = new TH1D("NLooseMu_Eta","",4,etabinsMu); NLooseEl_Eta = new TH1D("NLooseEl_Eta","",5,ptbins,4,etabinsEl); NLooseMu_Eta = new TH1D("NLooseMu_Eta","",5,ptbins,4,etabinsMu); NTightEl_Pt = new TH1D("NTightEl_Pt","",5,ptbins); NTightMu_Pt = new TH1D("NTightMu_Pt","",5,ptbins); NTightEl_Eta = new TH1D("NTightEl_Eta","",4,etabinsEl); NTightMu_Eta = new TH1D("NTightMu_Eta","",4,etabinsMu); NTightEl_Eta = new TH1D("NTightEl_Eta","",5,ptbins,4,etabinsEl); NTightMu_Eta = new TH1D("NTightMu_Eta","",5,ptbins,4,etabinsMu); */ TH1D *NLEl_DY = (TH1D*)f1->Get("NLooseEl_Eta"); TH1D *NLMu_DY = (TH1D*)f1->Get("NLooseMu_Eta"); TH1D *NTEl_DY = (TH1D*)f1->Get("NTightEl_Eta"); TH1D *NTMu_DY = (TH1D*)f1->Get("NTightMu_Eta"); TH1D *NLEl_WJ100 = (TH1D*)g1->Get("NLooseEl_Eta"); TH1D *NLMu_WJ100 = (TH1D*)g1->Get("NLooseMu_Eta"); TH1D *NTEl_WJ100 = (TH1D*)g1->Get("NTightEl_Eta"); TH1D *NTMu_WJ100 = (TH1D*)g1->Get("NTightMu_Eta"); TH1D *NLEl_WJ200 = (TH1D*)g2->Get("NLooseEl_Eta"); TH1D *NLMu_WJ200 = (TH1D*)g2->Get("NLooseMu_Eta"); TH1D *NTEl_WJ200 = (TH1D*)g2->Get("NTightEl_Eta"); TH1D *NTMu_WJ200 = (TH1D*)g2->Get("NTightMu_Eta"); TH1D *NLEl_WJ400 = (TH1D*)g3->Get("NLooseEl_Eta"); TH1D *NLMu_WJ400 = (TH1D*)g3->Get("NLooseMu_Eta"); TH1D *NTEl_WJ400 = (TH1D*)g3->Get("NTightEl_Eta"); TH1D *NTMu_WJ400 = (TH1D*)g3->Get("NTightMu_Eta"); TH1D *NLEl_WJ600 = (TH1D*)g4->Get("NLooseEl_Eta"); TH1D *NLMu_WJ600 = (TH1D*)g4->Get("NLooseMu_Eta"); TH1D *NTEl_WJ600 = (TH1D*)g4->Get("NTightEl_Eta"); TH1D *NTMu_WJ600 = (TH1D*)g4->Get("NTightMu_Eta"); TH1D *NLEl_WJ800 = (TH1D*)g5->Get("NLooseEl_Eta"); TH1D *NLMu_WJ800 = (TH1D*)g5->Get("NLooseMu_Eta"); TH1D *NTEl_WJ800 = (TH1D*)g5->Get("NTightEl_Eta"); TH1D *NTMu_WJ800 = (TH1D*)g5->Get("NTightMu_Eta"); TH1D *NLEl_WJ1200 = (TH1D*)g6->Get("NLooseEl_Eta"); TH1D *NLMu_WJ1200 = (TH1D*)g6->Get("NLooseMu_Eta"); TH1D *NTEl_WJ1200 = (TH1D*)g6->Get("NTightEl_Eta"); TH1D *NTMu_WJ1200 = (TH1D*)g6->Get("NTightMu_Eta"); TH1D *NLEl_WJ2500 = (TH1D*)g7->Get("NLooseEl_Eta"); TH1D *NLMu_WJ2500 = (TH1D*)g7->Get("NLooseMu_Eta"); TH1D *NTEl_WJ2500 = (TH1D*)g7->Get("NTightEl_Eta"); TH1D *NTMu_WJ2500 = (TH1D*)g7->Get("NTightMu_Eta"); TH1D *NLEl_QCD100 = (TH1D*)f2->Get("NLooseEl_Eta"); TH1D *NLMu_QCD100 = (TH1D*)f2->Get("NLooseMu_Eta"); TH1D *NTEl_QCD100 = (TH1D*)f2->Get("NTightEl_Eta"); TH1D *NTMu_QCD100 = (TH1D*)f2->Get("NTightMu_Eta"); TH1D *NLEl_QCD200 = (TH1D*)f3->Get("NLooseEl_Eta"); TH1D *NLMu_QCD200 = (TH1D*)f3->Get("NLooseMu_Eta"); TH1D *NTEl_QCD200 = (TH1D*)f3->Get("NTightEl_Eta"); TH1D *NTMu_QCD200 = (TH1D*)f3->Get("NTightMu_Eta"); TH1D *NLEl_QCD300 = (TH1D*)f4->Get("NLooseEl_Eta"); TH1D *NLMu_QCD300 = (TH1D*)f4->Get("NLooseMu_Eta"); TH1D *NTEl_QCD300 = (TH1D*)f4->Get("NTightEl_Eta"); TH1D *NTMu_QCD300 = (TH1D*)f4->Get("NTightMu_Eta"); TH1D *NLEl_QCD500 = (TH1D*)f5->Get("NLooseEl_Eta"); TH1D *NLMu_QCD500 = (TH1D*)f5->Get("NLooseMu_Eta"); TH1D *NTEl_QCD500 = (TH1D*)f5->Get("NTightEl_Eta"); TH1D *NTMu_QCD500 = (TH1D*)f5->Get("NTightMu_Eta"); TH1D *NLEl_QCD700 = (TH1D*)f6->Get("NLooseEl_Eta"); TH1D *NLMu_QCD700 = (TH1D*)f6->Get("NLooseMu_Eta"); TH1D *NTEl_QCD700 = (TH1D*)f6->Get("NTightEl_Eta"); TH1D *NTMu_QCD700 = (TH1D*)f6->Get("NTightMu_Eta"); TH1D *NLEl_QCD1000 = (TH1D*)f7->Get("NLooseEl_Eta"); TH1D *NLMu_QCD1000 = (TH1D*)f7->Get("NLooseMu_Eta"); TH1D *NTEl_QCD1000 = (TH1D*)f7->Get("NTightEl_Eta"); TH1D *NTMu_QCD1000 = (TH1D*)f7->Get("NTightMu_Eta"); TH1D *NLEl_QCD1500 = (TH1D*)f8->Get("NLooseEl_Eta"); TH1D *NLMu_QCD1500 = (TH1D*)f8->Get("NLooseMu_Eta"); TH1D *NTEl_QCD1500 = (TH1D*)f8->Get("NTightEl_Eta"); TH1D *NTMu_QCD1500 = (TH1D*)f8->Get("NTightMu_Eta"); TH1D *NLEl_DMC = (TH1D*)h1->Get("NLooseEl_Eta"); TH1D *NLMu_DMC = (TH1D*)h1->Get("NLooseMu_Eta"); TH1D *NTEl_DMC = (TH1D*)h1->Get("NTightEl_Eta"); TH1D *NTMu_DMC = (TH1D*)h1->Get("NTightMu_Eta"); TH1D *NLEl_DMD = (TH1D*)h2->Get("NLooseEl_Eta"); TH1D *NLMu_DMD = (TH1D*)h2->Get("NLooseMu_Eta"); TH1D *NTEl_DMD = (TH1D*)h2->Get("NTightEl_Eta"); TH1D *NTMu_DMD = (TH1D*)h2->Get("NTightMu_Eta"); TH1D *NLEl_DEC = (TH1D*)h3->Get("NLooseEl_Eta"); TH1D *NLMu_DEC = (TH1D*)h3->Get("NLooseMu_Eta"); TH1D *NTEl_DEC = (TH1D*)h3->Get("NTightEl_Eta"); TH1D *NTMu_DEC = (TH1D*)h3->Get("NTightMu_Eta"); TH1D *NLEl_DED = (TH1D*)h4->Get("NLooseEl_Eta"); TH1D *NLMu_DED = (TH1D*)h4->Get("NLooseMu_Eta"); TH1D *NTEl_DED = (TH1D*)h4->Get("NTightEl_Eta"); TH1D *NTMu_DED = (TH1D*)h4->Get("NTightMu_Eta"); TH1D *NLEl_TT = (TH1D*)h5->Get("NLooseEl_Eta"); TH1D *NLMu_TT = (TH1D*)h5->Get("NLooseMu_Eta"); TH1D *NTEl_TT = (TH1D*)h5->Get("NTightEl_Eta"); TH1D *NTMu_TT = (TH1D*)h5->Get("NTightMu_Eta"); double scale_WJ100 = 201.4*1345.0*1.21/10205377.; double scale_WJ200 = 201.4*359.7*1.21/4949568.; double scale_WJ400 = 201.4*48.91*1.21/1943664.; double scale_WJ600 = 201.4*12.05*1.21/3767766.; double scale_WJ800 = 201.4*5.501*1.21/1568277.; double scale_WJ1200 = 201.4*1.329*1.21/246239.; double scale_WJ2500 = 201.4*0.03216*1.21/251982.; double scale_QCD100 = 201.4*27990000.0/82095800.; double scale_QCD200 = 201.4*1712000.0/18784379.; double scale_QCD300 = 201.4*347700.0/16909004.; double scale_QCD500 = 201.4*32100.0/19665695.; double scale_QCD700 = 201.4*6831.0/15547962.; double scale_QCD1000 = 201.4*1207.0/5049267.; double scale_QCD1500 = 201.4*119.9/3939077.; double scale_DY = 201.4*6025.2/81236727.; double scale_TT = 201.4*831.76/97994442; double ElCoeff = 46.8/201.4; NTEl_WJ100->Scale(ElCoeff*scale_WJ100); NTMu_WJ100->Scale(scale_WJ100); NTEl_WJ200->Scale(ElCoeff*scale_WJ200); NTMu_WJ200->Scale(scale_WJ200); NTEl_WJ400->Scale(ElCoeff*scale_WJ400); NTMu_WJ400->Scale(scale_WJ400); NTEl_WJ600->Scale(ElCoeff*scale_WJ600); NTMu_WJ600->Scale(scale_WJ600); NTEl_WJ800->Scale(ElCoeff*scale_WJ800); NTMu_WJ800->Scale(scale_WJ800); NTEl_WJ1200->Scale(ElCoeff*scale_WJ1200); NTMu_WJ1200->Scale(scale_WJ1200); NTEl_WJ2500->Scale(ElCoeff*scale_WJ2500); NTMu_WJ2500->Scale(scale_WJ2500); NLEl_WJ100->Scale(ElCoeff*scale_WJ100); NLMu_WJ100->Scale(scale_WJ100); NLEl_WJ200->Scale(ElCoeff*scale_WJ200); NLMu_WJ200->Scale(scale_WJ200); NLEl_WJ400->Scale(ElCoeff*scale_WJ400); NLMu_WJ400->Scale(scale_WJ400); NLEl_WJ600->Scale(ElCoeff*scale_WJ600); NLMu_WJ600->Scale(scale_WJ600); NLEl_WJ800->Scale(ElCoeff*scale_WJ800); NLMu_WJ800->Scale(scale_WJ800); NLEl_WJ1200->Scale(ElCoeff*scale_WJ1200); NLMu_WJ1200->Scale(scale_WJ1200); NLEl_WJ2500->Scale(ElCoeff*scale_WJ2500); NLMu_WJ2500->Scale(scale_WJ2500); NTEl_QCD100->Scale(ElCoeff*scale_QCD100); NTMu_QCD100->Scale(scale_QCD100); NTEl_QCD200->Scale(ElCoeff*scale_QCD200); NTMu_QCD200->Scale(scale_QCD200); NTEl_QCD300->Scale(ElCoeff*scale_QCD300); NTMu_QCD300->Scale(scale_QCD300); NTEl_QCD500->Scale(ElCoeff*scale_QCD500); NTMu_QCD500->Scale(scale_QCD500); NTEl_QCD700->Scale(ElCoeff*scale_QCD700); NTMu_QCD700->Scale(scale_QCD700); NTEl_QCD1000->Scale(ElCoeff*scale_QCD1000); NTMu_QCD1000->Scale(scale_QCD1000); NTEl_QCD1500->Scale(ElCoeff*scale_QCD1500); NTMu_QCD1500->Scale(scale_QCD1500); NLEl_QCD100->Scale(ElCoeff*scale_QCD100); NLMu_QCD100->Scale(scale_QCD100); NLEl_QCD200->Scale(ElCoeff*scale_QCD200); NLMu_QCD200->Scale(scale_QCD200); NLEl_QCD300->Scale(ElCoeff*scale_QCD300); NLMu_QCD300->Scale(scale_QCD300); NLEl_QCD500->Scale(ElCoeff*scale_QCD500); NLMu_QCD500->Scale(scale_QCD500); NLEl_QCD700->Scale(ElCoeff*scale_QCD700); NLMu_QCD700->Scale(scale_QCD700); NLEl_QCD1000->Scale(ElCoeff*scale_QCD1000); NLMu_QCD1000->Scale(scale_QCD1000); NLEl_QCD1500->Scale(ElCoeff*scale_QCD1500); NLMu_QCD1500->Scale(scale_QCD1500); NTEl_DY->Scale(ElCoeff*scale_DY); NTEl_TT->Scale(ElCoeff*scale_TT); NLEl_DY->Scale(ElCoeff*scale_DY); NLEl_TT->Scale(ElCoeff*scale_TT); NTMu_DY->Scale(scale_DY); NTMu_TT->Scale(scale_TT); NLMu_DY->Scale(scale_DY); NLMu_TT->Scale(scale_TT); NTEl_WJ100->Add(NTEl_WJ200); NTMu_WJ100->Add(NTMu_WJ200); NTEl_WJ100->Add(NTEl_WJ400); NTMu_WJ100->Add(NTMu_WJ400); NTEl_WJ100->Add(NTEl_WJ600); NTMu_WJ100->Add(NTMu_WJ600); NTEl_WJ100->Add(NTEl_WJ800); NTMu_WJ100->Add(NTMu_WJ800); NTEl_WJ100->Add(NTEl_WJ1200); NTMu_WJ100->Add(NTMu_WJ1200); NTEl_WJ100->Add(NTEl_WJ2500); NTMu_WJ100->Add(NTMu_WJ2500); NLEl_WJ100->Add(NLEl_WJ200); NLMu_WJ100->Add(NLMu_WJ200); NLEl_WJ100->Add(NLEl_WJ400); NLMu_WJ100->Add(NLMu_WJ400); NLEl_WJ100->Add(NLEl_WJ600); NLMu_WJ100->Add(NLMu_WJ600); NLEl_WJ100->Add(NLEl_WJ800); NLMu_WJ100->Add(NLMu_WJ800); NLEl_WJ100->Add(NLEl_WJ1200); NLMu_WJ100->Add(NLMu_WJ1200); NLEl_WJ100->Add(NLEl_WJ2500); NLMu_WJ100->Add(NLMu_WJ2500); NTEl_QCD100->Add(NTEl_QCD200); NTMu_QCD100->Add(NTMu_QCD200); NTEl_QCD100->Add(NTEl_QCD300); NTMu_QCD100->Add(NTMu_QCD300); NTEl_QCD100->Add(NTEl_QCD500); NTMu_QCD100->Add(NTMu_QCD500); NTEl_QCD100->Add(NTEl_QCD700); NTMu_QCD100->Add(NTMu_QCD700); NTEl_QCD100->Add(NTEl_QCD1000); NTMu_QCD100->Add(NTMu_QCD1000); NTEl_QCD100->Add(NTEl_QCD1500); NTMu_QCD100->Add(NTMu_QCD1500); NLEl_QCD100->Add(NLEl_QCD200); NLMu_QCD100->Add(NLMu_QCD200); NLEl_QCD100->Add(NLEl_QCD300); NLMu_QCD100->Add(NLMu_QCD300); NLEl_QCD100->Add(NLEl_QCD500); NLMu_QCD100->Add(NLMu_QCD500); NLEl_QCD100->Add(NLEl_QCD700); NLMu_QCD100->Add(NLMu_QCD700); NLEl_QCD100->Add(NLEl_QCD1000); NLMu_QCD100->Add(NLMu_QCD1000); NLEl_QCD100->Add(NLEl_QCD1500); NLMu_QCD100->Add(NLMu_QCD1500); NTEl_DEC->Add(NTEl_DED); NTMu_DEC->Add(NTMu_DED); NTEl_DEC->Add(NTEl_DMC); NTMu_DEC->Add(NTMu_DMC); NTEl_DEC->Add(NTEl_DMD); NTMu_DEC->Add(NTMu_DMD); NLEl_DEC->Add(NLEl_DED); NLMu_DEC->Add(NLMu_DED); NLEl_DEC->Add(NLEl_DMC); NLMu_DEC->Add(NLMu_DMC); NLEl_DEC->Add(NLEl_DMD); NLMu_DEC->Add(NLMu_DMD); TH1D *NREl_WJ100 = (TH1D*)NTEl_WJ100->Clone("NREl_WJ100"); TH1D *NRMu_WJ100 = (TH1D*)NTMu_WJ100->Clone("NRMu_WJ100"); TH1D *NREl_QCD100 = (TH1D*)NTEl_QCD100->Clone("NREl_QCD100"); TH1D *NRMu_QCD100 = (TH1D*)NTMu_QCD100->Clone("NRMu_QCD100"); TH1D *NREl_DY = (TH1D*)NTEl_DY->Clone("NREl_DY"); TH1D *NRMu_DY = (TH1D*)NTMu_DY->Clone("NRMu_DY"); TH1D *NREl_TT = (TH1D*)NTEl_TT->Clone("NREl_TT"); TH1D *NRMu_TT = (TH1D*)NTMu_TT->Clone("NRMu_TT"); TH1D *NREl_DEC = (TH1D*)NTEl_DEC->Clone("NREl_DEC"); TH1D *NRMu_DEC = (TH1D*)NTMu_DEC->Clone("NRMu_DEC"); NREl_WJ100->Divide(NLEl_WJ100); NRMu_WJ100->Divide(NLMu_WJ100); NREl_QCD100->Divide(NLEl_QCD100); NRMu_QCD100->Divide(NLMu_QCD100); NREl_DY->Divide(NLEl_DY); NRMu_DY->Divide(NLMu_DY); NREl_TT->Divide(NLEl_TT); NRMu_TT->Divide(NLMu_TT); NREl_DEC->Divide(NLEl_DEC); NRMu_DEC->Divide(NLMu_DEC); TCanvas *c1 = new TCanvas("c1","c1",800,600); gStyle->SetPalette(1); NREl_WJ100->Draw("colz"); c1->SaveAs("FakeRatePlots/FakeRate_WJets_El_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_WJets_El_Eta.png"); NRMu_WJ100->Draw("colz"); c1->SaveAs("FakeRatePlots/FakeRate_WJets_Mu_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_WJets_Mu_Eta.png"); NREl_QCD100->Draw("colz"); c1->SaveAs("FakeRatePlots/FakeRate_QCD_El_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_QCD_El_Eta.png"); NRMu_QCD100->Draw("colz"); c1->SaveAs("FakeRatePlots/FakeRate_QCD_Mu_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_QCD_Mu_Eta.png"); NREl_DY->Draw("colz"); c1->SaveAs("FakeRatePlots/FakeRate_DY_El_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_DY_El_Eta.png"); NRMu_DY->Draw("colz"); c1->SaveAs("FakeRatePlots/FakeRate_DY_Mu_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_DY_Mu_Eta.png"); NREl_TT->Draw("colz"); c1->SaveAs("FakeRatePlots/FakeRate_TT_El_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_TT_El_Eta.png"); NRMu_TT->Draw("colz"); c1->SaveAs("FakeRatePlots/FakeRate_TT_Mu_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_TT_Mu_Eta.png"); NREl_DEC->Draw("colz"); c1->SaveAs("FakeRatePlots/FakeRate_Data_El_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_Data_El_Eta.png"); NRMu_DEC->Draw("colz"); c1->SaveAs("FakeRatePlots/FakeRate_Data_Mu_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_Data_Mu_Eta.png"); TH1D *newtightEl = (TH1D*)NTEl_DEC->Clone("newtightEl"); TH1D *newlooseEl = (TH1D*)NLEl_DEC->Clone("newlooseEl"); newtightEl->Add(NTEl_WJ100,-1); newtightEl->Add(NTEl_DY,-1); newtightEl->Add(NTEl_TT,-1); // newlooseEl->Add(NLEl_WJ100,-1); // newlooseEl->Add(NLEl_DY,-1); // newlooseEl->Add(NLEl_TT,-1); TH1D *newratioEl = (TH1D*)newtightEl->Clone("newratioEl"); newratioEl->Divide(newlooseEl); TH1D *newtightMu = (TH1D*)NTMu_DEC->Clone("newtightMu"); TH1D *newlooseMu = (TH1D*)NLMu_DEC->Clone("newlooseMu"); newtightMu->Add(NTMu_WJ100,-1); newtightMu->Add(NTMu_DY,-1); newtightMu->Add(NTMu_TT,-1); // newlooseMu->Add(NLMu_WJ100,-1); // newlooseMu->Add(NLMu_DY,-1); // newlooseMu->Add(NLMu_TT,-1); TH1D *newratioMu = (TH1D*)newtightMu->Clone("newratioMu"); newratioMu->Divide(newlooseMu); TH1D *ratio_QCDdata_el = (TH1D*)newratioEl->Clone("ratio_QCDdata_el"); ratio_QCDdata_el->Divide(NREl_QCD100); TH1D *ratio_QCDdata_mu = (TH1D*)newratioMu->Clone("ratio_QCDdata_mu"); ratio_QCDdata_mu->Divide(NRMu_QCD100); newratioEl->Draw("colz"); c1->SaveAs("FakeRatePlots/FakeRate_Data_subtr_El_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_Data_subtr_El_Eta.png"); newratioMu->Draw("colz"); c1->SaveAs("FakeRatePlots/FakeRate_Data_subtr_Mu_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_Data_subtr_Mu_Eta.png"); ratio_QCDdata_el->Draw(); c1->SaveAs("FakeRatePlots/FakeRate_ratio_QCDData_subtr_El_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_ratio_QCDData_subtr_El_Eta.png"); ratio_QCDdata_mu->Draw(); c1->SaveAs("FakeRatePlots/FakeRate_ratio_QCDData_subtr_Mu_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_ratio_QCDData_subtr_Mu_Eta.png"); NREl_TT->GetYaxis()->SetRangeUser(0,1); NREl_TT->SetLineColor(kBlue); NREl_WJ100->SetLineColor(kGreen); NREl_DY->SetLineColor(kViolet); NREl_QCD100->SetLineColor(kRed); NREl_DEC->SetLineColor(kBlack); newratioEl->SetLineColor(kBlack); newratioEl->SetLineStyle(5); leg_El = new TLegend(0.9-0.38,0.1+0.5,0.9,0.1+0.2+0.5); leg_El->AddEntry(NREl_TT,"top","lep"); leg_El->AddEntry(NREl_WJ100,"W","lep"); leg_El->AddEntry(NREl_DY,"DY","lep"); leg_El->AddEntry(NREl_QCD100,"QCD","lep"); leg_El->AddEntry(NREl_DEC,"Data","lep"); leg_El->AddEntry(newratioEl,"Data (subtracted)","lep"); NREl_TT->Draw(); NREl_WJ100->Draw("same"); NREl_DY->Draw("same"); NREl_QCD100->Draw("same"); NREl_DEC->Draw("same"); newratioEl->Draw("same"); leg_El->Draw("same"); c1->SaveAs("FakeRatePlots/FakeRate_All_El_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_All_El_Eta.png"); NRMu_TT->GetYaxis()->SetRangeUser(0,1); NRMu_TT->SetLineColor(kBlue); NRMu_WJ100->SetLineColor(kGreen); NRMu_DY->SetLineColor(kViolet); NRMu_QCD100->SetLineColor(kRed); NRMu_DEC->SetLineColor(kBlack); newratioMu->SetLineColor(kBlack); newratioMu->SetLineStyle(5); leg_Mu = new TLegend(0.9-0.38,0.1,0.9,0.1+0.2); leg_Mu->AddEntry(NREl_TT,"top","lep"); leg_Mu->AddEntry(NREl_WJ100,"W","lep"); leg_Mu->AddEntry(NREl_DY,"DY","lep"); leg_Mu->AddEntry(NREl_QCD100,"QCD","lep"); leg_Mu->AddEntry(NREl_DEC,"Data","lep"); leg_Mu->AddEntry(newratioEl,"Data (subtracted)","lep"); NRMu_TT->Draw(); NRMu_WJ100->Draw("same"); NRMu_DY->Draw("same"); NRMu_QCD100->Draw("same"); NRMu_DEC->Draw("same"); newratioMu->Draw("same"); leg_Mu->Draw("same"); c1->SaveAs("FakeRatePlots/FakeRate_All_Mu_Eta.C"); c1->SaveAs("FakeRatePlots/FakeRate_All_Mu_Eta.png"); for(int i = 1; i < NREl_WJ100->GetNbinsX()+1; i++){ for(int j = 1; j < NREl_WJ100->GetNbinsY()+1; j++){ cout << "---------------------------------------------------------------" << endl; cout << "Pt = " << NREl_WJ100->GetXaxis()->GetBinLowEdge(i) << " - " << NREl_WJ100->GetXaxis()->GetBinLowEdge(i+1) << ", Eta = " << NREl_WJ100->GetYaxis()->GetBinLowEdge(j) << " - " << NREl_WJ100->GetYaxis()->GetBinLowEdge(j+1) << endl; cout << "WJets El: FR = " << NREl_WJ100->GetBinContent(i,j) << " +/- " << NREl_WJ100->GetBinError(i,j) << ", NT = " << NTEl_WJ100->GetBinContent(i,j) << ", NL = " << NLEl_WJ100->GetBinContent(i,j) << endl; cout << "DY El: FR = " << NREl_DY->GetBinContent(i,j) << " +/- " << NREl_DY->GetBinError(i,j) << ", NT = " << NTEl_DY->GetBinContent(i,j) << ", NL = " << NLEl_DY->GetBinContent(i,j)<< endl; cout << "TT El: FR = " << NREl_TT->GetBinContent(i,j) << " +/- " << NREl_TT->GetBinError(i,j) << ", NT = " << NTEl_TT->GetBinContent(i,j) << ", NL = " << NLEl_TT->GetBinContent(i,j)<< endl; cout << "QCD El: FR = " << NREl_QCD100->GetBinContent(i,j) << " +/- " << NREl_QCD100->GetBinError(i,j) << ", NT = " << NTEl_QCD100->GetBinContent(i,j) << ", NL = " << NLEl_QCD100->GetBinContent(i,j)<< endl; cout << "Data El: FR = " << NREl_DEC->GetBinContent(i,j) << " +/- " << NREl_DEC->GetBinError(i,j) << ", NT = " << NTEl_DEC->GetBinContent(i,j) << ", NL = " << NLEl_DEC->GetBinContent(i,j)<< endl; cout << "Data El W/Z/T subtracted: FR = " << newratioEl->GetBinContent(i,j) << " +/- " << newratioEl->GetBinError(i,j) << ", NT = " << newtightEl->GetBinContent(i,j) << ", NL = " << newlooseEl->GetBinContent(i,j) << endl; } } for(int i = 1; i < NRMu_WJ100->GetNbinsX()+1; i++){ for(int j = 1; j < NRMu_WJ100->GetNbinsY()+1; j++){ cout << "---------------------------------------------------------------" << endl; cout << "Pt = " << NRMu_WJ100->GetXaxis()->GetBinLowEdge(i) << " - " << NRMu_WJ100->GetXaxis()->GetBinLowEdge(i+1) << ", Eta = " << NRMu_WJ100->GetYaxis()->GetBinLowEdge(j) << " - " << NRMu_WJ100->GetYaxis()->GetBinLowEdge(j+1) << endl; cout << "WJets Mu: FR = " << NRMu_WJ100->GetBinContent(i,j) << " +/- " << NRMu_WJ100->GetBinError(i,j) << ", NT = " << NTMu_WJ100->GetBinContent(i,j) << ", NL = " << NLMu_WJ100->GetBinContent(i,j) << endl; cout << "DY Mu: FR = " << NRMu_DY->GetBinContent(i,j) << " +/- " << NRMu_DY->GetBinError(i,j) << ", NT = " << NTMu_DY->GetBinContent(i,j) << ", NL = " << NLMu_DY->GetBinContent(i,j)<< endl; cout << "TT Mu: FR = " << NRMu_TT->GetBinContent(i,j) << " +/- " << NRMu_TT->GetBinError(i,j) << ", NT = " << NTMu_TT->GetBinContent(i,j) << ", NL = " << NLMu_TT->GetBinContent(i,j)<< endl; cout << "QCD Mu: FR = " << NRMu_QCD100->GetBinContent(i,j) << " +/- " << NRMu_QCD100->GetBinError(i,j) << ", NT = " << NTMu_QCD100->GetBinContent(i,j) << ", NL = " << NLMu_QCD100->GetBinContent(i,j)<< endl; cout << "Data Mu: FR = " << NRMu_DEC->GetBinContent(i,j) << " +/- " << NRMu_DEC->GetBinError(i,j) << ", NT = " << NTMu_DEC->GetBinContent(i,j) << ", NL = " << NLMu_DEC->GetBinContent(i,j)<< endl; cout << "Data Mu W/Z/T subtracted: FR = " << newratioMu->GetBinContent(i,j) << " +/- " << newratioMu->GetBinError(i,j) << ", NT = " << newtightMu->GetBinContent(i,j) << ", NL = " << newlooseMu->GetBinContent(i,j) << endl; } } cout << "DONE" << endl; }
void bfractionVsCent(char *tagger="discr_ssvHighEff", double workingPoint=2., int fixCL=0, char *taggerName="ssvHighEff", float ptlo=80, float pthi=100, float etalo=0., float etahi=2.) { gStyle->SetOptStat(0); gStyle->SetOptTitle(0); gStyle->SetLabelFont(43,"xyz"); gStyle->SetLabelSize(20,"xyz"); gStyle->SetTitleFont(43,"xyz"); gStyle->SetTitleSize(26,"xyz"); gStyle->SetTitleOffset(1.0,"xy"); gROOT->ForceStyle(1); int doLTJP=1; int doLTCSV=0; const int nBins = 2; double centBin[nBins+1] = {0,30,100}; //const int nBins = 3; //double centBin[nBins+1] = {0,20,50,100}; Double_t bPurMC, bPurData, bEffMC, bEffDataLTJP, bEffDataLTCSV, taggedFracData, bFracMC, bFracData, bFracDataLTJP, bFracDataLTCSV, bFracJPdirect; Double_t bPurMCError, bPurDataError, bEffMCError, bEffDataLTJPError, bEffDataLTCSVError, taggedFracDataError, bFracMCError, bFracDataError, bFracDataLTJPError, bFracDataLTCSVError, bFracJPdirectError; Enumerations numbers; TH1D *hBPurityData = new TH1D("hBPurityData","hBPurityData;Centrality;B-Tagging purity",nBins,centBin); TH1D *hBPurityMC = new TH1D("hBPurityMC","hBPurityMC;Centrality;B-Tagging purity",nBins,centBin); TH1D *hBEfficiencyMC = new TH1D("hBEfficiencyMC","hBEfficiencyMC;Centrality;B-Tagging efficiency",nBins,centBin); TH1D *hBEfficiencyDataLTJP = new TH1D("hBEfficiencyDataLTJP","hBEfficiencyDataLTJP;Centrality;B-Tagging efficiency",nBins,centBin); TH1D *hBEfficiencyDataLTCSV = new TH1D("hBEfficiencyDataLTCSV","hBEfficiencyDataLTCSV;Centrality;B-Tagging efficiency",nBins,centBin); TH1D *hBFractionMC = new TH1D("hBFractionMC","hBFractionMC;Centrality;B-jet fraction",nBins,centBin); TH1D *hBFractionData = new TH1D("hBFractionData","hBFractionData;Centrality;B-jet fraction",nBins,centBin); TH1D *hBFractionDataLTJP = new TH1D("hBFractionDataLTJP","hBFractionDataLTJP;Centrality;B-jet fraction",nBins,centBin); TH1D *hBFractionDataLTCSV = new TH1D("hBFractionDataLTCSV","hBFractionDataLTCSV;Centrality;B-jet fraction",nBins,centBin); TH1D *hBFractionJPdirect = new TH1D("hBFractionJPdirect","hBFractionJPdirect;Centrality;B-jet fraction",nBins,centBin); int ncol=1; int nrow=1; if(nBins==3||nBins==2){ ncol=nBins; } if(nBins==4){ ncol=nBins/2; nrow=nBins/2; } TCanvas *c1=new TCanvas("c1","c1",1200,600); //c1->Divide(ncol,nrow,0,0); c1->Divide(ncol,nrow); TCanvas *c2=new TCanvas("c2","c2",1200,600); //c2->Divide(ncol,nrow,0,0); c2->Divide(ncol,nrow); TCanvas *c3=new TCanvas("c3","c3",1200,600); //c3->Divide(ncol,nrow,0,0); c3->Divide(ncol,nrow); TCanvas *c4=new TCanvas("c4","c4",1200,600); //c4->Divide(ncol,nrow,0,0); c4->Divide(ncol,nrow); TCanvas *cCount = new TCanvas("cCount","cCount",600,600); for (int n=0;n<nBins;n++) { cout<<"Processing jet centrality bin ["<<centBin[n]<<","<<centBin[n+1]<<"] ..."<<endl; cCount->cd(); cout<<"centBin[n]: "<<centBin[n]<<" centBin[n+1]: "<<centBin[n+1]<<" tagger: "<<tagger<<" workingPoint: "<<workingPoint<<" ptlo: "<<ptlo<<" pthi: "<<pthi<<" etalo: "<<etalo<<" etahi: "<<etahi<<endl; numbers = count(centBin[n],centBin[n+1],tagger,workingPoint,ptlo,pthi,etalo,etahi); c1->cd(n+1); c1->GetPad(n+1)->SetLogy(); RooRealVar fitSvtxmTag = bfractionFit(fixCL,"svtxm",0,6,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,tagger,workingPoint,6,"b-tagged sample (SSVHE > 2)",9e3); //RooRealVar fitSvtxmTag = bfractionFit(fixCL,"svtxm",0,6,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,tagger,workingPoint,10,Form("b-tagged sample (%s at %.1f)",taggerName,workingPoint)); //RooRealVar fitJpDirect = bfractionFit(fixCL,"discr_prob",0,3,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,tagger,-2,10,"inclusive sample",5e4); c2->cd(n+1); c2->GetPad(n+1)->SetLogy(); RooRealVar fitJpDirect = bfractionFit(fixCL,"discr_prob",0.0,3.,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,"discr_prob",0.,3.,"inclusive sample",4e5); if (doLTJP) { c3->cd(n+1); c3->GetPad(n+1)->SetLogy(); RooRealVar fitJpBeforetag = bfractionFit(fixCL,"discr_prob",0.0,3.,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,"discr_prob",0,3.,"jets with JP info",4e5); c4->cd(n+1); c4->GetPad(n+1)->SetLogy(); RooRealVar fitJpTag = bfractionFit(fixCL,"discr_prob",0.0,3.,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,tagger,workingPoint,6,"b-tagged sample (SSVHE > 2)",4e5); } if (doLTCSV) { RooRealVar fitCsvBeforetag = bfractionFit(fixCL,"discr_csvSimple",0,1,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,tagger,-2,10,"jets with CSV info",4e5); RooRealVar fitCsvTag = bfractionFit(fixCL,"discr_csvSimple",0,1,centBin[n],centBin[n+1],ptlo,pthi,etalo,etahi,tagger,workingPoint,10,"b-tagged sample (SSVHE > 2)",4e5); } taggedFracData = numbers.nTaggedJetsData / (numbers.nTaggedJetsData+numbers.nUntaggedJetsData); taggedFracDataError = fracError(numbers.nTaggedJetsData,numbers.nUntaggedJetsData,numbers.nTaggedJetsDataError,numbers.nUntaggedJetsDataError); //* --- b-tagging purity --- bPurMC = numbers.nTaggedBjetsMC / numbers.nTaggedJetsMC; cout<<" bPurMC "<<bPurMC<<" numbers.nTaggedBjetsMC "<<numbers.nTaggedBjetsMC<<" numbers.nTaggedJetsMC "<<numbers.nTaggedJetsMC<<endl; bPurMCError = fracError(numbers.nTaggedBjetsMC,numbers.nTaggedNonBjetsMC,numbers.nTaggedBjetsMCError,numbers.nTaggedNonBjetsMCError); bPurData = fitSvtxmTag.getVal(); bPurDataError = fitSvtxmTag.getError(); hBPurityMC->SetBinContent(n+1,bPurMC); hBPurityMC->SetBinError(n+1,bPurMCError); hBPurityData->SetBinContent(n+1,bPurData); hBPurityData->SetBinError(n+1,bPurDataError); //*/ //* --- b-tagging efficiency --- bEffMC = numbers.nTaggedBjetsMC / numbers.nBjetsMC; bEffMCError = fracError(numbers.nTaggedBjetsMC,numbers.nUntaggedBjetsMC,numbers.nTaggedBjetsMCError,numbers.nUntaggedBjetsMCError); 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 = fracError(numbers.nBjetsMC,numbers.nNonBjetsMC,numbers.nBjetsMCError,numbers.nNonBjetsMCError); 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 = fitJpDirect.getVal(); bFracJPdirectError = fitJpDirect.getError(); hBFractionJPdirect->SetBinContent(n+1,bFracJPdirect); hBFractionJPdirect->SetBinError(n+1,bFracJPdirectError); //*/ //* cout<<"nTaggedJetsMC "<<numbers.nTaggedJetsMC<<endl; cout<<"nUntaggedJetsMC "<<numbers.nUntaggedJetsMC<<endl; cout<<"nJetsMC "<<numbers.nJetsMC<<endl; cout<<"nTaggedBjetsMC "<<numbers.nTaggedBjetsMC<<endl; cout<<"nUntaggedBjetsMC "<<numbers.nUntaggedBjetsMC<<endl; cout<<"nBjetsMC "<<numbers.nBjetsMC<<endl; cout<<"nNonBjetsMC "<<numbers.nNonBjetsMC<<endl; cout<<"nTaggedNonBjetsMC "<<numbers.nTaggedNonBjetsMC<<endl; cout<<"nTaggedJetsData "<<numbers.nTaggedJetsData<<endl; cout<<"nUntaggedJetsData "<<numbers.nUntaggedJetsData<<endl; cout<<"bPurMC "<<bPurMC<<endl; cout<<"bPurData "<<bPurData<<endl; cout<<"bEffMC "<<bEffMC<<endl; cout<<"CbForJP "<<numbers.cbForJP<<endl; cout<<"bEffDataLTJP "<<bEffDataLTJP<<endl; cout<<"CbForCSV "<<numbers.cbForCSV<<endl; cout<<"bEffDataLTCSV "<<bEffDataLTCSV<<endl; cout<<"bFracMC "<<bFracMC<<endl; cout<<"bFracData "<<bFracData<<endl; cout<<"bFracDataLTJP "<<bFracDataLTJP<<endl; cout<<"bFracDataLTCSV "<<bFracDataLTCSV<<endl; cout<<"bFracJPdirect "<<bFracJPdirect<<endl; cout<<endl; //*/ } TLegend *legPur = new TLegend(0.4,0.15,0.85,0.3,Form("Purity of b-tagged sample (%s at %.1f)",taggerName,workingPoint)); legPur->SetBorderSize(0); //legPur->SetFillColor(kGray); legPur->SetFillStyle(0); legPur->AddEntry(hBPurityMC,"MC Input","pl"); legPur->AddEntry(hBPurityData,"Data","pl"); TCanvas *cBPurity = new TCanvas("cBPurity","b purity",600,600); hBPurityMC->SetAxisRange(0,1,"Y"); hBPurityMC->SetTitleOffset(1.3,"Y"); hBPurityMC->SetLineColor(2); hBPurityMC->SetMarkerColor(2); hBPurityMC->SetMarkerStyle(21); hBPurityMC->Draw(); hBPurityData->SetLineColor(1); hBPurityData->SetMarkerColor(1); hBPurityData->SetMarkerStyle(20); hBPurityData->Draw("same"); legPur->Draw(); //cBPurity->SaveAs("purity.gif"); TLegend *legEff = new TLegend(0.4,0.65,0.85,0.8,Form("Efficiency for tagging b-jets (%s at %.1f)",taggerName,workingPoint)); legEff->SetBorderSize(0); //legEff->SetFillColor(kGray); legEff->SetFillStyle(0); legEff->AddEntry(hBEfficiencyMC,"MC Efficiency","pl"); if (doLTJP) legEff->AddEntry(hBEfficiencyDataLTJP,"LT method (JP)","pl"); if (doLTCSV) legEff->AddEntry(hBEfficiencyDataLTCSV,"LT method (CSV)","pl"); TCanvas *cBEfficiency = new TCanvas("cBEfficiency","B-Tagging efficiency",600,600); hBEfficiencyMC->SetAxisRange(0,1,"Y"); hBEfficiencyMC->SetTitleOffset(1.3,"Y"); hBEfficiencyMC->SetLineColor(2); hBEfficiencyMC->SetMarkerColor(2); hBEfficiencyMC->SetMarkerStyle(21); hBEfficiencyMC->Draw(); if (doLTJP) { hBEfficiencyDataLTJP->SetLineColor(8); hBEfficiencyDataLTJP->SetMarkerColor(8); hBEfficiencyDataLTJP->SetMarkerStyle(20); hBEfficiencyDataLTJP->Draw("same"); } if (doLTCSV) { hBEfficiencyDataLTCSV->SetLineColor(7); hBEfficiencyDataLTCSV->SetMarkerColor(7); hBEfficiencyDataLTCSV->SetMarkerStyle(20); hBEfficiencyDataLTCSV->Draw("same"); } legEff->Draw(); //cBEfficiency->SaveAs("efficiency.gif"); TLegend *legFrac = new TLegend(0.25,0.15,0.85,0.3); legFrac->SetBorderSize(0); //legFrac->SetFillColor(kGray); legFrac->SetFillStyle(0); legFrac->AddEntry(hBFractionMC,"MC Input","pl"); legFrac->AddEntry(hBFractionData,Form("%s at %.1f + pur. from SV mass + eff. from MC",taggerName,workingPoint),"pl"); if (doLTJP) legFrac->AddEntry(hBFractionDataLTJP,Form("%s at %.1f + pur. from SV mass + eff. from LT (JP)",taggerName,workingPoint),"pl"); if (doLTCSV) legFrac->AddEntry(hBFractionDataLTCSV,Form("%s at %.1f + pur. from SV mass + eff. from LT (CSV)",taggerName,workingPoint),"pl"); legFrac->AddEntry(hBFractionJPdirect,"Direct fit to JP","pl"); TCanvas *cBFraction = new TCanvas("cBFraction","B-jet fraction",600,600); hBFractionMC->SetAxisRange(0,0.03,"Y"); hBFractionMC->SetTitleOffset(1.8,"Y"); hBFractionMC->SetLineColor(2); hBFractionMC->SetMarkerColor(2); hBFractionMC->SetMarkerStyle(21); hBFractionMC->Draw(); hBFractionData->SetLineColor(1); hBFractionData->SetMarkerColor(1); hBFractionData->SetMarkerStyle(20); hBFractionData->Draw("same"); if (doLTJP) { hBFractionDataLTJP->SetLineColor(8); hBFractionDataLTJP->SetMarkerColor(8); hBFractionDataLTJP->SetMarkerStyle(20); hBFractionDataLTJP->Draw("same"); } if (doLTCSV) { hBFractionDataLTCSV->SetLineColor(7); hBFractionDataLTCSV->SetMarkerColor(7); hBFractionDataLTCSV->SetMarkerStyle(20); hBFractionDataLTCSV->Draw("same"); } hBFractionJPdirect->SetLineColor(4); hBFractionJPdirect->SetMarkerColor(4); hBFractionJPdirect->SetMarkerStyle(20); hBFractionJPdirect->Draw("same"); legFrac->Draw(); //cBFraction->SaveAs("bfraction.gif"); TFile *fout = new TFile(Form("output/bFractionMerged_%sat%.1fFixCL%d_centDep.root",taggerName,workingPoint,fixCL),"recreate"); hBFractionMC->Write(); hBFractionData->Write(); if (doLTJP) hBFractionDataLTJP->Write(); if (doLTCSV) hBFractionDataLTCSV->Write(); hBFractionJPdirect->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 compIsol(int varnum) { TString varname, vartitle; if(varnum==1) { varname="hHEIsoPt"; vartitle="H/E Isolation"; } if(varnum==2) { varname="hHcalIsoPt"; vartitle="HCAL Isolation"; } if(varnum==3) { varname="hEcalIsoPt"; vartitle="ECAL Isolation"; } if(varnum==4) { varname="hTrkIsoPt"; vartitle="Track Isolation"; } if(varnum==5) { varname="hJetEt"; vartitle="Jet E_{T} [GeV]"; } if(varnum==6) { varname="hNJets"; vartitle="Number of Jets"; } TH1D* hBorn; TH1D* hADD; if(varnum<=4) { TH2D* hBorn2d = dynamic_cast<TH2D*>(GetPlot(1, varname)); TH2D* hADD2d = dynamic_cast<TH2D*>(GetPlot(3, varname)); hBorn = hBorn2d->ProjectionX(varname+"born"); hADD = hADD2d->ProjectionX(varname+"add"); cout << "asdf" << endl; } else { hBorn = dynamic_cast<TH1D*>(GetPlot(1, varname)); hADD = dynamic_cast<TH1D*>(GetPlot(3, varname)); } hBorn->Scale(1/hBorn->GetSumOfWeights()); hADD->Scale(1/hADD->GetSumOfWeights()); hBorn->SetLineColor(kBlue+2); hADD->SetLineColor(kCyan+4); hBorn->SetFillColor(0); hADD->SetFillColor(0); hBorn->SetLineStyle(1); hADD->SetLineStyle(2); // hBorn->SetStats(0); // hADD->SetStats(0); gPad->SetLogy(1); hBorn->GetXaxis()->SetTitle(vartitle); hBorn->GetYaxis()->SetTitle("Normalized Units"); hBorn->SetTitle("Leading Photons in Pythia/Sherpa Samples"); hBorn->Draw(); hADD->Draw("sames"); hBorn->SetMaximum(1); gPad->Update(); TPaveStats *st1=(TPaveStats*)hBorn->GetListOfFunctions()->FindObject("stats"); TPaveStats *st2=(TPaveStats*)hADD->GetListOfFunctions()->FindObject("stats"); st1->SetName("Born"); st2->SetName("ADD"); st1->SetOptStat(101100); st2->SetOptStat(101100); st1->SetX1NDC(.25); st1->SetX2NDC(.55); st1->SetY1NDC(.56); st1->SetY2NDC(.80); st2->SetX1NDC(.56); st2->SetX2NDC(.86); st2->SetY1NDC(.56); st2->SetY2NDC(.80); TLegend* leg=new TLegend(.25,.78,.55,.85); leg->AddEntry(hBorn, "Pythia (Born)", "l"); leg->SetBorderSize(0); leg->SetFillColor(0); leg->SetTextSize(0.045); leg->Draw(); TLegend* leg=new TLegend(.56,.78,.86,.85); leg->AddEntry(hADD, "Sherpa (ADD)", "l"); leg->SetBorderSize(0); leg->SetFillColor(0); leg->SetTextSize(0.045); leg->Draw(); gPad->Update(); return; }
TH1D* readData(TString dataset, TString name, TString wavel, Double_t peak1, Double_t peak2, Double_t intTime, Double_t shift){ TString fileName = "./Data/" + dataset + ".txt"; Double_t histoMin = 99999, histoMax = 0; ifstream ifs(fileName); if(!ifs.is_open()){cout << "Error. File " << fileName << " not found. Exiting...\n"; return NULL;} Double_t entry, wavelength, photons, stepsize; while(ifs >> entry >> wavelength >> photons){ if(entry == 1) stepsize = wavelength; else if(entry == 2) stepsize = wavelength - stepsize; if(wavelength < histoMin) histoMin = wavelength; if(wavelength > histoMax) histoMax = wavelength; } ifs.close(); TH1D *histo = new TH1D(name + wavel + TString::Format(" %1.2f", shift), name + wavel + TString::Format(" %1.2f", shift), Nint(entry), histoMin + shift - stepsize/2.0, histoMax + shift + stepsize/2.0); ifs.open(fileName); if(!ifs.is_open()){cout << "Error. File " << fileName << " not found. Exiting...\n"; return NULL;} while(ifs >> entry >> wavelength >> photons){ for(Int_t x = 0; x< photons/(1000.0/intTime); x++){ histo->Fill(wavelength + shift); } } ifs.close(); TF1 *f; if(peak2 == 0.){ f = new TF1("fit", "[0]+[1]*TMath::Voigt(x-[2],[3],[4])"); f->SetParameter(0, histo->GetMinimum()); f->SetParameter(1, histo->GetMaximum()/25.); f->SetParameter(2, peak1 + shift); f->SetParameter(3, .02); f->SetParameter(4, .02); f->SetParName(0, "Offset"); f->SetParName(1, "Normalization"); f->SetParName(2, "Mean"); f->SetParName(3, "Sigma"); f->SetParName(4, "Gamma"); } else{ f = new TF1("fit", "[0]+[1]*TMath::Voigt(x-[2],[3],[4])+[5]*TMath::Voigt(x-[6],[7],[8])"); f->SetParameter(0, histo->GetMinimum()); f->SetParameter(1, histo->GetMaximum()/20.); f->SetParameter(2, peak1+shift-0.1); f->SetParameter(3, .02); f->SetParameter(4, .02); f->SetParameter(5, histo->GetMaximum()/20.); f->SetParameter(6, peak2+shift+0.1); f->SetParameter(7, .02); f->SetParameter(8, .02); f->SetParName(0, "Offset"); f->SetParName(1, "Normalization 1"); f->SetParName(2, "Mean 1"); f->SetParName(3, "Sigma 1"); f->SetParName(4, "Gamma 1"); f->SetParName(5, "Normalization 2"); f->SetParName(6, "Mean 2"); f->SetParName(7, "Sigma 2"); f->SetParName(8, "Gamma 2"); } histo->SetLineWidth(2); histo->SetMarkerStyle(20); histo->SetMarkerSize(1.5); histo->SetMarkerColor(kRed); histo->SetLineColor(kBlack); histo->GetXaxis()->SetTitle("Wavelength (#AA)"); histo->GetXaxis()->CenterTitle(); histo->GetXaxis()->SetTitleSize(0.045); histo->GetXaxis()->SetTitleOffset(1.00); histo->GetXaxis()->SetLabelOffset(0.010); histo->GetXaxis()->SetLabelSize(0.045); histo->GetYaxis()->SetTitle("Photon count"); histo->GetYaxis()->CenterTitle(); histo->GetYaxis()->SetTitleSize(0.050); histo->GetYaxis()->SetTitleOffset(0.95); histo->GetYaxis()->SetLabelSize(0.045); gStyle->SetTitleSize(0.070, "t"); if(peak2 == 0.) histo->SetTitle(name + TString::Format(" %4.2f #AA", f->GetParameter(2))); else histo->SetTitle(name + TString::Format(" %4.2f / %4.2f #AA", f->GetParameter(2), f->GetParameter(6))); //histo->SetTitle("Sodium 5890.522 / 5890.567 #AA"); cout << shift << endl; f->SetLineColor(kBlue); f->SetLineWidth(4); cout << "Fitting " << name << endl; histo->Fit(f, "ME"); return histo; }
void MuScale() { //-------------------------------------------------------------------------------------------------------------- // Settings //============================================================================================================== // event category enumeration enum { eMuMu2HLT=1, eMuMu1HLT1L1, eMuMu1HLT, eMuMuNoSel, eMuSta, eMuTrk }; // event category enum TString outputDir = "MuScaleResults"; vector<TString> infilenamev; infilenamev.push_back("/afs/cern.ch/work/c/cmedlock/public/wz-ntuples/Zmumu/ntuples/data_select.trkCuts.root"); // data infilenamev.push_back("/afs/cern.ch/work/c/cmedlock/public/wz-ntuples/Zmumu/ntuples/zmm_select.raw.trkCuts.root"); // MC const Double_t MASS_LOW = 60; const Double_t MASS_HIGH = 120; const Double_t PT_CUT = 25; const Double_t ETA_CUT = 2.4; const Double_t MU_MASS = 0.105658369; vector<pair<Double_t,Double_t> > scEta_limits; scEta_limits.push_back(make_pair(0.0,1.2)); scEta_limits.push_back(make_pair(1.2,2.1)); scEta_limits.push_back(make_pair(2.1,2.4)); CPlot::sOutDir = outputDir; const TString format("png"); //-------------------------------------------------------------------------------------------------------------- // Main analysis code //============================================================================================================== enum { eData=0, eMC }; char hname[100]; vector<TH1D*> hMCv, hDatav; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) { sprintf(hname,"mc_%i_%i",ibin,jbin); hMCv.push_back(new TH1D(hname,"",80,MASS_LOW,MASS_HIGH)); hMCv.back()->Sumw2(); sprintf(hname,"data_%i_%i",ibin,jbin); hDatav.push_back(new TH1D(hname,"",80,MASS_LOW,MASS_HIGH)); hDatav.back()->Sumw2(); } } // // Declare output ntuple variables // UInt_t runNum, lumiSec, evtNum; Float_t scale1fb, puWeight; UInt_t matchGen; UInt_t category; UInt_t npv, npu; Int_t q1, q2; TLorentzVector *dilep=0, *lep1=0, *lep2=0; for(UInt_t ifile=0; ifile<infilenamev.size(); ifile++) { cout << "Processing " << infilenamev[ifile] << "..." << endl; TFile *infile = TFile::Open(infilenamev[ifile]); assert(infile); TTree *intree = (TTree*)infile->Get("Events"); assert(intree); intree->SetBranchAddress("runNum", &runNum); // event run number intree->SetBranchAddress("lumiSec", &lumiSec); // event lumi section intree->SetBranchAddress("evtNum", &evtNum); // event number intree->SetBranchAddress("scale1fb", &scale1fb); // event weight intree->SetBranchAddress("puWeight", &puWeight); // pileup reweighting intree->SetBranchAddress("matchGen", &matchGen); // event has both leptons matched to MC Z->ll intree->SetBranchAddress("category", &category); // dilepton category intree->SetBranchAddress("npv", &npv); // number of primary vertices intree->SetBranchAddress("npu", &npu); // number of in-time PU events (MC) intree->SetBranchAddress("q1", &q1); // charge of lead lepton intree->SetBranchAddress("q2", &q2); // charge of trail lepton intree->SetBranchAddress("dilep", &dilep); // dilepton 4-vector intree->SetBranchAddress("lep1", &lep1); // lead lepton 4-vector intree->SetBranchAddress("lep2", &lep2); // trail lepton 4-vector for(UInt_t ientry=0; ientry<intree->GetEntries(); ientry++) { intree->GetEntry(ientry); Double_t weight = 1; if(ifile==eMC) { //if(!matchGen) continue; weight=scale1fb*puWeight*1.1*TMath::Power(10,7)/5610.0; } if((category!=eMuMu2HLT) && (category!=eMuMu1HLT) && (category!=eMuMu1HLT1L1)) continue; if(q1 == q2) continue; if(dilep->M() < MASS_LOW) continue; if(dilep->M() > MASS_HIGH) continue; if(lep1->Pt() < PT_CUT) continue; if(lep2->Pt() < PT_CUT) continue; if(fabs(lep1->Eta()) > ETA_CUT) continue; if(fabs(lep2->Eta()) > ETA_CUT) continue; TLorentzVector vLep1(0,0,0,0); TLorentzVector vLep2(0,0,0,0); vLep1.SetPtEtaPhiM(lep1->Pt(), lep1->Eta(), lep1->Phi(), MU_MASS); vLep2.SetPtEtaPhiM(lep2->Pt(), lep2->Eta(), lep2->Phi(), MU_MASS); TLorentzVector vDilep = vLep1 + vLep2; Int_t bin1=-1, bin2=-1; for(UInt_t i=0; i<scEta_limits.size(); i++) { Double_t etalow = scEta_limits.at(i).first; Double_t etahigh = scEta_limits.at(i).second; if(fabs(lep1->Eta())>=etalow && fabs(lep1->Eta())<=etahigh) bin1=i; if(fabs(lep2->Eta())>=etalow && fabs(lep2->Eta())<=etahigh) bin2=i; } assert(bin1>=0); assert(bin2>=0); Int_t ibin= (bin1<=bin2) ? bin1 : bin2; Int_t jbin= (bin1<=bin2) ? bin2 : bin1; UInt_t n=jbin-ibin; for(Int_t k=0; k<ibin; k++) n+=(scEta_limits.size()-k); if(ifile==eData) hDatav[n]->Fill(vDilep.M(),weight); if(ifile==eMC) hMCv[n]->Fill(vDilep.M(),weight); } delete infile; infile=0, intree=0; } // // Fit for energy scale and resolution corrections // char vname[100]; // buffer for RooFit object names char pname[100]; char str1[100]; char str2[100]; TCanvas *c = MakeCanvas("c","c",800,600); // Dummy histograms for TLegend (I can't figure out how to properly pass RooFit objects...) TH1D *hDummyData = new TH1D("hDummyData","",0,0,10); hDummyData->SetMarkerStyle(kFullCircle); hDummyData->SetMarkerSize(0.9); TH1D *hDummyMC = new TH1D("hDummyMC","",0,0,10); hDummyMC->SetLineColor(kBlue); hDummyMC->SetFillColor(kBlue); hDummyMC->SetFillStyle(3002); TH1D *hDummyFit = new TH1D("hDummyFit","",0,0,10); hDummyFit->SetLineColor(kGreen+2); RooRealVar mass("mass","M_{#mu#mu}",60.0,120.0,"GeV") ; mass.setBins(1600,"cache"); RooRealVar massmc("massmc","massmc",0.0,150.0,"GeV"); // mass variable for building MC template RooCategory zscEta_cat("zscEta_cat","zscEta_cat"); RooSimultaneous combscalefit("combscalefit","combscalefit",zscEta_cat); map<string,TH1*> hmap; // Mapping of category labels and data histograms RooArgList scalebins; // List of RooRealVars storing per bin energy scale corrections RooArgList sigmabins; // List of RooRealVars storing per bin energy resolution corrections Int_t intOrder = 1; // Interpolation order for for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { sprintf(vname,"scale_%i",ibin); RooRealVar *scalebinned = new RooRealVar(vname,vname,1.0,0.5,1.5); scalebins.add(*scalebinned); sprintf(vname,"sigma_%i",ibin); RooRealVar *sigmabinned = new RooRealVar(vname,vname,1.0,0.0,2.0); sigmabins.add(*sigmabinned); } for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) { UInt_t n=jbin-ibin; for(UInt_t k=0; k<ibin; k++) n+=(scEta_limits.size()-k); sprintf(vname,"masslinearshifted_%i_%i",ibin,jbin); RooFormulaVar *masslinearshifted = new RooFormulaVar(vname,vname,"sqrt(@0*@1)",RooArgList(*scalebins.at(ibin),*scalebins.at(jbin))); sprintf(vname,"massshiftedscEta_%i_%i",ibin,jbin); RooLinearVar *massshiftedscEta = new RooLinearVar(vname,vname,mass,*masslinearshifted,RooConst(0.0)); // MC-based template sprintf(vname,"zmassmcscEta_%i_%i",ibin,jbin); RooDataHist *zmassmcscEta = new RooDataHist(vname,vname,RooArgList(massmc),hMCv[n]); sprintf(vname,"masstemplatescEta_%i_%i",ibin,jbin); RooHistPdf *masstemplatescEta = new RooHistPdf(vname,vname,RooArgList(*massshiftedscEta),RooArgList(massmc),*zmassmcscEta,intOrder); // Gaussian smearing function sprintf(vname,"sigmascEta_%i_%i",ibin,jbin); RooFormulaVar *sigmascEta = new RooFormulaVar(vname,vname,"sqrt(@0*@0+@1*@1)",RooArgList(*sigmabins.at(ibin),*sigmabins.at(jbin))); sprintf(vname,"resscEta_%i_%i",ibin,jbin); RooGaussian *resscEta = new RooGaussian(vname,vname,mass,RooConst(0.),*sigmascEta); // Fit model: MC-template convoluted with Gaussian sprintf(vname,"fftscEta_%i_%i",ibin,jbin); RooFFTConvPdf *fftscEta = new RooFFTConvPdf(vname,vname,mass,*masstemplatescEta,*resscEta); fftscEta->setBufferStrategy(RooFFTConvPdf::Flat); // Add bin as a category char zscEta_catname[100]; sprintf(zscEta_catname,"zscEta_cat_%i_%i",ibin,jbin); zscEta_cat.defineType(zscEta_catname); zscEta_cat.setLabel(zscEta_catname); hmap.insert(pair<string,TH1*>(zscEta_catname,hDatav[n])); combscalefit.addPdf(*fftscEta,zscEta_catname); } } // perform fit RooDataHist zdatascEta_comb("zdatascEta_comb","zdatascEta_comb",RooArgList(mass),zscEta_cat,hmap,1.0); combscalefit.fitTo(zdatascEta_comb,PrintEvalErrors(kFALSE),Minos(kFALSE),Strategy(0),Minimizer("Minuit2","")); Double_t xval[scEta_limits.size()]; Double_t xerr[scEta_limits.size()]; Double_t scaleDatatoMC[scEta_limits.size()]; Double_t scaleDatatoMCerr[scEta_limits.size()]; Double_t scaleMCtoData[scEta_limits.size()]; Double_t scaleMCtoDataerr[scEta_limits.size()]; Double_t sigmaMCtoData[scEta_limits.size()]; Double_t sigmaMCtoDataerr[scEta_limits.size()]; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { Double_t etalow = scEta_limits.at(ibin).first; Double_t etahigh = scEta_limits.at(ibin).second; xval[ibin] = 0.5*(etahigh+etalow); xerr[ibin] = 0.5*(etahigh-etalow); scaleDatatoMC[ibin] = ((RooRealVar*)scalebins.at(ibin))->getVal(); scaleDatatoMCerr[ibin] = ((RooRealVar*)scalebins.at(ibin))->getError(); scaleMCtoData[ibin] = 1.0/scaleDatatoMC[ibin]; scaleMCtoDataerr[ibin] = scaleDatatoMCerr[ibin]/scaleDatatoMC[ibin]/scaleDatatoMC[ibin]; sigmaMCtoData[ibin] = ((RooRealVar*)sigmabins.at(ibin))->getVal(); sigmaMCtoDataerr[ibin] = ((RooRealVar*)sigmabins.at(ibin))->getError(); } TGraphErrors *grScaleDatatoMC = new TGraphErrors(scEta_limits.size(),xval,scaleDatatoMC,xerr,scaleDatatoMCerr); TGraphErrors *grScaleMCtoData = new TGraphErrors(scEta_limits.size(),xval,scaleMCtoData,xerr,scaleMCtoDataerr); TGraphErrors *grSigmaMCtoData = new TGraphErrors(scEta_limits.size(),xval,sigmaMCtoData,xerr,sigmaMCtoDataerr); CPlot plotScale1("mu_scale_datatomc","","Muon |#eta|","Data scale correction"); plotScale1.AddGraph(grScaleDatatoMC,"",kBlue); plotScale1.SetYRange(0.98,1.02); plotScale1.AddLine(0,1,2.5,1,kBlack,7); plotScale1.Draw(c,kTRUE,format); CPlot plotScale2("mu_scale_mctodata","","Muon |#eta|","MC#rightarrowData scale correction"); plotScale2.AddGraph(grScaleMCtoData,"",kBlue); plotScale2.SetYRange(0.98,1.02); plotScale2.AddLine(0,1,2.5,1,kBlack,7); plotScale2.Draw(c,kTRUE,format); CPlot plotRes("mu_res_mctodata","","Muon |#eta|","MC#rightarrowData additional smear [GeV]"); plotRes.AddGraph(grSigmaMCtoData,"",kBlue); plotRes.SetYRange(0,1.6); plotRes.Draw(c,kTRUE,format); double nData=0; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { for(UInt_t jbin=ibin; jbin<scEta_limits.size(); jbin++) { UInt_t n=jbin-ibin; for(UInt_t k=0; k<ibin; k++) n+=(scEta_limits.size()-k); // Post-fit plot RooPlot *frame = mass.frame(); char catname[100]; sprintf(catname,"zscEta_cat_%i_%i",ibin,jbin); char cutstr[100]; sprintf(cutstr,"zscEta_cat==zscEta_cat::%s",catname); RooDataHist zmc(catname,catname,RooArgList(mass),hMCv[n]); RooHistPdf mctemplate(catname,catname,RooArgList(mass),zmc,intOrder); //mctemplate.plotOn(frame,LineColor(kBlue),LineWidth(1),Normalization(hDatav[n]->GetEntries())); mctemplate.plotOn(frame,LineColor(kBlue),LineWidth(1),Normalization(hDatav[n]->Integral())); //mctemplate.plotOn(frame,LineColor(kBlue),FillColor(kBlue),FillStyle(3002),DrawOption("F"),Normalization(hDatav[n]->GetEntries())); mctemplate.plotOn(frame,LineColor(kBlue),FillColor(kBlue),FillStyle(3002),DrawOption("F"),Normalization(hDatav[n]->Integral())); zdatascEta_comb.plotOn(frame,Cut(cutstr),MarkerStyle(kFullCircle),MarkerSize(1.0),DrawOption("ZP")); combscalefit.plotOn(frame,Slice(zscEta_cat,catname),ProjWData(RooArgSet(mass,catname),zdatascEta_comb), LineColor(kGreen+2)); sprintf(pname,"postfit_%i_%i",ibin,jbin); sprintf(str1,"[%.1f, %.1f]",scEta_limits.at(ibin).first,scEta_limits.at(ibin).second); sprintf(str2,"[%.1f, %.1f]",scEta_limits.at(jbin).first,scEta_limits.at(jbin).second); CPlot plot(pname,frame,"","m(#mu^{+}#mu^{-}) [GeV/c^{2}]","Events / 0.6 GeV/c^{2}"); plot.AddTextBox(str1,0.21,0.80,0.45,0.87,0,kBlack,-1); plot.AddTextBox(str2,0.21,0.73,0.45,0.80,0,kBlack,-1); plot.SetLegend(0.75,0.64,0.93,0.88); plot.GetLegend()->AddEntry(hDummyData,"Data","PL"); plot.GetLegend()->AddEntry(hDummyMC,"Sim","FL"); plot.GetLegend()->AddEntry(hDummyFit,"Fit","L"); plot.Draw(c,kTRUE,format); nData += hDatav[n]->Integral(); } } cout<<"nData = "<<nData<<endl; //-------------------------------------------------------------------------------------------------------------- // Output //============================================================================================================== cout << "*" << endl; cout << "* SUMMARY" << endl; cout << "*--------------------------------------------------" << endl; cout << endl; ofstream txtfile; char txtfname[100]; sprintf(txtfname,"%s/summary.txt",outputDir.Data()); txtfile.open(txtfname); assert(txtfile.is_open()); txtfile << " Data->MC scale correction" << endl; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { Double_t etalow = scEta_limits.at(ibin).first; Double_t etahigh = scEta_limits.at(ibin).second; txtfile << "$" << etalow << " < |\\eta| < " << etahigh << "$ & "; txtfile << "$" << ((RooRealVar*)scalebins.at(ibin))->getVal() << "$ \\pm $" << ((RooRealVar*)scalebins.at(ibin))->getError() << "$ \\\\" << endl; } txtfile << endl; txtfile << " MC->Data resolution correction [GeV]" << endl; for(UInt_t ibin=0; ibin<scEta_limits.size(); ibin++) { Double_t etalow = scEta_limits.at(ibin).first; Double_t etahigh = scEta_limits.at(ibin).second; txtfile << etalow << " < |\\eta| < " << etahigh << " & "; txtfile << "$" << ((RooRealVar*)sigmabins.at(ibin))->getVal() << "$ \\pm $" << ((RooRealVar*)sigmabins.at(ibin))->getError() << "$ \\\\" << endl; } txtfile.close(); cout << endl; cout << " <> Output saved in " << outputDir << "/" << endl; cout << endl; }
TH1D * GetTPCTOFRatio(TFile *file, Int_t num, Int_t den, Int_t cent, Bool_t cutSpectrum = kTRUE) { /* pt limits for combined spectra */ Double_t ptMin_[9] = { 0.0, 0.0, 0.0, 0., 0., 0., 0.5, 0.5, 0.5 }; Double_t ptMax_[9] = { 1.2, 1.2, 1.2, 1.2, 1.2, 1.2, 1.8, 1.8, 1.8 }; Double_t ptMin = TMath::Max(ptMin_[num], ptMin_[den]); Double_t ptMax = TMath::Min(ptMax_[num], ptMax_[den]); Int_t part = 0, charge = 0; if (num == kPiMinus && den == kPiPlus) { part = AliPID::kPion; charge = 1; } else if (num == kKaMinus && den == kKaPlus) { part = AliPID::kKaon; charge = 1; } else if (num == kPrMinus && den == kPrPlus) { part = AliPID::kProton; charge = 1; } else if (num == kKaMinus && den == kPiMinus) { part = AliPID::kKaon; charge = 1; } else if (num == kKaPlus && den == kPiPlus) { part = AliPID::kKaon; charge = 0; } else if (num == kPrMinus && den == kPiMinus) { part = AliPID::kProton; charge = 1; } else if (num == kPrPlus && den == kPiPlus) { part = AliPID::kProton; charge = 0; } TH1D *hin = (TH1D *)file->Get(Form("%sFinal%s%d", TPCTOFPartName[part], TPCTOFChargeName[charge], cent)); if (!hin) return NULL; TH1D *h = new TH1D(Form("hTPCTOF_cent%d_%s_%s", cent, ratioName[num], ratioName[den]), "TPCTOF", NptBins, ptBin); Double_t pt, width, value, error; Int_t bin; for (Int_t ipt = 0; ipt < NptBins; ipt++) { /* get input bin */ pt = h->GetBinCenter(ipt + 1); width = h->GetBinWidth(ipt + 1); bin = hin->FindBin(pt); /* sanity check */ if (TMath::Abs(hin->GetBinCenter(bin) - pt) > 0.001 || TMath::Abs(hin->GetBinWidth(bin) - width) > 0.001) continue; /* check pt limits */ if (cutSpectrum && (pt < ptMin || pt > ptMax)) continue; /* copy bin */ value = hin->GetBinContent(bin); error = hin->GetBinError(bin); h->SetBinContent(ipt + 1, value); h->SetBinError(ipt + 1, error); } h->SetTitle("TPCTOF"); h->SetLineWidth(1); h->SetLineColor(1); h->SetMarkerStyle(22); h->SetMarkerColor(8); h->SetFillStyle(0); h->SetFillColor(0); return h; }
TH1D * GetTOFRatio(TFile *file, Int_t num, Int_t den, Int_t cent, Bool_t cutSpectrum = kTRUE) { /* pt limits for combined spectra */ Double_t ptMin_[9] = { 0.5, 0.5, 0.5, 0.45, 0.45, 0.45, 0.5, 0.5, 0.5 }; Double_t ptMax_[9] = { 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 4.5, 4.5, 4.5 }; Double_t ptMin = TMath::Max(ptMin_[num], ptMin_[den]); Double_t ptMax = TMath::Min(ptMax_[num], ptMax_[den]); TH1D *hin = (TH1D *)file->Get(Form("hRatio_cent%d_%s_%s", cent, ratioName[num], ratioName[den])); if (!hin) return NULL; #if 0 /* get matching systematics */ TFile *fsys = TFile::Open(Form("MATCHSYS_TOF_%s.root", TOFChargeName[charge])); TH1 *hsys = fsys->Get(Form("hErr%sMatch", ITSsaPartName[part])); TF1 *ffsys = new TF1("fsys", "[0] + [1] * x + [2] * TMath::Exp(-[3] * x)"); ffsys->SetParameter(0, 0.02); ffsys->FixParameter(1, 0.); ffsys->SetParameter(2, 0.5); ffsys->SetParameter(3, 10.); hsys->Fit(ffsys, "W"); ffsys->ReleaseParameter(1); hsys->Fit(ffsys, "W"); hsys->Fit(ffsys, "W"); hsys->Fit(ffsys, "W"); hsys->Draw(); #endif TH1D *h = new TH1D(Form("hTOF_cent%d_%s_%s", cent, ratioName[num], ratioName[den]), "TOF", NptBins, ptBin); Double_t pt, width, value, error, sys; Int_t bin; for (Int_t ipt = 0; ipt < NptBins; ipt++) { /* get input bin */ pt = h->GetBinCenter(ipt + 1); width = h->GetBinWidth(ipt + 1); bin = hin->FindBin(pt); /* sanity check */ if (TMath::Abs(hin->GetBinCenter(bin) - pt) > 0.001 || TMath::Abs(hin->GetBinWidth(bin) - width) > 0.001) continue; /* check pt limits */ if (cutSpectrum && (pt < ptMin || pt > ptMax)) continue; /* copy bin */ value = hin->GetBinContent(bin); error = hin->GetBinError(bin); /*** TEMP ADD SYS ***/ // sys = ffsys->Eval(pt) * value; // error = TMath::Sqrt(error * error + sys * sys); // h->SetBinContent(ipt + 1, value); // h->SetBinError(ipt + 1, error); h->SetBinContent(ipt + 1, value); h->SetBinError(ipt + 1, error); } h->SetTitle("TOF"); h->SetLineWidth(1); h->SetLineColor(1); h->SetMarkerStyle(23); h->SetMarkerColor(4); h->SetFillStyle(0); h->SetFillColor(0); return h; }
void plotphi(int top, bool phi=kFALSE){ if (setup("vm","","pol__")==kFALSE) return; gStyle->SetOptFit(1111); //pcev = 1111 //gStyle->SetTitleW(1.5); int itop = top-1; TFile* fy = _fyexp[itop]; int nq2wbins = fy->GetNkeys(); TIter nextkey(fy->GetListOfKeys()); TKey *key; int iq2wbin = 0; while (key = (TKey*)nextkey()) { TString Q2Wdirname = key->GetName(); if(Q2Wdirname.EqualTo("hYW_Dir") || Q2Wdirname.EqualTo("hYW"))continue; cout << "Q2Wdirname = " << Q2Wdirname << endl; THStack* hs[10]; TF1 *fphi = new TF1("fphi", "([0] + [1]*cos(x*TMath::DegToRad()) + [2]*cos(2*x*TMath::DegToRad()) + [3]*sin(x*TMath::DegToRad()))",0, 360); fphi->SetParameter(0,1); fphi->SetParameter(1,10); fphi->SetParameter(2,20); fphi->SetParameter(3,100); fphi->SetParName(0, "A"); fphi->SetParName(1, "B"); fphi->SetParName(2, "C"); fphi->SetParName(3, "hPR"); for (int i = 0; i < 10; i++) { TString hname_unp = TString::Format("%s/hPhi/Varset1/theta/hphi_%02d",Q2Wdirname.Data(),i+1); TString hname_pos = TString::Format("%s/hPhi_POS/Varset1/theta/hphi_%02d",Q2Wdirname.Data(),i+1); TString hname_neg = TString::Format("%s/hPhi_NEG/Varset1/theta/hphi_%02d",Q2Wdirname.Data(),i+1); cout << "hname_unp = " << hname_unp << endl; cout << "hname_pos = " << hname_pos << endl; cout << "hname_neg = " << hname_neg << endl; TH1D* hunp = (TH1D*)fy->Get(hname_unp); TH1D* hpos = (TH1D*)fy->Get(hname_pos); TH1D* hneg = (TH1D*)fy->Get(hname_neg); if (hunp==NULL || hpos==NULL || hneg==NULL) cout << "histogram not found" << endl; hunp->SetLineColor(kBlack); hpos->SetLineColor(kRed); hneg->SetLineColor(kBlue); hunp->Fit(fphi); hpos->Fit(fphi); hneg->Fit(fphi); //! Modify titles TObjArray *tarr; char t[100]; TPaveText *ptunp = new TPaveText(0.0, 0.9, 1.0, 1, "NDC"); TString tunp = hunp->GetTitle(); tarr = tunp.Tokenize("|"); sprintf(t, "%s:%s:%s", tarr->At(1)->GetName(), tarr->At(2)->GetName(), tarr->At(3)->GetName()); ptunp->AddText(tarr->At(0)->GetName()); ptunp->AddText(t); hunp->SetTitle(""); TPaveText *ptpos = new TPaveText(0.0, 0.9, 1.0, 1, "NDC"); TString tpos = hpos->GetTitle(); tarr = tpos.Tokenize("|"); sprintf(t, "%s:%s:%s", tarr->At(1)->GetName(), tarr->At(2)->GetName(), tarr->At(3)->GetName()); ptpos->AddText(tarr->At(0)->GetName()); ptpos->AddText(t); hpos->SetTitle(""); TPaveText *ptneg = new TPaveText(0.0, 0.9, 1.0, 1, "NDC"); TString tneg = hneg->GetTitle(); tarr = tneg.Tokenize("|"); sprintf(t, "%s:%s:%s", tarr->At(1)->GetName(), tarr->At(2)->GetName(), tarr->At(3)->GetName()); ptneg->AddText(tarr->At(0)->GetName()); ptneg->AddText(t); hneg->SetTitle(""); //! Draw histograms TCanvas *c = new TCanvas(hpos->GetName(),hpos->GetName(),900, 600); c->Divide(3,1); c->cd(1); hunp->Draw(); ptunp->Draw(); c->cd(2); hpos->Draw(); ptpos->Draw(); c->cd(3); hneg->Draw(); ptneg->Draw(); TString dir = TString::Format("./polobs/top%d/%s/Varset1/theta", top, Q2Wdirname.Data()); gSystem->mkdir(dir,1); c->SaveAs(TString::Format("%s/%s.png", dir.Data(), c->GetName())); c->Close(); c->Delete(); } } }
TH1D * GetITSsaRatio(TFile *file, Int_t num, Int_t den, Int_t cent, Bool_t cutSpectrum = kTRUE, Bool_t addSystematicError = kTRUE) { /* pt limits for combined spectra */ // Double_t ptMin[AliPID::kSPECIES] = {0., 0., 0.1, 0.2, 0.3}; // Double_t ptMax[AliPID::kSPECIES] = {0., 0., 0.6, 0.5, 0.6}; TH1 *hnum, *hden; Double_t ptMin = 0., ptMax = 10.; switch (num) { case kPiMinus: ptMin = TMath::Min(ptMin, 0.1); ptMax = TMath::Min(ptMax, 0.6); hnum = GetITSsaSpectrum(file, AliPID::kPion, 1, cent, kFALSE, kFALSE); break; case kPiPlus: ptMin = TMath::Min(ptMin, 0.1); ptMax = TMath::Min(ptMax, 0.6); hnum = GetITSsaSpectrum(file, AliPID::kPion, 0, cent, kFALSE, kFALSE); break; case kPi: ptMin = TMath::Min(ptMin, 0.1); ptMax = TMath::Min(ptMax, 0.6); hnum = GetITSsaSpectrum(file, AliPID::kPion, 1, cent, kFALSE, kFALSE); hnum->Add(GetITSsaSpectrum(file, AliPID::kPion, 0, cent, kFALSE, kFALSE)); break; case kKaMinus: ptMin = TMath::Min(ptMin, 0.2); ptMax = TMath::Min(ptMax, 0.5); hnum = GetITSsaSpectrum(file, AliPID::kKaon, 1, cent, kFALSE, kFALSE); break; case kKaPlus: ptMin = TMath::Min(ptMin, 0.2); ptMax = TMath::Min(ptMax, 0.5); hnum = GetITSsaSpectrum(file, AliPID::kKaon, 0, cent, kFALSE, kFALSE); break; case kKa: ptMin = TMath::Min(ptMin, 0.2); ptMax = TMath::Min(ptMax, 0.5); hnum = GetITSsaSpectrum(file, AliPID::kKaon, 1, cent, kFALSE, kFALSE); hnum->Add(GetITSsaSpectrum(file, AliPID::kKaon, 0, cent, kFALSE, kFALSE)); break; case kPrMinus: ptMin = TMath::Min(ptMin, 0.3); ptMax = TMath::Min(ptMax, 0.6); hnum = GetITSsaSpectrum(file, AliPID::kProton, 1, cent, kFALSE, kFALSE); break; case kPrPlus: ptMin = TMath::Min(ptMin, 0.3); ptMax = TMath::Min(ptMax, 0.6); hnum = GetITSsaSpectrum(file, AliPID::kProton, 0, cent, kFALSE, kFALSE); break; case kPr: ptMin = TMath::Min(ptMin, 0.3); ptMax = TMath::Min(ptMax, 0.6); hnum = GetITSsaSpectrum(file, AliPID::kProton, 1, cent, kFALSE, kFALSE); hnum->Add(GetITSsaSpectrum(file, AliPID::kProton, 0, cent, kFALSE, kFALSE)); break; } switch (den) { case kPiMinus: ptMin = TMath::Max(ptMin, 0.1); ptMax = TMath::Min(ptMax, 0.6); hden = GetITSsaSpectrum(file, AliPID::kPion, 1, cent, kFALSE, kFALSE); break; case kPiPlus: ptMin = TMath::Max(ptMin, 0.1); ptMax = TMath::Min(ptMax, 0.6); hden = GetITSsaSpectrum(file, AliPID::kPion, 0, cent, kFALSE, kFALSE); break; case kPi: ptMin = TMath::Max(ptMin, 0.1); ptMax = TMath::Min(ptMax, 0.6); hden = GetITSsaSpectrum(file, AliPID::kPion, 1, cent, kFALSE, kFALSE); hden->Add(GetITSsaSpectrum(file, AliPID::kPion, 0, cent, kFALSE, kFALSE)); break; case kKaMinus: ptMin = TMath::Max(ptMin, 0.2); ptMax = TMath::Min(ptMax, 0.5); hden = GetITSsaSpectrum(file, AliPID::kKaon, 1, cent, kFALSE, kFALSE); break; case kKaPlus: ptMin = TMath::Max(ptMin, 0.2); ptMax = TMath::Min(ptMax, 0.5); hden = GetITSsaSpectrum(file, AliPID::kKaon, 0, cent, kFALSE, kFALSE); break; case kKa: ptMin = TMath::Max(ptMin, 0.2); ptMax = TMath::Min(ptMax, 0.5); hden = GetITSsaSpectrum(file, AliPID::kKaon, 1, cent, kFALSE, kFALSE); hden->Add(GetITSsaSpectrum(file, AliPID::kKaon, 0, cent, kFALSE, kFALSE)); break; case kPrMinus: ptMin = TMath::Max(ptMin, 0.3); ptMax = TMath::Min(ptMax, 0.6); hden = GetITSsaSpectrum(file, AliPID::kProton, 1, cent, kFALSE, kFALSE); break; case kPrPlus: ptMin = TMath::Max(ptMin, 0.3); ptMax = TMath::Min(ptMax, 0.6); hden = GetITSsaSpectrum(file, AliPID::kProton, 0, cent, kFALSE, kFALSE); break; case kPr: ptMin = TMath::Max(ptMin, 0.3); ptMax = TMath::Min(ptMax, 0.6); hden = GetITSsaSpectrum(file, AliPID::kProton, 1, cent, kFALSE, kFALSE); hden->Add(GetITSsaSpectrum(file, AliPID::kProton, 0, cent, kFALSE, kFALSE)); break; } if (!hnum || !hden) return NULL; Char_t sysname[1024]; if (num == kPiMinus && den == kPiPlus) sprintf(sysname, "Pi_Pos2Neg"); else if (num == kKaMinus && den == kKaPlus) sprintf(sysname, "K_Pos2Neg"); else if (num == kPrMinus && den == kPrPlus) sprintf(sysname, "P_Pos2Neg"); else if ((num == kKa || num == kKaPlus || num == kKaMinus) && (den == kPi || den == kPiPlus || den == kPiMinus)) sprintf(sysname, "K2Pi"); else if ((num == kPr || num == kPrPlus || num == kPrMinus) && (den == kPi || den == kPiPlus || den == kPiMinus)) sprintf(sysname, "P2Pi"); TH1D *hin = (TH1D *)hnum->Clone("hin"); hin->Divide(hden); /* get systematics */ TFile *fsys = TFile::Open("RATIOSYS_ITSsa.root"); TH1 *hsys = fsys->Get(Form("hSystTot%s", sysname)); TH1D *h = new TH1D(Form("hITSsa_cent%d_%s_%s", cent, ratioName[num], ratioName[den]), "ITSsa", NptBins, ptBin); Double_t pt, width, value, error, sys; Int_t bin; for (Int_t ipt = 0; ipt < NptBins; ipt++) { /* get input bin */ pt = h->GetBinCenter(ipt + 1); width = h->GetBinWidth(ipt + 1); bin = hin->FindBin(pt); /* sanity check */ if (TMath::Abs(hin->GetBinCenter(bin) - pt) > 0.001 || TMath::Abs(hin->GetBinWidth(bin) - width) > 0.001) { // printf("skipping %f because of sanity checks\n", pt); continue; } /* check pt limits */ if (cutSpectrum && (pt < ptMin || pt > ptMax)) { // printf("skipping %f because of limits\n", pt); continue; } /* copy bin */ value = hin->GetBinContent(bin); error = hin->GetBinError(bin); /*** TEMP ADD SYS ***/ if (addSystematicError) { sys = hsys->GetBinContent(bin) * value; error = TMath::Sqrt(error * error + sys * sys); } h->SetBinContent(ipt + 1, value); h->SetBinError(ipt + 1, error); } h->SetTitle("ITSsa"); h->SetLineWidth(1); h->SetLineColor(1); h->SetMarkerStyle(20); h->SetMarkerColor(1); h->SetFillStyle(0); h->SetFillColor(0); return h; }
makeIasPredictionDataPngsFixedBins() { TCanvas t("myCanvas","myCanvas",100,100,800,600); t.cd(); t.SetLogy(); for(int nom=5; nom < 19; nom+=2) { for(int etaSlice=0; etaSlice < 16; etaSlice+=2) { string histName="nom"; histName+=intToString(nom); histName+="to"; if(nom==5) histName+=intToString(nom+3); else histName+=intToString(nom+1); histName+="eta"; histName+=intToString(etaSlice); histName+="to"; histName+=intToString(etaSlice+2); string histNameBeg = histName; histName+="iasPredictionFixedLimitsHist"; //histName+="iasPredictionFixedDiscoveryHist"; //cout << "Getting hist: " << histName << endl; TH1D* iasPredHistThisSlice = (TH1D*)_file0->Get(histName.c_str()); histName="nom"; histName+=intToString(nom); histName+="to"; if(nom==5) histName+=intToString(nom+3); else histName+=intToString(nom+1); histName+="eta"; histName+=intToString(etaSlice); histName+="to"; histName+=intToString(etaSlice+2); histName+="dRegionFixedHist"; //cout << "Getting hist: " << histName << endl; TH1D* iasDataHistThisSlice = (TH1D*)_file0->Get(histName.c_str()); iasDataHistThisSlice->SetLineColor(kBlack); iasDataHistThisSlice->SetMarkerColor(kBlack); iasDataHistThisSlice->SetMarkerStyle(20); iasDataHistThisSlice->Draw(); iasPredHistThisSlice->SetLineColor(kBlue); iasPredHistThisSlice->SetMarkerColor(kBlue); iasPredHistThisSlice->SetMarkerStyle(21); iasPredHistThisSlice->Draw("same"); // draw 3rd hist? string thirdHistName = histNameBeg; thirdHistName+="iasPredictionFixedSlopeMinusOneSigmaLimitsHist"; TH1D* iasPredThirdHist = (TH1D*)_file0->Get(thirdHistName.c_str()); iasPredThirdHist->SetLineColor(kRed); iasPredThirdHist->SetMarkerColor(kRed); iasPredThirdHist->SetMarkerStyle(23); iasPredThirdHist->Draw("same"); // draw 4th hist? string fourthHistName = histNameBeg; fourthHistName+="iasPredictionFixedSlopeAddOneSigmaLimitsHist"; TH1D* iasPredFourthHist = (TH1D*)_file0->Get(fourthHistName.c_str()); iasPredFourthHist->SetLineColor(kGreen+2); iasPredFourthHist->SetMarkerColor(kGreen+2); iasPredFourthHist->SetMarkerStyle(22); iasPredFourthHist->Draw("same"); if(iasDataHistThisSlice->GetMaximum() <= 0) iasDataHistThisSlice->GetYaxis()->SetRangeUser(1e-10,iasPredHistThisSlice->GetMaximum()*1.2); else iasDataHistThisSlice->GetYaxis()->SetRangeUser(1e-10,iasDataHistThisSlice->GetMaximum()*1.2); string name="nom"; name+=intToString(nom); name+="to"; if(nom==5) name+=intToString(nom+3); else name+=intToString(nom+1); name+="eta"; name+=intToString(etaSlice); name+="to"; name+=intToString(etaSlice+2); name+="iasDataPred"; t.Print((name+".png").c_str()); } if(nom==5) nom+=2; } }
void macroComparison(string sfileA,string sfileB,string sfileC, string fname){ TFile * fileA = new TFile(TString(sfileA), "READ"); TFile * fileB = new TFile(TString(sfileB), "READ"); TFile * fileC = new TFile(TString(sfileC), "READ"); // get canvas name TList *listA = fileA->GetListOfKeys(); TString canvasnameA = listA->At(0)->GetName(); TList *listB = fileB->GetListOfKeys(); TString canvasnameB = listB->At(0)->GetName(); TList *listC = fileC->GetListOfKeys(); TString canvasnameC = listC->At(0)->GetName(); // make histogram name out of canvas name TString histonameA = canvasnameA; Ssiz_t objIndexA = histonameA.Index("canvas"); histonameA.Resize(objIndexA); histonameA+= "_data_hist"; TString histonameB = canvasnameB; Ssiz_t objIndexB = histonameB.Index("canvas"); histonameB.Resize(objIndexB); histonameB+= "_data_hist"; TString histonameC = canvasnameC; Ssiz_t objIndexC = histonameC.Index("canvas"); histonameC.Resize(objIndexC); histonameC+= "_data_hist"; // get canvas from files // get histograms from canvases TCanvas *cvA = (TCanvas*) fileA->Get(canvasnameA); TH1D * histoA = (TH1D*) cvA->FindObject(histonameA)->Clone(); // set name to different value cvA->SetName("dummy"); TCanvas *cvB = (TCanvas*) fileB->Get(canvasnameB); TH1D * histoB = (TH1D*) cvB->FindObject(histonameB)->Clone(); cvB->SetName("dummy2"); TCanvas *cvC = (TCanvas*) fileC->Get(canvasnameC); TH1D * histoC = (TH1D*) cvC->FindObject(histonameC)->Clone(); // ratio plots TH1D * histoAoverBRatio = (TH1D*) histoA->Clone(); TH1D * histoAoverCRatio = (TH1D*) histoA->Clone(); TH1D * histoBoverCRatio = (TH1D*) histoB->Clone(); histoAoverBRatio->Divide(histoB); histoAoverCRatio->Divide(histoC); histoBoverCRatio->Divide(histoC); // make new Canvas for plotting TCanvas *cv1 = new TCanvas(histonameA, histonameA, 1024,1024); cv1->cd(); cv1->Clear(); cv1->Divide(1,2,0.01,0.0); cv1->cd(1); cv1->SetFillColor(0); gStyle->SetOptTitle(0); gPad->SetFillColor(0); gPad->SetPad( 0.0, 0.25, 1.0, 1.0 ); gPad->SetTopMargin(0.1); gPad->SetLeftMargin(0.16); gPad->SetRightMargin(0.04); cv1->cd(2); cv1->SetFillColor(0); gStyle->SetOptTitle(0); gPad->SetFillColor(0); gPad->SetPad( 0.0, 0.0, 1.0, 0.25 ); gPad->SetBottomMargin(0.375); gPad->SetLeftMargin(0.16); gPad->SetRightMargin(0.04); gPad->SetGridy(); cv1->cd(1); histoA->SetMarkerStyle(20); histoA->SetMarkerSize(2); histoA->SetMarkerColor(1); histoA->Draw("E1X0"); // histoA->DrawNormalized("E1X0"); histoB->SetMarkerStyle(21); histoB->SetMarkerSize(2); histoB->SetMarkerColor(2); histoB->Draw("E1X0SAME"); // histoB->DrawNormalized("E1X0SAME"); histoC->SetMarkerStyle(22); histoC->SetMarkerSize(2); histoC->SetMarkerColor(3); histoC->Draw("E1X0SAME"); // histoC->DrawNormalized("E1X0SAME"); TLegend *leg = new TLegend(0.685, 0.575, 0.8, 0.875); leg->AddEntry(histoA,"A"); leg->AddEntry(histoB,"B"); leg->AddEntry(histoC,"C"); leg->Draw("SAME"); // set style for ratio plots histoAoverBRatio->SetMarkerStyle(20); histoAoverCRatio->SetMarkerStyle(21); histoBoverCRatio->SetMarkerStyle(22); histoAoverBRatio->SetMarkerSize(1); histoAoverCRatio->SetMarkerSize(1); histoBoverCRatio->SetMarkerSize(1); histoAoverBRatio->SetMarkerColor(1); histoAoverCRatio->SetMarkerColor(2); histoBoverCRatio->SetMarkerColor(3); histoAoverBRatio->SetLineColor(1); histoAoverCRatio->SetLineColor(2); histoBoverCRatio->SetLineColor(3); cv1->cd(2); histoAoverBRatio->GetYaxis()->SetRangeUser(0.9,1.1); histoAoverBRatio->GetYaxis()->CenterTitle(1); histoAoverBRatio->GetYaxis()->SetTitleSize( 0.16 ); histoAoverBRatio->GetYaxis()->SetTitleOffset( 0.425 ); histoAoverBRatio->GetYaxis()->SetLabelSize( 0.16 ); histoAoverBRatio->GetYaxis()->SetNdivisions( 505 ); histoAoverBRatio->GetXaxis()->SetTitleSize( 0.16 ); histoAoverBRatio->GetXaxis()->SetLabelSize( 0.16 ); histoAoverBRatio->GetXaxis()->SetTitleOffset( 1 ); histoAoverBRatio->GetXaxis()->SetLabelOffset( 0.006 ); histoAoverBRatio->GetXaxis()->SetNdivisions( 510 ); histoAoverBRatio->GetXaxis()->SetTickLength( histoAoverBRatio->GetXaxis()->GetTickLength() * 3.0 ); histoAoverBRatio->SetYTitle("Data/Data"); histoAoverBRatio->Draw("E1X0"); histoAoverCRatio->Draw("E1X0SAME"); histoBoverCRatio->Draw("E1X0SAME"); cv1->Update(); cv1->Print(TString(fname)+TString("_Linear.png")); /// the same with log scale // make new Canvas for plotting TCanvas *cv2 = new TCanvas(histonameA+"log", histonameA+"log", 1024,1024); cv2->cd(); cv2->Clear(); cv2->Divide(1,2,0.01,0.0); cv2->cd(1); cv2->SetFillColor(0); gStyle->SetOptTitle(0); gPad->SetLogy(); gPad->SetFillColor(0); gPad->SetPad( 0.0, 0.25, 1.0, 1.0 ); gPad->SetTopMargin(0.1); gPad->SetLeftMargin(0.16); gPad->SetRightMargin(0.04); cv2->cd(2); cv2->SetFillColor(0); gStyle->SetOptTitle(0); gPad->SetFillColor(0); gPad->SetPad( 0.0, 0.0, 1.0, 0.25 ); gPad->SetBottomMargin(0.375); gPad->SetLeftMargin(0.16); gPad->SetRightMargin(0.04); gPad->SetGridy(); cv2->cd(1); histoA->Draw("E1X0"); histoB->Draw("E1X0SAME"); histoC->Draw("E1X0SAME"); TLegend *leg2 = new TLegend(0.685, 0.575, 0.8, 0.875); leg2->AddEntry(histoA,"A"); leg2->AddEntry(histoB,"B"); leg2->AddEntry(histoC,"C"); leg2->Draw("SAME"); cv2->cd(2); histoAoverBRatio->Draw("E1X0"); histoAoverCRatio->Draw("E1X0SAME"); histoBoverCRatio->Draw("E1X0SAME"); cv2->Update(); cv2->Print(TString(fname)+TString("_Log.png")); }
void MidRapAnalysis() { //Set up Canvas Area TCanvas* can2 = new TCanvas("can2", "Centrality"); double xAverage[] = {3.42, 2.62, 1.96, 1.45, 1.12, .87, .67, .49, .39, .28, .23}; double yAverage[] = {5.22, 3.33, 2.21, 1.40, 1.06, .72, .49, .22, .16, .06, .03}; double yError[] = {.36, .25, .12, .06, .01, .12, .04, .03, .01, .01, 0}; double xError[] = {0,0,0,0,0,0,0,0,0,0}; TGraphErrors* Emodel = new TGraphErrors(10, xAverage, yAverage, xError, yError); Emodel->SetFillStyle(3001); Emodel->SetFillColor(kBlue); double xAverageE[] = {4.19, 2.92, 2.03, 1.40, 1.04, .77, .57, .42, .32, .24}; double yAverageE[] = {5.39, 3.36, 2.14, 1.33, .90, .56, .37, .16, .14, .01}; double yErrorE[] = {.31, .24, .08, .07, .01, .01, .02, .06, .07, .01}; double xErrorE[] = {0,0,0,0,0,0,0,0,0,0}; TGraphErrors* EmodelE = new TGraphErrors(10, xAverageE, yAverageE, xErrorE, yErrorE); EmodelE->SetFillStyle(3001); EmodelE->SetFillColor(kGreen); can2->cd(); TH1F* frame = can2->DrawFrame(0, 0, 3.5, 7.2); TF1* line = new TF1("line", "x", 0, 4.3); TF1* line2 = new TF1("line2", "1.6*x", 0, 4.3); line2->SetLineColor(kWhite); line->SetLineColor(1); line2->GetYaxis()->SetTitle("#varUpsilon(1S)/<#varUpsilon(1S)>"); // line2->GetXaxis()->SetTitle("N_{Ch}^{|#eta|<2.4}/<N_{Ch}^{|#eta|<2.4}>"); line2->SetTitle("#varUpsilon(1S) Cross Section vs Event Activity"); line2->Draw(); Emodel->Draw("P3"); EmodelE->Draw("3"); //line2->Draw("same"); line->SetLineStyle(3); line->SetLineColor(kBlack); line->Draw("same"); TH1D* mod = new TH1D("mod", "Pythia Model", 400, 0, 4); mod->SetLineColor(kBlue); TH1D* modEnergy = new TH1D("modEnergy", "Pythia Energy Model", 400, 0, 4); modEnergy->SetLineColor(kGreen); TH1D* data = new TH1D("data", "CMS Data", 4000, 0, 4); data->SetMarkerStyle(20); data->SetMarkerColor(kRed); //Manually Entering CMS Data Points with Error data->SetBinContent(3262, 6.67); data->SetBinError(3262, .26); data->SetBinContent(2010, 3.12); data->SetBinError(2010, .15); data->SetBinContent(1240, 1.4); data->SetBinError(1240, .06); data->SetBinContent(630, .240); data->SetBinError(630, .01); //data->SetMarkerColor(kBlue); data->SetMarkerSize(1); data->SetLineColor(kRed); data->Draw("sameE"); TLegend* leg = new TLegend(.1,.7,.38,.9); leg->SetHeader("For |#eta| < 2.4"); leg->AddEntry(modEnergy->DrawCopy("same"), "Pythia 8 - #Sigma E_{T}/<#Sigma E_{T}>", "l"); leg->AddEntry(mod->DrawCopy("same"), "Pythia 8 - N_{Ch}/<N_{Ch}>", "l"); leg->AddEntry(data->DrawCopy("sameE"), "CMS data - N_{Ch}/<N_{Ch}>", "l"); leg->Draw("same"); mod->SetLineColor(kBlack); mod->Draw("same"); return; }
void CorrPtCut(char *prodname = "LHC10d4 PYTHIA D6T 7 TeV p+p", char *shortprodname = "LHC10d4", char *filename="Et.ESD.new.sim.LHC10d4.pp.merged.root"){ gStyle->SetOptTitle(0); gStyle->SetOptStat(0); gStyle->SetOptFit(0); TCanvas *c = new TCanvas("c","c",500,400); c->SetTopMargin(0.04); c->SetRightMargin(0.04); c->SetLeftMargin(0.181452); c->SetBottomMargin(0.134409); c->SetBorderSize(0); c->SetFillColor(0); c->SetFillColor(0); c->SetBorderMode(0); c->SetFrameFillColor(0); c->SetFrameBorderMode(0); float etacut = 0.7; cout<<"Pt cut = 150 MeV/c"<<endl; TH1D *High = GetHisto(0.15-.001,"High",filename,etacut); float tpcHigh=highbound; float tpcLow=lowbound; float tpcsyserr = syserr; float tpcmean = mean; float x1 = High->GetXaxis()->GetBinLowEdge(1); //TBox *tpcBox = new TBox(-x1*.99,1.0-tpcLow,x1*.99,1.0-tpcHigh); TBox *tpcBox = new TBox(-x1*.99,1.0-(mean-syserr),x1*.99,1.0-(mean+syserr)); tpcBox->SetFillColor(5); tpcBox->SetLineColor(0); tpcBox->SetFillStyle(1001); cout<<"Pt cut = 100 MeV/c"<<endl; TH1D *Low = GetHisto(0.1-.001,"Low",filename,etacut); float itsHigh=highbound; float itsLow=lowbound; float itssyserr = syserr; float itsmean = mean; cout<<Form("dataset & %2.4f \\pm %2.4f & %2.4f \\pm %2.4f \\",itsmean,itssyserr,tpcmean,tpcsyserr)<<endl; float x = Low->GetXaxis()->GetBinLowEdge(1); //TBox *itsBox = new TBox(-x*.99,1.0-itsLow,x*.99,1.0-itsHigh); TBox *itsBox = new TBox(-x1*.99,1.0-(mean-syserr),x1*.99,1.0-(mean+syserr)); itsBox->SetFillColor(5); itsBox->SetLineColor(0); itsBox->SetFillStyle(1001); cout<<"Pt cut = 50 MeV/c"<<endl; TH1D *Lowest = GetHisto(0.05-.001,"Lowest",filename,etacut); TF1 *funcLow = new TF1("funcLow","[0]",-.7,.7); funcLow->SetParameter(0,0.01); Low->Fit(funcLow); TF1 *funcHigh = new TF1("funcHigh","[0]",-.7,.7); funcHigh->SetParameter(0,0.02); High->Fit(funcLow); High->SetMaximum(0.06); High->SetMinimum(0.0); High->SetMarkerColor(2); Low->SetMarkerColor(4); High->SetLineColor(2); Low->SetLineColor(4); High->SetMinimum(0.0); High->SetMarkerStyle(20); Low->SetMarkerStyle(21); Lowest->SetMarkerStyle(22); High->Draw(); tpcBox->Draw("f"); High->Draw("same"); itsBox->Draw("f"); //return; Low->Draw("same"); //Lowest->Draw("same"); TLatex *tex = new TLatex(-0.723444,0.0373593+0.019,prodname); tex->SetTextSize(0.0537634); tex->Draw(); TLegend *leg = new TLegend(0.217742,0.696237,0.477823,0.873656); leg->AddEntry(High,"p_{T} cut-off = 0.15 GeV/c"); leg->AddEntry(Low,"p_{T} cut-off = 0.1 GeV/c"); //leg->AddEntry(Lowest,"p_{T} cut-off = 0.05 GeV/c"); leg->SetFillStyle(0); leg->SetFillColor(0); leg->SetBorderSize(0); leg->SetTextSize(0.0537634); leg->Draw(); c->SaveAs(Form("pics/%s/fptcut.eps",shortprodname)); c->SaveAs(Form("pics/%s/fptcut.png",shortprodname)); c->SaveAs(Form("pics/%s/fptcut.pdf",shortprodname)); }
void //Impose (TDirectory * target, TList * sourcelist, string & np_title_, vector<string> titles,vector<float> xsecs) Impose (TList * sourcelist, string & np_title_, vector<string> titles,vector<float> xsecs, TString &variable) { cout << " " << "========================================================" << endl; cout << " " << "This is a macro to superimpose plots of different root files." << endl; cout << " " << "Only TH2Dobjects are superimposed." << endl; float Lumi=1; Lumi = 15712.; bool norm_=false; int MaxEventsBin = 10; cout<<titles[0]<<" "<<titles.size()<<endl; //not really useful if plots already weighted to lumi - usefull is plots are in a.u. vector <float > lumiweights; lumiweights.clear(); // for (unsigned int kk=0; kk<signal_names.size();kk++){ // cout<<" HERE is some signal =============================================== "<<signal_names[kk]<<" "<<signalnames[kk]<<endl; // } TH2D* allbkg, *htt,*hstop,*hwj,*hdyj,*hrare,*hdib,*hqcd,*httx, *hrest; TFile *first_source = (TFile *) sourcelist->First (); first_source->cd ("mutau"); TH1D* eventCount = (TH1D*)first_source->Get("mutau/histWeightsH"); //TH1D* eventCount = (TH1D*)first_source->Get("mutau/inputEventsH"); //TH1D* hxsec = (TH1D*)first_source->Get("mutau/xsec"); float nGen = eventCount->GetSumOfWeights(); float xsec = 1;//hxsec->GetMean(); float norm = xsec*Lumi/nGen; norm =1; lumiweights.push_back(float(norm)); //cout<< " for first source file, there where "<<nGen<<" events with xsec "<<xsec<<" weight "<<lumiweights[0]<<endl;//" weight "<<float(xsec*Lumi/nGen)<<" norm "<<norm<<endl; TDirectory *current_sourcedir = gDirectory; //gain time, do not add the objects in the list in memory Bool_t status = TH1::AddDirectoryStatus (); TH1::AddDirectory (kFALSE); // loop over all keys in this directory TChain *globChain = 0; TIter nextkey (current_sourcedir->GetListOfKeys ()); //TIter nextkey (((TDirectory *) current_sourcedir->Get ("ana"))->GetListOfKeys ()); TKey *key, *oldkey = 0; while ((key = (TKey *) nextkey ())) { //variable="met_MTsum_16"; int count=0; count++; //if (count>20) break; //keep only the highest cycle number for each key // if (oldkey && !strcmp (oldkey->GetName (), key->GetName ())) // continue; // read object from first source file and create a canvas // first_source->cd (path); first_source->cd ("mutau"); TObject *obj = key->ReadObj (); //string nn = obj->GetName(); // if (std::string::npos == nn.find("Cut")) continue; //cout<<obj->GetName()<<endl; string nn = obj->GetName(); bool flcont = true; bool NormTT = false; if (string::npos != nn.find("_9") || string::npos != nn.find("_10") || string::npos != nn.find("_11") || string::npos != nn.find("_12") || string::npos != nn.find("_13") || string::npos != nn.find("_14") || string::npos != nn.find("_15") || string::npos != nn.find("_16") || string::npos != nn.find("_18") || string::npos != nn.find("_18") || string::npos != nn.find("_18")) NormTT = true; //if ( string::npos != nn.find("_11") || string::npos != nn.find("_12") || string::npos != nn.find("_13") || string::npos != nn.find("_14")) NormTT = true; NormTT=true; //if ( string::npos == nn.find("CutFlowUnW")) flcont=false; //if (string::npos == nn.find(""+variable) ) flcont=false; if (string::npos == nn.find(variable) ) continue; // if (!flcont) continue; if (obj->IsA ()->InheritsFrom ("TTree") ) continue; // if (obj->IsA ()->InheritsFrom ("TH1") ) continue; if (obj->IsA ()->InheritsFrom ("TH2") ) { cout<<"=================================================== OK for variable "<<variable<<endl; TH2D* hh[1500]; TH2D* hsignal[1500]; TH2D* h1 = (TH2D*) obj; ModifyHist (h1,1,Lumi,lumiweights[0],titles[0],norm_); TFile *nextsource = (TFile *) sourcelist->After (first_source); int cl, countsignal; h1->SetStats(000000); cl=1; countsignal=1; hh[cl]=h1; THStack *hs = new THStack(h1->GetName(),h1->GetTitle()); string sn="stau"; string sdata="Single"; string sdata2="MuonEG"; string cc1="C1"; while (nextsource) { string fname= nextsource->GetName(); bool flagg= false; if (std::string::npos != fname.find(sn) || std::string::npos != fname.find(cc1) || std::string::npos != fname.find(sdata) ) flagg=true; //if (flagg) cout<<"=============================================================== "<<fname<<endl; // make sure we are at the correct directory level by cd'ing to path nextsource->cd("mutau"); TH1D* eventCountt ; if ( std::string::npos == fname.find("TT_TuneCUETP8M1_13TeV-powheg-pythia8") || !NormTT) eventCountt = (TH1D*)nextsource->Get("mutau/histWeightsH"); if ( NormTT && std::string::npos != fname.find("TT_TuneCUETP8M1_13TeV-powheg-pythia8") ) eventCountt = (TH1D*)nextsource->Get("mutau/histTopPt"); TH1D* hxsecc = (TH1D*)nextsource->Get("mutau/xsec"); float xsecc = xsecs[cl]; float nGenn = eventCountt->GetSumOfWeights(); float normm = float(xsecc*Lumi) / float(nGenn) ; if (std::string::npos != fname.find("DataDriven")) normm=1.; lumiweights.push_back(normm); TKey *key2 = (TKey *) gDirectory->GetListOfKeys ()->FindObject (h1->GetName ()); if (key2) { cl++; countsignal++; TH2D *h2; h2 = (TH2D*) key2->ReadObj (); ModifyHist (h2, cl,Lumi,lumiweights[cl-1],titles[cl-1],norm_); h2->SetStats(0); hh[cl] = h2; if (cl==2){ allbkg = (TH2D*) h2->Clone(); allbkg->Reset(); htt = (TH2D*) h2->Clone(); httx = (TH2D*) h2->Clone(); hstop = (TH2D*) h2->Clone(); hwj = (TH2D*) h2->Clone(); hdyj = (TH2D*) h2->Clone(); hrare = (TH2D*) h2->Clone(); hdib = (TH2D*) h2->Clone(); hqcd = (TH2D*) h2->Clone(); hrest = (TH2D*) h2->Clone(); htt->Reset(); httx->Reset(); hstop->Reset(); hdyj->Reset(); hwj->Reset(); hrare->Reset(); hdib->Reset(); hqcd->Reset(); hrest->Reset(); } string hn_ = obj->GetName(); cout<<" "<<fname<<endl; if (std::string::npos != fname.find(sn) || std::string::npos != fname.find(cc1) || std::string::npos != fname.find(sdata) || std::string::npos != fname.find(sdata2) ) flagg=true; string title_ = fname; //cout<<" "<<fname<<endl; int col = 0; if (!flagg) { if (std::string::npos != title_.find("wJets")|| std::string::npos != title_.find("WJetsToLNu") || std::string::npos != title_.find("W1JetsToLNu") || std::string::npos != title_.find("W2JetsToLNu") || std::string::npos != title_.find("W3JetsToLNu") || std::string::npos != title_.find("W4JetsToLNu")) { col=mycolorwjet ; hwj->Add(h2); hwj->SetLineColor(col);} if (std::string::npos != title_.find("TT_TuneCUETP8M1_13TeV-powheg-pythia8") || std::string::npos != title_.find("TTPow")) { col= mycolortt;htt->Add(h2); htt->SetLineColor(col) ;} if (std::string::npos != title_.find("QCD")) {col= mycolorqcd;hqcd->Add(h2); hqcd->SetLineColor(col); cout<<" QCD ======================== "<<hqcd->GetSumOfWeights()<<endl;} if (std::string::npos != title_.find("DYJets") || std::string::npos != title_.find("DY1Jets") || std::string::npos != title_.find("DY2Jets") || std::string::npos != title_.find("DY3Jets") || std::string::npos != title_.find("DY4Jets")) {col= mycolordyj;hdyj->Add(h2); hdyj->SetLineColor(col);} if (std::string::npos != title_.find("ST_") || std::string::npos != title_.find("channel") ) {col= mycolortt; hstop->Add(h2);hstop->SetLineColor(col);} if ( std::string::npos != title_.find("WW") || std::string::npos != title_.find("ZZ") || std::string::npos != title_.find("WZ") || std::string::npos != title_.find("WG") || std::string::npos != title_.find("ZG") ) {col=mycolorvv; hdib->Add(h2); hdib->SetLineColor(col);} if ( std::string::npos != title_.find("TTW") || std::string::npos != title_.find("TTZ") || std::string::npos != title_.find("tZq") || std::string::npos != title_.find("TG") || std::string::npos != title_.find("tG") || std::string::npos != title_.find("TTG") || std::string::npos != title_.find("ttW") || std::string::npos != title_.find("ttZ") || std::string::npos != title_.find("tZ") || std::string::npos != title_.find("TTT_") ) {col=mycolorttx ;httx->Add(h2); httx->SetLineColor(col);} //cout<<" will add histogram "<<h2->GetName()<< " for "<<titles[cl-1]<<" "<<fname<<" cl "<<cl<<endl; hs->Add(h2); allbkg->Add(h2); } } nextsource = (TFile *) sourcelist->After (nextsource); } // while ( nextsource ) } cout<<" Will now extract and save the 1D "<<endl; //const char *s1; TString s1; TH1D * histbkg; string n = obj->GetName(); vector<float> scales; bool b_scale=true; if (std::string::npos != n.find(variable) && obj) { TH2D *hsum = ((TH2D*)(hs->GetStack()->Last())); // the "SUM" scales.push_back(40000.); for (int sc = 0 ; sc<scales.size();sc++){ float scale = float(scales[sc])/float(Lumi); //stringstream ss (stringstream::in | stringstream::out); TString lumistring = "40invfb"; TString smFilename = "Templates_"+variable+"_"+lumistring+"_mt_C1C1.root"; //TString smFilename = "Templates_mt.root"; TFile *smFile = TFile::Open (smFilename, "recreate"); smFile->cd(); //if (sc==0) smFile->mkdir("mt"); smFile->cd(); allbkg = hsum; allbkg->SetMinimum(0.1); allbkg->SetLineColor(kRed); allbkg->SetMarkerColor(kRed); allbkg->SetFillColor(kRed); allbkg->SetFillStyle(3011); allbkg->SetMinimum(0.1); s1 = "data_obsMC_" + variable; //s1 = "data_obsMC"; allbkg->SetName(s1); cout<<" Total Integral before scaling up - "<<allbkg->GetSumOfWeights()<<" "<<variable<<" data "<<hh[1]->GetSumOfWeights()<<" tt "<< htt->GetSumOfWeights()<<" dy "<<hdyj->GetSumOfWeights()<<" wj "<<hwj->GetSumOfWeights()<<" stop "<<hstop->GetSumOfWeights()<< " vv "<<hdib->GetSumOfWeights()<<" qcd "<<hqcd->GetSumOfWeights()<<endl; if(b_scale) allbkg->Scale(scale); cout<<" Total Integral after scaling up - "<<allbkg->GetSumOfWeights()<<" "<<variable<<endl; allbkg->Write(); histbkg = Unroll(allbkg,s1,1.); s1 = "1D_allbkg_" + variable; //s1 = "1D_data_obsMC";//_" + variable+"_"+lumistring; histbkg->SetName(s1); histbkg->SetMarkerColor(kRed); histbkg->SetLineColor(kRed); histbkg->Write(); if(b_scale){ htt->Scale(scale); hwj->Scale(scale); hdyj->Scale(scale); hstop->Scale(scale); hdib->Scale(scale); hqcd->Scale(scale); httx->Scale(scale); } htt->SetMinimum(0.1); hdyj->SetMinimum(0.1); hwj->SetMinimum(0.1); httx->SetMinimum(0.1); hstop->SetMinimum(0.1); hdib->SetMinimum(0.1); hqcd->SetMinimum(0.1); s1 = "tt_"+variable; htt->SetName(s1); htt->Write(); histbkg = Unroll(htt,s1,1.); s1 = "1D_tt_"+variable; histbkg->SetName(s1); histbkg->Write(); s1 = "wj_"+variable; hwj->SetName(s1); hwj->Write(); histbkg =Unroll(hwj,s1,1.); s1 = "1D_wj_"+variable; histbkg->SetName(s1); histbkg->Write(); s1 = "dyj_"+variable; hdyj->SetName(s1); hdyj->Write(); histbkg =Unroll(hdyj,s1,1.); s1 = "1D_dyj_"+variable; histbkg->SetName(s1); histbkg->Write(); s1 = "sT_"+variable; hstop->SetName(s1); hstop->Write(); histbkg =Unroll(hstop,s1,1.); s1 = "1D_sT_"+variable; histbkg->SetName(s1); histbkg->Write(); s1 = "dib_"+variable; hdib->SetName(s1); hdib->Write(); histbkg =Unroll(hdib,s1,1.); s1 = "1D_dib_"+variable; histbkg->SetName(s1); histbkg->Write(); s1 = "ttx_"+variable; httx->SetName(s1); httx->Write(); histbkg =Unroll(httx,s1,1.); s1 = "1D_ttx_"+variable; histbkg->SetName(s1); histbkg->Write(); s1 = "qcd_"+variable; hqcd->SetName(s1); hqcd->Write(); histbkg =Unroll(hqcd,s1,1.); s1 = "1D_qcd_"+variable; histbkg->SetName(s1); histbkg->Write(); //rest of bkg hold all but ttjets and wjets background s1 = "rest_bkg_"+variable; //hrest->Add(hdyj,1); //hrest->Add(httj,1); //hrest->Add(hwj,1); hrest->Add(hstop,1); hrest->Add(hdib,1); hrest->Add(hqcd,1); hrest->Add(httx,1); hrest->SetName(s1); hrest->Write(); histbkg =Unroll(hrest,s1,1.); s1 = "1D_rest_bkg_"+variable; histbkg->SetName(s1); histbkg->Write(); hh[1]->SetMinimum(0.1); hh[1]->SetLineColor(kBlack); hh[1]->SetFillColor(kBlack); hh[1]->SetMarkerColor(kBlack); s1 = "data_obs_"+variable; hh[1]->SetName(s1); if(b_scale) hh[1]->Scale(scale); hh[1]->Write(); histbkg =Unroll(hh[1],s1,1.); //histbkg =Unroll(allbkg,s1,1.); s1 = "1D_data_obs_"; s1 = "data_obs"; histbkg->SetName(s1); histbkg->Write(); for (unsigned int ij=0;ij<signal_names.size();++ij){ //cout<<" again "<<signal_names[ij]<<endl; //cout<<" again "<<hh[ij+2]->GetName()<<" "<<ij<<" "<<signal_names[ij].c_str()<<endl; TString ss1 = signal_names[ij].c_str(); s1 = "1D_"+ss1 +"_"+variable; if(b_scale) hh[ij+2]->Scale(scale); histbkg = Unroll(hh[ij+2],s1,1.); smFile->cd(); histbkg->SetName(s1); histbkg->SetMarkerColor(kBlue); histbkg->SetLineColor(kBlue); histbkg->Write(); } smFile->SaveSelf (kTRUE); smFile->Close(); delete smFile; }//loop over different predictions }///find variable } //delete c1; // save modifications to target file //target->SaveSelf (kTRUE); TH1::AddDirectory (status); cout << " " << "========================================================" << endl; cout<< " Ended SuperImpose of files.... " <<endl; }
void packTemplatesMass(const int iMass) { // This Root macro is for the purpose of providing input for expected limit computation // It packs predicted background and a set of signal samples into a root file per Higgs mass // TH1::SetDefaultSumw2(); TH2::SetDefaultSumw2(); canvas = new TCanvas ("cg1","PadX",10,10,800,600); gStyle->SetPadColor(0); canvas->SetFillColor(0); // const int nbtag = 4; const int nbtag = 1; //const std::string sbtag[nbtag] = { "TCHPT", "TCHP6", "CSVT", "SSVHPT" }; const std::string sbtag[nbtag] = { "CSVT" }; const int nfc=3; const int ncateg=3; string sfc[nfc] = { "q", "c", "b" }; // this is for the combination of triggers in real data int nTCombData = 4; std::string tCombData[] = {"Trig0", "Trig1", "Trig2", "Trig3"}; std::string L1L2Mode("Weight"); std::string signalMode("PU_WEIGHTED-NEW"); // std::string L1L2Mode("Cut"); // std::string signalMode("CUT_BASED"); //std::string scenario("LowMass2011"); //std::string scenario("MediumMass2011"); std::string scenario; bool useTemplateError; bool useNP; if ( getHbbCfg(scenario,useTemplateError,useNP) != 0 ) return; string IgorVersion("V6"); #include "Analysis/Utilities/interface/HbbMass.h" if (iMass >= nSignal) { std::cout << "Bad iMass=" << iMass << std::endl; return; } // const int nSignal=7; // int signalMass[nSignal] = { 90, 100, 120, 140, 180, 250, 350 }; // int signalMass[nSignal] = { 90, 100, 120, 130, 140, 160, 180, 200, 250, 350 } // there are also : 450, 500, 600, 700, 800, 900, 1000 // double efficiency[nSignal] = { 0.0022081, 0.00324694, 0.00600146, 0.00918135, // 0.0138382, 0.0189684, 0.0206572 }; double efficiency[nSignal][nbtag]; double intLumi = 0; string IgorScen(""); string spacer(""); string SashaPath(""); string IgorPath("/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/SignalTemplates-Production"); if (IgorVersion == "V4") { IgorPath.assign("/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/Systematics-test-4"); } else if (IgorVersion == "V6") { IgorPath.assign("/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/SignalTemplates-Production2"); } if (scenario == "LowMass2011") { //intLumi = 2.66794; // in fb-1 intLumi = 2.692643; // with new method IgorScen.assign("low"); spacer.assign(""); //SashaPath.assign("Data-Run2011AB"); SashaPath.assign("Data-Run2011AB/TripleBtagAnalysis_CR3_SF7"); } else if (scenario == "MediumMass2011") { //intLumi = 3.99983; // in fb-1 intLumi = 4.040802; IgorScen.assign("medium"); spacer.assign("/MEDIUM"); //SashaPath.assign("Data-Run2011AB-Medium"); SashaPath.assign("Data-Run2011AB/TripleBtagAnalysis_CR3_SF7_med"); } else if (scenario == "MediumMass2012") { //intLumi = 3.99983; // in fb-1 intLumi = 2.663; IgorScen.assign("medium"); spacer.assign("/MEDIUM"); //SashaPath.assign("Data-Run2011AB-Medium"); SashaPath.assign(""); } else { std::cout << "Bad scenario in packing" << std::endl; return; } string signalHistPattern("massEvBtag/mjjEvBTag_%s"); if (L1L2Mode == "Weight") { signalHistPattern.assign("massEvBtagTW/mjjEvBTagTW_%s"); } double fScal[nSignal][nbtag]; // systematics // const int nSyst = 3; // std::string systName[nSyst] = { "JES", "SFbc", "SFudsg" }; // bool realDataNuisance[nSyst] = { false, true, true }; // indicate if relevant for real data string bbPurity("DataDriven"); // "MC", "DataDrivenR", "None" //string bbPurity("None"); // "MC", "DataDrivenR", "None" bool onlineBtagCorr = true; int nSyst = 4; std::string systName[] = { "JES", "SFbc", "SFudsg", "JER" }; bool realDataNuisance[] = { false, true, true, false }; // indicate if relevant for real data const int nUpDown = 2; std::string signalFile = ""; bool dosignal=true; #if defined(MEDIUM2012) dosignal=false; nTCombData=1; ///only one trigger //nSyst=0; /// no syst templates #endif // signal templates if (IgorVersion != "V3") { std::cout << "Using signal files " << IgorVersion << std::endl; signalFile.assign( Form("%s/theMergeList-SUSYBBHToBB_M-%d_7TeV-pythia6-tauola%s/SF/job_1/TripleBtagAnalysisM-%d_%s.root",IgorPath.c_str(),signalMass[iMass],spacer.c_str(),signalMass[iMass],IgorScen.c_str() ) ); } else { std::cout << "Using V3 signal files" << std::endl; signalFile.assign( Form("/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/Systematics-test-3/%s/theMergeList-SUSYBBHToBB_M-%d_7TeV-pythia6-tauola%s/SF/job_1/TripleBtagAnalysisM-%d_%s.root",signalMode.c_str(),signalMass[iMass],spacer.c_str(),signalMass[iMass],IgorScen.c_str() ) ); } std::string signalSystFiles[nSyst][nUpDown]; //bool activeNuisance[nSyst] = { true, true, true }; std::string upDownName[nUpDown] = { "Up", "Down" }; TH2F* hSignalSyst[nSyst][nUpDown][nbtag]; // output file TFile* hout = new TFile(Form("packedTemplates-M-%d.root",signalMass[iMass]),"recreate"); hout->cd(); TH2::AddDirectory(true); TFile* fSig = new TFile( signalFile.c_str() ); if ( fSig == NULL ) { std::cout << "Could not open signal central file " << signalFile.c_str() << std::endl; return; } else { std::cout << "Open signal file " << signalFile.c_str() << std::endl; } TH2F* hSignalCentral[nbtag]; for (int ibtag=0; ibtag<nbtag; ++ibtag) { hSignalCentral[ibtag] = mergeSignal(fSig,Form(signalHistPattern.c_str(),sbtag[ibtag].c_str()), Form("bbH_%s",sbtag[ibtag].c_str())); // read the efficiency TH1F* histEffMerged = (TH1F*) fSig->Get(Form("TrigEff/EffMerged%s",sbtag[ibtag].c_str())); if ( histEffMerged == NULL) { std::cout << "Efficiency histo not found" << std::endl; return; } double newEff = histEffMerged->GetBinContent(1); std::cout << "Mass= " << signalMass[iMass] << " btag= " << sbtag[ibtag] << " Efficiency = " << newEff << std::endl; efficiency[iMass][ibtag] = newEff; double normShould = 1000 * intLumi * efficiency[iMass][ibtag]; double normIs = hSignalCentral[ibtag]->GetSumOfWeights(); std::cout << hSignalCentral[ibtag]->GetName() << " TotalContents=" << hSignalCentral[ibtag]->GetSumOfWeights() << std::endl; fScal[iMass][ibtag] = normShould / normIs; std::cout << "normShould = " << normShould << " normIs " << normIs << " rescale by " << fScal[iMass][ibtag] << std::endl; hSignalCentral[ibtag]->Scale( fScal[iMass][ibtag] ); hout->cd(); hSignalCentral[ibtag]->Write(); histEffMerged->Write(); // create empty file just as marker ofstream markerFile; markerFile.open(Form("pack-%s-%s.txt",sbtag[ibtag].c_str(),scenario.c_str()),ios::app); markerFile << "Template for mass " << signalMass[iMass] << std::endl; markerFile.close(); } // read the nominal cross section TH1F* histXSect = (TH1F*) fSig->Get("xsection/xsect"); if ( histXSect == NULL) { std::cout << "xsection/xsect" << " not found" << std::endl; return; } histXSect->Write(); for (int iSyst=0; iSyst<nSyst; ++iSyst) { for (int iUpDown=0; iUpDown<nUpDown; ++iUpDown) { if (IgorVersion != "V3") { signalSystFiles[iSyst][iUpDown] = Form( "%s/theMergeList-SUSYBBHToBB_M-%d_7TeV-pythia6-tauola%s/%s_Sys%s/job_1/TripleBtagAnalysisM-%d_%s.root", IgorPath.c_str(),signalMass[iMass],spacer.c_str(),systName[iSyst].c_str(), upDownName[iUpDown].c_str(),signalMass[iMass],IgorScen.c_str()); } else { signalSystFiles[iSyst][iUpDown] = Form( "/data/user/marfin/CMSSW_5_0_1/src/Analysis/HbbMSSMAnalysis/test/Systematics-test-3/%s/theMergeList-SUSYBBHToBB_M-%d_7TeV-pythia6-tauola%s/%s_Sys%s/job_1/TripleBtagAnalysisM-%d_%s.root", signalMode.c_str(),signalMass[iMass],spacer.c_str(),systName[iSyst].c_str(), upDownName[iUpDown].c_str(),signalMass[iMass],IgorScen.c_str()); } std::cout << "Signal systematics file " << signalSystFiles[iSyst][iUpDown] << std::endl; TFile* fSigSys = new TFile( signalSystFiles[iSyst][iUpDown].c_str() ); if ( fSigSys == NULL ) { std::cout << "Could not open signal syst file " << signalSystFiles[iSyst][iUpDown].c_str() << std::endl; return; } for (int ibtag=0; ibtag<nbtag; ++ibtag) { hSignalSyst[iSyst][iUpDown][ibtag] = mergeSignal(fSigSys,Form(signalHistPattern.c_str(),sbtag[ibtag].c_str()), Form("bbH_%s_%s_%s",systName[iSyst].c_str(), upDownName[iUpDown].c_str(),sbtag[ibtag].c_str())); std::cout << "The merged hist has name " << hSignalSyst[iSyst][iUpDown][ibtag]->GetName() << std::endl; std::cout << hSignalSyst[iSyst][iUpDown][ibtag]->GetName() << " TotalContents=" << hSignalSyst[iSyst][iUpDown][ibtag]->GetSumOfWeights() << std::endl; hSignalSyst[iSyst][iUpDown][ibtag]->Scale( fScal[iMass][ibtag] ); hout->cd(); hSignalSyst[iSyst][iUpDown][ibtag]->Write(); } fSigSys->Close(); } } // real data std::string backgroundFile( Form("/afs/naf.desy.de/user/r/rmankel/scratch/HbbPat/CMSSW_4_2_4_patch1/src/Analysis/HbbMSSMAnalysis/test/results/v1/%s/TripleBtagAnalysis_SF/TripleBtagAnalysis.root",SashaPath.c_str()) ); #if defined(MEDIUM2012) //bool dosignal=true; //backgroundFile = std::string("/data/user/marfin/CMSSW_5_3_3/src/Analysis/HbbMSSMAnalysis/test/Analysis2012/MVA-production-selection-trees/TripleBtagAnalysis.root"); backgroundFile = std::string("/data/user/marfin/CMSSW_5_3_3/src/Analysis/HbbMSSMAnalysis/test/Analysis2012/Blind-test-BG-only-Fit/MEDIUM/TripleBtagAnalysis_SF/TripleBtagAnalysis.root"); #endif std::cout << "Background central file : " << backgroundFile << std::endl; TFile* fBac = new TFile( backgroundFile.c_str() ); if ( fBac == NULL ) { std::cout << "Could not open background central file " << signalFile.c_str() << std::endl; return; } // hist-to-be-fitted TH2F* mjjEbtdata[nbtag]; for (int ibtag=0; ibtag<nbtag; ++ibtag) { mjjEbtdata[ibtag] = getTrigsAndMerge(fBac,Form("massEvBtag/mjjEvBTag_%s",sbtag[ibtag].c_str()),nTCombData,tCombData); if (mjjEbtdata[ibtag] == NULL) { std::cout << "Histogram not found: " << Form("massEvBtag/mjjEvBTag_%s",sbtag[ibtag].c_str()) << std::endl; return; } // rename mjjEbtdata[ibtag]->SetName( Form("Data_%s",sbtag[ibtag].c_str() ) ); hout->cd(); mjjEbtdata[ibtag]->Write(); } TH2F* hBackgroundCentral[nbtag][ncateg][nfc]; TH2F* hBackgroundCentralError[nbtag][ncateg][nfc]; for (int ibtag=0; ibtag<nbtag; ++ibtag) { for (int icateg=0; icateg<ncateg; ++icateg) { int theTpat; if (onlineBtagCorr) { theTpat = 3; } else { theTpat = icateg; } for (int ifc=0; ifc<nfc; ++ifc) { string templateCore("massBTagTemplatesCld/MassBTagTemplateCld"); if (bbPurity == "None") { templateCore.assign("massBTagTemplatesCld/MassBTagTemplateUncld"); } string hbSystName( Form("%s_%s_%s_Cat%dTpat%d",templateCore.c_str(), sfc[ifc].c_str(),sbtag[ibtag].c_str(),icateg,theTpat) ); hBackgroundCentral[ibtag][icateg][ifc] = getTrigsAndMerge(fBac,Form("%s_%s_%s_Cat%dTpat%d", templateCore.c_str(), sfc[ifc].c_str(), sbtag[ibtag].c_str(),icateg,theTpat),nTCombData,tCombData); if ( hBackgroundCentral[ibtag][icateg][ifc] == NULL ) { std::cout << "Hist not found: " << hbSystName << std::endl; return; } // rename templateId tName(ifc,icateg); hBackgroundCentral[ibtag][icateg][ifc]->SetName( Form("%s_%s",tName.name().c_str(),sbtag[ibtag].c_str()) ); // read the template errors templateCore.assign("errorMassBTagTemplates/ErrorMassBTagTemplate"); string hbSystNameError( Form("%s_%s_%s_Cat%dTpat%d",templateCore.c_str(), sfc[ifc].c_str(),sbtag[ibtag].c_str(),icateg,theTpat) ); hBackgroundCentralError[ibtag][icateg][ifc] = getTrigsAndMerge(fBac,Form("%s_%s_%s_Cat%dTpat%d", templateCore.c_str(), sfc[ifc].c_str(), sbtag[ibtag].c_str(),icateg,theTpat),nTCombData,tCombData); if ( hBackgroundCentralError[ibtag][icateg][ifc] == NULL ) { std::cout << "Hist not found: " << hbSystNameError << std::endl; return; } if (useTemplateError) { // add the template error std::cout << " ==== Adding Btag Errors ==== " << hBackgroundCentral[ibtag][icateg][ifc]->GetName() << std::endl; for (int ibinx=1; ibinx<= (hBackgroundCentral[ibtag][icateg][ifc]->GetXaxis()->GetNbins()); ++ibinx) { for (int ibiny=1; ibiny<= (hBackgroundCentral[ibtag][icateg][ifc]->GetYaxis()->GetNbins()); ++ibiny) { float oldError = hBackgroundCentral[ibtag][icateg][ifc]->GetBinError(ibinx,ibiny); float addError = hBackgroundCentralError[ibtag][icateg][ifc]->GetBinContent(ibinx,ibiny); float newError = sqrt( oldError * oldError + addError * addError ); hBackgroundCentral[ibtag][icateg][ifc]->SetBinError(ibinx,ibiny,newError); } } } hout->cd(); hBackgroundCentral[ibtag][icateg][ifc]->Write(); } } } std::string backgroundSystFiles[nSyst][nUpDown]; std::string systNameSasha[] = { "JES", "SFbc", "SFq" }; std::string upDownNameSasha[nUpDown] = { "plus2", "minus2" }; TH2F* hBackgroundSyst[nSyst][nUpDown][nbtag][ncateg][nfc]; TH2F* hBackgroundSystError[nSyst][nUpDown][nbtag][ncateg][nfc]; //#if !defined(MEDIUM2012) // for nuisances like JEC, the up/down templates are just copies of the central templates for (int iSyst=0; iSyst<nSyst; ++iSyst) { if (! realDataNuisance[iSyst]) { std::cout << "Non-real data relevant nuisance: " << systName[iSyst].c_str() << std::endl; for (int iUpDown=0; iUpDown<nUpDown; ++iUpDown) { for (int ibtag=0; ibtag<nbtag; ++ibtag) { for (int icateg=0; icateg<ncateg; ++icateg) { for (int ifc=0; ifc<nfc; ++ifc) { hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] = new TH2F( *hBackgroundCentral[ibtag][icateg][ifc] ); // rename templateId tName(ifc,icateg); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] ->SetName( Form("%s_%s_%s_%s", tName.name().c_str(),systName[iSyst].c_str(), upDownName[iUpDown].c_str(),sbtag[ibtag].c_str()) ); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->Write(); } } } } } } //#endif fBac->Close(); for (int iSyst=0; iSyst<nSyst; ++iSyst) { if (realDataNuisance[iSyst]) { std::cout << "Real data relevant nuisance: " << systName[iSyst].c_str() << std::endl; for (int iUpDown=0; iUpDown<nUpDown; ++iUpDown) { // backgroundSystFiles[iSyst][iUpDown] = Form( "/afs/naf.desy.de/user/r/rmankel/scratch/HbbPat/CMSSW_4_2_4_patch1/src/Analysis/HbbMSSMAnalysis/test/results/v1/%s/TripleBtagAnalysis_%s%s/TripleBtagAnalysis.root",SashaPath.c_str(),systNameSasha[iSyst].c_str(),upDownNameSasha[iUpDown].c_str() ); backgroundSystFiles[iSyst][iUpDown] = Form( "/data/user/marfin/CMSSW_5_3_3/src/Analysis/HbbMSSMAnalysis/test/Analysis2012/Blind-test-BG-only-Fit/MEDIUM/TripleBtagAnalysis_%s%s/TripleBtagAnalysis.root",systNameSasha[iSyst].c_str(),upDownNameSasha[iUpDown].c_str() ); TFile* fBacSys = new TFile( backgroundSystFiles[iSyst][iUpDown].c_str() ); std::cout << "Background systematics file " << backgroundSystFiles[iSyst][iUpDown] << std::endl; if ( fBacSys == NULL ) { std::cout << "Could not open background syst file " << backgroundSystFiles[iSyst][iUpDown] << std::endl; return; } for (int ibtag=0; ibtag<nbtag; ++ibtag) { for (int icateg=0; icateg<ncateg; ++icateg) { int theTpat; if (onlineBtagCorr) { theTpat = 3; } else { theTpat = icateg; } for (int ifc=0; ifc<nfc; ++ifc) { string templateCore("massBTagTemplatesCld/MassBTagTemplateCld"); if (bbPurity == "None") { templateCore.assign("massBTagTemplatesCld/MassBTagTemplateUncld"); } string hbSystName( Form("%s_%s_%s_Cat%dTpat%d",templateCore.c_str(), sfc[ifc].c_str(),sbtag[ibtag].c_str(),icateg,theTpat) ); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] = getTrigsAndMerge(fBacSys,Form("%s_%s_%s_Cat%dTpat%d", templateCore.c_str(), sfc[ifc].c_str(), sbtag[ibtag].c_str(),icateg,theTpat),nTCombData,tCombData); if ( hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] == NULL ) { std::cout << "Hist not found: " << hbSystName << std::endl; return; } // rename templateId tName(ifc,icateg); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc] ->SetName( Form("%s_%s_%s_%s", tName.name().c_str(),systName[iSyst].c_str(), upDownName[iUpDown].c_str(),sbtag[ibtag].c_str()) ); // read template errors templateCore.assign("errorMassBTagTemplates/ErrorMassBTagTemplate"); string hbSystNameError( Form("%s_%s_%s_Cat%dTpat%d",templateCore.c_str(), sfc[ifc].c_str(),sbtag[ibtag].c_str(),icateg,theTpat) ); hBackgroundSystError[iSyst][iUpDown][ibtag][icateg][ifc] = getTrigsAndMerge(fBacSys,Form("%s_%s_%s_Cat%dTpat%d", templateCore.c_str(), sfc[ifc].c_str(), sbtag[ibtag].c_str(),icateg,theTpat),nTCombData,tCombData); if ( hBackgroundSystError[iSyst][iUpDown][ibtag][icateg][ifc] == NULL ) { std::cout << "Hist not found: " << hbSystNameError << std::endl; return; } if (useTemplateError) { // add the template error std::cout << " ==== ErrorAdd ==== " << hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetName() << std::endl; for (int ibinx=1; ibinx<= (hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetXaxis()->GetNbins()); ++ibinx) { for (int ibiny=1; ibiny<= (hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetYaxis()->GetNbins()); ++ibiny) { float oldError = hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetBinError(ibinx,ibiny); float addError = hBackgroundSystError[iSyst][iUpDown][ibtag][icateg][ifc]->GetBinContent(ibinx,ibiny); float newError = sqrt( oldError * oldError + addError * addError ); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->SetBinError(ibinx,ibiny,newError); } } } hout->cd(); hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->Write(); } } } fBacSys->Close(); } } } std::cout << "Everything done " << std::endl; #ifdef PROJECTIONS TFile * projections_out=TFile::Open("projections.root","RECREATE"); // loop over background templates //TH1D* bgProX[nbtag][ncateg][nfc]; TH1D* bgSystProX[nSyst][nUpDown][nbtag][ncateg][nfc]; for (int ibtag=0; ibtag<nbtag; ++ibtag) { for (int icateg=0; icateg<ncateg; ++icateg) { for (int ifc=0; ifc<nfc; ++ifc) { TH2F* theTemp = hBackgroundCentral[ibtag][icateg][ifc]; TH1D* theTempProX = theTemp->ProjectionX(Form("%sProX",theTemp->GetName()),0,-1,"e"); theTempProX->SetName( Form("%sProX",theTemp->GetName()) ); TH1D* theTempProY = theTemp->ProjectionY(Form("%sProY",theTemp->GetName()),0,-1,"e"); std::cout << "Made projection " << theTempProX->GetName() << std::endl; if ( (icateg == 0) && (ifc == 0) ) { for (int ibinx=1; ibinx<= theTempProX->GetXaxis()->GetNbins(); ++ibinx) { std::cout << ibinx << " content " << theTempProX->GetBinContent(ibinx) << " error " << theTempProX->GetBinError(ibinx) << std::endl; } } theTempProX->SetMarkerStyle(20); theTempProX->SetMarkerColor(1); theTempProX->SetLineColor(1); theTempProX->SetMarkerSize(1); std::cout << "Draw" << std::endl; theTempProX->Draw("EP"); theTempProX->Write(); //theTempProX->Draw("LP,SAME"); // draw the SFbc systematics int colSyst[3] = {1, 2, 4}; int lstyleUpDown[2] = {1, 1}; for (int iSyst=1; iSyst<nSyst; ++iSyst) { for (int iUpDown=0; iUpDown<nUpDown; ++iUpDown) { bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc] = hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->ProjectionX(Form("%sProXX",hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetName()),0,-1,"e"); bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->SetName( Form("%sProXX",hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]->GetName()) ); std::cout << "Made projection " << bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->GetName() << std::endl; bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->SetLineColor( colSyst[iSyst] ); bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->Draw("HIST,SAME"); bgSystProX[iSyst][iUpDown][ibtag][icateg][ifc]->Write(); // TH2F* theTemp = hBackgroundSyst[iSyst][iUpDown][ibtag][icateg][ifc]; // TH1D* theTempProX = theTemp->ProjectionX(Form("%sProX",theTemp->GetName()),0,-1,"e"); // theTempProX->SetLineColor( colSyst[iSyst] ); // TH1D* theTempProY = theTemp->ProjectionY(Form("%sProY",theTemp->GetName()),0,-1,"e"); // theTempProY->SetLineColor( colSyst[iSyst] ); // //theTempProX->Draw("HIST"); } } canvas->Print(Form("Template_%s_%s_Cat%d_ProX.png",sbtag[ibtag].c_str(),sfc[ifc].c_str(),icateg)); theTempProY->SetMarkerStyle(20); theTempProY->SetMarkerColor(1); theTempProY->SetLineColor(1); theTempProY->SetMarkerSize(1); std::cout << "Draw" << std::endl; theTempProY->Draw("EP"); theTempProY->Write(); } } } projections_out->Write(); projections_out->Close(); #endif hout->Write(); hout->Close(); // close the signal central file fSig->Close(); return; }
void makePlots_hltEleHT_TTcr( bool printPDF_ = false, int useSample_ = 0 ){ TH1::SetDefaultSumw2(); int NumSamples = 3; TFile* file[NumSamples]; file[0] = new TFile("HistoFiles/hltEleHT_treeReader_TTcr_TT_13TeV_Spring15_Asympt25ns_histo.root"); file[1] = new TFile("HistoFiles/hltEleHT_treeReader_TTcr_ttHTobb_M125_13TeV_powheg_pythia8_Spring15_Asympt25ns_histo.root"); file[2] = new TFile("HistoFiles/hltEleHT_treeReader_TTcr_SingleElectron_Run2015D_PromptReco_254231_258158_histo.root"); std::vector<TString> histLabels(NumSamples); histLabels[0] = "TTJets"; histLabels[1] = "ttHTobb"; histLabels[2] = "Data"; Color_t color[5]; color[0] = kBlack; color[1] = kBlue; color[2] = kRed; color[3] = kGreen+1; // color[2] = kBlack; // color[3] = kGreen+1; // color[4] = kMagenta+2; // color[5] = kRed+1; // color[6] = kGreen-5; // color[7] = kRed+3; std::vector<std::vector<int> > projection_start_bins; std::vector<std::vector<int> > projection_end_bins; std::vector<std::vector<TString> > projection_labels; // elePt std::vector<int> proj_elePt_start_bins; proj_elePt_start_bins.push_back(1); proj_elePt_start_bins.push_back(4); proj_elePt_start_bins.push_back(6); proj_elePt_start_bins.push_back(7); std::vector<int> proj_elePt_end_bins; proj_elePt_end_bins.push_back(12); proj_elePt_end_bins.push_back(5); proj_elePt_end_bins.push_back(8); proj_elePt_end_bins.push_back(12); std::vector<TString> proj_elePt_labels; proj_elePt_labels.push_back("elePt30toInf"); proj_elePt_labels.push_back("elePt30to50"); proj_elePt_labels.push_back("elePt50to80"); proj_elePt_labels.push_back("elePt80toInf"); // numJet std::vector<int> proj_numJet_start_bins; proj_numJet_start_bins.push_back(1); proj_numJet_start_bins.push_back(1); proj_numJet_start_bins.push_back(4); proj_numJet_start_bins.push_back(5); std::vector<int> proj_numJet_end_bins; proj_numJet_end_bins.push_back(8); proj_numJet_end_bins.push_back(3); proj_numJet_end_bins.push_back(4); proj_numJet_end_bins.push_back(8); std::vector<TString> proj_numJet_labels; proj_numJet_labels.push_back("numJet0toInf"); proj_numJet_labels.push_back("numJet0to2"); proj_numJet_labels.push_back("numJet3to3"); proj_numJet_labels.push_back("numJet4toInf"); projection_start_bins.push_back(proj_elePt_start_bins); projection_end_bins.push_back(proj_elePt_end_bins); projection_labels.push_back(proj_elePt_labels); projection_start_bins.push_back(proj_numJet_start_bins); projection_end_bins.push_back(proj_numJet_end_bins); projection_labels.push_back(proj_numJet_labels); projection_start_bins.push_back(proj_elePt_start_bins); projection_end_bins.push_back(proj_elePt_end_bins); projection_labels.push_back(proj_elePt_labels); projection_start_bins.push_back(proj_elePt_start_bins); projection_end_bins.push_back(proj_elePt_end_bins); projection_labels.push_back(proj_elePt_labels); std::vector<int> NumProjBins; NumProjBins.push_back( int(proj_elePt_labels.size()) ); NumProjBins.push_back( int(proj_numJet_labels.size()) ); NumProjBins.push_back( int(proj_elePt_labels.size()) ); NumProjBins.push_back( int(proj_elePt_labels.size()) ); TString dirprefix = "Images/Images_2015_10_13_hltEleHT_TTcr_" + histLabels[useSample_] + "/"; struct stat st; if( stat(dirprefix.Data(),&st) != 0 ) mkdir(dirprefix.Data(),0777); ///////////////////////////////////////////////////////////////////////////////////////////////////////////// std::vector<std::string> histoname1; std::vector<std::string> histoname2; std::vector<std::string> histoname3; histoname1.push_back("h_HT30"); histoname1.push_back("h_HT30er"); histoname1.push_back("h_HT30_4j"); histoname2.push_back("elePt"); histoname2.push_back("numJet"); histoname2.push_back("eleEBPt"); histoname2.push_back("eleEEPt"); histoname3.push_back("h_event_selection"); ///////////////////////////////////////////////////////////////////////////////////////////////////////////// TGaxis::SetMaxDigits(3); TString lumiinfo = "553 pb^{-1} (13 TeV)"; TLatex LumiInfoLatex(0.65, 0.94, lumiinfo); LumiInfoLatex.SetNDC(); LumiInfoLatex.SetTextFont(42); LumiInfoLatex.SetTextSize(0.04); //TString cmsinfo = "CMS Preliminary"; TString cmsinfo = "CMS"; TLatex CMSInfoLatex(0.13, 0.94, cmsinfo); CMSInfoLatex.SetNDC(); CMSInfoLatex.SetTextFont(42); CMSInfoLatex.SetTextFont(61); CMSInfoLatex.SetTextSize(0.055); //SBOUTLE std::string publishinfo = "Preliminary"; //DPUIGH TLatex PublishInfoLatex(0.26, 0.94, publishinfo.c_str()); //SBOUTLE PublishInfoLatex.SetNDC(); PublishInfoLatex.SetTextFont(52); PublishInfoLatex.SetTextSize(0.045); //SBOUTLE TString plotname; TCanvas* c1 = new TCanvas("c1", "c1", 600,700); TH2D* h_L1HTT_elePt = (TH2D*)file[useSample_]->Get("h_L1HTT_elePt"); TH2D* h_HT30_HT30er = (TH2D*)file[useSample_]->Get("h_HT30_HT30er"); TH2D* h_HT30_L1HTT = (TH2D*)file[useSample_]->Get("h_HT30_L1HTT"); TProfile* p_L1HTT_elePt = (TProfile*)h_L1HTT_elePt->ProfileX("p_L1HTT_elePt"); // TProfile* p_HT30_HT30er = (TProfile*)h_HT30_HT30er->ProfileX("p_HT30_HT30er"); // TProfile* p_HT30_L1HTT = (TProfile*)h_HT30_L1HTT->ProfileX("p_HT30_L1HTT"); p_L1HTT_elePt->SetMarkerStyle(20); h_L1HTT_elePt->Draw("colz"); p_L1HTT_elePt->Draw("pe1same"); plotname = dirprefix + "h_L1HTT_elePt" + "_2D_colz.png"; c1->Print(plotname); h_HT30_HT30er->Draw("colz"); //p_HT30_HT30er->Draw("pe1same"); plotname = dirprefix + "h_HT30_HT30er" + "_2D_colz.png"; c1->Print(plotname); h_HT30_L1HTT->Draw("colz"); //p_HT30_L1HTT->Draw("pe1same"); plotname = dirprefix + "h_HT30_L1HTT" + "_2D_colz.png"; c1->Print(plotname); for( int i=0; i<int(histoname1.size()); i++ ){ for( int j=0; j<int(histoname2.size()); j++ ){ for( int k=0; k<2; k++ ){ TString temp = histoname1[i]; TString suffix = histoname2[j]; TString l1suffix = ( k==0 ) ? "125" : "100"; if( temp!="h_HT30" && suffix!="elePt" ) continue; TString temp_L1 = temp + "_L1HTT" + l1suffix + "_" + suffix; TString temp_HLT = temp + "_L1HTT" + l1suffix + "_passHLTEle27HT200_" + suffix; TString temp_mh = temp; temp_mh.ReplaceAll("h_",""); temp = temp + "_" + suffix; //TLegend *legend = new TLegend(0.2,0.83,0.9,0.89); TLegend *legend = new TLegend(0.2,0.85,0.9,0.91); legend->SetFillColor(kWhite); legend->SetLineColor(kWhite); legend->SetShadowColor(kWhite); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->SetNColumns(2); int rebin = ( useSample_==2 ) ? 25 : 10; TH2D* h_all = (TH2D*)file[useSample_]->Get(temp)->Clone(temp+"_"+suffix+"_"+l1suffix); TH2D* h_l1t = (TH2D*)file[useSample_]->Get(temp_L1)->Clone(temp_L1+"_"+suffix+"_"+l1suffix); TH2D* h_hlt = (TH2D*)file[useSample_]->Get(temp_HLT)->Clone(temp_HLT+"_"+suffix+"_"+l1suffix); TH2D* h_temp_hlt_all = (TH2D*)h_all->Clone("h_temp_hlt_all_"+suffix+"_"+l1suffix); TH2D* h_temp_l1t_all = (TH2D*)h_all->Clone("h_temp_l1t_all_"+suffix+"_"+l1suffix); TH2D* h_temp_hlt_l1t = (TH2D*)h_l1t->Clone("h_temp_hlt_l1t_"+suffix+"_"+l1suffix); TH2D* h_ratio_hlt_all = (TH2D*)h_hlt->Clone("h_ratio_hlt_all_"+suffix+"_"+l1suffix); TH2D* h_ratio_l1t_all = (TH2D*)h_l1t->Clone("h_ratio_l1t_all_"+suffix+"_"+l1suffix); TH2D* h_ratio_hlt_l1t = (TH2D*)h_hlt->Clone("h_ratio_hlt_l1t_"+suffix+"_"+l1suffix); h_temp_hlt_all->RebinY(rebin); h_temp_l1t_all->RebinY(rebin); h_temp_hlt_l1t->RebinY(rebin); h_ratio_hlt_all->RebinY(rebin); h_ratio_l1t_all->RebinY(rebin); h_ratio_hlt_l1t->RebinY(rebin); h_ratio_hlt_all->Divide(h_temp_hlt_all); h_ratio_l1t_all->Divide(h_temp_l1t_all); h_ratio_hlt_l1t->Divide(h_temp_hlt_l1t); TProfile* p_all = (TProfile*)h_all->ProfileX("p_all"); TProfile* p_l1t = (TProfile*)h_l1t->ProfileX("p_l1t"); TProfile* p_hlt = (TProfile*)h_hlt->ProfileX("p_hlt"); p_all->SetMarkerStyle(20); p_l1t->SetMarkerStyle(20); p_hlt->SetMarkerStyle(20); h_all->Draw("colz"); p_all->Draw("pe1same"); plotname = dirprefix + temp + "_2D_colz.png"; c1->Print(plotname); h_l1t->Draw("colz"); p_l1t->Draw("pe1same"); plotname = dirprefix + temp_L1 + "_2D_colz.png"; c1->Print(plotname); h_hlt->Draw("colz"); p_hlt->Draw("pe1same"); plotname = dirprefix + temp_HLT + "_2D_colz.png"; c1->Print(plotname); h_ratio_hlt_all->SetStats(0); h_ratio_hlt_all->GetYaxis()->SetRangeUser(0.,400.); h_ratio_hlt_all->Draw("colz"); plotname = dirprefix + "h_ratio_hlt_all" + "_2D_colz.png"; c1->Print(plotname); h_ratio_l1t_all->SetStats(0); h_ratio_l1t_all->GetYaxis()->SetRangeUser(0.,400.); h_ratio_l1t_all->Draw("colz"); plotname = dirprefix + "h_ratio_l1t_all" + "_2D_colz.png"; c1->Print(plotname); h_ratio_hlt_l1t->SetStats(0); h_ratio_hlt_l1t->GetYaxis()->SetRangeUser(0.,400.); h_ratio_hlt_l1t->Draw("colz"); plotname = dirprefix + "h_ratio_hlt_l1t" + "_2D_colz.png"; c1->Print(plotname); int numProjBin = NumProjBins[j]; TH1D* h_py_all[numProjBin]; TH1D* h_py_l1t[numProjBin]; TH1D* h_py_hlt[numProjBin]; TEfficiency* eff_hlt_all[numProjBin]; TEfficiency* eff_l1t_all[numProjBin]; TEfficiency* eff_hlt_l1t[numProjBin]; for( int iBin=0; iBin<numProjBin; iBin++ ){ int bin_start = projection_start_bins[j][iBin]; int bin_end = projection_end_bins[j][iBin]; h_py_all[iBin] = (TH1D*)h_all->ProjectionY(Form("h_py_all_%d",iBin),bin_start,bin_end); h_py_l1t[iBin] = (TH1D*)h_l1t->ProjectionY(Form("h_py_l1t_%d",iBin),bin_start,bin_end); h_py_hlt[iBin] = (TH1D*)h_hlt->ProjectionY(Form("h_py_hlt_%d",iBin),bin_start,bin_end); h_py_all[iBin]->Rebin(rebin); h_py_l1t[iBin]->Rebin(rebin); h_py_hlt[iBin]->Rebin(rebin); eff_l1t_all[iBin] = makeEfficiency(h_py_l1t[iBin], h_py_all[iBin]); eff_hlt_l1t[iBin] = makeEfficiency(h_py_hlt[iBin], h_py_l1t[iBin]); eff_hlt_all[iBin] = makeEfficiency(h_py_hlt[iBin], h_py_all[iBin]); eff_l1t_all[iBin]->SetLineColor(color[iBin]); eff_l1t_all[iBin]->SetMarkerColor(color[iBin]); eff_l1t_all[iBin]->SetMarkerStyle(20); eff_hlt_l1t[iBin]->SetLineColor(color[iBin]); eff_hlt_l1t[iBin]->SetMarkerColor(color[iBin]); eff_hlt_l1t[iBin]->SetMarkerStyle(20); eff_hlt_all[iBin]->SetLineColor(color[iBin]); eff_hlt_all[iBin]->SetMarkerColor(color[iBin]); eff_hlt_all[iBin]->SetMarkerStyle(20); legend->AddEntry(eff_l1t_all[iBin], projection_labels[j][iBin],"pe1"); } h_py_all[0]->SetStats(0); h_py_all[0]->GetYaxis()->SetTitle("Efficiency"); h_py_all[0]->GetYaxis()->SetRangeUser(0.,1.15); h_py_all[0]->GetXaxis()->SetRangeUser(0.,600.); // h_data_all->SetStats(0); c1->SetTopMargin(.07); c1->SetRightMargin(.05); // h_data_all->GetYaxis()->SetTitleOffset(1.0); // h_data_all->GetYaxis()->SetTitleSize(0.05); // h_data_all->GetYaxis()->SetRangeUser(0.,1.15); // if( temp.Contains("_pt") ){ // h_data_all->GetXaxis()->SetRangeUser(0.,150.); // myRatio->GetXaxis()->SetRangeUser(0.,150.); // } //// l1t_all h_py_all[0]->Draw("axis"); for( int iBin=0; iBin<numProjBin; iBin++ ) eff_l1t_all[iBin]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_"+suffix+"_l1t" + l1suffix + "_all_lin.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_"+suffix+"_l1t" + l1suffix + "_all_lin.pdf"; if( printPDF_ ) c1->Print(plotname); //// hlt_all h_py_all[0]->Draw("axis"); for( int iBin=0; iBin<numProjBin; iBin++ ) eff_hlt_all[iBin]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_all_lin.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_all_lin.pdf"; if( printPDF_ ) c1->Print(plotname); //// hlt_l1t h_py_all[0]->Draw("axis"); for( int iBin=0; iBin<numProjBin; iBin++ ) eff_hlt_l1t[iBin]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_lin.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_lin.pdf"; if( printPDF_ ) c1->Print(plotname); h_py_all[0]->GetYaxis()->SetRangeUser(0.85,1.15); //// l1t_all h_py_all[0]->Draw("axis"); for( int iBin=0; iBin<numProjBin; iBin++ ) eff_l1t_all[iBin]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_"+suffix+"_l1t" + l1suffix + "_all_lin_zoom.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_"+suffix+"_l1t" + l1suffix + "_all_lin_zoom.pdf"; if( printPDF_ ) c1->Print(plotname); //// hlt_all h_py_all[0]->Draw("axis"); for( int iBin=0; iBin<numProjBin; iBin++ ) eff_hlt_all[iBin]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_all_lin_zoom.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_all_lin_zoom.png"; if( printPDF_ ) c1->Print(plotname); //// hlt_l1t h_py_all[0]->Draw("axis"); for( int iBin=0; iBin<numProjBin; iBin++ ) eff_hlt_l1t[iBin]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_lin_zoom.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_"+suffix+"_hlt_l1t" + l1suffix + "_lin_zoom.pdf"; if( printPDF_ ) c1->Print(plotname); delete legend; } // end loop on hists } } if( true ){ TString temp = "h_HT30"; TString temp_L1 = temp + "_L1HTT125"; TString temp_HLT = temp + "_L1HTT125_passHLTEle27HT200"; TString temp_mh = temp; temp_mh.ReplaceAll("h_",""); //TLegend *legend = new TLegend(0.2,0.83,0.9,0.89); TLegend *legend = new TLegend(0.2,0.87,0.85,0.91); legend->SetFillColor(kWhite); legend->SetLineColor(kWhite); legend->SetShadowColor(kWhite); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->SetNColumns(3); int rebin = 25; TH1D* h_all[NumSamples]; TH1D* h_l1t[NumSamples]; TH1D* h_hlt[NumSamples]; TEfficiency* eff_hlt_all[NumSamples]; TEfficiency* eff_l1t_all[NumSamples]; TEfficiency* eff_hlt_l1t[NumSamples]; for( int iSample=0; iSample<NumSamples; iSample++ ){ h_all[iSample] = (TH1D*)file[iSample]->Get(temp.Data())->Clone(Form("%s_%s",temp.Data(),histLabels[iSample].Data())); h_l1t[iSample] = (TH1D*)file[iSample]->Get(temp_L1.Data())->Clone(Form("%s_%s",temp.Data(),histLabels[iSample].Data())); h_hlt[iSample] = (TH1D*)file[iSample]->Get(temp_HLT.Data())->Clone(Form("%s_%s",temp.Data(),histLabels[iSample].Data())); h_all[iSample]->Rebin(rebin); h_l1t[iSample]->Rebin(rebin); h_hlt[iSample]->Rebin(rebin); eff_l1t_all[iSample] = makeEfficiency(h_l1t[iSample], h_all[iSample]); eff_hlt_l1t[iSample] = makeEfficiency(h_hlt[iSample], h_l1t[iSample]); eff_hlt_all[iSample] = makeEfficiency(h_hlt[iSample], h_all[iSample]); eff_l1t_all[iSample]->SetLineColor(color[iSample]); eff_l1t_all[iSample]->SetMarkerColor(color[iSample]); eff_l1t_all[iSample]->SetMarkerStyle(20); eff_hlt_l1t[iSample]->SetLineColor(color[iSample]); eff_hlt_l1t[iSample]->SetMarkerColor(color[iSample]); eff_hlt_l1t[iSample]->SetMarkerStyle(20); eff_hlt_all[iSample]->SetLineColor(color[iSample]); eff_hlt_all[iSample]->SetMarkerColor(color[iSample]); eff_hlt_all[iSample]->SetMarkerStyle(20); legend->AddEntry(eff_l1t_all[iSample], histLabels[iSample],"pl"); } h_all[0]->SetStats(0); h_all[0]->GetYaxis()->SetTitle("Efficiency"); h_all[0]->GetYaxis()->SetRangeUser(0.,1.15); h_all[0]->GetXaxis()->SetRangeUser(0.,600.); //// l1t_all h_all[0]->Draw("axis"); for( int iSample=0; iSample<NumSamples; iSample++ ) eff_l1t_all[iSample]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_compareSamples_l1t_all_lin.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_compareSamples_l1t_all_lin.pdf"; if( printPDF_ ) c1->Print(plotname); //// hlt_all h_all[0]->Draw("axis"); for( int iSample=0; iSample<NumSamples; iSample++ ) eff_hlt_all[iSample]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_compareSamples_hlt_all_lin.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_compareSamples_hlt_all_lin.pdf"; if( printPDF_ ) c1->Print(plotname); //// hlt_l1t h_all[0]->Draw("axis"); for( int iSample=0; iSample<NumSamples; iSample++ ) eff_hlt_l1t[iSample]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_compareSamples_hlt_l1t_lin.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_compareSamples_hlt_l1t_lin.pdf"; if( printPDF_ ) c1->Print(plotname); h_all[0]->GetYaxis()->SetRangeUser(0.85,1.15); //// l1t_all h_all[0]->Draw("axis"); for( int iSample=0; iSample<NumSamples; iSample++ ) eff_l1t_all[iSample]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_compareSamples_l1t_all_lin_zoom.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_compareSamples_l1t_all_lin_zoom.pdf"; if( printPDF_ ) c1->Print(plotname); //// hlt_all h_all[0]->Draw("axis"); for( int iSample=0; iSample<NumSamples; iSample++ ) eff_hlt_all[iSample]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_compareSamples_hlt_all_lin_zoom.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_compareSamples_hlt_all_lin_zoom.pdf"; if( printPDF_ ) c1->Print(plotname); //// hlt_l1t h_all[0]->Draw("axis"); for( int iSample=0; iSample<NumSamples; iSample++ ) eff_hlt_l1t[iSample]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_compareSamples_hlt_l1t_lin_zoom.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_compareSamples_hlt_l1t_lin_zoom.pdf"; if( printPDF_ ) c1->Print(plotname); delete legend; } if( true ){ TString temp = "h_HT30"; std::vector<TString> useL1Name; useL1Name.push_back(temp + "_L1HTT125"); useL1Name.push_back(temp + "_L1HTT100"); std::vector<TString> labelL1Name; labelL1Name.push_back("L1_HTT125"); labelL1Name.push_back("L1_HTT100"); std::vector<Color_t> useColor; useColor.push_back(kBlack); useColor.push_back(kRed); TString temp_mh = temp; temp_mh.ReplaceAll("h_",""); //TLegend *legend = new TLegend(0.2,0.83,0.9,0.89); TLegend *legend = new TLegend(0.15,0.83,0.85,0.89); legend->SetFillColor(kWhite); legend->SetLineColor(kWhite); legend->SetShadowColor(kWhite); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->SetNColumns(2); int rebin = 25; int NumL1Samples = int(useL1Name.size()); TH1D* h_all[NumL1Samples]; TH1D* h_l1t[NumL1Samples]; TEfficiency* eff_l1t_all[NumL1Samples]; for( int iSample=0; iSample<NumL1Samples; iSample++ ){ h_all[iSample] = (TH1D*)file[useSample_]->Get(temp)->Clone(Form("%s_%s",temp.Data(),labelL1Name[iSample].Data())); h_l1t[iSample] = (TH1D*)file[useSample_]->Get(useL1Name[iSample])->Clone(Form("%s_%s",useL1Name[iSample].Data(),labelL1Name[iSample].Data())); h_all[iSample]->Rebin(rebin); h_l1t[iSample]->Rebin(rebin); eff_l1t_all[iSample] = makeEfficiency(h_l1t[iSample], h_all[iSample]); eff_l1t_all[iSample]->SetLineColor(useColor[iSample]); eff_l1t_all[iSample]->SetMarkerColor(useColor[iSample]); eff_l1t_all[iSample]->SetMarkerStyle(20); legend->AddEntry(eff_l1t_all[iSample], labelL1Name[iSample],"pl"); } h_all[0]->SetStats(0); h_all[0]->GetYaxis()->SetTitle("Efficiency"); h_all[0]->GetYaxis()->SetRangeUser(0.,1.15); h_all[0]->GetXaxis()->SetRangeUser(0.,600.); //// l1t_all h_all[0]->Draw("axis"); for( int iSample=0; iSample<NumL1Samples; iSample++ ) eff_l1t_all[iSample]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_compareL1_l1t_all_lin.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_compareL1_l1t_all_lin.pdf"; if( printPDF_ ) c1->Print(plotname); h_all[0]->GetYaxis()->SetRangeUser(0.85,1.15); //// l1t_all h_all[0]->Draw("axis"); for( int iSample=0; iSample<NumL1Samples; iSample++ ) eff_l1t_all[iSample]->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); plotname = dirprefix + temp_mh + "_compareL1_l1t_all_lin_zoom.png"; c1->Print(plotname); plotname = dirprefix + temp_mh + "_compareL1_l1t_all_lin_zoom.pdf"; if( printPDF_ ) c1->Print(plotname); delete legend; } //////////////////////////////////////////////////////////////////////////// TCanvas* myC1 = new TCanvas("myC1", "myC1", 600,700); gStyle->SetPadBorderMode(0); gStyle->SetFrameBorderMode(0); Float_t small = 1.e-5; myC1->Divide(1,2,small,small); const float padding=1e-5; const float ydivide=0.3; myC1->GetPad(1)->SetPad( padding, ydivide + padding , 1-padding, 1-padding); myC1->GetPad(2)->SetPad( padding, padding, 1-padding, ydivide-padding); myC1->GetPad(1)->SetLeftMargin(.11); myC1->GetPad(2)->SetLeftMargin(.11); myC1->GetPad(1)->SetRightMargin(.05); myC1->GetPad(2)->SetRightMargin(.05); myC1->GetPad(1)->SetBottomMargin(.3); myC1->GetPad(2)->SetBottomMargin(.3); myC1->GetPad(1)->Modified(); myC1->GetPad(2)->Modified(); myC1->cd(1); gPad->SetBottomMargin(small); gPad->Modified(); for( int i=0; i<int(histoname3.size()); i++ ){ TString temp = histoname3[i]; TString temp_mh = temp; temp_mh.ReplaceAll("h_",""); //TLegend *legend = new TLegend(0.1,0.91,0.9,0.99); TLegend *legend = new TLegend(0.2,0.83,0.88,0.89); legend->SetFillColor(kWhite); legend->SetLineColor(kWhite); legend->SetShadowColor(kWhite); legend->SetTextFont(42); legend->SetTextSize(0.04); legend->SetNColumns(2); int rebin = 1; if( temp.Contains("_mass") ) rebin = 2; if( temp.Contains("_L1HTT") ) rebin = 2; if( temp.Contains("_met") ) rebin = 5; if( temp.Contains("_jet_") && temp.Contains("_pt") ) rebin = 10; if( temp.Contains("_jet_") && temp.Contains("_eta") ) rebin = 4; if( temp.Contains("_jet_") && temp.Contains("_phi") ) rebin = 4; if( temp.Contains("_csv") ) rebin = 8; if( temp.Contains("_diele_mass_closestZmass") ) rebin = 5; TH1D* h_data = (TH1D*)file[2]->Get(temp.Data()); TH1D* h_mc = (TH1D*)file[0]->Get(temp.Data()); h_data->Rebin(rebin); h_mc->Rebin(rebin); if( temp.Contains("_numPV") ){ h_mc->Scale( h_data->Integral() / h_mc->Integral() ); } h_data->SetLineColor(color[0]); h_mc->SetLineColor(color[2]); h_data->SetMarkerColor(color[0]); h_mc->SetMarkerColor(color[2]); h_data->SetMarkerStyle(20); h_mc->SetMarkerStyle(20); legend->AddEntry(h_data,histLabels[2],"p"); legend->AddEntry(h_mc,histLabels[0],"p"); //c3->SetTopMargin(.05); //c1->SetRightMargin(.05); double ratioMax = 1.6; double ratioMin = 0.5; int nbins = h_data->GetNbinsX(); double xmin = h_data->GetBinLowEdge(1); double xmax = h_data->GetBinLowEdge(nbins) + h_data->GetBinWidth(nbins); TH1D* myRatio = new TH1D("ratio", "", nbins, xmin, xmax ); myRatio->SetStats(0); myRatio->Sumw2(); myRatio->SetLineColor(kBlack); myRatio->SetMarkerColor(kBlack); myRatio->Divide(h_data,h_mc); myRatio->SetMinimum(ratioMin); myRatio->SetMaximum(ratioMax); //myRatio->GetYaxis()->SetNdivisions(50000+404); myRatio->GetYaxis()->SetNdivisions(50000+204); myRatio->GetYaxis()->SetLabelSize(0.1); //make y label bigger myRatio->GetXaxis()->SetLabelSize(0.1); //make y label bigger myRatio->GetXaxis()->SetTitleOffset(1.1); myRatio->GetXaxis()->SetTitle(h_data->GetXaxis()->GetTitle()); //make y label bigger myRatio->GetXaxis()->SetLabelSize(0.12); myRatio->GetXaxis()->SetLabelOffset(0.04); myRatio->GetXaxis()->SetTitleSize(0.12); myRatio->GetYaxis()->SetTitle("Data/MC"); myRatio->GetYaxis()->SetTitleSize(0.09); myRatio->GetYaxis()->SetTitleOffset(.55); myC1->cd(2); gPad->SetTopMargin(small); gPad->SetTickx(); gPad->Modified(); myRatio->GetYaxis()->CenterTitle(kTRUE); if( temp.Contains("_selection") ){ for( int iBin=0; iBin<nbins; iBin++ ) myRatio->GetXaxis()->SetBinLabel(iBin+1,h_data->GetXaxis()->GetBinLabel(iBin+1)); myC1->GetPad(2)->SetBottomMargin(.4); myC1->GetPad(1)->SetRightMargin(.10); myC1->GetPad(2)->SetRightMargin(.10); myRatio->GetXaxis()->SetTitle(""); } else{ myC1->GetPad(2)->SetBottomMargin(.3); myC1->GetPad(1)->SetRightMargin(.05); myC1->GetPad(2)->SetRightMargin(.05); } h_data->SetStats(0); h_data->GetYaxis()->SetTitleOffset(1.0); h_data->GetYaxis()->SetTitleSize(0.05); h_data->GetYaxis()->SetTitle("Number of Events"); int max_bin_data = h_data->GetMaximumBin(); double max_data = h_data->GetBinContent(max_bin_data) + h_data->GetBinError(max_bin_data); int max_bin_mc = h_mc->GetMaximumBin(); double max_mc = h_mc->GetBinContent(max_bin_mc) + h_mc->GetBinError(max_bin_mc); double max_content = std::max(max_data, max_mc); h_data->GetYaxis()->SetRangeUser(0.,1.2 * max_content); if( temp.Contains("_mass") ){ h_data->GetXaxis()->SetRangeUser(40.,140.); myRatio->GetXaxis()->SetRangeUser(40.,140.); } if( temp.Contains("_met") ){ h_data->GetXaxis()->SetRangeUser(0.,150.); myRatio->GetXaxis()->SetRangeUser(0.,150.); } // if( temp.Contains("_eta") ) h_all->GetYaxis()->SetRangeUser(0.4,1.1); // if( temp.Contains("_numGenPVs") ) h_all->GetYaxis()->SetRangeUser(0.4,1.1); // if( temp.Contains("_numJets") ) h_all->GetYaxis()->SetRangeUser(0.4,1.1); TLine* myLine; if( temp.Contains("_mass") ) myLine = new TLine(40, 1, 140, 1); else if( temp.Contains("_met") ) myLine = new TLine(0, 1, 150, 1); else myLine = new TLine(h_data->GetXaxis()->GetXmin(), 1, h_data->GetXaxis()->GetXmax(), 1); // HLT myC1->cd(1); h_data->Draw("pe1"); h_mc->Draw("pe1same"); legend->Draw(); LumiInfoLatex.Draw(); CMSInfoLatex.Draw(); PublishInfoLatex.Draw(); myC1->cd(2); myRatio->SetLineWidth(2); myRatio->Draw("pe1"); myLine->Draw(); plotname = dirprefix + temp_mh + "_data2mc_lin.png"; myC1->Print(plotname); plotname = dirprefix + temp_mh + "_data2mc_lin.pdf"; if( printPDF_ ) myC1->Print(plotname); // log h_data->GetYaxis()->SetRangeUser(0.4,12 * max_content); if( temp.Contains("_selection") ){ h_data->GetYaxis()->SetRangeUser(400,12 * max_content); } myC1->cd(1); gPad->SetLogy(1); plotname = dirprefix + temp_mh + "_data2mc_log.png"; myC1->Print(plotname); plotname = dirprefix + temp_mh + "_data2mc_log.pdf"; if( printPDF_ ) myC1->Print(plotname); gPad->SetLogy(0); delete myRatio; delete myLine; delete legend; } // end loop on hists //////////////////////////////////////////////////////////////////////////// // Close the file for( int iFile=0; iFile<NumSamples; iFile++ ) file[iFile]->Close(); std::cout << " Done! " << std::endl; }
void updateHIN11010(int etPho = 60, int etJet = 30, bool scaleByR=true, bool drawMC=true, int prodDate=20131021) { bool mcOnly=false; int percentBin[5] = {0,10,30,50,100}; TH1D* hxgj[5][10]; //[data kind] [ centrality] TH1D* hxgjpp[20]; TFile *fSum1 = new TFile(Form("histOutputFiles60GeVInclusive/HisOutput_Photonv7_v29_akPu3PF_InclPtRatio_gamma%djet%ddphiSig2749_Isol0_Norm1.root",etPho,etJet)); for ( int icent=0; icent<=3 ; icent++) { hxgj[khimc][icent] = (TH1D*)fSum1->Get(Form("dataSrc%d_reco1_cent%dSubtractedExtrapExtrapNorm",khimc,icent)); hxgj[khidata][icent] = (TH1D*)fSum1->Get(Form("dataSrc%d_reco1_cent%dSubtractedExtrapExtrapNorm",khidata,icent)); } hxgjpp[kppdata] = (TH1D*)fSum1->Get("dataSrc2_reco1_cent0SubtractedExtrapExtrapNorm"); TFile *fSum2 = new TFile(Form("histOutputFiles60GeVInclusive/HisOutput_Photonv7_v29_akPu3PF_InclPtRatio_gamma%djet%ddphiSig2749_Isol0_Norm2.root",etPho,etJet)); TGraphAsymmErrors* mxhimc = (TGraphAsymmErrors*)fSum2->Get("dataSrc0_reco1_x_Summary_0"); TGraphAsymmErrors* mxhidata = (TGraphAsymmErrors*)fSum2->Get("dataSrc1_reco1_x_Summary_0"); // TGraphAsymmErrors* mxppdata = (TGraphAsymmErrors*)fSum2->Get("dataSrc2_reco1_x_Summary_0"); TGraphAsymmErrors* mxppdata; TGraphAsymmErrors* mxppmc = (TGraphAsymmErrors*)fSum2->Get("dataSrc10_reco1_x_Summary_0"); TGraphAsymmErrors* rxhimc = (TGraphAsymmErrors*)fSum2->Get("dataSrc0_reco1_R_Summary_0"); TGraphAsymmErrors* rxhidata = (TGraphAsymmErrors*)fSum2->Get("dataSrc1_reco1_R_Summary_0"); TGraphAsymmErrors* rxppdata = (TGraphAsymmErrors*)fSum2->Get("dataSrc2_reco1_R_Summary_0"); TGraphAsymmErrors* rxppmc = (TGraphAsymmErrors*)fSum2->Get("dataSrc10_reco1_R_Summary_0"); TFile *fSum3 = new TFile(Form("histOutputFiles60GeVInclusive/HisOutput_Photonv7_v29_akPu3PF_InclDeltaPhi_gamma%djet%ddphiSig628_subJ1SS1_Isol0_Norm1.root",etPho,etJet)); TFile *fSum4 = new TFile("histOutputFiles60GeVInclusive/HisSummary_Photonv7_v29_akPu3PF_InclDeltaPhi_gamma60jet30dphiSig628_subJ1SS1_Isol0_Norm1.root"); TGraphAsymmErrors* dphihimc = (TGraphAsymmErrors*)fSum4->Get("dataSrc0_reco1_dphi_Summary"); TGraphAsymmErrors* dphihidata = (TGraphAsymmErrors*)fSum4->Get("dataSrc1_reco1_dphi_Summary"); TGraphAsymmErrors* dphippdata = (TGraphAsymmErrors*)fSum4->Get("dataSrc2_reco1_dphi_Summary"); TGraphAsymmErrors* dphippmc = (TGraphAsymmErrors*)fSum4->Get("dataSrc10_reco1_dphi_Summary"); // new dphihidata points // double sysDphi[4] = {0.032,0.03,0.045,0.077}; //0.109940, 0.046998, 0.034206,0.142664}; double sysDphipp[1] = {sysDphi[3]}; double sysR[4] = {0.045,0.039,0.041,0.037}; //0.017232,0.012847,0.011691,0.012724}; double sysRpp[1] = {sysR[3]}; double sysMx[4] = { 0.053,0.048,0.051,0.032}; double sysMxpp[1] = {0.009}; double corrSysMx = 0.028; TH1D* hdphi[5][5]; //[data kind] [ centrality] TH1D* hdphipp[20]; for ( int icent=0; icent<=3 ; icent++) { hdphi[khimc][icent] = (TH1D*)fSum3->Get(Form("dataSrc%d_reco1_cent%dSubtractedExtrapExtrapNorm",khimc,icent)); hdphi[khidata][icent] = (TH1D*)fSum3->Get(Form("dataSrc%d_reco1_cent%dSubtractedExtrapExtrapNorm",khidata,icent)); } hdphipp[kppdata] = (TH1D*)fSum3->Get("dataSrc2_reco1_cent0SubtractedExtrapExtrapNorm"); // 2013 pp data!!!!!! TFile* pp13 = new TFile(Form("ffFilesPP60GeVInclusive/photonTrackCorr_ppDATA_output_photonPtThr60_to_9999_jetPtThr30_%d.root", prodDate)); // TFile* pp13 = new TFile("ffFilesPP60GeVInclusive/oldSmearing.root"); hdphi[kppdata13][1] = (TH1D*)pp13->Get("jetDphi_icent10010_final"); hxgj[kppdata13][1] = (TH1D*)pp13->Get("xjg_icent10010_final"); hdphi[kppdata13][2] = (TH1D*)pp13->Get("jetDphi_icent11030_final"); hxgj[kppdata13][2] = (TH1D*)pp13->Get("xjg_icent11030_final"); hdphi[kppdata13][3] = (TH1D*)pp13->Get("jetDphi_icent13050_final"); hxgj[kppdata13][3] = (TH1D*)pp13->Get("xjg_icent13050_final"); hdphi[kppdata13][4] = (TH1D*)pp13->Get("jetDphi_icent15099_final"); hxgj[kppdata13][4] = (TH1D*)pp13->Get("xjg_icent15099_final"); hdphi[kppdata13][5] = (TH1D*)pp13->Get("jetDphi_icent7_final"); hxgj[kppdata13][5] = (TH1D*)pp13->Get("xjg_icent7_final"); for ( int icent = 1 ; icent<=5 ; icent++) { hdphi[kppdata13][icent]->Scale(1./hdphi[kppdata13][icent]->Integral()); for ( int i = 1 ; i<=5 ; i++) { hdphi[kppdata13][icent]->SetBinContent(i,-1e4); } // hxgj[kppdata13][icent]->Rebin(10); // Now the bins are already rebined from photonTrackCorr_ppDATA_output_photonPtThr60_to_9999_jetPtThr30_20131021.root hxgj[kppdata13][icent]->Scale(1./hxgj[kppdata13][icent]->Integral("width")); } TH1D* hPtPP2013[10]; hPtPP2013[1] = (TH1D*)pp13->Get("jetPt_icent10010_final"); hPtPP2013[2] = (TH1D*)pp13->Get("jetPt_icent11030_final"); hPtPP2013[3] = (TH1D*)pp13->Get("jetPt_icent13050_final"); hPtPP2013[4] = (TH1D*)pp13->Get("jetPt_icent15099_final"); hPtPP2013[5] = (TH1D*)pp13->Get("jetPt_icent7_final"); TH1D* hRpp2013[10]; hRpp2013[1] = new TH1D("hrpp2013_icent1","",1, 359.1-10, 359.1+10); hRpp2013[2] = new TH1D("hrpp2013_icent2","",1, 235.6-10, 235.6+10); hRpp2013[3] = new TH1D("hrpp2013_icent3","",1, 116.4-10, 116.4+10); hRpp2013[4] = new TH1D("hrpp2013_icent4","",1, 43.6-10, 43.6 +10); hRpp2013[5] = new TH1D("hrpp2013_icent5","",1, -8, 18 ); for ( int icent=1 ; icent<=5; icent++) { double temprPP13err; double temprPP13 = hPtPP2013[icent]->IntegralAndError(1,hPtPP2013[icent]->GetNbinsX(),temprPP13err,"width"); hRpp2013[icent]->SetBinContent(1,temprPP13); hRpp2013[icent]->SetBinError(1,temprPP13err); handsomeTH1(hRpp2013[icent],1); hRpp2013[icent]->SetMarkerStyle(21); } TH1D* hMXpp2013[10]; hMXpp2013[1] = new TH1D("hmxpp2013_icent1","",1, 359.1-10, 359.1+10); hMXpp2013[2] = new TH1D("hmxpp2013_icent2","",1, 235.6-10, 235.6+10); hMXpp2013[3] = new TH1D("hmxpp2013_icent3","",1, 116.4-10, 116.4+10); hMXpp2013[4] = new TH1D("hmxpp2013_icent4","",1, 43.6-10, 43.6 +10); hMXpp2013[5] = new TH1D("hmxpp2013_icent5","",1, -8, 18); for ( int icent=1 ; icent<=5; icent++) { hMXpp2013[icent]->SetBinContent(1,hxgj[kppdata13][icent]->GetMean()); hMXpp2013[icent]->SetBinError(1,hxgj[kppdata13][icent]->GetMeanError()); handsomeTH1(hMXpp2013[icent],1); hMXpp2013[icent]->SetMarkerStyle(21); } TFile* fPPsys = new TFile("ffFilesPP60GeVInclusive/relativeSys_merged_pp60GeV.root"); TH1D* hdphiWidth = (TH1D*)fPPsys->Get("dphiWidth_uncertainty_merged"); TH1D* hDphiPPUnc = new TH1D("hdphippunc","",1,0,1); hDphiPPUnc->SetBinContent(1, hdphiWidth->GetBinContent(1) ); TH1D* ppSysX[4]; ppSysX[0] = (TH1D*)fPPsys->Get("dNdXjg_uncertainty_merged"); ppSysX[1] = (TH1D*)ppSysX[0]->Clone("ppSysx1"); ppSysX[2] = (TH1D*)ppSysX[0]->Clone("ppSysx2"); ppSysX[3] = (TH1D*)ppSysX[0]->Clone("ppSysx3"); TH1D* meanXpp13Sys = (TH1D*)fPPsys->Get("meanXjg_uncertainty_merged"); float ppSysMx60 = meanXpp13Sys->GetBinContent(1); // UPDATED on Oct 22nd TH1D* ppSysMx = new TH1D("ppSysMx","",1,0,1); ppSysMx->SetBinContent(1,ppSysMx60); TH1D* meanRpp13Sys = (TH1D*)fPPsys->Get("meanRjg_uncertainty_merged"); float ppSysR60 = meanRpp13Sys->GetBinContent(1); // UPDATED on Oct 22nd TH1D* ppSysR = new TH1D("ppSysR","",1,0,1); ppSysR->SetBinContent(1,ppSysR60); // xjg distributions TCanvas *c1 = new TCanvas("c1","",1100,330); makeMultiPanelCanvas(c1,4,1,0.0,0.0,0.24,0.15,0.075); c1->cd(0); drawCMSppPbPb(0.1,0.95); //c1->Divide(4,1,0.0,0.0); for ( int icent=0; icent<=3 ; icent++) { c1->cd( 4 - icent); //hxgj[khimc][icent]->SetAxisRange(-.2,2.5,"Y"); hxgj[khimc][icent]->SetAxisRange(0,2.5,"Y"); hxgj[khimc][icent]->SetNdivisions(505); // hxgj[khimc][icent]->SetTitle(";x_{J#gamma} = p^{Jet}_{T}/p^{#gamma}_{T}; #frac{1}{N_{J#gamma}} #frac{dN_{J#gamma}}{dx_{J#gamma}}"); hxgj[khimc][icent]->SetTitle(";x_{J#gamma}; #frac{1}{N_{J#gamma}} #frac{dN_{J#gamma}}{dx_{J#gamma}}"); handsomeTH1(hxgj[khimc][icent]); fixedFontHist(hxgj[khimc][icent],1,1.35); mcStyle2(hxgj[khimc][icent]); handsomeTH1(hxgj[khidata][icent],2); hxgj[khimc][icent]->GetYaxis()->SetTitleOffset(1.5); TH1D * htemp41 = (TH1D*)hxgj[khimc][icent]->Clone(Form("htemp41_%d",icent)); for ( int i=0 ; i<=20 ; i++) { htemp41->SetBinContent(i,0); htemp41->SetBinError(i,0); } if (scaleByR) { htemp41->SetAxisRange(0,2,"Y"); htemp41->SetYTitle("#frac{1}{N_{#gamma}} #frac{dN_{J#gamma}}{dx_{J#gamma}}"); } htemp41->DrawCopy("hist"); if (scaleByR) { hxgj[kppdata13][icent+1]->Scale(hRpp2013[icent+1]->GetBinContent(1)); std::cout <<" Scaled by pp R :" << hRpp2013[icent+1]->GetBinContent(1) << std::endl; double x,y; rxhidata->GetPoint(icent, x,y); hxgj[khidata][icent]->Scale(y); std::cout << " scaled by PbPb R: " << y << std::endl; rxhimc->GetPoint(icent, x,y); hxgj[khimc][icent]->Scale(y); std::cout << " scaled by PbPb R: " << y << std::endl; } if(drawMC) hxgj[khimc][icent]->DrawCopy("hist same"); if ( !mcOnly ) drawXSys(icent,hxgj[khidata][icent]); // if ( icent==3){ } handsomeTH1(hxgj[kppdata13][icent+1]); hxgj[kppdata13][icent+1]->SetMarkerStyle(21); drawSys(hxgj[kppdata13][icent+1],ppSysX[icent],kGreen,3001); hxgj[kppdata13][icent+1]->Draw("same "); if ( !mcOnly ) hxgj[khidata][icent]->Draw("same"); //onSun(0,0,2,0); // if ( icent == 2) { // TLegend *leg0 = new TLegend(0.2796373,0.7545885,0.9742202,0.9937661,NULL,"brNDC"); // easyLeg(leg0,""); // // if ( !mcOnly ) leg0->AddEntry(hxgj[khidata][icent],"PbPb Data","p"); // leg0->AddEntry(hxgj[khimc][icent],"PYTHIA + HYDJET","f"); // leg0->AddEntry(hxgjpp[kppdata],"",""); // leg0->Draw(); // } if ( icent == 3) { TLegend *leg0 = new TLegend(0.2916647,0.7045885,0.9862476,0.9869226,NULL,"brNDC"); easyLeg(leg0); leg0->AddEntry(hxgj[khidata][icent],"PbPb Data","p"); if ( !mcOnly ) leg0->AddEntry(hxgj[kppdata13][icent+1],"Smeared pp reference","p"); // leg0->AddEntry(hxgj[khidata][icent],"",""); if(drawMC) leg0->AddEntry(hxgj[khimc][icent],"PbPb PYTHIA + HYDJET","f"); leg0->Draw(); //drawText("#sqrt{s_{NN}}=2.76 TeV ",0.65,0.74,0,15); } if ( icent == 2) { drawText(Form("p^{#gamma}_{T} > %d GeV/c |#eta^{#gamma}| < 1.44",etPho),0.2,0.85,0,15); drawText(Form("p^{Jet}_{T} > %d GeV/c |#eta^{Jet}| < 1.6",etJet),0.2,0.77,0,15); drawText("#Delta#phi_{J#gamma} > #frac{7}{8}#pi",0.2,0.69,0,15); } if ( icent == 0 ) { // drawText("CMS",0.8,0.9,1); // drawText("pp #int L dt = 231 nb^{-1}",0.4,0.68,1,15); } if ( icent == 3) drawText(Form("%d%% - %d%%",percentBin[icent],percentBin[icent+1]),0.72,0.5,0,15); else drawText(Form("%d%% - %d%%",percentBin[icent],percentBin[icent+1]),0.67,0.5,0,15); /* if ( icent == 3) drawText("(a)",0.275,0.8,1); if ( icent == 2) drawText("(b)",0.05,0.8,1); if ( icent == 1) drawText("(c)",0.05,0.8,1); if ( icent == 0) drawText("(d)",0.05,0.8,1); */ gPad->RedrawAxis(); } c1->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_distribution.pdf"); //c1->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_distribution.png"); //c1->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_distribution.gif"); //c1->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_distribution.C"); // TCanvas *c1all = new TCanvas("c1all","",500,500); // for ( int icent=0;icent<4;icent++){ // hxgj[khimc][icent]->SetFillStyle(0); // hxgj[khimc][icent]->SetMarkerSize(1.5); // } // hxgj[khimc][0]->SetMarkerStyle(22); // hxgj[khimc][1]->SetMarkerStyle(26); // hxgj[khimc][2]->SetMarkerStyle(23); // hxgj[khimc][3]->SetMarkerStyle(32); // hxgj[khimc][0]->DrawCopy(""); // hxgj[khimc][1]->DrawCopy(" same"); // hxgj[khimc][2]->DrawCopy(" same"); // hxgj[khimc][3]->DrawCopy(" same"); // jumSun(0,0,2,0); // drawText("PYTHIA+HYDJET",0.2,0.80,0,25); // TLegend *legc1all = new TLegend(0.6149194,0.6716102,0.9435484,0.9555085,NULL,"brNDC"); // easyLeg(legc1all,""); // legc1all->AddEntry(hxgj[khimc][3],"50-100%","p"); // legc1all->AddEntry(hxgj[khimc][2],"30-50%","p"); // legc1all->AddEntry(hxgj[khimc][1],"10-30%","p"); // legc1all->AddEntry(hxgj[khimc][0],"0-10%","p"); // legc1all->Draw(); // dphi distributions TCanvas *c1ppDphi = new TCanvas("c1ppDphi","",500,500); TString fitFunc = "(TMath::Pi()/20.0)*exp(-(TMath::Pi()-x)/[0])/([0]*(1-exp(-TMath::Pi()/[0])))"; float fitxmin=3.1415926*2./3; TF1 *fdphiPP[10]; TH1D* hDphiPP2013[10]; hDphiPP2013[1] = new TH1D("hDphiPP2013_icent1","",1, 359.1-10, 359.1+10); hDphiPP2013[2] = new TH1D("hDphiPP2013_icent2","",1, 235.6-10, 235.6+10); hDphiPP2013[3] = new TH1D("hDphiPP2013_icent3","",1, 116.4-10, 116.4+10); hDphiPP2013[4] = new TH1D("hDphiPP2013_icent4","",1, 43.6-10, 43.6 +10); hDphiPP2013[5] = new TH1D("hDphiPP2013_icent5","",1, -8, 18); for ( int icent=1; icent<=5 ; icent++) { fdphiPP[icent] = new TF1(Form("fdphiPP_icent%d",icent),fitFunc.Data(),2.0*TMath::Pi()/3.0,TMath::Pi()); fdphiPP[icent]->SetParName(0,"width"); fdphiPP[icent]->SetParameter("width",0.3); hdphi[kppdata13][icent]->Fit(Form("fdphiPP_icent%d",icent),"0","",fitxmin,3.1415926); fdphiPP[icent]->SetLineWidth(1); fdphiPP[icent]->SetLineStyle(2); fdphiPP[icent]->SetLineColor(1); hdphi[kppdata13][icent]->SetAxisRange(1.00001e-3,1,"Y"); hdphi[kppdata13][icent]->SetStats(0); hdphi[kppdata13][icent]->Draw(""); hdphi[kppdata13][icent]->SetAxisRange(1.00001e-3,1,"Y"); hdphi[kppdata13][icent]->SetStats(0); fdphiPP[icent]->SetLineWidth(2); fdphiPP[icent]->SetLineStyle(7); fdphiPP[icent]->DrawCopy("same"); gPad->SetLogy(); float dphiWidth13 = fdphiPP[icent]->GetParameter(0) ; float dphiWidth13err = fdphiPP[icent]->GetParError(0); hDphiPP2013[icent]->SetBinContent(1,dphiWidth13); hDphiPP2013[icent]->SetBinError( 1,dphiWidth13err); handsomeTH1(hDphiPP2013[icent],1); hDphiPP2013[icent]->SetMarkerStyle(21); } TCanvas *c1dphi = new TCanvas("c1dphi","",1100,330); makeMultiPanelCanvas(c1dphi,4,1,0.0,0.0,0.24,0.18,0.075); c1dphi->cd(0); drawCMSppPbPb(0.1,0.95); for ( int icent=0; icent<=3 ; icent++) { c1dphi->cd( 4 - icent); hdphi[khimc][icent]->SetAxisRange(1.e-3,1,"Y"); // hdphi[khimc][icent]->SetNdivisions(505); hdphi[khimc][icent]->GetXaxis()->SetNdivisions(3,5,0,kFALSE); hdphi[khimc][icent]->SetTitle(";#Delta#phi_{J#gamma};Pair Fraction"); handsomeTH1(hdphi[khimc][icent]); fixedFontHist(hdphi[khimc][icent],1,1.35); mcStyle2(hdphi[khimc][icent]); handsomeTH1(hdphi[khidata][icent],2); TF1 *fdphi = new TF1("fdphi",fitFunc.Data(),2.0*TMath::Pi()/3.0,TMath::Pi()); fdphi->SetParName(0,"width"); fdphi->SetParameter("width",0.3); hdphi[khimc][icent]->Fit("fdphi","0llm","",fitxmin,3.1415926); fdphi->SetLineWidth(1); fdphi->SetLineStyle(2); fdphi->SetLineColor(kBlue); // float dphiWidth = fdphi->GetParameter("width"); // float dphiWidthErr = fdphi->GetParError(0); // std::cout << " dphiWidth,dphiWidthErr = " << dphiWidth <<" "<< dphiWidthErr << std::endl; hdphi[khimc][icent]->SetAxisRange(1.00001e-3,1,"Y"); hdphi[khimc][icent]->SetStats(0); TH1D* hdphitemp = (TH1D*)hdphi[khimc][icent]->Clone(Form("hdphitemp55_%d",icent)); if(!drawMC) { for ( int i=0;i<=30;i++) { hdphitemp->SetBinContent(i,0); hdphitemp->SetBinError(i,0); } } hdphitemp->Draw("hist"); hdphi[khidata][icent]->SetAxisRange(1.00001e-3,1,"Y"); if (!mcOnly) hdphi[khidata][icent]->Draw("same "); hdphi[khidata][icent]->SetStats(0); fdphi->SetLineWidth(2); fdphi->SetLineStyle(7); if ( mcOnly ) fdphi->DrawCopy("same"); gPad->SetLogy(); handsomeTH1(hdphi[kppdata13][icent+1]); hdphi[kppdata13][icent+1]->SetMarkerStyle(21); hdphi[kppdata13][icent+1]->Draw("same"); if ( icent == 3) { TLegend *leg0 = new TLegend(0.32,0.7,0.9,0.89,NULL,"brNDC"); easyLeg(leg0); if ( !mcOnly ) leg0->AddEntry(hdphi[kppdata13][icent+1],"Smeared pp reference","p"); if ( !mcOnly ) leg0->AddEntry(hdphi[khidata][icent],"PbPb Data","p"); if(drawMC) leg0->AddEntry(hdphi[khimc][icent],"PYTHIA + HYDJET","f"); leg0->Draw(); } if (( !mcOnly ) && ( icent == 2)) { //drawText("#sqrt{s_{NN}}=2.76 TeV ",0.4,0.88,0,15); //drawText("#int L dt = 150 #mub^{-1}",0.4,0.75,0,15); } if ( icent == 1) { drawText(Form("p^{#gamma}_{T} > %d GeV/c |#eta^{#gamma}| < 1.44",etPho),0.15,0.8,0,15); drawText(Form("p^{Jet}_{T} > %d GeV/c |#eta^{Jet}| < 1.6",etJet),0.15,0.7,0,15); } if ( icent == 0 ) { // drawText("CMS",0.8,0.9,1); // drawText("pp #int L dt = 231 nb^{-1}",0.4,0.68,1,15); } if ( icent == 3) drawText(Form("%d%% - %d%%",percentBin[icent],percentBin[icent+1]),0.313,0.6,0,15); else drawText(Form("%d%% - %d%%",percentBin[icent],percentBin[icent+1]),0.1,0.6,0,15); if ( icent == 3) drawText("(a)",0.275,0.8,1); if ( icent == 2) drawText("(b)",0.05,0.8,1); if ( icent == 1) drawText("(c)",0.05,0.8,1); if ( icent == 0) drawText("(d)",0.05,0.8,1); double bottomY = 0.0009; double pi = TMath::Pi(); drawPatch(-0.5,bottomY/100,pi+0.5,bottomY); bottomY = 0.0005; drawText("0",0.05,bottomY,0,18,false); drawText("#frac{1}{3}#pi",pi/3-0.05,bottomY,0,18,0); drawText("#frac{2}{3}#pi",2*pi/3-0.05,bottomY,0,18,0); if ( icent==0) drawText("#pi",pi-0.1,bottomY,0,18,0); drawText("#Delta#phi_{J#gamma}",pi/2.-0.1,bottomY-0.0002,0,18,0); } gPad->RedrawAxis(); c1dphi->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dPhi_dist.pdf"); //c1dphi->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dPhi_dist.png"); //c1dphi->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dPhi_dist.gif"); //c1dphi->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dPhi_dist.C"); ////////////////////////////// summary plots TCanvas *c2 = new TCanvas("c2","",350,350); TH1D* hTemp2 = new TH1D("htemp2",";N_{part};<x_{J#gamma}>",100,-20,400); hTemp2->SetNdivisions(505); handsomeTH1(hTemp2,1); handsomeTGraph(mxhidata,2); mxhidata->SetMarkerStyle(20); handsomeTGraph(mxhimc,1); mxhimc->SetMarkerStyle(24); // handsomeTGraph(mxppdata,1); // mxppdata->SetMarkerStyle(21); handsomeTGraph(mxppmc,1); mxppmc->SetMarkerStyle(25); hTemp2->SetAxisRange(0.6,1.1,"Y"); hTemp2->DrawCopy(); // TH1D* hMXpp2013_2 = new TH1D("hmxpp2013_2","",1,-10,370); // hMXpp2013_2->SetBinContent(1,hMXpp2013->GetBinContent(1)); // if ( !mcOnly ) drawSys(hMXpp2013_2,sysMxpp,kGreen,3001); if ( !mcOnly ) drawSys(mxhidata,sysMx,10); // mxppmc->Draw("p"); // if ( !mcOnly ) mxppdata->Draw("p"); if ( !mcOnly ) { hMXpp2013[5]->SetMarkerStyle(20); for ( int icent = 1 ; icent<=5 ; icent++) { drawSys(hMXpp2013[icent],ppSysMx,kGreen,3001); hMXpp2013[icent]->DrawCopy("p same"); } } if(drawMC) mxhimc->Draw("p same"); if ( !mcOnly ) mxhidata->Draw("p same"); hMXpp2013[5]->SetFillStyle(3001); hMXpp2013[5]->SetFillColor(kGreen); hMXpp2013[5]->SetLineColor(0); hDphiPP2013[2]->SetFillStyle(3001); hDphiPP2013[2]->SetFillColor(kGreen); hDphiPP2013[2]->SetLineColor(0); TH1D *dummyHist = new TH1D("dummyHist","",10,0,1); dummyHist->SetFillStyle(1001); dummyHist->SetMarkerColor(kRed); dummyHist->SetFillColor(90); dummyHist->SetLineColor(0); //// sys bar by energy scale /* TBox *b1 = new TBox(400-20,0.85 - corrSysMx ,400, 0.85 + corrSysMx); b1->SetFillColor(1); b1->SetFillStyle(1001); if ( !mcOnly ) b1->Draw(); TBox *b2 = new TBox(400-20+3,0.85 - corrSysMx+ 0.002 ,400-3, 0.85 + corrSysMx- 0.002); b2->SetFillColor(0); b2->SetFillStyle(1001); if ( !mcOnly ) b2->Draw(); */ // drawText("Common uncertainty due to jet ",0.35,0.25,0,15); // drawText("energy scale & photon purity",0.35,0.2,0,15); // drawText("#sqrt{s_{NN}}=2.76 TeV ",0.5,0.85,0,15); // drawText("#int L dt = 150 #mub^{-1}",0.5,0.72,0,15); // drawText("(a)",0.22,0.87,1); drawText("#Delta#phi_{J#gamma} > #frac{7}{8}#pi",0.7,0.75,0); drawCMSppPbPb(0.1,0.95,12); // drawText("#Delta#phi_{J#gamma} > #frac{7}{8}#pi",0.5,0.38,0); // drawText("CMS",0.78,0.88,1); TLegend *leg4 = new TLegend(0.1630303,0.6054839,0.7590909,0.8931183,NULL,"brNDC"); easyLeg(leg4,""); // if ( !mcOnly ) leg4->AddEntry(mxppdata,"pp Data 231nb^{-1}","p"); if ( !mcOnly ) leg4->AddEntry(dummyHist,"PbPb Data","fp"); if ( !mcOnly ) leg4->AddEntry(hMXpp2013[5],"pp Data","fp"); if ( !mcOnly ) leg4->AddEntry(hDphiPP2013[2],"Smeared pp reference","fp"); if(drawMC) leg4->AddEntry(mxhimc,"PYTHIA + HYDJET","p"); // leg4->AddEntry(mxppmc,"PYTHIA","p"); // leg4->AddEntry(hSysTemp,"Sys. Uncertainty","f"); leg4->Draw(); gPad->RedrawAxis(); c2->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_npart.pdf"); //c2->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_npart.png"); //c2->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_npart.gif"); //c2->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_xjg_npart.C"); ////////////////////////////// rx TCanvas *c3 = new TCanvas("c3","",350,350); TH1D* hTemp3 = new TH1D("htemp2",";N_{part};R_{J#gamma}",100,-20,400); hTemp3->SetNdivisions(505); handsomeTH1(hTemp3,1); handsomeTGraph(rxhidata,2); rxhidata->SetMarkerStyle(20); handsomeTGraph(rxhimc,1); rxhimc->SetMarkerStyle(24); handsomeTGraph(rxppdata,1); rxppdata->SetMarkerStyle(21); handsomeTGraph(rxppmc,1); rxppmc->SetMarkerStyle(25); hTemp3->SetAxisRange(0.41,1.,"Y"); hTemp3->Draw(); // Ratio // DivideTG(rxppdata,rxppmc); // DivideTG(rxhidata,rxhimc); ////////////////////////////////////////////// // TH1D* hdphi2013_2 = new TH1D("hdphi2013_2","",1,-10,370); // hdphi2013_2->SetBinContent(1,hRpp2013->GetBinContent(1)); // if ( !mcOnly ) drawSys(hdphi2013_2,sysRpp,kGreen,3001); if ( !mcOnly ) drawSys(rxhidata,sysR,10); // if ( !mcOnly ) drawSys(rxppdata,sysRpp,10); // jumSun(-10,1,400,1); if(drawMC) rxhimc->Draw("p"); // rxppmc->Draw("p"); // if ( !mcOnly ) rxppdata->Draw("p"); if ( !mcOnly ) { hRpp2013[5]->SetMarkerStyle(20); for ( int icent =1 ; icent<=5 ; icent++) { drawSys(hRpp2013[icent],ppSysR,kGreen,3001); hRpp2013[icent]->Draw("same"); } } if ( !mcOnly ) rxhidata->Draw("p same"); // drawText(Form("p^{#gamma}_{T} > %d GeV/c",etPho),0.6,0.75,0,15); // drawText(Form("p^{Jet}_{T} > %d GeV/c",etJet),0.6,0.67,0,15); // drawText("CMS",0.78,0.88,1); // drawText("(b)",0.22,0.87,1); drawText("#Delta#phi_{J#gamma} > #frac{7}{8}#pi",0.7,0.75,0); drawCMSppPbPb(0.1,0.95,12); leg4->Draw(); gPad->RedrawAxis(); c3->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_r_npart.pdf"); //c3->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_r_npart.png"); //c3->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_r_npart.gif"); //c3->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_r_npart.C"); TCanvas *c4 = new TCanvas("c4","",350,350); TH1D* hTemp4 = new TH1D("htemp2",";N_{part};#sigma(#Delta#phi_{J#gamma})",100,-20,400); hTemp4->SetNdivisions(505); handsomeTH1(hTemp4,1); handsomeTGraph(dphihidata,2); dphihidata->SetMarkerStyle(20); handsomeTGraph(dphihimc,1); dphihimc->SetMarkerStyle(24); handsomeTGraph(dphippdata,1); dphippdata->SetMarkerStyle(21); handsomeTGraph(dphippmc,1); dphippmc->SetMarkerStyle(25); hTemp4->SetAxisRange(0,.5,"Y"); hTemp4->Draw(); // TH1D* h2013_3 = new TH1D("hdphi2013_3","",1,-10,370); // h2013_3->SetBinContent(1,hDphiPP2013->GetBinContent(1)); // if ( !mcOnly ) drawSys(h2013_3,sysDphipp,kGreen,3001); if ( !mcOnly ) drawSys(dphihidata,sysDphi,10); if(drawMC) dphihimc->Draw("p same"); // dphippmc->Draw("p"); // if ( !mcOnly ) dphippdata->Draw("p"); for ( int icent=1 ; icent<=5 ; icent++){ drawSys(hDphiPP2013[icent], hDphiPPUnc, kGreen,3001); } TH1D* hDphiPP2013Temp = new TH1D("hDphiPP2013Temp","",1,380,400); hDphiPP2013Temp->SetBinContent(1,0.27); hDphiPP2013[5]->SetMarkerStyle(20); for ( int icent=1 ; icent<=5 ; icent++){ hDphiPP2013[icent]->Draw("same"); } if ( !mcOnly ) dphihidata->Draw("p"); // TLegend *legDphi = new TLegend(0.32,0.18,0.93,0.7,NULL,"brNDC"); // easyLeg(legDphi,""); // legDphi->SetTextSize(17); // // drawText("|#Delta#phi_{J#gamma}| > #frac{2}{3}#pi",0.5,0.38,0); // // drawText("Fit : #frac{e^{#frac{|#Delta#phi_{J#gamma}|-#pi}{#sigma}}}{#sigma(1-e^{-#pi/#sigma})}",0.5,0.23,0); // legDphi->Draw(); // // drawText("(a)",0.22,0.87,1); // // drawText("CMS",0.78,0.88,1); TH1D* hSysTemp = new TH1D("hSystemp","",1,0,1); hSysTemp->SetFillColor(newYellow); hSysTemp->SetLineColor(newYellow); leg4->Draw(); drawText(Form("p^{#gamma}_{T} > %d GeV/c |#eta^{#gamma}| < 1.44",etPho),0.25,0.3,0,15); drawText(Form("p^{Jet}_{T} > %d GeV/c |#eta^{Jet}| < 1.6",etJet),0.25,0.2,0,15); drawCMSppPbPb(0.1,0.95,12); gPad->RedrawAxis(); c4->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dphi_npart.pdf"); //c4->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dphi_npart.png"); //c4->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dphi_npart.gif"); //c4->SaveAs("plotPPPbPb/inclusivePt_ppPbPb_dphi_npart.C"); // // print numbers // std::cout << " Summary of Points for PbPb " << std::endl; // PrintGraphAndSys(dphihidata,sysDphi); // PrintGraphAndSys(mxhidata,sysMx); // PrintGraphAndSys(rxhidata,sysR); // std::cout << " Summary of Points for PYTHIA + HYDJET " << std::endl; // PrintGraph(dphihimc); // PrintGraph(mxhimc); // PrintGraph(rxhimc); // std::cout << " Summary of Points for pp " << std::endl; // PrintGraphAndSys(dphippdata[5],sysDphipp); // PrintGraphAndSys(mxppdata[5],sysMxpp); // PrintGraphAndSys(rxppdata[5],sysRpp); /* TCanvas *c5 = new TCanvas("c5","",500,500); hxgj[khidata][0]->SetAxisRange(-.2,2.5,"Y"); hxgj[khidata][0]->SetNdivisions(505); fixedFontHist(hxgj[khidata][0],1,1.35); handsomeTH1(hxgj[khidata][0],2); hxgj[khidata][0]->GetYaxis()->SetTitleOffset(1.5); hxgj[khidata][0]->DrawCopy(""); handsomeTH1(hxgj[kppdata13][5],4); hxgj[kppdata13][5]->Draw("same hist"); onSun(0,0,2,0); */ }
void drawDCAcontamination(){ gStyle->SetOptStat(0); TFile * file = TFile::Open("/Users/sandrobjelogrlic/Analysis/HFCorrelations/Results/MCCE/83_12022015/10f7a/AnalysisResults.root"); TDirectoryFile * dir = (TDirectoryFile*)file->Get("PWGHF_HFCJ_SE_EffY_DEffY_vsPt_32_bins_SE_RECO_reco_2_348_sigmas"); TList * list = (TList*)dir->Get("OutputMCSE_RECO"); TH1D * isPhysPrimDCA = (TH1D*)list->FindObject("isPhysPrimDCA"); TH1D * isSecondaryDCA = (TH1D*)list->FindObject("isSecondaryDCA"); isPhysPrimDCA->GetXaxis()->SetRangeUser(0,2); isPhysPrimDCA->SetLineColor(2); isSecondaryDCA->SetLineColor(4); isPhysPrimDCA->SetTitle("; DCA_{XY} (cm); Counts"); isPhysPrimDCA->GetYaxis()->SetTitleOffset(1.2); TPaveText * PaveText = new TPaveText(0.5,0.55,0.8,0.7,"NDC"); PaveText->SetBorderSize(0); PaveText->SetFillColor(0); PaveText->SetName("pave"); // PaveText->AddText("THIS THESIS"); // PaveText->AddText(" "); PaveText->AddText("Phytia, pp #sqrt{s} = 7 TeV"); //PaveText->AddText(" "); // PaveText->AddText("Fraction of Primary tracks as funct"); TLine * cut = new TLine(0.25,0,0.25,10000000); cut->SetLineStyle(2); TLegend * legend = new TLegend(0.4,0.7,0.8,0.85); // TLegend * legend = new TLegend(0.1, 1.2*DStarPeak->GetBinContent(DStarPeak->GetMaximumBin()),0.4, 1.6*DStarPeak->GetBinContent(DStarPeak->GetMaximumBin())); legend->SetFillColor(0); legend->SetTextSize(0.03); legend->SetBorderSize(0); legend->AddEntry(isPhysPrimDCA,"Primary tracks","l"); legend->AddEntry(isSecondaryDCA,"Secondary tracks","l"); legend->AddEntry(cut,"Standard cut, DCA_{XY} < 0.25 cm","l"); //legend->AddEntry(h_Perugia2011,"Pythia, Perugia 2011 tune","lep"); TCanvas * c1 = new TCanvas("c1","c1",0,0,1000,1000); c1->cd(); c1->SetLogy(); isPhysPrimDCA->Draw(); isSecondaryDCA->Draw("same"); legend->Draw("same"); PaveText->Draw("same"); cut->Draw("same"); // cout << "Integral is " << getIntegral(DCA,isPhysPrimDCA) << endl; TLegend * legend2 = new TLegend(0.4,0.7,0.8,0.85); // TLegend * legend = new TLegend(0.1, 1.2*DStarPeak->GetBinContent(DStarPeak->GetMaximumBin()),0.4, 1.6*DStarPeak->GetBinContent(DStarPeak->GetMaximumBin())); legend2->SetFillColor(0); legend2->SetTextSize(0.03); legend2->SetBorderSize(0); legend2->AddEntry(cut,"Standard cut, DCA_{XY} < 0.25 cm","l"); TPaveText * PaveText2 = new TPaveText(0.5,0.3,0.8,0.5,"NDC"); PaveText2->SetBorderSize(0); PaveText2->SetFillColor(0); PaveText2->SetName("pave2"); // PaveText->AddText("THIS THESIS"); // PaveText->AddText(" "); PaveText2->AddText("PYTHIA, pp #sqrt{s} = 7 TeV"); TH1D * contamination = (TH1D*)isPhysPrimDCA->Clone("contamination"); contamination->Reset(); contamination->SetTitle("; DCA_{XY} (cm); Purity"); contamination->GetYaxis()->SetRangeUser(0.8,1.05); contamination->GetXaxis()->SetRangeUser(0,1); contamination->SetLineColor(1); contamination->SetLineWidth(2); contamination->GetYaxis()->SetTitleOffset(1.4); Double_t dcavalue = 0; for(Int_t k=0; k<2000; k++){ dcavalue += 0.001; contamination->SetBinContent(k+1,getPurity(dcavalue,isPhysPrimDCA,isSecondaryDCA)); } TLine * cut2 = new TLine(0.25,0.8,0.25,1.05); cut2->SetLineStyle(2); TCanvas * c2 = new TCanvas("c2","c2",0,0,1000,1000); c2->cd(); contamination->Draw(); PaveText2->Draw("same"); cut2->Draw("same"); legend2->Draw("same"); c1->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/DCADistrib.pdf"); c1->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/DCADistrib.eps"); c1->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/DCADistrib.png"); c1->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/DCADistrib.root"); c2->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/purity.pdf"); c2->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/purity.png"); c2->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/purity.eps"); c2->SaveAs("/Users/sandrobjelogrlic/PhD_Thesis/Figures/Chapter_3/purity.root"); }
// ----------------------------------------------------------------------------- // TCanvas* createPlot( TString path, TString canvas_name, TString name, TString dirmame, int rebin, bool norm, bool log, TDirectory* file ) { // SetSomeStyles(); float lumi = 250.0;// 15.04;//10.9;//6.8; // Create legend TLegend* legend = new TLegend(0.75, 0.6, 0.99, 0.99, "", "brNDC" ); legend->SetFillColor(0); legend->SetLineColor(0); legend->SetShadowColor(0); TLatex* prelim = new TLatex(0.6,0.54,"#scale[0.8]{CMS preliminary 2010}"); prelim->SetNDC(); TLatex* alumi = new TLatex(0.6,.45,"#scale[0.8]{#int L dt = 35 pb^{-1}, #sqrt{s} = 7 TeV}"); alumi->SetNDC(); // Create canvas TCanvas* aCanvas = createCanvas( canvas_name, file, log ); // Create histogram TString aname("nAll"); // TH1D* data1 = getHisto( path+"S14datacleaned/Edward_Data_Skim/",name,"data.root",aname,rebin); // TH1D* data = getHisto( path+"S14datacleaned/Edward_Data_Skim/",name,"data.root",dirmame,rebin); TH1D* data = getHisto( path+"", name, "tt.root", dirmame, rebin ); TH1D* qcd = getHisto( path+"", name, "lm1.root", dirmame, rebin ); TH1D* w_jets = getHisto( path+"", name, "w.root", dirmame, rebin ); TH1D* tt_jets = getHisto( path+"", name, "tt.root", dirmame, rebin ); TH1D* z_jets = getHisto( path+"", name, "z.root", dirmame, rebin ); TH1D* lm3 = getHisto( path+"", name, "lm3.root", dirmame, rebin ); TH1D* lm1 = getHisto( path+"", name, "lm1.root", dirmame, rebin ); TH1D* lm6 = getHisto( path+"", name, "data.root", dirmame, rebin ); TH1D* wm = getHisto( path+"", name, "w.root", dirmame, rebin ); data->Scale(lumi/100.); qcd->Scale(lumi/100.); tt_jets->Scale(lumi/100); w_jets->Scale(lumi/100); // w_jets->Scale(10); // z_inv->Scale(lumi/100); // lm6->Scale(lumi/100); lm1->Scale(lumi/100); lm3->Scale(lumi/100); z_jets->Scale(lumi/100); wm->Scale(lumi/100); // Combine Z+jets and Z->inv // TH1D* z_all = z_inv->Clone(); // z_all->Add(z_jets,1); //z_jets->Add(z_inv,1); TH1D* total = tt_jets->Clone(); total->Add(w_jets); total->Add(z_jets); // total-> Int_t binMax = total->GetNbinsX(); Double_t& err = new Double_t(0.); total->IntegralAndError(10,binMax ,err); Double_t& errW = new Double_t(0.); w_jets->IntegralAndError(10,binMax ,errW); Double_t& errtt = new Double_t(0.); tt_jets->IntegralAndError(10,binMax ,errtt); Double_t& errZ = new Double_t(0.); z_jets->IntegralAndError(10,binMax ,errZ); Double_t& errQCD = new Double_t(0.); qcd->IntegralAndError(10,binMax ,errQCD ); cout <<endl; // cout << "MC:" << total->IntegralAndError(11,binMax ,err) <<" && " << w_jets->Integral(11,binMax)<<" && "<<tt_jets->Integral(11,binMax) << "&& "<<z_jets->Integral(11,binMax)<<" && "<< "\/\ /\hline"<<endl; // cout << total->IntegralAndError(0,binMax ,err) <<" & " << lm1->Integral(0,binMax) <<" & " << lm3->Integral(0,binMax)<<" & " << lm6->Integral(0,binMax) <<"\\\\ \\hline"<<endl; // cout <<"270: " << total->IntegralAndError(27,binMax ,err) <<" & " << lm1->Integral(27,binMax) <<" & " << lm3->Integral(27,binMax)<<" & " << lm6->Integral(27,binMax) <<"\\\\ \\hline"<<endl; cout <<"250& " << total->IntegralAndError(6,binMax ,err) <<" & " << lm1->Integral(6,binMax) <<" & " << lm3->Integral(6,binMax)<<" & " << lm6->Integral(6,binMax) <<"\\\\ \\hline"<<endl; // cout << "300: " << total->IntegralAndError(7,binMax ,err) <<" & " << lm1->Integral(7,binMax) <<" & " << lm3->Integral(7,binMax)<<" &" << lm6->Integral(7,binMax) <<"\\\\ \\hline"<<endl; cout <<"350& " << total->IntegralAndError(8,binMax ,err) <<" & " << lm1->Integral(8,binMax) <<" & " << lm3->Integral(8,binMax)<<" & " << lm6->Integral(8,binMax) <<"\\\\ \\hline"<<endl; // cout << "400: " << total->IntegralAndError(9,binMax ,err) <<" & " << lm1->Integral(9,binMax) <<" & " << lm3->Integral(9,binMax)<<" & " << lm6->Integral(9,binMax) <<"\\\\ \\hline"<<endl; cout << "450& " << total->IntegralAndError(10,binMax ,err) <<" & " << lm1->Integral(10,binMax) <<" & " << lm3->Integral(10,binMax)<<" & " << lm6->Integral(10,binMax) <<"\\\\ \\hline"<<endl; //cout << "500: " << total->IntegralAndError(11,binMax ,err) <<" & " << lm1->Integral(11,binMax) <<" & " << lm3->Integral(11,binMax)<<" & " << lm6->Integral(11,binMax) <<"\\\\ \\hline"<<endl; cout <<"550& " << total->IntegralAndError(12,binMax ,err) <<" & " << lm1->Integral(12,binMax) <<" & " << lm3->Integral(12,binMax)<<" & " << lm6->Integral(12,binMax) <<"\\\\ \\hline"<<endl; /* cout << "MC:" << total->IntegralAndError(7,binMax ,err) <<" && " << lm1->Integral(7,binMax) <<" && " << lm3->Integral(7,binMax)<<" && " << lm6->Integral(6,binMax) <<"/\/\ /\hline"<<endl; cout << "MC:" << total->IntegralAndError(8,binMax ,err) <<" && " << lm1->Integral(8,binMax) <<" && " << lm3->Integral(8,binMax)<<" && " << lm6->Integral(7,binMax) <<"/\/\ /\hline"<<endl; cout << "MC:" << total->IntegralAndError(10,binMax ,err) <<" && " << lm1->Integral(10,binMax) <<" && " << lm3->Integral(10,binMax)<<" && " << lm6->Integral(10,binMax) <<"/\/\ /\hline"<<endl; cout << "MC:" << total->IntegralAndError(11,binMax ,err) <<" && " << lm1->Integral(11,binMax) <<" && " << lm3->Integral(11,binMax)<<" && " << lm6->Integral(11,binMax) <<"/\/\ /\hline"<<endl; cout << "MC:" << total->IntegralAndError(12,binMax ,err) <<" && " << lm1->Integral(12,binMax) <<" && " << lm3->Integral(12,binMax)<<" && " << lm6->Integral(12,binMax) <<"/\/\ /\hline"<<endl; // cout << "MC:" << err <<", W: " << errW<<", tt: "<<errtt << ", Z: "<<errZ<<", QCD: "<< errQCD<< endl; */ // cout << "data:" << data->Integral() << endl; TH1D* hcen = total->Clone(); TH1D* herr = total->Clone(); herr->SetLineColor(kTeal+3); herr->SetMarkerColor(kAzure+6); herr->SetFillColor(kAzure+6); herr->SetLineWidth(3); total->SetLineWidth(3); total->SetFillColor(kAzure+2); total->SetLineColor(kAzure+2); total->SetFillStyle(3245); hcen->SetFillStyle(0); hcen->SetMarkerColor(kTeal+3); hcen->SetLineColor(kTeal+3); hcen->SetLineWidth(3); // Merge Z+jets and Z->inv bool combine = false; // Line colour and fill qcd->SetLineColor(kPink+4); qcd->SetLineWidth(3); tt_jets->SetLineColor(kBlue+1); tt_jets->SetLineWidth(3); w_jets->SetLineColor(kPink+7); w_jets->SetLineWidth(3); z_jets->SetLineWidth(3); z_jets->SetLineColor(kTeal-7); if ( combine ) { z_all->SetLineColor(kBlack); z_all->SetLineStyle(3); z_all->SetLineWidth(1); } else { data->SetLineColor(1); data->SetLineStyle(1); data->SetLineWidth(3); data->SetMarkerStyle(20); data->SetFillColor(0); } // lm0->SetLineColor(kRed); // lm0->SetLineWidth(3); // lm1->SetLineColor(kRed+3); // lm1->SetLineWidth(3); // Populate legend // legend->AddEntry( data, "tt fully leptonic/", "LP" ); legend->AddEntry( herr, "full SM", "LP" ); legend->AddEntry( z_jets, " Z+jets ", "LP" ); legend->AddEntry( w_jets, " W+jets", "LP" ); legend->AddEntry( tt_jets, " t#bar{t}", "LP" ); // legend->AddEntry( lm3, " SUSY LM3", "LP" ); // legend->AddEntry( lm1, " SUSY LM1", "LP" ); legend->AddEntry( lm6, " data", "LP" ); // legend->AddEntry(wm,"W Mad","lp"); // Calc maximum number of entries double aMax = 0.; if( data->GetMaximum() > aMax ) { aMax = data->GetMaximum()+data->GetBinError(data->GetMaximumBin()); } if ( qcd->GetMaximum() > aMax ) { aMax = qcd->GetMaximum(); } // if ( lm0->GetMaximum() > aMax ) { aMax = lm0->GetMaximum(); } // if ( lm1->GetMaximum() > aMax ) { aMax = lm1->GetMaximum(); } if ( tt_jets->GetMaximum() > aMax ) { aMax = tt_jets->GetMaximum(); } if ( w_jets->GetMaximum() > aMax ) { aMax = w_jets->GetMaximum(); } if ( combine ) { if ( z_all->GetMaximum() > aMax ) { aMax = z_all->GetMaximum(); } } else { // if ( data->GetMaximum() > aMax ) { aMax = z_inv->GetMaximum(); } if ( z_jets->GetMaximum() > aMax ) { aMax = z_jets->GetMaximum(); } } // Calc minimum number of entries double aMin = 1.e12; if ( qcd->GetMinimum(1.e-12) < aMin ) { aMin = qcd->GetMinimum(1.e-12); } // if ( lm0->GetMinimum(1.e-12) < aMin ) { aMin = lm0->GetMinimum(1.e-12); } // if ( lm1->GetMinimum(1.e-12) < aMin ) { aMin = lm1->GetMinimum(1.e-12); } if ( tt_jets->GetMinimum(1.e-12) < aMin ) { aMin = tt_jets->GetMinimum(1.e-12); } if ( w_jets->GetMinimum(1.e-12) < aMin ) { aMin = w_jets->GetMinimum(1.e-12); } if ( combine ) { if ( z_all->GetMinimum(1.e-12) < aMin ) { aMin = z_all->GetMinimum(1.e-12); } } else { // if ( data->GetMinimum(1.e-12) < aMin ) { aMin = z_inv->GetMinimum(1.e-12); } if ( z_jets->GetMinimum(1.e-12) < aMin ) { aMin = z_jets->GetMinimum(1.e-12); } } if ( qcd ) qcd->GetYaxis()->SetTitleOffset(1.43); if ( qcd ) qcd->GetYaxis()->SetTitleSize(0.06); if ( qcd ) qcd->GetXaxis()->SetTitleSize(0.06); if ( qcd ) qcd->GetXaxis()->SetTitleOffset(0.9); if ( log ) { if ( qcd ) herr->SetMaximum( aMax * 10. ); // if ( qcd ) herr->SetMinimum( aMin * 0.1 ); if ( qcd ) herr->SetMinimum( 0.005); } else { if ( qcd ) herr->SetMaximum( aMax * 1.1 ); // if ( qcd ) herr->SetMinimum( aMin * 0.9 ); if ( qcd ) herr->SetMinimum( 0.005); } /* TPad* mainPad = new TPad("","",0.01,0.25,0.99,0.99); mainPad->SetNumber(1); mainPad->SetFillColor(0); // mainPad->Range(-288.2483,-2.138147,1344.235,6.918939); mainPad->SetFillColor(0); mainPad->SetBorderMode(0); mainPad->SetBorderSize(2); if ( log == true)mainPad->SetLogy(); mainPad->SetLeftMargin(0.1765705); mainPad->SetRightMargin(0.05772496); mainPad->SetTopMargin(0.04778761); mainPad->SetBottomMargin(0.1256637); mainPad->SetFrameFillStyle(0); mainPad->SetFrameLineWidth(2); mainPad->SetFrameBorderMode(0); mainPad->SetFrameFillStyle(0); mainPad->SetFrameLineWidth(2); mainPad->SetFrameBorderMode(0); if ( log == true)mainPad->SetLogy(); mainPad->Draw(); TPad* ratioPad = new TPad("","",0.01,0.01,0.99,0.25); ratioPad->SetNumber(2); ratioPad->SetFillColor(0); ratioPad->SetFillColor(0); ratioPad->SetBorderMode(0); ratioPad->SetBorderSize(2); // if ( log == true)ratioPad->SetLogy(); ratioPad->SetLeftMargin(0.1765705); ratioPad->SetRightMargin(0.05772496); ratioPad->SetTopMargin(0.04778761); ratioPad->SetBottomMargin(0.1256637); ratioPad->SetFrameFillStyle(0); ratioPad->SetFrameLineWidth(2); ratioPad->SetFrameBorderMode(0); ratioPad->SetFrameFillStyle(0); ratioPad->SetFrameLineWidth(2); ratioPad->SetFrameBorderMode(0); // if ( log == true)ratioPad->SetLogy(); ratioPad->Draw(); aCanvas->cd(1); */ herr->GetYaxis()->SetTitle("events"); if ( norm ) { if ( qcd ) qcd->DrawNormalized("Ehist"); // if ( lm0->GetEntries() > 0. ) { lm0->DrawNormalized("hsame"); } if ( lm1->GetEntries() > 0. ) { lm1->DrawNormalized("hsame"); } if ( tt_jets->GetEntries() > 0. ) { tt_jets->DrawNormalized("hsame"); } if ( w_jets->GetEntries() > 0. ) { w_jets->DrawNormalized("hsame"); } if ( combine ) { if ( z_all->GetEntries() > 0. ) { z_all->DrawNormalized("hsame"); } } else { if ( data->GetEntries() > 0. ) { z_inv->DrawNormalized("hsame"); } if ( z_jets->GetEntries() > 0. ) { z_jets->DrawNormalized("hsame"); } } } else { herr->Draw("hist"); // qcd->SetFillStyle(3240); // qcd->SetFillColor(kPink+4); // qcd->Draw("hist"); w_jets->Draw("hSameh"); z_jets->Draw("9Sameh"); w_jets->Draw("9Sameh"); tt_jets->Draw("9SAMEh"); //data1->Draw("9SAMEh"); //lm0->Draw("9SAMEh"); lm1->SetLineColor(12); lm1->SetLineStyle(2); lm1->SetLineWidth(2); // lm1->Draw("9SAMEh"); lm3->SetLineColor(14); lm3->SetLineStyle(2); lm3->SetLineWidth(2); // lm3->Draw("9SAMEh"); lm6->Draw("9SAMEh"); wm->SetLineStyle(2); wm->SetLineColor(kPink+7); // wm->Draw("9Sameh"); // total->DrawNormalized("9E2same"); // data->Draw("SAMEh"); // tt_jets->Divide(data); // tt_jets->Draw("h"); // data->SetLineColor(kRed); // data->Draw("sameh"); // data1->SetLineColor(kRed); // data1->Draw("9SAMEP"); } legend->Draw(); // prelim->Draw(); // alumi->Draw(); /* TH1D* ratioBottom = total->Clone(); TH1D* ratioTop = data->Clone(); ratioTop->GetYaxis()->SetTitle("data / sim"); ratioTop->Divide(ratioBottom); aCanvas->cd(1)->Update(); aCanvas->cd(2); ratioTop->SetTitleSize(0.1, "XYZ"); ratioTop->SetTitleOffset(0.55, "X"); ratioTop->SetTitleOffset(0.3, "Y"); ratioTop->SetLabelSize(0.06,"XY"); // ratioTop->GetXaxis().SetRangeUser(MinX,MaxX); ratioTop->GetYaxis()->SetRangeUser(0.,2.0); ratioTop->Draw();*/ /* TBox* unity = TBox(ratioTop->GetXaxis()->GetBinLowEdge(ratioTop->GetXaxis()->GetFirst()), 0.89,ratioTop->GetXaxis()->GetBinLowEdge(ratioTop->GetXaxis()->GetLast()), 1.11); unity->SetLineWidth(2); unity->SetLineColor(2); unity->SetFillColor(2); unity->SetFillStyle(3002); unity->Draw(); */ file->cd(); aCanvas->SaveAs( std::string(canvas_name+".pdf").c_str() ); aCanvas->Write(); // aCanvas->Print(".png"); return aCanvas; }
/* ***************************************************************************************************************** */ int main(int argc, char* argv[]) { cout << "sis3316_offline" << endl; // prints sis3316_offline /******************************************************************************************************************************/ /* CERN ROOT */ /******************************************************************************************************************************/ #ifdef CERN_ROOT_PLOT printf("--> CERN_ROOT_PLOT is defined \n"); int root_graph_x ; int root_graph_y ; int root_graph_x_size ; int root_graph_y_size ; char root_graph_text[80] ; root_graph_x_size = 1000 ; root_graph_y_size = 500 ; root_graph_x = 10 ; root_graph_y = 620 ; cout << "argc: " << argc << endl; for (int i = 1; i < argc; i++){ cout << "argv[" << i << "]: " << argv[i] << endl; } // this root class extracts data from argc and argv, modifying them in the // process TApplication theApp("SIS3316 Application: Test", &argc, argv); strcpy(root_graph_text,"SIS3316 Graph: Raw data") ; gl_graph_raw = new sis_root_graph(root_graph_text, root_graph_x, root_graph_y, root_graph_x_size, root_graph_y_size) ; #endif #ifdef raus printf("--> raus is defined \n"); // file read gl_FILE_DataEvenFilePointer = fopen("ne213/sis3316_test_data.dat","rb") ; if (gl_FILE_DataEvenFilePointer == NULL) { printf("gl_FILE_DataEvenFilePointer == NULL \n"); return -1; } else { printf("file is opened \n"); } #endif UInt_t valid_BankBufferHeader_valid_flag ; int nof_read ; UInt_t buffer_no ; UInt_t i_event ; UInt_t nof_events ; UInt_t buffer_length ; UInt_t event_length ; UInt_t header_length ; UInt_t wfm_length ; UInt_t channel_no ; UInt_t maw_length ; UInt_t i_ch ; UInt_t headerformat ; UInt_t header_indentifier ; UInt_t header_reserved ; //gl_graph_raw->sis3316_draw_XYaxis (50000); // clear and draw X/Y //gl_graph_raw->sis3316_draw_XYaxis (wfm_length); // clear and draw X/Y UInt_t bank_buffer_counter ; char filename[128] ; int i_file; bank_buffer_counter = 8 ; bool doDraw = true; if ( gROOT->IsBatch() ) { doDraw = false; cout << "--> running in batch mode" << endl; } // loop over enumerated files in internal directory: //for (i_file=0; i_file<10; i_file++) { //sprintf(filename,"../data_files/sample_test_gui/sis3316_test_data_%d.dat",i_file ) ; //sprintf(filename,"../data_files/external/sis3316_test_data_%d.dat",i_file ) ; //sprintf(filename,"../data_files/internal/sis3316_test_data_%d.dat",i_file ) ; // loop over args: for (i_file = 1; i_file<theApp.Argc(); i_file++) { //cout << "filename: " << argv[i_file+1] << endl; //sprintf(filename,"%s",argv[i_file+1]) ; sprintf(filename,"%s", theApp.Argv(i_file)) ; #ifdef CERN_ROOT_PLOT string filename_str(filename); if ( filename_str.size() < 3 ) { cout << "option: " << filename_str << endl; continue; } cout << "filename: " << filename << endl; size_t dot = filename_str.find_last_of("."); size_t slash = filename_str.find_last_of("/"); string basename_str = "tier1_" + filename_str.substr(slash+1, dot-slash-1); string config_filename_str = filename_str.substr(0, dot) + ".ini"; cout << "Setting file label " << basename_str << endl; // open a root file TFile root_file((basename_str + ".root").c_str(), "recreate"); // make trees TTree *tree[16]; //default values for branches //global parameters Bool_t is_external = true; Float_t sampling_freq_Hz = 25e6; // in Hz UShort_t wfm_delay = 200; UShort_t maw_delay = 600; Bool_t is_pospolarity[16]; Bool_t is_50ohm[16]; Bool_t is_2Vinput[16]; UShort_t maw_gap = 250; UShort_t maw_peaking = 50; UShort_t maw_thres = 60; for(int i=0; i<=15; i++) {is_pospolarity[i] = is_50ohm[i] = is_2Vinput[i] = true;} //read from config file ReadConfigFile(config_filename_str, &is_external, &sampling_freq_Hz, &wfm_delay, &maw_delay, is_pospolarity, is_50ohm, is_2Vinput, &maw_gap, &maw_peaking, &maw_thres); //other parameters Int_t wfm_max = 0; UShort_t wfm_max_time = 0; Int_t wfm_min = 0; Int_t maw_max = 0; Int_t maw_min = 0; UChar_t channel = 0; ULong64_t timestamp = 0; Double_t timestampDouble = 0; //ULong64_t timestampLo = 0; //ULong64_t timestampHi = 0; UShort_t * wfm = new UShort_t[65536]; Int_t * maw = new Int_t[2048*4]; //read configuration file for(int i=0; i<=15; i++) { // looping over the 16 trees ostringstream treename; treename << "tree" << i; tree[i] = new TTree(treename.str().c_str(), "tree of SIS waveform data"); // global parameters tree[i]->Branch("is_external", &is_external, "is_external/O"); tree[i]->Branch("sampling_freq_Hz", &sampling_freq_Hz, "sampling_freq_Hz/F"); tree[i]->Branch("wfm_delay", &wfm_delay, "wfm_delay/s"); tree[i]->Branch("wfm_length", &wfm_length, "wfm_length/i"); tree[i]->Branch("maw_delay", &maw_delay, "maw_delay/s"); tree[i]->Branch("maw_length", &maw_length, "maw_length/i"); tree[i]->Branch("is_pospolarity", &is_pospolarity[i], "is_pospolarity/O"); tree[i]->Branch("is_50ohm", &is_50ohm[i], "is_50ohm/O"); tree[i]->Branch("is_2Vinput", &is_2Vinput[i], "is_2Vinput/O"); tree[i]->Branch("maw_gap", &maw_gap, "maw_gap/s"); tree[i]->Branch("maw_peaking", &maw_peaking, "maw_peaking/s"); tree[i]->Branch("maw_thres", &maw_thres, "maw_thres/s"); // create a maximum-value branch //UInt_t wfm_max = 0; tree[i]->Branch("wfm_max", &wfm_max, "wfm_max/I"); // time of waveform max value: //UInt_t wfm_max_time = 0; tree[i]->Branch("wfm_max_time", &wfm_max_time, "wfm_max_time/s"); // create a mininum-value branch //UInt_t wfm_min = 0; tree[i]->Branch("wfm_min", &wfm_min, "wfm_min/I"); // create a maximum-value branch //signed int maw_max = 0; tree[i]->Branch("maw_max", &maw_max, "maw_max/I"); // create a mininum-value branch //signed int maw_min = 0; tree[i]->Branch("maw_min", &maw_min, "maw_min/I"); // create a channel branch //int channel = 0; tree[i]->Branch("channel", &channel, "channel/b"); // 8 bit unsigned integer // create a timestamp branch //ULong64_t timestamp = 0; //double timestampDouble = 0; tree[i]->Branch("timestamp", ×tamp, "timestamp/l"); // 64 bit unsigned integer (ULong64_t) tree[i]->Branch("timestampDouble", ×tampDouble, "timestampDouble/D"); // (Double_t) // create a buffer number branch // tree[i]->Branch("buffer_no", &buffer_no); // create an event number branch tree[i]->Branch("event", &i_event, "event/i"); // unsigned integer (UInt_t) // wfm //UShort_t * wfm = new UShort_t[2048*4]; tree[i]->Branch("wfm", wfm, "wfm[wfm_length]/s"); // maw buffer tree[i]->Branch("maw_length", &maw_length); // maw //signed int * maw = new signed int[2048*4]; tree[i]->Branch("maw", maw, "maw[maw_length]/I"); } #endif cout << "argc: " << argc << endl; for (int i = 1; i < argc; i++){ cout << "argv[" << i << "]: " << argv[i] << endl; } //cout << theApp.Argc() << endl; //cout << theApp.Argv(i_file) << endl; printf("--> processing file: %s\n",filename) ; gl_FILE_DataEvenFilePointer = fopen(filename,"rb") ; if (gl_FILE_DataEvenFilePointer != NULL) { do { valid_BankBufferHeader_valid_flag = 0 ; // read the buffer header nof_read = ReadBufferHeaderCounterNofChannelToDataFile (&header_indentifier, &buffer_no, &channel_no, &nof_events, &event_length, &maw_length, &header_reserved) ; buffer_length = event_length * nof_events ; printf("\n"); printf("header information: \tnof_read = %d \tindentifier = %d \tbuffer_no = %d \tchannel_no = %d \n", nof_read, header_indentifier, buffer_no, channel_no); printf("header information: \tnof_events = %d \tbuffer_length = %d \tevent_length = %d \n", nof_events, buffer_length, event_length ); printf("header information: \tmaw_length = %d \treserved = %d \n", maw_length, header_reserved); unsigned uint_plot_axis_flag; if (nof_read == 8) { uint_plot_axis_flag = 1 ; valid_BankBufferHeader_valid_flag = 1 ; // read buffer (of nof_events events) into gl_ch_data nof_read = ReadEventsFromDataFile (gl_ch_data, buffer_length); // grab header format and channel number from the 0th event; assume // this applies to all nof_events // mask to get the header format: headerformat = (gl_ch_data[0] & 0xf) ; // mask and bitshift to get the channel number i_ch = (gl_ch_data[0] & 0xfff0) >> 4 ; printf("nof_read = %d \tch = %d \theaderformat = 0x%02X \n", nof_read, i_ch, headerformat); if (i_ch != channel_no) { cout << "WARNING -- i_ch=" << i_ch << ", channel_no=" << channel_no << endl; } header_length = 3 ; // if headerformat == 0 if((headerformat & 0x1) == 1) {header_length = header_length + 7; } if((headerformat & 0x2) == 2) {header_length = header_length + 2; } if((headerformat & 0x4) == 4) {header_length = header_length + 3; } if((headerformat & 0x8) == 8) {header_length = header_length + 2; } // wfm_length is the number of 16-bit ADC samples in each event // event_length is the number of 32-bit words in each event wfm_length = 2 * (gl_ch_data[header_length-1] & 0x3ffffff) ; // if headerformat == 0 if(uint_plot_axis_flag == 1) { //printf("uint_plot_axis_flag == 1\n"); uint_plot_axis_flag = 0 ; gl_graph_raw->sis3316_draw_XYaxis (wfm_length); // clear and draw X/Y } // loop over all events in gl_ch_data for (i_event = 0; i_event < nof_events; i_event++) { //if (i_event<10) { // plot ony the first 10. events //if (i_event<1) { // plot ony 1. event //cout << sizeof(UInt_t) << endl; // gl_ch_data is an UInt_t is 4 bytes (32 bits), at least on // Alexis' Mac. Bit mask each part of the timestamp, then bit shift to // make the 48-bit timestamp // 0xffff = 32 bits, 4 bytes size_t event_index = i_event*event_length; //cout << "gl_ch_data[event_index + 1] : " << gl_ch_data[event_index + 1] << endl; //cout << "gl_ch_data[event_index]: " << gl_ch_data[event_index] << endl; //cout << "(gl_ch_data[event_index] & 0xffff0000): " << ( (ULong64_t) (gl_ch_data[event_index] & 0xffff0000)) << endl; //cout << "(gl_ch_data[event_index] & 0xffff0000) << 16 :" << ( (ULong64_t) (gl_ch_data[event_index] & 0xffff0000) << 16) << endl; timestamp = ( (ULong64_t) (gl_ch_data[event_index] & 0xffff0000) << 16) ; timestamp += gl_ch_data[event_index + 1]; //timestampHi = ( (ULong64_t) (gl_ch_data[event_index] & 0xffff0000) << 16) ; //timestampLo = gl_ch_data[event_index + 1]; timestampDouble = (Double_t) timestamp; // find the wfm maximum value wfm_max = 0; wfm_max_time = 0; wfm_min = pow(2, 14); // max value of ADC UShort_t* ushort_adc_buffer_ptr = (UShort_t*) (&gl_ch_data[i_event*(event_length) + header_length]); for (UInt_t i = 0; i < wfm_length; i++ ) { UInt_t adc_value = (UInt_t) ushort_adc_buffer_ptr[i]; wfm[i] = adc_value; //cout << i << " | " << adc_value << endl; if (adc_value > wfm_max){ wfm_max = adc_value; wfm_max_time = i; } if (adc_value < wfm_min){ wfm_min = adc_value; } } if (doDraw) { cout << "wfm_max: " << wfm_max << endl; cout << "timestamp: " << timestamp << endl; gl_graph_raw->sis3316_draw_chN (wfm_length, &gl_ch_data[event_index + header_length], i_ch&0xf); // insert pause cout << "event " << i_event << " | channel " << i_ch << " | enter to continue (q=quit, b=batch, p=print)--> "; int val = cin.get(); cout << endl; if (val == (int) 'q' || val == (int) 'Q') { return 0; } if (val == (int) 'b') { doDraw = false; } if (val == (int) 'p') { ostringstream plotName; plotName << basename_str << i_event; //gl_graph_raw->c1->Print((plotName.str() + ".png").c_str()); //gl_graph_raw->c1->Print((plotName.str() + ".pdf").c_str()); } } //wfm = (UShort_t*) &(gl_ch_data[event_index + header_length]); //------------------------------------------------------------------------------ // MAW //------------------------------------------------------------------------------ // find the maw maximum value // I hope this is the MAW maw_max = 0; maw_min = INT_MAX; // max value of MAW //UShort_t* maw_adc_buffer_ptr = (UShort_t*) //(&gl_ch_data[i_event*(event_length) + header_length + //wfm_length/2]); // Tino says maw is 32 bits: UInt_t* maw_adc_buffer_ptr = &gl_ch_data[i_event*(event_length) + header_length + wfm_length/2]; for (UInt_t i = 0; i < maw_length; i++ ) { signed int maw_value = maw_adc_buffer_ptr[i] - 0x8000000; // per Tino maw[i] = maw_value; //cout << i // << " | maw_adc_buffer_ptr[i]:" << maw_adc_buffer_ptr[i] // << " | maw_value: " << maw_value // << " | maw[i] " << maw[i] // << endl; if (maw_value > maw_max){ maw_max = maw_value; } if (maw_value < maw_min){ maw_min = maw_value; } } /* if (doDraw) { cout << "maw_max: " << maw_max << endl; cout << "timestamp: " << timestamp << endl; gl_graph_raw->sis3316_draw_chN (wfm_length, &gl_ch_data[event_index + header_length + wfm_length/2], i_ch&0xf); // insert pause cout << "event " << i_event << " | channel " << i_ch << " | enter to continue (q=quit, b=batch)--> "; int val = cin.get(); cout << endl; if (val == (int) 'q' || val == (int) 'Q') { return 0; } if (val == (int) 'b') { doDraw = false; } } */ channel = (gl_ch_data[event_index] & 0xfff0) >> 4; tree[channel]->Fill(); // each buffer should contain data from only one channel if (i_ch != channel_no) { cout << "WARNING -- channel=" << channel << ", channel_no=" << channel_no << endl; } //} // end limit on n events } // end loop over events } // end if(nof_read==8) else { valid_BankBufferHeader_valid_flag = 0 ; } } while(valid_BankBufferHeader_valid_flag == 1) ; printf("\n"); fclose(gl_FILE_DataEvenFilePointer); printf("file closed and finished \n"); bank_buffer_counter++; } gROOT->SetStyle("Plain"); gStyle->SetOptStat(0); gStyle->SetPalette(1); gStyle->SetTitleStyle(0); gStyle->SetTitleBorderSize(0); int n_bins = 200; int min = 0; int max = 16384; const size_t n_channels = 16; const size_t n_colors = 4; TH1D* hist_array[n_channels]; int color[n_colors] = {kRed, kBlue, kGreen+1, kViolet}; int fillStyle[n_channels] = {3004, 3005, 3006, 3007, 3001, 3002, 3003, 3016, 3017, 3018, 3020, 3021}; TH1D frame_hist("frame_hist","",n_bins, min, max); frame_hist.SetXTitle("Waveform max (ADC units)"); frame_hist.SetYTitle("Counts"); for (size_t i = 0; i <n_channels; i++) { ostringstream name; name << "h" << i; TH1D* hist = new TH1D(name.str().c_str(), "", n_bins, min, max); int i_color = i % n_colors; //cout << i << " | " << name.str() << " | " << i_color << endl; hist->SetLineColor(color[i_color]); hist->SetFillColor(color[i_color]); hist->SetFillStyle(fillStyle[i]); hist_array[i] = hist; } TLegend legend(0.1, 0.81, 0.9, 0.99); legend.SetNColumns(4); TCanvas canvas("canvas", ""); canvas.SetLogy(1); canvas.SetGrid(1,1); canvas.SetTopMargin(0.2); double hist_max = 0; frame_hist.Draw(); for (size_t i = 0; i < n_channels; i++) { ostringstream entry; ostringstream name; ostringstream selection; name << "wfm_max >> h" << i; selection << "channel==" << i; int n_counts = tree[0]->Draw(name.str().c_str(), selection.str().c_str(), "same"); cout << i << " | n counts = " << n_counts << " | " << name.str() << " | " << selection.str() << endl; entry << "ch " << i+1 << " (" << n_counts << ")"; TH1D* hist = hist_array[i]; legend.AddEntry(hist, entry.str().c_str(), "f"); if ( n_counts > hist_max ) { hist_max = n_counts; } } frame_hist.SetMaximum(hist_max*1.1); legend.Draw(); canvas.Update(); //canvas.Print((basename_str + ".png").c_str()); //canvas.Print((basename_str + ".pdf").c_str()); for(int i=0; i<=15; i++) {tree[i]->Write();} canvas.Write(); // create a run_tree with event parameters TTree *run_tree = new TTree("run_tree", "run tree"); run_tree->Branch("is_external", &is_external, "is_external/O"); run_tree->Branch("sampling_freq_Hz", &sampling_freq_Hz, "sampling_freq_Hz/F"); run_tree->Branch("wfm_delay", &wfm_delay, "wfm_delay/s"); run_tree->Branch("wfm_length", &wfm_length, "wfm_length/i"); run_tree->Branch("maw_delay", &maw_delay, "maw_delay/s"); run_tree->Branch("maw_length", &maw_length, "maw_length/i"); run_tree->Branch("maw_gap", &maw_gap, "maw_gap/s"); run_tree->Branch("maw_peaking", &maw_peaking, "maw_peaking/s"); run_tree->Branch("maw_thres", &maw_thres, "maw_thres/s"); run_tree->Fill(); run_tree->Write(); } // end loop over arguments/files
void fakerate (int min = 0 , int max = 999) { TStyle * ts = (TStyle*)gROOT->GetStyle("Plain"); ts->cd(); ts->SetTitle(0); ts->SetOptStat(0000000); //ts->SetPalette(1); //cross sections in mb double sigma_15_20 = 1.46; double sigma_20_30 = 0.632; double sigma_30_50 = 0.163; double sigma_50_80 = 0.0216; double sigma_80_120 = 0.00308; std::vector<std::string> files; std::vector<double> weights; files.push_back("new1/FakeRate_qcd_loose_20_30.root"); files.push_back("new1/FakeRate_qcd_loose_30_50.root"); files.push_back("new1/FakeRate_qcd_loose_50_80.root"); files.push_back("new1/FakeRate_qcd_loose_80_120.root"); weights.push_back(sigma_20_30); weights.push_back(sigma_30_50); weights.push_back(sigma_50_80); weights.push_back(sigma_80_120); std::vector<std::string> files1; files1.push_back("new1/FakeRate_qcd_medium_20_30.root"); files1.push_back("new1/FakeRate_qcd_medium_30_50.root"); files1.push_back("new1/FakeRate_qcd_medium_50_80.root"); files1.push_back("new1/FakeRate_qcd_medium_80_120.root"); std::vector<std::string> files2; files2.push_back("new1/FakeRate_qcd_tight_20_30.root"); files2.push_back("new1/FakeRate_qcd_tight_30_50.root"); files2.push_back("new1/FakeRate_qcd_tight_50_80.root"); files2.push_back("new1/FakeRate_qcd_tight_80_120.root"); std::vector<TFile*> tfiles; std::vector<TFile*> tfiles1; std::vector<TFile*> tfiles2; for (int i=0; i<files.size(); i++) { tfiles.push_back(new TFile(files[i].c_str())); } for (int i=0; i<files1.size(); i++) { tfiles1.push_back(new TFile(files1[i].c_str())); } for (int i=0; i<files2.size(); i++) { tfiles2.push_back(new TFile(files2[i].c_str())); } TCanvas* cFakeIdDiv = new TCanvas ("cFakeIdDiv","Electron Id Fake Rate vs Jet Et"); cFakeIdDiv->SetLogy(); cFakeIdDiv->SetGridy(); cFakeIdDiv->SetGridx(); TH1D* hSelPT = (TH1D*)plot("HFakeNumSelEt","HFakeDenEt",tfiles,weights); TH1D* hSelPT1 = (TH1D*)plot("HFakeNumSelEt","HFakeDenEt",tfiles1,weights); TH1D* hSelPT2 = (TH1D*)plot("HFakeNumSelEt","HFakeDenEt",tfiles2,weights); TH1D* hRecoPT = (TH1D*)plot("HFakeNumEt","HFakeDenEt",tfiles,weights); hSelPT->SetTitle(0); hRecoPT->SetTitle(0); hSelPT->GetXaxis()->SetRangeUser(10,65); hSelPT->GetYaxis()->SetRangeUser(1e-3,1); //hSelPT->SetMaximum(1.0); hSelPT->GetXaxis()->SetTitle("E_{T} of Reco Jet (GeV)"); hSelPT->GetYaxis()->SetTitle("Electron fake rate from jets (d#epsilon/dE_{T})"); hSelPT->Draw("E"); hSelPT->SetLineColor(4); hSelPT1->SetLineColor(8); hSelPT2->SetLineColor(2); hRecoPT->Draw("sameE"); hSelPT1->Draw("sameE"); hSelPT2->Draw("sameE"); TLegend* legA = new TLegend(0.6,0.2,0.85,0.4); legA->AddEntry(hRecoPT,"Reconstruction","l"); legA->AddEntry(hSelPT,"Id loose","l"); legA->AddEntry(hSelPT1,"Id medium","l"); legA->AddEntry(hSelPT2,"Id tight","l"); legA->SetFillColor(0); legA->SetTextSize(0.04); legA->Draw(); gPad->Update(); TCanvas* cFakeIdDiv1 = new TCanvas ("cFakeIdDiv1","Electron Id Fake Rate vs Jet Et (Rel)"); cFakeIdDiv1->SetLogy(); cFakeIdDiv1->SetGridy(); cFakeIdDiv1->SetGridx(); TH1D* hSelPTA = (TH1D*)plot("HFakeNumSelEt","HFakeNumEt",tfiles,weights); TH1D* hSelPT1A = (TH1D*)plot("HFakeNumSelEt","HFakeNumEt",tfiles1,weights); TH1D* hSelPT2A = (TH1D*)plot("HFakeNumSelEt","HFakeNumEt",tfiles2,weights); hSelPTA->SetTitle(0); hSelPTA->GetXaxis()->SetRangeUser(10,65); hSelPTA->GetYaxis()->SetRangeUser(1e-2,1); //hSelPT->SetMaximum(1.0); hSelPTA->GetXaxis()->SetTitle("E_{T} of Reco Jet (GeV)"); hSelPTA->GetYaxis()->SetTitle("Electron fake rate from jets (d#epsilon/dE_{T})"); hSelPTA->Draw("E"); hSelPTA->SetLineColor(4); hSelPT1A->SetLineColor(8); hSelPT2A->SetLineColor(2); hSelPT1A->Draw("sameE"); hSelPT2A->Draw("sameE"); TLegend* legAA = new TLegend(0.6,0.2,0.85,0.4); legAA->AddEntry(hSelPTA,"Id loose","l"); legAA->AddEntry(hSelPT1A,"Id medium","l"); legAA->AddEntry(hSelPT2A,"Id tight","l"); legAA->SetFillColor(0); legAA->SetTextSize(0.04); legAA->Draw(); gPad->Update(); TCanvas* cFakeIdNum = new TCanvas ("cFakeIdNum","Et spectrum of jets that match reco electrons"); cFakeIdNum->SetLogy(); cFakeIdNum->SetGridy(); cFakeIdNum->SetGridx(); TH1D* hSelJetPT = (TH1D*)Plot1D("HFakeNumSelEt",tfiles,weights); TH1D* hSelJetPT1 = (TH1D*)Plot1D("HFakeNumSelEt",tfiles1,weights); TH1D* hSelJetPT2 = (TH1D*)Plot1D("HFakeNumSelEt",tfiles2,weights); TH1D* hRecoJetPT = (TH1D*)Plot1D("HFakeNumEt",tfiles,weights); hSelJetPT->SetTitle(0); hRecoJetPT->SetTitle(0); hSelJetPT->GetXaxis()->SetRangeUser(10,65); //hSelJetPT->GetYaxis()->SetRangeUser(1e-6,1); hSelJetPT->SetMaximum(1e5); hSelJetPT->SetMinimum(1.0001); hSelJetPT->GetXaxis()->SetTitle("E_{T} of Reco Jet that fakes an electron(GeV)"); hSelJetPT->GetYaxis()->SetTitle("Arbitrary Scale"); hSelJetPT->Draw("E"); hSelJetPT->SetLineColor(4); hSelJetPT1->SetLineColor(8); hSelJetPT2->SetLineColor(2); hRecoJetPT->Draw("sameE"); hSelJetPT1->Draw("sameE"); hSelJetPT2->Draw("sameE"); TLegend* legA1 = new TLegend(0.6,0.2,0.85,0.4); legA1->AddEntry(hRecoJetPT,"Reconstruction","l"); legA1->AddEntry(hSelJetPT,"Id loose","l"); legA1->AddEntry(hSelJetPT1,"Id medium","l"); legA1->AddEntry(hSelJetPT2,"Id tight","l"); legA1->SetFillColor(0); legA1->SetTextSize(0.04); legA1->Draw(); gPad->Update(); TCanvas* cFakeIdDen = new TCanvas ("cFakeIdDen","Et spectrum of jets"); cFakeIdDen->SetLogy(); cFakeIdDen->SetGridy(); cFakeIdDen->SetGridx(); TH1D* hJetPT = (TH1D*)Plot1D("HFakeDenEt",tfiles,weights); //hJetPT->Scale(1.0/hJetPT->Integral()); hJetPT->SetTitle(0); hJetPT->GetXaxis()->SetRangeUser(10,65); //hJetPT->GetYaxis()->SetRangeUser(1e-6,1); hJetPT->SetMaximum(1e5); hJetPT->SetMinimum(1.0001); hJetPT->SetLineColor(1); hJetPT->GetXaxis()->SetTitle("E_{T} of Reco Jet (GeV)"); hJetPT->GetYaxis()->SetTitle("Arbitrary Scale"); hJetPT->Draw("E"); TCanvas* cFakeIdDivEta = new TCanvas ("cFakeIdDivEta","Electron Id Fake Rate vs Jet Eta"); cFakeIdDivEta->SetLogy(); cFakeIdDivEta->SetGridy(); cFakeIdDivEta->SetGridx(); TH1D* hSelEta = (TH1D*)plot("HFakeNumSelEta","HFakeDenEta",tfiles,weights); TH1D* hSelEta1 = (TH1D*)plot("HFakeNumSelEta","HFakeDenEta",tfiles1,weights); TH1D* hSelEta2 = (TH1D*)plot("HFakeNumSelEta","HFakeDenEta",tfiles2,weights); TH1D* hRecoEta = (TH1D*)plot("HFakeNumEta","HFakeDenEta",tfiles,weights); hSelEta->SetTitle(0); hRecoEta->SetTitle(0); hSelEta->GetXaxis()->SetRangeUser(10,65); hSelEta->GetYaxis()->SetRangeUser(1e-4,1); //hSelEta->SetMaximum(1.0); hSelEta->GetXaxis()->SetTitle("#eta of Reco Jet (GeV)"); hSelEta->GetYaxis()->SetTitle("Electron fake rate from jets (d#epsilon/d#eta)"); hSelEta->Draw("E"); hSelEta->SetLineColor(4); hSelEta1->SetLineColor(8); hSelEta2->SetLineColor(2); hRecoEta->Draw("sameE"); hSelEta1->Draw("sameE"); hSelEta2->Draw("sameE"); TLegend* legB = new TLegend(0.6,0.2,0.85,0.4); legB->AddEntry(hRecoEta,"Reconstruction","l"); legB->AddEntry(hSelEta,"Id loose","l"); legB->AddEntry(hSelEta1,"Id medium","l"); legB->AddEntry(hSelEta2,"Id tight","l"); legB->SetFillColor(0); legB->SetTextSize(0.04); legB->Draw(); gPad->Update(); TCanvas* cFakeIdDivEta1 = new TCanvas ("cFakeIdDivEta1","Electron Id Fake Rate vs Jet Eta (Rel)"); cFakeIdDivEta1->SetLogy(); cFakeIdDivEta1->SetGridy(); cFakeIdDivEta1->SetGridx(); TH1D* hSelEtaB = (TH1D*)plot("HFakeNumSelEta","HFakeNumEta",tfiles,weights); TH1D* hSelEta1B = (TH1D*)plot("HFakeNumSelEta","HFakeNumEta",tfiles1,weights); TH1D* hSelEta2B = (TH1D*)plot("HFakeNumSelEta","HFakeNumEta",tfiles2,weights); hSelEtaB->SetTitle(0); hSelEtaB->GetXaxis()->SetRangeUser(10,65); hSelEtaB->GetYaxis()->SetRangeUser(1e-4,1); //hSelEta->SetMaximum(1.0); hSelEtaB->GetXaxis()->SetTitle("#eta of Reco Jet (GeV)"); hSelEtaB->GetYaxis()->SetTitle("Electron fake rate from jets (d#epsilon/d#eta)"); hSelEtaB->Draw("E"); hSelEtaB->SetLineColor(4); hSelEta1B->SetLineColor(8); hSelEta2B->SetLineColor(2); hSelEta1B->Draw("sameE"); hSelEta2B->Draw("sameE"); TLegend* legBB = new TLegend(0.6,0.2,0.85,0.4); legBB->AddEntry(hSelEtaB,"Id loose","l"); legBB->AddEntry(hSelEta1B,"Id medium","l"); legBB->AddEntry(hSelEta2B,"Id tight","l"); legBB->SetFillColor(0); legBB->SetTextSize(0.04); legBB->Draw(); gPad->Update(); TCanvas* cFakeIdNumEta = new TCanvas ("cFakeIdNumEta","#eta spectrum of jets that match reco electrons"); cFakeIdNumEta->SetLogy(); cFakeIdNumEta->SetGridy(); cFakeIdNumEta->SetGridx(); TH1D* hSelJetEta = (TH1D*)Plot1D("HFakeNumSelEta",tfiles,weights); TH1D* hSelJetEta1 = (TH1D*)Plot1D("HFakeNumSelEta",tfiles1,weights); TH1D* hSelJetEta2 = (TH1D*)Plot1D("HFakeNumSelEta",tfiles2,weights); TH1D* hRecoJetEta = (TH1D*)Plot1D("HFakeNumEta",tfiles,weights); hSelJetEta->SetTitle(0); hRecoJetEta->SetTitle(0); hSelJetEta->GetXaxis()->SetRangeUser(10,65); //hSelJetEta->GetYaxis()->SetRangeUser(1e-6,1); hSelJetEta->SetMaximum(1e4); hSelJetEta->SetMinimum(1.0001); hSelJetEta->GetXaxis()->SetTitle("#eta of Reco Jet that fakes an electron(GeV)"); hSelJetEta->GetYaxis()->SetTitle("Arbitrary Scale"); hSelJetEta->Draw("E"); hSelJetEta->SetLineColor(4); hSelJetEta1->SetLineColor(8); hSelJetEta2->SetLineColor(2); hRecoJetEta->Draw("sameE"); hSelJetEta1->Draw("sameE"); hSelJetEta2->Draw("sameE"); TLegend* legB1 = new TLegend(0.6,0.2,0.85,0.4); legB1->AddEntry(hRecoJetPT,"Reconstruction","l"); legB1->AddEntry(hSelJetPT,"Id loose","l"); legB1->AddEntry(hSelJetPT1,"Id medium","l"); legB1->AddEntry(hSelJetPT2,"Id tight","l"); legB1->SetFillColor(0); legB1->SetTextSize(0.04); legB1->Draw(); gPad->Update(); TCanvas* cFakeIdDenEta = new TCanvas ("cFakeIdDenEta","#eta spectrum of jets"); cFakeIdDenEta->SetLogy(); cFakeIdDenEta->SetGridy(); cFakeIdDenEta->SetGridx(); TH1D* hJetEta = (TH1D*)Plot1D("HFakeDenEta",tfiles,weights); hJetEta->SetTitle(0); hJetEta->GetXaxis()->SetRangeUser(10,65); //hJetEta->GetYaxis()->SetRangeUser(1e-6,1); hJetEta->SetMaximum(1e4); hJetEta->SetMinimum(1.0001); hJetEta->SetLineColor(1); hJetEta->GetXaxis()->SetTitle("#eta of Reco Jet (GeV)"); hJetEta->GetYaxis()->SetTitle("Arbitrary Scale"); hJetEta->Draw("E"); TCanvas* cEtJetvsEtElec = new TCanvas ("cEtJetvsEtElec","E_{T} of Electron vs E_{T} of Jet"); cEtJetvsEtElec->SetLogz(); TH2D* hJetvsElec = (TH2D*)Plot2D("HEtJetvsEtElectron",tfiles,weights); hJetvsElec->SetTitle(0); hJetvsElec->GetXaxis()->SetTitle("E_{T} of Reco Jet (GeV)"); hJetvsElec->GetYaxis()->SetTitle("E_{T} of Reco Electron (GeV)"); hJetvsElec->Draw("COLZ"); TCanvas* cDRJetElec = new TCanvas ("cDRJetElec","minimum #DeltaR between electron and jets "); cDRJetElec->SetLogy(); cDRJetElec->SetGridy(); cDRJetElec->SetGridx(); TH1D* hDRJetElec = (TH1D*)Plot1D("HdRminElecjet",tfiles,weights); hDRJetElec->SetTitle(0); hDRJetElec->SetLineColor(1); hDRJetElec->GetXaxis()->SetTitle("Minimum #DeltaR between electrons and jets"); hDRJetElec->GetYaxis()->SetTitle("Arbitrary Scale"); hDRJetElec->Draw(); }
void run_DataGammaJetsZllToZnunu(){ // defs --------------------------------------------------------- gSystem->CompileMacro("../MT2Code/src/MT2Shapes.cc", "k"); // logStream fLogStream = new std::ostringstream(); // create dir if(!fOutDir.EndsWith("/")) fOutDir += "/"; char cmd[500]; sprintf(cmd,"mkdir -p %s", fOutDir.Data()); system(cmd); DefineCutStreams(fHTmin, fHTmax, fMT2min, fMT2max); TString filename=fOutDir+"/"+fRootFile; fOutFile = new TFile(filename.Data(), "RECREATE"); fDir = (TDirectory*) fOutFile; // fix output dir // if(fHTmax <10000) fOutDir= TString::Format("%s_%d_HT_%d", fOutDir.Data(), abs(fHTmin), abs(fHTmax)); // else fOutDir= TString::Format("%s_%d_HT_%s", fOutDir.Data(), abs(fHTmin), "Inf"); // if(fMT2max<10000) fOutDir= TString::Format("%s_%d_MT2_%d", fOutDir.Data(), abs(fMT2min), abs(fMT2max)); // else fOutDir= TString::Format("%s_%d_MT2_%s", fOutDir.Data(), abs(fMT2min), "Inf"); // log MT2 and HT cuts *fLogStream << "------------------------------------------------------------------------------------------------" << endl; *fLogStream << "+++ new Znunu with Gamma+jets prediction +++" << endl; *fLogStream << "+++ outputdir: " << fOutDir << "+++" << endl; *fLogStream << "------------------------------------------------------------------------------------------------" << endl; // new prediction ------------------------------------------------------ Prediction* prediction = new Prediction(); prediction->fVerbose=fVerbose; prediction->fSave =fSaveResults; // Photon Pt if(fDoPhotonPtShape){ const int gNMT2bins = 11; double gMT2bins[gNMT2bins+1] = {150, 160, 170, 180, 190, 200, 225, 250, 300, 400, 550, 800}; prediction->ChPhotonPt = new Channel("PhotonPt", "photon[0].lv.Pt()", cutStream_PhotonPt.str().c_str(), fTriggerStream.str().c_str(),fSamplesPhotonPt); prediction->ChPhotonPt->fVerbose =prediction->fVerbose; // prediction->ChPhotonPt->GetShapes("PhotonPt", "#gamma Pt", 2, 300, 800); prediction->ChPhotonPt->GetShapes("PhotonPt", "#gamma Pt", 100, 150, 800); // prediction->ChPhotonPt->GetShapes("PhotonPt", "#gamma Pt", gNMT2bins, gMT2bins); } // Zll Pt if(fDoZllPtShape){ const int gNMT2bins = 11; double gMT2bins[gNMT2bins+1] = {150, 160, 170, 180, 190, 200, 225, 250, 300, 400, 550, 800}; prediction->ChZllPt = new Channel("ZllPt", "RecoOSDiLeptPt(20,2.4,71,111)", cutStreamZll.str().c_str(), fTriggerStream.str().c_str(),fSamplesZllPt); prediction->ChZllPt->fVerbose =prediction->fVerbose; // prediction->ChZllPt->GetShapes("ZllPt", "Zll Pt", 2, 300, 800); prediction->ChZllPt->GetShapes("ZllPt", "Zll Pt", 100, 150, 800); // prediction->ChZllPt->GetShapes("ZllPt", "Zll Pt", gNMT2bins, gMT2bins); } // compute Zll/gamma pt ratio if(fDoPhotonPtShape && fDoZllPtShape){ TH1D* hPhotonToZllPtRatio = prediction->GetRatio(fDoDataZllToPhotonRatio? prediction->ChZllPt->hData : prediction->ChZllPt->hZJetsToLL, fDoDataZllToPhotonRatio? prediction->ChPhotonPt->hData : prediction->ChPhotonPt->hPhotons, 4); DrawHisto(hPhotonToZllPtRatio,hPhotonToZllPtRatio->GetName(),"EX0"); TString rationame=hPhotonToZllPtRatio->GetName(); rationame +="_fittedRatio"; TF1 *f_lin = new TF1(rationame,"pol0(0)", fZllToGammaFitMin , fZllToGammaFitMax); f_lin->SetLineColor(8); if(fDoFits){ hPhotonToZllPtRatio->Fit(rationame,"0L","", fZllToGammaFitMin, fZllToGammaFitMax); // set al weights to 1 fZllToPhotonRatio = f_lin->GetParameter(0); } else{ fZllToPhotonRatio = prediction->GetLimitedRatio(fDoDataZllToPhotonRatio? prediction->ChZllPt->hData: prediction->ChZllPt->hZJetsToLL, fDoDataZllToPhotonRatio? prediction->ChPhotonPt->hData : prediction->ChPhotonPt->hPhotons, fZllToGammaFitMin, fZllToGammaFitMax, false, fZllToPhotonRatioRelErr); f_lin->SetParameter(0,fZllToPhotonRatio); } const int nBins= 3; const double Bins[nBins+1] = {150, fZllToGammaFitMin>150?fZllToGammaFitMin:150.0001, fZllToGammaFitMax<800? fZllToGammaFitMax:799.99, 800}; TH1D* hErrorbar = new TH1D(rationame.Data(), "", nBins, Bins); hErrorbar->SetBinContent(2,fZllToPhotonRatio); hErrorbar->SetBinError(2,fZllToPhotonRatioRelErr*fZllToPhotonRatio); hErrorbar->SetBinContent(1,-10); hErrorbar->SetBinError( 1,0); hErrorbar->SetFillColor(5); hErrorbar->SetFillStyle(3001); hErrorbar->Draw("e2same"); f_lin->Draw("same"); hPhotonToZllPtRatio->Draw("EX0same"); } // GenLevel Zll Pt, no acceptance cuts if(fDoGenZllShape){ prediction->ChGenZllPt = new Channel("GenZllPt", "GenDiLeptPt(0,10,0,1000,true)", cutStreamGenZll.str().c_str(), fTriggerStream.str().c_str(),fSamplesZllPtMConly); prediction->ChGenZllPt->fVerbose =prediction->fVerbose; prediction->ChGenZllPt->GetShapes("GenZllPt", "GenZll Pt", 8, 0, 800); } // GenLevel Zll Pt, within acceptance if(fDoGenAccZllShape){ prediction->ChGenZllPtAcc = new Channel("GenZllPtAcc", "GenDiLeptPt(20,2.4,71,111,true)", cutStreamGenZllAcc.str().c_str(), fTriggerStream.str().c_str(),fSamplesZllPtMConly); prediction->ChGenZllPtAcc->fVerbose =prediction->fVerbose; prediction->ChGenZllPtAcc->GetShapes("GenZllPtAcc", "GenZll Pt", 8, 0, 800); } // Get Acceptance Efficiency if(fDoGenZllShape && fDoGenAccZllShape){ Bool_t binomial =true; TH1D* hZllAccEff = prediction->GetRatio(prediction->ChGenZllPtAcc->hZJetsToLL, prediction->ChGenZllPt->hZJetsToLL, 1, binomial); DrawHisto(hZllAccEff,hZllAccEff->GetName(),"EX"); // TString rationame=hZllAccEff->GetName(); // rationame +="_fittedRatio"; // TF1 *f_lin = new TF1(rationame,"pol0(0)", fZllAccFitMin , fZllAccFitMax); f_lin->SetLineColor(8); // if(fDoFits){ // hZllAccEff->Fit(rationame,"0L","", fZllAccFitMin, fZllAccFitMax); // set al weights to 1 // fZllAccEff= f_lin->GetParameter(0); // } else{ // fZllAccEff= prediction->GetLimitedRatio(prediction->ChGenZllPtAcc->hZJetsToLL,prediction->ChGenZllPt->hZJetsToLL, // fZllAccFitMin, fZllAccFitMax, true, fZllAccEffRelErr); // f_lin->SetParameter(0,fZllAccEff); // } // const int nBins= 3; // const double Bins[nBins+1] = {150, fZllAccFitMin>150?fZllAccFitMin:150.0001, fZllAccFitMax<800? fZllAccFitMax:799.99, 800}; // TH1D* hErrorbar = new TH1D(rationame.Data(), "", nBins,Bins); // hErrorbar->SetBinContent(2,fZllAccEff); // hErrorbar->SetBinError(2,fZllAccEffRelErr*fZllAccEff); // hErrorbar->SetBinContent(1,-1); // hErrorbar->SetBinError(1,0); // hErrorbar->SetFillColor(5); // hErrorbar->SetFillStyle(3001); // hErrorbar->Draw("e2same"); // f_lin->Draw("same"); // hZllAccEff->Draw("EX0same"); } // GenLevel Zll Pt, within acceptance, OS dilepton recoed if(fDoGenAccZllRecoShape){ prediction->ChGenZllPtAccRecoed = new Channel("GenZllPtAccRecoed", "GenDiLeptPt(20,2.4,71,111,true)", cutStreamGenZllAcc_recoed.str().c_str(), fTriggerStream.str().c_str(),fSamplesZllPtMConly); prediction->ChGenZllPtAccRecoed->fVerbose =prediction->fVerbose; prediction->ChGenZllPtAccRecoed->GetShapes("GenZllPtAccRecoed", "GenZll Pt", 100, 150, 800); } if(fDoGenAccZllShape && fDoGenAccZllRecoShape){ Bool_t binomial =true; TH1D* hZllRecoEff = prediction->GetRatio(prediction->ChGenZllPtAccRecoed->hZJetsToLL, prediction->ChGenZllPtAcc->hZJetsToLL, 4, binomial); DrawHisto(hZllRecoEff,hZllRecoEff->GetName(),"EX"); TString rationame=hZllRecoEff->GetName(); rationame +="_fittedRatio"; TF1 *f_lin = new TF1(rationame,"pol0(0)", fZllRecoEffFitMin , fZllRecoEffFitMax); f_lin->SetLineColor(8); if(fDoFits){ hZllRecoEff->Fit(rationame,"0L","", fZllRecoEffFitMin, fZllRecoEffFitMax); // set al weights to 1 fZllRecoEff= f_lin->GetParameter(0); } else{ fZllRecoEff= prediction->GetLimitedRatio(prediction->ChGenZllPtAccRecoed->hZJetsToLL,prediction->ChGenZllPtAcc->hZJetsToLL, fZllRecoEffFitMin, fZllRecoEffFitMax, true, fZllRecoEffRelErr); f_lin->SetParameter(0,fZllRecoEff); } const int nBins= 3; const double Bins[nBins+1] = {150, fZllRecoEffFitMin>150?fZllRecoEffFitMin:150.001, fZllRecoEffFitMax<800? fZllRecoEffFitMax:799.99, 800}; TH1D* hErrorbar = new TH1D(rationame.Data(), "", nBins,Bins); hErrorbar->SetBinContent(2,fZllRecoEff); hErrorbar->SetBinError(2,fZllRecoEffRelErr*fZllRecoEff); hErrorbar->SetBinContent(1,-1); hErrorbar->SetBinError(1,0); hErrorbar->SetFillColor(5); hErrorbar->SetFillStyle(3001); hErrorbar->Draw("e2same"); f_lin->Draw("same"); hZllRecoEff->Draw("EX0same"); } // Photons Hadronic Search MT2 if(fDoPhotonMT2Shape){ prediction->ChPhotonsMT2 = new Channel("PhotonsMT2", "photon[0].lv.Pt()", cutStreamPhotonMT2.str().c_str(), fTriggerStream.str().c_str(),fSamplesPhotonPt); prediction->ChPhotonsMT2->fVerbose =prediction->fVerbose; prediction->ChPhotonsMT2->GetShapes("PhotonsMT2", "MET", 40, 0, 800); } // Znunu Hadronic Search MT2 if(fDoZnunuMT2Shape){ prediction->ChZnunuMT2 = new Channel("ZnunuMT2", "misc.MET", cutStreamZnunuMT2.str().c_str(), fTriggerStream.str().c_str(),fSamplesZnunu); prediction->ChZnunuMT2->fVerbose =prediction->fVerbose; prediction->ChZnunuMT2->GetShapes("ZnunuMT2", "MET", 40, 0, 800); } if(fDoZnunuMT2Shape && fDoPhotonMT2Shape){ TH1D* ZnunuToPhotonMT2Ratio = prediction->GetRatio(prediction->ChZnunuMT2->hZJetsToNuNu, prediction->ChPhotonsMT2->hPhotons, 1); DrawHisto(ZnunuToPhotonMT2Ratio,ZnunuToPhotonMT2Ratio->GetName(),"EX0"); } // Do Pt spectra comparison plot if(fDoPtSpectraComparison && fDoPhotonPtShape && fDoZllPtShape){ *fLogStream<< "************************* produce pr spectra plot ****************************** " << endl; TH1D* hZllMC_cp = prediction->GetScaledHisto(prediction->ChZllPt->hZJetsToLL, fDoPtSpectraComparisonScaling?(prediction->ChZllPt->hData->Integral())/(prediction->ChZllPt->hZJetsToLL->Integral()) :1, 0, 1); TH1D* hZllData_cp = prediction->GetScaledHisto(prediction->ChZllPt->hData, 1, 0, 1) ; TH1D* hPhotonMC_cp = prediction->GetScaledHisto(prediction->ChPhotonPt->hPhotons,fDoPtSpectraComparisonScaling?(prediction->ChPhotonPt->hData->Integral())/(prediction->ChPhotonPt->hPhotons->Integral()):1, 0, 1); TH1D* hPhotonData_cp = prediction->GetScaledHisto(prediction->ChPhotonPt->hData, 1, 0, 1); if(fDoPtSpectraComparisonAccCorr){ TFile *f = new TFile("../RootMacros/ZllAcceptance.root", "OPEN"); TH1D* hZllAcc = (TH1D*) f->Get("ZJetsToLL_GenZllPtAcc_ZJetsToLL_GenZllPt_Ratio"); if (hZllAcc==0) {cout << "WARNING: could not get histo ZJetsToLL_GenZllPtAcc_ZJetsToLL_GenZllPt_Ratio" << endl; exit(1);} for(int i=1; i<=hZllMC_cp->GetNbinsX(); ++i){ if(hZllAcc->GetBinLowEdge(i) != hZllMC_cp->GetBinLowEdge(i)) {cout << "Zll Acc Correction: binnin does not match!!" << endl; exit(1);} if(hZllMC_cp ->GetBinContent(i)<=0) continue; double acc_eff = hZllAcc->GetBinContent(i); double orig_mc = hZllMC_cp ->GetBinContent(i); double orig_data = hZllData_cp ->GetBinContent(i); cout << "bin i " << i << " acc eff " << acc_eff << " orig_mc " << orig_mc << " become " << orig_mc/acc_eff << " orig_data " << orig_data << " becomes " << orig_data/acc_eff << endl; hZllMC_cp ->SetBinContent(i, orig_mc /acc_eff); hZllData_cp ->SetBinContent(i, orig_data/acc_eff); } delete f; } hZllMC_cp->SetMarkerStyle(22); hZllMC_cp->SetLineColor(kOrange); hZllMC_cp->SetMarkerColor(kOrange); hZllMC_cp->SetMarkerSize(1.2); hZllData_cp->SetMarkerStyle(26); hZllData_cp->SetMarkerColor(kBlack); hZllData_cp->SetLineColor(kBlack); hPhotonMC_cp->SetLineColor(kMagenta+2); hPhotonMC_cp->SetMarkerColor(kMagenta+2); hPhotonMC_cp->SetMarkerStyle(20); hPhotonMC_cp->SetMarkerSize(1.2); hPhotonData_cp->SetMarkerStyle(4); hPhotonData_cp->SetMarkerColor(kBlack); hPhotonData_cp->SetLineColor(kBlack); TCanvas *col = new TCanvas("ZllToGammaPtSpectra", "", 0, 0, 500, 500); col->SetFillStyle(0); col->SetFrameFillStyle(0); // col->cd(); gPad->SetFillStyle(0); gStyle->SetPalette(1); gPad->SetRightMargin(0.15); TLegend* leg2 = new TLegend(0.2, 0.6, 0.5, 0.9); leg2->AddEntry(hPhotonMC_cp,"Gamma+Jets MC","p" ); leg2->AddEntry(hPhotonData_cp,"Photon Data","p" ); leg2->AddEntry(hZllMC_cp ,"Zll MC","p" ); leg2->AddEntry(hZllData_cp,"Zll Data","p" ); leg2 -> SetFillColor(0); leg2 -> SetBorderSize(0); // hPhotonMC_cp->SetXTitle("V boson p_{T} (GeV)"); hPhotonMC_cp->SetYTitle("Events / 7 GeV"); hPhotonMC_cp->Draw("EX"); hPhotonData_cp->Draw("EXsame"); hZllMC_cp->Draw("EXsame"); hZllData_cp->Draw("EXsame"); leg2->Draw(); TCanvas *c3 = new TCanvas("ZllToGammaPtSpectraRatio", "", 500, 500); TH1D* h_ratio = (TH1D*) hZllMC_cp ->Clone("h_ratio"); TH1D* h_ratioData = (TH1D*) hZllData_cp ->Clone("h_ratioData"); TH1D* hPhotonMC_cp2 = (TH1D*) hPhotonMC_cp ->Clone("hPhotonMC_cp2"); TH1D* hPhotonData_cp2 = (TH1D*) hPhotonData_cp ->Clone("hPhotonData_cp2"); h_ratio->Rebin(1); h_ratioData->Rebin(1); h_ratio->SetYTitle("#frac{Z(ll)}{#gamma}"); h_ratio->SetXTitle("boson p_{T} (GeV)"); h_ratio ->Divide(hPhotonMC_cp2->Rebin(1)); h_ratioData->Divide(hPhotonData_cp2->Rebin(1)); h_ratio ->SetMarkerStyle(20); h_ratio ->SetMarkerSize(1.2); h_ratio ->SetLineColor(kMagenta+2); h_ratio ->SetMarkerColor(kMagenta+2); h_ratioData->SetMarkerStyle(26); h_ratioData->SetMarkerColor(kBlack); h_ratio ->Draw("EX0"); h_ratioData->Draw("EX0same"); TLegend* leg3 = new TLegend(0.2, 0.6, 0.5, 0.9); leg3->AddEntry(h_ratioData,"Zll/photon Data","p" ); leg3->AddEntry(h_ratio ,"Zll/photon MC","p" ); leg3 -> SetFillColor(0); leg3 -> SetBorderSize(0); leg3 ->Draw(); } if(fDoMT2SpectraCompaison && fDoZnunuMT2Shape && fDoPhotonMT2Shape){ *fLogStream<< "************************* MT2 spectra comparison *************** " << endl; TH1D* hZNunuMT2 = prediction->GetScaledHisto(prediction->ChZnunuMT2 ->hZJetsToNuNu, fDoMT2SpectraCompaisonScaling?(prediction->ChPhotonsMT2 ->hData->Integral())/(prediction->ChPhotonsMT2 ->hPhotons->Integral()):1, 0, 1); TH1D* hPhotonMT2 = prediction->GetScaledHisto(prediction->ChPhotonsMT2 ->hPhotons, fDoMT2SpectraCompaisonScaling?(prediction->ChPhotonsMT2 ->hData->Integral())/(prediction->ChPhotonsMT2 ->hPhotons->Integral()):1, 0, 1); TH1D* hPhotonDataMT2 = prediction->GetScaledHisto(prediction->ChPhotonsMT2 ->hData, 1, 0, 1); hZNunuMT2->SetFillStyle(0); hZNunuMT2->SetLineWidth(3); TCanvas *col = new TCanvas("ZnunuToGammaPtSpectra", "", 0, 0, 500, 500); col->SetFillStyle(0); col->SetFrameFillStyle(0); // col->cd(); gPad->SetFillStyle(0); gStyle->SetPalette(1); gPad->SetRightMargin(0.15); gPad->SetLogy(1); TLegend* leg2 = new TLegend(0.2, 0.6, 0.5, 0.9); leg2->AddEntry(hPhotonMT2,"#gamma+jets MC","f" ); leg2->AddEntry(hZNunuMT2,"Z(#nu#nu)+jets MC","l" ); leg2->AddEntry(hPhotonDataMT2,"data","p" ); leg2 -> SetFillColor(0); leg2 -> SetBorderSize(0); // hPhotonMT2->SetXTitle("min #Delta #phi(jets,MET)"); hPhotonMT2->SetYTitle("Events"); hPhotonMT2->Draw("hist"); hZNunuMT2->Draw("histsame"); hPhotonDataMT2->Draw("EXsame"); leg2->Draw(); // gPad->RedrawAxis(); // cout integral above 250 in MT2 and ratio // double sumPhotons=0; // double sumZnunu =0; // for(int i=1; i<=hPhotonMT2->GetNbinsX(); ++i){ // if(hPhotonMT2->GetBinLowEdge(i)>=250){ // sumPhotons+=hPhotonMT2->GetBinContent(i); // sumZnunu +=hZNunuMT2 ->GetBinContent(i); // } // } // *fLogStream<< ">>> hPhotonMT2: integral above 250: " << sumPhotons << endl; // *fLogStream<< ">>> hZNunuMT2 : integral above 250: " << sumZnunu << endl; // *fLogStream<< ">>> -> Ratio : " << sumZnunu/sumPhotons << endl; } if(fDoZnunuGammaGenPtSpectraComparison){ *fLogStream<< "*************************ZnunuGammaGenPtSpectraComparison**********" << endl; // gen photons prediction->ChGenPhotonPt = new Channel("GenPhotonPt", "GenPhoton[0].Pt()", cutStreamGenPhoton.str().c_str(), fTriggerStream.str().c_str(),fSamplesPhotonPtMConly); prediction->ChGenPhotonPt->fVerbose =prediction->fVerbose; prediction->ChGenPhotonPt->GetShapes("GenPhotonPt", "Gen-level #gamma Pt", 50, 150, 800); // Gen Znunu prediction->ChGenZnunuPt = new Channel("GenZnunuPt", "GenZ[0].Pt()", cutStreamGenZnunu.str().c_str(), fTriggerStream.str().c_str(),fSamplesZnunu); prediction->ChGenZnunuPt->fVerbose =prediction->fVerbose; prediction->ChGenZnunuPt->GetShapes("GenZnunuPt", "Gen-level Z(#nu#nu) Pt", 50, 150, 800); prediction->DrawHistos(prediction->ChGenPhotonPt->hPhotons, prediction->ChGenZnunuPt->hZJetsToNuNu, "EX0" , "EX0same", kViolet+3 , kBlack, 20 ,4, "#gamma Pt" ,"Z(#nu#nu)"); TH1D* hGenPhotonToZnunuRatio = prediction->GetRatio(prediction->ChGenZnunuPt->hZJetsToNuNu, prediction->ChGenPhotonPt->hPhotons, 1, false); hGenPhotonToZnunuRatio->SetMarkerColor(kBlack); hGenPhotonToZnunuRatio->SetLineColor(kBlack); hGenPhotonToZnunuRatio->SetMarkerStyle(4); DrawHisto(hGenPhotonToZnunuRatio, "GenPhotonToZnunuRatio","EX0", prediction->ChGenPhotonPt); } if(fDoPhotonRecoEff){ prediction->ChGenPhotonPtForRecoEff = new Channel("GenPhotonPtForRecoEff", "GenPhoton[0].Pt()", cutStream_GenPhotonforRecoEff.str().c_str(), fTriggerStream.str().c_str(),fSamplesPhotonPtMConly); prediction->ChGenPhotonPtForRecoEff->fVerbose =prediction->fVerbose; prediction->ChGenPhotonPtForRecoEff->GetShapes("GenPhotonPtForRecoEff", "Gen-level #gamma Pt", 50, 150, 800); prediction->ChPhotonPtForRecoEff = new Channel("PhotonPtForRecoEff", "GenPhoton[0].Pt()", cutStream_PhotonPtforRecoEff.str().c_str(), fTriggerStream.str().c_str(),fSamplesPhotonPtMConly); prediction->ChPhotonPtForRecoEff->fVerbose =prediction->fVerbose; prediction->ChPhotonPtForRecoEff->GetShapes("PhotonPtForRecoEff", "Gen-level #gamma Pt", 50, 150, 800); prediction->DrawHistos(prediction->ChGenPhotonPtForRecoEff->hPhotons, prediction->ChPhotonPtForRecoEff->hPhotons, "EX0" , "EX0same", kViolet+3 , kBlack, 20 ,4, "#all" ,"recoed"); TH1D* hPhotonRecoEff = prediction->GetRatio(prediction->ChPhotonPtForRecoEff->hPhotons, prediction->ChGenPhotonPtForRecoEff->hPhotons, 1, false); hPhotonRecoEff->SetMarkerColor(kBlack); hPhotonRecoEff->SetLineColor(kBlack); hPhotonRecoEff->SetMarkerStyle(4); DrawHisto(hPhotonRecoEff, "PhotonRecoEff","EX0", prediction->ChPhotonPtForRecoEff); } // Prediction if(fDoPrediction){ *fLogStream<< "************************* Prediction ****************************** " << endl; TH1D* MCZnunu = prediction->GetScaledHisto(prediction->ChZnunuMT2->hZJetsToNuNu,fLumiCorr,0); // scale to lumi 4400 double MCZnunuEst = MCZnunu->GetBinContent(1); double MCZnunuEstErr = MCZnunu->GetBinError(1); delete MCZnunu; if(fDoData){ double nGamma = prediction->ChPhotonsMT2->hData->Integral(); double nGammaErr = sqrt(nGamma); *fLogStream << "********** Data Prediction ***************************************************** " << endl; MakePrediction(nGamma, nGammaErr, fZllToPhotonRatio, fZllToPhotonRatioRelErr, fZllAccEff, fZllAccEffRelErr, fZllRecoEff, fZllRecoEffRelErr, MCZnunuEst, MCZnunuEstErr); } TH1D* hDummy = prediction->GetScaledHisto(prediction->ChPhotonsMT2->hPhotons, 1, 0); float nGammaMC =hDummy->GetBinContent(1); float nGammaMCErr=hDummy->GetBinError(1); *fLogStream << "********** MC Prediction ***************************************************** " << endl; MakePrediction(nGammaMC, nGammaMCErr, fZllToPhotonRatio, fZllToPhotonRatioRelErr, fZllAccEff, fZllAccEffRelErr, fZllRecoEff, fZllRecoEffRelErr, MCZnunuEst, MCZnunuEstErr); } // write ----------- if(fWriteToFile){ TString logname =fOutDir + ".log"; ofstream f_log (logname.Data(), ios::app); f_log << fLogStream->str(); } else{ cout << fLogStream->str(); } // fOutFile->Close(); }
// Compare energy spectra/coincidences under different experimental conditions void CompareRuns(){ TCanvas* c1 = new TCanvas(); TCanvas* c2 = new TCanvas(); TCanvas* c3 = new TCanvas(); double thresh = 35; double dmin = 400, dmax = 6000; //6000=24us; //add 100 us //dmin += 25000; dmax += 25000; double E0 = 5.37873, E1 = 0.157501; //calibration double emax = 6000; //HV + UCN on c1->cd(); TH1D* hP = new TH1D("hP","hP",emax/4.,0,emax); TH2D* hch = new TH2D("hch","hch",16,0,16,16,0,16); TH1D* ht = (TH1D*) gROOT->FindObject("ht"); if (ht != 0) delete ht; TH1D* ht = new TH1D("ht","ht",300,0,15000); TH2D* hPT = new TH2D("hPT","hPT",500,0,50,emax/4.,0,emax); ftf.SetPath("Files/Dec15/Fixed"); ftf.Open(27); double endtime = 4*500.; ftf.GetEvent(0); double lasttime = ftf.Fit_event.t; int lastch = ftf.Fit_event.ch; for (int i = 0; i < ftf.GetNumEvents(); i++) { ftf.GetEvent(i); double time = ftf.Fit_event.t; if (ftf.Fit_event.E > thresh && ftf.Fit_event.shaping > 180 && ftf.Fit_event.shaping < 240 && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff < dmax) { ht->Fill(diff); hPT->Fill(diff*0.004,ftf.Fit_event.E*E1 + E0); } if (diff > dmin && diff < dmax) {//4 to 24 us hP->Fill(ftf.Fit_event.E*E1 + E0); hch->Fill(ftf.Fit_event.ch,lastch); } lasttime = time; lastch = ftf.Fit_event.ch; } } ftf.Open(30); double endtime = 4*510.; ftf.GetEvent(0); lasttime = ftf.Fit_event.t; lastch = ftf.Fit_event.ch; for (int i = 0; i < ftf.GetNumEvents(); i++) { ftf.GetEvent(i); double time = ftf.Fit_event.t; if (ftf.Fit_event.E > thresh && ftf.Fit_event.shaping > 180 && ftf.Fit_event.shaping < 240 && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff < dmax){ ht->Fill(diff); hPT->Fill(diff*0.004,ftf.Fit_event.E*E1 + E0); } if (diff > dmin && diff < dmax) {//4 to 24 us hP->Fill(ftf.Fit_event.E*E1 + E0); hch->Fill(ftf.Fit_event.ch,lastch); } lasttime = time; lastch = ftf.Fit_event.ch; } } ftf.Open(33); double endtime = 2250.; ftf.GetEvent(0); lasttime = ftf.Fit_event.t; lastch = ftf.Fit_event.ch; for (int i = 0; i < ftf.GetNumEvents(); i++) { if (ftf.Fit_event.E > thresh && ftf.Fit_event.shaping > 180 && ftf.Fit_event.shaping < 240 && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff < dmax){ ht->Fill(diff); hPT->Fill(diff*0.004,ftf.Fit_event.E*E1 + E0); } if (diff > dmin && diff < dmax) {//4 to 24 us hP->Fill(ftf.Fit_event.E*E1 + E0); hch->Fill(ftf.Fit_event.ch,lastch); } lasttime = time; lastch = ftf.Fit_event.ch; } } ftf.Open(35); double endtime = 1000.; ftf.GetEvent(0); lasttime = ftf.Fit_event.t; lastch = ftf.Fit_event.ch; for (int i = 0; i < ftf.GetNumEvents(); i++) { ftf.GetEvent(i); if (ftf.Fit_event.E > thresh && ftf.Fit_event.shaping > 180 && ftf.Fit_event.shaping < 240 && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff < dmax){ ht->Fill(diff); hPT->Fill(diff*0.004,ftf.Fit_event.E*E1 + E0); } if (diff > dmin && diff < dmax) {//4 to 24 us hP->Fill(ftf.Fit_event.E*E1 + E0); hch->Fill(ftf.Fit_event.ch,lastch); } lasttime = time; lastch = ftf.Fit_event.ch; } } ftf.Open(36); double endtime = 900.; ftf.GetEvent(0); lasttime = ftf.Fit_event.t; lastch = ftf.Fit_event.ch; for (int i = 0; i < ftf.GetNumEvents(); i++) { ftf.GetEvent(i); if (ftf.Fit_event.E > thresh && ftf.Fit_event.shaping > 180 && ftf.Fit_event.shaping < 240 && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff < dmax){ ht->Fill(diff); hPT->Fill(diff*0.004,ftf.Fit_event.E*E1 + E0); } if (diff > dmin && diff < dmax) {//4 to 24 us hP->Fill(ftf.Fit_event.E*E1 + E0); hch->Fill(ftf.Fit_event.ch,lastch); } lasttime = time; lastch = ftf.Fit_event.ch; } } ftf.Open(38); double endtime = 1800.; ftf.GetEvent(0); lasttime = ftf.Fit_event.t; lastch = ftf.Fit_event.ch; for (int i = 0; i < ftf.GetNumEvents(); i++) { ftf.GetEvent(i); if (ftf.Fit_event.E > thresh && ftf.Fit_event.shaping > 180 && ftf.Fit_event.shaping < 240 && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff < dmax){ ht->Fill(diff); hPT->Fill(diff,ftf.Fit_event.E*E1 + E0); } if (diff > dmin && diff < dmax) {//4 to 24 us hP->Fill(ftf.Fit_event.E*E1 + E0); hch->Fill(ftf.Fit_event.ch,lastch); } lasttime = time; lastch = ftf.Fit_event.ch; } } gROOT->cd(); c3->cd(); hPT->Draw("COLZ"); c2->cd(); hch->Draw("COLZ"); c1->cd(); endtime = 4*(500.+510.) + 2250. + 1000. + 900. + 1800.; hP->Scale(1./endtime); hP->SetLineColor(kRed); hP->Draw(); //HV off, UCN on TH1D* hB = new TH1D("hB","hB",emax/4.,0,emax); ftf.Open(26); endtime = 4*220.; ftf.GetEvent(0); lasttime = ftf.Fit_event.t; for (int i = 0; i < ftf.GetNumEvents(); i++) { ftf.GetEvent(i); if (ftf.Fit_event.E > thresh && ftf.Fit_event.shaping > 180 && ftf.Fit_event.shaping < 240 && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff > dmin && diff < dmax) //4 to 24 us hB->Fill(ftf.Fit_event.E*E1 + E0); lasttime = time; } } ftf.Open(31); endtime = 4*230.; ftf.GetEvent(0); lasttime = ftf.Fit_event.t; for (int i = 0; i < ftf.GetNumEvents(); i++) { ftf.GetEvent(i); if (ftf.Fit_event.E > thresh && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff > dmin && diff < dmax) //4 to 24 us hB->Fill(ftf.Fit_event.E*E1 + E0); lasttime = time; } } ftf.Open(32); endtime = 4*100.; ftf.GetEvent(0); lasttime = ftf.Fit_event.t; for (int i = 0; i < ftf.GetNumEvents(); i++) { ftf.GetEvent(i); if (ftf.Fit_event.E > thresh && ftf.Fit_event.shaping > 180 && ftf.Fit_event.shaping < 240 && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff > dmin && diff < dmax) //4 to 24 us hB->Fill(ftf.Fit_event.E*E1 + E0); lasttime = time; } } ftf.Open(37); double endtime = 1300.; ftf.GetEvent(0); lasttime = ftf.Fit_event.t; lastch = ftf.Fit_event.ch; for (int i = 0; i < ftf.GetNumEvents(); i++) { ftf.GetEvent(i); if (ftf.Fit_event.E > thresh && ftf.Fit_event.shaping > 180 && ftf.Fit_event.shaping < 240 && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff > dmin && diff < dmax) //4 to 24 us hB->Fill(ftf.Fit_event.E*E1 + E0); lasttime = time; } } gROOT->cd(); endtime = 4*(220.+230.+100.)+1300.; hB->Scale(1./endtime); hB->SetLineColor(kGreen); hB->Draw("same"); //HV on, UCN off TH1D* hO = new TH1D("hO","hO",emax/4,0,emax); ftf.Open(29); endtime = 4*165.; ftf.GetEvent(0); lasttime = ftf.Fit_event.t; for (int i = 0; i < ftf.GetNumEvents(); i++) { ftf.GetEvent(i); if (ftf.Fit_event.E > thresh && ftf.Fit_event.shaping > 180 && ftf.Fit_event.shaping < 240 && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff > dmin && diff < dmax) //4 to 24 us hO->Fill(ftf.Fit_event.E*E1 + E0); lasttime = time; } } ftf.Open(34); endtime = 540.; ftf.GetEvent(0); lasttime = ftf.Fit_event.t; for (int i = 0; i < ftf.GetNumEvents(); i++) { ftf.GetEvent(i); if (ftf.Fit_event.E > thresh && ftf.Fit_event.shaping > 180 && ftf.Fit_event.shaping < 240 && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff > dmin && diff < dmax) //4 to 24 us hO->Fill(ftf.Fit_event.E*E1 + E0); lasttime = time; } } ftf.Open(39); endtime = 2500.; ftf.GetEvent(0); lasttime = ftf.Fit_event.t; for (int i = 0; i < ftf.GetNumEvents(); i++) { ftf.GetEvent(i); if (ftf.Fit_event.E > thresh && ftf.Fit_event.shaping > 180 && ftf.Fit_event.shaping < 240 && ftf.Fit_event.t*tsmp < endtime && ftf.Fit_event.ch != 2 && ftf.Fit_event.ch < 16) { double diff = time - lasttime; if (diff > dmin && diff < dmax) //4 to 24 us hO->Fill(ftf.Fit_event.E*E1 + E0); lasttime = time; } } gROOT->cd(); endtime = 4*(165.)+540+2500; hO->Scale(1./endtime); hO->SetLineColor(kBlack); hO->Draw("same"); }
void Channel::GetShapes(TString SelectionName, TString xtitle, const int nbins, const double *bins){ MT2Shapes *tA; if(fWriteToFile) tA = new MT2Shapes(fOutDir, fRootFile, fLogStream); else tA = new MT2Shapes(fOutDir, fRootFile); tA->setVerbose(fVerbose); tA->init(fSamples); tA->SetPrintSummary(true); tA->SetDraw(false); tA->SetWrite(false); // variable, cuts, njet, nlep, selection_name, HLT, xtitle nbins bins tA->GetShapes(fVariable, fCuts, -1, -10 , SelectionName, fTrigger , xtitle , nbins, bins); // retrieve shapes for(int i=0; i<tA->GetNShapes(); ++i){ TString name =tA->fh_shapes[i]->GetName(); if (name.Contains("QCD_")) {hQCD = (TH1D*) tA->fh_shapes[i]->Clone(tA->fh_shapes[i]->GetName()); hQCD->SetDirectory(fDir);} else if (name.Contains("PhotonsJets_")){hPhotons = (TH1D*) tA->fh_shapes[i]->Clone(tA->fh_shapes[i]->GetName()); hPhotons->SetDirectory(fDir);} else if (name.Contains("Data_")) {hData = (TH1D*) tA->fh_shapes[i]->Clone(tA->fh_shapes[i]->GetName()); hData->SetDirectory(fDir);} else if (name.Contains("WJets_")) {hWJets = (TH1D*) tA->fh_shapes[i]->Clone(tA->fh_shapes[i]->GetName()); hWJets->SetDirectory(fDir);} else if (name.Contains("ZJetsToLL_")) {hZJetsToLL = (TH1D*) tA->fh_shapes[i]->Clone(tA->fh_shapes[i]->GetName()); hZJetsToLL->SetDirectory(fDir);} else if (name.Contains("ZJetsToNuNu_")){hZJetsToNuNu = (TH1D*) tA->fh_shapes[i]->Clone(tA->fh_shapes[i]->GetName()); hZJetsToNuNu->SetDirectory(fDir);} else if (name.Contains("Top_")) {hTop = (TH1D*) tA->fh_shapes[i]->Clone(tA->fh_shapes[i]->GetName()); hTop->SetDirectory(fDir);} else if (name.Contains("Signal_")) {hSignal = (TH1D*) tA->fh_shapes[i]->Clone(tA->fh_shapes[i]->GetName()); hSignal->SetDirectory(fDir);} else if (name.Contains("Other_")) {hOther = (TH1D*) tA->fh_shapes[i]->Clone(tA->fh_shapes[i]->GetName()); hOther->SetDirectory(fDir);} } delete tA; fGotShapes=true; fDir->cd(); // fix colors if(hQCD!=0) {hQCD ->SetLineColor(kYellow+1); hQCD ->SetFillColor(kYellow+1); hQCD ->SetFillStyle(3001);} if(hPhotons!=0) {hPhotons->SetLineColor(kViolet-3); hPhotons->SetFillColor(kViolet-3); hPhotons->SetFillStyle(3001);} if(hOther!=0) {hOther ->SetLineColor(kCyan+2); hOther ->SetFillColor(kCyan+2); hOther ->SetFillStyle(3001);} if(hZJetsToNuNu!=0){hZJetsToNuNu->SetLineColor(kGreen+1); hZJetsToNuNu->SetFillColor(kGreen+1); hZJetsToNuNu ->SetFillStyle(3001);} if(hSignal!=0) {hSignal ->SetLineColor(kBlack); hSignal ->SetFillColor(kBlack); hSignal ->SetFillStyle(3001);} if(hZJetsToLL!=0) {hZJetsToLL->SetLineColor(kOrange); hZJetsToLL->SetFillColor(kOrange); hZJetsToLL->SetFillStyle(3001);} if(hTop!=0) {hTop ->SetLineColor(600); hTop ->SetFillColor(600); hTop->SetFillStyle(3001);} if(fSaveResults){ if(hQCD!=0) {hQCD->Write();} if(hPhotons!=0) {hPhotons->Write();} if(hOther!=0) {hOther->Write();} if(hData!=0) {hData->Write();} if(hTop!=0) {hTop->Write();} if(hZJetsToLL!=0) {hZJetsToLL->Write();} if(hZJetsToNuNu!=0) {hZJetsToNuNu->Write();} if(hSignal!=0) {hSignal->Write();} } if(fDraw){ if(hQCD!=0) DrawHisto(hQCD, hQCD->GetName(), "hist", this); if(hPhotons!=0) DrawHisto(hPhotons, hPhotons->GetName(), "hist", this); if(hOther!=0) DrawHisto(hOther, hOther->GetName(), "hist", this); if(hData!=0) DrawHisto(hData, hData->GetName(), "EXO", this); if(hTop!=0) DrawHisto(hTop, hTop ->GetName(), "hist", this); if(hZJetsToNuNu!=0)DrawHisto(hZJetsToNuNu, hZJetsToNuNu->GetName(), "hist", this); if(hSignal!=0) DrawHisto(hSignal, hSignal->GetName(), "hist", this); if(hZJetsToLL!=0) DrawHisto(hZJetsToLL, hZJetsToLL->GetName(), "hist", this); } }
void PtSpectraCombination_StagedNormalization_EtaCM_M03_M08_NoOLDAlignmentRuns_CombpPbPbp() { gROOT->Reset(); gROOT->ProcessLine(".x rootlogonChristof.C"); gROOT->ForceStyle(); gStyle->SetPalette(1); gStyle->SetTitleYOffset(1.27); gStyle->SetOptFit(0000); // gStyle->SetPadRightMargin(0.16); bool doSave = true; TFile *f_minbias_pPb = new TFile("CombineSpectra_minbias_EtaCM_M03_M08_NoOLDAlignmentRuns.root"); TFile *f_FullTrack_12_pPb = new TFile("CombineSpectra_FullTrackTrigger_Track12_EtaCM_M03_M08_NoOLDAlignmentRuns.root"); TFile *f_FullTrack_20_pPb = new TFile("CombineSpectra_FullTrackTrigger_Track20_EtaCM_M03_M08_NoOLDAlignmentRuns.root"); TFile *f_FullTrack_30_pPb = new TFile("CombineSpectra_FullTrackTrigger_Track30_EtaCM_M03_M08_NoOLDAlignmentRuns.root"); TFile *f_minbias_Pbp = new TFile("ReverseBeam/CombineSpectra_minbias_EtaCM_P03_P08.root"); TFile *f_FullTrack_12_Pbp = new TFile("ReverseBeam/CombineSpectra_FullTrackTrigger_Track12_EtaCM_P03_P08.root"); TFile *f_FullTrack_20_Pbp = new TFile("ReverseBeam/CombineSpectra_FullTrackTrigger_Track20_EtaCM_P03_P08.root"); TFile *f_FullTrack_30_Pbp = new TFile("ReverseBeam/CombineSpectra_FullTrackTrigger_Track30_Track50_EtaCM_P03_P08.root"); TFile *f_out = new TFile("PtSpectraCombination_StagedNormalization_EtaCM_M03_M08_NoOLDAlignmentRuns_CombpPbPbp_TrackTrigger.root","recreate"); //Get spectra TH1D* hPartPt_minbias_corrected_pPb = (TH1D*)f_minbias_pPb->Get("hPartPt_minbias_trkCorr_trigCorr"); TH1D* hPartPt_0_14_minbias_corrected_pPb = (TH1D*)f_minbias_pPb->Get("hPartPt_0_14_minbias_trkCorr_trigCorr"); TH1D* hPartPt_14_22_FullTrack12_corrected_pPb = (TH1D*)f_FullTrack_12_pPb->Get("hPartPt_FullTrack12_14_22_trkCorr_trigCorr"); TH1D* hPartPt_22_32_FullTrack20_corrected_pPb = (TH1D*)f_FullTrack_20_pPb->Get("hPartPt_FullTrack20_22_32_trkCorr_trigCorr"); TH1D* hPartPt_32_X_FullTrack30_corrected_pPb = (TH1D*)f_FullTrack_30_pPb->Get("hPartPt_FullTrack30_SpectComb_trkCorr_trigCorr"); TH1D* hPartPt_minbias_corrected_Pbp = (TH1D*)f_minbias_Pbp->Get("hPartPt_minbias_trkCorr_trigCorr"); TH1D* hPartPt_0_14_minbias_corrected_Pbp = (TH1D*)f_minbias_Pbp->Get("hPartPt_0_14_minbias_trkCorr_trigCorr"); TH1D* hPartPt_14_22_FullTrack12_corrected_Pbp = (TH1D*)f_FullTrack_12_Pbp->Get("hPartPt_FullTrack12_14_22_trkCorr_trigCorr"); TH1D* hPartPt_22_32_FullTrack20_corrected_Pbp = (TH1D*)f_FullTrack_20_Pbp->Get("hPartPt_FullTrack20_22_32_trkCorr_trigCorr"); TH1D* hPartPt_32_X_FullTrack30_corrected_Pbp = (TH1D*)f_FullTrack_30_Pbp->Get("hPartPt_FullTrack30_SpectComb_trkCorr_trigCorr"); TH1D* hPartPt_minbias_corrected = (TH1D*)hPartPt_minbias_corrected_pPb->Clone("hPartPt_minbias_corrected"); hPartPt_minbias_corrected->Add(hPartPt_minbias_corrected_Pbp); TH1D* hPartPt_0_14_minbias_corrected = (TH1D*)hPartPt_0_14_minbias_corrected_pPb->Clone("hPartPt_0_14_minbias_corrected"); hPartPt_0_14_minbias_corrected->Add(hPartPt_0_14_minbias_corrected_Pbp); TH1D* hPartPt_14_22_FullTrack12_corrected = (TH1D*)hPartPt_14_22_FullTrack12_corrected_pPb->Clone("hPartPt_14_22_FullTrack12_corrected"); hPartPt_14_22_FullTrack12_corrected->Add(hPartPt_14_22_FullTrack12_corrected_Pbp); TH1D* hPartPt_22_32_FullTrack20_corrected = (TH1D*)hPartPt_22_32_FullTrack20_corrected_pPb->Clone("hPartPt_22_32_FullTrack20_corrected"); hPartPt_22_32_FullTrack20_corrected->Add(hPartPt_22_32_FullTrack20_corrected_Pbp); TH1D* hPartPt_32_X_FullTrack30_corrected = (TH1D*)hPartPt_32_X_FullTrack30_corrected_pPb->Clone("hPartPt_32_X_FullTrack30_corrected"); hPartPt_32_X_FullTrack30_corrected->Add(hPartPt_32_X_FullTrack30_corrected_Pbp); /* hPartPt_0_14_minbias_corrected_pPb->SetBinContent(hPartPt_0_14_minbias_corrected_pPb->FindBin(103.24),0);//Remove muon event hPartPt_0_14_minbias_corrected_pPb->SetBinError(hPartPt_0_14_minbias_corrected_pPb->FindBin(103.24),0);//Remove muon event hPartPt_minbias_corrected_pPb->SetBinContent(hPartPt_minbias_corrected_pPb->FindBin(103.24),0);//Remove muon event hPartPt_minbias_corrected_pPb->SetBinError(hPartPt_minbias_corrected_pPb->FindBin(103.24),0);//Remove muon event */ //Get number of events TH1D* hNumEv_minbias_pPb = (TH1D*)f_minbias_pPb->Get("hNumEv_minbias_trigCorr"); TH1D* hNumEv_0_14_minbias_pPb = (TH1D*)f_minbias_pPb->Get("hNumEv_0_14_minbias_trigCorr"); TH1D* hNumEv_14_22_minbias_pPb = (TH1D*)f_minbias_pPb->Get("hNumEv_14_22_minbias_trigCorr"); TH1D* hNumEv_14_22_FullTrack12_pPb = (TH1D*)f_FullTrack_12_pPb->Get("hNumEv_FullTrack12_14_22_trigCorr"); TH1D* hNumEv_22_32_FullTrack12_pPb = (TH1D*)f_FullTrack_12_pPb->Get("hNumEv_FullTrack12_22_32_trigCorr"); TH1D* hNumEv_22_32_FullTrack20_pPb = (TH1D*)f_FullTrack_20_pPb->Get("hNumEv_FullTrack20_22_32_trigCorr"); TH1D* hNumEv_32_X_FullTrack20_pPb = (TH1D*)f_FullTrack_20_pPb->Get("hNumEv_FullTrack20_32_X_trigCorr"); TH1D* hNumEv_32_X_FullTrack30_pPb = (TH1D*)f_FullTrack_30_pPb->Get("hNumEv_FullTrack30_32_X_trigCorr"); TH1D* hNumEv_minbias_Pbp = (TH1D*)f_minbias_Pbp->Get("hNumEv_minbias_trigCorr"); TH1D* hNumEv_0_14_minbias_Pbp = (TH1D*)f_minbias_Pbp->Get("hNumEv_0_14_minbias_trigCorr"); TH1D* hNumEv_14_22_minbias_Pbp = (TH1D*)f_minbias_Pbp->Get("hNumEv_14_22_minbias_trigCorr"); TH1D* hNumEv_14_22_FullTrack12_Pbp = (TH1D*)f_FullTrack_12_Pbp->Get("hNumEv_FullTrack12_14_22_trigCorr"); TH1D* hNumEv_22_32_FullTrack12_Pbp = (TH1D*)f_FullTrack_12_Pbp->Get("hNumEv_FullTrack12_22_32_trigCorr"); TH1D* hNumEv_22_32_FullTrack20_Pbp = (TH1D*)f_FullTrack_20_Pbp->Get("hNumEv_FullTrack20_22_32_trigCorr"); TH1D* hNumEv_32_X_FullTrack20_Pbp = (TH1D*)f_FullTrack_20_Pbp->Get("hNumEv_FullTrack20_32_X_trigCorr"); TH1D* hNumEv_32_X_FullTrack30_Pbp = (TH1D*)f_FullTrack_30_Pbp->Get("hNumEv_FullTrack30_32_X_trigCorr"); TH1D* hNumEv_minbias = (TH1D*)hNumEv_minbias_pPb->Clone("hNumEv_minbias"); hNumEv_minbias->Add(hNumEv_minbias_Pbp); TH1D* hNumEv_0_14_minbias = (TH1D*)hNumEv_0_14_minbias_pPb->Clone("hNumEv_0_14_minbias"); hNumEv_0_14_minbias->Add(hNumEv_0_14_minbias_Pbp); TH1D* hNumEv_14_22_minbias = (TH1D*)hNumEv_14_22_minbias_pPb->Clone("hNumEv_14_22_minbias"); hNumEv_14_22_minbias->Add(hNumEv_14_22_minbias_Pbp); TH1D* hNumEv_14_22_FullTrack12 = (TH1D*)hNumEv_14_22_FullTrack12_pPb->Clone("hNumEv_14_22_FullTrack12"); hNumEv_14_22_FullTrack12->Add(hNumEv_14_22_FullTrack12_Pbp); TH1D* hNumEv_22_32_FullTrack12 = (TH1D*)hNumEv_22_32_FullTrack12_pPb->Clone("hNumEv_22_32_FullTrack12"); hNumEv_22_32_FullTrack12->Add(hNumEv_22_32_FullTrack12_Pbp); TH1D* hNumEv_22_32_FullTrack20 = (TH1D*)hNumEv_22_32_FullTrack20_pPb->Clone("hNumEv_22_32_FullTrack20"); hNumEv_22_32_FullTrack20->Add(hNumEv_22_32_FullTrack20_Pbp); TH1D* hNumEv_32_X_FullTrack20 = (TH1D*)hNumEv_32_X_FullTrack20_pPb->Clone("hNumEv_32_X_FullTrack20"); hNumEv_32_X_FullTrack20->Add(hNumEv_32_X_FullTrack20_Pbp); TH1D* hNumEv_32_X_FullTrack30 = (TH1D*)hNumEv_32_X_FullTrack30_pPb->Clone("hNumEv_32_X_FullTrack30"); hNumEv_32_X_FullTrack30->Add(hNumEv_32_X_FullTrack30_Pbp); float numev_minbias = hNumEv_minbias->GetBinContent(1); float numev_0_14_minbias = hNumEv_0_14_minbias->GetBinContent(1); float numev_14_22_minbias = hNumEv_14_22_minbias->GetBinContent(1); float numev_14_22_FullTrack12 = hNumEv_14_22_FullTrack12->GetBinContent(1); float numev_22_32_FullTrack12 = hNumEv_22_32_FullTrack12->GetBinContent(1); float numev_22_32_FullTrack20 = hNumEv_22_32_FullTrack20->GetBinContent(1); float numev_32_X_FullTrack20 = hNumEv_32_X_FullTrack20->GetBinContent(1); float numev_32_X_FullTrack30 = hNumEv_32_X_FullTrack30->GetBinContent(1); std::cerr<<" Number of minbias events in the normalization classes:" << std::endl; std::cerr<<" All : " << numev_minbias << std::endl; std::cerr<<" 0-14 MB : " << numev_0_14_minbias << std::endl; std::cerr<<" 14-22 MB : " << numev_14_22_minbias << std::endl; std::cerr<<" 14-22 T12: " << numev_14_22_FullTrack12 << std::endl; std::cerr<<" 22-32 T12: " << numev_22_32_FullTrack12 << std::endl; std::cerr<<" 22-32 T20: " << numev_22_32_FullTrack20 << std::endl; std::cerr<<" 32-X T20: " << numev_32_X_FullTrack20 << std::endl; std::cerr<<" 32-X T30: " << numev_32_X_FullTrack30 << std::endl; std::cerr<<" numev_minbias/numev_0_14_minbias: " << 100.*numev_minbias/numev_0_14_minbias << "%" << std::endl; std::cerr<<" numev_14_22_minbias/numev_0_14_minbias: " << 100.*numev_14_22_minbias/numev_0_14_minbias << "%" << std::endl; std::cerr<<" numev_14_22_FullTrack12/numev_22_32_FullTrack12: " << 100.*numev_14_22_FullTrack12/numev_22_32_FullTrack12 << std::endl; //Prepare the individual normalizations float norm_0_14_minbias = numev_minbias; float norm_14_22_FullTrack12 = norm_0_14_minbias*numev_14_22_FullTrack12/numev_14_22_minbias; // float norm_14_22_FullTrack12 = numev_14_22_FullTrack12*2466.480; float norm_22_32_FullTrack20 = norm_14_22_FullTrack12*numev_22_32_FullTrack20/numev_22_32_FullTrack12; float norm_32_X_FullTrack30 = norm_22_32_FullTrack20*numev_32_X_FullTrack30/numev_32_X_FullTrack20; std::cerr<<"Normalization factors:" << std::endl; std::cerr<<" norm_0_14_minbias : " << norm_0_14_minbias << std::endl; std::cerr<<" norm_14_22_FullTrack12: " << norm_14_22_FullTrack12 << std::endl; std::cerr<<" norm_22_32_FullTrack20: " << norm_22_32_FullTrack20 << std::endl; std::cerr<<" norm_32_X_FullTrack30 : " << norm_32_X_FullTrack30 << std::endl; hPartPt_minbias_corrected->Scale(1./numev_minbias); hPartPt_0_14_minbias_corrected->Scale(1./norm_0_14_minbias); hPartPt_14_22_FullTrack12_corrected->Scale(1./norm_14_22_FullTrack12); hPartPt_22_32_FullTrack20_corrected->Scale(1./norm_22_32_FullTrack20); hPartPt_32_X_FullTrack30_corrected->Scale(1./norm_32_X_FullTrack30); TCanvas *c1 = new TCanvas("c1","c1"); c1->cd(); c1->SetLogy(); hPartPt_0_14_minbias_corrected->GetXaxis()->CenterTitle(); hPartPt_0_14_minbias_corrected->GetYaxis()->CenterTitle(); hPartPt_0_14_minbias_corrected->GetXaxis()->SetTitle("p_{T} [GeV/c]"); hPartPt_0_14_minbias_corrected->GetYaxis()->SetTitle("1/N_{ev} dN/dp_{T} (|#eta_{CM}|<1)"); // hPartPt_0_14_minbias_corrected->SetNdivisions(505); hPartPt_0_14_minbias_corrected->SetMarkerColor(42); hPartPt_0_14_minbias_corrected->SetLineColor(42); hPartPt_0_14_minbias_corrected->SetMarkerStyle(34); hPartPt_0_14_minbias_corrected->SetMinimum(1e-11); hPartPt_0_14_minbias_corrected->SetFillColor(42); // hPartPt_0_14_minbias_corrected->SetFillStyle(3305); hPartPt_0_14_minbias_corrected->Draw("hist"); hPartPt_minbias_corrected->SetMarkerStyle(20); hPartPt_minbias_corrected->Draw("same"); hPartPt_14_22_FullTrack12_corrected->SetMarkerColor(2); hPartPt_14_22_FullTrack12_corrected->SetLineColor(2); hPartPt_14_22_FullTrack12_corrected->SetMarkerStyle(20); hPartPt_14_22_FullTrack12_corrected->SetFillColor(2); hPartPt_14_22_FullTrack12_corrected->SetFillStyle(3002); hPartPt_14_22_FullTrack12_corrected->Draw("same"); hPartPt_22_32_FullTrack20_corrected->SetMarkerColor(4); hPartPt_22_32_FullTrack20_corrected->SetLineColor(4); hPartPt_22_32_FullTrack20_corrected->SetMarkerStyle(20); // hPartPt_22_32_FullTrack20_corrected->SetFillColor(2); // hPartPt_22_32_FullTrack20_corrected->SetFillStyle(3002); hPartPt_22_32_FullTrack20_corrected->Draw("samehist"); hPartPt_32_X_FullTrack30_corrected->SetMarkerColor(2); hPartPt_32_X_FullTrack30_corrected->SetLineColor(2); hPartPt_32_X_FullTrack30_corrected->SetMarkerStyle(20); // hPartPt_32_X_FullTrack30_corrected->SetFillColor(2); // hPartPt_32_X_FullTrack30_corrected->SetFillStyle(3002); hPartPt_32_X_FullTrack30_corrected->Draw("samehist"); //Sum TH1D * hSumPartPt = (TH1D*)hPartPt_0_14_minbias_corrected->Clone("hSumPartPt"); hSumPartPt->Add(hPartPt_14_22_FullTrack12_corrected); hSumPartPt->Add(hPartPt_22_32_FullTrack20_corrected); hSumPartPt->Add(hPartPt_32_X_FullTrack30_corrected); hSumPartPt->SetMarkerStyle(25); hSumPartPt->SetMarkerColor(1); hSumPartPt->SetLineColor(1); hSumPartPt->Draw("same"); TLegend *leg1 = new TLegend(0.48,0.47,0.93,0.95,NULL,"brNDC"); leg1->AddEntry(hPartPt_minbias_corrected,"MinBias, inclusive","pl"); leg1->AddEntry(hPartPt_0_14_minbias_corrected,"MinBias, p_{T}<14 GeV/c","f"); leg1->AddEntry(hPartPt_14_22_FullTrack12_corrected,"FullTrack12, 14<p_{T}<22 GeV/c","pl"); leg1->AddEntry(hPartPt_22_32_FullTrack20_corrected,"FullTrack20, 22<p_{T}<32 GeV/c","l"); leg1->AddEntry(hPartPt_32_X_FullTrack30_corrected,"FullTrack30, 32<p_{T} GeV/c","l"); leg1->AddEntry(hSumPartPt,"Combined spectrum","pl"); leg1->SetFillStyle(0); leg1->SetFillColor(0); leg1->SetBorderSize(0); leg1->Draw(); if(doSave) { c1->SaveAs("Figs/PtSpectraCombination_StagedNormalization_EtaCM_M03_M08_NoOLDAlignmentRuns_CombpPbPbp_c1.gif"); c1->SaveAs("Figs/PtSpectraCombination_StagedNormalization_EtaCM_M03_M08_NoOLDAlignmentRuns_CombpPbPbp_c1.eps"); c1->SaveAs("Figs/PtSpectraCombination_StagedNormalization_EtaCM_M03_M08_NoOLDAlignmentRuns_CombpPbPbp_c1.C"); } TCanvas *c2 = new TCanvas("c2","c2"); c2->cd(); TH1D *hSumPartPt_copy1 = (TH1D*)hSumPartPt->Clone("hSumPartPt_copy1"); hSumPartPt_copy1->Divide(hPartPt_minbias_corrected); hSumPartPt_copy1->GetYaxis()->SetTitle("Combined spectrum / MB inclusive"); hSumPartPt_copy1->Draw(); TLatex *inf1 = new TLatex(0.33,0.17,"Combined spectrum: from track triggers"); inf1->SetNDC(); inf1->SetTextSize(0.035); inf1->Draw(); TPad *c2_zoom = new TPad("c2_zoom","c2_zoom",0.56,0.56,0.94,0.93); c2_zoom->SetFillStyle(0); c2_zoom->SetLogx(); c2_zoom->Draw(); c2_zoom->cd(); TH1D *hSumPartPt_copy2 = (TH1D*)hSumPartPt_copy1->Clone("hSumPartPt_copy2"); hSumPartPt_copy2->GetXaxis()->CenterTitle(); hSumPartPt_copy2->GetYaxis()->CenterTitle(); hSumPartPt_copy2->GetXaxis()->SetTitle("p_{T} [GeV/c]"); hSumPartPt_copy2->GetYaxis()->SetTitle("Combined spectrum / MB inclusive "); hSumPartPt_copy2->GetXaxis()->SetRangeUser(0.,18.); hSumPartPt_copy2->SetMinimum(0.95); hSumPartPt_copy2->SetMaximum(1.05); hSumPartPt_copy2->Draw(); if(doSave) { c2->SaveAs("Figs/PtSpectraCombination_StagedNormalization_EtaCM_M03_M08_NoOLDAlignmentRuns_CombpPbPbp_c2.gif"); c2->SaveAs("Figs/PtSpectraCombination_StagedNormalization_EtaCM_M03_M08_NoOLDAlignmentRuns_CombpPbPbp_c2.eps"); c2->SaveAs("Figs/PtSpectraCombination_StagedNormalization_EtaCM_M03_M08_NoOLDAlignmentRuns_CombpPbPbp_c2.C"); } /* TLegend *leg2 = new TLegend(0.80,0.75,0.95,0.95,NULL,"brNDC"); leg2->AddEntry(hPartPt_Jet40_copy1,"Jet40","pl"); leg2->AddEntry(hPartPt_Jet60_copy1,"Jet60","pl"); leg2->AddEntry(hPartPt_Jet80_copy1,"Jet80","pl"); leg2->AddEntry(hPartPt_Jet100_copy1,"Jet100","pl"); leg2->SetFillStyle(0); leg2->SetFillColor(0); leg2->SetBorderSize(0); leg2->Draw(); */ f_out->cd(); hSumPartPt->Write(); f_out->Close(); }
// ----------------------------------------------------------------------------- // TCanvas* aDrawBkgdPlots( TString path, TString canvas_name, TString name, TString dirmame, int rebin, bool norm, bool log, TDirectory* file ) { // SetSomeStyles(); // Create legend TLegend* legend = new TLegend( 0.75, 0.65, 0.92, 0.92, NULL, "brNDC" ); legend->SetFillColor(0); legend->SetLineColor(0); // Create canvas TCanvas* aCanvas = getaCanvas( canvas_name, file, log ); // Create histograms TH1D* qcd = readHist( path, name, "IC5Calo_QCD_Pythia_Merged.root", dirmame, rebin ); TH1D* tt_jets = readHist( path, name, "IC5Calo_TTbarJets.root", dirmame, rebin ); TH1D* w_jets = readHist( path, name, "IC5Calo_WJets.root", dirmame, rebin ); TH1D* z_inv = readHist( path, name, "IC5Calo_Zinv.root", dirmame, rebin ); TH1D* z_jets = readHist( path, name, "IC5Calo_ZJets.root", dirmame, rebin ); TH1D* lm0 = readHist( path, name, "IC5Calo_LM0.root", dirmame, rebin ); TH1D* lm1 = readHist( path, name, "IC5Calo_LM1.root", dirmame, rebin ); // Combine Z+jets and Z->inv TH1D* z_all = z_inv->Clone(); z_all->Add(z_jets,1); // TH1D* z_all = 0; // if ( z_inv && z_jets ) { // z_all = z_inv->Clone(); // z_all->Add(z_jets,1); // } else if ( z_inv ) { // z_all = z_inv->Clone(); // } else if ( z_jets ) { // z_all = z_jets->Clone(); // } // Select Z+jets and Z->inv separate or not bool combine = true; // Line colour and fill if ( qcd ) qcd->SetLineColor(kGreen+2); if ( qcd ) qcd->SetFillColor(kGreen+2); if ( qcd ) qcd->SetFillStyle(3003); if ( tt_jets ) tt_jets->SetLineColor(kBlue); if ( tt_jets ) tt_jets->SetLineStyle(1); if ( tt_jets ) tt_jets->SetLineWidth(1); w_jets->SetLineColor(kBlue); w_jets->SetLineStyle(3); w_jets->SetLineWidth(1); if ( combine ) { z_all->SetLineColor(kBlack); z_all->SetLineStyle(3); z_all->SetLineWidth(1); } else { z_inv->SetLineColor(kBlack); z_inv->SetLineStyle(1); z_inv->SetLineWidth(1); z_jets->SetLineColor(kBlack); z_jets->SetLineStyle(3); z_jets->SetLineWidth(1); } lm0->SetLineColor(kRed); lm0->SetLineStyle(1); lm0->SetLineWidth(2); lm1->SetLineColor(kRed); lm1->SetLineStyle(3); lm1->SetLineWidth(2); // Populate legend legend->AddEntry( qcd, " QCD", "f" ); legend->AddEntry( lm0, " SUSY LM0", "L" ); legend->AddEntry( lm1, " SUSY LM1", "L" ); legend->AddEntry( tt_jets, " t#bar{t}+jets", "L" ); legend->AddEntry( w_jets, " W+jets", "L" ); if ( combine ) { legend->AddEntry( z_all, " Z", "L" ); } else { legend->AddEntry( z_jets, " Z+jets", "L" ); legend->AddEntry( z_inv, " Z#rightarrow#nu#nu", "L" ); } // Calc maximum number of entries double aMax = 0.; if ( qcd->GetMaximum() > aMax ) { aMax = qcd->GetMaximum(); } if ( lm0->GetMaximum() > aMax ) { aMax = lm0->GetMaximum(); } if ( lm1->GetMaximum() > aMax ) { aMax = lm1->GetMaximum(); } if ( tt_jets->GetMaximum() > aMax ) { aMax = tt_jets->GetMaximum(); } if ( w_jets->GetMaximum() > aMax ) { aMax = w_jets->GetMaximum(); } if ( combine ) { if ( z_all->GetMaximum() > aMax ) { aMax = z_all->GetMaximum(); } } else { if ( z_inv->GetMaximum() > aMax ) { aMax = z_inv->GetMaximum(); } if ( z_jets->GetMaximum() > aMax ) { aMax = z_jets->GetMaximum(); } } // Calc minimum number of entries double aMin = 1.e12; if ( qcd->GetMinimum(1.e-12) < aMin ) { aMin = qcd->GetMinimum(1.e-12); } if ( lm0->GetMinimum(1.e-12) < aMin ) { aMin = lm0->GetMinimum(1.e-12); } if ( lm1->GetMinimum(1.e-12) < aMin ) { aMin = lm1->GetMinimum(1.e-12); } if ( tt_jets->GetMinimum(1.e-12) < aMin ) { aMin = tt_jets->GetMinimum(1.e-12); } if ( w_jets->GetMinimum(1.e-12) < aMin ) { aMin = w_jets->GetMinimum(1.e-12); } if ( combine ) { if ( z_all->GetMinimum(1.e-12) < aMin ) { aMin = z_all->GetMinimum(1.e-12); } } else { if ( z_inv->GetMinimum(1.e-12) < aMin ) { aMin = z_inv->GetMinimum(1.e-12); } if ( z_jets->GetMinimum(1.e-12) < aMin ) { aMin = z_jets->GetMinimum(1.e-12); } } if ( qcd ) qcd->GetYaxis()->SetTitleOffset(1.43); if ( qcd ) qcd->GetYaxis()->SetTitleSize(0.06); if ( qcd ) qcd->GetXaxis()->SetTitleSize(0.06); if ( qcd ) qcd->GetXaxis()->SetTitleOffset(0.9); if ( log ) { if ( qcd ) qcd->SetMaximum( aMax * 10. ); if ( qcd ) qcd->SetMinimum( aMin * 0.1 ); } else { if ( qcd ) qcd->SetMaximum( aMax * 1.1 ); if ( qcd ) qcd->SetMinimum( aMin * 0.9 ); } if ( norm ) { if ( qcd ) qcd->DrawNormalized("Ehist"); if ( lm0->GetEntries() > 0. ) { lm0->DrawNormalized("hsame"); } if ( lm1->GetEntries() > 0. ) { lm1->DrawNormalized("hsame"); } if ( tt_jets->GetEntries() > 0. ) { tt_jets->DrawNormalized("hsame"); } if ( w_jets->GetEntries() > 0. ) { w_jets->DrawNormalized("hsame"); } if ( combine ) { if ( z_all->GetEntries() > 0. ) { z_all->DrawNormalized("hsame"); } } else { if ( z_inv->GetEntries() > 0. ) { z_inv->DrawNormalized("hsame"); } if ( z_jets->GetEntries() > 0. ) { z_jets->DrawNormalized("hsame"); } } } else { if ( qcd ) qcd->Draw("h"); lm0->Draw("sameH"); lm1->Draw("sameH"); if ( tt_jets ) tt_jets->Draw("sameh"); w_jets->Draw("sameH"); if ( combine ) { z_all->Draw("sameH"); } else { z_inv->Draw("sameH"); z_jets->Draw("sameH"); } } file->cd(); legend->Draw("same"); aCanvas->Write(); return aCanvas; }
void diffXsect() { //choice of systematic to look at int choice = 0; bool writeFile =true; //MET will need choice of variable at the top // TString Variable ="_MET"; // int Nbins = 6; // TString bins[6] = {"_bin_0-25", "_bin_25-45", "_bin_45-70", "_bin_70-100", "_bin_100-150", "_bin_150-inf"}; // double width[6] = {25, 20, 25, 30, 50, 100}; // double xbins[7] = {1,25,45,70,100,150, 250}; // TString varBin = "Binned_MET_Analysis/patType1CorrectedPFMet"; // TString Xtitle = "MET [GeV]"; //HT // TString Variable ="_HT"; // int Nbins = 8; // TString bins[8] = {"_bin_0-50", "_bin_50-150", "_bin_150-250", "_bin_250-350", "_bin_350-450", "_bin_450-650", "_bin_650-1100", "_bin_1100-inf"}; // double width[8] = {50,100,100,100,100,200,450,400}; // double xbins[9] = {1,50,150,250,350,450,650,1100, 1500}; // TString varBin = "Binned_HT_Analysis/HT"; // TString Xtitle = "HT [GeV]"; //ST TString Variable ="_ST"; int Nbins = 8; TString bins[8] = {"_bin_0-150", "_bin_150-250", "_bin_250-350", "_bin_350-450", "_bin_450-550", "_bin_550-750", "_bin_750-1250", "_bin_1250-inf"}; double width[8] = {150,100,100,100,100,200,500,500}; double xbins[9] = {1,150,250,350,450,550,750,1250, 1750}; TString varBin = "Binned_ST_Analysis/ST_with_patType1CorrectedPFMet"; TString Xtitle = "ST [GeV]"; //MT // TString Variable ="_MT"; // int Nbins = 5; // TString bins[5] = {"_bin_0-40", "_bin_40-65", "_bin_65-85", "_bin_85-150", "_bin_150-inf"}; // double width[5] = {40,25,20,65,50}; // double xbins[6] = {1,40,65,85,150,200}; // TString varBin = "Binned_MT_Analysis/MT_with_patType1CorrectedPFMet"; // TString Xtitle = "M(W)_{T} [GeV]"; //int Nsys = 1; int Nsys = 27; //from fit double NfitVal[Nbins][Nsys]; double NfitErr[Nbins][Nsys]; double NttbarVal[Nbins][Nsys]; double NttbarErr[Nbins][Nsys]; double sigmaVal[Nbins][Nsys]; double sigmaErr[Nbins][Nsys]; //before fit double madgraphVals[Nbins][Nsys]; double mcatnloVals[Nbins][Nsys]; double powhegVals[Nbins][Nsys]; double ttbarPre[Nbins][Nsys]; double singletPre[Nbins][Nsys]; double wjetsPre[Nbins][Nsys]; double zjetsPre[Nbins][Nsys]; double qcdPre[Nbins][Nsys]; double BGscale[Nbins][Nsys]; double totXsect[Nsys]; //sample //TString dir = "central"; //TString dir = "JES_up"; TString dirs[27] = {"central","JES_up","JES_down", "BJet_up", "BJet_down", "PU_up", "PU_down", "Scale_up_tt", "Scale_down_tt", "Scale_up", "Scale_down", "Match_up_tt", "Match_down_tt", "Match_up", "Match_down", "UnclusteredEnUp", "UnclusteredEnDown", "JetEnUp", "JetEnDown", "JetResUp", "JetResDown", "TauEnUp", "TauEnDown", "MuonEnUp", "MuonEnDown", "ElectronEnUp", "ElectronEnDown"}; //loop over systematics for(int sys = 0; sys < Nsys; sys++) { TString dir = dirs[sys]; totXsect[sys]= 0; int rebinFact = 1; //for ttbar total TH1D* tt_tot = getSample("TTJet", lumi*225.197/6920475, rebinFact, "Muon", dir); TH1D* mcnlo_tot = getSample("TTJet_MCNLO", lumi*225.197/6920475, rebinFact, "Muon", "central"); TH1D* powheg_tot = getSample("TTJet_POWHEG", lumi*225.197/6920475, rebinFact, "Muon", "central"); //loop over bins of distribution for(int i = 0; i < Nbins; i++) { TString bin = varBin; if(dir == "UnclusteredEnUp" || dir == "UnclusteredEnDown" || dir == "JetEnUp" || dir == "JetEnDown" || dir == "JetResUp" || dir == "JetResDown" || dir == "TauEnUp" || dir == "TauEnDown" || dir == "MuonEnUp" || dir == "MuonEnDown" || dir == "ElectronEnUp" || dir == "ElectronEnDown") bin += dir; bin += bins[i]; bool inclZ = false; bool inclW = false; if(dir == "Scale_up" || dir == "Scale_down" || dir == "Match_up" || dir == "Match_down") { inclZ = true; inclW = true; } cout << bin << endl; TH1D* tt = getSample("TTJet", lumi*225.197/6920475, rebinFact, bin, dir); TH1D* tt_mcnlo = getSample("TTJet_MCNLO", lumi*225.197/6920475, rebinFact, bin, "central"); TH1D* tt_powheg = getSample("TTJet_POWHEG", lumi*225.197/6920475, rebinFact, bin, "central"); TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707, rebinFact, bin, dir); TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395, rebinFact, bin, dir); TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516, rebinFact, bin, dir); TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817, rebinFact, bin, dir); TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239, rebinFact, bin, dir); TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948, rebinFact, bin, dir); TH1D* wjets; //TH1D* w1jets = getSample("W1Jet", lumi*5400.0/23140779, rebinFact, bin, dir); TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404, rebinFact, bin, dir); TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443, rebinFact, bin, dir); TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904, rebinFact, bin, dir); TH1D* zjets; //TH1D* z1jets = getSample("DY1JetsToLL", lumi*561.0/24042904, rebinFact, bin, dir); TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749, rebinFact, bin, dir); TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628, rebinFact, bin, dir); TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785, rebinFact, bin, dir); TH1D* qcd_mc = getSample("QCD_Pt-15to20_MuEnrichedPt5", lumi*7.022e8 * 0.0039/1722678, rebinFact, bin, dir); TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5", lumi*2.87e8 * 0.0065/8486893, rebinFact, bin, dir); TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5", lumi*6.609e7 * 0.0122/8928999, rebinFact, bin, dir); TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5", lumi*8082000.0 * 0.0218/7256011, rebinFact, bin, dir); TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5", lumi*1024000.0 * 0.0395/9030624, rebinFact, bin, dir); TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505, rebinFact, bin, dir); TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483, rebinFact, bin, dir); TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481, rebinFact, bin, dir); TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767, rebinFact, bin, dir); TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142, rebinFact, bin, dir); TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5", lumi*0.774 * 0.1097/3807263, rebinFact, bin, dir); qcd_mc->Add(qcd2); qcd_mc->Add(qcd3); qcd_mc->Add(qcd4); qcd_mc->Add(qcd5); qcd_mc->Add(qcd6); qcd_mc->Add(qcd7); qcd_mc->Add(qcd8); qcd_mc->Add(qcd9); qcd_mc->Add(qcd10); qcd_mc->Add(qcd11); if(inclZ == true) { zjets = getSample("DYJetsToLL", lumi*5745.25/30457954, rebinFact, bin, dir); } else { zjets = getSample("DY1JetsToLL", lumi*561.0/24042904, rebinFact, bin, dir); zjets->Add(z2jets); zjets->Add(z3jets); zjets->Add(z4jets); } if(inclW == true) { wjets = getSample("WJetsToLNu", lumi*37509/57708550, rebinFact, bin, dir); } else { wjets = getSample("W1Jet", lumi*5400.0/23140779, rebinFact, bin, dir); wjets->Add(w2jets); wjets->Add(w3jets); wjets->Add(w4jets); } //sum single top into one TH1D* single_top = (TH1D*)top_t->Clone("single top"); single_top->Add(top_tw); single_top->Add(top_s); single_top->Add(tbar_t); single_top->Add(tbar_tw); single_top->Add(tbar_s); NfitVal[i][sys] = etaFit(bin, "measured",dir); NfitErr[i][sys] = etaFit(bin, "measuredErr",dir); BGscale[i][sys] = etaFit(bin,"bgscale",dir); NttbarVal[i][sys] = NfitVal[i][sys]-single_top->Integral(); NttbarErr[i][sys] = NfitErr[i][sys] ; sigmaVal[i][sys] = ((NfitVal[i][sys]-single_top->Integral())/tt_tot->Integral())*225.197; sigmaErr[i][sys] = (((NfitVal[i][sys]+NfitErr[i][sys]-single_top->Integral())/tt_tot->Integral())*225.197)-sigmaVal[i][sys]; //cout << "error: " << sigmaErr[i][sys] << endl; madgraphVals[i][sys] = (tt->Integral()/tt_tot->Integral())*225.197; mcatnloVals[i][sys] = (tt_mcnlo->Integral()/mcnlo_tot->Integral())*225.197; powhegVals[i][sys] = (tt_powheg->Integral()/powheg_tot->Integral())*225.197; ttbarPre[i][sys] = tt->Integral(); singletPre[i][sys] = single_top->Integral(); wjetsPre[i][sys] = wjets->Integral(); zjetsPre[i][sys] = zjets->Integral(); qcdPre[i][sys] = qcd_mc->Integral(); totXsect[sys] += sigmaVal[i][sys]; } } //will need to change MET for other variables TFile resultsfile("outFiles/diffResults"+Variable+".root", "UPDATE", "comment"); for(int sys = 0; sys < Nsys; sys++) { TString dir = dirs[sys]; resultsfile.mkdir(dir+"_dir"); resultsfile.cd(dir+"_dir"); //measured histo will have to put name of systematic in here to write into file TH1D *muon_part = new TH1D(dir+"_signal_fit", "", Nbins, xbins); //muon TH1D *ttbar_fit = new TH1D(dir+"_ttbar_fit", "", Nbins, xbins); //muon TH1D *ttbar_prefit = new TH1D(dir+"_ttbar_prefit", "", Nbins, xbins); //muon TH1D *singlet_prefit = new TH1D(dir+"_singlet_prefit", "", Nbins, xbins); //muon TH1D *wjets_prefit = new TH1D(dir+"_wjets_prefit", "", Nbins, xbins); //muon TH1D *zjets_prefit = new TH1D(dir+"_zjets_prefit", "", Nbins, xbins); //muon TH1D *qcd_prefit = new TH1D(dir+"_qcd_prefit", "", Nbins, xbins); //muon TH1D *wjets_fit = new TH1D(dir+"_wjets_fit", "", Nbins, xbins); //mu TH1D *zjets_fit = new TH1D(dir+"_zjets_fit", "", Nbins, xbins); //mu TH1D *qcd_fit = new TH1D(dir+"_qcd_fit", "", Nbins, xbins); //muon // muon_part->SetDirectory(directory); //loop over bins of distribution for(int i = 0; i < Nbins; i++) { muon_part->SetBinContent(i+1,NfitVal[i][sys]); muon_part->SetBinError(i+1, NfitErr[i][sys]); ttbar_fit->SetBinContent(i+1,NttbarVal[i][sys]); ttbar_fit->SetBinError(i+1, NttbarErr[i][sys]); ttbar_prefit->SetBinContent(i+1,ttbarPre[i][sys]); singlet_prefit->SetBinContent(i+1,singletPre[i][sys]); wjets_prefit->SetBinContent(i+1, wjetsPre[i][sys]); zjets_prefit->SetBinContent(i+1, zjetsPre[i][sys]); qcd_prefit->SetBinContent(i+1, qcdPre[i][sys]); wjets_fit->SetBinContent(i+1, wjetsPre[i][sys]*BGscale[i][sys]); zjets_fit->SetBinContent(i+1, zjetsPre[i][sys]*BGscale[i][sys]); qcd_fit->SetBinContent(i+1, qcdPre[i][sys]*BGscale[i][sys]); } resultsfile.cd(); } if(writeFile ==true) resultsfile.Write(); resultsfile.Close(); cout << "N fit: " << endl; for(int i = 0; i < Nbins; i++) { cout << bins[i] << ": " << " = " << NfitVal[i][choice] << " +- " << NfitErr[i][choice] << endl; } cout << "partial xsects: " << endl; for(int i = 0; i < Nbins; i++) { cout << bins[i] << ": " << " = " << sigmaVal[i][choice] << " +- " << sigmaErr[i][choice] << endl; //cout << bins[i] << ": " << " = " << madgraphVals[i] << endl; } cout << "normalised xsects: " << endl; for(int i = 0; i < Nbins; i++) { cout << bins[i] << ": " << " = " << sigmaVal[i][choice]/totXsect[choice] << endl; } cout << "normalised differential: " << endl; for(int i = 0; i < Nbins; i++) { cout << bins[i] << ": " << " = " << sigmaVal[i][choice]/(totXsect[choice]*width[i]) << endl; } cout << "cross section is: " << totXsect[choice] << endl; //measured histo will have to put name of systematic in here to write into file TH1D *muon_part = new TH1D("central", "", Nbins, xbins); //muon //different generators TH1D *madgraph = new TH1D("madgraph", "", Nbins, xbins); TH1D *mcatnlo = new TH1D("mcatnlo", "", Nbins, xbins); TH1D *powheg = new TH1D("powheg", "", Nbins, xbins); madgraph->SetLineColor(kRed); mcatnlo->SetLineColor(kBlue); powheg->SetLineColor(kGreen+2); for(int i = 0; i < Nbins; i++) { muon_part->SetBinContent(i+1,sigmaVal[i][choice]); muon_part->SetBinError(i+1, sigmaErr[i][choice]); madgraph->SetBinContent(i+1,madgraphVals[i][choice]); madgraph->SetBinError(i+1,0.0); mcatnlo->SetBinContent(i+1,mcatnloVals[i][choice]); mcatnlo->SetBinError(i+1,0.0); powheg->SetBinContent(i+1,powhegVals[i][choice]); powheg->SetBinError(i+1,0.0); } //do the plots TCanvas *c= new TCanvas("c","c",10,10,800,600); muon_part->SetMarkerStyle(20); muon_part->Draw("E"); muon_part->SetMaximum(muon_part->GetBinContent(muon_part->GetMaximumBin())*1.5); muon_part->SetMinimum(0.); mcatnlo->Draw("same"); powheg->Draw("same"); madgraph->Draw("same"); TLegend *tleg; tleg = new TLegend(0.6,0.75,0.85,0.9); tleg->SetTextSize(0.03); tleg->SetBorderSize(0); tleg->SetFillColor(10); tleg->AddEntry(muon_part , "data '12'" , "lep"); tleg->AddEntry(madgraph , "MadGraph" , "l"); tleg->AddEntry(mcatnlo , "MC@NLO" , "l"); tleg->AddEntry(powheg , "POWHEG" , "l"); tleg->Draw(); //titles muon_part->GetYaxis()->SetTitle("#partial #sigma [pb]"); muon_part->GetYaxis()->SetTitleSize(0.05); muon_part->GetXaxis()->SetTitle(Xtitle); muon_part->GetXaxis()->SetTitleSize(0.05); TText* textPrelim = doPrelim(0.16,0.96); textPrelim->Draw(); c->SaveAs("plots/Measurments/partialXsect"+Variable+".pdf"); //normailise for(int i = 0; i < Nbins; i++) { muon_part->SetBinContent(i+1,sigmaVal[i][choice]/totXsect[choice]); muon_part->SetBinError(i+1,sigmaErr[i][choice]/totXsect[choice]); // muon_norm_diff->SetBinContent(i+1,sigmaVal[i]/(totXsect*width)); madgraph->SetBinContent(i+1,madgraphVals[i][choice]/225.197); madgraph->SetBinError(i+1,0.0/225.197); mcatnlo->SetBinContent(i+1,mcatnloVals[i][choice]/225.197); mcatnlo->SetBinError(i+1,0.0/225.197); powheg->SetBinContent(i+1,powhegVals[i][choice]/225.197); powheg->SetBinError(i+1,0.0/225.197); } delete c; TCanvas *c2= new TCanvas("c2","c2",10,10,800,600); muon_part->SetMarkerStyle(20); muon_part->Draw("E"); muon_part->SetMaximum(muon_part->GetBinContent(muon_part->GetMaximumBin())*1.5); mcatnlo->Draw("same"); powheg->Draw("same"); madgraph->Draw("same"); tleg->Draw(); //titles muon_part->GetYaxis()->SetTitle("#frac{1}{#sigma} #partial #sigma [pb GeV^{-1}]"); muon_part->GetYaxis()->SetTitleSize(0.05); //muon_part->GetXaxis()->SetTitle(Xtitle); //muon_part->GetXaxis()->SetTitleSize(0.05); textPrelim->Draw(); c2->SaveAs("plots/Measurments/partialXsectNorm"+Variable+".pdf"); //normailise and differential for(int i = 0; i < Nbins; i++) { double width = muon_part->GetBinWidth(i+1); muon_part->SetBinContent(i+1,sigmaVal[i][choice]/(totXsect[choice]*width)); muon_part->SetBinError(i+1,sigmaErr[i][choice]/(totXsect[choice]*width)); madgraph->SetBinContent(i+1,madgraphVals[i][choice]/(225.197*width)); madgraph->SetBinError(i+1,0.0/(225.197*width)); mcatnlo->SetBinContent(i+1,mcatnloVals[i][choice]/(225.197*width)); mcatnlo->SetBinError(i+1,0.0/(225.197*width)); powheg->SetBinContent(i+1,powhegVals[i][choice]/(225.197*width)); powheg->SetBinError(i+1,0.0/(225.197*width)); } delete c2; TCanvas *c3= new TCanvas("c3","c3",10,10,800,600); muon_part->SetMarkerStyle(20); muon_part->Draw("E"); muon_part->SetMaximum(muon_part->GetBinContent(muon_part->GetMaximumBin())*1.5); mcatnlo->Draw("same"); powheg->Draw("same"); madgraph->Draw("same"); tleg->Draw(); //titles muon_part->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{#partial #sigma}{#partial MET} [GeV^{-1}]"); muon_part->GetYaxis()->SetTitleSize(0.05); //muon_part->GetXaxis()->SetTitle("MET [GeV]"); //muon_part->GetXaxis()->SetTitleSize(0.05); textPrelim->Draw(); c3->SaveAs("plots/Measurments/partialXsectNormDiff"+Variable+".pdf"); delete c3; }
GenVBosonPlot(TString name, int rebin,float min = -1,float max =0, bool log=false){ // TCanvas* aCan = new TCanvas(name,name,0.6,0.6,0.8,0.8); TCanvas* aCan = new TCanvas(name); aCan->Divide(2,1); aCan->cd(1); if(log) aCan->SetLogy(); // int rebin= 10; TFile* W = new TFile("results5/IC5Calo_WJets_madgraph.root"); //W->ls(); TDirectory* Wdir = ( TDirectory*) W->Get("GenVBoson200"); Wdir->ls(); TH1D* Wh = (TH1D*) Wdir->Get(name); Wh->Rebin(rebin); Wh->SetLineWidth(2); Wh->SetLineStyle(2); // Wh-> if(min>-.2) Wh->GetXaxis()->SetRangeUser(min,max); Wh->DrawNormalized(); //cout << Wh->GetMaximum() <<endl; Wh->GetXaxis()->SetRangeUser(0.00001,1); // Wh->SetMaximum( Wh->GetMaximum()*1.75); TFile* Z = new TFile("results5/IC5Calo_Zinvisible_jets.root"); //Z->ls(); TDirectory* Zdir = ( TDirectory*) Z->Get("GenVBoson200"); // Zdir->ls(); TH1D* Zh = (TH1D*) Zdir->Get(name); Zh->SetLineColor(kRed); Zh->SetLineWidth(2); Zh->SetLineStyle(2); Zh->Rebin(rebin); Zh->DrawNormalized("same"); TFile* Ph = new TFile("results5/photon.root"); Ph->ls(); TDirectory* Phdir = ( TDirectory*) Ph->Get("GenVBoson200"); // Phdir->ls(); TH1D* Phh = (TH1D*) Phdir->Get(name); Phh->SetLineColor(kBlue); Phh->SetLineWidth(2); Phh->Rebin(rebin); Phh->DrawNormalized("same"); TLegend* leg = new TLegend(0.5,0.5,0.7,0.7); leg->AddEntry(Zh,"Z","l" ); leg->AddEntry(Wh,"W","l" ); leg->AddEntry(Phh,"#gamma","l" ); leg->Draw("same"); aCan->cd(1); TH1D* DivPhh = Phh->Clone(); DivPhh->Divide(Zh); TH1D* DivWh = Wh->Clone(); DivWh->Divide(Zh); DivPhh->Draw(); DivWh->Draw("same"); }