Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JTestRuns_t.hh
Go to the documentation of this file.
1 #ifndef __JTESTRUNS_T__
2 #define __JTESTRUNS_T__
3 
4 #include <iostream>
5 #include "JTest_t.hh"
6 
7 using namespace std;
8 
9 /*
10  * Runs test.
11  */
13 {
14 public:
15 
17 
18  /*
19  * Tests the statistical compatibility of two ROOT TObjects
20  *
21  * \param h1 First object
22  * \param h2 Second object
23  */
24  JTestResult JRunsTest(TH1* h1, TH1* h2, double threshold, bool logX, bool logY) {
25 
26  JTestResult r;
27 
28  if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
29  ERROR("Histograms with different bining. The objects: " << h1 -> GetName() << " can not be compared." << endl);
30 
31  double R = h1->Integral();
32  double T = h2->Integral();
33 
34  int n = 1;
35  double p = 0;
36  double q = 0;
37 
38  bool a = ((T/R)*h1->GetBinContent(1) - h2->GetBinContent(1)) < 0;
39 
40  (a ? p++ : q++);
41 
42  for (int i = 2 ; i<h1->GetNbinsX() ; ++i){
43 
44  bool b = ((T/R)*h1->GetBinContent(i) - h2->GetBinContent(i)) < 0;
45 
46  (b ? p++ : q++);
47 
48  if (b != a){
49  n++;
50  a=b;
51  }
52  }
53 
54  double N = 1 + 2*p*q/(p+q) ;
55  double s = sqrt( 2*p*q*(2*p*q-p-q)/(p+q)/(p+q)/(p+q-1) );
56  double d = (n-N)/s;
57 
58  (fabs(d) > threshold ? r.passed = false : r.passed = true);
59 
60  r.message = MAKE_STRING(scientific << setprecision(2)<< "Test: " << "Runs" <<
61  " HA: " << h1->GetUniqueID() << " " << h1->GetName() <<
62  " HB: " << h2->GetUniqueID() << " " << h2->GetName() <<
63  " Threshold: " << threshold << " Result: " << fabs(d) << " " << (r.passed ? "PASSED" : "FAILED"));
64 
65  TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
66  MAKE_CSTRING(to_string(h1->GetName())) :
67  MAKE_CSTRING(to_string(h1->GetName()) + "_VS_" + to_string(h2->GetName())));
68 
69  for (int i=1 ; i<h1->GetNbinsX() ; ++i) {
70  h3->SetBinContent(i , (T/R)*h1->GetBinContent(i) - h2->GetBinContent(i));
71  }
72 
73  JResultTitle title("Runs", "Deviation[#sigma] ", r.passed , fabs(d));
74 
75  h3->SetTitle(title.getTitle().c_str());
76 
77  r.obj = h3;
78 
79  return r;
80  };
81 };
82 
83 #endif
#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
fi JEventTimesliceWriter a
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:699
do set_variable OUTPUT_DIRECTORY $WORKDIR T
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 getTitle()
Definition: JTest_t.hh:48
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:40
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.
JTestResult JRunsTest(TH1 *h1, TH1 *h2, double threshold, bool logX, bool logY)
Definition: JTestRuns_t.hh:24
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