Jpp 20.0.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JCOMPAREHISTOGRAMS::JTestSlice2D Class Reference

Abstract base class for 2D slice tests. More...

#include <JTestSlice2D.hh>

Inheritance diagram for JCOMPAREHISTOGRAMS::JTestSlice2D:
JCOMPAREHISTOGRAMS::JTest_t std::vector< JTestResult > JCOMPAREHISTOGRAMS::JTestChi2_Slice2D JCOMPAREHISTOGRAMS::JTestKolmogorov_Slice2D JCOMPAREHISTOGRAMS::JTestRuns_Slice2D

Public Member Functions

 JTestSlice2D (const std::string &testName, const std::string &resultType, JTest_t *p)
 Constructor.
 
void check (const TH1 *h1, const TH1 *h2) const
 Check if given input histograms have equal binning.
 
TH1 & getProjectionOntoSlicedAxis (const TH2 &h, const char *const name="projection", const Int_t firstBin=0, const Int_t lastBin=-1, const Option_t *option="") const
 Get projection of given 2D histogram onto sliced axis.
 
TH1 & getProjection (const TH2 &h, const char *const name="projection", const Int_t firstBin=0, const Int_t lastBin=-1, const Option_t *option="") const
 Get projection of given 2D histogram onto non-sliced axis.
 
void test (const TObject *o1, const TObject *o2) override
 Tests the statistical compatibility of two ROOT TObjects.
 
std::istream & read (std::istream &in) override
 Read test parameters from input.
 
virtual std::ostream & write (std::ostream &out, const char delimiter=' ', const bool onlyFailures=false) const
 Write test result to output.
 
virtual void save (TFile *f, const std::string &path, const bool onlyFailures=false) const
 Writes the test result to root file.
 
const std::string & getTestName () const
 Get test name.
 
const std::string & getResultType () const
 Get result type.
 

Protected Types

typedef TH1D *(TH2::*) pFunction(const char *, Int_t, Int_t, Option_t *) const
 Type definition of pointer to TH2 member function for projection.
 

Protected Attributes

pFunction mfp1
 Pointer to TH2 member method for projections onto the sliced axis.
 
pFunction mfp2
 Pointer to TH2 member method for projections onto the non-sliced axis.
 
std::unique_ptr< JTest_tpTest1D
 Unique pointer to 1D test variant.
 
double threshold
 threshold value to decide if test has passed.
 
double failuresThreshold
 threshold value to decide if test has passed.
 
char slice
 Axis to slice. x or X for x-axis, y or Y for y-axis, n or N for None.
 
const std::string testName
 test name
 
const std::string resultType
 test result type
 

Detailed Description

Abstract base class for 2D slice tests.

The parameter slice can have the values x, X, y or Y. The histograms are sliced along the corresponding axis, and the runs test is applied to each slice.
This test uses the input parameter threshold to evaluate whether the test is passed or failed for each slice.
The evaluation is done by comparing the threshold value with the result of the runs test.

Definition at line 29 of file JTestSlice2D.hh.

Member Typedef Documentation

◆ pFunction

TH1D *(TH2::*) JCOMPAREHISTOGRAMS::JTestSlice2D::pFunction(const char *, Int_t, Int_t, Option_t *) const
protected

Type definition of pointer to TH2 member function for projection.

Definition at line 260 of file JTestSlice2D.hh.

Constructor & Destructor Documentation

◆ JTestSlice2D()

JCOMPAREHISTOGRAMS::JTestSlice2D::JTestSlice2D ( const std::string & testName,
const std::string & resultType,
JTest_t * p )
inline

Constructor.

Parameters
testNametest name
resultTyperesult type
ppointer to 1D test variant

Definition at line 41 of file JTestSlice2D.hh.

