AliPhysics  v5-06-40-01 (42bb456)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
DrawQAoutput.C
Go to the documentation of this file.
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <Riostream.h>
3 #include <fstream>
4 #include <TFile.h>
5 #include <TString.h>
6 #include <TH2F.h>
7 #include <TH1F.h>
8 #include <TF1.h>
9 #include <TGraph.h>
10 #include <TDirectoryFile.h>
11 #include <TList.h>
12 #include <TCanvas.h>
13 #include <TLegend.h>
14 #include <TPaveText.h>
15 #include <TPaveStats.h>
16 #include <TStyle.h>
17 #include <TClass.h>
18 #include <TDatabasePDG.h>
19 #include <TParameter.h>
20 #include <AliCounterCollection.h>
21 #include <AliRDHFCuts.h>
22 
23 #include "MakePIDqaReport.C"
24 
25 #endif
26 
27 /* $Id$ */
28 
29 TString *periodsname;
30 
31 //read the file and take list and stat
32 
33 Bool_t ReadFile(TList* &list,TList* &hstat, TString listname,TString partname,TString path="./",TString filename=/*"AnalysisResults.root"*/"PWG3histograms.root", TString dirname="PWG3_D2H_QA");
34 Bool_t ReadFileMore(TList* &list,TList* &hstat, AliRDHFCuts* &cutobj, TString listname,TString partname,TString path="./",TString filename=/*"AnalysisResults.root"*/"PWG3histograms.root", TString dirname="PWG3_D2H_QA");
35 void SuperimposeBBToTPCSignal(Int_t period /*0=LHC10bc, 1=LHC10d, 2=LHC10h*/,TCanvas* cpid, Int_t set);
36 void TPCBetheBloch(Int_t set);
37 Bool_t ReadFilesForCompilation(TString inputtextfile, TList**& lists, Int_t&numb, TString*& legend);
38 void CompilationEvSelection(Int_t n,TList** lists, TString* legend);
39 void CompilationTrackSelection(Int_t n,TList** lists, TString* legend);
40 
41 Bool_t ReadFile(TList* &list,TList* &lstat, TString listname,TString partname,TString path,TString filename, TString dirname){
42 
43  TString lstatname="nEntriesQA", cutobjname="";
44  filename.Prepend(path);
45  listname+=partname;
46  lstatname+=partname;
47 
48  TFile* f=new TFile(filename.Data());
49  if(!f->IsOpen()){
50  cout<<filename.Data()<<" not found"<<endl;
51  return kFALSE;
52  }
53  TDirectoryFile* dir=(TDirectoryFile*)f->Get(dirname);
54  if(!dir){
55  cout<<dirname.Data()<<" not found in "<<filename.Data()<<endl;
56  f->ls();
57  return kFALSE;
58  }
59 
60  list=(TList*)dir->Get(listname);
61  if(!list){
62  cout<<"List "<<listname.Data()<<" not found"<<endl;
63  dir->ls();
64  return kFALSE;
65  }
66 
67  lstat=(TList*)dir->Get(lstatname);
68  if(!lstat){
69  cout<<lstatname.Data()<<" not found"<<endl;
70  return kFALSE;
71  }
72 
73  return kTRUE;
74 }
75 
76 Bool_t ReadFileMore(TList* &list,TList* &lstat, AliRDHFCuts* &cutobj, TString listname,TString partname,TString path,TString filename,TString dirname){
77 
78  TString lstatname="nEntriesQA", cutobjname="";
79  filename.Prepend(path);
80  listname+=partname;
81  lstatname+=partname;
82 
83  if(partname.Contains("Dplus")) cutobjname="AnalysisCuts";//"DplustoKpipiCutsStandard";
84  else{
85  if(partname.Contains("D0")) cutobjname="D0toKpiCutsStandard";//"D0toKpiCuts"
86  else{
87  if(partname.Contains("Dstar")) cutobjname="DStartoKpipiCuts";
88  else{
89  if(partname.Contains("Ds")) cutobjname="DstoKKpiCuts";
90  else{
91  if(partname.Contains("D04")) cutobjname="D0toKpipipiCuts";
92  else{
93  if(partname.Contains("Lc")) cutobjname="LctopKpiAnalysisCuts";
94  }
95  }
96  }
97  }
98  }
99 
100  TFile* f=new TFile(filename.Data());
101  if(!f->IsOpen()){
102  cout<<filename.Data()<<" not found"<<endl;
103  return kFALSE;
104  }
105  TDirectoryFile* dir=(TDirectoryFile*)f->Get(dirname);
106  if(!dir){
107  cout<<dirname.Data()<<" not found in "<<filename.Data()<<endl;
108  return kFALSE;
109  }
110 
111  list=(TList*)dir->Get(listname);
112  if(!list){
113  cout<<"List "<<listname.Data()<<" not found"<<endl;
114  dir->ls();
115  return kFALSE;
116  }
117 
118  lstat=(TList*)dir->Get(lstatname);
119  if(!lstat){
120  cout<<lstatname.Data()<<" not found"<<endl;
121  return kFALSE;
122  }
123 
124  cutobj=(AliRDHFCuts*)dir->Get(cutobjname);
125  if(!cutobj){
126  cout<<cutobjname.Data()<<" not found"<<endl;
127  return kFALSE;
128  }
129 
130  return kTRUE;
131 }
132 
133 //draw "track related" histograms (list "outputTrack")
134 void DrawOutputTrack(TString partname="D00100",TString textleg="",TString path="./", Bool_t superimpose=kFALSE, TString suffixdir="",TString filename="AnalysisResults.root", Bool_t normint=kTRUE /*normalize at integral, or at nevents*/){
135  gStyle->SetCanvasColor(0);
136  gStyle->SetTitleFillColor(0);
137  gStyle->SetStatColor(0);
138  gStyle->SetPalette(1);
139 
140  TString listname="outputTrack",name1="",name2="",path2="",filename2="PWG3histograms.root",legtext1="",legtext2="",suffixdir2="";
141  TString tmp="y";
142  name1=suffixdir;
143 
144  if(superimpose){
145  cout<<"Enter the names:\n>";
146  cin>>name1;
147  cout<<">";
148  cin>>name2;
149  cout<<"Are they in the same output file? (y/n)"<<endl;
150  cin>>tmp;
151  if(tmp=="n"){
152  cout<<"Path: \n";
153  cout<<">";
154  cin>>path2;
155  cout<<"Filename: "<<endl;
156  cout<<">";
157  cin>>filename2;
158  cout<<"Suffix in the dir name, if any (otherwhise write no)\n>";
159  cin>>suffixdir2;
160  if(suffixdir2=="no") suffixdir2="";
161  cout<<"Text in the legend:\n 1)";
162  cin>>legtext1;
163  cout<<"2)";
164  cin>>legtext2;
165  }
166 
167  }
168 
169  Float_t nevents=0,nevents2=0;
170  TList* list = NULL;
171  TList * lstat = NULL;
172  TH1F * hEntr = NULL;
173  TH1F* hHasFilterBit = NULL;
174 
175  TString dirname="PWG3_D2H_QA";
176  // dirname+=suffixdir;
177  Bool_t isRead=ReadFile(list,lstat,listname,Form("%s%s",partname.Data(),name1.Data()),path,filename,Form("%s%s",dirname.Data(),suffixdir.Data()));
178  if(!isRead) return;
179  if(!list || !lstat){
180  cout<<":-( null pointers..."<<endl;
181  return;
182  }
183  hEntr = (TH1F*) lstat->FindObject("hNentries");
184  hHasFilterBit = (TH1F*) lstat->FindObject("HasSelBit");
185 
186  nevents=hEntr->GetBinContent(1);
187  TPaveText *pvtxt=new TPaveText(0.6,0.6,0.9,0.9,"NDC");
188  pvtxt->SetBorderSize(0);
189  pvtxt->SetFillStyle(0);
190  pvtxt->AddText(legtext1);
191 
192  TList* llist = NULL;
193  TList* llstat = NULL;
194  TH1F* hEntr1 = NULL;
195  TH1F* hHasFilterBit1 = NULL;
196 
197  if(superimpose){
198  isRead=ReadFile(llist,llstat,listname,Form("%s%s",partname.Data(),name2.Data()),path2,filename2,Form("%s%s",dirname.Data(),suffixdir2.Data()));
199  if(!isRead) return;
200  if(!llist || !llstat){
201  cout<<":-( null pointers..."<<endl;
202  return;
203  }
204  hEntr1 = (TH1F*) llstat->FindObject("hNentries");
205  hHasFilterBit1 = (TH1F*) llstat->FindObject("HasSelBit");
206 
207  nevents2=hEntr1->GetBinContent(1);
208  TText *redtext=pvtxt->AddText(legtext2);
209  redtext->SetTextColor(kRed);
210  hEntr1->Scale(hEntr->Integral()/hEntr1->Integral());
211  hHasFilterBit1->Scale(hEntr->Integral()/hEntr1->Integral());
212  }
213 
214  for(Int_t i=0;i<list->GetEntries();i++){
215  TH1F* h=(TH1F*)list->At(i);
216  TH1F* hh=0x0;
217  TH1F* hr=0x0;
218  if(superimpose){
219  hh=(TH1F*)llist->At(i);
220  hr=(TH1F*)hh->Clone(Form("%s_ratio",hh->GetName()));
221  if(hh && TMath::Abs(hh->Integral()) > 1e-6)hh->Scale(h->Integral()/hh->Integral());
222  }
223  if(!h || (superimpose && !hh)){
224  cout<<"Histogram "<<i<<" not found"<<endl;
225  continue;
226  }
227  if(superimpose){
228  if(normint) hh->Scale(h->Integral()/hh->Integral());
229  else hh->Scale(nevents/nevents2);
230  hEntr1->SetLineColor(kRed);
231  hh->SetLineColor(kRed);
232  hr->Divide(h);
233  }
234 
235  TCanvas* c=new TCanvas(Form("c%s",h->GetName()),h->GetName());
236  c->cd();
237  c->SetGrid();
238  TString hname=h->GetName();
239  if(!hname.Contains("nCls")){
240  c->SetLogy();
241  if(hname.Contains("Layer")){
242  for(Int_t ibin=1;ibin<=h->GetNbinsX();ibin++){
243  h->GetXaxis()->SetBinLabel(ibin+1,Form("%d",ibin));
244  }
245  h->GetXaxis()->SetLabelSize(0.06);
246  h->GetXaxis()->SetRangeUser(0,6); //comment to see ntracks!
247  }
248  //h->SetMinimum(1);
249  if(hname.Contains("vs")||hname.Contains("dauphi")|| hname.Contains("dauphi_filt")){
250  h->Draw("colz");
251  }else h->Draw();
252 
253  if(superimpose)
254  {
255  hh->Draw("sames");
256  TCanvas* c2=new TCanvas(Form("c2%s",h->GetName()),h->GetName());
257  c2->cd();
258  c2->SetGrid();
259  hr->Draw();
260  c2->SaveAs(Form("%s%s%s%sRatio.png",c->GetName(),name1.Data(),name2.Data(),textleg.Data()));
261 
262  }
263  } else {
264  h->Draw("htext0");
265  if(superimpose)hh->Draw("htext0sames");
266  }
267  c->cd();
268  pvtxt->Draw();
269  c->SaveAs(Form("%s%s%s%s.png",c->GetName(),name1.Data(),name2.Data(),textleg.Data()));
270  c->SaveAs(Form("%s%s%s%s.eps",c->GetName(),name1.Data(),name2.Data(),textleg.Data()));
271  }
272 
273 
274  TCanvas* cstFilter=new TCanvas("cstFilter","Stat_HasFilterBit");
275  cstFilter->SetGridy();
276  cstFilter->cd();
277  hHasFilterBit->Draw("htext0");
278 
279  if(superimpose) {
280  hHasFilterBit1->Draw("htext0sames");
281  pvtxt->Draw();
282  }
283  cstFilter->SaveAs(Form("%s%s.png",hHasFilterBit->GetName(),textleg.Data()));
284  cstFilter->SaveAs(Form("%s%s.eps",hHasFilterBit->GetName(),textleg.Data()));
285 
286 
287 
288  TCanvas* cst=new TCanvas("cst","Stat");
289  cst->SetGridy();
290  cst->cd();
291  hEntr->Draw("htext0");
292 
293  if(superimpose) {
294  hEntr1->Draw("htext0sames");
295  pvtxt->Draw();
296  }
297  cst->SaveAs(Form("%s%s.png",hEntr->GetName(),textleg.Data()));
298  cst->SaveAs(Form("%s%s.eps",hEntr->GetName(),textleg.Data()));
299 
300  TH1F* hd0fb4=(TH1F*)list->FindObject("hd0TracksFilterBit4");
301  TH1F* hd0SPD1=(TH1F*)list->FindObject("hd0TracksSPDin");
302  TH1F* hd0SPDany=(TH1F*)list->FindObject("hd0TracksSPDany");
303  TH1F* hd0TPCITScuts=(TH1F*)list->FindObject("hd0TracksTPCITSSPDany");
304  TH1F* hhd0fb4=0x0; TH1F* hhd0SPD1=0x0; TH1F* hhd0SPDany=0x0; TH1F* hhd0TPCITScuts=0x0;
305  if(superimpose){
306  hhd0fb4=(TH1F*)llist->FindObject("hd0TracksFilterBit4");
307  hhd0SPD1=(TH1F*)llist->FindObject("hd0TracksSPDin");
308  hhd0SPDany=(TH1F*)llist->FindObject("hd0TracksSPDany");
309  hhd0TPCITScuts=(TH1F*)llist->FindObject("hd0TracksTPCITSSPDany");
310 
311  }
312  if(hd0fb4 && hd0SPD1 && hd0SPDany && hd0TPCITScuts){
313  TCanvas* ctrsel=new TCanvas("ctrsel","Track Sel");
314  ctrsel->SetLogy();
315  hd0SPD1->SetLineColor(kCyan+3);
316  hd0SPD1->Draw();
317  ctrsel->Update();
318  TPaveStats *st1=(TPaveStats*)hd0SPD1->GetListOfFunctions()->FindObject("stats");
319  st1->SetTextColor(kCyan+3);
320  st1->SetY1NDC(0.71);
321  st1->SetY2NDC(0.9);
322  hd0SPDany->SetLineColor(4);
323  hd0SPDany->Draw("sames");
324  ctrsel->Update();
325  TPaveStats *st2=(TPaveStats*)hd0SPDany->GetListOfFunctions()->FindObject("stats");
326  st2->SetY1NDC(0.51);
327  st2->SetY2NDC(0.7);
328  st2->SetTextColor(4);
329  hd0fb4->SetLineColor(2);
330  hd0fb4->Draw("sames");
331  ctrsel->Update();
332  TPaveStats *st3=(TPaveStats*)hd0fb4->GetListOfFunctions()->FindObject("stats");
333  st3->SetY1NDC(0.31);
334  st3->SetY2NDC(0.5);
335  st3->SetTextColor(2);
336  hd0TPCITScuts->SetLineColor(kGreen+1);
337  hd0TPCITScuts->Draw("sames");
338  ctrsel->Update();
339  TPaveStats *st4=(TPaveStats*)hd0TPCITScuts->GetListOfFunctions()->FindObject("stats");
340  st4->SetY1NDC(0.71);
341  st4->SetY2NDC(0.9);
342  st4->SetX1NDC(0.55);
343  st4->SetX2NDC(0.75);
344  st4->SetTextColor(kGreen+1);
345  ctrsel->Modified();
346  TLegend* leg=new TLegend(0.15,0.5,0.45,0.78);
347  leg->SetFillStyle(0);
348  leg->SetBorderSize(0);
349  leg->AddEntry(hd0SPD1,"kITSrefit+SPD inner","L");
350  leg->AddEntry(hd0SPDany,"kITSrefit+SPD any","L");
351  leg->AddEntry(hd0TPCITScuts,"TPC+ITS cuts+SPD any","L");
352  leg->AddEntry(hd0fb4,"Filter Bit 4","L");
353  leg->Draw();
354 
355  if(superimpose && hhd0fb4 && hhd0SPD1 && hhd0SPDany && hhd0TPCITScuts){
356  hhd0SPD1->SetLineColor(kCyan+3);
357  hhd0SPD1->SetStats(0);
358  hhd0SPD1->SetLineStyle(3);
359  hhd0SPDany->SetLineColor(4);
360  hhd0SPDany->SetStats(0);
361  hhd0SPDany->SetLineStyle(3);
362  hhd0TPCITScuts->SetLineColor(kGreen+1);
363  hhd0TPCITScuts->SetStats(0);
364  hhd0TPCITScuts->SetLineStyle(3);
365  hhd0fb4->SetLineColor(2);
366  hhd0fb4->SetStats(0);
367  hhd0fb4->SetLineStyle(3);
368  ctrsel->cd();
369  hhd0SPD1->Draw("sames");
370  hhd0SPDany->Draw("sames");
371  hhd0TPCITScuts->Draw("sames");
372  hhd0fb4->Draw("sames");
373 
374  }
375  ctrsel->SaveAs("ImpactParameterTrackSel.eps");
376  ctrsel->SaveAs("ImpactParameterTrackSel.png");
377 
378  }
379 }
380 
381 //draw "pid related" histograms (list "outputPID")
382 //period=-999 to draw the pull instead of the cut
383 void DrawOutputPID(TString partname="D00100", Int_t mode=0/*0=with pull, 1=with nsigma*/,TString textleg="",TString path="./",TString suffixdir="", TString filename="AnalysisResults.root"){
384  gStyle->SetCanvasColor(0);
385  gStyle->SetTitleFillColor(0);
386  gStyle->SetOptStat(0);
387  gStyle->SetPalette(1);
388 
389  Int_t period=2 ,set=0;
390  if(mode==1){
391  cout<<"Choose period: \n-LHC10h -> 2;\n-LHC10de -> 1;\n-LHC10bc -> 0"<<endl;
392  cin>>period;
393  if(period>0){
394  cout<<"Choose set: "<<endl;
395  if(period==2) cout<<"-pass1 -> 0;\n-pass2 -> 1"<<endl;
396  cin>>set;
397  }
398  }
399 
400  TString listname="outputPid";
401  TString dirname="PWG3_D2H_QA";
402  dirname+=suffixdir;
403 
404  TList* list = NULL;
405  TList * lstat = NULL;
406  //needed only for mode 1
407  AliRDHFCuts* cutobj;
408  AliAODPidHF* aodpid;
409  Double_t nsigmaTOF=0;
410  Double_t nsigmaTPC[3]={},plimTPC[2]={};
411 
412  if(mode==1){
413  Bool_t isRead=ReadFileMore(list,lstat,cutobj,listname,partname+suffixdir,path,filename,dirname);
414  if(!isRead) return;
415  if(!list || !lstat){
416  cout<<":-( null pointers..."<<endl;
417  return;
418  }
419  aodpid=(AliAODPidHF*)cutobj->GetPidHF();
420  if(!aodpid){
421  cout<<"PidHF object not found! cannot get the nsigma values"<<endl;
422  return;
423  }
424  nsigmaTOF=aodpid->GetSigma(3);
425 
426  nsigmaTPC[0]=aodpid->GetSigma(0);
427  nsigmaTPC[1]=aodpid->GetSigma(1);
428  nsigmaTPC[2]=aodpid->GetSigma(2);
429  aodpid->GetPLimit(plimTPC);
430 
431  }else{
432  Bool_t isRead=ReadFile(list,lstat,listname,partname+suffixdir,path,filename,dirname);
433  if(!isRead) return;
434  if(!list || !lstat){
435  cout<<":-( null pointers..."<<endl;
436  return;
437  }
438  }
439 
440 
441  TPaveText *txtsigmaTOF=new TPaveText(0.1,0.65,0.5,0.9,"NDC");
442  txtsigmaTOF->SetBorderSize(0);
443  txtsigmaTOF->SetFillStyle(0);
444  txtsigmaTOF->AddText(Form("nsigmacut from cutobj = %.1f",nsigmaTOF));
445  TLine lTOF;
446  lTOF.SetLineColor(kMagenta+1);
447  lTOF.SetLineStyle(2);
448  lTOF.SetLineWidth(3);
449 
450  TPaveText *txtsigmaTPC=new TPaveText(0.3,0.6,0.6,0.9,"NDC");
451  txtsigmaTPC->SetBorderSize(0);
452  txtsigmaTPC->SetFillStyle(0);
453  txtsigmaTPC->AddText("nsigmacut from cutobj \n");
454  txtsigmaTPC->AddText(Form("p < %.1f : %.1f \n",plimTPC[0],nsigmaTPC[0]));
455  txtsigmaTPC->AddText(Form("%.1f < p < %.1f : %.1f \n",plimTPC[0],plimTPC[1],nsigmaTPC[1]));
456  txtsigmaTPC->AddText(Form("p > %.1f : %.1f \n",plimTPC[1],nsigmaTPC[2]));
457  TLine lTPC;
458  lTPC.SetLineColor(kMagenta+1);
459  lTPC.SetLineStyle(2);
460  lTPC.SetLineWidth(3);
461 
462  // TCanvas *ctest=new TCanvas("text","Test text");
463  // ctest->cd();
464  // txtsigmaTPC->Draw();
465  // txtsigmaTOF->Draw();
466 
467 
468  for(Int_t i=0;i<list->GetEntries();i++){
469  TClass* objtype=list->At(i)->IsA();
470  TString tpname=objtype->GetName();
471 
472  if(tpname=="TH1F"){
473  TH1F* h=(TH1F*)list->At(i);
474 
475  if(!h){
476  cout<<"Histogram "<<i<<" not found"<<endl;
477  continue;
478  }
479  //h->Scale(1./h->Integral("width"));
480  TCanvas* c=new TCanvas(Form("c%s",h->GetName()),h->GetName());
481  c->SetLogz();
482  c->cd();
483  h->Draw();
484 
485  //write
486  c->SaveAs(Form("%s%s.png",h->GetName(),textleg.Data()));
487  c->SaveAs(Form("%s%s.eps",h->GetName(),textleg.Data()));
488  TFile* fout=new TFile(Form("%s.root",h->GetName()),"recreate");
489  fout->cd();
490  c->Write();
491  }
492 
493  if(tpname=="TH2F"){
494  TH2F* h=(TH2F*)list->At(i);
495 
496  if(!h){
497  cout<<"Histogram "<<i<<" not found"<<endl;
498  continue;
499  }
500  TString hname=h->GetName();
501  h->Sumw2();
502  if(h->Integral("width")==0) {cout<<"Empty histogram, skip\n"; continue;}
503  h->Scale(1./h->Integral("width"));
504 
505  Double_t maxzaxis=h->GetBinContent(h->GetMaximumBin());
506  Double_t minzaxis=h->GetBinContent(h->GetMinimumBin());
507  printf("Minimum = %f, maximum = %f\n",minzaxis,maxzaxis);
508  TH2F* hallzrange=(TH2F*)h->Clone(Form("%swholez",hname.Data()));
509  hallzrange->SetAxisRange(1e-07,maxzaxis,"Z");
510  //hallzrange->SetAxisRange(minzaxis,maxzaxis,"Z");
511 
512  TCanvas* cwholez=new TCanvas(Form("c%swholez",hname.Data()),Form("%s down to lowest z",hname.Data()));
513  cwholez->SetLogz();
514  hallzrange->Draw("colz");
515  cwholez->SaveAs(Form("%swholez.png",h->GetName()));
516  cwholez->SaveAs(Form("%swholez.eps",h->GetName()));
517 
518  if(hname.Contains("hTOFtimeKaonHyptime")){
519  TCanvas* cz=new TCanvas(Form("c%szoom",hname.Data()),Form("%szoom",hname.Data()));
520  cz->SetLogz();
521  TH2F* hz=(TH2F*)h->Clone(Form("%sz",hname.Data()));
522  hz->Draw("colz");
523  hz->SetAxisRange(-1500,1500,"Y");
524  hz->SetAxisRange(0.,5.,"X");
525  //write
526  cz->SaveAs(Form("%szoom.png",h->GetName()));
527  cz->SaveAs(Form("%szoom.eps",h->GetName()));
528  }
529 
530  TCanvas* c=new TCanvas(Form("c%s",hname.Data()),hname.Data());
531  c->SetLogz();
532  //c->SetLogx();
533  TCanvas* c2=new TCanvas(Form("c2%s",hname.Data()),hname.Data());
534  c2->SetLogz();
535 
536  c->cd();
537  h->DrawClone("colz");
538 
539  if (hname.Contains("Sig") || hname.Contains("sigma"))h->SetAxisRange(-5,5,"Y");
540  c2->cd();
541  //if (hname.Contains("TOFtime"))h->SetAxisRange(-1500,1500,"Y");
542  h->SetAxisRange(0.,5.,"X");
543 
544  h->Draw("colz");
545 
546  //TCanvas *test=new TCanvas("test","test");
547  if(mode==0){
548  AddFit(h);
549  }else{ //mode 1
550 
551  if(hname.Contains("TOFsigma")) {
552 
553  c->cd();
554  txtsigmaTOF->Draw();
555  lTOF.DrawLine(.2,nsigmaTOF,20,nsigmaTOF);
556  lTOF.DrawLine(.2,-1*nsigmaTOF,4.,-1*nsigmaTOF);
557 
558  }
559 
560 
561  if(hname.Contains("TPCsigma")){
562 
563  c->cd();
564  txtsigmaTPC->Draw();
565  lTPC.DrawLine(0.,nsigmaTPC[0],plimTPC[0],nsigmaTPC[0]);
566  lTPC.DrawLine(plimTPC[0],nsigmaTPC[1],plimTPC[1],nsigmaTPC[1]);
567  lTPC.DrawLine(plimTPC[1],nsigmaTPC[2],4,nsigmaTPC[2]);
568  lTPC.DrawLine(0.,-1*nsigmaTPC[0],plimTPC[0],-1*nsigmaTPC[0]);
569  lTPC.DrawLine(plimTPC[0],-1*nsigmaTPC[1],plimTPC[1],-1*nsigmaTPC[1]);
570  lTPC.DrawLine(plimTPC[1],-1*nsigmaTPC[2],4,-1*nsigmaTPC[2]);
571  }
572 
573  if(hname.Contains("TPCsigvsp")){
574  SuperimposeBBToTPCSignal(period,c,set);
575  }
576  }
577 
578  //write
579  c->SaveAs(Form("%s%d.png",h->GetName(),mode));
580  c->SaveAs(Form("%s%d.eps",h->GetName(),mode));
581  c2->SaveAs(Form("%s2%d.png",h->GetName(),mode));
582  c2->SaveAs(Form("%s2%d.eps",h->GetName(),mode));
583 
584  TFile* fout=new TFile(Form("%s%d.root",h->GetName(),mode),"recreate");
585  fout->cd();
586  c->Write();
587  c2->Write();
588  }
589  }
590 }
591 
592 void SuperimposeBBToTPCSignal(Int_t period /*0=LHC10bc, 1=LHC10d, 2=LHC10h*/,TCanvas* cpid,Int_t set /*see below*/){
593 
594  TFile* fBethe=new TFile("BetheBlochTPC.root");
595  if(!fBethe->IsOpen()){
596  TPCBetheBloch(set);
597  fBethe=new TFile("BetheBlochTPC.root");
598  }
599  const Int_t npart=4;
600  TString partnames[npart]={"Kaon","Pion","Electron","Proton"};
601  for(Int_t ipart=0;ipart<npart;ipart++){
602  TString grname=Form("%sP%d",partnames[ipart].Data(),period);
603  TGraph* gr=(TGraph*)fBethe->Get(grname);
604  cpid->cd();
605  gr->SetLineColor(1);
606  gr->SetLineWidth(2);
607  gr->Draw("L");
608  }
609 
610  //cpid->SaveAs(Form("%sBB.png",hname.Data()));
611 }
612 
613 //draw and save Bethe Bloch from TPC in different periods
614 void TPCBetheBloch(Int_t set){
615  gStyle->SetOptTitle(0);
616  gStyle->SetCanvasColor(0);
617 
618  AliTPCPIDResponse *tpcResp=new AliTPCPIDResponse();
619 
620  const Int_t npart=4;
621  //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*/};
622  TString partnames[npart]={"Kaon","Pion","Electron","Proton"};
623  //printf("%s = %.4f,%s = %.4f,%s = %.4f\n",partnames[0].Data(),masses[0],partnames[1].Data(),masses[1],partnames[2].Data(),masses[2]);
624  TCanvas *cBethe=new TCanvas("cBethe","Bethe Bloch K pi e p");
625  Int_t nperiods=4; //LHC10b+c, LHC10d, LHC10h, MC
626  Double_t alephParameters[5]={};
627  Int_t nsets=1/*LHC10bc*/+2/*LHC10de*/+2/*LHC10h*/+3/*MC*/;
628 
629  periodsname=new TString[nsets];
630  cout<<"Creating the file of the Bethe Bloch"<<endl;
631  TFile* fout=new TFile("BetheBlochTPC.root","recreate");
632 
633  for(Int_t iperiod=0;iperiod<nperiods;iperiod++){
634  cout<<"Period "<<iperiod<<" : ";
635  if(iperiod==0){ //LHC10bc
636 
637  alephParameters[0] = 0.0283086/0.97;
638  alephParameters[1] = 2.63394e+01;
639  alephParameters[2] = 5.04114e-11;
640  alephParameters[3] = 2.12543e+00;
641  alephParameters[4] = 4.88663e+00;
642  periodsname[0]="dataLHC10bc";
643  }
644  if(iperiod==1){ //LHC10de,low energy
645  if(set==0){
646  alephParameters[0] = 1.63246/50.;
647  alephParameters[1] = 2.20028e+01;
648  alephParameters[2] = TMath::Exp(-2.48879e+01);
649  alephParameters[3] = 2.39804e+00;
650  alephParameters[4] = 5.12090e+00;
651  periodsname[1]="dataLHC10deold";
652  }
653  if(set==1){
654  alephParameters[0] = 1.34490e+00/50.;
655  alephParameters[1] = 2.69455e+01;
656  alephParameters[2] = TMath::Exp(-2.97552e+01);
657  alephParameters[3] = 2.35339e+00;
658  alephParameters[4] = 5.98079e+00;
659  periodsname[2]="dataLHC10denew";
660  }
661  }
662 
663  if(iperiod==2){//LHC10h
664  if(set==0){//pass1
665  alephParameters[0]=1.25202/50.;
666  alephParameters[1]=2.74992e+01;
667  alephParameters[2]=TMath::Exp(-3.31517e+01);
668  alephParameters[3]=2.46246;
669  alephParameters[4]=6.78938;
670  periodsname[3]="dataLHC10hpass1";
671  }
672  if (set==1){//pass2 (AOD044)
673  alephParameters[0]=1.25202/50.;
674  alephParameters[1]=2.74992e+01;
675  alephParameters[2]=TMath::Exp(-3.31517e+01);
676  alephParameters[3]=2.46246;
677  alephParameters[4]=6.78938;
678  periodsname[4]="dataLHC10hpass2";
679  }
680  }
681  if(iperiod==3){ //MC
682  if(set==0){
683  alephParameters[0] = 2.15898e+00/50.;
684  alephParameters[1] = 1.75295e+01;
685  alephParameters[2] = 3.40030e-09;
686  alephParameters[3] = 1.96178e+00;
687  alephParameters[4] = 3.91720e+00;
688  periodsname[5]="MCold";
689  }
690  if(set==1){ //new
691  alephParameters[0] = 1.44405/50;
692  alephParameters[1] = 2.35409e+01;
693  alephParameters[2] = TMath::Exp(-2.90330e+01);
694  alephParameters[3] = 2.10681;
695  alephParameters[4] = 4.62254;
696  periodsname[6]="MCnew";
697  }
698 
699  if(set==2){ //new BB from Francesco
700  alephParameters[0] = 0.029021;
701  alephParameters[1] = 25.4181;
702  alephParameters[2] = 4.66596e-08;
703  alephParameters[3] = 1.90008;
704  alephParameters[4] = 4.63783;
705  periodsname[7]="MCBBFrancesco";
706  }
707 
708  if(set==3){ //low energy 2011
709  alephParameters[0] = 0.0207667;
710  alephParameters[1] = 29.9936;
711  alephParameters[2] = 3.87866e-11;
712  alephParameters[3] = 2.17291;
713  alephParameters[4] = 7.1623;
714  //periodsname[8]="MClowen2011";
715  }
716 
717 
718  }
719  //cout<<periodsname[iperiod]<<endl;
720  tpcResp->SetBetheBlochParameters(alephParameters[0],alephParameters[1],alephParameters[2],alephParameters[3],alephParameters[4]);
721  cout<<"here"<<endl;
722  for(Int_t ipart=0;ipart<npart;ipart++){
723 
724  const Int_t n=1000;
725  Double_t p[n],bethe[n];
726 
727  for(Int_t k=0;k<n;k++){ //loop on the momentum steps
728  p[k]=0.0001+k*4./n; //limits 0.-4. GeV/c
729  //cout<<p[k]<<"\t";
730  //bethe[k]=-tpcResp->Bethe(p[k]/masses[ipart]);
731  AliPID::EParticleType ptype=AliPID::kKaon;
732  if(ipart==1) ptype=AliPID::kPion;
733  if(ipart==2) ptype=AliPID::kElectron;
734  if(ipart==3) ptype=AliPID::kProton;
735  bethe[k]=tpcResp->GetExpectedSignal(p[k],ptype);
736  }
737  //cout<<endl;
738  TGraph *gr=new TGraph(n,p,bethe);
739  gr->SetName(Form("%sP%d",partnames[ipart].Data(),iperiod));
740  gr->SetTitle(Form("%sP%d;p (GeV/c);",partnames[ipart].Data(),iperiod));
741  gr->SetLineColor(ipart+1);
742  gr->SetMarkerColor(ipart+1);
743  gr->GetYaxis()->SetRangeUser(35,100);
744  cBethe->cd();
745  if(iperiod==0 && ipart==0)gr->DrawClone("AL");
746  else gr->DrawClone("L");
747 
748  fout->cd();
749  gr->Write();
750  }
751 
752  }
753  TParameter<int> sett;
754  sett.SetVal(set);
755  fout->cd();
756  sett.Write();
757 
758  fout->Close();
759 }
760 
761 void DrawOutputCentrality(TString partname="D0",TString textleg="",TString path="./", Bool_t superimpose=kFALSE,TString suffixdir="",TString filename=/*"AnalysisResults.root"*/"PWG3histograms.root"){
762  gStyle->SetCanvasColor(0);
763  gStyle->SetTitleFillColor(0);
764  gStyle->SetStatColor(0);
765  gStyle->SetPalette(1);
766 
767  TString listname="outputCentrCheck",partname2="",path2="",suffixdir2="",filename2="PWG3histograms.root";
768 
769  // if(superimpose){
770  // cout<<"Enter the names:\n>";
771  // cin>>name1;
772  // cout<<">";
773  // cin>>name2;
774  // }
775  // TString listname="outputTrack",name1="",name2="";
776  TString tmp="y";
777 
778  if(superimpose){
779  cout<<"##Second file\n";
780  cout<<"Enter the name:\n";
781  cout<<">";
782  cin>>partname2;
783  cout<<"Are they in the same output file? (y/n)"<<endl;
784  cin>>tmp;
785  if(tmp=="n"){
786  cout<<"Path: \n";
787  cout<<">";
788  cin>>path2;
789  cout<<"Dir name:\n";
790  cout<<">";
791  cin>>suffixdir2;
792  cout<<"Filename: "<<endl;
793  cout<<">";
794  cin>>filename2;
795  }
796 
797  }
798  // Int_t nhist=1;
799  // TString *name=0x0;
800  // if(superimpose){
801  // cout<<"Number of histogram to superimpose: ";
802  // cin>>nhist;
803  // name=new TString[nhist];
804  // for (Int_t j=0;j<nhist;j++){
805  // cout<<">";
806  // cin>>name[j];
807  // }
808  // }
809 
810  TList* list = NULL;
811  TList * lstat = NULL;
812  TH1F* hEntr = NULL;
813 
814  TString dirname="PWG3_D2H_QA",dirname2=dirname;
815  dirname+=suffixdir;
816  dirname2+=suffixdir2;
817  Bool_t isRead=ReadFile(list,lstat,listname,partname.Data(),path,filename,dirname);
818  if(!isRead) return;
819  if(!list || !lstat){
820  cout<<":-( null pointers..."<<endl;
821  return;
822  }
823 
824  TPaveText *pvtxt=new TPaveText(0.6,0.6,0.9,0.9,"NDC");
825  pvtxt->SetBorderSize(0);
826  pvtxt->SetFillStyle(0);
827  pvtxt->AddText(partname);
828 
829  TList* llist = NULL;
830  TList* llstat = NULL;
831  TH1F* hEntr1 = NULL;
832 
833  if(superimpose){
834  isRead=ReadFile(llist,llstat,listname,partname2.Data(),path2,filename2,dirname2);
835  if(!isRead) return;
836  if(!llist || !llstat){
837  cout<<":-( null pointers..."<<endl;
838  return;
839  }
840  TText *redtext=pvtxt->AddText(partname2);
841  redtext->SetTextColor(kRed);
842 
843  }
844 
845 
846  TCanvas* cst=new TCanvas("cst","Stat");
847  cst->SetGridy();
848  cst->cd();
849  hEntr=(TH1F*)lstat->FindObject("hNentries");
850  hEntr1=(TH1F*)llstat->FindObject("hNentries");
851  Int_t nevents=hEntr->GetBinContent(1);
852  hEntr->Draw("htext0");
853  cst->SaveAs(Form("%s%s.png",hEntr->GetName(),textleg.Data()));
854  cst->SaveAs(Form("%s%s.eps",hEntr->GetName(),textleg.Data()));
855  Int_t nevents080=1,nnevents080=1;
856 
857  //TCanvas *spare=new TCanvas("sparecv","Spare");
858 
859  for(Int_t i=0;i<list->GetEntries();i++){
860 
861  TClass* objtype=list->At(i)->IsA();
862  TString tpname=objtype->GetName();
863 
864  if(tpname=="TH1F"){
865 
866  TH1F* h=(TH1F*)list->At(i);
867  TH1F* hh=0x0;
868  if(superimpose){
869  hh=(TH1F*)llist->At(i);
870  }
871  if(!h || (superimpose && !hh)){
872  cout<<"Histogram "<<i<<" not found"<<endl;
873  continue;
874  }
875  if(superimpose){
876  hEntr1->SetLineColor(kRed);
877  hh->SetLineColor(kRed);
878  }
879 
880  TCanvas* c=new TCanvas(Form("c%s",h->GetName()),h->GetName());
881  TPaveText *pvtxt2=new TPaveText(0.6,0.6,0.9,0.9,"NDC");
882  pvtxt2->SetBorderSize(0);
883  pvtxt2->SetFillStyle(0);
884 
885  c->cd();
886  c->SetGrid();
887  c->SetLogy();
888  Int_t entries=h->Integral();
889  pvtxt2->AddText(Form("%.1f %s of the events",(Double_t)entries/(Double_t)nevents*100,"%"));
890  h->Draw();
891  if(superimpose) {
892  hh->Draw("sames");
893  pvtxt->Draw();
894  }
895  pvtxt2->Draw();
896  c->SaveAs(Form("%s%s.pdf",c->GetName(),textleg.Data()));
897  c->SaveAs(Form("%s%s.eps",c->GetName(),textleg.Data()));
898  }
899  if(tpname=="TH2F"){
900  TH2F* hhh=(TH2F*)list->At(i);
901  if(!hhh){
902  cout<<"Histogram "<<i<<" not found"<<endl;
903  continue;
904  }
905  TCanvas* c=new TCanvas(Form("c%s",hhh->GetName()),hhh->GetName());
906  TPaveText *pvtxt3=new TPaveText(0.6,0.6,0.9,0.9,"NDC");
907  pvtxt3->SetBorderSize(0);
908  pvtxt3->SetFillStyle(0);
909 
910  c->cd();
911  c->SetGrid();
912  Int_t entries=hhh->Integral();
913  pvtxt3->AddText(Form("%.1f %s of the events",(Double_t)entries/(Double_t)nevents*100,"%"));
914  hhh->Draw("colz");
915  c->SetLogz();
916  pvtxt3->Draw();
917  c->SaveAs(Form("%s%s.pdf",c->GetName(),textleg.Data()));
918  c->SaveAs(Form("%s%s.eps",c->GetName(),textleg.Data()));
919  }
920  }
921 
922 
923  listname="countersCentrality";
924 
925  isRead=ReadFile(list,lstat,listname,partname.Data(),path,filename,dirname);
926  if(!isRead) return;
927  if(!list || !lstat){
928  cout<<":-( null pointers..."<<endl;
929  return;
930  }
931 
932 
933  if(superimpose){
934  isRead=ReadFile(llist,llstat,listname,partname2.Data(),path2,filename2,dirname2);
935  if(!isRead) return;
936  if(!llist || !llstat){
937  cout<<":-( null pointers..."<<endl;
938  return;
939  }
940  TText *redtext=pvtxt->AddText(partname2);
941  redtext->SetTextColor(kRed);
942 
943  }
944 
945  TH1F* hallcntr=0x0;
946  TH1F* hhallcntr=0x0;
947  cout<<"normalizing to 0-80% as a check"<<endl;
948  Int_t ncentr=10;//check this
949  TH1F* h020=0x0;
950  TH1F* h2080=0x0;
951  TH1F* hh020=0x0;
952  TH1F* hh2080=0x0;
953 
954  TCanvas *cvnocnt=new TCanvas("cvnocnt","No Centrality estimation",800,400);
955  cvnocnt->Divide(2,1);
956  TCanvas *ccent=0x0;
957 
958  for(Int_t i=0;i<list->GetEntries();i++){
959  AliCounterCollection* coll=(AliCounterCollection*)list->At(i);
960  AliCounterCollection* colle=0x0;
961  if(superimpose) colle=(AliCounterCollection*)llist->At(i);
962  coll->SortRubric("run");//sort by run number
963 
964  h020=0x0;
965  h2080=0x0;
966  hh020=0x0;
967  hh2080=0x0;
968 
969  hallcntr=0x0;
970  hhallcntr=0x0;
971 
972  TH1F* hbad=(TH1F*)coll->Get("run",Form("centralityclass:-990_-980"));
973  cvnocnt->cd(i+1);
974  if(hbad) hbad->Draw();
975 
976  ccent=new TCanvas(Form("ccent%s",coll->GetName()),Form("Centrality vs Run (%s)",coll->GetName()),1400,800);
977  ccent->SetTicky();
978  ccent->Divide(4,2);
979 
980  TH1F* hh=0x0;
981 
982  for(Int_t ic=0;ic<8/*ncentr*/;ic++){ //normalizing to 0-80% as a check
983 
984  TH1F* h=(TH1F*)coll->Get("run",Form("centralityclass:%d_%d",ic*10,ic*10+10));
985  h->SetName(Form("h%d%d",i,ic));
986  if(!hallcntr) {
987  hallcntr=(TH1F*)h->Clone("hallcntr");
988  hallcntr->Sumw2();
989  } else {
990  hallcntr->Add(h);
991  }
992 
993  nevents080+=h->Integral();
994 
995  if(superimpose){
996  hh=(TH1F*)colle->Get("run",Form("centralityclass:%d_%d",ic*10,ic*10+10));
997  hh->SetName(Form("hh%d%d",i,ic));
998  if(!hhallcntr) {
999  hhallcntr=(TH1F*)hh->Clone("hhallcntr");
1000  hhallcntr->Sumw2();
1001  }else hhallcntr->Add(hh);
1002 
1003  nnevents080+=hh->Integral();
1004 
1005  }
1006  }
1007 
1008  for(Int_t ic=0;ic<ncentr;ic++){
1009 
1010  TH1F* h=(TH1F*)coll->Get("run",Form("centralityclass:%d_%d",ic*10,ic*10+10));
1011  h->SetName(Form("h%d%d",i,ic));
1012  h->Sumw2();
1013 
1014  if(ic>=0 && ic<=1){ //0-20
1015  if(!h020) {
1016  h020=(TH1F*)h->Clone(Form("h020%s",coll->GetName()));
1017  h020->SetTitle(Form("Centrality 0-20 %s",coll->GetName()));
1018  if(superimpose){
1019  hh020=(TH1F*)hh->Clone(Form("hh020%s",coll->GetName()));
1020  hh020->SetTitle(Form("Centrality 0-20 %s",coll->GetName()));
1021  }
1022  }
1023  else {
1024  h020->Add(h);
1025  if(superimpose)hh020->Add(hh);
1026  }
1027  }
1028  if(ic>=2 && ic<=7){ //20-80
1029  if(!h2080) {
1030  h2080=(TH1F*)h->Clone(Form("h2080%s",coll->GetName()));
1031  h2080->SetTitle(Form("Centrality 20-80 %s",coll->GetName()));
1032  if(superimpose){
1033  hh2080=(TH1F*)hh->Clone(Form("hh2080%s",coll->GetName()));
1034  hh2080->SetTitle(Form("Centrality 20-80 %s",coll->GetName()));
1035  }
1036  }
1037  else {
1038  h2080->Add(h);
1039  if(superimpose)hh2080->Add(hh);
1040  }
1041 
1042  }
1043 
1044  h->Divide(hallcntr);
1045 
1046  if(ic<8){
1047  ccent->cd(ic+1);
1048  h->GetYaxis()->SetLabelSize(0.05);
1049  h->GetYaxis()->SetTitleOffset(1.5);
1050  h->SetMinimum(0);
1051  //h->GetYaxis()->SetRangeUser(0.,0.15);
1052  h->DrawClone();
1053  }
1054  /*
1055  if(ic==0&&i==0){
1056  spare->cd();
1057  h->Draw();
1058  }
1059  */
1060  // ccent->cd(1);
1061  // h->SetLineColor(ic+1);
1062  // if(ic==0)h->DrawClone();
1063  // else h->DrawClone("sames");
1064  }
1065  h020->Divide(hallcntr);
1066  if(superimpose){
1067  hh020->Divide(hhallcntr);
1068  hh020->SetLineColor(2);
1069  hh020->SetMarkerColor(2);
1070  }
1071 
1072  /*//draw 0-20 and 20-80 in the multi pad canvas (increase divisions before uncommenting)
1073  ccent->cd(ncentr+1);
1074  h020->DrawClone();
1075  if(superimpose){
1076  hh020->DrawClone("sames");
1077  }
1078  */
1079  TCanvas* cv020=new TCanvas(Form("cv020-%d",i),"0-20% vs run number",1400,600);
1080  cv020->cd();
1081  cv020->SetTicky();
1082  h020->GetYaxis()->SetRangeUser(0.,1.);
1083  h020->DrawClone();
1084  if(superimpose)hh020->DrawClone("sames");
1085  cv020->SaveAs(Form("cv020-%d.pdf",i));
1086  cv020->SaveAs(Form("cv020-%d.eps",i));
1087 
1088  h2080->Divide(hallcntr);
1089  if(superimpose) {
1090  hh2080->Divide(hhallcntr);
1091  hh2080->SetLineColor(2);
1092  hh2080->SetMarkerColor(2);
1093  }
1094 
1095  /*
1096  ccent->cd(ncentr+2);
1097  h2080->DrawClone();
1098 
1099  if(superimpose){
1100  hh2080->DrawClone("sames");
1101  }
1102  */
1103  TCanvas* cv2080=new TCanvas(Form("cv2080-%d",i),"20-80% vs run number",1400,600);
1104  cv2080->cd();
1105  cv2080->SetTicky();
1106  h2080->GetYaxis()->SetRangeUser(0.,1.);
1107  h2080->DrawClone();
1108  if(superimpose)hh2080->DrawClone("sames");
1109  cv2080->SaveAs(Form("cv2080-%d.pdf",i));
1110  cv2080->SaveAs(Form("cv2080-%d.eps",i));
1111 
1112  ccent->SaveAs(Form("%s%s.pdf",ccent->GetName(),textleg.Data()));
1113  ccent->SaveAs(Form("%s%s.eps",ccent->GetName(),textleg.Data()));
1114  }
1115 
1116 }
1117 
1118 void 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*/){
1119  gStyle->SetCanvasColor(0);
1120  gStyle->SetTitleFillColor(0);
1121  gStyle->SetStatColor(0);
1122  gStyle->SetPalette(1);
1123 
1124  TString listname="outputCentrCheck";
1125  TString dirname="PWG3_D2H_QA";
1126  dirname+=suffixdir;
1127 
1128  TList* list = NULL;
1129  TList * lstat = NULL;
1130  TH1F* hEntr = NULL;
1131 
1132  Bool_t isRead=ReadFile(list,lstat,listname,partname,path,filename,dirname);
1133  if(!isRead) return;
1134  if(!list || !lstat){
1135  cout<<":-( null pointers..."<<endl;
1136  return;
1137  }
1138  hEntr = (TH1F*) lstat->FindObject("hNentries");
1139  Double_t nevents=hEntr->GetBinContent(5); //ev good vertex
1140 
1141  TH2F* h2=(TH2F*)list->FindObject(h2dname);
1142  if(!h2){
1143  cout<<h2dname.Data()<<" not found"<<endl;
1144  list->ls();
1145  return;
1146  }
1147  TCanvas* cv2d=new TCanvas("cv2d",h2->GetName());
1148  cv2d->cd();
1149  cv2d->SetLogz();
1150  cv2d->SetGrid();
1151  h2->Draw("colz");
1152  TPaveText *pvst=new TPaveText(0.6,0.2,0.9,0.7,"NDC");
1153  pvst->SetBorderSize(0);
1154  pvst->SetFillStyle(0);
1155  pvst->AddText("Bin -> Cont/nEvVtx");
1156 
1157  //nsteps=group bins in the Y(X) direction if projecting on the X(Y) direction
1158  Int_t nsteps=0;
1159 
1160  if(direction=="X") nsteps=h2->GetNbinsY()/groupnbins;
1161  if(direction=="Y") nsteps=h2->GetNbinsX()/groupnbins;
1162  cout<<"Grouping bins by " <<groupnbins<<" I obtaine "<<nsteps<<" projections"<<endl;
1163 
1164  TCanvas *cvpj=new TCanvas(Form("cvpj%s%s",direction.Data(),h2dname.Data()),Form("cvpj%s",direction.Data()),1200,800);
1165  cvpj->Divide((Int_t)(nsteps/3)+1,3);
1166  TFile* fout=new TFile(Form("proj%s%s.root",direction.Data(),h2dname.Data()), "recreate");
1167  //Float_t maxx[nsteps];
1168  //Float_t maxx[12]={9000,9000,6000,4000,2000,1400,800,500,200,100,40,25};
1169  Double_t integralpernev[nsteps];
1170 
1171  Double_t minx=0,maxx=0;
1172  if(direction=="X"){
1173  minx=h2->GetYaxis()->GetXmin();
1174  maxx=h2->GetYaxis()->GetXmax();
1175  }
1176  if(direction=="Y"){
1177  minx=h2->GetXaxis()->GetXmin();
1178  maxx=h2->GetXaxis()->GetXmax();
1179  }
1180  printf("Plotting from %.1f to %.1f\n",minx,maxx);
1181  TCanvas *cintegral=new TCanvas("cintegral","Integral of each projection");
1182  TH1F* hint=new TH1F("hint","Integral of each projection;Centrality (%);Entries",nsteps,minx,maxx);
1183  Double_t minint=999999999,maxint=0;
1184 
1185  for(Int_t i=0;i<nsteps;i++){
1186  TH1F* h=0x0;
1187  // if(direction=="X")h=(TH1F*)h2->ProjectionX(Form("px%d",i),i+kbins,i+2*kbins);
1188  // if(direction=="Y")h=(TH1F*)h2->ProjectionY(Form("py%d",i),i+kbins,i+2*kbins);
1189  if(direction=="X")h=(TH1F*)h2->ProjectionX(Form("px%d",i),groupnbins*i+1,groupnbins*(i+1));
1190  if(direction=="Y")h=(TH1F*)h2->ProjectionY(Form("py%d",i),groupnbins*i+1,groupnbins*(i+1));
1191  Double_t projint=h->Integral();
1192  cout<<"Integral of projection "<<i<<" = "<<projint<<endl;
1193  hint->SetBinContent(i+1,projint);
1194  hint->SetBinError(i+1,TMath::Sqrt(projint));
1195 
1196  if(projint<1e-7) continue;
1197  if(minint>projint) minint=projint;
1198  if(projint>maxint) maxint=projint;
1199  integralpernev[i]=h->Integral()/nevents;
1200 
1201  TPaveText *pvtxt=new TPaveText(0.6,0.6,0.9,0.9,"NDC");
1202  pvtxt->SetBorderSize(0);
1203  pvtxt->SetFillStyle(0);
1204  pvtxt->AddText(Form("%.0f - %.0f",h2->GetYaxis()->GetBinLowEdge(groupnbins*i+1),h2->GetYaxis()->GetBinLowEdge(groupnbins*(i+1))));
1205  pvst->AddText(Form("%.0f - %.0f -> %.2f",h2->GetYaxis()->GetBinLowEdge(groupnbins*i+1),h2->GetYaxis()->GetBinLowEdge((groupnbins*(i+1))),integralpernev[i]));
1206 
1207  cvpj->cd(i+1);
1208  //h->GetXaxis()->SetRangeUser(0,maxx[i]);
1209  h->Draw();
1210  pvtxt->Draw();
1211  fout->cd();
1212  h->Write();
1213  }
1214  cvpj->SaveAs(Form("cvpj%s%s.pdf",direction.Data(),h2dname.Data()));
1215  cvpj->SaveAs(Form("cvpj%s%s.eps",direction.Data(),h2dname.Data()));
1216 
1217  cv2d->cd();
1218  pvst->Draw();
1219  cv2d->SaveAs(Form("%s.pdf",h2->GetName()));
1220  cv2d->SaveAs(Form("%s.eps",h2->GetName()));
1221 
1222  cintegral->cd();
1223  hint->SetMarkerStyle(20);
1224  hint->Draw("PE");
1225  if(!fitfunc.Contains("nofit")){
1226  hint->Fit(fitfunc.Data(),"RL","PE",fitmin,fitmax);
1227  TF1* fpolfit=hint->GetFunction(fitfunc.Data());
1228  TPaveText *txtvar=new TPaveText(0.3,0.1,0.9,0.4,"NDC");
1229  txtvar->SetBorderSize(0);
1230  txtvar->SetFillStyle(0);
1231  //txtvar->AddText(Form("Full spread %.0f- %.0f",maxint,minint));
1232  txtvar->AddText(Form("Fit in %.1f-%.1f; ",fitmin,fitmax));
1233  for(Int_t ipar=0;ipar<fpolfit->GetNpar();ipar++){
1234  txtvar->AddText(Form("par%d = %.0f, ",ipar, fpolfit->GetParameter(ipar)));
1235  }
1236  txtvar->AddText(Form("#tilde{#chi}^{2} = %.2f",fpolfit->GetChisquare()/fpolfit->GetNDF()));
1237  txtvar->AddText(Form("bin width = %.1f %s",hint->GetBinWidth(3),"%"));
1238  txtvar->Draw();
1239  }
1240  fout->cd();
1241  hint->Write();
1242  cintegral->SaveAs(Form("%s.pdf",hint->GetName()));
1243  cintegral->SaveAs(Form("%s.eps",hint->GetName()));
1244 }
1245 
1246 void DrawEventSelection(TString partname="D0", TString path="./",TString suffixdir="",TString filename="AnalysisResults.root"){
1247  gStyle->SetCanvasColor(0);
1248  gStyle->SetTitleFillColor(0);
1249  gStyle->SetStatColor(0);
1250  gStyle->SetPalette(1);
1251  gStyle->SetOptStat(0);
1252 
1253  TString listname="outputEvSel";
1254  TString dirname="PWG3_D2H_QA";
1255  dirname+=suffixdir;
1256 
1257  TList* list= NULL;
1258  TList * lstat = NULL;
1259  TH1F* hEntr= NULL;
1260 
1261 
1262  Bool_t isRead=ReadFile(list,lstat,listname,partname,path,filename,dirname);
1263  if(!isRead) return;
1264  if(!list || !lstat){
1265  cout<<":-( null pointers..."<<endl;
1266  return;
1267  }
1268  hEntr =(TH1F *)lstat->FindObject("hNentries");
1269  //Double_t neventsgv=hstat->Integral(5,5); //ev good vertex
1270 
1271  for(Int_t i=0;i<list->GetEntries();i++){
1272 
1273  TClass* objtype=list->At(i)->IsA();
1274  TString tpname=objtype->GetName();
1275 
1276  if(tpname=="TH1F"){
1277  TH1F* htmp=(TH1F*)list->At(i);
1278  TCanvas* c=new TCanvas(Form("c%s",htmp->GetName()),Form("c%s",htmp->GetName()));
1279  c->cd();
1280  htmp->Draw();
1281  c->SaveAs(Form("%s.pdf",htmp->GetName()));
1282  c->SaveAs(Form("%s.eps",htmp->GetName()));
1283  }
1284 
1285  if(tpname=="TH2F"){
1286  TH2F* htmp=(TH2F*)list->At(i);
1287  TCanvas* c=new TCanvas(Form("c%s",htmp->GetName()),Form("c%s",htmp->GetName()),1200,800);
1288  c->cd();
1289  htmp->SetMarkerSize(1.3);
1290  htmp->Draw("colzhtext45");
1291  c->SaveAs(Form("%s.pdf",htmp->GetName()));
1292  c->SaveAs(Form("%s.eps",htmp->GetName()));
1293  }
1294  }
1295 
1296  AliCounterCollection* coll=(AliCounterCollection*)list->FindObject("trigCounter");
1297  if(!coll) {
1298  cout<<"Trigger counter not found"<<endl;
1299  return;
1300  }
1301 
1302  coll->SortRubric("run");//sort by run number
1303 
1304  TString collname=coll->GetName();
1305 
1306  TString keywords=coll->GetKeyWords("triggertype");
1307 
1308  Int_t nkeys=keywords.CountChar(',')+1;
1309 
1310  TString *words = new TString[nkeys];
1311  for(Int_t k=0;k<nkeys;k++) words[k]="";
1312  printf("Keywords: ");
1313  Int_t count=0;
1314  for(Int_t l=0;l<keywords.Length();l++){
1315  if(keywords[l] != ',') words[count]+=keywords[l];
1316  else {
1317  printf("%s ",words[count].Data());
1318  count++;
1319  }
1320  }
1321  cout<<endl;
1322 
1323  TH1D** htrig=new TH1D*[nkeys]; //each trigger type in one histogram of counts vs run
1324  TH1D** htrignormAll=new TH1D*[nkeys]; //normalized to the counts in kAll
1325  TH1D** htrignormAny=new TH1D*[nkeys]; //normalized to the counts in kAny
1326  TCanvas* ctrigfractionAll=new TCanvas("cvtrigfrac","Fraction of given trigger type vs run (kAll)",1400,800);
1327  TCanvas* ctrigfractionAny=new TCanvas("cvtrigfracAll","Fraction of given trigger type vs run (kAny)",1400,800);
1328  TLegend* legtr=new TLegend(0.15,0.5,0.35,0.8);
1329  legtr->SetBorderSize(0);
1330  legtr->SetFillStyle(0);
1331 
1332  TH1D* htrigkAny=new TH1D();
1333  htrigkAny = coll->Get("run",Form("triggertype:%s","ANY"));
1334  htrigkAny->SetName(Form("h%s","ANY"));
1335  htrigkAny->SetTitle("Trigger type;RUN; counts");
1336  htrigkAny->Sumw2();
1337  TH1D* htrigkAll=new TH1D();
1338  htrigkAll = coll->Get("run",Form("triggertype:%s","ALL"));
1339  htrigkAll->SetName(Form("h%s","ALL"));
1340  htrigkAll->SetTitle("Trigger type;RUN; counts");
1341  htrigkAll->Sumw2();
1342 
1343  for(Int_t k=0;k<nkeys;k++){
1344  htrig[k]=coll->Get("run",Form("triggertype:%s",words[k].Data()));
1345  htrig[k]->SetName(Form("h%s",words[k].Data()));
1346  htrig[k]->SetTitle("Trigger type;RUN; counts");
1347  htrig[k]->SetMarkerColor(k+1);
1348  htrig[k]->SetMarkerStyle(k+20);
1349  htrig[k]->Sumw2();
1350  legtr->AddEntry(htrig[k],Form("%s",words[k].Data()),"P");
1351  //drawings
1352  //1) counts of a given trigger over counts in kAll
1353  htrignormAll[k]=(TH1D*)htrig[k]->Clone(Form("h%snormAll",words[k].Data()));
1354  htrignormAll[k]->SetTitle("Trigger type over ALL trigger;RUN; counts/countsALL");
1355  htrignormAll[k]->Divide(htrig[k],htrigkAll,1.,1.,"B");
1356  htrignormAll[k]->GetXaxis()->SetRangeUser(0,1.1);
1357 
1358  ctrigfractionAll->cd();
1359  if(k>0)htrignormAll[k]->Draw("PEsames");
1360  else htrignormAll[k]->Draw("PE");
1361 
1362  //1) counts of a given trigger over counts in kAny
1363  htrignormAny[k]=(TH1D*)htrig[k]->Clone(Form("h%snormAny",words[k].Data()));
1364  htrignormAny[k]->SetTitle("Trigger type over ANY trigger;RUN; counts/countsANY");
1365  htrignormAny[k]->Divide(htrig[k],htrigkAny,1.,1.,"B");
1366  htrignormAny[k]->GetXaxis()->SetRangeUser(0,1.1);
1367 
1368  ctrigfractionAny->cd();
1369  if(k>0)htrignormAny[k]->Draw("PEsames");
1370  else htrignormAny[k]->Draw("PE");
1371  }
1372 
1373  ctrigfractionAll->cd();
1374  legtr->Draw();
1375  ctrigfractionAll->SaveAs("TrgFractionOverALL.pdf");
1376  ctrigfractionAll->SaveAs("TrgFractionOverALL.eps");
1377 
1378  ctrigfractionAny->cd();
1379  legtr->Draw();
1380  ctrigfractionAny->SaveAs("TrgFractionOverANY.pdf");
1381  ctrigfractionAny->SaveAs("TrgFractionOverANY.eps");
1382 
1383  delete [] words;
1384  delete htrigkAll; delete htrigkAny;
1385 
1386  //draw number of events per trigger
1387  TH2F* hTrigMul=(TH2F*)list->FindObject("hTrigMul");
1388 
1389  TH1F *hnEvPerTrig=(TH1F*)hTrigMul->ProjectionX("hnEvPerTrig");
1390  hnEvPerTrig->SetTitle("Number of events per trigger");
1391  TCanvas* cnev=new TCanvas("cnev","Number of events",1400,800);
1392  cnev->cd();
1393  hnEvPerTrig->Draw("htext0");
1394  cnev->SaveAs(Form("%s.pdf",cnev->GetName()));
1395  cnev->SaveAs(Form("%s.eps",cnev->GetName()));
1396 
1397  //draw number of events selected per trigger
1398  TH2F* hTrigMulSel=(TH2F*)list->FindObject("hTrigMulSel");
1399 
1400  TH1F *hnEvPerTrigSel=(TH1F*)hTrigMulSel->ProjectionX("hnEvPerTrigSel");
1401  hnEvPerTrigSel->SetTitle("Number of events selected per trigger");
1402  TCanvas* cnevs=new TCanvas("cnevs","Number of events selected",1400,800);
1403  cnevs->cd();
1404  hnEvPerTrigSel->Draw("htext0");
1405  cnevs->SaveAs(Form("%s%s.pdf",cnevs->GetName(),suffixdir.Data()));
1406  cnevs->SaveAs(Form("%s%s.eps",cnevs->GetName(),suffixdir.Data()));
1407 
1408  TH1F* hnEvSelPerc=(TH1F*)hnEvPerTrigSel->Clone("hnEvSelFrac");
1409  hnEvSelPerc->SetTitle("Fraction of event selected per trigger");
1410  hnEvSelPerc->Divide(hnEvPerTrig);
1411  TCanvas* cnevsp=new TCanvas("cnevsp","Fraction of events selected",1400,800);
1412  cnevsp->cd();
1413  hnEvSelPerc->Draw("htext0");
1414  cnevsp->SaveAs(Form("%s%s.pdf",cnevsp->GetName(),suffixdir.Data()));
1415  cnevsp->SaveAs(Form("%s%s.eps",cnevsp->GetName(),suffixdir.Data()));
1416 }
1417 
1418 void WriteTextFileForCompilation(TString inputtextfile, Int_t analysistype){
1419  //This method writes a text file with the name given in input containing the path of the QA output file, the directories and the lists of histograms to be read to perform a comparison of QA outputs
1420  // analysistype = 1 is the OutputTrack
1421  // analysistype = 2 is the OutputEventSelection
1422  // other outputs can be implemented
1423 
1424  // The paths and trigger type (or more in general the suffix of the directories to be read have to be set in this method)
1425  // The legend is set either equal to the trigger type if they are different, or it should be set manually
1426  // Run this methos before CompilationOfTriggeredEvents unless the text file has been already produced
1427 
1428  Printf("WARNING! Did you customize the parameters in the macro?");
1429  const Int_t n=8; //customize this
1430  TString prepath="/data/Work/HFQA/LHC12QATrainOutputs/";//"./";
1431  TString pathname[n]={"LHC12a/Train165/","LHC12b/Train166/","LHC12d/Train168/","LHC12e/Train170/","LHC12f/Train171/","LHC12g/Train172/"};
1432 
1433  TString dirname[n];
1434  TString listname[n];
1435  ofstream myfile;
1436  myfile.open(inputtextfile);
1437  myfile<<n<<endl;
1438 
1439  TString filename="AnalysisResults.root";
1440  TString basedirname="PWG3_D2H_QA";
1441  TString trgnames[n];//={"INT7","EMC7","EMCJET7","EMCGAMMA7","INT8","EMC8","EMCJET8","EMCGAMMA8"}; //customize this
1442  TString baselistname="", partname="D00100";
1443  TString legend[n]={"LHC12a165","LHC12b166","LHC12d168","LHC12e170","LHC12f171","LHC12g172"}; //Customize this if want it to be different from trgnames
1444  if(analysistype==1) baselistname="outputTrack";
1445  if(analysistype==2) baselistname="outputEvSel";
1446  //... others could be added
1447 
1448  //All in the same directory on your computer
1449  for(Int_t i=0;i<n;i++){
1450  //set
1451  pathname[i]=prepath+pathname[i];//"./";
1452  trgnames[i]="EMC7";
1453  dirname[i]=basedirname+trgnames[i];
1454  listname[i]=baselistname+partname+trgnames[i];
1455  if(legend[i]=="") legend[i]=trgnames[i];
1456 
1457  //Printf("Trigger name is %s",trgnames[i].Data());
1458  //Printf("Legend is %s",legend[i].Data());
1459 
1460  //write text file
1461  myfile<<endl;
1462  myfile<<endl;
1463  myfile<<pathname[i].Data()<<filename.Data()<<endl;
1464  myfile<<dirname[i].Data()<<endl;
1465  myfile<<listname[i].Data()<<endl;
1466  myfile<<legend[i].Data()<<endl;
1467 
1468  }
1469  myfile.close();
1470 
1471 }
1472 
1473 Bool_t ReadFilesForCompilation(TString inputtextfile, TList**& lists, Int_t& numb, TString*& legend){
1474 
1475  //Method to read the QA files indicated in the text file in input (to be written with WriteTextFileForCompilation() method)
1476  ifstream myfile;
1477  myfile.open(inputtextfile);
1478  if(!myfile.is_open()) Printf("No files found, did you make it correctly?");
1479  Int_t n;
1480  myfile >> n;
1481  lists=new TList*[n];
1482  legend= new TString[n];
1483  numb=n;
1484 
1485  Int_t k=0;
1486 
1487  while(myfile){
1488 
1489  TString filename;
1490  myfile>>filename;
1491  //Printf("Filename = %s",filename.Data());
1492  TFile *fin=new TFile(filename);
1493  if(!fin->IsOpen()){
1494  Printf("File %s not found",filename.Data());
1495  return kFALSE;
1496  }
1497 
1498  TString dirname;
1499  myfile>>dirname;
1500  //Printf("Dirname = %s",dirname.Data());
1501  TDirectoryFile* dir=(TDirectoryFile*)fin->Get(dirname);
1502  if(!dir){
1503  Printf("Directory %s not found in %s",dirname.Data(),filename.Data());
1504  fin->ls();
1505  return kFALSE;
1506  }
1507 
1508  TString listname;
1509  myfile>>listname;
1510  //Printf("Listname = %s",listname.Data());
1511  lists[k]=(TList*)dir->Get(listname);
1512  if(!lists[k]){
1513  Printf("List %s not found in %s",listname.Data(),dirname.Data());
1514  dir->ls();
1515  return kFALSE;
1516  }
1517 
1518  TString temp;
1519  myfile>>temp;
1520  legend[k]=temp;
1521  Printf("Legend = %s",legend[k].Data());
1522  if(!legend[k]){
1523  Printf("Legend %s not found",filename.Data());
1524  return kFALSE;
1525  }
1526 
1527 
1528  k++;
1529  if(k==n)return kTRUE;// Needed as the while loop does not always realise the end is reached.
1530  }
1531  return kTRUE;
1532 }
1533 
1534 void CompilationOfTriggeredEvents(TString inputtextfile,Int_t analysistype){
1535  //This method draws the histograms superimposed
1536 
1537  // analysistype = 1 is the OutputTrack
1538  // analysistype = 2 is the OutputEventSelection
1539  // other outputs can be implemented
1540 
1541  TList **lists=0x0;
1542  Int_t n;
1543  TString* legend=0x0;
1544  Bool_t okread=ReadFilesForCompilation(inputtextfile,lists,n,legend);
1545  if(!okread){
1546  Printf("Did you write %s with WriteTextFileForCompilation(%s)?",inputtextfile.Data(),inputtextfile.Data());
1547  return;
1548  }
1549 
1550  if(analysistype==2){CompilationEvSelection(n,lists,legend);}
1551  if(analysistype==1){CompilationTrackSelection(n,lists,legend);}
1552 }
1553 
1554 void CompilationEvSelection(Int_t n,TList** lists, TString* legend){
1555  // Specific method for EventSelection output (2)
1556 
1557  TCanvas *cnevs=new TCanvas("cnevs","Number of events selected",1400,800);
1558  TCanvas *cnevsp=new TCanvas("cnevsp","Fraction of events selected",1400,800);
1559  TH1F** hnEvPerTrig=new TH1F*[n];
1560  TH1F** hnEvPerTrigSel=new TH1F*[n];
1561  TH1F** hnEvSelPerc=new TH1F*[n];
1562 
1563  TLegend* leg=new TLegend(0.15,0.5,0.45,0.78);
1564  leg->SetFillStyle(0);
1565  leg->SetBorderSize(0);
1566 
1567  Bool_t first=kTRUE;
1568  Int_t nentriesl=lists[0]->GetEntries();
1569  TCanvas** c=new TCanvas*[nentriesl];
1570  Int_t nth1f=0;
1571 
1572  for(Int_t i=0;i<n;i++){
1573 
1574  TH2F* hTrigMul=(TH2F*)lists[i]->FindObject("hTrigMul");
1575 
1576  hnEvPerTrig[i]=(TH1F*)hTrigMul->ProjectionX(Form("hnEvPerTrig%d",i));
1577  hnEvPerTrig[i]->SetTitle("Number of events selected per trigger");
1578 
1579 
1580  TH2F* hTrigMulSel=(TH2F*)lists[i]->FindObject("hTrigMulSel");
1581 
1582  hnEvPerTrigSel[i]=(TH1F*)hTrigMulSel->ProjectionX(Form("hnEvPerTrigSel%d",i));
1583  hnEvPerTrigSel[i]->SetTitle("Number of events selected per trigger");
1584  hnEvPerTrigSel[i]->SetLineColor(i+1);
1585  hnEvPerTrigSel[i]->SetLineWidth(2);
1586 
1587  cnevs->cd();
1588  if(i==0) hnEvPerTrigSel[i]->Draw();
1589  else hnEvPerTrigSel[i]->Draw("sames");
1590 
1591  hnEvSelPerc[i]=(TH1F*)hnEvPerTrigSel[i]->Clone(Form("hnEvSelFrac%d",i));
1592  hnEvSelPerc[i]->SetTitle("Fraction of event selected per trigger");
1593  hnEvSelPerc[i]->SetLineColor(i+1);
1594  hnEvSelPerc[i]->SetLineWidth(2);
1595  hnEvSelPerc[i]->Divide(hnEvPerTrig[i]);
1596  cnevsp->cd();
1597  if(i==0) hnEvSelPerc[i]->Draw("htext0");
1598  else hnEvSelPerc[i]->Draw("htext0sames");
1599  nth1f=0; //restart counting per each file
1600 
1601  //fill legend
1602  leg->AddEntry(hnEvSelPerc[i],legend[i],"L");
1603 
1604  for(Int_t j=0; j<nentriesl; j++){
1605  TClass* objtype=lists[i]->At(j)->IsA();
1606  TString tpname=objtype->GetName();
1607 
1608  if (tpname=="TH1F"){
1609  TH1F* htmp=(TH1F*)lists[i]->At(j);
1610 
1611  htmp->SetLineColor(1+i);
1612  if(htmp->Integral()>0) htmp->Scale(1./htmp->Integral());
1613 
1614  if(first) {
1615  c[nth1f]=new TCanvas(Form("c%s",htmp->GetName()),Form("c%s",htmp->GetName()));
1616  c[nth1f]->cd();
1617  htmp->Draw();
1618 
1619  }
1620  else {
1621  c[nth1f]->cd();
1622  htmp->Draw("sames");
1623  }
1624  nth1f++;
1625  }
1626  }
1627 
1628  first=kFALSE;
1629 
1630  }
1631 
1632  for(Int_t j=0;j<nth1f;j++){
1633  c[j]->cd();
1634  leg->Draw();
1635  c[j]->SaveAs(Form("%s.pdf",c[j]->GetName()));
1636  c[j]->SaveAs(Form("%s.eps",c[j]->GetName()));
1637  }
1638 
1639  cnevs->cd();
1640  leg->Draw();
1641  cnevs->SaveAs(Form("%s.eps",cnevs->GetName()));
1642  cnevs->SaveAs(Form("%s.pdf",cnevs->GetName()));
1643 
1644  cnevsp->cd();
1645  leg->Draw();
1646  cnevsp->SaveAs(Form("%s.eps",cnevsp->GetName()));
1647  cnevsp->SaveAs(Form("%s.pdf",cnevsp->GetName()));
1648  TCanvas *test=new TCanvas();
1649  test->cd(); leg->Draw();
1650 }
1651 
1652 
1653 void CompilationTrackSelection(Int_t n,TList** lists,TString* legend)
1654 {
1655  // Specific method for Track output (1)
1656 
1657  for(Int_t i=0;i<lists[0]->GetEntries();i++){
1658  TObjArray* plotseth=new TObjArray();
1659  TObjArray* plotsethr=new TObjArray();
1660 
1661  Bool_t is2d=false;
1662  is2d = lists[0]->At(i)->InheritsFrom("TH2");
1663  if(is2d) continue;
1664 
1665  for(Int_t j=0; j<n; j++){
1666  TH1F* temph=(TH1F*)lists[j]->At(i);
1667  TH1F * temphr=0x0;
1668  TH1F * ploto=0x0; //0th plot to divide by
1669 
1670  // plot ratios and scale all plots to integral
1671  temphr= (TH1F*)temph->Clone(Form("%s_ratio",temph->GetName()));
1672  if(j==0)ploto = temphr;
1673  else ploto = (TH1F*)plotseth->At(0);
1674  temphr->Divide(ploto);
1675  if(temphr->Integral()>0){temphr-> Scale(1./temphr->Integral());}// take out for nonscaled ratios
1676  if(temph->Integral()>0){ temph-> Scale(1./temph->Integral());}
1677 
1678  plotseth->AddLast(new TH1F(*temph));
1679  plotsethr->AddLast(new TH1F(*temphr));
1680  }
1681 
1682 
1683  TH1F *h = (TH1F*)plotseth->At(0);
1684  TCanvas* c=new TCanvas(Form("c%s",h->GetName()),h->GetName());
1685  c->cd();
1686  c->SetGrid();
1687  TString hname=h->GetName();
1688 
1689  if(!hname.Contains("nCls")){
1690  c->SetLogy();
1691  if(hname.Contains("Layer")){
1692  for(Int_t ibin=1;ibin<=h->GetNbinsX();ibin++){
1693  h->GetXaxis()->SetBinLabel(ibin+1,Form("%d",ibin));
1694  }
1695  h->GetXaxis()->SetLabelSize(0.06);
1696  h->GetXaxis()->SetRangeUser(0,6); //comment to see ntracks!
1697  }
1698  //h->SetMinimum(1);
1699  h->Draw();
1700 
1701  TLegend* leg=new TLegend(0.15,0.5,0.45,0.78);
1702  leg->SetFillStyle(0);
1703  leg->SetBorderSize(0);
1704  leg->AddEntry(h,legend[0],"L");
1705 
1706  for(Int_t j=1; j<n; j++){
1707  TH1F * h2 = (TH1F*)plotseth->At(j);
1708  h2->SetLineColor(1+j);
1709  h2->Draw("sames");
1710  leg->AddEntry(h2,legend[j],"L");
1711  }
1712 
1713  leg->Draw();
1714 
1715  TCanvas* c2=new TCanvas(Form("c2%s",h->GetName()),h->GetName());
1716  c2->cd();
1717  c2->SetGrid();
1718  TH1F *hr = (TH1F*)plotsethr->At(1);
1719  hr->SetLineColor(2);
1720  hr->Draw();
1721  TLegend* leg2=new TLegend(0.15,0.5,0.45,0.78);
1722  leg2->SetFillStyle(0);
1723  leg2->SetBorderSize(0);
1724 
1725  TString ratioleg;
1726  ratioleg+=legend[1];
1727  ratioleg+="/";
1728  ratioleg+=legend[0];
1729 
1730  leg2->AddEntry(hr,ratioleg,"L");
1731 
1732  for(Int_t j=2; j<n; j++){
1733  TH1F * hr2 = (TH1F*)plotsethr->At(j);
1734  hr2->SetLineColor(1+j);
1735  hr2->Draw("sames");
1736 
1737  TString ratioleg2;
1738  ratioleg2+=legend[j];
1739  ratioleg2+="/";
1740  ratioleg2+=legend[0];
1741 
1742  leg2->AddEntry(hr2,ratioleg2,"L");
1743  }
1744  leg2->Draw();
1745  c2->SaveAs(Form("%s%s%sRatio.pdf",c->GetName(),legend[0].Data(), legend[n-1].Data()));
1746  c2->SaveAs(Form("%s%s%sRatio.eps",c->GetName(),legend[0].Data(), legend[n-1].Data()));
1747  }
1748  else {
1749  h->Draw("htext0");
1750 
1751  TLegend* leg=new TLegend(0.15,0.5,0.45,0.78);
1752  leg->SetFillStyle(0);
1753  leg->SetBorderSize(0);
1754  leg->AddEntry(h,legend[0],"L");
1755 
1756  for(Int_t j=1; j<n; j++){
1757  TH1F * h2 = (TH1F*)plotseth->At(j);
1758  h2->SetLineColor(1+j);
1759  leg->AddEntry(h2,legend[j],"L");
1760  h2->Draw("htext0sames");
1761  }
1762 
1763  leg->Draw();
1764  }
1765  c->cd();
1766  c->SaveAs(Form("%s%s%s.eps",c->GetName(),legend[0].Data(), legend[n-1].Data()));
1767  c->SaveAs(Form("%s%s%s.pdf",c->GetName(),legend[0].Data(), legend[n-1].Data()));
1768  }
1769 
1770  Int_t check=0;
1771  Int_t maxfa=1;
1772  if(n<=10)maxfa=n;
1773  else cout<<"Warning: To many files for combinationplot, show only original"<<endl;
1774  TLegend* leg3=new TLegend(0.15,0.5,0.45,0.78);
1775  leg3->SetFillStyle(0);
1776  leg3->SetBorderSize(0);
1777  TCanvas* ctrsel=new TCanvas("ctrsel","Track Sel");
1778  ctrsel->SetLogy();
1779  for(Int_t i=0; i<maxfa; i++){
1780  TH1F* hd0fb4=(TH1F*)lists[i]->FindObject("hd0TracksFilterBit4");
1781  TH1F* hd0SPD1=(TH1F*)lists[i]->FindObject("hd0TracksSPDin");
1782  TH1F* hd0SPDany=(TH1F*)lists[i]->FindObject("hd0TracksSPDany");
1783  TH1F* hd0TPCITScuts=(TH1F*)lists[i]->FindObject("hd0TracksTPCITSSPDany");
1784  if(hd0fb4 && hd0SPD1 && hd0SPDany && hd0TPCITScuts){
1785  if(i==0){check=1;}
1786  else{if(check==0)return;}
1787  ctrsel->cd();
1788  hd0SPD1->SetLineColor(kCyan+3);
1789  hd0SPDany->SetLineColor(4);
1790  hd0TPCITScuts->SetLineColor(kGreen+1);
1791  hd0fb4->SetLineColor(2);
1792  if(i==0){
1793  hd0SPD1->Draw();
1794  ctrsel->Update();
1795  TPaveStats *st1=(TPaveStats*)hd0SPD1->GetListOfFunctions()->FindObject("stats");
1796  st1->SetTextColor(kCyan+3);
1797  st1->SetY1NDC(0.71);
1798  st1->SetY2NDC(0.9);
1799  hd0SPDany->Draw("sames");
1800  ctrsel->Update();
1801  TPaveStats *st2=(TPaveStats*)hd0SPDany->GetListOfFunctions()->FindObject("stats");
1802  st2->SetY1NDC(0.51);
1803  st2->SetY2NDC(0.7);
1804  st2->SetTextColor(4);
1805  hd0fb4->Draw("sames");
1806  ctrsel->Update();
1807  TPaveStats *st3=(TPaveStats*)hd0fb4->GetListOfFunctions()->FindObject("stats");
1808  st3->SetY1NDC(0.31);
1809  st3->SetY2NDC(0.5);
1810  st3->SetTextColor(2);
1811  hd0TPCITScuts->Draw("sames");
1812  ctrsel->Update();
1813  TPaveStats *st4=(TPaveStats*)hd0TPCITScuts->GetListOfFunctions()->FindObject("stats");
1814  st4->SetY1NDC(0.71);
1815  st4->SetY2NDC(0.9);
1816  st4->SetX1NDC(0.55);
1817  st4->SetX2NDC(0.75);
1818  st4->SetTextColor(kGreen+1);
1819  ctrsel->Modified();
1820  leg3->AddEntry(hd0SPD1,"kITSrefit+SPD inner","L");
1821  leg3->AddEntry(hd0SPDany,"kITSrefit+SPD any","L");
1822  leg3->AddEntry(hd0TPCITScuts,"TPC+ITS cuts+SPD any","L");
1823  leg3->AddEntry(hd0fb4,"Filter Bit 4","L");
1824  leg3->AddEntry(hd0SPD1, legend[i], "L");
1825  }
1826  else{
1827  hd0SPD1->SetStats(0);
1828  hd0SPD1->SetLineStyle(i+1);
1829  hd0SPD1->Draw("sames");
1830  hd0SPDany->SetStats(0);
1831  hd0SPDany->SetLineStyle(i+1);
1832  hd0TPCITScuts->SetStats(0);
1833  hd0TPCITScuts->SetLineStyle(i+1);
1834  hd0fb4->SetStats(0);
1835  hd0fb4->SetLineStyle(i+1);
1836  ctrsel->cd();
1837  hd0SPD1->Draw("sames");
1838  hd0SPDany->Draw("sames");
1839  hd0TPCITScuts->Draw("sames");
1840  hd0fb4->Draw("sames");
1841  leg3->AddEntry(hd0SPD1, legend[i], "L");
1842  }
1843 
1844  }
1845  }
1846  leg3->Draw();
1847  ctrsel->SaveAs("ImpactParameterTrackSel.eps");
1848  ctrsel->SaveAs("ImpactParameterTrackSel.pdf");
1849 }
1850 
Bool_t ReadFileMore(TList *&list, TList *&hstat, AliRDHFCuts *&cutobj, TString listname, TString partname, TString path="./", TString filename="PWG3histograms.root", TString dirname="PWG3_D2H_QA")
Definition: DrawQAoutput.C:76
void DrawOutputPID(TString partname="D00100", Int_t mode=0, TString textleg="", TString path="./", TString suffixdir="", TString filename="AnalysisResults.root")
Definition: DrawQAoutput.C:383
void CompilationEvSelection(Int_t n, TList **lists, TString *legend)
Bool_t ReadFilesForCompilation(TString inputtextfile, TList **&lists, Int_t &numb, TString *&legend)
void 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")
Double_t GetSigma(Int_t idet) const
Definition: AliAODPidHF.h:134
TList * list
void DrawEventSelection(TString partname="D0", TString path="./", TString suffixdir="", TString filename="AnalysisResults.root")
AliAODPidHF * GetPidHF() const
Definition: AliRDHFCuts.h:231
void WriteTextFileForCompilation(TString inputtextfile, Int_t analysistype)
void DrawOutputCentrality(TString partname="D0", TString textleg="", TString path="./", Bool_t superimpose=kFALSE, TString suffixdir="", TString filename="PWG3histograms.root")
Definition: DrawQAoutput.C:761
void SuperimposeBBToTPCSignal(Int_t period, TCanvas *cpid, Int_t set)
Definition: DrawQAoutput.C:592
void DrawOutputTrack(TString partname="D00100", TString textleg="", TString path="./", Bool_t superimpose=kFALSE, TString suffixdir="", TString filename="AnalysisResults.root", Bool_t normint=kTRUE)
Definition: DrawQAoutput.C:134
void GetPLimit(Double_t *plim) const
Definition: AliAODPidHF.h:139
Bool_t ReadFile(TList *&list, TList *&hstat, TString listname, TString partname, TString path="./", TString filename="PWG3histograms.root", TString dirname="PWG3_D2H_QA")
Definition: DrawQAoutput.C:41
Int_t mode
Definition: anaM.C:40
void TPCBetheBloch(Int_t set)
Definition: DrawQAoutput.C:614
void CompilationOfTriggeredEvents(TString inputtextfile, Int_t analysistype)
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
TString * periodsname
Definition: DrawQAoutput.C:29
void CompilationTrackSelection(Int_t n, TList **lists, TString *legend)
Int_t nevents[nsamples]
TF1 ** fitfunc