HPS-MC
 
Loading...
Searching...
No Matches
add_mother.cc
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <math.h>
4#include <string.h>
5#include <stdhep_util.hh>
6
7#include <unistd.h>
8
13int main(int argc,char** argv)
14{
15 int nevhep;
16 vector<stdhep_entry> new_event;
17
18 int id = 622;
19 int c;
20
21 while ((c = getopt(argc,argv,"hi:")) != -1)
22 switch (c)
23 {
24 case 'h':
25 printf("-h: print this help\n");
26 printf("-i: PDG ID of mother\n");
27 return(0);
28 break;
29 case 'i':
30 id = atoi(optarg);
31 break;
32 case '?':
33 printf("Invalid option or missing option argument; -h to list options\n");
34 return(1);
35 default:
36 abort();
37 }
38
39 if (argc-optind < 2)
40 {
41 printf("<input stdhep filename> <output stdhep filename>\n");
42 return 1;
43 }
44
45 int n_events;
46 int istream = 0;
47 int ostream = 1;
48
49 n_events = open_read(argv[optind], istream);
50
51 open_write(argv[optind+1], ostream, n_events);
52
53 while (true) {
54 if (!read_next(istream)) {
55 close_read(istream);
56 close_write(ostream);
57 return(0);
58 }
59
60 struct stdhep_entry *temp = new struct stdhep_entry;
61 temp->isthep = 3;
62 temp->idhep = id;
63 for (int j = 0; j < 2; j++) temp->jmohep[j] = 0;
64 for (int j = 0; j < 2; j++) temp->jdahep[j] = 0;
65 for (int j = 0; j < 5; j++) temp->phep[j] = 0.0;
66 temp->phep[2] += 0.1;
67 temp->phep[3] += 0.1;
68 for (int j = 0; j < 4; j++) temp->vhep[j] = 0.0;
69 new_event.push_back(*temp);
70
71 nevhep = read_stdhep(&new_event);
72
73 for (int i = 1; i < new_event.size(); i++) {
74 if (new_event[i].jmohep[0] == 0 && new_event[i].jmohep[1] == 0) {
75 new_event[i].jmohep[0] = 1;
76 new_event[i].jmohep[1] = 1;
77 if (new_event[0].jdahep[0] == 0) new_event[0].jdahep[0] = i+1;
78 new_event[0].jdahep[1] = i+1;
79 }
80 }
81
82 write_stdhep(&new_event,nevhep);
83 write_file(ostream);
84 nevhep++;
85 }
86}
87
int main(int argc, char **argv)
Definition add_mother.cc:13
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)
Definition stdhep_util.hh:7
int idhep
Definition stdhep_util.hh:9
double vhep[4]
int jmohep[2]
double phep[5]
int isthep
Definition stdhep_util.hh:8
int jdahep[2]