43 :
45 mfp1(&TH2::ProjectionX),
46 mfp2(&TH2::ProjectionY),
47 pTest1D(p),
48 threshold(0.0),
50 slice('x')
51 {
52 using namespace JPP;
53
54 if (!p) {
55 THROW(JNullPointerException, "JTestSlice2D::JTestSlice2D(): Uninitialised 1D test variant");
56 }
57 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
pFunction mfp1
Pointer to TH2 member method for projections onto the sliced axis.
pFunction mfp2
Pointer to TH2 member method for projections onto the non-sliced axis.
std::unique_ptr< JTest_t > pTest1D
Unique pointer to 1D test variant.
char slice
Axis to slice. x or X for x-axis, y or Y for y-axis, n or N for None.
double threshold
threshold value to decide if test has passed.
double failuresThreshold
threshold value to decide if test has passed.
const std::string resultType
test result type
Definition JTest_t.hh:181
const std::string testName
test name
Definition JTest_t.hh:180
JTest_t(const std::string &testName, const std::string &resultType)
Constructor.
Definition JTest_t.hh:51
Exception for null pointer operation.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).

Member Function Documentation

◆ check()

void JCOMPAREHISTOGRAMS::JTestSlice2D::check ( const TH1 * h1,
const TH1 * h2 ) const
inline

Check if given input histograms have equal binning.

Parameters
h1first histogram
h2second histogram

Definition at line 66 of file JTestSlice2D.hh.

68 {
69 using namespace JPP;
70
71 if (h1 == NULL || h2 == NULL) {
72 THROW(JCastException, "JTestSlice2D::check(): Could not cast given TObjects to TH2.");
73 }
74
75 int nSlices1 = 0;
76 int nSlices2 = 0;
77
78 if (slice == 'x' || slice == 'X') {
79
80 nSlices1 = h1->GetNbinsX();
81 nSlices2 = h2->GetNbinsX();
82
83 } else if (slice == 'y' || slice == 'Y') {
84
85 nSlices1 = h1->GetNbinsY();
86 nSlices2 = h2->GetNbinsY();
87 }
88
89 if (nSlices1 != nSlices2) {
90 THROW(JValueOutOfRange, "JTestSlice2D::configure(): Histograms with different binning. The objects: " << h1->GetName() << " and " << h2->GetName() << " can not be compared");
91 }
92 }
Exception for cast operation.
Exception for accessing a value in a collection that is outside of its range.

◆ getProjectionOntoSlicedAxis()

TH1 & JCOMPAREHISTOGRAMS::JTestSlice2D::getProjectionOntoSlicedAxis ( const TH2 & h,
const char *const name = "projection",
const Int_t firstBin = 0,
const Int_t lastBin = -1,
const Option_t * option = "" ) const
inline

Get projection of given 2D histogram onto sliced axis.

Parameters
hhistogram
namename
firstBinfirst bin
lastBinlast bin
optionoption
Returns
projection of input histogram on sliced axis

Definition at line 105 of file JTestSlice2D.hh.

110 {
111 using namespace JPP;
112
113 TH1* hp = (h.*mfp1)(name, firstBin, lastBin, option);
114
115 if (hp != NULL) {
116 return *hp;
117 } else {
118 THROW(JNullPointerException, "JTestSlice2D::getProjectionOntoSlicedAxis(): Projection failed.");
119 }
120 }

◆ getProjection()

TH1 & JCOMPAREHISTOGRAMS::JTestSlice2D::getProjection ( const TH2 & h,
const char *const name = "projection",
const Int_t firstBin = 0,
const Int_t lastBin = -1,
const Option_t * option = "" ) const
inline

Get projection of given 2D histogram onto non-sliced axis.

Parameters
hhistogram
namename
firstBinfirst bin
lastBinlast bin
optionoption
Returns
projection of input histogram on sliced axis

Definition at line 133 of file JTestSlice2D.hh.

138 {
139 using namespace JPP;
140
141 TH1* hp = (h.*mfp2)(name, firstBin, lastBin, option);
142
143 if (hp != NULL) {
144 return *hp;
145 } else {
146 THROW(JNullPointerException, "JTestSlice2D::getProjection(): Projection failed.");
147 }
148 }

◆ test()

void JCOMPAREHISTOGRAMS::JTestSlice2D::test ( const TObject * o1,
const TObject * o2 )
inlineoverridevirtual

Tests the statistical compatibility of two ROOT TObjects.

