source: HiSusy/trunk/Pythia8/pythia8170/examples/main41.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.3 KB
Line 
1// main41.cc is a part of the PYTHIA event generator.
2// Copyright (C) 2012 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 hepmcout41.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("hepmcout41.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("Beams:eCM = 8000.");   
48  pythia.readString("HardQCD:all = on");   
49  pythia.readString("PhaseSpace:pTHatMin = 20.");   
50  pythia.init();
51  Hist mult("charged multiplicity", 100, -0.5, 799.5);
52
53  // Begin event loop. Generate event. Skip if error. List first one.
54  for (int iEvent = 0; iEvent < 100; ++iEvent) {
55    if (!pythia.next()) continue;
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    // To retain units in GeV uncomment line below.
74    //ToHepMC.set_convert_to_mev( false);
75    HepMC::GenEvent* hepmcevt = new HepMC::GenEvent();
76#endif
77
78    // Fill HepMC event, including PDF info.
79    ToHepMC.fill_next_event( pythia, hepmcevt );
80    // This alternative older method fills event, without PDF info.
81    // ToHepMC.fill_next_event( pythia.event, hepmcevt );
82
83    // Write the HepMC event to file. Done with it.
84    ascii_io << hepmcevt;
85    delete hepmcevt;
86
87  // End of event loop. Statistics. Histogram.
88  }
89  pythia.stat();
90  cout << mult; 
91
92  // Done.
93  return 0;
94}
Note: See TracBrowser for help on using the repository browser.