UtilsExt.h
Go to the documentation of this file.
1 #pragma once
2 
3 // This is a subset of the original Utilities.h - eventually we will move all
4 // of it, but it differs between the experiments. While it's split we need a
5 // different filename
6 
7 #include <cxxabi.h>
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 class TH1;
13 class TH2;
14 class TH3;
15 class TF1;
16 class TH1D;
17 class TH1F;
18 class TH2F;
19 class TH2D;
20 class TH3D;
21 
22 namespace ana
23 {
24  class Binning;
25  class Spectrum;
26  class Ratio;
27 
28  enum EBinType
29  {
30  kBinContent, ///< Regular histogram
31  kBinDensity ///< Divide bin contents by bin widths
32  };
33 
34  /// For use as an argument to \ref Spectrum::ToTH1
38  };
39 
40  /// Return a different string each time, for creating histograms
42 
43  /// \brief Prevent histograms being added to the current directory
44  ///
45  /// Upon going out of scope, restores the previous setting
47  {
48  public:
51  protected:
52  bool fBackup;
53  };
54 
55  bool AlmostEqual(double a, double b, double eps = .0001); // allow 0.01% error by default
56 
57  /// Utility function to avoid need to switch on bins.IsSimple()
58  TH1D* MakeTH1D(const char* name, const char* title, const Binning& bins);
59  TH1F* MakeTH1F(const char* name, const char* title, const Binning& bins);
60  /// Utility function to avoid 4-way combinatorial explosion on the bin types
61  TH2D* MakeTH2D(const char* name, const char* title,
62  const Binning& binsx,
63  const Binning& binsy);
64  TH2F* MakeTH2F(const char* name, const char* title,
65  const Binning& binsx,
66  const Binning& binsy);
67  /// Utility function for 3D hist
68  // TODO: make bins more simple-like
69  TH3D* MakeTH3D(const char* name, const char* title,
70  const Binning& binsx,
71  const Binning& binsy,
72  const Binning& binsz);
73 
74 
75  /// \brief For use with \ref Var2D
76  ///
77  /// Re-expand a histogram flattened by \ref Var2D into a 2D histogram for
78  /// plotting purposes. The binning scheme must match that used in the
79  /// original Var.
80  TH2* ToTH2(const Spectrum& s, double exposure, ana::EExposureType expotype,
81  const Binning& binsx, const Binning& binsy,
83 
84  /// Same as ToTH2, but with 3 dimensions
85  TH3* ToTH3(const Spectrum& s, double exposure, ana::EExposureType expotype,
86  const Binning& binsx, const Binning& binsy, const Binning& binsz,
88 
89  /// \brief For use with \ref Var2D
90  ///
91  /// Re-expand a flatenned histogram into a 2D histogram for
92  /// plotting purposes. The binning scheme must match that used in the
93  /// original Var.
94  TH2* ToTH2(const Ratio& r, const Binning& binsx, const Binning& binsy);
95 
96  /// Same as ToTH2, but with 3 dimensions
97  TH3* ToTH3(const Ratio& r, const Binning& binsx,
98  const Binning& binsy, const Binning& binsz);
99 
100  /// Helper for ana::ToTH2
101  TH2* ToTH2Helper(std::unique_ptr<TH1> h1,
102  const Binning& binsx,
103  const Binning& binsy,
105 
106  /// Helper for ana::ToTH3
107  TH3* ToTH3Helper(std::unique_ptr<TH1> h1,
108  const Binning& binsx,
109  const Binning& binsy,
110  const Binning& binsz,
112 
113  /// utility method to figure out exactly what kind of object I am
114  template<class T> std::string DemangledTypeName(T* obj)
115  {
116  return abi::__cxa_demangle(typeid(*obj).name(), 0, 0, 0);
117  }
118 
119  template<class T> constexpr char* DemangledTypeName()
120  {
121  return abi::__cxa_demangle(typeid(T).name(), 0, 0, 0);
122  }
123 
124  std::string pnfs2xrootd(std::string loc, bool unauth = false);
125 
126  /// Find files matching a UNIX glob, plus expand environment variables
127  std::vector<std::string> Wildcard(const std::string& wildcardString);
128 
129  bool SAMDefinitionExists(const std::string& def);
130 }
const XML_Char * name
Definition: expat.h:151
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
std::string DemangledTypeName(T *obj)
utility method to figure out exactly what kind of object I am
Definition: UtilsExt.h:114
TH1F * MakeTH1F(const char *name, const char *title, const Binning &bins)
Definition: UtilsExt.cxx:80
TH3 * ToTH3Helper(std::unique_ptr< TH1 > h1, const Binning &binsx, const Binning &binsy, const Binning &binsz, ana::EBinType bintype)
Helper for ana::ToTH3.
Definition: UtilsExt.cxx:186
TH1D * MakeTH1D(const char *name, const char *title, const Binning &bins)
Utility function to avoid need to switch on bins.IsSimple()
Definition: UtilsExt.cxx:74
TH2F * MakeTH2F(const char *name, const char *title, const Binning &binsx, const Binning &binsy)
Definition: UtilsExt.cxx:94
Divide bin contents by bin widths.
Definition: UtilsExt.h:31
std::string pnfs2xrootd(std::string loc, bool unauth)
Definition: UtilsExt.cxx:237
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
EBinType
Definition: UtilsExt.h:28
const XML_Char * s
Definition: expat.h:262
std::vector< std::string > Wildcard(const std::string &wildcardString)
Find files matching a UNIX glob, plus expand environment variables.
Definition: UtilsExt.cxx:268
bool AlmostEqual(double a, double b, double eps)
Definition: UtilsExt.cxx:40
const double a
EExposureType
For use as an argument to Spectrum::ToTH1.
Definition: UtilsExt.h:35
std::vector< float > Spectrum
Definition: Constants.h:610
Regular histogram.
Definition: UtilsExt.h:30
Represent the ratio between two spectra.
Definition: Ratio.h:8
TH2D * MakeTH2D(const char *name, const char *title, const Binning &binsx, const Binning &binsy)
Utility function to avoid 4-way combinatorial explosion on the bin types.
Definition: UtilsExt.cxx:86
const Binning bins
Definition: NumuCC_CPiBin.h:8
TH1F * h1
bool SAMDefinitionExists(const std::string &def)
Definition: UtilsExt.cxx:296
const hit & b
Definition: hits.cxx:21
TRandom3 r(0)
TH2 * ToTH2Helper(std::unique_ptr< TH1 > h1, const Binning &binsx, const Binning &binsy, ana::EBinType bintype)
Helper for ana::ToTH2.
Definition: UtilsExt.cxx:135
double T
Definition: Xdiff_gwt.C:5
TH3D * MakeTH3D(const char *name, const char *title, const Binning &binsx, const Binning &binsy, const Binning &binsz)
Utility function for 3D hist.
Definition: UtilsExt.cxx:102
Prevent histograms being added to the current directory.
Definition: UtilsExt.h:46
TH3 * ToTH3(const Spectrum &s, double exposure, ana::EExposureType expotype, const Binning &binsx, const Binning &binsy, const Binning &binsz, ana::EBinType bintype)
Same as ToTH2, but with 3 dimensions.
Definition: UtilsExt.cxx:162
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:29
TH2 * ToTH2(const Spectrum &s, double exposure, ana::EExposureType expotype, const Binning &binsx, const Binning &binsy, ana::EBinType bintype)
For use with Var2D.
Definition: UtilsExt.cxx:115
enum BeamMode string