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 }
QGLikelihoodObject::data
std::vector< Entry > data
Definition: QGLikelihoodObject.h:33
MessageLogger.h
ESHandle.h
QGLikelihoodCalculator.h
QGLikelihoodCalculator::systematicSmearing
float systematicSmearing(edm::ESHandle< QGLikelihoodSystematicsObject > &QGLParamsColl, float pt, float eta, float rho, float qgValue, int qgIndex) const
Definition: QGLikelihoodCalculator.cc:100
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
min
T min(T a, T b)
Definition: MathUtil.h:58
QGLikelihoodCategory::PtMin
float PtMin
Definition: QGLikelihoodObject.h:10
ZElectronSkim_cff.rho
rho
Definition: ZElectronSkim_cff.py:38
QGLikelihoodCalculator::isValidRange
bool isValidRange(float pt, float rho, float eta, const QGLikelihoodCategory &qgValidRange) const
Check the valid range of this qg tagger.
Definition: QGLikelihoodCalculator.cc:63
callgraph.G
G
Definition: callgraph.py:17
QGLikelihoodObject::Entry
Definition: QGLikelihoodObject.h:25
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
class-composition.Q
Q
Definition: class-composition.py:82
QGLikelihoodCategory::EtaMin
float EtaMin
Definition: QGLikelihoodObject.h:10
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
vars
vars
Definition: DeepTauId.cc:164
PVValHelper::eta
Definition: PVValidationHelpers.h:70
edm::ESHandle
Definition: DTSurvey.h:22
b
double b
Definition: hdecay.h:118
QGLikelihoodSystematicsObject::data
std::vector< Entry > data
Definition: QGLikelihoodObject.h:44
QGLikelihoodCalculator::computeQGLikelihood
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.
Definition: QGLikelihoodCalculator.cc:8
QGLikelihoodCategory
Category structure: ranges associated with QGLikelihood histograms.
Definition: QGLikelihoodObject.h:9
QGLikelihoodCategory::RhoMax
float RhoMax
Definition: QGLikelihoodObject.h:10
a
double a
Definition: hdecay.h:119
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
QGLikelihoodObject::qgValidRange
QGLikelihoodCategory qgValidRange
Definition: QGLikelihoodObject.h:32
QGLikelihoodCalculator::findEntry
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.
Definition: QGLikelihoodCalculator.cc:36
QGLikelihoodObject.h
QGLikelihoodCategory::RhoMin
float RhoMin
Definition: QGLikelihoodObject.h:10
QGLikelihoodParameters
Parameters structure.
Definition: QGLikelihoodObject.h:16
QGLikelihoodCategory::EtaMax
float EtaMax
Definition: QGLikelihoodObject.h:10
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
hydjet2DefaultParameters_cff.myParameters
myParameters
Definition: hydjet2DefaultParameters_cff.py:354
QGLikelihoodCategory::PtMax
float PtMax
Definition: QGLikelihoodObject.h:10
QGLikelihoodCalculator::smearingFunction
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.
Definition: QGLikelihoodCalculator.cc:83