ATLAS Offline Software
Loading...
Searching...
No Matches
LArAutoCorrExtrapolate.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5/********************************************************************
6
7 NAME: LArAutoCorrExtrapolate.cxx
8 PACKAGE: offline/LArCalorimeter/LArCalibUtils
9
10 AUTHORS: G.Unal
11 CREATED: Sept 2008
12
13 PURPOSE: extrapolate autocorr from High gain from random to Low /Medium Gain
14 (from medium to low for HEC)
15
16 HISTORY:
17
18********************************************************************/
19
20// Include files
24
27
29
30
31LArAutoCorrExtrapolate::LArAutoCorrExtrapolate(const std::string& name, ISvcLocator* pSvcLocator)
32 : AthAlgorithm(name, pSvcLocator),
33 m_onlineId(nullptr)
34{
35 m_useBad=true;
36 declareProperty("KeyOutput", m_keyoutput="LArAutoCorr");
37 declareProperty("keyPedestal", m_keyPedestal="Pedestal");
38 declareProperty("keyAutoInput", m_keyinput="LArAutoCorrElec");
39 declareProperty("keyPedInput", m_keyPedInput="PedestalElec");
40 declareProperty("keyRamp", m_keyRamp="LArRamp");
41 declareProperty("nSamples", m_Nsamples=5);
42}
43
44
46= default;
47
49{
50 ATH_MSG_INFO ( ">>> Initialize" );
51
52 if (m_BFKey.initialize().isFailure()) {
53 ATH_MSG_WARNING ( "No bad febs key" );
54 m_useBad=false;
55 }
56
57 ATH_CHECK(m_cablingKey.initialize());
58
59 return StatusCode::SUCCESS;
60}
61
62
63//---------------------------------------------------------------------------
65{
66 return StatusCode::SUCCESS;
67}
68
69
70//---------------------------------------------------------------------------
72{
73 ATH_MSG_INFO ( ">>> stop()" );
74
75 ATH_CHECK( detStore()->retrieve(m_onlineId, "LArOnlineID") );
77 const LArOnOffIdMapping* cabling{*cablingHdl};
78 if(!cabling){
79 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key() );
80 return StatusCode::FAILURE;
81 }
82
83 LArAutoCorrComplete* larAutoCorrComplete = nullptr;
84 ATH_CHECK( detStore()->retrieve(larAutoCorrComplete,m_keyoutput) );
85 ATH_MSG_INFO ( " Got computed Autocorrelation from physics " );
86
87 const LArAutoCorrComplete* larAutoCorrElec = nullptr;
88 ATH_CHECK( detStore()->retrieve(larAutoCorrElec,m_keyinput) );
89 ATH_MSG_INFO ( " Got electronics noise autocorrelation from database " );
90
91 const LArPedestalComplete* larPedestalElec = nullptr;
92 ATH_CHECK( detStore()->retrieve(larPedestalElec,m_keyPedInput) );
93 ATH_MSG_INFO ( " Got pedestal from database " );
94
95 const ILArRamp* larRamp = nullptr;
96 ATH_CHECK( detStore()->retrieve(larRamp,m_keyRamp) );
97 ATH_MSG_INFO ( " Got ramp from database " );
98
100 const LArBadFebCont *bfCont {*readHandle};
101 if ( bfCont == nullptr) {
102 ATH_MSG_WARNING("Failed to retrieve BadFebCont with key "<<m_BFKey.key() );
103 m_useBad=false;
104 }
105
106// loop over channels
107 std::vector<HWIdentifier>::const_iterator it = m_onlineId->channel_begin();
108 std::vector<HWIdentifier>::const_iterator it_e = m_onlineId->channel_end();
109 for (;it!=it_e;++it) {
110 HWIdentifier hwid = (*it);
111
112// skip disconnected channels
113
114 if (!(cabling->isOnlineConnected(hwid))) continue;
115
116// if HEC , correct low gain, otherwise correct Medium and Low
119 if (m_onlineId->isHECchannel(hwid)) {
121 gain1 = CaloGain::LARLOWGAIN;
122 }
124
125 ATH_MSG_VERBOSE ( " hwid,gain0,gain1,gain2 " << m_onlineId->channel_name(hwid) << " " << gain0 << " " << gain1 << " " << gain2 );
126
127// get AutoCorr for highest gain, physics event
128 ILArAutoCorr::AutoCorrRef_t corr=larAutoCorrComplete->autoCorr(hwid,gain0);
129 ATH_MSG_VERBOSE ( " corr.size() " << corr.size() );
130
131// get electronics noise + autocorrelation from pedestal run for highest gain
132 float sigma0_elec;
133 if (larPedestalElec->pedestalRMS(hwid,gain0)>=(1.0+LArElecCalib::ERRORCODE))
134 sigma0_elec = larPedestalElec->pedestalRMS(hwid,gain0);
135 else {
136 ATH_MSG_WARNING ( " Cannot not find elec pedestal RMS " << m_onlineId->channel_name(hwid) );
137 continue;
138 }
139 ILArAutoCorr::AutoCorrRef_t corr0_elec = larAutoCorrElec->autoCorr(hwid,gain0);
140 ATH_MSG_VERBOSE ( " sigma0_elec " << sigma0_elec << " corr0_ele.size() " << corr0_elec.size() );
141 if (corr0_elec.size()==0) {
142 ATH_MSG_WARNING ( " cannot find elec autocorr " << m_onlineId->channel_name(hwid) );
143 continue;
144 }
145
146 {
147 msg() << MSG::VERBOSE << " corr0_elec ";
148 unsigned int ii=0;
149 for (;ii<corr0_elec.size();ii++)
150 msg() << MSG::VERBOSE << corr0_elec[ii] << " ";
151 msg() << MSG::VERBOSE << endmsg;
152 }
153
154 float sigma0_elec2 = sigma0_elec*sigma0_elec;
155
156// in case of some channels with missing data, try to recover using electronics autocorrelation only
157 std::vector<float> corr2;
158 bool recovered=false;
159 if (corr.size()==0) {
160 HWIdentifier febId = m_onlineId->feb_Id(hwid);
161 if (m_useBad && (!bfCont->status(febId).good()) ) {
162 ATH_MSG_DEBUG ( " Known missing Feb, no physics autocorr " << m_onlineId->channel_name(hwid) << "... use electronics from db " );
163 } else {
164 ATH_MSG_WARNING ( " No physics autocorr for channel " << m_onlineId->channel_name(hwid) << " .. use electronics from db" );
165 }
166 if (corr0_elec.size()==0) {
167 ATH_MSG_WARNING ( " No physics and no electronics autocorrelation available " << m_onlineId->channel_name(hwid) );
168 continue;
169 }
170 int n = m_Nsamples;
171 if (corr0_elec.size()<(unsigned int)(n-1)) n = corr0_elec.size()+1;
172 unsigned int size = n*(n+1)/2;
173 std::vector<float> corr2;
174 corr2.resize(size,0.);
175 unsigned k=0;
176 for (int i=0;i<n;i++) {
177 for (int j=i;j<n;j++,k++) {
178 if (i==j) corr2[k]=sigma0_elec2;
179 else corr2[k]=corr0_elec[j-i-1]*sigma0_elec2;
180 }
181 }
182 larAutoCorrComplete->set(hwid,gain0,corr2);
183 recovered=true;
184 }
185
186
187// loop over gains to correct
188 for (int gain=gain1;gain<=gain2;gain++) {
189
190// for Presampler skip lowgain
191 if (m_onlineId->isEMBPS(hwid) && gain==CaloGain::LARLOWGAIN) continue;
192
193 // get electronics noise autocorrelation
194 ILArAutoCorr::AutoCorrRef_t corr_elec = larAutoCorrElec->autoCorr(hwid,gain);
195 if (corr_elec.size()==0) {
196 ATH_MSG_WARNING ( " cannot find elec autocorr " << m_onlineId->channel_name(hwid) );
197 continue;
198 }
199 {
200 msg() << MSG::VERBOSE << " corr_elec ";
201 unsigned int ii=0;
202 for (;ii<corr_elec.size();ii++)
203 msg() << MSG::VERBOSE << corr_elec[ii] << " ";
204 msg() << MSG::VERBOSE << endmsg;
205 }
206
207
208 // get electronic noise in ADC counts
209 float sigma_elec;
210 if (larPedestalElec->pedestalRMS(hwid,gain) >= (1.0+LArElecCalib::ERRORCODE))
211 sigma_elec = larPedestalElec->pedestalRMS(hwid,gain);
212 else {
213 ATH_MSG_WARNING ( " cannot find elec noise RMS " << m_onlineId->channel_name(hwid) );
214 continue;
215 }
216 ATH_MSG_VERBOSE ( " sigma_elec " << sigma_elec << " corr_elec.size() " << corr_elec.size() );
217 float sigma_elec2 = sigma_elec*sigma_elec;
218
219 // extrapolate to high gain using ramp
220 float ratio=0.1;
221 if (gain0==CaloGain::LARHIGHGAIN && gain==CaloGain::LARLOWGAIN) ratio=0.01;
222 const ILArRamp::RampRef_t rampcoeff=larRamp->ADC2DAC(hwid, gain);
223 const ILArRamp::RampRef_t rampcoeff0=larRamp->ADC2DAC(hwid, gain0);
224 if (rampcoeff.size()>1 && rampcoeff0.size()>1) {
225 float ramp1 = rampcoeff[1];
226 float ramp0 = rampcoeff0[1];
227 if (ramp1>0.01 && ramp0>0.01 && ramp1<1e4 && ramp0<1e4) ratio = ramp0/ramp1;
228 }
229 //float ratio2=ratio*ratio;
230 ATH_MSG_VERBOSE ( " gain ratio " << ratio );
231
232// compute new autocorrelation
233
234 std::vector<float> new_corr;
235 if (!recovered) new_corr.reserve(corr.size());
236 else new_corr.reserve(corr2.size());
237
238 unsigned int k=0;
239 for (int i=0;i<m_Nsamples;i++) {
240 for (int j=i;j<m_Nsamples;j++,k++) {
241 float rij_0=0.;
242 if (!recovered) {
243 if (k<corr.size()) rij_0 = corr[k];
244 }
245 else {
246 if (k<corr2.size()) rij_0 = corr2[k];
247 }
248
249 float corre0 = 0. ;
250 float corre = 0. ;
251 if (i==j) {
252 corre0=1.;
253 corre=1.;
254 }
255 else {
256 unsigned int index = j-i-1;
257 if (index<corr0_elec.size()) corre0=corr0_elec[index];
258 if (index<corr_elec.size()) corre=corr_elec[index];
259 }
260 float rij_tot = rij_0*ratio - sigma0_elec2*corre0*ratio + sigma_elec2*corre;
261 new_corr.push_back(rij_tot);
262 }
263 }
264
265 {
266 msg() << MSG::VERBOSE << " old corr ";
267 if (corr.size()>=((unsigned int)(m_Nsamples*(m_Nsamples+1)/2))) {
268 unsigned k=0;
269 for (int i=0;i<m_Nsamples;i++) {
270 for (int j=i;j<m_Nsamples;j++,k++)
271 msg() << MSG::VERBOSE << corr[k] << " ";
272 msg() << MSG::VERBOSE << endmsg;
273 }
274 }
275 }
276 {
277 msg() << MSG::VERBOSE << " new corr ";
278 unsigned k=0;
279 for (int i=0;i<m_Nsamples;i++) {
280 for (int j=i;j<m_Nsamples;j++,k++)
281 msg() << MSG::VERBOSE << new_corr[k] << " ";
282 msg() << MSG::VERBOSE << endmsg;
283 }
284 }
285
286// save new extrapolation
287 larAutoCorrComplete->set(hwid,gain,new_corr);
288
289
290 } // loop over gains
291
292 } // loop over channels
293
294 return StatusCode::SUCCESS;
295}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
LArBadXCont< LArBadFeb > LArBadFebCont
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
MsgStream & msg() const
LArVectorProxy AutoCorrRef_t
virtual RampRef_t ADC2DAC(const HWIdentifier &id, int gain) const =0
LArVectorProxy RampRef_t
This class defines the interface for accessing Ramp @stereotype Interface.
Definition ILArRamp.h:31
This class implements the ILArAutoCorr interface.
virtual AutoCorrRef_t autoCorr(const HWIdentifier &CellID, int gain) const
void set(const HWIdentifier &CellID, int gain, const std::vector< float > &vAutoCorr)
const LArOnlineID * m_onlineId
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
LArAutoCorrExtrapolate(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadCondHandleKey< LArBadFebCont > m_BFKey
bool good() const
Returns true if no problems at all (all bits at zero)
Definition LArBadFeb.h:27
LArBC_t status(const HWIdentifier channel) const
Query the status of a particular channel or FEB This is the main client access method.
This class implements the ILArPedestal interface.
virtual float pedestalRMS(const HWIdentifier &CellID, int gain) const override
access to RMS of Pedestal index by Identifier, and gain setting
@ LARMEDIUMGAIN
Definition CaloGain.h:18
@ LARLOWGAIN
Definition CaloGain.h:18
@ LARHIGHGAIN
Definition CaloGain.h:18
Definition index.py:1