ATLAS Offline Software
METRegionsTool.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 // 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 
27 namespace met {
28 
29  using std::vector;
30  //
31  using xAOD::IParticle;
32  //
33  using xAOD::MissingET;
38 
40  // Public methods:
42 
43  // Constructors
45  METRegionsTool::METRegionsTool(const std::string& name) :
46  AsgTool(name),
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 }
xAOD::MissingETComponentMap_v1
Definition: MissingETComponentMap_v1.h:25
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
met::METRegionsTool::m_region_eta_values
std::vector< std::pair< float, float > > m_region_eta_values
Definition: METRegionsTool.h:57
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
met::METRegionsTool::m_region_values
std::vector< float > m_region_values
Definition: METRegionsTool.h:55
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
met::METRegionsTool::METRegionsTool
METRegionsTool()
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAOD::MissingETComposition::find
static MissingETComponentMap::const_iterator find(const MissingETComponentMap *pMap, const MissingET *pmetObj)
Find non-modifiable contribution for a given MET object.
Definition: Event/xAOD/xAODMissingET/Root/MissingETComposition.cxx:82
met::METRegionsTool::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: METRegionsTool.cxx:62
MissingETAuxComponentMap.h
xAOD::MissingETComponent_v1::Weight::wet
double wet() const
Returns .
skel.it
it
Definition: skel.GENtoEVGEN.py:396
xAOD::MissingET
MissingET_v1 MissingET
Version control by type defintion.
Definition: Event/xAOD/xAODMissingET/xAODMissingET/MissingET.h:15
met::METRegionsTool::m_base_met_mapKey
std::string m_base_met_mapKey
Definition: METRegionsTool.h:52
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
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
met::METRegionsTool::m_base_met_inputKey
std::string m_base_met_inputKey
Definition: METRegionsTool.h:53
met::METRegionsTool::finalize
StatusCode finalize()
Definition: METRegionsTool.cxx:115
xAOD::MissingET_v1::setName
void setName(const std::string &name)
Set the name of the MET object.
xAOD::MissingETComposition::insert
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.
Definition: Event/xAOD/xAODMissingET/Root/MissingETComposition.cxx:42
xAOD::MissingETContainer_v1::find
const_iterator find(const std::string &name) const
Find non-modifiable MET object by name.
Definition: MissingETContainer_v1.cxx:52
met
Definition: IMETSignificance.h:24
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
xAOD::MissingET_v1
Principal data object for Missing ET.
Definition: MissingET_v1.h:25
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
METRegionsTool.h
met::METRegionsTool::m_base_met_containerKey
std::string m_base_met_containerKey
Definition: METRegionsTool.h:51
xAOD::MissingETComponent_v1::Weight::wpy
double wpy() const
Returns .
xAOD::MissingET_v1::name
const std::string & name() const
Identifier getters.
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
MissingET
Athena::TPCnvVers::Old Athena::TPCnvVers::Old MissingET
Definition: RecTPCnv.cxx:64
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
met::METRegionsTool::m_region_names
std::vector< std::string > m_region_names
Definition: METRegionsTool.h:56
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
met::METRegionsTool::~METRegionsTool
~METRegionsTool()
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
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
met::METRegionsTool::executeTool
StatusCode executeTool(xAOD::MissingET *metTerm, xAOD::MissingETComponentMap *metMap) const
Definition: METRegionsTool.cxx:126
xAOD::MissingETComponent_v1::Weight::wpx
double wpx() const
Returns .
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
DeMoScan.index
string index
Definition: DeMoScan.py:364
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
xAOD::MissingETComponent_v1::Weight
Kinematic weight descriptor.
Definition: MissingETComponent_v1.h:28
SG::AuxElement::container
const SG::AuxVectorData * container() const
Return the container holding this element.
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
met::METRefinerTool
Definition: METRefinerTool.h:39
xAOD::MissingETComponent
MissingETComponent_v1 MissingETComponent
Version control by type definition.
Definition: MissingETComponent.h:15
MissingETComposition.h
MissingETContainer.h
met::METRefinerTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: METRefinerTool.cxx:52