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