ATLAS Offline Software
Loading...
Searching...
No Matches
CTP_AllBinsAreEmptyExceptZero.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
28namespace 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
40dqm_core::Algorithm*
45
46
47dqm_core::Result*
48CTP_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
74 dqm_core::Result* result = new dqm_core::Result();
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
78 result->status_ = dqm_core::Result::Green;
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_ = std::move(tags);
95
96 // Return the result
97 return result;
98}
99
100
101void
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
static dqm_algorithms::AveragePrint staticInstance
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config) override
std::vector< std::string > tags
Definition hcg.cxx:105
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
STL namespace.
#define IsA
Declare the TObject style functions.