AliPhysics  cdeda5a (cdeda5a)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
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 
133 void AliEmcalContainer::SetArray(const AliVEvent *event)
134 {
135  if (fIsEmbedding) {
136  // this is an embedding container
137  // will ignore the provided event and use the event
138  // from the embedding helper class
139 
141  if (!embedding) return;
142 
143  event = embedding->GetExternalEvent();
144  }
145 
146  if (!event) return;
147 
148  const AliVVertex *vertex = event->GetPrimaryVertex();
149  if (vertex) vertex->GetXYZ(fVertex);
150 
151  if (!fClArrayName.IsNull() && !fClArray) {
152  fClArray = dynamic_cast<TClonesArray*>(event->FindListObject(fClArrayName));
153  if (!fClArray) {
154  AliError(Form("%s: Could not retrieve array with name %s!", GetName(), fClArrayName.Data()));
155  return;
156  }
157  } else {
158  return;
159  }
160 
161  fLoadedClass = fClArray->GetClass();
162 
163  if (!fClassName.IsNull()) {
164  if (!fLoadedClass->InheritsFrom(fClassName)) {
165  AliError(Form("%s: Objects of type %s in %s are not inherited from %s!",
166  GetName(), fLoadedClass->GetName(), fClArrayName.Data(), fClassName.Data()));
167  fClArray = 0;
168  fLoadedClass = 0;
169  }
170  }
171 
172  fLabelMap = dynamic_cast<AliNamedArrayI*>(event->FindListObject(fClArrayName + "_Map"));
173 }
174 
179 Int_t AliEmcalContainer::GetNAcceptEntries() const{
180  Int_t result = 0;
181  for(int index = 0; index < GetNEntries(); index++){
182  UInt_t rejectionReason = 0;
183  if(AcceptObject(index, rejectionReason)) result++;
184  }
185  return result;
186 }
187 
193 Int_t AliEmcalContainer::GetIndexFromLabel(Int_t lab) const
194 {
195  if (fLabelMap) {
196  if (lab < fLabelMap->GetSize()) {
197  return fLabelMap->At(lab);
198  }
199  else {
200  AliDebug(3,Form("%s_AliEmcalContainer::GetIndexFromLabel - Label not found in the map, returning -1...",fClArrayName.Data()));
201  return -1;
202  }
203  }
204  else {
205  AliDebug(3,Form("%s_AliEmcalContainer::GetIndexFromLabel - No index-label map found, returning label...",fClArrayName.Data()));
206  return lab;
207  }
208 }
209 
215 UShort_t AliEmcalContainer::GetRejectionReasonBitPosition(UInt_t rejectionReason)
216 {
217  UInt_t rs = rejectionReason;
218  UShort_t p = 0;
219  while (rs >>= 1) { p++; }
220  return p;
221 }
222 
230 Bool_t AliEmcalContainer::SamePart(const AliVParticle* part1, const AliVParticle* part2, Double_t dist)
231 {
232  if(!part1) return kFALSE;
233  if(!part2) return kFALSE;
234  Double_t dPhi = TMath::Abs(part1->Phi() - part2->Phi());
235  Double_t dEta = TMath::Abs(part1->Eta() - part2->Eta());
236  Double_t dpT = TMath::Abs(part1->Pt() - part2->Pt());
237  dPhi = TVector2::Phi_mpi_pi(dPhi);
238  if (dPhi > dist) return kFALSE;
239  if (dEta > dist) return kFALSE;
240  if (dpT > dist) return kFALSE;
241  return kTRUE;
242 }
243 
253 Bool_t AliEmcalContainer::ApplyKinematicCuts(const AliTLorentzVector& mom, UInt_t &rejectionReason) const
254 {
255  if (mom.Pt() < fMinPt || mom.Pt() > fMaxPt) {
256  rejectionReason |= kPtCut;
257  return kFALSE;
258  }
259 
260  if (mom.E() < fMinE || mom.E() > fMaxE) {
261  rejectionReason |= kPtCut;
262  return kFALSE;
263  }
264 
265  Double_t eta = mom.Eta();
266  Double_t phi = mom.Phi_0_2pi();
267 
268  if (fMinEta < fMaxEta && (eta < fMinEta || eta > fMaxEta)) {
269  rejectionReason |= kAcceptanceCut;
270  return kFALSE;
271  }
272 
273  if (fMinPhi < fMaxPhi && (phi < fMinPhi || phi > fMaxPhi)) {
274  rejectionReason |= kAcceptanceCut;
275  return kFALSE;
276  }
277 
278  return kTRUE;
279 }
280 
286 const AliEmcalIterableContainer AliEmcalContainer::all() const {
287  return AliEmcalIterableContainer(this, false);
288 }
289 
295 const AliEmcalIterableContainer AliEmcalContainer::accepted() const {
296  return AliEmcalIterableContainer(this, true);
297 }
298 
304 const AliEmcalIterableMomentumContainer AliEmcalContainer::all_momentum() const {
305  return AliEmcalIterableMomentumContainer(this, false);
306 }
307 
313 const AliEmcalIterableMomentumContainer AliEmcalContainer::accepted_momentum() const {
314  return AliEmcalIterableMomentumContainer(this, true);
315 }
316 
323 Double_t AliEmcalContainer::RelativePhi(Double_t mphi, Double_t vphi)
324 {
325  vphi = TVector2::Phi_0_2pi(vphi);
326  mphi = TVector2::Phi_0_2pi(mphi);
327 
328  Double_t dphi = TVector2::Phi_mpi_pi(mphi - vphi);
329  return dphi;
330 }
double Double_t
Definition: External.C:58
Declaration of class AliTLorentzVector.
Declaration of class AliAnalysisTaskEmcalEmbeddingHelper.
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
Double_t Phi_0_2pi() const
Implementation of task to embed external events.
Container implementing iterable functionality of the EMCAL containers.
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
unsigned short UShort_t
Definition: External.C:28
bool Bool_t
Definition: External.C:53
static const AliAnalysisTaskEmcalEmbeddingHelper * GetInstance()