ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterCellMonAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "CaloDetDescr/CaloDetDescrElement.h"
10#include "Identifier/Identifier.h"
15
16#include <algorithm>
17
18
19
22
23 ATH_MSG_DEBUG("CaloClusterCellMonAlg::initialize() start");
24
25 // Initialize superclass
27
28 ATH_CHECK(detStore()->retrieve(m_onlineID, "LArOnlineID"));
29 ATH_CHECK( m_caloMgrKey.initialize() );
30 ATH_CHECK( m_cablingKey.initialize() );
31 ATH_CHECK( m_clusterContainerKey.initialize() );
32
33 //JobO consistency check:
34 if (m_useTrigger && std::all_of(m_triggerNames.begin(),m_triggerNames.end(),[](const std::string& trigName){return trigName.empty();})) {
35 ATH_MSG_WARNING("UseTrigger set to true but no trigger names given! Forcing useTrigger to false");
36 m_useTrigger=false;
37 }
38
39 ATH_MSG_DEBUG("CaloClusterCellMonAlg::initialize() is done!");
40
41 return StatusCode::SUCCESS;
42}
43
44
46
47 auto mon_trig = Monitored::Scalar<float>("trigType",-1);
48 mon_trig=0.5;
49 fill(m_MonGroupName,mon_trig);
50
51 const ToolHandle<Trig::TrigDecisionTool>& trigTool = getTrigDecisionTool();
52 if (m_useTrigger && !trigTool.empty()) {
53 for (unsigned i=0;i<m_triggerNames.size();++i) {
54 const std::string& chainName=m_triggerNames[i];
55 if(!chainName.empty()) {
56 const Trig::ChainGroup* cg = trigTool->getChainGroup(chainName);
57 if(cg->isPassed()) {
58 mon_trig=0.5+i;
59 fill(m_MonGroupName,mon_trig);
60 }
61 }
62 }//end of loop over trigger types
63
64 } //end if trigger used
65 else {
66 mon_trig=6.5;
67 fill(m_MonGroupName,mon_trig);
68 }
69}
70
71
72
73
75StatusCode CaloClusterCellMonAlg::fillHistograms(const EventContext& ctx) const{
76
77 ATH_MSG_DEBUG("CaloClusterCellMonAlg::fillHistograms() starts");
78
80 ATH_CHECK(caloMgrHandle.isValid());
81 const CaloDetDescrManager* caloDDMgr = *caloMgrHandle;
82
84 const LArOnOffIdMapping* cabling{*cablingHdl};
85
87
88 bool ifPass = true;
89 bool passBeamBackgroundRemoval = true;
90 ATH_CHECK(checkFilters(ifPass,passBeamBackgroundRemoval,m_MonGroupName,ctx)); //Check ATLAS-Ready, beam-background, etc from base class
91 if(!ifPass) return StatusCode::SUCCESS;
92
93 auto eventCounter = Monitored::Scalar<size_t>("eventCounter",0);
94 fill(m_MonGroupName,eventCounter);
95
97
98 IdentifierHash larCellMin, larCellMax;
99 m_calo_id->calo_cell_hash_range(CaloCell_ID::LARFCAL, larCellMin,larCellMax); // hash-end of FCAL is also the hash-end of LAr
100 std::vector<unsigned> hitMap(m_calo_id->calo_cell_hash_max(), 0);
101 std::vector<std::pair<IdentifierHash, float> > clusteredCells;
102 for (const xAOD::CaloCluster* cluster : *clusterHdl) {
103 if (cluster->e() < m_clusterECut)
104 continue;
105 // Loop over cells in cluster:
106 auto cellIt = cluster->cell_begin();
107 auto cellIt_e = cluster->cell_end();
108 clusteredCells.clear();
109 clusteredCells.reserve(cluster->size());
110 for (; cellIt != cellIt_e; ++cellIt) {
111 const IdentifierHash hash = cellIt->caloDDE()->calo_hash();
112 if (hash < hitMap.size()) {
113 const float cellE = cellIt->energy();
114 clusteredCells.emplace_back(std::make_pair(hash, cellE));
115 }
116 } // end loop over cells in cluster
117 // Sort & filter list of cells in this cluster if needed:
118 if (m_nCellsPerCluster > 0 && m_nCellsPerCluster < clusteredCells.size()) {
119 auto middle = clusteredCells.begin() + m_nCellsPerCluster;
120 // sort per cell energy
121 std::partial_sort(clusteredCells.begin(), middle, clusteredCells.end(),
122 [](const std::pair<IdentifierHash, float>& p1,
123 const std::pair<IdentifierHash, float>& p2) {
124 return (p1.second > p2.second);
125 });
126 // Shrink container to required cells
127 clusteredCells.resize(m_nCellsPerCluster);
128 } // end if m_nClusteredCells>0
129 for (const auto& cc : clusteredCells) {
130 ++hitMap[cc.first];
131 } // end loop over clusteredCells
132 } // end loop over clusteres
133
134 for (const CaloDetDescrElement* caloDDE : caloDDMgr->element_range()) {
135 const IdentifierHash h=caloDDE->calo_hash();
136 if (h<hitMap.size() && hitMap[h]) {
137 float celleta, cellphi;
138 unsigned iLyr, iLyrNS;
139 std::string layerName;
140 if (h<larCellMax) {
141 //LAr Cells
142 getHistoCoordinates(caloDDE, celleta, cellphi, iLyr, iLyrNS);
143 layerName=m_layerNames[iLyr];
144 const HWIdentifier chid=cabling->createSignalChannelID(caloDDE->identify());
145 const IdentifierHash onlHash=m_onlineID->channel_Hash(chid);
146 auto mon_id = Monitored::Scalar<unsigned>("larhash",onlHash);
147 fill(m_MonGroupName,mon_id);
148 }
149 else {
150 //Tile cells
151 celleta=caloDDE->eta_raw();
152 cellphi=caloDDE->phi_raw();
153 iLyr=caloDDE->getSampling();
154 if (iLyr<12 || iLyr>20 ) {
155 ATH_MSG_ERROR("Unexpected tile sampling " << iLyr);
156 return StatusCode::FAILURE;
157 }
158 layerName=m_tileNames[iLyr-12];
159 layerName += (celleta>0) ? "A" : "C";
160 auto mon_tileOnl = Monitored::Scalar<unsigned>("tilehash",caloDDE->onl1());
161 fill(m_MonGroupName,mon_tileOnl);
162 //Fill also hash of second Tile PMT (if present):
163 if (caloDDE->onl2() != 64000) {
164 mon_tileOnl=caloDDE->onl2();
165 fill(m_MonGroupName,mon_tileOnl);
166 }
167 }
168 auto mon_eta = Monitored::Scalar<float>("celleta_"+layerName,celleta);
169 auto mon_phi = Monitored::Scalar<float>("cellphi_"+layerName,cellphi);
170 auto mon_hit = Monitored::Scalar<unsigned>("NClusteredCells_"+layerName,hitMap[h]);
171
172
173
174 fill(m_MonGroupName,mon_eta,mon_phi,mon_hit);
175 }//end if cell used in a cluster
176 }
177 return StatusCode::SUCCESS;
178}
179
180
181
182
183
184
#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...
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
virtual StatusCode initialize() override
initialize
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)