ATLAS Offline Software
EgammaxAODHelpers.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "xAODEgamma/Egamma.h"
7 #include "xAODEgamma/Photon.h"
8 #include "xAODEgamma/Electron.h"
11 
13  return ( (eg->type()==xAOD::Type::Electron) &&
15 }
16 // ==================================================================
19 }
20 // ==================================================================
22  return (eg->type()==xAOD::Type::Photon);
23 }
24 // ==================================================================
26  if (!eg || eg->type()!=xAOD::Type::Photon){
27  return false;
28  }
29  const xAOD::Photon *ph = static_cast<const xAOD::Photon*>(eg);
30  return xAOD::EgammaHelpers::isConvertedPhoton(ph,excludeTRT);
31 }
32 // ==================================================================
34  return (eg ? isBarrel(eg->caloCluster()) : false);
35 }
36 // ==================================================================
38  const bool isBarrel = cluster->inBarrel();
39  const bool isEndcap = cluster->inEndcap();
40  if (isBarrel && isEndcap){
41  return cluster->eSample(CaloSampling::EMB2) >= cluster->eSample(CaloSampling::EME2);
42  }
43  return isBarrel;
44 }
45 // ==================================================================
47  const bool hasEME2 = cluster->hasSampling(CaloSampling::EME2);
48  const bool hasFCAL0 = cluster->hasSampling(CaloSampling::FCAL0);
49  if (hasEME2 && hasFCAL0){
50  return cluster->eSample(CaloSampling::FCAL0) >= cluster->eSample(CaloSampling::EME2);
51  }
52  return hasFCAL0;
53 }
54 // ==================================================================
56  const xAOD::Egamma* eg, bool cook)
57 {
58  if (!eg) { return nullptr; }
59  if (!cook) { return eg->caloCluster(); }
61  cookClusLinkAcc( "cookiecutClusterLink" );
62  if (!cookClusLinkAcc.isAvailable(*eg) || !cookClusLinkAcc(*eg).isValid())
63  { return nullptr; }
64  return (*cookClusLinkAcc(*eg));
65 }
66 // ==================================================================
67 std::vector< ElementLink< xAOD::CaloClusterContainer > > xAOD::EgammaHelpers::getAssociatedTopoClustersLinks(const xAOD::CaloCluster *cluster){
68 
69  static const SG::AuxElement::Accessor < std::vector< ElementLink< xAOD::CaloClusterContainer > > > caloClusterLinks("constituentClusterLinks");
70  std::vector< ElementLink< xAOD::CaloClusterContainer > > veclinks;
71  if(caloClusterLinks.isAvailable(*cluster)){
72  veclinks=caloClusterLinks(*cluster);
73  }
74  return veclinks;
75 }
76 // ==================================================================
77 std::vector<const xAOD::CaloCluster*> xAOD::EgammaHelpers::getAssociatedTopoClusters(const xAOD::CaloCluster *cluster){
78  std::vector< const xAOD::CaloCluster* > topoclusters;
79  std::vector< ElementLink< xAOD::CaloClusterContainer > > veclinks = xAOD::EgammaHelpers::getAssociatedTopoClustersLinks(cluster);
80  for (const auto& i : veclinks){
81  if(i.isValid()){
82  topoclusters.push_back(*i);
83  }
84  else{
85  topoclusters.push_back(nullptr);
86  }
87  }
88  return topoclusters;
89 }
90 // ==================================================================
91 std::vector< ElementLink< xAOD::FlowElementContainer > > xAOD::EgammaHelpers::getAssociatedFlowElementsLinks(const xAOD::Egamma *eg,
92  bool neutral){
93  static const SG::AuxElement::Accessor < std::vector< ElementLink< xAOD::FlowElementContainer > > > nflowElementLinks("neutralFELinks");
94  static const SG::AuxElement::Accessor < std::vector< ElementLink< xAOD::FlowElementContainer > > > cflowElementLinks("chargedFELinks");
95  std::vector< ElementLink< xAOD::FlowElementContainer > > veclinks;
96  if(neutral && nflowElementLinks.isAvailable(*eg)){
97  veclinks=nflowElementLinks(*eg);
98  } else if(!neutral && cflowElementLinks.isAvailable(*eg)){
99  veclinks=cflowElementLinks(*eg);
100  }
101  return veclinks;
102 }
103 // ==================================================================
104 std::vector<const xAOD::FlowElement*> xAOD::EgammaHelpers::getAssociatedFlowElements(const xAOD::Egamma *eg,
105  bool neutral, bool charged){
106  std::vector< const xAOD::FlowElement* > flowelements;
107  if (!neutral && !charged)
108  return flowelements;
109  std::vector< ElementLink< xAOD::FlowElementContainer > > veclinks = xAOD::EgammaHelpers::getAssociatedFlowElementsLinks(eg,neutral);
110  for (const auto& i : veclinks){
111  if(i.isValid()){
112  flowelements.push_back(*i);
113  }
114  else{
115  flowelements.push_back(nullptr);
116  }
117  }
118  if (neutral && charged) {
119  std::vector< ElementLink< xAOD::FlowElementContainer > > oveclinks = xAOD::EgammaHelpers::getAssociatedFlowElementsLinks(eg,false);
120  for (const auto& i : oveclinks){
121  if(i.isValid()){
122  flowelements.push_back(*i);
123  }
124  else{
125  flowelements.push_back(nullptr);
126  }
127  }
128  }
129  return flowelements;
130 }
131 // ==================================================================
132 std::set<const xAOD::TrackParticle*> xAOD::EgammaHelpers::getTrackParticles(const xAOD::Egamma *eg,
133  bool useBremAssoc /* = true */,
134  bool allParticles /* = true */){
135 
136  if (eg) {
137  if (eg->type()==xAOD::Type::Electron) {
138  const xAOD::Electron* el = static_cast<const xAOD::Electron*> (eg);
139  if (el) {
140  return getTrackParticles(el, useBremAssoc, allParticles);
141  }
142  }
143  else if (eg->type()==xAOD::Type::Photon) {
144  const xAOD::Photon* ph = static_cast<const xAOD::Photon*> (eg);
145  if (ph) {
146  return getTrackParticles(ph, useBremAssoc);
147  }
148  }
149  }
150  return std::set<const xAOD::TrackParticle*>{};
151 }
152 // ==================================================================
153 std::vector<const xAOD::TrackParticle*> xAOD::EgammaHelpers::getTrackParticlesVec(const xAOD::Egamma *eg,
154  bool useBremAssoc /* = true */,
155  bool allParticles /* = true */){
156  if (eg) {
157  if (eg->type()==xAOD::Type::Electron) {
158  const xAOD::Electron* el = static_cast<const xAOD::Electron*> (eg);
159  if (el) {
160  return getTrackParticlesVec(el, useBremAssoc, allParticles);
161  }
162  }
163  else if (eg->type()==xAOD::Type::Photon) {
164  const xAOD::Photon* ph = static_cast<const xAOD::Photon*> (eg);
165  if (ph) {
166  return getTrackParticlesVec(ph, useBremAssoc);
167  }
168  }
169  }
170  return std::vector<const xAOD::TrackParticle*>{};
171 }
172 // ==================================================================
174  const xAOD::SummaryType& info,
175  int deflt /* = -999 */){
176  uint8_t dummy(0);
177  return (tp.summaryValue(dummy, info) ? dummy : deflt);
178 }
179 // ==================================================================
181  const xAOD::SummaryType& info,
182  float deflt /* = -999. */){
183  float dummy(0);
184  return (tp.summaryValue(dummy, info) ? dummy : deflt);
185 }
186 
187 // ==================================================================
189  double& e2, double& e3) {
190 
191  const static SG::AuxElement::ConstAccessor<float> acc_Eadded_s2("Eadded_Lr2");
192  const static SG::AuxElement::ConstAccessor<float> acc_Eadded_s3("Eadded_Lr3");
193 
194  unsigned short status = 0;
195  if (acc_Eadded_s2.isAvailable(eg))
196  { e2 = acc_Eadded_s2(eg); }
197  else
198  { status += 1; }
199  if (acc_Eadded_s3.isAvailable(eg))
200  { e3 = acc_Eadded_s3(eg); }
201  else
202  { status += 2; }
203  return status;
204 }
xAOD::EgammaHelpers::energyInMissingCells
unsigned short energyInMissingCells(const xAOD::Egamma &eg, double &e2, double &e3)
Get the energies in sampling 2 and 3 that are in cells rejected by the topo-cluster timing cut but th...
Definition: EgammaxAODHelpers.cxx:188
xAOD::EgammaHelpers::summaryValueFloat
float summaryValueFloat(const xAOD::TrackParticle &tp, const xAOD::SummaryType &info, float deflt=-999.)
return the summary value for a TrackParticle or default value (-999)
Definition: EgammaxAODHelpers.cxx:180
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
xAOD::EgammaHelpers::getAssociatedTopoClusters
std::vector< const xAOD::CaloCluster * > getAssociatedTopoClusters(const xAOD::CaloCluster *cluster)
Return a vector of all the topo clusters associated with the egamma cluster.
Definition: EgammaxAODHelpers.cxx:77
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:553
ParticleTest.eg
eg
Definition: ParticleTest.py:29
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
xAOD::EgammaHelpers::getAssociatedFlowElements
std::vector< const xAOD::FlowElement * > getAssociatedFlowElements(const xAOD::Egamma *eg, bool neutral=true, bool charged=false)
Return a vector of the flow elements associated with the egamma cluster (only neutral for default)
Definition: EgammaxAODHelpers.cxx:104
ParticleTest.tp
tp
Definition: ParticleTest.py:25
xAOD::EgammaHelpers::getTrackParticles
std::set< const xAOD::TrackParticle * > getTrackParticles(const xAOD::Egamma *eg, bool useBremAssoc=true, bool allParticles=true)
Return a list of all or only the best TrackParticle associated to the object.
Definition: EgammaxAODHelpers.cxx:132
xAOD::Egamma_v1
Definition: Egamma_v1.h:56
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
xAOD::EgammaParameters::AuthorFwdElectron
const uint16_t AuthorFwdElectron
Electron reconstructed by the Forward cluster-based algorithm.
Definition: EgammaDefs.h:30
xAOD::EgammaHelpers::getTrackParticlesVec
std::vector< const xAOD::TrackParticle * > getTrackParticlesVec(const xAOD::Egamma *eg, bool useBremAssoc=true, bool allParticles=true)
Return a list of all or only the best TrackParticle associated to the object.
Definition: EgammaxAODHelpers.cxx:153
xAOD::EgammaHelpers::isBarrel
bool isBarrel(const xAOD::Egamma *eg)
return true if the cluster is in the barrel
Definition: EgammaxAODHelpers.cxx:33
Egamma.h
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
xAOD::CaloCluster_v1::inEndcap
bool inEndcap() const
Returns true if at least one clustered cell in the endcap.
Definition: CaloCluster_v1.h:892
EgammaxAODHelpers.h
xAOD::SummaryType
SummaryType
Enumerates the different types of information stored in Summary.
Definition: TrackingPrimitives.h:229
xAOD::EgammaHelpers::isConvertedPhoton
bool isConvertedPhoton(const xAOD::Egamma *eg, bool excludeTRT=false)
is the object a converted photon
Definition: EgammaxAODHelpers.cxx:25
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloCluster.h
Photon.h
xAOD::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:12
CalibDbCompareRT.dummy
dummy
Definition: CalibDbCompareRT.py:59
xAOD::CaloCluster_v1::inBarrel
bool inBarrel() const
Returns true if at least one clustered cell in the barrel.
Definition: CaloCluster_v1.h:887
python.getProblemFolderFromLogs.el
dictionary el
Definition: getProblemFolderFromLogs.py:48
xAOD::EgammaHelpers::getAssociatedTopoClustersLinks
std::vector< ElementLink< xAOD::CaloClusterContainer > > getAssociatedTopoClustersLinks(const xAOD::CaloCluster *cluster)
Return a vector of all the elementlinks to the topo clusters associated with the egamma cluster.
Definition: EgammaxAODHelpers.cxx:67
xAOD::EgammaHelpers::isFwdElectron
bool isFwdElectron(const xAOD::Egamma *eg)
is the object a Fwd electron
Definition: EgammaxAODHelpers.cxx:17
xAOD::EgammaHelpers::summaryValueInt
int summaryValueInt(const xAOD::TrackParticle &tp, const xAOD::SummaryType &info, int deflt=-999)
return the summary value for a TrackParticle or default value (-999) (to be used mostly in python whe...
Definition: EgammaxAODHelpers.cxx:173
CP::neutral
@ neutral
Definition: Reconstruction/PFlow/PFlowUtils/PFlowUtils/PFODefs.h:11
xAOD::EgammaHelpers::isFCAL
bool isFCAL(const xAOD::CaloCluster *cluster)
return true if the cluster (or the majority of its energy) is in the FCAL0
Definition: EgammaxAODHelpers.cxx:46
xAOD::Electron_v1
Definition: Electron_v1.h:34
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
TrackParticle.h
xAOD::EgammaHelpers::getAssociatedFlowElementsLinks
std::vector< ElementLink< xAOD::FlowElementContainer > > getAssociatedFlowElementsLinks(const xAOD::Egamma *eg, bool neutral=true)
Return a vector of the elementlinks to the flow elements associated with the egamma cluster (neutral ...
Definition: EgammaxAODHelpers.cxx:91
xAOD::CaloCluster_v1::eSample
float eSample(const CaloSample sampling) const
Definition: CaloCluster_v1.cxx:514
xAOD::Photon_v1
Definition: Photon_v1.h:37
egammaEnergyPositionAllSamples::e2
double e2(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 2nd sampling
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:21
python.LArCondContChannels.isBarrel
isBarrel
Definition: LArCondContChannels.py:659
SG::ConstAccessor< T, AuxAllocator_t< T > >::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
merge.status
status
Definition: merge.py:16
Electron.h
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:44
xAOD::CaloCluster_v1::hasSampling
bool hasSampling(const CaloSample s) const
Checks if certain smapling contributes to cluster.
Definition: CaloCluster_v1.h:882
CaloCell_ID_FCS::FCAL0
@ FCAL0
Definition: FastCaloSim_CaloCell_ID.h:40
python.ParticleTypeUtil.info
def info
Definition: ParticleTypeUtil.py:87
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
CP::charged
@ charged
Definition: Reconstruction/PFlow/PFlowUtils/PFlowUtils/PFODefs.h:11
xAOD::EgammaHelpers::getCluster
const xAOD::CaloCluster * getCluster(const xAOD::Egamma *eg, bool cook=true)
return the associated egamma cluster, that might be cookie-cut cluster (fwd electron)
Definition: EgammaxAODHelpers.cxx:55