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>
36 "The Track Segment Finder module of the CDC trigger.\n"
37 "Combines CDCHits from the same super layer to CDCTriggerSegmentHits.\n"
42 "Name of the input StoreArray of CDCHits.",
43 string(
"CDCHits4Trg"));
46 "Name of the output StoreArray of CDCTriggerSegmentHits.",
50 "The filename of LUT for track segments from the inner-most super layer",
54 "The filename of LUT for track segments from the outer super layers",
58 "Switch to simulate each data clock cycle separately.",
62 "Switch to create a table of hit pattern <-> "
63 "number of true left / true right, which is needed to create the LUT",
67 "Switch to create a table of hit pattern <-> "
68 "number of reconstructed left / true right, which is needed to create the LUT",
72 "Filename for the true left/right table for the innermost super layer.",
73 string(
"innerTrueLRTable.dat"));
76 "Filename for the true left/right table for the outer super layers.",
77 string(
"outerTrueLRTable.dat"));
80 "Mask dead channels based on database. True:mask False:unmask",
84 "TDC based crosstalk filtering logic on CDCFE. True:enable False:disable",
88 "Filename for the reconnstructed left/right table for the innermost super layer.",
89 string(
"innerRecoLRTable.dat"));
92 "Filename for the reconstructed left/right table for the outer super layers.",
93 string(
"outerRecoLRTable.dat"));
96 "Flag to relate all cdchits to the TrackSegment, not just the priority hits.",
100 "remove hits with lower ADC than cut threshold. True:enable False:disable",
104 "Threshold for the adc cut for all wires used for TSF. Default: -1",
108 "Flag to save ADC for other trg module or not, Default: false",
112 "Assign ADC based flag for full hit tracker. Lower threshold of ADC.",
116 "Assign ADC based flag for full hit tracker. Higher threshold of ADC.",
119 "Switch to use database to load run dependent parameters. ",
true);
134 if (m_makeRecoLRTable) {
151 const unsigned nLayers = cdc.nWireLayers();
152 TRGClock* clockTDC =
new TRGClock(
"CDCTrigger TDC clock", 0, 500. / cdc.getTdcBinWidth());
153 TRGClock* clockData =
new TRGClock(
"CDCTrigger data clock", *clockTDC, 1, 16);
154 clocks.push_back(clockTDC);
155 clocks.push_back(clockData);
158 int superLayerId = -1;
159 unsigned lastNWires = 0;
160 int lastShifts = -1000;
166 unsigned axialStereoLayerId;
167 unsigned axialStereoSuperLayerId = 0;
169 for (
unsigned i = 0; i < nLayers; i++) {
170 if (i < cdc.getOffsetOfFirstLayer()) {
173 const unsigned nWiresInLayer = cdc.nWiresInLayer(i);
176 int nShifts = cdc.nShifts(i);
177 bool axial = (nShifts == 0);
180 axialStereoLayerId = (axial) ? ia : is;
183 if (
superLayers.size() == 0 and cdc.getOffsetOfFirstSuperLayer() != 0) {
184 for (uint superLayerOffset = 0; superLayerOffset < cdc.getOffsetOfFirstSuperLayer(); superLayerOffset++) {
191 if ((lastNWires != nWiresInLayer) || (lastShifts != nShifts)) {
196 axialStereoSuperLayerId = (axial) ? ias : iss;
197 lastNWires = nWiresInLayer;
198 lastShifts = nShifts;
202 const float swr = cdc.senseWireR(i);
203 const float innerRadius = cdc.fieldWireR(i - 1);
204 const float outerRadius = (i < nLayers - 1) ?
206 swr + (swr - innerRadius);
213 axialStereoSuperLayerId,
214 cdc.zOffsetWireLayer(i),
216 M_PI * swr * swr / nWiresInLayer,
223 for (
unsigned j = 0; j < nWiresInLayer; j++) {
224 const P3D fp = P3D(cdc.wireForwardPosition(i, j).x(),
225 cdc.wireForwardPosition(i, j).y(),
226 cdc.wireForwardPosition(i, j).z());
227 const P3D bp = P3D(cdc.wireBackwardPosition(i, j).x(),
228 cdc.wireBackwardPosition(i, j).y(),
229 cdc.wireBackwardPosition(i, j).z());
231 layer->push_back(tw);
236 const unsigned nWiresInTS[2] = {15, 11};
237 const int shape[2][30] = {
273 const int layerOffset[2] = {5, 2};
276 for (
unsigned i = 0; i <
superLayers.size(); i++) {
277 if (i < cdc.getOffsetOfFirstSuperLayer()) {
282 unsigned tsType = (i) ? 1 : 0;
290 const unsigned nWiresInLayer = ww->
layer().
nCells();
291 B2DEBUG(100,
"SL " << i <<
" layerOffset " << layerOffset[tsType] <<
", "
292 <<
superLayers[i].size() <<
" layers, " << nWiresInLayer <<
" wires");
293 for (
unsigned j = 0; j < nWiresInLayer; j++) {
297 const unsigned localId = w.
localId();
299 vector<const TRGCDCWire*> cells;
301 B2DEBUG(110,
"TS localId " << localId <<
" layerId " << layerId);
303 for (
unsigned k = 0; k < nWiresInTS[tsType]; k++) {
304 const int laid = layerId + shape[tsType][k * 2];
305 const int loid = localId + shape[tsType][k * 2 + 1];
307 B2DEBUG(120,
"cell localId " << loid <<
" layerId " << laid);
332 layer->push_back(ts);
344 B2ERROR(
"No database for CDCTRG dead channel mapping. Channel masking is skipped. exp " << evtMetaData->getExperiment() <<
" run "
345 << evtMetaData->getRun());
346 for (
unsigned int i = 0; i < c_nSuperLayers; i++) {
348 for (
unsigned int k = 0; k < c_maxNDriftCells; k++) {
354 for (
unsigned int i = 0; i < c_nSuperLayers; i++) {
356 for (
unsigned int k = 0; k < c_maxNDriftCells; k++) {
367 B2FATAL(
"No database for CDCTRG TSF parameter. exp " << evtMetaData->getExperiment() <<
" run "
368 << evtMetaData->getRun());
386 vector<int> filtered_hit;
387 for (
int i = 0; i <
m_cdcHits.getEntries(); ++i) {
388 filtered_hit.push_back(0);
393 int ncdchit_asic[500][6] = {{0}};
394 vector<int> id_ncdchit_asic[500][6];
395 for (
int i = 0; i <
m_cdcHits.getEntries(); ++i) {
396 UChar_t lay =
m_cdcHits[i]->getICLayer();
397 UShort_t IWire =
m_cdcHits[i]->getIWire();
398 WireID wireid(lay, IWire);
399 int boardid = cdc.getBoardID(wireid);
400 int fechid = cdc.getChannelID(wireid);
401 int asicid = fechid / 8;
402 if (boardid >= 0 && boardid < 500 && asicid >= 0 && asicid < 6) {
403 ncdchit_asic[boardid][asicid]++;
404 id_ncdchit_asic[boardid][asicid].push_back(i);
408 for (
int i = 0; i < 500; i++) {
409 for (
int j = 0; j < 6; j++) {
410 if (ncdchit_asic[i][j] >= 4) {
411 std::vector<short> tdc_asic;
412 for (
int k = 0; k < ncdchit_asic[i][j]; k++) {
413 short tdc =
m_cdcHits[id_ncdchit_asic[i][j][k]]->getTDCCount();
414 tdc_asic.push_back(tdc);
416 std::sort(tdc_asic.begin(), tdc_asic.end());
417 for (
int ncoin = ncdchit_asic[i][j]; ncoin >= 4; ncoin--) {
418 bool breakOuterLoop =
false;
419 for (
int k = 0; k < ncdchit_asic[i][j] - ncoin; k++) {
420 if (tdc_asic[k + ncoin - 1] - tdc_asic[k] <= 16) {
421 for (
int l = k; l < k + ncoin - 1; l++) {
422 filtered_hit[id_ncdchit_asic[i][j][l]] = 1;
424 breakOuterLoop =
true;
438 for (
int i = 0; i <
m_cdcHits.getEntries(); ++i) {
443 if (!
deadch_map[h.getISuperLayer()][h.getILayer()][h.getIWire()]) {
448 if (filtered_hit[i] == 1)
continue;
450 if (h.getTDCCount() < 4450 || h.getTDCCount() > 4950)
continue;
454 if (h.getADCCount() <
m_adccut)
continue;
461 const int tdcCount = floor((cdc.getT0(
WireID(h.getID())) / cdc.getTdcBinWidth()
462 - h.getTDCCount() + 0.5) / 2);
473 if (w.
hit())
continue;
477 0, 0, 0, 0, 0, 0, 0, 0);
484 unsigned neibor_hit[10][1000] = {};
485 for (
unsigned isl = 0; isl <
tsLayers.size(); ++isl) {
486 for (
unsigned its = 0; its <
tsLayers[isl]->nCells(); ++its) {
493 neibor_hit[isl][its] = 1;
499 for (
unsigned isl = 0; isl <
tsLayers.size(); ++isl) {
500 for (
unsigned its = 0; its <
tsLayers[isl]->nCells(); ++its) {
512 if (s.priorityPosition() != 3 && (neibor_hit[isl][(its - 1) %
tsLayers[isl]->nCells()] == 1
513 || neibor_hit[isl][(its + 1) %
tsLayers[isl]->nCells()] == 1))
continue;
518 std::vector<float> fullADC = {};
520 int nwires = (isl == 0) ? 15 : 11;
521 for (
int iwire = 0; iwire < nwires; iwire++) {
522 if (!s[iwire] || !(s[iwire]->hit())) {
523 fullADC.push_back(-1);
533 s.priorityPosition(),
534 s.LUT()->getValue(s.lutPattern()),
543 unsigned short adcSum = 0;
545 for (
unsigned iw = 0; iw < s.wires().size(); ++iw) {
549 double weight = (wire == &(s.priority())) ? 2. : 1.;
558 for (
unsigned imc = 0; imc < mcrel.
size(); ++imc) {
559 mcrel[imc]->addRelationTo(tsHit, mcrel.
weight(imc));
566 B2DEBUG(100, its <<
" creating entry in TrueLUT for pattern: " << s.lutPattern() <<
" : " << simHit->
getLeftRightPassage());
574 B2DEBUG(100, its <<
" creating entry in TrueLUT for pattern: " << s.lutPattern() <<
" : " << simHit->
getLeftRightPassage());
578 B2DEBUG(100, its <<
" creating bghit in TrueLUT for pattern: " << s.lutPattern());
583 B2DEBUG(100, its <<
" creating bghit in TrueLUT for pattern: " << s.lutPattern());
591 if (m_makeRecoLRTable) {
595 for (
int ireco = 0; ireco <
m_recoTracks.getEntries(); ++ireco) {
609 bool related =
false;
610 for (
unsigned iHit = 0; iHit < cdcHits.size(); ++iHit) {
612 if (tsHit->
getID() == cdcHits[iHit]->getID()) {
615 if (related ==
false) related =
true;
628 B2DEBUG(100, its <<
" creating entry in recoLUT for pattern: " << s.lutPattern() <<
" : " << lrflag <<
" (recotrack " << ireco <<
636 B2DEBUG(100, its <<
" creating entry in recoLUT for pattern: " << s.lutPattern() <<
" : " << lrflag <<
" (recotrack " << ireco <<
646 B2DEBUG(100, its <<
" creating bghit in recoLUT for pattern: " << s.lutPattern());
651 B2DEBUG(100, its <<
" creating bghit in recoLUT for pattern: " << s.lutPattern());
673 for (
unsigned ic = 0; ic <
clocks.size(); ++ic) {
679 for (
unsigned isl = 0; isl <
superLayers.size(); ++isl) {
680 for (
unsigned il = 0; il <
superLayers[isl].size(); ++il) {
681 for (
unsigned iw = 0; iw <
superLayers[isl][il]->nCells(); ++iw) {
691 for (
unsigned isl = 0; isl <
tsLayers.size(); ++isl) {
692 for (
unsigned its = 0; its <
tsLayers[isl]->nCells(); ++its) {
702 ostream_iterator<unsigned> innerIterator(innerFile,
" ");
709 ostream_iterator<unsigned> outerIterator(outerFile,
" ");
718 if (m_makeRecoLRTable) {
720 ostream_iterator<unsigned> innerIterator(innerFile,
" ");
727 ostream_iterator<unsigned> outerIterator(outerFile,
" ");
740 for (
unsigned isl = 0; isl <
superLayers.size(); ++isl) {
741 if (isl < cdc.getOffsetOfFirstSuperLayer()) {
744 for (
unsigned il = 0; il <
superLayers[isl].size(); ++il) {
745 for (
unsigned iw = 0; iw <
superLayers[isl][il]->nCells(); ++iw) {
751 for (
unsigned its = 0; its <
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::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
bool m_saveadc
flag for saving adc information or not.
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
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.
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
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< 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...
bool m_useDB
switch to use database to load run dependent parameter
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.
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
Abstract base class for different kinds of events.