Skip to content

Commit

Permalink
Added S3 file grabbing and filtering with hepmc file.
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaJunHuang120000 committed Oct 1, 2024
1 parent 2f38d6f commit 47226e2
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 19,355 deletions.
40 changes: 39 additions & 1 deletion benchmarks/semi_coherent/Snakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
import os
import shutil

from snakemake.remote.S3 import RemoteProvider as S3RemoteProvider


S3 = S3RemoteProvider(
endpoint_url="https://eics3.sdcc.bnl.gov:9000",
access_key_id=os.environ["S3_ACCESS_KEY"],
secret_access_key=os.environ["S3_SECRET_KEY"],
)

rule semi_coherent_get:
input:
S3.remote("eictest/EPIC/EVGEN/CI/ePb_beagle.hepmc"),
output:
"benchmarks/semi_coherent/ePb_beagle.hepmc",
run:
shutil.move(input[0], output[0])

rule semi_coherent_filter:
input:
"benchmarks/semi_coherent/ePb_beagle.hepmc",
output:
"benchmarks/semi_coherent/filtered.hepmc",
shell:
"""
python3 benchmarks/semi_coherent/filter.py {input} {output}
"""

rule semi_coherent_afterburner:
input:
"benchmarks/semi_coherent/filtered.hepmc",
output:
"benchmarks/semi_coherent/ab_output.hepmc.hepmc",
shell:
"""
abconv {input} -p 2
"""

rule semi_coherent_sim:
input:
hepmcfile="benchmarks/semi_coherent/input.hepmc",
hepmcfile="benchmarks/semi_coherent/ab_output.hepmc.hepmc",
warmup="warmup/{DETECTOR_CONFIG}.edm4hep.root",
output:
"sim_output/semi_coherent/{DETECTOR_CONFIG}_semi_coherent.edm4hep.root",
Expand Down
50 changes: 50 additions & 0 deletions benchmarks/semi_coherent/filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import sys

def filter_events(input_file,output_file, particle_id=80000, status=-3):
with open(input_file, 'r') as f:
lines = f.readlines()

events = []
current_event = []

for line in lines:
if line.startswith('E '):
if current_event:
events.append(current_event)
current_event = []
current_event.append(line)

# Append the last event
if current_event:
events.append(current_event)

filtered_events = []
filtered_events.append(lines[0:4])
for event in events:
particle_found = False
for line_index, line in enumerate(event):
if line.startswith('P '):
parts = line.split()
if int(parts[3]) == particle_id and int(parts[2]) == status:
particle_found = True
parts[2] = '-2' # Change the third index to -2
parts[-1] = '200' # Change the last index to 200
event[line_index] = ' '.join(parts) + '\n' # Join the parts back into a line
break
if particle_found:
filtered_events.append(event)

with open(output_file,'w') as f:
for event in filtered_events:
for line in event:
f.write(line)

if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python filter_hepmc.py input.hepmc")
sys.exit(1)

input_file = sys.argv[1]
output_file = sys.argv[2]
filter_events(input_file,output_file)

Loading

0 comments on commit 47226e2

Please sign in to comment.