ATLAS Offline Software
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 
5 #include "./DipzLikelihoodCmp.h"
7 
8 #include <cmath>
9 #include <numeric>
10 
11 DipzLikelihood::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 
17 double 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 
42 double DipzLikelihood::calcNum(double acml, const pHypoJet &ip) const {
43 
44  double sigma_squared =
46 
47  double muoversigmasq =
49 
50  return acml + muoversigmasq;
51 }
52 
53 
54 double 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 
63 double 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 
84 double 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 
111 DipzLikelihoodCmp::DipzLikelihoodCmp(const std::string &decName_z,
112  const std::string &decName_negLogSigma2):
113  m_likelihoodCalculator(decName_z, decName_negLogSigma2) {
114 }
115 
117  const HypoJetVector& r) {
119 }
120 
121 
beamspotman.r
def r
Definition: beamspotman.py:676
DipzLikelihood::m_decName_negLogSigma2
const std::string m_decName_negLogSigma2
Definition: DipzLikelihoodCmp.h:51
DipzLikelihood::DipzLikelihood
DipzLikelihood(const std::string &decName_z, const std::string &decName_negLogSigma2)
Definition: DipzLikelihoodCmp.cxx:11
HypoJetDefs.h
DipzLikelihood::getDipzMLPLDecValue
double getDipzMLPLDecValue(const pHypoJet &ip, const std::string &decName) const
Definition: DipzLikelihoodCmp.cxx:27
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
DipzLikelihoodCmp::operator()
bool operator()(const HypoJetVector &, const HypoJetVector &)
Definition: DipzLikelihoodCmp.cxx:116
M_PI
#define M_PI
Definition: ActiveFraction.h:11
DipzLikelihoodCmp::m_likelihoodCalculator
DipzLikelihood m_likelihoodCalculator
Definition: DipzLikelihoodCmp.h:74
DipzLikelihood::checkedRatio
double checkedRatio(double num, double den) const
Definition: DipzLikelihoodCmp.cxx:17
DipzLikelihood::calcLogTerm
double calcLogTerm(double acmlt, const pHypoJet &ip, double zhat) const
Definition: DipzLikelihoodCmp.cxx:63
DipzLikelihood::calcNum
double calcNum(double acmlt, const pHypoJet &ip) const
Definition: DipzLikelihoodCmp.cxx:42
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
pHypoJet
std::shared_ptr< const HypoJet::IJet > pHypoJet
Definition: HypoJetDefs.h:25
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
DipzLikelihoodCmp.h
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
HypoJetVector
std::vector< pHypoJet > HypoJetVector
Definition: HypoJetDefs.h:27
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
DipzLikelihood::calcDenom
double calcDenom(double acmlt, const pHypoJet &ip) const
Definition: DipzLikelihoodCmp.cxx:54
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
DipzLikelihood::m_decName_z
const std::string m_decName_z
Definition: DipzLikelihoodCmp.h:50
DipzLikelihood::operator()
double operator()(const HypoJetVector &) const
Definition: DipzLikelihoodCmp.cxx:84
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
DipzLikelihoodCmp::DipzLikelihoodCmp
DipzLikelihoodCmp(const std::string &decName_z, const std::string &decName_negLogSigma2)
Definition: DipzLikelihoodCmp.cxx:111