ATLAS Offline Software
LArRampValidationAlg.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 LArRampValidationAlg::LArRampValidationAlg(const std::string& name, ISvcLocator* pSvcLocator) :
9  LArRampValidationBase(name,pSvcLocator),
10  m_hasRawRampContainer(false),
11  m_rawRampContainer(0),
12  m_rampGlobalVal(0),
13  m_rmsGlobalVal(0),
14  m_rampGlobalRef(0),
15  m_rmsGlobalRef(0),
16  m_nEntriesGlobal(0)
17 {
18  declareProperty("KeyList", m_contKey);
19  declareProperty("RawRampTimeMinADC",m_rawrampTimeADC=100,
20  "Minimal ADC, where the RampTime is computed");
21  declareProperty("RampTolerance",m_toleranceInit,
22  "Allowed deviation of ramp (%)");
23  declareProperty("RampToleranceFEB",m_toleranceInitFEB,
24  "Allowed deviation of ramp (average over one FEB,");
25  declareProperty("RawRampTimeTolerance",m_rawrampTimeTolerance=1.,
26  "Allowed deviation of the reconstructed time (ns)");
27 }
28 
29 
31 
32  //Initialize CellGroup object storing the threhsolds:
34  ATH_MSG_ERROR ( "Failed to initialize CaloCellGroup of thresholds!" ) ;
35  return StatusCode::FAILURE;
36  }
37 
38  if (m_tolerance.getDefaults().size()!=3) {
39  ATH_MSG_ERROR ( "Expected three values in CaloCellGroup of thresholds for three gains!" ) ;
40  return StatusCode::FAILURE;
41  }
42  if (this->msgLvl(MSG::DEBUG)) m_tolerance.printDef();//for debugging....
43 
44 
45  //Initialize CellGroup object storing the threhsolds:
47  ATH_MSG_ERROR ( "Failed to initialize CaloCellGroup of thresholds!" ) ;
48  return StatusCode::FAILURE;
49  }
50 
51  if (m_toleranceFEB.getDefaults().size()!=3) {
52  ATH_MSG_ERROR ( "Expected three values in CaloCellGroup of thresholds for three gains!" ) ;
53  return StatusCode::FAILURE;
54  }
55  if (this->msgLvl(MSG::DEBUG)) m_toleranceFEB.printDef();//for debugging....
56 
57 
58  m_rampGlobalRef=0.;
59  m_rampGlobalVal=0.;
61  m_rawRampContainer=NULL;
62 
63  // Retrieve Raw Ramps Container
64  m_hasRawRampContainer = false;
65  for (const std::string& key_it : m_contKey) {
66  StatusCode sc=detStore()->retrieve(m_rawRampContainer,key_it);
67  if (sc!=StatusCode::SUCCESS || !m_rawRampContainer) {
68  ATH_MSG_WARNING ( "Unable to retrieve LArRawRampContainer with key " << key_it ) ;
69  }
70  else {
71  ATH_MSG_DEBUG ( "Got LArRawRampContainer with key " << key_it ) ;
72  m_hasRawRampContainer = true;
73  }
74  }
76  ATH_MSG_WARNING ( "No LArRawRampContainer found. Only fitted ramp will be tested " ) ;
77 
78  // Check Raw Ramps
80 
83  for (;cont_it!=cont_it_e;++cont_it) {
84  const std::vector<LArRawRamp::RAMPPOINT_t>& singleRamp=(*cont_it)->theRamp();
85  for (unsigned int DACIndex=0; DACIndex<singleRamp.size(); DACIndex++) {
86 
87  ATH_MSG_DEBUG ( "DAC Index:" << DACIndex
88  << " DAC value : " << singleRamp[DACIndex].DAC
89  << " ADC value : " << singleRamp[DACIndex].ADC
90  << " Time " << singleRamp[DACIndex].TimeMax ) ;
91 
92  // Check point with DAC > m_rawrampTimeDAC where DeltaT is meaningful
93  if(singleRamp[DACIndex].ADC > m_rawrampTimeADC){
94  if (fabs(singleRamp[DACIndex].TimeMax) > m_rawrampTimeTolerance){
95  msg().setf(std::ios::fixed,std::ios::floatfield);
96  msg().precision(2);
97  msg() << m_myMsgLvl << "Deviating! chan= " << (*cont_it)->channelID()<< " gain= "<<(*cont_it)->gain() << " DeltaT=" << singleRamp[DACIndex].TimeMax << " DAC = " << singleRamp[DACIndex].DAC << endmsg;
98  }
99  break; //Stop loop after testing the m_rawrampTimeDAC DAC point
100  }
101 
102  } //end DAC points loop
103  } // end channels loop
104  }
105  return StatusCode::SUCCESS;
106 }
107 
109 
110 
111  HWIdentifier febid=m_onlineHelper->feb_Id(chid);
112  Identifier offlineID = cabling->cnvToIdentifier(chid);
113 
115 
116  // Store average Ramp value per FEB
117  DataPerRegion& dataPerFEB=m_vDataPerFEB[febid];
118  dataPerFEB.rampVal+=val.m_vRamp[1];
119  dataPerFEB.rampRef+=ref.m_vRamp[1];
120  ++(dataPerFEB.nEntries);
121 
122  m_rampGlobalVal+=val.m_vRamp[1];
123  m_rampGlobalRef+=ref.m_vRamp[1];
124 
125  const Identifier region=m_caloId->region_id(offlineID);
126  int eta = m_caloId->eta(offlineID);
127  //Build fake-identifier with phi=0 to identify sector:
128  //Identifier cell_id (const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule,const int region_or_dummy,const int eta, const int phi ) const;
129  //mis-used phi for gain:
130  const Identifier sectorId=m_caloId->cell_id(region,eta,gain);
131 
132  // Store avg Ramp value per sector : pos_neg/region/layer/eta (average over phi)
133  DataPerRegion& dataPerSector=m_vDataPerSector[sectorId];
134  dataPerSector.rampVal+=val.m_vRamp[1];
135  ++(dataPerSector.nEntries);
136 
137  // Check individual channel for Ramp deviation
138  const float& tolerance=m_tolerance.valuesForCell(offlineID)[gain];
139 
140 
141  if (fabs(val.m_vRamp[1]-ref.m_vRamp[1])/ref.m_vRamp[1] > tolerance){
143  std::stringstream devMsg;
144  devMsg.setf(std::ios::fixed,std::ios::floatfield);
145  devMsg.precision(3);
146  devMsg << "Deviating! " << channelDescription(chid,cabling,bcCont,gain) << " Ramp: " << val.m_vRamp[1] << " (" << ref.m_vRamp[1] << ", ";
147  devMsg.precision(2);
148  devMsg << 100*(val.m_vRamp[1]-ref.m_vRamp[1])/ref.m_vRamp[1] << "%)";
149  msg() << this->m_myMsgLvl << devMsg.str() << endmsg;
150  ATH_MSG_DEBUG ( "Ramp Tolerance: " << tolerance ) ;
151  }
153  msg() << this->m_myMsgLvl << "Channel deviation message has already been printed " << m_maxmessages << " times. Now silent..." << endmsg;
154 
155  return false;
156  }
157  else
158  return true;
159 
160 
161 }
162 
164 
165  // FEBs
166  unsigned nBadFebs=0;
167  for(auto& dataPerFebPair : m_vDataPerFEB) {
168  DataPerRegion& dataPerFeb=dataPerFebPair.second;
169  const HWIdentifier febAndGainId=dataPerFebPair.first;
170  const int gain=m_onlineHelper->channel(febAndGainId);
171  const HWIdentifier febId=m_onlineHelper->feb_Id(febAndGainId);
172  dataPerFeb.rampVal/=dataPerFeb.nEntries;
173  dataPerFeb.rampRef/=dataPerFeb.nEntries;
174 
175  ATH_MSG_DEBUG ( " nb of channels = " << dataPerFeb.nEntries
176  << " for FEB " << channelDescription(febId,cabling,bcCont) ) ;
177 
178  //Get offline identifier of channel 0 of this FEB, should be good enough ...
179  const Identifier id=cabling->cnvToIdentifier(febId);
180  const float& tolerance=m_toleranceFEB.valuesForCell(id)[gain];
181 
182  if (fabs(dataPerFeb.rampVal-dataPerFeb.rampRef)/dataPerFeb.rampRef > tolerance){
183  msg().precision(3);
184  msg().setf(std::ios::fixed,std::ios::floatfield);
185  msg() << m_myMsgLvl << "Deviating! " << channelDescription(febId,cabling,bcCont,gain,true) << "Average Ramp: "
186  << dataPerFeb.rampVal << " (reference: " << dataPerFeb.rampRef << ")" << endmsg;
187  ATH_MSG_DEBUG ( "Ramp FEB average tolerance: " << tolerance ) ;
188  ++nBadFebs;
189  }
190  }
191 
192  if (nBadFebs) {
193  ATH_MSG_ERROR ( "Found " << nBadFebs << " out of " << m_vDataPerFEB.size()
194  << " FEBs deviating from reference" ) ;
195  return false;
196  } else {
197  ATH_MSG_INFO ( "All " << m_vDataPerFEB.size()
198  << " FEBs withing given tolerance." ) ;
199  return true;
200  }
201  /*
202  // Sectors
203  std::vector<DataPerSector>::iterator it2=m_vDataPerSector.begin();
204  std::vector<DataPerSector>::iterator it2_e=m_vDataPerSector.end();
205  for (;it2!=it2_e;++it2) {
206  DataPerSector& dataPerSector=*it2;
207  dataPerSector.rampVal/=dataPerSector.nEntries;
208  //dataPerSector.rampRef/=dataPerSector.nEntries;
209 
210  (*m_log) << MSG::DEBUG << " nb of channels = " << dataPerSector.nEntries
211  << " for Sector : gain " << dataPerSector.gain
212  << " pos_neg " << dataPerSector.pos_neg
213  << " region " << dataPerSector.region
214  << " layer " << dataPerSector.layer
215  << " eta " << dataPerSector.eta << endmsg;
216  }
217  */
218 }
219 
221 
222  Identifier offlineID = cabling->cnvToIdentifier(chid);
223  const Identifier regId=m_caloId->region_id(offlineID);
224  const int eta = m_caloId->eta(offlineID);
225  const Identifier sectorId=m_caloId->cell_id(regId,eta,gain);
226 
227  const auto& dataPerSector=m_vDataPerSector[sectorId];
228  if (dataPerSector.rampVal == 0 ){
229  ATH_MSG_ERROR ( "Found Sector with Ramp Average equals to zero" ) ;
230  ATH_MSG_ERROR ( "Sector : pos_neg " << m_caloId->side(regId) << " region " << m_caloId->region(regId)
231  << " layer " << m_caloId->sampling(regId) << " eta " << eta << " gain " << gain);
232  return false;
233  }else{
234  float ratio = val.m_vRamp[1]/dataPerSector.rampVal;
235  if ( ratio > 2.){
236  msg() << m_myMsgLvl << "!!! Deviating Sector channel = " <<channelDescription(chid,cabling,bcCont,gain) << "Ramp: " << val.m_vRamp[1] << " (Average Sector Ramp: " << dataPerSector.rampRef << ")" << endmsg;
237  return false;
238  }
239  }
240  return true;
241 }
242 
244  StatusCode sc=StatusCode::SUCCESS;
245  //1nd step: Check the FEB-averages:
246  if (m_doFebAverages && !febSummary(cabling, bcCont))
247  sc=StatusCode::RECOVERABLE;
248  //2nd step: Call the summary method from base-class (single-channel summary)
249  if (!LArRampValidationBase::summary(cabling, bcCont).isSuccess())
250  sc=StatusCode::RECOVERABLE;
251  //3rd step: Check the gobal averages:
252  if (m_nEntriesGlobal) {
257  }
258  ATH_MSG_INFO ( "Gobal ramp average: " << m_rampGlobalVal << " Reference: " << m_rampGlobalRef
259  << " Deviation: " << m_rampGlobalVal-m_rampGlobalRef ) ;
260 
261  return sc;
262 }
263 
264 
266  auto ramp=m_reference->ADC2DAC(chid,gain);
267  return LArCondObj(std::vector<float>(ramp.begin(),ramp.end()));
268 }
269 
LArRampValidationAlg::m_rmsGlobalRef
double m_rmsGlobalRef
Definition: LArRampValidationAlg.h:107
python.TileHitInfoD3PDObject.TimeMax
TimeMax
Definition: TileHitInfoD3PDObject.py:14
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
tolerance
constexpr double tolerance
Definition: runMdtGeoComparison.cxx:105
LArCalibValidationAlg::m_onlineHelper
const LArOnlineID_Base * m_onlineHelper
Definition: LArCalibValidationAlg.h:177
MonDataType::ADC
@ ADC
LArCalibValidationAlg::m_nFailedValidation
unsigned m_nFailedValidation
Number of channels for which vaildateChannel returned false.
Definition: LArCalibValidationAlg.h:221
CaloCell_Base_ID::region
int region(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
LArCalibValidationAlg::m_reference
const REFCONTAINER * m_reference
Pointer to container with reference values.
Definition: LArCalibValidationAlg.h:182
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
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
LArRampValidationAlg::m_vDataPerSector
std::unordered_map< Identifier, DataPerRegion > m_vDataPerSector
Definition: LArRampValidationAlg.h:101
LArBadXCont
Conditions-Data class holding LAr Bad Channel or Bad Feb information.
Definition: LArBadChannelCont.h:28
CaloCell_Base_ID::region_id
Identifier region_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy) const
Make a region ID from constituting fields and subCalo index; for (Mini)FCAL and Tiles,...
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
LArRampValidationAlg::m_hasRawRampContainer
bool m_hasRawRampContainer
To check if Raw Ramps are found.
Definition: LArRampValidationAlg.h:81
HWIdentifier
Definition: HWIdentifier.h:13
LArRampValidationAlg.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
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
LArRampValidationAlg::m_rawrampTimeTolerance
float m_rawrampTimeTolerance
Raw Ramp time tolerance (in ns) (job-Property)
Definition: LArRampValidationAlg.h:64
LArRampValidationAlg::febSummary
bool febSummary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont)
Method to compare FEB averages.
Definition: LArRampValidationAlg.cxx:163
LArRampValidationAlg::m_toleranceInitFEB
std::vector< std::string > m_toleranceInitFEB
Ramp tolerance (FEB average) as CaloCellGroup object (job-Property)
Definition: LArRampValidationAlg.h:75
LArRampValidationAlg::deviateFromAvg
bool deviateFromAvg(const LArCondObj &val, const HWIdentifier chid, const int gain, const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont)
Definition: LArRampValidationAlg.cxx:220
LArOnlineID_Base::channel
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Definition: LArOnlineID_Base.cxx:1967
LArRampValidationAlg::LArRampValidationAlg
LArRampValidationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Regular algorithm constructor.
Definition: LArRampValidationAlg.cxx:8
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArRampValidationAlg::DataPerRegion
Definition: LArRampValidationAlg.h:90
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
CaloCell_Base_ID::sampling
int sampling(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
LArRampValidationAlg::m_rawrampTimeADC
float m_rawrampTimeADC
Raw Ramp ADC (job-Property)
Definition: LArRampValidationAlg.h:66
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
LArRampValidationAlg::DataPerRegion::rampVal
double rampVal
Definition: LArRampValidationAlg.h:92
LArRampValidationAlg::m_tolerance
CaloCellGroupList m_tolerance
Ramp tolerance as CaloCellGroup object.
Definition: LArRampValidationAlg.h:72
LArRampValidationAlg::m_vDataPerFEB
std::unordered_map< HWIdentifier, DataPerRegion > m_vDataPerFEB
Definition: LArRampValidationAlg.h:100
CaloCell_Base_ID::eta
int eta(const Identifier id) const
LAr field values (NOT_VALID == invalid request)
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...
LArRampValidationAlg::m_rawRampContainer
LArRawRampContainer * m_rawRampContainer
Definition: LArRampValidationAlg.h:103
LArCalibValidationAlg::m_caloId
const CaloCell_Base_ID * m_caloId
Definition: LArCalibValidationAlg.h:178
LArRampValidationAlg::m_toleranceInit
std::vector< std::string > m_toleranceInit
Ramp tolerance as init string for CellGroupObject (job-Property)
Definition: LArRampValidationAlg.h:69
LArCalibValidationAlg::LArCondObj
CONDITIONSCONTAINER::LArCondObj LArCondObj
Definition: LArCalibValidationAlg.h:80
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
tolerance
Definition: suep_shower.h:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArCalibValidationAlg::m_myMsgLvl
MSG::Level m_myMsgLvl
Message level for reporting deviations.
Definition: LArCalibValidationAlg.h:163
LArRampValidationAlg::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 ramps single readout channels.
Definition: LArRampValidationAlg.cxx:108
LArRampValidationAlg::DataPerRegion::nEntries
unsigned nEntries
Definition: LArRampValidationAlg.h:96
CaloCell_Base_ID::cell_id
Identifier cell_id(const int subCalo, const int barec_or_posneg, const int sampling_or_fcalmodule, const int region_or_dummy, const int eta, const int phi) const
Make a cell (== channel) ID from constituting fields and subCalo index; for (Mini)FCAL,...
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
LArRampValidationAlg::m_rmsGlobalVal
double m_rmsGlobalVal
Definition: LArRampValidationAlg.h:106
CaloCell_Base_ID::side
int side(const Identifier id) const
Tile field values (NOT_VALID == invalid request)
python.compareTCTs.ratio
ratio
Definition: compareTCTs.py:295
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArRampValidationAlg::m_contKey
std::vector< std::string > m_contKey
To store Gain Keys for Raw Ramps (job-Property)
Definition: LArRampValidationAlg.h:62
ref
const boost::regex ref(r_ef)
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArRampValidationAlg::DataPerRegion::rampRef
double rampRef
Definition: LArRampValidationAlg.h:94
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
LArRampValidationAlg::m_rampGlobalVal
double m_rampGlobalVal
Definition: LArRampValidationAlg.h:106
LArRampValidationAlg::m_rampGlobalRef
double m_rampGlobalRef
Definition: LArRampValidationAlg.h:107
LArRampValidationAlg::preLoop
virtual StatusCode preLoop() override
Executed before the loop over all channels to reset global sums.
Definition: LArRampValidationAlg.cxx:30
LArRampValidationAlg::m_toleranceFEB
CaloCellGroupList m_toleranceFEB
Ramp tolerance (FEB average) as initializer string CaloCellGroup object.
Definition: LArRampValidationAlg.h:78
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
LArRampValidationAlg::getRefObj
LArCondObj getRefObj(const HWIdentifier chid, const int gain) const override final
Method implmented in derived class to get the reference object from ref-container.
Definition: LArRampValidationAlg.cxx:265
CaloCellGroupList::setDefinition
bool setDefinition(const CaloCell_Base_ID *caloCellId, const std::vector< std::string > &definitions, MsgStream &logStr)
Definition: CaloCellGroup.cxx:225
LArRampValidationAlg::m_nEntriesGlobal
unsigned m_nEntriesGlobal
Definition: LArRampValidationAlg.h:108
LArCalibValidationAlg::m_doFebAverages
bool m_doFebAverages
wether to compare feb-averages (used only by derived class)
Definition: LArCalibValidationAlg.h:210
LArRampValidationAlg::summary
virtual StatusCode summary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont) override
Summary method executed after the loop over all channels.
Definition: LArRampValidationAlg.cxx:243
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20