]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/QA/tasks/macros/drawGlobalESDHistograms.C
Update master to aliroot
[u/mrichter/AliRoot.git] / HLT / QA / tasks / macros / drawGlobalESDHistograms.C
CommitLineData
0740807a 1// $Id$
2/*
3 * Plotting macro for comparing offline- and HLT- ESD trees from
4 * HLT-OFFLINE-GLOBAL-comparison.root produced using $ALICE_ROOT/HLT/QA/tasks/AliAnalysisTaskHLT.*
5 *
b3b7d2b5 6 * Usage: aliroot drawGlobalESDHistograms.C++ in compiled mode
25ccfa3d 7 *
44c80892 8 * It saves all canvases with the output histograms in a png and a ROOT file.
9 * The second argument of the macro will produce individual files for all pads,
10 * in case it is turned to kTRUE.
0740807a 11 *
12 * @ingroup alihlt_qa
13 * @author Camilla.Stokkevag@student.uib.no, Kalliopi.Kanaki@ift.uib.no
14 */
15
25ccfa3d 16#if !defined(__CINT__) || defined(__MAKECINT__)
17#include "TSystem.h"
18#include "TROOT.h"
19#include "TFile.h"
20#include "TString.h"
21#include "TList.h"
22#include "TCanvas.h"
23#include "TText.h"
25ccfa3d 24#include "TPaveStats.h"
e48c64c8 25#include "TPaveText.h"
25ccfa3d 26#include "TH1D.h"
27#include "TH2D.h"
28#include "TLegend.h"
29#include "TStyle.h"
30#include "TPad.h"
31#include <iostream>
32#include <cstdlib>
33using std::endl;
34#endif
35
36// --------------------- forward declerations --------------//
37
25ccfa3d 38void plot(TH1F *h1, TH1F *h2);
1281a832 39void printStats(TH1F *h1);
40void printStats(TH1F *h1, TH1F *h2);
25ccfa3d 41
42//==========================================================//
43
44c80892 44void drawGlobalESDHistograms(const char* filename="HLT-OFFLINE-GLOBAL-comparison.root", bool option=kFALSE){
0740807a 45
46 gROOT->SetStyle("Plain");
47 gStyle->SetPalette(1);
25ccfa3d 48 gStyle->SetOptStat("emr");
69c78ecd 49 gStyle->SetTitleX(gStyle->GetPadLeftMargin());
0740807a 50
be66aae0 51 TFile *file = TFile::Open(filename);
52 if(!file || file->IsZombie()) {
fa315f9c 53 printf("file %s does not exist or there is an error opening it\n", filename);
54 return;
55 }
56
be66aae0 57 TList *list = (TList*)file->Get("global_histograms");
58 if(!list){
59 printf("No list %s contained in your input file\n", list->GetName());
fa315f9c 60 return;
61 }
0740807a 62
e48c64c8 63 TText *runInfo = (TText*)list->FindObject("text");
64 if(!runInfo) printf("No runInfo string\n");
65
66 TText *cuts = (TText*)list->FindObject("cuts");
67 if(!cuts) printf("No cuts string\n");
be66aae0 68
69 TString folder = "GlobalTask_";
e48c64c8 70 folder += runInfo->GetTitle();
be66aae0 71 folder.ReplaceAll(" ","");
72 folder.ReplaceAll(",","_");
73 gSystem->Exec("mkdir "+folder); // create a folder whose name contains run number and date of run
74
2f281fd6 75 const static int sizeTrack=8;
76 const char *trackHLT[sizeTrack]={"fMomentum_hlt","fNcluster_hlt","fEta_hlt","fPhi_hlt","fDCAr_hlt","fDCAz_hlt","fCharge_hlt","fNITScluster_hlt"};
77 const char *trackOFF[sizeTrack]={"fMomentum_off","fNcluster_off","fEta_off","fPhi_off","fDCAr_off","fDCAz_off","fCharge_off","fNITScluster_off"};
78 const char *trackHLTcut[sizeTrack]={"fMomentum_hltcut","fNcluster_hltcut","fEta_hltcut","fPhi_hltcut","fDCAr_hltcut","fDCAz_hltcut","fCharge_hltcut","fNITScluster_hltcut"};
79
80 const static int sizeEvent=9;
81 const char *eventHLT[sizeEvent]={"fXvertex_hlt","fYvertex_hlt","fZvertex_hlt","fSPDXvertex_hlt","fSPDYvertex_hlt","fSPDZvertex_hlt","fMult_hlt","fNcont_hlt","fV0cent"};
82 const char *eventOFF[sizeEvent]={"fXvertex_off","fYvertex_off","fZvertex_off","fSPDXvertex_off","fSPDYvertex_off","fSPDZvertex_off","fMult_off","fNcont_off","fV0cent"};
83
84 TCanvas *c1 = new TCanvas("c1","track properties HLT vs. OFF",1250,700);
1281a832 85 c1->Divide(4,2);
86
25ccfa3d 87 TH1F *h1 = NULL;
88 TH1F *h2 = NULL;
1281a832 89
2f281fd6 90 for(int i=0;i<sizeTrack;i++){
91 c1->cd(i+1);
3afba926 92 h1 = (TH1F*)list->FindObject(trackHLT[i]);
93 h2 = (TH1F*)list->FindObject(trackOFF[i]);
94 if(h1 && h2){
95 plot(h1,h2);
96 if(i==0){
97 TLegend *leg1 = new TLegend(0.6,0.2,0.8,0.5);
98 leg1->SetFillColor(10);
99 leg1->SetLineColor(10);
100 leg1->AddEntry(h1,"HLT", "l");
101 leg1->AddEntry(h2,"OFF", "l");
102 leg1->Draw("same");
103 }
2f281fd6 104 }
105 }
c0fbe8ec 106
17ab437a 107 TCanvas *c4 = new TCanvas("c4","HLT track properties with and w/o cuts",1250,700);
108 c4->Divide(4,2);
c0fbe8ec 109
2f281fd6 110 for(int i=0;i<sizeTrack;i++){
111 c4->cd(i+1);
3afba926 112 h1 = (TH1F*)list->FindObject(trackHLT[i]);
113 h2 = (TH1F*)list->FindObject(trackHLTcut[i]);
114 if(h1 && h2){
115 plot(h1,h2);
116 if(i==0){
117 TPaveText *pave = new TPaveText(2.1,24000,8.3,31600);
118 pave->SetFillColor(kWhite);
119 pave->SetLineColor(kWhite);
120 pave->SetShadowColor(kWhite);
121 TString tmp=cuts->GetTitle();
122 pave->SetTextColor(2);
123 pave->AddText(tmp);
124 pave->SetTextFont(42);
125 pave->SetTextSize(0.04);
126 pave->Draw();
127 c4->Update();
128 }
2f281fd6 129 }
130 }
25ccfa3d 131
1281a832 132 TCanvas *c2 = new TCanvas("c2","vertex event properties",1200,700);
133 c2->Divide(3,2);
1281a832 134
2f281fd6 135 for(int i=0;i<6;i++){
136 c2->cd(i+1);
3afba926 137 h1 = (TH1F*)list->FindObject(eventHLT[i]);
138 h2 = (TH1F*)list->FindObject(eventOFF[i]);
139 if(h1 && h2){
140 plot(h1,h2);
141 if(i==0){
142 TLegend *leg1 = new TLegend(0.6,0.2,0.8,0.5);
143 leg1->SetFillColor(10);
144 leg1->SetLineColor(10);
145 leg1->AddEntry(h1,"HLT", "l");
146 leg1->AddEntry(h2,"OFF", "l");
147 leg1->Draw("same");
148 }
2f281fd6 149 }
150 }
1281a832 151
152 TCanvas *c3 = new TCanvas("c3","general event properties",1200,500);
153 c3->Divide(3,1);
154
2f281fd6 155 for(int i=6;i<9;i++){
156 c3->cd(i-5);
3afba926 157 h2 = (TH1F*)list->FindObject(eventOFF[i]);
158 h1 = (TH1F*)list->FindObject(eventHLT[i]);
159 if(h1 && h2){
160 plot(h1,h2);
161 if(i==6){
162 TLegend *leg1 = new TLegend(0.6,0.2,0.8,0.5);
163 leg1->SetFillColor(10);
164 leg1->SetLineColor(10);
165 leg1->AddEntry(h1,"HLT", "l");
166 leg1->AddEntry(h2,"OFF", "l");
167 leg1->Draw("same");
168 }
2f281fd6 169 }
170 }
171
1281a832 172 c1->SaveAs(folder+"/track_properties.png");
173 c1->SaveAs(folder+"/track_properties.root");
174 c2->SaveAs(folder+"/vertex_event_properties.png");
175 c2->SaveAs(folder+"/vertex_event_properties.root");
176 c3->SaveAs(folder+"/general_event_properties.png");
177 c3->SaveAs(folder+"/general_event_properties.root");
cb098126 178 c4->SaveAs(folder+"/HLT_track_properties_cuts.png");
179 c4->SaveAs(folder+"/HLT_track_properties_cuts.root");
44c80892 180
181 if(option==kTRUE){
182 TPad *pad = NULL;
183 for(int i=1; i<=sizeTrack; i++){
184 pad = (TPad*)c1->GetListOfPrimitives()->FindObject(Form("c1_%d",i));
185 if(!pad){
186 printf("Empty pad %d in canvas %s.\n", i, c1->GetName());
187 continue;
188 }
189 pad->SaveAs(Form(folder+"/c1_%s_off.png",trackHLT[i-1]));
190 }
191
192 for(int i=1; i<=sizeTrack; i++){
193 pad = (TPad*)c4->GetListOfPrimitives()->FindObject(Form("c4_%d",i));
194 if(!pad){
195 printf("Empty pad %d in canvas %s.\n", i, c4->GetName());
196 continue;
197 }
198 pad->SaveAs(Form(folder+"/c4_%s_cuts.png",trackHLT[i-1]));
199 }
200
201 for(int i=1; i<7; i++){
202 pad = (TPad*)c2->GetListOfPrimitives()->FindObject(Form("c2_%d",i));
203 if(!pad){
204 printf("Empty pad %d in canvas %s.\n", i, c2->GetName());
205 continue;
206 }
207 pad->SaveAs(Form(folder+"/c2_%s_off.png",eventHLT[i-1]));
208 }
209
210 for(int i=6; i<9; i++){
211 pad = (TPad*)c3->GetListOfPrimitives()->FindObject(Form("c3_%d",i-5));
212 if(!pad){
213 printf("Empty pad %d in canvas %s.\n", i-5, c3->GetName());
214 continue;
215 }
216 pad->SaveAs(Form(folder+"/c3_%s_off.png",eventHLT[i]));
217 }
2f281fd6 218 }
44c80892 219
220 return;
221}
25ccfa3d 222
2f281fd6 223void printStats(TH1F* h1, TH1F* h2){
25ccfa3d 224 gPad->Update();
225 TPaveStats *st1 = (TPaveStats*)h1->FindObject("stats"); if(!st1) { printf("TPaveStats st1 is 0x0\n"); return; }
226 st1->SetLineColor(0);
227
228 gPad->Update();
229 TPaveStats *st2 = (TPaveStats*)h2->FindObject("stats"); if(!st2) { printf("TPaveStats st2 is 0x0\n"); return; }
230 st2->SetY2NDC(st1->GetY1NDC()-0.05);
231 st2->SetY1NDC(st2->GetY2NDC()-TMath::Abs(st1->GetY1NDC()-st1->GetY2NDC()));
232 st2->SetLineColor(0);
233 st2->SetTextColor(h2->GetLineColor());
25ccfa3d 234 st2->Draw();
235 return;
236}
237
1281a832 238void printStats(TH1F* h1){
239 gPad->Update();
240 TPaveStats *st1 = (TPaveStats*)h1->FindObject("stats"); if(!st1) { printf("TPaveStats st1 is 0x0\n"); return; }
241 st1->SetLineColor(0);
242 return;
243}
244
25ccfa3d 245void plot(TH1F *h1, TH1F *h2){
246 //Y axis
247 if(h1->GetMaximum() > h2->GetMaximum()) h2->SetMaximum(1.1*h1->GetMaximum());
248 else h1->SetMaximum(1.1*h2->GetMaximum());
249
250 h1->SetMinimum(0);
251 h2->SetMinimum(0);
252 h2->SetLineColor(2);
253
254 // X axis
255 double xmin, xmax;
256 if(h1->GetBinLowEdge(1) > h2->GetBinLowEdge(1)) xmin = h1->GetBinLowEdge(1);
257 else xmin = h2->GetBinLowEdge(1);
258 if(h1->GetBinLowEdge(h1->GetNbinsX()+1) > h2->GetBinLowEdge(h1->GetNbinsX()+1)) xmax = h1->GetBinLowEdge(h1->GetNbinsX()+1);
259 else xmax = h2->GetBinLowEdge(h2->GetNbinsX()+1);
260
261 h2->SetAxisRange(xmin, xmax, "X");
25ccfa3d 262
263 h1->Draw();
264 h2->Draw("sames");
fa6dbeb8 265 printStats(h1,h2);
25ccfa3d 266 return;
0740807a 267}