1 #ifndef NEG_TWO_LL_MultiConstraint_HH 2 #define NEG_TWO_LL_MultiConstraint_HH 9 #include "RooMultiVarGaussian.h" 10 #include "RooRealVar.h" 11 #include "RooRealConstant.h" 12 #include "RooDataSet.h" 13 #include "TDecompChol.h" 19 using namespace RooFit ;
37 string constrain_s = constrain;
38 vector<string> constrain_v = split(constrain_s,
" ");
43 vector<double> corr_v = splitValues(corr_s,
" ");
45 TMatrixDSym cov(constrain_v.size());
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];
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;
65 _x =
new RooArgList();
66 _mu =
new RooArgList();
67 vector<double> sigma_v;
69 for(
int j= 0; j < constrain_v.size();j++){
71 cout <<
"Adding gauss constraint for parameter: " << constrain_v[j] << endl;
74 double sigma = -99999;
76 for(
unsigned int i=0; i < _mps->
size(); i++){
84 cout <<
"ERROR in Neg2LLMultiConstraint::Parameter not found" << endl;
88 RooRealVar* x =
new RooRealVar((constrain_v[j]).c_str(), (constrain_v[j]).c_str(),mean);
90 _mu->add(RooRealConstant::value(mean));
91 sigma_v.push_back(sigma);
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];
100 _cov =
new TMatrixDSym(cov);
105 _gauss_cov =
new RooMultiVarGaussian(
"gauss_cov",
"gauss_cov",*_x, *_mu, *_cov);
107 TDecompChol tdc(*_cov);
109 TMatrixD U = tdc.GetU();
110 _UT =
new TMatrixD(TMatrixD::kTransposed,U);
117 for(
int i=0; i < _x->getSize(); i++){
118 ((RooRealVar*)_x->at(i))->setVal(_mps->
getParPtr(_x->at(i)->GetName())->mean());
124 return -2. * log(_gauss_cov->getVal(*_x));
133 return _cov->GetNcols();
138 cout <<
"Smearing input values " << endl;
140 RooDataSet* data_cov = _gauss_cov->generate(*_x, 1);
141 RooArgList* xvec_cov= (RooArgList*)data_cov->get(0);
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;
155 TRandom3 r(seed + offset);
156 cout <<
"Smearing input values for parameter " << index <<
" using random seed = " << seed + offset << endl;
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);
165 _mps->
getParPtr(_x->at(i)->GetName())->setCurrentFitVal(val);
167 cout <<
"Set parameter " << _x->at(i)->GetName() <<
" to " << val << endl;
173 cout <<
"Smearing input values " << endl;
174 RooDataSet* data_cov = _gauss_cov->generate(*_x, N);
182 vector<string>
split(
string s,
string delimiter){
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());
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());
double smearInputValuesChol(int index=0, int seed=0, int offset=1)
vector< double > splitValues(string s, string delimiter)
IMinuitParameter * getParPtr(unsigned int i)
unsigned int size() const
virtual ~Neg2LLMultiConstraint()
virtual const std::string & name() const =0
Neg2LLMultiConstraint(MinuitParameterSet *mps=0, string label="")
virtual double mean() const =0
virtual double getNewVal()
RooMultiVarGaussian * _gauss_cov
virtual void parametersChanged()
TMatrixDSym * getCovMatrix()
TMatrixTSym< double > * _cov
MinuitParameterSet * _mps
RooDataSet * generateToys(int N=100)
vector< string > split(string s, string delimiter)