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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
#define _(A, B)
Definition cfortran.h:108
void TestHistBuffer()
Test collected entries if it looks like integer values and one can use better binning.
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:9074
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3393
const Int_t n
Definition legend1.C:16
TH1F * h1
Definition legend1.C:5