]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/EMCAL/AliEmcalParticle.cxx
Merge remote-tracking branch 'origin/master' into TPCdev
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliEmcalParticle.cxx
1 // $Id$
2 //
3 // Emcal particle class, which can contain either an AliVTrack or an AliVCluster
4 //
5 // Author: S.Aiola
6
7 #include "AliEmcalParticle.h"
8 #include "AliVCluster.h"
9 #include "AliLog.h"
10
11 //_________________________________________________________________________________________________
12 AliEmcalParticle::AliEmcalParticle() :
13   AliVParticle(),
14   fTrack(0), 
15   fCluster(0),
16   fNMatched(0),
17   fId(-1),
18   fPhi(0),
19   fEta(0),
20   fPt(0)
21 {
22   // Default constructor.
23
24   ResetMatchedObjects();
25 }
26
27 //_________________________________________________________________________________________________
28 AliEmcalParticle::AliEmcalParticle(TObject *particle, Int_t id, Double_t vx, Double_t vy, Double_t vz) :
29   AliVParticle(),
30   fTrack(0), 
31   fCluster(0),
32   fNMatched(0),
33   fId(id),
34   fPhi(0),
35   fEta(0),
36   fPt(0)
37 {
38   // Constructor.
39
40   if (!particle) {
41     AliWarning("Null pointer passed as particle.");
42     return;
43   }
44
45   fTrack = dynamic_cast<AliVTrack*>(particle);
46   if (fTrack) {
47     fEta = fTrack->Eta();
48     fPhi = fTrack->Phi();
49     fPt = fTrack->Pt();
50   } else {
51     fCluster = dynamic_cast<AliVCluster*>(particle);
52     if (fCluster) {
53       Double_t vtx[3]; vtx[0]=vx;vtx[1]=vy;vtx[2]=vz;
54       TLorentzVector vect;
55       fCluster->GetMomentum(vect, vtx);
56       fEta = vect.Eta();
57       fPhi = vect.Phi();
58       fPt  = vect.Pt();
59     }
60   }
61
62   if (!fTrack && !fCluster) {
63     AliWarning("Particle type not recognized (not AliVTrack nor AliVCluster).");
64     return;
65   }
66
67   ResetMatchedObjects();
68 }
69   
70 //_________________________________________________________________________________________________
71 AliEmcalParticle::AliEmcalParticle(const AliEmcalParticle &p) :
72   AliVParticle(p),
73   fTrack(p.fTrack),
74   fCluster(p.fCluster), 
75   fNMatched(p.fNMatched),
76   fId(p.fId),
77   fPhi(p.fPhi),
78   fEta(p.fEta),
79   fPt(p.fPt)
80 {
81   // Copy constructor.
82
83   ResetMatchedObjects();
84
85   memcpy(fMatchedIds, p.fMatchedIds, sizeof(UShort_t) * fSizeMatched);
86   memcpy(fMatchedDist, p.fMatchedDist, sizeof(Double_t) * fSizeMatched);
87 }
88
89 //_________________________________________________________________________________________________
90 AliEmcalParticle::~AliEmcalParticle()
91 {
92   // Destructor.
93 }
94
95 //_________________________________________________________________________________________________
96 AliEmcalParticle &AliEmcalParticle::operator=(const AliEmcalParticle &p)
97 {
98   // Assignment operator.
99
100   if (this != &p) {
101     fTrack    = p.fTrack;
102     fCluster  = p.fCluster;
103     fNMatched = p.fNMatched;
104     fId       = p.fId;
105     fPhi      = p.fPhi;
106     fEta      = p.fEta;
107     fPt       = p.fPt;
108
109     ResetMatchedObjects();
110     memcpy(fMatchedIds,  p.fMatchedIds,  sizeof(UShort_t) * fSizeMatched);
111     memcpy(fMatchedDist, p.fMatchedDist, sizeof(Double_t) * fSizeMatched);
112   }
113
114   return *this;
115 }
116
117 //_________________________________________________________________________________________________
118 void AliEmcalParticle::ResetMatchedObjects()
119 {
120   // Reset matched objects.
121
122   for (Int_t i = 0; i < fSizeMatched; i++) {
123     fMatchedIds[i] = -1;
124     fMatchedDist[i] = 999;
125   }
126 }
127
128 //_________________________________________________________________________________________________
129 void AliEmcalParticle::AddMatchedObj(Int_t id, Double_t d)
130 {
131   // Add a matched object.
132
133   Int_t i = 0;
134   while (i < fNMatched && d > fMatchedDist[i])
135     ++i;
136   
137   if (i < fNMatched) {
138     memmove(fMatchedIds  + i + 1, fMatchedIds  + i, sizeof(UShort_t) * (fNMatched - i));
139     memmove(fMatchedDist + i + 1, fMatchedDist + i, sizeof(Double_t) * (fNMatched - i));
140   }
141   
142   fMatchedIds[i]  = id;
143   fMatchedDist[i] = d;
144   ++fNMatched;
145
146   if (fNMatched >= fSizeMatched)
147     fNMatched = fSizeMatched - 1;
148 }
149
150 //_________________________________________________________________________________________________
151 TLorentzVector &AliEmcalParticle::GetLorentzVector(const Double_t *vertex) const
152 {
153   // Make a TLorentzVector and return it.
154
155   static TLorentzVector vect;
156
157   if (fTrack) {
158     vect.SetPtEtaPhiM(fTrack->Pt(), fTrack->Eta(), fTrack->Phi(), M());
159   }
160   else if (fCluster && vertex) {
161     fCluster->GetMomentum(vect, const_cast<Double_t*>(vertex));
162   }
163
164   return vect;
165 }