CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
QGLikelihoodCalculator.QGLikelihoodCalculator Class Reference

Public Member Functions

def __init__ (self, filename)
 
def computeQGLikelihood (self, jet, rho)
 
def findEntry (self, eta, pt, rho, qgType, varName)
 
def init (self, filename)
 
def isValidRange (self, pt, rho, eta)
 

Public Attributes

 etaBins
 
 pdfs
 
 ptBins
 
 qgNames
 
 rhoBins
 
 varNames
 

Detailed Description

Definition at line 18 of file QGLikelihoodCalculator.py.

Constructor & Destructor Documentation

def QGLikelihoodCalculator.QGLikelihoodCalculator.__init__ (   self,
  filename 
)

Member Function Documentation

def QGLikelihoodCalculator.QGLikelihoodCalculator.computeQGLikelihood (   self,
  jet,
  rho 
)

Definition at line 116 of file QGLikelihoodCalculator.py.

References AlignableDataIORoot.findEntry(), HIPUserVariablesIORoot.findEntry(), AlignmentParametersIORoot.findEntry(), EntryMgr.findEntry(), QGLikelihoodCalculator.QGLikelihoodCalculator.findEntry(), QGLikelihoodCalculator.QGLikelihoodCalculator.isValidRange(), and QGLikelihoodCalculator.QGLikelihoodCalculator.varNames.

116  def computeQGLikelihood( self, jet, rho ):
117 
118  if self.isValidRange(jet.pt(), rho, jet.eta())==False: return -1
119 
120  # careful!!! this needs to be in the same order of self.varNames
121  vars = {0:jet.mult, 1:jet.ptd, 2:jet.axis2}
122 
123  Q=1.
124  G=1.
125 
126  #print "----------------------"
127  #if jet.partonFlavour()==21 :
128  # print "this jet is a GLUON"
129  #elif math.fabs(jet.partonFlavour())<4 and jet.partonFlavour()!=0:
130  # print "this jet is a QUARK"
131  #print "pt: " + str(jet.pt()) + " eta: " + str(jet.eta()) + " rho: " + str(rho)
132  #print "multi: " + str(jet.mult) + " ptd: " + str(jet.ptd) + " axis2: " + str(jet.axis2)
133 
134  for i in vars :
135 
136  #print self.varNames[i] + ": " + str(vars[i])
137  # quarks
138  qgEntry = self.findEntry(jet.eta(), jet.pt(), rho, "quark", self.varNames[i])
139 
140  if qgEntry == None: return -1
141  Qi = qgEntry.GetBinContent(qgEntry.FindBin(vars[i]))
142  mQ = qgEntry.GetMean()
143  #print "Qi: " + str(Qi)
144 
145  # gluons
146  qgEntry = self.findEntry(jet.eta(), jet.pt(), rho, "gluon", self.varNames[i])
147 
148  if qgEntry == None: return -1
149  Gi = qgEntry.GetBinContent(qgEntry.FindBin(vars[i]))
150  mG = qgEntry.GetMean()
151  #print "Gi: " + str(Gi)
152 
153  epsilon=0.
154  delta=0.000001
155  if Qi <= epsilon and Gi <= epsilon :
156  if mQ>mG :
157  if vars[i] > mQ :
158  Qi = 1.-delta
159  Gi = delta
160  elif vars[i] < mG :
161  Qi = delta
162  Gi = 1.-delta
163  else :
164  if vars[i]<mQ :
165  Qi = 1.-delta
166  Gi = delta
167  elif vars[i]>mG :
168  Qi = delta
169  Gi = 1.-delta
170 
171  Q*=Qi
172  G*=Gi
173 
174 
175  #print "Q: " + str(Q)
176  #print "G: " + str(G)
177  if Q==0. : return 0.
178  else : return Q/(Q+G)
179 
def QGLikelihoodCalculator.QGLikelihoodCalculator.findEntry (   self,
  eta,
  pt,
  rho,
  qgType,
  varName 
)

Definition at line 100 of file QGLikelihoodCalculator.py.

References QGLikelihoodCalculator.QGLikelihoodCalculator.etaBins, CSCTFConstants.etaBins, ElectronStudy.etaBins, l1t::GlobalScales::ScaleParameters.etaBins, ZMuMu_efficiencyAnalyzer.etaBins, QGLikelihoodCalculator.getBinNumber(), BTagWeightCalculator.BTagWeightCalculator.pdfs, QGLikelihoodCalculator.QGLikelihoodCalculator.pdfs, PhysicsTools::Calibration::ProcLikelihood.pdfs, QGLikelihoodCalculator.QGLikelihoodCalculator.ptBins, ZMuMu_efficiencyAnalyzer.ptBins, and QGLikelihoodCalculator.QGLikelihoodCalculator.rhoBins.

