AliPhysics  ad6828d (ad6828d)
 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 
22 #include "AliEmcalContainer.h"
23 
25 ClassImp(AliEmcalContainer);
27 
33 AliEmcalContainer::AliEmcalContainer():
34  TObject(),
35  fName(),
36  fClArrayName(),
37  fBaseClassName(),
38  fIsParticleLevel(kFALSE),
39  fBitMap(0),
40  fMinPt(0.15),
41  fMaxPt(1000.),
42  fMaxE(1000.),
43  fMinE(0.),
44  fMinEta(-0.9),
45  fMaxEta(0.9),
46  fMinPhi(-10),
47  fMaxPhi(10),
48  fMinMCLabel(-1),
49  fMaxMCLabel(-1),
50  fMassHypothesis(-1),
51  fClArray(0),
52  fCurrentID(0),
53  fLabelMap(0),
54  fLoadedClass(0),
55  fClassName()
56 {
57  fVertex[0] = 0;
58  fVertex[1] = 0;
59  fVertex[2] = 0;
60 }
61 
69 AliEmcalContainer::AliEmcalContainer(const char *name):
70  TObject(),
71  fName(name),
72  fClArrayName(name),
73  fBaseClassName(),
74  fIsParticleLevel(kFALSE),
75  fBitMap(0),
76  fMinPt(0.15),
77  fMaxPt(1000.),
78  fMaxE(1000.),
79  fMinE(0.),
80  fMinEta(-0.9),
81  fMaxEta(0.9),
82  fMinPhi(-10),
83  fMaxPhi(10),
84  fMinMCLabel(-1),
85  fMaxMCLabel(-1),
86  fMassHypothesis(-1),
87  fClArray(0),
88  fCurrentID(0),
89  fLabelMap(0),
90  fLoadedClass(0),
91  fClassName()
92 {
93  fVertex[0] = 0;
94  fVertex[1] = 0;
95  fVertex[2] = 0;
96 }
97 
104 TObject *AliEmcalContainer::operator[](int index) const {
105  if(index >= 0 && index < GetNEntries()) return fClArray->At(index);
106  return NULL;
107 }
108 
113 void AliEmcalContainer::SetClassName(const char *clname)
114 {
115  TClass cls(clname);
116  if (cls.InheritsFrom(fBaseClassName)) {
117  fClassName = clname;
118  }
119  else {
120  AliError(Form("Unable to set class name %s for this container, it must inherits from %s!",clname,fBaseClassName.Data()));
121  }
122 }
123 
129 void AliEmcalContainer::SetArray(const AliVEvent *event)
130 {
131  const AliVVertex *vertex = event->GetPrimaryVertex();
132  if (vertex) vertex->GetXYZ(fVertex);
133 
134  if (!fClArrayName.IsNull() && !fClArray) {
135  fClArray = dynamic_cast<TClonesArray*>(event->FindListObject(fClArrayName));
136  if (!fClArray) {
137  AliError(Form("%s: Could not retrieve array with name %s!", GetName(), fClArrayName.Data()));
138  return;
139  }
140  } else {
141  return;
142  }
143 
144  fLoadedClass = fClArray->GetClass();
145 
146  if (!fClassName.IsNull()) {
147  if (!fLoadedClass->InheritsFrom(fClassName)) {
148  AliError(Form("%s: Objects of type %s in %s are not inherited from %s!",
149  GetName(), fLoadedClass->GetName(), fClArrayName.Data(), fClassName.Data()));
150  fClArray = 0;
151  fLoadedClass = 0;
152  }
153  }
154 
155  fLabelMap = dynamic_cast<AliNamedArrayI*>(event->FindListObject(fClArrayName + "_Map"));
156 }
157 
162 Int_t AliEmcalContainer::GetNAcceptEntries() const{
163  Int_t result = 0;
164  for(int index = 0; index < GetNEntries(); index++){
165  UInt_t rejectionReason = 0;
166  if(AcceptObject(index, rejectionReason)) result++;
167  }
168  return result;
169 }
170 
176 Int_t AliEmcalContainer::GetIndexFromLabel(Int_t lab) const
177 {
178  if (fLabelMap) {
179  if (lab < fLabelMap->GetSize()) {
180  return fLabelMap->At(lab);
181  }
182  else {
183  AliDebug(3,Form("%s_AliEmcalContainer::GetIndexFromLabel - Label not found in the map, returning -1...",fClArrayName.Data()));
184  return -1;
185  }
186  }
187  else {
188  AliDebug(3,Form("%s_AliEmcalContainer::GetIndexFromLabel - No index-label map found, returning label...",fClArrayName.Data()));
189  return lab;
190  }
191 }
192 
198 UShort_t AliEmcalContainer::GetRejectionReasonBitPosition(UInt_t rejectionReason)
199 {
200  UInt_t rs = rejectionReason;
201  UShort_t p = 0;
202  while (rs >>= 1) { p++; }
203  return p;
204 }
205 
213 Bool_t AliEmcalContainer::SamePart(const AliVParticle* part1, const AliVParticle* part2, Double_t dist)
214 {
215  if(!part1) return kFALSE;
216  if(!part2) return kFALSE;
217  Double_t dPhi = TMath::Abs(part1->Phi() - part2->Phi());
218  Double_t dEta = TMath::Abs(part1->Eta() - part2->Eta());
219  Double_t dpT = TMath::Abs(part1->Pt() - part2->Pt());
220  dPhi = TVector2::Phi_mpi_pi(dPhi);
221  if (dPhi > dist) return kFALSE;
222  if (dEta > dist) return kFALSE;
223  if (dpT > dist) return kFALSE;
224  return kTRUE;
225 }
226 
236 Bool_t AliEmcalContainer::ApplyKinematicCuts(const AliTLorentzVector& mom, UInt_t &rejectionReason) const
237 {
238  if (mom.Pt() < fMinPt || mom.Pt() > fMaxPt) {
239  rejectionReason |= kPtCut;
240  return kFALSE;
241  }
242 
243  if (mom.E() < fMinE || mom.E() > fMaxE) {
244  rejectionReason |= kPtCut;
245  return kFALSE;
246  }
247 
248  Double_t eta = mom.Eta();
249  Double_t phi = mom.Phi_0_2pi();
250 
251  if (fMinEta < fMaxEta && (eta < fMinEta || eta > fMaxEta)) {
252  rejectionReason |= kAcceptanceCut;
253  return kFALSE;
254  }
255 
256  if (fMinPhi < fMaxPhi && (phi < fMinPhi || phi > fMaxPhi)) {
257  rejectionReason |= kAcceptanceCut;
258  return kFALSE;
259  }
260 
261  return kTRUE;
262 }
263 
269 const AliEmcalIterableContainer AliEmcalContainer::all() const {
270  return AliEmcalIterableContainer(this, false);
271 }
272 
278 const AliEmcalIterableContainer AliEmcalContainer::accepted() const {
279  return AliEmcalIterableContainer(this, true);
280 }
281 
287 const AliEmcalIterableMomentumContainer AliEmcalContainer::all_momentum() const {
288  return AliEmcalIterableMomentumContainer(this, false);
289 }
290 
296 const AliEmcalIterableMomentumContainer AliEmcalContainer::accepted_momentum() const {
297  return AliEmcalIterableMomentumContainer(this, true);
298 }
299 
306 Double_t AliEmcalContainer::RelativePhi(Double_t mphi, Double_t vphi)
307 {
308  vphi = TVector2::Phi_0_2pi(vphi);
309  mphi = TVector2::Phi_0_2pi(mphi);
310 
311  Double_t dphi = TVector2::Phi_mpi_pi(mphi - vphi);
312  return dphi;
313 }
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.
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
unsigned short UShort_t
Definition: External.C:28
bool Bool_t
Definition: External.C:53