ATLAS Offline Software
LArFCalTowerStore.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /********************************************************************
6 
7 NAME: LArFCalTowerStore
8 PACKAGE: offline/LArCalorimeter/LArRecUtils
9 
10 AUTHORS: P. Loch
11 CREATED: May 2001
12 
13 PURPOSE: Intermediate store for cell/tower maps
14 
15 Updated:
16 
17 ********************************************************************/
18 #include "LArFCalTowerStore.h"
19 
20 // include header files
23 
26 
29 
30 #include "CaloEvent/CaloTowerContainer.h"
31 #include "GaudiKernel/Bootstrap.h"
32 #include "GaudiKernel/Service.h"
33 
34 #include <cmath>
35 
37 // Constructor and Destructor //
39 
40 // constructor
42  : m_indxOffset (0),
43  m_indxBound (0)
44 {
45  // some parameters
46  m_ndxFCal.resize(3);
47  m_ndyFCal.resize(3);
48  // set default
49  m_ndxFCal[0] = 4;
50  m_ndxFCal[1] = 4;
51  m_ndxFCal[2] = 6;
52  m_ndyFCal[0] = 4;
53  m_ndyFCal[1] = 6;
54  m_ndyFCal[2] = 6;
55 
56  }
57 
58 // destructor
60 // m_dataMatrix.clear();
61  m_TTCmatrix.clear();
62 }
63 
65 // Build LookUp Table //
67 
69  const CaloDetDescrManager& theManager,
70  CaloTowerContainer* theTowers)
71 {
73  // Store Preparation //
75 
76  // get cell id helper
77  const LArFCAL_ID& fcalIdHelper = *cellIdHelper.fcal_idHelper();
78 
79  // find numerical ranges
80  IdentifierHash firstIndex, lastIndex;
81  cellIdHelper.calo_cell_hash_range((int)CaloCell_ID::LARFCAL, firstIndex, lastIndex);
82  m_indxOffset = (size_t)firstIndex;
83  m_indxBound = (size_t)lastIndex;
84 
85  // check
86  if ( m_indxBound <= m_indxOffset ){
87  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "LArFCalTowerStore")
88  << "cannot initialize internal store properly, index offset = "
89  << m_indxOffset << ", index boundary = " << m_indxBound<< " -> module inactivated!"
90  << endmsg;
91  return false;
92  }
93 
94  // calculate number of rows in store matrix an initialize
95 // m_rowsMatrix = m_indxBound - m_indxOffset + 1;
96 // for ( size_t iRow=0; iRow < m_rowsMatrix; iRow++ ){
97 // m_dataMatrix.push_back(tower_data_store());
98 // }
99 
100  // report data store size
101 // msg << MSG::INFO << "internal matrix set up with " << m_dataMatrix.size()
102  // << " rows: Index Offset: " << m_indxOffset << " Index Boundary: "<< m_indxBound << endmsg;
103 
104 // m_weightInModule.resize(m_rowsMatrix);
105 // m_binDescriptor.resize(m_rowsMatrix);
106 
107  m_TTCmatrix.clear();
108  m_TTCmatrix.resize(theTowers->size());
109 
111  // Cell Loop //
113 
114  // consistent phi convention
115  CaloPhiRange correctPhi;
116 
117  // some stats
118 /* unsigned int aveTowers = 0;
119  unsigned int maxTowers = 0;
120  unsigned int minTowers = size_t(-1); */
121 
122  for( size_t cellIndex = m_indxOffset; cellIndex <= m_indxBound; cellIndex++){
123 
124 
125  // get cell geometry
126  const CaloDetDescrElement* theElement = theManager.get_element(cellIndex);
127  if (!theElement) {
128  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "LArFCalTowerStore")
129  << "Can't find element for index " << cellIndex << endmsg;
130  return false;
131  }
132  double xCell = theElement->x();
133  double yCell = theElement->y();
134  double zCell = theElement->z();
135  double dxCell = theElement->dx();
136  double dyCell = theElement->dy();
137 
138  // get cell logical location
139  int thisModule = fcalIdHelper.module(theElement->identify());
140  // get cell splitting
141  thisModule--;
142  double theXBin = dxCell / (double)m_ndxFCal[thisModule];
143  double theYBin = dyCell / (double)m_ndyFCal[thisModule];
144  double theWeight = 1. / ((double) m_ndxFCal[thisModule] * m_ndyFCal[thisModule]);
145 
146 // std::pair<size_t,double> wMod(thisModule,theWeight);
147 // m_weightInModule[anIndex] = wMod;
148 // std::pair<size_t,size_t> iBin(m_ndxFCal[thisModule],m_ndyFCal[thisModule]);
149 // m_binDescriptor[anIndex] = iBin;
150 
151  // loop the cell fragments
152  for ( double x = xCell-dxCell/2.; x < xCell+(dxCell-theXBin/8.)/2.; x += theXBin ){
153  for ( double y = yCell-dyCell/2.;y < yCell+(dyCell-theYBin/8.)/2.;y += theYBin ){
154  // eta,phi of fragment
155  double r = sqrt( x * x + y * y + zCell * zCell );
156  double eta = -0.5 * log((r-zCell)/(r+zCell));
157  double phi = correctPhi.fix(atan2(y,x));
158  // get indices
159  // cppcheck-suppress duplicateAssignExpression
160  CaloTowerContainer::index_t etaIndex = theTowers->flagOutOfRange();
162  if ( theTowers->getTowerIndices(eta,phi,etaIndex,phiIndex) ){
163 
164  CaloTowerContainer::index_t towerIndex = theTowers->getTowerIndex(etaIndex,phiIndex);
165  std::vector<std::pair<unsigned int,double> >::iterator i = m_TTCmatrix[towerIndex].begin();
166  std::vector<std::pair<unsigned int,double> >::iterator e = m_TTCmatrix[towerIndex].end();
167  bool found=false;
168  for (;i<e;++i){
169  if (i->first==cellIndex){
170  i->second+=theWeight;
171  found=true;
172  break;
173  }
174  }
175  if (!found)
176  m_TTCmatrix[towerIndex].push_back(std::make_pair(cellIndex,theWeight));
177 
178  /*
179  // check indices in look-up
180  if ( (m_dataMatrix[anIndex]).find(towerIndex) != (m_dataMatrix[anIndex]).end() ){
181  (m_dataMatrix[anIndex])[towerIndex] += theWeight;
182  }
183  else{
184  (m_dataMatrix[anIndex])[towerIndex] = theWeight;
185  }
186  */
187 
188  } // index retrieval check
189 
190  } // cell y loop
191  } // cell x loop
192 
193 /* // collect some stats
194  if ( (m_dataMatrix[anIndex]).size() < minTowers ) minTowers = (m_dataMatrix[anIndex]).size();
195  if ( (m_dataMatrix[anIndex]).size() > maxTowers )maxTowers = (m_dataMatrix[anIndex]).size();
196  aveTowers += (m_dataMatrix[anIndex]).size(); */
197 
198  } // cell index loop
199 
200 /* // report
201  double cellTowers = (double)aveTowers / (double)m_dataMatrix.size();
202  msg << MSG::INFO
203  << "FCal cell/tower lookup done - min/ave/max towers/cell: "
204  << minTowers << "/" << cellTowers << "/" << maxTowers
205  << ", total number of cell fragments "
206  << aveTowers
207  << endmsg; */
208 
209 
210 
211  return 1;
212 
213 }
214 
215 
216 
219 {
220  return tower_subseg_iterator::make (towers(), subseg);
221 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
beamspotman.r
def r
Definition: beamspotman.py:674
CaloTowerSeg::SubSegIterator
Iterator over a rectangular window of towers.
Definition: CaloTowerSeg.h:337
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:43
CaloPhiRange
This class defines the phi convention for Calorimeters.
Definition: CaloPhiRange.h:28
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
CaloDetDescrElement::y
float y() const
cell y
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:365
CaloTowerSeg::SubSegIterator::make
static SubSegIterator make(TOWER_ITERATOR beg, const SubSeg &subseg)
Construct a new iterator for iterating over a window.
Definition: CaloTowerSeg.h:609
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
LArFCalTowerStore::towers
tower_iterator towers() const
Definition: LArFCalTowerStore.h:53
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloDetDescrManager_Base::get_element
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
Definition: CaloDetDescrManager.cxx:159
LArFCAL_Base_ID::module
int module(const Identifier id) const
module [1,3]
x
#define x
CaloTowerContainer::getTowerIndex
index_t getTowerIndex(const CaloTower *aTower) const
Returns the combined index of a tower on the grid.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:598
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
CaloCell_ID.h
CaloTowerSeg::SubSeg
A rectangular window within the segmentation.
Definition: CaloTowerSeg.h:220
LArFCalTowerStore::m_TTCmatrix
tower_table_t m_TTCmatrix
Definition: LArFCalTowerStore.h:90
CaloDetDescrElement::identify
Identifier identify() const override final
cell identifier
Definition: CaloDetDescrElement.cxx:63
CaloTowerContainer
Storable container class for CaloTower.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:77
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloCell_Base_ID::calo_cell_hash_range
void calo_cell_hash_range(const Identifier id, IdentifierHash &caloCellMin, IdentifierHash &caloCellMax) const
to loop on 'global' cell hashes of one sub-calorimeter alone
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
CaloTowerContainer::getTowerIndices
bool getTowerIndices(const CaloTower *aTower, index_t &indexEta, index_t &indexPhi) const
Returns both and indices for a given tower.
Definition: CaloTowerContainer.cxx:235
LArFCalTowerStore::m_indxOffset
size_t m_indxOffset
Definition: LArFCalTowerStore.h:87
CaloPhiRange.h
CaloPhiRange class declaration.
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
CaloPhiRange::fix
static double fix(double phi)
Definition: CaloPhiRange.cxx:14
LArFCalTowerStore::m_indxBound
size_t m_indxBound
Definition: LArFCalTowerStore.h:88
REPORT_MESSAGE_WITH_CONTEXT
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:345
IdentifierHash.h
errorcheck.h
Helpers for checking error return status codes and reporting errors.
checkTriggerxAOD.found
found
Definition: checkTriggerxAOD.py:328
LArFCalTowerStore.h
LArFCalTowerStore::m_ndxFCal
std::vector< unsigned int > m_ndxFCal
Definition: LArFCalTowerStore.h:84
CaloDetDescrElement::x
float x() const
cell x
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:363
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
LArFCAL_ID.h
CaloTowerContainer::index_t
size_t index_t
Tower map index type.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:82
y
#define y
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
CaloDetDescrElement::dx
float dx() const
cell dx
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:375
CaloDetDescrElement::z
float z() const
cell z
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:367
LArFCalTowerStore::m_ndyFCal
std::vector< unsigned int > m_ndyFCal
Definition: LArFCalTowerStore.h:85
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
LArFCalTowerStore::~LArFCalTowerStore
~LArFCalTowerStore()
destructor
Definition: LArFCalTowerStore.cxx:59
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
LArFCAL_ID
Helper class for LArFCAL offline identifiers.
Definition: LArFCAL_ID.h:60
CaloDetDescrElement::dy
float dy() const
cell dy
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:377
LArFCalTowerStore::LArFCalTowerStore
LArFCalTowerStore()
constructor
Definition: LArFCalTowerStore.cxx:41
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
CaloCell_ID::fcal_idHelper
const LArFCAL_ID * fcal_idHelper() const
access to FCAL idHelper
Definition: CaloCell_ID.h:75
CaloTowerContainer::flagOutOfRange
index_t flagOutOfRange() const
Returns the index out-of-range indicator.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:651
LArFCalTowerStore::buildLookUp
bool buildLookUp(const CaloCell_ID &cellIdHelper, const CaloDetDescrManager &theManager, CaloTowerContainer *theTowers)
setup trigger
Definition: LArFCalTowerStore.cxx:68