93 <<
"TestBeamClusterProducer: produce() starts! Event number: "
94 <<
event.getEventHeader().getEventNumber();
100 input_collection_, passName_)};
103 ldmx_log(debug) <<
"Got digi collection " << input_collection_ <<
"_"
104 << passName_ <<
" with " << digis.size() <<
" entries ";
108 bool doDuplicate =
true;
112 for (
const auto &digi : digis) {
115 ldmx_log(debug) <<
"Digi has PE count " << digi.getPE() <<
" and energy "
118 if (
doCleanHits_ && digi.getQualityFlag() && digi.getQualityFlag() != 4) {
120 ldmx_log(debug) <<
"Skipping hit with non-zero quality flag "
121 << digi.getQualityFlag();
129 int ID = digi.getBarID();
133 ldmx_log(debug) <<
"Skipping channel with bar ID = " << ID <<
" > "
134 << maxChannelID_ <<
" (max instrumented nb)";
140 if (doDuplicate && hitChannelMap_.find((ID)) != hitChannelMap_.end()) {
142 std::map<int, int>::iterator itr = hitChannelMap_.find(idx);
143 double oldVal = digis.at(itr->second).getPE();
145 ldmx_log(debug) <<
"Got duplicate digis for channel " << idx
146 <<
", with already inserted value " << oldVal
147 <<
" and new " << digi.getPE();
149 if (digi.getPE() > oldVal) {
150 hitChannelMap_.erase(itr->first);
153 <<
"Skipped duplicate digi with smaller value for channel "
160 if (digi.getTime() > padTime_ + timeTolerance_)
continue;
162 hitChannelMap_.insert(std::pair<int, int>(ID, iDigi));
166 ldmx_log(debug) <<
"Mapping digi hit nb " << iDigi
167 <<
" with energy = " << digi.getEnergy()
168 <<
" MeV, nPE = " << digi.getPE() <<
" > " << minThr_
169 <<
" to key/channel " << ID;
177 std::map<int, int>::iterator itr;
180 std::vector<ldmx::TrigScintCluster> trigScintClusters;
183 for (itr = hitChannelMap_.begin(); itr != hitChannelMap_.end(); ++itr) {
185 if (hitChannelMap_.find(itr->first) == hitChannelMap_.end()) {
187 ldmx_log(debug) <<
"Attempting to use removed hit at channel "
188 << itr->first <<
"; skipping.";
197 bool hasUsed =
false;
198 for (
const auto &index : v_usedIndices_) {
199 if (index == itr->first) {
201 ldmx_log(warn) <<
"Attempting to re-use hit at channel " << itr->first
207 if (hasUsed)
continue;
209 ldmx_log(debug) <<
"\t At hit with channel nb " << itr->first <<
".";
212 if (hitChannelMap_.size() ==
216 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
217 "removed! Unclear how we even got here; interfering "
218 "here to get out of the loop. ";
225 if (digi.
getPE() >= seed_) {
227 ldmx_log(debug) <<
"Seeding cluster with channel " << itr->first
228 <<
"; content " << digi.
getPE();
236 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
237 << itr->first <<
".";
244 std::map<int, int>::iterator itrBack =
245 hitChannelMap_.find(itr->first - 1);
247 bool hasBacked =
false;
250 hitChannelMap_.end()) {
257 for (
const auto &index : v_usedIndices_) {
258 if (index == itrBack->first) {
260 ldmx_log(warn) <<
"Attempting to re-use hit at channel "
261 << itrBack->first <<
"; skipping.";
270 addHit(itrBack->first, digi);
274 ldmx_log(debug) <<
"Added -1 channel " << itrBack->first
275 <<
" to cluster; content " << digi.
getPE();
276 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
277 << itr->first <<
".";
292 if (v_addedIndices_.size() < maxWidth_) {
295 std::map<int, int>::iterator itrNeighb =
296 hitChannelMap_.find(itr->first + 1);
298 hitChannelMap_.end()) {
302 if (hitChannelMap_.find(itrNeighb->first + 1) !=
303 hitChannelMap_.end()) {
310 addHit(itrNeighb->first, digi);
314 <<
"No -1 hit. Added +1 channel " << itrNeighb->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_addedIndices_.size() < maxWidth_) {
321 if (hitChannelMap_.find(itrNeighb->first + 2) ==
325 itrNeighb = hitChannelMap_.find(itr->first + 2);
327 addHit(itrNeighb->first, digi);
330 <<
"No +3 hit. Added +2 channel " << itrNeighb->first
331 <<
" to cluster; content " << digi.
getPE();
333 <<
"\t itr is pointing at hit with channel nb "
334 << itr->first <<
".";
345 addHit(itrNeighb->first, digi);
349 <<
"Added +1 channel " << itrNeighb->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 (hasBacked &&
360 hitChannelMap_.find(itrBack->first - 1) !=
364 itrBack = hitChannelMap_.find(itr->first - 2);
366 addHit(itrBack->first, digi);
369 ldmx_log(debug) <<
"Added -2 channel " << itrBack->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_addedIndices_.size()
389 <<
" hits in the cluster ";
391 cluster.
setSeed(v_addedIndices_.at(0));
392 cluster.
setIDs(v_addedIndices_);
393 cluster.
setNHits(v_addedIndices_.size());
400 trigScintClusters.push_back(cluster);
402 if (verbose_) cluster.
Print();
409 v_addedIndices_.resize(
414 <<
"\t Finished processing of seeding hit with channel nb "
415 << itr->first <<
".";
420 if (hitChannelMap_.begin() == hitChannelMap_.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 (trigScintClusters.size() > 0)
429 event.add(output_collection_, trigScintClusters);
431 hitChannelMap_.clear();
432 v_usedIndices_.resize(