ATLAS Offline Software
TriggerMatchingAugmentation.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // TriggerMatchingAugmentation.cxx
8 // Author: Jacob Searcy (jsearcy@umich.edu)
9 //
10 
11 // local includes
13 
14 // EDM includes
17 #include "xAODMuon/MuonContainer.h"
20 #include <vector>
21 #include <string>
22 
23 namespace DerivationFramework {
24  using std::pair;
25  using std::string;
26 
28  const std::string& n,
29  const IInterface* p) :
30  AthAlgTool(t,n,p),
31  m_matchTool("Trig::MatchingTool"),
32  m_trigDec( "Trig::TrigDecisionTool/TrigDecisionTool" ),
33  m_decorPrefix("DFCommonTrigMatch_"),
34  m_muonContainerName("Muons"),
35  m_electronContainerName("Electrons"),
36  m_photonContainerName("Photons")
37  {
38  declareInterface<DerivationFramework::IAugmentationTool>(this);
39  declareProperty("MatchingTool", m_matchTool);
40  declareProperty("DecorationPrefix", m_decorPrefix);
41  declareProperty("PhotonContainerName", m_photonContainerName);
42  declareProperty("ElectronContainerName", m_electronContainerName);
43  declareProperty("MuonContainerName", m_muonContainerName);
44  declareProperty("SingleTriggerList", m_singleTriggerList);
45  declareProperty("DiMuonList", m_2mTriggerList);
46  declareProperty("DiElectronList", m_2eTriggerList);
47  declareProperty("ElectronMuonList", m_emTriggerList);
48  declareProperty( "TrigDecisionTool", m_trigDec);
49  }
50 
52  {
53  CHECK( m_trigDec.retrieve() );
54  CHECK( m_matchTool.retrieve() );
55 
56  if (m_photonContainerName.empty()) {
57  ATH_MSG_ERROR("No Photons collection provided for TriggerMatchingAugmentation!");
58  return StatusCode::FAILURE;
59  }
60  if (m_electronContainerName.empty()) {
61  ATH_MSG_ERROR("No Electrons collection provided for TriggerMatchingAugmentation!");
62  return StatusCode::FAILURE;
63  }
64  if (m_muonContainerName.empty()) {
65  ATH_MSG_ERROR("No Muon collection provided for TriggerMatchingAugmentation!");
66  return StatusCode::FAILURE;
67  }
68 
69  // Generate vectors of decorators to use in the event loop,
70  // to avoid needless overhead from searching the AuxStoreRegistry
71  for(const std::string& trigname: m_singleTriggerList) {
72  // Split up e/gamma/mu to avoid string comparisons in the event loop
73  decor_t decor(m_decorPrefix+trigname);
74  pair<const string, decor_t> decorpair(trigname,decor);
75  if (trigname.find("HLT_e")!=std::string::npos) {
76  m_1eDecorList.push_back(decorpair);
77  } else if (trigname.find("HLT_m")!=std::string::npos) {
78  m_1mDecorList.push_back(decorpair);
79  } else {
80  m_1gDecorList.push_back(decorpair);
81  }
82  // Add the trigger name/decorator pair to the selected list
83  }
84 
85  // Dilepton triggers are split by the user, so simpler to set up
86  for(const std::string& trigname: m_2mTriggerList) {
87  decor_t decor(m_decorPrefix+trigname);
88  pair<const string, decor_t> decorpair(trigname,decor);
89  m_2mDecorList.push_back(decorpair);
90  }
91  for(const std::string& trigname: m_2eTriggerList) {
92  decor_t decor(m_decorPrefix+trigname);
93  pair<const string, decor_t> decorpair(trigname,decor);
94  m_2eDecorList.push_back(decorpair);
95  }
96  for(const std::string& trigname: m_emTriggerList) {
97  decor_t decor(m_decorPrefix+trigname);
98  pair<const string, decor_t> decorpair(trigname,decor);
99  m_emDecorList.push_back(decorpair);
100  }
101 
102 
103  return StatusCode::SUCCESS;
104  }
105 
107  {
108  return StatusCode::SUCCESS;
109  }
110 
112  {
113 
114  // Retrieve the containers to decorate
115  const xAOD::PhotonContainer* photons = nullptr;
116  if (evtStore()->retrieve(photons, m_photonContainerName).isFailure()) {
117  ATH_MSG_WARNING("Couldn't retrieve " << m_photonContainerName << " from TEvent");
118  return StatusCode::FAILURE;
119  }
120  const xAOD::MuonContainer* muons = nullptr;
121  if (evtStore()->retrieve(muons, m_muonContainerName).isFailure()) {
122  ATH_MSG_WARNING("Couldn't retrieve " << m_muonContainerName << " from TEvent");
123  return StatusCode::FAILURE;
124  }
125  const xAOD::ElectronContainer* electrons = nullptr;
126  if (evtStore()->retrieve(electrons, m_electronContainerName).isFailure()) {
127  ATH_MSG_WARNING("Couldn't retrieve " << m_electronContainerName << " from TEvent");
128  return StatusCode::FAILURE;
129  }
130 
131  // Single electron triggers
132  for (const pair<const string, decor_t>& decorpair : m_1eDecorList ) {
133  const auto& trigname = decorpair.first;
134  const auto& decor = decorpair.second;
135  CHECK(matchSingle(electrons,trigname,decor));
136  }
137 
138  // Single muon triggers
139  for (const pair<const string, decor_t>& decorpair : m_1mDecorList ) {
140  const auto& trigname = decorpair.first;
141  const auto& decor = decorpair.second;
142  CHECK(matchSingle(muons,trigname,decor));
143  }
144 
145  // Single photon triggers
146  for (const pair<const string, decor_t>& decorpair : m_1gDecorList ) {
147  const auto& trigname = decorpair.first;
148  const auto& decor = decorpair.second;
149  CHECK(matchSingle(photons,trigname,decor));
150  }
151 
152  // Dielectron triggers
153  for (const pair<const string, decor_t>& decorpair : m_2eDecorList ) {
154  const auto& trigname = decorpair.first;
155  const auto& decor = decorpair.second;
156  CHECK(matchDi(electrons,electrons,trigname,decor));
157  }
158 
159  // Dimuon triggers
160  for (const pair<const string, decor_t>& decorpair : m_2mDecorList ) {
161  const auto& trigname = decorpair.first;
162  const auto& decor = decorpair.second;
163  CHECK(matchDi(muons,muons,trigname,decor));
164  }
165 
166  // Electron-muon triggers
167  for (const pair<const string, decor_t>& decorpair : m_emDecorList ) {
168  const auto& trigname = decorpair.first;
169  const auto& decor = decorpair.second;
170  CHECK(matchDi(electrons,muons,trigname,decor));
171  }
172 
173  return StatusCode::SUCCESS;
174  }
175 
176 
178  const std::string& trigger,
179  const decor_t& decor) const {
180  std::vector<const xAOD::IParticle*> particles;
181  bool fired=m_trigDec->isPassed( trigger );
182  for(const auto *p : *collection) {
183  // Avoid repeating if decoration was already attached
184  if(!decor.isAvailable(*p)) {
185  if(fired){
186  particles.clear();
187  particles.push_back( p );
188  decor(*p)=m_matchTool->match(particles,trigger);
189  }
190  }
191  else decor(*p)=false;
192  }
193  return StatusCode::SUCCESS;
194  }
195 
196 
197 
199  const xAOD::IParticleContainer* collection2,
200  const std::string& trigger,
201  const decor_t& decor) const {
202  std::vector<const xAOD::IParticle*> particles;
203  bool matched=false;
204  bool fired=m_trigDec->isPassed( trigger );
205  for(const auto *p1 : *collection1) {
206  for(const auto *p2: *collection2){
207  // Avoid repeating if decoration was already attached
208  if(!decor.isAvailable(*p1) && !decor.isAvailable(*p2)) {
209  if (fired){
210  particles.clear();
211  particles.push_back( p1 );
212  particles.push_back( p2 );
214  decor(*p1)=matched;
215  decor(*p2)=matched;
216  }
217  else{
218  decor(*p1)=matched;
219  decor(*p2)=matched;
220  }
221  }
222  }
223  }
224  return StatusCode::SUCCESS;
225  }
226 
227 
228 
229 
230 }
DerivationFramework::TriggerMatchingAugmentation::m_decorPrefix
std::string m_decorPrefix
Definition: TriggerMatchingAugmentation.h:46
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
DerivationFramework::TriggerMatchingAugmentation::m_matchTool
ToolHandle< Trig::IMatchingTool > m_matchTool
Definition: TriggerMatchingAugmentation.h:44
DerivationFramework::TriggerMatchingAugmentation::m_2eDecorList
std::vector< std::pair< const std::string, decor_t > > m_2eDecorList
Definition: TriggerMatchingAugmentation.h:61
DerivationFramework::TriggerMatchingAugmentation::m_2mTriggerList
std::vector< std::string > m_2mTriggerList
Definition: TriggerMatchingAugmentation.h:52
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
DerivationFramework::TriggerMatchingAugmentation::m_1mDecorList
std::vector< std::pair< const std::string, decor_t > > m_1mDecorList
Definition: TriggerMatchingAugmentation.h:58
DerivationFramework::TriggerMatchingAugmentation::m_muonContainerName
std::string m_muonContainerName
Definition: TriggerMatchingAugmentation.h:47
DerivationFramework::TriggerMatchingAugmentation::m_2eTriggerList
std::vector< std::string > m_2eTriggerList
Definition: TriggerMatchingAugmentation.h:53
TrigDecisionTool.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::TriggerMatchingAugmentation::initialize
StatusCode initialize()
Definition: TriggerMatchingAugmentation.cxx:51
DerivationFramework::TriggerMatchingAugmentation::m_trigDec
ToolHandle< Trig::TrigDecisionTool > m_trigDec
Definition: TriggerMatchingAugmentation.h:45
DerivationFramework::TriggerMatchingAugmentation::m_2mDecorList
std::vector< std::pair< const std::string, decor_t > > m_2mDecorList
Definition: TriggerMatchingAugmentation.h:62
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
DerivationFramework::TriggerMatchingAugmentation::m_singleTriggerList
std::vector< std::string > m_singleTriggerList
Definition: TriggerMatchingAugmentation.h:51
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
ElectronContainer.h
beamspotman.n
n
Definition: beamspotman.py:731
TriggerMatchingAugmentation.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::TriggerMatchingAugmentation::m_electronContainerName
std::string m_electronContainerName
Definition: TriggerMatchingAugmentation.h:48
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DerivationFramework::TriggerMatchingAugmentation::m_1gDecorList
std::vector< std::pair< const std::string, decor_t > > m_1gDecorList
Definition: TriggerMatchingAugmentation.h:59
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
DerivationFramework::TriggerMatchingAugmentation::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: TriggerMatchingAugmentation.cxx:111
DerivationFramework::TriggerMatchingAugmentation::m_emTriggerList
std::vector< std::string > m_emTriggerList
Definition: TriggerMatchingAugmentation.h:54
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
DerivationFramework::TriggerMatchingAugmentation::m_1eDecorList
std::vector< std::pair< const std::string, decor_t > > m_1eDecorList
Definition: TriggerMatchingAugmentation.h:57
MuonContainer.h
IMatchingTool.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
SG::Decorator::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
DerivationFramework::TriggerMatchingAugmentation::m_photonContainerName
std::string m_photonContainerName
Definition: TriggerMatchingAugmentation.h:49
DerivationFramework::TriggerMatchingAugmentation::finalize
StatusCode finalize()
Definition: TriggerMatchingAugmentation.cxx:106
AthAlgTool
Definition: AthAlgTool.h:26
DerivationFramework::TriggerMatchingAugmentation::matchDi
StatusCode matchDi(const xAOD::IParticleContainer *collection1, const xAOD::IParticleContainer *collection2, const std::string &trigger, const decor_t &decor) const
Definition: TriggerMatchingAugmentation.cxx:198
DerivationFramework::TriggerMatchingAugmentation::m_emDecorList
std::vector< std::pair< const std::string, decor_t > > m_emDecorList
Definition: TriggerMatchingAugmentation.h:63
DerivationFramework::TriggerMatchingAugmentation::matchSingle
StatusCode matchSingle(const xAOD::IParticleContainer *collection, const std::string &trigger, const decor_t &decor) const
Definition: TriggerMatchingAugmentation.cxx:177
DerivationFramework::TriggerMatchingAugmentation::TriggerMatchingAugmentation
TriggerMatchingAugmentation(const std::string &t, const std::string &n, const IInterface *p)
Definition: TriggerMatchingAugmentation.cxx:27
PhotonContainer.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
PhysDESDM_Quirks.trigger
trigger
Definition: PhysDESDM_Quirks.py:27