126 <<
"TrigScintClusterProducer: produce() starts! Event number: "
127 <<
event.getEventHeader().getEventNumber();
136 ldmx_log(debug) <<
"Got digi collection " << input_collection_ <<
"_"
137 << pass_name_ <<
" with " << digis.size() <<
" entries ";
141 bool do_duplicate =
true;
145 for (
const auto& digi : digis) {
153 int id = digi.getBarID();
159 hit_channel_map_.find((
id)) != hit_channel_map_.end()) {
161 std::map<int, int>::iterator itr = hit_channel_map_.find(idx);
162 double old_val = digis.at(itr->second).getPE();
164 ldmx_log(debug) <<
"Got duplicate digis for channel " << idx
165 <<
", with already inserted value " << old_val
166 <<
" and new " << digi.getPE();
168 if (digi.getPE() > old_val) {
169 hit_channel_map_.erase(itr->first);
172 <<
"Skipped duplicate digi with smaller value for channel "
179 if (digi.getTime() > pad_time_ + time_tolerance_) {
184 hit_channel_map_.insert(std::pair<int, int>(
id, i_digi));
188 ldmx_log(debug) <<
"Mapping digi hit nb " << i_digi
189 <<
" with energy = " << digi.getEnergy()
190 <<
" MeV, nPE = " << digi.getPE() <<
" > " << min_thr_
191 <<
" to key/channel " << id;
199 std::map<int, int>::iterator itr;
202 std::vector<ldmx::TrigScintCluster> trig_scint_clusters;
205 for (itr = hit_channel_map_.begin(); itr != hit_channel_map_.end(); ++itr) {
207 if (hit_channel_map_.find(itr->first) == hit_channel_map_.end()) {
209 ldmx_log(debug) <<
"Attempting to use removed hit at channel "
210 << itr->first <<
"; skipping.";
219 bool has_used =
false;
220 for (
const auto& index : v_used_indices_) {
221 if (index == itr->first) {
223 ldmx_log(warn) <<
"Attempting to re-use hit at channel " << itr->first
229 if (has_used)
continue;
231 ldmx_log(debug) <<
"\t At hit with channel nb " << itr->first <<
".";
234 if (hit_channel_map_.size() ==
238 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
239 "removed! Unclear how we even got here; interfering "
240 "here to get out of the loop. ";
247 if (digi.
getPE() >= seed_) {
249 ldmx_log(debug) <<
"Seeding cluster with channel " << itr->first
250 <<
"; content " << digi.
getPE();
258 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
259 << itr->first <<
".";
266 std::map<int, int>::iterator itr_back =
267 hit_channel_map_.find(itr->first - 1);
269 bool has_backed =
false;
280 for (
const auto& index : v_used_indices_) {
281 if (index == itr_back->first) {
283 ldmx_log(warn) <<
"Attempting to re-use hit at channel "
284 << itr_back->first <<
"; skipping.";
293 addHit(itr_back->first, digi);
297 ldmx_log(debug) <<
"Added -1 channel " << itr_back->first
298 <<
" to cluster; content " << digi.
getPE();
299 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
300 << itr->first <<
".";
315 if (v_added_indices_.size() < max_width_) {
318 std::map<int, int>::iterator itr_neighb =
319 hit_channel_map_.find(itr->first + 1);
326 if (hit_channel_map_.find(itr_neighb->first + 1) !=
327 hit_channel_map_.end()) {
334 addHit(itr_neighb->first, digi);
338 <<
"No -1 hit. Added +1 channel " << itr_neighb->first
339 <<
" to cluster; content " << digi.
getPE();
340 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
341 << itr->first <<
".";
344 if (v_added_indices_.size() < max_width_) {
345 if (hit_channel_map_.find(itr_neighb->first + 2) ==
349 itr_neighb = hit_channel_map_.find(itr->first + 2);
351 addHit(itr_neighb->first, digi);
354 <<
"No +3 hit. Added +2 channel " << itr_neighb->first
355 <<
" to cluster; content " << digi.
getPE();
357 <<
"\t itr is pointing at hit with channel nb "
358 << itr->first <<
".";
369 addHit(itr_neighb->first, digi);
373 <<
"Added +1 channel " << itr_neighb->first
374 <<
" as last channel to cluster; content " << digi.
getPE();
375 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
376 << itr->first <<
".";
383 else if (has_backed &&
384 hit_channel_map_.find(itr_back->first - 1) !=
388 itr_back = hit_channel_map_.find(itr->first - 2);
390 addHit(itr_back->first, digi);
393 ldmx_log(debug) <<
"Added -2 channel " << itr_back->first
394 <<
" to cluster; content " << digi.
getPE();
397 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
398 << itr->first <<
".";
414 ldmx_log(debug) <<
"Now have " << v_added_indices_.size()
415 <<
" hits in the cluster ";
417 cluster.
setSeed(v_added_indices_.at(0));
418 cluster.
setIDs(v_added_indices_);
419 cluster.
setNHits(v_added_indices_.size());
422 float cy = centroid_;
425 if (centroid_ < vert_bar_start_idx_) {
431 cx = (int)((centroid_ - vert_bar_start_idx_) / 4);
432 cy = (int)centroid_ % 4;
440 trig_scint_clusters.push_back(cluster);
442 ldmx_log(trace) << cluster;
453 v_added_indices_.resize(0);
457 <<
"\t Finished processing of seeding hit with channel nb "
458 << itr->first <<
".";
463 if (hit_channel_map_.begin() == hit_channel_map_.end()) {
465 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
466 "removed! Interfering here to get out of the loop. ";
471 event.add(output_collection_, trig_scint_clusters);
473 hit_channel_map_.clear();
475 v_used_indices_.resize(0);