Newer
Older
{
// Tests the first Multiply method for 1D Histograms with variable bin size
Double_t v[numberOfBins+1];
FillVariableRange(v);
Double_t c1 = r.Rndm();
Double_t c2 = r.Rndm();
Lorenzo Moneta
committed
TH1D* h1 = new TH1D("m1D1_h1", "h1-Title", numberOfBins, v);
TH1D* h2 = new TH1D("m1D1_h2", "h2-Title", numberOfBins, v);
TH1D* h3 = new TH1D("m1D1_h3", "h3=c1*h1*c2*h2", numberOfBins, v);
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
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, 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 );
}
Lorenzo Moneta
committed
TH1D* h4 = new TH1D("m1D1_h4", "h4=h1*h2", numberOfBins, v);
h4->Multiply(h1, h2, c1, c2);
bool ret = equals("MultiVar1D1", h3, h4, cmpOptStats, 1E-14);
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
if (cleanHistos) delete h2;
if (cleanHistos) delete h3;
return ret;
}
// Tests the second Multiply method for 1D Histograms
Lorenzo Moneta
committed
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);
Lorenzo Moneta
committed
if (cleanHistos) delete h2;
if (cleanHistos) delete h3;
return ret;
}
{
// Tests the second Multiply method for 1D Histograms with variable bin size
Double_t v[numberOfBins+1];
FillVariableRange(v);
Lorenzo Moneta
committed
TH1D* h1 = new TH1D("m1D2_h1", "h1-Title", numberOfBins, v);
TH1D* h2 = new TH1D("m1D2_h2", "h2-Title", numberOfBins, v);
TH1D* h3 = new TH1D("m1D2_h3", "h3=h1*h2", numberOfBins, v);
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
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("MultiVar1D2", h3, h1, cmpOptStats, 1E-14);
Lorenzo Moneta
committed
if (cleanHistos) delete h2;
if (cleanHistos) delete h3;
// Tests the first Multiply method for 2D Histograms
Double_t c1 = r.Rndm();
Double_t c2 = r.Rndm();
Lorenzo Moneta
committed
TH2D* h1 = new TH2D("m2D1_h1", "h1-Title",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
Lorenzo Moneta
committed
TH2D* h2 = new TH2D("m2D1_h2", "h2-Title",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
Lorenzo Moneta
committed
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 );
}
}
Lorenzo Moneta
committed
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);
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
if (cleanHistos) delete h2;
if (cleanHistos) delete h3;
return ret;
}
// Tests the second Multiply method for 2D Histograms
Lorenzo Moneta
committed
TH2D* h1 = new TH2D("m2D2_h1", "h1-Title",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
Lorenzo Moneta
committed
TH2D* h2 = new TH2D("m2D2_h2", "h2-Title",
numberOfBins, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
Lorenzo Moneta
committed
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);
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
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);
Lorenzo Moneta
committed
if (cleanHistos) delete h2;
if (cleanHistos) delete h3;
return ret;
}
// Tests the first Multiply method for 3D Histograms
Double_t c1 = r.Rndm();
Double_t c2 = r.Rndm();
Lorenzo Moneta
committed
TH3D* h1 = new TH3D("m3D1_h1", "h1-Title",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
Lorenzo Moneta
committed
TH3D* h2 = new TH3D("m3D1_h2", "h2-Title",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
Lorenzo Moneta
committed
TH3D* h3 = new TH3D("m3D1_h3", "h3=c1*h1*c2*h2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, 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);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->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);
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
h3->Fill(x, y, z, c1*c2*h1->GetBinContent( h1->GetXaxis()->FindBin(x),
h1->GetYaxis()->FindBin(y),
h1->GetZaxis()->FindBin(z) ) );
}
// 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);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h3->Fill(x, y, z, c1*c2*h2->GetBinContent( h2->GetXaxis()->FindBin(x),
h2->GetYaxis()->FindBin(y),
h2->GetZaxis()->FindBin(z) ) );
}
// 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 ) {
for ( Int_t h = 0; h <= h3->GetNbinsZ() + 1; ++h ) {
h3->SetBinContent(i, j, h, h3->GetBinContent(i, j, h) / 2 );
}
}
}
Lorenzo Moneta
committed
TH3D* h4 = new TH3D("m3D1_h4", "h4=h1*h2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
h4->Multiply(h1, h2, c1, c2);
bool ret = equals("Multiply3D1", h3, h4, cmpOptStats, 1E-13);
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
if (cleanHistos) delete h2;
if (cleanHistos) delete h3;
return ret;
}
// Tests the second Multiply method for 3D Histograms
Lorenzo Moneta
committed
TH3D* h1 = new TH3D("m3D2_h1", "h1-Title",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
Lorenzo Moneta
committed
TH3D* h2 = new TH3D("m3D2_h2", "h2-Title",
numberOfBins, minRange, maxRange,
numberOfBins + 1, minRange, maxRange,
numberOfBins + 2, minRange, maxRange);
Lorenzo Moneta
committed
TH3D* h3 = new TH3D("m3D2_h3", "h3=h1*h2",
numberOfBins, minRange, maxRange,
numberOfBins + 1, 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);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->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, h1->GetBinContent( h1->GetXaxis()->FindBin(x),
h1->GetYaxis()->FindBin(y),
h1->GetZaxis()->FindBin(z) ) );
}
Lorenzo Moneta
committed
// h3 has to be filled again so that the errors are properly calculated
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
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);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h3->Fill(x, y, z, h2->GetBinContent( h2->GetXaxis()->FindBin(x),
h2->GetYaxis()->FindBin(y),
h2->GetZaxis()->FindBin(z) ) );
}
// 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 ) {
for ( Int_t h = 0; h <= h3->GetNbinsZ() + 1; ++h ) {
h3->SetBinContent(i, j, h, h3->GetBinContent(i, j, h) / 2 );
}
}
}
h1->Multiply(h2);
bool ret = equals("Multiply3D2", h3, h1, cmpOptStats, 1E-13);
Lorenzo Moneta
committed
if (cleanHistos) delete h2;
if (cleanHistos) delete h3;
return ret;
}
template<typename HIST>
bool testMulHn()
Lorenzo Moneta
committed
{
// Tests the Multiply method for Sparse Histograms
Lorenzo Moneta
committed
Int_t bsize[] = { TMath::Nint( r.Uniform(1, 5) ),
TMath::Nint( r.Uniform(1, 5) ),
TMath::Nint( r.Uniform(1, 5) )};
Lorenzo Moneta
committed
Double_t xmin[] = {minRange, minRange, minRange};
Double_t xmax[] = {maxRange, maxRange, maxRange};
HIST* s1 = new HIST("m3D2-s1", "s1-Title", 3, bsize, xmin, xmax);
HIST* s2 = new HIST("m3D2-s2", "s2-Title", 3, bsize, xmin, xmax);
HIST* s3 = new HIST("m3D2-s3", "s3=s1*s2", 3, bsize, xmin, xmax);
Lorenzo Moneta
committed
s1->Sumw2();s2->Sumw2();s3->Sumw2();
Lorenzo Moneta
committed
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
UInt_t seed = r.GetSeed();
// For possible problems
r.SetSeed(seed);
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, 1.0);
}
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, 1.0);
Int_t points_s1[3];
points_s1[0] = s1->GetAxis(0)->FindBin( points[0] );
points_s1[1] = s1->GetAxis(1)->FindBin( points[1] );
points_s1[2] = s1->GetAxis(2)->FindBin( points[2] );
s3->Fill(points, s1->GetBinContent( points_s1 ) );
}
// s3 has to be filled again so that the errors are properly calculated
r.SetSeed(seed);
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 );
Int_t points_s2[3];
points_s2[0] = s2->GetAxis(0)->FindBin( points[0] );
points_s2[1] = s2->GetAxis(1)->FindBin( points[1] );
points_s2[2] = s2->GetAxis(2)->FindBin( points[2] );
s3->Fill(points, s2->GetBinContent( points_s2 ) );
}
// No the bin contents has to be reduced, as it was filled twice!
for ( Long64_t i = 0; i < s3->GetNbins(); ++i ) {
Int_t bin[3];
Double_t v = s3->GetBinContent(i, bin);
s3->SetBinContent( bin, v / 2 );
}
s1->Multiply(s2);
bool ret = equals(TString::Format("MultHn<%s>", HIST::Class()->GetName()), s3, s1, cmpOptNone, 1E-10);
Lorenzo Moneta
committed
delete s2;
delete s3;
return ret;
}
Lorenzo Moneta
committed
TH1D* h1 = new TH1D("mf1D_h1", "h1-Title", numberOfBins, minRange, maxRange);
TH1D* h2 = new TH1D("mf1D_h2", "h2=h1*c1*f1", numberOfBins, minRange, maxRange);
TF1* f = new TF1("sin", "sin(x)", minRange - 2, maxRange + 2);
h1->Sumw2();h2->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);
h2->Fill(value, f->Eval( h2->GetBinCenter( h2->FindBin(value) ) ) * c1 );
// stats fails because of the error precision
int status = equals("MULF H1D", h1, h2); //,cmpOptStats | cmpOptDebug);
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
Lorenzo Moneta
committed
TH1D* h1 = new TH1D("mf1D2_h1", "h1-Title", numberOfBins, minRange, maxRange);
TH1D* h2 = new TH1D("mf1D2_h2", "h2=h1*c1*f1", numberOfBins, minRange, maxRange);
minRange - 2, maxRange + 2,
minRange - 2, maxRange + 2);
h1->Sumw2();h2->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);
h2->Fill(value, f->Eval( h2->GetXaxis()->GetBinCenter( h2->GetXaxis()->FindBin(value) ),
h2->GetYaxis()->GetBinCenter( h2->GetYaxis()->FindBin(double(0)) ) )
* c1 );
// stats fails because of the error precision
int status = equals("MULF H1D2", h1, h2); //,cmpOptStats | cmpOptDebug);
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
Lorenzo Moneta
committed
TH2D* h1 = new TH2D("mf2D_h1", "h1-Title",
numberOfBins, minRange, maxRange,
numberOfBins, minRange, maxRange);
Lorenzo Moneta
committed
TH2D* h2 = new TH2D("mf2D_h2", "h2=h1*c1*f1",
numberOfBins, minRange, maxRange,
numberOfBins, minRange, maxRange);
TF1* f = new TF1("sin", "sin(x)", minRange - 2, maxRange + 2);
h1->Sumw2();h2->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);
h2->Fill(x, y, f->Eval( h2->GetXaxis()->GetBinCenter( h2->GetXaxis()->FindBin(x) ) ) * c1 );
// stats fails because of the error precision
int status = equals("MULF H2D", h1, h2); //, cmpOptStats | cmpOptDebug);
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
Lorenzo Moneta
committed
TH2D* h1 = new TH2D("mf2D2_h1", "h1-Title",
numberOfBins, minRange, maxRange,
Lorenzo Moneta
committed
TH2D* h2 = new TH2D("mf2D2_h2", "h2=h1*c1*f1",
numberOfBins, minRange, maxRange,
minRange - 2, maxRange + 2,
minRange - 2, maxRange + 2);
h1->Sumw2();h2->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);
h2->Fill(x, y, f->Eval( h2->GetXaxis()->GetBinCenter( h2->GetXaxis()->FindBin(x) ),
h2->GetYaxis()->GetBinCenter( h2->GetYaxis()->FindBin(y) ) )
* c1 );
// stats fails because of the error precision
int status = equals("MULF H2D2", h1, h2); //, cmpOptStats | cmpOptDebug);
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
Lorenzo Moneta
committed
TH3D* h1 = new TH3D("mf3D_h1", "h1-Title",
numberOfBins, minRange, maxRange,
numberOfBins, minRange, maxRange,
Lorenzo Moneta
committed
TH3D* h2 = new TH3D("mf3D_h2", "h2=h1*c1*f1",
numberOfBins, minRange, maxRange,
numberOfBins, minRange, maxRange,
numberOfBins, minRange, maxRange);
TF1* f = new TF1("sin", "sin(x)", minRange - 2, maxRange + 2);
h1->Sumw2();h2->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);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(x, y, z, 1.0);
h2->Fill(x, y, z, f->Eval( h2->GetXaxis()->GetBinCenter( h2->GetXaxis()->FindBin(x) ) ) * c1 );
// stats fails because of the error precision
int status = equals("MULF H3D", h1, h2); //, cmpOptStats | cmpOptDebug);
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
Lorenzo Moneta
committed
TH3D* h1 = new TH3D("mf3D2_h1", "h1-Title",
numberOfBins, minRange, maxRange,
numberOfBins, minRange, maxRange,
Lorenzo Moneta
committed
TH3D* h2 = new TH3D("mf3D2_h2", "h2=h1*c1*f1",
numberOfBins, minRange, maxRange,
numberOfBins, minRange, maxRange,
numberOfBins, minRange, maxRange);
minRange - 2, maxRange + 2,
minRange - 2, maxRange + 2);
h1->Sumw2();h2->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);
Double_t z = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(x, y, z, f->Eval( h2->GetXaxis()->GetBinCenter( h2->GetXaxis()->FindBin(x) ),
h2->GetYaxis()->GetBinCenter( h2->GetYaxis()->FindBin(y) ) )
* c1 );
// stats fails because of the error precision
int status = equals("MULF H3D2", h1, h2); //, cmpOptStats | cmpOptDebug);
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
template <typename HIST>
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};
HIST* s1 = new HIST("mfND-s1", "s1-Title", nDims, bsize, xmin, xmax);
HIST* s2 = new HIST("mfND-s2", "s2=f*s2", nDims, bsize, xmin, xmax);
TF1* f = new TF1("sin", "sin(x)", minRange - 2, maxRange + 2);
UInt_t seed = r.GetSeed();
// For possible problems
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t points[nDims];
for ( UInt_t i = 0; i < nDims; ++ i )
points[i] = r.Uniform( minRange * .9 , maxRange * 1.1 );
s1->Fill(points, 1.0);
s2->Fill(points, f->Eval( s2->GetAxis(0)->GetBinCenter( s2->GetAxis(0)->FindBin(points[0]) ) ) * c1);
int status = equals(TString::Format("MULF HND<%s>", HIST::Class()->GetName()), s1, s2);
template<typename HIST>
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};
HIST* s1 = new HIST("mfND-s1", "s1-Title", nDims, bsize, xmin, xmax);
HIST* s2 = new HIST("mfND-s2", "s2=f*s2", nDims, bsize, xmin, xmax);
minRange - 2, maxRange + 2,
minRange - 2, maxRange + 2);
s1->Sumw2();s2->Sumw2();
UInt_t seed = r.GetSeed();
// For possible problems
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents * nEvents; ++e ) {
Double_t points[nDims];
for ( UInt_t i = 0; i < nDims; ++ i )
points[i] = r.Uniform( minRange * .9 , maxRange * 1.1 );
s1->Fill(points, 1.0);
s2->Fill(points, f->Eval( s2->GetAxis(0)->GetBinCenter( s2->GetAxis(0)->FindBin(points[0]) ),
s2->GetAxis(1)->GetBinCenter( s2->GetAxis(1)->FindBin(points[1]) ) )
* c1);
int status = equals(TString::Format("MULF HND2<%s>", HIST::Class()->GetName()), s1, s2);
Double_t c1 = r.Rndm() + 1;
Double_t c2 = r.Rndm() + 1;
Lorenzo Moneta
committed
TH1D* h1 = new TH1D("d1D1_h1", "h1-Title", numberOfBins, minRange, maxRange);
TH1D* h2 = new TH1D("d1D1_h2", "h2-Title", numberOfBins, minRange, maxRange);
UInt_t seed = r.GetSeed();
// For possible problems
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value;
value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(value, 1.0);
value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(value, 1.0);
}
// avoid bins in h2 with zero content
if (h2->GetBinContent(i) == 0) h2->SetBinContent(i,1);
Lorenzo Moneta
committed
TH1D* h3 = new TH1D("d1D1_h3", "h3=(c1*h1)/(c2*h2)", numberOfBins, minRange, maxRange);
Lorenzo Moneta
committed
TH1D* h4 = new TH1D("d1D1_h4", "h4=h3*h2)", numberOfBins, minRange, maxRange);
h4->Multiply(h2, h3, c2/c1, 1);
for ( Int_t bin = 0; bin <= h4->GetNbinsX() + 1; ++bin ) {
Double_t error = h4->GetBinError(bin) * h4->GetBinError(bin);
error -= (2*(c2*c2)/(c1*c1)) * h3->GetBinContent(bin)*h3->GetBinContent(bin)*h2->GetBinError(bin)*h2->GetBinError(bin);
h4->SetBinError( bin, sqrt(error) );
}
h4->ResetStats();
bool ret = equals("Divide1D1", h1, h4, cmpOptStats );
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
if (cleanHistos) delete h2;
if (cleanHistos) delete h3;
// Tests the first Divide method for 1D Histograms with variable bin size
Double_t c1 = r.Rndm() + 1;
Double_t c2 = r.Rndm() + 1;
Lorenzo Moneta
committed
TH1D* h1 = new TH1D("d1D1_h1", "h1-Title", numberOfBins, v);
TH1D* h2 = new TH1D("d1D1_h2", "h2-Title", numberOfBins, v);
UInt_t seed = r.GetSeed();
// For possible problems
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value;
value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(value, 1.0);
Lorenzo Moneta
committed
TH1D* h3 = new TH1D("d1D1_h3", "h3=(c1*h1)/(c2*h2)", numberOfBins, v);
Lorenzo Moneta
committed
TH1D* h4 = new TH1D("d1D1_h4", "h4=h3*h2)", numberOfBins, v);
h4->Multiply(h2, h3, c2/c1, 1);
for ( Int_t bin = 0; bin <= h4->GetNbinsX() + 1; ++bin ) {
Double_t error = h4->GetBinError(bin) * h4->GetBinError(bin);
error -= (2*(c2*c2)/(c1*c1)) * h3->GetBinContent(bin)*h3->GetBinContent(bin)*h2->GetBinError(bin)*h2->GetBinError(bin);
h4->SetBinError( bin, sqrt(error) );
}
h4->ResetStats();
bool ret = equals("DivideVar1D1", h1, h4, cmpOptStats);
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
if (cleanHistos) delete h2;
if (cleanHistos) delete h3;
Double_t c1 = 1;//r.Rndm();
Double_t c2 = 1;//r.Rndm();
TProfile* p1 = new TProfile("d1D1_p1", "p1-Title", numberOfBins, minRange, maxRange);
TProfile* p2 = new TProfile("d1D1_p2", "p2-Title", numberOfBins, minRange, maxRange);
p1->Sumw2();p2->Sumw2();
UInt_t seed = r.GetSeed();
// For possible problems
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t x, y;
x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
x = r.Uniform(0.9 * minRange, 1.1 * maxRange);
y = r.Uniform(0.9 * minRange, 1.1 * maxRange);
p2->Fill(x, y, 1.0);
TProfile* p3 = new TProfile("d1D1_p3", "p3=(c1*p1)/(c2*p2)", numberOfBins, minRange, maxRange);
p3->Divide(p1, p2, c1, c2);
// There is no Multiply method to tests. And the errors are wrongly
// calculated in the TProfile::Division method, so there is no
// point to make the tests. Once the method is fixed, the tests
// will be finished.
return 0;
Lorenzo Moneta
committed
TH1D* h1 = new TH1D("d1D2_h1", "h1-Title", numberOfBins, minRange, maxRange);
TH1D* h2 = new TH1D("d1D2_h2", "h2-Title", numberOfBins, minRange, maxRange);
UInt_t seed = r.GetSeed();
// For possible problems
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value;
value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(value, 1.0);
TH1D* h3 = static_cast<TH1D*>( h1->Clone() );
h3->Divide(h2);
Lorenzo Moneta
committed
TH1D* h4 = new TH1D("d1D2_h4", "h4=h3*h2)", numberOfBins, minRange, maxRange);
h4->Multiply(h2, h3, 1.0, 1.0);
for ( Int_t bin = 0; bin <= h4->GetNbinsX() + 1; ++bin ) {
Double_t error = h4->GetBinError(bin) * h4->GetBinError(bin);
error -= 2 * h3->GetBinContent(bin)*h3->GetBinContent(bin)*h2->GetBinError(bin)*h2->GetBinError(bin);
bool ret = equals("Divide1D2", h1, h4, cmpOptStats);
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
if (cleanHistos) delete h2;
if (cleanHistos) delete h3;
// Tests the second Divide method for 1D Histograms with variable bin size
Double_t v[numberOfBins+1];
FillVariableRange(v);
Lorenzo Moneta
committed
TH1D* h1 = new TH1D("d1D2_h1", "h1-Title", numberOfBins, v);
TH1D* h2 = new TH1D("d1D2_h2", "h2-Title", numberOfBins, v);
UInt_t seed = r.GetSeed();
// For possible problems
r.SetSeed(seed);
for ( Int_t e = 0; e < nEvents; ++e ) {
Double_t value;
value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h1->Fill(value, 1.0);
value = r.Uniform(0.9 * minRange, 1.1 * maxRange);
h2->Fill(value, 1.0);
TH1D* h3 = static_cast<TH1D*>( h1->Clone() );
h3->Divide(h2);
Lorenzo Moneta
committed
TH1D* h4 = new TH1D("d1D2_h4", "h4=h3*h2)", numberOfBins, v);
h4->Multiply(h2, h3, 1.0, 1.0);
for ( Int_t bin = 0; bin <= h4->GetNbinsX() + 1; ++bin ) {
Double_t error = h4->GetBinError(bin) * h4->GetBinError(bin);
error -= 2 * h3->GetBinContent(bin)*h3->GetBinContent(bin)*h2->GetBinError(bin)*h2->GetBinError(bin);
bool ret = equals("DivideVar1D2", h1, h4, cmpOptStats);
Lorenzo Moneta
committed
if (cleanHistos) delete h1;
if (cleanHistos) delete h2;
if (cleanHistos) delete h3;
return ret;
}
Double_t c1 = r.Rndm() + 1;
Double_t c2 = r.Rndm() + 1;
Lorenzo Moneta
committed
TH2D* h1 = new TH2D("d2D1_h1", "h1-Title",