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 "Assign ADC based flag for full hit tracker. Lower threshold of ADC.",
112 "Assign ADC based flag for full hit tracker. Higher threshold of ADC.",
128 if (m_makeRecoLRTable) {
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);
151 int superLayerId = -1;
152 unsigned lastNWires = 0;
153 int lastShifts = -1000;
159 unsigned axialStereoLayerId;
160 unsigned axialStereoSuperLayerId = 0;
162 for (
unsigned i = 0; i < nLayers; i++) {
163 if (i < cdc.getOffsetOfFirstLayer()) {
166 const unsigned nWiresInLayer = cdc.nWiresInLayer(i);
169 int nShifts = cdc.nShifts(i);
170 bool axial = (nShifts == 0);
173 axialStereoLayerId = (axial) ? ia : is;
176 if (
superLayers.size() == 0 and cdc.getOffsetOfFirstSuperLayer() != 0) {
177 for (uint superLayerOffset = 0; superLayerOffset < cdc.getOffsetOfFirstSuperLayer(); superLayerOffset++) {
184 if ((lastNWires != nWiresInLayer) || (lastShifts != nShifts)) {
189 axialStereoSuperLayerId = (axial) ? ias : iss;
190 lastNWires = nWiresInLayer;
191 lastShifts = nShifts;
195 const float swr = cdc.senseWireR(i);
196 const float innerRadius = cdc.fieldWireR(i - 1);
197 const float outerRadius = (i < nLayers - 1) ?
199 swr + (swr - innerRadius);
206 axialStereoSuperLayerId,
207 cdc.zOffsetWireLayer(i),
209 M_PI * swr * swr / nWiresInLayer,
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());
224 layer->push_back(tw);
229 const unsigned nWiresInTS[2] = {15, 11};
230 const int shape[2][30] = {
266 const int layerOffset[2] = {5, 2};
269 for (
unsigned i = 0; i <
superLayers.size(); i++) {
270 if (i < cdc.getOffsetOfFirstSuperLayer()) {
275 unsigned tsType = (i) ? 1 : 0;
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++) {
290 const unsigned localId = w.localId();
291 const unsigned layerId = w.localLayerId();
292 vector<const TRGCDCWire*> cells;
294 B2DEBUG(110,
"TS localId " << localId <<
" layerId " << layerId);
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];
300 B2DEBUG(120,
"cell localId " << loid <<
" layerId " << laid);
309 if (w.superLayerId()) {
325 layer->push_back(ts);
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++) {
340 for (
unsigned int j = 0; j < MAX_N_LAYERS; j++) {
341 for (
unsigned int k = 0; k < c_maxNDriftCells; k++) {
347 for (
unsigned int i = 0; i < c_nSuperLayers; i++) {
348 for (
unsigned int j = 0; j < MAX_N_LAYERS; j++) {
349 for (
unsigned int k = 0; k < c_maxNDriftCells; k++) {
366 vector<int> filtered_hit;
367 for (
int i = 0; i <
m_cdcHits.getEntries(); ++i) {
368 filtered_hit.push_back(0);
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);
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);
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;
404 breakOuterLoop =
true;
418 for (
int i = 0; i <
m_cdcHits.getEntries(); ++i) {
423 if (!
deadch_map[h.getISuperLayer()][h.getILayer()][h.getIWire()]) {
428 if (filtered_hit[i] == 1)
continue;
430 if (h.getTDCCount() < 4450 || h.getTDCCount() > 4950)
continue;
434 if (h.getADCCount() <
m_adccut)
continue;
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());
450 w.addSignal_adc(signal);
453 if (w.hit())
continue;
457 0, 0, 0, 0, 0, 0, 0, 0);
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) {
473 neibor_hit[isl][its] = 1;
479 for (
unsigned isl = 0; isl <
tsLayers.size(); ++isl) {
480 for (
unsigned its = 0; its <
tsLayers[isl]->nCells(); ++its) {
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;
499 s.priorityPosition(),
500 s.LUT()->getValue(s.lutPattern()),
509 for (
unsigned iw = 0; iw < s.wires().size(); ++iw) {
513 double weight = (wire == &(s.priority())) ? 2. : 1.;
522 for (
unsigned imc = 0; imc < mcrel.
size(); ++imc) {
523 mcrel[imc]->addRelationTo(tsHit, mcrel.
weight(imc));
530 B2DEBUG(100, its <<
" creating entry in TrueLUT for pattern: " << s.lutPattern() <<
" : " << simHit->
getLeftRightPassage());
538 B2DEBUG(100, its <<
" creating entry in TrueLUT for pattern: " << s.lutPattern() <<
" : " << simHit->
getLeftRightPassage());
542 B2DEBUG(100, its <<
" creating bghit in TrueLUT for pattern: " << s.lutPattern());
547 B2DEBUG(100, its <<
" creating bghit in TrueLUT for pattern: " << s.lutPattern());
555 if (m_makeRecoLRTable) {
573 bool related =
false;
574 for (
unsigned iHit = 0; iHit < cdcHits.size(); ++iHit) {
576 if (tsHit->
getID() == cdcHits[iHit]->getID()) {
579 if (related ==
false) related =
true;
592 B2DEBUG(100, its <<
" creating entry in recoLUT for pattern: " << s.lutPattern() <<
" : " << lrflag <<
" (recotrack " << ireco <<
600 B2DEBUG(100, its <<
" creating entry in recoLUT for pattern: " << s.lutPattern() <<
" : " << lrflag <<
" (recotrack " << ireco <<
610 B2DEBUG(100, its <<
" creating bghit in recoLUT for pattern: " << s.lutPattern());
615 B2DEBUG(100, its <<
" creating bghit in recoLUT for pattern: " << s.lutPattern());
637 for (
unsigned ic = 0; ic <
clocks.size(); ++ic) {
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) {
655 for (
unsigned isl = 0; isl <
tsLayers.size(); ++isl) {
656 for (
unsigned its = 0; its <
tsLayers[isl]->nCells(); ++its) {
666 ostream_iterator<unsigned> innerIterator(innerFile,
" ");
673 ostream_iterator<unsigned> outerIterator(outerFile,
" ");
682 if (m_makeRecoLRTable) {
684 ostream_iterator<unsigned> innerIterator(innerFile,
" ");
691 ostream_iterator<unsigned> outerIterator(outerFile,
" ");
704 for (
unsigned isl = 0; isl <
superLayers.size(); ++isl) {
705 if (isl < cdc.getOffsetOfFirstSuperLayer()) {
708 for (
unsigned il = 0; il <
superLayers[isl].size(); ++il) {
709 for (
unsigned iw = 0; iw <
superLayers[isl][il]->nCells(); ++iw) {
715 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...
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
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.
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.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
T * appendNew()
Construct a new T object at the end of the array.
int getEntries() const
Get the number of objects in the array.
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.
TRGTime & reverse(void)
reverse edge.
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)
initilize variables.
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.
Abstract base class for different kinds of events.