]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODTrack.cxx
"Cleaned" initialization and usage of the run number.
[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 AliVParticle
20 //     Author: Markus Oldenburg, CERN
21 //     Markus.Oldenburg@cern.ch
22 //-------------------------------------------------------------------------
23
24 #include "AliAODTrack.h"
25
26 //#include <TPDGCode.h>
27 //#include <TDatabasePDG.h>
28
29 ClassImp(AliAODTrack)
30
31 //______________________________________________________________________________
32 AliAODTrack::AliAODTrack() : 
33   AliVParticle(),
34   fChi2perNDF(-999.),
35   fChi2MatchTrigger(0.),
36   fLabel(-999),
37   fITSMuonClusterMap(0),
38   fFilterMap(0),
39   fID(-999),
40   fCharge(-99),
41   fType(kUndef),
42   fCovMatrix(NULL),
43   fProdVertex(0x0)
44 {
45   // default constructor
46
47   SetP();
48   SetPosition((Float_t*)NULL);
49   SetPID((Float_t*)NULL);
50 }
51
52 //______________________________________________________________________________
53 AliAODTrack::AliAODTrack(Short_t id,
54                          Int_t label, 
55                          Double_t p[3],
56                          Bool_t cartesian,
57                          Double_t x[3],
58                          Bool_t isDCA,
59                          Double_t covMatrix[21],
60                          Short_t charge,
61                          UChar_t itsClusMap,
62                          Double_t pid[10],
63                          AliAODVertex *prodVertex,
64                          Bool_t usedForVtxFit,
65                          Bool_t usedForPrimVtxFit,
66                          AODTrk_t ttype,
67                          UInt_t selectInfo) :
68   AliVParticle(),
69   fChi2perNDF(-999.),
70   fChi2MatchTrigger(0.),
71   fLabel(label),
72   fITSMuonClusterMap(itsClusMap),
73   fFilterMap(selectInfo),
74   fID(id),
75   fCharge(charge),
76   fType(ttype),
77   fCovMatrix(NULL),
78   fProdVertex(prodVertex)
79 {
80   // constructor
81  
82   SetP(p, cartesian);
83   SetPosition(x, isDCA);
84   SetUsedForVtxFit(usedForVtxFit);
85   SetUsedForPrimVtxFit(usedForPrimVtxFit);
86   if(covMatrix) SetCovMatrix(covMatrix);
87   SetPID(pid);
88
89 }
90
91 //______________________________________________________________________________
92 AliAODTrack::AliAODTrack(Short_t id,
93                          Int_t label, 
94                          Float_t p[3],
95                          Bool_t cartesian,
96                          Float_t x[3],
97                          Bool_t isDCA,
98                          Float_t covMatrix[21],
99                          Short_t charge,
100                          UChar_t itsClusMap,
101                          Float_t pid[10],
102                          AliAODVertex *prodVertex,
103                          Bool_t usedForVtxFit,
104                          Bool_t usedForPrimVtxFit,
105                          AODTrk_t ttype,
106                          UInt_t selectInfo) :
107   AliVParticle(),
108   fChi2perNDF(-999.),
109   fChi2MatchTrigger(0.),
110   fLabel(label),
111   fITSMuonClusterMap(itsClusMap),
112   fFilterMap(selectInfo),
113   fID(id),
114   fCharge(charge),
115   fType(ttype),
116   fCovMatrix(NULL),
117   fProdVertex(prodVertex)
118 {
119   // constructor
120  
121   SetP(p, cartesian);
122   SetPosition(x, isDCA);
123   SetUsedForVtxFit(usedForVtxFit);
124   SetUsedForPrimVtxFit(usedForPrimVtxFit);
125   if(covMatrix) SetCovMatrix(covMatrix);
126   SetPID(pid);
127 }
128
129 //______________________________________________________________________________
130 AliAODTrack::~AliAODTrack() 
131 {
132   // destructor
133   delete fCovMatrix;
134 }
135
136
137 //______________________________________________________________________________
138 AliAODTrack::AliAODTrack(const AliAODTrack& trk) :
139   AliVParticle(trk),
140   fChi2perNDF(trk.fChi2perNDF),
141   fChi2MatchTrigger(trk.fChi2MatchTrigger),
142   fLabel(trk.fLabel),
143   fITSMuonClusterMap(trk.fITSMuonClusterMap),
144   fFilterMap(trk.fFilterMap),
145   fID(trk.fID),
146   fCharge(trk.fCharge),
147   fType(trk.fType),
148   fCovMatrix(NULL),
149   fProdVertex(trk.fProdVertex)
150 {
151   // Copy constructor
152
153   trk.GetP(fMomentum);
154   trk.GetPosition(fPosition);
155   SetUsedForVtxFit(trk.GetUsedForVtxFit());
156   SetUsedForPrimVtxFit(trk.GetUsedForPrimVtxFit());
157   if(trk.fCovMatrix) fCovMatrix=new AliAODRedCov<6>(*trk.fCovMatrix);
158   SetPID(trk.fPID);
159
160 }
161
162 //______________________________________________________________________________
163 AliAODTrack& AliAODTrack::operator=(const AliAODTrack& trk)
164 {
165   // Assignment operator
166   if(this!=&trk) {
167
168     AliVParticle::operator=(trk);
169
170     trk.GetP(fMomentum);
171     trk.GetPosition(fPosition);
172     trk.GetPID(fPID);
173
174     fChi2perNDF = trk.fChi2perNDF;
175     fChi2MatchTrigger = trk.fChi2MatchTrigger;
176
177     fID = trk.fID;
178     fLabel = trk.fLabel;    
179     
180     fITSMuonClusterMap = trk.fITSMuonClusterMap;
181     fFilterMap = trk.fFilterMap;
182
183     fCharge = trk.fCharge;
184     fType = trk.fType;
185
186     delete fCovMatrix;
187     if(trk.fCovMatrix) fCovMatrix=new AliAODRedCov<6>(*trk.fCovMatrix);
188     else fCovMatrix=NULL;
189     fProdVertex = trk.fProdVertex;
190
191     SetUsedForVtxFit(trk.GetUsedForVtxFit());
192     SetUsedForPrimVtxFit(trk.GetUsedForPrimVtxFit());
193   }
194
195   return *this;
196 }
197
198 //______________________________________________________________________________
199 Double_t AliAODTrack::M(AODTrkPID_t pid) const
200 {
201   // Returns the mass.
202   // Masses for nuclei don't exist in the PDG tables, therefore they were put by hand.
203
204   switch (pid) {
205
206   case kElectron :
207     return 0.000510999; //TDatabasePDG::Instance()->GetParticle(11/*::kElectron*/)->Mass();
208     break;
209
210   case kMuon :
211     return 0.1056584; //TDatabasePDG::Instance()->GetParticle(13/*::kMuonMinus*/)->Mass();
212     break;
213
214   case kPion :
215     return 0.13957; //TDatabasePDG::Instance()->GetParticle(211/*::kPiPlus*/)->Mass();
216     break;
217
218   case kKaon :
219     return 0.4937; //TDatabasePDG::Instance()->GetParticle(321/*::kKPlus*/)->Mass();
220     break;
221
222   case kProton :
223     return 0.9382720; //TDatabasePDG::Instance()->GetParticle(2212/*::kProton*/)->Mass();
224     break;
225
226   case kDeuteron :
227     return 1.8756; //TDatabasePDG::Instance()->GetParticle(1000010020)->Mass();
228     break;
229
230   case kTriton :
231     return 2.8089; //TDatabasePDG::Instance()->GetParticle(1000010030)->Mass();
232     break;
233
234   case kHelium3 :
235     return 2.8084; //TDatabasePDG::Instance()->GetParticle(1000020030)->Mass();
236     break;
237
238   case kAlpha :
239     return 3.7274; //TDatabasePDG::Instance()->GetParticle(1000020040)->Mass();
240     break;
241
242   case kUnknown :
243     return -999.;
244     break;
245
246   default :
247     return -999.;
248   }
249 }
250
251 //______________________________________________________________________________
252 Double_t AliAODTrack::E(AODTrkPID_t pid) const
253 {
254   // Returns the energy of the particle of a given pid.
255   
256   if (pid != kUnknown) { // particle was identified
257     Double_t m = M(pid);
258     return TMath::Sqrt(P()*P() + m*m);
259   } else { // pid unknown
260     return -999.;
261   }
262 }
263
264 //______________________________________________________________________________
265 Double_t AliAODTrack::Y(AODTrkPID_t pid) const
266 {
267   // Returns the rapidity of a particle of a given pid.
268   
269   if (pid != kUnknown) { // particle was identified
270     Double_t e = E(pid);
271     Double_t pz = Pz();
272     if (e>=0 && e!=pz) { // energy was positive (e.g. not -999.) and not equal to pz
273       return 0.5*TMath::Log((e+pz)/(e-pz));
274     } else { // energy not known or equal to pz
275       return -999.;
276     }
277   } else { // pid unknown
278     return -999.;
279   }
280 }
281
282 //______________________________________________________________________________
283 Double_t AliAODTrack::Y(Double_t m) const
284 {
285   // Returns the rapidity of a particle of a given mass.
286   
287   if (m >= 0.) { // mass makes sense
288     Double_t e = E(m);
289     Double_t pz = Pz();
290     if (e>=0 && e!=pz) { // energy was positive (e.g. not -999.) and not equal to pz
291       return 0.5*TMath::Log((e+pz)/(e-pz));
292     } else { // energy not known or equal to pz
293       return -999.;
294     }
295   } else { // pid unknown
296     return -999.;
297   }
298 }
299
300 //______________________________________________________________________________
301 AliAODTrack::AODTrkPID_t AliAODTrack::GetMostProbablePID() const 
302 {
303   // Returns the most probable PID array element.
304   
305   Int_t nPID = 10;
306   if (fPID) {
307     AODTrkPID_t loc = kUnknown;
308     Double_t max = 0.;
309     Bool_t allTheSame = kTRUE;
310     
311     for (Int_t iPID = 0; iPID < nPID; iPID++) {
312       if (fPID[iPID] >= max) {
313         if (fPID[iPID] > max) {
314           allTheSame = kFALSE;
315           max = fPID[iPID];
316           loc = (AODTrkPID_t)iPID;
317         } else {
318           allTheSame = kTRUE;
319         }
320       }
321     }
322     
323     return allTheSame ? kUnknown : loc;
324   } else {
325     return kUnknown;
326   }
327 }
328
329 //______________________________________________________________________________
330 void AliAODTrack::ConvertAliPIDtoAODPID()
331 {
332   // Converts AliPID array.
333   // The numbering scheme is the same for electrons, muons, pions, kaons, and protons.
334   // Everything else has to be set to zero.
335
336   fPID[kDeuteron] = 0.;
337   fPID[kTriton]   = 0.;
338   fPID[kHelium3]  = 0.;
339   fPID[kAlpha]    = 0.;
340   fPID[kUnknown]  = 0.;
341   
342   return;
343 }
344
345
346 //______________________________________________________________________________
347 template <class T> void AliAODTrack::SetP(const T *p, const Bool_t cartesian) 
348 {
349   // Set the momentum
350
351   if (p) {
352     if (cartesian) {
353       Double_t pt2 = p[0]*p[0] + p[1]*p[1];
354       Double_t pp  = TMath::Sqrt(pt2 + p[2]*p[2]);
355       
356       fMomentum[0] = TMath::Sqrt(pt2); // pt
357       fMomentum[1] = (pt2 != 0.) ? TMath::Pi()+TMath::ATan2(-p[1], -p[0]) : -999; // phi
358       fMomentum[2] = (pp != 0.) ? TMath::ACos(p[2] / pp) : -999.; // theta
359     } else {
360       fMomentum[0] = p[0];  // pt
361       fMomentum[1] = p[1];  // phi
362       fMomentum[2] = p[2];  // theta
363     }
364   } else {
365     fMomentum[0] = -999.;
366     fMomentum[1] = -999.;
367     fMomentum[2] = -999.;
368   }
369 }
370
371 //______________________________________________________________________________
372 template <class T> void AliAODTrack::SetPosition(const T *x, const Bool_t dca) 
373 {
374   // set the position
375
376   if (x) {
377     if (!dca) {
378       ResetBit(kIsDCA);
379
380       fPosition[0] = x[0];
381       fPosition[1] = x[1];
382       fPosition[2] = x[2];
383     } else {
384       SetBit(kIsDCA);
385       // don't know any better yet
386       fPosition[0] = -999.;
387       fPosition[1] = -999.;
388       fPosition[2] = -999.;
389     }
390   } else {
391     ResetBit(kIsDCA);
392
393     fPosition[0] = -999.;
394     fPosition[1] = -999.;
395     fPosition[2] = -999.;
396   }
397 }
398
399 //______________________________________________________________________________
400 void AliAODTrack::SetDCA(Double_t d, Double_t z) 
401 {
402   // set the dca
403   fPosition[0] = d;
404   fPosition[1] = z;
405   fPosition[2] = 0.;
406   SetBit(kIsDCA);
407 }
408
409 //______________________________________________________________________________
410 void AliAODTrack::Print(Option_t* /* option */) const
411 {
412   // prints information about AliAODTrack
413
414   printf("Object name: %s   Track type: %s\n", GetName(), GetTitle()); 
415   printf("        px = %f\n", Px());
416   printf("        py = %f\n", Py());
417   printf("        pz = %f\n", Pz());
418   printf("        pt = %f\n", Pt());
419   printf("      1/pt = %f\n", OneOverPt());
420   printf("     theta = %f\n", Theta());
421   printf("       phi = %f\n", Phi());
422   printf("  chi2/NDF = %f\n", Chi2perNDF());
423   printf("    charge = %d\n", Charge());
424   printf(" PID object: %p\n", PID());
425 }
426
427 void AliAODTrack::SetMatchTrigger(Int_t MatchTrigger){
428 //
429 // Set the MUON trigger information
430   switch(MatchTrigger){
431     case 0: // 0 track does not match trigger
432       fITSMuonClusterMap=fITSMuonClusterMap&0x3fffffff;
433       break;
434     case 1: // 1 track match but does not pass pt cut
435       fITSMuonClusterMap=(fITSMuonClusterMap&0x3fffffff)|0x40000000;
436       break;
437     case 2: // 2 track match Low pt cut
438       fITSMuonClusterMap=(fITSMuonClusterMap&0x3fffffff)|0x80000000;
439       break;
440     case 3: // 3 track match High pt cut
441       fITSMuonClusterMap=fITSMuonClusterMap|0xc0000000;
442       break;
443     default:
444       fITSMuonClusterMap=fITSMuonClusterMap&0x3fffffff;
445       printf("AliAODTrack::SetMatchTrigger unknown case for MatchTrigger: %d\n",MatchTrigger);
446   }
447 }
448
449 void AliAODTrack::SetHitsPatternInTrigCh(UShort_t hitsPatternInTrigCh){
450 //
451 // Set the MUON hit pattern (1 bit per chamber) 
452   fITSMuonClusterMap=(fITSMuonClusterMap&0xffff00ff)|(hitsPatternInTrigCh<<8);
453 }
454
455 Int_t AliAODTrack::HitsMT(Int_t istation, Int_t iplane, Char_t *cathode){
456 //
457 // Retrieve hit information for MUON identified by  (station, plane, cathode)
458   if(cathode){
459     if(cathode[0]=='x'||cathode[0]=='X'){
460       if(istation==1){
461         if(iplane==1)
462           return (fITSMuonClusterMap&0x8000)?1:0;
463         else if(iplane==2)
464           return (fITSMuonClusterMap&0x4000)?1:0;
465         else
466           return 0;
467       }else if(istation==2){
468         if(iplane==1)
469           return (fITSMuonClusterMap&0x2000)?1:0;
470         else if(iplane==2)
471           return (fITSMuonClusterMap&0x1000)?1:0;
472         else
473           return 0;
474       }else{
475         return 0;
476       }
477     }else if(cathode[0]=='y'||cathode[0]=='Y'){
478       if(istation==1){
479         if(iplane==1)
480           return (fITSMuonClusterMap&0x0800)?1:0;
481         else if(iplane==2)
482           return (fITSMuonClusterMap&0x0400)?1:0;
483         else
484           return 0;
485       }else if(istation==2){
486         if(iplane==1)
487           return (fITSMuonClusterMap&0x0200)?1:0;
488         else if(iplane==2)
489           return (fITSMuonClusterMap&0x0100)?1:0;
490         else
491           return 0;
492       }else{
493         return 0;
494       }
495     }else{
496       return 0;
497     }
498   }else{
499     if(istation==1){
500       if(iplane==1)
501         return (HitsMT(1,1,"X")||HitsMT(1,1,"Y"))?1:0;
502       else if(iplane==2)
503         return (HitsMT(1,2,"X")||HitsMT(1,2,"Y"))?1:0;
504       else
505         return 0;
506     }else if(istation==2){
507       if(iplane==1)
508         return (HitsMT(2,1,"X")||HitsMT(2,1,"Y"))?1:0;
509       else if(iplane==2)
510         return (HitsMT(2,2,"X")||HitsMT(2,2,"Y"))?1:0;
511       else
512         return 0;
513     }else{
514       return 0;
515     }
516   }
517 }
518
519 Int_t AliAODTrack::HitsMuonChamber(Int_t MuonChamber){
520 // Retrieve hit information for MUON Chamber
521   switch(MuonChamber){
522     case 11:
523       return HitsMT(1,1);
524     case 12:
525       return HitsMT(1,2);
526     case 13:
527       return HitsMT(2,1);
528     case 14:
529       return HitsMT(2,2);
530     default:
531       printf("Unknown MUON chamber: %d\n",MuonChamber);
532       return 0;
533   }
534 }
535
536
537
538 Bool_t AliAODTrack::PropagateTo(Double_t xk, Double_t b) {
539   //----------------------------------------------------------------
540   // Propagate this track to the plane X=xk (cm) in the field "b" (kG)
541   // This is in local coordinates!!!
542   //----------------------------------------------------------------
543
544   Double_t alpha = 0.;
545   Double_t localP[3] = {Px(), Py(), Pz()}; // set global (sic!) p
546   Global2LocalMomentum(localP, Charge(), alpha); // convert global to local momentum
547
548   AliAODVertex *origin = (AliAODVertex*)fProdVertex.GetObject();
549   Double_t localX[3] = {origin->GetX(), origin->GetY(), origin->GetZ()}; // set global (sic!) location of first track point
550   Global2LocalPosition(localX, alpha); // convert global to local position
551
552   Double_t &fX = localX[0];
553
554   Double_t dx=xk-fX;
555   if (TMath::Abs(dx)<=kAlmost0)  return kTRUE;
556
557   Double_t crv=localP[0]*b*kB2C;
558   if (TMath::Abs(b) < kAlmost0Field) crv=0.;
559
560   Double_t f1=localP[1], f2=f1 + crv*dx;
561   if (TMath::Abs(f1) >= kAlmost1) return kFALSE;
562   if (TMath::Abs(f2) >= kAlmost1) return kFALSE;
563
564   Double_t &fP0=localX[1], &fP1=localX[2], &fP2=localP[0], &fP3=localP[1], &fP4=localP[2];
565   /* covariance matrix to be fixed! 
566   Double_t 
567   &fC00=fC[0],
568   &fC10=fC[1],   &fC11=fC[2],  
569   &fC20=fC[3],   &fC21=fC[4],   &fC22=fC[5],
570   &fC30=fC[6],   &fC31=fC[7],   &fC32=fC[8],   &fC33=fC[9],  
571   &fC40=fC[10],  &fC41=fC[11],  &fC42=fC[12],  &fC43=fC[13], &fC44=fC[14];
572   */
573   Double_t r1=TMath::Sqrt(1.- f1*f1), r2=TMath::Sqrt(1.- f2*f2);
574
575   fX=xk;
576   fP0 += dx*(f1+f2)/(r1+r2);
577   fP1 += dx*(r2 + f2*(f1+f2)/(r1+r2))*fP3;
578   fP2 += dx*crv;
579
580   //f = F - 1
581    
582   Double_t f02=    dx/(r1*r1*r1);            Double_t cc=crv/fP4;
583   Double_t f04=0.5*dx*dx/(r1*r1*r1);         f04*=cc;
584   Double_t f12=    dx*fP3*f1/(r1*r1*r1);
585   Double_t f14=0.5*dx*dx*fP3*f1/(r1*r1*r1);  f14*=cc;
586   Double_t f13=    dx/r1;
587   Double_t f24=    dx;                       f24*=cc;
588   
589   /* covariance matrix to be fixed!
590   //b = C*ft
591   Double_t b00=f02*fC20 + f04*fC40, b01=f12*fC20 + f14*fC40 + f13*fC30;
592   Double_t b02=f24*fC40;
593   Double_t b10=f02*fC21 + f04*fC41, b11=f12*fC21 + f14*fC41 + f13*fC31;
594   Double_t b12=f24*fC41;
595   Double_t b20=f02*fC22 + f04*fC42, b21=f12*fC22 + f14*fC42 + f13*fC32;
596   Double_t b22=f24*fC42;
597   Double_t b40=f02*fC42 + f04*fC44, b41=f12*fC42 + f14*fC44 + f13*fC43;
598   Double_t b42=f24*fC44;
599   Double_t b30=f02*fC32 + f04*fC43, b31=f12*fC32 + f14*fC43 + f13*fC33;
600   Double_t b32=f24*fC43;
601   
602   //a = f*b = f*C*ft
603   Double_t a00=f02*b20+f04*b40,a01=f02*b21+f04*b41,a02=f02*b22+f04*b42;
604   Double_t a11=f12*b21+f14*b41+f13*b31,a12=f12*b22+f14*b42+f13*b32;
605   Double_t a22=f24*b42;
606
607   //F*C*Ft = C + (b + bt + a)
608   fC00 += b00 + b00 + a00;
609   fC10 += b10 + b01 + a01; 
610   fC20 += b20 + b02 + a02;
611   fC30 += b30;
612   fC40 += b40;
613   fC11 += b11 + b11 + a11;
614   fC21 += b21 + b12 + a12;
615   fC31 += b31; 
616   fC41 += b41;
617   fC22 += b22 + b22 + a22;
618   fC32 += b32;
619   fC42 += b42;
620   */
621   
622   Local2GlobalMomentum(localP, alpha); // convert local to global momentum
623   SetP(localP);
624
625   return kTRUE;
626 }