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 std;
27using namespace Belle2;
28
29//this line registers the module with the framework and actually makes it available
30//in steering files or the the module list (basf2 -m).
31REG_MODULE(CDCTriggerTSF);
32
34{
36 "The Track Segment Finder module of the CDC trigger.\n"
37 "Combines CDCHits from the same super layer to CDCTriggerSegmentHits.\n"
38 );
40 addParam("CDCHitCollectionName",
42 "Name of the input StoreArray of CDCHits.",
43 string("CDCHits4Trg"));
44 addParam("TSHitCollectionName",
46 "Name of the output StoreArray of CDCTriggerSegmentHits.",
47 string(""));
48 addParam("InnerTSLUTFile",
50 "The filename of LUT for track segments from the inner-most super layer",
51 string(""));
52 addParam("OuterTSLUTFile",
54 "The filename of LUT for track segments from the outer super layers",
55 string(""));
56 addParam("ClockSimulation",
58 "Switch to simulate each data clock cycle separately.",
59 false);
60 addParam("makeTrueLRTable",
62 "Switch to create a table of hit pattern <-> "
63 "number of true left / true right, which is needed to create the LUT",
64 false);
65 addParam("makeRecoLRTable",
66 m_makeRecoLRTable,
67 "Switch to create a table of hit pattern <-> "
68 "number of reconstructed left / true right, which is needed to create the LUT",
69 false);
70 addParam("innerTrueLRTableFilename",
72 "Filename for the true left/right table for the innermost super layer.",
73 string("innerTrueLRTable.dat"));
74 addParam("outerTrueLRTableFilename",
76 "Filename for the true left/right table for the outer super layers.",
77 string("outerTrueLRTable.dat"));
78 addParam("Deadchannel",
80 "Mask dead channels based on database. True:mask False:unmask",
81 true);
82 addParam("Crosstalk_tdcfilter",
84 "TDC based crosstalk filtering logic on CDCFE. True:enable False:disable",
85 false);
86 addParam("innerRecoLRTableFilename",
88 "Filename for the reconnstructed left/right table for the innermost super layer.",
89 string("innerRecoLRTable.dat"));
90 addParam("outerRecoLRTableFilename",
92 "Filename for the reconstructed left/right table for the outer super layers.",
93 string("outerRecoLRTable.dat"));
94 addParam("relateAllHits",
96 "Flag to relate all cdchits to the TrackSegment, not just the priority hits.",
97 true);
98 addParam("ADC_cut_enable",
100 "remove hits with lower ADC than cut threshold. True:enable False:disable",
101 false);
102 addParam("ADC_cut_threshold",
103 m_adccut,
104 "Threshold for the adc cut for all wires used for TSF. Default: -1",
105 -1);
106 addParam("ADCflag_low",
108 "Assign ADC based flag for full hit tracker. Lower threshold of ADC.",
109 10);
110 addParam("ADCflag_high",
112 "Assign ADC based flag for full hit tracker. Higher threshold of ADC.",
113 700);
114}
115
116void
118{
119 // register DataStore elements
122 if (m_makeTrueLRTable) {
123 StoreArray<CDCSimHit> simhits;
124 simhits.isRequired();
125 innerTrueLRTable.assign(pow(2, 16), vector<unsigned>(5, 0));
126 outerTrueLRTable.assign(pow(2, 12), vector<unsigned>(5, 0));
127 }
128 if (m_makeRecoLRTable) {
129 m_recoTracks.isRequired("RecoTracks");
130 innerRecoLRTable.assign(pow(2, 16), vector<unsigned>(5, 0));
131 outerRecoLRTable.assign(pow(2, 12), vector<unsigned>(5, 0));
132 }
133 // register relations
134 StoreArray<MCParticle> mcparticles;
140 // Prepare track segment shapes.
141 // First a structure of wires is created for all layers and super layers.
142 // Each track segment consists of pointers to wires in this structure.
144 const unsigned nLayers = cdc.nWireLayers();
145 TRGClock* clockTDC = new TRGClock("CDCTrigger TDC clock", 0, 500. / cdc.getTdcBinWidth());
146 TRGClock* clockData = new TRGClock("CDCTrigger data clock", *clockTDC, 1, 16);
147 clocks.push_back(clockTDC);
148 clocks.push_back(clockData);
149
150 //...Loop over layers...
151 int superLayerId = -1;
152 unsigned lastNWires = 0;
153 int lastShifts = -1000;
154 // separate counters for axial and stereo layers and super layers
155 int ia = -1;
156 int is = -1;
157 int ias = -1;
158 int iss = -1;
159 unsigned axialStereoLayerId;
160 unsigned axialStereoSuperLayerId = 0;
161 unsigned nWires = 0;
162 for (unsigned i = 0; i < nLayers; i++) {
163 if (i < cdc.getOffsetOfFirstLayer()) {
164 continue;
165 }
166 const unsigned nWiresInLayer = cdc.nWiresInLayer(i);
167
168 //...Axial or stereo?...
169 int nShifts = cdc.nShifts(i);
170 bool axial = (nShifts == 0);
171 if (axial) ++ia;
172 else ++is;
173 axialStereoLayerId = (axial) ? ia : is;
174
175 // Add empty TRGCDCLayer in case a superlayer is not present
176 if (superLayers.size() == 0 and cdc.getOffsetOfFirstSuperLayer() != 0) {
177 for (uint superLayerOffset = 0; superLayerOffset < cdc.getOffsetOfFirstSuperLayer(); superLayerOffset++) {
178 superLayers.push_back(vector<TRGCDCLayer*>());
179 superLayerId++;
180 }
181 }
182
183 //...Is this in a new super layer?...
184 if ((lastNWires != nWiresInLayer) || (lastShifts != nShifts)) {
185 ++superLayerId;
186 superLayers.push_back(vector<TRGCDCLayer*>());
187 if (axial) ++ias;
188 else ++iss;
189 axialStereoSuperLayerId = (axial) ? ias : iss;
190 lastNWires = nWiresInLayer;
191 lastShifts = nShifts;
192 }
193
194 //...Calculate radius of adjacent field wires...
195 const float swr = cdc.senseWireR(i);
196 const float innerRadius = cdc.fieldWireR(i - 1);
197 const float outerRadius = (i < nLayers - 1) ?
198 cdc.fieldWireR(i) :
199 swr + (swr - innerRadius);
200
201 //...New layer...
202 TRGCDCLayer* layer = new TRGCDCLayer(i,
203 superLayerId,
204 superLayers[superLayerId].size(),
205 axialStereoLayerId,
206 axialStereoSuperLayerId,
207 cdc.zOffsetWireLayer(i),
208 nShifts,
209 M_PI * swr * swr / nWiresInLayer,
210 nWiresInLayer,
211 innerRadius,
212 outerRadius);
213 superLayers.back().push_back(layer);
214
215 //...Loop over all wires in a layer...
216 for (unsigned j = 0; j < nWiresInLayer; j++) {
217 const P3D fp = P3D(cdc.wireForwardPosition(i, j).x(),
218 cdc.wireForwardPosition(i, j).y(),
219 cdc.wireForwardPosition(i, j).z());
220 const P3D bp = P3D(cdc.wireBackwardPosition(i, j).x(),
221 cdc.wireBackwardPosition(i, j).y(),
222 cdc.wireBackwardPosition(i, j).z());
223 TRGCDCWire* tw = new TRGCDCWire(nWires++, j, *layer, fp, bp, *clockTDC);
224 layer->push_back(tw);
225 }
226 }
227
228 //...Make TSF's...
229 const unsigned nWiresInTS[2] = {15, 11};
230 const int shape[2][30] = {
231 {
232 -2, 0, // relative layer id, relative wire id
233 -1, -1,
234 -1, 0,
235 0, -1,
236 0, 0,
237 0, 1,
238 1, -2,
239 1, -1,
240 1, 0,
241 1, 1,
242 2, -2,
243 2, -1,
244 2, 0,
245 2, 1,
246 2, 2
247 },
248 {
249 -2, -1,
250 -2, 0,
251 -2, 1,
252 -1, -1,
253 -1, 0,
254 0, 0,
255 1, -1,
256 1, 0,
257 2, -1,
258 2, 0,
259 2, 1,
260 0, 0,
261 0, 0,
262 0, 0,
263 0, 0
264 }
265 };
266 const int layerOffset[2] = {5, 2};
267 unsigned id = 0;
268 unsigned idTS = 0;
269 for (unsigned i = 0; i < superLayers.size(); i++) {
270 if (i < cdc.getOffsetOfFirstSuperLayer()) {
271 TRGCDCLayer* emptylayer = new TRGCDCLayer();
272 tsLayers.push_back(emptylayer);
273 continue;
274 }
275 unsigned tsType = (i) ? 1 : 0;
276
277 //...TS layer... w is a central wire
278 const TRGCDCCell* ww = superLayers[i][layerOffset[tsType]]->front();
279 TRGCDCLayer* layer = new TRGCDCLayer(id++, *ww);
280 tsLayers.push_back(layer);
281
282 //...Loop over all wires in a central wire layer...
283 const unsigned nWiresInLayer = ww->layer().nCells();
284 B2DEBUG(100, "SL " << i << " layerOffset " << layerOffset[tsType] << ", "
285 << superLayers[i].size() << " layers, " << nWiresInLayer << " wires");
286 for (unsigned j = 0; j < nWiresInLayer; j++) {
287 const TRGCDCWire& w =
288 (TRGCDCWire&) superLayers[i][layerOffset[tsType]]->cell(j);
289
290 const unsigned localId = w.localId();
291 const unsigned layerId = w.localLayerId();
292 vector<const TRGCDCWire*> cells;
293
294 B2DEBUG(110, "TS localId " << localId << " layerId " << layerId);
295
296 for (unsigned k = 0; k < nWiresInTS[tsType]; k++) {
297 const int laid = layerId + shape[tsType][k * 2];
298 const int loid = localId + shape[tsType][k * 2 + 1];
299
300 B2DEBUG(120, "cell localId " << loid << " layerId " << laid);
301
302 const TRGCDCWire& c =
303 (TRGCDCWire&) superLayers[i][laid]->cell(loid);
304
305 cells.push_back(&c);
306 }
307
308 TRGCDCSegment* ts;
309 if (w.superLayerId()) {
310 ts = new TRGCDCSegment(idTS++,
311 *layer,
312 w,
313 *clockData,
315 cells);
316 } else {
317 ts = new TRGCDCSegment(idTS++,
318 *layer,
319 w,
320 *clockData,
322 cells);
323 }
324 ts->initialize();
325 layer->push_back(ts);
326 }
327 }
328
329}
330
331void
333{
334 if (m_deadchflag) {
335 if (not m_db_deadchannel.isValid()) {
336 StoreObjPtr<EventMetaData> evtMetaData;
337 B2ERROR("No database for CDCTRG dead channel mapping. Channel masking is skipped. exp " << evtMetaData->getExperiment() << " run "
338 << evtMetaData->getRun());
339 for (unsigned int i = 0; i < c_nSuperLayers; i++) { //SL
340 for (unsigned int j = 0; j < MAX_N_LAYERS; j++) { //Layer
341 for (unsigned int k = 0; k < c_maxNDriftCells; k++) { //
342 deadch_map[i][j][k] = true;
343 }
344 }
345 }
346 } else {
347 for (unsigned int i = 0; i < c_nSuperLayers; i++) { //SL
348 for (unsigned int j = 0; j < MAX_N_LAYERS; j++) { //Layer
349 for (unsigned int k = 0; k < c_maxNDriftCells; k++) { //
350 deadch_map[i][j][k] = m_db_deadchannel->getdeadch(i, j, k);
351 }
352 }
353 }
354 }
355 }
356}
357
358void
360{
362
363 // fill CDCHits into track segment shapes
364
365 //crosstalk filter
366 vector<int> filtered_hit;
367 for (int i = 0; i < m_cdcHits.getEntries(); ++i) {
368 filtered_hit.push_back(0);
369 }
370
372 //check number of hits in each asic
373 int ncdchit_asic[500][6] = {{0}};
374 vector<int> id_ncdchit_asic[500][6];
375 for (int i = 0; i < m_cdcHits.getEntries(); ++i) {
376 UChar_t lay = m_cdcHits[i]->getICLayer();
377 UShort_t IWire = m_cdcHits[i]->getIWire();
378 WireID wireid(lay, IWire);
379 int boardid = cdc.getBoardID(wireid);
380 int fechid = cdc.getChannelID(wireid);
381 int asicid = fechid / 8;
382 if (boardid >= 0 && boardid < 500 && asicid >= 0 && asicid < 6) {
383 ncdchit_asic[boardid][asicid]++;
384 id_ncdchit_asic[boardid][asicid].push_back(i);
385 }
386 }
387 //check 16ns time coinsidence if >=4 hits are found in the same asic
388 for (int i = 0; i < 500; i++) {
389 for (int j = 0; j < 6; j++) {
390 if (ncdchit_asic[i][j] >= 4) {
391 std::vector<short> tdc_asic;
392 for (int k = 0; k < ncdchit_asic[i][j]; k++) {
393 short tdc = m_cdcHits[id_ncdchit_asic[i][j][k]]->getTDCCount();
394 tdc_asic.push_back(tdc);
395 }
396 std::sort(tdc_asic.begin(), tdc_asic.end());
397 for (int ncoin = ncdchit_asic[i][j]; ncoin >= 4; ncoin--) {
398 bool breakOuterLoop = false;
399 for (int k = 0; k < ncdchit_asic[i][j] - ncoin; k++) {
400 if (tdc_asic[k + ncoin - 1] - tdc_asic[k] <= 16) {
401 for (int l = k; l < k + ncoin - 1; l++) {
402 filtered_hit[id_ncdchit_asic[i][j][l]] = 1;
403 }
404 breakOuterLoop = true;
405 break;
406 }
407 }
408 if (breakOuterLoop)
409 break;
410 }
411 tdc_asic.clear();
412 }
413 }
414 }
415 }
416
417 //...Loop over CDCHits...
418 for (int i = 0; i < m_cdcHits.getEntries(); ++i) {
419 // get the wire
420 const CDCHit& h = *m_cdcHits[i];
421 // mask dead channel
422 if (m_deadchflag) {
423 if (!deadch_map[h.getISuperLayer()][h.getILayer()][h.getIWire()]) {
424 continue;
425 }
426 }
427 // skim crosstalk hit
428 if (filtered_hit[i] == 1)continue;
429 // select fixed timing window
430 if (h.getTDCCount() < 4450 || h.getTDCCount() > 4950)continue;
431
432 // remove hits with low ADC
433 if (m_adcflag) {
434 if (h.getADCCount() < m_adccut)continue;
435 }
436
437 TRGCDCWire& w =
438 (TRGCDCWire&) superLayers[h.getISuperLayer()][h.getILayer()]->cell(h.getIWire());
439
440 // trigger timing signal
441 const int tdcCount = floor((cdc.getT0(WireID(h.getID())) / cdc.getTdcBinWidth()
442 - h.getTDCCount() + 0.5) / 2);
443 TRGTime rise = TRGTime(tdcCount, true, w.signal().clock(), w.name());
444 TRGTime fall = rise;
445 fall.shift(1).reverse();
446 TRGSignal signal = rise & fall;
447 w.addSignal(signal);
448
449 if (h.getADCCount() > m_adcflag_low && h.getADCCount() < m_adcflag_high) {
450 w.addSignal_adc(signal);
451 }
452
453 if (w.hit()) continue;
454 // make a trigger wire hit (needed for relations)
455 // all unneeded variables are set to 0 (TODO: remove them completely?)
456 TRGCDCWireHit* hit = new TRGCDCWireHit(w, i,
457 0, 0, 0, 0, 0, 0, 0, 0);
458 w.hit(hit);
459 }
460
461
462
463 // neibor supression
464 unsigned neibor_hit[10][1000] = {};
465 for (unsigned isl = 0; isl < tsLayers.size(); ++isl) {
466 for (unsigned its = 0; its < tsLayers[isl]->nCells(); ++its) {
467 TRGCDCSegment& s = (TRGCDCSegment&) tsLayers[isl]->cell(its);
468 // simulate with logicLUTFlag = true
469 // TODO: either add parameter or remove the option in Segment::simulate()
470 s.simulate(m_clockSimulation, true,
472 if (!m_clockSimulation && s.signal().active() && s.priorityPosition() == 3) {
473 neibor_hit[isl][its] = 1;
474 }
475 }
476 }
477
478 // simulate track segments and create track segment hits
479 for (unsigned isl = 0; isl < tsLayers.size(); ++isl) {
480 for (unsigned its = 0; its < tsLayers[isl]->nCells(); ++its) {
481 TRGCDCSegment& s = (TRGCDCSegment&) 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 // store hits and create relations
487 // for clock simulation already done in simulate
488 // TODO: move it to simulate also for simulateWithoutClock?
489 if (!m_clockSimulation && s.signal().active()) {
490
491 //neibor supression
492 if (s.priorityPosition() != 3 && (neibor_hit[isl][(its - 1) % tsLayers[isl]->nCells()] == 1
493 || neibor_hit[isl][(its + 1) % tsLayers[isl]->nCells()] == 1))continue;
494
495 const CDCHit* priorityHit = m_cdcHits[s.priority().hit()->iCDCHit()];
496 const CDCTriggerSegmentHit* tsHit =
497 m_segmentHits.appendNew(*priorityHit,
498 s.id(),
499 s.priorityPosition(),
500 s.LUT()->getValue(s.lutPattern()),
501 s.priorityTime(),
502 s.fastestTime(),
503 s.foundTime(),
504 -1,
505 s.hitPattern(),
506 s.hitPattern_adc());
507 float adcSum = 0;
508 // relation to all CDCHits in segment
509 for (unsigned iw = 0; iw < s.wires().size(); ++iw) {
510 const TRGCDCWire* wire = (TRGCDCWire*)s[iw];
511 if (wire->signal().active()) {
512 // priority wire has relation weight 2
513 double weight = (wire == &(s.priority())) ? 2. : 1.; // not sure if this is needed..
514 if (weight == 2. || m_relateAllHits) {
515 tsHit->addRelationTo(m_cdcHits[wire->hit()->iCDCHit()], weight);
516 adcSum += m_cdcHits[wire->hit()->iCDCHit()]->getADCCount();
517 }
518 }
519 }
520 // relation to MCParticles (same as priority hit)
522 for (unsigned imc = 0; imc < mcrel.size(); ++imc) {
523 mcrel[imc]->addRelationTo(tsHit, mcrel.weight(imc));
524 }
525 // get true left/right
526 if (m_makeTrueLRTable) {
527 const CDCSimHit* simHit = priorityHit->getRelatedFrom<CDCSimHit>();
528 if (simHit && !simHit->getBackgroundTag()) {
529 if (isl == 0) {
530 B2DEBUG(100, its << " creating entry in TrueLUT for pattern: " << s.lutPattern() << " : " << simHit->getLeftRightPassage());
531 innerTrueLRTable[s.lutPattern()][simHit->getLeftRightPassage()] += 1;
532 innerTrueLRTable[s.lutPattern()][3] += tsHit->priorityTime();
533 innerTrueLRTable[s.lutPattern()][4] += adcSum;
534 } else {
535 outerTrueLRTable[s.lutPattern()][simHit->getLeftRightPassage()] += 1;
536 outerTrueLRTable[s.lutPattern()][3] += tsHit->priorityTime();
537 outerTrueLRTable[s.lutPattern()][4] += adcSum;
538 B2DEBUG(100, its << " creating entry in TrueLUT for pattern: " << s.lutPattern() << " : " << simHit->getLeftRightPassage());
539 }
540 } else {
541 if (isl == 0) {
542 B2DEBUG(100, its << " creating bghit in TrueLUT for pattern: " << s.lutPattern());
543 innerTrueLRTable[s.lutPattern()][2] += 1;
544 innerTrueLRTable[s.lutPattern()][3] += tsHit->priorityTime();
545 innerTrueLRTable[s.lutPattern()][4] += adcSum;
546 } else {
547 B2DEBUG(100, its << " creating bghit in TrueLUT for pattern: " << s.lutPattern());
548 outerTrueLRTable[s.lutPattern()][2] += 1;
549 outerTrueLRTable[s.lutPattern()][3] += tsHit->priorityTime();
550 outerTrueLRTable[s.lutPattern()][4] += adcSum;
551 }
552 }
553 }
554
555 if (m_makeRecoLRTable) {
556 // for the recotable, we have no simhits and w can have more than one recotrack per event
557 // so wee need to loop over them:
558 unsigned lrflag = 2; // see explanation below
559 for (int ireco = 0; ireco < m_recoTracks.getEntries(); ++ireco) {
560 // std::cout << "recotrack " << ireco << " of " << m_recoTracks.getEntries());
561 RecoTrack* recoTrack = m_recoTracks[ireco];
562 // since there is no relation between recotracks and the tshits yet, we need to create them first.
563 // within the recotrack class, there is a function which returns the hitids of the cdchits used
564 // in the recotrack. now we can loop over them and compare them with the id from the priorityhit:
565 // /
566 // Before looping over the recotracks, we set the rl information to 'bkg hit'. Then, we loop over all
567 // recotracks and determine if there is a relation and wether it passed left or right. If this is set for
568 // one recotrack, we set the rl information to the corresponding value. if it is set for another recotrack,
569 // we will also use this information for the recolrtable and set the corresponding value again.
570 // Just in the case, where after the loop over all recotracks it wasn't related to any of them, we will set
571 // the background flag in the recolrtable.
572 vector<CDCHit*> cdcHits = recoTrack->getCDCHitList();
573 bool related = false;
574 for (unsigned iHit = 0; iHit < cdcHits.size(); ++iHit) {
575//std::cout << "now looping over cdchits... " << iHit << "/" << cdcHits.size() << std::endl;
576 if (tsHit->getID() == cdcHits[iHit]->getID()) {
577 // check, wether recotrack is already related to ts, skip in this case.
578 // this is necessary because sometimes two wires are related to the same ts // dont get it, should be uneccessary
579 if (related == false) related = true;
580 else continue;
581// std::cout << "ts " << tsHit->getID() << " : creating relation to recotrack " << ireco;
582 // std::cout << tsHit->getID() << " " << cdcHits[iHit]->getID() << " " << iHit << " matching id of priohit and current cdchit, creating relation... " << std::endl;
583 recoTrack->addRelationTo(tsHit);
584 tsHit->addRelationTo(recoTrack);
585 if (isl == 0) {
586 // this getrightleftinformation function returns 2 for a right pass, and 3 for a left pass
587 if (recoTrack->getRightLeftInformation(cdcHits[iHit]) == 3) lrflag = 0;
588 if (recoTrack->getRightLeftInformation(cdcHits[iHit]) == 2) lrflag = 1;
589 innerRecoLRTable[s.lutPattern()][lrflag] += 1;
590 innerRecoLRTable[s.lutPattern()][3] += tsHit->priorityTime();
591 innerRecoLRTable[s.lutPattern()][4] += adcSum;
592 B2DEBUG(100, its << " creating entry in recoLUT for pattern: " << s.lutPattern() << " : " << lrflag << " (recotrack " << ireco <<
593 "), hit: " << iHit);
594 } else {
595 if (recoTrack->getRightLeftInformation(cdcHits[iHit]) == 3) lrflag = 0;
596 if (recoTrack->getRightLeftInformation(cdcHits[iHit]) == 2) lrflag = 1;
597 outerRecoLRTable[s.lutPattern()][lrflag] += 1;
598 outerRecoLRTable[s.lutPattern()][3] += tsHit->priorityTime();
599 outerRecoLRTable[s.lutPattern()][4] += adcSum;
600 B2DEBUG(100, its << " creating entry in recoLUT for pattern: " << s.lutPattern() << " : " << lrflag << " (recotrack " << ireco <<
601 "), hit: " << iHit);
602 }
603//std::cout << " , lrflag: " << lrflag << ", 0=left, 1=right";
604 //break;
605 }
606 }
607 }
608 if (lrflag == 2) {
609 if (isl == 0) {
610 B2DEBUG(100, its << " creating bghit in recoLUT for pattern: " << s.lutPattern());
611 innerRecoLRTable[s.lutPattern()][2] += 1;
612 innerRecoLRTable[s.lutPattern()][3] += tsHit->priorityTime();
613 innerRecoLRTable[s.lutPattern()][4] += adcSum;
614 } else {
615 B2DEBUG(100, its << " creating bghit in recoLUT for pattern: " << s.lutPattern());
616 outerRecoLRTable[s.lutPattern()][2] += 1;
617 outerRecoLRTable[s.lutPattern()][3] += tsHit->priorityTime();
618 outerRecoLRTable[s.lutPattern()][4] += adcSum;
619
620 }
621 //std::cout << " , lrflag: " << lrflag << ", 0=left, 1=right, 2=bg";
622 }
623 //std::cout << std::endl;
624 }
625 }
626 }
627 }
628
629 //...Clear hit information after we're finished...
630 clear();
631}
632
633void
635{
636 // delete clocks
637 for (unsigned ic = 0; ic < clocks.size(); ++ic) {
638 delete clocks[ic];
639 }
640 clocks.clear();
641
642 // delete wire layers
643 for (unsigned isl = 0; isl < superLayers.size(); ++isl) {
644 for (unsigned il = 0; il < superLayers[isl].size(); ++il) {
645 for (unsigned iw = 0; iw < superLayers[isl][il]->nCells(); ++iw) {
646 delete &(superLayers[isl][il]->cell(iw));
647 }
648 delete superLayers[isl][il];
649 }
650 superLayers[isl].clear();
651 }
652 superLayers.clear();
653
654 // delete TS layers
655 for (unsigned isl = 0; isl < tsLayers.size(); ++isl) {
656 for (unsigned its = 0; its < tsLayers[isl]->nCells(); ++its) {
657 delete &(tsLayers[isl]->cell(its));
658 }
659 delete tsLayers[isl];
660 }
661 tsLayers.clear();
662
663 // save true left/right table
664 if (m_makeTrueLRTable) {
665 ofstream innerFile(m_innerTrueLRTableFilename);
666 ostream_iterator<unsigned> innerIterator(innerFile, " ");
667 for (unsigned pattern = 0; pattern < innerTrueLRTable.size(); ++pattern) {
668 copy(innerTrueLRTable[pattern].begin(), innerTrueLRTable[pattern].end(),
669 innerIterator);
670 innerFile << "\n";
671 }
672 ofstream outerFile(m_outerTrueLRTableFilename);
673 ostream_iterator<unsigned> outerIterator(outerFile, " ");
674 for (unsigned pattern = 0; pattern < outerTrueLRTable.size(); ++pattern) {
675 copy(outerTrueLRTable[pattern].begin(), outerTrueLRTable[pattern].end(),
676 outerIterator);
677 outerFile << "\n";
678 }
679 }
680
681 // save reco left/right table
682 if (m_makeRecoLRTable) {
683 ofstream innerFile(m_innerRecoLRTableFilename);
684 ostream_iterator<unsigned> innerIterator(innerFile, " ");
685 for (unsigned pattern = 0; pattern < innerRecoLRTable.size(); ++pattern) {
686 copy(innerRecoLRTable[pattern].begin(), innerRecoLRTable[pattern].end(),
687 innerIterator);
688 innerFile << "\n";
689 }
690 ofstream outerFile(m_outerRecoLRTableFilename);
691 ostream_iterator<unsigned> outerIterator(outerFile, " ");
692 for (unsigned pattern = 0; pattern < outerRecoLRTable.size(); ++pattern) {
693 copy(outerRecoLRTable[pattern].begin(), outerRecoLRTable[pattern].end(),
694 outerIterator);
695 outerFile << "\n";
696 }
697 }
698}
699
700void
702{
704 for (unsigned isl = 0; isl < superLayers.size(); ++isl) {
705 if (isl < cdc.getOffsetOfFirstSuperLayer()) {
706 continue;
707 }
708 for (unsigned il = 0; il < superLayers[isl].size(); ++il) {
709 for (unsigned iw = 0; iw < superLayers[isl][il]->nCells(); ++iw) {
710 TRGCDCWire& w = (TRGCDCWire&) superLayers[isl][il]->cell(iw);
711 delete w.hit();
712 w.clear();
713 }
714 }
715 for (unsigned its = 0; its < tsLayers[isl]->nCells(); ++its) {
716 TRGCDCSegment& s = (TRGCDCSegment&) tsLayers[isl]->cell(its);
717 s.clear();
718 }
719 }
720
721}
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
Example Detector.
Definition: CDCSimHit.h:21
int getLeftRightPassage() const
The method to get new left/right info. for tracking.
Definition: CDCSimHit.h:238
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::string m_outerRecoLRTableFilename
filename for the table which contains the number of reconstructed left/right for each pattern in the ...
std::vector< TRGCDCLayer * > tsLayers
structure to hold pointers to all track segment shapes
bool m_relateAllHits
relate all cdchtis to ts, not just opriority wire
bool m_clockSimulation
switch for simulating clock by clock
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.
bool deadch_map[c_nSuperLayers][MAX_N_LAYERS][c_maxNDriftCells]
bad channel mapping
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
std::vector< std::vector< unsigned > > outerRecoLRTable
list of (# true right, # true left, # true background) for the outer super layers
virtual void terminate() override
Clean up pointers.
std::vector< std::vector< unsigned > > outerTrueLRTable
list of (# true right, # true left, # true background) for the outer super layers
std::string m_innerTSLUTFilename
The filename of LUT for the inner-most track segments.
virtual void beginRun() override
Register run-dependent DataStore arrays.
std::vector< std::vector< unsigned > > innerRecoLRTable
list of (# reconstructed right, # reconstructed left, # unrelated background) for the inner-most supe...
std::vector< std::vector< unsigned > > innerTrueLRTable
list of (# true right, # true left, # true background) for the inner-most super layer
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
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< TRGClock * > clocks
list of clocks used in the TSF
std::string m_innerTrueLRTableFilename
filename for the table which contains the number of true left/right for each pattern in the inner-mos...
std::vector< std::vector< TRGCDCLayer * > > superLayers
structure to hold pointers to all wires in the CDC
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
Base class for Modules.
Definition: Module.h:72
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
@ 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:455
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:339
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.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
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
TRGTime & reverse(void)
reverse edge.
Definition: Time.h:141
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)
initilize variables.
Definition: Segment.cc:65
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
Abstract base class for different kinds of events.
STL namespace.