ATLAS Offline Software
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 
9 namespace {
10 
11 bool 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 
23 CaloCellDumper::CaloCellDumper(const std::string & name, ISvcLocator * pSvcLocator) :
24  AthAlgorithm(name,pSvcLocator) {}
25 
26 
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 
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
CaloCellDumper::m_refName
Gaudi::Property< std::string > m_refName
Definition: CaloCellDumper.h:30
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
CaloCellDumper::CaloCellDumper
CaloCellDumper(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CaloCellDumper.cxx:23
CaloCellDumper::m_reffile
std::ifstream m_reffile
Definition: CaloCellDumper.h:27
CaloDetDescrElement::is_lar_em_endcap_inner
bool is_lar_em_endcap_inner() const
cell belongs to the inner wheel of EM end cap
Definition: CaloDetDescrElement.cxx:114
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
CaloDetDescrElement::is_lar_em_endcap_outer
bool is_lar_em_endcap_outer() const
cell belongs to the outer wheel of EM end cap
Definition: CaloDetDescrElement.cxx:122
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
physval_make_web_display.thresh
thresh
Definition: physval_make_web_display.py:36
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
Energy
std::vector< double > Energy
Definition: CalibHitToCaloCell.h:23
makePlot.Energies
Energies
Definition: makePlot.py:24
Event
Definition: trigbs_orderedMerge.cxx:42
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
JiveXML::Event
struct Event_t Event
Definition: ONCRPCServer.h:65
CaloCellDumper::m_key
SG::ReadHandleKey< CaloCellContainer > m_key
Definition: CaloCellDumper.h:28
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
CaloCellDumper::m_eCut
Gaudi::Property< float > m_eCut
Definition: CaloCellDumper.h:31
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
CaloCellDumper::m_compact
Gaudi::Property< bool > m_compact
Definition: CaloCellDumper.h:32
AthExHiveOpts.Time
Time
Definition: AthExHiveOpts.py:63
CaloCellDumper::execute
virtual StatusCode execute() override
Definition: CaloCellDumper.cxx:62
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloCellDumper::finalize
virtual StatusCode finalize() override
Definition: CaloCellDumper.cxx:52
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Athena_test::isEqual
bool isEqual(double x1, double x2, double thresh=1e-6)
Definition: FLOATassert.h:26
contains
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition: hcg.cxx:111
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
CaloDetDescrElement::is_lar_fcal
bool is_lar_fcal() const
cell belongs to FCAL
Definition: CaloDetDescrElement.cxx:138
AthAlgorithm
Definition: AthAlgorithm.h:47
CaloDetDescrElement::is_tile
bool is_tile() const
cell belongs to Tile
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:442
MonDataType::Energy
@ Energy
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CaloCellDumper::m_outfile
std::ofstream m_outfile
Definition: CaloCellDumper.h:26
CaloDetDescrElement::is_lar_em_barrel
bool is_lar_em_barrel() const
cell belongs to EM barrel
Definition: CaloDetDescrElement.cxx:98
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
CaloDetDescrElement::getSampling
CaloCell_ID::CaloSample getSampling() const
cell sampling
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:395
CaloCellDumper::m_fileName
Gaudi::Property< std::string > m_fileName
Definition: CaloCellDumper.h:29
CaloDetDescrElement::is_lar_hec
bool is_lar_hec() const
cell belongs to HEC
Definition: CaloDetDescrElement.cxx:130
CaloCellDumper.h
CaloCellDumper::initialize
virtual StatusCode initialize() override
Definition: CaloCellDumper.cxx:27