]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG2/RESONANCES/AliRsnDaughter.cxx
Some bug fixes, removal of some duplicates and clarified the logic of some pieces...
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnDaughter.cxx
index 0b425a376222d481b144ddce8b1f26d3b4794d90..e17b09296d80b6460d832c573626be8eac196f34 100644 (file)
 //
-// Class AliRsnDaughter
+//  This class works as generic interface to each candidate resonance daughter.
+//  Its main purpose is to provide a unique reference which includes all the
+//  facilities available in the AliVParticle generic base class, plus all info
+//  which could be needed during analysis, which are not in AliVParticle but
+//  need to be accessed from ESD or AOD objects, usually in different ways.
+//  When MC is available, AliRsnDaughter matches each reconstructed object with
+//  its corresponding MC particle.
+//  
+//  Currently, this interface can point to all kinds of single-particle object
+//  which one can have in the reconstructed event: charged tracks, V0s and 
+//  cascades. It is care of the user to treat each of them in the correct way,
+//  regarding cuts, functions to be computed, etc.
 //
-// Light-weight AOD object which contains all required track details
-// which are used for resonance analysis.
-// Provides converters from all kinds of input track type: ESD, AOD and MC.
+//  authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
+//           M. Vala (martin.vala@cern.ch)
 //
-// authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
-//          M. Vala (martin.vala@cern.ch)
-//
-
-#include <Riostream.h>
 
 #include <TParticle.h>
-#include <TString.h>
+#include <TDatabasePDG.h>
 
-#include "AliLog.h"
-#include "AliESDtrack.h"
-#include "AliAODTrack.h"
-#include "AliMCParticle.h"
-
-#include "AliRsnPIDDefESD.h"
-#include "AliRsnMCInfo.h"
 #include "AliRsnDaughter.h"
 
 ClassImp(AliRsnDaughter)
 
-AliRsnDaughter::EPIDMethod AliRsnDaughter::fgPIDMethod = AliRsnDaughter::kRealistic;
-
 //_____________________________________________________________________________
-AliRsnDaughter::AliRsnDaughter() :
-  AliVParticle(),
-  fIndex(-1),
-  fLabel(-1),
-  fCharge(0),
-  fFlags(0),
-  fKink(0),
-  fMass(0.0),
-  fChi2(0.0),
-  fNSigmaToVertex(-1.0),
-  fITSnum(0),
-  fTPCnum(0),
-  fRealisticPID(AliRsnPID::kUnknown),
-  fMCInfo(0x0)
+AliRsnDaughter::AliRsnDaughter(const AliRsnDaughter &copy) :
+   TObject(copy),
+   fOK(copy.fOK),
+   fLabel(copy.fLabel),
+   fMotherPDG(copy.fMotherPDG),
+   fRsnID(copy.fRsnID),
+   fPrec(copy.fPrec),
+   fPsim(copy.fPsim),
+   fRef(copy.fRef),
+   fRefMC(copy.fRefMC),
+   fOwnerEvent(copy.fOwnerEvent)
 {
 //
-// Default constructor.
-// Initializes all data-members with meaningless values.
+// Copy constructor.
+// Pointers are NOT duplicated, since they don't come from a 'new'
+// statement, but from just referencing something in the data source.
 //
-
-  Int_t i;
-  for (i = 0; i < AliRsnPID::kSpecies; i++)
-  {
-    if (i < 3)
-    {
-      fP[i] = 0.0;
-      fV[i] = 0.0;
-    }
-    fPIDWeight[i] = 0.0;
-    fPIDProb[i] = 0.0;
-  }
 }
 
 //_____________________________________________________________________________
