12 input_ecal_coll_name_ = ps.
get<std::string>(
"input_ecal_coll_name");
13 input_hcal_coll_name_ = ps.
get<std::string>(
"input_hcal_coll_name");
14 input_track_coll_name_ = ps.
get<std::string>(
"input_track_coll_name");
15 output_coll_name_ = ps.
get<std::string>(
"output_coll_name");
16 input_ecal_passname_ = ps.
get<std::string>(
"input_ecal_passname");
17 input_hcal_passname_ = ps.
get<std::string>(
"input_hcal_passname");
18 input_tracks_passname_ = ps.
get<std::string>(
"input_tracks_passname");
21 single_particle_ = ps.
get<
bool>(
"single_particle");
22 use_existing_ecal_clusters_ = ps.
get<
bool>(
"use_existing_ecal_clusters");
25 std::vector<float> em1{250.0, 750.0, 1250.0, 1750.0, 2250.0, 2750.0,
26 3250.0, 3750.0, 4250.0, 4750.0, 5250.0, 5750.};
27 std::vector<float> em2{1.175, 1.02, 0.99, 0.985, 0.975, 0.975,
28 0.96, 0.94, 0.87, 0.8, 0.73, 0.665};
29 std::vector<float> h1{25.0, 75.0, 125.0, 175.0, 225.0,
30 275.0, 325.0, 375.0, 425.0};
31 std::vector<float> h2{8.44, 7.38, 7.76, 8.535, 9.47,
32 10.45, 10.47, 9.71, 8.87};
33 e_corr_ =
new TGraph(em1.size(), em1.data(), em2.data());
34 h_corr_ =
new TGraph(h1.size(), h1.data(), h2.data());
136 if (!event.
exists(input_track_coll_name_, input_tracks_passname_)) {
137 ldmx_log(error) <<
"Unable to find (one) collection named "
138 << input_track_coll_name_ <<
"_" << input_tracks_passname_;
141 if (!event.
exists(input_ecal_coll_name_, input_ecal_passname_)) {
142 ldmx_log(error) <<
"Unable to find (one) collection named "
143 << input_ecal_coll_name_ <<
"_" << input_ecal_passname_;
146 if (!event.
exists(input_hcal_coll_name_, input_hcal_passname_)) {
147 ldmx_log(error) <<
"Unable to find (one) collection named "
148 << input_hcal_coll_name_ <<
"_" << input_hcal_passname_;
153 input_hcal_coll_name_, input_hcal_passname_);
155 input_track_coll_name_, input_tracks_passname_);
157 const auto ecal_clusters =
158 use_existing_ecal_clusters_
159 ? getEcalClusters(event, input_ecal_coll_name_, input_ecal_passname_)
161 input_ecal_passname_);
163 std::vector<ldmx::PFCandidate> pf_cands;
165 if (!single_particle_) {
179 std::map<int, std::vector<int> > tk_calo_map;
180 std::map<int, std::vector<int> > calo_tk_map;
181 std::map<std::pair<int, int>,
float> tk_em_dist;
183 for (
int i = 0; i < tracks.size(); i++) {
184 const auto& tk = tracks[i];
187 const float p = sqrt(pow(pxyz[0], 2) + pow(pxyz[1], 2) + pow(pxyz[2], 2));
189 for (
int j = 0; j < ecal_clusters.size(); j++) {
190 const auto& ecal = ecal_clusters[j];
192 const float ecal_clus_z = ecal.getCentroidZ();
193 const float tk_x_at_clus =
195 pxyz[0] / pxyz[2] * (ecal_clus_z - xyz[2]);
196 const float tk_y_at_clus =
197 xyz[1] + pxyz[1] / pxyz[2] * (ecal_clus_z - xyz[2]);
198 float dist = hypot((tk_x_at_clus - ecal.getCentroidX()) /
199 std::max(1.0, ecal.getRMSX()),
200 (tk_y_at_clus - ecal.getCentroidY()) /
201 std::max(1.0, ecal.getRMSY()));
202 tk_em_dist[{i, j}] = dist;
204 (dist < 2) && (ecal.getEnergy() > 0.3 * p &&
205 ecal.getEnergy() < 2 * p);
208 if (tk_calo_map.count(i))
209 tk_calo_map[i].push_back(j);
211 tk_calo_map[i] = {j};
212 if (calo_tk_map.count(j))
213 calo_tk_map[j].push_back(i);
215 calo_tk_map[j] = {i};
221 std::map<int, std::vector<int> > em_had_calo_map;
222 std::map<std::pair<int, int>,
float> em_had_dist;
223 for (
int i = 0; i < ecal_clusters.size(); i++) {
224 const auto& ecal = ecal_clusters[i];
225 for (
int j = 0; j < hcal_clusters.size(); j++) {
226 const auto& hcal = hcal_clusters[j];
228 const float x_at_h_clus =
229 ecal.getCentroidX() +
230 ecal.getDXDZ() * (hcal.getCentroidZ() -
231 ecal.getCentroidZ());
232 const float y_at_h_clus =
233 ecal.getCentroidY() +
234 ecal.getDYDZ() * (hcal.getCentroidZ() - ecal.getCentroidZ());
236 pow(x_at_h_clus - hcal.getCentroidX(), 2) /
237 std::max(1.0, pow(hcal.getRMSX(), 2) + pow(ecal.getRMSX(), 2)) +
238 pow(y_at_h_clus - hcal.getCentroidY(), 2) /
239 std::max(1.0, pow(hcal.getRMSY(), 2) + pow(ecal.getRMSY(), 2)));
240 em_had_dist[{i, j}] = dist;
241 bool is_match = (dist < 5);
243 if (em_had_calo_map.count(i))
244 em_had_calo_map[i].push_back(j);
246 em_had_calo_map[i] = {j};
253 std::map<int, std::vector<int> > tk_had_calo_map;
270 std::vector<bool> tk_is_em_linked(tracks.size(),
false);
271 std::vector<bool> em_is_tk_linked(ecal_clusters.size(),
false);
272 std::map<int, int> tk_em_pairs{};
273 for (
int i = 0; i < tracks.size(); i++) {
274 if (tk_calo_map.count(i)) {
276 for (
int em_idx : tk_calo_map[i]) {
277 if (!em_is_tk_linked[em_idx]) {
278 em_is_tk_linked[em_idx] =
true;
279 tk_is_em_linked[i] =
true;
280 tk_em_pairs[i] = em_idx;
288 std::vector<bool> em_is_had_linked(ecal_clusters.size(),
false);
289 std::vector<bool> had_is_em_linked(hcal_clusters.size(),
false);
290 std::map<int, int> em_had_pairs{};
291 for (
int i = 0; i < ecal_clusters.size(); i++) {
292 if (em_had_calo_map.count(i)) {
294 for (
int had_idx : em_had_calo_map[i]) {
295 if (!had_is_em_linked[had_idx]) {
296 had_is_em_linked[had_idx] =
true;
297 em_is_had_linked[i] =
true;
298 em_had_pairs[i] = had_idx;
315 for (
int i = 0; i < tracks.size(); i++) {
317 fillCandTrack(cand, tracks[i]);
319 cand.setTrackIndex(i);
320 if (!tk_is_em_linked[i]) {
323 fillCandEMCalo(cand, ecal_clusters[tk_em_pairs[i]]);
324 cand.setEcalIndex(tk_em_pairs[i]);
325 if (em_is_had_linked[tk_em_pairs[i]]) {
327 fillCandHadCalo(cand, hcal_clusters[em_had_pairs[tk_em_pairs[i]]]);
331 pf_cands.push_back(cand);
336 for (
int i = 0; i < ecal_clusters.size(); i++) {
338 if (em_is_tk_linked[i])
continue;
340 fillCandEMCalo(cand, ecal_clusters[i]);
341 cand.setEcalIndex(i);
342 if (em_is_had_linked[tk_em_pairs[i]]) {
343 fillCandHadCalo(cand, hcal_clusters[em_had_pairs[i]]);
348 pf_cands.push_back(cand);
350 std::vector<ldmx::PFCandidate> had_only;
351 for (
int i = 0; i < hcal_clusters.size(); i++) {
352 if (had_is_em_linked[i])
continue;
354 fillCandHadCalo(cand, hcal_clusters[i]);
355 cand.setHcalIndex(i);
357 pf_cands.push_back(cand);
435 fillCandTrack(pf, tracks[0]);
438 if (ecal_clusters.size()) {
439 fillCandEMCalo(pf, ecal_clusters[0]);
442 if (hcal_clusters.size()) {
443 fillCandHadCalo(pf, hcal_clusters[0]);
447 pf.setEnergy(pf.getEcalEnergy() + pf.getHcalEnergy());
448 pf_cands.push_back(pf);
451 event.add(output_coll_name_, pf_cands);
virtual void onProcessEnd()
Callback for the EventProcessor to take any necessary action when the processing of events finishes,...
virtual void configure(framework::config::Parameters &ps)
Callback for the EventProcessor to configure itself from the given set of parameters.