Belle II Software  release-05-01-25
SVDRecoDigit.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Peter Kvasnicka *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <vxd/dataobjects/VxdID.h>
12 #include <svd/dataobjects/SVDModeByte.h>
13 #include <svd/dataobjects/SVDRecoDigit.h>
14 #include <vector>
15 #include <string>
16 #include <cmath>
17 #include <gtest/gtest.h>
18 
19 namespace Belle2 {
24  namespace SVD {
25 
29  TEST(SVDRecoDigit, ConstructEmpty)
30  {
31  // Create an empty 6-digit
32  SVDRecoDigit digit;
33  // Test getters
34  EXPECT_EQ(0, digit.getSensorID());
35  EXPECT_TRUE(digit.isUStrip());
36  EXPECT_EQ(0, digit.getCellID());
37  EXPECT_EQ(0, digit.getAmplitude());
38  EXPECT_EQ(10, digit.getAmplitudeError());
39  EXPECT_EQ(0, digit.getTime());
40  EXPECT_EQ(100, digit.getTimeError());
41  const SVDRecoDigit::OutputProbArray pdf = digit.getProbabilities();
42  for (auto prob : pdf)
43  EXPECT_EQ(SVDRecoDigit::OutputProbType(1.0), prob);
44  EXPECT_EQ(100.0, digit.getChi2Ndf());
45  EXPECT_EQ(SVDModeByte::c_DefaultID, digit.getModeByte().getID());
46  EXPECT_EQ("0-suppr/global/6 samples/???", std::string(digit.getModeByte()));
47  }
48 
52  TEST(SVDRecoDigit, ConstructFromContainer)
53  {
54  // Create an arbitrary recodigit
55  VxdID sensorID(3, 4, 1);
56  short int cellID = 132;
57  SVDModeByte digitModeByte(151);
58  float init_charge = 23456;
59  float init_chargeErr = 1234;
60  float init_time = -16;
61  float init_timeErr = 3.21;
62  float init_chi2 = 2.34;
63 
64  std::vector<float> init_probs({0.0, 0.01, 0.10, 0.79, 0.06, 0.04});
65  SVDRecoDigit digit(sensorID, false, cellID, init_charge, init_chargeErr, init_time,
66  init_timeErr, init_probs, init_chi2, digitModeByte);
67  // Test getters
68  EXPECT_EQ(sensorID, digit.getSensorID());
69  EXPECT_FALSE(digit.isUStrip());
70  EXPECT_EQ(cellID, digit.getCellID());
71  EXPECT_EQ(init_charge, digit.getCharge());
72  EXPECT_EQ(init_chargeErr, digit.getAmplitudeError());
73  EXPECT_EQ(init_time, digit.getTime());
74  EXPECT_EQ(init_timeErr, digit.getTimeError());
75  const SVDRecoDigit::OutputProbArray pdf = digit.getProbabilities();
76  for (size_t ip = 0; ip < pdf.size(); ++ip)
77  EXPECT_LE(fabs(static_cast<SVDRecoDigit::OutputProbType>(init_probs[ip]) - pdf[ip]), 1.0 / SVDRecoDigit::storedProbArrayNorm);
78  // Also, norm must be 1
79  float outputNorm = std::accumulate(pdf.begin(), pdf.end(), 0.0);
80  EXPECT_LE(fabs(1.0 - outputNorm), 1.0e-6);
81  EXPECT_EQ(init_chi2, digit.getChi2Ndf());
82  EXPECT_EQ(digitModeByte, digit.getModeByte());
83  EXPECT_EQ("0-suppr/global/6 samples/???", std::string(digit.getModeByte()));
84  }
88  TEST(SVDRecoDigit, ToString)
89  {
90  // Create an arbitrary recodigit
91  VxdID sensorID(3, 4, 1);
92  short int cellID = 132;
93  SVDModeByte digitModeByte(151);
94  float init_charge = 23456;
95  float init_chargeErr = 1234;
96  float init_time = -16;
97  float init_timeErr = 3.21;
98  float init_chi2 = 2.34;
99 
100  std::vector<float> init_probs({0.0, 0.01, 0.10, 0.79, 0.06, 0.04});
101  SVDRecoDigit digit(sensorID, false, cellID, init_charge, init_chargeErr, init_time,
102  init_timeErr, init_probs, init_chi2, digitModeByte);
103  // Test getters
104  std::string
105  digitString("VXDID : 25632 = 3.4.1 strip: V-132 Amplitude: 23456 +/- 1234 Time: -16 +/- 3.21\n probabilities: 0 655 6553 51772 3932 2621 Chi2/ndf: 2.34 0-suppr/global/6 samples/???\n");
106  EXPECT_EQ(digitString, digit.toString());
107  }
108 
109  } // namespace SVD
111 } // namespace Belle2
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::SVDModeByte::c_DefaultID
static const baseType c_DefaultID
Default / non-informative id 10010111 = 151 Run type: zero-suppressed, 2 Event type: global run,...
Definition: SVDModeByte.h:116
Belle2::SVDRecoDigit::storedProbArrayNorm
static const uint16_t storedProbArrayNorm
some constant
Definition: SVDRecoDigit.h:62
Belle2::SVDModeByte
Class to store SVD mode information.
Definition: SVDModeByte.h:79
Belle2::SVDRecoDigit::OutputProbType
double OutputProbType
Type for output probability array.
Definition: SVDRecoDigit.h:67
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SVDRecoDigit
The SVD RecoDigit class.
Definition: SVDRecoDigit.h:54
Belle2::SVDRecoDigit::OutputProbArray
std::vector< OutputProbType > OutputProbArray
vector of OutProbType objects
Definition: SVDRecoDigit.h:68
Belle2::SVD::TEST
TEST(NNTimeFitter, DISABLED_CompareNetworkCoefficient)
Compare NN fitter parameter dump from Python with internal data representation in C++ to verify that ...
Definition: NNFitterTest.cc:37