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