ATLAS Offline Software
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 
14 LArAutoCorrNoiseCondAlg::LArAutoCorrNoiseCondAlg( const std::string& name, ISvcLocator* pSvcLocator )
15  : ::AthAlgorithm( 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
43 
45 
46  // Number of gains
47  m_nGains = ( m_isSuperCell ) ? 1 : 3;
48 
49  return StatusCode::SUCCESS;
50 }
51 
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArAutoCorrNoiseCondAlg::m_LArMCSymObjKey
SG::ReadCondHandleKey< LArMCSym > m_LArMCSymObjKey
Definition: LArAutoCorrNoiseCondAlg.h:32
SG::ReadCondHandle
Definition: ReadCondHandle.h:40
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArConditionsException.h
index
Definition: index.py:1
LArAutoCorrNoiseCondAlg::m_LArOnOffIdMappingObjKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_LArOnOffIdMappingObjKey
Definition: LArAutoCorrNoiseCondAlg.h:31
LArAutoCorrNoiseCondAlg::initialize
virtual StatusCode initialize() override
Definition: LArAutoCorrNoiseCondAlg.cxx:35
skel.it
it
Definition: skel.GENtoEVGEN.py:407
TRT_PAI_gasdata::AC
const float AC
Definition: TRT_PAI_gasdata.h:27
LArAutoCorrNoiseCondAlg::m_nSampl
int m_nSampl
Definition: LArAutoCorrNoiseCondAlg.h:42
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:161
HWIdentifier
Definition: HWIdentifier.h:13
LArOnlineID_Base::channel_end
id_iterator channel_end() const
Definition: LArOnlineID_Base.cxx:1931
XMLtoHeader.count
count
Definition: XMLtoHeader.py:84
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
ILArAutoCorr
This class defines the interface for accessing AutoCorrelation parameters for each channel @stereotyp...
Definition: ILArAutoCorr.h:29
MonDataType::AutoCorr
@ AutoCorr
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Trk::index3
@ index3
Definition: BoundarySurfaceFace.h:50
LArMCSym
Helper class to handle z-phi symmetry of calibration constants in MC.
Definition: LArMCSym.h:19
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition: WriteCondHandle.h:45
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::index1
@ index1
Definition: BoundarySurfaceFace.h:48
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition: AthCommonDataStore.h:145
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
WriteCellNoiseToCool.igain
igain
Definition: WriteCellNoiseToCool.py:338
LArAutoCorrNoiseCondAlg::m_MCsym
bool m_MCsym
Definition: LArAutoCorrNoiseCondAlg.h:39
AthAlgorithm
Definition: AthAlgorithm.h:47
LArAutoCorrNoiseCondAlg::m_isSuperCell
bool m_isSuperCell
Definition: LArAutoCorrNoiseCondAlg.h:38
LArOnlineID_Base
Helper for the Liquid Argon Calorimeter cell identifiers.
Definition: LArOnlineID_Base.h:97
Trk::index2
@ index2
Definition: BoundarySurfaceFace.h:49
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:239
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArOnlineID
Definition: LArOnlineID.h:21
LArOnline_SuperCellID
Definition: LArOnline_SuperCellID.h:21
LArAutoCorrNoiseCondAlg::m_LArAutoCorrObjKey
SG::ReadCondHandleKey< ILArAutoCorr > m_LArAutoCorrObjKey
Definition: LArAutoCorrNoiseCondAlg.h:34
LArAutoCorrNoiseCondAlg::m_LArAutoCorrNoiseObjKey
SG::WriteCondHandleKey< LArAutoCorrNoise > m_LArAutoCorrNoiseObjKey
Definition: LArAutoCorrNoiseCondAlg.h:36
DeMoScan.index
string index
Definition: DeMoScan.py:362
LArAutoCorrNoiseCondAlg::LArAutoCorrNoiseCondAlg
LArAutoCorrNoiseCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArAutoCorrNoiseCondAlg.cxx:14
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:252
LArOnline_SuperCellID.h
LArMCSym::symIds
const std::vector< HWIdentifier > & symIds() const
Return the list of symmetric hashes.
Definition: LArMCSym.h:132
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
LArAutoCorrNoiseCondAlg::execute
virtual StatusCode execute() override
Definition: LArAutoCorrNoiseCondAlg.cxx:52
LArAutoCorrNoiseCondAlg::~LArAutoCorrNoiseCondAlg
virtual ~LArAutoCorrNoiseCondAlg() override
Definition: LArAutoCorrNoiseCondAlg.cxx:33
LArOnlineID_Base::channel_begin
id_iterator channel_begin() const
Returns an iterator pointing to a channel identifier collection.
Definition: LArOnlineID_Base.cxx:1926
LArOnOffIdMapping::isOnlineConnected
bool isOnlineConnected(const HWIdentifier &sid) const
Test whether a HWIdentifier is connected of not (inline)
Definition: LArOnOffIdMapping.h:121
fitman.k
k
Definition: fitman.py:528
LArOnlineID.h
LArVectorProxy
Proxy for accessing a range of float values like a vector.
Definition: LArVectorProxy.h:38
LArAutoCorrNoiseCondAlg::m_nGains
unsigned int m_nGains
Definition: LArAutoCorrNoiseCondAlg.h:41
LArAutoCorrNoiseCondAlg.h
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20