ATLAS Offline Software
ElectronInJetSubtractionCollectionMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 // $Id: ElectronInJetSubtractionCollectionMaker.cxx 806051 2017-06-07 00:32:41Z tpelzer $
8 #include "TopEvent/EventTools.h"
9 
12 #include "xAODCore/ShallowCopy.h"
13 
14 namespace top {
16  asg::AsgTool(name),
17  m_config(nullptr),
18  m_doLooseCuts(false) {
19  declareProperty("config", m_config);
20  }
21 
23  if (!m_config->isMC()) m_doLooseCuts = true;
24 
25  if (m_config->doOverlapRemovalOnLooseLeptonDef()) m_doLooseCuts = true;
26 
27  if (m_config->doLooseEvents()) m_doLooseCuts = true;
28 
29  return StatusCode::SUCCESS;
30  }
31 
33  // Loop over nominal, all electron syst and all jet syst
34  // For each:
35  // Create a shallow electron and a shallow jet collection
36  // Run the subtraction algorithm:
37  // - Modify some jet 4-momentum
38  // - Veto some electrons
39  // Place modified shallow collections into TStore
40 
41  for (auto currentSystematic : *m_config->systHashElectronInJetSubtraction()) {
43  if (executeNominal && !m_config->isSystNominal(m_config->systematicName(currentSystematic))) continue;
44  if (!executeNominal && m_config->isSystNominal(m_config->systematicName(currentSystematic))) continue;
45 
46  // Get the Electrons
47  const xAOD::ElectronContainer* electrons(nullptr);
48  top::check(evtStore()->retrieve(electrons, m_config->sgKeyElectronsStandAlone(
49  currentSystematic)),
50  "ElectronInJetSubtractionCollectionMaker::execute() Failed to retrieve electrons");
51 
52  // Get the Jets
53  const xAOD::JetContainer* jets(nullptr);
54  top::check(evtStore()->retrieve(jets, m_config->sgKeyJetsStandAlone(
55  currentSystematic)),
56  "ElectronInJetSubtractionCollectionMaker::execute() Failed to retrieve jets");
57 
58  // Shallow copy the electrons
59  std::pair< xAOD::ElectronContainer*, xAOD::ShallowAuxContainer* > shallow_electrons = xAOD::shallowCopyContainer(
60  *electrons);
61  // Shallow copy the jets
62  std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > shallow_jets = xAOD::shallowCopyContainer(*jets);
63 
64  // Apply the Electron In Jet Subtraction
65  // The actual calculation is performed in another package
66  m_subtractionAlgorithm.apply(shallow_electrons.first, shallow_jets.first);
67 
68  // Save the modified electrons to TStore
69  std::string outputElectronsSGKey = m_config->sgKeyElectrons(currentSystematic);
70  std::string outputElectronsSGKeyAux = outputElectronsSGKey + "Aux.";
71 
72  StatusCode saveElectrons = evtStore()->tds()->record(shallow_electrons.first, outputElectronsSGKey);
73  StatusCode saveElectronsAux = evtStore()->tds()->record(shallow_electrons.second, outputElectronsSGKeyAux);
74  if (!saveElectrons || !saveElectronsAux) {
75  return StatusCode::FAILURE;
76  }
77 
78  // Save the modified jets to TStore
79  std::string outputJetsSGKey = m_config->sgKeyJets(currentSystematic, false);
80  std::string outputJetsSGKeyAux = outputJetsSGKey + "Aux.";
81 
82  StatusCode saveJets = evtStore()->tds()->record(shallow_jets.first, outputJetsSGKey);
83  StatusCode saveJetsAux = evtStore()->tds()->record(shallow_jets.second, outputJetsSGKeyAux);
84  if (!saveJets || !saveJetsAux) {
85  return StatusCode::FAILURE;
86  }
87 
88 
89  // If we are using loose lepton definitions anywhere, we'd better make more jet colelctions
90  // We subtract loose leptons from these jets
91  // We now have loose jets! fun fun fun, we all love combinatorics
92 
93  if (m_doLooseCuts) {
94  // Shallow copy the jets
95  std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > shallow_jetsLoose = xAOD::shallowCopyContainer(
96  *jets);
97 
98  // Apply the Electron In Jet Subtraction
99  // The actual calculation is performed in another package
100  m_subtractionAlgorithm.apply(shallow_electrons.first, shallow_jetsLoose.first, m_doLooseCuts);
101 
102  // Save the modified jets to TStore
103  std::string outputJetsLooseSGKey = m_config->sgKeyJets(currentSystematic, m_doLooseCuts);
104  std::string outputJetsLooseSGKeyAux = outputJetsLooseSGKey + "Aux.";
105 
106  StatusCode saveJetsLoose = evtStore()->tds()->record(shallow_jetsLoose.first, outputJetsLooseSGKey);
107  StatusCode saveJetsLooseAux =
108  evtStore()->tds()->record(shallow_jetsLoose.second, outputJetsLooseSGKeyAux);
109  if (!saveJetsLoose || !saveJetsLooseAux) {
110  return StatusCode::FAILURE;
111  }
112  }
113  }
114 
115  return StatusCode::SUCCESS;
116  }
117 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ShallowCopy.h
python.EGAM9.saveJets
bool saveJets
Definition: EGAM9.py:35
top::ElectronInJetSubtractionCollectionMaker::m_subtractionAlgorithm
top::ElectronInJetSubtractionAlgorithm m_subtractionAlgorithm
Definition: ElectronInJetSubtractionCollectionMaker.h:62
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
top::ElectronInJetSubtractionCollectionMaker::execute
StatusCode execute(bool)
Definition: ElectronInJetSubtractionCollectionMaker.cxx:32
asg
Definition: DataHandleTestTool.h:28
ElectronInJetSubtractionCollectionMaker.h
top::ElectronInJetSubtractionCollectionMaker::m_doLooseCuts
bool m_doLooseCuts
Definition: ElectronInJetSubtractionCollectionMaker.h:60
top::ElectronInJetSubtractionCollectionMaker::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: ElectronInJetSubtractionCollectionMaker.cxx:22
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ElectronAuxContainer.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TopConfig.h
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
top::ElectronInJetSubtractionCollectionMaker::m_config
std::shared_ptr< top::TopConfig > m_config
Definition: ElectronInJetSubtractionCollectionMaker.h:59
top::ElectronInJetSubtractionAlgorithm::apply
void apply(xAOD::ElectronContainer *electrons, xAOD::JetContainer *jets, const bool useLooseElectrons=false)
Definition: ElectronInJetSubtractionAlgorithm.cxx:18
top::ElectronInJetSubtractionCollectionMaker::ElectronInJetSubtractionCollectionMaker
ElectronInJetSubtractionCollectionMaker(const std::string &name)
Definition: ElectronInJetSubtractionCollectionMaker.cxx:15
JetAuxContainer.h
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17