ATLAS Offline Software
GepTowersAlg.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 /*
6  This algorithm creates clusters from CaloCells, and writes them out
7  as Caloclusters. The clustering strategy is carried out by helper objects.
8  The strategy used is chosen accoeding to string set at configure time. *
9 */
10 
11 #include "./GepTowersAlg.h"
12 
13 // concrete cluster maker classes:
14 #include "./TCTowerMaker.h"
15 #include "./TopoTowerMaker.h"
16 
17 #include "./Cluster.h"
18 #include "GaudiKernel/EventContext.h"
19 
22 
23 GepTowersAlg::GepTowersAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
24 AthReentrantAlgorithm( name, pSvcLocator ){
25  }
26 
27 
29  ATH_MSG_INFO ("Initializing " << name() << "...");
30  ATH_MSG_INFO ("Tower alg " << m_towerAlg);
31 
32  // Initialize read and write handles
38 
39  return StatusCode::SUCCESS;
40 }
41 
42 
43 StatusCode GepTowersAlg::execute(const EventContext& context) const {
44  // Feed the specified cell map to a cluster creation algorithm and writes
45  // them out
46 
47  ATH_MSG_DEBUG ("Executing " << name() << "...");
48 
49  auto h_eventInfo = SG::makeHandle(m_eventInfoKey, context);
50  CHECK(h_eventInfo.isValid());
51  ATH_MSG_DEBUG("eventNumber=" << h_eventInfo->eventNumber() );
52 
53  // read in clusters
54  auto h_caloClusters = SG::makeHandle(m_caloClustersKey, context);
55  CHECK(h_caloClusters.isValid());
56  ATH_MSG_DEBUG("Read in " << h_caloClusters->size() << " clusters");
57 
58  auto h_caloCells = SG::makeHandle(m_caloCellsKey, context);
59  CHECK(h_caloCells.isValid());
60 
61  // container for CaloCluster wrappers for Gep Clusters
62  SG::WriteHandle<xAOD::CaloClusterContainer> h_outputCaloClusters =
64  CHECK(h_outputCaloClusters.record(std::make_unique<xAOD::CaloClusterContainer>(),
65  std::make_unique<xAOD::CaloClusterAuxContainer>()));
66 
67  // Run a cluster algorithm
68  std::unique_ptr<Gep::ITowerMaker> towerMaker{};
69 
70  // Instantiate a cluster creater object
71  if( m_towerAlg == "TCTower" ){
72  towerMaker.reset(new Gep::TCTowerMaker());
73  }
74  else if( m_towerAlg == "TopoTower" ){
75  towerMaker.reset(new Gep::TopoTowerMaker());
76  }
77  if( !towerMaker ){
78  ATH_MSG_ERROR( "Unknown towerMaker" + m_towerAlg );
79  return StatusCode::FAILURE;
80  }
81 
82  ATH_MSG_DEBUG( "Running " << towerMaker->getName() << " tower algorithm." );
83 
84  // pass them to the tower maker
85  const xAOD::CaloClusterContainer& clusters = *h_caloClusters;
86  const CaloCellContainer& cells = *h_caloCells;
87  std::vector<Gep::Cluster> customTowers = towerMaker->makeTowers(clusters,cells);
88 
89  ATH_MSG_DEBUG( "Tower Maker Algorithm completed." );
90  ATH_MSG_DEBUG("No of towers: " << customTowers.size());
91  if (!customTowers.empty()){
92  ATH_MSG_DEBUG("Tower 0 Energy: " << (customTowers[0]).vec.E());
93  }
94 
95  // Store the Gep clusters to a CaloClusters, and write out.
96  h_outputCaloClusters->reserve(customTowers.size());
97 
98  for(const auto& gepclus: customTowers){
99 
100  // make a unique_ptr, but keep hold of the bare pointer
101  auto *ptr = h_outputCaloClusters->push_back(std::make_unique<xAOD::CaloCluster>());
102 
103  // to update the calo cluster.
104  ptr->setE(gepclus.vec.E());
105  ptr->setEta(gepclus.vec.Eta());
106  ptr->setPhi(gepclus.vec.Phi());
107  ptr->setTime(gepclus.time);
108  }
109 
110  return StatusCode::SUCCESS;
111 }
112 
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:281
TCTowerMaker.h
GepTowersAlg::m_caloClustersKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_caloClustersKey
Definition: GepTowersAlg.h:36
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
GepTowersAlg::m_outputCaloClustersKey
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outputCaloClustersKey
Definition: GepTowersAlg.h:39
GepTowersAlg::GepTowersAlg
GepTowersAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: GepTowersAlg.cxx:23
GepTowersAlg::m_caloCellsKey
SG::ReadHandleKey< CaloCellContainer > m_caloCellsKey
Definition: GepTowersAlg.h:33
Gep::TCTowerMaker
Definition: TCTowerMaker.h:18
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:9
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
CaloClusterAuxContainer.h
GepTowersAlg::initialize
virtual StatusCode initialize() override
Definition: GepTowersAlg.cxx:28
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
GepTowersAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition: GepTowersAlg.cxx:43
Gep::TopoTowerMaker
Definition: TopoTowerMaker.h:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
GepTowersAlg::m_towerAlg
Gaudi::Property< std::string > m_towerAlg
Definition: GepTowersAlg.h:27
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
GepTowersAlg::m_gepCellsKey
SG::ReadHandleKey< Gep::GepCellMap > m_gepCellsKey
Definition: GepTowersAlg.h:43
Cluster.h
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:794
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
GepTowersAlg::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: GepTowersAlg.h:30
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
GepTowersAlg.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
TopoTowerMaker.h
RunTileMonitoring.clusters
clusters
Definition: RunTileMonitoring.py:133