ROOT logo
/*
-----------------------------------------------------------------------------------
 AliFlowBayesianPID class implemented by F. Noferini (noferini@bo.infn.it)
 needed to use Bayesian probability in the flow package (used in AliFlowTrackCuts)
-----------------------------------------------------------------------------------
*/
#ifndef ALIFLOWBAYESIANPID_H
#define ALIFLOWBAYESIANPID_H

#include "AliESDpid.h"
#include "AliPIDResponse.h"

class TObject;
class TDatabasePDG;
class AliESDEvent;
class AliESDtrack;
class AliAODEvent;
class AliAODTrack;
class TH2D;
class TSpline3;
class TF1;
class TH1D;

/*
HOW TO

1) in your main program:

  AliFlowBayesianPID *mypid = new AliFlowBayesianPID();

or (if you want a global AliESDpid object)

  AliESDpid *PIDesd = new AliESDpid();
  ....
  AliFlowBayesianPID *mypid = new AliFlowBayesianPID(PIDesd);

for data starting from the PbPb pass2 reconstruction

  mypid->SetNewTrackParam();


before to loop on the on ESD tracks 
 mypid->SetDetResponse(esdEvent, centrality,AliESDpid::kTOF_T0,kFALSE); // centrality > 0 = PbPb or -1 for pp collisions

before to loop on the on AOD tracks 
 mypid->SetDetResponse(aodEvent, centrality); // centrality > 0 = PbPb or -1 for pp collisions

if you want to use a dE/dx depdence on DeltaPhi set the EP with its resolution otherwise it will be skipped
 mypid->SetPsiCorrectionDeDx(psiEP,resEP);


     for(...){ // track loop
       mypid->ComputeProb(track,centrality); // both for ESD and AOD tracks
       Float_t *prob = mypid->GetProb(); // Bayesian Probability (from 0 to 4) (Combined TPC || TOF) including a tuning of priors and TOF mismatch parameterization
     }


More details:
     // for the single detector weights (no priors)
     Float_t *tpcWeight = mypid->GetWeights(0); // TPC weights (equal weights in case of no kTPCpid)
     Float_t *tofWeight = mypid->GetWeights(1); // TOF weights (equal weights in case of no kTOFpid)

     // more tools
     TSpline3 *mismatchShape = mypid->GetMismatch(); // time distribution of mismatched tracks - L/c (L is the distance of the pad from the PV)
     TF1 *tpcprob = mypid->GetTPCprob(); // normalized TPC response function (in Nsigmas)  
     TF1 *tofprob = mypid->GetTOFprob(); // normalized TOF response function (in Nsigmas)  

     TH2D *hPr = mypid->GetHistoPriors(isp); // 2D (centrality - pT) histo for the priors of specie-isp (centrality < 0 means pp collisions)
                                             // all the priors are normalized to the pion ones

*/

class AliFlowBayesianPID : public AliPIDResponse{
 public:
  AliFlowBayesianPID(AliESDpid *esdpid=NULL); 
  virtual ~AliFlowBayesianPID();
  
  // virtual method of AliPIDResponse


  // setter
  void SetDetResponse(AliESDEvent *esd,Float_t centrality=-1.0,EStartTimeType_t flagStart=AliESDpid::kTOF_T0,Bool_t /*recomputeT0TOF*/=kFALSE);
  void SetDetResponse(AliAODEvent *aod,Float_t centrality=-1.0,EStartTimeType_t flagStart=AliESDpid::kTOF_T0);
  void SetNewTrackParam(Bool_t flag=kTRUE){fNewTrackParam=flag;};
  void SetDetAND(Int_t idet){if(idet < fgkNdetectors && idet >= 0) fMaskAND[idet] = kTRUE;};
  void SetDetOR(Int_t idet){if(idet < fgkNdetectors && idet >= 0) fMaskOR[idet] = kTRUE;};
  void ResetDetAND(Int_t idet){if(idet < fgkNdetectors && idet >= 0) fMaskAND[idet] = kFALSE;};
  void ResetDetOR(Int_t idet){if(idet < fgkNdetectors && idet >= 0) fMaskOR[idet] = kFALSE;};
  void SetPsiCorrectionDeDx(Float_t psi,Float_t res);
  void SetMC(Bool_t flag){fIsMC=flag;};

