Implementation of a bin-by-bin Chi2 test for 2D histograms.
More...
#include <JTestChi2_Bin.hh>
|
| JTestChi2_Bin () |
| Default constructor. More...
|
|
void | test (const TObject *o1, const TObject *o2) override |
| Tests the statistical compatibility of two ROOT 2D histograms. More...
|
|
std::istream & | read (std::istream &in) override |
| Read test parameters from input. More...
|
|
virtual std::ostream & | write (std::ostream &out, const char delimiter= ' ', const bool onlyFailures=false) const |
| Write test result to output. More...
|
|
virtual void | save (TFile *f, const std::string &path, const bool onlyFailures=false) const |
| Writes the test result to root file. More...
|
|
const std::string & | getTestName () const |
| Get test name. More...
|
|
const std::string & | getResultType () const |
| Get result type. More...
|
|
Implementation of a bin-by-bin Chi2 test for 2D histograms.
This class is derived from the abstract class JTest_t(). For a general description of the implementation of this and other tests derived from JTest_t(), see its documentation.
Definition at line 27 of file JTestChi2_Bin.hh.
JCOMPAREHISTOGRAMS::JTestChi2_Bin::JTestChi2_Bin |
( |
| ) |
|
|
inline |
Default constructor.
Definition at line 35 of file JTestChi2_Bin.hh.
36 JTest_t(
"Chi2_Bin",
"Outliers[%]")
JTest_t(const std::string &testName, const std::string &resultType)
Constructor.
void JCOMPAREHISTOGRAMS::JTestChi2_Bin::test |
( |
const TObject * |
o1, |
|
|
const TObject * |
o2 |
|
) |
| |
|
inlineoverridevirtual |
Tests the statistical compatibility of two ROOT 2D histograms.
- Parameters
-
o1 | First histogram |
o2 | Second histogram |
Implements JCOMPAREHISTOGRAMS::JTest_t.
Definition at line 46 of file JTestChi2_Bin.hh.
51 const TH1* h1 =
dynamic_cast<const TH1*
>(o1);
52 const TH1* h2 =
dynamic_cast<const TH1*
>(o2);
54 if (h1 == NULL || h2 == NULL) {
55 THROW(JValueOutOfRange,
"JTestChi2_Bin::test(): Could not cast given TObjects to TH1.");
58 const int nx1 = h1->GetNbinsX();
59 const int nx2 = h2->GetNbinsX();
60 const int ny1 = h1->GetNbinsY();
61 const int ny2 = h2->GetNbinsY();
62 const int nz1 = h1->GetNbinsZ();
63 const int nz2 = h2->GetNbinsZ();
65 const double M = h1->GetSumOfWeights();
66 const double N = h2->GetSumOfWeights();
68 if(nx1 != nx2 || ny1 != ny2 || nz1 != nz2 || M == 0 ||
N == 0) {
69 THROW(JValueOutOfRange,
"JTestChi2_t::JChi2TestBin_2D(): Histograms with different binning or with zero entries.");
72 TH1* h3 = (TH1*) h1->Clone(h1->GetName() == h2->GetName() ?
80 for (
int i=1 ;
i<nx1 ; ++
i) {
81 for (
int j=1 ;
j<ny1 ; ++
j) {
82 for (
int k=1 ;
k<nz1 ; ++
k) {
84 const double m = h1->GetBinContent(
i,
j,
k);
85 const double n = h2->GetBinContent(
i,
j,
k);
87 const double em = h1->GetBinError(
i,
j,
k);
88 const double en = h2->GetBinError(
i,
j,
k);
90 if (n > 0.0 && m > 0.0 && em > 0.0 && en > 0.0) {
92 const double delta =
N*m - M*
n;
93 const double sigma = M*M*en*en +
N*
N*em*em;
97 outliers += 1./(nx1*ny1);
100 h3->SetBinContent(
i,
j,
k,chi2);
110 h3->SetTitle(title.getTitle().c_str());
112 const int Ndims = h3->GetDimension();
116 }
else if (Ndims == 2) {
121 JRootObjectID(
MAKE_STRING(h1->GetDirectory()->GetPath() << h1->GetName())),
122 JRootObjectID(
MAKE_STRING(h2->GetDirectory()->GetPath() << h1->GetName())),
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
#define MAKE_CSTRING(A)
Make C-string.
double chi2Threshold
threshold chi2-value to decide if test is passed for a bin.
#define MAKE_STRING(A)
Make string.
const std::string resultType
test result type
const std::string testName
test name
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
then if[[!-f $DETECTOR]] then JDetector sh $DETECTOR fi cat $WORKDIR trigger_parameters txt<< EOFtrigger3DMuon.enabled=1;trigger3DMuon.numberOfHits=5;trigger3DMuon.gridAngle_deg=1;ctMin=0.0;TMaxLocal_ns=15.0;EOF set_variable TRIGGEREFFICIENCY_TRIGGERED_EVENTS_ONLY INPUT_FILES=() for((i=1;$i<=$NUMBER_OF_RUNS;++i));do JSirene.sh $DETECTOR $JPP_DATA/genhen.km3net_wpd_V2_0.evt.gz $WORKDIR/sirene_ ${i}.root JTriggerEfficiency.sh $DETECTOR $DETECTOR $WORKDIR/sirene_ ${i}.root $WORKDIR/trigger_efficiency_ ${i}.root $WORKDIR/trigger_parameters.txt $JPP_DATA/PMT_parameters.txt INPUT_FILES+=($WORKDIR/trigger_efficiency_ ${i}.root) done for ANGLE_DEG in $ANGLES_DEG[*];do set_variable SIGMA_NS 3.0 set_variable OUTLIERS 3 set_variable OUTPUT_FILE $WORKDIR/matrix\[${ANGLE_DEG}\deg\].root $JPP_DIR/examples/JReconstruction-f"$INPUT_FILES[*]"-o $OUTPUT_FILE-S ${SIGMA_NS}-A ${ANGLE_DEG}-O ${OUTLIERS}-d ${DEBUG}--!fiif[[$OPTION=="plot"]];then if((0));then for H1 in h0 h1;do JPlot1D-f"$WORKDIR/matrix["${^ANGLES_DEG}" deg].root:${H1}"-y"1 2e3"-Y-L TR-T""-\^"number of events [a.u.]"-> o chi2
Structure containing the result of the test.
double outliersThreshold
fraction of bins allowed to fail the test.
std::istream& JCOMPAREHISTOGRAMS::JTestChi2_Bin::read |
( |
std::istream & |
in | ) |
|
|
inlineoverridevirtual |
Read test parameters from input.
- Parameters
-
- Returns
- input stream
Implements JCOMPAREHISTOGRAMS::JTest_t.
Definition at line 135 of file JTestChi2_Bin.hh.
142 THROW(JValueOutOfRange,
"JTestChi2_Bin::read(): Invalid chi2-threshold value " <<
chi2Threshold);
145 if (outliersThreshold < 0.0 || outliersThreshold > 1.0) {
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
double chi2Threshold
threshold chi2-value to decide if test is passed for a bin.
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
double outliersThreshold
fraction of bins allowed to fail the test.
virtual std::ostream& JCOMPAREHISTOGRAMS::JTest_t::write |
( |
std::ostream & |
out, |
|
|
const char |
delimiter = ' ' , |
|
|
const bool |
onlyFailures = false |
|
) |
| const |
|
inlinevirtualinherited |
Write test result to output.
- Parameters
-
out | output stream |
delimiter | field delimiter |
onlyFailures | if true, write only failures. |
- Returns
- output stream
Definition at line 84 of file JTest_t.hh.
93 if (onlyFailures &&
r->passed) {
continue; }
95 print(out, *
r, delimiter,
true);
std::ostream & print(std::ostream &out, const JTestSummary &summary, const char delimiter= ' ', const bool useColors=true)
Print test summary.
virtual void JCOMPAREHISTOGRAMS::JTest_t::save |
( |
TFile * |
f, |
|
|
const std::string & |
path, |
|
|
const bool |
onlyFailures = false |
|
) |
| const |
|
inlinevirtualinherited |
Writes the test result to root file.
- Parameters
-
f | A ROOT file |
path | Path in root file. |
onlyFailures | If true, write only failures. |
Definition at line 108 of file JTest_t.hh.
115 if (
f->GetDirectory(
path.c_str())==0) {
116 f->mkdir(
path.c_str());
123 if (onlyFailures &&
r->passed) {
continue; }
$WORKDIR driver txt done cat $WORKDIR driver txt<< EOFprocess ${DATAFILTER}$FILTER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&(JDataFilter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAFILTER}-P $PORT</dev/null > &/dev/null &))';process ${DATAWRITER}$WRITER_HOST csh-c '(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&(JDataWriter-H\$SERVER\$-M\$LOGGER\$-d $DEBUG-u ${DATAWRITER}</dev/null > &/dev/null &))';print enterevent ev_init{RC_CMD}event ev_reset{RC_CMD}event ev_init{RC_CMD}event ev_configure{RC_DFLTR%<$WORKDIR/ev_configure_datafilter.txt > RC_DQSIM<$WORKDIR/ev_configure_dqsimulator.txt > RC_DWRT path
then JHobbit a $DETECTOR f
const std::string& JCOMPAREHISTOGRAMS::JTest_t::getTestName |
( |
| ) |
const |
|
inlineinherited |
Get test name.
- Returns
- test name
Definition at line 135 of file JTest_t.hh.
const std::string testName
test name
const std::string& JCOMPAREHISTOGRAMS::JTest_t::getResultType |
( |
| ) |
const |
|
inlineinherited |
Get result type.
- Returns
- result type
Definition at line 146 of file JTest_t.hh.
const std::string resultType
test result type
double JCOMPAREHISTOGRAMS::JTestChi2_Bin::chi2Threshold |
|
private |
threshold chi2-value to decide if test is passed for a bin.
Definition at line 155 of file JTestChi2_Bin.hh.
double JCOMPAREHISTOGRAMS::JTestChi2_Bin::outliersThreshold |
|
private |
const std::string JCOMPAREHISTOGRAMS::JTest_t::testName |
|
protectedinherited |
const std::string JCOMPAREHISTOGRAMS::JTest_t::resultType |
|
protectedinherited |
The documentation for this class was generated from the following file: