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 inputCollection_ = parameters.getParameter<std::string>("input_collection");
12 inputPassName_ = parameters.getParameter<std::string>("input_pass_name");
13 outputCollection_ = parameters.getParameter<std::string>("output_collection");
14 verbose_ = parameters.getParameter<bool>("verbose");
15
16 if (verbose_) {
17 ldmx_log(info) << "In TruthHitProducer: configure done!";
18 ldmx_log(info) << "Got parameters: "
19 << "\nInput collection: " << inputCollection_
20 << "\nInput pass name: " << inputPassName_
21 << "\nOutput collection: " << outputCollection_
22 << "\nVerbose: " << verbose_;
23 }
24}
25
27 // Check if the collection exists. If not, don't bother processing the event.
28 if (!event.exists(inputCollection_)) {
29 ldmx_log(error) << "No input collection called " << inputCollection_
30 << " found; skipping!";
31 return;
32 }
33 // looper over sim hits and aggregate energy depositions for each detID
34 const auto simHits{event.getCollection<ldmx::SimCalorimeterHit>(
36 auto particleMap{event.getMap<int, ldmx::SimParticle>("SimParticles")};
37
38 std::vector<ldmx::SimCalorimeterHit> truthBeamElectrons;
39
40 // TODO: Convert this to using a for_each and lambda
41 for (const auto &simHit : simHits) {
42 bool keep{false};
43 // check if hit is from beam electron and, if so, add to output collection
44 for (int i = 0; i < simHit.getNumberOfContribs(); i++) {
45 auto contrib = simHit.getContrib(i);
46 if (verbose_) {
47 ldmx_log(debug) << "contrib " << i << " trackID: " << contrib.trackID
48 << " pdgID: " << contrib.pdgCode
49 << " edep: " << contrib.edep;
50 ldmx_log(debug) << "\t particle id: "
51 << particleMap[contrib.trackID].getPdgID()
52 << " particle status: "
53 << particleMap[contrib.trackID].getGenStatus();
54 }
55 // if the trackID is in the map
56 if (particleMap.find(contrib.trackID) != particleMap.end()) {
57 // beam electron (PDGID = 11, genStatus == 1)
58 if (particleMap[contrib.trackID].getPdgID() == 11 &&
59 particleMap[contrib.trackID].getGenStatus() == 1) {
60 keep = true;
61 }
62 }
63 if (keep) truthBeamElectrons.push_back(simHit);
64 }
65 }
66 event.add(outputCollection_, truthBeamElectrons);
67}
68} // namespace trigscint
69
70DECLARE_PRODUCER_NS(trigscint, TruthHitProducer)
#define DECLARE_PRODUCER_NS(NS, 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: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 which represents the process under execution.
Definition Process.h:36
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
Stores simulated calorimeter hit information.
Class representing a simulated particle.
Definition SimParticle.h:23
TruthHitProducer(const std::string &name, framework::Process &process)
Constructor.
std::string inputCollection_
Name of the input collection containing the sim hits.
std::string inputPassName_
Name of the pass that the input collection is on (empty string means take any pass)
std::string outputCollection_
Name of the output collection that will be used to store the selected 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.
bool verbose_
Class to set the verbosity level.