ThinSliceDataSet.h
Go to the documentation of this file.
1 #ifndef THINSLICEDATASET_hh
2 #define THINSLICEDATASET_hh
3 
4 #include <vector>
5 #include <map>
6 
8 #include "ThinSliceSample.h"
9 
10 #include "TH1D.h"
11 #include "TH2D.h"
12 #include "TH3D.h"
13 #include "TRandom3.h"
14 
15 namespace protoana {
17  public:
19  ThinSliceDataSet(const std::vector<double> & incident_bins,
20  const std::vector<fhicl::ParameterSet> & selections);
22 
23  const std::map<int, std::string> & GetSelectionNames() const {
24  return fSelectionNames;
25  };
26 
28  return fSelectionNames.at(id);
29  }
30 
31  std::map<int, TH1 *> & GetSelectionHists() {
32  return fSelectionHists;
33  };
34 
35  std::map<int, TH1 *> & GetRebinnedSelectionHists() {
37  };
38 
39  TH1 * GetSelectionHist(int id) {
40  return fSelectionHists.at(id);
41  };
42 
43  TH1D & GetIncidentHist() {
44  return fIncidentHist;
45  };
46 
48  return fIncidentHistRebinned;
49  };
50 
51  TH1 * GetRebinnedSelectionHist(int id) {
52  return fSelectionHistsRebinned.at(id);
53  };
54 
55  void FillIncidentHist(const std::vector<double> & vals) {
56  for (size_t i = 0; i < vals.size(); ++i) {
57  fIncidentHist.Fill(vals.at(i));
58  }
59  };
60 
61  void FillSelectionHist(int id, double val) {
62  if (fSelectionHists.find(id) != fSelectionHists.end()) {
63  fSelectionHists.at(id)->Fill(val);
64  }
65  };
66 
67  template <size_t N> void FillSelectionHist(int id, const double (& vals)[N]) {
68  if (N < 1 || N > 3) {
69  std::string message = "Error: trying to fill hists with too many values";
70  message += std::to_string(N);
71  throw std::runtime_error(message);
72  }
73 
74  if (fSelectionHists.find(id) != fSelectionHists.end()) {
75  if (N == 1) {
76  fSelectionHists.at(id)->Fill(vals[0]);
77  }
78  else if (N == 2) {
79  ((TH2D*)fSelectionHists.at(id))->Fill(vals[0], vals[1]);
80  }
81  else if (N == 3) {
82  ((TH3D*)fSelectionHists.at(id))->Fill(vals[0], vals[1], vals[2]);
83  }
84  }
85  }
86 
87  void MakeRebinnedHists();
88  void Refill1DRebinned();
89 
90  void GetCumulatives() {
91  fTotal = 0;
92  std::cout << "Making cumulatives" << std::endl;
93  for (auto it = fSelectionHists.begin();
94  it != fSelectionHists.end(); ++it) {
95  for (int i = 1; i <= it->second->GetNbinsX(); ++i) {
96  double val = it->second->GetBinContent(i);
97  if (fCumulatives.size()) {
98  val += fCumulatives.back().second;
99  }
100  fCumulatives.push_back({{it->first, i}, val});
101  fTotal += it->second->GetBinContent(i);
102  std::cout << fCumulatives.back().second << " " << fTotal << std::endl;
103  }
104  }
105 
106  for (auto it = fCumulatives.begin(); it != fCumulatives.end(); ++it) {
107  it->second /= fTotal;
108  }
109 
110  std::sort(fCumulatives.begin(), fCumulatives.end(),
111  [](auto a, auto b){return (a.second > b.second);});
112  std::cout << "N Cumulatives: " << fCumulatives.size() << std::endl;
113  for (auto c : fCumulatives) {
114  std::cout << c.second << std::endl;
115  }
116  };
117 
119 
121  const std::map<int, std::vector<std::vector<ThinSliceSample>>> & samples,
122  double & flux);
123 
124  private:
125  void Rebin1D(TH1 * sel_hist, TH1 * rebinned);
126  void Rebin2D(TH1 * sel_hist, TH1 * rebinned);
127  void Rebin3D(TH1 * sel_hist, TH1 * rebinned);
128  std::map<int, TH1 *> fSelectionHists;
130  std::map<int, TH1 *> fSelectionHistsRebinned;
132  bool fMadeRebinned = false;
133  std::map<int, std::string> fSelectionNames;
134  std::vector<std::pair<std::pair<int, int>, double>> fCumulatives;
135  TRandom3 fRNG = TRandom3(0);
136  double fTotal;
137 
138 };
139 }
140 #endif
TH1 * GetRebinnedSelectionHist(int id)
std::string string
Definition: nybbler.cc:12
void FillSelectionHist(int id, const double(&vals)[N])
struct vector vector
void Rebin3D(TH1 *sel_hist, TH1 *rebinned)
std::map< int, TH1 * > & GetSelectionHists()
std::vector< std::pair< std::pair< int, int >, double > > fCumulatives
void Rebin2D(TH1 *sel_hist, TH1 *rebinned)
void FillIncidentHist(const std::vector< double > &vals)
std::map< int, TH1 * > fSelectionHistsRebinned
const double a
void FillHistsFromSamples(const std::map< int, std::vector< std::vector< ThinSliceSample >>> &samples, double &flux)
std::map< int, TH1 * > & GetRebinnedSelectionHists()
void Rebin1D(TH1 *sel_hist, TH1 *rebinned)
std::map< int, std::string > fSelectionNames
std::string & GetSelectionName(int id)
static bool * b
Definition: config.cpp:1043
std::map< int, TH1 * > fSelectionHists
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
QTextStream & endl(QTextStream &s)
void FillSelectionHist(int id, double val)
const std::map< int, std::string > & GetSelectionNames() const