Belle II Software development
SVDWaveform.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 <framework/dataobjects/RelationElement.h>
10#include <svd/simulation/SVDWaveform.h>
11#include <gtest/gtest.h>
12#include <iostream>
13#include <sstream>
14
15using namespace std;
16
17namespace Belle2 {
22 namespace SVD {
23
27 TEST(SVDWaveform, Getters)
28 {
29 // First create an artificial waveform and load it with data.
30 vector<double> charges;
31 charges.push_back(10);
32 charges.push_back(11);
33 charges.push_back(30);
34 vector<double> times;
35 for (int i = 0; i < 3; ++i) times.push_back(i * 15.0e-9);
36 vector<RelationElement::index_type> mcParticles;
37 for (int i = 0; i < 3; ++i) mcParticles.push_back(3 * i);
38 vector<RelationElement::index_type> trueHits;
39 for (int i = 0; i < 3; ++i) trueHits.push_back(7 * i);
40 const float tau = 25.0e-9;
41 SVDWaveform waveform;
42 for (int i = 0; i < 3; ++i) waveform.add(times.at(i), charges.at(i), tau, mcParticles.at(i), trueHits.at(i));
43 // Test SVDWaveform::getCharge()
44 double totalcharge = 0;
45 for (int i = 0; i < 3; ++i) totalcharge += charges.at(i);
46 EXPECT_EQ(waveform.getCharge(), totalcharge);
47 //Test SVDWaveform::getElementaryWaveforms()
49 for (int i = 0; i < 3; ++i) {
50 EXPECT_EQ(functions.at(i).m_initTime, times.at(i));
51 EXPECT_EQ(functions.at(i).m_charge, charges.at(i));
52 EXPECT_EQ(functions.at(i).m_tau, tau);
53 EXPECT_EQ(functions.at(i).m_particle, mcParticles.at(i));
54 EXPECT_EQ(functions.at(i).m_truehit, trueHits.at(i));
55 }
56 }
57
59 TEST(SVDWaveform, Constructors)
60 {
61 // Create an artificial waveform and load it with data.
62 vector<double> charges;
63 charges.push_back(10);
64 charges.push_back(11);
65 charges.push_back(30);
66 vector<double> times;
67 for (int i = 0; i < 3; ++i) times.push_back(i * 15.0e-9);
68 vector<RelationElement::index_type> mcParticles;
69 for (int i = 0; i < 3; ++i) mcParticles.push_back(3 * i);
70 vector<RelationElement::index_type> trueHits;
71 for (int i = 0; i < 3; ++i) trueHits.push_back(7 * i);
72 const float tau = 25.0e-9;
73 SVDWaveform waveform;
74 for (int i = 0; i < 3; ++i) waveform.add(times.at(i), charges.at(i), tau, mcParticles.at(i), trueHits.at(i));
75 // Test the copy constructor
76 SVDWaveform waveform2(waveform);
77 double totalcharge = 0;
78 for (int i = 0; i < 3; ++i) totalcharge += charges.at(i);
79 EXPECT_EQ(waveform2.getCharge(), totalcharge);
80 //Test SVDWaveform::getElementaryWaveforms()
82 size_t n = functions.size();
83 EXPECT_EQ(n, 3);
84 for (int i = 0; i < 3; ++i) {
85 EXPECT_EQ(functions.at(i).m_initTime, times.at(i));
86 EXPECT_EQ(functions.at(i).m_charge, charges.at(i));
87 EXPECT_EQ(functions.at(i).m_tau, tau);
88 EXPECT_EQ(functions.at(i).m_particle, mcParticles.at(i));
89 EXPECT_EQ(functions.at(i).m_truehit, trueHits.at(i));
90 }
91 }
92
94 TEST(SVDWaveform, Assignment)
95 {
96 // Create an artificial waveform and load it with data.
97 vector<double> charges;
98 charges.push_back(10);
99 charges.push_back(11);
100 charges.push_back(30);
101 vector<double> times;
102 for (int i = 0; i < 3; ++i) times.push_back(i * 15.0e-9);
103 vector<RelationElement::index_type> mcParticles;
104 for (int i = 0; i < 3; ++i) mcParticles.push_back(3 * i);
105 vector<RelationElement::index_type> trueHits;
106 for (int i = 0; i < 3; ++i) trueHits.push_back(7 * i);
107 const float tau = 25.0e-9;
108 SVDWaveform waveform;
109 for (int i = 0; i < 3; ++i) waveform.add(times.at(i), charges.at(i), tau, mcParticles.at(i), trueHits.at(i));
110 // Test the assignment operator
111 SVDWaveform waveform2 = waveform;
112 double totalcharge = 0;
113 for (int i = 0; i < 3; ++i) totalcharge += charges.at(i);
114 EXPECT_EQ(waveform2.getCharge(), totalcharge);
115 //Test SVDWaveform::getElementaryWaveforms()
117 for (int i = 0; i < 3; ++i) {
118 EXPECT_EQ(functions.at(i).m_initTime, times.at(i));
119 EXPECT_EQ(functions.at(i).m_charge, charges.at(i));
120 EXPECT_EQ(functions.at(i).m_tau, tau);
121 EXPECT_EQ(functions.at(i).m_particle, mcParticles.at(i));
122 EXPECT_EQ(functions.at(i).m_truehit, trueHits.at(i));
123 }
124 }
125
127 TEST(SVDWaveform, Waveform)
128 {
129 // Create an artificial waveform and load it with data.
130 vector<double> charges;
131 charges.push_back(10);
132 charges.push_back(11);
133 charges.push_back(30);
134 vector<double> times;
135 for (int i = 0; i < 3; ++i) times.push_back(i * 15.0e-9);
136 vector<RelationElement::index_type> mcParticles;
137 for (int i = 0; i < 3; ++i) mcParticles.push_back(3 * i);
138 vector<RelationElement::index_type> trueHits;
139 for (int i = 0; i < 3; ++i) trueHits.push_back(7 * i);
140 const float tau = 25.0e-9; // 25 ns shaping time
141 SVDWaveform waveform;
142 for (int i = 0; i < 3; ++i) waveform.add(times.at(i), charges.at(i), tau, mcParticles.at(i), trueHits.at(i));
143 // Test operator()
144 double time = 40.0e-9; // 40 ns
145 // expected function value
146 double expected_value = 0;
148 double value = waveform.waveform(time, wave);
149 expected_value += value;
150 }
151 double function_value = waveform(time);
152 EXPECT_EQ(function_value, expected_value);
153 }
154
156 TEST(SVDWaveform, toString)
157 {
158 // Create an artificial waveform and load it with data.
159 vector<double> charges;
160 charges.push_back(10);
161 charges.push_back(11);
162 charges.push_back(30);
163 vector<double> times;
164 for (int i = 0; i < 3; ++i) times.push_back(i * 15.0e-9);
165 vector<RelationElement::index_type> mcParticles;
166 for (int i = 0; i < 3; ++i) mcParticles.push_back(3 * i);
167 vector<RelationElement::index_type> trueHits;
168 for (int i = 0; i < 3; ++i) trueHits.push_back(7 * i);
169 const float tau = 50.0e-9; // 25 ns shaping time
170 SVDWaveform waveform;
171 for (int i = 0; i < 3; ++i) waveform.add(times.at(i), charges.at(i), tau, mcParticles.at(i), trueHits.at(i));
172 std::ostringstream os;
173 for (int i = 0; i < 3; ++i)
174 os << i + 1 << '\t' << times.at(i) << '\t' << charges.at(i) << '\t' << tau << std::endl;
175 EXPECT_EQ(waveform.toString(), os.str());
176 }
177
178 } // namespace SVD
180} // namespace Belle2
The SVD waveform class.
Definition: SVDWaveform.h:38
void add(double initTime, double charge, double tau, int particle=-1, int truehit=-1, WaveformShape wfun=w_betaprime)
Add a chargelet waveform to the total strip waveform.
Definition: SVDWaveform.h:106
std::string toString() const
Produce a string representation of the object.
Definition: SVDWaveform.h:186
std::deque< ElementaryWaveform > elementary_waveform_list
List of elementary waveforms.
Definition: SVDWaveform.h:77
double getCharge() const
Return the charge collected in the strip.
Definition: SVDWaveform.h:169
const elementary_waveform_list & getElementaryWaveforms() const
Return the list of waveform parameters.
Definition: SVDWaveform.h:174
double waveform(double t, double initTime, double charge, double tau, WaveformShape wfun=w_betaprime) const
Waveform shape.
Definition: SVDWaveform.h:138
Abstract base class for different kinds of events.
STL namespace.
Type to store elementary waveform parameters.
Definition: SVDWaveform.h:48