LDMX Software
PFTruthProducer.cxx
2
3#include "SimCore/Event/SimParticle.h"
5
6namespace recon {
7
9 primary_coll_name_ = ps.get<std::string>("output_primary_coll_name");
10 target_coll_name_ = ps.get<std::string>("output_target_coll_name");
11 ecal_coll_name_ = ps.get<std::string>("output_ecal_coll_name");
12 hcal_coll_name_ = ps.get<std::string>("output_hcal_coll_name");
13 target_sp_passname_ = ps.get<std::string>("target_sp_passname");
14 ecal_sp_passname_ = ps.get<std::string>("ecal_sp_passname");
15 sim_particles_coll_name_ = ps.get<std::string>("sim_particles_coll_name");
16 sim_particles_passname_ = ps.get<std::string>("sim_particles_passname");
17 sim_particles_event_passname_ =
18 ps.get<std::string>("sim_particles_event_passname");
19 ecal_sp_coll_name_ = ps.get<std::string>("ecal_sp_hits_event_passname");
20 ecal_sp_hits_event_passname_ =
21 ps.get<std::string>("ecal_sp_hits_event_passname");
22 target_sp_coll_name_ = ps.get<std::string>("target_sp_coll_name");
23 target_sp_hits_event_passname_ =
24 ps.get<std::string>("target_sp_hits_event_passname");
25}
26template <class T>
27void sortHits(std::vector<T> spHits) {
28 std::sort(spHits.begin(), spHits.end(),
29 [](T a, T b) { return a.getEnergy() > b.getEnergy(); });
30}
31
33 if (!event.exists(target_sp_coll_name_, target_sp_hits_event_passname_))
34 return;
35 if (!event.exists(ecal_sp_coll_name_, ecal_sp_hits_event_passname_)) return;
36 if (!event.exists(sim_particles_coll_name_, sim_particles_event_passname_))
37 return;
38 const auto targ_sp_hits = event.getCollection<ldmx::SimTrackerHit>(
39 target_sp_coll_name_, target_sp_passname_);
40 const auto ecal_sp_hits = event.getCollection<ldmx::SimTrackerHit>(
41 ecal_sp_coll_name_, ecal_sp_passname_);
42 const auto particle_map = event.getMap<int, ldmx::SimParticle>(
43 sim_particles_coll_name_, sim_particles_passname_);
44
45 std::map<int, ldmx::SimParticle> primaries;
46 std::set<int> sim_i_ds;
47 std::vector<ldmx::SimTrackerHit> at_target;
48 std::vector<ldmx::SimTrackerHit> at_ecal;
49 std::vector<ldmx::SimTrackerHit> at_hcal;
50 for (const auto &pm : particle_map) {
51 const auto &p = pm.second;
52 // sim particles only ever have exactly one parent
53 auto parents = p.getParents();
54 auto parent = parents.at(0);
55 // the parent of a primary is "track 0"
56 if (parent == 0) {
57 primaries[pm.first] = p;
58 sim_i_ds.insert(pm.first);
59 }
60 }
61 for (const auto &sp_hit : targ_sp_hits) {
62 if (sim_i_ds.count(sp_hit.getTrackID()) &&
63 fabs(0.18 - sp_hit.getPosition()[2]) < 0.1 &&
64 sp_hit.getMomentum()[2] > 0) {
65 at_target.push_back(sp_hit);
66 }
67 }
68 for (const auto &sp_hit : ecal_sp_hits) {
69 if (sim_i_ds.count(sp_hit.getTrackID()) &&
70 fabs(240 - sp_hit.getPosition()[2]) < 0.1 &&
71 sp_hit.getMomentum()[2] > 0) {
72 at_ecal.push_back(sp_hit);
73 }
74 if (sim_i_ds.count(sp_hit.getTrackID()) &&
75 fabs(840 - sp_hit.getPosition()[2]) < 0.1 &&
76 sp_hit.getMomentum()[2] > 0) {
77 at_hcal.push_back(sp_hit);
78 }
79 }
80 // sortHits(primaries); // use map instead
81 sortHits(at_target);
82 sortHits(at_ecal);
83 sortHits(at_hcal);
84 event.add(primary_coll_name_, primaries);
85 event.add(target_coll_name_, at_target);
86 event.add(ecal_coll_name_, at_ecal);
87 event.add(hcal_coll_name_, at_hcal);
88}
89} // namespace recon
90
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Track selection skeleton for PFlow Reco.
Class which encapsulates information from a hit in a simulated tracking detector.
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
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
Class representing a simulated particle.
Definition SimParticle.h:23
Represents a simulated tracker hit in the simulation.
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.