ATLAS Offline Software
TrigJetHypoTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // ********************************************************************
6 //
7 // NAME: TrigJetHypoTool.cxx
8 // PACKAGE: Trigger/TrigHypothesis/TrigHLTJetHypo
9 //
10 //
11 // ********************************************************************
12 
13 #include "TrigJetHypoTool.h"
14 
15 #include "GaudiKernel/StatusCode.h"
16 
19 #include "./DebugInfoCollector.h"
20 #include "./xAODJetCollector.h"
21 
23 
25 
26 
27 #include <sstream>
28 
35 
36 
38  const std::string& name,
39  const IInterface* parent) :
41  m_decisionID(HLT::Identifier::fromToolName(name))
42 {
43 }
44 
45 
47 }
48 
50 
51  if (!(m_endLabelIndex > 0)){
52  ATH_MSG_ERROR("endLabelIndex must be > 0, is " + std::to_string(m_endLabelIndex));
53  return StatusCode::FAILURE;
54  }
55 
56  if (m_endLabelIndex == 1u) {
57 
58  // This is a single-leg jet chain.
59  m_decisionIDs.push_back(m_decisionID);
60 
61  } else {
62 
63  // This is a multi-leg chain with (m_endLabelIndex - m_startLabelIndex) jet legs contained within
64 
65  if(not isLegId(m_decisionID)){
66  ATH_MSG_ERROR(name() << " is being configured to do jet selection for a multi-leg chain, from leg " << m_startLabelIndex <<
67  " to " << m_endLabelIndex << ", the HypoTool's name must therefore start with legXXX_ rather than HLT_");
68  return StatusCode::FAILURE;
69  }
70 
71  HLT::Identifier noLegNameDecisionID = getIDFromLeg(m_decisionID);
72  for (std::size_t i = m_startLabelIndex; i != m_endLabelIndex; ++i){
73  m_decisionIDs.push_back(createLegName(noLegNameDecisionID, i));
74  ATH_MSG_DEBUG("Adding jet-leg " << m_decisionIDs.size()-1 << " for " << noLegNameDecisionID << ", this is leg " << i << " in the chain:" << m_decisionIDs.back());
75  }
76 
77  }
78 
79  if (m_visitDebug){
80  DebugInfoCollector collector(name() + "_init");
81  CHECK(m_helper->getDescription(collector));
82  auto s = collector.toString();
83 
84  for(const auto& l : lineSplitter(s)){
85  ATH_MSG_INFO(l);
86  }
87  }
88 
89  if (!m_monTool.empty()) ATH_CHECK(m_monTool.retrieve());
90  return StatusCode::SUCCESS;
91 }
92 
93 
95  return StatusCode::SUCCESS;
96 }
97 
98 
101  const TrigCompositeUtils::DecisionIDContainer& previousDecisionIDs,
102  std::vector<JetDecision>& jetHypoInputs) const {
103 
104  // need only check against the decision ID corresponding to the name
105  // of this hypo. Leg indices are irrelevant at this point.
107  previousDecisionIDs)) {
108  return StatusCode::SUCCESS;
109  }
110 
111  std::unique_ptr<ITrigJetHypoInfoCollector> infocollector(nullptr);
112  std::unique_ptr<ITrigJetHypoInfoCollector> jetdumper(nullptr);
113  if(m_visitDebug){
114  auto collectorName = name() + "_" + std::to_string(m_id++);
115  infocollector.reset(new DebugInfoCollector(collectorName));
116  auto jetdumperName =
117  name()+"_passingjets_" + std::to_string(m_id++);
118  jetdumper.reset(new DebugInfoCollector(jetdumperName));
119  }
120 
121 
122  HypoJetVector hypoJets(jets->size());
123 
125  jets -> end(),
126  hypoJets.begin(),
128 
129  /* apply cleaning and hypothesis alg */
130  ATH_MSG_DEBUG("hypo helper start... "
131  << " no of jets ... "
132  << jets->size()
133  << "...");
134 
135  // steady_clock::time_point t = steady_clock::now();
136  // monitoring -- timing plots (filled for every call)
137  auto mon_NInputs = Monitored::Scalar("NJetsIn",jets->size());
138  auto mon_NOutputs = Monitored::Scalar("NJetsOut",-1);
139  auto tHypo = Monitored::Timer<std::chrono::milliseconds>("TIME_jetHypo");
140  auto monitor_group_multTime = Monitored::Group( m_monTool, tHypo, mon_NOutputs, mon_NInputs);
141 
142  xAODJetCollector jetCollector;
143  bool pass;
144  try{
145  pass = m_helper->pass(hypoJets, jetCollector, infocollector);
146  } catch(std::exception& e){
147  ATH_MSG_ERROR("Exception raised by the TrigJetHypoToolHelper: "
148  << e.what());
149  return StatusCode::FAILURE;
150  }
151  tHypo.stop();
152 
153  if (!pass) {
154 
155  if (infocollector){
156 
157  std::string msg =
158  "hypo testing done: no of input jets " + std::to_string(jets->size())
159  + " no of participating jets " + std::to_string(jetCollector.size())
160  + " pass: false ";
161 
162  infocollector->collect("TrigJetHypoTool", msg);
163  }
164 
165  return StatusCode::SUCCESS;
166  }
167 
168  CHECK(checkPassingJets(jetCollector, infocollector));
169  CHECK(reportPassingJets(jetCollector, jetHypoInputs));
170 
171  // accumulateTime(steady_clock::now() - t);
172 
173 
174  if (infocollector){
175 
176  std::string msg =
177  "hypo testing done: no of input jets " + std::to_string(jets->size())
178  + " no of particlating jets " + std::to_string(jetCollector.size())
179  + " pass: true";
180 
181 
182  infocollector->collect("TrigJetHypoTool", msg);
183  infocollector->write();
184 
185  std::stringstream ss;
186  ss << jetCollector.hypoJets();
187  jetdumper->collect("passed", ss.str());
188  }
189 
190  //monitoring -- filled in passing events
191  HypoJetVector hjv = jetCollector.hypoJets();
192 
193  mon_NOutputs = hjv.size();
194  for(const auto& j : hjv) {
195  auto mon_jetEt = Monitored::Scalar("Et", j->et()*0.001);
196  auto mon_jetEta = Monitored::Scalar("Eta", j->eta());
197  auto mon_jetPhi = Monitored::Scalar("Phi", j->phi());
198  auto mon_jetMass = Monitored::Scalar("Mass", j->m()*0.001);
199  float this_z = 999;
200  float this_negLogSigma2 = 999;
201  j->getAttribute("dipz20231122_z", this_z);
202  j->getAttribute("dipz20231122_negLogSigma2", this_negLogSigma2);
203  auto mon_dipz_z = Monitored::Scalar( "dipz_z", this_z);
204  auto mon_dipz_negLogSigma2 = Monitored::Scalar( "dipz_negLogSigma2", this_negLogSigma2);
205  auto monitor_group_passingjets = Monitored::Group( m_monTool, mon_jetEt, mon_jetEta, mon_jetPhi , mon_dipz_z, mon_dipz_negLogSigma2);
206  }
207  //monitor the passing jets for each leg (there should only be one per chain!)
208  auto legInds = jetCollector.legInds();
209  for (const auto& label : legInds) {
210  auto jets = jetCollector.hypoJets(label);
211  auto monitor_nJt = Monitored::Scalar( "NJets", jets.size());
212  auto htsum = Monitored::Scalar("HT", std::accumulate(jets.begin(), jets.end(),0.0,
213  [](double sum, const HypoJetVector::value_type jptr){return sum + jptr->et()*0.001;} ));
214  auto monitor_group_passinght = Monitored::Group(m_monTool, monitor_nJt,htsum);
215  }
216 
217  return StatusCode::SUCCESS;
218 }
219 
220 
221 const std::vector<HLT::Identifier>& TrigJetHypoTool::getIDs() const{
222  return m_decisionIDs;
223 }
224 
225 
226 const HLT::Identifier& TrigJetHypoTool::getID(std::size_t i) const{
227  return m_decisionIDs.at(i-m_startLabelIndex);
228 }
229 
230 
233  const std::unique_ptr<ITrigJetHypoInfoCollector>& infocollector) const {
234 
235  if (jetCollector.empty()) {
236  ATH_MSG_ERROR("HypoTool passed the event for " <<
237  m_chainName << " ev " << m_id <<
238  ", but did not specify which jets participated");
239  return StatusCode::FAILURE;
240  }
241 
242  auto legIndices = jetCollector.legInds();
243  if (!(legIndices.size() == (m_endLabelIndex - m_startLabelIndex))) {
244  ATH_MSG_ERROR("inconsistent number of leg indices");
245  return StatusCode::FAILURE;
246  }
247 
248  ATH_MSG_DEBUG("check passing jets? does it work?");
249  ATH_MSG_DEBUG("There are some indices: " << legIndices.size());
250  for(size_t i = 0; i < legIndices.size(); i ++){
251  ATH_MSG_DEBUG(" -- leg " << i << " has index " << legIndices.at(i));
252  }
253 
254  // jet hypo inputs:
255  // pairs of const xAOD::Jet* (first) and mutable Decision* (second)
256 
257  auto participating_jets = jetCollector.xAODJets();
258  if (infocollector) {
259  infocollector->
260  collect(name(),
261  "no of xAODJets " + std::to_string(participating_jets.size()));
262 
263  auto legInds = jetCollector.legInds();
264  std::stringstream ss;
265 
266  for(const auto& label : legInds){
267  auto jets = jetCollector.xAODJets(label);
268  ss << label << " [\n";
269  for(const auto& j : jets){
270  ss << static_cast<const void*>(j) << '\n';
271  }
272  ss << "]\n";
273  }
274  infocollector->collect(name(), ss.str());
275  }
276 
277  return StatusCode::SUCCESS;
278 }
279 
282  const std::vector<JetDecision>& jetHypoInputs) const {
283 
284  auto legIndices = jetCollector.legInds();
285  for(const auto& legInd : legIndices){
286  auto participating_jets = jetCollector.xAODJets(legInd);
287  CHECK(reportLeg(participating_jets, jetHypoInputs, legInd));
288  }
289 
290  return StatusCode::SUCCESS;
291 }
292 
293 
294 
295 
297 TrigJetHypoTool::reportLeg(const std::vector<const xAOD::Jet*>& jets,
298  const std::vector<JetDecision>& jetHypoInputs,
299  int legInd) const {
300 
301  // check if input jet is a participating jet. If so , add
302  // its Decision object.
303  for (auto& pair : jetHypoInputs) {
304  if (!inputJetParticipates(jets, pair)){continue;}
305 
306  TrigCompositeUtils::DecisionIDContainer passingIDs; // set<uint32_t>
307 
308  // Add the Leg DecisionID.
309  // Required by any downstream Steps which need to consume jets which
310  // are satisfying this leg's jet cuts and by the following ComboHypo
311  // Note that if the chain is single-leg, then the ID will be the chain-ID
312  // rathe than a leg-specific ID
313  passingIDs.insert(getID(legInd).numeric());
314 
315  // Copy these passingIDs into the Decision Object
316  // This call also performs de-duplication
317  TrigCompositeUtils::insertDecisionIDs(passingIDs, pair.second);
318  }
319 
320  return StatusCode::SUCCESS;
321 }
322 
323 
324 bool
325 TrigJetHypoTool::inputJetParticipates(const std::vector<const xAOD::Jet*>& jets,
326  const JetDecision& pair) const {
327 
328  return std::find(jets.begin(), jets.end(), pair.first) != jets.end();
329 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
lineSplitter.h
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
DebugInfoCollector::toString
virtual std::string toString() const override
Definition: DebugInfoCollector.cxx:70
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
xAODJetCollector::hypoJets
HypoJetVector hypoJets() const
Definition: xAODJetCollector.cxx:44
TrigCompositeUtils::DecisionID
unsigned int DecisionID
Definition: TrigComposite_v1.h:27
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
TrigCompositeUtils::DecisionContainer
xAOD::TrigCompositeContainer DecisionContainer
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigCompositeContainer.h:21
TrigCompositeUtils::passed
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
Definition: TrigCompositeUtilsRoot.cxx:117
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
HLT::Identifier::numeric
TrigCompositeUtils::DecisionID numeric() const
numeric ID
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:47
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
TrigJetHypoTool::m_endLabelIndex
Gaudi::Property< std::size_t > m_endLabelIndex
Definition: TrigJetHypoTool.h:83
xAODJetAsIJetFactory
Definition: xAODJetAsIJetFactory.h:6
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
python.TrigCompositeUtils.isLegId
def isLegId(chainName)
Definition: DecisionHandling/python/TrigCompositeUtils.py:18
TrigCompositeUtils::insertDecisionIDs
void insertDecisionIDs(const Decision *src, Decision *dest)
Appends the decision IDs of src to the dest decision object.
Definition: TrigCompositeUtilsRoot.cxx:80
TrigJetHypoTool::m_decisionID
HLT::Identifier m_decisionID
Definition: TrigJetHypoTool.h:68
lineSplitter
std::vector< std::string > lineSplitter(const std::string &s, char delimiter)
Definition: lineSplitter.cxx:8
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
ITrigJetHypoInfoCollector::write
virtual void write() const =0
ITrigJetHypoInfoCollector::collect
virtual void collect(const std::string &, const std::string &)=0
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
TrigJetHypoTool::TrigJetHypoTool
TrigJetHypoTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TrigJetHypoTool.cxx:37
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
TrigJetHypoTool::getID
const HLT::Identifier & getID(std::size_t) const
Definition: TrigJetHypoTool.cxx:226
xAODJetCollector::xAODJets
std::vector< const xAOD::Jet * > xAODJets() const
Definition: xAODJetCollector.cxx:18
TrigJetHypoTool::m_visitDebug
Gaudi::Property< bool > m_visitDebug
Definition: TrigJetHypoTool.h:86
xAODJetCollector::size
std::size_t size() const
Definition: xAODJetCollector.cxx:66
TrigCompositeUtils.h
TrigJetHypoTool::m_startLabelIndex
Gaudi::Property< std::size_t > m_startLabelIndex
Definition: TrigJetHypoTool.h:80
TrigJetHypoTool::reportLeg
StatusCode reportLeg(const std::vector< const xAOD::Jet * > &jets, const std::vector< JetDecision > &jetHypoInputs, int legInd) const
Definition: TrigJetHypoTool.cxx:297
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
TrigJetHypoTool.h
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
DebugInfoCollector.h
xAODJetCollector::legInds
std::vector< int > legInds() const
Definition: xAODJetCollector.cxx:95
TrigJetHypoTool::getIDs
const std::vector< HLT::Identifier > & getIDs() const
Definition: TrigJetHypoTool.cxx:221
DebugInfoCollector
Definition: DebugInfoCollector.h:13
xAODJetCollector.h
TrigJetHypoTool::m_decisionIDs
std::vector< HLT::Identifier > m_decisionIDs
Definition: TrigJetHypoTool.h:75
calibdata.exception
exception
Definition: calibdata.py:496
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
TrigJetHypoTool::initialize
StatusCode initialize()
Definition: TrigJetHypoTool.cxx:49
TrigJetHypoTool::decide
StatusCode decide(const xAOD::JetContainer *jets, const TrigCompositeUtils::DecisionIDContainer &previousDecisionIDs, std::vector< JetDecision > &jetHypoInputs) const
Definition: TrigJetHypoTool.cxx:100
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
HypoJetVector
std::vector< pHypoJet > HypoJetVector
Definition: HypoJetDefs.h:27
TrigJetHypoTool::checkPassingJets
StatusCode checkPassingJets(const xAODJetCollector &, const std::unique_ptr< ITrigJetHypoInfoCollector > &) const
Definition: TrigJetHypoTool.cxx:232
TrigJetHypoTool::m_id
std::atomic< size_t > m_id
Definition: TrigJetHypoTool.h:93
TrigJetHypoTool::m_chainName
Gaudi::Property< std::string > m_chainName
Definition: TrigJetHypoTool.h:89
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
HLT::Identifier
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:20
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
TrigJetHypoTool::reportPassingJets
StatusCode reportPassingJets(const xAODJetCollector &, const std::vector< JetDecision > &jetHypoInputs) const
Definition: TrigJetHypoTool.cxx:281
TrigJetHypoTool::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigJetHypoTool.h:95
xAODJetCollector::empty
bool empty() const
Definition: xAODJetCollector.cxx:68
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TrigCompositeUtils::Decision
xAOD::TrigComposite Decision
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:20
TrigJetHypoTool::~TrigJetHypoTool
~TrigJetHypoTool()
Definition: TrigJetHypoTool.cxx:46
xAODJetAsIJetFactory.h
xAODJetCollector
Definition: xAODJetCollector.h:20
TrigJetHypoTool::JetDecision
std::pair< const xAOD::Jet *, TrigCompositeUtils::Decision * > JetDecision
Definition: TrigJetHypoTool.h:48
TrigCompositeUtils::createLegName
HLT::Identifier createLegName(const HLT::Identifier &chainIdentifier, size_t counter)
Generate the HLT::Identifier which corresponds to a specific leg of a given chain.
Definition: TrigCompositeUtilsRoot.cxx:166
TrigJetHypoTool::finalize
StatusCode finalize()
Definition: TrigJetHypoTool.cxx:94
TrigCompositeUtils::isLegId
bool isLegId(const HLT::Identifier &legIdentifier)
Recognise whether the chain ID is a leg ID.
Definition: TrigCompositeUtilsRoot.cxx:204
TrigJetHypoTool::m_helper
ToolHandle< ITrigJetHypoToolHelper > m_helper
Definition: TrigJetHypoTool.h:77
TrigCompositeUtils::DecisionIDContainer
std::set< DecisionID > DecisionIDContainer
Definition: TrigComposite_v1.h:28
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
Trig::FeatureAccessImpl::collect
void collect(const HLT::TriggerElement *te, std::vector< Trig::Feature< T > > &data, const std::string &label, unsigned int condition, const std::string &teName, const HLT::TrigNavStructure *navstructure)
actual feature acceess implementation It has (thanks to the ClassTraits) functionality to flatten con...
Definition: FeatureCollectAthena.h:299
TrigJetHypoTool::inputJetParticipates
bool inputJetParticipates(const std::vector< const xAOD::Jet * > &jets, const JetDecision &pair) const
Definition: TrigJetHypoTool.cxx:325
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
TrigCompositeUtils::getIDFromLeg
HLT::Identifier getIDFromLeg(const HLT::Identifier &legIdentifier)
Generate the HLT::Identifier which corresponds to the chain name from the leg name.
Definition: TrigCompositeUtilsRoot.cxx:180
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
AthAlgTool
Definition: AthAlgTool.h:26
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
Identifier
Definition: IdentifierFieldParser.cxx:14