ATLAS Offline Software
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
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 it : passingLegs){
31  if(it.second.size() == 0) continue; //empty set of decisions
32  //only need to look at the first decision
33  const TrigCompositeUtils::Decision* decision(*(it.second[0]));
34  if(decision->hasObjectLink("djtrig_counts")){
35  dispj_leg_ids.insert(it.first);
36  }
37  }
38 
39  ATH_MSG_DEBUG("Have "<<dispj_leg_ids.size()<<" dispjet legs");
40 
41  std::vector<const xAOD::Jet*> input_jets;
42  std::map<const xAOD::Jet*, std::vector<Combo::LegDecision>> jet_decisions;
43 
44  //populate jet decision map first
45  for(const auto& leg_decs : legDecisions){
46  for(auto dec_pair : leg_decs){
47  const TrigCompositeUtils::Decision* decision(*(dec_pair.second));
48 
49  //this leg is not a displaced jet leg
50  //this tool should ignore it
51  if(dispj_leg_ids.count(dec_pair.first) == 0) continue;
52 
53  //find the jet feature
54  std::vector<TrigCompositeUtils::LinkInfo<xAOD::JetContainer>> jet_feature_links = TrigCompositeUtils::findLinks<xAOD::JetContainer>(decision, TrigCompositeUtils::featureString(), TrigDefs::lastFeatureOfType);
55  if(jet_feature_links.size() == 0) continue; //verify that we get a jet
56  ATH_CHECK(jet_feature_links.size() == 1); //ensure we only have 1 link
57  const TrigCompositeUtils::LinkInfo<xAOD::JetContainer> jet_feature_link = jet_feature_links.at(0);
58  //verify if the feature link is valid
59  ATH_CHECK(jet_feature_link.isValid());
60  const xAOD::Jet* jet = *(jet_feature_link.link);
61 
62  jet_decisions[jet].push_back(dec_pair);
63  }
64  }
65 
66  ATH_MSG_DEBUG("Have "<<jet_decisions.size()<<" jets");
67 
68 
69  //fill the input_jets vector
70  //filled from the map key which ensures it only gets one entry per jet
71  for(auto pair: jet_decisions){
72  input_jets.push_back(pair.first);
73  }
74 
75  if(input_jets.size() == 0){
76  //reject all legs
77  //this should not happen
78  ATH_MSG_DEBUG("No input jets, rejecting all legs");
79  eraseFromLegDecisionsMap(passingLegs);
80  return StatusCode::SUCCESS;
81  }
82 
83  //apply max jet cut to the number of input passing jets
84  if(m_maxjets > 0 && input_jets.size() > m_maxjets){
85  //max jets cut
86  //event fails
87  ATH_MSG_DEBUG("Reject event as it has "<<input_jets.size()<<" input passing jets but max jet cut is "<<m_maxjets);
88  eraseFromLegDecisionsMap(passingLegs);
89  return StatusCode::SUCCESS;
90  }
91 
92 
93  //rank jets by pt
94  std::sort(input_jets.begin(), input_jets.end(), [](const xAOD::Jet* a, const xAOD::Jet* b) -> bool
95  {
96  return a->pt() > b->pt();
97  }
98  );
99 
100  //map of legid -> vector of passing decisions
101  Combo::LegDecisionsMap accepted_decisions_by_leg;
102 
103  unsigned int n_jets_passed = 0;
104  //make a list of all decisions which are associated with passed jets
105  for(size_t i = 0; i<input_jets.size(); i++){
106  if(i > m_rankcut) continue; //skip jet as it is outside the rank cut
107  n_jets_passed += 1;
108 
109  //get all the decisions pairs [legId, decision] for this jet
110  for(auto leg_dec_pair: jet_decisions.at(input_jets.at(i))){
111  accepted_decisions_by_leg[leg_dec_pair.first].push_back(leg_dec_pair.second);
112  ATH_MSG_DEBUG("Accepting decision for jet "<<input_jets.at(i)->pt()/1000.0);
113  }
114  }
115 
116 
117  if(n_jets_passed < input_jets.size()){
118  //check that the number of jets has changed
119  //this is an optimisation to avoid a needless loop when all jets pass
120  //update the legs to only pass the decisions which are associated with passing jets
121  for (auto& legIt : passingLegs) {
122  if(dispj_leg_ids.count(legIt.first) == 0) continue; //do not do anything with none dispj legs
123 
124  auto accepted_decisions_on_leg = accepted_decisions_by_leg.find(legIt.first);
125 
126  if(accepted_decisions_on_leg != accepted_decisions_by_leg.end()){
127  //update the list of decisions
128  legIt.second = accepted_decisions_on_leg->second;
129  ATH_MSG_DEBUG("Updating leg "<<legIt.first<<" with "<<accepted_decisions_on_leg->second.size()<<" decisions");
130  }else{
131  //no jets pass this leg and the pt rank cut
132  //empty the leg
133  ATH_MSG_DEBUG("Updating leg "<<legIt.first<<"; clearing decisions");
134  legIt.second.clear();
135  }
136  }
137  }
138 
139  //apply the multiplicity rules
140  auto lm = legMultiplicity();
141  for(size_t i=0; i<lm.size(); i++){
142  auto legId = legDecisionId(i);
143 
144  if(passingLegs[legId].size() < (size_t)(lm.at(i))){
145  //leg has not got enough passes
146  //whole event fails as a leg does not pass
147  ATH_MSG_DEBUG("Leg "<<legId<<" fails mulitplicity check, rejecting event");
148  eraseFromLegDecisionsMap(passingLegs);
149  return StatusCode::SUCCESS;
150  }
151  }
152 
153  return StatusCode::SUCCESS;
154 }
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
skel.it
it
Definition: skel.GENtoEVGEN.py:396
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.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
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78