ATLAS Offline Software
HIEventShapeFillerTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include <CaloEvent/CaloCell.h>
12 
13 #include <iostream>
14 #include <iomanip>
15 
16 HIEventShapeFillerTool::HIEventShapeFillerTool(const std::string& myname) : asg::AsgTool(myname),
17 m_index(nullptr)
18 {
19 }
20 
21 
23 {
25  return StatusCode::SUCCESS;
26 }
27 
28 
29 StatusCode HIEventShapeFillerTool::initializeEventShapeContainer(std::unique_ptr<xAOD::HIEventShapeContainer>& evtShape) const
30 {
31  //use tool to initialize event shape object
33  return StatusCode::SUCCESS;
34 }
35 
36 
37 StatusCode HIEventShapeFillerTool::fillCollectionFromTowers(std::unique_ptr<xAOD::HIEventShapeContainer>& evtShape, const SG::ReadHandleKey<xAOD::CaloClusterContainer>& tower_container_key, const SG::ReadHandleKey<INavigable4MomentumCollection>& navi_container_key, const EventContext& ctx) const
38 {
39  //retrieve the tower container from store
40  if (m_useClusters)
41  {
42  SG::ReadHandle<xAOD::CaloClusterContainer> readHandleCaloClus(tower_container_key, ctx);
43  ATH_CHECK(readHandleCaloClus.isValid());
44  return fillCollectionFromClusterContainer(evtShape, readHandleCaloClus.cptr(),ctx);
45  }
46  SG::ReadHandle<INavigable4MomentumCollection> readHandleINav(navi_container_key, ctx);
47  ATH_CHECK(readHandleINav.isValid());
48  return fillCollectionFromTowerContainer(evtShape, readHandleINav.cptr());
49 }
50 
51 
52 StatusCode HIEventShapeFillerTool::fillCollectionFromTowerContainer(std::unique_ptr<xAOD::HIEventShapeContainer>& evtShape, const INavigable4MomentumCollection* navInColl) const
53 {
54  //loop on towers
55  for (INavigable4MomentumCollection::const_iterator towerItr = navInColl->begin();
56  towerItr != navInColl->end(); ++towerItr)
57  {
58  //navigate back to cells
59  //Default is to sort the cells by either pointer values leading to irreproducible output
60  //CaloCellIDFcn ensures cells are ordered by their IDs
62  (*towerItr)->fillToken(cellToken, double(1.));
63 
64  // Use eta/phi of tower in shape calculation
65  float eta0 = (*towerItr)->eta();
66  float phi0 = (*towerItr)->phi();
67 
68  if (cellToken.size() == 0) continue;
70  cellItr != cellToken.end(); ++cellItr) updateShape(evtShape, m_index, *cellItr, cellToken.getParameter(*cellItr), eta0, phi0);
71  }//end tower loop
72  return StatusCode::SUCCESS;
73 }
74 
75 
76 StatusCode HIEventShapeFillerTool::fillCollectionFromClusterContainer(std::unique_ptr<xAOD::HIEventShapeContainer>& evtShape, const xAOD::CaloClusterContainer* theClusters, const EventContext& ctx) const
77 {
78  constexpr float area_slice = HI::TowerBins::getBinArea() * HI::TowerBins::numPhiBins();
80  for (unsigned int eb = 0; eb < HI::TowerBins::numEtaBins(); eb++)
81  {
83  evtShape->push_back(e);
84  e->setLayer(0);
85  e->setEtaMin(HI::TowerBins::getBinLowEdgeEta(eb));
86  e->setEtaMax(HI::TowerBins::getBinUpEdgeEta(eb));
87  e->etCos().assign(m_numOrders, 0);
88  e->etSin().assign(m_numOrders, 0);
89  e->setArea(area_slice);
90  e->setNCells(HI::TowerBins::numPhiBins());
91  }
92 
93 
94  std::unique_ptr<std::vector<float> > weight_vector(new std::vector<float>());
95  weight_vector->reserve(theClusters->size());
96  SG::AuxElement::Decorator< float > decorator("HIEtaPhiWeight");
97 
98  std::unique_ptr<std::vector<float> > cm_vector(new std::vector<float>());
99  cm_vector->reserve(theClusters->size());
100  SG::AuxElement::Decorator< float > cm_decorator("HIMag");
101 
102  constexpr float area_cluster = HI::TowerBins::getBinArea();
103  int runIndex = -1;
104  if(!theClusters->empty() && m_towerWeightTool)
105  {
106  runIndex = m_towerWeightTool->getRunIndex(ctx);
107  }
108 
109  for (auto cl : *theClusters)
110  {
111  double ET = cl->e() / std::cosh(cl->eta0());
112  double phi = cl->phi0();
113  double eta = cl->eta0();
114  unsigned int eb = HI::TowerBins::findBinEta(eta);
115  xAOD::HIEventShape* slice = evtShape->at(eb);
116  float weight = 1;
117  if (m_towerWeightTool)
118  {
119  float recip = m_towerWeightTool->getEtaPhiResponse(eta, phi, runIndex);
120  if (recip != 0.) weight = 1. / recip;
121  }
122  weight_vector->push_back(weight);
123  decorator(*cl) = weight;
124 
125  //HIMag back in rel 22 (removed by mistake in 21)
126  float etot2 = 0;
127  float er2 = 0;
128 
129  for (unsigned int sample = 0; sample < 24; sample++)
130  {
132  if (!cl->hasSampling(s)) continue;
133  float esamp = std::abs(cl->eSample(s));
134  float w1 = m_towerWeightTool->getWeight(eta, phi, s);
135  float wr = m_towerWeightTool->getWeightMag(eta, phi, s);
136  etot2 += esamp * w1;
137  er2 += esamp * wr;
138 
139  }
140  float cm = 0;
141  if (etot2 != 0) cm = er2 / etot2;
142  //float cm=er2/etot2;
143  cm_vector->push_back(cm);
144  cm_decorator(*cl) = cm;
145 
146  //update members
147  slice->setEt(slice->et() + weight * ET);
148  slice->setRho(slice->rho() + weight * ET / area_cluster);
149 
150  for (unsigned int i = 0; i < static_cast<unsigned int>(m_numOrders); i++)
151  {
152  float nn = i + 1;
153  float tmp_cos = slice->etCos().at(i);
154  slice->etCos()[i] = tmp_cos + weight * ET * std::cos(nn * phi);
155  float tmp_sin = slice->etSin().at(i);
156  slice->etSin()[i] = tmp_sin + weight * ET * std::sin(nn * phi);
157  }
158  }
159  ATH_MSG_DEBUG("DUMPING HIEVENTSHAPE");
160  for (auto es : *evtShape)
161  {
162  ATH_MSG_DEBUG(std::setw(10) << es->etaMin()
163  << std::setw(10) << es->etaMax()
164  << std::setw(15) << es->et() * 1e-3);
165 
166  for (unsigned int i = 0; i < static_cast<unsigned int>(m_numOrders); i++)
167  {
168  ATH_MSG_DEBUG(std::setw(40) << i
169  << std::setw(15) << es->etCos().at(i)
170  << std::setw(15) << es->etSin().at(i));
171  }
172 
173  }
174  return StatusCode::SUCCESS;
175 }
176 
177 
178 StatusCode HIEventShapeFillerTool::fillCollectionFromCells(std::unique_ptr<xAOD::HIEventShapeContainer>& evtShape, const SG::ReadHandleKey<CaloCellContainer>& cell_container_key, const EventContext& ctx) const
179 {
180  //retrieve the cell container from store
181  SG::ReadHandle<CaloCellContainer> read_handle_caloCell(cell_container_key, ctx);
182  const CaloCellContainer* CellContainer = read_handle_caloCell.get();
183  return fillCollectionFromCellContainer(evtShape, CellContainer);
184 }
185 
186 
187 StatusCode HIEventShapeFillerTool::fillCollectionFromCellContainer(std::unique_ptr<xAOD::HIEventShapeContainer>& evtShape, const CaloCellContainer* CellContainer) const
188 {
189  //loop on Cells
190  for (const auto cellItr : *CellContainer) updateShape(evtShape, m_index, cellItr, 1., cellItr->eta(), cellItr->phi());
191  return StatusCode::SUCCESS;
192 }
193 
194 
195 void HIEventShapeFillerTool::updateShape(std::unique_ptr<xAOD::HIEventShapeContainer>& shape, const HIEventShapeIndex* index, const CaloCell* theCell, float geoWeight, float eta0, float phi0, bool isNeg) const
196 {
197  float sgn = (isNeg) ? -1 : 1;
198 
199  int layer = theCell->caloDDE()->getSampling();
200  float cell_et = theCell->et();
201 
202 
203  xAOD::HIEventShape* slice = index->getShape(eta0, layer, shape);
204  //update members
205  slice->setNCells(slice->nCells() + sgn);
206  slice->setEt(slice->et() + sgn * cell_et * geoWeight);
207  float deta = theCell->caloDDE()->deta();
208  float dphi = theCell->caloDDE()->dphi();
209  float area = std::abs(deta * dphi);
210  float rho = 0;
211  if (area != 0.) rho = cell_et / area;
212  slice->setArea(slice->area() + sgn * area * geoWeight);
213  slice->setRho(slice->rho() + sgn * rho);
214 
215  for (unsigned int ih = 0; ih < slice->etCos().size(); ih++)
216  {
217  float ih_f = ih + 1;
218  float tmp_cos = slice->etCos().at(ih);
219  slice->etCos()[ih] = tmp_cos + cell_et * cos(ih_f * phi0) * geoWeight;
220 
221  float tmp_sin = slice->etSin().at(ih);
222  slice->etSin()[ih] = tmp_sin + cell_et * sin(ih_f * phi0) * geoWeight;
223  }
224 }
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
CaloDetDescrElement::deta
float deta() const
cell deta
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:356
HIEventShapeMapTool.h
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
HIEventShapeFillerTool::fillCollectionFromClusterContainer
virtual StatusCode fillCollectionFromClusterContainer(std::unique_ptr< xAOD::HIEventShapeContainer > &evtShape, const xAOD::CaloClusterContainer *theClusters, const EventContext &ctx) const
Definition: HIEventShapeFillerTool.cxx:76
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
HIEventShapeFillerTool::fillCollectionFromCells
virtual StatusCode fillCollectionFromCells(std::unique_ptr< xAOD::HIEventShapeContainer > &evtShape, const SG::ReadHandleKey< CaloCellContainer > &cell_container_key, const EventContext &ctx) const override
Definition: HIEventShapeFillerTool.cxx:178
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
index
Definition: index.py:1
HI::TowerBins::findBinEta
unsigned int findBinEta(float eta)
Definition: HIEventDefs.h:46
InDetAccessor::phi0
@ phi0
Definition: InDetAccessor.h:33
NavigationToken.h
asg
Definition: DataHandleTestTool.h:28
CaloCell.h
xAOD::HIEventShape
HIEventShape_v2 HIEventShape
Definition of the latest event info version.
Definition: HIEventShape.h:16
HIEventShapeFillerTool::m_numOrders
Gaudi::Property< int > m_numOrders
Definition: HIEventShapeFillerTool.h:47
HIEventShapeFillerTool.h
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
SG::ReadHandleKey< xAOD::CaloClusterContainer >
HIEventDefs.h
HI::TowerBins::getBinLowEdgeEta
float getBinLowEdgeEta(unsigned int eb)
Definition: HIEventDefs.h:38
HIEventShapeFillerTool::m_eventShapeMapTool
ToolHandle< IHIEventShapeMapTool > m_eventShapeMapTool
Definition: HIEventShapeFillerTool.h:45
HIEventShapeFillerTool::HIEventShapeFillerTool
HIEventShapeFillerTool(const std::string &myname)
Definition: HIEventShapeFillerTool.cxx:16
HI::TowerBins::getBinArea
constexpr float getBinArea()
Definition: HIEventDefs.h:34
HIEventShapeFillerTool::fillCollectionFromTowerContainer
virtual StatusCode fillCollectionFromTowerContainer(std::unique_ptr< xAOD::HIEventShapeContainer > &evtShape, const INavigable4MomentumCollection *navInColl) const
Definition: HIEventShapeFillerTool.cxx:52
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
HIEventShapeIndex::initializeEventShapeContainer
void initializeEventShapeContainer(std::unique_ptr< xAOD::HIEventShapeContainer > &shape_container, unsigned int num_harmonics) const
Definition: HIEventShapeIndex.cxx:207
xAOD::HIEventShape_v2
Interface class for the HI reconstruction EDM.
Definition: HIEventShape_v2.h:32
HI::TowerBins::getBinUpEdgeEta
float getBinUpEdgeEta(unsigned int eb)
Definition: HIEventDefs.h:39
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:113
perfmonmt-refit.slice
slice
Definition: perfmonmt-refit.py:52
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CaloCell::caloDDE
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition: CaloCell.h:305
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
HIEventShape.h
HI::COMPACT
@ COMPACT
Definition: HIEventDefs.h:16
CaloCell::et
virtual double et() const override final
get et
Definition: CaloCell.h:407
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
HIEventShapeFillerTool::m_index
const HIEventShapeIndex * m_index
Definition: HIEventShapeFillerTool.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
HI::TowerBins::numEtaBins
constexpr unsigned int numEtaBins()
Definition: HIEventDefs.h:19
NavigationToken::begin
const_iterator begin() const
Definition: NavigationToken.h:229
HIEventShapeFillerTool::m_useClusters
Gaudi::Property< bool > m_useClusters
Definition: HIEventShapeFillerTool.h:46
HIEventShapeFillerTool::fillCollectionFromCellContainer
virtual StatusCode fillCollectionFromCellContainer(std::unique_ptr< xAOD::HIEventShapeContainer > &evtShape, const CaloCellContainer *CellContainer) const
Definition: HIEventShapeFillerTool.cxx:187
HIEventShapeIndex
Definition: HIEventShapeIndex.h:16
NavigationToken
Definition: NavigationToken.h:50
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
HIEventShapeFillerTool::updateShape
void updateShape(std::unique_ptr< xAOD::HIEventShapeContainer > &shape, const HIEventShapeIndex *index, const CaloCell *theCell, float geoWeight, float eta0, float phi0, bool isNeg=false) const
Definition: HIEventShapeFillerTool.cxx:195
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
NavigationToken::end
const_iterator end() const
Definition: NavigationToken.h:230
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
CaloDetDescrElement::dphi
float dphi() const
cell dphi
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:358
NavigationToken::NavigationTokenIterator
Definition: NavigationToken.h:72
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloDetDescrElement::getSampling
CaloCell_ID::CaloSample getSampling() const
cell sampling
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:395
HIEventShapeFillerTool::fillCollectionFromTowers
virtual StatusCode fillCollectionFromTowers(std::unique_ptr< xAOD::HIEventShapeContainer > &evtShape, const SG::ReadHandleKey< xAOD::CaloClusterContainer > &tower_container_key, const SG::ReadHandleKey< INavigable4MomentumCollection > &navi_container_key, const EventContext &ctx) const override
Definition: HIEventShapeFillerTool.cxx:37
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
NavigationToken::getParameter
CHILDPAR getParameter(const_child_ptr data) const
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
area
double area(double R)
Definition: ConvertStaveServices.cxx:42
HIEventShapeFillerTool::m_towerWeightTool
ToolHandle< IHITowerWeightTool > m_towerWeightTool
Definition: HIEventShapeFillerTool.h:44
HIEventShapeFillerTool::initializeEventShapeContainer
virtual StatusCode initializeEventShapeContainer(std::unique_ptr< xAOD::HIEventShapeContainer > &evtShape) const override
Definition: HIEventShapeFillerTool.cxx:29
HIEventShapeFillerTool::initializeIndex
virtual StatusCode initializeIndex() override
Definition: HIEventShapeFillerTool.cxx:22
HI::TowerBins::numPhiBins
constexpr unsigned int numPhiBins()
Definition: HIEventDefs.h:22
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
NavigationToken::size
unsigned int size()
Definition: NavigationToken.h:231
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
fitman.rho
rho
Definition: fitman.py:532
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.