]>
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), |
59a3310e | 20 | fM(0), |
02357c1c | 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), |
59a3310e | 38 | fM(0), |
02357c1c | 39 | fMatchedPtr(0) |
d11dc2a6 | 40 | { |
41 | // Constructor. | |
42 | ||
af0280a9 | 43 | if (!particle) { |
d11dc2a6 | 44 | AliWarning("Null pointer passed as particle."); |
af0280a9 | 45 | return; |
46 | } | |
d11dc2a6 | 47 | |
d11dc2a6 | 48 | fTrack = dynamic_cast<AliVTrack*>(particle); |
46dd554b | 49 | if (fTrack) { |
50 | fEta = fTrack->Eta(); | |
51 | fPhi = fTrack->Phi(); | |
59a3310e | 52 | fPt = fTrack->Pt(); |
53 | fM = fTrack->M(); | |
46dd554b | 54 | } else { |
d11dc2a6 | 55 | fCluster = dynamic_cast<AliVCluster*>(particle); |
af0280a9 | 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(); | |
59a3310e | 63 | fM = 0.; |
af0280a9 | 64 | } |
46dd554b | 65 | } |
af0280a9 | 66 | |
67 | if (!fTrack && !fCluster) { | |
d11dc2a6 | 68 | AliWarning("Particle type not recognized (not AliVTrack nor AliVCluster)."); |
af0280a9 | 69 | return; |
70 | } | |
d11dc2a6 | 71 | |
72 | ResetMatchedObjects(); | |
73 | } | |
74 | ||
75 | //_________________________________________________________________________________________________ | |
76 | AliEmcalParticle::AliEmcalParticle(const AliEmcalParticle &p) : | |
4e04e015 | 77 | AliVParticle(p), |
d11dc2a6 | 78 | fTrack(p.fTrack), |
79 | fCluster(p.fCluster), | |
80 | fNMatched(p.fNMatched), | |
46dd554b | 81 | fId(p.fId), |
82 | fPhi(p.fPhi), | |
83 | fEta(p.fEta), | |
02357c1c | 84 | fPt(p.fPt), |
59a3310e | 85 | fM(p.fM), |
02357c1c | 86 | fMatchedPtr(p.fMatchedPtr) |
d11dc2a6 | 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) { | |
02357c1c | 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; | |
59a3310e | 115 | fM = p.fM; |
02357c1c | 116 | fMatchedPtr = p.fMatchedPtr; |
46dd554b | 117 | |
d11dc2a6 | 118 | ResetMatchedObjects(); |
4e04e015 | 119 | memcpy(fMatchedIds, p.fMatchedIds, sizeof(UShort_t) * fSizeMatched); |
d11dc2a6 | 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]) | |
41eac91c | 144 | ++i; |
d11dc2a6 | 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; | |
41eac91c | 153 | ++fNMatched; |
d11dc2a6 | 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) { | |
59a3310e | 167 | vect.SetPtEtaPhiM(fPt, fEta, fPhi, fM); |
d11dc2a6 | 168 | } |
169 | else if (fCluster && vertex) { | |
170 | fCluster->GetMomentum(vect, const_cast<Double_t*>(vertex)); | |
171 | } | |
172 | ||
173 | return vect; | |
174 | } |