StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
main41.cc
1 // main41.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 // Author: Mikhail Kirsanov, Mikhail.Kirsanov@cern.ch, based on main01.cc.
7 // This program illustrates how HepMC can be interfaced to Pythia8.
8 // It studies the charged multiplicity distribution at the LHC.
9 // HepMC events are output to the hepmcout41.dat file.
10 
11 // WARNING: typically one needs 25 MB/100 events at the LHC.
12 // Therefore large event samples may be impractical.
13 
14 #include "Pythia8/Pythia.h"
15 #include "Pythia8/Pythia8ToHepMC.h"
16 #include "HepMC/GenEvent.h"
17 #include "HepMC/IO_GenEvent.h"
18 
19 using namespace Pythia8;
20 
21 int main() {
22 
23  // Interface for conversion from Pythia8::Event to HepMC event.
24  HepMC::Pythia8ToHepMC ToHepMC;
25 
26  // Specify file where HepMC events will be stored.
27  HepMC::IO_GenEvent ascii_io("hepmcout41.dat", std::ios::out);
28 
29  // Generator. Process selection. LHC initialization. Histogram.
30  Pythia pythia;
31  pythia.readString("Beams:eCM = 8000.");
32  pythia.readString("HardQCD:all = on");
33  pythia.readString("PhaseSpace:pTHatMin = 20.");
34  pythia.init();
35  Hist mult("charged multiplicity", 100, -0.5, 799.5);
36 
37  // Begin event loop. Generate event. Skip if error.
38  for (int iEvent = 0; iEvent < 100; ++iEvent) {
39  if (!pythia.next()) continue;
40 
41  // Find number of all final charged particles and fill histogram.
42  int nCharged = 0;
43  for (int i = 0; i < pythia.event.size(); ++i)
44  if (pythia.event[i].isFinal() && pythia.event[i].isCharged())
45  ++nCharged;
46  mult.fill( nCharged );
47 
48  // Construct new empty HepMC event and fill it.
49  // Units will be as chosen for HepMC build; but can be changed
50  // by arguments, e.g. GenEvt( HepMC::Units::GEV, HepMC::Units::MM)
51  HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
52  ToHepMC.fill_next_event( pythia, hepmcevt );
53 
54  // Write the HepMC event to file. Done with it.
55  ascii_io << hepmcevt;
56  delete hepmcevt;
57 
58  // End of event loop. Statistics. Histogram.
59  }
60  pythia.stat();
61  cout << mult;
62 
63  // Done.
64  return 0;
65 }
The GenEvent class is the core of HepMC.
Definition: GenEvent.h:155
IO_GenEvent also deals with HeavyIon and PdfInfo.
Definition: IO_GenEvent.h:63