LDMX Software
RecoilFiducialityProcessor.cxx
Go to the documentation of this file.
1
8
11#include "SimCore/Event/SimParticle.h"
13#include "Tools/AnalysisUtils.h"
14
15namespace recon {
16
19 min_p_mag_ = parameters.get<double>("min_p_mag");
20 min_tracker_hits_ = parameters.get<int>("min_tracker_hits");
21 input_pass_name_ = parameters.get<std::string>("input_pass_name");
22 ecal_collection_ = parameters.get<std::string>("ecal_collection");
23 hcal_collection_ = parameters.get<std::string>("hcal_collection");
24 recoil_collection_ = parameters.get<std::string>("recoil_collection");
25 output_collection_ = parameters.get<std::string>("output_collection");
26 inverse_skim_ = parameters.get<bool>("inverse_skim");
27}
28
30 // Get the collection of simulated particles from the event
31 auto particle_map{
32 event.getMap<int, ldmx::SimParticle>("SimParticles", input_pass_name_)};
33
34 // Search for the recoil electron
35 auto [recoil_track_id, recoil_electron] = analysis::getRecoil(particle_map);
36
37 // Get the collection of simulated Ecal hits_ from the event.
38 const std::vector<ldmx::SimCalorimeterHit> ecal_sim_hits =
39 event.getCollection<ldmx::SimCalorimeterHit>(ecal_collection_,
41
42 // Get the collection of simulated Ecal hits_ from the event.
43 const std::vector<ldmx::SimCalorimeterHit> hcal_sim_hits =
44 event.getCollection<ldmx::SimCalorimeterHit>(hcal_collection_,
46
47 // Get the collection of simulated tracker hits_ from the event.
48 const std::vector<ldmx::SimTrackerHit> recoil_sim_hits =
49 event.getCollection<ldmx::SimTrackerHit>(recoil_collection_,
51
52 // Loop through the Ecal hits_ and check if the recoil electron is
53 // associated with any of them.
54 bool has_ecal_hit = false;
55 int ecal_hit_id = -1;
56 for (const ldmx::SimCalorimeterHit& sim_hit : ecal_sim_hits) {
57 for (int i_contrib = 0; i_contrib < sim_hit.getNumberOfContribs();
58 ++i_contrib) {
59 ldmx::SimCalorimeterHit::Contrib contrib = sim_hit.getContrib(i_contrib);
60
61 if (contrib.track_id_ == recoil_track_id) {
62 has_ecal_hit = true;
63 ecal_hit_id = sim_hit.getID();
64 }
65 }
66 }
67
68 // Loop through the Hcal hits_ and check if the recoil electron is
69 // associated with any of them.
70 bool has_hcal_hit = false;
71 int hcal_hit_id = -1;
72 for (const ldmx::SimCalorimeterHit& sim_hit : hcal_sim_hits) {
73 for (int i_contrib = 0; i_contrib < sim_hit.getNumberOfContribs();
74 ++i_contrib) {
75 ldmx::SimCalorimeterHit::Contrib contrib = sim_hit.getContrib(i_contrib);
76
77 if (contrib.track_id_ == recoil_track_id) {
78 has_hcal_hit = true;
79 hcal_hit_id = sim_hit.getID();
80 }
81 }
82 }
83
84 // Loop through the recoil tracker hits_ and count how many
85 // the recoil electron is associated with
86 std::set<int> layers_hit;
87 for (const ldmx::SimTrackerHit& sim_hit : recoil_sim_hits) {
88 if (sim_hit.getTrackID() == recoil_track_id) {
89 // int sensorID = tracking::sim::utils::getSensorID(sim_hit);
90 if ((sim_hit.getTime() < 0.8) && (sim_hit.getMomentum()[2] > 0)) {
91 layers_hit.insert(sim_hit.getLayerID());
92 }
93 }
94 }
95 bool has_min_tracker_hits = false;
96 if (layers_hit.size() >= min_tracker_hits_) {
97 has_min_tracker_hits = true;
98 }
99
100 // Checking if the recoil electron energy is > min energy
101 bool has_min_energy = false;
102 if (recoil_electron->getEnergy() >= min_p_mag_) {
103 has_min_energy = true;
104 }
105
106 // Configure outputs
107 bool is_fiducial = has_min_energy && has_min_tracker_hits && has_ecal_hit;
108
109 int mask_tracker_e = has_min_energy << 0;
110 int mask_tracker_hits = has_min_tracker_hits << 1;
111 int mask_ecal = has_ecal_hit << 2;
112 int mask_hcal = has_hcal_hit << 3;
113 int fiducial_flag =
114 mask_tracker_e | mask_tracker_hits | mask_ecal | mask_hcal;
115
117 flag.setFiducialFlag(fiducial_flag, 6);
118 flag.setAlgoVar(0, recoil_electron->getEnergy());
119 flag.setAlgoVar(1, min_p_mag_);
120 flag.setAlgoVar(2, layers_hit.size());
122 flag.setAlgoVar(4, ecal_hit_id);
123 flag.setAlgoVar(5, hcal_hit_id);
124
125 flag.setIsFiducial(is_fiducial);
126 flag.setHasMinEnergy(has_min_energy);
127 flag.setHasMinTrackerHits(has_min_tracker_hits);
128 flag.setHasEcalHit(has_ecal_hit);
129 flag.setHasHcalHit(has_hcal_hit);
130
131 event.add(output_collection_, flag);
132
133 // Tell the skimmer to keep or drop the event based on whether there
134 // were recoil electron was fiducial.
135
136 if (!inverse_skim_) {
137 if (is_fiducial) {
139 } else {
141 }
142 } else {
143 if (is_fiducial) {
145 } else {
147 }
148 }
149}
150} // namespace recon
151
Collection of utility functions useful for analysis.
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that holds truth-level fiduciality flags on the signal recoil electron.
Class that flags events with a fiducial recoil electron.
Class which stores simulated calorimeter hit information.
Class which encapsulates information from a hit in a simulated tracking detector.
void setStorageHint(framework::StorageControl::Hint hint)
Mark the current event as having the given storage control hint from this module_.
Implements an event buffer system for storing event data.
Definition Event.h:40
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:26
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:75
Holds truth-level fiduciality flags on the signal recoil electron.
void setHasHcalHit(bool has_hcal_hit)
Set hcal hit flag.
void setAlgoVar(int element, double value)
Set an algorithm variable.
void setHasMinTrackerHits(bool has_min_tracker_hits)
Set tracker hit flag.
void setIsFiducial(bool is_fiducial)
Set fiduciality flag.
void setFiducialFlag(int fiducial_flag, int nvar)
Set fiduciality bit mask.
void setHasEcalHit(bool has_ecal_hit)
Set ecal hit flag.
void setHasMinEnergy(bool has_min_energy)
Set recoil min.
Stores simulated calorimeter hit information.
Class representing a simulated particle.
Definition SimParticle.h:25
Represents a simulated tracker hit in the simulation.
Flags events with a fiducial recoil electron, based on truth information.
bool inverse_skim_
Inverse option for skimming.
std::string ecal_collection_
The name of the ecal collection.
std::string hcal_collection_
The name of the hcal collection.
std::string output_collection_
The name of the output collection.
std::string recoil_collection_
The name of the recoil tracker collection.
int min_tracker_hits_
Minimum number of recoil electron hits in the recoil tracker.
void configure(framework::config::Parameters &parameters) override
Configure the processor using the given user specified parameters.
double min_p_mag_
Minimum recoil electron momentum at production.
void produce(framework::Event &event) override
Create a FiducialFlag object to contain info about whether the recoil electron satisfies certain fidu...
std::string input_pass_name_
The pass name of the input collections.
constexpr StorageControl::Hint HINT_SHOULD_DROP
storage control hint alias for backwards compatibility
constexpr StorageControl::Hint HINT_SHOULD_KEEP
storage control hint alias for backwards compatibility
Information about a contribution to the hit in the associated cell.
int track_id_
track ID of this contributor