Referenced by QGLikelihoodCalculator.QGLikelihoodCalculator.computeQGLikelihood().

100  def findEntry( self, eta, pt, rho, qgType, varName ) :
101 
102  etaBin = getBinNumber( self.etaBins, math.fabs(eta))
103  if etaBin==-1: return None
104  ptBin = getBinNumber( self.ptBins, pt )
105  if ptBin==-1 : return None
106 
107  rhoBin = getBinNumber( self.rhoBins, rho )
108  if rhoBin==-1 : return None
109 
110  return self.pdfs[qgType][varName][etaBin][ptBin][rhoBin]
111 
112 
113 
114 
115 
def findEntry(self, eta, pt, rho, qgType, varName)
def QGLikelihoodCalculator.QGLikelihoodCalculator.init (   self,
  filename 
)

Definition at line 29 of file QGLikelihoodCalculator.py.

References QGLikelihoodCalculator.QGLikelihoodCalculator.etaBins, CSCTFConstants.etaBins, ElectronStudy.etaBins, l1t::GlobalScales::ScaleParameters.etaBins, ZMuMu_efficiencyAnalyzer.etaBins, createfilelist.int, BTagWeightCalculator.BTagWeightCalculator.pdfs, QGLikelihoodCalculator.QGLikelihoodCalculator.pdfs, PhysicsTools::Calibration::ProcLikelihood.pdfs, QGLikelihoodCalculator.QGLikelihoodCalculator.ptBins, ZMuMu_efficiencyAnalyzer.ptBins, QGLikelihoodCalculator.QGLikelihoodCalculator.qgNames, QGLikelihoodCalculator.QGLikelihoodCalculator.rhoBins, split, and QGLikelihoodCalculator.QGLikelihoodCalculator.varNames.

29  def init(self, filename) :
30 
31  print "[QGLikelihoodCalculator]: Initializing from file: " + filename
32 
33  f = ROOT.TFile.Open(filename)
34  if f.IsZombie() : return False
35  try :
36  self.etaBins = f.Get("etaBins")
37  self.ptBins = f.Get("ptBins")
38  self.rhoBins = f.Get("rhoBins")
39  except :
40  return False
41 
42 
43 
44  self.pdfs = {}
45 
46  for it in range(0,len(self.qgNames)):
47  self.pdfs[self.qgNames[it]] = {}
48  for iv in range(0,len(self.varNames)):
49  self.pdfs[self.qgNames[it]][self.varNames[iv]] = {}
50  for ie in range(0,len(self.etaBins)):
51  self.pdfs[self.qgNames[it]][self.varNames[iv]][ie] = {}
52  for ip in range(0,len(self.ptBins)):
53  self.pdfs[self.qgNames[it]][self.varNames[iv]][ie][ip] = {}
54  for ir in range(0,len(self.rhoBins)):
55  self.pdfs[self.qgNames[it]][self.varNames[iv]][ie][ip][ir] = 0
56 
57 
58 
59  print "[QGLikelihoodCalculator]: Initialized binning of pdfs..."
60 
61  keys = f.GetListOfKeys()
62  for key in keys :
63  if key.IsFolder() == False: continue
64  hists = key.ReadObj().GetListOfKeys()
65  for hist in hists :
66  pieces = hist.GetName().split("_")
67  varName = pieces[0]
68  qgType = pieces[1]
69  etaStr = pieces[2]
70  ptStr = pieces[3]
71  rhoStr = pieces[4]
72  etaBin = int(etaStr.split("eta")[1])
73  ptBin = int( ptStr.split("pt") [1])
74  rhoBin = int(rhoStr.split("rho")[1])
75  histogram = hist.ReadObj()
76  histogram.SetDirectory(0)
77  self.pdfs[qgType][varName][etaBin][ptBin][rhoBin] = histogram
78 
79  print "[QGLikelihoodCalculator]: pdfs initialized..."
80 
81 
82  return True
83 
84 
85 
86 
double split
Definition: MVATrainer.cc:139
def QGLikelihoodCalculator.QGLikelihoodCalculator.isValidRange (   self,
  pt,
  rho,
  eta 
)

Member Data Documentation

QGLikelihoodCalculator.QGLikelihoodCalculator.pdfs
QGLikelihoodCalculator.QGLikelihoodCalculator.qgNames
QGLikelihoodCalculator.QGLikelihoodCalculator.varNames