File indexing completed on 2025-08-05 08:21:08
0001 #include <iostream>
0002 #include <sstream>
0003 #include <string>
0004
0005
0006 #include <getopt.h>
0007
0008
0009 #include <TFile.h>
0010 #include <TObjString.h>
0011 #include <TTree.h>
0012
0013 #include "factory.h"
0014 #include "pythia_commons.h"
0015 #include "pythia_erhic.h"
0016
0017
0018 std::string initialise(int argc, char* argv[]);
0019 void write_run_data(TFile&);
0020
0021
0022
0023
0024
0025 int main(int argc, char* argv[]) {
0026 std::string filename = initialise(argc, argv);
0027
0028
0029
0030 TFile file(filename.c_str(), "recreate");
0031 TTree tree("EICTree", "Output direct from pythia!");
0032 Factory factory;
0033 factory.Branch(tree, "event");
0034
0035 std::stringstream stream;
0036
0037
0038
0039 while(__pythia6_MOD_generate() == 0) {
0040 erhic::EventPythia* event = factory.Create();
0041 event->SetN(tree.GetEntries() + 1);
0042 tree.Fill();
0043
0044 std::cout << std::endl;
0045 }
0046 file.Write();
0047 write_run_data(file);
0048 __pythia6_MOD_finish();
0049 return 0;
0050 }
0051
0052
0053
0054
0055
0056 std::string initialise(int argc, char* argv[]) {
0057 std::string filename("pythia.root");
0058
0059 __pythia6_MOD_printascii = 1;
0060 static struct option long_options[] = {
0061
0062 {"ascii", no_argument, &__pythia6_MOD_printascii, 1},
0063 {"noascii", no_argument, &__pythia6_MOD_printascii, 0},
0064
0065
0066 {"out", required_argument, NULL, 'o'},
0067 {NULL, 0, NULL, 0}
0068 };
0069
0070 int option_index = 0;
0071 int code(0);
0072 while((code = getopt_long(argc, argv, "o:r:",
0073 long_options, &option_index)) not_eq -1) {
0074 switch(code) {
0075 case 0:
0076 if(long_options[option_index].flag not_eq 0) {
0077 break;
0078 }
0079 printf("option %s", long_options[option_index].name);
0080 if(optarg) {
0081 printf (" with arg %s", optarg);
0082 }
0083 printf("\n");
0084 break;
0085 case 'o':
0086 filename = optarg;
0087 break;
0088 default:
0089 abort();
0090 }
0091 }
0092
0093
0094
0095
0096 int result = __pythia6_MOD_initialise();
0097 if(0 not_eq result) {
0098 exit(result);
0099 }
0100 return filename;
0101 }
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112 void write_run_data(TFile& file) {
0113 TObjString text;
0114 std::stringstream stream;
0115
0116
0117 stream << pari(1) * 1000.;
0118 text.SetString(stream.str().c_str());
0119 file.WriteObject(&text, "crossSection");
0120
0121 stream.str("");
0122 stream.clear();
0123 stream << msti(5);
0124 text.SetString(stream.str().c_str());
0125 file.WriteObject(&text, "nEvents");
0126
0127 stream.str("");
0128 stream.clear();
0129 stream << ngen(0, 3);
0130 text.SetString(stream.str().c_str());
0131 file.WriteObject(&text, "nTrials");
0132 }