AliPhysics  de71be2 (de71be2)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AliMCParticleContainer.cxx
Go to the documentation of this file.
1 //
2 // Container with name, TClonesArray and cuts for particles
3 //
4 // Author: M. Verweij, S. Aiola
5 
6 #include <TClonesArray.h>
7 
8 #include "AliVEvent.h"
9 #include "AliLog.h"
10 
11 #include "AliTLorentzVector.h"
12 #include "AliMCParticleContainer.h"
13 
15 
16 //________________________________________________________________________
19  fMCFlag(AliAODMCParticle::kPhysicalPrim)
20 {
21  // Default constructor.
22 
23  fClassName = "AliAODMCParticle";
24 }
25 
26 //________________________________________________________________________
29  fMCFlag(AliAODMCParticle::kPhysicalPrim)
30 {
31  // Standard constructor.
32 
33  fClassName = "AliAODMCParticle";
34 }
35 
36 //________________________________________________________________________
37 AliAODMCParticle* AliMCParticleContainer::GetMCParticleWithLabel(Int_t lab) const
38 {
39  //Get particle with label lab in array
40 
41  Int_t i = GetIndexFromLabel(lab);
42  return GetMCParticle(i);
43 }
44 
45 //________________________________________________________________________
47 {
48  //Get particle with label lab in array
49 
50  Int_t i = GetIndexFromLabel(lab);
51  return GetAcceptMCParticle(i);
52 }
53 
54 //________________________________________________________________________
55 AliAODMCParticle* AliMCParticleContainer::GetMCParticle(Int_t i) const
56 {
57  //Get i^th jet in array
58 
59  if (i == -1) i = fCurrentID;
60  if (i < 0 || i >= fClArray->GetEntriesFast()) return 0;
61  AliAODMCParticle *vp = static_cast<AliAODMCParticle*>(fClArray->At(i));
62  return vp;
63 }
64 
65 //________________________________________________________________________
67 {
68  //return pointer to particle if particle is accepted
69 
70  if (i == -1) i = fCurrentID;
71  if (AcceptMCParticle(i)) {
72  return GetMCParticle(i);
73  }
74  else {
75  AliDebug(2,"Particle not accepted.");
76  return 0;
77  }
78 }
79 
80 //________________________________________________________________________
82 {
83  //Get next accepted particle; if i >= 0 (re)start counter from i; return 0 if no accepted particle could be found
84 
85  if (i >= 0) fCurrentID = i;
86 
87  const Int_t n = GetNEntries();
88 
89  AliAODMCParticle *p = 0;
90  do {
91  fCurrentID++;
92  if (fCurrentID >= n) break;
94  } while (!p);
95 
96  return p;
97 }
98 
99 //________________________________________________________________________
101 {
102  //Get next particle; if i >= 0 (re)start counter from i; return 0 if no particle could be found
103 
104  if (i >= 0) fCurrentID = i;
105 
106  const Int_t n = GetNEntries();
107  AliAODMCParticle *p = 0;
108  do {
109  fCurrentID++;
110  if (fCurrentID >= n) break;
112  } while (!p);
113 
114  return p;
115 }
116 
117 //________________________________________________________________________
118 Bool_t AliMCParticleContainer::GetMomentum(TLorentzVector &mom, const AliAODMCParticle* part, Double_t mass)
119 {
120  if (part) {
121  if (mass < 0) mass = part->M();
122  mom.SetPtEtaPhiM(part->Pt(), part->Eta(), part->Phi(), mass);
123  return kTRUE;
124  }
125  else {
126  mom.SetPtEtaPhiM(0, 0, 0, 0);
127  return kFALSE;
128  }
129 }
130 
131 //________________________________________________________________________
132 Bool_t AliMCParticleContainer::GetMomentum(TLorentzVector &mom, const AliAODMCParticle* part)
133 {
134  return GetMomentum(mom,part,fMassHypothesis);
135 }
136 
137 //________________________________________________________________________
138 Bool_t AliMCParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i)
139 {
140  //Get momentum of the i^th particle in array
141 
142  Double_t mass = fMassHypothesis;
143 
144  if (i == -1) i = fCurrentID;
145  AliAODMCParticle *vp = GetMCParticle(i);
146  if (vp) {
147  if (mass < 0) mass = vp->M();
148  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
149  return kTRUE;
150  }
151  else {
152  mom.SetPtEtaPhiM(0, 0, 0, 0);
153  return kFALSE;
154  }
155 }
156 
157 //________________________________________________________________________
158 Bool_t AliMCParticleContainer::GetNextMomentum(TLorentzVector &mom, Int_t i)
159 {
160  //Get momentum of the i^th particle in array
161 
162  Double_t mass = fMassHypothesis;
163 
164  AliAODMCParticle *vp = GetNextMCParticle(i);
165  if (vp) {
166  if (mass < 0) mass = vp->M();
167  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
168  return kTRUE;
169  }
170  else {
171  mom.SetPtEtaPhiM(0, 0, 0, 0);
172  return kFALSE;
173  }
174 }
175 
176 //________________________________________________________________________
177 Bool_t AliMCParticleContainer::GetAcceptMomentum(TLorentzVector &mom, Int_t i)
178 {
179  //Get momentum of the i^th particle in array
180 
181  Double_t mass = fMassHypothesis;
182 
183  if (i == -1) i = fCurrentID;
184  AliAODMCParticle *vp = GetAcceptMCParticle(i);
185  if (vp) {
186  if (mass < 0) mass = vp->M();
187  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
188  return kTRUE;
189  }
190  else {
191  mom.SetPtEtaPhiM(0, 0, 0, 0);
192  return kFALSE;
193  }
194 }
195 
196 //________________________________________________________________________
197 Bool_t AliMCParticleContainer::GetNextAcceptMomentum(TLorentzVector &mom, Int_t i)
198 {
199  //Get momentum of the i^th particle in array
200 
201  Double_t mass = fMassHypothesis;
202 
203  AliAODMCParticle *vp = GetNextAcceptMCParticle(i);
204  if (vp) {
205  if (mass < 0) mass = vp->M();
206  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
207  return kTRUE;
208  }
209  else {
210  mom.SetPtEtaPhiM(0, 0, 0, 0);
211  return kFALSE;
212  }
213 }
214 
215 //________________________________________________________________________
216 Bool_t AliMCParticleContainer::AcceptMCParticle(const AliAODMCParticle *vp)
217 {
218  // Return true if vp is accepted.
219  Bool_t r = ApplyMCParticleCuts(vp);
220  if (!r) return kFALSE;
221 
222  AliTLorentzVector mom;
223 
224  Int_t id = fClArray->IndexOf(vp);
225  if (id >= 0) {
226  GetMomentum(mom, id);
227  }
228  else {
229  GetMomentum(mom, vp);
230  }
231 
232  return ApplyKinematicCuts(mom);
233 }
234 
235 //________________________________________________________________________
237 {
238  // Return true if vp is accepted.
239  Bool_t r = ApplyMCParticleCuts(GetMCParticle(i));
240  if (!r) return kFALSE;
241 
242  AliTLorentzVector mom;
243  GetMomentum(mom, i);
244 
245  return ApplyKinematicCuts(mom);
246 }
247 
248 //________________________________________________________________________
249 Bool_t AliMCParticleContainer::ApplyMCParticleCuts(const AliAODMCParticle* vp)
250 {
251  // Return true if i^th particle is accepted.
252 
253  fRejectionReason = 0;
254 
255  // Cuts on the particle properties
256 
257  if ((vp->GetFlag() & fMCFlag) != fMCFlag) {
259  return kFALSE;
260  }
261 
262  return ApplyParticleCuts(vp);
263 }
264 
265 //________________________________________________________________________
266 void AliMCParticleContainer::SetClassName(const char *clname)
267 {
268  // Set the class name
269 
270  TClass cls(clname);
271  if (cls.InheritsFrom("AliAODMCParticle")) fClassName = clname;
272  else AliError(Form("Unable to set class name %s for a AliMCParticleContainer, it must inherits from AliAODMCParticle!",clname));
273 }
274 
275 //________________________________________________________________________
277 {
278  static TString trackString;
279 
280  if (GetMinPt() == 0) {
281  trackString = TString::Format("%s_pT0000", GetArrayName().Data());
282  }
283  else if (GetMinPt() < 1.0) {
284  trackString = TString::Format("%s_pT0%3.0f", GetArrayName().Data(), GetMinPt()*1000.0);
285  }
286  else {
287  trackString = TString::Format("%s_pT%4.0f", GetArrayName().Data(), GetMinPt()*1000.0);
288  }
289 
290  return trackString.Data();
291 }
virtual AliAODMCParticle * GetNextMCParticle(Int_t i=-1)
virtual AliAODMCParticle * GetMCParticle(Int_t i=-1) const
Int_t GetIndexFromLabel(Int_t lab) const
Double_t mass
virtual Bool_t GetAcceptMomentum(TLorentzVector &mom, Int_t i)
virtual Bool_t ApplyMCParticleCuts(const AliAODMCParticle *vp)
virtual Bool_t ApplyParticleCuts(const AliVParticle *vp)
virtual Bool_t GetNextMomentum(TLorentzVector &mom, Int_t i=-1)
UInt_t fRejectionReason
event vertex array
Double_t GetMinPt() const
virtual AliAODMCParticle * GetAcceptMCParticleWithLabel(Int_t lab)
const char * GetTitle() const
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
virtual Bool_t GetNextAcceptMomentum(TLorentzVector &mom, Int_t i=-1)
ClassImp(AliParticleContainer) AliMCParticleContainer
const TString & GetArrayName() const
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom)
virtual AliAODMCParticle * GetNextAcceptMCParticle(Int_t i=-1)
virtual Bool_t AcceptMCParticle(const AliAODMCParticle *vp)
void SetClassName(const char *clname)
virtual Bool_t GetMomentum(TLorentzVector &mom, const AliAODMCParticle *part, Double_t mass)
TClonesArray * fClArray
Int_t GetNEntries() const
Int_t fCurrentID
TClonesArray.
virtual AliAODMCParticle * GetMCParticleWithLabel(Int_t lab) const
virtual AliAODMCParticle * GetAcceptMCParticle(Int_t i=-1)