ATLAS Offline Software
LArFCalTowerBuilderToolTestAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
11 #undef NDEBUG
12 
15 #include "CaloEvent/CaloTowerContainer.h"
18 #include "TestTools/random.h"
19 #include "CLHEP/Units/SystemOfUnits.h"
20 #include "GaudiKernel/ThreadLocalContext.h"
21 #include <cstdlib>
22 #include <iostream>
23 #include <cmath>
24 
25 
26 using CLHEP::GeV;
27 
28 
29 namespace {
30 
31 
32 bool comp (double x1, double x2, double thresh = 1e-6)
33 {
34  double den = std::abs(x1) + std::abs(x2);
35  if (den == 0) return true;
36  double num = std::abs (x1 - x2);
37  return num / den < thresh;
38 }
39 
40 
41 } // anonymous namespace
42 
43 
48  (const std::string& name,
49  ISvcLocator* pSvcLocator)
50  : AthAlgorithm (name, pSvcLocator),
51  m_builder ("LArFCalTowerBuilderTool"),
52  m_seed (1)
53 {
54 }
55 
56 
61 {
62  m_calos.push_back (CaloCell_ID::LARFCAL);
63 
64  ATH_CHECK( m_builder.retrieve() );
66 
67  m_seg = CaloTowerSeg (100, 64, -5.0, 5.0);
68  m_builder->setTowerSeg (m_seg);
69  return StatusCode::SUCCESS;
70 }
71 
72 
75 {
78  if(!caloMgrHandle.isValid()) std::abort();
79  const CaloDetDescrManager* ddman = *caloMgrHandle;
80 
81  for (CaloCell_ID::SUBCALO subcalo : m_calos) {
82  for (const CaloDetDescrElement* dde :
83  ddman->element_range (subcalo))
84  {
86  cells->push_back (new CaloCell (dde, energy, 0, 0, 0,
88  }
89  }
90  cells->updateCaloIterators();
91  return cells;
92 }
93 
94 
97  const CaloTowerSeg::SubSeg& subseg,
98  const CaloCellContainer* cells,
99  const CaloTowerContainer* tow0)
100 {
101  CaloTowerContainer* tow = new CaloTowerContainer (subseg.segmentation());
102  CHECK( m_builder->execute (ctx, tow, cells, &subseg) );
103 
104  for (size_t i = 0; i < tow->size(); i++) {
106  index_t ieta1 = tow->getTowerEtaIndex (i);
107  index_t iphi1 = tow->getTowerPhiIndex (i);
108  index_t ieta0 = ieta1 + subseg.etamin()-1;
109  index_t iphi0 = iphi1 + subseg.phimin()-1;
110  if (iphi0 > m_seg.nphi())
111  iphi0 -= m_seg.nphi();
112  const CaloTower* t0 = tow0->getTower (ieta0, iphi0);
113  const CaloTower* t1 = tow->getTower (i);
114  if (!comp (t0->energy(), t1->energy()) ||
115  !comp (t0->eta(), t1->eta()) ||
116  !comp (t0->phi(), t1->phi()))
117  {
118  std::cout << "Energy mismatch " << i << " "
119  << ieta1 << " " << iphi1 << " "
120  << t0->eta() << " " << t0->phi() << " "
121  << t1->eta() << " " << t1->phi() << " "
122  << t0->energy() << " " << t1->energy() << "\n";
123  }
124 
125  std::vector<unsigned int> h0;
126  for (CaloTower::cell_iterator cit = t0->cell_begin();
127  cit != t0->cell_end();
128  ++cit)
129  {
130  h0.push_back ((*cit)->caloDDE()->calo_hash());
131  }
132 
133  std::vector<unsigned int> h1;
134  for (CaloTower::cell_iterator cit = t1->cell_begin();
135  cit != t1->cell_end();
136  ++cit)
137  {
138  h1.push_back ((*cit)->caloDDE()->calo_hash());
139  }
140 
141  if (h0 != h1) {
142  std::cout << "Cell list mismatch.\n";
143  for (size_t i = 0; i < h0.size(); i++)
144  std::cout << " " << h0[i];
145  std::cout << "\n";
146  for (size_t i = 0; i < h1.size(); i++)
147  std::cout << " " << h1[i];
148  std::cout << "\n";
149  }
150  }
151 
152  delete tow;
153 
154  return StatusCode::SUCCESS;
155 }
156 
157 
159 {
160  std::cout << "test1\n";
161  const EventContext& ctx = Gaudi::Hive::currentContext();
162 
165  CHECK( m_builder->execute (ctx, tow1, cells) );
166 
167 #if 0
168  std::cout << "cells\n";
169  for (size_t i = 0; i < cells->size(); i++) {
170  const CaloCell* c = (*cells)[i];
171  std::cout << i << " "
172  << (int)(c->caloDDE()->calo_hash()) << " "
173  << c->eta() << " " << c->phi() << " " << c->energy() << "\n";
174  }
175 #endif
176 
177  std::cout << "towers\n";
178  for (size_t i = 0; i < tow1->size(); i++) {
179  const CaloTower* t = (*tow1)[i];
180  std::cout << i << " "
181  << tow1->getTowerEtaIndex(i) << " "
182  << tow1->getTowerPhiIndex(i) << " "
183  << t->energy() << " ";
184  for (CaloTower::cell_iterator cit = t->cell_begin();
185  cit != t->cell_end();
186  ++cit)
187  {
188  std::cout << (*cit)->caloDDE()->calo_hash() << " ";
189  }
190  std::cout << "\n";
191  }
192 
193  CHECK( test_subseg (ctx, m_seg.subseg ( 4.5, 0.3, -0.2, 0.4), cells, tow1) );
194  CHECK( test_subseg (ctx, m_seg.subseg (-4.5, 0.3, 3.1, 0.4), cells, tow1) );
195 
196  delete cells;
197  delete tow1;
198  return StatusCode::SUCCESS;
199 }
200 
201 
206 {
207  CHECK( test1() );
208  return StatusCode::SUCCESS;
209 }
plotting.yearwise_luminosity_vs_mu.comp
comp
Definition: yearwise_luminosity_vs_mu.py:24
ICaloTowerBuilderToolBase.h
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
CaloDetDescrManager_Base::element_range
calo_element_range element_range() const
Range over element vector.
Definition: CaloDetDescrManager.cxx:123
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
CaloTowerContainer::getTower
CaloTower * getTower(index_t eta, index_t phi)
Returns a pointer to a tower with given indices.
Definition: CaloTowerContainer.cxx:266
CaloTowerSeg::SubSeg::phimin
index_t phimin() const
Lower phi index.
Definition: CaloTowerSeg.h:560
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:46
TileDCSDataPlotter.h0
h0
Definition: TileDCSDataPlotter.py:873
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
physval_make_web_display.thresh
thresh
Definition: physval_make_web_display.py:35
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
ALFA_EventTPCnv_Dict::t0
std::vector< ALFA_RawData_p1 > t0
Definition: ALFA_EventTPCnvDict.h:42
LArFCalTowerBuilderToolTestAlg::m_builder
ToolHandle< ICaloTowerBuilderToolBase > m_builder
Definition: LArFCalTowerBuilderToolTestAlg.h:62
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
LArFCalTowerBuilderToolTestAlg::m_seg
CaloTowerSeg m_seg
Definition: LArFCalTowerBuilderToolTestAlg.h:64
CaloTowerSeg::SubSeg::etamin
index_t etamin() const
Lower eta index.
Definition: CaloTowerSeg.h:538
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
read_hist_ntuple.h1
h1
Definition: read_hist_ntuple.py:21
CaloTowerSeg::nphi
index_t nphi() const
Retrieve number of bins.
Definition: CaloTowerSeg.h:428
CaloTowerContainer
Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current CaloTowerContainer
Definition: CaloTPCnv.cxx:68
RunTileCalibRec.CaloCellContainer
CaloCellContainer
Definition: RunTileCalibRec.py:403
CaloTowerSeg::SubSeg
A rectangular window within the segmentation.
Definition: CaloTowerSeg.h:220
random.h
Very simple random numbers for regression testing.
CaloTowerContainer
Storable container class for CaloTower.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:77
LArFCalTowerBuilderToolTestAlg.h
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
CaloTower::cell_iterator
CaloEnergyCluster::cell_iterator cell_iterator
Iterator on CaloCell s.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTower.h:94
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CaloCell_Base_ID::SUBCALO
SUBCALO
enumeration of sub calorimeters
Definition: CaloCell_Base_ID.h:46
LArFCalTowerBuilderToolTestAlg::make_cells
CaloCellContainer * make_cells()
Definition: LArFCalTowerBuilderToolTestAlg.cxx:74
LArFCalTowerBuilderToolTestAlg::execute
virtual StatusCode execute() override
Standard Gaudi execute method.
Definition: LArFCalTowerBuilderToolTestAlg.cxx:205
CaloTowerContainer::getTowerEtaIndex
index_t getTowerEtaIndex(const CaloTower *aTower) const
Returns the index for a given tower.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:616
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AthAlgorithm
Definition: AthAlgorithm.h:47
LArFCalTowerBuilderToolTestAlg::m_calos
std::vector< CaloCell_ID::SUBCALO > m_calos
Definition: LArFCalTowerBuilderToolTestAlg.h:63
MVAUtils::index_t
int32_t index_t
The index type of the node in the vector.
Definition: MVAUtilsDefs.h:12
CaloTower
Data class for calorimeter cell towers.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTower.h:55
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
LArFCalTowerBuilderToolTestAlg::initialize
virtual StatusCode initialize() override
Standard Gaudi initialize method.
Definition: LArFCalTowerBuilderToolTestAlg.cxx:60
LArFCalTowerBuilderToolTestAlg::LArFCalTowerBuilderToolTestAlg
LArFCalTowerBuilderToolTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: LArFCalTowerBuilderToolTestAlg.cxx:48
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
LArFCalTowerBuilderToolTestAlg::m_seed
uint32_t m_seed
Definition: LArFCalTowerBuilderToolTestAlg.h:65
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
CaloTowerSeg::SubSeg::segmentation
CaloTowerSeg segmentation() const
Return a new segmentation object corresponding to this window.
Definition: CaloTowerSeg.cxx:85
CaloTowerContainer::index_t
size_t index_t
Tower map index type.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:82
CaloGain::LARMEDIUMGAIN
@ LARMEDIUMGAIN
Definition: CaloGain.h:18
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
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
CaloTowerSeg
Data object stores CaloTower segmentation.
Definition: CaloTowerSeg.h:37
CaloTowerContainer::getTowerPhiIndex
index_t getTowerPhiIndex(const CaloTower *aTower) const
Returns the index for a given tower.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloTowerContainer.h:633
LArFCalTowerBuilderToolTestAlg::test1
StatusCode test1()
Definition: LArFCalTowerBuilderToolTestAlg.cxx:158
LArFCalTowerBuilderToolTestAlg::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: LArFCalTowerBuilderToolTestAlg.h:66
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
python.compressB64.c
def c
Definition: compressB64.py:93
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
LArFCalTowerBuilderToolTestAlg::test_subseg
StatusCode test_subseg(const EventContext &ctx, const CaloTowerSeg::SubSeg &subseg, const CaloCellContainer *cells, const CaloTowerContainer *tow0)
Definition: LArFCalTowerBuilderToolTestAlg.cxx:96
Athena_test::randf_seed
float randf_seed(uint32_t &seed, float rmax, float rmin=0)
Generate a floating-point random number between rmin and rmax.
Definition: random.h:53
CaloTowerSeg::subseg
SubSeg subseg(double eta, double deta, double phi, double dphi) const
Return a window within the current segmentation.
Definition: CaloTowerSeg.cxx:23