ATLAS Offline Software
LArFCalTowerStore.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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
22 
25 
28 
29 #include "CaloEvent/CaloTowerContainer.h"
30 #include "GaudiKernel/Bootstrap.h"
31 #include "GaudiKernel/Service.h"
32 
33 #include <cmath>
34 
36 // Constructor and Destructor //
38 
39 // constructor
41  : m_indxOffset (0),
42  m_indxBound (0)
43 {
44  // some parameters
45  m_ndxFCal.resize(3);
46  m_ndyFCal.resize(3);
47  // set default
48  m_ndxFCal[0] = 4;
49  m_ndxFCal[1] = 4;
50  m_ndxFCal[2] = 6;
51  m_ndyFCal[0] = 4;
52  m_ndyFCal[1] = 6;
53  m_ndyFCal[2] = 6;
54 
55  }
56 
57 // destructor
59 // m_dataMatrix.clear();
60  m_TTCmatrix.clear();
61 }
62 
64 // Build LookUp Table //
66 
68  const CaloDetDescrManager& theManager,
69  CaloTowerContainer* theTowers)
70 {
72  // Store Preparation //
74 
75  // messaging
76  IMessageSvc* theMsgSvc;
77  StatusCode sc = Gaudi::svcLocator()->service("MessageSvc",theMsgSvc);
78  if(sc.isFailure()){
79  std::cout << "LArFCalTowerStore: could not initialize the MessageSvc " << std::endl;
80  }
81  MsgStream msg(theMsgSvc,"LArFCalTowerStore");
82 
83  // get cell id helper
84  const LArFCAL_ID& fcalIdHelper = *cellIdHelper.fcal_idHelper();
85 
86  // find numerical ranges
87  IdentifierHash firstIndex, lastIndex;
88  cellIdHelper.calo_cell_hash_range((int)CaloCell_ID::LARFCAL, firstIndex, lastIndex);
89  m_indxOffset = (size_t)firstIndex;
90  m_indxBound = (size_t)lastIndex;
91 
92  // check
93  if ( m_indxBound <= m_indxOffset ){
94  msg << MSG::ERROR << "cannot initialize internal store properly, index offset = " << m_indxOffset << ", index boundary = "
95  << m_indxBound<< " -> module inactivated!"<< endmsg;
96  return false;
97  }
98 
99  // calculate number of rows in store matrix an initialize
100 // m_rowsMatrix = m_indxBound - m_indxOffset + 1;
101 // for ( size_t iRow=0; iRow < m_rowsMatrix; iRow++ ){
102 // m_dataMatrix.push_back(tower_data_store());
103 // }
104 
105  // report data store size
106 // msg << MSG::INFO << "internal matrix set up with " << m_dataMatrix.size()
107  // << " rows: Index Offset: " << m_indxOffset << " Index Boundary: "<< m_indxBound << endmsg;
108 
109 // m_weightInModule.resize(m_rowsMatrix);
110 // m_binDescriptor.resize(m_rowsMatrix);
111 
112  m_TTCmatrix.clear();
113  m_TTCmatrix.resize(theTowers->size());
114 
116  // Cell Loop //
118 
119  // consistent phi convention
120  CaloPhiRange correctPhi;
121 
122  // some stats
123 /* unsigned int aveTowers = 0;
124  unsigned int maxTowers = 0;
125  unsigned int minTowers = size_t(-1); */
126 
127  for( size_t cellIndex = m_indxOffset; cellIndex <= m_indxBound; cellIndex++){
128 
129 
130  // get cell geometry
131  const CaloDetDescrElement* theElement = theManager.get_element(cellIndex);
132  if (!theElement) {
133  msg << MSG::ERROR<< "Can't find element for index " << cellIndex
134  << endmsg;
135  return false;
136  }
137  double xCell = theElement->x();
138  double yCell = theElement->y();
139  double zCell = theElement->z();
140  double dxCell = theElement->dx();
141  double dyCell = theElement->dy();
142 
143  // get cell logical location
144  int thisModule = fcalIdHelper.module(theElement->identify());
145  // get cell splitting
146  thisModule--;
147  double theXBin = dxCell / (double)m_ndxFCal[thisModule];
148  double theYBin = dyCell / (double)m_ndyFCal[thisModule];
149  double theWeight = 1. / ((double) m_ndxFCal[thisModule] * m_ndyFCal[thisModule]);
150 
151 // std::pair<size_t,double> wMod(thisModule,theWeight);
152 // m_weightInModule[anIndex] = wMod;
153 // std::pair<size_t,size_t> iBin(m_ndxFCal[thisModule],m_ndyFCal[thisModule]);
154 // m_binDescriptor[anIndex] = iBin;
155 
156  // loop the cell fragments
157  for ( double x = xCell-dxCell/2.; x < xCell+(dxCell-theXBin/8.)/2.; x += theXBin ){
158  for ( double y = yCell-dyCell/2.;y < yCell+(dyCell-theYBin/8.)/2.;y += theYBin ){
159  // eta,phi of fragment
160  double r = sqrt( x * x + y * y + zCell * zCell );
161  double eta = -0.5 * log((r-zCell)/(r+zCell));
162  double phi = correctPhi.fix(atan2(y,x));
163  // get indices
164  // cppcheck-suppress duplicateAssignExpression
165  CaloTowerContainer::index_t etaIndex = theTowers->flagOutOfRange();
167  if ( theTowers->getTowerIndices(eta,phi,etaIndex,phiIndex) ){
168 
169  CaloTowerContainer::index_t towerIndex = theTowers->getTowerIndex(etaIndex,phiIndex);
170  std::vector<std::pair<unsigned int,double> >::iterator i = m_TTCmatrix[towerIndex].begin();
171  std::vector<std::pair<unsigned int,double> >::iterator e = m_TTCmatrix[towerIndex].end();
172  bool found=false;
173  for (;i<e;++i){
174  if (i->first==cellIndex){
175  i->second+=theWeight;
176  found=true;
177  break;
178  }
179  }
180  if (!found)
181  m_TTCmatrix[towerIndex].push_back(std::make_pair(cellIndex,theWeight));
182 
183  /*
184  // check indices in look-up
185  if ( (m_dataMatrix[anIndex]).find(towerIndex) != (m_dataMatrix[anIndex]).end() ){
186  (m_dataMatrix[anIndex])[towerIndex] += theWeight;
187  }
188  else{
189  (m_dataMatrix[anIndex])[towerIndex] = theWeight;
190  }
191  */
192 
193  } // index retrieval check
194 
195  } // cell y loop
196  } // cell x loop
197 
198 /* // collect some stats
199  if ( (m_dataMatrix[anIndex]).size() < minTowers ) minTowers = (m_dataMatrix[anIndex]).size();
200  if ( (m_dataMatrix[anIndex]).size() > maxTowers )maxTowers = (m_dataMatrix[anIndex]).size();
201  aveTowers += (m_dataMatrix[anIndex]).size(); */
202 
203  } // cell index loop
204 
205 /* // report
206  double cellTowers = (double)aveTowers / (double)m_dataMatrix.size();
207  msg << MSG::INFO
208  << "FCal cell/tower lookup done - min/ave/max towers/cell: "
209  << minTowers << "/" << cellTowers << "/" << maxTowers
210  << ", total number of cell fragments "
211  << aveTowers
212  << endmsg; */
213 
214 
215 
216  return 1;
217 
218 }
219 
220 
221 
224 {
225  return tower_subseg_iterator::make (towers(), subseg);
226 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
beamspotman.r
def r
Definition: beamspotman.py:676
CaloTowerSeg::SubSegIterator
Iterator over a rectangular window of towers.
Definition: CaloTowerSeg.h:337
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:46
CaloPhiRange
This class defines the phi convention for Calorimeters.
Definition: CaloPhiRange.h:28
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
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:79
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.
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
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:64
CaloTowerContainer
Storable container class for CaloTower.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:77
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
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
IdentifierHash.h
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
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
y
#define y
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
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:58
IdentifierHash
Definition: IdentifierHash.h:38
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:40
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
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:67