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
62StatusCode CaloCellDumper::execute(const EventContext& ctx) {
63
64 bool badCompare = false;
65
67
68 const unsigned evt=ctx.eventID().event_number();
69 m_outfile << "Event " << evt << " contains " << cells->size() << " CaloCells" << std::endl;
70 m_outfile << "ID\tEnergy\tTime\tQual\tprov" << std::endl;
71
72 if (m_reffile.is_open()) {
73 std::string Event, contains, CaloCells;
74 size_t evt_in, cells_size_in;
75 m_reffile >> Event >> evt_in >> contains >> cells_size_in >> CaloCells;
76 if (!m_reffile.good() || evt_in != evt || cells_size_in != cells->size())
77 {
78 ATH_MSG_ERROR ("Reference file miscompare. Read: " <<
79 Event << " " << evt_in << " " << contains << " "
80 << cells_size_in << " " << CaloCells <<
81 "; expected event number " << evt << " and cell count " <<
82 cells->size());
83 badCompare = true;
84 }
85
86 std::string ID, Energy, Time, Qual, prov;
87 m_reffile >> ID >> Energy >> Time >> Qual >> prov;
88 if (!m_reffile.good()) {
89 ATH_MSG_ERROR ("Bad read of reference file header: " <<
90 ID << " " << Energy << " " << Time << " " <<
91 Qual << " " << prov);
92 badCompare = true;
93 }
94 }
95
96 double remainingEne=0;
97 unsigned nRemaining=0;
98
99 for (const auto *cell : *cells) {
100 if (cell->e()>m_eCut.value()) {
101 std::stringstream id;
102 if (!m_compact.value()) {
103 const CaloDetDescrElement* dde=cell->caloDDE();
104 if (dde->is_lar_em_barrel()) {
105 id << "LAr Bar";
106 }
107 else if (dde->is_lar_em_endcap_inner()){
108 id << "LAR ECI";
109 }
110 else if (dde->is_lar_em_endcap_outer()){
111 id << "LAR ECO";
112 }
113 else if (dde->is_lar_hec()) {
114 id << "LAr_HEC";
115 }
116 else if (dde->is_lar_fcal()) {
117 id << "LAr_FCAL";
118 }
119 else if (dde->is_tile()) {
120 id << "TILE ";
121 }
122 else {
123 id << "UNKNOWN";
124 }
125 id << ", samp=" << dde->getSampling() << ", ";
126 }
127
128 m_outfile << id.str() << "0x" << std::hex << cell->ID().get_identifier32().get_compact() << std::dec
129 //m_outfile <<
130 << "\t" << cell->e() << "\t" << cell->time() << "\t" << cell->gain()
131 << "\t" << cell->quality() << "\t0x" << std::hex << cell->provenance() << std::dec << std::endl;
132 if (m_reffile.is_open()) {
133 unsigned id_in;
134 float energy_in, time_in;
135 int quality_in, provenance_in, gain_in;
136 if (!m_compact) {
137 std::string id, samp;
138 m_reffile >> id >> samp;
139 }
140 m_reffile >> std::hex >> id_in >> std::dec >> energy_in >> time_in >>
141 gain_in >> quality_in >> std::hex >> provenance_in >> std::dec;
142 if (!m_reffile.good() ||
143 !isEqual (energy_in, cell->e(), 1e-5) ||
144 !isEqual (time_in, cell->time(), 1e-5) ||
145 id_in != cell->ID().get_identifier32().get_compact() ||
146 gain_in != cell->gain() ||
147 quality_in != cell->quality() ||
148 provenance_in != cell->provenance())
149 {
150 ATH_MSG_ERROR ("Bad read of reference file: " <<
151 std::hex << "0x" << id_in << " " << std::dec <<
152 energy_in << " "
153 << time_in << " " <<
154 gain_in << " " << quality_in << " " <<
155 std::hex << "0x" << provenance_in << std::dec);
156 ATH_MSG_ERROR ("Expected " << id.str() << "0x" << std::hex <<
157 cell->ID().get_identifier32().get_compact() << std::dec << " " <<
158 cell->e() << " " << cell->time() << " "
159 << cell->gain() << " " <<
160 cell->quality() << " 0x" << std::hex << cell->provenance() << std::dec);
161 badCompare = true;
162 }
163 }
164 }
165 else {//not bigger that m_eCut
166 ++nRemaining;
167 remainingEne+=cell->e();
168 }
169 }
170 if (nRemaining) {
171 m_outfile << "Sum of " << nRemaining << " cell energies: " << remainingEne << std::endl;
172 if (m_reffile.is_open()) {
173 std::string Sum, Of, Cell, Energies;
174 unsigned nRemaining_in;
175 float remainingEne_in;
176 m_reffile >> Sum >> Of >> nRemaining_in >> Cell >> Energies >>
177 remainingEne_in;
178 if (!m_reffile.good() ||
179 nRemaining_in != nRemaining ||
180 !isEqual (remainingEne_in, remainingEne))
181 {
182 ATH_MSG_ERROR ("Bad read of reference file: " <<
183 Sum << Of << nRemaining_in << Cell << Energies <<
184 remainingEne_in);
185 ATH_MSG_ERROR ("Expected: " <<
186 "Sum of " << nRemaining << " cell energies: " << remainingEne);
187 badCompare = true;
188 }
189 }
190 }
191 if (badCompare) {
192 ATH_MSG_ERROR ("Reference file miscompare");
193 return StatusCode::FAILURE;
194 }
195 return StatusCode::SUCCESS;
196}
197
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
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.
Gaudi::Property< bool > m_compact
Gaudi::Property< float > m_eCut
std::ifstream m_reffile
Gaudi::Property< std::string > m_fileName
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
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:116
bool isEqual(double x1, double x2, double thresh=1e-6)
Definition FLOATassert.h:26