91 ldmx_log(debug) <<
"produce() starts! Event number: "
92 <<
event.getEventHeader().getEventNumber();
98 input_collection_, pass_name_)};
101 ldmx_log(debug) <<
"Got digi collection " << input_collection_ <<
"_"
102 << pass_name_ <<
" with " << digis.size() <<
" entries ";
106 bool do_duplicate =
true;
110 for (
const auto& digi : digis) {
113 ldmx_log(debug) <<
"Digi has PE count " << digi.getPE() <<
" and energy "
116 if (
do_clean_hits_ && digi.getQualityFlag() && digi.getQualityFlag() != 4) {
118 ldmx_log(debug) <<
"Skipping hit with non-zero quality flag "
119 << digi.getQualityFlag();
124 if (digi.getPE() > min_thr_) {
125 int id = digi.getBarID();
126 if (
id > max_channel_id_) {
129 ldmx_log(debug) <<
"Skipping channel with bar ID = " <<
id <<
" > "
130 << max_channel_id_ <<
" (max instrumented nb)";
137 hit_channel_map_.find((
id)) != hit_channel_map_.end()) {
139 std::map<int, int>::iterator itr = hit_channel_map_.find(idx);
140 double old_val = digis.at(itr->second).getPE();
142 ldmx_log(debug) <<
"Got duplicate digis for channel " << idx
143 <<
", with already inserted value " << old_val
144 <<
" and new " << digi.getPE();
146 if (digi.getPE() > old_val) {
147 hit_channel_map_.erase(itr->first);
150 <<
"Skipped duplicate digi with smaller value for channel "
157 if (digi.getTime() > pad_time_ + time_tolerance_)
continue;
159 hit_channel_map_.insert(std::pair<int, int>(
id, i_digi));
163 ldmx_log(debug) <<
"Mapping digi hit nb " << i_digi
164 <<
" with energy = " << digi.getEnergy()
165 <<
" MeV, nPE = " << digi.getPE() <<
" > " << min_thr_
166 <<
" to key/channel " << id;
174 std::map<int, int>::iterator itr;
177 std::vector<ldmx::TrigScintCluster> trig_scint_clusters;
180 for (itr = hit_channel_map_.begin(); itr != hit_channel_map_.end(); ++itr) {
182 if (hit_channel_map_.find(itr->first) == hit_channel_map_.end()) {
184 ldmx_log(debug) <<
"Attempting to use removed hit at channel "
185 << itr->first <<
"; skipping.";
194 bool has_used =
false;
195 for (
const auto& index : v_used_indices_) {
196 if (index == itr->first) {
198 ldmx_log(warn) <<
"Attempting to re-use hit at channel " << itr->first
204 if (has_used)
continue;
206 ldmx_log(debug) <<
"\t At hit with channel nb " << itr->first <<
".";
209 if (hit_channel_map_.size() ==
213 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
214 "removed! Unclear how we even got here; interfering "
215 "here to get out of the loop. ";
222 if (digi.
getPE() >= seed_) {
224 ldmx_log(debug) <<
"Seeding cluster with channel " << itr->first
225 <<
"; content " << digi.
getPE();
233 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
234 << itr->first <<
".";
241 std::map<int, int>::iterator itr_back =
242 hit_channel_map_.find(itr->first - 1);
244 bool has_backed =
false;
255 for (
const auto& index : v_used_indices_) {
256 if (index == itr_back->first) {
258 ldmx_log(warn) <<
"Attempting to re-use hit at channel "
259 << itr_back->first <<
"; skipping.";
268 addHit(itr_back->first, digi);
272 ldmx_log(debug) <<
"Added -1 channel " << itr_back->first
273 <<
" to cluster; content " << digi.
getPE();
274 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
275 << itr->first <<
".";
290 if (v_added_indices_.size() < max_width_) {
293 std::map<int, int>::iterator itr_neighb =
294 hit_channel_map_.find(itr->first + 1);
301 if (hit_channel_map_.find(itr_neighb->first + 1) !=
302 hit_channel_map_.end()) {
309 addHit(itr_neighb->first, digi);
313 <<
"No -1 hit. Added +1 channel " << itr_neighb->first
314 <<
" to cluster; content " << digi.
getPE();
315 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
316 << itr->first <<
".";
319 if (v_added_indices_.size() < max_width_) {
320 if (hit_channel_map_.find(itr_neighb->first + 2) ==
324 itr_neighb = hit_channel_map_.find(itr->first + 2);
326 addHit(itr_neighb->first, digi);
329 <<
"No +3 hit. Added +2 channel " << itr_neighb->first
330 <<
" to cluster; content " << digi.
getPE();
332 <<
"\t itr is pointing at hit with channel nb "
333 << itr->first <<
".";
344 addHit(itr_neighb->first, digi);
348 <<
"Added +1 channel " << itr_neighb->first
349 <<
" as last channel to cluster; content " << digi.
getPE();
350 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
351 << itr->first <<
".";
358 else if (has_backed &&
359 hit_channel_map_.find(itr_back->first - 1) !=
363 itr_back = hit_channel_map_.find(itr->first - 2);
365 addHit(itr_back->first, digi);
368 ldmx_log(debug) <<
"Added -2 channel " << itr_back->first
369 <<
" to cluster; content " << digi.
getPE();
372 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
373 << itr->first <<
".";
387 ldmx_log(debug) <<
"Now have " << v_added_indices_.size()
388 <<
" hits in the cluster ";
390 cluster.
setSeed(v_added_indices_.at(0));
391 cluster.
setIDs(v_added_indices_);
392 cluster.
setNHits(v_added_indices_.size());
399 trig_scint_clusters.push_back(cluster);
401 ldmx_log(trace) << cluster;
408 v_added_indices_.resize(
413 <<
"\t Finished processing of seeding hit with channel nb "
414 << itr->first <<
".";
419 if (hit_channel_map_.begin() == hit_channel_map_.end()) {
421 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
422 "removed! Interfering here to get out of the loop. ";
427 if (trig_scint_clusters.size() > 0)
428 event.add(output_collection_, trig_scint_clusters);
430 hit_channel_map_.clear();
431 v_used_indices_.resize(