HepMC3 event record library
testFourVector.cc
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2021 The HepMC collaboration (see AUTHORS for details)
5//
6#include <iostream>
7#include <fstream>
8#include <vector>
9#include "HepMC3/FourVector.h"
10#include "HepMC3/PrintStreams.h"
11#undef NDEBUG
12#include <assert.h>
13using namespace HepMC3;
14int main()
15{
16 std::vector<FourVector> vectors_to_test{
17 FourVector(0.0, 0.0, 0.0, 0.0),
18 FourVector(1.0, 2.0, 0.0, 0.0),
19 FourVector(0.0, 0.0, 0.0, 1.0),
20 FourVector(0.0, 0.0, 0.0,-1.0),
21 FourVector(0.0, 0.0, 1.0, 0.0),
22 FourVector(0.0, 0.0,-1.0, 0.0),
23 FourVector(1.0, 2.0, 3.0, 4.0),
24 FourVector(1.0, 2.0, 3.0, -4.0),
25 FourVector(1.0, 2.0, -3.0, 4.0),
26 FourVector(1.0, 2.0, -3.0, -4.0),
27 FourVector(1.0, 2.0, -3.0, 40.0),
28 FourVector(1.0, 2.0, -3.0, -40.0)
29 };
30 std::vector<double> correct_eta{
31 0.0,
32 0.0,
33 0.0,
34 0.0,
35 std::numeric_limits<double>::infinity(),
36 -std::numeric_limits<double>::infinity(),
37 /*
38 std::numeric_limits<double>::max(),
39 -std::numeric_limits<double>::max(),
40 */
41 std::log((std::sqrt(1.0*1.0 + 2.0*2.0 + 3.0*3.0) + 3.0) / (std::sqrt(1.0*1.0 + 2.0*2.0 + 3.0*3.0) - 3.0))*0.5,
42 std::log((std::sqrt(1.0*1.0 + 2.0*2.0 + 3.0*3.0) + 3.0) / (std::sqrt(1.0*1.0 + 2.0*2.0 + 3.0*3.0) - 3.0))*0.5,
43 std::log((std::sqrt(1.0*1.0 + 2.0*2.0 + 3.0*3.0) - 3.0) / (std::sqrt(1.0*1.0 + 2.0*2.0 + 3.0*3.0) + 3.0))*0.5,
44 std::log((std::sqrt(1.0*1.0 + 2.0*2.0 + 3.0*3.0) - 3.0) / (std::sqrt(1.0*1.0 + 2.0*2.0 + 3.0*3.0) + 3.0))*0.5,
45 std::log((std::sqrt(1.0*1.0 + 2.0*2.0 + 3.0*3.0) - 3.0) / (std::sqrt(1.0*1.0 + 2.0*2.0 + 3.0*3.0) + 3.0))*0.5,
46 std::log((std::sqrt(1.0*1.0 + 2.0*2.0 + 3.0*3.0) - 3.0) / (std::sqrt(1.0*1.0 + 2.0*2.0 + 3.0*3.0) + 3.0))*0.5
47 };
48
49 std::vector<double> correct_rap{
50 0.0,
51 0.0,
52 0.0,
53 0.0,
54 0.0,
55 0.0,
56 std::log((4.0 + 3.0) / (4.0 - 3.0))*0.5,
57 std::log((-4.0 + 3.0) / (-4.0 - 3.0))*0.5,
58 std::log((4.0 - 3.0) / (4.0 + 3.0))*0.5,
59 std::log((-4.0 - 3.0) / (-4.0 + 3.0))*0.5,
60 std::log((40.0 - 3.0) / (40.0 + 3.0))*0.5,
61 std::log((-40.0 - 3.0) / (-40.0 + 3.0))*0.5
62
63 };
64 cout.setf(ios_base::scientific);
65 cout.precision(10);
66 cout.width(15);
67 cout.setf(std::ios_base::showpos);
68 for (size_t i = 0; i < vectors_to_test.size(); i++) {
69 std::cout << " eta() = " << vectors_to_test.at(i).eta() << " rap()=" << vectors_to_test.at(i).rap() << " for " << vectors_to_test.at(i) << std::endl;
70 std::cout << " Correct eta() = " << correct_eta.at(i) << " Correct rap()=" << correct_rap.at(i) << std::endl << std::endl;
71 }
72 for (size_t i=0; i<vectors_to_test.size(); i++)
73 {
74 std::cout << "Testing " << vectors_to_test.at(i) << std::endl;
75 assert(vectors_to_test.at(i).eta() == correct_eta.at(i) );
76 assert(vectors_to_test.at(i).rap() == correct_rap.at(i) );
77
78 }
79 return 0;
80}
Definition of class FourVector.
Implementation of ostreams for the objects.
Generic 4-vector.
Definition: FourVector.h:36
double eta() const
Pseudorapidity.
Definition: FourVector.h:174
HepMC3 main namespace.