-AliRsnDaughter::AliRsnDaughter(const AliRsnDaughter &copy) :
-  AliVParticle(copy),
-  fIndex(copy.fIndex),
-  fLabel(copy.fLabel),
-  fCharge(copy.fCharge),
-  fFlags(copy.fFlags),
-  fKink(copy.fKink),
-  fMass(copy.fMass),
-  fChi2(copy.fChi2),
-  fNSigmaToVertex(copy.fNSigmaToVertex),
-  fITSnum(copy.fITSnum),
-  fTPCnum(copy.fTPCnum),
-  fRealisticPID(copy.fRealisticPID),
-  fMCInfo(0x0)
+AliRsnDaughter& AliRsnDaughter::operator=(const AliRsnDaughter &copy)
 {
 //
-// Copy constructor.
+// Assignment operator.
+// Pointers are NOT duplicated, since they don't come from a 'new'
+// statement, but from just referencing something in the data source.
 //
 
-  Int_t i;
-  for (i = 0; i < AliRsnPID::kSpecies; i++)
-  {
-    if (i < 3)
-    {
-      fP[i] = copy.fP[i];
-      fV[i] = copy.fV[i];
-    }
-    fPIDWeight[i] = copy.fPIDWeight[i];
-    fPIDProb[i] = copy.fPIDProb[i];
-  }
-
-  // initialize particle object
-  // only if it is present in the template object
-  if (copy.fMCInfo) fMCInfo = new AliRsnMCInfo(*(copy.fMCInfo));
+   fOK         = copy.fOK;
+   fLabel      = copy.fLabel;
+   fMotherPDG  = copy.fMotherPDG;
+   fRsnID      = copy.fRsnID;
+   fPsim       = copy.fPsim;
+   fPrec       = copy.fPrec;
+   fRef        = copy.fRef;
+   fRefMC      = copy.fRefMC;
+   fOwnerEvent = copy.fOwnerEvent;
+
+   return (*this);
 }
 
 //_____________________________________________________________________________
-AliRsnDaughter& AliRsnDaughter::operator=(const AliRsnDaughter &copy)
+void AliRsnDaughter::Reset()
 {
 //
-// Assignment operator.
-// Works like the copy constructor and returns a reference
-// to the initialized object for which it is called.
+// Reset this track to meaningless values and to a 'bad' status.
+// After this has been done, this object should not be used
+// for analysis unless initialized properly.
 //
 
-  fIndex  = copy.fIndex;
-  fLabel  = copy.fLabel;
-  fCharge = copy.fCharge;
-  fFlags  = copy.fFlags;
-  fKink   = copy.fKink;
-  fChi2   = copy.fChi2;
-  fNSigmaToVertex = copy.fNSigmaToVertex;
-  fITSnum = copy.fITSnum;
-  fTPCnum = copy.fTPCnum;
-
-  Int_t i;
-  for (i = 0; i < AliRsnPID::kSpecies; i++)
-  {
-    if (i < 3)
-    {
-      fP[i] = copy.fP[i];
-      fV[i] = copy.fV[i];
-    }
-    fPIDWeight[i] = copy.fPIDWeight[i];
-    fPIDProb[i] = copy.fPIDProb[i];
-  }
-
-  fMass = copy.fMass;
-  fRealisticPID = copy.fRealisticPID;
+   fOK        = kFALSE;
+   fLabel     = -1;
+   fMotherPDG =  0;
+   fRsnID     = -1;
+   
+   fPsim.SetXYZT(0.0, 0.0, 0.0, 0.0);
+   fPrec.SetXYZT(0.0, 0.0, 0.0, 0.0);
 
-  // initialize particle object
-  // only if it is present in the template object;
-  // otherwise, it is just cleared and not replaced with anything
-  if (fMCInfo)
-  {
-    delete fMCInfo;
-    fMCInfo = 0x0;
-  }
-  if (copy.fMCInfo) fMCInfo = new AliRsnMCInfo(*(copy.fMCInfo));
-
-  return (*this);
+   fRef = fRefMC = 0x0;
+   fOwnerEvent = 0x0;
 }
 
 //_____________________________________________________________________________
-AliRsnDaughter::~AliRsnDaughter()
+Int_t AliRsnDaughter::GetPDG()
 {
 //
-// Destructor
+// Return the PDG code of the particle from MC ref (if any).
+// If argument is kTRUE, returns its absolute value.
 //
 
-  if (fMCInfo)
-  {
-    delete fMCInfo;
-    fMCInfo = 0;
-  }
+   if (Match(fRefMC, AliMCParticle::Class()))
+      return ((AliMCParticle*)fRefMC)->Particle()->GetPdgCode();
+   else if (Match(fRefMC, AliAODMCParticle::Class()))
+      return ((AliAODMCParticle*)fRefMC)->GetPdgCode();
+   else {
+      AliWarning("Cannot retrieve PDG");
+      return 0;
+   }
 }
 
 //_____________________________________________________________________________
