ATLAS Offline Software
ClusterDumper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: ClusterDumper.cxx 767574 2016-08-11 13:52:47Z ssnyder $
6 
7 // Gaudi/Athena include(s):
9 
12 
13 // Local include(s):
14 #include "ClusterDumper.h"
15 
16 ClusterDumper::ClusterDumper( const std::string& name,
17  ISvcLocator* svcLoc )
18  : AthAlgorithm( name, svcLoc ),
19  m_out(&std::cout)
20 {
21  declareProperty( "FileName",m_fileName);
22 
23 }
24 
26  ATH_MSG_INFO( "Initializing" );
27 
28  if (!m_fileName.empty()) {
29  m_fileOut.open(m_fileName);
30  if (m_fileOut.is_open()) {
32  ATH_MSG_INFO("Writing to file " << m_fileName);
33  }
34  else {
35  msg(MSG::ERROR) << "Failed to open file " << m_fileName << endmsg;
36  return StatusCode::FAILURE;
37  }
38  }
39  else {
40  ATH_MSG_INFO("Writing to stdout");
41  }
42 
44  return StatusCode::SUCCESS;
45 }
46 
47 
49  if (m_fileOut.is_open()) {
50  m_fileOut.close();
51  }
52  return StatusCode::SUCCESS;
53 }
54 
56 
57  //const xAOD::CaloClusterContainer* clustercontainer = nullptr;
59  ATH_MSG_DEBUG( "Retrieved clusters with key: " << m_containerName.key() );
60 
61  const CaloClusterCellLinkContainer* cclptr=nullptr;
62  if (evtStore()->contains<CaloClusterCellLinkContainer>(m_containerName.key()+"_links")) {
63  CHECK(evtStore()->retrieve(cclptr,m_containerName.key()+"_links"));
64  ATH_MSG_INFO("Found corresponding cell-link container with size " << cclptr->size());
65  }
66  else
67  ATH_MSG_INFO("Did not find corresponding cell-link container");
68 
69  std::lock_guard<std::mutex> fileLock{m_fileMutex};
70  for (const auto itr: *clustercontainer) {
71  const xAOD::CaloCluster& cluster=*itr;
72  (*m_out) << "Kinematics :" << std::endl;
73  (*m_out) << "E=" << cluster.e() << ", eta=" << cluster.eta() << ", phi=" << cluster.phi() << ", m=" << cluster.m() << ", pt=" << cluster.pt() << std::endl;
74  (*m_out) << "Eta0=" << cluster.eta0() << ", Phi0=" << cluster.phi0() << std::endl;
75 
76  (*m_out) << "TLorentzVector :" << std::endl;
77  const xAOD::CaloCluster::FourMom_t& p4=cluster.p4();
78  (*m_out) << " p4.E=" << p4.E() << ", x=" << p4.X() << ", y=" << p4.Y() << ", z=" << p4.Z() << ", m=" << p4.M() << ", pt=" << p4.Pt() << std::endl;
79 
80  (*m_out) << "Sampling variables :" << std::endl;
81  for (unsigned iSamp=0;iSamp<CaloSampling::Unknown;++iSamp) {
83  if (cluster.hasSampling(s)) {
84  (*m_out) << " Sampling #" << s << ": E=" << cluster.eSample(s) << ", eta=" << cluster.etaSample(s) << ", phi=" << cluster.phiSample(s) << std::endl;
85  }
86  }
87 
88 
89 
90  //(*m_out) << "Auxiliary variables: " << std::endl;
91  // const SG::auxid_set_t& auxIds=cluster.container()->getAuxIDs(); //->getDynamicAuxIDs();
92  // const size_t idx= cluster.index();
93  // for (auto ai: auxIds) {
94  // const std::string& auxName=SG::AuxTypeRegistry::instance().getName(ai);
95  // const std::type_info* ti=SG::AuxTypeRegistry::instance().getType (ai);
96  // if ((*ti)==typeid(float)) {
97  // const float v=clustercontainer->getData<float>(ai,idx);
98  // (*m_out) << " Index=" <<idx << ", Auxid=" << ai << ", Name=" << auxName << " value=" << v << std::endl;
99  // }
100  // else
101  // (*m_out) << " Index=" <<idx << ", Auxid=" << ai << ", Name=" << auxName << ", unknown type" << ti->name() << std::endl;
102  // }
103 
104  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","CELL_SIGNIFICANCE","CELL_SIG_SAMPLING","AVG_LAR_Q","AVG_TILE_Q","EM_PROBABILITY","HAD_WEIGHT","OOC_WEIGHT","DM_WEIGHT","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"});
105  (*m_out) << "Cluster Moments" << std::endl;
106  for (const auto& momName : allMoments) {
108  if (a.isAvailable(cluster)) {
109  float v = a(cluster);
110  (*m_out) << " " << momName << ": " << v << std::endl;
111  }
112  }
113 
115  if (a.isAvailable(cluster)) {
116  (*m_out) << "Bad Channel data: " << std::endl;
117  for (const auto& bc : cluster.badChannelList()) {
118  (*m_out) << " eta=" << bc.eta() << ", phi=" << bc.phi() << ", layer=" << bc.layer() << ", word=" << bc.badChannel() << std::endl;
119  }
120  }
121 
122  (*m_out) << "Cell-links:" << std::endl;
123  const CaloClusterCellLink* cellLinks=cluster.getCellLinks();
124  if (cellLinks) {
125 // (*m_out) << " Total: " << cellLinks->size() << std::endl;
126  CaloClusterCellLink::const_iterator lnk_it=cellLinks->begin();
127  CaloClusterCellLink::const_iterator lnk_it_e=cellLinks->end();
128  for (;lnk_it!=lnk_it_e;++lnk_it) {
129  const CaloCell* cell=*lnk_it;
130  (*m_out) << " ID=" << std::hex << cell->ID() << std::dec << ", E=" << cell->e() << ", weight=" << lnk_it.weight() << std::endl;
131  }
132  }
133  else
134  (*m_out) << " No Cell Links found" << std::endl;
135 
136  }//end loop over clusters
137 
138  return StatusCode::SUCCESS;
139 }
140 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::CaloCluster_v1::phi0
flt_t phi0() const
Returns raw of cluster seed.
xAOD::CaloCluster_v1::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition: CaloCluster_v1.cxx:256
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
ClusterDumper::m_containerName
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_containerName
The key for the output xAOD::CaloClusterContainer.
Definition: ClusterDumper.h:39
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
ClusterDumper::m_fileName
std::string m_fileName
Definition: ClusterDumper.h:40
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAOD::CaloCluster_v1::m
virtual double m() const
The invariant mass of the particle.
Definition: CaloCluster_v1.cxx:261
ClusterDumper::m_out
std::ostream * m_out
Definition: ClusterDumper.h:42
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CaloClusterAuxContainer.h
xAOD::CaloCluster_v1::etaSample
float etaSample(const CaloSample sampling) const
Retrieve barycenter in a given sample.
Definition: CaloCluster_v1.cxx:532
ClusterDumper::finalize
virtual StatusCode finalize()
Definition: ClusterDumper.cxx:48
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
xAOD::CaloCluster_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: CaloCluster_v1.cxx:251
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
xAOD::CaloCluster_v1::phiSample
float phiSample(const CaloSample sampling) const
Retrieve barycenter in a given sample.
Definition: CaloCluster_v1.cxx:547
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
ClusterDumper::m_fileOut
std::ofstream m_fileOut
Definition: ClusterDumper.h:43
xAOD::CaloCluster_v1::getCellLinks
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
Definition: CaloCluster_v1.cxx:905
AthAlgorithm
Definition: AthAlgorithm.h:47
xAOD::CaloCluster_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: CaloCluster_v1.cxx:465
xAOD::CaloCluster_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle (negative for negative-energy clusters)
Definition: CaloCluster_v1.cxx:247
xAOD::CaloCluster_v1::FourMom_t
IParticle::FourMom_t FourMom_t
Definition of the 4-momentum type.
Definition: CaloCluster_v1.h:343
ClusterDumper::m_fileMutex
std::mutex m_fileMutex
Definition: ClusterDumper.h:45
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::CaloCluster_v1::badChannelList
const CaloClusterBadChannelList & badChannelList() const
Definition: CaloCluster_v1.cxx:279
errorcheck.h
Helpers for checking error return status codes and reporting errors.
ClusterDumper::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: ClusterDumper.cxx:55
python.PyAthena.v
v
Definition: PyAthena.py:157
xAOD::CaloCluster_v1::eta0
flt_t eta0() const
Returns raw of cluster seed.
xAOD::CaloCluster_v1::eSample
float eSample(const CaloSample sampling) const
Definition: CaloCluster_v1.cxx:521
a
TList * a
Definition: liststreamerinfos.cxx:10
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
CaloClusterContainer.h
ClusterDumper::ClusterDumper
ClusterDumper(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: ClusterDumper.cxx:16
ClusterDumper::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: ClusterDumper.cxx:25
xAOD::CaloCluster_v1::hasSampling
bool hasSampling(const CaloSample s) const
Checks if certain smapling contributes to cluster.
Definition: CaloCluster_v1.h:890
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::CaloCluster_v1::e
virtual double e() const
The total energy of the particle.
Definition: CaloCluster_v1.cxx:265
ClusterDumper.h