ATLAS Offline Software
Loading...
Searching...
No Matches
dqm_algorithms::tools Namespace Reference

Classes

struct  binContainer
struct  binCluster
class  DumpConfig
class  SimpleAlgorithmConfig
 This class provides a simple implementation of the DQMF abstract AlgorithmConfig interface which can be used in dqm_algorithms (see AddReference algorithms). More...

Enumerations

enum  AxisType {
  XYAxes , XAxis , YAxis , XYZAxes ,
  XZAxes , YZAxes , ZAxis
}
enum  Topology { Rectangle , CylinderX , CylinderY , Torus }

Functions

std::map< std::string, double > GetFitParams (const TF1 *func)
std::map< std::string, double > GetFitParamErrors (const TF1 *func)
dqm_core::Result * MakeComparisons (const std::map< std::string, double > &algparams, const std::map< std::string, double > &gthreshold, const std::map< std::string, double > &rthreshold)
dqm_core::Result * CompareWithErrors (const std::map< std::string, double > &algparams, const std::map< std::string, double > &paramErrors, const std::map< std::string, double > &gthreshold, const std::map< std::string, double > &rthreshold, double minSig)
dqm_core::Result * GetFitResult (const TF1 *func, const dqm_core::AlgorithmConfig &config, double minSig=0)
double GetFirstFromMap (const std::string &paramName, const std::map< std::string, double > &params)
double GetFirstFromMap (const std::string &paramName, const std::map< std::string, double > &params, double defaultValue)
const std::string & GetFirstFromMap (const std::string &paramName, const std::map< std::string, std::string > &params)
const std::string & GetFirstFromMap (const std::string &paramName, const std::map< std::string, std::string > &params, const std::string &defaultValue)
std::vector< int > GetBinRange (const TH1 *histogram, const std::map< std::string, double > &params)
void PublishBin (const TH1 *histogram, int xbin, int ybin, double content, dqm_core::Result *result)
TH1 * DivideByHistogram (const TH1 *hNumerator, const TH1 *hDenominator)
void ModifyHistogram (TH1 *histogram, const dqm_core::AlgorithmConfig &config)
std::string ExtractAlgorithmName (const dqm_core::AlgorithmConfig &config)
dqm_core::Result * ExecuteNamedAlgorithm (const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
TH1 * BookHistogramByExample (const TH1 *histogram, const std::string &name, const std::string &title, AxisType axisType)
template<class T>
const T & GetFromMap (const std::string &pname, const std::map< std::string, T > &params)
void handleReference (const TObject &inputReference, const TObject *&firstReference, TObject *&secondReference)
 Helper function used to handle complex reference histograms This function gets as input a reference object and checks if it is a collection of references, in this case extracts and returns the first element.
void findOutliers (std::vector< binContainer > &input, double &mean, double &scale, int &nIn, int nIterations, double exponent, double threshold, double SBCF=1., double nStop=8.)
void findOutliersUsingErrors (std::vector< binContainer > &input, double &mean, double &meanError, int &nIn, double mindiff=0, int minNin=4)
binCluster buildCluster (binContainer &seed, const std::vector< std::vector< binContainer * > > &binMap, const std::vector< double > &xValues, const std::vector< double > &yValues, double threhold, int topology=CylinderX)
std::vector< std::vector< binContainer * > > makeBinMap (std::vector< dqm_algorithms::tools::binContainer > &bins, int ixmax, int iymax, int topology=CylinderX)
dqm_core::Result::Status WorstCaseAddStatus (dqm_core::Result::Status baseStatus, dqm_core::Result::Status addedStatus, float weight=1.0)
dqm_core::Result::Status BestCaseAddStatus (dqm_core::Result::Status baseStatus, dqm_core::Result::Status addedStatus, float weight=1.0)
std::pair< double, double > CalcBinsProbChisq (const std::vector< double > &inputval, const std::vector< double > &inputerr, double x0, double x0_err)
std::pair< double, double > CalcBinsProbChisq (const std::vector< double > &inputval, const std::vector< double > &inputerr, const std::vector< double > &x0, const std::vector< double > &x0_err)
void MergePastMinStat (std::vector< std::vector< tools::binContainer > > &strips, int minStat)
void MakeBinTag (const binContainer &bin, std::string &tag)
void FormatToSize (double value, int size, std::string &str, bool showSign=true)

Enumeration Type Documentation

◆ AxisType

◆ Topology

Enumerator
Rectangle 
CylinderX 
CylinderY 
Torus 

Definition at line 41 of file AlgorithmHelper.h.

Function Documentation

◆ BestCaseAddStatus()

dqm_core::Result::Status dqm_algorithms::tools::BestCaseAddStatus ( dqm_core::Result::Status baseStatus,
dqm_core::Result::Status addedStatus,
float weight = 1.0 )

Definition at line 1359 of file AlgorithmHelper.cxx.

1359 {
1360 //-- Acts analogously to a logical AND -- (Red <-> True, etc.)
1361
1362 //apply the "weight" to addedstatus only: (same scheme as in WorstCaseAddStatus)
1363 if( weight <= 0 ) {
1364 return baseStatus;
1365 }
1366 if( weight <= 0.25 ) {
1367 if( addedStatus == dqm_core::Result::Yellow ) {
1368 addedStatus = dqm_core::Result::Green;
1369 }
1370 }
1371 if( weight <= 0.5 ) {
1372 if( addedStatus == dqm_core::Result::Red) {
1373 addedStatus = dqm_core::Result::Yellow;
1374 }
1375 }
1376
1377 if( (baseStatus == dqm_core::Result::Disabled) || (addedStatus == dqm_core::Result::Disabled) ) {
1378 return dqm_core::Result::Disabled;
1379 }
1380
1381 if( (baseStatus == dqm_core::Result::Undefined) || (addedStatus == dqm_core::Result::Undefined) ) {
1382 return dqm_core::Result::Undefined;
1383 }
1384
1385 if( (baseStatus == dqm_core::Result::Green) || (addedStatus == dqm_core::Result::Green) ) {
1386 return dqm_core::Result::Green;
1387 }
1388
1389 if( (baseStatus == dqm_core::Result::Red) && (addedStatus == dqm_core::Result::Red) ) {
1390 return dqm_core::Result::Red;
1391 }
1392
1393 return dqm_core::Result::Yellow;
1394
1395}

◆ BookHistogramByExample()

TH1 * dqm_algorithms::tools::BookHistogramByExample ( const TH1 * histogram,
const std::string & name,
const std::string & title,
AxisType axisType )

Definition at line 695 of file AlgorithmHelper.cxx.

695 {
696
697 switch (axisType) {
698 case XYAxes:
699
700 if (histogram->GetDimension() == 1){
701 throw dqm_core::BadConfig( ERS_HERE, name,"can't make a 2D histogram from a 1D histogram");
702 }
703 TH2F * resultXY;
704 if(histogram->GetXaxis()->IsVariableBinSize()) {
705 resultXY = new TH2F(name.c_str(),title.c_str(),
706 histogram->GetNbinsX(),histogram->GetXaxis()->GetXbins()->GetArray(),
707 histogram->GetNbinsY(),histogram->GetYaxis()->GetXbins()->GetArray());
708 }
709 else {
710 resultXY = new TH2F(name.c_str(),title.c_str(),
711 histogram->GetNbinsX(),histogram->GetXaxis()->GetXmin(),histogram->GetXaxis()->GetXmax(),
712 histogram->GetNbinsY(),histogram->GetYaxis()->GetXmin(),histogram->GetYaxis()->GetXmax());
713 }
714
715 resultXY->SetXTitle(histogram->GetXaxis()->GetTitle());
716 resultXY->SetYTitle(histogram->GetYaxis()->GetTitle());
717 return static_cast<TH1*> (resultXY);
718
719 case YAxis:
720
721 if (histogram->GetDimension() == 1){
722 throw dqm_core::BadConfig( ERS_HERE, name, "can't extract a Y-Axis from a 1D histogram");
723 }
724 TH1F *resultY;
725 if(histogram->GetYaxis()->IsVariableBinSize()) {
726 resultY = new TH1F(name.c_str(),title.c_str(),
727 histogram->GetNbinsY(),histogram->GetYaxis()->GetXbins()->GetArray());
728 }
729 else {
730 resultY = new TH1F(name.c_str(),title.c_str(),
731 histogram->GetNbinsY(),histogram->GetYaxis()->GetXmin(),histogram->GetYaxis()->GetXmax());
732 }
733 resultY->SetXTitle(histogram->GetYaxis()->GetTitle());
734 return static_cast<TH1*> (resultY);
735
736 case XYZAxes:
737
738 if (histogram->GetDimension() < 3){
739 throw dqm_core::BadConfig( ERS_HERE, name, "can't make a 3D histrogram without at least a 3D histogram");
740 }
741 TH3F *resultXYZ;
742 if(histogram->GetXaxis()->IsVariableBinSize()) {
743 resultXYZ = new TH3F(name.c_str(),title.c_str(),
744 histogram->GetNbinsX(),histogram->GetXaxis()->GetXbins()->GetArray(),
745 histogram->GetNbinsY(),histogram->GetYaxis()->GetXbins()->GetArray(),
746 histogram->GetNbinsZ(),histogram->GetZaxis()->GetXbins()->GetArray());
747 }
748 else {
749 resultXYZ = new TH3F(name.c_str(),title.c_str(),
750 histogram->GetNbinsX(),histogram->GetXaxis()->GetXmin(),histogram->GetXaxis()->GetXmax(),
751 histogram->GetNbinsY(),histogram->GetYaxis()->GetXmin(),histogram->GetYaxis()->GetXmax(),
752 histogram->GetNbinsZ(),histogram->GetZaxis()->GetXmin(),histogram->GetZaxis()->GetXmax());
753 }
754 resultXYZ->SetXTitle(histogram->GetXaxis()->GetTitle());
755 resultXYZ->SetYTitle(histogram->GetYaxis()->GetTitle());
756 resultXYZ->SetZTitle(histogram->GetZaxis()->GetTitle());
757 return resultXYZ;
758
759 case XZAxes:
760
761 if (histogram->GetDimension() < 3){
762 throw dqm_core::BadConfig( ERS_HERE, name,"can't extract a Z-Axis from a dimension < 3 histogram");
763 }
764 TH2F * resultXZ;
765 if(histogram->GetXaxis()->IsVariableBinSize()) {
766 resultXZ = new TH2F(name.c_str(),title.c_str(),
767 histogram->GetNbinsX(),histogram->GetXaxis()->GetXbins()->GetArray(),
768 histogram->GetNbinsZ(),histogram->GetZaxis()->GetXbins()->GetArray());
769 }
770 else {
771 resultXZ = new TH2F(name.c_str(),title.c_str(),
772 histogram->GetNbinsX(),histogram->GetXaxis()->GetXmin(),histogram->GetXaxis()->GetXmax(),
773 histogram->GetNbinsZ(),histogram->GetZaxis()->GetXmin(),histogram->GetZaxis()->GetXmax());
774 }
775 resultXZ->SetXTitle(histogram->GetXaxis()->GetTitle());
776 resultXZ->SetYTitle(histogram->GetZaxis()->GetTitle());
777 return static_cast<TH1*> (resultXZ);
778
779 case YZAxes:
780
781 if (histogram->GetDimension() < 3){
782 throw dqm_core::BadConfig( ERS_HERE, name,"can't extract a Z-Axis from a dimension < 3 histogram");
783 }
784 TH2F * resultYZ;
785 if(histogram->GetYaxis()->IsVariableBinSize()) {
786 resultYZ = new TH2F(name.c_str(),title.c_str(),
787 histogram->GetNbinsY(),histogram->GetYaxis()->GetXbins()->GetArray(),
788 histogram->GetNbinsZ(),histogram->GetZaxis()->GetXbins()->GetArray());
789 }
790 else {
791 resultYZ = new TH2F(name.c_str(),title.c_str(),
792 histogram->GetNbinsY(),histogram->GetYaxis()->GetXmin(),histogram->GetYaxis()->GetXmax(),
793 histogram->GetNbinsZ(),histogram->GetZaxis()->GetXmin(),histogram->GetZaxis()->GetXmax());
794 }
795 resultYZ->SetXTitle(histogram->GetYaxis()->GetTitle());
796 resultYZ->SetYTitle(histogram->GetZaxis()->GetTitle());
797 return static_cast<TH1*> (resultYZ);
798
799 case ZAxis:
800
801 if (histogram->GetDimension() < 3){
802 throw dqm_core::BadConfig( ERS_HERE, name, "can't extract a Z-Axis from a dimension < 3 histogram");
803 }
804 TH1F *resultZ;
805 if(histogram->GetZaxis()->IsVariableBinSize()) {
806 resultZ = new TH1F(name.c_str(),title.c_str(),
807 histogram->GetNbinsZ(),histogram->GetZaxis()->GetXbins()->GetArray());
808 }
809 else {
810 resultZ = new TH1F(name.c_str(),title.c_str(),
811 histogram->GetNbinsZ(),histogram->GetZaxis()->GetXmin(),histogram->GetZaxis()->GetXmax());
812 }
813 resultZ->SetXTitle(histogram->GetZaxis()->GetTitle());
814 return static_cast<TH1*> (resultZ);
815
816 case XAxis:
817 default:
818
819 TH1F *resultX;
820 if(histogram->GetXaxis()->IsVariableBinSize()) {
821 resultX = new TH1F(name.c_str(),title.c_str(),
822 histogram->GetNbinsX(),histogram->GetXaxis()->GetXbins()->GetArray());
823 }
824 else {
825 resultX = new TH1F(name.c_str(),title.c_str(),
826 histogram->GetNbinsX(),histogram->GetXaxis()->GetXmin(),histogram->GetXaxis()->GetXmax());
827 }
828 resultX->SetXTitle(histogram->GetXaxis()->GetTitle());
829 return static_cast<TH1*> (resultX );
830 }
831
832}
std::string histogram
Definition chains.cxx:52
TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)

