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