ROOT logo
#ifndef ALIAODVERTEX_H
#define ALIAODVERTEX_H
/* Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
 * See cxx source for full Copyright notice                               */

/* $Id$ */

//-------------------------------------------------------------------------
//     AOD vertex base class
//     Author: Markus Oldenburg, CERN
//     Inheritance from AliVVertex: A. Dainese
//-------------------------------------------------------------------------

#include <TRef.h>
#include <TRefArray.h>
#include <TMath.h>

#include "AliVVertex.h"
#include "AliAODRedCov.h"
#include "AliLog.h"

class AliAODVertex : public AliVVertex {

 public :

  enum AODVtx_t {kUndef=-1, kPrimary, kKink, kV0, kCascade, kMulti, kMainSPD, kPileupSPD, kPileupTracks,kMainTPC};

  AliAODVertex();
  AliAODVertex(const Double_t *position, 
	       const Double_t *covMatrix=0x0,
	       Double_t chi2perNDF = -999.,
	       TObject *parent = 0x0,
	       Short_t id=-1,
	       Char_t vtype=kUndef,
	       Int_t nprong = 0);
  AliAODVertex(const Float_t *position, 
	       const Float_t *covMatrix=0x0,
	       Double_t chi2perNDF = -999.,
	       TObject *parent = 0x0,
	       Short_t id=-1,
	       Char_t vtype=kUndef,
	       Int_t nprong = 0);
    AliAODVertex(const Double_t *position, 
		 Double_t chi2perNDF,
		 Char_t vtype=kUndef,
		 Int_t nprong = 0);
    AliAODVertex(const Float_t *position, 
		 Double_t chi2perNDF,
		 Char_t vtype=kUndef,
		 Int_t nprong = 0);

  virtual ~AliAODVertex();
  AliAODVertex(const AliAODVertex& vtx); 
  AliAODVertex& operator=(const AliAODVertex& vtx);

  virtual AliAODVertex* CloneWithoutRefs() const;
  
  void     SetX(Double_t x) { fPosition[0] = x; }
  void     SetY(Double_t y) { fPosition[1] = y; }
  void     SetZ(Double_t z) { fPosition[2] = z; }
  void     SetPosition(Double_t x, Double_t y, Double_t z) { fPosition[0] = x; fPosition[1] = y; fPosition[2] = z; }
  template <class T> void SetPosition(T *pos)
    { fPosition[0] = pos[0]; fPosition[1] = pos[1]; fPosition[2] = pos[2]; }

  void     SetChi2perNDF(Double_t chi2perNDF) { fChi2perNDF = chi2perNDF; }

  void     SetParent(TObject *parent) { fParent = parent; }

  Double_t GetX() const { return fPosition[0]; }
  Double_t GetY() const { return fPosition[1]; }
  Double_t GetZ() const { return fPosition[2]; }
  void     GetXYZ(Double_t position[3]) const 
    {position[0]=fPosition[0]; position[1]=fPosition[1]; position[2]=fPosition[2];}
  template <class T> void GetPosition(T *pos) const
    {pos[0]=fPosition[0]; pos[1]=fPosition[1]; pos[2]=fPosition[2];}

  template <class T> void SetCovMatrix(const T *covMatrix) {
    if(!fCovMatrix) fCovMatrix=new AliAODRedCov<3>();
    fCovMatrix->SetCovMatrix(covMatrix);}

  template <class T> Bool_t GetCovMatrix(T *covMatrix) const {
    if(!fCovMatrix) return kFALSE;
    fCovMatrix->GetCovMatrix(covMatrix); return kTRUE;}

  void GetCovarianceMatrix(Double_t covmatrix[6]) const 
                    {GetCovMatrix(covmatrix);}
  void RemoveCovMatrix() {delete fCovMatrix; fCovMatrix=NULL;}

  template <class T> void     GetSigmaXYZ(T *sigma) const;

  Double_t GetChi2perNDF() const { return fChi2perNDF; }
  Double_t GetChi2() const { return fChi2perNDF*(Double_t)GetNDF(); }
  Int_t    GetNDF() const { return 2*GetNContributors()-3; }

  Short_t  GetID() const { return fID; }
  void     SetID(Short_t id) { fID=id; }

  Char_t   GetType() const { return fType; }
  void     SetType(AODVtx_t vtype) { fType=vtype; }

