1414#include < string>
1515#include < boost/algorithm/string.hpp>
1616
17+ #include " DataFormatsEMCAL/ErrorTypeFEE.h"
1718#include " EMCALBase/Geometry.h"
19+ #include " EMCALReconstruction/AltroDecoder.h"
20+ #include " EMCALReconstruction/CaloRawFitter.h"
21+ #include " EMCALReconstruction/RawDecodingError.h"
22+ #include " EMCALReconstruction/ReconstructionErrors.h"
1823
1924#include " EMCAL/RawErrorCheck.h"
2025#include " QualityControl/MonitorObject.h"
@@ -48,6 +53,126 @@ void RawErrorCheck::configure()
4853 ILOG (Error, Support) << e.what () << ENDM ;
4954 }
5055 }
56+ const std::string keyThreshRawdataErrors = " ThresholdRDE" ,
57+ keyThreshPageError = " ThresholdPE" ,
58+ keyThreshMajorAltroError = " ThresholdMAAE" ,
59+ keyThreshMinorAltroError = " ThresholdMIAE" ,
60+ keyThresRawFitError = " ThresholdRFE" ,
61+ keyThresholdGeometryError = " ThresholdGEE" ,
62+ keyThresholdGainTypeError = " ThresholdGTE" ;
63+ for (auto [param, value] : mCustomParameters .getAllDefaults ()) {
64+ if (param.find (keyThreshRawdataErrors) == 0 ) {
65+ auto errortype = param.substr (keyThreshRawdataErrors.length ());
66+ auto errorcode = findErrorCodeRDE (errortype);
67+ if (errorcode > -1 ) {
68+ try {
69+ auto threshold = std::stoi (value);
70+ ILOG (Info) << " Setting custom threshold in Histogram RawDataErrors: " << errortype << " <= " << threshold << ENDM ;
71+ mErrorCountThresholdRDE [errorcode] = threshold;
72+ } catch (...) {
73+ ILOG (Error) << " Thresholds for histogram RawDataErrors: Failure in decoding threshold value (" << value << " ) for error type " << errortype << ENDM ;
74+ }
75+ } else {
76+ ILOG (Error) << " Thresholds for histogram RawDataErrors: Requested error type " << errortype << " not found" << ENDM ;
77+ }
78+ }
79+
80+ if (param.find (keyThreshPageError) == 0 ) {
81+ auto errortype = param.substr (keyThreshPageError.length ());
82+ auto errorcode = findErrorCodePE (errortype);
83+ if (errorcode > -1 ) {
84+ try {
85+ auto threshold = std::stoi (value);
86+ ILOG (Info) << " Setting custom threshold in Histogram PageErrors: " << errortype << " <= " << threshold << ENDM ;
87+ mErrorCountThresholdPE [errorcode] = threshold;
88+ } catch (...) {
89+ ILOG (Error) << " Thresholds for histogram PageErrors: Failure in decoding threshold value (" << value << " ) for error type " << errortype << ENDM ;
90+ }
91+ } else {
92+ ILOG (Error) << " Thresholds for histogram PageErrors: Requested error type " << errortype << " not found" << ENDM ;
93+ }
94+ }
95+
96+ if (param.find (keyThreshMajorAltroError) == 0 ) {
97+ auto errortype = param.substr (keyThreshMajorAltroError.length ());
98+ auto errorcode = findErrorCodeMAAE (errortype);
99+ if (errorcode > -1 ) {
100+ try {
101+ auto threshold = std::stoi (value);
102+ ILOG (Info) << " Setting custom threshold in Histogram MajorAltroErrors: " << errortype << " <= " << threshold << ENDM ;
103+ mErrorCountThresholdMAAE [errorcode] = threshold;
104+ } catch (...) {
105+ ILOG (Error) << " Thresholds for histogram MajorAltroErrors: Failure in decoding threshold value (" << value << " ) for error type " << errortype << ENDM ;
106+ }
107+ } else {
108+ ILOG (Error) << " Thresholds for histogram MajorAltroErrors: Requested error type " << errortype << " not found" << ENDM ;
109+ }
110+ }
111+
112+ if (param.find (keyThreshMinorAltroError) == 0 ) {
113+ auto errortype = param.substr (keyThreshMinorAltroError.length ());
114+ auto errorcode = findErrorCodeMIAE (errortype);
115+ if (errorcode > -1 ) {
116+ try {
117+ auto threshold = std::stoi (value);
118+ ILOG (Info) << " Setting custom threshold in Histogram MinorAltroError: " << errortype << " <= " << threshold << ENDM ;
119+ mErrorCountThresholdMAAE [errorcode] = threshold;
120+ } catch (...) {
121+ ILOG (Error) << " Thresholds for histogram MinorAltroError: Failure in decoding threshold value (" << value << " ) for error type " << errortype << ENDM ;
122+ }
123+ } else {
124+ ILOG (Error) << " Thresholds for histogram MinorAltroError: Requested error type " << errortype << " not found" << ENDM ;
125+ }
126+ }
127+
128+ if (param.find (keyThresRawFitError) == 0 ) {
129+ auto errortype = param.substr (keyThresRawFitError.length ());
130+ auto errorcode = findErrorCodeRFE (errortype);
131+ if (errorcode > -1 ) {
132+ try {
133+ auto threshold = std::stoi (value);
134+ ILOG (Info) << " Setting custom threshold in Histogram RawFitError: " << errortype << " <= " << threshold << ENDM ;
135+ mErrorCountThresholdRFE [errorcode] = threshold;
136+ } catch (...) {
137+ ILOG (Error) << " Thresholds for histogram RawFitError: Failure in decoding threshold value (" << value << " ) for error type " << errortype << ENDM ;
138+ }
139+ } else {
140+ ILOG (Error) << " Thresholds for histogram RawFitError: Requested error type " << errortype << " not found" << ENDM ;
141+ }
142+ }
143+
144+ if (param.find (keyThresholdGeometryError) == 0 ) {
145+ auto errortype = param.substr (keyThresholdGeometryError.length ());
146+ auto errorcode = findErrorCodeGEE (errortype);
147+ if (errorcode > -1 ) {
148+ try {
149+ auto threshold = std::stoi (value);
150+ ILOG (Info) << " Setting custom threshold in Histogram GeometryError: " << errortype << " <= " << threshold << ENDM ;
151+ mErrorCountThresholdGEE [errorcode] = threshold;
152+ } catch (...) {
153+ ILOG (Error) << " Thresholds for histogram GeometryError: Failure in decoding threshold value (" << value << " ) for error type " << errortype << ENDM ;
154+ }
155+ } else {
156+ ILOG (Error) << " Thresholds for histogram GeometryError: Requested error type " << errortype << " not found" << ENDM ;
157+ }
158+ }
159+
160+ if (param.find (keyThresholdGainTypeError) == 0 ) {
161+ auto errortype = param.substr (keyThresholdGainTypeError.length ());
162+ auto errorcode = findErrorCodeGTE (errortype);
163+ if (errorcode > -1 ) {
164+ try {
165+ auto threshold = std::stoi (value);
166+ ILOG (Info) << " Setting custom threshold in Histogram GainTypeError: " << errortype << " <= " << threshold << ENDM ;
167+ mErrorCountThresholdGTE [errorcode] = threshold;
168+ } catch (...) {
169+ ILOG (Error) << " Thresholds for histogram GainTypeError: Failure in decoding threshold value (" << value << " ) for error type " << errortype << ENDM ;
170+ }
171+ } else {
172+ ILOG (Error) << " Thresholds for histogram GainTypeError: Requested error type " << errortype << " not found" << ENDM ;
173+ }
174+ }
175+ }
51176}
52177
53178Quality RawErrorCheck::check (std::map<std::string, std::shared_ptr<MonitorObject>>* moMap)
@@ -57,20 +182,41 @@ Quality RawErrorCheck::check(std::map<std::string, std::shared_ptr<MonitorObject
57182 std::array<std::string, 2 > channelgainhists = { { " ChannelLGnoHG" , " ChannelHGnoLG" } };
58183 Quality result = Quality::Good;
59184
185+ std::map<std::string, const std::map<int , int >*> thresholdConfigErrorHists = {
186+ { " RawDataErrors" , &mErrorCountThresholdRDE },
187+ { " PageErrors" , &mErrorCountThresholdPE },
188+ { " MajorAltroErrors" , &mErrorCountThresholdMAAE },
189+ { " MinorAltroError" , &mErrorCountThresholdMIAE },
190+ { " RawFitError" , &mErrorCountThresholdRFE },
191+ { " GeometryError" , &mErrorCountThresholdGEE },
192+ { " GainTypeError" , &mErrorCountThresholdGTE }
193+ };
194+
60195 for (auto & [moName, mo] : *moMap) {
61196 if (std::find (errorhists.begin (), errorhists.end (), mo->getName ()) != errorhists.end ()) {
62197 // Check for presence of error codes
63198 auto * errorhist = dynamic_cast <TH2 *>(mo->getObject ());
64199
65- for (int linkID = 0 ; linkID < errorhist->GetXaxis ()->GetNbins (); linkID++) {
66- for (int errorcode = 0 ; errorcode < errorhist->GetYaxis ()->GetNbins (); errorcode++) {
67- if (errorhist->GetBinContent (linkID + 1 , errorcode + 1 )) {
68- // Found raw data error
69- if (result != Quality::Bad) {
70- result = Quality::Bad;
71- }
72- result.addReason (FlagReasonFactory::Unknown (), " Raw error " + std::string (errorhist->GetYaxis ()->GetBinLabel (errorcode + 1 )) + " found in DDL " + std::to_string (linkID));
200+ for (int errorcode = 0 ; errorcode < errorhist->GetYaxis ()->GetNbins (); errorcode++) {
201+ // try to find a threshold
202+ int threshold = 0 ;
203+ auto thresholdHandler = thresholdConfigErrorHists.find (mo->getName ());
204+ if (thresholdHandler != thresholdConfigErrorHists.end ()) {
205+ auto thresholdFound = thresholdHandler->second ->find (errorcode);
206+ if (thresholdFound != thresholdHandler->second ->end ()) {
207+ threshold = thresholdFound->second ;
208+ }
209+ }
210+ int numErrors = 0 ;
211+ for (int linkID = 0 ; linkID < errorhist->GetXaxis ()->GetNbins (); linkID++) {
212+ numErrors += errorhist->GetBinContent (linkID + 1 , errorcode + 1 );
213+ }
214+ if (numErrors > threshold) {
215+ // Found number of raw data errors is above threshold for bin
216+ if (result != Quality::Bad) {
217+ result = Quality::Bad;
73218 }
219+ result.addReason (FlagReasonFactory::Unknown (), " Raw error " + std::string (errorhist->GetYaxis ()->GetBinLabel (errorcode + 1 )) + " above threshold " + std::to_string (threshold));
74220 }
75221 }
76222 } else if (std::find (gainhists.begin (), gainhists.end (), mo->GetName ()) != gainhists.end ()) {
@@ -150,7 +296,7 @@ void RawErrorCheck::beautify(std::shared_ptr<MonitorObject> mo, Quality checkRes
150296 }
151297 }
152298 }
153- // SM grid
299+ // SM grid
154300 if (mo->getName ().find (" Channel" ) != std::string::npos) {
155301 auto * h2D = dynamic_cast <TH2 *>(mo->getObject ());
156302 // orizontal
@@ -170,7 +316,7 @@ void RawErrorCheck::beautify(std::shared_ptr<MonitorObject> mo, Quality checkRes
170316 TLine* l11 = new TLine (-0.5 , 200 , 95.5 , 200 );
171317 TLine* l12 = new TLine (47.5 , 200 , 47.5 , 207.5 );
172318
173- // vertical
319+ // vertical
174320 TLine* l13 = new TLine (47.5 , -0.5 , 47.5 , 128 );
175321 TLine* l14 = new TLine (31.5 , 128 , 31.5 , 200 );
176322 TLine* l15 = new TLine (63.5 , 128 , 63.5 , 200 );
@@ -221,4 +367,88 @@ bool RawErrorCheck::decodeBool(std::string value) const
221367 throw std::runtime_error (fmt::format (" Value {} not a boolean" , value.data ()).data ());
222368}
223369
370+ int RawErrorCheck::findErrorCodeRDE (const std::string_view errorname) const
371+ {
372+ int result = -1 ;
373+ for (int error = 0 ; error < o2::emcal::ErrorTypeFEE::getNumberOfErrorTypes (); error++) {
374+ if (std::string_view (o2::emcal::ErrorTypeFEE::getErrorTypeName (error)) == errorname) {
375+ result = error;
376+ break ;
377+ }
378+ }
379+ return result;
380+ }
381+
382+ int RawErrorCheck::findErrorCodePE (const std::string_view errorname) const
383+ {
384+ int result = -1 ;
385+ for (int error = 0 ; error < o2::emcal::RawDecodingError::getNumberOfErrorTypes (); error++) {
386+ if (std::string_view (o2::emcal::RawDecodingError::getErrorCodeNames (error)) == errorname) {
387+ result = error;
388+ break ;
389+ }
390+ }
391+ return result;
392+ }
393+
394+ int RawErrorCheck::findErrorCodeMAAE (const std::string_view errorname) const
395+ {
396+ int result = -1 ;
397+ for (int error = 0 ; error < o2::emcal::AltroDecoderError::getNumberOfErrorTypes (); error++) {
398+ if (std::string_view (o2::emcal::AltroDecoderError::getErrorTypeName (error)) == errorname) {
399+ result = error;
400+ break ;
401+ }
402+ }
403+ return result;
404+ }
405+
406+ int RawErrorCheck::findErrorCodeMIAE (const std::string_view errorname) const
407+ {
408+ int result = -1 ;
409+ for (int error = 0 ; error < o2::emcal::MinorAltroDecodingError::getNumberOfErrorTypes (); error++) {
410+ if (std::string_view (o2::emcal::MinorAltroDecodingError::getErrorTypeName (error)) == errorname) {
411+ result = error;
412+ break ;
413+ }
414+ }
415+ return result;
416+ }
417+
418+ int RawErrorCheck::findErrorCodeRFE (const std::string_view errorname) const
419+ {
420+ int result = -1 ;
421+ for (int error = 0 ; error < o2::emcal::CaloRawFitter::getNumberOfErrorTypes (); error++) {
422+ if (std::string_view (o2::emcal::CaloRawFitter::getErrorTypeName (error)) == errorname) {
423+ result = error;
424+ break ;
425+ }
426+ }
427+ return result;
428+ }
429+
430+ int RawErrorCheck::findErrorCodeGEE (const std::string_view errorname) const
431+ {
432+ int result = -1 ;
433+ for (int error = 0 ; error < o2::emcal::reconstructionerrors::getNumberOfGeometryErrorCodes (); error++) {
434+ if (std::string_view (o2::emcal::reconstructionerrors::getGeometryErrorName (error)) == errorname) {
435+ result = error;
436+ break ;
437+ }
438+ }
439+ return result;
440+ }
441+
442+ int RawErrorCheck::findErrorCodeGTE (const std::string_view errorname) const
443+ {
444+ int result = -1 ;
445+ for (int error = 0 ; error < o2::emcal::reconstructionerrors::getNumberOfGainErrorCodes (); error++) {
446+ if (std::string_view (o2::emcal::reconstructionerrors::getGainErrorName (error)) == errorname) {
447+ result = error;
448+ break ;
449+ }
450+ }
451+ return result;
452+ }
453+
224454} // namespace o2::quality_control_modules::emcal
0 commit comments