StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
main12.cc
1 // main12.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2012 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 Les Houches Event File input can be used in PYTHIA.
8 // It uses two LHE files, ttbar.lhe and ttbar2.lhe, which are combined
9 // using Beams:newLHEFsameInit = on to skip new initialization second time.
10 // Then the second file is viewed as a simple continuation of the first,
11 // just split for practical reasons, rather than as a separate new run
12 // with a new set of processes.
13 // In the first file top decays have been performed, in the second not,
14 // and are instead handled by the internal PYTHIA resonance-decay machinery.
15 // Furthermore the internal top production processes are switched on and
16 // mixed in, giving an unrealistic "double up" total top cross section.
17 // Much of this of course is not intended to be realistic,
18 // but rather illustrates several tricks that can be useful.
19 
20 #include "Pythia.h"
21 using namespace Pythia8;
22 int main() {
23 
24  // Number of listed events. Allow for possibility of a few faulty events.
25  int nPrintLHA = 1;
26  int nPrintRest = 0;
27  int nAbort = 10;
28 
29  // Generator
30  Pythia pythia;
31 
32  // Switch on internal ttbar production.
33  pythia.readString("Top:gg2ttbar = on");
34  pythia.readString("Top:qqbar2ttbar = on");
35 
36  // Use same top mass as in Pythia 6.4 to simplify comparison.
37  pythia.readString("6:m0 = 175.");
38 
39  // No automatic event listings - do it manually below.
40  pythia.readString("Next:numberShowLHA = 0");
41  pythia.readString("Next:numberShowInfo = 0");
42  pythia.readString("Next:numberShowProcess = 0");
43  pythia.readString("Next:numberShowEvent = 0");
44 
45  // Initialize Les Houches Event File run.
46  pythia.readString("Beams:frameType = 4");
47  pythia.readString("Beams:LHEF = ttbar.lhe");
48  pythia.init();
49 
50  // Book histogram.
51  Hist nCharged("charged particle multiplicity",100,-0.5,399.5);
52 
53  // Set counters.
54  int iPrintLHA = 0;
55  int iPrintRest = 0;
56  int iAbort = 0;
57  int iFile = 1;
58 
59  // Begin event loop
60  for (int iEvent = 0; ; ++iEvent) {
61 
62  // Generate until none left in input file.
63  if (!pythia.next()) {
64  if (pythia.info.atEndOfFile()) {
65 
66  // First time open next file, second time stop event loop.
67  if (iFile == 1) {
68  pythia.readString("Beams:newLHEFsameInit = on");
69  pythia.readString("Beams:LHEF = ttbar2.lhe");
70  pythia.init();
71  ++iFile;
72  continue;
73  } else break;
74  }
75 
76  // First few failures write off as "acceptable" errors, then quit.
77  if (++iAbort < nAbort) continue;
78  break;
79  }
80 
81  // List first few Les Houches and other events.
82  if (pythia.info.isLHA() && iPrintLHA < nPrintLHA) {
83  pythia.LHAeventList();
84  pythia.info.list();
85  pythia.process.list();
86  pythia.event.list();
87  ++iPrintLHA;
88  } else if (!pythia.info.isLHA() && iPrintRest < nPrintRest) {
89  pythia.info.list();
90  pythia.process.list();
91  pythia.event.list();
92  ++iPrintRest;
93  }
94 
95  // Sum up final charged multiplicity and fill in histogram.
96  int nChg = 0;
97  for (int i = 0; i < pythia.event.size(); ++i)
98  if (pythia.event[i].isFinal() && pythia.event[i].isCharged())
99  ++nChg;
100  nCharged.fill(nChg);
101 
102  // End of event loop.
103  }
104 
105  // Give statistics. Print histogram.
106  pythia.stat();
107  cout << nCharged;
108 
109  // Done.
110  return 0;
111 }