Loading [MathJax]/jax/input/TeX/config.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
DisplacedJetRankComboHypoTool.cxx
Go to the documentation of this file.
2 #include "xAODJet/JetContainer.h"
3 #include "xAODJet/Jet.h"
4 
5 DisplacedJetRankComboHypoTool::DisplacedJetRankComboHypoTool(const std::string& type, const std::string& name, const IInterface* parent): ComboHypoToolBase(type, name, parent) {}
6 
8  return StatusCode::SUCCESS;
9 }
10 
11 StatusCode DisplacedJetRankComboHypoTool::decide(Combo::LegDecisionsMap& passingLegs, const EventContext& /*context*/) const{
12  // if no combinations passed, then exit
13  if (passingLegs.size() == 0) {
14  return StatusCode::SUCCESS;
15  }
16 
17  std::vector<std::vector<Combo::LegDecision>> legDecisions;
18  ATH_CHECK(selectLegs(passingLegs, legDecisions));
19 
20  //get all the passing jets across all legs valid for this tool
21  //also fill a map of jet -> decisions
22  //derive ranks for these jets
23  //get the list of decision objects which can go on
24 
25  //need to establish which leg ids come from the displaced jet trigger
26  std::unordered_set<TrigCompositeUtils::DecisionID> dispj_leg_ids;
27 
28  ATH_MSG_DEBUG("Have "<<passingLegs.size()<<" passing legs in");
29 
30  for(auto legId: legDecisionIds()){
31  if(!passingLegs.contains(legId)) continue;
32 
33  auto decs = passingLegs[legId];
34  if(decs.size() == 0) continue;
35 
36  const TrigCompositeUtils::Decision* decision(*(decs[0]));
37  if(decision->hasObjectLink("djtrig_counts")){
38  dispj_leg_ids.insert(legId);
39  }
40  }
41 
42  ATH_MSG_DEBUG("Have "<<dispj_leg_ids.size()<<" dispjet legs");
43 
44  std::vector<const xAOD::Jet*> input_jets;
45  std::map<const xAOD::Jet*, std::vector<Combo::LegDecision>> jet_decisions;
46 
47  //populate jet decision map first
48  for(const auto& leg_decs : legDecisions){
49  for(auto dec_pair : leg_decs){
50  const TrigCompositeUtils::Decision* decision(*(dec_pair.second));
51 
52  //this leg is not a displaced jet leg
53  //this tool should ignore it
54  if(dispj_leg_ids.count(dec_pair.first) == 0) continue;
55 
56  //find the jet feature
57  std::vector<TrigCompositeUtils::LinkInfo<xAOD::JetContainer>> jet_feature_links = TrigCompositeUtils::findLinks<xAOD::JetContainer>(decision, TrigCompositeUtils::featureString(), TrigDefs::lastFeatureOfType);
58  if(jet_feature_links.size() == 0) continue; //verify that we get a jet
59  ATH_CHECK(jet_feature_links.size() == 1); //ensure we only have 1 link
60  const TrigCompositeUtils::LinkInfo<xAOD::JetContainer> jet_feature_link = jet_feature_links.at(0);
61  //verify if the feature link is valid
62  ATH_CHECK(jet_feature_link.isValid());
63  const xAOD::Jet* jet = *(jet_feature_link.link);
64 
65  jet_decisions[jet].push_back(dec_pair);
66  }
67  }
68 
69  ATH_MSG_DEBUG("Have "<<jet_decisions.size()<<" jets");
70 
71 
72  //fill the input_jets vector
73  //filled from the map key which ensures it only gets one entry per jet
74  for(auto pair: jet_decisions){
75  input_jets.push_back(pair.first);
76  }
77 
78  if(input_jets.size() == 0){
79  //reject all legs
80  //this should not happen
81  ATH_MSG_DEBUG("No input jets, rejecting all legs");
82  eraseFromLegDecisionsMap(passingLegs);
83  return StatusCode::SUCCESS;
84  }
85 
86  //apply max jet cut to the number of input passing jets
87  if(m_maxjets > 0 && input_jets.size() > m_maxjets){
88  //max jets cut
89  //event fails
90  ATH_MSG_DEBUG("Reject event as it has "<<input_jets.size()<<" input passing jets but max jet cut is "<<m_maxjets);
91  eraseFromLegDecisionsMap(passingLegs);
92  return StatusCode::SUCCESS;
93  }
94 
95 
96  //rank jets by pt
97  std::sort(input_jets.begin(), input_jets.end(), [](const xAOD::Jet* a, const xAOD::Jet* b) -> bool
98  {
99  return a->pt() > b->pt();
100  }
101  );
102 
103  //map of legid -> vector of passing decisions
104  Combo::LegDecisionsMap accepted_decisions_by_leg;
105 
106  unsigned int n_jets_passed = 0;
107  //make a list of all decisions which are associated with passed jets
108  for(size_t i = 0; i<input_jets.size(); i++){
109  if(i > m_rankcut) continue; //skip jet as it is outside the rank cut
110  n_jets_passed += 1;
111 
112  //get all the decisions pairs [legId, decision] for this jet
113  for(auto leg_dec_pair: jet_decisions.at(input_jets.at(i))){
114  accepted_decisions_by_leg[leg_dec_pair.first].push_back(leg_dec_pair.second);
115  ATH_MSG_DEBUG("Accepting decision for jet "<<input_jets.at(i)->pt()/1000.0);
116  }
117  }
118 
119 
120  if(n_jets_passed < input_jets.size()){
121  //check that the number of jets has changed
122  //this is an optimisation to avoid a needless loop when all jets pass
123  //update the legs to only pass the decisions which are associated with passing jets
124  for (auto& legIt : passingLegs) {
125  if(dispj_leg_ids.count(legIt.first) == 0) continue; //do not do anything with none dispj legs
126 
127  auto accepted_decisions_on_leg = accepted_decisions_by_leg.find(legIt.first);
128 
129  if(accepted_decisions_on_leg != accepted_decisions_by_leg.end()){
130  //update the list of decisions
131  legIt.second = accepted_decisions_on_leg->second;
132  ATH_MSG_DEBUG("Updating leg "<<legIt.first<<" with "<<accepted_decisions_on_leg->second.size()<<" decisions");
133  }else{
134  //no jets pass this leg and the pt rank cut
135  //empty the leg
136  ATH_MSG_DEBUG("Updating leg "<<legIt.first<<"; clearing decisions");
137  legIt.second.clear();
138  }
139  }
140  }
141 
142  //apply the multiplicity rules
143  auto lm = legMultiplicity();
144  for(size_t i=0; i<lm.size(); i++){
145  auto legId = legDecisionId(i);
146 
147  if(passingLegs[legId].size() < (size_t)(lm.at(i))){
148  //leg has not got enough passes
149  //whole event fails as a leg does not pass
150  ATH_MSG_DEBUG("Leg "<<legId<<" fails mulitplicity check, rejecting event");
151  eraseFromLegDecisionsMap(passingLegs);
152  return StatusCode::SUCCESS;
153  }
154  }
155 
156  return StatusCode::SUCCESS;
157 }
Jet.h
DisplacedJetRankComboHypoTool::initialize
virtual StatusCode initialize() override
Definition: DisplacedJetRankComboHypoTool.cxx:7
DisplacedJetRankComboHypoTool.h
TrigCompositeUtils::LinkInfo::link
ElementLink< T > link
Link to the feature.
Definition: LinkInfo.h:61
ComboHypoToolBase::eraseFromLegDecisionsMap
void eraseFromLegDecisionsMap(Combo::LegDecisionsMap &passingLegs) const
For when the tool rejects all combinations.
Definition: ComboHypoToolBase.cxx:253
DisplacedJetRankComboHypoTool::m_maxjets
Gaudi::Property< unsigned int > m_maxjets
Definition: DisplacedJetRankComboHypoTool.h:18
TrigCompositeUtils::LinkInfo::isValid
bool isValid() const
Definition: LinkInfo.h:43
ComboHypoToolBase::legDecisionId
HLT::Identifier legDecisionId(size_t i) const
Retrieves this ComboHypoTool's chain's decision ID for a given leg.
Definition: ComboHypoToolBase.h:60
xAOD::TrigComposite_v1::hasObjectLink
bool hasObjectLink(const std::string &name, const CLID clid=CLID_NULL) const
Check if a link to an object with a given name and type exists. CLID_NULL to not check type.
Definition: TrigComposite_v1.cxx:246
ComboHypoToolBase
Base class for tools which cut on properties of multi-object or multi-leg chains. User should derive ...
Definition: ComboHypoToolBase.h:26
Combo::LegDecisionsMap
std::map< TrigCompositeUtils::DecisionID, std::vector< ElementLink< TrigCompositeUtils::DecisionContainer > > > LegDecisionsMap
LegDecisionsMap For a given chain leg key, this map holds all Decision Objects which are active on th...
Definition: IComboHypoTool.h:28
DisplacedJetRankComboHypoTool::decide
virtual StatusCode decide(Combo::LegDecisionsMap &passingLegs, const EventContext &ctx) const override
retrieves the decisions associated to this decId, make their combinations and apply the algorithm
Definition: DisplacedJetRankComboHypoTool.cxx:11
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
lumiFormat.i
int i
Definition: lumiFormat.py:85
ComboHypoToolBase::legMultiplicity
const std::vector< int > & legMultiplicity() const
Gets the number of legs and the multiplicity required on each leg.
Definition: ComboHypoToolBase.h:54
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DisplacedJetRankComboHypoTool::DisplacedJetRankComboHypoTool
DisplacedJetRankComboHypoTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: DisplacedJetRankComboHypoTool.cxx:5
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:884
ComboHypoToolBase::selectLegs
StatusCode selectLegs(const Combo::LegDecisionsMap &IDCombMap, std::vector< std::vector< Combo::LegDecision >> &leg_decisions) const
Creates the per-leg vectors of Decision objects starting from the initial LegDecision map,...
Definition: ComboHypoToolBase.cxx:172
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
DisplacedJetRankComboHypoTool::m_rankcut
Gaudi::Property< unsigned int > m_rankcut
Definition: DisplacedJetRankComboHypoTool.h:17
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
TrigCompositeUtils::LinkInfo
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition: LinkInfo.h:28
a
TList * a
Definition: liststreamerinfos.cxx:10
JetContainer.h
ComboHypoToolBase::legDecisionIds
const std::vector< HLT::Identifier > & legDecisionIds() const
Retrieves this ComboHypoTool's chain's decision IDs for all legs.
Definition: ComboHypoToolBase.h:66