ATLAS Offline Software
Loading...
Searching...
No Matches
ClusterDumper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Gaudi/Athena include(s):
7
10
11// Local include(s):
12#include "ClusterDumper.h"
13
15 ATH_MSG_INFO( "Initializing" );
16
17 std::lock_guard<std::mutex> fileLock{m_fileMutex};
18 if (!m_fileName.empty()) {
20 if (m_fileOut.is_open()) {
22 ATH_MSG_INFO("Writing to file " << m_fileName);
23 }
24 else {
25 msg(MSG::ERROR) << "Failed to open file " << m_fileName << endmsg;
26 return StatusCode::FAILURE;
27 }
28 }
29 else {
30 ATH_MSG_INFO("Writing to stdout");
31 }
32
33 ATH_CHECK(m_eventInfoKey.initialize());
34 ATH_CHECK(m_containerName.initialize());
35 return StatusCode::SUCCESS;
36}
37
38
40 if (m_fileOut.is_open()) {
41 m_fileOut.close();
42 }
43 return StatusCode::SUCCESS;
44}
45
48 ATH_MSG_DEBUG( "Retrieved clusters with key: " << m_containerName.key() );
49
50 const CaloClusterCellLinkContainer* cclptr=nullptr;
52 CHECK(evtStore()->retrieve(cclptr,m_containerName.key()+"_links"));
53 ATH_MSG_INFO("Found corresponding cell-link container with size " << cclptr->size());
54 }
55 else
56 ATH_MSG_INFO("Did not find corresponding cell-link container");
57
58 std::lock_guard<std::mutex> fileLock{m_fileMutex};
60 (*m_out) << "Run " << eventInfo->runNumber() << ", evt " << eventInfo->eventNumber() << " contains " << clustercontainer->size() << " CaloClusters" << std::endl;
61
62 for (const auto itr: *clustercontainer) {
63 const xAOD::CaloCluster& cluster=*itr;
64 (*m_out) << "Kinematics :" << std::endl;
66 *m_out << std::format ("E={:.0f}, eta={}, phi={}, m={}, pt={:.1f}",
67 cluster.e(), cluster.eta(), cluster.phi(),
68 cluster.m(), cluster.pt())
69 << std::endl;
70 }
71 else {
72 *m_out << std::format ("E={}, eta={}, phi={}, m={}, pt={}",
73 cluster.e(), cluster.eta(), cluster.phi(),
74 cluster.m(), cluster.pt())
75 << std::endl;
76 }
77 (*m_out) << "Eta0=" << cluster.eta0() << ", Phi0=" << cluster.phi0() << std::endl;
78
79 (*m_out) << "TLorentzVector :" << std::endl;
80 const xAOD::CaloCluster::FourMom_t& p4=cluster.p4();
82 double mass = p4.M();
83 if (std::abs(mass) < 1e-2) mass = 0;
84 *m_out << std::format (" p4.E={:.0f}, x={:.0f}, y={:.0f}, z={:.0f}, m={:.2f}, pt={:.1f}",
85 p4.E(), p4.X(), p4.Y(), p4.Z(), mass, p4.Pt())
86 << std::endl;
87 }
88 else {
89 *m_out << std::format (" p4.E={}, x={}, y={}, z={}, m={}, pt={}",
90 p4.E(), p4.X(), p4.Y(), p4.Z(), p4.M(), p4.Pt())
91 << std::endl;
92 }
93
94 (*m_out) << "Sampling variables :" << std::endl;
95 for (unsigned iSamp=0;iSamp<CaloSampling::Unknown;++iSamp) {
97 if (cluster.hasSampling(s)) {
98 (*m_out) << " Sampling #" << s << ": E=" << cluster.eSample(s) << ", eta=" << cluster.etaSample(s) << ", phi=" << cluster.phiSample(s) << std::endl;
99 }
100 }
101
102
103
104 //(*m_out) << "Auxiliary variables: " << std::endl;
105 // const SG::auxid_set_t& auxIds=cluster.container()->getAuxIDs(); //->getDynamicAuxIDs();
106 // const size_t idx= cluster.index();
107 // for (auto ai: auxIds) {
108 // const std::string& auxName=SG::AuxTypeRegistry::instance().getName(ai);
109 // const std::type_info* ti=SG::AuxTypeRegistry::instance().getType (ai);
110 // if ((*ti)==typeid(float)) {
111 // const float v=clustercontainer->getData<float>(ai,idx);
112 // (*m_out) << " Index=" <<idx << ", Auxid=" << ai << ", Name=" << auxName << " value=" << v << std::endl;
113 // }
114 // else
115 // (*m_out) << " Index=" <<idx << ", Auxid=" << ai << ", Name=" << auxName << ", unknown type" << ti->name() << std::endl;
116 // }
117
118 constexpr auto allMoments=std::to_array<const char*>({"FIRST_PHI","FIRST_ETA","SECOND_R","SECOND_LAMBDA","DELTA_PHI","DELTA_THETA","DELTA_ALPHA","CENTER_X","CENTER_Y","CENTER_Z","CENTER_MAG","CENTER_LAMBDA","LATERAL","LONGITUDINAL","ENG_FRAC_EM","ENG_FRAC_MAX","ENG_FRAC_CORE","FIRST_ENG_DENS","SECOND_ENG_DENS","ISOLATION","ENG_BAD_CELLS","N_BAD_CELLS","N_BAD_CELLS_CORR","BAD_CELLS_CORR_E","BADLARQ_FRAC","ENG_POS","SIGNIFICANCE.3","CELL_SIGNIFICANCE.3","CELL_SIG_SAMPLING","AVG_LAR_Q","AVG_TILE_Q","EM_PROBABILITY","HAD_WEIGHT","OOC_WEIGHT","DM_WEIGHT.3","TILE_CONFIDENCE_LEVEL","VERTEX_FRACTION","NVERTEX_FRACTION","ENG_CALIB_TOT","ENG_CALIB_OUT_L","ENG_CALIB_OUT_M","ENG_CALIB_OUT_T","ENG_CALIB_DEAD_L","ENG_CALIB_DEAD_M","ENG_CALIB_DEAD_T","ENG_CALIB_EMB0","ENG_CALIB_EME0","ENG_CALIB_TILEG3","ENG_CALIB_DEAD_TOT","ENG_CALIB_DEAD_EMB0","ENG_CALIB_DEAD_TILE0","ENG_CALIB_DEAD_TILEG3","ENG_CALIB_DEAD_EME0","ENG_CALIB_DEAD_HEC0","ENG_CALIB_DEAD_FCAL","ENG_CALIB_DEAD_LEAKAGE","ENG_CALIB_DEAD_UNCLASS","ENG_CALIB_FRAC_EM","ENG_CALIB_FRAC_HAD","ENG_CALIB_FRAC_REST", "ENERGY_Truth"});
119 (*m_out) << "Cluster Moments\n";
120 static const std::string badChannelListStr{"BadChannelList"};
121 for (std::string momName : allMoments) {
122 int precision = 0;
123 std::string::size_type dpos = momName.find ('.');
124 if (dpos != std::string::npos) {
125 precision = std::stoi (momName.substr (dpos+1));
126 momName.erase (dpos, std::string::npos);
127 }
128 SG::AuxElement::Accessor<float> a(momName);
129 if (a.isAvailable(cluster)) {
130 float v = a(cluster);
131 if (m_reducedPrecision && precision > 0) {
132 *m_out << std::format (" {}: {:.{}f}", momName, v, precision) << "\n";
133 }
134 else {
135 (*m_out) << " " << momName << ": " << v << "\n";
136 }
137 }
138 }
139
140 SG::AuxElement::Accessor<xAOD::CaloClusterBadChannelList> a(badChannelListStr);
141 if (a.isAvailable(cluster)) {
142 (*m_out) << "Bad Channel data: \n";
143 for (const auto& bc : cluster.badChannelList()) {
144 (*m_out) << " eta=" << bc.eta() << ", phi=" << bc.phi() << ", layer=" << bc.layer() << ", word=" << bc.badChannel() << "\n";
145 }
146 }
147
148 const CaloClusterCellLink* cellLinks = cluster.getCellLinks();
149 if (cellLinks) {
150 if (m_printCellLinks) {
151 (*m_out) << "Cell-links:\n";
152 CaloClusterCellLink::const_iterator lnk_it = cellLinks->begin();
153 CaloClusterCellLink::const_iterator lnk_it_e = cellLinks->end();
154 for (; lnk_it != lnk_it_e; ++lnk_it) {
155 const CaloCell* cell = *lnk_it;
156 if (m_reducedPrecision) {
157 *m_out << std::format (" ID={}, E={:.2f}, weight={:.3f}\n",
158 cell->ID().getString(), cell->e(), lnk_it.weight());
159
160 }
161 else {
162 *m_out << std::format (" ID={}, E={}, weight={}\n",
163 cell->ID().getString(), cell->e(), lnk_it.weight());
164
165 }
166 }
167 } else
168 (*m_out) << " Nbr of cells: " << cellLinks->size() << "\n";
169 } else {
170 (*m_out) << " No Cell Links found\n";
171 }
172
173 }//end loop over clusters
174
175 return StatusCode::SUCCESS;
176}
177
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
static Double_t a
MsgStream & msg() const
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
std::ofstream m_fileOut
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_containerName
The key for the output xAOD::CaloClusterContainer.
Gaudi::Property< bool > m_reducedPrecision
virtual StatusCode finalize()
virtual StatusCode initialize()
Function initialising the algorithm.
std::mutex m_fileMutex
Gaudi::Property< bool > m_printCellLinks
std::ostream * m_out
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
Gaudi::Property< std::string > m_fileName
virtual StatusCode execute()
Function executing the algorithm.
size_type size() const noexcept
Returns the number of elements in the collection.
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version).
virtual double pt() const
The transverse momentum ( ) of the particle (negative for negative-energy clusters).
float phiSample(const CaloSample sampling) const
Retrieve barycenter in a given sample.
virtual double m() const
The invariant mass of the particle.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double e() const
The total energy of the particle.
float eSample(const CaloSample sampling) const
virtual double phi() const
The azimuthal angle ( ) of the particle.
float etaSample(const CaloSample sampling) const
Retrieve barycenter in a given sample.
flt_t eta0() const
Returns raw of cluster seed.
virtual FourMom_t p4() const
The full 4-momentum of the particle.
IParticle::FourMom_t FourMom_t
Definition of the 4-momentum type.
CaloSampling::CaloSample CaloSample
bool hasSampling(const CaloSample s) const
Checks if certain smapling contributes to cluster.
const CaloClusterBadChannelList & badChannelList() const
flt_t phi0() const
Returns raw of cluster seed.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.