~christopher-hunt08/maus/maus_radiation_det

« back to all changes in this revision

Viewing changes to tests/cpp_unit/Simulation/MAUSSteppingActionTest.cc

  • Committer: Christopher Hunt
  • Date: 2013-12-18 13:10:32 UTC
  • Revision ID: christopher.hunt08@imperial.ac.uk-20131218131032-nu2rv09mgd2ezogx
Dark Current Simulation interfaced - First commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
  stepping->SetWillKeepSteps(false);
84
84
  EXPECT_EQ(stepping->GetWillKeepSteps(), false);
85
85
 
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() );
 
94
 
 
95
  delete steps;
91
96
}
92
97
 
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);
 
109
//
 
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);
 
119
 
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 );
104
130
 
105
 
  ASSERT_TRUE(tracking->GetTracks()[Json::Value::UInt(0)].isObject());
106
 
  EXPECT_EQ(tracking->GetTracks()[Json::Value::UInt(0)]["kill_reason"].type(),
107
 
                                                             Json::stringValue);
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(),
112
 
                                                             Json::stringValue);
 
134
  EXPECT_NE(tracking->GetTracks()->front().GetKillReason(), std::string( "" ) );
113
135
  EXPECT_EQ(track->GetTrackStatus(), fStopAndKill);
114
136
 
 
137
  delete tracking->GetTracks();
 
138
  delete stepping->GetSteps();
115
139
}
116
140
 
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));
 
153
 
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);
 
158
 
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);
 
164
 
 
165
  delete stepping->GetSteps();
130
166
}
 
167
 
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());
 
182
//
 
183
//  out = stepping->StepToJson(step, false);
 
184
//  EXPECT_DOUBLE_EQ(out["time"].asDouble(), post->GetGlobalTime());
 
185
//}
145
186
 
146
 
  out = stepping->StepToJson(step, false);
147
 
  EXPECT_DOUBLE_EQ(out["time"].asDouble(), post->GetGlobalTime());
148
 
}
149
187
G4Track* SetG4TrackAndStep(G4Step* step) {
150
188
  G4ParticleDefinition* pd =
151
189
                       G4ParticleTable::GetParticleTable()->FindParticle(-13);
184
222
  mod.setProperty<std::string>("MultiplePasses", "NewStation");
185
223
 
186
224
  VirtualPlaneManager* vpm = MAUSGeant4Manager::GetInstance()->GetVirtualPlanes();
187
 
  vpm->SetVirtualHits(Json::Value(Json::arrayValue));
 
225
  //vpm->SetVirtualHits(Json::Value(Json::arrayValue));
 
226
  vpm->SetVirtualHits( new VirtualHitArray );
188
227
  vpm->ConstructVirtualPlanes(NULL, &mod);
189
228
  vpm->ConstructVirtualPlanes(NULL, &mod);
190
229
 
194
233
 
195
234
  stepping->UserSteppingAction(step);
196
235
  stepping->UserSteppingAction(step);
197
 
  EXPECT_EQ(vpm->GetVirtualHits().size(), static_cast<unsigned int>(4));
 
236
  EXPECT_EQ(vpm->GetVirtualHits()->size(), (VirtualHitArray::size_type)4);
198
237
}
199
238
 
200
239
} //namespace end