]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG2/FLOW/AliFlowTrack.cxx
Adding comments (Laurent)
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowTrack.cxx
index 3adf20d53abc45de90df4aaa8d28d1465636c60d..b07c630dd6677c2fedd813e5b228e9215dadc33a 100644 (file)
 // Description: 
 //         an array of AliFlowTrack is the core of the AliFlowEvent. 
 // The object AliFlowTrack contains data members wich summarize the track 
-// information most useful for flow study (such as Pt, eta, phi angle, 
-// p.id hypothesis, some detector informations like fitpoints, chi2, 
-// energy loss, t.o.f., ecc.). 
+// information most useful for flow study (such as Pt, eta, phi angle), some 
+// detector signals (fitpoints, chi2 of the track fit, energy loss, time of 
+// flight, ecc.), the p.id is stored as the detector response function, for 
+// each detector (with the possibility to costomly combine them), and the 
+// combined one (see bayesian P.Id. - chap.5 of the ALICE PPR). 
 // This class is optimized for reaction plane calculation and sub-event 
 // selection, through the appropriate methods in AliFlowEvent.  
 // Two arrays of flags in the AliFlowTrack object (fSelection[][] and 
 
 #include "AliFlowTrack.h"
 #include "AliFlowConstants.h"
+
+#include "TMath.h"
 #include <iostream>
 using namespace std; //required for resolving the 'cout' symbol
 
