ATLAS Offline Software
BinsFilledOutRange.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 #include <dqm_core/AlgorithmConfig.h>
12 #include <TH1.h>
13 #include <TF1.h>
14 #include <TClass.h>
15 #include <ers/ers.h>
16 
17 
18 
19 #include <dqm_core/AlgorithmManager.h>
20 static dqm_algorithms::BinsFilledOutRange myInstance;
21 
22 
23 
25 {
26  dqm_core::AlgorithmManager::instance().registerAlgorithm( "BinsFilledOutRange", this );
27 }
28 
30 {
31 }
32 
35 {
36  return new BinsFilledOutRange();
37 }
38 
39 
42  const TObject & object,
43  const dqm_core::AlgorithmConfig & config )
44 {
45  const TH1 * histogram;
46 
47  if(object.IsA()->InheritsFrom( "TH1" )) {
48  histogram = static_cast<const TH1*>(&object);
49  if (histogram->GetDimension() > 1 ){
50  throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 1 " );
51  }
52  } else {
53  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1");
54  }
55 
56 
57  const bool publish = (bool) dqm_algorithms::tools::GetFirstFromMap( "PublishBins", config.getParameters(), 0);
58  const int maxpublish = (int) dqm_algorithms::tools::GetFirstFromMap( "MaxPublish", config.getParameters(), 20);
59  const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
60  if (histogram->GetEntries() < minstat ) {
62  result->tags_["InsufficientEntries"] = histogram->GetEntries();
63  return result;
64  }
65 
66  double gthreshold;
67  double rthreshold;
68  try {
69  rthreshold = dqm_algorithms::tools::GetFromMap( "NBins", config.getRedThresholds() );
70  gthreshold = dqm_algorithms::tools::GetFromMap( "NBins", config.getGreenThresholds() );
71  }
72  catch( dqm_core::Exception & ex ) {
73  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
74  }
75 
76 
77  int count = 0;
78  std::vector<int> range=dqm_algorithms::tools::GetBinRange(histogram, config.getParameters());
79  int nbins=histogram->GetNbinsX();
81  TH1* resulthisto;
82  if (histogram->InheritsFrom("TH2")) {
83  resulthisto=(TH1*)(histogram->Clone());
84  } else if (histogram->InheritsFrom("TH1")) {
85  resulthisto=(TH1*)(histogram->Clone());
86  } else {
87  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
88  }
89 
90  resulthisto->Reset();
91 
92  for ( int i = 1; i < range[0]; ++i ) {
93  double content = histogram -> GetBinContent(i);
94  if ( content !=0 ) {
95  ++count;
96  resulthisto->SetBinContent(i,content);
97  if (publish && count<maxpublish) {
99  }
100  }
101  }
102  for ( int j = range[1]; j <= nbins; ++j ) {
103  double content= histogram -> GetBinContent(j);
104  if ( content != 0 ) {
105  ++count;
106  resulthisto->SetBinContent(j,content);
107  if (publish && count<maxpublish) {
109  }
110  }
111  }
112 
113  ERS_DEBUG(1,"Number of bins with content != 0 is " << count );
114  ERS_DEBUG(1,"Green threshold: "<< gthreshold << " bin(s); Red threshold : " << rthreshold << " bin(s) ");
115 
116 
117  result->tags_["NBins"] = count;
118  result->object_ = (boost::shared_ptr<TObject>)(TObject*)(resulthisto);
119 
120  if (gthreshold > rthreshold) {
121  if ( count >= gthreshold ) {
122  result->status_ = dqm_core::Result::Green;
123  } else if ( count > rthreshold ) {
124  result->status_ = dqm_core::Result::Yellow;
125  } else {
126  result->status_ = dqm_core::Result::Red;
127  }
128  } else {
129  if ( count <= gthreshold ) {
130  result->status_ = dqm_core::Result::Green;
131  } else if ( count < rthreshold ) {
132  result->status_ = dqm_core::Result::Yellow;
133  } else {
134  result->status_ = dqm_core::Result::Red;
135  }
136  }
137 
138  return result;
139 }
140 void
142 {
143  out<<"Bins_Filled_OutsideRange: Checks for number of non-empty bins outside bin range\n"<<std::endl;
144 
145  out<<"Mandatory Parameter: xmin: minimum x range"<<std::endl;
146  out<<"Mandatory Parameter: xmax: maximum x range"<<std::endl;
147  out<<"Mandatory Green/Red Threshold: NBins: Number of non-empty bins to give Green/Red result\n"<<std::endl;
148 
149  out<<"Optional Parameter: PublishBins: Save bins which are different from average in Result (set to 1)"<<std::endl;
150  out<<"Optional Parameter: MaxPublish: Max number of bins to save (default 20)"<<std::endl;
151  out<<"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm"<<std::endl;
152 }
153 
dqm_algorithms::tools::GetBinRange
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:380
Undefined
@ Undefined
Definition: MaterialTypes.h:8
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::tools::PublishBin
void PublishBin(const TH1 *histogram, int xbin, int ybin, double content, dqm_core::Result *result)
Definition: AlgorithmHelper.cxx:426
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
dqm_algorithms::BinsFilledOutRange::~BinsFilledOutRange
~BinsFilledOutRange()
Definition: BinsFilledOutRange.cxx:29
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
grepfile.content
string content
Definition: grepfile.py:56
dqm_algorithms::BinsFilledOutRange
Definition: BinsFilledOutRange.h:19
lumiFormat.i
int i
Definition: lumiFormat.py:85
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
BinsFilledOutRange.h
python.handimod.Green
int Green
Definition: handimod.py:524
dqm_algorithms::BinsFilledOutRange::BinsFilledOutRange
BinsFilledOutRange()
Definition: BinsFilledOutRange.cxx:24
python.handimod.Red
Red
Definition: handimod.py:551
dqm_algorithms::BinsFilledOutRange::clone
BinsFilledOutRange * clone()
Definition: BinsFilledOutRange.cxx:34
dqm_algorithms::BinsFilledOutRange::execute
dqm_core::Result * execute(const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
Definition: BinsFilledOutRange.cxx:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
dqm_algorithms::BinsFilledOutRange::printDescription
void printDescription(std::ostream &out)
Definition: BinsFilledOutRange.cxx:141
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
AlgorithmHelper.h
dqm_algorithms::tools::GetFromMap
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
Definition: AlgorithmHelper.h:114
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
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
histogram
std::string histogram
Definition: chains.cxx:52