From ef9d217041da4b45a11fbd0d9a5c9324a01f1ce3 Mon Sep 17 00:00:00 2001 From: Christopher Dilks <christopher.j.dilks@gmail.com> Date: Tue, 28 Feb 2023 21:51:10 -0500 Subject: [PATCH] feat: add energy deposition test for OpticalTracker example --- examples/OpticalTracker/CMakeLists.txt | 10 +++++++++ .../scripts/test_energy_deposition.C | 22 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 examples/OpticalTracker/scripts/test_energy_deposition.C diff --git a/examples/OpticalTracker/CMakeLists.txt b/examples/OpticalTracker/CMakeLists.txt index 9dffe3c65..4a3cb5f3b 100644 --- a/examples/OpticalTracker/CMakeLists.txt +++ b/examples/OpticalTracker/CMakeLists.txt @@ -57,3 +57,13 @@ dd4hep_add_test_reg( OpticalTracker_number_of_hits REGEX_FAIL "TEST: failed" DEPENDS OpticalTracker_simulation ) + +# ---Test: Energy deposition +dd4hep_add_test_reg( OpticalTracker_energy_deposition + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_OpticalTracker.sh" + EXEC_ARGS root.exe -b -x -n -q -l + "${OpticalTracker_INSTALL}/scripts/test_energy_deposition.C(\"${OpticalTracker_INSTALL}/sim.root\")" + REGEX_PASS "TEST: passed" + REGEX_FAIL "TEST: failed" + DEPENDS OpticalTracker_simulation + ) diff --git a/examples/OpticalTracker/scripts/test_energy_deposition.C b/examples/OpticalTracker/scripts/test_energy_deposition.C new file mode 100644 index 000000000..64a177334 --- /dev/null +++ b/examples/OpticalTracker/scripts/test_energy_deposition.C @@ -0,0 +1,22 @@ +#include "CLHEP/Units/SystemOfUnits.h" + +void test_energy_deposition(TString sim_file_name="sim.root") { + + // test requirements + const Double_t min_edep = 2*CLHEP::eV; + const Double_t max_edep = 5*CLHEP::eV; + + // get average energy deposition + auto sim_file = new TFile(sim_file_name); + auto t = (TTree*) sim_file->Get("EVENT"); + auto h = new TH1D("h","energy deposition",100,-1,20); + t->Project("h","PFRICHHits.energyDeposit"); + auto ave_edep = h->GetMean(); + + // check if the average energy deposition is within expected range + bool pass_test = ave_edep > min_edep && ave_edep < max_edep; + std::cout << "TEST: " << (pass_test ? "passed" : "failed") + << " with average energy deposition = " << ave_edep/CLHEP::eV << " eV" + << " (expected in range (" << min_edep/CLHEP::eV << "," << max_edep/CLHEP::eV << ") eV)" + << std::endl; +} -- GitLab