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>
34 #include <AliVEvent.h>
35 #include <AliVTrack.h>
38 #include <AliOADBContainer.h>
39 #include <AliTRDPIDResponseObject.h>
40 #include <AliTOFPIDParams.h>
42 #include "AliPIDResponse.h"
44 #include "AliCentrality.h"
46 ClassImp(AliPIDResponse);
48 AliPIDResponse::AliPIDResponse(Bool_t isMC/*=kFALSE*/) :
49 TNamed("PIDResponse","PIDResponse"),
56 fITSPIDmethod(kITSTruncMean),
68 fArrPidResponseMaster(0x0),
69 fResolutionCorrection(0x0),
70 fTRDPIDResponseObject(0x0),
80 AliLog::SetClassDebugLevel("AliPIDResponse",0);
81 AliLog::SetClassDebugLevel("AliESDpid",0);
82 AliLog::SetClassDebugLevel("AliAODpidUtil",0);
84 memset(fTRDslicesForPID,0,sizeof(UInt_t)*2);
87 //______________________________________________________________________________
88 AliPIDResponse::~AliPIDResponse()
93 delete fArrPidResponseMaster;
94 delete fTRDPIDResponseObject;
95 if (fTOFPIDParams) delete fTOFPIDParams;
98 //______________________________________________________________________________
99 AliPIDResponse::AliPIDResponse(const AliPIDResponse &other) :
101 fITSResponse(other.fITSResponse),
102 fTPCResponse(other.fTPCResponse),
103 fTRDResponse(other.fTRDResponse),
104 fTOFResponse(other.fTOFResponse),
105 fEMCALResponse(other.fEMCALResponse),
106 fRange(other.fRange),
107 fITSPIDmethod(other.fITSPIDmethod),
109 fOADBPath(other.fOADBPath),
113 fMCperiodUser(other.fMCperiodUser),
116 fRecoPassUser(other.fRecoPassUser),
119 fArrPidResponseMaster(0x0),
120 fResolutionCorrection(0x0),
121 fTRDPIDResponseObject(0x0),
124 fEMCALPIDParams(0x0),
131 memset(fTRDslicesForPID,0,sizeof(UInt_t)*2);
134 //______________________________________________________________________________
135 AliPIDResponse& AliPIDResponse::operator=(const AliPIDResponse &other)
141 delete fArrPidResponseMaster;
142 TNamed::operator=(other);
143 fITSResponse=other.fITSResponse;
144 fTPCResponse=other.fTPCResponse;
145 fTRDResponse=other.fTRDResponse;
146 fTOFResponse=other.fTOFResponse;
147 fEMCALResponse=other.fEMCALResponse;
149 fITSPIDmethod=other.fITSPIDmethod;
150 fOADBPath=other.fOADBPath;
155 fMCperiodUser=other.fMCperiodUser;
158 fRecoPassUser=other.fRecoPassUser;
161 fArrPidResponseMaster=0x0;
162 fResolutionCorrection=0x0;
163 fTRDPIDResponseObject=0x0;
165 memset(fTRDslicesForPID,0,sizeof(UInt_t)*2);
168 fCurrentEvent=other.fCurrentEvent;
173 //______________________________________________________________________________
174 Float_t AliPIDResponse::NumberOfSigmas(EDetCode detCode, const AliVParticle *track, AliPID::EParticleType type) const
177 // NumberOfSigmas for 'detCode'
181 case kDetITS: return NumberOfSigmasITS(track, type); break;
182 case kDetTPC: return NumberOfSigmasTPC(track, type); break;
183 case kDetTOF: return NumberOfSigmasTOF(track, type); break;
184 // case kDetTRD: return ComputeTRDProbability(track, type); break;
185 // case kDetPHOS: return ComputePHOSProbability(track, type); break;
186 // case kDetEMCAL: return NumberOfSigmasEMCAL(track, type); break;
187 // case kDetHMPID: return ComputeHMPIDProbability(track, type); break;
188 default: return -999.;
193 //______________________________________________________________________________
194 Float_t AliPIDResponse::NumberOfSigmasEMCAL(const AliVTrack *track, AliPID::EParticleType type) const {
196 AliVCluster *matchedClus = NULL;
201 Double_t fClsE = -1.;
203 Int_t nMatchClus = -1;
207 nMatchClus = track->GetEMCALcluster();
212 charge = track->Charge();
214 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
218 // matched cluster is EMCAL
219 if(matchedClus->IsEMCAL()){
221 fClsE = matchedClus->E();
225 // NSigma value really meaningful only for electrons!
226 return fEMCALResponse.GetNumberOfSigmas(pt,EovP,type,charge);
235 //______________________________________________________________________________
236 Float_t AliPIDResponse::NumberOfSigmasEMCAL(const AliVTrack *track, AliPID::EParticleType type, Double_t &eop, Double_t showershape[4]) const {
238 AliVCluster *matchedClus = NULL;
243 Double_t fClsE = -1.;
245 Int_t nMatchClus = -1;
249 nMatchClus = track->GetEMCALcluster();
254 charge = track->Charge();
256 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
260 // matched cluster is EMCAL
261 if(matchedClus->IsEMCAL()){
263 fClsE = matchedClus->E();
266 // fill used EMCAL variables here
268 showershape[0] = matchedClus->GetNCells(); // number of cells in cluster
269 showershape[1] = matchedClus->GetM02(); // long axis
270 showershape[2] = matchedClus->GetM20(); // short axis
271 showershape[3] = matchedClus->GetDispersion(); // dispersion
273 // NSigma value really meaningful only for electrons!
274 return fEMCALResponse.GetNumberOfSigmas(pt,EovP,type,charge);
282 //______________________________________________________________________________
283 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePIDProbability (EDetCode detCode, const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
286 // Compute PID response of 'detCode'
290 case kDetITS: return ComputeITSProbability(track, nSpecies, p); break;
291 case kDetTPC: return ComputeTPCProbability(track, nSpecies, p); break;
292 case kDetTOF: return ComputeTOFProbability(track, nSpecies, p); break;
293 case kDetTRD: return ComputeTRDProbability(track, nSpecies, p); break;
294 case kDetPHOS: return ComputePHOSProbability(track, nSpecies, p); break;
295 case kDetEMCAL: return ComputeEMCALProbability(track, nSpecies, p); break;
296 case kDetHMPID: return ComputeHMPIDProbability(track, nSpecies, p); break;
297 default: return kDetNoSignal;
301 //______________________________________________________________________________
302 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeITSProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
305 // Compute PID response for the ITS
308 // set flat distribution (no decision)
309 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
311 if ((track->GetStatus()&AliVTrack::kITSin)==0 &&
312 (track->GetStatus()&AliVTrack::kITSout)==0) return kDetNoSignal;
314 Double_t mom=track->P();
315 Double_t dedx=track->GetITSsignal();
318 ULong_t trStatus=track->GetStatus();
319 if(trStatus&AliVTrack::kTPCin) isSA=kFALSE;
320 UChar_t clumap=track->GetITSClusterMap();
321 Int_t nPointsForPid=0;
322 for(Int_t i=2; i<6; i++){
323 if(clumap&(1<<i)) ++nPointsForPid;
326 if(nPointsForPid<3) { // track not to be used for combined PID purposes
327 // track->ResetStatus(AliVTrack::kITSpid);
331 Bool_t mismatch=kTRUE/*, heavy=kTRUE*/;
332 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
333 Double_t mass=AliPID::ParticleMass(j);//GeV/c^2
334 Double_t bethe=fITSResponse.Bethe(momITS,mass);
335 Double_t sigma=fITSResponse.GetResolution(bethe,nPointsForPid,isSA);
336 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
337 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
339 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
343 // Check for particles heavier than (AliPID::kSPECIES - 1)
344 // if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
349 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
356 //______________________________________________________________________________
357 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTPCProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
360 // Compute PID response for the TPC
363 // set flat distribution (no decision)
364 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
366 // check quality of the track
367 if ( (track->GetStatus()&AliVTrack::kTPCin )==0 && (track->GetStatus()&AliVTrack::kTPCout)==0 ) return kDetNoSignal;
369 Double_t mom = track->GetTPCmomentum();
371 Double_t dedx=track->GetTPCsignal();
372 Bool_t mismatch=kTRUE/*, heavy=kTRUE*/;
374 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
375 AliPID::EParticleType type=AliPID::EParticleType(j);
376 Double_t bethe=fTPCResponse.GetExpectedSignal(mom,type);
377 Double_t sigma=fTPCResponse.GetExpectedSigma(mom,track->GetTPCsignalN(),type);
378 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
379 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
381 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
385 // TODO: Light nuclei, also in TPC pid response
387 // Check for particles heavier than (AliPID::kSPECIES - 1)
388 // if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
393 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
399 //______________________________________________________________________________
400 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTOFProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
403 // Compute PID response for the
406 Double_t meanCorrFactor = 0.11/fTOFtail; // Correction factor on the mean because of the tail (should be ~ 0.1 with tail = 1.1)
408 // set flat distribution (no decision)
409 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
411 if ((track->GetStatus()&AliVTrack::kTOFout)==0) return kDetNoSignal;
412 if ((track->GetStatus()&AliVTrack::kTIME)==0) return kDetNoSignal;
414 Double_t time[AliPID::kSPECIESN];
415 track->GetIntegratedTimes(time);
417 // Double_t sigma[AliPID::kSPECIES];
418 // for (Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++) {
419 // sigma[iPart] = fTOFResponse.GetExpectedSigma(track->P(),time[iPart],AliPID::ParticleMass(iPart));
422 Bool_t mismatch = kTRUE/*, heavy = kTRUE*/;
423 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
424 AliPID::EParticleType type=AliPID::EParticleType(j);
425 Double_t nsigmas=NumberOfSigmasTOF(track,type) + meanCorrFactor;
427 // Double_t sig = sigma[j];
428 Double_t expTime = fTOFResponse.GetExpectedSignal(track,type);
429 Double_t sig = fTOFResponse.GetExpectedSigma(track->P(),expTime,AliPID::ParticleMassZ(type));
430 if (TMath::Abs(nsigmas) > (fRange+2)) {
431 if(nsigmas < fTOFtail)
432 p[j] = TMath::Exp(-0.5*(fRange+2)*(fRange+2))/sig;
434 p[j] = TMath::Exp(-(fRange+2 - fTOFtail*0.5)*fTOFtail)/sig;
436 if(nsigmas < fTOFtail)
437 p[j] = TMath::Exp(-0.5*nsigmas*nsigmas)/sig;
439 p[j] = TMath::Exp(-(nsigmas - fTOFtail*0.5)*fTOFtail)/sig;
442 /* OLD Gaussian shape
443 if (TMath::Abs(nsigmas) > (fRange+2)) {
444 p[j] = TMath::Exp(-0.5*(fRange+2)*(fRange+2))/sig;
446 p[j] = TMath::Exp(-0.5*nsigmas*nsigmas)/sig;
449 if (TMath::Abs(nsigmas)<5.){
450 Double_t nsigmasTPC=NumberOfSigmasTPC(track,type);
451 if (TMath::Abs(nsigmasTPC)<5.) mismatch=kFALSE;
459 // TODO: Light nuclei
463 //______________________________________________________________________________
464 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTRDProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
467 // Compute PID response for the
470 // set flat distribution (no decision)
471 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
472 if((track->GetStatus()&AliVTrack::kTRDout)==0) return kDetNoSignal;
475 Double_t dedx[48]; // Allocate space for the maximum number of TRD slices
476 Int_t nslices = fTRDslicesForPID[1] - fTRDslicesForPID[0] + 1;
477 AliDebug(1, Form("First Slice: %d, Last Slice: %d, Number of slices: %d", fTRDslicesForPID[0], fTRDslicesForPID[1], nslices));
478 for(UInt_t ilayer = 0; ilayer < 6; ilayer++){
479 mom[ilayer] = track->GetTRDmomentum(ilayer);
480 for(UInt_t islice = fTRDslicesForPID[0]; islice <= fTRDslicesForPID[1]; islice++){
481 dedx[ilayer*nslices+islice-fTRDslicesForPID[0]] = track->GetTRDslice(ilayer, islice);
484 fTRDResponse.GetResponse(nslices, dedx, mom, p);
487 //______________________________________________________________________________
488 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeEMCALProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
491 // Compute PID response for the EMCAL
494 AliVCluster *matchedClus = NULL;
499 Double_t fClsE = -1.;
501 Int_t nMatchClus = -1;
505 nMatchClus = track->GetEMCALcluster();
511 charge = track->Charge();
513 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
517 // matched cluster is EMCAL
518 if(matchedClus->IsEMCAL()){
520 fClsE = matchedClus->E();
524 // compute the probabilities
525 if( 999 != fEMCALResponse.ComputeEMCALProbability(pt,EovP,charge,p)){
527 // in case everything is OK
535 // in all other cases set flat distribution (no decision)
536 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
540 //______________________________________________________________________________
541 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePHOSProbability (const AliVTrack */*track*/, Int_t nSpecies, Double_t p[]) const
544 // Compute PID response for the PHOS
547 // set flat distribution (no decision)
548 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
551 //______________________________________________________________________________
552 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeHMPIDProbability(const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
555 // Compute PID response for the HMPID
558 // set flat distribution (no decision)
559 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
560 if((track->GetStatus()&AliVTrack::kHMPIDpid)==0) return kDetNoSignal;
562 track->GetHMPIDpid(p);
567 //______________________________________________________________________________
568 void AliPIDResponse::InitialiseEvent(AliVEvent *event, Int_t pass)
571 // Apply settings for the current event
578 fRun=event->GetRunNumber();
585 //TPC resolution parametrisation PbPb
586 if ( fResolutionCorrection ){
587 Double_t corrSigma=fResolutionCorrection->Eval(GetTPCMultiplicityBin(event));
588 fTPCResponse.SetSigma(3.79301e-03*corrSigma, 2.21280e+04);
592 SetTOFResponse(event, (AliPIDResponse::EStartTimeType_t)fTOFPIDParams->GetStartTimeMethod());
595 // Get and set centrality
596 AliCentrality *centrality = event->GetCentrality();
598 fCurrCentrality = centrality->GetCentralityPercentile("V0M");
601 fCurrCentrality = -1;
605 //______________________________________________________________________________
606 void AliPIDResponse::ExecNewRun()
609 // Things to Execute upon a new run
613 SetITSParametrisation();
615 SetTPCPidResponseMaster();
616 SetTPCParametrisation();
618 SetTRDPidResponseMaster();
619 InitializeTRDResponse();
621 SetEMCALPidResponseMaster();
622 InitializeEMCALResponse();
624 SetTOFPidResponseMaster();
625 InitializeTOFResponse();
628 //_____________________________________________________
629 Double_t AliPIDResponse::GetTPCMultiplicityBin(const AliVEvent * const event)
632 // Get TPC multiplicity in bins of 150
635 const AliVVertex* vertexTPC = event->GetPrimaryVertex();
636 Double_t tpcMulti=0.;
638 Double_t vertexContribTPC=vertexTPC->GetNContributors();
639 tpcMulti=vertexContribTPC/150.;
640 if (tpcMulti>20.) tpcMulti=20.;
646 //______________________________________________________________________________
647 void AliPIDResponse::SetRecoInfo()
650 // Set reconstruction information
662 TPRegexp reg(".*(LHC1[1-2][a-z]+[0-9]+[a-z_]*)/.*");
664 //find the period by run number (UGLY, but not stored in ESD and AOD... )
665 if (fRun>=114737&&fRun<=117223) { fLHCperiod="LHC10B"; fMCperiodTPC="LHC10D1"; }
666 else if (fRun>=118503&&fRun<=121040) { fLHCperiod="LHC10C"; fMCperiodTPC="LHC10D1"; }
667 else if (fRun>=122195&&fRun<=126437) { fLHCperiod="LHC10D"; fMCperiodTPC="LHC10F6A"; }
668 else if (fRun>=127710&&fRun<=130850) { fLHCperiod="LHC10E"; fMCperiodTPC="LHC10F6A"; }
669 else if (fRun>=133004&&fRun<=135029) { fLHCperiod="LHC10F"; fMCperiodTPC="LHC10F6A"; }
670 else if (fRun>=135654&&fRun<=136377) { fLHCperiod="LHC10G"; fMCperiodTPC="LHC10F6A"; }
671 else if (fRun>=136851&&fRun<=139517) {
673 fMCperiodTPC="LHC10H8";
674 if (reg.MatchB(fCurrentFile)) fMCperiodTPC="LHC11A10";
677 else if (fRun>=139699&&fRun<=146860) { fLHCperiod="LHC11A"; fMCperiodTPC="LHC10F6A"; }
678 //TODO: periods 11B, 11C are not yet treated assume 11d for the moment
679 else if (fRun>=148531&&fRun<=155384) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
680 else if (fRun>=156477&&fRun<=159635) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
681 else if (fRun>=166529) {
683 fMCperiodTPC="LHC11A10";
688 //exception new pp MC productions from 2011
689 if (fBeamType=="PP" && reg.MatchB(fCurrentFile)) fMCperiodTPC="LHC11B2";
690 // exception for 11f1
691 if (fCurrentFile.Contains("LHC11f1/")) fMCperiodTPC="LHC11F1";
694 //______________________________________________________________________________
695 void AliPIDResponse::SetITSParametrisation()
698 // Set the ITS parametrisation
702 //______________________________________________________________________________
703 void AliPIDResponse::SetTPCPidResponseMaster()
706 // Load the TPC pid response functions from the OADB
708 //don't load twice for the moment
709 if (fArrPidResponseMaster) return;
712 //reset the PID response functions
713 delete fArrPidResponseMaster;
714 fArrPidResponseMaster=0x0;
716 TString fileName(Form("%s/COMMON/PID/data/TPCPIDResponse.root", fOADBPath.Data()));
718 TFile *f=TFile::Open(fileName.Data());
719 if (f && f->IsOpen() && !f->IsZombie()){
720 fArrPidResponseMaster=dynamic_cast<TObjArray*>(f->Get("TPCPIDResponse"));
724 if (!fArrPidResponseMaster){
725 AliFatal(Form("Could not retrieve the TPC pid response from: %s",fileName.Data()));
728 fArrPidResponseMaster->SetOwner();
731 //______________________________________________________________________________
732 void AliPIDResponse::SetTPCParametrisation()
735 // Change BB parametrisation for current run
738 if (fLHCperiod.IsNull()) {
739 AliFatal("No period set, not changing parametrisation");
744 // Set default parametrisations for data and MC
748 TString datatype="DATA";
749 //in case of mc fRecoPass is per default 1
758 for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
759 fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,0x0);
763 TString period=fLHCperiod;
764 if (fIsMC) period=fMCperiodTPC;
766 AliInfo(Form("Searching splines for: %s %s PASS%d %s",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
769 //set the new PID splines
771 if (fArrPidResponseMaster){
773 //for MC don't use period information
774 // if (fIsMC) period="[A-Z0-9]*";
775 //for MC use MC period information
776 //pattern for the default entry (valid for all particles)
777 TPRegexp reg(Form("TSPLINE3_%s_([A-Z]*)_%s_PASS%d_%s_MEAN",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
779 //loop over entries and filter them
780 for (Int_t iresp=0; iresp<fArrPidResponseMaster->GetEntriesFast();++iresp){
781 TObject *responseFunction=fArrPidResponseMaster->At(iresp);
782 if (responseFunction==0x0) continue;
783 TString responseName=responseFunction->GetName();
785 if (!reg.MatchB(responseName)) continue;
787 TObjArray *arr=reg.MatchS(responseName);
788 TString particleName=arr->At(1)->GetName();
790 if (particleName.IsNull()) continue;
791 if (particleName=="ALL") grAll=responseFunction;
794 for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
795 TString particle=AliPID::ParticleName(ispec);
797 if ( particle == particleName ){
798 fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,responseFunction);
799 fTPCResponse.SetUseDatabase(kTRUE);
800 AliInfo(Form("Adding graph: %d - %s",ispec,responseFunction->GetName()));
808 //set default response function to all particles which don't have a specific one
810 for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
811 if (!fTPCResponse.GetResponseFunction((AliPID::EParticleType)ispec)){
812 fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,grAll);
813 AliInfo(Form("Adding graph: %d - %s",ispec,grAll->GetName()));
821 AliError(Form("No splines found for: %s %s PASS%d %s",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
824 // Setup resolution parametrisation
828 fTPCResponse.SetSigma(3.79301e-03, 2.21280e+04);
831 fTPCResponse.SetSigma(2.30176e-02, 5.60422e+02);
833 if (fArrPidResponseMaster)
834 fResolutionCorrection=(TF1*)fArrPidResponseMaster->FindObject(Form("TF1_%s_ALL_%s_PASS%d_%s_SIGMA",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
836 if (fResolutionCorrection) AliInfo(Form("Setting multiplicity correction function: %s",fResolutionCorrection->GetName()));
839 //______________________________________________________________________________
840 void AliPIDResponse::SetTRDPidResponseMaster()
843 // Load the TRD pid params and references from the OADB
845 if(fTRDPIDResponseObject) return;
846 AliOADBContainer contParams("contParams");
848 Int_t statusResponse = contParams.InitFromFile(Form("%s/COMMON/PID/data/TRDPIDResponse.root", fOADBPath.Data()), "AliTRDPIDResponseObject");
850 AliError("Failed initializing PID Response Object from OADB");
852 AliInfo(Form("Loading TRD Response from %s/COMMON/PID/data/TRDPIDResponse.root", fOADBPath.Data()));
853 fTRDPIDResponseObject = dynamic_cast<AliTRDPIDResponseObject *>(contParams.GetObject(fRun));
854 if(!fTRDPIDResponseObject){
855 AliError(Form("TRD Response not found in run %d", fRun));
859 AliOADBContainer contRefs("contRefs");
860 Int_t statusRefs = contRefs.InitFromFile(Form("%s/COMMON/PID/data/TRDPIDReferenceLQ1D.root", fOADBPath.Data()), "AliTRDPIDReference");
862 AliInfo("Failed Loading References for TRD");
864 AliInfo(Form("Loading TRD References from %s/COMMON/PID/data/TRDPIDReferenceLQ1D.root", fOADBPath.Data()));
865 fTRDPIDReference = dynamic_cast<AliTRDPIDReference *>(contRefs.GetObject(fRun));
866 if(!fTRDPIDReference){
867 AliError(Form("TRD References not found in OADB Container for run %d", fRun));
873 //______________________________________________________________________________
874 void AliPIDResponse::InitializeTRDResponse(){
876 // Set PID Params and references to the TRD PID response
878 fTRDResponse.SetPIDResponseObject(fTRDPIDResponseObject);
879 if(fLHCperiod == "LHC10b" || fLHCperiod == "LHC10c" || fLHCperiod == "LHC10d" || fLHCperiod == "LHC10e"){
880 fTRDslicesForPID[0] = 0;
881 fTRDslicesForPID[1] = 7;
885 //______________________________________________________________________________
886 void AliPIDResponse::SetTOFPidResponseMaster()
889 // Load the TOF pid params from the OADB
891 TFile *oadbf = new TFile(Form("%s/COMMON/PID/data/TOFPIDParams.root",fOADBPath.Data()));
892 if (oadbf->IsOpen()) {
893 AliInfo(Form("Loading TOF Params from %s/COMMON/PID/data/TOFPIDParams.root", fOADBPath.Data()));
894 AliOADBContainer *oadbc = (AliOADBContainer *)oadbf->Get("TOFoadb");
895 if (fTOFPIDParams) delete fTOFPIDParams;
896 fTOFPIDParams = dynamic_cast<AliTOFPIDParams *>(oadbc->GetObject(fRun,"TOFparams"));
900 AliError(Form("TOFPIDParams.root not found in %s/COMMON/PID/data !!",fOADBPath.Data()));
906 //______________________________________________________________________________
907 void AliPIDResponse::InitializeTOFResponse(){
909 // Set PID Params to the TOF PID response
911 for (Int_t i=0;i<4;i++) {
912 fTOFResponse.SetTrackParameter(i,fTOFPIDParams->GetSigParams(i));
914 fTOFResponse.SetTimeResolution(fTOFPIDParams->GetTOFresolution());
919 //_________________________________________________________________________
920 Bool_t AliPIDResponse::IdentifiedAsElectronTRD(const AliVTrack *vtrack, Double_t efficiencyLevel) const {
922 // Check whether track is identified as electron under a given electron efficiency hypothesis
924 Double_t probs[AliPID::kSPECIES];
925 ComputeTRDProbability(vtrack, AliPID::kSPECIES, probs);
927 Int_t ntracklets = vtrack->GetTRDntrackletsPID();
928 // Take mean of the TRD momenta in the given tracklets
929 Float_t p = 0, trdmomenta[AliVTrack::kTRDnPlanes];
931 for(Int_t iPl=0;iPl<AliVTrack::kTRDnPlanes;iPl++){
932 if(vtrack->GetTRDmomentum(iPl) > 0.){
933 trdmomenta[nmomenta++] = vtrack->GetTRDmomentum(iPl);
936 p = TMath::Mean(nmomenta, trdmomenta);
938 return fTRDResponse.IdentifiedAsElectron(ntracklets, probs, p, efficiencyLevel);
941 //______________________________________________________________________________
942 void AliPIDResponse::SetEMCALPidResponseMaster()
945 // Load the EMCAL pid response functions from the OADB
947 TObjArray* fEMCALPIDParamsRun = NULL;
948 TObjArray* fEMCALPIDParamsPass = NULL;
950 if(fEMCALPIDParams) return;
951 AliOADBContainer contParams("contParams");
953 Int_t statusPars = contParams.InitFromFile(Form("%s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()), "AliEMCALPIDParams");
955 AliError("Failed initializing PID Params from OADB");
958 AliInfo(Form("Loading EMCAL Params from %s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()));
960 fEMCALPIDParamsRun = dynamic_cast<TObjArray *>(contParams.GetObject(fRun));
961 if(fEMCALPIDParamsRun) fEMCALPIDParamsPass = dynamic_cast<TObjArray *>(fEMCALPIDParamsRun->FindObject(Form("pass%d",fRecoPass)));
962 if(fEMCALPIDParamsPass) fEMCALPIDParams = dynamic_cast<TObjArray *>(fEMCALPIDParamsPass->FindObject(Form("EMCALPIDParams_Particles")));
964 if(!fEMCALPIDParams){
965 AliInfo(Form("EMCAL Params not found in run %d pass %d", fRun, fRecoPass));
966 AliInfo("Will take the standard LHC11d instead ...");
968 fEMCALPIDParamsRun = dynamic_cast<TObjArray *>(contParams.GetObject(156477));
969 if(fEMCALPIDParamsRun) fEMCALPIDParamsPass = dynamic_cast<TObjArray *>(fEMCALPIDParamsRun->FindObject(Form("pass%d",1)));
970 if(fEMCALPIDParamsPass) fEMCALPIDParams = dynamic_cast<TObjArray *>(fEMCALPIDParamsPass->FindObject(Form("EMCALPIDParams_Particles")));
972 if(!fEMCALPIDParams){
973 AliError(Form("DEFAULT EMCAL Params (LHC11d) not found in file %s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()));
979 //______________________________________________________________________________
980 void AliPIDResponse::InitializeEMCALResponse(){
982 // Set PID Params to the EMCAL PID response
984 fEMCALResponse.SetPIDParams(fEMCALPIDParams);
987 //_________________________________________________________________________
988 void AliPIDResponse::SetTOFResponse(AliVEvent *vevent,EStartTimeType_t option){
990 // Set TOF response function
991 // Input option for event_time used
994 Float_t t0spread = 0.; //vevent->GetEventTimeSpread();
995 if(t0spread < 10) t0spread = 80;
997 // T0 from TOF algorithm
999 Bool_t flagT0TOF=kFALSE;
1000 Bool_t flagT0T0=kFALSE;
1001 Float_t *startTime = new Float_t[fTOFResponse.GetNmomBins()];
1002 Float_t *startTimeRes = new Float_t[fTOFResponse.GetNmomBins()];
1003 Int_t *startTimeMask = new Int_t[fTOFResponse.GetNmomBins()];
1006 Float_t *estimatedT0event = new Float_t[fTOFResponse.GetNmomBins()];
1007 Float_t *estimatedT0resolution = new Float_t[fTOFResponse.GetNmomBins()];
1008 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1009 estimatedT0event[i]=0.0;
1010 estimatedT0resolution[i]=0.0;
1011 startTimeMask[i] = 0;
1014 Float_t resT0A=75,resT0C=65,resT0AC=55;
1015 if(vevent->GetT0TOF()){ // check if T0 detector information is available
1020 AliTOFHeader *tofHeader = (AliTOFHeader*)vevent->GetTOFHeader();
1022 if (tofHeader) { // read global info and T0-TOF
1023 fTOFResponse.SetTimeResolution(tofHeader->GetTOFResolution());
1024 t0spread = tofHeader->GetT0spread(); // read t0 sprad
1025 if(t0spread < 10) t0spread = 80;
1028 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){ // read T0-TOF default value
1029 startTime[i]=tofHeader->GetDefaultEventTimeVal();
1030 startTimeRes[i]=tofHeader->GetDefaultEventTimeRes();
1031 if(startTimeRes[i] < 1.e-5) startTimeRes[i] = t0spread;
1034 TArrayI *ibin=(TArrayI*)tofHeader->GetNvalues();
1035 TArrayF *t0Bin=(TArrayF*)tofHeader->GetEventTimeValues();
1036 TArrayF *t0ResBin=(TArrayF*)tofHeader->GetEventTimeRes();
1037 for(Int_t j=0;j < tofHeader->GetNbins();j++){ // fill T0-TOF in p-bins
1038 Int_t icurrent = (Int_t)ibin->GetAt(j);
1039 startTime[icurrent]=t0Bin->GetAt(j);
1040 startTimeRes[icurrent]=t0ResBin->GetAt(j);
1041 if(startTimeRes[icurrent] < 1.e-5) startTimeRes[icurrent] = t0spread;
1045 // for cut of 3 sigma on t0 spread
1046 Float_t t0cut = 3 * t0spread;
1047 if(t0cut < 500) t0cut = 500;
1049 if(option == kFILL_T0){ // T0-FILL is used
1050 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1051 estimatedT0event[i]=0.0;
1052 estimatedT0resolution[i]=t0spread;
1054 fTOFResponse.SetT0event(estimatedT0event);
1055 fTOFResponse.SetT0resolution(estimatedT0resolution);
1058 if(option == kTOF_T0){ // T0-TOF is used when available (T0-FILL otherwise) from ESD
1060 fTOFResponse.SetT0event(startTime);
1061 fTOFResponse.SetT0resolution(startTimeRes);
1062 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1063 if(startTimeRes[i]<t0spread) startTimeMask[i]=1;
1064 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1068 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1069 estimatedT0event[i]=0.0;
1070 estimatedT0resolution[i]=t0spread;
1071 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1073 fTOFResponse.SetT0event(estimatedT0event);
1074 fTOFResponse.SetT0resolution(estimatedT0resolution);
1077 else if(option == kBest_T0){ // T0-T0 or T0-TOF are used when available (T0-FILL otherwise) from ESD
1078 Float_t t0AC=-10000;
1082 t0AC= vevent->GetT0TOF()[0];
1083 t0A= vevent->GetT0TOF()[1];
1084 t0C= vevent->GetT0TOF()[2];
1087 Float_t t0t0Best = 0;
1088 Float_t t0t0BestRes = 9999;
1090 if(TMath::Abs(t0A) < t0cut && TMath::Abs(t0C) < t0cut && TMath::Abs(t0C-t0A) < 500){
1092 t0t0BestRes = resT0AC;
1095 else if(TMath::Abs(t0C) < t0cut){
1097 t0t0BestRes = resT0C;
1100 else if(TMath::Abs(t0A) < t0cut){
1102 t0t0BestRes = resT0A;
1106 if(flagT0TOF){ // if T0-TOF info is available
1107 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1108 if(t0t0BestRes < 999){
1109 if(startTimeRes[i] < t0spread){
1110 Double_t wtot = 1./startTimeRes[i]/startTimeRes[i] + 1./t0t0BestRes/t0t0BestRes;
1111 Double_t t0best = startTime[i]/startTimeRes[i]/startTimeRes[i] + t0t0Best/t0t0BestRes/t0t0BestRes;
1112 estimatedT0event[i]=t0best / wtot;
1113 estimatedT0resolution[i]=1./TMath::Sqrt(wtot);
1114 startTimeMask[i] = t0used+1;
1117 estimatedT0event[i]=t0t0Best;
1118 estimatedT0resolution[i]=t0t0BestRes;
1119 startTimeMask[i] = t0used;
1123 estimatedT0event[i]=startTime[i];
1124 estimatedT0resolution[i]=startTimeRes[i];
1125 if(startTimeRes[i]<t0spread) startTimeMask[i]=1;
1127 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1129 fTOFResponse.SetT0event(estimatedT0event);
1130 fTOFResponse.SetT0resolution(estimatedT0resolution);
1132 else{ // if no T0-TOF info is available
1133 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1134 fTOFResponse.SetT0binMask(i,t0used);
1135 if(t0t0BestRes < 999){
1136 estimatedT0event[i]=t0t0Best;
1137 estimatedT0resolution[i]=t0t0BestRes;
1140 estimatedT0event[i]=0.0;
1141 estimatedT0resolution[i]=t0spread;
1144 fTOFResponse.SetT0event(estimatedT0event);
1145 fTOFResponse.SetT0resolution(estimatedT0resolution);
1149 else if(option == kT0_T0){ // T0-T0 is used when available (T0-FILL otherwise)
1150 Float_t t0AC=-10000;
1154 t0AC= vevent->GetT0TOF()[0];
1155 t0A= vevent->GetT0TOF()[1];
1156 t0C= vevent->GetT0TOF()[2];
1159 if(TMath::Abs(t0A) < t0cut && TMath::Abs(t0C) < t0cut && TMath::Abs(t0C-t0A) < 500){
1160 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1161 estimatedT0event[i]=t0AC;
1162 estimatedT0resolution[i]=resT0AC;
1163 fTOFResponse.SetT0binMask(i,6);
1166 else if(TMath::Abs(t0C) < t0cut){
1167 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1168 estimatedT0event[i]=t0C;
1169 estimatedT0resolution[i]=resT0C;
1170 fTOFResponse.SetT0binMask(i,4);
1173 else if(TMath::Abs(t0A) < t0cut){
1174 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1175 estimatedT0event[i]=t0A;
1176 estimatedT0resolution[i]=resT0A;
1177 fTOFResponse.SetT0binMask(i,2);
1181 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1182 estimatedT0event[i]=0.0;
1183 estimatedT0resolution[i]=t0spread;
1184 fTOFResponse.SetT0binMask(i,0);
1187 fTOFResponse.SetT0event(estimatedT0event);
1188 fTOFResponse.SetT0resolution(estimatedT0resolution);
1190 delete [] startTime;
1191 delete [] startTimeRes;
1192 delete [] startTimeMask;
1193 delete [] estimatedT0event;
1194 delete [] estimatedT0resolution;