9 #include "Math/ProbFuncMathCore.h" 20 errorProb_ = ERROR_PROB_THRESHOLD;
21 warningProb_ = WARNING_PROB_THRESHOLD;
22 setAlgoName(
"NO_ALGORITHM");
24 message_ =
"NO_MESSAGE";
30 raiseDQMError(
"QCriterion",
"virtual runTest method called" );
53 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 54 << me-> getFullname() <<
"\n";
61 nbins = me->
getTH1F()->GetXaxis()->GetNbins();
62 nbinsref = me->
getRefTH1F()->GetXaxis()->GetNbins();
65 if (nbins != nbinsref)
return -1;
70 nbins = me->
getTH1S()->GetXaxis()->GetNbins();
71 nbinsref = me->
getRefTH1S()->GetXaxis()->GetNbins();
74 if (nbins != nbinsref)
return -1;
79 nbins = me->
getTH1D()->GetXaxis()->GetNbins();
80 nbinsref = me->
getRefTH1D()->GetXaxis()->GetNbins();
83 if (nbins != nbinsref)
return -1;
92 if (nbins != nbinsref)
return -1;
98 nbins = me->
getTH2F()->GetXaxis()->GetNbins() *
99 me->
getTH2F()->GetYaxis()->GetNbins();
100 nbinsref = me->
getRefTH2F()->GetXaxis()->GetNbins() *
104 if (nbins != nbinsref)
return -1;
110 nbins = me->
getTH2S()->GetXaxis()->GetNbins() *
111 me->
getTH2S()->GetYaxis()->GetNbins();
112 nbinsref = me->
getRefTH2S()->GetXaxis()->GetNbins() *
116 if (nbins != nbinsref)
return -1;
122 nbins = me->
getTH2D()->GetXaxis()->GetNbins() *
123 me->
getTH2D()->GetYaxis()->GetNbins();
124 nbinsref = me->
getRefTH2D()->GetXaxis()->GetNbins() *
128 if (nbins != nbinsref)
return -1;
134 nbins = me->
getTH3F()->GetXaxis()->GetNbins() *
135 me->
getTH3F()->GetYaxis()->GetNbins() *
136 me->
getTH3F()->GetZaxis()->GetNbins();
137 nbinsref = me->
getRefTH3F()->GetXaxis()->GetNbins() *
142 if (nbins != nbinsref)
return -1;
149 <<
" ME does not contain TH1F/TH1S/TH1D/TH2F/TH2S/TH2D/TH3F, exiting\n";
156 bool failure =
false;
160 if (contents != ref_->GetBinContent(
bin))
164 badChannels_.push_back(
chan);
167 if (failure)
return 0;
184 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 185 << me-> getFullname() <<
"\n";
214 <<
" ME does not contain TH1F/TH1S/TH1D/TProfile, exiting\n";
219 int ncx1 = h->GetXaxis()->GetNbins();
220 int ncx2 = ref_->GetXaxis()->GetNbins();
225 <<
" different number of channels! (" 226 << ncx1 <<
", " << ncx2 <<
"), exiting\n";
232 Ndof_ = 0; chi2_ = -1.; ncx1 = ncx2 = -1;
234 int i, i_start, i_end;
240 i_start = h->GetXaxis()->GetFirst();
241 i_end = h->GetXaxis()->GetLast();
246 double sum1=0,
sum2=0;
247 for (i=i_start; i<=i_end; i++)
249 sum1 += h->GetBinContent(i);
250 sum2 += ref_->GetBinContent(i);
258 <<
" Test Histogram " << h->GetName()
259 <<
" is empty, exiting\n";
266 <<
" Ref Histogram " << ref_->GetName()
267 <<
" is empty, exiting\n";
271 double bin1, bin2, err1, err2,
temp;
272 for (i=i_start; i<=i_end; i++)
274 bin1 = h->GetBinContent(i)/sum1;
275 bin2 = ref_->GetBinContent(i)/
sum2;
276 if (bin1 ==0 && bin2==0)
283 err1=h->GetBinError(i); err2=ref_->GetBinError(i);
284 if (err1 == 0 && err2 == 0)
288 <<
" bins with non-zero content and zero error, exiting\n";
291 err1*=err1 ; err2*=err2;
293 chi2 +=temp*temp/(err1+err2);
297 return TMath::Prob(0.5*chi2,
int(0.5*ndof));
309 if (minEntries_ != 0 && me->
getEntries() < minEntries_)
316 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 317 << me-> getFullname() <<
"\n";
346 <<
" ME does not contain TH2F/TH2S/TH2D/TProfile2D, exiting\n";
351 int ncx1 = h->GetXaxis()->GetNbins();
352 int ncx2 = ref_->GetXaxis()->GetNbins();
353 int ncy1 = h->GetYaxis()->GetNbins();
354 int ncy2 = ref_->GetYaxis()->GetNbins();
355 if ( ( ncx1 != ncx2) || ( ncy1 != ncy2) )
359 <<
" different number of channels! (" 360 << ncx1 <<
", " << ncx2 <<
"), (" 361 << ncy1 <<
", " << ncy2 <<
"), exiting\n";
367 Ndof_ = 0; chi2_ = -1.;
370 int i_start = h->GetXaxis()->GetFirst();
371 int i_end = h->GetXaxis()->GetLast();
372 int j_start = h->GetYaxis()->GetFirst();
373 int j_end = h->GetYaxis()->GetLast();
374 if (h->Integral(i_start, i_end, j_start, j_end) == 0)
378 <<
" Test Histogram " << h->GetName()
379 <<
" is empty, exiting\n";
382 if (ref_->Integral(i_start, i_end, j_start, j_end) == 0)
386 <<
" Ref Histogram " << ref_->GetName()
387 <<
" is empty, exiting\n";
393 double pValue = h->Chi2TestX(ref_, chi2_, Ndof_, igood,
"");
395 if (chi2_==-1. && Ndof_==0)
407 const double difprec = 1
e-5;
417 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 418 << me-> getFullname() <<
"\n";
447 <<
" ME does not contain TH1F/TH1S/TH1D/TProfile, exiting\n";
452 int ncx1 = h->GetXaxis()->GetNbins();
453 int ncx2 = ref_->GetXaxis()->GetNbins();
458 <<
" different number of channels! (" 459 << ncx1 <<
", " << ncx2 <<
"), exiting\n";
463 double diff1 =
std::abs(h->GetXaxis()->GetXmin() - ref_->GetXaxis()->GetXmin());
464 double diff2 =
std::abs(h->GetXaxis()->GetXmax() - ref_->GetXaxis()->GetXmax());
465 if (diff1 > difprec || diff2 > difprec)
469 <<
" histograms with different binning, exiting\n";
474 Bool_t afunc1 = kFALSE; Bool_t afunc2 = kFALSE;
475 double sum1 = 0,
sum2 = 0;
476 double ew1, ew2, w1 = 0,
w2 = 0;
478 for (bin=1;bin<=ncx1;bin++)
480 sum1 += h->GetBinContent(bin);
481 sum2 += ref_->GetBinContent(bin);
482 ew1 = h->GetBinError(bin);
483 ew2 = ref_->GetBinError(bin);
492 <<
" Test Histogram: " << h->GetName()
493 <<
": integral is zero, exiting\n";
500 <<
" Ref Histogram: " << ref_->GetName()
501 <<
": integral is zero, exiting\n";
505 double tsum1 = sum1;
double tsum2 =
sum2;
506 tsum1 += h->GetBinContent(0);
507 tsum2 += ref_->GetBinContent(0);
508 tsum1 += h->GetBinContent(ncx1+1);
509 tsum2 += ref_->GetBinContent(ncx1+1);
514 double ne1 = h->GetEntries();
515 double ne2 = ref_->GetEntries();
517 double difsum1 = (ne1-tsum1)/tsum1;
519 if (difsum1 > difprec &&
int(ne1) != ncx1)
521 if (h->GetSumw2N() == 0)
525 <<
" Weighted events and no Sumw2 for " 526 << h->GetName() <<
"\n";
530 esum1 = sum1*sum1/w1;
534 double difsum2 = (ne2-tsum2)/tsum2;
536 if (difsum2 > difprec &&
int(ne2) != ncx1)
538 if (ref_->GetSumw2N() == 0)
542 <<
" Weighted events and no Sumw2 for " 543 << ref_->GetName() <<
"\n";
551 double s1 = 1/tsum1;
double s2 = 1/tsum2;
553 double dfmax =0, rsum1 = 0, rsum2 = 0;
558 for ( bin=first; bin<=
last; bin++)
560 rsum1 += s1*h->GetBinContent(bin);
561 rsum2 += s2*ref_->GetBinContent(bin);
567 if (afunc1) z = dfmax*TMath::Sqrt(esum2);
568 else if (afunc2) z = dfmax*TMath::Sqrt(esum1);
569 else z = dfmax*TMath::Sqrt(esum1*esum2/(esum1+esum2));
575 <<
" Numerical problems with histogram " 576 << h->GetName() <<
"\n";
580 <<
" Numerical problems with histogram " 581 << ref_->GetName() <<
"\n";
583 return TMath::KolmogorovProb(z);
591 badChannels_.clear();
600 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 601 << me-> getFullname() <<
"\n";
619 if (verbose_>0)
std::cout <<
"QTest:ContentsXRange" 621 <<
" does not contain TH1F/TH1S/TH1D, exiting\n";
625 if (!rangeInitialized_)
628 setAllowedXRange(h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax());
632 int ncx = h->GetXaxis()->GetNbins();
642 for (bin = first; bin <=
last; ++
bin)
644 double contents = h->GetBinContent(bin);
645 double x = h->GetBinCenter(bin);
647 if (x < xmin_ || x > xmax_)fail +=
contents;
650 if (sum==0)
return 1;
652 return (sum - fail)/sum;
661 badChannels_.clear();
670 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 671 << me-> getFullname() <<
"\n";
690 <<
" does not contain TH1F/TH1S/TH1D, exiting\n";
694 if (!rangeInitialized_ || !h->GetXaxis())
return 1;
695 int ncx = h->GetXaxis()->GetNbins();
706 for (bin = first; bin <=
last; ++
bin)
708 double contents = h->GetBinContent(bin);
709 bool failure =
false;
710 failure = (contents < ymin_ || contents > ymax_);
714 badChannels_.push_back(
chan);
719 return 1.*(ncx -
fail)/ncx;
723 for (bin = first; bin <=
last; ++
bin)
725 double contents = h->GetBinContent(bin);
726 bool failure =
false;
727 if (contents) failure = (contents < ymin_ || contents > ymax_);
731 return 1.*(ncx -
fail)/ncx;
740 badChannels_.clear();
749 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 750 << me-> getFullname() <<
"\n";
786 <<
" does not contain TH1F/TH1S/TH1D/TH2F/TH2S/TH2D, exiting\n";
795 if (!rangeInitialized_ || !h1->GetXaxis() )
797 int ncx = h1->GetXaxis()->GetNbins();
803 for (bin = first; bin <=
last; ++
bin)
805 double contents = h1->GetBinContent(bin);
806 bool failure =
false;
807 failure = contents <= ymin_;
811 badChannels_.push_back(
chan);
816 return 1.*(ncx -
fail)/ncx;
821 else if (h2 !=
nullptr )
823 int ncx = h2->GetXaxis()->GetNbins();
824 int ncy = h2->GetYaxis()->GetNbins();
827 for (
int cx = 1; cx <= ncx; ++cx)
829 for (
int cy = 1; cy <= ncy; ++cy)
831 double contents = h2->GetBinContent(h2->GetBin(cx, cy));
832 bool failure =
false;
833 failure = contents <= ymin_;
836 DQMChannel chan(cx, cy, 0, contents, h2->GetBinError(h2->GetBin(cx, cy)));
837 badChannels_.push_back(chan);
843 return 1.*(ncx*ncy -
fail) / (ncx*ncy);
849 <<
" TH1/TH2F are NULL, exiting\n";
861 badChannels_.clear();
870 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 871 << me-> getFullname() <<
"\n";
874 int nbinsX=0, nbinsY=0;
878 nbins = me->
getTH1F()->GetXaxis()->GetNbins();
884 nbins = me->
getTH1S()->GetXaxis()->GetNbins();
890 nbins = me->
getTH1D()->GetXaxis()->GetNbins();
896 nbinsX = me->
getTH2F()->GetXaxis()->GetNbins();
897 nbinsY = me->
getTH2F()->GetYaxis()->GetNbins();
903 nbinsX = me->
getTH2S()->GetXaxis()->GetNbins();
904 nbinsY = me->
getTH2S()->GetYaxis()->GetNbins();
910 nbinsX = me->
getTH2F()->GetXaxis()->GetNbins();
911 nbinsY = me->
getTH2F()->GetYaxis()->GetNbins();
919 <<
" does not contain TH1F/TH1S/TH1D or TH2F/TH2S/TH2D, exiting\n";
929 int lastX = nbinsX, lastY = nbinsY;
935 if ( !rangeInitialized_ || !h->GetXaxis() ){
938 for (bin = first; bin <=
last; ++
bin)
940 double contents = h->GetBinContent(bin);
941 double average = getAverage(bin, h);
942 bool failure =
false;
944 failure = (((contents-average)/
std::abs(average)) > tolerance_);
950 badChannels_.push_back(
chan);
955 return 1.*(nbins -
fail)/nbins;
957 else if (h2 !=
nullptr ) {
958 for (binY = first; binY <= lastY; ++binY) {
959 for (binX = first; binX <= lastX; ++binX) {
960 double contents = h2->GetBinContent(binX, binY);
961 double average = getAverage2D(binX, binY, h2);
962 bool failure =
false;
964 failure = (((contents-average)/
std::abs(average)) > tolerance_);
969 badChannels_.push_back(
chan);
974 return 1.*((nbinsX * nbinsY) - fail)/(nbinsX * nbinsY);
980 <<
" TH1/TH2F are NULL, exiting\n";
990 int ncx = h->GetXaxis()->GetNbins();
992 int bin_start, bin_end;
996 bin_start = bin - numNeighbors_;
997 bin_end = bin + numNeighbors_;
999 if (bin_start < first) {
1000 add_right = first - bin_start;
1002 bin_end += add_right;
1003 if (bin_end > ncx) bin_end = ncx;
1006 if (bin_end > ncx) {
1007 add_left = bin_end - ncx;
1009 bin_start -= add_left;
1010 if (bin_start < first) bin_start =
first;
1013 sum += h->Integral(bin_start, bin_end);
1014 sum -= h->GetBinContent(bin);
1017 if ( dimension > h->GetNbinsX() ) dimension = h->GetNbinsX();
1019 return sum / (dimension - 1);
1028 int ncx = h2->GetXaxis()->GetNbins();
1029 int ncy = h2->GetYaxis()->GetNbins();
1031 int neighborsX, neighborsY;
1032 neighborsX = numNeighbors_;
1033 neighborsY = numNeighbors_;
1034 int bin_startX, bin_endX;
1037 int bin_startY, bin_endY;
1041 bin_startX = binX - neighborsX;
1042 bin_endX = binX + neighborsX;
1044 if (bin_startX < firstX) {
1045 add_rightX = firstX - bin_startX;
1046 bin_startX = firstX;
1047 bin_endX += add_rightX;
1048 if (bin_endX > ncx) bin_endX = ncx;
1051 if (bin_endX > ncx) {
1052 add_leftX = bin_endX - ncx;
1054 bin_startX -= add_leftX;
1055 if (bin_startX < firstX) bin_startX = firstX;
1058 bin_startY = binY - neighborsY;
1059 bin_endY = binY + neighborsY;
1061 if (bin_startY < firstY) {
1062 add_topY = firstY - bin_startY;
1063 bin_startY = firstY;
1064 bin_endY += add_topY;
1065 if (bin_endY > ncy) bin_endY = ncy;
1068 if (bin_endY > ncy){
1069 add_downY = bin_endY - ncy;
1071 bin_startY -= add_downY;
1072 if (bin_startY < firstY) bin_startY = firstY;
1075 sum += h2->Integral(bin_startX, bin_endX, bin_startY, bin_endY);
1076 sum -= h2->GetBinContent(binX, binY);
1078 int dimensionX = 2 * neighborsX + 1;
1079 int dimensionY = 2 * neighborsY + 1;
1081 if ( dimensionX > h2->GetNbinsX() ) dimensionX = h2->GetNbinsX();
1082 if ( dimensionY > h2->GetNbinsY() ) dimensionY = h2->GetNbinsY();
1084 return sum / (dimensionX * dimensionY - 1);
1095 badChannels_.clear();
1103 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 1104 << me-> getFullname() <<
"\n";
1112 nbinsX = me->
getTH1F()->GetXaxis()->GetNbins();
1113 nbinsY = me->
getTH1F()->GetYaxis()->GetNbins();
1119 nbinsX = me->
getTH1S()->GetXaxis()->GetNbins();
1120 nbinsY = me->
getTH1S()->GetYaxis()->GetNbins();
1126 nbinsX = me->
getTH1D()->GetXaxis()->GetNbins();
1127 nbinsY = me->
getTH1D()->GetYaxis()->GetNbins();
1133 nbinsX = me->
getTH2F()->GetXaxis()->GetNbins();
1134 nbinsY = me->
getTH2F()->GetYaxis()->GetNbins();
1140 nbinsX = me->
getTH2S()->GetXaxis()->GetNbins();
1141 nbinsY = me->
getTH2S()->GetYaxis()->GetNbins();
1147 nbinsX = me->
getTH2D()->GetXaxis()->GetNbins();
1148 nbinsY = me->
getTH2D()->GetYaxis()->GetNbins();
1156 <<
" does not contain TH1F/TH1S/TH1D or TH2F/TH2S/TH2D, exiting\n";
1162 if ( !rangeInitialized_ || !h->GetXaxis() )
1168 unsigned xMax = nbinsX;
1169 unsigned yMax = nbinsY;
1170 unsigned XBlocks = numXblocks_;
1171 unsigned YBlocks = numYblocks_;
1172 unsigned neighborsX = numNeighborsX_;
1173 unsigned neighborsY = numNeighborsY_;
1174 unsigned Xbinnum = 1;
1175 unsigned Ybinnum =1;
1176 unsigned XWidth = 0;
1177 unsigned YWidth = 0;
1179 if (neighborsX==999){
1182 if (neighborsY==999){
1186 if (xMin_ != 0 && xMax_ != 0) {
1189 if ((xMax_ <= nbinsX) && (xMin_ <= xMax_)) {
1190 nbinsX = xMax_ - xMin_ + 1;
1195 if (yMin_ != 0 && yMax_ != 0) {
1196 if ((yMax_ <= nbinsY) && (yMin_ <= yMax_)) {
1197 nbinsY = yMax_ - yMin_ + 1;
1203 if (neighborsX*2 >= nbinsX) {
1204 if (nbinsX%2 == 0) {
1205 neighborsX = nbinsX/2 - 1;
1207 else { neighborsX = (nbinsX - 1)/2; }
1210 if (neighborsY*2 >= nbinsY) {
1211 if (nbinsY%2 == 0) {
1212 neighborsY = nbinsY/2 - 1;
1214 else { neighborsY = (nbinsY - 1)/2; }
1224 Xbinnum = nbinsX/XBlocks;
1225 Ybinnum = nbinsY/YBlocks;
1226 for (
unsigned groupx=0; groupx<XBlocks; ++groupx){
1227 for (
unsigned groupy=0; groupy<YBlocks; ++groupy){
1229 double blocksum = 0;
1230 for (
unsigned binx=0; binx<Xbinnum; ++binx){
1231 for (
unsigned biny=0; biny<Ybinnum; ++biny){
1232 if (groupx*Xbinnum+xMin+binx<=xMax && groupy*Ybinnum+yMin+biny<=yMax){
1233 blocksum +=
abs(h->GetBinContent(groupx*Xbinnum+xMin+binx,groupy*Ybinnum+yMin+biny));
1238 double sum = getNeighborSum(groupx, groupy, XBlocks, YBlocks, neighborsX, neighborsY, h);
1241 if (neighborsX>groupx){
1242 XWidth = neighborsX + groupx + 1;
1243 }
else if (neighborsX>(XBlocks-(groupx+1))){
1244 XWidth = (XBlocks-groupx)+neighborsX;
1246 XWidth = 2*neighborsX+1;
1248 if (neighborsY>groupy){
1249 YWidth = neighborsY + groupy + 1;
1250 }
else if (neighborsY>(YBlocks-(groupy+1))){
1251 YWidth = (YBlocks-groupy)+neighborsY;
1253 YWidth = 2*neighborsY+1;
1256 double average = sum/(XWidth*YWidth - 1);
1257 double sigma = getNeighborSigma(average, groupx, groupy, XBlocks, YBlocks, neighborsX, neighborsY, h);
1258 sigma -= (average-blocksum) * (average-blocksum);
1259 double sigma_2 =
sqrt(sigma)/
sqrt(XWidth*YWidth - 2);
1260 double sigma_real = sigma_2/(XWidth*YWidth - 1);
1262 double avg_uncrt = 3*sigma_real;
1264 double probNoisy = ROOT::Math::poisson_cdf_c(blocksum - 1, average + avg_uncrt);
1265 double probDead = ROOT::Math::poisson_cdf(blocksum, average - avg_uncrt);
1266 double thresholdNoisy = ROOT::Math::normal_cdf_c(toleranceNoisy_);
1267 double thresholdDead = ROOT::Math::normal_cdf(-1 * toleranceDead_);
1269 int failureNoisy = 0;
1270 int failureDead = 0;
1273 if (noisy_ && dead_) {
1274 if (blocksum > average) {
1275 failureNoisy = probNoisy < thresholdNoisy;
1277 failureDead = probDead < thresholdDead;
1280 if (blocksum > average) {
1281 failureNoisy = probNoisy < thresholdNoisy;
1284 if (blocksum < average) {
1285 failureDead = probDead < thresholdDead;
1287 }
else {
std::cout<<
"No test type selected!\n"; }
1294 if (failureNoisy || failureDead) {
1301 return 1.*((XBlocks*YBlocks)-fail)/(XBlocks*YBlocks);
1306 double ContentSigma::getNeighborSum(
unsigned groupx,
unsigned groupy,
unsigned Xblocks,
unsigned Yblocks,
unsigned neighborsX,
unsigned neighborsY,
const TH1 *
h)
const {
1308 unsigned nbinsX = h->GetXaxis()->GetNbins();
1309 unsigned nbinsY = h->GetYaxis()->GetNbins();
1312 unsigned xMax = nbinsX;
1313 unsigned yMax = nbinsY;
1314 unsigned Xbinnum = 1;
1315 unsigned Ybinnum = 1;
1317 if (xMin_ != 0 && xMax_ != 0) {
1320 if ((xMax_ <= nbinsX) && (xMin_ <= xMax_)) {
1321 nbinsX = xMax_ - xMin_ + 1;
1326 if (yMin_ != 0 && yMax_ != 0) {
1327 if ((yMax_ <= nbinsY) && (yMin_ <= yMax_)) {
1328 nbinsY = yMax_ - yMin_ + 1;
1341 Xbinnum = nbinsX/Xblocks;
1342 Ybinnum = nbinsY/Yblocks;
1344 unsigned xLow,xHi,yLow,yHi;
1345 if (groupx>neighborsX){
1346 xLow=(groupx-neighborsX)*Xbinnum+xMin;
1353 xHi=(groupx+1+neighborsX)*Xbinnum+xMin;
1357 if (groupy>neighborsY){
1358 yLow=(groupy-neighborsY)*Ybinnum+yMin;
1365 yHi=(groupy+1+neighborsY)*Ybinnum+yMin;
1370 for (
unsigned xbin=xLow; xbin<=xHi; ++xbin){
1371 for (
unsigned ybin=yLow; ybin<=yHi; ++ybin){
1372 sum += h->GetBinContent(xbin,ybin);
1381 unsigned nbinsX = h->GetXaxis()->GetNbins();
1382 unsigned nbinsY = h->GetYaxis()->GetNbins();
1385 unsigned xMax = nbinsX;
1386 unsigned yMax = nbinsY;
1387 unsigned Xbinnum = 1;
1388 unsigned Ybinnum = 1;
1391 if (xMin_ != 0 && xMax_ != 0) {
1392 if ((xMax_ <= nbinsX) && (xMin_ <= xMax_)) {
1393 nbinsX = xMax_ - xMin_ + 1;
1398 if (yMin_ != 0 && yMax_ != 0) {
1399 if ((yMax_ <= nbinsY) && (yMin_ <= yMax_)) {
1400 nbinsY = yMax_ - yMin_ + 1;
1412 Xbinnum = nbinsX/Xblocks;
1413 Ybinnum = nbinsY/Yblocks;
1415 unsigned xLow,xHi,yLow,yHi;
1416 for (
unsigned x_block_count=0; x_block_count<=2*neighborsX; ++x_block_count){
1417 for (
unsigned y_block_count=0; y_block_count<=2*neighborsY; ++y_block_count){
1419 if (groupx + x_block_count > neighborsX){
1420 xLow=(groupx + x_block_count - neighborsX) * Xbinnum + xMin;
1427 xHi = xLow + Xbinnum;
1431 if (groupy + y_block_count > neighborsY){
1432 yLow=(groupy + y_block_count - neighborsY) * Ybinnum + yMin;
1439 yHi = yLow + Ybinnum;
1444 for (
unsigned x_block_bin=xLow; x_block_bin<=xHi; ++x_block_bin){
1445 for (
unsigned y_block_bin=yLow; y_block_bin<=yHi; ++y_block_bin){
1446 block_sum += h->GetBinContent(x_block_bin,y_block_bin);
1449 sigma += (average-block_sum)*(average-block_sum);
1462 badChannels_.clear();
1470 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 1471 << me-> getFullname() <<
"\n";
1481 ncx = me->
getTH2F()->GetXaxis()->GetNbins();
1482 ncy = me->
getTH2F()->GetYaxis()->GetNbins();
1488 ncx = me->
getTH2S()->GetXaxis()->GetNbins();
1489 ncy = me->
getTH2S()->GetYaxis()->GetNbins();
1495 ncx = me->
getTH2D()->GetXaxis()->GetNbins();
1496 ncy = me->
getTH2D()->GetYaxis()->GetNbins();
1516 std::cout <<
"QTest:ContentsWithinExpected" 1517 <<
" ME does not contain TH2F/TH2S/TH2D/TPROFILE/TPROFILE2D, exiting\n";
1525 if (checkMeanTolerance_)
1528 for (
int cx = 1; cx <= ncx; ++cx)
1530 for (
int cy = 1; cy <= ncy; ++cy)
1534 sum += h->GetBinContent(h->GetBin(cx, cy));
1539 sum += h->GetBinContent(h->GetBin(cx, cy));
1544 sum += h->GetBinContent(h->GetBin(cx, cy));
1549 if (me->
getTProfile()->GetBinEntries(h->GetBin(cx)) >= minEntries_/(ncx))
1551 sum += h->GetBinContent(h->GetBin(cx));
1557 if (me->
getTProfile2D()->GetBinEntries(h->GetBin(cx, cy)) >= minEntries_/(ncx*ncy))
1559 sum += h->GetBinContent(h->GetBin(cx, cy));
1573 for (
int cx = 1; cx <= ncx; ++cx)
1575 for (
int cy = 1; cy <= ncy; ++cy)
1577 bool failMean =
false;
1578 bool failRMS =
false;
1579 bool failMeanTolerance =
false;
1582 me->
getTProfile()->GetBinEntries(h->GetBin(cx)) < minEntries_/(ncx))
1586 me->
getTProfile2D()->GetBinEntries(h->GetBin(cx, cy)) < minEntries_/(ncx*ncy))
1591 double mean = h->GetBinContent(h->GetBin(cx, cy));
1592 failMean = (mean < minMean_ || mean > maxMean_);
1597 double rms = h->GetBinError(h->GetBin(cx, cy));
1598 failRMS = (rms < minRMS_ || rms > maxRMS_);
1601 if (checkMeanTolerance_)
1603 double mean = h->GetBinContent(h->GetBin(cx, cy));
1604 failMeanTolerance = (
std::abs(mean - average) > toleranceMean_*
std::abs(average));
1607 if (failMean || failRMS || failMeanTolerance)
1613 h->GetBinContent(h->GetBin(cx, cy)),
1614 h->GetBinError(h->GetBin(cx, cy)));
1615 badChannels_.push_back(chan);
1620 h->GetBinContent(h->GetBin(cx, cy)),
1621 h->GetBinError(h->GetBin(cx, cy)));
1622 badChannels_.push_back(chan);
1627 h->GetBinContent(h->GetBin(cx, cy)),
1628 h->GetBinError(h->GetBin(cx, cy)));
1629 badChannels_.push_back(chan);
1635 h->GetBinError(h->GetBin(cx)));
1636 badChannels_.push_back(chan);
1641 h->GetBinContent(h->GetBin(cx, cy)),
1642 h->GetBinError(h->GetBin(cx, cy)));
1643 badChannels_.push_back(chan);
1649 return 1.*(ncx*ncy -
fail)/(ncx*ncy);
1656 ncx = me->
getTH2F()->GetXaxis()->GetNbins();
1657 ncy = me->
getTH2F()->GetYaxis()->GetNbins();
1662 ncx = me->
getTH2S()->GetXaxis()->GetNbins();
1663 ncy = me->
getTH2S()->GetYaxis()->GetNbins();
1668 ncx = me->
getTH2D()->GetXaxis()->GetNbins();
1669 ncy = me->
getTH2D()->GetYaxis()->GetNbins();
1675 std::cout <<
"QTest:ContentsWithinExpected AS" 1676 <<
" ME does not contain TH2F/TH2S/TH2D, exiting\n";
1682 for (
int cx = 1; cx <= ncx; ++cx)
1684 for (
int cy = 1; cy <= ncy; ++cy)
1686 bool failure =
false;
1687 double Content = h->GetBinContent(h->GetBin(cx, cy));
1689 failure = (Content < minMean_ || Content > maxMean_);
1694 return 1.*(ncx*ncy-
fail)/(ncx*ncy);
1703 std::cout <<
"QTest:ContentsWitinExpected" 1704 <<
" Illogical range: (" << xmin <<
", " << xmax <<
"\n";
1715 std::cout <<
"QTest:ContentsWitinExpected" 1716 <<
" Illogical range: (" << xmin <<
", " << xmax <<
"\n";
1744 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 1745 << me-> getFullname() <<
"\n";
1747 if (minEntries_ != 0 && me->
getEntries() < minEntries_)
return -1;
1765 <<
" does not contain TH1F/TH1S/TH1D, exiting\n";
1771 double mean = h->GetMean();
1772 if (mean <= xmax_ && mean >= xmin_)
1781 double chi = (h->GetMean() - expMean_)/sigma_;
1782 return TMath::Prob(chi*chi, 1);
1788 <<
" Error, sigma_ is zero, exiting\n";
1794 if (h->GetRMS() != 0.)
1796 double chi = (h->GetMean() - expMean_)/h->GetRMS();
1797 return TMath::Prob(chi*chi, 1);
1803 <<
" Error, RMS is zero, exiting\n";
1810 <<
" Error, neither Range, nor Sigma, nor RMS, exiting\n";
1817 useSigma_ = useRMS_ =
false;
1822 <<
" Illogical range: (" << xmin_ <<
", " << xmax_ <<
"\n";
1827 useRMS_ = useRange_ =
false;
1828 sigma_ = expectedSigma;
1832 <<
" Expected sigma = " << sigma_ <<
"\n";
1838 useSigma_ = useRange_ =
false;
1854 badChannels_.clear();
1863 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 1864 << me-> getFullname() <<
"\n";
1865 std::cout <<
"\tMin = " << _min <<
"; Max = " << _max <<
"\n";
1866 std::cout <<
"\tMinMedian = " << _minMed <<
"; MaxMedian = " << _maxMed <<
"\n";
1867 std::cout <<
"\tUseEmptyBins = " << (_emptyBins?
"Yes":
"No" )<<
"\n";
1877 std::cout <<
"QTest:ContentsWithinExpected" 1878 <<
" ME does not contain TPROFILE2D, exiting\n";
1882 nBinsX = h->GetNbinsX();
1883 nBinsY = h->GetNbinsY();
1888 for (
int binX = 1; binX <= nBinsX; binX++ ){
1891 for (
int binY = 1; binY <= nBinsY; binY++){
1892 int bin = h->GetBin(binX, binY);
1893 auto content = (double)h->GetBinContent(bin);
1894 if (
content == 0 && !_emptyBins)
1899 if (binValues.empty())
1901 nbins+=binValues.size();
1904 if(!binValues.empty()){
1905 int medPos = (
int)binValues.size()/2;
1906 nth_element(binValues.begin(),binValues.begin()+medPos,binValues.end());
1907 median = *(binValues.begin()+medPos);
1913 std::cout <<
"QTest: Median is 0; the fixed cuts: [" << _minMed <<
"; " << _maxMed <<
"] are used\n";
1915 for(
int binY = 1; binY <= nBinsY; binY++){
1916 int bin = h->GetBin(binX, binY);
1917 auto content = (double)h->GetBinContent(bin);
1923 badChannels_.push_back(
chan);
1931 if (median*entries < _statCut )
1935 if(median > _maxMed || median < _minMed){
1936 for(
int binY = 1; binY <= nBinsY; binY++){
1937 int bin = h->GetBin(binX, binY);
1938 auto content = (double)h->GetBinContent(bin);
1943 badChannels_.push_back(
chan);
1950 float minCut = median*_min;
1951 float maxCut = median*_max;
1952 for(
int binY = 1; binY <= nBinsY; binY++){
1953 int bin = h->GetBin(binX, binY);
1954 auto content = (double)h->GetBinContent(bin);
1960 badChannels_.push_back(
chan);
1968 std::cout <<
"QTest:CompareToMedian: Histogram is empty" << std::endl;
1991 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 1992 << me-> getFullname() <<
"\n";
1993 std::cout <<
"\tMin = " << _min <<
"; Max = " << _max <<
"\n";
2006 std::cout <<
"QTest:ContentsWithinExpected" 2007 <<
" ME does not contain TH1F or TH2F, exiting\n";
2017 lastBinX = h1->FindLastBinAbove(_average,1);
2018 lastBinVal = h1->GetBinContent(lastBinX);
2019 if (h1->GetEntries() == 0 || lastBinVal < 0)
return 1;
2021 else if (h2 !=
nullptr)
2024 lastBinX = h2->FindLastBinAbove(_average,1);
2025 lastBinY = h2->FindLastBinAbove(_average,2);
2026 if ( h2->GetEntries() == 0 || lastBinX < 0 || lastBinY < 0 )
return 1;
2027 lastBinVal = h2->GetBinContent(h2->GetBin(lastBinX,lastBinY));
2029 if (verbose_ > 0)
std::cout <<
"QTest:"<< getAlgoName() <<
" Histogram does not exist" << std::endl;
2032 if (verbose_ > 0)
std::cout <<
"Min and Max values " << _min <<
" " << _max <<
" Av value " << _average <<
" lastBinX " << lastBinX<<
" lastBinY " << lastBinY <<
" lastBinVal " << lastBinVal << std::endl;
2033 if (lastBinVal > _min && lastBinVal <= _max)
2043 badChannels_.clear();
2052 std::cout <<
"QTest:" << getAlgoName() <<
"::runTest called on " 2053 << me-> getFullname() <<
"\n";
2070 if (verbose_>0)
std::cout <<
"QTest:CheckVariance" 2072 <<
" does not contain TH1F/TH1D/TPROFILE, exiting\n";
2076 int ncx = h->GetXaxis()->GetNbins();
2085 if (sum==0)
return -1;
2086 double avg = sum/ncx;
2091 sum2 += (contents - avg)*(contents - avg);
2094 double Variance = TMath::Sqrt(sum2/ncx);
TProfile * getTProfile() const
double getAverage(int bin, const TH1 *h) const
double getAverage2D(int binX, int binY, const TH2 *h) const
common ppss p3p6s2 common epss epspn46 common const1 w2
TProfile2D * getTProfile2D() const
float runTest(const MonitorElement *me) override
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
TObject * getRootObject() const
void setRMSRange(double xmin, double xmax)
set expected value for mean
void useSigma(double expectedSigma)
TProfile2D * getRefTProfile2D() const
float runTest(const MonitorElement *me) override
float runTest(const MonitorElement *me) override
float runTest(const MonitorElement *me) override
TObject * getRefRootObject() const
TH2S * getRefTH2S() const
float runTest(const MonitorElement *me) override
void init()
initialize values
TH1F * getRefTH1F() const
TH1S * getRefTH1S() const
Abs< T >::type abs(const T &t)
TH3F * getRefTH3F() const
static const int DID_NOT_RUN
static const float ERROR_PROB_THRESHOLD
float runTest(const MonitorElement *me) override
float runTest(const MonitorElement *me) override
bin
set the eta bin as selection string.
const std::string getFullname() const
get full name of ME including Pathname
void useRange(double xmin, double xmax)
double getEntries() const
get # of entries
double getNeighborSigma(double average, unsigned groupx, unsigned groupy, unsigned Xblocks, unsigned Yblocks, unsigned neighborsX, unsigned neighborsY, const TH1 *h) const
float runTest(const MonitorElement *me) override
float runTest(const MonitorElement *me) override
virtual float runTest(const MonitorElement *me)
float runTest(const MonitorElement *me) override
TH2D * getRefTH2D() const
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
TH2F * getRefTH2F() const
void setMeanRange(double xmin, double xmax)
set expected value for mean
double getNeighborSum(unsigned groupx, unsigned groupy, unsigned Xblocks, unsigned Yblocks, unsigned neighborsX, unsigned neighborsY, const TH1 *h) const
for each bin get sum of the surrounding neighbors
float runTest(const MonitorElement *me) override
TH1D * getRefTH1D() const
float runTest(const MonitorElement *me) override
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
void reset(double vett[256])
TProfile * getRefTProfile() const
Kind kind() const
Get the type of the monitor element.
static const float WARNING_PROB_THRESHOLD
default "probability" values for setting warnings & errors when running tests
float runTest(const MonitorElement *me) override
void raiseDQMError(const char *context, const char *fmt,...)