164 while ((c = getopt(argc, argv,
"hi:j:")) != -1) {
167 printf(
"-h: print this help\n");
168 printf(
"-i: PDG ID of beam particle (scattered electron/muon, default 623)\n");
169 printf(
"-j: PDG ID of pair particle (A-prime/virtual photon, default 622)\n");
170 printf(
"Usage: %s [-i beam_id] [-j pair_id] <input stdhep> <input lhe> <output stdhep>\n", argv[0]);
173 id_beam = atoi(optarg);
176 id_pair = atoi(optarg);
179 printf(
"Invalid option or missing option argument; -h to list options\n");
186 if (argc - optind < 3) {
187 printf(
"Usage: %s [-i beam_id] [-j pair_id] <input stdhep> <input lhe> <output stdhep>\n", argv[0]);
188 printf(
"Use -h for help\n");
196 int n_events =
open_read(argv[optind], istream);
198 fprintf(stderr,
"Error: Could not open STDHEP file %s\n", argv[optind]);
203 FILE* lhe_file = fopen(argv[optind + 1],
"r");
205 fprintf(stderr,
"Error: Could not open LHE file %s\n", argv[optind + 1]);
211 open_write(argv[optind + 2], ostream, n_events);
213 printf(
"Processing events with:\n");
214 printf(
" Beam particle ID: %d\n", id_beam);
215 printf(
" Pair particle ID: %d\n", id_pair);
218 int aprime_count = 0;
219 int radiative_count = 0;
228 vector<stdhep_entry> input_event;
234 LHEParticle scattered_particle, pair_or_electron, positron;
236 if (!
read_lhe_event(lhe_file, event_type, nup, scattered_particle,
237 pair_or_electron, positron, id_pair)) {
238 fprintf(stderr,
"Error reading LHE event %d\n", event_count);
243 vector<stdhep_entry> output_event;
251 int scattered_idx = -1;
252 for (
size_t i = 0; i < input_event.size(); i++) {
253 if (input_event[i].jmohep[0] == 0 && input_event[i].idhep == 11) {
260 int electron_idx = -1;
261 int positron_idx = -1;
264 for (
size_t i = 0; i < input_event.size(); i++) {
265 if (input_event[i].jmohep[0] == 1) {
266 if (input_event[i].idhep == 11) {
267 if (electron_idx == -1) {
271 }
else if (input_event[i].idhep == -11) {
272 if (positron_idx == -1) {
281 if (electron_idx == -1 || positron_idx == -1) {
282 fprintf(stderr,
"Error: Event %d - Could not find e+e- pair with jmohep[0]=1\n", event_count);
283 fprintf(stderr,
" Found electron: %d, Found positron: %d\n",
284 (electron_idx != -1), (positron_idx != -1));
288 if (pair_count > 2) {
289 fprintf(stderr,
"Warning: Event %d - Found %d particles with jmohep[0]=1, using first two\n",
290 event_count, pair_count);
293 if (input_event.size() > 3 && scattered_idx != -1) {
294 printf(
"Info: A-prime event %d has %lu particles (>3), ignoring extras\n",
295 event_count, input_event.size());
299 double scattered_vertex[4];
300 if (scattered_idx != -1) {
302 for (
int j = 0; j < 4; j++) {
303 scattered_vertex[j] = input_event[scattered_idx].vhep[j];
307 scattered_vertex[0] = 0.0;
308 scattered_vertex[1] = 0.0;
309 scattered_vertex[2] = 0.02;
310 scattered_vertex[3] = 0.0;
316 entry0.
idhep = id_beam;
321 entry0.
phep[0] = scattered_particle.
phep[0];
322 entry0.
phep[1] = scattered_particle.
phep[1];
323 entry0.
phep[2] = scattered_particle.
phep[2];
324 entry0.
phep[3] = scattered_particle.
phep[3];
326 for (
int j = 0; j < 4; j++) {
327 entry0.
vhep[j] = scattered_vertex[j];
329 output_event.push_back(entry0);
334 entry1.
idhep = id_pair;
339 entry1.
phep[0] = pair_or_electron.
phep[0];
340 entry1.
phep[1] = pair_or_electron.
phep[1];
341 entry1.
phep[2] = pair_or_electron.
phep[2];
342 entry1.
phep[3] = pair_or_electron.
phep[3];
343 entry1.
phep[4] = pair_or_electron.
phep[4];
345 for (
int j = 0; j < 4; j++) {
346 entry1.
vhep[j] = input_event[electron_idx].vhep[j];
348 output_event.push_back(entry1);
355 output_event.push_back(entry2);
362 output_event.push_back(entry3);
370 int scattered_idx = -1;
371 for (
size_t i = 0; i < input_event.size(); i++) {
372 if (input_event[i].jmohep[0] == 0 && input_event[i].idhep == 13) {
380 int electron_idx = -1;
381 int positron_idx = -1;
385 for (
size_t i = 0; i < input_event.size(); i++) {
386 if (input_event[i].jmohep[0] == 1) {
387 if (input_event[i].idhep == 11) {
388 if (electron_idx == -1) {
392 }
else if (input_event[i].idhep == -11) {
393 if (positron_idx == -1) {
402 if (electron_idx == -1 || positron_idx == -1) {
403 for (
size_t i = 0; i < input_event.size(); i++) {
404 if (input_event[i].jmohep[0] == 0) {
405 if (input_event[i].idhep == 11 && electron_idx == -1) {
407 }
else if (input_event[i].idhep == -11 && positron_idx == -1) {
415 if (electron_idx == -1 || positron_idx == -1) {
416 fprintf(stderr,
"Error: Event %d - Could not find e+e- pair in radiative event\n", event_count);
417 fprintf(stderr,
" Found electron: %d, Found positron: %d\n",
418 (electron_idx != -1), (positron_idx != -1));
422 if (pair_count > 2) {
423 fprintf(stderr,
"Warning: Event %d - Found %d particles with jmohep[0]=1, using first two\n",
424 event_count, pair_count);
427 if (input_event.size() > 2 && scattered_idx != -1) {
428 printf(
"Info: Radiative event %d has %lu particles (>2), ignoring extras\n",
429 event_count, input_event.size());
433 double scattered_vertex[4];
434 if (scattered_idx != -1) {
436 for (
int j = 0; j < 4; j++) {
437 scattered_vertex[j] = input_event[scattered_idx].vhep[j];
441 for (
int j = 0; j < 4; j++) {
442 scattered_vertex[j] = input_event[electron_idx].vhep[j];
449 entry0.
idhep = id_beam;
454 entry0.
phep[0] = scattered_particle.
phep[0];
455 entry0.
phep[1] = scattered_particle.
phep[1];
456 entry0.
phep[2] = scattered_particle.
phep[2];
457 entry0.
phep[3] = scattered_particle.
phep[3];
459 for (
int j = 0; j < 4; j++) {
460 entry0.
vhep[j] = scattered_vertex[j];
462 output_event.push_back(entry0);
468 entry1.
idhep = id_pair;
475 entry1.
phep[0] = input_event[electron_idx].phep[0] + input_event[positron_idx].phep[0];
476 entry1.
phep[1] = input_event[electron_idx].phep[1] + input_event[positron_idx].phep[1];
477 entry1.
phep[2] = input_event[electron_idx].phep[2] + input_event[positron_idx].phep[2];
478 entry1.
phep[3] = input_event[electron_idx].phep[3] + input_event[positron_idx].phep[3];
481 double E2 = entry1.
phep[3] * entry1.
phep[3];
482 double px2 = entry1.
phep[0] * entry1.
phep[0];
483 double py2 = entry1.
phep[1] * entry1.
phep[1];
484 double pz2 = entry1.
phep[2] * entry1.
phep[2];
485 entry1.
phep[4] = sqrt(E2 - px2 - py2 - pz2);
488 for (
int j = 0; j < 4; j++) {
489 entry1.
vhep[j] = input_event[electron_idx].vhep[j];
491 output_event.push_back(entry1);
498 output_event.push_back(entry2);
505 output_event.push_back(entry3);
508 fprintf(stderr,
"Error: Unknown event type for event %d\n", event_count);
518 if (event_count % 1000 == 0) {
519 printf(
"Processed %d events (%d A-prime, %d radiative)\n",
520 event_count, aprime_count, radiative_count);
529 printf(
"\nSuccessfully processed %d events\n", event_count);
530 printf(
" A-prime events: %d\n", aprime_count);
531 printf(
" Radiative events: %d\n", radiative_count);