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: AliPIDResponse.cxx 46193 2010-12-21 09:00:14Z wiechula $ */
18 //-----------------------------------------------------------------
19 // Base class for handling the pid response //
20 // functions of all detectors //
21 // and give access to the nsigmas //
23 // Origin: Jens Wiechula, Uni Tuebingen, jens.wiechula@cern.ch //
24 //-----------------------------------------------------------------
27 #include <TObjArray.h>
33 #include <AliVEvent.h>
34 #include <AliVTrack.h>
37 #include <AliOADBContainer.h>
38 #include <AliTRDPIDReference.h>
40 #include "AliPIDResponse.h"
42 ClassImp(AliPIDResponse);
44 AliPIDResponse::AliPIDResponse(Bool_t isMC/*=kFALSE*/) :
45 TNamed("PIDResponse","PIDResponse"),
52 fITSPIDmethod(kITSTruncMean),
64 fArrPidResponseMaster(0x0),
65 fResolutionCorrection(0x0),
67 fTRDPIDReference(0x0),
68 fTOFTimeZeroType(kBest_T0),
75 AliLog::SetClassDebugLevel("AliPIDResponse",10);
76 AliLog::SetClassDebugLevel("AliESDpid",10);
77 AliLog::SetClassDebugLevel("AliAODpidUtil",10);
79 memset(fTRDslicesForPID,0,sizeof(UInt_t)*2);
82 //______________________________________________________________________________
83 AliPIDResponse::~AliPIDResponse()
88 delete fArrPidResponseMaster;
90 delete fTRDPIDReference;
93 //______________________________________________________________________________
94 AliPIDResponse::AliPIDResponse(const AliPIDResponse &other) :
96 fITSResponse(other.fITSResponse),
97 fTPCResponse(other.fTPCResponse),
98 fTRDResponse(other.fTRDResponse),
99 fTOFResponse(other.fTOFResponse),
100 fEMCALResponse(other.fEMCALResponse),
101 fRange(other.fRange),
102 fITSPIDmethod(other.fITSPIDmethod),
104 fOADBPath(other.fOADBPath),
108 fMCperiodUser(other.fMCperiodUser),
111 fRecoPassUser(other.fRecoPassUser),
114 fArrPidResponseMaster(0x0),
115 fResolutionCorrection(0x0),
117 fTRDPIDReference(0x0),
118 fTOFTimeZeroType(AliPIDResponse::kBest_T0),
125 memset(fTRDslicesForPID,0,sizeof(UInt_t)*2);
128 //______________________________________________________________________________
129 AliPIDResponse& AliPIDResponse::operator=(const AliPIDResponse &other)
135 delete fArrPidResponseMaster;
136 TNamed::operator=(other);
137 fITSResponse=other.fITSResponse;
138 fTPCResponse=other.fTPCResponse;
139 fTRDResponse=other.fTRDResponse;
140 fTOFResponse=other.fTOFResponse;
141 fEMCALResponse=other.fEMCALResponse;
143 fITSPIDmethod=other.fITSPIDmethod;
144 fOADBPath=other.fOADBPath;
149 fMCperiodUser=other.fMCperiodUser;
152 fRecoPassUser=other.fRecoPassUser;
155 fArrPidResponseMaster=0x0;
156 fResolutionCorrection=0x0;
158 fTRDPIDReference=0x0;
159 memset(fTRDslicesForPID,0,sizeof(UInt_t)*2);
160 fTOFTimeZeroType=AliPIDResponse::kBest_T0;
162 fCurrentEvent=other.fCurrentEvent;
167 //______________________________________________________________________________
168 Float_t AliPIDResponse::NumberOfSigmas(EDetCode detCode, const AliVParticle *track, AliPID::EParticleType type) const
171 // NumberOfSigmas for 'detCode'
175 case kDetITS: return NumberOfSigmasITS(track, type); break;
176 case kDetTPC: return NumberOfSigmasTPC(track, type); break;
177 case kDetTOF: return NumberOfSigmasTOF(track, type); break;
178 // case kDetTRD: return ComputeTRDProbability(track, type); break;
179 // case kDetPHOS: return ComputePHOSProbability(track, type); break;
180 // case kDetEMCAL: return NumberOfSigmasEMCAL(track, type); break;
181 // case kDetHMPID: return ComputeHMPIDProbability(track, type); break;
182 default: return -999.;
187 //______________________________________________________________________________
188 Float_t AliPIDResponse::NumberOfSigmasEMCAL(const AliVTrack *track, AliPID::EParticleType type) const {
190 AliVCluster *matchedClus = NULL;
195 Double_t fClsE = -1.;
197 Int_t nMatchClus = -1;
201 nMatchClus = track->GetEMCALcluster();
206 charge = track->Charge();
208 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
212 // matched cluster is EMCAL
213 if(matchedClus->IsEMCAL()){
215 fClsE = matchedClus->E();
219 // NSigma value really meaningful only for electrons!
220 return fEMCALResponse.GetNumberOfSigmas(pt,EovP,type,charge);
229 //______________________________________________________________________________
230 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePIDProbability (EDetCode detCode, const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
233 // Compute PID response of 'detCode'
237 case kDetITS: return ComputeITSProbability(track, nSpecies, p); break;
238 case kDetTPC: return ComputeTPCProbability(track, nSpecies, p); break;
239 case kDetTOF: return ComputeTOFProbability(track, nSpecies, p); break;
240 case kDetTRD: return ComputeTRDProbability(track, nSpecies, p); break;
241 case kDetPHOS: return ComputePHOSProbability(track, nSpecies, p); break;
242 case kDetEMCAL: return ComputeEMCALProbability(track, nSpecies, p); break;
243 case kDetHMPID: return ComputeHMPIDProbability(track, nSpecies, p); break;
244 default: return kDetNoSignal;
248 //______________________________________________________________________________
249 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeITSProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
252 // Compute PID response for the ITS
255 // set flat distribution (no decision)
256 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
258 if ((track->GetStatus()&AliVTrack::kITSin)==0 &&
259 (track->GetStatus()&AliVTrack::kITSout)==0) return kDetNoSignal;
261 Double_t mom=track->P();
262 Double_t dedx=track->GetITSsignal();
265 ULong_t trStatus=track->GetStatus();
266 if(trStatus&AliVTrack::kTPCin) isSA=kFALSE;
267 UChar_t clumap=track->GetITSClusterMap();
268 Int_t nPointsForPid=0;
269 for(Int_t i=2; i<6; i++){
270 if(clumap&(1<<i)) ++nPointsForPid;
273 if(nPointsForPid<3) { // track not to be used for combined PID purposes
274 // track->ResetStatus(AliVTrack::kITSpid);
278 Bool_t mismatch=kTRUE/*, heavy=kTRUE*/;
279 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
280 Double_t mass=AliPID::ParticleMass(j);//GeV/c^2
281 Double_t bethe=fITSResponse.Bethe(momITS,mass);
282 Double_t sigma=fITSResponse.GetResolution(bethe,nPointsForPid,isSA);
283 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
284 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
286 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
290 // Check for particles heavier than (AliPID::kSPECIES - 1)
291 // if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
296 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
303 //______________________________________________________________________________
304 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTPCProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
307 // Compute PID response for the TPC
310 // set flat distribution (no decision)
311 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
313 // check quality of the track
314 if ( (track->GetStatus()&AliVTrack::kTPCin )==0 && (track->GetStatus()&AliVTrack::kTPCout)==0 ) return kDetNoSignal;
316 Double_t mom = track->GetTPCmomentum();
318 Double_t dedx=track->GetTPCsignal();
319 Bool_t mismatch=kTRUE/*, heavy=kTRUE*/;
321 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
322 AliPID::EParticleType type=AliPID::EParticleType(j);
323 Double_t bethe=fTPCResponse.GetExpectedSignal(mom,type);
324 Double_t sigma=fTPCResponse.GetExpectedSigma(mom,track->GetTPCsignalN(),type);
325 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
326 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
328 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
332 // TODO: Light nuclei, also in TPC pid response
334 // Check for particles heavier than (AliPID::kSPECIES - 1)
335 // if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
340 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
346 //______________________________________________________________________________
347 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTOFProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
350 // Compute PID response for the
353 // set flat distribution (no decision)
354 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
356 if ((track->GetStatus()&AliVTrack::kTOFout)==0) return kDetNoSignal;
357 if ((track->GetStatus()&AliVTrack::kTIME)==0) return kDetNoSignal;
359 Double_t time[AliPID::kSPECIESN];
360 track->GetIntegratedTimes(time);
362 Double_t sigma[AliPID::kSPECIES];
363 for (Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++) {
364 sigma[iPart] = fTOFResponse.GetExpectedSigma(track->P(),time[iPart],AliPID::ParticleMass(iPart));
367 Bool_t mismatch = kTRUE/*, heavy = kTRUE*/;
368 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
369 AliPID::EParticleType type=AliPID::EParticleType(j);
370 Double_t nsigmas=NumberOfSigmasTOF(track,type);
372 Double_t sig = sigma[j];
373 if (TMath::Abs(nsigmas) > (fRange+2)) {
374 p[j] = TMath::Exp(-0.5*(fRange+2)*(fRange+2))/sig;
376 p[j] = TMath::Exp(-0.5*nsigmas*nsigmas)/sig;
378 if (TMath::Abs(nsigmas)<5.){
379 Double_t nsigmasTPC=NumberOfSigmasTPC(track,type);
380 if (TMath::Abs(nsigmasTPC)<5.) mismatch=kFALSE;
388 // TODO: Light nuclei
392 //______________________________________________________________________________
393 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTRDProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
396 // Compute PID response for the
399 // set flat distribution (no decision)
400 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
401 if((track->GetStatus()&AliVTrack::kTRDout)==0) return kDetNoSignal;
404 Double_t dedx[48]; // Allocate space for the maximum number of TRD slices
405 Int_t nslices = fTRDslicesForPID[1] - fTRDslicesForPID[0] + 1;
406 AliDebug(1, Form("First Slice: %d, Last Slice: %d, Number of slices: %d", fTRDslicesForPID[0], fTRDslicesForPID[1], nslices));
407 for(UInt_t ilayer = 0; ilayer < 6; ilayer++){
408 mom[ilayer] = track->GetTRDmomentum(ilayer);
409 for(UInt_t islice = fTRDslicesForPID[0]; islice <= fTRDslicesForPID[1]; islice++){
410 dedx[ilayer*nslices+islice-fTRDslicesForPID[0]] = track->GetTRDslice(ilayer, islice);
413 fTRDResponse.GetResponse(nslices, dedx, mom, p);
416 //______________________________________________________________________________
417 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeEMCALProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
420 // Compute PID response for the EMCAL
423 AliVCluster *matchedClus = NULL;
428 Double_t fClsE = -1.;
430 Int_t nMatchClus = -1;
434 nMatchClus = track->GetEMCALcluster();
440 charge = track->Charge();
442 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
446 // matched cluster is EMCAL
447 if(matchedClus->IsEMCAL()){
449 fClsE = matchedClus->E();
453 // compute the probabilities
454 if( 999 != fEMCALResponse.ComputeEMCALProbability(pt,EovP,charge,p)){
456 // in case everything is OK
464 // in all other cases set flat distribution (no decision)
465 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
469 //______________________________________________________________________________
470 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePHOSProbability (const AliVTrack */*track*/, Int_t nSpecies, Double_t p[]) const
473 // Compute PID response for the PHOS
476 // set flat distribution (no decision)
477 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
480 //______________________________________________________________________________
481 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeHMPIDProbability(const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
484 // Compute PID response for the HMPID
487 // set flat distribution (no decision)
488 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
489 if((track->GetStatus()&AliVTrack::kHMPIDpid)==0) return kDetNoSignal;
491 track->GetHMPIDpid(p);
496 //______________________________________________________________________________
497 void AliPIDResponse::InitialiseEvent(AliVEvent *event, Int_t pass)
500 // Apply settings for the current event
507 fRun=event->GetRunNumber();
514 //TPC resolution parametrisation PbPb
515 if ( fResolutionCorrection ){
516 Double_t corrSigma=fResolutionCorrection->Eval(GetTPCMultiplicityBin(event));
517 fTPCResponse.SetSigma(3.79301e-03*corrSigma, 2.21280e+04);
521 SetTOFResponse(event, (AliPIDResponse::EStartTimeType_t)fTOFTimeZeroType);
525 //______________________________________________________________________________
526 void AliPIDResponse::ExecNewRun()
529 // Things to Execute upon a new run
533 SetITSParametrisation();
535 SetTPCPidResponseMaster();
536 SetTPCParametrisation();
538 SetTRDPidResponseMaster();
539 InitializeTRDResponse();
541 fTOFResponse.SetTimeResolution(fTOFres);
544 //_____________________________________________________
545 Double_t AliPIDResponse::GetTPCMultiplicityBin(const AliVEvent * const event)
548 // Get TPC multiplicity in bins of 150
551 const AliVVertex* vertexTPC = event->GetPrimaryVertex();
552 Double_t tpcMulti=0.;
554 Double_t vertexContribTPC=vertexTPC->GetNContributors();
555 tpcMulti=vertexContribTPC/150.;
556 if (tpcMulti>20.) tpcMulti=20.;
562 //______________________________________________________________________________
563 void AliPIDResponse::SetRecoInfo()
566 // Set reconstruction information
577 TPRegexp reg(".*(LHC11[a-z]+[0-9]+[a-z_]*)/.*");
578 //find the period by run number (UGLY, but not stored in ESD and AOD... )
579 if (fRun>=114737&&fRun<=117223) { fLHCperiod="LHC10B"; fMCperiodTPC="LHC10D1"; }
580 else if (fRun>=118503&&fRun<=121040) { fLHCperiod="LHC10C"; fMCperiodTPC="LHC10D1"; }
581 else if (fRun>=122195&&fRun<=126437) { fLHCperiod="LHC10D"; fMCperiodTPC="LHC10F6A"; }
582 else if (fRun>=127710&&fRun<=130850) { fLHCperiod="LHC10E"; fMCperiodTPC="LHC10F6A"; }
583 else if (fRun>=133004&&fRun<=135029) { fLHCperiod="LHC10F"; fMCperiodTPC="LHC10F6A"; }
584 else if (fRun>=135654&&fRun<=136377) { fLHCperiod="LHC10G"; fMCperiodTPC="LHC10F6A"; }
585 else if (fRun>=136851&&fRun<=139517) {
587 fMCperiodTPC="LHC10H8";
588 if (reg.MatchB(fCurrentFile)) fMCperiodTPC="LHC11A10";
591 else if (fRun>=139699) { fLHCperiod="LHC11A"; fMCperiodTPC="LHC10F6A"; }
593 //exception new pp MC productions from 2011
594 if (fBeamType=="PP" && reg.MatchB(fCurrentFile)) fMCperiodTPC="LHC11B2";
597 //______________________________________________________________________________
598 void AliPIDResponse::SetITSParametrisation()
601 // Set the ITS parametrisation
605 //______________________________________________________________________________
606 void AliPIDResponse::SetTPCPidResponseMaster()
609 // Load the TPC pid response functions from the OADB
611 //don't load twice for the moment
612 if (fArrPidResponseMaster) return;
615 //reset the PID response functions
616 delete fArrPidResponseMaster;
617 fArrPidResponseMaster=0x0;
619 TString fileName(Form("%s/COMMON/PID/data/TPCPIDResponse.root", fOADBPath.Data()));
621 TFile *f=TFile::Open(fileName.Data());
622 if (f && f->IsOpen() && !f->IsZombie()){
623 fArrPidResponseMaster=dynamic_cast<TObjArray*>(f->Get("TPCPIDResponse"));
627 if (!fArrPidResponseMaster){
628 AliFatal(Form("Could not retrieve the TPC pid response from: %s",fileName.Data()));
631 fArrPidResponseMaster->SetOwner();
634 //______________________________________________________________________________
635 void AliPIDResponse::SetTPCParametrisation()
638 // Change BB parametrisation for current run
641 if (fLHCperiod.IsNull()) {
642 AliFatal("No period set, not changing parametrisation");
647 // Set default parametrisations for data and MC
651 TString datatype="DATA";
652 //in case of mc fRecoPass is per default 1
661 for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
662 fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,0x0);
666 //set the new PID splines
668 TString period=fLHCperiod;
669 if (fArrPidResponseMaster){
671 //for MC don't use period information
672 // if (fIsMC) period="[A-Z0-9]*";
673 //for MC use MC period information
674 if (fIsMC) period=fMCperiodTPC;
675 //pattern for the default entry (valid for all particles)
676 TPRegexp reg(Form("TSPLINE3_%s_([A-Z]*)_%s_PASS%d_%s_MEAN",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
678 //loop over entries and filter them
679 for (Int_t iresp=0; iresp<fArrPidResponseMaster->GetEntriesFast();++iresp){
680 TObject *responseFunction=fArrPidResponseMaster->At(iresp);
681 if (responseFunction==0x0) continue;
682 TString responseName=responseFunction->GetName();
684 if (!reg.MatchB(responseName)) continue;
686 TObjArray *arr=reg.MatchS(responseName);
687 TString particleName=arr->At(1)->GetName();
689 if (particleName.IsNull()) continue;
690 if (particleName=="ALL") grAll=responseFunction;
693 for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
694 TString particle=AliPID::ParticleName(ispec);
696 if ( particle == particleName ){
697 fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,responseFunction);
698 fTPCResponse.SetUseDatabase(kTRUE);
699 AliInfo(Form("Adding graph: %d - %s",ispec,responseFunction->GetName()));
706 //set default response function to all particles which don't have a specific one
708 for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
709 if (!fTPCResponse.GetResponseFunction((AliPID::EParticleType)ispec)){
710 fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,grAll);
711 AliInfo(Form("Adding graph: %d - %s",ispec,grAll->GetName()));
718 // Setup resolution parametrisation
722 fTPCResponse.SetSigma(3.79301e-03, 2.21280e+04);
725 fTPCResponse.SetSigma(2.30176e-02, 5.60422e+02);
727 if (fArrPidResponseMaster)
728 fResolutionCorrection=(TF1*)fArrPidResponseMaster->FindObject(Form("TF1_%s_ALL_%s_PASS%d_%s_SIGMA",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
730 if (fResolutionCorrection) AliInfo(Form("Setting multiplicity correction function: %s",fResolutionCorrection->GetName()));
733 //______________________________________________________________________________
734 void AliPIDResponse::SetTRDPidResponseMaster()
737 // Load the TRD pid params and references from the OADB
739 if(fTRDPIDParams) return;
740 AliOADBContainer contParams("contParams");
742 contParams.InitFromFile(Form("%s/COMMON/PID/data/TRDPIDParams.root", fOADBPath.Data()), "AliTRDPIDParams");
743 fTRDPIDParams = (TObjArray *)contParams.GetObject(fRun);
745 AliOADBContainer contRefs("contRefs");
746 contRefs.InitFromFile(Form("%s/COMMON/PID/data/TRDPIDReferenceLQ1D.root", fOADBPath.Data()), "AliTRDPIDReference");
747 fTRDPIDReference = (AliTRDPIDReference *)contRefs.GetObject(fRun);
750 //______________________________________________________________________________
751 void AliPIDResponse::InitializeTRDResponse(){
753 // Set PID Params and references to the TRD PID response
755 fTRDResponse.SetPIDParams(fTRDPIDParams);
756 fTRDResponse.Load(fTRDPIDReference);
757 if(fLHCperiod == "LHC10b" || fLHCperiod == "LHC10c" || fLHCperiod == "LHC10d" || fLHCperiod == "LHC10e"){
758 fTRDslicesForPID[0] = 0;
759 fTRDslicesForPID[1] = 7;
763 //_________________________________________________________________________
764 Bool_t AliPIDResponse::IdentifiedAsElectronTRD(const AliVTrack *vtrack, Double_t efficiencyLevel) const {
766 // Check whether track is identified as electron under a given electron efficiency hypothesis
768 Double_t probs[AliPID::kSPECIES];
769 ComputeTRDProbability(vtrack, AliPID::kSPECIES, probs);
771 Int_t ntracklets = vtrack->GetTRDntrackletsPID();
772 // Take mean of the TRD momenta in the given tracklets
773 Float_t p = 0, trdmomenta[AliVTrack::kTRDnPlanes];
775 for(Int_t iPl=0;iPl<AliVTrack::kTRDnPlanes;iPl++){
776 if(vtrack->GetTRDmomentum(iPl) > 0.){
777 trdmomenta[nmomenta++] = vtrack->GetTRDmomentum(iPl);
780 p = TMath::Mean(nmomenta, trdmomenta);
782 return fTRDResponse.IdentifiedAsElectron(ntracklets, probs, p, efficiencyLevel);