Logo ROOT   6.10/09
Reference Guide
test_tprofile2poly.cxx
Go to the documentation of this file.
1 #include "TClass.h"
2 #include "TList.h"
3 #include "TRandom3.h"
4 #include "TProfile2D.h"
5 #include "TProfile2Poly.h"
6 
7 #include "gtest/gtest.h"
8 
9 #include <algorithm>
10 #include <iostream>
11 
12 using namespace std;
13 
14 Float_t delta=0.00000000001;
15 
16 
17 void FillForTest(TProfile2D* tp2d, TProfile2Poly* tpp, TRandom& ran) {
18  Double_t value, weight;
19  Double_t px, py;
20 
21  for (Int_t i = 0; i < 1000000; i++) {
22  px = ran.Gaus(5,2);
23  py = ran.Gaus(4,2);
24  value = ran.Gaus(20, 5);
25  //value = ran.Uniform(0, 20);
26  weight = ran.Gaus(17,20);
27  tp2d->Fill(px, py, value, weight);
28  tpp->Fill(px, py, value, weight);
29  }
30 }
31 
33  for(Int_t c=1; c<=3; ++c) {
34  ASSERT_NEAR(tp2d->GetMean(c), tpp->GetMean(c), delta);
35  ASSERT_NEAR(tp2d->GetMeanError(c), tpp->GetMeanError(c), delta);
36  ASSERT_NEAR(tp2d->GetStdDev(c), tpp->GetStdDev(c), delta);
37  }
38 }
39 
41  Double_t cont1, cont2;
42  for(Double_t y=0.5; y<10; y+=2.0) {
43  for(Double_t x=0.5; x<10; x+=2.0) {
44  cont1 = tp2d->GetBinContent(tp2d->FindBin(x,y));
45  cont2 = tpp->GetBinContent(tpp->FindBin(x,y));
46  ASSERT_NEAR(cont1, cont2, delta);
47  }
48  }
49  // test overflow
50  cont1 = tp2d->GetBinContent(tp2d->FindBin(11,11));
51  cont2 = tpp->GetBinContent(tpp->FindBin(11,11));
52  ASSERT_NEAR(cont1, cont2, delta);
53 }
54 
56  Double_t cont1, cont2;
57  for(Double_t y=0.5; y<10; y+=2.0) {
58  for(Double_t x=0.5; x<10; x+=2.0) {
59  cont1 = tp2d->GetBinEffectiveEntries(tp2d->FindBin(x,y));
60  cont2 = tpp->GetBinEffectiveEntries(tpp->FindBin(x,y));
61  ASSERT_NEAR(cont1, cont2, delta);
62  }
63 
64  }
65  // test overflow
66  cont1 = tp2d->GetBinEffectiveEntries(tp2d->FindBin(11,11));
67  cont2 = tpp->GetBinEffectiveEntries(tpp->FindBin(11,11));
68  ASSERT_NEAR(cont1, cont2, delta);
69 
70 }
71 
73  Double_t cont1, cont2;
74  for(Double_t y=0.5; y<10; y+=2.0) {
75  for(Double_t x=0.5; x<10; x+=2.0) {
76  cont1 = tp2d->GetBinError(tp2d->FindBin(x,y));
77  cont2 = tpp->GetBinError(tpp->FindBin(x,y));
78  // std::cout << x << " " << y << " " << tpp->FindBin(x,y) << " " << tpp->GetBinContent(tpp->FindBin(x,y))
79  // << " " << tpp->GetBinEffectiveEntries(tpp->FindBin(x,y)) << std::endl;
80  ASSERT_NEAR(cont1, cont2, delta);
81  }
82  }
83  // test overflow
84  cont1 = tp2d->GetBinError(tp2d->FindBin(11,11));
85  cont2 = tpp->GetBinError(tpp->FindBin(11,11));
86  ASSERT_NEAR(cont1, cont2, delta);
87 }
88 
89 void SetupPlots(TProfile2Poly* TP2P_2, TProfile2Poly* TP2P, TProfile2D* TP2D_2, TProfile2D* TP2D, TString opt = "")
90 {
91 
92  TP2D->SetErrorOption(opt);
93  TP2D_2->SetErrorOption(opt);
94  if (opt == "S") {
97  } else {
99  TP2P_2->SetErrorOption(kERRORMEAN);
100  }
101 
102  double minx = -10; double maxx = 10;
103  double miny = -10; double maxy = 10;
104  double binsz = 2;
105 
106  for (double i = minx; i < maxx; i += binsz) {
107  for (double j = miny; j < maxy; j += binsz) {
108  TP2P->AddBin(i, j, i + binsz, j + binsz);
109  TP2P_2->AddBin(i, j, i + binsz, j + binsz);
110  }
111  }
112 
113 }
114 
116 
117  TH1::StatOverflows(true);
118 
119  auto TP2D = new TProfile2D("1", "1", 10, -10, 10, 10, -10, 10, 0, 0);
120  auto TP2D_2 = new TProfile2D("2", "2", 10, -10, 10, 10, -10, 10, 0, 0);
121 
122  auto TP2P = new TProfile2Poly();
123  auto TP2P_2 = new TProfile2Poly();
124 
125  SetupPlots(TP2P_2, TP2P, TP2D_2, TP2D);
126 
127  TRandom3 ran(1);
128 
129  // ----- first comparison
130  FillForTest(TP2D, TP2P, ran);
131  globalStatsCompare(TP2D, TP2P);
132 
133  // ----- second comparison
134  FillForTest(TP2D_2, TP2P_2, ran);
135  globalStatsCompare(TP2D_2, TP2P_2);
136 
137  // ----- Merging first and second one and then comparing
138  TList DMerge;
139  TList PMerge;
140 
141  DMerge.Add(TP2D_2);
142  PMerge.Add(TP2P_2);
143 
144  TP2D->Merge(&DMerge);
145  TP2P->Merge(&PMerge);
146 
147  globalStatsCompare(TP2D, TP2P);
148 
149  delete TP2D;
150  delete TP2D_2;
151  delete TP2P;
152  delete TP2P_2;
153 }
154 
156  auto TP2D = new TProfile2D("1", "1", 10, -10, 10, 10, -10, 10, 0, 0);
157  auto TP2D_2 = new TProfile2D("2", "2", 10, -10, 10, 10, -10, 10, 0, 0);
158 
159  auto TP2P = new TProfile2Poly();
160  auto TP2P_2 = new TProfile2Poly();
161 
162  SetupPlots(TP2P_2, TP2P, TP2D_2, TP2D);
163 
164  TRandom3 ran(2);
165 
166  // ----- first comparison
167  FillForTest(TP2D, TP2P, ran);
168  binContentCompare(TP2D, TP2P);
169  binEntriesCompare(TP2D, TP2P);
170 
171  // ----- second comparison
172  FillForTest(TP2D_2, TP2P_2, ran);
173  binContentCompare(TP2D_2, TP2P_2);
174  binEntriesCompare(TP2D_2, TP2P_2);
175 
176  // ----- Merging first and second one and then comparing
177  TList DMerge;
178  TList PMerge;
179 
180  DMerge.Add(TP2D_2);
181  PMerge.Add(TP2P_2);
182 
183  TP2D->Merge(&DMerge);
184  TP2P->Merge(&PMerge);
185 
186  binContentCompare(TP2D, TP2P);
187  binEntriesCompare(TP2D, TP2P);
188 
189  delete TP2D;
190  delete TP2D_2;
191  delete TP2P;
192  delete TP2P_2;
193 }
194 
195 
197  auto TP2D = new TProfile2D("1", "1", 10, -10, 10, 10, -10, 10, 0, 0);
198  auto TP2D_2 = new TProfile2D("2", "2", 10, -10, 10, 10, -10, 10, 0, 0);
199 
200  auto TP2P = new TProfile2Poly();
201  auto TP2P_2 = new TProfile2Poly();
202 
203  SetupPlots(TP2P_2, TP2P, TP2D_2, TP2D, "S");
204 
205  TRandom3 ran(3);
206 
207  // ----- first comparison
208  FillForTest(TP2D, TP2P, ran);
209  binErrorCompare(TP2D, TP2P);
210 
211  // ----- second comparison
212  FillForTest(TP2D_2, TP2P_2, ran);
213  binErrorCompare(TP2D_2, TP2P_2);
214 
215  // ----- Merging first and second one and then comparing
216  TList DMerge;
217  TList PMerge;
218 
219  DMerge.Add(TP2D_2);
220  PMerge.Add(TP2P_2);
221 
222  TP2D->Merge(&DMerge);
223  TP2P->Merge(&PMerge);
224 
225  binErrorCompare(TP2D, TP2P);
226 
227  delete TP2D;
228  delete TP2D_2;
229  delete TP2P;
230  delete TP2P_2;
231 }
232 
234  auto TP2D = new TProfile2D("1", "1", 10, -10, 10, 10, -10, 10, 0, 0);
235  auto TP2D_2 = new TProfile2D("2", "2", 10, -10, 10, 10, -10, 10, 0, 0);
236 
237  auto TP2P = new TProfile2Poly();
238  auto TP2P_2 = new TProfile2Poly();
239 
240  SetupPlots(TP2P_2, TP2P, TP2D_2, TP2D,"");
241 
242  TRandom3 ran(3);
243 
244  // ----- first comparison
245  FillForTest(TP2D, TP2P, ran);
246  binErrorCompare(TP2D, TP2P);
247 
248  // ----- second comparison
249  FillForTest(TP2D_2, TP2P_2, ran);
250  binErrorCompare(TP2D_2, TP2P_2);
251 
252  // ----- Merging first and second one and then comparing
253  TList DMerge;
254  TList PMerge;
255 
256  DMerge.Add(TP2D_2);
257  PMerge.Add(TP2P_2);
258 
259  TP2D->Merge(&DMerge);
260  TP2P->Merge(&PMerge);
261 
262  binErrorCompare(TP2D, TP2P);
263 
264  delete TP2D;
265  delete TP2D_2;
266  delete TP2P;
267  delete TP2P_2;
268 }
269 
270 
271 // ------------ TEST CALLS ------------
272 
273 TEST(TProfile2Poly, GlobalCompare) {
275 }
276 
277 TEST(TProfile2Poly, BinContentCompare) {
279 }
280 
281 TEST(TProfile2Poly, BinErrorSpreadCompare) {
283 }
284 TEST(TProfile2Poly, BinErrorMeanCompare) {
286 }
static void StatOverflows(Bool_t flag=kTRUE)
if flag=kTRUE, underflows and overflows are used by the Fill functions in the computation of statisti...
Definition: TH1.cxx:6241
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
Return Global bin number corresponding to x,y,z.
Definition: TH1.cxx:3441
Random number generator class based on M.
Definition: TRandom3.h:27
Int_t FindBin(Double_t x, Double_t y, Double_t z=0)
Returns the bin number of the bin at the given coordinate.
Definition: TH2Poly.cxx:561
virtual Double_t GetBinError(Int_t bin) const
Return bin error of a Profile2D histogram.
Definition: TProfile2D.cxx:830
float Float_t
Definition: RtypesCore.h:53
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:235
virtual Double_t GetBinError(Int_t bin) const override
Returns the value of error associated to bin number bin.
void binEntriesCompare(TProfile2D *tp2d, TProfile2Poly *tpp)
virtual Double_t GetMeanError(Int_t axis=1) const
Return standard error of mean of this histogram along the X axis.
Definition: TH1.cxx:6794
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
Definition: TH1.cxx:6763
int Int_t
Definition: RtypesCore.h:41
void globalStatsCompare(TProfile2D *tp2d, TProfile2Poly *tpp)
void SetupPlots(TProfile2Poly *TP2P_2, TProfile2Poly *TP2P, TProfile2D *TP2D_2, TProfile2D *TP2D, TString opt="")
STL namespace.
void test_binErrorSpreadStats()
Float_t delta
void binContentCompare(TProfile2D *tp2d, TProfile2Poly *tpp)
Int_t Fill(const Double_t *v)
Definition: TProfile2D.h:50
Double_t x[n]
Definition: legend1.C:17
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
virtual Double_t GetBinContent(Int_t bin) const
Return bin content of a Profile2D histogram.
Definition: TProfile2D.cxx:778
virtual void SetErrorOption(Option_t *option="")
Set option to compute profile2D errors.
virtual Int_t AddBin(TObject *poly)
Adds a new bin to the histogram.
Definition: TH2Poly.cxx:214
void binErrorCompare(TProfile2D *tp2d, TProfile2Poly *tpp)
A doubly linked list.
Definition: TList.h:43
virtual Int_t Fill(Double_t xcoord, Double_t ycoord, Double_t value) override
Increment the bin containing (x,y) by w.
void test_binEntryStats()
void FillForTest(TProfile2D *tp2d, TProfile2Poly *tpp, TRandom &ran)
void SetErrorOption(EErrorType type)
virtual Double_t GetBinContent(Int_t bin) const override
Returns the content of the input bin For the overflow/underflow/sea bins: -1 | -2 | -3 ---+----+---- ...
double Double_t
Definition: RtypesCore.h:55
virtual Double_t GetBinEffectiveEntries(Int_t bin)
Return bin effective entries for a weighted filled Profile histogram.
Definition: TProfile2D.cxx:807
Double_t y[n]
Definition: legend1.C:17
Profile2D histograms are used to display the mean value of Z and its RMS for each cell in X...
Definition: TProfile2D.h:27
void test_binErrorMeanStats()
virtual void Add(TObject *obj)
Definition: TList.h:77
TEST(TProfile2Poly, GlobalCompare)
Double_t GetBinEffectiveEntries(Int_t bin) const
void test_globalStats()
virtual Double_t GetStdDev(Int_t axis=1) const
Returns the Standard Deviation (Sigma).
Definition: TH1.cxx:6817