CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions
QGLikelihoodCalculator Class Reference

#include <QGLikelihoodCalculator.h>

Public Member Functions

float computeQGLikelihood (const QGLikelihoodObject &QGLParamsColl, float pt, float eta, float rho, std::vector< float > vars) const
 Compute likelihood for a jet using the QGLikelihoodObject information and a set of variables. More...
 
 QGLikelihoodCalculator ()
 
float systematicSmearing (const QGLikelihoodSystematicsObject &QGLParamsColl, float pt, float eta, float rho, float qgValue, int qgIndex) const
 
 ~QGLikelihoodCalculator ()
 

Private Member Functions

const QGLikelihoodObject::EntryfindEntry (std::vector< QGLikelihoodObject::Entry > const &data, float eta, float pt, float rho, int qgIndex, int varIndex) const
 Find matching entry in vector for a given eta, pt, rho, qgIndex and varIndex. More...
 
bool isValidRange (float pt, float rho, float eta, const QGLikelihoodCategory &qgValidRange) const
 Check the valid range of this qg tagger. More...
 
float smearingFunction (float x0, float a, float b, float min, float max) const
 Return the smeared qgLikelihood value, given input x0 and parameters a, b, min and max. More...
 

Detailed Description

The QGLikelihoodCalculater calculates the likelihood for a jet It takes information on the valid range of the tool, the binning of the categories, and their PDFs from the QGLikelihoodObject The variables in the vars vector should match with the variables in the QGLikelihoodObject, in which they are identified by the varIndex Authors: andre.nosp@m.a.ca.nosp@m.rlo.m.nosp@m.arin.nosp@m.i@cer.nosp@m.n.ch, tom.c.nosp@m.orne.nosp@m.lis@c.nosp@m.ern..nosp@m.ch, cms-q.nosp@m.g-wo.nosp@m.rking.nosp@m.grou.nosp@m.p@cer.nosp@m.n.ch

Definition at line 12 of file QGLikelihoodCalculator.h.

Constructor & Destructor Documentation

◆ QGLikelihoodCalculator()

Definition at line 14 of file QGLikelihoodCalculator.h.

14 {};

◆ ~QGLikelihoodCalculator()

QGLikelihoodCalculator::~QGLikelihoodCalculator ( )
inline

Definition at line 15 of file QGLikelihoodCalculator.h.

15 {};

Member Function Documentation

◆ computeQGLikelihood()

float QGLikelihoodCalculator::computeQGLikelihood ( const QGLikelihoodObject QGLParamsColl,
float  pt,
float  eta,
float  rho,
std::vector< float >  vars 
) const

Compute likelihood for a jet using the QGLikelihoodObject information and a set of variables.

Definition at line 7 of file QGLikelihoodCalculator.cc.

References QGLikelihoodObject::data, PVValHelper::eta, findEntry(), cmssw_cycle_finder::G, isValidRange(), DiDispStaMuonMonitor_cfi::pt, and QGLikelihoodObject::qgValidRange.

Referenced by QGTagger::produce().

8  {
9  if (!isValidRange(pt, rho, eta, QGLParamsColl.qgValidRange))
10  return -1;
11 
12  float Q = 1., G = 1.;
13  for (unsigned int varIndex = 0; varIndex < vars.size(); ++varIndex) {
14  auto quarkEntry = findEntry(QGLParamsColl.data, eta, pt, rho, 0, varIndex);
15  auto gluonEntry = findEntry(QGLParamsColl.data, eta, pt, rho, 1, varIndex);
16  if (!quarkEntry || !gluonEntry)
17  return -2;
18 
19  int binQ = quarkEntry->histogram.findBin(vars[varIndex]);
20  float Qi = quarkEntry->histogram.binContent(binQ);
21 
22  int binG = gluonEntry->histogram.findBin(vars[varIndex]);
23  float Gi = gluonEntry->histogram.binContent(binG);
24 
25  Q *= Qi;
26  G *= Gi;
27  }
28 
29  if (Q == 0)
30  return 0;
31  return Q / (Q + G);
32 }
bool isValidRange(float pt, float rho, float eta, const QGLikelihoodCategory &qgValidRange) const
Check the valid range of this qg tagger.
vars
Definition: DeepTauIdBase.h:60
QGLikelihoodCategory qgValidRange
const QGLikelihoodObject::Entry * findEntry(std::vector< QGLikelihoodObject::Entry > const &data, float eta, float pt, float rho, int qgIndex, int varIndex) const
Find matching entry in vector for a given eta, pt, rho, qgIndex and varIndex.
std::vector< Entry > data

◆ findEntry()

const QGLikelihoodObject::Entry * QGLikelihoodCalculator::findEntry ( std::vector< QGLikelihoodObject::Entry > const &  data,
float  eta,
float  pt,
float  rho,
int  qgIndex,
int  varIndex 
) const
private

