ATLAS Offline Software
TileDigitsFlxMonitorAlgorithm.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 // Tile includes
9 
10 // Athena includes
11 #include "StoreGate/ReadHandle.h"
12 
13 #include <cmath>
14 #include <algorithm>
15 
16 
18 
20 
21  ATH_MSG_INFO("in initialize()");
22 
26 
27  std::ostringstream os;
28 
29  if ( m_fragIDsToCompare.size() != 0) {
30  std::sort(m_fragIDsToCompare.begin(), m_fragIDsToCompare.end());
31  for (int fragID : m_fragIDsToCompare) {
32  unsigned int ros = fragID >> 8;
33  unsigned int drawer = fragID & 0xFF;
35  os << " " << module << "/0x" << std::hex << fragID << std::dec;
36  }
37  } else {
38  os << "NONE";
39  }
40  m_firstFelix = static_cast<unsigned int>(m_firstSample) + m_felixOffset;
42 
43  ATH_MSG_INFO("Monitored modules/frag ID:" << os.str());
44 
45  return StatusCode::SUCCESS;
46 }
47 
48 
50 
51  // In case you want to measure the execution time
52  auto timer = Monitored::Timer("TIME_execute");
53 
55  ATH_CHECK( digitsContainerLegacy.isValid() );
56 
58  ATH_CHECK( digitsContainerFlx.isValid() );
59 
60  std::array<std::string, 2> gainName{"_LG", "_HG"};
61 
62  std::vector<float>digitsLegacy[TileCalibUtils::MAX_CHAN][TileCalibUtils::MAX_GAIN];
63  std::vector<float>digitsFlx[TileCalibUtils::MAX_CHAN][TileCalibUtils::MAX_GAIN];
65 
66  const TileFragHash& hashFunc = digitsContainerFlx->hashFunc();
67 
68  for (int fragID : m_fragIDsToCompare) {
69 
70  memset(found,0,sizeof(found));
71 
72  IdentifierHash hash = static_cast<IdentifierHash>(hashFunc(fragID));
73  unsigned int drawer = (fragID & 0x3F);
74  unsigned int ros = fragID >> 8;
76  std::array<std::string, 2> moduleName{module+gainName[0], module+gainName[1]};
77 
78  // Legacy digits
79  const TileDigitsCollection* digitsCollectionLegacy = digitsContainerLegacy->indexFindPtr(hash);
80  for (const TileDigits* tile_digits : *digitsCollectionLegacy) {
81 
82  ATH_MSG_VERBOSE((std::string) *tile_digits);
83 
84  unsigned int nSamples = tile_digits->nsamples();
85  if (m_firstSample < nSamples) {
86 
87  HWIdentifier adcId = tile_digits->adc_HWID();
88  int channel = m_tileHWID->channel(adcId);
89  int gain = m_tileHWID->adc(adcId);
90 
91  std::string sampleName = module + "_ch_" + std::to_string(channel) + gainName[gain] + "_samples";
92  auto channelSample = Monitored::Scalar<float>(sampleName, 0.0F);
93 
94  std::vector<float> digits_monitored;
95  auto it = tile_digits->samples().begin() + m_firstSample;
96  auto end = tile_digits->samples().end();
97  for(auto i = m_nSamples; it != end && i-->0; ++it) {
98  float sample = (*it);
99  channelSample = sample;
100  fill("TileLegacyMonSamples", channelSample);
101  digits_monitored.push_back(sample);
102  }
103 
104  nSamples = digits_monitored.size();
105  if (nSamples>0) {
106 
107  std::string channelName = moduleName[gain] + "_channel";
108  auto monitoredChannel = Monitored::Scalar<float>(channelName, channel);
109 
110  std::string monPedestal = moduleName[gain] + "_Pedestal";
111  auto pedestal = Monitored::Scalar<float>(monPedestal, digits_monitored[0]);
112  fill("TileLegacyMonPed", monitoredChannel, pedestal);
113 
114  if (nSamples>1) {
115 
116  double sampleSum = std::accumulate( digits_monitored.begin(), digits_monitored.end(), 0.0);
117 
118  double sampleRMS = std::accumulate( digits_monitored.begin(), digits_monitored.end(), 0.0, [] (double acc, float sample) {
119  return acc + sample * sample;
120  });
121  sampleRMS -= sampleSum * sampleSum / nSamples;
122  sampleRMS = (sampleRMS > 0.0) ? std::sqrt(sampleRMS / (nSamples - 1)) : 0.0;
123 
124  std::string monHFN = moduleName[gain] + "_HFN";
125  auto hfn = Monitored::Scalar<float>(monHFN, sampleRMS);
126  fill("TileLegacyMonHFN", monitoredChannel, hfn);
127  }
128 
129  found[channel][gain] |= 1;
130  digitsLegacy[channel][gain].swap(digits_monitored);
131  }
132  }
133  }
134 
135  // FELIX digits
136  const TileDigitsCollection* digitsCollectionFlx = digitsContainerFlx->indexFindPtr(hash);
137  for (const TileDigits* tile_digits : *digitsCollectionFlx) {
138 
139  ATH_MSG_VERBOSE((std::string) *tile_digits);
140 
141  unsigned int nSamples = tile_digits->nsamples();
142  if (m_firstFelix < nSamples) {
143 
144  HWIdentifier adcId = tile_digits->adc_HWID();
145  int channel = m_tileHWID->channel(adcId);
146  int gain = m_tileHWID->adc(adcId);
147 
148  std::string sampleName = module + "_ch_" + std::to_string(channel) + gainName[gain] + "_samples";
149  auto channelSample = Monitored::Scalar<float>(sampleName, 0.0F);
150 
151  std::vector<float> digits_monitored;
152  auto it = tile_digits->samples().begin() + m_firstFelix;
153  auto end = tile_digits->samples().end();
154 
155  for(auto i = m_nSamples; it != end && i-->0; ++it) {
156  float sample = (*it);
157  channelSample = sample;
158  fill("TileFlxMonSamples", channelSample);
159  digits_monitored.push_back(sample);
160  }
161 
162  nSamples = digits_monitored.size();
163  if (nSamples>0) {
164 
165  std::string channelName = moduleName[gain] + "_channel";
166  auto monitoredChannel = Monitored::Scalar<float>(channelName, channel);
167 
168  std::string monPedestal = moduleName[gain] + "_Pedestal";
169  auto pedestal = Monitored::Scalar<float>(monPedestal, digits_monitored[0]);
170  fill("TileFlxMonPed", monitoredChannel, pedestal);
171 
172  if (nSamples>1) {
173 
174  double sampleSum = std::accumulate( digits_monitored.begin(), digits_monitored.end(), 0.0);
175 
176  double sampleRMS = std::accumulate( digits_monitored.begin(), digits_monitored.end(), 0.0, [] (double acc, float sample) {
177  return acc + sample * sample;
178  });
179  sampleRMS -= sampleSum * sampleSum / nSamples;
180  sampleRMS = (sampleRMS > 0.0) ? std::sqrt(sampleRMS / (nSamples - 1)) : 0.0;
181 
182  std::string monHFN = moduleName[gain] + "_HFN";
183  auto hfn = Monitored::Scalar<float>(monHFN, sampleRMS);
184  fill("TileFlxMonHFN", monitoredChannel, hfn);
185  }
186 
187  found[channel][gain] |= 2;
188  digitsFlx[channel][gain].swap(digits_monitored);
189  }
190  }
191  }
192 
193  // Compare digits from Legacy and FELIX
194  for(unsigned int gain = 0; gain<TileCalibUtils::MAX_GAIN; ++gain) {
195 
196  std::string channelName = moduleName[gain] + "_channel";
197  std::string moduleSampleName = moduleName[gain] + "_samples_diff";
198 
199  auto monitoredChannel = Monitored::Scalar<float>(channelName, 0.0F);
200  auto moduleSampleDiff = Monitored::Scalar<float>(moduleSampleName, 0.0F);
201 
202  for(unsigned int channel = 0; channel<TileCalibUtils::MAX_CHAN; ++channel) {
203 
204  if (found[channel][gain] == 3) {
205 
206  monitoredChannel = channel;
207 
208  std::string sampleName = module + "_ch_" + std::to_string(channel) + gainName[gain] + "_samples_diff";
209  auto channelSampleDiff = Monitored::Scalar<float>(sampleName, 0.0F);
210 
211  for (auto it1=digitsLegacy[channel][gain].begin(), it2=digitsFlx[channel][gain].begin();
212  it1!=digitsLegacy[channel][gain].end() && it2!=digitsFlx[channel][gain].end(); ++it1, ++it2) {
213 
214  float diff = (*it2)- (*it1)*m_felixScale;
215  channelSampleDiff = diff;
216  moduleSampleDiff = diff;
217 
218  fill("TileChannelAllSamplesDiff", channelSampleDiff);
219  fill("TileModuleAllSamplesDiff", moduleSampleDiff);
220  fill("TileModuleSamplesDiff", monitoredChannel, moduleSampleDiff);
221  }
222  }
223  }
224  }
225  }
226 
227  fill("TileDigitsFlxMonExecuteTime", timer);
228 
229  return StatusCode::SUCCESS;
230 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
Example_ReadSampleNoise.hfn
hfn
Definition: Example_ReadSampleNoise.py:46
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TileDigitsFlxMonitorAlgorithm::m_nSamples
unsigned int m_nSamples
Definition: TileDigitsFlxMonitorAlgorithm.h:46
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TileDigitsFlxMonitorAlgorithm::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: TileDigitsFlxMonitorAlgorithm.cxx:49
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:396
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
TileDigitsFlxMonitorAlgorithm::m_firstFelix
unsigned int m_firstFelix
Definition: TileDigitsFlxMonitorAlgorithm.h:45
TileDigitsFlxMonitorAlgorithm.fragID
fragID
Definition: TileDigitsFlxMonitorAlgorithm.py:165
TileCalibUtils.h
TileDigitsFlxMonitorAlgorithm::m_lastSample
Gaudi::Property< unsigned int > m_lastSample
Definition: TileDigitsFlxMonitorAlgorithm.h:41
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TileFragHash
Hash table for Tile fragments (==drawers ==collections in StoreGate)
Definition: TileFragHash.h:24
HWIdentifier
Definition: HWIdentifier.h:13
Example_ReadSampleNoise.drawer
drawer
Definition: Example_ReadSampleNoise.py:39
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
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
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
python.PyAthena.module
module
Definition: PyAthena.py:131
TileHWID::adc
int adc(const HWIdentifier &id) const
extract adc field from HW identifier
Definition: TileHWID.h:193
TileHWID.h
TileDigitsFlxMonitorAlgorithm::m_fragIDsToCompare
Gaudi::Property< std::vector< int > > m_fragIDsToCompare
Definition: TileDigitsFlxMonitorAlgorithm.h:38
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:116
lumiFormat.i
int i
Definition: lumiFormat.py:85
TileDigitsFlxMonitorAlgorithm::m_digitsContainerKeyLegacy
SG::ReadHandleKey< TileDigitsContainer > m_digitsContainerKeyLegacy
Definition: TileDigitsFlxMonitorAlgorithm.h:30
DetDescrDictionaryDict::it1
std::vector< HWIdentifier >::iterator it1
Definition: DetDescrDictionaryDict.h:17
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TileDigitsFlxMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: TileDigitsFlxMonitorAlgorithm.cxx:17
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
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TileDigitsFlxMonitorAlgorithm.h
TileDigitsFlxMonitorAlgorithm::m_tileHWID
const TileHWID * m_tileHWID
Definition: TileDigitsFlxMonitorAlgorithm.h:36
TileDigitsFlxMonitorAlgorithm::m_firstSample
Gaudi::Property< unsigned int > m_firstSample
Definition: TileDigitsFlxMonitorAlgorithm.h:40
TileDigitsCollection
Definition: TileDigitsCollection.h:18
TileDigits
Definition: TileDigits.h:30
TileDigitsFlxMonitorAlgorithm::m_felixOffset
Gaudi::Property< unsigned int > m_felixOffset
Definition: TileDigitsFlxMonitorAlgorithm.h:42
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TileRawDataContainer::hashFunc
const TileFragHash & hashFunc() const
Definition: TileRawDataContainer.h:66
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
IdentifiableContainerMT::indexFindPtr
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
Definition: IdentifiableContainerMT.h:292
TileCalibUtils::getDrawerString
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
Definition: TileCalibUtils.cxx:145
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
F
#define F(x, y, z)
Definition: MD5.cxx:112
TileDigitsFlxMonitorAlgorithm::m_digitsContainerKeyFlx
SG::ReadHandleKey< TileDigitsContainer > m_digitsContainerKeyFlx
Definition: TileDigitsFlxMonitorAlgorithm.h:33
LArDigits2NtupleDumper.nSamples
nSamples
Definition: LArDigits2NtupleDumper.py:70
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
ReadHandle.h
Handle class for reading from StoreGate.
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
TileCalibUtils::MAX_CHAN
static const unsigned int MAX_CHAN
Number of channels in drawer.
Definition: TileCalibUtils.h:141
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
TileDigitsFlxMonitorAlgorithm::m_felixScale
Gaudi::Property< unsigned int > m_felixScale
Definition: TileDigitsFlxMonitorAlgorithm.h:43
TileCalibUtils::MAX_GAIN
static const unsigned int MAX_GAIN
Number of gains per channel
Definition: TileCalibUtils.h:142