7 #include <gsl/gsl_rng.h>
8 #include <gsl/gsl_randist.h>
15 while (i<event->size()) {
16 if (event->at(i).isthep == 0) {
17 event->erase(event->begin() + i);
18 for (
int j = 0; j <
event->size(); j++) {
19 if (event->at(j).jmohep[0] > i)
20 event->at(j).jmohep[0]--;
21 if (event->at(j).jmohep[1] > i)
22 event->at(j).jmohep[1]--;
23 if (event->at(j).jdahep[0] > i)
24 event->at(j).jdahep[0]--;
25 if (event->at(j).jdahep[1] > i)
26 event->at(j).jdahep[1]--;
35 for (
int i=0;i<
event->size();i++) {
36 event->at(i).jdahep[0] = 0;
37 event->at(i).jdahep[1] = 0;
38 for (
int j = 0; j <
event->size(); j++) {
39 if (event->at(j).jmohep[0] == i+1 || event->at(j).jmohep[1] == i+1) {
40 if (event->at(i).jdahep[0] == 0)
41 event->at(i).jdahep[0] = j+1;
42 event->at(i).jdahep[1] = j+1;
48 void displace_vertex(vector<stdhep_entry> *event, gsl_rng *r,
double decay_length)
52 for (
int i = 0; i <
event->size(); i++) {
53 if (event->at(i).idhep == 625 || event->at(i).idhep == 1000023) {
55 printf(
"multiple A' found\n");
59 double gamma =
event->at(i).phep[3]/
event->at(i).phep[4];
60 double beta = sqrt(1-pow(gamma,-2.0));
62 for (
int j = 0; j < 3; j++) p = sqrt(p*p + event->at(i).phep[j]*event->at(i).phep[j]);
63 double distance = decay_length*gsl_rng_uniform(r);;
64 for (
int j = 0; j < 3; j++) vx[j] = distance * event->at(i).phep[j]/p;
65 vx[3] = distance/beta;
69 if (ap_id < 0) printf(
"no A' found\n");
70 else for (
int i = 0; i <
event->size(); i++) {
71 if (event->at(i).jmohep[0] == ap_id+1 || event->at(i).jmohep[1] == ap_id+1 || event->at(i).idhep == 625 || event->at(i).idhep == 622) {
72 for (
int j = 0; j < 4; j++) event->at(i).vhep[j] = vx[j];
82 int main(
int argc,
char** argv)
85 vector<stdhep_entry> new_event;
88 double decay_length = 150.0;
91 while ((c = getopt(argc,argv,
"hs:l:")) != -1)
95 printf(
"-h: print this help\n");
96 printf(
"-s: RNG seed\n");
97 printf(
"-l: A' decay length in mm\n");
101 rseed = atoi(optarg);
104 decay_length = atof(optarg);
107 printf(
"Invalid option or missing option argument; -h to list options\n");
115 printf(
"<input stdhep filename> <output stdhep filename>\n");
120 in_file = fopen(argv[optind],
"r");
123 const gsl_rng_type * T;
128 r = gsl_rng_alloc (T);
129 gsl_rng_set(r, rseed);
136 printf(
"Applying decay length of %f mm\n", decay_length > 0 ? decay_length : 0.0);
140 bool found_event =
false;
141 while (fgets(
line, 1000, in_file) != NULL) {
142 if (strstr(
line,
"<event") != NULL) {
155 fgets(
line, 1000, in_file);
156 sscanf(
line,
"%d %*d %*f %*f %*f %*f", &nup);
157 for (
int i = 0; i < nup; i++) {
159 fgets(
line, 1000, in_file);
160 sscanf(
line,
"%d %d %d %d %*d %*d %lf %lf %lf %lf %lf %*f %*f",
174 switch (temp->
idhep) {
182 for (
int j = 0; j < 4; j++) temp->
vhep[j] = 0.0;
183 for (
int j = 0; j < 2; j++) temp->
jdahep[j] = 0;
184 new_event.push_back(*temp);
int main(int argc, char **argv)
void set_jdahep(vector< stdhep_entry > *event)
void remove_nulls(vector< stdhep_entry > *event)
void displace_vertex(vector< stdhep_entry > *event, gsl_rng *r, double decay_length)
void open_write(char *filename, int ostream, int n_events)
void write_stdhep(vector< stdhep_entry > *new_event, int nevhep)
void write_file(int ostream)
void close_write(int ostream)