ATLAS Offline Software
Loading...
Searching...
No Matches
METRegionsTool.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5*/
6
7// METRegionsTool.cxx
8// Implementation file for class METRegionsTool
9//
10// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
11//
12// Author: P Loch, S Resconi, TJ Khoo, AS Mete
14
15// STL includes
16#include <vector>
17
18// METReconstruction includes
20
21// MET EDM
26
27namespace met {
28
29 using std::vector;
30 //
31 using xAOD::IParticle;
32 //
33 using xAOD::MissingET;
38
40 // Public methods:
42
43 // Constructors
48 {
49 declareProperty( "InputMETContainer" , m_base_met_containerKey = "" );
50 declareProperty( "InputMETMap" , m_base_met_mapKey = "" );
51 declareProperty( "InputMETKey" , m_base_met_inputKey = "" );
52 declareProperty( "RegionValues" , m_region_values );
53 }
54
55 // Destructor
58 = default;
59
60 // Athena algtool's Hooks
63 {
65 ATH_MSG_VERBOSE ("Initializing " << name() << "...");
66
67 ATH_MSG_INFO("Base MET container: " << m_base_met_containerKey);
68 ATH_MSG_INFO("Base MET key: " << m_base_met_inputKey);
69
70 if( m_base_met_containerKey.empty() || m_base_met_inputKey.empty() ) {
71 ATH_MSG_FATAL("Both InputMETContainer and InputMETKey must be provided.");
72 return StatusCode::FAILURE;
73 }
74
75 if( m_region_values.empty()) {
76 ATH_MSG_WARNING("Setting up default regions");
77 m_region_values.push_back( 1.5);
78 m_region_values.push_back( 3.2);
79 m_region_values.push_back(10.0);
80 } else {
81 std::sort(m_region_values.begin(), m_region_values.end()); // Default should be good enough
82 }
83
84 // Set the names and eta ranges
85 float eta_min = 0., eta_max = 0.;
86 for(unsigned int index=0; index<m_region_values.size(); ++index) {
87 if(index == 0) {
88 eta_min = 0.;
89 eta_max = m_region_values.at(index);
90 } else {
91 eta_min = m_region_values.at(index-1);
92 eta_max = m_region_values.at(index);
93 }
94
95 // A few nice formatting
96 std::string lowerName = std::to_string(eta_min), higherName = std::to_string(eta_max);
97 lowerName.erase(lowerName.find_last_not_of('0') + 1, std::string::npos);
98 higherName.erase(higherName.find_last_not_of('0') + 1, std::string::npos);
99 if(lowerName[lowerName.size()-1] == '.') lowerName.append("0");
100 if(higherName[higherName.size()-1] == '.') higherName.append("0");
101 std::replace(lowerName.begin(),lowerName.end(),'.','p');
102 std::replace(higherName.begin(),higherName.end(),'.','p');
103
104 // Names
105 m_region_names.push_back(lowerName + "_" + higherName);
106
107 // Regions
108 std::pair<float, float> currentPair(eta_min,eta_max);
109 m_region_eta_values.push_back(currentPair);
110 }
111
112 return StatusCode::SUCCESS;
113 }
114
116 {
117 ATH_MSG_INFO ("Finalizing " << name() << "...");
118
119 return StatusCode::SUCCESS;
120 }
121
123 // Protected methods:
125
127 {
128 ATH_MSG_DEBUG ("In execute: " << name() << "...");
129
130 // First retrieve the BaseMET
132 if (!base_met_container.isValid()) {
133 ATH_MSG_WARNING("Could not retrieve base MET container!");
134 return StatusCode::SUCCESS;
135 }
136
137
138 // First retrieve the BaseMET
140 if (!base_met_map.isValid()) {
141 ATH_MSG_WARNING("Could not retrieve base MET map!");
142 return StatusCode::SUCCESS;
143 }
144
145
146 // Add to the Container
147 MissingETContainer* metCont = static_cast<MissingETContainer*>( metTerm_central->container() );
148 if(!metCont) {
149 ATH_MSG_DEBUG("METRegionsTool expecting a MissingETContainer given an inconsistent type.");
150 return StatusCode::SUCCESS;
151 }
152
153 // Get the components of the base MET
154 MissingETContainer::const_iterator iterBaseCont = base_met_container->find( m_base_met_inputKey );
155 MissingETComponentMap::const_iterator iterBaseConstit = MissingETComposition::find( base_met_map.cptr(), (*iterBaseCont) );
156
157 if( iterBaseCont == base_met_container->end() ) {
158 ATH_MSG_WARNING("Could not find base MET object " << m_base_met_inputKey << " in MET container!");
159 return StatusCode::SUCCESS;
160 }
161
162 if( iterBaseConstit == base_met_map->end() ) {
163 ATH_MSG_WARNING("Could not find base METComponent in MET Map!");
164 return StatusCode::SUCCESS;
165 }
166
167 std::map< std::pair<float,float>, xAOD::MissingET* > mapRangeToMET;
168
169 // Create MET term, push to container and maps
170 for(unsigned int index=0; index<m_region_values.size(); ++index) {
171 MissingET* currentMetTerm;
172 if(index == 0) {
173 currentMetTerm = metTerm_central;
174 currentMetTerm->setName( m_base_met_inputKey + "_" + m_region_names.at(index) );
175 } else {
176 currentMetTerm = new MissingET(0.,0.,0.);
177 ATH_MSG_DEBUG("Adding MET Term " << currentMetTerm->name() << " to MET container" );
178 metCont->push_back( currentMetTerm );
179 // Should also set the source
180 currentMetTerm->setName( m_base_met_inputKey + "_" + m_region_names.at(index) );
181 ATH_MSG_DEBUG("Adding MET Term " << currentMetTerm->name() << " to MET map" );
182 MissingETComposition::add( metMap, metCont->back() );
183 }
184 mapRangeToMET.insert(std::pair<std::pair<float,float>,MissingET*>(m_region_eta_values.at(index),metCont->back()));
185 }
186
187 // Fill the MET terms and maps
188 if(!(*iterBaseConstit)->empty()) {
189 vector<const IParticle*> objectList = (*iterBaseConstit)->objects();
190 vector<const IParticle*> dummyList;
191
192 for(const auto *iObj : objectList) {
193 MissingETBase::Types::weight_t objWeight = (*iterBaseConstit)->weight(iObj);
194 for(auto & it : mapRangeToMET) {
195 if( fabs(iObj->eta()) > it.first.first && fabs(iObj->eta()) < it.first.second ) {
196 it.second->add(iObj->pt()*cos(iObj->phi())*objWeight.wpx(),
197 iObj->pt()*sin(iObj->phi())*objWeight.wpy(),
198 iObj->pt()*objWeight.wet());
199 MissingETComposition::insert( metMap, it.second, iObj, dummyList, objWeight );
200 }
201 } // end of loop over met terms
202 } // end of loop over constituents
203 }
204
205 return StatusCode::SUCCESS;
206 }
207
208}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const T * back() const
Access the last element in the collection as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const SG::AuxVectorData * container() const
Return the container holding this element.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
METRefinerTool(const std::string &name)
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
StatusCode initialize()
Dummy implementation of the initialisation function.
std::string m_base_met_mapKey
std::vector< float > m_region_values
std::vector< std::string > m_region_names
StatusCode executeTool(xAOD::MissingET *metTerm, xAOD::MissingETComponentMap *metMap) const
std::string m_base_met_inputKey
std::string m_base_met_containerKey
std::vector< std::pair< float, float > > m_region_eta_values
Class providing the definition of the 4-vector interface.
double wpx() const
Returns .
double wpy() const
Returns .
double wet() const
Returns .
const std::string & name() const
Identifier getters.
void setName(const std::string &name)
Set the name of the MET object.
xAOD::MissingETComponent_v1::Weight weight_t
Type for kinematic weight.
Definition index.py:1
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
MissingETComponent_v1 MissingETComponent
Version control by type definition.
MissingETComponentMap_v1 MissingETComponentMap
Version control by type definition.
MissingET_v1 MissingET
Version control by type defintion.
static MissingETComponentMap::const_iterator find(const MissingETComponentMap *pMap, const MissingET *pmetObj)
Find non-modifiable contribution for a given MET object.
static bool insert(MissingETComponentMap *pMap, const MissingET *pMET, const IParticle *pPart, MissingETBase::Types::weight_t weight=MissingETBase::Types::weight_t())
Insert contributing signal or physics object by pointer, with optional kinematic weight object.
static bool add(MissingETComponentMap *pMap, const MissingET *pMET, MissingETBase::Types::bitmask_t sw=MissingETBase::Status::clearedStatus())
Adding a MissingET object to the map.
Collection of functions managing the MET composition map and association map.