  TObject* GetParent() const   { return fParent.GetObject(); }
  Bool_t   HasParent(TObject *parent) const { return (fParent.GetObject() == parent) ? kTRUE : kFALSE; }

  void     AddDaughter(TObject *daughter);
  void     RemoveDaughter(TObject *daughter) { fDaughters.Remove(daughter); }
  void     RemoveDaughters() { fDaughters.Clear(); if(fProngs) {delete [] fProngs; fProngs=0; MakeProngs(); fIprong=0;} }
  TObject* GetDaughter(Int_t i); 
  Bool_t   HasDaughter(TObject *daughter) const;
  Int_t    GetNDaughters() const;
  Int_t    GetNContributors() const;
  void     SetNContributors(Int_t nc) {fNContributors = nc;}
  // covariance matrix elements after rotation by phi around z-axis 
  // and, then, by theta around new y-axis
  Double_t  RotatedCovMatrixXX(Double_t phi = 0., Double_t theta = 0.) const;
  Double_t  RotatedCovMatrixXY(Double_t phi = 0., Double_t theta = 0.) const;
  Double_t  RotatedCovMatrixYY(Double_t phi = 0.) const;
  Double_t  RotatedCovMatrixXZ(Double_t phi = 0., Double_t theta = 0.) const;
  Double_t  RotatedCovMatrixYZ(Double_t phi = 0., Double_t theta = 0.) const;
  Double_t  RotatedCovMatrixZZ(Double_t phi = 0., Double_t theta = 0.) const;

  template <class T, class P> void     PhiAndThetaToVertex(AliAODVertex *vtx, P &phi, T &theta) const;
  Double_t  Distance2ToVertex(const AliAODVertex *vtx) const;
  Double_t  DistanceToVertex(AliAODVertex *vtx) const 
     {return TMath::Sqrt(Distance2ToVertex(vtx));}
  Double_t  DistanceXY2ToVertex(const AliAODVertex *vtx) const;
  Double_t  DistanceXYToVertex(AliAODVertex *vtx) const 
     {return TMath::Sqrt(DistanceXY2ToVertex(vtx));}
  Double_t  Error2DistanceToVertex(AliAODVertex *vtx) const;
  Double_t  ErrorDistanceToVertex(AliAODVertex *vtx) const
     {return TMath::Sqrt(Error2DistanceToVertex(vtx));}
  Double_t  Error2DistanceXYToVertex(AliAODVertex *vtx) const;
  Double_t  ErrorDistanceXYToVertex(AliAODVertex *vtx) const
     {return TMath::Sqrt(Error2DistanceXYToVertex(vtx));}
  
  void     PrintIndices() const;
  void     Print(Option_t* option = "") const;

  const char* AsString() const;
  
  static const char* GetTypeName(AODVtx_t type);
  void     SetBC(Int_t bc)               {fBCID = bc;}
  Int_t    GetBC()              const    {return fBCID;}  
private:
  void     MakeProngs() {if (fNprong > 0) {fProngs = new TRef[fNprong]; fIprong=0;}}
	  
 private:

  Double32_t      fPosition[3];   // vertex position
  Double32_t      fChi2perNDF;    // chi2/NDF of vertex fit
  Short_t         fID;            // vertex ID; corresponds to the array index of the appropriate ESD container
  Char_t          fBCID;          // BC ID assigned to vertex
  Char_t          fType;          // vertex type
  Int_t           fNprong;        // number of prongs
  Int_t           fIprong;        //!index  of prong
  Int_t           fNContributors; // Number of contributors for SPD vertex
  AliAODRedCov<3> *fCovMatrix;    // vertex covariance matrix; values of and below the diagonal
  TRef            fParent;        // reference to the parent particle
  TRefArray       fDaughters;     // references to the daughter particles
  TRef            *fProngs;       //[fNprong] alternative daughters for n-prong vertex
  
  ClassDef(AliAODVertex, 8);
};

inline  Int_t AliAODVertex::GetNDaughters() const
{
    if (!fProngs) {
	return fDaughters.GetEntriesFast();
    } else {
	return fNprong;
    }
}

inline TObject* AliAODVertex::GetDaughter(Int_t i)
{
    if (!fProngs) {
	return fDaughters.At(i);
    } else {
	if (i < fNprong) {
	    return fProngs[i].GetObject();
	} else {
	    AliWarning("Daughter index out of range !\n");
	    return 0;
	}
    }
}

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