LDMX Software
BeamElectronLocator.cxx
1#include "Recon/BeamElectronLocator.h"
2
3namespace recon {
4
6 framework::Process &process)
7 : framework::Producer(name, process) {}
8
10
12 inputColl_ = parameters.getParameter<std::string>("input_collection");
13 inputPassName_ = parameters.getParameter<std::string>("input_pass_name");
14 outputColl_ = parameters.getParameter<std::string>("output_collection");
15 granularityXmm_ = parameters.getParameter<double>("granularity_X_mm");
16 granularityYmm_ = parameters.getParameter<double>("granularity_Y_mm");
17 tolerance_ = parameters.getParameter<double>("min_granularity_mm");
18 minXmm_ = parameters.getParameter<double>("min_X_mm");
19 maxXmm_ = parameters.getParameter<double>("max_X_mm");
20 minYmm_ = parameters.getParameter<double>("min_Y_mm");
21 maxYmm_ = parameters.getParameter<double>("max_Y_mm");
22 verbose_ = parameters.getParameter<bool>("verbose");
23}
25 ldmx_log(debug) << "BeamElectronLocator is using parameters: "
26 << " \n\tinput_collection = " << inputColl_
27 << " \n\tinput_pass_name = " << inputPassName_
28 << " \n\toutput_collection = " << outputColl_
29 << " \n\tgranularity_X_mm = " << granularityXmm_
30 << " \n\tgranularity_Y_mm = " << granularityYmm_
31 << " \n\tmin_granularity_mm = " << tolerance_
32 << " \n\tmin_X_mm = " << minXmm_
33 << " \n\tmax_X_mm = " << maxXmm_
34 << " \n\tmin_Y_mm = " << minYmm_
35 << " \n\tmax_Y_mm = " << maxYmm_
36 << " \n\tverbose = " << verbose_;
37}
38
40 // Check if the input collection exists. If not,
41 // don't bother processing the event.
42 if (!event.exists(inputColl_, inputPassName_)) {
43 ldmx_log(fatal) << "Attemping to use non-existing input collection "
44 << inputColl_ << "_" << inputPassName_
45 << " to locate electrons! Exiting.";
46 return;
47 }
48
49 std::vector<ldmx::BeamElectronTruth> beamElectronInfo;
50 const auto simHits{
52
53 if (verbose_) {
54 ldmx_log(info) << "Looping through simhits in event "
55 << event.getEventNumber() << ".";
56 }
57
58 for (const auto &simHit : simHits) {
59 // check if we already caught this position, else, add it
60 bool isMatched = false;
61 std::vector<float> pos = simHit.getPosition();
62 for (auto foundElectrons : beamElectronInfo) {
63 // this check makes it square rather than a dR circle
64 if (fabs(pos[0] - foundElectrons.getX()) < tolerance_ &&
65 fabs(pos[1] - foundElectrons.getY()) < tolerance_) {
66 if (verbose_) {
67 ldmx_log(debug) << "\tHit at (x = " << pos[0] << ", y = " << pos[1]
68 << " matches electron found at (x = "
69 << foundElectrons.getX()
70 << ", y = " << foundElectrons.getY()
71 << "); skip this simhit";
72 }
73 isMatched = true;
74 break; // finding a match means Move on
75 } // if coordinates match something we already found
76 } // over found electrons
77 if (!isMatched) {
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 electronInfo;
83 electronInfo.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 electronInfo.setBarX(bin(pos[0], granularityXmm_, minXmm_, maxXmm_));
89 electronInfo.setBarY(bin(pos[1], granularityYmm_, minYmm_, maxYmm_));
90 // set coordinates to bin center
91 electronInfo.setBinnedX(minXmm_ +
92 (electronInfo.getBarX() + 0.5) * granularityXmm_);
93 electronInfo.setBinnedY(minYmm_ +
94 (electronInfo.getBarY() + 0.5) * granularityYmm_);
95
96 beamElectronInfo.push_back(electronInfo);
97 }
98 } // over simhits in the collection
99
100 event.add(outputColl_, beamElectronInfo);
101}
102
103int BeamElectronLocator::bin(float coordinate, double binWidth, double min,
104 double max) {
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}
118
119} // namespace recon
120
121DECLARE_PRODUCER_NS(recon, BeamElectronLocator)
#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.
Definition Event.h:41
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
Class which represents the process under execution.
Definition Process.h:36
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
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.
double granularityYmm_
The granularity of the detector (e.g.
double minXmm_
The min value measured by the system (edge) in X, in mm.
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.
virtual ~BeamElectronLocator()
Destructor.
std::string outputColl_
The name of the output collection used to save some electron counting variables.
BeamElectronLocator(const std::string &name, framework::Process &process)
Constructor.
std::string inputPassName_
The pass name of the input collection used for counting electrons.
bool verbose_
Indicate verbose printout to log according to log level.
double minYmm_
The min value measured by the system (edge) in Y, in mm.
std::string inputColl_
The name of the input collection used for counting electrons.
double maxYmm_
The max value measured by the system (edge) in Y, in mm.
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.
double granularityXmm_
The granularity of the detector (e.g.
double maxXmm_
The max value measured by the system (edge) in X, in mm.
All classes in the ldmx-sw project use this namespace.
Definition PerfDict.cxx:45