LDMX Software
hcal::VisiblesVetoProcessor Class Reference

Public Member Functions

 VisiblesVetoProcessor (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 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 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 clearProcessor ()
 
void buildBDTFeatureVector (const ldmx::VisiblesVetoResult &result)
 
bool inList (std::vector< int > parents, int track_id)
 

Private Attributes

int n_layers_hit_ {0}
 
double x_std_ {0}
 
double y_std_ {0}
 
double z_std_ {0}
 
double x_mean_ {0}
 
double y_mean_ {0}
 
double r_mean_ {0}
 
int iso_hits_ {0}
 
double iso_energy_ {0}
 
int n_readout_hits_ {0}
 
double summed_det_ {0}
 
double r_mean_from_photon_track_ {0}
 
double bdt_cut_val_ {0}
 
double beam_energy_mev_ {0}
 
std::vector< float > bdt_features_
 
std::string feature_list_name_
 
std::string rec_pass_name_
 
std::string rec_coll_name_
 
bool recoil_from_tracking_
 
std::string track_pass_name_
 
std::string track_collection_
 
std::string sp_collection_
 
std::string sp_pass_name_
 
std::string sim_particles_pass_name_
 
std::string collection_name_ {"VisiblesVeto"}
 
std::unique_ptr< ldmx::ort::ONNXRuntimert_
 

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

Definition at line 22 of file VisiblesVetoProcessor.h.

Constructor & Destructor Documentation

◆ VisiblesVetoProcessor()

hcal::VisiblesVetoProcessor::VisiblesVetoProcessor ( const std::string & name,
framework::Process & process )
inline

Definition at line 24 of file VisiblesVetoProcessor.h.

25 : Producer(name, process) {}
Producer(const std::string &name, Process &process)
Class constructor.
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.

◆ ~VisiblesVetoProcessor()

virtual hcal::VisiblesVetoProcessor::~VisiblesVetoProcessor ( )
inlinevirtual

Definition at line 27 of file VisiblesVetoProcessor.h.

27{}

Member Function Documentation

◆ buildBDTFeatureVector()

void hcal::VisiblesVetoProcessor::buildBDTFeatureVector ( const ldmx::VisiblesVetoResult & result)
private

Definition at line 18 of file VisiblesVetoProcessor.cxx.

19 {
20 bdt_features_.push_back(result.getNLayersHit());
21 bdt_features_.push_back(result.getXStd());
22 bdt_features_.push_back(result.getYStd());
23 bdt_features_.push_back(result.getZStd());
24 bdt_features_.push_back(result.getXMean());
25 bdt_features_.push_back(result.getYMean());
26 bdt_features_.push_back(result.getRMean());
27 bdt_features_.push_back(result.getIsoHits());
28 bdt_features_.push_back(result.getIsoEnergy());
29 bdt_features_.push_back(result.getNReadoutHits());
30 bdt_features_.push_back(result.getSummedDet());
31 bdt_features_.push_back(result.getDistFromPhotonTrack());
32}

◆ clearProcessor()

void hcal::VisiblesVetoProcessor::clearProcessor ( )
private

Definition at line 64 of file VisiblesVetoProcessor.cxx.

64 {
65 bdt_features_.clear();
66
67 n_layers_hit_ = 0;
68 x_std_ = 0.;
69 y_std_ = 0.;
70 z_std_ = 0.;
71 x_mean_ = 0.;
72 y_mean_ = 0.;
73 r_mean_ = 0.;
74 iso_hits_ = 0;
75 iso_energy_ = 0.;
76 n_readout_hits_ = 0;
77 summed_det_ = 0.;
78 r_mean_from_photon_track_ = 0.;
79}

◆ configure()

void hcal::VisiblesVetoProcessor::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 class_name equal to the EventProcessor class name.

For an example, look at MyProcessor.

Parameters
parametersParameters for configuration.

Reimplemented from framework::EventProcessor.

Definition at line 34 of file VisiblesVetoProcessor.cxx.

35 {
36 feature_list_name_ = parameters.get<std::string>("feature_list_name");
37 // Load BDT ONNX file
38 rt_ = std::make_unique<ldmx::ort::ONNXRuntime>(
39 parameters.get<std::string>("bdt_file"));
40
41 bdt_cut_val_ = parameters.get<double>("disc_cut");
42
43 beam_energy_mev_ = parameters.get<double>("beam_energy");
44
45 // collection and pass names
46 collection_name_ = parameters.get<std::string>("collection_name");
47 rec_pass_name_ = parameters.get<std::string>("rec_pass_name");
48 rec_coll_name_ = parameters.get<std::string>("rec_coll_name");
49
50 recoil_from_tracking_ = parameters.get<bool>("recoil_from_tracking");
51 track_collection_ = parameters.get<std::string>("track_collection");
52 track_pass_name_ = parameters.get<std::string>("track_pass_name");
53
54 sp_collection_ = parameters.get<std::string>("sp_coll_name");
55 sp_pass_name_ = parameters.get<std::string>("sp_pass_name");
56 sim_particles_pass_name_ =
57 parameters.get<std::string>("sim_particles_pass_name");
58}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78

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

◆ inList()

bool hcal::VisiblesVetoProcessor::inList ( std::vector< int > parents,
int track_id )
private

Definition at line 60 of file VisiblesVetoProcessor.cxx.

60 {
61 return std::find(parents.begin(), parents.end(), track_id) != parents.end();
62}

◆ produce()

void hcal::VisiblesVetoProcessor::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 81 of file VisiblesVetoProcessor.cxx.

81 {
83
84 clearProcessor();
85
86 const auto &particle_map{event.getMap<int, ldmx::SimParticle>(
87 "SimParticles", sim_particles_pass_name_)};
88
89 // Get target scoring plane hits for recoil electron
90 // Use this to calculate the projected photon line vector
91 // This currently uses truth-level information, but it should be replaced
92 // by reconstructed tracker information, when available
93 std::vector<double> gamma_p(3);
94 std::vector<double> gamma_x0(3);
95 if (recoil_from_tracking_) {
96 const auto &recoil_tracks{
97 event.getCollection<ldmx::Track>(track_collection_, track_pass_name_)};
98 // Fill this in later when you know how to use it
99 for (auto &track : recoil_tracks) {
100 // need to figure out how to best isolate candidate electron track
101 auto trk_pos = track.getPositionAtTarget();
102 auto trk_mom = track.getMomentumAtTarget();
103 if (track.getCharge() == 1 && track.getNhits() == 5 &&
104 trk_pos.size() == 3 && trk_mom.size() == 3) {
105 gamma_x0 = trk_pos;
106 gamma_p[0] = -1. * trk_mom[0];
107 gamma_p[1] = -1. * trk_mom[1];
108 gamma_p[2] = beam_energy_mev_ - trk_mom[2];
109 }
110 }
111 } else {
112 if (event.exists(sp_collection_, sp_pass_name_)) {
113 const auto &target_sp_hits = event.getCollection<ldmx::SimTrackerHit>(
114 sp_collection_, sp_pass_name_);
115 for (auto const &it : particle_map) {
116 for (auto const &sphit : target_sp_hits) {
117 if (sphit.getPosition()[2] > 0) {
118 if (it.first == sphit.getTrackID()) {
119 if (it.second.getPdgID() == 11 &&
120 inList(it.second.getParents(), 0)) {
121 /* Since SP hit positions are stored as floats and gamma_x0 is
122 a double vector, the conversion here is a little convolcuted.
123 */
124 std::vector<float> x0_float = sphit.getPosition();
125 std::vector<double> x0_double(x0_float.begin(), x0_float.end());
126 gamma_x0 = x0_double;
127 gamma_p[0] = -1. * sphit.getMomentum()[0];
128 gamma_p[1] = -1. * sphit.getMomentum()[1];
129 gamma_p[2] = beam_energy_mev_ - sphit.getMomentum()[2];
130 }
131 }
132 }
133 }
134 }
135 }
136 }
137
138 // Get Hcal reconstructed hits and loop through them to build features
139 const auto &hcal_rec_hits =
140 event.getCollection<ldmx::HcalHit>(rec_coll_name_, rec_pass_name_);
141
142 double z_mean = 0.; // need this when calculating z_std_
143 std::vector<int> layers_hit;
144 for (const ldmx::HcalHit &hit : hcal_rec_hits) {
145 if (hit.getEnergy() > 0.) {
146 ldmx::HcalID det_id(hit.getID());
147 if (det_id.getSection() != 0) { // skip hits that aren't in main Hcal
148 continue;
149 }
150 n_readout_hits_ += 1;
151 double hit_x = hit.getXPos();
152 double hit_y = hit.getYPos();
153 double hit_z = hit.getZPos();
154 double hit_r = sqrt(hit_x * hit_x + hit_y * hit_y);
155
156 summed_det_ += hit.getEnergy();
157
158 x_mean_ += hit_x * hit.getEnergy();
159 y_mean_ += hit_y * hit.getEnergy();
160 z_mean += hit_z * hit.getEnergy();
161 r_mean_ += hit_r * hit.getEnergy();
162
163 // check if this is a new layer in the collection
164 if (!(std::find(layers_hit.begin(), layers_hit.end(),
165 det_id.getLayerID()) != layers_hit.end())) {
166 layers_hit.push_back(det_id.getLayerID());
167 }
168
169 double proj_x =
170 gamma_x0[0] + (hit_z - gamma_x0[2]) * gamma_p[0] / gamma_p[2];
171 double proj_y =
172 gamma_x0[1] + (hit_z - gamma_x0[2]) * gamma_p[1] / gamma_p[2];
173
174 r_mean_from_photon_track_ +=
175 hit.getEnergy() * sqrt((hit_x - proj_x) * (hit_x - proj_x) +
176 (hit_y - proj_y) * (hit_y - proj_y));
177
178 // Calculate isolated hits
179 double closest_point = 9999.;
180 for (const ldmx::HcalHit &hit2 : hcal_rec_hits) {
181 if (hit2.getEnergy() > 0.) {
182 ldmx::HcalID det_i_d2(hit2.getID());
183 if (det_i_d2.getLayerID() == det_id.getLayerID()) {
184 // Determine if a bar is vertical (along y-axis) or horizontal
185 // (along x-axis) Odd layers have horizontal strips Even layers have
186 // vertical strips
187 if (hit.isOrientationX()) {
188 if (abs(hit2.getYPos() - hit_y) > 0) {
189 if (abs(hit2.getYPos() - hit_y) < closest_point) {
190 closest_point = abs(hit2.getYPos() - hit_y);
191 }
192 }
193 }
194 if (hit.isOrientationY()) {
195 if (abs(hit2.getXPos() - hit_x) > 0) {
196 if (abs(hit2.getXPos() - hit_x) < closest_point) {
197 closest_point = abs(hit2.getXPos() - hit_x);
198 }
199 }
200 }
201 }
202 }
203 }
204 if (closest_point > 50.) {
205 iso_hits_ += 1;
206 iso_energy_ += hit.getEnergy();
207 }
208 }
209 }
210
211 n_layers_hit_ = layers_hit.size();
212
213 if (summed_det_ > 0.) {
214 x_mean_ /= summed_det_;
215 y_mean_ /= summed_det_;
216 z_mean /= summed_det_;
217 r_mean_ /= summed_det_;
218
219 r_mean_from_photon_track_ /= summed_det_;
220 }
221
222 for (const ldmx::HcalHit &hit : hcal_rec_hits) {
223 if (hit.getEnergy() > 0.) {
224 ldmx::HcalID det_id(hit.getID());
225 if (det_id.getSection() == 0) {
226 x_std_ += hit.getEnergy() * (hit.getXPos() - x_mean_) *
227 (hit.getXPos() - x_mean_);
228 y_std_ += hit.getEnergy() * (hit.getYPos() - y_mean_) *
229 (hit.getYPos() - y_mean_);
230 z_std_ += hit.getEnergy() * (hit.getZPos() - z_mean) *
231 (hit.getZPos() - z_mean);
232 }
233 }
234 }
235
236 if (summed_det_ > 0.) {
237 x_std_ = sqrt(x_std_ / summed_det_);
238 y_std_ = sqrt(y_std_ / summed_det_);
239 z_std_ = sqrt(z_std_ / summed_det_);
240 }
241
242 result.setVariables(n_layers_hit_, x_std_, y_std_, z_std_, x_mean_, y_mean_,
243 r_mean_, iso_hits_, iso_energy_, n_readout_hits_,
244 summed_det_, r_mean_from_photon_track_);
245
246 buildBDTFeatureVector(result);
247
248 ldmx::ort::FloatArrays inputs({bdt_features_});
249 float pred =
250 rt_->run({feature_list_name_}, inputs, {"probabilities"})[0].at(1);
251 ldmx_log(info) << " Visibles BDT was ran, score is " << pred;
252
253 event.add(collection_name_, result);
254}
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:105
Stores reconstructed hit information from the HCAL.
Definition HcalHit.h:24
Implements detector ids for HCal subdetector.
Definition HcalID.h:19
Class representing a simulated particle.
Definition SimParticle.h:24
Represents a simulated tracker hit in the simulation.
Implementation of a track object.
Definition Track.h:53

References framework::Event::exists(), and ldmx::HcalID::getLayerID().

Member Data Documentation

◆ bdt_cut_val_

double hcal::VisiblesVetoProcessor::bdt_cut_val_ {0}
private

Definition at line 54 of file VisiblesVetoProcessor.h.

54{0};

◆ bdt_features_

std::vector<float> hcal::VisiblesVetoProcessor::bdt_features_
private

Definition at line 58 of file VisiblesVetoProcessor.h.

◆ beam_energy_mev_

double hcal::VisiblesVetoProcessor::beam_energy_mev_ {0}
private

Definition at line 56 of file VisiblesVetoProcessor.h.

56{0};

◆ collection_name_

std::string hcal::VisiblesVetoProcessor::collection_name_ {"VisiblesVeto"}
private

Definition at line 71 of file VisiblesVetoProcessor.h.

71{"VisiblesVeto"};

◆ feature_list_name_

std::string hcal::VisiblesVetoProcessor::feature_list_name_
private

Definition at line 59 of file VisiblesVetoProcessor.h.

◆ iso_energy_

double hcal::VisiblesVetoProcessor::iso_energy_ {0}
private

Definition at line 49 of file VisiblesVetoProcessor.h.

49{0};

◆ iso_hits_

int hcal::VisiblesVetoProcessor::iso_hits_ {0}
private

Definition at line 48 of file VisiblesVetoProcessor.h.

48{0};

◆ n_layers_hit_

int hcal::VisiblesVetoProcessor::n_layers_hit_ {0}
private

Definition at line 41 of file VisiblesVetoProcessor.h.

41{0};

◆ n_readout_hits_

int hcal::VisiblesVetoProcessor::n_readout_hits_ {0}
private

Definition at line 50 of file VisiblesVetoProcessor.h.

50{0};

◆ r_mean_

double hcal::VisiblesVetoProcessor::r_mean_ {0}
private

Definition at line 47 of file VisiblesVetoProcessor.h.

47{0};

◆ r_mean_from_photon_track_

double hcal::VisiblesVetoProcessor::r_mean_from_photon_track_ {0}
private

Definition at line 52 of file VisiblesVetoProcessor.h.

52{0};

◆ rec_coll_name_

std::string hcal::VisiblesVetoProcessor::rec_coll_name_
private

Definition at line 63 of file VisiblesVetoProcessor.h.

◆ rec_pass_name_

std::string hcal::VisiblesVetoProcessor::rec_pass_name_
private

Definition at line 62 of file VisiblesVetoProcessor.h.

◆ recoil_from_tracking_

bool hcal::VisiblesVetoProcessor::recoil_from_tracking_
private

Definition at line 64 of file VisiblesVetoProcessor.h.

◆ rt_

std::unique_ptr<ldmx::ort::ONNXRuntime> hcal::VisiblesVetoProcessor::rt_
private

Definition at line 73 of file VisiblesVetoProcessor.h.

◆ sim_particles_pass_name_

std::string hcal::VisiblesVetoProcessor::sim_particles_pass_name_
private

Definition at line 69 of file VisiblesVetoProcessor.h.

◆ sp_collection_

std::string hcal::VisiblesVetoProcessor::sp_collection_
private

Definition at line 67 of file VisiblesVetoProcessor.h.

◆ sp_pass_name_

std::string hcal::VisiblesVetoProcessor::sp_pass_name_
private

Definition at line 68 of file VisiblesVetoProcessor.h.

◆ summed_det_

double hcal::VisiblesVetoProcessor::summed_det_ {0}
private

Definition at line 51 of file VisiblesVetoProcessor.h.

51{0};

◆ track_collection_

std::string hcal::VisiblesVetoProcessor::track_collection_
private

Definition at line 66 of file VisiblesVetoProcessor.h.

◆ track_pass_name_

std::string hcal::VisiblesVetoProcessor::track_pass_name_
private

Definition at line 65 of file VisiblesVetoProcessor.h.

◆ x_mean_

double hcal::VisiblesVetoProcessor::x_mean_ {0}
private

Definition at line 45 of file VisiblesVetoProcessor.h.

45{0};

◆ x_std_

double hcal::VisiblesVetoProcessor::x_std_ {0}
private

Definition at line 42 of file VisiblesVetoProcessor.h.

42{0};

◆ y_mean_

double hcal::VisiblesVetoProcessor::y_mean_ {0}
private

Definition at line 46 of file VisiblesVetoProcessor.h.

46{0};

◆ y_std_

double hcal::VisiblesVetoProcessor::y_std_ {0}
private

Definition at line 43 of file VisiblesVetoProcessor.h.

43{0};

◆ z_std_

double hcal::VisiblesVetoProcessor::z_std_ {0}
private

Definition at line 44 of file VisiblesVetoProcessor.h.

44{0};

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