LDMX Software
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ecal::DNNEcalVetoProcessor Class Reference

Determines if event is vetoable using ECAL hit information w/ a deep neural network. More...

#include <DNNEcalVetoProcessor.h>

Public Member Functions

 DNNEcalVetoProcessor (const std::string &name, framework::Process &process)
 
void configure (framework::config::Parameters &parameters) override
 Callback for the EventProcessor to configure itself from the given set of parameters.
 
void produce (framework::Event &event) override
 Process the event and put new data products into it.
 
- Public Member Functions inherited from framework::Producer
 Producer (const std::string &name, Process &process)
 Class constructor.
 
virtual void beforeNewRun (ldmx::RunHeader &header)
 Handle allowing producers to modify run headers before the run begins.
 
- Public Member Functions inherited from framework::EventProcessor
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()
 Class destructor.
 
virtual void onNewRun (const ldmx::RunHeader &runHeader)
 Callback for the EventProcessor to take any necessary action when the run being processed changes.
 
virtual void onFileOpen (EventFile &eventFile)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &eventFile)
 Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
 
virtual void onProcessStart ()
 Callback for the EventProcessor to take any necessary action when the processing of events starts, such as creating histograms.
 
virtual void onProcessEnd ()
 Callback for the EventProcessor to take any necessary action when the processing of events finishes, such as calculating job-summary quantities.
 
template<class T >
const T & getCondition (const std::string &condition_name)
 Access a conditions object for the current event.
 
TDirectory * getHistoDirectory ()
 Access/create a directory in the histogram file for this event processor to create histograms and analysis tuples.
 
void setStorageHint (framework::StorageControl::Hint hint)
 Mark the current event as having the given storage control hint from this module.
 
void setStorageHint (framework::StorageControl::Hint hint, const std::string &purposeString)
 Mark the current event as having the given storage control hint from this module and the given purpose string.
 
int getLogFrequency () const
 Get the current logging frequency from the process.
 
int getRunNumber () const
 Get the run number from the process.
 
std::string getName () const
 Get the processor name.
 
void createHistograms (const std::vector< framework::config::Parameters > &histos)
 Internal function which is used to create histograms passed from the python configuration @parma histos vector of Parameters that configure histograms to create.
 

Private Member Functions

void make_inputs (const ldmx::EcalGeometry &geom, const std::vector< ldmx::EcalHit > &ecalRecHits)
 Make inputs to the DNN from ECAL RecHits.
 

Private Attributes

float disc_cut_ = -99
 
std::vector< std::vector< float > > data_
 
std::unique_ptr< ldmx::Ort::ONNXRuntimert_
 
std::string collectionName_ {"DNNEcalVeto"}
 Name of the collection which will containt the results.
 
bool debug_ = false
 

Static Private Attributes

static constexpr unsigned int max_num_hits_ = 50
 Maximum number of hits allowed in ECAL.
 
static constexpr unsigned int n_coordinate_dim_ = 3
 
static constexpr unsigned int coordinate_x_offset_ = 0
 
static constexpr unsigned int coordinate_y_offset_ = max_num_hits_
 
static constexpr unsigned int coordinate_z_offset_ = 2 * max_num_hits_
 
static constexpr unsigned int n_feature_dim_ = 5
 
static constexpr unsigned int feature_x_offset_ = 0
 
static constexpr unsigned int feature_y_offset_ = max_num_hits_
 
static constexpr unsigned int feature_z_offset_ = 2 * max_num_hits_
 
static constexpr unsigned int feature_layerid_offset_ = 3 * max_num_hits_
 
static constexpr unsigned int feature_energy_offset_ = 4 * max_num_hits_
 
static const std::vector< std::string > input_names_
 
static const std::vector< unsigned int > input_sizes_
 

Additional Inherited Members

- Static Public Member Functions inherited from framework::EventProcessor
static void declare (const std::string &classname, int classtype, EventProcessorMaker *)
 Internal function which is part of the PluginFactory machinery.
 
- Static Public Attributes inherited from framework::Producer
static const int CLASSTYPE {1}
 Constant used to track EventProcessor types by the PluginFactory.
 
- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramHelper histograms_
 Interface class for making and filling histograms.
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger theLog_
 The logger for this EventProcessor.
 

Detailed Description

Determines if event is vetoable using ECAL hit information w/ a deep neural network.

Definition at line 26 of file DNNEcalVetoProcessor.h.

Constructor & Destructor Documentation

◆ DNNEcalVetoProcessor()

