Skip to content

Commit

Permalink
move to a separate rule, avoid overwriting files
Browse files Browse the repository at this point in the history
  • Loading branch information
veprbl committed Dec 27, 2024
1 parent 8cce960 commit 21711f9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
13 changes: 4 additions & 9 deletions benchmarks/tracking_performances/NhitsvsEta_ePIC.C
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code to draw average number of hits vs eta at the generated level
// Shyam Kumar; shyam055119@gmail.com; shyam.kumar@ba.infn.it
void NhitsvsEta_ePIC(TString filePath="")
void NhitsvsEta_ePIC(TString filePath="", TString label="", TString output_prefix=".")
{

gStyle->SetPalette(1);
Expand All @@ -18,9 +18,6 @@ void NhitsvsEta_ePIC(TString filePath="")
// Find the last occurrence of '/'
Int_t lastSlashPos = filePath.Last('/');

// Extract the file name
TString filename = (lastSlashPos != kNPOS) ? filePath(lastSlashPos + 1, filePath.Length()) : filePath;

TTreeReaderArray<Float_t> charge(myReader, "MCParticles.charge");
TTreeReaderArray<Double_t> vx_mc(myReader, "MCParticles.vertex.x");
TTreeReaderArray<Double_t> vy_mc(myReader, "MCParticles.vertex.y");
Expand Down Expand Up @@ -109,10 +106,8 @@ void NhitsvsEta_ePIC(TString filePath="")
c1->SetGridx();
c1->SetGridy();

filename.Resize(filename.Sizeof()-14); // keep filename up to energy

TProfile* hits = new TProfile("hits","Nhits (#theta)",70,-3.5,3.5);
hits->SetTitle(Form("%s;#eta_{mc};Nhits",filename.Data()));
hits->SetTitle(Form("%s;#eta_{mc};Nhits",label.Data()));
hits->GetXaxis()->CenterTitle();
hits->GetYaxis()->CenterTitle();
hits->SetMinimum(0.);
Expand Down Expand Up @@ -241,7 +236,7 @@ void NhitsvsEta_ePIC(TString filePath="")
gPad->SetTicks(1,1);
hits->SetLineWidth(2);
hits->Draw("hist");
c1->SaveAs(Form("%s.png",filename.Data()));
c1->SaveAs(Form("Nhitsvsmom%s.root",filename.Data()));
c1->SaveAs(Form("%s/Nhits_vs_eta.png", output_prefix.Data()));
c1->SaveAs(Form("%s/Nhits_vs_eta.root", output_prefix.Data()));
}

