Belle II Software development
CDCTriggerTSFModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include "trg/cdc/modules/trgcdc/CDCTriggerTSFModule.h"
9
10#include <cdc/dataobjects/CDCSimHit.h>
11#include <cdc/dataobjects/CDCRawHit.h>
12#include <cdc/dataobjects/WireID.h>
13#include <mdst/dataobjects/MCParticle.h>
14
15#include <cdc/geometry/CDCGeometryPar.h>
16#include <trg/cdc/Layer.h>
17#include <trg/cdc/Wire.h>
18#include <trg/cdc/WireHit.h>
19#include <trg/cdc/Segment.h>
20#include <tracking/dataobjects/RecoTrack.h>
21
22#include <fstream>
23
24#define P3D HepGeom::Point3D<double>
25
26using namespace Belle2;
27
28//this line registers the module with the framework and actually makes it available
29//in steering files or the the module list (basf2 -m).
30REG_MODULE(CDCTriggerTSF);
31
33{
35 "The Track Segment Finder module of the CDC trigger.\n"
36 "Combines CDCHits from the same super layer to CDCTriggerSegmentHits.\n"
37 );
39 addParam("CDCHitCollectionName",
41 "Name of the input StoreArray of CDCHits.",
42 std::string("CDCHits4Trg"));
43 addParam("TSHitCollectionName",
45 "Name of the output StoreArray of CDCTriggerSegmentHits.",
46 std::string(""));
47 addParam("InnerTSLUTFile",
49 "The filename of LUT for track segments from the inner-most super layer",
50 std::string(""));
51 addParam("OuterTSLUTFile",
53 "The filename of LUT for track segments from the outer super layers",
54 std::string(""));
55 addParam("ClockSimulation",
57 "Switch to simulate each data clock cycle separately.",
58 false);
59 addParam("makeTrueLRTable",
61 "Switch to create a table of hit pattern <-> "
62 "number of true left / true right, which is needed to create the LUT",
63 false);
64 addParam("makeRecoLRTable",
65 m_makeRecoLRTable,
66 "Switch to create a table of hit pattern <-> "
67 "number of reconstructed left / true right, which is needed to create the LUT",
68 false);
69 addParam("innerTrueLRTableFilename",
71 "Filename for the true left/right table for the innermost super layer.",
72 std::string("innerTrueLRTable.dat"));
73 addParam("outerTrueLRTableFilename",
75 "Filename for the true left/right table for the outer super layers.",
76 std::string("outerTrueLRTable.dat"));
77 addParam("Deadchannel",
79 "Mask dead channels based on database. True:mask False:unmask",
80 true);
81 addParam("Crosstalk_tdcfilter",
83 "TDC based crosstalk filtering logic on CDCFE. True:enable False:disable",
84 false);
85 addParam("innerRecoLRTableFilename",
87 "Filename for the reconnstructed left/right table for the innermost super layer.",
88 std::string("innerRecoLRTable.dat"));
89 addParam("outerRecoLRTableFilename",
91 "Filename for the reconstructed left/right table for the outer super layers.",
92 std::string("outerRecoLRTable.dat"));
93 addParam("relateAllHits",
95 "Flag to relate all cdchits to the TrackSegment, not just the priority hits.",
96 true);
97 addParam("ADC_cut_enable",
99 "remove hits with lower ADC than cut threshold. True:enable False:disable",
100 false);
101 addParam("ADC_cut_threshold",
102 m_adccut,
103 "Threshold for the adc cut for all wires used for TSF. Default: -1",
104 -1);
105 addParam("SaveADC",
106 m_saveadc,
107 "Flag to save ADC for other trg module or not, Default: false",
108 false);
109 addParam("ADCflag_low",
111 "Assign ADC based flag for full hit tracker. Lower threshold of ADC.",
112 10);
113 addParam("ADCflag_high",
115 "Assign ADC based flag for full hit tracker. Higher threshold of ADC.",
116 10000);
117 addParam("useDB", m_useDB,
118 "Switch to use database to load run dependent parameters. ", true);
119}
120
121void
123{
124 // register DataStore elements
125 m_segmentHits.registerInDataStore(m_TSHitCollectionName);
127 if (m_makeTrueLRTable) {
128 StoreArray<CDCSimHit> simhits;
129 simhits.isRequired();
130 m_innerTrueLRTable.assign(pow(2, 16), std::vector<unsigned>(5, 0));
131 m_outerTrueLRTable.assign(pow(2, 12), std::vector<unsigned>(5, 0));
132 }
133 if (m_makeRecoLRTable) {
134 m_recoTracks.isRequired("RecoTracks");
135 m_cdcHits.isRequired();
136 m_innerRecoLRTable.assign(pow(2, 16), std::vector<unsigned>(5, 0));
137 m_outerRecoLRTable.assign(pow(2, 12), std::vector<unsigned>(5, 0));
138 }
139 // register relations
140 StoreArray<MCParticle> mcparticles;
141 m_segmentHits.registerRelationTo(m_cdcHits);
143 m_recoTracks.registerRelationTo(m_segmentHits);
144 m_recoTracks.registerRelationTo(m_cdcHits);
145 m_segmentHits.registerRelationTo(m_recoTracks);
146 // Prepare track segment shapes.
147 // First a structure of wires is created for all layers and super layers.
148 // Each track segment consists of pointers to wires in this structure.
150 const unsigned nLayers = cdc.nWireLayers();
151 TRGClock* clockTDC = new TRGClock("CDCTrigger TDC clock", 0, 500. / cdc.getTdcBinWidth());
152 TRGClock* clockData = new TRGClock("CDCTrigger data clock", *clockTDC, 1, 16);
153
154 //...Loop over layers...
155 int superLayerId = -1;
156 unsigned lastNWires = 0;
157 int lastShifts = -1000;
158 // separate counters for axial and stereo layers and super layers
159 int ia = -1;
160 int is = -1;
161 int ias = -1;
162 int iss = -1;
163 unsigned axialStereoLayerId;
164 unsigned axialStereoSuperLayerId = 0;
165 unsigned nWires = 0;
166 for (unsigned i = 0; i < nLayers; i++) {
167 if (i < cdc.getOffsetOfFirstLayer()) {
168 continue;
169 }
170 const unsigned nWiresInLayer = cdc.nWiresInLayer(i);
171
172 //...Axial or stereo?...
173 int nShifts = cdc.nShifts(i);
174 bool axial = (nShifts == 0);
175 if (axial) ++ia;
176 else ++is;
177 axialStereoLayerId = (axial) ? ia : is;
178
179 // Add empty TRGCDCLayer in case a superlayer is not present
180 if (m_superLayers.size() == 0 and cdc.getOffsetOfFirstSuperLayer() != 0) {
181 for (uint superLayerOffset = 0; superLayerOffset < cdc.getOffsetOfFirstSuperLayer(); superLayerOffset++) {
182 m_superLayers.push_back(std::vector<TRGCDCLayer*>());
183 superLayerId++;
184 }
185 }
186
187 //...Is this in a new super layer?...
188 if ((lastNWires != nWiresInLayer) || (lastShifts != nShifts)) {
189 ++superLayerId;
190 m_superLayers.push_back(std::vector<TRGCDCLayer*>());
191 if (axial) ++ias;
192 else ++iss;
193 axialStereoSuperLayerId = (axial) ? ias : iss;
194 lastNWires = nWiresInLayer;
195 lastShifts = nShifts;
196 }
197
198 //...Calculate radius of adjacent field wires...
199 const float swr = cdc.senseWireR(i);
200 const float innerRadius = cdc.fieldWireR(i - 1);
201 const float outerRadius = (i < nLayers - 1) ?
202 cdc.fieldWireR(i) :
203 swr + (swr - innerRadius);
204
205 //...New layer...
206 TRGCDCLayer* layer = new TRGCDCLayer(i,
207 superLayerId,
208 m_superLayers[superLayerId].size(),
209 axialStereoLayerId,
210 axialStereoSuperLayerId,
211 cdc.zOffsetWireLayer(i),
212 nShifts,
213 M_PI * swr * swr / nWiresInLayer,
214 nWiresInLayer,
215 innerRadius,
216 outerRadius);
217 m_superLayers.back().push_back(layer);
218
219 //...Loop over all wires in a layer...
220 for (unsigned j = 0; j < nWiresInLayer; j++) {
221 const P3D fp = P3D(cdc.wireForwardPosition(i, j).x(),
222 cdc.wireForwardPosition(i, j).y(),
223 cdc.wireForwardPosition(i, j).z());
224 const P3D bp = P3D(cdc.wireBackwardPosition(i, j).x(),
225 cdc.wireBackwardPosition(i, j).y(),
226 cdc.wireBackwardPosition(i, j).z());
227 TRGCDCWire* tw = new TRGCDCWire(nWires++, j, *layer, fp, bp, *clockTDC);
228 layer->push_back(tw);
229 }
230 }
231
232 //...Make TSF's...
233 const unsigned nWiresInTS[2] = {15, 11};
234 const int shape[2][30] = {
235 {
236 -2, 0, // relative layer id, relative wire id
237 -1, -1,
238 -1, 0,
239 0, -1,
240 0, 0,
241 0, 1,
242 1, -2,
243 1, -1,
244 1, 0,
245 1, 1,
246 2, -2,
247 2, -1,
248 2, 0,
249 2, 1,
250 2, 2
251 },
252 {
253 -2, -1,
254 -2, 0,
255 -2, 1,
256 -1, -1,
257 -1, 0,
258 0, 0,
259 1, -1,
260 1, 0,
261 2, -1,
262 2, 0,
263 2, 1,
264 0, 0,
265 0, 0,
266 0, 0,
267 0, 0
268 }
269 };
270 const int layerOffset[2] = {5, 2};
271 unsigned id = 0;
272 unsigned idTS = 0;
273 for (unsigned i = 0; i < m_superLayers.size(); i++) {
274 if (i < cdc.getOffsetOfFirstSuperLayer()) {
275 TRGCDCLayer* emptylayer = new TRGCDCLayer();
276 m_tsLayers.push_back(emptylayer);
277 continue;
278 }
279 unsigned tsType = (i) ? 1 : 0;
280
281 //...TS layer... w is a central wire
282 const TRGCDCCell* ww = m_superLayers[i][layerOffset[tsType]]->front();
283 TRGCDCLayer* layer = new TRGCDCLayer(id++, *ww);
284 m_tsLayers.push_back(layer);
285
286 //...Loop over all wires in a central wire layer...
287 const unsigned nWiresInLayer = ww->layer().nCells();
288 B2DEBUG(100, "SL " << i << " layerOffset " << layerOffset[tsType] << ", "
289 << m_superLayers[i].size() << " layers, " << nWiresInLayer << " wires");
290 for (unsigned j = 0; j < nWiresInLayer; j++) {
291 const TRGCDCWire& w =
292 (TRGCDCWire&) m_superLayers[i][layerOffset[tsType]]->cell(j);
293
294 const unsigned localId = w.localId();
295 const unsigned layerId = w.localLayerId();
296 std::vector<const TRGCDCWire*> cells;
297
298 B2DEBUG(110, "TS localId " << localId << " layerId " << layerId);
299
300 for (unsigned k = 0; k < nWiresInTS[tsType]; k++) {
301 const int laid = layerId + shape[tsType][k * 2];
302 const int loid = localId + shape[tsType][k * 2 + 1];
303
304 B2DEBUG(120, "cell localId " << loid << " layerId " << laid);
305
306 const TRGCDCWire& c =
307 (TRGCDCWire&) m_superLayers[i][laid]->cell(loid);
308
309 cells.push_back(&c);
310 }
311
312 TRGCDCSegment* ts;
313 if (w.superLayerId()) {
314 ts = new TRGCDCSegment(idTS++,
315 *layer,
316 w,
317 *clockData,
319 cells);
320 } else {
321 ts = new TRGCDCSegment(idTS++,
322 *layer,
323 w,
324 *clockData,
326 cells);
327 }
328 ts->initialize();
329 layer->push_back(ts);
330 }
331 }
332
333}
334
335void
337{
338 if (m_deadchflag) {
339 if (not m_db_deadchannel.isValid()) {
340 StoreObjPtr<EventMetaData> evtMetaData;
341 B2ERROR("No database for CDCTRG dead channel mapping. Channel masking is skipped. exp " << evtMetaData->getExperiment() << " run "
342 << evtMetaData->getRun());
343 for (unsigned int i = 0; i < c_nSuperLayers; i++) { //SL
344 for (unsigned int j = 0; j < MAX_N_LAYERS; j++) { //Layer
345 for (unsigned int k = 0; k < c_maxNDriftCells; k++) { //
346 m_deadChannelMap[i][j][k] = true;
347 }
348 }
349 }
350 } else {
351 for (unsigned int i = 0; i < c_nSuperLayers; i++) { //SL
352 for (unsigned int j = 0; j < MAX_N_LAYERS; j++) { //Layer
353 for (unsigned int k = 0; k < c_maxNDriftCells; k++) { //
354 m_deadChannelMap[i][j][k] = m_db_deadchannel->getdeadch(i, j, k);
355 }
356 }
357 }
358 }
359 }
360
361 if (m_useDB) {
362 if (not m_cdctrgtsf_DB.isValid()) {
363 StoreObjPtr<EventMetaData> evtMetaData;
364 B2FATAL("No database for CDCTRG TSF parameter. exp " << evtMetaData->getExperiment() << " run "
365 << evtMetaData->getRun());
366 } else {
367 m_adcflag = m_cdctrgtsf_DB->getuseADC();
368 m_adccut = m_cdctrgtsf_DB->getADC_threshold();
369 m_adcflag_low = m_cdctrgtsf_DB->getADC_threshold();
370 m_crosstalk_tdcfilter = m_cdctrgtsf_DB->getuseTDCfilter();
371 }
372 }
373}
374
375void
377{
379
380 // fill CDCHits into track segment shapes
381
382 //crosstalk filter
383 std::vector<int> filtered_hit(m_cdcHits.getEntries(), 0);
384
386 //check number of hits in each asic
387 int ncdchit_asic[500][6] = {{0}};
388 std::vector<int> id_ncdchit_asic[500][6];
389 for (int i = 0; i < m_cdcHits.getEntries(); ++i) {
390 UChar_t lay = m_cdcHits[i]->getICLayer();
391 UShort_t IWire = m_cdcHits[i]->getIWire();
392 WireID wireid(lay, IWire);
393 int boardid = cdc.getBoardID(wireid);
394 int fechid = cdc.getChannelID(wireid);
395 int asicid = fechid / 8;
396 if (boardid >= 0 && boardid < 500 && asicid >= 0 && asicid < 6) {
397 ncdchit_asic[boardid][asicid]++;
398 id_ncdchit_asic[boardid][asicid].push_back(i);
399 }
400 }
401 //check 16ns time coincidence if >=4 hits are found in the same asic
402 std::vector<short> tdc_asic;
403 for (int i = 0; i < 500; i++) {
404 for (int j = 0; j < 6; j++) {
405 if (ncdchit_asic[i][j] >= 4) {
406 tdc_asic.clear();
407 for (int k = 0; k < ncdchit_asic[i][j]; k++) {
408 short tdc = m_cdcHits[id_ncdchit_asic[i][j][k]]->getTDCCount();
409 tdc_asic.push_back(tdc);
410 }
411 std::sort(tdc_asic.begin(), tdc_asic.end());
412 for (int ncoin = ncdchit_asic[i][j]; ncoin >= 4; ncoin--) {
413 bool breakOuterLoop = false;
414 for (int k = 0; k < ncdchit_asic[i][j] - ncoin; k++) {
415 if (tdc_asic[k + ncoin - 1] - tdc_asic[k] <= 16) {
416 for (int l = k; l < k + ncoin - 1; l++) {
417 filtered_hit[id_ncdchit_asic[i][j][l]] = 1;
418 }
419 breakOuterLoop = true;
420 break;
421 }
422 }
423 if (breakOuterLoop)
424 break;
425 }
426 }
427 }
428 }
429 }
430
431 //...Loop over CDCHits...
432 for (int i = 0; i < m_cdcHits.getEntries(); ++i) {
433 // get the wire
434 const CDCHit& h = *m_cdcHits[i];
435 // mask dead channel
436 if (m_deadchflag) {
437 if (!m_deadChannelMap[h.getISuperLayer()][h.getILayer()][h.getIWire()]) {
438 continue;
439 }
440 }
441 // skim crosstalk hit
442 if (filtered_hit[i] == 1)continue;
443 // select fixed timing window
444 if (h.getTDCCount() < 4450 || h.getTDCCount() > 4950)continue;
445
446 // remove hits with low ADC
447 if (m_adcflag) {
448 if (h.getADCCount() < m_adccut)continue;
449 }
450
451 TRGCDCWire& w =
452 (TRGCDCWire&) m_superLayers[h.getISuperLayer()][h.getILayer()]->cell(h.getIWire());
453
454 // trigger timing signal
455 const int tdcCount = floor((cdc.getT0(WireID(h.getID())) / cdc.getTdcBinWidth()
456 - h.getTDCCount() + 0.5) / 2);
457 TRGTime rise = TRGTime(tdcCount, true, w.signal().clock(), w.name());
458 TRGTime fall = rise;
459 fall.shift(1).reverse();
460 TRGSignal signal = rise & fall;
461 w.addSignal(signal);
462
463 if (h.getADCCount() > m_adcflag_low && h.getADCCount() < m_adcflag_high) {
464 w.addSignal_adc(signal);
465 }
466
467 if (w.hit()) continue;
468 // make a trigger wire hit (needed for relations)
469 // all unneeded variables are set to 0 (TODO: remove them completely?)
470 TRGCDCWireHit* hit = new TRGCDCWireHit(w, i,
471 0, 0, 0, 0, 0, 0, 0, 0);
472 w.hit(hit);
473 }
474
475
476
477 // neighbor suppression
478 unsigned neibor_hit[10][1000] = {};
479 for (unsigned isl = 0; isl < m_tsLayers.size(); ++isl) {
480 for (unsigned its = 0; its < m_tsLayers[isl]->nCells(); ++its) {
481 TRGCDCSegment& s = (TRGCDCSegment&) m_tsLayers[isl]->cell(its);
482 // simulate with logicLUTFlag = true
483 // TODO: either add parameter or remove the option in Segment::simulate()
484 s.simulate(m_clockSimulation, true,
486 if (!m_clockSimulation && s.signal().active() && s.priorityPosition() == 3) {
487 neibor_hit[isl][its] = 1;
488 }
489 }
490 }
491
492 // simulate track segments and create track segment hits
493 for (unsigned isl = 0; isl < m_tsLayers.size(); ++isl) {
494 for (unsigned its = 0; its < m_tsLayers[isl]->nCells(); ++its) {
495 TRGCDCSegment& s = (TRGCDCSegment&) m_tsLayers[isl]->cell(its);
496 // simulate with logicLUTFlag = true
497 // TODO: either add parameter or remove the option in Segment::simulate()
498 s.simulate(m_clockSimulation, true,
500 // store hits and create relations
501 // for clock simulation already done in simulate
502 // TODO: move it to simulate also for simulateWithoutClock?
503 if (!m_clockSimulation && s.signal().active()) {
504
505 //neighbor suppression
506 if (s.priorityPosition() != 3 && (neibor_hit[isl][(its - 1) % m_tsLayers[isl]->nCells()] == 1
507 || neibor_hit[isl][(its + 1) % m_tsLayers[isl]->nCells()] == 1))continue;
508
509 const CDCHit* priorityHit = m_cdcHits[s.priority().hit()->iCDCHit()];
510
511 /* generate ADC Pattern for NN*/
512 std::vector<float> fullADC = {};
513 if (m_saveadc) {
514 int nwires = (isl == 0) ? 15 : 11;
515 fullADC.reserve(nwires + 1);
516 for (int iwire = 0; iwire < nwires; iwire++) {
517 if (!s[iwire] || !(s[iwire]->hit())) { //Make sure the wire do exist
518 fullADC.push_back(-1);
519 continue;
520 }
521 const CDCHit* cdchit0 = m_cdcHits[s[iwire]->hit()->iCDCHit()];
522 fullADC.push_back(cdchit0->getADCCount());
523 }
524 }
525 const CDCTriggerSegmentHit* tsHit =
526 m_segmentHits.appendNew(*priorityHit,
527 s.id(),
528 s.priorityPosition(),
529 s.LUT()->getValue(s.lutPattern()),
530 s.priorityTime(),
531 s.fastestTime(),
532 s.foundTime(),
533 -1,
534 s.hitPatternTime(),
535 s.hitPattern(),
536 fullADC,
537 s.hitPattern_adc());
538 unsigned short adcSum = 0;
539 // relation to all CDCHits in segment
540 for (unsigned iw = 0; iw < s.wires().size(); ++iw) {
541 const TRGCDCWire* wire = (TRGCDCWire*)s[iw];
542 if (wire->signal().active()) {
543 // priority wire has relation weight 2
544 double weight = (wire == &(s.priority())) ? 2. : 1.; // not sure if this is needed..
545 if (weight == 2. || m_relateAllHits) {
546 tsHit->addRelationTo(m_cdcHits[wire->hit()->iCDCHit()], weight);
547 adcSum += m_cdcHits[wire->hit()->iCDCHit()]->getADCCount();
548 }
549 }
550 }
551 // relation to MCParticles (same as priority hit)
553 for (unsigned imc = 0; imc < mcrel.size(); ++imc) {
554 mcrel[imc]->addRelationTo(tsHit, mcrel.weight(imc));
555 }
556 // get true left/right
557 if (m_makeTrueLRTable) {
558 const CDCSimHit* simHit = priorityHit->getRelatedFrom<CDCSimHit>();
559 if (simHit && !simHit->getBackgroundTag()) {
560 if (isl == 0) {
561 B2DEBUG(100, its << " creating entry in TrueLUT for pattern: " << s.lutPattern() << " : " << simHit->getLeftRightPassage());
562 m_innerTrueLRTable[s.lutPattern()][simHit->getLeftRightPassage()] += 1;
563 m_innerTrueLRTable[s.lutPattern()][3] += tsHit->priorityTime();
564 m_innerTrueLRTable[s.lutPattern()][4] += adcSum;
565 } else {
566 m_outerTrueLRTable[s.lutPattern()][simHit->getLeftRightPassage()] += 1;
567 m_outerTrueLRTable[s.lutPattern()][3] += tsHit->priorityTime();
568 m_outerTrueLRTable[s.lutPattern()][4] += adcSum;
569 B2DEBUG(100, its << " creating entry in TrueLUT for pattern: " << s.lutPattern() << " : " << simHit->getLeftRightPassage());
570 }
571 } else {
572 if (isl == 0) {
573 B2DEBUG(100, its << " creating bghit in TrueLUT for pattern: " << s.lutPattern());
574 m_innerTrueLRTable[s.lutPattern()][2] += 1;
575 m_innerTrueLRTable[s.lutPattern()][3] += tsHit->priorityTime();
576 m_innerTrueLRTable[s.lutPattern()][4] += adcSum;
577 } else {
578 B2DEBUG(100, its << " creating bghit in TrueLUT for pattern: " << s.lutPattern());
579 m_outerTrueLRTable[s.lutPattern()][2] += 1;
580 m_outerTrueLRTable[s.lutPattern()][3] += tsHit->priorityTime();
581 m_outerTrueLRTable[s.lutPattern()][4] += adcSum;
582 }
583 }
584 }
585
586 if (m_makeRecoLRTable) {
587 // for the recotable, we have no simhits and w can have more than one recotrack per event
588 // so we need to loop over them:
589 unsigned lrflag = 2; // see explanation below
590 for (int ireco = 0; ireco < m_recoTracks.getEntries(); ++ireco) {
591 // std::cout << "recotrack " << ireco << " of " << m_recoTracks.getEntries());
592 RecoTrack* recoTrack = m_recoTracks[ireco];
593 // since there is no relation between recotracks and the tshits yet, we need to create them first.
594 // within the recotrack class, there is a function which returns the hitids of the cdchits used
595 // in the recotrack. now we can loop over them and compare them with the id from the priorityhit:
596 // /
597 // Before looping over the recotracks, we set the rl information to 'bkg hit'. Then, we loop over all
598 // recotracks and determine if there is a relation and whether it passed left or right. If this is set for
599 // one recotrack, we set the rl information to the corresponding value. if it is set for another recotrack,
600 // we will also use this information for the recolrtable and set the corresponding value again.
601 // Just in the case, where after the loop over all recotracks it wasn't related to any of them, we will set
602 // the background flag in the recolrtable.
603 const std::vector<CDCHit*>& cdcHits = recoTrack->getCDCHitList();
604 bool related = false;
605 for (unsigned iHit = 0; iHit < cdcHits.size(); ++iHit) {
606//std::cout << "now looping over cdchits... " << iHit << "/" << cdcHits.size() << std::endl;
607 if (tsHit->getID() == cdcHits[iHit]->getID()) {
608 // check, whether recotrack is already related to ts, skip in this case.
609 // this is necessary because sometimes two wires are related to the same ts // dont get it, should be unnecessary
610 if (related == false) related = true;
611 else continue;
612// std::cout << "ts " << tsHit->getID() << " : creating relation to recotrack " << ireco;
613 // std::cout << tsHit->getID() << " " << cdcHits[iHit]->getID() << " " << iHit << " matching id of priohit and current cdchit, creating relation... " << std::endl;
614 recoTrack->addRelationTo(tsHit);
615 tsHit->addRelationTo(recoTrack);
616 if (isl == 0) {
617 // this getrightleftinformation function returns 2 for a right pass, and 3 for a left pass
618 if (recoTrack->getRightLeftInformation(cdcHits[iHit]) == 3) lrflag = 0;
619 if (recoTrack->getRightLeftInformation(cdcHits[iHit]) == 2) lrflag = 1;
620 m_innerRecoLRTable[s.lutPattern()][lrflag] += 1;
621 m_innerRecoLRTable[s.lutPattern()][3] += tsHit->priorityTime();
622 m_innerRecoLRTable[s.lutPattern()][4] += adcSum;
623 B2DEBUG(100, its << " creating entry in recoLUT for pattern: " << s.lutPattern() << " : " << lrflag << " (recotrack " << ireco <<
624 "), hit: " << iHit);
625 } else {
626 if (recoTrack->getRightLeftInformation(cdcHits[iHit]) == 3) lrflag = 0;
627 if (recoTrack->getRightLeftInformation(cdcHits[iHit]) == 2) lrflag = 1;
628 m_outerRecoLRTable[s.lutPattern()][lrflag] += 1;
629 m_outerRecoLRTable[s.lutPattern()][3] += tsHit->priorityTime();
630 m_outerRecoLRTable[s.lutPattern()][4] += adcSum;
631 B2DEBUG(100, its << " creating entry in recoLUT for pattern: " << s.lutPattern() << " : " << lrflag << " (recotrack " << ireco <<
632 "), hit: " << iHit);
633 }
634//std::cout << " , lrflag: " << lrflag << ", 0=left, 1=right";
635 //break;
636 }
637 }
638 }
639 if (lrflag == 2) {
640 if (isl == 0) {
641 B2DEBUG(100, its << " creating bghit in recoLUT for pattern: " << s.lutPattern());
642 m_innerRecoLRTable[s.lutPattern()][2] += 1;
643 m_innerRecoLRTable[s.lutPattern()][3] += tsHit->priorityTime();
644 m_innerRecoLRTable[s.lutPattern()][4] += adcSum;
645 } else {
646 B2DEBUG(100, its << " creating bghit in recoLUT for pattern: " << s.lutPattern());
647 m_outerRecoLRTable[s.lutPattern()][2] += 1;
648 m_outerRecoLRTable[s.lutPattern()][3] += tsHit->priorityTime();
649 m_outerRecoLRTable[s.lutPattern()][4] += adcSum;
650
651 }
652 //std::cout << " , lrflag: " << lrflag << ", 0=left, 1=right, 2=bg";
653 }
654 //std::cout << std::endl;
655 }
656 }
657 }
658 }
659
660 //...Clear hit information after we're finished...
661 clear();
662}
663
664void
666{
667 // delete wire layers
668 for (unsigned isl = 0; isl < m_superLayers.size(); ++isl) {
669 for (unsigned il = 0; il < m_superLayers[isl].size(); ++il) {
670 for (unsigned iw = 0; iw < m_superLayers[isl][il]->nCells(); ++iw) {
671 delete &(m_superLayers[isl][il]->cell(iw));
672 }
673 delete m_superLayers[isl][il];
674 }
675 m_superLayers[isl].clear();
676 }
677 m_superLayers.clear();
678
679 // delete TS layers
680 for (unsigned isl = 0; isl < m_tsLayers.size(); ++isl) {
681 for (unsigned its = 0; its < m_tsLayers[isl]->nCells(); ++its) {
682 delete &(m_tsLayers[isl]->cell(its));
683 }
684 delete m_tsLayers[isl];
685 }
686 m_tsLayers.clear();
687
688 // save true left/right table
689 if (m_makeTrueLRTable) {
690 std::ofstream innerFile(m_innerTrueLRTableFilename);
691 std::ostream_iterator<unsigned> innerIterator(innerFile, " ");
692 for (unsigned pattern = 0; pattern < m_innerTrueLRTable.size(); ++pattern) {
693 copy(m_innerTrueLRTable[pattern].begin(), m_innerTrueLRTable[pattern].end(),
694 innerIterator);
695 innerFile << "\n";
696 }
697 std::ofstream outerFile(m_outerTrueLRTableFilename);
698 std::ostream_iterator<unsigned> outerIterator(outerFile, " ");
699 for (unsigned pattern = 0; pattern < m_outerTrueLRTable.size(); ++pattern) {
700 copy(m_outerTrueLRTable[pattern].begin(), m_outerTrueLRTable[pattern].end(),
701 outerIterator);
702 outerFile << "\n";
703 }
704 }
705
706 // save reco left/right table
707 if (m_makeRecoLRTable) {
708 std::ofstream innerFile(m_innerRecoLRTableFilename);
709 std::ostream_iterator<unsigned> innerIterator(innerFile, " ");
710 for (unsigned pattern = 0; pattern < m_innerRecoLRTable.size(); ++pattern) {
711 copy(m_innerRecoLRTable[pattern].begin(), m_innerRecoLRTable[pattern].end(),
712 innerIterator);
713 innerFile << "\n";
714 }
715 std::ofstream outerFile(m_outerRecoLRTableFilename);
716 std::ostream_iterator<unsigned> outerIterator(outerFile, " ");
717 for (unsigned pattern = 0; pattern < m_outerRecoLRTable.size(); ++pattern) {
718 copy(m_outerRecoLRTable[pattern].begin(), m_outerRecoLRTable[pattern].end(),
719 outerIterator);
720 outerFile << "\n";
721 }
722 }
723}
724
725void
727{
729 for (unsigned isl = 0; isl < m_superLayers.size(); ++isl) {
730 if (isl < cdc.getOffsetOfFirstSuperLayer()) {
731 continue;
732 }
733 for (unsigned il = 0; il < m_superLayers[isl].size(); ++il) {
734 for (unsigned iw = 0; iw < m_superLayers[isl][il]->nCells(); ++iw) {
735 TRGCDCWire& w = (TRGCDCWire&) m_superLayers[isl][il]->cell(iw);
736 delete w.hit();
737 w.clear();
738 }
739 }
740 for (unsigned its = 0; its < m_tsLayers[isl]->nCells(); ++its) {
741 TRGCDCSegment& s = (TRGCDCSegment&) m_tsLayers[isl]->cell(its);
742 s.clear();
743 }
744 }
745
746}
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition CDCHit.h:40
unsigned short getADCCount() const
Getter for integrated charge.
Definition CDCHit.h:230
Example Detector.
Definition CDCSimHit.h:21
int getLeftRightPassage() const
The method to get new left/right info. for tracking.
Definition CDCSimHit.h:237
Combination of several CDCHits to a track segment hit for the trigger.
short priorityTime() const
get hit time of priority cell in trigger clocks
unsigned short getID() const
get the encoded wire number of the priority wire.
std::vector< std::vector< unsigned > > m_outerTrueLRTable
list of (# true right, # true left, # true background) for the outer super layers
std::vector< std::vector< TRGCDCLayer * > > m_superLayers
structure to hold pointers to all wires in the CDC
std::string m_outerRecoLRTableFilename
filename for the table which contains the number of reconstructed left/right for each pattern in the ...
bool m_relateAllHits
relate all cdchtis to ts, not just opriority wire
bool m_clockSimulation
switch for simulating clock by clock
bool m_deadChannelMap[c_nSuperLayers][MAX_N_LAYERS][c_maxNDriftCells]
bad channel mapping
std::string m_CDCHitCollectionName
name of the input StoreArray
std::string m_outerTrueLRTableFilename
filename for the table which contains the number of true left/right for each pattern in the outer sup...
CDCTriggerTSFModule()
Constructor, for setting module description and parameters.
bool m_crosstalk_tdcfilter
TDC based crosstalk filtering logic on CDCFE.
virtual void initialize() override
Initialize the module and register DataStore arrays.
std::string m_innerRecoLRTableFilename
filename for the table which contains the number of reconstructed left/right for each pattern in the ...
bool m_adcflag
remove hits with lower ADC than cut threshold.
virtual void event() override
Run the TSF for an event.
int m_adcflag_high
Assign ADC based flag for full hit tracker.
OptionalDBObjPtr< CDCTriggerDeadch > m_db_deadchannel
dbobject to store deadchannel
StoreArray< CDCTriggerSegmentHit > m_segmentHits
list of output track segment hits
bool m_saveadc
flag for saving adc information or not.
virtual void terminate() override
Clean up pointers.
std::vector< std::vector< unsigned > > m_innerTrueLRTable
list of (# true right, # true left, # true background) for the inner-most super layer
DBObjPtr< CDCTriggerTSFConfig > m_cdctrgtsf_DB
run dependent parameter database of TSF
std::string m_innerTSLUTFilename
The filename of LUT for the inner-most track segments.
std::vector< TRGCDCLayer * > m_tsLayers
structure to hold pointers to all track segment shapes
virtual void beginRun() override
Register run-dependent DataStore arrays.
int m_adcflag_low
Assign ADC based flag for full hit tracker.
int m_adccut
threshold for the adc cut.
bool m_makeTrueLRTable
switch for saving the number of true left/right for each pattern
std::string m_TSHitCollectionName
name of the output StoreArray
std::vector< std::vector< unsigned > > m_outerRecoLRTable
list of (# true right, # true left, # true background) for the outer super layers
static const int MAX_N_LAYERS
number of layers in Super layer
StoreArray< CDCHit > m_cdcHits
list of input CDC hits
StoreArray< RecoTrack > m_recoTracks
list of recotracks, needed for recolrtable
void clear()
remove hit information from last event
std::string m_outerTSLUTFilename
The filename of LUT for outer track segments.
std::vector< std::vector< unsigned > > m_innerRecoLRTable
list of (# reconstructed right, # reconstructed left, # unrelated background) for the inner-most supe...
std::string m_innerTrueLRTableFilename
filename for the table which contains the number of true left/right for each pattern in the inner-mos...
bool m_useDB
switch to use database to load run dependent parameter
bool m_deadchflag
mask Dead channel or not.
The Class for CDC Geometry Parameters.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
A Class to store the Monte Carlo particle information.
Definition MCParticle.h:32
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition Module.cc:208
Module()
Constructor.
Definition Module.cc:30
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition Module.h:80
This is the Reconstruction Event-Data Model Track.
Definition RecoTrack.h:79
std::vector< Belle2::RecoTrack::UsedCDCHit * > getCDCHitList() const
Return an unsorted list of cdc hits.
Definition RecoTrack.h:453
RightLeftInformation getRightLeftInformation(const HitType *hit) const
Return the right left information of a given hit (every type) or throws an exception of the hit is no...
Definition RecoTrack.h:337
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
float weight(int index) const
Get weight with index.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
RelationVector< FROM > getRelationsFrom(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from another store array to this object.
FROM * getRelatedFrom(const std::string &name="", const std::string &namedRelation="") const
Get the object from which this object has a relation.
virtual unsigned short getBackgroundTag() const
Get background tag.
Definition SimHitBase.h:46
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition StoreArray.h:140
Type-safe access to single objects in the data store.
Definition StoreObjPtr.h:96
A class to represent a wire in CDC.
Definition Cell.h:40
A class to represent a cell layer.
Definition Layer.h:33
A class to represent a wire in CDC.
Definition Segment.h:39
A class to represent a wire hit in CDC.
Definition WireHit.h:33
A class to represent a wire in CDC.
Definition Wire.h:56
A class to represent a digitized signal. Unit is nano second.
Definition Clock.h:38
A class to represent a digitized signal. Unit is nano second.
Definition Signal.h:23
A class to represent a signal timing in the trigger system.
Definition Time.h:25
Class to identify a wire inside the CDC.
Definition WireID.h:34
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:650
void addSignal(const TRGSignal &newSignal)
set signal |= newSignal
Definition Wire.h:169
const TRGClock & clock(void) const
returns clock.
Definition Signal.h:331
unsigned localLayerId(void) const
returns local layer id in a super layer.
Definition Cell.h:228
TRGTime & reverse(void)
reverse edge.
Definition Time.h:141
unsigned superLayerId(void) const
returns super layer id.
Definition Cell.h:221
const TRGSignal & signal(void) const override
returns an input to the trigger. This is sync'ed to 1GHz clock.
Definition Wire.h:242
TRGTime & shift(int unit)
delays by clock unit.
Definition Time.h:163
const TRGCDCWireHit * hit(void) const
returns a pointer to a TRGCDCWireHit.
Definition Wire.h:153
void initialize(void)
initialize variables.
Definition Segment.cc:62
std::string name(void) const override
returns name.
Definition Wire.cc:385
void clear(void) override
clears information.
Definition Wire.cc:370
unsigned iCDCHit(void) const
returns an index to CDCHit.
Definition CellHit.h:360
const TRGCDCLayer & layer(void) const
returns a pointer to a layer.
Definition Cell.h:235
bool active(void) const
returns true if there is a signal.
Definition Signal.h:277
unsigned nCells(void) const
returns # of cells.
Definition Layer.h:194
unsigned localId(void) const
returns local id in a layer.
Definition Cell.h:207
void addSignal_adc(const TRGSignal &newSignal)
set signal |= newSignal
Definition Wire.h:176
signed short IWire
The type of the wire ids enumerating wires within a given layer.
Definition IWire.h:20
Abstract base class for different kinds of events.