Skip to content

Commit 8d690b2

Browse files
author
Michał Sieczczyński
committed
Adding benchmark sampF
1 parent 2ce151d commit 8d690b2

File tree

11 files changed

+818
-0
lines changed

11 files changed

+818
-0
lines changed

.gitlab-ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ include:
152152
- local: 'benchmarks/femc_electron/config.yml'
153153
- local: 'benchmarks/femc_photon/config.yml'
154154
- local: 'benchmarks/femc_pi0/config.yml'
155+
- local: 'benchmarks/nhcal_acceptance/config.yml'
156+
- local: 'benchmarks/nhcal_basic_distribution/config.yml'
157+
- local: 'benchmarks/nhcal_sampling_fraction/config.yml'
158+
155159
deploy_results:
156160
allow_failure: true
157161
stage: deploy
@@ -182,6 +186,9 @@ deploy_results:
182186
- "collect_results:femc_electron"
183187
- "collect_results:femc_photon"
184188
- "collect_results:femc_pi0"
189+
- "collect_results:nhcal_acceptance"
190+
- "collect_results:nhcal_basic_distribution"
191+
- "collect_results:nhcal_sampling_fraction"
185192
script:
186193
- snakemake $SNAKEMAKE_FLAGS --cores 1 results/metadata.json
187194
- find results -print | sort | tee summary.txt

Snakefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ include: "benchmarks/insert_tau/Snakefile"
5252
include: "benchmarks/femc_electron/Snakefile"
5353
include: "benchmarks/femc_photon/Snakefile"
5454
include: "benchmarks/femc_pi0/Snakefile"
55+
include: "benchmarks/nhcal_acceptance/Snakefile"
56+
include: "benchmarks/nhcal_basic_distribution/Snakefile"
57+
include: "benchmarks/nhcal_sampling_fraction/Snakefile"
5558

