ATLAS Offline Software
LArClusterCellMonAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "LArClusterCellMonAlg.h"
6 
7 #include "CaloDetDescr/CaloDetDescrElement.h"
9 #include "Identifier/Identifier.h"
12 
13 #include <algorithm>
14 
15 
16 
19 
20  ATH_MSG_DEBUG("LArClusterCellMonAlg::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("LArClusterCellMonAlg::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 LArClusterCellMonAlg::fillHistograms(const EventContext& ctx) const{
73 
74  ATH_MSG_DEBUG("LArClusterCellMonAlg::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 caloCellMin, caloCellMax;
96  m_calo_id->calo_cell_hash_range(CaloCell_ID::LARFCAL,caloCellMin,caloCellMax);
97  //hash-end of FCAL is also the hash-end of LAr
98  std::vector<unsigned> hitMap(caloCellMax,0);
99  std::vector<std::pair<IdentifierHash,float> > clusteredCells;
100  for (const xAOD::CaloCluster* cluster : *clusterHdl) {
101  if (cluster->e()<m_clusterECut) 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()) { //Ignore tile cells
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) {return (p1.second>p2.second);});
121  //Shrink container to required cells
122  clusteredCells.resize(m_nCellsPerCluster);
123  }//end if m_nClusteredCells>0
124  for (const auto& cc : clusteredCells) {
125  ++hitMap[cc.first];
126  }//end if hash<size
127  }//end loop over clusteres
128 
129 
130  for (const CaloDetDescrElement* caloDDE : caloDDMgr->element_range()) {
131  const IdentifierHash h=caloDDE->calo_hash();
132  if (h<hitMap.size() && hitMap[h]) {
133  float celleta, cellphi;
134  unsigned iLyr, iLyrNS;
135  getHistoCoordinates(caloDDE, celleta, cellphi, iLyr, iLyrNS);
136 
137  auto mon_eta = Monitored::Scalar<float>("celleta_"+m_layerNames[iLyr],celleta);
138  auto mon_phi = Monitored::Scalar<float>("cellphi_"+m_layerNames[iLyr],cellphi);
139  auto mon_hit = Monitored::Scalar<unsigned>("NClusteredCells_"+m_layerNames[iLyr],hitMap[h]);
140 
141  const HWIdentifier chid=cabling->createSignalChannelID(caloDDE->identify());
142  const IdentifierHash onlHash=m_onlineID->channel_Hash(chid);
143  auto mon_id = Monitored::Scalar<unsigned>("cellhash",onlHash);
144 
145  fill(m_MonGroupName,mon_eta,mon_phi,mon_hit,mon_id);
146  }//end if cell used in a cluster
147  }
148  return StatusCode::SUCCESS;
149 }
150 
151 
152 
153 
154 
155 
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
LArClusterCellMonAlg::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArClusterCellMonAlg.h:39
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:46
LArOnlineID_Base::channel_Hash
IdentifierHash channel_Hash(HWIdentifier channelId) const
Create channel_hash from channel_Id.
Definition: LArOnlineID_Base.cxx:1632
LArClusterCellMonAlg::initialize
virtual StatusCode initialize() override final
initialize
Definition: LArClusterCellMonAlg.cxx:18
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
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:189
LArClusterCellMonAlg::m_useTrigger
BooleanProperty m_useTrigger
Definition: LArClusterCellMonAlg.h:55
HWIdentifier
Definition: HWIdentifier.h:13
CaloMonAlgBase::initialize
virtual StatusCode initialize()
initialize
Definition: CaloMonAlgBase.cxx:25
LArClusterCellMonAlg::m_clusterECut
Gaudi::Property< float > m_clusterECut
Definition: LArClusterCellMonAlg.h:66
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
LArClusterCellMonAlg::m_nCellsPerCluster
Gaudi::Property< unsigned > m_nCellsPerCluster
Definition: LArClusterCellMonAlg.h:67
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
LArClusterCellMonAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override final
adds event to the monitoring histograms
Definition: LArClusterCellMonAlg.cxx:72
LArClusterCellMonAlg::m_triggerNames
std::array< StringProperty, NOTA > m_triggerNames
Definition: LArClusterCellMonAlg.h:56
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
LArClusterCellMonAlg.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloMonAlgBase::m_calo_id
const CaloCell_ID * m_calo_id
Definition: CaloMonAlgBase.h:43
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
LArClusterCellMonAlg::checkTrigger
void checkTrigger() const
Definition: LArClusterCellMonAlg.cxx:42
CaloMonAlgBase::getHistoCoordinates
void getHistoCoordinates(const CaloDetDescrElement *dde, float &celleta, float &cellphi, unsigned &iLyr, unsigned &iLyrNS) const
Definition: CaloMonAlgBase.cxx:176
LArClusterCellMonAlg::m_clusterContainerKey
SG::ReadHandleKey< xAOD::CaloClusterContainer > m_clusterContainerKey
Definition: LArClusterCellMonAlg.h:36
Trig::ChainGroup
Definition: ChainGroup.h:51
Trig::ChainGroup::isPassed
bool isPassed(unsigned int condition=TrigDefs::Physics) const
tells if chain group passed
Definition: ChainGroup.cxx:208
LArClusterCellMonAlg::m_layerNames
StringArrayProperty m_layerNames
Definition: LArClusterCellMonAlg.h:44
LArClusterCellMonAlg::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition: LArClusterCellMonAlg.h:38
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:109
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArClusterCellMonAlg::m_MonGroupName
Gaudi::Property< std::string > m_MonGroupName
Definition: LArClusterCellMonAlg.h:41
python.TriggerAPI.TriggerAPISession.chainName
chainName
Definition: TriggerAPISession.py:426
LArClusterCellMonAlg::m_onlineID
const LArOnlineID * m_onlineID
Definition: LArClusterCellMonAlg.h:74
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
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
CaloGain.h
python.handimod.cc
int cc
Definition: handimod.py:523
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20