35 changes: 25 additions & 10 deletions benchmarks/tracking_performances/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,34 @@ rule tracking_performance_sim_hadd:
hadd {output} {input.simoutput}
"""

rule tracking_performance_at_momentum:
rule tracking_performance_hit_maps:
input:
script="benchmarks/tracking_performances/Tracking_Performances.C",
script_hitsmap="benchmarks/tracking_performances/draw_hits.C",
script_nhits_eta="benchmarks/tracking_performances/NhitsvsEta_ePIC.C",
outsim=lambda wildcards:
expand(
"sim_output/tracking_performance/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PARTICLE}.{ENERGY}.edm4hep.root",
DETECTOR_CONFIG="epic_craterlake_tracking_only", PARTICLE=wildcards.PARTICLE,
ENERGY=f"{float(wildcards.MOMENTUM):.0f}GeV" if float(wildcards.MOMENTUM) >= 1 else f"{float(wildcards.MOMENTUM) * 1000:.0f}MeV",
)
sim_hadd=expand(
"sim_output/tracking_performance/{DETECTOR_CONFIG}/{{PARTICLE}}/{{MOMENTUM}}/{{PARTICLE}}.{{MOMENTUM}}.edm4hep.root",
DETECTOR_CONFIG="epic_craterlake_tracking_only",
)
output:
"local/{SEEDING}/pi-/{MOMENTUM}/{SEEDING_IGNORE}/{PARTICLE}/hitsxy_dd4hep.png",
"local/{SEEDING}/pi-/{MOMENTUM}/{SEEDING_IGNORE}/{PARTICLE}/hitsxy_dd4hep.eps",
"local/{SEEDING}/pi-/{MOMENTUM}/{SEEDING_IGNORE}/{PARTICLE}/hitsxy_dd4hep.root",
"local/{SEEDING}/pi-/{MOMENTUM}/{SEEDING_IGNORE}/{PARTICLE}/hitsrz_dd4hep.png",
"local/{SEEDING}/pi-/{MOMENTUM}/{SEEDING_IGNORE}/{PARTICLE}/hitsrz_dd4hep.eps",
"local/{SEEDING}/pi-/{MOMENTUM}/{SEEDING_IGNORE}/{PARTICLE}/hitsrz_dd4hep.root",
"local/{SEEDING}/pi-/{MOMENTUM}/{SEEDING_IGNORE}/{PARTICLE}/Nhits_vs_eta.png",
"local/{SEEDING}/pi-/{MOMENTUM}/{SEEDING_IGNORE}/{PARTICLE}/Nhits_vs_eta.root",
shell: """
OUTPUT_PREFIX="$(dirname {output[0]})"
root -l -b -q {input.script_hitsmap}'("{input.outsim}", "'$OUTPUT_PREFIX'")'
root -l -b -q {input.script_nhits_eta}'("{input.outsim}", "{wildcards.MOMENTUM}", "'$OUTPUT_PREFIX'")'
"""

rule tracking_performance_at_momentum:
input:
script="benchmarks/tracking_performances/Tracking_Performances.C",
hit_maps=lambda wildcards:
[ "{CAMPAIGN}/{SEEDING}/pi-/{MOMENTUM}/{SEEDING_IGNORE}/{PARTICLE}/Nhits_vs_eta.png".format(**wildcards) ]
if wildcards.CAMPAIGN == "local" else
[],
# TODO pass as a file list?
Expand Down Expand Up @@ -107,8 +124,6 @@ fi
hadd {output.combined_root} {input.sim}
cd {wildcards.CAMPAIGN}
root -l -b -q ../{input.script}'("../{output.combined_root}", "{wildcards.PARTICLE}", {wildcards.MOMENTUM}, 0.15, '$TRUTH_SEEDING')'
root -l -b -q ../{input.script_hitsmap}'("../{input.outsim}")'
root -l -b -q ../{input.script_nhits_eta}'("../{input.outsim}")'
"""


Expand Down
14 changes: 7 additions & 7 deletions benchmarks/tracking_performances/draw_hits.C
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <TLegend.h>
#include <TMath.h>

void draw_hits(TString filename="")
void draw_hits(TString filename="", TString output_prefix=".")
{

//==========Style of the plot============
Expand Down Expand Up @@ -97,9 +97,9 @@ void draw_hits(TString filename="")
l->AddEntry(hitsxy_barrel_tof,"TOFBarrelHits");
l->AddEntry(hitsxy_barrel_mm_out,"OuterMPGDBarrelHits");
l->Draw();
c1->SaveAs("hitsxy_dd4hep.png");
c1->SaveAs("hitsxy_dd4hep.eps");
c1->SaveAs("hitsxy_dd4hep.root");
c1->SaveAs(Form("%s/hitsxy_dd4hep.png", output_prefix.Data()));
c1->SaveAs(Form("%s/hitsxy_dd4hep.eps", output_prefix.Data()));
c1->SaveAs(Form("%s/hitsxy_dd4hep.root", output_prefix.Data()));

TCanvas *c2 = new TCanvas("c2","c2",1200,1000);
c2->SetMargin(0.09, 0.03 ,0.1,0.06);
Expand Down Expand Up @@ -301,9 +301,9 @@ void draw_hits(TString filename="")
l1->AddEntry(hitsrz_bwd_mpgd,"BackwardMPGDEndcapHits");
l1->Draw();

c2->SaveAs("hitsrz_dd4hep.png");
c2->SaveAs("hitsrz_dd4hep.eps");
c2->SaveAs("hitsrz_dd4hep.root");
c2->SaveAs(Form("%s/hitsrz_dd4hep.png", output_prefix.Data()));
c2->SaveAs(Form("%s/hitsrz_dd4hep.eps", output_prefix.Data()));
c2->SaveAs(Form("%s/hitsrz_dd4hep.root", output_prefix.Data()));
// Timer Stop
timer.Stop();
Double_t realtime = timer.RealTime();
Expand Down

0 comments on commit 21711f9

Please sign in to comment.