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