ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Calorimeter
CaloCondPhysAlgs
src
CaloRescaleNoise.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
CaloRescaleNoise.h
"
6
#include "
CaloConditions/CaloNoise.h
"
7
#include "
CaloIdentifier/CaloGain.h
"
8
#include "
CaloEvent/CaloCell.h
"
9
#include "Identifier/Identifier.h"
10
#include "
CaloIdentifier/CaloCell_Base_ID.h
"
11
#include "
CaloIdentifier/CaloCell_SuperCell_ID.h
"
12
13
#include "TTree.h"
14
#include <cstdio>
15
16
//Constructor
17
CaloRescaleNoise::CaloRescaleNoise
(
const
std::string& name, ISvcLocator* pSvcLocator):
18
AthAlgorithm
(name,pSvcLocator)
19
{
20
}
21
22
//__________________________________________________________________________
23
//Destructor
24
CaloRescaleNoise::~CaloRescaleNoise
() =
default
;
25
26
//__________________________________________________________________________
27
StatusCode
CaloRescaleNoise::initialize
()
28
{
29
ATH_MSG_DEBUG
(
"CaloRescaleNoise initialize()"
);
30
ATH_CHECK
(
m_thistSvc
.retrieve());
31
32
const
CaloIdManager
* mgr =
nullptr
;
33
ATH_CHECK
(
detStore
()->retrieve( mgr ) );
34
m_calo_id
=
m_isSC
?
static_cast<
const
CaloCell_Base_ID
*
>
(mgr->getCaloCell_SuperCell_ID()) :
static_cast<
const
CaloCell_Base_ID
*
>
(mgr->getCaloCell_ID());
35
36
ATH_CHECK
(
m_elecNoiseKey
.initialize() );
37
ATH_CHECK
(
m_pileupNoiseKey
.initialize() );
38
39
ATH_CHECK
(
m_scaleCorrKey
.initialize(!
m_absScaling
) );
40
ATH_CHECK
(
m_cablingKey
.initialize());
41
ATH_CHECK
(
m_onlineScaleCorrKey
.initialize() );
42
ATH_CHECK
(
m_caloMgrKey
.initialize() );
43
ATH_CHECK
(
m_caloSCMgrKey
.initialize(
m_isSC
) );
44
45
m_tree
=
new
TTree(
"mytree"
,
"Calo Noise ntuple"
);
46
m_tree
->Branch(
"iCool"
,&
m_iCool
,
"iCool/I"
);
47
m_tree
->Branch(
"iSubHash"
,&
m_SubHash
,
"iSubHash/I"
);
48
m_tree
->Branch(
"iHash"
,&
m_Hash
,
"iHash/I"
);
49
m_tree
->Branch(
"iOffId"
,&
m_OffId
,
"iOffId/I"
);
50
m_tree
->Branch(
"eta"
,&
m_eta
,
"eta/F"
);
51
m_tree
->Branch(
"phi"
,&
m_phi
,
"phi/F"
);
52
m_tree
->Branch(
"layer"
,&
m_layer
,
"layer/I"
);
53
m_tree
->Branch(
"iGain"
,&
m_Gain
,
"iGain/I"
);
54
m_tree
->Branch(
"ElecNoise"
,&
m_elecNoise
,
"ElecNoise/F"
);
55
m_tree
->Branch(
"PileupNoise"
,&
m_pileupNoise
,
"PileupNoise/F"
);
56
m_tree
->Branch(
"ElecNoiseRescaled"
,&
m_elecNoiseRescaled
,
"ElecNoiseRescaled/F"
);
57
58
ATH_CHECK
(
m_thistSvc
->regTree(
"/file1/calonoise/mytree"
,
m_tree
) );
59
ATH_MSG_INFO
(
" end of CaloRescaleNoise::initialize "
);
60
return
StatusCode::SUCCESS;
61
}
62
//__________________________________________________________________________
63
StatusCode
CaloRescaleNoise::execute
(
const
EventContext&
/*ctx*/
)
64
{
65
ATH_MSG_DEBUG
(
"CaloRescaleNoise execute()"
);
66
return
StatusCode::SUCCESS;
67
}
68
69
//__________________________________________________________________________
70
StatusCode
CaloRescaleNoise::stop
()
71
{
72
const
EventContext& ctx = Gaudi::Hive::currentContext();
73
SG::ReadCondHandle<LArOnOffIdMapping>
cablingHdl{
m_cablingKey
,ctx};
74
const
LArOnOffIdMapping
* cabling{*cablingHdl};
75
if
(!cabling) {
76
ATH_MSG_ERROR
(
"Do not have cabling mapping from key "
<<
m_cablingKey
.key() );
77
return
StatusCode::FAILURE;
78
}
79
80
FILE* fp = std::fopen(
"calonoise.txt"
,
"w"
);
81
if
(!fp) {
82
ATH_MSG_ERROR
(
"Cannot open file calonoise.txt: "
<< strerror(errno));
83
return
StatusCode::FAILURE;
84
}
85
86
const
ILArHVScaleCorr
*scaleCorr =
nullptr
;
87
if
(!
m_absScaling
) {
88
SG::ReadCondHandle<ILArHVScaleCorr>
scaleCorrHdl (
m_scaleCorrKey
, ctx);
89
scaleCorr = *scaleCorrHdl;
90
}
91
SG::ReadCondHandle<ILArHVScaleCorr>
onlineScaleCorr (
m_onlineScaleCorrKey
, ctx);
92
SG::ReadCondHandle<CaloNoise>
elecNoise (
m_elecNoiseKey
, ctx);
93
SG::ReadCondHandle<CaloNoise>
pileupNoise (
m_pileupNoiseKey
, ctx);
94
95
const
CaloDetDescrManager_Base
*calodetdescrmgr=
nullptr
;
96
if
(
m_isSC
){
97
SG::ReadCondHandle<CaloSuperCellDetDescrManager>
caloSCMgrHandle{
m_caloSCMgrKey
, ctx};
98
if
( not caloSCMgrHandle.
isValid
()){
99
std::fclose(fp);
100
ATH_MSG_ERROR
(
"CaloRescaleNoise::stop: caloSCMgrHandle invalid."
);
101
return
StatusCode::FAILURE;
102
}
103
calodetdescrmgr =
static_cast<
const
CaloDetDescrManager_Base
*
>
(*caloSCMgrHandle);
104
105
}
else
{
106
SG::ReadCondHandle<CaloDetDescrManager>
caloMgrHandle{
m_caloMgrKey
, ctx};
107
if
( not caloMgrHandle.
isValid
()){
108
std::fclose(fp);
109
ATH_MSG_ERROR
(
"CaloRescaleNoise::stop: caloMgrHandle invalid."
);
110
return
StatusCode::FAILURE;
111
}
112
calodetdescrmgr =
static_cast<
const
CaloDetDescrManager_Base
*
>
(*caloMgrHandle);
113
}
114
115
int
ncell=
m_calo_id
->calo_cell_hash_max();
116
ATH_MSG_INFO
(
" start loop over Calo cells "
<< ncell );
117
for
(
int
i=0;i<ncell;i++) {
118
IdentifierHash
idHash=i;
119
Identifier
id
=
m_calo_id
->cell_id(idHash);
120
HWIdentifier
hwid=cabling->createSignalChannelID(
id
);
121
const
CaloDetDescrElement
* calodde = calodetdescrmgr->
get_element
(
id
);
122
int
subCalo;
123
IdentifierHash
idSubHash =
m_calo_id
->subcalo_cell_hash (idHash, subCalo);
124
125
int
iCool=-1;
126
if
(
m_calo_id
->is_em(
id
)) {
// EM calo
127
if
(
m_calo_id
->is_em_barrel(
id
)) {
128
if
(
m_calo_id
->pos_neg(
id
) > 0 )
129
iCool=2;
130
else
131
iCool=1;
132
}
133
if
(
m_calo_id
->is_em_endcap(
id
)) {
134
if
(
m_calo_id
->pos_neg(
id
) > 0 )
135
iCool=3;
136
else
137
iCool=0;
138
}
139
140
}
141
if
(
m_calo_id
->is_hec(
id
)) {
// HEC
142
iCool=16;
143
}
144
if
(
m_calo_id
->is_fcal(
id
)) {
// Fcal
145
iCool=32;
146
}
147
if
(
m_calo_id
->is_tile(
id
)) {
// Tile
148
iCool=48;
149
}
150
int
ii = (int) (idSubHash);
151
152
m_iCool
= iCool;
153
m_SubHash
= ii;
154
m_Hash
= i;
155
m_OffId
= (int)(
id
.get_identifier32().get_compact());
156
157
m_eta
= calodde->
eta_raw
();
158
m_phi
= calodde->
phi_raw
();
159
m_layer
=
m_calo_id
->calo_sample(
id
);
160
161
int
ngain;
162
if
(
m_isSC
) ngain=1;
163
else
if
(subCalo<3) ngain=3;
164
else
ngain=4;
165
166
float
hvcorr=1.;
167
float
hvonline=1.;
168
169
if
(iCool<48) {
170
if
(!
m_absScaling
) hvcorr = scaleCorr->
HVScaleCorr
(hwid);
171
hvonline = onlineScaleCorr->HVScaleCorr(hwid);
172
}
173
174
for
(
int
igain=0;igain<ngain;igain++) {
175
176
CaloGain::CaloGain
gain=
CaloGain::LARHIGHGAIN
;
177
if
(subCalo<3) {
178
if
(igain==0) gain=
CaloGain::LARHIGHGAIN
;
179
if
(igain==1) gain=
CaloGain::LARMEDIUMGAIN
;
180
if
(igain==2) gain=
CaloGain::LARLOWGAIN
;
181
}
182
else
{
183
if
(igain==0) gain=
CaloGain::TILELOWLOW
;
184
if
(igain==1) gain=
CaloGain::TILELOWHIGH
;
185
if
(igain==2) gain=
CaloGain::TILEHIGHLOW
;
186
if
(igain==3) gain=
CaloGain::TILEHIGHHIGH
;
187
}
188
m_Gain
= igain;
189
190
m_elecNoise
= elecNoise->getNoise(
id
,gain);
191
m_pileupNoise
= pileupNoise->getNoise(
id
,gain);
192
193
if
(hvonline>0.) {
194
if
(
m_absScaling
) {
195
m_elecNoiseRescaled
=
m_elecNoise
*hvonline;
196
if
(iCool<48 && m_elecNoise>0. && hvonline > 1.) {
197
ATH_MSG_WARNING
(
" Abs. scaled Noise cell "
<<
m_Hash
<<
198
" layer/ieta/iphi "
<<
m_calo_id
->sampling(
id
) <<
" "
<<
m_calo_id
->eta(
id
) <<
" "
<<
m_calo_id
->phi(
id
) <<
" OldNoise,NewNoise "
<<
199
m_elecNoise
<<
" "
<<
m_elecNoiseRescaled
);
200
}
201
}
else
{
202
m_elecNoiseRescaled
=
m_elecNoise
*hvcorr;
203
if
(iCool<48 && m_elecNoise>0. && std::fabs(
m_elecNoiseRescaled
/
m_elecNoise
-1.)>0.05) {
204
ATH_MSG_WARNING
(
" DifferentNoise cell "
<<
m_calo_id
->show_to_string(
id
) <<
205
" layer/eta/phi "
<<
m_layer
<<
" "
<<
m_eta
<<
" "
<<
m_phi
<<
" OldNoise,NewNoise "
<<
206
m_elecNoise
<<
" "
<<
m_elecNoiseRescaled
);
207
}
208
}
209
}
else
{
210
m_elecNoiseRescaled
=
m_elecNoise
;
211
}
212
213
// for SC debugging
214
if
(iCool<48) fprintf(fp,
"%10d %5d %5d %5d %8.3f %8.3f\n"
,
id
.get_identifier32().get_compact(),iCool,ii,gain,
m_elecNoiseRescaled
,
m_pileupNoise
);
215
216
m_tree
->Fill();
217
218
}
// loop over gains
219
220
}
// loop over cells
221
222
std::fclose(fp);
223
return
StatusCode::SUCCESS;
224
}
225
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_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CaloCell.h
CaloCell_Base_ID.h
Helper base class for offline cell identifiers.
CaloCell_SuperCell_ID.h
Helper class for offline supercell identifiers.
CaloGain.h
CaloNoise.h
CaloRescaleNoise.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Definition
AthCommonDataStore.h:95
CaloCell_Base_ID
Helper base class for offline cell identifiers.
Definition
CaloCell_Base_ID.h:40
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell.
Definition
Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
CaloDetDescrElement::eta_raw
float eta_raw() const
cell eta_raw
Definition
Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:350
CaloDetDescrElement::phi_raw
float phi_raw() const
cell phi_raw
Definition
Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:352
CaloDetDescrManager_Base
Definition
CaloDetDescrManager.h:145
CaloDetDescrManager_Base::get_element
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
Definition
CaloDetDescrManager.cxx:159
CaloIdManager
This class initializes the Calo (LAr and Tile) offline identifiers.
Definition
CaloIdManager.h:45
CaloRescaleNoise::m_Gain
int m_Gain
Definition
CaloRescaleNoise.h:81
CaloRescaleNoise::m_calo_id
const CaloCell_Base_ID * m_calo_id
Definition
CaloRescaleNoise.h:52
CaloRescaleNoise::m_layer
int m_layer
Definition
CaloRescaleNoise.h:80
CaloRescaleNoise::stop
virtual StatusCode stop() override
standard Athena-Algorithm method
Definition
CaloRescaleNoise.cxx:70
CaloRescaleNoise::~CaloRescaleNoise
virtual ~CaloRescaleNoise()
Default Destructor.
CaloRescaleNoise::m_elecNoiseKey
SG::ReadCondHandleKey< CaloNoise > m_elecNoiseKey
Definition
CaloRescaleNoise.h:55
CaloRescaleNoise::m_elecNoise
float m_elecNoise
Definition
CaloRescaleNoise.h:82
CaloRescaleNoise::initialize
virtual StatusCode initialize() override
standard Athena-Algorithm method
Definition
CaloRescaleNoise.cxx:27
CaloRescaleNoise::m_caloSCMgrKey
SG::ReadCondHandleKey< CaloSuperCellDetDescrManager > m_caloSCMgrKey
Definition
CaloRescaleNoise.h:69
CaloRescaleNoise::m_phi
float m_phi
Definition
CaloRescaleNoise.h:79
CaloRescaleNoise::m_pileupNoise
float m_pileupNoise
Definition
CaloRescaleNoise.h:83
CaloRescaleNoise::m_caloMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
Definition
CaloRescaleNoise.h:67
CaloRescaleNoise::m_SubHash
int m_SubHash
Definition
CaloRescaleNoise.h:75
CaloRescaleNoise::m_isSC
BooleanProperty m_isSC
Definition
CaloRescaleNoise.h:71
CaloRescaleNoise::m_Hash
int m_Hash
Definition
CaloRescaleNoise.h:76
CaloRescaleNoise::m_scaleCorrKey
SG::ReadCondHandleKey< ILArHVScaleCorr > m_scaleCorrKey
Definition
CaloRescaleNoise.h:60
CaloRescaleNoise::m_absScaling
BooleanProperty m_absScaling
Definition
CaloRescaleNoise.h:72
CaloRescaleNoise::m_OffId
int m_OffId
Definition
CaloRescaleNoise.h:77
CaloRescaleNoise::m_eta
float m_eta
Definition
CaloRescaleNoise.h:78
CaloRescaleNoise::m_pileupNoiseKey
SG::ReadCondHandleKey< CaloNoise > m_pileupNoiseKey
Definition
CaloRescaleNoise.h:57
CaloRescaleNoise::m_tree
TTree * m_tree
Definition
CaloRescaleNoise.h:85
CaloRescaleNoise::m_thistSvc
ServiceHandle< ITHistSvc > m_thistSvc
Definition
CaloRescaleNoise.h:50
CaloRescaleNoise::CaloRescaleNoise
CaloRescaleNoise(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition
CaloRescaleNoise.cxx:17
CaloRescaleNoise::execute
virtual StatusCode execute(const EventContext &ctx) override
standard Athena-Algorithm method
Definition
CaloRescaleNoise.cxx:63
CaloRescaleNoise::m_iCool
int m_iCool
Definition
CaloRescaleNoise.h:74
CaloRescaleNoise::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition
CaloRescaleNoise.h:62
CaloRescaleNoise::m_elecNoiseRescaled
float m_elecNoiseRescaled
Definition
CaloRescaleNoise.h:84
CaloRescaleNoise::m_onlineScaleCorrKey
SG::ReadCondHandleKey< ILArHVScaleCorr > m_onlineScaleCorrKey
Definition
CaloRescaleNoise.h:64
HWIdentifier
Definition
HWIdentifier.h:13
ILArHVScaleCorr
Definition
ILArHVScaleCorr.h:13
ILArHVScaleCorr::HVScaleCorr
virtual const float & HVScaleCorr(const HWIdentifier &id) const =0
IdentifierHash
This is a "hash" representation of an Identifier.
Definition
IdentifierHash.h:25
LArOnOffIdMapping
Definition
LArOnOffIdMapping.h:20
SG::ReadCondHandle
Definition
ReadCondHandle.h:40
SG::ReadCondHandle::isValid
bool isValid()
Definition
ReadCondHandle.h:205
CaloGain::CaloGain
CaloGain
Definition
CaloGain.h:11
CaloGain::LARMEDIUMGAIN
@ LARMEDIUMGAIN
Definition
CaloGain.h:18
CaloGain::TILELOWLOW
@ TILELOWLOW
Definition
CaloGain.h:12
CaloGain::LARLOWGAIN
@ LARLOWGAIN
Definition
CaloGain.h:18
CaloGain::TILELOWHIGH
@ TILELOWHIGH
Definition
CaloGain.h:13
CaloGain::TILEHIGHLOW
@ TILEHIGHLOW
Definition
CaloGain.h:14
CaloGain::TILEHIGHHIGH
@ TILEHIGHHIGH
Definition
CaloGain.h:15
CaloGain::LARHIGHGAIN
@ LARHIGHGAIN
Definition
CaloGain.h:18
Identifier
Definition
IdentifierFieldParser.cxx:14
Generated on
for ATLAS Offline Software by
1.17.0