ATLAS Offline Software
Loading...
Searching...
No Matches
TileRawChannelNNMaker.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
12#include <cmath>
13#include <fstream>
14#include <memory>
15#include <sstream>
16
18 ATH_CHECK( detStore()->retrieve(m_tileHWID) );
19 ATH_CHECK( m_digitsContainerKey.initialize() );
20 ATH_CHECK( m_rawChannelContainerKey.initialize() );
21 std::string weightsPath = PathResolverFindCalibFile(m_weightsFile);
22 if (weightsPath.empty()) {
23 ATH_MSG_ERROR( "Weights file not found: " << m_weightsFile );
24 return StatusCode::FAILURE;
25 }
26
27 std::ifstream weightsStream(weightsPath);
28 std::stringstream weightsText;
29 weightsText << weightsStream.rdbuf();
30 std::string error;
31 if (!m_nn.load(weightsText.str(), error)) {
32 ATH_MSG_ERROR( "Invalid weights file " << weightsPath << ": " << error );
33 return StatusCode::FAILURE;
34 }
35
36 m_ampPerCode = std::ldexp(m_nn.amplitudeScale(), -m_nn.outFracBits());
37 ATH_MSG_INFO( "Input digits container: '" << m_digitsContainerKey.key()
38 << "' output container: '" << m_rawChannelContainerKey.key()
39 << "' weights: '" << m_weightsFile.value()
40 << "' (" << m_nn.nSamples() << " samples)" );
41
42 return StatusCode::SUCCESS;
43}
44
45StatusCode TileRawChannelNNMaker::execute(const EventContext& ctx) const {
47 ATH_CHECK( digitsContainer.isValid() );
48 auto rawChannelContainer = std::make_unique<TileMutableRawChannelContainer>(
50
51 ATH_CHECK( rawChannelContainer->status() );
52 const int nSamples = m_nn.nSamples();
53 std::vector<float> s(nSamples);
54
55 for (const TileDigitsCollection* digitsCollection : *digitsContainer) {
57
58 for (const TileDigits* tileDigits : *digitsCollection) {
59 HWIdentifier adcId = tileDigits->adc_HWID();
60 digits[m_tileHWID->adc(adcId)][m_tileHWID->channel(adcId)] = tileDigits;
61 }
62
63 for (unsigned int channel = 0; channel < TileCalibUtils::MAX_CHAN; ++channel) {
64 const TileDigits* loGainDigits = digits[TileHWID::LOWGAIN][channel];
65 const TileDigits* hiGainDigits = digits[TileHWID::HIGHGAIN][channel];
66 if (!loGainDigits || !hiGainDigits) {
67 if (loGainDigits || hiGainDigits) ++m_nMissingGain;
68 continue;
69 }
70
71 if (loGainDigits->samples().size() != size_t(nSamples)
72 || hiGainDigits->samples().size() != size_t(nSamples)) {
74 continue;
75 }
76
77 for (int k = 0; k < nSamples; ++k) {
78 s[k] = m_nn.sValue(hiGainDigits->samples()[k], loGainDigits->samples()[k]);
79 }
80
81 float amplitude = static_cast<float>(m_nn.run(s.data()) * m_ampPerCode);
82 ATH_CHECK( rawChannelContainer->push_back(std::make_unique<TileRawChannel>(
83 loGainDigits->adc_HWID(), amplitude, 0.0F, 0.0F)) );
84 }
85 }
86
88 ATH_CHECK( rawChannelCnt.record(std::move(rawChannelContainer)) );
89
90 return StatusCode::SUCCESS;
91}
92
94 if (m_nMissingGain > 0 || m_nBadNSamples > 0) {
95 ATH_MSG_WARNING( "Skipped channels: " << m_nMissingGain << " with only one gain, "
96 << m_nBadNSamples << " without " << m_nn.nSamples() << " samples" );
97 }
98
99 return StatusCode::SUCCESS;
100}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
Helper for holding non-const raw data prior to recording in SG.
const ServiceHandle< StoreGateSvc > & detStore() const
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
static const unsigned int MAX_GAIN
Number of gains per channel.
static const unsigned int MAX_CHAN
Number of channels in drawer.
const std::vector< float > & samples() const
Definition TileDigits.h:58
@ HIGHGAIN
Definition TileHWID.h:73
@ LOWGAIN
Definition TileHWID.h:72
virtual StatusCode finalize() override
virtual StatusCode initialize() override
SG::ReadHandleKey< TileDigitsContainer > m_digitsContainerKey
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteHandleKey< TileRawChannelContainer > m_rawChannelContainerKey
Gaudi::Property< std::string > m_weightsFile
std::atomic< unsigned int > m_nBadNSamples
std::atomic< unsigned int > m_nMissingGain
HWIdentifier adc_HWID(void) const
Definition TileRawData.h:53