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