ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArRecUtils
src
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
5
#include "
LArAutoCorrNoiseCondAlg.h
"
6
7
#include "
LArElecCalib/LArConditionsException.h
"
8
9
#include "
LArIdentifier/LArOnlineID.h
"
10
#include "
LArIdentifier/LArOnline_SuperCellID.h
"
11
12
#include "GaudiKernel/EventIDRange.h"
13
14
LArAutoCorrNoiseCondAlg::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
33
LArAutoCorrNoiseCondAlg::~LArAutoCorrNoiseCondAlg
() {}
34
35
StatusCode
LArAutoCorrNoiseCondAlg::initialize
()
36
{
37
ATH_MSG_DEBUG
(
"initialize "
<< name() );
38
39
// ReadCondHandle initialization
40
ATH_CHECK
(
m_LArOnOffIdMappingObjKey
.initialize() );
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
52
StatusCode
LArAutoCorrNoiseCondAlg::execute
(
const
EventContext& ctx)
const
53
{
54
55
// WriteHandle setup
56
SG::WriteCondHandle<LArAutoCorrNoise>
writeHandle(
m_LArAutoCorrNoiseObjKey
, ctx );
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
;
75
SG::ReadCondHandle<LArOnOffIdMapping>
larOnOffIdMappingHdl{
m_LArOnOffIdMappingObjKey
, ctx};
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
) {
84
SG::ReadCondHandle<LArMCSym>
larMCsymHdl{
m_LArMCSymObjKey
, ctx};
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
96
SG::ReadCondHandle<ILArAutoCorr>
AutoCorrHdl{
m_LArAutoCorrObjKey
, ctx};
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
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
LArAutoCorrNoiseCondAlg.h
LArConditionsException.h
MonDataType::AutoCorr
@ AutoCorr
Definition
LArLATOMEDecoder.h:54
LArOnlineID.h
LArOnline_SuperCellID.h
size
size_t size() const
Number of registered mappings.
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Definition
AthCommonDataStore.h:95
AthCondAlgorithm
Base class for conditions algorithms.
Definition
AthCondAlgorithm.h:22
HWIdentifier
Definition
HWIdentifier.h:13
ILArAutoCorr
This class defines the interface for accessing AutoCorrelation parameters for each channel @stereotyp...
Definition
ILArAutoCorr.h:29
ILArAutoCorr::AutoCorrRef_t
LArVectorProxy AutoCorrRef_t
Definition
ILArAutoCorr.h:33
ILArAutoCorr::autoCorr
virtual AutoCorrRef_t autoCorr(const HWIdentifier &CellID, int gain) const =0
LArAutoCorrNoiseCondAlg::m_nSampl
int m_nSampl
Definition
LArAutoCorrNoiseCondAlg.h:42
LArAutoCorrNoiseCondAlg::m_LArAutoCorrNoiseObjKey
SG::WriteCondHandleKey< LArAutoCorrNoise > m_LArAutoCorrNoiseObjKey
Definition
LArAutoCorrNoiseCondAlg.h:36
LArAutoCorrNoiseCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
LArAutoCorrNoiseCondAlg.cxx:52
LArAutoCorrNoiseCondAlg::m_nGains
unsigned int m_nGains
Definition
LArAutoCorrNoiseCondAlg.h:41
LArAutoCorrNoiseCondAlg::initialize
virtual StatusCode initialize() override
Definition
LArAutoCorrNoiseCondAlg.cxx:35
LArAutoCorrNoiseCondAlg::LArAutoCorrNoiseCondAlg
LArAutoCorrNoiseCondAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
LArAutoCorrNoiseCondAlg.cxx:14
LArAutoCorrNoiseCondAlg::m_LArOnOffIdMappingObjKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_LArOnOffIdMappingObjKey
Definition
LArAutoCorrNoiseCondAlg.h:31
LArAutoCorrNoiseCondAlg::~LArAutoCorrNoiseCondAlg
virtual ~LArAutoCorrNoiseCondAlg() override
Definition
LArAutoCorrNoiseCondAlg.cxx:33
LArAutoCorrNoiseCondAlg::m_LArAutoCorrObjKey
SG::ReadCondHandleKey< ILArAutoCorr > m_LArAutoCorrObjKey
Definition
LArAutoCorrNoiseCondAlg.h:34
LArAutoCorrNoiseCondAlg::m_LArMCSymObjKey
SG::ReadCondHandleKey< LArMCSym > m_LArMCSymObjKey
Definition
LArAutoCorrNoiseCondAlg.h:32
LArAutoCorrNoiseCondAlg::m_isSuperCell
bool m_isSuperCell
Definition
LArAutoCorrNoiseCondAlg.h:38
LArAutoCorrNoiseCondAlg::m_MCsym
bool m_MCsym
Definition
LArAutoCorrNoiseCondAlg.h:39
LArMCSym
Helper class to handle z-phi symmetry of calibration constants in MC.
Definition
LArMCSym.h:19
LArMCSym::symIds
const std::vector< HWIdentifier > & symIds() const
Return the list of symmetric hashes.
Definition
LArMCSym.h:132
LArOnOffIdMapping
Definition
LArOnOffIdMapping.h:20
LArOnOffIdMapping::isOnlineConnected
bool isOnlineConnected(const HWIdentifier &sid) const
Test whether a HWIdentifier is connected of not (inline) .
Definition
LArOnOffIdMapping.h:121
LArOnlineID_Base
Helper for the Liquid Argon Calorimeter cell identifiers.
Definition
LArOnlineID_Base.h:97
LArOnlineID_Base::channel_end
id_iterator channel_end() const
Definition
LArOnlineID_Base.cxx:1637
LArOnlineID_Base::channel_begin
id_iterator channel_begin() const
Returns an iterator pointing to a channel identifier collection.
Definition
LArOnlineID_Base.cxx:1632
LArOnlineID
Definition
LArOnlineID.h:21
LArOnline_SuperCellID
Definition
LArOnline_SuperCellID.h:21
SG::ReadCondHandle
Definition
ReadCondHandle.h:40
SG::ReadCondHandle::range
bool range(EventIDRange &r)
Definition
ReadCondHandle.h:223
SG::ReadCondHandle::key
const std::string & key() const
Definition
ReadCondHandle.h:59
SG::WriteCondHandle
Definition
WriteCondHandle.h:26
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition
WriteCondHandle.h:161
SG::WriteCondHandle::isValid
bool isValid() const
Definition
WriteCondHandle.h:252
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition
WriteCondHandle.h:45
count
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
Definition
hcg.cxx:148
index
Definition
index.py:1
Generated on
for ATLAS Offline Software by
1.17.0