AliPhysics  06e4d4b (06e4d4b)
AliEmcalContainer.cxx
Go to the documentation of this file.
1 /************************************************************************************
2  * Copyright (C) 2016, Copyright Holders of the ALICE Collaboration *
3  * All rights reserved. *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions are met: *
7  * * Redistributions of source code must retain the above copyright *
8  * notice, this list of conditions and the following disclaimer. *
9  * * Redistributions in binary form must reproduce the above copyright *
10  * notice, this list of conditions and the following disclaimer in the *
11  * documentation and/or other materials provided with the distribution. *
12  * * Neither the name of the <organization> nor the *
13  * names of its contributors may be used to endorse or promote products *
14  * derived from this software without specific prior written permission. *
15  * *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
19  * DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26  ************************************************************************************/
27 #include <TClonesArray.h>
28 #include "AliVEvent.h"
29 #include "AliLog.h"
30 #include "AliNamedArrayI.h"
31 #include "AliVParticle.h"
32 #include "AliTLorentzVector.h"
33 
34 #include "AliEmcalContainerUtils.h"
35 
36 #include "AliEmcalContainer.h"
37 
38 ClassImp(AliEmcalContainer);
39 
41  TObject(),
42  fName(),
43  fClArrayName(),
44  fBaseClassName(),
45  fIsParticleLevel(kFALSE),
46  fBitMap(0),
47  fMinPt(0.15),
48  fMaxPt(1000.),
49  fMaxE(1000.),
50  fMinE(0.),
51  fMinEta(-0.9),
52  fMaxEta(0.9),
53  fMinPhi(-10),
54  fMaxPhi(10),
55  fMinMCLabel(-1),
56  fMaxMCLabel(-1),
57  fMassHypothesis(-1),
58  fIsEmbedding(kFALSE),
59  fClArray(0),
60  fCurrentID(0),
61  fLabelMap(0),
62  fLoadedClass(0),
63  fClassName()
64 {
65  fVertex[0] = 0;
66  fVertex[1] = 0;
67  fVertex[2] = 0;
68 }
69 
71  TObject(),
72  fName(name),
73  fClArrayName(name),
75  fIsParticleLevel(kFALSE),
76  fBitMap(0),
77  fMinPt(0.15),
78  fMaxPt(1000.),
79  fMaxE(1000.),
80  fMinE(0.),
81  fMinEta(-0.9),
82  fMaxEta(0.9),
83  fMinPhi(-10),
84  fMaxPhi(10),
85  fMinMCLabel(-1),
86  fMaxMCLabel(-1),
87  fMassHypothesis(-1),
88  fIsEmbedding(kFALSE),
89  fClArray(0),
90  fCurrentID(0),
91  fLabelMap(0),
92  fLoadedClass(0),
93  fClassName()
94 {
95  fVertex[0] = 0;
96  fVertex[1] = 0;
97  fVertex[2] = 0;
98 }
99 
101  if(index >= 0 && index < GetNEntries()) return fClArray->At(index);
102  return NULL;
103 }
104 
105 void AliEmcalContainer::SetClassName(const char *clname)
106 {
107  TClass cls(clname);
108  if (cls.InheritsFrom(fBaseClassName)) {
109  fClassName = clname;
110  }
111  else {
112  AliError(Form("Unable to set class name %s for this container, it must inherits from %s!",clname,fBaseClassName.Data()));
113  }
114 }
115 
116 void AliEmcalContainer::GetVertexFromEvent(const AliVEvent * event)
117 {
118  const AliVVertex *vertex = event->GetPrimaryVertex();
119  if (vertex) vertex->GetXYZ(fVertex);
120 }
121 
122 void AliEmcalContainer::SetArray(const AliVEvent *event)
123 {
124  // Handling of default containers
125  if(fClArrayName == "usedefault"){
127  }
128 
129  // Get the right event (either the current event of the embedded event)
131 
132  if (!event) return;
133 
134  GetVertexFromEvent(event);
135 
136  if (!fClArrayName.IsNull() && !fClArray) {
137  fClArray = dynamic_cast<TClonesArray*>(event->FindListObject(fClArrayName));
138  if (!fClArray) {
139  AliError(Form("%s: Could not retrieve array with name %s!", GetName(), fClArrayName.Data()));
140  return;
141  }
142  } else {
143  return;
144  }
145 
146  fLoadedClass = fClArray->GetClass();
147 
148  if (!fClassName.IsNull()) {
149  if (!fLoadedClass->InheritsFrom(fClassName)) {
150  AliError(Form("%s: Objects of type %s in %s are not inherited from %s!",
151  GetName(), fLoadedClass->GetName(), fClArrayName.Data(), fClassName.Data()));
152  fClArray = 0;
153  fLoadedClass = 0;
154  }
155  }
156 
157  fLabelMap = dynamic_cast<AliNamedArrayI*>(event->FindListObject(fClArrayName + "_Map"));
158 }
159 
160 void AliEmcalContainer::NextEvent(const AliVEvent * event)
161 {
162  // Get the right event (either the current event of the embedded event)
164 
165  if (!event) return;
166 
167  GetVertexFromEvent(event);
168 }
169 
171  Int_t result = 0;
172  for(int index = 0; index < GetNEntries(); index++){
173  UInt_t rejectionReason = 0;
174  if(AcceptObject(index, rejectionReason)) result++;
175  }
176  return result;
177 }
178 
180 {
181  if (fLabelMap) {
182  if (lab < fLabelMap->GetSize()) {
183  return fLabelMap->At(lab);
184  }
185  else {
186  AliDebug(3,Form("%s_AliEmcalContainer::GetIndexFromLabel - Label not found in the map, returning -1...",fClArrayName.Data()));
187  return -1;
188  }
189  }
190  else {
191  AliDebug(3,Form("%s_AliEmcalContainer::GetIndexFromLabel - No index-label map found, returning label...",fClArrayName.Data()));
192  return lab;
193  }
194 }
195 
197 {
198  UInt_t rs = rejectionReason;
199  UShort_t p = 0;
200  while (rs >>= 1) { p++; }
201  return p;
202 }
203 
204 Bool_t AliEmcalContainer::SamePart(const AliVParticle* part1, const AliVParticle* part2, Double_t dist)
205 {
206  if(!part1) return kFALSE;
207  if(!part2) return kFALSE;
208  Double_t dPhi = TMath::Abs(part1->Phi() - part2->Phi());
209  Double_t dEta = TMath::Abs(part1->Eta() - part2->Eta());
210  Double_t dpT = TMath::Abs(part1->Pt() - part2->Pt());
211  dPhi = TVector2::Phi_mpi_pi(dPhi);
212  if (dPhi > dist) return kFALSE;
213  if (dEta > dist) return kFALSE;
214  if (dpT > dist) return kFALSE;
215  return kTRUE;
216 }
217 
219 {
220  if (mom.Pt() < fMinPt || mom.Pt() > fMaxPt) {
221  rejectionReason |= kPtCut;
222  return kFALSE;
223  }
224 
225  if (mom.E() < fMinE || mom.E() > fMaxE) {
226  rejectionReason |= kPtCut;
227  return kFALSE;
228  }
229 
230  Double_t eta = mom.Eta();
231  Double_t phi = mom.Phi_0_2pi();
232 
233  if (fMinEta < fMaxEta && (eta < fMinEta || eta > fMaxEta)) {
234  rejectionReason |= kAcceptanceCut;
235  return kFALSE;
236  }
237 
238  if (fMinPhi < fMaxPhi && (phi < fMinPhi || phi > fMaxPhi)) {
239  rejectionReason |= kAcceptanceCut;
240  return kFALSE;
241  }
242 
243  return kTRUE;
244 }
245 
247  return AliEmcalIterableContainer(this, false);
248 }
249 
251  return AliEmcalIterableContainer(this, true);
252 }
253 
255  return AliEmcalIterableMomentumContainer(this, false);
256 }
257 
259  return AliEmcalIterableMomentumContainer(this, true);
260 }
261 
263 {
264  vphi = TVector2::Phi_0_2pi(vphi);
265  mphi = TVector2::Phi_0_2pi(mphi);
266 
267  Double_t dphi = TVector2::Phi_mpi_pi(mphi - vphi);
268  return dphi;
269 }
particle not in acceptance in and/or
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom, UInt_t &rejectionReason) const
Apply kinematical selection to the momentum vector provided.
static const AliVEvent * GetEvent(const AliVEvent *inputEvent, bool isEmbedding=false)
const AliEmcalIterableContainer all() const
Create an iterable container interface over all objects in the EMCAL container.
Int_t GetNAcceptEntries() const
Count accepted entries in the container.
double Double_t
Definition: External.C:58
Double_t fMinE
Max. cut on particle energy.
EMCALIterableContainer::AliEmcalIterableContainerT< TObject, EMCALIterableContainer::operator_star_pair< TObject > > AliEmcalIterableMomentumContainer
Double_t fMinPhi
Min. cut on particle .
Bool_t fIsEmbedding
if true, this container will connect to an external event
Double_t fMaxE
Min. cut on particle energy.
Int_t GetIndexFromLabel(Int_t lab) const
Get the index in the container from a given label.
Declaration of class AliTLorentzVector.
static Double_t RelativePhi(Double_t ang1, Double_t ang2)
Calculates the relative phi between two angle values and returns it in [-Pi, +Pi] range...
UInt_t fBitMap
bitmap mask
TString fClassName
name of the class in the TClonesArray
static UShort_t GetRejectionReasonBitPosition(UInt_t rejectionReason)
Returns the highest bit in the rejection map as reason why the object was rejected.
Double_t fMinPt
Min. cut on particle .
TClass * fLoadedClass
! Class of the objects contained in the TClonesArray
virtual void NextEvent(const AliVEvent *event)
Preparation for the next event.
Bool_t fIsParticleLevel
whether or not it is a particle level object collection
virtual Bool_t AcceptObject(Int_t i, UInt_t &rejectionReason) const =0
TString fName
object name
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
const AliEmcalIterableMomentumContainer accepted_momentum() const
Create an iterable container interface over accepted objects in the EMCAL container.
Double_t Phi_0_2pi() const
EMCALIterableContainer::AliEmcalIterableContainerT< TObject, EMCALIterableContainer::operator_star_object< TObject > > AliEmcalIterableContainer
Double_t fMaxPhi
Max. cut on particle .
virtual TObject * operator[](int index) const =0
Index operator.
Base class for container structures within the EMCAL framework.
Container implementing iterable functionality of the EMCAL containers.
AliNamedArrayI * fLabelMap
! Label-Index map
void SetClassName(const char *clname)
Int_t fMinMCLabel
minimum MC label
Double_t fMassHypothesis
if < 0 it will use a PID mass when available
Double_t fVertex[3]
! event vertex array
const char * GetName() const
Double_t fMaxPt
Max. cut on particle .
static Bool_t SamePart(const AliVParticle *part1, const AliVParticle *part2, Double_t dist=1.e-4)
Helper function to calculate the distance between two jets or a jet and a particle.
Double_t fMinEta
Min. cut on particle .
virtual void SetArray(const AliVEvent *event)
TString fBaseClassName
name of the base class that this container can handle
TString fClArrayName
name of branch
Int_t fMaxMCLabel
maximum MC label
unsigned short UShort_t
Definition: External.C:28
Double_t fMaxEta
Max. cut on particle .
const AliEmcalIterableContainer accepted() const
Create an iterable container interface over accepted objects in the EMCAL container.
void GetVertexFromEvent(const AliVEvent *event)
Retrieve the vertex from the given event.
TClonesArray * fClArray
! Pointer to array in input event
Int_t GetNEntries() const
bool Bool_t
Definition: External.C:53
Int_t fCurrentID
! current ID for automatic loops
const AliEmcalIterableMomentumContainer all_momentum() const
Create an iterable container interface over all objects in the EMCAL container.
virtual TString GetDefaultArrayName(const AliVEvent *const ev) const
Handling default Array names.
AliEmcalContainer()
Default constructor.