1#include "Ecal/DNNEcalVetoProcessor.h"
6#include "Ecal/Event/EcalHit.h"
10const std::vector<std::string> DNNEcalVetoProcessor::input_names_{
"coordinates",
12const std::vector<unsigned int> DNNEcalVetoProcessor::input_sizes_{
13 n_coordinate_dim_ * max_num_hits_, n_feature_dim_* max_num_hits_};
15DNNEcalVetoProcessor::DNNEcalVetoProcessor(
const std::string& name,
17 : Producer(name, process) {
18 for (
const auto& s : input_sizes_) {
19 data_.emplace_back(s, 0);
23void DNNEcalVetoProcessor::configure(
26 rt_ = std::make_unique<ldmx::Ort::ONNXRuntime>(
33 collectionName_ = parameters.
getParameter<std::string>(
"collection_name");
40 const auto& ecal_geometry = getCondition<ldmx::EcalGeometry>(
41 ldmx::EcalGeometry::CONDITIONS_OBJECT_NAME);
44 const auto ecalRecHits =
event.getCollection<
ldmx::EcalHit>(
"EcalRecHits");
45 auto nhits = std::count_if(
46 ecalRecHits.begin(), ecalRecHits.end(),
47 [](
const ldmx::EcalHit& hit) { return hit.getEnergy() > 0; });
49 if (nhits < max_num_hits_) {
51 make_inputs(ecal_geometry, ecalRecHits);
53 auto outputs = rt_->run(input_names_, data_)[0];
54 result.setDiscValue(outputs.at(1));
56 result.setDiscValue(-99);
60 std::cout <<
"... disc_val = " << result.getDisc() << std::endl;
63 result.setVetoResult(result.getDisc() > disc_cut_);
72 event.add(collectionName_, result);
75void DNNEcalVetoProcessor::make_inputs(
77 const std::vector<ldmx::EcalHit>& ecalRecHits) {
79 for (
auto& v : data_) {
80 std::fill(v.begin(), v.end(), 0);
84 for (
const auto& hit : ecalRecHits) {
85 if (hit.getEnergy() <= 0)
continue;
89 data_[0].at(coordinate_x_offset_ + idx) = x;
90 data_[0].at(coordinate_y_offset_ + idx) = y;
91 data_[0].at(coordinate_z_offset_ + idx) = z;
93 data_[1].at(feature_x_offset_ + idx) = x;
94 data_[1].at(feature_y_offset_ + idx) = y;
95 data_[1].at(feature_z_offset_ + idx) = z;
96 data_[1].at(feature_layerid_offset_ + idx) =
id.layer();
97 data_[1].at(feature_energy_offset_ + idx) = std::log(hit.getEnergy());
103 for (
unsigned iname = 0; iname < input_names_.size(); ++iname) {
104 std::cout <<
"=== " << input_names_[iname] <<
" ===" << std::endl;
105 for (
unsigned i = 0; i < input_sizes_[iname]; ++i) {
106 std::cout << data_[iname].at(i) <<
", ";
107 if ((i + 1) % max_num_hits_ == 0) {
108 std::cout << std::endl;
#define DECLARE_PRODUCER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Implements an event buffer system for storing event data.
Class which represents the process under execution.
Class encapsulating parameters for configuring a processor.
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Translation between real-space positions and cell IDs within the ECal.
std::tuple< double, double, double > getPosition(EcalID id) const
Get a cell's position from its ID number.
Stores reconstructed hit information from the ECAL.
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
bool passesVeto() const
Checks if the event passes the Ecal veto.
constexpr StorageControl::Hint hint_shouldKeep
storage control hint alias for backwards compatibility
constexpr StorageControl::Hint hint_shouldDrop
storage control hint alias for backwards compatibility