AliPhysics  63e47e1 (63e47e1)
AliEmcalContainer.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 #include <TClonesArray.h>
16 #include "AliVEvent.h"
17 #include "AliLog.h"
18 #include "AliNamedArrayI.h"
19 #include "AliVParticle.h"
20 #include "AliTLorentzVector.h"
21 
22 #include "AliEmcalContainerUtils.h"
23 
24 #include "AliEmcalContainer.h"
25 
27 ClassImp(AliEmcalContainer);
29 
35 AliEmcalContainer::AliEmcalContainer():
36  TObject(),
37  fName(),
38  fClArrayName(),
39  fBaseClassName(),
40  fIsParticleLevel(kFALSE),
41  fBitMap(0),
42  fMinPt(0.15),
43  fMaxPt(1000.),
44  fMaxE(1000.),
45  fMinE(0.),
46  fMinEta(-0.9),
47  fMaxEta(0.9),
48  fMinPhi(-10),
49  fMaxPhi(10),
50  fMinMCLabel(-1),
51  fMaxMCLabel(-1),
52  fMassHypothesis(-1),
53  fIsEmbedding(kFALSE),
54  fClArray(0),
55  fCurrentID(0),
56  fLabelMap(0),
57  fLoadedClass(0),
58  fClassName()
59 {
60  fVertex[0] = 0;
61  fVertex[1] = 0;
62  fVertex[2] = 0;
63 }
64 
72 AliEmcalContainer::AliEmcalContainer(const char *name):
73  TObject(),
74  fName(name),
75  fClArrayName(name),
76  fBaseClassName(),
77  fIsParticleLevel(kFALSE),
78  fBitMap(0),
79  fMinPt(0.15),
80  fMaxPt(1000.),
81  fMaxE(1000.),
82  fMinE(0.),
83  fMinEta(-0.9),
84  fMaxEta(0.9),
85  fMinPhi(-10),
86  fMaxPhi(10),
87  fMinMCLabel(-1),
88  fMaxMCLabel(-1),
89  fMassHypothesis(-1),
90  fIsEmbedding(kFALSE),
91  fClArray(0),
92  fCurrentID(0),
93  fLabelMap(0),
94  fLoadedClass(0),
95  fClassName()
96 {
97  fVertex[0] = 0;
98  fVertex[1] = 0;
99  fVertex[2] = 0;
100 }
101 
108 TObject *AliEmcalContainer::operator[](int index) const {
109  if(index >= 0 && index < GetNEntries()) return fClArray->At(index);
110  return NULL;
111 }
112 
117 void AliEmcalContainer::SetClassName(const char *clname)
118 {
119  TClass cls(clname);
120  if (cls.InheritsFrom(fBaseClassName)) {
121  fClassName = clname;
122  }
123  else {
124  AliError(Form("Unable to set class name %s for this container, it must inherits from %s!",clname,fBaseClassName.Data()));
125  }
126 }
127 
132 void AliEmcalContainer::GetVertexFromEvent(const AliVEvent * event)
133 {
134  const AliVVertex *vertex = event->GetPrimaryVertex();
135  if (vertex) vertex->GetXYZ(fVertex);
136 }
137 
143 void AliEmcalContainer::SetArray(const AliVEvent *event)
144 {
145  // Handling of default containers
146  if(fClArrayName == "usedefault"){
147  fClArrayName = GetDefaultArrayName(event);
148  }
149 
150  // Get the right event (either the current event of the embedded event)
151  event = AliEmcalContainerUtils::GetEvent(event, fIsEmbedding);
152 
153  if (!event) return;
154 
155  GetVertexFromEvent(event);
156 
157  if (!fClArrayName.IsNull() && !fClArray) {
158  fClArray = dynamic_cast<TClonesArray*>(event->FindListObject(fClArrayName));
159  if (!fClArray) {
160  AliError(Form("%s: Could not retrieve array with name %s!", GetName(), fClArrayName.Data()));
161  return;
162  }
163  } else {
164  return;
165  }
166 
167  fLoadedClass = fClArray->GetClass();
168 
169  if (!fClassName.IsNull()) {
170  if (!fLoadedClass->InheritsFrom(fClassName)) {
171  AliError(Form("%s: Objects of type %s in %s are not inherited from %s!",
172  GetName(), fLoadedClass->GetName(), fClArrayName.Data(), fClassName.Data()));
173  fClArray = 0;
174  fLoadedClass = 0;
175  }
176  }
177 
178  fLabelMap = dynamic_cast<AliNamedArrayI*>(event->FindListObject(fClArrayName + "_Map"));
179 }
180 
185 void AliEmcalContainer::NextEvent(const AliVEvent * event)
186 {
187  // Get the right event (either the current event of the embedded event)
188  event = AliEmcalContainerUtils::GetEvent(event, fIsEmbedding);
189 
190  if (!event) return;
191 
192  GetVertexFromEvent(event);
193 }
194 
199 Int_t AliEmcalContainer::GetNAcceptEntries() const{
200  Int_t result = 0;
201  for(int index = 0; index < GetNEntries(); index++){
202  UInt_t rejectionReason = 0;
203  if(AcceptObject(index, rejectionReason)) result++;
204  }
205  return result;
206 }
207 
213 Int_t AliEmcalContainer::GetIndexFromLabel(Int_t lab) const
214 {
215  if (fLabelMap) {
216  if (lab < fLabelMap->GetSize()) {
217  return fLabelMap->At(lab);
218  }
219  else {
220  AliDebug(3,Form("%s_AliEmcalContainer::GetIndexFromLabel - Label not found in the map, returning -1...",fClArrayName.Data()));
221  return -1;
222  }
223  }
224  else {
225  AliDebug(3,Form("%s_AliEmcalContainer::GetIndexFromLabel - No index-label map found, returning label...",fClArrayName.Data()));
226  return lab;
227  }
228 }
229 
235 UShort_t AliEmcalContainer::GetRejectionReasonBitPosition(UInt_t rejectionReason)
236 {
237  UInt_t rs = rejectionReason;
238  UShort_t p = 0;
239  while (rs >>= 1) { p++; }
240  return p;
241 }
242 
250 Bool_t AliEmcalContainer::SamePart(const AliVParticle* part1, const AliVParticle* part2, Double_t dist)
251 {
252  if(!part1) return kFALSE;
253  if(!part2) return kFALSE;
254  Double_t dPhi = TMath::Abs(part1->Phi() - part2->Phi());
255  Double_t dEta = TMath::Abs(part1->Eta() - part2->Eta());
256  Double_t dpT = TMath::Abs(part1->Pt() - part2->Pt());
257  dPhi = TVector2::Phi_mpi_pi(dPhi);
258  if (dPhi > dist) return kFALSE;
259  if (dEta > dist) return kFALSE;
260  if (dpT > dist) return kFALSE;
261  return kTRUE;
262 }
263 
273 Bool_t AliEmcalContainer::ApplyKinematicCuts(const AliTLorentzVector& mom, UInt_t &rejectionReason) const
274 {
275  if (mom.Pt() < fMinPt || mom.Pt() > fMaxPt) {
276  rejectionReason |= kPtCut;
277  return kFALSE;
278  }
279 
280  if (mom.E() < fMinE || mom.E() > fMaxE) {
281  rejectionReason |= kPtCut;
282  return kFALSE;
283  }
284 
285  Double_t eta = mom.Eta();
286  Double_t phi = mom.Phi_0_2pi();
287 
288  if (fMinEta < fMaxEta && (eta < fMinEta || eta > fMaxEta)) {
289  rejectionReason |= kAcceptanceCut;
290  return kFALSE;
291  }
292 
293  if (fMinPhi < fMaxPhi && (phi < fMinPhi || phi > fMaxPhi)) {
294  rejectionReason |= kAcceptanceCut;
295  return kFALSE;
296  }
297 
298  return kTRUE;
299 }
300 
306 const AliEmcalIterableContainer AliEmcalContainer::all() const {
307  return AliEmcalIterableContainer(this, false);
308 }
309 
315 const AliEmcalIterableContainer AliEmcalContainer::accepted() const {
316  return AliEmcalIterableContainer(this, true);
317 }
318 
324 const AliEmcalIterableMomentumContainer AliEmcalContainer::all_momentum() const {
325  return AliEmcalIterableMomentumContainer(this, false);
326 }
327 
333 const AliEmcalIterableMomentumContainer AliEmcalContainer::accepted_momentum() const {
334  return AliEmcalIterableMomentumContainer(this, true);
335 }
336 
343 Double_t AliEmcalContainer::RelativePhi(Double_t mphi, Double_t vphi)
344 {
345  vphi = TVector2::Phi_0_2pi(vphi);
346  mphi = TVector2::Phi_0_2pi(mphi);
347 
348  Double_t dphi = TVector2::Phi_mpi_pi(mphi - vphi);
349  return dphi;
350 }
static const AliVEvent * GetEvent(const AliVEvent *inputEvent, bool isEmbedding=false)
double Double_t
Definition: External.C:58
Declaration of class AliTLorentzVector.
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
Double_t Phi_0_2pi() const
Container implementing iterable functionality of the EMCAL containers.
unsigned short UShort_t
Definition: External.C:28
bool Bool_t
Definition: External.C:53