ATLAS Offline Software
TauObjectCollectionMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 // $Id: TauObjectCollectionMaker.cxx $
9 #include "TopEvent/EventTools.h"
10 
13 #include "xAODCore/ShallowCopy.h"
16 
17 namespace top {
19  asg::AsgTool(name),
20  m_config(nullptr),
21 
22  m_specifiedSystematics(),
23  m_recommendedSystematics(),
24 
25  m_calibrationTool("TauSmearingTool"),
26  m_truthMatchingTool("TauAnalysisTools::TauTruthMatchingTool") {
27  declareProperty("config", m_config);
28 
29  declareProperty("TauSmearingTool", m_calibrationTool);
30  }
31 
33  ATH_MSG_INFO(" top::TauObjectCollectionMaker initialize");
34 
35  top::check(m_calibrationTool.retrieve(), "Failed to retrieve tau calibration tool");
36  if (m_config->isMC())
37  top::check(m_truthMatchingTool.retrieve(), "Failed to retrieve tau truth matching tool");
38 
40  const std:: string& syststr = m_config->systematics();
41  std::set<std::string> syst;
42 
43  if (!m_config->isSystNominal(syststr) && !m_config->isSystAll(syststr)) {
44  bool ok = m_config->getSystematicsList(syststr, syst);
45  if (!ok) {
46  ATH_MSG_ERROR(" top::TauObjectCollectionMaker could not determine systematic list");
47  return StatusCode::FAILURE;
48  }
49  //here the idea is that if the user specifies AllXXX, we leave syst as an empty string, so that all recommended CP
50  // systematics are then used
51  if (m_config->contains(syst, "AllTaus")) {
52  syst.clear();
53  }
54  }
55 
57 
58  m_config->systematicsTaus(specifiedSystematics());
59 
60  return StatusCode::SUCCESS;
61  }
62 
65  const xAOD::TauJetContainer* xaod(nullptr);
66 
67  top::check(evtStore()->retrieve(xaod, m_config->sgKeyTaus()), "Failed to retrieve Taus");
68 
70  for (auto systematic : m_specifiedSystematics) {
72  if (executeNominal && !m_config->isSystNominal(m_config->systematicName(systematic.hash()))) continue;
73  if (!executeNominal && m_config->isSystNominal(m_config->systematicName(systematic.hash()))) continue;
74 
76  top::check(m_calibrationTool->applySystematicVariation(systematic), "Failed to applySystematicVariation");
77 
79  std::pair< xAOD::TauJetContainer*, xAOD::ShallowAuxContainer* > shallow_xaod_copy = xAOD::shallowCopyContainer(
80  *xaod);
81 
83  for (auto tau : *(shallow_xaod_copy.first)) {
85  if (m_config->isMC())
86  m_truthMatchingTool->getTruth(*tau);
87 
89  top::check(m_calibrationTool->applyCorrection(*tau), "Failed to applyCorrection");
90  }
91 
92 
94  bool setLinks = xAOD::setOriginalObjectLink(*xaod, *shallow_xaod_copy.first);
95  if (!setLinks) ATH_MSG_ERROR(" Cannot set original object links for taus, MET recalculation may struggle");
96 
97  // Save corrected xAOD Container to StoreGate / TStore
98  std::string outputSGKey = m_config->sgKeyTaus(systematic.hash());
99  std::string outputSGKeyAux = outputSGKey + "Aux.";
100 
101  StatusCode save = evtStore()->tds()->record(shallow_xaod_copy.first, outputSGKey);
102  StatusCode saveAux = evtStore()->tds()->record(shallow_xaod_copy.second, outputSGKeyAux);
103  if (!save || !saveAux) {
104  return StatusCode::FAILURE;
105  }
106  } // Loop over all systematics
107 
108  return StatusCode::SUCCESS;
109  }
110 
113  for (auto s : m_specifiedSystematics) {
114  const xAOD::TauJetContainer* xaod(nullptr);
115  top::check(evtStore()->retrieve(xaod, m_config->sgKeyTaus(s.hash())), "Failed to retrieve Taus");
116 
117  ATH_MSG_INFO(" Taus with sgKey = " << m_config->sgKeyTaus(s.hash()));
118  for (auto x : *xaod) {
119  ATH_MSG_INFO(" TAU pT , eta = " << x->pt() << " , " << x->eta());
120  }
121  }
122 
123  return StatusCode::SUCCESS;
124  }
125 
126  void TauObjectCollectionMaker::specifiedSystematics(const std::set<std::string>& specifiedSystematics) {
128  const std::vector<CP::SystematicSet> systList = CP::make_systematics_vector(
129  m_calibrationTool->recommendedSystematics());
130 
131  for (auto s : systList) {
132 
133  if(!m_config->getTreeFilter()->filterTree(s.name())) continue; // Applying tree filter
134  m_recommendedSystematics.push_back(s);
135  if (s.name() == "") {
136  m_specifiedSystematics.push_back(s);
137  }
138 
140  if (m_config->isMC()) {
142  if (!m_config->isSystNominal(m_config->systematics())) {
143  if (specifiedSystematics.size() == 0) {
144  m_specifiedSystematics.push_back(s);
145  }
146  if (specifiedSystematics.size() > 0) {
147  for (auto i : specifiedSystematics) {
149  if (!filter.filterTree(s.name())) {
150  m_specifiedSystematics.push_back(s);
151  }
152  }
153  }
154  }
155  }
156  }
158  m_recommendedSystematics.unique();
159  m_specifiedSystematics.sort();
160  m_specifiedSystematics.unique();
161  }
162 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ShallowCopy.h
top::TauObjectCollectionMaker::TauObjectCollectionMaker
TauObjectCollectionMaker(const std::string &name)
Definition: TauObjectCollectionMaker.cxx:18
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CP::make_systematics_vector
std::vector< CP::SystematicSet > make_systematics_vector(const SystematicSet &systematics)
utility functions for working with systematics
Definition: SystematicsUtil.cxx:25
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TauObjectCollectionMaker.h
TreeFilter.h
asg
Definition: DataHandleTestTool.h:28
top::TauObjectCollectionMaker::specifiedSystematics
virtual const std::list< CP::SystematicSet > & specifiedSystematics() const
Definition: TauObjectCollectionMaker.h:56
top::TauObjectCollectionMaker::m_calibrationTool
ToolHandle< TauAnalysisTools::ITauSmearingTool > m_calibrationTool
Definition: TauObjectCollectionMaker.h:69
x
#define x
TauJetAuxContainer.h
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
covarianceTool.filter
filter
Definition: covarianceTool.py:514
top::TreeFilter
Definition: TreeFilter.h:13
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
checkTP.save
def save(self, fileName="./columbo.out")
Definition: checkTP.py:178
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
top::TauObjectCollectionMaker::printout
StatusCode printout()
Definition: TauObjectCollectionMaker.cxx:111
top::TauObjectCollectionMaker::execute
StatusCode execute(bool)
Definition: TauObjectCollectionMaker.cxx:63
top::TauObjectCollectionMaker::m_recommendedSystematics
std::list< CP::SystematicSet > m_recommendedSystematics
Definition: TauObjectCollectionMaker.h:67
TauJetContainer.h
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::TauObjectCollectionMaker::m_truthMatchingTool
ToolHandle< TauAnalysisTools::ITauTruthMatchingTool > m_truthMatchingTool
Definition: TauObjectCollectionMaker.h:70
xAOD::setOriginalObjectLink
bool setOriginalObjectLink(const IParticle &original, IParticle &copy)
This function should be used by CP tools when they make a deep copy of an object in their correctedCo...
Definition: IParticleHelpers.cxx:30
top::TauObjectCollectionMaker::m_config
std::shared_ptr< top::TopConfig > m_config
Definition: TauObjectCollectionMaker.h:64
IParticleHelpers.h
top::TauObjectCollectionMaker::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: TauObjectCollectionMaker.cxx:32
top::TauObjectCollectionMaker::m_specifiedSystematics
std::list< CP::SystematicSet > m_specifiedSystematics
Definition: TauObjectCollectionMaker.h:66
SystematicsUtil.h