Parameters
o1First object
o2Second object

Implements JCOMPAREHISTOGRAMS::JTest_t.

Definition at line 157 of file JTestSlice2D.hh.

158 {
159 using namespace std;
160 using namespace JPP;
161
162 const TH2* h1 = dynamic_cast<const TH2*>(o1);
163 const TH2* h2 = dynamic_cast<const TH2*>(o2);
164
165 check(h1, h2);
166
167 const char* const h3name = (h1->GetName() == h2->GetName() ?
168 MAKE_CSTRING(h1->GetName() << "_" << testName << "_" << slice) :
169 MAKE_CSTRING(h1->GetName() << "_VS_" << h2->GetName() << "_" << testName << "_" << slice));
170
171 TH1& h3 = getProjectionOntoSlicedAxis(*h1, h3name);
172
173 const int nSlices = h3.GetNbinsX();
174
175 int nFailures = 0;
176
177 for (int i=1 ; i<=nSlices ; ++i){
178
179 const std::string sliceName = MAKE_STRING(h3.GetName() << "_" << to_string(i));
180
181 const TH1& s1 = getProjection(*h1, sliceName.c_str(), i, i);
182 const TH1& s2 = getProjection(*h2, sliceName.c_str(), i, i);
183
184 if (!(s1.GetSumOfWeights() > 0 && s2.GetSumOfWeights() > 0)) { continue; }
185
186 pTest1D->test(&s1, &s2);
187
188 const JTestResult& result1D = pTest1D->back();
189
190 if (!result1D.passed) nFailures++;
191
192 h3.SetBinContent(i, result1D.parameterValue);
193 }
194
195 const bool passed = (nFailures/((double) nSlices) < failuresThreshold);
196
197 const JResultTitle title(testName, resultType, passed , nFailures);
198
199 h3.SetTitle(title.getTitle().c_str());
200 h3.GetYaxis()->SetTitle(resultType.c_str());
201
202 const JTestResult r(testName,
203 JRootObjectID(MAKE_STRING(h1->GetDirectory()->GetPath() << h1->GetName())),
204 JRootObjectID(MAKE_STRING(h2->GetDirectory()->GetPath() << h1->GetName())),
205 resultType, nFailures, failuresThreshold, h3.Clone(), passed);
206
207 this->push_back(r);
208
209 pTest1D->clear();
210 }
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
void check(const TH1 *h1, const TH1 *h2) const
Check if given input histograms have equal binning.
TH1 & getProjectionOntoSlicedAxis(const TH2 &h, const char *const name="projection", const Int_t firstBin=0, const Int_t lastBin=-1, const Option_t *option="") const
Get projection of given 2D histogram onto sliced axis.
TH1 & getProjection(const TH2 &h, const char *const name="projection", const Int_t firstBin=0, const Int_t lastBin=-1, const Option_t *option="") const
Get projection of given 2D histogram onto non-sliced axis.
Auxiliary class to handle file name, ROOT directory and object name.
std::string to_string(const T &value)
Convert value to string.
Structure containing the result of the test.

◆ read()

std::istream & JCOMPAREHISTOGRAMS::JTestSlice2D::read ( std::istream & in)
inlineoverridevirtual

Read test parameters from input.

Parameters
ininput stream
Returns
input stream

Implements JCOMPAREHISTOGRAMS::JTest_t.

Definition at line 219 of file JTestSlice2D.hh.

220 {
221 using namespace std;
222 using namespace JPP;
223
224 if (pTest1D) {
225
226 try {
227 in >> (*pTest1D);
228 }
229 catch (const std::exception& error) {
230 THROW(JValueOutOfRange, "JTestSlice2D::read(): Could not read 1D test variant parameters due to the following error:" << endl << error.what());
231 }
232
233 } else {
234 THROW(JNullPointerException, "JTestSlice2D::read(): 1D test variant is not set");
235 }
236
237 in >> failuresThreshold >> slice;
238
240 THROW(JValueOutOfRange, "JTestSlice2D::read(): Invalid failuresThreshold value " << failuresThreshold);
241 }
242
243 if (slice == 'x' || slice == 'X') {
244 mfp1 = &TH2::ProjectionX;
245 mfp2 = &TH2::ProjectionY;
246 } else if (slice == 'y' || slice == 'Y') {
247 mfp1 = &TH2::ProjectionY;
248 mfp2 = &TH2::ProjectionX;
249 } else {
250 THROW(JValueOutOfRange, "JTestSlice2D::read(): Invalid slice option \'" << slice << "\'");
251 }
252
253 return in;
254 };

