ATLAS Offline Software
xAODMissingETRetriever.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "AthenaKernel/Units.h"
9 
10 namespace JiveXML {
11 
26  xAODMissingETRetriever::xAODMissingETRetriever(const std::string& type,const std::string& name,const IInterface* parent):
27  AthAlgTool(type,name,parent), m_typeName("ETMis"){
28 
29  //Only declare the interface
30  declareInterface<IDataRetriever>(this);
31 
32  declareProperty("FavouriteMETCollection" ,m_sgKeyFavourite = "MET_RefFinal" ,
33  "Collection to be first in output, shown in Atlantis without switching");
34  declareProperty("OtherMETCollections" ,m_otherKeys,
35  "Other collections to be retrieved. If list left empty, all available retrieved");
36  }
37 
42  StatusCode xAODMissingETRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
43 
44  ATH_MSG_DEBUG( "in retrieveAll()" );
45 
47  const xAOD::MissingETContainer* MissingETs;
48 
49  //obtain the default collection first
50  ATH_MSG_DEBUG( "Trying to retrieve " << dataTypeName() << " (" << m_sgKeyFavourite << ")" );
51  StatusCode sc = evtStore()->retrieve(MissingETs, m_sgKeyFavourite);
52  if (sc.isFailure() ) {
53  ATH_MSG_WARNING( "Collection " << m_sgKeyFavourite << " not found in SG " );
54  }else{
55  DataMap data = getData(MissingETs);
56  if ( FormatTool->AddToEvent(dataTypeName(), m_sgKeyFavourite+"_xAOD", &data).isFailure()){ //suffix can be removed later
57  ATH_MSG_WARNING( "Collection " << m_sgKeyFavourite << " not found in SG " );
58  }else{
59  ATH_MSG_DEBUG( dataTypeName() << " (" << m_sgKeyFavourite << ") MissingET retrieved" );
60  }
61  }
62 
63  if ( m_otherKeys.empty() ) {
64  //obtain all other collections from StoreGate
65  if (( evtStore()->retrieve(iterator, end)).isFailure()){
66  ATH_MSG_WARNING( "Unable to retrieve iterator for MET collection" );
67 // return false;
68  }
69 
70  for (; iterator!=end; ++iterator) {
71  if (iterator.key()!=m_sgKeyFavourite) {
72  ATH_MSG_DEBUG( "Trying to retrieve all " << dataTypeName() << " (" << iterator.key() << ")" );
74  if ( FormatTool->AddToEvent(dataTypeName(), iterator.key()+"_xAOD", &data).isFailure()){
75  ATH_MSG_WARNING( "Collection " << iterator.key() << " not found in SG " );
76  }else{
77  ATH_MSG_DEBUG( dataTypeName() << " (" << iterator.key() << ") xAOD_MET retrieved" );
78  }
79  }
80  }
81  }else {
82  //obtain all collections with the given keys
83  std::vector<std::string>::const_iterator keyIter;
84  for ( keyIter=m_otherKeys.begin(); keyIter!=m_otherKeys.end(); ++keyIter ){
85  if ( !evtStore()->contains<xAOD::MissingETContainer>( (*keyIter) ) ){ continue; } // skip if not in SG
86  StatusCode sc = evtStore()->retrieve( MissingETs, (*keyIter) );
87  if (!sc.isFailure()) {
88  ATH_MSG_DEBUG( "Trying to retrieve selected " << dataTypeName() << " (" << (*keyIter) << ")" );
89  DataMap data = getData(MissingETs);
90  if ( FormatTool->AddToEvent(dataTypeName(), (*keyIter)+"_xAOD", &data).isFailure()){
91  ATH_MSG_WARNING( "Collection " << (*keyIter) << " not found in SG " );
92  }else{
93  ATH_MSG_DEBUG( dataTypeName() << " (" << (*keyIter) << ") retrieved" );
94  }
95  }
96  }
97  }
98  //All collections retrieved okay
99  return StatusCode::SUCCESS;
100  }
101 
102 
108 
109  ATH_MSG_DEBUG( "in getData()" );
110 
112 
113  DataVect etx; etx.reserve(metCont->size());
114  DataVect ety; ety.reserve(metCont->size());
115  DataVect et; et.reserve(metCont->size());
116 
117  float mpx = 0.;
118  float mpy = 0.;
119  float sumet = 0.;
120 
122  xAOD::MissingETContainer::const_iterator metItrE = metCont->end();
123 
124  // current understanding is that we only need the final value
125  // out of the ~9 values within each MET container ('final')
126 
127  for (; metItr != metItrE; ++metItr) {
128  sumet = (*metItr)->sumet()/GeV;
129  mpx = (*metItr)->mpx()/GeV;
130  mpy = (*metItr)->mpy()/GeV;
131 
132  ATH_MSG_DEBUG( " Components: MissingET [GeV] mpx= " << mpx
133  << ", mpy= " << mpy
134  << ", sumet= " << sumet );
135 
136  } // end MissingETIterator
137 
138  ATH_MSG_DEBUG( " FINAL: MissingET [GeV] mpx= " << mpx
139  << ", mpy= " << mpy << ", sumet= " << sumet );
140 
141  etx.push_back(DataType( mpx ));
142  ety.push_back(DataType( mpy ));
143  et.push_back(DataType( sumet ));
144 
145  // four-vectors
146  DataMap["et"] = et;
147  DataMap["etx"] = etx;
148  DataMap["ety"] = ety;
149 
150  ATH_MSG_DEBUG( dataTypeName() << " retrieved with " << et.size() << " entries" );
151 
152  //All collections retrieved okay
153  return DataMap;
154 
155  } // retrieve
156 
157  //--------------------------------------------------------------------------
158 
159 } // JiveXML namespace
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
et
Extra patterns decribing particle interation process.
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
xAOD::et
et
Definition: TrigEMCluster_v1.cxx:25
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAODMissingETRetriever.h
JiveXML::xAODMissingETRetriever::getData
const DataMap getData(const xAOD::MissingETContainer *)
Retrieve basic parameters, mainly four-vectors, for each collection.
Definition: xAODMissingETRetriever.cxx:107
JiveXML::DataVect
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition: DataType.h:58
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
JiveXML::xAODMissingETRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: xAODMissingETRetriever.cxx:42
JiveXML::xAODMissingETRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type.
Definition: xAODMissingETRetriever.h:45
JiveXML::xAODMissingETRetriever::xAODMissingETRetriever
xAODMissingETRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: xAODMissingETRetriever.cxx:26
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
JiveXML::xAODMissingETRetriever::m_sgKeyFavourite
std::string m_sgKeyFavourite
Definition: xAODMissingETRetriever.h:51
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
test_pyathena.parent
parent
Definition: test_pyathena.py:15
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:22
xAOD::MissingETContainer_v1
Container for xAOD::MissingET_v1 objects.
Definition: MissingETContainer_v1.h:21
JiveXML::xAODMissingETRetriever::m_otherKeys
std::vector< std::string > m_otherKeys
Definition: xAODMissingETRetriever.h:52
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Units.h
Wrapper to avoid constant divisions when using units.
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthAlgTool
Definition: AthAlgTool.h:26
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
SG::ConstIterator
Definition: SGIterator.h:163
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.