2f3aa8075070de355ab889e2c4cd67a4a4cdb6b8
[u/mrichter/AliRoot.git] / PWGCF / FEMTOSCOPY / AliFemtoUser / AliFemtoESDTrackCut.cxx
1 /*
2 ***************************************************************************
3 *
4 * $Id$ 
5 *
6
7 ***************************************************************************
8 *
9
10 *              
11 *
12 ***************************************************************************
13 *
14 * $Log$
15 * Revision 1.3  2007/05/22 09:01:42  akisiel
16 * Add the possibiloity to save cut settings in the ROOT file
17 *
18 * Revision 1.2  2007/05/21 10:38:25  akisiel
19 * More coding rule conformance
20 *
21 * Revision 1.1  2007/05/16 10:25:06  akisiel
22 * Making the directory structure of AliFemtoUser flat. All files go into one common directory
23 *
24 * Revision 1.4  2007/05/03 09:46:10  akisiel
25 * Fixing Effective C++ warnings
26 *
27 * Revision 1.3  2007/04/27 07:25:59  akisiel
28 * Make revisions needed for compilation from the main AliRoot tree
29 *
30 * Revision 1.1.1.1  2007/04/25 15:38:41  panos
31 * Importing the HBT code dir
32 *
33 * Revision 1.4  2007-04-03 16:00:08  mchojnacki
34 * Changes to iprove memory managing
35 *
36 * Revision 1.3  2007/03/13 15:30:03  mchojnacki
37 * adding reader for simulated data
38 *
39 * Revision 1.2  2007/03/08 14:58:03  mchojnacki
40 * adding some alice stuff
41 *
42 * Revision 1.1.1.1  2007/03/07 10:14:49  mchojnacki
43 * First version on CVS
44 *
45 **************************************************************************/
46
47 #include "AliFemtoESDTrackCut.h"
48 #include <cstdio>
49
50 #ifdef __ROOT__ 
51 ClassImp(AliFemtoESDTrackCut)
52 #endif
53
54
55 // electron
56 // 0.13 - 1.8
57 // 0       7.594129e-02    8.256141e-03
58 // 1       -5.535827e-01   8.170825e-02
59 // 2       1.728591e+00    3.104210e-01
60 // 3       -2.827893e+00   5.827802e-01
61 // 4       2.503553e+00    5.736207e-01
62 // 5       -1.125965e+00   2.821170e-01
63 // 6       2.009036e-01    5.438876e-02
64
65 // pion
66 // 0.13 - 2.0
67 // 0       1.063457e+00    8.872043e-03
68 // 1       -4.222208e-01   2.534402e-02
69 // 2       1.042004e-01    1.503945e-02
70
71 // kaon
72 // 0.18 - 2.0
73 // 0       -7.289406e-02   1.686074e-03
74 // 1       4.415666e-01    1.143939e-02
75 // 2       -2.996790e-01   1.840964e-02
76 // 3       6.704652e-02    7.783990e-03
77
78 // proton
79 // 0.26 - 2.0
80 // 0       -3.730200e-02   2.347311e-03
81 // 1       1.163684e-01    1.319316e-02
82 // 2       8.354116e-02    1.997948e-02
83 // 3       -4.608098e-02   8.336400e-03
84
85
86   AliFemtoESDTrackCut::AliFemtoESDTrackCut() :
87     fCharge(0),
88     fLabel(0),
89     fStatus(0),
90     fPIDMethod(knSigma),
91   fNsigmaTPCTOF(kFALSE),
92     fminTPCclsF(0),
93     fminTPCncls(0),
94     fminITScls(0),
95     fMaxITSchiNdof(1000.0),
96     fMaxTPCchiNdof(1000.0),
97     fMaxSigmaToVertex(1000.0),
98     fNTracksPassed(0),
99     fNTracksFailed(0),
100     fRemoveKinks(kFALSE),
101     fRemoveITSFake(kFALSE),
102     fMostProbable(0), 
103     fMaxImpactXY(1000.0),
104   fMinImpactXY(-1000.0),
105     fMaxImpactZ(1000.0),
106     fMaxImpactXYPtOff(1000.0),
107     fMaxImpactXYPtNrm(1000.0),
108     fMaxImpactXYPtPow(1000.0),
109     fMinPforTOFpid(0.0),
110     fMaxPforTOFpid(10000.0),
111     fMinPforTPCpid(0.0),
112     fMaxPforTPCpid(10000.0),
113     fMinPforITSpid(0.0),
114     fMaxPforITSpid(10000.0)
115 {
116   // Default constructor
117   fNTracksPassed = fNTracksFailed = 0;
118   fCharge = 0;  // takes both charges 0
119   fPt[0]=0.0;              fPt[1] = 100.0;//100
120   fRapidity[0]=-2;       fRapidity[1]=2;//-2 2
121   fEta[0]=-2;       fEta[1]=2;//-2 2
122   fPidProbElectron[0]=-1;fPidProbElectron[1]=2;
123   fPidProbPion[0]=-1;    fPidProbPion[1]=2;
124   fPidProbKaon[0]=-1;fPidProbKaon[1]=2;
125   fPidProbProton[0]=-1;fPidProbProton[1]=2;
126   fPidProbMuon[0]=-1;fPidProbMuon[1]=2;
127   for (Int_t i = 0; i < 3; i++)
128     fCutClusterRequirementITS[i] = AliESDtrackCuts::kOff;
129   fLabel=false;
130   fStatus=0;
131   fminTPCclsF=0;
132   fminITScls=0;
133   fPIDMethod=knSigma;
134   fNsigmaTPCTOF=kFALSE;
135 }
136 //------------------------------
137 AliFemtoESDTrackCut::~AliFemtoESDTrackCut(){
138   /* noop */
139 }
140 //------------------------------
141 bool AliFemtoESDTrackCut::Pass(const AliFemtoTrack* track)
142 {
143   //cout<<"AliFemtoESDTrackCut::Pass"<<endl;
144
145   // test the particle and return 
146   // true if it meets all the criteria
147   // false if it doesn't meet at least one of the criteria
148   float tMost[5];
149   
150   //cout<<"AliFemtoESD  cut"<<endl;
151   //cout<<fPidProbPion[0]<<" < pi ="<<track->PidProbPion()<<" <"<<fPidProbPion[1]<<endl;
152   if (fStatus!=0)
153     {
154       //cout<<" status "<<track->Label()<<" "<<track->Flags()<<" "<<track->TPCnclsF()<<" "<<track->ITSncls()<<endl;
155       if ((track->Flags()&fStatus)!=fStatus)
156         {
157           //      cout<<track->Flags()<<" "<<fStatus<<" no go through status"<<endl;
158           return false;
159         }
160         
161     }
162   if (fRemoveKinks) {
163     if ((track->KinkIndex(0)) || (track->KinkIndex(1)) || (track->KinkIndex(2)))
164       return false;
165   }
166   if (fRemoveITSFake) {
167     if (track->ITSncls() < 0)
168       return false;
169   }
170   if (fminTPCclsF>track->TPCnclsF())
171     {
172       //cout<<" No go because TPC Number of ClsF"<<fminTPCclsF<< " "<<track->TPCnclsF()<<endl;
173       return false;
174     }
175   if (fminTPCncls>track->TPCncls())
176     {
177       //cout<<" No go because TPC Number of ClsF"<<fminTPCclsF<< " "<<track->TPCnclsF()<<endl;
178       return false;
179     }
180   if (fminITScls>track->ITSncls())
181     {
182       //cout<<" No go because ITS Number of Cls"<<fminITScls<< " "<<track->ITSncls()<<endl;
183       return false;
184     }
185
186   if (fMaxImpactXY < TMath::Abs(track->ImpactD()))
187     return false;
188
189   if (fMinImpactXY > TMath::Abs(track->ImpactD()))
190     return false;
191
192   if (fMaxImpactZ < TMath::Abs(track->ImpactZ()))
193     return false;
194   
195   if (fMaxSigmaToVertex < track->SigmaToVertex()) {
196     return false;
197   }
198   
199   if (track->ITSncls() > 0) 
200     if ((track->ITSchi2()/track->ITSncls()) > fMaxITSchiNdof) {
201       return false;
202     }
203
204   if (track->TPCncls() > 0)
205     if ((track->TPCchi2()/track->TPCncls()) > fMaxTPCchiNdof) {
206       return false;
207     }
208   //ITS cluster requirenments
209   for (Int_t i = 0; i < 3; i++)
210     if(!CheckITSClusterRequirement(fCutClusterRequirementITS[i], track->HasPointOnITSLayer(i*2), track->HasPointOnITSLayer(i*2+1)))
211       return false;
212
213   if (fLabel)
214     {
215       //cout<<"labels"<<endl;
216       if(track->Label()<0)
217         {
218           fNTracksFailed++;
219           //   cout<<"No Go Through the cut"<<endl;
220           //  cout<<fLabel<<" Label="<<track->Label()<<endl;
221           return false;
222         }    
223     }
224   if (fCharge!=0)
225     {              
226       //cout<<"AliFemtoESD  cut ch "<<endl;
227       //cout<<fCharge<<" Charge="<<track->Charge()<<endl;
228       if (track->Charge()!= fCharge)    
229         {
230           fNTracksFailed++;
231           //  cout<<"No Go Through the cut"<<endl;
232           // cout<<fCharge<<" Charge="<<track->Charge()<<endl;
233           return false;
234         }
235     }
236
237
238   
239
240   Bool_t tTPCPidIn = (track->Flags()&AliFemtoTrack::kTPCpid)>0;
241   Bool_t tITSPidIn = (track->Flags()&AliFemtoTrack::kITSpid)>0;
242   Bool_t tTOFPidIn = (track->Flags()&AliFemtoTrack::kTOFpid)>0;
243   
244   if(fMinPforTOFpid > 0 && track->P().Mag() > fMinPforTOFpid &&
245      track->P().Mag() < fMaxPforTOFpid && !tTOFPidIn)
246     {
247       fNTracksFailed++;
248       return false;
249     }
250   
251   if(fMinPforTPCpid > 0 && track->P().Mag() > fMinPforTPCpid &&
252      track->P().Mag() < fMaxPforTPCpid && !tTPCPidIn)
253     {
254       fNTracksFailed++;
255       return false;
256     }
257   
258   if(fMinPforITSpid > 0 && track->P().Mag() > fMinPforITSpid &&
259      track->P().Mag() < fMaxPforITSpid && !tITSPidIn)
260     {
261       fNTracksFailed++;
262       return false;
263     }
264   
265
266   float tEnergy = ::sqrt(track->P().Mag2()+fMass*fMass);
267   float tRapidity = 0.5*::log((tEnergy+track->P().z())/(tEnergy-track->P().z()));
268   float tPt = ::sqrt((track->P().x())*(track->P().x())+(track->P().y())*(track->P().y()));
269   float tEta = track->P().PseudoRapidity();
270   
271   if (fMaxImpactXYPtOff < 999.0) {
272     if ((fMaxImpactXYPtOff + fMaxImpactXYPtNrm*TMath::Power(tPt, fMaxImpactXYPtPow)) < TMath::Abs(track->ImpactD())) {
273       fNTracksFailed++;
274       return false;
275     }
276   }
277
278   if ((tRapidity<fRapidity[0])||(tRapidity>fRapidity[1]))
279     {
280       fNTracksFailed++;
281       //cout<<"No Go Through the cut"<<endl;   
282       //cout<<fRapidity[0]<<" < Rapidity ="<<tRapidity<<" <"<<fRapidity[1]<<endl;
283       return false;
284     }
285   if ((tEta<fEta[0])||(tEta>fEta[1]))
286     {
287       fNTracksFailed++;
288       //cout<<"No Go Through the cut"<<endl;   
289       //cout<<fEta[0]<<" < Eta ="<<tEta<<" <"<<fEta[1]<<endl;
290       return false;
291     }
292   if ((tPt<fPt[0])||(tPt>fPt[1]))
293     {
294       fNTracksFailed++;
295       //cout<<"No Go Through the cut"<<endl;
296       //cout<<fPt[0]<<" < Pt ="<<Pt<<" <"<<fPt[1]<<endl;
297       return false;
298     }
299
300
301
302
303   //   cout << "Track has pids: " 
304   //        << track->PidProbElectron() << " " 
305   //        << track->PidProbMuon() << " " 
306   //        << track->PidProbPion() << " " 
307   //        << track->PidProbKaon() << " " 
308   //        << track->PidProbProton() << " " 
309   //        << track->PidProbElectron()+track->PidProbMuon()+track->PidProbPion()+track->PidProbKaon()+track->PidProbProton() << endl;
310
311     
312   if ((track->PidProbElectron()<fPidProbElectron[0])||(track->PidProbElectron()>fPidProbElectron[1]))
313     {
314       fNTracksFailed++;
315       //cout<<"No Go Through the cut"<<endl;
316       //cout<<fPidProbElectron[0]<<" < e ="<<track->PidProbElectron()<<" <"<<fPidProbElectron[1]<<endl;
317       return false;
318     }
319   if ((track->PidProbPion()<fPidProbPion[0])||(track->PidProbPion()>fPidProbPion[1]))
320     {
321       fNTracksFailed++;
322       //cout<<"No Go Through the cut"<<endl;
323       //cout<<fPidProbPion[0]<<" < pi ="<<track->PidProbPion()<<" <"<<fPidProbPion[1]<<endl;
324       return false;
325     }
326   if ((track->PidProbKaon()<fPidProbKaon[0])||(track->PidProbKaon()>fPidProbKaon[1]))
327     {
328       fNTracksFailed++;
329       //cout<<"No Go Through the cut"<<endl;
330       //cout<<fPidProbKaon[0]<<" < k ="<<track->PidProbKaon()<<" <"<<fPidProbKaon[1]<<endl;
331       return false;
332     }
333   if ((track->PidProbProton()<fPidProbProton[0])||(track->PidProbProton()>fPidProbProton[1]))
334     {
335       fNTracksFailed++;
336       //cout<<"No Go Through the cut"<<endl;
337       //cout<<fPidProbProton[0]<<" < p  ="<<track->PidProbProton()<<" <"<<fPidProbProton[1]<<endl;
338       return false;
339     }
340   if ((track->PidProbMuon()<fPidProbMuon[0])||(track->PidProbMuon()>fPidProbMuon[1]))
341     {
342       fNTracksFailed++;
343       //cout<<"No Go Through the cut"<<endl;
344       //cout<<fPidProbMuon[0]<<" <  mi="<<track->PidProbMuon()<<" <"<<fPidProbMuon[1]<<endl;
345       return false;
346     }
347
348   if (fMostProbable) {
349   
350     int imost=0;
351     tMost[0] = track->PidProbElectron()*PidFractionElectron(track->P().Mag());
352     tMost[1] = 0.0;
353     tMost[2] = track->PidProbPion()*PidFractionPion(track->P().Mag());
354     tMost[3] = track->PidProbKaon()*PidFractionKaon(track->P().Mag());
355     tMost[4] = track->PidProbProton()*PidFractionProton(track->P().Mag());
356     float ipidmax = 0.0;
357
358
359     //****N Sigma Method****
360         if(fPIDMethod==0){
361           // Looking for pions
362           if (fMostProbable == 2) {
363             if (IsPionNSigma(track->P().Mag(), track->NSigmaTPCPi(), track->NSigmaTOFPi()))
364               imost = 2;
365
366           }
367           else if (fMostProbable == 3) { 
368
369     
370           if (IsKaonNSigma(track->P().Mag(), track->NSigmaTPCK(), track->NSigmaTOFK())){
371                     
372               imost = 3;
373             }
374   
375           }
376       else if (fMostProbable == 4) { // proton nsigma-PID required contour adjusting (in LHC10h)
377         if ( IsProtonNSigma(track->P().Mag(), track->NSigmaTPCP(), track->NSigmaTOFP()) && (TMath::Abs(track->NSigmaTPCP()) < TMath::Abs(track->NSigmaTPCPi())) && (TMath::Abs(track->NSigmaTPCP()) < TMath::Abs(track->NSigmaTPCK())) && (TMath::Abs(track->NSigmaTOFP()) < TMath::Abs(track->NSigmaTOFPi())) && (TMath::Abs(track->NSigmaTOFP()) < TMath::Abs(track->NSigmaTOFK()))
378              // && IsProtonTPCdEdx(track->P().Mag(), track->TPCsignal())
379             )
380               imost = 4;
381           }
382
383         }
384         
385         
386
387     //****Contour Method****
388         if(fPIDMethod==1){
389           for (int ip=0; ip<5; ip++)
390             if (tMost[ip] > ipidmax) { ipidmax = tMost[ip]; imost = ip; };
391
392           // Looking for pions
393           if (fMostProbable == 2) {
394             if (imost == 2) {
395               // Using the TPC to reject non-pions
396               if (!(IsPionTPCdEdx(track->P().Mag(), track->TPCsignal())))
397                 imost = 0;
398               if (0) {
399                 // Using the TOF to reject non-pions
400                 if (track->P().Mag() < 0.6) {
401                   if (tTOFPidIn)
402                     if (!IsPionTOFTime(track->P().Mag(), track->TOFpionTime()))
403                       imost = 0;
404                 }
405                 else {
406                   if (tTOFPidIn) {
407                     if (!IsPionTOFTime(track->P().Mag(), track->TOFpionTime()))
408                       imost = 0;
409                   }
410                   else {
411                     imost = 0;
412                   }
413                 }
414               }
415             }
416           }
417
418           // Looking for kaons
419           else if (fMostProbable == 3) {
420             //       if (imost == 3) {
421             // Using the TPC to reject non-kaons
422             if (track->P().Mag() < 0.6) {
423               if (!(IsKaonTPCdEdx(track->P().Mag(), track->TPCsignal())))
424                 imost = 0;
425               else imost = 3;
426               if (1) {
427                 // Using the TOF to reject non-kaons
428                 if (tTOFPidIn)
429                   if (!IsKaonTOFTime(track->P().Mag(), track->TOFkaonTime()))
430                     imost = 0;
431               }
432             }
433             else {
434               if (1) {
435                 if (tTOFPidIn) {
436                   if (!IsKaonTOFTime(track->P().Mag(), track->TOFkaonTime()))
437                     imost = 0;
438                   else
439                     imost = 3;
440                 }
441                 else {
442                   if (!(IsKaonTPCdEdx(track->P().Mag(), track->TPCsignal())))
443                     imost = 0;
444                   else 
445                     imost = 3;
446                 }
447               }
448             }
449             //       }
450           }
451     
452           // Looking for protons
453           else if (fMostProbable == 4) {
454             //       if (imost == 3) {
455             // Using the TPC to reject non-kaons
456             if (track->P().Mag() < 0.8) {
457               if (!(IsProtonTPCdEdx(track->P().Mag(), track->TPCsignal())))
458                 imost = 0;
459               else imost = 4;
460               if (0) {
461                 // Using the TOF to reject non-kaons
462                 if (tTOFPidIn)
463                   if (!IsKaonTOFTime(track->P().Mag(), track->TOFkaonTime()))
464                     imost = 0;
465               }
466             }
467             else {
468               if (0) {
469                 if (tTOFPidIn) {
470                   if (!IsKaonTOFTime(track->P().Mag(), track->TOFkaonTime()))
471                     imost = 0;
472                   else
473                     imost = 3;
474                 }
475                 else {
476                   if (!(IsKaonTPCdEdx(track->P().Mag(), track->TPCsignal())))
477                     imost = 0;
478                   else 
479                     imost = 3;
480                 }
481               }
482             }
483             //       }
484           }
485         }
486     if (imost != fMostProbable) return false;
487   }
488   
489   //fan
490   //cout<<"****** Go Through the cut ******"<<endl;
491   // cout<<fLabel<<" Label="<<track->Label()<<endl;
492   // cout<<fCharge<<" Charge="<<track->Charge()<<endl;
493   // cout<<fPt[0]<<" < Pt ="<<Pt<<" <"<<fPt[1]<<endl;
494   //cout<<fRapidity[0]<<" < Rapidity ="<<tRapidity<<" <"<<fRapidity[1]<<endl;
495   //cout<<fPidProbElectron[0]<<" <  e="<<track->PidProbElectron()<<" <"<<fPidProbElectron[1]<<endl;
496   //cout<<fPidProbPion[0]<<" <  pi="<<track->PidProbPion()<<" <"<<fPidProbPion[1]<<endl;
497   //cout<<fPidProbKaon[0]<<" <  k="<<track->PidProbKaon()<<" <"<<fPidProbKaon[1]<<endl;
498   //cout<<fPidProbProton[0]<<" <  p="<<track->PidProbProton()<<" <"<<fPidProbProton[1]<<endl;
499   //cout<<fPidProbMuon[0]<<" <  mi="<<track->PidProbMuon()<<" <"<<fPidProbMuon[1]<<endl;
500   fNTracksPassed++ ;
501   return true;
502     
503     
504 }
505 //------------------------------
506 AliFemtoString AliFemtoESDTrackCut::Report()
507 {
508   // Prepare report from the execution
509   string tStemp;
510   char tCtemp[100];
511   snprintf(tCtemp , 100, "Particle mass:\t%E\n",this->Mass());
512   tStemp=tCtemp;
513   snprintf(tCtemp , 100, "Particle charge:\t%d\n",fCharge);
514   tStemp+=tCtemp;
515   snprintf(tCtemp , 100, "Particle pT:\t%E - %E\n",fPt[0],fPt[1]);
516   tStemp+=tCtemp;
517   snprintf(tCtemp , 100, "Particle rapidity:\t%E - %E\n",fRapidity[0],fRapidity[1]);
518   tStemp+=tCtemp; 
519   snprintf(tCtemp , 100, "Particle eta:\t%E - %E\n",fEta[0],fEta[1]);
520   tStemp+=tCtemp;
521   snprintf(tCtemp , 100, "Number of tracks which passed:\t%ld  Number which failed:\t%ld\n",fNTracksPassed,fNTracksFailed);
522   tStemp += tCtemp;
523   AliFemtoString returnThis = tStemp;
524   return returnThis;
525 }
526 TList *AliFemtoESDTrackCut::ListSettings()
527 {
528   // return a list of settings in a writable form
529   TList *tListSetttings = new TList();
530   char buf[200];
531   snprintf(buf, 200, "AliFemtoESDTrackCut.mass=%f", this->Mass());
532   tListSetttings->AddLast(new TObjString(buf));
533
534   snprintf(buf, 200, "AliFemtoESDTrackCut.charge=%i", fCharge);
535   tListSetttings->AddLast(new TObjString(buf));
536   snprintf(buf, 200, "AliFemtoESDTrackCut.pidprobpion.minimum=%f", fPidProbPion[0]);
537   tListSetttings->AddLast(new TObjString(buf));
538   snprintf(buf, 200, "AliFemtoESDTrackCut.pidprobpion.maximum=%f", fPidProbPion[1]);
539   tListSetttings->AddLast(new TObjString(buf));
540   snprintf(buf, 200, "AliFemtoESDTrackCut.pidprobkaon.minimum=%f", fPidProbKaon[0]);
541   tListSetttings->AddLast(new TObjString(buf));
542   snprintf(buf, 200, "AliFemtoESDTrackCut.pidprobkaon.maximum=%f", fPidProbKaon[1]);
543   tListSetttings->AddLast(new TObjString(buf));
544   snprintf(buf, 200, "AliFemtoESDTrackCut.pidprobproton.minimum=%f", fPidProbProton[0]);
545   tListSetttings->AddLast(new TObjString(buf));
546   snprintf(buf, 200, "AliFemtoESDTrackCut.pidprobproton.maximum=%f", fPidProbProton[1]);
547   tListSetttings->AddLast(new TObjString(buf));
548   snprintf(buf, 200, "AliFemtoESDTrackCut.pidprobelectron.minimum=%f", fPidProbElectron[0]);
549   tListSetttings->AddLast(new TObjString(buf));
550   snprintf(buf, 200, "AliFemtoESDTrackCut.pidprobelectron.maximum=%f", fPidProbElectron[1]);
551   tListSetttings->AddLast(new TObjString(buf));
552   snprintf(buf, 200, "AliFemtoESDTrackCut.pidprobMuon.minimum=%f", fPidProbMuon[0]);
553   tListSetttings->AddLast(new TObjString(buf));
554   snprintf(buf, 200, "AliFemtoESDTrackCut.pidprobMuon.maximum=%f", fPidProbMuon[1]);
555   tListSetttings->AddLast(new TObjString(buf));
556   snprintf(buf, 200, "AliFemtoESDTrackCut.minimumtpcclusters=%i", fminTPCclsF);
557   tListSetttings->AddLast(new TObjString(buf));
558   snprintf(buf, 200, "AliFemtoESDTrackCut.minimumitsclusters=%i", fminTPCclsF);
559   tListSetttings->AddLast(new TObjString(buf));
560   snprintf(buf, 200, "AliFemtoESDTrackCut.pt.minimum=%f", fPt[0]);
561   tListSetttings->AddLast(new TObjString(buf));
562   snprintf(buf, 200, "AliFemtoESDTrackCut.pt.maximum=%f", fPt[1]);
563   tListSetttings->AddLast(new TObjString(buf));
564   snprintf(buf, 200, "AliFemtoESDTrackCut.rapidity.minimum=%f", fRapidity[0]);
565   tListSetttings->AddLast(new TObjString(buf));
566   snprintf(buf, 200, "AliFemtoESDTrackCut.rapidity.maximum=%f", fRapidity[1]);
567   tListSetttings->AddLast(new TObjString(buf));
568   snprintf(buf, 200, "AliFemtoESDTrackCut.removekinks=%i", fRemoveKinks);
569   tListSetttings->AddLast(new TObjString(buf));
570   snprintf(buf, 200, "AliFemtoESDTrackCut.maxitschindof=%f", fMaxITSchiNdof);
571   tListSetttings->AddLast(new TObjString(buf));
572   snprintf(buf, 200, "AliFemtoESDTrackCut.maxtpcchindof=%f", fMaxTPCchiNdof);
573   tListSetttings->AddLast(new TObjString(buf));
574   snprintf(buf, 200, "AliFemtoESDTrackCut.maxsigmatovertex=%f", fMaxSigmaToVertex);
575   tListSetttings->AddLast(new TObjString(buf));
576   snprintf(buf, 200, "AliFemtoESDTrackCut.maximpactxy=%f", fMaxImpactXY);
577   tListSetttings->AddLast(new TObjString(buf));
578   snprintf(buf, 200, "AliFemtoESDTrackCut.maximpactz=%f", fMaxImpactZ);
579   tListSetttings->AddLast(new TObjString(buf));
580   if (fMostProbable) {
581     if (fMostProbable == 2)
582       snprintf(buf, 200, "AliFemtoESDTrackCut.mostprobable=%s", "Pion");
583     if (fMostProbable == 3)
584       snprintf(buf, 200, "AliFemtoESDTrackCut.mostprobable=%s", "Kaon");
585     if (fMostProbable == 4)
586       snprintf(buf, 200, "AliFemtoESDTrackCut.mostprobable=%s", "Proton");
587     tListSetttings->AddLast(new TObjString(buf));
588   }
589   return tListSetttings;
590 }
591 void AliFemtoESDTrackCut::SetRemoveKinks(const bool& flag)
592 {
593   fRemoveKinks = flag;
594 }
595                             
596 void AliFemtoESDTrackCut::SetRemoveITSFake(const bool& flag)
597 {
598   fRemoveITSFake = flag;
599 }
600                             
601 // electron
602 // 0.13 - 1.8
603 // 0       7.594129e-02    8.256141e-03
604 // 1       -5.535827e-01   8.170825e-02
605 // 2       1.728591e+00    3.104210e-01
606 // 3       -2.827893e+00   5.827802e-01
607 // 4       2.503553e+00    5.736207e-01
608 // 5       -1.125965e+00   2.821170e-01
609 // 6       2.009036e-01    5.438876e-02
610 float AliFemtoESDTrackCut::PidFractionElectron(float mom) const
611 {
612   // Provide a parameterized fraction of electrons dependent on momentum
613   if (mom<0.13) 
614     return (7.594129e-02 
615             -5.535827e-01*0.13     
616             +1.728591e+00*0.13*0.13    
617             -2.827893e+00*0.13*0.13*0.13 
618             +2.503553e+00*0.13*0.13*0.13*0.13      
619             -1.125965e+00*0.13*0.13*0.13*0.13*0.13      
620             +2.009036e-01*0.13*0.13*0.13*0.13*0.13*0.13);   
621
622   if (mom>1.8)
623     return (7.594129e-02 
624             -5.535827e-01*1.8      
625             +1.728591e+00*1.8*1.8    
626             -2.827893e+00*1.8*1.8*1.8 
627             +2.503553e+00*1.8*1.8*1.8*1.8          
628             -1.125965e+00*1.8*1.8*1.8*1.8*1.8      
629             +2.009036e-01*1.8*1.8*1.8*1.8*1.8*1.8);   
630   return (7.594129e-02 
631           -5.535827e-01*mom        
632           +1.728591e+00*mom*mom    
633           -2.827893e+00*mom*mom*mom 
634           +2.503553e+00*mom*mom*mom*mom    
635           -1.125965e+00*mom*mom*mom*mom*mom      
636           +2.009036e-01*mom*mom*mom*mom*mom*mom);   
637 }
638
639 // pion
640 // 0.13 - 2.0
641 // 0       1.063457e+00    8.872043e-03
642 // 1       -4.222208e-01   2.534402e-02
643 // 2       1.042004e-01    1.503945e-02
644 float AliFemtoESDTrackCut::PidFractionPion(float mom) const
645 {
646   // Provide a parameterized fraction of pions dependent on momentum
647   if (mom<0.13) 
648     return ( 1.063457e+00
649              -4.222208e-01*0.13
650              +1.042004e-01*0.0169);
651   if (mom>2.0) 
652     return ( 1.063457e+00
653              -4.222208e-01*2.0
654              +1.042004e-01*4.0);
655   return ( 1.063457e+00
656            -4.222208e-01*mom
657            +1.042004e-01*mom*mom);
658 }
659
660 // kaon
661 // 0.18 - 2.0
662 // 0       -7.289406e-02   1.686074e-03
663 // 1       4.415666e-01    1.143939e-02
664 // 2       -2.996790e-01   1.840964e-02
665 // 3       6.704652e-02    7.783990e-03
666 float AliFemtoESDTrackCut::PidFractionKaon(float mom) const
667 {
668   // Provide a parameterized fraction of kaons dependent on momentum
669   if (mom<0.18) 
670     return (-7.289406e-02
671             +4.415666e-01*0.18     
672             -2.996790e-01*0.18*0.18    
673             +6.704652e-02*0.18*0.18*0.18);
674   if (mom>2.0) 
675     return (-7.289406e-02
676             +4.415666e-01*2.0      
677             -2.996790e-01*2.0*2.0    
678             +6.704652e-02*2.0*2.0*2.0);
679   return (-7.289406e-02
680           +4.415666e-01*mom        
681           -2.996790e-01*mom*mom    
682           +6.704652e-02*mom*mom*mom);
683 }
684
685 // proton
686 // 0.26 - 2.0
687 // 0       -3.730200e-02   2.347311e-03
688 // 1       1.163684e-01    1.319316e-02
689 // 2       8.354116e-02    1.997948e-02
690 // 3       -4.608098e-02   8.336400e-03
691 float AliFemtoESDTrackCut::PidFractionProton(float mom) const
692 {
693   // Provide a parameterized fraction of protons dependent on momentum
694   if (mom<0.26) return  0.0;
695   if (mom>2.0) 
696     return (-3.730200e-02  
697             +1.163684e-01*2.0         
698             +8.354116e-02*2.0*2.0       
699             -4.608098e-02*2.0*2.0*2.0);
700   return (-3.730200e-02  
701           +1.163684e-01*mom           
702           +8.354116e-02*mom*mom       
703           -4.608098e-02*mom*mom*mom);  
704 }
705
706 void AliFemtoESDTrackCut::SetMomRangeTOFpidIs(const float& minp, const float& maxp)
707 {
708   fMinPforTOFpid = minp;
709   fMaxPforTOFpid = maxp;
710 }
711
712 void AliFemtoESDTrackCut::SetMomRangeTPCpidIs(const float& minp, const float& maxp)
713 {
714   fMinPforTPCpid = minp;
715   fMaxPforTPCpid = maxp;
716 }
717
718 void AliFemtoESDTrackCut::SetMomRangeITSpidIs(const float& minp, const float& maxp)
719 {
720   fMinPforITSpid = minp;
721   fMaxPforITSpid = maxp;
722 }
723
724 bool AliFemtoESDTrackCut::IsPionTPCdEdx(float mom, float dEdx)
725 {
726   //   double a1 = -95.4545, b1 = 86.5455;
727   //   double a2 = 0.0,      b2 = 56.0;
728   double a1 = -343.75,  b1 = 168.125;
729   double a2 = 0.0,      b2 = 65.0;
730
731   if (mom < 0.32) {
732     if (dEdx < a1*mom+b1) return true;
733   }
734   if (dEdx < a2*mom+b2) return true;
735
736   return false;
737 }
738
739 bool AliFemtoESDTrackCut::IsKaonTPCdEdx(float mom, float dEdx)
740 {
741
742 //   double a1 = -547.0; double b1 =  297.0;
743 //   double a2 = -125.0; double b2 =  145.0;
744 //   double a3 = -420.0; double b3 =  357.0;
745 //   double a4 = -110.0; double b4 =  171.0;
746 //   double b5 =   72.0;
747
748 //   if (mom<0.2) return false;
749
750 //   if (mom<0.36) {
751 //     if (dEdx < a1*mom+b1) return false;
752 //     if (dEdx > a3*mom+b3) return false;
753 //   }
754 //   else if (mom<0.6) {
755 //     if (dEdx < a2*mom+b2) return false;
756 //     if (dEdx > a3*mom+b3) return false;
757 //   }
758 //   else if (mom<0.9) {
759 //     if (dEdx > a4*mom+b4) return false;
760 //     if (dEdx <        b5) return false;
761 //   }
762 //   else 
763 //     return false;
764 //   //   else {
765 //   //     if (dEdx > b5) return false;
766 //   //   }
767    
768 //   return true;
769
770   double a1 = -268.896; double b1 =  198.669;
771   double a2 = -49.0012;  double b2 =  88.7214;
772
773   if (mom<0.2) return false;
774
775   if (mom>0.3 && mom<0.5) {
776     if (dEdx < a1*mom+b1) return false;
777   }
778   else  if (mom<1.2) {
779     if (dEdx < a2*mom+b2) return false;
780   }
781
782   return true;
783
784 }
785
786 bool AliFemtoESDTrackCut::IsProtonTPCdEdx(float mom, float dEdx)
787 {
788   double a1 = -1800.0; double b1 =  940.0;
789   double a2 = -500.0;  double b2 =  420.0;
790   double a3 = -216.7;  double b3 =  250.0;
791
792   if (mom<0.2) return false;
793
794   if (mom>0.3 && mom<0.4) {
795     if (dEdx < a1*mom+b1) return false;
796   }
797   else  if (mom<0.6) {
798     if (dEdx < a2*mom+b2) return false;
799   }
800   else  if (mom<0.9) {
801     if (dEdx < a3*mom+b3) return false;
802   }
803
804   return true;
805    
806 }
807
808 bool AliFemtoESDTrackCut::IsPionTOFTime(float mom, float ttof)
809 {
810   double a1 = -427.0; double b1 =  916.0;
811   double a2 =  327.0; double b2 = -888.0;
812   if (mom<0.3) return kFALSE;
813   if (mom>2.0) return kFALSE;
814   if (ttof > a1*mom+b1) return kFALSE;
815   if (ttof < a2*mom+b2) return kFALSE;
816
817   return kTRUE;
818 }
819
820 bool AliFemtoESDTrackCut::IsKaonTOFTime(float mom, float ttof)
821 {
822   double a1 =   000.0; double b1 =  -500.0;
823   double a2 =   000.0; double b2 =   500.0;
824   double a3 =   850.0; double b3 = -1503.0;
825   double a4 = -1637.0; double b4 =  3621.0;
826
827   if (mom<0.3) return kFALSE;
828   if (mom>2.06) return kFALSE;
829   if (mom<1.2) {
830     if (ttof > a2*mom+b2) return kFALSE;
831     if (ttof < a1*mom+b1) return kFALSE;
832   }
833   if (mom<1.9) {
834     if (ttof > a2*mom+b2) return kFALSE;
835     if (ttof < a3*mom+b3) return kFALSE;
836   }
837   if (mom<2.06) {
838     if (ttof > a4*mom+b4) return kFALSE;
839     if (ttof < a3*mom+b3) return kFALSE;
840   }
841   return kTRUE;
842 }
843
844 bool AliFemtoESDTrackCut::IsProtonTOFTime(float mom, float ttof)
845 {
846   double a1 =   000.0; double b1 =  -915.0;
847   double a2 =   000.0; double b2 =   600.0;
848   double a3 =   572.0; double b3 = -1715.0;
849
850   if (mom<0.3) return kFALSE;
851   if (mom>3.0) return kFALSE;
852   if (mom<1.4) {
853     if (ttof > a2*mom+b2) return kFALSE;
854     if (ttof < a1*mom+b1) return kFALSE;
855   }
856   if (mom<3.0) {
857     if (ttof > a2*mom+b2) return kFALSE;
858     if (ttof < a3*mom+b3) return kFALSE;
859   }
860   return kTRUE;
861 }
862
863
864
865
866 bool AliFemtoESDTrackCut::IsKaonTPCdEdxNSigma(float mom, float nsigmaK)
867 {
868 //  cout<<" AliFemtoESDTrackCut::IsKaonTPCdEdxNSigma "<<mom<<" "<<nsigmaK<<endl;
869
870
871   if(mom<0.35 && TMath::Abs(nsigmaK)<5.0)return true;
872   if(mom>=0.35 && mom<0.5 && TMath::Abs(nsigmaK)<3.0)return true; 
873   if(mom>=0.5 && mom<0.7 && TMath::Abs(nsigmaK)<2.0)return true;
874
875   return false;
876 }
877
878 bool AliFemtoESDTrackCut::IsKaonTOFNSigma(float mom, float nsigmaK)
879 {
880 //  cout<<" AliFemtoESDTrackCut::IsKaonTPCdEdxNSigma "<<mom<<" "<<nsigmaK<<endl;
881   //fan
882   //  if(mom<1.5 && TMath::Abs(nsigmaK)<3.0)return true;
883   if(mom>=1.5 && TMath::Abs(nsigmaK)<2.0)return true; 
884   return false;
885 }
886
887 /*
888 bool AliFemtoESDTrackCut::IsKaonNSigma(float mom, float nsigmaTPCK, float nsigmaTOFK)
889 {
890
891
892   if(mom<0.5)
893     {
894           if(TMath::Abs(nsigmaTPCK)<2.0)
895            { 
896            return true;
897            } 
898            else 
899            {
900            return false;
901            }
902     }
903     
904     
905    if(mom>=0.5)
906     {
907          if(TMath::Abs(nsigmaTOFK)<3.0 && TMath::Abs(nsigmaTPCK)<3.0) 
908          {
909          return true;
910          }
911          else
912          {
913          return false;
914          }
915     }
916     
917 //   if(mom>1.5 || mom<0.15)return false;
918     
919
920 }
921
922 */
923
924 //old
925 bool AliFemtoESDTrackCut::IsKaonNSigma(float mom, float nsigmaTPCK, float nsigmaTOFK)
926 {
927
928   if(mom<0.4)
929     {
930       if(nsigmaTOFK<-999.)
931         {
932           if(TMath::Abs(nsigmaTPCK)<2.0) return true;
933         }
934       else if(TMath::Abs(nsigmaTOFK)<3.0 && TMath::Abs(nsigmaTPCK)<3.0) return true;
935     }
936   else if(mom>=0.4 && mom<=0.6)
937     {
938       if(nsigmaTOFK<-999.)
939         {
940           if(TMath::Abs(nsigmaTPCK)<2.0) return true;
941         }
942       else if(TMath::Abs(nsigmaTOFK)<3.0 && TMath::Abs(nsigmaTPCK)<3.0) return true;
943     }
944   else if(nsigmaTOFK<-999.)
945     {
946       return false;
947     }
948   else if(TMath::Abs(nsigmaTOFK)<3.0 && TMath::Abs(nsigmaTPCK)<3.0) return true;
949
950   return false;
951 }
952
953
954
955 bool AliFemtoESDTrackCut::IsPionNSigma(float mom, float nsigmaTPCPi, float nsigmaTOFPi)
956 {
957   if(mom<0.65)
958     {
959       if(nsigmaTOFPi<-999.)
960         {
961           if(mom<0.35 && TMath::Abs(nsigmaTPCPi)<3.0) return true;
962           else if(mom<0.5 && mom>=0.35 && TMath::Abs(nsigmaTPCPi)<3.0) return true;
963           else if(mom>=0.5 && TMath::Abs(nsigmaTPCPi)<2.0) return true;
964           else return false;      
965         }
966       else if(TMath::Abs(nsigmaTOFPi)<3.0 && TMath::Abs(nsigmaTPCPi)<3.0) return true;
967     }
968   else if(nsigmaTOFPi<-999.)
969     {
970       return false;
971     }
972   else if(mom<1.5 && TMath::Abs(nsigmaTOFPi)<3.0 && TMath::Abs(nsigmaTPCPi)<5.0) return true;
973   else if(mom>=1.5 && TMath::Abs(nsigmaTOFPi)<2.0 && TMath::Abs(nsigmaTPCPi)<5.0) return true;
974
975   return false;
976 }
977
978
979 bool AliFemtoESDTrackCut::IsProtonNSigma(float mom, float nsigmaTPCP, float nsigmaTOFP)
980 {
981
982   if (fNsigmaTPCTOF) {
983     if (mom > 0.8) {
984         if (TMath::Hypot( nsigmaTOFP, nsigmaTPCP )/TMath::Sqrt(2) < 3.0)
985             return true;
986         }
987     else {
988         if (TMath::Abs(nsigmaTPCP) < 3.0)
989             return true;
990     }
991   }
992   else {
993     if (mom > 0.8 && mom < 2.5) {
994       if ( TMath::Abs(nsigmaTPCP) < 3.0 && TMath::Abs(nsigmaTOFP) < 3.0)
995         return true;
996     }
997     else if (mom > 2.5) {
998       if ( TMath::Abs(nsigmaTPCP) < 3.0 && TMath::Abs(nsigmaTOFP) < 2.0)
999         return true;
1000     }
1001     else {
1002       if (TMath::Abs(nsigmaTPCP) < 3.0)
1003         return true;
1004     }
1005   }
1006
1007   return false;
1008 }
1009
1010
1011 void AliFemtoESDTrackCut::SetPIDMethod(ReadPIDMethodType newMethod)
1012 {
1013   fPIDMethod = newMethod;
1014 }
1015
1016
1017 void AliFemtoESDTrackCut::SetNsigmaTPCTOF(Bool_t nsigma)
1018 {
1019   fNsigmaTPCTOF = nsigma;
1020 }
1021  
1022 void AliFemtoESDTrackCut::SetClusterRequirementITS(AliESDtrackCuts::Detector det, AliESDtrackCuts::ITSClusterRequirement req) 
1023
1024   fCutClusterRequirementITS[det] = req; 
1025 }
1026
1027 Bool_t AliFemtoESDTrackCut::CheckITSClusterRequirement(AliESDtrackCuts::ITSClusterRequirement req, Bool_t clusterL1, Bool_t clusterL2)
1028 {
1029   // checks if the cluster requirement is fullfilled (in this case: return kTRUE)
1030   
1031   switch (req)
1032     {
1033     case AliESDtrackCuts::kOff:        return kTRUE;
1034     case AliESDtrackCuts::kNone:       return !clusterL1 && !clusterL2;
1035     case AliESDtrackCuts::kAny:        return clusterL1 || clusterL2;
1036     case AliESDtrackCuts::kFirst:      return clusterL1;
1037     case AliESDtrackCuts::kOnlyFirst:  return clusterL1 && !clusterL2;
1038     case AliESDtrackCuts::kSecond:     return clusterL2;
1039     case AliESDtrackCuts::kOnlySecond: return clusterL2 && !clusterL1;
1040     case AliESDtrackCuts::kBoth:       return clusterL1 && clusterL2;
1041   }
1042   
1043   return kFALSE;
1044 }