10 seed_ = ps.getParameter<
double>(
"seed_threshold");
11 minThr_ = ps.getParameter<
double>(
"clustering_threshold");
12 maxWidth_ = ps.getParameter<
int>(
"max_cluster_width");
13 input_collection_ = ps.getParameter<std::string>(
"input_collection");
14 passName_ = ps.getParameter<std::string>(
"input_pass_name");
15 output_collection_ = ps.getParameter<std::string>(
"output_collection");
16 verbose_ = ps.getParameter<
int>(
"verbosity");
17 vertBarStartIdx_ = ps.getParameter<
int>(
"vertical_bar_start_index");
18 timeTolerance_ = ps.getParameter<
double>(
"time_tolerance");
19 padTime_ = ps.getParameter<
double>(
"pad_time");
21 ldmx_log(info) <<
"In TrigScintClusterProducer: configure done!";
22 ldmx_log(info) <<
"Got parameters: \nSeed threshold: " << seed_
23 <<
"\nClustering threshold: " << minThr_
24 <<
"\nMax cluster width: " << maxWidth_
25 <<
"\nExpected pad hit time: " << padTime_
26 <<
"\nMax hit time delay: " << timeTolerance_
27 <<
"\nVertical bar start index: " << vertBarStartIdx_
28 <<
"\nInput collection: " << input_collection_
29 <<
"\nInput pass name: " << passName_
30 <<
"\nOutput collection: " << output_collection_
31 <<
"\nVerbosity: " << verbose_;
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_) {
182 hitChannelMap_.insert(std::pair<int, int>(ID, iDigi));
186 ldmx_log(debug) <<
"Mapping digi hit nb " << iDigi
187 <<
" with energy = " << digi.getEnergy()
188 <<
" MeV, nPE = " << digi.getPE() <<
" > " << minThr_
189 <<
" to key/channel " << ID;
197 std::map<int, int>::iterator itr;
200 std::vector<ldmx::TrigScintCluster> trigScintClusters;
203 for (itr = hitChannelMap_.begin(); itr != hitChannelMap_.end(); ++itr) {
205 if (hitChannelMap_.find(itr->first) == hitChannelMap_.end()) {
207 ldmx_log(debug) <<
"Attempting to use removed hit at channel "
208 << itr->first <<
"; skipping.";
217 bool hasUsed =
false;
218 for (
const auto &index : v_usedIndices_) {
219 if (index == itr->first) {
221 ldmx_log(warn) <<
"Attempting to re-use hit at channel " << itr->first
227 if (hasUsed)
continue;
229 ldmx_log(debug) <<
"\t At hit with channel nb " << itr->first <<
".";
232 if (hitChannelMap_.size() ==
236 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
237 "removed! Unclear how we even got here; interfering "
238 "here to get out of the loop. ";
245 if (digi.
getPE() >= seed_) {
247 ldmx_log(debug) <<
"Seeding cluster with channel " << itr->first
248 <<
"; content " << digi.
getPE();
256 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
257 << itr->first <<
".";
264 std::map<int, int>::iterator itrBack =
265 hitChannelMap_.find(itr->first - 1);
267 bool hasBacked =
false;
270 hitChannelMap_.end()) {
277 for (
const auto &index : v_usedIndices_) {
278 if (index == itrBack->first) {
280 ldmx_log(warn) <<
"Attempting to re-use hit at channel "
281 << itrBack->first <<
"; skipping.";
290 addHit(itrBack->first, digi);
294 ldmx_log(debug) <<
"Added -1 channel " << itrBack->first
295 <<
" to cluster; content " << digi.
getPE();
296 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
297 << itr->first <<
".";
312 if (v_addedIndices_.size() < maxWidth_) {
315 std::map<int, int>::iterator itrNeighb =
316 hitChannelMap_.find(itr->first + 1);
318 hitChannelMap_.end()) {
322 if (hitChannelMap_.find(itrNeighb->first + 1) !=
323 hitChannelMap_.end()) {
330 addHit(itrNeighb->first, digi);
334 <<
"No -1 hit. Added +1 channel " << itrNeighb->first
335 <<
" to cluster; content " << digi.
getPE();
336 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
337 << itr->first <<
".";
340 if (v_addedIndices_.size() < maxWidth_) {
341 if (hitChannelMap_.find(itrNeighb->first + 2) ==
345 itrNeighb = hitChannelMap_.find(itr->first + 2);
347 addHit(itrNeighb->first, digi);
350 <<
"No +3 hit. Added +2 channel " << itrNeighb->first
351 <<
" to cluster; content " << digi.
getPE();
353 <<
"\t itr is pointing at hit with channel nb "
354 << itr->first <<
".";
365 addHit(itrNeighb->first, digi);
369 <<
"Added +1 channel " << itrNeighb->first
370 <<
" as last channel to cluster; content " << digi.
getPE();
371 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
372 << itr->first <<
".";
379 else if (hasBacked &&
380 hitChannelMap_.find(itrBack->first - 1) !=
384 itrBack = hitChannelMap_.find(itr->first - 2);
386 addHit(itrBack->first, digi);
389 ldmx_log(debug) <<
"Added -2 channel " << itrBack->first
390 <<
" to cluster; content " << digi.
getPE();
393 ldmx_log(debug) <<
"\t itr is pointing at hit with channel nb "
394 << itr->first <<
".";
408 ldmx_log(debug) <<
"Now have " << v_addedIndices_.size()
409 <<
" hits in the cluster ";
411 cluster.
setSeed(v_addedIndices_.at(0));
412 cluster.
setIDs(v_addedIndices_);
413 cluster.
setNHits(v_addedIndices_.size());
416 float cy = centroid_;
422 cx = (int)((centroid_ - vertBarStartIdx_) / 4);
423 cy = (int)centroid_ % 4;
431 trigScintClusters.push_back(cluster);
433 if (verbose_) cluster.
Print();
442 v_addedIndices_.resize(
447 <<
"\t Finished processing of seeding hit with channel nb "
448 << itr->first <<
".";
453 if (hitChannelMap_.begin() == hitChannelMap_.end()) {
455 ldmx_log(warn) <<
"Time flies, and all clusters have already been "
456 "removed! Interfering here to get out of the loop. ";
461 if (trigScintClusters.size() > 0)
462 event.add(output_collection_, trigScintClusters);
464 hitChannelMap_.clear();
465 v_usedIndices_.resize(