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