127 <<
"TrigScintClusterProducer: produce() starts! Event number: "
128 <<
event.getEventHeader().getEventNumber();
137 ldmx_log(debug) <<
"Got digi collection " << input_collection_ <<
"_"
138 << pass_name_ <<
" with " << digis.size() <<
" entries ";
142 bool do_duplicate =
true;
146 for (
const auto &digi : digis) {
154 int id = digi.getBarID();
160 hit_channel_map_.find((
id)) != hit_channel_map_.end()) {
162 std::map<int, int>::iterator itr = hit_channel_map_.find(idx);
163 double old_val = digis.at(itr->second).getPE();
165 ldmx_log(debug) <<
"Got duplicate digis for channel " << idx
166 <<
", with already inserted value " << old_val
167 <<
" and new " << digi.getPE();
169 if (digi.getPE() > old_val) {
170 hit_channel_map_.erase(itr->first);
173 <<
"Skipped duplicate digi with smaller value for channel "
180 if (digi.getTime() > pad_time_ + time_tolerance_) {
185 hit_channel_map_.insert(std::pair<int, int>(
id, i_digi));
189 ldmx_log(debug) <<
"Mapping digi hit nb " << i_digi
190 <<
" with energy = " << digi.getEnergy()
191 <<
" MeV, nPE = " << digi.getPE() <<
" > " << min_thr_
192 <<
" to key/channel " << id;
200 std::map<int, int>::iterator itr;
203 std::vector<ldmx::TrigScintCluster> trig_scint_clusters;
206 for (itr = hit_channel_map_.begin(); itr != hit_channel_map_.end(); ++itr) {
208 if (hit_channel_map_.find(itr->first) == hit_channel_map_.end()) {
210 ldmx_log(debug) <<
"Attempting to use removed hit at channel "
211 << itr->first <<
"; skipping.";
220 bool has_used =
false;
221 for (
const auto &index : v_used_indices_) {
222 if (index == itr->first) {
224 ldmx_log(warn) <<
"Attempting to re-use hit at channel " << itr->first
230 if (has_used)
continue;
232 ldmx_log(debug) <<
"\t At hit with channel nb " << itr->first <<
".";
235 if (hit_channel_map_.size() ==
239 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
240 "removed! Unclear how we even got here; interfering "
241 "here to get out of the loop. ";
248 if (digi.
getPE() >= seed_) {
250 ldmx_log(debug) <<
"Seeding cluster with channel " << itr->first
251 <<
"; content " << digi.
getPE();
259 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
260 << itr->first <<
".";
267 std::map<int, int>::iterator itr_back =
268 hit_channel_map_.find(itr->first - 1);
270 bool has_backed =
false;
281 for (
const auto &index : v_used_indices_) {
282 if (index == itr_back->first) {
284 ldmx_log(warn) <<
"Attempting to re-use hit at channel "
285 << itr_back->first <<
"; skipping.";
294 addHit(itr_back->first, digi);
298 ldmx_log(debug) <<
"Added -1 channel " << itr_back->first
299 <<
" to cluster; content " << digi.
getPE();
300 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
301 << itr->first <<
".";
316 if (v_added_indices_.size() < max_width_) {
319 std::map<int, int>::iterator itr_neighb =
320 hit_channel_map_.find(itr->first + 1);
327 if (hit_channel_map_.find(itr_neighb->first + 1) !=
328 hit_channel_map_.end()) {
335 addHit(itr_neighb->first, digi);
339 <<
"No -1 hit. Added +1 channel " << itr_neighb->first
340 <<
" to cluster; content " << digi.
getPE();
341 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
342 << itr->first <<
".";
345 if (v_added_indices_.size() < max_width_) {
346 if (hit_channel_map_.find(itr_neighb->first + 2) ==
350 itr_neighb = hit_channel_map_.find(itr->first + 2);
352 addHit(itr_neighb->first, digi);
355 <<
"No +3 hit. Added +2 channel " << itr_neighb->first
356 <<
" to cluster; content " << digi.
getPE();
358 <<
"\t itr is pointing at hit with channel nb "
359 << itr->first <<
".";
370 addHit(itr_neighb->first, digi);
374 <<
"Added +1 channel " << itr_neighb->first
375 <<
" as last channel to cluster; content " << digi.
getPE();
376 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
377 << itr->first <<
".";
384 else if (has_backed &&
385 hit_channel_map_.find(itr_back->first - 1) !=
389 itr_back = hit_channel_map_.find(itr->first - 2);
391 addHit(itr_back->first, digi);
394 ldmx_log(debug) <<
"Added -2 channel " << itr_back->first
395 <<
" to cluster; content " << digi.
getPE();
398 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
399 << itr->first <<
".";
415 ldmx_log(debug) <<
"Now have " << v_added_indices_.size()
416 <<
" hits in the cluster ";
418 cluster.
setSeed(v_added_indices_.at(0));
419 cluster.
setIDs(v_added_indices_);
420 cluster.
setNHits(v_added_indices_.size());
423 float cy = centroid_;
426 if (centroid_ < vert_bar_start_idx_) {
432 cx = (int)((centroid_ - vert_bar_start_idx_) / 4);
433 cy = (int)centroid_ % 4;
441 trig_scint_clusters.push_back(cluster);
443 ldmx_log(trace) << cluster;
454 v_added_indices_.resize(0);
458 <<
"\t Finished processing of seeding hit with channel nb "
459 << itr->first <<
".";
464 if (hit_channel_map_.begin() == hit_channel_map_.end()) {
466 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
467 "removed! Interfering here to get out of the loop. ";
472 if (trig_scint_clusters.size() > 0)
473 event.add(output_collection_, trig_scint_clusters);
475 hit_channel_map_.clear();
477 v_used_indices_.resize(0);