CMS 3D CMS Logo

QGLikelihoodCalculator.cc
Go to the documentation of this file.
4 #include <cmath>
5 
8  const QGLikelihoodObject &QGLParamsColl, float pt, float eta, float rho, std::vector<float> vars) const {
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 }
33 
35 const QGLikelihoodObject::Entry *QGLikelihoodCalculator::findEntry(std::vector<QGLikelihoodObject::Entry> const &data,
36  float eta,
37  float pt,
38  float rho,
39  int qgIndex,
40  int varIndex) const {
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 }
60 
63  float rho,
64  float eta,
65  const QGLikelihoodCategory &qgValidRange) const {
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 }
80 
82 float QGLikelihoodCalculator::smearingFunction(float x0, float a, float b, float min, float max) const {
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 }
97 
98 // Get systematic smearing
100  float pt,
101  float eta,
102  float rho,
103  float qgValue,
104  int qgIndex) const {
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 systematicSmearing(const QGLikelihoodSystematicsObject &QGLParamsColl, float pt, float eta, float rho, float qgValue, int qgIndex) const
bool isValidRange(float pt, float rho, float eta, const QGLikelihoodCategory &qgValidRange) const
Check the valid range of this qg tagger.
void tanh(data_T data[CONFIG_T::n_in], res_T res[CONFIG_T::n_in])
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.
QGLikelihoodObject containing valid range and entries with category and histogram (mean is not used a...
Category structure: ranges associated with QGLikelihood histograms.
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...
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...
double b
Definition: hdecay.h:120
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
std::vector< Entry > data
double a
Definition: hdecay.h:121
float x
vars
Definition: DeepTauId.cc:166
QGLikelihoodSystematicsObject containing the parameters for the systematic smearing.
Log< level::Warning, false > LogWarning