LDMX Software
PFTruthProducer.cxx
2
3#include "SimCore/Event/SimParticle.h"
5
6namespace recon {
7
9 primary_coll_name_ = ps.get<std::string>("outputPrimaryCollName");
10 target_coll_name_ = ps.get<std::string>("outputTargetCollName");
11 ecal_coll_name_ = ps.get<std::string>("outputEcalCollName");
12 hcal_coll_name_ = ps.get<std::string>("outputHcalCollName");
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_passname_ = ps.get<std::string>("sim_particles_passname");
16 sim_particles_event_passname_ =
17 ps.get<std::string>("sim_particles_event_passname");
18 ecal_sp_hits_event_passname_ =
19 ps.get<std::string>("ecal_sp_hits_event_passname");
20 target_sp_hits_event_passname_ =
21 ps.get<std::string>("target_sp_hits_event_passname");
22}
23template <class T>
24void sortHits(std::vector<T> spHits) {
25 std::sort(spHits.begin(), spHits.end(),
26 [](T a, T b) { return a.getEnergy() > b.getEnergy(); });
27}
28
30 if (!event.exists("TargetScoringPlaneHits", target_sp_hits_event_passname_))
31 return;
32 if (!event.exists("EcalScoringPlaneHits", ecal_sp_hits_event_passname_))
33 return;
34 if (!event.exists("SimParticles", sim_particles_event_passname_)) return;
35 const auto targ_sp_hits = event.getCollection<ldmx::SimTrackerHit>(
36 "TargetScoringPlaneHits", target_sp_passname_);
37 const auto ecal_sp_hits = event.getCollection<ldmx::SimTrackerHit>(
38 "EcalScoringPlaneHits", ecal_sp_passname_);
39 const auto particle_map = event.getMap<int, ldmx::SimParticle>(
40 "SimParticles", sim_particles_passname_);
41
42 std::map<int, ldmx::SimParticle> primaries;
43 std::set<int> sim_i_ds;
44 std::vector<ldmx::SimTrackerHit> at_target;
45 std::vector<ldmx::SimTrackerHit> at_ecal;
46 std::vector<ldmx::SimTrackerHit> at_hcal;
47 for (const auto &pm : particle_map) {
48 const auto &p = pm.second;
49 // sim particles only ever have exactly one parent
50 auto parents = p.getParents();
51 auto parent = parents.at(0);
52 // the parent of a primary is "track 0"
53 if (parent == 0) {
54 primaries[pm.first] = p;
55 sim_i_ds.insert(pm.first);
56 }
57 }
58 for (const auto &sp_hit : targ_sp_hits) {
59 if (sim_i_ds.count(sp_hit.getTrackID()) &&
60 fabs(0.18 - sp_hit.getPosition()[2]) < 0.1 &&
61 sp_hit.getMomentum()[2] > 0) {
62 at_target.push_back(sp_hit);
63 }
64 }
65 for (const auto &sp_hit : ecal_sp_hits) {
66 if (sim_i_ds.count(sp_hit.getTrackID()) &&
67 fabs(240 - sp_hit.getPosition()[2]) < 0.1 &&
68 sp_hit.getMomentum()[2] > 0) {
69 at_ecal.push_back(sp_hit);
70 }
71 if (sim_i_ds.count(sp_hit.getTrackID()) &&
72 fabs(840 - sp_hit.getPosition()[2]) < 0.1 &&
73 sp_hit.getMomentum()[2] > 0) {
74 at_hcal.push_back(sp_hit);
75 }
76 }
77 // sortHits(primaries); // use map instead
78 sortHits(at_target);
79 sortHits(at_ecal);
80 sortHits(at_hcal);
81 event.add(primary_coll_name_, primaries);
82 event.add(target_coll_name_, at_target);
83 event.add(ecal_coll_name_, at_ecal);
84 event.add(hcal_coll_name_, at_hcal);
85}
86} // namespace recon
87
#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.