LTF
LTF.h
1 /*
2  Copyright 2021, D. Britzger, Max-Planck-Institute for Physics, Munich, Germany
3 
4  Permission is hereby granted, free of charge, to any person obtaining
5  a copy of this software and associated documentation files (the
6  "Software"), to deal in the Software without restriction, including
7  without limitation the rights to use, copy, modify, merge, publish,
8  distribute, sublicense, and/or sell copies of the Software, and to
9  permit persons to whom the Software is furnished to do so, subject to
10  the following conditions:
11 
12  The above copyright notice and this permission notice shall be
13  included in all copies or substantial portions of the Software.
14 
15  The Software is provided "as is", without warranty of any kind,
16  express or implied, including but not limited to the warranties of
17  merchantability, fitness for a particular purpose and
18  noninfringement. In no event shall the authors or copyright holders be
19  liable for any claim, damages or other liability, whether in an action
20  of contract, tort or otherwise, arising from, out of or in connection
21  with the Software or the use or other dealings in the Software.
22 */
23 #ifndef LTF_h
24 #define LTF_h
25 
26 // --------------------------------------------------------------- //
27 /*
28  *
29  * LTF
30  *
31  * The Linear Template Fit implemented using the Eigen library
32  *
33  */
34 // --------------------------------------------------------------- //
35 
36 #include "Eigen/Sparse"
37 #include "Eigen/Dense"
38 #include <string>
39 #include <map>
40 #include <unordered_map>
41 #include <iostream>
42 #include <memory>
43 
44 using namespace std;
45 
53 class LTF {
54 
55 public:
56  enum class Uncertainty { Constrained=1, Unconstrained=0, External=-1};
57 
58 public:
59 
60  // ------------------------------------------- //
65  class LiTeFit {
66  public:
67 
68  LiTeFit() {}
69  ~LiTeFit(){}
70  double DoLiTeFit();
71  double DoLiTeFit(int mPolN, int mOrdInfrc, const Eigen::VectorXd& ahat);
72  double DoIterativeFitNewton(int nIter=3, int nPol=2, int nInfrc=1);
73  double DoIterativeFitTaylor(int nIter=4, double StepSize=0.6, int nPol=2, int nInfrc=1);
74  void ApplyLogNormalDistribution();
75  void RescaleInputErrors(std::vector<double> values ){
76  RescaleInputErrors(Eigen::Map<Eigen::VectorXd>(&values[0],values.size()));
77  }
78  void RescaleInputErrors(const Eigen::VectorXd& values );
79 
80  // --- input, as used in LiTeFit
81  Eigen::VectorXd Dt;
82  Eigen::MatrixXd M ;
83  Eigen::MatrixXd Y ;
84  Eigen::MatrixXd X ;
85  Eigen::MatrixXd A ;
86  std::vector<std::pair<std::string,Eigen::MatrixXd > > Vs ;
87  std::vector<std::pair<std::string,Eigen::VectorXd > > Sys ;
88  std::map<std::string,Eigen::MatrixXd > VsExt ;
89  std::map<std::string,Eigen::VectorXd > SysExt;
90  std::map<std::string,LTF::Uncertainty> SysIsConstr;
91  std::map<std::string,Eigen::MatrixXd > SysY;
92  std::map<std::string,Eigen::MatrixXd > SysA;
93  std::map<std::string,double> corrSys;
94  vector<double> Gamma;
95 
96  // --- output
97  double a0 = 0;
98  double a0_errorFit = 0;
99  double a0_errorExt = 0;
100  double a0_errorTmpl = 0;
101  double a0_errorRespMat = 0;
102  double chisq = 0;
103  double chisq_error = 0;
104  Eigen::MatrixXd F;
105  Eigen::VectorXd chisq_y;
106  std::map<std::string,double> chisq_part;
107  Eigen::VectorXd ahat;
108  Eigen::VectorXd ahat_errorFit;
109  Eigen::VectorXd ahat_errorExt;
110  Eigen::VectorXd ahat_errorTmpl;
111  Eigen::VectorXd ahat_errorRespMat;
112  Eigen::VectorXd TheoFit;
113  std::map<std::string,Eigen::MatrixXd> Vsource;
114  std::map<std::string,Eigen::VectorXd> DeltaSys;
115  std::map<std::string,Eigen::MatrixXd> VsourceExt;
116  std::map<std::string,Eigen::VectorXd> DeltaSysExt;
117  std::map<std::string,Eigen::VectorXd> DeltaSysY;
118  std::map<std::string,Eigen::VectorXd> DeltaSysA;
119 
120  // --- result from alternative pol2-fit to chi2-values of the templates
121  Eigen::VectorXd achk;
122  Eigen::VectorXd achk_errorFit;
123  double achk_chisq;
124 
125  // --- result from linearized second-order model approximation
126  Eigen::VectorXd ahat21;
127  Eigen::VectorXd EDM21;
128  double EDM21_chisq;
129  Eigen::VectorXd delta_m21;
130 
131  // ---- printout, and useful getters
132  void PrintShort() const;
133  void PrintFull() const;
134  Eigen::MatrixXd Mc(int nPow=1, int nInfrc=0) const;
135  Eigen::VectorXd a0pow(int nPow, int nInfrc, const Eigen::VectorXd& ahat) const;
136  Eigen::MatrixXd McApprox(int powmax, int intfrc, const Eigen::VectorXd& ahat) const;
137  Eigen::MatrixXd W() const;
138  Eigen::MatrixXd VFit() const { return LTF::VSum(Vsource,DeltaSys); }
139  Eigen::MatrixXd VExt() const { return LTF::VSum(VsourceExt,DeltaSysExt); }
140  bool GetLogNormal() const { return LogNormal; }
141  Eigen::VectorXd CalculatePrediction(double v ) const {
142  return CalculatePrediction(std::vector<double>{v});}
143  Eigen::VectorXd CalculatePrediction(std::vector<double> v ) const {
144  return CalculatePrediction(Eigen::Map<Eigen::VectorXd>(&v[0],v.size()));}
145  Eigen::VectorXd CalculatePrediction(Eigen::VectorXd v ) const;
146 
147  Eigen::VectorXd ComputeLinearTemplateFit(int mPolN = 1, int mOrdInfrc = 0, const Eigen::VectorXd& ahat = Eigen::VectorXd() ) const;
148  Eigen::VectorXd ComputeNewtonEstimator(int mPolN = 1, int mOrdInfrc = 0, const Eigen::VectorXd& ahat = Eigen::VectorXd() ) /*const*/;
149 
150  protected:
151  void ApplyGamma(std::map<std::string,Eigen::VectorXd>& Delta) const;
152  void ApplyGamma(std::map<std::string,Eigen::MatrixXd>& VMat) const;
153  bool LogNormal = false;
154  std::vector<std::pair<std::string,Eigen::MatrixXd> > SysAX;
155  Eigen::VectorXd ErrorScale;
156  Eigen::VectorXd ybar;
157  Eigen::MatrixXd Ytil;
158 
159  }; // end class LTF::LiTeFitResult
160  // ------------------------------------------- //
161 
162 public:
163  LTF() {}
164  ~LTF() {}
165 
166  // ------------------------------------------- //
167  // --- set data
168  // ------------------------------------------- //
170  void SetData(const vector<double>& data) {
171  std::vector<double> tmp = data; // copy to no-const for eigen...
172  fDt = Eigen::Map<Eigen::VectorXd>(&tmp[0], tmp.size());
173  }
175  void SetData(size_t n, const double* data) {
176  SetData(vector<double>(data,data+n));
177  }
178 
179 
180  // ------------------------------------------- //
181  // --- add a new template
182  // ------------------------------------------- //
187  void AddTemplate(double mval, const vector<double>& dist) {
188  AddTemplate(vector<double>{mval},dist);
189  }
191  void AddTemplate(double mval, size_t n , const double* dist) {
194  AddTemplate(mval,std::vector<double>(dist, dist+n));
195  }
197  void AddTemplate(const vector<double> mvals, size_t n , const double* dist) {
198  AddTemplate(mvals,std::vector<double>(dist, dist+n));
199  }
201  void AddTemplate(const vector<double>& mvals, const vector<double>& dist);
202 
203 
204  // ------------------------------------------- //
205  // --- set error
206  // ------------------------------------------- //
213  void AddError(std::string name, size_t n, const double* error, double corr=0., LTF::Uncertainty constr = LTF::Uncertainty::Constrained);
214 
216  void AddError(const std::string& name, const std::vector<double>& error, double corr=0., LTF::Uncertainty constr = LTF::Uncertainty::Constrained) {
217  AddError(name,error.size(),&error[0],corr,constr);
218  }
219 
227  void AddError(const std::string& name, const std::vector<std::vector<double> >& cov, LTF::Uncertainty constr = LTF::Uncertainty::Constrained);
228 
236  void AddErrorRelative(const std::string& name, const std::vector<std::vector<double> >& cov_rel, LTF::Uncertainty constr = LTF::Uncertainty::Constrained);
237 
245  void AddErrorRelative(std::string name, size_t n, const double* error, double corr=0., LTF::Uncertainty constr = LTF::Uncertainty::Constrained) {
246  AddErrorRelative(name,std::vector<double>(error,error+n),corr,constr);
247  }
248 
249 
250 
252  void AddErrorRelative(const std::string& name, std::vector<double> error, double corr=0., LTF::Uncertainty constr = LTF::Uncertainty::Constrained) {
253  if ( fDt.rows() == 0 || size_t(fDt.rows()) != error.size() ) {
254  std::cerr<<"Error! Data distribution not set or its size is inconsistent with input uncertainty vector."<<std::endl;
255  exit(1);
256  }
257  for ( size_t i=0 ; i<error.size( ); i++ ) error[i] *= fDt(i);
258  AddError(name,error,corr,constr);
259  }
260 
263  void AddErrorPercent(std::string name, size_t n, const double* error, double corr=0., LTF::Uncertainty constr = LTF::Uncertainty::Constrained) {
264  AddErrorPercent(name,std::vector<double>(error,error+n),corr,constr);
265  }
266 
268  void AddErrorPercent(const std::string& name, std::vector<double> error, double corr=0., LTF::Uncertainty constr = LTF::Uncertainty::Constrained) {
269  if ( fDt.rows() == 0 || size_t(fDt.rows()) != error.size() ) {
270  std::cerr<<"Error! Data distribution not set or its size is inconsistent with input uncertainty vector."<<std::endl;
271  exit(1);
272  }
273  for ( size_t i=0 ; i<error.size( ); i++ ) error[i] *= fDt(i) / 100.;
274  AddError(name,error,corr,constr);
275  }
276 
284  void AddUncorrelatedErrorSquared(const std::string& name, size_t n, const double* error2, LTF::Uncertainty constr = LTF::Uncertainty::Constrained) {
285  if ( constr == LTF::Uncertainty::Unconstrained ) {
286  std::cerr<<"Error! An uncorrelated error cannot be 'unconstrained'. Error name: "<<name<<std::endl;
287  exit(1);
288  }
289  std::vector<std::vector<double> > cov(n);
290  for ( size_t i = 0 ; i<n ;i++ ) {
291  cov[i].resize(n);
292  cov[i][i] = error2[i];
293  }
294  AddError(name, cov, constr);
295  }
296 
304  void AddCorrelatedError(const std::string& name, vector<double> error, LTF::Uncertainty constr = LTF::Uncertainty::Constrained);
305 
306  // ------------------------------------------- //
316  void AddTemplateError(const std::string& name, const std::vector<double>& mvals, size_t n, const double* error, double corr=0.);
317 
319  void AddTemplateError(const std::string& name, double mval, size_t n, const double* error, double corr=0.) {
320  AddTemplateError(name, std::vector<double>{mval}, n, error, corr);
321  }
322 
324  void AddTemplateError(const std::string& name, const std::vector<double>& mvals, const std::vector<double>& error, double corr=0.) {
325  AddTemplateError(name,mvals,error.size(),&error[0],corr);
326  }
328  void AddTemplateError(const std::string& name, double mval, const std::vector<double>& error, double corr=0.) {
329  AddTemplateError(name,std::vector<double>{mval},error.size(),&error[0],corr);
330  }
331 
333  void AddTemplateErrorSquared(const std::string& name, const std::vector<double>& mvals, size_t n, const double* error2, double corr=0.) {
334  AddTemplateErrorSquared(name, mvals, std::vector<double>(error2, error2+n), corr);
335  }
337  void AddTemplateErrorSquared(const std::string& name, double mval, size_t n, const double* error2, double corr=0.) {
338  AddTemplateErrorSquared(name, std::vector<double>{mval}, std::vector<double>(error2, error2+n), corr);
339  }
340 
342  void AddTemplateErrorSquared(const std::string& name, const std::vector<double>& mvals, const std::vector<double>& error2, double corr=0.) {
343  std::vector<double> vect = error2;
344  for ( double& e : vect ) e = std::sqrt(e);
345  AddTemplateError(name, mvals, vect.size(), &vect[0], corr);
346  }
347 
348 
349  // ------------------------------------------- //
350  // --- set a (detector) response matrix [optional]
351  // ------------------------------------------- //
360  void SetResponseMatrix(const std::vector<std::vector<double> >& A);
361 
363  void SetResponseMatrix(const Eigen::MatrixXd& A) { fA = A; }
364 
365 
366  // ------------------------------------------- //
374  void AddResponseMatrixError(const std::string& name, const std::vector<std::vector<double> >& errorA, double corr=0.) {
375  AddResponseMatrixError(name, LTF::Std_to_Mat(errorA), corr);
376  }
378  void AddResponseMatrixError(const std::string& name, const Eigen::MatrixXd& errorA, double corr=0.) {
379  SetCorrSys(name,corr);
380  fSysA[name] = errorA;
381  }
383  void AddResponseMatrixErrorSquared(const std::string& name, std::vector<std::vector<double> > error2A, double corr=0.) {
384  for ( auto& v : error2A )
385  for ( double& e2 : v ) e2 = sqrt(e2);
386  AddResponseMatrixError(name, LTF::Std_to_Mat(error2A), corr);
387  }
389  void AddResponseMatrixErrorSquared(const std::string& name, const Eigen::MatrixXd& error2A, double corr=0.) {
390  AddResponseMatrixError(name, error2A.cwiseSqrt(), corr);
391  }
392 
393  // ------------------------------------------- //
394  // --- set exponential factor(s) gamma
395  // ------------------------------------------- //
400  void SetGamma(double gamma = 1) {
401  if ( fTmplDistN.empty() ) {
402  std::cerr<<"Warning in SetGamma. Templates should be set first!"<<std::endl;
403  fGamma = vector<double>(50,gamma);
404  }
405  else {
406  if ( fTmplDistN.begin()->first.size() > 1 )
407  std::cout<<"Warning."
408  <<" SetGamma(double) is ambigous when performing a multivariate LTF."
409  <<" Better use SetGamma(vector<double>)."<<std::endl;
410 
411  fGamma = vector<double>(fTmplDistN.begin()->first.size(),gamma);
412  }
413  }
415  void SetGamma(const vector<double>& gamma) {
416  fGamma = gamma;
417  }
418 
419  // ------------------------------------------- //
420  // --- fit range
421  // ------------------------------------------- //
425  void SetFitRange(int binmin, int binmax) {
426  fBinMin = binmin;
427  fBinNN = binmax -binmin+1;
428  if ( fBinNN<=0 ) {
429  cout<<"Error. No bins left for fit."<<endl;
430  exit(1);
431  }
432  }
433 
434  // ------------------------------------------- //
435  // --- perform linear template fit
436  // ------------------------------------------- //
439  const LiTeFit& DoLiTeFit();
440  const LiTeFit& DoIterativeFitNewton(int nIter=3, int nPol=2, int nInfrc=1);
441 
442  // ------------------------------------------- //
443  // --- Choose normal or log-normal uncertainties
444  // ------------------------------------------- //
449  void UseLogNormalUncertainties(bool LogNormal = true) {
450  fUseLog = LogNormal;
451  }
454  return fUseLog;
455  }
456 
457  // ------------------------------------------- //
458  // --- use nuisance parameter or covariance matrices
459  // ------------------------------------------- //
465  void UseNuisanceParameters(bool UseNuisance=true) {
466  fUseNuisance = UseNuisance;
467  }
468 
469 
470  // ------------------------------------------- //
471  // --- rescale (absolute) uncertainties
472  // ------------------------------------------- //
487  void RescaleInputErrors(std::vector<double> values ) {
488  if ( values.size() != size_t(fDt.rows()) ) {
489  std::cerr<<"Error in LTF::RescaleInputErrors. Size of input vector not compatible with size of data vector."<<std::endl;
490  exit(1);
491  }
492  fErrorScale = Eigen::Map<Eigen::VectorXd>(&values[0],values.size());
493  }
494 
495 
496 // ------------------------------------------- //
497 // --- members
498 protected:
499  Eigen::VectorXd fDt;
500  std::vector<std::pair<vector<double>,Eigen::VectorXd> > fTmplDistN;
501  Eigen::MatrixXd fA;
502  std::vector<std::pair<std::string,Eigen::MatrixXd > > fVs;
503  std::vector<std::pair<std::string,Eigen::VectorXd > > fSys;
504  std::map<std::string,LTF::Uncertainty> fSysIsConstr;
505  std::map<std::string,Eigen::MatrixXd > fVsExt;
506  std::map<std::string,Eigen::VectorXd > fSysExt;
507  std::map<std::string,std::map<vector<double>,Eigen::VectorXd> > fSysY;
508  std::map<std::string,Eigen::MatrixXd> fSysA;
509  std::map<std::string,double> fcorrSys;
510 
511  Eigen::VectorXd fErrorScale;
512  std::vector<double> fGamma;
513  bool fUseLog = false;
514  bool fUseNuisance = true;
516 
517  int fBinMin = 0;
518  int fBinNN = 0;
519 
520 // ------------------------------------------- //
521 // --- protected methods
522 protected:
523  size_t N() const;
524  Eigen::MatrixXd Calc_M() const;
525  Eigen::MatrixXd Calc_Y() const;
526  Eigen::MatrixXd Calc_X() const;
527  std::map<std::string,Eigen::MatrixXd > Calc_dY(
528  std::map<std::string,std::map<vector<double>,Eigen::VectorXd> >& fSysY) const;
529  void SetLiTeFitInput();
530  void SetCorrSys(const std::string& name, double c);
531 
532 
533 // ------------------------------------------- //
534 // ---- static helper functions
535 public:
536 
538  static Eigen::VectorXd GetDelta_V(const Eigen::MatrixXd& V) {
539  return V.diagonal().cwiseSqrt();
540  }
541 
543  static Eigen::MatrixXd GetV_Delta(const Eigen::VectorXd& d, double corr);
544 
546  template< class T >
547  static std::map<std::string,Eigen::MatrixXd> GetV_DeltaSys(const T& DeltaSys) {
548  std::map<std::string,Eigen::MatrixXd> ret;
549  for ( auto& s : DeltaSys ) ret[s.first] = LTF::GetV_Delta(s.second,1);
550  return ret;
551  }
552 
554  template< class T >
555  static std::map<std::string,Eigen::VectorXd> GetDelta_Vsource(const T& Vsource) {
556  std::map<std::string,Eigen::VectorXd> ret;
557  for ( auto& s : Vsource ) ret[s.first] = LTF::GetDelta_V(s.second);
558  return ret;
559  }
560 
564  static Eigen::MatrixXd VSum( const std::map<std::string,Eigen::MatrixXd>& Vs, const std::map<std::string,Eigen::VectorXd>& DeltaSys );
565 
568  static Eigen::MatrixXd VSum( const std::vector<std::pair<std::string,Eigen::MatrixXd > >& Vs );
569 
571  static Eigen::MatrixXd Cov_to_Cor(const Eigen::MatrixXd& V);
572 
574  static Eigen::MatrixXd Std_to_Mat(const std::vector<std::vector<double> >& A);
575 
576 };
577 
578 #endif
std::map< std::string, LTF::Uncertainty > SysIsConstr
uncertainty specification for Sys
Definition: LTF.h:90
static Eigen::MatrixXd VSum(const std::map< std::string, Eigen::MatrixXd > &Vs, const std::map< std::string, Eigen::VectorXd > &DeltaSys)
Calculate covariance matrix as sum of individual matrices and systematic shifts.
Definition: LTF.cxx:2262
static std::map< std::string, Eigen::VectorXd > GetDelta_Vsource(const T &Vsource)
calculate size of uncertainty from covariance matrix
Definition: LTF.h:555
std::map< std::string, Eigen::MatrixXd > fVsExt
Covariance matrices, treated as external.
Definition: LTF.h:505
void AddResponseMatrixErrorSquared(const std::string &name, std::vector< std::vector< double > > error2A, double corr=0.)
Add a new error source of the templates to LTF.
Definition: LTF.h:383
LiTeFit fLTF
result
Definition: LTF.h:515
void AddTemplate(double mval, size_t n, const double *dist)
Add new template for a given reference point.
Definition: LTF.h:191
std::vector< std::pair< vector< double >, Eigen::VectorXd > > fTmplDistN
templates
Definition: LTF.h:500
void AddTemplateError(const std::string &name, double mval, size_t n, const double *error, double corr=0.)
Add a new error source of the templates to LTF.
Definition: LTF.h:319
Eigen::MatrixXd fA
the response matrix (opional)
Definition: LTF.h:501
Eigen::MatrixXd A
Response matrix (optional) [only used for (relative) error propagation].
Definition: LTF.h:85
void AddTemplateErrorSquared(const std::string &name, const std::vector< double > &mvals, const std::vector< double > &error2, double corr=0.)
Add a new error source of the templates to LTF.
Definition: LTF.h:342
static Eigen::VectorXd GetDelta_V(const Eigen::MatrixXd &V)
calculate uncertainty from a covariance matrix
Definition: LTF.h:538
void AddTemplateError(const std::string &name, double mval, const std::vector< double > &error, double corr=0.)
Add a new error source of the templates to LTF.
Definition: LTF.h:328
Eigen::MatrixXd X
Matrix X (templates) [only required for error propagation].
Definition: LTF.h:84
static Eigen::MatrixXd GetV_Delta(const Eigen::VectorXd &d, double corr)
calculate covariance matrix from an uncertainty
Definition: LTF.cxx:2244
std::map< std::string, Eigen::MatrixXd > fSysA
uncertainty of the response matrix (uncorrelated)
Definition: LTF.h:508
void AddTemplateError(const std::string &name, const std::vector< double > &mvals, const std::vector< double > &error, double corr=0.)
Add a new error source of the templates to LTF.
Definition: LTF.h:324
Linear template fit.
Definition: LTF.h:53
void AddTemplateErrorSquared(const std::string &name, const std::vector< double > &mvals, size_t n, const double *error2, double corr=0.)
Add a new error source of the templates to LTF.
Definition: LTF.h:333
Eigen::VectorXd ahat_errorTmpl
Uncertainties from templates.
Definition: LTF.h:110
Eigen::VectorXd delta_m21
uncertainty on M from linearized second-order model (incl. interference)
Definition: LTF.h:129
Eigen::MatrixXd VExt() const
calculate covariance matrix of all uncertainties included in fit
Definition: LTF.h:139
void AddUncorrelatedErrorSquared(const std::string &name, size_t n, const double *error2, LTF::Uncertainty constr=LTF::Uncertainty::Constrained)
Set uncorrelated error.
Definition: LTF.h:284
std::vector< std::pair< std::string, Eigen::VectorXd > > fSys
correlated (syst.) uncertainty
Definition: LTF.h:503
std::map< std::string, double > corrSys
Correlation coefficient of the systematic uncertainties.
Definition: LTF.h:93
void AddTemplate(double mval, const vector< double > &dist)
Add new template for a given reference point.
Definition: LTF.h:187
Eigen::MatrixXd Y
Matrix Y (templates)
Definition: LTF.h:83
Eigen::VectorXd Dt
data distribution
Definition: LTF.h:81
void AddResponseMatrixError(const std::string &name, const std::vector< std::vector< double > > &errorA, double corr=0.)
Add a new error source of the templates to LTF Note: a repeated call with an already existent name wi...
Definition: LTF.h:374
void SetFitRange(int binmin, int binmax)
set fit range, i.e. exclude bins
Definition: LTF.h:425
void SetData(const vector< double > &data)
<
Definition: LTF.h:170
void AddResponseMatrixErrorSquared(const std::string &name, const Eigen::MatrixXd &error2A, double corr=0.)
Add a new error source of the templates to LTF.
Definition: LTF.h:389
void AddErrorRelative(const std::string &name, std::vector< double > error, double corr=0., LTF::Uncertainty constr=LTF::Uncertainty::Constrained)
Add a new error source to LTF with relative values.
Definition: LTF.h:252
double achk_chisq
chisq_min from polynomial fit to chi2's of templates
Definition: LTF.h:123
std::map< std::string, Eigen::VectorXd > fSysExt
correlated uncertainties, treated as external
Definition: LTF.h:506
void UseLogNormalUncertainties(bool LogNormal=true)
Select normal distributed or log-normal distributed uncertainties note: log-normal distributed uncert...
Definition: LTF.h:449
Eigen::VectorXd ahat_errorExt
Uncertainties not included in fit.
Definition: LTF.h:109
std::map< std::string, Eigen::VectorXd > DeltaSysExt
'external' correlated systematic uncertainty
Definition: LTF.h:116
void RescaleInputErrors(std::vector< double > values)
Rescale uncertainties All uncertainties are stored interally as absolute uncertainties....
Definition: LTF.h:487
void SetGamma(double gamma=1)
set exponential factor(s) gamma
Definition: LTF.h:400
Eigen::VectorXd CalculatePrediction(std::vector< double > v) const
Definition: LTF.h:143
Eigen::MatrixXd VFit() const
calculate covariance matrix of all uncertainties included in fit
Definition: LTF.h:138
std::map< std::string, Eigen::VectorXd > SysExt
external (correlated) systematic uncertainties
Definition: LTF.h:89
Eigen::MatrixXd M
Matrix M (reference values)
Definition: LTF.h:82
std::map< std::string, double > fcorrSys
Correlation coefficient of the systematic uncertainties (dA,dY)
Definition: LTF.h:509
void SetResponseMatrix(const Eigen::MatrixXd &A)
set a (detector) response matrix (optional)
Definition: LTF.h:363
Eigen::VectorXd achk
result from polynomial fit to chi2's of templates
Definition: LTF.h:121
std::vector< std::pair< std::string, Eigen::MatrixXd > > fVs
Covariance matrices.
Definition: LTF.h:502
bool GetLogNormal() const
return boolean if fit was performed with relative uncertainties
Definition: LTF.h:140
std::map< std::string, Eigen::MatrixXd > VsExt
external (uncor./Cov) uncertainties
Definition: LTF.h:88
Eigen::VectorXd ErrorScale
Reference values for error rescaling (default: data)
Definition: LTF.h:155
void UseNuisanceParameters(bool UseNuisance=true)
Consider correlated systematic uncertainties as 'shifts' with nuisance.
Definition: LTF.h:465
std::vector< std::pair< std::string, Eigen::MatrixXd > > SysAX
uncertainty of the response matrix when using log-normal
Definition: LTF.h:154
Eigen::VectorXd fErrorScale
Reference values for error rescaling (default: data)
Definition: LTF.h:511
double EDM21_chisq
expected distance to minimum (EDM), calculating the newton step for a non-linear model
Definition: LTF.h:128
Eigen::VectorXd ahat
results (a0, a1, ..., epsilon1, epsilon2,...)
Definition: LTF.h:107
std::vector< double > fGamma
exponential parameter (a+b*x^\gamma)
Definition: LTF.h:512
Small helper class to collect all results, All input parameters are set by class LTF The user can acc...
Definition: LTF.h:65
std::map< std::string, Eigen::VectorXd > DeltaSysY
systematic uncertainty from the templates
Definition: LTF.h:117
std::map< std::string, Eigen::MatrixXd > SysA
uncertainty of the response matrix
Definition: LTF.h:92
Eigen::MatrixXd F
Projection matrix of LiTeFit.
Definition: LTF.h:104
std::vector< std::pair< std::string, Eigen::VectorXd > > Sys
(correlated) systematic uncertainties
Definition: LTF.h:87
Eigen::VectorXd ahat_errorFit
Uncertainties included in fit.
Definition: LTF.h:108
std::map< std::string, Eigen::MatrixXd > VsourceExt
Covariance matrices from 'external' uncorr. and cov. uncertainties.
Definition: LTF.h:115
std::map< std::string, Eigen::VectorXd > DeltaSys
Correlated systematic uncertainties.
Definition: LTF.h:114
std::map< std::string, Eigen::MatrixXd > SysY
uncertainty of the templates
Definition: LTF.h:91
Eigen::VectorXd ahat_errorRespMat
Uncertainties from response matrix.
Definition: LTF.h:111
std::vector< std::pair< std::string, Eigen::MatrixXd > > Vs
(uncor./Cov) uncertainties
Definition: LTF.h:86
bool GetLogNormalUncertainties() const
get boolean for relative uncertainties (LogNormal)
Definition: LTF.h:453
void AddError(const std::string &name, const std::vector< double > &error, double corr=0., LTF::Uncertainty constr=LTF::Uncertainty::Constrained)
Add a new error source to LTF.
Definition: LTF.h:216
std::map< std::string, double > chisq_part
'partial' chi^2 for each error source
Definition: LTF.h:106
std::map< std::string, std::map< vector< double >, Eigen::VectorXd > > fSysY
uncertainty of the templates (uncorrelated)
Definition: LTF.h:507
Eigen::VectorXd achk_errorFit
result from polynomial fit to chi2's of templates
Definition: LTF.h:122
Eigen::VectorXd EDM21
expected distance to minimum (EDM), calculating the newton step for a non-linear model
Definition: LTF.h:127
Eigen::VectorXd ahat21
result from linearized second-order model approximation (incl. interference)
Definition: LTF.h:126
void SetGamma(const vector< double > &gamma)
set exponential factor(s) gamma
Definition: LTF.h:415
Eigen::VectorXd fDt
data distribution
Definition: LTF.h:499
void AddErrorRelative(std::string name, size_t n, const double *error, double corr=0., LTF::Uncertainty constr=LTF::Uncertainty::Constrained)
Add a new error source to LTF with relative values.
Definition: LTF.h:245
Eigen::VectorXd chisq_y
chi^2 for each template
Definition: LTF.h:105
std::map< std::string, Eigen::MatrixXd > Vsource
Covariance matrices from uncorr. and cov. uncertainties.
Definition: LTF.h:113
Eigen::VectorXd TheoFit
best-fit theory predictions
Definition: LTF.h:112
static std::map< std::string, Eigen::MatrixXd > GetV_DeltaSys(const T &DeltaSys)
calculate covariance matrices from (systematic) shifts
Definition: LTF.h:547
vector< double > Gamma
Use non-linear Gamma-factor.
Definition: LTF.h:94
std::map< std::string, LTF::Uncertainty > fSysIsConstr
uncertainty specification for fSys
Definition: LTF.h:504
void AddErrorPercent(const std::string &name, std::vector< double > error, double corr=0., LTF::Uncertainty constr=LTF::Uncertainty::Constrained)
Add a new error source to LTF with relative values.
Definition: LTF.h:268
void AddTemplateErrorSquared(const std::string &name, double mval, size_t n, const double *error2, double corr=0.)
Add a new error source of the templates to LTF.
Definition: LTF.h:337
void AddTemplate(const vector< double > mvals, size_t n, const double *dist)
Add new template for a given reference point.
Definition: LTF.h:197
std::map< std::string, Eigen::VectorXd > DeltaSysA
systematic uncertainty from the response matrix
Definition: LTF.h:118
void RescaleInputErrors(std::vector< double > values)
Definition: LTF.h:75
void AddErrorPercent(std::string name, size_t n, const double *error, double corr=0., LTF::Uncertainty constr=LTF::Uncertainty::Constrained)
Add a new error source to LTF.
Definition: LTF.h:263
static Eigen::MatrixXd Std_to_Mat(const std::vector< std::vector< double > > &A)
Calculate an Eigen-matrix from std::vector<std::vector<>>. T=double.
Definition: LTF.cxx:2313
void AddResponseMatrixError(const std::string &name, const Eigen::MatrixXd &errorA, double corr=0.)
Add a new error source of the templates to LTF.
Definition: LTF.h:378
Eigen::VectorXd CalculatePrediction(double v) const
Definition: LTF.h:141