@@ -18,7 +18,7 @@ int main(int argc, char **argv)
1818 int npart;
1919 double xProd, yProd, zProd;
2020 bool verbose, decay;
21-
21+
2222 /* * process arguments **/
2323 namespace po = boost::program_options;
2424 po::options_description desc (" Options" );
@@ -44,29 +44,40 @@ int main(int argc, char **argv)
4444 (" verbose,V" , po::bool_switch (&verbose)->default_value (false ), " Verbose event listing" )
4545 (" seed" , po::value<int >(&seed)->default_value (1 ), " initial seed" )
4646 ;
47-
47+
4848 po::variables_map vm;
4949 po::store (po::parse_command_line (argc, argv, desc), vm);
5050 po::notify (vm);
51-
51+
5252 if (vm.count (" help" )) {
5353 std::cout << desc << std::endl;
5454 return 1 ;
5555 }
56- }
57- catch (std::exception& e) {
56+ } catch (std::exception& e) {
5857 std::cerr << " Error: " << e.what () << std::endl;
5958 std::cout << desc << std::endl;
6059 return 1 ;
6160 }
62-
61+
6362 HepMC::Pythia8ToHepMC ToHepMC;
6463 HepMC::IO_GenEvent ascii_io (output, std::ios::out);
65-
64+
6665 // pythia
6766 Pythia pythia;
6867
68+ // configure pythia
69+ pythia.readString (" ProcessLevel:all = off" );
70+ // pythia.readString("SoftQCD:elastic on");
71+ if (!config.empty () && !pythia.readFile (config)) {
72+ std::cout << " Error: could not read config file \" " << config << " \" " << std::endl;
73+ return 1 ;
74+ }
75+
6976 // check valid pdg code
77+ if (!pythia.particleData .isParticle (pdg)) {
78+ std::cout << " Error: invalid PDG code \" " << pdg << " \" is not in the particle list" << std::endl;
79+ return 1 ;
80+ }
7081 if (!pythia.particleData .isLepton (pdg) &&
7182 !pythia.particleData .isHadron (pdg) &&
7283 !pythia.particleData .isResonance (pdg)) {
@@ -78,15 +89,7 @@ int main(int argc, char **argv)
7889 }
7990 }
8091
81- // config
82- pythia.readString (" ProcessLevel:all = off" );
83- // pythia.readString("SoftQCD:elastic on");
84- if (!config.empty () && !pythia.readFile (config)) {
85- std::cout << " Error: could not read config file \" " << config << " \" " << std::endl;
86- return 1 ;
87- }
88-
89- std::cout<<" Random:seed =" + std::to_string (seed)<<std::endl;
92+ std::cout << " Random:seed =" + std::to_string (seed) << std::endl;
9093 pythia.readString (" Random:setSeed = on" );
9194 pythia.readString (" Random:seed =" + std::to_string (seed));
9295 // init
@@ -103,7 +106,7 @@ int main(int argc, char **argv)
103106 particle.zProd (zProd);
104107
105108 // background interface
106- Pythia8::Pythia * pythia_bkg = nullptr ;
109+ Pythia8::Pythia* pythia_bkg = nullptr ;
107110 if (!background_config.empty ()) {
108111 std::cout << " Background: configure from " << background_config << std::endl;
109112 pythia_bkg = new Pythia8::Pythia;
@@ -113,17 +116,15 @@ int main(int argc, char **argv)
113116 }
114117 pythia_bkg->init ();
115118 }
116-
117119
118-
119120 // event loop
120121 double eta, phi, p, pt, pl, e;
121- srand (time (NULL ));
122+ srand (time (NULL ));
122123 for (int iev = 0 ; iev < nevents; ++iev) {
123124
124125 // reset, add particle and decay
125126 pythia.event .reset ();
126- for (int ipart = 0 ; ipart < npart; ipart++){
127+ for (int ipart = 0 ; ipart < npart; ipart++) {
127128 eta = eta_min + static_cast <float >(rand ()) / (static_cast <float >(RAND_MAX / (eta_max - eta_min)));
128129 phi = phi_min + static_cast <float >(rand ()) / (static_cast <float >(RAND_MAX / (phi_max - phi_min)));
129130 p = p_min + static_cast <float >(rand ()) / (static_cast <float >(RAND_MAX / (p_max - p_min)));
@@ -135,21 +136,23 @@ int main(int argc, char **argv)
135136 particle.py (pt * sin (phi));
136137 particle.pz (pl);
137138 pythia.event .append (particle);
138- if (decay) pythia.moreDecays ();
139+ if (decay)
140+ pythia.moreDecays ();
139141 pythia.next ();
140142 }
141-
143+
142144 // print verbose
143- if (verbose) pythia.event .list (1 );
145+ if (verbose)
146+ pythia.event .list (1 );
144147
145148 // background
146149 if (pythia_bkg) {
147150 pythia_bkg->next ();
148151 pythia.event += pythia_bkg->event ;
149- }
150-
152+ }
153+
151154 // write HepMC
152- HepMC::GenEvent * hepmcevt = new HepMC::GenEvent ();
155+ HepMC::GenEvent* hepmcevt = new HepMC::GenEvent ();
153156 ToHepMC.fill_next_event (pythia, hepmcevt);
154157 ascii_io << hepmcevt;
155158 delete hepmcevt;
@@ -161,7 +164,6 @@ int main(int argc, char **argv)
161164 pythia_bkg->stat ();
162165 delete pythia_bkg;
163166 }
164-
167+
165168 return 0 ;
166-
167169}
0 commit comments