CMS 3D CMS Logo

QGLikelihoodCalculator.cc
Go to the documentation of this file.
5 #include <cmath>
6 
9  edm::ESHandle<QGLikelihoodObject> &QGLParamsColl, float pt, float eta, float rho, std::vector<float> vars) const {
10  if (!isValidRange(pt, rho, eta, QGLParamsColl->qgValidRange))
11  return -1;
12 
13  float Q = 1., G = 1.;
14  for (unsigned int varIndex = 0; varIndex < vars.size(); ++varIndex) {
15  auto quarkEntry = findEntry(QGLParamsColl->data, eta, pt, rho, 0, varIndex);
16  auto gluonEntry = findEntry(QGLParamsColl->data, eta, pt, rho, 1, varIndex);
17  if (!quarkEntry || !gluonEntry)
18  return -2;
19 
20  int binQ = quarkEntry->histogram.findBin(vars[varIndex]);
21  float Qi = quarkEntry->histogram.binContent(binQ);
22 
23  int binG = gluonEntry->histogram.findBin(vars[varIndex]);
24  float Gi = gluonEntry->histogram.binContent(binG);
25 
26  Q *= Qi;
27  G *= Gi;
28  }
29 
30  if (Q == 0)
31  return 0;
32  return Q / (Q + G);
33 }
34 
36 const QGLikelihoodObject::Entry *QGLikelihoodCalculator::findEntry(std::vector<QGLikelihoodObject::Entry> const &data,
37  float eta,
38  float pt,
39  float rho,
40  int qgIndex,
41  int varIndex) const {
43  myParameters.Rho = rho;
44  myParameters.Pt = pt;
45  myParameters.Eta = fabs(eta);
46  myParameters.QGIndex = qgIndex;
47  myParameters.VarIndex = varIndex;
48 
49  auto myDataObject = data.begin();
50  while (!(myParameters == myDataObject->category)) {
51  ++myDataObject;
52  if (myDataObject == data.end()) {
53  edm::LogWarning("QGLCategoryNotFound")
54  << "Jet passed qgValidRange criteria, but no category found with rho=" << rho << ", pt=" << pt
55  << ", eta=" << eta << "\nPlease contact cms-qg-workinggroup@cern.ch" << std::endl;
56  return nullptr;
57  }
58  }
59  return &*myDataObject;
60 }
61 
64  float rho,
65  float eta,
66  const QGLikelihoodCategory &qgValidRange) const {
67  if (pt < qgValidRange.PtMin)
68  return false;
69  if (pt > qgValidRange.PtMax)
70  return false;
71  if (rho < qgValidRange.RhoMin)
72  return false;
73  if (rho > qgValidRange.RhoMax)
74  return false;
75  if (fabs(eta) < qgValidRange.EtaMin)
76  return false;
77  if (fabs(eta) > qgValidRange.EtaMax)
78  return false;
79  return true;
80 }
81 
83 float QGLikelihoodCalculator::smearingFunction(float x0, float a, float b, float min, float max) const {
84  float x = (x0 - min) / (max - min);
85  if (x < 0.)
86  x = 0.;
87  if (x > 1.)
88  x = 1.;
89 
90  float x1 = tanh(a * atanh(2. * x - 1.) + b) / 2. + .5;
91  if (x <= 0.)
92  x1 = 0.;
93  if (x >= 1.)
94  x1 = 1.;
95 
96  return x1 * (max - min) + min;
97 }
98 
99 // Get systematic smearing
101  float pt,
102  float eta,
103  float rho,
104  float qgValue,
105  int qgIndex) const {
106  if (qgValue < 0 || qgValue > 1)
107  return -1.;
108 
110  myParameters.Rho = rho;
111  myParameters.Pt = pt;
112  myParameters.Eta = fabs(eta);
113  myParameters.QGIndex = qgIndex;
114  myParameters.VarIndex = -1;
115 
116  auto myDataObject = QGLSystematicsColl->data.begin();
117  while (!(myParameters == myDataObject->systCategory)) {
118  ++myDataObject;
119  if (myDataObject == QGLSystematicsColl->data.end())
120  return -1; //Smearing not available in the whole qgValidRange: do not throw warnings or errors
121  }
122  return smearingFunction(qgValue, myDataObject->a, myDataObject->b, myDataObject->lmin, myDataObject->lmax);
123 }
Parameters structure.
bool isValidRange(float pt, float rho, float eta, const QGLikelihoodCategory &qgValidRange) const
Check the valid range of this qg tagger.
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...
QGLikelihoodCategory qgValidRange
float systematicSmearing(edm::ESHandle< QGLikelihoodSystematicsObject > &QGLParamsColl, float pt, float eta, float rho, float qgValue, int qgIndex) const
float computeQGLikelihood(edm::ESHandle< 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...
T min(T a, T b)
Definition: MathUtil.h:58
Category structure: ranges associated with QGLikelihood histograms.
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.
double b
Definition: hdecay.h:118
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
std::vector< Entry > data
double a
Definition: hdecay.h:119
vars
Definition: DeepTauId.cc:158