ATLAS Offline Software
Loading...
Searching...
No Matches
GepClusteringAlg.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2022 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 "./GepClusteringAlg.h"
12
13// concrete cluster maker classes:
14#include "./WFSClusterMaker.h"
16
19
20GepClusteringAlg::GepClusteringAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
21AthReentrantAlgorithm( name, pSvcLocator ){
22 }
23
24
26 ATH_MSG_INFO ("Initializing " << name() << "...");
27 ATH_MSG_INFO ("Clustering alg " << m_clusterAlg);
28
29 // Initialize read and write handles
30 CHECK(m_eventInfoKey.initialize());
31 CHECK(m_outputCaloClustersKey.initialize());
32 CHECK(m_gepCellsKey.initialize());
33
34 return StatusCode::SUCCESS;
35}
36
37
38StatusCode GepClusteringAlg::execute(const EventContext& ctx) const {
39 // Feed the specified cell map to a cluster creation algorithm and writes
40 // them out
41
42 ATH_MSG_DEBUG ("Executing " << name() << "...");
43
44 auto h_eventInfo = SG::makeHandle(m_eventInfoKey, ctx);
45 CHECK(h_eventInfo.isValid());
46 ATH_MSG_DEBUG("eventNumber=" << h_eventInfo->eventNumber() );
47
48 auto h_gepCellsMap = SG::makeHandle(m_gepCellsKey, ctx);
49 CHECK(h_gepCellsMap.isValid());
50 auto gepCellsMap = *h_gepCellsMap;
51
52 ATH_MSG_DEBUG("Read in " << gepCellsMap.size() << " GEP cells");
53
54 // container for CaloCluster wrappers for Gep Clusters
57 CHECK(h_outputCaloClusters.record(std::make_unique<xAOD::CaloClusterContainer>(),
58 std::make_unique<xAOD::CaloClusterAuxContainer>()));
59
60 // Run a cluster algorithm
61 std::unique_ptr<Gep::IClusterMaker> clusterMaker{};
62
63 // Instantiate a cluster creater object
64 if( m_clusterAlg == "WFS" ){
65 clusterMaker.reset(new Gep::WFSClusterMaker());
66 }
67
68 if( m_clusterAlg == "GEPBasic" ){
69 clusterMaker.reset(new Gep::BasicGepClusterMaker());
70 }
71
72 if( !clusterMaker ){
73 ATH_MSG_ERROR( "Unknown clusterMaker" + m_clusterAlg );
74 return StatusCode::FAILURE;
75 }
76
77 ATH_MSG_DEBUG( "Running " << clusterMaker->getName() << " cluster algorithm." );
78
79 // pass them to the cluster maker
80 auto pCellMap = gepCellsMap.getCellMap();
81 std::vector<Gep::Cluster> customClusters = clusterMaker->makeClusters(pCellMap);
82
83 ATH_MSG_DEBUG( "Clustering completed." );
84 ATH_MSG_DEBUG("No of clusters: " << customClusters.size());
85 if (!customClusters.empty()){
86 ATH_MSG_DEBUG("Cluster 0 Energy: " << (customClusters[0]).vec.E());
87 }
88
89 // Store the Gep clusters to a CaloClusters, and write out.
90 h_outputCaloClusters->reserve(customClusters.size());
91
92 for(const auto& gepclus: customClusters){
93
94 // make a unique_ptr, but keep hold of the bare pointer
95 auto caloCluster = std::make_unique<xAOD::CaloCluster>();
96 auto *ptr = caloCluster.get();
97
98 // store the calCluster to fix up the Aux container:
99 h_outputCaloClusters->push_back(std::move(caloCluster));
100
101 // this invalidates the unque_ptr, but can use the bare ptr
102 // to update the calo cluster.
103 ptr->setE(gepclus.vec.E());
104 ptr->setEta(gepclus.vec.Eta());
105 ptr->setPhi(gepclus.vec.Phi());
106 ptr->setTime(gepclus.time);
107
109
110 for (auto cell_id : gepclus.cell_id)
111 cccl->addCell(pCellMap->at(cell_id).index, 1.0);
112
113 ptr->addCellLink(std::make_unique<CaloClusterCellLink>(*cccl));
114 }
115
116
117 return StatusCode::SUCCESS;
118}
119
#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.
GepClusteringAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute(const EventContext &) const override
Gaudi::Property< std::string > m_clusterAlg
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
SG::ReadHandleKey< Gep::GepCellMap > m_gepCellsKey
virtual StatusCode initialize() override
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())