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

#include <JTestKolmogorov_1D.hh>

Inheritance diagram for JTestKolmogorov_1D:
JTestKolmogorov_t JTest_t

Public Member Functions

 JTestKolmogorov_1D ()
 
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 JKolmogorovTest (TH1 *h1, TH1 *h2, double threshold)
 
JTestResult JKolmogorovTest2D (TH2 *h1, TH2 *h2, double threshold)
 

Public Attributes

vector< JTestResultresults
 

Private Attributes

double threshold
 threshold p-value to decide if test is passed. More...
 

Detailed Description

Definition at line 18 of file JTestKolmogorov_1D.hh.

Constructor & Destructor Documentation

JTestKolmogorov_1D::JTestKolmogorov_1D ( )
inline

Definition at line 27 of file JTestKolmogorov_1D.hh.

27 {}

Member Function Documentation

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

Implements JTest_t.

Definition at line 35 of file JTestKolmogorov_1D.hh.

35  {
36  return in >> threshold;
37  };
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
double threshold
threshold p-value to decide if test is passed.
std::ostream& JTestKolmogorov_1D::write ( std::ostream &  out)
inlinevirtual

Implements JTest_t.

Definition at line 45 of file JTestKolmogorov_1D.hh.

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

Implements JTest_t.

Definition at line 58 of file JTestKolmogorov_1D.hh.

58  {
59 
60  if (!(dynamic_cast<TH2*>(o1) == NULL) || !(dynamic_cast<TH2*>(o2) == NULL)) {
61  ERROR("For 2D histograms call JTestKolmogorov_2D: " << o1->GetName() << endl);
62 
63  } else if (!(dynamic_cast<TH1*>(o1) == NULL) && !(dynamic_cast<TH1*>(o2) == NULL)) {
64 
65  TH1D* h1 = dynamic_cast<TH1D*>(o1);
66  TH1D* h2 = dynamic_cast<TH1D*>(o2);
67 
69 
70  results.push_back(r);
71  }
72  };
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
data_type r[M+1]
Definition: JPolint.hh:709
JTestResult JKolmogorovTest(TH1 *h1, TH1 *h2, double threshold)
#define ERROR(A)
Definition: JMessage.hh:66
vector< JTestResult > results
Definition: JTest_t.hh:77
double threshold
threshold p-value to decide if test is passed.
virtual void JTestKolmogorov_1D::save ( TFile *  f,
string  path 
)
inlinevirtual

Implements JTest_t.

Definition at line 79 of file JTestKolmogorov_1D.hh.

79  {
80 
81  for (vector<JTestResult>::const_iterator r = results.begin() ; r != results.end() ; ++r){
82 
83  if (f -> GetDirectory(path.c_str())==0) f->mkdir(path.c_str());
84  f->cd(path.c_str());
85  r->obj->Write();
86  }
87  }
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 JTestKolmogorov_1D::clear ( )
inlinevirtual

Implements JTest_t.

Definition at line 92 of file JTestKolmogorov_1D.hh.

92  {
93  results.clear();
94  }
vector< JTestResult > results
Definition: JTest_t.hh:77
JTestResult JTestKolmogorov_t::JKolmogorovTest ( TH1 *  h1,
TH1 *  h2,
double  threshold 
)
inlineinherited

Definition at line 32 of file JTestKolmogorov_t.hh.

