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