83
83
stepping->SetWillKeepSteps(false);
84
84
EXPECT_EQ(stepping->GetWillKeepSteps(), false);
86
EXPECT_THROW(stepping->SetSteps(Json::Value(Json::objectValue)), Squeal);
87
Json::Value array(Json::arrayValue);
88
array.append(Json::Value("Hello"));
89
EXPECT_NO_THROW(stepping->SetSteps(array));
90
EXPECT_EQ(array, stepping->GetSteps());
86
// EXPECT_THROW(stepping->SetSteps(Json::Value(Json::objectValue)), Squeal);
87
// Json::Value array(Json::arrayValue);
88
// array.append(Json::Value("Hello"));
89
// EXPECT_NO_THROW(stepping->SetSteps(array));
90
// EXPECT_EQ(array, stepping->GetSteps());
91
StepArray* steps = new StepArray;
92
stepping->SetSteps( steps );
93
EXPECT_EQ(steps, stepping->GetSteps() );
93
98
// test that we set stop and kill if stepping goes more than max n steps
94
99
TEST_F(MAUSSteppingActionTest, UserSteppingActionMaxNStepsTest) {
100
// Json::Value& conf = *MICERun::getInstance()->jsonConfiguration;
101
// int maxNSteps = JsonWrapper::GetProperty
102
// (conf, "maximum_number_of_steps", JsonWrapper::intValue).asInt();
103
// MAUSTrackingAction* tracking = MAUSGeant4Manager::GetInstance()->GetTracking();
104
// tracking->SetWillKeepTracks(true);
105
// tracking->SetTracks(Json::Value(Json::arrayValue));
106
// tracking->PreUserTrackingAction(step->GetTrack());
107
// stepping->SetSteps(Json::Value(Json::arrayValue));
108
// stepping->UserSteppingAction(step);
110
// ASSERT_TRUE(tracking->GetTracks()[Json::Value::UInt(0)].isObject());
111
// EXPECT_EQ(tracking->GetTracks()[Json::Value::UInt(0)]["kill_reason"].type(),
112
// Json::stringValue);
113
// for (int i = 0; i < maxNSteps+1; ++i)
114
// track->IncrementCurrentStepNumber();
115
// stepping->UserSteppingAction(step);
116
// EXPECT_EQ(tracking->GetTracks()[Json::Value::UInt(0)]["kill_reason"].type(),
117
// Json::stringValue);
118
// EXPECT_EQ(track->GetTrackStatus(), fStopAndKill);
95
120
Json::Value& conf = *MICERun::getInstance()->jsonConfiguration;
96
121
int maxNSteps = JsonWrapper::GetProperty
97
122
(conf, "maximum_number_of_steps", JsonWrapper::intValue).asInt();
98
123
MAUSTrackingAction* tracking = MAUSGeant4Manager::GetInstance()->GetTracking();
99
124
tracking->SetWillKeepTracks(true);
100
tracking->SetTracks(Json::Value(Json::arrayValue));
125
tracking->SetTracks( new TrackArray );
101
126
tracking->PreUserTrackingAction(step->GetTrack());
102
stepping->SetSteps(Json::Value(Json::arrayValue));
127
stepping->SetSteps( new StepArray );
103
128
stepping->UserSteppingAction(step);
129
EXPECT_NE( tracking->GetTracks(), (TrackArray*)NULL );
105
ASSERT_TRUE(tracking->GetTracks()[Json::Value::UInt(0)].isObject());
106
EXPECT_EQ(tracking->GetTracks()[Json::Value::UInt(0)]["kill_reason"].type(),
108
131
for (int i = 0; i < maxNSteps+1; ++i)
109
132
track->IncrementCurrentStepNumber();
110
133
stepping->UserSteppingAction(step);
111
EXPECT_EQ(tracking->GetTracks()[Json::Value::UInt(0)]["kill_reason"].type(),
134
EXPECT_NE(tracking->GetTracks()->front().GetKillReason(), std::string( "" ) );
113
135
EXPECT_EQ(track->GetTrackStatus(), fStopAndKill);
137
delete tracking->GetTracks();
138
delete stepping->GetSteps();
117
141
// test that we write steps correctly on each step (or not if flag is false)
118
142
TEST_F(MAUSSteppingActionTest, UserSteppingActionWriteStepsTest) {
119
stepping->SetSteps(Json::Value(Json::arrayValue));
143
// stepping->SetWillKeepSteps(false);
144
// stepping->SetSteps(Json::Value(Json::arrayValue));
145
// stepping->UserSteppingAction(step);
146
// EXPECT_EQ(stepping->GetSteps()[Json::UInt(0)].type(), Json::nullValue);
147
// stepping->SetWillKeepSteps(true);
148
// stepping->UserSteppingAction(step);
149
// stepping->UserSteppingAction(step);
150
// ASSERT_EQ(stepping->GetSteps().type(), Json::arrayValue);
151
// // we want 3 steps - 2 post steps plus the first one
152
// EXPECT_EQ(stepping->GetSteps().size(), static_cast<unsigned int>(3));
120
154
stepping->SetWillKeepSteps(false);
121
stepping->SetSteps(Json::Value(Json::arrayValue));
155
stepping->SetSteps( new StepArray );
122
156
stepping->UserSteppingAction(step);
123
EXPECT_EQ(stepping->GetSteps()[Json::UInt(0)].type(), Json::nullValue);
157
EXPECT_EQ(stepping->GetSteps()->size(), (StepArray::size_type) 0);
124
159
stepping->SetWillKeepSteps(true);
125
160
stepping->UserSteppingAction(step);
126
161
stepping->UserSteppingAction(step);
127
ASSERT_EQ(stepping->GetSteps().type(), Json::arrayValue);
128
162
// we want 3 steps - 2 post steps plus the first one
129
EXPECT_EQ(stepping->GetSteps().size(), static_cast<unsigned int>(3));
163
EXPECT_EQ(stepping->GetSteps()->size(), (StepArray::size_type) 3);
165
delete stepping->GetSteps();
131
168
// test that we write to json correctly
132
TEST_F(MAUSSteppingActionTest, StepToJsonTest) {
133
Json::Value out = stepping->StepToJson(step, true);
134
EXPECT_DOUBLE_EQ(out["position"]["x"].asDouble(), point->GetPosition().x());
135
EXPECT_DOUBLE_EQ(out["position"]["y"].asDouble(), point->GetPosition().y());
136
EXPECT_DOUBLE_EQ(out["position"]["z"].asDouble(), point->GetPosition().z());
137
EXPECT_DOUBLE_EQ(out["momentum"]["x"].asDouble(), point->GetMomentum().x());
138
EXPECT_DOUBLE_EQ(out["momentum"]["y"].asDouble(), point->GetMomentum().y());
139
EXPECT_DOUBLE_EQ(out["momentum"]["z"].asDouble(), point->GetMomentum().z());
140
EXPECT_DOUBLE_EQ(out["energy_deposited"].asDouble(), 8.);
141
EXPECT_DOUBLE_EQ(out["energy"].asDouble(), point->GetTotalEnergy());
142
EXPECT_DOUBLE_EQ(out["time"].asDouble(), point->GetGlobalTime());
143
EXPECT_DOUBLE_EQ(out["proper_time"].asDouble(), point->GetProperTime());
144
EXPECT_DOUBLE_EQ(out["path_length"].asDouble(), track->GetTrackLength());
169
//TEST_F(MAUSSteppingActionTest, StepToJsonTest) {
170
// Json::Value out = stepping->StepToJson(step, true);
171
// EXPECT_DOUBLE_EQ(out["position"]["x"].asDouble(), point->GetPosition().x());
172
// EXPECT_DOUBLE_EQ(out["position"]["y"].asDouble(), point->GetPosition().y());
173
// EXPECT_DOUBLE_EQ(out["position"]["z"].asDouble(), point->GetPosition().z());
174
// EXPECT_DOUBLE_EQ(out["momentum"]["x"].asDouble(), point->GetMomentum().x());
175
// EXPECT_DOUBLE_EQ(out["momentum"]["y"].asDouble(), point->GetMomentum().y());
176
// EXPECT_DOUBLE_EQ(out["momentum"]["z"].asDouble(), point->GetMomentum().z());
177
// EXPECT_DOUBLE_EQ(out["energy_deposited"].asDouble(), 8.);
178
// EXPECT_DOUBLE_EQ(out["energy"].asDouble(), point->GetTotalEnergy());
179
// EXPECT_DOUBLE_EQ(out["time"].asDouble(), point->GetGlobalTime());
180
// EXPECT_DOUBLE_EQ(out["proper_time"].asDouble(), point->GetProperTime());
181
// EXPECT_DOUBLE_EQ(out["path_length"].asDouble(), track->GetTrackLength());
183
// out = stepping->StepToJson(step, false);
184
// EXPECT_DOUBLE_EQ(out["time"].asDouble(), post->GetGlobalTime());
146
out = stepping->StepToJson(step, false);
147
EXPECT_DOUBLE_EQ(out["time"].asDouble(), post->GetGlobalTime());
149
187
G4Track* SetG4TrackAndStep(G4Step* step) {
150
188
G4ParticleDefinition* pd =
151
189
G4ParticleTable::GetParticleTable()->FindParticle(-13);