ATLAS Offline Software
Loading...
Searching...
No Matches
LArAutoCorrNoiseCondAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
11
12#include "GaudiKernel/EventIDRange.h"
13
14LArAutoCorrNoiseCondAlg::LArAutoCorrNoiseCondAlg( const std::string& name, ISvcLocator* pSvcLocator )
15 : ::AthCondAlgorithm( name, pSvcLocator )
16 , m_LArOnOffIdMappingObjKey( "LArOnOffIdMap" )
17 , m_LArMCSymObjKey( "LArMCSym" )
18 , m_LArAutoCorrObjKey( "LArAutoCorrSym" )
19 , m_LArAutoCorrNoiseObjKey( "LArAutoCorrNoise" )
20 , m_isSuperCell( false )
21 , m_MCsym( true )
22 , m_nSampl( 4 )
23{
24 declareProperty( "LArOnOffIdMappingObjKey", m_LArOnOffIdMappingObjKey, "Key to read LArOnOffIdMapping object" );
25 declareProperty( "LArMCSymObjKey", m_LArMCSymObjKey, "Key to read LArMCSym object" );
26 declareProperty( "LArAutoCorrObjKey", m_LArAutoCorrObjKey, "Key to read LArAutoCorr object" );
27 declareProperty( "LArAutoCorrNoiseObjKey", m_LArAutoCorrNoiseObjKey, "Key to write LArAutoCorrNoise object" );
28 declareProperty( "isSuperCell", m_isSuperCell );
29 declareProperty( "MCsym", m_MCsym );
30 declareProperty( "nSampl", m_nSampl );
31}
32
34
36{
37 ATH_MSG_DEBUG( "initialize " << name() );
38
39 // ReadCondHandle initialization
41 ATH_CHECK( m_LArMCSymObjKey.initialize() );
42 ATH_CHECK( m_LArAutoCorrObjKey.initialize() );
43
44 ATH_CHECK( m_LArAutoCorrNoiseObjKey.initialize() );
45
46 // Number of gains
47 m_nGains = ( m_isSuperCell ) ? 1 : 3;
48
49 return StatusCode::SUCCESS;
50}
51
52StatusCode LArAutoCorrNoiseCondAlg::execute(const EventContext& ctx) const
53{
54
55 // WriteHandle setup
57 if ( writeHandle.isValid() ) {
58 ATH_MSG_DEBUG( "CondHandle " << writeHandle.fullKey() << " is already valid." );
59 return StatusCode::SUCCESS;
60 }
61
62 // Identifier helper
63 const LArOnlineID_Base* larOnlineID = nullptr;
64 if ( m_isSuperCell ) {
65 const LArOnline_SuperCellID* scidhelper;
66 ATH_CHECK( detStore()->retrieve( scidhelper, "LArOnline_SuperCellID" ) );
67 larOnlineID = scidhelper; // cast to base-class
68 } else { // regular cells
69 const LArOnlineID* idhelper;
70 ATH_CHECK( detStore()->retrieve( idhelper, "LArOnlineID" ) );
71 larOnlineID = idhelper; // cast to base-class
72 }
73 // Mapping helper
74 const LArOnOffIdMapping* larOnOffIdMapping = nullptr;
76 larOnOffIdMapping = *larOnOffIdMappingHdl;
77 if ( larOnOffIdMapping == nullptr ) {
78 ATH_MSG_ERROR( "Failed to retrieve LArOnOffIdMapping object" );
79 return StatusCode::FAILURE;
80 }
81 // MC symmetrization helper
82 const LArMCSym* larMCsym = nullptr;
83 if ( !m_isSuperCell && m_MCsym ) {
85 larMCsym = *larMCsymHdl;
86 if ( larMCsym == nullptr ) {
87 ATH_MSG_ERROR( "Failed to retrieve LArMCSym object" );
88 return StatusCode::FAILURE;
89 }
90 }
91
92 // Get pointers to inputs
93 // Retrieve validity ranges and determine their intersection
94 EventIDRange rangeAutoCorr;
95
97 const ILArAutoCorr* larAutoCorr{*AutoCorrHdl};
98 if ( !AutoCorrHdl.range( rangeAutoCorr ) ) {
99 ATH_MSG_ERROR( "Failed to retrieve validity range for " << AutoCorrHdl.key() );
100 }
101
102 std::vector<std::map<HWIdentifier, std::vector<float>>> terms( m_nGains );
103
104 std::vector<HWIdentifier>::const_iterator it, it_e;
105 if ( !m_isSuperCell && m_MCsym ) {
106 it = larMCsym->symIds().begin();
107 it_e = larMCsym->symIds().end();
108 } else {
109 it = larOnlineID->channel_begin();
110 it_e = larOnlineID->channel_end();
111 }
112
113 int count{0};
114
115 for ( ; it != it_e; ++it ) {
116 count++;
117 const HWIdentifier id = *it;
118
119 if ( larOnOffIdMapping->isOnlineConnected( id ) ) {
120 // the Shape is a function of gain
121 for ( unsigned int igain = 0; igain < m_nGains; igain++ ) {
122 const ILArAutoCorr::AutoCorrRef_t AC = larAutoCorr->autoCorr( id, igain );
123
124 std::vector<float> vTerms;
125 const int size = m_nSampl * m_nSampl;
126 vTerms.resize( size );
127
128 // compute sqrt to covariance matrix
129 for ( int j = 0; j < m_nSampl; j++ ) {
130 // a) diagonal terms
131 double ck = 0.;
132 for ( int k = 0; k <= j - 1; k++ ) {
133 int index = j * m_nSampl + k;
134 ck = ck + vTerms[index] * vTerms[index];
135 }
136 // diagonal term of autocorr matrix = 1
137 vTerms[j * m_nSampl + j] = sqrt( std::fabs( 1. - ck ) );
138 // b) off-diagonal terms
139 for ( int i = j + 1; i < m_nSampl; i++ ) {
140 double ck = 0;
141 for ( int k = 0; k <= j - 1; k++ ) {
142 int index1 = i * m_nSampl + k;
143 int index2 = j * m_nSampl + k;
144 ck = ck + vTerms[index1] * vTerms[index2];
145 }
146 int index = i * m_nSampl + j;
147 int index2 = j * m_nSampl + j;
148 unsigned int index3 = ( i - j ) - 1;
149 double AutoCorr = 0.;
150 if ( index3 < ( AC.size() ) ) AutoCorr = AC[index3];
151 vTerms[index] = ( AutoCorr - ck ) / vTerms[index2];
152 }
153 }
154
155 terms[igain][id] = std::move(vTerms);
156
157 } //(loop on gains)
158
159 } else // unconnected
160 for ( unsigned int igain = 0; igain < m_nGains; igain++ ) {
161 terms[igain][id] = std::vector<float>( 1, 0. );
162 }
163 }
164
165 ATH_MSG_INFO( "LArAutoCorrNoise: Ncell " << ( ( m_MCsym ) ? "w/ MCsym" : "w/o MCsym: " ) << count );
166 ATH_MSG_DEBUG( "LArAutoCorrNoise: end of loop over cells" );
167
168 // Make output object
169 std::unique_ptr<LArAutoCorrNoise> larAutoCorrNoise =
170 std::make_unique<LArAutoCorrNoise>( std::move( terms ), larMCsym );
171
172 // Write
173 ATH_CHECK( writeHandle.record( rangeAutoCorr, larAutoCorrNoise.release() ) );
174
175 return StatusCode::SUCCESS;
176}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Base class for conditions algorithms.
This class defines the interface for accessing AutoCorrelation parameters for each channel @stereotyp...
LArVectorProxy AutoCorrRef_t
virtual AutoCorrRef_t autoCorr(const HWIdentifier &CellID, int gain) const =0
SG::WriteCondHandleKey< LArAutoCorrNoise > m_LArAutoCorrNoiseObjKey
virtual StatusCode execute(const EventContext &ctx) const override
virtual StatusCode initialize() override
LArAutoCorrNoiseCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadCondHandleKey< LArOnOffIdMapping > m_LArOnOffIdMappingObjKey
virtual ~LArAutoCorrNoiseCondAlg() override
SG::ReadCondHandleKey< ILArAutoCorr > m_LArAutoCorrObjKey
SG::ReadCondHandleKey< LArMCSym > m_LArMCSymObjKey
Helper class to handle z-phi symmetry of calibration constants in MC.
Definition LArMCSym.h:19
const std::vector< HWIdentifier > & symIds() const
Return the list of symmetric hashes.
Definition LArMCSym.h:132
bool isOnlineConnected(const HWIdentifier &sid) const
Test whether a HWIdentifier is connected of not (inline)
Helper for the Liquid Argon Calorimeter cell identifiers.
id_iterator channel_end() const
id_iterator channel_begin() const
Returns an iterator pointing to a channel identifier collection.
bool range(EventIDRange &r)
const std::string & key() const
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
Definition index.py:1