]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliESDpid.cxx
More decay options
[u/mrichter/AliRoot.git] / STEER / 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
10d100d4 29#include "AliLog.h"
30#include "AliPID.h"
f858b00e 31#include "AliTOFHeader.h"
8c6a71ab 32#include "AliESDpid.h"
af885e0f 33#include "AliESDEvent.h"
8c6a71ab 34#include "AliESDtrack.h"
35
36ClassImp(AliESDpid)
37
f858b00e 38Int_t AliESDpid::MakePID(AliESDEvent *event, Bool_t TPConly, Float_t timeZeroTOF) const {
10d100d4 39 //
40 // Calculate probabilities for all detectors, except if TPConly==kTRUE
41 // and combine PID
42 //
43 // Option TPConly==kTRUE is used during reconstruction,
44 // because ITS tracking uses TPC pid
45 // HMPID and TRD pid are done in detector reconstructors
46 //
47
48 /*
f858b00e 49 Float_t timeZeroTOF = 0;
10d100d4 50 if (subtractT0)
f858b00e 51 timeZeroTOF = event->GetT0();
10d100d4 52 */
53 Int_t nTrk=event->GetNumberOfTracks();
54 for (Int_t iTrk=0; iTrk<nTrk; iTrk++) {
55 AliESDtrack *track=event->GetTrack(iTrk);
56 MakeTPCPID(track);
57 if (!TPConly) {
58 MakeITSPID(track);
f858b00e 59 MakeTOFPID(track, timeZeroTOF);
10d100d4 60 //MakeHMPIDPID(track);
ce5d6908 61 //MakeTRDPID(track);
10d100d4 62 }
63 CombinePID(track);
64 }
65 return 0;
66}
8c6a71ab 67//_________________________________________________________________________
10d100d4 68void AliESDpid::MakeTPCPID(AliESDtrack *track) const
8c6a71ab 69{
4f679a16 70 //
10d100d4 71 // TPC pid using bethe-bloch and gaussian response
4f679a16 72 //
10d100d4 73 if ((track->GetStatus()&AliESDtrack::kTPCin )==0)
74 if ((track->GetStatus()&AliESDtrack::kTPCout)==0) return;
8c6a71ab 75
10d100d4 76 Double_t mom = track->GetP();
77 const AliExternalTrackParam *in=track->GetInnerParam();
78 if (in) mom = in->GetP();
8c6a71ab 79
10d100d4 80 Double_t p[AliPID::kSPECIES];
81 Double_t dedx=track->GetTPCsignal();
82 Bool_t mismatch=kTRUE, heavy=kTRUE;
8c6a71ab 83
10d100d4 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,track->GetTPCsignalN(),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 }
8c6a71ab 94
10d100d4 95 // Check for particles heavier than (AliPID::kSPECIES - 1)
96 if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
c630aafd 97
4a78b8c5 98 }
99
10d100d4 100 if (mismatch)
101 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1/AliPID::kSPECIES;
102
103 track->SetTPCpid(p);
104
105 if (heavy) track->ResetStatus(AliESDtrack::kTPCpid);
106
107}
108//_________________________________________________________________________
109void AliESDpid::MakeITSPID(AliESDtrack *track) const
110{
111 //
112 // ITS PID
113 // Two options, depending on fITSPIDmethod:
114 // 1) Truncated mean method
115 // 2) Likelihood, using charges measured in all 4 layers and
116 // Landau+gaus response functions
117 //
118
119 if ((track->GetStatus()&AliESDtrack::kITSin)==0 &&
120 (track->GetStatus()&AliESDtrack::kITSout)==0) return;
121
122 Double_t mom=track->GetP();
123 if (fITSPIDmethod == kITSTruncMean) {
124 Double_t dedx=track->GetITSsignal();
15e979c9 125 Bool_t isSA=kTRUE;
126 Double_t momITS=mom;
127 ULong_t trStatus=track->GetStatus();
99daa709 128 if(trStatus&AliESDtrack::kTPCin) isSA=kFALSE;
15e979c9 129 UChar_t clumap=track->GetITSClusterMap();
130 Int_t nPointsForPid=0;
131 for(Int_t i=2; i<6; i++){
132 if(clumap&(1<<i)) ++nPointsForPid;
133 }
134
135 if(nPointsForPid<3) { // track not to be used for combined PID purposes
136 track->ResetStatus(AliESDtrack::kITSpid);
137 return;
138 }
139
10d100d4 140 Double_t p[10];
15e979c9 141
10d100d4 142 Bool_t mismatch=kTRUE, heavy=kTRUE;
143 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
144 Double_t mass=AliPID::ParticleMass(j);//GeV/c^2
15e979c9 145 Double_t bethe=fITSResponse.Bethe(momITS,mass);
146 Double_t sigma=fITSResponse.GetResolution(bethe,nPointsForPid,isSA);
10d100d4 147 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
148 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
149 } else {
150 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
151 mismatch=kFALSE;
152 }
153
154 // Check for particles heavier than (AliPID::kSPECIES - 1)
155 if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
156
4a78b8c5 157 }
c630aafd 158
10d100d4 159 if (mismatch)
160 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
161
162 track->SetITSpid(p);
163
164 if (heavy) track->ResetStatus(AliESDtrack::kITSpid);
165 }
166 else { // Likelihood method
167 Double_t condprobfun[AliPID::kSPECIES];
168 Double_t qclu[4];
169 track->GetITSdEdxSamples(qclu);
170 fITSResponse.GetITSProbabilities(mom,qclu,condprobfun);
171 track->SetITSpid(condprobfun);
8c6a71ab 172 }
7a8614f3 173
10d100d4 174}
175//_________________________________________________________________________
f858b00e 176void AliESDpid::MakeTOFPID(AliESDtrack *track, Float_t /*timeZeroTOF*/) const
10d100d4 177{
178 //
179 // TOF PID using gaussian response
180 //
f858b00e 181
10d100d4 182 if ((track->GetStatus()&AliESDtrack::kTOFout)==0) return;
183 if ((track->GetStatus()&AliESDtrack::kTIME)==0) return;
184
f858b00e 185 Int_t ibin = fTOFResponse.GetMomBin(track->GetP());
186 Float_t timezero = fTOFResponse.GetT0bin(ibin);
187
10d100d4 188 Double_t time[AliPID::kSPECIESN];
189 track->GetIntegratedTimes(time);
190
191 Double_t sigma[AliPID::kSPECIES];
192 for (Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++) {
193 sigma[iPart] = fTOFResponse.GetExpectedSigma(track->GetP(),time[iPart],AliPID::ParticleMass(iPart));
194 }
195
196 AliDebugGeneral("AliESDpid::MakeTOFPID",2,
197 Form("Expected TOF signals [ps]: %f %f %f %f %f",
198 time[AliPID::kElectron],
199 time[AliPID::kMuon],
200 time[AliPID::kPion],
201 time[AliPID::kKaon],
202 time[AliPID::kProton]));
203
204 AliDebugGeneral("AliESDpid::MakeTOFPID",2,
205 Form("Expected TOF std deviations [ps]: %f %f %f %f %f",
206 sigma[AliPID::kElectron],
207 sigma[AliPID::kMuon],
208 sigma[AliPID::kPion],
209 sigma[AliPID::kKaon],
210 sigma[AliPID::kProton]
211 ));
212
f858b00e 213 Double_t tof = track->GetTOFsignal() - timezero;
10d100d4 214
215 Double_t p[AliPID::kSPECIES];
216 Bool_t mismatch = kTRUE, heavy = kTRUE;
217 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
218 Double_t sig = sigma[j];
f858b00e 219 if (TMath::Abs(tof-time[j]) > (fRange+2)*sig) {
220 p[j] = TMath::Exp(-0.5*(fRange+2)*(fRange+2))/sig;
10d100d4 221 } else
222 p[j] = TMath::Exp(-0.5*(tof-time[j])*(tof-time[j])/(sig*sig))/sig;
223
224 // Check the mismatching
225 Double_t mass = AliPID::ParticleMass(j);
226 Double_t pm = fTOFResponse.GetMismatchProbability(track->GetP(),mass);
227 if (p[j]>pm) mismatch = kFALSE;
228
229 // Check for particles heavier than (AliPID::kSPECIES - 1)
230 if (tof < (time[j] + fRange*sig)) heavy=kFALSE;
231
232 }
233
234 if (mismatch)
235 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1/AliPID::kSPECIES;
236
237 track->SetTOFpid(p);
238
239 if (heavy) track->ResetStatus(AliESDtrack::kTOFpid);
f858b00e 240 if (!CheckTOFMatching(track)) track->SetStatus(AliESDtrack::kTOFmismatch);
241
10d100d4 242}
243//_________________________________________________________________________
b439f460 244void AliESDpid::MakeTRDPID(AliESDtrack *track) const
245{
246 //
247 // Method to recalculate the TRD PID probabilities
248 //
249 if((track->GetStatus()&AliESDtrack::kTRDout)==0) return;
250 Double_t prob[AliPID::kSPECIES]; Float_t mom[6];
251 Double_t dedx[48]; // Allocate space for the maximum number of TRD slices
252 for(Int_t ilayer = 0; ilayer < 6; ilayer++){
253 mom[ilayer] = track->GetTRDmomentum(ilayer);
254 for(Int_t islice = 0; islice < track->GetNumberOfTRDslices(); islice++){
255 dedx[ilayer*track->GetNumberOfTRDslices()+islice] = track->GetTRDslice(ilayer, islice);
256 }
257 }
258 fTRDResponse.GetResponse(track->GetNumberOfTRDslices(), dedx, mom, prob);
259 track->SetTRDpid(prob);
260}
261//_________________________________________________________________________
10d100d4 262void AliESDpid::CombinePID(AliESDtrack *track) const
263{
264 //
265 // Combine the information of various detectors
266 // to determine the Particle Identification
267 //
268 Int_t ns=AliPID::kSPECIES;
269 Double_t p[10]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};
270
271 if (track->IsOn(AliESDtrack::kITSpid)) {
272 Double_t d[10];
273 track->GetITSpid(d);
274 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
275 }
276
277 if (track->IsOn(AliESDtrack::kTPCpid)) {
278 Double_t d[10];
279 track->GetTPCpid(d);
280 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
281 }
282
283 if (track->IsOn(AliESDtrack::kTRDpid)) {
284 Double_t d[10];
285 track->GetTRDpid(d);
286 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
287 }
288
289 if (track->IsOn(AliESDtrack::kTOFpid)) {
290 Double_t d[10];
291 track->GetTOFpid(d);
292 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
293 }
294
295 if (track->IsOn(AliESDtrack::kHMPIDpid)) {
296 Double_t d[10];
297 track->GetHMPIDpid(d);
298 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
299 }
300
301 track->SetESDpid(p);
8c6a71ab 302}
f858b00e 303//_________________________________________________________________________
304Bool_t AliESDpid::CheckTOFMatching(AliESDtrack *track) const{
305 Bool_t status = kFALSE;
306
307 Double_t exptimes[5];
308 track->GetIntegratedTimes(exptimes);
309
310 Float_t dedx = track->GetTPCsignal();
311 Float_t time = track->GetTOFsignal();
312
313 Float_t p = track->P();
314
315 Double_t ptpc[3];
316 track->GetInnerPxPyPz(ptpc);
317 Float_t momtpc=TMath::Sqrt(ptpc[0]*ptpc[0] + ptpc[1]*ptpc[1] + ptpc[2]*ptpc[2]);
318
319 for(Int_t i=0;i < 5;i++){
320 AliPID::EParticleType type=AliPID::EParticleType(i);
321
322 Float_t resolutionTOF = fTOFResponse.GetExpectedSigma(p, exptimes[i], AliPID::ParticleMass(i));
323 if(TMath::Abs(exptimes[i] - time) < fRange * resolutionTOF){
324 Float_t dedxExp = fTPCResponse.GetExpectedSignal(momtpc,type);
325 Float_t resolutionTPC = fTPCResponse.GetExpectedSigma(momtpc,track->GetTPCsignalN(),type);
326
327 if(TMath::Abs(dedx - dedxExp) < fRange * resolutionTPC){
328 status = kTRUE;
329 }
330 }
331 }
332
333 // for nuclei
334 Float_t dedxExpPr = fTPCResponse.GetExpectedSignal(momtpc,AliPID::kProton);
335 Float_t resolutionTPCpr = fTPCResponse.GetExpectedSigma(momtpc,track->GetTPCsignalN(),AliPID::kProton);
336 if(!status && (exptimes[4] < time && dedx > dedxExpPr + resolutionTPCpr*fRange)) status = kTRUE;
337
338
339 return status;
340}
341//_________________________________________________________________________
342void AliESDpid::SetTOFResponse(AliESDEvent *event,EStartTimeType_t option){
343 //
344 // Set TOF response function
345 // Input option for event_time used
346 //
347
348 Float_t t0spread = 0.; //event->GetEventTimeSpread();
349 if(t0spread < 10) t0spread = 80;
350
351 // T0 from TOF algorithm
352 //Float_t t0Gen,t0ResGen;
353 //Int_t nt0;
354 //Float_t t0ESD[fTOFResponse.GetNmomBins()],t0resESD[fTOFResponse.GetNmomBins()];
355 //Int_t it0ESD[fTOFResponse.GetNmomBins()];
356
357 Bool_t flagT0TOF=kFALSE;
358 Bool_t flagT0T0=kFALSE;
359 Float_t startTime[fTOFResponse.GetNmomBins()];
360 Float_t startTimeRes[fTOFResponse.GetNmomBins()];
361
362 Float_t estimatedT0event[fTOFResponse.GetNmomBins()];
363 Float_t estimatedT0resolution[fTOFResponse.GetNmomBins()];
364 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
365 estimatedT0event[i]=0.0;
366 estimatedT0resolution[i]=0.0;
367 }
368
369 if(event->GetT0TOF()){
370 flagT0T0=kTRUE;
371 }
372
373
374 AliTOFHeader *tofHeader =(AliTOFHeader*)event->GetTOFHeader();
375
376 if(tofHeader){
377
378 flagT0TOF=kTRUE;
379 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
380 startTime[i]=tofHeader->GetDefaultEventTimeVal();//t0Gen;
381 startTimeRes[i]=tofHeader->GetDefaultEventTimeRes();//t0ResGen;
382 }
383
384 TArrayI *ibin=tofHeader->GetNvalues();
385 TArrayF *t0Bin=tofHeader->GetEventTimeValues();
386 TArrayF *t0ResBin=tofHeader->GetEventTimeRes();
387 for(Int_t j=0;j < tofHeader->GetNbins();j++){
388 Int_t icurrent = (Int_t)ibin->GetAt(j);
389 startTime[icurrent]=t0Bin->GetAt(j);//t0ESD[j];
390 startTimeRes[icurrent]=t0ResBin->GetAt(j);//t0resESD[j];
391 }
392 }
393
394 if(option == kFILL_T0){ // T0-FILL is used
395 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
396 estimatedT0event[i]=0.0;
397 estimatedT0resolution[i]=t0spread;
398 //fT0event[i] = 0.0;
399 //fT0resolution[i] = t0spread;
400 }
401 fTOFResponse.SetT0event(estimatedT0event);
402 fTOFResponse.SetT0resolution(estimatedT0resolution);
403 }
404 if(option == kTOF_T0){ // T0-TOF is used when available (T0-FILL otherwise) from ESD
405 if(flagT0TOF){
406 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
407 estimatedT0event[i]=0.0;
408 estimatedT0resolution[i]=t0spread;
409 //fT0event[i] = startTime[i];
410 //fT0resolution[i] = startTimeRes[i];
411 }
412 fTOFResponse.SetT0event(startTime);
413 fTOFResponse.SetT0resolution(startTimeRes);
414 }
415 else{
416 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
417 estimatedT0event[i]=0.0;
418 estimatedT0resolution[i]=t0spread;
419 //fT0event[i] = 0.0;
420 //fT0resolution[i] = t0spread;
421 }
422 fTOFResponse.SetT0event(estimatedT0event);
423 fTOFResponse.SetT0resolution(estimatedT0resolution);
424 }
425 }
426 else if(option == kBest_T0){ // T0-T0 is used when available (T0-FILL otherwise) from ESD
427 Float_t t0AC=-10000;
428 Float_t t0A=-10000;
429 Float_t t0C=-10000;
430 if(flagT0T0){
431 t0AC= event->GetT0TOF()[0];
432 t0A= event->GetT0TOF()[1];
433 t0C= event->GetT0TOF()[2];
434 }
435
436 Float_t t0t0Best = 0;
437 Float_t t0t0BestRes = 9999;
438 if(TMath::Abs(t0AC) < 500){
439 t0t0Best = t0AC;
440 t0t0BestRes = 55;
441 }
442 else if(TMath::Abs(t0A) < 500){
443 t0t0Best = t0A;
444 t0t0BestRes = 75;
445 }
446 else if(TMath::Abs(t0C) < 500){
447 t0t0Best = t0C;
448 t0t0BestRes = 65;
449 }
450
451 if(flagT0TOF){ // if T0-TOF info is available
452 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
453 if(t0t0BestRes<300){
454 if(startTimeRes[i]<t0spread){
455 Double_t wtot = 1./startTimeRes[i]/startTimeRes[i] + 1./t0t0BestRes/t0t0BestRes;
456 Double_t t0best = startTime[i]/startTimeRes[i]/startTimeRes[i] + t0t0Best/t0t0BestRes/t0t0BestRes;
457 estimatedT0event[i]=t0best / wtot;
458 estimatedT0resolution[i]=1./TMath::Sqrt(wtot);
459 //fT0event[i]=t0best / wtot;
460 //fT0resolution[i]=1./TMath::Sqrt(wtot);
461 }
462 else {
463 estimatedT0event[i]=t0t0Best;
464 estimatedT0resolution[i]=t0t0BestRes;
465 //fT0event[i] = t0t0Best;
466 //fT0resolution[i] = t0t0BestRes;
467 }
468 }
469 else{
470 estimatedT0event[i]=startTime[i];
471 estimatedT0resolution[i]=startTimeRes[i];
472 //fT0event[i] = startTime[i];
473 //fT0resolution[i] = startTimeRes[i];
474 }
475 }
476 fTOFResponse.SetT0event(estimatedT0event);
477 fTOFResponse.SetT0resolution(estimatedT0resolution);
478 }
479 else{ // if no T0-TOF info is available
480 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
481 if(t0t0BestRes<300){
482 estimatedT0event[i]=t0t0Best;
483 estimatedT0resolution[i]=t0t0BestRes;
484 //fT0event[i] = t0t0Best;
485 //fT0resolution[i] = t0t0BestRes;
486 }
487 else{
488 estimatedT0event[i]=0.0;
489 estimatedT0resolution[i]=t0spread;
490 //fT0event[i] = 0.0;
491 //fT0resolution[i] = t0spread;
492 }
493 }
494 fTOFResponse.SetT0event(estimatedT0event);
495 fTOFResponse.SetT0resolution(estimatedT0resolution);
496 }
497 }
498 else if(option == kT0_T0){ // the best of what available (T0-FILL otherwise) from ESD
499 Float_t t0AC=-10000;
500 Float_t t0A=-10000;
501 Float_t t0C=-10000;
502 if(flagT0T0){
503 t0AC= event->GetT0TOF()[0];
504 t0A= event->GetT0TOF()[1];
505 t0C= event->GetT0TOF()[2];
506 }
507
508// printf("T0_T0 = %f %f %f\n",t0AC,t0A,t0C);
509
510 if(TMath::Abs(t0AC) < 500){
511 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
512 estimatedT0event[i]=t0AC;
513 estimatedT0resolution[i]=55;
514 //fT0event[i] = t0AC;
515 //fT0resolution[i] = 55;
516 }
517 }
518 else if(TMath::Abs(t0A) < 500){
519 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
520 estimatedT0event[i]=t0A;
521 estimatedT0resolution[i]=75;
522 //fT0event[i] = t0A;
523 //fT0resolution[i] = 75;
524 }
525 }
526 else if(TMath::Abs(t0C) < 500){
527 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
528 estimatedT0event[i]=t0C;
529 estimatedT0resolution[i]=65;
530 //fT0event[i] = t0C;
531 //fT0resolution[i] = 65;
532 }
533 }
534 else{
535 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
536 estimatedT0event[i]=0.0;
537 estimatedT0resolution[i]=t0spread;
538 //fT0event[i] = 0.0;
539 //fT0resolution[i] = t0spread;
540 }
541 }
542 fTOFResponse.SetT0event(estimatedT0event);
543 fTOFResponse.SetT0resolution(estimatedT0resolution);
544 }
545}