ATLAS Offline Software
LArAutoCorrNoiseCondAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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  }
80  // MC symmetrization helper
81  const LArMCSym* larMCsym = nullptr;
82  if ( !m_isSuperCell && m_MCsym ) {
84  larMCsym = *larMCsymHdl;
85  if ( larMCsym == nullptr ) {
86  ATH_MSG_ERROR( "Failed to retrieve LArMCSym object" );
87  return StatusCode::FAILURE;
88  }
89  }
90 
91  // Get pointers to inputs
92  // Retrieve validity ranges and determine their intersection
93  EventIDRange rangeAutoCorr;
94 
96  const ILArAutoCorr* larAutoCorr{*AutoCorrHdl};
97  if ( !AutoCorrHdl.range( rangeAutoCorr ) ) {
98  ATH_MSG_ERROR( "Failed to retrieve validity range for " << AutoCorrHdl.key() );
99  }
100 
101  std::vector<std::map<HWIdentifier, std::vector<float>>> terms( m_nGains );
102 
103  std::vector<HWIdentifier>::const_iterator it, it_e;
104  if ( !m_isSuperCell && m_MCsym ) {
105  it = larMCsym->symIds().begin();
106  it_e = larMCsym->symIds().end();
107  } else {
108  it = larOnlineID->channel_begin();
109  it_e = larOnlineID->channel_end();
110  }
111 
112  int count{0};
113 
114  for ( ; it != it_e; ++it ) {
115  count++;
116  const HWIdentifier id = *it;
117 
118  if ( larOnOffIdMapping->isOnlineConnected( id ) ) {
119  // the Shape is a function of gain
120  for ( unsigned int igain = 0; igain < m_nGains; igain++ ) {
121  const ILArAutoCorr::AutoCorrRef_t AC = larAutoCorr->autoCorr( id, igain );
122 
123  std::vector<float> vTerms;
124  const int size = m_nSampl * m_nSampl;
125  vTerms.resize( size );
126 
127  // compute sqrt to covariance matrix
128  for ( int j = 0; j < m_nSampl; j++ ) {
129  // a) diagonal terms
130  double ck = 0.;
131  for ( int k = 0; k <= j - 1; k++ ) {
132  int index = j * m_nSampl + k;
133  ck = ck + vTerms[index] * vTerms[index];
134  }
135  // diagonal term of autocorr matrix = 1
136  vTerms[j * m_nSampl + j] = sqrt( std::fabs( 1. - ck ) );
137  // b) off-diagonal terms
138  for ( int i = j + 1; i < m_nSampl; i++ ) {
139  double ck = 0;
140  for ( int k = 0; k <= j - 1; k++ ) {
141  int index1 = i * m_nSampl + k;
142  int index2 = j * m_nSampl + k;
143  ck = ck + vTerms[index1] * vTerms[index2];
144  }
145  int index = i * m_nSampl + j;
146  int index2 = j * m_nSampl + j;
147  unsigned int index3 = ( i - j ) - 1;
148  double AutoCorr = 0.;
149  if ( index3 < ( AC.size() ) ) AutoCorr = AC[index3];
150  vTerms[index] = ( AutoCorr - ck ) / vTerms[index2];
151  }
152  }
153 
154  terms[igain][id] = vTerms;
155 
156  } //(loop on gains)
157 
158  } else // unconnected
159  for ( unsigned int igain = 0; igain < m_nGains; igain++ ) {
160  terms[igain][id] = std::vector<float>( 1, 0. );
161  }
162  }
163 
164  ATH_MSG_INFO( "LArAutoCorrNoise: Ncell " << ( ( m_MCsym ) ? "w/ MCsym" : "w/o MCsym: " ) << count );
165  ATH_MSG_DEBUG( "LArAutoCorrNoise: end of loop over cells" );
166 
167  // Make output object
168  std::unique_ptr<LArAutoCorrNoise> larAutoCorrNoise =
169  std::make_unique<LArAutoCorrNoise>( std::move( terms ), larMCsym );
170 
171  // Write
172  ATH_CHECK( writeHandle.record( rangeAutoCorr, larAutoCorrNoise.release() ) );
173 
174  return StatusCode::SUCCESS;
175 }
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:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArConditionsException.h
index
Definition: index.py:1
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
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:423
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:157
HWIdentifier
Definition: HWIdentifier.h:13
LArOnlineID_Base::channel_end
id_iterator channel_end() const
Definition: LArOnlineID_Base.cxx:1926
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
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:41
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
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:105
Trk::index2
@ index2
Definition: BoundarySurfaceFace.h:49
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArOnlineID
Definition: LArOnlineID.h:20
LArOnline_SuperCellID
Definition: LArOnline_SuperCellID.h:20
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:364
LArAutoCorrNoiseCondAlg::LArAutoCorrNoiseCondAlg
LArAutoCorrNoiseCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArAutoCorrNoiseCondAlg.cxx:14
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:248
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:1921
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