LDMX Software
TruthHitProducer.cxx
1
2#include "TrigScint/TruthHitProducer.h"
3
4namespace trigscint {
5
6TruthHitProducer::TruthHitProducer(const std::string &name,
7 framework::Process &process)
8 : Producer(name, process) {}
9
11 input_collection_ = parameters.getParameter<std::string>("input_collection");
12 input_pass_name_ = parameters.getParameter<std::string>("input_pass_name");
14 parameters.getParameter<std::string>("output_collection");
16 parameters.getParameter<std::string>("sim_particles_pass_name");
17
18 ldmx_log(info) << "In TruthHitProducer: configure done!";
19 ldmx_log(info) << "Got parameters: " << "\nInput collection: "
21 << "\nInput pass name: " << input_pass_name_
22 << "\nOutput collection: " << output_collection_;
23}
24
26 // Check if the collection exists. If not, don't bother processing the event.
28 ldmx_log(error) << "No input collection called " << input_collection_ << "_"
29 << input_pass_name_ << " found; skipping!";
30 return;
31 }
32 if (!event.exists("SimParticles", sim_particles_pass_name_)) {
33 ldmx_log(error) << "No input SimParticle collection with pass "
34 << sim_particles_pass_name_ << " found; skipping!";
35 return;
36 }
37
38 // looper over sim hits and aggregate energy depositions for each detID
39 const auto sim_hits{event.getCollection<ldmx::SimCalorimeterHit>(
41 auto particle_map{event.getMap<int, ldmx::SimParticle>(
42 "SimParticles", sim_particles_pass_name_)};
43
44 std::vector<ldmx::SimCalorimeterHit> truth_beam_electrons;
45
46 // TODO: Convert this to using a for_each and lambda
47 for (const auto &sim_hit : sim_hits) {
48 bool keep{false};
49 // check if hit is from beam electron and, if so, add to output collection
50 for (int i = 0; i < sim_hit.getNumberOfContribs(); i++) {
51 auto contrib = sim_hit.getContrib(i);
52 ldmx_log(trace) << "contrib " << i << " track_id: " << contrib.track_id_
53 << " pdgID: " << contrib.pdg_code_
54 << " edep: " << contrib.edep_;
55 ldmx_log(trace) << "\t particle id: "
56 << particle_map[contrib.track_id_].getPdgID()
57 << " particle status: "
58 << particle_map[contrib.track_id_].getGenStatus();
59
60 // if the trackID is in the map
61 if (particle_map.find(contrib.track_id_) != particle_map.end()) {
62 // beam electron (PDGID = 11, genStatus == 1)
63 if (particle_map[contrib.track_id_].getPdgID() == 11 &&
64 particle_map[contrib.track_id_].getGenStatus() == 1) {
65 keep = true;
66 }
67 }
68 if (keep) truth_beam_electrons.push_back(sim_hit);
69 } // over simhit contribs
70 } // over simhits
71 event.add(output_collection_, truth_beam_electrons);
72}
73} // namespace trigscint
74
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
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 which represents the process under execution.
Definition Process.h:37
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
Stores simulated calorimeter hit information.
Class representing a simulated particle.
Definition SimParticle.h:23
Producer making a collection based on some truth info cuts.
TruthHitProducer(const std::string &name, framework::Process &process)
Constructor.
std::string input_collection_
Name of the input collection containing the sim hits.
void produce(framework::Event &event) override
Process the event and put new data products into it.
void configure(framework::config::Parameters &parameters) override
Configure the processor using the given user specified parameters.
std::string sim_particles_pass_name_
Name of the pass that the input simparticles collection is on.
std::string input_pass_name_
Name of the pass that the input collection is on (empty string means take any pass)
std::string output_collection_
Name of the output collection that will be used to store the selected sim hits.