HiggsObservable.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 HEPfit Collaboration
3  * All rights reserved.
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 
20 //HiggsObservable::~HiggsObservable() {}
21 
22 void HiggsObservable::setParametricLikelihood(std::string filename, std::vector<ThObservable*> thObsV)
23 {
24  this->filename = filename;
25  this->thObsV = thObsV;
26  std::ifstream ifile(filename.c_str());
27  if (!ifile.is_open())
28  throw std::runtime_error("\nERROR: " + filename + " does not exist. Make sure to specify a valid Higgs parameters configuration file.\n");
29  std::string line;
30  bool IsEOF;
31  int i = 0, nrows = 0;
32  do {
33  IsEOF = getline(ifile, line).eof();
34  if (line.compare(0, 11, "MEASUREMENT") == 0) nrows++;
35  } while (!IsEOF);
36  if (nrows == 0) {
37  std::stringstream ss;
38  ss << "\nERROR: " << filename << " should contain at least 1 measurement.\n";
39  throw std::runtime_error(ss.str());
40  }
41  int implicit_tth = (isnew ? 0 : -1);
42  channels.ResizeTo(nrows, thObsV.size() + 3 + implicit_tth);
43  ifile.clear();
44  ifile.seekg(0, ifile.beg);
45  do {
46  IsEOF = getline(ifile, line).eof();
47  if (*line.rbegin() == '\r') line.erase(line.length() - 1); // for CR+LF
48  if (line.compare(0, 11, "MEASUREMENT") != 0)
49  continue;
50  boost::char_separator<char> sep(" |");
51  boost::tokenizer<boost::char_separator<char> > tok(line, sep);
52  boost::tokenizer<boost::char_separator<char> >::iterator beg = tok.begin();
53  // Read the necessary information from the config file. Each row contains:
54  // ggH fraction
55  // VBF fraction
56  // VH fraction (ttH is computed as 1-ggH-VBF-VH)
57  // average value of mu
58  // left-side error
59  // right-side error
60  beg++; // skip label
61  for (int j = 0; j < channels.GetNcols(); j++)
62  channels(i, j) = atof((*(++beg)).c_str());
63  i++;
64 
65  } while (!IsEOF);
66  if (i != nrows) {
67  std::stringstream ss;
68  ss << "\nERROR: " << filename << " should contain " << nrows << " measurements, but I have read " << i << " ones instead.\n";
69  throw std::runtime_error(ss.str());
70  }
71 
72  thobsvsize = thObsV.size();
73  channelsize = channels.GetNrows();
74  theoryValues.resize(thobsvsize + 1 + channelsize);
75 }
76 
78 {
79  double logprob = 0;
80 
81  if (isnew) {
82  for (int i = 0; i < channels.GetNrows(); i++) {
83  double mu = 0;
84  for (unsigned int j = 0; j < thobsvsize; j++) {
85  theoryValues.at(j) = thObsV.at(j)->computeThValue();
86  mu += channels(i, j) * theoryValues.at(j);
87  }
88  theoryValues.at(thobsvsize) = tho->computeThValue();
89  theoryValues.at(thobsvsize + i + 1) = mu * theoryValues.at(thobsvsize);
90  logprob += LogSplitGaussian(theoryValues.at(thobsvsize + i), channels(i, thobsvsize), channels(i, thobsvsize + 1), channels(i, thobsvsize + 2));
91  }
92 
93  } else {
94  for (int i = 0; i < channels.GetNrows(); i++) {
95  double mu = 0, sum = 0.;
96  for (unsigned int j = 0; j < thobsvsize - 1; j++) {
97  theoryValues.at(j) = thObsV.at(j)->computeThValue();
98  mu += channels(i, j) * theoryValues.at(j);
99  sum += channels(i, j);
100  }
101  mu += (1. - sum) * thObsV.at(thobsvsize - 1)->computeThValue();
102  theoryValues.at(thobsvsize) = tho->computeThValue();
103  theoryValues.at(thobsvsize + i + 1) = mu * theoryValues.at(thobsvsize);
104  logprob += LogSplitGaussian(theoryValues.at(thobsvsize + i), channels(i, 3), channels(i, 4), channels(i, 5));
105  }
106  }
107 
108  return (logprob);
109 }
110 
111 
112 boost::tokenizer<boost::char_separator<char> >::iterator & HiggsObservable::ParseHiggsObservable(boost::tokenizer<boost::char_separator<char> >::iterator & beg,
113  ThObsFactory& myObsFactory,
115  int rank)
116 {
117  std::string type = "HiggsObservable";
118  setObsType(type);
119  std::vector<ThObservable*> hthobs;
120  ++beg;
121  distr = *beg;
122  if (distr.compare("parametric") == 0) {
123  setIsnew(false);
124  ++beg;
125  distr = *beg;
126  if (distr.compare("LHC7") == 0) {
127  hthobs.push_back(myObsFactory.CreateThMethod("ggH7", *myModel));
128  hthobs.push_back(myObsFactory.CreateThMethod("VBF7", *myModel));
129  hthobs.push_back(myObsFactory.CreateThMethod("VH7", *myModel));
130  hthobs.push_back(myObsFactory.CreateThMethod("ttH7", *myModel));
131  } else if (distr.compare("LHC8") == 0) {
132  hthobs.push_back(myObsFactory.CreateThMethod("ggH8", *myModel));
133  hthobs.push_back(myObsFactory.CreateThMethod("VBF8", *myModel));
134  hthobs.push_back(myObsFactory.CreateThMethod("VH8", *myModel));
135  hthobs.push_back(myObsFactory.CreateThMethod("ttH8", *myModel));
136  } else if (distr.compare("TeV196") == 0) {
137  hthobs.push_back(myObsFactory.CreateThMethod("ggH196", *myModel));
138  hthobs.push_back(myObsFactory.CreateThMethod("VBF196", *myModel));
139  hthobs.push_back(myObsFactory.CreateThMethod("VH196", *myModel));
140  hthobs.push_back(myObsFactory.CreateThMethod("ttH196", *myModel));
141  } else if (rank == 0)
142  throw std::runtime_error("ERROR: wrong keyword " + distr + " in " + getName());
143  setParametricLikelihood(*(++beg), hthobs);
144  } else if (distr.compare("new_parametric") == 0) {
145  std::string filename_h = *(++beg);
146  std::ifstream ifile(filename_h.c_str());
147  if (!ifile.is_open()) {
148  if (rank == 0) throw std::runtime_error("\nERROR: " + filename_h + " does not exist. Make sure to specify a valid Higgs parameters configuration file.\n");
149  else sleep (2);
150  }
151  std::string line_h;
152  bool IsEOF_h;
153  do {
154  IsEOF_h = getline(ifile, line_h).eof();
155  if (line_h.compare(0, 10, "CATEGORIES") == 0) {
156  boost::char_separator<char> sep(" \t");
157  boost::tokenizer<boost::char_separator<char> > mytok(line_h, sep);
158  boost::tokenizer<boost::char_separator<char> >::iterator beg2 = mytok.begin();
159  beg2++;
160  while (beg2 != mytok.end()) {
161  std::string cat = *beg2;
162  hthobs.push_back(myObsFactory.CreateThMethod(cat, *myModel));
163  beg2++;
164  }
165  }
166  } while (!IsEOF_h);
167  if (hthobs.size() > 0)
168  setParametricLikelihood(filename_h, hthobs);
169  else {
170  if (rank == 0) throw std::runtime_error("\nERROR: " + getName() + " does not provide at least one category\n");
171  else sleep(2);
172  }
173  } else {
174  if (rank == 0) throw std::runtime_error("ERROR: wrong distribution flag " + distr + " in " + getName());
175  else sleep(2);
176  }
177 
178  return beg;
179 }
180 
virtual double computeThValue()=0
A member to be overloaded by the respective theory observable. class that calculates the value of the...
TMatrixD channels
A matrix holding the information of all the channels.
A class for.
Definition: ThObsFactory.h:26
std::vector< double > theoryValues
void setIsnew(bool isnew)
A method to set the observable to the new parametric form.
A model class for the Standard Model.
ThObservable * CreateThMethod(const std::string &name, const StandardModel &model) const
This method checks for the existence of an observable of a specific name in the map thobs and returns...
std::string getName() const
A get method to access the name of the observable.
Definition: Observable.h:304
double LogSplitGaussian(double x, double ave, double errl, double errr)
Definition: Observable.cpp:126
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
std::string filename
The name of the file containing the experimental likelihood for the observable.
Definition: Observable.h:444
ThObservable * tho
A pointer of to the object of the ThObservables class.
Definition: Observable.h:439
virtual void setParametricLikelihood(std::string filename, std::vector< ThObservable * > thObsV)
Set the parametric likelihood describing one Higgs decay channel from a config file.
std::string distr
The name of the distribution of the the observable.
Definition: Observable.h:443
virtual double computeWeight()
A method to compute the weight associated with the observable.
std::vector< ThObservable * > thObsV
A vector of ThObservables.
My own Model.
Definition: myModel.h:17
void setObsType(std::string &obsType_s)
A set method to set the Observable type.
Definition: Observable.h:367
bool isnew
A boolean which is true if the parametrization is new.