ATLAS Offline Software
BinContentDump.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 #include "dqm_core/AlgorithmManager.h"
10 #include "dqm_core/AlgorithmConfig.h"
13 #include "TH1.h"
14 #include "TClass.h"
15 #include "ers/ers.h"
16 
17 #include <string>
18 #include <sstream>
19 
20 static dqm_algorithms::BinContentDump myInstance;
21 
23 {
24  dqm_core::AlgorithmManager::instance().registerAlgorithm("BinContentDump", this);
25 }
26 
28 {
29 }
30 
32 {
33  return new BinContentDump();
34 }
35 
36 dqm_core::Result *dqm_algorithms::BinContentDump::execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config)
37 {
38  const TH1 *histogram;
39 
40  if (object.IsA()->InheritsFrom("TH1")) {
41  histogram = static_cast<const TH1*>(&object);
42  if (histogram->GetDimension() > 2) {
43  throw dqm_core::BadConfig(ERS_HERE, name, "dimension > 2");
44  }
45  } else {
46  throw dqm_core::BadConfig(ERS_HERE, name, "does not inherit from TH1");
47  }
48 
49  const double minstat = dqm_algorithms::tools::GetFirstFromMap("MinStat", config.getParameters(), -1);
50  const unsigned int publishType = static_cast<unsigned int>(dqm_algorithms::tools::GetFirstFromMap("PublishType", config.getParameters(), 1));
51  // const int maxpublish = (int) dqm_algorithms::tools::GetFirstFromMap("MaxPublish", config.getParameters(), 20);
52 
53  if (histogram->GetEntries() < minstat) {
55  result->tags_["InsufficientEntries"] = histogram->GetEntries();
56  return result;
57  }
58 
60 
61  for (int i = 1; i <= histogram->GetNbinsX(); ++i) {
62  const double binContent = histogram->GetBinContent(i);
63  const double binError = histogram->GetBinError(i);
64  std::string label = histogram->GetXaxis()->GetBinLabel(i);
65 
66  // Check if user has defined a minimum value on this bin
67  const double undefined = -99999;
68  const double binThreshold = dqm_algorithms::tools::GetFirstFromMap(label, config.getParameters(), undefined);
69  if ((binThreshold != undefined) && (binContent < binThreshold)) result->status_ = dqm_core::Result::Red;
70 
71  if (label.empty()) {
72  std::ostringstream oss;
73  oss << "Bin_" << i;
74  label = oss.str();
75  }
76 
77  if (publishType & 0x01) result->tags_[label] = binContent;
78  if (publishType & 0x02) result->tags_[label + "Error"] = binError;
79  }
80  return result;
81 }
83 {
84  out << "BinContentDump: Dumps the contents of all bins, labelled either with their bin label or with \"Bin_N\". Returns green status.\n"
85  "Optional parameters: <label>: The bin with this label must be greater than the given value, otherwise the algorithm returns red status.\n"
86  "Optional parameter: PublishType: What to publish. 0 = nothing, 1 = bin contents (default), 2 = bin errors, 3 = both\n"
87  "Thresholds: None." << std::endl;
88 }
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
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
BinContentDump.h
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::BinContentDump::printDescription
virtual void printDescription(std::ostream &out)
Definition: BinContentDump.cxx:82
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::BinContentDump::~BinContentDump
~BinContentDump()
Definition: BinContentDump.cxx:27
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::BinContentDump::BinContentDump
BinContentDump()
Definition: BinContentDump.cxx:22
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
AlgorithmHelper.h
dqm_algorithms::BinContentDump::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: BinContentDump.cxx:36
pickleTool.object
object
Definition: pickleTool.py:30
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
dqm_algorithms::BinContentDump::clone
BinContentDump * clone()
Definition: BinContentDump.cxx:31
histogram
std::string histogram
Definition: chains.cxx:52
dqm_algorithms::BinContentDump
Definition: BinContentDump.h:15