51fdbcbc3fd120c68a66b85901ad013079e9a530
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliAODRecoDecayHF.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2006, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /////////////////////////////////////////////////////////////
17 //
18 // Base class for AOD reconstructed heavy-flavour decay
19 //
20 // Author: A.Dainese, andrea.dainese@lnl.infn.it
21 /////////////////////////////////////////////////////////////
22
23 #include <TDatabasePDG.h>
24 #include <TVector3.h>
25 #include "AliAODRecoDecay.h"
26 #include "AliAODRecoDecayHF.h"
27 #include "AliKFVertex.h"
28 #include "AliVVertex.h"
29 #include "AliESDVertex.h"
30
31 ClassImp(AliAODRecoDecayHF)
32
33 //--------------------------------------------------------------------------
34 AliAODRecoDecayHF::AliAODRecoDecayHF() :
35   AliAODRecoDecay(),
36   fOwnPrimaryVtx(0x0),
37   fEventPrimaryVtx(),
38   fd0err(0x0), 
39   fProngID(0x0) 
40 {
41   //
42   // Default Constructor
43   //
44 }
45 //--------------------------------------------------------------------------
46 AliAODRecoDecayHF::AliAODRecoDecayHF(AliAODVertex *vtx2,Int_t nprongs,Short_t charge,
47                                      Double_t *px,Double_t *py,Double_t *pz,
48                                      Double_t *d0,Double_t *d0err) :
49   AliAODRecoDecay(vtx2,nprongs,charge,px,py,pz,d0),
50   fOwnPrimaryVtx(0x0),
51   fEventPrimaryVtx(),
52   fd0err(0x0),
53   fProngID(0x0) 
54 {
55   //
56   // Constructor with AliAODVertex for decay vertex
57   //
58   fd0err = new Double_t[GetNProngs()];
59   for(Int_t i=0; i<GetNProngs(); i++) fd0err[i] = d0err[i];
60 }
61 //--------------------------------------------------------------------------
62 AliAODRecoDecayHF::AliAODRecoDecayHF(AliAODVertex *vtx2,Int_t nprongs,Short_t charge,
63                                      Double_t *d0,Double_t *d0err) :
64   AliAODRecoDecay(vtx2,nprongs,charge,d0),
65   fOwnPrimaryVtx(0x0),
66   fEventPrimaryVtx(),
67   fd0err(0x0),
68   fProngID(0x0) 
69 {
70   //
71   // Constructor with AliAODVertex for decay vertex and without prongs momenta
72   //
73   fd0err = new Double_t[GetNProngs()];
74   for(Int_t i=0; i<GetNProngs(); i++) fd0err[i] = d0err[i];
75 }
76 //--------------------------------------------------------------------------
77 AliAODRecoDecayHF::AliAODRecoDecayHF(Double_t vtx1[3],Double_t vtx2[3],
78                                      Int_t nprongs,Short_t charge,
79                                      Double_t *px,Double_t *py,Double_t *pz,
80                                      Double_t *d0) :
81   AliAODRecoDecay(0x0,nprongs,charge,px,py,pz,d0),
82   fOwnPrimaryVtx(0x0),
83   fEventPrimaryVtx(),
84   fd0err(0x0),
85   fProngID(0x0) 
86 {
87   //
88   // Constructor that can used for a "MC" object
89   //
90
91   fOwnPrimaryVtx = new AliAODVertex(vtx1);
92
93   AliAODVertex *vtx = new AliAODVertex(vtx2);
94   SetOwnSecondaryVtx(vtx);
95
96 }
97 //--------------------------------------------------------------------------
98 AliAODRecoDecayHF::AliAODRecoDecayHF(const AliAODRecoDecayHF &source) :
99   AliAODRecoDecay(source),
100   fOwnPrimaryVtx(0x0),
101   fEventPrimaryVtx(source.fEventPrimaryVtx),
102   fd0err(0x0),
103   fProngID(0x0)
104 {
105   //
106   // Copy constructor
107   //
108   if(source.GetOwnPrimaryVtx()) fOwnPrimaryVtx = new AliAODVertex(*(source.GetOwnPrimaryVtx()));
109
110   if(source.GetNProngs()>0) {
111     fd0err = new Double_t[GetNProngs()];
112     memcpy(fd0err,source.fd0err,GetNProngs()*sizeof(Double_t));
113     if(source.fProngID) {
114       fProngID = new UShort_t[GetNProngs()];
115       memcpy(fProngID,source.fProngID,GetNProngs()*sizeof(UShort_t));
116     }
117   }
118 }
119 //--------------------------------------------------------------------------
120 AliAODRecoDecayHF &AliAODRecoDecayHF::operator=(const AliAODRecoDecayHF &source)
121 {
122   //
123   // assignment operator
124   //
125   if(&source == this) return *this;
126
127   AliAODRecoDecay::operator=(source);
128
129   fEventPrimaryVtx = source.fEventPrimaryVtx;
130
131   if(source.GetOwnPrimaryVtx()) fOwnPrimaryVtx = new AliAODVertex(*(source.GetOwnPrimaryVtx()));
132
133   if(source.GetNProngs()>0) {
134     fd0err = new Double_t[GetNProngs()];
135     memcpy(fd0err,source.fd0err,GetNProngs()*sizeof(Double_t));
136     if(source.fProngID) {
137       fProngID = new UShort_t[GetNProngs()];
138       memcpy(fProngID,source.fProngID,GetNProngs()*sizeof(UShort_t));
139     }
140   }
141   return *this;
142 }
143 //--------------------------------------------------------------------------
144 AliAODRecoDecayHF::~AliAODRecoDecayHF() {
145   //  
146   // Default Destructor
147   //
148   if(fOwnPrimaryVtx) delete fOwnPrimaryVtx;
149   if(fd0err) delete [] fd0err;
150   if(fProngID) delete [] fProngID;
151 }
152 //---------------------------------------------------------------------------
153 AliKFParticle *AliAODRecoDecayHF::ApplyVertexingKF(Int_t *iprongs,Int_t nprongs,Int_t *pdgs,Bool_t topoCostraint, Double_t bzkG, Double_t *mass) const {
154   //
155   // Applies the KF vertexer 
156   // Int_t iprongs[nprongs] = indices of the prongs to be used from the vertexer
157   // Int_t pdgs[nprongs] = pdgs assigned to the prongs, needed to define the AliKFParticle
158   // Bool_t topoCostraint = if kTRUE, the topological constraint is applied
159   // Double_t bzkG = magnetic field
160   // Double_t mass[2] = {mass, sigma} for the mass constraint (if mass[0]>0 the constraint is applied).
161   //
162
163   AliKFParticle::SetField(bzkG);
164   AliKFParticle *vertexKF=0;
165   
166   AliKFVertex copyKF;
167   Int_t nt=0,ntcheck=0;
168
169   Double_t pos[3]={0.,0.,0.};
170   if(!fOwnPrimaryVtx) {
171     printf("AliAODRecoDecayHF::ApplyVertexingKF(): cannot apply because primary vertex is not found\n");
172     return vertexKF;
173   }
174   fOwnPrimaryVtx->GetXYZ(pos);
175   Int_t contr=fOwnPrimaryVtx->GetNContributors();
176   Double_t covmatrix[6]={0.,0.,0.,0.,0.,0.};
177   fOwnPrimaryVtx->GetCovarianceMatrix(covmatrix);
178   Double_t chi2=fOwnPrimaryVtx->GetChi2();
179   AliESDVertex primaryVtx2(pos,covmatrix,chi2,contr,"Vertex");
180  
181
182   if(topoCostraint){
183    copyKF=AliKFVertex(primaryVtx2);
184    nt=primaryVtx2.GetNContributors();
185    ntcheck=nt;
186   }
187
188   vertexKF = new AliKFParticle();
189   for(Int_t i= 0;i<nprongs;i++){
190     Int_t ipr=iprongs[i];
191     AliAODTrack *aodTrack = (AliAODTrack*)GetDaughter(ipr);
192     if(!aodTrack) {
193       printf("AliAODRecoDecayHF::ApplyVertexingKF(): no daughters available\n");
194       delete vertexKF; vertexKF=NULL;
195       return vertexKF;
196     }
197     AliKFParticle daughterKF(*aodTrack,pdgs[i]);
198     vertexKF->AddDaughter(daughterKF);
199     
200     if(topoCostraint && nt>0){
201       //Int_t index=(Int_t)GetProngID(ipr);
202       if(!aodTrack->GetUsedForPrimVtxFit()) continue;
203       copyKF -= daughterKF;
204       ntcheck--;
205     }
206   }
207   
208   if(topoCostraint){
209     if(ntcheck>0) {
210       copyKF += (*vertexKF);
211       vertexKF->SetProductionVertex(copyKF);
212     }
213  }
214   
215   if(mass[0]>0.){
216     vertexKF->SetMassConstraint(mass[0],mass[1]);
217   }
218   
219   return vertexKF;
220 }