ATLAS Offline Software
Loading...
Searching...
No Matches
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
11
13
14 ATH_MSG_DEBUG("in initialize()");
15
16 // initialize superclass
18
20
21 ATH_CHECK( detStore()->retrieve(m_tileHWID) );
22
23 ATH_CHECK( m_cablingSvc.retrieve() );
24 m_cabling = m_cablingSvc->cablingService();
25
26 ATH_CHECK( m_digitsContainerKey.initialize() );
27 ATH_CHECK( m_DQstatusKey.initialize() );
28 ATH_CHECK( m_badChannelsKey.initialize() );
29 ATH_CHECK( m_DCSStateKey.initialize(m_checkDCS) );
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
42StatusCode TileDigiNoiseMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
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) {
118 if (m_cabling->isDisconnected(ros, drawer, 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
143 if (m_ignoreDisconnectedChannels && m_cabling->isDisconnected(ros, drawer, channel)) {
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
178 if (!m_cabling->isDisconnected(ros, drawer, channel)) {
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}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
static const Attributes_t empty
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
virtual StatusCode initialize() override
initialize
SG::ReadHandle< xAOD::EventInfo > GetEventInfo(const EventContext &) const
Return a ReadHandle for an EventInfo object (get run/event numbers, etc.)
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
A monitored timer.
const_pointer_type cptr()
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Static class providing several utility functions and constants.
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
static const unsigned int MAX_CHAN
Number of channels in drawer.
Condition object to keep Tile DCS status from DB.
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...
Class that holds Data Quality fragment information and provides functions to extract the data quality...
bool isAdcDQgood(int partition, int drawer, int ch, int gain) const
returns status of single ADC returns False if there are any errors
Gaudi::Property< bool > m_ignoreDisconnectedChannels
std::vector< std::vector< int > > m_hfnGroups
SG::ReadCondHandleKey< TileBadChannels > m_badChannelsKey
Name of TileBadChannels in condition store.
Gaudi::Property< std::vector< int > > m_fragIDsToIgnoreDMUerrors
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
ToolHandle< TileCondToolNoiseSample > m_tileCondToolNoiseSample
SG::ReadHandleKey< TileDigitsContainer > m_digitsContainerKey
Gaudi::Property< std::vector< unsigned int > > m_triggerTypes
SG::ReadCondHandleKey< TileDCSState > m_DCSStateKey
Name of TileDCSState object in condition store.
ServiceHandle< TileCablingSvc > m_cablingSvc
Name of Tile cabling service.
SG::ReadHandleKey< TileDQstatus > m_DQstatusKey
std::vector< std::vector< int > > m_pedGroups
virtual StatusCode initialize() override
initialize
uint32_t lumiBlock() const
The current event's luminosity block number.
uint32_t bcid() const
The bunch crossing ID of the event.
uint16_t level1TriggerType() const
The Level-1 trigger type.
const std::vector< StreamTag > & streamTags() const
Get the streams that the event was put in.
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
Generic monitoring tool for athena components.
std::vector< V > buildToolMap(const ToolHandleArray< GenericMonitoringTool > &tools, const std::string &baseName, int nHist)
Builds an array of indices (base case)
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
EventInfo_v1 EventInfo
Definition of the latest event info version.
void fill(H5::Group &out_file, size_t iterations)
MsgStream & msg
Definition testRead.cxx:32