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.get<std::string>("input_collection");
12 input_pass_name_ = parameters.get<std::string>("input_pass_name");
13 output_collection_ = parameters.get<std::string>("output_collection");
14 sim_particles_passname_ =
15 parameters.get<std::string>("sim_particles_passname");
16 input_collection_events_passname_ =
17 parameters.get<std::string>("input_collection_events_passname");
18
19 verbose_ = parameters.get<bool>("verbose");
20
21 if (verbose_) {
22 ldmx_log(info) << "In TruthHitProducer: configure done!";
23 ldmx_log(info) << "Got parameters: " << "\nInput collection: "
25 << "\nInput pass name: " << input_pass_name_
26 << "\nOutput collection: " << output_collection_
27 << "\nVerbose: " << verbose_;
28 }
29}
30
32 // Check if the collection exists. If not, don't bother processing the event.
33 if (!event.exists(input_collection_, input_collection_events_passname_)) {
34 ldmx_log(error) << "No input collection called " << input_collection_
35 << " found; skipping!";
36 return;
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_passname_)};
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 if (verbose_) {
53 ldmx_log(debug) << "contrib " << i << " trackID: " << contrib.track_id_
54 << " pdgID: " << contrib.pdg_code_
55 << " edep: " << contrib.edep_;
56 ldmx_log(debug) << "\t particle id: "
57 << particle_map[contrib.track_id_].getPdgID()
58 << " particle status: "
59 << particle_map[contrib.track_id_].getGenStatus();
60 }
61 // if the trackID is in the map
62 if (particle_map.find(contrib.track_id_) != particle_map.end()) {
63 // beam electron (PDGID = 11, genStatus == 1)
64 if (particle_map[contrib.track_id_].getPdgID() == 11 &&
65 particle_map[contrib.track_id_].getGenStatus() == 1) {
66 keep = true;
67 }
68 }
69 if (keep) truth_beam_electrons.push_back(sim_hit);
70 }
71 }
72 event.add(output_collection_, truth_beam_electrons);
73}
74} // namespace trigscint
75
#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:36
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
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 input_pass_name_
Name of the pass that the input collection is on (empty string means take any pass)
bool verbose_
Class to set the verbosity level.
std::string output_collection_
Name of the output collection that will be used to store the selected sim hits.