ATLAS Offline Software
METRecoTool.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // METRecoTool.cxx
8 // Implementation file for class METRecoTool
9 //
10 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
11 //
12 // Author: P Loch, S Resconi, TJ Khoo
14 
15 // METReconstruction includes
17 
18 // MET EDM
25 
26 #include <iomanip>
27 
28 namespace met {
29 
30  using xAOD::MissingET;
36  //
37  using std::string;
38  using std::setw;
39  using std::setprecision;
40  using std::fixed;
41 
43  // Public methods:
45 
46  // Constructors
48  METRecoTool::METRecoTool(const std::string& name) :
49  AsgTool(name),
50  m_doMetSum(false),
51  m_metbuilders(this),
52  m_metrefiners(this),
53  m_nevt(0)
54  {
55  declareProperty( "METBuilders", m_metbuilders );
56  declareProperty( "METRefiners", m_metrefiners );
57  declareProperty( "METContainer", m_contname = "MET" );
58  declareProperty( "METComponentMap", m_mapname = "METMap" );
59  declareProperty( "WarnIfDuplicate", m_warnOfDupes = true );
60  declareProperty( "METFinalName", m_metfinalname = "" );
61  }
62 
63  // Athena algtool's Hooks
66  {
67  ATH_MSG_INFO ("Initializing " << name() << "...");
68 
69  if( m_contname.key().empty() ) {
70  ATH_MSG_FATAL("Output MissingETContainer name must be provided.");
71  return StatusCode::FAILURE;
72  }
73 
74  if( m_mapname.key().empty() ) {
75  ATH_MSG_FATAL("Output MissingETComponentMap name must be provided.");
76  return StatusCode::FAILURE;
77  }
78  ATH_CHECK( m_contname.initialize() );
79  ATH_CHECK( m_mapname.initialize() );
80 
81 
82  ATH_MSG_INFO ("Reconstructing MET container: " << m_contname
83  << " with composition map: " << m_mapname );
84 
85  // Do we need a flag to toggle the summation?
86  // Or will we require the summation to be made
87  if( !m_metfinalname.empty() ) {
88  m_doMetSum = true;
89  ATH_MSG_INFO ("Will produce final MET sum \"" << m_metfinalname << "\"");
90  } else {
91  ATH_MSG_INFO ("Will not sum MET in this container.");
92  }
93 
94  ATH_CHECK( m_metbuilders.retrieve() );
95  ATH_CHECK( m_metrefiners.retrieve() );
96  return StatusCode::SUCCESS;
97  }
98 
100  {
101  ATH_MSG_DEBUG ("In execute: " << name() << "...");
102 
103  // Create a MissingETContainer with its aux store
104  auto metHandle= SG::makeHandle (m_contname);
105  //note that the method below automatically creates the MET container and its corresponding aux store (which will be named "m_contname+Aux.")
106  ATH_CHECK( metHandle.record (std::make_unique<xAOD::MissingETContainer>(), std::make_unique<xAOD::MissingETAuxContainer>()) );
107  xAOD::MissingETContainer* metCont=metHandle.ptr();
108 
109 
110  // Create a MissingETComponentMap with its aux store
111 
112  auto metMapHandle= SG::makeHandle (m_mapname);
113  //note that the method below automatically creates the MET container and its corresponding aux store (which will be named "m_contname+Aux.")
114  ATH_CHECK( metMapHandle.record (std::make_unique<xAOD::MissingETComponentMap>(), std::make_unique<xAOD::MissingETAuxComponentMap>()) );
115  xAOD::MissingETComponentMap* metMap=metMapHandle.ptr();
116 
117 
118  if( buildMET(metCont, metMap).isFailure() ) {
119  ATH_MSG_WARNING("Failed in MissingET reconstruction");
120  return StatusCode::SUCCESS;
121  }
122 
123  return StatusCode::SUCCESS;
124  }
125 
127  {
128  ATH_MSG_INFO ("Finalizing " << name() << "...");
129  return StatusCode::SUCCESS;
130  }
131 
132 
134  // Protected methods:
136 
138  {
139 
140 
141  MissingET* metFinal = nullptr;
142  if( m_doMetSum ) {
143  ATH_MSG_DEBUG("Building final MET sum: " << m_metfinalname);
144  metFinal = new MissingET(0.,0.,0., m_metfinalname, MissingETBase::Source::total());
145  }
146 
147  // Run the MET reconstruction tools in sequence
148  for(auto tool : m_metbuilders) {
149  ATH_MSG_VERBOSE("Building new MET term with: " << tool->name() );
150  MissingET* metTerm = new MissingET(0.,0.,0.);
151  ATH_MSG_VERBOSE("Insert MET object into container");
152  metCont->push_back(metTerm);
153  ATH_MSG_VERBOSE("Insert MET object into ComponentMap");
154  MissingETComposition::add(metMap,metTerm);
155  ATH_MSG_VERBOSE("Execute tool");
156  if( tool->execute(metTerm, metMap).isFailure() ) {
157  ATH_MSG_WARNING("Failed to execute tool: " << tool->name());
158  // return StatusCode::SUCCESS;
159  }
161  // FIXME: Make a genuine decision about whether
162  // to include terms in the sum here.
165  ATH_MSG_DEBUG("Adding constructed term: " << metTerm->name() << " to sum" );
166  (*metFinal) += (*metTerm);
167  }
168  }
169 
170  // Run the MET reconstruction tools in sequence
171  for(auto tool : m_metrefiners) {
172  ATH_MSG_VERBOSE("Refining MET with: " << tool->name() );
173  MissingET* metTerm = new MissingET(0.,0.,0.);
174  ATH_MSG_VERBOSE("Insert MET object into container");
175  metCont->push_back(metTerm);
176  ATH_MSG_VERBOSE("Insert MET object into ComponentMap");
177  MissingETComposition::add(metMap,metTerm);
178  ATH_MSG_VERBOSE("Execute tool");
179  if( tool->execute(metTerm, metMap).isFailure() ) {
180  ATH_MSG_WARNING("Failed to execute tool: " << tool->name());
181  // return StatusCode::SUCCESS;
182  }
183  }
184 
185  if( m_doMetSum ) {
187  metFinal->setSource(source);
188  metCont->push_back(metFinal);
189  }
190  ++m_nevt;
191  return StatusCode::SUCCESS;
192  }
193 
194 }
met::METRecoTool::m_warnOfDupes
bool m_warnOfDupes
Definition: METRecoTool.h:94
xAOD::MissingETComponentMap_v1
Definition: MissingETComponentMap_v1.h:25
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
met::METRecoTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: METRecoTool.cxx:65
xAOD::MissingETAuxComponentMap
MissingETAuxComponentMap_v1 MissingETAuxComponentMap
Version control by type definition.
Definition: MissingETAuxComponentMap.h:15
xAOD::MissingETAuxContainer
MissingETAuxContainer_v1 MissingETAuxContainer
Definition: MissingETAuxContainer.h:16
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
MissingETBase::Source::hasCategory
static bool hasCategory(Types::bitmask_t bits, Category cat)
Check if bit pattern includes a given category.
Definition: MissingETBase.h:392
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
met::METRecoTool::buildMET
StatusCode buildMET(xAOD::MissingETContainer *metCont, xAOD::MissingETComponentMap *metMap) const
Definition: METRecoTool.cxx:137
MissingETAuxComponentMap.h
xAOD::MissingET
MissingET_v1 MissingET
Version control by type defintion.
Definition: Event/xAOD/xAODMissingET/xAODMissingET/MissingET.h:15
MissingETComposition
Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Current MissingETComposition
Definition: RecTPCnv.cxx:86
xAOD::MissingETContainer
MissingETContainer_v1 MissingETContainer
Definition: Event/xAOD/xAODMissingET/xAODMissingET/MissingETContainer.h:16
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MissingETBase::Types::bitmask_t
uint64_t bitmask_t
Type for status word bit mask.
Definition: MissingETBase.h:39
met::METRecoTool::m_metbuilders
ToolHandleArray< IMETToolBase > m_metbuilders
Definition: METRecoTool.h:98
xAOD::MissingET_v1::setSource
void setSource(MissingETBase::Types::bitmask_t src)
Set the source of the MET object.
met::METRecoTool::finalize
virtual StatusCode finalize()
Definition: METRecoTool.cxx:126
met::METRecoTool::m_mapname
SG::WriteHandleKey< xAOD::MissingETComponentMap > m_mapname
Definition: METRecoTool.h:96
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:269
met
Definition: IMETSignificance.h:24
met::METRecoTool::m_contname
SG::WriteHandleKey< xAOD::MissingETContainer > m_contname
Definition: METRecoTool.h:95
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MissingETAuxContainer.h
MissingETBase::Source::Category::Refined
@ Refined
Indicator for genuine reconstructed MET terms.
xAOD::MissingET_v1
Principal data object for Missing ET.
Definition: MissingET_v1.h:25
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::MissingET_v1::name
const std::string & name() const
Identifier getters.
MissingET
Athena::TPCnvVers::Old Athena::TPCnvVers::Old MissingET
Definition: RecTPCnv.cxx:64
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
MissingET.h
met::METRecoTool::execute
virtual StatusCode execute() const
Definition: METRecoTool.cxx:99
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::MissingETComposition::add
static bool add(MissingETComponentMap *pMap, const MissingET *pMET, MissingETBase::Types::bitmask_t sw=MissingETBase::Status::clearedStatus())
Adding a MissingET object to the map.
Definition: Event/xAOD/xAODMissingET/Root/MissingETComposition.cxx:29
xAOD::MissingET_v1::source
MissingETBase::Types::bitmask_t source() const
MET object source tag.
met::METRecoTool::m_metfinalname
std::string m_metfinalname
Definition: METRecoTool.h:97
MissingETComponentMap.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::MissingETComponentMap
MissingETComponentMap_v1 MissingETComponentMap
Version control by type definition.
Definition: MissingETComponentMap.h:16
met::METRecoTool::m_doMetSum
bool m_doMetSum
Definition: METRecoTool.h:93
met::METRecoTool::m_nevt
std::atomic< unsigned int > m_nevt
Definition: METRecoTool.h:101
met::METRecoTool::m_metrefiners
ToolHandleArray< IMETToolBase > m_metrefiners
Definition: METRecoTool.h:99
MissingETBase::Source::total
static Types::bitmask_t total(Region reg=Region::FullAcceptance)
Standard full reconstructed MET.
Definition: MissingETBase.h:271
METRecoTool.h
met::METRecoTool::METRecoTool
METRecoTool()
Default constructor:
MissingETComposition.h
MissingETContainer.h