◆ buildCluster()

dqm_algorithms::tools::binCluster dqm_algorithms::tools::buildCluster ( binContainer & seed,
const std::vector< std::vector< binContainer * > > & binMap,
const std::vector< double > & xValues,
const std::vector< double > & yValues,
double threhold,
int topology = CylinderX )

Definition at line 1032 of file AlgorithmHelper.cxx.

1033 {
1034
1035 binCluster cluster = {0.,0.,xValues[seed.ix],yValues[seed.iy],-1.,0,seed.ix,seed.ix,seed.iy,seed.iy};
1036 std::list<binContainer*> binsToCheck;
1037 std::vector<binContainer*> binsInCluster;
1038 binsToCheck.push_back(&seed);
1039 double pvpX = 0;
1040 double pvpY = 0;
1041 double error2 = 0;
1042
1043 double maxDistanceX = -1;
1044 double maxDistanceY = -1;
1045 int ixRangeMax = (int)xValues.size() - 2;
1046 int iyRangeMax = (int)yValues.size() - 2;
1047
1048 switch(topology) {
1049 case CylinderX:
1050 maxDistanceY = (yValues.back() - yValues.front()) / 2;
1051 break;
1052 case CylinderY:
1053 maxDistanceX = (xValues.back() - xValues.front()) / 2;
1054 break;
1055 case Torus:
1056 maxDistanceX = (xValues.back() - xValues.front()) / 2;
1057 maxDistanceY = (yValues.back() - yValues.front()) / 2;
1058 break;
1059 }
1060
1061 while( binsToCheck.size() != 0) {
1062
1063 std::list<binContainer*> newNeighbors;
1064 for( std::list<binContainer*>::const_iterator bin = binsToCheck.begin(); bin != binsToCheck.end(); ++bin ) {
1065
1066 //If bin is a null pointer, continue to the next bin:
1067 if( *bin == 0) {
1068 continue;
1069 }
1070
1071 //If the bin passes the threshold, add its values to the clusters and its neighbors to the list of bins to look at:
1072 //(As long as it hasn't already been added to another cluster or otherwise excluded)
1073 if( ( fabs((*bin)->value) > (threshold + 5*(*bin)->error ) ) && ( (*bin)->test == 0 ) && ((*bin)->error >= 0) ) {
1074 //Add bin to cluster:
1075 binsInCluster.push_back(*bin);
1076 (*bin)->test = 10;
1077
1078 cluster.value += (*bin)->value;
1079 error2 += pow( (*bin)->error, 2);
1080 cluster.n++;
1081
1082 int ix = (*bin)->ix;
1083 int iy = (*bin)->iy;
1084 double xPosition = xValues[ix];
1085 double yPosition = yValues[iy];
1086
1087 //Adjust position information if it looks like we may have jumped a discontinuity
1088 // and such discontinuities are expected. Also check for max, min ix, iy:
1089 if( (maxDistanceX > 0) && (fabs(xPosition - cluster.x) > maxDistanceX) ) {
1090 //Correct for topological mapping difficulties:
1091 if( xPosition < maxDistanceX ) {
1092 xPosition += 2 * maxDistanceX;
1093 if( (ix + ixRangeMax) > cluster.ixmax ) {
1094 cluster.ixmax = ix + ixRangeMax;
1095 }
1096 }
1097 else {
1098 xPosition -= 2 * maxDistanceX;
1099 if( (ix - ixRangeMax) < cluster.ixmin ) {
1100 cluster.ixmin = ix - ixRangeMax;
1101 }
1102 }
1103 }
1104 else {
1105 //No topological difficulties:
1106 if( ix < cluster.ixmin ) {
1107 cluster.ixmin = ix;
1108 }
1109 if( ix > cluster.ixmax ) {
1110 cluster.ixmax = ix;
1111 }
1112 }
1113
1114 if( (maxDistanceY > 0) && (fabs(yPosition - cluster.y) > maxDistanceY) ) {
1115 //Correct for topological mapping difficulties:
1116 if( yPosition < maxDistanceY ) {
1117 yPosition += 2 * maxDistanceY;
1118 if( (iy + iyRangeMax) > cluster.iymax ) {
1119 cluster.iymax = iy + iyRangeMax;
1120 }
1121 }
1122 else {
1123 yPosition -= 2 * maxDistanceY;
1124 if( (iy - iyRangeMax) < cluster.iymin ) {
1125 cluster.iymin = iy - iyRangeMax;
1126 }
1127 }
1128 }
1129 else {
1130 //No topological difficulties:
1131 if( iy < cluster.iymin ) {
1132 cluster.iymin = iy;
1133 }
1134 if( iy > cluster.iymax ) {
1135 cluster.iymax = iy;
1136 }
1137 }
1138
1139 pvpX += xPosition * (*bin)->value;
1140 pvpY += yPosition * (*bin)->value;
1141
1142
1143 //Find neighbors
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] );
1147
1148 newNeighbors.push_back( binMap[ix][iy+1] );
1149 newNeighbors.push_back( binMap[ix][iy-1] );
1150
1151 newNeighbors.push_back( binMap[ix-1][iy+1] );
1152 newNeighbors.push_back( binMap[ix-1][iy] );
1153 newNeighbors.push_back( binMap[ix-1][iy-1] );
1154
1155
1156 }
1157 }//End looping over binsToCheck (last set of neighbors)
1158
1159 //Remove repeated references to the same bin:
1160 newNeighbors.unique();
1161 //Perpare to check the cluster's new neighbors:
1162 binsToCheck = std::move(newNeighbors);
1163
1164 if (cluster.value != 0) {
1165 cluster.x = pvpX / cluster.value;
1166 cluster.y = pvpY / cluster.value;
1167 }
1168 else {
1169 cluster.x = cluster.y = 0;
1170 }
1171 }//Finished finding bins in cluster
1172
1173 //Assume that the input errors are uncorrelated (or that the caller will deal with this)
1174 cluster.error = sqrt( error2 );
1175
1176 //loop to calculate the radius of the cluster (the value weighted average distance from its center)
1177 double dvpSum = 0;
1178 for(std::vector<binContainer*>::const_iterator bin = binsInCluster.begin(); bin != binsInCluster.end(); ++bin) {
1179 double xDistance = fabs( xValues[(*bin)->ix] - cluster.x );
1180 double yDistance = fabs( yValues[(*bin)->iy] - cluster.y );
1181 if (maxDistanceX > 0 && (xDistance > maxDistanceX) ) {
1182 xDistance = 2 * maxDistanceX - xDistance;
1183 }
1184 if (maxDistanceY > 0 && (yDistance > maxDistanceY) ) {
1185 yDistance = 2 * maxDistanceY - yDistance;
1186 }
1187
1188 dvpSum += (*bin)->value * sqrt( pow( xValues[(*bin)->ix] - cluster.x,2) + pow(yValues[(*bin)->iy] - cluster.y,2) );
1189 }
1190 cluster.radius = cluster.value != 0 ? dvpSum / cluster.value : 0;
1191
1192 //Check that positions are within the bounds of the histogram and correct
1193 while( cluster.ixmin < 1 ){
1194 cluster.ixmin += ixRangeMax;
1195 }
1196 while( cluster.ixmax > ixRangeMax ){
1197 cluster.ixmax -= ixRangeMax;
1198 }
1199 while( cluster.iymin < 1 ){
1200 cluster.iymin += iyRangeMax;
1201 }
1202 while( cluster.iymax > iyRangeMax ){
1203 cluster.iymax -= iyRangeMax;
1204 }
1205
1206 if( cluster.x < xValues.front() ) {
1207 cluster.x += 2 * maxDistanceX;
1208 }
1209 if( cluster.x > xValues.back() ) {
1210 cluster.x -= 2 * maxDistanceX;
1211 }
1212 if( cluster.y < yValues.front() ) {
1213 cluster.y += 2 * maxDistanceY;
1214 }
1215 if( cluster.y > yValues.back() ) {
1216 cluster.y -= 2 * maxDistanceY;
1217 }
1218
1219
1220 return cluster;
1221}
constexpr int pow(int x)
Definition conifer.h:27

