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