Fixes for coverity checks.
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / qa / DrawOccupancy.C
CommitLineData
2970d087 1/**
2 * @file DrawOccupancy.C
3 * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
4 * @date Thu Jul 7 10:24:58 2011
5 *
6 * @brief A script to draw the Poisson vs Energy Loss correlation
7 *
8 *
9 * @ingroup pwg2_forward_scripts_qa
10 *
11 */
d015ecfe 12#ifndef __CINT__
13# include <TH1.h>
14# include <TH2.h>
15# include <TList.h>
16# include <TFile.h>
17# include <TString.h>
18# include <TError.h>
19# include <TPad.h>
20# include <TCanvas.h>
21# include <TLine.h>
22# include <TLatex.h>
23# include <TStyle.h>
24#else
25class TList;
26#endif
2970d087 27
28/**
29 * Draw the poisson @f$N_{ch}@f$ estimate against the @f$\Delta@f$
30 * @f$N_{ch}@f$ estimate and do a regression line between the two
31 *
32 * @param p List
33 * @param d Detector
34 * @param r Ring
35 * @param xmin Minimum
36 * @param xmax Maximum
37 *
38 * @return The regression coefficient
39 *
40 * @ingroup pwg2_forward_scripts_qa
41 */
42Double_t
43DrawRingOccupancy(TList* p, UShort_t d, Char_t r)
44{
d015ecfe 45 if (!p) return 0;
2970d087 46
47 TList* ring = static_cast<TList*>(p->FindObject(Form("FMD%d%c",d,r)));
48 if (!ring) {
49 Error("DrawOccupancy", "List FMD%d%c not found in %s",d,r,p->GetName());
d015ecfe 50 return 0;
2970d087 51 }
52
53 TH1* corr = static_cast<TH1*>(ring->FindObject("occupancy"));
54 if (!corr) {
55 Error("DrawRingOccupancy", "Histogram occupancy not found in FMD%d%c",
56 d, r);
d015ecfe 57 return 0;
2970d087 58 }
d015ecfe 59 corr->Rebin(4);
60
2970d087 61 TPad* pad = static_cast<TPad*>(gPad);
62 pad->SetGridy();
63 pad->SetGridx();
64 pad->SetLogy();
65 pad->SetFillColor(0);
66 pad->SetRightMargin(0.01);
67#if 0
68 if (d == 3) {
69 pad->SetPad(pad->GetXlowNDC(), pad->GetYlowNDC(), .99,
70 pad->GetYlowNDC()+pad->GetHNDC());
71 pad->SetRightMargin(0.15);
72 }
73#endif
74
75 corr->Draw("hist");
76
77 TLatex* ltx = new TLatex(.95, .95, Form("FMD%d%c", d, r));
78 ltx->SetNDC();
79 ltx->SetTextAlign(33);
80 ltx->SetTextSize(.08);
81 ltx->Draw();
82
83 return corr->GetMean();
84}
85
86/**
87 * Draw the correlation between the Poisson @f$N_{ch}@f$ estimate
88 * and the @f$\Delta@f$ @f$N_{ch}@f$ estimate and do a regression
89 * line between the two for each ring
90 *
91 * @param filename File to read
92 * @param xmax Minimum X
93 * @param xmin Maximum X
94 *
95 * @ingroup pwg2_forward_scripts_qa
96 */
97void
98DrawOccupancy(const char* filename="forward.root",
d015ecfe 99 const char* folder="ForwardResults")
2970d087 100{
101 gStyle->SetPalette(1);
102 gStyle->SetOptFit(0);
103 gStyle->SetOptStat(0);
104 gStyle->SetOptTitle(0);
105 gStyle->SetTitleW(.4);
106 gStyle->SetTitleH(.1);
107 gStyle->SetTitleX(.4);
108 // gStyle->SetTitleY(.1);
109 gStyle->SetTitleColor(0);
110 gStyle->SetTitleStyle(0);
111 gStyle->SetTitleBorderSize(0);
112
113 TFile* file = TFile::Open(filename, "READ");
114 if (!file) {
115 Error("DrawOccupancy", "failed to open %s", filename);
116 return;
117 }
118
d015ecfe 119 TList* forward = static_cast<TList*>(file->Get(folder));
2970d087 120 if (!forward) {
d015ecfe 121 Error("DrawOccupancy", "List %s not found in %s", folder, filename);
2970d087 122 return;
123 }
124
125 TList* dc = static_cast<TList*>(forward->FindObject("fmdDensityCalculator"));
126 if (!dc) {
127 Error("DrawOccupancy", "List fmdDensityCalculator not found in Forward");
128 return;
129 }
130
131 TCanvas* c = new TCanvas("occupancy",
132 "Mean Occupancy", 900, 700);
133 c->SetFillColor(0);
134 c->SetBorderSize(0);
135 c->SetBorderMode(0);
136 c->SetHighLightColor(0);
137 c->SetBottomMargin(.15);
138 c->SetTopMargin(.02);
139 c->SetRightMargin(.02);
140 c->SetLeftMargin(.15);
141 c->Divide(3, 2, 0, 0);
142
143
144 Double_t corrs[5];
145 c->cd(1); corrs[0] = DrawRingOccupancy(dc, 1, 'I');
146 c->cd(2); corrs[1] = DrawRingOccupancy(dc, 2, 'I');
147 c->cd(5); corrs[2] = DrawRingOccupancy(dc, 2, 'O');
148 c->cd(3); corrs[3] = DrawRingOccupancy(dc, 3, 'I');
149 c->cd(6); corrs[4] = DrawRingOccupancy(dc, 3, 'O');
150
151 TVirtualPad* p = c->cd(4);
152 p->SetTopMargin(0.05);
153 p->SetRightMargin(0.10);
154 p->SetLeftMargin(0.15);
155 p->SetBottomMargin(0.15);
156 p->SetFillColor(0);
157
158 TH1D* hc = new TH1D("occ", "Mean occupancy", 5, .5, 5.5);
159 hc->SetFillColor(kRed+1);
160 hc->SetFillStyle(3001);
161 hc->SetMinimum(0.0);
162 hc->GetXaxis()->SetBinLabel(1,"FMD1i"); hc->SetBinContent(1,corrs[0]);
163 hc->GetXaxis()->SetBinLabel(2,"FMD2i"); hc->SetBinContent(2,corrs[1]);
164 hc->GetXaxis()->SetBinLabel(3,"FMD2o"); hc->SetBinContent(3,corrs[2]);
165 hc->GetXaxis()->SetBinLabel(4,"FMD3i"); hc->SetBinContent(4,corrs[3]);
166 hc->GetXaxis()->SetBinLabel(5,"FMD3o"); hc->SetBinContent(5,corrs[4]);
167 hc->GetXaxis()->SetLabelSize(0.08);
168 hc->GetYaxis()->SetTitle("#bar{occupancy}");
169 hc->SetMarkerSize(1.5);
170 hc->Draw("text hist");
171 hc->SetMaximum(hc->GetMaximum()*1.5);
172
173 // TH2D* highCuts = static_cast<TH2D*>(dc->FindObject("highCuts"));
174 // if (highCuts) highCuts->Draw("colz");
175 c->cd();
176 c->SaveAs("occupancy.png");
177}
178//
179// EOF
180//