-void AliRsnDaughter::RotateP(Double_t angle, Bool_t isDegrees)
+Int_t AliRsnDaughter::GetID()
 {
 //
-// Rotate the transverse momentum by an angle (in DEGREES)
-// around Z axis (does not change the Z component)
+// Return reference index, using the "GetID" method
+// of the possible source object.
+// When this method is unsuccessful (e.g.: V0s), return the label.
 //
 
-  if (isDegrees) angle *= TMath::DegToRad();
+   // ESD tracks
+   AliESDtrack *esd = Ref2ESDtrack();
+   if (esd) return esd->GetID();
+
+   // AOD tracks
+   AliAODTrack *aod = Ref2AODtrack();
+   if (aod) return aod->GetID();
 
-  Double_t s = TMath::Sin(angle);
-  Double_t c = TMath::Cos(angle);
-  Double_t xx = fP[0];
-  fP[0] = c*xx - s*fP[1];
-  fP[1] = s*xx + c*fP[1];
+   // whatever else
+   return GetLabel();
 }
 
 //_____________________________________________________________________________
-Double_t AliRsnDaughter::AngleTo(AliRsnDaughter *d, Bool_t outInDegrees)
+Int_t AliRsnDaughter::GetMother()
 {
 //
-// Compute angle between the vector momentum of this
-// and the one of argument.
+// Return index of the first mother of the MC reference, if any.
+// Otherwise, returns -1 (the same as for primary tracks)
 //
 
-  Double_t arg, dot, ptot2 = P2() * d->P2();
-
-  if(ptot2 <= 0) {
-    return 0.0;
-  }
-  else {
-    dot = Px()*d->Px() + Py()*d->Py() + Pz()*d->Pz();
-    arg = dot / TMath::Sqrt(ptot2);
-    if (arg >  1.0) arg =  1.0;
-    if (arg < -1.0) arg = -1.0;
-    if (outInDegrees) return TMath::ACos(arg) * TMath::RadToDeg();
-    else return TMath::ACos(arg);
-  }
+   if (!fRefMC) return -1;
+
+   if (fRefMC->InheritsFrom(AliMCParticle::Class())) {
+      AliMCParticle *mc = (AliMCParticle*)fRefMC;
+      return mc->Particle()->GetFirstMother();
+   } else if (fRefMC->InheritsFrom(AliAODMCParticle::Class())) {
+      AliAODMCParticle *mc = (AliAODMCParticle*)fRefMC;
+      return mc->GetMother();
+   }
+   else
+      return -1;
 }
+   
+   
 
-//_____________________________________________________________________________
-void  AliRsnDaughter::RealisticPID()
+//______________________________________________________________________________
+void AliRsnDaughter::Print(Option_t *opt) const
 {
 //
-// Assign realistic PID from largest probability
+// Override of TObject::Print()
 //
 
-  Int_t i, imax = 0;
-  Double_t pmax = fPIDProb[0];
-
-  // search for maximum
-  for (i = 1; i < AliRsnPID::kSpecies; i++)
-  {
-    if (fPIDProb[i] > pmax)
-    {
-      imax = i;
-      pmax = fPIDProb[i];
-    }
-  }
-
-  fRealisticPID = (AliRsnPID::EType)imax;
+   AliInfo("=== DAUGHTER INFO ======================================================================");
+   AliInfo(Form(" (sim) px,py,pz = %6.2f %6.2f %6.2f", fPsim.X(), fPsim.Y(), fPsim.Z()));
+   AliInfo(Form(" (rec) px,py,pz = %6.2f %6.2f %6.2f", fPrec.X(), fPrec.Y(), fPrec.Z()));
+   AliInfo(Form(" OK, RsnID, Label, MotherPDG = %s, %5d, %5d, %4d", (fOK ? "true " : "false"), fRsnID, fLabel, fMotherPDG));
+   AliInfo("========================================================================================");
 }
 