◆ CalcBinsProbChisq() [1/2]

std::pair< double, double > dqm_algorithms::tools::CalcBinsProbChisq ( const std::vector< double > & inputval,
const std::vector< double > & inputerr,
const std::vector< double > & x0,
const std::vector< double > & x0_err )

Definition at line 1399 of file AlgorithmHelper.cxx.

1399 {
1400
1401 double chisq = 0.;
1402 std::vector<double>::const_iterator iter_vals = inputval.begin();
1403 std::vector<double>::const_iterator iter_err = inputerr.begin();
1404
1405 std::vector<double>::const_iterator iter_x0 = x0.begin();
1406 std::vector<double>::const_iterator iter_x0err = x0err.begin();
1407
1408 int ndf = 0;
1409 for ( ; iter_vals != inputval.end(); ++iter_vals,++iter_err,++iter_x0,++iter_x0err){
1410 if (fabs(*iter_err) > 1.0e-5 || fabs(*iter_x0err) > 1.0e-5){
1411 double chisq_cont = pow(((*iter_vals)-(*iter_x0)),2.)/(pow(*iter_err,2.0)+pow(*iter_x0err,2.0));
1412 ++ndf;
1413 chisq += chisq_cont;
1414 }
1415 }
1416
1417 double prob = ROOT::Math::chisquared_cdf_c(chisq,ndf);
1418 double sigma_chisq = ROOT::Math::normal_quantile_c(prob,1.);
1419 return std::make_pair(prob,sigma_chisq);
1420}

◆ CalcBinsProbChisq() [2/2]

std::pair< double, double > dqm_algorithms::tools::CalcBinsProbChisq ( const std::vector< double > & inputval,
const std::vector< double > & inputerr,
double x0,
double x0_err )

Definition at line 1423 of file AlgorithmHelper.cxx.

1423 {
1424
1425 double chisq = 0.;
1426 std::vector<double>::const_iterator iter_vals = inputval.begin();
1427 std::vector<double>::const_iterator iter_err = inputerr.begin();
1428 int ndf = 0;
1429 for ( ; iter_vals != inputval.end(); ++iter_vals,++iter_err){
1430 if (fabs(*iter_err) > 1.0e-5){
1431 double chisq_cont = pow(((*iter_vals)-x0),2.)/(pow(*iter_err,2.0)+pow(x0_err,2.0));
1432 ++ndf;
1433 chisq += chisq_cont;
1434 }
1435 }
1436
1437 double prob = ROOT::Math::chisquared_cdf_c(chisq,ndf);
1438 double sigma_chisq = ROOT::Math::normal_quantile_c(prob,1.);
1439 return std::make_pair(prob,sigma_chisq);
1440}

◆ CompareWithErrors()

dqm_core::Result * dqm_algorithms::tools::CompareWithErrors ( const std::map< std::string, double > & algparams,
const std::map< std::string, double > & paramErrors,
const std::map< std::string, double > & gthreshold,
const std::map< std::string, double > & rthreshold,
double minSig )

Definition at line 175 of file AlgorithmHelper.cxx.

179{
180
181 int red = 0;
182 int yellow = 0;
183 int green = 0;
184 int undefined = 0;
185
186
187 if (gthreshold.size() != rthreshold.size()) {
188 throw dqm_core::BadConfig( ERS_HERE, "MakeComparisons", "Need same number of Red and Green Threshold" );
189 }
190
191 if (gthreshold.size() == 0 ) {
192 throw dqm_core::BadConfig( ERS_HERE, "MakeComparisons", "No Threshold specified" );
193 }
194
195 std::map<std::string,double>::const_iterator g_iter;
196
197 for (g_iter=gthreshold.begin();g_iter!=gthreshold.end();++g_iter){
198
199 std::string name=(std::string) g_iter->first;
200 std::string findname=name;
201 double gtvalue=g_iter->second;
202
203 if (name == "AbsMean" )
204 findname="Mean";
205 if (name == "AbsXMean" )
206 findname="XMean";
207 if (name == "AbsYMean" )
208 findname="YMean";
209
210
211 std::map<std::string,double>::const_iterator ait = algparams.find(findname);
212 std::map<std::string,double>::const_iterator errItr = paramErrors.find(findname);
213 std::map<std::string,double>::const_iterator rit = rthreshold.find(name);
214
215 double rtvalue = -999;
216 double avalue = -999;
217 double error = 0;
218
219 if ( ait != algparams.end() ) {
220 avalue=ait->second;
221 }
222 else {
223 throw dqm_core::BadConfig( ERS_HERE, "None", std::move(name) );
224 }
225
226 if ( errItr != paramErrors.end() ) {
227 error = errItr->second;
228 }
229 else {
230 throw dqm_core::BadConfig( ERS_HERE, "Problem retrieving fit param error", std::move(name) );
231 }
232 if ( error < 0 ) error = 0;
233
234 if ( rit != rthreshold.end() ) {
235 rtvalue=rit->second;
236 }
237 else {
238 throw dqm_core::BadConfig( ERS_HERE, "None", std::move(name) );
239 }
240
241 //cppcheck-suppress accessMoved
242 if (name == "AbsMean" || name == "AbsXMean" || name== "AbsYMean") {
243 avalue = fabs(avalue);
244 if (gtvalue < 0 || rtvalue <0 ) {
245 throw dqm_core::BadConfig( ERS_HERE, "None", std::move(name) );
246 }
247 }
248
249 ERS_DEBUG(1, name<<" :red value "<<rtvalue<<" :green value "<<gtvalue<<" :param value "<<avalue <<" :param error "<<error);
250
251 double significanceBound = error * minSig;
252
253
254 if (gtvalue < rtvalue) {
255
256 if ( avalue <= (gtvalue - significanceBound) ){
257 ++green;
258 }
259 else if( avalue > (rtvalue + significanceBound) ){
260 ++red;
261 }
262 else if( avalue > (gtvalue + significanceBound) ) {
263 ++yellow;
264 }
265 else {
266 ++undefined;
267 }
268 }
269 else if (gtvalue > rtvalue) {
270 if ( avalue >= (gtvalue + significanceBound) ){
271 ++green;
272 }
273 else if( avalue < (rtvalue - significanceBound) ){
274 ++red;
275 }
276 else if( avalue < (gtvalue - significanceBound) ){
277 ++yellow;
278 }
279 else {
280 ++undefined;
281 }
282 }
283 else {
284 ERS_DEBUG(0, "red threshold same as green threshold: can't evaluate result");
285 throw dqm_core::BadConfig( ERS_HERE, "None", std::move(name) );
286 }
287
288 }
289 ERS_DEBUG(1, "red: "<<red<<" yellow: "<<yellow<<" green: "<<green << " undefined: " <<undefined);
290
291
292 dqm_core::Result* result = new dqm_core::Result();
293
294 result->tags_ = algparams;
295
296 // We use a strung undefined here: if one of the test parameters was in the undefined region about gth,
297 // then the overall result will be undefined.
298 if (red>0) {
299 result->status_= dqm_core::Result::Red;
300 }
301 else if (yellow>0) {
302 result->status_= dqm_core::Result::Yellow;
303 }
304 else if (undefined>0) {
305 result->status_= dqm_core::Result::Undefined;
306 }
307 else if (green>0) {
308 result->status_= dqm_core::Result::Green;
309 }
310
311 return result;
312}

