From 9c109190a69e5caefb2926f6c03bace78fc8dbda Mon Sep 17 00:00:00 2001
From: Wouter Deconinck <wdconinc@gmail.com>
Date: Tue, 1 Mar 2022 14:45:45 +0000
Subject: [PATCH] Forward DRICH benchmark

---
 benchmarks/pid/config.yml                 | 22 +++++++
 benchmarks/pid/scripts/drich_analysis.cxx | 73 +++++++++++++++++++++++
 2 files changed, 95 insertions(+)
 create mode 100644 benchmarks/pid/scripts/drich_analysis.cxx

diff --git a/benchmarks/pid/config.yml b/benchmarks/pid/config.yml
index 6d93582e..bc5d9971 100644
--- a/benchmarks/pid/config.yml
+++ b/benchmarks/pid/config.yml
@@ -8,6 +8,16 @@ sim:backward:
     matrix:
       - PARTICLE: ["e-", "pi+", "proton"]
 
+sim:forward:
+  extends: .det_benchmark
+  stage: simulate
+  script:
+    - ddsim --runType batch --numberOfEvents 100 --filter.tracker edep0 --compactFile ${DETECTOR_PATH}/${JUGGLER_DETECTOR}.xml --enableGun --gun.energy "5*GeV" --gun.particle "${PARTICLE}" --gun.thetaMin 3*deg --gun.thetaMax 50*deg --gun.distribution "cos(theta)" --outputFile sim_output/sim_pid_forward_${PARTICLE}_5GeV.edm4hep.root
+    - rootls -t sim_output/sim_pid_forward_${PARTICLE}_5GeV.edm4hep.root
+  parallel:
+    matrix:
+      - PARTICLE: ["e-", "pi+", "proton"]
+
 bench:mrich:
   extends: .det_benchmark
   stage: benchmarks
@@ -25,6 +35,18 @@ bench:mrich:
     matrix:
       - PARTICLE: ["e-", "pi+", "proton"]
 
+bench:drich:
+  extends: .det_benchmark
+  stage: benchmarks
+  needs: ["sim:forward"]
+  script:
+    - |
+      mkdir -p results/pid/forward/drich/
+      root -t -x -q -b "benchmarks/pid/scripts/drich_analysis.cxx+(\"sim_output/sim_pid_forward_${PARTICLE}_5GeV.edm4hep.root\", \"${PARTICLE}\")"
+  parallel:
+    matrix:
+      - PARTICLE: ["e-", "pi+", "proton"]
+
 bench:erich:
   extends: .det_benchmark
   stage: benchmarks
diff --git a/benchmarks/pid/scripts/drich_analysis.cxx b/benchmarks/pid/scripts/drich_analysis.cxx
new file mode 100644
index 00000000..768a1c09
--- /dev/null
+++ b/benchmarks/pid/scripts/drich_analysis.cxx
@@ -0,0 +1,73 @@
+////////////////////////////////////////
+// Read reconstruction ROOT output file
+// Plot variables
+////////////////////////////////////////
+
+#include "ROOT/RDataFrame.hxx"
+#include <iostream>
+#include <fmt/core.h>
+
+#include "edm4hep/MCParticleCollection.h"
+#include "edm4hep/SimTrackerHitCollection.h"
+
+#include "TCanvas.h"
+#include "TStyle.h"
+#include "TMath.h"
+#include "TH1.h"
+#include "TF1.h"
+#include "TH1D.h"
+
+using ROOT::RDataFrame;
+using namespace ROOT::VecOps;
+
+void drich_analysis(const char* input_fname = "sim_output/sim_pid_forward_e-_5GeV.edm4hep.root", const char* input_pname = "e-")
+{
+  // Setting for graphs
+  gROOT->SetStyle("Plain");
+  gStyle->SetOptFit(1);
+  gStyle->SetLineWidth(2);
+  gStyle->SetPadTickX(1);
+  gStyle->SetPadTickY(1);
+  gStyle->SetPadGridX(1);
+  gStyle->SetPadGridY(1);
+  gStyle->SetPadLeftMargin(0.14);
+  gStyle->SetPadRightMargin(0.14);
+
+  ROOT::EnableImplicitMT();
+  ROOT::RDataFrame d0("events", input_fname);
+
+  // Define variables
+  auto d1 = d0.Define("nhits", {"DRICHHits.size()"});
+
+  // Define Histograms
+  auto hNhits =
+      d1.Histo1D({"hNhits", "Number of hits per events; Number of hits; Events",
+                  100, 0.0, 2000.0},
+                 "nhits");
+  auto hXYhits =
+      d1.Histo2D({"hXYhits", "Hit positions for events; Horizontal position [mm]; Vertical position [mm]",
+                  1000, -2500.0, +2500.0, 1000, -2500.0, +2500.0},
+                 "DRICHHits.position.x", "DRICHHits.position.y");
+
+  // Event Counts
+  auto nevents_thrown = d1.Count();
+  std::cout << "Number of Thrown Events: " << (*nevents_thrown) << "\n";
+
+  // Draw Histograms
+  {
+    TCanvas* c1 = new TCanvas("c1", "c1", 700, 500);
+    auto h = hXYhits->DrawCopy();
+    c1->SaveAs(fmt::format("results/pid/forward/drich/drich_{}_hits_xy.png",input_pname).c_str());
+    c1->SaveAs(fmt::format("results/pid/forward/drich/drich_{}_hits_xy.pdf",input_pname).c_str());
+  }
+  {
+    TCanvas* c2 = new TCanvas("c2", "c2", 700, 500);
+    c2->SetLogy(1);
+    auto h = hNhits->DrawCopy();
+    //h->GetYaxis()->SetTitleOffset(1.4);
+    h->SetLineWidth(2);
+    h->SetLineColor(kBlue);
+    c2->SaveAs(fmt::format("results/pid/forward/drich/drich_{}_nhits.png",input_pname).c_str());
+    c2->SaveAs(fmt::format("results/pid/forward/drich/drich_{}_nhits.pdf",input_pname).c_str());
+  }
+}
-- 
GitLab