Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
NeutrinoFluxReweight::CentralValuesAndUncertainties Class Reference

A class to manage parameter central values and their uncertanities. More...

#include <CentralValuesAndUncertainties.h>

Public Member Functions

 CentralValuesAndUncertainties ()
 
void readFromXML (const char *filename)
 Read a xml file name to parse the parameters. More...
 
void addUncorrelated (Parameter &cv_par, double uncertainty)
 Add a parameter with its central value and its uncertainty. The parameter is specified as uncorrelated with all other parameters in the table, and any others that will be added. In that case, the uncertainty can be represented as a single floating point value. More...
 
void addCorrelated (ParameterTable &cv_pars, TMatrixD &cov_mx)
 Add a set of parameters with correlated uncertainties. The central values of the parameters must be provided along with the covariance matrix of the parameters. These parameters are assumed to be block uncorrelated with all the other parameters. More...
 
void setBaseSeed (int val)
 Set a beggining/base seed to be used in generating random parameter shifts for the many universe method. This base seed should be unique and not shared by any other many universe error calculator. More...
 
ParameterTable calculateParsForUniverse (int universe)
 Calculate a table of randomly varied parameters for a particular universe i. The universe number is used, along with the base seed, to calculate a unique seed for this universe, allowing our computation to be repeatable. We loop over all uncorrelated parameters and sample each from a normal distribution with mean=CV parameter and variance=sqrate of the uncertainty. We loop over all correlated sets of parameters. For each, we have a list of N central values x and a single joint NxN covariance matrix V. We execute a cholesky decomposition of V to find a lower left diagonal matrix L such that L L^T =V. Then we generate. More...
 
ParameterTable getCVPars ()
 Get the central value parameters. More...
 

Static Public Member Functions

static CentralValuesAndUncertaintiesgetInstance ()
 

Private Attributes

ParameterTable uncorrelated_pars
 
boost::interprocess::flat_map< std::string, double > uncorrelated_errors
 
std::vector< ParameterTablecorrelated_par_tables
 
std::vector< TMatrixD > covariance_matrices
 
TRandom3 * r3
 
int baseSeed
 

Static Private Attributes

static CentralValuesAndUncertaintiesinstance = 0
 

Detailed Description

A class to manage parameter central values and their uncertanities.

Definition at line 20 of file CentralValuesAndUncertainties.h.

Constructor & Destructor Documentation

NeutrinoFluxReweight::CentralValuesAndUncertainties::CentralValuesAndUncertainties ( )

Setting the seed to zero.

Definition at line 20 of file CentralValuesAndUncertainties.cpp.

20  {
21  //! Setting the seed to zero.
22  r3=new TRandom3(0);
23  baseSeed = 0;
24  }

Member Function Documentation

void NeutrinoFluxReweight::CentralValuesAndUncertainties::addCorrelated ( ParameterTable cv_pars,
TMatrixD &  cov_mx 
)

Add a set of parameters with correlated uncertainties. The central values of the parameters must be provided along with the covariance matrix of the parameters. These parameters are assumed to be block uncorrelated with all the other parameters.

Definition at line 127 of file CentralValuesAndUncertainties.cpp.

127  {
128  correlated_par_tables.push_back(cv_pars);
129  covariance_matrices.push_back(cov_mx);
130  }
void NeutrinoFluxReweight::CentralValuesAndUncertainties::addUncorrelated ( Parameter cv_par,
double  uncertainty 
)

Add a parameter with its central value and its uncertainty. The parameter is specified as uncorrelated with all other parameters in the table, and any others that will be added. In that case, the uncertainty can be represented as a single floating point value.

Definition at line 121 of file CentralValuesAndUncertainties.cpp.

121  {
123  uncorrelated_errors[cv_par.first] = uncertainty;
124  }
boost::interprocess::flat_map< std::string, double > uncorrelated_errors
void setParameter(Parameter p)
add a parameter to the table or, if already there, reset its value
ParameterTable NeutrinoFluxReweight::CentralValuesAndUncertainties::calculateParsForUniverse ( int  universe)

Calculate a table of randomly varied parameters for a particular universe i. The universe number is used, along with the base seed, to calculate a unique seed for this universe, allowing our computation to be repeatable. We loop over all uncorrelated parameters and sample each from a normal distribution with mean=CV parameter and variance=sqrate of the uncertainty. We loop over all correlated sets of parameters. For each, we have a list of N central values x and a single joint NxN covariance matrix V. We execute a cholesky decomposition of V to find a lower left diagonal matrix L such that L L^T =V. Then we generate.

We are going to use 100% correlated bin-to-bin for systematic errors in thin target data:

Definition at line 135 of file CentralValuesAndUncertainties.cpp.

