Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Units.cc
Go to the documentation of this file.
1 ///
2 /// @file Units.cc
3 /// @brief Unit conversion factors
4 ///
5 
6 //**** This file is a part of the HAMMER library
7 //**** Copyright (C) 2016 - 2020 The HAMMER Collaboration
8 //**** HAMMER is licensed under version 3 of the GPL; see COPYING for details
9 //**** Please note the MCnet academic guidelines; see GUIDELINES for details
10 
11 // -*- C++ -*-
12 #include "Hammer/Math/Units.hh"
13 #include "Hammer/Exceptions.hh"
14 #include "Hammer/Tools/Logging.hh"
15 
16 using namespace std;
17 
18 namespace Hammer {
19 
20  Units* Units::_theUnits = nullptr;
21 
22  Units* Units::getUnitsInstance() {
23  if(_theUnits == nullptr) {
24  _theUnits = new Units();
25  _theUnits->init();
26  }
27  return _theUnits;
28  }
29 
30  Units& Units::instance() {
31  return *Units::getUnitsInstance();
32  }
33 
34  void Units::init() {
35  _unitfactors.insert({"eV", eV});
36  _unitfactors.insert({"ev", eV});
37  _unitfactors.insert({"EV", eV});
38  _unitfactors.insert({"keV", keV});
39  _unitfactors.insert({"KeV", keV});
40  _unitfactors.insert({"KEV", keV});
41  _unitfactors.insert({"kev", keV});
42  _unitfactors.insert({"MeV", MeV});
43  _unitfactors.insert({"mev", MeV});
44  _unitfactors.insert({"MEV", MeV});
45  _unitfactors.insert({"GeV", GeV});
46  _unitfactors.insert({"GEV", GeV});
47  _unitfactors.insert({"gev", GeV});
48  _unitfactors.insert({"TeV", TeV});
49  _unitfactors.insert({"TEV", TeV});
50  _unitfactors.insert({"tev", TeV});
51  }
52 
53  double Units::getUnitsRescalingToMC(string mcunits, string localunits) const {
54  auto it = _unitfactors.find(mcunits);
55  auto it2 = _unitfactors.find(localunits);
56  if(it != _unitfactors.end() && it2 != _unitfactors.end()) {
57  return it2->second/it->second;
58  } else if (it == _unitfactors.end()) {
59  throw Error("Specified " + mcunits + " units not found. Mars Climate Orbiter would like a word.");
60  } else if (it2 == _unitfactors.end()) {
61  throw Error("Specified " + localunits + " units not found. Sometimes the bull wins.");
62  }
63  return 1.;
64  }
65 
66 } // namespace Hammer
static constexpr double MeV
Definition: Units.hh:23
Hammer class for dealing with units.
Definition: Units.hh:38
Message logging routines.
Hammer exception definitions.
Unit conversion factors.
static constexpr double GeV
Definition: Units.hh:25
Generic error class.
Definition: Exceptions.hh:23
static const double eV
Definition: Units.hh:19
static const double TeV
Definition: Units.hh:27
static const double keV
Definition: Units.hh:21