StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VinciaQED.h
1 // VinciaQED.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 Peter Skands, Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // This file contains the QED antenna-shower class and auxiliary
7 // classes. Main author is Rob Verheyen.
8 
9 #ifndef Pythia8_VinciaQED_H
10 #define Pythia8_VinciaQED_H
11 
12 // Standard library.
13 #include <iostream>
14 #include <vector>
15 #include <stdlib.h>
16 #include <cfloat>
17 #include <cmath>
18 
19 // PYTHIA 8 headers.
20 #include "Pythia8/BeamParticle.h"
21 #include "Pythia8/Event.h"
22 #include "Pythia8/StandardModel.h"
23 #include "Pythia8/PartonSystems.h"
24 
25 // VINCIA headers.
26 #include "Pythia8/VinciaCommon.h"
27 #include "Pythia8/VinciaWeights.h"
28 
29 namespace Pythia8 {
30 
31 //==========================================================================
32 
33 // Class for the "Hungarian" pairing algorithm. Adapted for Vincia
34 // from an implementation by M. Buehren and C. Ma, see notices below.
35 
36 // This is a C++ wrapper with slight modification of a hungarian algorithm
37 // implementation by Markus Buehren. The original implementation is a few
38 // mex-functions for use in MATLAB, found here:
39 // http://www.mathworks.com/matlabcentral/fileexchange/
40 // 6543-functions-for-the-rectangular-assignment-problem
41 //
42 // Both this code and the orignal code are published under the BSD license.
43 // by Cong Ma, 2016.
44 //
45 // Copyright (c) 2014, Markus Buehren
46 // All rights reserved.
47 //
48 // Redistribution and use in source and binary forms, with or without
49 // modification, are permitted provided that the following conditions are
50 // met:
51 //
52 // * Redistributions of source code must retain the above copyright
53 // notice, this list of conditions and the following disclaimer.
54 // * Redistributions in binary form must reproduce the above copyright
55 // notice, this list of conditions and the following disclaimer in
56 // the documentation and/or other materials provided with the distribution
57 //
58 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
59 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
62 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
63 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
64 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
65 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
66 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
67 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
68 // POSSIBILITY OF SUCH DAMAGE.
69 
71 
72 public:
73 
74  // Constructor.
75  HungarianAlgorithm() {;}
76  // Destructor.
77  ~HungarianAlgorithm() {;}
78 
79  // Function wrapper for solving assignment problem.
80  double solve(std::vector <std::vector<double> >& distMatrix,
81  std::vector<int>& assignment);
82 
83  private:
84 
85  // Solve optimal solution for assignment problem using Munkres algorithm,
86  // also known as the Hungarian algorithm.
87  void optimal(int *assignment, double *cost, double *distMatrix,
88  int nOfRows, int nOfColumns);
89  // Build the assignment vector.
90  void vect(int *assignment, bool *starMatrix, int nOfRows,
91  int nOfColumns);
92  // Calculate the assignment cost.
93  void calcCost(int *assignment, double *cost, double *distMatrix,
94  int nOfRows);
95  // Factorized step 2a of the algorithm.
96  void step2a(int *assignment, double *distMatrix, bool *starMatrix,
97  bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns,
98  bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
99  // Factorized step 2b of the algorithm.
100  void step2b(int *assignment, double *distMatrix, bool *starMatrix,
101  bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns,
102  bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
103  // Factorized step 3 of the algorithm.
104  void step3(int *assignment, double *distMatrix, bool *starMatrix,
105  bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns,
106  bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
107  // Factorized step 4 of the algorithm.
108  void step4(int *assignment, double *distMatrix, bool *starMatrix,
109  bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns,
110  bool *coveredRows, int nOfRows, int nOfColumns, int minDim,
111  int row, int col);
112  // Factorized step 5 of the algorithm.
113  void step5(int *assignment, double *distMatrix, bool *starMatrix,
114  bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns,
115  bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
116 };
117 
118 //==========================================================================
119 
120 // Class for QED emissions.
121 
123 
124 public:
125 
126  // Friends for internal private members.
127  friend class QEDemitSystem;
128 
129  // Constuctor.
130  QEDemitElemental() : rndmPtr(nullptr), partonSystemsPtr(nullptr), q2Sav(0.),
131  zetaSav(0.), phiSav(0.), sxjSav(0.), syjSav(0.), alpha(0.), c(0.),
132  hasTrial(false), x(0), y(0), idx(0), idy(0), mx2(0.), my2(0.),
133  ex(0.), ey(0.), m2Ant(0.), sAnt(0.), QQ(0.), isII(false), isIF(false),
134  isFF(false), isRF(false), isIA(true), isDip(false), shh(0.),
135  isInitPtr(false), isInit(false), verbose(1) {;}
136 
137  // Initialize the pointers.
138  void initPtr(Rndm* rndmPtrIn, PartonSystems* partonSystemsPtrIn);
139  // Initialize.
140  void init(Event &event, int xIn, int yIn, double shhIn,
141  double verboseIn);
142  // Initialize.
143  void init(Event &event, int xIn, vector<int> iRecoilIn, double shhIn,
144  double verboseIn);
145  // Generate a trial point.
146  double generateTrial(Event &event, double q2Start, double q2Low,
147  double alphaIn, double cIn);
148 
149 private:
150 
151  // Random pointer.
152  Rndm* rndmPtr;
153 
154  // Parton system pointer.
155  PartonSystems* partonSystemsPtr;
156 
157  // Trial variables.
158  double q2Sav, zetaSav, phiSav;
159  double sxjSav, syjSav;
160  double alpha, c;
161  bool hasTrial;
162 
163  // Particle indices.
164  int x, y;
165  // Recoiler indices.
166  vector<int> iRecoil;
167  // IDs.
168  int idx, idy;
169  // Particle masses.
170  double mx2, my2;
171  // Particle energies.
172  double ex, ey;
173  // Antenna invariant mass.
174  double m2Ant;
175  // Antenna dot product.
176  double sAnt;
177  // The negative of the product of charges.
178  double QQ;
179 
180  // Type switches.
181  bool isII, isIF, isFF, isRF, isIA, isDip;
182 
183  // Hadronic invariant mass.
184  double shh;
185 
186  // Initialization.
187  bool isInitPtr, isInit;
188  int verbose;
189 
190 };
191 
192 //==========================================================================
193 
194 // Class for a QED emission system.
195 
197 
198 public:
199 
200  QEDemitSystem() :
201  iSys(-1), shh(-1.), cMat(0.), eleTrial(nullptr), trialIsVec(false),
202  beamAPtr(nullptr), beamBPtr(nullptr), infoPtr(nullptr),
203  partonSystemsPtr(nullptr), particleDataPtr(nullptr), rndmPtr(nullptr),
204  settingsPtr(nullptr), vinComPtr(nullptr), mode(-1), verbose(-1),
205  useFullWkernel(false), q2Cut(-1.), isBelowHad(false),
206  emitBelowHad(false), isInitPtr(false), isInit(false), TINYPDF(-1.) {;}
207 
208  // Initialize pointers.
209  void initPtr(Info* infoPtrIn, VinciaCommon* vinComPtrIn);
210  // Initialize settings for current run.
211  void init(BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn, int verboseIn);
212  // Prepare a QCD system.
213  void prepare(int iSysIn, Event &event, double q2CutIn, bool isBelowHadIn,
214  vector<double> evolutionWindowsIn, AlphaEM alIn);
215 
216  // Trial antenna function.
217  double aTrial(QEDemitElemental* ele, double sxj, double syj, double sxy);
218  // Physical antenna function.
219  double aPhys (QEDemitElemental* ele, double sxj, double syj, double sxy);
220  // Ratio between PDFs.
221  double PDFratio(bool isA, double eOld, double eNew, int id, double Qt2);
222  // Set up antenna pairing for incoherent mode.
223  void buildSystem(Event &event);
224  // Generate a trial scale.
225  double generateTrialScale(Event &event, double q2Start);
226  // Check the veto.
227  bool checkVeto(Event &event);
228  // Print the QED emit internal system.
229  void print();
230 
231 private:
232 
233  // Event system.
234  int iSys;
235  double shh;
236 
237  // Internal storage.
238  vector<vector<QEDemitElemental> > eleMat;
239  vector<int> iCoh;
240  double cMat;
241  vector<QEDemitElemental> eleVec;
242 
243  // AlphaEM.
244  AlphaEM al;
245 
246  // Evolution window.
247  vector<double> evolutionWindows;
248 
249  // Trial pointer.
250  QEDemitElemental* eleTrial;
251  bool trialIsVec;
252 
253  // Pointers.
254  BeamParticle* beamAPtr;
255  BeamParticle* beamBPtr;
256  Info* infoPtr;
257  PartonSystems* partonSystemsPtr;
258  ParticleData* particleDataPtr;
259  Rndm* rndmPtr;
260  Settings* settingsPtr;
261  VinciaCommon* vinComPtr;
262 
263  // Settings.
264  int mode, verbose;
265  bool useFullWkernel;
266  double q2Cut;
267  bool isBelowHad;
268  bool emitBelowHad;
269 
270  // Initialization.
271  bool isInitPtr, isInit;
272 
273  // PDF check.
274  double TINYPDF;
275 
276 };
277 
278 //==========================================================================
279 
280 // Class for trial QED splittings.
281 
283 
284 public:
285 
286  // Friends for internal private members.
287  friend class QEDsplitSystem;
288 
289  // Default constructor.
290  QEDsplitElemental() = default;
291 
292  // Constructor.
293  QEDsplitElemental(Event &event, int iPhotIn, int iSpecIn):
294  iPhot(iPhotIn), iSpec(iSpecIn), ariWeight(0) {
295  m2Ant = m2(event[iPhotIn], event[iSpecIn]);
296  sAnt = 2.*event[iPhotIn].p()*event[iSpecIn].p();
297  m2Spec = event[iSpecIn].m2();}
298 
299  // Kallen function.
300  double getKallen() {return m2Ant/(m2Ant - m2Spec);}
301 
302 private:
303 
304  // Internal members.
305  int iPhot{}, iSpec{};
306  double m2Spec{}, m2Ant{}, sAnt{};
307  double ariWeight{};
308 };
309 
310 //==========================================================================
311 
312 // Class for a QED splitting system.
313 
315 
316 public:
317 
318  // Constructor.
319  QEDsplitSystem() :
320  iSys(-1), totIdWeight(-1.), maxIdWeight(-1.), hasTrial(false),
321  q2Trial(-1.), zTrial(-1.), phiTrial(-1.), idTrial(0), eleTrial(nullptr),
322  nQuark(-1), nLepton(-1), verbose(-1), q2Max(-1.), q2Cut(-1.),
323  isBelowHad(false), beamAPtr(nullptr), beamBPtr(nullptr), infoPtr(nullptr),
324  partonSystemsPtr(nullptr), particleDataPtr(nullptr), rndmPtr(nullptr),
325  settingsPtr(nullptr), vinComPtr(nullptr), isInitPtr(false), isInit(false)
326  {;}
327 
328  // Initialize pointers.
329  void initPtr(Info* infoPtrIn, VinciaCommon* vinComPtrIn);
330  // Initialize.
331  void init(BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn, int verboseIn);
332  // Prepare list of final-state photons - with recoilers - for splittings.
333  void prepare(int iSysIn, Event &event, double q2CutIn, bool isBelowHadIn,
334  vector<double> evolutionWindowsIn, AlphaEM alIn);
335  // Build the splitting system.
336  void buildSystem(Event &event);
337  // Generate a scale for the system.
338  double generateTrialScale(Event &event, double q2Start);
339  // Check the veto.
340  bool checkVeto(Event &event);
341  // Print the system.
342  void print();
343 
344 private:
345 
346  // Event system.
347  int iSys;
348 
349  // AlphaEM.
350  AlphaEM al;
351 
352  // Evolution window.
353  vector<double> evolutionWindows;
354 
355  // Weights for splitting IDs.
356  vector<int> ids;
357  vector<double> idWeights;
358  double totIdWeight, maxIdWeight;
359 
360  // Antennae.
361  vector<QEDsplitElemental> eleVec;
362 
363  // Trial variables.
364  bool hasTrial;
365  double q2Trial, zTrial, phiTrial, idTrial;
366  QEDsplitElemental* eleTrial;
367 
368  // Settings.
369  int nQuark, nLepton, verbose;
370  double q2Max, q2Cut;
371  bool isBelowHad;
372 
373  // Pointers.
374  BeamParticle* beamAPtr;
375  BeamParticle* beamBPtr;
376  Info* infoPtr;
377  PartonSystems* partonSystemsPtr;
378  ParticleData* particleDataPtr;
379  Rndm* rndmPtr;
380  Settings* settingsPtr;
381  VinciaCommon* vinComPtr;
382 
383  // Initialization.
384  bool isInitPtr, isInit;
385 
386 };
387 
388 //==========================================================================
389 
390 // Class for a QED conversion system.
391 
393 
394 public:
395 
396  // Constructor.
397  QEDconvSystem() : totIdWeight(-1.), maxIdWeight(-1.), iSys(-1), shh(-1.),
398  s(-1.), iA(-1), iB(-1), isAPhot(false), isBPhot(false), hasTrial(false),
399  iPhotTrial(-1), iSpecTrial(-1), q2Trial(-1.), zTrial(-1.), phiTrial(-1.),
400  idTrial(-1), nQuark(-1), verbose(-1), q2Cut(-1.),
401  isBelowHad(false), beamAPtr(nullptr), beamBPtr(nullptr),
402  infoPtr(nullptr), partonSystemsPtr(nullptr), particleDataPtr(nullptr),
403  rndmPtr(nullptr), settingsPtr(nullptr), vinComPtr(nullptr),
404  isInitPtr(false), isInit(false), TINYPDF(-1.) {;}
405 
406  // Initialize the pointers.
407  void initPtr(Info* infoPtrIn, VinciaCommon* vinCluPtrIn);
408  // Initialize the system.
409  void init(BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn, int verboseIn);
410  // Prepare for backwards-evolution of photons.
411  void prepare(int iSysIn, Event &event, double q2CutIn, bool isBelowHadIn,
412  vector<double> evolutionWindowsIn, AlphaEM alIn);
413  // Build the system.
414  void buildSystem(Event &event);
415  // Generate a trial scale.
416  double generateTrialScale(Event &event, double q2Start);
417  // Check the veto.
418  bool checkVeto(Event &event);
419  // Print.
420  void print();
421 
422 private:
423 
424  // Trial pdf ratios for conversion.
425  map<int,double> Rhat;
426 
427  // AlphaEM.
428  AlphaEM al;
429 
430  // Evolution window.
431  vector<double> evolutionWindows;
432 
433  // Weights for conversion IDs.
434  vector<int> ids;
435  vector<double> idWeights;
436  double totIdWeight, maxIdWeight;
437  int iSys;
438  double shh;
439 
440  // Antenna parameters.
441  double s;
442  int iA, iB;
443  bool isAPhot, isBPhot;
444 
445  // Trial variables.
446  bool hasTrial;
447  int iPhotTrial, iSpecTrial;
448  double q2Trial, zTrial, phiTrial, idTrial;
449 
450  // Settings.
451  int nQuark, verbose;
452  double q2Cut;
453  bool isBelowHad;
454 
455  // Pointers.
456  BeamParticle* beamAPtr;
457  BeamParticle* beamBPtr;
458  Info* infoPtr;
459  PartonSystems* partonSystemsPtr;
460  ParticleData* particleDataPtr;
461  Rndm* rndmPtr;
462  Settings* settingsPtr;
463  VinciaCommon* vinComPtr;
464 
465  // Initialization.
466  bool isInitPtr, isInit;
467  double TINYPDF;
468 
469 };
470 
471 //==========================================================================
472 
473 // Class for performing QED showers.
474 
475 class QEDShower {
476 
477 public:
478 
479  // Friends for internal private members.
480  friend class VinciaFSR;
481 
482  // Constructor.
483  QEDShower() : isInitSav(false) {;}
484 
485  // Initialise pointers (called at construction time).
486  void initPtr(Info* infoPtrIn, VinciaCommon* vinCluPtrIn);
487  // Initialise settings for current run (called as part of Pythia::init())
488  void init(BeamParticle* beamAPtrIn = 0, BeamParticle* beamBPtrIn = 0);
489  // Prepare to shower a system.
490  void prepare(int iSysIn, Event &event, bool isBelowHadIn);
491  // Update QED shower system(s) each time something has changed in event.
492  void update(Event &event, int iSys);
493  // Set verbosity level.
494  void setVerbose(int verboseIn) {verbose = verboseIn;}
495  // Generate a trial scale.
496  double generateTrialScale(Event &event, double q2Start);
497  // Check the veto.
498  bool checkVeto(Event &event);
499  // Check if initialized.
500  bool isInit() {return isInitSav;}
501  // Return the system window.
502  int sysWin() {return iSysTrial;}
503  // Return scales.
504  double q2minColoured() {return q2minColouredSav;}
505  double q2min() {return q2minSav;}
506 
507 private:
508 
509  // Systems.
510  vector<int> iSystems;
511  vector<QEDemitSystem> emitSystems;
512  vector<QEDsplitSystem> splitSystems;
513  vector<QEDconvSystem> convSystems;
514 
515  // Settings.
516  int verbose;
517  bool doQED;
518  bool doEmission;
519  int nGammaToLepton, nGammaToQuark;
520  bool doConvertGamma, doConvertQuark;
521 
522  // Scales.
523  double q2minSav, q2minColouredSav;
524 
525  // Trial information.
526  int iSysTrial;
527  int iSysIndexTrial;
528  double q2Trial;
529  bool isTrialEmit;
530  bool isTrialSplit;
531  bool isTrialConv;
532 
533  // Pointers.
534  Info* infoPtr;
535  BeamParticle* beamAPtr;
536  BeamParticle* beamBPtr;
537  ParticleData* particleDataPtr;
538  PartonSystems* partonSystemsPtr;
539  Rndm* rndmPtr;
540  Settings* settingsPtr;
541  VinciaCommon* vinComPtr;
542 
543  // AlphaEM.
544  AlphaEM al;
545 
546  // Evolution windows
547  vector<double> evolutionWindows;
548 
549  // Initialize.
550  bool isInitPtr, isInitSav;
551 
552 };
553 
554 //==========================================================================
555 
556 } // end namespace Pythia8
557 
558 #endif // end Pythia8_VinciaQED_H