ATLAS Offline Software
Loading...
Searching...
No Matches
BinsDiffFromPreviousLBs.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9#include <dqm_core/AlgorithmConfig.h>
12#include <dqm_core/AlgorithmManager.h>
13
14#include <TH1.h>
15#include <TF1.h>
16#include <TClass.h>
17#include <cmath>
18#include <algorithm>
19
20#include <iostream>
21
22
24
26{
27 dqm_core::AlgorithmManager::instance().registerAlgorithm("BinsDiffFromPreviousLBs", this);
28}
29
33
40
42{
43 if (lbs.empty()) return false;
44 if (lbs.size() == 1) return true;
45 const bool monotonic = std::is_sorted(lbs.begin(), lbs.end());
46 const bool withinRange = (lbs.back() - lbs.front() + 1) == std::ssize(lbs);
47 return monotonic and withinRange;
48}
49
50
51dqm_core::Result *
53 const TObject& object,
54 const dqm_core::AlgorithmConfig& config )
55{
56 const TH1* histogram = nullptr;
57
58 if( object.IsA()->InheritsFrom( "TH1" ) ) {
59 histogram = static_cast<const TH1*>(&object);
60 if (histogram->GetDimension() > 2 ){
61 throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
62 }
63 } else {
64 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
65 }
66
67 const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
68 const double ignoreval = dqm_algorithms::tools::GetFirstFromMap( "ignoreval", config.getParameters(), -99999);
69 bool greaterthan = (bool) dqm_algorithms::tools::GetFirstFromMap( "GreaterThan", config.getParameters(), 0);
70 bool lessthan = (bool) dqm_algorithms::tools::GetFirstFromMap( "LessThan", config.getParameters(), 0);
71 const bool publish = (bool) dqm_algorithms::tools::GetFirstFromMap( "PublishBins", config.getParameters(), 0);
72 const int maxpublish = (int) dqm_algorithms::tools::GetFirstFromMap( "MaxPublish", config.getParameters(), 20);
73 const double maxdiffabs = dqm_algorithms::tools::GetFirstFromMap( "MaxDiffAbs", config.getParameters(), -1);
74
75 if (greaterthan && lessthan) {
76 ERS_INFO("Both GreaterThan and LessThan parameters set: Will check for for both");
77 greaterthan = false;
78 lessthan = false;
79 }
80
81 if ( histogram->GetEntries() < minstat ) {
82 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
83 result->tags_["InsufficientEntries"] = histogram->GetEntries();
84 return result;
85 }
86
87 double bin_threshold;
88 double nsigmas;
89 double gthreshold;
90 double rthreshold;
91 try {
92 nsigmas = dqm_algorithms::tools::GetFirstFromMap( "NSigma", config.getParameters() );
93 bin_threshold = dqm_algorithms::tools::GetFirstFromMap( "BinThreshold", config.getParameters() );
94 rthreshold = dqm_algorithms::tools::GetFromMap( "NBins", config.getRedThresholds() );
95 gthreshold = dqm_algorithms::tools::GetFromMap( "NBins", config.getGreenThresholds() );
96 }
97 catch( dqm_core::Exception & ex ) {
98 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
99 }
100
101 TH1* resulthisto = nullptr;
102 if (histogram->InheritsFrom("TH2")) {
103 resulthisto=(TH1*)(histogram->Clone());
104 } else if (histogram->InheritsFrom("TH1")) {
105 resulthisto=(TH1*)(histogram->Clone());
106 } else {
107 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
108 }
109
110 resulthisto->Reset();
111
112 std::vector<int> range=dqm_algorithms::tools::GetBinRange(histogram, config.getParameters());
113
114 std::vector<int> LBs;
115 dqm_core::Result* result = new dqm_core::Result();
116
117 for ( int k = range[0]; k <= range[1]; ++k ) {
118 for ( int l = range[2]; l <= range[3]; ++l ) {
119 double inputcont = histogram->GetBinContent(k,l);
120 double inputerr = histogram->GetBinError(k,l);
121 double diff=inputcont - bin_threshold;
122 if (inputcont == ignoreval) continue;
123 if (inputerr != 0){
124 double sigma=diff/inputerr;
125 if (greaterthan && diff < 0. ) continue;
126 if (lessthan && diff > 0. ) continue;
127 if ( (std::abs(sigma) > nsigmas) && (std::abs(diff) > maxdiffabs) ) {
128 resulthisto->SetBinContent(k,l,inputcont);
129 LBs.push_back(k);
130 if (publish && (int)LBs.size() < maxpublish){
132 }
133 }
134 }
135
136 }
137 }
138
139 int count = LBs.size();
140
141 result->tags_["NBins"] = count;
142 result->object_ = boost::shared_ptr<TObject>(resulthisto);
143
144 ERS_DEBUG(1,"Number of bins " << nsigmas << " Sigma away from average of "<< bin_threshold << " is " << count);
145 ERS_DEBUG(1,"Green threshold: "<< gthreshold << " bin(s); Red threshold : " << rthreshold << " bin(s) ");
146
147 if ( count <= gthreshold ) {
148 result->status_ = dqm_core::Result::Green;
149 } else if ( count < rthreshold ) {
150 result->status_ = dqm_core::Result::Yellow;
151 } else {
152 result->status_ = dqm_core::Result::Red;
153 }
154 return result;
155
156}
157void
159{
160
161 out<<"BinsDiffFromPreviousLBs: Checks for number of bins (subsequent LBs) NSigma within threshold \n"<<std::endl;
162
163 out<<"Mandatory Parameter: BinThreshold: Look for bins NSigna away from threshold \n"<<std::endl;
164 out<<"Mandatory Parameter: NSigma: Number of sigma each bin must be within average bin value\n"<<std::endl;
165 out<<"Mandatory Green/Red Threshold: NBins: number of bins N sigma away from average to give Green/Red result\n"<<std::endl;
166
167 out<<"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm"<<std::endl;
168 out<<"Optional Parameter: doCheckOnSingleLB: check done not necessarly on subsequent bins (set to 0)"<<std::endl;
169 out<<"Optional Parameter: ignoreval: valued to be ignored for calculating average"<<std::endl;
170 out<<"Optional Parameter: GreaterThan: check only for bins which are GreaterThan average (set to 1)"<<std::endl;
171 out<<"Optional Parameter: LessThan: check only for bins which are LessThan average (set to 1)"<<std::endl;
172 out<<"Optional Parameter: PublishBins: Save bins which are different from average in Result (set to 1)"<<std::endl;
173 out<<"Optional Parameter: MaxPublish: Max number of bins to save (default 20)"<<std::endl;
174 out<<"Optional Parameter: MaxDiffAbs: test fails if NBins more than NSigma away and NBins more than MaxDiffAbs (absolut difference) away from average"<<std::endl;
175
176}
177
static dqm_algorithms::BinContentComp myInstance
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
std::string histogram
Definition chains.cxx:52
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
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)
bool areConsecutive(const std::vector< int > &lbVec)
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
#define IsA
Declare the TObject style functions.