Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RNTupleDrawVisitor.cxx
Go to the documentation of this file.
1/// \file RNTupleDrawVisitor.cxx
2/// \author Sergey Linev <S.Linev@gsi.de>, Jakob Blomer <jblomer@cern.ch>
3/// \date 2025-07-24
4
5/*************************************************************************
6 * Copyright (C) 1995-2025, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
14
15#include <TH1F.h>
16
17#include <algorithm>
18#include <cmath>
19#include <cstddef>
20#include <memory>
21#include <utility>
22
24{
25 std::size_t len = fHist->GetBufferLength();
26 auto buf = fHist->GetBuffer();
27
28 if (!buf || (len < 5))
29 return;
30
31 double min = buf[1];
32 double max = buf[1];
33 bool is_integer = true;
34
35 for (std::size_t n = 0; n < len; ++n) {
36 double v = buf[2 + 2 * n];
37 max = std::max(max, v);
38 min = std::min(min, v);
39 double _;
40 if (std::abs(std::modf(v, &_)) > 1e-5) {
41 is_integer = false;
42 break;
43 }
44 }
45
46 // special case when only integer values in short range - better binning
47 if (is_integer && (max - min < 100)) {
48 max += 2;
49 if (min > 1)
50 min -= 2;
51 int npoints = std::nearbyint(max - min);
52 std::unique_ptr<TH1> h1 = std::make_unique<TH1F>(fHist->GetName(), fHist->GetTitle(), npoints, min, max);
53 h1->SetDirectory(nullptr);
54 for (size_t n = 0; n < len; ++n)
55 h1->Fill(buf[2 + 2 * n], buf[1 + 2 * n]);
56 std::swap(fHist, h1);
57 }
58}
#define e(i)
Definition RSha256.hxx:103
#define _(A, B)
Definition cfortran.h:108
void TestHistBuffer()
Test collected entries if it looks like integer values and one can use better binning.
const Int_t n
Definition legend1.C:16
TH1F * h1
Definition legend1.C:5