-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVinciaQED.cc
3010 lines (2536 loc) · 91.2 KB
/
VinciaQED.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// VinciaQED.cc is a part of the PYTHIA event generator.
// Copyright (C) 2024 Peter Skands, Torbjorn Sjostrand.
// PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
// Please respect the MCnet Guidelines, see GUIDELINES for details.
// Function definitions (not found in the header) for Vincia's QED
// shower class and related auxiliary methods. Main author is Rob
// Verheyen.
#include "Pythia8/VinciaQED.h"
namespace Pythia8 {
using namespace VinciaConstants;
//==========================================================================
// Class for QED emissions.
//--------------------------------------------------------------------------
// Initialize the pointers.
void QEDemitElemental::initPtr(Rndm* rndmPtrIn,
PartonSystems* partonSystemsPtrIn) {
rndmPtr = rndmPtrIn;
partonSystemsPtr = partonSystemsPtrIn;
isInitPtr = true;
}
//--------------------------------------------------------------------------
// Initialize.
void QEDemitElemental::init(Event &event, int xIn, int yIn, double shhIn,
double verboseIn) {
if (!isInitPtr) printOut(__METHOD_NAME__, "initPtr not called");
x = xIn;
y = yIn;
shh = shhIn;
hasTrial = false;
isII = false;
isIF = false;
isFF = false;
isRF = false;
isIA = false;
isDip = false;
// If an II antenna, make sure x is the positive pz state.
if (!event[x].isFinal() && !event[y].isFinal() && event[x].pz() < 0)
swap(x,y);
// If an IF/RF antenna, make sure x is the initial state.
if (event[x].isFinal() && !event[y].isFinal()) swap(x,y);
// If a dipole, make sure x is the emitting object.
if (event[x].isFinal() && event[y].isFinal())
if (!event[x].isCharged() || event[y].isCharged()) swap(x,y);
idx = event[x].id();
idy = event[y].id();
mx2 = max(0., event[x].m2());
my2 = max(0., event[y].m2());
ex = event[x].e();
ey = event[y].e();
m2Ant = m2(event[x], event[y]);
sAnt = 2*dot4(event[x], event[y]);
QQ = - event[x].charge() * event[y].charge();
// II.
if (!event[x].isFinal() && !event[y].isFinal()) isII = true;
// IF/RF.
if (!event[x].isFinal() && event[y].isFinal()) {
// QQ is flipped for IF antennae.
QQ = -QQ;
// Check if initial state is in a beam.
int mother1 = event[x].mother1();
// Check if initial particle is A or B.
if (mother1 <= 2) {
isIF = true;
if (event[x].pz() > 0) isIA = true;
// Otherwise it's a resonance decay.
} else isRF = true;
}
// FF.
if (event[x].isFinal() && event[y].isFinal()) isFF = true;
isInit = true;
verbose = verboseIn;
}
//--------------------------------------------------------------------------
// Initialize.
void QEDemitElemental::init(Event &event, int xIn, vector<int> iRecoilIn,
double shhIn, double verboseIn) {
x = xIn;
iRecoil = iRecoilIn;
shh = shhIn;
hasTrial = false;
isII = false;
isIF = false;
isFF = false;
isRF = false;
isIA = false;
isDip = true;
idx = event[x].id();
mx2 = max(0., event[x].m2());
// Compute total recoiler momentum.
Vec4 pRecoil;
for (int i = 0; i < (int)iRecoil.size(); i++)
pRecoil += event[iRecoil[i]].p();
my2 = max(0., pRecoil.m2Calc());
m2Ant = (pRecoil + event[xIn].p()).m2Calc();
sAnt = 2*pRecoil*event[xIn].p();
QQ = 1;
isInit = true;
verbose = verboseIn;
}
//--------------------------------------------------------------------------
// Generate a trial point.
double QEDemitElemental::generateTrial(Event &event, double q2Start,
double q2Low, double alphaIn, double cIn) {
if (!isInit) return 0.;
if (hasTrial) {
if (verbose >= VinciaConstants::DEBUG)
printOut(__METHOD_NAME__, "Elemental has a trial already.");
return q2Sav;
}
q2Sav = 0.;
double q2TrialNow = 0.;
alpha = alphaIn;
c = cIn;
// FF.
if (isFF || isDip) {
// Adjust starting scale.
q2Start = min(q2Start, sAnt/4.);
if (q2Start < q2Low) {
if (verbose >= VinciaConstants::DEBUG) printOut(__METHOD_NAME__,
"No phase space for FF in this window.");
return 0.;
}
// Compute phase space constants.
double lambda = m2Ant*m2Ant + mx2*mx2 + my2*my2
- 2.*m2Ant*mx2 - 2.*m2Ant*my2 - 2.*mx2*my2;
// zMin is identical for all instances.
double zMin = (4*q2Low/sAnt < 1E-8) ? q2Low/sAnt
: 0.5*(1. - sqrt(1. - 4*q2Low/sAnt));
// Generate scale for eikonal piece.
if (true) {
double Iz = (zMin < 1E-8) ? -2*log(zMin) - 2*zMin - pow2(zMin)
: 2*log((1-zMin)/zMin);
double comFac = 2*M_PI*sqrt(lambda)/alpha/Iz/c/sAnt;
double q2New = q2Start*pow(rndmPtr->flat(), comFac);
if (q2New > q2TrialNow) {
q2TrialNow = q2New;
zetaSav = 1/(exp(Iz*(0.5 - rndmPtr->flat())) + 1);
// Note: return infinity if zeta=1 or =0 within machine precision
// to make sure it gets vetoed later.
sxjSav = zetaSav != 1 ? sqrt(sAnt*q2TrialNow*zetaSav/((1-zetaSav))) :
numeric_limits<double>::infinity();
syjSav = zetaSav != 0 ? sqrt(sAnt*q2TrialNow*(1-zetaSav)/(zetaSav)) :
numeric_limits<double>::infinity();
}
}
// Generate scale for additional W piece on x.
if (isFF && abs(idx) == 24) {
double Iz = (zMin < 1E-8) ?
-log(zMin) - zMin - pow2(zMin)/2. : log((1-zMin)/zMin);
double comFac = 3.*M_PI*sqrt(lambda)/alpha/Iz/c/sAnt/2.;
double q2New = q2Start*pow(rndmPtr->flat(), comFac);
if (q2New > q2TrialNow) {
q2TrialNow = q2New;
double r = rndmPtr->flat();
zetaSav = (zMin < 1E-8) ? 1 - pow(zMin,r)*(1. - (1.-r)*zMin)
: 1 - pow(zMin,r)*pow(1.-zMin, 1.-r);
sxjSav = q2TrialNow/zetaSav;
syjSav = zetaSav*sAnt;
}
}
// Generate scale for additional W piece on y.
if (isFF && abs(idy) == 24) {
double Iz = (zMin < 1E-8) ? -log(zMin) - zMin - pow2(zMin)/2.
: log((1-zMin)/zMin);
double comFac = 3.*M_PI*sqrt(lambda)/alpha/Iz/c/sAnt/2.;
double q2New = q2Start*pow(rndmPtr->flat(), comFac);
if (q2New > q2TrialNow) {
q2TrialNow = q2New;
double r = rndmPtr->flat();
zetaSav = (zMin < 1E-8) ? 1 - pow(zMin,r)*(1. - (1.-r)*zMin)
: 1 - pow(zMin,r)*pow(1.-zMin, 1.-r);
sxjSav = zetaSav*sAnt;
syjSav = q2TrialNow/zetaSav;
}
}
}
// IF.
if (isIF) {
// Compute exmax and sjkMax.
double exUsed = 0;
int nSys = partonSystemsPtr->sizeSys();
for (int i=0; i<nSys; i++) {
int iEv;
if (isIA) iEv = partonSystemsPtr->getInA(i);
else iEv = partonSystemsPtr->getInB(i);
exUsed += event[iEv].e();
}
double exMax = sqrt(shh)/2.0 - (exUsed-ex);
double sjkMax = sAnt*(exMax-ex)/ex;
// Adjust starting scale.
q2Start = min(q2Start, sAnt*(exMax - ex)/ex);
if (q2Start < q2Low) {
if (verbose >= VinciaConstants::DEBUG) printOut(__METHOD_NAME__,
"No phase space for IF in this window.");
return 0.;
}
double zMax = sjkMax/(sjkMax + my2);
double zMin = q2Low/sjkMax;
// Check if there is any phase space available.
if (zMin < zMax) {
// Generate scale for eikonal piece.
if (true) {
double Iz = log(zMax/zMin);
double Rpdf = 1.;
double comFac = M_PI/alpha/Iz/c/Rpdf;
double q2New = q2Start*pow(rndmPtr->flat(), comFac);
if (q2New > q2TrialNow) {
q2TrialNow = q2New;
zetaSav = zMin*pow(zMax/zMin, rndmPtr->flat());
sxjSav = sAnt*zetaSav + q2TrialNow;
syjSav = q2TrialNow/zetaSav;
}
}
// Generate scale for additional W piece on y. The veto
// probability for this antenna piece includes an additional
// factor which is incorporated by a veto locally.
if (abs(idy) == 24) {
double Iz = log((1-zMin)/(1-zMax));
double Rpdf = 1.;
double comFac = 3.*M_PI/alpha/Iz/c/Rpdf/2.;
double q2New = q2Start;
double zetaNew, sxjNew, syjNew;
while (true) {
q2New *= pow(rndmPtr->flat(), comFac);
if (q2New < q2TrialNow) {break;}
zetaNew = 1. - (1-zMin)*pow((1-zMax)/(1-zMin),rndmPtr->flat());
sxjNew = sAnt*zetaNew + q2New;
syjNew = q2New/zetaNew;
// Veto probability.
double pVeto = sAnt/(sAnt + syjNew);
if (rndmPtr->flat() < pVeto) {
q2TrialNow = q2New;
zetaSav = zetaNew;
sxjSav = sxjNew;
syjSav = syjNew;
break;
}
}
}
}
}
// II.
if (isII) {
// Adjust starting scale.
q2Start = min(q2Start, pow2(shh-sAnt)/shh/4.);
if (q2Start < q2Low) {
if (verbose >= VinciaConstants::DEBUG) printOut(__METHOD_NAME__,
"No phase space for II in this window.");
return 0.;
}
// Generate scale for eikonal piece.
if (true) {
double zMin = 0.5*(shh-sAnt -
sqrt((shh-sAnt)*(shh-sAnt) - (4.*shh*q2Low)))/shh;
double zMax = 0.5*(shh-sAnt +
sqrt((shh-sAnt)*(shh-sAnt) - (4.*shh*q2Low)))/shh;
if (4.*shh*q2Low/pow2((shh-sAnt)) < 1e-8)
zMin = q2Low/(shh-sAnt);
double Iz = log(zMax*(1-zMin)/(1-zMax)/zMin);
double Rpdf = 1.;
double comFac = M_PI/alpha/Iz/c/Rpdf;
double q2New = q2Start*pow(rndmPtr->flat(), comFac);
if (q2New > q2TrialNow) {
q2TrialNow = q2New;
double r = rndmPtr->flat();
double w = pow(zMax/(1-zMax), r) * pow(zMin/(1-zMin), 1.-r);
zetaSav = w/(1.+w);
sxjSav = (q2TrialNow + sAnt*zetaSav)/(1.-zetaSav);
syjSav = q2TrialNow/zetaSav;
}
}
}
// RF.
if (isRF) {
// Compute phase space constants.
double mr2 = abs((event[x].p() - event[y].p()).m2Calc());
double mx = sqrt(mx2);
double my = sqrt(my2);
double mr = sqrt(mr2);
double lambda = mr2*mr2 + mx2*mx2 + my2*my2
- 2.*mr2*mx2 - 2.*mr2*my2 - 2.*mx2*my2;
double sjkMax = pow2(mx - mr) - my2;
double sajMax = mx2 - pow2(my + mr);
// Adjust starting scale.
q2Start = min(q2Start, sajMax*sjkMax/(sAnt + sjkMax));
// Generate scale for eikonal piece.
if (true) {
double zMin = q2Low/sjkMax;
double zMax = sajMax/sAnt;
if (zMin < zMax) {
double Iz = log(zMax/zMin);
double comFac = M_PI*sqrt(lambda)*sAnt/alpha/Iz/c/pow2(sAnt+sjkMax);
double q2New = q2Start;
double zetaNew, sxjNew, syjNew;
while (true) {
q2New *= pow(rndmPtr->flat(), comFac);
if (q2New < q2TrialNow) break;
zetaNew = zMin*pow(zMax/zMin, rndmPtr->flat());
sxjNew = sAnt*zetaNew + q2New;
syjNew = q2New/zetaNew;
// Veto probability.
double pVeto = pow2(syjNew+sAnt)/pow2(sjkMax+sAnt);
if (rndmPtr->flat() < pVeto) {
q2TrialNow = q2New;
zetaSav = zetaNew;
sxjSav = sxjNew;
syjSav = syjNew;
break;
}
}
}
}
// Generate scale for W in initial state.
if (abs(idx) == 24) {
double zMin = q2Low/(sajMax - q2Low);
double zMax = sjkMax/sAnt;
if (zMin < zMax && zMin > 0) {
double Iz = pow2(zMax) + (1./3.)*pow3(zMax)
- pow2(zMin) - (1./3.)*pow3(zMin);
double comFac = 3.*M_PI*sqrt(lambda)/alpha/Iz/c/sAnt/2.;
double q2New = q2Start*pow(rndmPtr->flat(), comFac);
if (q2New > q2TrialNow) {
double a = rndmPtr->flat()*Iz + pow2(zMin) + (1./3.)*pow3(zMin);
// Solve for zeta using Newton-Raphson.
int n = 0;
zetaSav = zMin;
while(true) {
n++;
double f = pow2(zetaSav) + pow3(zetaSav)/3. - a;
double fPrime = 2.*zetaSav + pow2(zetaSav);
double zetaNew = zetaSav - f/fPrime;
if (zetaNew > zMax) {zetaSav = zMax; continue;}
if (zetaNew < zMin) {zetaSav = zMin; continue;}
if (abs(zetaNew - zetaSav) < 1E-8*zetaNew) {
zetaSav = zetaNew;
break;
}
if (n > 500) {
printOut(__METHOD_NAME__,
"RF(W) failed to find zeta with Newton-Raphson");
break;
}
zetaSav = zetaNew;
}
q2TrialNow = q2New;
sxjSav = (1.+zetaSav)*q2TrialNow/zetaSav;
syjSav = sAnt*zetaSav;
}
}
}
// Generate scale for W in final state.
if (abs(idy) == 24) {
double zMin = q2Low/sjkMax;
double zMax = sajMax/sAnt;
if (zMin < zMax) {
double Iz = log((1-zMin)/(1-zMax));
double comFac = 3.*M_PI*sqrt(lambda)/alpha/Iz/c/(sAnt+sjkMax)/2.;
double q2New = q2Start;
double zetaNew, sxjNew, syjNew;
while (true) {
q2New *= pow(rndmPtr->flat(), comFac);
if (q2New < q2TrialNow) {break;}
zetaNew = 1. - (1-zMin)*pow((1-zMax)/(1-zMin),rndmPtr->flat());
sxjNew = sAnt*zetaNew + q2New;
syjNew = q2New/zetaNew;
// Veto probability.
double pVeto = (syjNew+sAnt)/(sjkMax+sAnt);
if (rndmPtr->flat() < pVeto) {
q2TrialNow = q2New;
zetaSav = zetaNew;
sxjSav = sxjNew;
syjSav = syjNew;
break;
}
}
}
}
}
phiSav = 2.*M_PI*rndmPtr->flat();
if (q2TrialNow > q2Low) {
hasTrial = true;
q2Sav = q2TrialNow;
if (verbose >= VinciaConstants::DEBUG)
printOut(__METHOD_NAME__,"Generated a new trial.");
}
return q2TrialNow;
}
//==========================================================================
// QEDsystem (base class) member functions.
//--------------------------------------------------------------------------
// Initialize pointers.
void QEDsystem::initPtr(Info* infoPtrIn, ParticleData* particleDataPtrIn,
PartonSystems* partonSystemsPtrIn, Rndm* rndmPtrIn,
Settings* settingsPtrIn, VinciaCommon* vinComPtrIn) {
infoPtr = infoPtrIn;
loggerPtr = infoPtr->loggerPtr;
particleDataPtr = particleDataPtrIn;
partonSystemsPtr = partonSystemsPtrIn;
rndmPtr = rndmPtrIn;
settingsPtr = settingsPtrIn;
vinComPtr = vinComPtrIn;
isInitPtr = true;
}
//--------------------------------------------------------------------------
// Update the partons systems.
void QEDsystem::updatePartonSystems() {
if (partonSystemsPtr == nullptr) return;
if (verbose >= VinciaConstants::DEBUG) {
stringstream ss(" Updating iSys = ");
ss <<iSys<<" sizeSys = " << partonSystemsPtr->sizeSys();
printOut(__METHOD_NAME__, ss.str());
}
if (iSys < partonSystemsPtr->sizeSys()) {
int iAOld(0), iBOld(0);
if (isInitial() && partonSystemsPtr->hasInAB(iSys)) {
iAOld = partonSystemsPtr->getInA(iSys);
iBOld = partonSystemsPtr->getInB(iSys);
}
// Replace old IDs.
for (auto it = iReplace.begin(); it!= iReplace.end() ; ++it) {
int iOld(it->first), iNew(it->second);
if (iAOld == iOld) partonSystemsPtr->setInA(iSys,iNew);
else if (iBOld == iOld) partonSystemsPtr->setInB(iSys,iNew);
partonSystemsPtr->replace(iSys, iOld, iNew);
}
// Add new.
partonSystemsPtr->addOut(iSys, jNew);
// Save sHat if we set it.
if (shat > 0.) partonSystemsPtr->setSHat(iSys, shat);
}
}
//==========================================================================
// QEDemitSystem member functions.
//--------------------------------------------------------------------------
// Initialize settings for current run.
void QEDemitSystem::init(BeamParticle* beamAPtrIn, BeamParticle* beamBPtrIn,
int verboseIn) {
// Verbose setting.
if (!isInitPtr)
printOut(__METHOD_NAME__, "QEDemitSystem:initPtr not called");
verbose = verboseIn;
// Set beam pointers.
beamAPtr = beamAPtrIn;
beamBPtr = beamBPtrIn;
bool isHadronA = beamAPtr->isHadron();
bool isHadronB = beamBPtr->isHadron();
bool doRemnants = settingsPtr->flag("PartonLevel:Remnants");
// QED mode for hard systems: pairing or multipole.
qedMode = settingsPtr->mode("Vincia:ewMode");
// (If weak shower used for hard systems, use pairing as fallback.
if (qedMode == 3) qedMode = 1;
// QED mode for MPI cannot be more sophisticated than that of hard process.
qedModeMPI = min(settingsPtr->mode("Vincia:ewModeMPI"),qedMode);
// Other QED settings.
kMapTypeFinal = settingsPtr->mode("Vincia:kineMapEWFinal");
useFullWkernel = settingsPtr->flag("Vincia:fullWkernel");
emitBelowHad = (isHadronA || isHadronB) ? doRemnants : true;
// Constants.
TINYPDF = 1.0e-10;
// Initialized.
isInit = true;
}
//--------------------------------------------------------------------------
// Prepare a QED system.
void QEDemitSystem::prepare(int iSysIn, Event &event, double q2CutIn,
bool isBelowHadIn, vector<double> evolutionWindowsIn, AlphaEM alIn) {
if (!isInit) {
loggerPtr->ERROR_MSG("not initialised");
return;
}
// Verbose output.
if (verbose >= VinciaConstants::DEBUG)
printOut(__METHOD_NAME__, "begin", DASHLEN);
// Input.
iSys = iSysIn;
shh = infoPtr->s();
q2Cut = q2CutIn;
isBelowHad = isBelowHadIn;
evolutionWindows = evolutionWindowsIn;
al = alIn;
// Build internal system.
buildSystem(event);
// Done.
if (verbose >= VinciaConstants::DEBUG) print();
if (verbose >= VinciaConstants::DEBUG)
printOut(__METHOD_NAME__, "end", DASHLEN);
}
//--------------------------------------------------------------------------
// Set up antenna pairing for incoherent mode.
void QEDemitSystem::buildSystem(Event &event) {
// Verbose output.
if (verbose >= VinciaConstants::DEBUG)
printOut(__METHOD_NAME__, "begin", DASHLEN);
// Clear previous antennae.
eleVec.clear();
eleMat.clear();
iCoh.clear();
// Construct hungarian algorithm solver.
HungarianAlgorithm ha;
// Below hadronization scale.
if (isBelowHad && emitBelowHad) {
map<int, vector<int> > posMap, negMap;
vector<Vec4> posMoms, negMoms;
// Find all (final-state) quarks and leptons.
vector<int> iTriplets, iLeptons;
int sysSize = partonSystemsPtr->sizeOut(iSys);
for (int i = 0; i < sysSize; ++i) {
int iEv = partonSystemsPtr->getOut(iSys, i);
if (event[iEv].col() != 0 && event[iEv].acol()==0 &&
event[iEv].isFinal()) {
// For now, ignore quarks that are connected to junctions. In
// principle, we could add them, and any antijunction dittos.
bool isJun = false;
for (int iJun = 0; iJun < event.sizeJunction(); ++iJun) {
for (int iLeg = 0; iLeg < 3; ++iLeg) {
if (event[iEv].col() == event.endColJunction(iJun,iLeg)) {
isJun = true;
break;
}
}
}
if (!isJun) iTriplets.push_back(iEv);
}
if (event[iEv].isLepton() && event[iEv].isCharged())
iLeptons.push_back(iEv);
}
// Currently no showering below hadronisation scale if no leptons.
if (iLeptons.size() == 0) return;
// Sort all leptons into maps.
for (int i = 0; i < (int)iLeptons.size(); i++) {
int iEv = iLeptons[i];
vector<int> iLeptonVec;
iLeptonVec.push_back(iEv);
if (event[iEv].chargeType() == 3) {
posMoms.push_back(event[iEv].p());
posMap[posMoms.size()-1] = iLeptonVec;
}
if (event[iEv].chargeType() == -3) {
negMoms.push_back(event[iEv].p());
negMap[negMoms.size()-1] = iLeptonVec;
}
}
// Find all colour strings.
for (int i = 0; i < (int)iTriplets.size(); i++) {
// Get initial quark and add to pseudo particle.
Vec4 pPseudo;
int iEv = iTriplets[i];
vector<int> iPseudoVec;
iPseudoVec.push_back(iEv);
pPseudo += event[iEv].p();
// Find next colour-connected particle.
double nLoop = 0;
do {
if (++nLoop > 10000) {
loggerPtr->ERROR_MSG("caught in infinite loop");
break;
}
int colTag = event[iEv].col();
for (int j = 0; j < sysSize; j++) {
int jEv = partonSystemsPtr->getOut(iSys, j);
if (event[jEv].acol() == colTag && event[jEv].isFinal()) {
iEv = jEv;
break;
}
}
if (iEv == iPseudoVec.back()) {
loggerPtr->ERROR_MSG("colour tracing failed");
break;
}
iPseudoVec.push_back(iEv);
pPseudo += event[iEv].p();
} while(!event[iEv].isQuark()&&!event[iEv].isDiquark());
// Get charge of pseudoparticle and sort into maps.
int chargeTypePseudo = event[iPseudoVec.front()].chargeType()
+ event[iPseudoVec.back()].chargeType();
// Strings with only quarks are total charge 1 or -1.
if (chargeTypePseudo == 3) {
posMoms.push_back(pPseudo);
posMap[posMoms.size()-1] = iPseudoVec;
} else if (chargeTypePseudo == -3) {
negMoms.push_back(pPseudo);
negMap[negMoms.size()-1] = iPseudoVec;
// Strings with a diquark can be charge 2 or -2. Add these
// twice to list of recoilers.
} else if (chargeTypePseudo == 6) {
posMoms.push_back(pPseudo);
posMap[posMoms.size()-1] = iPseudoVec;
posMoms.push_back(pPseudo);
posMap[posMoms.size()-1] = iPseudoVec;
} else if (chargeTypePseudo == -6) {
negMoms.push_back(pPseudo);
negMap[negMoms.size()-1] = iPseudoVec;
negMoms.push_back(pPseudo);
negMap[negMoms.size()-1] = iPseudoVec;
}
}
// If no leptons and overall hadronic system has charge = 0, do nothing.
if (posMoms.size() == 0) return;
// Solve assignment problem.
vector<vector<double> > weights;
weights.resize(posMoms.size());
for (int i = 0; i < (int)posMoms.size(); i++) {
weights[i].resize(negMoms.size());
for (int j = 0; j < (int)negMoms.size(); j++)
weights[i][j] =
posMoms[i]*negMoms[j] - posMoms[i].mCalc()*negMoms[j].mCalc();
}
vector<int> assignment;
ha.solve(weights, assignment);
for (int i = 0; i < (int)posMoms.size(); i++) {
int iPos = i;
int iNeg = assignment[i];
// Only keep antennae with at least one lepton.
if (posMap[iPos].size() == 1 || negMap[iNeg].size() == 1) {
eleVec.push_back(QEDemitElemental());
eleVec.back().initPtr(rndmPtr, partonSystemsPtr);
// If two leptons, add regular antenna.
if (posMap[iPos].size() == 1 && negMap[iNeg].size() == 1)
eleVec.back().init(event, posMap[iPos][0], negMap[iNeg][0], shh,
verbose);
// If lepton + pseudoparticle, add dipole.
if (posMap[iPos].size() == 1 && negMap[iNeg].size() != 1)
eleVec.back().init(event, posMap[iPos][0], negMap[iNeg], shh,
verbose);
if (posMap[iPos].size()!=1 && negMap[iNeg].size()==1)
eleVec.back().init(event, negMap[iNeg][0], posMap[iPos], shh,
verbose);
}
}
// Above hadronization scale.
} else if (!isBelowHad) {
// Collect relevant particles.
int sysSize = partonSystemsPtr->sizeAll(iSys);
for (int i = 0; i < sysSize; i++) {
int iEv = partonSystemsPtr->getAll(iSys, i);
if (event[iEv].isCharged()) iCoh.push_back(iEv);
}
// Catch cases (like hadron->partons decays) where an explicit
// charged mother may not have been added to the partonSystem as a
// resonance.
if (partonSystemsPtr->getInA(iSys) == 0 &&
partonSystemsPtr->getInB(iSys) == 0 &&
partonSystemsPtr->getInRes(iSys) == 0) {
// Guess that the decaying particle is mother of first parton.
int iRes = event[partonSystemsPtr->getOut(iSys, 0)].mother1();
if (iRes != 0 && event[iRes].isCharged()) {
// Check daughter list consistent with whole system.
int ida1 = event[iRes].daughter1();
int ida2 = event[iRes].daughter2();
if (ida2 > ida1) {
bool isOK = true;
for (int i=0; i<partonSystemsPtr->sizeOut(iSys); ++i)
if (partonSystemsPtr->getOut(iSys,i) < ida1
|| partonSystemsPtr->getOut(iSys,i) > ida2) isOK = false;
if (isOK) {iCoh.push_back(iRes);}
}
}
}
// First check charge conservation.
int chargeTypeTot = 0;
for (int i = 0; i < (int)iCoh.size(); i++) {
double cType = event[iCoh[i]].chargeType();
chargeTypeTot += (event[iCoh[i]].isFinal() ? cType : -cType);
}
if (chargeTypeTot != 0) {
loggerPtr->ERROR_MSG("charge not conserved above hadronization scale");
if (verbose >= Logger::REPORT) {
printOut(__METHOD_NAME__, "Printing events and systems");
event.list();
partonSystemsPtr->list();
}
}
// Decide whether to use pairing (1) or coherent (2) algorithm.
int qedModeSys = qedMode;
if (iSys > 0 && partonSystemsPtr->hasInAB(iSys)) qedModeSys = qedModeMPI;
// Dipole-Pairing Algorithm.
if (qedModeSys == 1) {
vector<vector<int> > posChargeTypes;
posChargeTypes.resize(3);
vector<vector<int> > negChargeTypes;
negChargeTypes.resize(3);
for (int i = 0; i < (int)iCoh.size(); i++) {
int iEv = iCoh[i];
// Separate particles into charge types.
double Q = event[iEv].charge();
// Get index in pos/negChargeTypes.
int n = abs(event[iEv].chargeType()) - 1;
// Flip charge contribution of initial state.
if (!event[iEv].isFinal()) {Q = -Q;}
if (Q > 0) posChargeTypes[n].push_back(iEv);
else negChargeTypes[n].push_back(iEv);
}
// Clear list of charged particles.
iCoh.clear();
// Solve assignment problems.
for (int i=0; i<3; i++) {
int posSize = posChargeTypes[i].size();
int negSize = negChargeTypes[i].size();
int maxSize = max(posSize,negSize);
if (maxSize > 0) {
vector<vector<double> > weights;
weights.resize(maxSize);
// Set up matrix of weights.
for (int x = 0; x < maxSize; x++) {
weights[x].resize(maxSize);
for (int y = 0; y < maxSize; y++) {
// If either index is out of range. Add some random
// large weight.
double wIn = (0.9 + 0.2*rndmPtr->flat())*1E300;
if (x < posSize && y < negSize) {
int xEv = posChargeTypes[i][x];
int yEv = negChargeTypes[i][y];
wIn = event[xEv].p()*event[yEv].p()
- event[xEv].m()*event[yEv].m();
}
weights[x][y] = wIn;
}
}
// Find solution.
vector<int> assignment;
ha.solve(weights, assignment);
// Add pairings to list of emitElementals.
// Add unpaired particles to index list for coherent algorithm.
for (int j = 0; j < maxSize; j++) {
int x = j;
int y = assignment[j];
if (x < posSize && y < negSize) {
int xEv = posChargeTypes[i][x];
int yEv = negChargeTypes[i][y];
eleVec.push_back(QEDemitElemental());
eleVec.back().initPtr(rndmPtr, partonSystemsPtr);
eleVec.back().init(event, xEv, yEv, shh, verbose);
} else if (x < posSize) {
int xEv = posChargeTypes[i][x];
iCoh.push_back(xEv);
} else if (y < negSize) {
int yEv = negChargeTypes[i][y];
iCoh.push_back(yEv);
}
}
}
}
}
// Create eleMat.
eleMat.resize(iCoh.size());
for (int i = 0; i < (int)iCoh.size(); i++) {
eleMat[i].resize(i);
for (int j = 0; j < i; j++) {
eleMat[i][j].initPtr(rndmPtr, partonSystemsPtr);
eleMat[i][j].init(event, iCoh[i], iCoh[j], shh, verbose);
}
}
// Compute overestimate constant.
cMat = 0;
for (int i = 0; i < (int)eleMat.size(); i++)
for (int j = 0; j < i; j++) cMat += max(eleMat[i][j].QQ, 0.);
}
if (verbose >= VinciaConstants::DEBUG) {
printOut(__METHOD_NAME__,"end (nEmitters(II+IF+RF+FF) ="
+ num2str((int)eleVec.size())+" (pairs) + "+num2str((int)eleMat.size())
+ " (multipole))");
}
}
//--------------------------------------------------------------------------
// Generate a trial scale.
double QEDemitSystem::q2Next(Event &event, double q2Start) {
// Don't do anything if empty!
if (eleVec.size() == 0 && eleMat.size()==0 ) {
if (verbose >= VinciaConstants::DEBUG)
printOut(__METHOD_NAME__,"Nothing to do.");
return 0.;
}
if (verbose >= VinciaConstants::DEBUG) {
stringstream ss;
ss<<"Starting evolution at q2Start = "<<q2Start;
printOut(__METHOD_NAME__,ss.str());
}
// Check if qTrial is below the cutoff.
if (q2Start < q2Cut || evolutionWindows.size() == 0) {
if (verbose >= VinciaConstants::DEBUG)
printOut(__METHOD_NAME__,"Below cutoff.");
return 0;
}
// Find lower value from evolution window.
int iEvol = evolutionWindows.size() - 1;
while (iEvol >= 1 && q2Start <= evolutionWindows[iEvol]) iEvol--;
double q2Low = evolutionWindows[iEvol];
if (q2Low < 0)
loggerPtr->ERROR_MSG("Evolution window < 0");
double q2Trial = 0;
// Generate a scale.
double alphaMax = al.alphaEM(q2Start);
// Pull scales from eleVec.
if (verbose >= VinciaConstants::DEBUG) {
stringstream ss;
ss<<"Looping over "<<eleVec.size()<< " emit pairing elementals.";
printOut(__METHOD_NAME__,ss.str());
}
for (int i = 0; i < (int)eleVec.size(); i++) {
double c = eleVec[i].QQ;
double q2New = eleVec[i].generateTrial(event, q2Start, q2Low, alphaMax, c);
if (q2New > q2Low && q2New > q2Trial) {
q2Trial = q2New;
eleTrial = &eleVec[i];
trialIsVec = true;
}
}
// Pull scales from eleMat.
for (int i = 0; i < (int)eleMat.size(); i++) {
if (verbose >= VinciaConstants::DEBUG) {
stringstream ss;
ss<<"Looping over "<<eleMat[i].size()<<" coherent elementals.";
printOut(__METHOD_NAME__,ss.str());
}
for (int j = 0; j < i; j++) {
double q2New = eleMat[i][j].generateTrial(event, q2Start, q2Low,
alphaMax, cMat);
if (q2New > q2Low && q2New > q2Trial) {
q2Trial = q2New;
eleTrial = &eleMat[i][j];
trialIsVec = false;
}
}
}
// Verbose output.
if (verbose >= VinciaConstants::DEBUG) {
stringstream ss;
ss<<"Generated a new trial = "<< q2Trial;
ss<<" in window = "<<iEvol << " (q2Low = "<<q2Low<<" )";
printOut(__METHOD_NAME__,ss.str());
}
// Check if evolution window was crossed.
if (q2Trial < q2Low) {
if (iEvol == 0) {
if (verbose >= VinciaConstants::DEBUG) printOut(__METHOD_NAME__,
"Dropped below QED cutoff.");
return 0;
}
else if (verbose >= VinciaConstants::DEBUG) printOut(__METHOD_NAME__,
"Trial was below window lower bound. Try again. ");
// Reset all trials.
for (int i = 0; i < (int)eleVec.size(); i++) eleVec[i].hasTrial = false;
for (int i=0; i<(int)eleMat.size(); i++)
for (int j=0; j<i; j++) eleMat[i][j].hasTrial = false;
return q2Next(event, q2Low);
}
// Otherwise return trial scale.
if (verbose >= VinciaConstants::DEBUG) printOut(__METHOD_NAME__,"Done");
return q2Trial;
}
//--------------------------------------------------------------------------
// Check the veto. Return false if branching should be vetoed.
bool QEDemitSystem::acceptTrial(Event &event) {
if (verbose >= VinciaConstants::DEBUG)
printOut(__METHOD_NAME__, "begin", DASHLEN);
// Mark trial as used.
eleTrial->hasTrial = false;
// Pre- and post-branching momenta.
vector<Vec4> pOld;
pNew.clear();
// Global recoil momenta.
pRec.clear();
iRec.clear();
// II.
if (eleTrial->isII) {
double saj = eleTrial->sxjSav;
double sbj = eleTrial->syjSav;