ATLAS Offline Software
Loading...
Searching...
No Matches
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
23GepTowersAlg::GepTowersAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
24AthReentrantAlgorithm( 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
33 CHECK(m_eventInfoKey.initialize());
34 CHECK(m_caloCellsKey.initialize());
35 CHECK(m_caloClustersKey.initialize());
36 CHECK(m_outputCaloClustersKey.initialize());
37 CHECK(m_gepCellsKey.initialize());
38
39 return StatusCode::SUCCESS;
40}
41
42
43StatusCode 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
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
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Definition of CaloDetDescrManager.
std::vector< size_t > vec
#define CHECK(...)
Evaluate an expression and check for errors.
An algorithm that can be simultaneously executed in multiple threads.
Container class for CaloCell.
SG::ReadHandleKey< Gep::GepCellMap > m_gepCellsKey
virtual StatusCode initialize() override
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_caloClustersKey
GepTowersAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute(const EventContext &) const override
Gaudi::Property< std::string > m_towerAlg
SG::ReadHandleKey< CaloCellContainer > m_caloCellsKey
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outputCaloClustersKey
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.