ATLAS Offline Software
LArAutoCorrValidationAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <cmath>
8 
9 LArAutoCorrValidationAlg::LArAutoCorrValidationAlg(const std::string& name, ISvcLocator* pSvcLocator) :
10  LArAutoCorrValidationBase(name,pSvcLocator) {
11 
12  declareProperty("AutoCorrTolerance",m_covToleranceInit,
13  "CaloCellGroup of allowed deviation of cov[i]");
14  declareProperty("AutoCorrToleranceFEB",m_covToleranceFEBInit,
15  "CaloCellGroup of allowed deviation of cov[i] (average over one FEB,");
16 
17  declareProperty("NSamplesToCheck",m_nSamplesToCheck=1,
18  "Number of samples (covr elements) to check");
19 
20 
21  declareProperty("CheckFifthSample",m_checkFifthSample=false);
22  m_covGlobalRef=0.;
23  m_covGlobalVal=0.;
25 }
26 
27 
29  m_covGlobalRef=0.;
30  m_covGlobalVal=0.;
32 
33  bool stat;
34 
35  ATH_MSG_INFO ( "Initialize covariance tolerances (CaloCellGroup)" ) ;
37  if (!stat) {
38  ATH_MSG_ERROR ( "Failed to initialize CaloCellGroup of covariance tolerances!" ) ;
39  return StatusCode::FAILURE;
40  }
41  if (m_covTolerance.getDefaults().size()!=3) {
42  ATH_MSG_ERROR ( "Configuration error: Expected three covariance tolerance values (one per gain), got "
43  << m_covTolerance.getDefaults().size() ) ;
44  return StatusCode::FAILURE;
45  }
46  if (this->msgLvl(MSG::DEBUG)) m_covTolerance.printDef();//for debugging....
47 
48 
49 
50  ATH_MSG_INFO ( "Initialize covariance FEB tolerances (CaloCellGroup)" ) ;
52  if (!stat) {
53  ATH_MSG_ERROR ( "Failed to initialize CaloCellGroup of covariance tolerances!" ) ;
54  return StatusCode::FAILURE;
55  }
56  if (m_covToleranceFEB.getDefaults().size()!=3) {
57  ATH_MSG_ERROR ( "Configuration error: Expected three covariance tolerance values (one per gain), got "
58  << m_covToleranceFEB.getDefaults().size() ) ;
59  return StatusCode::FAILURE;
60  }
61  if (this->msgLvl(MSG::DEBUG)) m_covToleranceFEB.printDef();//for debugging....
62 
63 
64  return StatusCode::SUCCESS;
65 
66 }
67 
69 
70 if (gain<0 || gain>2) {
71  ATH_MSG_ERROR ( "Unexpected gain value " << gain ) ;
72  return false;
73  }
74 
75  if (val.m_vAutoCorr.size()==0) {
76  msg() << this->m_myMsgLvl << "Empty! No AC found for " << channelDescription(chid,cabling, bcCont, gain) << endmsg;
77  return false;
78  }
79  if (ref.m_vAutoCorr.size()==0) {
80  ATH_MSG_WARNING ( "No reference value found for " << channelDescription(chid,cabling, bcCont, gain) ) ;
81  return false;
82  }
83 
84  const float covVal=val.m_vAutoCorr[0];
85  const float covRef=ref.m_vAutoCorr[0];
86 
87  const Identifier id=cabling->cnvToIdentifier(chid);
88 
89  const float covTolerance=m_covTolerance.valuesForCell(id)[gain];
90 
91 
92  HWIdentifier febid=m_onlineHelper->feb_Id(chid);
93  DataPerFEB* dataPerFEB = m_vDataPerFEB.empty() ? nullptr : &(m_vDataPerFEB.back());
94  if (!dataPerFEB || dataPerFEB->febid!=febid) {//Got to new FEB
95  m_vDataPerFEB.push_back(DataPerFEB(chid,febid,gain));
96  dataPerFEB=&(m_vDataPerFEB.back());
97  }
98  dataPerFEB->covVal+=covVal;
99  dataPerFEB->covRef+=covRef;
100  ++(dataPerFEB->nEntries);
101 
102  m_covGlobalVal+=covVal;
103  m_covGlobalRef+=covRef;
105 
106  const size_t s=val.m_vAutoCorr.size();
107  const size_t sr=ref.m_vAutoCorr.size();
108  for (size_t i=0;i<s;++i) {
109  const float covVal_i=val.m_vAutoCorr[i];
110  if (fabs(covVal_i)>1.0) {
111  msg() << this->m_myMsgLvl << "Unphysical! " << channelDescription(chid, cabling, bcCont, gain) << " AutoCorr[" << i << "]: "
112  << std::setprecision(4) << covVal_i << endmsg;
113  return false;
114  }
115  if (m_checkFifthSample and i==5 and fabs(covVal_i)>0.13) {
116  msg() << this->m_myMsgLvl << "LARGE Autocorr sample 5 " << channelDescription(chid, cabling, bcCont, gain) << " AutoCorr[" << i << "]: " << covVal_i << endmsg;
117  return false;
118  }
119  if (i<m_nSamplesToCheck && i<sr) {
120  const float covRef_i=ref.m_vAutoCorr[i];
121  if (fabs(covVal_i-covRef_i)> covTolerance){
123  std::stringstream devMsg;
124  devMsg.setf(std::ios::fixed,std::ios::floatfield);
125  devMsg << "Deviating! " << channelDescription(chid, cabling, bcCont,gain) << " AutoCorr[" << i << "]: " << std::setprecision(4) << covVal_i
126  <<" (" << covRef_i << ", " << std::setprecision(2) << ((covVal_i-covRef_i)/covRef_i)*100 << "%)";
127  msg() << this->m_myMsgLvl << devMsg.str() << endmsg;
128  ATH_MSG_DEBUG ( "Covariance Tolerance: " << covTolerance ) ;
129  }
131  msg() << this->m_myMsgLvl << "Channel deviation message has already been printed " << m_maxmessages << " times. Now silent..." << endmsg;
132  return false;
133  }//end if > tolerance
134  }//end if nSamplesToCheck
135  }// End loop over all samples
136  return true;
137 }
138 
139 
141  unsigned nBadFebs=0;
142  msg().precision(3);
143  msg().setf(std::ios::fixed,std::ios::floatfield);
144  for (DataPerFEB& dataPerFeb : m_vDataPerFEB) {
145  dataPerFeb.covVal/=dataPerFeb.nEntries;
146  dataPerFeb.covRef/=dataPerFeb.nEntries;
147 
148  const Identifier id=cabling->cnvToIdentifier(dataPerFeb.chid);
149  const float& covToleranceFEB=m_covToleranceFEB.valuesForCell(id)[dataPerFeb.gain];
150 
151  if (fabs(dataPerFeb.covVal-dataPerFeb.covRef)>covToleranceFEB){
152  msg() << m_myMsgLvl << "Deviating!" << channelDescription(dataPerFeb.febid, cabling, bcCont, dataPerFeb.gain,true) << "Average AutoCorr: "
153  << dataPerFeb.covVal << " (" << dataPerFeb.covRef << ")" << endmsg;
154  ++nBadFebs;
155  }
156  }
157 
158  if (nBadFebs) {
159  msg() << m_myMsgLvl << "Found " << nBadFebs << " out of " << m_vDataPerFEB.size() << " FEBs deviating from reference" << endmsg;
160  return false;
161  }
162  else {
163  ATH_MSG_INFO ( "All" << m_vDataPerFEB.size() << " FEBs withing given tolerance." ) ;
164  return true;
165  }
166 }
168  StatusCode sc=StatusCode::SUCCESS;
169  //1nd step: Check the FEB-averages:
170  if (m_doFebAverages && !febSummary(cabling, bcCont))
171  sc=StatusCode::RECOVERABLE;
172  //2nd step: Call the summary method from base-class (single-channel summary)
173  if (!LArAutoCorrValidationBase::summary(cabling, bcCont).isSuccess())
174  sc=StatusCode::RECOVERABLE;
175  //3rd step: Check the gobal averages:
176  if (m_nEntriesGlobal) {
179  }
180  ATH_MSG_INFO ( "Global autocorr average: " << m_covGlobalVal << " Referecence:" << m_covGlobalRef
181  << " Deviation:" << m_covGlobalVal-m_covGlobalRef ) ;
182  return sc;
183 }
LArAutoCorrValidationAlg::DataPerFEB
Definition: LArAutoCorrValidationAlg.h:78
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
LArCalibValidationAlg::m_onlineHelper
const LArOnlineID_Base * m_onlineHelper
Definition: LArCalibValidationAlg.h:177
LArCalibValidationAlg::m_nFailedValidation
unsigned m_nFailedValidation
Number of channels for which vaildateChannel returned false.
Definition: LArCalibValidationAlg.h:221
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArAutoCorrValidationAlg::m_nSamplesToCheck
unsigned m_nSamplesToCheck
Number of elements of the Covariance vector that should be checked.
Definition: LArAutoCorrValidationAlg.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloCellGroupList::getDefaults
const std::vector< float > & getDefaults() const
Definition: CaloCellGroup.h:72
LArBadXCont
Conditions-Data class holding LAr Bad Channel or Bad Feb information.
Definition: LArBadChannelCont.h:28
LArAutoCorrValidationAlg::m_nEntriesGlobal
unsigned m_nEntriesGlobal
Definition: LArAutoCorrValidationAlg.h:96
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
LArAutoCorrValidationAlg::m_covTolerance
CaloCellGroupList m_covTolerance
Definition: LArAutoCorrValidationAlg.h:67
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
LArAutoCorrValidationAlg::DataPerFEB::covRef
double covRef
Definition: LArAutoCorrValidationAlg.h:88
HWIdentifier
Definition: HWIdentifier.h:13
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
CaloCell_ID.h
LArAutoCorrValidationAlg::m_checkFifthSample
bool m_checkFifthSample
Definition: LArAutoCorrValidationAlg.h:72
LArAutoCorrValidationAlg::DataPerFEB::covVal
double covVal
Definition: LArAutoCorrValidationAlg.h:87
python.SystemOfUnits.sr
int sr
Definition: SystemOfUnits.py:113
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArAutoCorrValidationAlg::validateChannel
bool validateChannel(const LArCondObj &ref, const LArCondObj &val, const HWIdentifier chid, const int gain, const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont) override final
Method to validate readout channels.
Definition: LArAutoCorrValidationAlg.cxx:68
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
LArAutoCorrValidationAlg::DataPerFEB::febid
HWIdentifier febid
Definition: LArAutoCorrValidationAlg.h:85
LArAutoCorrValidationAlg::preLoop
virtual StatusCode preLoop() override
Executed before the loop over all channels to reset global sums.
Definition: LArAutoCorrValidationAlg.cxx:28
LArCalibValidationAlg::summary
virtual StatusCode summary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont)
Method executed after the loop over all channels The implementation in the base class writes out only...
LArCalibValidationAlg::m_caloId
const CaloCell_Base_ID * m_caloId
Definition: LArCalibValidationAlg.h:178
LArAutoCorrValidationAlg::DataPerFEB::nEntries
unsigned nEntries
Definition: LArAutoCorrValidationAlg.h:89
LArCalibValidationAlg::LArCondObj
CONDITIONSCONTAINER::LArCondObj LArCondObj
Definition: LArCalibValidationAlg.h:80
beamspotman.stat
stat
Definition: beamspotman.py:266
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:1479
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
LArCalibValidationAlg::m_myMsgLvl
MSG::Level m_myMsgLvl
Message level for reporting deviations.
Definition: LArCalibValidationAlg.h:163
LArAutoCorrValidationAlg::m_covGlobalVal
double m_covGlobalVal
Definition: LArAutoCorrValidationAlg.h:95
LArAutoCorrValidationAlg::m_covToleranceFEBInit
std::vector< std::string > m_covToleranceFEBInit
Covariace tolerance of one FEB (job-Property)
Definition: LArAutoCorrValidationAlg.h:61
LArAutoCorrValidationAlg::LArAutoCorrValidationAlg
LArAutoCorrValidationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Regular algorithm constructor.
Definition: LArAutoCorrValidationAlg.cxx:9
LArAutoCorrValidationAlg::m_covToleranceFEB
CaloCellGroupList m_covToleranceFEB
Definition: LArAutoCorrValidationAlg.h:62
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ref
const boost::regex ref(r_ef)
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
DEBUG
#define DEBUG
Definition: page_access.h:11
LArAutoCorrValidationAlg::m_covGlobalRef
double m_covGlobalRef
Definition: LArAutoCorrValidationAlg.h:95
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArCalibValidationAlg::m_maxmessages
unsigned m_maxmessages
Limit for the number of messages about indiviual deviating channels (usd only by derived class)
Definition: LArCalibValidationAlg.h:213
LArCalibValidationAlg
Algorithm to validate LAr Autocorr;.
Definition: LArCalibValidationAlg.h:47
LArAutoCorrValidationAlg::m_covToleranceInit
std::vector< std::string > m_covToleranceInit
Covariance tolerance (job-Property)
Definition: LArAutoCorrValidationAlg.h:66
CaloCellGroupList::printDef
void printDef() const
Definition: CaloCellGroup.cxx:301
LArCalibValidationAlg::channelDescription
const std::string channelDescription(const HWIdentifier &chid, const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont, const unsigned gain=99, bool isFeb=false) const
Textual representation of gain and location of a certain cell or FEB.
LArAutoCorrValidationAlg::summary
virtual StatusCode summary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont) override
Summary method executed after the loop over all channels.
Definition: LArAutoCorrValidationAlg.cxx:167
CaloCellGroupList::valuesForCell
const std::vector< float > & valuesForCell(const Identifier id)
Definition: CaloCellGroup.cxx:266
LArAutoCorrValidationAlg.h
CaloCellGroupList::setDefinition
bool setDefinition(const CaloCell_Base_ID *caloCellId, const std::vector< std::string > &definitions, MsgStream &logStr)
Definition: CaloCellGroup.cxx:225
LArCalibValidationAlg::m_doFebAverages
bool m_doFebAverages
wether to compare feb-averages (used only by derived class)
Definition: LArCalibValidationAlg.h:210
LArAutoCorrValidationAlg::m_vDataPerFEB
std::vector< DataPerFEB > m_vDataPerFEB
Definition: LArAutoCorrValidationAlg.h:92
LArAutoCorrValidationAlg::febSummary
bool febSummary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont)
Method to compare FEB averages.
Definition: LArAutoCorrValidationAlg.cxx:140
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
Identifier
Definition: IdentifierFieldParser.cxx:14