Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calo_pid: pass input files via a list file #118

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions benchmarks/calo_pid/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,29 @@ rule calo_pid_recon:
set -m # monitor mode to prevent lingering processes
exec env DETECTOR_CONFIG={wildcards.DETECTOR_CONFIG} \
eicrecon {input} -Ppodio:output_file={output} \
-Ppodio:output_collections=MCParticles,EcalEndcapNRecHits,EcalEndcapNClusters,EcalEndcapNParticleIDInput_features,EcalEndcapNParticleIDTarget
-Ppodio:output_collections=MCParticles,EcalEndcapNRecHits,EcalEndcapNClusters,EcalEndcapNParticleIDInput_features,EcalEndcapNParticleIDTarget,EcalEndcapNParticleIDOutput_probability_tensor
"""


rule calo_pid:
rule calo_pid_input_list:
input:
electrons=expand(
"sim_output/calo_pid/{{DETECTOR_CONFIG}}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.tree.edm4eic.root",
PARTICLE=["e-"],
ENERGY=["100MeVto20GeV"],
PHASE_SPACE=["130to177deg"],
INDEX=range(100),
),
pions=expand(
"sim_output/calo_pid/{{DETECTOR_CONFIG}}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.tree.edm4eic.root",
PARTICLE=["pi-"],
"sim_output/calo_pid/{{DETECTOR_CONFIG}}/{{PARTICLE}}/{ENERGY}/{PHASE_SPACE}/{{PARTICLE}}_{ENERGY}_{PHASE_SPACE}.{INDEX:04d}.eicrecon.tree.edm4eic.root",
ENERGY=["100MeVto20GeV"],
PHASE_SPACE=["130to177deg"],
INDEX=range(100),
),
output:
"listing/calo_pid/{DETECTOR_CONFIG}/{PARTICLE}.lst",
run:
with open(output[0], "wt") as fp:
fp.write("\n".join(input))


rule calo_pid:
input:
electrons="listing/calo_pid/{DETECTOR_CONFIG}/e-.lst",
pions="listing/calo_pid/{DETECTOR_CONFIG}/pi-.lst",
matplotlibrc=".matplotlibrc",
script="benchmarks/calo_pid/calo_pid.py",
output:
Expand Down
14 changes: 10 additions & 4 deletions benchmarks/calo_pid/calo_pid.org
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ vector.register_awkward()
#+begin_src jupyter-python :results silent
DETECTOR_CONFIG=os.environ.get("DETECTOR_CONFIG")
PLOT_TITLE=os.environ.get("PLOT_TITLE")
INPUT_PIONS=os.environ.get("INPUT_PIONS", "").split(" ")
INPUT_ELECTRONS=os.environ.get("INPUT_ELECTRONS", "").split(" ")
INPUT_PIONS=os.environ.get("INPUT_PIONS")
INPUT_ELECTRONS=os.environ.get("INPUT_ELECTRONS")

output_dir=Path(os.environ.get("OUTPUT_DIR", "./"))
output_dir.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -75,8 +75,13 @@ def filter_pointing(events):
cond = (part_momentum.eta[:,0] > -3.5) & (part_momentum.eta[:,0] < -2.)
return events[cond]

e = filter_pointing(uproot.concatenate({filename: "events" for filename in INPUT_ELECTRONS}, filter_name=["MCParticles.*", "*EcalEndcapN*"]))
pi = filter_pointing(uproot.concatenate({filename: "events" for filename in INPUT_PIONS}, filter_name=["MCParticles.*", "*EcalEndcapN*"]))
def readlist(path):
with open(path, "rt") as fp:
paths = [line.rstrip() for line in fp.readlines()]
return paths

e = filter_pointing(uproot.concatenate({filename: "events" for filename in readlist(INPUT_ELECTRONS)}, filter_name=["MCParticles.*", "*EcalEndcapN*"]))
pi = filter_pointing(uproot.concatenate({filename: "events" for filename in readlist(INPUT_PIONS)}, filter_name=["MCParticles.*", "*EcalEndcapN*"]))

e_train = e[:len(pi)//2]
pi_train = pi[:len(pi)//2]
Expand Down Expand Up @@ -358,6 +363,7 @@ if "_EcalEndcapNParticleIDOutput_probability_tensor_floatData" in pi_train.field
eval_proba = ak.concatenate([pi_eval_proba, e_eval_proba])

plt.hist(clf.predict_proba(eval_x.to_numpy())[:,1] - eval_proba[:,1].to_numpy())
plt.savefig(output_dir / f"proba_diff.pdf", bbox_inches="tight")
plt.show()
else:
print("EcalEndcapNParticleIDOutput not present")
Expand Down
Loading