ATLAS Offline Software
Loading...
Searching...
No Matches
LArFCalTowerBuilderTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7#include "LArFCalTowerStore.h"
8
12
14
15#include "CaloEvent/CaloCell.h"
17#include "CaloEvent/CaloTower.h"
18#include "CaloEvent/CaloTowerContainer.h"
19
20#include <string>
21#include <cmath>
22
25
27 const std::string& type,
28 const IInterface* parent)
29 : CaloTowerBuilderToolBase(name,type,parent)
30 , m_minEt(0.)
31 , m_cellIdHelper(nullptr)
32 , m_larFCalId(nullptr)
33{
34 // Et cut for minicells
35 declareProperty("MinimumEt",m_minEt);
36}
37
40
42// Specific Initialization //
44
46 ATH_CHECK( detStore()->retrieve (m_cellIdHelper, "CaloCell_ID") );
47 m_larFCalId = m_cellIdHelper->fcal_idHelper();
48
49 // ignore other input!
50 ATH_MSG_INFO( "CaloTowerBuilder for the FCal initiated" );
51
52 return StatusCode::SUCCESS;
53}
54
56// Tower Builder Helpers //
58
59
60inline
61void
63 const ElementLink<CaloCellContainer>& cellsEL,
64 CaloTower* tower) const
65{
66 LArFCalTowerStore::cell_iterator firstC = m_cellStore.firstCellofTower(t);
67 LArFCalTowerStore::cell_iterator lastC = m_cellStore.lastCellofTower(t);
68 // here get needed size of this vector and use it to reserve tower size.
69 int ts= m_cellStore.towerSize(t);
70 double wsumE = tower->getBasicEnergy(); // this is not 0 since some towers already have cells from other calos.
71 const CaloCellContainer* cells = cellsEL.getDataPtr();
72 for (; firstC != lastC; ++firstC) {
73
74 unsigned int ci = firstC->first;
75 double weightC = firstC->second;
76 int cndx = cells->findIndex(ci);
77 const CaloCell* cellPtr = nullptr;
78 if (cndx >= 0)
79 cellPtr = (*cells)[cndx];
80 // get weights
81 if (cellPtr) {
82 wsumE += weightC * cellPtr->e(); // Summ up weighted energies .
83 tower->addUniqueCellNoKine(cellsEL, cndx, weightC, ts); // add cells to tower.
84 }
85 }
86 tower->setE(wsumE); // update tower kinematics.
87}
88
89
90inline
91void
93 const ElementLink<CaloCellContainer>& cellsEL) const
94{
95 size_t sz = towers->size();
96 assert(m_cellStore.size() == sz);
97 tower_iterator tower_it = m_cellStore.towers();
98
99 for (unsigned int t = 0; t < sz; ++t, ++tower_it) {
100 CaloTower* aTower = towers->getTower(t);
101 addTower (tower_it, cellsEL, aTower);
102 }
103}
104
105
106inline
107void
109 const ElementLink<CaloCellContainer>& cellsEL,
110 const CaloTowerSeg::SubSeg* subseg) const
111{
112 size_t sz = towers->size();
113 assert(subseg->size() == sz);
114 LArFCalTowerStore::tower_subseg_iterator tower_it = m_cellStore.towers(*subseg);
115
116 for (unsigned int t = 0; t < sz; ++t, ++tower_it) {
117 CaloTower* aTower = towers->getTower(tower_it.itower());
118 addTower (tower_it, cellsEL, aTower);
119 }
120}
121
122
124// Find Towers in FCal //
126
127void LArFCalTowerBuilderTool::runTimeInit(const EventContext& ctx) const {
128 //cast alway const-ness, acceptable since this is protected under a std::call_once
130 if( thisNC->rebuildLookup(ctx)!=StatusCode::SUCCESS )
131 throw std::runtime_error("LArFCalTowerBuilderTool::runTimeInit rebuildLookup table failed");
132}
133
134StatusCode
135LArFCalTowerBuilderTool::execute(const EventContext& ctx,
136 CaloTowerContainer* theTowers,
137 const CaloCellContainer* theCells,
138 const CaloTowerSeg::SubSeg* subseg) const
139{
140
141 //Init internal structure m_cellStore on first invocation
142 //Alignment updates are not taken into account!
143 std::call_once(m_onceFlag,&LArFCalTowerBuilderTool::runTimeInit,this,ctx);
144
145 if (m_cellStore.size() == 0) {
146 ATH_MSG_ERROR("Cell store not initialized.");
147 return StatusCode::FAILURE;
148 }
149
150 // retrieve cells
151 if (!theCells) {
152 theCells = getCells();
153 if (!theCells) {
154 return StatusCode::SUCCESS;
155 }
156 }
157
158 // check if any FCal in container
159 if ( theCells->nCellsCalo(m_caloIndex) == 0 ){
160 ATH_MSG_DEBUG( "no FCal cells in CaloCellContainer, skip tool!" );
161 return StatusCode::SUCCESS;
162 }
163
165 // Map Cells on Towers //
167
168 // register this calorimeter
169 theTowers->setCalo(m_caloIndex);
170
171 const ElementLink<CaloCellContainer> cellsEL (*theCells, 0, ctx);
172 if (subseg)
173 iterateSubSeg (theTowers, cellsEL, subseg);
174 else
175 iterateFull (theTowers, cellsEL);
176
177 return StatusCode::SUCCESS;
178}
179
180
189StatusCode LArFCalTowerBuilderTool::execute (const EventContext& ctx,
190 CaloTowerContainer* theContainer)
191{
192 if (m_cellStore.size() == 0) {
193 setTowerSeg (theContainer->towerseg());
194 ATH_CHECK( rebuildLookup(ctx) );
195 }
196
197 return execute (ctx, theContainer, nullptr, nullptr);
198}
199
200
201
205StatusCode LArFCalTowerBuilderTool::rebuildLookup(const EventContext& ctx)
206{
207// std::cout << "rebuildLookup in context : " << ctx << std::endl;
208 ATH_MSG_DEBUG("Building lookup table");
210 const CaloDetDescrManager* theManager = *caloMgrHandle;
211 CaloTowerContainer theTowers (towerSeg());
212 if ( m_cellStore.buildLookUp(*m_cellIdHelper,
213 *theManager,
214 &theTowers) )
215 {
216 return StatusCode::SUCCESS;
217 }
218 return StatusCode::FAILURE;
219}
220
221
222
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Definition of CaloDetDescrManager.
static Double_t sz
#define ATLAS_THREAD_SAFE
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Container class for CaloCell.
int nCellsCalo(const CaloCell_ID::SUBCALO caloNum) const
get number of cels of given calorimeter
CaloCell_Base_ID::SUBCALO SUBCALO
Definition CaloCell_ID.h:50
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
virtual double e() const override final
get energy (data member) (synonym to method energy()
Definition CaloCell.h:333
This class provides the client interface for accessing the detector description information common to...
void addUniqueCellNoKine(const CaloCellContainer *theContainer, index_type theIndex, double weight, size_t size_hint=0)
Add a cell (very fast)
const CaloTowerSeg & towerSeg() const
Return the tower segmentation.
virtual void setTowerSeg(const CaloTowerSeg &theTowerSeg) override
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
CaloTowerBuilderToolBase(const std::string &name, const std::string &type, const IInterface *parent)
AlgTool constructor.
const CaloCellContainer * getCells() const
Retrieve cells from StoreGate.
Storable container class for CaloTower.
void setCalo(const CaloCell_ID::SUBCALO &nCalo)
Adds a calorimeter index to the tower.
const CaloTowerSeg & towerseg() const
Return a copy of the attached CaloTowerSeg.
size_t itower() const
The tower index to which the iterator is referring.
A rectangular window within the segmentation.
size_t size() const
The number of towers in this window.
Data class for calorimeter cell towers.
virtual double getBasicEnergy() const override
Basic signal getter.
Definition CaloTower.cxx:51
const CaloCell_ID * m_cellIdHelper
virtual StatusCode execute(const EventContext &ctx, CaloTowerContainer *theContainer, const CaloCellContainer *theCell=0, const CaloTowerSeg::SubSeg *subseg=0) const override
Run tower building and add results to the tower container.
void iterateFull(CaloTowerContainer *towers, const ElementLink< CaloCellContainer > &cellsEL) const
LArFCalTowerStore::tower_iterator tower_iterator
virtual StatusCode initializeTool() override
LArFCalTowerBuilderTool(const LArFCalTowerBuilderTool &)=delete
static const CaloCell_ID::SUBCALO m_caloIndex
void runTimeInit(const EventContext &ctx) const
StatusCode rebuildLookup(const EventContext &ctx)
Rebuild the cell lookup table.
void iterateSubSeg(CaloTowerContainer *towers, const ElementLink< CaloCellContainer > &cellsEL, const CaloTowerSeg::SubSeg *subseg) const
void addTower(const tower_iterator &t, const ElementLink< CaloCellContainer > &cellsEL, CaloTower *tower) const
CaloTowerSeg::SubSegIterator< tower_iterator > tower_subseg_iterator
tower_data_t::const_iterator cell_iterator
virtual void setE(double theE)
set energy data member
Definition P4EEtaPhiM.h:114
int ts
Definition globals.cxx:24