ATLAS Offline Software
Loading...
Searching...
No Matches
CaloRescaleNoise.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 "CaloRescaleNoise.h"
9#include "Identifier/Identifier.h"
12
13#include "TTree.h"
14#include <cstdio>
15
16
17//Constructor
18CaloRescaleNoise::CaloRescaleNoise(const std::string& name, ISvcLocator* pSvcLocator):
19 AthAlgorithm(name,pSvcLocator),
20 m_calo_id(nullptr),
21 m_iCool(0),
22 m_SubHash(0),
23 m_Hash(0),
24 m_OffId(0),
25 m_eta(0),
26 m_phi(0),
27 m_layer(0),
28 m_Gain(0),
29 m_elecNoise(0),
30 m_pileupNoise (0),
32 m_tree(nullptr)
33{
34 declareProperty("absScaling",m_absScaling=false);
35}
36
37//__________________________________________________________________________
38//Destructor
40{
41 ATH_MSG_DEBUG ( "CaloRescaleNoise destructor called" );
42}
43//__________________________________________________________________________
45{
46 ATH_MSG_DEBUG ("CaloRescaleNoise initialize()" );
47 ATH_CHECK(m_thistSvc.retrieve());
48
49 const CaloIdManager* mgr = nullptr;
50 ATH_CHECK( detStore()->retrieve( mgr ) );
51 m_calo_id = m_isSC ? static_cast<const CaloCell_Base_ID*>(mgr->getCaloCell_SuperCell_ID()) : static_cast<const CaloCell_Base_ID*>(mgr->getCaloCell_ID());
52
53 ATH_CHECK( m_elecNoiseKey.initialize() );
54 ATH_CHECK( m_pileupNoiseKey.initialize() );
55
57 ATH_CHECK( m_cablingKey.initialize());
58 ATH_CHECK( m_onlineScaleCorrKey.initialize() );
59 ATH_CHECK( m_caloMgrKey.initialize() );
60 ATH_CHECK( m_caloSCMgrKey.initialize(m_isSC) );
61
62 m_tree = new TTree("mytree","Calo Noise ntuple");
63 m_tree->Branch("iCool",&m_iCool,"iCool/I");
64 m_tree->Branch("iSubHash",&m_SubHash,"iSubHash/I");
65 m_tree->Branch("iHash",&m_Hash,"iHash/I");
66 m_tree->Branch("iOffId",&m_OffId,"iOffId/I");
67 m_tree->Branch("eta",&m_eta,"eta/F");
68 m_tree->Branch("phi",&m_phi,"phi/F");
69 m_tree->Branch("layer",&m_layer,"layer/I");
70 m_tree->Branch("iGain",&m_Gain,"iGain/I");
71 m_tree->Branch("ElecNoise",&m_elecNoise,"ElecNoise/F");
72 m_tree->Branch("PileupNoise",&m_pileupNoise,"PileupNoise/F");
73 m_tree->Branch("ElecNoiseRescaled",&m_elecNoiseRescaled,"ElecNoiseRescaled/F");
74
75 ATH_CHECK( m_thistSvc->regTree("/file1/calonoise/mytree",m_tree) );
76 ATH_MSG_INFO ( " end of CaloRescaleNoise::initialize " );
77 return StatusCode::SUCCESS;
78}
79//__________________________________________________________________________
81{
82 ATH_MSG_DEBUG ("CaloRescaleNoise execute()" );
83 return StatusCode::SUCCESS;
84}
85
86//__________________________________________________________________________
88{
89 const EventContext& ctx = Gaudi::Hive::currentContext();
91 const LArOnOffIdMapping* cabling{*cablingHdl};
92 if(!cabling) {
93 ATH_MSG_ERROR( "Do not have cabling mapping from key " << m_cablingKey.key() );
94 return StatusCode::FAILURE;
95 }
96
97 FILE* fp = std::fopen("calonoise.txt","w");
98
99 const ILArHVScaleCorr *scaleCorr = nullptr;
100 if(!m_absScaling) {
102 scaleCorr = *scaleCorrHdl;
103 }
107
108 const CaloDetDescrManager_Base *calodetdescrmgr=nullptr;
109 if(m_isSC){
111 if( not caloSCMgrHandle.isValid()){
112 std::fclose(fp);
113 ATH_MSG_ERROR("CaloRescaleNoise::stop: caloSCMgrHandle invalid.");
114 return StatusCode::FAILURE;
115 }
116 calodetdescrmgr = static_cast<const CaloDetDescrManager_Base *>(*caloSCMgrHandle);
117
118 } else {
120 if( not caloMgrHandle.isValid()){
121 std::fclose(fp);
122 ATH_MSG_ERROR("CaloRescaleNoise::stop: caloMgrHandle invalid.");
123 return StatusCode::FAILURE;
124 }
125 calodetdescrmgr = static_cast<const CaloDetDescrManager_Base *>(*caloMgrHandle);
126 }
127
128 int ncell=m_calo_id->calo_cell_hash_max();
129 ATH_MSG_INFO ( " start loop over Calo cells " << ncell );
130 for (int i=0;i<ncell;i++) {
131 IdentifierHash idHash=i;
132 Identifier id=m_calo_id->cell_id(idHash);
133 HWIdentifier hwid=cabling->createSignalChannelID(id);
134 const CaloDetDescrElement* calodde = calodetdescrmgr->get_element(id);
135 int subCalo;
136 IdentifierHash idSubHash = m_calo_id->subcalo_cell_hash (idHash, subCalo);
137
138 int iCool=-1;
139 if (m_calo_id->is_em(id)) { // EM calo
140 if (m_calo_id->is_em_barrel(id)) {
141 if (m_calo_id->pos_neg(id) > 0 )
142 iCool=2;
143 else
144 iCool=1;
145 }
146 if (m_calo_id->is_em_endcap(id)) {
147 if (m_calo_id->pos_neg(id) > 0 )
148 iCool=3;
149 else
150 iCool=0;
151 }
152
153 }
154 if (m_calo_id->is_hec(id)) { // HEC
155 iCool=16;
156 }
157 if (m_calo_id->is_fcal(id)) { // Fcal
158 iCool=32;
159 }
160 if (m_calo_id->is_tile(id)) { // Tile
161 iCool=48;
162 }
163 int ii = (int) (idSubHash);
164
165 m_iCool = iCool;
166 m_SubHash = ii;
167 m_Hash = i;
168 m_OffId = (int)(id.get_identifier32().get_compact());
169
170 m_eta = calodde->eta_raw();
171 m_phi = calodde->phi_raw();
172 m_layer = m_calo_id->calo_sample(id);
173
174 int ngain;
175 if (m_isSC) ngain=1;
176 else if (subCalo<3) ngain=3;
177 else ngain=4;
178
179 float hvcorr=1.;
180 float hvonline=1.;
181
182 if (iCool<48) {
183 if(!m_absScaling) hvcorr = scaleCorr->HVScaleCorr(hwid);
184 hvonline = onlineScaleCorr->HVScaleCorr(hwid);
185 }
186
187 for (int igain=0;igain<ngain;igain++) {
188
190 if (subCalo<3) {
191 if (igain==0) gain=CaloGain::LARHIGHGAIN;
192 if (igain==1) gain=CaloGain::LARMEDIUMGAIN;
193 if (igain==2) gain=CaloGain::LARLOWGAIN;
194 }
195 else {
196 if (igain==0) gain=CaloGain::TILELOWLOW;
197 if (igain==1) gain=CaloGain::TILELOWHIGH;
198 if (igain==2) gain=CaloGain::TILEHIGHLOW;
199 if (igain==3) gain=CaloGain::TILEHIGHHIGH;
200 }
201 m_Gain = igain;
202
203 m_elecNoise = elecNoise->getNoise(id,gain);
204 m_pileupNoise = pileupNoise->getNoise(id,gain);
205
206 if (hvonline>0.) {
207 if (m_absScaling) {
209 if (iCool<48 && m_elecNoise>0. && hvonline > 1.) {
210 ATH_MSG_WARNING ( " Abs. scaled Noise cell " << m_Hash <<
211 " layer/ieta/iphi " << m_calo_id->sampling(id) << " " << m_calo_id->eta(id) << " " << m_calo_id->phi(id) << " OldNoise,NewNoise " <<
213 }
214 } else {
216 if (iCool<48 && m_elecNoise>0. && std::fabs(m_elecNoiseRescaled/m_elecNoise-1.)>0.05) {
217 ATH_MSG_WARNING ( " DifferentNoise cell " << m_calo_id->show_to_string(id) <<
218 " layer/eta/phi " << m_layer << " " << m_eta << " " << m_phi << " OldNoise,NewNoise " <<
220 }
221 }
222 } else {
224 }
225
226 // for SC debugging
227 if (iCool<48) fprintf(fp,"%10d %5d %5d %8.3f %8.3f\n",id.get_identifier32().get_compact(),ii,gain,m_elecNoiseRescaled,m_pileupNoise);
228
229 m_tree->Fill();
230
231 } // loop over gains
232
233 } // loop over cells
234
235 std::fclose(fp);
236 return StatusCode::SUCCESS;
237 }
238
240{
241 return StatusCode::SUCCESS;
242}
#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:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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
virtual StatusCode finalize() override
standard Athena-Algorithm method
SG::ReadCondHandleKey< ILArHVScaleCorr > m_scaleCorrKey
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