5659
use_s3 = config["remote_provider"].lower() == "s3"
5760
use_xrootd = config["remote_provider"].lower() == "xrootd"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import os
2+
3+
DETECTOR_PATH = os.environ["DETECTOR_PATH"]
4+
5+
rule nhcal_acceptance_simulate:
6+
output:
7+
"sim_output/nhcal_acceptance/E{ENERGY}GeV/sim_{DETECTOR_CONFIG}.{INDEX}.edm4hep.root",
8+
params:
9+
N_EVENTS=10000,
10+
shell:
11+
"""
12+
set -m
13+
mkdir -p sim_output/nhcal_acceptance/E{wildcards.ENERGY}GeV
14+
exec ddsim \
15+
--compactFile {DETECTOR_PATH}/{wildcards.DETECTOR_CONFIG}.xml \
16+
--numberOfEvents {params.N_EVENTS} \
17+
--random.seed $RANDOM \
18+
--enableGun \
19+
-v WARNING \
20+
--gun.particle pi- \
21+
--gun.thetaMin 120*degree \
22+
--gun.thetaMax 180*degree \
23+
--gun.distribution uniform \
24+
--gun.energy "{wildcards.ENERGY}*GeV" \
25+
--outputFile {output}
26+
"""
27+
28+
29+
rule nhcal_acceptance_combine:
30+
input:
31+
lambda wildcards: expand(
32+
"sim_output/nhcal_acceptance/E{ENERGY}GeV/sim_{DETECTOR_CONFIG}.{INDEX:02d}.edm4hep.root",
33+
DETECTOR_CONFIG=wildcards.DETECTOR_CONFIG,
34+
ENERGY=wildcards.ENERGY,
35+
INDEX=range(int(wildcards.N)),
36+
),
37+
wildcard_constraints:
38+
N=r"\d+",
39+
ENERGY=r"\d+"
40+
output:
41+
f"sim_output/nhcal_acceptance/sim_{{DETECTOR_CONFIG}}_E{{ENERGY}}GeV_combined_{{N}}files.edm4hep.root",
42+
shell:
43+
"""
44+
hadd -f {output} {input}
45+
"""
46+
47+
rule nhcal_acceptance_analysis:
48+
input:
49+
combined="sim_output/nhcal_acceptance/sim_{DETECTOR_CONFIG}_E{ENERGY}GeV_combined_{N}files.edm4hep.root",
50+
script="benchmarks/nhcal_acceptance/scripts/acceptance_analysis.cxx",
51+
output:
52+
png=f"results/nhcal_acceptance/analysis_{{DETECTOR_CONFIG}}_E{{ENERGY}}GeV_combined_{{N}}files.png",
53+
pdf=f"results/nhcal_acceptance/analysis_{{DETECTOR_CONFIG}}_E{{ENERGY}}GeV_combined_{{N}}files.pdf",
54+
shell:
55+
"""
56+
root -l -b -q '{input.script}("{input.combined}","{output.pdf}","{output.png}")'
57+
"""
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
sim:nhcal_acceptance:
2+
extends: .det_benchmark
3+
stage: simulate
4+
parallel:
5+
matrix:
6+
- ENERGY: ["1GeV", "5GeV", "10GeV"]
7+
INDEX: ["00","01","02","03","04","05","06","07","08","09"]
8+
script:
9+
- snakemake --cores 5 sim_output/nhcal_acceptance/E${ENERGY}/sim_epic_backward_hcal_only.${INDEX}.edm4hep.root
10+
11+
bench:nhcal_acceptance_analysis:
12+
extends: .det_benchmark
13+
stage: benchmarks
14+
needs:
15+
- "sim:nhcal_acceptance"
16+
parallel:
17+
matrix:
18+
- ENERGY: ["1GeV", "5GeV", "10GeV"]
19+
script:
20+
- snakemake --cores 1 results/nhcal_acceptance/analysis_epic_backward_hcal_only_E${ENERGY}_combined_10files.pdf
21+
22+
collect_results:nhcal_acceptance:
23+
extends: .det_benchmark
24+
stage: collect
25+
needs:
26+
- "bench:nhcal_acceptance_analysis"
27+
parallel:
28+
matrix:
29+
- ENERGY: ["1GeV", "5GeV", "10GeV"]
30+
script:
31+
- ls -lrht
32+
- mv results{,_save}/
33+
- snakemake $SNAKEMAKE_FLAGS --cores 1 --delete-all-output results/nhcal_acceptance/analysis_epic_backward_hcal_only_E${ENERGY}_combined_10files.pdf
34+
- mv results{_save,}/
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include <TChain.h>
2+
#include <TTreeReader.h>
3+
#include <TTreeReaderArray.h>
4+
#include <TTreeReaderValue.h>
5+
#include <TH2D.h>
6+
#include <TCanvas.h>
7+
#include <TFile.h>
8+
#include <TMath.h>
9+
#include <set>
10+
#include <iostream>
11+
#include <TString.h>
12+
13+
using namespace std;
14+
15+
int acceptance_analysis(TString filename, string outname_pdf, string outname_png)
16+
{
17+
TChain *chain = new TChain("events");
18+
chain->Add(filename);
19+
20+
TTreeReader reader(chain);
21+
22+
TTreeReaderArray<int> mc_pdg(reader, "MCParticles.PDG");
23+
TTreeReaderArray<int> mc_genStatus(reader, "MCParticles.generatorStatus");
24+
TTreeReaderArray<double> mc_px(reader, "MCParticles.momentum.x");
25+
TTreeReaderArray<double> mc_py(reader, "MCParticles.momentum.y");
26+
TTreeReaderArray<double> mc_pz(reader, "MCParticles.momentum.z");
27+
28+
TTreeReaderArray<int> contrib_particle_idx(reader, "_HcalEndcapNHitsContributions_particle.index");
29+
TTreeReaderArray<unsigned int> contrib_particle_cid(reader, "_HcalEndcapNHitsContributions_particle.collectionID");
30+
31+
int nEtaBins = 100;
32+
int nPhiBins = 100;
33+
double etaMin = -5, etaMax = 0;
34+
35+
TH2D* hEtaPhiAll = new TH2D("hEtaPhiAll", "All #pi- (status==1); #eta[1]; #phi[rad]",
36+
nEtaBins, etaMin, etaMax, nPhiBins, -TMath::Pi(), TMath::Pi());
37+
38+
TH2D* hEtaPhiDetected = new TH2D("hEtaPhiDetected", "#pi- detected in nHCal; #eta[1]; #phi[rad]",
39+
nEtaBins, etaMin, etaMax, nPhiBins, -TMath::Pi(), TMath::Pi());
40+
41+
while (reader.Next())
42+
{
43+
map<int, pair<double, double>> pi_minus_eta_phi;
44+
set<int> detected;
45+
for (size_t i = 0; i < mc_pdg.GetSize(); ++i)
46+
{
47+
if (mc_pdg[i] == -211 && mc_genStatus[i] == 1)
48+
{
49+
float px = mc_px[i];
50+
float py = mc_py[i];
51+
float pz = mc_pz[i];
52+
53+
float p = sqrt(px * px + py * py + pz * pz);
54+
float eta = 0.5 * log((p + pz) / (p - pz + 1e-8));
55+
float phi = atan2(py, px);
56+
57+
hEtaPhiAll->Fill(eta, phi);
58+
pi_minus_eta_phi[i] = make_pair(eta, phi);
59+
}
60+
}
61+
62+
for (size_t i = 0; i < contrib_particle_idx.GetSize(); i++) {
63+
int idx = contrib_particle_idx[i];
64+
if (pi_minus_eta_phi.count(idx)) {
65+
detected.insert(idx);
66+
}
67+
}
68+
69+
for (auto idx : detected) {
70+
auto [eta, phi] = pi_minus_eta_phi[idx];
71+
hEtaPhiDetected->Fill(eta, phi);
72+
}
73+
}
74+
75+
TH2D* hAcceptance = (TH2D*)hEtaPhiAll->Clone("hAcceptance");
76+
hAcceptance->Divide(hEtaPhiDetected);
77+
hAcceptance->SetTitle("#pi- detected/All");
78+
hAcceptance->SetMinimum(0);
79+
hAcceptance->SetMaximum(1);
80+
81+
TCanvas *canvas = new TCanvas("canvas", "pi- All", 1600, 600);
82+
canvas->Divide(3,1);
83+
canvas->cd(1);
84+
hEtaPhiAll->Draw("COLZ");
85+
canvas->cd(2);
86+
hEtaPhiDetected->Draw("COLZ");
87+
canvas->cd(3);
88+
hAcceptance->Draw("COLZ");
89+
90+
canvas->SaveAs(outname_pdf.c_str());
91+
canvas->SaveAs(outname_png.c_str());
92+
93+
return 0;
94+
}
95+
96+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import os
2+
3+
DETECTOR_PATH = os.environ["DETECTOR_PATH"]
4+
5+
rule nhcal_basic_distribution_simulate:
6+
output:
7+
"sim_output/nhcal_basic_distribution/E{ENERGY}GeV/sim_{DETECTOR_CONFIG}.{INDEX}.edm4hep.root",
8+
params:
9+
N_EVENTS=10000,
10+
shell:
11+
"""
12+
set -m
13+
mkdir -p sim_output/nhcal_basic_distribution/E{wildcards.ENERGY}GeV
14+
exec ddsim \
15+
--compactFile {DETECTOR_PATH}/{wildcards.DETECTOR_CONFIG}.xml \
16+
--numberOfEvents {params.N_EVENTS} \
17+
--random.seed $RANDOM \
18+
--enableGun \
19+
-v WARNING \
20+
--gun.particle neutron \
21+
--gun.thetaMin 120*degree \
22+
--gun.thetaMax 180*degree \
23+
--gun.distribution uniform \
24+
--gun.energy "{wildcards.ENERGY}*GeV" \
25+
--outputFile {output}
26+
"""
27+
28+
29+
rule nhcal_basic_distribution_combine:
30+
input:
31+
lambda wildcards: expand(
32+
"sim_output/nhcal_basic_distribution/E{ENERGY:.1f}GeV/sim_{DETECTOR_CONFIG}.{INDEX:02d}.edm4hep.root",
33+
DETECTOR_CONFIG=wildcards.DETECTOR_CONFIG,
34+
ENERGY=float(wildcards.ENERGY),
35+
INDEX=range(int(wildcards.N)),
36+
),
37+
wildcard_constraints:
38+
N=r"\d+",
39+
ENERGY=r"\d+(\.\d+)?"
40+
output:
41+
f"sim_output/nhcal_basic_distribution/sim_{{DETECTOR_CONFIG}}_E{{ENERGY}}GeV_combined_{{N}}files.edm4hep.root",
42+
shell:
43+
"""
44+
hadd -f {output} {input}
45+
"""
46+
47+
rule nhcal_basic_distribution_analysis:
48+
input:
49+
combined="sim_output/nhcal_basic_distribution/sim_{DETECTOR_CONFIG}_E{ENERGY}GeV_combined_{N}files.edm4hep.root",
50+
script="benchmarks/nhcal_basic_distribution/scripts/basic_distribution_analysis.cxx",
51+
output:
52+
pdf=f"results/nhcal_basic_distribution/analysis_{{DETECTOR_CONFIG}}_E{{ENERGY}}GeV_combined_{{N}}files.pdf",
53+
png=f"results/nhcal_basic_distribution/analysis_{{DETECTOR_CONFIG}}_E{{ENERGY}}GeV_combined_{{N}}files.png",
54+
shell:
55+
"""
56+
root -l -b -q '{input.script}("{input.combined}","{output.pdf}","{output.png}")'
57+
"""
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
sim:nhcal_basic_distribution:
2+
extends: .det_benchmark
3+
stage: simulate
4+
parallel:
5+
matrix:
6+
- ENERGY: ["0.5GeV", "0.7GeV", "1.0GeV", "2.0GeV", "5.0GeV"]
7+
INDEX: ["00","01","02","03","04","05","06","07","08","09"]
8+
script:
9+
- snakemake --cores 5 sim_output/nhcal_basic_distribution/E${ENERGY}/sim_epic_backward_hcal_only.${INDEX}.edm4hep.root
10+
11+
sim:nhcal_basic_distribution_full:
12+
extends: .det_benchmark
13+
stage: simulate
14+
parallel:
15+
matrix:
16+
- ENERGY: ["0.5GeV", "0.7GeV", "1.0GeV", "2.0GeV", "5.0GeV"]
17+
INDEX: ["00","01","02","03","04","05","06","07","08","09"]
18+
script:
19+
- snakemake --cores 5 sim_output/nhcal_basic_distribution/E${ENERGY}/sim_epic_full.${INDEX}.edm4hep.root
20+
21+
bench:nhcal_basic_distribution_analysis:
22+
extends: .det_benchmark
23+
stage: benchmarks
24+
needs:
25+
- "sim:nhcal_basic_distribution"
26+
parallel:
27+
matrix:
28+
- ENERGY: ["0.5GeV", "0.7GeV", "1.0GeV", "2.0GeV", "5.0GeV"]
29+
script:
30+
- snakemake --cores 1 results/nhcal_basic_distribution/analysis_epic_backward_hcal_only_E${ENERGY}_combined_10files.pdf
31+
32+
bench:nhcal_basic_distribution_analysis_full:
33+
extends: .det_benchmark
34+
stage: benchmarks
35+
needs:
36+
- "sim:nhcal_basic_distribution_full"
37+
parallel:
38+
matrix:
39+
- ENERGY: ["0.5GeV", "0.7GeV", "1.0GeV", "2.0GeV", "5.0GeV"]
40+
script:
41+
- snakemake --cores 1 results/nhcal_basic_distribution/analysis_epic_full_E${ENERGY}_combined_10files.pdf
42+
43+
44+
collect_results:nhcal_basic_distribution:
45+
extends: .det_benchmark
46+
stage: collect
47+
needs:
48+
- "bench:nhcal_basic_distribution_analysis"
49+
- "bench:nhcal_basic_distribution_analysis_full"
50+
parallel:
51+
matrix:
52+
- ENERGY: ["0.5GeV", "0.7GeV", "1.0GeV", "2.0GeV", "5.0GeV"]
53+
DETECTOR_CONFIG: ["epic_backward_hcal_only", "epic_full"]
54+
script:
55+
- ls -lrht
56+
- mv results{,_save}/
57+
- snakemake $SNAKEMAKE_FLAGS --cores 1 --delete-all-output results/nhcal_basic_distribution/analysis_${DETECTOR_CONFIG}_E${ENERGY}_combined_10files.pdf
58+
- mv results{_save,}/
59+

0 commit comments

Comments
 (0)