ATLAS Offline Software
Loading...
Searching...
No Matches
OverlapRemovalGenUseAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 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_electronKey.declareOutput(m_overlapLabel);
56 m_photonKey.declareOutput(m_overlapLabel);
57 m_muonKey.declareOutput(m_overlapLabel);
58 m_tauKey.declareOutput(m_overlapLabel);
59 ATH_CHECK(m_jetKey.initialize());
60 ATH_CHECK(m_electronKey.initialize());
61 ATH_CHECK(m_muonKey.initialize());
62 ATH_CHECK(m_vtxKey.initialize());
63 ATH_CHECK(m_photonKey.initialize(m_photonKey.empty()));
64 ATH_CHECK(m_tauKey.initialize(m_tauKey.empty()));
65
66 return StatusCode::SUCCESS;
67}
68
69//-----------------------------------------------------------------------------
70// Execute
71//-----------------------------------------------------------------------------
73{
74 const EventContext& ctx = Gaudi::Hive::currentContext();
75 // Electrons
77 if (!electrons.isValid()) {
78 ATH_MSG_FATAL("Failed to retrieve electron container "<<m_electronKey.key());
79 return StatusCode::FAILURE;
80 }
81 applySelection(*electrons);
82 // Muons
84 if (!muons.isValid()) {
85 ATH_MSG_FATAL("Failed to retrieve muon container "<<m_muonKey.key());
86 return StatusCode::FAILURE;
87 }
88 applySelection(*muons);
89 // Jets
91 if (!jets.isValid()) {
92 ATH_MSG_FATAL("Failed to retrieve jet container "<<m_jetKey.key());
93 return StatusCode::FAILURE;
94 }
95 applySelection(*jets);
96 // Taus
97 const xAOD::TauJetContainer* taus{nullptr};
98 if(!m_tauKey.empty()) {
100 if (!readHandle.isValid()) {
101 ATH_MSG_FATAL("Failed to retrieve TauJetContainer "<<m_tauKey.key());
102 return StatusCode::FAILURE;
103 }
104 taus = readHandle.cptr();
106 }
107 const xAOD::PhotonContainer* photons{nullptr};
108 if(!m_photonKey.empty()) {
110 if (!readHandle.isValid()) {
111 ATH_MSG_FATAL("Failed to retrieve PhotonContainer "<<m_photonKey.key());
112 return StatusCode::FAILURE;
113 }
114 photons = readHandle.cptr();
115 applySelection(*photons);
116 }
117
118 // Primary Vertices
120 if (!vertices.isValid()) {
121 ATH_MSG_FATAL("Failed to retrieve primary vertex container "<<m_vtxKey.key());
122 return StatusCode::FAILURE;
123 }
124 bool checkVtx = false;
125 for(const xAOD::Vertex* vtx : *vertices) {
126 if(vtx->vertexType() == xAOD::VxType::PriVtx)
127 checkVtx = true;
128 }
129
130
131 if(checkVtx) {
132 // Apply the overlap removal
133 ATH_CHECK( m_orTool->removeOverlaps(electrons.cptr(), muons.cptr(), jets.cptr(), taus, photons) );}
134 else{
135 // Reset all decorations to failing
136 ATH_MSG_DEBUG("No primary vertices found, cannot do overlap removal! Will return all fails.");
138 setDefaultDecorations(*electrons);
139 setDefaultDecorations(*muons);
141 if(photons) setDefaultDecorations(*photons);
142 }
143
144 // Dump the objects
145 ATH_MSG_VERBOSE("Dumping results");
146#ifdef XAOD_STANDALONE
147 auto msglvl = msg().level();
148#else
149 auto msglvl = msgLevel();
150#endif
151 if(msglvl >= MSG::VERBOSE){
152 printObjects(*electrons, "ele");
153 printObjects(*muons, "muo");
154 printObjects(*jets, "jet");
155 if(taus) printObjects(*taus, "tau");
156 if(photons) printObjects(*photons, "pho");
157 }
158
159 return StatusCode::SUCCESS;
160}
161
162//---------------------------------------------------------------------------
163// Reset output decoration
164//---------------------------------------------------------------------------
165 template<class ContainerType>
167 const ort::inputDecorator_t defaultDec(m_overlapLabel);
168 for(auto obj : container){
169 defaultDec(*obj) = m_defaultValue; //default to all objects being overlaps if we can't get primary vertices. Ensures the event cleaning decision fails.
170 }
171}
172
173
174//-----------------------------------------------------------------------------
175// Apply selection to a container
176//-----------------------------------------------------------------------------
177 template<class ContainerType>
179{
181 for(auto obj : container){
182 selDec(*obj) = selectObject(*obj);
183 ATH_MSG_VERBOSE(" Obj " << obj->index() << " of type " << obj->type()
184 << " selected? " << int(selDec(*obj)));
185 }
186}
187//-----------------------------------------------------------------------------
188template<class ObjType>
190{
191 if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false;
192 return true;
193}
194//-----------------------------------------------------------------------------
195template<>
197{
198 // Selection
199 if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false;
200 return true;
201}
202
203//-----------------------------------------------------------------------------
204template<>
206{
207 if(m_electronLabel.empty()) return true; //disable selection for objects with empty labels
208 const SG::AuxElement::ConstAccessor<char> acc_ElectronPass(m_electronLabel);
209 if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false;
210 if(!acc_ElectronPass(obj)) return false;
211 return true;
212}
213
214//-----------------------------------------------------------------------------
215template<>
217{
218 if(m_photonLabel.empty()) return true; //disable selection for objects with empty labels
219 const SG::AuxElement::ConstAccessor<char> acc_PhotonPass(m_photonLabel);
220 if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false;
221 if(!acc_PhotonPass(obj)) return false;
222 return true;
223}
224
225//-----------------------------------------------------------------------------
226template<>
228{
229 if(m_muonLabel.empty()) return true; //disable selection for objects with empty labels
230 const SG::AuxElement::ConstAccessor<char> acc_MuonPass(m_muonLabel);
231 if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false;
232 if(!acc_MuonPass(obj)) return false;
233 return true;
234}
235
236//-----------------------------------------------------------------------------
237template<>
239{
240 if(m_tauLabel.empty()) return true; //disable selection for objects with empty labels
241 const SG::AuxElement::ConstAccessor<char> acc_TauPass(m_tauLabel);
242 if(obj.pt() < m_ptCut*GeV || std::abs(obj.eta()) > m_etaCut) return false;
243 if(!acc_TauPass(obj)) return false;
244 return true;
245}
246
247
248//-----------------------------------------------------------------------------
249// Print object
250//-----------------------------------------------------------------------------
252 const std::string& type)
253{
256 for(auto obj : container){
257 if(selectAcc(*obj)){
258 bool overlaps = overlapAcc(*obj);
259 ATH_MSG_VERBOSE(" " << type << " pt " << obj->pt()*invGeV
260 << " eta " << obj->eta() << " phi " << obj->phi()
261 << " overlaps " << overlaps);
262 }
263 }
264}
#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.
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
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.
MsgStream & msg
Definition testRead.cxx:32