herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
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
22namespace Herwig {
23
24using namespace ThePEG;
25
36
37public:
38
43
44public:
45
49 vector<Ptr<Tree2toNDiagram>::ptr> generate(const PDVector&,
50 unsigned int orderInGs,
51 unsigned int orderInGem);
52
53 typedef vector<Ptr<Helicity::VertexBase>::ptr> VertexVector;
54
58 VertexVector& vertices() { return theVertices; }
59
63 const VertexVector& vertices() const { return theVertices; }
64
69
73 const PDVector& excludeInternal() const { return theExcludeInternal; }
74
75public:
76
84
90 void persistentInput(PersistentIStream & is, int version);
92
99 static void Init();
100
101public:
102
106 struct Vertex {
107
113 vector<Vertex> children;
114
119
124
129
134
139 : spacelike(false), externalId(-1), parentId(-1) {}
140
144 void print(ostream& os, const string& prefix = "") const {
145 os << prefix << parent->PDGName()
146 << "[" << (spacelike ? "s" : "t") << "] (";
147 if ( externalId < 0 )
148 os << "x)\n";
149 else
150 os << externalId << ")\n";
151 if ( !children.empty() ) {
152 os << prefix << "|__\n";
153 children[0].print(os,prefix + "| ");
154 os << prefix << "|__\n";
155 children[1].print(os,prefix + "| ");
156 }
157 }
158
162 int nspace() const {
163 if ( children.empty() )
164 return 1;
165 int ret = 1;
166 ret += children[0].nspace();
167 return ret;
168 }
169
175 map<int,pair<int,PDPtr> >& outgoing,
176 int& lastUsed) {
177 if ( externalId == 0 ) {
178 assert(lastUsed==0);
179 ++lastUsed;
180 diag.operator,(parent);
181 children[0].parentId = lastUsed;
182 children[1].parentId = lastUsed;
183 children[0].update(diag,outgoing,lastUsed);
184 children[1].update(diag,outgoing,lastUsed);
185 for ( map<int,pair<int,PDPtr> >::iterator out =
186 outgoing.begin(); out != outgoing.end(); ++out ) {
187 diag.operator,(out->second.first);
188 diag.operator,(out->second.second);
189 }
190 return;
191 }
192 if ( spacelike ) {
193 ++lastUsed;
194 diag.operator,(parent);
195 if ( externalId == 1 )
196 return;
197 children[0].parentId = lastUsed;
198 children[1].parentId = lastUsed;
199 children[0].update(diag,outgoing,lastUsed);
200 children[1].update(diag,outgoing,lastUsed);
201 return;
202 }
203 if ( children.empty() ) {
205 make_pair(parentId,parent);
206 return;
207 }
208 diag.operator,(parentId);
209 diag.operator,(parent);
210 ++lastUsed;
211 children[0].parentId = lastUsed;
212 children[1].parentId = lastUsed;
213 children[0].update(diag,outgoing,lastUsed);
214 children[1].update(diag,outgoing,lastUsed);
215 }
216
221 int nsp = nspace();
222 Tree2toNDiagram res(nsp);
223 int diagid = 0;
224 map<int,pair<int,PDPtr> > out;
225 update(res,out,diagid);
226 res.operator,(-id);
227 return res;
228 }
229
230 };
231
235 list<vector<Vertex> > cluster(const vector<Vertex>& children,
236 unsigned int orderInGs,
237 unsigned int orderInGem) const;
238
242 list<vector<Vertex> > clusterAll(const list<vector<Vertex> >& current,
243 unsigned int orderInGs,
244 unsigned int orderInGem) const;
245
249 list<vector<Vertex> > clusterAll(const PDVector& external,
250 unsigned int orderInGs,
251 unsigned int orderInGem);
252
256 struct LineMatcher {
257
261 set<tcPDPtr> particles;
262
266 pair<int,int> range;
267
271 int count;
272
277 : range(0,0), count(0) {}
278
283 const pair<int,int>& r)
284 : range(r), count(0) {
285 copy(p.begin(),p.end(),inserter(particles,particles.begin()));
286 }
287
292 set<tcPDPtr> oldp = particles;
293 particles.clear();
294 for ( set<tcPDPtr>::const_iterator p = oldp.begin();
295 p != oldp.end(); ++p )
296 particles.insert(g->getParticleData((**p).id()));
297 }
298
302 void reset() {
303 count = 0;
304 }
305
309 void add(tcPDPtr p, int n) {
310 if ( particles.find(p) == particles.end() )
311 return;
312 count += n;
313 }
314
318 bool check() const {
319 return
320 count >= range.first && count <= range.second;
321 }
322
323 };
324
325protected:
326
333 virtual IBPtr clone() const;
334
339 virtual IBPtr fullclone() const;
341
342
343// If needed, insert declarations of virtual function defined in the
344// InterfacedBase class here (using ThePEG-interfaced-decl in Emacs).
345
346private:
347
351 VertexVector theVertices;
352
357
361 unsigned int maxOrderGs;
362
366 unsigned int maxOrderGem;
367
372
376 VertexVector theExcludeVertices;
377
381 vector<LineMatcher> spaceLikeAllowed;
382
386 vector<LineMatcher> timeLikeAllowed;
387
392
396 string doSpaceLikeRange(string);
397
401 string doTimeLikeRange(string);
402
406 string doClearRestrictLines(string);
407
408private:
409
415
416};
417
419 os << m.particles << m.range << m.count;
420 return os;
421}
422
423inline PersistentIStream& operator>>(PersistentIStream& is, Tree2toNGenerator::LineMatcher& m) {
424 is >> m.particles >> m.range >> m.count;
425 return is;
426}
427
428}
429
430#endif /* Herwig_Tree2toNGenerator_H */
Generate Tree2toNDiagrams for a given process.
bool prepared
Wether or not the generator has been prepared.
string doSpaceLikeRange(string)
Command to set an allowed range of spacelike internal lines.
PDVector theExcludeInternal
The particles to be excluded from internal lines.
vector< LineMatcher > spaceLikeAllowed
Minimal and maximal occurences of spacelike internal lines.
const VertexVector & vertices() const
Return the vertices.
string doTimeLikeRange(string)
Command to set an allowed range of timelike internal lines.
vector< LineMatcher > timeLikeAllowed
Minimal and maximal occurences of timelike internal lines.
virtual IBPtr fullclone() const
Make a clone of this object, possibly modifying the cloned object to make it sane.
PDVector theRestrictLines
The next particle for which internal lines need to be restricted.
list< vector< Vertex > > cluster(const vector< Vertex > &children, unsigned int orderInGs, unsigned int orderInGem) const
For the given set of trees determine all allowed clusterings.
list< vector< Vertex > > clusterAll(const list< vector< Vertex > > &current, unsigned int orderInGs, unsigned int orderInGem) const
For the given set of outgoing lines cluster recursively.
virtual IBPtr clone() const
Make a simple clone of this object.
vector< Ptr< Tree2toNDiagram >::ptr > generate(const PDVector &, unsigned int orderInGs, unsigned int orderInGem)
Generate all diagrams for the given process.
unsigned int maxOrderGem
Maximum order in gem to consider.
VertexVector theVertices
The vertices to be used.
VertexVector theExcludeVertices
The vertices to be excluded.
Tree2toNGenerator()
The default constructor.
VertexVector & vertices()
Access the vertices.
unsigned int maxOrderGs
Maximum order in gs to consider.
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
static void Init()
The standard Init function used to initialize the interfaces.
const PDVector & excludeInternal() const
Return the particles to be excluded from internal lines.
list< vector< Vertex > > clusterAll(const PDVector &external, unsigned int orderInGs, unsigned int orderInGem)
For the given set of outgoing lines cluster recursively.
string doClearRestrictLines(string)
Command to clear the restrict lines container.
PDVector & excludeInternal()
Access the particles to be excluded from internal lines.
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
Tree2toNGenerator & operator=(const Tree2toNGenerator &)=delete
The assignment operator is private and must never be called.
-*- C++ -*-
PersistentIStream & operator>>(PersistentIStream &is, HandlerGroup< HDLR > &hg)
vector< PDPtr > PDVector
ThePEG::Ptr< InterfacedBase >::pointer IBPtr
ThePEG::Ptr< ParticleData >::transient_const_pointer tcPDPtr
ThePEG::Ptr< ParticleData >::pointer PDPtr
ostream & operator<<(ostream &, const Collision &)
std::insert_iterator< Cont > inserter(Cont &c)
Helper for topology restrictions.
void add(tcPDPtr p, int n)
Count the given multiplicity.
LineMatcher(const PDVector &p, const pair< int, int > &r)
Construct given particles and a range.
pair< int, int > range
The range allowed.
set< tcPDPtr > particles
The group of lines to be considered.
bool check() const
Ceck if restrictions are met.
void rebind(Tree2toNGenerator *g)
Rebind the particle data pointers.
A node in internally used trees.
PDPtr parent
The incoming line at this node.
void print(ostream &os, const string &prefix="") const
Debug printout.
void update(Tree2toNDiagram &diag, map< int, pair< int, PDPtr > > &outgoing, int &lastUsed)
Update diagram returning a map of external ids to diagram id parents.
Vertex()
The default constructor.
vector< Vertex > children
The outgoing particles.
Tree2toNDiagram generate(int id)
Generate a diagram of given id.
int nspace() const
Count the number of spacelike lines.
int externalId
The external leg id.
int parentId
The parent diagram id.
bool spacelike
True, if this is spacelike node.