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 "GaudiKernel/ThreadLocalContext.h"
21#include <cstdlib>
22#include <iostream>
23#include <cmath>
24
25
26using CLHEP::GeV;
27
28
29namespace {
30
31
32bool 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() );
65 ATH_CHECK( m_caloMgrKey.initialize() );
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 {
85 float energy = Athena_test::randf_seed (m_seed, 100*GeV);
86 cells->push_back (new CaloCell (dde, energy, 0, 0, 0,
88 }
89 }
90 cells->updateCaloIterators();
91 return cells;
92}
93
94
95StatusCode
97 const CaloTowerSeg::SubSeg& subseg,
98 const CaloCellContainer* cells,
99 const CaloTowerContainer* tow0)
100{
102 CHECK( m_builder->execute (ctx, tow, cells, &subseg) );
103
104 for (size_t i = 0; i < tow->size(); i++) {
105 typedef CaloTowerContainer::index_t index_t;
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
163 const CaloCellContainer* cells = make_cells();
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}
#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 with parameters:
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
virtual StatusCode initialize() override
Standard Gaudi initialize method.
virtual StatusCode execute() 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.