]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGHF/vertexingHF/macros/DrawQAoutput.C
Updates in plottinmg macro (ChiaraB)
[u/mrichter/AliRoot.git] / PWGHF / vertexingHF / macros / DrawQAoutput.C
CommitLineData
9cadfad3 1#if !defined(__CINT__) || defined(__MAKECINT__)
9af24f46 2#include <Riostream.h>
3#include <TFile.h>
4#include <TString.h>
5#include <TH2F.h>
6#include <TH1F.h>
7#include <TF1.h>
1fc8d3c0 8#include <TGraph.h>
9af24f46 9#include <TDirectoryFile.h>
10#include <TList.h>
11#include <TCanvas.h>
12#include <TLegend.h>
13#include <TPaveText.h>
0e4ff34e 14#include <TPaveStats.h>
9af24f46 15#include <TStyle.h>
82f89d0d 16#include <TClass.h>
1fc8d3c0 17#include <TDatabasePDG.h>
18#include <TParameter.h>
82f89d0d 19#include <AliCounterCollection.h>
1fc8d3c0 20#include <AliRDHFCuts.h>
9cadfad3 21#endif
9af24f46 22
9bec6e28 23/* $Id$ */
24
04fd2703 25TString *periodsname;
26
9af24f46 27//read the file and take list and stat
28
9cadfad3 29Bool_t ReadFile(TList* &list,TH1F* &hstat, TString listname,TString partname,TString path="./",TString filename=/*"AnalysisResults.root"*/"PWG3histograms.root", TString dirname="PWG3_D2H_QA");
30Bool_t ReadFileMore(TList* &list,TH1F* &hstat, AliRDHFCuts* &cutobj, TString listname,TString partname,TString path="./",TString filename=/*"AnalysisResults.root"*/"PWG3histograms.root", TString dirname="PWG3_D2H_QA");
04fd2703 31void SuperimposeBBToTPCSignal(Int_t period /*0=LHC10bc, 1=LHC10d, 2=LHC10h*/,TCanvas* cpid, Int_t set);
1fc8d3c0 32void TPCBetheBloch(Int_t set);
9af24f46 33
9cadfad3 34Bool_t ReadFile(TList* &list,TH1F* &hstat, TString listname,TString partname,TString path,TString filename, TString dirname){
9af24f46 35
9cadfad3 36 TString hstatname="nEntriesQA", cutobjname="";
9af24f46 37 filename.Prepend(path);
38 listname+=partname;
39 hstatname+=partname;
40
41 TFile* f=new TFile(filename.Data());
9cadfad3 42 if(!f->IsOpen()){
9af24f46 43 cout<<filename.Data()<<" not found"<<endl;
44 return kFALSE;
45 }
46 TDirectoryFile* dir=(TDirectoryFile*)f->Get(dirname);
9cadfad3 47 if(!dir){
48 cout<<dirname.Data()<<" not found in "<<filename.Data()<<endl;
49 f->ls();
9af24f46 50 return kFALSE;
51 }
52
53 list=(TList*)dir->Get(listname);
54 if(!list){
55 cout<<"List "<<listname.Data()<<" not found"<<endl;
56 dir->ls();
57 return kFALSE;
58 }
59
60 hstat=(TH1F*)dir->Get(hstatname);
61 if(!hstat){
62 cout<<hstatname.Data()<<" not found"<<endl;
63 return kFALSE;
64 }
1fc8d3c0 65
66 return kTRUE;
67}
68
9cadfad3 69Bool_t ReadFileMore(TList* &list,TH1F* &hstat, AliRDHFCuts* &cutobj, TString listname,TString partname,TString path,TString filename,TString dirname){
1fc8d3c0 70
9cadfad3 71 TString hstatname="nEntriesQA", cutobjname="";
1fc8d3c0 72 filename.Prepend(path);
73 listname+=partname;
74 hstatname+=partname;
75
f3e1ad2f 76 if(partname.Contains("Dplus")) cutobjname="AnalysisCuts";//"DplustoKpipiCutsStandard";
1fc8d3c0 77 else{
0093a491 78 if(partname.Contains("D0")) cutobjname="D0toKpiCutsStandard";//"D0toKpiCuts"
1fc8d3c0 79 else{
80 if(partname.Contains("Dstar")) cutobjname="DStartoKpipiCuts";
81 else{
82 if(partname.Contains("Ds")) cutobjname="DstoKKpiCuts";
83 else{
84 if(partname.Contains("D04")) cutobjname="D0toKpipipiCuts";
85 else{
86 if(partname.Contains("Lc")) cutobjname="LctopKpiAnalysisCuts";
87 }
88 }
89 }
90 }
91 }
92
93 TFile* f=new TFile(filename.Data());
9cadfad3 94 if(!f->IsOpen()){
1fc8d3c0 95 cout<<filename.Data()<<" not found"<<endl;
96 return kFALSE;
97 }
98 TDirectoryFile* dir=(TDirectoryFile*)f->Get(dirname);
9cadfad3 99 if(!dir){
1fc8d3c0 100 cout<<dirname.Data()<<" not found in "<<filename.Data()<<endl;
101 return kFALSE;
102 }
103
104 list=(TList*)dir->Get(listname);
105 if(!list){
106 cout<<"List "<<listname.Data()<<" not found"<<endl;
107 dir->ls();
108 return kFALSE;
109 }
110
111 hstat=(TH1F*)dir->Get(hstatname);
112 if(!hstat){
113 cout<<hstatname.Data()<<" not found"<<endl;
114 return kFALSE;
115 }
116
117 cutobj=(AliRDHFCuts*)dir->Get(cutobjname);
118 if(!cutobj){
119 cout<<cutobjname.Data()<<" not found"<<endl;
120 return kFALSE;
121 }
122
9af24f46 123 return kTRUE;
124}
125
126//draw "track related" histograms (list "outputTrack")
9bec6e28 127void DrawOutputTrack(TString partname="D0",TString textleg="",TString path="./", Bool_t superimpose=kFALSE, TString suffixdir="",TString filename=/*"AnalysisResults.root"*/"PWG3histograms.root", Bool_t normint=kTRUE /*normalize at integral, or at nevents*/){
9af24f46 128 gStyle->SetCanvasColor(0);
129 gStyle->SetTitleFillColor(0);
130 gStyle->SetStatColor(0);
131 gStyle->SetPalette(1);
132
9bec6e28 133 TString listname="outputTrack",name1="",name2="",path2="",filename2="PWG3histograms.root",legtext1="",legtext2="",suffixdir2="";
1fc8d3c0 134 TString tmp="y";
135
136 if(superimpose){
137 cout<<"Enter the names:\n>";
138 cin>>name1;
139 cout<<">";
140 cin>>name2;
141 cout<<"Are they in the same output file? (y/n)"<<endl;
142 cin>>tmp;
143 if(tmp=="n"){
04fd2703 144 cout<<"Path: \n";
145 cout<<">";
1fc8d3c0 146 cin>>path2;
04fd2703 147 cout<<"Filename: "<<endl;
148 cout<<">";
1fc8d3c0 149 cin>>filename2;
9bec6e28 150 cout<<"Suffix in the dir name, if any (otherwhise write no)\n>";
151 cin>>suffixdir2;
152 if(suffixdir2=="no") suffixdir2="";
153 cout<<"Text in the legend:\n 1)";
154 cin>>legtext1;
155 cout<<"2)";
156 cin>>legtext2;
1fc8d3c0 157 }
158
159 }
9af24f46 160
9bec6e28 161 Float_t nevents,nevents2;
9af24f46 162 TList* list;
163 TH1F * hstat;
9cadfad3 164 TString dirname="PWG3_D2H_QA";
9bec6e28 165 //dirname+=suffixdir;
166 Bool_t isRead=ReadFile(list,hstat,listname,Form("%s%s",partname.Data(),name1.Data()),path,filename,Form("%s%s",dirname.Data(),suffixdir.Data()));
9af24f46 167 if(!isRead) return;
168 if(!list || !hstat){
169 cout<<":-( null pointers..."<<endl;
170 return;
171 }
9bec6e28 172 nevents=hstat->GetBinContent(1);
1fc8d3c0 173 TPaveText *pvtxt=new TPaveText(0.6,0.6,0.9,0.9,"NDC");
174 pvtxt->SetBorderSize(0);
175 pvtxt->SetFillStyle(0);
9bec6e28 176 pvtxt->AddText(legtext1);
1fc8d3c0 177
178 TList* llist;
179 TH1F* hhstat;
180 if(superimpose){
9bec6e28 181 isRead=ReadFile(llist,hhstat,listname,Form("%s%s",partname.Data(),name2.Data()),path2,filename2,Form("%s%s",dirname.Data(),suffixdir2.Data()));
1fc8d3c0 182 if(!isRead) return;
183 if(!llist || !hhstat){
184 cout<<":-( null pointers..."<<endl;
185 return;
186 }
9bec6e28 187 nevents2=hhstat->GetBinContent(1);
188 TText *redtext=pvtxt->AddText(legtext2);
1fc8d3c0 189 redtext->SetTextColor(kRed);
04fd2703 190 hhstat->Scale(hstat->Integral()/hhstat->Integral());
1fc8d3c0 191
192 }
9af24f46 193
194 for(Int_t i=0;i<list->GetEntries();i++){
195 TH1F* h=(TH1F*)list->At(i);
1fc8d3c0 196 TH1F* hh=0x0;
52bcee7a 197 TH1F* hr=0x0;
1fc8d3c0 198 if(superimpose){
199 hh=(TH1F*)llist->At(i);
0093a491 200 hr=(TH1F*)hh->Clone(Form("%s_ratio",hh->GetName()));
9bec6e28 201 if(hh && TMath::Abs(hh->Integral()) > 1e-6)hh->Scale(h->Integral()/hh->Integral());
1fc8d3c0 202 }
203 if(!h || (superimpose && !hh)){
9af24f46 204 cout<<"Histogram "<<i<<" not found"<<endl;
205 continue;
206 }
1fc8d3c0 207 if(superimpose){
9bec6e28 208 if(normint) hh->Scale(h->Integral()/hh->Integral());
209 else hh->Scale(nevents/nevents2);
1fc8d3c0 210 hhstat->SetLineColor(kRed);
211 hh->SetLineColor(kRed);
52bcee7a 212 hr->Divide(h);
1fc8d3c0 213 }
214
9af24f46 215 TCanvas* c=new TCanvas(Form("c%s",h->GetName()),h->GetName());
216 c->cd();
217 c->SetGrid();
218 TString hname=h->GetName();
04fd2703 219 if(!hname.Contains("nCls")){
9af24f46 220 c->SetLogy();
0093a491 221 if(hname.Contains("Layer")){
222 for(Int_t ibin=1;ibin<=h->GetNbinsX();ibin++){
223 h->GetXaxis()->SetBinLabel(ibin+1,Form("%d",ibin));
224 }
225 h->GetXaxis()->SetLabelSize(0.06);
226 h->GetXaxis()->SetRangeUser(0,6); //comment to see ntracks!
227 }
1fc8d3c0 228 //h->SetMinimum(1);
9af24f46 229 h->Draw();
0093a491 230 if(superimpose)
9cadfad3 231 {
232 hh->Draw("sames");
233 TCanvas* c2=new TCanvas(Form("c2%s",h->GetName()),h->GetName());
234 c2->cd();
235 c2->SetGrid();
236 hr->Draw();
237 c2->SaveAs(Form("%s%s%s%sRatio.png",c->GetName(),name1.Data(),name2.Data(),textleg.Data()));
0093a491 238
9cadfad3 239 }
1fc8d3c0 240 } else {
241 h->Draw("htext0");
242 if(superimpose)hh->Draw("htext0sames");
243 }
52bcee7a 244 c->cd();
1fc8d3c0 245 pvtxt->Draw();
246 c->SaveAs(Form("%s%s%s%s.png",c->GetName(),name1.Data(),name2.Data(),textleg.Data()));
0093a491 247 c->SaveAs(Form("%s%s%s%s.eps",c->GetName(),name1.Data(),name2.Data(),textleg.Data()));
9af24f46 248 }
249
250 TCanvas* cst=new TCanvas("cst","Stat");
251 cst->SetGridy();
252 cst->cd();
253 hstat->Draw("htext0");
1fc8d3c0 254 if(superimpose) {
255 hhstat->Draw("htext0sames");
256 pvtxt->Draw();
257 }
9af24f46 258 cst->SaveAs(Form("%s%s.png",hstat->GetName(),textleg.Data()));
0093a491 259 cst->SaveAs(Form("%s%s.eps",hstat->GetName(),textleg.Data()));
9af24f46 260
0e4ff34e 261 TH1F* hd0fb4=(TH1F*)list->FindObject("hd0TracksFilterBit4");
262 TH1F* hd0SPD1=(TH1F*)list->FindObject("hd0TracksSPDin");
263 TH1F* hd0SPDany=(TH1F*)list->FindObject("hd0TracksSPDany");
264 TH1F* hd0TPCITScuts=(TH1F*)list->FindObject("hd0TracksTPCITSSPDany");
9bec6e28 265 TH1F* hhd0fb4=0x0; TH1F* hhd0SPD1=0x0; TH1F* hhd0SPDany=0x0; TH1F* hhd0TPCITScuts=0x0;
266 if(superimpose){
267 hhd0fb4=(TH1F*)llist->FindObject("hd0TracksFilterBit4");
268 hhd0SPD1=(TH1F*)llist->FindObject("hd0TracksSPDin");
269 hhd0SPDany=(TH1F*)llist->FindObject("hd0TracksSPDany");
270 hhd0TPCITScuts=(TH1F*)llist->FindObject("hd0TracksTPCITSSPDany");
271
272 }
0e4ff34e 273 if(hd0fb4 && hd0SPD1 && hd0SPDany && hd0TPCITScuts){
274 TCanvas* ctrsel=new TCanvas("ctrsel","Track Sel");
275 ctrsel->SetLogy();
9bec6e28 276 hd0SPD1->SetLineColor(kCyan+3);
0e4ff34e 277 hd0SPD1->Draw();
278 ctrsel->Update();
279 TPaveStats *st1=(TPaveStats*)hd0SPD1->GetListOfFunctions()->FindObject("stats");
9bec6e28 280 st1->SetTextColor(kCyan+3);
0e4ff34e 281 st1->SetY1NDC(0.71);
282 st1->SetY2NDC(0.9);
283 hd0SPDany->SetLineColor(4);
284 hd0SPDany->Draw("sames");
285 ctrsel->Update();
286 TPaveStats *st2=(TPaveStats*)hd0SPDany->GetListOfFunctions()->FindObject("stats");
287 st2->SetY1NDC(0.51);
288 st2->SetY2NDC(0.7);
289 st2->SetTextColor(4);
290 hd0fb4->SetLineColor(2);
291 hd0fb4->Draw("sames");
292 ctrsel->Update();
293 TPaveStats *st3=(TPaveStats*)hd0fb4->GetListOfFunctions()->FindObject("stats");
294 st3->SetY1NDC(0.31);
295 st3->SetY2NDC(0.5);
296 st3->SetTextColor(2);
297 hd0TPCITScuts->SetLineColor(kGreen+1);
298 hd0TPCITScuts->Draw("sames");
299 ctrsel->Update();
300 TPaveStats *st4=(TPaveStats*)hd0TPCITScuts->GetListOfFunctions()->FindObject("stats");
301 st4->SetY1NDC(0.71);
302 st4->SetY2NDC(0.9);
303 st4->SetX1NDC(0.55);
304 st4->SetX2NDC(0.75);
305 st4->SetTextColor(kGreen+1);
306 ctrsel->Modified();
307 TLegend* leg=new TLegend(0.15,0.5,0.45,0.78);
308 leg->SetFillStyle(0);
309 leg->SetBorderSize(0);
310 leg->AddEntry(hd0SPD1,"kITSrefit+SPD inner","L");
311 leg->AddEntry(hd0SPDany,"kITSrefit+SPD any","L");
312 leg->AddEntry(hd0TPCITScuts,"TPC+ITS cuts+SPD any","L");
313 leg->AddEntry(hd0fb4,"Filter Bit 4","L");
314 leg->Draw();
315
9bec6e28 316 if(superimpose && hhd0fb4 && hhd0SPD1 && hhd0SPDany && hhd0TPCITScuts){
317 hhd0SPD1->SetLineColor(kCyan+3);
318 hhd0SPD1->SetStats(0);
319 hhd0SPD1->SetLineStyle(3);
320 hhd0SPDany->SetLineColor(4);
321 hhd0SPDany->SetStats(0);
322 hhd0SPDany->SetLineStyle(3);
323 hhd0TPCITScuts->SetLineColor(kGreen+1);
324 hhd0TPCITScuts->SetStats(0);
325 hhd0TPCITScuts->SetLineStyle(3);
326 hhd0fb4->SetLineColor(2);
327 hhd0fb4->SetStats(0);
328 hhd0fb4->SetLineStyle(3);
329 ctrsel->cd();
330 hhd0SPD1->Draw("sames");
331 hhd0SPDany->Draw("sames");
332 hhd0TPCITScuts->Draw("sames");
333 hhd0fb4->Draw("sames");
334
335 }
0e4ff34e 336 ctrsel->SaveAs("ImpactParameterTrackSel.eps");
337 ctrsel->SaveAs("ImpactParameterTrackSel.png");
338
339 }
82f89d0d 340}
9af24f46 341
82f89d0d 342//draw "pid related" histograms (list "outputPID")
1fc8d3c0 343//period=-999 to draw the pull instead of the cut
9cadfad3 344void DrawOutputPID(TString partname="D0", Int_t mode=0/*0=with pull, 1=with nsigma*/,TString textleg="",TString path="./",TString suffixdir="", TString filename="AnalysisResults.root"){
82f89d0d 345 gStyle->SetCanvasColor(0);
346 gStyle->SetTitleFillColor(0);
9cadfad3 347 gStyle->SetOptStat(0);
82f89d0d 348 gStyle->SetPalette(1);
349
1fc8d3c0 350 Int_t period=2 ,set=0;
351 if(mode==1){
04fd2703 352 cout<<"Choose period: \n-LHC10h -> 2;\n-LHC10de -> 1;\n-LHC10bc -> 0"<<endl;
1fc8d3c0 353 cin>>period;
354 if(period>0){
355 cout<<"Choose set: "<<endl;
356 if(period==2) cout<<"-pass1 -> 0;\n-pass2 -> 1"<<endl;
357 cin>>set;
358 }
359 }
360
82f89d0d 361 TString listname="outputPid";
9cadfad3 362 TString dirname="PWG3_D2H_QA";
363 dirname+=suffixdir;
82f89d0d 364
365 TList* list;
366 TH1F * hstat;
1fc8d3c0 367 //needed only for mode 1
368 AliRDHFCuts* cutobj;
369 AliAODPidHF* aodpid;
370 Double_t nsigmaTOF=0;
371 Double_t nsigmaTPC[3]={},plimTPC[2]={};
372
373 if(mode==1){
9cadfad3 374 Bool_t isRead=ReadFileMore(list,hstat,cutobj,listname,partname,path,filename,dirname);
1fc8d3c0 375 if(!isRead) return;
376 if(!list || !hstat){
377 cout<<":-( null pointers..."<<endl;
378 return;
379 }
380 aodpid=(AliAODPidHF*)cutobj->GetPidHF();
04fd2703 381 if(!aodpid){
382 cout<<"PidHF object not found! cannot get the nsigma values"<<endl;
383 return;
384 }
1fc8d3c0 385 nsigmaTOF=aodpid->GetSigma(3);
386
387 nsigmaTPC[0]=aodpid->GetSigma(0);
388 nsigmaTPC[1]=aodpid->GetSigma(1);
389 nsigmaTPC[2]=aodpid->GetSigma(2);
390 aodpid->GetPLimit(plimTPC);
391
392 }else{
9cadfad3 393 Bool_t isRead=ReadFile(list,hstat,listname,partname,path,filename,dirname);
1fc8d3c0 394 if(!isRead) return;
395 if(!list || !hstat){
396 cout<<":-( null pointers..."<<endl;
397 return;
398 }
9af24f46 399 }
400
1fc8d3c0 401
402 TPaveText *txtsigmaTOF=new TPaveText(0.1,0.65,0.5,0.9,"NDC");
403 txtsigmaTOF->SetBorderSize(0);
404 txtsigmaTOF->SetFillStyle(0);
405 txtsigmaTOF->AddText(Form("nsigmacut from cutobj = %.1f",nsigmaTOF));
406 TLine lTOF;
407 lTOF.SetLineColor(kMagenta+1);
408 lTOF.SetLineStyle(2);
409 lTOF.SetLineWidth(3);
410
411 TPaveText *txtsigmaTPC=new TPaveText(0.3,0.6,0.6,0.9,"NDC");
412 txtsigmaTPC->SetBorderSize(0);
413 txtsigmaTPC->SetFillStyle(0);
414 txtsigmaTPC->AddText("nsigmacut from cutobj \n");
415 txtsigmaTPC->AddText(Form("p < %.1f : %.1f \n",plimTPC[0],nsigmaTPC[0]));
416 txtsigmaTPC->AddText(Form("%.1f < p < %.1f : %.1f \n",plimTPC[0],plimTPC[1],nsigmaTPC[1]));
417 txtsigmaTPC->AddText(Form("p > %.1f : %.1f \n",plimTPC[1],nsigmaTPC[2]));
418 TLine lTPC;
419 lTPC.SetLineColor(kMagenta+1);
420 lTPC.SetLineStyle(2);
421 lTPC.SetLineWidth(3);
422
423 // TCanvas *ctest=new TCanvas("text","Test text");
424 // ctest->cd();
425 // txtsigmaTPC->Draw();
426 // txtsigmaTOF->Draw();
427
428
82f89d0d 429 for(Int_t i=0;i<list->GetEntries();i++){
430 TClass* objtype=list->At(i)->IsA();
431 TString tpname=objtype->GetName();
432
433 if(tpname=="TH1F"){
434 TH1F* h=(TH1F*)list->At(i);
435
436 if(!h){
437 cout<<"Histogram "<<i<<" not found"<<endl;
438 continue;
439 }
440 //h->Scale(1./h->Integral("width"));
441 TCanvas* c=new TCanvas(Form("c%s",h->GetName()),h->GetName());
442 c->SetLogz();
443 c->cd();
444 h->Draw();
445
446 //write
1ff03d38 447 c->SaveAs(Form("%s%s.png",h->GetName(),textleg.Data()));
0093a491 448 c->SaveAs(Form("%s%s.eps",h->GetName(),textleg.Data()));
82f89d0d 449 TFile* fout=new TFile(Form("%s.root",h->GetName()),"recreate");
450 fout->cd();
451 c->Write();
452 }
453
454 if(tpname=="TH2F"){
455 TH2F* h=(TH2F*)list->At(i);
456
457 if(!h){
458 cout<<"Histogram "<<i<<" not found"<<endl;
459 continue;
460 }
9cadfad3 461 TString hname=h->GetName();
ac0c2841 462 h->Sumw2();
9cadfad3 463 if(h->Integral("width")==0) {cout<<"Empty histogram, skip\n"; continue;}
82f89d0d 464 h->Scale(1./h->Integral("width"));
9cadfad3 465
466 Double_t maxzaxis=h->GetBinContent(h->GetMaximumBin());
467 Double_t minzaxis=h->GetBinContent(h->GetMinimumBin());
2e7bd978 468 printf("Minimum = %f, maximum = %f\n",minzaxis,maxzaxis);
9cadfad3 469 TH2F* hallzrange=(TH2F*)h->Clone(Form("%swholez",hname.Data()));
470 hallzrange->SetAxisRange(1e-07,maxzaxis,"Z");
2e7bd978 471 //hallzrange->SetAxisRange(minzaxis,maxzaxis,"Z");
9cadfad3 472
473 TCanvas* cwholez=new TCanvas(Form("c%swholez",hname.Data()),Form("%s down to lowest z",hname.Data()));
474 cwholez->SetLogz();
475 hallzrange->Draw("colz");
476 cwholez->SaveAs(Form("%swholez.png",h->GetName()));
477 cwholez->SaveAs(Form("%swholez.eps",h->GetName()));
1fc8d3c0 478
479 if(hname.Contains("hTOFtimeKaonHyptime")){
480 TCanvas* cz=new TCanvas(Form("c%szoom",hname.Data()),Form("%szoom",hname.Data()));
481 cz->SetLogz();
482 TH2F* hz=(TH2F*)h->Clone(Form("%sz",hname.Data()));
483 hz->Draw("colz");
484 hz->SetAxisRange(-1500,1500,"Y");
0093a491 485 hz->SetAxisRange(0.,5.,"X");
1fc8d3c0 486 //write
487 cz->SaveAs(Form("%szoom.png",h->GetName()));
0093a491 488 cz->SaveAs(Form("%szoom.eps",h->GetName()));
1fc8d3c0 489 }
490
491 TCanvas* c=new TCanvas(Form("c%s",hname.Data()),hname.Data());
82f89d0d 492 c->SetLogz();
ac0c2841 493 //c->SetLogx();
9cadfad3 494 TCanvas* c2=new TCanvas(Form("c2%s",hname.Data()),hname.Data());
495 c2->SetLogz();
496
82f89d0d 497 c->cd();
9cadfad3 498 h->DrawClone("colz");
499
0093a491 500 if (hname.Contains("Sig") || hname.Contains("sigma"))h->SetAxisRange(-5,5,"Y");
9cadfad3 501 c2->cd();
0093a491 502 //if (hname.Contains("TOFtime"))h->SetAxisRange(-1500,1500,"Y");
503 h->SetAxisRange(0.,5.,"X");
504
82f89d0d 505 h->Draw("colz");
1fc8d3c0 506
507 //TCanvas *test=new TCanvas("test","test");
508 if(mode==0){
509 //mean and pull, code from Jens Wiechula
510 TF1 fg("fg","gaus",-2.,2.); // fit range +- 2 sigma
511 TLine l;
512 TObjArray arr;
513
514 //h->Draw("colz");
515 fg.SetParameters(1,0,1);
516 h->FitSlicesY(&fg,0,-1,0,"NQR",&arr);
517
518 TH1 *hM=(TH1*)arr.At(1);
519 hM->SetMarkerStyle(20);
520 hM->SetMarkerSize(.5);
521 hM->DrawClone("sames");
522
523 TH1 *hS=(TH1*)arr.At(2);
524 hS->SetMarkerStyle(20);
525 hS->SetMarkerSize(.5);
526 hS->SetMarkerColor(kRed);
527 hS->SetLineColor(kRed);
528 hS->DrawClone("same");
529
530 l.SetLineColor(kBlack);
531 l.DrawLine(.2,0,20,0);
532 l.SetLineColor(kRed);
533 l.DrawLine(.2,1,20,1);
534
535 }else{ //mode 1
536
537 if(hname.Contains("TOFsigma")) {
538
539 c->cd();
540 txtsigmaTOF->Draw();
541 lTOF.DrawLine(.2,nsigmaTOF,20,nsigmaTOF);
542 lTOF.DrawLine(.2,-1*nsigmaTOF,4.,-1*nsigmaTOF);
ac0c2841 543
1fc8d3c0 544 }
545
ac0c2841 546
1fc8d3c0 547 if(hname.Contains("TPCsigma")){
548
549 c->cd();
550 txtsigmaTPC->Draw();
551 lTPC.DrawLine(0.,nsigmaTPC[0],plimTPC[0],nsigmaTPC[0]);
552 lTPC.DrawLine(plimTPC[0],nsigmaTPC[1],plimTPC[1],nsigmaTPC[1]);
553 lTPC.DrawLine(plimTPC[1],nsigmaTPC[2],4,nsigmaTPC[2]);
554 lTPC.DrawLine(0.,-1*nsigmaTPC[0],plimTPC[0],-1*nsigmaTPC[0]);
555 lTPC.DrawLine(plimTPC[0],-1*nsigmaTPC[1],plimTPC[1],-1*nsigmaTPC[1]);
556 lTPC.DrawLine(plimTPC[1],-1*nsigmaTPC[2],4,-1*nsigmaTPC[2]);
557 }
ac0c2841 558
1fc8d3c0 559 if(hname.Contains("TPCsigvsp")){
560 SuperimposeBBToTPCSignal(period,c,set);
561 }
562 }
563
82f89d0d 564 //write
f3e1ad2f 565 c->SaveAs(Form("%s%d.png",h->GetName(),mode));
0093a491 566 c->SaveAs(Form("%s%d.eps",h->GetName(),mode));
9cadfad3 567 c2->SaveAs(Form("%s2%d.png",h->GetName(),mode));
568 c2->SaveAs(Form("%s2%d.eps",h->GetName(),mode));
569
f3e1ad2f 570 TFile* fout=new TFile(Form("%s%d.root",h->GetName(),mode),"recreate");
82f89d0d 571 fout->cd();
572 c->Write();
9cadfad3 573 c2->Write();
1fc8d3c0 574 }
575 }
576}
577
578void SuperimposeBBToTPCSignal(Int_t period /*0=LHC10bc, 1=LHC10d, 2=LHC10h*/,TCanvas* cpid,Int_t set /*see below*/){
579
580 TFile* fBethe=new TFile("BetheBlochTPC.root");
581 if(!fBethe->IsOpen()){
582 TPCBetheBloch(set);
583 fBethe=new TFile("BetheBlochTPC.root");
584 }
585 const Int_t npart=4;
586 TString partnames[npart]={"Kaon","Pion","Electron","Proton"};
587 for(Int_t ipart=0;ipart<npart;ipart++){
588 TString grname=Form("%sP%d",partnames[ipart].Data(),period);
589 TGraph* gr=(TGraph*)fBethe->Get(grname);
590 cpid->cd();
591 gr->SetLineColor(1);
592 gr->SetLineWidth(2);
593 gr->Draw("L");
594 }
595
596 //cpid->SaveAs(Form("%sBB.png",hname.Data()));
597}
598
599//draw and save Bethe Bloch from TPC in different periods
600void TPCBetheBloch(Int_t set){
601 gStyle->SetOptTitle(0);
602 gStyle->SetCanvasColor(0);
603
604 AliTPCPIDResponse *tpcResp=new AliTPCPIDResponse();
605
606 const Int_t npart=4;
0093a491 607 //Double_t masses[npart]={TDatabasePDG::Instance()->GetParticle(321)->Mass()/*Kaon*/,TDatabasePDG::Instance()->GetParticle(211)->Mass()/*Pion*/,TDatabasePDG::Instance()->GetParticle(11)->Mass()/*Electron*/,TDatabasePDG::Instance()->GetParticle(2212)->Mass()/*Proton*/};
1fc8d3c0 608 TString partnames[npart]={"Kaon","Pion","Electron","Proton"};
609 //printf("%s = %.4f,%s = %.4f,%s = %.4f\n",partnames[0].Data(),masses[0],partnames[1].Data(),masses[1],partnames[2].Data(),masses[2]);
610 TCanvas *cBethe=new TCanvas("cBethe","Bethe Bloch K pi e p");
04fd2703 611 Int_t nperiods=4; //LHC10b+c, LHC10d, LHC10h, MC
1fc8d3c0 612 Double_t alephParameters[5]={};
04fd2703 613 Int_t nsets=1/*LHC10bc*/+2/*LHC10de*/+2/*LHC10h*/+3/*MC*/;
1fc8d3c0 614
04fd2703 615 periodsname=new TString[nsets];
616 cout<<"Creating the file of the Bethe Bloch"<<endl;
1fc8d3c0 617 TFile* fout=new TFile("BetheBlochTPC.root","recreate");
618
619 for(Int_t iperiod=0;iperiod<nperiods;iperiod++){
04fd2703 620 cout<<"Period "<<iperiod<<" : ";
621 if(iperiod==0){ //LHC10bc
622
623 alephParameters[0] = 0.0283086/0.97;
624 alephParameters[1] = 2.63394e+01;
625 alephParameters[2] = 5.04114e-11;
626 alephParameters[3] = 2.12543e+00;
627 alephParameters[4] = 4.88663e+00;
628 periodsname[0]="dataLHC10bc";
1fc8d3c0 629 }
04fd2703 630 if(iperiod==1){ //LHC10de,low energy
1fc8d3c0 631 if(set==0){
632 alephParameters[0] = 1.63246/50.;
633 alephParameters[1] = 2.20028e+01;
634 alephParameters[2] = TMath::Exp(-2.48879e+01);
635 alephParameters[3] = 2.39804e+00;
636 alephParameters[4] = 5.12090e+00;
04fd2703 637 periodsname[1]="dataLHC10deold";
1fc8d3c0 638 }
639 if(set==1){
640 alephParameters[0] = 1.34490e+00/50.;
641 alephParameters[1] = 2.69455e+01;
642 alephParameters[2] = TMath::Exp(-2.97552e+01);
643 alephParameters[3] = 2.35339e+00;
644 alephParameters[4] = 5.98079e+00;
04fd2703 645 periodsname[2]="dataLHC10denew";
1fc8d3c0 646 }
647 }
04fd2703 648
649 if(iperiod==2){//LHC10h
650 if(set==0){//pass1
651 alephParameters[0]=1.25202/50.;
652 alephParameters[1]=2.74992e+01;
653 alephParameters[2]=TMath::Exp(-3.31517e+01);
654 alephParameters[3]=2.46246;
655 alephParameters[4]=6.78938;
656 periodsname[3]="dataLHC10hpass1";
657 }
658 if (set==1){//pass2 (AOD044)
659 alephParameters[0]=1.25202/50.;
660 alephParameters[1]=2.74992e+01;
661 alephParameters[2]=TMath::Exp(-3.31517e+01);
662 alephParameters[3]=2.46246;
663 alephParameters[4]=6.78938;
664 periodsname[4]="dataLHC10hpass2";
665 }
1fc8d3c0 666 }
04fd2703 667 if(iperiod==3){ //MC
f3e1ad2f 668 if(set==0){
669 alephParameters[0] = 2.15898e+00/50.;
670 alephParameters[1] = 1.75295e+01;
671 alephParameters[2] = 3.40030e-09;
672 alephParameters[3] = 1.96178e+00;
673 alephParameters[4] = 3.91720e+00;
04fd2703 674 periodsname[5]="MCold";
f3e1ad2f 675 }
676 if(set==1){ //new
677 alephParameters[0] = 1.44405/50;
678 alephParameters[1] = 2.35409e+01;
679 alephParameters[2] = TMath::Exp(-2.90330e+01);
680 alephParameters[3] = 2.10681;
681 alephParameters[4] = 4.62254;
04fd2703 682 periodsname[6]="MCnew";
683 }
684
685 if(set==2){ //new BB from Francesco
686 alephParameters[0] = 0.029021;
687 alephParameters[1] = 25.4181;
688 alephParameters[2] = 4.66596e-08;
689 alephParameters[3] = 1.90008;
690 alephParameters[4] = 4.63783;
691 periodsname[7]="MCBBFrancesco";
f3e1ad2f 692 }
04fd2703 693
694 if(set==3){ //low energy 2011
695 alephParameters[0] = 0.0207667;
696 alephParameters[1] = 29.9936;
697 alephParameters[2] = 3.87866e-11;
698 alephParameters[3] = 2.17291;
699 alephParameters[4] = 7.1623;
700 //periodsname[8]="MClowen2011";
701 }
702
703
f3e1ad2f 704 }
04fd2703 705 //cout<<periodsname[iperiod]<<endl;
1fc8d3c0 706 tpcResp->SetBetheBlochParameters(alephParameters[0],alephParameters[1],alephParameters[2],alephParameters[3],alephParameters[4]);
04fd2703 707 cout<<"here"<<endl;
1fc8d3c0 708 for(Int_t ipart=0;ipart<npart;ipart++){
ac0c2841 709
1fc8d3c0 710 const Int_t n=1000;
711 Double_t p[n],bethe[n];
712
713 for(Int_t k=0;k<n;k++){ //loop on the momentum steps
714 p[k]=0.0001+k*4./n; //limits 0.-4. GeV/c
715 //cout<<p[k]<<"\t";
716 //bethe[k]=-tpcResp->Bethe(p[k]/masses[ipart]);
717 AliPID::EParticleType ptype=AliPID::kKaon;
718 if(ipart==1) ptype=AliPID::kPion;
719 if(ipart==2) ptype=AliPID::kElectron;
720 if(ipart==3) ptype=AliPID::kProton;
721 bethe[k]=tpcResp->GetExpectedSignal(p[k],ptype);
722 }
723 //cout<<endl;
724 TGraph *gr=new TGraph(n,p,bethe);
725 gr->SetName(Form("%sP%d",partnames[ipart].Data(),iperiod));
726 gr->SetTitle(Form("%sP%d;p (GeV/c);",partnames[ipart].Data(),iperiod));
727 gr->SetLineColor(ipart+1);
728 gr->SetMarkerColor(ipart+1);
729 gr->GetYaxis()->SetRangeUser(35,100);
730 cBethe->cd();
731 if(iperiod==0 && ipart==0)gr->DrawClone("AL");
732 else gr->DrawClone("L");
733
734 fout->cd();
735 gr->Write();
82f89d0d 736 }
1fc8d3c0 737
9af24f46 738 }
1fc8d3c0 739 TParameter<int> sett;
740 sett.SetVal(set);
741 fout->cd();
742 sett.Write();
743
744 fout->Close();
9af24f46 745}
746
9cadfad3 747void DrawOutputCentrality(TString partname="D0",TString textleg="",TString path="./", Bool_t superimpose=kFALSE,TString suffixdir="",TString filename=/*"AnalysisResults.root"*/"PWG3histograms.root"){
9af24f46 748 gStyle->SetCanvasColor(0);
749 gStyle->SetTitleFillColor(0);
750 gStyle->SetStatColor(0);
751 gStyle->SetPalette(1);
752
2e7bd978 753 TString listname="outputCentrCheck",partname2="",path2="",suffixdir2="",filename2="PWG3histograms.root";
04fd2703 754
755 // if(superimpose){
756 // cout<<"Enter the names:\n>";
757 // cin>>name1;
758 // cout<<">";
759 // cin>>name2;
760 // }
761 // TString listname="outputTrack",name1="",name2="";
762 TString tmp="y";
1fc8d3c0 763
764 if(superimpose){
2e7bd978 765 cout<<"##Second file\n";
766 cout<<"Enter the name:\n";
1fc8d3c0 767 cout<<">";
2e7bd978 768 cin>>partname2;
04fd2703 769 cout<<"Are they in the same output file? (y/n)"<<endl;
770 cin>>tmp;
771 if(tmp=="n"){
772 cout<<"Path: \n";
773 cout<<">";
774 cin>>path2;
2e7bd978 775 cout<<"Dir name:\n";
776 cout<<">";
777 cin>>suffixdir2;
04fd2703 778 cout<<"Filename: "<<endl;
779 cout<<">";
780 cin>>filename2;
781 }
782
1fc8d3c0 783 }
784 // Int_t nhist=1;
785 // TString *name=0x0;
786 // if(superimpose){
787 // cout<<"Number of histogram to superimpose: ";
788 // cin>>nhist;
789 // name=new TString[nhist];
790 // for (Int_t j=0;j<nhist;j++){
791 // cout<<">";
792 // cin>>name[j];
793 // }
794 // }
9af24f46 795
796 TList* list;
797 TH1F * hstat;
798
2e7bd978 799 TString dirname="PWG3_D2H_QA",dirname2=dirname;
9cadfad3 800 dirname+=suffixdir;
2e7bd978 801 dirname2+=suffixdir2;
802 Bool_t isRead=ReadFile(list,hstat,listname,partname.Data(),path,filename,dirname);
9af24f46 803 if(!isRead) return;
804 if(!list || !hstat){
805 cout<<":-( null pointers..."<<endl;
806 return;
807 }
1ff03d38 808
1fc8d3c0 809 TPaveText *pvtxt=new TPaveText(0.6,0.6,0.9,0.9,"NDC");
810 pvtxt->SetBorderSize(0);
811 pvtxt->SetFillStyle(0);
2e7bd978 812 pvtxt->AddText(partname);
1fc8d3c0 813
814 TList* llist;
815 TH1F* hhstat;
816 if(superimpose){
2e7bd978 817 isRead=ReadFile(llist,hhstat,listname,partname2.Data(),path2,filename2,dirname2);
1fc8d3c0 818 if(!isRead) return;
819 if(!llist || !hhstat){
820 cout<<":-( null pointers..."<<endl;
821 return;
822 }
2e7bd978 823 TText *redtext=pvtxt->AddText(partname2);
1fc8d3c0 824 redtext->SetTextColor(kRed);
825
826 }
827
828
82f89d0d 829 TCanvas* cst=new TCanvas("cst","Stat");
830 cst->SetGridy();
831 cst->cd();
0093a491 832 Int_t nevents=hstat->GetBinContent(1);
82f89d0d 833 hstat->Draw("htext0");
834 cst->SaveAs(Form("%s%s.png",hstat->GetName(),textleg.Data()));
0093a491 835 cst->SaveAs(Form("%s%s.eps",hstat->GetName(),textleg.Data()));
04fd2703 836 Int_t nevents080=1,nnevents080=1;
1ff03d38 837
ac0c2841 838 //TCanvas *spare=new TCanvas("sparecv","Spare");
839
1ff03d38 840 for(Int_t i=0;i<list->GetEntries();i++){
841
842 TClass* objtype=list->At(i)->IsA();
843 TString tpname=objtype->GetName();
844
845 if(tpname=="TH1F"){
846
847 TH1F* h=(TH1F*)list->At(i);
1fc8d3c0 848 TH1F* hh=0x0;
849 if(superimpose){
850 hh=(TH1F*)llist->At(i);
851 }
852 if(!h || (superimpose && !hh)){
1ff03d38 853 cout<<"Histogram "<<i<<" not found"<<endl;
854 continue;
855 }
1fc8d3c0 856 if(superimpose){
857 hhstat->SetLineColor(kRed);
858 hh->SetLineColor(kRed);
859 }
860
1ff03d38 861 TCanvas* c=new TCanvas(Form("c%s",h->GetName()),h->GetName());
1fc8d3c0 862 TPaveText *pvtxt2=new TPaveText(0.6,0.6,0.9,0.9,"NDC");
863 pvtxt2->SetBorderSize(0);
864 pvtxt2->SetFillStyle(0);
1ff03d38 865
866 c->cd();
867 c->SetGrid();
1fc8d3c0 868 c->SetLogy();
1ff03d38 869 Int_t entries=h->Integral();
04fd2703 870 pvtxt2->AddText(Form("%.1f %s of the events",(Double_t)entries/(Double_t)nevents*100,"%"));
1ff03d38 871 h->Draw();
1fc8d3c0 872 if(superimpose) {
873 hh->Draw("sames");
874 pvtxt->Draw();
875 }
876 pvtxt2->Draw();
0093a491 877 c->SaveAs(Form("%s%s.pdf",c->GetName(),textleg.Data()));
878 c->SaveAs(Form("%s%s.eps",c->GetName(),textleg.Data()));
1ff03d38 879 }
880 if(tpname=="TH2F"){
881 TH2F* h=(TH2F*)list->At(i);
882 if(!h){
883 cout<<"Histogram "<<i<<" not found"<<endl;
884 continue;
885 }
886 TCanvas* c=new TCanvas(Form("c%s",h->GetName()),h->GetName());
2e7bd978 887 TPaveText *pvtxt3=new TPaveText(0.6,0.6,0.9,0.9,"NDC");
888 pvtxt3->SetBorderSize(0);
889 pvtxt3->SetFillStyle(0);
1ff03d38 890
891 c->cd();
892 c->SetGrid();
893 Int_t entries=h->Integral();
2e7bd978 894 pvtxt3->AddText(Form("%.1f %s of the events",(Double_t)entries/(Double_t)nevents*100,"%"));
1ff03d38 895 h->Draw("colz");
896 c->SetLogz();
2e7bd978 897 pvtxt3->Draw();
0093a491 898 c->SaveAs(Form("%s%s.pdf",c->GetName(),textleg.Data()));
899 c->SaveAs(Form("%s%s.eps",c->GetName(),textleg.Data()));
1ff03d38 900 }
901 }
902
82f89d0d 903
904 listname="countersCentrality";
905
2e7bd978 906 isRead=ReadFile(list,hstat,listname,partname.Data(),path,filename,dirname);
82f89d0d 907 if(!isRead) return;
908 if(!list || !hstat){
909 cout<<":-( null pointers..."<<endl;
910 return;
911 }
1ff03d38 912
04fd2703 913
914 if(superimpose){
2e7bd978 915 isRead=ReadFile(llist,hhstat,listname,partname2.Data(),path2,filename2,dirname2);
04fd2703 916 if(!isRead) return;
917 if(!llist || !hhstat){
918 cout<<":-( null pointers..."<<endl;
919 return;
920 }
2e7bd978 921 TText *redtext=pvtxt->AddText(partname2);
04fd2703 922 redtext->SetTextColor(kRed);
923
924 }
925
1ff03d38 926 TH1F* hallcntr=0x0;
04fd2703 927 TH1F* hhallcntr=0x0;
1ff03d38 928 cout<<"normalizing to 0-80% as a check"<<endl;
0093a491 929 Int_t ncentr=10;//check this
930 TH1F* h020=0x0;
931 TH1F* h2080=0x0;
932 TH1F* hh020=0x0;
933 TH1F* hh2080=0x0;
1ff03d38 934
935 TCanvas *cvnocnt=new TCanvas("cvnocnt","No Centrality estimation",800,400);
936 cvnocnt->Divide(2,1);
0093a491 937 TCanvas *ccent=0x0;
1ff03d38 938
82f89d0d 939 for(Int_t i=0;i<list->GetEntries();i++){
940 AliCounterCollection* coll=(AliCounterCollection*)list->At(i);
04fd2703 941 AliCounterCollection* colle=0x0;
942 if(superimpose) colle=(AliCounterCollection*)llist->At(i);
82f89d0d 943 coll->SortRubric("run");//sort by run number
1ff03d38 944
9cadfad3 945 h020=0x0;
946 h2080=0x0;
947 hh020=0x0;
948 hh2080=0x0;
0093a491 949
9cadfad3 950 hallcntr=0x0;
951 hhallcntr=0x0;
0093a491 952
9cadfad3 953 TH1F* hbad=(TH1F*)coll->Get("run",Form("centralityclass:-990_-980"));
954 cvnocnt->cd(i+1);
955 if(hbad) hbad->Draw();
0093a491 956
9cadfad3 957 ccent=new TCanvas(Form("ccent%s",coll->GetName()),Form("Centrality vs Run (%s)",coll->GetName()),1400,800);
958 ccent->SetTicky();
959 ccent->Divide(4,2);
960
961 TH1F* hh=0x0;
0093a491 962
9cadfad3 963 for(Int_t ic=0;ic<8/*ncentr*/;ic++){ //normalizing to 0-80% as a check
0093a491 964
9cadfad3 965 TH1F* h=(TH1F*)coll->Get("run",Form("centralityclass:%d_%d",ic*10,ic*10+10));
966 h->SetName(Form("h%d%d",i,ic));
967 if(!hallcntr) {
968 hallcntr=(TH1F*)h->Clone("hallcntr");
969 hallcntr->Sumw2();
970 } else {
971 hallcntr->Add(h);
82f89d0d 972 }
9cadfad3 973
974 nevents080+=h->Integral();
0093a491 975
9cadfad3 976 if(superimpose){
977 hh=(TH1F*)colle->Get("run",Form("centralityclass:%d_%d",ic*10,ic*10+10));
978 hh->SetName(Form("hh%d%d",i,ic));
979 if(!hhallcntr) {
980 hhallcntr=(TH1F*)hh->Clone("hhallcntr");
981 hhallcntr->Sumw2();
982 }else hhallcntr->Add(hh);
2e7bd978 983
9cadfad3 984 nnevents080+=hh->Integral();
985
986 }
987 }
0093a491 988
9cadfad3 989 for(Int_t ic=0;ic<ncentr;ic++){
0093a491 990
9cadfad3 991 TH1F* h=(TH1F*)coll->Get("run",Form("centralityclass:%d_%d",ic*10,ic*10+10));
992 h->SetName(Form("h%d%d",i,ic));
993 h->Sumw2();
994
995 if(ic>=0 && ic<=1){ //0-20
996 if(!h020) {
997 h020=(TH1F*)h->Clone(Form("h020%s",coll->GetName()));
998 h020->SetTitle(Form("Centrality 0-20 %s",coll->GetName()));
999 if(superimpose){
1000 hh020=(TH1F*)hh->Clone(Form("hh020%s",coll->GetName()));
1001 hh020->SetTitle(Form("Centrality 0-20 %s",coll->GetName()));
04fd2703 1002 }
82f89d0d 1003 }
9cadfad3 1004 else {
1005 h020->Add(h);
1006 if(superimpose)hh020->Add(hh);
1007 }
1008 }
1009 if(ic>=2 && ic<=7){ //20-80
1010 if(!h2080) {
1011 h2080=(TH1F*)h->Clone(Form("h2080%s",coll->GetName()));
1012 h2080->SetTitle(Form("Centrality 20-80 %s",coll->GetName()));
1013 if(superimpose){
1014 hh2080=(TH1F*)hh->Clone(Form("hh2080%s",coll->GetName()));
1015 hh2080->SetTitle(Form("Centrality 20-80 %s",coll->GetName()));
0093a491 1016 }
0093a491 1017 }
9cadfad3 1018 else {
1019 h2080->Add(h);
1020 if(superimpose)hh2080->Add(hh);
1021 }
1022
1023 }
82f89d0d 1024
9cadfad3 1025 h->Divide(hallcntr);
1ff03d38 1026
9cadfad3 1027 if(ic<8){
0093a491 1028 ccent->cd(ic+1);
9cadfad3 1029 h->GetYaxis()->SetLabelSize(0.05);
1030 h->GetYaxis()->SetTitleOffset(1.5);
1031 h->SetMinimum(0);
1032 //h->GetYaxis()->SetRangeUser(0.,0.15);
0093a491 1033 h->DrawClone();
ac0c2841 1034 }
9cadfad3 1035 /*
1036 if(ic==0&&i==0){
1037 spare->cd();
1038 h->Draw();
1039 }
1040 */
1041 // ccent->cd(1);
1042 // h->SetLineColor(ic+1);
1043 // if(ic==0)h->DrawClone();
1044 // else h->DrawClone("sames");
82f89d0d 1045 }
1ff03d38 1046 h020->Divide(hallcntr);
04fd2703 1047 if(superimpose){
1048 hh020->Divide(hhallcntr);
1049 hh020->SetLineColor(2);
1050 hh020->SetMarkerColor(2);
2e7bd978 1051 }
1052
1053 /*//draw 0-20 and 20-80 in the multi pad canvas (increase divisions before uncommenting)
1054 ccent->cd(ncentr+1);
1055 h020->DrawClone();
1056 if(superimpose){
04fd2703 1057 hh020->DrawClone("sames");
1058 }
9cadfad3 1059 */
1fc8d3c0 1060 TCanvas* cv020=new TCanvas(Form("cv020-%d",i),"0-20% vs run number",1400,600);
1ff03d38 1061 cv020->cd();
9cadfad3 1062 cv020->SetTicky();
1ff03d38 1063 h020->GetYaxis()->SetRangeUser(0.,1.);
82f89d0d 1064 h020->DrawClone();
04fd2703 1065 if(superimpose)hh020->DrawClone("sames");
0093a491 1066 cv020->SaveAs(Form("cv020-%d.pdf",i));
1067 cv020->SaveAs(Form("cv020-%d.eps",i));
82f89d0d 1068
1ff03d38 1069 h2080->Divide(hallcntr);
2e7bd978 1070 if(superimpose) {
04fd2703 1071 hh2080->Divide(hhallcntr);
1072 hh2080->SetLineColor(2);
1073 hh2080->SetMarkerColor(2);
04fd2703 1074 }
82f89d0d 1075
2e7bd978 1076 /*
1077 ccent->cd(ncentr+2);
1078 h2080->DrawClone();
1079
1080 if(superimpose){
1081 hh2080->DrawClone("sames");
1082 }
1083 */
1fc8d3c0 1084 TCanvas* cv2080=new TCanvas(Form("cv2080-%d",i),"20-80% vs run number",1400,600);
1ff03d38 1085 cv2080->cd();
9cadfad3 1086 cv2080->SetTicky();
1ff03d38 1087 h2080->GetYaxis()->SetRangeUser(0.,1.);
1088 h2080->DrawClone();
04fd2703 1089 if(superimpose)hh2080->DrawClone("sames");
0093a491 1090 cv2080->SaveAs(Form("cv2080-%d.pdf",i));
1091 cv2080->SaveAs(Form("cv2080-%d.eps",i));
1ff03d38 1092
0093a491 1093 ccent->SaveAs(Form("%s%s.pdf",ccent->GetName(),textleg.Data()));
1094 ccent->SaveAs(Form("%s%s.eps",ccent->GetName(),textleg.Data()));
9af24f46 1095 }
0093a491 1096
9af24f46 1097}
1ff03d38 1098
2e7bd978 1099void DrawProjections(TString partname="D0",TString h2dname="hMultvsPercentile",Int_t groupnbins=5,Float_t fitmin=15,Float_t fitmax=50,TString direction="X",TString path="./",TString suffixdir="", TString filename="AnalysisResults.root", TString fitfunc="pol0"/*option "nofit" does not fit*/){
1ff03d38 1100 gStyle->SetCanvasColor(0);
1101 gStyle->SetTitleFillColor(0);
1102 gStyle->SetStatColor(0);
29df3603 1103 gStyle->SetPalette(1);
1ff03d38 1104
1105 TString listname="outputCentrCheck";
9cadfad3 1106 TString dirname="PWG3_D2H_QA";
1107 dirname+=suffixdir;
1ff03d38 1108
1109 TList* list;
1110 TH1F * hstat;
1111
9cadfad3 1112 Bool_t isRead=ReadFile(list,hstat,listname,partname,path,filename,dirname);
1ff03d38 1113 if(!isRead) return;
1114 if(!list || !hstat){
1115 cout<<":-( null pointers..."<<endl;
1116 return;
1117 }
0093a491 1118 Double_t nevents=hstat->GetBinContent(5); //ev good vertex
1ff03d38 1119
1120 TH2F* h2=(TH2F*)list->FindObject(h2dname);
1121 if(!h2){
1122 cout<<h2dname.Data()<<" not found"<<endl;
2e7bd978 1123 list->ls();
1ff03d38 1124 return;
1125 }
29df3603 1126 TCanvas* cv2d=new TCanvas("cv2d",h2->GetName());
1127 cv2d->cd();
1128 cv2d->SetLogz();
1fc8d3c0 1129 cv2d->SetGrid();
29df3603 1130 h2->Draw("colz");
1fc8d3c0 1131 TPaveText *pvst=new TPaveText(0.6,0.2,0.9,0.7,"NDC");
1132 pvst->SetBorderSize(0);
1133 pvst->SetFillStyle(0);
1134 pvst->AddText("Bin -> Cont/nEvVtx");
1135
2e7bd978 1136 //nsteps=group bins in the Y(X) direction if projecting on the X(Y) direction
1137 Int_t nsteps=0;
29df3603 1138
2e7bd978 1139 if(direction=="X") nsteps=h2->GetNbinsY()/groupnbins;
1140 if(direction=="Y") nsteps=h2->GetNbinsX()/groupnbins;
1141 cout<<"Grouping bins by " <<groupnbins<<" I obtaine "<<nsteps<<" projections"<<endl;
1ff03d38 1142
0093a491 1143 TCanvas *cvpj=new TCanvas(Form("cvpj%s%s",direction.Data(),h2dname.Data()),Form("cvpj%s",direction.Data()),1200,800);
1ff03d38 1144 cvpj->Divide((Int_t)(nsteps/3)+1,3);
1145 TFile* fout=new TFile(Form("proj%s%s.root",direction.Data(),h2dname.Data()), "recreate");
1fc8d3c0 1146 //Float_t maxx[nsteps];
2e7bd978 1147 //Float_t maxx[12]={9000,9000,6000,4000,2000,1400,800,500,200,100,40,25};
1fc8d3c0 1148 Double_t integralpernev[nsteps];
1149
2e7bd978 1150 Double_t minx=0,maxx=0;
1151 if(direction=="X"){
1152 minx=h2->GetYaxis()->GetXmin();
1153 maxx=h2->GetYaxis()->GetXmax();
1154 }
1155 if(direction=="Y"){
1156 minx=h2->GetXaxis()->GetXmin();
1157 maxx=h2->GetXaxis()->GetXmax();
1158 }
1159 printf("Plotting from %.1f to %.1f\n",minx,maxx);
1160 TCanvas *cintegral=new TCanvas("cintegral","Integral of each projection");
1161 TH1F* hint=new TH1F("hint","Integral of each projection;Centrality (%);Entries",nsteps,minx,maxx);
1162 Double_t minint=999999999,maxint=0;
1163
1ff03d38 1164 for(Int_t i=0;i<nsteps;i++){
1165 TH1F* h=0x0;
2e7bd978 1166 // if(direction=="X")h=(TH1F*)h2->ProjectionX(Form("px%d",i),i+kbins,i+2*kbins);
1167 // if(direction=="Y")h=(TH1F*)h2->ProjectionY(Form("py%d",i),i+kbins,i+2*kbins);
1168 if(direction=="X")h=(TH1F*)h2->ProjectionX(Form("px%d",i),groupnbins*i+1,groupnbins*(i+1));
1169 if(direction=="Y")h=(TH1F*)h2->ProjectionY(Form("py%d",i),groupnbins*i+1,groupnbins*(i+1));
1170 Double_t projint=h->Integral();
1171 cout<<"Integral of projection "<<i<<" = "<<projint<<endl;
1172 hint->SetBinContent(i+1,projint);
1173 hint->SetBinError(i+1,TMath::Sqrt(projint));
1174
1175 if(projint<1e-7) continue;
1176 if(minint>projint) minint=projint;
1177 if(projint>maxint) maxint=projint;
1fc8d3c0 1178 integralpernev[i]=h->Integral()/nevents;
ac0c2841 1179
1180 TPaveText *pvtxt=new TPaveText(0.6,0.6,0.9,0.9,"NDC");
1181 pvtxt->SetBorderSize(0);
1182 pvtxt->SetFillStyle(0);
2e7bd978 1183 pvtxt->AddText(Form("%.0f - %.0f",h2->GetYaxis()->GetBinLowEdge(groupnbins*i+1),h2->GetYaxis()->GetBinLowEdge(groupnbins*(i+1))));
1184 pvst->AddText(Form("%.0f - %.0f -> %.2f",h2->GetYaxis()->GetBinLowEdge(groupnbins*i+1),h2->GetYaxis()->GetBinLowEdge((groupnbins*(i+1))),integralpernev[i]));
1185
1ff03d38 1186 cvpj->cd(i+1);
2e7bd978 1187 //h->GetXaxis()->SetRangeUser(0,maxx[i]);
1ff03d38 1188 h->Draw();
ac0c2841 1189 pvtxt->Draw();
1ff03d38 1190 fout->cd();
1191 h->Write();
1192 }
0093a491 1193 cvpj->SaveAs(Form("cvpj%s%s.pdf",direction.Data(),h2dname.Data()));
1194 cvpj->SaveAs(Form("cvpj%s%s.eps",direction.Data(),h2dname.Data()));
1ff03d38 1195
1fc8d3c0 1196 cv2d->cd();
1197 pvst->Draw();
0093a491 1198 cv2d->SaveAs(Form("%s.pdf",h2->GetName()));
1199 cv2d->SaveAs(Form("%s.eps",h2->GetName()));
1200
2e7bd978 1201 cintegral->cd();
1202 hint->SetMarkerStyle(20);
1203 hint->Draw("PE");
1204 if(!fitfunc.Contains("nofit")){
1205 hint->Fit(fitfunc.Data(),"RL","PE",fitmin,fitmax);
1206 TF1* fpolfit=hint->GetFunction(fitfunc.Data());
1207 TPaveText *txtvar=new TPaveText(0.3,0.1,0.9,0.4,"NDC");
1208 txtvar->SetBorderSize(0);
1209 txtvar->SetFillStyle(0);
1210 //txtvar->AddText(Form("Full spread %.0f- %.0f",maxint,minint));
1211 txtvar->AddText(Form("Fit in %.1f-%.1f; ",fitmin,fitmax));
1212 for(Int_t ipar=0;ipar<fpolfit->GetNpar();ipar++){
1213 txtvar->AddText(Form("par%d = %.0f, ",ipar, fpolfit->GetParameter(ipar)));
1214 }
1215 txtvar->AddText(Form("#tilde{#chi}^{2} = %.2f",fpolfit->GetChisquare()/fpolfit->GetNDF()));
1216 txtvar->AddText(Form("bin width = %.1f %s",hint->GetBinWidth(3),"%"));
1217 txtvar->Draw();
1218 }
1219 fout->cd();
1220 hint->Write();
1221 cintegral->SaveAs(Form("%s.pdf",hint->GetName()));
1222 cintegral->SaveAs(Form("%s.eps",hint->GetName()));
0093a491 1223}
1224
9cadfad3 1225void DrawEventSelection(TString partname="D0", TString path="./",TString suffixdir="",TString filename="AnalysisResults.root"){
0093a491 1226 gStyle->SetCanvasColor(0);
1227 gStyle->SetTitleFillColor(0);
1228 gStyle->SetStatColor(0);
1229 gStyle->SetPalette(1);
1230 gStyle->SetOptStat(0);
1231
9cadfad3 1232 TString listname="outputEvSel";
1233 TString dirname="PWG3_D2H_QA";
1234 dirname+=suffixdir;
1fc8d3c0 1235
0093a491 1236 TList* list;
1237 TH1F * hstat;
1238
9cadfad3 1239 Bool_t isRead=ReadFile(list,hstat,listname,partname,path,filename,dirname);
0093a491 1240 if(!isRead) return;
1241 if(!list || !hstat){
1242 cout<<":-( null pointers..."<<endl;
1243 return;
1244 }
1245 //Double_t neventsgv=hstat->Integral(5,5); //ev good vertex
1246
1247 for(Int_t i=0;i<list->GetEntries();i++){
1248
1249 TClass* objtype=list->At(i)->IsA();
1250 TString tpname=objtype->GetName();
1251
1252 if(tpname=="TH1F"){
1253 TH1F* htmp=(TH1F*)list->At(i);
1254 TCanvas* c=new TCanvas(Form("c%s",htmp->GetName()),Form("c%s",htmp->GetName()));
1255 c->cd();
1256 htmp->Draw();
1257 c->SaveAs(Form("%s.pdf",htmp->GetName()));
1258 c->SaveAs(Form("%s.eps",htmp->GetName()));
1259 }
1260
1261 if(tpname=="TH2F"){
1262 TH2F* htmp=(TH2F*)list->At(i);
9cadfad3 1263 TCanvas* c=new TCanvas(Form("c%s",htmp->GetName()),Form("c%s",htmp->GetName()),1200,800);
0093a491 1264 c->cd();
1265 htmp->SetMarkerSize(1.3);
9cadfad3 1266 htmp->Draw("colzhtext45");
0093a491 1267 c->SaveAs(Form("%s.pdf",htmp->GetName()));
1268 c->SaveAs(Form("%s.eps",htmp->GetName()));
1269 }
1270 }
9cadfad3 1271
1272 AliCounterCollection* coll=(AliCounterCollection*)list->FindObject("trigCounter");
1273 if(!coll) {
1274 cout<<"Trigger counter not found"<<endl;
1275 return;
1276 }
1277
1278 coll->SortRubric("run");//sort by run number
1279
1280 TString collname=coll->GetName();
1281
1282 TString keywords=coll->GetKeyWords("triggertype");
1283
1284 Int_t nkeys=keywords.CountChar(',')+1;
1285
2e7bd978 1286 TString *words = new TString[nkeys];
9cadfad3 1287 for(Int_t k=0;k<nkeys;k++) words[k]="";
1288 printf("Keywords: ");
1289 Int_t count=0;
1290 for(Int_t l=0;l<keywords.Length();l++){
1291 if(keywords[l] != ',') words[count]+=keywords[l];
1292 else {
1293 printf("%s ",words[count].Data());
1294 count++;
1295 }
1296 }
1297 cout<<endl;
1298
1299 TH1D** htrig=new TH1D*[nkeys]; //each trigger type in one histogram of counts vs run
1300 TH1D** htrignorm=new TH1D*[nkeys]; //normalized to the counts in kAny
1301 TCanvas* ctrigfraction=new TCanvas("cvtrigfrac","Fraction of given trigger type vs run",1400,800);
1302 TLegend* legtr=new TLegend(0.15,0.5,0.35,0.8);
1303 legtr->SetBorderSize(0);
1304 legtr->SetFillStyle(0);
1305 for(Int_t k=0;k<nkeys;k++){
1306 htrig[k]=coll->Get("run",Form("triggertype:%s",words[k].Data()));
1307 htrig[k]->SetName(Form("h%s",words[k].Data()));
1308 htrig[k]->SetTitle("Trigger type;RUN; counts");
1309 htrig[k]->SetMarkerColor(k+1);
1310 htrig[k]->SetMarkerStyle(k+20);
1311 htrig[k]->Sumw2();
1312 legtr->AddEntry(htrig[k],Form("%s",words[k].Data()),"P");
1313 //drawings
1314 //1) counts of a given trigger over counts in kAny
1315 htrignorm[k]=(TH1D*)htrig[k]->Clone(Form("h%snormAny",words[k].Data()));
1316 htrignorm[k]->SetTitle("Trigger type over ANY trigger;RUN; counts/countsANY");
1317 htrignorm[k]->Divide(htrig[k],htrig[0],1.,1.,"B");
1318 htrignorm[k]->GetXaxis()->SetRangeUser(0,1.1);
1319
1320 ctrigfraction->cd();
1321 if(k>0)htrignorm[k]->Draw("PEsames");
1322 else htrignorm[k]->Draw("PE");
1323 }
1324
1325 ctrigfraction->cd();
1326 legtr->Draw();
1327 ctrigfraction->SaveAs("TrgFractionOverANY.pdf");
1328 ctrigfraction->SaveAs("TrgFractionOverANY.eps");
2e7bd978 1329
1330 delete [] words;
1331
1ff03d38 1332}