ATLAS Offline Software
HIEventShapeMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 
10 #include <GaudiKernel/ServiceHandle.h>
11 #include "StoreGate/ReadHandle.h"
12 #include "StoreGate/WriteHandle.h"
13 
14 HIEventShapeMaker::HIEventShapeMaker(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator)
15 {
16 }
17 
18 
20 {
21  ATH_MSG_INFO("Inside HIEventShapeMaker::initialize()");
22 
23  //First we initialize keys - after initialization they are frozen
27  ATH_CHECK(m_outputKey.initialize(!m_summaryOnly));
29  ATH_CHECK(m_summaryKey.initialize(!m_summaryKey.key().empty()));
30 
31  // assure consistent setup of the input
33 
34  //Create the HIEventShapeFillerTool
35  if (!m_summaryOnly)
36  {
38  m_HIEventShapeFillerTool->setContainerName(m_outputKey.key());
39  ATH_CHECK(m_HIEventShapeFillerTool->initializeIndex());
40  }
41  if (m_summaryKey.key().compare("") != 0) ATH_CHECK(m_summaryTool->initialize());
42 
43  return StatusCode::SUCCESS;
44 }
45 
46 StatusCode HIEventShapeMaker::execute(const EventContext& ctx) const
47 {
48  const xAOD::HIEventShapeContainer* evtShape_const = nullptr;
49  if (m_summaryOnly) {
51  if (!readHandleEvtShape.isValid()) {
52  ATH_MSG_FATAL("Could not find HI event shape! (" << m_readExistingKey.key() << ").");
53  return(StatusCode::FAILURE);
54  }
55  evtShape_const = readHandleEvtShape.cptr();
56  }
57  else
58  {
59  auto evtShape=std::make_unique<xAOD::HIEventShapeContainer>();
60  auto evtShapeAux=std::make_unique<xAOD::HIEventShapeAuxContainer>();
61  evtShape->setStore(evtShapeAux.get());
62 
63  ATH_CHECK(m_HIEventShapeFillerTool->initializeEventShapeContainer(evtShape));
64 
65  if (not m_cellContainerKey.empty()) {
66  ATH_CHECK(m_HIEventShapeFillerTool->fillCollectionFromCells(evtShape,m_cellContainerKey, ctx));
67  } else {
68  ATH_CHECK(m_HIEventShapeFillerTool->fillCollectionFromTowers(evtShape,m_towerContainerKey, m_naviContainerKey, ctx));
69  }
70 
72  ATH_CHECK( writeHandleEvtShape.record(std::move(evtShape), std::move(evtShapeAux)) );
73 
74  evtShape_const = writeHandleEvtShape.cptr();
75  }
76 
78 
79  if (!m_summaryKey.empty())
80  {
82  ATH_CHECK(write_handle_esSummary.record(std::make_unique<xAOD::HIEventShapeContainer>(),
83  std::make_unique<xAOD::HIEventShapeAuxContainer>()));
84  if (m_summaryOnly) {
85  ATH_CHECK(m_summaryTool->summarize(evtShape_const, write_handle_esSummary.ptr()));
86  } else {
87  ATH_CHECK(m_summaryTool->summarize(evtShape_const, write_handle_esSummary.ptr()));
88  }
89  }
90  return StatusCode::SUCCESS;
91 }
92 
93 
95 {
96  return StatusCode::SUCCESS;
97 }
98 
99 
101 {
102  std::stringstream buffer;
103  buffer << std::endl << "|############|############|############|############|############|" << std::endl;
104  buffer << "|" << std::setw(10) << "EtaMin" << " |"\
105  << std::setw(10) << "EtaMax" << " |"\
106  << std::setw(10) << "Layer" << " |"\
107  << std::setw(10) << "NCells" << " |"\
108  << std::setw(10) << "Et" << " |"<< std::endl;
109  unsigned int size = Container->size();
110  for (unsigned int i = 0;i < size;i++) {
111  const xAOD::HIEventShape* sh = Container->at(i);
112  int NCells = sh->nCells();
113  int Layer = sh->layer();
114  float Et = sh->et();
115  float EtaMin = sh->etaMin();
116  float EtaMax = sh->etaMax();
117 
118  if (Et == 0) continue;
119  buffer << "|" << std::setw(10) << EtaMin << " |"\
120  << std::setw(10) << EtaMax << " |"\
121  << std::setw(10) << Layer << " |"\
122  << std::setw(10) << NCells << " |"\
123  << std::setw(10) << Et << " |" <<std::endl;
124  }
125  buffer << "|############|############|############|############|############|" << std::endl;
126 
127  return buffer.str();
128 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
HIEventShapeMaker::HIEventShapeMaker
HIEventShapeMaker(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition: HIEventShapeMaker.cxx:14
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
HIEventShapeMaker::m_cellContainerKey
SG::ReadHandleKey< CaloCellContainer > m_cellContainerKey
Definition: HIEventShapeMaker.h:46
HIEventShapeMaker::PrintHIEventShapeContainer
std::string PrintHIEventShapeContainer(const xAOD::HIEventShapeContainer *Container) const
Definition: HIEventShapeMaker.cxx:100
HIEventShapeMaker::m_towerContainerKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_towerContainerKey
Definition: HIEventShapeMaker.h:44
SG::WriteHandle::cptr
const_pointer_type cptr() const
Dereference the pointer.
HIEventShapeMaker.h
HIEventShapeMaker::initialize
virtual StatusCode initialize() override
Definition: HIEventShapeMaker.cxx:19
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
python.RingerConstants.Layer
Layer
Definition: RingerConstants.py:42
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
PixelConvert::EtaMax
const int EtaMax
Definition: PixelConvert.cxx:13
Container
storage of the time histories of all the cells
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
xAOD::HIEventShape_v2
Interface class for the HI reconstruction EDM.
Definition: HIEventShape_v2.h:31
WriteHandle.h
Handle class for recording to StoreGate.
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
HIEventShapeMaker::m_readExistingKey
SG::ReadHandleKey< xAOD::HIEventShapeContainer > m_readExistingKey
Definition: HIEventShapeMaker.h:47
lumiFormat.i
int i
Definition: lumiFormat.py:92
RCU::Shell
Definition: ShellExec.cxx:28
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HIEventShape.h
HIEventShapeContainer.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
HIEventShapeMaker::m_summaryOnly
Gaudi::Property< bool > m_summaryOnly
Definition: HIEventShapeMaker.h:51
HIEventShapeMaker::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: HIEventShapeMaker.cxx:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
HIEventShapeAuxContainer.h
HIEventShapeMaker::m_summaryTool
ToolHandle< IHIEventShapeSummaryTool > m_summaryTool
Definition: HIEventShapeMaker.h:54
ReadHandle.h
Handle class for reading from StoreGate.
TBXMLWriter_jobOptions.EtaMin
EtaMin
Definition: TBXMLWriter_jobOptions.py:30
HIEventShapeMaker::finalize
virtual StatusCode finalize() override
Definition: HIEventShapeMaker.cxx:94
HIEventShapeMaker::m_HIEventShapeFillerTool
ToolHandle< IHIEventShapeFiller > m_HIEventShapeFillerTool
Definition: HIEventShapeMaker.h:53
HIEventShapeMaker::m_naviContainerKey
SG::ReadHandleKey< INavigable4MomentumCollection > m_naviContainerKey
Definition: HIEventShapeMaker.h:45
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
HIEventShapeMaker::m_outputKey
SG::WriteHandleKey< xAOD::HIEventShapeContainer > m_outputKey
Definition: HIEventShapeMaker.h:48
HIEventShapeMaker::m_summaryKey
SG::WriteHandleKey< xAOD::HIEventShapeContainer > m_summaryKey
Definition: HIEventShapeMaker.h:49