-//_____________________________________________________________________________
-AliRsnPID::EType AliRsnDaughter::PIDType(Double_t &prob) const
+//______________________________________________________________________________
+const char* AliRsnDaughter::SpeciesName(ESpecies species)
 {
 //
-// Return the PID type according to the selected method
-// in the argument passed by reference, the probability is stored.
-// It will be realistic for realistic PID and 1 for perfect PID.
+// Return a string with the short name of the particle
 //
 
-  switch (fgPIDMethod)
-  {
-    case kNoPID:
-      AliWarning("Requested a PIDtype call in NoPID mode");
-      prob = 1.0;
-      return AliRsnPID::kUnknown;
-    case kPerfect:
-      prob = 1.0;
-      if (fMCInfo) return AliRsnPID::InternalType(fMCInfo->PDG());
-      else return AliRsnPID::kUnknown;
-    default:
-      if (fRealisticPID >= 0 && fRealisticPID < AliRsnPID::kSpecies)
-      {
-        prob = fPIDProb[fRealisticPID];
-        return fRealisticPID;
-      }
-      else
-      {
-        prob = 1.0;
-        return AliRsnPID::kUnknown;
-      }
-  }
+   switch (species) {
+      case kElectron: return "E";
+      case kMuon:     return "Mu";
+      case kPion:     return "Pi";
+      case kKaon:     return "K";
+      case kProton:   return "P";
+      case kKaon0:    return "K0s";
+      case kLambda:   return "Lambda";
+      case kXi:       return "Xi";
+      case kOmega:    return "Omega";
+      default:        return "Undef";
+   }
 }
 
-//_____________________________________________________________________________
-void AliRsnDaughter::Print(Option_t *option) const
+//______________________________________________________________________________
+Int_t AliRsnDaughter::SpeciesPDG(ESpecies species)
 {
 //
-// Prints the values of data members, using the options:
-// - P --> momentum
-// - V --> DCA vertex
-// - C --> electric charge
-// - F --> flags
-// - I --> identification (PID, probability and mass)
-// - W --> PID weights
-// - M --> Montecarlo (from AliRsnMCInfo)
-// - L --> index & label
-// - A --> angles
-// - ALL --> All oprions switched on
+// Return the PDG code of a particle species (abs value)
 //
-// Index and label are printed by default.
-//
-
-  TString opt(option);
-  opt.ToUpper();
 
-  if (opt.Contains("L") || opt.Contains("ALL"))
-  {
-    cout << ".......Index            : " << fIndex << endl;
-    cout << ".......Label            : " << fLabel << endl;
-  }
-  if (opt.Contains("P") || opt.Contains("ALL"))
-  {
-    cout << ".......Px, Py, Pz, Pt   : " << Px() << ' ' << Py() << ' ' << Pz() << ' ' << Pt() << endl;
-  }
-  if (opt.Contains("A") || opt.Contains("ALL"))
-  {
-    cout << ".......Phi, Theta       : " << Phi() << ' ' << Theta() << endl;
-  }
-  if (opt.Contains("V") || opt.Contains("ALL"))
-  {
-    cout << ".......Vx, Vy, Vz       : " << Xv() << ' ' << Yv() << ' ' << Zv() << endl;
-  }
-  if (opt.Contains("I") || opt.Contains("ALL"))
-  {
-    AliRsnPID::EType type;
-    Double_t prob;
-    type = PIDType(prob);
-    cout << ".......PID & prob       : " << AliRsnPID::ParticleName(type) << ' ' << prob << endl;
-  }
-  if (opt.Contains("C") || opt.Contains("ALL"))
-  {
-    cout << ".......Charge           : " << fCharge << endl;
-  }
-  if (opt.Contains("F") || opt.Contains("ALL"))
-  {
-    cout << ".......Flags            : " << fFlags << endl;
-  }
-  if (opt.Contains("W") || opt.Contains("ALL"))
-  {
-    cout << ".......Weights          : ";
-    Int_t i;
-    for (i = 0; i < AliRsnPID::kSpecies; i++) cout << fPIDWeight[i] << ' ';
-    cout << endl;
-  }
-  if (opt.Contains("M") || opt.Contains("ALL"))
-  {
-    if (fMCInfo)
-    {
-      cout << ".......PDG code         : " << fMCInfo->PDG() << endl;
-      cout << ".......Mother (label)   : " << fMCInfo->Mother() << endl;
-      cout << ".......Mother (PDG code): " << fMCInfo->MotherPDG() << endl;
-    }
-    else
-    {
-      cout << ".......MC info not present" << endl;
-    }
-  }
+   switch (species) {
+      case kElectron: return 11;
+      case kMuon:     return 13;
+      case kPion:     return 211;
+      case kKaon:     return 321;
+      case kProton:   return 2212;
+      case kKaon0:    return 310;
+      case kLambda:   return 3122;
+      case kXi:       return 3312;
+      case kOmega:    return 3334;
+      default:        return 0;
+   }
 }
 
