From 7fc65523b2a71ccec641bc59e00a55690456bb88 Mon Sep 17 00:00:00 2001
From: Dmitry Kalinkin <dmitry.kalinkin@gmail.com>
Date: Thu, 10 Oct 2024 21:47:15 -0400
Subject: [PATCH] benchmarks/femc_*: scale event count with momentum

---
 benchmarks/femc_electron/Snakefile | 20 ++++++++++++++------
 benchmarks/femc_photon/Snakefile   | 20 ++++++++++++++------
 benchmarks/femc_pi0/Snakefile      | 20 ++++++++++++++------
 3 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/benchmarks/femc_electron/Snakefile b/benchmarks/femc_electron/Snakefile
index 0e8dd084..c2a83698 100644
--- a/benchmarks/femc_electron/Snakefile
+++ b/benchmarks/femc_electron/Snakefile
@@ -1,8 +1,15 @@
+def get_n_events(wildcards):
+    energy = float(wildcards.P)
+    n_events = 1000
+    n_events = int(n_events // ((energy / 20) ** 0.5))
+    return n_events
+
+
 rule femc_electron_generate:
 	input:
                 script="benchmarks/femc_electron/analysis/gen_particles.cxx",
 	params:
-		NEVENTS_GEN=1000,
+		N_EVENTS=get_n_events,
 		th_max=28,
 		th_min=2.0
 	output:
@@ -10,23 +17,23 @@ rule femc_electron_generate:
 	shell:
 		"""
 mkdir -p sim_output/femc_electron
-root -l -b -q '{input.script}({params.NEVENTS_GEN},"{output.GEN_FILE}", "e-", {params.th_min}, {params.th_max}, 0., 360., {wildcards.P})'
+root -l -b -q '{input.script}({params.N_EVENTS},"{output.GEN_FILE}", "e-", {params.th_min}, {params.th_max}, 0., 360., {wildcards.P})'
 """
 
 rule femc_electron_simulate:
 	input:
 		GEN_FILE="sim_output/femc_electron/e-_{P}GeV.hepmc"
 	params:
+		N_EVENTS=get_n_events,
 		PHYSICS_LIST="FTFP_BERT"
 	output:
 		SIM_FILE="sim_output/femc_electron/{DETECTOR_CONFIG}_sim_e-_{P}GeV.edm4hep.root"
 	shell:
 		"""
-NEVENTS_SIM=1000
 # Running simulation
 npsim \
    --compactFile $DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml \
-   --numberOfEvents $NEVENTS_SIM \
+   --numberOfEvents {params.N_EVENTS} \
    --physicsList {params.PHYSICS_LIST} \
    --inputFiles {input.GEN_FILE} \
    --outputFile {output.SIM_FILE}
@@ -37,10 +44,11 @@ rule femc_electron_recon:
                 SIM_FILE="sim_output/femc_electron/{DETECTOR_CONFIG}_sim_e-_{P}GeV.edm4hep.root"
         output:
                 REC_FILE="sim_output/femc_electron/{DETECTOR_CONFIG}_rec_e-_{P}GeV.edm4eic.root"
+	params:
+		N_EVENTS=get_n_events,
         shell:
                 """
-NEVENTS_REC=1000
-eicrecon {input.SIM_FILE} -Ppodio:output_file={output.REC_FILE} -Pdd4hep:xml_files=$DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml -Ppodio:output_collections=MCParticles,HcalEndcapPInsertRecHits,HcalEndcapPInsertClusters,HcalEndcapPInsertSubcellHits,EcalEndcapPInsertRecHits,EcalEndcapPInsertClusters,EcalEndcapPInsertRecHits,EcalEndcapPClusters  -Pjana:nevents=$NEVENTS_REC
+eicrecon {input.SIM_FILE} -Ppodio:output_file={output.REC_FILE} -Pdd4hep:xml_files=$DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml -Ppodio:output_collections=MCParticles,HcalEndcapPInsertRecHits,HcalEndcapPInsertClusters,HcalEndcapPInsertSubcellHits,EcalEndcapPInsertRecHits,EcalEndcapPInsertClusters,EcalEndcapPInsertRecHits,EcalEndcapPClusters -Pjana:nevents={params.N_EVENTS}
 """
 
 rule femc_electron_analysis:
diff --git a/benchmarks/femc_photon/Snakefile b/benchmarks/femc_photon/Snakefile
index 40524365..cf976044 100644
--- a/benchmarks/femc_photon/Snakefile
+++ b/benchmarks/femc_photon/Snakefile
@@ -1,8 +1,15 @@
+def get_n_events(wildcards):
+    energy = float(wildcards.P)
+    n_events = 1000
+    n_events = int(n_events // ((energy / 20) ** 0.5))
+    return n_events
+
+
 rule femc_photon_generate:
 	input:
                 script="benchmarks/femc_photon/analysis/gen_particles.cxx",
 	params:
-		NEVENTS_GEN=1000,
+		N_EVENTS=get_n_events,
 		th_max=28,
 		th_min=2.0
 	output:
@@ -10,23 +17,23 @@ rule femc_photon_generate:
 	shell:
 		"""
 mkdir -p sim_output/femc_photon
-root -l -b -q '{input.script}({params.NEVENTS_GEN},"{output.GEN_FILE}", "gamma", {params.th_min}, {params.th_max}, 0., 360., {wildcards.P})'
+root -l -b -q '{input.script}({params.N_EVENTS},"{output.GEN_FILE}", "gamma", {params.th_min}, {params.th_max}, 0., 360., {wildcards.P})'
 """
 
 rule femc_photon_simulate:
 	input:
 		GEN_FILE="sim_output/femc_photon/photon_{P}GeV.hepmc"
 	params:
+		N_EVENTS=get_n_events,
 		PHYSICS_LIST="FTFP_BERT"
 	output:
 		SIM_FILE="sim_output/femc_photon/{DETECTOR_CONFIG}_sim_photon_{P}GeV.edm4hep.root"
 	shell:
 		"""
-NEVENTS_SIM=1000
 # Running simulation
 npsim \
    --compactFile $DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml \
-   --numberOfEvents $NEVENTS_SIM \
+   --numberOfEvents {params.N_EVENTS} \
    --physicsList {params.PHYSICS_LIST} \
    --inputFiles {input.GEN_FILE} \
    --outputFile {output.SIM_FILE}
@@ -37,10 +44,11 @@ rule femc_photon_recon:
                 SIM_FILE="sim_output/femc_photon/{DETECTOR_CONFIG}_sim_photon_{P}GeV.edm4hep.root"
         output:
                 REC_FILE="sim_output/femc_photon/{DETECTOR_CONFIG}_rec_photon_{P}GeV.edm4eic.root"
+	params:
+		N_EVENTS=get_n_events,
         shell:
                 """
-NEVENTS_REC=1000
-eicrecon {input.SIM_FILE} -Ppodio:output_file={output.REC_FILE} -Pdd4hep:xml_files=$DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml -Ppodio:output_collections=MCParticles,HcalEndcapPInsertRecHits,HcalEndcapPInsertClusters,HcalEndcapPInsertSubcellHits,EcalEndcapPInsertRecHits,EcalEndcapPInsertClusters,EcalEndcapPInsertRecHits,EcalEndcapPClusters  -Pjana:nevents=$NEVENTS_REC
+eicrecon {input.SIM_FILE} -Ppodio:output_file={output.REC_FILE} -Pdd4hep:xml_files=$DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml -Ppodio:output_collections=MCParticles,HcalEndcapPInsertRecHits,HcalEndcapPInsertClusters,HcalEndcapPInsertSubcellHits,EcalEndcapPInsertRecHits,EcalEndcapPInsertClusters,EcalEndcapPInsertRecHits,EcalEndcapPClusters -Pjana:nevents={params.N_EVENTS}
 """
 
 rule femc_photon_analysis:
diff --git a/benchmarks/femc_pi0/Snakefile b/benchmarks/femc_pi0/Snakefile
index 4936040c..49497f06 100644
--- a/benchmarks/femc_pi0/Snakefile
+++ b/benchmarks/femc_pi0/Snakefile
@@ -1,8 +1,15 @@
+def get_n_events(wildcards):
+    energy = float(wildcards.P)
+    n_events = 1000
+    n_events = int(n_events // ((energy / 20) ** 0.5))
+    return n_events
+
+
 rule femc_pi0_generate:
 	input:
                 script="benchmarks/femc_pi0/analysis/gen_particles.cxx",
 	params:
-		NEVENTS_GEN=1000,
+		N_EVENTS=get_n_events,
 		th_max=28,
 		th_min=2.0
 	output:
@@ -10,23 +17,23 @@ rule femc_pi0_generate:
 	shell:
 		"""
 mkdir -p sim_output/femc_pi0
-root -l -b -q '{input.script}({params.NEVENTS_GEN},"{output.GEN_FILE}", "pi0", {params.th_min}, {params.th_max}, 0., 360., {wildcards.P})'
+root -l -b -q '{input.script}({params.N_EVENTS},"{output.GEN_FILE}", "pi0", {params.th_min}, {params.th_max}, 0., 360., {wildcards.P})'
 """
 
 rule femc_pi0_simulate:
 	input:
 		GEN_FILE="sim_output/femc_pi0/pi0_{P}GeV.hepmc"
 	params:
+		N_EVENTS=get_n_events,
 		PHYSICS_LIST="FTFP_BERT"
 	output:
 		SIM_FILE="sim_output/femc_pi0/{DETECTOR_CONFIG}_sim_pi0_{P}GeV.edm4hep.root"
 	shell:
 		"""
-NEVENTS_SIM=1000
 # Running simulation
 npsim \
    --compactFile $DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml \
-   --numberOfEvents $NEVENTS_SIM \
+   --numberOfEvents {params.N_EVENTS} \
    --physicsList {params.PHYSICS_LIST} \
    --inputFiles {input.GEN_FILE} \
    --outputFile {output.SIM_FILE}
@@ -37,10 +44,11 @@ rule femc_pi0_recon:
                 SIM_FILE="sim_output/femc_pi0/{DETECTOR_CONFIG}_sim_pi0_{P}GeV.edm4hep.root"
         output:
                 REC_FILE="sim_output/femc_pi0/{DETECTOR_CONFIG}_rec_pi0_{P}GeV.edm4eic.root"
+	params:
+		N_EVENTS=get_n_events,
         shell:
                 """
-NEVENTS_REC=1000
-eicrecon {input.SIM_FILE} -Ppodio:output_file={output.REC_FILE} -Pdd4hep:xml_files=$DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml -Ppodio:output_collections=MCParticles,HcalEndcapPInsertRecHits,HcalEndcapPInsertClusters,HcalEndcapPInsertSubcellHits,EcalEndcapPInsertRecHits,EcalEndcapPInsertClusters,EcalEndcapPInsertRecHits,EcalEndcapPClusters  -Pjana:nevents=$NEVENTS_REC
+eicrecon {input.SIM_FILE} -Ppodio:output_file={output.REC_FILE} -Pdd4hep:xml_files=$DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml -Ppodio:output_collections=MCParticles,HcalEndcapPInsertRecHits,HcalEndcapPInsertClusters,HcalEndcapPInsertSubcellHits,EcalEndcapPInsertRecHits,EcalEndcapPInsertClusters,EcalEndcapPInsertRecHits,EcalEndcapPClusters -Pjana:nevents={params.N_EVENTS}
 """
 
 rule femc_pi0_analysis:
-- 
GitLab