  // getter
  AliESDpid* GetESDpid(){return fPIDesd;};
  const TH2D *GetHistoPriors(Int_t specie) const {if(specie >=0 && specie < fgkNspecies) return fghPriors[specie]; else return NULL;};
  TSpline3 *GetMismatch();  
  const TF1 *GetTOFprob() const {return fTOFResponseF;};
  const TF1 *GetTPCprob() const {return fTPCResponseF;};
  const Float_t *GetWeights(Int_t det) const {if(det < fgkNdetectors && det >= 0){return fWeights[det];} else{return NULL;}};
  Float_t *GetProb() {return fProb;};
  Float_t GetTOFMismWeight() const {return fWTofMism;};
  Float_t GetTOFMismProb() const {return fProbTofMism;};
  Float_t GetMassOverZ() const {return fMassTOF;};
  Float_t GetZ() const {return fZ;};
  Bool_t GetDetANDstatus(Int_t idet) const {if(idet < fgkNdetectors && idet >= 0){return fMaskAND[idet];} else{return kFALSE;} };
  Bool_t GetDetORstatus(Int_t idet) const {if(idet < fgkNdetectors && idet >= 0){return fMaskOR[idet];} else{return kFALSE;} };
  Bool_t GetCurrentMask(Int_t idet) const {if(idet < fgkNdetectors && idet >= 0){return fMaskCurrent[idet];} else{return kFALSE;} };

  Float_t GetExpDeDx(const AliVTrack *t,Int_t iS) const;
  Float_t GetExpDeDx(const AliVTrack *t,Float_t m) const;

  // methods for Bayesina Combined PID
  void ComputeWeights(const AliESDtrack *t);
  void ComputeProb(const AliESDtrack *t,Float_t); // obsolete method
  void ComputeProb(const AliESDtrack *t){ComputeProb(t,0.0);}; 
  void ComputeWeights(const AliAODTrack *t,const AliAODEvent *aod=NULL);
  void ComputeProb(const AliAODTrack *t,const AliAODEvent *aod=NULL); // obsolete method

  void SetTOFres(Float_t res){fTOFresolution=res;};

  Float_t GetDeDx() const {return fDedx;};

  void ForceOldDedx(Bool_t status=kTRUE) {fForceOldDedx=status;};

 private: 
  void SetPriors();

  static const Int_t fgkNdetectors = 2; // Number of detector used for PID
  static const Int_t fgkNspecies = 9;// 0=el, 1=mu, 2=pi, 3=ka, 4=pr, 5=deuteron, 6=triton, 7=He3 
  static TH2D* fghPriors[fgkNspecies]; // histo with priors (hardcoded)
  static TSpline3 *fgMism; // function for mismatch

  AliESDpid *fPIDesd;//ESDpid object
  TDatabasePDG *fDB; // Database pdg
  Double_t fMass[fgkNspecies]; // mass for el(0),mu(1),pi(2),K(3),p(4)

  Bool_t fNewTrackParam; // switch for new tracking resolution TOF parameterization
  Float_t fTOFresolution; // TOF res needed only if T0-TOF should be recomputed

  AliFlowBayesianPID(const AliFlowBayesianPID&); // not implemented
  AliFlowBayesianPID& operator=(const AliFlowBayesianPID&); // not implemented 

  TF1 *fTOFResponseF; // TOF Gaussian+tail response function (tail at 1.1 sigma)
  TF1 *fTPCResponseF; // TPC Gaussian+tail response function (tail at 1.8 sigma)

  Float_t fWeights[fgkNdetectors][fgkNspecies]; // weights: 0=tpc,1=tof
  Float_t fProb[fgkNspecies],fWTofMism,fProbTofMism; // Bayesian Combined PID + mismatch weights and probability 

  Float_t fZ,fMassTOF; //measured charge(Z) and mass/Z
  TF1 *fBBdata; // Bethe Bloch function (needed to compute the charge of the particle)

