- save all canvases in png files in addition to root files
[u/mrichter/AliRoot.git] / HLT / QA / tasks / macros / drawTHnSparse.C
CommitLineData
21fba467 1// $Id$
2/*
3 * Drawing macro for reading the THnSparse output of the
4 * HLT/QA/tasks/AliAnalysisTaskHLTCentralBarrel.cxx task.
5 *
6 * The cuts are user defined as arguments of the function.
7 * The input file contains information about the run number
8 * and date that will appear in the canvas title.
9 *
10 * The cuts are turned into strings and incorporated in the
11 * name of the output file, which contains canvases with event
12 * and track properties for HLT and offline.
13 *
14 * Since the run information is available, there will be a new
15 * folder created and the canvas ROOT files will be saved in there.
16 *
17 * @ingroup alihlt_qa
18 * @author Kalliopi.Kanaki@ift.uib.no
19 */
20
21void drawTHnSparse( TString inputFile,
22 double minEta=-2, double maxEta=2,
23 int minTrackMult=0, int maxTrackMult=20000,
24 double minPt=0, double maxPt=200,
25 double minDCAr=-80, double maxDCAr=80,
26 double minDCAz=-80, double maxDCAz=80,
27 int minTPCclus=0, int maxTPCclus=200,
cb9ecd10 28 int minITSclus=0, int maxITSclus=6,
21fba467 29 int vertexStatus=2
30 )
31{
32 gROOT->SetStyle("Plain");
33 gStyle->SetPalette(1);
34 gStyle->SetOptStat(10);
35 TH1::AddDirectory(kFALSE);
36
37 TFile *file = TFile::Open(inputFile);
38 if(!file){
39 printf("Error: No file %s in folder.\n", inputFile);
40 return;
41 }
42
43 TList *list = static_cast<TList*>(file->Get("esd_thnsparse"));
44 if(!list){
45 printf("Error: No List contained in file %s.\n", inputFile);
46 return;
47 }
48
49 THnSparseF *heventHLT = (THnSparse*)list->FindObject("fEventHLT");
50 if(!heventHLT){
51 printf("Error: There is no HLT THnSparse object in file %s\n", inputFile);
52 }
53 THnSparseF *heventOFF = (THnSparse*)list->FindObject("fEventOFF");
54 if(!heventOFF){
55 printf("Error: There is no OFF THnSparse object in file %s\n", inputFile);
56 }
57 THnSparseF *htrackHLT = (THnSparse*)list->FindObject("fTrackHLT");
58 if(!htrackHLT){
59 printf("Error: No HLT THnSparse object found\n");
60 return;
61 }
62 THnSparseF *htrackOFF = (THnSparse*)list->FindObject("fTrackOFF");
63 if(!htrackOFF){
64 printf("Error: No OFF THnSparse object found\n");
65 return;
66 }
67
68
69 TText *hText = list->FindObject("text");
70 if(!hText) printf("No hText\n");
71
72 TString t = "event properties for ";
73 t+=hText->GetTitle();
74
75 TCanvas *can0 = new TCanvas("can0",t,900,600);
76 can0->Divide(3,2);
77 plotEventQuantities(can0,heventOFF,heventHLT,hText);
78
79 TCanvas *can1 = new TCanvas("can1","track properties",1100,900);
80 can1->Divide(4,3);
81 plotTrackQuantities(can1, htrackOFF, htrackHLT, hText,
82 minEta, maxEta, minPt, maxPt, minDCAr, maxDCAr, minDCAz, maxDCAz, minTPCclus, maxTPCclus, minITSclus, maxITSclus, minTrackMult, maxTrackMult, vertexStatus);
83
84 TCanvas *can2 = new TCanvas("can2","2-D HLT track correlations",1200,800);
85 can2->Divide(4,2);
86 plot2D(can2, htrackHLT, minEta, maxEta, minPt, maxPt, minDCAr, maxDCAr, minDCAz, maxDCAz, minTPCclus, maxTPCclus, minITSclus, maxITSclus, minTrackMult, maxTrackMult);
87
88 TCanvas *can3 = new TCanvas("can3","2-D OFF track correlations",1200,800);
89 can3->Divide(4,2);
90 plot2D(can3, htrackOFF, minEta, maxEta, minPt, maxPt, minDCAr, maxDCAr, minDCAz, maxDCAz, minTPCclus, maxTPCclus, minITSclus, maxITSclus, minTrackMult, maxTrackMult);
91
92 TString folder = hText->GetTitle();
93 folder.ReplaceAll(" ","");
94 folder.Remove(0,3);
95 folder.Remove(6,15);
96
97 gSystem->Exec("mkdir "+folder);
98 can0->SaveAs(folder+"/event_properties.root");
5608862a 99 can0->SaveAs(folder+"/event_properties.png");
21fba467 100
101
102 stringstream sMinEta, sMaxEta;
103 sMinEta << minEta; sMaxEta << maxEta;
104
105 stringstream sMinTM, sMaxTM;
106 sMinTM << minTrackMult; sMaxTM << maxTrackMult;
107
108 stringstream sMinPt, sMaxPt;
109 sMinPt << minPt; sMaxPt << maxPt;
110
111 stringstream sMinDCAr, sMaxDCAr;
112 sMinDCAr << minDCAr; sMaxDCAr << maxDCAr;
113
114 stringstream sMinDCAz, sMaxDCAz;
115 sMinDCAz << minDCAz; sMaxDCAz << maxDCAz;
116
117 stringstream sMinTPCclus, sMaxTPCclus;
118 sMinTPCclus << minTPCclus; sMaxTPCclus << maxTPCclus;
119
120 stringstream sMinITSclus, sMaxITSclus;
121 sMinITSclus << minITSclus; sMaxITSclus << maxITSclus;
122
123 stringstream sVS; sVS << vertexStatus;
124
125 TString trackName = "track_properties_";
126 trackName += "eta"+sMinEta.str()+"_"+sMaxEta.str()+"_";
127 trackName += "Pt"+sMinPt.str()+"_"+sMaxPt.str()+"_";
128 trackName += "TM"+sMinTM.str()+"_"+sMaxTM.str()+"_";
129 trackName += "DCAr"+sMinDCAr.str()+"_"+sMaxDCAr.str()+"_";
130 trackName += "DCAz"+sMinDCAz.str()+"_"+sMaxDCAz.str()+"_";
131 trackName += "TPCclus"+sMinTPCclus.str()+"_"+sMaxTPCclus.str()+"_";
132 trackName += "ITSclus"+sMinITSclus.str()+"_"+sMaxITSclus.str()+"_";
133 if(vertexStatus==2){
134 trackName.Chop(); trackName += ".root";
135 }
136 else {
137 trackName += "VS"+sVS.str();
138 trackName += ".root";
139 }
140 can1->SaveAs(folder+"/"+trackName);
5608862a 141 trackName.ReplaceAll("root","png");
142 can1->SaveAs(folder+"/"+trackName);
143
21fba467 144
145 can2->SaveAs(folder+"/HLT_2D_track_correlations.root");
146 can3->SaveAs(folder+"/OFF_2D_track_correlations.root");
5608862a 147 can2->SaveAs(folder+"/HLT_2D_track_correlations.png");
148 can3->SaveAs(folder+"/OFF_2D_track_correlations.png");
21fba467 149
150 return;
151}
152
153void printStats(TH1D *hlt, TH1D *off){
154 gPad->Update();
155 TPaveStats *st1 = (TPaveStats*)hlt->FindObject("stats");
156 st1->SetLineColor(0);
157
158 gPad->Update();
159 TPaveStats *st2 = (TPaveStats*)off->FindObject("stats");
160 st2->SetY2NDC(st1->GetY1NDC()-0.05);
161 st2->SetY1NDC(st2->GetY2NDC()-TMath::Abs(st1->GetY1NDC()-st1->GetY2NDC()));
162 st2->SetLineColor(0);
163 st2->SetTextColor(off->GetLineColor());
164 st2->SetFillStyle(0);
165 st2->Draw();
166}
167
168void defineYaxisMax(TH1D *hlt, TH1D *off){
169 if(hlt->GetMaximum() > off->GetMaximum()) off->SetMaximum(1.1*hlt->GetMaximum());
170 else hlt->SetMaximum(1.1*off->GetMaximum());
171}
172
173void printLegend(TLegend *l, TH1D *hlt, TH1D *off){
174 l->SetFillColor(10);
175 l->SetLineColor(10);
176 l->AddEntry(hlt, "HLT", "l");
177 l->AddEntry(off, "OFF", "l");
178 l->Draw("same");
179}
180
181//====================== for 1D distributions ===============================//
182
183void plotAid(TCanvas* can, THnSparse* hOFF, THnSparse* hHLT, TText* hText, TH1D *hlt, TH1D *off, TLegend *l, int size,
184 double minEta, double maxEta,
185 double minPt, double maxPt,
186 double minDCAr, double maxDCAr,
187 double minDCAz, double maxDCAz,
188 int minTPCclus, int maxTPCclus,
189 int minITSclus, int maxITSclus,
190 int minTrackMult, int maxTrackMult,
191 int VS
192 )
193{
194 hHLT->GetAxis(0)->SetRangeUser(minPt,maxPt);
195 hHLT->GetAxis(1)->SetRangeUser(minTPCclus,maxTPCclus);
196 hHLT->GetAxis(3)->SetRangeUser(minEta, maxEta);
197 hHLT->GetAxis(5)->SetRangeUser(minDCAr, maxDCAr);
198 hHLT->GetAxis(6)->SetRangeUser(minDCAz, maxDCAz);
199 hHLT->GetAxis(10)->SetRangeUser(minITSclus, maxITSclus);
200 hHLT->GetAxis(11)->SetRangeUser(minTrackMult, maxTrackMult);
201 if(VS!=2) hHLT->GetAxis(12)->SetRangeUser(VS,VS);
202
203 hOFF->GetAxis(0)->SetRangeUser(minPt,maxPt);
204 hOFF->GetAxis(1)->SetRangeUser(minTPCclus,maxTPCclus);
205 hOFF->GetAxis(3)->SetRangeUser(minEta, maxEta);
206 hOFF->GetAxis(5)->SetRangeUser(minDCAr, maxDCAr);
207 hOFF->GetAxis(6)->SetRangeUser(minDCAz, maxDCAz);
208 hOFF->GetAxis(10)->SetRangeUser(minITSclus, maxITSclus);
209 hOFF->GetAxis(11)->SetRangeUser(minTrackMult, maxTrackMult);
210 if(VS!=2) hOFF->GetAxis(12)->SetRangeUser(VS,VS);
211
212 for(int i=0; i<size; i++){
213
214 hlt = hHLT->Projection(i);
215 off = hOFF->Projection(i);
216 hlt->SetTitle(hHLT->Projection(i)->GetTitle());
217 defineYaxisMax(hlt, off);
e84c79f2 218 //off->SetLineColor(2);
219 off->SetLineStyle(2);
21fba467 220
221 can->cd(i+1);
222 hlt->Draw();
223 off->Draw("sames");
224 printStats(hlt, off);
225 }
226 printLegend(l,hlt,off);
227}
228
229//====================== for 2D distributions ===============================//
230
231void plot2D(TCanvas* can, THnSparse* h,
232 double minEta, double maxEta,
233 double minPt, double maxPt,
234 double minDCAr, double maxDCAr,
235 double minDCAz, double maxDCAz,
236 int minTPCclus, int maxTPCclus,
237 int minITSclus, int maxITSclus,
238 int minTrackMult, int maxTrackMult
239 )
240{
241
242 h->GetAxis(0)->SetRangeUser(minPt,maxPt);
243 h->GetAxis(1)->SetRangeUser(minTPCclus,maxTPCclus);
244 h->GetAxis(3)->SetRangeUser(minEta, maxEta);
245 h->GetAxis(5)->SetRangeUser(minDCAr, maxDCAr);
246 h->GetAxis(6)->SetRangeUser(minDCAz, maxDCAz);
247 h->GetAxis(10)->SetRangeUser(minITSclus, maxITSclus);
248 h->GetAxis(11)->SetRangeUser(minTrackMult, maxTrackMult);
249
250 can->cd(1);
251 h->Projection(1,0)->Draw("colz");
252 can->cd(2);
253 h->Projection(1,3)->Draw("colz");
254 can->cd(3);
255 h->Projection(1,5)->Draw("colz");
256 can->cd(4);
257 h->Projection(1,6)->Draw("colz");
258
259 can->cd(5);
260 h->Projection(6,0)->Draw("colz");
261 can->cd(6);
262 h->Projection(6,3)->Draw("colz");
263 can->cd(7);
264 h->Projection(3,0)->Draw("colz");
265 can->cd(8);
266 h->Projection(3,4)->Draw("colz");
267
268}
269
270void plotAid(TCanvas* can, THnSparse* hOFF, THnSparse* hHLT, TText* hText, TH1D *hlt, TH1D *off, TLegend *l, int size){
271
272 for(int i=0; i<size; i++){
273 hlt = hHLT->Projection(i);
274 off = hOFF->Projection(i);
275 hlt->SetTitle(hHLT->Projection(i)->GetTitle());
276 defineYaxisMax(hlt, off);
277 off->SetLineColor(2);
278
279 can->cd(i+1);
280 hlt->Draw();
281 off->Draw("sames");
282 printStats(hlt, off);
283 }
284 printLegend(l,hlt,off);
285}
286
287void plotEventQuantities(TCanvas* can, THnSparse* heventOFF, THnSparse* heventHLT, TText* hText){
288
289 TH1D *hlt = NULL;
290 TH1D *off = NULL;
291
292 TLegend *leg1 = new TLegend(0.6,0.6,0.8,0.8);
293
294 plotAid(can, heventOFF, heventHLT, hText, hlt, off, leg1, 6);
295 return;
296}
297
298void plotTrackQuantities( TCanvas* can, THnSparse* htrackOFF, THnSparse* htrackHLT, TText* hText,
299 double minEta, double maxEta,
300 double minPt, double maxPt,
301 double minDCAr, double maxDCAr,
302 double minDCAz, double maxDCAz,
303 int minTPCclus, int maxTPCclus,
304 int minITSclus, int maxITSclus,
305 int minTrackMult, int maxTrackMult,
306 int VS
307 )
308{
309 TH1D *hlt = NULL;
310 TH1D *off = NULL;
311
312 TLegend *leg1 = new TLegend(0.6,0.6,0.8,0.8);
313 plotAid(can, htrackOFF, htrackHLT, hText, hlt, off, leg1, 11,
314 minEta, maxEta, minPt, maxPt, minDCAr, maxDCAr, minDCAz, maxDCAz, minTPCclus, maxTPCclus, minITSclus, maxITSclus, minTrackMult, maxTrackMult, VS);
315return;
316}