ATLAS Offline Software
Loading...
Searching...
No Matches
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"
9#include "Identifier/Identifier.h"
12
13#include "TTree.h"
14#include <cstdio>
15
16//Constructor
17CaloRescaleNoise::CaloRescaleNoise(const std::string& name, ISvcLocator* pSvcLocator):
18 AthAlgorithm(name,pSvcLocator)
19{
20}
21
22//__________________________________________________________________________
23//Destructor
25
26//__________________________________________________________________________
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
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//__________________________________________________________________________
64{
65 ATH_MSG_DEBUG ("CaloRescaleNoise execute()" );
66 return StatusCode::SUCCESS;
67}
68
69//__________________________________________________________________________
71{
72 const EventContext& ctx = Gaudi::Hive::currentContext();
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) {
89 scaleCorr = *scaleCorrHdl;
90 }
94
95 const CaloDetDescrManager_Base *calodetdescrmgr=nullptr;
96 if(m_isSC){
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 {
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
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) {
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 " <<
200 }
201 } else {
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 " <<
207 }
208 }
209 } else {
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helper base class for offline cell identifiers.
Helper class for offline supercell identifiers.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
Helper base class for offline cell identifiers.
This class groups all DetDescr information related to a CaloCell.
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
This class initializes the Calo (LAr and Tile) offline identifiers.
const CaloCell_Base_ID * m_calo_id
virtual StatusCode stop() override
standard Athena-Algorithm method
virtual ~CaloRescaleNoise()
Default Destructor.
SG::ReadCondHandleKey< CaloNoise > m_elecNoiseKey
virtual StatusCode initialize() override
standard Athena-Algorithm method
SG::ReadCondHandleKey< CaloSuperCellDetDescrManager > m_caloSCMgrKey
SG::ReadCondHandleKey< CaloDetDescrManager > m_caloMgrKey
BooleanProperty m_isSC
SG::ReadCondHandleKey< ILArHVScaleCorr > m_scaleCorrKey
BooleanProperty m_absScaling
SG::ReadCondHandleKey< CaloNoise > m_pileupNoiseKey
ServiceHandle< ITHistSvc > m_thistSvc
virtual StatusCode execute() override
standard Athena-Algorithm method
CaloRescaleNoise(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
SG::ReadCondHandleKey< ILArHVScaleCorr > m_onlineScaleCorrKey
virtual const float & HVScaleCorr(const HWIdentifier &id) const =0
This is a "hash" representation of an Identifier.
@ LARMEDIUMGAIN
Definition CaloGain.h:18
@ TILELOWLOW
Definition CaloGain.h:12
@ LARLOWGAIN
Definition CaloGain.h:18
@ TILELOWHIGH
Definition CaloGain.h:13
@ TILEHIGHLOW
Definition CaloGain.h:14
@ TILEHIGHHIGH
Definition CaloGain.h:15
@ LARHIGHGAIN
Definition CaloGain.h:18