LDMX Software
PFTruthProducer.cxx
2
3#include "SimCore/Event/SimParticle.h"
5
6namespace recon {
7
9 primaryCollName_ = ps.getParameter<std::string>("outputPrimaryCollName");
10 targetCollName_ = ps.getParameter<std::string>("outputTargetCollName");
11 ecalCollName_ = ps.getParameter<std::string>("outputEcalCollName");
12 hcalCollName_ = ps.getParameter<std::string>("outputHcalCollName");
13}
14template <class T>
15void sortHits(std::vector<T> spHits) {
16 std::sort(spHits.begin(), spHits.end(),
17 [](T a, T b) { return a.getEnergy() > b.getEnergy(); });
18}
19
21 if (!event.exists("TargetScoringPlaneHits")) return;
22 if (!event.exists("EcalScoringPlaneHits")) return;
23 if (!event.exists("SimParticles")) return;
24 const auto targSpHits =
25 event.getCollection<ldmx::SimTrackerHit>("TargetScoringPlaneHits");
26 const auto ecalSpHits =
27 event.getCollection<ldmx::SimTrackerHit>("EcalScoringPlaneHits");
28 const auto particle_map =
29 event.getMap<int, ldmx::SimParticle>("SimParticles");
30
31 std::map<int, ldmx::SimParticle> primaries;
32 std::set<int> simIDs;
33 std::vector<ldmx::SimTrackerHit> atTarget;
34 std::vector<ldmx::SimTrackerHit> atEcal;
35 std::vector<ldmx::SimTrackerHit> atHcal;
36 for (const auto &pm : particle_map) {
37 const auto &p = pm.second;
38 // sim particles only ever have exactly one parent
39 auto parents = p.getParents();
40 auto parent = parents.at(0);
41 // the parent of a primary is "track 0"
42 if (parent == 0) {
43 primaries[pm.first] = p;
44 simIDs.insert(pm.first);
45 }
46 }
47 for (const auto &spHit : targSpHits) {
48 if (simIDs.count(spHit.getTrackID()) &&
49 fabs(0.18 - spHit.getPosition()[2]) < 0.1 &&
50 spHit.getMomentum()[2] > 0) {
51 atTarget.push_back(spHit);
52 }
53 }
54 for (const auto &spHit : ecalSpHits) {
55 if (simIDs.count(spHit.getTrackID()) &&
56 fabs(240 - spHit.getPosition()[2]) < 0.1 &&
57 spHit.getMomentum()[2] > 0) {
58 atEcal.push_back(spHit);
59 }
60 if (simIDs.count(spHit.getTrackID()) &&
61 fabs(840 - spHit.getPosition()[2]) < 0.1 &&
62 spHit.getMomentum()[2] > 0) {
63 atHcal.push_back(spHit);
64 }
65 }
66 // sortHits(primaries); // use map instead
67 sortHits(atTarget);
68 sortHits(atEcal);
69 sortHits(atHcal);
70 event.add(primaryCollName_, primaries);
71 event.add(targetCollName_, atTarget);
72 event.add(ecalCollName_, atEcal);
73 event.add(hcalCollName_, atHcal);
74}
75} // namespace recon
76
77DECLARE_PRODUCER_NS(recon, PFTruthProducer);
#define DECLARE_PRODUCER_NS(NS, 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
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.