8 #ifndef DQM_ALGORITHMS_TOOLS_ALGORITHMHELPER_CXX
9 #define DQM_ALGORITHMS_TOOLS_ALGORITHMHELPER_CXX
17 #include <Math/ProbFuncMathCore.h>
18 #include <Math/DistFunc.h>
24 #include <dqm_core/Result.h>
26 #include <dqm_core/AlgorithmManager.h>
27 #include <dqm_core/LibraryManager.h>
29 std::map<std::string, double >
32 std::map<std::string,double> fitparams;
34 const int nPar =(
int) func->GetNpar();
36 for (
int i = 0;
i< nPar; ++
i ) {
37 std::string
name = func->GetParName(
i );
38 fitparams[
name] = func->GetParameter(
i );
43 std::map<std::string, double >
46 std::map<std::string,double> fitParamErrors;
48 const int nPar =(
int) func->GetNpar();
50 for (
int i = 0;
i< nPar; ++
i ) {
51 std::string
name = func->GetParName(
i );
52 fitParamErrors[
name] = func->GetParError(
i );
54 return fitParamErrors;
61 const std::map<std::string,double> & gthreshold,
62 const std::map<std::string,double> & rthreshold )
70 if (gthreshold.size() != rthreshold.size()) {
71 throw dqm_core::BadConfig( ERS_HERE,
"MakeComparisons",
"Need same number of Red and Green Threshold" );
74 if (gthreshold.size() == 0 ) {
75 throw dqm_core::BadConfig( ERS_HERE,
"MakeComparisons",
"No Threshold specified" );
78 std::map<std::string,double>::const_iterator g_iter;
80 for (g_iter=gthreshold.begin();g_iter!=gthreshold.end();++g_iter){
82 std::string
name=(std::string) g_iter->first;
83 std::string findname=
name;
84 double gtvalue=g_iter->second;
88 if (
name ==
"AbsXMean" )
90 if (
name ==
"AbsYMean" )
94 std::map<std::string,double>::const_iterator ait = algparams.find(findname);
95 std::map<std::string,double>::const_iterator rit = rthreshold.find(
name);
99 if ( ait != algparams.end() ) {
103 throw dqm_core::BadConfig( ERS_HERE,
"None",
name );
106 if ( rit != rthreshold.end() ) {
110 throw dqm_core::BadConfig( ERS_HERE,
"None",
name );
114 if (
name ==
"AbsMean" ||
name ==
"AbsXMean" ||
name==
"AbsYMean") {
115 avalue = fabs(avalue);
116 if (gtvalue < 0 || rtvalue <0 ) {
117 throw dqm_core::BadConfig( ERS_HERE,
"None",
name );
121 ERS_DEBUG(1,
name<<
" :red value "<<rtvalue<<
" :green value "<<gtvalue<<
" :param value "<<avalue);
123 if (gtvalue < rtvalue) {
125 if (avalue <= gtvalue ){
127 }
else if(avalue < rtvalue){
133 else if (gtvalue > rtvalue) {
134 if (avalue >= gtvalue ){
136 }
else if(avalue > rtvalue){
143 ERS_DEBUG(0,
"red threshold (" << rtvalue <<
") same as green threshold "<< gtvalue <<
") for parameter " <<
name <<
": can't evaluate result");
144 throw dqm_core::BadConfig( ERS_HERE,
"None",
name );
148 ERS_DEBUG(1,
"red: "<<
red<<
" yellow: "<<
yellow<<
" green: "<<
green);
153 result->tags_ = algparams;
159 result->status_= dqm_core::Result::Yellow;
169 const std::map<std::string,double> & paramErrors,
170 const std::map<std::string,double> & gthreshold,
171 const std::map<std::string,double> & rthreshold,
double minSig )
180 if (gthreshold.size() != rthreshold.size()) {
181 throw dqm_core::BadConfig( ERS_HERE,
"MakeComparisons",
"Need same number of Red and Green Threshold" );
184 if (gthreshold.size() == 0 ) {
185 throw dqm_core::BadConfig( ERS_HERE,
"MakeComparisons",
"No Threshold specified" );
188 std::map<std::string,double>::const_iterator g_iter;
190 for (g_iter=gthreshold.begin();g_iter!=gthreshold.end();++g_iter){
192 std::string
name=(std::string) g_iter->first;
193 std::string findname=
name;
194 double gtvalue=g_iter->second;
198 if (
name ==
"AbsXMean" )
200 if (
name ==
"AbsYMean" )
204 std::map<std::string,double>::const_iterator ait = algparams.find(findname);
205 std::map<std::string,double>::const_iterator errItr = paramErrors.find(findname);
206 std::map<std::string,double>::const_iterator rit = rthreshold.find(
name);
208 double rtvalue = -999;
209 double avalue = -999;
212 if ( ait != algparams.end() ) {
216 throw dqm_core::BadConfig( ERS_HERE,
"None",
name );
219 if ( errItr != paramErrors.end() ) {
220 error = errItr->second;
223 throw dqm_core::BadConfig( ERS_HERE,
"Problem retrieving fit param error",
name );
227 if ( rit != rthreshold.end() ) {
231 throw dqm_core::BadConfig( ERS_HERE,
"None",
name );
235 if (
name ==
"AbsMean" ||
name ==
"AbsXMean" ||
name==
"AbsYMean") {
236 avalue = fabs(avalue);
237 if (gtvalue < 0 || rtvalue <0 ) {
238 throw dqm_core::BadConfig( ERS_HERE,
"None",
name );
242 ERS_DEBUG(1,
name<<
" :red value "<<rtvalue<<
" :green value "<<gtvalue<<
" :param value "<<avalue <<
" :param error "<<
error);
244 double significanceBound =
error * minSig;
247 if (gtvalue < rtvalue) {
249 if ( avalue <= (gtvalue - significanceBound) ){
252 else if( avalue > (rtvalue + significanceBound) ){
255 else if( avalue > (gtvalue + significanceBound) ) {
262 else if (gtvalue > rtvalue) {
263 if ( avalue >= (gtvalue + significanceBound) ){
266 else if( avalue < (rtvalue - significanceBound) ){
269 else if( avalue < (gtvalue - significanceBound) ){
277 ERS_DEBUG(0,
"red threshold same as green threshold: can't evaluate result");
278 throw dqm_core::BadConfig( ERS_HERE,
"None",
name );
287 result->tags_ = algparams;
295 result->status_= dqm_core::Result::Yellow;
311 std::map<std::string, double > greenthresh=
config.getGreenThresholds();
312 std::map<std::string,double>::const_iterator ait = greenthresh.find(
"Chi2_per_NDF");
313 if ( ait != greenthresh.end() ) {
314 params[
"Chi2_per_NDF"]=func->GetChisquare()/ func->GetNDF();
330 for ( std::map<std::string,double>::const_iterator peItr = paramErrors.begin(); peItr != paramErrors.end(); ++peItr ) {
331 std::string errorName = peItr->first;
332 errorName +=
" Error";
333 result->tags_[errorName] = peItr->second;
341 std::map<std::string, double >::const_iterator
it =
params.find(paramName);
343 throw dqm_core::BadConfig(ERS_HERE,
"None", paramName);
351 std::map<std::string, double >::const_iterator
it =
params.find(paramName);
362 std::map<std::string, std::string >::const_iterator
it =
params.find(paramName);
364 throw dqm_core::BadConfig(ERS_HERE,
"None", paramName);
372 std::map<std::string, std::string >::const_iterator
it =
params.find(paramName);
382 std::vector<int>
range;
383 const TAxis *xAxis =
h->GetXaxis();
384 const TAxis *yAxis =
h->GetYaxis();
386 if (
h->GetDimension() > 2) {
387 throw dqm_core::BadConfig(ERS_HERE,
h->GetName(),
"histogram has more than 2 dimensions");
390 const double notFound = -99999;
401 const int xlow = (
xmin == notFound) ? 1 : xAxis->FindBin(
xmin);
402 const int xhigh = (
xmax == notFound) ? xAxis->GetNbins() : (xAxis->GetBinLowEdge(xAxis->FindBin(
xmax))==
xmax) ? (xAxis->FindBin(
xmax)-1) : xAxis->FindBin(
xmax);
403 const int ylow = (
ymin == notFound) ? 1 : yAxis->FindBin(
ymin);
404 const int yhigh = (
ymax == notFound) ? yAxis->GetNbins() : (yAxis->GetBinLowEdge(yAxis->FindBin(
ymax))==
ymax) ? (yAxis->FindBin(
ymax)-1) : yAxis->FindBin(
ymax);
409 sprintf(temp,
"Bin Range Error: xmin = %.3g, xmax = %.3g",
xmin,
xmax);
410 throw dqm_core::BadConfig( ERS_HERE,
h->GetName(), temp );
414 sprintf(temp,
"Bin Range Error: xmin = %.3g, xmax = %.3g",
xmin,
xmax);
415 throw dqm_core::BadConfig( ERS_HERE,
h->GetName(), temp );
418 range.push_back(xlow);
419 range.push_back(xhigh);
420 range.push_back(ylow);
421 range.push_back(yhigh);
429 double xbin =
histogram->GetXaxis()->GetBinCenter(
x);
430 std::string xbinlabel = (std::string)(
histogram->GetXaxis()->GetBinLabel(
x));
432 double ybin =
histogram->GetYaxis()->GetBinCenter(
y);
433 std::string ybinlabel = (std::string)(
histogram->GetYaxis()->GetBinLabel(
y));
434 std::string badbin = Form(
"x-axis %s(%f) y-axis %s(%f))",xbinlabel.c_str(),xbin,ybinlabel.c_str(),ybin);
435 result->tags_[badbin.c_str()] = inputcont;
436 ERS_DEBUG(1,
"x bin "<<xbin<<
" y bin "<<ybin <<
" value "<<inputcont);
438 std::string badbin = Form(
"%s(%f)",xbinlabel.c_str(),xbin);
439 result->tags_[badbin.c_str()] = inputcont;
440 ERS_DEBUG(1,
"x bin "<<xbin<<
" value "<<inputcont);
451 int hNdimension = hNumerator->GetDimension();
452 int hDdimension = hDenominator->GetDimension();
454 if( hDdimension == hNdimension ) {
455 if( (hNumerator->GetNbinsX() != hDenominator->GetNbinsX()) || (hNumerator->GetNbinsY() != hDenominator->GetNbinsY()) ||
456 (hNumerator->GetNbinsZ() != hNumerator->GetNbinsZ()) ) {
457 throw dqm_core::BadConfig( ERS_HERE,
"DivideByHistogram",
"number of bins do not match");
462 if( hNdimension == 1) {
465 else if ( hNdimension == 2 ) {
468 else if ( hNdimension == 3 ) {
472 throw dqm_core::BadConfig( ERS_HERE,
"DivideByHistogram",
"Histograms with dimension greater than 3 are not supported");
476 hResult->Divide(hNumerator,hDenominator);
478 else if ( hNdimension > hDdimension ) {
482 const TAxis* xax = hNumerator->GetXaxis();
483 int nbinsx = xax->GetNbins();
484 const TAxis* yax = hNumerator->GetYaxis();
485 int nbinsy = yax->GetNbins();
486 const TAxis* zax = hNumerator->GetZaxis();
487 int nbinsz = zax->GetNbins();
489 if( nbinsx != hDenominator->GetNbinsX() ) {
490 throw dqm_core::BadConfig( ERS_HERE,
"DivideByHistogram",
"number of bins in x-axis do not match");
492 if( (hDdimension == 2) && (nbinsy != hDenominator->GetNbinsY()) ) {
493 throw dqm_core::BadConfig( ERS_HERE,
"DivideByHistogram",
"number of bins in y-axis do not match");
496 double numeratorCont = 0;
497 double denominatorCont = 0;
498 double numeratorError = 0;
499 double denominatorError = 0;
501 if(hNdimension == 2) {
504 else if(hNdimension == 3) {
508 throw dqm_core::BadConfig( ERS_HERE,
"DivideByHistogram",
"Histograms with dimension greater than 3 are not supported");
511 for (
int i=1;
i <= nbinsx;
i++) {
512 if( hDdimension == 1){
513 denominatorCont = hDenominator->GetBinContent(
i);
514 denominatorError = hDenominator->GetBinError(
i);
516 for (
int j=1; j <= nbinsy; j++) {
517 if( hDdimension == 2){
518 denominatorCont = hDenominator->GetBinContent(
i,j);
519 denominatorError = hDenominator->GetBinError(
i,j);
521 if( hNdimension == 2){
522 numeratorCont = hNumerator->GetBinContent(
i,j);
523 numeratorError = hNumerator->GetBinError(
i,j);
524 if(denominatorCont != 0){
525 hResult->SetBinContent(
i,j,numeratorCont/denominatorCont);
526 hResult->SetBinError(
i,j,sqrt( (
pow(numeratorError,2)/
pow(denominatorCont,2) )
527 + (
pow(denominatorError,2) *
pow(numeratorCont,2) /
pow(denominatorCont,4) ) ) );
531 for (
int k=1;
k <= nbinsz;
k++) {
532 numeratorCont = hNumerator->GetBinContent(
i,j,
k);
533 numeratorError = hNumerator->GetBinError(
i,j,
k);
534 if(denominatorCont != 0){
535 hResult->SetBinContent(
i,j,
k,numeratorCont/denominatorCont);
536 hResult->SetBinError(
i,j,
k,sqrt( (
pow(numeratorError,2)/
pow(denominatorCont,2) )
537 + (
pow(denominatorError,2) *
pow(numeratorCont,2) /
pow(denominatorCont,4) ) ) );
548 const TAxis* xax = hDenominator->GetXaxis();
549 int nbinsx = xax->GetNbins();
550 const TAxis* yax = hDenominator->GetYaxis();
551 int nbinsy = yax->GetNbins();
552 const TAxis* zax = hDenominator->GetZaxis();
553 int nbinsz = zax->GetNbins();
555 if( nbinsx != hNumerator->GetNbinsX() ) {
556 throw dqm_core::BadConfig( ERS_HERE,
"number of bins in x-axis",
"do not match");
558 if( (hNdimension == 2) && (nbinsy != hNumerator->GetNbinsY()) ) {
559 throw dqm_core::BadConfig( ERS_HERE,
"number of bins in y-axis",
"do not match");
562 double denominatorCont = 0;
563 double numeratorCont = 0;
564 double denominatorError = 0;
565 double numeratorError = 0;
567 if(hDdimension == 2) {
570 else if(hDdimension == 3) {
574 throw dqm_core::BadConfig( ERS_HERE,
"DivideByHistogram",
"Histograms with dimension greater than 3 are not supported");
578 for (
int i=1;
i <= nbinsx;
i++) {
579 if( hNdimension == 1){
580 numeratorCont = hNumerator->GetBinContent(
i);
581 numeratorError = hNumerator->GetBinError(
i);
583 for (
int j=1; j <= nbinsy; j++) {
584 if( hNdimension == 2){
585 numeratorCont = hNumerator->GetBinContent(
i,j);
586 numeratorError = hNumerator->GetBinError(
i,j);
588 if( hDdimension == 2){
589 denominatorCont = hDenominator->GetBinContent(
i,j);
590 denominatorError = hDenominator->GetBinError(
i,j);
591 if(denominatorCont != 0){
592 hResult->SetBinContent(
i,j,numeratorCont/denominatorCont);
593 hResult->SetBinError(
i,j,sqrt( (
pow(numeratorError,2)/
pow(denominatorCont,2) )
594 + (
pow(denominatorError,2) *
pow(numeratorCont,2) /
pow(denominatorCont,4) ) ) );
598 for (
int k=1;
k <= nbinsz;
k++) {
599 denominatorCont = hDenominator->GetBinContent(
i,j,
k);
600 denominatorError = hDenominator->GetBinError(
i,j,
k);
601 if(denominatorCont != 0){
602 hResult->SetBinContent(
i,j,
k,numeratorCont/denominatorCont);
603 hResult->SetBinError(
i,j,sqrt( (
pow(numeratorError,2)/
pow(denominatorCont,2) )
604 + (
pow(denominatorError,2) *
pow(numeratorCont,2) /
pow(denominatorCont,4) ) ) );
620 std::string algNameTag =
"AuxAlgName--";
623 if (
config.getParameters().empty()){
624 throw dqm_core::BadConfig( ERS_HERE,
"ExtractAlgorithmName",
"called with an empty config file");
627 std::map<std::string,double > confParams =
config.getParameters();
628 for ( std::map<std::string,double >::const_iterator itr = confParams.begin();itr != confParams.end();++itr ) {
630 if ( (stringPos = itr->first.find(algNameTag)) != std::string::npos ){
631 stringPos += algNameTag.length();
632 algName = itr->first.substr(stringPos);
645 if (
name.compare(
"None") == 0 ) {
646 throw dqm_core::BadConfig( ERS_HERE,
"no auxiliary algorithm specified",
name);
652 catch( dqm_core::Exception& ex ) {
653 throw dqm_core::BadConfig( ERS_HERE,
"unable to get algorithm of this name",
name);
663 if (
config.getParameters().empty()){
667 std::map<std::string,double > confParams =
config.getParameters();
668 for ( std::map<std::string,double >::const_iterator itr = confParams.begin();itr != confParams.end();++itr ) {
669 if ( itr->first.find(
"MultiplyHistogramByValue") != std::string::npos ){
673 if ( itr->first.find(
"DivideHistogramByValue") != std::string::npos ){
678 std::string configTag =
"SetHistogramTitle";
679 if ( (stringPos = itr->first.find(configTag)) != std::string::npos ){
680 stringPos += configTag.length();
681 histogram->SetTitle( (itr->first.substr(stringPos)).c_str() );
694 throw dqm_core::BadConfig( ERS_HERE,
name,
"can't make a 2D histogram from a 1D histogram");
697 if(
histogram->GetXaxis()->IsVariableBinSize()) {
708 resultXY->SetXTitle(
histogram->GetXaxis()->GetTitle());
709 resultXY->SetYTitle(
histogram->GetYaxis()->GetTitle());
710 return (TH1*) resultXY;
715 throw dqm_core::BadConfig( ERS_HERE,
name,
"can't extract a Y-Axis from a 1D histogram");
718 if(
histogram->GetYaxis()->IsVariableBinSize()) {
726 resultY->SetXTitle(
histogram->GetYaxis()->GetTitle());
727 return (TH1*) resultY;
732 throw dqm_core::BadConfig( ERS_HERE,
name,
"can't make a 3D histrogram without at least a 3D histogram");
735 if(
histogram->GetXaxis()->IsVariableBinSize()) {
736 resultXYZ =
new TH3F(
name.c_str(),
title.c_str(),
742 resultXYZ =
new TH3F(
name.c_str(),
title.c_str(),
747 resultXYZ->SetXTitle(
histogram->GetXaxis()->GetTitle());
748 resultXYZ->SetYTitle(
histogram->GetYaxis()->GetTitle());
749 resultXYZ->SetZTitle(
histogram->GetZaxis()->GetTitle());
755 throw dqm_core::BadConfig( ERS_HERE,
name,
"can't extract a Z-Axis from a dimension < 3 histogram");
758 if(
histogram->GetXaxis()->IsVariableBinSize()) {
768 resultXZ->SetXTitle(
histogram->GetXaxis()->GetTitle());
769 resultXZ->SetYTitle(
histogram->GetZaxis()->GetTitle());
770 return (TH1*) resultXZ;
775 throw dqm_core::BadConfig( ERS_HERE,
name,
"can't extract a Z-Axis from a dimension < 3 histogram");
778 if(
histogram->GetYaxis()->IsVariableBinSize()) {
788 resultYZ->SetXTitle(
histogram->GetYaxis()->GetTitle());
789 resultYZ->SetYTitle(
histogram->GetZaxis()->GetTitle());
790 return (TH1*) resultYZ;
795 throw dqm_core::BadConfig( ERS_HERE,
name,
"can't extract a Z-Axis from a dimension < 3 histogram");
798 if(
histogram->GetZaxis()->IsVariableBinSize()) {
806 resultZ->SetXTitle(
histogram->GetZaxis()->GetTitle());
807 return (TH1*) resultZ;
813 if(
histogram->GetXaxis()->IsVariableBinSize()) {
821 resultX->SetXTitle(
histogram->GetXaxis()->GetTitle());
822 return (TH1*) resultX ;
829 const TObject*& firstReference ,
830 TObject*& secondReference )
832 if ( ro.InheritsFrom(
"TH1") )
835 firstReference = &ro;
839 else if ( ro.InheritsFrom(
"TCollection") )
842 const TCollection* coll =
static_cast<const TCollection*
>(&ro);
843 TIterator*
it = coll->MakeIterator();
847 throw dqm_core::BadRefHist(ERS_HERE,
"handleReference",
" Could not retreive reference");
849 firstReference =
static_cast<TH1 *
>(
content);
850 Int_t csize = coll->GetEntries();
857 else if ( coll->GetEntries() == 2 )
860 secondReference =
it->Next();
866 secondReference =
static_cast<TObject*
>( (coll->IsA())->New() );
867 if ( secondReference == 0 || secondReference->InheritsFrom(
"TCollection") == kFALSE )
869 throw dqm_core::BadRefHist(ERS_HERE,
"handleReference",
" Could not retreive reference");
873 static_cast<TCollection*
>(secondReference)->Add(
content);
881 throw dqm_core::BadRefHist(ERS_HERE,
"handleReference",
" Could not retreive reference");
889 int nIterations,
double exponent,
double threshold,
double SBCF,
double nStop) {
896 if (nStop < 0) nStop = 0;
897 if (SBCF < 0) SBCF = 0;
899 std::vector<binContainer>::const_iterator cbegin =
input.begin();
900 std::vector<binContainer>::const_iterator cend =
input.end();
911 for (
int j = 0; j < nIterations ; j++ ) {
926 int nOut =
size - newNin;
928 if (newNin < (2 + nStop + SBCF * nOut) ) {
931 newMean = newNin ? (
sum / newNin) : 0;
933 if ( (newNin == nIn) && (newMean ==
mean) ) {
940 for ( std::vector<binContainer>::const_iterator
it = cbegin;
it != cend; ++
it ) {
942 scaleSum +=
pow( fabs(
it->value - newMean) , exponent );
945 newScale =
pow( scaleSum / (nIn - 1 - (SBCF * nOut) ), 1/exponent);
957 if( minDiff < 0 ) minDiff = 0;
958 if( minNin < 2) minNin = 3;
972 double sumError2 = 0;
975 sumError2 +=
pow(
it->error,2);
979 meanError = sqrt( sumError2/ nIn );
984 std::map<double,binContainer*> absDiffMap;
987 absDiffMap[ fabs(
it->value -
mean ) ] = &(*it);
994 if( outlierCandidate->first < minDiff ) {
1000 double newMeanError = 0;
1003 sum +=
it->second->value;
1004 sumError2 +=
pow(
it->second->error,2);
1006 newMean =
sum/(nIn - 1);
1007 newMeanError = sqrt( sumError2/(nIn - 2) );
1009 double meanShift = fabs(
mean - newMean );
1012 if( meanShift > newMeanError ) {
1013 outlierCandidate->second->test =
false;
1015 meanError = newMeanError;
1026 const std::vector<double>& xValues,
const std::vector<double>& yValues,
double threshold,
int topology ) {
1028 binCluster cluster = {0.,0.,xValues[seed.ix],yValues[seed.iy],-1.,0,seed.ix,seed.ix,seed.iy,seed.iy};
1029 std::list<binContainer*> binsToCheck;
1030 std::vector<binContainer*> binsInCluster;
1031 binsToCheck.push_back(&seed);
1036 double maxDistanceX = -1;
1037 double maxDistanceY = -1;
1038 int ixRangeMax = (
int)xValues.size() - 2;
1039 int iyRangeMax = (
int)yValues.size() - 2;
1043 maxDistanceY = (yValues.back() - yValues.front()) / 2;
1046 maxDistanceX = (xValues.back() - xValues.front()) / 2;
1049 maxDistanceX = (xValues.back() - xValues.front()) / 2;
1050 maxDistanceY = (yValues.back() - yValues.front()) / 2;
1054 while( binsToCheck.size() != 0) {
1056 std::list<binContainer*> newNeighbors;
1057 for( std::list<binContainer*>::const_iterator
bin = binsToCheck.begin();
bin != binsToCheck.end(); ++
bin ) {
1066 if( ( fabs((*bin)->value) > (
threshold + 5*(*bin)->error ) ) && ( (*bin)->test == 0 ) && ((*bin)->error >= 0) ) {
1068 binsInCluster.push_back(*
bin);
1071 cluster.
value += (*bin)->value;
1072 error2 +=
pow( (*bin)->error, 2);
1075 int ix = (*bin)->ix;
1076 int iy = (*bin)->iy;
1077 double xPosition = xValues[ix];
1078 double yPosition = yValues[iy];
1082 if( (maxDistanceX > 0) && (fabs(xPosition - cluster.
x) > maxDistanceX) ) {
1084 if( xPosition < maxDistanceX ) {
1085 xPosition += 2 * maxDistanceX;
1086 if( (ix + ixRangeMax) > cluster.
ixmax ) {
1087 cluster.
ixmax = ix + ixRangeMax;
1091 xPosition -= 2 * maxDistanceX;
1092 if( (ix - ixRangeMax) < cluster.
ixmin ) {
1093 cluster.
ixmin = ix - ixRangeMax;
1099 if( ix < cluster.
ixmin ) {
1102 if( ix > cluster.
ixmax ) {
1107 if( (maxDistanceY > 0) && (fabs(yPosition - cluster.
y) > maxDistanceY) ) {
1109 if( yPosition < maxDistanceY ) {
1110 yPosition += 2 * maxDistanceY;
1111 if( (iy + iyRangeMax) > cluster.
iymax ) {
1112 cluster.
iymax = iy + iyRangeMax;
1116 yPosition -= 2 * maxDistanceY;
1117 if( (iy - iyRangeMax) < cluster.
iymin ) {
1118 cluster.
iymin = iy - iyRangeMax;
1124 if( iy < cluster.
iymin ) {
1127 if( iy > cluster.
iymax ) {
1132 pvpX += xPosition * (*bin)->value;
1133 pvpY += yPosition * (*bin)->value;
1137 newNeighbors.push_back( binMap[ix+1][iy+1] );
1138 newNeighbors.push_back( binMap[ix+1][iy] );
1139 newNeighbors.push_back( binMap[ix+1][iy-1] );
1141 newNeighbors.push_back( binMap[ix][iy+1] );
1142 newNeighbors.push_back( binMap[ix][iy-1] );
1144 newNeighbors.push_back( binMap[ix-1][iy+1] );
1145 newNeighbors.push_back( binMap[ix-1][iy] );
1146 newNeighbors.push_back( binMap[ix-1][iy-1] );
1153 newNeighbors.unique();
1155 binsToCheck = newNeighbors;
1157 cluster.
x = pvpX / cluster.
value;
1158 cluster.
y = pvpY / cluster.
value;
1162 cluster.
error = sqrt( error2 );
1166 for(std::vector<binContainer*>::const_iterator
bin = binsInCluster.begin();
bin != binsInCluster.end(); ++
bin) {
1167 double xDistance = fabs( xValues[(*bin)->ix] - cluster.
x );
1168 double yDistance = fabs( yValues[(*bin)->iy] - cluster.
y );
1169 if (maxDistanceX > 0 && (xDistance > maxDistanceX) ) {
1170 xDistance = 2 * maxDistanceX - xDistance;
1172 if (maxDistanceY > 0 && (yDistance > maxDistanceY) ) {
1173 yDistance = 2 * maxDistanceY - yDistance;
1176 dvpSum += (*bin)->value * sqrt(
pow( xValues[(*bin)->ix] - cluster.
x,2) +
pow(yValues[(*bin)->iy] - cluster.
y,2) );
1181 while( cluster.
ixmin < 1 ){
1182 cluster.
ixmin += ixRangeMax;
1184 while( cluster.
ixmax > ixRangeMax ){
1185 cluster.
ixmax -= ixRangeMax;
1187 while( cluster.
iymin < 1 ){
1188 cluster.
iymin += iyRangeMax;
1190 while( cluster.
iymax > iyRangeMax ){
1191 cluster.
iymax -= iyRangeMax;
1194 if( cluster.
x < xValues.front() ) {
1195 cluster.
x += 2 * maxDistanceX;
1197 if( cluster.
x > xValues.back() ) {
1198 cluster.
x -= 2 * maxDistanceX;
1200 if( cluster.
y < yValues.front() ) {
1201 cluster.
y += 2 * maxDistanceY;
1203 if( cluster.
y > yValues.back() ) {
1204 cluster.
y -= 2 * maxDistanceY;
1213 std::vector<std::vector<dqm_algorithms::tools::binContainer*> >
1216 std::vector<binContainer*> emptyVector;
1217 for(
int iy = 0; iy <= iymax + 1; ++iy) {
1219 emptyVector.push_back(emptyPointer);
1221 std::vector<std::vector<binContainer*> > binMap;
1222 for(
int ix = 0; ix <= ixmax + 1; ++ix) {
1223 binMap.push_back(emptyVector);
1231 binMap[
it->ix][
it->iy] = &(*it);
1233 binMap[
it->ix][iymax+1] = &(*it);
1235 else if(
it->iy == iymax){
1236 binMap[
it->ix][0] = &(*it);
1245 binMap[
it->ix][
it->iy] = &(*it);
1247 binMap[ixmax+1][
it->iy] = &(*it);
1249 else if(
it->ix == ixmax){
1250 binMap[0][
it->iy] = &(*it);
1259 binMap[
it->ix][
it->iy] = &(*it);
1261 binMap[ixmax+1][
it->iy] = &(*it);
1263 binMap[ixmax+1][iymax+1] = &(*it);
1265 if(
it->iy == iymax){
1266 binMap[ixmax+1][0] = &(*it);
1269 else if(
it->ix == ixmax){
1270 binMap[0][
it->iy] = &(*it);
1272 binMap[0][iymax+1] = &(*it);
1274 if(
it->iy == iymax){
1275 binMap[0][0] = &(*it);
1279 binMap[
it->ix][iymax+1] = &(*it);
1281 else if(
it->iy == iymax){
1282 binMap[
it->ix][0] = &(*it);
1291 binMap[
it->ix][
it->iy] = &(*it);
1312 if( addedStatus == dqm_core::Result::Yellow ) {
1318 addedStatus = dqm_core::Result::Yellow;
1326 if(baseStatus == dqm_core::Result::Disabled) {
1329 if(addedStatus == dqm_core::Result::Disabled) {
1343 return dqm_core::Result::Yellow;
1355 if( addedStatus == dqm_core::Result::Yellow ) {
1361 addedStatus = dqm_core::Result::Yellow;
1365 if( (baseStatus == dqm_core::Result::Disabled) || (addedStatus == dqm_core::Result::Disabled) ) {
1366 return dqm_core::Result::Disabled;
1381 return dqm_core::Result::Yellow;
1386 std::pair<double,double>
1390 std::vector<double>::const_iterator iter_vals = inputval.begin();
1391 std::vector<double>::const_iterator iter_err = inputerr.begin();
1393 std::vector<double>::const_iterator iter_x0 = x0.begin();
1394 std::vector<double>::const_iterator iter_x0err = x0err.begin();
1397 for ( ; iter_vals != inputval.end(); ++iter_vals,++iter_err,++iter_x0,++iter_x0err){
1398 if (fabs(*iter_err) > 1.0
e-5 || fabs(*iter_x0err) > 1.0
e-5){
1399 double chisq_cont =
pow(((*iter_vals)-(*iter_x0)),2.)/(
pow(*iter_err,2.0)+
pow(*iter_x0err,2.0));
1401 chisq += chisq_cont;
1405 double prob = ROOT::Math::chisquared_cdf_c(chisq,
ndf);
1406 double sigma_chisq = ROOT::Math::normal_quantile_c(
prob,1.);
1407 return std::make_pair(
prob,sigma_chisq);
1410 std::pair<double,double>
1414 std::vector<double>::const_iterator iter_vals = inputval.begin();
1415 std::vector<double>::const_iterator iter_err = inputerr.begin();
1417 for ( ; iter_vals != inputval.end(); ++iter_vals,++iter_err){
1418 if (fabs(*iter_err) > 1.0
e-5){
1419 double chisq_cont =
pow(((*iter_vals)-x0),2.)/(
pow(*iter_err,2.0)+
pow(x0_err,2.0));
1421 chisq += chisq_cont;
1425 double prob = ROOT::Math::chisquared_cdf_c(chisq,
ndf);
1426 double sigma_chisq = ROOT::Math::normal_quantile_c(
prob,1.);
1427 return std::make_pair(
prob,sigma_chisq);
1436 if(strips.size() < 2) {
1440 std::vector<std::vector<tools::binContainer> >
::iterator begining = strips.begin();
1441 std::vector<std::vector<tools::binContainer> >
::iterator ending = strips.end();
1444 while ( begining != ending ) {
1445 std::vector<std::vector<tools::binContainer> >
::iterator minBinsItr = begining;
1446 for( std::vector<std::vector<tools::binContainer> >::
iterator itr = begining; itr != (ending+1); ++itr ) {
1447 if( (!itr->empty()) && ((itr->size() < minBinsItr->size()) || minBinsItr->empty()) ) {
1452 if( ((
int)minBinsItr->size()) < minStat ) {
1453 if( minBinsItr == begining ) {
1455 std::vector<std::vector<tools::binContainer> >
::iterator mergeStripItr = minBinsItr;
1457 while( mergeStripItr->empty() ) {
1459 if( mergeStripItr == ending )
break;
1461 mergeStripItr->insert( mergeStripItr->end(), minBinsItr->begin(), minBinsItr->end() );
1462 minBinsItr->clear();
1463 begining = mergeStripItr;
1465 else if( minBinsItr == ending ) {
1467 std::vector<std::vector<tools::binContainer> >
::iterator mergeStripItr = minBinsItr;
1469 while( mergeStripItr->empty() ) {
1471 if( mergeStripItr == begining )
break;
1473 mergeStripItr->insert( mergeStripItr->end(), minBinsItr->begin(), minBinsItr->end() );
1474 minBinsItr->clear();
1475 ending = mergeStripItr;
1479 std::vector<std::vector<tools::binContainer> >
::iterator mergeLeftItr = minBinsItr;
1480 std::vector<std::vector<tools::binContainer> >
::iterator mergeRightItr = minBinsItr;
1483 while( mergeLeftItr->empty() && mergeRightItr->empty() ) {
1487 if( mergeLeftItr->empty() ) {
1488 mergeRightItr->insert( mergeRightItr->end(), minBinsItr->begin(), minBinsItr->end() );
1489 minBinsItr->clear();
1491 else if( mergeRightItr->empty() ) {
1492 mergeLeftItr->insert( mergeLeftItr->end(), minBinsItr->begin(), minBinsItr->end() );
1493 minBinsItr->clear();
1496 if( mergeLeftItr->size() < mergeRightItr->size() ) {
1497 mergeLeftItr->insert( mergeLeftItr->end(), minBinsItr->begin(), minBinsItr->end() );
1498 minBinsItr->clear();
1501 mergeRightItr->insert( mergeRightItr->end(), minBinsItr->begin(), minBinsItr->end() );
1502 minBinsItr->clear();
1518 tag +=
"(eta,phi)[err]= (";
1556 if( (
value > 0) && !showSign ) {
1562 else if(
order == -1 ) {
1580 else if(
order == -1 ) {
1598 #endif // #ifndef DQM_ALGORITHMS_TOOLS_ALGORITHMHELPER_CXX