1#include <catch2/catch_approx.hpp>
2#include <catch2/catch_test_macros.hpp>
3#include <catch2/matchers/catch_matchers.hpp>
8#include "Framework/Configure/Python.h"
24static const double PE_ENERGY = 4.66 / 68;
45static const double MAX_PE_ERROR_DAQ = 40;
47static const double MAX_PE_PERCENT_ERROR_DAQ = 0.4;
59static const int NUM_TEST_SIM_HITS = 1000;
84 double const &rel_diff)
96 bool match(
const double &daq)
const override {
105 std::ostringstream ss;
150 header.setDetectorName(
"ldmx-det-v12");
155 std::vector<ldmx::SimCalorimeterHit> pretend_sim_hits(1);
161 pretend_sim_hits[0].setPosition(-6.70265, 3.70265, 879);
162 pretend_sim_hits[0].setID(
id.raw());
163 pretend_sim_hits[0].addContrib(
173 REQUIRE_NOTHROW(event.add(
"HcalFakeSimHits", pretend_sim_hits));
195 const bool SAVE =
false;
198 std::string hcal_fake_sim_hits_passname_;
199 std::string hcal_rec_hits_passname_;
200 std::string hcal_digis_passname_;
208 hcal_fake_sim_hits_passname_ =
209 ps.getParameter(
"hcal_fake_sim_hits_passname",
"");
210 hcal_digis_passname_ = ps.getParameter(
"hcal_digis_passname",
"");
211 hcal_rec_hits_passname_ = ps.getParameter(
"hcal_rec_hits_passname",
"");
237 "HcalFakeSimHits", hcal_fake_sim_hits_passname_);
239 REQUIRE(sim_hits.size() == 1);
241 float truth_energy = sim_hits.at(0).getEdep();
245 ntuple_.
setVar<
float>(
"SimX", sim_hits.at(0).getPosition()[0]);
246 ntuple_.
setVar<
float>(
"SimY", sim_hits.at(0).getPosition()[1]);
247 ntuple_.
setVar<
float>(
"SimZ", sim_hits.at(0).getPosition()[2]);
248 ntuple_.
setVar<
float>(
"SimTime", sim_hits.at(0).getContrib(0).time_);
252 "HcalDigis", hcal_digis_passname_)};
253 auto daq_digi = daq_digis.getDigi(0);
254 bool is_in_adc_mode = daq_digi.isADC();
264 "HcalRecHits", hcal_rec_hits_passname_);
265 CHECK(rec_hits.size() == 1);
267 auto hit = rec_hits.at(0);
269 CHECK_FALSE(hit.isNoise());
270 CHECK(
id.raw() == sim_hits.at(0).getID());
282 double daq_pe{hit.getPE()};
283 CHECK_THAT(daq_pe,
IsCloseEnough(truth_energy / PE_ENERGY, MAX_PE_ERROR_DAQ,
284 MAX_PE_PERCENT_ERROR_DAQ));
334TEST_CASE(
"Hcal Digi Pipeline test",
"[Hcal][functionality]") {
335 const std::string config_file{
"hcal_digi_pipeline_test_config.py"};
336 char **args{
nullptr};
340 auto p{std::make_unique<framework::Process>(cfg)};
Base classes for all user event processing components to extend.
#define DECLARE_ANALYZER(CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that stores Stores reconstructed hit information from the HCAL.
Class that defines an HCal sensitive detector.
Class that represents a digitized hit in a calorimeter cell readout by an HGCROC.
Class which represents the process under execution.
Class which stores simulated calorimeter hit information.
Base class for a module which does not produce a data product.
NtupleManager & ntuple_
Manager for any ntuples.
TDirectory * getHistoDirectory()
Access/create a directory in the histogram file for this event processor to create histograms and ana...
Implements an event buffer system for storing event data.
void addVar(const std::string &tname, const std::string &vname)
Add a variable of type VarType to the ROOT tree with name 'tname'.
void create(const std::string &tname)
Create a ROOT tree to hold the ntuple variables (ROOT leaves).
void setVar(const std::string &vname, const T &value)
Set the value of the variable named 'vname'.
Class which represents the process under execution.
Base class for a module which produces a data product.
Producer(const std::string &name, Process &process)
Class constructor.
Class encapsulating parameters for configuring a processor.
void analyze(const framework::Event &event) final override
Process the event and make histograms or summaries.
void onProcessStart() final override
Callback for the EventProcessor to take any necessary action when the processing of events starts,...
void configure(framework::config::Parameters &ps) override
Callback for the EventProcessor to configure itself from the given set of parameters.
const double ENERGY_STEP
The step between energies is calculated depending on the min, max energy and the total number of sim ...
const double MAX_ENERGY
Maximum energy to make a simulated hit for [MeV].
double curr_energy_
current energy of the sim hit we are on
const double MIN_ENERGY
Minimum energy to make a sim hit for [MeV] Needs to be above readout threshold (after internal HcalDi...
void beforeNewRun(ldmx::RunHeader &header) final override
Callback for Producers to add parameters to the run header before conditions are initialized.
void produce(framework::Event &event) final override
Process the event and put new data products into it.
Our custom checker which makes sure that the input energy/position is "close enough" to the truth ene...
virtual std::string describe() const override
Describes matcher for printing to terminal.
bool match(const double &daq) const override
Performs the test for this matcher.
const double MAX_ABSOLUTE_DIFF
maximum absolute difference
IsCloseEnough(double const &truth, double const &abs_diff, double const &rel_diff)
Constructor.
const double MAX_RELATIVE_DIFF
maximum relative difference
double truth_
correct (sim-level)
Stores reconstructed hit information from the HCAL.
Implements detector ids for HCal subdetector.
Represents a collection of the digi hits readout by an HGCROC.
Stores simulated calorimeter hit information.
Parameters run(const std::string &root_object, const std::string &pythonScript, char *args[], int nargs)
run the python script and extract the parameters
All classes in the ldmx-sw project use this namespace.