StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testUnits.cc
1 //
2 // Test Units
3 //
4 #include <iostream>
5 
6 #include "HepMC/Units.h"
7 
8 int main()
9 {
10 
11  int err = 0;
12  double cf;
13 
14  std::cout << "Default units: " << HepMC::Units::name(HepMC::Units::default_momentum_unit())
15  << " " << HepMC::Units::name(HepMC::Units::default_length_unit()) << std::endl;
16 
17  // check momentum conversion factors
18  cf = conversion_factor( HepMC::Units::GEV, HepMC::Units::GEV );
19  if( cf != 1 ) {
20  ++err;
21  std::cerr << "wrong conversion factor " << cf
22  << " for GEV to GEV - should be 1 \n";
23  }
24  cf = conversion_factor( HepMC::Units::MEV, HepMC::Units::MEV );
25  if( cf != 1 ) {
26  ++err;
27  std::cerr << "wrong conversion factor " << cf
28  << " for MEV to MEV - should be 1 \n";
29  }
30  cf = conversion_factor( HepMC::Units::MEV, HepMC::Units::GEV );
31  if( cf != 0.001 ) {
32  ++err;
33  std::cerr << "wrong conversion factor " << cf
34  << " for MEV to GEV - should be 0.001 \n";
35  }
36  cf = conversion_factor( HepMC::Units::GEV, HepMC::Units::MEV );
37  if( cf != 1000.0 ) {
38  ++err;
39  std::cerr << "wrong conversion factor " << cf
40  << " for GEV to MEV - should be 1000 \n";
41  }
42 
43  // check length conversion factors
44  cf = conversion_factor( HepMC::Units::MM, HepMC::Units::MM );
45  if( cf != 1 ) {
46  ++err;
47  std::cerr << "wrong conversion factor " << cf
48  << " for MM to MM - should be 1 \n";
49  }
50  cf = conversion_factor( HepMC::Units::CM, HepMC::Units::CM );
51  if( cf != 1 ) {
52  ++err;
53  std::cerr << "wrong conversion factor " << cf
54  << " for CM to CM - should be 1 \n";
55  }
56  cf = conversion_factor( HepMC::Units::CM, HepMC::Units::MM );
57  if( cf != 10.0 ) {
58  ++err;
59  std::cerr << "wrong conversion factor " << cf
60  << " for CM to MM - should be 10 \n";
61  }
62  cf = conversion_factor( HepMC::Units::MM, HepMC::Units::CM );
63  if( cf != 0.1 ) {
64  ++err;
65  std::cerr << "wrong conversion factor " << cf
66  << " for MM to CM - should be 0.1 \n";
67  }
68 
69  return err;
70 }