CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SMHiggsBuilder.py
Go to the documentation of this file.
1 from math import *
2 from array import array
3 import os
4 import ROOT
5 
7  def __init__(self,modelBuilder,datadir=None):
8  self.modelBuilder = modelBuilder
9  if datadir == None:
10  datadir = os.environ['CMSSW_BASE']+"/src/HiggsAnalysis/CombinedLimit/data/lhc-hxswg/sm"
11  self.datadir = datadir
12  self.brpath = os.path.join(self.datadir,'br')
13  def makeXS(self,process, energy='7TeV'):
14  self.xspath = os.path.join(self.datadir, 'xs', energy)
15  if process == "ggH": self.textToSpline("SM_XS_ggH_"+energy, os.path.join(self.xspath, energy+"-ggH.txt") );
16  if process == "qqH": self.textToSpline("SM_XS_qqH_"+energy, os.path.join(self.xspath, energy+"-vbfH.txt") );
17  if process == "ttH": self.textToSpline("SM_XS_ttH_"+energy, os.path.join(self.xspath, energy+"-ttH.txt") );
18  if process == "WH": self.textToSpline("SM_XS_WH_"+energy, os.path.join(self.xspath, energy+"-WH.txt") );
19  if process == "ZH": self.textToSpline("SM_XS_ZH_"+energy, os.path.join(self.xspath, energy+"-ZH.txt") );
20  if process == "VH":
21  makeXS("WH", energy); makeXS("ZH", energy);
22  self.modelBuilder.factory_('sum::SM_XS_VH_'+energy+'(SM_XS_WH_'+energy+',SM_XS_ZH_'+energy+')')
23  def makeTotalWidth(self):
24  self.textToSpline("SM_GammaTot", self.datadir+"YR-BR.txt", ycol=6);
25  def makeBR(self,decay):
26  if decay == "hww": self.textToSpline("SM_BR_hww", os.path.join(self.brpath, "BR.txt"), ycol=4);
27  if decay == "hzz": self.textToSpline("SM_BR_hzz", os.path.join(self.brpath, "BR.txt"), ycol=5);
28  if decay == "hgg": self.textToSpline("SM_BR_hgg", os.path.join(self.brpath, "BR.txt"), ycol=2);
29  if decay == "hZg": self.textToSpline("SM_BR_hZg", os.path.join(self.brpath, "BR.txt"), ycol=3);
30  if decay == "hbb": self.textToSpline("SM_BR_hbb", os.path.join(self.brpath, "BR1.txt"), ycol=1);
31  if decay == "htt": self.textToSpline("SM_BR_htt", os.path.join(self.brpath, "BR1.txt"), ycol=2);
32  if decay == "hmm": self.textToSpline("SM_BR_hmm", os.path.join(self.brpath, "BR1.txt"), ycol=3);
33  if decay == "hss": self.textToSpline("SM_BR_hss", os.path.join(self.brpath, "BR1.txt"), ycol=4);
34  if decay == "hcc": self.textToSpline("SM_BR_hcc", os.path.join(self.brpath, "BR1.txt"), ycol=5);
35  if decay == "hgluglu": self.textToSpline("SM_BR_hgluglu", os.path.join(self.brpath, "BR.txt"), ycol=1);
36  if decay == "htoptop": self.textToSpline("SM_BR_htoptop", os.path.join(self.brpath, "BR1.txt"), ycol=6);
37  def makePartialWidth(self,decay):
38  self.makeTotalWidth();
39  self.makeBR(decay);
40  self.modelBuilder.factory_('prod::SM_Gamma_%s(SM_GammaTot,SM_BR_%s)' % (decay,decay))
41  def dump(self,name,xvar,values,logfile):
42  xv = self.modelBuilder.out.var(xvar)
43  yf = self.modelBuilder.out.function(name)
44  if yf == None: raise RuntimeError, "Missing "+name
45  log = open(logfile, "w")
46  for x in values:
47  xv.setVal(x)
48  log.write("%.3f\t%.7g\n" % (x, yf.getVal()) )
49  def textToSpline(self,name,filename,xvar="MH",ycol=1,xcol=0,skipRows=1,algo="CSPLINE"):
50  if (self.modelBuilder.out.function(name) != None): return
51  x = []; y = []
52  file = open(filename,'r')
53  lines = [l for l in file]
54  for line in lines[skipRows:]:
55  if len(line.strip()) == 0: continue
56  cols = line.split();
57  x.append(float(cols[xcol]))
58  y.append(float(cols[ycol]))
59  xv = self.modelBuilder.out.var(xvar)
60  spline = ROOT.RooSpline1D(name, "file %s, x=%d, y=%d" % (filename,xcol,ycol), xv, len(x), array('d', x), array('d', y), algo)
61  self.modelBuilder.out._import(spline)
62 
63 #if __name__ == "__main__":
64 # sm = SMHiggsBuilder()