  Bool_t fMaskAND[fgkNdetectors],fMaskOR[fgkNdetectors],fMaskCurrent[fgkNdetectors]; // mask detector should be used

  Float_t fCurrCentrality; // Centrality in current event

  Float_t fPsi,fPsiRes;    // RP and its resolution for the event (999 if not available) to correct dEdx for p > 1

  Bool_t fIsMC; // switch for MC analysis

  Bool_t fForceOldDedx;    // switch to force to use old 2010 dEdx paramterization (even if PIDResponse is available)

  Float_t fDedx; // dE/dx tuned for MC

  Bool_t fIsTOFheaderAOD; // check the TOF header in AOD

  static TH1D *fgHtofChannelDist; // channel distance from IP

  ClassDef(AliFlowBayesianPID, 10); // example of analysis
};

#endif



 AliFlowBayesianPID.h:1
 AliFlowBayesianPID.h:2
 AliFlowBayesianPID.h:3
 AliFlowBayesianPID.h:4
 AliFlowBayesianPID.h:5
 AliFlowBayesianPID.h:6
 AliFlowBayesianPID.h:7
 AliFlowBayesianPID.h:8
 AliFlowBayesianPID.h:9
 AliFlowBayesianPID.h:10
 AliFlowBayesianPID.h:11
 AliFlowBayesianPID.h:12
 AliFlowBayesianPID.h:13
 AliFlowBayesianPID.h:14
 AliFlowBayesianPID.h:15
 AliFlowBayesianPID.h:16
 AliFlowBayesianPID.h:17
 AliFlowBayesianPID.h:18
 AliFlowBayesianPID.h:19
 AliFlowBayesianPID.h:20
 AliFlowBayesianPID.h:21
 AliFlowBayesianPID.h:22
 AliFlowBayesianPID.h:23
 AliFlowBayesianPID.h:24
 AliFlowBayesianPID.h:25
 AliFlowBayesianPID.h:26
 AliFlowBayesianPID.h:27
 AliFlowBayesianPID.h:28
 AliFlowBayesianPID.h:29
 AliFlowBayesianPID.h:30
 AliFlowBayesianPID.h:31
 AliFlowBayesianPID.h:32
 AliFlowBayesianPID.h:33
 AliFlowBayesianPID.h:34
 AliFlowBayesianPID.h:35
 AliFlowBayesianPID.h:36
 AliFlowBayesianPID.h:37
 AliFlowBayesianPID.h:38
 AliFlowBayesianPID.h:39
 AliFlowBayesianPID.h:40
 AliFlowBayesianPID.h:41
 AliFlowBayesianPID.h:42
 AliFlowBayesianPID.h:43
 AliFlowBayesianPID.h:44
 AliFlowBayesianPID.h:45
 AliFlowBayesianPID.h:46
 AliFlowBayesianPID.h:47
 AliFlowBayesianPID.h:48
 AliFlowBayesianPID.h:49
 AliFlowBayesianPID.h:50
 AliFlowBayesianPID.h:51
 AliFlowBayesianPID.h:52
 AliFlowBayesianPID.h:53
 AliFlowBayesianPID.h:54
 AliFlowBayesianPID.h:55
 AliFlowBayesianPID.h:56
 AliFlowBayesianPID.h:57
 AliFlowBayesianPID.h:58
 AliFlowBayesianPID.h:59
 AliFlowBayesianPID.h:60
 AliFlowBayesianPID.h:61
 AliFlowBayesianPID.h:62
 AliFlowBayesianPID.h:63
 AliFlowBayesianPID.h:64
 AliFlowBayesianPID.h:65
 AliFlowBayesianPID.h:66
 AliFlowBayesianPID.h:67
 AliFlowBayesianPID.h:68
 AliFlowBayesianPID.h:69
 AliFlowBayesianPID.h:70
 AliFlowBayesianPID.h:71
 AliFlowBayesianPID.h:72
 AliFlowBayesianPID.h:73
 AliFlowBayesianPID.h:74
 AliFlowBayesianPID.h:75
 AliFlowBayesianPID.h:76
 AliFlowBayesianPID.h:77
 AliFlowBayesianPID.h:78
 AliFlowBayesianPID.h:79
 AliFlowBayesianPID.h:80
 AliFlowBayesianPID.h:81
 AliFlowBayesianPID.h:82
 AliFlowBayesianPID.h:83
 AliFlowBayesianPID.h:84
 AliFlowBayesianPID.h:85
 AliFlowBayesianPID.h:86
 AliFlowBayesianPID.h:87
 AliFlowBayesianPID.h:88
 AliFlowBayesianPID.h:89
 AliFlowBayesianPID.h:90
 AliFlowBayesianPID.h:91
 AliFlowBayesianPID.h:92
 AliFlowBayesianPID.h:93
 AliFlowBayesianPID.h:94
 AliFlowBayesianPID.h:95
 AliFlowBayesianPID.h:96
 AliFlowBayesianPID.h:97
 AliFlowBayesianPID.h:98
 AliFlowBayesianPID.h:99
 AliFlowBayesianPID.h:100
 AliFlowBayesianPID.h:101
 AliFlowBayesianPID.h:102
 AliFlowBayesianPID.h:103
 AliFlowBayesianPID.h:104
 AliFlowBayesianPID.h:105
 AliFlowBayesianPID.h:106
 AliFlowBayesianPID.h:107
 AliFlowBayesianPID.h:108
 AliFlowBayesianPID.h:109
 AliFlowBayesianPID.h:110
 AliFlowBayesianPID.h:111
 AliFlowBayesianPID.h:112
 AliFlowBayesianPID.h:113
 AliFlowBayesianPID.h:114
 AliFlowBayesianPID.h:115
 AliFlowBayesianPID.h:116
 AliFlowBayesianPID.h:117
 AliFlowBayesianPID.h:118
 AliFlowBayesianPID.h:119
 AliFlowBayesianPID.h:120
 AliFlowBayesianPID.h:121
 AliFlowBayesianPID.h:122
 AliFlowBayesianPID.h:123
 AliFlowBayesianPID.h:124
 AliFlowBayesianPID.h:125
 AliFlowBayesianPID.h:126
 AliFlowBayesianPID.h:127
 AliFlowBayesianPID.h:128
 AliFlowBayesianPID.h:129
 AliFlowBayesianPID.h:130
 AliFlowBayesianPID.h:131
 AliFlowBayesianPID.h:132
 AliFlowBayesianPID.h:133
 AliFlowBayesianPID.h:134
 AliFlowBayesianPID.h:135
 AliFlowBayesianPID.h:136
 AliFlowBayesianPID.h:137
 AliFlowBayesianPID.h:138
 AliFlowBayesianPID.h:139
 AliFlowBayesianPID.h:140
 AliFlowBayesianPID.h:141
 AliFlowBayesianPID.h:142
 AliFlowBayesianPID.h:143
 AliFlowBayesianPID.h:144
 AliFlowBayesianPID.h:145
 AliFlowBayesianPID.h:146
 AliFlowBayesianPID.h:147
 AliFlowBayesianPID.h:148
 AliFlowBayesianPID.h:149
 AliFlowBayesianPID.h:150
 AliFlowBayesianPID.h:151
 AliFlowBayesianPID.h:152
 AliFlowBayesianPID.h:153
 AliFlowBayesianPID.h:154
 AliFlowBayesianPID.h:155
 AliFlowBayesianPID.h:156
 AliFlowBayesianPID.h:157
 AliFlowBayesianPID.h:158
 AliFlowBayesianPID.h:159
 AliFlowBayesianPID.h:160
 AliFlowBayesianPID.h:161
 AliFlowBayesianPID.h:162
 AliFlowBayesianPID.h:163
 AliFlowBayesianPID.h:164
 AliFlowBayesianPID.h:165
 AliFlowBayesianPID.h:166
 AliFlowBayesianPID.h:167
 AliFlowBayesianPID.h:168
 AliFlowBayesianPID.h:169
 AliFlowBayesianPID.h:170
 AliFlowBayesianPID.h:171
 AliFlowBayesianPID.h:172
 AliFlowBayesianPID.h:173