4 #ifndef _cic_ConstIntCut_h_
5 #define _cic_ConstIntCut_h_
20 typedef std::function<double(double, double)>
SFunction;
25 const double maxSin2Theta,
26 const unsigned int nBinsSin2Theta,
27 const double sRange) :
30 utl::EquidistantInNorm<
Event>(
34 [](const
Event& e) {
return e.fSin2Theta; }
49 unsigned int GetNBins()
const {
return fSin2ThetaBins.GetNBins(); }
56 typedef std::pair<double, double> DD;
57 std::sort(pairs.begin(), pairs.end(),
58 [](
const DD&
a,
const DD&
b) {
return a.first <
b.first; });
67 -std::numeric_limits<double>::infinity());
68 fLnSMinMaxN = fSin2ThetaMinMaxN;
73 const double mins2,
const double maxs2)
77 const unsigned int ns2 = 10;
78 const double ds2 = (maxs2 - mins2) / ns2;
80 for (
unsigned int i = 1; i <= ns2; ++i)
81 minLnAtt(log(att(mins2 + i*ds2)));
82 const double eps = 0.01;
92 const unsigned int n = fSin2ThetaBins.GetNBins();
96 for (
unsigned int i = 0; i < n; ++i) {
97 const double minLnAtt =
98 GetMinLnAttenuation(att, fSin2ThetaBins.GetBinLowerEdge(i),
99 fSin2ThetaBins.GetBinUpperEdge(i));
100 const BinType&
b = fSin2ThetaBins[i];
102 for (
const Event& e : b.GetCollection()) {
103 const double cut1000 = lnSCut + log(att(e.fSin2Theta));
104 const double w = fSFunc(e.fLnS1000 - cut1000, e.fLnS1000Err);
105 if (!w && !fSFunc(e.fLnS1000 - (lnSCut + minLnAtt), e.fLnS1000Err))
110 fNEventsAboveCut += sum;
111 fSin2ThetaMinMaxN(sum);
116 template<
class Binning>
117 std::vector<std::vector<double>>
122 using namespace utl::Accumulator;
125 const unsigned int nlns = binLnS38.GetNBins();
126 const double minLnSCut = binLnS38.GetBinLowerEdge(0);
127 const unsigned int ns2 = fSin2ThetaBins.GetNBins();
128 vector<vector<double>> ret(nlns, vector<double>(ns2));
129 const vector<Collect<Event>>& s2Bins = fSin2ThetaBins.GetAllBins();
130 for (
unsigned int is2 = 0; is2 < ns2; ++is2) {
131 const double minLnAtt =
132 GetMinLnAttenuation(att, fSin2ThetaBins.GetBinLowerEdge(is2),
133 fSin2ThetaBins.GetBinUpperEdge(is2));
134 for (
const Event& e : s2Bins[is2].GetCollection()) {
135 const double lnS38 = e.fLnS1000 - log(att(e.fSin2Theta));
136 const double err = e.fLnS1000Err;
137 double wup = fSFunc(lnS38 - binLnS38.GetBinUpperEdge(nlns-1), err);
138 for (
int ilns = nlns-1; ilns >= 0; --ilns) {
140 fSFunc(lnS38 - binLnS38.GetBinLowerEdge(ilns), err);
141 const double w = wdn - wup;
146 if (!wup && !fSFunc(e.fLnS1000 - (minLnSCut + minLnAtt), err))
149 for (
unsigned int ilns = 0; ilns < nlns; ++ilns)
150 ret[ilns][is2] = binLnS38[ilns].GetSum();
155 for (
const auto& row : ret) {
157 for (
const double n : row) {
159 fSin2ThetaMinMaxN(n);
161 fNEventsAboveCut += rowSum;
168 std::vector<std::pair<double, double>>
173 const unsigned int n = fSin2ThetaBins.GetNBins();
174 vector<pair<double, double>> wcdf;
176 for (
unsigned int i = 0; i < n; ++i) {
177 const double minLnAtt =
178 GetMinLnAttenuation(att, fSin2ThetaBins.GetBinLowerEdge(i),
179 fSin2ThetaBins.GetBinUpperEdge(i));
180 for (
const Event& e : fSin2ThetaBins[i].GetCollection()) {
181 const double s2 = e.fSin2Theta;
182 const double cut1000 = lnSCut + log(att(s2));
183 const double w = fSFunc(e.fLnS1000 - cut1000, e.fLnS1000Err);
185 wcdf.push_back(make_pair(s2 / fMaxSin2Theta, w));
186 fNEventsAboveCut += w;
187 }
else if (!fSFunc(e.fLnS1000 - (lnSCut + minLnAtt), e.fLnS1000Err))
195 template<
class Binning>
196 std::vector<std::vector<std::pair<double, double>>>
201 using namespace utl::Accumulator;
203 typedef pair<double, double> DD;
205 const unsigned int nlns = binLnS38.GetNBins();
206 const double minLnSCut = binLnS38.GetBinLowerEdge(0);
207 const unsigned int ns2 = fSin2ThetaBins.GetNBins();
208 const vector<Collect<Event>>& s2Bins = fSin2ThetaBins.
GetAllBins();
209 for (
unsigned int is2 = 0; is2 < ns2; ++is2) {
210 const double minLnAtt =
211 GetMinLnAttenuation(att, fSin2ThetaBins.GetBinLowerEdge(is2),
212 fSin2ThetaBins.GetBinUpperEdge(is2));
213 for (
const Event& e : s2Bins[is2].GetCollection()) {
214 const double s2 = e.fSin2Theta;
215 const double lnS38 = e.fLnS1000 - log(att(s2));
216 const double err = e.fLnS1000Err;
217 double wup = fSFunc(lnS38 - binLnS38.GetBinUpperEdge(nlns-1), err);
218 for (
int ilns = nlns-1; ilns >= 0; --ilns) {
220 fSFunc(lnS38 - binLnS38.GetBinLowerEdge(ilns), err);
221 const double w = wdn - wup;
223 binLnS38[ilns](make_pair(s2 / fMaxSin2Theta, w));
226 if (!wup && !fSFunc(e.fLnS1000 - (minLnSCut + minLnAtt), err))
231 vector<vector<DD>> ret(nlns);
232 for (
unsigned int i = 0; i < nlns; ++i) {
233 ret[i] = binLnS38[i].GetCollection();
234 sort(ret[i].begin(), ret[i].end(),
235 [](
const DD&
a,
const DD&
b) {
return a.first < b.first; });
238 for (
const auto& row : ret) {
240 for (
const DD& xw : row)
242 fNEventsAboveCut += rowSum;
253 const std::vector<double> pdf = MakePDF(att, lnSCut);
260 const std::vector<double> pdf = MakePDF(att, lnSCut);
268 const std::vector<std::pair<double, double>> cdf = MakeCDF(att, lnSCut);
276 const std::vector<std::pair<double, double>> cdf = MakeCDF(att, lnSCut);
280 template<
class Binning>
287 template<
class Binning>
294 double fMaxSin2Theta = 0;
300 unsigned int fNEvents = 0;
301 double fNEventsAboveCut = 0;
304 -std::numeric_limits<double>::infinity());
307 -std::numeric_limits<double>::infinity());
double UniformKolmogorovSmirnov(const vector< pair< double, double >> &wcdf, double wtot)
std::vector< std::vector< std::pair< double, double > > > MakeCDF2D(const Attenuation &att, const Binning &lnS38Binning)
double GetAndersonDarling(const Attenuation &att, const double lnSCut)
unsigned int GetNBins() const
static void SortByFirst(std::vector< std::pair< double, double >> &pairs)
double GetPoissonChi2(const Attenuation &att, const double lnSCut)
utl::Accumulator::Collect< Event > BinType
std::function< double(double, double)> SFunction
double GetMinLnAttenuation(const Attenuation &att, const double mins2, const double maxs2)
std::vector< std::pair< double, double > > MakeCDF(const Attenuation &att, const double lnSCut)
double UniformPoissonChi2(const std::vector< T > &counts, double nTot=0)
std::vector< std::vector< double > > MakePDF2D(const Attenuation &att, const Binning &lnS38Binning)
double UniformAndersonDarling(const vector< pair< double, double >> &wcdf, double wtot)
double GetKS(const Attenuation &att, const double lnSCut)
ConstIntCut(const std::vector< Event > &e, const SFunction &sFunc, const double maxSin2Theta, const unsigned int nBinsSin2Theta, const double sRange)
double GetChi2Ndof(const Attenuation &att, const double lnSCut)
std::function< double(double)> Attenuation
double GetPoissonChi22D(const Attenuation &att, const Binning &lnSBinning)
std::vector< BinType > & GetAllBins()
double GetAndersonDarling2D(const Attenuation &att, const Binning &lnSBinning)
utl::Bin< BinType, utl::EquidistantInNorm< Event > > fSin2ThetaBins
std::vector< double > MakePDF(const Attenuation &att, const double lnSCut)
double UniformChi2Ndof(const std::vector< T > &counts, double nTot=0)