herwig is hosted by Hepforge, IPPP Durham
Herwig  7.2.1
Tree2toNGenerator.h
1 // -*- C++ -*-
2 //
3 // Tree2toNGenerator.h is a part of Herwig - A multi-purpose Monte Carlo event generator
4 // Copyright (C) 2002-2019 The Herwig Collaboration
5 //
6 // Herwig is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef Herwig_Tree2toNGenerator_H
10 #define Herwig_Tree2toNGenerator_H
11 //
12 // This is the declaration of the Tree2toNGenerator class.
13 //
14 
15 #include "ThePEG/Handlers/HandlerBase.h"
16 #include "ThePEG/Helicity/Vertex/VertexBase.h"
17 #include "ThePEG/MatrixElement/Tree2toNDiagram.h"
18 
19 #include "ThePEG/Persistency/PersistentOStream.h"
20 #include "ThePEG/Persistency/PersistentIStream.h"
21 
22 namespace Herwig {
23 
24 using namespace ThePEG;
25 
36 
37 public:
38 
45 
49  virtual ~Tree2toNGenerator();
51 
52 public:
53 
57  vector<Ptr<Tree2toNDiagram>::ptr> generate(const PDVector&,
58  unsigned int orderInGs,
59  unsigned int orderInGem);
60 
61  typedef vector<Ptr<Helicity::VertexBase>::ptr> VertexVector;
62 
66  VertexVector& vertices() { return theVertices; }
67 
71  const VertexVector& vertices() const { return theVertices; }
72 
76  PDVector& excludeInternal() { return theExcludeInternal; }
77 
81  const PDVector& excludeInternal() const { return theExcludeInternal; }
82 
83 public:
84 
91  void persistentOutput(PersistentOStream & os) const;
92 
98  void persistentInput(PersistentIStream & is, int version);
100 
107  static void Init();
108 
109 public:
110 
114  struct Vertex {
115 
121  vector<Vertex> children;
122 
127 
131  bool spacelike;
132 
137 
141  int parentId;
142 
147  : spacelike(false), externalId(-1), parentId(-1) {}
148 
152  void print(ostream& os, const string& prefix = "") const {
153  os << prefix << parent->PDGName()
154  << "[" << (spacelike ? "s" : "t") << "] (";
155  if ( externalId < 0 )
156  os << "x)\n";
157  else
158  os << externalId << ")\n";
159  if ( !children.empty() ) {
160  os << prefix << "|__\n";
161  children[0].print(os,prefix + "| ");
162  os << prefix << "|__\n";
163  children[1].print(os,prefix + "| ");
164  }
165  }
166 
170  int nspace() const {
171  if ( children.empty() )
172  return 1;
173  int ret = 1;
174  ret += children[0].nspace();
175  return ret;
176  }
177 
183  map<int,pair<int,PDPtr> >& outgoing,
184  int& lastUsed) {
185  if ( externalId == 0 ) {
186  assert(lastUsed==0);
187  ++lastUsed;
188  diag.operator,(parent);
189  children[0].parentId = lastUsed;
190  children[1].parentId = lastUsed;
191  children[0].update(diag,outgoing,lastUsed);
192  children[1].update(diag,outgoing,lastUsed);
193  for ( map<int,pair<int,PDPtr> >::iterator out =
194  outgoing.begin(); out != outgoing.end(); ++out ) {
195  diag.operator,(out->second.first);
196  diag.operator,(out->second.second);
197  }
198  return;
199  }
200  if ( spacelike ) {
201  ++lastUsed;
202  diag.operator,(parent);
203  if ( externalId == 1 )
204  return;
205  children[0].parentId = lastUsed;
206  children[1].parentId = lastUsed;
207  children[0].update(diag,outgoing,lastUsed);
208  children[1].update(diag,outgoing,lastUsed);
209  return;
210  }
211  if ( children.empty() ) {
212  outgoing[externalId] =
213  make_pair(parentId,parent);
214  return;
215  }
216  diag.operator,(parentId);
217  diag.operator,(parent);
218  ++lastUsed;
219  children[0].parentId = lastUsed;
220  children[1].parentId = lastUsed;
221  children[0].update(diag,outgoing,lastUsed);
222  children[1].update(diag,outgoing,lastUsed);
223  }
224 
229  int nsp = nspace();
230  Tree2toNDiagram res(nsp);
231  int diagid = 0;
232  map<int,pair<int,PDPtr> > out;
233  update(res,out,diagid);
234  res.operator,(-id);
235  return res;
236  }
237 
238  };
239 
243  list<vector<Vertex> > cluster(const vector<Vertex>& children,
244  unsigned int orderInGs,
245  unsigned int orderInGem) const;
246 
250  list<vector<Vertex> > clusterAll(const list<vector<Vertex> >& current,
251  unsigned int orderInGs,
252  unsigned int orderInGem) const;
253 
257  list<vector<Vertex> > clusterAll(const PDVector& external,
258  unsigned int orderInGs,
259  unsigned int orderInGem);
260 
264  struct LineMatcher {
265 
269  set<tcPDPtr> particles;
270 
274  pair<int,int> range;
275 
279  int count;
280 
285  : range(0,0), count(0) {}
286 
291  const pair<int,int>& r)
292  : range(r), count(0) {
293  copy(p.begin(),p.end(),inserter(particles,particles.begin()));
294  }
295 
300  set<tcPDPtr> oldp = particles;
301  particles.clear();
302  for ( set<tcPDPtr>::const_iterator p = oldp.begin();
303  p != oldp.end(); ++p )
304  particles.insert(g->getParticleData((**p).id()));
305  }
306 
310  void reset() {
311  count = 0;
312  }
313 
317  void add(tcPDPtr p, int n) {
318  if ( particles.find(p) == particles.end() )
319  return;
320  count += n;
321  }
322 
326  bool check() const {
327  return
328  count >= range.first && count <= range.second;
329  }
330 
331  };
332 
333 protected:
334 
341  virtual IBPtr clone() const;
342 
347  virtual IBPtr fullclone() const;
349 
350 
351 // If needed, insert declarations of virtual function defined in the
352 // InterfacedBase class here (using ThePEG-interfaced-decl in Emacs).
353 
354 private:
355 
359  VertexVector theVertices;
360 
365 
369  unsigned int maxOrderGs;
370 
374  unsigned int maxOrderGem;
375 
379  bool prepared;
380 
384  VertexVector theExcludeVertices;
385 
389  vector<LineMatcher> spaceLikeAllowed;
390 
394  vector<LineMatcher> timeLikeAllowed;
395 
400 
404  string doSpaceLikeRange(string);
405 
409  string doTimeLikeRange(string);
410 
414  string doClearRestrictLines(string);
415 
416 private:
417 
422  Tree2toNGenerator & operator=(const Tree2toNGenerator &) = delete;
423 
424 };
425 
427  os << m.particles << m.range << m.count;
428  return os;
429 }
430 
432  is >> m.particles >> m.range >> m.count;
433  return is;
434 }
435 
436 }
437 
438 #endif /* Herwig_Tree2toNGenerator_H */
bool check() const
Ceck if restrictions are met.
unsigned int maxOrderGem
Maximum order in gem to consider.
LineMatcher(const PDVector &p, const pair< int, int > &r)
Construct given particles and a range.
ThePEG::Ptr< InterfacedBase >::pointer IBPtr
PDVector theRestrictLines
The next particle for which internal lines need to be restricted.
Vertex()
The default constructor.
vector< LineMatcher > spaceLikeAllowed
Minimal and maximal occurences of spacelike internal lines.
void update(Tree2toNDiagram &diag, map< int, pair< int, PDPtr > > &outgoing, int &lastUsed)
Update diagram returning a map of external ids to diagram id parents.
std::insert_iterator< Cont > inserter(Cont &c)
void rebind(Tree2toNGenerator *g)
Rebind the particle data pointers.
Generate Tree2toNDiagrams for a given process.
PDPtr parent
The incoming line at this node.
ostream & operator<<(ostream &, const DecayIntegrator &)
Output information on the DecayIntegrator for debugging purposes.
PDVector theExcludeInternal
The particles to be excluded from internal lines.
void print(ostream &os, const string &prefix="") const
Debug printout.
pair< int, int > range
The range allowed.
PDPtr getParticleData(PID) const
PersistentIStream & operator>>(PersistentIStream &is, map< ShowerInteraction, T, Cmp, A > &m)
Read a map with ShowerInteraction as the key.
ThePEG::Ptr< ParticleData >::transient_const_pointer tcPDPtr
A node in internally used trees.
vector< LineMatcher > timeLikeAllowed
Minimal and maximal occurences of timelike internal lines.
ThePEG::Ptr< ParticleData >::pointer PDPtr
const PDVector & excludeInternal() const
Return the particles to be excluded from internal lines.
VertexVector theExcludeVertices
The vertices to be excluded.
VertexVector theVertices
The vertices to be used.
pair< double, double > generate(const Generator< Density > &gen, double r)
Generate a random variable and return its weight.
bool prepared
Wether or not the generator has been prepared.
-*- C++ -*-
void add(tcPDPtr p, int n)
Count the given multiplicity.
int parentId
The parent diagram id.
vector< PDPtr > PDVector
int nspace() const
Count the number of spacelike lines.
unsigned int maxOrderGs
Maximum order in gs to consider.
bool spacelike
True, if this is spacelike node.
Tree2toNDiagram generate(int id)
Generate a diagram of given id.
set< tcPDPtr > particles
The group of lines to be considered.
int externalId
The external leg id.
const VertexVector & vertices() const
Return the vertices.
VertexVector & vertices()
Access the vertices.
vector< Vertex > children
The outgoing particles.
PDVector & excludeInternal()
Access the particles to be excluded from internal lines.
Helper for topology restrictions.