1 // main31.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2010 Mikhail Kirsanov, 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 is a simple test program.
7 // It 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 hepmcout31.dat file.
10 // Written by Mikhail Kirsanov based on main01.cc.
13 #include "HepMCInterface.h"
15 #include "HepMC/GenEvent.h"
16 #include "HepMC/IO_GenEvent.h"
17 // Following line to be used with HepMC 2.04 onwards.
18 //#include "HepMC/Units.h"
19 // Following two lines are deprecated alternative.
20 //#include "HepMC/IO_Ascii.h"
21 //#include "HepMC/IO_AsciiParticles.h"
23 using namespace Pythia8;
27 // Interface for conversion from Pythia8::Event to HepMC one.
28 HepMC::I_Pythia8 ToHepMC;
29 // ToHepMC.set_crash_on_problem();
31 // Specify file where HepMC events will be stored.
32 HepMC::IO_GenEvent ascii_io("hepmcout31.dat", std::ios::out);
33 // Following two lines are deprecated alternative.
34 // HepMC::IO_Ascii ascii_io("hepmcout31.dat", std::ios::out);
35 // HepMC::IO_AsciiParticles ascii_io("hepmcout31.dat", std::ios::out);
37 // Generator. Process selection. LHC initialization. Histogram.
39 pythia.readString("HardQCD:all = on");
40 pythia.readString("PhaseSpace:pTHatMin = 20.");
41 pythia.init( 2212, 2212, 14000.);
42 Hist mult("charged multiplicity", 100, -0.5, 799.5);
44 // Begin event loop. Generate event. Skip if error. List first one.
45 for (int iEvent = 0; iEvent < 100; ++iEvent) {
46 if (!pythia.next()) continue;
47 if (iEvent < 1) {pythia.info.list(); pythia.event.list();}
49 // Find number of all final charged particles and fill histogram.
51 for (int i = 0; i < pythia.event.size(); ++i)
52 if (pythia.event[i].isFinal() && pythia.event[i].isCharged())
54 mult.fill( nCharged );
56 // Construct new empty HepMC event. Form with arguments is only
57 // meaningful for HepMC 2.04 onwards, and even then unnecessary
58 // if HepMC was built with GeV and mm as units from the onset.
59 HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
60 //HepMC::GenEvent* hepmcevt = new HepMC::GenEvent(
61 // HepMC::Units::GEV, HepMC::Units::MM);
63 // Fill HepMC event, including PDF info.
64 ToHepMC.fill_next_event( pythia, hepmcevt );
65 // This alternative older method fills event, without PDF info.
66 // ToHepMC.fill_next_event( pythia.event, hepmcevt );
68 // Write the HepMC event to file. Done with it.
72 // End of event loop. Statistics. Histogram.