Priors.cxx
Go to the documentation of this file.
1 #include "CAFAna/Fit/Priors.h"
2 
3 #include "Utilities/func/Stan.h"
6 
7 namespace ana
8 {
9  //----------------------------------------------------------------------
11  {
12  return 0.;
13  }
14 
15  //----------------------------------------------------------------------
16  std::function<stan::math::var(const stan::math::var&, const osc::IOscCalcAdjustableStan*)>
17  TopHatPriorInFitVar(double hatCenter, double hatWidth, double transitionFracWidth)
18  {
19  if (hatWidth <= 0)
20  {
21  std::cerr << "TopHatPriorInFitVar(): hatWidth parameter must be positive, not " << hatWidth << std::endl;
22  abort();
23  }
24 
25  auto E = [](const stan::math::var & x) -> stan::math::var
26  {
27  if (x < -1)
28  return -1;
29  if (x > 1)
30  return 1;
31  return stan::math::erf(x/sqrt(1-x*x)); // just set L=1, seems to always be ok and saves an operation
32  };
33 
34  auto H = [=](const stan::math::var & x) -> stan::math::var
35  {
36  return 0.5 * (1 + E(x));
37  };
38 
39  return [=](const stan::math::var &var, const osc::IOscCalcAdjustableStan *) -> stan::math::var
40  {
41  const double chi = 0.5 * hatWidth;
42  const double Psi = chi + transitionFracWidth;
43  const double Omega = 0.5 * (Psi - chi);
44 
45  auto x = var - hatCenter;
46 
47  if (abs(x) >= Psi)
48  return -std::numeric_limits<stan::math::var>::infinity(); // log(0) ........
49  if (abs(x) <= chi)
50  return 0;
51 
52  if (x < -chi)
53  return log(H( (x + chi + Omega)/Omega ));
54  if (x > chi)
55  return log(H( -(x - chi - Omega)/Omega ));
56 
57  std::cerr << "TopHatPriorInFitVar(): How did we get here??" << std::endl;
58  abort();
59  };
60 
61  }
62 
63 
64  //----------------------------------------------------------------------
66  {
67  return stan::math::normal_lpdf(dm32, 2.45, 0.5);
68  }
69 
70 
71  //----------------------------------------------------------------------
73  {
74  // need the Jacobian from sin^2(2*theta_23) to theta_23.
75  // that's 4*sin(2*theta_23) = 4 * sqrt(sin^2(2*theta_23))
76  //return log(4 * sqrt(ss2th23));
77  return log(4) + 0.5 * log(ss2th23);
78  }
79 
80  //----------------------------------------------------------------------
82  {
83  // Jacobian from sin^2(theta_23) to theta_23 = 2*sin(theta_23)
84  //return log(2 * sqrt(ssth23));
85  return log(2) + 0.5*log(ssth23);
86  }
87 
88  }
std::function< stan::math::var(const stan::math::var &, const osc::IOscCalcAdjustableStan *)> TopHatPriorInFitVar(double hatCenter, double hatWidth, double transitionFracWidth=0.01)
Definition: Priors.h:22
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
double ssth23
T sqrt(T number)
Definition: d0nt_math.hpp:156
OStream cerr
Definition: OStream.cxx:7
void abs(TH1 *hist)
stan::math::var UniformTh23Prior_FitSS2Th23(const stan::math::var &ss2th23, const osc::IOscCalcAdjustableStan *)
Prior uniform in theta_23 for use when fitting sin^2(2*theta_23).
Definition: Priors.cxx:72
fvar< T > erf(const fvar< T > &x)
Definition: erf.hpp:14
Float_t E
Definition: plot.C:20
return_type< T_y, T_loc, T_scale >::type normal_lpdf(const T_y &y, const T_loc &mu, const T_scale &sigma)
Definition: normal_lpdf.hpp:45
stan::math::var PriorUniformInFitVar(const stan::math::var &, const osc::IOscCalcAdjustableStan *)
Prior uniform in the variable that is being fitted.
Definition: Priors.cxx:10
General interface to any calculator that lets you set the parameters.
stan::math::var UniformTh23Prior_FitSSTh23(const stan::math::var &ssth23, const osc::IOscCalcAdjustableStan *)
Prior uniform in theta_23 for use when fitting sin^2(theta_23)
Definition: Priors.cxx:81
stan::math::var GaussianPriorDm32Scaled(const stan::math::var &dm32, const osc::IOscCalcAdjustableStan *)
Definition: Priors.cxx:65