1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /* $Id: AliAODpidUtil.cxx 38329 2010-01-17 19:17:24Z hristov $ */
18 //-----------------------------------------------------------------
19 // Implementation of the combined PID class
21 // containing information on the particle identification
22 // Origin: Rosa Romita, GSI, r.romita@gsi.de
23 //-----------------------------------------------------------------
28 #include "AliAODpidUtil.h"
29 #include "AliAODEvent.h"
30 #include "AliAODTrack.h"
31 #include "AliAODPid.h"
32 #include "AliTRDPIDResponse.h"
33 #include "AliESDtrack.h"
34 #include "AliAODMCHeader.h"
35 #include "AliAODMCParticle.h"
37 #include <AliDetectorPID.h>
39 ClassImp(AliAODpidUtil)
41 Int_t AliAODpidUtil::MakePID(const AliAODTrack *track,Double_t *p) const {
43 // Calculate probabilities for all detectors, except if TPConly==kTRUE
46 // Option TPConly==kTRUE is used during reconstruction,
47 // because ITS tracking uses TPC pid
48 // HMPID and TRD pid are done in detector reconstructors
52 Float_t TimeZeroTOF = 0;
54 TimeZeroTOF = event->GetT0();
56 Int_t ns=AliPID::kSPECIES;
57 Double_t tpcPid[AliPID::kSPECIES];
58 MakeTPCPID(track,tpcPid);
59 Double_t itsPid[AliPID::kSPECIES];
60 Double_t tofPid[AliPID::kSPECIES];
61 Double_t trdPid[AliPID::kSPECIES];
62 MakeITSPID(track,itsPid);
63 MakeTOFPID(track,tofPid);
64 //MakeHMPIDPID(track);
65 MakeTRDPID(track,trdPid);
66 for (Int_t j=0; j<ns; j++) {
67 p[j]=tpcPid[j]*itsPid[j]*tofPid[j]*trdPid[j];
72 //_________________________________________________________________________
73 Float_t AliAODpidUtil::GetTPCsignalTunedOnData(const AliVTrack *t) const {
74 AliAODTrack *track = (AliAODTrack *) t;
75 Float_t dedx = track->GetTPCsignalTunedOnData();
76 if(dedx > 0) return dedx;
78 Double_t mom = t->GetTPCmomentum();
80 dedx = t->GetTPCsignal();
81 track->SetTPCsignalTunedOnData(dedx);
83 if(dedx < 20) return dedx;
86 AliPID::EParticleType type = AliPID::kPion;
88 AliAODMCHeader *mcHeader = dynamic_cast<AliAODMCHeader*>(track->GetAODEvent()->GetList()->FindObject(AliAODMCHeader::StdBranchName()));
90 TClonesArray *mcArray = (TClonesArray*)track->GetAODEvent()->GetList()->FindObject(AliAODMCParticle::StdBranchName());
94 Int_t iS = TMath::Abs(((AliAODMCParticle*)mcArray->At(TMath::Abs(t->GetLabel())))->GetPdgCode());
95 if(iS==AliPID::ParticleCode(AliPID::kElectron)){
96 type = AliPID::kElectron;
98 else if(iS==AliPID::ParticleCode(AliPID::kMuon)){
101 else if(iS==AliPID::ParticleCode(AliPID::kPion)){
102 type = AliPID::kPion;
104 else if(iS==AliPID::ParticleCode(AliPID::kKaon)){
105 type = AliPID::kKaon;
107 else if(iS==AliPID::ParticleCode(AliPID::kProton)){
108 type = AliPID::kProton;
110 else if(iS==AliPID::ParticleCode(AliPID::kDeuteron)){ // d
111 type = AliPID::kDeuteron;
113 else if(iS==AliPID::ParticleCode(AliPID::kTriton)){ // t
114 type = AliPID::kTriton;
116 else if(iS==AliPID::ParticleCode(AliPID::kHe3)){ // 3He
119 else if(iS==AliPID::ParticleCode(AliPID::kAlpha)){ // 4He
120 type = AliPID::kAlpha;
126 Double_t bethe=fTPCResponse.GetExpectedSignal(mom,type);
127 Double_t sigma=fTPCResponse.GetExpectedSigma(mom,t->GetTPCsignalN(),type);
128 dedx = gRandom->Gaus(bethe,sigma);
130 if(iS == AliPID::ParticleCode(AliPID::kHe3) || iS == AliPID::ParticleCode(AliPID::kAlpha)) dedx *= 5;
135 track->SetTPCsignalTunedOnData(dedx);
138 //_________________________________________________________________________
139 void AliAODpidUtil::MakeTPCPID(const AliAODTrack *track,Double_t *p) const
142 // TPC pid using bethe-bloch and gaussian response
145 if ((track->GetStatus()&AliESDtrack::kTPCin )==0) return;
147 AliAODPid *pidObj = track->GetDetPid();
148 Double_t mom = track->P();
150 UShort_t nTPCClus = 0;
152 nTPCClus = pidObj->GetTPCsignalN();
153 dedx = pidObj->GetTPCsignal();
154 mom = pidObj->GetTPCmomentum();
157 Bool_t mismatch=kTRUE;
159 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
160 AliPID::EParticleType type=AliPID::EParticleType(j);
161 Double_t bethe=fTPCResponse.GetExpectedSignal(mom,type);
162 Double_t sigma=fTPCResponse.GetExpectedSigma(mom,nTPCClus,type);
163 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
164 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
166 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
173 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
178 //_________________________________________________________________________
179 void AliAODpidUtil::MakeITSPID(const AliAODTrack *track,Double_t *p) const
183 // 1) Truncated mean method
187 if ((track->GetStatus()&AliESDtrack::kITSin)==0) return;
188 UChar_t clumap=track->GetITSClusterMap();
189 Int_t nPointsForPid=0;
190 for(Int_t i=2; i<6; i++){
191 if(clumap&(1<<i)) ++nPointsForPid;
193 if(nPointsForPid<3) { // track not to be used for combined PID purposes
194 for (Int_t j=0; j<AliPID::kSPECIES; j++)
195 p[j] = 1./AliPID::kSPECIES;
198 Double_t mom=track->P();
199 AliAODPid *pidObj = track->GetDetPid();
203 dedx = pidObj->GetITSsignal();
206 Bool_t mismatch = kTRUE;
208 if(track->GetStatus() & AliESDtrack::kTPCin){
211 mom = pidObj->GetTPCmomentum();
213 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
214 Double_t mass = AliPID::ParticleMass(j);//GeV/c^2
215 Double_t bethe = fITSResponse.Bethe(mom,mass);
216 Double_t sigma = fITSResponse.GetResolution(bethe,nPointsForPid,isSA);
217 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
218 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
220 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
224 // Check for particles heavier than (AliPID::kSPECIES - 1)
229 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
234 //_________________________________________________________________________
235 void AliAODpidUtil::MakeTOFPID(const AliAODTrack *track, Double_t *p) const
238 // TOF PID using gaussian response
240 if ((track->GetStatus()&AliESDtrack::kTOFout )==0) return;
241 if ((track->GetStatus()&AliESDtrack::kTIME )==0) return;
242 if ((track->GetStatus()&AliESDtrack::kTOFpid )==0) return;
244 Double_t time[AliPID::kSPECIES];
245 Double_t sigma[AliPID::kSPECIES];
246 AliAODPid *pidObj = track->GetDetPid();
247 pidObj->GetIntegratedTimes(time);
249 for (Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++) {
250 sigma[iPart] = fTOFResponse.GetExpectedSigma(track->P(),time[iPart],AliPID::ParticleMass(iPart));
253 AliDebugGeneral("AliESDpid::MakeTOFPID",2,
254 Form("Expected TOF signals [ps]: %f %f %f %f %f",
255 time[AliPID::kElectron],
259 time[AliPID::kProton]));
261 AliDebugGeneral("AliESDpid::MakeTOFPID",2,
262 Form("Expected TOF std deviations [ps]: %f %f %f %f %f",
263 sigma[AliPID::kElectron],
264 sigma[AliPID::kMuon],
265 sigma[AliPID::kPion],
266 sigma[AliPID::kKaon],
267 sigma[AliPID::kProton]
270 Double_t tof = pidObj->GetTOFsignal();
272 Bool_t mismatch = kTRUE;
273 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
274 Double_t sig = sigma[j];
275 if (TMath::Abs(tof-time[j]) > fRange*sig) {
276 p[j] = TMath::Exp(-0.5*fRange*fRange)/sig;
278 p[j] = TMath::Exp(-0.5*(tof-time[j])*(tof-time[j])/(sig*sig))/sig;
280 // Check the mismatching
281 Double_t mass = AliPID::ParticleMass(j);
282 Double_t pm = fTOFResponse.GetMismatchProbability(track->P(),mass);
283 if (p[j]>pm) mismatch = kFALSE;
285 // Check for particles heavier than (AliPID::kSPECIES - 1)
290 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
294 //_________________________________________________________________________
295 void AliAODpidUtil::MakeTRDPID(const AliAODTrack *track,Double_t *p) const
297 ComputeTRDProbability(track, AliPID::kSPECIES, p);
301 //_________________________________________________________________________
302 Float_t AliAODpidUtil::NumberOfSigmasTOF(const AliVParticle *vtrack, AliPID::EParticleType type) const
305 // Number of sigma implementation for the TOF
308 AliAODTrack *track=(AliAODTrack*)vtrack;
310 // look for cached value first
311 if (track->GetDetectorPID()){
312 return track->GetDetectorPID()->GetNumberOfSigmas(kTOF, type);
317 AliAODPid *pidObj = track->GetDetPid();
318 if (!pidObj) return -999.;
319 Double_t tofTime=pidObj->GetTOFsignal();
320 Double_t expTime=fTOFResponse.GetExpectedSignal((AliVTrack*)vtrack,type);
321 Double_t sigmaTOFPid[AliPID::kSPECIES];
322 pidObj->GetTOFpidResolution(sigmaTOFPid);
323 AliAODEvent *event=(AliAODEvent*)track->GetAODEvent();
324 if (event) { // protection if the user didn't call GetTrack, which sets the internal pointer
325 AliTOFHeader* tofH=(AliTOFHeader*)event->GetTOFHeader();
326 if (tofH && (TMath::Abs(sigmaTOFPid[0]) <= 1.E-16) ) { // new AOD
327 sigTOF=fTOFResponse.GetExpectedSigma(track->P(),expTime,AliPID::ParticleMassZ(type)); //fTOFResponse is set in InitialiseEvent
328 tofTime -= fTOFResponse.GetStartTime(vtrack->P());
332 AliError("pointer to AliAODEvent not found, please call GetTrack to set it");
335 if (oldAod) { // old AOD
336 if (type <= AliPID::kProton) {
337 sigTOF=sigmaTOFPid[type];
338 } else return -998.; // light nuclei cannot be supported on old AOD because we don't have timeZero resolution
340 if (sigTOF>0) return (tofTime - expTime)/sigTOF;