]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODpidUtil.cxx
63d092d3fa3870db409f43718f9d668a6876b07d
[u/mrichter/AliRoot.git] / STEER / AliAODpidUtil.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id: AliAODpidUtil.cxx 38329 2010-01-17 19:17:24Z hristov $ */
17
18 //-----------------------------------------------------------------
19 //           Implementation of the combined PID class
20 //           For the AOD Class
21 //           containing information on the particle identification
22 //      Origin: Rosa Romita, GSI, r.romita@gsi.de
23 //-----------------------------------------------------------------
24
25 #include "AliLog.h"
26 #include "AliPID.h"
27 #include "AliAODpidUtil.h"
28 #include "AliAODEvent.h"
29 #include "AliAODTrack.h"
30 #include "AliAODPid.h"
31 #include "AliTRDPIDResponse.h"
32 #include "AliESDtrack.h"
33
34 ClassImp(AliAODpidUtil)
35
36   Int_t AliAODpidUtil::MakePID(AliAODTrack *track,Double_t *p) const {
37   //
38   //  Calculate probabilities for all detectors, except if TPConly==kTRUE
39   //  and combine PID
40   //  
41   //   Option TPConly==kTRUE is used during reconstruction, 
42   //  because ITS tracking uses TPC pid
43   //  HMPID and TRD pid are done in detector reconstructors
44   //
45
46   /*
47     Float_t TimeZeroTOF = 0;
48     if (subtractT0) 
49     TimeZeroTOF = event->GetT0();
50   */
51   Int_t ns=AliPID::kSPECIES;
52   Double_t tpcPid[AliPID::kSPECIES];
53   MakeTPCPID(track,tpcPid);
54   Double_t itsPid[AliPID::kSPECIES];
55   Double_t tofPid[AliPID::kSPECIES];
56   Double_t trdPid[AliPID::kSPECIES];
57   MakeITSPID(track,itsPid);
58   MakeTOFPID(track,tofPid);
59   //MakeHMPIDPID(track);
60   MakeTRDPID(track,trdPid);
61   for (Int_t j=0; j<ns; j++) {
62     p[j]=tpcPid[j]*itsPid[j]*tofPid[j]*trdPid[j];
63   }
64
65   return 0;
66 }
67 //_________________________________________________________________________
68 void AliAODpidUtil::MakeTPCPID(AliAODTrack *track,Double_t *p) const
69 {
70   //
71   //  TPC pid using bethe-bloch and gaussian response
72   //
73
74   if ((track->GetStatus()&AliESDtrack::kTPCin )==0) return;
75
76   Double_t mom = track->P();
77   AliAODPid *pidObj = track->GetDetPid();
78   if (pidObj) mom = pidObj->GetTPCmomentum();
79   UShort_t nTPCClus=pidObj->GetTPCsignalN();
80    
81   Double_t dedx = 0.;
82   if (pidObj) dedx = pidObj->GetTPCsignal(); 
83   Bool_t mismatch=kTRUE;
84
85   for (Int_t j=0; j<AliPID::kSPECIES; j++) {
86     AliPID::EParticleType type=AliPID::EParticleType(j);
87     Double_t bethe=fTPCResponse.GetExpectedSignal(mom,type); 
88     Double_t sigma=fTPCResponse.GetExpectedSigma(mom,nTPCClus,type);
89     if (TMath::Abs(dedx-bethe) > fRange*sigma) {
90       p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
91     } else {
92       p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
93       mismatch=kFALSE;
94     }
95
96   }
97
98   if (mismatch)
99     for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1/AliPID::kSPECIES;
100
101
102   return;
103 }
104 //_________________________________________________________________________
105 void AliAODpidUtil::MakeITSPID(AliAODTrack *track,Double_t *p) const
106 {
107   //
108   // ITS PID
109   //  1) Truncated mean method
110   //
111
112
113   if ((track->GetStatus()&AliESDtrack::kITSin)==0) return;
114   UChar_t clumap=track->GetITSClusterMap();
115   Int_t nPointsForPid=0;
116   for(Int_t i=2; i<6; i++){
117    if(clumap&(1<<i)) ++nPointsForPid;
118   }
119   if(nPointsForPid<3) { // track not to be used for combined PID purposes
120     for (Int_t j=0; j<AliPID::kSPECIES; j++) 
121       p[j] = 1./AliPID::kSPECIES;
122     return;
123   }
124   Double_t mom=track->P();  
125   AliAODPid *pidObj = track->GetDetPid();
126
127   Double_t dedx = 0.;
128   if (pidObj) {
129       dedx = pidObj->GetITSsignal();
130   }
131   
132   Bool_t mismatch = kTRUE;
133   Bool_t isSA = kTRUE;
134   if(track->GetStatus() & AliESDtrack::kTPCin){
135     isSA = kFALSE;
136     if (pidObj)
137       mom = pidObj->GetTPCmomentum();
138   }
139   for (Int_t j=0; j<AliPID::kSPECIES; j++) {
140     Double_t mass = AliPID::ParticleMass(j);//GeV/c^2
141     Double_t bethe = fITSResponse.Bethe(mom,mass);
142     Double_t sigma = fITSResponse.GetResolution(bethe,nPointsForPid,isSA);
143     if (TMath::Abs(dedx-bethe) > fRange*sigma) {
144       p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
145     } else {
146       p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
147       mismatch=kFALSE;
148     }
149
150     // Check for particles heavier than (AliPID::kSPECIES - 1)
151
152   }
153
154   if (mismatch)
155     for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
156
157   return;
158
159 }
160 //_________________________________________________________________________
161 void AliAODpidUtil::MakeTOFPID(AliAODTrack *track, Double_t *p) const
162 {
163   //
164   //   TOF PID using gaussian response
165   //
166   if ((track->GetStatus()&AliESDtrack::kTOFout )==0)    return;
167   if ((track->GetStatus()&AliESDtrack::kTIME )==0)     return;
168   if ((track->GetStatus()&AliESDtrack::kTOFpid )==0)   return;
169
170   Double_t time[AliPID::kSPECIESN];
171   Double_t sigma[AliPID::kSPECIESN];
172   AliAODPid *pidObj = track->GetDetPid();
173   pidObj->GetIntegratedTimes(time);
174
175   for (Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++) {
176     sigma[iPart] = fTOFResponse.GetExpectedSigma(track->P(),time[iPart],AliPID::ParticleMass(iPart));
177   }
178
179   AliDebugGeneral("AliESDpid::MakeTOFPID",2,
180                   Form("Expected TOF signals [ps]: %f %f %f %f %f",
181                        time[AliPID::kElectron],
182                        time[AliPID::kMuon],
183                        time[AliPID::kPion],
184                        time[AliPID::kKaon],
185                        time[AliPID::kProton]));
186
187   AliDebugGeneral("AliESDpid::MakeTOFPID",2,
188                   Form("Expected TOF std deviations [ps]: %f %f %f %f %f",
189                        sigma[AliPID::kElectron],
190                        sigma[AliPID::kMuon],
191                        sigma[AliPID::kPion],
192                        sigma[AliPID::kKaon],
193                        sigma[AliPID::kProton]
194                        ));
195
196   Double_t tof = pidObj->GetTOFsignal();
197
198   Bool_t mismatch = kTRUE;
199   for (Int_t j=0; j<AliPID::kSPECIES; j++) {
200     Double_t sig = sigma[j];
201     if (TMath::Abs(tof-time[j]) > fRange*sig) {
202       p[j] = TMath::Exp(-0.5*fRange*fRange)/sig;
203     } else
204       p[j] = TMath::Exp(-0.5*(tof-time[j])*(tof-time[j])/(sig*sig))/sig;
205
206     // Check the mismatching
207     Double_t mass = AliPID::ParticleMass(j);
208     Double_t pm = fTOFResponse.GetMismatchProbability(track->P(),mass);
209     if (p[j]>pm) mismatch = kFALSE;
210
211     // Check for particles heavier than (AliPID::kSPECIES - 1)
212
213   }
214
215   if (mismatch)
216     for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1/AliPID::kSPECIES;
217
218   return;
219 }
220 //_________________________________________________________________________
221 void AliAODpidUtil::MakeTRDPID(AliAODTrack *track,Double_t *p) const
222 {
223   
224   // Method to recalculate the TRD PID probabilities
225   if ((track->GetStatus()&AliESDtrack::kTRDout )==0)   return;
226
227   AliAODPid *pidObj = track->GetDetPid();
228   Float_t *mom=pidObj->GetTRDmomentum();
229   Int_t ntracklets=0;
230   for(Int_t iPl=0;iPl<6;iPl++){
231    if(mom[iPl]>0.) ntracklets++;
232   }
233    if(ntracklets<4) return;
234
235   Double_t* dedx=pidObj->GetTRDsignal();
236   Bool_t norm=kTRUE;
237   fTRDResponse.GetResponse(pidObj->GetTRDnSlices(),dedx,mom,p,norm);
238   return;
239 }