92 ldmx_log(debug) <<
"produce() starts! Event number: "
93 <<
event.getEventHeader().getEventNumber();
99 input_collection_, pass_name_)};
102 ldmx_log(debug) <<
"Got digi collection " << input_collection_ <<
"_"
103 << pass_name_ <<
" with " << digis.size() <<
" entries ";
107 bool do_duplicate =
true;
111 for (
const auto &digi : digis) {
114 ldmx_log(debug) <<
"Digi has PE count " << digi.getPE() <<
" and energy "
117 if (
do_clean_hits_ && digi.getQualityFlag() && digi.getQualityFlag() != 4) {
119 ldmx_log(debug) <<
"Skipping hit with non-zero quality flag "
120 << digi.getQualityFlag();
125 if (digi.getPE() > min_thr_) {
126 int id = digi.getBarID();
127 if (
id > max_channel_id_) {
130 ldmx_log(debug) <<
"Skipping channel with bar ID = " <<
id <<
" > "
131 << max_channel_id_ <<
" (max instrumented nb)";
138 hit_channel_map_.find((
id)) != hit_channel_map_.end()) {
140 std::map<int, int>::iterator itr = hit_channel_map_.find(idx);
141 double old_val = digis.at(itr->second).getPE();
143 ldmx_log(debug) <<
"Got duplicate digis for channel " << idx
144 <<
", with already inserted value " << old_val
145 <<
" and new " << digi.getPE();
147 if (digi.getPE() > old_val) {
148 hit_channel_map_.erase(itr->first);
151 <<
"Skipped duplicate digi with smaller value for channel "
158 if (digi.getTime() > pad_time_ + time_tolerance_)
continue;
160 hit_channel_map_.insert(std::pair<int, int>(
id, i_digi));
164 ldmx_log(debug) <<
"Mapping digi hit nb " << i_digi
165 <<
" with energy = " << digi.getEnergy()
166 <<
" MeV, nPE = " << digi.getPE() <<
" > " << min_thr_
167 <<
" to key/channel " << id;
175 std::map<int, int>::iterator itr;
178 std::vector<ldmx::TrigScintCluster> trig_scint_clusters;
181 for (itr = hit_channel_map_.begin(); itr != hit_channel_map_.end(); ++itr) {
183 if (hit_channel_map_.find(itr->first) == hit_channel_map_.end()) {
185 ldmx_log(debug) <<
"Attempting to use removed hit at channel "
186 << itr->first <<
"; skipping.";
195 bool has_used =
false;
196 for (
const auto &index : v_used_indices_) {
197 if (index == itr->first) {
199 ldmx_log(warn) <<
"Attempting to re-use hit at channel " << itr->first
205 if (has_used)
continue;
207 ldmx_log(debug) <<
"\t At hit with channel nb " << itr->first <<
".";
210 if (hit_channel_map_.size() ==
214 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
215 "removed! Unclear how we even got here; interfering "
216 "here to get out of the loop. ";
223 if (digi.
getPE() >= seed_) {
225 ldmx_log(debug) <<
"Seeding cluster with channel " << itr->first
226 <<
"; content " << digi.
getPE();
234 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
235 << itr->first <<
".";
242 std::map<int, int>::iterator itr_back =
243 hit_channel_map_.find(itr->first - 1);
245 bool has_backed =
false;
256 for (
const auto &index : v_used_indices_) {
257 if (index == itr_back->first) {
259 ldmx_log(warn) <<
"Attempting to re-use hit at channel "
260 << itr_back->first <<
"; skipping.";
269 addHit(itr_back->first, digi);
273 ldmx_log(debug) <<
"Added -1 channel " << itr_back->first
274 <<
" to cluster; content " << digi.
getPE();
275 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
276 << itr->first <<
".";
291 if (v_added_indices_.size() < max_width_) {
294 std::map<int, int>::iterator itr_neighb =
295 hit_channel_map_.find(itr->first + 1);
302 if (hit_channel_map_.find(itr_neighb->first + 1) !=
303 hit_channel_map_.end()) {
310 addHit(itr_neighb->first, digi);
314 <<
"No -1 hit. Added +1 channel " << itr_neighb->first
315 <<
" to cluster; content " << digi.
getPE();
316 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
317 << itr->first <<
".";
320 if (v_added_indices_.size() < max_width_) {
321 if (hit_channel_map_.find(itr_neighb->first + 2) ==
325 itr_neighb = hit_channel_map_.find(itr->first + 2);
327 addHit(itr_neighb->first, digi);
330 <<
"No +3 hit. Added +2 channel " << itr_neighb->first
331 <<
" to cluster; content " << digi.
getPE();
333 <<
"\t itr is pointing at hit with channel nb "
334 << itr->first <<
".";
345 addHit(itr_neighb->first, digi);
349 <<
"Added +1 channel " << itr_neighb->first
350 <<
" as last channel to cluster; content " << digi.
getPE();
351 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
352 << itr->first <<
".";
359 else if (has_backed &&
360 hit_channel_map_.find(itr_back->first - 1) !=
364 itr_back = hit_channel_map_.find(itr->first - 2);
366 addHit(itr_back->first, digi);
369 ldmx_log(debug) <<
"Added -2 channel " << itr_back->first
370 <<
" to cluster; content " << digi.
getPE();
373 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
374 << itr->first <<
".";
388 ldmx_log(debug) <<
"Now have " << v_added_indices_.size()
389 <<
" hits in the cluster ";
391 cluster.
setSeed(v_added_indices_.at(0));
392 cluster.
setIDs(v_added_indices_);
393 cluster.
setNHits(v_added_indices_.size());
400 trig_scint_clusters.push_back(cluster);
402 ldmx_log(trace) << cluster;
409 v_added_indices_.resize(
414 <<
"\t Finished processing of seeding hit with channel nb "
415 << itr->first <<
".";
420 if (hit_channel_map_.begin() == hit_channel_map_.end()) {
422 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
423 "removed! Interfering here to get out of the loop. ";
428 if (trig_scint_clusters.size() > 0)
429 event.add(output_collection_, trig_scint_clusters);
431 hit_channel_map_.clear();
432 v_used_indices_.resize(