9 input_ecal_coll_name_ = ps.
get<std::string>(
"inputEcalCollName");
10 input_hcal_coll_name_ = ps.
get<std::string>(
"inputHcalCollName");
11 input_track_coll_name_ = ps.
get<std::string>(
"inputTrackCollName");
12 output_coll_name_ = ps.
get<std::string>(
"outputCollName");
13 input_ecal_passname_ = ps.
get<std::string>(
"input_ecal_passname");
14 input_hcal_passname_ = ps.
get<std::string>(
"input_hcal_passname");
15 input_tracks_passname_ = ps.
get<std::string>(
"input_tracks_passname");
18 single_particle_ = ps.
get<
bool>(
"singleParticle");
19 use_existing_ecal_clusters_ = ps.
get<
bool>(
"use_existing_ecal_clusters");
22 std::vector<float> em1{250.0, 750.0, 1250.0, 1750.0, 2250.0, 2750.0,
23 3250.0, 3750.0, 4250.0, 4750.0, 5250.0, 5750.};
24 std::vector<float> em2{1.175, 1.02, 0.99, 0.985, 0.975, 0.975,
25 0.96, 0.94, 0.87, 0.8, 0.73, 0.665};
26 std::vector<float> h1{25.0, 75.0, 125.0, 175.0, 225.0,
27 275.0, 325.0, 375.0, 425.0};
28 std::vector<float> h2{8.44, 7.38, 7.76, 8.535, 9.47,
29 10.45, 10.47, 9.71, 8.87};
30 e_corr_ =
new TGraph(em1.size(), em1.data(), em2.data());
31 h_corr_ =
new TGraph(h1.size(), h1.data(), h2.data());
133 if (!event.
exists(input_track_coll_name_, input_tracks_passname_)) {
134 ldmx_log(error) <<
"Unable to find (one) collection named "
135 << input_track_coll_name_ <<
"_" << input_tracks_passname_;
138 if (!event.
exists(input_ecal_coll_name_, input_ecal_passname_)) {
139 ldmx_log(error) <<
"Unable to find (one) collection named "
140 << input_ecal_coll_name_ <<
"_" << input_ecal_passname_;
143 if (!event.
exists(input_hcal_coll_name_, input_hcal_passname_)) {
144 ldmx_log(error) <<
"Unable to find (one) collection named "
145 << input_hcal_coll_name_ <<
"_" << input_hcal_passname_;
150 input_hcal_coll_name_, input_hcal_passname_);
152 input_track_coll_name_, input_tracks_passname_);
154 const auto ecal_clusters =
155 use_existing_ecal_clusters_
156 ? getEcalClusters(event, input_ecal_coll_name_, input_ecal_passname_)
158 input_ecal_passname_);
160 std::vector<ldmx::PFCandidate> pf_cands;
162 if (!single_particle_) {
176 std::map<int, std::vector<int> > tk_calo_map;
177 std::map<int, std::vector<int> > calo_tk_map;
178 std::map<std::pair<int, int>,
float> tk_em_dist;
180 for (
int i = 0; i < tracks.size(); i++) {
181 const auto& tk = tracks[i];
184 const float p = sqrt(pow(pxyz[0], 2) + pow(pxyz[1], 2) + pow(pxyz[2], 2));
186 for (
int j = 0; j < ecal_clusters.size(); j++) {
187 const auto& ecal = ecal_clusters[j];
189 const float ecal_clus_z = ecal.getCentroidZ();
190 const float tk_x_at_clus =
192 pxyz[0] / pxyz[2] * (ecal_clus_z - xyz[2]);
193 const float tk_y_at_clus =
194 xyz[1] + pxyz[1] / pxyz[2] * (ecal_clus_z - xyz[2]);
195 float dist = hypot((tk_x_at_clus - ecal.getCentroidX()) /
196 std::max(1.0, ecal.getRMSX()),
197 (tk_y_at_clus - ecal.getCentroidY()) /
198 std::max(1.0, ecal.getRMSY()));
199 tk_em_dist[{i, j}] = dist;
201 (dist < 2) && (ecal.getEnergy() > 0.3 * p &&
202 ecal.getEnergy() < 2 * p);
205 if (tk_calo_map.count(i))
206 tk_calo_map[i].push_back(j);
208 tk_calo_map[i] = {j};
209 if (calo_tk_map.count(j))
210 calo_tk_map[j].push_back(i);
212 calo_tk_map[j] = {i};
218 std::map<int, std::vector<int> > em_had_calo_map;
219 std::map<std::pair<int, int>,
float> em_had_dist;
220 for (
int i = 0; i < ecal_clusters.size(); i++) {
221 const auto& ecal = ecal_clusters[i];
222 for (
int j = 0; j < hcal_clusters.size(); j++) {
223 const auto& hcal = hcal_clusters[j];
225 const float x_at_h_clus =
226 ecal.getCentroidX() +
227 ecal.getDXDZ() * (hcal.getCentroidZ() -
228 ecal.getCentroidZ());
229 const float y_at_h_clus =
230 ecal.getCentroidY() +
231 ecal.getDYDZ() * (hcal.getCentroidZ() - ecal.getCentroidZ());
233 pow(x_at_h_clus - hcal.getCentroidX(), 2) /
234 std::max(1.0, pow(hcal.getRMSX(), 2) + pow(ecal.getRMSX(), 2)) +
235 pow(y_at_h_clus - hcal.getCentroidY(), 2) /
236 std::max(1.0, pow(hcal.getRMSY(), 2) + pow(ecal.getRMSY(), 2)));
237 em_had_dist[{i, j}] = dist;
238 bool is_match = (dist < 5);
240 if (em_had_calo_map.count(i))
241 em_had_calo_map[i].push_back(j);
243 em_had_calo_map[i] = {j};
250 std::map<int, std::vector<int> > tk_had_calo_map;
267 std::vector<bool> tk_is_em_linked(tracks.size(),
false);
268 std::vector<bool> em_is_tk_linked(ecal_clusters.size(),
false);
269 std::map<int, int> tk_em_pairs{};
270 for (
int i = 0; i < tracks.size(); i++) {
271 if (tk_calo_map.count(i)) {
273 for (
int em_idx : tk_calo_map[i]) {
274 if (!em_is_tk_linked[em_idx]) {
275 em_is_tk_linked[em_idx] =
true;
276 tk_is_em_linked[i] =
true;
277 tk_em_pairs[i] = em_idx;
285 std::vector<bool> em_is_had_linked(ecal_clusters.size(),
false);
286 std::vector<bool> had_is_em_linked(hcal_clusters.size(),
false);
287 std::map<int, int> em_had_pairs{};
288 for (
int i = 0; i < ecal_clusters.size(); i++) {
289 if (em_had_calo_map.count(i)) {
291 for (
int had_idx : em_had_calo_map[i]) {
292 if (!had_is_em_linked[had_idx]) {
293 had_is_em_linked[had_idx] =
true;
294 em_is_had_linked[i] =
true;
295 em_had_pairs[i] = had_idx;
312 for (
int i = 0; i < tracks.size(); i++) {
314 fillCandTrack(cand, tracks[i]);
316 if (!tk_is_em_linked[i]) {
319 fillCandEMCalo(cand, ecal_clusters[tk_em_pairs[i]]);
320 if (em_is_had_linked[tk_em_pairs[i]]) {
322 fillCandHadCalo(cand, hcal_clusters[em_had_pairs[tk_em_pairs[i]]]);
326 pf_cands.push_back(cand);
331 for (
int i = 0; i < ecal_clusters.size(); i++) {
333 if (em_is_tk_linked[i])
continue;
336 fillCandEMCalo(cand, ecal_clusters[i]);
337 if (em_is_had_linked[tk_em_pairs[i]]) {
338 fillCandHadCalo(cand, hcal_clusters[em_had_pairs[i]]);
343 pf_cands.push_back(cand);
345 std::vector<ldmx::PFCandidate> had_only;
346 for (
int i = 0; i < hcal_clusters.size(); i++) {
347 if (had_is_em_linked[i])
continue;
349 fillCandHadCalo(cand, hcal_clusters[i]);
351 pf_cands.push_back(cand);
429 fillCandTrack(pf, tracks[0]);
432 if (ecal_clusters.size()) {
433 fillCandEMCalo(pf, ecal_clusters[0]);
436 if (hcal_clusters.size()) {
437 fillCandHadCalo(pf, hcal_clusters[0]);
441 pf.setEnergy(pf.getEcalEnergy() + pf.getHcalEnergy());
442 pf_cands.push_back(pf);
445 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.