ATLAS Offline Software
Loading...
Searching...
No Matches
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
8
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
21
23{
24 dqm_core::AlgorithmManager::instance().registerAlgorithm("BinContentDump", this);
25}
26
30
35
36dqm_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) {
54 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
55 result->tags_["InsufficientEntries"] = histogram->GetEntries();
56 return result;
57 }
58
59 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Green);
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}
static dqm_algorithms::BinContentComp myInstance
std::string histogram
Definition chains.cxx:52
std::string label(const std::string &format, int i)
Definition label.h:19
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
virtual void printDescription(std::ostream &out)
#define IsA
Declare the TObject style functions.