-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythia.cc
2275 lines (1891 loc) · 77.1 KB
/
Pythia.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
// Pythia.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 Pythia class.
#include "Pythia8/Pythia.h"
#include "Pythia8/ColourReconnection.h"
#include "Pythia8/Dire.h"
#include "Pythia8/HeavyIons.h"
#include "Pythia8/History.h"
#include "Pythia8/StringInteractions.h"
#include "Pythia8/Vincia.h"
#include "Pythia8/Plugins.h"
namespace Pythia8 {
//==========================================================================
// The Pythia class.
//--------------------------------------------------------------------------
// The current Pythia (sub)version number, to agree with XML version.
const double Pythia::VERSIONNUMBERHEAD = PYTHIA_VERSION;
const double Pythia::VERSIONNUMBERCODE = 8.312;
//--------------------------------------------------------------------------
// Constructor.
Pythia::Pythia(string xmlDir, bool printBanner) {
// Initialise / reset pointers and global variables.
initPtrs();
// Find path to data files, i.e. xmldoc directory location.
// Environment variable takes precedence, then constructor input,
// and finally the pre-processor constant XMLDIR.
const char* envPath = getenv("PYTHIA8DATA");
xmlPath = envPath ? envPath : "";
if (xmlPath == "") {
if (xmlDir.length() && xmlDir[xmlDir.length() - 1] != '/') xmlDir += "/";
xmlPath = xmlDir;
ifstream xmlFile((xmlPath + "Index.xml").c_str());
if (!xmlFile.good()) xmlPath = XMLDIR;
xmlFile.close();
}
if (xmlPath.empty() || (xmlPath.length() && xmlPath[xmlPath.length() - 1]
!= '/')) xmlPath += "/";
// Read in files with all flags, modes, parms and words.
settings.initPtrs(&logger);
string initFile = xmlPath + "Index.xml";
isConstructed = settings.init( initFile);
if (!isConstructed) {
logger.ABORT_MSG("settings unavailable");
return;
}
// Save XML path in settings.
settings.addWord("xmlPath", xmlPath);
// Allow include files to be saved to settings.
settings.addWord("include", "");
// Check that XML and header version numbers match code version number.
if (!checkVersion()) return;
// Read in files with all particle data.
particleData.initPtrs( &infoPrivate);
string dataFile = xmlPath + "ParticleData.xml";
isConstructed = particleData.init( dataFile);
if (!isConstructed) {
logger.ABORT_MSG("particle data unavailable");
return;
}
// Write the Pythia banner to output.
if (printBanner) banner();
// Not initialized until at the end of the init() call.
isInit = false;
infoPrivate.addCounter(0);
// Special settings needed for heavy ion setup.
HeavyIons::addSpecialSettings(settings);
}
//--------------------------------------------------------------------------
// Constructor from pre-initialised ParticleData and Settings objects.
Pythia::Pythia(Settings& settingsIn, ParticleData& particleDataIn,
bool printBanner) {
// Initialise / reset pointers and global variables.
initPtrs();
// Copy XML path from existing Settings database.
xmlPath = settingsIn.word("xmlPath");
// Copy settings database and redirect pointers.
settings = settingsIn;
settings.initPtrs(&logger);
isConstructed = settings.getIsInit();
if (!isConstructed) {
logger.ABORT_MSG("settings unavailable");
return;
}
// Check XML and header version numbers match code version number.
if (!checkVersion()) return;
// Copy particleData database and redirect pointers.
particleData = particleDataIn;
particleData.initPtrs( &infoPrivate);
isConstructed = particleData.getIsInit();
if (!isConstructed) {
logger.ABORT_MSG("particle data unavailable");
return;
}
// Write the Pythia banner to output.
if (printBanner) banner();
// Not initialized until at the end of the init() call.
isInit = false;
infoPrivate.addCounter(0);
}
//--------------------------------------------------------------------------
// Constructor from string streams.
Pythia::Pythia( istream& settingsStrings, istream& particleDataStrings,
bool printBanner) {
// Initialise / reset pointers and global variables.
initPtrs();
// Copy settings database
settings.init( settingsStrings );
// Reset pointers to pertain to this PYTHIA object.
settings.initPtrs( &logger);
isConstructed = settings.getIsInit();
if (!isConstructed) {
logger.ABORT_MSG("settings unavailable");
return;
}
// Check XML and header version numbers match code version number.
if (!checkVersion()) return;
// Read in files with all particle data.
particleData.initPtrs( &infoPrivate);
isConstructed = particleData.init( particleDataStrings );
if (!isConstructed) {
logger.ABORT_MSG("particle data unavailable");
return;
}
// Write the Pythia banner to output.
if (printBanner) banner();
// Not initialized until at the end of the init() call.
isInit = false;
infoPrivate.addCounter(0);
}
//--------------------------------------------------------------------------
// Initialise new Pythia object (common code called by constructors).
void Pythia::initPtrs() {
// Setup of Info.
infoPrivate.setPtrs( &settings, &particleData, &logger, &rndm, &beamSetup,
&coupSM, &coupSUSY, &partonSystems, &sigmaTot, &sigmaCmb,
&hadronWidths, &weightContainer);
registerPhysicsBase(processLevel);
registerPhysicsBase(partonLevel);
registerPhysicsBase(trialPartonLevel);
registerPhysicsBase(hadronLevel);
registerPhysicsBase(sigmaTot);
registerPhysicsBase(nucleonExcitations);
registerPhysicsBase(sigmaLowEnergy);
registerPhysicsBase(sigmaCmb);
registerPhysicsBase(hadronWidths);
registerPhysicsBase(junctionSplitting);
registerPhysicsBase(rHadrons);
registerPhysicsBase(beamSetup);
}
//--------------------------------------------------------------------------
// Initialise user provided plugins.
void Pythia::initPlugins() {
// Create map of pointers to pass to Pythia.
map<string, PDFPtr> pdfs = beamSetup.getPDFPtr();
// Store the previous plugin type.
string objLast;
// Loop over the plugins.
for (string plugin : settings.wvec("Init:plugins")) {
// Split by the plugin entry by the "::" delimiter.
vector<string> vals;
size_t pos(0);
string cmnd(plugin);
while (pos != string::npos) {
pos = plugin.find("::");
vals.push_back(plugin.substr(0, pos));
plugin = plugin.substr(pos + 2);
}
if (vals.size() < 2) {
logger.ERROR_MSG("plugin setting " + plugin +
" must at least specify library and class");
continue;
}
string libName(vals[0]), className(vals[1]), key("default"), fileName("");
int sub(SUBRUNDEFAULT);
if (vals.size() > 2) key = vals[2];
if (vals.size() > 3) fileName = vals[3];
if (vals.size() > 4) sub = stoi(vals[4]);
// Determine the plugin type.
shared_ptr<void> libPtr = dlopen_plugin(libName, &logger);
if (libPtr == nullptr) continue;
string objType = type_plugin(libName, className, &logger);
if (objType == "") continue;
// Handle the case of a PDF plugin.
if (objType == typeid(PDF).name()) {
// If default beam type, set both A and B.
if (key == "default") {
for (string keyNow : {"A", "B"}) {
if (pdfs[keyNow] != nullptr)
logger.WARNING_MSG("replacing PDF pointer " + keyNow);
pdfs[keyNow] = make_plugin<PDF>(
libName, className, this, fileName, sub);
}
continue;
}
// Otherwise, set the specified PDF beam.
if (pdfs.find(key) == pdfs.end()) {
logger.ERROR_MSG("cannot set unknown PDF pointer " + key);
continue;
} else if (pdfs[key] != nullptr)
logger.WARNING_MSG("replacing PDF pointer " + key);
pdfs[key] = make_plugin<PDF>(
libName, className, this, fileName, sub);
continue;
}
// Check if the plugin should be set or added.
if (key == "default") key = "set";
if (key != "set" && key != "add") {
logger.ERROR_MSG("the third argument must be set or add");
continue;
}
// Load the other plugin types and set appropriately.
if (vals.size() > 3) fileName = vals[3];
if (vals.size() > 4) sub = stoi(vals[4]);
if (objType == typeid(LHAup).name()) {setLHAupPtr(
make_plugin<LHAup>(libName, className, this, fileName, sub));
} else if (objType == typeid(DecayHandler).name()) {setDecayPtr(
make_plugin<DecayHandler>(libName, className, this, fileName, sub));
} else if (objType == typeid(RndmEngine).name()) {setRndmEnginePtr(
make_plugin<RndmEngine>(libName, className, this, fileName, sub));
} else if (objType == typeid(UserHooks).name()) {
if (key == "add") addUserHooksPtr(
make_plugin<UserHooks>(libName, className, this, fileName, sub));
else setUserHooksPtr(
make_plugin<UserHooks>(libName, className, this, fileName, sub));
} else if (objType == typeid(Merging).name()) {setMergingPtr(
make_plugin<Merging>(libName, className, this, fileName, sub));
} else if (objType == typeid(MergingHooks).name()) {setMergingHooksPtr(
make_plugin<MergingHooks>(libName, className, this, fileName, sub));
} else if (objType == typeid(BeamShape).name()) {setBeamShapePtr(
make_plugin<BeamShape>(libName, className, this, fileName, sub));
} else if (objType == typeid(SigmaProcess).name()) {
if (key == "add") addSigmaPtr(
make_plugin<SigmaProcess>(libName, className, this, fileName, sub));
else setSigmaPtr(
make_plugin<SigmaProcess>(libName, className, this, fileName, sub));
} else if (objType == typeid(PhaseSpace).name() &&
objLast == typeid(SigmaProcess).name()) {
SigmaProcessPtr sigmaPtr = sigmaPtrs.back();
if (key == "add") {sigmaPtrs.pop_back(); phaseSpacePtrs.pop_back();}
else {sigmaPtrs.resize(0); phaseSpacePtrs.resize(0);}
addSigmaPtr(sigmaPtr,
make_plugin<PhaseSpace>(libName, className, this, fileName, sub));
} else if (objType == typeid(ResonanceWidths).name()) {
if (key == "add") addResonancePtr(
make_plugin<ResonanceWidths>(libName, className, this, fileName, sub));
else setResonancePtr(
make_plugin<ResonanceWidths>(libName, className, this, fileName, sub));
} else if (objType == typeid(ShowerModel).name()) {setShowerModelPtr(
make_plugin<ShowerModel>(libName, className, this, fileName, sub));
} else if (objType == typeid(HeavyIons).name()) {setHeavyIonsPtr(
make_plugin<HeavyIons>(libName, className, this, fileName, sub));
} else if (objType == typeid(HIUserHooks).name()) {setHIHooks(
make_plugin<HIUserHooks>(libName, className, this, fileName, sub));
} else {logger.ERROR_MSG("the class " + demangle(objType) + " cannot be "
"passed to a Pythia object");
}
objLast = objType;
}
// Set the PDF pointers.
setPDFPtr(pdfs["A"], pdfs["B"], pdfs["HardA"], pdfs["HardB"],
pdfs["PomA"], pdfs["PomB"], pdfs["GamA"], pdfs["GamB"],
pdfs["HardGamA"], pdfs["HardGamB"], pdfs["UnresA"], pdfs["UnresB"],
pdfs["UnresGamA"], pdfs["UnresGamB"], pdfs["VMDA"], pdfs["VMDB"]);
}
//--------------------------------------------------------------------------
// Check for consistency of version numbers (called by constructors).
bool Pythia::checkVersion() {
// Check that XML version number matches code version number.
double versionNumberXML = parm("Pythia:versionNumber");
isConstructed = (abs(versionNumberXML - VERSIONNUMBERCODE) < 0.0005);
if (!isConstructed) {
ostringstream errCode;
errCode << fixed << setprecision(3) << ": in code " << VERSIONNUMBERCODE
<< " but in XML " << versionNumberXML;
logger.ABORT_MSG("unmatched version numbers", errCode.str());
return false;
}
// Check that header version number matches code version number.
isConstructed = (abs(VERSIONNUMBERHEAD - VERSIONNUMBERCODE) < 0.0005);
if (!isConstructed) {
ostringstream errCode;
errCode << fixed << setprecision(3) << ": in code " << VERSIONNUMBERCODE
<< " but in header " << VERSIONNUMBERHEAD;
logger.ABORT_MSG("unmatched version numbers", errCode.str());
return false;
}
// All is well that ends well.
return true;
}
//--------------------------------------------------------------------------
// Read in one update for a setting or particle data from a single line.
bool Pythia::readString(string line, bool warn, int subrun) {
// Check that constructor worked.
if (!isConstructed) return false;
// If empty line then done.
if (line.find_first_not_of(" \n\t\v\b\r\f\a") == string::npos) return true;
// If Settings input stretches over several lines then continue with it.
if (settings.unfinishedInput()) return settings.readString(line, warn);
// If first character is not a letter/digit, then taken to be a comment.
int firstChar = line.find_first_not_of(" \n\t\v\b\r\f\a");
if (!isalnum(line[firstChar])) return true;
// Send on particle data to the ParticleData database.
if (isdigit(line[firstChar])) {
bool passed = particleData.readString(line, warn);
if (passed) particleDataBuffer << line << endl;
return passed;
}
// Include statements.
if (line.find("include") == 0 && settings.readString(line, warn) &&
word("include") != "") {
// Try normal path first.
string fileName = word("include");
settings.word("include", "");
ifstream isUser(fileName.c_str());
if (!isUser.good()) {
// Split the paths from PYTHIA8CMND.
vector<string> paths;
size_t pos(0);
const char* envChar = getenv("PYTHIA8CMND");
string envPath = envChar ? envChar : "";
while (envPath != "" && pos != string::npos) {
pos = envPath.find(":");
paths.push_back(envPath.substr(0, pos));
envPath = envPath.substr(pos + 1);
}
// Add the Pythia settings directory.
paths.push_back(word("xmlPath"). substr(0, xmlPath.length() - 7)
+ "settings");
// Try the different paths.
for (string path : paths) {
ifstream isPath((path + "/" + fileName).c_str());
if (isPath.good()) return readFile(isPath, warn, subrun);
}
logger.ERROR_MSG("did not find file", fileName);
return false;
} else return readFile(isUser, warn, subrun);
}
// Everything else sent on to Settings.
return settings.readString(line, warn);
}
//--------------------------------------------------------------------------
// Read in updates for settings or particle data from user-defined file.
bool Pythia::readFile(string fileName, bool warn, int subrun) {
// Check that constructor worked.
if (!isConstructed) return false;
// Open file for reading.
ifstream is(fileName.c_str());
if (!is.good()) {
logger.ERROR_MSG("did not find file", fileName);
return false;
}
// Hand over real work to next method.
return readFile( is, warn, subrun);
}
//--------------------------------------------------------------------------
// Read in updates for settings or particle data
// from user-defined stream (or file).
bool Pythia::readFile(istream& is, bool warn, int subrun) {
// Check that constructor worked.
if (!isConstructed) return false;
// Read in one line at a time.
string line;
bool isCommented = false;
bool accepted = true;
int subrunNow = SUBRUNDEFAULT;
while ( getline(is, line) ) {
// Check whether entering, leaving or inside commented-commands section.
int commentLine = readCommented( line);
if (commentLine == +1) isCommented = true;
else if (commentLine == -1) isCommented = false;
else if (isCommented) ;
else {
// Check whether entered new subrun.
int subrunLine = readSubrun( line, warn);
if (subrunLine >= 0) subrunNow = subrunLine;
// Process the line if in correct subrun.
if ( (subrunNow == subrun || subrunNow == SUBRUNDEFAULT)
&& !readString( line, warn) ) accepted = false;
}
// Reached end of input file.
};
return accepted;
}
//--------------------------------------------------------------------------
// Routine to initialize with the variable values of the Beams kind.
bool Pythia::init() {
// Check that constructor worked.
if (!isConstructed) {
logger.ABORT_MSG("constructor initialization failed");
isInit = false;
return false;
}
// Check if this is the first call to init.
if (isInit)
logger.WARNING_MSG("be aware that successive "
"calls to init() do not clear previous settings");
// Only create plugins the first time.
else initPlugins();
isInit = false;
// Early catching of heavy ion mode.
doHeavyIons = HeavyIons::isHeavyIon(settings) || mode("HeavyIon:mode") == 2;
if ( doHeavyIons ) {
if ( !heavyIonsPtr ) heavyIonsPtr = make_shared<Angantyr>(*this);
registerPhysicsBase(*heavyIonsPtr);
if ( hiHooksPtr ) heavyIonsPtr->setHIUserHooksPtr(hiHooksPtr);
if ( !heavyIonsPtr->init() ) {
doHeavyIons = false;
isInit = false;
logger.ABORT_MSG("the heavy ion model "
"failed to initialize. Double check settings");
return false;
}
}
// Early readout, if return false or changed when no beams.
doProcessLevel = flag("ProcessLevel:all");
// Check that changes in Settings and ParticleData have worked.
if (settings.unfinishedInput()) {
logger.ABORT_MSG("opening { not matched by closing }");
return false;
}
if (settings.readingFailed()) {
logger.ABORT_MSG("some user settings did not make sense");
return false;
}
if (particleData.readingFailed()) {
logger.ABORT_MSG("some user particle data did not make sense");
return false;
}
// Initialize error printing settings.
logger.init(settings);
// Initialize the random number generator.
if ( flag("Random:setSeed") ) rndm.init( mode("Random:seed") );
else rndm.init(Rndm::DEFAULTSEED);
// Count up number of initializations.
infoPrivate.addCounter(1);
// Master choice of shower model.
int showerModel = mode("PartonShowers:model");
// Set up values related to CKKW-L merging.
bool doUserMerging = flag("Merging:doUserMerging");
bool doMGMerging = flag("Merging:doMGMerging");
bool doKTMerging = flag("Merging:doKTMerging");
bool doPTLundMerging = flag("Merging:doPTLundMerging");
bool doCutBasedMerging = flag("Merging:doCutBasedMerging");
// Set up values related to unitarised CKKW merging
bool doUMEPSTree = flag("Merging:doUMEPSTree");
bool doUMEPSSubt = flag("Merging:doUMEPSSubt");
// Set up values related to NL3 NLO merging
bool doNL3Tree = flag("Merging:doNL3Tree");
bool doNL3Loop = flag("Merging:doNL3Loop");
bool doNL3Subt = flag("Merging:doNL3Subt");
// Set up values related to unitarised NLO merging
bool doUNLOPSTree = flag("Merging:doUNLOPSTree");
bool doUNLOPSLoop = flag("Merging:doUNLOPSLoop");
bool doUNLOPSSubt = flag("Merging:doUNLOPSSubt");
bool doUNLOPSSubtNLO = flag("Merging:doUNLOPSSubtNLO");
bool doXSectionEst = flag("Merging:doXSectionEstimate");
doMerging = doUserMerging || doMGMerging || doKTMerging
|| doPTLundMerging || doCutBasedMerging || doUMEPSTree || doUMEPSSubt
|| doNL3Tree || doNL3Loop || doNL3Subt || doUNLOPSTree
|| doUNLOPSLoop || doUNLOPSSubt || doUNLOPSSubtNLO || doXSectionEst;
doMerging = doMerging || flag("Merging:doMerging");
// If not using Vincia, Merging:Process must not be enclosed in {}.
if (doMerging && showerModel != 2) {
string mergingProc = word("Merging:Process");
if (mergingProc.front()=='{' && mergingProc.back() == '}') {
stringstream ss;
ss<<"invalid Merging:Process for PartonShower:Model = "<<showerModel;
logger.ABORT_MSG(ss.str());
return false;
}
}
// Set/Reset the weights
weightContainer.initPtrs(&infoPrivate);
weightContainer.init(doMerging);
// Set up MergingHooks object for simple shower model.
if (doMerging && showerModel == 1) {
if (!mergingHooksPtr) mergingHooksPtr = make_shared<MergingHooks>();
registerPhysicsBase(*mergingHooksPtr);
mergingHooksPtr->setLHEInputFile("");
}
// Set up Merging object for simple shower model.
if ( doMerging && showerModel == 1 && !mergingPtr ) {
mergingPtr = make_shared<Merging>();
registerPhysicsBase(*mergingPtr);
}
// Set up beams and kinematics.
if (!beamSetup.initFrame()) return false;
// Spread LHA information generated in initFrame.
doLHA = beamSetup.doLHA;
useNewLHA = beamSetup.useNewLHA;
lhaUpPtr = beamSetup.lhaUpPtr;
if (doLHA) processLevel.setLHAPtr( lhaUpPtr);
// Done if only new LHA file.
if (beamSetup.skipInit) {
isInit = true;
infoPrivate.addCounter(2);
return true;
}
// Store the name of the input LHEF for merging.
if ( (beamSetup.frameType == 4 || beamSetup.frameType == 5)
&& doMerging && showerModel == 1) {
string lhef = (beamSetup.frameType == 4) ? word("Beams:LHEF") : "";
mergingHooksPtr->setLHEInputFile( lhef);
}
// Set up values related to user hooks.
doVetoProcess = false;
doVetoPartons = false;
retryPartonLevel = false;
canVetoHadronization = false;
if ( userHooksPtr ) {
infoPrivate.userHooksPtr = userHooksPtr;
registerPhysicsBase(*userHooksPtr);
pushInfo();
if (!userHooksPtr->initAfterBeams()) {
logger.ABORT_MSG("could not initialise UserHooks");
return false;
}
doVetoProcess = userHooksPtr->canVetoProcessLevel();
doVetoPartons = userHooksPtr->canVetoPartonLevel();
retryPartonLevel = userHooksPtr->retryPartonLevel();
canVetoHadronization = userHooksPtr->canVetoAfterHadronization();
}
// Setup objects for string interactions (swing, colour
// reconnection, shoving and rope hadronisation).
if ( !stringInteractionsPtr ) {
if ( flag("Ropewalk:RopeHadronization") )
stringInteractionsPtr = make_shared<Ropewalk>();
else
stringInteractionsPtr = make_shared<StringInteractions>();
registerPhysicsBase(*stringInteractionsPtr);
}
stringInteractionsPtr->init();
// Back to common initialization. Reset error counters.
nErrEvent = 0;
infoPrivate.setTooLowPTmin(false);
infoPrivate.sigmaReset();
// Initialize data members extracted from database.
doPartonLevel = flag("PartonLevel:all");
doHadronLevel = flag("HadronLevel:all");
doLowEnergy = flag("LowEnergyQCD:all")
|| flag("LowEnergyQCD:nonDiffractive")
|| flag("LowEnergyQCD:elastic")
|| flag("LowEnergyQCD:singleDiffractiveXB")
|| flag("LowEnergyQCD:singleDiffractiveAX")
|| flag("LowEnergyQCD:doubleDiffractive")
|| flag("LowEnergyQCD:excitation")
|| flag("LowEnergyQCD:annihilation")
|| flag("LowEnergyQCD:resonant");
doSoftQCDall = flag("SoftQCD:all");
doSoftQCDinel = flag("SoftQCD:inelastic");
doCentralDiff = flag("SoftQCD:centralDiffractive");
doDiffraction = flag("SoftQCD:singleDiffractive")
|| flag("SoftQCD:singleDiffractiveXB")
|| flag("SoftQCD:singleDiffractiveAX")
|| flag("SoftQCD:doubleDiffractive")
|| doSoftQCDall || doSoftQCDinel || doCentralDiff;
doSoftQCD = doDiffraction ||
flag("SoftQCD:nonDiffractive") ||
flag("SoftQCD:elastic");
doHardDiff = flag("Diffraction:doHard");
doResDec = flag("ProcessLevel:resonanceDecays");
doFSRinRes = doPartonLevel && flag("PartonLevel:FSR")
&& flag("PartonLevel:FSRinResonances");
decayRHadrons = flag("RHadrons:allowDecay");
doPartonVertex = flag("PartonVertex:setVertex");
eMinPert = parm("Beams:eMinPert");
eWidthPert = parm("Beams:eWidthPert");
abortIfVeto = flag("Check:abortIfVeto");
checkEvent = flag("Check:event");
checkHistory = flag("Check:history");
nErrList = mode("Check:nErrList");
epTolErr = parm("Check:epTolErr");
epTolWarn = parm("Check:epTolWarn");
mTolErr = parm("Check:mTolErr");
mTolWarn = parm("Check:mTolWarn");
// Warn/abort for unallowed process and beam combinations.
bool doHardProc = settings.hasHardProc() || doLHA;
if (doSoftQCD && doHardProc) {
logger.WARNING_MSG("should not combine softQCD processes with hard ones");
}
if (beamSetup.doVarEcm && doHardProc) {
logger.ABORT_MSG("variable energy only works for softQCD processes");
return false;
}
if (doLowEnergy && doHardProc) {
logger.ABORT_MSG("lowEnergy and hard processes cannot be used together");
return false;
}
// Check that combinations of settings are allowed; change if not.
checkSettings();
// Initialize the SM couplings (needed to initialize resonances).
coupSM.init( settings, &rndm );
// Initialize SLHA interface (including SLHA/BSM couplings).
bool useSLHAcouplings = false;
slhaInterface = SLHAinterface();
slhaInterface.setPtr( &infoPrivate);
slhaInterface.init( useSLHAcouplings, particleDataBuffer );
// Reset couplingsPtr to the correct memory address.
particleData.initPtrs( &infoPrivate);
// Set headers to distinguish the two event listing kinds.
int startColTag = mode("Event:startColTag");
process.init("(hard process)", &particleData, startColTag);
event.init("(complete event)", &particleData, startColTag);
// Final setup stage of particle data, notably resonance widths.
particleData.initWidths( resonancePtrs);
// Read in files with particle widths.
string dataFile = xmlPath + "HadronWidths.dat";
if (!hadronWidths.init(dataFile)) {
logger.ABORT_MSG("hadron widths unavailable");
return false;
}
if (!hadronWidths.check()) {
logger.ABORT_MSG("hadron widths are invalid");
return false;
}
// Set up R-hadrons particle data, where relevant.
rHadrons.init();
// Set up and initialize setting of parton production vertices.
if (doPartonVertex) {
if (!partonVertexPtr) partonVertexPtr = make_shared<PartonVertex>();
registerPhysicsBase(*partonVertexPtr);
partonVertexPtr->init();
}
// Prepare for variable-beam and -energy cross sections.
string dataFileNucl = xmlPath + "NucleonExcitations.dat";
if (!nucleonExcitations.init(dataFileNucl)) {
logger.ABORT_MSG("nucleon excitation data unavailable");
return false;
}
sigmaLowEnergy.init( &nucleonExcitations);
sigmaCmb.init( &sigmaLowEnergy);
// Prepare for low-energy QCD processes.
doNonPert = hadronLevel.initLowEnergyProcesses();
if (doNonPert && !doSoftQCD && !doHardProc) doProcessLevel = false;
// Initialise merging hooks for simple shower model.
if ( doMerging && mergingHooksPtr && showerModel == 1 ) {
mergingHooksPtr->init();
}
// Set up and initialize the ShowerModel (if not provided by user).
if ( !showerModelPtr ) {
if ( showerModel == 2 ) showerModelPtr = make_shared<Vincia>();
else if (showerModel == 3 ) showerModelPtr = make_shared<Dire>();
else showerModelPtr = make_shared<SimpleShowerModel>();
}
// Register shower model as physicsBase object (also sets pointers)
registerPhysicsBase(*showerModelPtr);
// Initialise shower model
if ( !showerModelPtr->init(mergingPtr, mergingHooksPtr,
partonVertexPtr, &weightContainer) ) {
logger.ABORT_MSG("shower model failed to initialise");
return false;
}
// Vincia adds a userhook -> need to push this to all physics objects.
if ( showerModel == 2 ) pushInfo();
// Get relevant pointers from shower models.
if (doMerging && showerModel != 1) {
mergingPtr = showerModelPtr->getMerging();
mergingHooksPtr = showerModelPtr->getMergingHooks();
}
timesPtr = showerModelPtr->getTimeShower();
timesDecPtr = showerModelPtr->getTimeDecShower();
spacePtr = showerModelPtr->getSpaceShower();
// Initialize pointers in showers.
if (showerModel == 1 || showerModel == 3) {
if ( timesPtr )
timesPtr->initPtrs( mergingHooksPtr, partonVertexPtr,
&weightContainer);
if ( timesDecPtr && timesDecPtr != timesPtr )
timesDecPtr->initPtrs( mergingHooksPtr, partonVertexPtr,
&weightContainer);
if ( spacePtr )
spacePtr->initPtrs( mergingHooksPtr, partonVertexPtr,
&weightContainer);
}
// At this point, the mergingPtr should be set. If that is not the
// case, then the initialization should be aborted.
if (doMerging && !mergingPtr) {
logger.ABORT_MSG(
"merging requested, but merging class not correctly created");
return false;
}
// Set up the beams.
StringFlav* flavSelPtr = hadronLevel.getStringFlavPtr();
if (!beamSetup.initBeams(doNonPert, flavSelPtr)) return false;
// Spread information on beam switching from beamSetup.
if ( beamSetup.allowIDAswitch)
partonLevel.initSwitchID( beamSetup.idAList);
// Turn off central diffraction for VMD processes.
if (beamSetup.getVMDsideA() || beamSetup.getVMDsideB()) {
if (doCentralDiff) {
logger.WARNING_MSG(
"central diffractive events not implemented for gamma + p/gamma");
return false;
}
if (doSoftQCDall) {
logger.WARNING_MSG(
"central diffractive events not implemented for gamma + p/gamma");
settings.flag("SoftQCD:all", false);
settings.flag("SoftQCD:elastic", true);
settings.flag("SoftQCD:nonDiffractive", true);
settings.flag("SoftQCD:singleDiffractive", true);
settings.flag("SoftQCD:doubleDiffractive", true);
}
if (doSoftQCDinel) {
logger.WARNING_MSG(
"central diffractive events not implemented for gamma + p/gamma");
settings.flag("SoftQCD:inelastic", false);
settings.flag("SoftQCD:nonDiffractive", true);
settings.flag("SoftQCD:singleDiffractive", true);
settings.flag("SoftQCD:doubleDiffractive", true);
}
}
// Send info/pointers to process level for initialization.
if ( doProcessLevel ) {
sigmaTot.init();
if (!processLevel.init(doLHA, &slhaInterface, sigmaPtrs, phaseSpacePtrs)) {
logger.ABORT_MSG("processLevel initialization failed");
return false;
}
}
// Initialize shower handlers using initialized beams.
if (!showerModelPtr->initAfterBeams()) {
string message = "Fail to initialize ";
if (showerModel==1) message += "default";
else if (showerModel==2) message += "Vincia";
else if (showerModel==3) message += "Dire";
message += " shower.";
logger.ABORT_MSG(message);
return false;
}
// Initialize timelike showers already here, since needed in decays.
// The pointers to the beams are needed by some external plugin showers.
timesDecPtr->init( &beamSetup.beamA, &beamSetup.beamB);
// Alternatively only initialize resonance decays.
if ( !doProcessLevel) processLevel.initDecays(lhaUpPtr);
// Send info/pointers to parton level for initialization.
if ( doPartonLevel && doProcessLevel && !partonLevel.init(timesDecPtr,
timesPtr, spacePtr, &rHadrons, mergingHooksPtr,
partonVertexPtr, stringInteractionsPtr, false) ) {
logger.ABORT_MSG("partonLevel initialization failed");
return false;
}
// Make pointer to shower available for merging machinery.
if ( doMerging && mergingHooksPtr )
mergingHooksPtr->setShowerPointer(&partonLevel);
// Alternatively only initialize final-state showers in resonance decays.
if ( (!doProcessLevel || !doPartonLevel)
&& (!doNonPert || doSoftQCD) ) partonLevel.init(
timesDecPtr, nullptr, nullptr, &rHadrons, nullptr,
partonVertexPtr, stringInteractionsPtr, false);
// Set up shower variation groups if enabled
bool doVariations = flag("UncertaintyBands:doVariations");
if ( doVariations && showerModel==1 ) weightContainer.weightsShowerPtr->
initWeightGroups(true);
// Send info/pointers to parton level for trial shower initialization.
if ( doMerging && !trialPartonLevel.init( timesDecPtr, timesPtr,
spacePtr, &rHadrons, mergingHooksPtr, partonVertexPtr,
stringInteractionsPtr, true) ) {
logger.ABORT_MSG("trialPartonLevel initialization failed");
return false;
}
// Initialise the merging wrapper class.
if (doMerging && mergingPtr && mergingHooksPtr) {
mergingPtr->initPtrs( mergingHooksPtr, &trialPartonLevel);
mergingPtr->init();
}
// Send info/pointers to hadron level for initialization.
// Note: forceHadronLevel() can come, so we must always initialize.
if ( !hadronLevel.init( timesDecPtr, &rHadrons, decayHandlePtr,
handledParticles, stringInteractionsPtr, partonVertexPtr,
sigmaLowEnergy, nucleonExcitations) ) {
logger.ABORT_MSG("hadronLevel initialization failed");
return false;
}
// Optionally check particle data table for inconsistencies.
if ( flag("Check:particleData") )
particleData.checkTable( mode("Check:levelParticleData") );
// Optionally show settings and particle data, changed or all.
bool showCS = flag("Init:showChangedSettings");
bool showAS = flag("Init:showAllSettings");
bool showCPD = flag("Init:showChangedParticleData");
bool showCRD = flag("Init:showChangedResonanceData");
bool showAPD = flag("Init:showAllParticleData");
int show1PD = mode("Init:showOneParticleData");
bool showPro = flag("Init:showProcesses");
if (showCS) settings.listChanged();
if (showAS) settings.listAll();
if (show1PD > 0) particleData.list(show1PD);
if (showCPD) particleData.listChanged(showCRD);
if (showAPD) particleData.listAll();
// Listing options for the next() routine.
nCount = mode("Next:numberCount");
nShowLHA = mode("Next:numberShowLHA");
nShowInfo = mode("Next:numberShowInfo");
nShowProc = mode("Next:numberShowProcess");
nShowEvt = mode("Next:numberShowEvent");
showSaV = flag("Next:showScaleAndVertex");
showMaD = flag("Next:showMothersAndDaughters");
// Init junction splitting.
junctionSplitting.init();
// Flags for colour reconnection.
doReconnect = flag("ColourReconnection:reconnect");
reconnectMode = mode("ColourReconnection:mode");
forceHadronLevelCR = flag("ColourReconnection:forceHadronLevelCR");
if ( doReconnect ) colourReconnectionPtr =
stringInteractionsPtr->getColourReconnections();
// Succeeded.
isInit = true;
infoPrivate.addCounter(2);
if (useNewLHA && showPro) lhaUpPtr->listInit();
return true;
}
//--------------------------------------------------------------------------
// Check that combinations of settings are allowed; change if not.
void Pythia::checkSettings() {
// Double rescattering not allowed if ISR or FSR.
if ((flag("PartonLevel:ISR") || flag("PartonLevel:FSR"))
&& flag("MultipartonInteractions:allowDoubleRescatter")) {
logger.WARNING_MSG(
"double rescattering switched off since showering is on");
settings.flag("MultipartonInteractions:allowDoubleRescatter", false);
}
// Optimize settings for collisions with direct photon(s).
if ( beamSetup.beamA2gamma || beamSetup.beamB2gamma
|| (beamSetup.idA == 22) || (beamSetup.idB == 22) ) {