ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellDumper.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#include "CaloCellDumper.h"
6#include <cmath>
7
8
9namespace {
10
11bool isEqual (double x1, double x2, double thresh = 1e-6)
12{
13 double den = std::abs(x1+x2);
14 if (den < thresh) return true;
15 double diff = std::abs (x1-x2) / den;
16 if (diff < thresh)
17 return true;
18 return false;
19}
20
21} // anonymous namespace
22
23CaloCellDumper::CaloCellDumper(const std::string & name, ISvcLocator * pSvcLocator) :
24 AthAlgorithm(name,pSvcLocator) {}
25
26
28 ATH_CHECK(m_key.initialize());
29 m_outfile.open(m_fileName,std::ios::out);
30
31 if (!m_outfile.good()) {
32 ATH_MSG_ERROR("Failed to open output text file " << m_fileName);
33 return StatusCode::FAILURE;
34 }
35
36 if (!m_refName.value().empty()) {
37 m_reffile.open(m_refName, std::ios::in);
38 if (!m_reffile.good()) {
39 ATH_MSG_ERROR("Failed to open reference file " << m_refName);
40 return StatusCode::FAILURE;
41 }
42 else {
43 ATH_MSG_INFO("Using reference file " << m_refName.value());
44 }
45 }
46
47 ATH_MSG_INFO("Cell energy cut=" << m_eCut.value());
48 return StatusCode::SUCCESS;
49}
50
51
53 m_outfile.close();
54 if (m_reffile.is_open()) {
55 m_reffile.close();
56 }
57 return StatusCode::SUCCESS;
58}
59
60
61
63
64 bool badCompare = false;
65 const EventContext& ctx = getContext();
66
68
69 const unsigned evt=ctx.eventID().event_number();
70 m_outfile << "Event " << evt << " contains " << cells->size() << " CaloCells" << std::endl;
71 m_outfile << "ID\tEnergy\tTime\tQual\tprov" << std::endl;
72
73 if (m_reffile.is_open()) {
74 std::string Event, contains, CaloCells;
75 size_t evt_in, cells_size_in;
76 m_reffile >> Event >> evt_in >> contains >> cells_size_in >> CaloCells;
77 if (!m_reffile.good() || evt_in != evt || cells_size_in != cells->size())
78 {
79 ATH_MSG_ERROR ("Reference file miscompare. Read: " <<
80 Event << " " << evt_in << " " << contains << " "
81 << cells_size_in << " " << CaloCells <<
82 "; expected event number " << evt << " and cell count " <<
83 cells->size());
84 badCompare = true;
85 }
86
87 std::string ID, Energy, Time, Qual, prov;
88 m_reffile >> ID >> Energy >> Time >> Qual >> prov;
89 if (!m_reffile.good()) {
90 ATH_MSG_ERROR ("Bad read of reference file header: " <<
91 ID << " " << Energy << " " << Time << " " <<
92 Qual << " " << prov);
93 badCompare = true;
94 }
95 }
96
97 double remainingEne=0;
98 unsigned nRemaining=0;
99
100 for (const auto *cell : *cells) {
101 if (cell->e()>m_eCut.value()) {
102 std::stringstream id;
103 if (!m_compact.value()) {
104 const CaloDetDescrElement* dde=cell->caloDDE();
105 if (dde->is_lar_em_barrel()) {
106 id << "LAr Bar";
107 }
108 else if (dde->is_lar_em_endcap_inner()){
109 id << "LAR ECI";
110 }
111 else if (dde->is_lar_em_endcap_outer()){
112 id << "LAR ECO";
113 }
114 else if (dde->is_lar_hec()) {
115 id << "LAr_HEC";
116 }
117 else if (dde->is_lar_fcal()) {
118 id << "LAr_FCAL";
119 }
120 else if (dde->is_tile()) {
121 id << "TILE ";
122 }
123 else {
124 id << "UNKNOWN";
125 }
126 id << ", samp=" << dde->getSampling() << ", ";
127 }
128
129 m_outfile << id.str() << "0x" << std::hex << cell->ID().get_identifier32().get_compact() << std::dec
130 //m_outfile <<
131 << "\t" << cell->e() << "\t" << cell->time() << "\t" << cell->gain()
132 << "\t" << cell->quality() << "\t0x" << std::hex << cell->provenance() << std::dec << std::endl;
133 if (m_reffile.is_open()) {
134 unsigned id_in;
135 float energy_in, time_in;
136 int quality_in, provenance_in, gain_in;
137 if (!m_compact) {
138 std::string id, samp;
139 m_reffile >> id >> samp;
140 }
141 m_reffile >> std::hex >> id_in >> std::dec >> energy_in >> time_in >>
142 gain_in >> quality_in >> std::hex >> provenance_in >> std::dec;
143 if (!m_reffile.good() ||
144 !isEqual (energy_in, cell->e(), 1e-5) ||
145 !isEqual (time_in, cell->time(), 1e-5) ||
146 id_in != cell->ID().get_identifier32().get_compact() ||
147 gain_in != cell->gain() ||
148 quality_in != cell->quality() ||
149 provenance_in != cell->provenance())
150 {
151 ATH_MSG_ERROR ("Bad read of reference file: " <<
152 std::hex << "0x" << id_in << " " << std::dec <<
153 energy_in << " "
154 << time_in << " " <<
155 gain_in << " " << quality_in << " " <<
156 std::hex << "0x" << provenance_in << std::dec);
157 ATH_MSG_ERROR ("Expected " << id.str() << "0x" << std::hex <<
158 cell->ID().get_identifier32().get_compact() << std::dec << " " <<
159 cell->e() << " " << cell->time() << " "
160 << cell->gain() << " " <<
161 cell->quality() << " 0x" << std::hex << cell->provenance() << std::dec);
162 badCompare = true;
163 }
164 }
165 }
166 else {//not bigger that m_eCut
167 ++nRemaining;
168 remainingEne+=cell->e();
169 }
170 }
171 if (nRemaining) {
172 m_outfile << "Sum of " << nRemaining << " cell energies: " << remainingEne << std::endl;
173 if (m_reffile.is_open()) {
174 std::string Sum, Of, Cell, Energies;
175 unsigned nRemaining_in;
176 float remainingEne_in;
177 m_reffile >> Sum >> Of >> nRemaining_in >> Cell >> Energies >>
178 remainingEne_in;
179 if (!m_reffile.good() ||
180 nRemaining_in != nRemaining ||
181 !isEqual (remainingEne_in, remainingEne))
182 {
183 ATH_MSG_ERROR ("Bad read of reference file: " <<
184 Sum << Of << nRemaining_in << Cell << Energies <<
185 remainingEne_in);
186 ATH_MSG_ERROR ("Expected: " <<
187 "Sum of " << nRemaining << " cell energies: " << remainingEne);
188 badCompare = true;
189 }
190 }
191 }
192 if (badCompare) {
193 ATH_MSG_ERROR ("Reference file miscompare");
194 return StatusCode::FAILURE;
195 }
196 return StatusCode::SUCCESS;
197}
198
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
std::vector< Identifier > ID
std::vector< double > Energy
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Property< bool > m_compact
Gaudi::Property< float > m_eCut
std::ifstream m_reffile
virtual StatusCode execute() override
Gaudi::Property< std::string > m_fileName
CaloCellDumper(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize() override
virtual StatusCode finalize() override
SG::ReadHandleKey< CaloCellContainer > m_key
Gaudi::Property< std::string > m_refName
std::ofstream m_outfile
This class groups all DetDescr information related to a CaloCell.
CaloCell_ID::CaloSample getSampling() const
cell sampling
bool is_lar_em_endcap_outer() const
cell belongs to the outer wheel of EM end cap
bool is_lar_hec() const
cell belongs to HEC
bool is_lar_em_barrel() const
cell belongs to EM barrel
bool is_lar_em_endcap_inner() const
cell belongs to the inner wheel of EM end cap
bool is_lar_fcal() const
cell belongs to FCAL
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
bool isEqual(double x1, double x2, double thresh=1e-6)
Definition FLOATassert.h:26