]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/QA/tasks/macros/drawGlobalESDHistograms.C
- included run number and date info in the output list
[u/mrichter/AliRoot.git] / HLT / QA / tasks / macros / drawGlobalESDHistograms.C
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  *
6  * Usage: aliroot drawGlobalESDHistograms.C'("HLT-OFFLINE-GLOBAL-comparison.root")'
7  *
8  * or aliroot drawGlobalESDHistograms.C++ in compiled mode
9  *
10  * It saves the canvas with the output histograms in a png and a ROOT file.
11  *
12  * @ingroup alihlt_qa
13  * @author Camilla.Stokkevag@student.uib.no, Kalliopi.Kanaki@ift.uib.no 
14  */
15
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"
24 #include "TPaveStats.h"
25 #include "TH1D.h"
26 #include "TH2D.h"
27 #include "TLegend.h"
28 #include "TStyle.h"
29 #include "TPad.h"
30 #include <iostream>
31 #include <cstdlib>
32 using std::endl;
33 #endif
34
35 // --------------------- forward declerations --------------//
36
37 void printStats(TH1F *h1, TH1F *h2);
38 void plot(TH1F *h1, TH1F *h2);
39
40 //==========================================================//
41
42 void drawGlobalESDHistograms(const char* filename="HLT-OFFLINE-GLOBAL-comparison.root"){
43  
44  gROOT->SetStyle("Plain");
45  gStyle->SetPalette(1);
46  gStyle->SetOptStat("emr");
47  gStyle->SetTitleX(gStyle->GetPadLeftMargin());
48
49  TFile *file = TFile::Open(filename); 
50  if(!file || file->IsZombie()) {
51     printf("file %s does not exist or there is an error opening it\n", filename);
52     return;
53  }
54
55  TList *list = (TList*)file->Get("global_histograms");
56  if(!list){
57     printf("No list %s contained in your input file\n", list->GetName()); 
58     return; 
59  }
60  
61  TText *hText = (TText*)list->FindObject("text");
62  if(!hText) printf("No hText\n");
63
64  TString folder = "GlobalTask_";
65  folder += hText->GetTitle();
66  folder.ReplaceAll(" ",""); 
67  folder.ReplaceAll(",","_");
68  gSystem->Exec("mkdir "+folder); // create a folder whose name contains run number and date of run
69
70  TCanvas *c1 = new TCanvas("c1","HLT vs. offline",1200,700);
71  c1->Divide(3,3);
72  TH1F *h1 = NULL;
73  TH1F *h2 = NULL;
74
75  h1 = (TH1F*)list->FindObject("fNcluster_hlt"); if(!h1) { printf("Empty histogram fNcluster_hlt\n"); return; }
76  h2 = (TH1F*)list->FindObject("fNcluster_off"); if(!h2) { printf("Empty histogram fNcluster_off\n"); return; }
77  h1->SetTitle("TPC cluster distribution");
78  h1->GetXaxis()->SetTitle("TPC clusters per track");
79
80  TLegend *leg1 = new TLegend(0.7,0.6,0.88,0.77);
81  leg1->SetFillColor(10);
82  leg1->SetLineColor(10);
83  leg1->AddEntry(h1,"HLT", "l");
84  leg1->AddEntry(h2,"OFF", "l");
85
86  c1->cd(1);
87  plot(h1,h2);
88  leg1->Draw("same");
89
90 //-------------------------------------------------
91
92  h1 = (TH1F*)list->FindObject("fDCA_hlt"); if(!h1) { printf("Empty histogram fDCA_hlt\n"); return; }
93  h2 = (TH1F*)list->FindObject("fDCA_off"); if(!h2) { printf("Empty histogram fDCA_off\n"); return; }
94  h1->SetTitle("DCA between track and vertex on XY plane");
95  h1->SetXTitle("DCAr (cm)");
96  
97  c1->cd(2);
98  plot(h1,h2);
99
100 //------------------------------------------------- 
101
102  h1 = (TH1F*)list->FindObject("fMult_hlt"); if(!h1) { printf("Empty histogram fMult_hlt\n"); return; }
103  h2 = (TH1F*)list->FindObject("fMult_off"); if(!h2) { printf("Empty histogram fMult_off\n"); return; }
104  h1->SetTitle("track multiplicity");
105
106  c1->cd(3);
107  plot(h1,h2);
108
109 //------------------------------------------------- 
110
111  h1 = (TH1F*)list->FindObject("fCharge_hlt"); if(!h1) { printf("Empty histogram fCharge_hlt\n"); return; }
112  h2 = (TH1F*)list->FindObject("fCharge_off"); if(!h2) { printf("Empty histogram fCharge_off\n"); return; }
113  h1->SetXTitle("polarity"); 
114  h1->SetTitle("charge distribution");
115
116  c1->cd(4);
117  plot(h1,h2);
118
119 //------------------------------------------------- 
120
121  h1 = (TH1F*)list->FindObject("fMomentum_hlt"); if(!h1) { printf("Empty histogram fMomentum_hlt\n"); return; }
122  h2 = (TH1F*)list->FindObject("fMomentum_off"); if(!h2) { printf("Empty histogram fMomentum_off\n"); return; }
123  h1->SetXTitle("p_{t} (GeV/c)"); 
124  h1->SetTitle("transverse momentum");
125
126  c1->cd(5);
127  plot(h1,h2);
128
129 //------------------------------------------------- 
130
131  h1 = (TH1F*)list->FindObject("fEta_hlt"); if(!h1) { printf("Empty histogram fEta_hlt\n"); return; }
132  h2 = (TH1F*)list->FindObject("fEta_off"); if(!h2) { printf("Empty histogram fEta_off\n"); return; }
133  h1->SetTitle("pseudorapidity");
134  h1->SetXTitle("#eta");
135
136  c1->cd(6);
137  plot(h1,h2);
138
139 //------------------------------------------------- 
140
141  h1 = (TH1F*)list->FindObject("fXvertex_hlt"); if(!h1) { printf("Empty histogram fXvertex_hlt\n"); return; }
142  h2 = (TH1F*)list->FindObject("fXvertex_off"); if(!h2) { printf("Empty histogram fXvertex_off\n"); return; }
143  h1->SetXTitle("x (cm)");
144  h1->SetTitle("x of primary vertex");
145
146  c1->cd(7);
147  plot(h1,h2);
148
149 //------------------------------------------------- 
150
151  h1 = (TH1F*)list->FindObject("fYvertex_hlt"); if(!h1) { printf("Empty histogram fYvertex_hlt\n"); return; }
152  h2 = (TH1F*)list->FindObject("fYvertex_off"); if(!h2) { printf("Empty histogram fYvertex_off\n"); return; }
153  h1->SetXTitle("y (cm)");
154  h1->SetTitle("y of primary vertex");
155  
156  c1->cd(8);
157  plot(h1,h2);
158
159 //------------------------------------------------- 
160
161  h1 = (TH1F*)list->FindObject("fZvertex_hlt"); if(!h1) { printf("Empty histogram fZvertex_hlt\n"); return; }
162  h2 = (TH1F*)list->FindObject("fZvertex_off"); if(!h2) { printf("Empty histogram fZvertex_off\n"); return; }
163  h1->SetXTitle("z (cm)");
164  h1->SetTitle("z of primary vertex");
165
166  c1->cd(9);
167  plot(h1,h2);
168
169 //------------------------------------------------- 
170
171  c1->SaveAs(folder+"/HLT-offline.png");  
172  c1->SaveAs(folder+"/HLT-offline.root");  
173  return;        
174 }
175
176 void printStats(TH1F* h1, TH1F* h2){  
177   
178   gPad->Update();
179   TPaveStats *st1 = (TPaveStats*)h1->FindObject("stats"); if(!st1) { printf("TPaveStats st1 is 0x0\n"); return; }       
180   st1->SetLineColor(0);
181  
182   gPad->Update();
183   TPaveStats *st2 = (TPaveStats*)h2->FindObject("stats"); if(!st2) { printf("TPaveStats st2 is 0x0\n"); return; }
184   st2->SetY2NDC(st1->GetY1NDC()-0.05);
185   st2->SetY1NDC(st2->GetY2NDC()-TMath::Abs(st1->GetY1NDC()-st1->GetY2NDC()));
186   st2->SetLineColor(0);
187   st2->SetTextColor(h2->GetLineColor());
188   st2->SetFillStyle(0);
189   st2->Draw();  
190   return;
191 }
192
193 void plot(TH1F *h1, TH1F *h2){ 
194   //Y axis
195   if(h1->GetMaximum() > h2->GetMaximum()) h2->SetMaximum(1.1*h1->GetMaximum());
196   else h1->SetMaximum(1.1*h2->GetMaximum());
197   
198   h1->SetMinimum(0);
199   h2->SetMinimum(0);
200   h2->SetLineColor(2);
201  
202   // X axis  
203   double xmin, xmax;  
204   if(h1->GetBinLowEdge(1) > h2->GetBinLowEdge(1)) xmin = h1->GetBinLowEdge(1);
205   else xmin = h2->GetBinLowEdge(1);
206   if(h1->GetBinLowEdge(h1->GetNbinsX()+1) > h2->GetBinLowEdge(h1->GetNbinsX()+1)) xmax = h1->GetBinLowEdge(h1->GetNbinsX()+1);
207   else xmax = h2->GetBinLowEdge(h2->GetNbinsX()+1);
208   
209   h2->SetAxisRange(xmin, xmax, "X");  
210   printStats(h1,h2);
211   
212   h1->Draw();
213   h2->Draw("sames");
214   return;
215 }