ATLAS Offline Software
Loading...
Searching...
No Matches
OverlapRemovalGenUseAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// EDM includes
6
7// Local includes
12
13namespace
14{
16 const float GeV = 1000.;
17 const float invGeV = 1./GeV;
18}
19
20//-----------------------------------------------------------------------------
21// Constructor
22//-----------------------------------------------------------------------------
24 ISvcLocator* svcLoc)
25 : EL::AnaAlgorithm(name, svcLoc) { }
26
27
28//-----------------------------------------------------------------------------
29// Initialize
30//-----------------------------------------------------------------------------
32{
33 ATH_MSG_INFO("Initialize");
34
35 // Try to retrieve the tool
36 ATH_CHECK( m_orTool.retrieve() );
37
38 if (!m_bJetLabel.empty()){
39 m_jetKey.declareDependency(m_bJetLabel);
40 }
41 if (!m_electronLabel.empty()){
42 m_electronKey.declareDependency(m_electronLabel);
43 }
44 if (!m_photonLabel.empty()){
45 m_photonKey.declareDependency(m_photonLabel);
46 }
47 if (!m_muonLabel.empty()){
48 m_muonKey.declareDependency(m_muonLabel);
49 }
50 if (!m_tauLabel.empty()){
51 m_tauKey.declareDependency(m_tauLabel);
52 }
53
54 m_jetKey.declareOutput(m_overlapLabel);
55 m_jetKey.declareOutput(m_selectionLabel);
56 m_electronKey.declareOutput(m_overlapLabel);
57 m_electronKey.declareOutput(m_selectionLabel);
58 m_photonKey.declareOutput(m_overlapLabel);
59 m_photonKey.declareOutput(m_selectionLabel);
60 m_muonKey.declareOutput(m_overlapLabel);
61 m_muonKey.declareOutput(m_selectionLabel);
62 m_tauKey.declareOutput(m_overlapLabel);
63 m_tauKey.declareOutput(m_selectionLabel);
64 ATH_CHECK(m_jetKey.initialize());
65 ATH_CHECK(m_electronKey.initialize());
66 ATH_CHECK(m_muonKey.initialize());
67 ATH_CHECK(m_vtxKey.initialize());
68 ATH_CHECK(m_photonKey.initialize(m_photonKey.empty()));
69 ATH_CHECK(m_tauKey.initialize(m_tauKey.empty()));
70
71 return StatusCode::SUCCESS;
72}
73
74//-----------------------------------------------------------------------------
75// Execute
76//-----------------------------------------------------------------------------
78{
79 const EventContext& ctx = Gaudi::Hive::currentContext();
80 // Electrons
82 if (!electrons.isValid()) {
83 ATH_MSG_FATAL("Failed to retrieve electron container "<<m_electronKey.key());
84 return StatusCode::FAILURE;
85 }
86 applySelection(*electrons);
87 // Muons
89 if (!muons.isValid()) {
90 ATH_MSG_FATAL("Failed to retrieve muon container "<<m_muonKey.key());
91 return StatusCode::FAILURE;
92 }
93 applySelection(*muons);
94 // Jets
96 if (!jets.isValid()) {
97 ATH_MSG_FATAL("Failed to retrieve jet container "<<m_jetKey.key());
98 return StatusCode::FAILURE;
99 }
100 applySelection(*jets);
101 // Taus
102 const xAOD::TauJetContainer* taus{nullptr};
103 if(!m_tauKey.empty()) {
105 if (!readHandle.isValid()) {
106 ATH_MSG_FATAL("Failed to retrieve TauJetContainer "<<m_tauKey.key());
107 return StatusCode::FAILURE;
108 }
109 taus = readHandle.cptr();
111 }
112 const xAOD::PhotonContainer* photons{nullptr};
113 if(!m_photonKey.empty()) {
115 if (!readHandle.isValid()) {
116 ATH_MSG_FATAL("Failed to retrieve PhotonContainer "<<m_photonKey.key());
117 return StatusCode::FAILURE;
118 }
119 photons = readHandle.cptr();
120 applySelection(*photons);
121 }
122
123 // Primary Vertices
125 if (!vertices.isValid()) {
126 ATH_MSG_FATAL("Failed to retrieve primary vertex container "<<m_vtxKey.key());
127 return StatusCode::FAILURE;
128 }
129 bool checkVtx = false;
130 for(const xAOD::Vertex* vtx : *vertices) {
131 if(vtx->vertexType() == xAOD::VxType::PriVtx)
132 checkVtx = true;
133 }
134
135
136 if(checkVtx) {
137 // Apply the overlap removal
138 ATH_CHECK( m_orTool->removeOverlaps(electrons.cptr(), muons.cptr(), jets.cptr(), taus, photons) );}
139 else{
140 // Reset all decorations to failing
141 ATH_MSG_DEBUG("No primary vertices found, cannot do overlap removal! Will return all fails.");
143 setDefaultDecorations(*electrons);
144 setDefaultDecorations(*muons);
146 if(photons) setDefaultDecorations(*photons);
147 }
148
149 // Dump the objects
150 ATH_MSG_VERBOSE("Dumping results");
151#ifdef XAOD_STANDALONE
152 auto msglvl = msg().level();
153#else
154 auto msglvl = msgLevel();
155#endif
156 if(msglvl >= MSG::VERBOSE){
157 printObjects(*electrons, "ele");
158 printObjects(*muons, "muo");
159 printObjects(*jets, "jet");
160 if(taus) printObjects(*taus, "tau");
161 if(photons) printObjects(*photons, "pho");
162 }
163
164 // Lock the decorations that we wrote.
165 auto lockDecors = [&] (const auto& handler) {
166 handler.template lockDecor<char> (m_selectionLabel, ctx);
167 handler.template lockDecor<char> (m_overlapLabel, ctx);
168 };
169 lockDecors (m_electronKey);
170 lockDecors (m_muonKey);
171 lockDecors (m_photonKey);
172 lockDecors (m_jetKey);
173 lockDecors (m_tauKey);
174
175 return StatusCode::SUCCESS;
176}
177
178//---------------------------------------------------------------------------
179// Reset output decoration
180//---------------------------------------------------------------------------
181 template<class ContainerType>
182void OverlapRemovalGenUseAlg::setDefaultDecorations(const ContainerType& container) {
183 const ort::inputDecorator_t defaultDec(m_overlapLabel);
184 for(auto obj : container){
185 defaultDec(*obj) = m_defaultValue; //default to all objects being overlaps if we can't get primary vertices. Ensures the event cleaning decision fails.
186 }
187}
188
189
190//-----------------------------------------------------------------------------
191// Apply selection to a container
192//-----------------------------------------------------------------------------
193 template<class ContainerType>
194void OverlapRemovalGenUseAlg::applySelection(const ContainerType& container)
195{
197 for(auto obj : container){
198 selDec(*obj) = selectObject(*obj);
199 ATH_MSG_VERBOSE(" Obj " << obj->index() << " of type " << obj->type()
200 << " selected? " << int(selDec(*obj)));
201 }
202}
203//-----------------------------------------------------------------------------
204template<class ObjType>
206{
207 if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false;
208 return true;
209}
210//-----------------------------------------------------------------------------
211template<>
213{
214 // Selection
215 if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false;
216 return true;
217}
218
219//-----------------------------------------------------------------------------
220template<>
222{
223 if(m_electronLabel.empty()) return true; //disable selection for objects with empty labels
224 const SG::AuxElement::ConstAccessor<char> acc_ElectronPass(m_electronLabel);
225 if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false;
226 if(!acc_ElectronPass(obj)) return false;
227 return true;
228}
229
230//-----------------------------------------------------------------------------
231template<>
233{
234 if(m_photonLabel.empty()) return true; //disable selection for objects with empty labels
235 const SG::AuxElement::ConstAccessor<char> acc_PhotonPass(m_photonLabel);
236 if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false;
237 if(!acc_PhotonPass(obj)) return false;
238 return true;
239}
240
241//-----------------------------------------------------------------------------
242template<>
244{
245 if(m_muonLabel.empty()) return true; //disable selection for objects with empty labels
246 const SG::AuxElement::ConstAccessor<char> acc_MuonPass(m_muonLabel);
247 if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false;
248 if(!acc_MuonPass(obj)) return false;
249 return true;
250}
251
252//-----------------------------------------------------------------------------
253template<>
255{
256 if(m_tauLabel.empty()) return true; //disable selection for objects with empty labels
257 const SG::AuxElement::ConstAccessor<char> acc_TauPass(m_tauLabel);
258 if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false;
259 if(!acc_TauPass(obj)) return false;
260 return true;
261}
262
263
264//-----------------------------------------------------------------------------
265// Print object
266//-----------------------------------------------------------------------------
268 const std::string& type)
269{
272 for(auto obj : container){
273 if(selectAcc(*obj)){
274 bool overlaps = overlapAcc(*obj);
275 ATH_MSG_VERBOSE(" " << type << " pt " << obj->pt()*invGeV
276 << " eta " << obj->eta() << " phi " << obj->phi()
277 << " overlaps " << overlaps);
278 }
279 }
280}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
static Double_t taus
const ort::outputAccessor_t overlapAcc(outputLabel)
const ort::inputAccessor_t selectAcc(inputLabel)
constexpr float invGeV
AnaAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
constructor with parameters
OverlapRemovalGenUseAlg(const std::string &name, ISvcLocator *svcLoc)
Standard algorithm constructor.
DataKeyHandler< xAOD::PhotonContainer > m_photonKey
Gaudi::Property< std::string > m_electronLabel
SG::ReadHandleKey< xAOD::VertexContainer > m_vtxKey
DataKeyHandler< xAOD::MuonContainer > m_muonKey
DataKeyHandler< xAOD::ElectronContainer > m_electronKey
void applySelection(const ContainerType &container)
Simple object selection.
DataKeyHandler< xAOD::TauJetContainer > m_tauKey
Gaudi::Property< float > m_etaCut
Gaudi::Property< std::string > m_muonLabel
Gaudi::Property< bool > m_defaultValue
void printObjects(const xAOD::IParticleContainer &container, const std::string &type)
Print object info.
Gaudi::Property< float > m_ptCut
Gaudi::Property< std::string > m_selectionLabel
Label configuration --> Internal usage no data dependency needed.
Gaudi::Property< std::string > m_photonLabel
Gaudi::Property< std::string > m_bJetLabel
Gaudi::Property< std::string > m_overlapLabel
void setDefaultDecorations(const ContainerType &container)
virtual StatusCode execute()
Execute the algorithm.
Gaudi::Property< std::string > m_tauLabel
virtual StatusCode initialize()
Initialize the algorithm.
DataKeyHandler< xAOD::JetContainer > m_jetKey
bool selectObject(const ObjType &obj)
Simple object selection.
ToolHandle< ORUtils::IOverlapRemovalTool > m_orTool
Handle to the tool.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
This module defines the arguments passed from the BATCH driver to the BATCH worker.
SG::AuxElement::ConstAccessor< inputFlag_t > inputAccessor_t
Input object accessor.
SG::AuxElement::Decorator< inputFlag_t > inputDecorator_t
Input object decorator (for convenience if users want it).
SG::AuxElement::ConstAccessor< outputFlag_t > outputAccessor_t
Output object accessor (for convenience).
@ PriVtx
Primary vertex.
Jet_v1 Jet
Definition of the current "jet version".
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TauJet_v3 TauJet
Definition of the current "tau version".
Muon_v1 Muon
Reference the current persistent version:
Photon_v1 Photon
Definition of the current "egamma version".
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".
Electron_v1 Electron
Definition of the current "egamma version".
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
void handler(int sig)
signal handler
Definition rmain.cxx:99
MsgStream & msg
Definition testRead.cxx:32