Commit b79f03e6 authored by Plaszczynski Stephane's avatar Plaszczynski Stephane
Browse files

protected access to Parser::vars()

parent 5d370ad3
......@@ -54,6 +54,7 @@
#include"Timer.hh"
#include"message_error.h"
#include<iostream>
#include<sstream>
#include <vector>
//--------------------
......@@ -68,11 +69,10 @@ using namespace std;
Chi2Combiner*
Chi2Factory::gimeChi2(Parser& parser){
//chi2 construit a partir de tous le Cl-Likeilihood
Chi2CMB* allCl= new Chi2CMB(parser.user_par);
Chi2CMB* allCl= new Chi2CMB(parser.vars());
//CLIK case
#ifdef CLIK
......@@ -166,7 +166,7 @@ Chi2Factory::gimeChi2(Parser& parser){
if (engine=="pico") {
cout << "USING pico ENGINE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl;
e=new MnPicoEngine(parser.user_par,lmax,PICODATA,false);
e=new MnPicoEngine(parser.vars(),lmax,PICODATA,false);
}
else{
//extra class params
......@@ -193,13 +193,13 @@ Chi2Factory::gimeChi2(Parser& parser){
//le calculateur de spectres
//MnUserVariables upar(parser.upar);
e=new MnClassEngine(parser.user_par,
e=new MnClassEngine(parser.vars(),
classparms,
pre);
}
//3. combiner de chi2 construit avec l'engine
Chi2Combiner* comb=new Chi2Combiner(parser.user_par,e);
Chi2Combiner* comb=new Chi2Combiner(parser.vars(),e);
//4. observables:
......@@ -211,38 +211,46 @@ Chi2Factory::gimeChi2(Parser& parser){
//lensing
#ifdef CLIK
if (lensing) {
Chi2Lensing* l=new Chi2Lensing(lensing,parser.user_par,e);
Chi2Lensing* l=new Chi2Lensing(lensing,parser.vars(),e);
comb->add(l);
}
#endif
//constrainte gaussienne (eg, H0)
vector<MinuitParameter> parameters=parser.constraints.Parameters();
for (size_t ip=0;ip<parameters.size();ip++){
MinuitParameter& p=parameters[ip];
Chi2Gauss1* g=new Chi2Gauss1(p.GetName(),p.Value(),p.Error(),parser.user_par);
comb->add(g);
}
//constrainte gaussienne on sum of 2 variables
vector<MinuitParameter> parameters1=parser.cons2.first.Parameters();
vector<MinuitParameter> parameters2=parser.cons2.second.Parameters();
for (size_t ip=0;ip<parameters1.size();ip++){
MinuitParameter& p1=parameters1[ip];
MinuitParameter& p2=parameters2[ip];
Chi2GaussSum* g=new Chi2GaussSum(p1.GetName(),p2.GetName(),parser.weight_cons2[0],parser.weight_cons2[1],p1.Value(),p1.Error(),parser.user_par);
comb->add(g);
std::cout << parser.weight_cons2[0] << " " << parser.weight_cons2[1] << endl;
//constrainte gaussienne: passed throught strings
for (size_t i=0;i<parser.cons.size();i++){
string line= parser.cons[i];
istringstream stream(line);
string token,tag;
stream >> token;
tag=trim(token);
if (tag=="gauss1") {
string parName;
double mean,sigma;
if (!(stream >> parName >> mean >> sigma)) throw Message_error("fail decode line="+line);
Chi2Gauss1* g=new Chi2Gauss1(parName,mean,sigma,parser.vars());
comb->add(g);
}
else if (tag=="gausssum2"){
string parName1,parName2;
double mean,sigma;
double weight1,weight2;
if (!(stream >> parName1 >> parName2 >> weight1 >> weight2 >> mean >> sigma)) throw Message_error("fail decode line="+line);
Chi2GaussSum* g=new Chi2GaussSum(parName1,parName2,weight1,weight2,mean,sigma,parser.vars());
comb->add(g);
}
else {
throw Message_error("Unknown constraint tag="+tag);
}
}
//BAO1d-packed
if (parser.params.param_present("BAOFile")){
{
const string myfile=Parser::getParFile(parser.params.find<string>("BAOFile",""));
cout << "BAO1D data taken from=" << myfile <<endl;
BAO_chi2* b=new BAO_chi2(myfile,parser.user_par,e);
BAO_chi2* b=new BAO_chi2(myfile,parser.vars(),e);
comb->add(b);
}
}
......@@ -252,7 +260,7 @@ Chi2Factory::gimeChi2(Parser& parser){
const string myfile=( parser.params.param_present("BAO2DFile")? Parser::getParFile(parser.params.find<string>("BAO2DFile","")) : Parser::getParFile(parser.params.find<string>("BAO2DFile1","")) );
cout << "BAO2d data taken from=" << myfile <<endl;
BAO2D_chi2* lik=new BAO2D_chi2(myfile,parser.user_par,e);
BAO2D_chi2* lik=new BAO2D_chi2(myfile,parser.vars(),e);
comb->add(lik);
......@@ -261,7 +269,7 @@ Chi2Factory::gimeChi2(Parser& parser){
while(parser.params.param_present(string("BAO2DFile")+dataToString(ibao2d))){
string b2did=Parser::getParFile(parser.params.find<string>(string("BAO2DFile")+dataToString(ibao2d)));
cout << "new BAO2d data from" << b2did << endl;
lik=new BAO2D_chi2(b2did,parser.user_par,e);
lik=new BAO2D_chi2(b2did,parser.vars(),e);
comb->add(lik) ;
ibao2d++;
......@@ -273,7 +281,7 @@ Chi2Factory::gimeChi2(Parser& parser){
if (parser.params.param_present("JLA_SNIA_File")){
const string myfile=Parser::getParFile(parser.params.find<string>("JLA_SNIA_File",""));
cout << " SNIa data for JLA chi2 from "<< myfile<< endl;
JLA_chi2* jla = new JLA_chi2(myfile,parser.user_par,e);
JLA_chi2* jla = new JLA_chi2(myfile,parser.vars(),e);
comb->add (jla);
}
#endif
......@@ -286,7 +294,7 @@ Chi2Factory::gimeChi2(Parser& parser){
comb->dumpIndex();
//single print
Variables upar(parser.user_par);
Variables upar(parser.vars());
cout << "it | " ;
for (size_t i=0;i<upar.Params().size();i++) cout << upar.Name(i) <<" | ";
cout << "status | chi2 | ptime"<<endl;
......
......@@ -91,7 +91,7 @@ void MCMC_adaptive::fill_chain(pdf* target_func, pdf* proposal,int init_step, co
_add_flag=false;
if(pl && (pl->_likelihood)->_parser.add_par)
if(pl && (pl->_likelihood)->_parser.derived.size()!=0)
{
_add_flag=true;
cout << "there will be derived par chain" << endl;
......
......@@ -92,7 +92,7 @@ void MCMC_metropolis::fill_chain(pdf* target_func, pdf* proposal,int init_step,c
for(int l=0;l<_par_name.size();l++) { chain_running << _par_name[l] << "\t";}
chain_running << endl;
_add_flag=false;
if(pl && (pl->_likelihood)->_parser.add_par)
if(pl && (pl->_likelihood)->_parser.derived.size()!=0)
{
_add_flag=true;
cout << "there will be derived par chain" << endl;
......
......@@ -391,25 +391,25 @@ void MCMC_sampler::set_par(const char* str, int dim)
void MCMC_sampler::set_par(Parser parser)
{
vector<bool> fix_par(parser.user_par.fixedParams());
vector<bool> fix_par(parser.vars().fixedParams());
int stop=fix_par.size();
HepVector size(_dim); //at this stage _dim is already defined
_starting_point=size;
_min_par=size;
_max_par=size;
_par_err=size;
vector<double> err=(parser.user_par).Errors();
vector<double> err=(parser.vars()).Errors();
int j=0;
for(int i = 0; i < stop; i++)
{
if(fix_par[i]==0)
{
_min_par[j]=(parser.user_par).Parameter(i).LowerLimit();
_max_par[j]=(parser.user_par).Parameter(i).UpperLimit();
_starting_point[j]=(parser.user_par).Parameter(i).Value();
_min_par[j]=(parser.vars()).Parameter(i).LowerLimit();
_max_par[j]=(parser.vars()).Parameter(i).UpperLimit();
_starting_point[j]=(parser.vars()).Parameter(i).Value();
_par_err[j]=err[i];
//setting par names
_par_name.push_back(parser.user_par.parNames()[i]);
_par_name.push_back(parser.vars().parNames()[i]);
j++;
}
......
......@@ -7,9 +7,9 @@
using namespace std;
//default constructor
planck_lkh::planck_lkh(Chi2Combiner* chi2, Parser parser): _chi2(chi2), _parser(parser), _e(0),_par(_parser.user_par.Params()),_fix_par(parser.user_par.fixedParams())
planck_lkh::planck_lkh(Chi2Combiner* chi2, Parser parser): _chi2(chi2), _parser(parser), _e(0),_par(_parser.vars().Params()),_fix_par(parser.vars().fixedParams())
{
if(_parser.add_par)
if(_parser.derived.size()!=0)
{
_derived_list=_parser.derived;
_derived_par.resize( _derived_list.size());
......@@ -51,7 +51,7 @@ void planck_lkh::evaluate(const HepVector& value)
_func_value=(*_chi2)(_par);
//need to treat cases where chi2 evaluation failed
_flag_fail_evaluate=!(_chi2->success());
if(_parser.add_par && !_flag_fail_evaluate){ //if extra parameters and not failed
if(_parser.derived.size()!=0 && !_flag_fail_evaluate){ //if extra parameters and not failed
_e=(_chi2->getEngine());
for(int index=0; index<_derived_list.size();index++)
{
......
......@@ -43,14 +43,11 @@ Parser::Parser(const char* filepar):params(filepar)
ifstream fin(filepar,ios::in);
string line;
Variables c1;
Variables c2;
//parmetres minuit +class
while (getline(fin,line)) {
string token,key;
istringstream info(line);
if (info >> token){
istringstream stream(line);
if (stream >> token){
key=trim(token);
// PAR OR FIX CASE////////////////////////////////////////////////
......@@ -58,12 +55,12 @@ Parser::Parser(const char* filepar):params(filepar)
//decode suite
string parName,parType;
double val;
if (!(info >> parName)) throw Message_error("fail parName in line="+line);
if (!(stream >> parName)) throw Message_error("fail parName in line="+line);
if (!(info >> parType)) throw Message_error("cannot decode type (cosmo/nui/derived?) in="+line);
if (!(stream >> parType)) throw Message_error("cannot decode type (cosmo/nui/derived?) in="+line);
bool isNui(parType.find("nui")!=string::npos);
if (!(info >> val)) throw Message_error("fail reading val in line="+line);
if (!(stream >> val)) throw Message_error("fail reading val in line="+line);
//fill arrays
if (key=="fix"){ //fix (pas besoin de step)
user_par.add(parName,isNui,val);
......@@ -72,11 +69,11 @@ Parser::Parser(const char* filepar):params(filepar)
}
else{ //error required
double step,xmin,xmax;;
if (!(info >> step)) throw Message_error("cannot decode step in="+line);
if (!(stream >> step)) throw Message_error("cannot decode step in="+line);
user_par.add(parName,isNui,val,step); //not fixed
// and optionally limits
cout << key << "\t" << parName << "\t" << parType << "\t" << val << "\t" << step ;
if ((info >> xmin >> xmax)) {
if ((stream >> xmin >> xmax)) {
user_par.SetLimits(parName,xmin,xmax);
cout << "\t" << xmin << "\t" << xmax ;
}
......@@ -88,15 +85,15 @@ Parser::Parser(const char* filepar):params(filepar)
//CLASS CASE ///////////////////////////////////////////////////////
else if (key=="class"){
string classname,classval;
if (!(info >> classname )) throw Message_error("fail decode line="+line);
if (!(stream >> classname )) throw Message_error("fail decode line="+line);
if (classname.substr(classname.size()-1,1)==string("\\")){
classname=classname.substr(0,classname.size()-1);
classname+=" ";
string suite;
info >> suite;
stream >> suite;
classname+=suite;
}
if (!(info >> classval)) throw Message_error("fail decode line="+line);
if (!(stream >> classval)) throw Message_error("fail decode line="+line);
//in case classname conatains "file" check existence+PARFILE
string::size_type index=classname.find("file");
if (index!=string::npos){
......@@ -110,25 +107,22 @@ Parser::Parser(const char* filepar):params(filepar)
else if (key=="gauss1"){
string parName;
double mean,sigma;
if (!(info >> parName >> mean >> sigma)) throw Message_error("fail decode line="+line);
constraints.Add(parName,mean,sigma);
if (!(stream >> parName >> mean >> sigma)) throw Message_error("fail decode line="+line);
cons.push_back(line);
}
// double PRIOR CASE (ie linear relation) ///////////////////////////////////////////////////////
else if (key=="gausssum2"){
string parName1,parName2;
double mean,sigma;
double weight1,weight2;
if (!(info >> parName1 >> parName2 >> weight1 >> weight2 >> mean >> sigma)) throw Message_error("fail decode line="+line);
c1.Add(parName1,mean,sigma);
c2.Add(parName2,mean,sigma);
weight_cons2.push_back(weight1);
weight_cons2.push_back(weight2);
if (!(stream >> parName1 >> parName2 >> weight1 >> weight2 >> mean >> sigma)) throw Message_error("fail decode line="+line);
cons.push_back(line);
}
// MCMC DERIVED PARAMETERS ///////////////////////////////////////////////////////
else if (key=="derived"){
add_par=true;
string parName;
if (!(info >> parName)) throw Message_error("fail decode line="+line);
if (!(stream >> parName)) throw Message_error("fail decode line="+line);
derived.push_back(parName);
cout << key << "\t" << parName <<endl;
}
......@@ -137,9 +131,6 @@ Parser::Parser(const char* filepar):params(filepar)
}
if (c1.Parameters().size() !=0)
cons2=make_pair<Variables,Variables>(c1,c2);
cout << __FILE__ << "*******************************************" << endl;
unsigned nn=0;
for (size_t i=0;i< user_par.Params().size();i++){
......
......@@ -47,21 +47,19 @@ public:
inline bool mnContours() {return params.find<bool>("computecontour",false);}
//inline string precisionFile() {return params.find<string>("precisionFile","");}
//utlity to read filenames/dir: if not found look into PARFILE dir (defined through macro)
//utlity to access filenames/dir: if not found build path relative to PARFILE dir (your par/ directory)
static std::string getParFile(const std::string& filename);
static std::string getParDir(const std::string& dirname);
//parameters
Variables user_par;
//acess to all Variables
const Variables& vars() const {return user_par;}
//derived par
bool add_par;
std::vector<string> derived;
std::vector<std::string> derived;
//for constraints
std::vector<std::string> cons;
//for gaussian constraints
MnUserParameters constraints;
std::pair<Variables,Variables> cons2;
std::vector<float> weight_cons2;
//CLASS
ClassParams classparms;
......@@ -71,6 +69,9 @@ public:
private:
Variables user_par;
};
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment