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