67 : fValue(nullptr), fDim(dim), fBins(bins), fNum(num), fSparse(nullptr), fHist(nullptr), fHn(nullptr)
72 Double_t GetTime(EHist hist, ETime time)
const
75 return fTime[hist][0];
76 return fTime[hist][1];
78 static void SetDebug(
Int_t lvl) { fgDebug = lvl; }
79 THnSparse *GetSparse()
const {
return fSparse; }
82 void Fill(EHist hist);
84 void SetupHist(EHist hist);
100Int_t TTimeHists::fgDebug = 0;
102TTimeHists::~TTimeHists()
110bool TTimeHists::Run()
116 for (
int h = 0;
h < 2; ++
h) {
127 check[
h] = Check((EHist)
h);
130 }
while ((!
h &&
w.RealTime() < 0.1) || (
h && rep[0] > 0 && rep[1] < rep[0]));
132 fTime[
h][0] = (1. * fNum * rep[
h]) /
w.RealTime() / 1E6;
133 fTime[
h][1] = (1. * fNum * rep[
h]) /
w.CpuTime() / 1E6;
135 if (
h == 1 && (fTime[
h][0] > 1E20 || fTime[
h][1] > 1E20)) {
143 }
while (
w.RealTime() < 0.1);
145 fTime[
h][0] = (1. * fNum * rep[
h]) /
w.RealTime() / 1E6;
146 fTime[
h][1] = (1. * fNum * rep[
h]) /
w.CpuTime() / 1E6;
149 if (fTime[
h][0] > 1E20)
151 if (fTime[
h][1] > 1E20)
153 }
catch (std::exception &) {
154 fTime[
h][0] = fTime[
h][1] = -1.;
159 if (check[0] != check[1])
161 printf(
"ERROR: mismatch of histogram (%g) and sparse histogram (%g) for dim=%d, bins=%d!\n", check[0],
162 check[1], fDim, fBins);
166 return (check[0] == check[1]);
169void TTimeHists::NextValues()
175void TTimeHists::SetupValues()
183void TTimeHists::Fill(EHist hist)
188 printf(
"%ld: fill %s",
n, hist == kHist ? (fDim < 4 ?
"hist" :
"arr") :
"sparse");
190 printf(
"[%g]", fValue[
d]);
195 case 1: fHist->Fill(fValue[0]);
break;
196 case 2: ((
TH2F *)fHist)->Fill(fValue[0], fValue[1]);
break;
197 case 3: ((
TH3F *)fHist)->Fill(fValue[0], fValue[1], fValue[2]);
break;
198 default: fHn->Fill(fValue);
break;
201 fSparse->Fill(fValue);
206void TTimeHists::SetupHist(EHist hist)
210 case 1: fHist =
new TH1F(
"h1",
"h1", fBins, -1., 1.);
break;
211 case 2: fHist =
new TH2F(
"h2",
"h2", fBins, -1., 1., fBins, -1., 1.);
break;
212 case 3: fHist =
new TH3F(
"h3",
"h3", fBins, -1., 1., fBins, -1., 1., fBins, -1., 1.);
break;
218 if ((
Int_t)(
size *
sizeof(
Float_t)) > std::numeric_limits<int>::max() / (fBins + 2) ||
220 throw std::bad_alloc();
224 throw std::bad_alloc();
249Double_t TTimeHists::Check(EHist hist)
254 memset(
x, 0,
sizeof(
Int_t) * fDim);
261 while (
x[0] <= fBins + 1) {
266 histidx = fHist->GetBin(
x[0],
x[1]);
268 histidx = fHist->GetBin(
x[0],
x[1],
x[2]);
269 v = fHist->GetBinContent(histidx);
271 v = fHn->GetBinContent(
x);
278 if (fgDebug > 2 || (fgDebug > 1 &&
v)) {
279 printf(
"%s%d", fDim < 4 ?
"hist" :
"arr", fDim);
281 printf(
"[%d]",
x[
d]);
282 printf(
" = %g\n",
v);
288 for (
Int_t d = fDim - 1;
d > 0; --
d) {
289 if (
x[
d] > fBins + 1) {
297 for (
Long64_t i = 0; i < fSparse->GetNbins(); ++i) {
305 printf(
"sparse%d", fDim);
307 printf(
"[%d]",
x[
d]);
308 printf(
" = %g\n",
v);
314 printf(
"check %s%d = %g\n", hist == kHist ? (fDim < 4 ?
"hist" :
"arr") :
"sparse", fDim, check);
318void hist103_THnSparse_hist()
322#if defined(__CLING__)
323 printf(
"Please run this script in compiled mode by running \".x hist103_THnSparse_hist.C+\"\n");
327 TH2F *htime[TTimeHists::kNumHist][TTimeHists::kNumTime];
328 for (
int h = 0;
h < TTimeHists::kNumHist; ++
h)
329 for (
int t = 0; t < TTimeHists::kNumTime; ++t) {
339 title.
Form(
"Throughput (fill,get) %s (%s, 1M entries/sec);dim;bins;1M entries/sec",
340 h == 0 ?
"TH1/2/3/nF" :
"THnSparseF", t == 0 ?
"real" :
"CPU");
341 htime[
h][t] =
new TH2F(
name, title, 6, 0.5, 6.5, 10, 5, 105);
345 new TH2F(
"hsparse_mem",
"Fractional memory usage;dim;bins;fraction of memory used", 6, 0.5, 6.5, 10, 5, 105);
346 TH2F *hsparse_bins =
new TH2F(
"hsparse_bins",
"Fractional number of used bins;dim;bins;fraction of filled bins", 6,
347 0.5, 6.5, 10, 5, 105);
351 for (
Int_t dim = 1; dim < 7; ++dim) {
352 printf(
"Processing dimension %d", dim);
353 for (
Int_t bins = 10; bins <= 100; bins += 10) {
354 TTimeHists timer(dim, bins, 1000);
356 for (
int h = 0;
h < TTimeHists::kNumHist; ++
h) {
357 for (
int t = 0; t < TTimeHists::kNumTime; ++t) {
358 Double_t time = timer.GetTime((TTimeHists::EHist)
h, (TTimeHists::ETime)t);
360 htime[
h][t]->
Fill(dim, bins, time);
363 hsparse_mem->
Fill(dim, bins, timer.GetSparse()->GetSparseFractionMem());
364 hsparse_bins->
Fill(dim, bins, timer.GetSparse()->GetSparseFractionBins());
366 if (max < timer.GetTime(TTimeHists::kSparse, TTimeHists::kReal))
367 max = timer.GetTime(TTimeHists::kSparse, TTimeHists::kReal);
378 TH2F *htime_ratio[TTimeHists::kNumTime];
379 for (
int t = 0; t < TTimeHists::kNumTime; ++t) {
380 const char *
name = t ?
"htime_ratio" :
"htime_ratio_r";
381 htime_ratio[t] = (
TH2F *)htime[TTimeHists::kSparse][t]->Clone(
name);
383 title.
Form(
"Relative speed improvement (%s, 1M entries/sec): sparse/hist;dim;bins;#Delta 1M entries/sec",
384 t == 0 ?
"real" :
"CPU");
386 htime_ratio[t]->
Divide(htime[TTimeHists::kHist][t]);
391 TFile *
f =
new TFile(
"sparsehist.root",
"RECREATE");
399 const char *opt =
"TEXT COL";
401 for (
int t = 0; t < TTimeHists::kNumTime; ++t) {
402 for (
int h = 0;
h < TTimeHists::kNumHist; ++
h) {
405 canv->
cd(1 +
h + 3 * t);
406 htime[
h][t]->
Draw(opt);
410 htime_ratio[t]->
Draw(opt);
412 htime_ratio[t]->
Write();
416 hsparse_mem->
Draw(opt);
418 hsparse_bins->
Draw(opt);
419 hsparse_mem->
Write();
420 hsparse_bins->
Write();
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int)
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
float Float_t
Float 4 bytes (float)
double Double_t
Double 8 bytes.
long long Long64_t
Portable signed long integer 8 bytes.
THnSparseT< TArrayF > THnSparseF
R__EXTERN TRandom * gRandom
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
1-D histogram with a float per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
void SetTitle(const char *title) override
Change/set the title.
virtual void SetMaximum(Double_t maximum=-1111)
void Draw(Option_t *option="") override
Draw this histogram with options.
virtual void SetMinimum(Double_t minimum=-1111)
virtual Bool_t Divide(TF1 *f1, Double_t c1=1)
Performs the operation: this = this/(c1*f1) if errors are defined (see TH1::Sumw2),...
2-D histogram with a float per channel (see TH1 documentation)
Int_t Fill(Double_t) override
Invalid Fill method.
3-D histogram with a float per channel (see TH1 documentation)
Efficient multidimensional histogram.
Multidimensional histogram.
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
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...
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
void SetPaintTextFormat(const char *format="g")
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
See TColor::SetPalette.
virtual int GetMemInfo(MemInfo_t *info) const
Returns ram and swap memory usage info into the MemInfo_t structure.