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 **************************************************************************/
18 //-----------------------------------------------------------------
19 // Implementation of the combined PID class
20 // For the Event Summary Data Class
21 // produced by the reconstruction process
22 // and containing information on the particle identification
23 // Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
24 //-----------------------------------------------------------------
31 #include "AliTOFHeader.h"
32 #include "AliESDpid.h"
33 #include "AliESDEvent.h"
34 #include "AliESDtrack.h"
38 Int_t AliESDpid::MakePID(AliESDEvent *event, Bool_t TPConly, Float_t timeZeroTOF) const {
40 // Calculate probabilities for all detectors, except if TPConly==kTRUE
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
49 Float_t timeZeroTOF = 0;
51 timeZeroTOF = event->GetT0();
53 Int_t nTrk=event->GetNumberOfTracks();
54 for (Int_t iTrk=0; iTrk<nTrk; iTrk++) {
55 AliESDtrack *track=event->GetTrack(iTrk);
59 MakeTOFPID(track, timeZeroTOF);
60 //MakeHMPIDPID(track);
67 //_________________________________________________________________________
68 void AliESDpid::MakeTPCPID(AliESDtrack *track) const
71 // TPC pid using bethe-bloch and gaussian response
73 if ((track->GetStatus()&AliESDtrack::kTPCin )==0)
74 if ((track->GetStatus()&AliESDtrack::kTPCout)==0) return;
76 Double_t mom = track->GetP();
77 const AliExternalTrackParam *in=track->GetInnerParam();
78 if (in) mom = in->GetP();
80 Double_t p[AliPID::kSPECIES];
81 Double_t dedx=track->GetTPCsignal();
82 Bool_t mismatch=kTRUE, heavy=kTRUE;
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;
91 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
95 // Check for particles heavier than (AliPID::kSPECIES - 1)
96 if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
101 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1/AliPID::kSPECIES;
105 if (heavy) track->ResetStatus(AliESDtrack::kTPCpid);
108 //_________________________________________________________________________
109 void AliESDpid::MakeITSPID(AliESDtrack *track) const
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
119 if ((track->GetStatus()&AliESDtrack::kITSin)==0 &&
120 (track->GetStatus()&AliESDtrack::kITSout)==0) return;
122 Double_t mom=track->GetP();
123 if (fITSPIDmethod == kITSTruncMean) {
124 Double_t dedx=track->GetITSsignal();
127 ULong_t trStatus=track->GetStatus();
128 if(trStatus&AliESDtrack::kTPCin) isSA=kFALSE;
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;
135 if(nPointsForPid<3) { // track not to be used for combined PID purposes
136 track->ResetStatus(AliESDtrack::kITSpid);
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
145 Double_t bethe=fITSResponse.Bethe(momITS,mass);
146 Double_t sigma=fITSResponse.GetResolution(bethe,nPointsForPid,isSA);
147 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
148 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
150 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
154 // Check for particles heavier than (AliPID::kSPECIES - 1)
155 if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
160 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
164 if (heavy) track->ResetStatus(AliESDtrack::kITSpid);
166 else { // Likelihood method
167 Double_t condprobfun[AliPID::kSPECIES];
169 track->GetITSdEdxSamples(qclu);
170 fITSResponse.GetITSProbabilities(mom,qclu,condprobfun);
171 track->SetITSpid(condprobfun);
175 //_________________________________________________________________________
176 void AliESDpid::MakeTOFPID(AliESDtrack *track, Float_t /*timeZeroTOF*/) const
179 // TOF PID using gaussian response
182 if ((track->GetStatus()&AliESDtrack::kTOFout)==0) return;
183 if ((track->GetStatus()&AliESDtrack::kTIME)==0) return;
185 Int_t ibin = fTOFResponse.GetMomBin(track->GetP());
186 Float_t timezero = fTOFResponse.GetT0bin(ibin);
188 Double_t time[AliPID::kSPECIESN];
189 track->GetIntegratedTimes(time);
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));
196 AliDebugGeneral("AliESDpid::MakeTOFPID",2,
197 Form("Expected TOF signals [ps]: %f %f %f %f %f",
198 time[AliPID::kElectron],
202 time[AliPID::kProton]));
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]
213 Double_t tof = track->GetTOFsignal() - timezero;
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];
219 if (TMath::Abs(tof-time[j]) > (fRange+2)*sig) {
220 p[j] = TMath::Exp(-0.5*(fRange+2)*(fRange+2))/sig;
222 p[j] = TMath::Exp(-0.5*(tof-time[j])*(tof-time[j])/(sig*sig))/sig;
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;
229 // Check for particles heavier than (AliPID::kSPECIES - 1)
230 if (tof < (time[j] + fRange*sig)) heavy=kFALSE;
235 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1/AliPID::kSPECIES;
239 if (heavy) track->ResetStatus(AliESDtrack::kTOFpid);
240 if (!CheckTOFMatching(track)) track->SetStatus(AliESDtrack::kTOFmismatch);
243 //_________________________________________________________________________
244 void AliESDpid::MakeTRDPID(AliESDtrack *track) const
247 // Method to recalculate the TRD PID probabilities
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);
258 fTRDResponse.GetResponse(track->GetNumberOfTRDslices(), dedx, mom, prob);
259 track->SetTRDpid(prob);
261 //_________________________________________________________________________
262 void AliESDpid::CombinePID(AliESDtrack *track) const
265 // Combine the information of various detectors
266 // to determine the Particle Identification
268 Int_t ns=AliPID::kSPECIES;
269 Double_t p[10]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};
271 if (track->IsOn(AliESDtrack::kITSpid)) {
274 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
277 if (track->IsOn(AliESDtrack::kTPCpid)) {
280 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
283 if (track->IsOn(AliESDtrack::kTRDpid)) {
286 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
289 if (track->IsOn(AliESDtrack::kTOFpid)) {
292 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
295 if (track->IsOn(AliESDtrack::kHMPIDpid)) {
297 track->GetHMPIDpid(d);
298 for (Int_t j=0; j<ns; j++) p[j]*=d[j];
303 //_________________________________________________________________________
304 Bool_t AliESDpid::CheckTOFMatching(AliESDtrack *track) const{
305 Bool_t status = kFALSE;
307 Double_t exptimes[5];
308 track->GetIntegratedTimes(exptimes);
310 Float_t p = track->P();
312 Float_t dedx = track->GetTPCsignal();
313 Float_t time = track->GetTOFsignal() - fTOFResponse.GetStartTime(p);
316 track->GetInnerPxPyPz(ptpc);
317 Float_t momtpc=TMath::Sqrt(ptpc[0]*ptpc[0] + ptpc[1]*ptpc[1] + ptpc[2]*ptpc[2]);
319 for(Int_t i=0;i < 5;i++){
320 AliPID::EParticleType type=AliPID::EParticleType(i);
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);
327 if(TMath::Abs(dedx - dedxExp) < fRangeTOFMismatch * resolutionTPC){
334 Float_t resolutionTOFpr = fTOFResponse.GetExpectedSigma(p, exptimes[4], AliPID::ParticleMass(4));
335 if(!status && (exptimes[4] + fRange*resolutionTOFpr < time)) status = kTRUE;
340 //_________________________________________________________________________
341 void AliESDpid::SetTOFResponse(AliESDEvent *event,EStartTimeType_t option){
343 // Set TOF response function
344 // Input option for event_time used
347 Float_t t0spread = 0.; //event->GetEventTimeSpread();
348 if(t0spread < 10) t0spread = 80;
350 // T0 from TOF algorithm
352 Bool_t flagT0TOF=kFALSE;
353 Bool_t flagT0T0=kFALSE;
354 Float_t *startTime = new Float_t[fTOFResponse.GetNmomBins()];
355 Float_t *startTimeRes = new Float_t[fTOFResponse.GetNmomBins()];
358 Float_t *estimatedT0event = new Float_t[fTOFResponse.GetNmomBins()];
359 Float_t *estimatedT0resolution = new Float_t[fTOFResponse.GetNmomBins()];
360 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
361 estimatedT0event[i]=0.0;
362 estimatedT0resolution[i]=0.0;
365 Float_t resT0A=75,resT0C=65,resT0AC=55;
366 if(event->GetT0TOF()){ // check if T0 detector information is available
371 AliTOFHeader *tofHeader =(AliTOFHeader*)event->GetTOFHeader();
373 if(tofHeader){ // read global info and T0-TOF info from ESD
374 fTOFResponse.SetTimeResolution(tofHeader->GetTOFResolution());
375 t0spread = tofHeader->GetT0spread(); // read t0 sprad
376 if(t0spread < 10) t0spread = 80;
379 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){ // read T0-TOF default value
380 startTime[i]=tofHeader->GetDefaultEventTimeVal();
381 startTimeRes[i]=tofHeader->GetDefaultEventTimeRes();
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++){ // fill T0-TOF in p-bins
388 Int_t icurrent = (Int_t)ibin->GetAt(j);
389 startTime[icurrent]=t0Bin->GetAt(j);
390 startTimeRes[icurrent]=t0ResBin->GetAt(j);
394 // for cut of 3 sigma on t0 spread
395 Float_t t0cut = 3 * t0spread;
396 if(t0cut < 500) t0cut = 500;
398 if(option == kFILL_T0){ // T0-FILL is used
399 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
400 estimatedT0event[i]=0.0;
401 estimatedT0resolution[i]=t0spread;
403 fTOFResponse.SetT0event(estimatedT0event);
404 fTOFResponse.SetT0resolution(estimatedT0resolution);
407 if(option == kTOF_T0){ // T0-TOF is used when available (T0-FILL otherwise) from ESD
409 fTOFResponse.SetT0event(startTime);
410 fTOFResponse.SetT0resolution(startTimeRes);
413 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
414 estimatedT0event[i]=0.0;
415 estimatedT0resolution[i]=t0spread;
417 fTOFResponse.SetT0event(estimatedT0event);
418 fTOFResponse.SetT0resolution(estimatedT0resolution);
421 else if(option == kBest_T0){ // T0-T0 is used when available (T0-FILL otherwise) from ESD
426 t0AC= event->GetT0TOF()[0];
427 t0A= event->GetT0TOF()[1];
428 t0C= event->GetT0TOF()[2];
431 Float_t t0t0Best = 0;
432 Float_t t0t0BestRes = 9999;
433 if(TMath::Abs(t0A) < t0cut && TMath::Abs(t0C) < t0cut && TMath::Abs(t0C-t0A) < 500){
435 t0t0BestRes = resT0AC;
437 else if(TMath::Abs(t0C) < t0cut){
439 t0t0BestRes = resT0C;
441 else if(TMath::Abs(t0A) < t0cut){
443 t0t0BestRes = resT0A;
446 if(flagT0TOF){ // if T0-TOF info is available
447 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
448 if(t0t0BestRes < 999){
449 if(startTimeRes[i] < t0spread){
450 Double_t wtot = 1./startTimeRes[i]/startTimeRes[i] + 1./t0t0BestRes/t0t0BestRes;
451 Double_t t0best = startTime[i]/startTimeRes[i]/startTimeRes[i] + t0t0Best/t0t0BestRes/t0t0BestRes;
452 estimatedT0event[i]=t0best / wtot;
453 estimatedT0resolution[i]=1./TMath::Sqrt(wtot);
456 estimatedT0event[i]=t0t0Best;
457 estimatedT0resolution[i]=t0t0BestRes;
461 estimatedT0event[i]=startTime[i];
462 estimatedT0resolution[i]=startTimeRes[i];
465 fTOFResponse.SetT0event(estimatedT0event);
466 fTOFResponse.SetT0resolution(estimatedT0resolution);
468 else{ // if no T0-TOF info is available
469 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
470 if(t0t0BestRes < 999){
471 estimatedT0event[i]=t0t0Best;
472 estimatedT0resolution[i]=t0t0BestRes;
475 estimatedT0event[i]=0.0;
476 estimatedT0resolution[i]=t0spread;
479 fTOFResponse.SetT0event(estimatedT0event);
480 fTOFResponse.SetT0resolution(estimatedT0resolution);
484 else if(option == kT0_T0){ // the best of what available (T0-FILL otherwise) from ESD
489 t0AC= event->GetT0TOF()[0];
490 t0A= event->GetT0TOF()[1];
491 t0C= event->GetT0TOF()[2];
494 if(TMath::Abs(t0A) < t0cut && TMath::Abs(t0C) < t0cut && TMath::Abs(t0C-t0A) < 500){
495 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
496 estimatedT0event[i]=t0AC;
497 estimatedT0resolution[i]=resT0AC;
500 else if(TMath::Abs(t0C) < t0cut){
501 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
502 estimatedT0event[i]=t0C;
503 estimatedT0resolution[i]=resT0C;
506 else if(TMath::Abs(t0A) < t0cut){
507 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
508 estimatedT0event[i]=t0A;
509 estimatedT0resolution[i]=resT0A;
513 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
514 estimatedT0event[i]=0.0;
515 estimatedT0resolution[i]=t0spread;
518 fTOFResponse.SetT0event(estimatedT0event);
519 fTOFResponse.SetT0resolution(estimatedT0resolution);
522 delete [] startTimeRes;
523 delete [] estimatedT0event;
524 delete [] estimatedT0resolution;