Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticleData.cc
Go to the documentation of this file.
1 ///
2 /// @file ParticleData.cc
3 /// @brief Hammer decay PDG code management
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 <algorithm>
13 #include <iterator>
14 #include <iostream>
15 
16 #include <boost/functional/hash.hpp>
17 
20 #include "Hammer/Tools/Pdg.hh"
21 #include "Hammer/Tools/Pdg.hh"
22 
23 using namespace std;
24 
25 namespace Hammer {
26 
27  ParticleData::ParticleData() {
28  _signatureIndex = 0ul;
29  }
30 
31  ParticleData::~ParticleData() {
32  _signatures.clear();
33  _signatureIndex = 0ul;
34  }
35 
36  HashId ParticleData::id() const {
37  return _signatures[_signatureIndex].id;
38  }
39 
40  HashId ParticleData::hadronicId() const {
41  return _signatures[_signatureIndex].hadronicId;
42  }
43 
44  const vector<double>& ParticleData::masses() const {
45  return _signatures[_signatureIndex].masses;
46  }
47 
48  bool ParticleData::checkValidSignature(PdgId parent, const vector<PdgId>& daughters,
49  const vector<PdgId>& granddaughters) {
50  vector<PdgId> flippedDaughters;
51  vector<PdgId> flippedGrandDaughters;
52  flippedDaughters.reserve(daughters.size());
53  flippedGrandDaughters.reserve(granddaughters.size());
54  transform(daughters.begin(),daughters.end(),back_inserter(flippedDaughters), [parent](PdgId id) -> PdgId { return (parent > 0) ? id : flipSign(id); });
55  transform(granddaughters.begin(),granddaughters.end(),back_inserter(flippedGrandDaughters), [parent](PdgId id) -> PdgId { return (parent > 0) ? id : flipSign(id); });
56  auto result1 = daughters;
57  result1.reserve(daughters.size() + granddaughters.size());
58  result1.insert(result1.end(), granddaughters.begin(), granddaughters.end());
59  auto result2 = combineDaughters(flippedDaughters, flippedGrandDaughters);
60  transform(result2.begin(),result2.end(), result2.begin(),[parent](PdgId id) -> PdgId { return (parent > 0) ? id : flipSign(id);});
61  return equal(result1.begin(),result1.end(),result2.begin());
62  }
63 
64  void ParticleData::addProcessSignature(PdgId parent, const vector<PdgId>& daughters,
65  const vector<PdgId>& granddaughters) {
66  ASSERT_MSG(checkValidSignature(parent, daughters, granddaughters),
67  "Particle order does not respect Hammer Convention in addProcessSignature. Shame on you!");
68  Signature newsig;
69  newsig.parent = parent;
70  newsig.daughters = combineDaughters(daughters, granddaughters); //ordered by abs, for unique HashId
71  newsig.calcIds(daughters.size());
72  newsig.masses.clear();
73  newsig.addMass(parent); //masses added in the order within addProcessSignature
74  newsig.addMasses(daughters);
75  newsig.addMasses(granddaughters);
76  _signatures.push_back(newsig);
77  }
78 
79  void ParticleData::Signature::calcIds(size_t numDaughters) {
80  id = processID(parent, daughters);
81  vector<PdgId> hadDaughters;
82  copy_n(daughters.begin(), numDaughters, back_inserter(hadDaughters));
83  hadDaughters.erase(remove_if(hadDaughters.begin(), hadDaughters.end(), [](PdgId idx){ return (abs(idx) < 100); }),
84  hadDaughters.end());
85  hadronicId = processID(parent, hadDaughters);
86  }
87 
88  void ParticleData::Signature::addMass(PdgId idx) {
89  PID& pdg = PID::instance();
90  masses.push_back(pdg.getMass(idx));
91  }
92 
93  void ParticleData::Signature::addMasses(const vector<PdgId>& ids) {
94  PID& pdg = PID::instance();
95  for(auto elem: ids) {
96  masses.push_back(pdg.getMass(elem));
97  }
98  }
99 
100  bool ParticleData::setSignatureIndex(size_t idx) {
101  if(idx > _signatures.size()) {
102  _signatureIndex = 0ul;
103  return false;
104  }
105  else {
106  _signatureIndex = idx;
107  return true;
108  }
109  }
110 
111  size_t ParticleData::numSignatures() const {
112  return _signatures.size();
113  }
114 
115 } // namespace Hammer
std::vector< PdgId > daughters
particle IDs of the (ordered) daughter (and granddaughter) particles.
Definition: ParticleData.hh:57
#define ASSERT_MSG(x, msg)
Definition: Exceptions.hh:88
PDG codes to UID functions.
PdgId parent
particle ID of the parent particle
Definition: ParticleData.hh:56
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...
Hammer decay PDG code management.
Decay signature information.
Definition: ParticleData.hh:54
std::vector< double > masses
list of particle mass values parent + daughters (in the same order as the particle ID vector) ...
Definition: ParticleData.hh:64
void addMasses(const std::vector< PdgId > &ids)
appends the masses of a list of particles to the mass list
Definition: ParticleData.cc:93
void calcIds(size_t numDaughters)
computes the unique IDs from the PDG codes
Definition: ParticleData.cc:79
void addMass(PdgId id)
appends the mass of a particle to the mass list
Definition: ParticleData.cc:88
PdgId flipSign(const PdgId &id)
return the PDG code of the conjugate particle (itself if self-conjugate)
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
double getMass(PdgId id) const
particle mass from a PDG code
Definition: Pdg.cc:62