/* This file is part of MAUS: http:// micewww.pp.rl.ac.uk:8080/projects/maus
*
* MAUS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MAUS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MAUS. If not, see .
*/
#include "gtest/gtest.h"
#include "Geant4/G4Step.hh"
#include "Geant4/G4ParticleTable.hh"
#include "Geant4/G4Material.hh"
#include "Geant4/G4GRSVolume.hh"
#include "Geant4/G4RotationMatrix.hh"
#include "Geant4/G4ThreeVector.hh"
#include "Geant4/G4PVPlacement.hh"
#include "src/common_cpp/Utils/JsonWrapper.hh"
#include "src/common_cpp/Simulation/MAUSGeant4Manager.hh"
#include "src/common_cpp/Simulation/MAUSSteppingAction.hh"
#include "src/common_cpp/Simulation/VirtualPlanes.hh"
#include "src/legacy/Interface/MICERun.hh"
using namespace MAUS;
namespace {
class MAUSSteppingActionTest : public ::testing::Test {
protected:
MAUSSteppingActionTest() : stepping(MAUSGeant4Manager::GetInstance()->GetStepping()) {
stepping->SetSteps(new std::vector());
G4ParticleDefinition* pd =
G4ParticleTable::GetParticleTable()->FindParticle(-13);
G4DynamicParticle* dyn =
new G4DynamicParticle(pd, G4ThreeVector(1., 2., 3.));
track = new G4Track(dyn, 7., G4ThreeVector(4., 5., 6.));
step = new G4Step(); // memory leak?
point = new G4StepPoint();
point->SetPosition(G4ThreeVector(1., 2., 3.));
point->SetMass(pd->GetPDGMass());
point->SetMomentumDirection(G4ThreeVector(0., ::sqrt(0.5), ::sqrt(0.5)));
point->SetKineticEnergy(100.);
post = new G4StepPoint();
post->SetPosition(G4ThreeVector(7., 8., 9.));
post->SetMass(pd->GetPDGMass());
post->SetMomentumDirection(G4ThreeVector(::sqrt(1./3.), ::sqrt(1./3.), ::sqrt(1./3.)));
post->SetKineticEnergy(110.);
post->SetGlobalTime(-10.);
track->SetStep(step);
step->SetTrack(track);
step->SetPreStepPoint(point);
step->SetPostStepPoint(post);
track->AddTrackLength(10.);
step->SetTotalEnergyDeposit(8.);
point->SetGlobalTime(1.);
point->SetProperTime(2.);
point->SetPosition(G4ThreeVector(2.,3.,4.));
point->SetMomentumDirection(G4ThreeVector(1.,2.,3.));
point->SetKineticEnergy(9.);
}
virtual ~MAUSSteppingActionTest() {}
virtual void SetUp() {}
virtual void TearDown() {}
MAUS::MAUSSteppingAction* stepping;
G4Track* track;
G4Step* step;
G4StepPoint* point;
G4StepPoint* post;
};
// test get and set work correctly
TEST_F(MAUSSteppingActionTest, GetSetTest) {
stepping->SetWillKeepSteps(true);
EXPECT_EQ(stepping->GetWillKeepSteps(), true);
stepping->SetWillKeepSteps(false);
EXPECT_EQ(stepping->GetWillKeepSteps(), false);
std::vector* steps = new std::vector();
EXPECT_NO_THROW(stepping->SetSteps(steps));
EXPECT_EQ(steps, stepping->GetSteps());
}
// test that we set stop and kill if stepping goes more than max n steps
// check that the kill reason is filled with something
TEST_F(MAUSSteppingActionTest, UserSteppingActionMaxNStepsTest) {
Json::Value& conf = *MICERun::getInstance()->jsonConfiguration;
int maxNSteps = JsonWrapper::GetProperty
(conf, "maximum_number_of_steps", JsonWrapper::intValue).asInt();
MAUSTrackingAction* tracking = MAUSGeant4Manager::GetInstance()->GetTracking();
tracking->SetWillKeepTracks(true);
tracking->SetTracks(new std::vector