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

Constructor & Destructor Documentation

◆ __init__()

def QGLikelihoodCalculator.QGLikelihoodCalculator.__init__ (   self,
  filename 
)

Definition at line 22 of file QGLikelihoodCalculator.py.

22  def __init__(self, filename) :
23  self.pdfs = {}
24  self.etaBins = []
25  self.ptBins = []
26  self.rhoBins = []
27  self.varNames = { 0:'mult', 1:'ptD', 2:'axis2' }
28  self.qgNames = { 0:'quark', 1:'gluon' }
29  self.init(filename)
30 

Member Function Documentation

◆ computeQGLikelihood()

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

Definition at line 118 of file QGLikelihoodCalculator.py.

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

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

◆ findEntry()

def QGLikelihoodCalculator.QGLikelihoodCalculator.findEntry (   self,
  eta,
  pt,
  rho,
  qgType,
  varName 
)

Definition at line 102 of file QGLikelihoodCalculator.py.

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

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().

◆ init()

def QGLikelihoodCalculator.QGLikelihoodCalculator.init (   self,
  filename 
)

Definition at line 31 of file QGLikelihoodCalculator.py.

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

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, print(), QGLikelihoodCalculator.QGLikelihoodCalculator.ptBins, ZMuMu_efficiencyAnalyzer.ptBins, QGLikelihoodCalculator.QGLikelihoodCalculator.qgNames, FastTimerService_cff.range, QGLikelihoodCalculator.QGLikelihoodCalculator.rhoBins, submitPVValidationJobs.split(), and QGLikelihoodCalculator.QGLikelihoodCalculator.varNames.

◆ isValidRange()

def QGLikelihoodCalculator.QGLikelihoodCalculator.isValidRange (   self,
  pt,
  rho,
  eta 
)

Definition at line 89 of file QGLikelihoodCalculator.py.

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

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().

Member Data Documentation

◆ etaBins

QGLikelihoodCalculator.QGLikelihoodCalculator.etaBins

◆ pdfs

QGLikelihoodCalculator.QGLikelihoodCalculator.pdfs

◆ ptBins

QGLikelihoodCalculator.QGLikelihoodCalculator.ptBins

◆ qgNames

QGLikelihoodCalculator.QGLikelihoodCalculator.qgNames

◆ rhoBins

QGLikelihoodCalculator.QGLikelihoodCalculator.rhoBins

◆ varNames

QGLikelihoodCalculator.QGLikelihoodCalculator.varNames
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
init
int init
Definition: HydjetWrapper.h:64
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
createfilelist.int
int
Definition: createfilelist.py:10
QGLikelihoodCalculator.getBinNumber
def getBinNumber(bins, value)
Definition: QGLikelihoodCalculator.py:8