ATLAS Offline Software
CaloClusterCellMonAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "CaloDetDescr/CaloDetDescrElement.h"
9 #include "Identifier/Identifier.h"
12 
13 #include <algorithm>
14 
15 
16 
19 
20  ATH_MSG_DEBUG("CaloClusterCellMonAlg::initialize() start");
21 
22  // Initialize superclass
24 
25  ATH_CHECK(detStore()->retrieve(m_onlineID, "LArOnlineID"));
29 
30  //JobO consistency check:
31  if (m_useTrigger && std::all_of(m_triggerNames.begin(),m_triggerNames.end(),[](const std::string& trigName){return trigName.empty();})) {
32  ATH_MSG_WARNING("UseTrigger set to true but no trigger names given! Forcing useTrigger to false");
33  m_useTrigger=false;
34  }
35 
36  ATH_MSG_DEBUG("CaloClusterCellMonAlg::initialize() is done!");
37 
38  return StatusCode::SUCCESS;
39 }
40 
41 
43 
44  auto mon_trig = Monitored::Scalar<float>("trigType",-1);
45  mon_trig=0.5;
46  fill(m_MonGroupName,mon_trig);
47 
48  const ToolHandle<Trig::TrigDecisionTool>& trigTool = getTrigDecisionTool();
49  if (m_useTrigger && !trigTool.empty()) {
50  for (unsigned i=0;i<m_triggerNames.size();++i) {
51  const std::string& chainName=m_triggerNames[i];
52  if(!chainName.empty()) {
53  const Trig::ChainGroup* cg = trigTool->getChainGroup(chainName);
54  if(cg->isPassed()) {
55  mon_trig=0.5+i;
56  fill(m_MonGroupName,mon_trig);
57  }
58  }
59  }//end of loop over trigger types
60 
61  } //end if trigger used
62  else {
63  mon_trig=6.5;
64  fill(m_MonGroupName,mon_trig);
65  }
66 }
67 
68 
69 
70 
72 StatusCode CaloClusterCellMonAlg::fillHistograms(const EventContext& ctx) const{
73 
74  ATH_MSG_DEBUG("CaloClusterCellMonAlg::fillHistograms() starts");
75 
77  ATH_CHECK(caloMgrHandle.isValid());
78  const CaloDetDescrManager* caloDDMgr = *caloMgrHandle;
79 
81  const LArOnOffIdMapping* cabling{*cablingHdl};
82 
84 
85  bool ifPass = true;
86  bool passBeamBackgroundRemoval = true;
87  ATH_CHECK(checkFilters(ifPass,passBeamBackgroundRemoval,m_MonGroupName,ctx)); //Check ATLAS-Ready, beam-background, etc from base class
88  if(!ifPass) return StatusCode::SUCCESS;
89 
90  auto eventCounter = Monitored::Scalar<size_t>("eventCounter",0);
91  fill(m_MonGroupName,eventCounter);
92 
93  checkTrigger();
94 
95  IdentifierHash larCellMin, larCellMax;
96  m_calo_id->calo_cell_hash_range(CaloCell_ID::LARFCAL, larCellMin,larCellMax); // hash-end of FCAL is also the hash-end of LAr
97  std::vector<unsigned> hitMap(m_calo_id->calo_cell_hash_max(), 0);
98  std::vector<std::pair<IdentifierHash, float> > clusteredCells;
99  for (const xAOD::CaloCluster* cluster : *clusterHdl) {
100  if (cluster->e() < m_clusterECut)
101  continue;
102  // Loop over cells in cluster:
103  auto cellIt = cluster->cell_begin();
104  auto cellIt_e = cluster->cell_end();
105  clusteredCells.clear();
106  clusteredCells.reserve(cluster->size());
107  for (; cellIt != cellIt_e; ++cellIt) {
108  const IdentifierHash hash = cellIt->caloDDE()->calo_hash();
109  if (hash < hitMap.size()) {
110  const float cellE = cellIt->energy();
111  clusteredCells.emplace_back(std::make_pair(hash, cellE));
112  }
113  } // end loop over cells in cluster
114  // Sort & filter list of cells in this cluster if needed:
115  if (m_nCellsPerCluster > 0 && m_nCellsPerCluster < clusteredCells.size()) {
116  auto middle = clusteredCells.begin() + m_nCellsPerCluster;
117  // sort per cell energy
118  std::partial_sort(clusteredCells.begin(), middle, clusteredCells.end(),
119  [](const std::pair<IdentifierHash, float>& p1,
120  const std::pair<IdentifierHash, float>& p2) {
121  return (p1.second > p2.second);
122  });
123  // Shrink container to required cells
124  clusteredCells.resize(m_nCellsPerCluster);
125  } // end if m_nClusteredCells>0
126  for (const auto& cc : clusteredCells) {
127  ++hitMap[cc.first];
128  } // end loop over clusteredCells
129  } // end loop over clusteres
130 
131  for (const CaloDetDescrElement* caloDDE : caloDDMgr->element_range()) {
132  const IdentifierHash h=caloDDE->calo_hash();
133  if (h<hitMap.size() && hitMap[h]) {
134  float celleta, cellphi;
135  unsigned iLyr, iLyrNS;
136  std::string layerName;
137  if (h<larCellMax) {
138  //LAr Cells
139  getHistoCoordinates(caloDDE, celleta, cellphi, iLyr, iLyrNS);
140  layerName=m_layerNames[iLyr];
141  const HWIdentifier chid=cabling->createSignalChannelID(caloDDE->identify());
142  const IdentifierHash onlHash=m_onlineID->channel_Hash(chid);
143  auto mon_id = Monitored::Scalar<unsigned>("larhash",onlHash);
144  fill(m_MonGroupName,mon_id);
145  }
146  else {
147  //Tile cells
148  celleta=caloDDE->eta_raw();
149  cellphi=caloDDE->phi_raw();
150  iLyr=caloDDE->getSampling();
151  if (iLyr<12 || iLyr>20 ) {
152  ATH_MSG_ERROR("Unexpected tile sampling " << iLyr);
153  }
154  layerName=m_tileNames[iLyr-12];
155  layerName += (celleta>0) ? "A" : "C";
156  auto mon_tileOnl = Monitored::Scalar<unsigned>("tilehash",caloDDE->onl1());
157  fill(m_MonGroupName,mon_tileOnl);
158  //Fill also hash of second Tile PMT (if present):
159  if (caloDDE->onl2() != 64000) {
160  mon_tileOnl=caloDDE->onl2();
161  fill(m_MonGroupName,mon_tileOnl);
162  }
163  }
164  auto mon_eta = Monitored::Scalar<float>("celleta_"+layerName,celleta);
165  auto mon_phi = Monitored::Scalar<float>("cellphi_"+layerName,cellphi);
166  auto mon_hit = Monitored::Scalar<unsigned>("NClusteredCells_"+layerName,hitMap[h]);
167 
168 
169 
170  fill(m_MonGroupName,mon_eta,mon_phi,mon_hit);
171  }//end if cell used in a cluster
172  }
173  return StatusCode::SUCCESS;
174 }
175 
176 
177 
178 
179 
180 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
CaloMonAlgBase::checkFilters
StatusCode checkFilters(bool &ifPass, bool &passBeamBackgroundRemoval, const std::string &MonGroupName, const EventContext &ctx) const
Definition: CaloMonAlgBase.cxx:61
CaloDetDescrManager_Base::element_range
calo_element_range element_range() const
Range over element vector.
Definition: CaloDetDescrManager.cxx:123
CaloCell_Base_ID::LARFCAL
@ LARFCAL
Definition: CaloCell_Base_ID.h:43
LArOnlineID_Base::channel_Hash
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
Definition: LArOnlineID_Base.cxx:1632
CaloClusterCellMonAlg::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: CaloClusterCellMonAlg.h:38
CaloClusterCellMonAlg::m_clusterContainerKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterContainerKey
Definition: CaloClusterCellMonAlg.h:36
CaloClusterCellMonAlg::initialize
virtual StatusCode initialize() override final
initialize
Definition: CaloClusterCellMonAlg.cxx:18
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
CaloClusterCellMonAlg.h
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
AthMonitorAlgorithm::getTrigDecisionTool
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
Definition: AthMonitorAlgorithm.cxx:194
CaloClusterCellMonAlg::m_useTrigger
BooleanProperty m_useTrigger
Definition: CaloClusterCellMonAlg.h:55
HWIdentifier
Definition: HWIdentifier.h:13
CaloMonAlgBase::initialize
virtual StatusCode initialize()
initialize
Definition: CaloMonAlgBase.cxx:25
CaloDetDescrManager.h
Definition of CaloDetDescrManager.
CaloCell_ID.h
AthCommonDataStore< AthCommonMsg< Gaudi::Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
CaloClusterCellMonAlg::m_layerNames
StringArrayProperty m_layerNames
Definition: CaloClusterCellMonAlg.h:44
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
CaloClusterCellMonAlg::m_MonGroupName
Gaudi::Property< std::string > m_MonGroupName
Definition: CaloClusterCellMonAlg.h:41
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloClusterCellMonAlg::m_nCellsPerCluster
Gaudi::Property< unsigned > m_nCellsPerCluster
Definition: CaloClusterCellMonAlg.h:67
CaloCell_Base_ID::calo_cell_hash_max
size_type calo_cell_hash_max() const
cell 'global' hash table max size
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloCell_Base_ID::calo_cell_hash_range
void calo_cell_hash_range(const Identifier id, IdentifierHash &caloCellMin, IdentifierHash &caloCellMax) const
to loop on 'global' cell hashes of one sub-calorimeter alone
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
CaloMonAlgBase::m_calo_id
const CaloCell_ID * m_calo_id
Definition: CaloMonAlgBase.h:43
CaloClusterCellMonAlg::m_triggerNames
std::array< StringProperty, NOTA > m_triggerNames
Definition: CaloClusterCellMonAlg.h:56
AthMonitorAlgorithm::fill
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &&variables) const
Fills a vector of variables to a group by reference.
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
CaloMonAlgBase::getHistoCoordinates
void getHistoCoordinates(const CaloDetDescrElement *dde, float &celleta, float &cellphi, unsigned &iLyr, unsigned &iLyrNS) const
Definition: CaloMonAlgBase.cxx:176
Trig::ChainGroup
Definition: ChainGroup.h:51
CaloClusterCellMonAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override final
adds event to the monitoring histograms
Definition: CaloClusterCellMonAlg.cxx:72
Trig::ChainGroup::isPassed
bool isPassed(unsigned int condition=TrigDefs::Physics) const
tells if chain group passed
Definition: ChainGroup.cxx:208
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
h
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:108
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.TriggerAPI.TriggerAPISession.chainName
chainName
Definition: TriggerAPISession.py:426
CaloClusterCellMonAlg::m_clusterECut
Gaudi::Property< float > m_clusterECut
Definition: CaloClusterCellMonAlg.h:66
CaloClusterCellMonAlg::m_tileNames
const std::array< std::string, 9 > m_tileNames
Definition: CaloClusterCellMonAlg.h:76
CaloClusterCellMonAlg::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: CaloClusterCellMonAlg.h:39
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
CaloClusterCellMonAlg::m_onlineID
const LArOnlineID * m_onlineID
Definition: CaloClusterCellMonAlg.h:74
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
CaloClusterCellMonAlg::checkTrigger
void checkTrigger() const
Definition: CaloClusterCellMonAlg.cxx:42
CaloGain.h
python.handimod.cc
int cc
Definition: handimod.py:522
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20