ATLAS Offline Software
MDTMLOverview.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: MDTMLOverview.cxx,v 1.0 2008/10/08 Valerio Consorti
7 // **********************************************************************
8 
10 
11 
12 
13 #include <TClass.h>
14 #include <TH1.h>
15 #include <TAxis.h>
16 #include <TF1.h>
17 #include <TProfile.h>
18 
19 #include "dqm_core/exceptions.h"
20 #include "dqm_core/AlgorithmConfig.h"
21 #include "dqm_core/AlgorithmManager.h"
22 #include "dqm_core/Result.h"
24 #include "ers/ers.h"
25 
26 #include <cmath>
27 #include <iostream>
28 #include <map>
29 #include <list>
30 #include <string>
31 #include <vector>
32 
33 static dqm_algorithms::MDTMLOverview staticInstance;
34 
35 
36 namespace dqm_algorithms {
37 
38 // *********************************************************************
39 // Public Methods
40 // *********************************************************************
41 
43  : m_name("MDTMLoverview")
44 {
45  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
46 }
47 
48 
50 {
51 }
52 
53 
56 {
57  return new MDTMLOverview(*this);
58 }
59 
60 
62 MDTMLOverview::execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
63 {
64  const TH1 * hist;
65  const TH1 * ref;
66 
67  if( object.IsA()->InheritsFrom( "TH1" ) ) {
68  hist = static_cast<const TH1*>(&object);
69  if (hist->GetDimension() >= 2 ){
70  throw dqm_core::BadConfig( ERS_HERE, name, "dimension >= 2 " );
71  }
72  } else {
73  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
74  }
75 
76  //Get Parameters and Thresholds
77  bool ref_y_n=0;
78  double thresh;
79  double minstat;
80  double greenTh;
81  double redTh;
82  try {
83  ref_y_n = dqm_algorithms::tools::GetFirstFromMap("ref", config.getParameters(), 0);
84  thresh = dqm_algorithms::tools::GetFirstFromMap("thresh", config.getParameters());
85  minstat = dqm_algorithms::tools::GetFirstFromMap("MinStat", config.getParameters(), 50);
86  redTh = dqm_algorithms::tools::GetFromMap( "Limits", config.getRedThresholds());
87  greenTh = dqm_algorithms::tools::GetFromMap( "Limits", config.getGreenThresholds() );
88  }
89  catch ( dqm_core::Exception & ex ) {
90  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
91  }
92 
93  //Get Reference Histo
94 
95  try {
96  ref = static_cast<const TH1*>( config.getReference() );
97  }
98  catch ( dqm_core::Exception & ex ) {
99  throw dqm_core::BadRefHist(ERS_HERE,name," Could not retrieve reference");
100  }
101 
102  if (hist->GetDimension() != ref->GetDimension() ) {
103  throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different dimension!" );
104  }
105  if (hist->GetNbinsX() != ref->GetNbinsX() ) {
106  throw dqm_core::BadRefHist( ERS_HERE, name, "Reference VS histo: Different bin number in X axis!" );
107  }
108 
109  //Check of statistics
110  if (hist->GetEntries() < minstat ) {
111  ERS_INFO("Histogram does not satisfy MinStat requirement " <<hist->GetName());
113  result->tags_["InsufficientEntries"] = hist->GetEntries();
114  return result;
115  }
116  ERS_DEBUG(1,"Statistics: "<< hist->GetEntries()<< " entries ");
117 
118 
119  //Algo
120 
121  int binX = hist->GetNbinsX();
122  //double x_center=0;
123 
124  std::vector<int> hist_buffer;
125  std::vector<int> ref_buffer;
126 
127  std::vector< double > new_empty_bins;
128  int count=0;
129 
130  for(int x_index=1; x_index<=binX; x_index++){
131  if( hist->GetBinContent(x_index) != 0 ) hist_buffer.push_back((int)hist->GetBinContent(x_index));
132  if(ref_y_n==1) {
133  if( ref->GetBinContent(x_index) != 0 ) ref_buffer.push_back((int)ref->GetBinContent(x_index));
134  }
135  };
136 
137 
138 
139  auto median=[](std::vector<int> & v)->int {
140  const auto midPoint = v.begin()+v.size()/2;
141  std::nth_element(v.begin(), midPoint, v.end());
142  return v[v.size()/2];
143  };
144 
145 
146  double percentThreshold = thresh*0.01;
147  const int mediana_hist = median(hist_buffer);
148 
149  if(ref_y_n==1) {
150  const int mediana_ref = median(ref_buffer);
151  for(int xi=1; xi<=binX; xi++){
152  if( hist->GetBinContent(xi) < mediana_hist*percentThreshold && ref->GetBinContent(xi) >= mediana_ref*percentThreshold){
153  count++;
154  new_empty_bins.push_back(hist->GetBinCenter(xi));
155  };
156  };
157  } else if(ref_y_n==0){
158  for(int xi=1; xi<=binX; xi++){
159  if( hist->GetBinContent(xi) < mediana_hist*percentThreshold){
160  count++;
161  new_empty_bins.push_back(hist->GetBinCenter(xi));
162  };
163  };
164  };
165 
166 
167  //double tot=binX;
168  //if(ref_y_n==0) tot=binX;
169 
170  //Tag generator
171 
173 
174  std::string message;
175  std::string eta="ETA_";
176  std::string ml="__ML";
177  char eta_num[3];
178  std::string ml_num;
179  double num_ml_off=1;
180  int counter=0;
181 
182  int empty_bin_number=new_empty_bins.size();
183 
184  for(int i=0; i<empty_bin_number; i++){
185  counter=-1;
186  do{
187  counter++;
188  if(counter>=20) break;
189  }while(std::abs(counter-new_empty_bins[i])>0.3);
190 
191  snprintf(eta_num,sizeof(eta_num),"%d",counter);
192  if( (counter-new_empty_bins[i])>=0)ml_num="1";
193  if( (counter-new_empty_bins[i])<0) ml_num="2";
194  message=eta+(std::string)eta_num+ml+ml_num;
195  result->tags_[message]=num_ml_off;
196  };
197 
198  //Result
199 
200  result->tags_["00-number_of_off_ML"] = count;
201 
202  if (count<greenTh) {
203  result->status_ = dqm_core::Result::Green;
204  ERS_DEBUG(1,"Green");
205  } else if ( count>=greenTh && count<redTh ) {
206  result->status_ = dqm_core::Result::Yellow;
207  ERS_DEBUG(1,"Yellow");
208  } else if (count>=redTh) {
209  result->status_ = dqm_core::Result::Red;
210  ERS_DEBUG(1,"Red");
211  }
212  return result;
213 }
214 
215 
216 void
218 {
219  std::string message;
220  message += "\n";
221  message += "Algorithm: \"" + m_name + "\"\n";
222  message += "Description: compare the histo with reference and check if there are any ML switched off\n";
223  message += "Mandatory Green/Red Threshold: Limits: number of new ML switched off while are on in reference\n";
224  message += " thresh = % of the mean entries per ML under which the algo will set ML off\n";
225  message += "Optional Parameters: MinStat = Minimum histogram statistics needed to perform Algorithm\n";
226  message += " ref = Bool value: 1 if you want perform the check comparing with ref\n";
227  message += " 0 if you want perform the check without the comparison with ref\n";
228  message += "\n";
229 
230  out << message;
231 }
232 
233 } // 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:35
dqm_algorithms::MDTMLOverview::MDTMLOverview
MDTMLOverview()
Definition: MDTMLOverview.cxx:42
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
plotmaker.hist
hist
Definition: plotmaker.py:148
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
InDet::median
float median(std::vector< float > &Vec)
Definition: BTagVrtSec.cxx:35
dqm_algorithms::MDTMLOverview::printDescription
virtual void printDescription(std::ostream &out)
Definition: MDTMLOverview.cxx:217
ReweightUtils.message
message
Definition: ReweightUtils.py:15
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
dqm_algorithms::MDTMLOverview::m_name
std::string m_name
Definition: MDTMLOverview.h:29
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
dqm_algorithms::MDTMLOverview::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
Definition: MDTMLOverview.cxx:62
MDTMLOverview.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
python.handimod.Green
int Green
Definition: handimod.py:524
dqm_algorithms::MDTMLOverview::clone
virtual dqm_core::Algorithm * clone()
Definition: MDTMLOverview.cxx:55
dqm_algorithms::MDTMLOverview::~MDTMLOverview
virtual ~MDTMLOverview()
Definition: MDTMLOverview.cxx:49
Trk::binX
@ binX
Definition: BinningType.h:47
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
python.PyAthena.v
v
Definition: PyAthena.py:157
dqm_algorithms
Definition: AddReference.h:17
ref
const boost::regex ref(r_ef)
TH1
Definition: rootspy.cxx:268
dqm_algorithms::MDTMLOverview
Definition: MDTMLOverview.h:16
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
test_pyathena.counter
counter
Definition: test_pyathena.py:15
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339