1 #include "CAFAna/Core/Var.h" 14 _Var(
const std::function<VarFunc_t>& fun)
15 : fFunc(fun), fID(fgNextID++)
22 _Var(
const std::function<VarFunc_t>& fun,
int id)
38 if(&v ==
this)
return;
58 if(&v ==
this)
return *
this;
85 double c,
const T*
sr)
87 const double val =
v(sr);
110 #define COMPARISON(OP, OPNAME) \ 112 template<class T> _Cut<T> _Var<T>:: \ 113 operator OP(double c) const \ 117 _Var<T> v; double c; \ 118 bool operator()(const T* sr) \ 120 return ValHelper(v, #OP, c, sr) OP c; \ 124 return _Cut<T>(OPNAME{*this, c}); \ 128 template<class T> _Cut<T> _Var<T>:: \ 129 operator OP(const _Var<T>& v) const \ 134 bool operator()(const T* sr) \ 137 ValHelper(a, b, #OP, sr, va, vb); \ 142 return _Cut<T>(OPNAME{*this, v}); \ 144 void dummy() // trick to require a semicolon 155 template class _Var<caf::SRProxy>;
156 template class _Var<caf::SRSpillProxy>;
157 template class _Var<caf::SRNeutrinoProxy>;
168 : fA(a), fBinsA(binsa),
176 const double va = fA(sr);
177 const double vb = fB(sr);
180 if(va < fBinsA.Min() || vb < fBinsB.Min())
return -1;
181 if(va > fBinsA.Max() || vb > fBinsB.Max())
return fBinsA.NBins() * fBinsB.NBins();
184 const int ia = fBinsA.FindBin(va) - 1;
185 const int ib = fBinsB.FindBin(vb) - 1;
187 const int i = ia*fBinsB.NBins()+ib;
206 : fA(a), fBinsA(binsa),
207 fB(b), fBinsB(binsb),
215 const double va = fA(sr);
216 const double vb = fB(sr);
217 const double vc =
fC(sr);
220 if(va < fBinsA.Min() || vb < fBinsB.Min() || vc < fBinsC.Min()){
224 if(va > fBinsA.Max() || vb > fBinsB.Max() || vc > fBinsC.Max()){
225 return fBinsA.NBins() * fBinsB.NBins() * fBinsC.NBins();
228 const int ia = fBinsA.FindBin(va) - 1;
229 const int ib = fBinsB.FindBin(vb) - 1;
230 const int ic = fBinsC.FindBin(vc) - 1;
231 const int i = ia*fBinsB.NBins()*fBinsC.NBins() + ib*fBinsC.NBins() + ic;
256 const _Var<T>&
b,
int nb,
double b0,
double b1)
267 template Var Var2D(
const Var&,
int,
double,
double,
const Var&,
int,
double,
double);
283 const _Var<T>&
b,
int nb,
double b0,
double b1,
296 template Var Var3D(
const Var&,
int,
double,
double,
const Var&,
int,
double,
double,
const Var&,
int,
double,
double);
297 template SpillVar Var3D(
const SpillVar&,
int,
double,
double,
const SpillVar&,
int,
double,
double,
const SpillVar&,
int,
double,
double);
298 template NuTruthVar Var3D(
const NuTruthVar&,
int,
double,
double,
const NuTruthVar&,
int,
double,
double,
const NuTruthVar&,
int,
double,
double);
305 const Var v;
double s;
321 return Var(Const{c});
334 return Var(Sqrter{v});
341 static std::map<std::pair<int, int>,
int>
ids;
342 const std::pair<int, int>
key(
ID(), v.
ID());
351 return _Var<T>(Times{*
this, v});
358 static std::map<std::pair<int, int>,
int>
ids;
359 const std::pair<int, int>
key(
ID(), v.
ID());
366 const double denom =
b(sr);
368 return a(sr) / denom;
382 static std::map<std::pair<int, int>,
int>
ids;
383 const std::pair<int, int>
key(
ID(), v.
ID());
399 static std::map<std::pair<int, int>,
int>
ids;
400 const std::pair<int, int>
key(
ID(), v.
ID());
std::function< VarFunc_t > fFunc
ratio_hxv Divide(hxv, goal_hxv)
Represent the binning of a Spectrum's x-axis.
Cuts and Vars for the 2020 FD DiF Study.
int ID() const
Vars with the same definition will have the same ID.
double operator()(const T *sr) const
Proxy for caf::StandardRecord.
_Var< T > Var2D(const _Var< T > &a, const Binning &binsa, const _Var< T > &b, const Binning &binsb)
Variable formed from two input variables.
_Var< T > operator+(const _Var< T > &v) const
Deep magic to fix static initialization order. Here Be Dragons!
double operator()(const T *sr) const
_Var< T > operator/(const _Var< T > &v) const
static constexpr Double_t fC
_Var< T > Var3D(const _Var< T > &a, const Binning &binsa, const _Var< T > &b, const Binning &binsb, const _Var< T > &c, const Binning &binsc)
This is just like a Var2D, but useful for 3D Spectra.
_Var< caf::SRProxy > Var
Representation of a variable to be retrieved from a caf::StandardRecord object.
Var Constant(double c)
Use to weight events up and down by some factor.
int isnan(const stan::math::var &a)
double operator()(const T *sr) const
Allows a variable to be called with double value = myVar(sr) syntax.
void RegisterDependency(const T *parent, T *child)
Call from copy constructor and assignment operator.
double ValHelper(const _Var< T > &v, const std::string &op, double c, const T *sr)
_Var< T > operator-(const _Var< T > &v) const
Var Sqrt(const Var &v)
Use to take sqrt of a var.
void RegisterDestruction(T *x)
Call from destructor.
_Var< T > operator*(const _Var< T > &v) const
_Var(const std::function< VarFunc_t > &fun)
std::function can wrap a real function, function object, or lambda
void RegisterConstruction(T *x)
Call from constructor (in the success case)
Var2DFunc(const _Var< T > &a, const Binning binsa, const _Var< T > &b, const Binning binsb)
Var Scaled(const Var &v, double s)
Use to rescale another variable.
Template for Var and SpillVar.
static int fgNextID
The next ID that hasn't yet been assigned.
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
simulatedPeak Scale(1/simulationNormalisationFactor)
_Var & operator=(const _Var< T > &v)
Var3DFunc(const _Var< T > &a, const Binning binsa, const _Var< T > &b, const Binning binsb, const _Var< T > &c, const Binning binsc)