diff --git a/examples/OpticalTracker/CMakeLists.txt b/examples/OpticalTracker/CMakeLists.txt index 9dffe3c6588128dced55857d021a9ec8179f5d2d..4a3cb5f3b9cb26ecc72ea9fa6a57d0768acb9db2 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 0000000000000000000000000000000000000000..64a1773346655134f3981b971dd0453e095198ca --- /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; +}