]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODTrack.cxx
891982ae883f193877588aa62a362191975298c2
[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 //#include <TPDGCode.h>
26 //#include <TDatabasePDG.h>
27
28 ClassImp(AliAODTrack)
29
30 //______________________________________________________________________________
31 AliAODTrack::AliAODTrack() : 
32   AliVParticle(),
33   fChi2perNDF(-999.),
34   fID(-999),
35   fLabel(-999),
36   fCovMatrix(NULL),
37   fProdVertex(0x0),
38   fCharge(-99),
39   fITSMuonClusterMap(0),
40   fType(kUndef),
41   fChi2MatchTrigger(0.),
42   fFilterMap(0)
43 {
44   // default constructor
45
46   SetP();
47   SetPosition((Float_t*)NULL);
48   SetPID((Float_t*)NULL);
49 }
50
51 //______________________________________________________________________________
52 AliAODTrack::AliAODTrack(Int_t id,
53                          Int_t label, 
54                          Double_t p[3],
55                          Bool_t cartesian,
56                          Double_t x[3],
57                          Bool_t isDCA,
58                          Double_t covMatrix[21],
59                          Short_t charge,
60                          UChar_t itsClusMap,
61                          Double_t pid[10],
62                          AliAODVertex *prodVertex,
63                          Bool_t usedForVtxFit,
64                          Bool_t usedForPrimVtxFit,
65                          AODTrk_t ttype,
66                          UInt_t selectInfo) :
67   AliVParticle(),
68   fChi2perNDF(-999.),
69   fID(id),
70   fLabel(label),
71   fCovMatrix(NULL),
72   fProdVertex(prodVertex),
73   fCharge(charge),
74   fITSMuonClusterMap(itsClusMap),
75   fType(ttype),
76   fChi2MatchTrigger(0.),
77   fFilterMap(selectInfo)
78 {
79   // constructor
80  
81   SetP(p, cartesian);
82   SetPosition(x, isDCA);
83   SetUsedForVtxFit(usedForVtxFit);
84   SetUsedForPrimVtxFit(usedForPrimVtxFit);
85   if(covMatrix) SetCovMatrix(covMatrix);
86   SetPID(pid);
87
88 }
89
90 //______________________________________________________________________________
91 AliAODTrack::AliAODTrack(Int_t id,
92                          Int_t label, 
93                          Float_t p[3],
94                          Bool_t cartesian,
95                          Float_t x[3],
96                          Bool_t isDCA,
97                          Float_t covMatrix[21],
98                          Short_t charge,
99                          UChar_t itsClusMap,
100                          Float_t pid[10],
101                          AliAODVertex *prodVertex,
102                          Bool_t usedForVtxFit,
103                          Bool_t usedForPrimVtxFit,
104                          AODTrk_t ttype,
105                          UInt_t selectInfo) :
106   AliVParticle(),
107   fChi2perNDF(-999.),
108   fID(id),
109   fLabel(label),
110   fCovMatrix(NULL),
111   fProdVertex(prodVertex),
112   fCharge(charge),
113   fITSMuonClusterMap(itsClusMap),
114   fType(ttype),
115   fChi2MatchTrigger(0.),
116   fFilterMap(selectInfo)
117 {
118   // constructor
119  
120   SetP(p, cartesian);
121   SetPosition(x, isDCA);
122   SetUsedForVtxFit(usedForVtxFit);
123   SetUsedForPrimVtxFit(usedForPrimVtxFit);
124   if(covMatrix) SetCovMatrix(covMatrix);
125   SetPID(pid);
126 }
127
128 //______________________________________________________________________________
129 AliAODTrack::~AliAODTrack() 
130 {
131   // destructor
132   delete fCovMatrix;
133 }
134
135
136 //______________________________________________________________________________
137 AliAODTrack::AliAODTrack(const AliAODTrack& trk) :
138   AliVParticle(trk),
139   fChi2perNDF(trk.fChi2perNDF),
140   fID(trk.fID),
141   fLabel(trk.fLabel),
142   fCovMatrix(NULL),
143   fProdVertex(trk.fProdVertex),
144   fCharge(trk.fCharge),
145   fITSMuonClusterMap(trk.fITSMuonClusterMap),
146   fType(trk.fType),
147   fChi2MatchTrigger(0.),
148   fFilterMap(trk.fFilterMap)
149 {
150   // Copy constructor
151
152   trk.GetP(fMomentum);
153   trk.GetPosition(fPosition);
154   SetUsedForVtxFit(trk.GetUsedForVtxFit());
155   SetUsedForPrimVtxFit(trk.GetUsedForPrimVtxFit());
156   if(trk.fCovMatrix) fCovMatrix=new AliAODRedCov<6>(*trk.fCovMatrix);
157   SetPID(trk.fPID);
158
159 }
160
161 //______________________________________________________________________________
162 AliAODTrack& AliAODTrack::operator=(const AliAODTrack& trk)
163 {
164   // Assignment operator
165   if(this!=&trk) {
166
167     AliVParticle::operator=(trk);
168
169     trk.GetP(fMomentum);
170     trk.GetPosition(fPosition);
171     trk.GetPID(fPID);
172
173     fChi2perNDF = trk.fChi2perNDF;
174
175     fID = trk.fID;
176     fLabel = trk.fLabel;    
177     
178     delete fCovMatrix;
179     if(trk.fCovMatrix) fCovMatrix=new AliAODRedCov<6>(*trk.fCovMatrix);
180     else fCovMatrix=NULL;
181     fProdVertex = trk.fProdVertex;
182
183     fCharge = trk.fCharge;
184     fITSMuonClusterMap = trk.fITSMuonClusterMap;
185     SetUsedForVtxFit(trk.GetUsedForVtxFit());
186     SetUsedForPrimVtxFit(trk.GetUsedForPrimVtxFit());
187     fType = trk.fType;
188     fFilterMap = trk.fFilterMap;
189   }
190
191   return *this;
192 }
193
194 //______________________________________________________________________________
195 Double_t AliAODTrack::M(AODTrkPID_t pid) const
196 {
197   // Returns the mass.
198   // Masses for nuclei don't exist in the PDG tables, therefore they were put by hand.
199
200   switch (pid) {
201
202   case kElectron :
203     return 0.000510999; //TDatabasePDG::Instance()->GetParticle(11/*::kElectron*/)->Mass();
204     break;
205
206   case kMuon :
207     return 0.1056584; //TDatabasePDG::Instance()->GetParticle(13/*::kMuonMinus*/)->Mass();
208     break;
209
210   case kPion :
211     return 0.13957; //TDatabasePDG::Instance()->GetParticle(211/*::kPiPlus*/)->Mass();
212     break;
213
214   case kKaon :
215     return 0.4937; //TDatabasePDG::Instance()->GetParticle(321/*::kKPlus*/)->Mass();
216     break;
217
218   case kProton :
219     return 0.9382720; //TDatabasePDG::Instance()->GetParticle(2212/*::kProton*/)->Mass();
220     break;
221
222   case kDeuteron :
223     return 1.8756; //TDatabasePDG::Instance()->GetParticle(1000010020)->Mass();
224     break;
225
226   case kTriton :
227     return 2.8089; //TDatabasePDG::Instance()->GetParticle(1000010030)->Mass();
228     break;
229
230   case kHelium3 :
231     return 2.8084; //TDatabasePDG::Instance()->GetParticle(1000020030)->Mass();
232     break;
233
234   case kAlpha :
235     return 3.7274; //TDatabasePDG::Instance()->GetParticle(1000020040)->Mass();
236     break;
237
238   case kUnknown :
239     return -999.;
240     break;
241
242   default :
243     return -999.;
244   }
245 }
246
247 //______________________________________________________________________________
248 Double_t AliAODTrack::E(AODTrkPID_t pid) const
249 {
250   // Returns the energy of the particle of a given pid.
251   
252   if (pid != kUnknown) { // particle was identified
253     Double_t m = M(pid);
254     return TMath::Sqrt(P()*P() + m*m);
255   } else { // pid unknown
256     return -999.;
257   }
258 }
259
260 //______________________________________________________________________________
261 Double_t AliAODTrack::Y(AODTrkPID_t pid) const
262 {
263   // Returns the rapidity of a particle of a given pid.
264   
265   if (pid != kUnknown) { // particle was identified
266     Double_t e = E(pid);
267     Double_t pz = Pz();
268     if (e>=0 && e!=pz) { // energy was positive (e.g. not -999.) and not equal to pz
269       return 0.5*TMath::Log((e+pz)/(e-pz));
270     } else { // energy not known or equal to pz
271       return -999.;
272     }
273   } else { // pid unknown
274     return -999.;
275   }
276 }
277
278 //______________________________________________________________________________
279 Double_t AliAODTrack::Y(Double_t m) const
280 {
281   // Returns the rapidity of a particle of a given mass.
282   
283   if (m >= 0.) { // mass makes sense
284     Double_t e = E(m);
285     Double_t pz = Pz();
286     if (e>=0 && e!=pz) { // energy was positive (e.g. not -999.) and not equal to pz
287       return 0.5*TMath::Log((e+pz)/(e-pz));
288     } else { // energy not known or equal to pz
289       return -999.;
290     }
291   } else { // pid unknown
292     return -999.;
293   }
294 }
295
296 //______________________________________________________________________________
297 AliAODTrack::AODTrkPID_t AliAODTrack::GetMostProbablePID() const 
298 {
299   // Returns the most probable PID array element.
300   
301   Int_t nPID = 10;
302   if (fPID) {
303     AODTrkPID_t loc = kUnknown;
304     Double_t max = 0.;
305     Bool_t allTheSame = kTRUE;
306     
307     for (Int_t iPID = 0; iPID < nPID; iPID++) {
308       if (fPID[iPID] >= max) {
309         if (fPID[iPID] > max) {
310           allTheSame = kFALSE;
311           max = fPID[iPID];
312           loc = (AODTrkPID_t)iPID;
313         } else {
314           allTheSame = kTRUE;
315         }
316       }
317     }
318     
319     return allTheSame ? kUnknown : loc;
320   } else {
321     return kUnknown;
322   }
323 }
324
325 //______________________________________________________________________________
326 void AliAODTrack::ConvertAliPIDtoAODPID()
327 {
328   // Converts AliPID array.
329   // The numbering scheme is the same for electrons, muons, pions, kaons, and protons.
330   // Everything else has to be set to zero.
331
332   fPID[kDeuteron] = 0.;
333   fPID[kTriton]   = 0.;
334   fPID[kHelium3]  = 0.;
335   fPID[kAlpha]    = 0.;
336   fPID[kUnknown]  = 0.;
337   
338   return;
339 }
340
341
342 //______________________________________________________________________________
343 template <class T> void AliAODTrack::SetP(const T *p, const Bool_t cartesian) 
344 {
345   // Set the momentum
346
347   if (p) {
348     if (cartesian) {
349       Double_t pt2 = p[0]*p[0] + p[1]*p[1];
350       Double_t P = TMath::Sqrt(pt2 + p[2]*p[2]);
351       
352       fMomentum[0] = TMath::Sqrt(pt2); // pt
353       fMomentum[1] = (pt2 != 0.) ? TMath::ATan2(p[1], p[0]) : -999; // phi
354       fMomentum[2] = (P != 0.) ? TMath::ACos(p[2]/P) : -999.; // theta
355     } else {
356       fMomentum[0] = p[0];  // pt
357       fMomentum[1] = p[1];  // phi
358       fMomentum[2] = p[2];  // theta
359     }
360   } else {
361     fMomentum[0] = -999.;
362     fMomentum[1] = -999.;
363     fMomentum[2] = -999.;
364   }
365 }
366
367 //______________________________________________________________________________
368 template <class T> void AliAODTrack::SetPosition(const T *x, const Bool_t dca) 
369 {
370   // set the position
371
372   if (x) {
373     if (!dca) {
374       ResetBit(kIsDCA);
375
376       fPosition[0] = x[0];
377       fPosition[1] = x[1];
378       fPosition[2] = x[2];
379     } else {
380       SetBit(kIsDCA);
381       // don't know any better yet
382       fPosition[0] = -999.;
383       fPosition[1] = -999.;
384       fPosition[2] = -999.;
385     }
386   } else {
387     ResetBit(kIsDCA);
388
389     fPosition[0] = -999.;
390     fPosition[1] = -999.;
391     fPosition[2] = -999.;
392   }
393 }
394
395 //______________________________________________________________________________
396 void AliAODTrack::SetDCA(Double_t d, Double_t z) 
397 {
398   // set the dca
399   fPosition[0] = d;
400   fPosition[1] = z;
401   fPosition[2] = 0.;
402   SetBit(kIsDCA);
403 }
404
405 //______________________________________________________________________________
406 void AliAODTrack::Print(Option_t* /* option */) const
407 {
408   // prints information about AliAODTrack
409
410   printf("Object name: %s   Track type: %s\n", GetName(), GetTitle()); 
411   printf("        px = %f\n", Px());
412   printf("        py = %f\n", Py());
413   printf("        pz = %f\n", Pz());
414   printf("        pt = %f\n", Pt());
415   printf("      1/pt = %f\n", OneOverPt());
416   printf("     theta = %f\n", Theta());
417   printf("       phi = %f\n", Phi());
418   printf("  chi2/NDF = %f\n", Chi2perNDF());
419   printf("    charge = %d\n", Charge());
420   printf(" PID object: %p\n", PID());
421 }
422
423 void AliAODTrack::SetMatchTrigger(Int_t MatchTrigger){
424 //
425 // Set the MUON trigger information
426   switch(MatchTrigger){
427     case 0: // 0 track does not match trigger
428       fITSMuonClusterMap=fITSMuonClusterMap&0x3fffffff;
429       break;
430     case 1: // 1 track match but does not pass pt cut
431       fITSMuonClusterMap=(fITSMuonClusterMap&0x3fffffff)|0x40000000;
432       break;
433     case 2: // 2 track match Low pt cut
434       fITSMuonClusterMap=(fITSMuonClusterMap&0x3fffffff)|0x80000000;
435       break;
436     case 3: // 3 track match High pt cut
437       fITSMuonClusterMap=fITSMuonClusterMap|0xc0000000;
438       break;
439     default:
440       fITSMuonClusterMap=fITSMuonClusterMap&0x3fffffff;
441       printf("AliAODTrack::SetMatchTrigger unknown case for MatchTrigger: %d\n",MatchTrigger);
442   }
443 }
444
445 void AliAODTrack::SetHitsPatternInTrigCh(UShort_t hitsPatternInTrigCh){
446 //
447 // Set the MUON hit pattern (1 bit per chamber) 
448   fITSMuonClusterMap=(fITSMuonClusterMap&0xffff00ff)|(hitsPatternInTrigCh<<8);
449 }
450
451 Int_t AliAODTrack::HitsMT(Int_t istation, Int_t iplane, Char_t *cathode){
452 //
453 // Retrieve hit information for MUON identified by  (station, plane, cathode)
454   if(cathode){
455     if(cathode[0]=='x'||cathode[0]=='X'){
456       if(istation==1){
457         if(iplane==1)
458           return (fITSMuonClusterMap&0x8000)?1:0;
459         else if(iplane==2)
460           return (fITSMuonClusterMap&0x4000)?1:0;
461         else
462           return 0;
463       }else if(istation==2){
464         if(iplane==1)
465           return (fITSMuonClusterMap&0x2000)?1:0;
466         else if(iplane==2)
467           return (fITSMuonClusterMap&0x1000)?1:0;
468         else
469           return 0;
470       }else{
471         return 0;
472       }
473     }else if(cathode[0]=='y'||cathode[0]=='Y'){
474       if(istation==1){
475         if(iplane==1)
476           return (fITSMuonClusterMap&0x0800)?1:0;
477         else if(iplane==2)
478           return (fITSMuonClusterMap&0x0400)?1:0;
479         else
480           return 0;
481       }else if(istation==2){
482         if(iplane==1)
483           return (fITSMuonClusterMap&0x0200)?1:0;
484         else if(iplane==2)
485           return (fITSMuonClusterMap&0x0100)?1:0;
486         else
487           return 0;
488       }else{
489         return 0;
490       }
491     }else{
492       return 0;
493     }
494   }else{
495     if(istation==1){
496       if(iplane==1)
497         return (HitsMT(1,1,"X")||HitsMT(1,1,"Y"))?1:0;
498       else if(iplane==2)
499         return (HitsMT(1,2,"X")||HitsMT(1,2,"Y"))?1:0;
500       else
501         return 0;
502     }else if(istation==2){
503       if(iplane==1)
504         return (HitsMT(2,1,"X")||HitsMT(2,1,"Y"))?1:0;
505       else if(iplane==2)
506         return (HitsMT(2,2,"X")||HitsMT(2,2,"Y"))?1:0;
507       else
508         return 0;
509     }else{
510       return 0;
511     }
512   }
513 }
514
515 Int_t AliAODTrack::HitsMuonChamber(Int_t MuonChamber){
516 // Retrieve hit information for MUON Chamber
517   switch(MuonChamber){
518     case 11:
519       return HitsMT(1,1);
520     case 12:
521       return HitsMT(1,2);
522     case 13:
523       return HitsMT(2,1);
524     case 14:
525       return HitsMT(2,2);
526     default:
527       printf("Unknown MUON chamber: %d\n",MuonChamber);
528       return 0;
529   }
530 }