ATLAS Offline Software
MDTPercentUnderThresh.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // **********************************************************************
6 // $Id: MDTPercentUnderThresh.cxx,v 1.0 2009/06/10 Valerio Consorti
7 // **********************************************************************
8 
9 
11 
12 #include <cmath>
13 #include <iostream>
14 #include <map>
15 
16 #include <TClass.h>
17 #include <TH1.h>
18 #include <TF1.h>
19 
20 #include "dqm_core/exceptions.h"
21 #include "dqm_core/AlgorithmConfig.h"
22 #include "dqm_core/AlgorithmManager.h"
23 #include "dqm_core/Result.h"
25 #include "ers/ers.h"
26 
27 
28 static dqm_algorithms::MDTPercentUnderThresh staticInstance;
29 
30 
31 namespace dqm_algorithms {
32 
33 // *********************************************************************
34 // Public Methods
35 // *********************************************************************
36 
38  : m_name("MDTpercent_under_thresh")
39 {
40  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
41 }
42 
43 
45 {
46 }
47 
48 
49 dqm_core::Algorithm*
51 {
52  return new MDTPercentUnderThresh(*this);
53 }
54 
55 
57 MDTPercentUnderThresh::execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
58 {
59  const TH1 * hist;
60 
61  if( object.IsA()->InheritsFrom( "TH1" ) ) {
62  hist = static_cast<const TH1*>(&object);
63  if (hist->GetDimension() >= 2 ){
64  throw dqm_core::BadConfig( ERS_HERE, name, "dimension >= 2 " );
65  }
66  } else {
67  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
68  }
69 
70  //Get Parameters and Thresholds
71  double minstat;
72  double thresh;
73  double greenTh;
74  double redTh;
75  try {
76  thresh = dqm_algorithms::tools::GetFirstFromMap( "Thresh", config.getParameters());
77  minstat = dqm_algorithms::tools::GetFirstFromMap("MinStat", config.getParameters(), 0);
78  redTh = dqm_algorithms::tools::GetFromMap( "Percent", config.getRedThresholds());
79  greenTh = dqm_algorithms::tools::GetFromMap( "Percent", config.getGreenThresholds() );
80  }
81  catch ( dqm_core::Exception & ex ) {
82  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
83  }
84 
85  //Check of statistics
86  if (hist->GetEntries() < minstat ) {
87  ERS_INFO("Histogram does not satisfy MinStat requirement " <<hist->GetName());
89  result->tags_["InsufficientEntries"] = hist->GetEntries();
90  return result;
91  }
92  ERS_DEBUG(1,"Statistics: "<< hist->GetEntries()<< " entries ");
93 
94  //Algo
95 
96  Double_t hit_under_th=0;
97 
98  Double_t N = hist->GetEntries();
99 
100  if(N == 0) {
102  result->tags_["Empty_Histogram_found_N_Entries"] = N;
104  return result;
105  };
106 
107  int i=0;
108 
109  do{
110  i++;
111  if(i>hist->GetNbinsX()){
113  result->tags_["Config_error_maximum_bin_exceed_looking_for_bin_number"] = i;
115  return result;
116  };
117  hit_under_th += hist->GetBinContent(i);
118  }while(hist->GetBinCenter(i)<thresh);
119 
120  double percent = 100 - 100*((double) hit_under_th)/((double) N);
121 
122  //Result
123 
125  result->tags_["Entries_above_thresh(%)"] = percent;
126 
127  if( percent >= greenTh ) {
128  result->status_ = dqm_core::Result::Green;
129  }
130  else if( percent <greenTh && percent>redTh ) {
131  result->status_ = dqm_core::Result::Yellow;
132  }
133  else {
134  result->status_ = dqm_core::Result::Red;
135  }
136 
137  // Return the result
138  return result;
139 }
140 
141 
142 void
144  std::string message;
145  message += "\n";
146  message += "Algorithm: \"" + m_name + "\"\n";
147  message += "Description: Compute the percent of entries above a threshold and and compare it with user defined green and red Threshold\n";
148  message += "Mandatory Parameters: Green/Red Threshold: Percent: Percent of the entries above threshold requested";
149  message += "Optional Parameters: MinStat = Minimum histogram statistics needed to perform Algorithm\n";
150  message += " thresh = threshold\n";
151  message += "\n";
152 
153  out << message;
154 }
155 
156 } // namespace dqm_algorithms
Undefined
@ Undefined
Definition: MaterialTypes.h:8
get_generator_info.result
result
Definition: get_generator_info.py:21
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
physval_make_web_display.thresh
thresh
Definition: physval_make_web_display.py:36
EvoMonitoring.percent
def percent(a, b)
Definition: EvoMonitoring.py:33
plotmaker.hist
hist
Definition: plotmaker.py:148
dqm_algorithms::MDTPercentUnderThresh::~MDTPercentUnderThresh
virtual ~MDTPercentUnderThresh()
Definition: MDTPercentUnderThresh.cxx:44
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
MDTPercentUnderThresh.h
ReweightUtils.message
message
Definition: ReweightUtils.py:15
dqm_algorithms::MDTPercentUnderThresh
Definition: MDTPercentUnderThresh.h:16
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
dqm_algorithms::MDTPercentUnderThresh::printDescription
virtual void printDescription(std::ostream &out)
Definition: MDTPercentUnderThresh.cxx:143
lumiFormat.i
int i
Definition: lumiFormat.py:85
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
python.handimod.Green
int Green
Definition: handimod.py:524
dqm_algorithms::MDTPercentUnderThresh::clone
virtual dqm_core::Algorithm * clone()
Definition: MDTPercentUnderThresh.cxx:50
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
dqm_algorithms::MDTPercentUnderThresh::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
Definition: MDTPercentUnderThresh.cxx:57
dqm_algorithms
Definition: AddReference.h:17
dqm_algorithms::MDTPercentUnderThresh::MDTPercentUnderThresh
MDTPercentUnderThresh()
Definition: MDTPercentUnderThresh.cxx:37
AlgorithmHelper.h
dqm_algorithms::tools::GetFromMap
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
Definition: AlgorithmHelper.h:114
pickleTool.object
object
Definition: pickleTool.py:30
dqm_algorithms::MDTPercentUnderThresh::m_name
std::string m_name
Definition: MDTPercentUnderThresh.h:28
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339