-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_fits_try.cpp
208 lines (188 loc) · 7.87 KB
/
plot_fits_try.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
constexpr float minpt = 0;
constexpr float maxpt = 6;
constexpr float miny[] = {0.3,-2.3};
constexpr float maxy[] = {1.4,2.3};
constexpr double sx[2]{0.355,1.-2*sx[0]};
constexpr double sy[2]{0.35,0.15};
constexpr double sy_top[2]{0.,-0.0525};
constexpr double sy_bot[2]{0.,+0.0525};
constexpr double fx = sx[1];
constexpr double fy = 0.85;
double global_y = 1.;
double global_x = 0.;
const char *titles[2]={"; ;antimatter / matter", "; ;pull"};
const char *particle_ratios[] = {"#Omega","#pi","p","{}^{3}_{#Lambda}H","{}^{3}H","{}^{3}He"};
constexpr int nRow=4;
constexpr int nCol=3;
std::array<TPad*,12> CreatePads(TCanvas* &cv)
{
if (!cv) cv = new TCanvas;
std::array<TPad*,12> pads{nullptr};
for (int iP = 0; iP < 12; ++iP) {
const int col = iP % nCol;
const int row = iP / nCol;
int top = (row == 0);
int bot_global = (row == 3);
int top_low = (row == 2);
int bot = (row == (nRow - 1) || row == (nRow-3));
int left = col==0;
int right = col==(nCol-1);
int center = !(left || right);
std::cout << sx[0] * col << "\t" << global_y - sy[bot] - sy_top[top_low] - sy_bot[bot_global] << "\t" << sx[0] + col * (1. - sx[0]) << "\t" << global_y << std::endl;
if (!((row== 1 && col==2)||(row==0 && col== 2))) pads[iP] = new TPad(Form("ratio%i",iP),"",global_x, std::abs(global_y - sy[bot] - sy_top[top_low] - sy_bot[bot_global]), global_x + sx[center], global_y);
else if (row== 0 && col==2) pads[iP] = new TPad(Form("ratio%i",iP),"",global_x, std::abs(global_y - sy[0] - sy[1]), global_x + sx[center], global_y);
else pads[iP] = new TPad(Form("ratio%i",iP),"",0., 0., 0.5, 0.5);
if (col == nCol - 1) global_y -= (sy[bot] + sy_top[top_low]);
global_x = (right) ? 0. : global_x + sx[center];
pads[iP]->SetRightMargin(right * (1 - fx / sx[center]));
pads[iP]->SetLeftMargin(left * (1 - fx / sx[center]));
pads[iP]->SetTopMargin(0.0);
if (row == 0) {
pads[iP]->SetTopMargin(top * (1 - fy));
if (col == 2)pads[iP]->SetTopMargin(top * (1 - 0.895));
}
pads[iP]->SetBottomMargin((bot_global) * (1 - 0.74074074));
cv->cd();
pads[iP]->Draw();
pads[iP]->cd();
if (!(row== 1 && col==2)){
if (row == 1 || row == 3)pads[iP]->SetGridy();
TH2F *rframe = new TH2F(Form("rframe%i",iP),titles[row%2],6,minpt,maxpt,100,miny[bot],maxy[bot]);
for (int i_part=0;i_part<6;i_part++){
rframe->GetXaxis()->SetBinLabel(i_part+1,particle_ratios[i_part]);
rframe->GetXaxis()->ChangeLabel(i_part+1,-1.,-1.,21);
}
rframe->GetYaxis()->CenterTitle();
rframe->GetYaxis()->SetTickLength(0.01 / sx[center] / (1+bot*fy));
if (row == 2)rframe->GetYaxis()->SetTickLength(0.01 / sx[center] / (1+0.2));
if (row == 3)rframe->GetYaxis()->SetTickLength(0.01 / sx[center] / (1+0.2));
if (row==0 && col == 2) rframe->GetYaxis()->SetTickLength(0);
rframe->GetYaxis()->SetTitleSize(33);
rframe->GetYaxis()->SetTitleFont((!col) * 43);
rframe->GetYaxis()->SetTitleOffset(1.);
rframe->GetYaxis()->SetLabelOffset(0.01);
rframe->GetYaxis()->SetNdivisions(505);
rframe->GetYaxis()->SetDecimals(1);
if (row==1 || row==3) rframe->GetYaxis()->SetNdivisions(5);
rframe->GetYaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3)
rframe->GetYaxis()->SetLabelSize(/* (!col) * */(col%2 - 1) * 3 + 22);
/* rframe->GetXaxis()->CenterTitle(); */
rframe->GetXaxis()->SetTickLength(0.004 / sx[1-center] / (sy[bot] + sy_top[top_low] + sy_bot[bot_global]));
if (row==0 && col == 2) rframe->GetXaxis()->SetTickLength(0);
rframe->GetXaxis()->SetLabelSize(33);
rframe->GetXaxis()->SetLabelFont(43);
rframe->GetXaxis()->SetLabelOffset(0.09);
rframe->GetXaxis()->SetNdivisions(505);
rframe->GetXaxis()->SetDecimals(1);
std::cout<<rframe->GetXaxis()->GetLabelSize()<<" "<<rframe->GetXaxis()->GetTickLength()<<" "<<rframe->GetYaxis()->GetLabelSize()<<" "<<rframe->GetYaxis()->GetTickLength()<<std::endl;
rframe->Draw("col");
}
}
return pads;
}
Color_t colors[]={kOrange+7, kAzure+4, kTeal+4};
double x_limits[3][2]={{0.7,1.6},{1.0,3.0},{2.,8.}};
int i_particle=2;
const char *format_fit_results[] = {"R=%.3f #pm %.3f","R=%.3f #pm %.3f","R=%.2f #pm%.2f (stat.) #pm%.2f (syst.) #pm%.2f (mat.)"};
const char *format_fit_results_more[] = {"R=%.4f #pm %.4f"};
double text_position_up_right[3][2]={{1.2,1.023},{2.12,1.063},{1.9,1.4}};
double text_position_low_right[3][2]={{1.2,1.017},{2.12,1.050},{1.9,1.3}};
double text_position_up_left[3][2]={{0.71,1.023},{1.06,1.063},{8.2,1.4}};
double text_position_low_left[3][2]={{0.71,1.017},{1.06,1.050},{1.9,1.2}};
const char* cent_labels[] = {"0_5","5_10","10_30","30_50","50_90"};
const char* ax_labels[] = {"#Omega","#pi","p","{}^{3}_{#Lambda}H","{}^{3}H","{}^{3}He"};
void plot_fits_try(){
gStyle->SetOptStat(0);
TFile in_file("FinalPlot3D_new_2.root");
TCanvas *c=new TCanvas("c","c",1300,900);
auto pads=CreatePads(c);
std::vector<TCanvas*> cc;
for (auto label : cent_labels){
cc.push_back((TCanvas*)in_file.Get(Form("cRatiosParticle_%s",label)));
}
for (int i_c{0}; i_c < sizeof(cent_labels)/sizeof(cent_labels[0]); ++i_c){
pads[i_c]->cd();
if (i_c > 1) pads[i_c+4]->cd();
auto g_ratio = (TGraphErrors*)(cc[i_c]->FindObject(Form("Graph_from_hRatiosParticle_%s",cent_labels[i_c])));
auto g_fit = (TGraphErrors*)(cc[i_c]->FindObject(Form("Graph_from_hRatiosParticleFit_%s",cent_labels[i_c])));
auto t_cent = (TLatex*)cc[i_c]->FindObject("centrality");
auto t_mub = (TLatex*)cc[i_c]->FindObject("mu_b");
auto t_muq = (TLatex*)cc[i_c]->FindObject("mu_q");
auto t_chi2 = (TLatex*)cc[i_c]->FindObject("chi2");
g_ratio->SetMarkerSize(2.);
g_fit->Draw("esame");
g_ratio->Draw("samepe");
t_cent->SetNDC(false);
t_mub->SetNDC(false);
t_muq->SetNDC(false);
t_chi2->SetNDC(false);
t_cent->SetTextFont(44);
t_mub->SetTextFont(44);
t_muq->SetTextFont(44);
t_chi2->SetTextFont(44);
t_cent->SetTextSize(33);
t_mub->SetTextSize(20);
t_muq->SetTextSize(20);
t_chi2->SetTextSize(20);
t_cent->SetX(0.3);
t_mub->SetX(0.3);
t_muq->SetX(0.3);
t_chi2->SetX(0.3);
t_cent->SetY(1.22);
t_mub->SetY(0.5);
t_muq->SetY(0.4);
t_chi2->SetY(0.6);
t_cent->Draw("same");
t_mub->Draw("same");
t_muq->Draw("same");
t_chi2->Draw("same");
auto h_pull = (TH1D*)(cc[i_c]->FindObject(Form("hNSigmaRatioFitParticle_%s",cent_labels[i_c])));
h_pull->SetMarkerSize(2.);
pads[i_c+3]->cd();
std::cout<<"pad = "<<1+(i_c)*2<<std::endl;
if (i_c > 1) pads[i_c+7]->cd();
TGraph *g_pull = new TGraph(h_pull);
g_pull->Draw("pesame");
//cc[i_c]->DrawClonePad();
auto leg = (TLegend*)c->FindObject("TPave");
//leg->Delete();
}
TGraphErrors g;
g.AddPoint(-100,-100);
TF1 f("f","pol0");
f.SetParameter(0,-1000);
pads[2]->cd();
g.SetMarkerStyle(20);
g.SetMarkerSize(2.);
g.SetLineColor(kBlack);
g.SetMarkerColor(kBlack);
g.Draw("pe");
f.SetLineColor(kBlack);
f.Draw("same");
TLatex t;
t.SetTextFont(44);
t.SetTextSize(35);
//t.DrawLatexNDC(0.08,0.7,"ALICE");
t.SetTextSize(30);
//t.DrawLatexNDC(0.08,0.6,"Pb#minusPb #sqrt{#it{s}_{NN}} = 5.02 TeV");
//t.DrawLatexNDC(0.15,0.6,"|y| < 0.5");
TLegend l(0.02,0.4,0.5,0.7);
l.AddEntry(&g,"#splitline{ALICE}{Pb#minusPb #sqrt{#it{s}_{NN}} = 5.02 TeV}","pe");
l.AddEntry(&f,"Thermal-FIST","l");
t.SetTextSize(30);
t.DrawLatex(1., 0.72, "#it{T}_{ch} = 155 #pm 2 MeV");
t.DrawLatex(1., 0.62, "#it{#mu}_{S} constrained");
l.SetTextFont(44);
l.SetTextSize(25);
l.Draw("same");
TLegendEntry *le1 = (TLegendEntry*)(l.GetListOfPrimitives()->At(0));
le1->SetTextFont(43);
le1->SetTextSize(30);
TLegendEntry *le2 = (TLegendEntry*)(l.GetListOfPrimitives()->At(1));
le2->SetTextFont(43);
le2->SetTextSize(30);
TFile out("fit_out_prova.root","recreate");
c->Write();
out.Close();
c->Print("fits.pdf");
}