double Prediction::GetLimitedRatio(TH1D* h1, TH1D* h2, float min, float max, bool binomial, float &relerror){ if(h1->GetNbinsX() != h2->GetNbinsX()){cout << "GetIntegral ERROR! " << endl; exit(-1);} TH1D* h1cp = h1->Clone("h1cp"); TH1D* h2cp = h2->Clone("h2cp"); for(int i=1; i<=h1cp->GetNbinsX(); ++i){ if(h1cp->GetBinLowEdge(i) <min || h1cp->GetBinLowEdge(i)+h1cp->GetBinWidth(i) >max){ h1cp->SetBinContent(i, 0); h1cp->SetBinError(i, 0); h2cp->SetBinContent(i, 0); h2cp->SetBinError(i, 0); } } TH1D* h1cp_2 = GetScaledHisto(h1cp, 1, 0, h1cp->GetNbinsX()); TH1D* h2cp_2 = GetScaledHisto(h2cp, 1, 0, h1cp->GetNbinsX()); TH1D* r = h1cp_2->Clone("r"); r->Divide(h1cp_2, h2cp_2, 1, 1, binomial? "B":""); *fLogStream << "Getting Limited Ratio for " << h1->GetName() << " " << h2->GetName() << endl; *fLogStream << ">>> ratio = " << r->GetBinContent(1) << " pm " << r->GetBinError(1) << endl; if(fDoRatioStatErr){ relerror = r->GetBinError(1)/r->GetBinContent(1); } double ratio = r->GetBinContent(1); delete h1cp; delete h2cp; delete h1cp_2; delete h2cp_2; delete r; return ratio; }
void MCefficiency(TString inputmc, TString outputfile, TString tfend, TString selmcgen, TString cut, TString weight, Float_t centmin, Float_t centmax) { Float_t hiBinMin,hiBinMax; hiBinMin = centmin*2; hiBinMax = centmax*2; selmcgen = Form("%s&&hiBin>=%f&&hiBin<%f",selmcgen.Data(),hiBinMin,hiBinMax); cut = Form("%s&&hiBin>=%f&&hiBin<%f",cut.Data(),hiBinMin,hiBinMax); TFile* infMC = new TFile(inputmc.Data()); TTree* ntMC = (TTree*)infMC->Get("ntDkpi"); ntMC->AddFriend("ntHi"); ntMC->AddFriend("ntSkim"); TTree* ntGen = (TTree*)infMC->Get("ntGen"); ntGen->AddFriend("ntHi"); ntGen->AddFriend("ntSkim"); TH1D* hPtMC = new TH1D("hPtMC","",nPtBins,ptBins); TH1D* hPtGen = new TH1D("hPtGen","",nPtBins,ptBins); ntMC->Project("hPtMC","Dpt",TCut(weight)*(TCut(cut.Data())&&"(Dgen==23333)")); divideBinWidth(hPtMC); ntGen->Project("hPtGen","Gpt",TCut(weight)*(TCut(selmcgen.Data()))); divideBinWidth(hPtGen); TH1D* hEff = (TH1D*)hPtMC->Clone("hEff"); hEff->Divide(hPtGen); TFile* fout=new TFile(Form("%s_cent_%.0f_%.0f_%s.root",outputfile.Data(),centmin,centmax,tfend.Data()),"recreate"); fout->cd(); hEff->Write(); fout->Close(); }
TH1D* plot (std::string num, std::string den,std::vector<TFile*>& tfiles,std::vector<double>& weights) { double weightTot = 0.0; for ( int i = 0; i<weights.size(); i++) { weightTot+=weights[i]; } std::string name = num; name+="NEW"; TH1D* hNum = (TH1D*)tfiles[0]->Get(num.c_str()); TH1D* HNum = (TH1D*)hNum->Clone(name.c_str()); HNum->Sumw2(); name=den; name+="NEW"; TH1D* hDen = (TH1D*)tfiles[0]->Get(den.c_str()); TH1D* HDen = (TH1D*)hDen->Clone(name.c_str()); HDen->Sumw2(); for (int i=1; i<tfiles.size(); i++) { TH1D* htempNum = (TH1D*)tfiles[i]->Get(num.c_str()); TH1D* htempDen = (TH1D*)tfiles[i]->Get(den.c_str()); HNum->Add(htempNum,weights[i]/weightTot); HDen->Add(htempDen,weights[i]/weightTot); } name = num; name+="Div"; TH1D* hDiv = (TH1D*)HNum->Clone(name.c_str()); //hDiv->Sumw2(); hDiv->Divide(HDen); return hDiv; }
void plotter::draw_purity(TH1D* numerator_, TH1D* denominator_, TString file_name){ TH1D* numerator = (TH1D*) numerator_->Clone("numerator"); TH1D* denominator = (TH1D*) denominator_->Clone("denominator"); TH1D* purity = numerator; // just to set correct binning purity->Divide(numerator, denominator, 1., 1., "B"); purity->SetTitle(" "); purity->GetXaxis()->SetTitle("m_{gen}"); purity->GetYaxis()->SetTitle("purity"); purity->GetYaxis()->SetRangeUser(0,1); purity->GetXaxis()->SetTitleSize(0.05); purity->GetYaxis()->SetTitleSize(0.05); purity->GetXaxis()->SetTitleOffset(0.9); purity->GetYaxis()->SetTitleOffset(0.8); purity->GetXaxis()->SetNdivisions(505); purity->GetYaxis()->SetNdivisions(505); purity->SetMarkerStyle(20); purity->SetMarkerSize(0.8); purity->SetLineColor(1); TCanvas *c= new TCanvas("Purity","",600,600); gPad->SetLeftMargin(0.15); TGaxis::SetMaxDigits(3); purity->Draw("E1"); gPad->RedrawAxis(); c->SaveAs(directory + file_name + ".pdf"); delete c; }
TH1* processFile(TString fname, double scaleFactor){ static int hcounter=0; cout<<"Doing fname="<<fname<<endl; TFile *_file2 = TFile::Open(fname); PS->cd(); TString plot = "lLV[0].lpfIso:lLV[0].fP.Eta()"; TString hname = Form("h%i",hcounter); jets2p->Draw(plot +" >> " + hname+"(24,-3,3,100,0,2)","","qn"); TH2D *aux = (TH2D*)gDirectory->Get(hname); //aux->Scale(scaleFactor); TH1D * ss = aux->ProjectionX(hname+"ss",1,10); // signal region TH1D * ni = aux->ProjectionX(hname+"ni",16,100);// nonIso region (use 11 //cout<<"h="<<hcounter<<" ss="<<ss->GetEntries()<<" ni="<<ni->GetEntries()<<endl; TString statis = Form("( %i / %i )",(int)ss->GetEntries(),(int)ni->GetEntries()); ss->Divide(ni); ss->GetYaxis()->SetTitle(TString("N_{signal}/N_{nonIso}")+statis); ss->GetXaxis()->SetTitle("#eta"); hcounter++; return ss; }
TH1D* Prediction::GetRatio(TH1D* h1, TH1D* h2, int mergenbins, bool binomial){ // compute Zll/Photon ratio *fLogStream << "------------------------------------------------------------------------" << endl; *fLogStream << "Compute ratio between " << h1->GetName() << " and " << h2->GetName() << endl; if(h1==0 || h2==0 ){ cout << "GetMCZnunuToPhotonRatio: received 0 pointer!" << endl; exit(-1); } // GetScaled histos with only one bin and probagated errors: stat error and error on scale factor TH1D *currh1 = GetScaledHisto(h1, 1, 0, mergenbins); TH1D *currh2 = GetScaledHisto(h2, 1, 0, mergenbins); TString name = h1->GetName(); name += "_"; name += h2->GetName(); name += "_Ratio"; TH1D *ratio = (TH1D*) currh1->Clone(name); ratio->Divide(currh1, currh2, 1,1, binomial?"B":""); // binomial errors ratio->SetLineColor(kBlack); ratio->SetMarkerColor(kBlack); ratio->SetMarkerStyle(4); if(fWriteToFile){ ratio ->Write(); } delete currh1; delete currh2; return ratio; }
void CheckTaggEffButVsH() { Char_t Name[256]; Char_t *VarName; //Connect to all existing histograms RootFileBut = new TFile(Str_RootFilesBut); TH2D *hBut2D = (TH2D*)gROOT->FindObject("hTaggerTime"); RootFileH = new TFile(Str_RootFilesH); TH2D *hH2D = (TH2D*)gROOT->FindObject("hTaggerTime"); gROOT->cd(); TH1D *hButBg = hBut2D->ProjectionY("TempBut1D", 800, 950); TH1D *hHBg = hH2D->ProjectionY("TempH1D", 800, 950); TCanvas *c1 = new TCanvas(); gStyle->SetPalette(1); c1->Divide(2,2); c1->cd(1); hButBg->Draw(""); c1->cd(2); hHBg ->Draw(""); c1->cd(3); delete gROOT->FindObject("Diff"); TH1D *hDiff = (TH1D*) hButBg->Clone("Diff"); hDiff->Divide(hHBg); hDiff->Draw(); RootFileBut->Close(); RootFileH->Close(); printf("Finished.\n"); }
void merge(){ TVectorD Nevent; Nevent.ResizeTo(nbin); Nevent.Zero(); // TVectorD totmultall; totmultall.ResizeTo(nbin); totmultall.Zero(); // TVectorD avgmultall; avgmultall.ResizeTo(nbin); avgmultall.Zero(); TVectorD tottrk; tottrk.ResizeTo(nbin); tottrk.Zero(); // TVectorD totptall; totptall.ResizeTo(nbin); totptall.Zero(); // TVectorD totetaall; totetaall.ResizeTo(nbin); totetaall.Zero(); TVectorD avgtrk; avgtrk.ResizeTo(nbin); avgtrk.Zero(); // TVectorD avgmult; avgmult.ResizeTo(nbin); TH2F* s[nbin]; TH2F* b[nbin]; for(int ibin=0;ibin<nbin;ibin++){ s[ibin] = new TH2F(Form("s_%d",ibin),Form("signal",ibin),detastep,detamin,detamax,dphistep,dphimin,dphimax); s[ibin]->Sumw2(); b[ibin] = new TH2F(Form("b_%d",ibin), "background",detastep,detamin,detamax,dphistep,dphimin,dphimax); b[ibin]->Sumw2(); } TFile *fout = new TFile(Form("Anav3_merged.root"),"Recreate"); TFile *f[nFileAll]; for(int ifile=; ifile<63; ifile++){ f[ifile] = TFile::Open(Form("%s/Anav3_%d.root",outdir.Data(),ifile)); if(!f[ifile]) continue; TVectorD* Nevent_t = (TVectorD*)f[ifile]->Get(Form("Nevent")); // TVectorD* totmultall_t = (TVectorD*)f[ifile]->Get(Form("totmultall")); TVectorD* tottrk_t = (TVectorD*)f[ifile]->Get(Form("tottrk")); // TVectorD* totptall_t = (TVectorD*)f[ifile]->Get(Form("totptall")); // TVectorD* totetaall_t = (TVectorD*)f[ifile]->Get(Form("totetaall")); for(int ibin=0;ibin<nbin;ibin++){ // totptall[ibin] += (*totptall_t)[ibin]; // totetaall[ibin] += (*totetaall_t)[ibin]; Nevent[ibin] += (*Nevent_t)[ibin]; // totmultall[ibin] += (*totmultall_t)[ibin]; tottrk[ibin] += (*tottrk_t)[ibin]; TH1D* s_t = (TH1D*)f[ifile]->Get(Form("signal_%d",ibin)); TH1D* b_t = (TH1D*)f[ifile]->Get(Form("background_%d",ibin)); s[ibin]->Add(s_t); b[ibin]->Add(b_t); } f[ifile]->Close(); } for(int ibin=0;ibin<nbin;ibin++){ avgtrk[ibin] = tottrk[ibin]/Nevent[ibin]; TH1D* hr = (TH1D*)s[ibin]->Clone("hr"); hr->Divide(b[ibin]); hr->Scale(b[ibin]->GetBinContent(b[ibin]->FindBin(0,0))); fout->cd(); Nevent.Write("Nevent"); avgtrk.Write("avgtrk"); TDirectory *dir0 = (TDirectory*)fout->mkdir(Form("D_%d",ibin)); dir0->cd(); s[ibin]->Write("s"); b[ibin]->Write("b"); hr->Write(); } }
TH1D* GetRawCorrFunc1D_ratio(int itrg, int jass) { TH1D* hsignalphi = GetRawSignal1D(itrg,jass); TH1D* hcorrphi = (TH1D*)hsignalphi->Clone(Form("corrphi_trg%d_ass%d",itrg,jass)); hcorrphi->SetYTitle("C(#Delta#phi)"); TH1D* hbackphi = GetRawBackground1D(itrg,jass); hcorrphi->Divide(hbackphi); float max = hcorrphi->GetBinContent(hcorrphi->GetMaximumBin()); // hcorrphi->SetAxisRange(ymin,max*1.3,"Y"); return hcorrphi; }
void compareOldandNew() { TCanvas * c1 = new TCanvas("c1","c1",800,600); TLatex lat; int centBounds[6] = {60,80,100,120,140,200}; for(int i = 0 ; i<5; i++){ const char * histName = "pPbPbp_FF"; TFile * fold = TFile::Open("FragmentationFunctionsUE2_nominal.root","read"); TFile * fnew = TFile::Open("FragmentationFunctionsUE2.root","read"); TH1D * num = (TH1D*)fnew->Get(Form("%s_%d_%d",histName,centBounds[i],centBounds[i+1])); TH1D * den = (TH1D*)fold->Get(Form("%s_%d_%d",histName,centBounds[i],centBounds[i+1])); //den->Add(num); num->Divide(den); //num->Scale(2); num->GetYaxis()->SetTitle("(no L2 residual)/(Nominal)"); num->GetYaxis()->SetRangeUser(0.7,1.3); num->GetXaxis()->SetTitle("p_{T}"); num->GetXaxis()->SetRangeUser(0.5,200); num->Print("All"); num->Draw(); lat.DrawLatex(1,1.2,Form("%d < p_{T}^{jet} < %d",centBounds[i],centBounds[i+1])); c1->SetLogx(); c1->SaveAs(Form("diffPlots/noL2Residual_%d_%d.png",centBounds[i],centBounds[i+1])); c1->SaveAs(Form("diffPlots/noL2Residual_%d_%d.pdf",centBounds[i],centBounds[i+1])); fnew->Close(); fold->Close(); } /*const char * histName = "PbPbTrackSpectrum_0_5"; TFile * fnew = TFile::Open("Spectra_Jun9_noChi2Cut.root","read"); TFile * fold = TFile::Open("Spectra_Jun9_withChi2Cut.root","read"); TH1D * num = (TH1D*)fnew->Get(histName); TH1D * den = (TH1D*)fold->Get(histName); //den->Add(num); num->Divide(den); //num->Scale(2); num->GetYaxis()->SetTitle("(No Chi2)/(With Chi2)"); num->GetYaxis()->SetRangeUser(0.7,1.5); num->GetXaxis()->SetRangeUser(0.7,350); num->Print("All"); num->Draw(); c1->SetLogx(); c1->SaveAs("plots/comparisonPlots/Chi2CutTest_PbPb_0_5.png"); c1->SaveAs("plots/comparisonPlots/Chi2CutTest_PbPb_0_5.pdf"); */ //c1->SaveAs("plots/comparisonPlots/ppChargeFraction2.C"); }
TH1D* makeRatioHist(TH1D& Hist1, TH1D& Hist2, char* name="CaloJetPtRatio2over1", double maxX=100.0) { TH1D* hist = Hist2.Clone(name); TH1D* temphist = Hist1.Clone("temphist"); //temphist->Add( &Hist2, -1); hist->Divide(temphist); hist->GetXaxis()->SetTitle("jet p_{T} (GeV/c)"); hist->SetMinimum(0.0); if(maxX > 110.0) hist->SetMaximum(0.35); else hist->SetMaximum(0.3); hist->GetXaxis()->SetRangeUser(0,maxX); delete temphist; return hist; }
void SaveClosure(TH1D* prediction, TH1D* expectation, TDirectory* Folder) // prediction durch expectation { TH1D* Closure = (TH1D*) prediction->Clone(); Closure->Divide(prediction,expectation,1,1,"B"); TString title = prediction->GetTitle(); title +="_closure"; // title = "#mu & e Control-Sample Ratio in Search Bins; Search bins; #mu / e CS"; Closure->SetTitle(title); title = prediction->GetName(); title+="_closure"; Closure->SetName(title); Folder->cd(); Closure->Write(); }
void mytestreweight(){ TFile*finput=new TFile("fworking.root"); TH1D*hBPtFONLL=(TH1D*)finput->Get("hBPt"); TH1D*hDPtFONLL=(TH1D*)finput->Get("hDPt"); TH2D*hD=(TH2D*)finput->Get("hD"); hD->SetXTitle("B p_{T} (GeV/c)"); hD->SetYTitle("D^{0} p_{T} (GeV/c)"); hBPtFONLL->SetXTitle("B p_{T} (GeV/c)"); hDPtFONLL->SetXTitle("D p_{T} (GeV/c)"); TH2D *hDreweight = (TH2D*)hD->Clone("hDreweight"); TH1D *hBPtPythia = hD->ProjectionX("hBPtPythia"); TH1D *hDPtPythia = hD->ProjectionY("hDPtPythia"); for (int x=1;x<=hDreweight->GetNbinsX()+1;x++){ //loop over the B pt bins if (hBPtPythia->GetBinContent(x)==0) continue; double ratio = hBPtFONLL->GetBinContent(x)/hBPtPythia->GetBinContent(x); // in each pt bin we calculate the ratio of pythiaB/FONLLB for (int y=1;y<=hDreweight->GetNbinsY()+1;y++){ //loop over the D pt bins double ratio2 = ratio; //copy the ratio for each B bin double val = hDreweight->GetBinContent(x,y)*ratio2; double valError = hDreweight->GetBinError(x,y)*ratio2; hDreweight->SetBinContent(x,y,val); hDreweight->SetBinError(x,y,valError); } } TH1D *hBPtPythiaReweight = hDreweight->ProjectionX("hBPtPythiaReweight"); TH1D *hDPtPythiaReweight = hDreweight->ProjectionY("hDPtPythiaReweight"); hBPtPythiaReweight->Divide(hBPtFONLL); TCanvas*canvas=new TCanvas("canvas","canvas",1000,500); canvas->SetLogy(); canvas->Divide(3,1); canvas->cd(1); hBPtFONLL->Draw(); canvas->cd(2); hBPtPythia->Draw(); canvas->cd(3); hBPtPythiaReweight->Draw(); }
//======================== void PlotRatio1D(Int_t iEff, Int_t iVar){ Char_t name[100]; sprintf(name, "c1_%sEff_%s", effName[iEff], varName[iVar]); TCanvas *c1 = new TCanvas(name, name); sprintf(name, "hRatio_%sEff_%s", effName[iEff], varName[iVar]); TH1D *hRatio = (TH1D *) hEffTP[iEff][iVar]->Clone(name); hRatio->Divide(hEffMCTruth1D[iEff][iVar]); hRatio->SetMarkerStyle(20); hRatio->SetMinimum(0.); hRatio->SetMaximum(1.5); hRatio->Draw("p"); sprintf(name, "Figures/ratio_%sEff_%s.pdf", effName[iEff], varName[iVar]); c1->Print(name); }
void quickDphi() { TH1::SetDefaultSumw2(); TFile *pAFile = TFile::Open("gammaJets_pA_Data.root"); TTree *jets = (TTree*)pAFile->Get("jetTree"); jets->AddFriend("photonTree","gammaJets_pA_Data.root"); TH1D *hfp20 = new TH1D("hfp20",";#Delta #phi_{J#gamma}", 50, 0, TMath::Pi()); TH1D *hfl20 = (TH1D*)hfp20->Clone("hfl20"); TCut anaCut = "photonTree.hadronicOverEm<0.1 && abs(photonTree.eta)<1.44 && abs(jetTree.eta)<1.6 && jetTree.pt>30 && photonTree.ecalRecHitSumEtConeDR04 <4.2 && photonTree.hcalTowerSumEtConeDR04 < 2.2 && photonTree.trkSumPtHollowConeDR04 < 2"; // jets->Project("hfl20","dPhi",anaCut&&"(photonTree.HFplusEta4+photonTree.HFminusEta4 < 20)"); // jets->Project("hfp20","dPhi",anaCut&&"(photonTree.HFplusEta4+photonTree.HFminusEta4 > 20)"); jets->Project("hfl20","dPhi",anaCut&&"(photonTree.pt > 40)"); jets->Project("hfp20","dPhi",anaCut&&"(photonTree.pt > 60)"); hfp20->Scale(1./hfp20->GetEntries()); hfl20->Scale(1./hfl20->GetEntries()); TCanvas *c1 = new TCanvas(); c1->SetLogy(); // hfp20->Draw(); // hfp20->GetXaxis()->CenterTitle(); // hfl20->SetMarkerColor(kBlue); // hfl20->SetLineColor(kBlue); // hfl20->Draw("same"); // TLegend *leg = new TLegend(0.15,0.5,0.5,0.8); // leg->SetFillColor(0); // // leg->AddEntry(hfp20,"E^{HF |#eta|>4} > 20","l"); // // leg->AddEntry(hfl20,"E^{HF |#eta|>4} < 20","l"); // leg->AddEntry(hfp20,"#gamma p_{T} > 60GeV","l"); // leg->AddEntry(hfl20,"#gamma p_{T} > 40GeV","l"); // leg->Draw(); TH1D *ratio = (TH1D*)hfp20->Clone("ratio"); //ratio->SetYTitle("(E^{HF |#eta|>4} > 20)/(E^{HF |#eta|>4} < 20)"); ratio->Divide(hfp20,hfl20,1,1); ratio->Draw(); }
TH1D *HistoRatio (TH1D *hisNum, TH1D *hisDen){ //Graph Ratio Clone TH1D *Ratio; Ratio = (TH1D*)hisNum->Clone(); Ratio->Divide(hisDen); for(int ibin=1;ibin<=Ratio->GetNbinsX();ibin++) { if (Ratio->GetBinContent(ibin) == 0.0 ) { Ratio->SetBinContent(ibin, 1.0); Ratio->SetBinError(ibin, 0.0); } } Ratio->SetFillColor(0); Ratio->SetLineColor(kGray+2); // Ratio->SetLineColor(kMagenta-5); Ratio->SetLineWidth(1); Ratio->SetTitle(""); Ratio->GetYaxis()->SetTitle("Obs/Exp"); Ratio->GetYaxis()->CenterTitle(); Ratio->GetYaxis()->SetTitleFont(42); Ratio->GetYaxis()->SetTitleSize(0.135); Ratio->GetYaxis()->SetTitleOffset(0.28); Ratio->GetYaxis()->SetLabelFont(42); Ratio->GetYaxis()->SetLabelSize(0.115); Ratio->GetYaxis()->SetNdivisions(402); Ratio->GetXaxis()->SetTitle("CSVv2 bin"); Ratio->GetXaxis()->SetNdivisions(509); //(402) Ratio->GetXaxis()->SetTitleOffset(1.1); Ratio->GetXaxis()->SetTitleFont(42); Ratio->GetXaxis()->SetTitleSize(0.16); Ratio->GetXaxis()->SetTitleFont(42); Ratio->GetXaxis()->SetLabelSize(0.14); Ratio->SetMinimum(0.4); Ratio->SetMaximum(1.6); return Ratio; }
void makeWeightDistribution(TH1D *mcScenario, vector<double> & dataPileupDistribution, vector<double> & result) { std::cout<<"does it even start?"<<std::endl; Int_t nbins = mcScenario->GetNbinsX(); std::cout<<"splitter"<<std::endl; Int_t ndatabins = dataPileupDistribution.size(); std::cout<<"two more lines"<<std::endl; TH1D *hweights = new TH1D("hweights", "hweights", nbins, mcScenario->GetXaxis()->GetXmin(), mcScenario->GetXaxis()->GetXmax()); //std::cout<<" ****************************************** 1"<<std::endl; for(int ibin=0; ibin<nbins; ++ibin) { //std::cout<<" ****************************************** 2"<<std::endl; if(ibin<ndatabins) hweights->SetBinContent(ibin+1, dataPileupDistribution[ibin]); else hweights->SetBinContent(ibin+1, 0.); } // Check integrals, make sure things are normalized float deltaH = hweights->Integral(); if( fabs(1.0 - deltaH)>0.02 ) { // *OOPS*... hweights->Scale( 1.0/hweights->Integral() ); } float deltaMC = mcScenario->Integral(); if( fabs(1.0 - deltaMC)>0.02 ) { mcScenario->Scale( 1.0/mcScenario->Integral() ); } //std::cout<<" ****************************************** 3"<<std::endl; hweights->Divide( mcScenario ); // so now the average weight should be 1.0 for(int ibin=0; ibin<nbins; ++ibin) { //std::cout<<" ****************************************** 4"<<std::endl; result.push_back(hweights->GetBinContent(ibin+1)); } //std::cout<<" ****************************************** 5"<<std::endl; delete hweights; //std::cout<<" ****************************************** 6"<<std::endl; return; }
TH1D* momResHist(TFile* f, int i) { Double_t xbins[33] = {0,0.2,0.4,0.6,0.8, 1.0,1.6,2.2,2.8,3.4, 4.4,5.4,6.0,8.0,10.0, 12.0,14.0,18.0,22.0,26.0, 30.0,36.0,42.0,50.0,55.0, 60.0,70.0,80.0,100.0,120.0, 140.0,160.0,200.0}; TH3F *hRes3D = (TH3F*) f->Get("trkEffAnalyzer/hresStoR3D"); double feta = 2.4; int binMaxEta = hRes3D->GetXaxis()->FindBin(feta); int binMinEta = hRes3D->GetXaxis()->FindBin(-1.0*feta); hRes3D->GetXaxis()->SetRange(binMinEta,binMaxEta); TH2D *hRes2D = (TH2D*) hRes3D->Project3D("zy"); // zy: rec-> y axis, sim -> x axis hRes2D->SetName("hRes2D"); hRes2D->FitSlicesY(0,0,-1,10); TH1D *h1 = (TH1D*)gDirectory->Get("hRes2D_1"); TH1D *h2 = (TH1D*)gDirectory->Get("hRes2D_2"); h1->Rebin(32,Form("h1new%d",i),xbins); h2->Rebin(32,Form("h2new%d",i),xbins); TH1D* h1new = (TH1D*) gDirectory->Get(Form("h1new%d",i)); TH1D* h2new = (TH1D*) gDirectory->Get(Form("h2new%d",i)); TH1D *momres = (TH1D*) h2new->Clone("momres"); momres->SetName(Form("momres_%d",i)); momres->SetMaximum(0.15); momres->SetMinimum(0.0); momres->SetTitle("Momentum resolution;p_{T} [GeV/c]"); momres->SetStats(0); momres->SetMarkerStyle(20); momres->Divide(h1new); return momres; }
void JetChemistry_Gen_MB() { TFile* f_ks = new TFile("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PythiaReco_Minbias_2760GeV/unmerged/PythiaReco_Minbias_2760GeV_TuneZ2_MB_TESTKs_ffrom0_fto2_vtxmin-15.0_vtxmax15.0_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root"); TFile* f_la = new TFile("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PythiaReco_Minbias_2760GeV/unmerged/PythiaReco_Minbias_2760GeV_TuneZ2_MB_TESTLambda_ffrom0_fto2_vtxmin-15.0_vtxmax15.0_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root"); // TFile* f_ks = new TFile("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PythiaReco_Minbias_2760GeV/merged/PythiaReco_Minbias_2760GeV_TuneZ2_Pt120_TESTKs_ffrom0_fto10_vtxmin-15.0_vtxmax15.0_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root"); // TFile* f_la = new TFile("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PythiaReco_Minbias_2760GeV/merged/PythiaReco_Minbias_2760GeV_TuneZ2_Pt120_TESTLambda_ffrom0_fto10_vtxmin-15.0_vtxmax15.0_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root"); TH1D* hJetPt_ks = f_ks->Get("ptall_ass"); TH1D* hJetPt_la = f_la->Get("ptall_ass"); hJetPt_ks->Rebin(2); hJetPt_la->Rebin(2); TCanvas* c1 = new TCanvas("c1","",550,500); TH1D* hRatio = (TH1D*)hJetPt_la->Clone("ratio"); hRatio->Divide(hJetPt_ks); hRatio->Scale(0.5); hRatio->Draw("PE"); }
void closureTesterFSR(void) { TString REGIME = ""; //_corr //2D case TFile* g = new TFile("../Inputs/unfold/unfoldData_HLT_Double_2D_NoTRM.root"); g->cd(); TH1F* unfolded = (TH1F*)gDirectory->Get("hunfolded"); //FSR correction TFile* gg = new TFile("../Inputs/FSR/BinByBin.root"); gg->cd(); TH1F* FSRcorr_num = (TH1F*)gDirectory->Get("hpostFSR2"); TH1F* FSRcorr_den = (TH1F*)gDirectory->Get("hpreFSR2"); TH1F* FSRcorr = (TH1F*)FSRcorr_num->Clone(); FSRcorr->Divide(FSRcorr_num,FSRcorr_den); for (int i = 0; i < 132; i++) { unfolded->SetBinContent(i+1,unfolded->GetBinContent(i+1)*FSRcorr->GetBinContent(i+1)); } unfolded->SetMarkerStyle(22); unfolded->GetXaxis()->SetTitle("Bin number"); unfolded->GetYaxis()->SetTitle("Events"); unfolded->Draw("hist"); TH1D* other = (TH1D*)unfolded->Clone(); other->SetMarkerStyle(22); other->SetMarkerColor(kRed); other->SetLineColor(kRed); other->Draw("Psame"); TCanvas* c = new TCanvas(); c->cd(); TH1D* ratio = (TH1D*)unfolded->Clone(); ratio->Divide(other,unfolded); ratio->SetMarkerStyle(22); ratio->GetXaxis()->SetTitle("N_{unfolded}/N_{preunfolded}"); ratio->GetXaxis()->SetTitle("Bin number"); ratio->Draw("P"); }
TH1D* GetRatio(TH1D* hEM,TH1D* hME,double xmin, double xmax) { TH1D* ratio = (TH1D*)hEM->Clone("ratio"); ratio->Divide(hME); // ratio->GetYaxis()->SetTitle("Ratio"); //ratio->SetTitleFont(64); ratio->GetYaxis()->SetTitle("Ratio"); ratio->GetYaxis()->SetTitleSize(0.1); ratio->GetYaxis()->SetTitleOffset(0.3); ratio->GetYaxis()->CenterTitle(); // ratio->SetTitleSize(0.1); ratio->GetXaxis()->SetRangeUser(xmin,xmax); ratio->SetLineColor(kBlack); ratio->GetYaxis()->SetRangeUser(0,2); ratio->SetLineWidth(2); ratio->SetMarkerStyle(8); ratio->SetMarkerSize(0.7); ratio->SetMarkerColor(kBlack); ratio->GetXaxis()->SetTitle("M_{coll} (GeV)"); ratio->GetXaxis()->SetTitleSize(0.15); ratio->GetXaxis()->SetTitleOffset(0.8); ratio->GetXaxis()->SetLabelOffset(); ratio->GetYaxis()->SetLabelSize(0.1); ratio->GetYaxis()->SetNdivisions(5); ratio->GetXaxis()->SetLabelSize(0.1); ratio->GetXaxis()->SetRangeUser(xmin,xmax); for (int i=1; i<=hEM->GetXaxis()->FindBin(99); i++){ double n = hEM->GetBinContent(i); double m = hME->GetBinContent(i); double deltaN = hEM->GetBinError(i); double deltaM = hME->GetBinError(i); double err = (1./m)*TMath::Sqrt(TMath::Power(deltaN,2)+TMath::Power(n*deltaM/m,2)); ratio->SetBinError(i,err); } for (int i=hEM->GetXaxis()->FindBin(151); i<=hEM->GetXaxis()->GetNbins(); i++){ double n = hEM->GetBinContent(i); double m = hME->GetBinContent(i); double deltaN = hEM->GetBinError(i); double deltaM = hME->GetBinError(i); double err = (1./m)*TMath::Sqrt(TMath::Power(deltaN,2)+TMath::Power(n*deltaM/m,2)); ratio->SetBinError(i,err); } return ratio; }
void trksplit() { TFile* f = new TFile("../cfg/dihadroncorrelation_wsplit_real_cent010_mc.root"); TFile* f1 = new TFile("../cfg/dihadroncorrelation_wosplit_cent010_mc.root"); TH1D* hpt = (TH1D*)f->Get("corr_ana_HI/ptall_trg"); TH1D* hpt1 = (TH1D*)f1->Get("corr_ana_HI/ptall_trg"); hpt->SetMarkerStyle(20); hpt1->SetMarkerStyle(20); hpt->SetMarkerColor(4); hpt->Rebin(4); hpt1->Rebin(4); TCanvas* c = new TCanvas("c","c",500,450); hpt->SetAxisRange(0,5.0,"X"); hpt->Draw("PE"); hpt1->Draw("PESAME"); TH1D* hratio = (TH1D*)hpt->Clone("hratio"); hratio->Divide(hpt1); TCanvas* c1 = new TCanvas("c1","c1",500,450); hratio->Draw("PE"); }
void balanceMetVsAj(TString infname = "dj_HCPR-J50U-hiGoodMergedTracks_OfficialSelv2_Final0_120_50.root", TCut myCut = "cent<30", char *title = "",bool drawLegend = false, bool drawSys = true ) { // =========================================================== // Get Input // =========================================================== TFile *inf = new TFile(infname); TTree *t = (TTree*)inf->Get("ntjt"); t->SetAlias("metxMergedAll","(metOutOfConex0+metOutOfConex1+metOutOfConex2+metOutOfConex3+metOutOfConex4+metOutOfConex5)"); t->SetAlias("metxMerged0","(metOutOfConex0)"); t->SetAlias("metxMerged1","(metOutOfConex1)"); t->SetAlias("metxMerged2","(metOutOfConex2)"); t->SetAlias("metxMerged3","(metOutOfConex3)"); t->SetAlias("metxMerged4","(metOutOfConex4+metOutOfConex5)"); // =========================================================== // Analysis Setup // =========================================================== const int nBin = 5; double bins[nBin+1] = {0.5,1.0,1.5,4,8,1000}; int colors[5] = {kBlue-10,kYellow-7, kOrange-2,kGreen-5,kRed-3}; const int nBinAj = 4; double ajBins[nBinAj+1] = {0.0001,0.11,0.22,0.33,0.49999}; // Selection cut TCut evtCut = "nljet>120&&abs(nljetacorr)<2&&aljet>50&&abs(aljetacorr)<2&&jdphi>2./3*TMath::Pi()&&!maskEvt"; // TCut evtCut = "nljet>120&&abs(nljetacorr)<2&&aljet>50&&abs(aljetacorr)<2&&jdphi>3&&!maskEvt"; cout << "Sel evt: " << t->GetEntries(evtCut&&myCut) << endl; // =========================================================== // Find Average Weights // =========================================================== TH1D *hw[nBinAj]; float meanWt[nBinAj]; for ( int iaj = 0 ; iaj< nBinAj ; iaj++) { hw[iaj] = new TH1D(Form("hw_aj%d",iaj),"",1000,0,100); TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]); t->Draw(Form("weight>>hw_aj%d",iaj), evtCut&&myCut&&ajCut); meanWt[iaj] = hw[iaj]->GetMean(); cout << " <Weight>: " << meanWt[iaj] << endl; } // =========================================================== // Draw Weighted Averages // =========================================================== TH1D *ppos[nBin]; TH1D *pneg[nBin]; TH1D *pe[nBin]; for (int i=0;i<nBin;i++) { TH1D *h1 = new TH1D(Form("h1%d",i),"",nBinAj,ajBins); TH1D *h2 = new TH1D(Form("h2%d",i),"",nBinAj,ajBins); TH1D *he[nBinAj]; // ================================= // Get Weighted Mean for each Aj bin // ================================= h1->Sumw2(); h2->Sumw2(); t->Draw(Form("Aj>>h1%d",i), "weight"*(evtCut&&myCut)); t->Draw(Form("Aj>>h2%d",i), Form("((-weight*metxMerged%d))",i)*(evtCut&&myCut)); pe[i]=(TH1D*)h2->Clone(); pe[i]->SetName(Form("p%d",i)); pe[i]->Divide(h1); ppos[i] = new TH1D(Form("ppos%d",i),"",nBinAj,ajBins); ppos[i]->SetLineColor(1); ppos[i]->SetMarkerColor(colors[i]); ppos[i]->SetFillColor(colors[i]); ppos[i]->SetFillStyle(1001); pneg[i] = new TH1D(Form("pneg%d",i),"",nBinAj,ajBins); pneg[i]->SetLineColor(1); pneg[i]->SetMarkerColor(colors[i]); pneg[i]->SetFillColor(colors[i]); pneg[i]->SetFillStyle(1001); // ================================= // Caculated Stat Error of the Mean // ================================= cout << "Stat Error for pt bin " << i << ": "; for ( int iaj = 0 ; iaj< nBinAj ; iaj++) { he[iaj] = new TH1D(Form("he%d_aj%d",i,iaj),"",100,-200,200); TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]); t->Draw(Form("((metxMerged%d))>>he%d_aj%d",i,i,iaj), "weight" * evtCut&&myCut&&ajCut); float theError = he[iaj]->GetRMS()/ (sqrt(he[iaj]->GetEntries())); cout << theError << " "; pe[i]->SetBinError(iaj+1, theError); } cout << endl; } // Stack for (int i=nBin-1;i>=0;i--) { for(int iaj = 0 ; iaj< nBinAj ; iaj++) { double posVal=0, negVal=0; double posValErr=0, negValErr=0; if (i!=nBin-1) { posVal = ppos[i+1]->GetBinContent(iaj+1); posValErr = ppos[i+1]->GetBinError(iaj+1); negVal = pneg[i+1]->GetBinContent(iaj+1); negValErr = pneg[i+1]->GetBinError(iaj+1); } if (pe[i]->GetBinContent(iaj+1)<0) { negVal+=pe[i]->GetBinContent(iaj+1); negValErr=pe[i]->GetBinError(iaj+1); posValErr=0; } else if (pe[i]->GetBinContent(iaj+1)>0) { posVal+=pe[i]->GetBinContent(iaj+1); posValErr=pe[i]->GetBinError(iaj+1); negValErr=0; } ppos[i]->SetBinContent(iaj+1,posVal); ppos[i]->SetBinError(iaj+1,posValErr); pneg[i]->SetBinContent(iaj+1,negVal); pneg[i]->SetBinError(iaj+1,negValErr); } } TH1D *pall; TH1D *pallE; TH1D *h1 = new TH1D(Form("hAll1"),"",nBinAj,ajBins); TH1D *h2 = new TH1D(Form("hAll2"),"",nBinAj,ajBins); h1->Sumw2(); h2->Sumw2(); t->Draw(Form("Aj>>hAll1"), "weight"*(evtCut&&myCut)); t->Draw(Form("Aj>>hAll2"), Form("((-weight*metxMergedAll))")*(evtCut&&myCut)); pall=(TH1D*)h2->Clone(); pall->SetName("pall"); pall->Divide(h1); // replace the sys error from pallE to pall TH1D *he[nBinAj]; cout << "Stat Error for All pt: "; for ( int iaj = 0 ; iaj< nBinAj ; iaj++) { he[iaj] = new TH1D(Form("heAll_aj%d",iaj),"",100,-200,200); TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]); t->Draw(Form("((metxMergedAll))>>heAll_aj%d",iaj), "weight" * evtCut&&myCut&&ajCut); float theError = he[iaj]->GetRMS()/ (sqrt(he[iaj]->GetEntries())); cout << theError << " "; pall->SetBinError(iaj+1, theError); } cout << endl; pall->SetXTitle("A_{J}"); pall->SetYTitle("<#slash{p}_{T}^{#parallel}> (GeV/c)"); pall->GetXaxis()->CenterTitle(); pall->GetYaxis()->CenterTitle(); pall->GetXaxis()->SetLabelSize(22); pall->GetXaxis()->SetLabelFont(43); pall->GetXaxis()->SetTitleSize(24); pall->GetXaxis()->SetTitleFont(43); pall->GetYaxis()->SetLabelSize(22); pall->GetYaxis()->SetLabelFont(43); pall->GetYaxis()->SetTitleSize(24); pall->GetYaxis()->SetTitleFont(43); pall->GetXaxis()->SetTitleOffset(1.8); pall->GetYaxis()->SetTitleOffset(2.4); pall->SetNdivisions(505); pall->SetAxisRange(-59.9,59.9,"Y"); pall->SetMarkerSize(1); pall->Draw("E"); float addSys = 0; if ( drawSys==1) addSys=0; // No sys error at this moment // ==================== // Finally Draw // ==================== for (int i=0;i<nBin;++i) { ppos[i]->SetLineWidth(1); ppos[i]->Draw("hist same"); pneg[i]->SetLineWidth(1); pneg[i]->Draw("hist same"); } // ==================== // Draw Statistical Error bars // ==================== for (int i=0;i<nBin;++i) { if ( i==0 ) drawErrorShift(ppos[i],-0.016, addSys); if ( i==1 || i==4) drawErrorShift(ppos[i],-0.008,addSys); if ( i==2 ) drawErrorShift(ppos[i],0.008,addSys); if ( i==3 ) drawErrorShift(ppos[i],0.016,addSys); if ( i==0 ) drawErrorShift(pneg[i],-0.016, addSys); if ( i==1 || i==4) drawErrorShift(pneg[i],-0.008,addSys); if ( i==2 ) drawErrorShift(pneg[i],0.008,addSys); if ( i==3 ) drawErrorShift(pneg[i],0.016,addSys); } pall->Draw("E same"); // ==================== // Draw Systematic Errors // ==================== if (drawSys == 1) { for(int i = 0; i < nBinAj; ++i){ double x = pall->GetBinCenter(i+1); double y = pall->GetBinContent(i+1); // Quote the difference between GEN and RECO in >8 Bin (20%) before adjusting eff as systematics double err = fabs(pe[nBin-1]->GetBinContent(i+1)*0.2); DrawTick(y,err,err,x,1,0.02,1); } } // ==================== // Draw Legend // ==================== TLegend *leg = new TLegend(0.10,0.68,0.70,0.96); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextFont(63); leg->SetTextSize(16); leg->AddEntry(pall,Form("> %.1f GeV/c",bins[0]),"pl"); for (int i=0;i<nBin;++i) { if (i!=nBin-1){ leg->AddEntry(ppos[i],Form("%.1f - %.1f GeV/c",bins[i],bins[i+1]),"f"); } else { leg->AddEntry(ppos[i],Form("> %.1f GeV/c",bins[i]),"f"); } } if (drawLegend) leg->Draw(); TLine * l0 = new TLine(0,0,0.5,0); l0->SetLineStyle(2); l0->Draw(); TLine * l1 = new TLine(0.0001,-10,0.0001,10); l1->Draw(); TText *titleText = new TText(0.3,30,title); titleText->Draw(); }
void plotEfficiency() { TCut PtCut="Pt>10"; TCut EtaCut ="abs(Eta)<2.5"; TCut Signal ="MatchedGen && MatchedGenFromWZ"; TCut Bkg ="(!MatchedGen || (MatchedGen && !MatchedGenFromWZ ))"; TCut barr = "abs(Eta)<1.479"; TCut endc = "abs(Eta)>1.550&&abs(Eta)<2.5"; TCut qcd ="(processID==11 || processID==12 || processID==13 || processID==28 || processID==53 || processID==68)"; TFile *_file2 = TFile::Open("Data/Gumbo/New/Gumbo_All.root"); TTree* g = _file2->Get("ElTree"); TFile *_file1 = TFile::Open("Data/WZ_3l/New/WZCSA07-WZ.root"); TTree* s = _file1->Get("ElTree"); TH1D* h1 = new TH1D("h1","",100,0,100); TH1D* h2 = new TH1D("h2","",100,0,100); TH1D* sig = new TH1D("sig","",100,0,100); h1->Sumw2(); h2->Sumw2(); TH1D* b1 = new TH1D("b1","",100,0,100); TH1D* b2 = new TH1D("b2","",100,0,100); b1->Sumw2(); b2->Sumw2(); TH1D* bkg = new TH1D("bkg","",100,0,100); TCut sig_preselection = PtCut && Signal && barr; TCut bkg_preselection = PtCut && Bkg && qcd && barr; // Barrel- Loose Id TCut eb_deta = "DeltaEtaVtx < 0.009"; TCut eb_dphi = "DeltaPhiVtx < 0.05"; TCut eb_sEE = "sqrt(CovEtaEta)<0.012"; TCut eb_trkIso = "(IsoKFTrackDR030 - IsoKFTrackDR005)/Pt<0.1"; TCut eb_EseedPout = "ESeed/Trk_P_Out>0.9"; // additional cut for Tight criteria TCut eb_EmHadIso = "(IsoEmCaloRecHitDR030 + IsoHadCaloRecHitDR030 - ESC)/ESC<0.18"; TCut eb_id = eb_deta && eb_dphi && eb_sEE && eb_trkIso && eb_EseedPout; // && eb_EmHadIso; s->Draw("Pt>>h1", sig_preselection); s->Draw("Pt>>h2", sig_preselection && eb_id); g->Draw("Pt>>b1", "weight"*(bkg_preselection)); g->Draw("Pt>>b2", "weight"*(bkg_preselection && eb_id)); sig->Divide(h2, h1, 1, 1, "B"); bkg->Divide(b2, b1, 1, 1, "B"); sig->SetMarkerColor(2); sig->SetMarkerStyle(21); sig->SetMarkerSize(1); bkg->SetMarkerColor(4); bkg->SetMarkerStyle(22); bkg->SetMarkerSize(1); gStyle->SetOptStat(0); sig->GetXaxis()->SetTitle("P_{T} (GeV)"); sig->GetYaxis()->SetTitle("Efficiency"); sig->Draw("E"); bkg->Draw("SAMEE"); TLegend* leg = new TLegend(0.5,0.5,0.8,0.8); leg->AddEntry(sig, "Signal electron"); leg->AddEntry(bkg, "mis-identified jet (Gumbo)"); leg->SetLineColor(0); leg->SetBorderSize(0); leg->Draw(); }
int RateVsVar(unsigned k=1, unsigned l=0){ TCanvas c1; std::string filename = Form("output/DoubleJet%u.root",k); std::string histname; std::string outname; std::string Xname; double xmin; double xmax; double step; if(true){ histname = "hMuVary"; outname = "RateOut/Mu.pdf"; Xname = "L1 muon p_{T} cut [GeV]"; xmin = 8; xmax = 18; step = 1; } if(true){ histname = "leadJetVary"; outname = "RateOut/JetPt.pdf"; Xname = "L1 lead jet p_{T} cut [GeV]"; xmin = 97; xmax = 120; step = 1; } if(false){ histname = "hsubleadJetVary"; outname = "RateOut/Jet2Pt.pdf"; Xname = "L1 sub-lead jet p_{T} cut [GeV]"; xmin = 30; xmax = 60; step = 1; } if(false){ histname = "hMjjVary"; outname = "RateOut/Mjj.pdf"; Xname = "L1 M_{jj} cut [GeV]"; xmin = 620; xmax = 750; step = 10; } TFile *f0 = new TFile(filename.c_str()); TH2D *h1 = (TH2D*)f0->Get(histname.c_str()); TH1D *hout = new TH1D("hout", "hout",20,0,2); TH1D *hdenum = new TH1D("hdenum", "hdenum",20,0,2); hout->Sumw2(); TH1D *h_rate = new TH1D("h_rate","h_rate",(int)(xmax-xmin)/step,xmin,xmax); h_rate->SetFillStyle(0); h_rate->GetXaxis()->SetTitle(Xname.c_str()); h_rate->GetYaxis()->SetTitle("L1 Rate @ 1.5e34cm^{-2}s^{-1} [kHz]"); for(unsigned i=(unsigned)xmin; i<=xmax; i+=(unsigned)step){ cout << i << endl; for(unsigned j=1; j<=(unsigned)h1->GetNbinsX(); ++j){ hout->SetBinContent(j,h1->Integral(j,j,h1->GetYaxis()->FindBin(i),h1->GetNbinsY()+1)); double error=0; h1->IntegralAndError(j,j,h1->GetYaxis()->FindBin(i),h1->GetNbinsY()+1,error); hout->SetBinError(j,error); hdenum->SetBinContent(j,h1->GetBinContent(j,1)); } hout->Divide(hdenum); //hout->Draw(); double rate1pt2=0; double rate1pt5=0; //hout->GetXaxis()->SetRangeUser(0.4,1.6); if(l==0){ TF1 *f1 = new TF1("f1","pol1",0.4,1.6); hout->Fit("f1","R"); rate1pt2 = f1->GetParameter(0) + f1->GetParameter(1)*1.2; rate1pt5 = f1->GetParameter(0) + f1->GetParameter(1)*1.5; } if(l==1){ TF1 *f1 = new TF1("f1","pol2",0.4,1.6); hout->Fit("f1","R"); rate1pt2 = f1->GetParameter(0) + f1->GetParameter(1)*1.2 + f1->GetParameter(2)*1.2*1.2; rate1pt5 = f1->GetParameter(0) + f1->GetParameter(1)*1.5 + f1->GetParameter(2)*1.5*1.5; } h_rate->SetBinContent(h_rate->GetXaxis()->FindBin(i),rate1pt5); //std::cout << "Rate @ 1.2e34: " << rate1pt2 << std::endl; //std::cout << "Rate @ 1.5e34: " << rate1pt5 << std::endl; } h_rate->Draw(); c1.Print(outname.c_str()); c1.Print(outname.c_str()); bool Proceed = true; while(Proceed){ std::string temp; cin >> temp; if(temp == "y") Proceed = false; } return k; }
void plottingmacro_IVF() { double fa = 0.46502; double fb = 0.53498; bool debug_ = true; // std::string path("Nov10thFall11Plots/"); // std::string path("Nov10Fall1160MTopSlimPlots/"); std::string path("Nov10Fall1160MTopIVFPlots_b/"); if(debug_) std::cout << "Init the style form setTDRStyle" << std::endl; setTDRStyle(); gStyle->SetErrorX(0.5); gROOT->ForceStyle(); initOptions(); if(debug_) std::cout << "Init the sample" << std::endl; // std::vector<Sample> s = Nov10thDiJetPtUpdatedSlimHistos(); //std::vector<Sample> s = Nov10Fall1160MTopSlimHistos(); std::vector<Sample> s = Nov10Fall1160MTopIVFHistos(); Sample data(1,"fake data","S1.root",0,true,1000); if(debug_) std::cout << "Init the data sample" << std::endl; for(size_t i=0;i< s.size();i++) if(s[i].data) {data=s[i];break;} if(debug_) std::cout << "Ls data sample" << std::endl; data.file()->ls(); if(debug_) std::cout << "Init the mc sample" << std::endl; for(size_t i=0;i< s.size();i++) s[i].dump(1,fa,fb); std::vector<std::string> names; if(debug_) std::cout << "Get List of Keys" << std::endl; TList * subs = data.file()->GetListOfKeys(); for(size_t i=0;i< subs->GetSize();i++) { TString nn = subs->At(i)->GetName(); if( nn.Contains(TRegexp("Count*")) ) continue; if(debug_) std::cout << "Get List of Keys in subdirs" << std::endl; TList * objs = ((TDirectoryFile *)data.file()->Get(subs->At(i)->GetName()))->GetListOfKeys(); for(size_t j=0;j< objs->GetSize();j++) { if(debug_) std::cout << "Name = " << subs->At(i)->GetName()+std::string("/") + objs->At(j)->GetName() << std::endl; names.push_back(subs->At(i)->GetName()+std::string("/") + objs->At(j)->GetName()); // std::cout << subs->At(i)->GetName() << "/" << objs->At(j)->GetName() << std::endl; //TODO: select plots via regexp } } if(debug_) std::cout << "Starting plotting" << std::endl; std::string process; for(size_t i = 0 ; i < names.size() ; i++) { std::map<std::string,TH1F *> grouped; TString n=names[i]; // if(!n.Contains(TRegexp("VlightRegionHZee/HiggsPtVlightRegionHZee"))) continue; // if(!n.Contains(TRegexp("VlightRegionHZee/ZPtVlightRegionHZee"))) continue; // if(!n.Contains(TRegexp("VlightRegionHZee"))) continue; // if(!n.Contains(TRegexp("ZSVRegionZmmSV"))) continue; // if(!n.Contains(TRegexp("ZSVRegionZeeSV"))) continue; // if(!n.Contains(TRegexp("ZSVRegionZcombSV"))) continue; // if(!n.Contains(TRegexp("ZSVPureRegionZcombSV"))) continue; // if(!n.Contains(TRegexp("ZSVTTbarPureRegionZcombSV"))) continue; if(!n.Contains(TRegexp("TTbarRegionZeeSVJets"))) continue; if(n.Contains(TRegexp("RegionHZcomb"))) process = "Z(l^{+}l^{-})H(b#bar{b})"; if(n.Contains(TRegexp("RegionHZmm"))) process = "Z(#mu^{+}#mu^{-})H(b#bar{b})"; if(n.Contains(TRegexp("RegionHZee"))) process = "Z(e^{+}e^{-})H(b#bar{b})"; if(debug_) std::cout << "Creating the Canvas" << std::endl; TCanvas *c = new TCanvas(); c->SetLogy(false); c->SetTitle(names[i].c_str()); if(debug_) std::cout << "Creating histograms" << std::endl; TH1F *hd = ((TH1F*)data.file()->Get(names[i].c_str())); hd->Sumw2(); Options o=options[names[i]]; // hd->Rebin(o.rebin); hd->SetMarkerStyle(20); hd->GetXaxis()->SetLabelOffset(99); hd->SetYTitle(o.yaxis.c_str()); double nbin = hd->GetNbinsX(); double min_bin = hd->GetXaxis()->GetXmin(); double max_bin = hd->GetXaxis()->GetXmax(); TH1F *hmc = new TH1F("hmc","hmc", nbin, min_bin, max_bin); hmc->SetFillColor(kWhite); hmc->Sumw2(); // hmc->Rebin(o.rebin); if(debug_) std::cout << "Creating the THStack and Legend" << std::endl; THStack * sta = new THStack("sta",hd->GetTitle()); TLegend * l = new TLegend(o.legendx1,o.legendy1,o.legendx2,o.legendy2); //0.7,0.1,0.9,0.6); l->SetFillColor(kWhite); l->SetBorderSize(0); l->SetTextFont(62); l->SetTextSize(0.03); if(debug_) std::cout << "Adding data to the legend" << std::endl; l->AddEntry(hd, "Data","P"); if(debug_) std::cout << "Adding MC to the THStack" << std::endl; //with the proper trigger eff // double SF[] = {1.01,1.03,1.00}; // double SF[] = {1.03,1.054,1.032}; double SF[] = {1.0,1.0,1.0}; if(debug_){ for(int i = 0; i< 3; ++i) std::cout << "SF [" << i << "] = " << SF[i] << std::endl; } double mcIntegral=0; for(size_t j=0;j< s.size() ;j++) { if(!s[j].data) { if(debug_) std::cout << "Creating TH1F from file " << s[j].name << std::endl; TH1F * h = ((TH1F*)s[j].file()->Get(names[i].c_str())); h->Sumw2(); if(debug_){ std::cout << "TH1F created from file " << s[j].name << std::endl; std::cout << "Scaling : " << s[j].scale(data.lumi(),fa,fb) << std::endl; std::cout << "Scaling with SF : " << s[j].scale(data.lumi(),fa,fb,SF) << std::endl; std::cout << "Histo integral before scaling = " << h->Integral() << std::endl; } h->Scale(s[j].scale(data.lumi(),fa,fb,SF)); if(debug_){ std::cout << "Histo integral after scaling = " << h->Integral() << std::endl; std::cout << "Managing style... " << std::endl; } h->SetLineWidth(1.); h->SetFillColor(s[j].color); h->SetLineColor(s[j].color); // h->Rebin(options[names[i]].rebin); if(debug_) std::cout << "Cloning and update legend " << std::endl; if(grouped.find(s[j].name) == grouped.end()){ l->AddEntry(h,s[j].name.c_str(),"F"); } std::cout << "Sample : " << s[j].name << " - Integral for plot " << names[i] << " = " << h->Integral(-10000,10000) << std::endl; mcIntegral += h->Integral(); sta->Add(h); hmc->Add(h); //TO FIX grouped map // sovrascrive histo con lo stesso nome tipo VV o ST etc... grouped[s[j].name]=(TH1F *)h->Clone(("_"+names[i]).c_str()); } } if(debug_){ std::cout << "Data total = " << hd->Integral() << std::endl; std::cout << "MC = " << mcIntegral << std::endl; std::cout << "Data/MC = " << hd->Integral()/mcIntegral << std::endl; } TPad * TopPad = new TPad("TopPad","Top Pad",0.,0.3,1.,1. ) ; TPad * BtmPad = new TPad("BtmPad","Bottom Pad",0.,0.,1.,0.313 ) ; TopPad->SetBottomMargin(0.02); BtmPad->SetTopMargin(0.0); BtmPad->SetFillStyle(4000); TopPad->SetFillStyle(4000); BtmPad->SetFillColor(0); BtmPad->SetBottomMargin(0.35); TopPad->Draw() ; BtmPad->Draw() ; std::cout << "hd maximum = " << hd->GetMaximum() << " sta maximum = " << sta->GetMaximum() << std::endl; double maxY; if(hd->GetMaximum() > sta->GetMaximum()) maxY = (hd->GetMaximum())*1.5; else maxY = (sta->GetMaximum())*1.5; TopPad->cd(); hd->Draw("E1X0"); sta->Draw("sameHIST"); hmc->Draw("sameE2"); hmc->SetFillColor(2); hmc->SetMarkerSize(0); hmc->SetFillStyle(3013); hd->Draw("E1X0same"); l->Draw("same"); std::cout << "Set Maximum to = " << maxY << std::endl; hd->GetYaxis()->SetRangeUser(0.,maxY); hd->GetXaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max); BtmPad->cd(); std::cout << "Division" << std::endl; TH1D * divisionErrorBand = (TH1D*)(hmc)->Clone("divisionErrorBand"); divisionErrorBand->Sumw2(); divisionErrorBand->Divide(hmc); divisionErrorBand->Draw("E2"); divisionErrorBand->SetMaximum(2.49); divisionErrorBand->SetMinimum(0); divisionErrorBand->SetMarkerStyle(20); divisionErrorBand->SetMarkerSize(0.55); divisionErrorBand->GetXaxis()->SetTitleOffset(1.12); divisionErrorBand->GetXaxis()->SetLabelSize(0.12); divisionErrorBand->GetXaxis()->SetTitleSize(0.5); divisionErrorBand->GetYaxis()->SetTitle("Data/MC"); divisionErrorBand->GetYaxis()->SetLabelSize(0.12); divisionErrorBand->GetYaxis()->SetTitleSize(0.12); divisionErrorBand->GetYaxis()->SetTitleOffset(0.40); divisionErrorBand->GetYaxis()->SetNdivisions(505); //divisionErrorBand->UseCurrentStyle(); divisionErrorBand->SetFillColor(2); divisionErrorBand->SetFillStyle(3001); divisionErrorBand->SetMarkerSize(0.); TH1D * division = (TH1D*)(hd)->Clone("division"); division->Sumw2(); division->Divide(hmc); // division->SetMaximum(2.5); // division->SetMinimum(0); // division->SetMarkerStyle(20); // division->SetMarkerSize(0.55); // division->GetXaxis()->SetLabelSize(0.12); // division->GetXaxis()->SetTitleSize(0.14); // division->GetYaxis()->SetLabelSize(0.10); // division->GetYaxis()->SetTitleSize(0.10); // division->GetYaxis()->SetTitle("Data/MC"); Double_t min = division->GetXaxis()->GetXmin(); Double_t max = division->GetXaxis()->GetXmax(); division->Draw("E1X0same"); TLine *line = new TLine(min, 1.0, max, 1.0); line->SetLineColor(kRed); line->Draw("same"); TLegend * leg3 =new TLegend(0.50,0.86,0.69,0.96); leg3->AddEntry(divisionErrorBand,"MC uncert. (stat.)","f"); leg3->SetFillColor(0); leg3->SetLineColor(0); leg3->SetShadowColor(0); leg3->SetTextFont(62); leg3->SetTextSize(0.06); leg3->Draw(); TPaveText *pave = new TPaveText(0.15,0.85,0.32,0.96,"brNDC"); pave->SetTextAlign(12); pave->SetLineColor(0); pave->SetFillColor(0); pave->SetShadowColor(0); //TText *text = pave->AddText(Form("#chi_{#nu}^{2} = %.3f, K_{s} = %.3f",histDt->Chi2Test(histCopyMC5,"UWCHI2/NDF"),histDt->KolmogorovTest(histCopyMC5))); // stat + sys TText *text = pave->AddText(Form("#chi_{#nu}^{2} = %.3f, K_{s} = %.3f",hd->Chi2Test(hmc,"UWCHI2/NDF"),hd->KolmogorovTest(hmc))); // stat only text->SetTextFont(62); text->SetTextSize(0.08); pave->Draw(); TopPad->cd(); TLatex latex; latex.SetNDC(); latex.SetTextAlign(12); latex.SetTextSize(0.052); latex.DrawLatex(0.17,0.89,"CMS Preliminary"); latex.SetTextSize(0.04); latex.DrawLatex(0.17,0.84,"#sqrt{s} = 7 TeV, L = 4.7 fb^{-1}"); // latex.DrawLatex(0.17,0.79,"Z(e^{+}e^{-})H(b#bar{b})"); latex.DrawLatex(0.17,0.79,process.c_str()); c->Update(); std::string cName= hd->GetName(); cName += "_bare.pdf"; cName = path+cName; c->Print(cName.c_str(),"pdf"); // std::cout << names[i] << " d: " << hd->Integral() << " "; // THStack * sta2 = new THStack("sta2",hd->GetTitle()); // float tot=0; // float toterr2=0; // if(debug_) // std::cout << "Putting the iterator in the for loop" << std::endl; // for(std::map<std::string,TH1F *>::reverse_iterator it=grouped.rbegin(); it!=grouped.rend();++it) // { // if(debug_) // std::cout << "Using the iterator" << std::endl; // std::cout << (*it).first << " " << (*it).second->Integral() << " | " << std::endl ; // if((*it).second->GetEntries() > 0) { // float er=1.*sqrt((*it).second->GetEntries())/(*it).second->GetEntries()*(*it).second->Integral(); // toterr2+=er*er; // } // tot+=(*it).second->Integral(); // sta2->Add(it->second); // } // std::cout << " Tot: " << tot << "+-" << sqrt(toterr2) << " SF: " << hd->Integral()/tot << std::endl; // TCanvas *c2 = new TCanvas(); // c2->SetTitle(names[i].c_str()); // std::cout << "hd maximum = " << hd->GetMaximum() << " sta2 maximum = " << sta2->GetMaximum() << std::endl; // if(hd->GetMaximum() > sta2->GetMaximum()) maxY = hd->GetBinContent(hd->GetMaximumBin()) * 1.5; // else maxY = ( sta2->GetMaximum())*1.5; // // hd->Draw("E1"); // sta2->Draw("PADSHIST"); // // hd->Draw("E1same"); // // l->Draw("same"); // std::cout << "Set Maximum to = " << maxY << std::endl; // hd->GetYaxis()->SetRangeUser(0.,maxY); // hd->GetXaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max); // c2->Update(); // std::string c2Name = hd->GetName(); // c2Name = path+c2Name; // c2Name += "_norm.pdf"; // c2->Print(c2Name.c_str(),"pdf"); } }
TCanvas *drawRatioPlot(TH1D *prediction, TH1D *sr, TH1D *data, TString xTitle, TString filename, double ecaloCut){ gStyle -> SetPadLeftMargin(0.20); data->SetMarkerStyle(20); data->SetMarkerColor(kGreen); data->SetLineColor(kGreen); TCanvas *c = new TCanvas("c"+filename,"c",0,0,500,500); float y = 0.3; TPad *pad1 = new TPad("pad1", "Control Plots 1", 0.01, y, 0.99, 0.99); TPad *padRatio = new TPad("rp1", "Ratio1", 0.01, 0.01, 0.99, y-0.01); pad1->SetNumber(100); pad1->SetTicks(0,1); cout<<"number pad1 = "<<pad1->GetNumber()<<endl; cout<<"number padRatio = "<<padRatio->GetNumber()<<endl; TH1D *ratio = 0; //ratio = (TH1D*) sr->Clone(); //ratio->Divide(prediction); ratio = (TH1D*) prediction->Clone(); ratio->Divide(data); for(int i=1; i<=ratio->GetNbinsX();i++){ if(ratio->GetBinContent(i) != 0){ cout<<"N in CR in "<<i<<". bin ="<<prediction->GetBinContent(i)<<endl; cout<<"N in SR in "<<i<<". bin ="<<sr->GetBinContent(i)<<endl; cout<<"Rel. difference in "<<i<<". bin ="<<(1./ratio->GetBinContent(i)-1.)*100<<"%"<<endl; } else if(sr->GetBinContent(i) == 0 && prediction->GetBinContent(i) !=0) cout<<"Scaling Factor in "<<i<<". bin <"<<prediction->GetBinContent(i)/1.15<<" +/- "<<ratio->GetBinError(i)<<endl; else if(sr->GetBinContent(i) != 0 && prediction->GetBinContent(i) ==0) cout<<"Scaling Factor in "<<i<<". bin <"<<(sr->GetEntries()/prediction->GetEntries())/sr->GetBinContent(i)<<" +/- "<<ratio->GetBinError(i)<<endl; } ratio->GetYaxis()->SetTitle("#frac{CR (MC)}{CR (data)}"); ratio->SetTitle(""); ratio->SetLabelSize(0.1,"X"); ratio->SetLabelSize(0.1,"Y"); ratio->SetTitleOffset(0.5,"Y"); ratio->SetTitleSize(0.15,"Y"); padRatio->cd(); //ratio->GetYaxis()->SetRangeUser(0,2); ratio->Draw("e"); // Draw line at one! float xmin = ratio->GetXaxis()->GetXmin(); float xmax = ratio->GetXaxis()->GetXmax(); TLine *line = new TLine(xmin,1,xmax,1); line->SetLineWidth(2); line->Draw("same"); padRatio->Modified(); TLegend *leg = new TLegend(0.5,0.7,0.9,0.9); leg->AddEntry(sr,"SR (MC)","l"); leg->AddEntry(prediction,"lepton CR (MC)","pel"); pad1->cd(); pad1->SetLogy(); // pad1->SetLogx(); sr->SetLineColor(kRed); sr->SetMarkerColor(kRed); sr->SetMarkerStyle(20); sr->SetTitle(""); prediction->SetMarkerStyle(20); prediction->SetTitle(""); prediction->GetXaxis()->SetTitle(xTitle); sr->GetXaxis()->SetTitle(xTitle); prediction->SetTitleSize(0.07,"X"); prediction->GetXaxis()->SetTitleOffset(0.7); sr->SetTitleSize(0.07,"X"); sr->GetXaxis()->SetTitleOffset(0.7); double maximum = 0; double minimum = 1000000; if(sr->GetMinimum()!=0 && sr->GetMinimum()<minimum){ minimum=sr->GetMinimum()*0.5; } if(prediction->GetMinimum()!=0 && prediction->GetMinimum()<minimum){ minimum=prediction->GetMinimum()*0.5; } if(data->GetMinimum()!=0 && data->GetMinimum()<minimum){ minimum=data->GetMinimum()*0.5; } if(sr->GetMaximum()>maximum){ maximum=sr->GetMaximum()*2.5; } if(prediction->GetMaximum()>maximum){ maximum=prediction->GetMaximum()*2.5; } if(data->GetMaximum()>maximum){ maximum=data->GetMaximum()*2.5; } prediction->GetYaxis()->SetRangeUser(minimum,maximum); ratio->GetYaxis()->SetRangeUser(0,2); prediction->Draw("e"); sr->Draw("e same"); leg->AddEntry(data,"lepton CR (data)","pel"); data->Draw("e same"); leg->Draw("same"); TLatex* info1 = new TLatex(); info1->SetTextFont(132); info1-> SetNDC(); info1->SetTextSize(0.06); info1->DrawLatex(0.55,0.62,Form("E_{calo}<%.0fGeV",ecaloCut)); // Draw both pads to canvas c->cd(); pad1->Draw(); padRatio->SetGridy(); padRatio->Draw(); c->SaveAs(filename); return c; }
void AxEffSyst(TString modOCDBOutputPath, TString stdOCDBOutputPath){ gStyle->SetOptStat(0); TFile *axEffModOCDBFile = new TFile(modOCDBOutputPath.Data(),"READONLY"); TFile *axEffStdOCDBFile = new TFile(stdOCDBOutputPath.Data(),"READONLY"); TH1D *axEffModOCDBHisto = 0x0; axEffModOCDBFile->GetObject("ratio1", axEffModOCDBHisto); axEffModOCDBHisto->SetLineColor(kBlue); axEffModOCDBHisto->SetLineWidth(2); axEffModOCDBHisto->SetTitle("A#times#epsilon"); axEffModOCDBHisto->GetXaxis()->SetTitle("Rapidity"); axEffModOCDBHisto->GetYaxis()->SetTitle("A#times#epsilon"); TH1D *axEffStdOCDBHisto = 0x0; axEffStdOCDBFile->GetObject("ratio1", axEffStdOCDBHisto); axEffStdOCDBHisto->SetLineColor(kRed); axEffStdOCDBHisto->SetTitle("A#times#epsilon Std OCDB"); axEffStdOCDBHisto->GetXaxis()->SetTitle("Rapidity"); axEffStdOCDBHisto->GetYaxis()->SetTitle("A#times#epsilon"); axEffModOCDBHisto->Sumw2(kTRUE); axEffStdOCDBHisto->Sumw2(kTRUE); TH1D *ratio = (TH1D*)axEffStdOCDBHisto->Clone(); ratio->Sumw2(kTRUE); ratio->SetLineWidth(1); ratio->Add(axEffModOCDBHisto, -1.); ratio->Divide(axEffStdOCDBHisto); ratio->SetLineColor(kBlack); ratio->SetTitle("#frac{A#times#epsilon_{Std OCDB}-A#times#epsilon_{Mod OCDB}}{A#times#epsilon_{Std OCDB}}"); ratio->GetXaxis()->SetTitle("Rapidity"); ratio->GetYaxis()->SetTitle("Ratio (%)"); for (Int_t iBinsRatio = 0; iBinsRatio <= ratio->GetNbinsX()+1; iBinsRatio++) { Double_t binContent = ratio->GetBinContent(iBinsRatio); cout<<binContent<<"->"; if ( binContent<0. ) ratio->SetBinContent(iBinsRatio, -binContent*100.); else ratio->SetBinContent(iBinsRatio, binContent*100.); binContent = ratio->GetBinContent(iBinsRatio); cout<<binContent<<endl; } TCanvas *canv = new TCanvas("canv"); canv->Divide(2,1); canv->cd(1); axEffModOCDBHisto->SetDirectory(0); axEffModOCDBHisto->Draw("E"); axEffStdOCDBHisto->SetDirectory(0); axEffStdOCDBHisto->Draw("SAME E"); canv->cd(2); ratio->GetYaxis()->SetRangeUser(-0.5,ratio->GetMaximum()*2); ratio->SetDirectory(0); ratio->Draw("E"); axEffModOCDBFile->Close(); axEffStdOCDBFile->Close(); }
void studydoubleratio(Bool_t doweight=true) { gStyle->SetTextSize(0.05); gStyle->SetTextFont(42); gStyle->SetPadRightMargin(0.043); gStyle->SetPadLeftMargin(0.18); gStyle->SetPadTopMargin(0.1); gStyle->SetPadBottomMargin(0.145); gStyle->SetTitleX(.0f); void clean0 (TH1D* h); TF1* fitDstar3prongs (TTree* nt, TTree* ntMC, Double_t ptmin, Double_t ptmax); TF1* fitDstar5prongs (TTree* nt, Double_t ptmin, Double_t ptmax); TFile* infData3prong = new TFile(infnameData3p[isData].Data()); TFile* infData5prong = new TFile(infnameData5p[isData].Data()); TFile* infMC3prong = new TFile(infnameMC3p[isData].Data()); TFile* infMC5prong = new TFile(infnameMC5p[isData].Data()); TTree* ntData3prong = (TTree*)infData3prong->Get("ntDD0kpipi"); TTree* ntData5prong = (TTree*)infData5prong->Get("ntDD0kpipipipi"); TTree* ntMC3prong = (TTree*)infMC3prong->Get("ntDD0kpipi"); TTree* ntMC5prong = (TTree*)infMC5prong->Get("ntDD0kpipipipi"); TTree* ntGen3prong = (TTree*)infMC3prong->Get("ntGen"); TTree* ntGen5prong = (TTree*)infMC5prong->Get("ntGen"); TTree* HltTreeData3prong = (TTree*)infData3prong->Get("ntHlt"); TTree* HltTreeData5prong = (TTree*)infData5prong->Get("ntHlt"); ntData3prong->AddFriend(HltTreeData3prong); ntData5prong->AddFriend(HltTreeData5prong); TTree* HltTreeMC3prong = (TTree*)infMC3prong->Get("ntHlt"); TTree* HltTreeMC5prong = (TTree*)infMC5prong->Get("ntHlt"); ntMC3prong->AddFriend(HltTreeMC3prong); ntMC5prong->AddFriend(HltTreeMC5prong); ntGen3prong->AddFriend(HltTreeMC3prong); ntGen5prong->AddFriend(HltTreeMC5prong); TH1D* hPt3prong = new TH1D("hPt3prong","",nBins,ptBins); TH1D* hPt5prong = new TH1D("hPt5prong","",nBins,ptBins); hPt3prong->Sumw2(); hPt5prong->Sumw2(); TH1D* hPtMC3prong = new TH1D("hPtMC3prong","",nBins,ptBins); TH1D* hPtMC5prong = new TH1D("hPtMC5prong","",nBins,ptBins); hPtMC3prong->Sumw2(); hPtMC5prong->Sumw2(); TH1D* hPtGen3prong = new TH1D("hPtGen3prong","",nBins,ptBins); TH1D* hPtGen5prong = new TH1D("hPtGen5prong","",nBins,ptBins); hPtGen3prong->Sumw2(); hPtGen5prong->Sumw2(); for(int i=0;i<nBins;i++) { TF1* fData3prong = fitDstar3prongs(ntData3prong,ntMC3prong, ptBins[i],ptBins[i+1]); TF1* fData5prong = fitDstar5prongs(ntData5prong,ptBins[i],ptBins[i+1]); Double_t yieldData3prong = fData3prong->Integral(minmass3prong,maxmass3prong)/binwidth3prong; Double_t yieldData3prongErr = fData3prong->Integral(minmass3prong,maxmass3prong)/binwidth3prong*fData3prong->GetParError(0)/fData3prong->GetParameter(0); Double_t yieldData5prong = fData5prong->Integral(minmass5prong,maxmass5prong)/binwidth5prong; Double_t yieldData5prongErr = fData5prong->Integral(minmass5prong,maxmass5prong)/binwidth5prong*fData5prong->GetParError(0)/fData5prong->GetParameter(0); hPt3prong->SetBinContent(i+1,yieldData3prong/(ptBins[i+1]-ptBins[i])); hPt3prong->SetBinError(i+1,yieldData3prongErr/(ptBins[i+1]-ptBins[i])); hPt5prong->SetBinContent(i+1,yieldData5prong/(ptBins[i+1]-ptBins[i])); hPt5prong->SetBinError(i+1,yieldData5prongErr/(ptBins[i+1]-ptBins[i])); } ntMC3prong->Project("hPtMC3prong","Dpt",Form("%s&&%s",selmc3p.Data(),triggerselection[isData].Data())); divideBinWidth(hPtMC3prong); ntGen3prong->Project("hPtGen3prong","Gpt",Form("%s&&%s",selgen3p.Data(),triggerselection[isData].Data())); divideBinWidth(hPtGen3prong); ntMC5prong->Project("hPtMC5prong","Dpt",Form("%s&&%s",selmc5p.Data(),triggerselection[isData].Data())); divideBinWidth(hPtMC5prong); ntGen5prong->Project("hPtGen5prong","Gpt",Form("%s&&%s",selgen5p.Data(),triggerselection[isData].Data())); divideBinWidth(hPtGen5prong); TCanvas* cPt3prong = new TCanvas("cPt3prong","",600,600); cPt3prong->SetLogy(); hPt3prong->SetXTitle("D p_{T} (GeV/c)"); hPt3prong->SetYTitle(Form("%s Uncorrected 3-prong N(D*)/dp_{T}",texData[isData].Data())); hPt3prong->Draw(); cPt3prong->SaveAs(Form("plots/pp/c_%s_Pt3prong.pdf",texData[isData].Data())); hPt3prong->Scale(scaleMC3p[isData]); TCanvas* cPt5prong = new TCanvas("cPt5prong","",600,600); cPt5prong->SetLogy(); hPt5prong->SetXTitle("D p_{T} (GeV/c)"); hPt5prong->SetYTitle(Form("%s Uncorrected 5-prong N(D*)/dp_{T}",texData[isData].Data())); hPt5prong->Draw(); cPt5prong->SaveAs(Form("plots/pp/c_%s_Pt5prong.pdf",texData[isData].Data())); hPt5prong->Scale(scaleMC5p[isData]); TH1D* hRatio = (TH1D*)hPt5prong->Clone("hRatio"); hRatio->SetTitle(Form(";D p_{T} (GeV/c);%s Raw dN(D*)/dp_{T} 5/3 prong Ratio",texData[isData].Data())); hRatio->Divide(hPt3prong); TCanvas* cRatio = new TCanvas("cRatio","",600,600); hRatio->Draw(); cRatio->SaveAs(Form("plots/pp/c_%s_Ratio.pdf",texData[isData].Data())); TH1D* hEff3prong = (TH1D*)hPtMC3prong->Clone("hEff3prong"); hEff3prong->SetTitle(Form(";D p_{T} (GeV/c);%s 3-prong Efficiency",texData[isData].Data())); hEff3prong->Divide(hPtGen3prong); TCanvas* cEff3prong = new TCanvas("cEff3prong","",600,600); hEff3prong->Draw(); cEff3prong->SaveAs("plots/pp/cEff3prong.pdf"); TH1D* hEff5prong = (TH1D*)hPtMC5prong->Clone("hEff5prong"); hEff5prong->SetTitle(Form(";D p_{T} (GeV/c);%s 5-prong Efficiency",texData[isData].Data())); hEff5prong->Divide(hPtGen5prong); TCanvas* cEff5prong = new TCanvas("cEff5prong","",600,600); hEff5prong->Draw(); cEff5prong->SaveAs("plots/pp/cEff5prong.pdf"); TH1D* hPtCor3prong = (TH1D*)hPt3prong->Clone("hPtCor3prong"); hPtCor3prong->SetTitle(Form(";D p_{T} (GeV/c);%s Corrected 3-prong dN(D*)/dp_{T}",texData[isData].Data())); hPtCor3prong->Divide(hEff3prong); TCanvas* cPtCor3prong = new TCanvas("cCor3prong","",600,600); cPtCor3prong->SetLogy(); hPtCor3prong->Draw(); if(isData==0||isData==2) { hPtGen3prong->SetLineColor(kRed); hPtGen3prong->Draw("same hist"); TLegend* legPtCor3prong = myLegend(0.55,0.70,0.90,0.84); legPtCor3prong->AddEntry(hPtCor3prong,"Corrected signal","pl"); legPtCor3prong->AddEntry(hPtGen3prong,"Generated D*","lf"); legPtCor3prong->Draw("same"); } cPtCor3prong->SaveAs(Form("plots/pp/c_%s_PtCor3prong.pdf",texData[isData].Data())); TH1D* hPtCor5prong = (TH1D*)hPt5prong->Clone("hPtCor3prong"); hPtCor5prong->SetTitle(Form(";D p_{T} (GeV/c);%s Corrected 5-prong dN(D*)/dp_{T}",texData[isData].Data())); hPtCor5prong->Divide(hEff5prong); TCanvas* cPtCor5prong = new TCanvas("cCor5prong","",600,600); cPtCor5prong->SetLogy(); hPtCor5prong->SetMinimum(hPtGen5prong->GetMinimum()*0.1); hPtCor5prong->Draw(); if(isData==0||isData==2) { hPtGen5prong->SetLineColor(kRed); hPtGen5prong->Draw("same hist"); TLegend* legPtCor5prong = myLegend(0.55,0.70,0.90,0.84); legPtCor5prong->AddEntry(hPtCor5prong,"Corrected signal","pl"); legPtCor5prong->AddEntry(hPtGen5prong,"Generated D*","lf"); legPtCor5prong->Draw("same"); } cPtCor5prong->SaveAs(Form("plots/pp/c_%s_PtCor5prong.pdf",texData[isData].Data())); TH1D* hRatioCor = (TH1D*)hPtCor5prong->Clone("hRatioCor"); hRatioCor->SetTitle(Form(";D p_{T} (GeV/c);%s Corrected dN(D*)/dp_{T} 5/3 prong Ratio",texData[isData].Data())); hRatioCor->Divide(hPtCor3prong); TCanvas* cRatioCor = new TCanvas("cRatioCor","",600,600); hRatioCor->Draw(); cRatioCor->SaveAs(Form("plots/pp/c_%s_RatioCor.pdf",texData[isData].Data())); TFile *outputfile=new TFile(outputfilename.Data(),"recreate"); outputfile->cd(); hPt3prong->Write(); hPt5prong->Write(); hRatio->Write(); outputfile->Close(); }
void MCefficiencyCent(int isPbPb=0,TString inputmc="/data/wangj/MC2015/Dntuple/pp/revised/ntD_pp_Dzero_kpi_prompt/ntD_EvtBase_20160303_Dfinder_20160302_pp_Pythia8_prompt_D0_dPt0tkPt0p5_pthatweight.root", TString selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))",TString selmcgenacceptance="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))&&abs(Gtk1eta)<2.0&&abs(Gtk2eta)<2.0&&Gtk1pt>2.0&&Gtk2pt>2.0", TString cut_recoonly="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11", TString cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)",TString label="PP",TString outputfile="test", int useweight=1,Float_t centmin=0., Float_t centmax=100.) { hiBinMin = centmin*2; hiBinMax = centmax*2; centMin = centmin; centMax = centmax; if(isPbPb==1) { selmcgen = selmcgen+Form("&&hiBin>=%f&&hiBin<=%f",hiBinMin,hiBinMax); selmcgenacceptance=selmcgenacceptance+Form("&&hiBin>=%f&&hiBin<=%f",hiBinMin,hiBinMax); cut_recoonly=cut_recoonly+Form("&&hiBin>=%f&&hiBin<=%f",hiBinMin,hiBinMax); cut=cut+Form("&&hiBin>=%f&&hiBin<=%f",hiBinMin,hiBinMax); } std::cout<<"selmcgen="<<selmcgen<<std::endl; std::cout<<"selmcgenacceptance="<<selmcgenacceptance<<std::endl; std::cout<<"cut_recoonly"<<cut_recoonly<<std::endl; std::cout<<"cut="<<cut<<std::endl; std::cout<<"option="<<useweight<<std::endl; gStyle->SetOptTitle(0); gStyle->SetOptStat(0); gStyle->SetEndErrorSize(0); gStyle->SetMarkerStyle(20); TFile* infMC = new TFile(inputmc.Data()); TTree* ntMC = (TTree*)infMC->Get("ntKp"); TTree* ntGen = (TTree*)infMC->Get("ntGen"); TTree* ntSkim = (TTree*)infMC->Get("ntSkim"); TTree* ntmvaTree = (TTree*)infMC->Get("mvaTree"); TTree* ntHlt = (TTree*)infMC->Get("ntHlt"); ntMC->AddFriend(ntmvaTree); ntMC->AddFriend(ntGen); ntMC->AddFriend(ntSkim); ntMC->AddFriend(ntHlt); TTree* nthi = (TTree*)infMC->Get("ntHi"); ntGen->AddFriend(nthi); ntGen->AddFriend(ntSkim); ntGen->AddFriend(ntHlt); nthi->AddFriend(ntMC); ntMC->AddFriend(nthi); // optimal weigths TCut weighpthat = "1"; TCut weightGpt = "1"; TCut weightBgenpt = "1"; TCut weightHiBin = "1"; if(useweight==0) { weightfunctiongen="1"; weightfunctionreco="1"; weighpthat = "pthatweight"; weightGpt = "(pow(10,-0.094152+0.008102*Gpt+Gpt*Gpt*0.000171+Gpt*Gpt*Gpt*-0.000005+Gpt*Gpt*Gpt*Gpt*-0.000000+Gpt*Gpt*Gpt*Gpt*Gpt*0.000000))"; weightBgenpt = "(pow(10,-0.094152+0.008102*Bgenpt+Bgenpt*Bgenpt*0.000171+Bgenpt*Bgenpt*Bgenpt*-0.000005+Bgenpt*Bgenpt*Bgenpt*Bgenpt*-0.000000+Bgenpt*Bgenpt*Bgenpt*Bgenpt*Bgenpt*0.000000))"; } if(useweight==1) { weightfunctiongen="6.08582+hiBin*(-0.155739)+hiBin*hiBin*(0.00149946)+hiBin*hiBin*hiBin*(-6.41629e-06)+hiBin*hiBin*hiBin*hiBin*(1.02726e-08)"; weightfunctionreco="6.08582+hiBin*(-0.155739)+hiBin*hiBin*(0.00149946)+hiBin*hiBin*hiBin*(-6.41629e-06)+hiBin*hiBin*hiBin*hiBin*(1.02726e-08)"; weighpthat = "pthatweight"; weightGpt = "(pow(10,-0.107832+0.010248*Gpt+Gpt*Gpt*0.000079+Gpt*Gpt*Gpt*-0.000003+Gpt*Gpt*Gpt*Gpt*-0.000000+Gpt*Gpt*Gpt*Gpt*Gpt*0.000000))"; weightBgenpt = "(pow(10,-0.107832+0.010248*Bgenpt+Bgenpt*Bgenpt*0.000079+Bgenpt*Bgenpt*Bgenpt*-0.000003+Bgenpt*Bgenpt*Bgenpt*Bgenpt*-0.000000+Bgenpt*Bgenpt*Bgenpt*Bgenpt*Bgenpt*0.000000))"; weightHiBin = "(6.08582+hiBin*(-0.155739)+hiBin*hiBin*(0.00149946)+hiBin*hiBin*hiBin*(-6.41629e-06)+hiBin*hiBin*hiBin*hiBin*(1.02726e-08))"; } std::cout<<"fit function parameters="<<weightfunctiongen<<std::endl; TH1D* hPtMC = new TH1D("hPtMC","",_nBins,_ptBins); TH1D* hPtMCrecoonly = new TH1D("hPtMCrecoonly","",_nBins,_ptBins); TH1D* hPtGen = new TH1D("hPtGen","",_nBins,_ptBins); TH1D* hPtGenAcc = new TH1D("hPtGenAcc","",_nBins,_ptBins); TH1D* hPtGenAccWeighted = new TH1D("hPtGenAccWeighted","",_nBins,_ptBins); TH1D* hPthat = new TH1D("hPthat","",100,0,500); TH1D* hPthatweight = new TH1D("hPthatweight","",100,0,500); //ntMC->Project("hPtMC","hiBin",TCut(weightfunctionreco)*(TCut(cut.Data())&&"(Bgen==23333)")); ntMC->Project("hPtMC","hiBin",TCut(weighpthat)*TCut(weightBgenpt)*TCut(weightHiBin)*(TCut(cut.Data())&&"(Bgen==23333)")); divideBinWidth(hPtMC); //ntMC->Project("hPtMCrecoonly","hiBin",TCut(weightfunctionreco)*(TCut(cut_recoonly.Data())&&"(Bgen==23333)")); ntMC->Project("hPtMCrecoonly","hiBin",TCut(weighpthat)*TCut(weightBgenpt)*TCut(weightHiBin)*(TCut(cut_recoonly.Data())&&"(Bgen==23333)")); divideBinWidth(hPtMCrecoonly); //ntGen->Project("hPtGen","hiBin",(TCut(selmcgen.Data()))); ntGen->Project("hPtGen","hiBin",TCut(weighpthat)*TCut(weightGpt)*(TCut(selmcgen.Data()))); divideBinWidth(hPtGen); //ntGen->Project("hPtGenAcc","hiBin",(TCut(selmcgenacceptance.Data()))); ntGen->Project("hPtGenAcc","hiBin",TCut(weighpthat)*TCut(weightGpt)*(TCut(selmcgenacceptance.Data()))); divideBinWidth(hPtGenAcc); //ntGen->Project("hPtGenAccWeighted","hiBin",TCut(weightfunctiongen)*(TCut(selmcgenacceptance.Data()))); ntGen->Project("hPtGenAccWeighted","hiBin",TCut(weighpthat)*TCut(weightGpt)*TCut(weightHiBin)*(TCut(selmcgenacceptance.Data()))); divideBinWidth(hPtGenAccWeighted); ntMC->Project("hPthat","pthat","1"); ntMC->Project("hPthatweight","pthat",TCut("1")); hPtMC->Sumw2(); hPtGenAcc->Sumw2(); hPtMCrecoonly->Sumw2(); //Acceptance TH1D* hEffAcc = (TH1D*)hPtGenAcc->Clone("hEffAcc"); hEffAcc->Sumw2(); hEffAcc->Divide(hEffAcc,hPtGen,1,1,"b"); //Selection TH1D* hEffSelection = (TH1D*)hPtMC->Clone("hEffSelection"); hEffSelection->Sumw2(); hEffSelection->Divide(hEffSelection,hPtGenAccWeighted,1,1,"b"); //Acc * Eff (one shot) TH1D* hEffReco = (TH1D*)hPtMCrecoonly->Clone("hEffReco"); hEffReco->Sumw2(); hEffReco->Divide(hEffReco,hPtGen,1,1,"b"); //Acc * Eff TH1D* hEff = (TH1D*)hEffSelection->Clone("hEff"); hEff->Sumw2(); //hEff->Divide(hPtMC,hPtGen,1,1,""); hEff->Multiply(hEff,hEffAcc,1,1); TH2F* hemptyEff=new TH2F("hemptyEff","",50,_ptBins[0]-5.,_ptBins[_nBins]+5.,10.,0,1.0); hemptyEff->GetXaxis()->CenterTitle(); hemptyEff->GetYaxis()->CenterTitle(); //hemptyEff->GetYaxis()->SetTitle("acceptance x #epsilon_{reco} x #epsilon_{sel} "); hemptyEff->GetYaxis()->SetTitle("#alpha x #epsilon"); hemptyEff->GetXaxis()->SetTitle("Centrality"); hemptyEff->GetXaxis()->SetTitleOffset(0.9); hemptyEff->GetYaxis()->SetTitleOffset(0.95); hemptyEff->GetXaxis()->SetTitleSize(0.05); hemptyEff->GetYaxis()->SetTitleSize(0.05); hemptyEff->GetXaxis()->SetTitleFont(42); hemptyEff->GetYaxis()->SetTitleFont(42); hemptyEff->GetXaxis()->SetLabelFont(42); hemptyEff->GetYaxis()->SetLabelFont(42); hemptyEff->GetXaxis()->SetLabelSize(0.035); hemptyEff->GetYaxis()->SetLabelSize(0.035); hemptyEff->SetMaximum(2); hemptyEff->SetMinimum(0.); hemptyEff->Draw(); TH2F* hemptyEffAcc=(TH2F*)hemptyEff->Clone("hemptyEffAcc"); TH2F* hemptyEffReco=(TH2F*)hemptyEff->Clone("hemptyEffReco"); TH2F* hemptyEffSelection=(TH2F*)hemptyEff->Clone("hemptyEffSelection"); TCanvas*canvasEff=new TCanvas("canvasEff","canvasEff",1000.,500); canvasEff->Divide(2,1); canvasEff->cd(1); hemptyEffAcc->SetYTitle("#alpha"); hemptyEffAcc->Draw(); hEffAcc->Draw("same"); canvasEff->cd(2); hemptyEff->Draw(); hEff->Draw("same"); canvasEff->SaveAs(Form("plotEff/canvasEff_study%s_Cent.pdf",Form(label.Data()))); TH2F* hemptyPthat=new TH2F("hemptyPthat","",50,0.,500.,10,1e-5,1e9); hemptyPthat->GetXaxis()->CenterTitle(); hemptyPthat->GetYaxis()->CenterTitle(); hemptyPthat->GetYaxis()->SetTitle("Entries"); hemptyPthat->GetXaxis()->SetTitle("pthat"); hemptyPthat->GetXaxis()->SetTitleOffset(0.9); hemptyPthat->GetYaxis()->SetTitleOffset(0.95); hemptyPthat->GetXaxis()->SetTitleSize(0.05); hemptyPthat->GetYaxis()->SetTitleSize(0.05); hemptyPthat->GetXaxis()->SetTitleFont(42); hemptyPthat->GetYaxis()->SetTitleFont(42); hemptyPthat->GetXaxis()->SetLabelFont(42); hemptyPthat->GetYaxis()->SetLabelFont(42); hemptyPthat->GetXaxis()->SetLabelSize(0.035); hemptyPthat->GetYaxis()->SetLabelSize(0.035); hemptyPthat->SetMaximum(2); hemptyPthat->SetMinimum(0.); TH2F* hemptySpectra=new TH2F("hemptySpectra","",50,0.,130.,10,1,1e5); hemptySpectra->GetXaxis()->CenterTitle(); hemptySpectra->GetYaxis()->CenterTitle(); hemptySpectra->GetYaxis()->SetTitle("Entries"); hemptySpectra->GetXaxis()->SetTitle("Centrality"); hemptySpectra->GetXaxis()->SetTitleOffset(0.9); hemptySpectra->GetYaxis()->SetTitleOffset(0.95); hemptySpectra->GetXaxis()->SetTitleSize(0.05); hemptySpectra->GetYaxis()->SetTitleSize(0.05); hemptySpectra->GetXaxis()->SetTitleFont(42); hemptySpectra->GetYaxis()->SetTitleFont(42); hemptySpectra->GetXaxis()->SetLabelFont(42); hemptySpectra->GetYaxis()->SetLabelFont(42); hemptySpectra->GetXaxis()->SetLabelSize(0.035); hemptySpectra->GetYaxis()->SetLabelSize(0.035); TH2F* hemptyPthatWeighted=(TH2F*)hemptyPthat->Clone("hemptyPthatWeighted"); hemptyPthatWeighted->GetXaxis()->SetTitle("pthat reweighted"); TCanvas*canvasPthat=new TCanvas("canvasPthat","canvasPthat",1000.,500); canvasPthat->Divide(2,1); canvasPthat->cd(1); gPad->SetLogy(); hemptyPthat->Draw("same"); hPthat->Draw("same"); canvasPthat->cd(2); gPad->SetLogy(); hemptyPthatWeighted->Draw(); hPthatweight->Draw("same"); canvasPthat->SaveAs(Form("plotEff/canvasPthat_%s_Cent.pdf",Form(label.Data()))); TCanvas*canvasSpectra=new TCanvas("canvasSpectra","canvasSpectra",1000.,500); canvasSpectra->Divide(2,1); canvasSpectra->cd(1); gPad->SetLogy(); hemptySpectra->Draw(); hPtMC->Draw("same"); canvasSpectra->cd(2); gPad->SetLogy(); hemptySpectra->Draw(); hPtGen->Draw("same"); canvasSpectra->SaveAs(Form("plotEff/canvasSpectra_%s_Cent.pdf",Form(label.Data()))); //### 1D histogram //hEff = hPtMC / hPtGen //hEffReco = hPtMCrecoonly / hPtGen //hEffAcc = hPtGenAcc / hPtGen //hEffSelection = hPtMC / hPtMCrecoonly /* ntMC->Project("hPtMC","hiBin",TCut(weightfunctionreco)*(TCut(cut.Data())&&"(Bgen==23333)")); ntMC->Project("hPtMCrecoonly","hiBin",TCut(weightfunctionreco)*(TCut(cut_recoonly.Data())&&"(Bgen==23333)")); ntGen->Project("hPtGen","hiBin",TCut(weightfunctiongen)*(TCut(selmcgen.Data()))); ntGen->Project("hPtGenAcc","hiBin",TCut(weightfunctiongen)*(TCut(selmcgenacceptance.Data()))); */ TCanvas*canvas1D=new TCanvas("canvas1D","",600,600); canvas1D->cd(); gPad->SetLogy(); hemptySpectra->SetYTitle("Entries of hPtMC"); hemptySpectra->Draw(); hPtMC->Draw("same"); canvas1D->SaveAs(Form("plotEff/canvas1DhPtMC_%s_Cent.pdf",Form(label.Data()))); canvas1D->Clear(); canvas1D=new TCanvas("canvas1D","",600,600); canvas1D->cd(); gPad->SetLogy(); hemptySpectra->SetYTitle("Entries of hPtMCrecoonly"); hemptySpectra->Draw(); hPtMCrecoonly->Draw("same"); canvas1D->SaveAs(Form("plotEff/canvas1DhPtMCrecoonly_%s_Cent.pdf",Form(label.Data()))); canvas1D->Clear(); canvas1D=new TCanvas("canvas1D","",600,600); canvas1D->cd(); gPad->SetLogy(); hemptySpectra->SetYTitle("Entries of hPtGen"); hemptySpectra->Draw(); hPtGen->Draw("same"); canvas1D->SaveAs(Form("plotEff/canvas1DhPtGen_%s_Cent.pdf",Form(label.Data()))); canvas1D->Clear(); canvas1D=new TCanvas("canvas1D","",600,600); canvas1D->cd(); gPad->SetLogy(); hemptySpectra->SetYTitle("Entries of hPtGenAcc"); hemptySpectra->Draw(); hPtGenAcc->Draw("same"); canvas1D->SaveAs(Form("plotEff/canvas1DhPtGenAcc_%s_Cent.pdf",Form(label.Data()))); canvas1D->Clear(); canvas1D=new TCanvas("canvas1D","",600,600); canvas1D->cd(); gPad->SetLogy(0); hemptyEff->SetYTitle("hPtMC / hPtGen"); hemptyEff->Draw(); hEff->Draw("same"); canvas1D->SaveAs(Form("plotEff/canvas1DhEff_%s_Cent.pdf",Form(label.Data()))); canvas1D->Clear(); canvas1D=new TCanvas("canvas1D","",600,600); canvas1D->cd(); hemptyEff->SetYTitle("hPtMCrecoonly / hPtGen"); hemptyEff->Draw(); hEffReco->Draw("same"); canvas1D->SaveAs(Form("plotEff/canvas1DhEffReco_%s_Cent.pdf",Form(label.Data()))); canvas1D->Clear(); canvas1D=new TCanvas("canvas1D","",600,600); canvas1D->cd(); hemptyEff->SetYTitle("hPtGenAcc / hPtGen"); hemptyEff->Draw(); hEffAcc->Draw("same"); canvas1D->SaveAs(Form("plotEff/canvas1DhEffAcc_%s_Cent.pdf",Form(label.Data()))); canvas1D->Clear(); canvas1D=new TCanvas("canvas1D","",600,600); canvas1D->cd(); hemptyEff->SetYTitle("hPtMC / hPtGenAcc"); hemptyEff->Draw(); hEffSelection->Draw("same"); canvas1D->SaveAs(Form("plotEff/canvas1DhEffSelection_%s_Cent.pdf",Form(label.Data()))); canvas1D->Clear(); gStyle->SetPalette(55); TCanvas* canvas2D=new TCanvas("canvas2D","",600,600); TFile *fout=new TFile(outputfile.Data(),"recreate"); fout->cd(); hPtGen->Write(); hEffAcc->Write(); hEffReco->Write(); hEffSelection->Write(); hEff->Write(); hPtMC->Write(); fout->Close(); }