* provided "as is" without express or implied warranty. *
**************************************************************************/
-//-----------------------------------------------------------------
-// Implementation of the TOF PID class
-// Very naive one... Should be made better by the detector experts...
-// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
-//-----------------------------------------------------------------
-#include "TFile.h"
-#include "TTree.h"
-#include "TClonesArray.h"
-#include "TError.h"
+//-----------------------------------------------------------------//
+// //
+// Implementation of the TOF PID class //
+// Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch //
+// //
+//-----------------------------------------------------------------//
-#include "AliTOFpidESD.h"
-#include "AliESD.h"
-#include "AliESDtrack.h"
-#include "AliTOFdigit.h"
-#include "AliTOFGeometry.h"
+#include "TMath.h"
+#include "AliLog.h"
-#include <stdlib.h>
+#include "AliESDtrack.h"
+#include "AliESDEvent.h"
+#include "AliTOFpidESD.h"
ClassImp(AliTOFpidESD)
//_________________________________________________________________________
-AliTOFpidESD::AliTOFpidESD(Double_t *param) {
+AliTOFpidESD::AliTOFpidESD():
+ fSigma(0),
+ fRange(0),
+ fPmax(0), // zero at 0.5 GeV/c for pp
+ fTime0(0)
+{
+}
+//_________________________________________________________________________
+AliTOFpidESD::AliTOFpidESD(Double_t *param):
+ fSigma(param[0]),
+ fRange(param[1]),
+ fPmax(0), // zero at 0.5 GeV/c for pp
+ fTime0(0)
+{
//
// The main constructor
//
- fR=378.;
- fDy=AliTOFGeometry::XPad(); fDz=AliTOFGeometry::ZPad();
- fN=0; fEventN=0;
-
- fSigma=param[0];
- fRange=param[1];
+ //
+ //fPmax=TMath::Exp(-0.5*3*3)/fSigma; // ~3 sigma at 0.5 GeV/c for PbPb
}
//_________________________________________________________________________
-Int_t AliTOFpidESD::LoadClusters(TTree *dTree, AliTOFGeometry *geom) {
- //--------------------------------------------------------------------
- //This function loads the TOF clusters
- //--------------------------------------------------------------------
- TBranch *branch=dTree->GetBranch("TOF");
- if (!branch) {
- Error("LoadClusters"," can't get the branch with the TOF digits !\n");
- return 1;
- }
-
- TClonesArray dummy("AliTOFdigit",10000), *digits=&dummy;
- branch->SetAddress(&digits);
-
- dTree->GetEvent(0);
- Int_t nd=digits->GetEntriesFast();
- Info("LoadClusters","number of digits: %d",nd);
-
- for (Int_t i=0; i<nd; i++) {
- AliTOFdigit *d=(AliTOFdigit*)digits->UncheckedAt(i);
- Int_t dig[5]; Float_t g[3];
- dig[0]=d->GetSector();
- dig[1]=d->GetPlate();
- dig[2]=d->GetStrip();
- dig[3]=d->GetPadz();
- dig[4]=d->GetPadx();
-
- geom->GetPos(dig,g);
-
- Double_t h[5];
- h[0]=TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
- h[1]=TMath::ATan2(g[1],g[0]); h[2]=g[2];
- h[3]=d->GetTdc(); h[4]=d->GetAdc();
-
- AliTOFcluster *cl=new AliTOFcluster(h,d->GetTracks(),i);
- InsertCluster(cl);
- }
+Double_t
+AliTOFpidESD::GetMismatchProbability(Double_t p, Double_t mass) const {
+ //
+ // Returns the probability of mismatching
+ // assuming 1/(p*beta)^2 scaling
+ //
+ const Double_t km=0.5; // "reference" momentum (GeV/c)
- return 0;
-}
+ Double_t ref2=km*km*km*km/(km*km + mass*mass);// "reference" (p*beta)^2
+ Double_t p2beta2=p*p*p*p/(p*p + mass*mass);
-//_________________________________________________________________________
-void AliTOFpidESD::UnloadClusters() {
- //--------------------------------------------------------------------
- //This function unloads TOF clusters
- //--------------------------------------------------------------------
- for (Int_t i=0; i<fN; i++) delete fClusters[i];
- fN=0;
+ return fPmax*ref2/p2beta2;
}
//_________________________________________________________________________
-Int_t AliTOFpidESD::InsertCluster(AliTOFcluster *c) {
- //--------------------------------------------------------------------
- //This function adds a cluster to the array of clusters sorted in Z
- //--------------------------------------------------------------------
- if (fN==kMaxCluster) {
- Error("InsertCluster","Too many clusters !\n");
- return 1;
- }
-
- if (fN==0) {fClusters[fN++]=c; return 0;}
- Int_t i=FindClusterIndex(c->GetZ());
- memmove(fClusters+i+1 ,fClusters+i,(fN-i)*sizeof(AliTOFcluster*));
- fClusters[i]=c; fN++;
-
- return 0;
-}
+Int_t AliTOFpidESD::MakePID(AliESDEvent *event, Double_t timeZero)
+{
+ //
+ // This function calculates the "detector response" PID probabilities
+ // Just for a bare hint...
-//_________________________________________________________________________
-Int_t AliTOFpidESD::FindClusterIndex(Double_t z) const {
- //--------------------------------------------------------------------
- // This function returns the index of the nearest cluster
- //--------------------------------------------------------------------
- if (fN==0) return 0;
- if (z <= fClusters[0]->GetZ()) return 0;
- if (z > fClusters[fN-1]->GetZ()) return fN;
- Int_t b=0, e=fN-1, m=(b+e)/2;
- for (; b<e; m=(b+e)/2) {
- if (z > fClusters[m]->GetZ()) b=m+1;
- else e=m;
- }
- return m;
-}
+ AliDebug(1,Form("TOF PID Parameters: Sigma (ps)= %f, Range= %f",fSigma,fRange));
+ AliDebug(1,"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n");
-static int cmp(const void *p1, const void *p2) {
- AliESDtrack *t1=*((AliESDtrack**)p1);
- AliESDtrack *t2=*((AliESDtrack**)p2);
- Double_t c1[15]; t1->GetExternalCovariance(c1);
- Double_t c2[15]; t2->GetExternalCovariance(c2);
- if (c1[0]*c1[2] <c2[0]*c2[2]) return -1;
- if (c1[0]*c1[2]==c2[0]*c2[2]) return 0;
- return 1;
+ fTime0=timeZero;
+ return MakePID(event);
}
//_________________________________________________________________________
-Int_t AliTOFpidESD::MakePID(AliESD *event)
+Int_t AliTOFpidESD::MakePID(AliESDEvent *event)
{
//
// This function calculates the "detector response" PID probabilities
// Just for a bare hint...
- static const Double_t kMasses[]={
- 0.000511, 0.105658, 0.139570, 0.493677, 0.938272, 1.875613
- };
-
Int_t ntrk=event->GetNumberOfTracks();
AliESDtrack **tracks=new AliESDtrack*[ntrk];
AliESDtrack *t=event->GetTrack(i);
tracks[i]=t;
}
- qsort(tracks,ntrk,sizeof(AliESDtrack*),cmp);
- Int_t nmatch=0;
for (i=0; i<ntrk; i++) {
AliESDtrack *t=tracks[i];
+ if ((t->GetStatus()&AliESDtrack::kTOFout)==0) continue;
+ if ((t->GetStatus()&AliESDtrack::kTIME)==0) continue;
- if ((t->GetStatus()&AliESDtrack::kTRDout)==0) continue;
- if ((t->GetStatus()&AliESDtrack::kTRDStop)!=0) continue;
-
- Double_t x,par[5]; t->GetExternalParameters(x,par);
- Double_t cov[15]; t->GetExternalCovariance(cov);
+ Double_t time[AliPID::kSPECIES];
+ if (!ExpectedSignals(t,time,AliPID::kSPECIES)) continue;
+ Double_t sigma[AliPID::kSPECIES];
+ if (!ExpectedSigmas(t,sigma,AliPID::kSPECIES)) continue;
+
+ AliDebug(2,Form("Expected TOF signals [ps]: %f %f %f %f %f",
+ GetExpectedSignal(t,AliPID::kElectron),
+ GetExpectedSignal(t,AliPID::kMuon),
+ GetExpectedSignal(t,AliPID::kPion),
+ GetExpectedSignal(t,AliPID::kKaon),
+ GetExpectedSignal(t,AliPID::kProton)
+ ));
+
+ AliDebug(2,Form("Expected TOF std deviations [ps]: %f %f %f %f %f",
+ GetExpectedSigma(t,AliPID::kElectron),
+ GetExpectedSigma(t,AliPID::kMuon),
+ GetExpectedSigma(t,AliPID::kPion),
+ GetExpectedSigma(t,AliPID::kKaon),
+ GetExpectedSigma(t,AliPID::kProton)
+ ));
+
+ AliDebug(2,Form("Expected TOF std deviations [number of expected sigmas]: %f %f %f %f %f",
+ GetNumberOfSigmas(t,AliPID::kElectron),
+ GetNumberOfSigmas(t,AliPID::kMuon),
+ GetNumberOfSigmas(t,AliPID::kPion),
+ GetNumberOfSigmas(t,AliPID::kKaon),
+ GetNumberOfSigmas(t,AliPID::kProton)
+ ));
+
+ Double_t tof = t->GetTOFsignal() - fTime0;
+
+ Double_t p[AliPID::kSPECIES];
+ Bool_t mismatch = kTRUE, heavy = kTRUE;
+ for (Int_t j=0; j<AliPID::kSPECIES; j++) {
+ Double_t sig = sigma[j];
+ if (TMath::Abs(tof-time[j]) > fRange*sig) {
+ p[j] = TMath::Exp(-0.5*fRange*fRange)/sig;
+ } else
+ p[j] = TMath::Exp(-0.5*(tof-time[j])*(tof-time[j])/(sig*sig))/sig;
+
+ // Check the mismatching
+ Double_t mass = AliPID::ParticleMass(j);
+ Double_t pm = GetMismatchProbability(t->GetP(),mass);
+ if (p[j]>pm) mismatch = kFALSE;
+
+ // Check for particles heavier than (AliPID::kSPECIES - 1)
+ if (tof < (time[j] + fRange*sig)) heavy=kFALSE;
-Double_t dphi=(5*TMath::Sqrt(cov[0]) + 0.5*fDy + 2.5*TMath::Abs(par[2]))/fR;
-Double_t dz=5*TMath::Sqrt(cov[2]) + 0.5*fDz + 2.5*TMath::Abs(par[3]);
+ }
- Double_t phi=TMath::ATan2(par[0],x) + t->GetAlpha();
- if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
- if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
- Double_t z=par[1];
+ if (mismatch)
+ for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1/AliPID::kSPECIES;
- Double_t d2max=1000.;
- Int_t index=-1;
- for (Int_t k=FindClusterIndex(z-dz); k<fN; k++) {
- AliTOFcluster *c=fClusters[k];
+ t->SetTOFpid(p);
- if (c->GetZ() > z+dz) break;
- if (c->IsUsed()) continue;
+ if (heavy) t->ResetStatus(AliESDtrack::kTOFpid);
- Double_t dph=TMath::Abs(c->GetPhi()-phi);
- if (dph>TMath::Pi()) dph-=TMath::Pi();
- if (dph>dphi) continue;
+ }
- Double_t d2=dph*dph*fR*fR + (c->GetZ()-z)*(c->GetZ()-z);
- if (d2 > d2max) continue;
+ delete[] tracks;
+
+ return 0;
+}
- d2max=d2;
- index=k;
- }
+//_________________________________________________________________________
+Bool_t AliTOFpidESD::ExpectedSignals(const AliESDtrack *t,
+ Double_t s[],Int_t n) const
+{
+ //
+ // Return the expected PID signals for the involved particle species
+ //
- if (index<0) {
- //Info("MakePID","matching failed ! %d",TMath::Abs(t->GetLabel()));
- continue;
- }
+ if (n > AliPID::kSPECIESN) return kFALSE;
+ if ( !t->IsOn(AliESDtrack::kTIME) ) return kFALSE;
- nmatch++;
+ Double_t time[AliPID::kSPECIESN];
+ t->GetIntegratedTimes(time);
+ for (Int_t i=0; i<n; i++) s[i]=time[i];
+ return kTRUE;
+}
- AliTOFcluster *c=fClusters[index];
- c->Use();
+//_________________________________________________________________________
+Bool_t AliTOFpidESD::ExpectedSigmas(const AliESDtrack *t,
+ Double_t s[],Int_t n) const
+{
+ //
+ // Return the expected sigma of PID signals for the involved
+ // particle species.
+ // This approximate (but reasonable) formula takes into account the
+ // relative momentum resolution.
+ //
- Double_t tof=50*c->GetTDC()+32; // in ps
- t->SetTOFsignal(tof);
- t->SetTOFcluster(c->GetIndex());
+ Double_t time[AliPID::kSPECIESN];
+ if ( !ExpectedSignals(t,time,n) ) return kFALSE;
- if ((t->GetStatus()&AliESDtrack::kTIME)==0) continue;
+ Double_t mom = t->GetP();
+ Double_t dpp = 0.01; //mean relative pt resolution;
+ if (mom>0.5) dpp = 0.01*mom;
+ for (Int_t i=0; i<n; i++) {
+ Double_t mass = AliPID::ParticleMass(i);
+ Double_t sigma = dpp*time[i]/(1.+ mom*mom/(mass*mass));
+ s[i] = TMath::Sqrt(sigma*sigma + fSigma*fSigma);
+ }
+ return kTRUE;
+}
- Double_t time[10]; t->GetIntegratedTimes(time);
+//_________________________________________________________________________
+Bool_t AliTOFpidESD::NumberOfSigmas(const AliESDtrack *t,
+ Double_t s[],Int_t n) const
+{
+ //
+ // Returns the deviation of the actual PID signal from the expected
+ // signal, in units of expected sigmas.
+ //
- //track length correction
- Double_t rc=TMath::Sqrt(c->GetR()*c->GetR() + c->GetZ()*c->GetZ());
- Double_t rt=TMath::Sqrt(x*x + par[0]*par[0] + par[1]*par[1]);
- Double_t dlt=rc-rt;
+ Double_t time[AliPID::kSPECIESN];
+ if ( !ExpectedSignals(t,time,n) ) return kFALSE;
- Double_t p[10];
- Double_t mom=t->GetP();
- for (Int_t j=0; j<AliESDtrack::kSPECIES; j++) {
+ if ( !ExpectedSigmas(t,s,n) ) return kFALSE;
+
+ Double_t tof = t->GetTOFsignal() - fTime0;
+ for (Int_t i=0; i<n; i++) s[i] = (time[i]-tof)/s[i];
- p[j]=1.00/AliESDtrack::kSPECIES; // don't do anything
- if (mom<0.7) continue; // with the low momenta
-
- Double_t mass=kMasses[j];
- Double_t dpp=0.01; //mean relative pt resolution;
- if (mom>0.5) dpp=0.01*mom;
- Double_t sigma=dpp*time[j]/(1.+ mom*mom/(mass*mass));
- sigma=TMath::Sqrt(sigma*sigma + fSigma*fSigma);
-
- time[j]+=dlt/3e-2*TMath::Sqrt(mom*mom+mass*mass)/mom;
-
- if (TMath::Abs(tof-time[j]) > fRange*sigma) {
- p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
- continue;
- }
- p[j]=TMath::Exp(-0.5*(tof-time[j])*(tof-time[j])/(sigma*sigma))/sigma;
- }
- /*
- if (c->GetLabel(0)!=TMath::Abs(t->GetLabel())) {
- cerr<<"Wrong matching: "<<t->GetLabel()<<endl;
- continue;
- }
- */
- t->SetTOFpid(p);
+ return kTRUE;
+}
- }
+//_________________________________________________________________________
+ Double_t AliTOFpidESD::GetExpectedSignal(const AliESDtrack *t,
+ AliPID::EParticleType n) const
+{
+ //
+ // Return the expected PID signal for the specified particle type.
+ // If the operation is not possible, return a negative value.
+ //
- Info("MakePID","Number of matched ESD track: %d",nmatch);
+ if (Int_t(n) >= AliPID::kSPECIESN) return -1.;
+ if ( !t->IsOn(AliESDtrack::kTIME) ) return -1.;
- delete[] tracks;
+ Double_t time[AliPID::kSPECIESN];
+ t->GetIntegratedTimes(time);
- return 0;
+ return time[n];
+}
+
+//_________________________________________________________________________
+ Double_t AliTOFpidESD::GetExpectedSigma(const AliESDtrack *t,
+ AliPID::EParticleType n) const
+{
+ //
+ // Return the expected sigma of the PID signal for the specified
+ // particle type.
+ // If the operation is not possible, return a negative value.
+ //
+
+ Double_t time[AliPID::kSPECIESN];
+ if ( !ExpectedSignals(t,time,AliPID::kSPECIESN) ) return -1.;
+
+ Double_t mom = t->GetP();
+ Double_t dpp = 0.01; //mean relative pt resolution;
+ if (mom>0.5) dpp = 0.01*mom;
+
+ Double_t mass = AliPID::ParticleMass(n);
+ Double_t sigma = dpp*time[n]/(1.+ mom*mom/(mass*mass));
+
+ return TMath::Sqrt(sigma*sigma + fSigma*fSigma);
}
+//_________________________________________________________________________
+ Double_t AliTOFpidESD::GetNumberOfSigmas(const AliESDtrack *t,
+ AliPID::EParticleType n) const
+{
+ //
+ // Returns the deviation of the actual PID signal from the expected
+ // signal for the specified particle type, in units of expected
+ // sigmas.
+ // If the operation is not possible, return a negative value.
+ //
+
+ Double_t time=GetExpectedSignal(t,n);;
+ if (time < 0.) return -1.;
+
+ Double_t sigma=GetExpectedSigma(t,n);
+ if (sigma < 0.) return -1;
+
+ Double_t tof=t->GetTOFsignal() - fTime0;
+ return (time-tof)/sigma;
+}