ATLAS Offline Software
Public Member Functions | List of all members
dqm_algorithms::Bins_Diff_FromAvg Struct Reference

#include <Bins_Diff_FromAvg.h>

Inheritance diagram for dqm_algorithms::Bins_Diff_FromAvg:
Collaboration diagram for dqm_algorithms::Bins_Diff_FromAvg:

Public Member Functions

 Bins_Diff_FromAvg ()
 
 ~Bins_Diff_FromAvg ()
 
Bins_Diff_FromAvgclone ()
 
dqm_core::Resultexecute (const std::string &, const TObject &, const dqm_core::AlgorithmConfig &)
 
void printDescription (std::ostream &out)
 

Detailed Description

Definition at line 18 of file Bins_Diff_FromAvg.h.

Constructor & Destructor Documentation

◆ Bins_Diff_FromAvg()

dqm_algorithms::Bins_Diff_FromAvg::Bins_Diff_FromAvg ( )

Definition at line 25 of file Bins_Diff_FromAvg.cxx.

26 {
27  dqm_core::AlgorithmManager::instance().registerAlgorithm("Bins_Diff_FromAvg", this);
28 }

◆ ~Bins_Diff_FromAvg()

dqm_algorithms::Bins_Diff_FromAvg::~Bins_Diff_FromAvg ( )

Definition at line 30 of file Bins_Diff_FromAvg.cxx.

31 {
32 }

Member Function Documentation

◆ clone()

dqm_algorithms::Bins_Diff_FromAvg * dqm_algorithms::Bins_Diff_FromAvg::clone ( )

Definition at line 35 of file Bins_Diff_FromAvg.cxx.

36 {
37 
38  return new Bins_Diff_FromAvg();
39 }

◆ execute()

dqm_core::Result * dqm_algorithms::Bins_Diff_FromAvg::execute ( const std::string &  name,
const TObject &  object,
const dqm_core::AlgorithmConfig &  config 
)

Definition at line 43 of file Bins_Diff_FromAvg.cxx.

46 {
47  const TH1* histogram;
48 
49  if( object.IsA()->InheritsFrom( "TH1" ) ) {
50  histogram = static_cast<const TH1*>(&object);
51  if (histogram->GetDimension() > 2 ){
52  throw dqm_core::BadConfig( ERS_HERE, name, "dimension > 2 " );
53  }
54  } else {
55  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
56  }
57 
58  const double minstat = dqm_algorithms::tools::GetFirstFromMap( "MinStat", config.getParameters(), -1);
59  const double ignoreval = dqm_algorithms::tools::GetFirstFromMap( "ignoreval", config.getParameters(), -99999);
60  bool greaterthan = (bool) dqm_algorithms::tools::GetFirstFromMap( "GreaterThan", config.getParameters(), 0);
61  bool lessthan = (bool) dqm_algorithms::tools::GetFirstFromMap( "LessThan", config.getParameters(), 0);
62  const bool publish = (bool) dqm_algorithms::tools::GetFirstFromMap( "PublishBins", config.getParameters(), 0);
63  const int maxpublish = (int) dqm_algorithms::tools::GetFirstFromMap( "MaxPublish", config.getParameters(), 20);
64  const double maxdiffabs = dqm_algorithms::tools::GetFirstFromMap( "MaxDiffAbs", config.getParameters(), -1);
65  const double maxdiffrel = dqm_algorithms::tools::GetFirstFromMap( "MaxDiffRel", config.getParameters(), -1);
66 
67  if (greaterthan && lessthan) {
68  ERS_INFO("Both GreaterThan and LessThan parameters set: Will check for for both");
69  greaterthan = false;
70  lessthan = false;
71  }
72 
73  if ( histogram->GetEntries() < minstat ) {
75  result->tags_["InsufficientEntries"] = histogram->GetEntries();
76  return result;
77  }
78 
79  double bin_threshold;
80  double gthreshold;
81  double rthreshold;
82  try {
83  bin_threshold = dqm_algorithms::tools::GetFirstFromMap( "NSigma", config.getParameters() );
84  rthreshold = dqm_algorithms::tools::GetFromMap( "NBins", config.getRedThresholds() );
85  gthreshold = dqm_algorithms::tools::GetFromMap( "NBins", config.getGreenThresholds() );
86  }
87  catch( dqm_core::Exception & ex ) {
88  throw dqm_core::BadConfig( ERS_HERE, name, ex.what(), ex );
89  }
90 
91 
92  double sumwe=0;
93  double sume=0;
94  TH1* resulthisto;
95  if (histogram->InheritsFrom("TH2")) {
96  resulthisto=(TH1*)(histogram->Clone());
97  } else if (histogram->InheritsFrom("TH1")) {
98  resulthisto=(TH1*)(histogram->Clone());
99  } else {
100  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
101  }
102 
103  resulthisto->Reset();
104 
105  int count = 0;
106  std::vector<int> range=dqm_algorithms::tools::GetBinRange(histogram, config.getParameters());
107 
108  for ( int i = range[0]; i <= range[1]; ++i ) {
109  for ( int j = range[2]; j <= range[3]; ++j ) {
110  if (histogram->GetBinContent(i,j) == ignoreval) continue;
111  if (histogram->GetBinError(i,j) == 0 ) continue;
112  sumwe += histogram->GetBinContent(i,j)*(1./std::pow(histogram->GetBinError(i,j),2));
113  sume += 1./std::pow(histogram->GetBinError(i,j),2);
114  }
115  }
116  double avg;
117 
118  if (sume !=0 ) {
119  avg=sumwe/sume;
120  } else {
122  result->tags_["SumErrors"] = sume;
123  delete resulthisto;
124  return result;
125  }
126 
128  result->tags_["Average"] = avg;
129 
130  for ( int k = range[0]; k <= range[1]; ++k ) {
131  for ( int l = range[2]; l <= range[3]; ++l ) {
132  double inputcont = histogram->GetBinContent(k,l);
133  double inputerr = histogram->GetBinError(k,l);
134  double diff=inputcont - avg;
135  double reldiff=1;
136  if(avg!=0) reldiff=diff/avg;
137  else if(diff==0) reldiff=0;
138  if (inputcont == ignoreval) continue;
139  if (inputerr != 0){
140  double sigma=diff/inputerr;
141  if (greaterthan && diff < 0. ) continue;
142  if (lessthan && diff > 0. ) continue;
143 
144  if ( (std::abs(sigma) > bin_threshold) && (std::abs(diff) > maxdiffabs) && (std::abs(reldiff) > maxdiffrel) ) {
145  resulthisto->SetBinContent(k,l,inputcont);
146  count++;
147  if (publish && count < maxpublish){
149  }
150  }
151  }
152 
153  }
154  }
155 
156  result->tags_["NBins"] = count;
157  result->object_ = (boost::shared_ptr<TObject>)(TObject*)(resulthisto);
158 
159  ERS_DEBUG(1,"Number of bins " << bin_threshold << " Sigma away from average of "<< avg << " is " << count);
160  ERS_DEBUG(1,"Green threshold: "<< gthreshold << " bin(s); Red threshold : " << rthreshold << " bin(s) ");
161 
162 
163 
164  if ( count <= gthreshold ) {
165  result->status_ = dqm_core::Result::Green;
166  } else if ( count < rthreshold ) {
167  result->status_ = dqm_core::Result::Yellow;
168  } else {
169  result->status_ = dqm_core::Result::Red;
170  }
171  return result;
172 
173 }

