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 #include "./BasicGepClusterMaker.h"
16 
19 
20 GepClusteringAlg::GepClusteringAlg( const std::string& name, ISvcLocator* pSvcLocator ) :
21 AthReentrantAlgorithm( 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
33 
34  return StatusCode::SUCCESS;
35 }
36 
37 
38 StatusCode 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
55  SG::WriteHandle<xAOD::CaloClusterContainer> h_outputCaloClusters =
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 
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
GepClusteringAlg::GepClusteringAlg
GepClusteringAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: GepClusteringAlg.cxx:20
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
GepClusteringAlg::m_eventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Definition: GepClusteringAlg.h:32
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:9
GepClusteringAlg.h
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
CaloClusterAuxContainer.h
GepClusteringAlg::m_outputCaloClustersKey
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outputCaloClustersKey
Definition: GepClusteringAlg.h:35
WFSClusterMaker.h
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
GepClusteringAlg::initialize
virtual StatusCode initialize() override
Definition: GepClusteringAlg.cxx:25
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
GepClusteringAlg::m_clusterAlg
Gaudi::Property< std::string > m_clusterAlg
Definition: GepClusteringAlg.h:29
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::execute
virtual StatusCode execute(const EventContext &) const override
Definition: GepClusteringAlg.cxx:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
BasicGepClusterMaker.h
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.
Gep::WFSClusterMaker
Definition: WFSClusterMaker.h:14
GepClusteringAlg::m_gepCellsKey
SG::ReadHandleKey< Gep::GepCellMap > m_gepCellsKey
Definition: GepClusteringAlg.h:38
Gep::BasicGepClusterMaker
Definition: BasicGepClusterMaker.h:14