14 : Producer(name, process) {}
18 max_time_ = parameters.getParameter<
double>(
"max_time");
19 output_coll_name_ = parameters.getParameter<std::string>(
"output_coll_name");
20 input_hit_coll_name_ =
21 parameters.getParameter<std::string>(
"input_hit_coll_name");
22 input_hit_pass_name_ =
23 parameters.getParameter<std::string>(
"input_hit_pass_name");
29 default_max_hit_.
Clear();
30 default_max_hit_.
setPE(-9999);
35 default_max_hit_.
setEnd(-999);
42 double max_depth_ = parameters.getParameter<
double>(
"max_depth", 0.);
43 if (max_depth_ != 0.) {
46 "Earlier versions of the Hcal veto defined a max depth for "
47 "positions which is no longer implemented. Remove the "
48 "parameter (max_depth) from your configuration. See "
49 "https://github.com/LDMX-Software/Hcal/issues/61 for details");
51 back_min_PE_ = parameters.getParameter<
double>(
"back_min_pe");
53 parameters.getParameter<
bool>(
"exclude_recoil_ele",
false);
55 parameters.getParameter<std::string>(
"track_collection",
"RecoilTracks");
57 parameters.getParameter<
double>(
"dr_from_recoil_max", 100);
58 inverse_skim_ = parameters.getParameter<
bool>(
"inverse_skim");
63 const std::vector<ldmx::HcalHit> hcal_rec_hits =
65 input_hit_pass_name_);
68 float recoil_pos_x{0.0};
69 float recoil_pos_y{0.0};
70 float recoil_pos_z{-9999.0};
71 float recoil_mom_x{-9999.0};
72 float recoil_mom_y{-9999.0};
73 float recoil_mom_z{-9999.0};
75 if (exclude_recoil_ele_) {
76 std::vector<float> recoil_track_states;
78 auto recoil_tracks{
event.getCollection<
ldmx::Track>(track_collection_)};
80 ldmx::TrackStateType ts_type = ldmx::TrackStateType::AtHCAL;
81 recoil_track_states =
trackProp(recoil_tracks, ts_type,
"hcal");
82 if (!recoil_track_states.empty()) {
83 recoil_pos_x = recoil_track_states[0];
84 recoil_pos_y = recoil_track_states[1];
85 recoil_pos_z = recoil_track_states[2];
86 recoil_mom_x = recoil_track_states[3];
87 recoil_mom_y = recoil_track_states[4];
88 recoil_mom_z = recoil_track_states[5];
96 int num_total_hits{0};
97 int num_valid_hits{0};
98 int num_non_recoil_hits{0};
109 float pe = hcal_hit.getPE();
118 if ((
id.section() == ldmx::HcalID::BACK) &&
125 if (exclude_recoil_ele_) {
127 auto hit_pos_x = hcal_hit.getXPos();
128 auto hit_pos_y = hcal_hit.getYPos();
129 auto hit_pos_z = hcal_hit.getZPos();
130 auto dZ = recoil_pos_z - hit_pos_z;
132 auto drift_recoil_x = (dZ * (recoil_mom_x / recoil_mom_z)) + recoil_pos_x;
133 auto drift_recoil_y = (dZ * (recoil_mom_y / recoil_mom_z)) + recoil_pos_y;
134 auto dx = drift_recoil_x - hit_pos_x;
135 auto dy = drift_recoil_y - hit_pos_y;
136 auto dR_squared = dx * dx + dy * dy + dZ * dZ;
137 auto dR = sqrt(dR_squared);
138 ldmx_log(debug) <<
" This hit is at " << hit_pos_x <<
" / "
139 << hit_pos_y <<
" / " << hit_pos_z <<
" mm";
140 ldmx_log(debug) <<
" Ele is projected at " << drift_recoil_x <<
" / "
141 << drift_recoil_y <<
" / " << recoil_pos_z - dZ;
142 ldmx_log(debug) <<
" from " << recoil_pos_x <<
" / " << recoil_pos_y
143 <<
" / " << recoil_pos_z <<
" / "
146 ldmx_log(debug) <<
" Ele had momentum of " << recoil_mom_x <<
" / "
147 << recoil_mom_y <<
" / " << recoil_mom_z <<
" MeV";
148 ldmx_log(debug) <<
" This hit has PE = " << pe <<
" and dR from ele = "
149 <<
"is " << dR <<
" mm";
153 if (dR < dr_from_recoil_max_) {
157 num_non_recoil_hits++;
162 max_PE_hit = &hcal_hit;
166 ldmx_log(info) <<
"There are " << num_valid_hits <<
" / " << num_total_hits
167 <<
" HCal hits read out. " << num_non_recoil_hits
168 <<
" are not associated with the recoil ele. Total PE of "
172 ldmx_log(info) <<
"HCAL veto passed? " << passes_veto;
181 if (!inverse_skim_) {
196 event.add(output_coll_name_, result);
200 ldmx::TrackStateType ts_type,
201 const std::string &ts_title) {
203 std::vector<float> new_track_states;
206 if (tracks.empty())
return new_track_states;
209 for (
auto &track : tracks) {
211 auto trk_ts = track.getTrackState(ts_type);
213 if (!trk_ts.has_value())
continue;
217 if (hcal_track_state.params.size() < 5)
continue;
219 float track_state_loc0 =
static_cast<float>(hcal_track_state.params[0]);
220 float track_state_loc1 =
static_cast<float>(hcal_track_state.params[1]);
226 double p_track_state = (-1 / hcal_track_state.params[4]) * 1000;
228 double recoil_mom_x = p_track_state * sin(hcal_track_state.params[3]) *
229 sin(hcal_track_state.params[2]);
231 double recoil_mom_y = p_track_state * cos(hcal_track_state.params[3]);
233 double recoil_mom_z = p_track_state * sin(hcal_track_state.params[3]) *
234 cos(hcal_track_state.params[2]);
237 new_track_states.push_back(track_state_loc0);
238 new_track_states.push_back(track_state_loc1);
240 new_track_states.push_back(540.0);
241 new_track_states.push_back(recoil_mom_x);
242 new_track_states.push_back(recoil_mom_y);
243 new_track_states.push_back(recoil_mom_z);
247 return new_track_states;
#define DECLARE_PRODUCER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Processor that determines if an event is vetoed by the Hcal.
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.
Class which represents the process under execution.
Class encapsulating parameters for configuring a processor.
HcalVetoProcessor(const std::string &name, framework::Process &process)
Constructor.
double total_PE_threshold_
Total PE threshold.
float max_time_
Maximum hit time that should be considered by the veto.
void configure(framework::config::Parameters ¶meters) override
Configure the processor using the given user specified parameters.
std::vector< float > trackProp(const ldmx::Tracks &tracks, ldmx::TrackStateType ts_type, const std::string &ts_title)
Return a vector of parameters for a propagated recoil track.
void produce(framework::Event &event) override
Run the processor and create a collection of results which indicate if the event passes/fails the Hca...
float back_min_PE_
The minimum number of PE in both bars needed for a hit to be considered in double ended readout mode.
Stores reconstructed hit information from the HCAL.
void setSection(int section)
Set the section for this hit.
void Clear()
Clear the data in the object.
void setEnd(int end)
Set the end (0 neg, 1 pos side).
void setToaNeg(double toaNeg)
Set toa of the negative end.
void setTimeDiff(double timeDiff)
Set time difference (uncorrected)
void setMinPE(float minpe)
Set the minimum number of photoelectrons estimated for this hit.
void setToaPos(double toaPos)
Set toa of the positive end.
void setAmplitudeNeg(double amplitudeNeg)
Set amplitude of the negative end.
void setStrip(int strip)
Set the strip for this hit.
void setAmplitudePos(double amplitudePos)
Set amplitude of the positive end.
void setLayer(int layer)
Set the layer for this hit.
void setPE(float pe)
Set the number of photoelectrons estimated for this hit.
Implements detector ids for HCal subdetector.
void setVetoResult(const bool &passes_veto=true)
Sets whether the Hcal veto was passed or not.
void setTotalPE(const float total_PE)
Set the total number of PE.
void setNumValidHits(const float num_valid_hits)
Set the number of valid hits.
void setMaxPEHit(const ldmx::HcalHit max_PE_hit)
Set the maximum PE hit.
Implementation of a track object.
constexpr StorageControl::Hint hint_shouldKeep
storage control hint alias for backwards compatibility
constexpr StorageControl::Hint hint_shouldDrop
storage control hint alias for backwards compatibility