7 #include <gsl/gsl_rng.h>
8 #include <gsl/gsl_randist.h>
14 double px = entry->
phep[0];
15 double py = entry->
phep[1];
16 double pz = entry->
phep[2];
17 double vx = entry->
vhep[0];
18 double vy = entry->
vhep[1];
19 double vz = entry->
vhep[2];
22 entry->
phep[1] = py*cos(theta_x) - pz*sin(theta_x);
23 entry->
phep[2] = py*sin(theta_x) + pz*cos(theta_x);
29 entry->
phep[0] = px*cos(theta_y) + pz*sin(theta_y);
30 entry->
phep[2] = pz*cos(theta_y) - px*sin(theta_y);
33 entry->
vhep[1] = vy*cos(theta_x) - vz*sin(theta_x);
34 entry->
vhep[2] = vy*sin(theta_x) + vz*cos(theta_x);
40 entry->
vhep[0] = vx*cos(theta_y) + vz*sin(theta_y);
41 entry->
vhep[2] = vz*cos(theta_y) - vx*sin(theta_y);
48 int main(
int argc,
char** argv)
51 vector<stdhep_entry> new_event;
56 double theta_y = 0.0305;
66 while ((c = getopt(argc,argv,
"hs:x:y:u:v:w:X:Y:Z:")) != -1)
70 printf(
"-h: print this help\n");
71 printf(
"-s: RNG seed\n");
72 printf(
"-x: beam sigma_x in mm; default = 0\n");
73 printf(
"-y: beam sigma_y in mm; default = 0\n");
74 printf(
"-u: beam x rotation in radians; default = 0\n");
75 printf(
"-v: beam y rotation in radians; default = 0.0305 rad\n");
76 printf(
"-w: beam z rotation in radians; default = 0\n");
77 printf(
"-X: target X in mm; default = 0\n");
78 printf(
"-Y: target Y in mm; default = 0\n");
79 printf(
"-Z: target Z in mm; default = 0\n");
86 theta_x = atof(optarg);
89 theta_y = atof(optarg);
92 theta_z = atof(optarg);
95 sigma_x = atof(optarg);
98 sigma_y = atof(optarg);
101 target_x = atof(optarg);
104 target_y = atof(optarg);
107 target_z = atof(optarg);
110 printf(
"Invalid option or missing option argument; -h to list options\n");
118 printf(
"<input stdhep filename> <output stdhep filename>\n");
123 const gsl_rng_type * T;
128 r = gsl_rng_alloc (T);
129 gsl_rng_set(r, rseed);
135 n_events =
open_read(argv[optind], istream);
137 open_write(argv[optind+1], ostream, n_events);
139 printf(
"Rotating by %f radians in X, %f radians in Y, and %f radians in Z;\nbeam size %f mm in X and %f mm in Y;\ntarget shifted by (X,Y,Z)=(%f,%f,%f) mm\n", theta_x, theta_y, theta_z, sigma_x, sigma_y, target_x, target_y, target_z);
149 double shift_x = 0.0, shift_y = 0.0;
150 if (sigma_x > 0) shift_x = sigma_x * gsl_ran_gaussian(r, sigma_x);
151 if (sigma_y > 0) shift_y = sigma_y * gsl_ran_gaussian(r, sigma_y);
153 double temp_x, temp_y;
154 temp_x = shift_x * cos(theta_z) - shift_y * sin(theta_z);
155 temp_y = shift_y * cos(theta_z) + shift_x * sin(theta_z);
160 for (
int i = 0; i < new_event.size(); i++) {
162 new_event[i].vhep[2] += target_z;
163 new_event[i].vhep[0] += (shift_x + target_x);
164 new_event[i].vhep[1] += (shift_y + target_y);
int main(int argc, char **argv)
void rotate_entry(stdhep_entry *entry, double theta_x, double theta_y)
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)