LDMX Software
PileupFinder.cxx
2
3#include <cmath>
4#include <vector>
5
6#include "Ecal/Event/EcalHit.h"
9
10namespace recon {
11
13 // I/O
14 rec_hit_coll_name_ = ps.getParameter<std::string>("rec_hit_coll_name");
15 rec_hit_pass_name_ = ps.getParameter<std::string>("rec_hit_pass_name");
16 pf_cand_coll_name_ = ps.getParameter<std::string>("pf_cand_coll_name");
17 pf_cand_pass_name_ = ps.getParameter<std::string>("pf_cand_pass_name");
18 cluster_coll_name_ = ps.getParameter<std::string>("cluster_coll_name");
19 cluster_pass_name_ = ps.getParameter<std::string>("cluster_pass_name");
20 output_rec_hit_coll_name_ =
21 ps.getParameter<std::string>("output_rec_hit_coll_name");
22 // Algorithm configuration
23 min_mom_ = ps.getParameter<double>("min_momentum");
24}
25
26// get pileup candidates from PFlow and make a cleaned-up hit collection
28 if (!event.exists(rec_hit_coll_name_, rec_hit_pass_name_)) { // ecal rechits
29 ldmx_log(error) << "Unable to find (one) collection named "
30 << rec_hit_coll_name_ << "_" << rec_hit_pass_name_;
31 return;
32 }
33 if (!event.exists(pf_cand_coll_name_, pf_cand_pass_name_)) {
34 ldmx_log(error) << "Unable to find (one) collection named "
35 << pf_cand_coll_name_ << "_" << pf_cand_pass_name_;
36 return;
37 }
38 if (!event.exists(cluster_coll_name_, cluster_pass_name_)) {
39 ldmx_log(error) << "Unable to find (one) collection named "
40 << cluster_coll_name_ << "_" << cluster_pass_name_;
41 return;
42 }
43
44 const auto& ecal_hits{event.getCollection<ldmx::EcalHit>(rec_hit_coll_name_,
45 rec_hit_pass_name_)};
46
47 const auto& pf_cands{event.getCollection<ldmx::PFCandidate>(
48 pf_cand_coll_name_, pf_cand_pass_name_)};
49
50 const auto& clusters{event.getCollection<ldmx::CaloCluster>(
51 cluster_coll_name_, cluster_pass_name_)};
52 // get PID 3 and 7 -- the ones with track and ecal matching
53 // get the high-momentum track ones from there -- pileup candidate!
54 // get the list of hits associated with pileup candidates
55 // if a rechit is not on that list, add to output collection.
56 std::vector<ldmx::EcalHit> output_hits;
57 std::vector<unsigned int> pileup_hit_i_ds;
58
59 // this needs to be a two-step procedure: loop over all clusters deemed to be
60 // pileup to find all their associated hits
61 // then loop over that list to make a collection of output hits that doesn't
62 // contain them
63 for (const auto& pf_cand : pf_cands) {
64 if (pf_cand.getPID() == 3 || pf_cand.getPID() == 7) {
65 // we have both ecal cluster and track
66 std::vector<float> mom_vec = pf_cand.getTrackPxPyPz();
67 float mom = mom_vec[0] * mom_vec[0] + mom_vec[1] * mom_vec[1] +
68 mom_vec[2] * mom_vec[2];
69 mom = sqrt(mom);
70
71 if (mom < min_mom_) continue;
72 ldmx_log(trace) << "Got pileup candidate with PID = " << pf_cand.getPID()
73 << " and momentum = " << mom << " MeV.";
74
75 // now! use the hit-candidate association to get the associated ecal hits.
76 int pf_cl_idx = pf_cand.getEcalIndex();
77 ldmx_log(trace) << "Got Ecal cluster with index " << pf_cl_idx
78 << " while cluster array length is " << clusters.size();
79 if (pf_cl_idx < 0) // was never set
80 continue;
81 auto cl = clusters[pf_cl_idx];
82 auto hit_i_ds = cl.getHitIDs();
83 // add to collection of pileup hits
84 pileup_hit_i_ds.insert(pileup_hit_i_ds.end(), hit_i_ds.begin(),
85 hit_i_ds.end());
86 } // if trk/ecal matched
87 } // over PF objects
88
89 for (auto hit : ecal_hits) {
90 auto found_index = std::find(std::begin(pileup_hit_i_ds),
91 std::end(pileup_hit_i_ds), hit.getID());
92 // When the element is not found, std::find returns the end of the range
93 if (found_index ==
94 std::end(pileup_hit_i_ds)) { // hit not part of any pileup cluster
95 output_hits.emplace_back(hit); // keep it
96 ldmx_log(trace) << "Got no-pileup hit! ";
97 }
98 }
99 event.add(output_rec_hit_coll_name_, output_hits);
100}
102 ldmx_log(debug) << "Process ends!";
103
104 return;
105}
106
107} // namespace recon
108
Class that stores calorimeter cluster information.
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that represents a reconstructed particle candidate.
Simple PFlow algorithm.
Implements an event buffer system for storing event data.
Definition Event.h:40
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:107
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
Stores cluster information from the ECal.
Definition CaloCluster.h:25
Stores reconstructed hit information from the ECAL.
Definition EcalHit.h:19
Represents a reconstructed particle.
Definition PFCandidate.h:19
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.
virtual void produce(framework::Event &event)
Process the event and put new data products into it.