]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODRecoDecay.h
Faster inv. mass selection (no sqrt)
[u/mrichter/AliRoot.git] / STEER / AliAODRecoDecay.h
1 #ifndef ALIAODRECODECAY_H
2 #define ALIAODRECODECAY_H
3 /* Copyright(c) 1998-2006, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 //***********************************************************
7 // Class AliAODRecoDecay
8 // base class for AOD reconstructed decays
9 // Author: A.Dainese, andrea.dainese@lnl.infn.it
10 //***********************************************************
11
12 #include <TMath.h>
13 #include <TRef.h>
14 #include <TClonesArray.h>
15 #include "AliAODVertex.h"
16 #include "AliAODTrack.h"
17 #include "AliVTrack.h"
18
19 class AliVVertex;
20
21 class AliAODRecoDecay : public AliVTrack {
22
23  public:
24
25   AliAODRecoDecay();
26   AliAODRecoDecay(AliAODVertex *vtx2,Int_t nprongs,Short_t charge,
27                   Double_t *px,Double_t *py,Double_t *pz,
28                   Double_t *d0);
29   AliAODRecoDecay(AliAODVertex *vtx2,Int_t nprongs,Short_t charge,
30                   Double_t *d0);
31   virtual ~AliAODRecoDecay();
32
33   AliAODRecoDecay(const AliAODRecoDecay& source);
34   AliAODRecoDecay& operator=(const AliAODRecoDecay& source); 
35    
36
37   // decay vertex
38   Double_t GetSecVtxX() const {return GetSecondaryVtx()->GetX();}
39   Double_t GetSecVtxY() const {return GetSecondaryVtx()->GetY();}
40   Double_t GetSecVtxZ() const {return GetSecondaryVtx()->GetZ();}
41   Double_t RadiusSecVtx() const;
42   void     SetSecondaryVtx(AliAODVertex *vtx2) {fSecondaryVtx=vtx2;}
43   AliAODVertex* GetSecondaryVtx() const { return (((AliAODVertex*)fSecondaryVtx.GetObject()) ? (AliAODVertex*)fSecondaryVtx.GetObject() : GetOwnSecondaryVtx()); }
44   void     SetOwnSecondaryVtx(AliAODVertex *vtx2) {fOwnSecondaryVtx=vtx2;}
45   AliAODVertex* GetOwnSecondaryVtx() const {return fOwnSecondaryVtx;}
46   void     GetSecondaryVtx(Double_t vtx[3]) const;
47   Double_t GetReducedChi2() const {return GetSecondaryVtx()->GetChi2perNDF();}
48   Short_t  Charge() const {return fCharge;}
49   Short_t  GetCharge() const {return fCharge;}
50   void     SetCharge(Short_t charge=0) {fCharge=charge;}
51
52   // Match to MC signal:
53   // check if this candidate is matched to a MC signal
54   // If no, return -1
55   // If yes, return label (>=0) of the AliAODMCParticle
56   // if ndgCk>0, checks also daughters PDGs
57   Int_t    MatchToMC(Int_t pdgabs,TClonesArray *mcArray,Int_t ndgCk=0,Int_t *pdgDg=0) const;
58
59   // PID
60   void      SetPID(Int_t nprongs,Double_t *pid);
61   Double_t *GetPID() const { return fPID; }
62   void      GetPIDProng(Int_t ip,Double_t *pid) const;
63   virtual const Double_t *PID() const { return fPID; }
64
65   // prong-to-prong DCAs
66   void    SetDCAs(Int_t nDCA,Double_t *dca);
67   void    SetDCA(Double_t dca); // 2 prong
68   Double_t GetDCA(Int_t i=0) const {return fDCA[i];}
69
70   //event and run number
71   void SetEventRunNumbers(Int_t en,Int_t rn) 
72     { fEventNumber=en; fRunNumber=rn; return; }
73   Int_t GetEventNumber() const { return fEventNumber; }
74   Int_t GetRunNumber() const { return fRunNumber; }
75
76   // methods of AliVTrack
77   virtual Int_t    GetID() const { return -1; }
78   virtual UChar_t  GetITSClusterMap() const;
79   virtual ULong_t  GetStatus() const;
80   virtual Bool_t   GetXYZ(Double_t *p) const { return XvYvZv(p); }
81   virtual Bool_t   GetCovarianceXYZPxPyPz(Double_t cv[21]) const;
82   virtual Bool_t   PropagateToDCA(const AliVVertex* vtx,Double_t b,Double_t maxd,Double_t dz[2],Double_t covar[3]);
83
84   // kinematics & topology
85   Double_t Px() const; 
86   Double_t Py() const;
87   Double_t Pz() const;
88   Double_t P2() const {return Px()*Px()+Py()*Py()+Pz()*Pz();}
89   Double_t Pt2() const {return Px()*Px()+Py()*Py();}
90   Double_t P() const {return TMath::Sqrt(Pt2());}
91   Double_t Pt() const {return TMath::Sqrt(P2());}
92   Double_t OneOverPt() const {return (Pt() ? 1./Pt() : 0.);}
93   Bool_t   PxPyPz(Double_t p[3]) const { p[0] = Px(); p[1] = Py(); p[2] = Pz(); return kTRUE; }
94   Double_t Phi() const {return TMath::Pi()+TMath::ATan2(-Py(),-Px());}
95   Double_t Theta() const {return 0.5*TMath::Pi()-TMath::ATan(Pz()/(Pt()+1.e-13));}
96   Double_t Eta() const {return 0.5*TMath::Log((P()+Pz())/(P()-Pz()+1.e-13));}
97   Double_t Xv() const { return GetSecVtxX(); }
98   Double_t Yv() const { return GetSecVtxY(); }
99   Double_t Zv() const { return GetSecVtxZ(); }
100   virtual Bool_t   XvYvZv(Double_t x[3]) const { x[0] = Xv(); x[1] = Yv(); x[2] = Zv(); return kTRUE; }
101   Double_t E2(UInt_t pdg) const;
102   Double_t E(UInt_t pdg) const {return TMath::Sqrt(E2(pdg));}
103   Double_t Y(UInt_t pdg) const {Double_t e=E(pdg); return 0.5*TMath::Log((e+Pz())/(e-Pz()+1.e-13));}
104   Double_t DecayLength2(Double_t point[3]) const;
105   Double_t DecayLength(Double_t point[3]) const {return TMath::Sqrt(DecayLength2(point));}
106   Double_t DecayLength2(AliAODVertex *vtx1) const
107   {return GetSecondaryVtx()->Distance2ToVertex(vtx1);}
108   Double_t DecayLength(AliAODVertex *vtx1) const
109     {return TMath::Sqrt(DecayLength2(vtx1));}
110   Double_t DecayLengthError2(AliAODVertex *vtx1) const
111     {return GetSecondaryVtx()->Error2DistanceToVertex(vtx1);}
112   Double_t DecayLengthError(AliAODVertex *vtx1) const
113     {return TMath::Sqrt(DecayLengthError2(vtx1));}
114   Double_t NormalizedDecayLength2(AliAODVertex *vtx1) const 
115     {return DecayLength2(vtx1)/DecayLengthError2(vtx1);}
116   Double_t NormalizedDecayLength(AliAODVertex *vtx1) const 
117   {return TMath::Sqrt(NormalizedDecayLength2(vtx1));}
118   Double_t DecayLengthXY(Double_t point[3]) const;
119   Double_t DecayLengthXY(AliAODVertex *vtx1) const
120     {return GetSecondaryVtx()->DistanceXYToVertex(vtx1);}
121   Double_t DecayLengthXYError(AliAODVertex *vtx1) const
122     {return GetSecondaryVtx()->ErrorDistanceXYToVertex(vtx1);}
123   Double_t NormalizedDecayLengthXY(AliAODVertex *vtx1) const 
124     {return DecayLengthXY(vtx1)/DecayLengthXYError(vtx1);}
125   Double_t Ct(UInt_t pdg,Double_t point[3]) const;
126   Double_t Ct(UInt_t pdg,AliAODVertex *vtx1) const;
127   Double_t CosPointingAngle(Double_t point[3]) const;
128   Double_t CosPointingAngle(AliAODVertex *vtx1) const;
129   Double_t CosPointingAngleXY(Double_t point[3]) const;
130   Double_t CosPointingAngleXY(AliAODVertex *vtx1) const;
131   Double_t CosThetaStar(Int_t ip,UInt_t pdgvtx,UInt_t pdgprong0,UInt_t pdgprong1) const;
132   Double_t InvMass2(Int_t npdg,UInt_t *pdg) const;
133   Double_t InvMass(Int_t npdg,UInt_t *pdg) const {return TMath::Sqrt(InvMass2(npdg,pdg));}
134   Double_t ImpParXY(Double_t point[3]) const;
135   Double_t ImpParXY(AliAODVertex *vtx1) const;
136   Bool_t   PassInvMassCut(Int_t pdgMom,Int_t npdgDg,UInt_t *pdgDg,Double_t cut) const;
137
138   // prongs
139   Int_t    GetNProngs() const {return fNProngs;}
140   Int_t    GetNDaughters() const {return GetSecondaryVtx()->GetNDaughters();}
141   TObject *GetDaughter(Int_t i) const {return (GetNDaughters()>i ? GetSecondaryVtx()->GetDaughter(i) : 0x0);}
142
143   Short_t  ChargeProng(Int_t ip) const;
144   Double_t Getd0Prong(Int_t ip) const {return fd0[ip];}
145   Double_t Prodd0d0(Int_t ip1=0,Int_t ip2=0) const {return fd0[ip1]*fd0[ip2];} 
146   void     SetPxPyPzProngs(Int_t nprongs,Double_t *px,Double_t *py,Double_t *pz);
147   Double_t PxProng(Int_t ip) const {return fPx[ip];}
148   Double_t PyProng(Int_t ip) const {return fPy[ip];}
149   Double_t PzProng(Int_t ip) const {return fPz[ip];}
150   Double_t PtProng(Int_t ip) const {return TMath::Sqrt(Pt2Prong(ip));}
151   Double_t Pt2Prong(Int_t ip) const; 
152   Double_t PProng(Int_t ip) const {return TMath::Sqrt(P2Prong(ip));}
153   Double_t P2Prong(Int_t ip) const; 
154   Double_t PhiProng(Int_t ip) const 
155     {return TMath::ATan2(PyProng(ip),PxProng(ip));}
156     Double_t ThetaProng(Int_t ip) const 
157       {return 0.5*TMath::Pi()-TMath::ATan(PzProng(ip)/(PtProng(ip)+1.e-13));}
158   Double_t EtaProng(Int_t ip) const 
159     {return -TMath::Log(TMath::Tan(0.5*ThetaProng(ip)));}
160   Double_t E2Prong(Int_t ip,UInt_t pdg) const;
161   Double_t EProng(Int_t ip,UInt_t pdg) const {return TMath::Sqrt(E2Prong(ip,pdg));}
162   Double_t YProng(Int_t ip,UInt_t pdg) const 
163     {return 0.5*TMath::Log((EProng(ip,pdg)+PzProng(ip))/(EProng(ip,pdg)-PzProng(ip)+1.e-13));}
164   Double_t Alpha() const;             // for Armenteros-Podolanski plot (V0's)
165   Double_t QlProng(Int_t ip) const;
166   Double_t QtProng(Int_t ip=0) const; // for Armenteros-Podolanski plot (V0's)
167   Double_t QlProngFlightLine(Int_t ip,Double_t point[3]) const;
168   Double_t QlProngFlightLine(Int_t ip,AliAODVertex *vtx1) const;
169   Double_t QtProngFlightLine(Int_t ip,Double_t point[3]) const;
170   Double_t QtProngFlightLine(Int_t ip,AliAODVertex *vtx1) const;
171   Double_t InvMass2Prongs(Int_t ip1,Int_t ip2,UInt_t pdg1,UInt_t pdg2) const;
172   Double_t ProngsRelAngle(Int_t ip1=0,Int_t ip2=1) const;
173
174   // relate to other objects
175   //Double_t DistanceToVertex(AliAODVertex *vtx) // distance to a AliAODVertex
176   //Double_t DistanceToTrack(AliAODTrack *trk)   // distance to a AliAODTrack
177
178
179   // print
180   void    Print(Option_t* option = "") const;
181   //void    PrintIndices() const {GetSecondaryVtx()->PrintIndices();}
182
183   // dummy functions for inheritance from AliVParticle
184   Double_t E() const 
185     {printf("Dummy function; use AliAODRecoDecay::E(UInt_t pdg) instead"); return (Double_t)-999.;}
186   Double_t Y() const 
187     {printf("Dummy function; use AliAODRecoDecay::Y(UInt_t pdg) instead"); return (Double_t)-999.;}
188   Double_t M() const 
189     {printf("Dummy function"); return (Double_t)-999.;}
190   Int_t GetLabel() const {return -1;}
191   Int_t PdgCode()  const {return  0;}
192   
193  protected:
194
195   Int_t    MatchToMC(Int_t pdgabs,TClonesArray *mcArray,Int_t dgLabels[10],Int_t ndg,Int_t ndgCk=0,Int_t *pdgDg=0) const;
196   Int_t    MatchToMC(Int_t pdgabs,TClonesArray *mcArray,Int_t dgLabels[10]) const { return MatchToMC(pdgabs,mcArray,dgLabels,GetNDaughters()); }
197
198   TRef     fSecondaryVtx;  // decay vertex
199   AliAODVertex *fOwnSecondaryVtx;  // temporary solution (to work outside AliAODEvent)
200   Short_t  fCharge;  // charge, use this convention for prongs charges:
201                      // if(charge== 0) even-index prongs are +
202                      //                odd-index prongs are -
203                      // if(charge==+1) even-index prongs are +
204                      //                odd-index prongs are -
205                      // if(charge==-1) even-index prongs are -
206                      //                odd-index prongs are +
207
208   // TEMPORARY, to be removed when we do analysis on AliAODEvent
209   Int_t fNProngs;    // number of prongs
210   Int_t fNDCA;       // number of dca's
211   Int_t fNPID;       // number of PID probabilities
212   Double32_t *fPx;   //[fNProngs] px of tracks at the vertex [GeV/c]
213   Double32_t *fPy;   //[fNProngs] py of tracks at the vertex [GeV/c]
214   Double32_t *fPz;   //[fNProngs] pz of tracks at the vertex [GeV/c]
215   Double32_t *fd0;   //[fNProngs] rphi impact params w.r.t. Primary Vtx [cm]
216   Double32_t *fDCA;  //[fNDCA] prong-to-prong DCA [cm]
217                      // convention:fDCA[0]=p0p1,fDCA[1]=p0p2,fDCA[2]=p1p2,...
218   Double32_t *fPID;  //[fNPID] combined pid
219                      //  (combined detector response probabilities)
220                             
221   // TEMPORARY, to be removed when we do analysis on AliAODEvent
222   Int_t fEventNumber;
223   Int_t fRunNumber;
224   // TO BE PUT IN SPECIAL MC CLASS
225   //Bool_t   fSignal; // TRUE if signal, FALSE if background (for simulation)
226   //Int_t  fTrkNum[2]; // numbers of the two decay tracks  
227   //Int_t fPdg[2];  // PDG codes of the two tracks (for sim.)
228   //Int_t fMum[2];  // PDG codes of the mothers    (for sim.)
229
230   //
231
232   ClassDef(AliAODRecoDecay,4)  // base class for AOD reconstructed decays
233 };
234
235
236 inline Short_t AliAODRecoDecay::ChargeProng(Int_t ip) const
237 {
238   if(fCharge==0 || fCharge==+1) {
239     if(ip%2==0) {
240       return (Short_t)1;
241     } else {
242       return (Short_t)-1;
243     }
244   } else { // fCharge==-1
245     if(ip%2==0) {
246       return (Short_t)-1;
247     } else {
248       return (Short_t)1;
249     }
250   }
251 }
252
253 inline Double_t AliAODRecoDecay::RadiusSecVtx() const 
254
255   return TMath::Sqrt(GetSecVtxX()*GetSecVtxX()+GetSecVtxY()*GetSecVtxY());
256 }
257
258 inline void AliAODRecoDecay::GetSecondaryVtx(Double_t vtx[3]) const 
259 {
260   GetSecondaryVtx()->GetPosition(vtx);
261   return;
262 }
263
264 inline Double_t AliAODRecoDecay::Px() const 
265 {
266   Double_t px=0.; 
267   for(Int_t i=0;i<GetNProngs();i++) px+=PxProng(i); 
268   return px;
269 }
270
271 inline Double_t AliAODRecoDecay::Py() const 
272 {
273   Double_t py=0.; 
274   for(Int_t i=0;i<GetNProngs();i++) py+=PyProng(i); 
275   return py;
276 }
277
278 inline Double_t AliAODRecoDecay::Pz() const 
279 {
280   Double_t pz=0.; 
281   for(Int_t i=0;i<GetNProngs();i++) pz+=PzProng(i); 
282   return pz;
283 }
284
285 inline Double_t AliAODRecoDecay::Ct(UInt_t pdg,AliAODVertex *vtx1) const
286 {
287   Double_t v[3];
288   vtx1->GetPosition(v);
289   return Ct(pdg,v);
290 }
291
292 inline Double_t AliAODRecoDecay::CosPointingAngle(AliAODVertex *vtx1) const
293 {
294   Double_t v[3];
295   vtx1->GetPosition(v);
296   return CosPointingAngle(v);
297 }
298
299 inline Double_t AliAODRecoDecay::CosPointingAngleXY(AliAODVertex *vtx1) const
300 {
301   Double_t v[3];
302   vtx1->GetPosition(v);
303   return CosPointingAngleXY(v);
304 }
305
306 inline Double_t AliAODRecoDecay::ImpParXY(AliAODVertex *vtx1) const
307 {
308   Double_t v[3];
309   vtx1->GetPosition(v);
310   return ImpParXY(v);
311 }
312
313 inline Double_t AliAODRecoDecay::Pt2Prong(Int_t ip) const 
314 {
315   return PxProng(ip)*PxProng(ip)+PyProng(ip)*PyProng(ip);
316 }
317
318 inline Double_t AliAODRecoDecay::P2Prong(Int_t ip) const 
319 {
320   return Pt2Prong(ip)+PzProng(ip)*PzProng(ip);
321 }
322
323 inline Double_t AliAODRecoDecay::QlProngFlightLine(Int_t ip,AliAODVertex *vtx1) const
324 {
325   Double_t v[3];
326   vtx1->GetPosition(v);
327   return QlProngFlightLine(ip,v);
328 }
329
330 inline Double_t AliAODRecoDecay::QtProngFlightLine(Int_t ip,AliAODVertex *vtx1) const
331 {
332   Double_t v[3];
333   vtx1->GetPosition(v);
334   return QtProngFlightLine(ip,v);
335 }
336
337 inline void AliAODRecoDecay::SetPxPyPzProngs(Int_t nprongs,Double_t *px,Double_t *py,Double_t *pz) 
338 {
339   if(nprongs!=GetNProngs()) { 
340     printf("Wrong number of momenta, must be nProngs");
341     return;
342   }
343   if(!fPx) {
344     fPx = new Double32_t[nprongs];
345     fPy = new Double32_t[nprongs];
346     fPz = new Double32_t[nprongs];
347   }
348   for(Int_t i=0;i<nprongs;i++) {
349     fPx[i] = px[i]; 
350     fPy[i] = py[i]; 
351     fPz[i] = pz[i]; 
352   }
353
354   return;
355 }
356
357 inline void AliAODRecoDecay::SetDCAs(Int_t nDCA,Double_t *dca) 
358 {
359   if(nDCA!=(GetNProngs()*(GetNProngs()-1)/2)) { 
360     printf("Wrong number of DCAs, must be nProngs*(nProngs-1)/2");
361     return;
362   }
363   if(fDCA) delete [] fDCA;
364   fNDCA = nDCA;
365   fDCA = new Double32_t[nDCA];
366   for(Int_t i=0;i<nDCA;i++) 
367     fDCA[i] = dca[i]; 
368   return;
369 }
370
371 inline void AliAODRecoDecay::SetDCA(Double_t dca) 
372 {
373   Double_t ddca[1]; ddca[0]=dca;
374   SetDCAs(1,ddca);
375   return;
376 }
377
378 inline void AliAODRecoDecay::SetPID(Int_t nprongs,Double_t *pid) 
379 {
380   if(nprongs!=GetNProngs()) {
381     printf("Wrong number of prongs");
382     return;
383   }
384   if(fPID) delete [] fPID;
385   fNPID = nprongs*5;
386   fPID = new Double32_t[nprongs*5];
387   for(Int_t i=0;i<nprongs;i++) 
388     for(Int_t j=0;j<5;j++)
389       fPID[i*5+j] = pid[i*5+j]; 
390   return;
391 }
392
393 inline void AliAODRecoDecay::GetPIDProng(Int_t ip,Double_t *pid) const
394
395   for(Int_t j=0;j<5;j++)
396     pid[j] = fPID[ip*5+j];
397   return;
398 }
399
400
401
402 #endif
403