Process the event and put new data products into it.
37 {
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 if (verbose_) {
124 ldmx_log(debug)
125 << "TrigScintClusterProducer: produce() starts! Event number: "
126 << event.getEventHeader().getEventNumber();
127 }
128
129
130
131 const auto digis{
133
134 if (verbose_) {
135 ldmx_log(debug) << "Got digi collection " << input_collection_ << "_"
136 << passName_ << " with " << digis.size() << " entries ";
137 }
138
139
140 bool doDuplicate = true;
141
142
143 auto iDigi{0};
144 for (const auto &digi : digis) {
145
146
147
148 if (digi.getPE() >
149 minThr_) {
150
151
152 int ID = digi.getBarID();
153
154
155
156
157 if (doDuplicate && hitChannelMap_.find((ID)) != hitChannelMap_.end()) {
158 int idx = ID;
159 std::map<int, int>::iterator itr = hitChannelMap_.find(idx);
160 double oldVal = digis.at(itr->second).getPE();
161 if (verbose_) {
162 ldmx_log(debug) << "Got duplicate digis for channel " << idx
163 << ", with already inserted value " << oldVal
164 << " and new " << digi.getPE();
165 }
166 if (digi.getPE() > oldVal) {
167 hitChannelMap_.erase(itr->first);
168 if (verbose_) {
169 ldmx_log(debug)
170 << "Skipped duplicate digi with smaller value for channel "
171 << idx;
172 }
173 }
174 }
175
176
177 if (digi.getTime() > padTime_ + timeTolerance_) continue;
178
179 hitChannelMap_.insert(std::pair<int, int>(ID, iDigi));
180
181
182 if (verbose_) {
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;
187 }
188 }
189 iDigi++;
190 }
191
192
193
194 std::map<int, int>::iterator itr;
195
196
197 std::vector<ldmx::TrigScintCluster> trigScintClusters;
198
199
200 for (itr = hitChannelMap_.begin(); itr != hitChannelMap_.end(); ++itr) {
201
202 if (hitChannelMap_.find(itr->first) == hitChannelMap_.end()) {
203 if (verbose_ > 1) {
204 ldmx_log(debug) << "Attempting to use removed hit at channel "
205 << itr->first << "; skipping.";
206 }
207 continue;
208 }
209
210
211
212
213
214 bool hasUsed = false;
215 for (const auto &index : v_usedIndices_) {
216 if (index == itr->first) {
217 if (verbose_ > 1) {
218 ldmx_log(warn) << "Attempting to re-use hit at channel " << itr->first
219 << "; skipping.";
220 }
221 hasUsed = true;
222 }
223 }
224 if (hasUsed) continue;
225 if (verbose_ > 1) {
226 ldmx_log(debug) << "\t At hit with channel nb " << itr->first << ".";
227 }
228
229 if (hitChannelMap_.size() ==
230 0)
231 {
232 if (verbose_)
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. ";
236 break;
237 }
238
240
241
242 if (digi.
getPE() >= seed_) {
243 if (verbose_ > 1) {
244 ldmx_log(debug) << "Seeding cluster with channel " << itr->first
245 <<
"; content " << digi.
getPE();
246 }
247
248
249
251
252 if (verbose_ > 1) {
253 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
254 << itr->first << ".";
255 }
256
257
258
259
260
261 std::map<int, int>::iterator itrBack =
262 hitChannelMap_.find(itr->first - 1);
263
264 bool hasBacked = false;
265
266 if (itrBack !=
267 hitChannelMap_.end()) {
268
269
270
271
272
273 hasUsed = false;
274 for (const auto &index : v_usedIndices_) {
275 if (index == itrBack->first) {
276 if (verbose_ > 1) {
277 ldmx_log(warn) << "Attempting to re-use hit at channel "
278 << itrBack->first << "; skipping.";
279 }
280 hasUsed = true;
281 }
282 }
283 if (!hasUsed) {
285
286
287 addHit(itrBack->first, digi);
288 hasBacked = true;
289
290 if (verbose_ > 1) {
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 << ".";
295 }
296
297 }
298 }
299
300
301
302
303
304
305
306
307
308
309 if (v_addedIndices_.size() < maxWidth_) {
310
311
312 std::map<int, int>::iterator itrNeighb =
313 hitChannelMap_.find(itr->first + 1);
314 if (itrNeighb !=
315 hitChannelMap_.end()) {
316
317
318
319 if (hitChannelMap_.find(itrNeighb->first + 1) !=
320 hitChannelMap_.end()) {
321
322 if (!hasBacked) {
323
324
325
327 addHit(itrNeighb->first, digi);
328
329 if (verbose_ > 1) {
330 ldmx_log(debug)
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 << ".";
335 }
336
337 if (v_addedIndices_.size() < maxWidth_) {
338 if (hitChannelMap_.find(itrNeighb->first + 2) ==
339 hitChannelMap_
340 .end()) {
341
342 itrNeighb = hitChannelMap_.find(itr->first + 2);
344 addHit(itrNeighb->first, digi);
345 if (verbose_ > 1) {
346 ldmx_log(debug)
347 << "No +3 hit. Added +2 channel " << itrNeighb->first
348 <<
" to cluster; content " << digi.
getPE();
349 ldmx_log(debug)
350 << "\t itr is pointing at hit with channel nb "
351 << itr->first << ".";
352 }
353 }
354
355 }
356 }
357 }
358 else {
360 itrNeighb->second);
361
362 addHit(itrNeighb->first, digi);
363
364 if (verbose_ > 1) {
365 ldmx_log(debug)
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 << ".";
370 }
371 }
372 }
373
374
375
376 else if (hasBacked &&
377 hitChannelMap_.find(itrBack->first - 1) !=
378 hitChannelMap_
379 .end()) {
380
381 itrBack = hitChannelMap_.find(itr->first - 2);
383 addHit(itrBack->first, digi);
384
385 if (verbose_ > 1) {
386 ldmx_log(debug) << "Added -2 channel " << itrBack->first
387 <<
" to cluster; content " << digi.
getPE();
388 }
389 if (verbose_ > 1) {
390 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
391 << itr->first << ".";
392 }
393
394 }
395
396 }
397
398
399 centroid_ /= val_;
400 centroid_ -= 1;
401
403
404 if (verbose_ > 1) {
405 ldmx_log(debug) << "Now have " << v_addedIndices_.size()
406 << " hits in the cluster ";
407 }
408 cluster.
setSeed(v_addedIndices_.at(0));
409 cluster.
setIDs(v_addedIndices_);
410 cluster.
setNHits(v_addedIndices_.size());
412 float cx;
413 float cy = centroid_;
414 float cz = -99999;
415 if (centroid_ <
416 vertBarStartIdx_)
417 cx = -1;
418 else {
419 cx = (int)((centroid_ - vertBarStartIdx_) / 4);
420 cy = (int)centroid_ % 4;
421 }
427
428 trigScintClusters.push_back(cluster);
429
430 if (verbose_) cluster.
Print();
431
432 centroid_ = 0;
433 centroidX_ = -1;
434 centroidY_ = -1;
435 val_ = 0;
436 valE_ = 0;
437 beamE_ = 0;
438 time_ = 0;
439 v_addedIndices_.resize(
440 0);
441
442 if (verbose_ > 1) {
443 ldmx_log(debug)
444 << "\t Finished processing of seeding hit with channel nb "
445 << itr->first << ".";
446 }
447
448 }
449
450 if (hitChannelMap_.begin() == hitChannelMap_.end()) {
451 if (verbose_)
452 ldmx_log(warn) << "Time flies, and all clusters have already been "
453 "removed! Interfering here to get out of the loop. ";
454 break;
455 }
456 }
457
458 if (trigScintClusters.size() > 0)
459 event.add(output_collection_, trigScintClusters);
460
461 hitChannelMap_.clear();
462 v_usedIndices_.resize(
463 0);
464
465 return;
466}
Stores cluster information from the trigger scintillator pads.
void setIDs(std::vector< unsigned int > &hitIDs)
The channel numbers of hits forming the cluster.
void setNHits(int nHits)
The number of hits forming the cluster.
void setCentroidXYZ(double x, double y, double z)
The cluster centroid in x,y,z.
void setEnergy(double energy)
Set the cluster energy.
void Print(Option_t *option="") const
Print a description of this object.
void setCentroid(double centroid)
void setPE(float PE)
Set the cluster photoelectron count (PE)
void setBeamEfrac(float e)
Set beam energy fraction of hit.
void setTime(float t)
Set time of hit.
virtual void addHit(uint idx, ldmx::TrigScintHit hit)
add a hit at index idx to a cluster