1 // main03.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2013 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.
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 main03.cmnd file.
12 using namespace Pythia8;
19 // Shorthand for the event record in pythia.
20 Event& event = pythia.event;
22 // Read in commands from external file.
23 pythia.readFile("main03.cmnd");
25 // Extract settings to be used in the main program.
26 int nEvent = pythia.mode("Main:numberOfEvents");
27 int nAbort = pythia.mode("Main:timesAllowErrors");
33 Hist pThard("process pT scale", 100, 0., 500.);
34 Hist nFinal("final particle multiplicity", 100, -0.5, 1599.5);
35 Hist nCharged("charged particle multiplicity", 100, -0.5, 799.5);
36 Hist dndy("dn/dy for charged particles", 100, -10., 10.);
37 Hist dndeta("dn/d(eta) for charged particles", 100, -10., 10.);
38 Hist dndpT("dn/dpT for charged particles", 100, 0., 10.);
39 Hist epCons("deviation from energy-momentum conservation", 100, 0., 1e-6);
43 for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
45 // Generate events. Quit if many failures.
47 if (++iAbort < nAbort) continue;
48 cout << " Event generation aborted prematurely, owing to error!\n";
52 // Fill hard scale of event.
53 pThard.fill( pythia.info.pTHat() );
55 // Loop over final particles in the event.
59 for (int i = 0; i < event.size(); ++i) if (event[i].isFinal()) {
61 // Analyze all particles.
65 // Analyze charged particles and fill histograms.
66 if (event[i].isCharged()) {
68 dndy.fill( event[i].y() );
69 dndeta.fill( event[i].eta() );
70 dndpT.fill( event[i].pT() );
73 // End of particle loop. Fill global properties.
76 nCharged.fill( nChg );
78 double epDev = abs(pSum.e() - 1.) + abs(pSum.px()) + abs(pSum.py())
85 // Final statistics. Normalize and output histograms.
88 dndeta *= 5. / nEvent;
89 dndpT *= 10. / nEvent;
90 cout << pThard << nFinal << nCharged << dndy << dndeta << dndpT << epCons;