ATLAS Offline Software
TileDigiNoiseMonitorAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 #include "StoreGate/ReadHandle.h"
11 
13 
14  ATH_MSG_DEBUG("in initialize()");
15 
16  // initialize superclass
18 
20 
22 
23  ATH_CHECK( m_cablingSvc.retrieve() );
24  m_cabling = m_cablingSvc->cablingService();
25 
31 
32  using Tile = TileCalibUtils;
33  using namespace Monitored;
34 
35  m_pedGroups = buildToolMap<std::vector<int>>(m_tools, "TileDigiNoisePed", Tile::MAX_ROS - 1, Tile::MAX_GAIN);
36  m_hfnGroups = buildToolMap<std::vector<int>>(m_tools, "TileDigiNoiseHFN", Tile::MAX_ROS - 1, Tile::MAX_GAIN);
37 
38  return StatusCode::SUCCESS;
39 }
40 
41 
43 
44  using Tile = TileCalibUtils;
45 
46  // In case you want to measure the execution time
47  auto timer = Monitored::Timer("TIME_execute");
48 
49  const xAOD::EventInfo* eventInfo = GetEventInfo(ctx).get();
50 
51 
52  if (msgLvl(MSG::DEBUG)) {
53  msg(MSG::DEBUG) << "Run = " << eventInfo->runNumber()
54  << " LB = " << eventInfo->lumiBlock()
55  << " Evt = " << eventInfo->eventNumber()
56  << " BCID = " << eventInfo->bcid()
57  << " lvl1 = 0x" << std::hex << eventInfo->level1TriggerType() << std::dec;
58 
59  const std::vector<xAOD::EventInfo::StreamTag>& evtStreamTags = eventInfo->streamTags();
60  if (!evtStreamTags.empty()) {
61  msg(MSG::DEBUG) << " stream name/type:";
62  for (const auto& evtStreamTag : evtStreamTags) {
63  msg(MSG::DEBUG) << " " << evtStreamTag.name() << "/" << evtStreamTag.type();
64  }
65  }
66 
67  msg(MSG::DEBUG) << endmsg;
68  }
69 
70 
71  unsigned int lvl1TriggerType = eventInfo->level1TriggerType();
72 
73  if (m_triggerTypes.empty()
74  || std::find( m_triggerTypes.begin(), m_triggerTypes.end(), lvl1TriggerType) != m_triggerTypes.end()) {
75 
76  std::vector<int> drawers[Tile::MAX_ROS - 1][Tile::MAX_GAIN];
77  std::vector<int> channels[Tile::MAX_ROS - 1][Tile::MAX_GAIN];
78  std::vector<float> pedestals[Tile::MAX_ROS - 1][Tile::MAX_GAIN];
79  std::vector<float> hfns[Tile::MAX_ROS - 1][Tile::MAX_GAIN];
80 
81  int nChannelsInPartition = 2880; // LB
82  for (unsigned int partition = 0; partition < Tile::MAX_ROS - 1; ++partition) {
83  if (partition > 1) nChannelsInPartition = 2048; // EB
84  for (unsigned int gain : {0, 1}) {
85  drawers[partition][gain].reserve(nChannelsInPartition);
86  channels[partition][gain].reserve(nChannelsInPartition);
87  pedestals[partition][gain].reserve(nChannelsInPartition);
88  hfns[partition][gain].reserve(nChannelsInPartition);
89  }
90  }
91 
92  const TileDQstatus* dqStatus = SG::makeHandle(m_DQstatusKey, ctx).get();
93  const TileDCSState* dcsState = m_checkDCS ? SG::ReadCondHandle(m_DCSStateKey, ctx).cptr() : nullptr;
94 
96 
98  ATH_CHECK( digitsContainer.isValid() );
99 
100  for (const TileDigitsCollection* digitsCollection : *digitsContainer) {
101  if (digitsCollection->empty() ) continue;
102 
103  if (digitsCollection->getLvl1Type() != lvl1TriggerType) {
104  ATH_MSG_DEBUG("Level1 Trigger Type in Tile digits [0x" << std::hex
105  << digitsCollection->getLvl1Type() << "] != [0x"
106  << lvl1TriggerType << std::dec << "] from the event info");
107  continue;
108  }
109 
110  HWIdentifier adc_id = digitsCollection->front()->adc_HWID();
111  int ros = m_tileHWID->ros(adc_id);
112  int drawer = m_tileHWID->drawer(adc_id);
113  unsigned int drawerIdx = TileCalibUtils::getDrawerIdx(ros, drawer);
114  int partition = ros - 1;
115 
116  unsigned int nBadOrDisconnectedChannels = 0;
117  for (unsigned int channel = 0; channel < TileCalibUtils::MAX_CHAN; ++channel) {
119  ++nBadOrDisconnectedChannels;
120  }
121  }
122 
123  unsigned int nRequiredChannels = TileCalibUtils::MAX_CHAN - nBadOrDisconnectedChannels;
124  if (digitsCollection->size() < nRequiredChannels) {
125  ATH_MSG_DEBUG("Number of Tile channels with digits [" << digitsCollection->size()
126  << "] less than expected [" << nRequiredChannels << "]");
127  continue;
128  }
129 
130  bool checkDQ = true;
131 
132  int fragId = digitsCollection->identify();
133  if (std::binary_search(m_fragIDsToIgnoreDMUerrors.begin(), m_fragIDsToIgnoreDMUerrors.end(), fragId)) {
134  checkDQ = false;
135  }
136 
137  for (const TileDigits* tile_digits : *digitsCollection) {
138 
139  adc_id = tile_digits->adc_HWID();
140  int channel = m_tileHWID->channel(adc_id);
141  int adc = m_tileHWID->adc(adc_id);
142 
144  ATH_MSG_VERBOSE(m_tileHWID->to_string(adc_id) << ": Disconnected => skipping!");
145  continue;
146  }
147 
148  if (checkDQ && !(dqStatus->isAdcDQgood(ros, drawer, channel, adc))) {
149  ATH_MSG_VERBOSE(m_tileHWID->to_string(adc_id) << ": DQ is BAD => skipping!");
150  continue;
151  }
152 
153  if (m_checkDCS && dcsState->isStatusBad(ros, drawer, channel)) {
154  ATH_MSG_VERBOSE(m_tileHWID->to_string(adc_id) << ": DCS is Bad => skipping!");
155  continue;
156  }
157 
158  if (badChannels->getAdcStatus(adc_id).isBad()) {
159  ATH_MSG_VERBOSE(m_tileHWID->to_string(adc_id) << ": Status is BAD => skipping!");
160  continue;
161  }
162 
163  std::vector<float> digits = tile_digits->samples();
164 
165  double sampleMean = 0.0;
166  double sampleRMS = 0.0;
167  unsigned int nSamples = digits.size();
168 
169  for (double sample : digits) {
170  sampleMean += sample;
171  sampleRMS += sample * sample;
172  }
173 
174  if (nSamples > 1) {
175  double pedestal = digits[0];
176 
179  pedestal -= m_tileCondToolNoiseSample->getPed(drawerIdx, channel, adc, TileRawChannelUnit::ADCcounts, ctx);
180  } else {
181  pedestal = 0.0;
182  }
183  }
184 
185  drawers[partition][adc].push_back(drawer);
186  channels[partition][adc].push_back(channel);
187  pedestals[partition][adc].push_back(pedestal);
188 
189  sampleMean /= nSamples;
190  sampleRMS = sampleRMS / nSamples - sampleMean * sampleMean;
191  sampleRMS = (sampleRMS > 0.0) ? sqrt(sampleRMS * nSamples / (nSamples - 1)) : 0.0;
192 
193  hfns[partition][adc].push_back(sampleRMS);
194 
195  ATH_MSG_VERBOSE(m_tileHWID->to_string(adc_id) << ": pedestal = " << pedestal << " HFN = " << sampleRMS);
196  }
197  } // digits
198  }
199 
200  for (unsigned int partition = 0; partition < Tile::MAX_ROS - 1; ++partition) {
201  for (unsigned int gain = 0; gain < Tile::MAX_GAIN; ++gain) {
202  if (!pedestals[partition][gain].empty()) {
203  auto monModule = Monitored::Collection("module", drawers[partition][gain]);
204  auto monChannel = Monitored::Collection("channel", channels[partition][gain]);
205  auto monPedestal = Monitored::Collection("pedestal", pedestals[partition][gain]);
206  fill(m_tools[m_pedGroups[partition][gain]], monModule, monChannel, monPedestal);
207 
208  auto monHFN = Monitored::Collection("HFN", hfns[partition][gain]);
209  fill(m_tools[m_hfnGroups[partition][gain]], monModule, monChannel, monHFN);
210  }
211  }
212  }
213  }
214 
215  fill("TileDigiNoiseMonExecuteTime", timer);
216 
217  return StatusCode::SUCCESS;
218 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TileDigiNoiseMonitorAlgorithm::m_ignoreDisconnectedChannels
Gaudi::Property< bool > m_ignoreDisconnectedChannels
Definition: TileDigiNoiseMonitorAlgorithm.h:45
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
TileDigiNoiseMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: TileDigiNoiseMonitorAlgorithm.cxx:42
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TileDigiNoiseMonitorAlgorithm::m_tileHWID
const TileHWID * m_tileHWID
Definition: TileDigiNoiseMonitorAlgorithm.h:78
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
TileDigiNoiseMonitorAlgorithm::m_DCSStateKey
SG::ReadCondHandleKey< TileDCSState > m_DCSStateKey
Name of TileDCSState object in condition store.
Definition: TileDigiNoiseMonitorAlgorithm.h:57
TileCalibUtils.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
TileDigiNoiseMonitorAlgorithm::m_checkDCS
Gaudi::Property< bool > m_checkDCS
Definition: TileDigiNoiseMonitorAlgorithm.h:38
TileDCSState::isStatusBad
bool isStatusBad(unsigned int ros, unsigned int drawer) const
Return true if given Tile drawer considered as bad by summary drawer states per LVPS otherwise return...
Definition: TileDCSState.h:320
Example_ReadSampleNoise.drawer
drawer
Definition: Example_ReadSampleNoise.py:39
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
ReadCondHandle.h
TileHWID::channel
int channel(const HWIdentifier &id) const
extract channel field from HW identifier
Definition: TileHWID.h:189
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
dq_defect_copy_defect_database.channels
def channels
Definition: dq_defect_copy_defect_database.py:56
TileDigiNoiseMonitorAlgorithm.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
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
TileHWID::ros
int ros(const HWIdentifier &id) const
extract ros field from HW identifier
Definition: TileHWID.h:167
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TileDQstatus
Class that holds Data Quality fragment information and provides functions to extract the data quality...
Definition: TileDQstatus.h:49
TileHWID::adc
int adc(const HWIdentifier &id) const
extract adc field from HW identifier
Definition: TileHWID.h:193
Tile
Definition: TileVolumeBuilder.h:43
TileDigiNoiseMonitorAlgorithm::m_badChannelsKey
SG::ReadCondHandleKey< TileBadChannels > m_badChannelsKey
Name of TileBadChannels in condition store.
Definition: TileDigiNoiseMonitorAlgorithm.h:66
TileHWID.h
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:116
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
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
TileDigiNoiseMonitorAlgorithm::m_fillPedestalDifference
Gaudi::Property< bool > m_fillPedestalDifference
Definition: TileDigiNoiseMonitorAlgorithm.h:42
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TileDigiNoiseMonitorAlgorithm::m_triggerTypes
Gaudi::Property< std::vector< unsigned int > > m_triggerTypes
Definition: TileDigiNoiseMonitorAlgorithm.h:39
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
maskDeadModules.ros
ros
Definition: maskDeadModules.py:35
TileDigiNoiseMonitorAlgorithm::m_tileCondToolNoiseSample
ToolHandle< TileCondToolNoiseSample > m_tileCondToolNoiseSample
Definition: TileDigiNoiseMonitorAlgorithm.h:69
TileDigiNoiseMonitorAlgorithm::m_hfnGroups
std::vector< std::vector< int > > m_hfnGroups
Definition: TileDigiNoiseMonitorAlgorithm.h:82
AthMonitorAlgorithm::GetEventInfo
SG::ReadHandle< xAOD::EventInfo > GetEventInfo(const EventContext &) const
Return a ReadHandle for an EventInfo object (get run/event numbers, etc.)
Definition: AthMonitorAlgorithm.cxx:107
TileDigiNoiseMonitorAlgorithm::m_cablingSvc
ServiceHandle< TileCablingSvc > m_cablingSvc
Name of Tile cabling service.
Definition: TileDigiNoiseMonitorAlgorithm.h:75
xAOD::EventInfo_v1::lumiBlock
uint32_t lumiBlock() const
The current event's luminosity block number.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TileDQstatus::isAdcDQgood
bool isAdcDQgood(int partition, int drawer, int ch, int gain) const
returns status of single ADC returns False if there are any errors
Definition: TileDQstatus.cxx:178
AthMonitorAlgorithm::m_tools
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
Definition: AthMonitorAlgorithm.h:338
TileDigitsCollection
Definition: TileDigitsCollection.h:18
TileDigits
Definition: TileDigits.h:30
TileDigiNoiseMonitorAlgorithm::m_cabling
const TileCablingService * m_cabling
Definition: TileDigiNoiseMonitorAlgorithm.h:79
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
TileDigiNoiseMonitorAlgorithm::m_pedGroups
std::vector< std::vector< int > > m_pedGroups
Definition: TileDigiNoiseMonitorAlgorithm.h:81
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
TileBadChannels::getAdcStatus
const TileBchStatus & getAdcStatus(const HWIdentifier adc_id) const
Return Tile ADC status.
Definition: TileBadChannels.cxx:24
xAOD::EventInfo_v1::streamTags
const std::vector< StreamTag > & streamTags() const
Get the streams that the event was put in.
Definition: EventInfo_v1.cxx:283
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
TileCablingService::isDisconnected
bool isDisconnected(int ros, int drawer, int channel) const
Definition: TileCablingService.cxx:2461
TileHWID::drawer
int drawer(const HWIdentifier &id) const
extract drawer field from HW identifier
Definition: TileHWID.h:171
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
TileDigiNoiseMonitorAlgorithm::m_DQstatusKey
SG::ReadHandleKey< TileDQstatus > m_DQstatusKey
Definition: TileDigiNoiseMonitorAlgorithm.h:51
DEBUG
#define DEBUG
Definition: page_access.h:11
python.Classes.TileCalibUtils
TileCalibUtils
Definition: TileCalib/TileCalibBlobObjs/python/Classes.py:5
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
StateLessPT_NewConfig.partition
partition
Definition: StateLessPT_NewConfig.py:49
xAOD::EventInfo_v1::level1TriggerType
uint16_t level1TriggerType() const
The Level-1 trigger type.
TileDCSState
Condition object to keep Tile DCS status from DB.
Definition: TileDCSState.h:24
LArDigits2NtupleDumper.nSamples
nSamples
Definition: LArDigits2NtupleDumper.py:70
TileCalibUtils::getDrawerIdx
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
Definition: TileCalibUtils.cxx:60
TileHWID::to_string
std::string to_string(const HWIdentifier &id, int level=0) const
extract all fields from HW identifier HWIdentifier get_all_fields ( const HWIdentifier & id,...
Definition: TileHWID.cxx:50
ReadHandle.h
Handle class for reading from StoreGate.
TileCalibUtils::MAX_CHAN
static const unsigned int MAX_CHAN
Number of channels in drawer.
Definition: TileCalibUtils.h:141
xAOD::EventInfo_v1::bcid
uint32_t bcid() const
The bunch crossing ID of the event.
TileDigiNoiseMonitorAlgorithm::m_fragIDsToIgnoreDMUerrors
Gaudi::Property< std::vector< int > > m_fragIDsToIgnoreDMUerrors
Definition: TileDigiNoiseMonitorAlgorithm.h:48
TileDigiNoiseMonitorAlgorithm::m_digitsContainerKey
SG::ReadHandleKey< TileDigitsContainer > m_digitsContainerKey
Definition: TileDigiNoiseMonitorAlgorithm.h:60
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
TileRawChannelUnit::ADCcounts
@ ADCcounts
Definition: TileRawChannelUnit.h:17
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition: ReadCondHandle.h:67
TileDigiNoiseMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: TileDigiNoiseMonitorAlgorithm.cxx:12