◆ DivideByHistogram()

TH1 * dqm_algorithms::tools::DivideByHistogram ( const TH1 * hNumerator,
const TH1 * hDenominator )

Definition at line 453 of file AlgorithmHelper.cxx.

454{
455
456 TH1 * hResult = 0;
457
458 int hNdimension = hNumerator->GetDimension();
459 int hDdimension = hDenominator->GetDimension();
460
461 if( hDdimension == hNdimension ) {
462 if( (hNumerator->GetNbinsX() != hDenominator->GetNbinsX()) || (hNumerator->GetNbinsY() != hDenominator->GetNbinsY()) ||
463 (hNumerator->GetNbinsZ() != hNumerator->GetNbinsZ()) ) {
464 throw dqm_core::BadConfig( ERS_HERE, "DivideByHistogram", "number of bins do not match");
465 }
466 //since the dimensions match, use the root TH1 division method
467 //as recommended in root documentation, we call Sumw2 first to keep the errors well behaved:
468
469 if( hNdimension == 1) {
470 hResult = BookHistogramByExample(hNumerator,"hQuotient","Result of Division of One Histogram By Another",XAxis);
471 }
472 else if ( hNdimension == 2 ) {
473 hResult = BookHistogramByExample(hNumerator,"hQuotient","Result of Division of One Histogram By Another",XYAxes);
474 }
475 else if ( hNdimension == 3 ) {
476 hResult = BookHistogramByExample(hNumerator,"hQuotient","Result of Division of One Histogram By Another",XYZAxes);
477 }
478 else {
479 throw dqm_core::BadConfig( ERS_HERE, "DivideByHistogram", "Histograms with dimension greater than 3 are not supported");
480 }
481 hResult->Sumw2();
482
483 hResult->Divide(hNumerator,hDenominator);
484 }
485 else if ( hNdimension > hDdimension ) {
486 //Handle division for case where denominator has lower dimension than numerator:
487 //There are only a few possibilities, hNdimension = 2 or 3, hDdimension = 1 or 2.
488
489 const TAxis* xax = hNumerator->GetXaxis();
490 int nbinsx = xax->GetNbins();
491 const TAxis* yax = hNumerator->GetYaxis();
492 int nbinsy = yax->GetNbins();
493 const TAxis* zax = hNumerator->GetZaxis();
494 int nbinsz = zax->GetNbins();
495
496 if( nbinsx != hDenominator->GetNbinsX() ) {
497 throw dqm_core::BadConfig( ERS_HERE, "DivideByHistogram", "number of bins in x-axis do not match");
498 }
499 if( (hDdimension == 2) && (nbinsy != hDenominator->GetNbinsY()) ) {
500 throw dqm_core::BadConfig( ERS_HERE, "DivideByHistogram", "number of bins in y-axis do not match");
501 }
502
503 double numeratorCont = 0;
504 double denominatorCont = 0;
505 double numeratorError = 0;
506 double denominatorError = 0;
507
508 if(hNdimension == 2) {
509 hResult = BookHistogramByExample(hNumerator,"hQuotient","Result of Division of One Histogram By Another",XYAxes);
510 }
511 else if(hNdimension == 3) {
512 hResult = BookHistogramByExample(hNumerator,"hQuotient","Result of Division of One Histogram By Another",XYZAxes);
513 }
514 else {
515 throw dqm_core::BadConfig( ERS_HERE, "DivideByHistogram", "Histograms with dimension greater than 3 are not supported");
516 }
517
518 for (int i=1; i <= nbinsx; i++) {
519 if( hDdimension == 1){
520 denominatorCont = hDenominator->GetBinContent(i);
521 denominatorError = hDenominator->GetBinError(i);
522 }
523 for (int j=1; j <= nbinsy; j++) {
524 if( hDdimension == 2){
525 denominatorCont = hDenominator->GetBinContent(i,j);
526 denominatorError = hDenominator->GetBinError(i,j);
527 }
528 if( hNdimension == 2){
529 numeratorCont = hNumerator->GetBinContent(i,j);
530 numeratorError = hNumerator->GetBinError(i,j);
531 if(denominatorCont != 0){
532 hResult->SetBinContent(i,j,numeratorCont/denominatorCont);
533 hResult->SetBinError(i,j,sqrt( ( pow(numeratorError,2)/pow(denominatorCont,2) )
534 + ( pow(denominatorError,2) * pow(numeratorCont,2) / pow(denominatorCont,4) ) ) );
535 }
536 }
537 else {
538 for (int k=1; k <= nbinsz; k++) {
539 numeratorCont = hNumerator->GetBinContent(i,j,k);
540 numeratorError = hNumerator->GetBinError(i,j,k);
541 if(denominatorCont != 0){
542 hResult->SetBinContent(i,j,k,numeratorCont/denominatorCont);
543 hResult->SetBinError(i,j,k,sqrt( ( pow(numeratorError,2)/pow(denominatorCont,2) )
544 + ( pow(denominatorError,2) * pow(numeratorCont,2) / pow(denominatorCont,4) ) ) );
545 }
546 }
547 }
548 }
549 }
550 }
551 else {
552 //Handle division for case where the numerator has lower dimension than the denominator
553 //There are only a few possibilities, hNdimension = 1 or 2, hDdimension = 2 or 3.
554
555 const TAxis* xax = hDenominator->GetXaxis();
556 int nbinsx = xax->GetNbins();
557 const TAxis* yax = hDenominator->GetYaxis();
558 int nbinsy = yax->GetNbins();
559 const TAxis* zax = hDenominator->GetZaxis();
560 int nbinsz = zax->GetNbins();
561
562 if( nbinsx != hNumerator->GetNbinsX() ) {
563 throw dqm_core::BadConfig( ERS_HERE, "number of bins in x-axis", "do not match");
564 }
565 if( (hNdimension == 2) && (nbinsy != hNumerator->GetNbinsY()) ) {
566 throw dqm_core::BadConfig( ERS_HERE, "number of bins in y-axis", "do not match");
567 }
568
569 double denominatorCont = 0;
570 double numeratorCont = 0;
571 double denominatorError = 0;
572 double numeratorError = 0;
573
574 if(hDdimension == 2) {
575 hResult = BookHistogramByExample(hDenominator,"hQuotient","Result of Division of One Histogram By Another",XYAxes);
576 }
577 else if(hDdimension == 3) {
578 hResult = BookHistogramByExample(hDenominator,"hQuotient","Result of Division of One Histogram By Another",XYZAxes);
579 }
580 else {
581 throw dqm_core::BadConfig( ERS_HERE, "DivideByHistogram", "Histograms with dimension greater than 3 are not supported");
582 }
583
584 // Always loop so at to handle over/underflows too
585 for (int i=1; i <= nbinsx; i++) {
586 if( hNdimension == 1){
587 numeratorCont = hNumerator->GetBinContent(i);
588 numeratorError = hNumerator->GetBinError(i);
589 }
590 for (int j=1; j <= nbinsy; j++) {
591 if( hNdimension == 2){
592 numeratorCont = hNumerator->GetBinContent(i,j);
593 numeratorError = hNumerator->GetBinError(i,j);
594 }
595 if( hDdimension == 2){
596 denominatorCont = hDenominator->GetBinContent(i,j);
597 denominatorError = hDenominator->GetBinError(i,j);
598 if(denominatorCont != 0){
599 hResult->SetBinContent(i,j,numeratorCont/denominatorCont);
600 hResult->SetBinError(i,j,sqrt( ( pow(numeratorError,2)/pow(denominatorCont,2) )
601 + ( pow(denominatorError,2) * pow(numeratorCont,2) / pow(denominatorCont,4) ) ) );
602 }
603 }
604 else {
605 for (int k=1; k <= nbinsz; k++) {
606 denominatorCont = hDenominator->GetBinContent(i,j,k);
607 denominatorError = hDenominator->GetBinError(i,j,k);
608 if(denominatorCont != 0){
609 hResult->SetBinContent(i,j,k,numeratorCont/denominatorCont);
610 hResult->SetBinError(i,j,sqrt( ( pow(numeratorError,2)/pow(denominatorCont,2) )
611 + ( pow(denominatorError,2) * pow(numeratorCont,2) / pow(denominatorCont,4) ) ) );
612 }
613 }
614 }
615 }
616 }
617 }
618 return hResult;
619}
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
TH1 * BookHistogramByExample(const TH1 *histogram, const std::string &name, const std::string &title, AxisType axisType)