-//_____________________________________________________________________________
-void AliRsnDaughter::InitMCInfo()
+//______________________________________________________________________________
+Double_t AliRsnDaughter::SpeciesMass(ESpecies species)
 {
 //
-// Initializes the particle object with default constructor.
+// Return the mass of a particle species
 //
 
-  fMCInfo = new AliRsnMCInfo;
+   TDatabasePDG *db = TDatabasePDG::Instance();
+   TParticlePDG *part = 0x0;
+   
+   Int_t pdg = SpeciesPDG(species);
+   if (pdg) {
+      part = db->GetParticle(pdg);
+      return part->Mass();
+   }
+   else
+      return 0.0;
 }
 
-//_____________________________________________________________________________
-Bool_t AliRsnDaughter::InitMCInfo(TParticle *particle)
+//______________________________________________________________________________
+EPARTYPE AliRsnDaughter::ToAliPID(ESpecies species)
 {
 //
-// Copies data from an MC particle into the object which
-// contains all MC details taken from kinematics info.
-// If requested by second argument, momentum and vertex
-// of the Particle are copied into the 'fP' and 'fV'
-// data members, to simulate a perfect reconstruction.
-// If something goes wrong, returns kFALSE,
-// otherwise returns kTRUE.
+// Convert an enum element from this object
+// into the enumeration of AliPID.
+// If no match are cound 'kUnknown' is returned.
 //
 
-  // retrieve the TParticle object pointed by this MC track
-  if (!particle)
-  {
-    AliError("Passed NULL particle object");
-    return kFALSE;
-  }
-
-  // initialize object if not initialized yet
-  if (fMCInfo) delete fMCInfo;
-  fMCInfo = new AliRsnMCInfo;
-  fMCInfo->Adopt(particle);
-
-  return kTRUE;
+   switch (species) {
+      case kElectron: return AliPID::kElectron;
+      case kMuon:     return AliPID::kMuon;
+      case kPion:     return AliPID::kPion;
+      case kKaon:     return AliPID::kKaon;
+      case kProton:   return AliPID::kProton;
+      case kKaon0:    return AliPID::kKaon0;
+      default:        return AliPID::kUnknown;
+   }
 }
 
-//_____________________________________________________________________________
-Int_t AliRsnDaughter::Compare(const TObject* obj) const
+//______________________________________________________________________________
+AliRsnDaughter::ESpecies AliRsnDaughter::FromAliPID(EPARTYPE pid)
 {
 //
-// Compare two tracks with respect to their transverse momentum.
-// Citation from ROOT reference:
-// "Must return -1 if this is smaller than obj, 0 if objects are equal
-//  and 1 if this is larger than obj".
+// Convert an enum element from AliPID
+// into the enumeration of this object.
+// If no match are cound 'kUnknown' is returned.
 //
 
-  AliRsnDaughter *that = (AliRsnDaughter*)obj;
-  if (Pt() < that->Pt()) return 1;
-  else if (Pt() > that->Pt()) return -1;
-  else return 0;
+   switch (pid) {
+      case AliPID::kElectron: return kElectron;
+      case AliPID::kMuon:     return kMuon;
+      case AliPID::kPion:     return kPion;
+      case AliPID::kKaon:     return kKaon;
+      case AliPID::kProton:   return kProton;
+      case AliPID::kKaon0:    return kKaon0;
+      default:                return kUnknown;
+   }
 }