ATLAS Offline Software
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"
15 
18 
19 GepClusteringAlg::GepClusteringAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
20 AthReentrantAlgorithm( name, pSvcLocator ){
21  }
22 
23 
25  ATH_MSG_INFO ("Initializing " << name() << "...");
26  ATH_MSG_INFO ("Clustering alg " << m_clusterAlg);
27 
28  // Retrieve AlgTools
29  CHECK(m_caloCellsTool.retrieve());
30 
34 
35 
36  return StatusCode::SUCCESS;
37 }
38 
39 
40 StatusCode GepClusteringAlg::execute(const EventContext& ctx) const {
41  // Read in a CaloCell container. Clean up the collection (noise handling),
42  // and transform the cells to a more congenial format. Feed the cells
43  // to a cluster creation algorithm. Convert these clusters to CaloCells,
44  // and write them out.
45 
46  ATH_MSG_DEBUG ("Executing " << name() << "...");
47 
48  auto h_eventInfo = SG::makeHandle(m_eventInfoKey, ctx);
49  CHECK(h_eventInfo.isValid());
50  ATH_MSG_DEBUG("eventNumber=" << h_eventInfo->eventNumber() );
51 
52  //
53  // Read in a container containing (all) CaloCells
54 
55  auto h_caloCells = SG::makeHandle(m_caloCellsKey, ctx);
56  CHECK(h_caloCells.isValid());
57  auto cells = *h_caloCells;
58 
59  // container for CaloCluster wrappers for Gep Clusters
60  SG::WriteHandle<xAOD::CaloClusterContainer> h_outputCaloClusters =
62  CHECK(h_outputCaloClusters.record(std::make_unique<xAOD::CaloClusterContainer>(),
63  std::make_unique<xAOD::CaloClusterAuxContainer>()));
64 
65  ATH_MSG_INFO("read in " + std::to_string(h_caloCells->size()) + " cells");
66 
67  // Run a cluster algorithm
68  std::unique_ptr<Gep::IClusterMaker> clusterMaker{};
69 
70  // Instantiate a cluster creater object
71  if( m_clusterAlg == "WFS" ){
72  clusterMaker.reset(new Gep::WFSClusterMaker());
73  }
74 
75  if( !clusterMaker ){
76  ATH_MSG_ERROR( "Unknown clusterMaker" + m_clusterAlg );
77  return StatusCode::FAILURE;
78  }
79 
80  ATH_MSG_DEBUG( "Running " << clusterMaker->getName() << " cluster algorithm." );
81 
82  // run the clustering algorthm, and obtain the Gep clusters
83  // first get the massaged Cells
84  auto cell_map = std::make_unique<GepCellMap>();
85  CHECK(m_caloCellsTool->getGepCellMap(*h_caloCells, cell_map, ctx));
86 
87  // pass them to the cluster maker
88  std::vector<Gep::Cluster> customClusters =
89  clusterMaker->makeClusters(cell_map);
90 
91  ATH_MSG_DEBUG( "Clustering completed." );
92  ATH_MSG_DEBUG("No of clusters: " << customClusters.size());
93  if (!customClusters.empty()){
94  ATH_MSG_DEBUG("Cluster 0 Energy: " << (customClusters[0]).vec.E());
95  }
96 
97 
98  // Store the Gep clusters to a CaloClusters, and write out.
99  h_outputCaloClusters->reserve(customClusters.size());
100 
101  for(const auto& gepclus: customClusters){
102 
103  // make a unique_ptr, but keep hold of the bare pointer
104  auto caloCluster = std::make_unique<xAOD::CaloCluster>();
105  auto *ptr = caloCluster.get();
106 
107  // store the calCluster to fix up the Aux container:
108  h_outputCaloClusters->push_back(std::move(caloCluster));
109 
110  // this invalidates the unque_ptr, but can use the bare ptr
111  // to update the calo cluster.
112  ptr->setE(gepclus.vec.E());
113  ptr->setEta(gepclus.vec.Eta());
114  ptr->setPhi(gepclus.vec.Phi());
115  ptr->setTime(gepclus.time);
116 
118  for (auto cell_id : gepclus.cell_id)
119  cccl->addCell(cell_map->at(cell_id).index, 1.0);
120 
121  ptr->addCellLink(cccl);
122  }
123 
124 
125  return StatusCode::SUCCESS;
126 }
127 
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
GepClusteringAlg::GepClusteringAlg
GepClusteringAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: GepClusteringAlg.cxx:19
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
GepClusteringAlg::m_caloCellsTool
ToolHandle< CaloCellsHandlerTool > m_caloCellsTool
Definition: GepClusteringAlg.h:29
GepClusteringAlg::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: GepClusteringAlg.h:38
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
GepClusteringAlg.h
CaloClusterAuxContainer.h
GepClusteringAlg::m_outputCaloClustersKey
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outputCaloClustersKey
Definition: GepClusteringAlg.h:42
WFSClusterMaker.h
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
GepClusteringAlg::initialize
virtual StatusCode initialize() override
Definition: GepClusteringAlg.cxx:24
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
GepClusteringAlg::m_clusterAlg
Gaudi::Property< std::string > m_clusterAlg
Definition: GepClusteringAlg.h:26
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
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
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
GepClusteringAlg::m_caloCellsKey
SG::ReadHandleKey< CaloCellContainer > m_caloCellsKey
Definition: GepClusteringAlg.h:35
GepClusteringAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition: GepClusteringAlg.cxx:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
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.
Gep::WFSClusterMaker
Definition: WFSClusterMaker.h:14