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

#include <JTestKolmogorov_t.hh>

Inheritance diagram for JTestKolmogorov_t:
JTestKolmogorov_1D JTestKolmogorov_2D

Public Member Functions

 JTestKolmogorov_t ()
 
JTestResult JKolmogorovTest (TH1 *h1, TH1 *h2, double threshold)
 
JTestResult JKolmogorovTest2D (TH2 *h1, TH2 *h2, double threshold)
 

Detailed Description

Definition at line 15 of file JTestKolmogorov_t.hh.

Constructor & Destructor Documentation

JTestKolmogorov_t::JTestKolmogorov_t ( )
inline

Definition at line 21 of file JTestKolmogorov_t.hh.

21 {}

Member Function Documentation

JTestResult JTestKolmogorov_t::JKolmogorovTest ( TH1 *  h1,
TH1 *  h2,
double  threshold 
)
inline

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 
)
inline

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

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