Overwrite Charge() to patch a bug in AliAnalysisVertexingHF (now fixed) (Francesco...
[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
17//***********************************************************
18// Class AliAODPidHF
19// class for PID with AliAODRecoDecayHF
20// Authors: D. Caffarri caffarri@bo.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
21//***********************************************************
22#include "AliAODPidHF.h"
23#include "AliAODPid.h"
24#include "AliAODTrack.h"
25#include "AliPID.h"
26#include "AliTPCPIDResponse.h"
27#include "AliITSPIDResponse.h"
28#include "AliTOFPIDResponse.h"
29#include "AliAODpidUtil.h"
f9e3cf8e 30#include "AliESDtrack.h"
7ce8802c 31
32
33ClassImp(AliAODPidHF)
34
35//------------------------------
36AliAODPidHF::AliAODPidHF():
37 fSigma(3.),
38 fPriors()
39{
40 //
41 // Default constructor
42 //
43
44}
45//----------------------
46AliAODPidHF::~AliAODPidHF()
47{
48 // destructor
49}
50//------------------------
51AliAODPidHF::AliAODPidHF(const AliAODPidHF& pid) :
52 AliAODPid(pid),
53 fSigma(pid.fSigma),
54 fPriors(pid.fPriors)
55 {
56
57 for(Int_t i=0;i<5;i++){
58 fPriors[i]=pid.fPriors[i];
59 }
60
61 }
62
63//----------------------
64Int_t AliAODPidHF::RawSignalPID(AliAODTrack *track, TString detector){
65
f9e3cf8e 66 Int_t specie=-1;
67 if(detector.Contains("ITS")) return ApplyPidITSRaw(track,specie);
68 if(detector.Contains("TPC")) return ApplyPidTPCRaw(track,specie);
69 if(detector.Contains("TOF")) return ApplyPidTOFRaw(track,specie);
7ce8802c 70
f9e3cf8e 71 return specie;
7ce8802c 72
73}
74//---------------------------
75Bool_t AliAODPidHF::IsKaonRaw (AliAODTrack *track, TString detector){
76
77 Int_t specie=0;
78
79 if(detector.Contains("ITS")) specie=ApplyPidITSRaw(track,3);
80 if(detector.Contains("TPC")) specie=ApplyPidTPCRaw(track,3);
81 if(detector.Contains("TOF")) specie=ApplyPidTOFRaw(track,3);
82
83 if(specie==3) return kTRUE;
84 return kFALSE;
85}
86//---------------------------
87Bool_t AliAODPidHF::IsPionRaw (AliAODTrack *track, TString detector){
88
89 Int_t specie=0;
90
91 if(detector.Contains("ITS")) specie=ApplyPidITSRaw(track,2);
92 if(detector.Contains("TPC")) specie=ApplyPidTPCRaw(track,2);
93 if(detector.Contains("TOF")) specie=ApplyPidTOFRaw(track,2);
94
95 if(specie==2) return kTRUE;
96 return kFALSE;
97}
98//---------------------------
99Bool_t AliAODPidHF::IsProtonRaw (AliAODTrack *track, TString detector){
100
101 Int_t specie=0;
102 if(detector.Contains("ITS")) specie=ApplyPidITSRaw(track,4);
103 if(detector.Contains("TPC")) specie=ApplyPidTPCRaw(track,4);
104 if(detector.Contains("TOF")) specie=ApplyPidTOFRaw(track,4);
105
106 if(specie==4) return kTRUE;
107
108 return kFALSE;
109}
f9e3cf8e 110//--------------------------
111Bool_t AliAODPidHF::IsElectronRaw (AliAODTrack *track, TString detector){
112
113 Int_t specie=-1;
114 if(detector.Contains("ITS")) specie=ApplyPidITSRaw(track,0);
115 if(detector.Contains("TPC")) specie=ApplyPidTPCRaw(track,0);
116 if(detector.Contains("TOF")) specie=ApplyPidTOFRaw(track,0);
117
118 if(specie==0) return kTRUE;
119
120 return kFALSE;
121}
122//--------------------------
7ce8802c 123Int_t AliAODPidHF::ApplyPidTPCRaw(AliAODTrack *track,Int_t specie){
124
f9e3cf8e 125 if(!CheckStatus(track,"TPC")) return -1;
7ce8802c 126 AliAODPid *pidObj = track->GetDetPid();
127
128 Double_t dedx=pidObj->GetTPCsignal();
129 Double_t mom = pidObj->GetTPCmomentum();
130 AliTPCPIDResponse tpcResponse;
f9e3cf8e 131 Int_t pid=-1;
132 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
7ce8802c 133 Double_t nsigmaMax=fSigma;
f9e3cf8e 134 for(Int_t ipart=0;ipart<5;ipart++){
7ce8802c 135 AliPID::EParticleType type=AliPID::EParticleType(ipart);
f9e3cf8e 136 Double_t nsigma = TMath::Abs(tpcResponse.GetNumberOfSigmas(mom,dedx,track->GetTPCNcls(),type));
7ce8802c 137 if((nsigma<nsigmaMax) && (nsigma<fSigma)) {
138 pid=ipart;
139 nsigmaMax=nsigma;
140 }
141 }
142 }else{ // asks only for one particle specie
143 AliPID::EParticleType type=AliPID::EParticleType(specie);
f9e3cf8e 144 Double_t nsigma = TMath::Abs(tpcResponse.GetNumberOfSigmas(mom,dedx,track->GetTPCNcls(),type));
7ce8802c 145 if (nsigma>fSigma) {
f9e3cf8e 146 pid=-1;
7ce8802c 147 }else{
148 pid=specie;
149 }
150 }
151
152 return pid;
153
154}
155//----------------------------
156Int_t AliAODPidHF::ApplyPidITSRaw(AliAODTrack *track,Int_t specie){
f9e3cf8e 157
158 if(!CheckStatus(track,"ITS")) return -1;
159
7ce8802c 160 Double_t mom=track->P();
161 AliAODPid *pidObj = track->GetDetPid();
162
163 Double_t dedx=pidObj->GetITSsignal();
164 AliITSPIDResponse itsResponse;
f9e3cf8e 165 Int_t pid=-1;
166 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
7ce8802c 167 Double_t nsigmaMax=fSigma;
f9e3cf8e 168 for(Int_t ipart=0;ipart<5;ipart++){
7ce8802c 169 AliPID::EParticleType type=AliPID::EParticleType(ipart);
170 Double_t nsigma = TMath::Abs(itsResponse.GetNumberOfSigmas(mom,dedx,type));
171 if((nsigma<nsigmaMax) && (nsigma<fSigma)) {
172 pid=ipart;
173 nsigmaMax=nsigma;
174 }
175 }
176 }else{ // asks only for one particle specie
177 AliPID::EParticleType type=AliPID::EParticleType(specie);
178 Double_t nsigma = TMath::Abs(itsResponse.GetNumberOfSigmas(mom,dedx,type));
179 if (nsigma>fSigma) {
f9e3cf8e 180 pid=-1;
7ce8802c 181 }else{
182 pid=specie;
183 }
184 }
185 return pid;
186}
187//----------------------------
188Int_t AliAODPidHF::ApplyPidTOFRaw(AliAODTrack *track,Int_t specie){
f9e3cf8e 189
190 if(!CheckStatus(track,"TOF")) return -1;
191
7ce8802c 192 Double_t time[AliPID::kSPECIESN];
193 AliAODPid *pidObj = track->GetDetPid();
194 pidObj->GetIntegratedTimes(time);
195 AliTOFPIDResponse tofResponse;
f9e3cf8e 196 Int_t pid=-1;
7ce8802c 197
f9e3cf8e 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
7ce8802c 199 Double_t nsigmaMax=fSigma;
f9e3cf8e 200 for(Int_t ipart=0;ipart<5;ipart++){
7ce8802c 201 AliPID::EParticleType type=AliPID::EParticleType(ipart);
202 Double_t nsigma = tofResponse.GetExpectedSigma(track->P(),time[type],AliPID::ParticleMass(type));
203 if((nsigma<nsigmaMax) && (nsigma<fSigma)) {
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(tofResponse.GetExpectedSigma(track->P(),time[type],AliPID::ParticleMass(type)));
211 if (nsigma>fSigma) {
f9e3cf8e 212 pid=-1;
7ce8802c 213 }else{
214 pid=specie;
215 }
216 }
217 return pid;
218
219}
220//------------------------------
221void AliAODPidHF::CombinedProbability(AliAODTrack *track,Bool_t *type){
222
223 const Double_t *pid=track->PID();
224 Float_t max=0.;
225 Int_t k=-1;
226 for (Int_t i=0; i<10; i++) {
227 if (pid[i]>max) {k=i; max=pid[i];}
228 }
229
230 if(k==2) type[0]=kTRUE;
231 if(k==3) type[1]=kTRUE;
232 if(k==4) type[2]=kTRUE;
233
234 return;
235}
236//--------------------
237void AliAODPidHF::BayesianProbability(AliAODTrack *track,TString detectors,Double_t *pid){
238
239 if(detectors.Contains("ITS")) {BayesianProbabilityITS(track,pid);return;}
240 if(detectors.Contains("TPC")) {BayesianProbabilityTPC(track,pid);return;}
241 if(detectors.Contains("TOF")) {BayesianProbabilityTOF(track,pid);return;}
242
243 if(detectors.Contains("All")) {
244 Double_t probITS[5]={0.,0.,0.,0.,0.};
245 Double_t probTPC[5]={0.,0.,0.,0.,0.};
246 Double_t probTOF[5]={0.,0.,0.,0.,0.};
247 BayesianProbabilityITS(track,probITS);
248 BayesianProbabilityTPC(track,probTPC);
249 BayesianProbabilityTOF(track,probTOF);
250 Double_t probTot[5]={0.,0.,0.,0.,0.};
251 for(Int_t i=0;i<5;i++){
252 probTot[i]=probITS[i]*probTPC[i]*probTOF[i];
253 }
254 for(Int_t i2=0;i2<5;i2++){
255 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]);
256 }
257 }
258
259 return;
260
261}
262//------------------------------------
263void AliAODPidHF::BayesianProbabilityITS(AliAODTrack *track,Double_t *prob){
264
265 AliAODpidUtil pid;
266 Double_t itspid[AliPID::kSPECIES];
267 pid.MakeITSPID(track,itspid);
268 for(Int_t ind=0;ind<AliPID::kSPECIES;ind++){
269 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]);
270 }
271 return;
272
273}
274//------------------------------------
275void AliAODPidHF::BayesianProbabilityTPC(AliAODTrack *track,Double_t *prob){
276
277 AliAODpidUtil pid;
278 Double_t tpcpid[AliPID::kSPECIES];
279 pid.MakeTPCPID(track,tpcpid);
280 for(Int_t ind=0;ind<AliPID::kSPECIES;ind++){
281 if(tpcpid[ind]>0.) {
282 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]);
283 }else{
284 prob[ind]=0.;
285 }
286 }
287 return;
288
289}
290//------------------------------------
291void AliAODPidHF::BayesianProbabilityTOF(AliAODTrack *track,Double_t *prob){
292
293 AliAODpidUtil pid;
294 Double_t tofpid[AliPID::kSPECIES];
f9e3cf8e 295 //pid.MakeTOFPID(track,tofpid);
7ce8802c 296 for(Int_t ind=0;ind<AliPID::kSPECIES;ind++){
297 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]);
298 }
299 return;
300
301}
f9e3cf8e 302//---------------------------------
303void AliAODPidHF::BayesianProbabilityTRD(AliAODTrack *track,Double_t *prob){
304
305 AliAODpidUtil pid;
306 Double_t trdpid[AliPID::kSPECIES];
307 pid.MakeTRDPID(track,trdpid);
308 for(Int_t ind=0;ind<AliPID::kSPECIES;ind++){
309 if(trdpid[ind]>0.) {
310 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]);
311 }else{
312 prob[ind]=0.;
313 }
314 }
315 return;
316
317 }
318//--------------------------------
319Bool_t AliAODPidHF::CheckStatus(AliAODTrack *track,TString detectors){
320
321
322 if(detectors.Contains("ITS")){
323 if ((track->GetStatus()&AliESDtrack::kITSin)==0) return kFALSE;
324 UChar_t clumap=track->GetITSClusterMap();
325 Int_t nPointsForPid=0;
326 for(Int_t i=2; i<6; i++){
327 if(clumap&(1<<i)) ++nPointsForPid;
328 }
329 if(nPointsForPid<3) return kFALSE;// track not to be used for PID purposes
330 }
331
332 if(detectors.Contains("TPC")){
333 if ((track->GetStatus()&AliESDtrack::kTPCin )==0) return kFALSE;
334 UShort_t nTPCClus=track->GetTPCClusterMap().CountBits();
335 if (nTPCClus<70) return kFALSE;
336 }
337
338 if(detectors.Contains("TOF")){
339 if ((track->GetStatus()&AliESDtrack::kTOFout )==0) return kFALSE;
340 if ((track->GetStatus()&AliESDtrack::kTIME )==0) return kFALSE;
341 if ((track->GetStatus()&AliESDtrack::kTOFpid )==0) return kFALSE;
342 }
343
344
345 if(detectors.Contains("TRD")){
346 if ((track->GetStatus()&AliESDtrack::kTRDout )==0) return kFALSE;
347 AliAODPid *pidObj = track->GetDetPid();
348 Float_t *mom=pidObj->GetTRDmomentum();
349 Int_t ntracklets=0;
350 for(Int_t iPl=0;iPl<6;iPl++){
351 if(mom[iPl]>0.) ntracklets++;
352 }
353 if(ntracklets<4) return kFALSE;
354 }
355
356 return kTRUE;
357}