herwig is hosted by Hepforge, IPPP Durham
Herwig  7.2.1
ColourFlows.h
1 // -*- C++ -*-
2 
3 //
4 // ColourFlowBasis.hpp is part of CVolver, (C) 2013 Simon Plätzer -- simon.plaetzer@desy.de, The Herwig Collaboration
5 // CVolver is licenced under version 3 of the GPL, see COPYING for details.
6 //
7 
8 #ifndef CVOLVER_ColourFlowBasis_hpp_included
9 #define CVOLVER_ColourFlowBasis_hpp_included
10 
11 #include <vector>
12 #include <map>
13 #include <set>
14 #include <cassert>
15 #include <algorithm>
16 
17 namespace CVolver {
18 
22  template<class ForwardIterator, class T>
23  void iota(ForwardIterator begin, ForwardIterator end, T value) {
24  while ( begin != end ) {
25  *begin = value;
26  value += 1;
27  ++begin;
28  }
29  }
30 
34  inline std::vector<std::size_t> identicalPermutation(const std::size_t n) {
35  std::vector<std::size_t> res(n);
36  CVolver::iota(res.begin(),res.end(),0);
37  return res;
38  }
39 
43  template<class Rnd>
44  std::vector<std::size_t> randomPermutation(const std::size_t n, Rnd& rnd) {
45  std::vector<std::size_t> pick = identicalPermutation(n);
46  std::vector<std::size_t> res(n);
47  std::size_t count = 0;
48  while ( !pick.empty() ) {
49  std::size_t i = rnd.template uniform_int_distribution<std::size_t>(0,pick.size()-1);
50  res[count] = pick[i];
51  pick.erase(pick.begin()+i);
52  ++count;
53  }
54  return res;
55  }
56 
60  class ColourFlow {
61 
62  public:
63 
68 
72  explicit ColourFlow(const std::vector<size_t>& perm)
73  : thePermutation(perm) {}
74 
78  template<class Rnd>
79  static ColourFlow randomFlow(const std::size_t& n, Rnd& rnd) {
80  return ColourFlow(randomPermutation(n,rnd));
81  }
82 
86  static std::set<ColourFlow> allFlows(const std::size_t& n);
87 
91  bool operator==(const ColourFlow& other) const {
92  return thePermutation == other.thePermutation;
93  }
94 
98  bool operator!=(const ColourFlow& other) const {
99  return thePermutation != other.thePermutation;
100  }
101 
105  bool operator<(const ColourFlow& other) const {
106  return thePermutation < other.thePermutation;
107  }
108 
113  std::vector<std::size_t> tmp = thePermutation;
114  for ( std::size_t k = 0; k < tmp.size(); ++k ) {
115  thePermutation[tmp[k]] = k;
116  }
117  return *this;
118  }
119 
124  std::size_t scalarProduct(const ColourFlow& other) const;
125 
129  const std::vector<std::size_t>& permutation() const {
130  return thePermutation;
131  }
132 
136  const std::size_t& antiColour(const std::size_t& i) const {
137  assert(i < thePermutation.size());
138  return thePermutation[i];
139  }
140 
144  std::size_t colour(const std::size_t& i) const {
145  std::vector<std::size_t>::const_iterator k =
146  std::find(thePermutation.begin(),thePermutation.end(),i);
147  assert(k != thePermutation.end());
148  return std::distance(thePermutation.begin(),k);
149  }
150 
155  std::pair<std::size_t,std::size_t> getTranspositionOf(const ColourFlow& other) const;
156 
160  ColourFlow& swap(const std::size_t& i, const std::size_t& j) {
161  assert(i < thePermutation.size() && j < thePermutation.size());
162  std::swap(thePermutation[i],thePermutation[j]);
163  return *this;
164  }
165 
171  thePermutation.push_back(thePermutation.size());
172  return *this;
173  }
174 
178  ColourFlow& emitFromColour(const std::size_t& i) {
179  assert(i < thePermutation.size());
180  thePermutation.push_back(thePermutation[i]);
181  thePermutation[i] = thePermutation.size()-1;
182  return *this;
183  }
184 
188  ColourFlow& emitFromAntiColour(const std::size_t& i) {
189  return emitFromColour(colour(i));
190  }
191 
196  bool isNonZero(const std::vector<std::size_t>& colours,
197  const std::vector<std::size_t>& antiColours) const;
198 
202  size_t nLegs() const { return thePermutation.size(); }
203 
204  private:
205 
210  std::vector<std::size_t> thePermutation;
211 
212  };
213 
217  template<class ParticleData>
219 
223  static bool isSinglet(const ParticleData&) { return true; }
224 
228  static bool isAntiFundamental(const ParticleData&) { return false; }
229 
233  static bool isFundamental(const ParticleData&) { return false; }
234 
238  static bool isAdjoint(const ParticleData&) { return false; }
239 
240  };
241 
246 
247  private:
248 
252  void addColourCrossing(const std::size_t& leg,
253  std::size_t& count,
254  double sign) {
255  theColourMap[count] = leg;
256  theColourCrossingSigns[count] = sign;
257  theReverseColourMap[leg] = count;
258  ++count;
259  }
260 
264  void addAntiColourCrossing(const std::size_t& leg,
265  std::size_t& count,
266  double sign) {
267  theAntiColourMap[count] = leg;
268  theAntiColourCrossingSigns[count] = sign;
269  theReverseAntiColourMap[leg] = count;
270  ++count;
271  }
272 
273  public:
274 
279  : theNFlows(0) {}
280 
284  template<class ParticleData>
285  explicit ColourFlowCrossing(const std::vector<ParticleData>& proc,
286  bool signs = true)
287  : theNFlows(0) {
288  typedef ParticleDataTraits<ParticleData> Traits;
289  std::size_t colourCounter = 0;
290  std::size_t antiColourCounter = 0;
291  for ( std::size_t k = 0; k < proc.size(); ++k ) {
292  if ( Traits::isSinglet(proc[k]) )
293  continue;
294  double sign = k > 1 ? 1. : -1.;
295  if ( Traits::isAntiFundamental(proc[k]) ) {
296  if ( k > 1 )
297  addAntiColourCrossing(k,antiColourCounter,signs ? sign : 1.0);
298  else
299  addColourCrossing(k,colourCounter,signs ? sign : 1.0);
300  }
301  if ( Traits::isFundamental(proc[k]) ) {
302  if ( k > 1 )
303  addColourCrossing(k,colourCounter,signs ? sign : 1.0);
304  else
305  addAntiColourCrossing(k,antiColourCounter,signs ? sign : 1.0);
306  }
307  if ( Traits::isAdjoint(proc[k]) ) {
308  addColourCrossing(k,colourCounter,1.0);
309  addAntiColourCrossing(k,antiColourCounter,1.0);
310  }
311  }
312  theNFlows = colourCounter;
313  }
314 
318  const std::size_t& nFlows() const { return theNFlows; }
319 
323  std::size_t colourLeg(const std::size_t& i) const {
324  std::map<std::size_t,std::size_t>::const_iterator l =
325  theColourMap.find(i);
326  assert(l != theColourMap.end());
327  return l->second;
328  }
329 
333  std::size_t antiColourLeg(const std::size_t& i) const {
334  std::map<std::size_t,std::size_t>::const_iterator l =
335  theAntiColourMap.find(i);
336  assert(l != theAntiColourMap.end());
337  return l->second;
338  }
339 
343  std::size_t colourCrossingSign(const std::size_t& i) const {
344  std::map<std::size_t,double>::const_iterator l =
345  theColourCrossingSigns.find(i);
346  assert(l != theColourCrossingSigns.end());
347  return l->second;
348  }
349 
353  double antiColourCrossingSign(const std::size_t& i) const {
354  std::map<std::size_t,double>::const_iterator l =
355  theAntiColourCrossingSigns.find(i);
356  assert(l != theAntiColourCrossingSigns.end());
357  return l->second;
358  }
359 
363  bool coloured(const std::size_t& i) const {
364  return theReverseColourMap.find(i) != theReverseColourMap.end();
365  }
366 
370  std::size_t colourLine(const std::size_t& i) const {
371  std::map<std::size_t,std::size_t>::const_iterator l =
372  theReverseColourMap.find(i);
373  assert(l != theReverseColourMap.end());
374  return l->second;
375  }
376 
380  bool antiColoured(const std::size_t& i) const {
381  return theReverseAntiColourMap.find(i) != theReverseAntiColourMap.end();
382  }
383 
387  std::size_t antiColourLine(const std::size_t& i) const {
388  std::map<std::size_t,std::size_t>::const_iterator l =
389  theReverseAntiColourMap.find(i);
390  assert(l != theReverseAntiColourMap.end());
391  return l->second;
392  }
393 
394  private:
395 
399  std::size_t theNFlows;
400 
404  std::map<std::size_t,std::size_t> theColourMap;
405 
409  std::map<std::size_t,std::size_t> theAntiColourMap;
410 
414  std::map<std::size_t,std::size_t> theReverseColourMap;
415 
419  std::map<std::size_t,std::size_t> theReverseAntiColourMap;
420 
424  std::map<std::size_t,double> theColourCrossingSigns;
425 
429  std::map<std::size_t,double> theAntiColourCrossingSigns;
430 
431  };
432 
433 }
434 
435 #endif // CVOLVER_ColourFlowBasis_hpp_included
const std::size_t & antiColour(const std::size_t &i) const
Return the anti-colour index connected to the given colour index.
Definition: ColourFlows.h:136
ColourFlow()
Default constructor.
Definition: ColourFlows.h:67
std::size_t antiColourLine(const std::size_t &i) const
Return the anti-colour line for the given external leg.
Definition: ColourFlows.h:387
ColourFlow(const std::vector< size_t > &perm)
Construct a colour flow given a permutation.
Definition: ColourFlows.h:72
bool coloured(const std::size_t &i) const
Return true, if the external line carries colour.
Definition: ColourFlows.h:363
std::map< std::size_t, std::size_t > theColourMap
Map colour legs to external legs.
Definition: ColourFlows.h:404
ColourFlowCrossing(const std::vector< ParticleData > &proc, bool signs=true)
Construct for the given process.
Definition: ColourFlows.h:285
std::size_t scalarProduct(const ColourFlow &other) const
Return the scalar product with another basis tensor as the resulting power of N.
std::map< std::size_t, std::size_t > theReverseColourMap
Map external legs to colour legs.
Definition: ColourFlows.h:414
bool antiColoured(const std::size_t &i) const
Return true, if the external line carries anti-colour.
Definition: ColourFlows.h:380
void addColourCrossing(const std::size_t &leg, std::size_t &count, double sign)
Add colour leg mapping.
Definition: ColourFlows.h:252
static ColourFlow randomFlow(const std::size_t &n, Rnd &rnd)
Generate a random colour flow.
Definition: ColourFlows.h:79
std::size_t colour(const std::size_t &i) const
Return the colour index connected to the given anti-colour index.
Definition: ColourFlows.h:144
ColourFlowCrossing()
Default constructor.
Definition: ColourFlows.h:278
ParticleData traits.
Definition: ColourFlows.h:218
std::map< std::size_t, double > theAntiColourCrossingSigns
Map anti-colour legs to crossing signs.
Definition: ColourFlows.h:429
size_t nLegs() const
Return the number of coloured legs.
Definition: ColourFlows.h:202
const std::vector< std::size_t > & permutation() const
Return the permutation.
Definition: ColourFlows.h:129
std::size_t antiColourLeg(const std::size_t &i) const
Return the external leg for the given anti-colour.
Definition: ColourFlows.h:333
std::map< std::size_t, double > theColourCrossingSigns
Map colour legs to crossing signs.
Definition: ColourFlows.h:424
std::map< std::size_t, std::size_t > theAntiColourMap
Map anti-colour legs to external legs.
Definition: ColourFlows.h:409
bool operator!=(const ColourFlow &other) const
Compare for inequality.
Definition: ColourFlows.h:98
ColourFlow & conjugate()
Conjugate this basis tensor.
Definition: ColourFlows.h:112
A colour flow (basis tensor).
Definition: ColourFlows.h:60
bool operator==(const ColourFlow &other) const
Compare for equality.
Definition: ColourFlows.h:91
static bool isSinglet(const ParticleData &)
Return true, if singlet.
Definition: ColourFlows.h:223
double antiColourCrossingSign(const std::size_t &i) const
Return the crossing sign for the given anti-colour.
Definition: ColourFlows.h:353
std::size_t colourLine(const std::size_t &i) const
Return the colour line for the given external leg.
Definition: ColourFlows.h:370
ColourFlow & emitSinglet()
Add another flow to this basis tensor; this correspons to emitting a `singlet&#39; gluon.
Definition: ColourFlows.h:170
The crossing of a physical process to a colour flow basis.
Definition: ColourFlows.h:245
ColourFlow & emitFromAntiColour(const std::size_t &i)
Emit a gluon on a given anti-colour line.
Definition: ColourFlows.h:188
ColourFlow & swap(const std::size_t &i, const std::size_t &j)
Act a transposition on this index.
Definition: ColourFlows.h:160
static bool isFundamental(const ParticleData &)
Return true, if fundamental.
Definition: ColourFlows.h:233
std::map< std::size_t, std::size_t > theReverseAntiColourMap
Map external legs to anti-colour legs.
Definition: ColourFlows.h:419
std::vector< std::size_t > thePermutation
The vector representing the permutation of anti-fundamental w.r.t.
Definition: ColourFlows.h:210
std::size_t colourLeg(const std::size_t &i) const
Return the external leg for the given colour.
Definition: ColourFlows.h:323
const std::size_t & nFlows() const
Return the number of colour flows.
Definition: ColourFlows.h:318
double sign(double x)
Small helper.
Definition: RandomHelpers.h:30
bool operator<(const ColourFlow &other) const
Compare for ordering.
Definition: ColourFlows.h:105
static bool isAntiFundamental(const ParticleData &)
Return true, if anti-fundamental.
Definition: ColourFlows.h:228
static std::set< ColourFlow > allFlows(const std::size_t &n)
Generate all colour flows.
static bool isAdjoint(const ParticleData &)
Return true, if adjoint.
Definition: ColourFlows.h:238
std::pair< std::size_t, std::size_t > getTranspositionOf(const ColourFlow &other) const
Return the swapped indices, if this corresponds to a transposition of the given one, or (0,0)
std::size_t colourCrossingSign(const std::size_t &i) const
Return the crossing sign for the given colour.
Definition: ColourFlows.h:343
ColourFlow & emitFromColour(const std::size_t &i)
Emit a gluon on a given colour line.
Definition: ColourFlows.h:178
void addAntiColourCrossing(const std::size_t &leg, std::size_t &count, double sign)
Add anti-colour leg mapping.
Definition: ColourFlows.h:264
std::size_t theNFlows
The number of colour flows.
Definition: ColourFlows.h:399
bool isNonZero(const std::vector< std::size_t > &colours, const std::vector< std::size_t > &antiColours) const
Return true, if this colour flow is non-vanishing for the given colours and anticolours.