From 21711f9f74e3df75e43e63b2f054f9b4ad18c4f3 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Fri, 27 Dec 2024 00:43:08 -0500 Subject: [PATCH] move to a separate rule, avoid overwriting files --- .../tracking_performances/NhitsvsEta_ePIC.C | 13 +++---- benchmarks/tracking_performances/Snakefile | 35 +++++++++++++------ benchmarks/tracking_performances/draw_hits.C | 14 ++++---- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/benchmarks/tracking_performances/NhitsvsEta_ePIC.C b/benchmarks/tracking_performances/NhitsvsEta_ePIC.C index ce4be54..10eabf6 100644 --- a/benchmarks/tracking_performances/NhitsvsEta_ePIC.C +++ b/benchmarks/tracking_performances/NhitsvsEta_ePIC.C @@ -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); @@ -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 charge(myReader, "MCParticles.charge"); TTreeReaderArray vx_mc(myReader, "MCParticles.vertex.x"); TTreeReaderArray vy_mc(myReader, "MCParticles.vertex.y"); @@ -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.); @@ -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())); } diff --git a/benchmarks/tracking_performances/Snakefile b/benchmarks/tracking_performances/Snakefile index ff21418..d9bb20c 100644 --- a/benchmarks/tracking_performances/Snakefile +++ b/benchmarks/tracking_performances/Snakefile @@ -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? @@ -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}")' """ diff --git a/benchmarks/tracking_performances/draw_hits.C b/benchmarks/tracking_performances/draw_hits.C index abf5c1b..d632c67 100644 --- a/benchmarks/tracking_performances/draw_hits.C +++ b/benchmarks/tracking_performances/draw_hits.C @@ -8,7 +8,7 @@ #include #include -void draw_hits(TString filename="") +void draw_hits(TString filename="", TString output_prefix=".") { //==========Style of the plot============ @@ -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); @@ -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();