CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes
QGLikelihoodCalculator.QGLikelihoodCalculator Class Reference

Public Member Functions

def __init__
 
def computeQGLikelihood
 
def findEntry
 
def init
 
def isValidRange
 

Public Attributes

 etaBins
 
 pdfs
 
 ptBins
 
 qgNames
 
 rhoBins
 
 varNames
 

Detailed Description

Definition at line 20 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 118 of file QGLikelihoodCalculator.py.

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

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

Definition at line 102 of file QGLikelihoodCalculator.py.

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

Referenced by QGLikelihoodCalculator.QGLikelihoodCalculator.computeQGLikelihood().

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

Definition at line 31 of file QGLikelihoodCalculator.py.

References QGLikelihoodCalculator.QGLikelihoodCalculator.etaBins, CSCTFConstants.etaBins, l1t::GlobalScales::ScaleParameters.etaBins, BTagWeightCalculator.BTagWeightCalculator.pdfs, QGLikelihoodCalculator.QGLikelihoodCalculator.pdfs, PhysicsTools::Calibration::ProcLikelihood.pdfs, print(), QGLikelihoodCalculator.QGLikelihoodCalculator.ptBins, QGLikelihoodCalculator.QGLikelihoodCalculator.qgNames, sistrip::SpyUtilities.range(), QGLikelihoodCalculator.QGLikelihoodCalculator.rhoBins, submitPVValidationJobs.split(), and QGLikelihoodCalculator.QGLikelihoodCalculator.varNames.

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

Definition at line 89 of file QGLikelihoodCalculator.py.

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

Referenced by QGLikelihoodCalculator.QGLikelihoodCalculator.computeQGLikelihood().

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

Member Data Documentation

QGLikelihoodCalculator.QGLikelihoodCalculator.etaBins

Definition at line 24 of file QGLikelihoodCalculator.py.

Referenced by QGLikelihoodCalculator.QGLikelihoodCalculator.findEntry(), QGLikelihoodCalculator.QGLikelihoodCalculator.init(), and QGLikelihoodCalculator.QGLikelihoodCalculator.isValidRange().

QGLikelihoodCalculator.QGLikelihoodCalculator.pdfs

Definition at line 23 of file QGLikelihoodCalculator.py.

Referenced by QGLikelihoodCalculator.QGLikelihoodCalculator.findEntry(), and QGLikelihoodCalculator.QGLikelihoodCalculator.init().

QGLikelihoodCalculator.QGLikelihoodCalculator.ptBins

Definition at line 25 of file QGLikelihoodCalculator.py.

Referenced by QGLikelihoodCalculator.QGLikelihoodCalculator.findEntry(), QGLikelihoodCalculator.QGLikelihoodCalculator.init(), and QGLikelihoodCalculator.QGLikelihoodCalculator.isValidRange().

QGLikelihoodCalculator.QGLikelihoodCalculator.qgNames

Definition at line 28 of file QGLikelihoodCalculator.py.

Referenced by QGLikelihoodCalculator.QGLikelihoodCalculator.init().

QGLikelihoodCalculator.QGLikelihoodCalculator.rhoBins

Definition at line 26 of file QGLikelihoodCalculator.py.

Referenced by QGLikelihoodCalculator.QGLikelihoodCalculator.findEntry(), QGLikelihoodCalculator.QGLikelihoodCalculator.init(), and QGLikelihoodCalculator.QGLikelihoodCalculator.isValidRange().

QGLikelihoodCalculator.QGLikelihoodCalculator.varNames

Definition at line 27 of file QGLikelihoodCalculator.py.

Referenced by QGLikelihoodCalculator.QGLikelihoodCalculator.computeQGLikelihood(), and QGLikelihoodCalculator.QGLikelihoodCalculator.init().