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