135  {
136 
137  //If universe = -1, then it is the central value:
138  double cvfactor = 1.0;
139  if(universe==-1)cvfactor = 0.0;
140  int univ_seed = baseSeed + universe;
141  r3->SetSeed(univ_seed);
142 
143  ParameterTable ptable;
144 
145  //! We are going to use 100% correlated bin-to-bin for systematic errors in thin target data:
146  double sigma_pc_pip = r3->Gaus(0.0,1.0);
147  double sigma_pc_pim = r3->Gaus(0.0,1.0);
148  double sigma_pc_kap = r3->Gaus(0.0,1.0);
149  double sigma_pc_kam = r3->Gaus(0.0,1.0);
150  double sigma_pc_p = r3->Gaus(0.0,1.0);
151  double sigma_pc_n = r3->Gaus(0.0,1.0);
152 
153  const boost::interprocess::flat_map<std::string, double>& table_uncorr_pars = uncorrelated_pars.getMap();
155  for(;it!=table_uncorr_pars.end();++it){
156  double sigma = r3->Gaus(0.0,1.0);
157  //redefining sigma for 100% correlation:
158  if((it->first).find("ThinTarget_pC_pip_sys")<10)sigma = sigma_pc_pip;
159  if((it->first).find("ThinTarget_pC_pim_sys")<10)sigma = sigma_pc_pim;
160  if((it->first).find("ThinTargetLowxF_pC_kap_sys")<10)sigma = sigma_pc_kap;
161  if((it->first).find("ThinTargetLowxF_pC_kam_sys")<10)sigma = sigma_pc_kam;
162  if((it->first).find("ThinTarget_pC_p_sys")<10) sigma = sigma_pc_p;
163  if((it->first).find("ThinTarget_pC_n_sys")<10) sigma = sigma_pc_n;
164  double new_val = it->second + cvfactor*sigma*uncorrelated_errors[it->first];
165  Parameter p(it->first,new_val);
166  ptable.setParameter(p);
167  }
168 
169  TDecompChol *decomp;
170 
171  for(size_t ii=0;ii<covariance_matrices.size();++ii){
172 
173  decomp=new TDecompChol(covariance_matrices[ii],0.0);
174 
175  bool isPosDef=decomp->Decompose();
176  TMatrixD MxU = decomp->GetU();
177  delete decomp;
178  TMatrixD MxV(MxU);
179  MxV.Transpose(MxU);
180  int nmat = MxV.GetNcols();
181  TVectorD vsigma(nmat);
182  for(int jj=0;jj<nmat;jj++){
183  vsigma[jj]=cvfactor*(r3->Gaus(0.0,1.0));
184  }
185  TVectorD vecDShift = MxV*vsigma;
186 
187  const boost::interprocess::flat_map<std::string, double>& tb = (correlated_par_tables[ii]).getMap();
189 
190  for(;it_tb != tb.end();++it_tb){
191  std::string tmp_name = it_tb->first;
192  std::string snID = tmp_name.substr((it_tb->first).rfind("_")+1,(it_tb->first).length());
193  std::stringstream ssID(snID);
194  int nID;
195  ssID >> nID;
196  double new_val = it_tb->second + vecDShift[nID];
197  Parameter p(it_tb->first,new_val);
198  if(isPosDef)ptable.setParameter(p);
199  }
200 
201  }
202 
203  return ptable;
204 
205  }
const boost::interprocess::flat_map< std::string, double > & getMap() const
std::string string
Definition: nybbler.cc:12
intermediate_table::const_iterator const_iterator
std::pair< std::string, double > Parameter
p
Definition: test.py:223
boost::interprocess::flat_map< std::string, double > uncorrelated_errors
ParameterTable NeutrinoFluxReweight::CentralValuesAndUncertainties::getCVPars ( )

Get the central value parameters.

Definition at line 207 of file CentralValuesAndUncertainties.cpp.

207  {
208 
209  ParameterTable ptableCV;
210 
211  const boost::interprocess::flat_map<std::string, double>& table_pars=uncorrelated_pars.getMap();
213  for(;it!=table_pars.end();it++){
214  Parameter p(it->first,it->second);
215  ptableCV.setParameter(p);
216  }
217 
218  //Correlated:
219  for(size_t ii=0;ii<covariance_matrices.size();ii++){
220  const boost::interprocess::flat_map<std::string, double>& corr_table_pars = correlated_par_tables[ii].getMap();
221  it = corr_table_pars.begin();
222  for(;it != corr_table_pars.end();it++){
223  Parameter p(it->first,it->second);
224  ptableCV.setParameter(p);
225  }
226 
227  }
228 
229  return ptableCV;
230 
231  }
const boost::interprocess::flat_map< std::string, double > & getMap() const
intermediate_table::const_iterator const_iterator
std::pair< std::string, double > Parameter
p
Definition: test.py:223
CentralValuesAndUncertainties * NeutrinoFluxReweight::CentralValuesAndUncertainties::getInstance ( )
static
void NeutrinoFluxReweight::CentralValuesAndUncertainties::readFromXML ( const char *  filename)

Read a xml file name to parse the parameters.

Reading the uncorrelated parameters:

Reading the uncorrelated list:

Reading the correlated parameters:

Definition at line 26 of file CentralValuesAndUncertainties.cpp.

