Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Public Attributes | Private Attributes | List of all members
JTestChi2_Bin Class Reference

#include <JTestChi2_Bin.hh>

Inheritance diagram for JTestChi2_Bin:
JTest_t JTestChi2_t

Public Member Functions

 JTestChi2_Bin ()
 
std::istream & read (std::istream &in)
 
std::ostream & write (std::ostream &out)
 
void test (TObject *o1, TObject *o2)
 
virtual void save (TFile *f, string path)
 
void clear ()
 
JTestResult JChi2Test (TH1 *h1, TH1 *h2, double threshold)
 
JTestResult JChi2TestBin_2D (TH2 *h1, TH2 *h2, double outliersThreshold, double chi2Threshold)
 

Public Attributes

vector< JTestResultresults
 

Private Attributes

double chi2Threshold
 threshold p-value to decide if test is passed for a bin. More...
 
double outliersThreshold
 number of bins allowed to fail the test. More...
 

Detailed Description

Definition at line 17 of file JTestChi2_Bin.hh.

Constructor & Destructor Documentation

JTestChi2_Bin::JTestChi2_Bin ( )
inline

Definition at line 25 of file JTestChi2_Bin.hh.

25 {}

Member Function Documentation

std::istream& JTestChi2_Bin::read ( std::istream &  in)
inlinevirtual

Implements JTest_t.

Definition at line 33 of file JTestChi2_Bin.hh.

33  {
34  return in >> outliersThreshold >> chi2Threshold;
35  };
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
double outliersThreshold
number of bins allowed to fail the test.
double chi2Threshold
threshold p-value to decide if test is passed for a bin.
std::ostream& JTestChi2_Bin::write ( std::ostream &  out)
inlinevirtual

Implements JTest_t.

Definition at line 43 of file JTestChi2_Bin.hh.

43  {
44  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r) {
45  out << scientific << setprecision(2) << (r->passed ? GREEN : RED) << r->message << endl;
46  }
47  return out;
48  };
data_type r[M+1]
Definition: JPolint.hh:709
vector< JTestResult > results
Definition: JTest_t.hh:77
void JTestChi2_Bin::test ( TObject o1,
TObject o2 
)
inlinevirtual

Implements JTest_t.

Definition at line 58 of file JTestChi2_Bin.hh.

58  {
59 
60  if (!(dynamic_cast<TH2*>(o1) == NULL) && !(dynamic_cast<TH2*>(o2) == NULL)) {
61 
62  TH2D* h1 = dynamic_cast<TH2D*>(o1);
63  TH2D* h2 = dynamic_cast<TH2D*>(o2);
64 
66  results.push_back(r);
67  }
68  };
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
data_type r[M+1]
Definition: JPolint.hh:709
JTestResult JChi2TestBin_2D(TH2 *h1, TH2 *h2, double outliersThreshold, double chi2Threshold)
Definition: JTestChi2_t.hh:89
double outliersThreshold
number of bins allowed to fail the test.
vector< JTestResult > results
Definition: JTest_t.hh:77
double chi2Threshold
threshold p-value to decide if test is passed for a bin.
virtual void JTestChi2_Bin::save ( TFile *  f,
string  path 
)
inlinevirtual

Implements JTest_t.

Definition at line 75 of file JTestChi2_Bin.hh.

75  {
76 
77  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
78 
79  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
80  f->cd(path.c_str());
81  r->obj->Write();
82  }
83  }
data_type r[M+1]
Definition: JPolint.hh:709
then JPizza f
Definition: JPizza.sh:46
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
vector< JTestResult > results
Definition: JTest_t.hh:77
void JTestChi2_Bin::clear ( )
inlinevirtual

Implements JTest_t.

Definition at line 88 of file JTestChi2_Bin.hh.

88  {
89  results.clear();
90  }
vector< JTestResult > results
Definition: JTest_t.hh:77
JTestResult JTestChi2_t::JChi2Test ( TH1 *  h1,
TH1 *  h2,
double  threshold 
)
inlineinherited

Definition at line 33 of file JTestChi2_t.hh.

