a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
HiggsObservable.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 HEPfit Collaboration
3 *
4 *
5 * For the licensing terms see doc/COPYING.
6 */
7
8#include "HiggsObservable.h"
9#include "ThObsFactory.h"
10#include <TNamed.h>
11#include <TFile.h>
12#include <TROOT.h>
13#include <TMath.h>
14#include <iostream>
15#include <fstream>
16#include <boost/tokenizer.hpp>
17#include <string>
18#include <sstream>
19
21Observable(Obs)
22{
23 isnew = true;
24 isCorrelated = false;
26};
27
29{
30 channels = orig.channels;
31 thObsV = orig.thObsV;
34 isnew = orig.isnew;
37 InvCov = orig.InvCov;
38 rank = orig.rank;
39}
40
41//HiggsObservable::~HiggsObservable() {}
42
43void HiggsObservable::setParametricLikelihood(std::string filename, std::vector<ThObservable*> thObsV)
44{
45 this->filename = filename;
46 this->thObsV = thObsV;
47 std::ifstream ifile(filename.c_str());
48 if (!ifile.is_open())
49 throw std::runtime_error("\nERROR: " + filename + " does not exist. Make sure to specify a valid Higgs parameters configuration file.\n");
50 std::string line;
51 bool IsEOF;
52 bool readCorrelations = false;
53 unsigned int i = 0;
54 unsigned int nrows = 0;
55 do {
56 IsEOF = getline(ifile, line).eof();
57 if (line.compare(0, 11, "MEASUREMENT") == 0) nrows++;
58 } while (!IsEOF);
59 if (nrows == 0) {
60 std::stringstream ss;
61 ss << "\nERROR: " << filename << " should contain at least 1 measurement.\n";
62 throw std::runtime_error(ss.str());
63 }
64 int implicit_tth = (isnew ? 0 : -1);
65 channels.ResizeTo(nrows, thObsV.size() + 3 + implicit_tth);
66 ifile.clear();
67 ifile.seekg(0, ifile.beg);
68 int lineNo = 0;
69 do {
70 IsEOF = getline(ifile, line).eof();
71 lineNo++;
72 if (*line.rbegin() == '\r') line.erase(line.length() - 1); // for CR+LF
73 if (line.compare(0, 11, "MEASUREMENT") != 0 && !readCorrelations) {
74 continue;
75 } else {
76 boost::char_separator<char> sep(" |\t");
77 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
78 boost::tokenizer<boost::char_separator<char> >::iterator beg = tok.begin();
79 if (isCorrelated) readCorrelations = true;
80 // Read the necessary information from the config file. Each row contains:
81 // ggH fraction
82 // VBF fraction
83 // VH fraction (ttH is computed as 1-ggH-VBF-VH)
84 // average value of mu
85 // left-side error
86 // right-side error
87 beg++; // skip label
88 for (int j = 0; j < channels.GetNcols(); j++)
89 channels(i, j) = atof((*(++beg)).c_str());
90 if (isCorrelated && (std::fabs(channels(i, thObsV.size() + 1)) != std::fabs(channels(i, thObsV.size() + 2)))) {
91 if (rank == 0) throw std::runtime_error("ERROR: Gaussian errors must be symmetric for CorrelatedHiggsObservables in " + filename + " at line number:" + boost::lexical_cast<std::string>(lineNo) + ".\n");
92 else sleep(2);
93 }
94 i++;
95 if (readCorrelations && (i == nrows)) {
96 gslpp::matrix<double> myCorr(gslpp::matrix<double>::Id(nrows));
97 int ni = 0;
98 for (unsigned int irow = 0; irow < nrows; irow++) {
99 IsEOF = getline(ifile, line).eof();
100 if (line.empty() || line.at(0) == '#') {
101 if (rank == 0) throw std::runtime_error("ERROR: no comments or empty lines in CorrelatedHiggsObservables please! In file " + filename + " at line number:" + boost::lexical_cast<std::string>(lineNo) + ".\n");
102 else sleep(2);
103 }
104 lineNo++;
105 boost::tokenizer<boost::char_separator<char> > mytok(line, sep);
106 beg = mytok.begin();
107 int nj = 0;
108 for (unsigned int jcol = 0; jcol < nrows; jcol++) {
109 if ((*beg).compare(0, 1, "0") == 0
110 || (*beg).compare(0, 1, "1") == 0
111 || (*beg).compare(0, 1, "-") == 0 || (covarianceFromConfig == true)) {
112 if (std::distance(mytok.begin(), mytok.end()) < nrows) {
113 if (rank == 0) throw std::runtime_error(("ERROR: Correlation matrix is of wrong size in CorrelatedHiggsObservables: " + name + +" at line number:" + boost::lexical_cast<std::string>(lineNo) + ".\n").c_str());
114 else sleep(2);
115 }
116 myCorr(ni, nj) = atof((*beg).c_str());
117 nj++;
118 beg++;
119 } else {
120 if (rank == 0) throw std::runtime_error("ERROR: invalid correlation matrix for " + name + ". Check element (" + boost::lexical_cast<std::string>(ni + 1) + "," + boost::lexical_cast<std::string>(nj + 1) + ") in line number " + boost::lexical_cast<std::string>(lineNo) + " in file " + filename + ".\n");
121 else sleep(2);
122 }
123 }
124 ni++;
125 }
126 if (myCorr.size_i() != nrows || myCorr.size_j() != nrows)
127 throw std::runtime_error("The size of the correlated observables in " + name + " does not match the size of the correlation matrix!");
128 InvCov = new gslpp::matrix<double>(nrows, nrows, 0.);
130 for (unsigned int i = 0; i < nrows; i++)
131 for (unsigned int j = 0; j < nrows; j++)
132 (*InvCov)(i, j) = myCorr(i, j);
133 } else {
134 for (unsigned int i = 0; i < nrows; i++)
135 for (unsigned int j = 0; j < nrows; j++)
136 (*InvCov)(i, j) = channels(i, thObsV.size() + 2) * myCorr(i, j) * channels(i, thObsV.size() + 2); // left = right imposed above
137 *InvCov = InvCov->inverse();
138 }
139 readCorrelations = false;
140 }
141 }
142 } while (!IsEOF);
143 if (i != nrows) {
144 std::stringstream ss;
145 ss << "\nERROR: " << filename << " should contain " << nrows << " measurements, but I have read " << i << " ones instead.\n";
146 throw std::runtime_error(ss.str());
147 }
148
149 thobsvsize = thObsV.size();
150 channelsize = channels.GetNrows();
151 theoryValues.resize(thobsvsize + 1 + channelsize);
152}
153
155{
156 double logprob = 0;
157
158 if (isnew) {
159 for (int i = 0; i < channels.GetNrows(); i++) {
160 double mu = 0;
161 for (unsigned int j = 0; j < thobsvsize; j++) {
162 theoryValues.at(j) = thObsV.at(j)->computeThValue();
163 mu += channels(i, j) * theoryValues.at(j);
164 }
166 if (thObsV.at(0)->getModel().isModelLinearized())
167 theoryValues.at(thobsvsize + i + 1) = -1. + mu + theoryValues.at(thobsvsize);
168 else
169 theoryValues.at(thobsvsize + i + 1) = mu * theoryValues.at(thobsvsize);
171 }
172 if (isCorrelated) {
173 gslpp::vector<double> theObsVal(channels.GetNrows(), 0.);
174 for (int i = 0; i < channels.GetNrows(); i++) {
175 theObsVal(i) = theoryValues.at(thobsvsize + i + 1);
176 }
177 logprob = (-0.5 * theObsVal * ((*InvCov) * theObsVal));
178 }
179 } else {
180 for (int i = 0; i < channels.GetNrows(); i++) {
181 double mu = 0, sum = 0.;
182 for (unsigned int j = 0; j < thobsvsize - 1; j++) {
183 theoryValues.at(j) = thObsV.at(j)->computeThValue();
184 mu += channels(i, j) * theoryValues.at(j);
185 sum += channels(i, j);
186 }
187 mu += (1. - sum) * thObsV.at(thobsvsize - 1)->computeThValue();
189 theoryValues.at(thobsvsize + i + 1) = mu * theoryValues.at(thobsvsize);
190 logprob += LogSplitGaussian(theoryValues.at(thobsvsize + i + 1), channels(i, 3), channels(i, 4), channels(i, 5));
191 }
192 }
193
194 return (logprob);
195}
196
197boost::tokenizer<boost::char_separator<char> >::iterator & HiggsObservable::ParseHiggsObservable(
198 boost::tokenizer<boost::char_separator<char> >::iterator & beg,
199 ThObsFactory& myObsFactory,
200 StandardModel * myModel,
201 int rank)
202{
203 this->rank = rank;
204 std::string type = "HiggsObservable";
205 setObsType(type);
206 std::vector<ThObservable*> hthobs;
207 ++beg;
208 distr = *beg;
209 if (distr.compare("parametric") == 0) {
210 setIsnew(false);
211 ++beg;
212 distr = *beg;
213 if (distr.compare("LHC7") == 0) {
214 hthobs.push_back(myObsFactory.CreateThMethod("ggH7", *myModel));
215 hthobs.push_back(myObsFactory.CreateThMethod("VBF7", *myModel));
216 hthobs.push_back(myObsFactory.CreateThMethod("VH7", *myModel));
217 hthobs.push_back(myObsFactory.CreateThMethod("ttH7", *myModel));
218 } else if (distr.compare("LHC8") == 0) {
219 hthobs.push_back(myObsFactory.CreateThMethod("ggH8", *myModel));
220 hthobs.push_back(myObsFactory.CreateThMethod("VBF8", *myModel));
221 hthobs.push_back(myObsFactory.CreateThMethod("VH8", *myModel));
222 hthobs.push_back(myObsFactory.CreateThMethod("ttH8", *myModel));
223 } else if (distr.compare("TeV196") == 0) {
224 hthobs.push_back(myObsFactory.CreateThMethod("ggH196", *myModel));
225 hthobs.push_back(myObsFactory.CreateThMethod("VBF196", *myModel));
226 hthobs.push_back(myObsFactory.CreateThMethod("VH196", *myModel));
227 hthobs.push_back(myObsFactory.CreateThMethod("ttH196", *myModel));
228 } else if (rank == 0)
229 throw std::runtime_error("ERROR: wrong keyword " + distr + " in " + getName());
230 setParametricLikelihood(*(++beg), hthobs);
231 } else if (distr.compare("new_parametric") == 0) {
232 std::string filename_h = *(++beg);
233 std::ifstream ifile(filename_h.c_str());
234 if (!ifile.is_open()) {
235 if (rank == 0) throw std::runtime_error("\nERROR: " + filename_h + " does not exist. Make sure to specify a valid Higgs parameters configuration file.\n");
236 else sleep(2);
237 }
238 std::string line_h;
239 bool IsEOF_h;
240 do {
241 IsEOF_h = getline(ifile, line_h).eof();
242 if (line_h.compare(0, 10, "CATEGORIES") == 0) {
243 boost::char_separator<char> sep(" \t");
244 boost::tokenizer<boost::char_separator<char> > mytok(line_h, sep);
245 boost::tokenizer<boost::char_separator<char> >::iterator beg2 = mytok.begin();
246 beg2++;
247 while (beg2 != mytok.end()) {
248 std::string cat = *beg2;
249 hthobs.push_back(myObsFactory.CreateThMethod(cat, *myModel));
250 beg2++;
251 }
252 }
253 } while (!IsEOF_h);
254 if (hthobs.size() > 0)
255 setParametricLikelihood(filename_h, hthobs);
256 else {
257 if (rank == 0) throw std::runtime_error("\nERROR: " + getName() + " does not provide at least one category\n");
258 else sleep(2);
259 }
260 } else {
261 if (rank == 0) throw std::runtime_error("ERROR: wrong distribution flag " + distr + " in " + getName());
262 else sleep(2);
263 }
264
265 return beg;
266}
267
A class for Higgs experimental analyses.
virtual void setParametricLikelihood(std::string filename, std::vector< ThObservable * > thObsV)
Set the parametric likelihood describing one Higgs decay channel from a config file.
TMatrixD channels
A matrix holding the information of all the channels.
gslpp::matrix< double > * InvCov
The inverse covariance matrix.
double channelsize
The number of channels in the Higgs Observable.
int rank
The rank of the process initializing this observable.
bool isnew
A boolean which is true if the parametrization is new.
bool isCorrelated
A flag for correlated Higgs Observable.
HiggsObservable(const Observable &Obs)
std::vector< double > theoryValues
A vector to contain the theoryvalues.
void setIsnew(bool isnew)
A method to set the observable to the new parametric form.
std::vector< ThObservable * > thObsV
A vector of ThObservables.
virtual double computeWeight()
A method to compute the weight associated with the observable.
double thobsvsize
The size of the theory observables vector.
boost::tokenizer< boost::char_separator< char > >::iterator & ParseHiggsObservable(boost::tokenizer< boost::char_separator< char > >::iterator &beg, ThObsFactory &myObsFactory, StandardModel *myModel, int rank)
the parser for HiggsObservables
bool covarianceFromConfig
A flag for reading inverse covariance from config file.
A class for observables.
Definition: Observable.h:28
std::string distr
The name of the distribution of the the observable.
Definition: Observable.h:482
double LogSplitGaussian(double x, double ave, double errl, double errr)
Definition: Observable.cpp:141
std::string getName() const
A get method to access the name of the observable.
Definition: Observable.h:323
std::string filename
The name of the file containing the experimental likelihood for the observable.
Definition: Observable.h:483
void setObsType(std::string &obsType_s)
A set method to set the Observable type.
Definition: Observable.h:395
ThObservable * tho
A pointer of to the object of the ThObservables class.
Definition: Observable.h:478
std::string name
A name for the observable.
Definition: Observable.h:479
A model class for the Standard Model.
A class for.
Definition: ThObsFactory.h:26
ThObservable * CreateThMethod(const std::string &name, StandardModel &model) const
This method checks for the existence of an observable of a specific name in the map thobs and returns...
virtual double computeThValue()=0
A member to be overloaded by the respective theory observable. class that calculates the value of the...