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 19 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 117 of file QGLikelihoodCalculator.py.

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

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

Definition at line 101 of file QGLikelihoodCalculator.py.

References QGLikelihoodCalculator.QGLikelihoodCalculator.etaBins, CSCTFConstants.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().

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

Definition at line 30 of file QGLikelihoodCalculator.py.

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

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

Definition at line 88 of file QGLikelihoodCalculator.py.

References QGLikelihoodCalculator.QGLikelihoodCalculator.etaBins, CSCTFConstants.etaBins, l1t::GlobalScales::ScaleParameters.etaBins, ZMuMu_efficiencyAnalyzer.etaBins, QGLikelihoodCalculator.QGLikelihoodCalculator.ptBins, ZMuMu_efficiencyAnalyzer.ptBins, and QGLikelihoodCalculator.QGLikelihoodCalculator.rhoBins.

Referenced by QGLikelihoodCalculator.QGLikelihoodCalculator.computeQGLikelihood().

88  def isValidRange( self, pt, rho, eta ) :
89 
90  if pt < self.ptBins[0]: return False
91  if pt > self.ptBins[len(self.ptBins)-1]: return False
92  if rho < self.rhoBins[0]: return False
93  if rho > self.rhoBins[len(self.rhoBins)-1]: return False
94  if math.fabs(eta) < self.etaBins[0]: return False
95  if math.fabs(eta) > self.etaBins[len(self.etaBins)-1]: return False
96  return True
97 
98 
99 
100 

Member Data Documentation

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