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