LDMX Software
BeamElectronLocator.cxx
1#include "Recon/BeamElectronLocator.h"
2
3#include <cmath>
4
7
8namespace recon {
9
11 framework::Process& process)
12 : framework::Producer(name, process) {}
13
15
17 input_coll_ = parameters.get<std::string>("input_collection");
18 input_pass_name_ = parameters.get<std::string>("input_pass_name");
19 output_coll_ = parameters.get<std::string>("output_collection");
20 granularity_xmm_ = parameters.get<double>("granularity_x_mm");
21 granularity_ymm_ = parameters.get<double>("granularity_y_mm");
22 tolerance_ = parameters.get<double>("min_granularity_mm");
23 min_xmm_ = parameters.get<double>("min_x_mm");
24 max_xmm_ = parameters.get<double>("max_x_mm");
25 min_ymm_ = parameters.get<double>("min_y_mm");
26 max_ymm_ = parameters.get<double>("max_y_mm");
27 verbose_ = parameters.get<bool>("verbose");
28}
30 ldmx_log(debug) << "BeamElectronLocator is using parameters: "
31 << " \n\tinput_collection = " << input_coll_
32 << " \n\tinput_pass_name = " << input_pass_name_
33 << " \n\toutput_collection = " << output_coll_
34 << " \n\tgranularity_X_mm = " << granularity_xmm_
35 << " \n\tgranularity_Y_mm = " << granularity_ymm_
36 << " \n\tmin_granularity_mm = " << tolerance_
37 << " \n\tmin_X_mm = " << min_xmm_
38 << " \n\tmax_X_mm = " << max_xmm_
39 << " \n\tmin_Y_mm = " << min_ymm_
40 << " \n\tmax_Y_mm = " << max_ymm_
41 << " \n\tverbose = " << verbose_;
42}
43
45 // Check if the input collection exists. If not,
46 // don't bother processing the event.
47 if (!event.exists(input_coll_, input_pass_name_)) {
48 ldmx_log(fatal) << "Attemping to use non-existing input collection "
49 << input_coll_ << "_" << input_pass_name_
50 << " to locate electrons! Exiting.";
51 return;
52 }
53
54 std::vector<ldmx::BeamElectronTruth> beam_electron_info;
55 const auto sim_hits{event.getCollection<ldmx::SimCalorimeterHit>(
57
58 if (verbose_) {
59 ldmx_log(info) << "Looping through simhits in event "
60 << event.getEventNumber() << ".";
61 }
62
63 for (const auto& sim_hit : sim_hits) {
64 // check if we already caught this position, else, add it
65 bool is_matched = false;
66 std::vector<float> pos = sim_hit.getPosition();
67 for (auto found_electrons : beam_electron_info) {
68 // this check makes it square rather than a dR circle
69 if (fabs(pos[0] - found_electrons.getX()) < tolerance_ &&
70 fabs(pos[1] - found_electrons.getY()) < tolerance_) {
71 if (verbose_) {
72 ldmx_log(debug) << "\tHit at (x_ = " << pos[0] << ", y_ = " << pos[1]
73 << " matches electron found at (x_ = "
74 << found_electrons.getX()
75 << ", y_ = " << found_electrons.getY()
76 << "); skip this simhit";
77 }
78 is_matched = true;
79 break; // finding a match means Move on
80 } // if coordinates match something we already found
81 } // over found electrons
82 if (!is_matched) {
83 if (verbose_) {
84 ldmx_log(info) << "\tHit at (x_ = " << pos[0] << ", y_ = " << pos[1]
85 << " not formerly matched. Adding to collection.";
86 }
87 ldmx::BeamElectronTruth electron_info;
88 electron_info.setXYZ(pos[0], pos[1], pos[2]);
89 // find a way to do this later
90 // electronInfo.setThreeMomentum(simHit.getPx(), simHit.getPy(),
91 // simHit.getPz());
92
93 electron_info.setBarX(bin(pos[0], granularity_xmm_, min_xmm_, max_xmm_));
94 electron_info.setBarY(bin(pos[1], granularity_ymm_, min_ymm_, max_ymm_));
95 // set coordinates to bin center
96 electron_info.setBinnedX(min_xmm_ + (electron_info.getBarX() + 0.5) *
98 electron_info.setBinnedY(min_ymm_ + (electron_info.getBarY() + 0.5) *
100
101 beam_electron_info.push_back(electron_info);
102 }
103 } // over simhits in the collection
104
105 event.add(output_coll_, beam_electron_info);
106}
107
108int BeamElectronLocator::bin(float coordinate, double binWidth, double min,
109 double max) {
110 int n = 0;
111 while (coordinate > min + n * binWidth) {
112 n++;
113 if (min + n * binWidth > max) {
114 // don't go out of bounds, but, still indicate overflow by increasing n
115 // before breaking
116 break;
117 }
118 }
119 // the n we have now is the first bin beyond our coordinate.
120 // better aligned with conventions to return the lower edge.
121 return n - 1;
122}
123
124} // namespace recon
125
Class that represents the truth information about beam electron at the target.
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class which stores simulated calorimeter hit information.
Implements an event buffer system for storing event data.
Definition Event.h:40
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:107
Class which represents the process under execution.
Definition Process.h:34
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
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.
Electron counting processor.
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.
void onProcessStart() override
Prints the configuration to log in debug mode.
void configure(framework::config::Parameters &parameters) override
Configure the processor using the given user specified parameters.
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.
virtual ~BeamElectronLocator()
Destructor.
BeamElectronLocator(const std::string &name, framework::Process &process)
Constructor.
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.
int bin(float coordinate, double binWidth, double min, double max)
Bins coordinates according to some given granularity (passed as argument).
void produce(framework::Event &event) override
Process the event and put new data products into it.
All classes in the ldmx-sw project use this namespace.