LDMX Software
recon::BeamElectronLocator Class Reference

Electron counting processor. More...

#include <BeamElectronLocator.h>

Public Member Functions

 BeamElectronLocator (const std::string &name, framework::Process &process)
 Constructor.
 
virtual ~BeamElectronLocator ()
 Destructor.
 
void configure (framework::config::Parameters &parameters) override
 Configure the processor using the given user specified parameters.
 
void onProcessStart () override
 Prints the configuration to log in debug mode.
 
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 process (Event &event) final
 Processing an event for a Producer is calling produce.
 
- Public Member Functions inherited from framework::EventProcessor
 DECLARE_FACTORY (EventProcessor, EventProcessor *, const std::string &, Process &)
 declare that we have a factory for this class
 
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()=default
 Class destructor.
 
virtual void beforeNewRun (ldmx::RunHeader &run_header)
 Callback for Producers to add parameters to the run header before conditions are initialized.
 
virtual void onNewRun (const ldmx::RunHeader &run_header)
 Callback for the EventProcessor to take any necessary action when the run being processed changes.
 
virtual void onFileOpen (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
 
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

int bin (float coordinate, double binWidth, double min, double max)
 Bins coordinates according to some given granularity (passed as argument).
 

Private Attributes

std::string input_coll_
 The name of the input collection used for counting electrons.
 
std::string input_pass_name_
 The pass name of the input collection used for counting electrons.
 
std::string output_coll_
 The name of the output collection used to save some electron counting variables.
 
double min_xmm_
 The min value measured by the system (edge) in X, in mm.
 
double max_xmm_
 The max value measured by the system (edge) in X, in mm.
 
double min_ymm_
 The min value measured by the system (edge) in Y, in mm.
 
double max_ymm_
 The max value measured by the system (edge) in Y, in mm.
 
double granularity_xmm_
 The granularity of the detector (e.g.
 
double granularity_ymm_
 The granularity of the detector (e.g.
 
double tolerance_
 The tolerance within which simhits are considered to belong to the same electron.
 
bool verbose_ {false}
 Indicate verbose printout to log according to log level.
 

Additional Inherited Members

- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramPool histograms_
 helper object for making and filling histograms
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger the_log_
 The logger for this EventProcessor.
 

Detailed Description

Electron counting processor.

This processor uses calo simhits in e.g. the target to get truth info about beam electrons. The hits associated with beam electrons can already be isolated by the truth hit collection producer. However, the simhits have approximately infinite resolution. This processor's raison d'ĂȘtre is to run some sort of grouping, to ensure we have at most one reconstructed truth information object per electron.

Definition at line 26 of file BeamElectronLocator.h.

Constructor & Destructor Documentation

◆ BeamElectronLocator()

recon::BeamElectronLocator::BeamElectronLocator ( const std::string & name,
framework::Process & process )

Constructor.

Parameters
nameName for this instance of the class.
processThe Process class associated with EventProcessor, provided by the framework.

Definition at line 5 of file BeamElectronLocator.cxx.

Base class for a module which produces a data product.
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.

◆ ~BeamElectronLocator()

recon::BeamElectronLocator::~BeamElectronLocator ( )
virtual

Destructor.

Definition at line 9 of file BeamElectronLocator.cxx.

9{}

Member Function Documentation

◆ bin()

int recon::BeamElectronLocator::bin ( float coordinate,
double binWidth,
double min,
double max )
private

Bins coordinates according to some given granularity (passed as argument).

Returns the lower bin edge. -1 for underflow (coordinate < min_in_mm); with a system of N bins, returns n = N if coordinate > max_in_mm.

TODO also implement a function that returns the grid of non-empty hit coordinates, which accounts for that we don't know the multiplicity at a location

Definition at line 103 of file BeamElectronLocator.cxx.

104 {
105 int n = 0;
106 while (coordinate > min + n * binWidth) {
107 n++;
108 if (min + n * binWidth > max) {
109 // don't go out of bounds, but, still indicate overflow by increasing n
110 // before breaking
111 break;
112 }
113 }
114 // the n we have now is the first bin beyond our coordinate.
115 // better aligned with conventions to return the lower edge.
116 return n - 1;
117}

Referenced by produce().

◆ configure()

void recon::BeamElectronLocator::configure ( framework::config::Parameters & parameters)
overridevirtual

Configure the processor using the given user specified parameters.

The user specified parameters that are available are defined in the python configuration class. Look at the beamElecronLocator.py in Recon/python for the python structure.

Parameters
parametersSet of parameters used to configure this processor.

Reimplemented from framework::EventProcessor.

Definition at line 11 of file BeamElectronLocator.cxx.

11 {
12 input_coll_ = parameters.get<std::string>("input_collection");
13 input_pass_name_ = parameters.get<std::string>("input_pass_name");
14 output_coll_ = parameters.get<std::string>("output_collection");
15 granularity_xmm_ = parameters.get<double>("granularity_X_mm");
16 granularity_ymm_ = parameters.get<double>("granularity_Y_mm");
17 tolerance_ = parameters.get<double>("min_granularity_mm");
18 min_xmm_ = parameters.get<double>("min_X_mm");
19 max_xmm_ = parameters.get<double>("max_X_mm");
20 min_ymm_ = parameters.get<double>("min_Y_mm");
21 max_ymm_ = parameters.get<double>("max_Y_mm");
22 verbose_ = parameters.get<bool>("verbose");
23}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
std::string input_coll_
The name of the input collection used for counting electrons.
double max_ymm_
The max value measured by the system (edge) in Y, in mm.
double granularity_ymm_
The granularity of the detector (e.g.
double tolerance_
The tolerance within which simhits are considered to belong to the same electron.
double min_xmm_
The min value measured by the system (edge) in X, in mm.
std::string input_pass_name_
The pass name of the input collection used for counting electrons.
bool verbose_
Indicate verbose printout to log according to log level.
double min_ymm_
The min value measured by the system (edge) in Y, in mm.
double max_xmm_
The max value measured by the system (edge) in X, in mm.
std::string output_coll_
The name of the output collection used to save some electron counting variables.
double granularity_xmm_
The granularity of the detector (e.g.

References framework::config::Parameters::get(), granularity_xmm_, granularity_ymm_, input_coll_, input_pass_name_, max_xmm_, max_ymm_, min_xmm_, min_ymm_, output_coll_, tolerance_, and verbose_.

◆ onProcessStart()

void recon::BeamElectronLocator::onProcessStart ( )
overridevirtual

Prints the configuration to log in debug mode.

Reimplemented from framework::EventProcessor.

Definition at line 24 of file BeamElectronLocator.cxx.

24 {
25 ldmx_log(debug) << "BeamElectronLocator is using parameters: "
26 << " \n\tinput_collection = " << input_coll_
27 << " \n\tinput_pass_name = " << input_pass_name_
28 << " \n\toutput_collection = " << output_coll_
29 << " \n\tgranularity_X_mm = " << granularity_xmm_
30 << " \n\tgranularity_Y_mm = " << granularity_ymm_
31 << " \n\tmin_granularity_mm = " << tolerance_
32 << " \n\tmin_X_mm = " << min_xmm_
33 << " \n\tmax_X_mm = " << max_xmm_
34 << " \n\tmin_Y_mm = " << min_ymm_
35 << " \n\tmax_Y_mm = " << max_ymm_
36 << " \n\tverbose = " << verbose_;
37}

References granularity_xmm_, granularity_ymm_, input_coll_, input_pass_name_, max_xmm_, max_ymm_, min_xmm_, min_ymm_, output_coll_, tolerance_, and verbose_.

◆ produce()

void recon::BeamElectronLocator::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 39 of file BeamElectronLocator.cxx.

39 {
40 // Check if the input collection exists. If not,
41 // don't bother processing the event.
42 if (!event.exists(input_coll_, input_pass_name_)) {
43 ldmx_log(fatal) << "Attemping to use non-existing input collection "
44 << input_coll_ << "_" << input_pass_name_
45 << " to locate electrons! Exiting.";
46 return;
47 }
48
49 std::vector<ldmx::BeamElectronTruth> beam_electron_info;
50 const auto sim_hits{event.getCollection<ldmx::SimCalorimeterHit>(
52
53 if (verbose_) {
54 ldmx_log(info) << "Looping through simhits in event "
55 << event.getEventNumber() << ".";
56 }
57
58 for (const auto &sim_hit : sim_hits) {
59 // check if we already caught this position, else, add it
60 bool is_matched = false;
61 std::vector<float> pos = sim_hit.getPosition();
62 for (auto found_electrons : beam_electron_info) {
63 // this check makes it square rather than a dR circle
64 if (fabs(pos[0] - found_electrons.getX()) < tolerance_ &&
65 fabs(pos[1] - found_electrons.getY()) < tolerance_) {
66 if (verbose_) {
67 ldmx_log(debug) << "\tHit at (x_ = " << pos[0] << ", y_ = " << pos[1]
68 << " matches electron found at (x_ = "
69 << found_electrons.getX()
70 << ", y_ = " << found_electrons.getY()
71 << "); skip this simhit";
72 }
73 is_matched = true;
74 break; // finding a match means Move on
75 } // if coordinates match something we already found
76 } // over found electrons
77 if (!is_matched) {
78 if (verbose_) {
79 ldmx_log(info) << "\tHit at (x_ = " << pos[0] << ", y_ = " << pos[1]
80 << " not formerly matched. Adding to collection.";
81 }
82 ldmx::BeamElectronTruth electron_info;
83 electron_info.setXYZ(pos[0], pos[1], pos[2]);
84 // find a way to do this later
85 // electronInfo.setThreeMomentum(simHit.getPx(), simHit.getPy(),
86 // simHit.getPz());
87
88 electron_info.setBarX(bin(pos[0], granularity_xmm_, min_xmm_, max_xmm_));
89 electron_info.setBarY(bin(pos[1], granularity_ymm_, min_ymm_, max_ymm_));
90 // set coordinates to bin center
91 electron_info.setBinnedX(min_xmm_ + (electron_info.getBarX() + 0.5) *
93 electron_info.setBinnedY(min_ymm_ + (electron_info.getBarY() + 0.5) *
95
96 beam_electron_info.push_back(electron_info);
97 }
98 } // over simhits in the collection
99
100 event.add(output_coll_, beam_electron_info);
101}
bool exists(const std::string &name, const std::string &passName, bool unique=true) const
Check for the existence of an object or collection with the given name and pass name in the event.
Definition Event.cxx:92
Represents the truth information on beam electrons at the target.
void setBarX(double x)
Set x bar number of the found beam electron.
void setBinnedY(double y)
SetBinned y coordinate of the found beam electron.
double getBarX()
Get x bar number of the found beam electron.
double getBarY()
Get y_ bar number of the found beam electron.
void setXYZ(double x, double y, double z)
Set all three spatial coordinates at once.
void setBarY(double y)
Set y_ bar number of the found beam electron.
void setBinnedX(double x)
SetBinned x coordinate of the found beam electron.
Stores simulated calorimeter hit information.
int bin(float coordinate, double binWidth, double min, double max)
Bins coordinates according to some given granularity (passed as argument).

References bin(), framework::Event::exists(), ldmx::BeamElectronTruth::getBarX(), ldmx::BeamElectronTruth::getBarY(), granularity_xmm_, granularity_ymm_, input_coll_, input_pass_name_, max_xmm_, max_ymm_, min_xmm_, min_ymm_, output_coll_, ldmx::BeamElectronTruth::setBarX(), ldmx::BeamElectronTruth::setBarY(), ldmx::BeamElectronTruth::setBinnedX(), ldmx::BeamElectronTruth::setBinnedY(), ldmx::BeamElectronTruth::setXYZ(), tolerance_, and verbose_.

Member Data Documentation

◆ granularity_xmm_

double recon::BeamElectronLocator::granularity_xmm_
private

The granularity of the detector (e.g.

TS) in X, in mm

Definition at line 101 of file BeamElectronLocator.h.

Referenced by configure(), onProcessStart(), and produce().

◆ granularity_ymm_

double recon::BeamElectronLocator::granularity_ymm_
private

The granularity of the detector (e.g.

TS) in Y, in mm

Definition at line 105 of file BeamElectronLocator.h.

Referenced by configure(), onProcessStart(), and produce().

◆ input_coll_

std::string recon::BeamElectronLocator::input_coll_
private

The name of the input collection used for counting electrons.

Definition at line 67 of file BeamElectronLocator.h.

Referenced by configure(), onProcessStart(), and produce().

◆ input_pass_name_

std::string recon::BeamElectronLocator::input_pass_name_
private

The pass name of the input collection used for counting electrons.

Definition at line 72 of file BeamElectronLocator.h.

Referenced by configure(), onProcessStart(), and produce().

◆ max_xmm_

double recon::BeamElectronLocator::max_xmm_
private

The max value measured by the system (edge) in X, in mm.

Definition at line 87 of file BeamElectronLocator.h.

Referenced by configure(), onProcessStart(), and produce().

◆ max_ymm_

double recon::BeamElectronLocator::max_ymm_
private

The max value measured by the system (edge) in Y, in mm.

Definition at line 96 of file BeamElectronLocator.h.

Referenced by configure(), onProcessStart(), and produce().

◆ min_xmm_

double recon::BeamElectronLocator::min_xmm_
private

The min value measured by the system (edge) in X, in mm.

Definition at line 83 of file BeamElectronLocator.h.

Referenced by configure(), onProcessStart(), and produce().

◆ min_ymm_

double recon::BeamElectronLocator::min_ymm_
private

The min value measured by the system (edge) in Y, in mm.

Definition at line 92 of file BeamElectronLocator.h.

Referenced by configure(), onProcessStart(), and produce().

◆ output_coll_

std::string recon::BeamElectronLocator::output_coll_
private

The name of the output collection used to save some electron counting variables.

Definition at line 78 of file BeamElectronLocator.h.

Referenced by configure(), onProcessStart(), and produce().

◆ tolerance_

double recon::BeamElectronLocator::tolerance_
private

The tolerance within which simhits are considered to belong to the same electron.

Definition at line 111 of file BeamElectronLocator.h.

Referenced by configure(), onProcessStart(), and produce().

◆ verbose_

bool recon::BeamElectronLocator::verbose_ {false}
private

Indicate verbose printout to log according to log level.

Definition at line 116 of file BeamElectronLocator.h.

116{false};

Referenced by configure(), onProcessStart(), and produce().


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