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