ATLAS Offline Software
Loading...
Searching...
No Matches
TileBinsOutRange.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <dqm_core/AlgorithmConfig.h>
8#include <TH1.h>
9#include <TProfile.h>
10#include <TProfile2D.h>
11#include <TClass.h>
12#include <ers/ers.h>
13
14#include <dqm_core/AlgorithmManager.h>
15
16namespace {
18}
19
20namespace dqm_algorithms {
21
23 dqm_core::AlgorithmManager::instance().registerAlgorithm(m_name, this);
24}
25
26
30
31
32dqm_core::Result* TileBinsOutRange::execute(const std::string& name,
33 const TObject& object,
34 const dqm_core::AlgorithmConfig& config) {
35
36 const TH1* histogram = nullptr;
37
38 if(object.IsA()->InheritsFrom( "TH1" )) {
39 histogram = static_cast<const TH1*>(&object);//type already checked in preceding line
40 if (histogram->GetDimension() > 2 ){
41 throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
42 }
43 } else {
44 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH2");
45 }
46
47 const bool publish = static_cast<bool>(dqm_algorithms::tools::GetFirstFromMap( "PublishBins", config.getParameters(), 0));
48 const bool publishHistogram = static_cast<bool>(dqm_algorithms::tools::GetFirstFromMap( "PublishHistogram", config.getParameters(), 1));
49 const int maxPublish = static_cast<int>(dqm_algorithms::tools::GetFirstFromMap( "MaxPublish", config.getParameters(), 20));
50 const double minStat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
51 const double ignoreValue = dqm_algorithms::tools::GetFirstFromMap( "IgnoreValue", config.getParameters(), -99999);
52
53 const TProfile* profile(nullptr);
54 const TProfile2D* profile2D(nullptr);
55 const double minBinEntries = dqm_algorithms::tools::GetFirstFromMap( "MinBinEntries", config.getParameters(), -1);
56 if(minBinEntries > 0) {
57 if (object.InheritsFrom("TProfile")) profile = dynamic_cast<const TProfile*>(&object);
58 else if (object.InheritsFrom("TProfile2D")) profile2D = dynamic_cast<const TProfile2D*>(&object);
59 }
60
61 if (histogram->GetEntries() < minStat ) {
62 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
63 result->tags_["InsufficientEntries"] = histogram->GetEntries();
64 return result;
65 }
66
67 double minValue;
68 double maxValue;
69 double redThreshold;
70 double greenThreshold;
71 try {
72 minValue = dqm_algorithms::tools::GetFromMap( "MinValue", config.getGreenThresholds() );
73 maxValue = dqm_algorithms::tools::GetFromMap( "MaxValue", config.getGreenThresholds() );
74 greenThreshold = dqm_algorithms::tools::GetFromMap("NBins", config.getGreenThresholds());
75 redThreshold = dqm_algorithms::tools::GetFromMap("NBins", config.getRedThresholds());
76 } catch( dqm_core::Exception & ex ) {
77 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
78 }
79
80 TH1* resultHistogram = nullptr;
81 if (publishHistogram) {
82 if (histogram->InheritsFrom("TH1")) {
83 resultHistogram = static_cast<TH1*>(histogram->Clone());//type already checked
84 } else {
85 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
86 }
87 resultHistogram->Reset();
88 }
89
90 int nBins = 0;
91 int nSkippedBins = 0;
92 dqm_core::Result* result = new dqm_core::Result();
93 std::vector<int> range = dqm_algorithms::tools::GetBinRange(histogram, config.getParameters());
94 for (int i = range[0]; i <= range[1]; ++i) {
95 for (int j = range[2]; j <= range[3]; ++j) {
96
97 if (minBinEntries > 0) {
98 int bin = histogram->GetBin(i, j);
99 if (profile) {
100 if (profile->GetBinEntries(bin) < minBinEntries) {
101 ++nSkippedBins;
102 continue;
103 }
104 } else if (profile2D) {
105 if (profile2D->GetBinEntries(bin) < minBinEntries) {
106 ++nSkippedBins;
107 continue;
108 }
109 }
110 }
111
112 double binValue = histogram->GetBinContent(i, j);
113 if((binValue == ignoreValue) || (binValue > minValue && binValue < maxValue )) continue;
114
115 ++nBins;
116 if (resultHistogram){
117 resultHistogram->SetBinContent(i, binValue);
118 if (publish && nBins < maxPublish) {
120 }
121 }
122 }
123 }
124
125 ERS_DEBUG(1,"Number of bad bins is " << nBins );
126 ERS_DEBUG(1,"Green threshold: " << greenThreshold << " bin(s); Red threshold : " << redThreshold << " bin(s) ");
127
128 result->tags_["NBins"] = nBins;
129 result->tags_["NSkippedBins"] = nSkippedBins;
130 if (resultHistogram) result->object_ = boost::shared_ptr<TObject>(resultHistogram);
131
132 if (greenThreshold > redThreshold) {
133 if (nBins >= greenThreshold) {
134 result->status_ = dqm_core::Result::Green;
135 } else if (nBins > redThreshold) {
136 result->status_ = dqm_core::Result::Yellow;
137 } else {
138 result->status_ = dqm_core::Result::Red;
139 }
140 } else {
141 if (nBins <= greenThreshold) {
142 result->status_ = dqm_core::Result::Green;
143 } else if (nBins < redThreshold) {
144 result->status_ = dqm_core::Result::Yellow;
145 } else {
146 result->status_ = dqm_core::Result::Red;
147 }
148 }
149
150 return result;
151}
152
153void TileBinsOutRange::printDescription(std::ostream& out) {
154
155 out << m_name << ": Check number of bins which are out of range (MinValue, MaxValue) " << std::endl;
156 out << "Mandatory Green Threshold: MinValue: minimum value of range" << std::endl;
157 out << "Mandatory Green Threshold: MaxValue: maximum value of range" << std::endl;
158 out << "Mandatory Green/Red Threshold: NBins: Number of non-empty bins to give Green/Red result\n" << std::endl;
159 out << "Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm" << std::endl;
160 out << "Optional Parameter: IgnoreValue: valued to be ignored for being processed" << std::endl;
161 out << "Optional Parameter: MaxPublish: Max number of bins to save (default 20)" << std::endl;
162 out << "Optional Parameter: MinBinEntries: Minimum bin entries in profile histogram needed to check this bin (by default: -1)" << std::endl;
163
164}
165
166}
static dqm_algorithms::BinContentComp myInstance
#define maxValue(current, test)
#define minValue(current, test)
std::string histogram
Definition chains.cxx:52
void printDescription(std::ostream &out)
virtual TileBinsOutRange * clone() override
virtual dqm_core::Result * execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config) override
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
void PublishBin(const TH1 *histogram, int xbin, int ybin, double content, dqm_core::Result *result)
#define IsA
Declare the TObject style functions.