ATLAS Offline Software
Loading...
Searching...
No Matches
SectorEfficiencyCheck.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
8#include <dqm_core/AlgorithmManager.h>
9#include "dqm_core/AlgorithmConfig.h"
10#include <dqm_core/exceptions.h>
11
12#include <TEfficiency.h>
13#include <TH1.h>
14#include <iostream>
15#include <sstream>
16#include <iomanip> // For std::fixed, std::setprecision
17
18namespace {
20}
21
23 dqm_core::AlgorithmManager::instance().registerAlgorithm("SectorEfficiencyCheck", this);
24}
25
28
33
34dqm_core::Result*
36 const TObject& object,
37 const dqm_core::AlgorithmConfig& config ) {
38
39 if ( !object.IsA()->InheritsFrom( "TEfficiency" ) ) {
40 throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TEfficiency" );
41 }
42
43 auto efficiency_object = static_cast<const TEfficiency*>( &object );
44
45 const TH1* h_total = efficiency_object->GetTotalHistogram();
46 if (h_total->GetEntries() == 0) {
47 auto result = new dqm_core::Result();
48 result->status_ = dqm_core::Result::Undefined;
49 return result;
50 }
51
52
53 int MIN_STATISTICS_CUT = 50.0;
54 float EFF_THRESH_low = 0.50;
55 float EFF_THRESH_medium = 0.80;
56 float EFF_THRESH_high = 0.90;
57 int N_Sect_low_max = 4;
58 int N_Sect_medium = 5;
59 int N_Sect_high_min = 6;
60 try {
61 MIN_STATISTICS_CUT = static_cast<int>( dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters() ) );
62 EFF_THRESH_high = static_cast<float>( dqm_algorithms::tools::GetFirstFromMap( "EffThreshHigh", config.getParameters() ));
63 EFF_THRESH_medium = static_cast<float>( dqm_algorithms::tools::GetFirstFromMap( "EffThreshMedium", config.getParameters() ));
64 N_Sect_low_max = static_cast<float>( dqm_algorithms::tools::GetFirstFromMap( "NSectLowMax", config.getParameters() ));
65 N_Sect_medium = static_cast<float>( dqm_algorithms::tools::GetFirstFromMap( "NSectMedium", config.getParameters() ));
66 N_Sect_high_min = static_cast<float>( dqm_algorithms::tools::GetFirstFromMap( "NSectHighMin", config.getParameters() ));
67 }catch ( dqm_core::Exception & ex ) {
68 MIN_STATISTICS_CUT = 50;
69 EFF_THRESH_low = 0.50;
70 EFF_THRESH_medium = 0.80;
71 EFF_THRESH_high = 0.90;
72 N_Sect_low_max = 4;
73 N_Sect_medium = 5;
74 N_Sect_high_min = 6;
75 }
76
77
78 int nLBs = h_total->GetNbinsX();
79 int nSectors = h_total->GetNbinsY();
80
81 bool red_flag_triggered = false;
82
83 uint32_t total_low_eff_bins = 0;
84
85 //loop on lb
86 for (int x_lb_bin = 1; x_lb_bin <= nLBs; ++x_lb_bin) {
87
88 int count_eff_lt_50 = 0;
89 int count_eff_lt_80 = 0;
90 int count_eff_lt_90 = 0;
91
92 //loop on sectors
93 for (int y_sector_bin = 1; y_sector_bin <= nSectors; ++y_sector_bin) {
94
95 int bin_idx = h_total->GetBin(x_lb_bin, y_sector_bin);
96 double total_events = h_total->GetBinContent(bin_idx);
97
98 // min stat cut
99 if (total_events > MIN_STATISTICS_CUT) {
100
101 double bin_eff = efficiency_object->GetEfficiency(bin_idx);
102
103 if (bin_eff < EFF_THRESH_high) {
104 count_eff_lt_90++;
105 }
106 if (bin_eff < EFF_THRESH_medium) {
107 count_eff_lt_80++;
108 }
109 if (bin_eff < EFF_THRESH_low) {
110 count_eff_lt_50++;
111 total_low_eff_bins++;
112 }
113 }
114 } // sector loop
115
116 // --- RED Flag criteria ---
117
118 if (count_eff_lt_90 >= N_Sect_high_min) {
119 red_flag_triggered = true;
120 break;
121 }
122 else if (count_eff_lt_80 == N_Sect_medium) {
123 red_flag_triggered = true;
124 break;
125 }
126 else if (count_eff_lt_50 >= 2 && count_eff_lt_50 <= N_Sect_low_max) {
127 red_flag_triggered = true;
128 break;
129 }
130
131 } // loop LB
132
133 auto result = new dqm_core::Result();
134
135 if (red_flag_triggered) {
136 result->status_ = dqm_core::Result::Red;
137 } else {
138 result->status_ = dqm_core::Result::Green;
139 }
140
141
142 result->tags_[ "N_Bad_Bins_Lt_50_Percent" ] = (double)total_low_eff_bins;
143 result->tags_[ "Red_Flag_Triggered" ] = (double)(red_flag_triggered ? 1.0 : 0.0);
144
145
146 return result;
147}
148
150 out << "SectorEfficiencyCheck: analysis of an 2d efficiency map \n"
151 << std::endl;
152}
std::map< std::string, double > instance
void printDescriptionTo(std::ostream &out) override
dqm_core::Result * execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config) override
SectorEfficiencyCheck * clone() override
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
#define IsA
Declare the TObject style functions.