26  {
27  using boost::property_tree::ptree;
28  ptree top;
29 
30  read_xml(filename,top,2); // option 2 removes comment strings
31 
32  //! Reading the uncorrelated parameters:
33  ptree& uncorrelated = top.get_child("pars.uncorrelated");
34  ptree::iterator it = uncorrelated.begin();
35  for(; it!=uncorrelated.end(); ++it){
36  // it->first is the name
37  // it->second is the child property tree
38  double cv=it->second.get<double>("cv");
39  double err=it->second.get<double>("err");
40  Parameter p(it->first,cv);
42  }
43 
44  //! Reading the uncorrelated list:
45  ptree& uncorrelated_list = top.get_child("pars.uncorrelated_list");
46  it = uncorrelated_list.begin();
47  for(; it!=uncorrelated_list.end(); ++it){
48  // it->first is the name
49  // it->second is the child property tree
50 
51  std::string cvs_string=it->second.get<std::string>("cvs");
52  std::string errs_string=it->second.get<std::string>("errs");
53  double cv=0;
54  int ii=0;
56  std::stringstream ss(cvs_string);
57  std::vector<Parameter> tmp_par;
58  while(ss >> cv){
59  std::stringstream sID;
60  sID << ii;
61  std::string nameID = sID.str();
62  name = it->first + "_" + nameID;
63  Parameter p(name,cv);
64  tmp_par.push_back(p);
65  ii++;
66  };
67 
68  double err=0;
69  std::stringstream sserr(errs_string);
70  ii=0;
71  while(sserr >> err){
73  ii++;
74  }
75 
76  }
77 
78  //! Reading the correlated parameters:
79  ptree& correlated = top.get_child("pars.correlated");
80  it = correlated.begin();
81  for(; it!=correlated.end(); ++it){
82  // it->first is the name
83  // it->second is the child property tree
84  std::string cvs_string=it->second.get<std::string>("cvs");
85  std::string covmx_string=it->second.get<std::string>("covmx");
86 
87  //filling the Parameter table:
88  std::stringstream ss(cvs_string);
89  double cv=0;
90  int ii=0;
92  ParameterTable ptable;
93  while(ss >> cv){
94  std::stringstream sID;
95  sID << ii;
96  std::string nameID = sID.str();
97  name = it->first + "_" +nameID;
98  Parameter p(name,cv);
99  ptable.setParameter(p);
100  ii++;
101  };
102  TMatrixD mcov(ii,ii);
103  //filling the matrix:
104  std::stringstream ssmx(covmx_string);
105  double err;
106  int idx = 0;
107  while(ssmx >> err){
108  mcov(idx/ii,idx%ii) = err;
109  idx++;
110  }
112  }
113 
114  //Auxiliar parameter.
115  //cv=1.0 and error 100%:
116  Parameter par_aux("aux_parameter",1.0);
118 
119  }
static QCString name
Definition: declinfo.cpp:673
intermediate_table::iterator iterator
std::string string
Definition: nybbler.cc:12
std::pair< std::string, double > Parameter
string filename
Definition: train.py:213
p
Definition: test.py:223
void addUncorrelated(Parameter &cv_par, double uncertainty)
Add a parameter with its central value and its uncertainty. The parameter is specified as uncorrelate...
void err(const char *fmt,...)
Definition: message.cpp:226
void addCorrelated(ParameterTable &cv_pars, TMatrixD &cov_mx)
Add a set of parameters with correlated uncertainties. The central values of the parameters must be p...
void NeutrinoFluxReweight::CentralValuesAndUncertainties::setBaseSeed ( int  val)

Set a beggining/base seed to be used in generating random parameter shifts for the many universe method. This base seed should be unique and not shared by any other many universe error calculator.

Definition at line 132 of file CentralValuesAndUncertainties.cpp.

Member Data Documentation

int NeutrinoFluxReweight::CentralValuesAndUncertainties::baseSeed
private

Definition at line 54 of file CentralValuesAndUncertainties.h.

std::vector<ParameterTable> NeutrinoFluxReweight::CentralValuesAndUncertainties::correlated_par_tables
private

Definition at line 51 of file CentralValuesAndUncertainties.h.

std::vector<TMatrixD> NeutrinoFluxReweight::CentralValuesAndUncertainties::covariance_matrices
private

Definition at line 52 of file CentralValuesAndUncertainties.h.

CentralValuesAndUncertainties * NeutrinoFluxReweight::CentralValuesAndUncertainties::instance = 0
staticprivate

Definition at line 47 of file CentralValuesAndUncertainties.h.

TRandom3* NeutrinoFluxReweight::CentralValuesAndUncertainties::r3
private

Definition at line 53 of file CentralValuesAndUncertainties.h.

boost::interprocess::flat_map<std::string, double> NeutrinoFluxReweight::CentralValuesAndUncertainties::uncorrelated_errors
private

Definition at line 50 of file CentralValuesAndUncertainties.h.

ParameterTable NeutrinoFluxReweight::CentralValuesAndUncertainties::uncorrelated_pars
private

Definition at line 49 of file CentralValuesAndUncertainties.h.


The documentation for this class was generated from the following files: