MINT2
Public Member Functions | Protected Attributes | List of all members
MINT::Neg2LLMultiConstraint Class Reference

#include <Neg2LLMultiConstraint.h>

Inheritance diagram for MINT::Neg2LLMultiConstraint:
MINT::Minimisable MINT::IMinimisable

Public Member Functions

 Neg2LLMultiConstraint (MinuitParameterSet *mps=0, string label="")
 
virtual void beginFit ()
 
virtual void parametersChanged ()
 
virtual void endFit ()
 
virtual double getVal ()
 
virtual double getNewVal ()
 
int getNumberParams ()
 
void smearInputValues ()
 
double smearInputValuesChol (int index=0, int seed=0, int offset=1)
 
RooDataSet * generateToys (int N=100)
 
TMatrixDSym * getCovMatrix ()
 
vector< string > split (string s, string delimiter)
 
vector< double > splitValues (string s, string delimiter)
 
virtual ~Neg2LLMultiConstraint ()
 
- Public Member Functions inherited from MINT::Minimisable
 Minimisable (MinuitParameterSet *mps=0)
 
 Minimisable (const Minimisable &other)
 
virtual ~Minimisable ()
 
void setPset (MinuitParameterSet *mps)
 
MinuitParameterSetgetParSet ()
 
- Public Member Functions inherited from MINT::IMinimisable
virtual void Gradient (std::vector< double > &grad)
 
virtual bool useAnalyticGradient ()
 
virtual void setUseAnalyticGradient (bool useAnalyticGradient)
 
virtual ~IMinimisable ()
 

Protected Attributes

RooArgList * _x
 
RooArgList * _mu
 
RooMultiVarGaussian * _gauss_cov
 
TMatrixTSym< double > * _cov
 
MinuitParameterSet_mps
 
TMatrixD * _UT
 

Detailed Description

Definition at line 23 of file Neg2LLMultiConstraint.h.

Constructor & Destructor Documentation

◆ Neg2LLMultiConstraint()

MINT::Neg2LLMultiConstraint::Neg2LLMultiConstraint ( MinuitParameterSet mps = 0,
string  label = "" 
)
inline

Parameters to constrain

Cov. matrix

Sanity checks

Definition at line 32 of file Neg2LLMultiConstraint.h.

33  : Minimisable(mps), _mps(mps) {
34 
36  NamedParameter<string> constrain(("ConstrainMulti"+label).c_str(), (string)"" , (char*) 0);
37  string constrain_s = constrain;
38  vector<string> constrain_v = split(constrain_s, " ");
39 
41  NamedParameter<string> corr(("ConstrainMulti"+label+"_corr").c_str(),(string)"", (char*) 0);
42  string corr_s = corr;
43  vector<double> corr_v = splitValues(corr_s, " ");
44 
45  TMatrixDSym cov(constrain_v.size());
46  int index = 0;
47  for(int i=0; i < cov.GetNcols(); i++){
48  for(int j=i; j < cov.GetNcols(); j++){
49  cov(i,j) = corr_v[index];
50  cov(j,i) = corr_v[index];
51  index++;
52  }
53  }
54 
55  //double* corr_a = &corr_v[0];
56  //TMatrixDSym cov(constrain_v.size(),corr_a);
57  cov.Print();
58 
60  if(constrain_v.size() * (constrain_v.size()+1)/2 != corr_v.size()) {
61  cout << "ERROR in Neg2LLMultiConstraint::Inconsistent number of parameters and cov. matrix" << endl;
62  throw "ERROR";
63  }
64 
65  _x = new RooArgList();
66  _mu = new RooArgList();
67  vector<double> sigma_v;
68 
69  for(int j= 0; j < constrain_v.size();j++){
70 
71  cout << "Adding gauss constraint for parameter: " << constrain_v[j] << endl;
72 
73  double mean = -99999;
74  double sigma = -99999;
75 
76  for(unsigned int i=0; i < _mps->size(); i++){
77  if(0 == _mps->getParPtr(i)) continue;
78  if(constrain_v[j] == _mps->getParPtr(i)->name()){
79  mean = _mps->getParPtr(i)->mean();
80  sigma = ((FitParameter*)_mps->getParPtr(i))->stepInit();
81  }
82  }
83  if(mean == -99999) {
84  cout << "ERROR in Neg2LLMultiConstraint::Parameter not found" << endl;
85  throw "ERROR";
86  }
87  else {
88  RooRealVar* x = new RooRealVar((constrain_v[j]).c_str(), (constrain_v[j]).c_str(),mean);
89  _x->add(*x);
90  _mu->add(RooRealConstant::value(mean));
91  sigma_v.push_back(sigma);
92  }
93  }
94 
95  for(int i=0; i < cov.GetNcols(); i++){
96  for(int j=0; j < cov.GetNcols(); j++){
97  cov(i,j) = cov(i,j) * sigma_v[i] * sigma_v[j];
98  }
99  }
100  _cov = new TMatrixDSym(cov);
101 
102  _x->Print();
103  _mu->Print();
104  _cov->Print();
105  _gauss_cov = new RooMultiVarGaussian("gauss_cov","gauss_cov",*_x, *_mu, *_cov);
106 
107  TDecompChol tdc(*_cov);
108  tdc.Decompose();
109  TMatrixD U = tdc.GetU();
110  _UT = new TMatrixD(TMatrixD::kTransposed,U);
111  _UT->Print();
112 
113  };
vector< double > splitValues(string s, string delimiter)
IMinuitParameter * getParPtr(unsigned int i)
unsigned int size() const
virtual const std::string & name() const =0
virtual double mean() const =0
Minimisable(MinuitParameterSet *mps=0)
Definition: Minimisable.cpp:6
RooMultiVarGaussian * _gauss_cov
TMatrixTSym< double > * _cov
vector< string > split(string s, string delimiter)

