From Francesco: Now I pass the MC event handler with a method avoiding to call AliAna...
[u/mrichter/AliRoot.git] / STEER / ESD / AliESDpid.cxx
CommitLineData
8c6a71ab 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
4f679a16 16/* $Id$ */
17
8c6a71ab 18//-----------------------------------------------------------------
19// Implementation of the combined PID class
4f679a16 20// For the Event Summary Data Class
21// produced by the reconstruction process
22// and containing information on the particle identification
8c6a71ab 23// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
24//-----------------------------------------------------------------
25
f858b00e 26#include "TArrayI.h"
27#include "TArrayF.h"
28
539a5a59 29#include "TRandom.h"
10d100d4 30#include "AliLog.h"
31#include "AliPID.h"
f858b00e 32#include "AliTOFHeader.h"
8c6a71ab 33#include "AliESDpid.h"
af885e0f 34#include "AliESDEvent.h"
8c6a71ab 35#include "AliESDtrack.h"
539a5a59 36#include "AliMCEvent.h"
539a5a59 37
8c6a71ab 38
39ClassImp(AliESDpid)
40
f858b00e 41Int_t AliESDpid::MakePID(AliESDEvent *event, Bool_t TPConly, Float_t timeZeroTOF) const {
10d100d4 42 //
43 // Calculate probabilities for all detectors, except if TPConly==kTRUE
44 // and combine PID
45 //
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
49 //
50
51 /*
f858b00e 52 Float_t timeZeroTOF = 0;
10d100d4 53 if (subtractT0)
f858b00e 54 timeZeroTOF = event->GetT0();
10d100d4 55 */
56 Int_t nTrk=event->GetNumberOfTracks();
57 for (Int_t iTrk=0; iTrk<nTrk; iTrk++) {
58 AliESDtrack *track=event->GetTrack(iTrk);
59 MakeTPCPID(track);
60 if (!TPConly) {
61 MakeITSPID(track);
f858b00e 62 MakeTOFPID(track, timeZeroTOF);
10d100d4 63 //MakeHMPIDPID(track);
ce5d6908 64 //MakeTRDPID(track);
10d100d4 65 }
66 CombinePID(track);
67 }
68 return 0;
69}
8c6a71ab 70//_________________________________________________________________________
539a5a59 71Float_t AliESDpid::GetTPCsignalTunedOnData(const AliVTrack *t) const {
72 AliESDtrack *track = (AliESDtrack *) t;
73 Float_t dedx = track->GetTPCsignalTunedOnData();
74
75 if(dedx > 0) return dedx;
76
77 Double_t mom = t->GetTPCmomentum();
78 dedx = t->GetTPCsignal();
79 track->SetTPCsignalTunedOnData(dedx);
80 if(dedx < 20) return dedx;
81
82 AliPID::EParticleType type = AliPID::kPion;
83
a864479b 84 AliMCEventHandler* eventHandler=dynamic_cast<AliMCEventHandler*>(fEventHandler);
539a5a59 85 if (eventHandler) {
86 AliMCEvent* mcEvent = eventHandler->MCEvent();
87 if(mcEvent){
88 Bool_t kGood = kTRUE;
89 AliMCParticle *MCpart = (AliMCParticle *) mcEvent->GetTrack(TMath::Abs(t->GetLabel()));
90 TParticle *part = MCpart->Particle();
91
92 Int_t iS = TMath::Abs(part->GetPdgCode());
93
94 if(iS==AliPID::ParticleCode(AliPID::kElectron)){
95 type = AliPID::kElectron;
96 }
97 else if(iS==AliPID::ParticleCode(AliPID::kMuon)){
98 type = AliPID::kMuon;
99 }
100 else if(iS==AliPID::ParticleCode(AliPID::kPion)){
101 type = AliPID::kPion;
102 }
103 else if(iS==AliPID::ParticleCode(AliPID::kKaon)){
104 type = AliPID::kKaon;
105 }
106 else if(iS==AliPID::ParticleCode(AliPID::kProton)){
107 type = AliPID::kProton;
108 }
109 else if(iS==AliPID::ParticleCode(AliPID::kDeuteron)){ // d
110 type = AliPID::kDeuteron;
111 }
112 else if(iS==AliPID::ParticleCode(AliPID::kTriton)){ // t
113 type = AliPID::kTriton;
114 }
115 else if(iS==AliPID::ParticleCode(AliPID::kHe3)){ // 3He
116 type = AliPID::kHe3;
117 }
118 else if(iS==AliPID::ParticleCode(AliPID::kAlpha)){ // 4He
119 type = AliPID::kAlpha;
120 }
121 else
122 kGood = kFALSE;
123
124 if(kGood){
125 Double_t bethe=fTPCResponse.GetExpectedSignal(mom,type);
126 Double_t sigma=fTPCResponse.GetExpectedSigma(mom,t->GetTPCsignalN(),type);
127 dedx = gRandom->Gaus(bethe,sigma);
128 if(iS == AliPID::ParticleCode(AliPID::kHe3) || iS == AliPID::ParticleCode(AliPID::kAlpha)) dedx *= 5;
129 }
130 }
131 }
132
133 track->SetTPCsignalTunedOnData(dedx);
134 return dedx;
135}
136//_________________________________________________________________________
10d100d4 137void AliESDpid::MakeTPCPID(AliESDtrack *track) const
8c6a71ab 138{
4f679a16 139 //
10d100d4 140 // TPC pid using bethe-bloch and gaussian response
4f679a16 141 //
10d100d4 142 if ((track->GetStatus()&AliESDtrack::kTPCin )==0)
143 if ((track->GetStatus()&AliESDtrack::kTPCout)==0) return;
8c6a71ab 144
10d100d4 145 Double_t mom = track->GetP();
146 const AliExternalTrackParam *in=track->GetInnerParam();
147 if (in) mom = in->GetP();
8c6a71ab 148
10d100d4 149 Double_t p[AliPID::kSPECIES];
150 Double_t dedx=track->GetTPCsignal();
151 Bool_t mismatch=kTRUE, heavy=kTRUE;
8c6a71ab 152
10d100d4 153 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
154 AliPID::EParticleType type=AliPID::EParticleType(j);
155 Double_t bethe=fTPCResponse.GetExpectedSignal(mom,type);
156 Double_t sigma=fTPCResponse.GetExpectedSigma(mom,track->GetTPCsignalN(),type);
157 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
158 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
159 } else {
160 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
161 mismatch=kFALSE;
162 }
8c6a71ab 163
10d100d4 164 // Check for particles heavier than (AliPID::kSPECIES - 1)
165 if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
c630aafd 166
4a78b8c5 167 }
168
10d100d4 169 if (mismatch)
77638021 170 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
10d100d4 171
172 track->SetTPCpid(p);
173
174 if (heavy) track->ResetStatus(AliESDtrack::kTPCpid);
175
176}
177//_________________________________________________________________________
178void AliESDpid::MakeITSPID(AliESDtrack *track) const
179{
180 //
181 // ITS PID
182 // Two options, depending on fITSPIDmethod:
183 // 1) Truncated mean method
184 // 2) Likelihood, using charges measured in all 4 layers and
185 // Landau+gaus response functions
186 //
187
188 if ((track->GetStatus()&AliESDtrack::kITSin)==0 &&
189 (track->GetStatus()&AliESDtrack::kITSout)==0) return;
190
191 Double_t mom=track->GetP();
192 if (fITSPIDmethod == kITSTruncMean) {
193 Double_t dedx=track->GetITSsignal();
15e979c9 194 Bool_t isSA=kTRUE;
195 Double_t momITS=mom;
196 ULong_t trStatus=track->GetStatus();
99daa709 197 if(trStatus&AliESDtrack::kTPCin) isSA=kFALSE;
15e979c9 198 UChar_t clumap=track->GetITSClusterMap();
199 Int_t nPointsForPid=0;
200 for(Int_t i=2; i<6; i++){
201 if(clumap&(1<<i)) ++nPointsForPid;
202 }
203
204 if(nPointsForPid<3) { // track not to be used for combined PID purposes
205 track->ResetStatus(AliESDtrack::kITSpid);
206 return;
207 }
208
10d100d4 209 Double_t p[10];
15e979c9 210
10d100d4 211 Bool_t mismatch=kTRUE, heavy=kTRUE;
212 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
213 Double_t mass=AliPID::ParticleMass(j);//GeV/c^2
15e979c9 214 Double_t bethe=fITSResponse.Bethe(momITS,mass);
215 Double_t sigma=fITSResponse.GetResolution(bethe,nPointsForPid,isSA);
10d100d4 216 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
217 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
218 } else {
219 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
220 mismatch=kFALSE;
221 }
222
223 // Check for particles heavier than (AliPID::kSPECIES - 1)
224 if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
225
4a78b8c5 226 }
c630aafd 227
10d100d4 228 if (mismatch)
229 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
230
231 track->SetITSpid(p);
232
233 if (heavy) track->ResetStatus(AliESDtrack::kITSpid);
234 }
235 else { // Likelihood method
236 Double_t condprobfun[AliPID::kSPECIES];
237 Double_t qclu[4];
238 track->GetITSdEdxSamples(qclu);
239 fITSResponse.GetITSProbabilities(mom,qclu,condprobfun);
240 track->SetITSpid(condprobfun);
8c6a71ab 241 }
7a8614f3 242
10d100d4 243}
244//_________________________________________________________________________
f858b00e 245void AliESDpid::MakeTOFPID(AliESDtrack *track, Float_t /*timeZeroTOF*/) const
10d100d4 246{
247 //
248 // TOF PID using gaussian response
249 //
f858b00e 250
10d100d4 251 if ((track->GetStatus()&AliESDtrack::kTOFout)==0) return;
252 if ((track->GetStatus()&AliESDtrack::kTIME)==0) return;
a512bf97 253 if ((track->GetStatus()&AliESDtrack::kITSin)==0) return;
10d100d4 254
f858b00e 255 Int_t ibin = fTOFResponse.GetMomBin(track->GetP());
256 Float_t timezero = fTOFResponse.GetT0bin(ibin);
257
10d100d4 258 Double_t time[AliPID::kSPECIESN];
259 track->GetIntegratedTimes(time);
260
261 Double_t sigma[AliPID::kSPECIES];
262 for (Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++) {
263 sigma[iPart] = fTOFResponse.GetExpectedSigma(track->GetP(),time[iPart],AliPID::ParticleMass(iPart));
264 }
265
266 AliDebugGeneral("AliESDpid::MakeTOFPID",2,
267 Form("Expected TOF signals [ps]: %f %f %f %f %f",
268 time[AliPID::kElectron],
269 time[AliPID::kMuon],
270 time[AliPID::kPion],
271 time[AliPID::kKaon],
272 time[AliPID::kProton]));
273
274 AliDebugGeneral("AliESDpid::MakeTOFPID",2,
275 Form("Expected TOF std deviations [ps]: %f %f %f %f %f",
276 sigma[AliPID::kElectron],
277 sigma[AliPID::kMuon],
278 sigma[AliPID::kPion],
279 sigma[AliPID::kKaon],
280 sigma[AliPID::kProton]
281 ));
282
f858b00e 283 Double_t tof = track->GetTOFsignal() - timezero;
10d100d4 284
285 Double_t p[AliPID::kSPECIES];
286 Bool_t mismatch = kTRUE, heavy = kTRUE;
287 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
288 Double_t sig = sigma[j];
f858b00e 289 if (TMath::Abs(tof-time[j]) > (fRange+2)*sig) {
290 p[j] = TMath::Exp(-0.5*(fRange+2)*(fRange+2))/sig;
10d100d4 291 } else
292 p[j] = TMath::Exp(-0.5*(tof-time[j])*(tof-time[j])/(sig*sig))/sig;
293
294 // Check the mismatching
ee251349 295
10d100d4 296 Double_t mass = AliPID::ParticleMass(j);
297 Double_t pm = fTOFResponse.GetMismatchProbability(track->GetP(),mass);
298 if (p[j]>pm) mismatch = kFALSE;
299
300 // Check for particles heavier than (AliPID::kSPECIES - 1)
301 if (tof < (time[j] + fRange*sig)) heavy=kFALSE;
302
303 }
304
ee251349 305 /*
306 if (mismatch)
77638021 307 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
ee251349 308 */
10d100d4 309
310 track->SetTOFpid(p);
311
ee251349 312 if (heavy) track->ResetStatus(AliESDtrack::kTOFpid);
f858b00e 313
ee251349 314 if (!CheckTOFMatching(track)) track->SetStatus(AliESDtrack::kTOFmismatch);
315 else track->ResetStatus(AliESDtrack::kTOFmismatch);
10d100d4 316}
317//_________________________________________________________________________
b439f460 318void AliESDpid::MakeTRDPID(AliESDtrack *track) const
319{
320 //
321 // Method to recalculate the TRD PID probabilities
322 //
ea235c90 323 Double_t prob[AliPID::kSPECIES];
324 ComputeTRDProbability(track, AliPID::kSPECIES, prob);
b439f460 325 track->SetTRDpid(prob);
326}
327//_________________________________________________________________________
10d100d4 328void AliESDpid::CombinePID(AliESDtrack *track) const
329{
330 //
331 // Combine the information of various detectors
332 // to determine the Particle Identification
333 //
334 Int_t ns=AliPID::kSPECIES;
335 Double_t p[10]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};
336
337 if (track->IsOn(AliESDtrack::kITSpid)) {
338 Double_t d[10];
339 track->GetITSpid(d);
340 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
341 }
342
343 if (track->IsOn(AliESDtrack::kTPCpid)) {
344 Double_t d[10];
345 track->GetTPCpid(d);
346 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
347 }
348
349 if (track->IsOn(AliESDtrack::kTRDpid)) {
350 Double_t d[10];
351 track->GetTRDpid(d);
352 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
353 }
354
355 if (track->IsOn(AliESDtrack::kTOFpid)) {
356 Double_t d[10];
357 track->GetTOFpid(d);
358 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
359 }
360
361 if (track->IsOn(AliESDtrack::kHMPIDpid)) {
362 Double_t d[10];
363 track->GetHMPIDpid(d);
364 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
365 }
366
367 track->SetESDpid(p);
8c6a71ab 368}
f858b00e 369//_________________________________________________________________________
370Bool_t AliESDpid::CheckTOFMatching(AliESDtrack *track) const{
ea235c90 371 //
372 // Check pid matching of TOF with TPC as reference
373 //
f858b00e 374 Bool_t status = kFALSE;
375
376 Double_t exptimes[5];
377 track->GetIntegratedTimes(exptimes);
378
f858b00e 379 Float_t p = track->P();
380
7170298c 381 Float_t dedx = track->GetTPCsignal();
382 Float_t time = track->GetTOFsignal() - fTOFResponse.GetStartTime(p);
383
f858b00e 384 Double_t ptpc[3];
385 track->GetInnerPxPyPz(ptpc);
386 Float_t momtpc=TMath::Sqrt(ptpc[0]*ptpc[0] + ptpc[1]*ptpc[1] + ptpc[2]*ptpc[2]);
387
388 for(Int_t i=0;i < 5;i++){
389 AliPID::EParticleType type=AliPID::EParticleType(i);
390
391 Float_t resolutionTOF = fTOFResponse.GetExpectedSigma(p, exptimes[i], AliPID::ParticleMass(i));
392 if(TMath::Abs(exptimes[i] - time) < fRange * resolutionTOF){
393 Float_t dedxExp = fTPCResponse.GetExpectedSignal(momtpc,type);
394 Float_t resolutionTPC = fTPCResponse.GetExpectedSigma(momtpc,track->GetTPCsignalN(),type);
395
7170298c 396 if(TMath::Abs(dedx - dedxExp) < fRangeTOFMismatch * resolutionTPC){
f858b00e 397 status = kTRUE;
398 }
399 }
400 }
401
402 // for nuclei
c1252298 403 Float_t resolutionTOFpr = fTOFResponse.GetExpectedSigma(p, exptimes[4], AliPID::ParticleMass(4));
404 if(!status && (exptimes[4] + fRange*resolutionTOFpr < time)) status = kTRUE;
f858b00e 405
406
407 return status;
408}