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 == 622) {
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 += event->at(i).phep[j]*
event->at(i).phep[j];
64 double proper_time = gsl_ran_exponential(r, decay_length);
65 double distance = gamma*beta*proper_time;
66 for (
int j = 0; j < 3; j++) vx[j] = distance * event->at(i).phep[j]/p;
67 vx[3] = gamma*proper_time;
71 if (ap_id < 0) printf(
"no A' found\n");
72 else for (
int i = 0; i <
event->size(); i++) {
73 if (event->at(i).jmohep[0] == ap_id+1 || event->at(i).jmohep[1] == ap_id+1) {
74 for (
int j = 0; j < 4; j++) event->at(i).vhep[j] = vx[j];
84 int main(
int argc,
char** argv)
87 vector<stdhep_entry> new_event;
90 double decay_length = -1.0;
93 while ((c = getopt(argc,argv,
"hs:l:")) != -1)
97 printf(
"-h: print this help\n");
98 printf(
"-s: RNG seed\n");
99 printf(
"-l: A' decay length in mm\n");
103 rseed = atoi(optarg);
106 decay_length = atof(optarg);
109 printf(
"Invalid option or missing option argument; -h to list options\n");
117 printf(
"<input stdhep filename> <output stdhep filename>\n");
122 in_file = fopen(argv[optind],
"r");
125 const gsl_rng_type * T;
130 r = gsl_rng_alloc (T);
131 gsl_rng_set(r, rseed);
138 printf(
"Applying decay length of %f mm\n", decay_length > 0 ? decay_length : 0.0);
142 bool found_event =
false;
143 while (fgets(
line, 1000, in_file) != NULL) {
144 if (strstr(
line,
"<event") != NULL) {
157 fgets(
line, 1000, in_file);
158 sscanf(
line,
"%d %*d %*f %*f %*f %*f", &nup);
159 for (
int i = 0; i < nup; i++) {
161 fgets(
line, 1000, in_file);
162 int icolup0, icolup1;
163 double phep0 = 100.0;
165 sscanf(
line,
"%d %d %d %d %*d %*d %lf %lf %lf %lf %lf %*f %*f", &(temp->
idhep), &(temp->
isthep), &(temp->
jmohep[0]), &(temp->
jmohep[1]), &(temp->
phep[0]), &(temp->
phep[1]), &(temp->
phep[2]), &(temp->
phep[3]), &(temp->
phep[4]));
177 switch (temp->
idhep) {
185 for (
int j = 0; j < 4; j++) temp->
vhep[j] = 0.0;
186 for (
int j = 0; j < 2; j++) temp->
jdahep[j] = 0;
187 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)