]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFPID.cxx
Updated SDigitizer
[u/mrichter/AliRoot.git] / TOF / AliTOFPID.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 //_________________________________________________________________________
17 // TTask class for TOF PID.
18 // Use case: start root and execute the following macro
19 /*
20 {
21   // Dynamically link some shared libs
22   if (gClassTable->GetID("AliRun") < 0) {
23     gROOT->LoadMacro("loadlibs.C");
24     loadlibs();
25   }
26   // create an instance of the AliTOFPID class
27   // You have to pass the ntuple and cuts filenames
28  AliTOFPID* tofpid=new AliTOFPID("ntuple.root","cuts.root");
29
30  // option "pp" for pp events (it includes also electron in the analysis)
31  // option "visual" to shows interactively histos
32  // option "asC" or "asEPS" to save canvas in the current dir in .C or .eps format
33
34  // make a choice: uncomment one of these lines
35  // tofpid->Exec("pp","visual","asC");
36  // tofpid->Exec("pp","novisual","asC");
37  // tofpid->Exec("Pb-Pb","visual","asC");
38  // tofpid->Exec("pp","visual","asC");
39  // tofpid->Exec("pp","novisual","asEPS");
40 }
41 */
42 //
43 //
44 //
45 //
46 //
47 //
48 // 
49 //
50 //-- Authors: B. Zagreev , F. Pierella
51 //////////////////////////////////////////////////////////////////////////////
52
53
54 #include "TROOT.h"
55 #include "TStyle.h"
56 #include "TTask.h"
57 #include "TTree.h"
58 #include "TSystem.h"
59 #include "TFile.h"
60 #include "TCanvas.h"
61 #include "TPad.h"
62 #include "TText.h"
63 #include "TLine.h"
64 #include "TPaveLabel.h"
65 #include "TPaveText.h"
66 #include "AliConst.h"
67 #include "AliTOFConstants.h"
68 #include "AliTOFPID.h"
69 #include <TClonesArray.h>
70 #include "TFile.h"
71 #include <TF1.h>
72 #include <TF2.h>
73 #include "TTask.h"
74 #include "TTree.h"
75 #include "TSystem.h"
76 #include "TROOT.h"
77 #include "TFolder.h"
78 #include "TNtuple.h"
79 #include "TLeaf.h"
80 #include <stdlib.h>
81 #include <iostream.h>
82 #include <fstream.h>
83
84 ClassImp(AliTOFPID)
85
86 //____________________________________________________________________________ 
87   AliTOFPID::AliTOFPID():TTask("AliTOFPID","") 
88 {
89   // default ctor - set the pointer member vars to zero
90   felectron = 0;
91   fpion     = 0;
92   fkaon     = 0;
93   fproton   = 0;
94   fcut      = 0;
95   fhfile    = 0;
96   fNtuple   = 0;
97   fgen      = 0;
98   foutfileName  = 0;
99 }
100            
101 //____________________________________________________________________________ 
102   AliTOFPID::AliTOFPID(char* headerFile, char *cutsFile, const Option_t* opt):TTask("AliTOFPID","") 
103 {
104   fhfile = TFile::Open(headerFile); // connect file with ntuple
105   fcut = TFile::Open(cutsFile); // connect file for cuts
106   foutfileName=headerFile;
107
108   Init(opt);
109   // add Task to //root/Tasks folder
110   TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ; 
111   roottasks->Add(this) ; 
112 }
113 //____________________________________________________________________________ 
114 void AliTOFPID::Init(const Option_t* opt)
115 {
116   if(strstr(opt,"pp")){ 
117     if(fcut->GetKey("electron")) felectron = (TCutG*)fcut->Get("electron");
118     fcut->Print();
119     if(fcut->GetKey("pion")) fpion = (TCutG*)fcut->Get("pion");
120     fcut->Print();
121   }
122   if(fcut->GetKey("kaon")) fkaon = (TCutG*)fcut->Get("kaon");
123   fcut->Print();
124   if(fcut->GetKey("proton")) fproton = (TCutG*)fcut->Get("proton");
125
126   gFile->ls();
127   fNtuple= (TNtuple*)fhfile->Get("Ntuple"); // get ntuple from file
128   Int_t nvar = fNtuple->GetNvar(); cout <<"N of var.="<< nvar << endl;
129   fNtuple->GetEvent(0);
130
131 }
132
133 //____________________________________________________________________________ 
134   AliTOFPID::~AliTOFPID()
135 {
136   //
137   // dtor (free used memory)
138   //
139
140   if (felectron)
141     {
142       delete felectron;
143       felectron = 0;
144     }
145
146   if (fpion)
147     {
148       delete fpion;
149       fpion = 0;
150     }
151
152   if (fkaon)
153     {
154       delete fkaon;
155       fkaon = 0;
156     }
157
158   if (fproton)
159     {
160       delete fproton;
161       fproton = 0;
162     }
163
164   if (fcut)
165     {
166       delete fcut;
167       fcut = 0;
168     }
169
170
171   if (fhfile)
172     {
173       delete fhfile;
174       fhfile = 0;
175     }
176
177
178   if (fNtuple)
179     {
180       delete fNtuple;
181       fNtuple = 0;
182     }
183
184   if (fgen)
185     {
186       delete fgen;
187       fgen = 0;
188     }
189
190   if (foutfileName)
191     {
192       delete foutfileName;
193       foutfileName = 0;
194     }
195 }
196
197
198 //____________________________________________________________________________
199 void AliTOFPID::Exec(const Option_t *eventType, const Option_t *outputmode, const Option_t *outputsavemode) 
200
201   //
202   // Performs PID for TOF detector
203   // 
204
205   fTask=1;
206   TAxis *xaxis;
207   ////////// Create histograms /////////////////
208   // for electron only in pp case
209   TH1F* eleff=0;
210   TH1F *elcon=0;
211   TH1F *elid=0;
212   TH1F *elall=0;
213
214   if(strstr(eventType,"pp")){
215     eleff = new TH1F("eleff","",10,0,0.6);
216     xaxis=eleff->GetYaxis();
217     xaxis->SetLabelSize(.08);
218     elcon = new TH1F("elcon","",10,0,0.6);
219     xaxis=elcon->GetXaxis();
220     xaxis->SetLabelSize(.09);
221     xaxis=elcon->GetYaxis();
222     xaxis->SetLabelSize(.08);
223     elid = new TH1F("elid","Identified electrons",10,0,0.6);
224     elall = new TH1F("elall","Electrons",10,0,0.6);
225   }
226
227   // pions
228   TH1F *pit  = new TH1F("pit","",15,0,2.5); //part. with tracks
229   TH1F *pig  = new TH1F("pig","",15,0,2.5); //part. in geometry acceptance
230   TH1F *pieff = new TH1F("pieff","",15,0,2.5); //efficiency
231   xaxis=pieff->GetYaxis();
232   xaxis->SetLabelSize(.08);
233   TH1F *picon = new TH1F("picon","",15,0,2.5); //contamination
234   xaxis=picon->GetXaxis();
235   xaxis->SetLabelSize(.09);
236   xaxis=picon->GetYaxis();
237   xaxis->SetLabelSize(.08);
238   TH1F *piid  = new TH1F("piid","Identified pions",15,0,2.5);
239   TH1F *piall = new TH1F("piall","Pions",15,0,2.5);
240   TH1F *pigen = new TH1F("pigen","Pions",15,0,2.5);
241   xaxis=pigen->GetXaxis();
242   xaxis->SetLabelSize(.09);
243   pigen->SetXTitle("P?t! (GeV/c)");
244   xaxis->SetTitleSize(.09);
245   xaxis=pigen->GetYaxis();
246   xaxis->SetLabelSize(.08);
247   //pigen->SetYTitle("1/P?t!dN/dP?t! (GeV/c)^-2!");
248   xaxis->SetTitleSize(.09);
249
250   // kaons
251   TH1F *kat  = new TH1F("kat","",15,0,2.5);
252   TH1F *kag  = new TH1F("kag","",15,0,2.5);
253   TH1F *kaeff = new TH1F("kaeff","",15,0,2.5);
254   xaxis=kaeff->GetYaxis();
255   xaxis->SetLabelSize(.08);
256   TH1F *kacon = new TH1F("kacon","",15,0,2.5);
257   xaxis=kacon->GetXaxis();
258   xaxis->SetLabelSize(.09);
259   xaxis=kacon->GetYaxis();
260   xaxis->SetLabelSize(.08);
261   TH1F *kaid  = new TH1F("kaid","Identified kaons",15,0,2.5);
262   TH1F *kaall = new TH1F("kaall","Kaons",15,0,2.5);
263   TH1F *kagen = new TH1F("kagen","Kaons",15,0,2.5);
264   xaxis=kagen->GetXaxis();
265   xaxis->SetLabelSize(.09);
266   kagen->SetXTitle("P?t! (GeV/c)");
267   xaxis->SetTitleSize(.09);
268   xaxis=kagen->GetYaxis();
269   xaxis->SetLabelSize(.08);
270   //kagen->SetYTitle("1/P?t!dN/dP?t! (GeV/c)^-2!");
271   xaxis->SetTitleSize(.09);
272
273   // protons
274   TH1F *prt  = new TH1F("prt","",15,0,4.4);
275   TH1F *prg  = new TH1F("prg","",15,0,4.4);
276   TH1F *preff = new TH1F("preff","",15,0,4.4);
277   xaxis=preff->GetYaxis();
278   xaxis->SetLabelSize(.08);
279   TH1F *prcon = new TH1F("prcon","",15,0,4.4);
280   xaxis=prcon->GetXaxis();
281   xaxis->SetLabelSize(.09);
282   xaxis=prcon->GetYaxis();
283   xaxis->SetLabelSize(.08);
284   TH1F *prid  = new TH1F("prid","Identified protons",15,0,4.4);
285   TH1F *prall = new TH1F("prall","Protons",15,0,4.4);
286   TH1F *prgen = new TH1F("prgen","Protons",15,0,4.4);
287   xaxis=prgen->GetXaxis();
288   xaxis->SetLabelSize(.09);
289   prgen->SetXTitle("P?t! (GeV/c)");
290   xaxis->SetTitleSize(.09);
291   xaxis=prgen->GetYaxis();
292   xaxis->SetLabelSize(.08);
293   //prgen->SetYTitle("1/P?t!dN/dP?t! (GeV/c)^-2!");
294   xaxis->SetTitleSize(.09);
295
296   // 2-D histos (extrapolated mass vs momentum)
297   TH2F* hel=0;
298   if(strstr(eventType,"pp")){
299     hel = new TH2F("hel","",1000,-.2,1.2,1000,-4.2,0.);
300     hel->SetXTitle("Mass (GeV/c^{2})");
301     hel->SetYTitle("Momentum (GeV/c)");
302   }
303   TH2F *hpi = new TH2F("hpi","",1000,-.2,1.2,1000,-4.2,0.);
304   hpi->SetXTitle("Mass (GeV/c^{2})");
305   hpi->SetYTitle("Momentum (GeV/c)");
306   TH2F *hka = new TH2F("hka","",1000,-.2,1.2,1000,-4.2,0.);
307   hka->SetXTitle("Mass (GeV/c^{2})");
308   hka->SetYTitle("Momentum (GeV/c)");
309   TH2F *hpr = new TH2F("hpr","",1000,-.2,1.2,1000,-4.2,0.);
310   hpr->SetXTitle("Mass (GeV/c^{2})");
311   hpr->SetYTitle("Momentum (GeV/c)");
312   
313
314   fhfile->cd();
315   Int_t nparticles = (Int_t)fNtuple->GetEntries();
316   cout << " Number of nparticles =" << nparticles << endl;
317   if (nparticles <= 0) return;
318
319   Float_t ka=0, pi=0, pr=0, kaal=0, pial=0, pral=0;
320   Float_t pitrack=0, pimag=0, pigeom=0;
321   Float_t katrack=0, kamag=0, kageom=0;
322   Float_t prtrack=0, prmag=0, prgeom=0;
323   Float_t pif=0, kaf=0, prf=0, pin=0, kan=0, prn=0;
324   Float_t px, py, pz, x, y, z, pdgcode, mass;
325   Int_t event, matc, imam;
326   Int_t indexOfFile=0, numfile=0;
327   //////// Loop over tracks (particles)///////////////////////
328   
329   for (Int_t i=0; i < nparticles; i++) {
330     fNtuple->GetEvent(i);
331     event=fNtuple->GetLeaf("event")->GetValue();
332     pdgcode=fNtuple->GetLeaf("ipart")->GetValue();
333     mass=fNtuple->GetLeaf("mext")->GetValue(0);
334     matc=fNtuple->GetLeaf("matc")->GetValue(0);
335     imam=fNtuple->GetLeaf("imam")->GetValue(0);
336     px=fNtuple->GetLeaf("pxvtx")->GetValue(0);
337     py=fNtuple->GetLeaf("pyvtx")->GetValue(0);
338     pz=fNtuple->GetLeaf("pzvtx")->GetValue(0);
339     x=fNtuple->GetLeaf("xvtx")->GetValue(0);
340     y=fNtuple->GetLeaf("yvtx")->GetValue(0);
341     z=fNtuple->GetLeaf("zvtx")->GetValue(0);
342     Float_t pvtx=TMath::Sqrt(px*px+py*py+pz*pz);
343     Float_t ptvtx=TMath::Sqrt(px*px+py*py);
344     Float_t mt=0.;
345     Int_t abspdgcode=TMath::Abs(pdgcode);
346     switch(abspdgcode){
347     case 321:
348       mt=TMath::Sqrt(AliTOFConstants::fgkKaonMass*AliTOFConstants::fgkKaonMass+px*px+py*py);
349       break;
350     case 2212:
351       mt=TMath::Sqrt(AliTOFConstants::fgkProtonMass*AliTOFConstants::fgkProtonMass+px*px+py*py);
352       break;
353     case 11:
354       mt=TMath::Sqrt(AliTOFConstants::fgkElectronMass*AliTOFConstants::fgkElectronMass+px*px+py*py);
355       break;
356     default:
357       mt=TMath::Sqrt(AliTOFConstants::fgkPionMass*AliTOFConstants::fgkPionMass+px*px+py*py);
358       break;
359     }
360
361     if (imam == 0 && pz !=0 && TMath::ATan(TMath::Abs(ptvtx/pz))>TMath::Pi()*45./180.)
362       {//only primary +/-45  
363         if (fkaon->IsInside(mass,-pvtx) && matc>2) {
364           ka++;
365           if (fTask!=2) kaid->Fill(pvtx); else {kaid->Fill(ptvtx);}
366           if (TMath::Abs(pdgcode)==321) {kaf++; kaeff->Fill(pvtx);} else {kan++; kacon->Fill(pvtx);}
367         } else if (fproton->IsInside(mass,-pvtx) && matc>1) {
368           pr++;
369           if (fTask!=2) prid->Fill(pvtx); else 
370             {prid->Fill(ptvtx);}
371           if (TMath::Abs(pdgcode)==2212) {prf++; preff->Fill(pvtx);} else {prn++; prcon->Fill(pvtx);}
372         } else  if (strstr(eventType,"pp") && felectron->IsInside(mass,-pvtx) && matc>2) {elid->Fill(pvtx);
373         if (strstr(eventType,"pp") && TMath::Abs(pdgcode)==11) eleff->Fill(pvtx); else elcon->Fill(pvtx);
374         } else if (matc>0) {
375           //||matc==-4&&fpion->IsInside(mass,-pvtx)
376           pi++;
377           if (fTask!=2) piid->Fill(pvtx); else {piid->Fill(ptvtx);}
378           if (TMath::Abs(pdgcode)==211) {pif++; pieff->Fill(pvtx);} else {pin++; picon->Fill(pvtx);}
379         }
380
381         //////////////// Normalization histograms ////////////////////
382         if (strstr(eventType,"pp") && TMath::Abs(pdgcode)==11) {
383           if (fTask!=2) elall->Fill(pvtx); else elall->Fill(ptvtx);
384           if (fTask==1) hel->Fill(mass,-pvtx);
385           
386         } else if (TMath::Abs(pdgcode)==211) {
387           pial++;
388           if (matc!=0) {
389             pitrack++; 
390             pit->Fill(pvtx);
391             if (matc!=-1) {
392               pimag++;
393               if (matc>-2 || matc==-4) {
394                 pigeom++;
395                 pig->Fill(pvtx);
396               }
397             }
398           }
399           if (fTask!=2) piall->Fill(pvtx); 
400           else {
401             piall->Fill(ptvtx,1/ptvtx);
402           }
403           if (fTask==1) hpi->Fill(mass,-pvtx); 
404           
405         } else if (TMath::Abs(pdgcode)==321) {
406           kaal++;
407           if (matc!=0) {
408             katrack++;
409             kat->Fill(pvtx);
410             if (matc!=-1) {
411               kamag++;
412               if (matc>-2 || matc==-4) {
413                 kageom++;
414                 kag->Fill(pvtx);
415               }
416             }
417           }
418           if (fTask!=2) kaall->Fill(pvtx); 
419           else {
420             kaall->Fill(ptvtx,1/ptvtx);
421           }
422           if (fTask==1) hka->Fill(mass,-pvtx);
423           
424         } else if (TMath::Abs(pdgcode)==2212) {
425           pral++;
426           if (matc!=0) {
427             prtrack++;
428             prt->Fill(pvtx);
429             if (matc!=-1) {
430               prmag++;
431               if (matc>-2 || matc==-4) {
432                 prgeom++;
433                 prg->Fill(pvtx);
434               }
435             }
436           }
437           if (fTask!=2) prall->Fill(pvtx); 
438           else {
439             prall->Fill(ptvtx,1/ptvtx);
440           }
441           if (fTask==1) hpr->Fill(mass,-pvtx);}
442         
443       }// End of cuts appling
444   }// End of loop over particles
445
446   // display results
447   cout<< "Pions in 45-135 deg.     "<< pial <<" (100%)"<< endl;
448   cout<< "Pions that have track    "<< pitrack/pial*100 <<" %"<<endl;
449   cout<< "Magnetic field           "<< pimag/pial*100 <<" %"<<endl;
450   cout<< "Geometry efficiency      "<< pigeom/pial*100 <<" %"<<endl;
451   cout<< "PID procedure            "<< pif/pial*100 <<" %"<<endl;
452   cout<< "Contamination            "<< pin/pi*100 <<" %"<<endl;
453   cout<<endl;
454   cout<< "Kaons in 45-135 deg.     "<< kaal <<" (100%)"<< endl;
455   cout<< "Kaons that have track    "<< katrack/kaal*100 <<" %"<<endl;
456   cout<< "Magnetic field           "<< kamag/kaal*100 <<" %"<<endl;
457   cout<< "Geometry efficiency      "<< kageom/kaal*100 <<" %"<<endl;
458   cout<< "PID procedure(+decays)   "<< kaf/kaal*100 <<" %"<<endl;
459   cout<< "Contamination            "<< kan/ka*100 <<" %"<<endl;
460   cout<<endl;
461   cout<< "Protons in 45-135 deg.   "<< pral <<" (100%)"<< endl;
462   cout<< "Protons that have track  "<< prtrack/pral*100 <<" %"<<endl;
463   cout<< "Magnetic field           "<< prmag/pral*100 <<" %"<<endl;
464   cout<< "Geometry efficiency      "<< prgeom/pral*100 <<" %"<<endl;
465   cout<< "PID procedure            "<< prf/pral*100 <<" %"<<endl;
466   cout<< "Contamination            "<< prn/pr*100 <<" %"<<endl;
467   cout<<endl;
468   cout<< "All part. in 45-135 deg.  "<< pial+kaal+pral <<" (100%)"<< endl;
469   cout<< "All part. that have track "<< (pitrack+katrack+prtrack)/(pial+kaal+pral)*100 <<" %"<<endl;
470   cout<< "Magnetic field            "<< (pimag+kamag+prmag)/(pial+kaal+pral)*100 <<" %"<<endl;
471   cout<< "Geometry efficiency       "<< (pigeom+kageom+prgeom)/(pial+kaal+pral)*100 <<" %"<<endl;
472   cout<< "PID procedure             "<< (pif+kaf+prf)/(pial+kaal+pral)*100 <<" %"<<endl;
473   cout<< "Contamination             "<< (pin+kan+prn)/(pi+ka+pr)*100 <<" %"<<endl;
474   cout<<endl;
475   
476   TCanvas *pidCanvas=0;
477   TCanvas *momvsmassCanvas=0;
478   TPad  *tp=0;
479   TPad  *pad1=0;
480   TPad  *pad2=0;
481   TPad  *pad3=0;
482   TPad  *pad4=0;
483   TPad  *pad5=0;
484   TPad  *pad6=0;
485   TPad  *pad7=0;
486   TPad  *pad8=0;
487
488   //////////////////////// For fTask 1 ///////////////////////////
489   if (fTask==1) {
490     if (strstr(eventType,"pp")){
491       eleff->Divide(elall);
492     }
493     pieff->Divide(piall);
494     kaeff->Divide(kaall);
495     preff->Divide(prall);
496     pit->Divide(piall);
497     kat->Divide(kaall);
498     prt->Divide(prall);
499     pig->Divide(piall);
500     kag->Divide(kaall);
501     prg->Divide(prall);
502     if (strstr(eventType,"pp")){
503       elcon->Divide(elid);
504     }
505     picon->Divide(piid);
506     kacon->Divide(kaid);
507     prcon->Divide(prid);
508     //Create a canvas, set the view range, show histograms
509     if (indexOfFile==0) {
510       pidCanvas = new TCanvas("pidCanvas","PID ",10,100,800,500);
511       pidCanvas->SetBorderMode(0);
512       pidCanvas->SetBorderSize(0);
513       pidCanvas->SetFillColor(0);
514       pidCanvas->SetFillStyle(0);
515       if (strstr(outputmode,"visual")) pidCanvas->Draw();
516       Float_t pxs=0.25+0.125; //X size of pad
517       Float_t pys=0.5+0.055; //y size of pad
518       tp = new TPad("histo","Histograms",.1,.1,.9,.9);
519       if (strstr(eventType,"Pb-Pb")){
520         //pad1 = new TPad("pad1","electron efficiency",0.,.5-.055,0.+pxs,.5-.055+pys-.00001,0,0,0);
521         pad2 = new TPad("pad2","pion efficiency",0.,0.5-.055,0.+pxs,0.5-.055+pys-.00001,0,0,0);
522         pad3 = new TPad("pad3","kaon efficiency",0.3,0.5-.055,0.3+pxs,0.5-.055+pys-.00001,0,0,0);
523         pad4 = new TPad("pad4","proton efficiency",0.6,0.5-.055,0.6+pxs,0.5-.055+pys-.00001,0,0,0);
524         //pad5 = new TPad("pad5","electron contamination",0.,0.,0.+pxs,0.+pys,0,0,0);
525         pad6 = new TPad("pad6","pion contamination",0.,0.,0.+pxs,0.+pys,0,0,0);
526         pad7 = new TPad("pad7","kaon contamination",.3,0.,0.3+pxs,0.+pys,0,0,0);
527         pad8 = new TPad("pad8","proton contamination",.6,0.,0.6+pxs,0.+pys,0,0,0);
528       }
529
530       if (strstr(eventType,"pp")){
531         pad1 = new TPad("pad1","electron efficiency",0.,.5-.055,0.25+0.045,1.,0,0,0);
532         pad2 = new TPad("pad2","pion efficiency",0.25-0.015,0.5-.055,0.5+0.03,1.,0,0,0);
533         pad3 = new TPad("pad3","kaon efficiency",0.5-0.03,0.5-.055,0.75+0.015,1.,0,0,0);
534         pad4 = new TPad("pad4","proton efficiency",0.75-0.045,0.5-.055,1.,1.,0,0,0);
535         pad5 = new TPad("pad5","electron contamination",0.,0.,.25+.045,.5+.055,0,0,0);
536         pad6 = new TPad("pad6","pion contamination",.25-.015,0.,.5+.03,.5+.055,0,0,0);
537         pad7 = new TPad("pad7","kaon contamination",.5-.03,0.,.75+.015,.5+.055,0,0,0);
538         pad8 = new TPad("pad8","proton contamination",.75-.045,0.,1.,.5+.055,0,0,0);
539       }
540
541       gStyle->SetOptStat(0);
542       tp->SetFillStyle(0);
543       tp->SetFillColor(0);
544       tp->SetBorderSize(0);
545       pidCanvas->cd();
546       TText *text1= new TText(.1,.2,"Contamination              Efficiency"); 
547       text1->SetTextAngle(90);
548       if (strstr(outputmode,"visual")) text1->Draw();
549       //tp->DrawText(.3,.0,"p (GeV/c");
550       pidCanvas->cd();
551       TText *text2= new TText(.8,.0,"p (GeV/c)"); 
552       if (strstr(outputmode,"visual")) {
553         text2->Draw();
554         tp->Draw();
555       }
556     }
557
558
559     if (strstr(eventType,"pp")){
560       pad1->SetFillStyle(0);
561       pad1->SetFillColor(10);
562       tp->cd();
563       if (strstr(outputmode,"visual")) pad1->Draw();
564       pad1->cd();
565       //eleff->SetLineWidth(15);
566       eleff->SetLineWidth(3);
567       eleff->SetMaximum(1.);
568       if (indexOfFile==0) {
569         //eleff->SetFillColor(33);
570         //eleff->SetFillColor(30);
571         //eleff->SetFillColor(0);
572         //eleff->SetLineColor(4);
573         eleff->SetLineColor(1);
574         if (strstr(outputmode,"visual")) eleff->Draw();}
575       else {
576         eleff->SetFillStyle(0);
577         eleff->SetFillColor(30);
578         if (indexOfFile==2) {
579           eleff->SetLineColor(3);
580           eleff->SetLineWidth(3);
581         } else {
582           //eleff->SetLineColor(2);
583           eleff->SetLineColor(1);
584           eleff->SetLineStyle(2);}
585         if (strstr(outputmode,"visual")) eleff->Draw("same");}
586       //   eleff->Fit("pol1");
587       TPaveLabel *ellab = new TPaveLabel(.42,.85,.52,1.05,"e");
588       if (strstr(outputmode,"visual")) ellab->Draw();
589     }
590     
591     pad2->SetFillStyle(0);
592     pad2->SetFillColor(10);
593     tp->cd();
594     if (strstr(outputmode,"visual")) pad2->Draw();
595     pad2->cd();
596     pieff->SetLineWidth(3);
597     pieff->SetMaximum(1.);
598     if (indexOfFile==0) {
599       pieff->SetLineColor(1);
600       if (strstr(outputmode,"visual")) pieff->Draw();
601     } else {
602       pieff->SetFillStyle(0);
603       pieff->SetFillColor(30);
604       if (indexOfFile==1) {
605         pieff->SetLineStyle(2);
606       } else if (indexOfFile==2) {
607         pieff->SetLineStyle(3);
608       } else {
609         pieff->SetLineStyle(4);}
610       if (strstr(outputmode,"visual")) pieff->Draw("same");}
611     TPaveLabel *pilab = new TPaveLabel(1.7,.85,2.2,1.05,"#pi");
612     if (strstr(outputmode,"visual")) pilab->Draw();
613     
614     pad3->SetFillStyle(0);
615     pad3->SetFillColor(10);
616     tp->cd();
617     if (strstr(outputmode,"visual")) pad3->Draw();
618     pad3->cd();
619     kaeff->SetLineWidth(3);
620     kaeff->SetMaximum(1.);
621     if (indexOfFile==0) {
622       kaeff->SetLineColor(1);
623       if (strstr(outputmode,"visual")) kaeff->Draw();
624     } else {
625       kaeff->SetFillStyle(0);
626       kaeff->SetFillColor(30);
627       if (indexOfFile==1) { 
628         kaeff->SetLineStyle(2);
629       } else if (indexOfFile==2) {
630         kaeff->SetLineStyle(3);
631       } else {
632         kaeff->SetLineStyle(4);}
633       if (strstr(outputmode,"visual")) kaeff->Draw("same");}
634     TPaveLabel *kalab = new TPaveLabel(1.7,.85,2.2,1.05,"K");
635     if (strstr(outputmode,"visual")) kalab->Draw();
636     
637     pad4->SetFillStyle(0);
638     pad4->SetFillColor(10);
639     tp->cd();
640     if (strstr(outputmode,"visual")) pad4->Draw();
641     pad4->cd();
642     preff->SetLineWidth(3);
643     preff->SetMaximum(1.);
644     if (indexOfFile==0) {
645       preff->SetLineColor(1);
646       if (strstr(outputmode,"visual")) preff->Draw();
647     } else {
648       preff->SetFillStyle(0);
649       preff->SetFillColor(30);
650       if (indexOfFile==1) {
651         preff->SetLineStyle(2);
652       } else if (indexOfFile==2) {
653         preff->SetLineStyle(3);
654       } else {
655         preff->SetLineStyle(4);}
656       if (strstr(outputmode,"visual")) preff->Draw("same");}
657     TPaveLabel *prlab = new TPaveLabel(3.2,.85,4.1,1.05,"p");
658     if (strstr(outputmode,"visual")) prlab->Draw();
659
660     if (strstr(eventType,"pp")){
661       pad5->SetFillStyle(0);
662       pad5->SetFillColor(10);
663       tp->cd();
664       if (strstr(outputmode,"visual")) pad5->Draw();
665       pad5->cd();
666       //elcon->SetLineWidth(5);
667       elcon->SetLineWidth(3);
668       elcon->SetMaximum(1.);
669       if (indexOfFile==0) {
670         //elcon->SetFillColor(33);
671         //elcon->SetFillColor(30);
672         //elcon->SetLineColor(4);
673         elcon->SetLineColor(1);
674         if (strstr(outputmode,"visual")) elcon->Draw();}
675       else {
676         elcon->SetFillStyle(4000);
677         elcon->SetFillColor(30);
678         if (indexOfFile==2) {
679           elcon->SetLineColor(3);
680           elcon->SetLineWidth(3);
681         } else {
682           elcon->SetLineColor(2);
683           elcon->SetLineStyle(2);}
684         if (strstr(outputmode,"visual")) elcon->Draw("same");}
685     }
686
687
688     pad6->SetFillStyle(0);
689     pad6->SetFillColor(10);
690     tp->cd();
691     if (strstr(outputmode,"visual")) pad6->Draw();
692     pad6->cd();
693     picon->SetLineWidth(3);
694     picon->SetMaximum(1.);
695     if (indexOfFile==0) {
696       picon->SetLineColor(1);
697       if (strstr(outputmode,"visual")) picon->Draw();}
698     else {
699       picon->SetFillStyle(0);
700       picon->SetFillColor(30);
701       if (indexOfFile==1) { 
702         picon->SetLineStyle(2);
703       } else if (indexOfFile==2) {
704         picon->SetLineStyle(3);
705       } else {
706         picon->SetLineStyle(4);
707         TLine* line;
708         line = new TLine(0.2,0.85,0.9,0.85);
709         line->SetLineStyle(2);
710         line->SetLineWidth(1);
711         if (strstr(outputmode,"visual")) line->Draw();
712         line = new TLine(0.2,0.65,0.9,0.65);
713         line->SetLineWidth(2);
714         if (strstr(outputmode,"visual")) line->Draw();
715         line = new TLine(0.2,0.45,0.9,0.45);
716         line->SetLineStyle(3);
717         line->SetLineWidth(1);
718         if (strstr(outputmode,"visual")) line->Draw();
719         line = new TLine(0.2,0.25,0.9,0.25);
720         line->SetLineStyle(4);
721         line->SetLineWidth(1);
722         if (strstr(outputmode,"visual")) line->Draw();
723         TPaveLabel *pl = new TPaveLabel(1.1,0.8,1.9,0.9,"100 ps","br");
724         pl->SetFillColor(18);
725         pl->SetTextSize(0.99);
726         if (strstr(outputmode,"visual")) pl->Draw();
727         pl = new TPaveLabel(1.1,0.6,1.9,0.7,"150 ps","br");
728         pl->SetFillColor(18);
729         pl->SetTextSize(0.99);
730         if (strstr(outputmode,"visual")) pl->Draw();
731         pl = new TPaveLabel(1.1,0.4,1.9,0.5,"200 ps","br");
732         pl->SetFillColor(18);
733         pl->SetTextSize(0.99);
734         if (strstr(outputmode,"visual")) pl->Draw();
735         pl = new TPaveLabel(1.1,0.2,1.9,0.3,"300 ps","br");
736         pl->SetFillColor(18);
737         pl->SetTextSize(0.99);
738         if (strstr(outputmode,"visual")) pl->Draw();
739       }
740       if (strstr(outputmode,"visual")) picon->Draw("same");}
741     
742     pad7->SetFillStyle(0);
743     pad7->SetFillColor(10);
744     tp->cd();
745     if (strstr(outputmode,"visual")) pad7->Draw();
746     pad7->cd();
747     kacon->SetLineWidth(3);
748     kacon->SetMaximum(1.);
749     if (indexOfFile==0) {
750       kacon->SetLineColor(1);
751       if (strstr(outputmode,"visual")) kacon->Draw();}
752     else {
753       kacon->SetFillStyle(0);
754       kacon->SetFillColor(30);
755       if (indexOfFile==1) {
756         kacon->SetLineStyle(2);
757       } else if (indexOfFile==2) {
758         kacon->SetLineStyle(3);
759       } else {
760         kacon->SetLineStyle(4);}
761       if (strstr(outputmode,"visual")) kacon->Draw("same");}
762     
763     pad8->SetFillStyle(0);
764     pad8->SetFillColor(10);
765     tp->cd();
766     if (strstr(outputmode,"visual")) pad8->Draw();
767     pad8->cd();
768     prcon->SetLineWidth(3);
769     prcon->SetMaximum(1.);
770     if (indexOfFile==0) {
771       prcon->SetLineColor(1);
772       if (strstr(outputmode,"visual")) prcon->Draw();}
773     else {
774       prcon->SetFillStyle(0);
775       prcon->SetFillColor(30);
776       if (indexOfFile==1) {
777         prcon->SetLineStyle(2);
778       } else if (indexOfFile==2) {
779         prcon->SetLineStyle(3);
780       } else {
781         prcon->SetLineStyle(4);}
782       if (strstr(outputmode,"visual")) prcon->Draw("same");}
783     
784     if (indexOfFile==0) {
785       momvsmassCanvas = new TCanvas("momvsmassCanvas","Momentum vs mass disribution",500,10,700,700);
786       momvsmassCanvas->SetFillColor(0);
787       momvsmassCanvas->SetBorderMode(0);
788       gPad->SetFillStyle(0);
789       gPad->SetBorderMode(0);
790       gPad->SetFillColor(0);
791       //   gStyle->SetOptStat(11);
792       if (numfile==4) momvsmassCanvas->Divide(1,2,0,0); 
793     } else if (indexOfFile==1 && numfile == 4) {
794       momvsmassCanvas->cd(1);
795       TPaveLabel *pl = new TPaveLabel(-0.0376218,-3.03586,0.0979277,-2.70158,"100 ps","br");
796       pl->SetFillColor(18);
797       pl->SetTextSize(0.99);
798       if (strstr(outputmode,"visual")) pl->Draw();
799     } else if (indexOfFile==3 && numfile == 4) {
800       momvsmassCanvas->cd(2);
801       TPaveLabel *pl = new TPaveLabel(-0.0591866,-3.17077,0.076363,-2.86857,"300 ps","br");
802       pl->SetFillColor(18);
803       pl->SetTextSize(0.99);
804       if (strstr(outputmode,"visual")) pl->Draw();
805     }
806     if (numfile !=4) momvsmassCanvas->cd();
807     if (numfile !=4 || indexOfFile==1 || indexOfFile==3) {
808       //   hpi->PaintStat2(01);
809       hpi->SetMarkerColor(5);
810       if (strstr(outputmode,"visual")) hpi->Draw();
811       if(strstr(eventType,"pp")){
812         hel->SetMarkerColor(2);
813         if (strstr(outputmode,"visual")) hel->Draw("same");
814       }
815       hka->SetMarkerColor(4);
816       if (strstr(outputmode,"visual")) hka->Draw("same");
817       hpr->SetMarkerColor(3);
818       if (strstr(outputmode,"visual")) hpr->Draw("same");
819       if (strstr(outputmode,"visual")) {
820         fkaon->Draw();
821         fproton->Draw();
822         if(strstr(eventType,"pp")){
823           felectron->Draw();
824           fpion->Draw();
825         }
826       }
827       if(strstr(eventType,"pp")){
828         //TPaveText *ep = new TPaveText(-0.05,-0.5,0.05,-0.3);
829         //ep->AddText("e");
830         TPaveLabel *ep = new TPaveLabel(.42,.85,.52,1.05,"e");
831         if (strstr(outputmode,"visual")) ep->Draw();
832       }
833
834       TPaveText *pip = new TPaveText(0.15,-1.0,0.25,-0.8);
835       pip->AddText("#pi");
836       if (strstr(outputmode,"visual")) pip->Draw();
837       TPaveText *kp = new TPaveText(0.5,-2.0,0.6,-1.8);
838       kp->AddText("K");
839       if (strstr(outputmode,"visual")) kp->Draw();
840       TPaveText *prp = new TPaveText(0.9,-2.7,1.0,-2.5);
841       prp->AddText("p");
842       if (strstr(outputmode,"visual")) prp->Draw();
843       //   TText *text2= new TText(.59,.06,"Momentum"); 
844       //   text1->SetTextAngle(90);
845       //   text1->Draw();
846       //pidCanvas->DrawText(.1,.2,"Contamination               Efficiency");
847       momvsmassCanvas->Update();
848       if(strstr(outputsavemode,"asC")) momvsmassCanvas->Print("momvsmassCanvas.C");
849       if(strstr(outputsavemode,"asEPS")) momvsmassCanvas->Print("momvsmassCanvas.eps");
850       pidCanvas->cd();
851       pidCanvas->Update();
852       if(strstr(outputsavemode,"asC")) pidCanvas->Print("pidCanvas.C");
853       if(strstr(outputsavemode,"asEPS")) pidCanvas->Print("pidCanvas.eps");
854       char outFileName[100];
855       strcpy(outFileName,"histos");
856       strcat(outFileName,foutfileName);
857       TFile *houtfile = new TFile(outFileName,"recreate");
858       houtfile->cd();
859       // saving canvas
860       pidCanvas->Write(0,TObject::kOverwrite);
861       momvsmassCanvas->Write(0,TObject::kOverwrite);
862       // saving histos
863       pit->Write(0,TObject::kOverwrite);
864       pig->Write(0,TObject::kOverwrite);
865       pieff->Write(0,TObject::kOverwrite);
866       picon->Write(0,TObject::kOverwrite);
867       piid->Write(0,TObject::kOverwrite);
868       piall->Write(0,TObject::kOverwrite);
869       pigen->Write(0,TObject::kOverwrite);
870       kat->Write(0,TObject::kOverwrite);
871       kag->Write(0,TObject::kOverwrite);
872       kaeff->Write(0,TObject::kOverwrite);
873       kaid->Write(0,TObject::kOverwrite);
874       kaall->Write(0,TObject::kOverwrite);
875       kagen->Write(0,TObject::kOverwrite);
876       kacon->Write(0,TObject::kOverwrite);
877       prt->Write(0,TObject::kOverwrite);
878       prg->Write(0,TObject::kOverwrite);
879       preff->Write(0,TObject::kOverwrite);
880       prcon->Write(0,TObject::kOverwrite);
881       prid->Write(0,TObject::kOverwrite);
882       prall->Write(0,TObject::kOverwrite);
883       prgen->Write(0,TObject::kOverwrite);
884       // 2-D
885       hpi->Write(0,TObject::kOverwrite);
886       hka->Write(0,TObject::kOverwrite);
887       hpr->Write(0,TObject::kOverwrite);
888       // electron histos
889       if (hel && eleff && elcon && elid && elall){
890         hel->Write(0,TObject::kOverwrite);
891         eleff->Write(0,TObject::kOverwrite);
892         elcon->Write(0,TObject::kOverwrite);
893         elid->Write(0,TObject::kOverwrite);
894         elall->Write(0,TObject::kOverwrite);
895       }
896       cout << "file " << houtfile << " has been created" << endl;
897       cout << "it contains PID histos and canvas" << endl;
898       houtfile->Close();
899       houtfile->Write(0,TObject::kOverwrite);
900     }
901   }
902
903   if (strstr(outputmode,"novisual")){
904     // free used memory
905     delete pit  ; pit=0;
906     delete pig  ; pig=0;
907     delete pieff; pieff=0;
908     delete picon; picon=0;
909     delete piid ; piid=0;
910     delete piall; piall=0;
911     delete pigen; pigen=0;
912     delete kat  ; kat=0;
913     delete kag  ; kag=0;
914     delete kaeff; kaeff=0;
915     delete kaid;  kaid=0;
916     delete kaall; kaall=0;
917     delete kagen; kagen=0;
918     delete kacon; kacon=0;
919     delete prt;   prt=0;
920     delete prg;   prg=0;
921     delete preff; preff=0;
922     delete prcon; prcon=0;
923     delete prid;  prid=0;
924     delete prall; prall=0;
925     delete prgen; prgen=0;
926     // 2-D
927     delete hpi; hpi=0;
928     delete hka; hka=0;
929     delete hpr; hpr=0;
930     if (hel){ 
931       delete hel;
932       hel=0;
933     }
934     if (eleff){ 
935       delete eleff;
936       eleff=0;
937     }
938     if (elcon){ 
939       delete elcon;
940       elcon=0;
941     }
942     if (elid){ 
943       delete elid;
944       elid=0;
945     }
946     if (elall){ 
947       delete elall;
948       elall=0;
949     }
950   }
951 }
952
953
954 //__________________________________________________________________
955 Bool_t AliTOFPID::operator==( AliTOFPID const & tofrec)const
956 {
957   // dummy version of Equal operator.
958   // requested by coding conventions
959   return kTRUE;
960
961 }