32  {
33 
34  JTestResult r;
35 
36  int n1 = h1 -> GetNbinsX();
37  int n2 = h2 -> GetNbinsX();
38 
39  if(n1 != n2)
40  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
41 
42  TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
43  MAKE_CSTRING(to_string(h1->GetName())) :
44  MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName())));
45 
46  bool afunc1 = false;
47  bool afunc2 = false;
48  double s1 = 1./h1->Integral();
49  double s2 = 1./h2->Integral();
50 
51  double ew1, ew2, w1 = 0, w2 = 0;
52 
53  for (int bin = 1; bin <= n1; ++bin){
54  ew1 = h1->GetBinError(bin);
55  ew2 = h2->GetBinError(bin);
56  w1 += ew1*ew1;
57  w2 += ew2*ew2;
58  }
59 
60  double esum1 = 0, esum2 = 0;
61  if (w1 > 0)
62  esum1 = 1./s1/s1/w1;
63  else
64  afunc1 = true;
65  if (w2 > 0)
66  esum2 = 1./s2/s2/w2;
67  else
68  afunc2 = true;
69  if (afunc2 && afunc1) {
70  ERROR("Errors are zero for both histograms\n");
71  }
72 
73  double c1 = 0, c2 = 0;
74 
75  double dmax = 0;
76  for (int bin=1 ; bin<=n1 ; ++bin){
77  c1 += s1*h1->GetBinContent(bin);
78  c2 += s2*h2->GetBinContent(bin);
79  double d = TMath::Abs(c1-c2)*TMath::Sqrt(esum1*esum2/(esum1+esum2));
80  double p = TMath::KolmogorovProb(d);
81  h3->SetBinContent(bin,p);
82  dmax = TMath::Max(dmax,TMath::Abs(c1-c2));
83  }
84 
85  double z;
86 
87  if (afunc1)
88  z = dmax*TMath::Sqrt(esum2);
89  else if (afunc2)
90  z = dmax*TMath::Sqrt(esum1);
91  else
92  z = dmax*TMath::Sqrt(esum1*esum2/(esum1+esum2));
93 
94  double pValue = TMath::KolmogorovProb(z);
95 
96  (pValue < threshold ? r.passed = false : r.passed = true);
97 
98  r.message = MAKE_STRING(scientific << setprecision(2)<< "Test: " << "Kolmogorov" <<
99  " HA: " << h1->GetUniqueID() << " " << h1->GetName() <<
100  " HB: " << h2->GetUniqueID() << " " << h2->GetName() <<
101  " Threshold: " << threshold << " Result: " << pValue << " " << (r.passed ? "PASSED" : "FAILED"));
102 
103 
104  JResultTitle title("KS", "P(compatible)", r.passed , pValue);
105 
106  h3->SetTitle(title.getTitle().c_str());
107 
108  r.obj = h3;
109 
110  return r;
111  };
#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
then print_variable DETECTOR INPUT_FILE INTERMEDIATE_FILE check_input_file $DETECTOR $INPUT_FILE check_output_file $INTERMEDIATE_FILE $OUTPUT_FILE JMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JPath.sh:52
#define ERROR(A)
Definition: JMessage.hh:66
string message
Definition: JTest_t.hh:65
TCanvas * c1
Global variables to handle mouse events.
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
JTestResult JTestKolmogorov_t::JKolmogorovTest2D ( TH2 *  h1,
TH2 *  h2,
double  threshold 
)
inlineinherited

Definition at line 122 of file JTestKolmogorov_t.hh.

