Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// @(#)root/test:$name: $:$id: stressHistogram.cxx,v 1.15 2002/10/25 10:47:51 rdm exp $
// Authors: David Gonzalez Maline November 2008
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*//
// //
// //
// Here there is a set of tests for the histogram classes (including //
// histograms and profiles). The methods tested work on: //
// //
// 1. Projection testing (with and without weights) //
// 2. Rebinning //
// 3. Addition, multiplication an division operations. //
// 4. Building and copying instances. //
// 5. I/O functionality (including reference with older versions). //
// 6. Labeling. //
// 7. Interpolation //
// //
// To see the tests individually, at the bottom of the file the tests //
// are exectued using the structure TTestSuite, that defines the //
// subset, the number of routines to be tested as well as the pointes //
// for these. Every tests is mean to be simple enough to be understood //
// without much comments. //
// //
// Finally, for debugging reasons, the struct compareOptions can be //
// used to define the level of output of the tests, beging set //
// generally for the whole suit in defaultEqualOptions. //
// //
// //
// An example of output when all the tests run OK is shown below: //
// **************************************************************************** //
// * Starting stress H I S T O G R A M * //
// **************************************************************************** //
// Test 1: Testing Projections without weights..............................OK //
// Test 2: Testing Projections with weights.................................OK //
// Test 3: Histogram Rebinning..............................................OK //
// Test 4: Add tests for 1D, 2D and 3D Histograms and Profiles..............OK //
// Test 5: Multiply tests for 1D, 2D and 3D Histograms......................OK //
// Test 6: Divide tests for 1D, 2D and 3D Histograms........................OK //
// Test 7: Copy tests for 1D, 2D and 3D Histograms and Profiles.............OK //
// Test 8: Read/Write tests for 1D, 2D and 3D Histograms and Profiles.......OK //
// Test 9: Merge tests for 1D, 2D and 3D Histograms and Profiles............OK //
// Test 10: Label tests for 1D Histograms (TAxis)............................OK //
// Test 11: Interpolation tests for Histograms...............................OK //
// Test 12: Reference File Read for Histograms and Profiles..................OK //
// **************************************************************************** //
// stressHistogram: Real Time = 48.82 seconds Cpu Time = 48.66 seconds //
// ROOTMARKS = 565.557 ROOT version: 5.23/01 branches/dev/mathDev@27607 //
// **************************************************************************** //
// //
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*//
#include <sstream>
#include <cmath>
#include "TH2.h"
#include "TH3.h"
#include "TH2.h"
#include "THnSparse.h"
#include "TProfile.h"
#include "TProfile2D.h"
#include "TProfile3D.h"
#include "TApplication.h"
Lorenzo Moneta
committed
#include "TBenchmark.h"
#include "Riostream.h"
#include "TMath.h"
#include "TRandom2.h"
#include "TFile.h"
#include "TROOT.h"
#include <algorithm>
const unsigned int __DRAW__ = 0;
const Double_t minRange = 1;
const Double_t maxRange = 5;
const Double_t minRebin = 3;
const Double_t maxRebin = 7;
const int minBinValue = 1;
const int maxBinValue = 10;
const int nEvents = 1000;
const int numberOfBins = 10;
enum compareOptions {
Lorenzo Moneta
committed
cmpOptNone=0,
cmpOptPrint=1,
cmpOptDebug=2,
cmpOptNoError=4,
cmpOptStats=8
const int defaultEqualOptions = 0; //cmpOptPrint;
Lorenzo Moneta
committed
const double defaultErrorLimit = 1.E-10;
enum RefFileEnum {
refFileRead = 1,
refFileWrite = 2
};
const int refFileOption = 1;
TFile * refFile = 0;
const char* refFileName = "http://root.cern.ch/files/stressHistogram.5.18.00.root";
// set to zero if want to run different every time
const int initialSeed = 111;
typedef bool ( * pointer2Test) ();
struct TTestSuite {
unsigned int nTests;
char suiteName[75];
pointer2Test* tests;
};
// Methods for histogram comparisions (later implemented)
void printResult(const char* msg, bool status);
Lorenzo Moneta
committed
int equals(const char* msg, TH1D* h1, TH1D* h2, int options = 0, double ERRORLIMIT = defaultErrorLimit);
int equals(const char* msg, TH2D* h1, TH2D* h2, int options = 0, double ERRORLIMIT = defaultErrorLimit);
int equals(const char* msg, TH3D* h1, TH3D* h2, int options = 0, double ERRORLIMIT = defaultErrorLimit);
int equals(const char* msg, THnSparse* h1, THnSparse* h2, int options = 0, double ERRORLIMIT = defaultErrorLimit);
int equals(Double_t n1, Double_t n2, double ERRORLIMIT = defaultErrorLimit);
int compareStatistics( TH1* h1, TH1* h2, bool debug, double ERRORLIMIT = defaultErrorLimit);
ostream& operator<<(ostream& out, TH1D* h);
// old stresHistOpts.cxx file
bool testAdd1()
{
// Tests the first Add method for 1D Histograms
Double_t c1 = r.Rndm();
Double_t c2 = r.Rndm();
TH1D* h1 = new TH1D("t1D1-h1", "h1-Title", numberOfBins, minRange, maxRange);
TH1D* h2 = new TH1D("t1D1-h2", "h2-Title", numberOfBins, minRange, maxRange);
TH1D* h3 = new TH1D("t1D1-h3", "h3=c1*h1+c2*h2", numberOfBins, minRange, maxRange);
h1->Sumw2();h2->Sumw2();h3->Sumw2();
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(value, 1.0);
h3->Fill(value, c1);
}
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(value, 1.0);
h3->Fill(value, c2);
}
TH1D* h4 = new TH1D("t1D1-h4", "h4=c1*h1+h2*c2", numberOfBins, minRange, maxRange);
h4->Add(h1, h2, c1, c2);
bool ret = equals("Add1D1", h3, h4, cmpOptStats, 1E-13);
delete h1;
delete h2;
delete h3;
return ret;
}
bool testAddProfile1()
{
// Tests the first Add method for 1D Profiles
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
Double_t c1 = r.Rndm();
Double_t c2 = r.Rndm();
TProfile* p1 = new TProfile("t1D1-p1", "p1-Title", numberOfBins, minRange, maxRange);
TProfile* p2 = new TProfile("t1D1-p2", "p2-Title", numberOfBins, minRange, maxRange);
TProfile* p3 = new TProfile("t1D1-p3", "p3=c1*p1+c2*p2", numberOfBins, minRange, maxRange);
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p1->Fill(x, y, 1.0);
p3->Fill(x, y, c1);
}
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p2->Fill(x, y, 1.0);
p3->Fill(x, y, c2);
}
TProfile* p4 = new TProfile("t1D1-p4", "p4=c1*p1+p2*c2", numberOfBins, minRange, maxRange);
p4->Add(p1, p2, c1, c2);
bool ret = equals("Add1DProfile1", p3, p4, cmpOptStats, 1E-13);
delete p1;
delete p2;
delete p3;
return ret;
}
bool testAdd2()
{
// Tests the second Add method for 1D Histograms
Double_t c2 = r.Rndm();
TH1D* h5 = new TH1D("t1D2-h5", "h5= h6+c2*h7", numberOfBins, minRange, maxRange);
TH1D* h6 = new TH1D("t1D2-h6", "h6-Title", numberOfBins, minRange, maxRange);
TH1D* h7 = new TH1D("t1D2-h7", "h7-Title", numberOfBins, minRange, maxRange);
h5->Sumw2();h6->Sumw2();h7->Sumw2();
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h6->Fill(value, 1.0);
h5->Fill(value, 1.0);
}
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h7->Fill(value, 1.0);
h5->Fill(value, c2);
}
h6->Add(h7, c2);
bool ret = equals("Add1D2", h5, h6, cmpOptStats, 1E-13);
delete h5;
delete h7;
return ret;
}
bool testAddProfile2()
{
// Tests the second Add method for 1D Profiles
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
Double_t c2 = r.Rndm();
TProfile* p5 = new TProfile("t1D2-p5", "p5= p6+c2*p7", numberOfBins, minRange, maxRange);
TProfile* p6 = new TProfile("t1D2-p6", "p6-Title", numberOfBins, minRange, maxRange);
TProfile* p7 = new TProfile("t1D2-p7", "p7-Title", numberOfBins, minRange, maxRange);
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p6->Fill(x, y, 1.0);
p5->Fill(x, y, 1.0);
}
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p7->Fill(x, y, 1.0);
p5->Fill(x, y, c2);
}
p6->Add(p7, c2);
bool ret = equals("Add1DProfile2", p5, p6, cmpOptStats, 1E-13);
delete p5;
delete p7;
return ret;
}
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
bool testAdd3()
{
// Tests the first add method to do scalation of 1D Histograms
Double_t c1 = r.Rndm();
TH1D* h1 = new TH1D("t1D1-h1", "h1-Title", numberOfBins, minRange, maxRange);
TH1D* h2 = new TH1D("t1D1-h2", "h2=c1*h1+c2*h2", numberOfBins, minRange, maxRange);
h1->Sumw2();h2->Sumw2();
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(value, 1.0);
h2->Fill(value, c1 / h1->GetBinWidth( h1->FindBin(value) ) );
}
TH1D* h3 = new TH1D("t1D1-h3", "h3=c1*h1", numberOfBins, minRange, maxRange);
h3->Add(h1, h1, c1, -1);
bool ret = equals("Add1D1", h2, h3, cmpOptStats, 1E-13);
delete h1;
delete h2;
return ret;
}
bool testAdd2D3()
{
// Tests the first add method to do scalation of 2D Histograms
Double_t c1 = r.Rndm();
TH2D* h1 = new TH2D("t1D1-h1", "h1-Title",
numberOfBins, minRange, maxRange,
numberOfBins+2, minRange, maxRange);
TH2D* h2 = new TH2D("t1D1-h2", "h2=c1*h1+c2*h2",
numberOfBins, minRange, maxRange,
numberOfBins+2, minRange, maxRange);
h1->Sumw2();h2->Sumw2();
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(x, y, 1.0);
Int_t binx = h1->GetXaxis()->FindBin(x);
Int_t biny = h1->GetYaxis()->FindBin(y);
Double_t area = h1->GetXaxis()->GetBinWidth( binx ) * h1->GetYaxis()->GetBinWidth( biny );
h2->Fill(x, y, c1 / area);
}
TH2D* h3 = new TH2D("t1D1-h3", "h3=c1*h1",
numberOfBins, minRange, maxRange,
numberOfBins+2, minRange, maxRange);
h3->Add(h1, h1, c1, -1);
bool ret = equals("Add1D2", h2, h3, cmpOptStats, 1E-10);
delete h1;
delete h2;
return ret;
}
bool testAdd3D3()
{
// Tests the first add method to do scalation of 3D Histograms
Double_t c1 = r.Rndm();
TH3D* h1 = new TH3D("t1D1-h1", "h1-Title",
numberOfBins, minRange, maxRange,
numberOfBins+1, minRange, maxRange,
numberOfBins+2, minRange, maxRange);
TH3D* h2 = new TH3D("t1D1-h2", "h2=c1*h1+c2*h2",
numberOfBins, minRange, maxRange,
numberOfBins+1, minRange, maxRange,
numberOfBins+2, minRange, maxRange);
h1->Sumw2();h2->Sumw2();
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(x, y, z, 1.0);
Int_t binx = h1->GetXaxis()->FindBin(x);
Int_t biny = h1->GetYaxis()->FindBin(y);
Int_t binz = h1->GetZaxis()->FindBin(z);
Double_t area = h1->GetXaxis()->GetBinWidth( binx ) *
h1->GetYaxis()->GetBinWidth( biny ) *
h1->GetZaxis()->GetBinWidth( binz );
h2->Fill(x, y, z, c1 / area);
}
TH3D* h3 = new TH3D("t1D1-h3", "h3=c1*h1",
numberOfBins, minRange, maxRange,
numberOfBins+1, minRange, maxRange,
numberOfBins+2, minRange, maxRange);
h3->Add(h1, h1, c1, -1);
bool ret = equals("Add2D3", h2, h3, cmpOptStats, 1E-10);
delete h1;
delete h2;
return ret;
}
bool testAdd2D1()
{
// Tests the first Add method for 2D Histograms
Double_t c1 = r.Rndm();
Double_t c2 = r.Rndm();
TH2D* h1 = new TH2D("t2D1-h1", "h1",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TH2D* h2 = new TH2D("t2D1-h2", "h2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TH2D* h3 = new TH2D("t2D1-h3", "h3=c1*h1+c2*h2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
h1->Sumw2();h2->Sumw2();h3->Sumw2();
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(x, y, 1.0);
h3->Fill(x, y, c1);
}
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(x, y, 1.0);
h3->Fill(x, y, c2);
}
TH2D* h4 = new TH2D("t2D1-h4", "h4=c1*h1+c2*h2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
h4->Add(h1, h2, c1, c2);
bool ret = equals("Add2D1", h3, h4, cmpOptStats , 1E-10);
delete h1;
delete h2;
delete h3;
return ret;
}
bool testAdd2DProfile1()
{
// Tests the first Add method for 1D Profiles
Double_t c1 = r.Rndm();
Double_t c2 = r.Rndm();
TProfile2D* p1 = new TProfile2D("t2D1-p1", "p1",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TProfile2D* p2 = new TProfile2D("t2D1-p2", "p2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TProfile2D* p3 = new TProfile2D("t2D1-p3", "p3=c1*p1+c2*p2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p1->Fill(x, y, z, 1.0);
p3->Fill(x, y, z, c1);
}
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p2->Fill(x, y, z, 1.0);
p3->Fill(x, y, z, c2);
}
TProfile2D* p4 = new TProfile2D("t2D1-p4", "p4=c1*p1+c2*p2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
p4->Add(p1, p2, c1, c2);
bool ret = equals("Add2DProfile1", p3, p4, cmpOptStats , 1E-10);
delete p1;
delete p2;
delete p3;
return ret;
}
bool testAdd2D2()
{
// Tests the second Add method for 2D Histograms
Double_t c2 = r.Rndm();
TH2D* h1 = new TH2D("t2D2-h1", "h1",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TH2D* h2 = new TH2D("t2D2-h2", "h2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TH2D* h3 = new TH2D("t2D2-h3", "h3=h1+c2*h2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
h1->Sumw2();h2->Sumw2();h3->Sumw2();
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(x, y, 1.0);
h3->Fill(x, y, 1.0);
}
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(x, y, 1.0);
h3->Fill(x, y, c2);
}
h1->Add(h2, c2);
bool ret = equals("Add2D2", h3, h1, cmpOptStats, 1E-10);
delete h2;
delete h3;
return ret;
}
bool testAdd2DProfile2()
{
// Tests the second Add method for 2D Profiles
Double_t c2 = r.Rndm();
TProfile2D* p1 = new TProfile2D("t2D2-p1", "p1",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TProfile2D* p2 = new TProfile2D("t2D2-p2", "p2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TProfile2D* p3 = new TProfile2D("t2D2-p3", "p3=p1+c2*p2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p1->Fill(x, y, z, 1.0);
p3->Fill(x, y, z, 1.0);
}
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p2->Fill(x, y, z, 1.0);
p3->Fill(x, y, z, c2);
}
p1->Add(p2, c2);
bool ret = equals("Add2DProfile2", p3, p1, cmpOptStats, 1E-10);
delete p2;
delete p3;
return ret;
}
bool testAdd3D1()
{
// Tests the first Add method for 3D Histograms
Double_t c1 = r.Rndm();
Double_t c2 = r.Rndm();
TH3D* h1 = new TH3D("t3D1-h1", "h1",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TH3D* h2 = new TH3D("t3D1-h2", "h2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TH3D* h3 = new TH3D("t3D1-h3", "h3=c1*h1+c2*h2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
h1->Sumw2();h2->Sumw2();h3->Sumw2();
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(x, y, z, 1.0);
h3->Fill(x, y, z, c1);
}
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(x, y, z, 1.0);
h3->Fill(x, y, z, c2);
}
TH3D* h4 = new TH3D("t3D1-h4", "h4=c1*h1+c2*h2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
h4->Add(h1, h2, c1, c2);
bool ret = equals("Add3D1", h3, h4, cmpOptStats, 1E-10);
delete h1;
delete h2;
delete h3;
return ret;
}
bool testAdd3DProfile1()
{
// Tests the second Add method for 3D Profiles
Double_t c1 = r.Rndm();
Double_t c2 = r.Rndm();
TProfile3D* p1 = new TProfile3D("t3D1-p1", "p1",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TProfile3D* p2 = new TProfile3D("t3D1-p2", "p2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TProfile3D* p3 = new TProfile3D("t3D1-p3", "p3=c1*p1+c2*p2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t t = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p1->Fill(x, y, z, t, 1.0);
p3->Fill(x, y, z, t, c1);
}
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t t = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p2->Fill(x, y, z, t, 1.0);
p3->Fill(x, y, z, t, c2);
}
TProfile3D* p4 = new TProfile3D("t3D1-p4", "p4=c1*p1+c2*p2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
p4->Add(p1, p2, c1, c2);
bool ret = equals("Add3DProfile1", p3, p4, cmpOptStats, 1E-10);
delete p1;
delete p2;
delete p3;
return ret;
}
bool testAdd3D2()
{
// Tests the second Add method for 3D Histograms
Double_t c2 = r.Rndm();
TH3D* h1 = new TH3D("t3D2-h1", "h1",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TH3D* h2 = new TH3D("t3D2-h2", "h2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TH3D* h3 = new TH3D("t3D2-h3", "h3=h1+c2*h2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
h1->Sumw2();h2->Sumw2();h3->Sumw2();
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(x, y, z, 1.0);
h3->Fill(x, y, z, 1.0);
}
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(x, y, z, 1.0);
h3->Fill(x, y, z, c2);
}
h1->Add(h2, c2);
bool ret = equals("Add3D2", h3, h1, cmpOptStats, 1E-10);
delete h2;
delete h3;
return ret;
}
bool testAdd3DProfile2()
{
// Tests the second Add method for 3D Profiles
Double_t c2 = r.Rndm();
TProfile3D* p1 = new TProfile3D("t3D2-p1", "p1",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TProfile3D* p2 = new TProfile3D("t3D2-p2", "p2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TProfile3D* p3 = new TProfile3D("t3D2-p3", "p3=p1+c2*p2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t t = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p1->Fill(x, y, z, t, 1.0);
p3->Fill(x, y, z, t, 1.0);
}
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t t = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p2->Fill(x, y, z, t, 1.0);
p3->Fill(x, y, z, t, c2);
}
p1->Add(p2, c2);
bool ret = equals("Add3DProfile2", p3, p1, cmpOptStats, 1E-10);
delete p2;
delete p3;
return ret;
}
Lorenzo Moneta
committed
bool testAddSparse()
{
// Tests the Add method for Sparse Histograms
Lorenzo Moneta
committed
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
Double_t c = r.Rndm();
Int_t bsize[] = { TMath::Nint( r.Uniform(1, 5) ),
TMath::Nint( r.Uniform(1, 5) ),
TMath::Nint( r.Uniform(1, 5) )};
Double_t xmin[] = {minRange, minRange, minRange};
Double_t xmax[] = {maxRange, maxRange, maxRange};
THnSparseD* s1 = new THnSparseD("tS-s1", "s1", 3, bsize, xmin, xmax);
THnSparseD* s2 = new THnSparseD("tS-s2", "s2", 3, bsize, xmin, xmax);
THnSparseD* s3 = new THnSparseD("tS-s3", "s3=s1+c*s2", 3, bsize, xmin, xmax);
s1->Sumw2();s2->Sumw2();s3->Sumw2();
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t points[3];
points[0] = r.Uniform( minRange * .9 , maxRange * 1.1 );
points[1] = r.Uniform( minRange * .9 , maxRange * 1.1 );
points[2] = r.Uniform( minRange * .9 , maxRange * 1.1 );
s1->Fill(points);
s3->Fill(points);
}
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t points[3];
points[0] = r.Uniform( minRange * .9 , maxRange * 1.1 );
points[1] = r.Uniform( minRange * .9 , maxRange * 1.1 );
points[2] = r.Uniform( minRange * .9 , maxRange * 1.1 );
s2->Fill(points);
s3->Fill(points, c);
}
s1->Add(s2, c);
bool ret = equals("AddSparse", s3, s1, cmpOptStats , 1E-10);
delete s2;
delete s3;
return ret;
}
bool testMul1()
{
// Tests the first Multiply method for 1D Histograms
Double_t c1 = r.Rndm();
Double_t c2 = r.Rndm();
TH1D* h1 = new TH1D("m1D1-h1", "h1-Title", numberOfBins, minRange, maxRange);
TH1D* h2 = new TH1D("m1D1-h2", "h2-Title", numberOfBins, minRange, maxRange);
TH1D* h3 = new TH1D("m1D1-h3", "h3=c1*h1*c2*h2", numberOfBins, minRange, maxRange);
h1->Sumw2();h2->Sumw2();h3->Sumw2();
UInt_t seed = r.GetSeed();
// For possible problems
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(value, 1.0);
}
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(value, 1.0);
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
h3->Fill(value, c1*c2*h1->GetBinContent( h1->GetXaxis()->FindBin(value) ) );
}
// h3 has to be filled again so that the erros are properly calculated
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h3->Fill(value, c1*c2*h2->GetBinContent( h2->GetXaxis()->FindBin(value) ) );
}
// No the bin contents has to be reduced, as it was filled twice!
for ( Int_t bin = 0; bin <= h3->GetNbinsX() + 1; ++bin ) {
h3->SetBinContent(bin, h3->GetBinContent(bin) / 2 );
}
TH1D* h4 = new TH1D("m1D1-h4", "h4=h1*h2", numberOfBins, minRange, maxRange);
h4->Multiply(h1, h2, c1, c2);
bool ret = equals("Multiply1D1", h3, h4, cmpOptStats, 1E-14);
delete h1;
delete h2;
delete h3;
return ret;
}
bool testMul2()
{
// Tests the second Multiply method for 1D Histograms
TH1D* h1 = new TH1D("m1D2-h1", "h1-Title", numberOfBins, minRange, maxRange);
TH1D* h2 = new TH1D("m1D2-h2", "h2-Title", numberOfBins, minRange, maxRange);
TH1D* h3 = new TH1D("m1D2-h3", "h3=h1*h2", numberOfBins, minRange, maxRange);
h1->Sumw2();h2->Sumw2();h3->Sumw2();
UInt_t seed = r.GetSeed();
// For possible problems
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(value, 1.0);
}
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(value, 1.0);
h3->Fill(value, h1->GetBinContent( h1->GetXaxis()->FindBin(value) ) );
}
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h3->Fill(value, h2->GetBinContent( h2->GetXaxis()->FindBin(value) ) );
}
for ( Int_t bin = 0; bin <= h3->GetNbinsX() + 1; ++bin ) {
h3->SetBinContent(bin, h3->GetBinContent(bin) / 2 );
}
h1->Multiply(h2);
bool ret = equals("Multiply1D2", h3, h1, cmpOptStats, 1E-14);
delete h2;
delete h3;
return ret;
}
bool testMul2D1()
{
// Tests the first Multiply method for 2D Histograms
Double_t c1 = r.Rndm();
Double_t c2 = r.Rndm();
TH2D* h1 = new TH2D("m2D1-h1", "h1-Title",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TH2D* h2 = new TH2D("m2D1-h2", "h2-Title",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TH2D* h3 = new TH2D("m2D1-h3", "h3=c1*h1*c2*h2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
h1->Sumw2();h2->Sumw2();h3->Sumw2();
UInt_t seed = r.GetSeed();
// For possible problems
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(x, y, 1.0);
}
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(x, y, 1.0);
h3->Fill(x, y, c1*c2*h1->GetBinContent( h1->GetXaxis()->FindBin(x),
h1->GetYaxis()->FindBin(y) ) );
}
// h3 has to be filled again so that the erros are properly calculated
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h3->Fill(x, y, c1*c2*h2->GetBinContent( h2->GetXaxis()->FindBin(x),
h2->GetYaxis()->FindBin(y) ) );
}
// No the bin contents has to be reduced, as it was filled twice!
for ( Int_t i = 0; i <= h3->GetNbinsX() + 1; ++i ) {
for ( Int_t j = 0; j <= h3->GetNbinsY() + 1; ++j ) {
h3->SetBinContent(i, j, h3->GetBinContent(i, j) / 2 );
}
}
TH2D* h4 = new TH2D("m2D1-h4", "h4=h1*h2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
h4->Multiply(h1, h2, c1, c2);
bool ret = equals("Multiply2D1", h3, h4, cmpOptStats, 1E-12);
delete h1;
delete h2;
delete h3;
return ret;
}
bool testMul2D2()
{
// Tests the second Multiply method for 2D Histograms
TH2D* h1 = new TH2D("m2D2-h1", "h1-Title",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TH2D* h2 = new TH2D("m2D2-h2", "h2-Title",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
TH2D* h3 = new TH2D("m2D2-h3", "h3=h1*h2",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
h1->Sumw2();h2->Sumw2();h3->Sumw2();
UInt_t seed = r.GetSeed();
// For possible problems
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(x, y, 1.0);
}
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(x, y, 1.0);
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
h3->Fill(x, y, h1->GetBinContent( h1->GetXaxis()->FindBin(x),
h1->GetYaxis()->FindBin(y) ) );
}
// h3 has to be filled again so that the erros are properly calculated
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
Double_t y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h3->Fill(x, y, h2->GetBinContent( h2->GetXaxis()->FindBin(x),
h2->GetYaxis()->FindBin(y) ) );
}
// No the bin contents has to be reduced, as it was filled twice!
for ( Int_t i = 0; i <= h3->GetNbinsX() + 1; ++i ) {
for ( Int_t j = 0; j <= h3->GetNbinsY() + 1; ++j ) {
h3->SetBinContent(i, j, h3->GetBinContent(i, j) / 2 );
}
}
h1->Multiply(h2);
bool ret = equals("Multiply2D2", h3, h1, cmpOptStats, 1E-12);
delete h2;
delete h3;
return ret;
}
bool testMul3D1()
{
// Tests the first Multiply method for 3D Histograms