/** * * * @param o * @param useWeights * @param correct * * @ingroup pwglf_forward_scripts_tests */ void TestPoisson(Double_t o=.3, bool useWeights=false, bool correct=true) { const char* load = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C"; if (!gROOT->GetClass("AliAODForwardMult")) { gROOT->Macro(load); gROOT->GetInterpreter()->UnloadFile(gSystem->ExpandPathName(load)); } // --- Parameters of this script ----------------------------------- Int_t nBin = 5; // Our detector matrix size Int_t nMax = TMath::Max(Int_t(nBin * nBin * o + .5)+nBin/2,nBin); Int_t nEv = 10000; // Number of events Double_t mp = o; // The 'hit' probability TH2D* base = new TH2D("base", "Basic histogram", nBin,-.5, nBin-.5, nBin, -.5, nBin-.5); base->SetXTitle("#eta"); base->SetYTitle("#varphi"); base->SetDirectory(0); base->SetOption("colz"); Int_t tN1=nMax; Double_t tMin1; Double_t tMax1; Int_t tN2=nMax*10; Double_t tMin2; Double_t tMax2=nMax; MakeIntegerAxis(tN1, tMin1, tMax1); MakeIntegerAxis(tN2, tMin2, tMax2); TH2D* corr = new TH2D("comp", "Comparison", tN1, tMin1, tMax1, tN2, tMin2, tMax2); corr->SetXTitle("Input"); corr->SetYTitle("Poisson"); corr->SetDirectory(0); corr->SetOption("colz"); corr->SetStats(0); TLine* lcorr = new TLine(0, 0, tMax2, tMax2); Int_t mm = TMath::Max(Int_t(nBin * o + .5),nBin/2); tN2=mm*10; tMax2 = mm; MakeIntegerAxis(tN2, tMin2, tMax2); Info("", "Making mean w/nbins=%d,range=[%f,%f]", tN2, tMin2, tMax2); TH2D* mean = new TH2D("mean", "Mean comparison", tN2, tMin2, tMax2, tN2, tMin2, tMax2); mean->SetXTitle("Input"); mean->SetYTitle("Poisson"); mean->SetDirectory(0); mean->SetOption("colz"); mean->SetStats(0); TLine* lmean = new TLine(tMin2, tMin2, tMax2, tMax2); TH1D* dist = new TH1D("dist", "Distribution of hits", tN1, tMin1, tMax1); dist->SetXTitle("s"); dist->SetYTitle("P(s)"); dist->SetFillColor(kRed+1); dist->SetFillStyle(3001); dist->SetDirectory(0); TH1D* diff = new TH1D("diff", "P-T", 100, -25, 25); diff->SetXTitle("Difference"); diff->SetFillColor(kRed+1); diff->SetFillStyle(3001); diff->SetYTitle("Prob"); AliPoissonCalculator* c = new AliPoissonCalculator("ignored"); c->Init(nBin ,nBin); for (Int_t i = 0; i < nEv; i++) { c->Reset(base); base->Reset(); for (Int_t iEta = 0; iEta < nBin; iEta++) { for (Int_t iPhi = 0; iPhi < nBin; iPhi++) { // Throw a die Int_t m = gRandom->Poisson(mp); dist->Fill(m); // Fill into our base histogram base->Fill(iEta, iPhi, m); // Fill into poisson calculator c->Fill(iEta, iPhi, m > 0, (useWeights ? m : 1)); } } // Calculate the result TH2D* res = c->Result(correct); // Now loop and compare Double_t mBase = 0; Double_t mPois = 0; for (Int_t iEta = 0; iEta < nBin; iEta++) { for (Int_t iPhi = 0; iPhi < nBin; iPhi++) { Double_t p = res->GetBinContent(iEta, iPhi); Double_t t = base->GetBinContent(iEta, iPhi); mBase += t; mPois += p; corr->Fill(t, p); diff->Fill(p-t); } } Int_t nn = nBin * nBin; mean->Fill(mBase / nn, mPois / nn); } TCanvas* cc = new TCanvas("c", "c", 900, 900); cc->SetFillColor(0); cc->SetFillStyle(0); cc->SetBorderMode(0); cc->SetRightMargin(0.02); cc->SetTopMargin(0.02); cc->Divide(2,2); TVirtualPad* pp = cc->cd(1); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.15); pp->SetTopMargin(0.02); pp->SetLogz(); pp->SetGridx(); pp->SetGridy(); corr->Draw(); lcorr->Draw(); pp = cc->cd(2); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.02); pp->SetTopMargin(0.02); #if 0 c->GetMean()->Draw(); #elif 1 pp->SetLogy(); diff->Draw(); #elif 1 c->GetOccupancy()->Draw(); #else pp->SetLogy(); dist->SetStats(0); dist->Scale(1. / dist->Integral()); dist->Draw(); TH1D* m1 = c->GetMean(); m1->Scale(1. / m1->Integral()); m1->Draw("same"); Double_t eI; Double_t ii = 100 * dist->Integral(2, 0); TLatex* ll = new TLatex(.97, .85, Form("Input #bar{m}: %5.3f", mp)); ll->SetNDC(); ll->SetTextFont(132); ll->SetTextAlign(31); ll->Draw(); ll->DrawLatex(.97, .75, Form("Result #bar{m}: %5.3f", dist->GetMean())); ll->DrawLatex(.97, .65, Form("Occupancy: #int_{1}^{#infty}P(s)ds = %6.2f%%", ii)); #endif pp = cc->cd(3); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.15); pp->SetTopMargin(0.02); pp->SetGridx(); pp->SetGridy(); c->GetCorrection()->Draw(); pp = cc->cd(4); pp->SetFillColor(0); pp->SetFillStyle(0); pp->SetBorderMode(0); pp->SetRightMargin(0.15); pp->SetTopMargin(0.02); pp->SetLogz(); pp->SetGridx(); pp->SetGridy(); mean->Draw(); lmean->Draw(); cc->cd(); }
void plotMerged(Bool_t onlyPlot=0) { gStyle->SetPalette(1); TFile f("histoSum.root","UPDATE"); TH1F* hAllMC = f.Get("allMC"); TH1F* hAllFound= f.Get("allFound"); TH1F* hImperfect= f.Get("imperfect"); TH1F* hPerfect= f.Get("perfect"); TH1F* hNoMCTrack= f.Get("noMCtrack"); // have to be recalculated TH1F* hPurity = f.Get("purity"); TH1F* hEff= f.Get("efficiency"); TH1F* hFake= f.Get("fake"); TH1F* hAnna= f.Get("annaEff"); TH2D* h2Ddca= f.Get("dca2D"); TGraphErrors *d0= f.Get("dca"); TH2D* h2Dpt= f.Get("dPt2D"); TGraphErrors *gPt= f.Get("dPt"); if (!onlyPlot) { /* // Get Errors right hAllMC->Sumw2(); hAllFound->Sumw2(); hPerfect->Sumw2(); hImperfect->Sumw2(); h2Dpt->Sumw2(); h2Ddca->Sumw2(); */ // Efficiencies - and normalize to 100% TF1 f1("f1","100+x*0",0.,1.e3); hPurity->Divide(hPerfect,hAllFound,1,1,"b"); hPurity->Multiply(&f1); hPurity->SetMarkerColor(kGreen); hPurity->SetMarkerStyle(21); hPurity->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); hPurity->SetStats(0); hPurity->GetYaxis()->SetRangeUser(0,100); hPurity->SetTitle("Efficiency & Purity"); hEff->Divide(hPerfect,hAllMC,1,1,"b"); hEff->Multiply(&f1); hEff->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); hEff->SetMarkerColor(kBlue); hEff->SetMarkerStyle(21); hEff->SetStats(0); hFake->Divide(hImperfect,hAllMC,1,1,"b"); hFake->Multiply(&f1); hFake->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); hFake->SetMarkerColor(kRed); hFake->SetMarkerStyle(21); hFake->SetStats(0); hAnna->Divide(hAllFound,hAllMC,1,1,"b"); hAnna->Multiply(&f1); hAnna->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); hAnna->SetMarkerColor(kBlack); hAnna->SetMarkerStyle(21); hAnna->SetStats(0); // Impact parameter resolution --------------- TCanvas *c3 = new TCanvas("c3","impact");//,200,10,900,900); c3->Divide(2,1); c3->cd(1); h2Ddca->DrawCopy("colz"); h2Ddca->FitSlicesY() ; TH2D *dcaM = (TH2D*)gDirectory->Get("dca2D_1"); dcaM->Draw("same"); TH2D *dcaRMS = (TH2D*)gDirectory->Get("dca2D_2"); //dcaRMS->Draw(); TGraphErrors *d0 = new TGraphErrors(); for (Int_t ibin =1; ibin<=dcaRMS->GetXaxis()->GetNbins(); ibin++) { d0->SetPoint( ibin-1,dcaRMS->GetBinCenter(ibin),dcaRMS->GetBinContent(ibin)*1e4); // microns d0->SetPointError(ibin-1,0,dcaRMS->GetBinError(ibin)*1e4); // microns } d0->SetMarkerStyle(21); d0->SetMaximum(200); d0->SetMinimum(0); d0->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); d0->GetYaxis()->SetTitle("R-#phi Pointing Resolution (#mum)"); d0->SetName("dca"); d0->SetTitle("DCAvsPt"); // c3->cd(1); h2Ddca->Draw("surf2"); c3->cd(2); d0->Draw("APE"); // PT RESOLUTION ------------ TCanvas *c4 = new TCanvas("c4","pt resolution");//,200,10,900,900); c4->Divide(2,1); c4->cd(1); h2Dpt->DrawCopy("colz"); h2Dpt->FitSlicesY() ; TH2D *dPtM = (TH2D*)gDirectory->Get("dPt2D_1"); dPtM->Draw("same"); TH2D *dPtRMS = (TH2D*)gDirectory->Get("dPt2D_2"); // dPtRMS->Draw(""); TGraphErrors *gPt = new TGraphErrors(); for (Int_t ibin =1; ibin<=dPtRMS->GetXaxis()->GetNbins(); ibin++) { gPt->SetPoint( ibin-1,dPtRMS->GetBinCenter(ibin),dPtRMS->GetBinContent(ibin)); gPt->SetPointError(ibin-1,0,dPtRMS->GetBinError(ibin)); } gPt->SetMarkerStyle(21); gPt->SetMaximum(20); gPt->SetMinimum(0); gPt->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); gPt->GetYaxis()->SetTitle("relative momentum resolution (%)"); gPt->SetName("dPt"); gPt->SetTitle("DPTvsPt"); // c4->cd(1); h2Dpt->Draw("surf2"); c4->cd(2); gPt->Draw("APE"); // overwrite with normalized graphs hPurity->Write(); hEff->Write(); hFake->Write(); hAnna->Write(); h2Ddca->Write(); d0->Write(); h2Dpt->Write(); gPt->Write(); } // Plots TCanvas *c2 = new TCanvas("c2","Eff&Purity");//,200,10,900,900); TVirtualPad *pad = c2->cd(); pad->SetGridx(); pad->SetGridy(); // pad->SetLogx(); TLegend *leg = new TLegend(0.1,0.8,0.6,0.9);leg->SetFillColor(0); leg->AddEntry(hPurity,"Purity (\"Perfect tracks\" within \"Found Tracks\")","PE"); leg->AddEntry(hEff,"Efficiency (\"Perfect tracks\" within \"MC findable Tracks\")","PE"); leg->AddEntry(hFake,"Fake (\"Inperfect tracks\" within \"MC findable Tracks\")","PE"); leg->AddEntry(hAnna,"AnnaLisa - Efficiency (\"Found tracks\" within \"MC findable Tracks\")","PE"); hPurity->DrawCopy("E"); hEff->DrawCopy("Same E"); hFake->DrawCopy("Same E"); hAnna->DrawCopy("Same E"); leg->Draw(); c2->SaveAs("EffPlot.png"); f.Close(); }
void ExtractOutputHistos(Bool_t onlyPrims=0,Bool_t onlyPion=0,Int_t plotFlag=0) { // gROOT->SetStyle("Plain"); gStyle->SetPalette(1); const Int_t nbins=20; Double_t ptmin=0.06;//04; Double_t ptmax=2.0;//GeV Double_t logxmin = TMath::Log10(ptmin); Double_t logxmax = TMath::Log10(ptmax); Double_t binwidth = (logxmax-logxmin)/(nbins+1); enum {nb=nbins+1}; Double_t xbins[nb]; xbins[0] = ptmin; for (Int_t i=1;i<=nbins;i++) { xbins[i] = ptmin + TMath::Power(10,logxmin+(i)*binwidth); // cout<<xbins[i]<<endl; } // TH1F *h = new TH1F("h","hist with log x axis",nbins,xbins); TH1F *hMultCount = new TH1F("mult","averaged multiplicity (charg. prim)",80,-4.,4.); hMultCount->GetXaxis()->SetTitle("eta"); hMultCount->GetYaxis()->SetTitle("N/d#eta"); TH1F *hAllMC = new TH1F("allMC","All Tracks MC primaries",nbins,xbins); TH1F *hAllFound = new TH1F("allFound","All Tracks found",nbins,xbins); TH1F *hImperfect = new TH1F("imperfect","Imperfect tracks",nbins,xbins); TH1F *hPerfect = new TH1F("perfect","Perfect tracks",nbins,xbins); TH1F *hEff = new TH1F("efficiency","Efficiency (Perfect tracks in \"ALL MC\")",nbins,xbins); TH1F *hFake = new TH1F("fake","Fake tracks (Inperfect tracks in \"ALL MC\")",nbins,xbins); TH1F *hPurity = new TH1F("purity","Purity (Perfect tracks in \"All Found\")",nbins,xbins); TH1F *hAnna = new TH1F("annaEff","AnnalisaEff ",nbins,xbins); TH1F *hNoMCTrack = new TH1F("noMCtrack","noMCtrack ",nbins,xbins); TH1F *hEta = new TH1F("","",50,-2,2); // TH1F *hEtaMC = new TH1F("","",50,-2,2); TH2D *h2Ddca = new TH2D("dca2D","DCAvsPt2D",nbins,xbins,50,-0.05,0.05); TH2D *h2Dpt = new TH2D("dPt2D","dPtdvsPt2D",nbins,xbins,50,-25,25); // open run loader and load gAlice, kinematics and header AliRunLoader* runLoader = AliRunLoader::Open("galice.root"); if (!runLoader) { Error("Check kine", "getting run loader from file %s failed", "galice.root"); return; } runLoader->LoadgAlice(); gAlice = runLoader->GetAliRun(); if (!gAlice) { Error("Check kine", "no galice object found"); return; } runLoader->LoadHeader(); runLoader->LoadKinematics(); TFile* esdFile = TFile::Open("AliESDs.root"); if (!esdFile || !esdFile->IsOpen()) { Error("CheckESD", "opening ESD file %s failed", "AliESDs.root"); return; } AliESDEvent *esd = new AliESDEvent(); TTree* tree = (TTree*) esdFile->Get("esdTree"); if (!tree) { Error("CheckESD", "no ESD tree found"); return; } esd->ReadFromTree(tree); Int_t nTrackTotalMC = 0; Int_t nTrackFound = 0; Int_t nTrackImperfect = 0; Int_t nTrackPerfect = 0; Int_t nNoMCTrack = 0; for(Int_t iEv =0; iEv<tree->GetEntries(); iEv++){ tree->GetEvent(iEv); runLoader->GetEvent(iEv); printf("+++ event %i (of %lld) +++++++++++++++++++++++ # ESDtracks: %d \n",iEv,tree->GetEntries()-1,esd->GetNumberOfTracks()); Int_t nESDtracks = esd->GetNumberOfTracks(); for (Int_t iTrack = 0; iTrack < nESDtracks; iTrack++) { AliESDtrack* track = esd->GetTrack(iTrack); if (!(iTrack%1000)) printf("event %i: ESD track count %d (of %d)\n",iEv,iTrack,nESDtracks); Int_t label = track->GetLabel(); Int_t idx[12]; // Int_t ncl = track->GetITSclusters(idx); if(label<0) { // cout<< " ESD track label " << label; // cout<<" ---> imperfect track (label "<<label<<"<0) !! -> track Pt: "<< track->Pt() << endl; } AliStack* stack = runLoader->Stack(); // nTrackTotalMC += stack->GetNprimary(); TParticle* particle = stack->Particle(TMath::Abs(label)); Double_t pt = track->Pt(); if(particle) { if (TMath::Abs(particle->Eta())>etaCut) continue; Double_t ptMC = particle->Pt(); // Efficiencies if (onlyPion && TMath::Abs(particle->GetPdgCode())!=211) continue; if ( (!onlyPrims) || stack->IsPhysicalPrimary(TMath::Abs(label))) { // cout<<" # clusters "<<ncl<<endl; nTrackFound++; hAllFound->Fill(ptMC); hEta->Fill(track->Eta()); if (label<0) { nTrackImperfect++; hImperfect->Fill(ptMC); } else { nTrackPerfect++; hPerfect->Fill(ptMC); } } // following only for "true tracks, pions if(particle->Pt() < 0.001)continue; if (TMath::Abs(particle->GetPdgCode())!=211) continue; if (label>0) { // Impact parameters for Pions only Double_t dca = track->GetD(0,0,0.5); h2Ddca->Fill(ptMC,dca); // Pt resolution for Pions only Double_t dPt = (pt-ptMC)/ptMC*100; h2Dpt->Fill(ptMC,dPt); } } else { nNoMCTrackFound++; hNoMCTrack->Fill(pt); cout<<" according MC particle not found"<<endl; } } //entries track esd }//entries tree runLoader->UnloadHeader(); runLoader->UnloadKinematics(); delete runLoader; // Count trackable MC tracks CountTrackableMCs(hAllMC, onlyPrims, onlyPion); // Count trackable MC tracks CountPrimaries(hMultCount); // Get Errors right hMultCount->Sumw2(); hAllMC->Sumw2(); hAllFound->Sumw2(); hPerfect->Sumw2(); hImperfect->Sumw2(); h2Dpt->Sumw2(); h2Ddca->Sumw2(); // -- Global efficienies nTrackTotalMC = hAllMC->GetEntries(); Double_t eff = ((Double_t)nTrackPerfect)/nTrackTotalMC; printf("-> Total number of events: %lld -> MCtracks %d -> nPerfect %d -> Eff: %3.2lf \n", tree->GetEntries(),nTrackTotalMC,nTrackPerfect,eff); Double_t purity = ((Double_t)nTrackPerfect)/nTrackFound; printf("-> Total number of events: %lld -> FoundTracks %d -> nPerfect %d -> Purity: %3.2lf \n", tree->GetEntries(),nTrackFound,nTrackPerfect,purity); // Efficiencies - and normalize to 100% TF1 f1("f1","100+x*0",0.,1.e3); hPurity->Divide(hPerfect,hAllFound,1,1,"b"); hPurity->Multiply(&f1); hPurity->SetMarkerColor(kGreen); hPurity->SetMarkerStyle(21); hPurity->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); hPurity->SetStats(0); hPurity->GetYaxis()->SetRangeUser(0,100); hPurity->SetTitle("Efficiency & Purity"); hEff->Divide(hPerfect,hAllMC,1,1,"b"); hEff->Multiply(&f1); hEff->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); hEff->SetMarkerColor(kBlue); hEff->SetMarkerStyle(21); hEff->SetStats(0); hFake->Divide(hImperfect,hAllMC,1,1,"b"); hFake->Multiply(&f1); hFake->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); hFake->SetMarkerColor(kRed); hFake->SetMarkerStyle(21); hFake->SetStats(0); hAnna->Divide(hAllFound,hAllMC,1,1,"b"); hAnna->Multiply(&f1); hAnna->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); hAnna->SetMarkerColor(kBlack); hAnna->SetMarkerStyle(21); hAnna->SetStats(0); TCanvas *c1 = new TCanvas("c1","NoMCTrackFound");//,200,10,900,900); TVirtualPad *pad = c1->cd(); pad->SetGridx(); pad->SetGridy(); hNoMCTrack->Draw(); TCanvas *c2 = new TCanvas("c2","Eff&Purity");//,200,10,900,900); TVirtualPad *pad = c2->cd(); pad->SetGridx(); pad->SetGridy(); // pad->SetLogx(); hPurity->Draw("E"); hEff->Draw("Same E"); hFake->Draw("Same E"); hAnna->Draw("Same E"); TLegend *leg = new TLegend(0.1,0.8,0.6,0.9);leg->SetFillColor(0); leg->AddEntry(hPurity,"Purity (\"Perfect tracks\" within \"Found Tracks\")","PE"); leg->AddEntry(hEff,"Efficiency (\"Perfect tracks\" within \"MC findable Tracks\")","PE"); leg->AddEntry(hFake,"Fake (\"Inperfect tracks\" within \"MC findable Tracks\")","PE"); leg->AddEntry(hAnna,"AnnaLisa - Efficiency (\"Found tracks\" within \"MC findable Tracks\")","PE"); leg->Draw(); if (plotFlag==1){ hAllMC->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); hAllMC->Draw(); // MC pt distribution hAllFound->SetLineColor(2); hAllFound->Draw("same"); // MC pt distribution } /* .L ~/ITSupgrade/BuildDetector/DetectorK.cxx+ // All NEW DetectorK its("ALICE","ITS"); its.MakeAliceAllNew(0); its.SetMaxRadiusOfSlowDetectors(0.01); its.SolveViaBilloir(0); TGraph *c = its.GetGraphRecoEfficiency(0,3,2); c->Draw("C"); // Current DetectorK its("ALICE","ITS"); its.MakeAliceCurrent(0,0); its.SetMaxRadiusOfSlowDetectors(0.01); its.SolveViaBilloir(0); TGraph *c = its.GetGraphRecoEfficiency(0,4,2); c->Draw("C"); */ TCanvas *c3 = new TCanvas("c3","impact");//,200,10,900,900); c3->Divide(2,1); c3->cd(1); // Impact parameter // Impact parameter resolution --------------- h2Ddca->Draw("colz"); h2Ddca->FitSlicesY() ; TH2D *dcaM = (TH2D*)gDirectory->Get("dca2D_1"); dcaM->Draw("same"); TH2D *dcaRMS = (TH2D*)gDirectory->Get("dca2D_2"); //dcaRMS->Draw(); TGraphErrors *d0 = new TGraphErrors(); for (Int_t ibin =1; ibin<=dcaRMS->GetXaxis()->GetNbins(); ibin++) { d0->SetPoint( ibin-1,dcaRMS->GetBinCenter(ibin),dcaRMS->GetBinContent(ibin)*1e4); // microns d0->SetPointError(ibin-1,0,dcaRMS->GetBinError(ibin)*1e4); // microns } d0->SetMarkerStyle(21); d0->SetMaximum(200); d0->SetMinimum(0); d0->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); d0->GetYaxis()->SetTitle("R-#phi Pointing Resolution (#mum)"); d0->SetName("dca"); d0->SetTitle("DCAvsPt"); c3->cd(1); h2Ddca->Draw("surf2"); c3->cd(2); d0->Draw("APE"); // PT RESOLUTION ------------ TCanvas *c4 = new TCanvas("c4","pt resolution");//,200,10,900,900); c4->Divide(2,1); c4->cd(1); // Impact parameter h2Dpt->Draw("colz"); h2Dpt->FitSlicesY() ; TH2D *dPtM = (TH2D*)gDirectory->Get("dPt2D_1"); dPtM->Draw("same"); TH2D *dPtRMS = (TH2D*)gDirectory->Get("dPt2D_2"); // dPtRMS->Draw(""); TGraphErrors *gPt = new TGraphErrors(); for (Int_t ibin =1; ibin<=dPtRMS->GetXaxis()->GetNbins(); ibin++) { gPt->SetPoint( ibin-1,dPtRMS->GetBinCenter(ibin),dPtRMS->GetBinContent(ibin)); gPt->SetPointError(ibin-1,0,dPtRMS->GetBinError(ibin)); } gPt->SetMarkerStyle(21); gPt->SetMaximum(20); gPt->SetMinimum(0); gPt->GetXaxis()->SetTitle("transverse momentum p_{t} (GeV)"); gPt->GetYaxis()->SetTitle("relative momentum resolution (%)"); gPt->SetName("dPt"); gPt->SetTitle("DPTvsPt"); c4->cd(1); h2Dpt->Draw("surf2"); c4->cd(2); gPt->Draw("APE"); // EXPORT -------- TFile f("histos.root","RECREATE"); hMultCount->Write(); hAllMC->Write(); hAllFound->Write(); hImperfect->Write(); hPerfect->Write(); hNoMCTrack->Write(); hPurity->Write(); hEff->Write(); hFake->Write(); hAnna->Write(); h2Ddca->Write(); d0->Write(); h2Dpt->Write(); gPt->Write(); f.Close(); return; }
void validation() { msglvl[DBG] = SILENT; msglvl[INF] = VISUAL; msglvl[WRN] = VISUAL; msglvl[ERR] = VISUAL; msglvl[FAT] = VISUAL; TDirectory* oldDir = gDirectory; // remember old directory style(); Int_t g4bin = (ng4bins/g4max+1); //==> g^4=1 ==> SSM ! TString suffix = ""; if(doTruth) suffix = "_truth"; TString mctype = (isMC11c) ? "mc11c" : "mc11a"; // TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_overallEWkF_noInAmpSigEWkF_noHighMbins_wthOfficialZP_Xmass2000.root"; // TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root"; // TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_wthOfficialZP_treeLevelMass_Xmass2000.root"; // TString fBGname = "plots/ZP_2dtemplates_mc11c_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_wthOfficialZP_fixedBWwidth_treeLevelMass_Xmass2000.root"; // TString fBGname = "plots/ZP_2dtemplates_mc11c_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root"; // TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root"; // TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_fixedBWwidth_treeLevelMass_Xmass2000.root"; TLegend* legR = new TLegend(0.15,0.75,0.35,0.85,NULL,"brNDC"); legR->SetFillStyle(4000); //will be transparent legR->SetFillColor(0); legR->SetTextFont(42); TH1D* hDummy = new TH1D("","",1,0.,1.); hDummy->SetMarkerStyle(20); hDummy->SetMarkerSize(0.8); hDummy->SetMarkerColor(kBlack); if(!doResiduals) legR->AddEntry(hDummy,"#frac{template}{official}","lep"); else legR->AddEntry(hDummy,"#frac{template - official}{#sqrt{#delta^{2}template + #delta^{2}official}}","lep"); TPaveText* ptxt = new TPaveText(0.145,0.35,0.245,0.55,"NDC"); TText* txt; ptxt->SetTextSize(0.03); ptxt->SetBorderSize(0); ptxt->SetFillStyle(4000); //will be transparent ptxt->SetFillColor(0); ptxt->SetTextAlign(12); txt = ptxt->AddText("This range"); txt = ptxt->AddText("is chopped"); txt = ptxt->AddText("before the"); txt = ptxt->AddText("template is"); txt = ptxt->AddText("handed to"); txt = ptxt->AddText("BAT (limit)."); oldDir->cd(); TString fBGname = "plots/validation/ZP_2dtemplates_mc11c_33st_noKKtmplates_wthOfficialZP_treeLevelMass_Xmass2000.root"; TFile* fD = new TFile(fBGname,"READ"); TH1D* hDY = NULL; if(doTruth) hDY = (TH1D*)fD->Get("hMass_DYmumu_truth")->Clone(); else hDY = (TH1D*)fD->Get("hMass_DYmumu")->Clone(); hDY->SetLineColor(kMagenta-5); hDY->SetMarkerColor(kMagenta-5); oldDir->cd(); TFile* fDYrozmin = new TFile("plots/mass_plot_tables_3st.root","READ"); TH1D* hDYrozmin = (TH1D*)fDYrozmin->Get("mass_log_dy")->Clone(); hDYrozmin = (TH1D*)hGeV2TeV(hDYrozmin)->Clone(); hDYrozmin = (TH1D*)hChopper(hDYrozmin,bins2chop)->Clone(); oldDir->cd(); TFile* f1dTemplates = new TFile("plots/ZpSignal_MM_MC11c_5points.root","READ"); TObjArray* toarr1d = new TObjArray(); toarr1d->Read("template"); TMapTSP2TH1D h1dBrandeisTmpltMap; double Nflat = 399948; double sigmaflat = 4.3988E+07*nb2fb; double Lmcflat = Nflat/sigmaflat; double scale = luminosity/Lmcflat; TH1D* h1dTmp = NULL; h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(0/*22*/))->Clone(); h1dTmp->Scale(scale); h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone(); h1dTmp->Add(hDYrozmin); h1dBrandeisTmpltMap.insert( make_pair("1000",(TH1D*)resetErrors(h1dTmp)->Clone("1000")) ); h1dTmp = NULL; h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(1/*28*/))->Clone(); h1dTmp->Scale(scale); h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone(); h1dTmp->Add(hDYrozmin); h1dBrandeisTmpltMap.insert( make_pair("1250",(TH1D*)resetErrors(h1dTmp)->Clone("1250")) ); h1dTmp = NULL; h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(2/*34*/))->Clone(); h1dTmp->Scale(scale); h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone(); h1dTmp->Add(hDYrozmin); h1dBrandeisTmpltMap.insert( make_pair("1500",(TH1D*)resetErrors(h1dTmp)->Clone("1500")) ); h1dTmp = NULL; h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(3/*40*/))->Clone(); h1dTmp->Scale(scale); h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone(); h1dTmp->Add(hDYrozmin); h1dBrandeisTmpltMap.insert( make_pair("1750",(TH1D*)resetErrors(h1dTmp)->Clone("1750")) ); h1dTmp = NULL; h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(4/*47*/))->Clone(); h1dTmp->Scale(scale); h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone(); h1dTmp->Add(hDYrozmin); h1dBrandeisTmpltMap.insert( make_pair("2000",(TH1D*)resetErrors(h1dTmp)->Clone("2000")) ); oldDir->cd(); TMapTSP2TH1D h1Map; h1Map.insert( make_pair("1000o", (TH1D*)fD->Get("hMass_Zprime_SSM1000"+suffix)->Clone()) ); h1Map.insert( make_pair("1000t", (TH1D*)fD->Get("hMass_Zprime_SSM1000_template"+suffix)->Clone()) ); if(isMC11c) { h1Map.insert( make_pair("1250o", (TH1D*)fD->Get("hMass_Zprime_SSM1250"+suffix)->Clone()) ); h1Map.insert( make_pair("1250t", (TH1D*)fD->Get("hMass_Zprime_SSM1250_template"+suffix)->Clone()) ); } h1Map.insert( make_pair("1500o", (TH1D*)fD->Get("hMass_Zprime_SSM1500"+suffix)->Clone()) ); h1Map.insert( make_pair("1500t", (TH1D*)fD->Get("hMass_Zprime_SSM1500_template"+suffix)->Clone()) ); h1Map.insert( make_pair("1750o", (TH1D*)fD->Get("hMass_Zprime_SSM1750"+suffix)->Clone()) ); h1Map.insert( make_pair("1750t", (TH1D*)fD->Get("hMass_Zprime_SSM1750_template"+suffix)->Clone()) ); h1Map.insert( make_pair("2000o", (TH1D*)fD->Get("hMass_Zprime_SSM2000"+suffix)->Clone()) ); h1Map.insert( make_pair("2000t", (TH1D*)fD->Get("hMass_Zprime_SSM2000_template"+suffix)->Clone()) ); TMapTSP2TH1D h1rMap; h1rMap.insert( make_pair("1000", (TH1D*)fD->Get("hMass_Zprime_SSM1000"+suffix)->Clone()) ); if(isMC11c) h1rMap.insert( make_pair("1250", (TH1D*)fD->Get("hMass_Zprime_SSM1250"+suffix)->Clone()) ); h1rMap.insert( make_pair("1500", (TH1D*)fD->Get("hMass_Zprime_SSM1500"+suffix)->Clone()) ); h1rMap.insert( make_pair("1750", (TH1D*)fD->Get("hMass_Zprime_SSM1750"+suffix)->Clone()) ); h1rMap.insert( make_pair("2000", (TH1D*)fD->Get("hMass_Zprime_SSM2000"+suffix)->Clone()) ); for(TMapTSP2TH1D::iterator it=h1rMap.begin() ; it!=h1rMap.end() ; ++it) { it->second->Reset(); if(!doResiduals) it->second->Divide(h1Map[it->first+"o"],h1Map[it->first+"t"],1.,1.,"B"); else residuals(h1Map[it->first+"o"], h1Map[it->first+"t"], it->second); // for(Int_t i=0 ; i<=it->second->GetNbinsX()+1 ; i++) it->second->SetBinError(i,0); it->second->SetMarkerStyle(20); it->second->SetMarkerSize(0.5); it->second->GetXaxis()->SetLabelSize(0.073); it->second->GetYaxis()->SetLabelSize(0.073); it->second->GetXaxis()->SetTitleSize(0.073); it->second->GetYaxis()->SetTitleSize(0.073); it->second->SetTitleSize(0.075); it->second->GetYaxis()->SetTitleOffset(0.5); if(!doResiduals) { it->second->SetMinimum(0.2); it->second->SetMaximum(1.8); } else { it->second->SetMinimum(-5.); it->second->SetMaximum(+5.); } it->second->SetTitle(""); if(!doResiduals) it->second->GetYaxis()->SetTitle("ratio"); else it->second->GetYaxis()->SetTitle("residuals"); } TMapTSP2TGAE poissonGraphMap; TMapTSP2TLeg legMap; _INFO(""); oldDir->cd(); fD->cd(); TH1D* h1Template = (TH1D*)fD->Get("hMass_DYmumu"+suffix)->Clone(); h1Template->Reset(); TObjArray* toarr = new TObjArray(); if(doTruth) toarr->Read("truth_template2d"); else toarr->Read("template2d"); TH2D* h2SSM2000 = (TH2D*)((TObjArray*)toarr->At(0))->Clone("hMass"+suffix+"_Zprime_SSM2000_template2d"); for(Int_t bin=1 ; bin<=h2SSM2000->GetNbinsX() ; bin++) { h1Template->SetBinContent(bin, h2SSM2000->GetBinContent(bin,g4bin)); h1Template->SetBinError(bin, h2SSM2000->GetBinError(bin,g4bin)); } h1Template->SetLineColor(kViolet); h1Template->SetLineWidth(1); h1Template->SetMarkerStyle(20); h1Template->SetMarkerSize(0.3); h1Template->SetMarkerColor(kViolet); // the functions h2Template = (TH2D*)h2SSM2000->Clone(); vector<TF1*> vfunc; unsigned int nmllbins = h2Template->GetNbinsX(); for(unsigned int mll=1 ; mll<=(nmllbins-bins2chop) ; mll++) // 1...(56-9 = 47) { TString mllname = (TString)_s(mll); TString mllval = (TString)_s(h2Template->GetXaxis()->GetBinCenter(mll+bins2chop)); TF1* f = new TF1("fNominal_mll"+mllname,fTH1toTF1,g4min,g4max,1); f->SetParameter(0,mll); f->SetParNames("mll"); // f->SetLineColor(kBlue); // f->SetLineWidth(1); f->SetNpx(400); vfunc.push_back(f); } TGraph* graphDY = new TGraph(); graphDY->SetMarkerStyle(25); graphDY->SetMarkerSize(0.6); graphDY->SetMarkerColor(kGreen+2); TGraph* graphSSM = new TGraph(); graphSSM->SetMarkerStyle(24); graphSSM->SetMarkerSize(0.6); graphSSM->SetMarkerColor(kOrange+8); for(unsigned int i=0 ; i<vfunc.size() ; i++) { double DY = vfunc[i]->Eval(0.0); double SSM = vfunc[i]->Eval(1.0); graphDY->SetPoint(i,h2Template->GetXaxis()->GetBinCenter(bins2chop+i+1),DY); graphSSM->SetPoint(i,h2Template->GetXaxis()->GetBinCenter(bins2chop+i+1),SSM); } oldDir->cd(); TObjArray* toarr1dTLV = new TObjArray(); TMapTSP2TH1D h1dTlvTmpltMap; TFile* fT = NULL; TString fTname = "plots/validation/ZP_2dtemplates_mc11c_33st_noInterference_noKKtmplates_noOverallEWkF_wthOfficialZP_treeLevelMass_Xmass"; fT = new TFile(fTname+"1000.root","READ"); toarr1dTLV->Read("template"); h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone(); h1dTmp->Add(hDY); h1dTlvTmpltMap.insert( make_pair("1000",(TH1D*)resetErrors(h1dTmp)->Clone("1000")) ); fT = new TFile(fTname+"1250.root","READ"); toarr1dTLV->Read("template"); h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone(); h1dTmp->Add(hDY); h1dTlvTmpltMap.insert( make_pair("1250",(TH1D*)resetErrors(h1dTmp)->Clone("1250")) ); fT = new TFile(fTname+"1500.root","READ"); toarr1dTLV->Read("template"); h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone(); h1dTmp->Add(hDY); h1dTlvTmpltMap.insert( make_pair("1500",(TH1D*)resetErrors(h1dTmp)->Clone("1500")) ); fT = new TFile(fTname+"1750.root","READ"); toarr1dTLV->Read("template"); h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone(); h1dTmp->Add(hDY); h1dTlvTmpltMap.insert( make_pair("1750",(TH1D*)resetErrors(h1dTmp)->Clone("1750")) ); fT = new TFile(fTname+"2000.root","READ"); toarr1dTLV->Read("template"); h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone(); h1dTmp->Add(hDY); h1dTlvTmpltMap.insert( make_pair("2000",(TH1D*)resetErrors(h1dTmp)->Clone("2000")) ); oldDir->cd(); for(TMapTSP2TH1D::iterator it=h1Map.begin() ; it!=h1Map.end() ; ++it) { if(it->first.Contains("o")) { TString name = it->first; name.ReplaceAll("o",""); it->second->SetFillColor(kAzure-9); if(doTruth) it->second->SetTitle("m_{Z'} = "+name+" GeV (truth)"); else it->second->SetTitle("m_{Z'} = "+name+" GeV"); } if(it->first.Contains("t")) { //TGraphAsymmErrors* poisson(TH1D* h) it->second->SetLineColor(kBlue); it->second->SetMarkerStyle(20); it->second->SetMarkerSize(0.4); it->second->SetMarkerColor(kBlue); it->second->SetLineWidth(1); TString name = it->first; name.ReplaceAll("t",""); poissonGraphMap.insert( make_pair(name, (TGraphAsymmErrors*)poisson(it->second)->Clone()) ); poissonGraphMap[name]->SetMarkerStyle(20); poissonGraphMap[name]->SetMarkerSize(0.3); poissonGraphMap[name]->SetMarkerColor(kBlue); poissonGraphMap[name]->SetLineWidth(1); poissonGraphMap[name]->SetLineColor(kBlue); } } Double_t yLine = (!doResiduals) ? 1. : 0.; TLine* line = new TLine(0.07,yLine,3.,yLine); line->SetLineColor(kRed); line->SetLineWidth(2); TMapTSP2TCNV cnvMap; cnvMap.insert( make_pair("1000", new TCanvas("1000","1000",600,550)) ); if(isMC11c) cnvMap.insert( make_pair("1250", new TCanvas("1250","1250",600,550)) ); cnvMap.insert( make_pair("1500", new TCanvas("1500","1500",600,550)) ); cnvMap.insert( make_pair("1750", new TCanvas("1750","1750",600,550)) ); cnvMap.insert( make_pair("2000", new TCanvas("2000","2000",600,550)) ); for(TMapTSP2TCNV::iterator it=cnvMap.begin() ; it!=cnvMap.end() ; ++it) { _INFO("starting "+(string)it->first); if(it->first=="2000") legMap.insert( make_pair(it->first, new TLegend(0.35,0.55,0.83,0.84,NULL,"brNDC")) ); else legMap.insert( make_pair(it->first, new TLegend(0.35,0.60,0.83,0.84,NULL,"brNDC")) ); legMap[it->first]->SetFillStyle(4000); //will be transparent legMap[it->first]->SetFillColor(0); legMap[it->first]->SetTextFont(42); legMap[it->first]->AddEntry(h1Map[it->first+"o"],"Official Z'_{SSM}","F"); legMap[it->first]->AddEntry(hDY,"Official DY#mu#mu","lep"); legMap[it->first]->AddEntry(h1Map[it->first+"t"],"ME^{2} method: Template w/o couplings scale","lep"); if(it->first=="2000") { legMap[it->first]->AddEntry(h1Template,"ME^{2} method: Template histogram at #it{g=1} (SSM)","lep"); legMap[it->first]->AddEntry(graphSSM, "ME^{2} method: Template function at #it{g=1} (SSM)","p"); legMap[it->first]->AddEntry(graphDY, "ME^{2} method: Template function at #it{g=0} (DY)","p"); } if(!doTruth) { h1dTlvTmpltMap[it->first]->SetLineColor(kCyan+2); h1dTlvTmpltMap[it->first]->SetMarkerColor(kCyan+2); h1dTlvTmpltMap[it->first]->SetMarkerStyle(5); h1dTlvTmpltMap[it->first]->SetMarkerSize(0.5); legMap[it->first]->AddEntry(h1dTlvTmpltMap[it->first],"ME^{2} method: DY+Template (no interference)","p"); h1dBrandeisTmpltMap[it->first]->SetLineColor(kRed); h1dBrandeisTmpltMap[it->first]->SetMarkerColor(kRed); h1dBrandeisTmpltMap[it->first]->SetMarkerStyle(27); h1dBrandeisTmpltMap[it->first]->SetMarkerSize(0.5); legMap[it->first]->AddEntry(h1dBrandeisTmpltMap[it->first],"Flat Z' method: DY+Template (no interference)","p"); } it->second->Divide(1,2); TVirtualPad* ph = it->second->cd(1); TVirtualPad* pr = it->second->cd(2); ph->SetPad(0.00, 0.35, 1.00, 1.00); pr->SetPad(0.00, 0.00, 1.00, 0.35); ph->SetBottomMargin(0.012); pr->SetBottomMargin(0.20); pr->SetTopMargin(0.012); ph->cd(); ph->Draw(); ph->SetTicks(1,1); ph->SetLogy(); ph->SetLogx(); // h1Map[it->first+"o"]->SetMaximum( h1Map[it->first+"t"]->GetMaximum()*1.5 ); // h1Map[it->first+"o"]->Draw(); TH1D* hTmpNoErr = (TH1D*)resetErrors(h1Map[it->first+"o"])->Clone(); hTmpNoErr->SetMaximum( h1Map[it->first+"t"]->GetMaximum()*1.5 ); hTmpNoErr->SetLineStyle(1); hTmpNoErr->SetLineColor(kBlack); hTmpNoErr->SetFillColor(kAzure-9); hTmpNoErr->Draw(); TH1D* hTmpErr = (TH1D*)ShiftLog(h1Map[it->first+"o"],0.2)->Clone(); hTmpErr->SetFillStyle(4000); //will be transparent hTmpErr->SetFillColor(0); hTmpErr->DrawCopy("epx0SAMES"); hDY->Draw("SAMES"); h1Map[it->first+"t"]->Draw("epSAMES"); //poissonGraphMap[it->first]->Draw("pSAMES"); if(it->first=="2000") { graphDY->Draw("SAMESp"); graphSSM->Draw("SAMESp"); h1Template->Draw("epSAMES"); } _INFO(""); h1dTlvTmpltMap[it->first]->Draw("SAMESp"); h1dBrandeisTmpltMap[it->first]->Draw("SAMESp"); TLine* chopline = new TLine(0.12805,getYmin(h1Map[it->first+"o"]),0.12805,7.e5); chopline->SetLineStyle(2); chopline->SetLineColor(kBlack); chopline->Draw("SAMES"); ptxt->Draw("SAMES"); legMap[it->first]->Draw("SAMES"); ph->RedrawAxis(); ph->Update(); _INFO(""); pr->cd(); pr->Draw(); pr->SetTicks(1,1); pr->SetGridy(); pr->SetLogx(); h1rMap[it->first]->Draw("ep"); line->Draw("SAMES"); h1rMap[it->first]->Draw("epSAMES"); legR->Draw("SAMES"); pr->RedrawAxis(); pr->Update(); unsigned int savestate = 1; if(it->first=="1000") savestate = 0; else if(it->first=="2000") savestate = 2; else savestate = 1; TString testType = (doResiduals) ? "_residuals" : "_ratio"; mutype = (doTruth) ? "_truth" : "_recon"; savemultipdf(it->second, "plots/validation/validation"+mutype+testType+"_"+mctype+"_all.pdf", savestate); saveas(it->second, "plots/validation/validation"+mutype+testType+"_"+mctype+"_"+it->first); TCanvas* c = new TCanvas(it->first,"",600,400); c->cd(); c->Draw(); c->SetTicks(1,1); c->SetLogy(); c->SetLogx(); hTmpNoErr->Draw(); hTmpErr->DrawCopy("epx0SAMES"); hDY->Draw("SAMES"); h1Map[it->first+"t"]->Draw("epSAMES"); //poissonGraphMap[it->first]->Draw("pSAMES"); if(it->first=="2000") { graphDY->Draw("SAMESp"); graphSSM->Draw("SAMESp"); h1Template->Draw("epSAMES"); } h1dTlvTmpltMap[it->first]->Draw("SAMESp"); h1dBrandeisTmpltMap[it->first]->Draw("SAMESp"); legMap[it->first]->Draw("SAMES"); chopline->Draw("SAMES"); ptxt->Draw("SAMES"); c->RedrawAxis(); c->Update(); saveas(c,"plots/validation/validation_"+it->first+"_"+mutype+testType); _INFO("done "+(string)it->first); } }