4 #define _USE_MATH_DEFINES
7 #include <ginac/ginac.h>
18 using namespace GiNaC;
22 measure(
double v=0,
double e=0):value(v),error(e){}
44 virtual double loglikelihood(
double hipothesis)
const = 0;
45 virtual double error(
double hipothesis)
const = 0;
60 limitedobs(
double limit,
double cl=0.9,
double m=0): s(fabs(limit-m)/(1.282+sqrt(M_PI_2))), min(m),lim(limit) {
61 if(cl==0.95) s*=(1.282+sqrt(M_PI_2))/(1.645+sqrt(M_PI_2));
65 double diff=(hipothesis-min-sqrt(M_PI_2)*s)/s;
69 double error(
double hipothesis)
const {
70 double diff=(hipothesis-min )/s;
85 gaussobs(
double mean,
double sigma): m(mean), s(mean*sigma) {}
88 double diff=(m-hipothesis)/s;
91 double error(
double hipothesis)
const {
92 double diff=(hipothesis-m)/s;
107 gauss2obs(
double mean,
double sigma): m(mean), s(sigma) {}
110 double diff=(m-hipothesis)/s;
113 double error(
double hipothesis)
const {
114 double diff=(hipothesis-m)/s;
130 freeparameter(
double mi,
double ma, TRandom3 * r,
double ss=1e-2): min(mi), max(ma), value(mi+(ma-mi)*r->Rndm()), step((ma-mi)*ss) {}
135 void next(TRandom3 * r,
double f=1){
137 value+=r->Gaus()*step*f;
141 return min<=value && value<=max;
147 return std::pow((x-value)/step,2);
167 discreteparameter(
int mi,
int ma, TRandom3 * r): min(mi), max(ma), value(mi+r->Integer(ma-mi+1)) {}
182 void next(TRandom3 * r,
double f=1){
183 for(iterator i=begin();i!=end();i++){
194 for(const_iterator i=begin();i!=end();i++){
195 if(!i->isvalid())
return 0;
202 for(
uint i=0;i<size();i++){
203 total+=at(i).dist(p[i].value);
205 return sqrt(total/size());
210 for(
uint i=0;i<size();i++){
211 at(i).value=p[i].value;
217 for(const_iterator i=begin();i!=end();i++){
225 for(
uint i=0;i<size();i++){
226 l*=TMath::Gaus((p2[i].value-at(i).value)/at(i).step);
243 virtual double operator()(
const parameters & p)
const=0;
268 int n=p.
values.size(), m=1;
269 e(&n,&(p.
values[0]),&m,&ret);
270 if(pass) ret=o->loglikelihood(ret);
276 shared_ptr<observable>
o;
291 ret=ex_to<numeric>(e.subs(p.
p,subs_options::no_pattern).evalf()).to_double();
293 catch(GiNaC::pole_error e){
295 cout<<
"Pole error"<<endl;
298 cout<<e.what()<<endl;
301 cout<<
"Other exception"<<endl;
304 if(pass) ret=o->loglikelihood(ret);
315 cout<<e.subs(p.
p)<<endl;
317 ret=ex_to<numeric>(e.subs(p.
p,subs_options::no_pattern).evalf()).to_double();
319 catch(GiNaC::pole_error er){
321 cout<<
"Pole error"<<endl;
326 cout<<er.what()<<endl;
327 cout<<e.subs(p.
p,subs_options::no_pattern).evalf()<<endl;
330 cout<<
"Other exception"<<endl;
333 if(pass) ret=o->error(ret);
339 shared_ptr<observable>
o;
361 class Model:
public vector< prediction > {
367 virtual parameters generateparameters(
int max=0)
const = 0;
375 if(veto(p,max) && check)
return 0;
376 double total=loglike(p,0);
377 if(total<-1000)
return 0;
382 if(veto(p,max) && check)
return -1000;
387 for(const_iterator i=begin();i!=end();i++) {
390 total+=i->loglikelihood(pp);
393 cout<<n<<e.what()<<endl;
double min
minimum possible value for the parameter
void next(TRandom3 *r, double f=1)
changes randomly the ::value of the parameter, the standard deviation is ::step
double operator()(const parameters &p) const
double loglikelihood(const parameters &p) const
double min
minimum possible value for the parameter
A base class representing an experimental measure.
prediction(observable *ob, const ex &e0)
A parameter which will be fitted in the simulation.
A class containing the value and uncertainty of an experimental measure.
measure operator/(measure m2) const
double dist(double x) const
probability distribution, to be used by the Markov Chain Monte Carlo simulation
double error(const parameters &p) const
prediction(const prediction &p)
calcuex(observable *ob, const ex &e0)
discreteparameter(int mi, int ma, TRandom3 *r)
double value
value of the parameter
double operator()(const parameters &p) const
An experimental measure which is an upper limit on a parameter with a given Confidence Level...
An experimental measure of a parameter which is a mean value and a standard deviation.
class to do the calculus of a constraint based on a GiNaC symbolic expression
gaussobs(double mean, double sigma)
limitedobs(double limit, double cl=0.9, double m=0)
double likelihood(const parameters &p, bool check=1, int max=0) const
calculates the probability of getting all the experimental measures if the model describes the realit...
double loglikelihood(double hipothesis) const
double loglike(const parameters &p, bool check=1, int max=0) const
Abstract class for a model.
Base class to do the calculus of a constraint to the model.
shared_ptr< observable > o
double loglikelihood(double hipothesis) const
freeparameter(double mi, double ma, TRandom3 *r, double ss=1e-2)
bool isvalid() const
checks if the value of the parameter is between ::min and ::max
double value
value of the parameter
double max
maximum possible value for the parameter
calcuba(observable *ob, const FUNCP_CUBA &e0)
double loglikelihood(double hipothesis) const
double gausslikelihood(const parameters &p2) const
measure(double v=0, double e=0)
double error(double hipothesis) const
virtual int veto(const parameters &p, int max=0) const
double max
maximum possible value for the parameter
class to do the calculus of a constraint based on a GiNaC compiled expression
A parameter which will be fitted in the simulation.
double error(double hipothesis) const
the same as gaussobs but with a different initializer, such that the uncertainty sigma is absolute ...
void next(TRandom3 *r, double f=1)
changes randomly the value of the parameters
gauss2obs(double mean, double sigma)
shared_ptr< observable > o
theoretical expression for an experimental measure
prediction(observable *ob, const FUNCP_CUBA &e0)
void setvalues(const parameters &p)
double dist(const parameters &p) const
checks if this and another vector of parameters are within 1sigma of distance
bool isvalid() const
checks if all the values are between their minimums and maximums
shared_ptr< calcu > calculate
theoretical expression for the experimental measure
double error(double hipothesis) const
measure operator*(measure m2) const
double step
standard deviation of the random changes of ::value in next(TRandom3 *)