◆ write()

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
outoutput stream
delimiterfield delimiter
onlyFailuresif true, write only failures.
Returns
output stream

Definition at line 84 of file JTest_t.hh.

87 {
88 using namespace std;
89 using namespace JPP;
90
91 for (vector<JTestResult>::const_iterator r = this->begin() ; r != this->end() ; ++r) {
92
93 if (onlyFailures && r->passed) { continue; }
94
95 print(out, *r, delimiter, true);
96 }
97
98 return out;
99 }
std::ostream & print(std::ostream &out, const JTestSummary &summary, T __begin, T __end, const bool useColors=true, const JFormat_t &formatting=JFormat_t(18, 3, std::ios::fixed))
Print test summary.

◆ save()

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
fA ROOT file
pathPath in root file.
onlyFailuresIf true, write only failures.

Definition at line 108 of file JTest_t.hh.

111 {
112 using namespace std;
113 using namespace JPP;
114
115 if (f->GetDirectory(path.c_str())==0) {
116 f->mkdir(path.c_str());
117 }
118
119 f->cd(path.c_str());
120
121 for (vector<JTestResult>::const_iterator r = this->begin() ; r != this->end() ; ++r) {
122
123 if (onlyFailures && r->passed) { continue; }
124
125 r->obj->Write();
126 }
127 }

◆ getTestName()

const std::string & JCOMPAREHISTOGRAMS::JTest_t::getTestName ( ) const
inlineinherited

Get test name.

Returns
test name

Definition at line 135 of file JTest_t.hh.

136 {
137 return testName;
138 }

◆ getResultType()

const std::string & JCOMPAREHISTOGRAMS::JTest_t::getResultType ( ) const
inlineinherited

Get result type.

Returns
result type

Definition at line 146 of file JTest_t.hh.

147 {
148 return resultType;
149 }

Member Data Documentation

◆ mfp1

pFunction JCOMPAREHISTOGRAMS::JTestSlice2D::mfp1
protected

Pointer to TH2 member method for projections onto the sliced axis.

Definition at line 262 of file JTestSlice2D.hh.

◆ mfp2

pFunction JCOMPAREHISTOGRAMS::JTestSlice2D::mfp2
protected

Pointer to TH2 member method for projections onto the non-sliced axis.

Definition at line 263 of file JTestSlice2D.hh.

◆ pTest1D

std::unique_ptr<JTest_t> JCOMPAREHISTOGRAMS::JTestSlice2D::pTest1D
protected

Unique pointer to 1D test variant.

Definition at line 265 of file JTestSlice2D.hh.

◆ threshold

double JCOMPAREHISTOGRAMS::JTestSlice2D::threshold
protected

threshold value to decide if test has passed.

Definition at line 267 of file JTestSlice2D.hh.

◆ failuresThreshold

double JCOMPAREHISTOGRAMS::JTestSlice2D::failuresThreshold
protected

threshold value to decide if test has passed.

Definition at line 268 of file JTestSlice2D.hh.

◆ slice

char JCOMPAREHISTOGRAMS::JTestSlice2D::slice
protected

Axis to slice. x or X for x-axis, y or Y for y-axis, n or N for None.

Definition at line 269 of file JTestSlice2D.hh.

◆ testName

const std::string JCOMPAREHISTOGRAMS::JTest_t::testName
protectedinherited

test name

Definition at line 180 of file JTest_t.hh.

◆ resultType

const std::string JCOMPAREHISTOGRAMS::JTest_t::resultType
protectedinherited

test result type

Definition at line 181 of file JTest_t.hh.


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