7 #include <gsl/gsl_rng.h>
8 #include <gsl/gsl_randist.h>
15 int main(
int argc,
char** argv)
18 vector<stdhep_entry> new_event;
20 double poisson_mu = -1.0;
21 int output_n = 500000;
22 int max_output_files = 0;
23 int output_filename_digits = 2;
25 int only_this_file = 0;
31 while ((c = getopt(argc,argv,
"hn:m:N:s:O:")) != -1)
35 printf(
"-h: print this help\n");
36 printf(
"-m: mean number of events in an event\n");
37 printf(
"-N: max number of files to write\n");
38 printf(
"-n: output events per output file\n");
39 printf(
"-s: RNG seed\n");
40 printf(
"-O: only write this one file\n");
44 poisson_mu = atof(optarg);
47 output_n = atoi(optarg);
50 max_output_files = atoi(optarg);
51 output_filename_digits = strlen(optarg);
57 only_this_file = atoi(optarg);
60 printf(
"Invalid option or missing option argument; -h to list options\n");
66 printf(
"Mean events per output event %f, output events per output file %d, max output files %d\n", poisson_mu, output_n, max_output_files);
68 if (argc - optind < 2)
70 printf(
"<input stdhep filenames> <output stdhep basename>\n");
75 const gsl_rng_type * T;
80 r = gsl_rng_alloc (T);
81 gsl_rng_set(r, rseed);
88 if (max_output_files != 0 && poisson_mu < 0) {
95 printf(
"Counted %d events\n", evcount);
97 poisson_mu = (double) evcount/(output_n*max_output_files*poisson_mu);
98 printf(
"set mu = %f\n", poisson_mu);
101 if (poisson_mu < 0) poisson_mu *= -1;
103 char *output_basename = argv[argc-1];
104 char output_filename[100];
108 while (max_output_files == 0 || file_n - 1 < max_output_files) {
109 bool write_this_file =
true;
110 if (only_this_file != 0 && file_n != only_this_file) {
111 printf(
"skip file %d\n", file_n);
112 write_this_file =
false;
114 sprintf(output_filename,
"%s_%0*d.stdhep", output_basename, output_filename_digits, file_n);
116 open_write(output_filename, ostream, output_n);
117 for (
int nevhep = 0; nevhep < output_n; nevhep++)
119 int n_merge = gsl_ran_poisson(r, poisson_mu);
120 if (n_merge == 0 && write_this_file)
123 for (
int i = 0; i < n_merge; i++)
127 if (optind < argc - 1)
133 printf(
"Out of input events\n");
144 if (write_this_file) {
int main(int argc, char **argv)
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)