125 <<
"TrigScintClusterProducer: produce() starts! Event number: "
126 <<
event.getEventHeader().getEventNumber();
135 ldmx_log(debug) <<
"Got digi collection " << input_collection_ <<
"_"
136 << passName_ <<
" with " << digis.size() <<
" entries ";
140 bool doDuplicate =
true;
144 for (
const auto &digi : digis) {
152 int ID = digi.getBarID();
157 if (doDuplicate && hitChannelMap_.find((ID)) != hitChannelMap_.end()) {
159 std::map<int, int>::iterator itr = hitChannelMap_.find(idx);
160 double oldVal = digis.at(itr->second).getPE();
162 ldmx_log(debug) <<
"Got duplicate digis for channel " << idx
163 <<
", with already inserted value " << oldVal
164 <<
" and new " << digi.getPE();
166 if (digi.getPE() > oldVal) {
167 hitChannelMap_.erase(itr->first);
170 <<
"Skipped duplicate digi with smaller value for channel "
177 if (digi.getTime() > padTime_ + timeTolerance_)
continue;
179 hitChannelMap_.insert(std::pair<int, int>(ID, iDigi));
183 ldmx_log(debug) <<
"Mapping digi hit nb " << iDigi
184 <<
" with energy = " << digi.getEnergy()
185 <<
" MeV, nPE = " << digi.getPE() <<
" > " << minThr_
186 <<
" to key/channel " << ID;
194 std::map<int, int>::iterator itr;
197 std::vector<ldmx::TrigScintCluster> trigScintClusters;
200 for (itr = hitChannelMap_.begin(); itr != hitChannelMap_.end(); ++itr) {
202 if (hitChannelMap_.find(itr->first) == hitChannelMap_.end()) {
204 ldmx_log(debug) <<
"Attempting to use removed hit at channel "
205 << itr->first <<
"; skipping.";
214 bool hasUsed =
false;
215 for (
const auto &index : v_usedIndices_) {
216 if (index == itr->first) {
218 ldmx_log(warn) <<
"Attempting to re-use hit at channel " << itr->first
224 if (hasUsed)
continue;
226 ldmx_log(debug) <<
"\t At hit with channel nb " << itr->first <<
".";
229 if (hitChannelMap_.size() ==
233 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
234 "removed! Unclear how we even got here; interfering "
235 "here to get out of the loop. ";
242 if (digi.
getPE() >= seed_) {
244 ldmx_log(debug) <<
"Seeding cluster with channel " << itr->first
245 <<
"; content " << digi.
getPE();
253 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
254 << itr->first <<
".";
261 std::map<int, int>::iterator itrBack =
262 hitChannelMap_.find(itr->first - 1);
264 bool hasBacked =
false;
267 hitChannelMap_.end()) {
274 for (
const auto &index : v_usedIndices_) {
275 if (index == itrBack->first) {
277 ldmx_log(warn) <<
"Attempting to re-use hit at channel "
278 << itrBack->first <<
"; skipping.";
287 addHit(itrBack->first, digi);
291 ldmx_log(debug) <<
"Added -1 channel " << itrBack->first
292 <<
" to cluster; content " << digi.
getPE();
293 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
294 << itr->first <<
".";
309 if (v_addedIndices_.size() < maxWidth_) {
312 std::map<int, int>::iterator itrNeighb =
313 hitChannelMap_.find(itr->first + 1);
315 hitChannelMap_.end()) {
319 if (hitChannelMap_.find(itrNeighb->first + 1) !=
320 hitChannelMap_.end()) {
327 addHit(itrNeighb->first, digi);
331 <<
"No -1 hit. Added +1 channel " << itrNeighb->first
332 <<
" to cluster; content " << digi.
getPE();
333 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
334 << itr->first <<
".";
337 if (v_addedIndices_.size() < maxWidth_) {
338 if (hitChannelMap_.find(itrNeighb->first + 2) ==
342 itrNeighb = hitChannelMap_.find(itr->first + 2);
344 addHit(itrNeighb->first, digi);
347 <<
"No +3 hit. Added +2 channel " << itrNeighb->first
348 <<
" to cluster; content " << digi.
getPE();
350 <<
"\t itr is pointing at hit with channel nb "
351 << itr->first <<
".";
362 addHit(itrNeighb->first, digi);
366 <<
"Added +1 channel " << itrNeighb->first
367 <<
" as last channel to cluster; content " << digi.
getPE();
368 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
369 << itr->first <<
".";
376 else if (hasBacked &&
377 hitChannelMap_.find(itrBack->first - 1) !=
381 itrBack = hitChannelMap_.find(itr->first - 2);
383 addHit(itrBack->first, digi);
386 ldmx_log(debug) <<
"Added -2 channel " << itrBack->first
387 <<
" to cluster; content " << digi.
getPE();
390 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
391 << itr->first <<
".";
405 ldmx_log(debug) <<
"Now have " << v_addedIndices_.size()
406 <<
" hits in the cluster ";
408 cluster.
setSeed(v_addedIndices_.at(0));
409 cluster.
setIDs(v_addedIndices_);
410 cluster.
setNHits(v_addedIndices_.size());
413 float cy = centroid_;
419 cx = (int)((centroid_ - vertBarStartIdx_) / 4);
420 cy = (int)centroid_ % 4;
428 trigScintClusters.push_back(cluster);
430 if (verbose_) cluster.
Print();
439 v_addedIndices_.resize(
444 <<
"\t Finished processing of seeding hit with channel nb "
445 << itr->first <<
".";
450 if (hitChannelMap_.begin() == hitChannelMap_.end()) {
452 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
453 "removed! Interfering here to get out of the loop. ";
458 if (trigScintClusters.size() > 0)
459 event.add(output_collection_, trigScintClusters);
461 hitChannelMap_.clear();
462 v_usedIndices_.resize(