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 // the only parent of a primary is "track 0"
39 if (p.getParents().size() == 1 && p.getParents()[0] == 0) {
40 primaries[pm.first] = p;
41 simIDs.insert(pm.first);
42 }
43 }
44 for (const auto &spHit : targSpHits) {
45 if (simIDs.count(spHit.getTrackID()) &&
46 fabs(0.18 - spHit.getPosition()[2]) < 0.1 &&
47 spHit.getMomentum()[2] > 0) {
48 atTarget.push_back(spHit);
49 }
50 }
51 for (const auto &spHit : ecalSpHits) {
52 if (simIDs.count(spHit.getTrackID()) &&
53 fabs(240 - spHit.getPosition()[2]) < 0.1 &&
54 spHit.getMomentum()[2] > 0) {
55 atEcal.push_back(spHit);
56 }
57 if (simIDs.count(spHit.getTrackID()) &&
58 fabs(840 - spHit.getPosition()[2]) < 0.1 &&
59 spHit.getMomentum()[2] > 0) {
60 atHcal.push_back(spHit);
61 }
62 }
63 // sortHits(primaries); // use map instead
64 sortHits(atTarget);
65 sortHits(atEcal);
66 sortHits(atHcal);
67 event.add(primaryCollName_, primaries);
68 event.add(targetCollName_, atTarget);
69 event.add(ecalCollName_, atEcal);
70 event.add(hcalCollName_, atHcal);
71}
72} // namespace recon
73
74DECLARE_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:41
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:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
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.