Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Process.hh
Go to the documentation of this file.
1 ///
2 /// @file Process.hh
3 /// @brief Hammer process class
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 #ifndef HAMMER_PROCESS_HH
13 #define HAMMER_PROCESS_HH
14 
15 #include <map>
16 #include <string>
17 #include <vector>
18 #include <unordered_map>
19 
20 #include "Hammer/IndexTypes.hh"
21 #include "Hammer/Particle.hh"
24 
25 namespace Hammer {
26 
27  class Log;
28 
29  /// @brief Decay process class
30  ///
31  /// Contains the amplitudes, weights and info associated to a decay, ...
32  ///
33  /// @ingroup Core
34  class Process : public SettingsConsumer {
35 
36  public:
37  Process();
38 
39  Process(const Process& other) = default;
40  Process& operator=(const Process& other) = default;
41  Process(Process&& other) = default;
42  Process& operator=(Process&& other) = default;
43 
44  ~Process() noexcept = default;
45 
46  public:
47 
48  using TreeMap = std::map<ParticleIndex, ParticleIndices>;
49  using const_iterator = TreeMap::const_iterator;
50 
51  const_iterator begin() const;
52 
53  const_iterator end() const;
54 
55  const_iterator find(ParticleIndex particle) const;
56 
57  public:
58 
59  /// @brief
60  /// @param[in] p
61  /// @return
63 
64  /// @brief
65  /// @param[in] parent
66  /// @param[in] daughters
67  void addVertex(ParticleIndex parent, const ParticleIndices& daughters);
68 
69  /// @brief
70  /// @param[in] parent
71  /// @param[in] prune
72  void removeVertex(ParticleIndex parent, bool prune = false);
73 
74  /// @brief
75  /// @param[in] parent
76  /// @return
77  const ParticleIndices& getDaughtersIds(ParticleIndex parent = 0) const;
78 
79  /// @brief
80  /// @param[in] daughter
81  /// @return
82  ParticleIndex getParentId(ParticleIndex daughter) const;
83 
84  /// @brief
85  /// @param[in] particle
86  /// @return
87  ParticleIndices getSiblingsIds(ParticleIndex particle = 0) const;
88 
89  /// @brief
90  /// @param[in] id
91  /// @return
92  const Particle& getParticle(ParticleIndex id) const;
93 
94  /// @brief
95  /// @param[in] parent
96  /// @param[in] sorted
97  /// @return
98  ParticleList getDaughters(ParticleIndex parent = 0, bool sorted = false) const;
99 
100  /// @brief
101  /// @param[in] particle
102  /// @param[in] sorted
103  /// @return
104  ParticleList getSiblings(ParticleIndex particle = 0, bool sorted = false) const;
105 
106  /// @brief
107  /// @param[in] daughter
108  /// @return
109  const Particle& getParent(ParticleIndex daughter) const;
110 
111  bool isParent(ParticleIndex particle) const;
112 
114 
115  /// @brief
116  /// @return
117  HashId getId() const;
118 
119  const std::set<HashId>& fullId() const;
120 
121  /// @brief
122  /// @param[in] parent
123  /// @param[in] daughters
124  /// @return
125  std::pair<Particle, ParticleList> getParticlesByVertex(PdgId parent, std::vector<PdgId> daughters) const;
126 
127  /// @brief
128  /// @param[in] vertex
129  /// @return
130  std::pair<Particle, ParticleList> getParticlesByVertex(std::string vertex) const;
131 
132  /// @brief
133  /// @param[in] vertex
134  /// @return
135  HashId getVertexId(std::string vertex) const;
136 
137  bool initialize();
138 
139  void disable();
140 
141  /// @brief
142  /// @param[in] msgwriter
143  /// @param[in] msg
144  void write(flatbuffers::FlatBufferBuilder* msgwriter, flatbuffers::Offset<Serial::FBProcIDs>* msg) const;
145 
146  /// @brief
147  /// @param[in] msgreader
148  void read(const Serial::FBProcIDs* msgreader);
149 
150  size_t numParticles(bool withoutPhotons = false) const;
151 
152  private:
153  /// @brief purely virtual function for a class to define new settings
154  virtual void defineSettings();
155 
156  /// @brief logging facility
157  /// @return stream to be used for logging
158  Log& getLog() const;
159 
160  // ///@brief
161  // ///@TODO: implement or remove
162  // void expandSoftPhotonVertices();
163 
164  ///@brief
165  void pruneSoftPhotons();
166 
167  /// @brief
168  void calcSignatures();
169 
172 
174 
175  private:
176 
177 
180 
184 
185  ParticleIndex _firstVertexIdx = std::numeric_limits<size_t>::max();
186  std::unordered_map<ParticleIndex, ParticleIndex> _parentDict;
188  bool _initialized = false;
189  };
190 
192  return it->first;
193  }
194 
196  return it->second;
197  }
198 
199 } // namespace Hammer
200 
201 #endif
HashId ProcessUID
Definition: IndexTypes.hh:49
const_iterator begin() const
Definition: Process.cc:40
const_iterator end() const
Definition: Process.cc:44
ParticleIndex findFirstVertex() const
Definition: Process.cc:242
HashId getVertexId(std::string vertex) const
Definition: Process.cc:212
ParticleIndices getSiblingsIds(ParticleIndex particle=0) const
Definition: Process.cc:100
Forward declaration of serialization related typedefs and includes.
ParticleList getSiblings(ParticleIndex particle=0, bool sorted=false) const
Definition: Process.cc:163
Hammer data types declarations.
void calcSignatures()
Definition: Process.cc:371
void read(const Serial::FBProcIDs *msgreader)
Definition: Process.cc:414
ParticleList sortByParent(ParticleIndex parent, ParticleList parts) const
Definition: Process.cc:135
void addVertex(ParticleIndex parent, const ParticleIndices &daughters)
Definition: Process.cc:59
const ParticleIndices & getDaughtersIds(ParticleIndex parent=0) const
Definition: Process.cc:96
const ParticleIndices & daughtersId(Process::const_iterator it)
Definition: Process.hh:195
HashId getId() const
Definition: Process.cc:389
const Particle & getParent(ParticleIndex daughter) const
Definition: Process.cc:158
Decay process class.
Definition: Process.hh:34
void write(flatbuffers::FlatBufferBuilder *msgwriter, flatbuffers::Offset< Serial::FBProcIDs > *msg) const
Definition: Process.cc:402
bool initialize()
Definition: Process.cc:275
ParticleIndex getParentId(ParticleIndex daughter) const
Definition: Process.cc:115
ParticleList getDaughters(ParticleIndex parent=0, bool sorted=false) const
Definition: Process.cc:145
Process & operator=(const Process &other)=default
UniqueParticleIndices _erasedGammas
Definition: Process.hh:187
std::set< VertexUID > VertexUIDSet
Definition: IndexTypes.hh:43
Base class to access the settings repository.
void pruneSoftPhotons()
Definition: Process.cc:290
ProcessUID _hashId
Definition: Process.hh:181
bool _initialized
Definition: Process.hh:188
std::map< ParticleIndex, ParticleIndices > TreeMap
Definition: Process.hh:48
void cacheParticleDependencies()
Definition: Process.cc:257
std::vector< Particle > ParticleList
Definition: Particle.fhh:20
~Process() noexcept=default
Log & getLog() const
logging facility
Definition: Process.cc:429
ParticleIndex _firstVertexIdx
Definition: Process.hh:185
void disable()
Definition: Process.cc:397
std::pair< Particle, ParticleList > getParticlesByVertex(PdgId parent, std::vector< PdgId > daughters) const
Definition: Process.cc:186
Logging class.
Definition: Logging.hh:33
Particle class.
Definition: Particle.hh:30
size_t numParticles(bool withoutPhotons=false) const
Definition: Process.cc:231
ParticleIndex getFirstVertex() const
Definition: Process.cc:235
ParticleIndex parentId(Process::const_iterator it)
Definition: Process.hh:191
Base class for accessing Hammer settings repository.
ParticleList _particles
Definition: Process.hh:178
const Particle & getParticle(ParticleIndex id) const
Definition: Process.cc:127
std::unordered_map< ParticleIndex, ParticleIndex > _parentDict
Definition: Process.hh:186
virtual void defineSettings()
purely virtual function for a class to define new settings
Definition: Process.cc:425
std::vector< ParticleIndex > ParticleIndices
Definition: IndexTypes.hh:28
std::map< ProcessUID, T > ProcIdDict
Definition: IndexTypes.hh:51
size_t ParticleIndex
Definition: IndexTypes.hh:27
const_iterator find(ParticleIndex particle) const
Definition: Process.cc:48
VertexUIDSet _fullId
Definition: Process.hh:182
ProcIdDict< ParticleIndex > _idTree
Definition: Process.hh:183
TreeMap _processTree
Definition: Process.hh:179
Hammer particle class.
std::set< ParticleIndex > UniqueParticleIndices
Definition: IndexTypes.hh:29
ParticleIndex addParticle(const Particle &p)
Definition: Process.cc:52
size_t HashId
Definition: IndexTypes.hh:31
bool isParent(ParticleIndex particle) const
Definition: Process.cc:182
TreeMap::const_iterator const_iterator
Definition: Process.hh:49
int PdgId
Definition: Pdg.fhh:17
const std::set< HashId > & fullId() const
Definition: Process.cc:393
void removeVertex(ParticleIndex parent, bool prune=false)
Definition: Process.cc:72