source: HiSusy/trunk/hepmc/x86_64-slc5-gcc41-opt/share/HepMC/examples/pythia8/main31.cc @ 1

Last change on this file since 1 was 1, checked in by zerwas, 11 years ago

first import of structure, PYTHIA8 and DELPHES

File size: 3.2 KB
Line 
1// main31.cc is a part of the PYTHIA event generator.
2// Copyright (C) 2011 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// WARNING: typically one needs 25 MB/100 events at the LHC.
13// Therefore large event samples may be impractical.
14
15#include "Pythia.h"
16#include "HepMCInterface.h"
17
18#include "HepMC/GenEvent.h"
19#include "HepMC/IO_GenEvent.h"
20
21// Following line is a deprecated alternative, removed in recent versions
22//#include "HepMC/IO_Ascii.h"
23//#include "HepMC/IO_AsciiParticles.h"
24
25// Following line to be used with HepMC 2.04 onwards.
26#ifdef HEPMC_HAS_UNITS
27#include "HepMC/Units.h"
28#endif
29
30using namespace Pythia8; 
31
32int main() {
33
34  // Interface for conversion from Pythia8::Event to HepMC one.
35  HepMC::I_Pythia8 ToHepMC;
36  //  ToHepMC.set_crash_on_problem();
37
38  // Specify file where HepMC events will be stored.
39  HepMC::IO_GenEvent ascii_io("hepmcout31.dat", std::ios::out);
40  // Following line is a deprecated alternative, removed in recent versions
41  // HepMC::IO_Ascii ascii_io("hepmcout31.dat", std::ios::out);
42  // Line below is an eye-readable one-way output, uncomment the include above
43  // HepMC::IO_AsciiParticles ascii_io("hepmcout31.dat", std::ios::out);
44
45  // Generator. Process selection. LHC initialization. Histogram.
46  Pythia pythia;
47  pythia.readString("HardQCD:all = on");   
48  pythia.readString("PhaseSpace:pTHatMin = 20.");   
49  pythia.init( 2212, 2212, 14000.);
50  Hist mult("charged multiplicity", 100, -0.5, 799.5);
51
52  // Begin event loop. Generate event. Skip if error. List first one.
53  for (int iEvent = 0; iEvent < 100; ++iEvent) {
54    if (!pythia.next()) continue;
55    if (iEvent < 1) {pythia.info.list(); pythia.event.list();} 
56
57    // Find number of all final charged particles and fill histogram.
58    int nCharged = 0;
59    for (int i = 0; i < pythia.event.size(); ++i) 
60      if (pythia.event[i].isFinal() && pythia.event[i].isCharged()) 
61        ++nCharged; 
62    mult.fill( nCharged );
63
64    // Construct new empty HepMC event.
65#ifdef HEPMC_HAS_UNITS
66    // This form with arguments is only meaningful for HepMC 2.04 onwards,
67    // and even then unnecessary if HepMC was built with GeV and mm as units..
68    HepMC::GenEvent* hepmcevt = new HepMC::GenEvent( 
69      HepMC::Units::GEV, HepMC::Units::MM);
70#else
71    // This form is needed for backwards compatibility.
72    // In HepMCInterface.cc a conversion from GeV to MeV will be done.
73    HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
74#endif
75
76    // Fill HepMC event, including PDF info.
77    ToHepMC.fill_next_event( pythia, hepmcevt );
78    // This alternative older method fills event, without PDF info.
79    // ToHepMC.fill_next_event( pythia.event, hepmcevt );
80
81    // Write the HepMC event to file. Done with it.
82    ascii_io << hepmcevt;
83    delete hepmcevt;
84
85  // End of event loop. Statistics. Histogram.
86  }
87  pythia.statistics();
88  cout << mult; 
89
90  // Done.
91  return 0;
92}
Note: See TracBrowser for help on using the repository browser.