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>
35 #include <AliVEvent.h>
36 #include <AliVTrack.h>
39 #include <AliOADBContainer.h>
40 #include <AliTRDPIDResponseObject.h>
41 #include <AliTOFPIDParams.h>
43 #include "AliPIDResponse.h"
44 #include "AliDetectorPID.h"
46 #include "AliCentrality.h"
48 ClassImp(AliPIDResponse);
50 AliPIDResponse::AliPIDResponse(Bool_t isMC/*=kFALSE*/) :
51 TNamed("PIDResponse","PIDResponse"),
58 fITSPIDmethod(kITSTruncMean),
61 fCustomTPCpidResponse(),
71 fArrPidResponseMaster(0x0),
72 fResolutionCorrection(0x0),
73 fTRDPIDResponseObject(0x0),
84 AliLog::SetClassDebugLevel("AliPIDResponse",0);
85 AliLog::SetClassDebugLevel("AliESDpid",0);
86 AliLog::SetClassDebugLevel("AliAODpidUtil",0);
88 memset(fTRDslicesForPID,0,sizeof(UInt_t)*2);
91 //______________________________________________________________________________
92 AliPIDResponse::~AliPIDResponse()
97 delete fArrPidResponseMaster;
98 delete fTRDPIDResponseObject;
102 //______________________________________________________________________________
103 AliPIDResponse::AliPIDResponse(const AliPIDResponse &other) :
105 fITSResponse(other.fITSResponse),
106 fTPCResponse(other.fTPCResponse),
107 fTRDResponse(other.fTRDResponse),
108 fTOFResponse(other.fTOFResponse),
109 fEMCALResponse(other.fEMCALResponse),
110 fRange(other.fRange),
111 fITSPIDmethod(other.fITSPIDmethod),
113 fOADBPath(other.fOADBPath),
114 fCustomTPCpidResponse(other.fCustomTPCpidResponse),
118 fMCperiodUser(other.fMCperiodUser),
121 fRecoPassUser(other.fRecoPassUser),
124 fArrPidResponseMaster(0x0),
125 fResolutionCorrection(0x0),
126 fTRDPIDResponseObject(0x0),
129 fEMCALPIDParams(0x0),
131 fCurrCentrality(0.0),
132 fTuneMConData(kFALSE)
137 memset(fTRDslicesForPID,0,sizeof(UInt_t)*2);
140 //______________________________________________________________________________
141 AliPIDResponse& AliPIDResponse::operator=(const AliPIDResponse &other)
147 delete fArrPidResponseMaster;
148 TNamed::operator=(other);
149 fITSResponse=other.fITSResponse;
150 fTPCResponse=other.fTPCResponse;
151 fTRDResponse=other.fTRDResponse;
152 fTOFResponse=other.fTOFResponse;
153 fEMCALResponse=other.fEMCALResponse;
155 fITSPIDmethod=other.fITSPIDmethod;
156 fOADBPath=other.fOADBPath;
157 fCustomTPCpidResponse=other.fCustomTPCpidResponse;
162 fMCperiodUser=other.fMCperiodUser;
165 fRecoPassUser=other.fRecoPassUser;
168 fArrPidResponseMaster=0x0;
169 fResolutionCorrection=0x0;
170 fTRDPIDResponseObject=0x0;
172 memset(fTRDslicesForPID,0,sizeof(UInt_t)*2);
175 fCurrentEvent=other.fCurrentEvent;
180 //______________________________________________________________________________
181 Float_t AliPIDResponse::NumberOfSigmas(EDetCode detCode, const AliVParticle *track, AliPID::EParticleType type) const
184 // NumberOfSigmas for 'detCode'
188 case kDetITS: return NumberOfSigmasITS(track, type); break;
189 case kDetTPC: return NumberOfSigmasTPC(track, type); break;
190 case kDetTOF: return NumberOfSigmasTOF(track, type); break;
191 case kDetEMCAL: return NumberOfSigmasEMCAL(track, type); break;
192 default: return -999.;
197 //______________________________________________________________________________
198 Float_t AliPIDResponse::NumberOfSigmas(EDetector detCode, const AliVParticle *track, AliPID::EParticleType type) const
201 // NumberOfSigmas for 'detCode'
203 return NumberOfSigmas((EDetCode)(1<<detCode), track, type);
206 //______________________________________________________________________________
207 Float_t AliPIDResponse::NumberOfSigmasITS(const AliVParticle *vtrack, AliPID::EParticleType type) const
210 // Calculate the number of sigmas in the ITS
213 AliVTrack *track=(AliVTrack*)vtrack;
215 // look for cached value first
216 // only the non SA tracks are cached
217 if ( track->GetDetectorPID() ){
218 return track->GetDetectorPID()->GetNumberOfSigmas(kITS, type);
221 Float_t dEdx=track->GetITSsignal();
222 if (dEdx<=0) return -999.;
224 UChar_t clumap=track->GetITSClusterMap();
225 Int_t nPointsForPid=0;
226 for(Int_t i=2; i<6; i++){
227 if(clumap&(1<<i)) ++nPointsForPid;
229 Float_t mom=track->P();
231 //check for ITS standalone tracks
233 if( track->GetStatus() & AliVTrack::kTPCin ) isSA=kFALSE;
235 //TODO: in case of the electron, use the SA parametrisation,
236 // this needs to be changed if ITS provides a parametrisation
237 // for electrons also for ITS+TPC tracks
238 return fITSResponse.GetNumberOfSigmas(mom,dEdx,type,nPointsForPid,isSA || (type==AliPID::kElectron));
241 //______________________________________________________________________________
242 Float_t AliPIDResponse::NumberOfSigmasTPC(const AliVParticle *vtrack, AliPID::EParticleType type) const
245 // Calculate the number of sigmas in the TPC
248 AliVTrack *track=(AliVTrack*)vtrack;
250 // look for cached value first
251 if (track->GetDetectorPID()){
252 return track->GetDetectorPID()->GetNumberOfSigmas(kTPC, type);
255 Double_t mom = track->GetTPCmomentum();
256 Double_t sig = track->GetTPCsignal();
257 UInt_t sigN = track->GetTPCsignalN();
259 Double_t nSigma = -999.;
260 if (sigN>0) nSigma=fTPCResponse.GetNumberOfSigmas(mom,sig,sigN,type);
265 //______________________________________________________________________________
266 Float_t AliPIDResponse::NumberOfSigmasEMCAL(const AliVParticle *vtrack, AliPID::EParticleType type) const
269 // Calculate the number of sigmas in the EMCAL
272 AliVTrack *track=(AliVTrack*)vtrack;
274 // look for cached value first
275 if (track->GetDetectorPID()){
276 return track->GetDetectorPID()->GetNumberOfSigmas(kEMCAL, type);
279 AliVCluster *matchedClus = NULL;
284 Double_t fClsE = -1.;
286 Int_t nMatchClus = -1;
290 nMatchClus = track->GetEMCALcluster();
295 charge = track->Charge();
297 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
301 // matched cluster is EMCAL
302 if(matchedClus->IsEMCAL()){
304 fClsE = matchedClus->E();
308 // NSigma value really meaningful only for electrons!
309 return fEMCALResponse.GetNumberOfSigmas(pt,EovP,type,charge);
318 //______________________________________________________________________________
319 Float_t AliPIDResponse::NumberOfSigmasEMCAL(const AliVParticle *vtrack, AliPID::EParticleType type, Double_t &eop, Double_t showershape[4]) const {
321 AliVTrack *track=(AliVTrack*)vtrack;
323 AliVCluster *matchedClus = NULL;
328 Double_t fClsE = -1.;
330 // initialize eop and shower shape parameters
332 for(Int_t i = 0; i < 4; i++){
333 showershape[i] = -1.;
336 Int_t nMatchClus = -1;
340 nMatchClus = track->GetEMCALcluster();
345 charge = track->Charge();
347 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
351 // matched cluster is EMCAL
352 if(matchedClus->IsEMCAL()){
354 fClsE = matchedClus->E();
357 // fill used EMCAL variables here
359 showershape[0] = matchedClus->GetNCells(); // number of cells in cluster
360 showershape[1] = matchedClus->GetM02(); // long axis
361 showershape[2] = matchedClus->GetM20(); // short axis
362 showershape[3] = matchedClus->GetDispersion(); // dispersion
364 // NSigma value really meaningful only for electrons!
365 return fEMCALResponse.GetNumberOfSigmas(pt,EovP,type,charge);
373 //______________________________________________________________________________
374 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePIDProbability (EDetCode detCode, const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
377 // Compute PID response of 'detCode'
381 case kDetITS: return ComputeITSProbability(track, nSpecies, p); break;
382 case kDetTPC: return ComputeTPCProbability(track, nSpecies, p); break;
383 case kDetTRD: return ComputeTRDProbability(track, nSpecies, p); break;
384 case kDetTOF: return ComputeTOFProbability(track, nSpecies, p); break;
385 case kDetPHOS: return ComputePHOSProbability(track, nSpecies, p); break;
386 case kDetEMCAL: return ComputeEMCALProbability(track, nSpecies, p); break;
387 case kDetHMPID: return ComputeHMPIDProbability(track, nSpecies, p); break;
388 default: return kDetNoSignal;
392 //______________________________________________________________________________
393 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePIDProbability (EDetector detCode, const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
396 // Compute PID response of 'detCode'
399 return ComputePIDProbability((EDetCode)(1<<detCode),track,nSpecies,p);
402 //______________________________________________________________________________
403 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeITSProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
406 // Compute PID response for the ITS
409 // look for cached value first
410 // only the non SA tracks are cached
411 if (track->GetDetectorPID()){
412 return track->GetDetectorPID()->GetRawProbability(kITS, p, nSpecies);
415 // set flat distribution (no decision)
416 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
418 if ((track->GetStatus()&AliVTrack::kITSin)==0 &&
419 (track->GetStatus()&AliVTrack::kITSout)==0) return kDetNoSignal;
421 //check for ITS standalone tracks
423 if( track->GetStatus() & AliVTrack::kTPCin ) isSA=kFALSE;
425 Double_t mom=track->P();
426 Double_t dedx=track->GetITSsignal();
428 UChar_t clumap=track->GetITSClusterMap();
429 Int_t nPointsForPid=0;
430 for(Int_t i=2; i<6; i++){
431 if(clumap&(1<<i)) ++nPointsForPid;
434 if(nPointsForPid<3) { // track not to be used for combined PID purposes
435 // track->ResetStatus(AliVTrack::kITSpid);
439 Bool_t mismatch=kTRUE/*, heavy=kTRUE*/;
440 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
441 Double_t mass=AliPID::ParticleMassZ(j);//GeV/c^2
442 const Double_t chargeFactor = TMath::Power(AliPID::ParticleCharge(j),2.);
443 Double_t bethe=fITSResponse.Bethe(momITS,mass)*chargeFactor;
444 //TODO: in case of the electron, use the SA parametrisation,
445 // this needs to be changed if ITS provides a parametrisation
446 // for electrons also for ITS+TPC tracks
447 Double_t sigma=fITSResponse.GetResolution(bethe,nPointsForPid,isSA || (j==(Int_t)AliPID::kElectron));
448 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
449 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
451 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
455 // Check for particles heavier than (AliPID::kSPECIES - 1)
456 // if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
461 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
468 //______________________________________________________________________________
469 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTPCProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
472 // Compute PID response for the TPC
475 // look for cached value first
476 if (track->GetDetectorPID()){
477 return track->GetDetectorPID()->GetRawProbability(kTPC, p, nSpecies);
480 // set flat distribution (no decision)
481 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
483 // check quality of the track
484 if ( (track->GetStatus()&AliVTrack::kTPCin )==0 && (track->GetStatus()&AliVTrack::kTPCout)==0 ) return kDetNoSignal;
486 Double_t mom = track->GetTPCmomentum();
488 Double_t dedx=track->GetTPCsignal();
489 Bool_t mismatch=kTRUE/*, heavy=kTRUE*/;
491 if(fTuneMConData) dedx = this->GetTPCsignalTunedOnData(track);
493 for (Int_t j=0; j<AliPID::kSPECIESC; j++) {
494 AliPID::EParticleType type=AliPID::EParticleType(j);
495 Double_t bethe=fTPCResponse.GetExpectedSignal(mom,type);
496 Double_t sigma=fTPCResponse.GetExpectedSigma(mom,track->GetTPCsignalN(),type);
497 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
498 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
500 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
506 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
512 //______________________________________________________________________________
513 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTOFProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
516 // Compute PID response for the
519 // look for cached value first
520 if (track->GetDetectorPID()){
521 return track->GetDetectorPID()->GetRawProbability(kTOF, p, nSpecies);
524 Double_t meanCorrFactor = 0.11/fTOFtail; // Correction factor on the mean because of the tail (should be ~ 0.1 with tail = 1.1)
526 // set flat distribution (no decision)
527 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
529 if ((track->GetStatus()&AliVTrack::kTOFout)==0) return kDetNoSignal;
530 if ((track->GetStatus()&AliVTrack::kTIME)==0) return kDetNoSignal;
532 Bool_t mismatch = kTRUE/*, heavy = kTRUE*/;
533 for (Int_t j=0; j<AliPID::kSPECIESC; j++) {
534 AliPID::EParticleType type=AliPID::EParticleType(j);
535 Double_t nsigmas=NumberOfSigmasTOF(track,type) + meanCorrFactor;
537 Double_t expTime = fTOFResponse.GetExpectedSignal(track,type);
538 Double_t sig = fTOFResponse.GetExpectedSigma(track->P(),expTime,AliPID::ParticleMassZ(type));
539 if (TMath::Abs(nsigmas) > (fRange+2)) {
540 if(nsigmas < fTOFtail)
541 p[j] = TMath::Exp(-0.5*(fRange+2)*(fRange+2))/sig;
543 p[j] = TMath::Exp(-(fRange+2 - fTOFtail*0.5)*fTOFtail)/sig;
545 if(nsigmas < fTOFtail)
546 p[j] = TMath::Exp(-0.5*nsigmas*nsigmas)/sig;
548 p[j] = TMath::Exp(-(nsigmas - fTOFtail*0.5)*fTOFtail)/sig;
551 if (TMath::Abs(nsigmas)<5.){
552 Double_t nsigmasTPC=NumberOfSigmasTPC(track,type);
553 if (TMath::Abs(nsigmasTPC)<5.) mismatch=kFALSE;
561 // TODO: Light nuclei
565 //______________________________________________________________________________
566 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTRDProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
569 // Compute PID response for the
572 // look for cached value first
573 if (track->GetDetectorPID()){
574 return track->GetDetectorPID()->GetRawProbability(kTRD, p, nSpecies);
577 // set flat distribution (no decision)
578 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
579 if((track->GetStatus()&AliVTrack::kTRDout)==0) return kDetNoSignal;
582 Double_t dedx[48]={0.}; // Allocate space for the maximum number of TRD slices
583 Int_t nslices = fTRDslicesForPID[1] - fTRDslicesForPID[0] + 1;
584 AliDebug(1, Form("First Slice: %d, Last Slice: %d, Number of slices: %d", fTRDslicesForPID[0], fTRDslicesForPID[1], nslices));
585 for(UInt_t ilayer = 0; ilayer < 6; ilayer++){
586 mom[ilayer] = track->GetTRDmomentum(ilayer);
587 for(UInt_t islice = fTRDslicesForPID[0]; islice <= fTRDslicesForPID[1]; islice++){
588 dedx[ilayer*nslices+islice-fTRDslicesForPID[0]] = track->GetTRDslice(ilayer, islice);
591 fTRDResponse.GetResponse(nslices, dedx, mom, p);
594 //______________________________________________________________________________
595 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeEMCALProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
598 // Compute PID response for the EMCAL
601 // look for cached value first
602 if (track->GetDetectorPID()){
603 return track->GetDetectorPID()->GetRawProbability(kEMCAL, p, nSpecies);
606 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
608 AliVCluster *matchedClus = NULL;
613 Double_t fClsE = -1.;
615 Int_t nMatchClus = -1;
619 nMatchClus = track->GetEMCALcluster();
625 charge = track->Charge();
627 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
631 // matched cluster is EMCAL
632 if(matchedClus->IsEMCAL()){
634 fClsE = matchedClus->E();
638 // compute the probabilities
639 if(fEMCALResponse.ComputeEMCALProbability(nSpecies,pt,EovP,charge,p)){
641 // in case everything is OK
648 // in all other cases set flat distribution (no decision)
649 for (Int_t j=0; j<nSpecies; j++) p[j] = 1./nSpecies;
653 //______________________________________________________________________________
654 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePHOSProbability (const AliVTrack */*track*/, Int_t nSpecies, Double_t p[]) const
657 // Compute PID response for the PHOS
660 // look for cached value first
661 // if (track->GetDetectorPID()){
662 // return track->GetDetectorPID()->GetRawProbability(kPHOS, p, nSpecies);
665 // set flat distribution (no decision)
666 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
669 //______________________________________________________________________________
670 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeHMPIDProbability(const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
673 // Compute PID response for the HMPID
677 // look for cached value first
678 if (track->GetDetectorPID()){
679 return track->GetDetectorPID()->GetRawProbability(kHMPID, p, nSpecies);
682 // set flat distribution (no decision)
683 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
684 if((track->GetStatus()&AliVTrack::kHMPIDpid)==0) return kDetNoSignal;
686 track->GetHMPIDpid(p);
691 //______________________________________________________________________________
692 void AliPIDResponse::InitialiseEvent(AliVEvent *event, Int_t pass, Int_t run)
695 // Apply settings for the current event
703 else fRun=event->GetRunNumber();
710 //TPC resolution parametrisation PbPb
711 if ( fResolutionCorrection ){
712 Double_t corrSigma=fResolutionCorrection->Eval(GetTPCMultiplicityBin(event));
713 fTPCResponse.SetSigma(3.79301e-03*corrSigma, 2.21280e+04);
717 SetTOFResponse(event, (AliPIDResponse::EStartTimeType_t)fTOFPIDParams->GetStartTimeMethod());
720 // Get and set centrality
721 AliCentrality *centrality = event->GetCentrality();
723 fCurrCentrality = centrality->GetCentralityPercentile("V0M");
726 fCurrCentrality = -1;
730 //______________________________________________________________________________
731 void AliPIDResponse::ExecNewRun()
734 // Things to Execute upon a new run
738 SetITSParametrisation();
740 SetTPCPidResponseMaster();
741 SetTPCParametrisation();
743 SetTRDPidResponseMaster();
744 InitializeTRDResponse();
746 SetEMCALPidResponseMaster();
747 InitializeEMCALResponse();
749 SetTOFPidResponseMaster();
750 InitializeTOFResponse();
753 //_____________________________________________________
754 Double_t AliPIDResponse::GetTPCMultiplicityBin(const AliVEvent * const event)
757 // Get TPC multiplicity in bins of 150
760 const AliVVertex* vertexTPC = event->GetPrimaryVertex();
761 Double_t tpcMulti=0.;
763 Double_t vertexContribTPC=vertexTPC->GetNContributors();
764 tpcMulti=vertexContribTPC/150.;
765 if (tpcMulti>20.) tpcMulti=20.;
771 //______________________________________________________________________________
772 void AliPIDResponse::SetRecoInfo()
775 // Set reconstruction information
787 TPRegexp reg(".*(LHC1[1-2][a-z]+[0-9]+[a-z_]*)/.*");
788 TPRegexp reg12a17(".*(LHC12a17[a-z]+)/.*");
790 //find the period by run number (UGLY, but not stored in ESD and AOD... )
791 if (fRun>=114737&&fRun<=117223) { fLHCperiod="LHC10B"; fMCperiodTPC="LHC10D1"; }
792 else if (fRun>=118503&&fRun<=121040) { fLHCperiod="LHC10C"; fMCperiodTPC="LHC10D1"; }
793 else if (fRun>=122195&&fRun<=126437) { fLHCperiod="LHC10D"; fMCperiodTPC="LHC10F6A"; }
794 else if (fRun>=127710&&fRun<=130850) { fLHCperiod="LHC10E"; fMCperiodTPC="LHC10F6A"; }
795 else if (fRun>=133004&&fRun<=135029) { fLHCperiod="LHC10F"; fMCperiodTPC="LHC10F6A"; }
796 else if (fRun>=135654&&fRun<=136377) { fLHCperiod="LHC10G"; fMCperiodTPC="LHC10F6A"; }
797 else if (fRun>=136851&&fRun<=139517) {
799 fMCperiodTPC="LHC10H8";
800 if (reg.MatchB(fCurrentFile)) fMCperiodTPC="LHC11A10";
803 else if (fRun>=139699&&fRun<=146860) { fLHCperiod="LHC11A"; fMCperiodTPC="LHC10F6A"; }
804 //TODO: periods 11B, 11C are not yet treated assume 11d for the moment
805 else if (fRun>=148531&&fRun<=155384) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
806 else if (fRun>=156477&&fRun<=159635) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
807 // also for 11e,f use 11d
808 else if (fRun>=160676&&fRun<=162740) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
809 else if (fRun>=162933&&fRun<=165746) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
811 else if (fRun>=166529) {
813 fMCperiodTPC="LHC11A10";
815 if (reg12a17.MatchB(fCurrentFile)) fMCperiodTPC="LHC12A17";
819 //exception new pp MC productions from 2011
820 if (fBeamType=="PP" && reg.MatchB(fCurrentFile)) fMCperiodTPC="LHC11B2";
821 // exception for 11f1
822 if (fCurrentFile.Contains("LHC11f1/")) fMCperiodTPC="LHC11F1";
825 //______________________________________________________________________________
826 void AliPIDResponse::SetITSParametrisation()
829 // Set the ITS parametrisation
833 //______________________________________________________________________________
834 void AliPIDResponse::SetTPCPidResponseMaster()
837 // Load the TPC pid response functions from the OADB
839 //don't load twice for the moment
840 if (fArrPidResponseMaster) return;
843 //reset the PID response functions
844 delete fArrPidResponseMaster;
845 fArrPidResponseMaster=0x0;
847 TString fileName(Form("%s/COMMON/PID/data/TPCPIDResponse.root", fOADBPath.Data()));
848 if (!fCustomTPCpidResponse.IsNull()) fileName=fCustomTPCpidResponse;
850 TFile *f=TFile::Open(fileName.Data());
851 if (f && f->IsOpen() && !f->IsZombie()){
852 fArrPidResponseMaster=dynamic_cast<TObjArray*>(f->Get("TPCPIDResponse"));
856 if (!fArrPidResponseMaster){
857 AliFatal(Form("Could not retrieve the TPC pid response from: %s",fileName.Data()));
860 fArrPidResponseMaster->SetOwner();
863 //______________________________________________________________________________
864 void AliPIDResponse::SetTPCParametrisation()
867 // Change BB parametrisation for current run
870 if (fLHCperiod.IsNull()) {
871 AliFatal("No period set, not changing parametrisation");
876 // Set default parametrisations for data and MC
880 TString datatype="DATA";
881 //in case of mc fRecoPass is per default 1
883 if(!fTuneMConData) datatype="MC";
890 for (Int_t ispec=0; ispec<AliPID::kSPECIESC; ++ispec){
891 fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,0x0);
895 TString period=fLHCperiod;
896 if (fIsMC && !fTuneMConData) period=fMCperiodTPC;
898 AliInfo(Form("Searching splines for: %s %s PASS%d %s",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
901 //set the new PID splines
903 if (fArrPidResponseMaster){
904 Int_t recopass = fRecoPass;
905 if(fTuneMConData) recopass = fRecoPassUser;
907 //for MC don't use period information
908 // if (fIsMC) period="[A-Z0-9]*";
909 //for MC use MC period information
910 //pattern for the default entry (valid for all particles)
911 TPRegexp reg(Form("TSPLINE3_%s_([A-Z]*)_%s_PASS%d_%s_MEAN",datatype.Data(),period.Data(),recopass,fBeamType.Data()));
913 //loop over entries and filter them
914 for (Int_t iresp=0; iresp<fArrPidResponseMaster->GetEntriesFast();++iresp){
915 TObject *responseFunction=fArrPidResponseMaster->At(iresp);
916 if (responseFunction==0x0) continue;
917 TString responseName=responseFunction->GetName();
919 if (!reg.MatchB(responseName)) continue;
921 TObjArray *arr=reg.MatchS(responseName);
922 TString particleName=arr->At(1)->GetName();
924 if (particleName.IsNull()) continue;
925 if (!grAll&&particleName=="ALL") grAll=responseFunction;
928 for (Int_t ispec=0; ispec<AliPID::kSPECIESC; ++ispec){
929 TString particle=AliPID::ParticleName(ispec);
931 if ( particle == particleName ){
932 fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,responseFunction);
933 fTPCResponse.SetUseDatabase(kTRUE);
934 AliInfo(Form("Adding graph: %d - %s",ispec,responseFunction->GetName()));
935 // overwrite default with proton spline (for light nuclei)
936 if (ispec==AliPID::kProton) grAll=responseFunction;
944 //set default response function to all particles which don't have a specific one
946 for (Int_t ispec=0; ispec<AliPID::kSPECIESC; ++ispec){
947 if (!fTPCResponse.GetResponseFunction((AliPID::EParticleType)ispec)){
948 fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,grAll);
949 AliInfo(Form("Adding graph: %d - %s",ispec,grAll->GetName()));
957 AliError(Form("No splines found for: %s %s PASS%d %s",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
960 // Setup resolution parametrisation
964 fTPCResponse.SetSigma(3.79301e-03, 2.21280e+04);
967 fTPCResponse.SetSigma(2.30176e-02, 5.60422e+02);
969 if (fArrPidResponseMaster)
970 fResolutionCorrection=(TF1*)fArrPidResponseMaster->FindObject(Form("TF1_%s_ALL_%s_PASS%d_%s_SIGMA",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
972 if (fResolutionCorrection) AliInfo(Form("Setting multiplicity correction function: %s",fResolutionCorrection->GetName()));
975 //______________________________________________________________________________
976 void AliPIDResponse::SetTRDPidResponseMaster()
979 // Load the TRD pid params and references from the OADB
981 if(fTRDPIDResponseObject) return;
982 AliOADBContainer contParams("contParams");
984 Int_t statusResponse = contParams.InitFromFile(Form("%s/COMMON/PID/data/TRDPIDResponse.root", fOADBPath.Data()), "AliTRDPIDResponseObject");
986 AliError("Failed initializing PID Response Object from OADB");
988 AliInfo(Form("Loading TRD Response from %s/COMMON/PID/data/TRDPIDResponse.root", fOADBPath.Data()));
989 fTRDPIDResponseObject = dynamic_cast<AliTRDPIDResponseObject *>(contParams.GetObject(fRun));
990 if(!fTRDPIDResponseObject){
991 AliError(Form("TRD Response not found in run %d", fRun));
995 AliOADBContainer contRefs("contRefs");
996 Int_t statusRefs = contRefs.InitFromFile(Form("%s/COMMON/PID/data/TRDPIDReferenceLQ1D.root", fOADBPath.Data()), "AliTRDPIDReference");
998 AliInfo("Failed Loading References for TRD");
1000 AliInfo(Form("Loading TRD References from %s/COMMON/PID/data/TRDPIDReferenceLQ1D.root", fOADBPath.Data()));
1001 fTRDPIDReference = dynamic_cast<AliTRDPIDReference *>(contRefs.GetObject(fRun));
1002 if(!fTRDPIDReference){
1003 AliError(Form("TRD References not found in OADB Container for run %d", fRun));
1009 //______________________________________________________________________________
1010 void AliPIDResponse::InitializeTRDResponse(){
1012 // Set PID Params and references to the TRD PID response
1014 fTRDResponse.SetPIDResponseObject(fTRDPIDResponseObject);
1018 void AliPIDResponse::SetTRDPIDmethod(AliTRDPIDResponse::ETRDPIDMethod method){
1020 fTRDResponse.SetPIDmethod(method);
1021 if(fLHCperiod == "LHC10d" || fLHCperiod == "LHC10e"){
1022 // backward compatibility for setting with 8 slices
1023 fTRDslicesForPID[0] = 0;
1024 fTRDslicesForPID[1] = 7;
1027 if(method==AliTRDPIDResponse::kLQ1D){
1028 fTRDslicesForPID[0] = 0; // first Slice contains normalized dEdx
1029 fTRDslicesForPID[1] = 0;
1031 if(method==AliTRDPIDResponse::kLQ2D){
1032 fTRDslicesForPID[0] = 1;
1033 fTRDslicesForPID[1] = 7;
1036 AliDebug(1,Form("Slice Range set to %d - %d",fTRDslicesForPID[0],fTRDslicesForPID[1]));
1039 //______________________________________________________________________________
1040 void AliPIDResponse::SetTOFPidResponseMaster()
1043 // Load the TOF pid params from the OADB
1046 if (fTOFPIDParams) delete fTOFPIDParams;
1049 TFile *oadbf = new TFile(Form("%s/COMMON/PID/data/TOFPIDParams.root",fOADBPath.Data()));
1050 if (oadbf && oadbf->IsOpen()) {
1051 AliInfo(Form("Loading TOF Params from %s/COMMON/PID/data/TOFPIDParams.root", fOADBPath.Data()));
1052 AliOADBContainer *oadbc = (AliOADBContainer *)oadbf->Get("TOFoadb");
1053 if (oadbc) fTOFPIDParams = dynamic_cast<AliTOFPIDParams *>(oadbc->GetObject(fRun,"TOFparams"));
1059 if (!fTOFPIDParams) AliFatal("TOFPIDParams could not be retrieved");
1062 //______________________________________________________________________________
1063 void AliPIDResponse::InitializeTOFResponse(){
1065 // Set PID Params to the TOF PID response
1068 AliInfo("TOF PID Params loaded from OADB");
1069 AliInfo(Form(" TOF resolution %5.2f [ps]",fTOFPIDParams->GetTOFresolution()));
1070 AliInfo(Form(" StartTime method %d",fTOFPIDParams->GetStartTimeMethod()));
1071 AliInfo(Form(" TOF res. mom. params: %5.2f %5.2f %5.2f %5.2f",
1072 fTOFPIDParams->GetSigParams(0),fTOFPIDParams->GetSigParams(1),fTOFPIDParams->GetSigParams(2),fTOFPIDParams->GetSigParams(3)));
1074 for (Int_t i=0;i<4;i++) {
1075 fTOFResponse.SetTrackParameter(i,fTOFPIDParams->GetSigParams(i));
1077 fTOFResponse.SetTimeResolution(fTOFPIDParams->GetTOFresolution());
1082 //_________________________________________________________________________
1083 Bool_t AliPIDResponse::IdentifiedAsElectronTRD(const AliVTrack *vtrack, Double_t efficiencyLevel) const {
1085 // Check whether track is identified as electron under a given electron efficiency hypothesis
1087 Double_t probs[AliPID::kSPECIES];
1088 ComputeTRDProbability(vtrack, AliPID::kSPECIES, probs);
1090 Int_t ntracklets = vtrack->GetTRDntrackletsPID();
1091 // Take mean of the TRD momenta in the given tracklets
1092 Float_t p = 0, trdmomenta[AliVTrack::kTRDnPlanes];
1094 for(Int_t iPl=0;iPl<AliVTrack::kTRDnPlanes;iPl++){
1095 if(vtrack->GetTRDmomentum(iPl) > 0.){
1096 trdmomenta[nmomenta++] = vtrack->GetTRDmomentum(iPl);
1099 p = TMath::Mean(nmomenta, trdmomenta);
1101 return fTRDResponse.IdentifiedAsElectron(ntracklets, probs, p, efficiencyLevel);
1104 //______________________________________________________________________________
1105 void AliPIDResponse::SetEMCALPidResponseMaster()
1108 // Load the EMCAL pid response functions from the OADB
1110 TObjArray* fEMCALPIDParamsRun = NULL;
1111 TObjArray* fEMCALPIDParamsPass = NULL;
1113 if(fEMCALPIDParams) return;
1114 AliOADBContainer contParams("contParams");
1116 Int_t statusPars = contParams.InitFromFile(Form("%s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()), "AliEMCALPIDParams");
1118 AliError("Failed initializing PID Params from OADB");
1121 AliInfo(Form("Loading EMCAL Params from %s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()));
1123 fEMCALPIDParamsRun = dynamic_cast<TObjArray *>(contParams.GetObject(fRun));
1124 if(fEMCALPIDParamsRun) fEMCALPIDParamsPass = dynamic_cast<TObjArray *>(fEMCALPIDParamsRun->FindObject(Form("pass%d",fRecoPass)));
1125 if(fEMCALPIDParamsPass) fEMCALPIDParams = dynamic_cast<TObjArray *>(fEMCALPIDParamsPass->FindObject(Form("EMCALPIDParams_Particles")));
1127 if(!fEMCALPIDParams){
1128 AliInfo(Form("EMCAL Params not found in run %d pass %d", fRun, fRecoPass));
1129 AliInfo("Will take the standard LHC11d instead ...");
1131 fEMCALPIDParamsRun = dynamic_cast<TObjArray *>(contParams.GetObject(156477));
1132 if(fEMCALPIDParamsRun) fEMCALPIDParamsPass = dynamic_cast<TObjArray *>(fEMCALPIDParamsRun->FindObject(Form("pass%d",1)));
1133 if(fEMCALPIDParamsPass) fEMCALPIDParams = dynamic_cast<TObjArray *>(fEMCALPIDParamsPass->FindObject(Form("EMCALPIDParams_Particles")));
1135 if(!fEMCALPIDParams){
1136 AliError(Form("DEFAULT EMCAL Params (LHC11d) not found in file %s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()));
1142 //______________________________________________________________________________
1143 void AliPIDResponse::InitializeEMCALResponse(){
1145 // Set PID Params to the EMCAL PID response
1147 fEMCALResponse.SetPIDParams(fEMCALPIDParams);
1151 //_____________________________________________________
1152 void AliPIDResponse::FillTrackDetectorPID()
1155 // create detector PID information and setup the transient pointer in the track
1158 if (!fCurrentEvent) return;
1160 //TODO: which particles to include? See also the loops below...
1161 Double_t values[AliPID::kSPECIESC]={0};
1163 for (Int_t itrack=0; itrack<fCurrentEvent->GetNumberOfTracks(); ++itrack){
1164 AliVTrack *track=dynamic_cast<AliVTrack*>(fCurrentEvent->GetTrack(itrack));
1165 if (!track) continue;
1167 AliDetectorPID *detPID=new AliDetectorPID;
1168 for (Int_t idet=0; idet<kNdetectors; ++idet){
1171 for (Int_t ipart=0; ipart<AliPID::kSPECIESC; ++ipart)
1172 values[ipart]=NumberOfSigmas((EDetector)idet,track,(AliPID::EParticleType)ipart);
1173 detPID->SetNumberOfSigmas((EDetector)idet, values, (Int_t)AliPID::kSPECIESC);
1176 EDetPidStatus status=ComputePIDProbability((EDetector)idet,track,AliPID::kSPECIESC,values);
1177 detPID->SetRawProbability((EDetector)idet, values, (Int_t)AliPID::kSPECIESC, status);
1180 track->SetDetectorPID(detPID);
1184 //_________________________________________________________________________
1185 void AliPIDResponse::SetTOFResponse(AliVEvent *vevent,EStartTimeType_t option){
1187 // Set TOF response function
1188 // Input option for event_time used
1191 Float_t t0spread = 0.; //vevent->GetEventTimeSpread();
1192 if(t0spread < 10) t0spread = 80;
1194 // T0 from TOF algorithm
1196 Bool_t flagT0TOF=kFALSE;
1197 Bool_t flagT0T0=kFALSE;
1198 Float_t *startTime = new Float_t[fTOFResponse.GetNmomBins()];
1199 Float_t *startTimeRes = new Float_t[fTOFResponse.GetNmomBins()];
1200 Int_t *startTimeMask = new Int_t[fTOFResponse.GetNmomBins()];
1203 Float_t *estimatedT0event = new Float_t[fTOFResponse.GetNmomBins()];
1204 Float_t *estimatedT0resolution = new Float_t[fTOFResponse.GetNmomBins()];
1205 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1206 estimatedT0event[i]=0.0;
1207 estimatedT0resolution[i]=0.0;
1208 startTimeMask[i] = 0;
1211 Float_t resT0A=75,resT0C=65,resT0AC=55;
1212 if(vevent->GetT0TOF()){ // check if T0 detector information is available
1217 AliTOFHeader *tofHeader = (AliTOFHeader*)vevent->GetTOFHeader();
1219 if (tofHeader) { // read global info and T0-TOF
1220 fTOFResponse.SetTimeResolution(tofHeader->GetTOFResolution());
1221 t0spread = tofHeader->GetT0spread(); // read t0 sprad
1222 if(t0spread < 10) t0spread = 80;
1225 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){ // read T0-TOF default value
1226 startTime[i]=tofHeader->GetDefaultEventTimeVal();
1227 startTimeRes[i]=tofHeader->GetDefaultEventTimeRes();
1228 if(startTimeRes[i] < 1.e-5) startTimeRes[i] = t0spread;
1231 TArrayI *ibin=(TArrayI*)tofHeader->GetNvalues();
1232 TArrayF *t0Bin=(TArrayF*)tofHeader->GetEventTimeValues();
1233 TArrayF *t0ResBin=(TArrayF*)tofHeader->GetEventTimeRes();
1234 for(Int_t j=0;j < tofHeader->GetNbins();j++){ // fill T0-TOF in p-bins
1235 Int_t icurrent = (Int_t)ibin->GetAt(j);
1236 startTime[icurrent]=t0Bin->GetAt(j);
1237 startTimeRes[icurrent]=t0ResBin->GetAt(j);
1238 if(startTimeRes[icurrent] < 1.e-5) startTimeRes[icurrent] = t0spread;
1242 // for cut of 3 sigma on t0 spread
1243 Float_t t0cut = 3 * t0spread;
1244 if(t0cut < 500) t0cut = 500;
1246 if(option == kFILL_T0){ // T0-FILL is used
1247 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1248 estimatedT0event[i]=0.0;
1249 estimatedT0resolution[i]=t0spread;
1251 fTOFResponse.SetT0event(estimatedT0event);
1252 fTOFResponse.SetT0resolution(estimatedT0resolution);
1255 if(option == kTOF_T0){ // T0-TOF is used when available (T0-FILL otherwise) from ESD
1257 fTOFResponse.SetT0event(startTime);
1258 fTOFResponse.SetT0resolution(startTimeRes);
1259 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1260 if(startTimeRes[i]<t0spread) startTimeMask[i]=1;
1261 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1265 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1266 estimatedT0event[i]=0.0;
1267 estimatedT0resolution[i]=t0spread;
1268 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1270 fTOFResponse.SetT0event(estimatedT0event);
1271 fTOFResponse.SetT0resolution(estimatedT0resolution);
1274 else if(option == kBest_T0){ // T0-T0 or T0-TOF are used when available (T0-FILL otherwise) from ESD
1275 Float_t t0AC=-10000;
1279 t0AC= vevent->GetT0TOF()[0];
1280 t0A= vevent->GetT0TOF()[1];
1281 t0C= vevent->GetT0TOF()[2];
1284 Float_t t0t0Best = 0;
1285 Float_t t0t0BestRes = 9999;
1287 if(TMath::Abs(t0A) < t0cut && TMath::Abs(t0C) < t0cut && TMath::Abs(t0C-t0A) < 500){
1289 t0t0BestRes = resT0AC;
1292 else if(TMath::Abs(t0C) < t0cut){
1294 t0t0BestRes = resT0C;
1297 else if(TMath::Abs(t0A) < t0cut){
1299 t0t0BestRes = resT0A;
1303 if(flagT0TOF){ // if T0-TOF info is available
1304 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1305 if(t0t0BestRes < 999){
1306 if(startTimeRes[i] < t0spread){
1307 Double_t wtot = 1./startTimeRes[i]/startTimeRes[i] + 1./t0t0BestRes/t0t0BestRes;
1308 Double_t t0best = startTime[i]/startTimeRes[i]/startTimeRes[i] + t0t0Best/t0t0BestRes/t0t0BestRes;
1309 estimatedT0event[i]=t0best / wtot;
1310 estimatedT0resolution[i]=1./TMath::Sqrt(wtot);
1311 startTimeMask[i] = t0used+1;
1314 estimatedT0event[i]=t0t0Best;
1315 estimatedT0resolution[i]=t0t0BestRes;
1316 startTimeMask[i] = t0used;
1320 estimatedT0event[i]=startTime[i];
1321 estimatedT0resolution[i]=startTimeRes[i];
1322 if(startTimeRes[i]<t0spread) startTimeMask[i]=1;
1324 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1326 fTOFResponse.SetT0event(estimatedT0event);
1327 fTOFResponse.SetT0resolution(estimatedT0resolution);
1329 else{ // if no T0-TOF info is available
1330 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1331 fTOFResponse.SetT0binMask(i,t0used);
1332 if(t0t0BestRes < 999){
1333 estimatedT0event[i]=t0t0Best;
1334 estimatedT0resolution[i]=t0t0BestRes;
1337 estimatedT0event[i]=0.0;
1338 estimatedT0resolution[i]=t0spread;
1341 fTOFResponse.SetT0event(estimatedT0event);
1342 fTOFResponse.SetT0resolution(estimatedT0resolution);
1346 else if(option == kT0_T0){ // T0-T0 is used when available (T0-FILL otherwise)
1347 Float_t t0AC=-10000;
1351 t0AC= vevent->GetT0TOF()[0];
1352 t0A= vevent->GetT0TOF()[1];
1353 t0C= vevent->GetT0TOF()[2];
1356 if(TMath::Abs(t0A) < t0cut && TMath::Abs(t0C) < t0cut && TMath::Abs(t0C-t0A) < 500){
1357 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1358 estimatedT0event[i]=t0AC;
1359 estimatedT0resolution[i]=resT0AC;
1360 fTOFResponse.SetT0binMask(i,6);
1363 else if(TMath::Abs(t0C) < t0cut){
1364 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1365 estimatedT0event[i]=t0C;
1366 estimatedT0resolution[i]=resT0C;
1367 fTOFResponse.SetT0binMask(i,4);
1370 else if(TMath::Abs(t0A) < t0cut){
1371 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1372 estimatedT0event[i]=t0A;
1373 estimatedT0resolution[i]=resT0A;
1374 fTOFResponse.SetT0binMask(i,2);
1378 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1379 estimatedT0event[i]=0.0;
1380 estimatedT0resolution[i]=t0spread;
1381 fTOFResponse.SetT0binMask(i,0);
1384 fTOFResponse.SetT0event(estimatedT0event);
1385 fTOFResponse.SetT0resolution(estimatedT0resolution);
1387 delete [] startTime;
1388 delete [] startTimeRes;
1389 delete [] startTimeMask;
1390 delete [] estimatedT0event;
1391 delete [] estimatedT0resolution;