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