File indexing completed on 2024-04-06 12:10:09
0001 #ifndef DQMSERVICES_CORE_Q_CRITERION_H
0002 #define DQMSERVICES_CORE_Q_CRITERION_H
0003
0004 #include "DQMServices/Core/interface/MonitorElement.h"
0005 #include "TProfile2D.h"
0006 #include "TProfile.h"
0007 #include "TH2F.h"
0008 #include "TH1F.h"
0009 #include <sstream>
0010 #include <string>
0011 #include <map>
0012 #include <utility>
0013
0014
0015
0016 using DQMChannel = MonitorElementData::QReport::DQMChannel;
0017 using QReport = MonitorElementData::QReport;
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 class QCriterion {
0032
0033
0034 public:
0035 typedef dqm::legacy::MonitorElement MonitorElement;
0036
0037 int getStatus() const { return status_; }
0038
0039 std::string getMessage() const { return message_; }
0040
0041 std::string getName() const { return qtname_; }
0042
0043 std::string algoName() const { return algoName_; }
0044
0045 void setWarningProb(float prob) { warningProb_ = prob; }
0046 void setErrorProb(float prob) { errorProb_ = prob; }
0047
0048
0049 virtual std::vector<DQMChannel> getBadChannels() const { return std::vector<DQMChannel>(); }
0050
0051 QCriterion(std::string qtname) {
0052 qtname_ = std::move(qtname);
0053 init();
0054 }
0055
0056 void init();
0057
0058 virtual ~QCriterion() = default;
0059
0060
0061 static const float WARNING_PROB_THRESHOLD;
0062 static const float ERROR_PROB_THRESHOLD;
0063
0064 float runTest(const MonitorElement *me, QReport &qr, DQMNet::QValue &qv) {
0065 assert(qv.qtname == qtname_);
0066
0067 prob_ = runTest(me);
0068
0069 if (prob_ < errorProb_)
0070 status_ = dqm::qstatus::ERROR;
0071 else if (prob_ < warningProb_)
0072 status_ = dqm::qstatus::WARNING;
0073 else
0074 status_ = dqm::qstatus::STATUS_OK;
0075
0076 setMessage();
0077
0078 if (verbose_ == 2)
0079 std::cout << " Message = " << message_ << std::endl;
0080 if (verbose_ == 2)
0081 std::cout << " Name = " << qtname_ << " / Algorithm = " << algoName_ << " / Status = " << status_
0082 << " / Prob = " << prob_ << std::endl;
0083
0084 qv.code = status_;
0085 qv.message = message_;
0086 qv.qtname = qtname_;
0087 qv.algorithm = algoName_;
0088 qv.qtresult = prob_;
0089 qr.setBadChannels(getBadChannels());
0090
0091 return prob_;
0092 }
0093
0094 protected:
0095
0096 void setAlgoName(std::string name) { algoName_ = std::move(name); }
0097
0098 virtual float runTest(const MonitorElement *me);
0099
0100
0101 virtual void setMessage() = 0;
0102
0103 std::string qtname_;
0104 std::string algoName_;
0105 float prob_;
0106 int status_;
0107 std::string message_;
0108 float warningProb_, errorProb_;
0109 void setVerbose(int verbose) { verbose_ = verbose; }
0110 int verbose_;
0111
0112 private:
0113
0114 friend class dqm::legacy::MonitorElement;
0115 friend class dqm::impl::MonitorElement;
0116 };
0117
0118
0119
0120
0121
0122 class SimpleTest : public QCriterion {
0123 public:
0124 SimpleTest(const std::string &name, bool keepBadChannels = false)
0125 : QCriterion(name), minEntries_(0), keepBadChannels_(keepBadChannels) {}
0126
0127
0128 void setMinimumEntries(unsigned n) { minEntries_ = n; }
0129
0130 std::vector<DQMChannel> getBadChannels() const override {
0131 return keepBadChannels_ ? badChannels_ : QCriterion::getBadChannels();
0132 }
0133
0134 protected:
0135
0136 void setMessage() override { message_.clear(); }
0137
0138 unsigned minEntries_;
0139 std::vector<DQMChannel> badChannels_;
0140 bool keepBadChannels_;
0141 };
0142
0143
0144
0145
0146
0147
0148
0149 class ContentsXRange : public SimpleTest {
0150 public:
0151 ContentsXRange(const std::string &name) : SimpleTest(name) {
0152 rangeInitialized_ = false;
0153 setAlgoName(getAlgoName());
0154 }
0155 static std::string getAlgoName() { return "ContentsXRange"; }
0156 float runTest(const MonitorElement *me) override;
0157
0158
0159 virtual void setAllowedXRange(double xmin, double xmax) {
0160 xmin_ = xmin;
0161 xmax_ = xmax;
0162 rangeInitialized_ = true;
0163 }
0164
0165 protected:
0166 double xmin_;
0167 double xmax_;
0168 bool rangeInitialized_;
0169 };
0170
0171
0172
0173 class ContentsYRange : public SimpleTest {
0174 public:
0175 ContentsYRange(const std::string &name) : SimpleTest(name, true) {
0176 rangeInitialized_ = false;
0177 setAlgoName(getAlgoName());
0178 }
0179 static std::string getAlgoName() { return "ContentsYRange"; }
0180 float runTest(const MonitorElement *me) override;
0181
0182 void setUseEmptyBins(unsigned int useEmptyBins) { useEmptyBins_ = useEmptyBins; }
0183 virtual void setAllowedYRange(double ymin, double ymax) {
0184 ymin_ = ymin;
0185 ymax_ = ymax;
0186 rangeInitialized_ = true;
0187 }
0188
0189 protected:
0190 double ymin_;
0191 double ymax_;
0192 bool rangeInitialized_;
0193 unsigned int useEmptyBins_;
0194 };
0195
0196
0197
0198 class DeadChannel : public SimpleTest {
0199 public:
0200 DeadChannel(const std::string &name) : SimpleTest(name, true) {
0201 rangeInitialized_ = false;
0202 setAlgoName(getAlgoName());
0203 }
0204 static std::string getAlgoName() { return "DeadChannel"; }
0205 float runTest(const MonitorElement *me) override;
0206
0207
0208 void setThreshold(double ymin) {
0209 ymin_ = ymin;
0210 rangeInitialized_ = true;
0211 }
0212
0213 protected:
0214 double ymin_;
0215 bool rangeInitialized_;
0216 };
0217
0218
0219
0220 class NoisyChannel : public SimpleTest {
0221 public:
0222 NoisyChannel(const std::string &name) : SimpleTest(name, true) {
0223 rangeInitialized_ = false;
0224 numNeighbors_ = 1;
0225 setAlgoName(getAlgoName());
0226 }
0227 static std::string getAlgoName() { return "NoisyChannel"; }
0228 float runTest(const MonitorElement *me) override;
0229
0230
0231
0232
0233
0234
0235
0236
0237 void setNumNeighbors(unsigned n) {
0238 if (n > 0)
0239 numNeighbors_ = n;
0240 }
0241
0242
0243
0244
0245
0246 void setTolerance(float percentage) {
0247 if (percentage >= 0) {
0248 tolerance_ = percentage;
0249 rangeInitialized_ = true;
0250 }
0251 }
0252
0253 protected:
0254
0255
0256 double getAverage(int bin, const TH1 *h) const;
0257 double getAverage2D(int binX, int binY, const TH2 *h) const;
0258
0259 float tolerance_;
0260 unsigned numNeighbors_;
0261
0262 bool rangeInitialized_;
0263 };
0264
0265
0266
0267 class ContentSigma : public SimpleTest {
0268 public:
0269 ContentSigma(const std::string &name) : SimpleTest(name, true) {
0270 rangeInitialized_ = false;
0271 numXblocks_ = 1;
0272 numYblocks_ = 1;
0273 numNeighborsX_ = 1;
0274 numNeighborsY_ = 1;
0275 setAlgoName(getAlgoName());
0276 }
0277 static std::string getAlgoName() { return "ContentSigma"; }
0278
0279 float runTest(const MonitorElement *me) override;
0280
0281
0282
0283
0284
0285
0286
0287 void setNumXblocks(unsigned ncx) {
0288 if (ncx > 0)
0289 numXblocks_ = ncx;
0290 }
0291 void setNumYblocks(unsigned ncy) {
0292 if (ncy > 0)
0293 numYblocks_ = ncy;
0294 }
0295 void setNumNeighborsX(unsigned ncx) {
0296 if (ncx > 0)
0297 numNeighborsX_ = ncx;
0298 }
0299 void setNumNeighborsY(unsigned ncy) {
0300 if (ncy > 0)
0301 numNeighborsY_ = ncy;
0302 }
0303
0304
0305
0306
0307 void setToleranceNoisy(float factorNoisy) {
0308 if (factorNoisy >= 0) {
0309 toleranceNoisy_ = factorNoisy;
0310 rangeInitialized_ = true;
0311 }
0312 }
0313 void setToleranceDead(float factorDead) {
0314 if (factorDead >= 0) {
0315 toleranceDead_ = factorDead;
0316 rangeInitialized_ = true;
0317 }
0318 }
0319 void setNoisy(bool noisy) { noisy_ = noisy; }
0320 void setDead(bool dead) { dead_ = dead; }
0321
0322 void setXMin(unsigned xMin) { xMin_ = xMin; }
0323 void setXMax(unsigned xMax) { xMax_ = xMax; }
0324 void setYMin(unsigned yMin) { yMin_ = yMin; }
0325 void setYMax(unsigned yMax) { yMax_ = yMax; }
0326
0327 protected:
0328
0329
0330 double getNeighborSum(unsigned groupx,
0331 unsigned groupy,
0332 unsigned Xblocks,
0333 unsigned Yblocks,
0334 unsigned neighborsX,
0335 unsigned neighborsY,
0336 const TH1 *h) const;
0337 double getNeighborSigma(double average,
0338 unsigned groupx,
0339 unsigned groupy,
0340 unsigned Xblocks,
0341 unsigned Yblocks,
0342 unsigned neighborsX,
0343 unsigned neighborsY,
0344 const TH1 *h) const;
0345
0346 bool noisy_;
0347 bool dead_;
0348 float toleranceNoisy_;
0349 float toleranceDead_;
0350 unsigned numXblocks_;
0351 unsigned numYblocks_;
0352 unsigned numNeighborsX_;
0353
0354 unsigned numNeighborsY_;
0355
0356 bool rangeInitialized_;
0357 unsigned xMin_;
0358 unsigned xMax_;
0359 unsigned yMin_;
0360 unsigned yMax_;
0361 };
0362
0363
0364
0365 class ContentsWithinExpected : public SimpleTest {
0366 public:
0367 ContentsWithinExpected(const std::string &name) : SimpleTest(name, true) {
0368 checkMean_ = checkRMS_ = false;
0369 minMean_ = maxMean_ = minRMS_ = maxRMS_ = 0.0;
0370 checkMeanTolerance_ = false;
0371 toleranceMean_ = -1.0;
0372 setAlgoName(getAlgoName());
0373 }
0374 static std::string getAlgoName() { return "ContentsWithinExpected"; }
0375 float runTest(const MonitorElement *me) override;
0376
0377 void setUseEmptyBins(unsigned int useEmptyBins) { useEmptyBins_ = useEmptyBins; }
0378 void setMeanRange(double xmin, double xmax);
0379 void setRMSRange(double xmin, double xmax);
0380
0381
0382 void setMeanTolerance(float fracTolerance) {
0383 if (fracTolerance >= 0.0) {
0384 toleranceMean_ = fracTolerance;
0385 checkMeanTolerance_ = true;
0386 }
0387 }
0388
0389 protected:
0390 bool checkMean_;
0391 bool checkRMS_;
0392 bool checkMeanTolerance_;
0393 float toleranceMean_;
0394 float minMean_, maxMean_;
0395 float minRMS_, maxRMS_;
0396 unsigned int useEmptyBins_;
0397 };
0398
0399
0400
0401 class MeanWithinExpected : public SimpleTest {
0402 public:
0403 MeanWithinExpected(const std::string &name) : SimpleTest(name) { setAlgoName(getAlgoName()); }
0404 static std::string getAlgoName() { return "MeanWithinExpected"; }
0405 float runTest(const MonitorElement *me) override;
0406
0407 void setExpectedMean(double mean) { expMean_ = mean; }
0408 void useRange(double xmin, double xmax);
0409 void useSigma(double expectedSigma);
0410 void useRMS();
0411
0412 protected:
0413 bool useRMS_;
0414 bool useSigma_;
0415 bool useRange_;
0416 double sigma_;
0417 double expMean_;
0418 double xmin_, xmax_;
0419 };
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484 #if 0
0485 class FlatOccupancy1d : public SimpleTest
0486 {
0487 public:
0488 FlatOccupancy1d(const std::string &name) : SimpleTest(name)
0489 {
0490 Nbins = 0;
0491 FailedBins[0] = 0;
0492 FailedBins[1] = 0;
0493 setAlgoName(getAlgoName());
0494 }
0495
0496 ~FlatOccupancy1d(void)
0497 {
0498 delete [] FailedBins[0];
0499 delete [] FailedBins[1];
0500 }
0501
0502 static std::string getAlgoName(void) { return "RuleFlatOccupancy1d"; }
0503
0504 void set_ExclusionMask(double *mask) { ExclusionMask = mask; }
0505 void set_epsilon_min(double epsilon) { epsilon_min = epsilon; }
0506 void set_epsilon_max(double epsilon) { epsilon_max = epsilon; }
0507 void set_S_fail(double S) { S_fail = S; }
0508 void set_S_pass(double S) { S_pass = S; }
0509 double get_FailedBins(void) { return *FailedBins[1]; }
0510 int get_result() { return result; }
0511
0512 float runTest(const MonitorElement*me);
0513
0514 protected:
0515 double *ExclusionMask;
0516 double epsilon_min, epsilon_max;
0517 double S_fail, S_pass;
0518 double *FailedBins[2];
0519 int Nbins;
0520 int result;
0521 };
0522 #endif
0523
0524
0525 class FixedFlatOccupancy1d : public SimpleTest {
0526 public:
0527 FixedFlatOccupancy1d(const std::string &name) : SimpleTest(name) {
0528 Nbins = 0;
0529 FailedBins[0] = nullptr;
0530 FailedBins[1] = nullptr;
0531 setAlgoName(getAlgoName());
0532 }
0533
0534 ~FixedFlatOccupancy1d() override {
0535 if (Nbins > 0) {
0536 delete[] FailedBins[0];
0537 delete[] FailedBins[1];
0538 }
0539 }
0540
0541 static std::string getAlgoName() { return "RuleFixedFlatOccupancy1d"; }
0542
0543 void set_Occupancy(double level) { b = level; }
0544 void set_ExclusionMask(double *mask) { ExclusionMask = mask; }
0545 void set_epsilon_min(double epsilon) { epsilon_min = epsilon; }
0546 void set_epsilon_max(double epsilon) { epsilon_max = epsilon; }
0547 void set_S_fail(double S) { S_fail = S; }
0548 void set_S_pass(double S) { S_pass = S; }
0549 double get_FailedBins() { return *FailedBins[1]; }
0550 int get_result() { return result; }
0551
0552 float runTest(const MonitorElement *me) override;
0553
0554 protected:
0555 double b;
0556 double *ExclusionMask;
0557 double epsilon_min, epsilon_max;
0558 double S_fail, S_pass;
0559 double *FailedBins[2];
0560 int Nbins;
0561 int result;
0562 };
0563
0564
0565 class CSC01 : public SimpleTest {
0566 public:
0567 CSC01(const std::string &name) : SimpleTest(name) { setAlgoName(getAlgoName()); }
0568 static std::string getAlgoName() { return "RuleCSC01"; }
0569
0570 void set_epsilon_max(double epsilon) { epsilon_max = epsilon; }
0571 void set_S_fail(double S) { S_fail = S; }
0572 void set_S_pass(double S) { S_pass = S; }
0573 double get_epsilon_obs() { return epsilon_obs; }
0574 double get_S_fail_obs() { return S_fail_obs; }
0575 double get_S_pass_obs() { return S_pass_obs; }
0576 int get_result() { return result; }
0577
0578 float runTest(const MonitorElement *me) override;
0579
0580 protected:
0581 double epsilon_max;
0582 double S_fail, S_pass;
0583 double epsilon_obs;
0584 double S_fail_obs, S_pass_obs;
0585 int result;
0586 };
0587
0588
0589 class CompareToMedian : public SimpleTest {
0590 public:
0591
0592 CompareToMedian(const std::string &name) : SimpleTest(name, true) {
0593 this->_min = 0.2;
0594 this->_max = 3.0;
0595 this->_emptyBins = 0;
0596 this->_maxMed = 10;
0597 this->_minMed = 0;
0598 this->nBins = 0;
0599 this->_statCut = 0;
0600 reset();
0601 setAlgoName(getAlgoName());
0602 };
0603
0604 ~CompareToMedian() override = default;
0605 ;
0606
0607 static std::string getAlgoName() { return "CompareToMedian"; }
0608
0609 float runTest(const MonitorElement *me) override;
0610 void setMin(float min) { _min = min; };
0611 void setMax(float max) { _max = max; };
0612 void setEmptyBins(int eB) { eB > 0 ? _emptyBins = 1 : _emptyBins = 0; };
0613 void setMaxMedian(float max) { _maxMed = max; };
0614 void setMinMedian(float min) { _minMed = min; };
0615 void setStatCut(float cut) { _statCut = (cut > 0) ? cut : 0; };
0616
0617 protected:
0618 void setMessage() override {
0619 std::ostringstream message;
0620 message << "Test " << qtname_ << " (" << algoName_ << "): Entry fraction within range = " << prob_;
0621 message_ = message.str();
0622 }
0623
0624 private:
0625 float _min, _max;
0626 int _emptyBins;
0627 float _maxMed, _minMed;
0628 float _statCut;
0629
0630 int nBinsX, nBinsY;
0631
0632 int nBins;
0633
0634
0635 std::vector<float> binValues;
0636
0637 void reset() { binValues.clear(); };
0638 };
0639
0640 class CompareLastFilledBin : public SimpleTest {
0641 public:
0642
0643 CompareLastFilledBin(const std::string &name) : SimpleTest(name, true) {
0644 this->_min = 0.0;
0645 this->_max = 1.0;
0646 this->_average = 0.0;
0647 setAlgoName(getAlgoName());
0648 };
0649
0650 ~CompareLastFilledBin() override = default;
0651 ;
0652
0653 static std::string getAlgoName() { return "CompareLastFilledBin"; }
0654
0655 float runTest(const MonitorElement *me) override;
0656 void setAverage(float average) { _average = average; };
0657 void setMin(float min) { _min = min; };
0658 void setMax(float max) { _max = max; };
0659
0660 protected:
0661 void setMessage() override {
0662 std::ostringstream message;
0663 message << "Test " << qtname_ << " (" << algoName_ << "): Last Bin filled with desired value = " << prob_;
0664 message_ = message.str();
0665 }
0666
0667 private:
0668 float _min, _max;
0669 float _average;
0670 };
0671
0672
0673 #if 0
0674 class AllContentAlongDiagonal : public SimpleTest
0675
0676 public:
0677 AllContentAlongDiagonal(const std::string &name) : SimpleTest(name)
0678 {
0679 setAlgoName(getAlgoName());
0680 }
0681 static std::string getAlgoName(void) { return "RuleAllContentAlongDiagonal"; }
0682
0683 void set_epsilon_max(double epsilon) { epsilon_max = epsilon; }
0684 void set_S_fail(double S) { S_fail = S; }
0685 void set_S_pass(double S) { S_pass = S; }
0686 double get_epsilon_obs() { return epsilon_obs; }
0687 double get_S_fail_obs() { return S_fail_obs; }
0688 double get_S_pass_obs() { return S_pass_obs; }
0689 int get_result() { return result; }
0690
0691
0692
0693 float runTest(const MonitorElement*me);
0694
0695 protected:
0696 double epsilon_max;
0697 double S_fail, S_pass;
0698 double epsilon_obs;
0699 double S_fail_obs, S_pass_obs;
0700 int result;
0701 };
0702 #endif
0703
0704
0705 class CheckVariance : public SimpleTest {
0706 public:
0707 CheckVariance(const std::string &name) : SimpleTest(name) { setAlgoName(getAlgoName()); }
0708
0709 static std::string getAlgoName() { return "CheckVariance"; }
0710 float runTest(const MonitorElement *me) override;
0711 };
0712 #endif