ATLAS Offline Software
Loading...
Searching...
No Matches
CheckBinSpike.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// **********************************************************************
6// $Id: CheckBinSpike.cxx,v 1.0 2024-06-12 19:40:53 jlieberm $
7// **********************************************************************
8
10
11#include <cmath>
12#include <iostream>
13
14
15#include "dqm_core/exceptions.h"
16#include "dqm_core/AlgorithmManager.h"
17#include "dqm_core/Result.h"
19
20namespace{
21 dqm_algorithms::CheckBinSpike CheckBinSpike_1D("1D");
22}
23
24namespace dqm_algorithms {
25
26// *********************************************************************
27// Public Methods
28// *********************************************************************
29
30CheckBinSpike::CheckBinSpike( const std::string & name )
31 : m_name ( name )
32{
33 dqm_core::AlgorithmManager::instance().registerAlgorithm("CheckBinSpike_" + name, this );
34}
35
39
40
41dqm_core::Result* CheckBinSpike::execute( const std::string& name, const TObject& data, const dqm_core::AlgorithmConfig & config ){
42 // Cast to the type of TObject to assess
43 const TH1* h = dynamic_cast<const TH1*>( &data );
44 if( h == 0 ) {
45 throw dqm_core::BadConfig( ERS_HERE, name, "Cannot cast data to type TH1" );
46 }
47 const TH1* ref = dynamic_cast<const TH1*>( config.getReference() );
48 if( ref == 0 ) {
49 throw dqm_core::BadConfig( ERS_HERE, name, "Cannot obtain reference of type TH1" );
50 }
51 double greenThr, redThr;
52
53 std::string thrName="MaxDist";
54
55 try {
56 greenThr = dqm_algorithms::tools::GetFromMap( thrName, config.getGreenThresholds() );
57 redThr = dqm_algorithms::tools::GetFromMap( thrName, config.getRedThresholds() );
58 }
59 catch ( dqm_core::Exception & ex ) {
60 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
61
62 }
63 float bin = 0;
64 float maxValue = 0;
66 std::unique_ptr<dqm_core::Result> result (new dqm_core::Result());
67 result->tags_["MaximumValue"] = maxValue;
68 result->tags_["SpottedBin"] = bin;
69
70 if( maxValue < greenThr ) {
71 result->status_ = dqm_core::Result::Green;
72 }
73 else if( maxValue > redThr ) {
74 result->status_ = dqm_core::Result::Red;
75 }
76 else {
77 result->status_ = dqm_core::Result::Yellow;
78 }
79 return result.release();
80}
81
82void CheckBinSpike::checkBinByBin(const TH1* hist, float &result, float &detectedBin) {
83 std::vector<float> values;
84 for ( int ibin=1; ibin<hist->GetNbinsX()+1; ibin++ ){
85 float ref = (hist->GetBinContent(ibin-1) + hist->GetBinContent(ibin+1))*0.5;
86 if ( ibin==1 ) {
87 ref = (hist->GetBinContent(hist->GetNbinsX()) + hist->GetBinContent(ibin+1))*0.5;
88 }
89 if ( ibin==hist->GetNbinsX() ){
90 ref = (hist->GetBinContent(1) + hist->GetBinContent(ibin-1))*0.5;
91 }
92 float test = hist->GetBinContent(ibin);
93 values.push_back(test/ref);
94 }
95 result = *std::max_element(values.begin(),values.end());
96 int bin = std::max_element(values.begin(),values.end()) - values.begin();
97 detectedBin = hist->GetXaxis()->GetBinCenter(bin);
98}
99
100void CheckBinSpike::printDescription(std::ostream& out){
101 std::string message;
102 message += "\n";
103 message += "Algorithm: \"" + m_name + "\"\n";
104 message += "Description: Checks if the maximum ratio between bins in a TH1F\n";
105 message += " is above a given threshold. Useful for peak detection\n";
106 message += "Parameters: none\n";
107 message += "\n";
108 out << message;
109}
110
111} // namespace dqm_algorithms
112
const boost::regex ref(r_ef)
file declares the dqm_algorithms::CheckBinSpike class.
#define maxValue(current, test)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Header file for AthHistogramAlgorithm.
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 &)
void checkBinByBin(const TH1 *hist, float &result, float &detectedBin)
CheckBinSpike(const std::string &name)
void printDescription(std::ostream &out)