ATLAS Offline Software
Loading...
Searching...
No Matches
TileTMDBDigitsMonitorAlgorithm.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Tile includes
9
10#include <math.h>
11// Athena includes
13
14
15TileTMDBDigitsMonitorAlgorithm::TileTMDBDigitsMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator )
16 :AthMonitorAlgorithm(name, pSvcLocator)
17 , m_tileHWID(nullptr)
18{
19
20}
21
24
25
27
29
30 ATH_MSG_DEBUG("in initialize()");
31
32 ATH_CHECK( detStore()->retrieve(m_tileHWID) );
33
34 ATH_CHECK( m_digitsContainerKey.initialize() );
35
36 using Tile = TileCalibUtils;
37 using namespace Monitored;
38
39 m_hfnGroups = buildToolMap<int>(m_tools, "TMDB_DigitsHFN", Tile::MAX_ROS - 1);
40 m_pedGroups = buildToolMap<int>(m_tools, "TMDB_DigitsPedestal", Tile::MAX_ROS - 1);
41 m_ampGroups = buildToolMap<int>(m_tools, "TMDB_DigitsAmplitude", Tile::MAX_ROS - 1);
42
43
44 if (m_nChannels.size() != (Tile::MAX_ROS - 1)) {
45 ATH_MSG_FATAL( "Size of NumberOfChannels should be 4 (LBA, LBC, EBA, EBC), but is " << m_nChannels.size() );
46 return StatusCode::FAILURE;
47 }
48
49 std::vector<std::string> partitionName = {"LBA", "LBC", "EBA", "EBC"}; // ROS - 1 to partition name map
50 for (unsigned int partition = 0; partition < Tile::MAX_ROS-1; ++partition) {
52 "TMDB_DigitsCellPedestal_" + partitionName[partition],
53 m_nChannels[partition]));
55 "TMDB_DigitsCellHFN_" + partitionName[partition],
56 m_nChannels[partition]));
58 "TMDB_DigitsCellAmplitude_" + partitionName[partition],
59 m_nChannels[partition]));
60 }
61
62 return StatusCode::SUCCESS;
63}
64
65
66StatusCode TileTMDBDigitsMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
67
68 ATH_MSG_DEBUG( "in fillHistograms()" );
69 using Tile = TileCalibUtils;
70 std::vector<int> drawers[Tile::MAX_ROS - 1];
71 std::vector<int> channels[Tile::MAX_ROS - 1];
72 std::vector<float> pedestals[Tile::MAX_ROS - 1];
73 std::vector<float> amplitudes[Tile::MAX_ROS - 1];
74 std::vector<float> hfns[Tile::MAX_ROS - 1];
75 static constexpr int TMDB_MAX_CHANNEL = 8;
76 std::vector<float> cellPedestals[Tile::MAX_ROS - 1][TMDB_MAX_CHANNEL];
77 std::vector<float> cellHFNs[Tile::MAX_ROS - 1][TMDB_MAX_CHANNEL];
78 std::vector<float> cellAmplitudes[Tile::MAX_ROS - 1][TMDB_MAX_CHANNEL];
79
81 ATH_CHECK( digitsContainer.isValid() );
82
83 for (IdentifierHash hash : digitsContainer->GetAllCurrentHashes()) {
84 const TileDigitsCollection* digitsCollection = digitsContainer->indexFindPtr (hash);
85
86 int fragId = digitsCollection->identify();
87 unsigned int drawer = (fragId & 0x3F);
88 unsigned int ros = fragId >> 8;
89 unsigned int partition = ros - 1;
90
91 for (const TileDigits* tile_digits : *digitsCollection) {
92
93 HWIdentifier adc_id = tile_digits->adc_HWID();
94 int channel = m_tileHWID->channel(adc_id);
95 std::vector<float> digits = tile_digits->samples();
96
97 double mean_samp = 0.0;
98 double rms_samp = 0.0;
99 unsigned int n_digits = digits.size();
100
101 for (double digit : digits) {
102 mean_samp += digit;
103 rms_samp += digit * digit;
104 }
105
106 if (n_digits > 1) {
107 drawers[partition].push_back(drawer);
108 channels[partition].push_back(channel);
109
110 double ped = digits[0];
111 pedestals[partition].push_back(ped);
112
113 mean_samp /= n_digits;
114 rms_samp = rms_samp / n_digits - mean_samp * mean_samp;
115 rms_samp = (rms_samp > 0.0) ? sqrt(rms_samp * n_digits / (n_digits - 1)) : 0.0;
116 hfns[partition].push_back(rms_samp);
117
118 //-- temporary until TMDB raw channel monitoring tool be ready --//
119
120 auto min_max = std::minmax_element(digits.begin(), digits.end());
121 float min_digit = *min_max.first;
122 float max_digit = *min_max.second;
123 float amplitude = max_digit - min_digit;
124 amplitudes[partition].push_back(amplitude);
125
126
127 //---------------------------------------------------------------//
128 if (channel < m_nChannels[partition]) {
129 cellPedestals[partition][channel].push_back(ped);
130 cellHFNs[partition][channel].push_back(rms_samp);
131 cellAmplitudes[partition][channel].push_back(amplitude);
132 }
133
134 }
135 }
136 }
137
138
139 for (unsigned int partition = 0; partition < Tile::MAX_ROS - 1; ++partition) {
140 if (!pedestals[partition].empty()) {
141 auto monModule = Monitored::Collection("module", drawers[partition]);
142 auto monChannel = Monitored::Collection("channel", channels[partition]);
143 auto monPedestal = Monitored::Collection("pedestal", pedestals[partition]);
144 fill(m_tools[m_pedGroups[partition]], monModule, monChannel, monPedestal);
145
146 auto monHFN = Monitored::Collection("HFN", hfns[partition]);
147 fill(m_tools[m_hfnGroups[partition]], monModule, monChannel, monHFN);
148
149 auto monAmplitude = Monitored::Collection("amplitude", amplitudes[partition]);
150 fill(m_tools[m_ampGroups[partition]], monModule, monChannel, monAmplitude);
151
152 for (int channel = 0; channel < int(m_nChannels[partition]); ++channel) {
153 if (!cellPedestals[partition][channel].empty()) {
154 auto monPedestal = Monitored::Collection("pedestal", cellPedestals[partition][channel]);
155 fill(m_tools[m_cellPedGroups[partition][channel]], monPedestal);
156 }
157 if (!cellHFNs[partition][channel].empty()) {
158 auto monHFN = Monitored::Collection("HFN", cellHFNs[partition][channel]);
159 fill(m_tools[m_cellHFNGroups[partition][channel]], monHFN);
160 }
161 if (!cellAmplitudes[partition][channel].empty()) {
162 auto monAmplitude = Monitored::Collection("amplitude", cellAmplitudes[partition][channel]);
163 fill(m_tools[m_cellAmpGroups[partition][channel]], monAmplitude);
164 }
165 }
166 }
167 }
168
169
170 return StatusCode::SUCCESS;
171}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
static const Attributes_t empty
const ServiceHandle< StoreGateSvc > & detStore() const
virtual StatusCode initialize() override
initialize
AthMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
This is a "hash" representation of an Identifier.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Static class providing several utility functions and constants.
SG::ReadHandleKey< TileDigitsContainer > m_digitsContainerKey
std::vector< std::vector< int > > m_cellAmpGroups
Gaudi::Property< std::vector< int > > m_nChannels
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
TileTMDBDigitsMonitorAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< std::vector< int > > m_cellHFNGroups
virtual StatusCode initialize() override
initialize
std::vector< std::vector< int > > m_cellPedGroups
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.
void fill(H5::Group &out_file, size_t iterations)