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