]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/vertexingHF/AliAODPidHF.cxx
Speed up
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliAODPidHF.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2006, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  *                                                                        *
5  * Author: The ALICE Off-line Project.                                    *
6  * Contributors are mentioned in the code where appropriate.              *
7  *
8  * Permission to use, copy, modify and distribute this software and its   *
9  * documentation strictly for non-commercial purposes is hereby granted   *
10  * without fee, provided that the above copyright notice appears in all   *
11  * copies and that both the copyright notice and this permission notice   *
12  * appear in the supporting documentation. The authors make no claims     *
13  * about the suitability of this software for any purpose. It is          *
14  * provided "as is" without express or implied warranty.                  *
15  * *************************************************************************/
16
17 //***********************************************************
18 // Class AliAODPidHF
19 // class for PID with AliAODRecoDecayHF
20 // Authors: D. Caffarri caffarri@pd.infn.it, A.Dainese andrea.dainese@pd.infn.it, S. Dash dash@to.infn.it, F. Prino prino@to.infn.it, R. Romita r.romita@gsi.de, Y. Wang yifei@pi0.physi.uni-heidelberg.de P. Antonioli pietro.antonioli@bo.infn.it
21 //***********************************************************
22 #include "AliAODPidHF.h"
23 #include "AliAODPid.h"
24 #include "AliPID.h"
25 #include "AliTPCPIDResponse.h"
26 #include "AliITSPIDResponse.h"
27 #include "AliTOFPIDResponse.h"
28 #include "AliAODpidUtil.h"
29 #include "AliESDtrack.h"
30
31
32 ClassImp(AliAODPidHF)
33
34 //------------------------------
35 AliAODPidHF::AliAODPidHF():
36   AliAODPid(),
37   fnNSigma(5),
38   fnSigma(),
39   fTOFSigma(160.),
40   fnPriors(5),
41   fPriors(),
42   fnPLimit(2),
43   fPLimit(),
44   fAsym(kFALSE),
45   fTPC(kFALSE),
46   fTOF(kFALSE),
47   fITS(kFALSE),
48   fTRD(kFALSE),
49   fMatch(0),
50   fCompat(kFALSE),
51   fMC(kFALSE),
52   fOnePad(kFALSE),
53   fPbPb(kFALSE)
54 {
55  //
56  // Default constructor
57  //
58  fPLimit=new Double_t[fnPLimit];
59  fnSigma=new Double_t[fnNSigma];
60  fPriors=new Double_t[fnPriors];
61
62  for(Int_t i=0;i<fnNSigma;i++){
63   fnSigma[i]=0.;
64  }
65  for(Int_t i=0;i<fnPriors;i++){
66   fPriors[i]=0.;
67  }
68  for(Int_t i=0;i<fnPLimit;i++){
69   fPLimit[i]=0.;
70  }
71
72 }
73 //----------------------
74 AliAODPidHF::~AliAODPidHF()
75 {
76       // destructor
77  //   if(fPLimit) delete fPLimit;
78  //   if(fnSigma)  delete fnSigma;
79  //   if(fPriors)  delete fPriors;
80 }
81 //------------------------
82 AliAODPidHF::AliAODPidHF(const AliAODPidHF& pid) :
83   AliAODPid(pid),
84   fnNSigma(pid.fnNSigma),
85   fnSigma(pid.fnSigma),
86   fTOFSigma(pid.fTOFSigma),
87   fnPriors(pid.fnPriors),
88   fPriors(pid.fPriors),
89   fnPLimit(pid.fnPLimit),
90   fPLimit(pid.fPLimit),
91   fAsym(pid.fAsym),
92   fTPC(pid.fTPC),
93   fTOF(pid.fTOF),
94   fITS(pid.fITS),
95   fTRD(pid.fTRD),
96   fMatch(pid.fMatch),
97   fCompat(pid.fCompat),
98   fMC(pid.fMC),
99   fOnePad(pid.fOnePad),
100   fPbPb(pid.fPbPb)
101   {
102   
103   for(Int_t i=0;i<5;i++){
104     fPriors[i]=pid.fPriors[i];
105   }
106   
107   }
108
109 //----------------------
110 Int_t AliAODPidHF::RawSignalPID(AliAODTrack *track, TString detector) const{
111 // raw PID for single detectors, returns the particle type with smaller sigma
112    Int_t specie=-1;
113    if(detector.Contains("ITS")) return ApplyPidITSRaw(track,specie);
114    if(detector.Contains("TPC")) return ApplyPidTPCRaw(track,specie);
115    if(detector.Contains("TOF")) return ApplyPidTOFRaw(track,specie);
116
117   return specie;
118
119 }
120 //---------------------------
121 Bool_t AliAODPidHF::IsKaonRaw(AliAODTrack *track, TString detector) const{
122 // checks if the track can be a kaon, raw PID applied for single detectors
123  Int_t specie=0;
124
125  if(detector.Contains("ITS")) specie=ApplyPidITSRaw(track,3);
126  if(detector.Contains("TPC")) specie=ApplyPidTPCRaw(track,3);
127  if(detector.Contains("TOF")) specie=ApplyPidTOFRaw(track,3);
128
129  if(specie==3) return kTRUE;
130  return kFALSE;
131 }
132 //---------------------------
133 Bool_t AliAODPidHF::IsPionRaw (AliAODTrack *track, TString detector) const{
134 // checks if the track can be a pion, raw PID applied for single detectors
135
136  Int_t specie=0;
137
138  if(detector.Contains("ITS")) specie=ApplyPidITSRaw(track,2);
139  if(detector.Contains("TPC")) specie=ApplyPidTPCRaw(track,2);
140  if(detector.Contains("TOF")) specie=ApplyPidTOFRaw(track,2);
141
142  if(specie==2) return kTRUE;
143  return kFALSE;
144 }
145 //---------------------------
146 Bool_t AliAODPidHF::IsProtonRaw (AliAODTrack *track, TString detector) const{
147 // checks if the track can be a proton raw PID applied for single detectors
148
149  Int_t specie=0;
150  if(detector.Contains("ITS")) specie=ApplyPidITSRaw(track,4);
151  if(detector.Contains("TPC")) specie=ApplyPidTPCRaw(track,4); 
152  if(detector.Contains("TOF")) specie=ApplyPidTOFRaw(track,4);
153
154  if(specie==4) return kTRUE;
155
156  return kFALSE;
157 }
158 //--------------------------
159 Bool_t AliAODPidHF::IsElectronRaw(AliAODTrack *track, TString detector) const{
160 // checks if the track can be an electron raw PID applied for single detectors
161
162  Int_t specie=-1;
163  if(detector.Contains("ITS")) specie=ApplyPidITSRaw(track,0);
164  if(detector.Contains("TPC")) specie=ApplyPidTPCRaw(track,0);
165  if(detector.Contains("TOF")) specie=ApplyPidTOFRaw(track,0);
166
167  if(specie==0) return kTRUE;
168
169  return kFALSE;
170 }
171 //--------------------------
172 Int_t AliAODPidHF::ApplyPidTPCRaw(AliAODTrack *track,Int_t specie) const{
173 // n-sigma cut, TPC PID
174
175   if(!CheckStatus(track,"TPC")) return 0;
176   AliAODPid *pidObj = track->GetDetPid();
177   
178   Double_t dedx=pidObj->GetTPCsignal();
179   Double_t mom = pidObj->GetTPCmomentum();
180   AliTPCPIDResponse tpcResponse;
181   SetBetheBloch(tpcResponse); 
182
183   Int_t pid=-1;
184   if(specie<0){  // from RawSignalPID : should return the particle specie to wich the de/dx is closer to the bethe-block curve -> performance to be checked
185    Double_t nsigmaMax=fnSigma[0];
186    for(Int_t ipart=0;ipart<5;ipart++){
187     AliPID::EParticleType type=AliPID::EParticleType(ipart);
188     Double_t nsigma = TMath::Abs(tpcResponse.GetNumberOfSigmas(mom,dedx,track->GetTPCNcls(),type));
189     if((nsigma<nsigmaMax) && (nsigma<fnSigma[0])) {
190      pid=ipart;
191      nsigmaMax=nsigma;
192     }
193    }
194   }else{ // asks only for one particle specie
195    AliPID::EParticleType type=AliPID::EParticleType(specie);
196     Double_t nsigma = TMath::Abs(tpcResponse.GetNumberOfSigmas(mom,dedx,track->GetTPCNcls(),type));
197    if (nsigma>fnSigma[0]) {
198     pid=-1; 
199    }else{
200     pid=specie;
201    }
202   }
203
204  return pid;
205
206 }
207 //----------------------------
208 Int_t AliAODPidHF::ApplyPidITSRaw(AliAODTrack *track,Int_t specie) const{
209 // truncated mean, ITS PID
210
211   if(!CheckStatus(track,"ITS")) return 0;
212
213   Double_t mom=track->P();
214   AliAODPid *pidObj = track->GetDetPid();
215
216   Double_t dedx=pidObj->GetITSsignal();
217   UChar_t clumap=track->GetITSClusterMap();
218   Int_t nPointsForPid=0;
219   for(Int_t i=2; i<6; i++){
220    if(clumap&(1<<i)) ++nPointsForPid;
221   }
222
223   Bool_t isSA=kTRUE;
224   if(track->GetStatus() & AliESDtrack::kTPCin) isSA = kFALSE;
225
226   AliITSPIDResponse itsResponse;
227   Int_t pid=-1;
228   if(specie<0){  // from RawSignalPID : should return the particle specie to wich the de/dx is closer to the bethe-block curve -> performance to be checked
229    Double_t nsigmaMax=fnSigma[4];
230    for(Int_t ipart=0;ipart<5;ipart++){
231     AliPID::EParticleType type=AliPID::EParticleType(ipart);
232     Double_t nsigma = TMath::Abs(itsResponse.GetNumberOfSigmas(mom,dedx,type,nPointsForPid,isSA));
233     if((nsigma<nsigmaMax) && (nsigma<fnSigma[4])) {
234      pid=ipart;
235      nsigmaMax=nsigma;
236     }
237    }
238   }else{ // asks only for one particle specie
239    AliPID::EParticleType type=AliPID::EParticleType(specie);
240     Double_t nsigma = TMath::Abs(itsResponse.GetNumberOfSigmas(mom,dedx,type));
241    if (nsigma>fnSigma[4]) {
242     pid=-1; 
243    }else{
244     pid=specie;
245    }
246   }
247  return pid; 
248 }
249 //----------------------------
250 Int_t AliAODPidHF::ApplyPidTOFRaw(AliAODTrack *track,Int_t specie) const{
251 // n-sigma cut, TOF PID
252
253  if(!CheckStatus(track,"TOF")) return 0;
254
255  Double_t time[AliPID::kSPECIESN];
256  Double_t sigmaTOFPid[AliPID::kSPECIES];
257  AliAODPid *pidObj = track->GetDetPid();
258  pidObj->GetIntegratedTimes(time);
259  Double_t sigTOF=pidObj->GetTOFsignal();
260  pidObj->GetTOFpidResolution(sigmaTOFPid);
261
262  Int_t pid=-1;
263
264   if(specie<0){  
265    Double_t sigmaTOFtrack;
266    if (sigmaTOFPid[4]>0) sigmaTOFtrack=sigmaTOFPid[4];
267    else sigmaTOFtrack=fTOFSigma;
268    Double_t nsigmaMax=sigmaTOFtrack*fnSigma[3];
269    for(Int_t ipart=0;ipart<5;ipart++){
270     Double_t nsigma=TMath::Abs(sigTOF-time[ipart]);
271     if (sigmaTOFPid[ipart]>0) sigmaTOFtrack=sigmaTOFPid[ipart]; 
272     else sigmaTOFtrack=fTOFSigma;  // backward compatibility for old AODs
273     if((nsigma<nsigmaMax) && (nsigma<fnSigma[3]*sigmaTOFtrack)) {
274      pid=ipart;
275      nsigmaMax=nsigma;
276     }
277    }
278   }else{ // asks only for one particle specie
279     Double_t nsigma=TMath::Abs(sigTOF-time[specie]);
280     Double_t sigmaTOFtrack;
281     if (sigmaTOFPid[specie]>0) sigmaTOFtrack=sigmaTOFPid[specie]; 
282     else sigmaTOFtrack=fTOFSigma;  // backward compatibility for old AODs
283     if (nsigma>fnSigma[3]*sigmaTOFtrack) {
284       pid=-1; 
285     }else{
286       pid=specie;
287     }
288   }
289  return pid; 
290
291 }
292 //------------------------------
293 void AliAODPidHF::CombinedProbability(AliAODTrack *track,Bool_t *type) const{
294 // combined PID stored inside the AOD track
295
296  const Double_t *pid=track->PID();
297  Float_t max=0.;
298  Int_t k=-1;
299  for (Int_t i=0; i<10; i++) {
300    if (pid[i]>max) {k=i; max=pid[i];}  
301  }
302
303  if(k==2) type[0]=kTRUE;
304  if(k==3) type[1]=kTRUE;
305  if(k==4) type[2]=kTRUE;
306
307  return;
308 }
309 //--------------------
310 void AliAODPidHF::BayesianProbability(AliAODTrack *track,Double_t *pid) const{
311 // bayesian PID for single detectors or combined
312
313   if(fITS && !fTPC && !fTOF) {BayesianProbabilityITS(track,pid);return;}
314   if(fTPC && !fITS && !fTOF) {BayesianProbabilityTPC(track,pid);return;}
315   if(fTOF && !fITS && !fTPC) {BayesianProbabilityTOF(track,pid);return;}
316
317     Double_t probITS[5]={1.,1.,1.,1.,1.};
318     Double_t probTPC[5]={1.,1.,1.,1.,1.};
319     Double_t probTOF[5]={1.,1.,1.,1.,1.};
320     if(fITS) BayesianProbabilityITS(track,probITS);
321     if(fTPC) BayesianProbabilityTPC(track,probTPC);
322     if(fTOF) BayesianProbabilityTOF(track,probTOF);
323     Double_t probTot[5]={0.,0.,0.,0.,0.};
324     for(Int_t i=0;i<5;i++){
325      probTot[i]=probITS[i]*probTPC[i]*probTOF[i];
326     }
327     for(Int_t i2=0;i2<5;i2++){
328      pid[i2]=probTot[i2]*fPriors[i2]/(probTot[0]*fPriors[0]+probTot[1]*fPriors[1]+probTot[2]*fPriors[2]+probTot[3]*fPriors[3]+probTot[4]*fPriors[4]);
329     }
330
331  return;
332
333 }
334 //------------------------------------
335 void AliAODPidHF::BayesianProbabilityITS(AliAODTrack *track,Double_t *prob) const{
336
337 // bayesian PID for ITS
338  AliAODpidUtil pid;
339  Double_t itspid[AliPID::kSPECIES];
340  pid.MakeITSPID(track,itspid);
341  for(Int_t ind=0;ind<AliPID::kSPECIES;ind++){
342   if(fTOF || fTPC || fTRD){
343    prob[ind]=itspid[ind];
344   }else{
345    prob[ind]=itspid[ind]*fPriors[ind]/(itspid[0]*fPriors[0]+itspid[1]*fPriors[1]+itspid[2]*fPriors[2]+itspid[3]*fPriors[3]+itspid[4]*fPriors[4]);
346   }
347  }
348  return;
349
350 }
351 //------------------------------------
352 void AliAODPidHF::BayesianProbabilityTPC(AliAODTrack *track,Double_t *prob) const{
353 // bayesian PID for TPC
354
355  AliAODpidUtil pid;
356  Double_t tpcpid[AliPID::kSPECIES];
357  pid.MakeTPCPID(track,tpcpid);
358  for(Int_t ind=0;ind<AliPID::kSPECIES;ind++){
359   if(fTOF || fITS || fTRD){
360    prob[ind]=tpcpid[ind];
361   }else{
362    prob[ind]=tpcpid[ind]*fPriors[ind]/(tpcpid[0]*fPriors[0]+tpcpid[1]*fPriors[1]+tpcpid[2]*fPriors[2]+tpcpid[3]*fPriors[3]+tpcpid[4]*fPriors[4]);
363  }
364 }
365  return;
366
367 }
368 //------------------------------------
369 void AliAODPidHF::BayesianProbabilityTOF(AliAODTrack *track,Double_t *prob) const{
370 // bayesian PID for TOF
371
372  AliAODpidUtil pid;
373  Double_t tofpid[AliPID::kSPECIES];
374  pid.MakeTOFPID(track,tofpid);
375  for(Int_t ind=0;ind<AliPID::kSPECIES;ind++){
376   if(fTPC || fITS || fTRD){
377    prob[ind]=tofpid[ind];
378   }else{
379   prob[ind]=tofpid[ind]*fPriors[ind]/(tofpid[0]*fPriors[0]+tofpid[1]*fPriors[1]+tofpid[2]*fPriors[2]+tofpid[3]*fPriors[3]+tofpid[4]*fPriors[4]);
380  }
381 }
382  return;
383
384 }
385 //---------------------------------
386 void AliAODPidHF::BayesianProbabilityTRD(AliAODTrack *track,Double_t *prob) const{
387 // bayesian PID for TRD
388
389  AliAODpidUtil pid;
390  Double_t trdpid[AliPID::kSPECIES];
391  pid.MakeTRDPID(track,trdpid);
392  for(Int_t ind=0;ind<AliPID::kSPECIES;ind++){
393   if(fTPC || fITS || fTOF){
394    prob[ind]=trdpid[ind];
395   }else{
396    prob[ind]=trdpid[ind]*fPriors[ind]/(trdpid[0]*fPriors[0]+trdpid[1]*fPriors[1]+trdpid[2]*fPriors[2]+trdpid[3]*fPriors[3]+trdpid[4]*fPriors[4]);
397  }
398 }
399   return;
400
401  }
402 //--------------------------------
403 Bool_t AliAODPidHF::CheckStatus(AliAODTrack *track,TString detectors) const{
404
405 // Quality cuts on the tracks, detector by detector
406
407  if(detectors.Contains("ITS")){
408   if ((track->GetStatus()&AliESDtrack::kITSin)==0) return kFALSE;
409   UChar_t clumap=track->GetITSClusterMap();
410   Int_t nPointsForPid=0;
411   for(Int_t i=2; i<6; i++){
412    if(clumap&(1<<i)) ++nPointsForPid;
413   }
414   if(nPointsForPid<3) return kFALSE;
415  }
416
417  if(detectors.Contains("TPC")){
418    if ((track->GetStatus()&AliESDtrack::kTPCin )==0) return kFALSE;
419    UShort_t nTPCClus=track->GetTPCClusterMap().CountBits();
420    if (nTPCClus<70) return kFALSE;
421  }
422
423  if(detectors.Contains("TOF")){
424    if ((track->GetStatus()&AliESDtrack::kTOFout )==0)    return kFALSE;
425    if ((track->GetStatus()&AliESDtrack::kTIME )==0)     return kFALSE;
426    if ((track->GetStatus()&AliESDtrack::kTOFpid )==0)   return kFALSE;
427    if (!(track->GetStatus()&AliESDtrack::kTOFmismatch)==0)    return kFALSE;
428  }
429
430
431  if(detectors.Contains("TRD")){
432   if ((track->GetStatus()&AliESDtrack::kTRDout )==0)   return kFALSE;
433   AliAODPid *pidObj = track->GetDetPid();
434   Float_t *mom=pidObj->GetTRDmomentum();
435   Int_t ntracklets=0;
436   for(Int_t iPl=0;iPl<6;iPl++){
437    if(mom[iPl]>0.) ntracklets++;
438   }
439    if(ntracklets<4) return kFALSE;
440  }
441
442  return kTRUE;
443 }
444 //--------------------------------------------
445 Bool_t AliAODPidHF::TPCRawAsym(AliAODTrack* track,Int_t specie) const{
446 // TPC nsigma cut PID, different sigmas in different p bins
447
448   if(!CheckStatus(track,"TPC")) return kFALSE;
449   AliAODPid *pidObj = track->GetDetPid();
450   Double_t mom = pidObj->GetTPCmomentum();
451   Double_t dedx=pidObj->GetTPCsignal();
452   
453   AliTPCPIDResponse tpcResponse;
454   SetBetheBloch(tpcResponse); 
455   AliPID::EParticleType type=AliPID::EParticleType(specie);
456   Double_t nsigma = TMath::Abs(tpcResponse.GetNumberOfSigmas(mom,dedx,track->GetTPCNcls(),type)); 
457
458   if(mom<fPLimit[0] && nsigma<fnSigma[0]) return kTRUE;
459   if(mom<fPLimit[1] && mom>fPLimit[0] && nsigma<fnSigma[1]) return kTRUE;
460   if(mom>fPLimit[1] && nsigma<fnSigma[2]) return kTRUE;
461
462  return kFALSE;
463 }
464 //------------------
465 Int_t AliAODPidHF::MatchTPCTOF(AliAODTrack *track,Int_t mode,Int_t specie,Bool_t compat){
466 // combination of the PID info coming from TPC and TOF
467  if(mode==1){
468   //TOF || TPC (a la' Andrea R.)
469  // convention: 
470  // for the single detectors: -1 = kFALSE, 1 = kTRUE, 0 = compatible
471  // the method returns the sum of the response of the 2 detectors
472   if(fTPC && fTOF) {if(!CheckStatus(track,"TPC") && !CheckStatus(track,"TOF")) return 0;}
473
474   
475   Int_t tTPCinfo=0;
476   if(fTPC){
477   if(CheckStatus(track,"TPC")) {
478    if(fAsym) {
479     if(TPCRawAsym(track,specie)) {
480       tTPCinfo=1;
481      }else{
482       tTPCinfo=-1;
483      }
484    }else{
485     if(specie==2 && IsPionRaw(track,"TPC")) {
486      tTPCinfo=1;
487     }else{
488      tTPCinfo=-1;
489     }
490     if(specie==3 && IsKaonRaw(track,"TPC")) {
491      tTPCinfo=1;
492     }else{
493      tTPCinfo=-1;
494     }
495     if(specie==4 && IsProtonRaw(track,"TPC")) {
496      tTPCinfo=1;
497     }else{
498      tTPCinfo=-1;
499     }
500
501    }
502
503
504    if(compat && tTPCinfo<0){
505     Double_t sig0tmp=fnSigma[0];
506     SetSigma(0,3.);
507     if(specie==2 && IsPionRaw(track,"TPC")) tTPCinfo=0;
508     if(specie==3 && IsKaonRaw(track,"TPC")) tTPCinfo=0;
509     if(specie==4 && IsProtonRaw(track,"TPC")) tTPCinfo=0;
510     SetSigma(0,sig0tmp);
511    }
512
513   }
514  }
515
516  Int_t tTOFinfo=0;
517  if(fTOF){
518   if(!CheckStatus(track,"TOF") && fTPC) return tTPCinfo;
519
520   tTOFinfo=-1;
521  
522   if(specie==2 && IsPionRaw(track,"TOF")) tTOFinfo=1;
523   if(specie==3 && IsKaonRaw(track,"TOF")) tTOFinfo=1;
524   if(specie==4 && IsProtonRaw(track,"TOF")) tTOFinfo=1;
525
526   if(compat && tTOFinfo>0){
527    Double_t ptrack=track->P();
528    if(ptrack>1.5) tTOFinfo=0;
529   }
530  }
531
532  if(tTPCinfo+tTOFinfo==0 && fITS){
533   if(!CheckStatus(track,"ITS")) return tTPCinfo+tTOFinfo;
534   Int_t tITSinfo = -1;
535   if(specie==2 && IsPionRaw(track,"TOF")) tITSinfo=1;
536   if(specie==3 && IsKaonRaw(track,"TOF")) tITSinfo=1;
537   if(specie==4 && IsProtonRaw(track,"TOF")) tITSinfo=1;
538   return tITSinfo;
539  }
540
541  return tTPCinfo+tTOFinfo;
542 }
543  if(mode==2){
544   //TPC & TOF (a la' Yifei)
545  // convention: -1 = kFALSE, 1 = kTRUE, 0 = not identified
546   Int_t tTPCinfo=0; 
547   
548   if(fTPC && CheckStatus(track,"TPC")) {
549    tTPCinfo=1;
550    if(fAsym){
551     if(!TPCRawAsym(track,specie)) tTPCinfo=-1;
552    }else{
553     if(specie==2 && !IsPionRaw(track,"TPC")) tTPCinfo=-1;
554     if(specie==3 && !IsKaonRaw(track,"TPC")) tTPCinfo=-1;
555     if(specie==4 && !IsProtonRaw(track,"TPC")) tTPCinfo=-1;
556    }
557   }
558
559   Int_t tTOFinfo=1;
560   if(fTOF){
561    if(fTPC && !CheckStatus(track,"TOF")) return tTPCinfo;
562
563    if(specie==2 && !IsPionRaw(track,"TOF")) tTOFinfo=-1;
564    if(specie==3 && !IsKaonRaw(track,"TOF")) tTOFinfo=-1;
565    if(specie==4 && !IsProtonRaw(track,"TOF")) tTOFinfo=-1;
566   }
567
568  if(tTOFinfo==1 && tTPCinfo==1) return 1;
569
570  if(tTPCinfo+tTOFinfo==0 && fITS){
571   if(!CheckStatus(track,"ITS")) return tTPCinfo+tTOFinfo;
572   Int_t tITSinfo = -1;
573   if(specie==2 && IsPionRaw(track,"TOF")) tITSinfo=1;
574   if(specie==3 && IsKaonRaw(track,"TOF")) tITSinfo=1;
575   if(specie==4 && IsProtonRaw(track,"TOF")) tITSinfo=1;
576   return tITSinfo;
577  }
578
579    return -1;
580
581 }
582
583  if(mode==3){
584  //TPC for p<fPLimit[0], TOF for p>=fPLimit[0] (a la' Andrea A.)
585  // convention (temporary): -1 = kFALSE, 1 = kTRUE, 0 = not identified
586   
587   if(fTPC && fTOF) if(!CheckStatus(track,"TPC") && !CheckStatus(track,"TOF")) return 0;
588
589   Double_t ptrack=track->P();
590   
591
592   Int_t tTPCinfo=-1;
593
594    if(ptrack>=fPLimit[0] && ptrack<fPLimit[1] && fTPC) {  
595     if(!CheckStatus(track,"TPC")) return 0;
596     if(fAsym) {
597      if(TPCRawAsym(track,specie)) tTPCinfo=1;
598     }else{
599      if(specie==2 && IsPionRaw(track,"TPC")) tTPCinfo=1;
600      if(specie==3 && IsKaonRaw(track,"TPC")) tTPCinfo=1;
601      if(specie==4 && IsProtonRaw(track,"TPC")) tTPCinfo=1;
602     } 
603     return tTPCinfo;
604    }
605
606    Int_t tTOFinfo=-1;
607    if(ptrack>=fPLimit[1] && fTOF){
608     if(!CheckStatus(track,"TOF")) return 0;
609     if(specie==2 && IsPionRaw(track,"TOF")) tTOFinfo=1;
610     if(specie==3 && IsKaonRaw(track,"TOF")) tTOFinfo=1;
611     if(specie==4 && IsProtonRaw(track,"TOF")) tTOFinfo=1;
612     return tTOFinfo;
613    }
614
615    Int_t tITSinfo=-1;
616    if(ptrack<fPLimit[0] && fITS){
617     if(!CheckStatus(track,"ITS")) return 0;
618     if(specie==2 && IsPionRaw(track,"ITS")) tITSinfo=1;
619     if(specie==3 && IsKaonRaw(track,"ITS")) tITSinfo=1;
620     if(specie==4 && IsProtonRaw(track,"ITS")) tITSinfo=1;
621     return tITSinfo;
622    }
623
624  }
625
626  return -1;
627
628 }
629 //----------------------------------   
630 Int_t AliAODPidHF::MakeRawPid(AliAODTrack *track, Int_t specie){
631 // general method to compute PID
632  if(fMatch>0){
633   return MatchTPCTOF(track,fMatch,specie,fCompat); 
634  }else{
635   if(fTPC && !fTOF && !fITS) {
636    Int_t tTPCres=ApplyPidTPCRaw(track,specie);
637    if(tTPCres==specie){return 1;}else{return tTPCres;};
638   }else{
639    AliError("You should enable just one detector if you don't want to match");
640    return 0;
641   }
642   if(fTOF && !fTPC && !fITS) {
643    Int_t tTOFres=ApplyPidTOFRaw(track,specie); 
644    if(tTOFres==specie){return 1;}else{return tTOFres;};
645   }else{
646    AliError("You should enable just one detector if you don't want to match");
647    return 0;
648   }
649
650   if(fITS && !fTPC && !fTOF) {
651    Int_t tITSres=ApplyPidITSRaw(track,specie);
652    if(tITSres==specie){return 1;}else{return tITSres;};
653   }else{
654    AliError("You should enable just one detector if you don't want to match");
655    return 0;
656   }
657  } 
658   
659 }
660 //--------------------------------------------
661 void AliAODPidHF::SetBetheBloch(AliTPCPIDResponse tpcResp) const{
662
663  Double_t alephParameters[5];
664  if(fMC){
665   alephParameters[0] = 2.15898e+00/50.;
666   alephParameters[1] = 1.75295e+01;
667   alephParameters[2] = 3.40030e-09;
668   alephParameters[3] = 1.96178e+00;
669   alephParameters[4] = 3.91720e+00;
670
671  }else{
672
673   if(fOnePad) {
674
675    alephParameters[0] =1.34490e+00/50; 
676    alephParameters[1] = 2.69455e+01; 
677    alephParameters[2] = TMath::Exp(-2.97552+01); 
678    alephParameters[3] = 2.35339e+00; 
679    alephParameters[4] = 5.98079e+00;
680
681   } else if(fPbPb) {
682
683    alephParameters[0] = 1.25202/50.; 
684    alephParameters[1] = 2.74992e+01; 
685    alephParameters[2] = TMath::Exp(-3.31517e+01); 
686    alephParameters[3] = 2.46246; 
687    alephParameters[4] = 6.78938;
688
689   } else {
690     alephParameters[0] = 0.0283086/0.97;
691     alephParameters[1] = 2.63394e+01;
692     alephParameters[2] = 5.04114e-11;
693     alephParameters[3] = 2.12543e+00;
694     alephParameters[4] = 4.88663e+00;
695
696   }
697
698  }
699
700  tpcResp.SetBetheBlochParameters(alephParameters[0],alephParameters[1],alephParameters[2],alephParameters[3],alephParameters[4]);
701
702
703  return;
704
705 }
706 //-----------------------
707 Bool_t AliAODPidHF::IsTOFPiKexcluded(AliAODTrack *track,Double_t nsigmaK){
708
709
710  if(!CheckStatus(track,"TOF")) return 0;
711
712   Double_t time[AliPID::kSPECIESN];
713   Double_t sigmaTOFPid[AliPID::kSPECIES];
714   AliAODPid *pidObj = track->GetDetPid();
715   pidObj->GetIntegratedTimes(time);
716   Double_t sigTOF=pidObj->GetTOFsignal();
717   pidObj->GetTOFpidResolution(sigmaTOFPid);
718   Double_t sigmaTOFtrack;
719   if (sigmaTOFPid[3]>0) sigmaTOFtrack=sigmaTOFPid[3];
720   else sigmaTOFtrack=fTOFSigma;  // backward compatibility for old AODs
721   
722   if((sigTOF-time[3])>nsigmaK*sigmaTOFtrack)return kTRUE;// K, Pi excluded (->LIKELY A PROTON)
723   
724   return kFALSE;
725
726 }
727