ATLAS Offline Software
CTP_AllBinsAreEmptyExceptZero.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <cmath>
8 #include <iostream>
9 #include <map>
10 #include <vector>
11 #include <string>
12 
13 #include <TClass.h>
14 #include <TH1.h>
15 #include <TH2.h>
16 
17 #include "dqm_core/exceptions.h"
18 #include "dqm_core/AlgorithmConfig.h"
19 #include "dqm_core/AlgorithmManager.h"
20 #include "dqm_core/Result.h"
22 #include "ers/ers.h"
23 
24 
26 
27 
28 namespace dqm_algorithms {
29 
30 // *********************************************************************
31 // Public Methods
32 // *********************************************************************
33 
35  : m_name("CTP_AllBinsAreEmptyExceptZero")
36 {
37  dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
38 }
39 
40 dqm_core::Algorithm*
42 {
43  return new CTP_AllBinsAreEmptyExceptZero(*this);
44 }
45 
46 
48 CTP_AllBinsAreEmptyExceptZero::execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
49 {
50  using namespace std;
51 
52  const TH1 *hist;
53 
54  if(object.IsA()->InheritsFrom( "TH1" )) {
55  hist = static_cast<const TH1*>( &object );
56  if (hist->GetDimension() > 1 ){
57  throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 1 " );
58  }
59  } else {
60  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
61  }
62 
63  //Get Parameters and Thresholds
64  double threshold = 0;
65 
66  try {
67  threshold = dqm_algorithms::tools::GetFirstFromMap("threshold", config.getParameters(), 0);
68  }
69  catch ( dqm_core::Exception & ex ) {
70  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
71  }
72 
73  //Algo
75  std::map<std::string,double> tags; //defined in https://gitlab.cern.ch/atlas-tdaq-software/dqm_core/-/blob/master/dqm_core/Result.h
76 
77  //assume all good, until find a bad one
79  int nbinsx = hist->GetXaxis()->GetNbins();
80  int badBins = 0;
81 
82  for(int iBin = 1; iBin <= nbinsx-1; ++iBin) //foreach bin of the projection (0=underflow)
83  {
84  // If bin content is nonzero, and 0 does not lie in between bin edges
85  if( hist->GetBinContent(iBin) > threshold && hist->GetBinLowEdge(iBin) * hist->GetBinLowEdge(iBin+1) > 0 )
86  {
87  result->status_ = dqm_core::Result::Red;
88  ++ badBins;
89  }
90  }
91  tags["# Bad bins"] = badBins;
92 
93  //set the result tags
94  result->tags_ = tags;
95 
96  // Return the result
97  return result;
98 }
99 
100 
101 void
103  std::string message;
104  message += "\n";
105  message += "Algorithm: \"" + m_name + "\"\n";
106  message += "Description: Check that the only non-empty bin is the one centered in zero.\n";
107  out << message;
108 }
109 
110 } // namespace dqm_algorithms
CTP_AllBinsAreEmptyExceptZero.h
get_generator_info.result
result
Definition: get_generator_info.py:21
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
plotmaker.hist
hist
Definition: plotmaker.py:148
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
ReweightUtils.message
message
Definition: ReweightUtils.py:15
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
tags
std::vector< std::string > tags
Definition: hcg.cxx:102
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
dqm_algorithms::CTP_AllBinsAreEmptyExceptZero::CTP_AllBinsAreEmptyExceptZero
CTP_AllBinsAreEmptyExceptZero()
Definition: CTP_AllBinsAreEmptyExceptZero.cxx:34
dqm_algorithms::CTP_AllBinsAreEmptyExceptZero::clone
virtual dqm_core::Algorithm * clone() override
Definition: CTP_AllBinsAreEmptyExceptZero.cxx:41
python.handimod.Green
int Green
Definition: handimod.py:524
python.handimod.Red
Red
Definition: handimod.py:551
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
threshold
Definition: chainparser.cxx:74
dqm_algorithms::CTP_AllBinsAreEmptyExceptZero::execute
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config) override
Definition: CTP_AllBinsAreEmptyExceptZero.cxx:48
dqm_algorithms
Definition: AddReference.h:17
dqm_algorithms::CTP_AllBinsAreEmptyExceptZero
Definition: CTP_AllBinsAreEmptyExceptZero.h:15
AlgorithmHelper.h
pickleTool.object
object
Definition: pickleTool.py:30
dqm_algorithms::CTP_AllBinsAreEmptyExceptZero::m_name
std::string m_name
Definition: CTP_AllBinsAreEmptyExceptZero.h:27
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
dqm_algorithms::CTP_AllBinsAreEmptyExceptZero::printDescription
virtual void printDescription(std::ostream &out)
Definition: CTP_AllBinsAreEmptyExceptZero.cxx:102