3 #include "TDirectory.h"
5 #include "TObjString.h"
20 const std::vector<std::string>&
labels)
22 assert(labels.empty() || int(labels.size()) == n);
29 for (
int i = 0; i <=
n; i++)
30 bins.
fEdges[i] = lo + i*(hi-lo)/
n;
39 const std::vector<std::string>&
labels)
43 auto it =
IDMap().find(bins);
49 bins.
fID = it->second;
58 std::vector<double> edges(n+1);
59 const double logSpacing =
exp( (log(hi) - log(lo)) / n );
60 for (
int i = 0; i <=
n; ++i) {
61 if (i == 0) edges[i] = lo;
62 else edges[i] = logSpacing*edges[i-1];
70 assert(edges.size() > 1);
74 bins.fNBins = edges.size()-1;
75 bins.fMin = edges.front();
76 bins.fMax = edges.back();
77 bins.fIsSimple =
false;
87 auto it =
IDMap().find(bins);
93 bins.
fID = it->second;
103 if (x <
fMin)
return 0;
110 int bin = (x -
fMin) / binwidth + 1;
116 if (x ==
fEdges[bin]) bin++;
117 assert(bin >= 0 && bin < (
int)
fEdges.size());
127 if(!ax->GetXbins()->GetArray()){
128 bins =
SimpleHelper(ax->GetNbins(), ax->GetXmin(), ax->GetXmax());
131 std::vector<double> edges(ax->GetNbins()+1);
132 ax->GetLowEdge(&edges.front());
133 edges[ax->GetNbins()] = ax->GetBinUpEdge(ax->GetNbins());
138 auto it =
IDMap().find(bins);
140 bins.
fID = it->second;
161 const int kNumTrueEnergyBins = 80;
164 std::vector<double> edges(kNumTrueEnergyBins+1);
166 const double Emin = .2;
169 const double N = kNumTrueEnergyBins-1;
170 const double A = N*Emin;
174 for(
int i = 1; i <=
N; ++i){
175 edges[kNumTrueEnergyBins-i] = A/i;
178 edges[kNumTrueEnergyBins] = 20;
189 const int kNumTrueLOverTrueEBins = 2000;
190 const double klow = 0.0;
191 const double khigh = 5.0;
199 TDirectory* tmp = gDirectory;
202 TObjString(
"Binning").Write(
"type");
210 nminmax.Write(
"nminmax");
212 TVectorD issimple(1);
214 issimple.Write(
"issimple");
216 TVectorD edges(
fEdges.size());
217 for(
unsigned int i = 0; i <
fEdges.size(); ++i)
220 edges.Write(
"edges");
222 for(
unsigned int i = 0; i <
fLabels.size(); ++i)
223 TObjString(
fLabels[i].c_str()).Write(TString::Format(
"label%d", i).Data());
231 TObjString* tag = (TObjString*)dir->Get(
"type");
233 assert(tag->GetString() ==
"Binning");
235 TVectorD* vMinMax = (TVectorD*)dir->Get(
"nminmax");
240 const TVectorD* issimple = (TVectorD*)dir->Get(
"issimple");
247 const TVectorD* vEdges = (TVectorD*)dir->Get(
"edges");
248 std::vector<double> edges(vEdges->GetNrows());
249 for(
int i = 0; i < vEdges->GetNrows(); ++i) edges[i] = (*vEdges)[i];
254 for(
unsigned int i = 0; ; ++i){
255 TObjString*
s = (TObjString*)dir->Get(TString::Format(
"label%d", i).Data());
257 ret.
fLabels.push_back(s->GetString().Data());
260 return std::make_unique<Binning>(ret);
292 static std::map<Binning, int> ret;
Represent the binning of a Spectrum's x-axis.
bool operator<(const Binning &rhs) const
process_name opflash particleana ie x
Binning TrueLOverTrueEBins()
static Binning FromTAxis(const TAxis *ax)
static std::map< Binning, int > & IDMap()
std::vector< std::string > fLabels
static Binning CustomHelper(const std::vector< double > &edges)
process_name opflashCryoW ana
std::vector< double > fEdges
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
static int fgNextID
The next ID that hasn't yet been assigned.
bool operator==(const Binning &rhs) const
auto end(FixedBins< T, C > const &) noexcept
void SaveTo(TDirectory *dir) const
int FindBin(float x) const
static Binning Custom(const std::vector< double > &edges)
Binning TrueEnergyBins()
Default true-energy bin edges.
static Binning LogUniform(int n, double lo, double hi)
then echo File list $list not found else cat $list while read file do echo $file sed s
process_name largeant stream1 can override from command line with o or output physics producers generator N
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
static std::unique_ptr< Binning > LoadFrom(TDirectory *dir)
static Binning SimpleHelper(int n, double lo, double hi, const std::vector< std::string > &labels={})