]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PYTHIA8/pythia8145/examples/main31.cc
Use Output directive instead of the old OutputFile and OUtputArchive. Save fileinfo...
[u/mrichter/AliRoot.git] / PYTHIA8 / pythia8145 / examples / main31.cc
CommitLineData
9419eeef 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.
5
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.
11
12#include "Pythia.h"
13#include "HepMCInterface.h"
14
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"
22
23using namespace Pythia8;
24
25int main() {
26
27 // Interface for conversion from Pythia8::Event to HepMC one.
28 HepMC::I_Pythia8 ToHepMC;
29 // ToHepMC.set_crash_on_problem();
30
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);
36
37 // Generator. Process selection. LHC initialization. Histogram.
38 Pythia pythia;
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);
43
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();}
48
49 // Find number of all final charged particles and fill histogram.
50 int nCharged = 0;
51 for (int i = 0; i < pythia.event.size(); ++i)
52 if (pythia.event[i].isFinal() && pythia.event[i].isCharged())
53 ++nCharged;
54 mult.fill( nCharged );
55
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);
62
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 );
67
68 // Write the HepMC event to file. Done with it.
69 ascii_io << hepmcevt;
70 delete hepmcevt;
71
72 // End of event loop. Statistics. Histogram.
73 }
74 pythia.statistics();
75 cout << mult;
76
77 // Done.
78 return 0;
79}