AliPhysics  19b3b9d (19b3b9d)
 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  // Handling of default containers
136  if(fClArrayName == "usedefault"){
137  fClArrayName = GetDefaultArrayName(event);
138  }
139 
140  if (fIsEmbedding) {
141  // this is an embedding container
142  // will ignore the provided event and use the event
143  // from the embedding helper class
144 
146  if (!embedding) return;
147 
148  event = embedding->GetExternalEvent();
149  }
150 
151  if (!event) return;
152 
153  const AliVVertex *vertex = event->GetPrimaryVertex();
154  if (vertex) vertex->GetXYZ(fVertex);
155 
156  if (!fClArrayName.IsNull() && !fClArray) {
157  fClArray = dynamic_cast<TClonesArray*>(event->FindListObject(fClArrayName));
158  if (!fClArray) {
159  AliError(Form("%s: Could not retrieve array with name %s!", GetName(), fClArrayName.Data()));
160  return;
161  }
162  } else {
163  return;
164  }
165 
166  fLoadedClass = fClArray->GetClass();
167 
168  if (!fClassName.IsNull()) {
169  if (!fLoadedClass->InheritsFrom(fClassName)) {
170  AliError(Form("%s: Objects of type %s in %s are not inherited from %s!",
171  GetName(), fLoadedClass->GetName(), fClArrayName.Data(), fClassName.Data()));
172  fClArray = 0;
173  fLoadedClass = 0;
174  }
175  }
176 
177  fLabelMap = dynamic_cast<AliNamedArrayI*>(event->FindListObject(fClArrayName + "_Map"));
178 }
179 
184 Int_t AliEmcalContainer::GetNAcceptEntries() const{
185  Int_t result = 0;
186  for(int index = 0; index < GetNEntries(); index++){
187  UInt_t rejectionReason = 0;
188  if(AcceptObject(index, rejectionReason)) result++;
189  }
190  return result;
191 }
192 
198 Int_t AliEmcalContainer::GetIndexFromLabel(Int_t lab) const
199 {
200  if (fLabelMap) {
201  if (lab < fLabelMap->GetSize()) {
202  return fLabelMap->At(lab);
203  }
204  else {
205  AliDebug(3,Form("%s_AliEmcalContainer::GetIndexFromLabel - Label not found in the map, returning -1...",fClArrayName.Data()));
206  return -1;
207  }
208  }
209  else {
210  AliDebug(3,Form("%s_AliEmcalContainer::GetIndexFromLabel - No index-label map found, returning label...",fClArrayName.Data()));
211  return lab;
212  }
213 }
214 
220 UShort_t AliEmcalContainer::GetRejectionReasonBitPosition(UInt_t rejectionReason)
221 {
222  UInt_t rs = rejectionReason;
223  UShort_t p = 0;
224  while (rs >>= 1) { p++; }
225  return p;
226 }
227 
235 Bool_t AliEmcalContainer::SamePart(const AliVParticle* part1, const AliVParticle* part2, Double_t dist)
236 {
237  if(!part1) return kFALSE;
238  if(!part2) return kFALSE;
239  Double_t dPhi = TMath::Abs(part1->Phi() - part2->Phi());
240  Double_t dEta = TMath::Abs(part1->Eta() - part2->Eta());
241  Double_t dpT = TMath::Abs(part1->Pt() - part2->Pt());
242  dPhi = TVector2::Phi_mpi_pi(dPhi);
243  if (dPhi > dist) return kFALSE;
244  if (dEta > dist) return kFALSE;
245  if (dpT > dist) return kFALSE;
246  return kTRUE;
247 }
248 
258 Bool_t AliEmcalContainer::ApplyKinematicCuts(const AliTLorentzVector& mom, UInt_t &rejectionReason) const
259 {
260  if (mom.Pt() < fMinPt || mom.Pt() > fMaxPt) {
261  rejectionReason |= kPtCut;
262  return kFALSE;
263  }
264 
265  if (mom.E() < fMinE || mom.E() > fMaxE) {
266  rejectionReason |= kPtCut;
267  return kFALSE;
268  }
269 
270  Double_t eta = mom.Eta();
271  Double_t phi = mom.Phi_0_2pi();
272 
273  if (fMinEta < fMaxEta && (eta < fMinEta || eta > fMaxEta)) {
274  rejectionReason |= kAcceptanceCut;
275  return kFALSE;
276  }
277 
278  if (fMinPhi < fMaxPhi && (phi < fMinPhi || phi > fMaxPhi)) {
279  rejectionReason |= kAcceptanceCut;
280  return kFALSE;
281  }
282 
283  return kTRUE;
284 }
285 
291 const AliEmcalIterableContainer AliEmcalContainer::all() const {
292  return AliEmcalIterableContainer(this, false);
293 }
294 
300 const AliEmcalIterableContainer AliEmcalContainer::accepted() const {
301  return AliEmcalIterableContainer(this, true);
302 }
303 
309 const AliEmcalIterableMomentumContainer AliEmcalContainer::all_momentum() const {
310  return AliEmcalIterableMomentumContainer(this, false);
311 }
312 
318 const AliEmcalIterableMomentumContainer AliEmcalContainer::accepted_momentum() const {
319  return AliEmcalIterableMomentumContainer(this, true);
320 }
321 
328 Double_t AliEmcalContainer::RelativePhi(Double_t mphi, Double_t vphi)
329 {
330  vphi = TVector2::Phi_0_2pi(vphi);
331  mphi = TVector2::Phi_0_2pi(mphi);
332 
333  Double_t dphi = TVector2::Phi_mpi_pi(mphi - vphi);
334  return dphi;
335 }
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(AliAnalysisTaskDeltaPt) AliAnalysisTaskDeltaPt
unsigned short UShort_t
Definition: External.C:28
bool Bool_t
Definition: External.C:53
static const AliAnalysisTaskEmcalEmbeddingHelper * GetInstance()