This repository was archived by the owner on Oct 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain42_new.cc
98 lines (79 loc) · 3.21 KB
/
main42_new.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// main42.cc is a part of the PYTHIA event generator.
// Copyright (C) 2015 Torbjorn Sjostrand.
// PYTHIA is licenced under the GNU GPL version 2, see COPYING for details.
// Please respect the MCnet Guidelines, see GUIDELINES for details.
// Author: Mikhail Kirsanov, [email protected].
// This program illustrates how a file with HepMC events
// can be generated by Pythia8.
// Input and output files are specified on the command line, e.g. like
// ./main42.exe main42.cmnd hepmcout42.dat > out
// The main program contains no analysis; this is intended to happen later.
// It therefore "never" has to be recompiled to handle different tasks.
// WARNING: typically one needs 25 MB/100 events at the LHC.
// Therefore large event samples may be impractical.
#include <iostream>
#include "Pythia8/Pythia.h"
#include "Pythia8/Settings.h"
using namespace Pythia8;
int main(int argc, char* argv[]) {
// Check that correct number of command-line arguments
if (argc != 3) {
cerr << " Unexpected number of command-line arguments. \n You are"
<< " expected to provide one input and one output file name. \n"
<< " Program stopped! " << endl;
return 1;
}
// Check that the provided input name corresponds to an existing file.
ifstream is(argv[1]);
if (!is) {
cerr << " Command-line file " << argv[1] << " was not found. \n"
<< " Program stopped! " << endl;
return 1;
}
// Confirm that external files will be used for input and output.
cout << "\n >>> PYTHIA settings will be read from file " << argv[1]
<< " <<< \n >>> HepMC events will be written to file "
<< argv[2] << " <<< \n" << endl;
// Interface for conversion from Pythia8::Event to HepMC event.
// Specify file where HepMC events will be stored.
std::ofstream ascii_io(argv[2], std::ios::out);
// Generator.
Pythia pythia;
pythia.settings.init("xmldoc/Index.xml");
// Read in commands from external file.
pythia.readFile(argv[1]);
// Extract settings to be used in the main program.
int nEvent = pythia.mode("Main:numberOfEvents");
int nAbort = pythia.mode("Main:timesAllowErrors");
// Initialization.
pythia.init();
// Begin event loop.
int iAbort = 0;
int totEv = 0;
for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
// Generate event.
if (!pythia.next()) {
// If failure because reached end of file then exit event loop.
if (pythia.info.atEndOfFile()) {
cout << " Aborted since reached end of Les Houches Event File\n";
break;
}
// First few failures write off as "acceptable" errors, then quit.
if (++iAbort < nAbort) continue;
cout << " Event generation aborted prematurely, owing to error!\n";
break;
}
++totEv;
for (int i = 0; i < pythia.event.size(); ++i) {
if (pythia.event[i].isFinal() && pythia.event[i].isCharged() &&
abs(pythia.event[i].id()) == 1000010020) {
ascii_io << pythia.event[i].id() << "\t" << pythia.event[i].pT() << "\t";
ascii_io << pythia.event[i].pz() << "\t" << pythia.event[i].eta() << "\t" << pythia.event[i].y() << std::endl;
}
// End of event loop. Statistics.
}
}
ascii_io << "#" << totEv << endl;
// Done.
return 0;
}