Process the event and make histograms or summaries.
58 {
59 std::vector<float> bdt_features;
60
61 double decay_z;
62
64 "SimParticles", sim_particles_pass_name_)};
65
66 for (auto const &it : particle_map) {
67 std::vector<int> parents = it.second.getParents();
68 for (int track_id : parents) {
69 if (track_id == 0 && it.second.getPdgID() == -11) {
70 decay_z = it.second.getVertex()[2];
71 }
72 }
73 }
74
76
77
78
79
80
81 std::vector<double> gamma_p(3);
82 double gamma_energy = 90000.;
83 std::vector<double> gamma_x0(3);
84
85 std::vector<double> recoil_p(3);
86 bool found_recoil_e = false;
87
88 if (recoil_from_tracking_) {
89 const auto &recoil_tracks{
90 event.getCollection<
ldmx::Track>(track_collection_, track_pass_name_)};
91 for (auto &track : recoil_tracks) {
92
93 if (track.q() == 1 && track.getNhits() == 5) {
94 gamma_x0 = track.getPosition();
95 gamma_p[0] = -1. * track.getMomentum()[0];
96 gamma_p[1] = -1. * track.getMomentum()[1];
97 gamma_p[2] = 8000. - track.getMomentum()[2];
98 }
99 }
100 } else {
101 if (event.
exists(sp_collection_, sp_pass_name_)) {
103 sp_collection_, sp_pass_name_);
104 bool found_rec = false;
105 for (auto const &it : particle_map) {
106 for (auto const &sphit : target_sp_hits) {
107 if (sphit.getPosition()[2] > 0) {
108 if (it.first == sphit.getTrackID()) {
109 if (it.second.getPdgID() == 622) {
110 std::vector<float> x0_float = sphit.getPosition();
111 std::vector<double> x0_double(x0_float.begin(), x0_float.end());
112 gamma_x0 = x0_double;
113 gamma_p = sphit.getMomentum();
114 gamma_energy = sphit.getEnergy();
115 found_rec = true;
116 }
117 if (it.second.getPdgID() == 11 &&
118 inList(it.second.getParents(), 0)) {
119 if (!found_rec) {
120 std::vector<float> x0_float = sphit.getPosition();
121 std::vector<double> x0_double(x0_float.begin(),
122 x0_float.end());
123 gamma_x0 = x0_double;
124 gamma_p[0] = -1. * sphit.getMomentum()[0];
125 gamma_p[1] = -1. * sphit.getMomentum()[1];
126 gamma_p[2] = beam_energy_mev_ - sphit.getMomentum()[2];
127 gamma_energy = beam_energy_mev_ - sphit.getEnergy();
128 found_rec = true;
129 }
130 recoil_p = sphit.getMomentum();
131 found_recoil_e = true;
132 }
133 }
134 }
135 }
136 }
137 }
138 }
141 std::acos(gamma_p[2] / std::sqrt(gamma_p[0] * gamma_p[0] +
142 gamma_p[1] * gamma_p[1] +
143 gamma_p[2] * gamma_p[2])));
144
145 double p_mag = 0.;
146 if (found_recoil_e) {
147 p_mag = std::sqrt(recoil_p[0] * recoil_p[0] + recoil_p[1] * recoil_p[1] +
148 recoil_p[2] * recoil_p[2]);
149 }
150
151 if (p_mag < 50. && all_cuts_) {
152 return;
153 }
155
156
157 const auto &ecal_rec_hits =
event.getCollection<
ldmx::EcalHit>(
158 ecal_rec_collection_, ecal_rec_pass_name_);
159 const auto &hcal_rec_hits =
event.getCollection<
ldmx::HcalHit>(
160 hcal_rec_collection_, hcal_rec_pass_name_);
161
162 double trigger = 0.;
163 double ecal_energy = 0.;
164 double hcal_energy = 0.;
165 bool hcal_containment = true;
166
168 if (hit.getEnergy() > 0.) {
169 ecal_energy += hit.getEnergy();
170 if (hit.getZPos() <= 541.722) {
171 trigger += hit.getEnergy();
172 }
173 }
174 }
176 if (hit.getEnergy() > 0.) {
178 if (det_id.getSection() != 0) {
179 continue;
180 }
181 if (det_id.getLayerID() == 1 && hit.getPE() > 5) {
182 hcal_containment = false;
183 }
184 hcal_energy += 12. * hit.getEnergy();
185 }
186 }
187
188 if (trigger > 3160. && all_cuts_) {
189 return;
190 }
192
193 if (ecal_energy > 3160. && all_cuts_) {
194 return;
195 }
197
198 if (p_mag > 2400. && all_cuts_) {
199 return;
200 }
202
204 ecal_veto_collection_, ecal_veto_pass_)};
205 if (ecal_veto.getDisc() < ecal_bdt_cut_val_ && all_cuts_) {
206 return;
207 }
209
210 if (hcal_energy < 4840 && all_cuts_) {
211 return;
212 }
214
215 if (!hcal_containment && all_cuts_) {
216 return;
217 }
219
220
221 int n_layers_hit = 0;
222 double x_std = 0.;
223 double y_std = 0.;
224 double z_std = 0.;
225 double x_mean = 0.;
226 double y_mean = 0.;
227 double r_mean = 0.;
228 int iso_hits = 0;
229 double iso_energy = 0.;
230 int n_readout_hits = 0;
231 double summed_det = 0.;
232 double r_mean_from_photon_track = 0.;
233
234 double z_mean = 0.;
235 std::vector<int> layers_hit;
237 if (hit.getEnergy() > 0.) {
239 if (det_id.getSection() != 0) {
240 continue;
241 }
242 if (fabs(hit.getXPos()) > 1000 || fabs(hit.getYPos()) > 1000) {
243 continue;
244 }
245 n_readout_hits += 1;
246 double hit_x = hit.getXPos();
247 double hit_y = hit.getYPos();
248 double hit_z = hit.getZPos();
249 double hit_r = sqrt(hit_x * hit_x + hit_y * hit_y);
250
251 summed_det += hit.getEnergy();
252
253 x_mean += hit_x * hit.getEnergy();
254 y_mean += hit_y * hit.getEnergy();
255 z_mean += hit_z * hit.getEnergy();
256 r_mean += hit_r * hit.getEnergy();
257
258
259 if (!(std::find(layers_hit.begin(), layers_hit.end(),
260 det_id.getLayerID()) != layers_hit.end())) {
261 layers_hit.push_back(det_id.getLayerID());
262 }
263
264 double proj_x =
265 gamma_x0[0] + (hit_z - gamma_x0[2]) * gamma_p[0] / gamma_p[2];
266 double proj_y =
267 gamma_x0[1] + (hit_z - gamma_x0[2]) * gamma_p[1] / gamma_p[2];
268
269 r_mean_from_photon_track +=
270 hit.getEnergy() * sqrt((hit_x - proj_x) * (hit_x - proj_x) +
271 (hit_y - proj_y) * (hit_y - proj_y));
272
273
274 double closest_point = 9999.;
276 if (hit2.getEnergy() > 0.) {
278 if (fabs(hit2.getXPos()) > 1000 || fabs(hit2.getYPos()) > 1000) {
279 continue;
280 }
281 if (det_i_d2.getLayerID() == det_id.getLayerID()) {
282
283
284
285 if (hit.isOrientationX()) {
286 if (fabs(hit2.getYPos() - hit_y) > 0) {
287 if (fabs(hit2.getYPos() - hit_y) < closest_point) {
288 closest_point = abs(hit2.getYPos() - hit_y);
289 }
290 }
291 }
292 if (hit.isOrientationY()) {
293 if (fabs(hit2.getXPos() - hit_x) > 0) {
294 if (fabs(hit2.getXPos() - hit_x) < closest_point) {
295 closest_point = fabs(hit2.getXPos() - hit_x);
296 }
297 }
298 }
299 }
300 }
301 }
302 if (closest_point > 50.) {
303 iso_hits += 1;
304 iso_energy += hit.getEnergy();
305 }
306 }
307 }
308
309 n_layers_hit = layers_hit.size();
310
311 if (summed_det > 0.) {
312 x_mean /= summed_det;
313 y_mean /= summed_det;
314 z_mean /= summed_det;
315 r_mean /= summed_det;
316
317 r_mean_from_photon_track /= summed_det;
318 }
319
321 if (hit.getEnergy() > 0.) {
322 if (fabs(hit.getXPos()) > 1000 || fabs(hit.getYPos()) > 1000) {
323 continue;
324 }
326 if (det_id.getSection() == 0) {
327 x_std += hit.getEnergy() * (hit.getXPos() - x_mean) *
328 (hit.getXPos() - x_mean);
329 y_std += hit.getEnergy() * (hit.getYPos() - y_mean) *
330 (hit.getYPos() - y_mean);
331 z_std += hit.getEnergy() * (hit.getZPos() - z_mean) *
332 (hit.getZPos() - z_mean);
333 }
334 }
335 }
336
337 if (summed_det > 0.) {
338 x_std = sqrt(x_std / summed_det);
339 y_std = sqrt(y_std / summed_det);
340 z_std = sqrt(z_std / summed_det);
341 }
342
343
356
357 bdt_features.push_back(n_layers_hit);
358 bdt_features.push_back(x_std);
359 bdt_features.push_back(y_std);
360 bdt_features.push_back(z_std);
361 bdt_features.push_back(x_mean);
362 bdt_features.push_back(y_mean);
363 bdt_features.push_back(r_mean);
364 bdt_features.push_back(iso_hits);
365 bdt_features.push_back(iso_energy);
366 bdt_features.push_back(n_readout_hits);
367 bdt_features.push_back(hcal_energy);
368 bdt_features.push_back(r_mean_from_photon_track);
369
370 ldmx::ort::FloatArrays inputs({bdt_features});
371 float pred =
372 rt_->run({feature_list_name_}, inputs, {"probabilities"})[0].at(1);
373
375
376 for (int i = 0; i < 10000; i++) {
377 double disc = 0.999 + (double(i) / 10000.) * (1. - 0.999);
379 0.999 + ((double(i) + 0.5) / 10000.) * (1. - 0.999));
380 double disc_roc = 0.99 + (double(i) / 10000.) * (1. - 0.99);
381 if (pred >= disc) {
383 0.999 + ((double(i) + 0.5) / 10000.) * (1. - 0.999));
384 }
385 if (pred >= disc_roc) {
387 }
388 }
389
391
392 if (pred < bdt_cut_val_) {
393 return;
394 }
396
397 return;
398}
HistogramPool histograms_
helper object for making and filling histograms
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.
void fill(const std::string &name, const T &val)
Fill a 1D histogram.
Stores reconstructed hit information from the ECAL.
Stores reconstructed hit information from the HCAL.
Implements detector ids for HCal subdetector.
Class representing a simulated particle.
Represents a simulated tracker hit in the simulation.
Implementation of a track object.