ATLAS Offline Software
JetCleaningSelector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 #include "TopEvent/EventTools.h"
7 #include "xAODJet/JetContainer.h"
10 using namespace TopEventSelectionTools;
11 
12 namespace top {
13  JetCleaningSelector::JetCleaningSelector(const std::string& level, std::shared_ptr<top::TopConfig> config) :
14  m_level(level),
15  m_useLooseBad(true),
16  m_config(config) {
17  if (!m_config->isTruthDxAOD()) {
18  m_jetCleaningToolLooseBad = ToolHandle<IJetSelector>("JetCleaningToolLooseBad");
19  m_jetCleaningToolTightBad = ToolHandle<IJetSelector>("JetCleaningToolTightBad");
20  m_jetEventCleaningToolLooseBad = ToolHandle<ECUtils::IEventCleaningTool>("JetEventCleaningToolLooseBad");
21  m_jetEventCleaningToolTightBad = ToolHandle<ECUtils::IEventCleaningTool>("JetEventCleaningToolTightBad");
22 
23  if (m_level != "LooseBad" && m_level != "TightBad") {
24  ATH_MSG_ERROR("JetCleaningSelector level not recognised - " << m_level << "\n"
25  << "Should be LooseBad or TightBad");
26  throw std::runtime_error ("JetCleaningSelector: Cannot continue");
27  }
28 
29  if (m_level == "LooseBad") m_useLooseBad = true;
30  if (m_level == "TightBad") m_useLooseBad = false;
31 
32 
33  m_useEventLevelJetCleaningTool = m_config->useEventLevelJetCleaningTool();
34 
35  // Checking configuration for particle-flow jets:
36  if (m_config->useParticleFlowJets()) {
38  "JetCleaningSelector: This cleaning configuration is not available for particle-flow jets. The only available configuration is\n JETCLEAN LooseBad");
39  }
40 
41  // We can't yet use jet cleaning or event cleaning tools for particle-flow jets
42  if (!m_config->useParticleFlowJets()) {
45  m_jetEventCleaningToolLooseBad.retrieve(), "Failed to retrieve JetEventCleaningToolLooseBad");
46  else top::check(m_jetEventCleaningToolTightBad.retrieve(), "Failed to retrieve JetEventCleaningToolTightBad");
47 
48  } else {
50  m_jetCleaningToolLooseBad.retrieve(), "Failed to retrieve JetCleaningToolLooseBad");
51  else top::check(m_jetCleaningToolTightBad.retrieve(), "Failed to retrieve JetCleaningToolTightBad");
52  }
53  } // end (!m_config->useParticleFlowJets())
54  }
55  }
56 
58  if (m_config->isTruthDxAOD()) return true;
59 
60  if (m_config->useParticleFlowJets()) {
61  top::check(event.m_info->isAvailable<char>(
62  "DFCommonJets_eventClean_LooseBad"),
63  "JetCleaningSelector: DFCommonJets_eventClean_LooseBad not available in EventInfo. Needed for particle-flow jets cleaning");
64  bool result = event.m_info->auxdataConst<char>("DFCommonJets_eventClean_LooseBad");
65 
66  if (result && m_config->useBadBatmanCleaning()) {
67  // passed the standard cleaning
68  // finally, check if the BadBatman cleaning should be applied
70  }
71  return result;
72  }
73 
74  // There are two jet cleaning tools and we have a request to test the event level one
75  // These should be very close/ equivalent as we already handle the OR and JVT elsewhere
77  // If we are to use the event object, we can just do acceptEvent
78 
79  if (m_useLooseBad) return m_jetEventCleaningToolLooseBad->acceptEvent(&event.m_jets);
80  else return m_jetEventCleaningToolTightBad->acceptEvent(&event.m_jets);
81  }
82  // This is the default/standard method for jet cleaning
83  else {
84  for (const auto* const jetPtr : event.m_jets) {
85  if (m_useLooseBad) {
86  if (m_jetCleaningToolLooseBad->keep(*jetPtr) == 0) {
87  return false;
88  }
89  } else {
90  if (m_jetCleaningToolTightBad->keep(*jetPtr) == 0) {
91  return false;
92  }
93  }
94  }
95  }
96 
97  // passed the standard cleaning
98  // finally, check if the BadBatman cleaning should be applied
99  if (m_config->useBadBatmanCleaning()) {
101  }
102 
103  return true;
104  }
105 
106  std::string JetCleaningSelector::name() const {
107  return "JETCLEAN " + m_level;
108  }
109 
111  // we apply this only to Data
112  if (m_config->isMC()) {
113  return true;
114  }
115  // first check if the RunNUmber are within the specified range
116  const unsigned int runNumber = event.m_info->runNumber();
117 
118  if ((m_config->badBatmanCleaningMin() >= runNumber) || (m_config->badBatmanCleaningMax() <= runNumber)) {
119  // is outside of the specified range
120  return true;
121  }
122 
123  top::check(event.m_info->isAvailable<char>(
124  "DFCommonJets_isBadBatman"),
125  "JetCleaningSelector: DFCommonJets_isBadBatman not available in EventInfo. Needed for BadBatman cleaning");
126  const bool result = event.m_info->auxdataConst<char>("DFCommonJets_isBadBatman");
127  // we need to return negation of the flag as it is true for problematic events
128  return !result;
129  }
130 }
get_generator_info.result
result
Definition: get_generator_info.py:21
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
top::JetCleaningSelector::name
std::string name() const override
Print the name of the tool and level.
Definition: JetCleaningSelector.cxx:106
top::JetCleaningSelector::m_config
std::shared_ptr< top::TopConfig > m_config
Definition: JetCleaningSelector.h:76
MsgCategory.h
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
top::JetCleaningSelector::m_jetCleaningToolLooseBad
ToolHandle< IJetSelector > m_jetCleaningToolLooseBad
The jet cleaning tools.
Definition: JetCleaningSelector.h:64
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
top::JetCleaningSelector::m_useEventLevelJetCleaningTool
bool m_useEventLevelJetCleaningTool
Definition: JetCleaningSelector.h:74
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
top::JetCleaningSelector::m_jetEventCleaningToolLooseBad
ToolHandle< ECUtils::IEventCleaningTool > m_jetEventCleaningToolLooseBad
The jet event cleaning tools.
Definition: JetCleaningSelector.h:68
top::JetCleaningSelector::m_jetEventCleaningToolTightBad
ToolHandle< ECUtils::IEventCleaningTool > m_jetEventCleaningToolTightBad
Definition: JetCleaningSelector.h:69
top::JetCleaningSelector::m_jetCleaningToolTightBad
ToolHandle< IJetSelector > m_jetCleaningToolTightBad
Definition: JetCleaningSelector.h:65
TopConfig.h
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
JetContainer.h
top::JetCleaningSelector::checkBadBatman
bool checkBadBatman(const top::Event &event) const
A helper function to check if the event passes BadBatman cleaning in a specified range (from config) ...
Definition: JetCleaningSelector.cxx:110
top::JetCleaningSelector::m_useLooseBad
bool m_useLooseBad
Definition: JetCleaningSelector.h:73
top::Event
Very simple class to hold event data after reading from a file.
Definition: Event.h:49
top::JetCleaningSelector::apply
bool apply(const top::Event &event) const override
Only accept the event if the tool says all the jets are okay.
Definition: JetCleaningSelector.cxx:57
JetCleaningSelector.h
top::JetCleaningSelector::m_level
std::string m_level
The level to configure to, so we can print it in the name.
Definition: JetCleaningSelector.h:72