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 << pass_name_ << " with " << digis.size() << " entries ";
137 }
138
139
140 bool do_duplicate = true;
141
142
143 auto i_digi{0};
144 for (const auto &digi : digis) {
145
146
147
148 if (digi.getPE() >
149 min_thr_) {
150
151
152 int id = digi.getBarID();
153
154
155
156
157 if (do_duplicate &&
158 hit_channel_map_.find((id)) != hit_channel_map_.end()) {
159 int idx = id;
160 std::map<int, int>::iterator itr = hit_channel_map_.find(idx);
161 double old_val = digis.at(itr->second).getPE();
162 if (verbose_) {
163 ldmx_log(debug) << "Got duplicate digis for channel " << idx
164 << ", with already inserted value " << old_val
165 << " and new " << digi.getPE();
166 }
167 if (digi.getPE() > old_val) {
168 hit_channel_map_.erase(itr->first);
169 if (verbose_) {
170 ldmx_log(debug)
171 << "Skipped duplicate digi with smaller value for channel "
172 << idx;
173 }
174 }
175 }
176
177
178 if (digi.getTime() > pad_time_ + time_tolerance_) {
179 i_digi++;
180 continue;
181 }
182
183 hit_channel_map_.insert(std::pair<int, int>(id, i_digi));
184
185
186 if (verbose_) {
187 ldmx_log(debug) << "Mapping digi hit nb " << i_digi
188 << " with energy = " << digi.getEnergy()
189 << " MeV, nPE = " << digi.getPE() << " > " << min_thr_
190 << " to key/channel " << id;
191 }
192 }
193 i_digi++;
194 }
195
196
197
198 std::map<int, int>::iterator itr;
199
200
201 std::vector<ldmx::TrigScintCluster> trig_scint_clusters;
202
203
204 for (itr = hit_channel_map_.begin(); itr != hit_channel_map_.end(); ++itr) {
205
206 if (hit_channel_map_.find(itr->first) == hit_channel_map_.end()) {
207 if (verbose_ > 1) {
208 ldmx_log(debug) << "Attempting to use removed hit at channel "
209 << itr->first << "; skipping.";
210 }
211 continue;
212 }
213
214
215
216
217
218 bool has_used = false;
219 for (const auto &index : v_used_indices_) {
220 if (index == itr->first) {
221 if (verbose_ > 1) {
222 ldmx_log(warn) << "Attempting to re-use hit at channel " << itr->first
223 << "; skipping.";
224 }
225 has_used = true;
226 }
227 }
228 if (has_used) continue;
229 if (verbose_ > 1) {
230 ldmx_log(debug) << "\t At hit with channel nb " << itr->first << ".";
231 }
232
233 if (hit_channel_map_.size() ==
234 0)
235 {
236 if (verbose_)
237 ldmx_log(warn) << "Time flies, and all clusters have already been "
238 "removed! Unclear how we even got here; interfering "
239 "here to get out of the loop. ";
240 break;
241 }
242
244
245
246 if (digi.
getPE() >= seed_) {
247 if (verbose_ > 1) {
248 ldmx_log(debug) << "Seeding cluster with channel " << itr->first
249 <<
"; content " << digi.
getPE();
250 }
251
252
253
255
256 if (verbose_ > 1) {
257 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
258 << itr->first << ".";
259 }
260
261
262
263
264
265 std::map<int, int>::iterator itr_back =
266 hit_channel_map_.find(itr->first - 1);
267
268 bool has_backed = false;
269
270 if (itr_back !=
271 hit_channel_map_
272 .end()) {
273
274
275
276
277
278 has_used = false;
279 for (const auto &index : v_used_indices_) {
280 if (index == itr_back->first) {
281 if (verbose_ > 1) {
282 ldmx_log(warn) << "Attempting to re-use hit at channel "
283 << itr_back->first << "; skipping.";
284 }
285 has_used = true;
286 }
287 }
288 if (!has_used) {
290
291
292 addHit(itr_back->first, digi);
293 has_backed = true;
294
295 if (verbose_ > 1) {
296 ldmx_log(debug) << "Added -1 channel " << itr_back->first
297 <<
" to cluster; content " << digi.
getPE();
298 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
299 << itr->first << ".";
300 }
301
302 }
303 }
304
305
306
307
308
309
310
311
312
313
314 if (v_added_indices_.size() < max_width_) {
315
316
317 std::map<int, int>::iterator itr_neighb =
318 hit_channel_map_.find(itr->first + 1);
319 if (itr_neighb !=
320 hit_channel_map_
321 .end()) {
322
323
324
325 if (hit_channel_map_.find(itr_neighb->first + 1) !=
326 hit_channel_map_.end()) {
327
328 if (!has_backed) {
329
330
331
333 addHit(itr_neighb->first, digi);
334
335 if (verbose_ > 1) {
336 ldmx_log(debug)
337 << "No -1 hit. Added +1 channel " << itr_neighb->first
338 <<
" to cluster; content " << digi.
getPE();
339 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
340 << itr->first << ".";
341 }
342
343 if (v_added_indices_.size() < max_width_) {
344 if (hit_channel_map_.find(itr_neighb->first + 2) ==
345 hit_channel_map_
346 .end()) {
347
348 itr_neighb = hit_channel_map_.find(itr->first + 2);
350 addHit(itr_neighb->first, digi);
351 if (verbose_ > 1) {
352 ldmx_log(debug)
353 << "No +3 hit. Added +2 channel " << itr_neighb->first
354 <<
" to cluster; content " << digi.
getPE();
355 ldmx_log(debug)
356 << "\t itr is pointing at hit with channel nb "
357 << itr->first << ".";
358 }
359 }
360
361 }
362 }
363 }
364 else {
366 itr_neighb->second);
367
368 addHit(itr_neighb->first, digi);
369
370 if (verbose_ > 1) {
371 ldmx_log(debug)
372 << "Added +1 channel " << itr_neighb->first
373 <<
" as last channel to cluster; content " << digi.
getPE();
374 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
375 << itr->first << ".";
376 }
377 }
378 }
379
380
381
382 else if (has_backed &&
383 hit_channel_map_.find(itr_back->first - 1) !=
384 hit_channel_map_
385 .end()) {
386
387 itr_back = hit_channel_map_.find(itr->first - 2);
389 addHit(itr_back->first, digi);
390
391 if (verbose_ > 1) {
392 ldmx_log(debug) << "Added -2 channel " << itr_back->first
393 <<
" to cluster; content " << digi.
getPE();
394 }
395 if (verbose_ > 1) {
396 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
397 << itr->first << ".";
398 }
399
400 }
401
402 }
403
404
405 centroid_ /= val_;
406 centroid_ -= 1;
407
409
410 if (verbose_ > 1) {
411 ldmx_log(debug) << "Now have " << v_added_indices_.size()
412 << " hits in the cluster ";
413 }
414 cluster.
setSeed(v_added_indices_.at(0));
415 cluster.
setIDs(v_added_indices_);
416 cluster.
setNHits(v_added_indices_.size());
418 float cx;
419 float cy = centroid_;
420 float cz = -99999;
421
422 if (centroid_ < vert_bar_start_idx_) {
423
424 cx = -1;
425 }
426
427 else {
428 cx = (int)((centroid_ - vert_bar_start_idx_) / 4);
429 cy = (int)centroid_ % 4;
430 }
436
437 trig_scint_clusters.push_back(cluster);
438
439 ldmx_log(trace) << cluster;
440
441 centroid_ = 0;
442 centroid_x_ = -1;
443 centroid_y_ = -1;
444 val_ = 0;
445 val_e_ = 0;
446 beam_e_ = 0;
447 time_ = 0;
448
449 v_added_indices_.resize(0);
450
451 if (verbose_ > 1) {
452 ldmx_log(debug)
453 << "\t Finished processing of seeding hit with channel nb "
454 << itr->first << ".";
455 }
456
457 }
458
459 if (hit_channel_map_.begin() == hit_channel_map_.end()) {
460 if (verbose_)
461 ldmx_log(warn) << "Time flies, and all clusters have already been "
462 "removed! Interfering here to get out of the loop. ";
463 break;
464 }
465 }
466
467 if (trig_scint_clusters.size() > 0)
468 event.add(output_collection_, trig_scint_clusters);
469
470 hit_channel_map_.clear();
471
472 v_used_indices_.resize(0);
473
474 return;
475}
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 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