ATLAS Offline Software
Loading...
Searching...
No Matches
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
9LArAutoCorrValidationAlg::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);
25}
26
27
32
33 bool stat;
34
35 ATH_MSG_INFO ( "Initialize covariance tolerances (CaloCellGroup)" ) ;
36 stat=m_covTolerance.setDefinition(m_caloId,m_covToleranceInit,msg());
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
68bool LArAutoCorrValidationAlg::validateChannel(const LArCondObj& ref, const LArCondObj& val, const HWIdentifier chid, const int gain, const LArOnOffIdMapping *cabling,const LArBadChannelCont *bcCont) {
69
70if (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}
const boost::regex ref(r_ef)
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
LArCalibValidationAlg< LArAutoCorrComplete, LArAutoCorrComplete > LArAutoCorrValidationBase
@LArAutoCorrValidatonAlg.h
LArBadXCont< LArBadChannel > LArBadChannelCont
static Double_t sc
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual StatusCode preLoop() override
Executed before the loop over all channels to reset global sums.
unsigned m_nSamplesToCheck
Number of elements of the Covariance vector that should be checked.
std::vector< DataPerFEB > m_vDataPerFEB
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.
std::vector< std::string > m_covToleranceInit
Covariance tolerance (job-Property)
LArAutoCorrValidationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Regular algorithm constructor.
bool febSummary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont)
Method to compare FEB averages.
virtual StatusCode summary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont) override
Summary method executed after the loop over all channels.
std::vector< std::string > m_covToleranceFEBInit
Covariace tolerance of one FEB (job-Property)
virtual StatusCode summary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont)
const std::string channelDescription(const HWIdentifier &chid, const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont, const unsigned gain=99, bool isFeb=false) const