Coverity
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliAODRecoDecayHF3Prong.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 /* $Id$ */
17
18 /////////////////////////////////////////////////////////////
19 //
20 // Base class for AOD reconstructed heavy-flavour 3-prong decay
21 //
22 // Author: E.Bruna bruna@to.infn.it, F.Prino prino@to.infn.it
23 /////////////////////////////////////////////////////////////
24
25 #include <TDatabasePDG.h>
26 #include "AliAODRecoDecayHF.h"
27 #include "AliAODRecoDecayHF3Prong.h"
28 #include "AliAODTrack.h"
29 #include "AliESDtrack.h"
30 #include "AliVertexerTracks.h"
31 #include "TVector3.h"
32 #include "TLorentzVector.h"
33
34 ClassImp(AliAODRecoDecayHF3Prong)
35
36 //--------------------------------------------------------------------------
37 AliAODRecoDecayHF3Prong::AliAODRecoDecayHF3Prong() :
38   AliAODRecoDecayHF(), 
39   fSigmaVert(0),
40   fDist12toPrim(0),
41   fDist23toPrim(0)
42 {
43   //
44   // Default Constructor
45   //
46 }
47 //--------------------------------------------------------------------------
48 AliAODRecoDecayHF3Prong::AliAODRecoDecayHF3Prong(AliAODVertex *vtx2,
49                                                  Double_t *px,Double_t *py,Double_t *pz,
50                                                  Double_t *d0,Double_t *d0err,
51                                                  Double_t *dca, Double_t sigvert,
52                                                  Double_t dist12,Double_t dist23,Short_t charge) :
53   AliAODRecoDecayHF(vtx2,3,charge,px,py,pz,d0,d0err),
54   fSigmaVert(sigvert),
55   fDist12toPrim(dist12),
56   fDist23toPrim(dist23)
57 {
58   //
59   // Constructor with AliAODVertex for decay vertex
60   //
61   SetDCAs(3,dca);
62 }
63 //--------------------------------------------------------------------------
64 AliAODRecoDecayHF3Prong::AliAODRecoDecayHF3Prong(AliAODVertex *vtx2,
65                                                  Double_t *d0,Double_t *d0err,
66                                                  Double_t *dca, Double_t sigvert,
67                                                  Double_t dist12,Double_t dist23, Short_t charge) :
68   AliAODRecoDecayHF(vtx2,3,charge,d0,d0err),
69   fSigmaVert(sigvert),
70   fDist12toPrim(dist12),
71   fDist23toPrim(dist23)
72 {
73   //
74   // Constructor with AliAODVertex for decay vertex and without prongs momenta
75   //
76   SetDCAs(3,dca);
77 }
78 //--------------------------------------------------------------------------
79 AliAODRecoDecayHF3Prong::AliAODRecoDecayHF3Prong(const AliAODRecoDecayHF3Prong &source) :
80   AliAODRecoDecayHF(source),
81   fSigmaVert(source.fSigmaVert),
82   fDist12toPrim(source.fDist12toPrim),
83   fDist23toPrim(source.fDist23toPrim)
84 {
85   //
86   // Copy constructor
87   //
88 }
89 //--------------------------------------------------------------------------
90 AliAODRecoDecayHF3Prong &AliAODRecoDecayHF3Prong::operator=(const AliAODRecoDecayHF3Prong &source)
91 {
92   //
93   // assignment operator
94   //
95   if(&source == this) return *this;
96
97   AliAODRecoDecayHF::operator=(source);
98
99   fDist12toPrim= source.fDist12toPrim;
100   fDist23toPrim= source.fDist23toPrim;
101   fSigmaVert= source.fSigmaVert;
102
103   return *this;
104 }
105 //--------------------------------------------------------------------------
106 Bool_t AliAODRecoDecayHF3Prong::SelectDplus(const Double_t *cuts)
107   const {
108 //
109 // This function compares the Dplus with a set of cuts:
110 //
111 // cuts[0] = inv. mass half width [GeV]   
112 // cuts[1] = pTK [GeV/c]
113 // cuts[2] = pTPi [GeV/c]
114 // cuts[3] = d0K [cm]   lower limit!
115 // cuts[4] = d0Pi [cm]  lower limit!
116 // cuts[5] = dist12 (cm)
117 // cuts[6] = sigmavert (cm)
118 // cuts[7] = dist prim-sec (cm)
119 // cuts[8] = pM=Max{pT1,pT2,pT3} (GeV/c)
120 // cuts[9] = cosThetaPoint
121 // cuts[10] = Sum d0^2 (cm^2)
122 // cuts[11] = dca cut (cm)
123 //
124 // If candidate Dplus does not pass the cuts return kFALSE
125 //
126
127   Double_t mDplusPDG = TDatabasePDG::Instance()->GetParticle(411)->Mass();
128   Double_t mDplus=InvMassDplus();
129   if(TMath::Abs(mDplus-mDplusPDG)>cuts[0])return kFALSE;
130   //single track
131   if(TMath::Abs(PtProng(1)) < cuts[1] || TMath::Abs(Getd0Prong(1))<cuts[3])return kFALSE;//Kaon
132   if(TMath::Abs(PtProng(0)) < cuts[2] || TMath::Abs(Getd0Prong(0))<cuts[4])return kFALSE;//Pion1
133   if(TMath::Abs(PtProng(2)) < cuts[2] || TMath::Abs(Getd0Prong(2))<cuts[4])return kFALSE;//Pion2
134
135   //DCA
136   for(Int_t i=0;i<3;i++) if(GetDCA(i)>cuts[11])return kFALSE;
137
138   //2track cuts
139   if(fDist12toPrim<cuts[5] || fDist23toPrim<cuts[5])return kFALSE;
140   if(Getd0Prong(0)*Getd0Prong(1)<0. && Getd0Prong(2)*Getd0Prong(1)<0.)return kFALSE;
141
142   //sec vert
143   if(fSigmaVert>cuts[6])return kFALSE;
144
145   if(DecayLength()<cuts[7])return kFALSE;
146
147   if(TMath::Abs(PtProng(0))<cuts[8] && TMath::Abs(PtProng(1))<cuts[8] && TMath::Abs(PtProng(2))<cuts[8])return kFALSE;
148   if(CosPointingAngle()   < cuts[9])return kFALSE;
149   Double_t sum2=Getd0Prong(0)*Getd0Prong(0)+Getd0Prong(1)*Getd0Prong(1)+Getd0Prong(2)*Getd0Prong(2);
150   if(sum2<cuts[10])return kFALSE;
151   return kTRUE;
152 }
153 //--------------------------------------------------------------------------
154 Bool_t AliAODRecoDecayHF3Prong::SelectDs(const Double_t *cuts,Int_t &okDsKKpi,Int_t &okDspiKK, Int_t &okMassPhi, Int_t &okMassK0star)
155   const {
156 //
157 // This function compares the Ds with a set of cuts 
158 // (same variables as D+, for now)
159 //
160 // cuts[0] = inv. mass half width [GeV]   
161 // cuts[1] = pTK [GeV/c]
162 // cuts[2] = pTPi [GeV/c]
163 // cuts[3] = d0K [cm]   lower limit!
164 // cuts[4] = d0Pi [cm]  lower limit!
165 // cuts[5] = dist12 (cm)
166 // cuts[6] = sigmavert (cm)
167 // cuts[7] = dist prim-sec (cm)
168 // cuts[8] = pM=Max{pT1,pT2,pT3} (GeV/c)
169 // cuts[9] = cosThetaPoint
170 // cuts[10] = Sum d0^2 (cm^2)
171 // cuts[11] = dca cut (cm)
172 // cuts[12] = max. inv. mass difference(Mphi-MKK) [GeV] 
173 // cuts[13] = max. inv. mass difference(MK0*-MKpi) [GeV] 
174 //
175 // If candidate Ds does not pass the cuts return kFALSE
176 //
177   Double_t mDsKKpi,mDspiKK;
178   okDsKKpi=1; okDspiKK=1;
179   okMassPhi=0; okMassK0star=0;
180
181   Double_t mDsPDG = TDatabasePDG::Instance()->GetParticle(431)->Mass();
182
183   mDsKKpi=InvMassDsKKpi();
184   mDspiKK=InvMassDspiKK();
185
186   if(TMath::Abs(mDsKKpi-mDsPDG)>cuts[0]) okDsKKpi = 0;
187   if(TMath::Abs(mDspiKK-mDsPDG)>cuts[0]) okDspiKK = 0;
188   if(!okDsKKpi && !okDspiKK) return kFALSE;
189
190   //single track
191   if(TMath::Abs(PtProng(0)) < cuts[1] || TMath::Abs(Getd0Prong(0))<cuts[3])return kFALSE;//Kaon1
192   if(TMath::Abs(PtProng(1)) < cuts[1] || TMath::Abs(Getd0Prong(1))<cuts[3])return kFALSE;//Kaon2
193   if(TMath::Abs(PtProng(2)) < cuts[2] || TMath::Abs(Getd0Prong(2))<cuts[4])return kFALSE;//Pion
194
195   // cuts on resonant decays (via Phi or K0*)
196   Double_t mPhiPDG = TDatabasePDG::Instance()->GetParticle(333)->Mass();
197   Double_t mK0starPDG = TDatabasePDG::Instance()->GetParticle(313)->Mass();
198   if(okDsKKpi){
199     Double_t mass01phi=InvMass2Prongs(0,1,321,321);
200     Double_t mass12K0s=InvMass2Prongs(1,2,321,211);
201     if(TMath::Abs(mass01phi-mPhiPDG)<cuts[12]) okMassPhi=1;
202     if(TMath::Abs(mass12K0s-mK0starPDG)<cuts[13]) okMassK0star = 1;
203     if(!okMassPhi && !okMassK0star) okDsKKpi=kFALSE;
204   }
205   if(okDspiKK){
206     Double_t mass01K0s=InvMass2Prongs(0,1,211,321);
207     Double_t mass12phi=InvMass2Prongs(1,2,321,321);
208     if(TMath::Abs(mass01K0s-mK0starPDG)<cuts[13]) okMassK0star = 1;
209     if(TMath::Abs(mass12phi-mPhiPDG)<cuts[12]) okMassPhi=1;
210     if(!okMassPhi && !okMassK0star) okDspiKK=kFALSE;
211   }
212   if(!okDsKKpi && !okDspiKK) return kFALSE;
213
214
215
216   
217   //DCA
218   for(Int_t i=0;i<3;i++) if(GetDCA(i)>cuts[11])return kFALSE;
219
220   //2track cuts
221   if(fDist12toPrim<cuts[5] || fDist23toPrim<cuts[5])return kFALSE;
222
223   //sec vert
224   if(fSigmaVert>cuts[6])return kFALSE;
225
226   if(DecayLength()<cuts[7])return kFALSE;
227
228   if(TMath::Abs(PtProng(0))<cuts[8] && TMath::Abs(PtProng(1))<cuts[8] && TMath::Abs(PtProng(2))<cuts[8])return kFALSE;
229   if(CosPointingAngle()   < cuts[9])return kFALSE;
230   Double_t sum2=Getd0Prong(0)*Getd0Prong(0)+Getd0Prong(1)*Getd0Prong(1)+Getd0Prong(2)*Getd0Prong(2);
231   if(sum2<cuts[10])return kFALSE;
232
233   return kTRUE;
234 }
235 //--------------------------------------------------------------------------
236 Bool_t AliAODRecoDecayHF3Prong::SelectLc(const Double_t *cuts,Int_t &okLcpKpi,Int_t &okLcpiKp)
237   const {
238 //
239 // This function compares the Lc with a set of cuts 
240 // (same variables as D+, for now)
241 //
242 // cuts[0] = inv. mass half width [GeV]   
243 // cuts[1] = pTP [GeV/c]
244 // cuts[2] = pTPi and pTK [GeV/c]
245 // cuts[3] = d0P [cm]   lower limit!
246 // cuts[4] = d0Pi and d0K [cm]  lower limit!
247 // cuts[5] = dist12 (cm)
248 // cuts[6] = sigmavert (cm)
249 // cuts[7] = dist prim-sec (cm)
250 // cuts[8] = pM=Max{pT1,pT2,pT3} (GeV/c)
251 // cuts[9] = cosThetaPoint
252 // cuts[10] = Sum d0^2 (cm^2)
253 // cuts[11] = dca cut (cm)
254 //
255 // If candidate Lc does not pass the cuts return kFALSE
256 //
257   Double_t mLcpKpi,mLcpiKp;
258   okLcpKpi=1; okLcpiKp=1;
259
260   Double_t mLcPDG = TDatabasePDG::Instance()->GetParticle(4122)->Mass();
261
262   mLcpKpi=InvMassLcpKpi();
263   mLcpiKp=InvMassLcpiKp();
264
265   if(TMath::Abs(mLcpKpi-mLcPDG)>cuts[0]) okLcpKpi = 0;
266   if(TMath::Abs(mLcpiKp-mLcPDG)>cuts[0]) okLcpiKp = 0;
267   if(!okLcpKpi && !okLcpiKp) return kFALSE;
268
269   //single track
270   if(TMath::Abs(PtProng(0)) < cuts[1] || TMath::Abs(Getd0Prong(0))<cuts[3])return kFALSE;//Proton
271   if(TMath::Abs(PtProng(1)) < cuts[2] || TMath::Abs(Getd0Prong(1))<cuts[4])return kFALSE;//Kaon
272   if(TMath::Abs(PtProng(2)) < cuts[2] || TMath::Abs(Getd0Prong(2))<cuts[4])return kFALSE;//Pion
273
274   //DCA
275   for(Int_t i=0;i<3;i++) if(GetDCA(i)>cuts[11])return kFALSE;
276
277   //2track cuts
278   if(fDist12toPrim<cuts[5] || fDist23toPrim<cuts[5])return kFALSE;
279   if(Getd0Prong(0)*Getd0Prong(1)<0. && Getd0Prong(2)*Getd0Prong(1)<0.)return kFALSE;
280
281   //sec vert
282   if(fSigmaVert>cuts[6])return kFALSE;
283
284   if(DecayLength()<cuts[7])return kFALSE;
285
286   if(TMath::Abs(PtProng(0))<cuts[8] && TMath::Abs(PtProng(1))<cuts[8] && TMath::Abs(PtProng(2))<cuts[8])return kFALSE;
287   if(CosPointingAngle()   < cuts[9])return kFALSE;
288   Double_t sum2=Getd0Prong(0)*Getd0Prong(0)+Getd0Prong(1)*Getd0Prong(1)+Getd0Prong(2)*Getd0Prong(2);
289   if(sum2<cuts[10])return kFALSE;
290
291   return kTRUE;
292 }
293
294
295 //----------------------------------------------------------------------
296 Double_t AliAODRecoDecayHF3Prong::CosPiKPhiRFrame(Int_t option)
297 const {
298   // computes cosine of angle between pi and K in the phi rest frame
299
300  Int_t indexPi;
301  Int_t indexK1;
302  Int_t indexK2;
303
304   if (option==0){ //KKpi
305     indexPi=2;
306     indexK1=0;
307     indexK2=1;
308   }else{   //piKK
309     indexPi=0;
310     indexK1=1;
311     indexK2=2;
312   }
313           
314   Double_t ePhi=EProng(indexK1,321)+EProng(indexK2,321);
315   Double_t pxPhi=PxProng(indexK1)+PxProng(indexK2);
316   Double_t pyPhi=PyProng(indexK1)+PyProng(indexK2);
317   Double_t pzPhi=PzProng(indexK1)+PzProng(indexK2);
318   Double_t bxPhi=pxPhi/ePhi;
319   Double_t byPhi=pyPhi/ePhi;
320   Double_t bzPhi=pzPhi/ePhi;
321  
322   TVector3 vecK1Phiframe;
323   TLorentzVector* vecK1=new TLorentzVector(PxProng(indexK1),PyProng(indexK1),PzProng(indexK1),EProng(indexK1,321));
324   vecK1->Boost(-bxPhi,-byPhi,-bzPhi);                                          
325   vecK1->Boost(vecK1Phiframe); 
326   vecK1Phiframe=vecK1->BoostVector();   
327     
328   TVector3 vecPiPhiframe;
329   TLorentzVector* vecPi=new TLorentzVector(PxProng(indexPi),PyProng(indexPi),PzProng(indexPi),EProng(indexPi,211));
330   vecPi->Boost(-bxPhi,-byPhi,-bzPhi);                                         
331   vecPi->Boost(vecPiPhiframe); 
332   vecPiPhiframe=vecPi->BoostVector();   
333                                                              
334   Double_t innera=vecPiPhiframe.Dot(vecK1Phiframe);
335   Double_t norm1a=TMath::Sqrt(vecPiPhiframe.Dot(vecPiPhiframe));
336   Double_t norm2a=TMath::Sqrt(vecK1Phiframe.Dot(vecK1Phiframe));
337   Double_t cosK1PhiFrame=innera/(norm1a*norm2a);                                                      
338
339   return cosK1PhiFrame;
340
341 }
342
343 //----------------------------------------------------------------------
344 Double_t AliAODRecoDecayHF3Prong::CosPiDsLabFrame(Int_t option)
345 const {
346   // computes cosine of angle between pi and Ds in the Ds rest frame
347
348  Int_t indexPi;
349
350   if (option==0){ //KKpi
351     indexPi=2;
352   }else{ //piKK
353     indexPi=0;
354   }
355
356  
357   Double_t bxD=Px()/E(431);
358   Double_t byD=Py()/E(431);
359   Double_t bzD=Pz()/E(431);
360
361   TVector3 piDsframe;
362   TLorentzVector* vecPi=new TLorentzVector(PxProng(indexPi),PyProng(indexPi),PzProng(indexPi),EProng(indexPi,211));  
363   vecPi->Boost(-bxD,-byD,-bzD);                                                
364   vecPi->Boost(piDsframe); 
365   piDsframe=vecPi->BoostVector();   
366  
367   TVector3 vecDs(Px(),Py(),Pz());
368       
369   Double_t inner=vecDs.Dot(piDsframe);
370   Double_t norm1=TMath::Sqrt(vecDs.Dot(vecDs));
371   Double_t norm2=TMath::Sqrt(piDsframe.Dot(piDsframe));
372   Double_t cosPiDsFrame=inner/(norm1*norm2);    
373  
374
375   return cosPiDsFrame;
376
377 }
378
379 //----------------------------------------------------------------------
380 Double_t AliAODRecoDecayHF3Prong::ComputeSigmaVert(AliAODEvent* aod) const{
381   // computes track dispersion around secondary vertex starting from tracks
382
383   AliVertexerTracks vertexer(aod->GetMagneticField());
384   Double_t pos[3],cov[6];
385   AliAODVertex* aodV=aod->GetPrimaryVertex();
386   aodV->GetXYZ(pos);
387   aodV->GetCovarianceMatrix(cov);
388   Double_t chi2=aodV->GetChi2();
389   Int_t nC=aodV->GetNContributors();
390   AliESDVertex vprim(pos,cov,chi2,nC);
391   vertexer.SetVtxStart(&vprim);
392   TObjArray threeTrackArray(3);
393
394   for(Int_t iDau=0; iDau<GetNDaughters(); iDau++){
395     AliVTrack* at=(AliVTrack*)GetDaughter(iDau);
396     threeTrackArray.AddAt(new AliESDtrack(at),iDau);
397   }
398
399   AliESDVertex* secVert=vertexer.VertexForSelectedESDTracks(&threeTrackArray,kFALSE,kTRUE,kFALSE);
400   Double_t disp=secVert->GetDispersion();
401   
402   threeTrackArray.Delete();
403   delete secVert;
404   return disp;
405   
406 }