ATLAS Offline Software
xAODCaloClusterRetriever.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 "CaloGeoHelpers/CaloSampling.h"
8 
9 #include "AthenaKernel/Units.h"
10 using Athena::Units::GeV;
11 
12 namespace JiveXML {
13 
20  xAODCaloClusterRetriever::xAODCaloClusterRetriever(const std::string& type,const std::string& name,const IInterface* parent):
22  m_typeName("Cluster"),
23  m_sgKeyFavourite("egammaClusters") // new SGKey in rel.20
24  {
25 
26  //Only declare the interface
27  declareInterface<IDataRetriever>(this);
28 
29  declareProperty("FavouriteClusterCollection" ,m_sgKeyFavourite,
30  "Collection to be first in output, shown in Atlantis without switching");
31  declareProperty("OtherClusterCollections" ,m_otherKeys,
32  "Other collections to be retrieved. If list left empty, all available retrieved");
33  declareProperty("DoWriteHLT", m_doWriteHLT = false,"Ignore HLTAutokey object by default."); // ignore HLTAutoKey objects
34  }
35 
41  StatusCode xAODCaloClusterRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
42 
43  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "in retrieveAll()" << endmsg;
44 
46  const xAOD::CaloClusterContainer* ccc;
47 
48  //obtain the default collection first
49  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve " << dataTypeName() << " (" << m_sgKeyFavourite << ")" << endmsg;
50  StatusCode sc = evtStore()->retrieve(ccc, m_sgKeyFavourite);
51  if (sc.isFailure() ) {
52  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << m_sgKeyFavourite << " not found in SG " << endmsg;
53  }else{
54  DataMap data = getData(ccc);
55  if ( FormatTool->AddToEvent(dataTypeName(), m_sgKeyFavourite+"_xAOD", &data).isFailure()){
56  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << m_sgKeyFavourite << " not found in SG " << endmsg;
57  }else{
58  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << m_sgKeyFavourite << ") AODCaloCluster retrieved" << endmsg;
59  }
60  }
61 
62  if ( m_otherKeys.empty() ) {
63  //obtain all other collections from StoreGate
64  if (( evtStore()->retrieve(iterator, end)).isFailure()){
65  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) <<
66  "Unable to retrieve iterator for AODCaloCluster collection" << endmsg;
67 // return false;
68  }
69 
70  for (; iterator!=end; ++iterator) {
71  if ((iterator.key().find("HLT",0) != std::string::npos) && (!m_doWriteHLT)){
72  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Ignoring HLT collection: " << iterator.key() << endmsg;
73  continue; }
74  if (iterator.key()!=m_sgKeyFavourite) {
75  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve all. Current collection: " << dataTypeName() << " (" << iterator.key() << ")" << endmsg;
77  if ( FormatTool->AddToEvent(dataTypeName(), iterator.key()+"_xAOD", &data).isFailure()){
78  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << iterator.key() << " not found in SG " << endmsg;
79  }else{
80  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << iterator.key() << ") AODCaloCluster retrieved" << endmsg;
81  }
82  }
83  }
84  }else {
85  //obtain all collections with the given keys
86  std::vector<std::string>::const_iterator keyIter;
87  for ( keyIter=m_otherKeys.begin(); keyIter!=m_otherKeys.end(); ++keyIter ){
88  StatusCode sc = evtStore()->retrieve( ccc, (*keyIter) );
89  if (!sc.isFailure()) {
90  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Trying to retrieve selected " << dataTypeName() << " (" << (*keyIter) << ")" << endmsg;
91  DataMap data = getData(ccc);
92  if ( FormatTool->AddToEvent(dataTypeName(), (*keyIter), &data).isFailure()){
93  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Collection " << (*keyIter) << " not found in SG " << endmsg;
94  }else{
95  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << " (" << (*keyIter) << ") retrieved" << endmsg;
96  }
97  }
98  }
99  }
100  //All collections retrieved okay
101  return StatusCode::SUCCESS;
102  }
103 
104 
112 
113  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "retrieve()" << endmsg;
114 
116 
117  DataVect phi; phi.reserve(ccc->size());
118  DataVect eta; eta.reserve(ccc->size());
119  DataVect et; et.reserve(ccc->size());
120  DataVect cells; cells.reserve(ccc->size());
121  DataVect numCells; numCells.reserve(ccc->size());
122  DataVect idVec; idVec.reserve(ccc->size());
123  DataVect emfracVec; emfracVec.reserve(ccc->size());
124  DataVect labelVec; labelVec.reserve(ccc->size());
125 
126  std::string label="";
127  int id = 0;
128  int s = 0;
129  float eInSample = 0.;
130  float eInSampleFull = 0.;
131  float emfrac = 0.;
132  float rawemfrac = 0.;
133 
134 // cells n/a in AOD, but keep this for compatibility
135 // with 'full' clusters in AtlantisJava
136  std::string tagCells;
137  tagCells = "cells multiple=\"1.0\"";
138 
140  for (; itr != ccc->end(); ++itr) {
141 
142 // sum over samplings to get EMfraction:
144 // full sum:
145  for (s=0;s<CaloSampling::Unknown; s++){
146  eInSampleFull += (*itr)->eSample(CaloSampling::CaloSample(s));
147  }
148 // Now only EMB1-3, EME1-3 and FCAL1:
149  eInSample += (*itr)->eSample(CaloSampling::EMB1);
150  eInSample += (*itr)->eSample(CaloSampling::EMB2);
151  eInSample += (*itr)->eSample(CaloSampling::EMB3);
152  eInSample += (*itr)->eSample(CaloSampling::EME1);
153  eInSample += (*itr)->eSample(CaloSampling::EME2);
154  eInSample += (*itr)->eSample(CaloSampling::EME3);
155  eInSample += (*itr)->eSample(CaloSampling::FCAL1);
156 
157  emfrac = eInSample/eInSampleFull;
158  rawemfrac = emfrac;
159 // sanity cut: emfrac should be within [0,1]
160  if ( emfrac > 1.0 ) emfrac = 1.;
161  if ( emfrac < 0.0 ) emfrac = 0.;
162  emfracVec.push_back( DataType(emfrac).toString() );
163 
164  if ( DataType( eInSample ).toString() != "0." ){
165  label = "AllMeV_SumEMSampl=" + DataType( eInSample ).toString() +
166  "_SumAllSampl=" + DataType( eInSampleFull ).toString() +
167  "_calcEMFrac=" + DataType( rawemfrac ).toString()+
168  "_outEMFrac=" + DataType( emfrac ).toString();
169  }else{ label = "n_a"; }
170  eInSample = 0.;
171  eInSampleFull = 0.;
172 
173  labelVec.push_back( label );
174  if (msgLvl(MSG::VERBOSE)) {
175  msg(MSG::VERBOSE) << "label is " << label << endmsg;
176  }
177 
178 // now the standard variables
179 // getBasicEnergy n/a in xAOD !
180 
181  phi.push_back(DataType((*itr)->phi()));
182  eta.push_back(DataType((*itr)->eta()));
183  et.push_back(DataType((*itr)->et()/GeV));
184  numCells.push_back(DataType( "0" ));
185  cells.push_back(DataType( "0" ));
186  idVec.push_back(DataType( ++id ));
187 
188  if (msgLvl(MSG::VERBOSE)) {
189  msg(MSG::VERBOSE) << dataTypeName() << " cluster #" << id
190  << " ,e=" << (*itr)->e()/GeV << ", et=";
191  msg(MSG::VERBOSE) << (*itr)->et()/GeV << ", eta=" << (*itr)->eta()
192  << ", phi=" << (*itr)->phi() << endmsg;
193  }
194 
195  }
196  // Start with mandatory entries
197  DataMap["phi"] = phi;
198  DataMap["eta"] = eta;
199  DataMap["et"] = et;
200  DataMap[tagCells] = cells;
201  DataMap["numCells"] = numCells;
202  DataMap["id"] = idVec;
203  DataMap["emfrac"] = emfracVec; // not in Atlantis yet ! Could be used in legoplot
204  DataMap["label"] = labelVec; // not in Atlantis yet !
205 
206  //Be verbose
207  if (msgLvl(MSG::DEBUG)) {
208  msg(MSG::DEBUG) << dataTypeName() << " (AOD, no cells), collection: " << dataTypeName();
209  msg(MSG::DEBUG) << " retrieved with " << phi.size() << " entries"<< endmsg;
210  }
211 
212  //All collections retrieved okay
213  return DataMap;
214 
215  } // retrieve
216 
217  //--------------------------------------------------------------------------
218 
219 } // JiveXML namespace
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
xAODCaloClusterRetriever.h
JiveXML::xAODCaloClusterRetriever::m_doWriteHLT
bool m_doWriteHLT
Definition: xAODCaloClusterRetriever.h:56
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
JiveXML::xAODCaloClusterRetriever::xAODCaloClusterRetriever
xAODCaloClusterRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: xAODCaloClusterRetriever.cxx:20
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
JiveXML::xAODCaloClusterRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: xAODCaloClusterRetriever.cxx:41
et
Extra patterns decribing particle interation process.
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
xAOD::et
et
Definition: TrigEMCluster_v1.cxx:25
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
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
CaloCell_ID_FCS::FCAL1
@ FCAL1
Definition: FastCaloSim_CaloCell_ID.h:41
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
JiveXML::xAODCaloClusterRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type.
Definition: xAODCaloClusterRetriever.h:48
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::xAODCaloClusterRetriever::getData
const DataMap getData(const xAOD::CaloClusterContainer *)
Retrieve basic parameters, mainly four-vectors.
Definition: xAODCaloClusterRetriever.cxx:111
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
JiveXML::xAODCaloClusterRetriever::m_sgKeyFavourite
std::string m_sgKeyFavourite
Definition: xAODCaloClusterRetriever.h:54
test_pyathena.parent
parent
Definition: test_pyathena.py:15
constants.EME1
int EME1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:55
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:21
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
CaloCell_ID_FCS::EME3
@ EME3
Definition: FastCaloSim_CaloCell_ID.h:26
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.
xAOD::TauJetParameters::numCells
@ numCells
Definition: TauDefs.h:171
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
AthAlgTool
Definition: AthAlgTool.h:26
JiveXML::xAODCaloClusterRetriever::m_otherKeys
std::vector< std::string > m_otherKeys
Definition: xAODCaloClusterRetriever.h:55
CaloCell_ID_FCS::EMB3
@ EMB3
Definition: FastCaloSim_CaloCell_ID.h:22
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
SG::ConstIterator
Definition: SGIterator.h:163
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.