ATLAS Offline Software
CaloStripsRingsBuilder.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 
9 #include "CaloGeoHelpers/CaloSampling.h"
10 #include "CaloUtils/CaloCellList.h"
11 #include "xAODBase/IParticle.h"
18 #include <algorithm>
19 #include <cfloat>
20 #include <cmath>
21 #include <sstream>
22 
23 namespace Ringer {
24 
25 // =================================================================================
27  const std::string& name,
28  const ::IInterface* parent)
30 {
31 
32  declareInterface<ICaloRingsBuilder>(this);
33  declareProperty("Axis", m_axis=0, "Which axis to use when building the strips");
34  declareProperty("doEtaAxesDivision", m_doEtaAxesDivision = false, "Eta Axes can be divide in two.");
35  declareProperty("doPhiAxesDivision", m_doPhiAxesDivision = false, "Phi Axes can be divide in two.");
36 }
37 
38 // =====================================================================================
40 
41 // =====================================================================================
43 {
44  ATH_MSG_WARNING("Initializing " << name() );
45  m_nRingSets = m_nRings.size();
46  auto itr = m_layers.begin();
47 
48  for (size_t rsConfIdx = 0; rsConfIdx < m_nRingSets; ++rsConfIdx) {
49 
50  const auto rsNLayers = m_nLayers[rsConfIdx];
51  auto end_itr = itr + rsNLayers;
52 
53  const auto& caloSampleItr = reinterpret_cast< std::vector<CaloSampling::CaloSample>::iterator& >(itr);
54  const auto& caloSampleEndItr = reinterpret_cast< std::vector<CaloSampling::CaloSample>::iterator& >(end_itr);
55 
56  std::vector<CaloSampling::CaloSample> rsLayers( caloSampleItr , caloSampleEndItr);
57  itr += rsNLayers;
58 
60  m_nRings[rsConfIdx],
61  rsLayers,
62  m_etaWidth[rsConfIdx], m_phiWidth[rsConfIdx],
66  );
67  m_rsRawConfCol.push_back(rawConf);
68  }
69 
70  try {
72  } catch ( const std::runtime_error &e) {
73  ATH_MSG_ERROR("Could not add collection bounderies due to: " << e.what() );
74  ATH_MSG_ERROR("RawConfCollection is: ");
75  std::ostringstream str;
77  ATH_MSG_ERROR(str.str());
78  return StatusCode::FAILURE;
79  }
80 
81  ATH_CHECK( m_crContName.initialize() );
82  ATH_CHECK( m_rsContName.initialize() );
85  return StatusCode::SUCCESS;
86 }
87 
88 // =====================================================================================
90 {
91  return StatusCode::SUCCESS;
92 }
93 // =================================================================================
94 
96  const xAOD::RingSetConf::RawConf &rawConf,
97  const AtlasGeoPoint &seed,
98  xAOD::RingSet *rs)
99 {
100  const auto nStrips = rawConf.nRings;
101  int midPoint = nStrips/2;
102 
104  if(!cellsCont.isValid()) {
105  ATH_MSG_FATAL("Failed to retrieve "<< m_cellsContName.key());
106  return StatusCode::FAILURE;
107  }
108 
110  const CaloDetDescrManager* caloMgr=*caloMgrHandle;
111  CaloCellList cells(caloMgr, cellsCont.ptr() );
112 
113  std::function<double(const CaloCell*)> calcDelta;
114  if (m_axis){
115  calcDelta = [&rawConf, &seed](const CaloCell* cell){
116  return CaloPhiRange::diff(seed.phi(), cell->phi())/rawConf.phiWidth;
117  };
118  } else {
119  calcDelta = [&rawConf, &seed](const CaloCell* cell){
120  return (seed.eta() - cell->eta())/rawConf.etaWidth;
121  };
122  }
123  // loop over cells
124  for ( const int layer : rawConf.layers) {
125  cells.select(seed.eta(), seed.phi(), m_cellMaxDEtaDist, m_cellMaxDPhiDist, layer );
126  for ( const CaloCell *cell : cells ) {
127  float deltaPhi = CaloPhiRange::diff(cell->phi(), seed.phi());
128  bool phiPositive = deltaPhi > 0;
129  const auto delta = calcDelta( cell );
130  int idx =copysign(static_cast<int>(std::floor( delta + .5)),delta);
131  unsigned int stripIdx(0);
132 
133  if(!phiPositive){
134  stripIdx = midPoint - (idx*2);
135  if (stripIdx>100000){stripIdx = 0;}
136  }else{
137  stripIdx = midPoint - (idx*2 + 1);
138  if (stripIdx>100000){stripIdx = 0;}
139  }
140  if ( stripIdx < nStrips ){
142  rs->at(stripIdx) += cell->energy()/std::cosh(cell->eta());
143  }else{
144  rs->at(stripIdx) += cell->energy();
145  }
146  }
147  }
148  }
149  return StatusCode::SUCCESS;
150 }
151 
152 }
153 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Ringer::CaloStripsRingsBuilder::m_doPhiAxesDivision
bool m_doPhiAxesDivision
This can be set True to divide in two the phi axes.
Definition: CaloStripsRingsBuilder.h:75
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
Ringer::CaloStripsRingsBuilder::finalize
virtual StatusCode finalize() override
finalize method
Definition: CaloStripsRingsBuilder.cxx:89
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
CaloStripsRingsBuilder.h
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::CaloRingsBuilder::m_cellMaxDPhiDist
Gaudi::Property< float > m_cellMaxDPhiDist
Maximum cell distance in phi to seed.
Definition: CaloRingsBuilder.h:191
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
Ringer::CaloStripsRingsBuilder::initialize
virtual StatusCode initialize() override
Tool main methods:
Definition: CaloStripsRingsBuilder.cxx:42
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloCellList.h
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:160
Ringer::CaloStripsRingsBuilder::m_doTransverseEnergy
bool m_doTransverseEnergy
Definition: CaloStripsRingsBuilder.h:77
Ringer::CaloStripsRingsBuilder::CaloStripsRingsBuilder
CaloStripsRingsBuilder(const std::string &type, const std::string &name, const IInterface *parent)
Default constructor.
Definition: CaloStripsRingsBuilder.cxx:26
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
Ringer::CaloStripsRingsBuilder::m_axis
std::size_t m_axis
Tool props (python configurables):
Definition: CaloStripsRingsBuilder.h:64
xAOD::RingSetConf_v1::whichLayer
static Ringer::CalJointLayer whichLayer(const std::vector< CaloSampling::CaloSample > &layers)
Definition: RingSetConf_v1.cxx:188
CaloRingsAuxContainer.h
CaloRingsContainer.h
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
CaloCluster.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
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
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
Ringer::CaloStripsRingsBuilder::buildRingSet
virtual StatusCode buildRingSet(const xAOD::RingSetConf::RawConf &rawConf, const AtlasGeoPoint &seed, xAOD::RingSet *rs) override
main method where the strips are build
Definition: CaloStripsRingsBuilder.cxx:95
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
RingSetContainer.h
MuonGM::nStrips
int nStrips(const MuonGM::TgcReadoutElement &readoutEle, int layer)
Definition: MuonDetDescr/MuonGeoModelTest/src/GeoModelTgcTest.cxx:46
RingSetConf.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
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
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
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
AtlasGeoPoint
Definition: AtlasGeoPoint.h:15
xAOD::RingSetConf_v1::RawConf
Definition: RingSetConf_v1.h:49
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
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
Ringer::CaloStripsRingsBuilder::m_doEtaAxesDivision
bool m_doEtaAxesDivision
This can be set True to divide in two the eta axes.
Definition: CaloStripsRingsBuilder.h:71
Ringer::CaloStripsRingsBuilder::~CaloStripsRingsBuilder
~CaloStripsRingsBuilder()
Destructor.
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