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