ATLAS Offline Software
TrigL1FexJetMonitorTool.cxx
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 */
6 
10 
11 #include "./JTMContainers.h"
12 #include "./L1MonitorAdaptors.h"
13 #include "./DataStructs.h"
14 #include <memory>
15 
17 
18 template<typename T>
20  const std::string& name,
21  const IInterface* parent)
22  : base_class( type, name, parent )
23 {
24  declareProperty("l1container", m_l1jetContainerkey);
25 
26 }
27 
28 
29 
30 template<typename T>
32 {
33  ATH_CHECK(m_l1jetContainerkey.initialize());
34 
35  if (m_doMatching) {
36  m_offmatchedKey =
37  m_l1jetContainerkey.key() + ".matched_" + m_offlineJetContainerToMatch;
38 
39  m_offptdiffKey =
40  m_l1jetContainerkey.key() + ".ptdiff_" + m_offlineJetContainerToMatch;
41 
42  m_offenergydiffKey =
43  m_l1jetContainerkey.key() + ".energydiff_" + m_offlineJetContainerToMatch;
44 
45  m_offmassdiffKey =
46  m_l1jetContainerkey.key() + ".massdiff_" + m_offlineJetContainerToMatch;
47 
48  m_offptrespKey =
49  m_l1jetContainerkey.key() + ".ptresp_" + m_offlineJetContainerToMatch;
50 
51  m_offenergyrespKey =
52  m_l1jetContainerkey.key() + ".energyresp_" + m_offlineJetContainerToMatch;
53 
54  m_offmassrespKey =
55  m_l1jetContainerkey.key() + ".massresp_" + m_offlineJetContainerToMatch;
56 
57  m_offptrefKey =
58  m_l1jetContainerkey.key() + ".ptRef_" + m_offlineJetContainerToMatch;
59 
60  m_offetarefKey =
61  m_l1jetContainerkey.key() + ".etaRef_" + m_offlineJetContainerToMatch;
62 
63  ATH_CHECK(m_offmatchedKey.initialize() );
64  ATH_CHECK(m_offptdiffKey.initialize() );
65  ATH_CHECK(m_offenergydiffKey.initialize() );
66  ATH_CHECK(m_offmassdiffKey.initialize() );
67  ATH_CHECK(m_offptrespKey.initialize() );
68  ATH_CHECK(m_offenergyrespKey.initialize() );
69  ATH_CHECK(m_offmassrespKey.initialize() );
70  ATH_CHECK(m_offptrefKey.initialize() );
71  ATH_CHECK(m_offetarefKey.initialize() );
72 
73  m_hltmatchedKey =
74  m_l1jetContainerkey.key() + ".matched_" + m_HLTJetContainerToMatch;
75 
76  m_hltptdiffKey =
77  m_l1jetContainerkey.key() + ".ptdiff_" + m_HLTJetContainerToMatch;
78 
79  m_hltenergydiffKey =
80  m_l1jetContainerkey.key() + ".energydiff_" + m_HLTJetContainerToMatch;
81 
82  m_hltmassdiffKey =
83  m_l1jetContainerkey.key() + ".massdiff_" + m_HLTJetContainerToMatch;
84 
85  m_hltptrespKey =
86  m_l1jetContainerkey.key() + ".ptresp_" + m_HLTJetContainerToMatch;
87 
88  m_hltenergyrespKey =
89  m_l1jetContainerkey.key() + ".energyresp_" + m_HLTJetContainerToMatch;
90 
91  m_hltmassrespKey =
92  m_l1jetContainerkey.key() + ".massresp_" + m_HLTJetContainerToMatch;
93 
94  m_hltptrefKey =
95  m_l1jetContainerkey.key() + ".ptRef_" + m_HLTJetContainerToMatch;
96 
97  m_hltetarefKey =
98  m_l1jetContainerkey.key() + ".etaRef_" + m_HLTJetContainerToMatch;
99 
100  ATH_CHECK(m_hltmatchedKey.initialize());
101  ATH_CHECK(m_hltptdiffKey.initialize());
102  ATH_CHECK(m_hltenergydiffKey.initialize());
103  ATH_CHECK(m_hltmassdiffKey.initialize());
104  ATH_CHECK(m_hltptrespKey.initialize());
105  ATH_CHECK(m_hltenergyrespKey.initialize());
106  ATH_CHECK(m_hltmassrespKey.initialize());
107  ATH_CHECK(m_hltptrefKey.initialize());
108  ATH_CHECK(m_hltetarefKey.initialize());
109 
110  } else {
111  // declare the keys unused if no matching is configured
112 
113  // offline container matching
114  ATH_CHECK(m_offmatchedKey.initialize(false));
115  ATH_CHECK(m_offptdiffKey.initialize(false));
116  ATH_CHECK(m_offenergydiffKey.initialize(false));
117  ATH_CHECK(m_offmassdiffKey.initialize(false));
118  ATH_CHECK(m_offptrespKey.initialize(false));
119  ATH_CHECK(m_offenergyrespKey.initialize(false));
120  ATH_CHECK(m_offmassrespKey.initialize(false));
121  ATH_CHECK(m_offptrefKey.initialize(false));
122  ATH_CHECK(m_offetarefKey.initialize(false));
123 
124  // trigger container matching
125  ATH_CHECK(m_hltmatchedKey.initialize(false));
126  ATH_CHECK(m_hltptdiffKey.initialize(false));
127  ATH_CHECK(m_hltenergydiffKey.initialize(false));
128  ATH_CHECK(m_hltmassdiffKey.initialize(false));
129  ATH_CHECK(m_hltptrespKey.initialize(false));
130  ATH_CHECK(m_hltenergyrespKey.initialize(false));
131  ATH_CHECK(m_hltmassrespKey.initialize(false));
132  ATH_CHECK(m_hltptrefKey.initialize(false));
133  ATH_CHECK(m_hltetarefKey.initialize(false));
134  }
135 
136  return StatusCode::SUCCESS;
137 }
138 
139 
140 
141 template<typename T>
143 TrigL1FexJetMonitorTool<T>::getData(const EventContext& ctx,
144  std::vector<JetData>& jetData
145  ) const{
146 
147 
148  // Retrieve the L1 jet container
149  SG::ReadHandle<JetContainer> jets(m_l1jetContainerkey, ctx);
150  if( !jets.isValid() ){
151  // the L1 containers should _always_ be present, although may be empty.
152  ATH_MSG_WARNING("evtStore() does not contain the L1 jet collection with name "
153  << m_l1jetContainerkey);
154  return StatusCode::SUCCESS;
155  }
156 
157  // find variables associated with jets in the input container.
158  for(const auto jet : *jets){
159  /*
160  Ensure that the the et is above a hardware threshold:
161  From Sergi Rodriguez 23/02/2022
162  in the bitwise simulation we also have an energy threshold,
163  which is taken from the trigger menu.
164  If the Et is below the threshold the TOB word is set to 0
165  */
166 
167  if (vetoJet(jet)) {continue;} // see L1MonitoredAdaptors
168 
169  jetData.emplace_back(et(jet)*0.001, // see L1MonitoredAdaptors
170  jet->eta(),
171  jet->phi(),
172  et_label(jet));
173 
174  }
175  return StatusCode::SUCCESS;
176 }
177 
178 
179 
180 template<typename T>
183  MatchToEnum matchTo,
184  std::vector<JetMatchData>& jetMatchData
185  ) const {
186  if (!m_doMatching) {
187  // otherwise will attempt to use uniniatialied Keys
188  return StatusCode::SUCCESS;
189  }
190 
191  std::unique_ptr<SG::ReadDecorHandle<JetContainer, char>> matchedHandle;
192  std::unique_ptr<SG::ReadDecorHandle<JetContainer, double>> ptdiffHandle;
193  std::unique_ptr<SG::ReadDecorHandle<JetContainer, double>> energydiffHandle;
194  std::unique_ptr<SG::ReadDecorHandle<JetContainer, double>> massdiffHandle;
195  std::unique_ptr<SG::ReadDecorHandle<JetContainer, double>> ptrespHandle;
196  std::unique_ptr<SG::ReadDecorHandle<JetContainer, double>> energyrespHandle;
197  std::unique_ptr<SG::ReadDecorHandle<JetContainer, double>> massrespHandle;
198  std::unique_ptr<SG::ReadDecorHandle<JetContainer, double>> ptrefHandle;
199  std::unique_ptr<SG::ReadDecorHandle<JetContainer, double>> etarefHandle;
200 
201  if (matchTo == MatchToEnum::hlt) {
202 
203  matchedHandle.reset(new SG::ReadDecorHandle<JetContainer, char> (m_hltmatchedKey, ctx));
204  ptdiffHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_hltptdiffKey, ctx));
205  energydiffHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_hltenergydiffKey, ctx));
206  massdiffHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_hltmassdiffKey, ctx));
207  ptrespHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_hltptrespKey, ctx));
208  energyrespHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_hltenergyrespKey, ctx));
209  massrespHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_hltmassrespKey, ctx));
210  ptrefHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_hltptrefKey, ctx));
211  etarefHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_hltetarefKey, ctx));
212  } else if (matchTo == MatchToEnum::offline) {
213  matchedHandle.reset(new SG::ReadDecorHandle<JetContainer, char> (m_offmatchedKey, ctx));
214  ptdiffHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_offptdiffKey, ctx));
215  energydiffHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_offenergydiffKey, ctx));
216  massdiffHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_offmassdiffKey, ctx));
217  ptrespHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_offptrespKey, ctx));
218  energyrespHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_offenergyrespKey, ctx));
219  massrespHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_offmassrespKey, ctx));
220  ptrefHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_offptrefKey, ctx));
221  etarefHandle.reset(new SG::ReadDecorHandle<JetContainer, double> (m_offetarefKey, ctx));
222  } else {
223  ATH_MSG_ERROR ("unsupported MatchTo value");
224  return StatusCode::FAILURE;
225  }
226 
227  ATH_CHECK((*matchedHandle).initialize());
228  ATH_CHECK((*ptdiffHandle).initialize());
229  ATH_CHECK((*energydiffHandle).initialize());
230  ATH_CHECK((*massdiffHandle).initialize());
231  ATH_CHECK((*ptrespHandle).initialize());
232  ATH_CHECK((*energyrespHandle).initialize());
233  ATH_CHECK((*massrespHandle).initialize());
234  ATH_CHECK((*ptrefHandle).initialize());
235  ATH_CHECK((*etarefHandle).initialize());
236 
237 
238  // Loop over L1 jets and fill pt, energy, mass differences and responses
239  // between matched jets, plus reference pT and eta
240 
241  // Retrieve the L1 jet container
242  SG::ReadHandle<JetContainer> jets(m_l1jetContainerkey, ctx);
243  if(!jets.isValid()){
244  // the L1 containers should _always_ be present, although may be empty.
245  ATH_MSG_WARNING("evtStore() does not contain the L1 jet collection with name "
246  << m_l1jetContainerkey);
247  return StatusCode::SUCCESS;
248  }
249 
250  for(const auto jet : *jets){
251  bool matched = (*matchedHandle)(*jet);
252 
253  if(matched){
254  jetMatchData.emplace_back((*ptdiffHandle)(*jet),
255  (*energydiffHandle)(*jet),
256  (*massdiffHandle)(*jet),
257  (*ptrespHandle)(*jet),
258  (*energyrespHandle)(*jet),
259  (*massrespHandle)(*jet),
260  (*ptrefHandle)(*jet),
261  (*etarefHandle)(*jet));
262  }
263  }
264 
265  return StatusCode::SUCCESS;
266 }
267 
272 
273 
xAOD::et
et
Definition: TrigEMCluster_v1.cxx:25
MatchToEnum::offline
@ offline
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MatchToEnum::hlt
@ hlt
TrigL1FexJetMonitorTool::m_l1jetContainerkey
SG::ReadHandleKey< JetContainer > m_l1jetContainerkey
Definition: TrigL1FexJetMonitorTool.h:48
L1MonitorAdaptors.h
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
JTMContainers.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
TrigL1FexJetMonitorTool::getMatchData
virtual StatusCode getMatchData(const EventContext &ctx, MatchToEnum, std::vector< JetMatchData > &jetData) const override
Definition: TrigL1FexJetMonitorTool.cxx:182
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthMonitorAlgorithm.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
et_label
std::string et_label(const xAOD::jFexSRJetRoI *)
Definition: L1MonitorAdaptors.h:20
TrigL1FexJetMonitorTool
Definition: TrigL1FexJetMonitorTool.h:22
TrigL1FexJetMonitorTool::getData
virtual StatusCode getData(const EventContext &ctx, std::vector< JetData > &jetData) const override
Definition: TrigL1FexJetMonitorTool.cxx:143
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
TrigL1FexJetMonitorTool::initialize
virtual StatusCode initialize() override
Definition: TrigL1FexJetMonitorTool.cxx:31
TrigL1FexJetMonitorTool::TrigL1FexJetMonitorTool
TrigL1FexJetMonitorTool(const std::string &, const std::string &, const IInterface *)
Definition: TrigL1FexJetMonitorTool.cxx:19
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TrigL1FexJetMonitorTool.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
ReadDecorHandle.h
Handle class for reading a decoration on an object.
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
MatchToEnum
MatchToEnum
Definition: ITrigJetMonitorTool.h:17
DataStructs.h
vetoJet
bool vetoJet(const xAOD::jFexSRJetRoI *j)
Definition: L1MonitorAdaptors.h:14