ATLAS Offline Software
Loading...
Searching...
No Matches
MUCTPISLTiming.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("MUCTPISLTiming")
36{
37 dqm_core::AlgorithmManager::instance().registerAlgorithm( m_name, this );
38}
39
40dqm_core::Algorithm*
42{
43 return new MUCTPISLTiming(*this);
44}
45
46
47dqm_core::Result*
48MUCTPISLTiming::execute( const std::string& name, const TObject& object, const dqm_core::AlgorithmConfig& config)
49{
50 using namespace std;
51
52 const TH2 * hist;
53 //TH2 * ref; //not using reference in this case
54
55 if( object.IsA()->InheritsFrom( "TH2" ) ) {
56 hist = static_cast<const TH2*>(&object);
57 if (hist->GetDimension() != 2 ){
58 throw dqm_core::BadConfig( ERS_HERE, name, "dimension != 2 " );
59 }
60 } else {
61 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH2" );
62 }
63
64 //Get Parameters and Thresholds
65 double thresh=0.5;
66 double minstat=-1;
67 int centralBin=4; // the middle of 7 bins;
68
69 try {
70 thresh = dqm_algorithms::tools::GetFirstFromMap("thresh", config.getParameters(), 0.5);
71 minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
72 }
73 catch ( dqm_core::Exception & ex ) {
74 throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
75 }
76
77 //Algo
78
79 //project our 2D histogram to 1D (x-axis), thus summing up along y
80 //will then compare every bin of the projection with the GetBinContent of the central bin in the 2D histo
81 TH1* projection = hist->ProjectionX();
82
83 dqm_core::Result* result = new dqm_core::Result();
84 std::map<std::string,double> tags; //defined in https://gitlab.cern.ch/atlas-tdaq-software/dqm_core/-/blob/master/dqm_core/Result.h
85
86 //assume all good, until find a bad one
87 result->status_ = dqm_core::Result::Green;
88 uint howmanybad=0;
89
90 for(int iBin=1;iBin<=projection->GetNbinsX();iBin++)//0=underflow bin
91 {
92 if( projection->GetBinContent(iBin)*thresh > hist->GetBinContent(iBin,centralBin) ) //if central slice is less than half of SL sum => bad
93 {
94 result->status_ = dqm_core::Result::Yellow;
95 howmanybad++;
96 //add tag to print which bins are actually the "problematic" ones
97 std::string slNum = std::to_string(iBin-1);
98 if(iBin < 10) slNum = "0" + slNum; // leading zero for conformity
99
100 tags[slNum] = hist->GetBinContent(iBin,centralBin)*1.0 / projection->GetBinContent(iBin) ;
101 }
102 }
103 tags["howmanybad"] = howmanybad;
104
105 //set the result tags
106 result->tags_ = std::move(tags);
107
108 //If more than 2SL have bad timing, make it red
109 if(howmanybad>2)
110 result->status_ = dqm_core::Result::Red;
111
112 Double_t stats[7];
113 hist->GetStats(stats);
114 //if not enough stats, reset the result (but keep this here, so can still see the tag for bad SL)
115 if(stats[0]<minstat)
116 result->status_ = dqm_core::Result::Undefined;
117
118 // Return the result
119 return result;
120}
121
122
123void
125 std::string message;
126 message += "\n";
127 message += "Algorithm: \"" + m_name + "\"\n";
128 message += "Description: for each SL x-slice (set of y-bins for the same x value) check that the central y bin has at least 'thresh' percent(ratio) of the sum of values in the SL \n";
129 out << message;
130}
131
132} // namespace dqm_algorithms
static dqm_algorithms::AveragePrint staticInstance
unsigned int uint
virtual dqm_core::Algorithm * clone()
virtual void printDescription(std::ostream &out)
virtual dqm_core::Result * execute(const std::string &name, const TObject &data, const dqm_core::AlgorithmConfig &config)
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.