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