ATLAS Offline Software
CaloAsymRingsBuilder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // =================================================================================
6 #include "CaloAsymRingsBuilder.h"
7 //#include "CaloRingsBuilder.h"
8 
10 
11 // Cell includes:
12 #include "CaloUtils/CaloCellList.h"
13 #include "CaloGeoHelpers/CaloSampling.h"
15 
16 // RingSet includes:
19 
20 // CaloRings includes:
23 
24 // Ringer Conf include:
26 
27 // Other xAOD includes:
28 #include "xAODBase/IParticle.h"
30 
31 // STL
32 #include <algorithm>
33 #include <cfloat>
34 #include <cmath>
35 #include <sstream>
36 
37 namespace Ringer {
38 
39 // =================================================================================
41  const std::string& name,
42  const ::IInterface* parent)
43  : CaloRingsBuilder(type, name, parent)//AthAlgTool(type, name, parent)
44 {
45 
46  // declare interface
47  declareInterface<ICaloRingsBuilder>(this);
48 
49  declareProperty("doEtaAxesDivision", m_doEtaAxesDivision = false,
50  "Eta Axes can be divide in two.");
51  declareProperty("doPhiAxesDivision", m_doPhiAxesDivision = false,
52  "Phi Axes can be divide in two.");
53 }
54 
55 // =====================================================================================
57 = default;
58 
59 // =====================================================================================
61 {
62  ATH_MSG_DEBUG("Initializing " << name() );
63 
64  m_nRingSets = m_nRings.size();
65 
66  auto itr = m_layers.begin();
67 
68  // Build RingSets configuration:
69  for (size_t rsConfIdx = 0; rsConfIdx < m_nRingSets; ++rsConfIdx) {
70 
71  const auto rsNLayers = m_nLayers[rsConfIdx];
72 
73  auto end_itr = itr + rsNLayers;
74 
75  // Unfortunately, as we can't declare property to a
76  // std::vector<CaloSampling::CaloSample>, we will have to do this to
77  // convert the types:
78  const auto& caloSampleItr = reinterpret_cast<
80  >(itr);
81  const auto& caloSampleEndItr = reinterpret_cast<
83  >(end_itr);
84 
85  std::vector<CaloSampling::CaloSample> rsLayers( caloSampleItr ,
86  caloSampleEndItr);
87 
88  itr += rsNLayers;
89 
91  m_nRings[rsConfIdx],
92  rsLayers,
93  m_etaWidth[rsConfIdx], m_phiWidth[rsConfIdx],
98  );
99 
100  // Build our raw configuration structure:
101  m_rsRawConfCol.push_back(rawConf);
102  }
103 
104  // We have finished filling the main raw configuration properties, now we add
105  // it bounderies:
106  try {
108  } catch ( const std::runtime_error &e) {
109  ATH_MSG_ERROR("Could not add collection bounderies due to: " << e.what() );
110  ATH_MSG_ERROR("RawConfCollection is: ");
111  std::ostringstream str;
113  ATH_MSG_ERROR(str.str());
114  return StatusCode::FAILURE;
115  }
116 
117  // Print our collection
118  if (msgLevel() <= MSG::DEBUG){
119  std::ostringstream str;
121  ATH_MSG_DEBUG(str.str());
122  }
123  ATH_CHECK( m_crContName.initialize() );
124  ATH_CHECK( m_rsContName.initialize() );
127  return StatusCode::SUCCESS;
128 }
129 
130 // =====================================================================================
132 {
133  return StatusCode::SUCCESS;
134 }
135 
136 // =================================================================================
138  const xAOD::RingSetConf::RawConf &rawConf,
139  const AtlasGeoPoint &seed,
140  xAOD::RingSet *rs)
141 {
142  // Retrieve CaloCells
144  // check is only used for serial running; remove when MT scheduler used
145  if(!cellsCont.isValid()) {
146  ATH_MSG_FATAL("Failed to retrieve "<< m_cellsContName.key());
147  return StatusCode::FAILURE;
148  }
149 
151  const CaloDetDescrManager* caloMgr=*caloMgrHandle;
152 
153  CaloCellList cells(caloMgr, cellsCont.ptr() );
154 
155  // Get this RingSet size:
156  const auto nRings = rawConf.nRings;
157  // loop over cells
158  for ( const int layer : rawConf.layers) { // We use int here because the
159  // cells.select() method needs int as param
160  // FIXME This could have its speed improved by selecting only the truly
161  // needed window:
162  // If the nRings * eta/phi width is lower than cellMaxDEtaDist, then use it
163  // instead
164  cells.select(seed.eta(), seed.phi(), m_cellMaxDEtaDist, m_cellMaxDPhiDist, layer );
165  for ( const CaloCell *cell : cells ) {
166  unsigned int ringNumber(0);
167 
168  // calculate the normalised difference in eta
169  float deltaEta = (cell->eta() - seed.eta())
170  / rawConf.etaWidth;
171  bool etaPositive = deltaEta > 0;
172  deltaEta = fabs(deltaEta);
173 
174  // TODO Add phi asimetry...
175  // calculate the normalised difference in phi
176  float deltaPhi = CaloPhiRange::diff(cell->phi(), seed.phi());
177 
178  bool phiPositive = deltaPhi > 0;
179  deltaPhi = fabs(deltaPhi)/rawConf.phiWidth;
180 
181  // The biggest difference indicates the ring number (we are using
182  // squared-shape rings)
183  const float deltaGreater = std::max(deltaEta, deltaPhi);
184 
185  // Round to nearest integer:
186  ringNumber = static_cast<unsigned int>(std::floor(deltaGreater + .5));
187 
188  // Correct position in which we shall fill the ring:
189  if ( m_doEtaAxesDivision && m_doPhiAxesDivision && ringNumber ){
190  if (phiPositive){
191  if (etaPositive){
192  ringNumber = (ringNumber * 4) - 3;
193  }
194  else{
195  ringNumber = (ringNumber * 4) - 2;
196  }
197  }
198  else if (etaPositive){
199  ringNumber = (ringNumber * 4) - 1;
200  }
201  else{
202  ringNumber = (ringNumber * 4);
203  }
204  } else if ((m_doEtaAxesDivision || m_doPhiAxesDivision) && ringNumber){
205  if (m_doEtaAxesDivision){
206  ringNumber = (etaPositive)?(ringNumber * 2):
207  ((ringNumber * 2) - 1);
208  }
209  else {
210  ringNumber = (phiPositive)?(ringNumber * 2):
211  ((ringNumber * 2) - 1);
212  }
213  }
214 
215  if ( ringNumber < nRings ){
217  rs->at(ringNumber) += cell->energy()/cosh(cell->eta());
218  }else{
219  rs->at(ringNumber) += cell->energy();
220  }
221  }
222 
223  }
224  }
225  return StatusCode::SUCCESS;
226 }
227 
228 
229 } // namespace Ringer
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Ringer::CaloRingsBuilder::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: CaloRingsBuilder.h:245
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
xAOD::RingSetConf_v1::print
static void print(const RawConf &raw, std::ostream &stream)
Prints rawConf.
Definition: RingSetConf_v1.cxx:206
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CaloCellList
Definition: CaloCellList.h:40
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
IParticle.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
Ringer::CaloRingsBuilder::m_etaWidth
Gaudi::Property< std::vector< float > > m_etaWidth
Width of the ring in eta.
Definition: CaloRingsBuilder.h:175
Ringer::CaloAsymRingsBuilder::~CaloAsymRingsBuilder
~CaloAsymRingsBuilder()
Destructor.
Ringer::CaloRingsBuilder::m_cellMaxDPhiDist
Gaudi::Property< float > m_cellMaxDPhiDist
Maximum cell distance in phi to seed.
Definition: CaloRingsBuilder.h:191
Ringer::CaloAsymRingsBuilder::m_doPhiAxesDivision
bool m_doPhiAxesDivision
This can be set True to divide in two the phi axes.
Definition: CaloAsymRingsBuilder.h:70
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
CaloCellList.h
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
CaloAsymRingsBuilder.h
Ringer::CaloAsymRingsBuilder::m_doEtaAxesDivision
bool m_doEtaAxesDivision
This can be set True to divide in two the eta axes.
Definition: CaloAsymRingsBuilder.h:66
Ringer::CaloAsymRingsBuilder::CaloAsymRingsBuilder
CaloAsymRingsBuilder(const std::string &type, const std::string &name, const IInterface *parent)
Default constructor.
Definition: CaloAsymRingsBuilder.cxx:40
Ringer::CaloRingsBuilder::m_rsContName
SG::WriteHandleKey< xAOD::RingSetContainer > m_rsContName
Name of RingSetContainer on Event StoreGate.
Definition: CaloRingsBuilder.h:159
Ringer::CaloRingsBuilder::rawConf
const xAOD::RingSetConf::RawConfCollection & rawConf() override
Extra methods:
Definition: CaloRingsBuilder.h:95
xAOD::RingSet_v1::at
float & at(const unsigned int i)
Get/set ring Et at ith position.
Definition: RingSet_v1.cxx:42
RingSetAuxContainer.h
Ringer::CaloRingsBuilder::m_phiWidth
Gaudi::Property< std::vector< float > > m_phiWidth
Width of the ring in phi.
Definition: CaloRingsBuilder.h:180
xAOD::RingSet_v1
Class holding a set of rings.
Definition: RingSet_v1.h:31
Ringer::CaloRingsBuilder::m_cellsContName
SG::ReadHandleKey< CaloCellContainer > m_cellsContName
Name of CaloCellContainer.
Definition: CaloRingsBuilder.h:167
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
xAOD::RingSetConf_v1::whichLayer
static Ringer::CalJointLayer whichLayer(const std::vector< CaloSampling::CaloSample > &layers)
Definition: RingSetConf_v1.cxx:188
Ringer::CaloAsymRingsBuilder::initialize
virtual StatusCode initialize() override
Tool main methods:
Definition: CaloAsymRingsBuilder.cxx:60
CaloRingsAuxContainer.h
CaloRingsContainer.h
Ringer::CaloAsymRingsBuilder::buildRingSet
virtual StatusCode buildRingSet(const xAOD::RingSetConf::RawConf &rawConf, const AtlasGeoPoint &seed, xAOD::RingSet *rs) override
main method where the RingSets are built.
Definition: CaloAsymRingsBuilder.cxx:137
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Ringer::CaloRingsBuilder::m_layers
Gaudi::Property< std::vector< int > > m_layers
Calorimeter layers in each ringset.
Definition: CaloRingsBuilder.h:215
P4Helpers::deltaEta
double deltaEta(const I4Momentum &p1, const I4Momentum &p2)
Computes efficiently .
Definition: P4Helpers.h:66
CaloCluster.h
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
Ringer::CaloRingsBuilder::m_nLayers
Gaudi::Property< std::vector< unsigned int > > m_nLayers
Number of calorimeter layers in each ringset.
Definition: CaloRingsBuilder.h:222
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
Ringer::CaloRingsBuilder::m_cellMaxDEtaDist
Gaudi::Property< float > m_cellMaxDEtaDist
Maximum cell distance in eta to seed.
Definition: CaloRingsBuilder.h:185
xAOD::RingSetConf_v1::addRawConfColBounderies
static void addRawConfColBounderies(RawConfCollection &clRingsConf)
Add to RawConfCollection its JointLayer/JointSection bounderies.
Definition: RingSetConf_v1.cxx:239
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
Ringer::CaloAsymRingsBuilder::m_doTransverseEnergy
bool m_doTransverseEnergy
Definition: CaloAsymRingsBuilder.h:72
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
RingSetContainer.h
RingSetConf.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Ringer::CaloAsymRingsBuilder::finalize
virtual StatusCode finalize() override
finalize method
Definition: CaloAsymRingsBuilder.cxx:131
errorcheck.h
Helpers for checking error return status codes and reporting errors.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCellContainer.h
Ringer::CaloRingsBuilder::m_nRingSets
size_t m_nRingSets
hold the number of RingSets we are building for each CaloRings
Definition: CaloRingsBuilder.h:276
SG::ReadHandle::ptr
const_pointer_type ptr()
Dereference the pointer.
Ringer::CaloRingsBuilder::m_rsRawConfCol
xAOD::RingSetConf::RawConfCollection m_rsRawConfCol
holds each RingSet configuration (filled at initialize)
Definition: CaloRingsBuilder.h:262
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
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
Ringer::CaloRingsBuilder
Definition: CaloRingsBuilder.h:42
Ringer::CaloRingsBuilder::m_crContName
SG::WriteHandleKey< xAOD::CaloRingsContainer > m_crContName
Tool props (python configurables):
Definition: CaloRingsBuilder.h:151
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
AtlasGeoPoint
Definition: AtlasGeoPoint.h:15
xAOD::RingSetConf_v1::RawConf
Definition: RingSetConf_v1.h:49
str
Definition: BTagTrackIpAccessor.cxx:11
Ringer::CaloRingsBuilder::m_nRings
Gaudi::Property< std::vector< unsigned int > > m_nRings
Number of rings in a ringset.
Definition: CaloRingsBuilder.h:197
xAOD::RingSetConf_v1::whichSection
static Ringer::CalJointSection whichSection(const std::vector< CaloSampling::CaloSample > &layers)
Definition: RingSetConf_v1.cxx:179
CaloPhiRange::diff
static double diff(double phi1, double phi2)
simple phi1 - phi2 calculation, but result is fixed to respect range.
Definition: CaloPhiRange.cxx:22
Ringer
Namespace dedicated for Ringer utilities.
Definition: CaloRingsDefs.h:9