ATLAS Offline Software
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)
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 
39 }
40 
42 // Specific Initialization //
44 
46  ATH_CHECK( detStore()->retrieve (m_cellIdHelper, "CaloCell_ID") );
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 
60 inline
61 void
63  const ElementLink<CaloCellContainer>& cellsEL,
64  CaloTower* tower) const
65 {
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 
90 inline
91 void
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 
106 inline
107 void
109  const ElementLink<CaloCellContainer>& cellsEL,
110  const CaloTowerSeg::SubSeg* subseg) const
111 {
112  size_t sz = towers->size();
113  assert(subseg->size() == sz);
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 
127 void 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 
135 LArFCalTowerBuilderTool::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 
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 
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());
213  *theManager,
214  &theTowers) )
215  {
216  return StatusCode::SUCCESS;
217  }
218  return StatusCode::FAILURE;
219 }
220 
221 
222 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArFCalTowerStore::cell_iterator
tower_data_t::const_iterator cell_iterator
Definition: LArFCalTowerStore.h:41
CaloTowerSeg::SubSegIterator
Iterator over a rectangular window of towers.
Definition: CaloTowerSeg.h:337
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:46
fitman.sz
sz
Definition: fitman.py:527
LArFCalTowerBuilderTool::~LArFCalTowerBuilderTool
virtual ~LArFCalTowerBuilderTool()
Definition: LArFCalTowerBuilderTool.cxx:38
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArFCalTowerBuilderTool::iterateFull
void iterateFull(CaloTowerContainer *towers, const ElementLink< CaloCellContainer > &cellsEL) const
Definition: LArFCalTowerBuilderTool.cxx:92
LArFCalTowerStore::size
size_t size() const
size of internal data store
Definition: LArFCalTowerStore.h:80
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArFCalTowerBuilderTool::rebuildLookup
StatusCode rebuildLookup(const EventContext &ctx)
Rebuild the cell lookup table.
Definition: LArFCalTowerBuilderTool.cxx:205
LArFCalTowerStore::towers
tower_iterator towers() const
Definition: LArFCalTowerStore.h:53
LArFCalTowerBuilderTool::m_cellIdHelper
const CaloCell_ID * m_cellIdHelper
Definition: LArFCalTowerBuilderTool.h:94
CaloCell.h
CaloCell::e
virtual double e() const override final
get energy (data member) (synonym to method energy()
Definition: CaloCell.h:317
CaloTowerBuilderToolBase::getCells
const CaloCellContainer * getCells() const
Retrieve cells from StoreGate.
Definition: CaloTowerBuilderToolBase.cxx:59
LArFCalTowerStore::lastCellofTower
cell_iterator lastCellofTower(tower_iterator t) const
Definition: LArFCalTowerStore.h:71
LArFCalTowerBuilderTool::tower_iterator
LArFCalTowerStore::tower_iterator tower_iterator
Definition: LArFCalTowerBuilderTool.h:71
LArFCalTowerBuilderTool::m_minEt
double m_minEt
Definition: LArFCalTowerBuilderTool.h:67
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
LArFCalTowerStore::firstCellofTower
cell_iterator firstCellofTower(tower_iterator t) const
iterators: cells
Definition: LArFCalTowerStore.h:70
CaloEnergyCluster::addUniqueCellNoKine
void addUniqueCellNoKine(const CaloCellContainer *theContainer, index_type theIndex, double weight, size_t size_hint=0)
Add a cell (very fast)
Definition: CaloEnergyCluster.cxx:125
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
CaloCell_ID.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
CaloTowerSeg::SubSeg
A rectangular window within the segmentation.
Definition: CaloTowerSeg.h:220
LArFCalTowerBuilderTool::m_larFCalId
const LArFCAL_ID * m_larFCalId
Definition: LArFCalTowerBuilderTool.h:95
CaloTowerContainer
Storable container class for CaloTower.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:77
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
CaloCell_Base_ID::SUBCALO
SUBCALO
enumeration of sub calorimeters
Definition: CaloCell_Base_ID.h:46
CaloCellContainer::nCellsCalo
int nCellsCalo(const CaloCell_ID::SUBCALO caloNum) const
get number of cels of given calorimeter
Definition: CaloCellContainer.cxx:145
CaloTowerBuilderToolBase::towerSeg
const CaloTowerSeg & towerSeg() const
Return the tower segmentation.
Definition: CaloTowerBuilderToolBase.cxx:50
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CaloTowerSeg::SubSegIterator::itower
size_t itower() const
The tower index to which the iterator is referring.
Definition: CaloTowerSeg.h:710
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArFCalTowerBuilderTool::m_caloIndex
static const CaloCell_ID::SUBCALO m_caloIndex
Definition: LArFCalTowerBuilderTool.h:92
LArFCalTowerBuilderTool::m_cellStore
LArFCalTowerStore m_cellStore
Definition: LArFCalTowerBuilderTool.h:97
CaloTower
Data class for calorimeter cell towers.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTower.h:55
CaloTowerContainer::towerseg
const CaloTowerSeg & towerseg() const
Return a copy of the attached CaloTowerSeg.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:591
LArFCalTowerBuilderTool::LArFCalTowerBuilderTool
LArFCalTowerBuilderTool(const LArFCalTowerBuilderTool &)=delete
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
LArFCalTowerStore::towerSize
unsigned int towerSize(tower_iterator t) const
Definition: LArFCalTowerStore.h:72
LArFCalTowerStore.h
CaloTowerBuilderToolBase::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: CaloTowerBuilderToolBase.h:95
LArFCalTowerBuilderTool::initializeTool
virtual StatusCode initializeTool() override
Definition: LArFCalTowerBuilderTool.cxx:45
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
LArFCalTowerBuilderTool::runTimeInit
void runTimeInit(const EventContext &ctx) const
Definition: LArFCalTowerBuilderTool.cxx:127
LArFCAL_ID.h
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
RunTileMonitoring.towers
towers
Definition: RunTileMonitoring.py:133
LArFCalTowerBuilderTool
special tower builder for FCal
Definition: LArFCalTowerBuilderTool.h:36
CaloTowerBuilderToolBase
Definition: CaloTowerBuilderToolBase.h:31
LArFCalTowerBuilderTool::m_onceFlag
std::once_flag m_onceFlag
Definition: LArFCalTowerBuilderTool.h:98
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
P4EEtaPhiM::setE
virtual void setE(double theE)
set energy data member
Definition: P4EEtaPhiM.h:114
LArFCalTowerBuilderTool::addTower
void addTower(const tower_iterator &t, const ElementLink< CaloCellContainer > &cellsEL, CaloTower *tower) const
Definition: LArFCalTowerBuilderTool.cxx:62
CaloTowerSeg::SubSeg::size
size_t size() const
The number of towers in this window.
Definition: CaloTowerSeg.h:591
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
LArFCalTowerBuilderTool.h
python.CaloScaleNoiseConfig.ts
ts
Definition: CaloScaleNoiseConfig.py:86
LArFCalTowerBuilderTool::execute
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.
Definition: LArFCalTowerBuilderTool.cxx:135
CaloTowerBuilderToolBase.h
CaloTowerContainer::setCalo
void setCalo(const CaloCell_ID::SUBCALO &nCalo)
Adds a calorimeter index to the tower.
Definition: CaloTowerContainer.cxx:169
CaloTowerBuilderToolBase::setTowerSeg
virtual void setTowerSeg(const CaloTowerSeg &theTowerSeg) override
Definition: CaloTowerBuilderToolBase.cxx:37
CaloCell_ID::fcal_idHelper
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition: CaloCell_ID.h:75
LArFCalTowerStore::buildLookUp
bool buildLookUp(const CaloCell_ID &cellIdHelper, const CaloDetDescrManager &theManager, CaloTowerContainer *theTowers)
setup trigger
Definition: LArFCalTowerStore.cxx:68
CaloTower::getBasicEnergy
virtual double getBasicEnergy() const override
Basic signal getter.
Definition: CaloTower.cxx:51
LArFCalTowerBuilderTool::iterateSubSeg
void iterateSubSeg(CaloTowerContainer *towers, const ElementLink< CaloCellContainer > &cellsEL, const CaloTowerSeg::SubSeg *subseg) const
Definition: LArFCalTowerBuilderTool.cxx:108