1 #ifndef __JCOMPAREHISTOGRAMS__JTESTCHI2_T__
2 #define __JCOMPAREHISTOGRAMS__JTESTCHI2_T__
14 namespace JCOMPAREHISTOGRAMS {
50 if(h1 -> GetNbinsX() != h2 -> GetNbinsX())
51 ERROR(
"Histograms with different bining. The objects: " << h1 -> GetName() <<
" can not be compared." << endl);
53 double chi2 = h1 -> Chi2Test (h2 , options.c_str());
55 double M = h1->Integral();
56 double N = h2->Integral();
58 TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
64 for (
int i=1 ; i < h1->GetNbinsX() ; ++i){
66 double m = h1->GetBinContent(i);
67 double n = h2->GetBinContent(i);
70 double c = (M*n -
N*m)/sqrt((n+m)*(
N*M));
71 h3->SetBinContent(i,c);
77 if (options.find(
"CHI2") != std::string::npos) {
78 (
chi2 > threshold ? passed =
false : passed =
true);
80 (
chi2 < threshold ? passed =
false : passed =
true);
85 h3->SetTitle(title.
getTitle().c_str());
90 parameterName,
chi2, threshold, h3, passed);
124 if(slice ==
'x' || slice ==
'X'){
126 int nSlices1 = h1->GetNbinsX();
127 int nSlices2 = h2->GetNbinsX();
129 TH1* h3 = h1->ProjectionX(
MAKE_CSTRING(h1->GetName() <<
"_VS_" <<
130 h2->GetName() <<
"_Chi2TestSliceX"));
132 if (nSlices1 != nSlices2) {
133 ERROR(
"Histograms with different binning. The objects: " << h1->GetName() <<
" and " << h2->GetName() <<
" can not be compared." << endl);
136 for (
int i=1 ; i<=nSlices1 ; ++i){
140 TH1D* s1 = h1->ProjectionY (sliceName.c_str(),i,i);
141 TH1D* s2 = h2->ProjectionY (sliceName.c_str(),i,i);
143 if (!(s1->GetSumOfWeights() > 0 && s2->GetSumOfWeights() > 0)) {
continue; }
145 double chi2 = s1->Chi2Test(s2 , options.c_str());
147 bool passed = (options.find(
"CHI2") != std::string::npos ?
148 (chi2 > threshold ?
false :
true) :
149 (chi2 < threshold ?
false :
true));
151 if (!passed) nFailures++;
153 h3->SetBinContent(i,chi2);
156 bool passed = (nFailures/nSlices1 > failuresThreshold ?
false :
true);
158 JResultTitle title(testName, parameterName, passed , nFailures);
160 h3->SetTitle(title.
getTitle().c_str());
165 parameterName, nFailures, failuresThreshold, h3, passed);
167 }
else if (slice ==
'y' || slice ==
'Y') {
169 int nSlices1 = h1->GetNbinsY();
170 int nSlices2 = h2->GetNbinsY();
172 TH1* h3 = h1->ProjectionY(
MAKE_CSTRING(h1->GetName() <<
"_VS_" <<
173 h2->GetName() <<
"_Chi2TestSliceY"));
175 if (nSlices1 != nSlices2) {
176 ERROR(
"Histograms with different binning. The objects: " << h1->GetName() <<
" can not be compared." << endl);
179 for (
int i=1 ; i<=nSlices1 ; ++i){
183 TH1D* s1 = h1->ProjectionX (sliceName.c_str(),i,i);
184 TH1D* s2 = h2->ProjectionX (sliceName.c_str(),i,i);
186 if (!(s1->GetSumOfWeights() > 0 && s2->GetSumOfWeights() > 0)) {
continue; }
188 double chi2 = s1 -> Chi2Test (s2 , options.c_str());
190 bool passed = (options.find(
"CHI2") != std::string::npos ?
191 (chi2 > threshold ?
false :
true) :
192 (chi2 < threshold ?
false :
true));;
194 if (!passed) nFailures++;
196 h3->SetBinContent(i,chi2);
199 bool passed = (nFailures/nSlices1 > failuresThreshold ?
false :
true);
201 JResultTitle title(testName, parameterName, passed , nFailures);
203 h3->SetTitle(title.
getTitle().c_str());
208 parameterName, nFailures, failuresThreshold, h3, passed);
236 int nx1 = h1->GetNbinsX();
237 int nx2 = h2->GetNbinsX();
238 int ny1 = h1->GetNbinsY();
239 int ny2 = h2->GetNbinsY();
241 double M = h1->Integral();
242 double N = h2->Integral();
244 if(nx1 != nx2 || ny1 != ny2 || M == 0 ||
N == 0)
245 ERROR(
"Histograms with different binning. The objects: " << h1->GetName() <<
" can not be compared." << endl);
247 TH2D* h3 = (TH2D*)h1->Clone(h1->GetName()==h2->GetName() ?
255 for (
int i=1 ; i<nx1 ; ++i){
256 for (
int j=1 ;
j<ny1 ; ++
j){
258 double m = h1 -> GetBinContent(i,
j);
259 double n = h2 -> GetBinContent(i,
j);
260 double chi2 = (n-m*
N/M)/sqrt(m*
N/M);
261 (fabs(chi2) > chi2Threshold ? outliers+=1./(nx1*ny1) : outliers+=0 );
262 h3->SetBinContent(i,
j,chi2);
268 (outliers > outliersThreshold ? passed =
false : passed =
true);
270 JResultTitle title(testName, parameterName , passed , 100*outliers);
272 h3->SetTitle(title.
getTitle().c_str());
277 parameterName, 100*outliers, 100*outliersThreshold, h3, passed);
JTestResult JChi2TestSlice(TH2 *h1, TH2 *h2, double threshold, double failuresThreshold, std::string testName, std::string parameterName, std::string options, char slice)
Chi2 test for sliced 2D histograms.
JTestResult JChi2Test(TH1 *h1, TH1 *h2, double threshold, std::string testName, std::string parameterName, std::string options)
Chi2 test for 1D histograms.
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
JTestResult JChi2TestBin_2D(TH2 *h1, TH2 *h2, double outliersThreshold, double chi2Threshold, std::string testName, std::string parameterName)
Bin-by-Bin Chi2 comparison of 2D histograms.
then JShowerPostfit f $INPUT_FILE o $OUTPUT_FILE N
#define MAKE_CSTRING(A)
Make C-string.
Auxiliary class to handle file name, ROOT directory and object name.
#define MAKE_STRING(A)
Make string.
JTestChi2_t()
Default constructor.
then usage $script[port]< option > nPossible options
$WORKDIR ev_configure_dqsimulator txt echo process $DQ_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DQ_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
std::string to_string(const T &value)
Convert value to string.
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.
std::string getTitle()
Returns a standard string to be used as title of a graphical root object.
Implementation of the different Chi2-related tests.