]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/EMCAL/AliParticleContainer.cxx
Removed depricated analysis framework, ie renamed
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliParticleContainer.cxx
1 // $Id$
2 //
3 // Container with name, TClonesArray and cuts for particles
4 //
5 // Author: M. Verweij
6
7 #include <TClonesArray.h>
8
9 #include "AliVEvent.h"
10 #include "AliLog.h"
11
12 #include "AliParticleContainer.h"
13
14 ClassImp(AliParticleContainer)
15
16 //________________________________________________________________________
17 AliParticleContainer::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
30   fClassName = "AliVParticle";
31 }
32
33 //________________________________________________________________________
34 AliParticleContainer::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
47   fClassName = "AliVParticle";
48 }
49
50 //________________________________________________________________________
51 AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt) 
52 {
53   // Get the leading particle; use p if "p" is contained in opt
54
55   TString option(opt);
56   option.ToLower();
57
58   Int_t tempID = fCurrentID;
59
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   }
73
74   fCurrentID = tempID;
75
76   return partMax;
77 }
78
79 //________________________________________________________________________
80 AliVParticle* 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 //________________________________________________________________________
91 AliVParticle* 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
105 //________________________________________________________________________
106 AliVParticle* 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 //________________________________________________________________________
115 AliVParticle* 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
123 //________________________________________________________________________
124 AliVParticle* AliParticleContainer::GetNextAcceptParticle(Int_t i) {
125
126   //Get next accepted particle; if i >= 0 (re)start counter from i; return 0 if no accepted particle could be found
127
128   if (i>=0) fCurrentID = i;
129
130   const Int_t n = GetNEntries();
131   AliVParticle *p = 0;
132   while (fCurrentID < n && !p) { 
133     p = GetAcceptParticle(fCurrentID);
134     fCurrentID++;
135   }
136
137   return p;
138 }
139
140 //________________________________________________________________________
141 AliVParticle* 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
157 //________________________________________________________________________
158 void 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
166 //________________________________________________________________________
167 Bool_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 }
196
197 //________________________________________________________________________
198 void AliParticleContainer::SetClassName(const char *clname)
199 {
200   // Set the class name
201
202   TClass cls(clname);
203   if (cls.InheritsFrom("AliVParticle")) fClassName = clname;
204   else AliError(Form("Unable to set class name %s for a AliParticleContainer, it must inherits from AliVParticle!",clname));
205 }