ATLAS Offline Software
Loading...
Searching...
No Matches
DisplacedJetRankComboHypoTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
6#include "xAODJet/Jet.h"
7
8DisplacedJetRankComboHypoTool::DisplacedJetRankComboHypoTool(const std::string& type, const std::string& name, const IInterface* parent): ComboHypoToolBase(type, name, parent) {}
9
11 return StatusCode::SUCCESS;
12}
13
14StatusCode DisplacedJetRankComboHypoTool::decide(Combo::LegDecisionsMap& passingLegs, const EventContext& /*context*/) const{
15 // if no combinations passed, then exit
16 if (passingLegs.size() == 0) {
17 return StatusCode::SUCCESS;
18 }
19
20 std::vector<std::vector<Combo::LegDecision>> legDecisions;
21 ATH_CHECK(selectLegs(passingLegs, legDecisions));
22
23 //get all the passing jets across all legs valid for this tool
24 //also fill a map of jet -> decisions
25 //derive ranks for these jets
26 //get the list of decision objects which can go on
27
28 //need to establish which leg ids come from the displaced jet trigger
29 std::unordered_set<TrigCompositeUtils::DecisionID> dispj_leg_ids;
30
31 ATH_MSG_DEBUG("Have "<<passingLegs.size()<<" passing legs in");
32
33 for(auto legId: legDecisionIds()){
34 if(!passingLegs.contains(legId)) continue;
35
36 auto decs = passingLegs[legId];
37 if(decs.size() == 0) continue;
38
39 const TrigCompositeUtils::Decision* decision(*(decs[0]));
40 if(decision->hasObjectLink("djtrig_counts")){
41 dispj_leg_ids.insert(legId);
42 }
43 }
44
45 ATH_MSG_DEBUG("Have "<<dispj_leg_ids.size()<<" dispjet legs");
46
47 std::vector<const xAOD::Jet*> input_jets;
48 std::map<const xAOD::Jet*, std::vector<Combo::LegDecision>> jet_decisions;
49
50 //populate jet decision map first
51 for(const auto& leg_decs : legDecisions){
52 for(auto dec_pair : leg_decs){
53 const TrigCompositeUtils::Decision* decision(*(dec_pair.second));
54
55 //this leg is not a displaced jet leg
56 //this tool should ignore it
57 if(dispj_leg_ids.count(dec_pair.first) == 0) continue;
58
59 //find the jet feature
60 std::vector<TrigCompositeUtils::LinkInfo<xAOD::JetContainer>> jet_feature_links = TrigCompositeUtils::findLinks<xAOD::JetContainer>(decision, TrigCompositeUtils::featureString(), TrigDefs::lastFeatureOfType);
61 if(jet_feature_links.size() == 0) continue; //verify that we get a jet
62 ATH_CHECK(jet_feature_links.size() == 1); //ensure we only have 1 link
63 const TrigCompositeUtils::LinkInfo<xAOD::JetContainer> jet_feature_link = jet_feature_links.at(0);
64 //verify if the feature link is valid
65 ATH_CHECK(jet_feature_link.isValid());
66 const xAOD::Jet* jet = *(jet_feature_link.link);
67
68 jet_decisions[jet].push_back(dec_pair);
69 }
70 }
71
72 ATH_MSG_DEBUG("Have "<<jet_decisions.size()<<" jets");
73
74
75 //fill the input_jets vector
76 //filled from the map key which ensures it only gets one entry per jet
77 for(const auto & pair: jet_decisions){
78 input_jets.push_back(pair.first);
79 }
80
81 if(input_jets.empty()){
82 //reject all legs
83 //this should not happen
84 ATH_MSG_DEBUG("No input jets, rejecting all legs");
85 eraseFromLegDecisionsMap(passingLegs);
86 return StatusCode::SUCCESS;
87 }
88
89 //apply max jet cut to the number of input passing jets
90 if(m_maxjets > 0 && input_jets.size() > m_maxjets){
91 //max jets cut
92 //event fails
93 ATH_MSG_DEBUG("Reject event as it has "<<input_jets.size()<<" input passing jets but max jet cut is "<<m_maxjets);
94 eraseFromLegDecisionsMap(passingLegs);
95 return StatusCode::SUCCESS;
96 }
97
98
99 //rank jets by pt
100 std::sort(input_jets.begin(), input_jets.end(), [](const xAOD::Jet* a, const xAOD::Jet* b) -> bool
101 {
102 return a->pt() > b->pt();
103 }
104 );
105
106 //map of legid -> vector of passing decisions
107 Combo::LegDecisionsMap accepted_decisions_by_leg;
108
109 unsigned int n_jets_passed = 0;
110 //make a list of all decisions which are associated with passed jets
111 for(size_t i = 0; i<input_jets.size(); i++){
112 if(i > m_rankcut) continue; //skip jet as it is outside the rank cut
113 n_jets_passed += 1;
114
115 //get all the decisions pairs [legId, decision] for this jet
116 for(auto leg_dec_pair: jet_decisions.at(input_jets.at(i))){
117 accepted_decisions_by_leg[leg_dec_pair.first].push_back(leg_dec_pair.second);
118 ATH_MSG_DEBUG("Accepting decision for jet "<<input_jets.at(i)->pt()/1000.0);
119 }
120 }
121
122
123 if(n_jets_passed < input_jets.size()){
124 //check that the number of jets has changed
125 //this is an optimisation to avoid a needless loop when all jets pass
126 //update the legs to only pass the decisions which are associated with passing jets
127 for (auto& legIt : passingLegs) {
128 if(dispj_leg_ids.count(legIt.first) == 0) continue; //do not do anything with none dispj legs
129
130 auto accepted_decisions_on_leg = accepted_decisions_by_leg.find(legIt.first);
131
132 if(accepted_decisions_on_leg != accepted_decisions_by_leg.end()){
133 //update the list of decisions
134 legIt.second = accepted_decisions_on_leg->second;
135 ATH_MSG_DEBUG("Updating leg "<<legIt.first<<" with "<<accepted_decisions_on_leg->second.size()<<" decisions");
136 }else{
137 //no jets pass this leg and the pt rank cut
138 //empty the leg
139 ATH_MSG_DEBUG("Updating leg "<<legIt.first<<"; clearing decisions");
140 legIt.second.clear();
141 }
142 }
143 }
144
145 //apply the multiplicity rules
146 auto lm = legMultiplicity();
147 for(size_t i=0; i<lm.size(); i++){
148 auto legId = legDecisionId(i);
149
150 if(passingLegs[legId].size() < (size_t)(lm.at(i))){
151 //leg has not got enough passes
152 //whole event fails as a leg does not pass
153 ATH_MSG_DEBUG("Leg "<<legId<<" fails mulitplicity check, rejecting event");
154 eraseFromLegDecisionsMap(passingLegs);
155 return StatusCode::SUCCESS;
156 }
157 }
158
159 return StatusCode::SUCCESS;
160}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
static Double_t a
const std::vector< int > & legMultiplicity() const
Gets the number of legs and the multiplicity required on each leg.
HLT::Identifier legDecisionId(size_t i) const
Retrieves this ComboHypoTool's chain's decision ID for a given leg.
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,...
void eraseFromLegDecisionsMap(Combo::LegDecisionsMap &passingLegs) const
For when the tool rejects all combinations.
ComboHypoToolBase(const std::string &type, const std::string &name, const IInterface *parent)
const std::vector< HLT::Identifier > & legDecisionIds() const
Retrieves this ComboHypoTool's chain's decision IDs for all legs.
Gaudi::Property< unsigned int > m_maxjets
Gaudi::Property< unsigned int > m_rankcut
DisplacedJetRankComboHypoTool(const std::string &type, const std::string &name, const IInterface *parent)
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
STL class.
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.
const std::string & featureString()
void findLinks(const Decision *start, const std::string &linkName, std::vector< LinkInfo< T > > &links, unsigned int behaviour=TrigDefs::allFeaturesOfType, std::set< const xAOD::TrigComposite * > *fullyExploredFrom=nullptr)
search back the TC links for the object of type T linked to the one of TC (recursively) Populates pro...
static const unsigned int lastFeatureOfType
Run 3 "enum". Only return the final feature along each route through the navigation.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
Jet_v1 Jet
Definition of the current "jet version".
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22
ElementLink< T > link
Link to the feature.
Definition LinkInfo.h:55