ATLAS Offline Software
Loading...
Searching...
No Matches
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
8LArRampValidationAlg::LArRampValidationAlg(const std::string& name, ISvcLocator* pSvcLocator) :
9 LArRampValidationBase(name,pSvcLocator),
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:
33 if (m_tolerance.setDefinition(m_caloId,m_toleranceInit,msg())==false) {
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:
46 if (m_toleranceFEB.setDefinition(m_caloId,m_toleranceInitFEB,msg())==false) {
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
62
63 // Retrieve Raw Ramps Container
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 ) ;
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
108bool LArRampValidationAlg::validateChannel(const LArCondObj& ref, const LArCondObj& val, const HWIdentifier chid, const int gain, const LArOnOffIdMapping *cabling,const LArBadChannelCont *bcCont) {
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
220bool LArRampValidationAlg::deviateFromAvg(const LArCondObj& val, const HWIdentifier chid, const int gain, const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont) {
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
243StatusCode LArRampValidationAlg::summary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont) {
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
const boost::regex ref(r_ef)
Scalar eta() const
pseudorapidity method
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
LArBadXCont< LArBadChannel > LArBadChannelCont
static Double_t sc
LArCalibValidationAlg< LArRampComplete, ILArRamp > LArRampValidationBase
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
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
LArRampValidationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Regular algorithm constructor.
CaloCellGroupList m_toleranceFEB
Ramp tolerance (FEB average) as initializer string CaloCellGroup object.
float m_rawrampTimeADC
Raw Ramp ADC (job-Property)
bool deviateFromAvg(const LArCondObj &val, const HWIdentifier chid, const int gain, const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont)
virtual StatusCode summary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont) override
Summary method executed after the loop over all channels.
float m_rawrampTimeTolerance
Raw Ramp time tolerance (in ns) (job-Property)
bool m_hasRawRampContainer
To check if Raw Ramps are found.
std::unordered_map< Identifier, DataPerRegion > m_vDataPerSector
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.
CaloCellGroupList m_tolerance
Ramp tolerance as CaloCellGroup object.
LArCondObj getRefObj(const HWIdentifier chid, const int gain) const override final
Method implmented in derived class to get the reference object from ref-container.
std::vector< std::string > m_contKey
To store Gain Keys for Raw Ramps (job-Property)
bool febSummary(const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont)
Method to compare FEB averages.
std::vector< std::string > m_toleranceInitFEB
Ramp tolerance (FEB average) as CaloCellGroup object (job-Property)
virtual StatusCode preLoop() override
Executed before the loop over all channels to reset global sums.
std::vector< std::string > m_toleranceInit
Ramp tolerance as init string for CellGroupObject (job-Property)
std::unordered_map< HWIdentifier, DataPerRegion > m_vDataPerFEB
LArRawRampContainer * m_rawRampContainer