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