◆ ExecuteNamedAlgorithm()

dqm_core::Result * dqm_algorithms::tools::ExecuteNamedAlgorithm ( const std::string & name,
const TObject & object,
const dqm_core::AlgorithmConfig & config )

Definition at line 647 of file AlgorithmHelper.cxx.

648{
649 // Function to find and execute the named algorithm
650 dqm_core::Algorithm* algorithm = 0;
651
652 if (name.compare("None") == 0 ) {
653 throw dqm_core::BadConfig( ERS_HERE,"no auxiliary algorithm specified", name);
654 }
655
656 try {
657 algorithm = dqm_core::AlgorithmManager::instance().getAlgorithm(name);
658 }
659 catch( dqm_core::Exception& ex ) {
660 throw dqm_core::BadConfig( ERS_HERE,"unable to get algorithm of this name", name);
661 }
662
663 return algorithm->execute(name,object,config);
664}
std::string algorithm
Definition hcg.cxx:87

◆ ExtractAlgorithmName()

std::string dqm_algorithms::tools::ExtractAlgorithmName ( const dqm_core::AlgorithmConfig & config)

Definition at line 622 of file AlgorithmHelper.cxx.

623{
624 // Function to extract the name of an auxiliary algorithm specified through an algorithm configuration parameter
625 // Uses syntax AuxAlgName::[Algorithm Name] = [value], where value is ignored.
626
627 std::string algNameTag = "AuxAlgName--";
628 std::string algName = "None";
629
630 if (config.getParameters().empty()){
631 throw dqm_core::BadConfig( ERS_HERE, "ExtractAlgorithmName","called with an empty config file");
632 }
633
634 std::map<std::string,double > confParams = config.getParameters();//Copy is necessary as AlgorithmConfig does not return map by reference (bug?)
635 for ( std::map<std::string,double >::const_iterator itr = confParams.begin();itr != confParams.end();++itr ) {
636 size_t stringPos;
637 if ( (stringPos = itr->first.find(algNameTag)) != std::string::npos ){
638 stringPos += algNameTag.length();
639 algName = itr->first.substr(stringPos);
640 }
641 }
642
643 return algName;
644}
const std::string & algName(ID id)
Converts a JetAlgorithmType::ID into a string.

◆ findOutliers()

void dqm_algorithms::tools::findOutliers ( std::vector< binContainer > & input,
double & mean,
double & scale,
int & nIn,
int nIterations,
double exponent,
double threshold,
double SBCF = 1.,
double nStop = 8. )

Definition at line 895 of file AlgorithmHelper.cxx.

896 {
897
898 int size = input.size();
899 if(size < 2) {
900 return;
901 }
902
903 if (nStop < 0) nStop = 0;
904 if (SBCF < 0) SBCF = 0;
905
906 std::vector<binContainer>::const_iterator cbegin = input.begin();
907 std::vector<binContainer>::const_iterator cend = input.end();
908
909 std::vector<binContainer>::iterator begin = input.begin();
910 std::vector<binContainer>::iterator end = input.end();
911
912 nIn = 0;
913 mean = 0;
914 scale = 0;
915
916 double newMean = 0;
917 double newScale = 0;
918 for ( int j = 0; j < nIterations ; j++ ) {
919 mean = newMean;
920 scale = newScale;
921
922 int newNin = 0;
923 double sum = 0;
924 //Loop to test, counting and summing elements that pass:
925 for ( std::vector<binContainer>::iterator it = begin; it != end; ++it ) {
926 //The Test:
927 it->test = ( (fabs(it->value - mean) < (threshold * scale) ) || (j==0) );
928 if ( it->test ) {
929 sum += it->value;
930 newNin++;
931 }
932 }
933 int nOut = size - newNin;
934 // Check if the iteration process is complete (or failed):
935 if (newNin < (2 + nStop + SBCF * nOut) ) {
936 return;
937 }
938 newMean = newNin ? (sum / newNin) : 0; // avoid to divide by zero (should never happen)
939 // Check if the iteration process has stabilized:
940 if ( (newNin == nIn) && (newMean == mean) ) {
941 return;
942 }
943 nIn = newNin;
944
945 // Calculate the scale parameter:
946 double scaleSum = 0;
947 for ( std::vector<binContainer>::const_iterator it = cbegin; it != cend; ++it ) {
948 if(it->test) {
949 scaleSum += pow( fabs(it->value - newMean) , exponent );
950 }
951 }
952 newScale = pow( scaleSum / (nIn - 1 - (SBCF * nOut) ), 1/exponent);
953 }
954 return;
955}
size_t size() const
Number of registered mappings.
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
const_iterator cend() const
Iterator at the end of the map.

◆ findOutliersUsingErrors()

void dqm_algorithms::tools::findOutliersUsingErrors ( std::vector< binContainer > & input,
double & mean,
double & meanError,
int & nIn,
double mindiff = 0,
int minNin = 4 )

Definition at line 958 of file AlgorithmHelper.cxx.

958 {
959
960
961 //Perform outlier determination using the bin errors and the relative pull on the mean,
962 // Taken from algorithm by Michele Petteni
963
964 if( minDiff < 0 ) minDiff = 0;
965 if( minNin < 2) minNin = 3;
966
967 nIn = input.size();
968 if(nIn < minNin) {
969 return;
970 }
971 meanError = 0;
972
973
974 std::vector<binContainer>::iterator begin = input.begin();
975 std::vector<binContainer>::iterator end = input.end();
976
977 //First pass: calucalate the mean:
978 double sum = 0;
979 double sumError2 = 0;
980 for( std::vector<binContainer>::iterator it = begin; it != end; ++it ) {
981 sum += it->value;
982 sumError2 += pow(it->error,2);
983 it->test = true;
984 }
985 mean = sum / nIn;
986 meanError = sqrt( sumError2/ nIn );
987 //Loop to tag and remove outliers:
988 while( nIn > 2 ) {
989
990 //Use map for ordering by distance from mean:
991 std::map<double,binContainer*> absDiffMap;
992 for( std::vector<binContainer>::iterator it = begin; it != end; ++it ) {
993 if( it->test ) {
994 absDiffMap[ fabs( it->value - mean ) ] = &(*it);
995 }
996 }
997
998 //If max(absDiff) < minDiff, this is not considered an outlier: we are done.
999 std::map<double,binContainer*>::iterator outlierCandidate = absDiffMap.end();
1000 --outlierCandidate;//<- the last element in a map is the largest.
1001 if( outlierCandidate->first < minDiff ) {
1002 return;
1003 }
1004
1005 //Find the mean and its error if we exclude the outlier candidate:
1006 double newMean = 0;
1007 double newMeanError = 0;
1008 sum = 0;
1009 for( std::map<double,binContainer*>::iterator it = absDiffMap.begin(); it != outlierCandidate; ++it) {
1010 sum += it->second->value;
1011 sumError2 += pow(it->second->error,2);
1012 }
1013 newMean = sum/(nIn - 1);
1014 newMeanError = sqrt( sumError2/(nIn - 2) );
1015
1016 double meanShift = fabs( mean - newMean );
1017
1018 //If the shift is bigger than the new error the candidate is an outlier: mark it and move on to the next one.
1019 if( meanShift > newMeanError ) {
1020 outlierCandidate->second->test = false;
1021 mean = newMean;
1022 meanError = newMeanError;
1023 nIn--;
1024 }
1025 else {
1026 return;
1027 }
1028 }
1029}

◆ FormatToSize()

void dqm_algorithms::tools::FormatToSize ( double value,
int size,
std::string & str,
bool showSign = true )

Definition at line 1540 of file AlgorithmHelper.cxx.

1540 {
1541 //Method to append size characters representing value to string str
1542
1543 char temp[35];
1544
1545 if( value == 0 ) {
1546 int prec = size - 2;
1547 if(prec < 0) prec = 0;
1548 sprintf(temp,"%.*f",prec,value);
1549 str += temp;
1550 return;
1551 }
1552
1553 std::string format;
1554 if(showSign) {
1555 format = "%+0*.*";
1556 }
1557 else {
1558 format = "%0*.*";
1559 }
1560
1561 int order = (int) floor( log10(fabs(value)) );
1562
1563 if( (size > 34) || (size < 1) || ((size < 5) && (order > size)) ) {
1564 size = 5;
1565 }
1566
1567 int prec = 0;
1568 if( (value > 0) && !showSign ) {
1569 if( ( (abs(order) > (size-3)) || (order < -2) ) && (size > 4) ) {
1570 prec = size-6;
1571 if(prec < 0) prec = 0;
1572 format += "e";
1573 }
1574 else if( order == -1 ) {
1575 prec = size - 2;
1576 if(prec < 0) prec = 0;
1577 format += "f";
1578 }
1579 else {
1580 prec = size - order -2;
1581 if(prec > (size - 2) ) prec = size - 2;
1582 if(prec < 0) prec = 0;
1583 format += "f";
1584 }
1585 }
1586 else {
1587 if( ( (abs(order) > (size-3)) || (order < -2) ) && (size > 4) ) {
1588 prec = size-7;
1589 if(prec < 0) prec = 0;
1590 format += "e";
1591 }
1592 else if( order == -1 ) {
1593 prec = size - 3;
1594 if(prec < 0) prec = 0;
1595 format += "f";
1596 }
1597 else {
1598 prec = size - order -3;
1599 if(prec > (size - 3) ) prec = size - 3;
1600 if(prec < 0) prec = 0;
1601 format += "f";
1602 }
1603 }
1604
1605 sprintf(temp,format.c_str(),size,prec,value);
1606
1607 str += temp;
1608}
order
Configure Herwig7.

