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