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