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 <AliTRDPIDParams.h>
39 #include <AliTRDPIDReference.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),
71 fTRDPIDReference(0x0),
81 AliLog::SetClassDebugLevel("AliPIDResponse",0);
82 AliLog::SetClassDebugLevel("AliESDpid",0);
83 AliLog::SetClassDebugLevel("AliAODpidUtil",0);
85 memset(fTRDslicesForPID,0,sizeof(UInt_t)*2);
88 //______________________________________________________________________________
89 AliPIDResponse::~AliPIDResponse()
94 delete fArrPidResponseMaster;
96 delete fTRDPIDReference;
97 if (fTOFPIDParams) delete fTOFPIDParams;
100 //______________________________________________________________________________
101 AliPIDResponse::AliPIDResponse(const AliPIDResponse &other) :
103 fITSResponse(other.fITSResponse),
104 fTPCResponse(other.fTPCResponse),
105 fTRDResponse(other.fTRDResponse),
106 fTOFResponse(other.fTOFResponse),
107 fEMCALResponse(other.fEMCALResponse),
108 fRange(other.fRange),
109 fITSPIDmethod(other.fITSPIDmethod),
111 fOADBPath(other.fOADBPath),
115 fMCperiodUser(other.fMCperiodUser),
118 fRecoPassUser(other.fRecoPassUser),
121 fArrPidResponseMaster(0x0),
122 fResolutionCorrection(0x0),
124 fTRDPIDReference(0x0),
127 fEMCALPIDParams(0x0),
134 memset(fTRDslicesForPID,0,sizeof(UInt_t)*2);
137 //______________________________________________________________________________
138 AliPIDResponse& AliPIDResponse::operator=(const AliPIDResponse &other)
144 delete fArrPidResponseMaster;
145 TNamed::operator=(other);
146 fITSResponse=other.fITSResponse;
147 fTPCResponse=other.fTPCResponse;
148 fTRDResponse=other.fTRDResponse;
149 fTOFResponse=other.fTOFResponse;
150 fEMCALResponse=other.fEMCALResponse;
152 fITSPIDmethod=other.fITSPIDmethod;
153 fOADBPath=other.fOADBPath;
158 fMCperiodUser=other.fMCperiodUser;
161 fRecoPassUser=other.fRecoPassUser;
164 fArrPidResponseMaster=0x0;
165 fResolutionCorrection=0x0;
167 fTRDPIDReference=0x0;
169 memset(fTRDslicesForPID,0,sizeof(UInt_t)*2);
172 fCurrentEvent=other.fCurrentEvent;
177 //______________________________________________________________________________
178 Float_t AliPIDResponse::NumberOfSigmas(EDetCode detCode, const AliVParticle *track, AliPID::EParticleType type) const
181 // NumberOfSigmas for 'detCode'
185 case kDetITS: return NumberOfSigmasITS(track, type); break;
186 case kDetTPC: return NumberOfSigmasTPC(track, type); break;
187 case kDetTOF: return NumberOfSigmasTOF(track, type); break;
188 // case kDetTRD: return ComputeTRDProbability(track, type); break;
189 // case kDetPHOS: return ComputePHOSProbability(track, type); break;
190 // case kDetEMCAL: return NumberOfSigmasEMCAL(track, type); break;
191 // case kDetHMPID: return ComputeHMPIDProbability(track, type); break;
192 default: return -999.;
197 //______________________________________________________________________________
198 Float_t AliPIDResponse::NumberOfSigmasEMCAL(const AliVTrack *track, AliPID::EParticleType type) const {
200 AliVCluster *matchedClus = NULL;
205 Double_t fClsE = -1.;
207 Int_t nMatchClus = -1;
211 nMatchClus = track->GetEMCALcluster();
216 charge = track->Charge();
218 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
222 // matched cluster is EMCAL
223 if(matchedClus->IsEMCAL()){
225 fClsE = matchedClus->E();
229 // NSigma value really meaningful only for electrons!
230 return fEMCALResponse.GetNumberOfSigmas(pt,EovP,type,charge);
239 //______________________________________________________________________________
240 Float_t AliPIDResponse::NumberOfSigmasEMCAL(const AliVTrack *track, AliPID::EParticleType type, Double_t &eop, Double_t showershape[4]) const {
242 AliVCluster *matchedClus = NULL;
247 Double_t fClsE = -1.;
249 Int_t nMatchClus = -1;
253 nMatchClus = track->GetEMCALcluster();
258 charge = track->Charge();
260 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
264 // matched cluster is EMCAL
265 if(matchedClus->IsEMCAL()){
267 fClsE = matchedClus->E();
270 // fill used EMCAL variables here
272 showershape[0] = matchedClus->GetNCells(); // number of cells in cluster
273 showershape[1] = matchedClus->GetM02(); // long axis
274 showershape[2] = matchedClus->GetM20(); // short axis
275 showershape[3] = matchedClus->GetDispersion(); // dispersion
277 // NSigma value really meaningful only for electrons!
278 return fEMCALResponse.GetNumberOfSigmas(pt,EovP,type,charge);
286 //______________________________________________________________________________
287 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePIDProbability (EDetCode detCode, const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
290 // Compute PID response of 'detCode'
294 case kDetITS: return ComputeITSProbability(track, nSpecies, p); break;
295 case kDetTPC: return ComputeTPCProbability(track, nSpecies, p); break;
296 case kDetTOF: return ComputeTOFProbability(track, nSpecies, p); break;
297 case kDetTRD: return ComputeTRDProbability(track, nSpecies, p); break;
298 case kDetPHOS: return ComputePHOSProbability(track, nSpecies, p); break;
299 case kDetEMCAL: return ComputeEMCALProbability(track, nSpecies, p); break;
300 case kDetHMPID: return ComputeHMPIDProbability(track, nSpecies, p); break;
301 default: return kDetNoSignal;
305 //______________________________________________________________________________
306 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeITSProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
309 // Compute PID response for the ITS
312 // set flat distribution (no decision)
313 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
315 if ((track->GetStatus()&AliVTrack::kITSin)==0 &&
316 (track->GetStatus()&AliVTrack::kITSout)==0) return kDetNoSignal;
318 Double_t mom=track->P();
319 Double_t dedx=track->GetITSsignal();
322 ULong_t trStatus=track->GetStatus();
323 if(trStatus&AliVTrack::kTPCin) isSA=kFALSE;
324 UChar_t clumap=track->GetITSClusterMap();
325 Int_t nPointsForPid=0;
326 for(Int_t i=2; i<6; i++){
327 if(clumap&(1<<i)) ++nPointsForPid;
330 if(nPointsForPid<3) { // track not to be used for combined PID purposes
331 // track->ResetStatus(AliVTrack::kITSpid);
335 Bool_t mismatch=kTRUE/*, heavy=kTRUE*/;
336 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
337 Double_t mass=AliPID::ParticleMass(j);//GeV/c^2
338 Double_t bethe=fITSResponse.Bethe(momITS,mass);
339 Double_t sigma=fITSResponse.GetResolution(bethe,nPointsForPid,isSA);
340 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
341 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
343 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
347 // Check for particles heavier than (AliPID::kSPECIES - 1)
348 // if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
353 for (Int_t j=0; j<AliPID::kSPECIES; j++) p[j]=1./AliPID::kSPECIES;
360 //______________________________________________________________________________
361 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTPCProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
364 // Compute PID response for the TPC
367 // set flat distribution (no decision)
368 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
370 // check quality of the track
371 if ( (track->GetStatus()&AliVTrack::kTPCin )==0 && (track->GetStatus()&AliVTrack::kTPCout)==0 ) return kDetNoSignal;
373 Double_t mom = track->GetTPCmomentum();
375 Double_t dedx=track->GetTPCsignal();
376 Bool_t mismatch=kTRUE/*, heavy=kTRUE*/;
378 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
379 AliPID::EParticleType type=AliPID::EParticleType(j);
380 Double_t bethe=fTPCResponse.GetExpectedSignal(mom,type);
381 Double_t sigma=fTPCResponse.GetExpectedSigma(mom,track->GetTPCsignalN(),type);
382 if (TMath::Abs(dedx-bethe) > fRange*sigma) {
383 p[j]=TMath::Exp(-0.5*fRange*fRange)/sigma;
385 p[j]=TMath::Exp(-0.5*(dedx-bethe)*(dedx-bethe)/(sigma*sigma))/sigma;
389 // TODO: Light nuclei, also in TPC pid response
391 // Check for particles heavier than (AliPID::kSPECIES - 1)
392 // if (dedx < (bethe + fRange*sigma)) heavy=kFALSE;
397 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
403 //______________________________________________________________________________
404 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTOFProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
407 // Compute PID response for the
410 Double_t meanCorrFactor = 0.11/fTOFtail; // Correction factor on the mean because of the tail (should be ~ 0.1 with tail = 1.1)
412 // set flat distribution (no decision)
413 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
415 if ((track->GetStatus()&AliVTrack::kTOFout)==0) return kDetNoSignal;
416 if ((track->GetStatus()&AliVTrack::kTIME)==0) return kDetNoSignal;
418 Double_t time[AliPID::kSPECIESN];
419 track->GetIntegratedTimes(time);
421 // Double_t sigma[AliPID::kSPECIES];
422 // for (Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++) {
423 // sigma[iPart] = fTOFResponse.GetExpectedSigma(track->P(),time[iPart],AliPID::ParticleMass(iPart));
426 Bool_t mismatch = kTRUE/*, heavy = kTRUE*/;
427 for (Int_t j=0; j<AliPID::kSPECIES; j++) {
428 AliPID::EParticleType type=AliPID::EParticleType(j);
429 Double_t nsigmas=NumberOfSigmasTOF(track,type) + meanCorrFactor;
431 // Double_t sig = sigma[j];
432 Double_t expTime = fTOFResponse.GetExpectedSignal(track,type);
433 Double_t sig = fTOFResponse.GetExpectedSigma(track->P(),expTime,AliPID::ParticleMassZ(type));
434 if (TMath::Abs(nsigmas) > (fRange+2)) {
435 if(nsigmas < fTOFtail)
436 p[j] = TMath::Exp(-0.5*(fRange+2)*(fRange+2))/sig;
438 p[j] = TMath::Exp(-(fRange+2 - fTOFtail*0.5)*fTOFtail)/sig;
440 if(nsigmas < fTOFtail)
441 p[j] = TMath::Exp(-0.5*nsigmas*nsigmas)/sig;
443 p[j] = TMath::Exp(-(nsigmas - fTOFtail*0.5)*fTOFtail)/sig;
446 /* OLD Gaussian shape
447 if (TMath::Abs(nsigmas) > (fRange+2)) {
448 p[j] = TMath::Exp(-0.5*(fRange+2)*(fRange+2))/sig;
450 p[j] = TMath::Exp(-0.5*nsigmas*nsigmas)/sig;
453 if (TMath::Abs(nsigmas)<5.){
454 Double_t nsigmasTPC=NumberOfSigmasTPC(track,type);
455 if (TMath::Abs(nsigmasTPC)<5.) mismatch=kFALSE;
463 // TODO: Light nuclei
467 //______________________________________________________________________________
468 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeTRDProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
471 // Compute PID response for the
474 // set flat distribution (no decision)
475 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
476 if((track->GetStatus()&AliVTrack::kTRDout)==0) return kDetNoSignal;
479 Double_t dedx[48]; // Allocate space for the maximum number of TRD slices
480 Int_t nslices = fTRDslicesForPID[1] - fTRDslicesForPID[0] + 1;
481 AliDebug(1, Form("First Slice: %d, Last Slice: %d, Number of slices: %d", fTRDslicesForPID[0], fTRDslicesForPID[1], nslices));
482 for(UInt_t ilayer = 0; ilayer < 6; ilayer++){
483 mom[ilayer] = track->GetTRDmomentum(ilayer);
484 for(UInt_t islice = fTRDslicesForPID[0]; islice <= fTRDslicesForPID[1]; islice++){
485 dedx[ilayer*nslices+islice-fTRDslicesForPID[0]] = track->GetTRDslice(ilayer, islice);
488 fTRDResponse.GetResponse(nslices, dedx, mom, p);
491 //______________________________________________________________________________
492 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeEMCALProbability (const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
495 // Compute PID response for the EMCAL
498 AliVCluster *matchedClus = NULL;
503 Double_t fClsE = -1.;
505 Int_t nMatchClus = -1;
509 nMatchClus = track->GetEMCALcluster();
515 charge = track->Charge();
517 matchedClus = (AliVCluster*)fCurrentEvent->GetCaloCluster(nMatchClus);
521 // matched cluster is EMCAL
522 if(matchedClus->IsEMCAL()){
524 fClsE = matchedClus->E();
528 // compute the probabilities
529 if( 999 != fEMCALResponse.ComputeEMCALProbability(pt,EovP,charge,p)){
531 // in case everything is OK
539 // in all other cases set flat distribution (no decision)
540 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
544 //______________________________________________________________________________
545 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputePHOSProbability (const AliVTrack */*track*/, Int_t nSpecies, Double_t p[]) const
548 // Compute PID response for the PHOS
551 // set flat distribution (no decision)
552 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
555 //______________________________________________________________________________
556 AliPIDResponse::EDetPidStatus AliPIDResponse::ComputeHMPIDProbability(const AliVTrack *track, Int_t nSpecies, Double_t p[]) const
559 // Compute PID response for the HMPID
562 // set flat distribution (no decision)
563 for (Int_t j=0; j<nSpecies; j++) p[j]=1./nSpecies;
564 if((track->GetStatus()&AliVTrack::kHMPIDpid)==0) return kDetNoSignal;
566 track->GetHMPIDpid(p);
571 //______________________________________________________________________________
572 void AliPIDResponse::InitialiseEvent(AliVEvent *event, Int_t pass)
575 // Apply settings for the current event
582 fRun=event->GetRunNumber();
589 //TPC resolution parametrisation PbPb
590 if ( fResolutionCorrection ){
591 Double_t corrSigma=fResolutionCorrection->Eval(GetTPCMultiplicityBin(event));
592 fTPCResponse.SetSigma(3.79301e-03*corrSigma, 2.21280e+04);
596 SetTOFResponse(event, (AliPIDResponse::EStartTimeType_t)fTOFPIDParams->GetStartTimeMethod());
599 // Get and set centrality
600 AliCentrality *centrality = event->GetCentrality();
602 fCurrCentrality = centrality->GetCentralityPercentile("V0M");
605 fCurrCentrality = -1;
609 //______________________________________________________________________________
610 void AliPIDResponse::ExecNewRun()
613 // Things to Execute upon a new run
617 SetITSParametrisation();
619 SetTPCPidResponseMaster();
620 SetTPCParametrisation();
622 SetTRDPidResponseMaster();
623 InitializeTRDResponse();
625 SetEMCALPidResponseMaster();
626 InitializeEMCALResponse();
628 SetTOFPidResponseMaster();
629 InitializeTOFResponse();
632 //_____________________________________________________
633 Double_t AliPIDResponse::GetTPCMultiplicityBin(const AliVEvent * const event)
636 // Get TPC multiplicity in bins of 150
639 const AliVVertex* vertexTPC = event->GetPrimaryVertex();
640 Double_t tpcMulti=0.;
642 Double_t vertexContribTPC=vertexTPC->GetNContributors();
643 tpcMulti=vertexContribTPC/150.;
644 if (tpcMulti>20.) tpcMulti=20.;
650 //______________________________________________________________________________
651 void AliPIDResponse::SetRecoInfo()
654 // Set reconstruction information
666 TPRegexp reg(".*(LHC1[1-2][a-z]+[0-9]+[a-z_]*)/.*");
668 //find the period by run number (UGLY, but not stored in ESD and AOD... )
669 if (fRun>=114737&&fRun<=117223) { fLHCperiod="LHC10B"; fMCperiodTPC="LHC10D1"; }
670 else if (fRun>=118503&&fRun<=121040) { fLHCperiod="LHC10C"; fMCperiodTPC="LHC10D1"; }
671 else if (fRun>=122195&&fRun<=126437) { fLHCperiod="LHC10D"; fMCperiodTPC="LHC10F6A"; }
672 else if (fRun>=127710&&fRun<=130850) { fLHCperiod="LHC10E"; fMCperiodTPC="LHC10F6A"; }
673 else if (fRun>=133004&&fRun<=135029) { fLHCperiod="LHC10F"; fMCperiodTPC="LHC10F6A"; }
674 else if (fRun>=135654&&fRun<=136377) { fLHCperiod="LHC10G"; fMCperiodTPC="LHC10F6A"; }
675 else if (fRun>=136851&&fRun<=139517) {
677 fMCperiodTPC="LHC10H8";
678 if (reg.MatchB(fCurrentFile)) fMCperiodTPC="LHC11A10";
681 else if (fRun>=139699&&fRun<=146860) { fLHCperiod="LHC11A"; fMCperiodTPC="LHC10F6A"; }
682 //TODO: periods 11B, 11C are not yet treated assume 11d for the moment
683 else if (fRun>=148531&&fRun<=155384) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
684 else if (fRun>=156477&&fRun<=159635) { fLHCperiod="LHC11D"; fMCperiodTPC="LHC10F6A"; }
685 else if (fRun>=166529) {
687 fMCperiodTPC="LHC11A10";
692 //exception new pp MC productions from 2011
693 if (fBeamType=="PP" && reg.MatchB(fCurrentFile)) fMCperiodTPC="LHC11B2";
694 // exception for 11f1
695 if (fCurrentFile.Contains("LHC11f1/")) fMCperiodTPC="LHC11F1";
698 //______________________________________________________________________________
699 void AliPIDResponse::SetITSParametrisation()
702 // Set the ITS parametrisation
706 //______________________________________________________________________________
707 void AliPIDResponse::SetTPCPidResponseMaster()
710 // Load the TPC pid response functions from the OADB
712 //don't load twice for the moment
713 if (fArrPidResponseMaster) return;
716 //reset the PID response functions
717 delete fArrPidResponseMaster;
718 fArrPidResponseMaster=0x0;
720 TString fileName(Form("%s/COMMON/PID/data/TPCPIDResponse.root", fOADBPath.Data()));
722 TFile *f=TFile::Open(fileName.Data());
723 if (f && f->IsOpen() && !f->IsZombie()){
724 fArrPidResponseMaster=dynamic_cast<TObjArray*>(f->Get("TPCPIDResponse"));
728 if (!fArrPidResponseMaster){
729 AliFatal(Form("Could not retrieve the TPC pid response from: %s",fileName.Data()));
732 fArrPidResponseMaster->SetOwner();
735 //______________________________________________________________________________
736 void AliPIDResponse::SetTPCParametrisation()
739 // Change BB parametrisation for current run
742 if (fLHCperiod.IsNull()) {
743 AliFatal("No period set, not changing parametrisation");
748 // Set default parametrisations for data and MC
752 TString datatype="DATA";
753 //in case of mc fRecoPass is per default 1
762 for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
763 fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,0x0);
767 TString period=fLHCperiod;
768 if (fIsMC) period=fMCperiodTPC;
770 AliInfo(Form("Searching splines for: %s %s PASS%d %s",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
773 //set the new PID splines
775 if (fArrPidResponseMaster){
777 //for MC don't use period information
778 // if (fIsMC) period="[A-Z0-9]*";
779 //for MC use MC period information
780 //pattern for the default entry (valid for all particles)
781 TPRegexp reg(Form("TSPLINE3_%s_([A-Z]*)_%s_PASS%d_%s_MEAN",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
783 //loop over entries and filter them
784 for (Int_t iresp=0; iresp<fArrPidResponseMaster->GetEntriesFast();++iresp){
785 TObject *responseFunction=fArrPidResponseMaster->At(iresp);
786 if (responseFunction==0x0) continue;
787 TString responseName=responseFunction->GetName();
789 if (!reg.MatchB(responseName)) continue;
791 TObjArray *arr=reg.MatchS(responseName);
792 TString particleName=arr->At(1)->GetName();
794 if (particleName.IsNull()) continue;
795 if (particleName=="ALL") grAll=responseFunction;
798 for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
799 TString particle=AliPID::ParticleName(ispec);
801 if ( particle == particleName ){
802 fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,responseFunction);
803 fTPCResponse.SetUseDatabase(kTRUE);
804 AliInfo(Form("Adding graph: %d - %s",ispec,responseFunction->GetName()));
812 //set default response function to all particles which don't have a specific one
814 for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
815 if (!fTPCResponse.GetResponseFunction((AliPID::EParticleType)ispec)){
816 fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,grAll);
817 AliInfo(Form("Adding graph: %d - %s",ispec,grAll->GetName()));
825 AliError(Form("No splines found for: %s %s PASS%d %s",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
828 // Setup resolution parametrisation
832 fTPCResponse.SetSigma(3.79301e-03, 2.21280e+04);
835 fTPCResponse.SetSigma(2.30176e-02, 5.60422e+02);
837 if (fArrPidResponseMaster)
838 fResolutionCorrection=(TF1*)fArrPidResponseMaster->FindObject(Form("TF1_%s_ALL_%s_PASS%d_%s_SIGMA",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
840 if (fResolutionCorrection) AliInfo(Form("Setting multiplicity correction function: %s",fResolutionCorrection->GetName()));
843 //______________________________________________________________________________
844 void AliPIDResponse::SetTRDPidResponseMaster()
847 // Load the TRD pid params and references from the OADB
849 if(fTRDPIDParams) return;
850 AliOADBContainer contParams("contParams");
852 Int_t statusPars = contParams.InitFromFile(Form("%s/COMMON/PID/data/TRDPIDParams.root", fOADBPath.Data()), "AliTRDPIDParams");
854 AliError("Failed initializing PID Params from OADB");
856 AliInfo(Form("Loading TRD Params from %s/COMMON/PID/data/TRDPIDParams.root", fOADBPath.Data()));
857 fTRDPIDParams = dynamic_cast<AliTRDPIDParams *>(contParams.GetObject(fRun));
859 AliError(Form("TRD Params not found in run %d", fRun));
863 AliOADBContainer contRefs("contRefs");
864 Int_t statusRefs = contRefs.InitFromFile(Form("%s/COMMON/PID/data/TRDPIDReferenceLQ1D.root", fOADBPath.Data()), "AliTRDPIDReference");
866 AliInfo("Failed Loading References for TRD");
868 AliInfo(Form("Loading TRD References from %s/COMMON/PID/data/TRDPIDReferenceLQ1D.root", fOADBPath.Data()));
869 fTRDPIDReference = dynamic_cast<AliTRDPIDReference *>(contRefs.GetObject(fRun));
870 if(!fTRDPIDReference){
871 AliError(Form("TRD References not found in OADB Container for run %d", fRun));
876 //______________________________________________________________________________
877 void AliPIDResponse::InitializeTRDResponse(){
879 // Set PID Params and references to the TRD PID response
881 fTRDResponse.SetPIDParams(fTRDPIDParams);
882 fTRDResponse.Load(fTRDPIDReference);
883 if(fLHCperiod == "LHC10b" || fLHCperiod == "LHC10c" || fLHCperiod == "LHC10d" || fLHCperiod == "LHC10e"){
884 fTRDslicesForPID[0] = 0;
885 fTRDslicesForPID[1] = 7;
889 //______________________________________________________________________________
890 void AliPIDResponse::SetTOFPidResponseMaster()
893 // Load the TOF pid params from the OADB
895 TFile *oadbf = new TFile(Form("%s/COMMON/PID/data/TOFPIDParams.root",fOADBPath.Data()));
896 if (oadbf->IsOpen()) {
897 AliInfo(Form("Loading TOF Params from %s/COMMON/PID/data/TOFPIDParams.root", fOADBPath.Data()));
898 AliOADBContainer *oadbc = (AliOADBContainer *)oadbf->Get("TOFoadb");
899 if (fTOFPIDParams) delete fTOFPIDParams;
900 fTOFPIDParams = dynamic_cast<AliTOFPIDParams *>(oadbc->GetObject(fRun,"TOFparams"));
904 AliError(Form("TOFPIDParams.root not found in %s/COMMON/PID/data !!",fOADBPath.Data()));
910 //______________________________________________________________________________
911 void AliPIDResponse::InitializeTOFResponse(){
913 // Set PID Params to the TOF PID response
915 for (Int_t i=0;i<4;i++) {
916 fTOFResponse.SetTrackParameter(i,fTOFPIDParams->GetSigParams(i));
918 fTOFResponse.SetTimeResolution(fTOFPIDParams->GetTOFresolution());
923 //_________________________________________________________________________
924 Bool_t AliPIDResponse::IdentifiedAsElectronTRD(const AliVTrack *vtrack, Double_t efficiencyLevel) const {
926 // Check whether track is identified as electron under a given electron efficiency hypothesis
928 Double_t probs[AliPID::kSPECIES];
929 ComputeTRDProbability(vtrack, AliPID::kSPECIES, probs);
931 Int_t ntracklets = vtrack->GetTRDntrackletsPID();
932 // Take mean of the TRD momenta in the given tracklets
933 Float_t p = 0, trdmomenta[AliVTrack::kTRDnPlanes];
935 for(Int_t iPl=0;iPl<AliVTrack::kTRDnPlanes;iPl++){
936 if(vtrack->GetTRDmomentum(iPl) > 0.){
937 trdmomenta[nmomenta++] = vtrack->GetTRDmomentum(iPl);
940 p = TMath::Mean(nmomenta, trdmomenta);
942 return fTRDResponse.IdentifiedAsElectron(ntracklets, probs, p, efficiencyLevel);
945 //______________________________________________________________________________
946 void AliPIDResponse::SetEMCALPidResponseMaster()
949 // Load the EMCAL pid response functions from the OADB
951 TObjArray* fEMCALPIDParamsRun = NULL;
952 TObjArray* fEMCALPIDParamsPass = NULL;
954 if(fEMCALPIDParams) return;
955 AliOADBContainer contParams("contParams");
957 Int_t statusPars = contParams.InitFromFile(Form("%s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()), "AliEMCALPIDParams");
959 AliError("Failed initializing PID Params from OADB");
962 AliInfo(Form("Loading EMCAL Params from %s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()));
964 fEMCALPIDParamsRun = dynamic_cast<TObjArray *>(contParams.GetObject(fRun));
965 if(fEMCALPIDParamsRun) fEMCALPIDParamsPass = dynamic_cast<TObjArray *>(fEMCALPIDParamsRun->FindObject(Form("pass%d",fRecoPass)));
966 if(fEMCALPIDParamsPass) fEMCALPIDParams = dynamic_cast<TObjArray *>(fEMCALPIDParamsPass->FindObject(Form("EMCALPIDParams_Particles")));
968 if(!fEMCALPIDParams){
969 AliInfo(Form("EMCAL Params not found in run %d pass %d", fRun, fRecoPass));
970 AliInfo("Will take the standard LHC11d instead ...");
972 fEMCALPIDParamsRun = dynamic_cast<TObjArray *>(contParams.GetObject(156477));
973 if(fEMCALPIDParamsRun) fEMCALPIDParamsPass = dynamic_cast<TObjArray *>(fEMCALPIDParamsRun->FindObject(Form("pass%d",1)));
974 if(fEMCALPIDParamsPass) fEMCALPIDParams = dynamic_cast<TObjArray *>(fEMCALPIDParamsPass->FindObject(Form("EMCALPIDParams_Particles")));
976 if(!fEMCALPIDParams){
977 AliError(Form("DEFAULT EMCAL Params (LHC11d) not found in file %s/COMMON/PID/data/EMCALPIDParams.root", fOADBPath.Data()));
983 //______________________________________________________________________________
984 void AliPIDResponse::InitializeEMCALResponse(){
986 // Set PID Params to the EMCAL PID response
988 fEMCALResponse.SetPIDParams(fEMCALPIDParams);
991 //_________________________________________________________________________
992 void AliPIDResponse::SetTOFResponse(AliVEvent *vevent,EStartTimeType_t option){
994 // Set TOF response function
995 // Input option for event_time used
998 Float_t t0spread = 0.; //vevent->GetEventTimeSpread();
999 if(t0spread < 10) t0spread = 80;
1001 // T0 from TOF algorithm
1003 Bool_t flagT0TOF=kFALSE;
1004 Bool_t flagT0T0=kFALSE;
1005 Float_t *startTime = new Float_t[fTOFResponse.GetNmomBins()];
1006 Float_t *startTimeRes = new Float_t[fTOFResponse.GetNmomBins()];
1007 Int_t *startTimeMask = new Int_t[fTOFResponse.GetNmomBins()];
1010 Float_t *estimatedT0event = new Float_t[fTOFResponse.GetNmomBins()];
1011 Float_t *estimatedT0resolution = new Float_t[fTOFResponse.GetNmomBins()];
1012 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1013 estimatedT0event[i]=0.0;
1014 estimatedT0resolution[i]=0.0;
1015 startTimeMask[i] = 0;
1018 Float_t resT0A=75,resT0C=65,resT0AC=55;
1019 if(vevent->GetT0TOF()){ // check if T0 detector information is available
1024 AliTOFHeader *tofHeader = (AliTOFHeader*)vevent->GetTOFHeader();
1026 if (tofHeader) { // read global info and T0-TOF
1027 fTOFResponse.SetTimeResolution(tofHeader->GetTOFResolution());
1028 t0spread = tofHeader->GetT0spread(); // read t0 sprad
1029 if(t0spread < 10) t0spread = 80;
1032 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){ // read T0-TOF default value
1033 startTime[i]=tofHeader->GetDefaultEventTimeVal();
1034 startTimeRes[i]=tofHeader->GetDefaultEventTimeRes();
1035 if(startTimeRes[i] < 1.e-5) startTimeRes[i] = t0spread;
1038 TArrayI *ibin=(TArrayI*)tofHeader->GetNvalues();
1039 TArrayF *t0Bin=(TArrayF*)tofHeader->GetEventTimeValues();
1040 TArrayF *t0ResBin=(TArrayF*)tofHeader->GetEventTimeRes();
1041 for(Int_t j=0;j < tofHeader->GetNbins();j++){ // fill T0-TOF in p-bins
1042 Int_t icurrent = (Int_t)ibin->GetAt(j);
1043 startTime[icurrent]=t0Bin->GetAt(j);
1044 startTimeRes[icurrent]=t0ResBin->GetAt(j);
1045 if(startTimeRes[icurrent] < 1.e-5) startTimeRes[icurrent] = t0spread;
1049 // for cut of 3 sigma on t0 spread
1050 Float_t t0cut = 3 * t0spread;
1051 if(t0cut < 500) t0cut = 500;
1053 if(option == kFILL_T0){ // T0-FILL is used
1054 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1055 estimatedT0event[i]=0.0;
1056 estimatedT0resolution[i]=t0spread;
1058 fTOFResponse.SetT0event(estimatedT0event);
1059 fTOFResponse.SetT0resolution(estimatedT0resolution);
1062 if(option == kTOF_T0){ // T0-TOF is used when available (T0-FILL otherwise) from ESD
1064 fTOFResponse.SetT0event(startTime);
1065 fTOFResponse.SetT0resolution(startTimeRes);
1066 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1067 if(startTimeRes[i]<t0spread) startTimeMask[i]=1;
1068 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1072 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1073 estimatedT0event[i]=0.0;
1074 estimatedT0resolution[i]=t0spread;
1075 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1077 fTOFResponse.SetT0event(estimatedT0event);
1078 fTOFResponse.SetT0resolution(estimatedT0resolution);
1081 else if(option == kBest_T0){ // T0-T0 or T0-TOF are used when available (T0-FILL otherwise) from ESD
1082 Float_t t0AC=-10000;
1086 t0AC= vevent->GetT0TOF()[0];
1087 t0A= vevent->GetT0TOF()[1];
1088 t0C= vevent->GetT0TOF()[2];
1091 Float_t t0t0Best = 0;
1092 Float_t t0t0BestRes = 9999;
1094 if(TMath::Abs(t0A) < t0cut && TMath::Abs(t0C) < t0cut && TMath::Abs(t0C-t0A) < 500){
1096 t0t0BestRes = resT0AC;
1099 else if(TMath::Abs(t0C) < t0cut){
1101 t0t0BestRes = resT0C;
1104 else if(TMath::Abs(t0A) < t0cut){
1106 t0t0BestRes = resT0A;
1110 if(flagT0TOF){ // if T0-TOF info is available
1111 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1112 if(t0t0BestRes < 999){
1113 if(startTimeRes[i] < t0spread){
1114 Double_t wtot = 1./startTimeRes[i]/startTimeRes[i] + 1./t0t0BestRes/t0t0BestRes;
1115 Double_t t0best = startTime[i]/startTimeRes[i]/startTimeRes[i] + t0t0Best/t0t0BestRes/t0t0BestRes;
1116 estimatedT0event[i]=t0best / wtot;
1117 estimatedT0resolution[i]=1./TMath::Sqrt(wtot);
1118 startTimeMask[i] = t0used+1;
1121 estimatedT0event[i]=t0t0Best;
1122 estimatedT0resolution[i]=t0t0BestRes;
1123 startTimeMask[i] = t0used;
1127 estimatedT0event[i]=startTime[i];
1128 estimatedT0resolution[i]=startTimeRes[i];
1129 if(startTimeRes[i]<t0spread) startTimeMask[i]=1;
1131 fTOFResponse.SetT0binMask(i,startTimeMask[i]);
1133 fTOFResponse.SetT0event(estimatedT0event);
1134 fTOFResponse.SetT0resolution(estimatedT0resolution);
1136 else{ // if no T0-TOF info is available
1137 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1138 fTOFResponse.SetT0binMask(i,t0used);
1139 if(t0t0BestRes < 999){
1140 estimatedT0event[i]=t0t0Best;
1141 estimatedT0resolution[i]=t0t0BestRes;
1144 estimatedT0event[i]=0.0;
1145 estimatedT0resolution[i]=t0spread;
1148 fTOFResponse.SetT0event(estimatedT0event);
1149 fTOFResponse.SetT0resolution(estimatedT0resolution);
1153 else if(option == kT0_T0){ // T0-T0 is used when available (T0-FILL otherwise)
1154 Float_t t0AC=-10000;
1158 t0AC= vevent->GetT0TOF()[0];
1159 t0A= vevent->GetT0TOF()[1];
1160 t0C= vevent->GetT0TOF()[2];
1163 if(TMath::Abs(t0A) < t0cut && TMath::Abs(t0C) < t0cut && TMath::Abs(t0C-t0A) < 500){
1164 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1165 estimatedT0event[i]=t0AC;
1166 estimatedT0resolution[i]=resT0AC;
1167 fTOFResponse.SetT0binMask(i,6);
1170 else if(TMath::Abs(t0C) < t0cut){
1171 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1172 estimatedT0event[i]=t0C;
1173 estimatedT0resolution[i]=resT0C;
1174 fTOFResponse.SetT0binMask(i,4);
1177 else if(TMath::Abs(t0A) < t0cut){
1178 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1179 estimatedT0event[i]=t0A;
1180 estimatedT0resolution[i]=resT0A;
1181 fTOFResponse.SetT0binMask(i,2);
1185 for(Int_t i=0;i<fTOFResponse.GetNmomBins();i++){
1186 estimatedT0event[i]=0.0;
1187 estimatedT0resolution[i]=t0spread;
1188 fTOFResponse.SetT0binMask(i,0);
1191 fTOFResponse.SetT0event(estimatedT0event);
1192 fTOFResponse.SetT0resolution(estimatedT0resolution);
1194 delete [] startTime;
1195 delete [] startTimeRes;
1196 delete [] startTimeMask;
1197 delete [] estimatedT0event;
1198 delete [] estimatedT0resolution;