◆ ~Neg2LLMultiConstraint()

virtual MINT::Neg2LLMultiConstraint::~Neg2LLMultiConstraint ( )
inlinevirtual

Definition at line 207 of file Neg2LLMultiConstraint.h.

207 {}

Member Function Documentation

◆ beginFit()

virtual void MINT::Neg2LLMultiConstraint::beginFit ( )
inlinevirtual

Reimplemented from MINT::Minimisable.

Definition at line 115 of file Neg2LLMultiConstraint.h.

115 {};

◆ endFit()

virtual void MINT::Neg2LLMultiConstraint::endFit ( )
inlinevirtual

Reimplemented from MINT::Minimisable.

Definition at line 121 of file Neg2LLMultiConstraint.h.

121 {};

◆ generateToys()

RooDataSet* MINT::Neg2LLMultiConstraint::generateToys ( int  N = 100)
inline

Definition at line 172 of file Neg2LLMultiConstraint.h.

172  {
173  cout << "Smearing input values " << endl;
174  RooDataSet* data_cov = _gauss_cov->generate(*_x, N);
175  return data_cov;
176  }
RooMultiVarGaussian * _gauss_cov

◆ getCovMatrix()

TMatrixDSym* MINT::Neg2LLMultiConstraint::getCovMatrix ( )
inline

Definition at line 178 of file Neg2LLMultiConstraint.h.

178  {
179  return _cov;
180  }
TMatrixTSym< double > * _cov

◆ getNewVal()

virtual double MINT::Neg2LLMultiConstraint::getNewVal ( )
inlinevirtual

Reimplemented from MINT::Minimisable.

Definition at line 127 of file Neg2LLMultiConstraint.h.

127  {
129  return getVal();
130  }

◆ getNumberParams()

int MINT::Neg2LLMultiConstraint::getNumberParams ( )
inline

Definition at line 132 of file Neg2LLMultiConstraint.h.

132  {
133  return _cov->GetNcols();
134  }
TMatrixTSym< double > * _cov

◆ getVal()

virtual double MINT::Neg2LLMultiConstraint::getVal ( )
inlinevirtual

Implements MINT::Minimisable.

Definition at line 123 of file Neg2LLMultiConstraint.h.

123  {
124  return -2. * log(_gauss_cov->getVal(*_x));
125  }
RooMultiVarGaussian * _gauss_cov

◆ parametersChanged()

virtual void MINT::Neg2LLMultiConstraint::parametersChanged ( )
inlinevirtual

Reimplemented from MINT::Minimisable.

Definition at line 116 of file Neg2LLMultiConstraint.h.

116  {
117  for(int i=0; i < _x->getSize(); i++){
118  ((RooRealVar*)_x->at(i))->setVal(_mps->getParPtr(_x->at(i)->GetName())->mean());
119  }
120  };
IMinuitParameter * getParPtr(unsigned int i)

◆ smearInputValues()

void MINT::Neg2LLMultiConstraint::smearInputValues ( )
inline

