ATLAS Offline Software
LArCaliWaveValidationAlg.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>
7 
8 LArCaliWaveValidationAlg::LArCaliWaveValidationAlg(const std::string& name, ISvcLocator* pSvcLocator) :
9  LArCaliWaveValidationBase(name,pSvcLocator) {
10 
11  declareProperty("TimeShiftDetection",m_timeShift=false,
12  "Enable detection of Pulse timeShift");
13  declareProperty("AmplitudeTolerance",m_ampToleranceInit,
14  "CaloCellGroup of allowed deviation of the amplitude (in permills)");
15  declareProperty("CaliWaveFWHMTolerance",m_fwhmToleranceInit,
16  "CaloCellGroup of llowed deviation of the FWHM (in permills)");
17  declareProperty("AmplitudeToleranceFEB",m_ampToleranceFEBInit,
18  "CaloCellGroup of llowed deviation of the amplitude (average over one FEB, in permills)");
19  declareProperty("CaliWaveFWHMToleranceFEB",m_fwhmToleranceFEBInit,
20  "CaloCellGroup of allowed deviation of the FWHM (average over one FEB, in permills)");
21 }
22 
23 
25  m_ampGlobalRef=0.;
26  m_fwhmGlobalRef=0.;
27  m_ampGlobalVal=0.;
28  m_fwhmGlobalVal=0.;
30  bool stat;
31 
32  //Initialize CaloCellGroups:
33 
34  ATH_MSG_INFO ( "Initialize Amplitude Tolerances (CaloCellGroup)" ) ;
36  if (!stat) {
37  ATH_MSG_ERROR ( "Failed to initialize CaloCellGroup of amplitude tolerances!" ) ;
38  return StatusCode::FAILURE;
39  }
40  if (m_ampTolerance.getDefaults().size()!=3) {
41  ATH_MSG_ERROR ( "Configuration error: Expected three amplitude tolerance values (one per gain), got "
42  << m_ampTolerance.getDefaults().size() ) ;
43  return StatusCode::FAILURE;
44  }
45  if (this->msgLvl(MSG::DEBUG)) m_ampTolerance.printDef();//for debugging....
46 
47 
48 
49  ATH_MSG_INFO ( "Initialize FWHM Tolerances (CaloCellGroup)" ) ;
51  if (!stat) {
52  ATH_MSG_ERROR ( "Failed to initialize CaloCellGroup of FWHM tolerances!" ) ;
53  return StatusCode::FAILURE;
54  }
55  if (m_fwhmTolerance.getDefaults().size()!=3) {
56  ATH_MSG_ERROR ( "Configuration error: Expected three FWHM tolerance values (one per gain), got "
57  << m_fwhmTolerance.getDefaults().size() ) ;
58  return StatusCode::FAILURE;
59  }
60  if (this->msgLvl(MSG::DEBUG)) m_fwhmTolerance.printDef();//for debugging....
61 
62 
63 
64  ATH_MSG_INFO ( "Initialize FEB Amplitude Tolerances (CaloCellGroup)" ) ;
66  if (!stat) {
67  ATH_MSG_ERROR ( "Failed to initialize CaloCellGroup of FEB amplitude tolerances!" ) ;
68  return StatusCode::FAILURE;
69  }
70  if (m_ampToleranceFEB.getDefaults().size()!=3) {
71  ATH_MSG_ERROR ( "Configuration error: Expected three FEB amplitude tolerance values (one per gain), got "
72  << m_ampToleranceFEB.getDefaults().size() ) ;
73  return StatusCode::FAILURE;
74  }
75  if (this->msgLvl(MSG::DEBUG)) m_ampToleranceFEB.printDef();//for debugging....
76 
77 
78 
79  ATH_MSG_INFO ( "Initialize FEB FWHM Tolerances (CaloCellGroup)" ) ;
81  if (!stat) {
82  ATH_MSG_ERROR ( "Failed to initialize CaloCellGroup of FEB FWHM tolerances!" ) ;
83  return StatusCode::FAILURE;
84  }
85  if (m_fwhmToleranceFEB.getDefaults().size()!=3) {
86  ATH_MSG_ERROR ( "Configuration error: Expected three FEB FWHM tolerance values (one per gain), got "
87  << m_fwhmToleranceFEB.getDefaults().size() ) ;
88  return StatusCode::FAILURE;
89  }
90  if (this->msgLvl(MSG::DEBUG)) m_fwhmToleranceFEB.printDef();//for debugging....
91 
92  return StatusCode::SUCCESS;
93 }
94 
96 
97  if (gain<0 || gain>2) {
98  ATH_MSG_ERROR ( "Unexpected gain value " << gain ) ;
99  return false;
100  }
101 
102  double ampVal=0;
103  double ampRef=0;
104 
105  float fwhmVal=0;
106  float fwhmRef=0;
107 
108  float TmaxVal=0;
109  float TmaxRef=0;
110 
111  float TMaxshift=5.;
112 
113 
114  const Identifier id=cabling->cnvToIdentifier(chid);
115 
116  const float ampTolerance=m_ampTolerance.valuesForCell(id)[gain];
117  const float fwhmTolerance=m_fwhmTolerance.valuesForCell(id)[gain];
118 
119  if (val.size()>0 && ref.size()>0){
120 
121  //We assume that the caliwavevec has only one entry.
122  const LArWave& wave=val[0];
123  const LArWave& waver=ref[0];
124  TmaxVal=m_waveHelper.getMax(wave);
125  TmaxRef=m_waveHelper.getMax(waver);
126  ampVal=m_waveHelper.getMaxAmp(wave);
127  ampRef=m_waveHelper.getMaxAmp(waver);
128  fwhmVal=wave.getDt()*m_waveHelper.getWidth(wave);
129  fwhmRef=waver.getDt()*m_waveHelper.getWidth(waver);
130  }
131 
132  const HWIdentifier febid=m_onlineHelper->feb_Id(chid);
133 
134 
135  DataPerFEB* dataPerFEB = m_vDataPerFEB.empty() ? nullptr : &(m_vDataPerFEB.back());
136  if (!dataPerFEB || dataPerFEB->febid!=febid) {//Got to new FEB
137  m_vDataPerFEB.push_back(DataPerFEB(chid,febid,gain));
138  dataPerFEB=&(m_vDataPerFEB.back());
139  }
140 
141  dataPerFEB->ampVal+=ampVal;
142  dataPerFEB->ampRef+=ampRef;
143  dataPerFEB->fwhmVal+=fwhmVal;
144  dataPerFEB->fwhmRef+=fwhmRef;
145  ++(dataPerFEB->nEntries);
146 
147 
148  m_ampGlobalVal+=ampVal;
149  m_fwhmGlobalVal+=fwhmVal;
150  m_ampGlobalRef+=ampRef;
151  m_fwhmGlobalRef+=fwhmRef;
153 
154  bool retval=true;
155  if (fabs(TmaxVal-TmaxRef)> TMaxshift && m_timeShift==true) {
156  retval=false;
158  msg() << m_myMsgLvl << "Shifted! " << channelDescription(chid,cabling,bcCont,gain) << " Tmax: " << TmaxVal << " ( " << TmaxRef << " ) " << endmsg;
159 
160  }
161 
162 
163  if (1000*fabs(ampVal-ampRef)/ampRef > ampTolerance || 1000*fabs(fwhmVal-fwhmRef)/fwhmRef > fwhmTolerance) {
164  retval=false;
166  msg().precision(2);
167  msg().setf(std::ios::fixed,std::ios::floatfield);
168  msg() << this->m_myMsgLvl << "Deviating! " << channelDescription(chid,cabling,bcCont,gain) << " Amp: " << ampVal << "( " << ampRef
169  << ", " << 100.*(ampVal-ampRef)/ampRef << " %)"
170  << " FWHM: " << fwhmVal << " ( " << fwhmRef << ", " << 100*(fwhmVal-fwhmRef)/fwhmVal << " %)" << endmsg;
171  ATH_MSG_DEBUG ( "Amplitude FEB tolerance: " << ampTolerance << ", FWHM FEB tolerance: " << fwhmTolerance ) ;
172  }
173  }
175  msg() << this->m_myMsgLvl << "Channel deviation message has already been printed " << m_maxmessages << " times. Now silent..." << endmsg;
176 
177  return retval;
178 }
179 
180 
182 
183  unsigned nBadFebs=0;
184 
185  msg().precision(3);
186  msg().setf(std::ios::fixed,std::ios::floatfield);
187 
188  for (DataPerFEB& dataPerFeb : m_vDataPerFEB) {
189  dataPerFeb.ampVal/=dataPerFeb.nEntries;
190  dataPerFeb.ampRef/=dataPerFeb.nEntries;
191  dataPerFeb.fwhmVal/=dataPerFeb.nEntries;
192  dataPerFeb.fwhmRef/=dataPerFeb.nEntries;
193 
194  const Identifier id=cabling->cnvToIdentifier(dataPerFeb.chid);
195  const float& ampToleranceFEB=m_ampToleranceFEB.valuesForCell(id)[dataPerFeb.gain];
196  const float& fwhmToleranceFEB=m_fwhmToleranceFEB.valuesForCell(id)[dataPerFeb.gain];
197 
198  if (fabs(dataPerFeb.ampVal-dataPerFeb.ampRef)/dataPerFeb.ampRef*1000>ampToleranceFEB ||
199  fabs(dataPerFeb.fwhmVal-dataPerFeb.fwhmRef)/dataPerFeb.fwhmRef*1000>fwhmToleranceFEB) {
200  msg() << m_myMsgLvl << "Deviating! " <<channelDescription(dataPerFeb.febid,cabling,bcCont,dataPerFeb.gain,true)<< "Average Amp: " << dataPerFeb.ampVal << " (" << dataPerFeb.ampRef << ")"
201  << " FWHM: " << dataPerFeb.fwhmVal << " (" << dataPerFeb.fwhmRef << ")" << endmsg;
202  ++nBadFebs;
203  ATH_MSG_DEBUG ( "Amplitude FEB tolerance: " << ampToleranceFEB << ", FWHM FEB tolerance: " << fwhmToleranceFEB ) ;
204  }
205  }
206 
207  if (nBadFebs) {
208  ATH_MSG_ERROR ( "Found " << nBadFebs << " out of " << m_vDataPerFEB.size() << " FEBs deviating from reference" ) ;
209  return false;
210  }
211  else {
212  ATH_MSG_INFO ( "All " << m_vDataPerFEB.size() << " FEBs withing given tolerance." ) ;
213  return true;
214  }
215 }
217  StatusCode sc=StatusCode::SUCCESS;
218  //1nd step: Check the FEB-averages:
219  if (m_doFebAverages && !febSummary(cabling, bcCont))
220  sc=StatusCode::RECOVERABLE;
221  //2st step: Call the summary method from base-class (single-channel summary)
222  if (!LArCaliWaveValidationBase::summary(cabling, bcCont).isSuccess())
223  sc=StatusCode::RECOVERABLE;
224  //3rd step: Check the gobal averages:
225  if (m_nEntriesGlobal) {
230  }
231  ATH_MSG_INFO ( "Global amplitude average: " << m_ampGlobalVal << " Reference:" << m_ampGlobalRef
232  << " Deviation:" << (m_ampGlobalVal-m_ampGlobalRef)/m_ampGlobalRef*1000 <<" permille" ) ;
233  ATH_MSG_INFO ( "Gobal FWHM average: " << m_fwhmGlobalVal << " Reference:" << m_fwhmGlobalRef
234  << " Deviation:" << (m_fwhmGlobalVal-m_fwhmGlobalRef)/m_fwhmGlobalRef*1000 <<" permille" ) ;
235  return sc;
236 }
LArWave
Definition: LArWave.h:31
LArCaliWaveValidationAlg::m_fwhmTolerance
CaloCellGroupList m_fwhmTolerance
Definition: LArCaliWaveValidationAlg.h:71
LArCaliWaveValidationAlg::m_ampToleranceFEB
CaloCellGroupList m_ampToleranceFEB
Definition: LArCaliWaveValidationAlg.h:67
LArCaliWaveValidationAlg::m_nEntriesGlobal
unsigned m_nEntriesGlobal
Definition: LArCaliWaveValidationAlg.h:106
LArCalibValidationAlg::m_onlineHelper
const LArOnlineID_Base * m_onlineHelper
Definition: LArCalibValidationAlg.h:177
LArCaliWaveValidationAlg::m_ampToleranceInit
std::vector< std::string > m_ampToleranceInit
Amplitude tolerance (in permills) (job-Property)
Definition: LArCaliWaveValidationAlg.h:62
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
LArWaveHelper::getWidth
double getWidth(const LArWave &theWave) const
Definition: LArWaveHelper.cxx:209
LArCaliWaveValidationAlg::DataPerFEB::nEntries
unsigned nEntries
Definition: LArCaliWaveValidationAlg.h:96
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArCaliWaveValidationAlg::DataPerFEB::ampRef
double ampRef
Definition: LArCaliWaveValidationAlg.h:94
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
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
LArWave::getDt
const double & getDt() const
delta time
Definition: LArWave.h:50
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
LArCaliWaveValidationAlg::m_ampTolerance
CaloCellGroupList m_ampTolerance
Definition: LArCaliWaveValidationAlg.h:63
LArWaveHelper::getMaxAmp
double getMaxAmp(const LArWave &theWave) const
Definition: LArWaveHelper.cxx:129
LArCaliWaveValidationAlg::m_ampGlobalRef
double m_ampGlobalRef
Definition: LArCaliWaveValidationAlg.h:104
LArWaveHelper::getMax
unsigned int getMax(const LArWave &theWave) const
return index of maximum sample
Definition: LArWaveHelper.cxx:89
HWIdentifier
Definition: HWIdentifier.h:13
LArCaliWaveValidationAlg::DataPerFEB::ampVal
double ampVal
Definition: LArCaliWaveValidationAlg.h:92
LArCaliWaveValidationAlg::febSummary
bool febSummary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont)
Method to compare FEB averages.
Definition: LArCaliWaveValidationAlg.cxx:181
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
LArCellBinning_test.retval
def retval
Definition: LArCellBinning_test.py:112
LArCaliWaveValidationAlg::DataPerFEB::fwhmVal
double fwhmVal
Definition: LArCaliWaveValidationAlg.h:93
LArCaliWaveValidationAlg::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 the pedestal single readout channels.
Definition: LArCaliWaveValidationAlg.cxx:95
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
LArCaliWaveValidationAlg::m_fwhmToleranceFEB
CaloCellGroupList m_fwhmToleranceFEB
Definition: LArCaliWaveValidationAlg.h:75
LArCaliWaveValidationAlg::DataPerFEB
Definition: LArCaliWaveValidationAlg.h:83
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
LArCaliWaveValidationAlg::m_fwhmToleranceFEBInit
std::vector< std::string > m_fwhmToleranceFEBInit
Tolerance for the average FWHM of one FEB (in permills) (job-Property)
Definition: LArCaliWaveValidationAlg.h:74
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:1483
LArCaliWaveValidationAlg::DataPerFEB::fwhmRef
double fwhmRef
Definition: LArCaliWaveValidationAlg.h:95
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArCaliWaveValidationAlg::m_timeShift
bool m_timeShift
Definition: LArCaliWaveValidationAlg.h:77
LArCaliWaveValidationAlg::preLoop
virtual StatusCode preLoop() override
Executed before the loop over all channels to reset global sums.
Definition: LArCaliWaveValidationAlg.cxx:24
LArCalibValidationAlg::m_myMsgLvl
MSG::Level m_myMsgLvl
Message level for reporting deviations.
Definition: LArCalibValidationAlg.h:163
LArCaliWaveValidationAlg::m_fwhmGlobalRef
double m_fwhmGlobalRef
Definition: LArCaliWaveValidationAlg.h:105
LArCaliWaveValidationAlg::m_fwhmToleranceInit
std::vector< std::string > m_fwhmToleranceInit
FWHM tolerance (in permills) (job-Property)
Definition: LArCaliWaveValidationAlg.h:70
LArCaliWaveValidationAlg::m_waveHelper
LArWaveHelper m_waveHelper
Definition: LArCaliWaveValidationAlg.h:108
LArCaliWaveValidationAlg::summary
virtual StatusCode summary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont) override
Summary method executed after the loop over all channels.
Definition: LArCaliWaveValidationAlg.cxx:216
LArCaliWaveValidationAlg::m_fwhmGlobalVal
double m_fwhmGlobalVal
Definition: LArCaliWaveValidationAlg.h:103
ref
const boost::regex ref(r_ef)
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
DEBUG
#define DEBUG
Definition: page_access.h:11
LArCaliWaveValidationAlg::m_vDataPerFEB
std::vector< DataPerFEB > m_vDataPerFEB
Definition: LArCaliWaveValidationAlg.h:99
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
LArCaliWaveValidationAlg::LArCaliWaveValidationAlg
LArCaliWaveValidationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Regular algorithm constructor.
Definition: LArCaliWaveValidationAlg.cxx:8
LArCalibValidationAlg
Algorithm to validate LAr Autocorr;.
Definition: LArCalibValidationAlg.h:47
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.
CaloCellGroupList::valuesForCell
const std::vector< float > & valuesForCell(const Identifier id)
Definition: CaloCellGroup.cxx:266
CaloCellGroupList::setDefinition
bool setDefinition(const CaloCell_Base_ID *caloCellId, const std::vector< std::string > &definitions, MsgStream &logStr)
Definition: CaloCellGroup.cxx:225
LArCaliWaveValidationAlg::m_ampGlobalVal
double m_ampGlobalVal
Definition: LArCaliWaveValidationAlg.h:102
LArCalibValidationAlg::m_doFebAverages
bool m_doFebAverages
wether to compare feb-averages (used only by derived class)
Definition: LArCalibValidationAlg.h:210
LArCaliWaveValidationAlg.h
LArCaliWaveValidationAlg::m_ampToleranceFEBInit
std::vector< std::string > m_ampToleranceFEBInit
Tolerance for the average amplitude of one FEB (in permills) (job-Property)
Definition: LArCaliWaveValidationAlg.h:66
LArCaliWaveValidationAlg::DataPerFEB::febid
HWIdentifier febid
Definition: LArCaliWaveValidationAlg.h:90
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20