StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
main11.cc
1 // main11.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2014 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 Pythia8.
8 // It uses the ttsample.lhe input file, the latter only with 100 events.
9 
10 #include "Pythia8/Pythia.h"
11 using namespace Pythia8;
12 int main() {
13 
14  // Generator. We here stick with default values, but changes
15  // could be inserted with readString or readFile.
16  Pythia pythia;
17 
18  // Initialize Les Houches Event File run. List initialization information.
19  pythia.readString("Beams:frameType = 4");
20  pythia.readString("Beams:LHEF = ttbar.lhe");
21  pythia.init();
22 
23  // Book histogram.
24  Hist nCharged("charged particle multiplicity",100,-0.5,399.5);
25 
26  // Allow for possibility of a few faulty events.
27  int nAbort = 10;
28  int iAbort = 0;
29 
30  // Begin event loop; generate until none left in input file.
31  for (int iEvent = 0; ; ++iEvent) {
32 
33  // Generate events, and check whether generation failed.
34  if (!pythia.next()) {
35 
36  // If failure because reached end of file then exit event loop.
37  if (pythia.info.atEndOfFile()) break;
38 
39  // First few failures write off as "acceptable" errors, then quit.
40  if (++iAbort < nAbort) continue;
41  break;
42  }
43 
44  // Sum up final charged multiplicity and fill in histogram.
45  int nChg = 0;
46  for (int i = 0; i < pythia.event.size(); ++i)
47  if (pythia.event[i].isFinal() && pythia.event[i].isCharged())
48  ++nChg;
49  nCharged.fill(nChg);
50 
51  // End of event loop.
52  }
53 
54  // Give statistics. Print histogram.
55  pythia.stat();
56  cout << nCharged;
57 
58  // Done.
59  return 0;
60 }