ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterCellMonAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "CaloDetDescr/CaloDetDescrElement.h"
9#include "Identifier/Identifier.h"
14
15#include <algorithm>
16
17
18
21
22 ATH_MSG_DEBUG("CaloClusterCellMonAlg::initialize() start");
23
24 // Initialize superclass
26
27 ATH_CHECK(detStore()->retrieve(m_onlineID, "LArOnlineID"));
28 ATH_CHECK( m_caloMgrKey.initialize() );
29 ATH_CHECK( m_cablingKey.initialize() );
30 ATH_CHECK( m_clusterContainerKey.initialize() );
31
32 //JobO consistency check:
33 if (m_useTrigger && std::all_of(m_triggerNames.begin(),m_triggerNames.end(),[](const std::string& trigName){return trigName.empty();})) {
34 ATH_MSG_WARNING("UseTrigger set to true but no trigger names given! Forcing useTrigger to false");
35 m_useTrigger=false;
36 }
37
38 ATH_MSG_DEBUG("CaloClusterCellMonAlg::initialize() is done!");
39
40 return StatusCode::SUCCESS;
41}
42
43
45
46 auto mon_trig = Monitored::Scalar<float>("trigType",-1);
47 mon_trig=0.5;
48 fill(m_MonGroupName,mon_trig);
49
50 const ToolHandle<Trig::TrigDecisionTool>& trigTool = getTrigDecisionTool();
51 if (m_useTrigger && !trigTool.empty()) {
52 for (unsigned i=0;i<m_triggerNames.size();++i) {
53 const std::string& chainName=m_triggerNames[i];
54 if(!chainName.empty()) {
55 const Trig::ChainGroup* cg = trigTool->getChainGroup(chainName);
56 if(cg->isPassed()) {
57 mon_trig=0.5+i;
58 fill(m_MonGroupName,mon_trig);
59 }
60 }
61 }//end of loop over trigger types
62
63 } //end if trigger used
64 else {
65 mon_trig=6.5;
66 fill(m_MonGroupName,mon_trig);
67 }
68}
69
70
71
72
74StatusCode CaloClusterCellMonAlg::fillHistograms(const EventContext& ctx) const{
75
76 ATH_MSG_DEBUG("CaloClusterCellMonAlg::fillHistograms() starts");
77
79 ATH_CHECK(caloMgrHandle.isValid());
80 const CaloDetDescrManager* caloDDMgr = *caloMgrHandle;
81
83 const LArOnOffIdMapping* cabling{*cablingHdl};
84
86
87 bool ifPass = true;
88 bool passBeamBackgroundRemoval = true;
89 ATH_CHECK(checkFilters(ifPass,passBeamBackgroundRemoval,m_MonGroupName,ctx)); //Check ATLAS-Ready, beam-background, etc from base class
90 if(!ifPass) return StatusCode::SUCCESS;
91
92 auto eventCounter = Monitored::Scalar<size_t>("eventCounter",0);
93 fill(m_MonGroupName,eventCounter);
94
96
97 IdentifierHash larCellMin, larCellMax;
98 m_calo_id->calo_cell_hash_range(CaloCell_ID::LARFCAL, larCellMin,larCellMax); // hash-end of FCAL is also the hash-end of LAr
99 std::vector<unsigned> hitMap(m_calo_id->calo_cell_hash_max(), 0);
100 std::vector<std::pair<IdentifierHash, float> > clusteredCells;
101 for (const xAOD::CaloCluster* cluster : *clusterHdl) {
102 if (cluster->e() < m_clusterECut)
103 continue;
104 // Loop over cells in cluster:
105 auto cellIt = cluster->cell_begin();
106 auto cellIt_e = cluster->cell_end();
107 clusteredCells.clear();
108 clusteredCells.reserve(cluster->size());
109 for (; cellIt != cellIt_e; ++cellIt) {
110 const IdentifierHash hash = cellIt->caloDDE()->calo_hash();
111 if (hash < hitMap.size()) {
112 const float cellE = cellIt->energy();
113 clusteredCells.emplace_back(std::make_pair(hash, cellE));
114 }
115 } // end loop over cells in cluster
116 // Sort & filter list of cells in this cluster if needed:
117 if (m_nCellsPerCluster > 0 && m_nCellsPerCluster < clusteredCells.size()) {
118 auto middle = clusteredCells.begin() + m_nCellsPerCluster;
119 // sort per cell energy
120 std::partial_sort(clusteredCells.begin(), middle, clusteredCells.end(),
121 [](const std::pair<IdentifierHash, float>& p1,
122 const std::pair<IdentifierHash, float>& p2) {
123 return (p1.second > p2.second);
124 });
125 // Shrink container to required cells
126 clusteredCells.resize(m_nCellsPerCluster);
127 } // end if m_nClusteredCells>0
128 for (const auto& cc : clusteredCells) {
129 ++hitMap[cc.first];
130 } // end loop over clusteredCells
131 } // end loop over clusteres
132
133 for (const CaloDetDescrElement* caloDDE : caloDDMgr->element_range()) {
134 const IdentifierHash h=caloDDE->calo_hash();
135 if (h<hitMap.size() && hitMap[h]) {
136 float celleta, cellphi;
137 unsigned iLyr, iLyrNS;
138 std::string layerName;
139 if (h<larCellMax) {
140 //LAr Cells
141 getHistoCoordinates(caloDDE, celleta, cellphi, iLyr, iLyrNS);
142 layerName=m_layerNames[iLyr];
143 const HWIdentifier chid=cabling->createSignalChannelID(caloDDE->identify());
144 const IdentifierHash onlHash=m_onlineID->channel_Hash(chid);
145 auto mon_id = Monitored::Scalar<unsigned>("larhash",onlHash);
146 fill(m_MonGroupName,mon_id);
147 }
148 else {
149 //Tile cells
150 celleta=caloDDE->eta_raw();
151 cellphi=caloDDE->phi_raw();
152 iLyr=caloDDE->getSampling();
153 if (iLyr<12 || iLyr>20 ) {
154 ATH_MSG_ERROR("Unexpected tile sampling " << iLyr);
155 }
156 layerName=m_tileNames[iLyr-12];
157 layerName += (celleta>0) ? "A" : "C";
158 auto mon_tileOnl = Monitored::Scalar<unsigned>("tilehash",caloDDE->onl1());
159 fill(m_MonGroupName,mon_tileOnl);
160 //Fill also hash of second Tile PMT (if present):
161 if (caloDDE->onl2() != 64000) {
162 mon_tileOnl=caloDDE->onl2();
163 fill(m_MonGroupName,mon_tileOnl);
164 }
165 }
166 auto mon_eta = Monitored::Scalar<float>("celleta_"+layerName,celleta);
167 auto mon_phi = Monitored::Scalar<float>("cellphi_"+layerName,cellphi);
168 auto mon_hit = Monitored::Scalar<unsigned>("NClusteredCells_"+layerName,hitMap[h]);
169
170
171
172 fill(m_MonGroupName,mon_eta,mon_phi,mon_hit);
173 }//end if cell used in a cluster
174 }
175 return StatusCode::SUCCESS;
176}
177
178
179
180
181
182
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Definition of CaloDetDescrManager.
const ServiceHandle< StoreGateSvc > & detStore() const
Header file for AthHistogramAlgorithm.
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
Gaudi::Property< unsigned > m_nCellsPerCluster
StringArrayProperty m_layerNames
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Gaudi::Property< float > m_clusterECut
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
virtual StatusCode initialize() override final
initialize
const std::array< std::string, 9 > m_tileNames
Gaudi::Property< std::string > m_MonGroupName
const LArOnlineID * m_onlineID
virtual StatusCode fillHistograms(const EventContext &ctx) const override final
adds event to the monitoring histograms
std::array< StringProperty, NOTA > m_triggerNames
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterContainerKey
This class groups all DetDescr information related to a CaloCell.
calo_element_range element_range() const
Range over element vector.
This class provides the client interface for accessing the detector description information common to...
virtual StatusCode initialize()
initialize
StatusCode checkFilters(bool &ifPass, bool &passBeamBackgroundRemoval, const std::string &MonGroupName, const EventContext &ctx) const
void getHistoCoordinates(const CaloDetDescrElement *dde, float &celleta, float &cellphi, unsigned &iLyr, unsigned &iLyrNS) const
const CaloCell_ID * m_calo_id
This is a "hash" representation of an Identifier.
Declare a monitored scalar variable.
bool isPassed(unsigned int condition=TrigDefs::Physics) const
tells if chain group passed
void partial_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > mid, DataModel_detail::iterator< DVL > end)
Specialization of partial_sort for DataVector/List.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
void fill(H5::Group &out_file, size_t iterations)