Logo ROOT   6.08/07
Reference Guide
EstimateSummary.cxx
Go to the documentation of this file.
1 // @(#)root/roostats:$Id: cranmer $
2 // Author: Kyle Cranmer, Akira Shibata
3 /*************************************************************************
4  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5  * All rights reserved. *
6  * *
7  * For the licensing terms see $ROOTSYS/LICENSE. *
8  * For the list of contributors see $ROOTSYS/README/CREDITS. *
9  *************************************************************************/
10 
11 ////////////////////////////////////////////////////////////////////////////////
12 
13 /*
14 BEGIN_HTML
15 <p>
16 </p>
17 END_HTML
18 */
19 //
20 
21 #include <algorithm>
23 
25 
26 using namespace std;
27 
28 namespace RooStats {
29  namespace HistFactory {
30 
31  EstimateSummary::EstimateSummary(){
32  nominal=0;
33 
34  normName="Lumi";
35  IncludeStatError = false;
36  StatConstraintType=Gaussian;
37  RelErrorThreshold=0.0;
38  relStatError=NULL;
39  shapeFactorName="";
40  }
41  EstimateSummary::~EstimateSummary(){}
42 
43  void EstimateSummary::Print(const char * /*opt*/) const {
44  cout << "EstimateSummary (name = " << name << " empty = " << name.empty() << ")"<< endl;
45  cout << " TObj name = " << this->GetName() << endl;
46  cout << " Channel = " << channel << endl;
47  cout << " NormName = " << normName << endl;
48  cout << " Nominal ptr = " << nominal << endl;
49  if (nominal) cout << " Nominal hist name = " << nominal->GetName() << endl;
50  cout << " Number of hist variations = " << systSourceForHist.size()
51  << " " << lowHists.size() << " "
52  << " " << highHists.size() << endl;
53  cout << " Number of overall systematics = " << overallSyst.size() << endl;
54  }
55 
56  void EstimateSummary::AddSyst(const string &sname, TH1* low, TH1* high){
57  systSourceForHist.push_back(sname);
58  lowHists.push_back(low);
59  highHists.push_back(high);
60  }
61 
62  bool EstimateSummary::operator==(const EstimateSummary &other) const {
63  // Comparator for two Estimate summary objects. Useful to make sure two analyses are the same
64 
65  //this->print();
66  //other.print();
67  if(! (name==other.name)){
68  cout << "names don't match : " << name << " vs " << other.name << endl;
69  return false;
70  }
71  if(! (channel==other.channel)){
72  cout << "channel names don't match : " << channel << " vs " << other.channel << endl;
73  return false;
74  }
75  if(! (normName==other.normName)){
76  cout << "norm names don't match : " << normName << " vs " << other.normName << endl;
77  return false;
78  }
79  if(! (shapeFactorName==other.shapeFactorName)){
80  cout << "norm names don't match : " << shapeFactorName << " vs " << other.shapeFactorName << endl;
81  return false;
82  }
83  if (nominal && other.nominal)
84  if(! CompareHisto( this->nominal, other.nominal ) ) {
85  cout << "nominal histo don't match" << endl;
86  return false;
87  }
88  if(! (IncludeStatError==other.IncludeStatError)){
89  cout << "Include Stat Error bools don't match : " << IncludeStatError << " vs " << other.IncludeStatError << endl;
90  return false;
91  }
92  if(! (StatConstraintType==other.StatConstraintType)){
93  cout << "Stat Constraint Types don't match : " << StatConstraintType << " vs " << other.StatConstraintType << endl;
94  return false;
95  }
96  if(! (RelErrorThreshold==other.RelErrorThreshold)){
97  cout << "Relative Stat Error Thresholds don't match : " << RelErrorThreshold << " vs " << other.RelErrorThreshold << endl;
98  return false;
99  }
100  if (relStatError && other.relStatError)
101  if(! CompareHisto( this->relStatError, other.relStatError ) ) {
102  cout << "relStatError histo don't match" << endl;
103  return false;
104  }
105  if(! (shapeFactorName==other.shapeFactorName)){
106  cout << "Shape Factor Names don't match : " << shapeFactorName << " vs " << other.shapeFactorName << endl;
107  return false;
108  }
109 
110 
111  /// compare histo sys
112  int counter=0;
113  for( vector<string>::const_iterator itr=systSourceForHist.begin(); itr!=systSourceForHist.end(); ++itr){
114  unsigned int ind = find(other.systSourceForHist.begin(), other.systSourceForHist.end(), *itr) - other.systSourceForHist.begin();
115  if(ind<other.systSourceForHist.size() && systSourceForHist.size() == other.systSourceForHist.size()){
116  if(! (CompareHisto( lowHists[ counter ], other.lowHists[ ind ]))){
117  cout << "contents of sys histo low " << *itr << " did not match" << endl;
118  }
119  else if (!( CompareHisto( highHists[counter], other.highHists[ ind ]) ) ){
120  cout << "contents of sys histo high " << *itr << " did not match" << endl;
121  }
122  } else {
123  cout << "mismatch in systSourceForHist : " << systSourceForHist.size() << " vs " << other.systSourceForHist.size() << endl;
124  for( vector<string>::const_iterator itr_this=systSourceForHist.begin(); itr_this!=systSourceForHist.end(); ++itr_this){
125  cout << " this contains: " << *itr_this << endl;
126  }
127  for( vector<string>::const_iterator itr_other=other.systSourceForHist.begin(); itr_other!=other.systSourceForHist.end(); ++itr_other){
128  cout << " other contains: " << *itr_other << endl;
129  }
130  return false;
131  }
132  counter++;
133  }
134  /// compare overall sys
135  if( overallSyst.size() != other.overallSyst.size()){
136  cout << "mismatch in overallSyst : " << overallSyst.size() << " vs " << other.overallSyst.size() << endl;
137  return false;
138  }
139  for( map<string, pair<double, double> >::const_iterator itr=overallSyst.begin(); itr!=overallSyst.end(); ++itr){
140  map<string, pair<double, double> >::const_iterator found=other.overallSyst.find(itr->first);
141  if(found==other.overallSyst.end()){
142  cout << "mismatch in overallSyst, didn't find " << itr->first << endl;
143  return false;
144  }
145  if(! (itr->second.first==found->second.first && itr->second.second==found->second.second)){
146  cout << "mismatch in overall Syst value of " << itr->first << endl;
147  return false;
148  }
149  }
150  return true;
151  }
152 
153  bool EstimateSummary::CompareHisto( const TH1 * one, const TH1 * two) const {
154 
155  if (!one && !two) return true;
156  if (!one) return false;
157  if (!two) return false;
158 
159  for(int i=1; i<=one->GetNbinsX(); ++i){
160  if(!(one->GetBinContent(i)-two->GetBinContent(i)==0)) return false;
161  }
162  return true;
163  //if(one->Integral()-two->Integral()==0) return true;
164  //cout << "Integral of " << one->GetName() << " : " << one->Integral() << " vs Integral ov " << two->GetName() << " : " << two->Integral() << endl;
165  }
166 
167  }
168 }
169 
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:140
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4638
STL namespace.
std::map< std::string, std::pair< double, double > > overallSyst
const std::string sname
Definition: testIO.cxx:45
std::vector< std::string > systSourceForHist
Namespace for the RooStats classes.
Definition: Asimov.h:20
#define ClassImp(name)
Definition: Rtypes.h:279
void Print(std::ostream &os, const OptionType &opt)
The TH1 histogram class.
Definition: TH1.h:80
Bool_t operator==(const TDatime &d1, const TDatime &d2)
Definition: TDatime.h:101
#define NULL
Definition: Rtypes.h:82
virtual Int_t GetNbinsX() const
Definition: TH1.h:301
char name[80]
Definition: TGX11.cxx:109