ROOT  6.06/09
Reference Guide
TAxis.cxx
Go to the documentation of this file.
1 /// \file TAxis.cxx
2 /// \ingroup Hist ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-08-06
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
6 
7 /*************************************************************************
8  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
9  * All rights reserved. *
10  * *
11  * For the licensing terms see $ROOTSYS/LICENSE. *
12  * For the list of contributors see $ROOTSYS/README/CREDITS. *
13  *************************************************************************/
14 
15 #include "ROOT/TAxis.h"
16 
17 #include <cmath>
18 
19 constexpr const int ROOT::TAxisBase::kNOverflowBins[4];
20 
21 /// If the coordinate `x` is a bin low edge (within 1E-6 of the coordinate),
22 /// return the bin for which this is a low edge. If it's not a bin edge, return
23 /// -1.
25  // fracBinIdx is the fractional bin index of x in this axis. It's (close to)
26  // an integer if it's an axis border.
27  double fracBinIdx = (x - GetMinimum()) * fInvBinWidth;
28  // fracBinIdx might be 12.99999999. It's a bin border if the deviation from
29  // an actual bin border is "fairly small".
30  int binIdx = std::round(fracBinIdx + 0.5);
31  double binOffset = fracBinIdx - binIdx;
32  if (std::fabs(binOffset) > x * 1E-6)
33  return -1;
34 
35  // If the bin index is below the first bin (i.e. x is the lower edge of the
36  // underflow bin) then it's out of range.
37  if (IsUnderflowBin(binIdx))
38  return -1;
39  // If x is the lower edge of the overflow bin then that's still okay - but if
40  // even the bin before binIdx is an overflow it's out of range.
41  if (IsOverflowBin(binIdx - 1))
42  return -1;
43 
44  return binIdx;
45 }
46 
47 /// Whether (and how) the source axis can be merged into the target axis.
49 ROOT::CanMap(TAxisEquidistant& target, TAxisEquidistant& source) noexcept {
50  if (source == target)
51  return EAxisCompatibility::kIdentical;
52 
53  int idxTargetLow = target.GetBinIndexForLowEdge(source.GetMinimum());
54  int idxTargetHigh = target.GetBinIndexForLowEdge(source.GetMaximum());
55  if (idxTargetLow < 0 || idxTargetHigh < 0)
56  return EAxisCompatibility::kIncompatible;
57 
58  // If both low and high exist in both axes and the bin width is identical then
59  // one axis contains the other.
60  if (source.GetInverseBinWidth() == target.GetInverseBinWidth())
61  return EAxisCompatibility::kContains;
62 
63  // Now we are left with the case
64  // source: 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6
65  // target: ...0.0, 0.3, 0.6...
66  // The question is: is the ratio of the bin width identical to the ratio of
67  // the number of bin?
68  if (std::fabs(target.GetInverseBinWidth() * source.GetNBinsNoOver()
69  - source.GetInverseBinWidth() * (idxTargetHigh - idxTargetLow))
70  > 1E-6 * target.GetInverseBinWidth())
71  return EAxisCompatibility::kIncompatible;
72 
73  // source is a fine-grained version of target.
74  return EAxisCompatibility::kSampling;
75 }
76 
77 //TODO: the other CanMap() overloads
int GetBinIndexForLowEdge(double x) const noexcept
If the coordinate x is a bin low edge (within 1E-6 of the coordinate), return the bin for which this ...
Definition: TAxis.cxx:24
Double_t x[n]
Definition: legend1.C:17
static constexpr const int kNOverflowBins[4]
Extra bins for each EAxisOverflow value.
Definition: TAxis.h:164
Axis with equidistant bin borders.
Definition: TAxis.h:271
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
static Vc_ALWAYS_INLINE Vector< T > round(const Vector< T > &x)
Definition: vector.h:452
Double_t E()
Definition: TMath.h:54
EAxisCompatibility CanMap(TAxisEquidistant &target, TAxisEquidistant &source) noexcept
Whether (and how) the source axis can be merged into the target axis.
Definition: TAxis.cxx:49
EAxisCompatibility
Definition: TAxis.h:751