ATLAS Offline Software
Loading...
Searching...
No Matches
TileTBPulseMonitorAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
9
11
12#include <algorithm>
13
15
16 ATH_MSG_INFO("in initialize()");
18
19 ATH_CHECK( m_rawChannelContainerKey.initialize() );
20 ATH_CHECK( m_digitsContainerKey.initialize() );
21 ATH_CHECK( m_cablingSvc.retrieve() );
22 ATH_CHECK( detStore()->retrieve(m_tileHWID) );
23
25 m_t0SamplePosition = (int) m_tileInfo->ItrigSample();
26
27 std::vector<std::string> modules;
28 for (int fragID : m_fragIDs) {
29 int ros = fragID >> 8;
30 int drawer = fragID & 0x3F;
31 modules.push_back(TileCalibUtils::getDrawerString(ros, drawer));
32 }
33
34 using namespace Monitored;
35 m_pulseGroups = buildToolMap<int>(m_tools, "TilePulseShape", modules);
36 m_pulseProfileGroups = buildToolMap<int>(m_tools, "TilePulseShapeProfile", modules);
37
38 std::ostringstream os;
39 if ( m_fragIDs.size() != 0) {
40 std::sort(m_fragIDs.begin(), m_fragIDs.end());
41 for (int fragID : m_fragIDs) {
42 unsigned int ros = fragID >> 8;
43 unsigned int drawer = fragID & 0xFF;
44 std::string module = TileCalibUtils::getDrawerString(ros, drawer);
45 os << " " << module << "/0x" << std::hex << fragID << std::dec;
46 }
47 } else {
48 os << "NONE";
49 }
50
51 ATH_MSG_INFO("Monitored modules/frag ID:" << os.str());
52
53 return StatusCode::SUCCESS;
54}
55
56
57StatusCode TileTBPulseMonitorAlgorithm::fillHistograms( const EventContext& ctx ) const {
58
59 // In case you want to measure the execution time
60 auto timer = Monitored::Timer("TIME_execute");
61
62 using Tile = TileCalibUtils;
63 float amplitude[Tile::MAX_CHAN][Tile::MAX_GAIN];
64 float time[Tile::MAX_CHAN][Tile::MAX_GAIN];
65 float pedestal[Tile::MAX_CHAN][Tile::MAX_GAIN];
66
68 ATH_CHECK( rawChannelContainer.isValid() );
69
71 ATH_CHECK( digitsContainer.isValid() );
72
73 const TileFragHash& rchHashFunc = rawChannelContainer->hashFunc();
74 const TileFragHash& digitsHashFunc = digitsContainer->hashFunc();
75
76 std::vector<float> times;
77 std::vector<float> amplitudes;
78
79 for (int fragID : m_fragIDs) {
80
81 IdentifierHash hash = static_cast<IdentifierHash>(rchHashFunc(fragID));
82 const TileRawChannelCollection* rawChannelCollection = rawChannelContainer->indexFindPtr(hash);
83 if (!rawChannelCollection || rawChannelCollection->empty()) continue;
84
85
86 hash = static_cast<IdentifierHash>(digitsHashFunc(fragID));
87 const TileDigitsCollection* digitsCollection = digitsContainer->indexFindPtr(hash);
88 if (!digitsCollection || digitsCollection->empty()) continue;
89
90 memset(amplitude, 0, sizeof(amplitude));
91 memset(time, 0, sizeof(time));
92 memset(pedestal, 0, sizeof(pedestal));
93
94 for (const TileRawChannel* rch : *rawChannelCollection) {
95
96 HWIdentifier adc_id = rch->adc_HWID();
97 int channel = m_tileHWID->channel(adc_id);
98 int adc = m_tileHWID->adc(adc_id);
99
100 amplitude[channel][adc] = rch->amplitude();
101 time[channel][adc] = rch->time();
102
103 float ped = rch->pedestal();
104 ped = ped - int( (ped + 500 ) * 1e-4) * 10000; // Remove encoded problems into pedestal
105 pedestal[channel][adc] = ped;
106
107 }
108
109 HWIdentifier adc_id = digitsCollection->front()->adc_HWID();
110 int ros = m_tileHWID->ros(adc_id);
111 int drawer = m_tileHWID->drawer(adc_id);
112 std::string module = TileCalibUtils::getDrawerString(ros, drawer);
113
114 for (const TileDigits* tile_digits : *digitsCollection) {
115
116 adc_id = tile_digits->adc_HWID();
117 int channel = m_tileHWID->channel(adc_id);
118 int adc = m_tileHWID->adc(adc_id);
119
120 std::vector<float> digits = tile_digits->samples();
121 ATH_MSG_VERBOSE("Ros: " << ros
122 << " drawer: " << drawer
123 << " channel: " << channel
124 << " gain: " << adc
125 << " amp: " << amplitude[channel][adc]
126 << " time: " << time[channel][adc] );
127
128
129 std::string channelGainSuffix = "_" + std::to_string(channel) + "_" + std::to_string(adc);
130
131 times.clear();
132 auto monTimes = Monitored::Collection("time" + channelGainSuffix, times);
133
134 amplitudes.clear();
135 auto monAmplitude = Monitored::Collection("amplitude" + channelGainSuffix, amplitudes);
136
137 int sampleIdx = 0;
138 if ( time[channel][adc] != 0 && amplitude[channel][adc] > 0.) {
139 for (double digit : digits) {
140 times.push_back( (sampleIdx - m_t0SamplePosition) * 25. - time[channel][adc] );
141 amplitudes.push_back( (digit - pedestal[channel][adc] ) / amplitude[channel][adc] );
142 ++sampleIdx;
143 }
144 }
145
146 fill(m_tools[m_pulseGroups.at(module)], monTimes, monAmplitude);
147 fill(m_tools[m_pulseProfileGroups.at(module)], monTimes, monAmplitude);
148 }
149
150 }
151
152 fill("TileTBPulseMonExecuteTime", timer);
153
154 return StatusCode::SUCCESS;
155}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
Handle class for reading from StoreGate.
const ServiceHandle< StoreGateSvc > & detStore() const
virtual StatusCode initialize() override
initialize
ToolHandleArray< GenericMonitoringTool > m_tools
Array of Generic Monitoring Tools.
const T * front() const
Access the first element in the collection as an rvalue.
bool empty() const noexcept
Returns true if the collection is empty.
This is a "hash" representation of an Identifier.
A monitored timer.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Static class providing several utility functions and constants.
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
Hash table for Tile fragments (==drawers ==collections in StoreGate)
Gaudi::Property< std::string > m_tileInfoName
virtual StatusCode initialize() override
initialize
ServiceHandle< TileCablingSvc > m_cablingSvc
Name of Tile cabling service.
SG::ReadHandleKey< TileRawChannelContainer > m_rawChannelContainerKey
std::map< std::string, int > m_pulseGroups
SG::ReadHandleKey< TileDigitsContainer > m_digitsContainerKey
Gaudi::Property< std::vector< int > > m_fragIDs
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
std::map< std::string, int > m_pulseProfileGroups
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 sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
void fill(H5::Group &out_file, size_t iterations)