Find matching entry in vector for a given eta, pt, rho, qgIndex and varIndex.

Definition at line 35 of file QGLikelihoodCalculator.cc.

References data, PVValHelper::eta, hydjet2DefaultParameters_cff::myParameters, and DiDispStaMuonMonitor_cfi::pt.

Referenced by computeQGLikelihood().

40  {
42  myParameters.Rho = rho;
43  myParameters.Pt = pt;
44  myParameters.Eta = fabs(eta);
45  myParameters.QGIndex = qgIndex;
46  myParameters.VarIndex = varIndex;
47 
48  auto myDataObject = data.begin();
49  while (!(myParameters == myDataObject->category)) {
50  ++myDataObject;
51  if (myDataObject == data.end()) {
52  edm::LogWarning("QGLCategoryNotFound")
53  << "Jet passed qgValidRange criteria, but no category found with rho=" << rho << ", pt=" << pt
54  << ", eta=" << eta << "\nPlease contact cms-qg-workinggroup@cern.ch" << std::endl;
55  return nullptr;
56  }
57  }
58  return &*myDataObject;
59 }
Parameters structure.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
Log< level::Warning, false > LogWarning

◆ isValidRange()

bool QGLikelihoodCalculator::isValidRange ( float  pt,
float  rho,
float  eta,
const QGLikelihoodCategory qgValidRange 
) const
private

Check the valid range of this qg tagger.

Definition at line 62 of file QGLikelihoodCalculator.cc.

References PVValHelper::eta, QGLikelihoodCategory::EtaMax, QGLikelihoodCategory::EtaMin, DiDispStaMuonMonitor_cfi::pt, QGLikelihoodCategory::PtMax, QGLikelihoodCategory::PtMin, QGLikelihoodCategory::RhoMax, and QGLikelihoodCategory::RhoMin.

Referenced by computeQGLikelihood().

65  {
66  if (pt < qgValidRange.PtMin)
67  return false;
68  if (pt > qgValidRange.PtMax)
69  return false;
70  if (rho < qgValidRange.RhoMin)
71  return false;
72  if (rho > qgValidRange.RhoMax)
73  return false;
74  if (fabs(eta) < qgValidRange.EtaMin)
75  return false;
76  if (fabs(eta) > qgValidRange.EtaMax)
77  return false;
78  return true;
79 }

◆ smearingFunction()

float QGLikelihoodCalculator::smearingFunction ( float  x0,
float  a,
float  b,
float  min,
float  max 
) const
private

Return the smeared qgLikelihood value, given input x0 and parameters a, b, min and max.

Definition at line 82 of file QGLikelihoodCalculator.cc.

References a, b, SiStripPI::max, SiStripPI::min, nnet::tanh(), and x.

Referenced by systematicSmearing().

82  {
83  float x = (x0 - min) / (max - min);
84  if (x < 0.)
85  x = 0.;
86  if (x > 1.)
87  x = 1.;
88 
89  float x1 = tanh(a * atanh(2. * x - 1.) + b) / 2. + .5;
90  if (x <= 0.)
91  x1 = 0.;
92  if (x >= 1.)
93  x1 = 1.;
94 
95  return x1 * (max - min) + min;
96 }
void tanh(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
float x

◆ systematicSmearing()

float QGLikelihoodCalculator::systematicSmearing ( const QGLikelihoodSystematicsObject QGLParamsColl,
float  pt,
float  eta,
float  rho,
float  qgValue,
int  qgIndex 
) const

Definition at line 99 of file QGLikelihoodCalculator.cc.

References QGLikelihoodSystematicsObject::data, PVValHelper::eta, hydjet2DefaultParameters_cff::myParameters, DiDispStaMuonMonitor_cfi::pt, and smearingFunction().

Referenced by QGTagger::produce().

104  {
105  if (qgValue < 0 || qgValue > 1)
106  return -1.;
107 
109  myParameters.Rho = rho;
110  myParameters.Pt = pt;
111  myParameters.Eta = fabs(eta);
112  myParameters.QGIndex = qgIndex;
113  myParameters.VarIndex = -1;
114 
115  auto myDataObject = QGLSystematicsColl.data.begin();
116  while (!(myParameters == myDataObject->systCategory)) {
117  ++myDataObject;
118  if (myDataObject == QGLSystematicsColl.data.end())
119  return -1; //Smearing not available in the whole qgValidRange: do not throw warnings or errors
120  }
121  return smearingFunction(qgValue, myDataObject->a, myDataObject->b, myDataObject->lmin, myDataObject->lmax);
122 }
Parameters structure.
float smearingFunction(float x0, float a, float b, float min, float max) const
Return the smeared qgLikelihood value, given input x0 and parameters a, b, min and max...