ATLAS Offline Software
MaximumBin.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "dqm_core/AlgorithmConfig.h"
7 #include "dqm_core/AlgorithmManager.h"
9 #include "TH1.h"
10 
11 static dqm_algorithms::MaximumBin myInstance;
12 
14 {
15  dqm_core::AlgorithmManager::instance().registerAlgorithm("MaximumBin", this);
16 }
17 
20 {
21  return new MaximumBin();
22 }
23 
24 
27  const TObject & object,
28  const dqm_core::AlgorithmConfig & config)
29 {
30  // get the histogram
31  const TH1 * histogram;
32 
33  if( object.IsA()->InheritsFrom( "TH1" ) ) {
34  histogram = static_cast<const TH1*>(&object);
35  } else {
36  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
37  }
38 
39  int dim = histogram->GetDimension();
40 
41  // get the reference maximum bin indices
42  int refBinX=-1, refBinY=-1, refBinZ=-1; // bin x,y,z-index to be compared to the maximum bin
43  try {
44  refBinX = (int)dqm_algorithms::tools::GetFirstFromMap("RefBinX", config.getParameters());
45  if (dim>1) refBinY = (int)dqm_algorithms::tools::GetFirstFromMap("RefBinY", config.getParameters());
46  if (dim>2) refBinZ = (int)dqm_algorithms::tools::GetFirstFromMap("RefBinZ", config.getParameters());
47  }
48  catch ( dqm_core::Exception & ex ) {
49  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
50  }
51 
52  // check MinStat
53  const double minstat = dqm_algorithms::tools::GetFirstFromMap("MinStat", config.getParameters(), -1);
54  if (histogram->GetEntries() < minstat ) {
56  result->tags_["InsufficientEntries"] = histogram->GetEntries();
57  return result;
58  }
59 
60  // find the maximum bin indices
61  int maxBinX=-1, maxBinY=-1, maxBinZ=-1;
62  histogram->GetMaximumBin(maxBinX,maxBinY,maxBinZ);
63 
64  // publish the maximum bin indices
66  result->tags_["MaxBin_xIndex"] = maxBinX;
67  if (dim>1) result->tags_["MaxBin_yIndex"] = maxBinY;
68  if (dim>2) result->tags_["MaxBin_zIndex"] = maxBinZ;
69 
70  // check if the conditions are met
71  bool match = (maxBinX == refBinX);
72  if (dim>1) match &= (maxBinY == refBinY);
73  if (dim>2) match &= (maxBinZ == refBinZ);
74 
75  // set the flag and return the result
76  if (match) result->status_ = dqm_core::Result::Green;
77  else result->status_ = dqm_core::Result::Red;
78 
79  return result;
80 }
81 
82 
84  out<<"MaximumBin : Finds a bin with the maximum content and checks if the bin index matches the expectation"<< std::endl;
85  out<<"Mandatory parameter : RefBinX : Bin x-index where the maximum is expected"<< std::endl;
86  out<<"Optional parameter : RefBinY : Bin y-index where the maximum is expected"<< std::endl;
87  out<<"Optional parameter : RefBinZ : Bin z-index where the maximum is expected"<< std::endl;
88  out<<"Optional Parameter : MinStat : Minimum histogram statistics needed to perform Algorithm\n"<< std::endl;
89 }
90 
dqm_algorithms::MaximumBin::printDescription
void printDescription(std::ostream &out)
Definition: MaximumBin.cxx:83
Undefined
@ Undefined
Definition: MaterialTypes.h:8
yodamerge_tmp.dim
dim
Definition: yodamerge_tmp.py:239
get_generator_info.result
result
Definition: get_generator_info.py:21
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
dqm_algorithms::MaximumBin
Definition: MaximumBin.h:15
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
MaximumBin.h
dqm_algorithms::MaximumBin::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: MaximumBin.cxx:26
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
dqm_algorithms::MaximumBin::clone
MaximumBin * clone()
Definition: MaximumBin.cxx:19
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:195
TH1
Definition: rootspy.cxx:268
AlgorithmHelper.h
pickleTool.object
object
Definition: pickleTool.py:30
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
dqm_algorithms::MaximumBin::MaximumBin
MaximumBin()
Definition: MaximumBin.cxx:13
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
histogram
std::string histogram
Definition: chains.cxx:52