122  {
123 
124  JTestResult r;
125 
126  int n1x = h1 -> GetNbinsX();
127  int n2x = h2 -> GetNbinsX();
128  int n1y = h1 -> GetNbinsY();
129  int n2y = h2 -> GetNbinsY();
130 
131  if(n1x != n2x || n1y != n2y)
132  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
133 
134  if(h1->Integral()==0 || h2->Integral()==0)
135  ERROR("Empty histogram: " << h1 -> GetName() << " can not be compared." << endl);
136 
137  double s1 = 1./h1->Integral();
138  double s2 = 1./h2->Integral();
139 
140  TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
141  MAKE_CSTRING(to_string(h1->GetName())) :
142  MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName())));
143 
144  bool afunc1 = false;
145  bool afunc2 = false;
146 
147  double ew1, ew2, w1 = 0, w2 = 0;
148 
149  for (int i = 1; i <= n1x; ++i){
150  for (int j = 1; j <= n1y; ++j){
151  ew1 = h1->GetBinError(i,j);
152  ew2 = h2->GetBinError(i,j);
153  w1 += ew1*ew1;
154  w2 += ew2*ew2;
155  }
156  }
157 
158  double esum1 = 0, esum2 = 0;
159  if (w1 > 0)
160  esum1 = 1./s1/s1/w1;
161  else
162  afunc1 = true;
163  if (w2 > 0)
164  esum2 = 1./s2/s2/w2;
165  else
166  afunc2 = true;
167  if (afunc2 && afunc1) {
168  ERROR("Errors are zero for both histograms\n");
169  }
170 
171  double c1 = 0, c2 = 0;
172 
173  double dmax1 = 0;
174  for (int i=1 ; i<=n1x ; ++i){
175  for (int j=1 ; j<=n1y ; ++j){
176  c1 += s1*h1->GetBinContent(i,j);
177  c2 += s2*h2->GetBinContent(i,j);
178  double d = TMath::Abs(c1-c2)*TMath::Sqrt(esum1*esum2/(esum1+esum2));
179  h3->Fill(i,j,d);
180  dmax1 = TMath::Max(dmax1,TMath::Abs(c1-c2));
181  }
182  }
183 
184  c1 = 0, c2 = 0;
185 
186  double dmax2 = 0;
187  for (int j=1 ; j<=n1y ; ++j){
188  for (int i=1 ; i<=n1x ; ++i){
189  c1 += s1*h1->GetBinContent(i,j);
190  c2 += s2*h2->GetBinContent(i,j);
191  double d = TMath::Abs(c1-c2)*TMath::Sqrt(esum1*esum2/(esum1+esum2));
192  h3->Fill(i,j,d);
193  dmax1 = TMath::Max(dmax2,TMath::Abs(c1-c2));
194  }
195  }
196 
197  double dmax = 0.5*(dmax1+dmax2);
198  double z;
199 
200  if (afunc1)
201  z = dmax*TMath::Sqrt(esum2);
202  else if (afunc2)
203  z = dmax*TMath::Sqrt(esum1);
204  else
205  z = dmax*TMath::Sqrt(esum1*esum2/(esum1+esum2));
206 
207  double pValue = TMath::KolmogorovProb(z);
208 
209  for (int i=1 ; i<=n1x ; ++i){
210  for (int j=1 ; j<=n1y ; ++j){
211  h3->SetBinContent(i,j,TMath::KolmogorovProb(0.5 * h3->GetBinContent(i,j)));
212  }
213  }
214 
215  (pValue < threshold ? r.passed = false : r.passed = true);
216 
217  r.message = MAKE_STRING(scientific << setprecision(2)<< "Test: " << "Kolmogorov" <<
218  " HA: " << h1->GetUniqueID() << " " << h1->GetName() <<
219  " HB: " << h2->GetUniqueID() << " " << h2->GetName() <<
220  " Threshold: " << threshold << " Result: " << pValue << " " << (r.passed ? "PASSED" : "FAILED"));
221 
222 
223  JResultTitle title("KS", "P(compatible)", r.passed , pValue);
224 
225  h3->SetTitle(title.getTitle().c_str());
226 
227  r.obj = h3;
228 
229  return r;
230  };
#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
then print_variable DETECTOR INPUT_FILE INTERMEDIATE_FILE check_input_file $DETECTOR $INPUT_FILE check_output_file $INTERMEDIATE_FILE $OUTPUT_FILE JMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JPath.sh:52
#define ERROR(A)
Definition: JMessage.hh:66
string message
Definition: JTest_t.hh:65
TCanvas * c1
Global variables to handle mouse events.
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

Member Data Documentation

double JTestKolmogorov_1D::threshold
private

threshold p-value to decide if test is passed.

Definition at line 97 of file JTestKolmogorov_1D.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: