]>
Commit | Line | Data |
---|---|---|
9419eeef | 1 | // main04.cc is a part of the PYTHIA event generator. |
2 | // Copyright (C) 2010 Torbjorn Sjostrand. | |
3 | // PYTHIA is licenced under the GNU GPL version 2, see COPYING for details. | |
4 | // Please respect the MCnet Guidelines, see GUIDELINES for details. | |
5 | ||
6 | // This is a simple test program. | |
7 | // It illustrates how different processes can be selected and studied. | |
8 | // All input is specified in the main04.cmnd file. | |
9 | ||
10 | #include "Pythia.h" | |
11 | ||
12 | using namespace Pythia8; | |
13 | ||
14 | int main() { | |
15 | ||
16 | // Generator. Shorthand for the event and the (static) Settings. | |
17 | Pythia pythia; | |
18 | Event& event = pythia.event; | |
19 | Settings& settings = pythia.settings; | |
20 | ||
21 | // Read in commands from external file. | |
22 | pythia.readFile("main04.cmnd"); | |
23 | ||
24 | // Extract settings to be used in the main program. | |
25 | int nEvent = pythia.mode("Main:numberOfEvents"); | |
26 | int nList = pythia.mode("Main:numberToList"); | |
27 | int nShow = pythia.mode("Main:timesToShow"); | |
28 | int nAbort = pythia.mode("Main:timesAllowErrors"); | |
29 | bool showCS = pythia.flag("Main:showChangedSettings"); | |
30 | bool showAS = pythia.flag("Main:showAllSettings"); | |
31 | ||
32 | // Also need the CM energy. | |
33 | double eCM = pythia.parm("Beams:eCM"); | |
34 | ||
35 | // Initialization using beam parameters in the .cmnd file. | |
36 | pythia.init(); | |
37 | ||
38 | // List changed or all data. | |
39 | if (showCS) settings.listChanged(); | |
40 | if (showAS) settings.listAll(); | |
41 | ||
42 | // Histograms. | |
43 | double epTol = 1e-6 * eCM; | |
44 | Hist epCons("deviation from energy-momentum conservation",100,0.,epTol); | |
45 | Hist nFinal("final particle multiplicity",100,-0.5,799.5); | |
46 | Hist dNdEta("dn/deta for particles",100,-10.,10.); | |
47 | ||
48 | // Begin event loop. | |
49 | int nPace = max(1, nEvent / max(1, nShow) ); | |
50 | int iAbort = 0; | |
51 | for (int iEvent = 0; iEvent < nEvent; ++iEvent) { | |
52 | if (nShow > 0 && iEvent%nPace == 0) | |
53 | cout << " Now begin event " << iEvent << endl; | |
54 | ||
55 | // Generate events. Quit if failure. | |
56 | if (!pythia.next()) { | |
57 | if (++iAbort < nAbort) continue; | |
58 | cout << " Event generation aborted prematurely, owing to error!\n"; | |
59 | break; | |
60 | } | |
61 | ||
62 | // List first few events, both hard process and complete events. | |
63 | if (iEvent < nList) { | |
64 | pythia.info.list(); | |
65 | pythia.process.list(); | |
66 | event.list(); | |
67 | } | |
68 | ||
69 | // Loop over final particles in the event. | |
70 | int nFin = 0; | |
71 | Vec4 pSum; | |
72 | for (int i = 0; i < event.size(); ++i) if (event[i].isFinal()) { | |
73 | nFin++; | |
74 | pSum += event[i].p(); | |
75 | dNdEta.fill(event[i].eta()); | |
76 | } | |
77 | ||
78 | // Check and print event with too big energy-momentum deviation. | |
79 | nFinal.fill(nFin); | |
80 | double epDev = abs(pSum.e() - eCM) + abs(pSum.px()) + abs(pSum.py()) | |
81 | + abs(pSum.pz()); | |
82 | epCons.fill(epDev); | |
83 | if (epDev > epTol) { | |
84 | cout << " Warning! Event with epDev = " << scientific | |
85 | << setprecision(4) << epDev << " now listed:"; | |
86 | event.list(); | |
87 | } | |
88 | ||
89 | // End of event loop. | |
90 | } | |
91 | ||
92 | // Final statistics and histogram output. | |
93 | pythia.statistics(); | |
94 | dNdEta *= 5./nEvent; | |
95 | cout << epCons << nFinal << dNdEta; | |
96 | ||
97 | return 0; | |
98 | } |