Definition at line 136 of file Neg2LLMultiConstraint.h.

136  {
137 
138  cout << "Smearing input values " << endl;
139 
140  RooDataSet* data_cov = _gauss_cov->generate(*_x, 1);
141  RooArgList* xvec_cov= (RooArgList*)data_cov->get(0);
142 
143  xvec_cov->Print();
144 
145  for(int i=0; i < xvec_cov->getSize(); i++){
146  _mps->getParPtr(xvec_cov->at(i)->GetName())->setCurrentFitVal(((RooRealVar*)xvec_cov->at(i))->getVal());
147  ((FitParameter*)_mps->getParPtr(xvec_cov->at(i)->GetName()))->setInit(((RooRealVar*)xvec_cov->at(i))->getVal());
148  cout << "Set parameter " << xvec_cov->at(i)->GetName() << " to " << _mps->getParPtr(xvec_cov->at(i)->GetName())->mean() << endl;
149  }
150  }
IMinuitParameter * getParPtr(unsigned int i)
RooMultiVarGaussian * _gauss_cov

◆ smearInputValuesChol()

double MINT::Neg2LLMultiConstraint::smearInputValuesChol ( int  index = 0,
int  seed = 0,
int  offset = 1 
)
inline

Definition at line 152 of file Neg2LLMultiConstraint.h.

152  {
153 
154  // Use the same random seed for each chol index
155  TRandom3 r(seed + offset);
156  cout << "Smearing input values for parameter " << index << " using random seed = " << seed + offset << endl;
157 
158  double val = 0;
159  for(int i = 0 ; i < _UT->GetNcols(); i++){
160  if(i != index)continue;
161  val = _mps->getParPtr(_x->at(i)->GetName())->mean();
162  for(int j = 0 ; j < _UT->GetNcols(); j++){
163  val += r.Gaus(0.,1.) * (*_UT)(i,j);
164  }
165  _mps->getParPtr(_x->at(i)->GetName())->setCurrentFitVal(val);
166  ((FitParameter*)_mps->getParPtr(_x->at(i)->GetName()))->setInit(val);
167  cout << "Set parameter " << _x->at(i)->GetName() << " to " << val << endl;
168  }
169  return val;
170  }
IMinuitParameter * getParPtr(unsigned int i)

◆ split()

vector<string> MINT::Neg2LLMultiConstraint::split ( string  s,
string  delimiter 
)
inline

Definition at line 182 of file Neg2LLMultiConstraint.h.

182  {
183  size_t pos = 0;
184  string token;
185  vector<string> list;
186  while ((pos = s.find(delimiter)) != string::npos) {
187  token = s.substr(0, pos);
188  list.push_back(token);
189  s.erase(0, pos + delimiter.length());
190  }
191  return list;
192  }
static const double s

◆ splitValues()

vector<double> MINT::Neg2LLMultiConstraint::splitValues ( string  s,
string  delimiter 
)
inline

Definition at line 194 of file Neg2LLMultiConstraint.h.

194  {
195  size_t pos = 0;
196  string token;
197  vector<double> list;
198  while ((pos = s.find(delimiter)) != string::npos) {
199  token = s.substr(0, pos);
200  list.push_back(atof(token.c_str()));
201  s.erase(0, pos + delimiter.length());
202  }
203  return list;
204  }
static const double s

Member Data Documentation

◆ _cov

TMatrixTSym<double>* MINT::Neg2LLMultiConstraint::_cov
protected

Definition at line 27 of file Neg2LLMultiConstraint.h.

◆ _gauss_cov

RooMultiVarGaussian* MINT::Neg2LLMultiConstraint::_gauss_cov
protected

Definition at line 26 of file Neg2LLMultiConstraint.h.

◆ _mps

MinuitParameterSet* MINT::Neg2LLMultiConstraint::_mps
protected

Definition at line 28 of file Neg2LLMultiConstraint.h.

◆ _mu

RooArgList * MINT::Neg2LLMultiConstraint::_mu
protected

Definition at line 25 of file Neg2LLMultiConstraint.h.

◆ _UT

TMatrixD* MINT::Neg2LLMultiConstraint::_UT
protected

Definition at line 29 of file Neg2LLMultiConstraint.h.

◆ _x

RooArgList* MINT::Neg2LLMultiConstraint::_x
protected

Definition at line 25 of file Neg2LLMultiConstraint.h.


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