1 // main19.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.
6 // This program runs four instances of Pythia simultaneously,
7 // one for signal events, one for pileup background ones, and two
8 // For beam-gas background ones. Note that Pythia does not do nuclear
9 // effects, so beam-gas is represented by "fixed-target" pp collisions.
10 // The = and += overloaded operators are used to join several
11 // event records into one, but should be used with caution.
13 // Note that each instance of Pythia is independent of any other,
14 // but with two important points to remember.
15 // 1) By default all generate the same random number sequence,
16 // which has to be corrected if they are to generate the same
17 // physics, like the two beam-gas ones below.
18 // 2) Interfaces to external Fortran programs are "by definition" static.
19 // Thus it is not a good idea to use LHAPDF to set different PDF's
20 // in different instances.
23 using namespace Pythia8;
25 //==========================================================================
27 // Method to pick a number according to a Poissonian distribution.
29 int poisson(double nAvg, Rndm& rndm) {
31 // Set maximum to avoid overflow.
35 double rPoisson = rndm.flat() * exp(nAvg);
41 // Add to sum and check whether done.
42 for (int i = 0; i < NMAX; ) {
44 if (rSum > rPoisson) return i;
46 // Evaluate next term.
55 //==========================================================================
59 // Number of signal events to generate.
65 // Average number of pileup events per signal event.
66 double nPileupAvg = 2.5;
68 // Average number of beam-gas events per signal ones, on two sides.
69 double nBeamAGasAvg = 0.5;
70 double nBeamBGasAvg = 0.5;
72 // Four generator instances.
75 Pythia pythiaBeamAGas;
76 Pythia pythiaBeamBGas;
78 // One object where all individual events are to be collected.
81 // Initialize generator for signal processes.
82 pythiaSignal.readString("HardQCD:all = on");
83 pythiaSignal.readString("PhaseSpace:pTHatMin = 50.");
84 pythiaSignal.init( 2212, 2212, 2. * eBeam);
86 // Initialize generator for pileup (background) processes.
87 pythiaPileup.readString("Random:setSeed = on");
88 pythiaPileup.readString("Random:seed = 10000002");
89 pythiaPileup.readString("SoftQCD:all = on");
90 pythiaPileup.init( 2212, 2212, 2. * eBeam);
92 // Initialize generators for beam A - gas (background) processes.
93 pythiaBeamAGas.readString("Random:setSeed = on");
94 pythiaBeamAGas.readString("Random:seed = 10000003");
95 pythiaBeamAGas.readString("SoftQCD:all = on");
96 pythiaBeamAGas.init( 2212, 2212, eBeam, 0.);
98 // Initialize generators for beam B - gas (background) processes.
99 pythiaBeamBGas.readString("Random:setSeed = on");
100 pythiaBeamBGas.readString("Random:seed = 10000004");
101 pythiaBeamBGas.readString("SoftQCD:all = on");
102 pythiaBeamBGas.init( 2212, 2212, 0., eBeam);
104 // Histograms: number of pileups, total charged multiplicity.
105 Hist nPileH("number of pileup events per signal event", 100, -0.5, 99.5);
106 Hist nAGH("number of beam A + gas events per signal event", 100, -0.5, 99.5);
107 Hist nBGH("number of beam B + gas events per signal event", 100, -0.5, 99.5);
108 Hist nChgH("number of charged multiplicity",100, -0.5, 1999.5);
109 Hist sumPZH("total pZ of system",100, -100000., 100000.);
112 for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
114 // Generate a signal event. Copy this event into sumEvent.
115 if (!pythiaSignal.next()) continue;
116 sumEvent = pythiaSignal.event;
118 // Select the number of pileup events to generate.
119 int nPileup = poisson(nPileupAvg, pythiaPileup.rndm);
120 nPileH.fill( nPileup );
122 // Generate a number of pileup events. Add them to sumEvent.
123 for (int iPileup = 0; iPileup < nPileup; ++iPileup) {
125 sumEvent += pythiaPileup.event;
128 // Select the number of beam A + gas events to generate.
129 int nBeamAGas = poisson(nBeamAGasAvg, pythiaBeamAGas.rndm);
130 nAGH.fill( nBeamAGas );
132 // Generate a number of beam A + gas events. Add them to sumEvent.
133 for (int iAG = 0; iAG < nBeamAGas; ++iAG) {
134 pythiaBeamAGas.next();
135 sumEvent += pythiaBeamAGas.event;
138 // Select the number of beam B + gas events to generate.
139 int nBeamBGas = poisson(nBeamBGasAvg, pythiaBeamBGas.rndm);
140 nBGH.fill( nBeamBGas );
142 // Generate a number of beam B + gas events. Add them to sumEvent.
143 for (int iBG = 0; iBG < nBeamBGas; ++iBG) {
144 pythiaBeamBGas.next();
145 sumEvent += pythiaBeamBGas.event;
148 // List first few events.
150 pythiaSignal.info.list();
151 pythiaSignal.process.list();
155 // Find charged multiplicity.
157 for (int i = 0; i < sumEvent.size(); ++i)
158 if (sumEvent[i].isFinal() && sumEvent[i].isCharged()) ++nChg;
161 // Fill net pZ - nonvanishing owing to beam + gas.
162 sumPZH.fill( sumEvent[0].pz() );
167 // Statistics. Histograms.
168 pythiaSignal.statistics();
169 pythiaPileup.statistics();
170 pythiaBeamAGas.statistics();
171 pythiaBeamBGas.statistics();
172 cout << nPileH << nAGH << nBGH << nChgH << sumPZH;