ATLAS Offline Software
Loading...
Searching...
No Matches
SideBand.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
10#include <TH1.h>
11#include <TClass.h>
12#include <dqm_core/AlgorithmConfig.h>
14#include <dqm_core/Result.h>
15#include <ers/ers.h>
16#include <string>
17#include <sstream>
18#include <dqm_core/AlgorithmManager.h>
19
20namespace
21{
22 dqm_algorithms::SideBand Absolute( "SideBand_Absolute" );
23 dqm_algorithms::SideBand Relative( "SideBand_Relative" );
24}
25
26dqm_algorithms::SideBand::SideBand(const std::string & name) : m_name(name) {
27 dqm_core::AlgorithmManager::instance().registerAlgorithm(name,this);
28}
29
33
34dqm_core::Result* dqm_algorithms::SideBand::execute(const std::string & name ,
35 const TObject & obj,
36 const dqm_core::AlgorithmConfig & config )
37{
38 const TH1* histo;
39 if ( obj.IsA()->InheritsFrom("TH2") || obj.IsA()->InheritsFrom("TH3") )
40 {
41 throw dqm_core::BadConfig( ERS_HERE , name , " dimension > 1 ");
42 }
43 if ( obj.IsA()->InheritsFrom("TH1") )
44 {
45 ERS_DEBUG(2,"Got TH1 called: "<<obj.GetName()<<" of type:"<<obj.IsA()->GetName());
46 histo=static_cast<const TH1*>(&obj);
47 }
48 else
49 {
50 throw dqm_core::BadConfig( ERS_HERE ,name , " does not inherit from TH1");
51 }
52 // Configure the DQ algorithm
53 const bool UseUnderFlow = static_cast<bool>(dqm_algorithms::tools::GetFirstFromMap("UseUnderFlow", config.getParameters(), 0));
54 const bool UseOverFlow = static_cast<bool>(dqm_algorithms::tools::GetFirstFromMap("UseOverFlow", config.getParameters(), 0));
55 // the following is a duplicate of dqm_algorithms::tools::GetBinRange, but with different parameter names
56 const double notFound = -99999;
57 const double xmin = dqm_algorithms::tools::GetFirstFromMap("Min", config.getParameters(), notFound);
58 const double xmax = dqm_algorithms::tools::GetFirstFromMap("Max", config.getParameters(), notFound);
59 const int minbin = (xmin == notFound) ? 1 : histo->GetXaxis()->FindBin(xmin);
60 const int maxbin = (xmax == notFound) ? histo->GetNbinsX() : histo->GetXaxis()->FindBin(xmax);
61
62 double grThr, reThr; // Green and Red thresholds
63 try
64 {
65 grThr = dqm_algorithms::tools::GetFromMap("Threshold",config.getGreenThresholds() );
66 reThr = dqm_algorithms::tools::GetFromMap("Threshold",config.getRedThresholds() );
67 }
68 catch ( dqm_core::Exception & ex )
69 {
70 throw dqm_core::BadConfig(ERS_HERE,name,"Paramter: 'Threshold' is mandatory, cannot continue");
71 }
72
73 if ( m_name== "SideBand_Relative" && (grThr>1.0 || reThr>1.0) )
74 //non sense case: compare fraction and threshold >100%
75 {
76 throw dqm_core::BadConfig(ERS_HERE,m_name,"Configuration Error: Threshold>100%");
77 }
78#if DEBUG_LEVEL > 1
79 std::stringstream configuration;
80 configuration
81 << " - UseUnderFlow = " << UseUnderFlow << " - UseOverFlow = " << UseOverFlow
82 << " - Min = " << xmin << " - Max = " << xmax
83 << " - Green Threshold = " << grThr << " - Red Threshold = " << reThr;
84 ERS_DEBUG(2,"Configuration:"<<configuration.str());
85#endif
86 // Just a translation in something more readable...
87 const bool AbsoluteValue = ( m_name == "SideBand_Absolute" );
88 Double_t tot = histo->Integral( 1, histo->GetNbinsX() );
89 Double_t inside = histo->Integral( minbin , maxbin );
90 if ( UseUnderFlow ) tot+=histo->GetBinContent(0);
91 if ( UseOverFlow ) tot+=histo->GetBinContent(histo->GetNbinsX()+1);
92 Double_t sideband = tot-inside;
93 if ( !AbsoluteValue ) { // Compare fraction of events in sideband
94 // if (tot != 0) {
95 if (tot > 0. || tot < 0.) {// should be safer than !=
96 sideband /= tot;
97 }
98 }
99 ERS_DEBUG(2,"Total:"<<tot<<" SideBand:"<<sideband);
100 dqm_core::Result * result = new dqm_core::Result;
101 result->tags_.insert(std::make_pair("TotalIntegral",tot));
102 result->tags_.insert(std::make_pair("SideBands",sideband));
103
104
105 if (reThr> grThr) {
106 if ( sideband>reThr ){
107 ERS_DEBUG(1,"[RED] Result : "<<sideband);
108 result->status_=dqm_core::Result::Red;
109 return result;
110 } else if ( sideband > grThr ){
111 ERS_DEBUG(1,"[YELLOW] Result : "<<sideband);
112 result->status_=dqm_core::Result::Yellow;
113 return result;
114 }
115 }else {
116 if ( sideband < reThr ){
117 ERS_DEBUG(1,"[RED] Result : "<<sideband);
118 result->status_=dqm_core::Result::Red;
119 return result;
120 } else if ( sideband < grThr ){
121 ERS_DEBUG(1,"[YELLOW] Result : "<<sideband);
122 result->status_=dqm_core::Result::Yellow;
123 return result;
124 }
125 }
126
127 ERS_DEBUG(1,"[GREEN] Result");
128 result->status_=dqm_core::Result::Green;
129 return result;
130}
131
133 std::stringstream msg;
134 msg<<m_name<<": Checks the integral of a histogram outside a specified range ";
135 if ( m_name=="SideBand_Absolute" )
136 msg<<" using an absolute threshold.";
137 else
138 msg<<" using a relative threshold.";
139 msg<<"\n\n";
140 out << msg.str() <<
141 "Parameter: UseUnderFlow: if != 0 include also underflow bin\n"
142 "Parameter: UseOverFlow: if != 0 include also overflow bin\n"
143 "Parameter: Min: Specify Lower limit (unset means full range)\n"
144 "Parameter: Max: Specify Upper limit (unset means full range)\n"
145 "Threshold: Threshold: How large or small the sidebands should be.\n"
146 " The comparison type (greater-than or less-than) depends on\n"
147 " the relative order of the green and red threshold value." << std::endl;
148}
#define Absolute(a)
file declares the dqm_algorithms::SideBand class.
SideBand(const std::string &name)
Definition SideBand.cxx:26
virtual dqm_core::Result * execute(const std::string &, const TObject &obj, const dqm_core::AlgorithmConfig &conf)
Definition SideBand.cxx:34
void printDescription(std::ostream &out)
Definition SideBand.cxx:132
virtual SideBand * clone()
Definition SideBand.cxx:30
double xmax
Definition listroot.cxx:61
double xmin
Definition listroot.cxx:60
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)
MsgStream & msg
Definition testRead.cxx:32