ATLAS Offline Software
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
23 #include "LArElecCalib/ILArRamp.h"
24 
27 
29 
30 
31 LArAutoCorrExtrapolate::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 
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)) {
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;
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 }
LArAutoCorrExtrapolate::m_Nsamples
int m_Nsamples
Definition: LArAutoCorrExtrapolate.h:62
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArAutoCorrExtrapolate::~LArAutoCorrExtrapolate
~LArAutoCorrExtrapolate()
LArAutoCorrExtrapolate.h
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArAutoCorrExtrapolate::initialize
StatusCode initialize()
Definition: LArAutoCorrExtrapolate.cxx:48
index
Definition: index.py:1
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArAutoCorrExtrapolate::m_keyRamp
std::string m_keyRamp
Definition: LArAutoCorrExtrapolate.h:60
LArBadXCont
Conditions-Data class holding LAr Bad Channel or Bad Feb information.
Definition: LArBadChannelCont.h:28
LArPedestalComplete
This class implements the ILArPedestal interface.
Definition: LArPedestalComplete.h:26
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
CaloTime_fillDB.gain2
gain2
Definition: CaloTime_fillDB.py:357
skel.it
it
Definition: skel.GENtoEVGEN.py:423
LArAutoCorrComplete::set
void set(const HWIdentifier &CellID, int gain, const std::vector< float > &vAutoCorr)
Definition: LArAutoCorrComplete.cxx:13
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
HWIdentifier
Definition: HWIdentifier.h:13
LArOnlineID_Base::channel_end
id_iterator channel_end() const
Definition: LArOnlineID_Base.cxx:1931
LArAutoCorrExtrapolate::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArAutoCorrExtrapolate.h:54
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
LArAutoCorrComplete
This class implements the ILArAutoCorr interface.
Definition: LArAutoCorrComplete.h:26
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArAutoCorrExtrapolate::m_useBad
bool m_useBad
Definition: LArAutoCorrExtrapolate.h:66
LArAutoCorrExtrapolate::m_keyPedestal
std::string m_keyPedestal
Definition: LArAutoCorrExtrapolate.h:57
lumiFormat.i
int i
Definition: lumiFormat.py:92
PixelAthClusterMonAlgCfg.e4
e4
Definition: PixelAthClusterMonAlgCfg.py:317
beamspotman.n
n
Definition: beamspotman.py:731
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LArAutoCorrExtrapolate::m_BFKey
SG::ReadCondHandleKey< LArBadFebCont > m_BFKey
Definition: LArAutoCorrExtrapolate.h:53
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ILArRamp
Definition: ILArRamp.h:12
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArAutoCorrExtrapolate::execute
StatusCode execute()
Definition: LArAutoCorrExtrapolate.cxx:64
CaloTime_fillDB.gain0
gain0
Definition: CaloTime_fillDB.py:355
LArAutoCorrComplete.h
LArAutoCorrExtrapolate::stop
StatusCode stop()
Definition: LArAutoCorrExtrapolate.cxx:71
LArPedestalComplete::pedestalRMS
virtual float pedestalRMS(const HWIdentifier &CellID, int gain) const override
access to RMS of Pedestal index by Identifier, and gain setting
Definition: LArPedestalComplete.h:37
AthAlgorithm
Definition: AthAlgorithm.h:47
LArOnlineID_Base::feb_Id
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
Definition: LArOnlineID_Base.cxx:1483
ILArRamp::ADC2DAC
virtual RampRef_t ADC2DAC(const HWIdentifier &id, int gain) const =0
CaloTime_fillDB.gain1
gain1
Definition: CaloTime_fillDB.py:356
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloGain::LARHIGHGAIN
@ LARHIGHGAIN
Definition: CaloGain.h:18
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
CaloGain::LARMEDIUMGAIN
@ LARMEDIUMGAIN
Definition: CaloGain.h:18
DeMoScan.index
string index
Definition: DeMoScan.py:362
ILArRamp.h
python.compareTCTs.ratio
ratio
Definition: compareTCTs.py:295
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArOnlineID_Base::isEMBPS
bool isEMBPS(const HWIdentifier id) const
Definition: LArOnlineID_Base.cxx:1665
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArPedestalComplete.h
LArAutoCorrExtrapolate::m_keyinput
std::string m_keyinput
Definition: LArAutoCorrExtrapolate.h:58
LArElecCalib::ERRORCODE
@ ERRORCODE
Definition: LArCalibErrorCode.h:17
LArAutoCorrExtrapolate::m_keyPedInput
std::string m_keyPedInput
Definition: LArAutoCorrExtrapolate.h:59
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
LArOnlineID::isHECchannel
bool isHECchannel(const HWIdentifier id) const override final
Definition: LArOnlineID.cxx:734
CaloGain::LARLOWGAIN
@ LARLOWGAIN
Definition: CaloGain.h:18
LArOnlineID_Base::channel_name
std::string channel_name(const HWIdentifier id) const
Return a string corresponding to a feedthrough name given an identifier.
Definition: LArOnlineID_Base.cxx:218
CaloGain.h
LArAutoCorrExtrapolate::m_keyoutput
std::string m_keyoutput
Definition: LArAutoCorrExtrapolate.h:56
LArAutoCorrExtrapolate::LArAutoCorrExtrapolate
LArAutoCorrExtrapolate(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArAutoCorrExtrapolate.cxx:31
LArOnlineID_Base::channel_begin
id_iterator channel_begin() const
Returns an iterator pointing to a channel identifier collection.
Definition: LArOnlineID_Base.cxx:1926
LArAutoCorrComplete::autoCorr
virtual AutoCorrRef_t autoCorr(const HWIdentifier &CellID, int gain) const
Definition: LArAutoCorrComplete.cxx:29
fitman.k
k
Definition: fitman.py:528
LArOnlineID.h
LArVectorProxy
Proxy for accessing a range of float values like a vector.
Definition: LArVectorProxy.h:38
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
LArAutoCorrExtrapolate::m_onlineId
const LArOnlineID * m_onlineId
Definition: LArAutoCorrExtrapolate.h:64