ATLAS Offline Software
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 
20 namespace{
21  dqm_algorithms::CheckBinSpike CheckBinSpike_1D("1D");
22 }
23 
24 namespace dqm_algorithms {
25 
26 // *********************************************************************
27 // Public Methods
28 // *********************************************************************
29 
30 CheckBinSpike::CheckBinSpike( const std::string & name )
31  : m_name ( name )
32 {
33  dqm_core::AlgorithmManager::instance().registerAlgorithm("CheckBinSpike_" + name, this );
34 }
35 
37  return new CheckBinSpike(m_name);
38 }
39 
40 
41 dqm_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 ) {
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 
82 void 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 
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 
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
CheckBinSpike.h
dqm_algorithms::CheckBinSpike::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: CheckBinSpike.cxx:41
get_generator_info.result
result
Definition: get_generator_info.py:21
maxValue
#define maxValue(current, test)
Definition: CompoundLayerMaterialCreator.h:22
dqm_algorithms::CheckBinSpike::clone
CheckBinSpike * clone()
Definition: CheckBinSpike.cxx:36
dqm_algorithms::CheckBinSpike::m_name
std::string m_name
Definition: CheckBinSpike.h:27
plotmaker.hist
hist
Definition: plotmaker.py:148
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
bin
Definition: BinsDiffFromStripMedian.h:43
dqm_algorithms::CheckBinSpike::printDescription
void printDescription(std::ostream &out)
Definition: CheckBinSpike.cxx:100
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:147
ReweightUtils.message
message
Definition: ReweightUtils.py:15
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
dqm_algorithms::CheckBinSpike
Definition: CheckBinSpike.h:19
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
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
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
dqm_algorithms::CheckBinSpike::CheckBinSpike
CheckBinSpike(const std::string &name)
Definition: CheckBinSpike.cxx:30
dqm_algorithms::CheckBinSpike::checkBinByBin
void checkBinByBin(const TH1 *hist, float &result, float &detectedBin)
Definition: CheckBinSpike.cxx:82
dqm_algorithms
Definition: AddReference.h:17
h
ref
const boost::regex ref(r_ef)
AlgorithmHelper.h
dqm_algorithms::tools::GetFromMap
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
Definition: AlgorithmHelper.h:114