7 #include <gsl/gsl_rng.h>
8 #include <gsl/gsl_randist.h>
18 int main(
int argc,
char** argv)
20 double poisson_mu = -1;
21 double poisson_mu_correction = 0;
22 int output_n = 2500000;
23 int output_filename_digits = 1;
28 while ((c = getopt(argc, argv,
"hn:m:t:s:")) != -1)
32 printf(
"-h: print this help\n");
33 printf(
"-m: mean number of events in an event\n");
34 printf(
"-t: corretion parameter for mu\n");
35 printf(
"-n: output events per output file\n");
36 printf(
"-s: RNG seed\n");
40 poisson_mu = atof(optarg);
43 poisson_mu_correction = atof(optarg);
46 output_n = atoi(optarg);
52 printf(
"Invalid option or missing option argument; -h to list options\n");
58 printf(
"Mean events per output event %f, output events per output file %d\n", poisson_mu, output_n);
60 if (argc - optind < 2)
62 printf(
"<input stdhep filenames> <output stdhep basename>\n");
67 const gsl_rng_type * T;
72 r = gsl_rng_alloc (T);
73 gsl_rng_set(r, rseed);
79 char *output_basename = argv[argc-1];
80 char output_filename[100];
83 int mark_optind = optind;
84 while(optind < argc - 1){
85 n_events +=
open_read(argv[optind++], istream);
88 printf(
"read %d events\n", n_events);
91 poisson_mu = ((double) n_events)/output_n*(1-poisson_mu_correction);
92 printf(
"Setting mu to %f\n", poisson_mu);
95 vector<stdhep_entry> new_event;
97 sprintf(output_filename,
"%s_%0*d.stdhep", output_basename, output_filename_digits, 1);
98 open_write(output_filename, ostream, output_n);
99 for (
int nevhep = 0; nevhep < output_n; nevhep++)
101 int n_merge = gsl_ran_poisson(r, poisson_mu);
105 for (
int i = 0; i < n_merge; i++)
109 if (mark_optind < argc - 1)
115 printf(
"Out of input events\n");
void add_filler_particle(vector< stdhep_entry > *new_event)
void open_write(char *filename, int ostream, int n_events)
int open_read(char *filename, int istream, int n_events)
void write_stdhep(vector< stdhep_entry > *new_event, int nevhep)
int read_stdhep(vector< stdhep_entry > *new_event)
bool read_next(int istream)
void close_read(int istream)
void write_file(int ostream)
void close_write(int ostream)