Belle II Software development
PDF1Dim.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <top/reconstruction_cpp/PDF1Dim.h>
10#include <top/reconstruction_cpp/TOPRecoManager.h>
11#include <framework/logging/Logger.h>
12#include <algorithm>
13#include <cmath>
14
15namespace Belle2 {
20 namespace TOP {
21
22 PDF1Dim::PDF1Dim(const PDFConstructor& pdfConstructor, double binSize, double timeWindow):
23 m_moduleID(pdfConstructor.getModuleID()), m_minTime(TOPRecoManager::getMinTime()),
24 m_maxTime(TOPRecoManager::getMaxTime())
25 {
26
27 if (binSize <= 0) B2FATAL("TOP::PDF1Dim: bin size must be positive");
28 if (not pdfConstructor.isValid()) {
29 B2ERROR("TOP::PDF1Dim: PDFConstructor is not valid, cannot continue");
30 return;
31 }
32
33 // binning
34 m_numBins = (m_maxTime - m_minTime) / binSize + 1;
36
37 // photon times
38 for (const auto& hit : pdfConstructor.getSelectedHits()) {
39 m_times.push_back(hit.time);
40 }
41 if (not m_times.empty()) {
42 std::sort(m_times.begin(), m_times.end());
43 m_tminFot = m_times.front();
44 m_tmaxFot = m_times.back();
45 }
46
49 m_expectedBG = std::max(pdfConstructor.getBkgRate() * timeWindow, 0.1);
50
51 // temporary histogram to make 1D projection of PDF
52 TH1F pdfHisto("pdf_temporary", "", m_numBins, m_minTime, m_maxTime);
53
54 // first add background and delta-ray PDF's
55 m_bkg = m_expectedBG / timeWindow * m_binSize;
56 const auto& deltaRayPDF = pdfConstructor.getDeltaRayPDF();
57 for (int i = 0; i < m_numBins; i++) {
58 double t = pdfHisto.GetBinCenter(i + 1);
59 pdfHisto.SetBinContent(i + 1, m_bkg + m_expectedDelta * deltaRayPDF.getPDFValue(t) * m_binSize);
60 }
61
62 // then fill signal PDF
63 bool start = true;
64 for (const auto& pixelPDF : pdfConstructor.getSignalPDF()) {
65 for (const auto& peak : pixelPDF.getPDFPeaks()) {
66 pdfHisto.Fill(peak.t0, m_expectedSignal * peak.nph);
67 if (start) {
68 start = false;
69 m_tminPDF = peak.t0;
70 m_tmaxPDF = peak.t0;
71 }
72 m_tminPDF = std::min(m_tminPDF, peak.t0);
73 m_tmaxPDF = std::max(m_tmaxPDF, peak.t0);
74 }
75 }
76
77 // finally make look-up table for log(PDF)
78 for (int i = 0; i < m_numBins; i++) {
79 m_logF.push_back(log(pdfHisto.GetBinContent(i + 1)));
80 }
81 m_logBkg = log(m_bkg);
82
83 // determine T0 search region
85 double maxT0 = m_tmaxFot - m_tminPDF;
86 m_numBinsT0 = std::max(int((maxT0 - m_minT0) / m_binSize), 3) + 1;
88
89 }
90
91
92 double PDF1Dim::getLogL(double timeShift) const
93 {
94 double logL = 0;
95 for (const auto& time : m_times) {
96 double f = m_logBkg;
97 double t = time - timeShift;
98 if (t >= m_minTime and t < m_maxTime) {
99 unsigned i = (t - m_minTime) / m_binSize;
100 if (i < m_logF.size()) f = m_logF[i];
101 }
102 logL += f;
103 }
104 return logL;
105 }
106
107
108 TH1F PDF1Dim::getHistogram(std::string name, std::string title) const
109 {
110 TH1F h(name.c_str(), title.c_str(), m_logF.size(), m_minTime, m_maxTime);
111 for (size_t i = 0; i < m_logF.size(); i++) {
112 h.SetBinContent(i + 1, exp(m_logF[i]));
113 }
114 return h;
115 }
116
117 } // end top namespace
119} // end Belle2 namespace
120
int m_numBinsT0
number of bins for T0 finder w/ same bin size as PDF
Definition: PDF1Dim.h:151
double getLogL(double timeShift) const
Returns log likelihood.
Definition: PDF1Dim.cc:92
double m_binSize
bin size
Definition: PDF1Dim.h:157
double m_expectedSignal
expected number of signal photons
Definition: PDF1Dim.h:153
double m_tmaxPDF
maximal time of signal PDF
Definition: PDF1Dim.h:146
double m_tmaxFot
maximal time of photons
Definition: PDF1Dim.h:148
TH1F getHistogram(std::string name, std::string title) const
Returns binned one dimensional PDF (projection to time axis)
Definition: PDF1Dim.cc:108
double m_logBkg
log(m_bkg)
Definition: PDF1Dim.h:159
double m_expectedDelta
expected number of delta-ray photons
Definition: PDF1Dim.h:154
double m_maxTime
upper edge of the last bin
Definition: PDF1Dim.h:142
double m_minTime
lower edge of the first bin
Definition: PDF1Dim.h:141
double m_maxT0
maximal T0
Definition: PDF1Dim.h:150
int m_numBins
number of bins for signal PDF
Definition: PDF1Dim.h:140
double m_expectedBG
expected number of background photons
Definition: PDF1Dim.h:152
std::vector< double > m_times
photon times, from a given slot
Definition: PDF1Dim.h:144
double m_tminPDF
minimal time of signal PDF
Definition: PDF1Dim.h:145
PDF1Dim(const PDFConstructor &pdfConstructor, double binSize, double timeWindow)
Full constructor.
Definition: PDF1Dim.cc:22
double m_bkg
background [photons/bin]
Definition: PDF1Dim.h:156
double m_minT0
minimal T0
Definition: PDF1Dim.h:149
std::vector< double > m_logF
log(PDF) values
Definition: PDF1Dim.h:158
double m_tminFot
minimal time of photons
Definition: PDF1Dim.h:147
PDF construction and log likelihood determination for a given track and particle hypothesis.
double getBkgRate() const
Returns estimated background hit rate.
const std::vector< TOPTrack::SelectedHit > & getSelectedHits() const
Returns selected photon hits belonging to this slot.
double getExpectedDeltaPhotons() const
Returns the expected number of delta-ray photons within the default time window.
bool isValid() const
Checks the object status.
const std::vector< SignalPDF > & getSignalPDF() const
Returns signal PDF.
double getExpectedSignalPhotons() const
Returns the expected number of signal photons within the default time window.
const DeltaRayPDF & getDeltaRayPDF() const
Returns delta-ray PDF.
Singleton class providing pre-constructed reconstruction objects.
Abstract base class for different kinds of events.