ATLAS Offline Software
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 
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 
20 namespace
21 {
22  dqm_algorithms::SideBand Absolute( "SideBand_Absolute" );
23  dqm_algorithms::SideBand Relative( "SideBand_Relative" );
24 }
25 
26 dqm_algorithms::SideBand::SideBand(const std::string & name) : m_name(name) {
27  dqm_core::AlgorithmManager::instance().registerAlgorithm(name,this);
28 }
29 
31  return new SideBand( m_name );
32 }
33 
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);
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");
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 }
SideBand.h
get_generator_info.result
result
Definition: get_generator_info.py:21
dqm_algorithms::SideBand
Definition: SideBand.h:40
dqm_algorithms::SideBand::SideBand
SideBand(const std::string &name)
Definition: SideBand.cxx:26
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
xmin
double xmin
Definition: listroot.cxx:60
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
python.handimod.Green
int Green
Definition: handimod.py:524
LB_AnalMapSplitter.tot
tot
Definition: LB_AnalMapSplitter.py:46
Absolute
#define Absolute(a)
Definition: PolygonTriangulator.cxx:270
python.handimod.Red
Red
Definition: handimod.py:551
dqm_algorithms::SideBand::printDescription
void printDescription(std::ostream &out)
Definition: SideBand.cxx:132
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Trk::inside
@ inside
Definition: PropDirection.h:29
TH1
Definition: rootspy.cxx:268
xmax
double xmax
Definition: listroot.cxx:61
AlgorithmHelper.h
dqm_algorithms::tools::GetFromMap
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
Definition: AlgorithmHelper.h:114
plotBeamSpotCompare.histo
histo
Definition: plotBeamSpotCompare.py:415
python.PyAthena.obj
obj
Definition: PyAthena.py:135
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
dqm_algorithms::SideBand::execute
virtual dqm_core::Result * execute(const std::string &, const TObject &obj, const dqm_core::AlgorithmConfig &conf)
Definition: SideBand.cxx:34
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
dqm_algorithms::SideBand::clone
virtual SideBand * clone()
Definition: SideBand.cxx:30