◆ GetBinRange()

std::vector< int > dqm_algorithms::tools::GetBinRange ( const TH1 * histogram,
const std::map< std::string, double > & params )

The nested ternaries do the following. Suppose xmax (or ymax) happen to be a value that corresponds to the boundary of a bin. TAxis::FindBin then returns the bin for which the xmax is the lower edge of the bin. The nested ternaries prevent this happening by decrementing the bin number returned by TAxis::FindBin by 1.

Definition at line 387 of file AlgorithmHelper.cxx.

388{
389 std::vector<int> range;
390 const TAxis *xAxis = h->GetXaxis();
391 const TAxis *yAxis = h->GetYaxis();
392
393 if (h->GetDimension() > 2) {
394 throw dqm_core::BadConfig(ERS_HERE, h->GetName(), "histogram has more than 2 dimensions");
395 }
396
397 const double notFound = -99999;
398 const double xmin = dqm_algorithms::tools::GetFirstFromMap("xmin", params, notFound);
399 const double xmax = dqm_algorithms::tools::GetFirstFromMap("xmax", params, notFound);
400 const double ymin = dqm_algorithms::tools::GetFirstFromMap("ymin", params, notFound);
401 const double ymax = dqm_algorithms::tools::GetFirstFromMap("ymax", params, notFound);
402
408 const int xlow = (xmin == notFound) ? 1 : xAxis->FindBin(xmin);
409 const int xhigh = (xmax == notFound) ? xAxis->GetNbins() : (xAxis->GetBinLowEdge(xAxis->FindBin(xmax))== xmax) ? (xAxis->FindBin(xmax)-1) : xAxis->FindBin(xmax);
410 const int ylow = (ymin == notFound) ? 1 : yAxis->FindBin(ymin);
411 const int yhigh = (ymax == notFound) ? yAxis->GetNbins() : (yAxis->GetBinLowEdge(yAxis->FindBin(ymax))== ymax) ? (yAxis->FindBin(ymax)-1) : yAxis->FindBin(ymax);
412
413
414 if (xlow>xhigh) {
415 char temp[128];
416 sprintf(temp,"Bin Range Error: xmin = %.3g, xmax = %.3g",xmin,xmax);
417 throw dqm_core::BadConfig( ERS_HERE, h->GetName(), temp );
418 }
419 if (ylow>yhigh) {
420 char temp[128];
421 sprintf(temp,"Bin Range Error: xmin = %.3g, xmax = %.3g",xmin,xmax);
422 throw dqm_core::BadConfig( ERS_HERE, h->GetName(), temp );
423 }
424
425 range.push_back(xlow);
426 range.push_back(xhigh);
427 range.push_back(ylow);
428 range.push_back(yhigh);
429 return range;
430}
if(pathvar)
Header file for AthHistogramAlgorithm.
double xmax
Definition listroot.cxx:61
double ymin
Definition listroot.cxx:63
double xmin
Definition listroot.cxx:60
double ymax
Definition listroot.cxx:64
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)

◆ GetFirstFromMap() [1/4]

double dqm_algorithms::tools::GetFirstFromMap ( const std::string & paramName,
const std::map< std::string, double > & params )

Definition at line 346 of file AlgorithmHelper.cxx.

347{
348 std::map<std::string, double >::const_iterator it = params.find(paramName);
349 if (it == params.end()) {
350 throw dqm_core::BadConfig(ERS_HERE, "None", paramName); // this is the only difference between the two overloaded versions
351 } else {
352 return it->second;
353 }
354}

◆ GetFirstFromMap() [2/4]

double dqm_algorithms::tools::GetFirstFromMap ( const std::string & paramName,
const std::map< std::string, double > & params,
double defaultValue )

Definition at line 356 of file AlgorithmHelper.cxx.

357{
358 std::map<std::string, double >::const_iterator it = params.find(paramName);
359 if (it == params.end()) {
360 return defaultValue; // this is the only difference between the two overloaded versions
361 } else {
362 return it->second;
363 }
364}

◆ GetFirstFromMap() [3/4]

const std::string & dqm_algorithms::tools::GetFirstFromMap ( const std::string & paramName,
const std::map< std::string, std::string > & params )

Definition at line 367 of file AlgorithmHelper.cxx.

368{
369 std::map<std::string, std::string >::const_iterator it = params.find(paramName);
370 if (it == params.end()) {
371 throw dqm_core::BadConfig(ERS_HERE, "None", paramName); // this is the only difference between the two overloaded versions
372 } else {
373 return it->second;
374 }
375}

◆ GetFirstFromMap() [4/4]

const std::string & dqm_algorithms::tools::GetFirstFromMap ( const std::string & paramName,
const std::map< std::string, std::string > & params,
const std::string & defaultValue )

Definition at line 377 of file AlgorithmHelper.cxx.

378{
379 std::map<std::string, std::string >::const_iterator it = params.find(paramName);
380 if (it == params.end()) {
381 return defaultValue; // this is the only difference between the two overloaded versions
382 } else {
383 return it->second;
384 }
385}

◆ GetFitParamErrors()

std::map< std::string, double > dqm_algorithms::tools::GetFitParamErrors ( const TF1 * func)

Definition at line 51 of file AlgorithmHelper.cxx.

52{
53 std::map<std::string,double> fitParamErrors;
54
55 const int nPar =(int) func->GetNpar();
56
57 for ( int i = 0; i< nPar; ++i ) {
58 std::string name = func->GetParName( i );
59 fitParamErrors[name] = func->GetParError( i );
60 }
61 return fitParamErrors;
62}

◆ GetFitParams()

std::map< std::string, double > dqm_algorithms::tools::GetFitParams ( const TF1 * func)

Definition at line 37 of file AlgorithmHelper.cxx.

38{
39 std::map<std::string,double> fitparams;
40
41 const int nPar =(int) func->GetNpar();
42
43 for ( int i = 0; i< nPar; ++i ) {
44 std::string name = func->GetParName( i );
45 fitparams[name] = func->GetParameter( i );
46 }
47 return fitparams;
48}

◆ GetFitResult()

dqm_core::Result * dqm_algorithms::tools::GetFitResult ( const TF1 * func,
const dqm_core::AlgorithmConfig & config,
double minSig = 0 )

Definition at line 315 of file AlgorithmHelper.cxx.

316{
317 std::map<std::string, double > params = GetFitParams(func);
318 std::map<std::string, double > greenthresh=config.getGreenThresholds();
319 std::map<std::string,double>::const_iterator ait = greenthresh.find(chi2Str);
320 if ( ait != greenthresh.end() ) {
321 params[chi2Str]=func->GetChisquare()/ func->GetNDF();
322 }
323 double subtractfrommean = GetFirstFromMap( "SubtractFromMean", config.getParameters(), 0 );
324
325 params["Mean"] = params["Mean"] - subtractfrommean;
326 dqm_core::Result * result;
327 std::map<std::string, double > paramErrors = GetFitParamErrors(func);
328 if( minSig == 0) {
329 result = MakeComparisons( params, config.getGreenThresholds(), config.getRedThresholds() );
330 //result->tags_ = params;
331 }
332 else {
333 result = CompareWithErrors( params, paramErrors, config.getGreenThresholds(), config.getRedThresholds(), minSig );
334 }
335
336 result->tags_ = std::move(params);
337 for ( std::map<std::string,double>::const_iterator peItr = paramErrors.begin(); peItr != paramErrors.end(); ++peItr ) {
338 std::string errorName = peItr->first;
339 errorName += " Error";
340 result->tags_[errorName] = peItr->second;
341 }
342
343 return result;
344}
dqm_core::Result * CompareWithErrors(const std::map< std::string, double > &algparams, const std::map< std::string, double > &paramErrors, const std::map< std::string, double > &gthreshold, const std::map< std::string, double > &rthreshold, double minSig)
std::map< std::string, double > GetFitParamErrors(const TF1 *func)
dqm_core::Result * MakeComparisons(const std::map< std::string, double > &algparams, const std::map< std::string, double > &gthreshold, const std::map< std::string, double > &rthreshold)
std::map< std::string, double > GetFitParams(const TF1 *func)

◆ GetFromMap()

template<class T>
const T & dqm_algorithms::tools::GetFromMap ( const std::string & pname,
const std::map< std::string, T > & params )

Definition at line 114 of file AlgorithmHelper.h.

115 {
116 typename std::map<std::string,T>::const_iterator it = params.find( pname );
117 if ( it != params.end() ){
118 return it->second;
119 }else {
120 throw dqm_core::BadConfig( ERS_HERE, "None", pname );
121 }
122 }

