testParticle.cc
Go to the documentation of this file.
1 
13 #include <string>
14 #include <cmath>
15 
16 #include <utl/Particle.h>
17 #include <utl/CoordinateSystem.h>
18 #include <utl/TimeInterval.h>
19 #include <utl/AugerUnits.h>
20 #include <utl/PhysicalConstants.h>
21 #include <utl/Math.h>
22 
23 #include <tst/Verify.h>
24 #include <cppunit/extensions/HelperMacros.h>
25 
26 using namespace utl;
27 using namespace std;
28 using namespace tst;
29 
34  : public CppUnit::TestFixture
35 {
36  CPPUNIT_TEST_SUITE(testParticle);
37  CPPUNIT_TEST(testProperties);
38  CPPUNIT_TEST(testMomentum);
39  // CPPUNIT_TEST(testFN);
40  // CPPUNIT_TEST_EXCEPTION(testFN, anException);
41  CPPUNIT_TEST_SUITE_END();
42 public:
43  // shared data for tests
44 
45  void setUp() { }
46 
47  void tearDown() { }
48 
50  {
51  CoordinateSystemPtr cs = CoordinateSystem::GetRootCoordinateSystem();
52  Point pos(0, 0, 0, cs);
53  Vector dir(0, 0, 0, cs);
54  TimeInterval t;
55 
56  Particle p1(Particle::eElectron, Particle::eShower, pos, dir, t, 0, 0);
57  CPPUNIT_ASSERT(Verify<Equal>(p1.GetType(), int(Particle::eElectron)));
58  CPPUNIT_ASSERT(Verify<Equal>(p1.GetName(), string("e-")));
59  CPPUNIT_ASSERT(Verify<Equal>(p1.GetMass(), kElectronMass));
60  }
61 
62  void testMomentum()
63  {
64  CoordinateSystemPtr cs = CoordinateSystem::GetRootCoordinateSystem();
65  Point pos(0, 0, 0, cs);
66  Vector p(0, 1*MeV, 0, cs);
67  Vector dir(p);
68  dir.Normalize();
69  TimeInterval t;
70 
71  Particle p1(Particle::ePhoton, Particle::eShower, pos, p, t, 0);
72  CPPUNIT_ASSERT(Verify<Equal>(p1.GetType(), int(Particle::ePhoton)));
73  CPPUNIT_ASSERT(Verify<Equal>(p1.GetName(), string("gamma")));
74  CPPUNIT_ASSERT(Verify<Equal>(p1.GetMass(), 0.));
75  CPPUNIT_ASSERT(Verify<CloseTo>(p1.GetKineticEnergy(), 1.*MeV));
76  CPPUNIT_ASSERT(Verify<CloseTo>(p1.GetTotalEnergy(), 1.*MeV));
77 
78  Particle p2(Particle::eProton, Particle::eShower, pos, p, t, 0);
79  CPPUNIT_ASSERT(Verify<Equal>(p2.GetType(), int(Particle::eProton)));
80  CPPUNIT_ASSERT(Verify<Equal>(p2.GetName(), string("proton")));
81  CPPUNIT_ASSERT(Verify<Equal>(p2.GetMass(), kProtonMass));
82  CPPUNIT_ASSERT(Verify<CloseTo>(p2.GetKineticEnergy(),
83  sqrt(Sqr(1.*MeV) + Sqr(p2.GetMass()))-p2.GetMass()));
84  CPPUNIT_ASSERT(Verify<CloseTo>(p2.GetTotalEnergy() - p2.GetKineticEnergy(),
85  p2.GetMass()));
86 
87  Vector p1000(1e3*p);
88  p2.SetMomentum(p1000);
89  CPPUNIT_ASSERT(Verify<CloseTo>(p1000.GetCoordinates(cs),
90  p2.GetMomentum().GetCoordinates(cs)));
91  CPPUNIT_ASSERT(Verify<CloseTo>(dir.GetCoordinates(cs),
92  p2.GetDirection().GetCoordinates(cs)));
93  CPPUNIT_ASSERT(Verify<CloseTo>(p2.GetKineticEnergy(),
94  sqrt(Sqr(1.*GeV) + Sqr(p2.GetMass()))-p2.GetMass()));
95  }
96 
97 };
98 
99 
101 
102 
103 // Configure (x)emacs for this file ...
104 // Local Variables:
105 // mode: c++
106 // compile-command: "make -C .. -k testParticles && ../testParticles"
107 // End:
void Normalize()
Definition: Vector.h:64
constexpr T Sqr(const T &x)
Point object.
Definition: Point.h:32
constexpr double kProtonMass
constexpr double kElectronMass
std::string GetName() const
string with particle name
Definition: Particle.h:104
Describes a particle for Simulation.
Definition: Particle.h:26
void SetMomentum(const utl::Vector &momentum)
Definition: Particle.cc:65
void testMomentum()
Definition: testParticle.cc:62
void testProperties()
Definition: testParticle.cc:49
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
constexpr double MeV
Definition: AugerUnits.h:184
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
double GetKineticEnergy() const
Get kinetic energy of the particle.
Definition: Particle.h:130
double GetTotalEnergy() const
Get Total (relativistic) energy.
Definition: Particle.h:136
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
constexpr double GeV
Definition: AugerUnits.h:187
double GetMass() const
Mass of the particle.
Definition: Particle.h:142
Vector object.
Definition: Vector.h:30
int GetType() const
Definition: Particle.h:101
void tearDown()
Definition: testParticle.cc:47
const Vector & GetDirection() const
Unit vector giving particle direction.
Definition: Particle.h:114
Vector GetMomentum() const
Vector giving particle momentum.
Definition: Particle.cc:55

, generated on Tue Sep 26 2023.