rivet is hosted by Hepforge, IPPP Durham
ParticleName.cc
Go to the documentation of this file.
00001 #include "Rivet/Tools/ParticleName.hh"
00002 #include "Rivet/Tools/Utils.hh"
00003 
00004 namespace Rivet {
00005 
00006   namespace PID {
00007 
00008 
00009     // Initialise ParticleNames singleton pointer
00010     unique_ptr<ParticleNames> ParticleNames::_instance = nullptr;
00011 
00012 
00013     const std::string& ParticleNames::_particleName(PdgId pid) {
00014       if (_ids_names.find(pid) == _ids_names.end()) {
00015         throw PidError("Particle ID '" + lexical_cast<string>(pid) + "' not known.");
00016       }
00017       return _ids_names[pid];
00018     }
00019 
00020 
00021     PdgId ParticleNames::_particleId(const std::string& pname) {
00022       if (_names_ids.find(pname) == _names_ids.end()) {
00023         if (toUpper(pname) == "P+" || toUpper(pname) == "P") return PROTON;
00024         if (toUpper(pname) == "P-" || toUpper(pname) == "PBAR") return ANTIPROTON;
00025         if (toUpper(pname) == "E-") return ELECTRON;
00026         if (toUpper(pname) == "E+") return POSITRON;
00027         if (toUpper(pname) == "GAMMA") return PHOTON;
00028         if (toUpper(pname) == "N") return NEUTRON;
00029         try {
00030           PdgId rtn = lexical_cast<PdgId>(pname);
00031           return rtn;
00032         } catch (const bad_lexical_cast& blc) {
00033           throw PidError("Particle name '" + pname + "' not known and could not be directly cast to a PDG ID.");
00034         }
00035       }
00036       return _names_ids[pname];
00037     }
00038 
00039 
00040   }
00041 
00042 }