ATLAS Offline Software
Loading...
Searching...
No Matches
DivideBin.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
8
9#include <dqm_core/AlgorithmConfig.h>
12#include <dqm_core/AlgorithmManager.h>
13#include <TH1.h>
14#include <TH2.h>
15#include <TF1.h>
16#include <TClass.h>
17#include <ers/ers.h>
18
20
22
23{
24 dqm_core::AlgorithmManager::instance().registerAlgorithm("DivideBin", this);
25}
26
29{
30
31 return new DivideBin();
32}
33
34
35dqm_core::Result *
36dqm_algorithms::DivideBin::execute(const std::string & name,
37 const TObject & object,
38 const dqm_core::AlgorithmConfig & config)
39{
40 const TH1 * histogram;
41
42 if( object.IsA()->InheritsFrom( "TH1" ) ) {
43 histogram = static_cast<const TH1*>(&object);
44 if (histogram->GetDimension() > 2 ){
45 throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
46 }
47 } else {
48 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
49 }
50
51
52 double gthresho;
53 double rthresho;
54 int xbin_num;
55 int xbin_denom;
56 try {
57 xbin_num = (int)dqm_algorithms::tools::GetFirstFromMap( "TestBin", config.getParameters());
58 xbin_denom = (int)dqm_algorithms::tools::GetFirstFromMap( "RefBin", config.getParameters());
59 }
60 catch ( dqm_core::Exception & ex ) {
61 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
62 }
63
64 try {
65 gthresho = dqm_algorithms::tools::GetFromMap( "Threshold", config.getGreenThresholds() );
66 rthresho = dqm_algorithms::tools::GetFromMap( "Threshold", config.getRedThresholds() );
67 }
68 catch ( dqm_core::Exception & ex ) {
69 throw dqm_core::BadConfig(ERS_HERE,name,"Parameter: 'Threshold' is mandatory, cannot continue");
70
71 }
72
73 const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
74
75 const double minrefentries = dqm_algorithms::tools::GetFirstFromMap( "MinRefEntries", config.getParameters(), 1 );
76
77 if (histogram->GetEntries() < minstat ) {
78 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
79 result->tags_["InsufficientEntries"] = histogram->GetEntries();
80 return result;
81 }
82
83 // Get the denominator
84 double hdenom = histogram->GetBinContent(xbin_denom);
85
86 if ( minrefentries > 0 && hdenom < minrefentries) {
87 dqm_core::Result *result = new dqm_core::Result(dqm_core::Result::Undefined);
88 result->tags_["InsufficientRefEntries"] = hdenom;
89 return result;
90 }
91
92 // Get the numerator
93 double hnum = histogram -> GetBinContent(xbin_num);
94
95 double value = hnum/hdenom;
96
97 dqm_core::Result* result = new dqm_core::Result();
98 result->tags_["BinRatio"] = value;
99
100if (rthresho < gthresho){
101 if ( value >= gthresho ) {
102 result->status_ = dqm_core::Result::Green;
103 } else if ( value < rthresho ) {
104 result->status_ = dqm_core::Result::Red;
105 } else {
106 result->status_ = dqm_core::Result::Yellow;
107 }
108} else {
109 if ( value <= gthresho ) {
110 result->status_ = dqm_core::Result::Green;
111 } else if ( value > rthresho ) {
112 result->status_ = dqm_core::Result::Red;
113 } else {
114 result->status_ = dqm_core::Result::Yellow;
115 }
116}
117
118 return result;
119}
120
121
123 out<<"DivideBin : Performs the division of a particular bin by the total entries in that histogram "<< std::endl;
124 out<<"Optional Parameter : MinStat : Minimum histogram statistics needed to perform Algorithm"<< std::endl;
125 out<<"Optional Parameter : MinRefEntries : Minimum number of entries in reference bin needed to perform Algorithm"<< std::endl;
126 out<<"Mandatory parameter: TestBin: Index of the bin in x that should be tested\n"<< std::endl;
127 out<<"Mandatory parameter: RefBin: Index of the bin in x that should be used as a reference\n"<< std::endl;
128
129}
130
static dqm_algorithms::BinContentComp myInstance
file declares the dqm_algorithms::DivideBin class.
std::string histogram
Definition chains.cxx:52
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)
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition DivideBin.cxx:36
void printDescription(std::ostream &out)
#define IsA
Declare the TObject style functions.