Skip to content

Commit 28f8d42

Browse files
author
Biao Zhang
committed
Add the simple code for 2D
1 parent 93ce951 commit 28f8d42

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

analysis/plots_2D.C

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#if !defined(__CINT__) || defined(__MAKECINT__)
2+
#include "TCanvas.h"
3+
#include "TDatabasePDG.h"
4+
#include "TEfficiency.h"
5+
#include "TF1.h"
6+
#include "TFile.h"
7+
#include "TH1D.h"
8+
#include "TH2D.h"
9+
#include "TLatex.h"
10+
#include "TMath.h"
11+
#include "TStyle.h"
12+
#endif
13+
14+
using namespace std;
15+
16+
Int_t nPtBins = 0;
17+
const Int_t nPtBinsToBeAnalyzed = 9;
18+
Double_t ptBinLimits[nPtBinsToBeAnalyzed] = {0};
19+
20+
void mystyle();
21+
22+
void plots_2D(const char *signalfilename = "final/nopid_sig.root") {
23+
24+
mystyle();
25+
26+
TFile *input_signal = new TFile(signalfilename, "read");
27+
TCanvas *cnvSig = new TCanvas("cnvSig", "Signal fit", 1500, 1000);
28+
cnvSig->Divide(3, 2);
29+
30+
auto dir_sig = (TDirectory *)input_signal->GetDirectory("hf-task-jpsi-mc");
31+
32+
auto hPtvsEtapr0 = (TH2D *)dir_sig->Get("hPtvsEtaGenProng0");
33+
auto hPtvsEtapr1 = (TH2D *)dir_sig->Get("hPtvsEtaGenProng1");
34+
auto hPtvsEtaGen = (TH2D *)dir_sig->Get("hPtvsEtaGen");
35+
auto hPtvsYRec = (TH2D *)dir_sig->Get("hPtvsYRecSig");
36+
auto hPtvsYGen = (TH2D *)dir_sig->Get("hYGen");
37+
38+
nPtBins = TMath::Min(hPtvsEtapr0->GetNbinsY(), nPtBinsToBeAnalyzed);
39+
40+
for (int i = 0; i < nPtBins; i++) {
41+
ptBinLimits[i] = hPtvsEtapr0->GetYaxis()->GetBinLowEdge(i + 1);
42+
ptBinLimits[i + 1] = hPtvsEtapr0->GetYaxis()->GetBinLowEdge(i + 1) +
43+
hPtvsEtapr0->GetYaxis()->GetBinWidth(i + 1);
44+
}
45+
46+
hPtvsEtapr0->SetTitle(
47+
"#it{p}_{T} (J/#psi) vs #it{p}_{T} "
48+
"daughter;#it{p}_{T}(prong0)(Gev/c);p_{T}(J/#psi)(Gev/#it{c}");
49+
hPtvsEtapr1->SetTitle(
50+
"#it{p}_{T} (J/#psi) vs #it{p}_{T} "
51+
"daughter;#it{p}_{T}(prong1)(Gev/c);p_{T}(J/#psi)(Gev/#it{c}c");
52+
hPtvsEtaGen->SetTitle("#it{p}_{T} vs #eta (Gen. "
53+
"Level);#eta(Gen);#it{p}_{T}(J/#psi)(Gev/#it{c}");
54+
hPtvsYRec->SetTitle(
55+
"#it{p}_{T} vs y (rec. Level);rapidity;#it{p}_{T}(J/#psi)(Gev/#it{c}");
56+
57+
cnvSig->cd(1);
58+
gPad->SetLogz();
59+
hPtvsEtapr0->Draw("colz");
60+
cnvSig->cd(2);
61+
gPad->SetLogz();
62+
hPtvsEtapr1->Draw("colz");
63+
cnvSig->cd(3);
64+
gPad->SetLogz();
65+
hPtvsEtaGen->Draw("colz");
66+
cnvSig->cd(4);
67+
gPad->SetLogz();
68+
// hPtvsYRec->Rebin2D(10,10,"hPtvsYRec");
69+
hPtvsYRec->Draw("colz");
70+
71+
auto g5 = (TH2D *)hPtvsYRec->Clone();
72+
auto g6 = (TH2D *)hPtvsYGen->Clone();
73+
g5->SetTitle("distribution of efficiency;rapidity;p_{T}(J/#psi)(Gev/c");
74+
75+
g5->Divide(g6);
76+
77+
cnvSig->cd(5);
78+
// gPad->SetLogz();
79+
g5->Rebin2D(4, 4, "g5");
80+
g5->Draw("colz ");
81+
82+
TFile *fileOutEff = new TFile("eff.root", "recreate");
83+
hPtvsEtapr0->Write();
84+
hPtvsEtapr1->Write();
85+
hPtvsEtaGen->Write();
86+
hPtvsYRec->Write();
87+
88+
cnvSig->SaveAs("2D_plots.pdf");
89+
fileOutEff->Close();
90+
}
91+
92+
//====================================================================================================================================================
93+
94+
void mystyle() {
95+
96+
gROOT->ForceStyle();
97+
gStyle->SetOptStat(0);
98+
gStyle->SetFrameLineWidth(2);
99+
gStyle->SetTitleSize(0.045, "x");
100+
gStyle->SetTitleSize(0.045, "y");
101+
gStyle->SetMarkerSize(1);
102+
gStyle->SetLineWidth(2);
103+
gStyle->SetLabelOffset(0.015, "x");
104+
gStyle->SetLabelOffset(0.01, "y");
105+
gStyle->SetTitleOffset(1, "x");
106+
gStyle->SetTitleOffset(0.8, "y");
107+
gStyle->SetTextSize(0.03);
108+
gStyle->SetTextAlign(5);
109+
gStyle->SetTextColor(1);
110+
}
111+
112+
//====================================================================================================================================================

0 commit comments

Comments
 (0)