]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/vertexingHF/macros/DrawQAoutput.C
Speed up
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / macros / DrawQAoutput.C
1 #include <Riostream.h>
2 #include <TFile.h>
3 #include <TString.h>
4 #include <TH2F.h>
5 #include <TH1F.h>
6 #include <TF1.h>
7 #include <TDirectoryFile.h>
8 #include <TList.h>
9 #include <TCanvas.h>
10 #include <TLegend.h>
11 #include <TPaveText.h>
12 #include <TStyle.h>
13 #include <TClass.h>
14 #include <AliCounterCollection.h>
15
16 //read the file and take list and stat
17
18 Bool_t ReadFile(TList* &list,TH1F* &hstat,TString listname,TString partname,TString path="./",TString filename="AnalysisResults.root");
19
20 Bool_t ReadFile(TList* &list,TH1F* &hstat,TString listname,TString partname,TString path,TString filename){
21
22   TString hstatname="nEntriesQA",dirname="PWG3_D2H_QA";
23   filename.Prepend(path);
24   listname+=partname;
25   hstatname+=partname;
26
27   TFile* f=new TFile(filename.Data());
28   if(!f){
29     cout<<filename.Data()<<" not found"<<endl;
30     return kFALSE;
31   }
32   TDirectoryFile* dir=(TDirectoryFile*)f->Get(dirname);
33   if(!f){
34     cout<<dirname.Data()<<" not found  in "<<filename.Data()<<endl;
35     return kFALSE;
36   }
37
38   list=(TList*)dir->Get(listname);
39   if(!list){
40     cout<<"List "<<listname.Data()<<" not found"<<endl;
41     dir->ls();
42     return kFALSE;
43   }
44
45   hstat=(TH1F*)dir->Get(hstatname);
46   if(!hstat){
47     cout<<hstatname.Data()<<" not found"<<endl;
48     return kFALSE;
49   }
50   return kTRUE;
51 }
52
53 //draw "track related" histograms (list "outputTrack")
54 void DrawOutputTrack(TString partname="D0",TString textleg="",TString path="./"){
55   gStyle->SetCanvasColor(0);
56   gStyle->SetTitleFillColor(0);
57   gStyle->SetStatColor(0);
58   gStyle->SetPalette(1);
59
60   TString listname="outputTrack";
61
62   TList* list;
63   TH1F * hstat;
64
65   Bool_t isRead=ReadFile(list,hstat,listname,partname,path);
66   if(!isRead) return;
67   if(!list || !hstat){
68     cout<<":-( null pointers..."<<endl;
69     return;
70   }
71
72   for(Int_t i=0;i<list->GetEntries();i++){
73     TH1F* h=(TH1F*)list->At(i);
74     if(!h){
75       cout<<"Histogram "<<i<<" not found"<<endl;
76       continue;
77     }
78     TCanvas* c=new TCanvas(Form("c%s",h->GetName()),h->GetName());
79     c->cd();
80     c->SetGrid();
81     TString hname=h->GetName();
82     if(!hname.Contains("nCls")){
83       c->SetLogy();
84       h->Draw();
85     } else h->Draw("htext0");
86     c->SaveAs(Form("%s%s.png",c->GetName(),textleg.Data()));
87   }
88   
89   TCanvas* cst=new TCanvas("cst","Stat");
90   cst->SetGridy();
91   cst->cd();
92   hstat->Draw("htext0");
93   cst->SaveAs(Form("%s%s.png",hstat->GetName(),textleg.Data()));
94
95
96 }
97
98 //draw "pid related" histograms (list "outputPID")
99 void DrawOutputPID(TString partname="D0",TString textleg="",TString path="./"){
100   gStyle->SetCanvasColor(0);
101   gStyle->SetTitleFillColor(0);
102   gStyle->SetStatColor(0);
103   gStyle->SetPalette(1);
104
105   TString listname="outputPid";
106
107   TList* list;
108   TH1F * hstat;
109
110   Bool_t isRead=ReadFile(list,hstat,listname,partname,path);
111   if(!isRead) return;
112   if(!list || !hstat){
113     cout<<":-( null pointers..."<<endl;
114     return;
115   }
116
117   for(Int_t i=0;i<list->GetEntries();i++){
118     TClass* objtype=list->At(i)->IsA();
119     TString tpname=objtype->GetName();
120
121     if(tpname=="TH1F"){
122       TH1F* h=(TH1F*)list->At(i);
123
124       if(!h){
125         cout<<"Histogram "<<i<<" not found"<<endl;
126         continue;
127       }
128       //h->Scale(1./h->Integral("width"));
129       TCanvas* c=new TCanvas(Form("c%s",h->GetName()),h->GetName());
130       c->SetLogz();
131       c->cd();
132       h->Draw();
133     
134       //write
135       c->SaveAs(Form("%s.png",h->GetName()));
136       TFile* fout=new TFile(Form("%s.root",h->GetName()),"recreate");
137       fout->cd();
138       c->Write();
139     }
140   
141     if(tpname=="TH2F"){
142       TH2F* h=(TH2F*)list->At(i);
143       
144       if(!h){
145         cout<<"Histogram "<<i<<" not found"<<endl;
146         continue;
147       }
148       h->Scale(1./h->Integral("width"));
149       TCanvas* c=new TCanvas(Form("c%s",h->GetName()),h->GetName());
150       c->SetLogz();
151       c->cd();
152       
153       h->Draw("colz");
154       //write
155       c->SaveAs(Form("%s.png",h->GetName()));
156       TFile* fout=new TFile(Form("%s.root",h->GetName()),"recreate");
157       fout->cd();
158       c->Write();
159     }
160   }
161 }
162
163 void DrawOutputCentrality(TString partname="D0",TString textleg="",TString path="./"){
164   gStyle->SetCanvasColor(0);
165   gStyle->SetTitleFillColor(0);
166   gStyle->SetStatColor(0);
167   gStyle->SetPalette(1);
168
169   TString listname="outputCentrCheck";
170
171   TList* list;
172   TH1F * hstat;
173
174   Bool_t isRead=ReadFile(list,hstat,listname,partname,path);
175   if(!isRead) return;
176   if(!list || !hstat){
177     cout<<":-( null pointers..."<<endl;
178     return;
179   }
180   
181   for(Int_t i=0;i<list->GetEntries();i++){
182     TH1F* h=(TH1F*)list->At(i);
183     if(!h){
184       cout<<"Histogram "<<i<<" not found"<<endl;
185       continue;
186     }
187     TCanvas* c=new TCanvas(Form("c%s",h->GetName()),h->GetName());
188     c->cd();
189     c->SetGrid();
190     h->Draw();
191     c->SaveAs(Form("%s%s.png",c->GetName(),textleg.Data()));
192   }
193   
194   TCanvas* cst=new TCanvas("cst","Stat");
195   cst->SetGridy();
196   cst->cd();
197   hstat->Draw("htext0");
198   cst->SaveAs(Form("%s%s.png",hstat->GetName(),textleg.Data()));
199   
200   listname="countersCentrality";
201
202   isRead=ReadFile(list,hstat,listname,partname,path);
203   if(!isRead) return;
204   if(!list || !hstat){
205     cout<<":-( null pointers..."<<endl;
206     return;
207   }
208   for(Int_t i=0;i<list->GetEntries();i++){
209     AliCounterCollection* coll=(AliCounterCollection*)list->At(i);
210     
211     coll->SortRubric("run");//sort by run number
212     //coll->PrintKeyWords();
213     Int_t ncentr=10;//check this
214     TH1F* h020=0x0;
215     TH1F* h2080=0x0;
216     TCanvas *ccent=new TCanvas(Form("ccent%s",coll->GetName()),Form("Centrality vs Run (%s)",coll->GetName()),1400,800);
217     ccent->Divide(5,3);
218
219     for(Int_t ic=0;ic<ncentr;ic++){
220
221       TH1F* h=(TH1F*)coll->Get("run",Form("centralityclass:%d_%d",ic*10,ic*10+10));
222       h->SetName(Form("h%d%d",i,ic));
223       if(ic>=0 && ic<=1){ //0-20
224         if(!h020) {
225           h020=(TH1F*)h->Clone(Form("h020%s",coll->GetName()));
226           h020->SetTitle(Form("Centrality 0-20 %s",coll->GetName()));
227         }
228         else h020->Add(h);
229       }
230       if(ic>=2 && ic<=7){ //20-80
231         if(!h2080) {
232           h2080=(TH1F*)h->Clone(Form("h2080%s",coll->GetName()));
233           h2080->SetTitle(Form("Centrality 20-80 %s",coll->GetName()));
234         }
235         else h2080->Add(h);
236       }
237
238       ccent->cd(ic+1);
239       h->DrawClone();
240       // ccent->cd(1);
241       // h->SetLineColor(ic+1);
242       // if(ic==0)h->DrawClone();
243       // else h->DrawClone("sames");
244     }
245
246     ccent->cd(ncentr+1);
247     h020->DrawClone();
248
249     ccent->cd(ncentr+2);
250     h2080->DrawClone();
251
252     ccent->SaveAs(Form("%s%s.png",ccent->GetName(),textleg.Data()));
253   }
254
255 }