ecal::DNNEcalVetoProcessor::DNNEcalVetoProcessor ( const std::string &  name,
framework::Process process 
)

Definition at line 15 of file DNNEcalVetoProcessor.cxx.

17 : Producer(name, process) {
18 for (const auto& s : input_sizes_) {
19 data_.emplace_back(s, 0);
20 }
21}
Producer(const std::string &name, Process &process)
Class constructor.

◆ ~DNNEcalVetoProcessor()

virtual ecal::DNNEcalVetoProcessor::~DNNEcalVetoProcessor ( )
inlinevirtual

Definition at line 29 of file DNNEcalVetoProcessor.h.

29{}

Member Function Documentation

◆ configure()

void ecal::DNNEcalVetoProcessor::configure ( framework::config::Parameters parameters)
overridevirtual

Callback for the EventProcessor to configure itself from the given set of parameters.

The parameters a processor has access to are the member variables of the python class in the sequence that has className equal to the EventProcessor class name.

For an example, look at MyProcessor.

Parameters
parametersParameters for configuration.

Reimplemented from framework::EventProcessor.

Definition at line 23 of file DNNEcalVetoProcessor.cxx.

24 {
25 disc_cut_ = parameters.getParameter<double>("disc_cut");
26 rt_ = std::make_unique<ldmx::Ort::ONNXRuntime>(
27 parameters.getParameter<std::string>("model_path"));
28
29 // debug mode
30 debug_ = parameters.getParameter<bool>("debug");
31
32 // Set the collection name as defined in the configuration
33 collectionName_ = parameters.getParameter<std::string>("collection_name");
34}
std::string collectionName_
Name of the collection which will containt the results.
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89

References framework::config::Parameters::getParameter().

◆ make_inputs()

void ecal::DNNEcalVetoProcessor::make_inputs ( const ldmx::EcalGeometry geom,
const std::vector< ldmx::EcalHit > &  ecalRecHits 
)
private

Make inputs to the DNN from ECAL RecHits.

Parameters
ecalRecHitsThe EcalHit collection.

Definition at line 75 of file DNNEcalVetoProcessor.cxx.

77 {
78 // clear data
79 for (auto& v : data_) {
80 std::fill(v.begin(), v.end(), 0);
81 }
82
83 unsigned idx = 0;
84 for (const auto& hit : ecalRecHits) {
85 if (hit.getEnergy() <= 0) continue;
86 ldmx::EcalID id(hit.getID());
87 auto [x, y, z] = geom.getPosition(id);
88
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;
92
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());
98
99 ++idx;
100 }
101
102 if (debug_) {
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;
109 }
110 }
111 }
112 } // debug
113}
static constexpr unsigned int max_num_hits_
Maximum number of hits allowed in ECAL.
std::tuple< double, double, double > getPosition(EcalID id) const
Get a cell's position from its ID number.
Extension of DetectorID providing access to ECal layers and cell numbers in a hex grid.
Definition EcalID.h:20

References ldmx::EcalGeometry::getPosition().

◆ produce()

void ecal::DNNEcalVetoProcessor::produce ( framework::Event event)
overridevirtual

Process the event and put new data products into it.

Parameters
eventThe Event to process.

Implements framework::Producer.

Definition at line 36 of file DNNEcalVetoProcessor.cxx.

36 {
38
39 // Get the Ecal Geometry
40 const auto& ecal_geometry = getCondition<ldmx::EcalGeometry>(
41 ldmx::EcalGeometry::CONDITIONS_OBJECT_NAME);
42
43 // Get the collection of digitized Ecal hits from the event.
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; });
48
49 if (nhits < max_num_hits_) {
50 // make inputs
51 make_inputs(ecal_geometry, ecalRecHits);
52 // run the DNN
53 auto outputs = rt_->run(input_names_, data_)[0];
54 result.setDiscValue(outputs.at(1));
55 } else {
56 result.setDiscValue(-99);
57 }
58
59 if (debug_) {
60 std::cout << "... disc_val = " << result.getDisc() << std::endl;
61 }
62
63 result.setVetoResult(result.getDisc() > disc_cut_);
64
65 // If the event passes the veto, keep it. Otherwise, drop the event.
66 if (result.passesVeto()) {
68 } else {
70 }
71
72 event.add(collectionName_, result);
73}
void make_inputs(const ldmx::EcalGeometry &geom, const std::vector< ldmx::EcalHit > &ecalRecHits)
Make inputs to the DNN from ECAL RecHits.
void setStorageHint(framework::StorageControl::Hint hint)
Mark the current event as having the given storage control hint from this module.
Stores reconstructed hit information from the ECAL.
Definition EcalHit.h:19
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

