StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
main13.cc
1 // main13.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 two Les Houches Event Files can be combined in PYTHIA,
8 // just like in main12.cc, but here with the difference that information is
9 // stored in main13.cmnd and read out using the subruns possibility.
10 
11 #include "Pythia.h"
12 using namespace Pythia8;
13 int main() {
14 
15  // Book histogram.
16  Hist nCharged("charged particle multiplicity",100,-0.5,399.5);
17 
18  // Generator.
19  Pythia pythia;
20 
21  // Read in subrun-independent data from main13.cmnd.
22  pythia.readFile( "main13.cmnd", 0);
23 
24  // Extract data to be used in main program. Set counters.
25  int nSubrun = pythia.mode("Main:numberOfSubruns");
26  int nAbort = pythia.mode("Main:timesAllowErrors");
27  int iAbort = 0;
28 
29  // Begin loop over subruns.
30  for (int iSubrun = 1; iSubrun <= nSubrun; ++iSubrun) {
31 
32  // Read in subrun-specific data from main13.cmnd.
33  pythia.readFile( "main13.cmnd", iSubrun);
34 
35  // Initialize generator.
36  pythia.init();
37 
38  // Begin infinite event loop - to be exited at end of file.
39  for (int iEvent = 0; ; ++iEvent) {
40 
41  // Generate next event.
42  if (!pythia.next()) {
43 
44  // Leave event loop if at end of file.
45  if (pythia.info.atEndOfFile()) break;
46 
47  // First few failures write off as "acceptable" errors, then quit.
48  if (++iAbort < nAbort) continue;
49  break;
50  }
51 
52  // Sum up final charged multiplicity and fill in histogram.
53  int nChg = 0;
54  for (int i = 0; i < pythia.event.size(); ++i)
55  if (pythia.event[i].isFinal() && pythia.event[i].isCharged()) ++nChg;
56  nCharged.fill(nChg);
57 
58  // End of event loop.
59  }
60 
61  // End of subrun loop.
62  }
63 
64  // Give statistics. Print histogram.
65  pythia.stat();
66  cout << nCharged;
67 
68  // Done.
69  return 0;
70 }