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