8#include "trg/cdc/modules/trgcdc/CDCTriggerTSFModule.h"
10#include <cdc/dataobjects/CDCSimHit.h>
11#include <cdc/dataobjects/CDCRawHit.h>
12#include <cdc/dataobjects/WireID.h>
13#include <mdst/dataobjects/MCParticle.h>
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>
24#define P3D HepGeom::Point3D<double>
35 "The Track Segment Finder module of the CDC trigger.\n"
36 "Combines CDCHits from the same super layer to CDCTriggerSegmentHits.\n"
41 "Name of the input StoreArray of CDCHits.",
42 std::string(
"CDCHits4Trg"));
45 "Name of the output StoreArray of CDCTriggerSegmentHits.",
49 "The filename of LUT for track segments from the inner-most super layer",
53 "The filename of LUT for track segments from the outer super layers",
57 "Switch to simulate each data clock cycle separately.",
61 "Switch to create a table of hit pattern <-> "
62 "number of true left / true right, which is needed to create the LUT",
66 "Switch to create a table of hit pattern <-> "
67 "number of reconstructed left / true right, which is needed to create the LUT",
71 "Filename for the true left/right table for the innermost super layer.",
72 std::string(
"innerTrueLRTable.dat"));
75 "Filename for the true left/right table for the outer super layers.",
76 std::string(
"outerTrueLRTable.dat"));
79 "Mask dead channels based on database. True:mask False:unmask",
83 "TDC based crosstalk filtering logic on CDCFE. True:enable False:disable",
87 "Filename for the reconnstructed left/right table for the innermost super layer.",
88 std::string(
"innerRecoLRTable.dat"));
91 "Filename for the reconstructed left/right table for the outer super layers.",
92 std::string(
"outerRecoLRTable.dat"));
95 "Flag to relate all cdchits to the TrackSegment, not just the priority hits.",
99 "remove hits with lower ADC than cut threshold. True:enable False:disable",
103 "Threshold for the adc cut for all wires used for TSF. Default: -1",
107 "Flag to save ADC for other trg module or not, Default: false",
111 "Assign ADC based flag for full hit tracker. Lower threshold of ADC.",
115 "Assign ADC based flag for full hit tracker. Higher threshold of ADC.",
118 "Switch to use database to load run dependent parameters. ",
true);
133 if (m_makeRecoLRTable) {
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);
155 int superLayerId = -1;
156 unsigned lastNWires = 0;
157 int lastShifts = -1000;
163 unsigned axialStereoLayerId;
164 unsigned axialStereoSuperLayerId = 0;
166 for (
unsigned i = 0; i < nLayers; i++) {
167 if (i < cdc.getOffsetOfFirstLayer()) {
170 const unsigned nWiresInLayer = cdc.nWiresInLayer(i);
173 int nShifts = cdc.nShifts(i);
174 bool axial = (nShifts == 0);
177 axialStereoLayerId = (axial) ? ia : is;
180 if (
m_superLayers.size() == 0 and cdc.getOffsetOfFirstSuperLayer() != 0) {
181 for (uint superLayerOffset = 0; superLayerOffset < cdc.getOffsetOfFirstSuperLayer(); superLayerOffset++) {
188 if ((lastNWires != nWiresInLayer) || (lastShifts != nShifts)) {
193 axialStereoSuperLayerId = (axial) ? ias : iss;
194 lastNWires = nWiresInLayer;
195 lastShifts = nShifts;
199 const float swr = cdc.senseWireR(i);
200 const float innerRadius = cdc.fieldWireR(i - 1);
201 const float outerRadius = (i < nLayers - 1) ?
203 swr + (swr - innerRadius);
210 axialStereoSuperLayerId,
211 cdc.zOffsetWireLayer(i),
213 M_PI * swr * swr / nWiresInLayer,
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());
228 layer->push_back(tw);
233 const unsigned nWiresInTS[2] = {15, 11};
234 const int shape[2][30] = {
270 const int layerOffset[2] = {5, 2};
274 if (i < cdc.getOffsetOfFirstSuperLayer()) {
279 unsigned tsType = (i) ? 1 : 0;
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++) {
294 const unsigned localId = w.
localId();
296 std::vector<const TRGCDCWire*> cells;
298 B2DEBUG(110,
"TS localId " << localId <<
" layerId " << layerId);
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];
304 B2DEBUG(120,
"cell localId " << loid <<
" layerId " << laid);
329 layer->push_back(ts);
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++) {
345 for (
unsigned int k = 0; k < c_maxNDriftCells; k++) {
351 for (
unsigned int i = 0; i < c_nSuperLayers; i++) {
353 for (
unsigned int k = 0; k < c_maxNDriftCells; k++) {
364 B2FATAL(
"No database for CDCTRG TSF parameter. exp " << evtMetaData->getExperiment() <<
" run "
365 << evtMetaData->getRun());
383 std::vector<int> filtered_hit(
m_cdcHits.getEntries(), 0);
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();
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);
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) {
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);
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;
419 breakOuterLoop =
true;
432 for (
int i = 0; i <
m_cdcHits.getEntries(); ++i) {
442 if (filtered_hit[i] == 1)
continue;
444 if (h.getTDCCount() < 4450 || h.getTDCCount() > 4950)
continue;
448 if (h.getADCCount() <
m_adccut)
continue;
455 const int tdcCount = floor((cdc.getT0(
WireID(h.getID())) / cdc.getTdcBinWidth()
456 - h.getTDCCount() + 0.5) / 2);
467 if (w.
hit())
continue;
471 0, 0, 0, 0, 0, 0, 0, 0);
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) {
487 neibor_hit[isl][its] = 1;
493 for (
unsigned isl = 0; isl <
m_tsLayers.size(); ++isl) {
494 for (
unsigned its = 0; its <
m_tsLayers[isl]->nCells(); ++its) {
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;
512 std::vector<float> fullADC = {};
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())) {
518 fullADC.push_back(-1);
528 s.priorityPosition(),
529 s.LUT()->getValue(s.lutPattern()),
538 unsigned short adcSum = 0;
540 for (
unsigned iw = 0; iw < s.wires().size(); ++iw) {
544 double weight = (wire == &(s.priority())) ? 2. : 1.;
553 for (
unsigned imc = 0; imc < mcrel.
size(); ++imc) {
554 mcrel[imc]->addRelationTo(tsHit, mcrel.
weight(imc));
561 B2DEBUG(100, its <<
" creating entry in TrueLUT for pattern: " << s.lutPattern() <<
" : " << simHit->
getLeftRightPassage());
569 B2DEBUG(100, its <<
" creating entry in TrueLUT for pattern: " << s.lutPattern() <<
" : " << simHit->
getLeftRightPassage());
573 B2DEBUG(100, its <<
" creating bghit in TrueLUT for pattern: " << s.lutPattern());
578 B2DEBUG(100, its <<
" creating bghit in TrueLUT for pattern: " << s.lutPattern());
586 if (m_makeRecoLRTable) {
590 for (
int ireco = 0; ireco <
m_recoTracks.getEntries(); ++ireco) {
603 const std::vector<CDCHit*>& cdcHits = recoTrack->
getCDCHitList();
604 bool related =
false;
605 for (
unsigned iHit = 0; iHit < cdcHits.size(); ++iHit) {
607 if (tsHit->
getID() == cdcHits[iHit]->getID()) {
610 if (related ==
false) related =
true;
623 B2DEBUG(100, its <<
" creating entry in recoLUT for pattern: " << s.lutPattern() <<
" : " << lrflag <<
" (recotrack " << ireco <<
631 B2DEBUG(100, its <<
" creating entry in recoLUT for pattern: " << s.lutPattern() <<
" : " << lrflag <<
" (recotrack " << ireco <<
641 B2DEBUG(100, its <<
" creating bghit in recoLUT for pattern: " << s.lutPattern());
646 B2DEBUG(100, its <<
" creating bghit in recoLUT for pattern: " << s.lutPattern());
669 for (
unsigned il = 0; il <
m_superLayers[isl].size(); ++il) {
670 for (
unsigned iw = 0; iw <
m_superLayers[isl][il]->nCells(); ++iw) {
680 for (
unsigned isl = 0; isl <
m_tsLayers.size(); ++isl) {
681 for (
unsigned its = 0; its <
m_tsLayers[isl]->nCells(); ++its) {
691 std::ostream_iterator<unsigned> innerIterator(innerFile,
" ");
698 std::ostream_iterator<unsigned> outerIterator(outerFile,
" ");
707 if (m_makeRecoLRTable) {
709 std::ostream_iterator<unsigned> innerIterator(innerFile,
" ");
716 std::ostream_iterator<unsigned> outerIterator(outerFile,
" ");
730 if (isl < cdc.getOffsetOfFirstSuperLayer()) {
733 for (
unsigned il = 0; il <
m_superLayers[isl].size(); ++il) {
734 for (
unsigned iw = 0; iw <
m_superLayers[isl][il]->nCells(); ++iw) {
740 for (
unsigned its = 0; its <
m_tsLayers[isl]->nCells(); ++its) {
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
unsigned short getADCCount() const
Getter for integrated charge.
int getLeftRightPassage() const
The method to get new left/right info. for tracking.
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.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
This is the Reconstruction Event-Data Model Track.
std::vector< Belle2::RecoTrack::UsedCDCHit * > getCDCHitList() const
Return an unsorted list of cdc hits.
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...
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.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
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.
Type-safe access to single objects in the data store.
A class to represent a wire in CDC.
A class to represent a cell layer.
A class to represent a wire in CDC.
A class to represent a wire hit in CDC.
A class to represent a wire in CDC.
A class to represent a digitized signal. Unit is nano second.
A class to represent a digitized signal. Unit is nano second.
A class to represent a signal timing in the trigger system.
Class to identify a wire inside the CDC.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
void addSignal(const TRGSignal &newSignal)
set signal |= newSignal
const TRGClock & clock(void) const
returns clock.
unsigned localLayerId(void) const
returns local layer id in a super layer.
TRGTime & reverse(void)
reverse edge.
unsigned superLayerId(void) const
returns super layer id.
const TRGSignal & signal(void) const override
returns an input to the trigger. This is sync'ed to 1GHz clock.
TRGTime & shift(int unit)
delays by clock unit.
const TRGCDCWireHit * hit(void) const
returns a pointer to a TRGCDCWireHit.
void initialize(void)
initialize variables.
std::string name(void) const override
returns name.
void clear(void) override
clears information.
unsigned iCDCHit(void) const
returns an index to CDCHit.
const TRGCDCLayer & layer(void) const
returns a pointer to a layer.
bool active(void) const
returns true if there is a signal.
unsigned nCells(void) const
returns # of cells.
unsigned localId(void) const
returns local id in a layer.
void addSignal_adc(const TRGSignal &newSignal)
set signal |= newSignal
signed short IWire
The type of the wire ids enumerating wires within a given layer.
Abstract base class for different kinds of events.