]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/EMCAL/AliParticleContainer.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliParticleContainer.cxx
CommitLineData
9239b066 1// $Id$
e58333e0 2//
9239b066 3// Container with name, TClonesArray and cuts for particles
e58333e0 4//
5// Author: M. Verweij
6
e58333e0 7#include <TClonesArray.h>
6421eeb0 8
e58333e0 9#include "AliVEvent.h"
10#include "AliLog.h"
11
12#include "AliParticleContainer.h"
13
14ClassImp(AliParticleContainer)
15
16//________________________________________________________________________
17AliParticleContainer::AliParticleContainer():
18 AliEmcalContainer("AliParticleContainer"),
19 fParticlePtCut(0.15),
20 fParticleMinEta(-0.9),
21 fParticleMaxEta(0.9),
22 fParticleMinPhi(-10),
23 fParticleMaxPhi(10),
24 fTrackBitMap(0),
25 fMCTrackBitMap(0),
bf9072ca 26 fMinMCLabel(0),
27 fMCFlag(0),
82aa1543 28 fGeneratorIndex(-1),
29 fCharge(-1)
e58333e0 30{
31 // Default constructor.
32
b6f970ad 33 fClassName = "AliVParticle";
e58333e0 34}
35
36//________________________________________________________________________
37AliParticleContainer::AliParticleContainer(const char *name):
38 AliEmcalContainer(name),
39 fParticlePtCut(0.15),
40 fParticleMinEta(-0.9),
41 fParticleMaxEta(0.9),
42 fParticleMinPhi(-10),
43 fParticleMaxPhi(10),
44 fTrackBitMap(0),
45 fMCTrackBitMap(0),
bf9072ca 46 fMinMCLabel(0),
47 fMCFlag(0),
82aa1543 48 fGeneratorIndex(-1),
49 fCharge(-1)
e58333e0 50{
51 // Standard constructor.
52
b6f970ad 53 fClassName = "AliVParticle";
e58333e0 54}
55
56//________________________________________________________________________
b6f970ad 57AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt)
e58333e0 58{
6421eeb0 59 // Get the leading particle; use p if "p" is contained in opt
e58333e0 60
6421eeb0 61 TString option(opt);
62 option.ToLower();
63
b6f970ad 64 Int_t tempID = fCurrentID;
65
6421eeb0 66 AliVParticle *partMax = GetNextAcceptParticle(0);
67 AliVParticle *part = 0;
68
69 if (option.Contains("p")) {
70 while ((part = GetNextAcceptParticle())) {
71 if (part->P() > partMax->P()) partMax = part;
72 }
73 }
74 else {
75 while ((part = GetNextAcceptParticle())) {
76 if (part->Pt() > partMax->Pt()) partMax = part;
77 }
78 }
e58333e0 79
b6f970ad 80 fCurrentID = tempID;
81
6421eeb0 82 return partMax;
e58333e0 83}
84
85//________________________________________________________________________
37509f02
CL
86AliVParticle* AliParticleContainer::GetParticle(Int_t i) const
87{
e58333e0 88 //Get i^th jet in array
89
db2fb8aa 90 if(i<0 || i>=fClArray->GetEntriesFast()) return 0;
e58333e0 91 AliVParticle *vp = static_cast<AliVParticle*>(fClArray->At(i));
92 return vp;
93
94}
95
96//________________________________________________________________________
97AliVParticle* AliParticleContainer::GetAcceptParticle(Int_t i) const {
98 //return pointer to particle if particle is accepted
99
100 AliVParticle *vp = GetParticle(i);
101 if(!vp) return 0;
102
103 if(AcceptParticle(vp))
82aa1543 104 return vp;
e58333e0 105 else {
106 AliDebug(2,"Particle not accepted.");
107 return 0;
108 }
109}
110
ef46ebe5 111//________________________________________________________________________
37509f02
CL
112AliVParticle* AliParticleContainer::GetParticleWithLabel(Int_t lab) const
113{
ef46ebe5 114 //Get particle with label lab in array
115
116 Int_t i = GetIndexFromLabel(lab);
117 return GetParticle(i);
118}
119
120//________________________________________________________________________
37509f02
CL
121AliVParticle* AliParticleContainer::GetAcceptParticleWithLabel(Int_t lab) const
122{
ef46ebe5 123 //Get particle with label lab in array
124
125 Int_t i = GetIndexFromLabel(lab);
126 return GetAcceptParticle(i);
127}
128
bf9072ca 129
6421eeb0 130//________________________________________________________________________
37509f02
CL
131AliVParticle* AliParticleContainer::GetNextAcceptParticle(Int_t i)
132{
6421eeb0 133 //Get next accepted particle; if i >= 0 (re)start counter from i; return 0 if no accepted particle could be found
134
b6f970ad 135 if (i>=0) fCurrentID = i;
6421eeb0 136
137 const Int_t n = GetNEntries();
138 AliVParticle *p = 0;
b6f970ad 139 while (fCurrentID < n && !p) {
140 p = GetAcceptParticle(fCurrentID);
141 fCurrentID++;
6421eeb0 142 }
143
144 return p;
145}
146
ef46ebe5 147//________________________________________________________________________
37509f02
CL
148AliVParticle* AliParticleContainer::GetNextParticle(Int_t i)
149{
ef46ebe5 150 //Get next particle; if i >= 0 (re)start counter from i; return 0 if no particle could be found
151
152 if (i>=0) fCurrentID = i;
153
154 const Int_t n = GetNEntries();
155 AliVParticle *p = 0;
156 while (fCurrentID < n && !p) {
157 p = GetParticle(fCurrentID);
158 fCurrentID++;
159 }
160
161 return p;
162}
163
6421eeb0 164//________________________________________________________________________
165void AliParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i) const
166{
167 //Get momentum of the i^th particle in array
168
169 AliVParticle *vp = GetParticle(i);
170 if(vp) mom.SetPtEtaPhiM(vp->Pt(),vp->Eta(),vp->Phi(),0.139);
171}
172
e58333e0 173//________________________________________________________________________
174Bool_t AliParticleContainer::AcceptParticle(AliVParticle *vp) const
175{
176 // Return true if vp is accepted.
177
178 if (!vp)
179 return kFALSE;
180
181 if (TMath::Abs(vp->GetLabel()) > fMinMCLabel) {
182 if(vp->TestBits(fMCTrackBitMap) != (Int_t)fMCTrackBitMap) {
183 AliDebug(2,"MC particle not accepted because of MC bit map.");
184 return kFALSE;
185 }
186 }
187 else {
188 if(vp->TestBits(fTrackBitMap) != (Int_t)fTrackBitMap) {
189 AliDebug(2,"Track not accepted because of bit map.");
190 return kFALSE;
191 }
192 }
193
194 if (vp->Pt() < fParticlePtCut)
195 return kFALSE;
196
197 if (vp->Eta() < fParticleMinEta || vp->Eta() > fParticleMaxEta ||
198 vp->Phi() < fParticleMinPhi || vp->Phi() > fParticleMaxPhi)
199 return kFALSE;
bf9072ca 200
201 if ((vp->GetFlag() & fMCFlag) != fMCFlag)
202 return kFALSE;
203
204 if (fGeneratorIndex >= 0 && fGeneratorIndex != vp->GetGeneratorIndex())
205 return kFALSE;
82aa1543 206
207 if (fCharge>=0 && fCharge != vp->Charge() )
208 return kFALSE;
e58333e0 209
210 return kTRUE;
211}
b6f970ad 212
8612dfc8 213//________________________________________________________________________
214Int_t AliParticleContainer::GetNAcceptedParticles()
215{
37509f02 216 // Get number of accepted particles
8612dfc8 217
218 Int_t nPart = 0;
219
220 AliVParticle *vp = GetNextAcceptParticle(0);
221 if(vp) nPart = 1;
222 while (GetNextAcceptParticle())
223 nPart++;
224
225 return nPart;
226}
227
b6f970ad 228//________________________________________________________________________
229void AliParticleContainer::SetClassName(const char *clname)
230{
231 // Set the class name
232
233 TClass cls(clname);
234 if (cls.InheritsFrom("AliVParticle")) fClassName = clname;
235 else AliError(Form("Unable to set class name %s for a AliParticleContainer, it must inherits from AliVParticle!",clname));
236}