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 
128 LArFCalTowerBuilderTool::execute(const EventContext& ctx,
129  CaloTowerContainer* theTowers,
130  const CaloCellContainer* theCells,
131  const CaloTowerSeg::SubSeg* subseg) const
132 {
133 
134  //Init internal structure m_cellStore on first invocation
135  //Alignment updates are not taken into account!
136  if (m_cellStoreInit.load() == false) {
137  //Aquire mutex before writing to m_cellStore
138  std::scoped_lock guard(m_cellStoreMutex);
139  //cast alway const-ness, acceptable since this is protected by a mutex
141  ATH_CHECK( thisNC->rebuildLookup(ctx) );
142  m_cellStoreInit.store(true);
143  }
144 
145 
146  if (m_cellStore.size() == 0) {
147  ATH_MSG_ERROR("Cell store not initialized.");
148  return StatusCode::FAILURE;
149  }
150 
151  // retrieve cells
152  if (!theCells) {
153  theCells = getCells();
154  if (!theCells) {
155  return StatusCode::SUCCESS;
156  }
157  }
158 
159  // check if any FCal in container
160  if ( theCells->nCellsCalo(m_caloIndex) == 0 ){
161  ATH_MSG_DEBUG( "no FCal cells in CaloCellContainer, skip tool!" );
162  return StatusCode::SUCCESS;
163  }
164 
166  // Map Cells on Towers //
168 
169  // register this calorimeter
170  theTowers->setCalo(m_caloIndex);
171 
172  const ElementLink<CaloCellContainer> cellsEL (*theCells, 0, ctx);
173  if (subseg)
174  iterateSubSeg (theTowers, cellsEL, subseg);
175  else
176  iterateFull (theTowers, cellsEL);
177 
178  return StatusCode::SUCCESS;
179 }
180 
181 
191  CaloTowerContainer* theContainer)
192 {
193  if (m_cellStore.size() == 0) {
194  setTowerSeg (theContainer->towerseg());
195  ATH_CHECK( rebuildLookup(ctx) );
196  }
197 
198  return execute (ctx, theContainer, nullptr, nullptr);
199 }
200 
201 
202 
207 {
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:206
LArFCalTowerStore::towers
tower_iterator towers() const
Definition: LArFCalTowerStore.h:53
LArFCalTowerBuilderTool::m_cellIdHelper
const CaloCell_ID * m_cellIdHelper
Definition: LArFCalTowerBuilderTool.h:92
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:93
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:90
LArFCalTowerBuilderTool::m_cellStore
LArFCalTowerStore m_cellStore
Definition: LArFCalTowerBuilderTool.h:95
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:195
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::m_cellStoreInit
std::atomic_bool m_cellStoreInit
Definition: LArFCalTowerBuilderTool.h:97
LArFCAL_ID.h
LArFCalTowerBuilderTool::m_cellStoreMutex
std::mutex m_cellStoreMutex
Definition: LArFCalTowerBuilderTool.h:96
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
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:128
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:67
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