ATLAS Offline Software
EventSelectionManager.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
7 #include "TopEvent/Event.h"
8 #include "TopEvent/EventTools.h"
11 
13 
14 #include <iostream>
15 #include <string>
16 #include <sstream>
17 #include <algorithm>
18 #include <iterator>
19 
20 #include "TFile.h"
21 #include "TClass.h"
22 #include "TROOT.h"
23 
25 
27 // use ATH_MSG macros defined in the namespace TopAnalysis
28 using namespace TopAnalysis;
29 
30 namespace top {
31  EventSelectionManager::EventSelectionManager(const std::vector<SelectionConfigurationData>& selectionConfigData,
32  TFile* outputFile, const std::string& toolLoaderNames,
33  const std::shared_ptr<top::TopConfig>& config, EL::Worker* wk) {
34  std::vector<std::string> tokens;
35 
36  std::stringstream ss(toolLoaderNames);
37  std::string item;
38  char delim = ' ';
39  while (std::getline(ss, item, delim))
40  tokens.push_back(item);
41 
42  std::vector<std::unique_ptr<top::ToolLoaderBase> > toolLoaders;
43  for (const auto& toolLoaderName : tokens) {
44  //remove the lib and add namespace and Loader to the class name
45  std::string className = "top::" + toolLoaderName.substr(3) + "Loader";
46 
47  ATH_MSG_INFO("Attempting to load Tools from this class: " << className);
48  TClass* c = ::TClass::GetClass(className.c_str());
49 
50  //okay, so that failed
51  //maybe the user didn't put it in the top namespace - try again without top::?
52  if (c == nullptr) {
53  className = toolLoaderName.substr(3) + "Loader";
54  ATH_MSG_INFO("Attempting to load Tools from this class: " << className);
55  c = ::TClass::GetClass(className.c_str());
56  }
57 
58  //okay, so that worked!
59  if (c != nullptr) {
60  ATH_MSG_INFO(" Success part 1 of 2");
61  top::ToolLoaderBase* bc = static_cast<top::ToolLoaderBase*> (c->New());
62 
63  if (bc) {
64  ATH_MSG_INFO(" Success part 2 of 2");
65  toolLoaders.push_back(std::unique_ptr<top::ToolLoaderBase>(bc));
66  } else ATH_MSG_ERROR(" Failure converting to ToolLoaderBase");
67  } else ATH_MSG_WARNING(" Class " << className << " in library " << toolLoaderName <<
68  " not found - this is only a problem if you wrote one in your library");
69  }
70 
71  ATH_MSG_INFO("Telling you how I'm configured, before I do anything:");
72  for (const auto& currentConfig : selectionConfigData)
73  m_selections.emplace_back(currentConfig.m_name, currentConfig.m_cutnames, outputFile, toolLoaders, config, wk);
74  }
75 
76  EventSelectionManager::EventSelectionManager(EventSelectionManager&& other) :
77  m_selections(std::move(other.m_selections)) {
78  }
79 
80  void EventSelectionManager::countInitial(const float mcEventWeight, const float pileupWeight) {
81  for (const auto& currentSelection : m_selections)
82  currentSelection.countInitial(mcEventWeight, pileupWeight);
83  }
84 
85  void EventSelectionManager::countGRL(const float mcEventWeight, const float pileupWeight) {
86  for (const auto& currentSelection : m_selections)
87  currentSelection.countGRL(mcEventWeight, pileupWeight);
88  }
89 
90  void EventSelectionManager::countGoodCalo(const float mcEventWeight, const float pileupWeight) {
91  for (const auto& currentSelection : m_selections)
92  currentSelection.countGoodCalo(mcEventWeight, pileupWeight);
93  }
94 
95  void EventSelectionManager::countPrimaryVertex(const float mcEventWeight, const float pileupWeight) {
96  for (const auto& currentSelection : m_selections)
97  currentSelection.countPrimaryVertex(mcEventWeight, pileupWeight);
98  }
99 
101  bool save(false);
102 
103  for (const auto& currentSelection : m_selections) {
104  const bool passedThisSelection = currentSelection.apply(event);
105 
106  //save result as new branch (int)
107  event.m_info->auxdecor<int>(currentSelection.name()) = passedThisSelection;
108  //save result as decoration
109  currentSystematic.auxdecor<int>(currentSelection.name()) = passedThisSelection ? 1 : 0;
110 
111  //Did any of the selections with SAVE specified pass for this event (if so we might want to keep the event)
112  save |= (passedThisSelection && currentSelection.ToBeSaved());
113  }
114 
115  return save;
116  }
117 
119  bool save(false);
120 
121  for (const auto& currentSelection : m_selections) {
122  const bool passedThisSelection = currentSelection.applyParticleLevel(plEvent);
123 
124  //save result as new branch (int)
125  plEvent.m_selectionDecisions[ currentSelection.name() ] = passedThisSelection;
126 
127  //Did any of the selections with SAVE specified pass for this event (if so we might want to keep the event)
128  save |= (passedThisSelection && currentSelection.ToBeSaved());
129  }
130 
131  return save;
132  }
133 
135  ATH_MSG_INFO("Final yields:");
136  for (const auto& currentSelection : m_selections)
137  currentSelection.finalise();
138  }
139 
140  void EventSelectionManager::addExtraBranches(std::vector<std::string>& extraBranchList) {
141  for (const auto& currentSelection : m_selections)
142  extraBranchList.push_back(currentSelection.name());
143  }
144 
145  std::vector<std::string> EventSelectionManager::GetFakesMMConfigs(const std::string& selection) const {
146  for (const auto& currentSelection : m_selections)
147  if (currentSelection.name() == selection) return currentSelection.GetFakesMMConfigs();
148 
149  ATH_MSG_WARNING("Attempt to retrieve the FakesMMConfigs for non-existing selection " << selection
150  << "\n This is nonense - returning empty list");
151  std::vector<std::string> empty;
152  return empty;
153  }
154 }
top::EventSelectionManager::addExtraBranches
virtual void addExtraBranches(std::vector< std::string > &extraBranchList)
To get the mini xAOD really small we need to tell it which branches to save.
Definition: EventSelectionManager.cxx:140
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
top::EventSelectionManager::apply
virtual bool apply(top::Event &event, const xAOD::SystematicEvent &currentSystematic)
Run through the event selections for each event.
Definition: EventSelectionManager.cxx:100
top::EventSelectionManager
Maybe you want to run multiple selections (e+jets, mu+jets) on the same input files at the same time.
Definition: EventSelectionManager.h:40
top::ParticleLevelEvent::m_selectionDecisions
std::unordered_map< std::string, int > m_selectionDecisions
Definition: ParticleLevelEvent.h:76
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
SystematicEvent.h
SG::AuxElement::auxdecor
Decorator< T, ALLOC >::reference_type auxdecor(const std::string &name) const
Fetch an aux decoration, as a non-const reference.
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,...
top::EventSelectionManager::applyParticleLevel
virtual bool applyParticleLevel(const top::ParticleLevelEvent &plEvent)
Execute the event selection using the Particle Level data.
Definition: EventSelectionManager.cxx:118
top::EventSelectionManager::countPrimaryVertex
virtual void countPrimaryVertex(const float mcEventWeight, const float pileupWeight)
Count the number of events passing Primary Vertex.
Definition: EventSelectionManager.cxx:95
compareGeometries.outputFile
string outputFile
Definition: compareGeometries.py:25
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
JetTagCalibConfig.className
string className
Definition: JetTagCalibConfig.py:31
EventSelectionManager.h
checkTP.save
def save(self, fileName="./columbo.out")
Definition: checkTP.py:178
MsgCategory.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::Worker
Definition: Worker.h:25
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
top::EventSelectionManager::countGoodCalo
virtual void countGoodCalo(const float mcEventWeight, const float pileupWeight)
Count the number of events passing Good Calo.
Definition: EventSelectionManager.cxx:90
top::ParticleLevelEvent
Definition: ParticleLevelEvent.h:24
top::EventSelectionManager::finalise
virtual void finalise()
Call finalise on each tool.
Definition: EventSelectionManager.cxx:134
Event.h
selection
std::string selection
Definition: fbtTestBasics.cxx:73
top::EventSelectionManager::countGRL
virtual void countGRL(const float mcEventWeight, const float pileupWeight)
Count the number of events passing GRL.
Definition: EventSelectionManager.cxx:85
item
Definition: ItemListSvc.h:43
TopConfig.h
top::EventSelectionManager::GetFakesMMConfigs
std::vector< std::string > GetFakesMMConfigs(const std::string &selection) const
Gives you the lists of the Fakes MM configurations associated to a selection.
Definition: EventSelectionManager.cxx:145
top::ToolLoaderBase
This allows user libraries (and TopEventSelectionTools and TopEventReconstructionTools) to supply eve...
Definition: ToolLoaderBase.h:33
top::EventSelectionManager::m_selections
std::vector< top::EventSelection > m_selections
A vector of EventSelection objects, for doing fancy things.
Definition: EventSelectionManager.h:147
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
xAOD::SystematicEvent
SystematicEvent A simple xAOD class which we can persist into a mini-xAOD The xAOD EDM is way too com...
Definition: SystematicEvent.h:27
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
top::EventSelectionManager::countInitial
virtual void countInitial(const float mcEventWeight, const float pileupWeight)
Count the number of initial events.
Definition: EventSelectionManager.cxx:80
top::Event
Very simple class to hold event data after reading from a file.
Definition: Event.h:49
ToolLoaderBase.h
ParticleLevelEvent.h
python.compressB64.c
def c
Definition: compressB64.py:93