◆ printDescription()

void dqm_algorithms::Bins_Diff_FromAvg::printDescription ( std::ostream &  out)

Definition at line 175 of file Bins_Diff_FromAvg.cxx.

176 {
177 
178  out<<"Bins_Diff_FromAvg: Calculates average bin value and checks number of bins N sigma away from calculated average\n"<<std::endl;
179 
180  out<<"Mandatory Parameter: NSigma: Number of sigma each bin must be within average bin value\n"<<std::endl;
181 
182 
183  out<<"Mandatory Green/Red Threshold: NBins: number of bins N sigma away from average to give Green/Red result\n"<<std::endl;
184 
185  out<<"Optional Parameter: MinStat: Minimum histogram statistics needed to perform Algorithm"<<std::endl;
186  out<<"Optional Parameter: xmin: minimum x range"<<std::endl;
187  out<<"Optional Parameter: xmax: maximum x range"<<std::endl;
188  out<<"Optional Parameter: ymin: minimum y range"<<std::endl;
189  out<<"Optional Parameter: ymax: maximum y range"<<std::endl;
190  out<<"Optional Parameter: ignoreval: valued to be ignored for calculating average"<<std::endl;
191  out<<"Optional Parameter: GreaterThan: check only for bins which are GreaterThan average (set to 1)"<<std::endl;
192  out<<"Optional Parameter: LessThan: check only for bins which are LessThan average (set to 1)"<<std::endl;
193  out<<"Optional Parameter: PublishBins: Save bins which are different from average in Result (set to 1)"<<std::endl;
194  out<<"Optional Parameter: MaxPublish: Max number of bins to save (default 20)"<<std::endl;
195  out<<"Optional Parameter: MaxDiffAbs: test fails if NBins more than NSigma away and NBins more than MaxDiffAbs (absolut difference) away from average"<<std::endl;
196  out<<"Optional Parameter: MaxDiffRel: test fails if NBins more than NSigma away and NBins more than MaxDiffRel (relative difference) away from average\n"<<std::endl;
197 
198 }

The documentation for this struct was generated from the following files:
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
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
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
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
dqm_algorithms::tools::PublishBin
void PublishBin(const TH1 *histogram, int xbin, int ybin, double content, dqm_core::Result *result)
Definition: AlgorithmHelper.cxx:426
dqm_algorithms::Bins_Diff_FromAvg::Bins_Diff_FromAvg
Bins_Diff_FromAvg()
Definition: Bins_Diff_FromAvg.cxx:25
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
lumiFormat.i
int i
Definition: lumiFormat.py:85
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
Recovery.avg
def avg(a, b)
Definition: Recovery.py:79
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
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:221
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
TileRawChannelBuilderTestConfig.reldiff
def reldiff(a, b)
Definition: TileRawChannelBuilderTestConfig.py:18
histogram
std::string histogram
Definition: chains.cxx:52
fitman.k
k
Definition: fitman.py:528