]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG2/RESONANCES/AliRsnDaughter.cxx
Block of updates on RSN package:
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnDaughter.cxx
index be2001aac8d149d58cd27d15c5fd59c66e4e071d..ae9b3494fc1fdfb92f6e7f0620a7ed1fe85e20b0 100644 (file)
-/**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- *                                                                        *
- * Author: The ALICE Off-line Project.                                    *
- * Contributors are mentioned in the code where appropriate.              *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          *
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
-//-------------------------------------------------------------------------
-//                      Class AliRsnDaughter
-//                     ----------------------
-//           A simple object which describes a reconstructed track
-//           with some references to its related generated particle
-//           and some facilities which could help in composing its
-//           4-momentum, for resonance study.
-// 
-// author: A. Pulvirenti             (email: alberto.pulvirenti@ct.infn.it)
-//-------------------------------------------------------------------------
-
-#include <Riostream.h>
+//
+// Class AliRsnDaughter
+//
+// Interface to candidate daughters of a resonance (tracks).
+// Points to the source of information, which is generally an AliVParticle-derived object
+// and contains few internal data-members to store "on fly" some important information
+// for the computations required during resonance analysis.
+// It contains a useful TLorentzVector data-member which, provided that a meaningful mass was assigned,
+// eases a lot the computation of invariant masses from summing up several of these objects.
+//
+// authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
+//          M. Vala (martin.vala@cern.ch)
+//
 
 #include <TParticle.h>
-#include <TString.h>
-
-#include "AliESDtrack.h"
+#include "AliAODVertex.h"
 #include "AliRsnDaughter.h"
 
 ClassImp(AliRsnDaughter)
 
-//--------------------------------------------------------------------------------------------------------
-AliRsnDaughter::AliRsnDaughter()
+//_____________________________________________________________________________
+AliRsnDaughter::AliRsnDaughter() :
+  fOK(kFALSE),
+  fLabel(-1),
+  fMotherPDG(0),
+  fPrec(0.0, 0.0, 0.0, 0.0),
+  fPsim(0.0, 0.0, 0.0, 0.0),
+  fRef(0x0),
+  fRefMC(0x0)
 {
-// 
+//
 // Default constructor.
-// Its unique argument defines how many PID weights are allowed. 
-// Actually, it should be the same as AliESDtrack::kSPECIES (=5).
-// 
-       fSign = (Char_t)0;
-       fPDG = (UShort_t)0;
-       fIndex = (UShort_t)0;
-       
-       fP[0] = fP[1] = fP[2] = 0.0;
-       fV[0] = fV[1] = fV[2] = 0.0;
-       fMass = 0.0;
-       
-       Int_t i;
-       for (i = 0; i < AliPID::kSPECIES; i++) {
-               fPIDwgt[i] = 0.0;
-       }
-                       
-       fLabel = -1;
-       fTruePDG = 0;
-       fMother = -1;
-       fMotherPDG = 0;
+//
 }
-//--------------------------------------------------------------------------------------------------------
-AliRsnDaughter::AliRsnDaughter(const AliRsnDaughter &copy) : TObject(copy)
+
+//_____________________________________________________________________________
+AliRsnDaughter::AliRsnDaughter(const AliRsnDaughter &copy) :
+  TObject(copy),
+  fOK(copy.fOK),
+  fLabel(copy.fLabel),
+  fMotherPDG(copy.fMotherPDG),
+  fPrec(copy.fPrec),
+  fPsim(copy.fPsim),
+  fRef(copy.fRef),
+  fRefMC(copy.fRefMC)
 {
 //
-// Copy constructor
+// Copy constructor.
+// Pointers are NOT duplicated, since they don't come from a 'new'
+// statement, but from just referencing something in the data source.
 //
-       fSign = copy.fSign;
-       fPDG = copy.fPDG;
-       fIndex = copy.fIndex;
-       
-       Int_t i;
-       for (i = 0; i < 3; i++) {
-               fP[i] = copy.fP[i];
-               fV[i] = copy.fV[i];
-       }
-       fMass = copy.fMass;
-       
-       for (i = 0; i < AliPID::kSPECIES; i++) {
-               fPIDwgt[i] = copy.fPIDwgt[i];
-       }
-               
-       fLabel = copy.fLabel;
-       fTruePDG = copy.fTruePDG;
-       fMother = copy.fMother;
-       fMotherPDG = copy.fMotherPDG;
 }
-//--------------------------------------------------------------------------------------------------------
-Bool_t AliRsnDaughter::Adopt(const AliESDtrack* esdTrack, Bool_t checkITSRefit)
+
+//_____________________________________________________________________________
+AliRsnDaughter& AliRsnDaughter::operator=(const AliRsnDaughter &copy)
 {
 //
-// Copies reconstructed data from an AliESDtrack:
+// Assignment operator.
+// Pointers are NOT duplicated, since they don't come from a 'new'
+// statement, but from just referencing something in the data source.
 //
-// - charge sign
-// - momentum
-// - point of closest approach to primary vertex
-// - ESD pid weights
-// - track label (AliESDtrack::GetLabel())
-// 
-// Makes the following checks:
+
+  fOK        = copy.fOK;
+  fLabel     = copy.fLabel;
+  fMotherPDG = copy.fMotherPDG;
+  fPrec      = copy.fPrec;
+  fPsim      = copy.fPsim;
+  fRef       = copy.fRef;
+  fRefMC     = copy.fRefMC;
+
+  return (*this);
+}
+
+//_____________________________________________________________________________
+void AliRsnDaughter::Reset()
+{
 //
-// - if argument 'checkITSRefit' is TRUE and the "ITS refit" flag is FALSE
-//   in the track, the "fIsOK" flag of (this) is set to "false" (track should be rejected)
-// - if the passed label is negative, track is considered as "fake", and 
-//   this info is kept to allow fake tracks exclusion when doing analysis
+// 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.
 //
-       // check for refit in the ITS (if requested)
-       if (checkITSRefit) {
-               if ( !(esdTrack->GetStatus() & AliESDtrack::kITSrefit) ) {
-                       return kFALSE;
-               }
-       }
-       
-       // get sign and number of species allowed for PID
-       fSign = (Char_t)esdTrack->GetSign();
-       
-       // get (and check) momentum
-       esdTrack->GetPxPyPz(fP);
-       if (fP[0] == 0.0 || fP[1] == 0.0 || fP[2] == 0.0) {
-               return kFALSE;
-       }
-       
-       // get (and check) vertex
-       esdTrack->GetXYZ(fV);
-       if (fV[0] == 0.0 || fV[1] == 0.0 || fV[2] == 0.0) {
-               return kFALSE;
-       }
-       
-       // get label 
-       // (other kinematics informations are set to default and meaningless values)
-       fLabel = esdTrack->GetLabel();
-       
-       // get PID weights
-       esdTrack->GetESDpid(fPIDwgt);
-       
-       return kTRUE;
+
+  fOK        = kFALSE;
+  fLabel     = -1;
+  fMotherPDG = 0;
+  fRef       = 0x0;
+  fRefMC     = 0x0;
+  
+  fPrec.SetXYZM(0.0, 0.0, 0.0, 0.0);
+  fPsim.SetXYZM(0.0, 0.0, 0.0, 0.0);
 }
-//--------------------------------------------------------------------------------------------------------
-Bool_t AliRsnDaughter::Adopt(TParticle* particle)
+
+//_____________________________________________________________________________
+Int_t AliRsnDaughter::GetPDG(Bool_t abs)
 {
 //
-// Copies data from a generated particle:
-// 
-// - PDG code
-// - charge sign
-// - momentum
-// - production vertex
-// - GEANT label of mother track
+// Return the PDG code of the particle from MC ref (if any).
+// If argument is kTRUE, returns its absolute value.
+//
+
+  Int_t pdg = 0;
+
+  // ESD
+  AliMCParticle *esd = GetRefMCESD();
+  if (esd) pdg = esd->Particle()->GetPdgCode();
+  
+  // AOD
+  AliAODMCParticle *aod = GetRefMCAOD();
+  if (aod) pdg = aod->GetPdgCode();
+  
+  // abs value if required
+  if (abs) pdg = TMath::Abs(pdg);
+  return pdg;
+}
+
+//_____________________________________________________________________________
+Int_t AliRsnDaughter::GetID()
+{
 //
-// When an AliRsnDaughter is copied from a TParticle, it is 
-// considered always good for analysis and never fake.
+// Return reference index, using the "GetID" method
+// of the possible source object.
+// In case of V0s, since this method is unsuccessful, return the label.
 //
-       // get particle sign form the sign of PDG code
-       Int_t pdg = particle->GetPdgCode();
-       if (TMath::Abs(pdg) < 20) {
-               if (pdg > 0) fSign = -1; else fSign = 1;
-       }
-       else if (TMath::Abs(pdg) < 3000) {
-               if (pdg > 0) fSign = 1; else fSign = -1;
-       }
-       
-       // get momentum
-       fP[0] = particle->Px();
-       fP[1] = particle->Py();
-       fP[2] = particle->Pz();
-       
-       // get vertex
-       fV[0] = particle->Vx();
-       fV[1] = particle->Vy();
-       fV[2] = particle->Vz();
-       
-       // set simulation data
-       fPDG = fTruePDG = (Short_t)particle->GetPdgCode();
-       fMother = particle->GetFirstMother();
-       fMotherPDG = 0;
-       
-       return kTRUE;
+
+  // ESD tracks
+  AliESDtrack *esd = GetRefESDtrack();
+  if (esd) return esd->GetID();
+
+  // AOD tracks
+  AliAODTrack *aod = GetRefAODtrack();
+  if (aod) return aod->GetID();
+
+  // whatever else
+  return GetLabel();
 }
-//--------------------------------------------------------------------------------------------------------
-void AliRsnDaughter::Print(Option_t *option) const
+
+//_____________________________________________________________________________
+Bool_t AliRsnDaughter::HasFlag(ULong_t flag)
 {
-// 
-// Print informations about track.
-// All options are used to add some specifical information as required:
-// "S" --> charge sign
-// "L" --> track label
-// "I" --> assigned PID (PDG code)
-// "T" --> true PDG code
-// "V" --> coordinates of track vertex
-// "P" --> coordinates of track momentum
-// "M" --> mother label
-// "N" --> mother PDG code
-// "W" --> ESD PID weights
+//
+// Checks that the 'status' flag of the source object has one or 
+// a combination of status flags specified in argument.
+// Works only with track-like objects, irrespectively if they
+// are ESD or AOD tracks, since it refers to their AliVTrack base class.
 //
 
-       TString output("Track info: ");
-       TString opt(option);
-       opt.ToUpper();
-       
-       if (opt.Contains("S")) {
-               output.Append(Form("sign = %d -- ", (Int_t)fSign));
-       }
-       if (opt.Contains("L")) {
-               output.Append(Form("label = %d -- ", fLabel));
-       }
-       if (opt.Contains("I")) {
-               output.Append(Form("PDG = %d -- ", fPDG));
-       }
-       if (opt.Contains("T")) {
-               output.Append(Form("true PDG = %d -- ", fTruePDG));
-       }
-       if (opt.Contains("V")) {
-               output.Append(Form("v = %f, %f, %f -- ", fV[0], fV[1], fV[2]));
-       }
-       if (opt.Contains("P")) {
-               output.Append(Form("p = %f, %f, %f -- ", fP[0], fP[1], fP[2]));
-       }
-       if (opt.Contains("M")) {
-               output.Append(Form("mum = %d -- ", fMother));
-       }
-       if (opt.Contains("N")) {
-               output.Append(Form("mum PDG = %d -- ", fMotherPDG));
-       }
-       if (opt.Contains("W")) {
-               output.Append(Form("PID wgts (e, mu, pi, K, p) = %f, %f, %f, %f, %f", fPIDwgt[0], fPIDwgt[1], fPIDwgt[2], fPIDwgt[3], fPIDwgt[4]));
-       }
-       
-       cout << output.Data() << endl;
+  AliVTrack *track  = dynamic_cast<AliVTrack*>(fRef);
+  if (!track) return kFALSE;
+  
+  ULong_t status = (ULong_t)track->GetStatus();
+  
+  return ((status & flag) != 0);
 }
-//--------------------------------------------------------------------------------------------------------
-AliRsnDaughter AliRsnDaughter::Sum(AliRsnDaughter t1, AliRsnDaughter t2)
+
+//_____________________________________________________________________________
+Bool_t AliRsnDaughter::SetMass(Double_t mass)
 {
 //
-// Builds a new AliRsnDaughter object with the sum of momenta of two particles.
+// Assign a mass hypothesis to the track.
+// This causes the 4-momentum data members to be initialized
+// using the momenta of referenced tracks/v0s and this mass.
+// This step is fundamental for the following of the analysis.
+// Of course, this operation is successful only if the mass is
+// a meaningful positive number, and the pointers are properly initialized.
 //
-       // create new AliRsnDaughter with default useless values for datamembers
-       AliRsnDaughter out;
-       
-       // if the summed particles are daughters of the same resonance
-       // their common mother label becomes the label of the sum
-       Int_t mum1 = t1.GetMother();
-       Int_t mum2 = t2.GetMother();
-       if (mum1 == mum2) {
-               out.SetLabel(mum1);
-               out.SetMotherPDG(t1.GetMotherPDG());
-       }
-       else {
-               out.SetLabel(-1);
-               out.SetMotherPDG(0);
-       }
 
-       // compute total 4-momentum
-       Double_t etot  = t1.GetEnergy() + t2.GetEnergy();
-       Double_t pxTot = t1.GetPx() + t2.GetPx();
-       Double_t pyTot = t1.GetPy() + t2.GetPy();
-       Double_t pzTot = t1.GetPz() + t2.GetPz();
-       Double_t mass  = TMath::Sqrt(etot*etot - pxTot*pxTot - pyTot*pyTot - pzTot*pzTot);
-       
-       //TLorentzVector v1 = track1.Get4Momentum();
-       //TLorentzVector v2 = track2.Get4Momentum();
-       //TLorentzVector sm = v1 + v2;
-       //Double_t pxTot = sum.X();
-       //Double_t pyTot = sum.Y();
-       //Double_t pzTot = sum.Z();
-       //Double_t mass = sm.M();
-       
-       out.SetPxPyPz(pxTot, pyTot, pzTot);
-       out.SetMass(mass);
-       
-       return out;
+  if (mass < 0.) return kFALSE;
+  
+  if (fRef)   fPrec.SetXYZM(fRef  ->Px(), fRef  ->Py(), fRef  ->Pz(), mass);
+  if (fRefMC) fPsim.SetXYZM(fRefMC->Px(), fRefMC->Py(), fRefMC->Pz(), mass);
+  
+  return kTRUE;
 }