ATLAS Offline Software
Loading...
Searching...
No Matches
DipzLikelihoodCmp.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include <cmath>
9#include <numeric>
10
11DipzLikelihood::DipzLikelihood(const std::string &decName_z,
12 const std::string &decName_negLogSigma2):
13 m_decName_z(decName_z),
14 m_decName_negLogSigma2(decName_negLogSigma2){
15}
16
17double DipzLikelihood::checkedRatio(double num, double den) const {
18 if (den == 0.) {
19 // dividing x/0 is picked up by FPEAditor. C++ simply returns
20 // +inf or -inf if x != 0, or a nan otherwise.
21 throw std::runtime_error("DipzLikelihood::checkedRatio dividing by 0");
22 }
23
24 return num/den;
25}
26
28 const std::string &decName) const
29{
30
31 float momentValue;
32 if (!(ip->getAttribute(decName, momentValue))) {
33 throw std::runtime_error("Impossible to retrieve decorator \'" +
34 decName + "\' for jet hypo");
35 }
36
37 // momentValue is retrieved as a float, but will be heavily used in
38 // further calculations. Convert to a double here
39 return momentValue;
40}
41
42double DipzLikelihood::calcNum(double acml, const pHypoJet &ip) const {
43
44 double sigma_squared =
46
47 double muoversigmasq =
48 checkedRatio( getDipzMLPLDecValue(ip, m_decName_z), sigma_squared);
49
50 return acml + muoversigmasq;
51}
52
53
54double DipzLikelihood::calcDenom(double acml, const pHypoJet &ip) const {
55 double sigma_squared =
57
58 double oneoversigmasq = checkedRatio(1, sigma_squared);
59
60 return acml + oneoversigmasq;
61}
62
63double DipzLikelihood::calcLogTerm(double acml,
64 const pHypoJet &ip,
65 double zhat) const {
66
67 double dipz_mu = getDipzMLPLDecValue(ip, m_decName_z);
68
69 double dipz_negLogSigmaSq =
71
72 double sigma_squared = std::exp(-1 * dipz_negLogSigmaSq);
73
74 double logterm =
75 -0.5 * std::log(2.0 * M_PI)
76 + 0.5 * dipz_negLogSigmaSq
77 - checkedRatio(std::pow(zhat - dipz_mu, 2), (2.0 * sigma_squared) );
78
79 return acml + logterm;
80
81}
82
83
84double DipzLikelihood::operator()(const HypoJetVector& ips) const {
85
86 auto zhat_num = std::accumulate(ips.begin(),
87 ips.end(),
88 0.0,
89 [this](double sum, const pHypoJet& jp) {
90 return this->calcNum(sum, jp);});
91
92 auto zhat_den = std::accumulate(ips.begin(),
93 ips.end(),
94 0.0,
95 [this](double sum, const pHypoJet& jp) {
96 return this->calcDenom(sum, jp);});
97
98 auto zhat = checkedRatio(zhat_num, zhat_den);
99
100 auto logproduct =
101 std::accumulate(ips.begin(),
102 ips.end(),
103 0.0,
104 [&zhat,this](double sum, const pHypoJet& jp) {
105 return this->calcLogTerm(sum, jp, zhat);});
106
107 return logproduct;
108}
109
110
111DipzLikelihoodCmp::DipzLikelihoodCmp(const std::string &decName_z,
112 const std::string &decName_negLogSigma2):
113 m_likelihoodCalculator(decName_z, decName_negLogSigma2) {
114}
115
120
121
#define M_PI
std::vector< pHypoJet > HypoJetVector
Definition HypoJetDefs.h:27
std::shared_ptr< const HypoJet::IJet > pHypoJet
Definition HypoJetDefs.h:25
bool operator()(const HypoJetVector &, const HypoJetVector &)
DipzLikelihood m_likelihoodCalculator
DipzLikelihoodCmp(const std::string &decName_z, const std::string &decName_negLogSigma2)
double checkedRatio(double num, double den) const
const std::string m_decName_z
double calcNum(double acmlt, const pHypoJet &ip) const
double operator()(const HypoJetVector &) const
double calcLogTerm(double acmlt, const pHypoJet &ip, double zhat) const
const std::string m_decName_negLogSigma2
double calcDenom(double acmlt, const pHypoJet &ip) const
DipzLikelihood(const std::string &decName_z, const std::string &decName_negLogSigma2)
double getDipzMLPLDecValue(const pHypoJet &ip, const std::string &decName) const
int r
Definition globals.cxx:22