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)
93 << "TestBeamClusterProducer: produce() starts! Event number: "
94 << event.getEventHeader().getEventNumber();
95 }
96
97
98
100 input_collection_, passName_)};
101
102 if (verbose_) {
103 ldmx_log(debug) << "Got digi collection " << input_collection_ << "_"
104 << passName_ << " with " << digis.size() << " entries ";
105 }
106
107
108 bool doDuplicate = true;
109
110
111 auto iDigi{0};
112 for (const auto &digi : digis) {
113
114
115 ldmx_log(debug) << "Digi has PE count " << digi.getPE() << " and energy "
116 << digi.getEnergy();
117
118 if (
doCleanHits_ && digi.getQualityFlag() && digi.getQualityFlag() != 4) {
119
120 ldmx_log(debug) << "Skipping hit with non-zero quality flag "
121 << digi.getQualityFlag();
122 continue;
123 }
124
125 if (digi.getPE() >
126 minThr_) {
127
128
129 int ID = digi.getBarID();
130 if (ID >
131 maxChannelID_) {
132
133 ldmx_log(debug) << "Skipping channel with bar ID = " << ID << " > "
134 << maxChannelID_ << " (max instrumented nb)";
135 continue;
136 }
137
138
139
140 if (doDuplicate && hitChannelMap_.find((ID)) != hitChannelMap_.end()) {
141 int idx = ID;
142 std::map<int, int>::iterator itr = hitChannelMap_.find(idx);
143 double oldVal = digis.at(itr->second).getPE();
144 if (verbose_) {
145 ldmx_log(debug) << "Got duplicate digis for channel " << idx
146 << ", with already inserted value " << oldVal
147 << " and new " << digi.getPE();
148 }
149 if (digi.getPE() > oldVal) {
150 hitChannelMap_.erase(itr->first);
151 if (verbose_) {
152 ldmx_log(debug)
153 << "Skipped duplicate digi with smaller value for channel "
154 << idx;
155 }
156 }
157 }
158
159
160 if (digi.getTime() > padTime_ + timeTolerance_) continue;
161
162 hitChannelMap_.insert(std::pair<int, int>(ID, iDigi));
163
164
165 if (verbose_) {
166 ldmx_log(debug) << "Mapping digi hit nb " << iDigi
167 << " with energy = " << digi.getEnergy()
168 << " MeV, nPE = " << digi.getPE() << " > " << minThr_
169 << " to key/channel " << ID;
170 }
171 }
172 iDigi++;
173 }
174
175
176
177 std::map<int, int>::iterator itr;
178
179
180 std::vector<ldmx::TrigScintCluster> trigScintClusters;
181
182
183 for (itr = hitChannelMap_.begin(); itr != hitChannelMap_.end(); ++itr) {
184
185 if (hitChannelMap_.find(itr->first) == hitChannelMap_.end()) {
186 if (verbose_ > 1) {
187 ldmx_log(debug) << "Attempting to use removed hit at channel "
188 << itr->first << "; skipping.";
189 }
190 continue;
191 }
192
193
194
195
196
197 bool hasUsed = false;
198 for (const auto &index : v_usedIndices_) {
199 if (index == itr->first) {
200 if (verbose_ > 1) {
201 ldmx_log(warn) << "Attempting to re-use hit at channel " << itr->first
202 << "; skipping.";
203 }
204 hasUsed = true;
205 }
206 }
207 if (hasUsed) continue;
208 if (verbose_ > 1) {
209 ldmx_log(debug) << "\t At hit with channel nb " << itr->first << ".";
210 }
211
212 if (hitChannelMap_.size() ==
213 0)
214 {
215 if (verbose_)
216 ldmx_log(warn) << "Time flies, and all clusters have already been "
217 "removed! Unclear how we even got here; interfering "
218 "here to get out of the loop. ";
219 break;
220 }
221
223
224
225 if (digi.
getPE() >= seed_) {
226 if (verbose_ > 1) {
227 ldmx_log(debug) << "Seeding cluster with channel " << itr->first
228 <<
"; content " << digi.
getPE();
229 }
230
231
232
234
235 if (verbose_ > 1) {
236 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
237 << itr->first << ".";
238 }
239
240
241
242
243
244 std::map<int, int>::iterator itrBack =
245 hitChannelMap_.find(itr->first - 1);
246
247 bool hasBacked = false;
248
249 if (itrBack !=
250 hitChannelMap_.end()) {
251
252
253
254
255
256 hasUsed = false;
257 for (const auto &index : v_usedIndices_) {
258 if (index == itrBack->first) {
259 if (verbose_ > 1) {
260 ldmx_log(warn) << "Attempting to re-use hit at channel "
261 << itrBack->first << "; skipping.";
262 }
263 hasUsed = true;
264 }
265 }
266 if (!hasUsed) {
268
269
270 addHit(itrBack->first, digi);
271 hasBacked = true;
272
273 if (verbose_ > 1) {
274 ldmx_log(debug) << "Added -1 channel " << itrBack->first
275 <<
" to cluster; content " << digi.
getPE();
276 ldmx_log(debug) << "\t itr is pointing at hit with channel nb "
277 << itr->first << ".";
278 }
279
280 }
281 }
282
283
284
285
286
287
288
289
290
291
292 if (v_addedIndices_.size() < maxWidth_) {
293
294
295 std::map<int, int>::iterator itrNeighb =
296 hitChannelMap_.find(itr->first + 1);
297 if (itrNeighb !=
298 hitChannelMap_.end()) {
299
300
301
302 if (hitChannelMap_.find(itrNeighb->first + 1) !=
303 hitChannelMap_.end()) {
304
305 if (!hasBacked) {
306
307
308
310 addHit(itrNeighb->first, digi);
311
312 if (verbose_ > 1) {
313 ldmx_log(debug)
314 << "No -1 hit. Added +1 channel " << itrNeighb->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_addedIndices_.size() < maxWidth_) {
321 if (hitChannelMap_.find(itrNeighb->first + 2) ==
322 hitChannelMap_
323 .end()) {
324
325 itrNeighb = hitChannelMap_.find(itr->first + 2);
327 addHit(itrNeighb->first, digi);
328 if (verbose_ > 1) {
329 ldmx_log(debug)
330 << "No +3 hit. Added +2 channel " << itrNeighb->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 itrNeighb->second);
344
345 addHit(itrNeighb->first, digi);
346
347 if (verbose_ > 1) {
348 ldmx_log(debug)
349 << "Added +1 channel " << itrNeighb->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 (hasBacked &&
360 hitChannelMap_.find(itrBack->first - 1) !=
361 hitChannelMap_
362 .end()) {
363
364 itrBack = hitChannelMap_.find(itr->first - 2);
366 addHit(itrBack->first, digi);
367
368 if (verbose_ > 1) {
369 ldmx_log(debug) << "Added -2 channel " << itrBack->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_addedIndices_.size()
389 << " hits in the cluster ";
390 }
391 cluster.
setSeed(v_addedIndices_.at(0));
392 cluster.
setIDs(v_addedIndices_);
393 cluster.
setNHits(v_addedIndices_.size());
399
400 trigScintClusters.push_back(cluster);
401
402 if (verbose_) cluster.
Print();
403
404 centroid_ = 0;
405 val_ = 0;
406 valE_ = 0;
407 beamE_ = 0;
408 time_ = 0;
409 v_addedIndices_.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 (hitChannelMap_.begin() == hitChannelMap_.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 (trigScintClusters.size() > 0)
429 event.add(output_collection_, trigScintClusters);
430
431 hitChannelMap_.clear();
432 v_usedIndices_.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 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, 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).