◆ handleReference()

void dqm_algorithms::tools::handleReference ( const TObject & inputReference,
const TObject *& firstReference,
TObject *& secondReference )

Helper function used to handle complex reference histograms This function gets as input a reference object and checks if it is a collection of references, in this case extracts and returns the first element.

Parameters
inputReference: the original reference object
firstReference: the first element of the reference object, If the input reference is a TCollection, otherwise the inputReference itself
secondReference: the remaining reference(s), if the input collection has 2 elements the secondReference is a TObject, otherwise it is of the same class as the inputReference
Exceptions
dqm_core::BadRefHist: in case of wrong references

Definition at line 835 of file AlgorithmHelper.cxx.

838{
839 if ( ro.InheritsFrom("TH1") )
840 {
841 //Simple reference
842 firstReference = &ro;
843 secondReference = 0;
844 return;
845 }
846 else if ( ro.InheritsFrom("TCollection") )
847 {
848 //The reference is a collection of TObjects
849 const TCollection* coll = static_cast<const TCollection*>(&ro);
850 TIterator* it = coll->MakeIterator();
851 TObject* content = it->Next();
852 if ( content == 0 || content->InheritsFrom("TH1") == kFALSE )
853 {
854 throw dqm_core::BadRefHist(ERS_HERE,"handleReference"," Could not retreive reference");
855 }
856 firstReference = static_cast<TH1 *>(content);
857 Int_t csize = coll->GetEntries();
858 if ( csize == 1 )
859 {
860 //Only one element, no secondReference is available.
861 secondReference = 0;
862 return;
863 }
864 else if ( coll->GetEntries() == 2 )
865 {
866 //The collection is a pair, the second reference will be used directly
867 secondReference = it->Next();
868 return;
869 }
870 else
871 {
872 //This case is more complex, we basically want to create a new collection without the first element
873 secondReference = static_cast<TObject*>( (coll->IsA())->New() );//Create a new container of the same class as the original one
874 if ( secondReference == 0 || secondReference->InheritsFrom("TCollection") == kFALSE )
875 {
876 throw dqm_core::BadRefHist(ERS_HERE,"handleReference"," Could not retreive reference");
877 }
878 while ( (content = it->Next()) )//start from second element, since we already called Next()
879 {
880 static_cast<TCollection*>(secondReference)->Add(content);
881 }
882 return;
883 }
884 }
885 else
886 {
887 //This kind of reference is not supported
888 throw dqm_core::BadRefHist(ERS_HERE,"handleReference"," Could not retreive reference");
889 }
890}

◆ makeBinMap()

std::vector< std::vector< dqm_algorithms::tools::binContainer * > > dqm_algorithms::tools::makeBinMap ( std::vector< dqm_algorithms::tools::binContainer > & bins,
int ixmax,
int iymax,
int topology = CylinderX )

Definition at line 1226 of file AlgorithmHelper.cxx.

1226 {
1227
1228 std::vector<binContainer*> emptyVector;
1229 for(int iy = 0; iy <= iymax + 1; ++iy) {
1230 binContainer* emptyPointer = 0;
1231 emptyVector.push_back(emptyPointer);
1232 }
1233 std::vector<std::vector<binContainer*> > binMap;
1234 for(int ix = 0; ix <= ixmax + 1; ++ix) {
1235 binMap.push_back(emptyVector);
1236 }
1237 switch(topology) {
1238 //The mapping depends on the topology of the histogram.
1239 case CylinderX:
1240 //Cylinder About X-Axis (default topology), wraps max Y to min Y.
1241 //Connect iy == 1 with iy == iymax while leaving hard (null pointer) walls at ix = 0 and ix = imax+1:
1242 for (std::vector<binContainer>::iterator it = bins.begin(); it != bins.end(); ++it) {
1243 binMap[it->ix][it->iy] = &(*it);
1244 if(it->iy == 1){
1245 binMap[it->ix][iymax+1] = &(*it);
1246 }
1247 else if(it->iy == iymax){
1248 binMap[it->ix][0] = &(*it);
1249 }
1250 }
1251 break;
1252
1253 case CylinderY:
1254 //Cylinder About Y-Axis
1255 //Connect ix == 1 with ix == ixmax while leaving hard (null pointer) walls at iy = 0 and iy = imax+1:
1256 for (std::vector<binContainer>::iterator it = bins.begin(); it != bins.end(); ++it) {
1257 binMap[it->ix][it->iy] = &(*it);
1258 if(it->ix == 1){
1259 binMap[ixmax+1][it->iy] = &(*it);
1260 }
1261 else if(it->ix == ixmax){
1262 binMap[0][it->iy] = &(*it);
1263 }
1264 }
1265 break;
1266
1267 case Torus:
1268 //Torus:
1269 //Connect iy == 1 with iy == iymax and ix == 1 with ix == ixmax
1270 for (std::vector<binContainer>::iterator it = bins.begin(); it != bins.end(); ++it) {
1271 binMap[it->ix][it->iy] = &(*it);
1272 if(it->ix == 1){
1273 binMap[ixmax+1][it->iy] = &(*it);
1274 if(it->iy == 1){
1275 binMap[ixmax+1][iymax+1] = &(*it);
1276 }
1277 if(it->iy == iymax){
1278 binMap[ixmax+1][0] = &(*it);
1279 }
1280 }
1281 else if(it->ix == ixmax){
1282 binMap[0][it->iy] = &(*it);
1283 if(it->iy == 1){
1284 binMap[0][iymax+1] = &(*it);
1285 }
1286 if(it->iy == iymax){
1287 binMap[0][0] = &(*it);
1288 }
1289 }
1290 if(it->iy == 1){
1291 binMap[it->ix][iymax+1] = &(*it);
1292 }
1293 else if(it->iy == iymax){
1294 binMap[it->ix][0] = &(*it);
1295 }
1296 }
1297 break;
1298
1299 default:
1300 //Rectangle:
1301 //Treat the histogram as a simple rectangle, leaving null pointers at its boundaries:
1302 for (std::vector<binContainer>::iterator it = bins.begin(); it != bins.end(); ++it) {
1303 binMap[it->ix][it->iy] = &(*it);
1304 }
1305 }
1306 return binMap;
1307}
static const std::vector< std::string > bins

◆ MakeBinTag()

void dqm_algorithms::tools::MakeBinTag ( const binContainer & bin,
std::string & tag )

Definition at line 1526 of file AlgorithmHelper.cxx.

1526 {
1527 if(bin.error < 0) {
1528 return;
1529 }
1530 tag += "(eta,phi)[err]= (";
1531 FormatToSize(bin.x,6,tag,true);
1532 tag += ",";
1533 FormatToSize(bin.y,6,tag,true);
1534 tag += ")[";
1535 FormatToSize(bin.error,5,tag,false);
1536 tag += "]";
1537}
void FormatToSize(double value, int size, std::string &str, bool showSign=true)

◆ MakeComparisons()

dqm_core::Result * dqm_algorithms::tools::MakeComparisons ( const std::map< std::string, double > & algparams,
const std::map< std::string, double > & gthreshold,
const std::map< std::string, double > & rthreshold )

Definition at line 67 of file AlgorithmHelper.cxx.

70{
71
72 int red=0;
73 int yellow=0;
74 int green=0;
75
76
77 if (gthreshold.size() != rthreshold.size()) {
78 throw dqm_core::BadConfig( ERS_HERE, "MakeComparisons", "Need same number of Red and Green Threshold" );
79 }
80
81 if (gthreshold.size() == 0 ) {
82 throw dqm_core::BadConfig( ERS_HERE, "MakeComparisons", "No Threshold specified" );
83 }
84
85 std::map<std::string,double>::const_iterator g_iter;
86
87 for (g_iter=gthreshold.begin();g_iter!=gthreshold.end();++g_iter){
88
89 std::string name=(std::string) g_iter->first;
90 std::string findname=name;
91 double gtvalue=g_iter->second;
92
93 if (name == "AbsMean" )
94 findname="Mean";
95 if (name == "AbsXMean" )
96 findname="XMean";
97 if (name == "AbsYMean" )
98 findname="YMean";
99
100
101 std::map<std::string,double>::const_iterator ait = algparams.find(findname);
102 std::map<std::string,double>::const_iterator rit = rthreshold.find(name);
103 double rtvalue=-999;
104 double avalue=-999;
105
106 if ( ait != algparams.end() ) {
107 avalue=ait->second;
108 }
109 else {
110 throw dqm_core::BadConfig( ERS_HERE, "None",std::move(name) );
111 }
112
113 if ( rit != rthreshold.end() ) {
114 rtvalue=rit->second;
115 }
116 else {
117 throw dqm_core::BadConfig( ERS_HERE, "None",std::move(name) );
118 }
119
120 //cppcheck-suppress accessMoved
121 if (name == "AbsMean" || name == "AbsXMean" || name== "AbsYMean") {
122 avalue = fabs(avalue);
123 if (gtvalue < 0 || rtvalue <0 ) {
124 throw dqm_core::BadConfig( ERS_HERE, "None",std::move(name) );
125 }
126 }
127
128 ERS_DEBUG(1, name<<" :red value "<<rtvalue<<" :green value "<<gtvalue<<" :param value "<<avalue);
129
130 if (gtvalue < rtvalue) {
131
132 if (avalue <= gtvalue ){
133 ++green;
134 }else if(avalue < rtvalue){
135 ++yellow;
136 }else {
137 ++red;
138 }
139 }
140 else if (gtvalue > rtvalue) {
141 if (avalue >= gtvalue ){
142 ++green;
143 }else if(avalue > rtvalue){
144 ++yellow;
145 }else {
146 ++red;
147 }
148 }
149 else {
150 ERS_DEBUG(0, "red threshold (" << rtvalue << ") same as green threshold "<< gtvalue <<") for parameter " << name << ": can't evaluate result");
151 throw dqm_core::BadConfig( ERS_HERE, "None", std::move(name) );
152 }
153
154 }
155 ERS_DEBUG(1, "red: "<<red<<" yellow: "<<yellow<<" green: "<<green);
156
157
158 dqm_core::Result* result = new dqm_core::Result();
159
160 result->tags_ = algparams;
161
162
163 if (red>0) {
164 result->status_= dqm_core::Result::Red;
165 }else if (yellow>0) {
166 result->status_= dqm_core::Result::Yellow;
167 }else if (green>0) {
168 result->status_= dqm_core::Result::Green;
169 }
170
171 return result;
172}