33  {
34 
35  JTestResult r;
36 
37  if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
38  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
39 
40  double chi2 = h1 -> Chi2Test (h2 , "WW");
41 
42  double M = h1->Integral();
43  double N = h2->Integral();
44 
45  TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
46  MAKE_CSTRING(to_string(h1->GetName())) :
47  MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName())));
48 
49  h3->Reset();
50 
51  for (int i=1 ; i < h1->GetNbinsX() ; ++i){
52 
53  double m = h1->GetBinContent(i);
54  double n = h2->GetBinContent(i);
55  if(n!=0 && m!=0){
56 
57  double c = (M*n - N*m)/sqrt((n+m)*(N*M));
58  h3->SetBinContent(i,c);
59  }
60  }
61 
62  (chi2 < threshold ? r.passed = false : r.passed = true);
63 
64  r.message = MAKE_STRING(scientific << setprecision(2)<< "Test: " << "Chi2" <<
65  " HA: " << h1->GetUniqueID() << " " << h1->GetName() <<
66  " HB: " << h2->GetUniqueID() << " " << h2->GetName() <<
67  " Threshold: " << threshold << " Result: " << chi2 << " " << (r.passed ? "PASSED" : "FAILED"));
68 
69 
70  JResultTitle title("Chi2_2D", "Deviation[#sigma] ", r.passed , chi2);
71 
72  h3->SetTitle(title.getTitle().c_str());
73 
74  r.obj = h3;
75 
76  return r;
77  };
do $JPP JMEstimator M
Definition: JMEstimator.sh:37
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:708
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
data_type r[M+1]
Definition: JPolint.hh:709
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:699
#define ERROR(A)
Definition: JMessage.hh:66
string message
Definition: JTest_t.hh:65
alias put_queue eval echo n
Definition: qlib.csh:19
std::string to_string(const T &value)
Convert value to string.
bool passed
Definition: JTest_t.hh:64
TObject * obj
Definition: JTest_t.hh:66
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:37
JTestResult JTestChi2_t::JChi2TestBin_2D ( TH2 *  h1,
TH2 *  h2,
double  outliersThreshold,
double  chi2Threshold 
)
inlineinherited

Definition at line 89 of file JTestChi2_t.hh.

89  {
90 
91  int nx1 = h1->GetNbinsX();
92  int nx2 = h2->GetNbinsX();
93  int ny1 = h1->GetNbinsY();
94  int ny2 = h2->GetNbinsY();
95 
96  double M = h1->Integral();
97  double N = h2->Integral();
98 
99  if(nx1 != nx2 || ny1 != ny2 || M == 0 || N == 0)
100  ERROR("Histograms with different binning. The objects: " << h1->GetName() << " can not be compared." << endl);
101 
102  TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
103  MAKE_CSTRING(to_string(h1->GetName())) :
104  MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName())));
105 
106  h3->Reset();
107 
108  JTestResult r;
109 
110  double outliers = 0;
111 
112  for (int i=1 ; i<nx1 ; ++i){
113  for (int j=1 ; j<ny1 ; ++j){
114 
115  double m = h1 -> GetBinContent(i,j);
116  double n = h2 -> GetBinContent(i,j);
117  double chi2 = (n-m*N/M)/sqrt(m*N/M);
118  (fabs(chi2) > chi2Threshold ? outliers+=1./(nx1*ny1) : outliers+=0 );
119  h3->SetBinContent(i,j,chi2);
120  }
121  }
122 
123  (outliers > outliersThreshold ? r.passed = false : r.passed = true);
124 
125  r.message = MAKE_STRING(scientific << setprecision(2)<< "Test: " << "Chi2_bin" <<
126  " HA: " << h1->GetUniqueID() << " " << h1->GetName() <<
127  " HB: " << h2->GetUniqueID() << " " << h2->GetName() <<
128  " Threshold: " << outliersThreshold << " Result: " << outliers << " " << (r.passed ? "PASSED" : "FAILED"));
129 
130  JResultTitle title("Chi2_bin", "Outliers[%] ", r.passed , 100*outliers);
131 
132  h3->SetTitle(title.getTitle().c_str());
133 
134  r.obj = h3;
135 
136  return r;
137  };
do $JPP JMEstimator M
Definition: JMEstimator.sh:37
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:708
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
data_type r[M+1]
Definition: JPolint.hh:709
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:699
#define ERROR(A)
Definition: JMessage.hh:66
string message
Definition: JTest_t.hh:65
alias put_queue eval echo n
Definition: qlib.csh:19
std::string to_string(const T &value)
Convert value to string.
int j
Definition: JPolint.hh:634
bool passed
Definition: JTest_t.hh:64
TObject * obj
Definition: JTest_t.hh:66
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:37

Member Data Documentation

double JTestChi2_Bin::chi2Threshold
private

threshold p-value to decide if test is passed for a bin.

Definition at line 93 of file JTestChi2_Bin.hh.

double JTestChi2_Bin::outliersThreshold
private

number of bins allowed to fail the test.

Definition at line 94 of file JTestChi2_Bin.hh.

vector<JTestResult> JTest_t::results
inherited

Definition at line 77 of file JTest_t.hh.


The documentation for this class was generated from the following file: