]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODpidUtil.cxx
Correction for
[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   UShort_t nTPCClus=track->GetTPCNcls();
76
77   Double_t mom = track->P();
78   AliAODPid *pidObj = track->GetDetPid();
79   if (pidObj) mom = pidObj->GetTPCmomentum();
80    
81   Double_t dedx=pidObj->GetTPCsignal(); 
82   Bool_t mismatch=kTRUE;
83
84   for (Int_t j=0; j<AliPID::kSPECIES; j++) {
85     AliPID::EParticleType type=AliPID::EParticleType(j);
86     Double_t bethe=fTPCResponse.GetExpectedSignal(mom,type); 
87     Double_t sigma=fTPCResponse.GetExpectedSigma(mom,nTPCClus,type);
88     if (TMath::Abs(dedx-bethe) > fRange*sigma) {
89       p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
90     } else {
91       p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
92       mismatch=kFALSE;
93     }
94
95   }
96
97   if (mismatch)
98     for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1/AliPID::kSPECIES;
99
100
101   return;
102 }
103 //_________________________________________________________________________
104 void AliAODpidUtil::MakeITSPID(AliAODTrack *track,Double_t *p) const
105 {
106   //
107   // ITS PID
108   //  1) Truncated mean method
109   //
110
111
112   if ((track->GetStatus()&AliESDtrack::kITSin)==0) return;
113   UChar_t clumap=track->GetITSClusterMap();
114   Int_t nPointsForPid=0;
115   for(Int_t i=2; i<6; i++){
116    if(clumap&(1<<i)) ++nPointsForPid;
117   }
118   if(nPointsForPid<3) return;// track not to be used for PID purposes
119
120   Double_t mom=track->P();  
121   AliAODPid *pidObj = track->GetDetPid();
122
123   Double_t dedx=pidObj->GetITSsignal();
124   Bool_t mismatch=kTRUE;
125   for (Int_t j=0; j<AliPID::kSPECIES; j++) {
126     Double_t mass=AliPID::ParticleMass(j);//GeV/c^2
127     Double_t bethe=fITSResponse.Bethe(mom,mass);
128     Double_t sigma=fITSResponse.GetResolution(bethe);
129     if (TMath::Abs(dedx-bethe) > fRange*sigma) {
130       p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
131     } else {
132       p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
133       mismatch=kFALSE;
134     }
135
136     // Check for particles heavier than (AliPID::kSPECIES - 1)
137
138   }
139
140   if (mismatch)
141     for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
142
143   return;
144
145 }
146 //_________________________________________________________________________
147 void AliAODpidUtil::MakeTOFPID(AliAODTrack *track, Double_t *p) const
148 {
149   //
150   //   TOF PID using gaussian response
151   //
152   if ((track->GetStatus()&AliESDtrack::kTOFout )==0)    return;
153   if ((track->GetStatus()&AliESDtrack::kTIME )==0)     return;
154   if ((track->GetStatus()&AliESDtrack::kTOFpid )==0)   return;
155
156   Double_t time[AliPID::kSPECIESN];
157   Double_t sigma[AliPID::kSPECIESN];
158   AliAODPid *pidObj = track->GetDetPid();
159   pidObj->GetIntegratedTimes(time);
160
161   for (Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++) {
162     sigma[iPart] = fTOFResponse.GetExpectedSigma(track->P(),time[iPart],AliPID::ParticleMass(iPart));
163   }
164
165   AliDebugGeneral("AliESDpid::MakeTOFPID",2,
166                   Form("Expected TOF signals [ps]: %f %f %f %f %f",
167                        time[AliPID::kElectron],
168                        time[AliPID::kMuon],
169                        time[AliPID::kPion],
170                        time[AliPID::kKaon],
171                        time[AliPID::kProton]));
172
173   AliDebugGeneral("AliESDpid::MakeTOFPID",2,
174                   Form("Expected TOF std deviations [ps]: %f %f %f %f %f",
175                        sigma[AliPID::kElectron],
176                        sigma[AliPID::kMuon],
177                        sigma[AliPID::kPion],
178                        sigma[AliPID::kKaon],
179                        sigma[AliPID::kProton]
180                        ));
181
182   Double_t tof = pidObj->GetTOFsignal();
183
184   Bool_t mismatch = kTRUE;
185   for (Int_t j=0; j<AliPID::kSPECIES; j++) {
186     Double_t sig = sigma[j];
187     if (TMath::Abs(tof-time[j]) > fRange*sig) {
188       p[j] = TMath::Exp(-0.5*fRange*fRange)/sig;
189     } else
190       p[j] = TMath::Exp(-0.5*(tof-time[j])*(tof-time[j])/(sig*sig))/sig;
191
192     // Check the mismatching
193     Double_t mass = AliPID::ParticleMass(j);
194     Double_t pm = fTOFResponse.GetMismatchProbability(track->P(),mass);
195     if (p[j]>pm) mismatch = kFALSE;
196
197     // Check for particles heavier than (AliPID::kSPECIES - 1)
198
199   }
200
201   if (mismatch)
202     for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1/AliPID::kSPECIES;
203
204   return;
205 }
206 //_________________________________________________________________________
207 void AliAODpidUtil::MakeTRDPID(AliAODTrack *track,Double_t *p) const
208 {
209   
210   // Method to recalculate the TRD PID probabilities
211   if ((track->GetStatus()&AliESDtrack::kTRDout )==0)   return;
212
213   AliAODPid *pidObj = track->GetDetPid();
214   Float_t *mom=pidObj->GetTRDmomentum();
215   Int_t ntracklets=0;
216   for(Int_t iPl=0;iPl<6;iPl++){
217    if(mom[iPl]>0.) ntracklets++;
218   }
219    if(ntracklets<4) return;
220
221   Double_t* dedx=pidObj->GetTRDsignal();
222   Bool_t norm=kTRUE;
223   fTRDResponse.GetResponse(pidObj->GetTRDnSlices(),dedx,mom,p,norm);
224   return;
225 }