]>
Commit | Line | Data |
---|---|---|
bf000c32 | 1 | //____________________________________________________________________ |
d389af40 | 2 | // |
3 | // Script to plot the lego information | |
4 | // | |
5 | #ifndef __CINT__ | |
6 | # include <TFile.h> | |
7 | # include <TCanvas.h> | |
8 | # include <TPad.h> | |
9 | # include <TH1D.h> | |
10 | # include <TString.h> | |
11 | # include <TLatex.h> | |
12 | # include <TLegend.h> | |
13 | # include <THStack.h> | |
14 | # include <TStyle.h> | |
15 | # include <iostream> | |
16 | using namespace std; | |
17 | #endif | |
9b48326f | 18 | /** @defgroup lego_script LEGO script |
19 | @ingroup FMD_script | |
20 | */ | |
bf000c32 | 21 | //____________________________________________________________________ |
9b48326f | 22 | /** @ingroup lego_script |
23 | @param ang | |
24 | @return */ | |
d389af40 | 25 | Float_t |
26 | deg2eta(Float_t ang) | |
27 | { | |
28 | if (ang == 180) ang -= .001; | |
29 | if (ang == 0) ang += .001; | |
30 | Float_t theta = ang * TMath::Pi() / 180; | |
31 | Float_t eta = - TMath::Log(TMath::Tan(theta / 2)); | |
32 | return eta; | |
33 | } | |
34 | ||
35 | ||
bf000c32 | 36 | //____________________________________________________________________ |
9b48326f | 37 | /** @ingroup lego_script |
38 | @param which | |
39 | @param what | |
40 | @param back | |
41 | @return */ | |
d389af40 | 42 | TH1* |
43 | getHisto(const Char_t* which, const Char_t* what, TH1* back=0) | |
44 | { | |
45 | TFile* file = TFile::Open(Form("Lego_%s.root", which), "READ"); | |
46 | if (!file) { | |
47 | cerr << "Couldn't open the file 'Lego_" << which << ".root" | |
48 | << endl; | |
49 | return 0; | |
50 | } | |
51 | TH1D* h1d = static_cast<TH1D*>(file->Get(Form("h%s_py", what))); | |
52 | if (!h1d) { | |
53 | cerr << "Couldn't find h" << what << "_py in " | |
54 | << "Lego_" << which << ".root" << endl; | |
55 | return 0; | |
56 | } | |
57 | ||
58 | TAxis* xaxis = h1d->GetXaxis(); | |
59 | Int_t n = xaxis->GetNbins(); | |
60 | TArrayF bins(n-1); | |
61 | for (Int_t i = n-1; i > 1; i--) { | |
62 | Float_t ang = xaxis->GetBinUpEdge(i); | |
63 | Float_t eta = deg2eta(ang); | |
64 | bins[n-i-1] = deg2eta(xaxis->GetBinUpEdge(i)); | |
65 | } | |
66 | bins[n-2] = deg2eta(xaxis->GetBinLowEdge(2)); | |
67 | ||
68 | TH1F* heta = new TH1F(Form("%s_eta", what), h1d->GetTitle(), | |
69 | n-2, bins.fArray); | |
70 | heta->SetXTitle("#eta"); | |
71 | heta->GetXaxis()->SetTitleSize(0); | |
72 | heta->GetXaxis()->SetTitleOffset(1.5); | |
73 | heta->GetXaxis()->SetTitleFont(132); | |
74 | heta->GetXaxis()->SetLabelFont(132); | |
75 | heta->SetYTitle(Form("%s per degree", h1d->GetTitle())); | |
76 | heta->GetYaxis()->SetTitleOffset(1.5); | |
77 | heta->GetYaxis()->SetTitleFont(132); | |
78 | heta->GetYaxis()->SetLabelFont(132); | |
79 | heta->GetYaxis()->SetTitleSize(0); | |
80 | heta->GetZaxis()->SetTitle(heta->GetTitle()); | |
81 | heta->GetZaxis()->SetTitleOffset(1.5); | |
82 | heta->GetZaxis()->SetTitleFont(132); | |
83 | heta->GetZaxis()->SetLabelFont(132); | |
84 | heta->GetYaxis()->SetTitleOffset(1.5); | |
85 | for (Int_t i = 2; i < n; i++) { | |
86 | Float_t ang = xaxis->GetBinUpEdge(i); | |
87 | Float_t eta = deg2eta(ang); | |
88 | Float_t y = h1d->GetBinContent(i); | |
89 | Float_t j = heta->FindBin(eta); | |
90 | if (back) { | |
91 | Float_t b = back->GetBinContent(j); | |
92 | if (y - b <= 0) y = .000001; | |
93 | else y = y - b; | |
94 | } | |
95 | // cout << i << ": " << ang << " -> " << eta << " = " << y << endl; | |
96 | heta->SetBinContent(j, y); | |
97 | } | |
98 | return heta; | |
99 | } | |
100 | ||
bf000c32 | 101 | //____________________________________________________________________ |
9b48326f | 102 | /** @ingroup lego_script |
103 | @param what | |
104 | */ | |
d389af40 | 105 | void |
106 | drawLego(const char* what="abso") | |
107 | { | |
108 | gStyle->SetOptTitle(0); | |
109 | gStyle->SetOptStat(0); | |
110 | gStyle->SetPadLeftMargin(0.15); | |
111 | gStyle->SetPadRightMargin(0.05); | |
112 | gStyle->SetPadTopMargin(0.05); | |
113 | gStyle->SetPadBottomMargin(0.15); | |
114 | gStyle->SetLabelFont(132, "xyz"); | |
115 | gStyle->SetTitleFont(132, "xyz"); | |
116 | gStyle->SetTitleOffset(1.5, "y"); | |
117 | ||
118 | TH1* nothing = getHisto("Nothing", what); | |
119 | TH1* its = getHisto("ITS", what, nothing); | |
120 | TH1* fmd = getHisto("FMD", what, nothing); | |
121 | TH1* pipe = getHisto("PIPE", what, nothing); | |
122 | TH1* inner = getHisto("Inner", what); | |
123 | ||
124 | if (!inner || !pipe || !fmd || !its || !nothing) { | |
125 | cerr << "Failed to get a histogram!" << endl; | |
126 | return; | |
127 | } | |
128 | TCanvas* c = new TCanvas(Form("single_%s", what), | |
129 | Form("Single %s", what), 800, 800); | |
130 | c->SetFillColor(0); | |
131 | c->SetBorderMode(0); | |
132 | c->SetBorderSize(0); | |
133 | TPad* p1 = new TPad("p1", "p1", 0.0, 0.5, 0.5, 1.0, 0, 0, 0); | |
134 | TPad* p2 = new TPad("p2", "p2", 0.5, 0.5, 1.0, 1.0, 0, 0, 0); | |
135 | TPad* p3 = new TPad("p3", "p3", 0.0, 0.0, 0.5, 0.5, 0, 0, 0); | |
136 | TPad* p4 = new TPad("p4", "p4", 0.5, 0.0, 1.0, 0.5, 0, 0, 0); | |
137 | ||
138 | TLatex* latex = new TLatex(0,0,""); | |
139 | latex->SetTextFont(132); | |
140 | ||
141 | float logmax = inner->GetMaximum(); | |
142 | float logmin = .001 * logmax; | |
143 | float latexy = 6 * logmin; | |
144 | ||
145 | c->cd(); | |
146 | p1->SetLogy(); | |
147 | p1->SetGridy(); | |
148 | p1->SetTopMargin(0.15); | |
149 | p1->SetBottomMargin(0); | |
150 | p1->SetRightMargin(0); | |
151 | p1->Draw(); | |
152 | p1->cd(); | |
153 | fmd->SetFillColor(4); | |
154 | fmd->GetYaxis()->SetRangeUser(logmin, logmax); | |
155 | fmd->GetYaxis()->SetTitleSize(.04); | |
156 | fmd->Draw(); | |
157 | latex->DrawLatex(-1, latexy, "FMD only"); | |
158 | ||
159 | c->cd(); | |
160 | p2->SetLogy(); | |
161 | p2->SetGridy(); | |
162 | p2->SetTopMargin(0.15); | |
163 | p2->SetBottomMargin(0); | |
164 | p2->SetLeftMargin(0); | |
165 | p2->SetRightMargin(0.15); | |
166 | p2->Draw(); | |
167 | p2->cd(); | |
168 | its->SetFillColor(2); | |
169 | its->GetYaxis()->SetRangeUser(logmin, logmax); | |
170 | its->Draw(); | |
171 | latex->DrawLatex(-1, latexy, "ITS only"); | |
172 | ||
173 | c->cd(); | |
174 | p3->SetLogy(); | |
175 | p3->SetGridy(); | |
176 | p3->SetTopMargin(0); | |
177 | p3->SetLeftMargin(0.15); | |
178 | p3->SetRightMargin(0); | |
179 | p3->Draw(); | |
180 | p3->cd(); | |
181 | pipe->SetFillColor(3); | |
182 | pipe->GetYaxis()->SetRangeUser(logmin, logmax); | |
183 | pipe->Draw(); | |
184 | latex->DrawLatex(-1, latexy, "PIPE only"); | |
185 | ||
186 | c->cd(); | |
187 | p4->SetLogy(); | |
188 | p4->SetGridy(); | |
189 | p4->SetTopMargin(0); | |
190 | p4->SetLeftMargin(0.); | |
191 | p4->SetRightMargin(0.15); | |
192 | p4->Draw(); | |
193 | p4->cd(); | |
194 | inner->GetYaxis()->SetRangeUser(logmin, logmax); | |
195 | inner->GetXaxis()->SetTitleSize(.04); | |
196 | inner->SetFillColor(5); | |
197 | inner->Draw(); | |
198 | latex->DrawLatex(-1, latexy, "PIPE, ITS, FMD and Air"); | |
199 | ||
200 | c->Modified(); | |
201 | c->cd(); | |
202 | c->Print(Form("%s_single.png", what)); | |
203 | ||
204 | TCanvas* accum = new TCanvas(Form("accum_%s", what), | |
205 | Form("Accumalted %s",what), | |
206 | 800, 500); | |
207 | accum->SetLogy(); | |
208 | accum->SetFillColor(0); | |
209 | accum->SetBorderMode(0); | |
210 | accum->SetBorderSize(0); | |
211 | ||
212 | THStack* stack = new THStack("stack", "Stack"); | |
213 | nothing->SetFillColor(6); | |
214 | stack->Add(nothing); | |
215 | stack->Add(pipe); | |
216 | stack->Add(fmd); | |
217 | stack->Add(its); | |
218 | ||
219 | TLegend* legend = new TLegend(.15, .65, .27, .95); | |
220 | legend->SetFillColor(0); | |
221 | legend->SetBorderSize(1); | |
222 | legend->AddEntry(its, "ITS", "f"); | |
223 | legend->AddEntry(fmd, "FMD", "f"); | |
224 | legend->AddEntry(pipe, "PIPE", "f"); | |
225 | legend->AddEntry(nothing, "Air", "f"); | |
226 | ||
227 | stack->SetMinimum(nothing->GetMinimum()); | |
228 | stack->SetMaximum(logmax); | |
229 | stack->Draw(); | |
230 | stack->GetXaxis()->SetTitle("#eta"); | |
231 | // stack->GetYaxis()->SetRangeUser(, ); | |
232 | stack->GetYaxis()->SetTitle(fmd->GetTitle()); | |
233 | legend->Draw(); | |
234 | accum->Modified(); | |
235 | ||
236 | accum->Modified(); | |
237 | accum->cd(); | |
238 | // accum->Print(Form("%s_accum.eps", what)); | |
239 | accum->Print(Form("%s_accum.png", what)); | |
240 | ||
241 | } | |
242 | ||
243 | ||
244 | ||
bf000c32 | 245 | //____________________________________________________________________ |
9b48326f | 246 | /** @ingroup lego_script |
247 | */ | |
d389af40 | 248 | void |
249 | DrawLego() | |
250 | { | |
251 | drawLego("abso"); | |
252 | drawLego("radl"); | |
253 | drawLego("gcm2"); | |
254 | } | |
255 | ||
bf000c32 | 256 | //____________________________________________________________________ |
257 | // | |
258 | // EOF | |
259 | // | |
260 | ||
d389af40 | 261 |