-ClassImp(AliFlowTrack) 
-//////////////////////////////////////////////////////////////////////////////
-AliFlowTrack::AliFlowTrack()
-{
+ClassImp(AliFlowTrack)
+//-------------------------------------------------------------
+AliFlowTrack::AliFlowTrack():
+fPhi(0.), fEta(0.), fPt(0.), fZFirstPoint(0.), fZLastPoint(0.), fChi2(0.), fTrackLength(0.), fMostLikelihoodPID(0), fPhiGlobal(0.), fEtaGlobal(0.), fPtGlobal(0.), fLabel(0) {
  // Default constructor
  
- fPhi = 0. ;
- fEta = 0. ;
- fPt  = 0. ;
- fPhiGlobal = 0. ;
- fEtaGlobal = 0. ;
- fPtGlobal  = 0. ;
- fChi2 = 0. ;
- fZFirstPoint = 0. ;                 
- fZLastPoint = 0. ;                          
- fTrackLength = 0. ;
- fMostLikelihoodPID = 0 ;                    
- for(Int_t ii=0;ii<2;ii++)         { fDcaSigned[ii] = 0 ; }                          
- for(Int_t ii=0;ii<AliFlowConstants::kPid;ii++) { fPidProb[ii] = 0. ; }
- for(Int_t ii=0;ii<4;ii++)
+ for(Int_t dd=0;dd<2;dd++)                     { fDcaSigned[dd] = 0. ; }                             
+ for(Int_t ii=0;ii<AliFlowConstants::kPid;ii++) { fCombRespFun[ii]   = 0. ; }
+ for(Int_t det=0;det<4;det++)
  {
-  fFitPts[4]  = 0  ; fMaxPts[4]  = 0  ; 
-  fFitChi2[4] = 0. ; fDedx[4]    = 0. ;
-  fMom[4] = 0. ;
+  fFitPts[det]  = 0  ; fMaxPts[det]   = 0  ; 
+  fFitChi2[det] = 0. ; fDedx[det]     = 0. ; fMom[det] = 0. ; 
+  for(Int_t ii=0;ii<AliFlowConstants::kPid;ii++) { fRespFun[det][ii] = -1. ; }
  }
  ResetSelection() ;                          
 }
-//////////////////////////////////////////////////////////////////////////////
-AliFlowTrack::AliFlowTrack(const Char_t* name) 
-{
+//-------------------------------------------------------------
+AliFlowTrack::AliFlowTrack(const Char_t* name):
+fPhi(0.), fEta(0.), fPt(0.), fZFirstPoint(0.), fZLastPoint(0.), fChi2(0.), fTrackLength(0.), fMostLikelihoodPID(0), fPhiGlobal(0.), fEtaGlobal(0.), fPtGlobal(0.), fLabel(0) {
  // TNamed constructor
   
  SetName(name) ;
  AliFlowTrack() ;
 }
-//////////////////////////////////////////////////////////////////////////////
+//-------------------------------------------------------------
 AliFlowTrack::~AliFlowTrack() 
 {
  // default destructor (dummy)
 }
-//////////////////////////////////////////////////////////////////////////////
+//-------------------------------------------------------------
 
-//////////////////////////////////////////////////////////////////////////////
+//-------------------------------------------------------------
 Float_t  AliFlowTrack::P() const 
 { 
- // Returns the total momentum of the constrained track (calculated from Pt & Eta),
- // if the track is not constrainable returns 0 (used as flag for contrainable tracks).
+ // Returns the total momentum of the constrained track (calculated from Pt & Eta).
+ // If the track is not constrainable or eta is infinite, returns 0.
  
- if(!IsConstrainable()) { return 0 ; }               
- Float_t momentum = Pt()/TMath::Sqrt(1-(TMath::TanH(Eta())*TMath::TanH(Eta()))); 
+ if(!IsConstrainable()) { return 0. ; }                      
+
+ Float_t momentum = 0. ; 
+ Float_t conv = 1 - ( TMath::TanH(Eta()) * TMath::TanH(Eta()) ) ;
+ if(conv>0) { momentum = Pt() / TMath::Sqrt(conv) ; } 
+
  return momentum; 
 }
-//////////////////////////////////////////////////////////////////////////////
-Float_t  AliFlowTrack::PGlobal()                   const 
+//-------------------------------------------------------------
+Float_t  AliFlowTrack::PGlobal() const 
 { 
- // Returns the total momentum of the unconstrained track (always>0). 
+ // Returns the total momentum of the unconstrained track (calculated from PtGlobal & EtaGlobal). 
+ // If etaGlobal is infinite, returns 0.
+
+ Float_t momentum = 0. ; 
+ Float_t conv = 1 - ( TMath::TanH(EtaGlobal()) * TMath::TanH(EtaGlobal()) ) ;
+ if(conv>0) { momentum = PtGlobal() / TMath::Sqrt(conv) ; }
 
- Float_t momentum = PtGlobal()/TMath::Sqrt(1-(TMath::TanH(EtaGlobal())*TMath::TanH(EtaGlobal()))); 
  return momentum; 
 }
-//////////////////////////////////////////////////////////////////////////////
+//-------------------------------------------------------------
 Float_t  AliFlowTrack::Mass() const 
 { 
  // Returns the mass of the track, basing on its P.Id. hypotesis
 
- Float_t M = 0.13957 ;  // pion mass 
+ Float_t mass = 0.13957 ;  // pion mass 
 
- if(MostLikelihoodPID() == 0)                        { M = -1.    ; }
- else if(TMath::Abs(MostLikelihoodPID()) == 11)              { M = 0.00051; }
- else if(TMath::Abs(MostLikelihoodPID()) == 13)              { M = 0.10566; }
- else if(TMath::Abs(MostLikelihoodPID()) == 211)      { M = 0.49368; }
- else if(TMath::Abs(MostLikelihoodPID()) == 321)      { M = 0.13957; }
- else if(TMath::Abs(MostLikelihoodPID()) == 2212)     { M = 0.93827; }
- else if(TMath::Abs(MostLikelihoodPID()) == 10010020) { M = 1.87505; }
+ if(MostLikelihoodPID() == 0)                        { mass = -1.    ; }
+ else if(TMath::Abs(MostLikelihoodPID()) == 11)              { mass = 0.00051; }
+ else if(TMath::Abs(MostLikelihoodPID()) == 13)              { mass = 0.10566; }
+ else if(TMath::Abs(MostLikelihoodPID()) == 211)      { mass = 0.49368; }
+ else if(TMath::Abs(MostLikelihoodPID()) == 321)      { mass = 0.13957; }
+ else if(TMath::Abs(MostLikelihoodPID()) == 2212)     { mass = 0.93827; }
+ else if(TMath::Abs(MostLikelihoodPID()) == 10010020) { mass = 1.87505; }
 
- return M ;
+ return mass ;
 }
-//////////////////////////////////////////////////////////////////////////////
+//-------------------------------------------------------------
 Float_t  AliFlowTrack::InvMass() const 
 { 
  // Returns the invariant mass of the track, calculated from T.O.F. and P_tot
 
- Float_t M = -1 ;                  // if no calculation possible, it returns -1
+ Float_t mass = -1 ;               // if no calculation possible, it returns -1
  Float_t c = TMath::Ccgs()/1e+12 ;  // = 0.02998 ;  --> speed of light in cm/psec
  Float_t tof = TofTOF() ;          // in pico-seconds
  Float_t lenght = TrackLength() ;   // in cm
- Float_t Ptot = 0 ;                // constrained parameters are used if there, otherwise unconstrained
- if(IsConstrainable()) { Ptot = P() ; }
- else                  { Ptot = PGlobal() ; }
+ Float_t ptot = 0 ;                // constrained parameters are used if there, otherwise unconstrained
+ Float_t beta, gamma ;
+ if(IsConstrainable()) { ptot = P() ; }
+ else                  { ptot = PGlobal() ; }
  if(tof>0 && lenght>0)
- { 
-  Float_t beta = lenght / (tof * c) ;
+ {
+  beta = lenght / (tof * c) ;
   if(beta<1) 
   {
-   Float_t gamma = 1/TMath::Sqrt(1-(beta*beta)) ;
-   M = TMath::Abs(Ptot/(beta*gamma)) ;  
-  } // cout << ii << ": Mass = " << cmass << " , t/l = " << (tof/lenght) << " , beta = " << beta << " , gamma = " << gamma << endl ; }
- }  // else { cout << ii << ": TOF = " << tof << "     , Lenght = " << lenght << endl ; }
+   gamma = 1 / TMath::Sqrt( 1 - (beta * beta) ) ;
+   mass = TMath::Abs( ptot / (beta * gamma) ) ;  
+  }
+  //cout << " (yes) Mass = " << mass << " , t/l = " << (tof/lenght) << " , beta = " << beta << " , gamma = " << gamma << endl ; 
+ }   
+ //else { cout << " (no)  TOF = " << tof << "  , Lenght = " << lenght << endl ; }
 
- return M ;
+ return mass ;
 }
-//////////////////////////////////////////////////////////////////////////////
+//-------------------------------------------------------------
 Float_t  AliFlowTrack::Y() const 
 {
  // Rapidity of the constrained track.
@@ -145,15 +149,15 @@ Float_t  AliFlowTrack::Y() const
  if(TMath::Abs((Float_t)P()) == TMath::Abs((Float_t)Pt()))     { return 0. ; }
  else if(TMath::Abs((Float_t)P()) < TMath::Abs((Float_t)Pt())) { cout << "track: " << GetName() << "has  Pt() > P() !!!" << endl ; }
  // -
float M = Mass() ; 
double Pz = TMath::Sqrt(P()*P() - Pt()*Pt()); 
- if(Eta()<0) { Pz = -Pz ; }
double E = TMath::Sqrt(P()*P() + M*M) ;
float rapidity = 0.5*TMath::Log((E + Pz)/(E - Pz)) ;
Float_t mass = Mass() ; 
Double_t pz = TMath::Sqrt(P()*P() - Pt()*Pt()); 
+ if(Eta()<0) { pz = -pz ; }
Double_t e = TMath::Sqrt(P()*P() + mass*mass) ;
Float_t rapidity = 0.5*TMath::Log((e + pz)/(e - pz)) ;
  
  return rapidity ;
 }
-//////////////////////////////////////////////////////////////////////////////
+//-------------------------------------------------------------
 Float_t  AliFlowTrack::YGlobal() const 
 {
  // Rapidity of the unconstrained track
@@ -161,151 +165,163 @@ Float_t  AliFlowTrack::YGlobal() const
  if(TMath::Abs((Float_t)PGlobal()) == TMath::Abs((Float_t)PtGlobal()))            { return 0. ; }
  else if(TMath::Abs((Float_t)PGlobal()) < TMath::Abs((Float_t)PtGlobal())) { cout << "track: " << GetName() << "has  Pt() > P() !!!" << endl ; }
  // -
float M = Mass() ; 
double Pz = TMath::Sqrt(PGlobal()*PGlobal() - PtGlobal()*PtGlobal()); 
- if(EtaGlobal()<0) { Pz = -Pz ; }
double E = TMath::Sqrt(PGlobal()*PGlobal() + M*M) ;
float rapidity = 0.5*TMath::Log((E + Pz)/(E - Pz)) ;
Float_t mass = Mass() ; 
Double_t pz = TMath::Sqrt(PGlobal()*PGlobal() - PtGlobal()*PtGlobal()); 
+ if(EtaGlobal()<0) { pz = -pz ; }
Double_t e = TMath::Sqrt(PGlobal()*PGlobal() + mass*mass) ;
Float_t rapidity = 0.5*TMath::Log((e + pz)/(e - pz)) ;
  
  return rapidity ;
 }
-//////////////////////////////////////////////////////////////////////////////
-Bool_t AliFlowTrack::Select(Int_t harmonic,Int_t selection,Int_t subevent) const 
-{
- // Returns the selection flag for [harmonic] [selection] [sub-event]
-
- if((subevent == -1) || (subevent == fSubevent[harmonic][selection])) 
- {
-  if(fSelection[harmonic][selection]) { return kTRUE ; }
- } 
- return kFALSE ;       
-}
-//////////////////////////////////////////////////////////////////////////////
-void AliFlowTrack::SetSelect(Int_t harmonic,Int_t selection) 
-{ 
- fSelection[harmonic][selection] = kTRUE ;
-}
-//////////////////////////////////////////////////////////////////////////////
-void AliFlowTrack::SetSubevent(Int_t harmonic,Int_t selection,Int_t subevent) 
-{ 
- fSubevent[harmonic][selection] = subevent ; 
-}
-//////////////////////////////////////////////////////////////////////////////
-void AliFlowTrack::PrintSelection() 
-{
- // Prints a short string of 0 & 1 to visualize the selections' flags
- // [har1][sel0],[har1][sel1],[har1][sel2],...,[har2][sel0],...
- for(int i=0;i<AliFlowConstants::kHars;i++)
- {
-  for(int j=0;j<AliFlowConstants::kSels;j++)
-  {
-   if(Select(i,j)) { cout << 1 ; }
-   else           { cout << 0 ; }
-  }
- }
- cout << endl ;
-}
-//////////////////////////////////////////////////////////////////////////////
-void AliFlowTrack::ResetSelection() 
-{
- // Re-sets all the selection/sub-event flags to 0 
- // (track won't be used in any R.P. calculation)
-
- for(Int_t ii=0;ii<AliFlowConstants::kHars;ii++)
- {
-  for(Int_t jj=0;jj<AliFlowConstants::kSels;jj++)
-  {
-   fSelection[ii][jj] = kFALSE ; 
-   fSubevent[ii][jj] = -1 ; 
-  }
- }
-}
-//////////////////////////////////////////////////////////////////////////////
-const char* AliFlowTrack::Pid() const
+//-------------------------------------------------------------
+const Char_t* AliFlowTrack::Pid() const
 {
  // Returns the P.Id. in characters (e,mu,pi,k,p,d) basing on the stored pdg code 
  // and its sign (both stored in MostLikelihoodPID() ) .
  
- const char *name[] = {"e","mu","pi","k","pr","d"} ;
int pdg_code = TMath::Abs(MostLikelihoodPID()) ;
int charge = Charge() ;
-
- TString p_id = "" ;
- if(pdg_code == 11)            { p_id = name[0] ; }
- else if(pdg_code == 13)       { p_id = name[1] ; }
- else if(pdg_code == 211)      { p_id = name[2] ; }
- else if(pdg_code == 321)      { p_id = name[3] ; }
- else if(pdg_code == 2212)     { p_id = name[4] ; }
- else if(pdg_code == 10010020) { p_id = name[5] ; }
- else                         { p_id = "0" ; }
-
- if(charge>0)          { p_id += "+" ; } 
- else if(charge<0)     { p_id += "-" ; }
- else                  { p_id += "" ; }
+ const Char_t *name[] = {"e","mu","pi","k","pr","d"} ;
Int_t pdgCode = TMath::Abs(MostLikelihoodPID()) ;
Int_t charge = Charge() ;
+
+ TString pId = "" ;
+ if(pdgCode == 11)            { pId = name[0] ; }
+ else if(pdgCode == 13)       { pId = name[1] ; }
+ else if(pdgCode == 211)      { pId = name[2] ; }
+ else if(pdgCode == 321)      { pId = name[3] ; }
+ else if(pdgCode == 2212)     { pId = name[4] ; }
+ else if(pdgCode == 10010020) { pId = name[5] ; }
+ else                        { pId = "0" ; }
+
+ if(charge>0)                { pId += "+" ; } 
+ else if(charge<0)           { pId += "-" ; }
+ else                        { pId += "" ; }
  
- return p_id.Data() ; 
+ return pId.Data() ; 
 }
-//////////////////////////////////////////////////////////////////////////////
-void AliFlowTrack::PidProbs(Float_t pidN[AliFlowConstants::kPid]) const 
+//-------------------------------------------------------------
+void AliFlowTrack::PidProbs(Float_t *pidN) const 
 { 
- // Returns the normalized probability for the given track to be [e,mu,pi,k,p,d] 
- // The detector response is weighted by the bayesian vector of particles 
- // abundances, stored in AliFlowConstants::fgBayesian[] .
+ // Returns the normalized probability (the "bayesian weights") for the given track to be [e,mu,pi,k,p,d] .  
+ // The COMBINED detector response function is scaled by the a priori probabilities 
+ // (the normalised particle abundances is stored in AliFlowConstants::fgBayesian[]) .
 
  Double_t sum = 0 ; 
- for(Int_t n=0;n<AliFlowConstants::kPid;n++)  { sum += fPidProb[n] * AliFlowConstants::fgBayesian[n] ; }
- if(sum)
- {
-  for(Int_t n=0;n<AliFlowConstants::kPid;n++) { pidN[n] = fPidProb[n] * AliFlowConstants::fgBayesian[n] / sum ; }
+ for(Int_t n=0;n<AliFlowConstants::kPid;n++) { pidN[n] = PidProb(n) ; sum += pidN[n] ; }
+ if(sum) 
+ {  
+  for(Int_t n=0;n<AliFlowConstants::kPid;n++)  { pidN[n] /=  sum ; }
+ }
+ else { cout << " ERROR - Empty Bayesian Vector !!! " << endl ; }
+} 
+//-------------------------------------------------------------
+void AliFlowTrack::PidProbsC(Float_t *pidN) const 
+{ 
+ // Returns the normalized probability (the "bayesian weights") for the given track to be [e,mu,pi,k,p,d] .  
+ // The CUSTOM detector response function (see AliFlowTrack) is scaled by the a priori probabilities 
+ // (the normalised particle abundances is stored in AliFlowConstants::fgBayesian[]) .
+ Double_t sum = 0 ; 
+ for(Int_t n=0;n<AliFlowConstants::kPid;n++) { pidN[n] = PidProbC(n) ; sum += pidN[n] ; }
+ if(sum) 
+ {  
+  for(Int_t n=0;n<AliFlowConstants::kPid;n++)  { pidN[n] /=  sum ; }
  }
  else { cout << " ERROR - Empty Bayesian Vector !!! " << endl ; }
 } 
-//////////////////////////////////////////////////////////////////////////////
-Float_t  AliFlowTrack::PidProb(Int_t nn)       const
+//-------------------------------------------------------------
+Float_t  AliFlowTrack::PidProb(Int_t nPid) const
 {
- // Returns the normalized probability of the track to be [nn] (e,mu,pi,k,pi,d).
+ // Returns the bayesian weight of the track to be [nPid = e,mu,pi,k,pi,d].
+ // The detector response function in use is the combined one (from the ESD)
 
- Float_t pidN[AliFlowConstants::kPid] ; 
- PidProbs(pidN) ;
- return pidN[nn] ;
+ if(nPid > AliFlowConstants::kPid) { return 0. ; } 
+
+ return (fCombRespFun[nPid] * AliFlowConstants::fgBayesian[nPid]) ;
 }
-//////////////////////////////////////////////////////////////////////////////
-TVector AliFlowTrack::PidProbs()               const
+//-------------------------------------------------------------
+Float_t  AliFlowTrack::PidProbC(Int_t nPid) const
 {
- // Returns the normalized probability for the given track to be [e,mu,pi,k,p,d] 
- // as a TVector.
+ // Returns the bayesian weight of the track to be [nPid = e,mu,pi,k,pi,d].
+ // The detector response function in use is the custom one ...
+
+ if(nPid > AliFlowConstants::kPid) { return 0. ; } 
 
- TVector pidNvec(AliFlowConstants::kPid) ;
- Float_t pidN[AliFlowConstants::kPid] ; 
- PidProbs(pidN) ;
- for(Int_t n=0;n<AliFlowConstants::kPid;n++)  { pidNvec[n] = pidN[n] ; }
+ Float_t  customRespFun[AliFlowConstants::kPid] ;
+ GetCustomRespFun(customRespFun) ;
 
- return pidNvec ;
+ return (customRespFun[nPid] * AliFlowConstants::fgBayesian[nPid]) ;
 }
-//////////////////////////////////////////////////////////////////////////////
-void AliFlowTrack::RawPidProbs(Float_t pidV[AliFlowConstants::kPid]) const 
+//-------------------------------------------------------------
+Float_t AliFlowTrack::MostLikelihoodRespFunc() const 
 { 
- // Returns the array of probabilities for the track to be [e,mu,pi,k,pi,d].
+ // Returns the detector response function for the most probable P.id. hypothesis
+ // (Warning: THIS IS NOT THE BAYESIAN WEIGHT !) 
 
- for(Int_t ii=0;ii<AliFlowConstants::kPid;ii++) { pidV[ii] = fPidProb[ii] ; }
-} 
-//////////////////////////////////////////////////////////////////////////////
-Float_t AliFlowTrack::MostLikelihoodProb()         const 
-{ 
- // Returns the probability of the most probable P.id.
- // (Warning: THIS IS NOT WEIGHTED IN THE BAYESIAN WAY...) 
-
- int pdg_code = TMath::Abs(MostLikelihoodPID()) ;
- if(pdg_code == 11)            { return fPidProb[0] ; }
- else if(pdg_code == 13)       { return fPidProb[1] ; }
- else if(pdg_code == 211)      { return fPidProb[2] ; }
- else if(pdg_code == 321)      { return fPidProb[3] ; }
- else if(pdg_code == 2212)     { return fPidProb[4] ; }
- else if(pdg_code == 10010020) { return fPidProb[5] ; }
+ Int_t pdgCode = TMath::Abs(MostLikelihoodPID()) ;
+ if(pdgCode == 11)            { return fCombRespFun[0] ; }
+ else if(pdgCode == 13)       { return fCombRespFun[1] ; }
+ else if(pdgCode == 211)      { return fCombRespFun[2] ; }
+ else if(pdgCode == 321)      { return fCombRespFun[3] ; }
+ else if(pdgCode == 2212)     { return fCombRespFun[4] ; }
+ else if(pdgCode == 10010020) { return fCombRespFun[5] ; }
  else { return 0. ; }
 } 
-//////////////////////////////////////////////////////////////////////////////
+//-------------------------------------------------------------
+void AliFlowTrack::SetRespFun(Int_t det, Float_t *r)
+{
+ // This function fills "AliFlowConstants::kPid" PID weights 
+ // (detector response functions) of the track .
+ // The method is private, cause it is called by the public 
+ // methods: SetRespFunITS, SetRespFunTPC, ...
+
+ for(Int_t i=0;i<AliFlowConstants::kPid;i++)
+ {
+  fRespFun[det][i] = r[i] ;
+ }
+}
+//-------------------------------------------------------------
+void AliFlowTrack::GetRespFun(Int_t det, Float_t *r) const
+{
+ // This function returns the response functions of the 
+ // detector [det] for the P.Id. of the track .
+ // The method is private, and it is called by the public 
+ // methods: GetRespFunITS, GetRespFunTPC, ...
+
+ for(Int_t i=0;i<AliFlowConstants::kPid;i++)
+ {
+  r[i] = fRespFun[det][i] ;
+ }
+}
+//-------------------------------------------------------------
+void AliFlowTrack::GetCombinedRespFun(Float_t *r) const 
+{
+ // This function returns the combined response functions for  
+ // [e,mu,pi,k,pi,d] as it is stored in the ESD .
+ for(Int_t i=0;i<AliFlowConstants::kPid;i++)
+ {
+  r[i] = fCombRespFun[i] ;
+ }
+}
+//------------------------------------------------------------- 
+void AliFlowTrack::GetCustomRespFun(Float_t *r) const
+{
+ // This function returns a combined response functions as setted 
+ // by the user ... at the moment just the sum of single responses ...  
+ // for the track to be [e,mu,pi,k,pi,d] .
+ Int_t sum ;
+ for(Int_t i=0;i<AliFlowConstants::kPid;i++)
+ {
+  r[i] = 0. ; sum = 0 ;
+  for(Int_t det=0;det<4;det++) 
+  { 
+   if(fRespFun[det][i]>0) { r[i] += fRespFun[det][i] ; sum += 1 ; } 
+  }
+  if(sum) { r[i] /= sum ; }
+ }
+}
+//-------------------------------------------------------------
 void AliFlowTrack::SetPid(const Char_t* pid)           
 { 
  // Sets the P.Id. hypotesis of the track from a String imput (that should be 
@@ -323,22 +339,15 @@ void AliFlowTrack::SetPid(const Char_t* pid)
  if(strchr(pid,'+'))      { fMostLikelihoodPID = TMath::Abs(fMostLikelihoodPID) * 1 ; }
  else if(strchr(pid,'-'))  { fMostLikelihoodPID = TMath::Abs(fMostLikelihoodPID) * -1 ; } 
 }
-//////////////////////////////////////////////////////////////////////////////
-Int_t AliFlowTrack::Charge() const 
+//-------------------------------------------------------------
+void AliFlowTrack::SetPid(Int_t pdgCode)               
 { 
- // Tracks charge (stored as sign of fMostLikelihoodPID). +/-2 if deuterium.
+ // Sets the P.Id. hypotesis of the track from the PDG code. 
+ // Sign can be given as well. 
  
- if(MostLikelihoodPID() == 10010020) { return TMath::Sign(2,MostLikelihoodPID()) ; }
- else                               { return TMath::Sign(1,MostLikelihoodPID()) ; }
-}            
-//////////////////////////////////////////////////////////////////////////////
-void AliFlowTrack::SetCharge(Int_t charge)
-{ 
- // Sets the charge of the track (+/- sign of MostLikelihoodPID()).
- fMostLikelihoodPID = TMath::Sign(TMath::Abs(fMostLikelihoodPID),charge) ;
+ fMostLikelihoodPID = pdgCode ;
 }
-//////////////////////////////////////////////////////////////////////////////
+//-------------------------------------------------------------
 Bool_t AliFlowTrack::IsConstrainable()             const 
 { 
  // Returns kTRUE if the track is constrainable. 
@@ -350,98 +359,83 @@ Bool_t AliFlowTrack::IsConstrainable()                const
  if(fPt==0 && fEta==0) { return kFALSE ; }
  else                 { return kTRUE ; }
 } 
-//////////////////////////////////////////////////////////////////////////////
-Float_t AliFlowTrack::Dca()                        const 
+//-------------------------------------------------------------
+Float_t AliFlowTrack::Dca() const 
 {
+ // distance of closest approach (norm(dca[2]))
+
  Double_t mag = 0 ;
  for(Int_t ii=0;ii<2;ii++) { mag += (fDcaSigned[ii]*fDcaSigned[ii]) ; } 
  return TMath::Sqrt(mag) ; 
 }     
-//////////////////////////////////////////////////////////////////////////////
-Float_t AliFlowTrack::Dca2(Float_t dca[2])         const 
-{ 
- Double_t mag = 0 ;
- for(Int_t ii=0;ii<2;ii++) 
- { 
-  dca[ii] = fDcaSigned[ii] ; 
-  mag += (fDcaSigned[ii]*fDcaSigned[ii]) ; 
+//-------------------------------------------------------------
+Float_t AliFlowTrack::DcaError() const 
+{
+ // error on the distance of closest approach
+
+ Double_t err = 0 ;
+ for(Int_t ii=0;ii<2;ii++) { err = (fDcaError[ii]*fDcaError[ii]) ; } 
+ return TMath::Sqrt(err) ; 
+}     
+//-------------------------------------------------------------
+void AliFlowTrack::DcaError3(Float_t err[3]) const 
+{
+ // Dca Error (xy, z, cov(xy,z)) ...
+
+ for(Int_t ii=0;ii<2;ii++) { err[ii] = TMath::Abs(fDcaError[ii]) ; }           
+}     
+//-------------------------------------------------------------
+
+//-------------------------------------------------------------
+Bool_t AliFlowTrack::Select(Int_t harmonic,Int_t selection,Int_t subevent) const 
+{
+ // Returns the selection flag for [harmonic] [selection] [sub-event]
+
+ if((subevent == -1) || (subevent == fSubevent[harmonic][selection])) 
+ {
+  return fSelection[harmonic][selection] ; 
  } 
- return TMath::Sqrt(mag) ; 
+ return kFALSE ;       
 }
-//////////////////////////////////////////////////////////////////////////////
-Float_t AliFlowTrack::Dca3(Float_t dca[3])         const 
+//-------------------------------------------------------------
+void AliFlowTrack::PrintSelection() const
 {
- dca[0] = TMath::Abs(fDcaSigned[0])* TMath::Cos(Phi()) ;
- dca[1] = TMath::Abs(fDcaSigned[0])* TMath::Sin(Phi()) ;
- dca[2] = TMath::Abs(fDcaSigned[1]) ;          
- return Dca() ; 
-}     
-//////////////////////////////////////////////////////////////////////////////
-Float_t  AliFlowTrack::Phi()                       const 
-{ 
- if(IsConstrainable()) { return fPhi ; }
- else          { return PhiGlobal() ; }
-}                  
-//////////////////////////////////////////////////////////////////////////////
-Float_t  AliFlowTrack::Pt()                        const 
-{  
- if(IsConstrainable())  { return fPt ; }
- else           { return PtGlobal() ; }
+ // Prints a short string of 0 & 1 to visualize the selections' flags
+ // [har1][sel0],[har1][sel1],[har1][sel2],...,[har2][sel0],...
+ for(Int_t i=0;i<AliFlowConstants::kHars;i++)
+ {
+  for(Int_t j=0;j<AliFlowConstants::kSels;j++)
+  {
+   if(Select(i,j)) { cout << 1 ; }
+   else           { cout << 0 ; }
+  }
+ }
+ cout << endl ;
+}
+//-------------------------------------------------------------
+void AliFlowTrack::ResetSelection() 
+{
+ // Re-sets all the selection/sub-event flags to 0 
+ // (track won't be used in any R.P. calculation)
+
+ for(Int_t ii=0;ii<AliFlowConstants::kHars;ii++)
+ {
+  for(Int_t jj=0;jj<AliFlowConstants::kSels;jj++)
+  {
+   fSelection[ii][jj] = kFALSE ; 
+   fSubevent[ii][jj] = -1 ; 
+  }
+ }
 }
-//////////////////////////////////////////////////////////////////////////////
-Float_t  AliFlowTrack::Eta()                       const 
-{  
- if(IsConstrainable())  { return fEta ; }
- else           { return EtaGlobal() ; }
-}                    
-//////////////////////////////////////////////////////////////////////////////
-Float_t  AliFlowTrack::PhiGlobal()                 const { return fPhiGlobal ; }                   
-Float_t  AliFlowTrack::PtGlobal()                  const { return fPtGlobal ; }                    
-Float_t  AliFlowTrack::EtaGlobal()                 const { return fEtaGlobal ; }                     
-//////////////////////////////////////////////////////////////////////////////
-Float_t AliFlowTrack::TransDcaSigned()                     const { return fDcaSigned[0] ; }            
-Float_t AliFlowTrack::TransDca()                   const { return TMath::Abs(TransDcaSigned()) ; }     
-Float_t  AliFlowTrack::Chi2()                      const { return fChi2 ; }                
-Float_t  AliFlowTrack::TrackLength()               const { return fTrackLength ; }         
-Float_t  AliFlowTrack::ZFirstPoint()               const { return fZFirstPoint ; }         
-Float_t  AliFlowTrack::ZLastPoint()                const { return fZLastPoint ; }          
-
-Int_t   AliFlowTrack::MostLikelihoodPID()          const { return fMostLikelihoodPID; } 
-Float_t  AliFlowTrack::ElectronPositronProb()      const { return PidProb(0) ; }
-Float_t  AliFlowTrack::MuonPlusMinusProb()         const { return PidProb(1) ; }
-Float_t  AliFlowTrack::PionPlusMinusProb()         const { return PidProb(2) ; }
-Float_t  AliFlowTrack::KaonPlusMinusProb()         const { return PidProb(3) ; }
-Float_t  AliFlowTrack::ProtonPbarProb()            const { return PidProb(4) ; }
-Float_t  AliFlowTrack::DeuteriumAntiDeuteriumProb() const { return PidProb(5) ; }
-
-Int_t   AliFlowTrack::FitPtsTPC()                  const { return fFitPts[0]  ; }  
-Int_t   AliFlowTrack::MaxPtsTPC()                  const { return fMaxPts[0]  ; }  
-Float_t  AliFlowTrack::Chi2TPC()                   const { return fFitChi2[0] ; }          
-Float_t  AliFlowTrack::DedxTPC()                   const { return fDedx[0]    ; }  
-Int_t   AliFlowTrack::FitPtsITS()                  const { return fFitPts[1]  ; }       
-Int_t   AliFlowTrack::MaxPtsITS()                  const { return fMaxPts[1]  ; }
-Float_t  AliFlowTrack::Chi2ITS()                   const { return fFitChi2[1] ; }               
-Float_t  AliFlowTrack::DedxITS()                   const { return fDedx[1]    ; }  
-Int_t   AliFlowTrack::NhitsTRD()                   const { return fFitPts[2]  ; }       
-Int_t   AliFlowTrack::MaxPtsTRD()                  const { return fMaxPts[2]  ; }  
-Float_t  AliFlowTrack::Chi2TRD()                   const { return fFitChi2[2] ; }               
-Float_t  AliFlowTrack::SigTRD()                            const { return fDedx[2]    ; }  
-Int_t   AliFlowTrack::NhitsTOF()                   const { return fFitPts[3]  ; }       
-Int_t   AliFlowTrack::MaxPtsTOF()                  const { return fMaxPts[3]  ; }  
-Float_t  AliFlowTrack::Chi2TOF()                   const { return fFitChi2[3] ; }               
-Float_t  AliFlowTrack::TofTOF()                            const { return fDedx[3]    ; }  
-
-Float_t  AliFlowTrack::PatTPC()                    const { return fMom[0] ; }
-Float_t  AliFlowTrack::PatITS()                    const { return fMom[1] ; }
-Float_t  AliFlowTrack::PatTRD()                    const { return fMom[2] ; }
-Float_t  AliFlowTrack::PatTOF()                    const { return fMom[3] ; }
-
-Int_t    AliFlowTrack::Label()                     const { return fLabel ; }         
-//////////////////////////////////////////////////////////////////////////////
+//-------------------------------------------------------------
+
+//-------------------------------------------------------------
 void AliFlowTrack::SetConstrainable()                        
 { 
- // fills the constrained parameters with the unconstrained ones, making it
- // a constrainable track.                            !!! TRICKY METHOD !!!
+ // fills the constrained parameters with the unconstrained ones,
+ // making the track a constrainable track.
+ //                                       !!! TRICKY METHOD !!!
 
  if(!IsConstrainable()) 
  { 
@@ -450,11 +444,12 @@ void AliFlowTrack::SetConstrainable()
   fPt  = fPtGlobal ; 
  } 
 }
-//////////////////////////////////////////////////////////////////////////////
+//-------------------------------------------------------------
 void AliFlowTrack::SetUnConstrainable()                              
 { 
- // deletes the constrained parameters making it  an unconstrainable track. 
- //                                                   !!! TRICKY METHOD !!!
+ // deletes the constrained parameters making the track an 
+ // unconstrainable track. 
+ //                                       !!! TRICKY METHOD !!!
 
  if(IsConstrainable()) 
  { 
@@ -463,49 +458,4 @@ void AliFlowTrack::SetUnConstrainable()
   fPt  = 0. ; 
  } 
 }
-//////////////////////////////////////////////////////////////////////////////
-void AliFlowTrack::SetPhi(Float_t phi)                       { fPhi = phi; }
-void AliFlowTrack::SetEta(Float_t eta)                       { fEta = eta; }
-void AliFlowTrack::SetPt(Float_t pt)                         { fPt = pt; }
-void AliFlowTrack::SetPhiGlobal(Float_t phi)                 { fPhiGlobal = phi; }
-void AliFlowTrack::SetEtaGlobal(Float_t eta)                 { fEtaGlobal = eta; }
-void AliFlowTrack::SetPtGlobal(Float_t pt)                   { fPtGlobal = pt; }
-void AliFlowTrack::SetDcaSigned(Float_t xy, Float_t z)        { fDcaSigned[0] = xy ; fDcaSigned[1] = z ; }
-void AliFlowTrack::SetTransDcaSigned(Float_t xy)             { fDcaSigned[0] = xy ; }
-void AliFlowTrack::SetChi2(Float_t chi2)                     { fChi2 = chi2; }
-void AliFlowTrack::SetTrackLength(Float_t tl)                { fTrackLength = tl; }
-void AliFlowTrack::SetZFirstPoint(Float_t zFirst)            { fZFirstPoint = zFirst; }
-void AliFlowTrack::SetZLastPoint(Float_t zLast)              { fZLastPoint = zLast; }
-
-void AliFlowTrack::SetMostLikelihoodPID(Int_t val)            { fMostLikelihoodPID = val ; }   // feed here the Signed pdg_code 
-void AliFlowTrack::SetElectronPositronProb(Float_t val)       { fPidProb[0] = TMath::Abs(val) ; } 
-void AliFlowTrack::SetMuonPlusMinusProb(Float_t val)         { fPidProb[1] = TMath::Abs(val) ; } 
-void AliFlowTrack::SetPionPlusMinusProb(Float_t val)         { fPidProb[2] = TMath::Abs(val) ; } 
-void AliFlowTrack::SetKaonPlusMinusProb(Float_t val)         { fPidProb[3] = TMath::Abs(val) ; } 
-void AliFlowTrack::SetProtonPbarProb(Float_t val)            { fPidProb[4] = TMath::Abs(val) ; } 
-void AliFlowTrack::SetDeuteriumAntiDeuteriumProb(Float_t val) { fPidProb[5] = TMath::Abs(val) ; }
-
-void AliFlowTrack::SetFitPtsTPC(Int_t fitPts)                { fFitPts[0]  = fitPts ; }
-void AliFlowTrack::SetMaxPtsTPC(Int_t maxPts)                { fMaxPts[0]  = maxPts ; }
-void AliFlowTrack::SetChi2TPC(Float_t chi2)                  { fFitChi2[0] = chi2   ; }
-void AliFlowTrack::SetDedxTPC(Float_t dedx)                  { fDedx[0]    = dedx   ; }
-void AliFlowTrack::SetFitPtsITS(Int_t nhits)                 { fFitPts[1]  = nhits  ; }
-void AliFlowTrack::SetMaxPtsITS(Int_t maxPts)                { fMaxPts[1]  = maxPts ; }
-void AliFlowTrack::SetChi2ITS(Float_t chi2)                  { fFitChi2[1] = chi2   ; }
-void AliFlowTrack::SetDedxITS(Float_t dedx)                  { fDedx[1]    = dedx   ; }
-void AliFlowTrack::SetNhitsTRD(Int_t fitPts)                 { fFitPts[2]  = fitPts ; }
-void AliFlowTrack::SetMaxPtsTRD(Int_t maxPts)                { fMaxPts[2]  = maxPts ; }
-void AliFlowTrack::SetChi2TRD(Float_t chi2)                  { fFitChi2[2] = chi2   ; }
-void AliFlowTrack::SetSigTRD(Float_t dedx)                   { fDedx[2]    = dedx   ; }
-void AliFlowTrack::SetNhitsTOF(Int_t fitPts)                 { fFitPts[3]  = fitPts ; }
-void AliFlowTrack::SetMaxPtsTOF(Int_t maxPts)                { fMaxPts[3]  = maxPts ; }
-void AliFlowTrack::SetChi2TOF(Float_t chi2)                  { fFitChi2[3] = chi2   ; }
-void AliFlowTrack::SetTofTOF(Float_t dedx)                   { fDedx[3]    = dedx   ; }
-
-void AliFlowTrack::SetPatTPC(Float_t p)                      { fMom[0] = p ; }
-void AliFlowTrack::SetPatITS(Float_t p)                      { fMom[1] = p ; }
-void AliFlowTrack::SetPatTRD(Float_t p)                      { fMom[2] = p ; }
-void AliFlowTrack::SetPatTOF(Float_t p)                      { fMom[3] = p ; }
-
-void AliFlowTrack::SetLabel(Int_t label)                     { fLabel = label ; }
-//////////////////////////////////////////////////////////////////////////////
+//-------------------------------------------------------------