1
/* This file is part of MAUS: http:// micewww.pp.rl.ac.uk:8080/projects/maus
3
* MAUS is free software: you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation, either version 3 of the License, or
6
* (at your option) any later version.
8
* MAUS is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with MAUS. If not, see <http:// www.gnu.org/licenses/>.
27
#include "TLorentzVector.h"
30
#include "gtest/gtest.h"
31
#include "json/reader.h"
32
#include "json/value.h"
34
#include "Utils/Exception.hh"
35
#include "Utils/JsonWrapper.hh"
36
#include "DataStructure/Global/Track.hh"
37
#include "DataStructure/Global/TrackPoint.hh"
38
#include "src/common_cpp/Optics/OpticsModel.hh"
39
#include "src/common_cpp/Optics/CovarianceMatrix.hh"
40
#include "src/common_cpp/Optics/PhaseSpaceVector.hh"
41
#include "Recon/Global/DataStructureHelper.hh"
42
#include "Recon/Global/MinuitTrackFitter.hh"
43
#include "Recon/Global/Particle.hh"
45
namespace GlobalDS = MAUS::DataStructure::Global;
46
namespace Recon = MAUS::recon::global;
48
Json::Value SetupConfig(int verbose_level);
50
class DummyOpticsModel : public MAUS::OpticsModel {
52
explicit DummyOpticsModel(Json::Value const * const configuration)
53
: MAUS::OpticsModel(configuration) { }
55
MAUS::CovarianceMatrix Transport(const MAUS::CovarianceMatrix & covariances,
56
const double end_plane) const
58
MAUS::CovarianceMatrix Transport(const MAUS::CovarianceMatrix & covariances,
59
const double start_plane,
60
const double end_plane) const
62
MAUS::PhaseSpaceVector Transport(const MAUS::PhaseSpaceVector & vector,
63
const double end_plane) const
65
MAUS::PhaseSpaceVector Transport(const MAUS::PhaseSpaceVector & vector,
66
const double start_plane,
67
const double end_plane) const
71
class MinuitTrackFitterTest : public testing::Test, public TObject {
73
MinuitTrackFitterTest() {
74
for (int index = 0; index < 3; ++index) {
75
GlobalDS::TrackPoint * track_point = new GlobalDS::TrackPoint();
76
TLorentzVector four_position(kStartVector[2]+index, kStartVector[4]+index,
77
0.0, kStartVector[0]+index);
78
track_point->set_position(four_position);
79
TLorentzVector position_error(1.0, 1.0, 1.0, 1.0);
80
track_point->set_position_error(position_error);
82
TLorentzVector four_momentum(kStartVector[3]+index, kStartVector[5]+index,
83
280.7780432, kStartVector[1]+index);
84
track_point->set_momentum(four_momentum);
85
TLorentzVector momentum_error(1.0, 1.0, 1.0, 1.0);
86
track_point->set_momentum_error(momentum_error);
87
detector_events_.push_back(track_point);
91
~MinuitTrackFitterTest() {
92
for (int index = 0; index < 3; ++index) {
93
delete detector_events_[index];
98
static const std::string kConfigurationString;
99
static const Json::Value kConfiguration;
100
static const double kMuonMass;
101
static const Double_t kStartVector[6];
102
std::vector<const GlobalDS::TrackPoint *> detector_events_;
103
static const DummyOpticsModel kOpticsModel;
106
// *************************************************
107
// MinuitTrackFitterTest static const initializations
108
// *************************************************
110
const std::string MinuitTrackFitterTest::kConfigurationString = "{"
111
"\"global_recon_minuit_minimizer\":\"MINIMIZE\",\n"
112
"\"global_recon_minuit_max_iterations\":2000,\n"
113
"\"global_recon_minuit_max_edm\":1e-9,\n"
114
"\"global_recon_minuit_rounds\":7,\n"
115
"\"global_recon_minuit_parameters\":[\n"
116
"{\"name\":\"Time\", \"fixed\":false, \"initial_value\":0.,"
117
" \"value_step\":0.1, \"min_value\":-3.0, \"max_value\":3.0},\n"
118
"{\"name\":\"Energy\", \"fixed\":false, \"initial_value\":226.19,\n"
119
" \"value_step\":0.01, \"min_value\":250., \"max_value\":350.},\n"
120
"{\"name\":\"x\", \"fixed\":false, \"initial_value\":0.,\n"
121
" \"value_step\":0.1, \"min_value\":-15., \"max_value\":15.},\n"
122
"{\"name\":\"Px\", \"fixed\":false, \"initial_value\":0.,\n"
123
" \"value_step\":0.1, \"min_value\":-15., \"max_value\":15.},\n"
124
"{\"name\":\"y\", \"fixed\":false, \"initial_value\":0.,"
125
" \"value_step\":0.1, \"min_value\":-15., \"max_value\":15.},\n"
126
"{\"name\":\"Py\", \"fixed\":false, \"initial_value\":0.,"
127
" \"value_step\":0.1, \"min_value\":-15., \"max_value\":15.}"
131
const double MinuitTrackFitterTest::kMuonMass
132
= Recon::Particle::GetInstance().GetMass(GlobalDS::kMuMinus);
134
const Json::Value MinuitTrackFitterTest::kConfiguration
135
= JsonWrapper::StringToJson(kConfigurationString);
137
const DummyOpticsModel MinuitTrackFitterTest::kOpticsModel
138
= DummyOpticsModel(&kConfiguration);
140
const Double_t MinuitTrackFitterTest::kStartVector[6] = {
141
0.0, 300.0, 5.0, 7.0, 9.0, 11.0 };
147
TEST_F(MinuitTrackFitterTest, Constructor) {
150
Recon::MinuitTrackFitter fitter(&kOpticsModel, 0.);
151
} catch (MAUS::Exception exc) {
154
EXPECT_TRUE(success);
157
TEST_F(MinuitTrackFitterTest, ScoreTrack) {
158
Double_t score = Recon::MinuitTrackFitter::ScoreTrack(
163
// chi^2 = 6*0^2 + 6*1^2 + 6*2^2 = 30. (see init. of detector_events_)
164
EXPECT_NEAR(30.0, score, 1e-9);
167
TEST_F(MinuitTrackFitterTest, Fit) {
168
Recon::MinuitTrackFitter fitter(&kOpticsModel, 0.);
170
std::vector<const GlobalDS::TrackPoint *> raw_track_points;
171
GlobalDS::Track raw_track;
172
for (int index = 0; index < 3; ++index) {
173
GlobalDS::TrackPoint * track_point = new GlobalDS::TrackPoint();
174
TLorentzVector four_position(kStartVector[2]+index, kStartVector[4]+index,
175
0.0, kStartVector[0]+index);
176
track_point->set_position(four_position);
177
TLorentzVector position_error(1.0, 1.0, 1.0, 1.0);
178
track_point->set_position_error(position_error);
180
TLorentzVector four_momentum(kStartVector[3]+index, kStartVector[5]+index,
181
280.7780432, kStartVector[1]+index);
182
track_point->set_momentum(four_momentum);
183
TLorentzVector momentum_error(1.0, 1.0, 1.0, 1.0);
184
track_point->set_momentum_error(momentum_error);
186
raw_track_points.push_back(track_point);
187
raw_track.AddTrackPoint(track_point);
190
GlobalDS::Track fit_track;
191
fitter.Fit(&raw_track, &fit_track, "MinuitTrackFitterTest");
194
for (int index = 0; index < 3; ++index) {
195
delete raw_track_points[index];
198
std::vector<const GlobalDS::TrackPoint *> fit_track_points
199
= fit_track.GetTrackPoints();
200
ASSERT_EQ(size_t(4), fit_track_points.size());
202
const GlobalDS::TrackPoint * fit_primary_point = fit_track_points[0];
203
Recon::DataStructureHelper helper = Recon::DataStructureHelper::GetInstance();
204
MAUS::PhaseSpaceVector fit_primary_vector
205
= helper.TrackPoint2PhaseSpaceVector(*fit_primary_point);
207
/* Since the dummy optics model does identity transport, one would expect
208
* the fit to settle on the 2nd detector event given the way the
209
* detector events are defined
211
for (int index = 0; index < 6; ++index) {
212
EXPECT_NEAR(kStartVector[index]+1., fit_primary_vector[index], 1.e-6);