ATLAS Offline Software
Loading...
Searching...
No Matches
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"
11
13 return ( (eg->type()==xAOD::Type::Electron) &&
15}
16// ==================================================================
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// ==================================================================
67std::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// ==================================================================
77std::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// ==================================================================
91std::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// ==================================================================
104std::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// ==================================================================
132std::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// ==================================================================
153std::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}
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
bool inBarrel() const
Returns true if at least one clustered cell in the barrel.
float eSample(const CaloSample sampling) const
bool inEndcap() const
Returns true if at least one clustered cell in the endcap.
bool hasSampling(const CaloSample s) const
Checks if certain smapling contributes to cluster.
@ Photon
The object is a photon.
Definition ObjectType.h:47
@ Electron
The object is an electron.
Definition ObjectType.h:46
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.
bool isBarrel(const xAOD::Egamma *eg)
return true if the cluster is in the barrel
bool isFwdElectron(const xAOD::Egamma *eg)
is the object a Fwd electron
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.
bool isConvertedPhoton(const xAOD::Egamma *eg, bool excludeTRT=false)
is the object a converted photon
bool isFCAL(const xAOD::CaloCluster *cluster)
return true if the cluster (or the majority of its energy) is in the FCAL0
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 ...
std::vector< const xAOD::CaloCluster * > getAssociatedTopoClusters(const xAOD::CaloCluster *cluster)
Return a vector of all the topo clusters associated with the egamma cluster.
const xAOD::CaloCluster * getCluster(const xAOD::Egamma *eg, bool cook=true)
return the associated egamma cluster, that might be cookie-cut cluster (fwd electron)
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...
float summaryValueFloat(const xAOD::TrackParticle &tp, const xAOD::SummaryType &info, float deflt=-999.)
return the summary value for a TrackParticle or default value (-999)
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...
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
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.
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)
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
const uint16_t AuthorFwdElectron
Electron reconstructed by the Forward cluster-based algorithm.
Definition EgammaDefs.h:30
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
Photon_v1 Photon
Definition of the current "egamma version".
SummaryType
Enumerates the different types of information stored in Summary.
Electron_v1 Electron
Definition of the current "egamma version".