]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODTrack.cxx
ITS cluster map extended to hold muon hits as well.
[u/mrichter/AliRoot.git] / STEER / AliAODTrack.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, 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 //     AOD track base class
20 //     Author: Markus Oldenburg, CERN
21 //-------------------------------------------------------------------------
22
23 #include "AliAODTrack.h"
24
25 ClassImp(AliAODTrack)
26
27 //______________________________________________________________________________
28 AliAODTrack::AliAODTrack() : 
29   AliVirtualParticle(),
30   fChi2perNDF(-999.),
31   fID(-999),
32   fLabel(-999),
33   fCovMatrix(NULL),
34   fProdVertex(0x0),
35   fCharge(-99),
36   fITSMuonClusterMap(0),
37   fType(kUndef)
38 {
39   // default constructor
40
41   SetP();
42   SetPosition((Float_t*)NULL);
43   SetPID((Float_t*)NULL);
44 }
45
46 //______________________________________________________________________________
47 AliAODTrack::AliAODTrack(Int_t id,
48                          Int_t label, 
49                          Double_t p[3],
50                          Bool_t cartesian,
51                          Double_t x[3],
52                          Bool_t isDCA,
53                          Double_t covMatrix[21],
54                          Short_t charge,
55                          UChar_t itsClusMap,
56                          Double_t pid[10],
57                          AliAODVertex *prodVertex,
58                          Bool_t usedForVtxFit,
59                          Bool_t usedForPrimVtxFit,
60                          AODTrk_t ttype) :
61   AliVirtualParticle(),
62   fChi2perNDF(-999.),
63   fID(id),
64   fLabel(label),
65   fCovMatrix(NULL),
66   fProdVertex(prodVertex),
67   fCharge(charge),
68   fITSMuonClusterMap(itsClusMap),
69   fType(ttype)
70 {
71   // constructor
72  
73   SetP(p, cartesian);
74   SetPosition(x, isDCA);
75   SetUsedForVtxFit(usedForVtxFit);
76   SetUsedForPrimVtxFit(usedForPrimVtxFit);
77   if(covMatrix) SetCovMatrix(covMatrix);
78   SetPID(pid);
79
80 }
81
82 //______________________________________________________________________________
83 AliAODTrack::AliAODTrack(Int_t id,
84                          Int_t label, 
85                          Float_t p[3],
86                          Bool_t cartesian,
87                          Float_t x[3],
88                          Bool_t isDCA,
89                          Float_t covMatrix[21],
90                          Short_t charge,
91                          UChar_t itsClusMap,
92                          Float_t pid[10],
93                          AliAODVertex *prodVertex,
94                          Bool_t usedForVtxFit,
95                          Bool_t usedForPrimVtxFit,
96                          AODTrk_t ttype) :
97   AliVirtualParticle(),
98   fChi2perNDF(-999.),
99   fID(id),
100   fLabel(label),
101   fCovMatrix(NULL),
102   fProdVertex(prodVertex),
103   fCharge(charge),
104   fITSMuonClusterMap(itsClusMap),
105   fType(ttype)
106 {
107   // constructor
108  
109   SetP(p, cartesian);
110   SetPosition(x, isDCA);
111   SetUsedForVtxFit(usedForVtxFit);
112   SetUsedForPrimVtxFit(usedForPrimVtxFit);
113   if(covMatrix) SetCovMatrix(covMatrix);
114   SetPID(pid);
115 }
116
117 //______________________________________________________________________________
118 AliAODTrack::~AliAODTrack() 
119 {
120   // destructor
121   delete fCovMatrix;
122 }
123
124
125 //______________________________________________________________________________
126 AliAODTrack::AliAODTrack(const AliAODTrack& trk) :
127   AliVirtualParticle(trk),
128   fChi2perNDF(trk.fChi2perNDF),
129   fID(trk.fID),
130   fLabel(trk.fLabel),
131   fCovMatrix(NULL),
132   fProdVertex(trk.fProdVertex),
133   fCharge(trk.fCharge),
134   fITSMuonClusterMap(trk.fITSMuonClusterMap),
135   fType(trk.fType)
136 {
137   // Copy constructor
138
139   trk.GetP(fMomentum);
140   trk.GetPosition(fPosition);
141   SetUsedForVtxFit(trk.GetUsedForVtxFit());
142   SetUsedForPrimVtxFit(trk.GetUsedForPrimVtxFit());
143   if(trk.fCovMatrix) fCovMatrix=new AliAODRedCov<6>(*trk.fCovMatrix);
144   SetPID(trk.fPID);
145
146 }
147
148 //______________________________________________________________________________
149 AliAODTrack& AliAODTrack::operator=(const AliAODTrack& trk)
150 {
151   // Assignment operator
152   if(this!=&trk) {
153
154     AliVirtualParticle::operator=(trk);
155
156     trk.GetP(fMomentum);
157     trk.GetPosition(fPosition);
158     trk.GetPID(fPID);
159
160     fChi2perNDF = trk.fChi2perNDF;
161
162     fID = trk.fID;
163     fLabel = trk.fLabel;    
164     
165     delete fCovMatrix;
166     if(trk.fCovMatrix) fCovMatrix=new AliAODRedCov<6>(*trk.fCovMatrix);
167     else fCovMatrix=NULL;
168     fProdVertex = trk.fProdVertex;
169
170     fCharge = trk.fCharge;
171     fITSMuonClusterMap = trk.fITSMuonClusterMap;
172     SetUsedForVtxFit(trk.GetUsedForVtxFit());
173     SetUsedForPrimVtxFit(trk.GetUsedForPrimVtxFit());
174     fType = trk.fType;
175   }
176
177   return *this;
178 }
179
180 //______________________________________________________________________________
181 Double_t AliAODTrack::M(AODTrkPID_t pid) const
182 {
183   // Returns the mass.
184   // In the case of elementary particles the hard coded mass values were taken 
185   // from the PDG. In all cases the errors on the values do not affect 
186   // the last digit.
187   
188
189   switch (pid) {
190
191   case kElectron :
192     return 0.000510999;
193     break;
194
195   case kMuon :
196     return 0.1056584;
197     break;
198
199   case kPion :
200     return 0.13957;
201     break;
202
203   case kKaon :
204     return 0.4937;
205     break;
206
207   case kProton :
208     return 0.9382720;
209     break;
210
211   case kDeuteron :
212     return 1.8756;
213     break;
214
215   case kTriton :
216     return 2.8089;
217     break;
218
219   case kHelium3 :
220     return 2.8084;
221     break;
222
223   case kAlpha :
224     return 3.7274;
225     break;
226
227   case kUnknown :
228     return -999.;
229     break;
230
231   default :
232     return -999.;
233   }
234 }
235
236 //______________________________________________________________________________
237 Double_t AliAODTrack::E(AODTrkPID_t pid) const
238 {
239   // Returns the energy of the particle of a given pid.
240   
241   if (pid != kUnknown) { // particle was identified
242     Double_t m = M(pid);
243     return TMath::Sqrt(P()*P() + m*m);
244   } else { // pid unknown
245     return -999.;
246   }
247 }
248
249 //______________________________________________________________________________
250 Double_t AliAODTrack::Y(AODTrkPID_t pid) const
251 {
252   // Returns the energy of the particle of a given pid.
253   
254   if (pid != kUnknown) { // particle was identified
255     Double_t e = E(pid);
256     Double_t pz = Pz();
257     if (e>=0 && e!=pz) { // energy was positive (e.g. not -999.) and not equal to pz
258       return 0.5*TMath::Log((e+pz)/(e-pz));
259     } else { // energy not known or equal to pz
260       return -999.;
261     }
262   } else { // pid unknown
263     return -999.;
264   }
265 }
266
267 //______________________________________________________________________________
268 Double_t AliAODTrack::Y(Double_t m) const
269 {
270   // Returns the energy of the particle of a given mass.
271   
272   if (m >= 0.) { // mass makes sense
273     Double_t e = E(m);
274     Double_t pz = Pz();
275     if (e>=0 && e!=pz) { // energy was positive (e.g. not -999.) and not equal to pz
276       return 0.5*TMath::Log((e+pz)/(e-pz));
277     } else { // energy not known or equal to pz
278       return -999.;
279     }
280   } else { // pid unknown
281     return -999.;
282   }
283 }
284
285 //______________________________________________________________________________
286 AliAODTrack::AODTrkPID_t AliAODTrack::GetMostProbablePID() const 
287 {
288   // Returns the most probable PID array element.
289   
290   Int_t nPID = 10;
291   if (fPID) {
292     AODTrkPID_t loc = kUnknown;
293     Double_t max = 0.;
294     Bool_t allTheSame = kTRUE;
295     
296     for (Int_t iPID = 0; iPID < nPID; iPID++) {
297       if (fPID[iPID] >= max) {
298         if (fPID[iPID] > max) {
299           allTheSame = kFALSE;
300           max = fPID[iPID];
301           loc = (AODTrkPID_t)iPID;
302         } else {
303           allTheSame = kTRUE;
304         }
305       }
306     }
307     
308     return allTheSame ? kUnknown : loc;
309   } else {
310     return kUnknown;
311   }
312 }
313
314 //______________________________________________________________________________
315 void AliAODTrack::ConvertAliPIDtoAODPID()
316 {
317   // Converts AliPID array.
318   // The numbering scheme is the same for electrons, muons, pions, kaons, and protons.
319   // Everything else has to be set to zero.
320
321   fPID[kDeuteron] = 0.;
322   fPID[kTriton] = 0.;
323   fPID[kHelium3] = 0.;
324   fPID[kAlpha] = 0.;
325   fPID[kUnknown] = 0.;
326   
327   return;
328 }
329
330
331 //______________________________________________________________________________
332 template <class T> void AliAODTrack::SetP(const T *p, const Bool_t cartesian) 
333 {
334   // set the momentum
335
336   if (p) {
337     if (cartesian) {
338       Double_t pt2 = p[0]*p[0] + p[1]*p[1];
339       Double_t P = TMath::Sqrt(pt2 + p[2]*p[2]);
340       
341       fMomentum[0] = TMath::Sqrt(pt2); // pt
342       fMomentum[1] = (pt2 != 0.) ? TMath::ATan2(p[1], p[0]) : -999; // phi
343       fMomentum[2] = (P != 0.) ? TMath::ACos(p[2]/P) : -999.; // theta
344     } else {
345       fMomentum[0] = p[0];  // pt
346       fMomentum[1] = p[1];  // phi
347       fMomentum[2] = p[2];  // theta
348     }
349   } else {
350     fMomentum[0] = -999.;
351     fMomentum[1] = -999.;
352     fMomentum[2] = -999.;
353   }
354 }
355
356 //______________________________________________________________________________
357 template <class T> void AliAODTrack::SetPosition(const T *x, const Bool_t dca) 
358 {
359   // set the position
360
361   if (x) {
362     if (!dca) {
363       ResetBit(kIsDCA);
364
365       fPosition[0] = x[0];
366       fPosition[1] = x[1];
367       fPosition[2] = x[2];
368     } else {
369       SetBit(kIsDCA);
370       // don't know any better yet
371       fPosition[0] = -999.;
372       fPosition[1] = -999.;
373       fPosition[2] = -999.;
374     }
375   } else {
376     ResetBit(kIsDCA);
377
378     fPosition[0] = -999.;
379     fPosition[1] = -999.;
380     fPosition[2] = -999.;
381   }
382 }
383
384 //______________________________________________________________________________
385 void AliAODTrack::SetDCA(Double_t d, Double_t z) 
386 {
387   // set the dca
388   fPosition[0] = d;
389   fPosition[1] = z;
390   fPosition[2] = 0.;
391   SetBit(kIsDCA);
392 }
393
394 //______________________________________________________________________________
395 void AliAODTrack::Print(Option_t* /* option */) const
396 {
397   // prints information about AliAODTrack
398
399   printf("Object name: %s   Track type: %s\n", GetName(), GetTitle()); 
400   printf("        px = %f\n", Px());
401   printf("        py = %f\n", Py());
402   printf("        pz = %f\n", Pz());
403   printf("        pt = %f\n", Pt());
404   printf("      1/pt = %f\n", OneOverPt());
405   printf("     theta = %f\n", Theta());
406   printf("       phi = %f\n", Phi());
407   printf("  chi2/NDF = %f\n", Chi2perNDF());
408   printf("    charge = %d\n", Charge());
409   printf(" PID object: %p\n", PID());
410 }
411