Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticleUtils.cc
Go to the documentation of this file.
1 ///
2 /// @file ParticleUtils.cc
3 /// @brief PDG codes to UID functions
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++ -*-
13 #include "Hammer/Tools/Pdg.hh"
14 
15 #include <algorithm>
16 #include <boost/functional/hash.hpp>
17 
18 using namespace std;
19 
20 namespace Hammer {
21 
22  std::vector<PdgId> flipSigns(const std::vector<PdgId>& list) {
23  PID& pdg = PID::instance();
24  vector<PdgId> res = list;
25  for (auto& elem : res) {
26  //check to ensure particle is not self conjugate particle: isMeson return false for -ve pid self conj meson.
27  if( pdg.isMeson(elem) == pdg.isMeson(-elem) && elem != PID::PHOTON ){
28  elem *= -1;
29  }
30  }
31  return res;
32  }
33 
34  PdgId flipSign(const PdgId& id) {
35  PdgId res = id;
36  PID& pdg = PID::instance();
37  //check to ensure particle is not self conjugate meson: isMeson return false for -ve pid self conj meson.
38  if( pdg.isMeson(res) == pdg.isMeson(-res) && res != PID::PHOTON ){
39  res *= -1;
40  }
41  return res;
42  }
43 
44  std::vector<PdgId> combineDaughters(const std::vector<PdgId>& daughters, const std::vector<PdgId>& subDaughters) {
45  vector<PdgId> res = daughters;
46  sort(res.begin(), res.end(), &pdgSorter);
47  if (subDaughters.size() > 0) {
48  vector<PdgId> tmp = subDaughters;
49  sort(tmp.begin(), tmp.end(), &pdgSorter);
50  res.insert(res.end(), tmp.begin(), tmp.end());
51  }
52  return res;
53  }
54 
55  HashId processID(PdgId parent, const std::vector<PdgId>& allDaughters) {
56  HashId seed = 0ul;
57  boost::hash_combine(seed, static_cast<int>(parent));
58  for (auto elem : allDaughters) {
59  boost::hash_combine(seed, static_cast<int>(elem));
60  }
61  return seed;
62  }
63 
64  HashId combineProcessIDs(const std::set<HashId>& allIds) {
65  HashId seed = 0ul;
66  for(auto elem: allIds) {
67  boost::hash_combine(seed, elem);
68  }
69  return seed;
70  }
71 
72 
73  bool pdgSorter(PdgId a, PdgId b) {
74  if (abs(static_cast<int>(a)) != abs(static_cast<int>(b))) {
75  return (abs(static_cast<int>(a)) > abs(static_cast<int>(b)));
76  } else {
77  return (a > b);
78  }
79  }
80 
81  bool particlesByPdg(const std::function<PdgId(const Particle&)>& pdgGetter, const Particle& a, const Particle& b) {
82  PdgId aId = pdgGetter(a);
83  PdgId bId = pdgGetter(b);
84  return pdgSorter(aId, bId);
85  }
86 
87 } // namespace Hammer
PDG codes to UID functions.
bool isMeson(PdgId id) const
check whether a PDG code corresponds to a meson
Definition: Pdg.cc:558
std::vector< PdgId > combineDaughters(const std::vector< PdgId > &daughters, const std::vector< PdgId > &subDaughters)
combine list of codes of daughters and grandaughters (for processes which parameterise two subsequent...
bool particlesByPdg(const std::function< PdgId(const Particle &)> &pdgGetter, const Particle &a, const Particle &b)
checks whether two particles are ordered according to the PDG code ordering used in computing hashes ...
bool pdgSorter(PdgId a, PdgId b)
sorting function for PDG ids for computing hashes.
std::vector< PdgId > flipSigns(const std::vector< PdgId > &list)
return the PDG codes of the conjugate particles (itself if self-conjugate) for all the PDG codes in a...
HashId combineProcessIDs(const std::set< HashId > &allIds)
PdgId flipSign(const PdgId &id)
return the PDG code of the conjugate particle (itself if self-conjugate)
Particle class.
Definition: Particle.hh:30
Hammer class for dealing with particle data.
Definition: Pdg.hh:32
Hammer particle data class.
HashId processID(PdgId parent, const std::vector< PdgId > &allDaughters)
compute a unique ID for a given process based on the PDG codes of the parent particle and the ordered...
size_t HashId
Definition: IndexTypes.hh:31
int PdgId
Definition: Pdg.fhh:17