-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessLevel.cc
1833 lines (1552 loc) · 68.3 KB
/
ProcessLevel.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
// ProcessLevel.cc is a part of the PYTHIA event generator.
// Copyright (C) 2024 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 the ProcessLevel class.
#include "Pythia8/ProcessLevel.h"
namespace Pythia8 {
//==========================================================================
// The ProcessLevel class.
//--------------------------------------------------------------------------
// Constants: could be changed here if desired, but normally should not.
// These are of technical nature, as described for each.
// Allow a few failures in final construction of events.
const int ProcessLevel::MAXLOOP = 5;
//--------------------------------------------------------------------------
// Destructor.
ProcessLevel::~ProcessLevel() {
// Run through list of first hard processes and delete them.
for (int i = 0; i < int(containerPtrs.size()); ++i)
delete containerPtrs[i];
// Run through list of second hard processes and delete them.
for (int i = 0; i < int(container2Ptrs.size()); ++i)
delete container2Ptrs[i];
}
//--------------------------------------------------------------------------
// Main routine to initialize generation process.
bool ProcessLevel::init( bool doLHA, SLHAinterface* slhaInterfacePtrIn,
vector<SigmaProcessPtr>& sigmaPtrs, vector<PhaseSpacePtr>& phaseSpacePtrs) {
// Store other input pointers.
slhaInterfacePtr = slhaInterfacePtrIn;
// Reference to Settings.
Settings& settings = *settingsPtr;
// Provisions for variable collision energy or beam kind.
doVarEcm = settings.flag("Beams:allowVariableEnergy");
allowIDAswitch = flag("Beams:allowIDAswitch");
// Check whether photon inside lepton and save the mode.
bool beamA2gamma = settings.flag("PDF:beamA2gamma");
bool beamB2gamma = settings.flag("PDF:beamB2gamma");
beamHasGamma = beamA2gamma || beamB2gamma;
gammaMode = settings.mode("Photon:ProcessType");
// Initialize gammaKinematics when relevant.
if (beamHasGamma)
gammaKin.init();
// Send on some input pointers.
resonanceDecays.init();
// Set up SigmaTotal. Store sigma_nondiffractive for future use.
int idA = infoPtr->idA();
int idB = infoPtr->idB();
double eCM = infoPtr->eCM();
if (beamHasGamma) {
int idAin = beamA2gamma ? 22 : idA;
int idBin = beamB2gamma ? 22 : idB;
sigmaTotPtr->calc( idAin, idBin, eCM);
sigmaND = sigmaTotPtr->sigmaND();
} else {
// Usage of both sigmaTotPtr and sigmaCmbPtr to be fixed in the future.
sigmaTotPtr->calc( idA, idB, eCM);
double mA = particleDataPtr->m0(idA);
double mB = particleDataPtr->m0(idB);
sigmaND = sigmaCmbPtr->sigmaPartial(idA, idB, eCM, mA, mB, 1);
}
// Starting values for potential future energy/beam switch.
switchedID = false;
switchedEcm = false;
eCMold = eCM;
// Check whether Hidden Valley colours may be used.
useHVcols = (settings.mode("HiddenValley:Ngauge") > 1);
// Options to allow second hard interaction and resonance decays.
doSecondHard = settings.flag("SecondHard:generate");
doSameCuts = settings.flag("PhaseSpace:sameForSecond");
doResDecays = settings.flag("ProcessLevel:resonanceDecays");
startColTag = settings.mode("Event:startColTag");
maxPDFreweight = settings.parm("SecondHard:maxPDFreweight");
// Check whether ISR or MPI applied. Affects processes with photon beams.
doISR = ( settings.flag("PartonLevel:ISR")
&& settings.flag("PartonLevel:all") );
doMPI = ( settings.flag("PartonLevel:MPI")
&& settings.flag("PartonLevel:all") );
// Second interaction not to be combined with biased phase space.
if (doSecondHard && userHooksPtr != 0
&& userHooksPtr->canBiasSelection()) {
loggerPtr->ERROR_MSG(
"cannot combine second interaction with biased phase space");
return false;
}
// Mass and pT cuts for two hard processes.
mHatMin1 = settings.parm("PhaseSpace:mHatMin");
mHatMax1 = settings.parm("PhaseSpace:mHatMax");
if (mHatMax1 < mHatMin1) mHatMax1 = eCM;
pTHatMin1 = settings.parm("PhaseSpace:pTHatMin");
pTHatMax1 = settings.parm("PhaseSpace:pTHatMax");
if (pTHatMax1 < pTHatMin1) pTHatMax1 = eCM;
mHatMin2 = settings.parm("PhaseSpace:mHatMinSecond");
mHatMax2 = settings.parm("PhaseSpace:mHatMaxSecond");
if (mHatMax2 < mHatMin2) mHatMax2 = eCM;
pTHatMin2 = settings.parm("PhaseSpace:pTHatMinSecond");
pTHatMax2 = settings.parm("PhaseSpace:pTHatMaxSecond");
if (pTHatMax2 < pTHatMin2) pTHatMax2 = eCM;
// Check whether mass and pT ranges agree or overlap.
cutsAgree = doSameCuts;
if (mHatMin2 == mHatMin1 && mHatMax2 == mHatMax1 && pTHatMin2 == pTHatMin1
&& pTHatMax2 == pTHatMax1) cutsAgree = true;
cutsOverlap = cutsAgree;
if (!cutsAgree) {
bool mHatOverlap = (max( mHatMin1, mHatMin2)
< min( mHatMax1, mHatMax2));
bool pTHatOverlap = (max( pTHatMin1, pTHatMin2)
< min( pTHatMax1, pTHatMax2));
if (mHatOverlap && pTHatOverlap) cutsOverlap = true;
}
// Set up containers for all the internal hard processes.
SetupContainers setupContainers;
setupContainers.init(containerPtrs, infoPtr);
// Append containers for external hard processes, if any.
if (sigmaPtrs.size() > 0) {
for (int iSig = 0; iSig < int(sigmaPtrs.size()); ++iSig) {
containerPtrs.push_back( new ProcessContainer(sigmaPtrs[iSig],
phaseSpacePtrs[iSig]) );
containerPtrs.back()->initInfoPtr(*infoPtr);
}
}
// Append single container for Les Houches processes, if any.
if (doLHA) {
SigmaProcessPtr sigmaPtr = make_shared<SigmaLHAProcess>();
containerPtrs.push_back( new ProcessContainer(sigmaPtr) );
containerPtrs.back()->initInfoPtr(*infoPtr);
// Store location of this container, and send in LHA pointer.
iLHACont = containerPtrs.size() - 1;
containerPtrs[iLHACont]->setLHAPtr(lhaUpPtr);
}
// If no processes found then refuse to do anything.
if ( int(containerPtrs.size()) == 0) {
loggerPtr->ERROR_MSG("no process switched on");
return false;
}
// Check whether pT-based weighting in 2 -> 2 is requested.
bool bias2Sel = false;
if (settings.flag("PhaseSpace:bias2Selection")) {
if (sigmaPtrs.size() == 0 && !doLHA && !doSecondHard) {
bias2Sel = true;
for (int i = 0; i < int(containerPtrs.size()); ++i) {
if (containerPtrs[i]->nFinal() != 2) bias2Sel = false;
int code = containerPtrs[i]->code();
if (code > 100 && code < 110) bias2Sel = false;
}
}
if (!bias2Sel) {
loggerPtr->ERROR_MSG("requested event weighting not possible");
return false;
}
}
// Check that SUSY couplings were indeed initialized where necessary.
bool hasSUSY = false;
for (int i = 0; i < int(containerPtrs.size()); ++i)
if (containerPtrs[i]->isSUSY()) hasSUSY = true;
// If SUSY processes requested but no SUSY couplings present
if (hasSUSY && !coupSUSYPtr->isSUSY) {
loggerPtr->ERROR_MSG(
"SUSY process switched on but no SUSY couplings found");
return false;
}
// Initialize each process.
int numberOn = 0;
for (int i = 0; i < int(containerPtrs.size()); ++i)
if (containerPtrs[i]->init(true, &resonanceDecays, slhaInterfacePtr,
&gammaKin))
++numberOn;
// Sum maxima for Monte Carlo choice.
sigmaMaxSum = 0.;
for (int i = 0; i < int(containerPtrs.size()); ++i)
sigmaMaxSum += containerPtrs[i]->sigmaMax();
// Option to pick a second hard interaction: repeat as above.
int number2On = 0;
if (doSecondHard) {
setupContainers.init2(container2Ptrs, infoPtr);
if ( int(container2Ptrs.size()) == 0) {
loggerPtr->ERROR_MSG("no second hard process switched on");
return false;
}
for (int i2 = 0; i2 < int(container2Ptrs.size()); ++i2)
if (container2Ptrs[i2]->init(false, &resonanceDecays,
slhaInterfacePtr, &gammaKin)) ++number2On;
sigma2MaxSum = 0.;
for (int i2 = 0; i2 < int(container2Ptrs.size()); ++i2)
sigma2MaxSum += container2Ptrs[i2]->sigmaMax();
}
// Check whether to create event weight from components.
doWt2 = !doLHA && !bias2Sel && !settings.flag("PhaseSpace:increaseMaximum");
// Printout during initialization is optional.
if (settings.flag("Init:showProcesses")) {
// Construct string with incoming beams and for cm energy.
string collision = "We collide " + particleDataPtr->name(idA)
+ " with " + particleDataPtr->name(idB) + " at a CM energy of ";
string pad( max( 0, 51 - int(collision.length())), ' ');
// Print initialization information: header.
cout << "\n *------- PYTHIA Process Initialization ---------"
<< "-----------------*\n"
<< " | "
<< " |\n"
<< " | " << collision << scientific << setprecision(3)
<< setw(9) << eCM << " GeV" << pad << " |\n"
<< " | "
<< " |\n"
<< " |---------------------------------------------------"
<< "---------------|\n"
<< " | "
<< " | |\n"
<< " | Subprocess Code"
<< " | Estimated |\n"
<< " | "
<< " | max (mb) |\n"
<< " | "
<< " | |\n"
<< " |---------------------------------------------------"
<< "---------------|\n"
<< " | "
<< " | |\n";
// Loop over existing processes: print individual process info.
map<int, double> sigmaMaxM;
map<int, string> nameM;
for (int i = 0; i < int(containerPtrs.size()); ++i) {
int code = containerPtrs[i]->code();
nameM[code] = containerPtrs[i]->name();
sigmaMaxM[code] = containerPtrs[i]->sigmaMax() > sigmaMaxM[code] ?
containerPtrs[i]->sigmaMax() : sigmaMaxM[code];
}
for (map<int, string>::iterator i = nameM.begin(); i != nameM.end(); ++i)
cout << " | " << left << setw(45) << i->second
<< right << setw(5) << i->first << " | "
<< scientific << setprecision(3) << setw(11)
<< sigmaMaxM[i->first] << " |\n";
// Loop over second hard processes, if any, and repeat as above.
if (doSecondHard) {
cout << " | "
<< " | |\n"
<< " |---------------------------------------------------"
<<"---------------|\n"
<< " | "
<<" | |\n";
sigmaMaxM.clear();
nameM.clear();
for (int i2 = 0; i2 < int(container2Ptrs.size()); ++i2) {
int code = container2Ptrs[i2]->code();
nameM[code] = container2Ptrs[i2]->name();
sigmaMaxM[code] = container2Ptrs[i2]->sigmaMax() > sigmaMaxM[code] ?
container2Ptrs[i2]->sigmaMax() : sigmaMaxM[code];
}
for (map<int, string>::iterator i2 = nameM.begin(); i2 != nameM.end();
++i2)
cout << " | " << left << setw(45) << i2->second
<< right << setw(5) << i2->first << " | "
<< scientific << setprecision(3) << setw(11)
<< sigmaMaxM[i2->first] << " |\n";
}
// Listing finished.
cout << " | "
<< " |\n"
<< " *------- End PYTHIA Process Initialization ----------"
<<"-------------*" << endl;
}
// If sum of maxima vanishes then refuse to do anything.
if ( numberOn == 0 || sigmaMaxSum <= 0.) {
loggerPtr->ERROR_MSG("all processes have vanishing cross sections");
return false;
}
if ( doSecondHard && (number2On == 0 || sigma2MaxSum <= 0.) ) {
loggerPtr->ERROR_MSG(
"all second hard processes have vanishing cross sections");
return false;
}
// If two hard processes then check whether some (but not all) agree.
allHardSame = true;
noneHardSame = true;
if (doSecondHard) {
bool foundMatch = false;
// Check for each first process if matched in second.
for (int i = 0; i < int(containerPtrs.size()); ++i) {
foundMatch = false;
if (cutsOverlap)
for (int i2 = 0; i2 < int(container2Ptrs.size()); ++i2)
if (container2Ptrs[i2]->code() == containerPtrs[i]->code())
foundMatch = true;
containerPtrs[i]->isSame( foundMatch );
if (!foundMatch) allHardSame = false;
if ( foundMatch) noneHardSame = false;
}
// Check for each second process if matched in first.
for (int i2 = 0; i2 < int(container2Ptrs.size()); ++i2) {
foundMatch = false;
if (cutsOverlap)
for (int i = 0; i < int(containerPtrs.size()); ++i)
if (containerPtrs[i]->code() == container2Ptrs[i2]->code())
foundMatch = true;
container2Ptrs[i2]->isSame( foundMatch );
if (!foundMatch) allHardSame = false;
if ( foundMatch) noneHardSame = false;
}
}
// Concluding classification, including cuts.
if (!cutsAgree) allHardSame = false;
someHardSame = !allHardSame && !noneHardSame;
// Done.
return true;
}
//--------------------------------------------------------------------------
// Switch to new beam particle identities.
void ProcessLevel::updateBeamIDs() {
// Update beam identities for phase space selection.
for (int i = 0; i < int(containerPtrs.size()); ++i)
containerPtrs[i]->updateBeamIDs();
if (doSecondHard) {
for (int i2 = 0; i2 < int(container2Ptrs.size()); ++i2)
container2Ptrs[i2]->updateBeamIDs();
}
switchedID = true;
}
//--------------------------------------------------------------------------
// Main routine to generate the hard process.
bool ProcessLevel::next( Event& process, int procTypeIn) {
// Save procType. Is almost always = 0.
procType = procTypeIn;
// Generate the next event with two or one hard interactions.
bool physical = (doSecondHard) ? nextTwo( process) : nextOne( process);
// Check that colour assignments make sense.
if (physical) physical = checkColours( process);
// Done.
return physical;
}
//--------------------------------------------------------------------------
// Generate (= read in) LHA input of resonance decay only.
bool ProcessLevel::nextLHAdec( Event& process) {
// Read resonance decays from LHA interface.
infoPtr->setEndOfFile(false);
if (!lhaUpPtr->setEvent()) {
infoPtr->setEndOfFile(true);
return false;
}
// Store LHA output in standard event record format.
containerLHAdec.constructDecays( process);
// Done.
return true;
}
//--------------------------------------------------------------------------
// Accumulate and update statistics (after possible user veto).
void ProcessLevel::accumulate( bool doAccumulate) {
// Increase number of accepted events.
if (doAccumulate) containerPtrs[iContainer]->accumulate();
// Provide current generated cross section estimate.
long nTrySum = 0;
long nSelSum = 0;
long nAccSum = 0;
double sigmaSum = 0.;
double delta2Sum = 0.;
double sigSelSum = 0.;
double weightSum = 0.;
int codeNow;
long nTryNow, nSelNow, nAccNow;
double sigmaNow, deltaNow, sigSelNow, weightNow;
map<int, bool> duplicate;
for (int i = 0; i < int(containerPtrs.size()); ++i)
if (containerPtrs[i]->sigmaMax() != 0.) {
codeNow = containerPtrs[i]->code();
nTryNow = containerPtrs[i]->nTried();
nSelNow = containerPtrs[i]->nSelected();
nAccNow = containerPtrs[i]->nAccepted();
sigmaNow = containerPtrs[i]->sigmaMC(doAccumulate);
deltaNow = containerPtrs[i]->deltaMC(doAccumulate);
sigSelNow = containerPtrs[i]->sigmaSelMC(doAccumulate);
weightNow = containerPtrs[i]->weightSum();
nTrySum += nTryNow;
nSelSum += nSelNow;
nAccSum += nAccNow;
sigmaSum += sigmaNow;
delta2Sum += pow2(deltaNow);
sigSelSum += sigSelNow;
weightSum += weightNow;
if (!doSecondHard) {
if (!duplicate[codeNow])
infoPtr->setSigma( codeNow, containerPtrs[i]->name(),
nTryNow, nSelNow, nAccNow, sigmaNow, deltaNow, weightNow);
else
infoPtr->addSigma( codeNow, nTryNow, nSelNow, nAccNow, sigmaNow,
deltaNow);
duplicate[codeNow] = true;
}
}
// Normally only one hard interaction. Then store info and done.
if (!doSecondHard) {
double deltaSum = sqrtpos(delta2Sum);
infoPtr->setSigma( 0, "sum", nTrySum, nSelSum, nAccSum, sigmaSum,
deltaSum, weightSum);
return;
}
// Increase counter for a second hard interaction.
if (doAccumulate) container2Ptrs[i2Container]->accumulate();
// Cross section estimate for second hard process.
double sigma2Sum = 0.;
double sig2SelSum = 0.;
for (int i2 = 0; i2 < int(container2Ptrs.size()); ++i2)
if (container2Ptrs[i2]->sigmaMax() != 0.) {
nTrySum += container2Ptrs[i2]->nTried();
if (doAccumulate) {
sigma2Sum += container2Ptrs[i2]->sigmaMC();
sig2SelSum += container2Ptrs[i2]->sigmaSelMC();
}
}
// Average impact-parameter factor.
double impactFac = max( 1., infoPtr->enhanceMPIavg() );
// Cross section estimate for combination of first and second process.
// Combine two possible ways and take average.
double sigmaCmb = 0.5 * (sigmaSum * sig2SelSum + sigSelSum * sigma2Sum)
* impactFac * maxPDFreweight / sigmaND;
if (allHardSame) sigmaCmb *= 0.5;
double deltaComb = (nAccSum == 0) ? 0. : sqrtpos(2. / nAccSum) * sigmaCmb;
// Store info and done.
infoPtr->setSigma( 0, "sum", nTrySum, nSelSum, nAccSum, sigmaCmb,
deltaComb, weightSum);
}
//--------------------------------------------------------------------------
// Print statistics on cross sections and number of events.
void ProcessLevel::statistics(bool reset) {
// Special processing if two hard interactions selected.
if (doSecondHard) {
statistics2(reset);
return;
}
// Header.
cout << "\n *------- PYTHIA Event and Cross Section Statistics ------"
<< "-------------------------------------------------------*\n"
<< " | "
<< " |\n"
<< " | Subprocess Code | "
<< " Number of events | sigma +- delta |\n"
<< " | | "
<< "Tried Selected Accepted | (estimated) (mb) |\n"
<< " | | "
<< " | |\n"
<< " |------------------------------------------------------------"
<< "-----------------------------------------------------|\n"
<< " | | "
<< " | |\n";
// Reset sum counters.
long nTrySum = 0;
long nSelSum = 0;
long nAccSum = 0;
double sigmaSum = 0.;
double delta2Sum = 0.;
// Reset process maps.
map<int, string> nameM;
map<int, long> nTryM, nSelM, nAccM;
map<int, double> sigmaM, delta2M;
vector<ProcessContainer*> lheContainerPtrs;
// Loop over existing processes.
for (int i = 0; i < int(containerPtrs.size()); ++i)
if (containerPtrs[i]->sigmaMax() != 0.) {
// Read info for process. Sum counters.
nTrySum += containerPtrs[i]->nTried();
nSelSum += containerPtrs[i]->nSelected();
nAccSum += containerPtrs[i]->nAccepted();
sigmaSum += containerPtrs[i]->sigmaMC();
delta2Sum += pow2(containerPtrs[i]->deltaMC());
// Skip Les Houches containers.
if (containerPtrs[i]->code() == 9999) {
lheContainerPtrs.push_back(containerPtrs[i]);
continue;
}
// Internal process info.
int code = containerPtrs[i]->code();
nameM[code] = containerPtrs[i]->name();
nTryM[code] += containerPtrs[i]->nTried();
nSelM[code] += containerPtrs[i]->nSelected();
nAccM[code] += containerPtrs[i]->nAccepted();
sigmaM[code] += containerPtrs[i]->sigmaMC();
delta2M[code]+= pow2(containerPtrs[i]->deltaMC());
}
// Print internal process info.
for (map<int, string>::iterator i = nameM.begin(); i != nameM.end(); ++i) {
int code = i->first;
cout << " | " << left << setw(45) << i->second
<< right << setw(5) << code << " | "
<< setw(11) << nTryM[code] << " " << setw(10) << nSelM[code] << " "
<< setw(10) << nAccM[code] << " | " << scientific << setprecision(3)
<< setw(11) << sigmaM[code]
<< setw(11) << sqrtpos(delta2M[code]) << " |\n";
}
// Print Les Houches process info.
for (int i = 0; i < int(lheContainerPtrs.size()); ++i) {
ProcessContainer *ptr = lheContainerPtrs[i];
cout << " | " << left << setw(45) << ptr->name()
<< right << setw(5) << ptr->code() << " | "
<< setw(11) << ptr->nTried() << " " << setw(10) << ptr->nSelected()
<< " " << setw(10) << ptr->nAccepted() << " | " << scientific
<< setprecision(3) << setw(11) << ptr->sigmaMC() << setw(11)
<< ptr->deltaMC() << " |\n";
// Print subdivision by user code for Les Houches process.
for (int j = 0; j < ptr->codeLHASize(); ++j)
cout << " | ... whereof user classification code " << setw(10)
<< ptr->subCodeLHA(j) << " | " << setw(11) << ptr->nTriedLHA(j)
<< " " << setw(10) << ptr->nSelectedLHA(j) << " " << setw(10)
<< ptr->nAcceptedLHA(j) << " | | \n";
}
// Print summed process info.
cout << " | | "
<< " | |\n"
<< " | " << left << setw(50) << "sum" << right << " | " << setw(11)
<< nTrySum << " " << setw(10) << nSelSum << " " << setw(10)
<< nAccSum << " | " << scientific << setprecision(3) << setw(11)
<< sigmaSum << setw(11) << sqrtpos(delta2Sum) << " |\n";
// Listing finished.
cout << " | "
<< " |\n"
<< " *------- End PYTHIA Event and Cross Section Statistics -----"
<< "-----------------------------------------------------*" << endl;
// Optionally reset statistics contants.
if (reset) resetStatistics();
}
//--------------------------------------------------------------------------
// Reset statistics on cross sections and number of events.
void ProcessLevel::resetStatistics() {
for (int i = 0; i < int(containerPtrs.size()); ++i)
containerPtrs[i]->reset();
if (doSecondHard)
for (int i2 = 0; i2 < int(container2Ptrs.size()); ++i2)
container2Ptrs[i2]->reset();
}
//--------------------------------------------------------------------------
// Generate the next event with one interaction.
bool ProcessLevel::nextOne( Event& process) {
// Update CM energy for phase space selection.
double eCM = infoPtr->eCM();
if (eCM != eCMold && doVarEcm) {
for (int i = 0; i < int(containerPtrs.size()); ++i)
containerPtrs[i]->newECM(eCM);
eCMold = eCM;
switchedEcm = true;
}
// New cross section values needed if switched id or updated energy.
if (switchedID || switchedEcm) {
sigmaMaxSum = 0.;
for (int i = 0; i < int(containerPtrs.size()); ++i) {
sigmaMaxSum += containerPtrs[i]->sigmaMaxSwitch();
}
switchedID = false;
switchedEcm = false;
}
// Outer loop in case of rare failures.
bool physical = true;
for (int loop = 0; loop < MAXLOOP; ++loop) {
if (!physical) process.clear();
physical = true;
// Loop over tries until trial event succeeds.
for ( ; ; ) {
// Pick one of the subprocesses.
if (procType == 0) {
double sigmaMaxNow = sigmaMaxSum * rndmPtr->flat();
int iMax = containerPtrs.size() - 1;
iContainer = -1;
do sigmaMaxNow -= containerPtrs[++iContainer]->sigmaMax();
while (sigmaMaxNow > 0. && iContainer < iMax);
// Special forced subprocess. Only for variable-energy SoftQCD.
} else {
iContainer = -1;
for (int iC = 0; iC < int(containerPtrs.size()); ++iC)
if (containerPtrs[iC]->code() == 100 + procType)
iContainer = iC;
if (iContainer == -1) {
loggerPtr->ERROR_MSG("requested procType unavailable");
continue;
}
}
// Do a trial event of this subprocess; accept or not.
if (containerPtrs[iContainer]->trialProcess()) break;
// Check for end-of-file condition for Les Houches events.
if (infoPtr->atEndOfFile()) return false;
}
// Update sum of maxima if current maximum violated.
if (containerPtrs[iContainer]->newSigmaMax()) {
sigmaMaxSum = 0.;
for (int i = 0; i < int(containerPtrs.size()); ++i)
sigmaMaxSum += containerPtrs[i]->sigmaMax();
}
// Construct kinematics of acceptable process.
containerPtrs[iContainer]->constructState();
if ( !containerPtrs[iContainer]->constructProcess( process) )
physical = false;
// For photon beams from leptons copy the state to additional photon beams.
if (beamHasGamma) {
beamGamAPtr->setGammaMode(beamAPtr->getGammaMode());
beamGamBPtr->setGammaMode(beamBPtr->getGammaMode());
}
// Do all resonance decays.
if ( physical && doResDecays
&& !containerPtrs[iContainer]->decayResonances( process) )
physical = false;
// Retry process for unphysical states.
for (int i =1; i < process.size(); ++i)
if (process[i].e() < 0.) {
loggerPtr->ERROR_MSG("constructed particle with negative energy");
physical = false;
}
// Add any junctions to the process event record list.
if (physical) findJunctions( process);
// Check that enough room for beam remnants in the photon beams and
// set the valence content for photon beams.
// Do not check for softQCD processes since no initiators yet.
if ( ( ( ( beamAPtr->isGamma() && !beamAPtr->isUnresolved() )
|| ( beamBPtr->isGamma() && !beamBPtr->isUnresolved() ) )
|| ( beamAPtr->hasResGamma() || beamBPtr->hasResGamma() ) )
&& !containerPtrs[iContainer]->isSoftQCD() ) {
if ( !roomForRemnants() ) {
physical = false;
continue;
}
}
// Outer loop should normally work first time around.
if (physical) break;
}
// Update information in VMD beams according to chosen state.
if (infoPtr->isVMDstateA()) {
beamVMDAPtr->setGammaMode(beamAPtr->getGammaMode());
beamVMDAPtr->setVMDstate(true, infoPtr->idVMDA(), infoPtr->mVMDA(),
infoPtr->scaleVMDA(), true);
}
if (infoPtr->isVMDstateB()) {
beamVMDBPtr->setGammaMode(beamBPtr->getGammaMode());
beamVMDBPtr->setVMDstate(true, infoPtr->idVMDB(), infoPtr->mVMDB(),
infoPtr->scaleVMDB(), true);
}
// Done.
return physical;
}
//--------------------------------------------------------------------------
// Generate the next event with two hard interactions.
bool ProcessLevel::nextTwo( Event& process) {
// Update CM energy for phase space selection.
double eCM = infoPtr->eCM();
for (int i = 0; i < int(containerPtrs.size()); ++i)
containerPtrs[i]->newECM(eCM);
for (int i2 = 0; i2 < int(container2Ptrs.size()); ++i2)
container2Ptrs[i2]->newECM(eCM);
// Outer loop in case of rare failures.
bool physical = true;
double wtViol1 = 1.;
double wtViol2 = 1.;
for (int loop = 0; loop < MAXLOOP; ++loop) {
if (!physical) process.clear();
physical = true;
// Loop over both hard processes to find consistent common kinematics.
for ( ; ; ) {
// Loop internally over tries for hardest process until succeeds.
for ( ; ; ) {
// Pick one of the subprocesses.
double sigmaMaxNow = sigmaMaxSum * rndmPtr->flat();
int iMax = containerPtrs.size() - 1;
iContainer = -1;
do sigmaMaxNow -= containerPtrs[++iContainer]->sigmaMax();
while (sigmaMaxNow > 0. && iContainer < iMax);
// Do a trial event of this subprocess; accept or not.
if (containerPtrs[iContainer]->trialProcess()) break;
// Check for end-of-file condition for Les Houches events.
if (infoPtr->atEndOfFile()) return false;
}
// Update sum of maxima if current maximum violated. Event weight.
if (containerPtrs[iContainer]->newSigmaMax()) {
sigmaMaxSum = 0.;
for (int i = 0; i < int(containerPtrs.size()); ++i)
sigmaMaxSum += containerPtrs[i]->sigmaMax();
}
wtViol1 = (doWt2) ? infoPtr->weight() : 1.;
// Loop internally over tries for second hardest process until succeeds.
for ( ; ; ) {
// Pick one of the subprocesses.
double sigma2MaxNow = sigma2MaxSum * rndmPtr->flat();
int i2Max = container2Ptrs.size() - 1;
i2Container = -1;
do sigma2MaxNow -= container2Ptrs[++i2Container]->sigmaMax();
while (sigma2MaxNow > 0. && i2Container < i2Max);
// Do a trial event of this subprocess; accept or not.
if (container2Ptrs[i2Container]->trialProcess()) break;
}
// Update sum of maxima if current maximum violated.
if (container2Ptrs[i2Container]->newSigmaMax()) {
sigma2MaxSum = 0.;
for (int i2 = 0; i2 < int(container2Ptrs.size()); ++i2)
sigma2MaxSum += container2Ptrs[i2]->sigmaMax();
}
wtViol2 = (doWt2) ? infoPtr->weight() : 1.;
// Pick incoming flavours (etc), needed for PDF reweighting.
containerPtrs[iContainer]->constructState();
container2Ptrs[i2Container]->constructState();
// Check whether common set of x values is kinematically possible.
double xA1 = containerPtrs[iContainer]->x1();
double xB1 = containerPtrs[iContainer]->x2();
double xA2 = container2Ptrs[i2Container]->x1();
double xB2 = container2Ptrs[i2Container]->x2();
if (xA1 + xA2 >= 1. || xB1 + xB2 >= 1.) continue;
// Parton densities for independent interactions.
int idA1 = containerPtrs[iContainer]->id1();
int idB1 = containerPtrs[iContainer]->id2();
int idA2 = container2Ptrs[i2Container]->id1();
int idB2 = container2Ptrs[i2Container]->id2();
double Q2Fac1 = containerPtrs[iContainer]->Q2Fac();
double Q2Fac2 = container2Ptrs[i2Container]->Q2Fac();
double pdfA1Raw = beamAPtr->xf( idA1, xA1,Q2Fac1);
double pdfB1Raw = beamBPtr->xf( idB1, xB1,Q2Fac1);
double pdfA2Raw = beamAPtr->xf( idA2, xA2,Q2Fac2);
double pdfB2Raw = beamBPtr->xf( idB2, xB2,Q2Fac2);
// Reset beam contents. Remove partons in second interaction from beams,
// and reevaluate pdf's for first interaction.
beamAPtr->clear();
beamBPtr->clear();
beamAPtr->append( 3, idA2, xA2);
beamAPtr->xfISR( 0, idA2, xA2, Q2Fac2);
beamAPtr->pickValSeaComp();
beamBPtr->append( 4, idB2, xB2);
beamBPtr->xfISR( 0, idB2, xB2, Q2Fac2);
beamBPtr->pickValSeaComp();
double pdfA1Mod = beamAPtr->xfMPI( idA1, xA1,Q2Fac1);
double pdfB1Mod = beamBPtr->xfMPI( idB1, xB1,Q2Fac1);
// Reset beam contents. Remove partons in first interaction from beams,
// and reevaluate pdf's for second interaction.
beamAPtr->clear();
beamBPtr->clear();
beamAPtr->append( 3, idA1, xA1);
beamAPtr->xfISR( 0, idA1, xA1, Q2Fac1);
beamAPtr->pickValSeaComp();
beamBPtr->append( 4, idB1, xB1);
beamBPtr->xfISR( 0, idB1, xB1, Q2Fac1);
beamBPtr->pickValSeaComp();
double pdfA2Mod = beamAPtr->xfMPI( idA2, xA2,Q2Fac2);
double pdfB2Mod = beamBPtr->xfMPI( idB2, xB2,Q2Fac2);
// Define modified PDF weight as average of two orderings above.
double wtPdf1 = (pdfA1Mod * pdfB1Mod) / (pdfA1Raw * pdfB1Raw);
double wtPdf2 = (pdfA2Mod * pdfB2Mod) / (pdfA2Raw * pdfB2Raw);
double wtPdfSame = 0.5 * (wtPdf1 + wtPdf2);
// Reduce by a factor of 2 for identical processes when others not,
// and when in same phase space region.
if ( someHardSame && containerPtrs[iContainer]->isSame()
&& container2Ptrs[i2Container]->isSame()) {
if (cutsAgree) wtPdfSame *= 0.5;
else {
double mHat1 = containerPtrs[iContainer]->mHat();
double pTHat1 = containerPtrs[iContainer]->pTHat();
double mHat2 = container2Ptrs[i2Container]->mHat();
double pTHat2 = container2Ptrs[i2Container]->pTHat();
if (mHat1 > mHatMin2 && mHat1 < mHatMax2
&& pTHat1 > pTHatMin2 && pTHat1 < pTHatMax2
&& mHat2 > mHatMin1 && mHat2 < mHatMax1
&& pTHat2 > pTHatMin1 && pTHat2 < pTHatMax1) wtPdfSame *= 0.5;
}
}
// Hit-and-miss to compensate for PDF weights. Catch maximum violation.
wtPdfSame *= wtViol1 * wtViol2 / maxPDFreweight;
if (doWt2) infoPtr->setWeight( max( 1., wtPdfSame), 0 );
if (wtPdfSame > 1.) loggerPtr->WARNING_MSG(
"joint PDF correction gives weight above unity");
if (wtPdfSame < rndmPtr->flat()) continue;
// If come this far then acceptable event.
break;
}
// Construct kinematics of acceptable processes.
Event process2;
process2.init( "(second hard)", particleDataPtr, startColTag);
process2.initColTag();
if ( !containerPtrs[iContainer]->constructProcess( process) )
physical = false;
if (physical && !container2Ptrs[i2Container]->constructProcess( process2,
false) ) physical = false;
// Do all resonance decays.
if ( physical && doResDecays
&& !containerPtrs[iContainer]->decayResonances( process) )
physical = false;
if ( physical && doResDecays
&& !container2Ptrs[i2Container]->decayResonances( process2) )
physical = false;
// Append second hard interaction to normal process object.
if (physical) {
combineProcessRecords( process, process2);
// Add any junctions to the process event record list.
findJunctions( process);
// Outer loop should normally work first time around.
break;
}
}
// Done.
return physical;
}
//--------------------------------------------------------------------------
// Check that enough room for beam remnants is left and fix the valence
// content for photon beams.
bool ProcessLevel::roomForRemnants() {
// Set the beamParticle pointers to photon beams.
bool beamAhasResGamma = beamAPtr->hasResGamma();
bool beamBhasResGamma = beamBPtr->hasResGamma();
bool beamHasResGamma = beamAhasResGamma || beamBhasResGamma;
BeamParticle* tmpBeamAPtr = beamAhasResGamma ? beamGamAPtr : beamAPtr;
BeamParticle* tmpBeamBPtr = beamBhasResGamma ? beamGamBPtr : beamBPtr;
// Check whether photons are unresolved.
bool resGammaA = !(beamGamAPtr->isUnresolved());
bool resGammaB = !(beamGamBPtr->isUnresolved());
// Get the x_gamma values from beam particle.
double xGamma1 = beamAPtr->xGamma();
double xGamma2 = beamBPtr->xGamma();
// Clear the previous choice.
tmpBeamAPtr->posVal(-1);
tmpBeamBPtr->posVal(-1);
// Store the relevant information.
int id1 = containerPtrs[iContainer]->id1();
int id2 = containerPtrs[iContainer]->id2();
double x1 = containerPtrs[iContainer]->x1();
double x2 = containerPtrs[iContainer]->x2();
double Q2 = containerPtrs[iContainer]->Q2Fac();
// Invariant mass of gamma-gamma system.
double eCMgmgm = infoPtr->eCM();
// If photon(s) from beam particle(s) use the derived gmgm CM energy.
if (beamHasResGamma) eCMgmgm = infoPtr->eCMsub();
// Calculate the mT left for the beams after hard interaction.
double mTRem = 0;
// Direct-resolved processes with photons from lepton beams.
if ( resGammaA != resGammaB && beamHasResGamma ) {
double wTot = infoPtr->eCMsub();
double w2scat = infoPtr->sHatNew();
mTRem = wTot - sqrt(w2scat);
// Direct-resolved processes with photons beams.
} else if ( tmpBeamAPtr->isUnresolved() && !tmpBeamBPtr->isUnresolved() ) {
mTRem = eCMgmgm*( 1. - sqrt( x2) );
} else if ( !tmpBeamAPtr->isUnresolved() && tmpBeamBPtr->isUnresolved() ) {