References framework::hint_shouldDrop, framework::hint_shouldKeep, and ldmx::EcalVetoResult::passesVeto().

Member Data Documentation

◆ collectionName_

std::string ecal::DNNEcalVetoProcessor::collectionName_ {"DNNEcalVeto"}
private

Name of the collection which will containt the results.

Definition at line 66 of file DNNEcalVetoProcessor.h.

66{"DNNEcalVeto"};

◆ coordinate_x_offset_

constexpr unsigned int ecal::DNNEcalVetoProcessor::coordinate_x_offset_ = 0
staticconstexprprivate

Definition at line 47 of file DNNEcalVetoProcessor.h.

◆ coordinate_y_offset_

constexpr unsigned int ecal::DNNEcalVetoProcessor::coordinate_y_offset_ = max_num_hits_
staticconstexprprivate

Definition at line 48 of file DNNEcalVetoProcessor.h.

◆ coordinate_z_offset_

constexpr unsigned int ecal::DNNEcalVetoProcessor::coordinate_z_offset_ = 2 * max_num_hits_
staticconstexprprivate

Definition at line 49 of file DNNEcalVetoProcessor.h.

◆ data_

std::vector<std::vector<float> > ecal::DNNEcalVetoProcessor::data_
private

Definition at line 62 of file DNNEcalVetoProcessor.h.

◆ debug_

bool ecal::DNNEcalVetoProcessor::debug_ = false
private

Definition at line 68 of file DNNEcalVetoProcessor.h.

◆ disc_cut_

float ecal::DNNEcalVetoProcessor::disc_cut_ = -99
private

Definition at line 61 of file DNNEcalVetoProcessor.h.

◆ feature_energy_offset_

constexpr unsigned int ecal::DNNEcalVetoProcessor::feature_energy_offset_ = 4 * max_num_hits_
staticconstexprprivate

Definition at line 56 of file DNNEcalVetoProcessor.h.

◆ feature_layerid_offset_

constexpr unsigned int ecal::DNNEcalVetoProcessor::feature_layerid_offset_ = 3 * max_num_hits_
staticconstexprprivate

Definition at line 55 of file DNNEcalVetoProcessor.h.

◆ feature_x_offset_

constexpr unsigned int ecal::DNNEcalVetoProcessor::feature_x_offset_ = 0
staticconstexprprivate

Definition at line 52 of file DNNEcalVetoProcessor.h.

◆ feature_y_offset_

constexpr unsigned int ecal::DNNEcalVetoProcessor::feature_y_offset_ = max_num_hits_
staticconstexprprivate

Definition at line 53 of file DNNEcalVetoProcessor.h.

◆ feature_z_offset_

constexpr unsigned int ecal::DNNEcalVetoProcessor::feature_z_offset_ = 2 * max_num_hits_
staticconstexprprivate

Definition at line 54 of file DNNEcalVetoProcessor.h.

◆ input_names_

const std::vector< std::string > ecal::DNNEcalVetoProcessor::input_names_
staticprivate
Initial value:
{"coordinates",
"features"}

Definition at line 58 of file DNNEcalVetoProcessor.h.

◆ input_sizes_

const std::vector< unsigned int > ecal::DNNEcalVetoProcessor::input_sizes_
staticprivate
Initial value:
{
n_coordinate_dim_ * max_num_hits_, n_feature_dim_* max_num_hits_}

Definition at line 59 of file DNNEcalVetoProcessor.h.

◆ max_num_hits_

constexpr unsigned int ecal::DNNEcalVetoProcessor::max_num_hits_ = 50
staticconstexprprivate

Maximum number of hits allowed in ECAL.

Events with more hits will be marked as BKG directly without running the DNN.

Definition at line 44 of file DNNEcalVetoProcessor.h.

◆ n_coordinate_dim_

constexpr unsigned int ecal::DNNEcalVetoProcessor::n_coordinate_dim_ = 3
staticconstexprprivate

Definition at line 46 of file DNNEcalVetoProcessor.h.

◆ n_feature_dim_

constexpr unsigned int ecal::DNNEcalVetoProcessor::n_feature_dim_ = 5
staticconstexprprivate

Definition at line 51 of file DNNEcalVetoProcessor.h.

◆ rt_

std::unique_ptr<ldmx::Ort::ONNXRuntime> ecal::DNNEcalVetoProcessor::rt_
private

Definition at line 63 of file DNNEcalVetoProcessor.h.


The documentation for this class was generated from the following files: