ATLAS Offline Software
Loading...
Searching...
No Matches
LArFCalTowerBuilderToolTestAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
10
11#undef NDEBUG
12
15#include "CaloEvent/CaloTowerContainer.h"
18#include "TestTools/random.h"
19#include "CLHEP/Units/SystemOfUnits.h"
20#include <cstdlib>
21#include <iostream>
22#include <cmath>
23
24
25using CLHEP::GeV;
26
27
28namespace {
29
30
31bool comp (double x1, double x2, double thresh = 1e-6)
32{
33 double den = std::abs(x1) + std::abs(x2);
34 if (den == 0) return true;
35 double num = std::abs (x1 - x2);
36 return num / den < thresh;
37}
38
39
40} // anonymous namespace
41
42
47 (const std::string& name,
48 ISvcLocator* pSvcLocator)
49 : AthAlgorithm (name, pSvcLocator),
50 m_builder ("LArFCalTowerBuilderTool"),
51 m_seed (1)
52{
53}
54
55
60{
61 m_calos.push_back (CaloCell_ID::LARFCAL);
62
63 ATH_CHECK( m_builder.retrieve() );
64 ATH_CHECK( m_caloMgrKey.initialize() );
65
66 m_seg = CaloTowerSeg (100, 64, -5.0, 5.0);
67 m_builder->setTowerSeg (m_seg);
68 return StatusCode::SUCCESS;
69}
70
71
74{
77 if(!caloMgrHandle.isValid()) std::abort();
78 const CaloDetDescrManager* ddman = *caloMgrHandle;
79
80 for (CaloCell_ID::SUBCALO subcalo : m_calos) {
81 for (const CaloDetDescrElement* dde :
82 ddman->element_range (subcalo))
83 {
84 float energy = Athena_test::randf_seed (m_seed, 100*GeV);
85 cells->push_back (new CaloCell (dde, energy, 0, 0, 0,
87 }
88 }
89 cells->updateCaloIterators();
90 return cells;
91}
92
93
94StatusCode
96 const CaloTowerSeg::SubSeg& subseg,
97 const CaloCellContainer* cells,
98 const CaloTowerContainer* tow0)
99{
101 CHECK( m_builder->execute (ctx, tow, cells, &subseg) );
102
103 for (size_t i = 0; i < tow->size(); i++) {
104 typedef CaloTowerContainer::index_t index_t;
105 index_t ieta1 = tow->getTowerEtaIndex (i);
106 index_t iphi1 = tow->getTowerPhiIndex (i);
107 index_t ieta0 = ieta1 + subseg.etamin()-1;
108 index_t iphi0 = iphi1 + subseg.phimin()-1;
109 if (iphi0 > m_seg.nphi())
110 iphi0 -= m_seg.nphi();
111 const CaloTower* t0 = tow0->getTower (ieta0, iphi0);
112 const CaloTower* t1 = tow->getTower (i);
113 if (!comp (t0->energy(), t1->energy()) ||
114 !comp (t0->eta(), t1->eta()) ||
115 !comp (t0->phi(), t1->phi()))
116 {
117 std::cout << "Energy mismatch " << i << " "
118 << ieta1 << " " << iphi1 << " "
119 << t0->eta() << " " << t0->phi() << " "
120 << t1->eta() << " " << t1->phi() << " "
121 << t0->energy() << " " << t1->energy() << "\n";
122 }
123
124 std::vector<unsigned int> h0;
125 for (CaloTower::cell_iterator cit = t0->cell_begin();
126 cit != t0->cell_end();
127 ++cit)
128 {
129 h0.push_back ((*cit)->caloDDE()->calo_hash());
130 }
131
132 std::vector<unsigned int> h1;
133 for (CaloTower::cell_iterator cit = t1->cell_begin();
134 cit != t1->cell_end();
135 ++cit)
136 {
137 h1.push_back ((*cit)->caloDDE()->calo_hash());
138 }
139
140 if (h0 != h1) {
141 std::cout << "Cell list mismatch.\n";
142 for (size_t i = 0; i < h0.size(); i++)
143 std::cout << " " << h0[i];
144 std::cout << "\n";
145 for (size_t i = 0; i < h1.size(); i++)
146 std::cout << " " << h1[i];
147 std::cout << "\n";
148 }
149 }
150
151 delete tow;
152
153 return StatusCode::SUCCESS;
154}
155
156
157StatusCode LArFCalTowerBuilderToolTestAlg::test1(const EventContext& ctx)
158{
159 std::cout << "test1\n";
160
161 const CaloCellContainer* cells = make_cells();
163 CHECK( m_builder->execute (ctx, tow1, cells) );
164
165#if 0
166 std::cout << "cells\n";
167 for (size_t i = 0; i < cells->size(); i++) {
168 const CaloCell* c = (*cells)[i];
169 std::cout << i << " "
170 << (int)(c->caloDDE()->calo_hash()) << " "
171 << c->eta() << " " << c->phi() << " " << c->energy() << "\n";
172 }
173#endif
174
175 std::cout << "towers\n";
176 for (size_t i = 0; i < tow1->size(); i++) {
177 const CaloTower* t = (*tow1)[i];
178 std::cout << i << " "
179 << tow1->getTowerEtaIndex(i) << " "
180 << tow1->getTowerPhiIndex(i) << " "
181 << t->energy() << " ";
182 for (CaloTower::cell_iterator cit = t->cell_begin();
183 cit != t->cell_end();
184 ++cit)
185 {
186 std::cout << (*cit)->caloDDE()->calo_hash() << " ";
187 }
188 std::cout << "\n";
189 }
190
191 CHECK( test_subseg (ctx, m_seg.subseg ( 4.5, 0.3, -0.2, 0.4), cells, tow1) );
192 CHECK( test_subseg (ctx, m_seg.subseg (-4.5, 0.3, 3.1, 0.4), cells, tow1) );
193
194 delete cells;
195 delete tow1;
196 return StatusCode::SUCCESS;
197}
198
199
203StatusCode LArFCalTowerBuilderToolTestAlg::execute(const EventContext& ctx)
204{
205 CHECK( test1(ctx) );
206 return StatusCode::SUCCESS;
207}
#define ATH_CHECK
Evaluate an expression and check for errors.
Athena::TPCnvVers::Old Athena::TPCnvVers::Old Athena::TPCnvVers::Current Athena::TPCnvVers::Current CaloTowerContainer
Definition CaloTPCnv.cxx:68
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t t0
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Container class for CaloCell.
CaloCell_Base_ID::SUBCALO SUBCALO
Definition CaloCell_ID.h:50
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
This class groups all DetDescr information related to a CaloCell.
calo_element_range element_range() const
Range over element vector.
This class provides the client interface for accessing the detector description information common to...
Storable container class for CaloTower.
CaloTower * getTower(index_t eta, index_t phi)
Returns a pointer to a tower with given indices.
index_t getTowerEtaIndex(const CaloTower *aTower) const
Returns the index for a given tower.
index_t getTowerPhiIndex(const CaloTower *aTower) const
Returns the index for a given tower.
A rectangular window within the segmentation.
index_t etamin() const
Lower eta index.
index_t phimin() const
Lower phi index.
CaloTowerSeg segmentation() const
Return a new segmentation object corresponding to this window.
Data object stores CaloTower segmentation.
Data class for calorimeter cell towers.
CaloEnergyCluster::cell_iterator cell_iterator
Iterator on CaloCell s.
size_type size() const noexcept
Returns the number of elements in the collection.
ToolHandle< ICaloTowerBuilderToolBase > m_builder
StatusCode test_subseg(const EventContext &ctx, const CaloTowerSeg::SubSeg &subseg, const CaloCellContainer *cells, const CaloTowerContainer *tow0)
std::vector< CaloCell_ID::SUBCALO > m_calos
StatusCode test1(const EventContext &ctx)
virtual StatusCode initialize() override
Standard Gaudi initialize method.
virtual StatusCode execute(const EventContext &ctx) override
Standard Gaudi execute method.
LArFCalTowerBuilderToolTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
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
@ LARMEDIUMGAIN
Definition CaloGain.h:18
Very simple random numbers for regression testing.