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