create general emcal task lib
[u/mrichter/AliRoot.git] / PWG / EMCAL / 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() :
4e04e015 13 AliVParticle(),
d11dc2a6 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) :
4e04e015 29 AliVParticle(),
d11dc2a6 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
af0280a9 40 if (!particle) {
d11dc2a6 41 AliWarning("Null pointer passed as particle.");
af0280a9 42 return;
43 }
d11dc2a6 44
d11dc2a6 45 fTrack = dynamic_cast<AliVTrack*>(particle);
46dd554b 46 if (fTrack) {
47 fEta = fTrack->Eta();
48 fPhi = fTrack->Phi();
49 fPt = fTrack->Pt();
50 } else {
d11dc2a6 51 fCluster = dynamic_cast<AliVCluster*>(particle);
af0280a9 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 }
46dd554b 60 }
af0280a9 61
62 if (!fTrack && !fCluster) {
d11dc2a6 63 AliWarning("Particle type not recognized (not AliVTrack nor AliVCluster).");
af0280a9 64 return;
65 }
d11dc2a6 66
67 ResetMatchedObjects();
68}
69
70//_________________________________________________________________________________________________
71AliEmcalParticle::AliEmcalParticle(const AliEmcalParticle &p) :
4e04e015 72 AliVParticle(p),
d11dc2a6 73 fTrack(p.fTrack),
74 fCluster(p.fCluster),
75 fNMatched(p.fNMatched),
46dd554b 76 fId(p.fId),
77 fPhi(p.fPhi),
78 fEta(p.fEta),
79 fPt(p.fPt)
d11dc2a6 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//_________________________________________________________________________________________________
90AliEmcalParticle::~AliEmcalParticle()
91{
92 // Destructor.
93}
94
95//_________________________________________________________________________________________________
96AliEmcalParticle &AliEmcalParticle::operator=(const AliEmcalParticle &p)
97{
98 // Assignment operator.
99
100 if (this != &p) {
46dd554b 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
d11dc2a6 109 ResetMatchedObjects();
4e04e015 110 memcpy(fMatchedIds, p.fMatchedIds, sizeof(UShort_t) * fSizeMatched);
d11dc2a6 111 memcpy(fMatchedDist, p.fMatchedDist, sizeof(Double_t) * fSizeMatched);
112 }
113
114 return *this;
115}
116
117//_________________________________________________________________________________________________
118void 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//_________________________________________________________________________________________________
129void 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])
41eac91c 135 ++i;
d11dc2a6 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;
41eac91c 144 ++fNMatched;
d11dc2a6 145
146 if (fNMatched >= fSizeMatched)
147 fNMatched = fSizeMatched - 1;
148}
149
150//_________________________________________________________________________________________________
151TLorentzVector &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}