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 if (verbose_) {
92 ldmx_log(debug) << "produce() starts! Event number: "
93 << event.getEventHeader().getEventNumber();
94 }
95
96
97
99 input_collection_, pass_name_)};
100
101 if (verbose_) {
102 ldmx_log(debug) << "Got digi collection " << input_collection_ << "_"
103 << pass_name_ << " with " << digis.size() << " entries ";
104 }
105
106
107 bool do_duplicate = true;
108
109
110 auto i_digi{0};
111 for (const auto &digi : digis) {
112
113
114 ldmx_log(debug) << "Digi has PE count " << digi.getPE() << " and energy "
115 << digi.getEnergy();
116
117 if (
do_clean_hits_ && digi.getQualityFlag() && digi.getQualityFlag() != 4) {
118
119 ldmx_log(debug) << "Skipping hit with non-zero quality flag "
120 << digi.getQualityFlag();
121 continue;
122 }
123
124
125 if (digi.getPE() > min_thr_) {
126 int id = digi.getBarID();
127 if (id > max_channel_id_) {
128
129
130 ldmx_log(debug) << "Skipping channel with bar ID = " << id << " > "
131 << max_channel_id_ << " (max instrumented nb)";
132 continue;
133 }
134
135
136
137 if (do_duplicate &&
138 hit_channel_map_.find((id)) != hit_channel_map_.end()) {
139 int idx = id;
140 std::map<int, int>::iterator itr = hit_channel_map_.find(idx);
141 double old_val = digis.at(itr->second).getPE();
142 if (verbose_) {
143 ldmx_log(debug) << "Got duplicate digis for channel " << idx
144 << ", with already inserted value " << old_val
145 << " and new " << digi.getPE();
146 }
147 if (digi.getPE() > old_val) {
148 hit_channel_map_.erase(itr->first);
149 if (verbose_) {
150 ldmx_log(debug)
151 << "Skipped duplicate digi with smaller value for channel "
152 << idx;
153 }
154 }
155 }
156
157
158 if (digi.getTime() > pad_time_ + time_tolerance_) continue;
159
160 hit_channel_map_.insert(std::pair<int, int>(id, i_digi));
161
162
163 if (verbose_) {
164 ldmx_log(debug) << "Mapping digi hit nb " << i_digi
165 << " with energy = " << digi.getEnergy()
166 << " MeV, nPE = " << digi.getPE() << " > " << min_thr_
167 << " to key/channel " << id;
168 }
169 }
170 i_digi++;
171 }
172
173
174
175 std::map<int, int>::iterator itr;
176
177
178 std::vector<ldmx::TrigScintCluster> trig_scint_clusters;
179
180
181 for (itr = hit_channel_map_.begin(); itr != hit_channel_map_.end(); ++itr) {
182
183 if (hit_channel_map_.find(itr->first) == hit_channel_map_.end()) {
184 if (verbose_ > 1) {
185 ldmx_log(debug) << "Attempting to use removed hit at channel "
186 << itr->first << "; skipping.";
187 }
188 continue;
189 }
190
191
192
193
194
195 bool has_used = false;
196 for (const auto &index : v_used_indices_) {
197 if (index == itr->first) {
198 if (verbose_ > 1) {
199 ldmx_log(warn) << "Attempting to re-use hit at channel " << itr->first
200 << "; skipping.";
201 }
202 has_used = true;
203 }
204 }
205 if (has_used) continue;
206 if (verbose_ > 1) {
207 ldmx_log(debug) << "\t At hit with channel nb " << itr->first << ".";
208 }
209
210 if (hit_channel_map_.size() ==
211 0)
212 {
213 if (verbose_)
214 ldmx_log(warn) << "Time flies, and all clusters have already been "
215 "removed! Unclear how we even got here; interfering "
216 "here to get out of the loop. ";
217 break;
218 }
219
221
222
223 if (digi.
getPE() >= seed_) {
224 if (verbose_ > 1) {
225 ldmx_log(debug) << "Seeding cluster with channel " << itr->first
226 <<
"; content " << digi.
getPE();
227 }
228
229
230
232
233 if (verbose_ > 1) {
234 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
235 << itr->first << ".";
236 }
237
238
239
240
241
242 std::map<int, int>::iterator itr_back =
243 hit_channel_map_.find(itr->first - 1);
244
245 bool has_backed = false;
246
247 if (itr_back !=
248 hit_channel_map_
249 .end()) {
250
251
252
253
254
255 has_used = false;
256 for (const auto &index : v_used_indices_) {
257 if (index == itr_back->first) {
258 if (verbose_ > 1) {
259 ldmx_log(warn) << "Attempting to re-use hit at channel "
260 << itr_back->first << "; skipping.";
261 }
262 has_used = true;
263 }
264 }
265 if (!has_used) {
267
268
269 addHit(itr_back->first, digi);
270 has_backed = true;
271
272 if (verbose_ > 1) {
273 ldmx_log(debug) << "Added -1 channel " << itr_back->first
274 <<
" to cluster; content " << digi.
getPE();
275 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
276 << itr->first << ".";
277 }
278
279 }
280 }
281
282
283
284
285
286
287
288
289
290
291 if (v_added_indices_.size() < max_width_) {
292
293
294 std::map<int, int>::iterator itr_neighb =
295 hit_channel_map_.find(itr->first + 1);
296 if (itr_neighb !=
297 hit_channel_map_
298 .end()) {
299
300
301
302 if (hit_channel_map_.find(itr_neighb->first + 1) !=
303 hit_channel_map_.end()) {
304
305 if (!has_backed) {
306
307
308
310 addHit(itr_neighb->first, digi);
311
312 if (verbose_ > 1) {
313 ldmx_log(debug)
314 << "No -1 hit. Added +1 channel " << itr_neighb->first
315 <<
" to cluster; content " << digi.
getPE();
316 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
317 << itr->first << ".";
318 }
319
320 if (v_added_indices_.size() < max_width_) {
321 if (hit_channel_map_.find(itr_neighb->first + 2) ==
322 hit_channel_map_
323 .end()) {
324
325 itr_neighb = hit_channel_map_.find(itr->first + 2);
327 addHit(itr_neighb->first, digi);
328 if (verbose_ > 1) {
329 ldmx_log(debug)
330 << "No +3 hit. Added +2 channel " << itr_neighb->first
331 <<
" to cluster; content " << digi.
getPE();
332 ldmx_log(debug)
333 << "\t itr is pointing at hit with channel nb "
334 << itr->first << ".";
335 }
336 }
337
338 }
339 }
340 }
341 else {
343 itr_neighb->second);
344
345 addHit(itr_neighb->first, digi);
346
347 if (verbose_ > 1) {
348 ldmx_log(debug)
349 << "Added +1 channel " << itr_neighb->first
350 <<
" as last channel to cluster; content " << digi.
getPE();
351 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
352 << itr->first << ".";
353 }
354 }
355 }
356
357
358
359 else if (has_backed &&
360 hit_channel_map_.find(itr_back->first - 1) !=
361 hit_channel_map_
362 .end()) {
363
364 itr_back = hit_channel_map_.find(itr->first - 2);
366 addHit(itr_back->first, digi);
367
368 if (verbose_ > 1) {
369 ldmx_log(debug) << "Added -2 channel " << itr_back->first
370 <<
" to cluster; content " << digi.
getPE();
371 }
372 if (verbose_ > 1) {
373 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
374 << itr->first << ".";
375 }
376
377 }
378
379 }
380
381
382 centroid_ /= val_;
383 centroid_ -= 1;
384
386
387 if (verbose_ > 1) {
388 ldmx_log(debug) << "Now have " << v_added_indices_.size()
389 << " hits in the cluster ";
390 }
391 cluster.
setSeed(v_added_indices_.at(0));
392 cluster.
setIDs(v_added_indices_);
393 cluster.
setNHits(v_added_indices_.size());
399
400 trig_scint_clusters.push_back(cluster);
401
402 ldmx_log(trace) << cluster;
403
404 centroid_ = 0;
405 val_ = 0;
406 val_e_ = 0;
407 beam_e_ = 0;
408 time_ = 0;
409 v_added_indices_.resize(
410 0);
411
412 if (verbose_ > 1) {
413 ldmx_log(debug)
414 << "\t Finished processing of seeding hit with channel nb "
415 << itr->first << ".";
416 }
417
418 }
419
420 if (hit_channel_map_.begin() == hit_channel_map_.end()) {
421 if (verbose_)
422 ldmx_log(warn) << "Time flies, and all clusters have already been "
423 "removed! Interfering here to get out of the loop. ";
424 break;
425 }
426 }
427
428 if (trig_scint_clusters.size() > 0)
429 event.add(output_collection_, trig_scint_clusters);
430
431 hit_channel_map_.clear();
432 v_used_indices_.resize(
433 0);
434
435 return;
436}
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 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, trigscint::TestBeamHit hit)
add a hit at index idx to a cluster
This class represents the linearised QIE output from the trigger scintillator, in charge (fC).