◆ MergePastMinStat()

void dqm_algorithms::tools::MergePastMinStat ( std::vector< std::vector< tools::binContainer > > & strips,
int minStat )

Definition at line 1443 of file AlgorithmHelper.cxx.

1443 {
1444 //Method to merge neighboring vectors so that all non-empty vectors have a size of at least minStat
1445 //If two vectors are equally close to the vector with size < minstat, it will be merged with the one
1446 //with the smallest size.
1447
1448 if(strips.size() < 2) {
1449 return;
1450 }
1451
1452 std::vector<std::vector<tools::binContainer> >::iterator begining = strips.begin();
1453 std::vector<std::vector<tools::binContainer> >::iterator ending = strips.end();
1454 --ending;
1455
1456 while ( begining != ending ) {
1457 std::vector<std::vector<tools::binContainer> >::iterator minBinsItr = begining;
1458 for( std::vector<std::vector<tools::binContainer> >::iterator itr = begining; itr != (ending+1); ++itr ) {
1459 if( (!itr->empty()) && ((itr->size() < minBinsItr->size()) || minBinsItr->empty()) ) {
1460 minBinsItr = itr;
1461 }
1462 }
1463
1464 if( ((int)minBinsItr->size()) < minStat ) {
1465 if( minBinsItr == begining ) {
1466 //Merge right
1467 std::vector<std::vector<tools::binContainer> >::iterator mergeStripItr = minBinsItr;
1468 ++mergeStripItr;
1469 while( mergeStripItr->empty() ) {
1470 ++mergeStripItr;
1471 if( mergeStripItr == ending ) break;
1472 }
1473 mergeStripItr->insert( mergeStripItr->end(), minBinsItr->begin(), minBinsItr->end() );
1474 minBinsItr->clear();
1475 begining = mergeStripItr;
1476 }
1477 else if( minBinsItr == ending ) {
1478 //Merge left
1479 std::vector<std::vector<tools::binContainer> >::iterator mergeStripItr = minBinsItr;
1480 --mergeStripItr;
1481 while( mergeStripItr->empty() ) {
1482 --mergeStripItr;
1483 if( mergeStripItr == begining ) break;
1484 }
1485 mergeStripItr->insert( mergeStripItr->end(), minBinsItr->begin(), minBinsItr->end() );
1486 minBinsItr->clear();
1487 ending = mergeStripItr;
1488 }
1489 else {
1490 //Merge with the smallest of nearest neighbors:
1491 std::vector<std::vector<tools::binContainer> >::iterator mergeLeftItr = minBinsItr;
1492 std::vector<std::vector<tools::binContainer> >::iterator mergeRightItr = minBinsItr;
1493 --mergeLeftItr;
1494 ++mergeRightItr;
1495 while( mergeLeftItr->empty() && mergeRightItr->empty() ) {
1496 --mergeLeftItr;
1497 ++mergeRightItr;
1498 }
1499 if( mergeLeftItr->empty() ) {
1500 mergeRightItr->insert( mergeRightItr->end(), minBinsItr->begin(), minBinsItr->end() );
1501 minBinsItr->clear();
1502 }
1503 else if( mergeRightItr->empty() ) {
1504 mergeLeftItr->insert( mergeLeftItr->end(), minBinsItr->begin(), minBinsItr->end() );
1505 minBinsItr->clear();
1506 }
1507 else {
1508 if( mergeLeftItr->size() < mergeRightItr->size() ) {
1509 mergeLeftItr->insert( mergeLeftItr->end(), minBinsItr->begin(), minBinsItr->end() );
1510 minBinsItr->clear();
1511 }
1512 else {
1513 mergeRightItr->insert( mergeRightItr->end(), minBinsItr->begin(), minBinsItr->end() );
1514 minBinsItr->clear();
1515 }
1516 }
1517 }
1518 }
1519 else {
1520 break;
1521 }
1522 }
1523}

◆ ModifyHistogram()

void dqm_algorithms::tools::ModifyHistogram ( TH1 * histogram,
const dqm_core::AlgorithmConfig & config )

Definition at line 668 of file AlgorithmHelper.cxx.

669{
670 if (config.getParameters().empty()){
671 //Nothing to do
672 return;
673 }
674 std::map<std::string,double > confParams = config.getParameters();//Copy is necessary as AlgorithmConfig does not return map by reference
675 for ( std::map<std::string,double >::const_iterator itr = confParams.begin();itr != confParams.end();++itr ) {
676 if ( itr->first.find(multiplyHistoStr) != std::string::npos ){
677 histogram->Scale(itr->second);
678 continue;
679 }
680 if ( itr->first.find(divideHistoStr) != std::string::npos ){
681 histogram->Scale( (1./itr->second) );
682 continue;
683 }
684 size_t stringPos;
685
686 if ( (stringPos = itr->first.find(setHistoTitle)) != std::string::npos ){
687 stringPos += setHistoTitle.length();
688 histogram->SetTitle( (itr->first.substr(stringPos)).c_str() );
689 continue;
690 }
691 }
692}

◆ PublishBin()

void dqm_algorithms::tools::PublishBin ( const TH1 * histogram,
int xbin,
int ybin,
double content,
dqm_core::Result * result )

Definition at line 433 of file AlgorithmHelper.cxx.

433 {
434
435 std::string name = histogram->GetName();
436 double xbin = histogram->GetXaxis()->GetBinCenter(x);
437 std::string xbinlabel = (std::string)(histogram->GetXaxis()->GetBinLabel(x));
438 if (histogram->GetDimension() == 2){
439 double ybin = histogram->GetYaxis()->GetBinCenter(y);
440 std::string ybinlabel = (std::string)(histogram->GetYaxis()->GetBinLabel(y));
441 std::string badbin = Form("x-axis %s(%f) y-axis %s(%f))",xbinlabel.c_str(),xbin,ybinlabel.c_str(),ybin);
442 result->tags_[badbin.c_str()] = inputcont;
443 ERS_DEBUG(1,"x bin "<<xbin<<" y bin "<<ybin <<" value "<<inputcont);
444 } else {
445 std::string badbin = Form("%s(%f)",xbinlabel.c_str(),xbin);
446 result->tags_[badbin.c_str()] = inputcont;
447 ERS_DEBUG(1,"x bin "<<xbin<<" value "<<inputcont);
448 }
449}
#define y
#define x

◆ WorstCaseAddStatus()

dqm_core::Result::Status dqm_algorithms::tools::WorstCaseAddStatus ( dqm_core::Result::Status baseStatus,
dqm_core::Result::Status addedStatus,
float weight = 1.0 )

Definition at line 1312 of file AlgorithmHelper.cxx.

1312 {
1313 //-- Acts analogously to a logical OR -- (Red <-> True, etc.)
1314
1315 if(baseStatus == dqm_core::Result::Red) {
1316 return dqm_core::Result::Red;
1317 }
1318 //apply the "weight" to addedstatus only:
1319 if( weight <= 0 ) {
1320 return baseStatus;
1321 }
1322
1323 if( weight <= 0.25 ) {
1324 if( addedStatus == dqm_core::Result::Yellow ) {
1325 addedStatus = dqm_core::Result::Green;
1326 }
1327 }
1328 if( weight <= 0.5 ) {
1329 if( addedStatus == dqm_core::Result::Red) {
1330 addedStatus = dqm_core::Result::Yellow;
1331 }
1332 }
1333
1334 if(addedStatus == dqm_core::Result::Red) {
1335 return dqm_core::Result::Red;
1336 }
1337
1338 if(baseStatus == dqm_core::Result::Disabled) {
1339 return addedStatus;
1340 }
1341 if(addedStatus == dqm_core::Result::Disabled) {
1342 return baseStatus;
1343 }
1344 if(baseStatus == dqm_core::Result::Undefined) {
1345 return addedStatus;
1346 }
1347 if(addedStatus == dqm_core::Result::Undefined) {
1348 return baseStatus;
1349 }
1350
1351 if( (baseStatus == dqm_core::Result::Green) && (addedStatus == dqm_core::Result::Green) ) {
1352 return dqm_core::Result::Green;
1353 }
1354
1355 return dqm_core::Result::Yellow;
1356}