Belle II Software development
VXDDedxTrack.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#include <reconstruction/dataobjects/VXDDedxTrack.h>
9#include <framework/logging/Logger.h>
10#include <cmath>
11
12namespace Belle2 {
18 void VXDDedxTrack::addHit(int sid, int layer, int adcCount, double dx, double dEdx)
19 {
20 m_sensorID.push_back(sid);
21 m_layer.push_back(layer);
22 m_adcCount.push_back(adcCount);
23 m_dx.push_back(dx);
24 m_dEdx.push_back(dEdx);
25 }
26
27 void VXDDedxTrack::addDedx(int layer, double distance, double dedxValue)
28 {
29 dedxLayer.push_back(layer);
30 dist.push_back(distance);
31 dedx.push_back(dedxValue);
32 m_length += distance;
33 }
34
36 {
37 if (detector == Const::PXD) return m_dedxAvgTruncated[Dedx::c_PXD];
38 if (detector == Const::SVD) return m_dedxAvgTruncated[Dedx::c_SVD];
39 return 0.0;
40 }
41
43 {
44 if (detector == Const::PXD) return m_dedxAvgTruncatedErr[Dedx::c_PXD];
45 if (detector == Const::SVD) return m_dedxAvgTruncatedErr[Dedx::c_SVD];
46 return 0.0;
47 }
48
50 {
51 if (detector == Const::PXD) return m_dedxAvg[Dedx::c_PXD];
52 if (detector == Const::SVD) return m_dedxAvg[Dedx::c_SVD];
53 return 0.0;
54 }
55
57 {
58 for (auto& logl : m_vxdLogl) logl = 0;
59 m_numAdded = 0;
60 }
61
62 void VXDDedxTrack::addLogLikelihoods(const std::vector<const TH2F*>& PDFs, Dedx::Detector detector, bool truncated)
63 {
64 if (detector != Dedx::c_PXD and detector != Dedx::c_SVD) return;
65
66 if (truncated) {
67 addLogLikelihoods(PDFs, m_dedxAvgTruncated[detector], 1e-3);
68 } else {
69 for (size_t i = 0; i < dedx.size(); i++) {
70 if (detector == Dedx::c_PXD and std::abs(dedxLayer[i]) > 2) continue;
71 if (detector == Dedx::c_SVD and std::abs(dedxLayer[i]) < 3) continue;
72 addLogLikelihoods(PDFs, dedx[i], 1e-5);
73 }
74 }
75
76 }
77
78 void VXDDedxTrack::addLogLikelihoods(const std::vector<const TH2F*>& PDFs, double dedxValue, double minPDFValue)
79 {
80 if (dedxValue <= 0) return;
81
82 int binX = PDFs[0]->GetXaxis()->FindFixBin(m_p);
83 int binY = PDFs[0]->GetYaxis()->FindFixBin(dedxValue);
84 bool inRange = binX > 0 and binX <= PDFs[0]->GetNbinsX() and binY > 0 and binY <= PDFs[0]->GetNbinsY();
85 for (unsigned int iPart = 0; iPart < Const::ChargedStable::c_SetSize; iPart++) {
86 double pdfValue = 0;
87 const auto& pdf = PDFs[iPart];
88 if (inRange) {
89 pdfValue = const_cast<TH2F*>(pdf)->Interpolate(m_p, dedxValue);
90 } else {
91 pdfValue = pdf->GetBinContent(binX, binY);
92 }
93 if (pdfValue != pdfValue) {
94 B2ERROR("pdfValue is NAN for a track with p=" << m_p << " and dedx=" << dedxValue);
96 return;
97 }
98 if (pdfValue <= 0) pdfValue = minPDFValue;
99 m_vxdLogl[iPart] += std::log(pdfValue);
100 }
101
102 m_numAdded++;
103 }
104
106} // end namespace Belle2
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
Definition: Const.h:615
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:42
double m_p
momentum at the IP
Definition: VXDDedxTrack.h:146
std::vector< double > m_dx
path length in layer
Definition: VXDDedxTrack.h:130
double m_dedxAvgTruncated[2]
dE/dx truncated mean per track
Definition: VXDDedxTrack.h:142
std::vector< int > m_layer
VXD layer number.
Definition: VXDDedxTrack.h:127
std::vector< int > m_adcCount
adcCount per hit
Definition: VXDDedxTrack.h:129
double m_vxdLogl[Const::ChargedStable::c_SetSize]
log likelihood for each particle
Definition: VXDDedxTrack.h:138
double m_length
total distance travelled by the track
Definition: VXDDedxTrack.h:148
std::vector< int > m_sensorID
unique sensor ID
Definition: VXDDedxTrack.h:128
double m_dedxAvgTruncatedErr[2]
standard deviation of m_dedxAvgTruncated
Definition: VXDDedxTrack.h:143
int m_numAdded
counter of added log likelihood values
Definition: VXDDedxTrack.h:156
double m_dedxAvg[2]
dE/dx mean value per track
Definition: VXDDedxTrack.h:141
std::vector< double > dist
distance flown through active medium in current segment
Definition: VXDDedxTrack.h:135
std::vector< double > m_dEdx
charge per path length
Definition: VXDDedxTrack.h:131
std::vector< double > dedxLayer
layer id corresponding to dE/dx measurement
Definition: VXDDedxTrack.h:136
std::vector< double > dedx
extracted dE/dx (arb.
Definition: VXDDedxTrack.h:134
void addHit(int sid, int layer, int adcCount, double dx, double dEdx)
Add a single hit to the object.
Definition: VXDDedxTrack.cc:18
void addDedx(int layer, double distance, double dedxValue)
add dE/dx information for a VXD layer
Definition: VXDDedxTrack.cc:27
void addLogLikelihoods(const std::vector< const TH2F * > &PDFs, Dedx::Detector detector, bool truncated)
Calculate and add log likelihoods to array m_vxdLogl.
Definition: VXDDedxTrack.cc:62
void clearLogLikelihoods()
Clear log likelihoods (set to zero) and reset the counter of added log likelihood values.
Definition: VXDDedxTrack.cc:56
double getDedxError(Const::EDetector detector) const
Get the error on the dE/dx truncated mean for given detector.
Definition: VXDDedxTrack.cc:42
double getDedxMean(Const::EDetector detector) const
Get the dE/dx mean for given detector.
Definition: VXDDedxTrack.cc:49
double getDedx(Const::EDetector detector) const
Get dE/dx truncated mean for given detector.
Definition: VXDDedxTrack.cc:35
Abstract base class for different kinds of events.