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. Default: -1",
120 if (m_makeRecoLRTable) {
136 const unsigned nLayers = cdc.nWireLayers();
137 TRGClock* clockTDC =
new TRGClock(
"CDCTrigger TDC clock", 0, 500. / cdc.getTdcBinWidth());
138 TRGClock* clockData =
new TRGClock(
"CDCTrigger data clock", *clockTDC, 1, 16);
139 clocks.push_back(clockTDC);
140 clocks.push_back(clockData);
143 int superLayerId = -1;
144 unsigned lastNWires = 0;
145 int lastShifts = -1000;
151 unsigned axialStereoLayerId;
152 unsigned axialStereoSuperLayerId = 0;
154 for (
unsigned i = 0; i < nLayers; i++) {
155 if (i < cdc.getOffsetOfFirstLayer()) {
158 const unsigned nWiresInLayer = cdc.nWiresInLayer(i);
161 int nShifts = cdc.nShifts(i);
162 bool axial = (nShifts == 0);
165 axialStereoLayerId = (axial) ? ia : is;
168 if (
superLayers.size() == 0 and cdc.getOffsetOfFirstSuperLayer() != 0) {
169 for (uint superLayerOffset = 0; superLayerOffset < cdc.getOffsetOfFirstSuperLayer(); superLayerOffset++) {
176 if ((lastNWires != nWiresInLayer) || (lastShifts != nShifts)) {
181 axialStereoSuperLayerId = (axial) ? ias : iss;
182 lastNWires = nWiresInLayer;
183 lastShifts = nShifts;
187 const float swr = cdc.senseWireR(i);
188 const float innerRadius = cdc.fieldWireR(i - 1);
189 const float outerRadius = (i < nLayers - 1) ?
191 swr + (swr - innerRadius);
198 axialStereoSuperLayerId,
199 cdc.zOffsetWireLayer(i),
201 M_PI * swr * swr / nWiresInLayer,
208 for (
unsigned j = 0; j < nWiresInLayer; j++) {
209 const P3D fp = P3D(cdc.wireForwardPosition(i, j).x(),
210 cdc.wireForwardPosition(i, j).y(),
211 cdc.wireForwardPosition(i, j).z());
212 const P3D bp = P3D(cdc.wireBackwardPosition(i, j).x(),
213 cdc.wireBackwardPosition(i, j).y(),
214 cdc.wireBackwardPosition(i, j).z());
216 layer->push_back(tw);
221 const unsigned nWiresInTS[2] = {15, 11};
222 const int shape[2][30] = {
258 const int layerOffset[2] = {5, 2};
261 for (
unsigned i = 0; i <
superLayers.size(); i++) {
262 if (i < cdc.getOffsetOfFirstSuperLayer()) {
267 unsigned tsType = (i) ? 1 : 0;
275 const unsigned nWiresInLayer = ww->
layer().
nCells();
276 B2DEBUG(100,
"SL " << i <<
" layerOffset " << layerOffset[tsType] <<
", "
277 <<
superLayers[i].size() <<
" layers, " << nWiresInLayer <<
" wires");
278 for (
unsigned j = 0; j < nWiresInLayer; j++) {
282 const unsigned localId = w.localId();
283 const unsigned layerId = w.localLayerId();
284 vector<const TRGCDCWire*> cells;
286 B2DEBUG(110,
"TS localId " << localId <<
" layerId " << layerId);
288 for (
unsigned k = 0; k < nWiresInTS[tsType]; k++) {
289 const int laid = layerId + shape[tsType][k * 2];
290 const int loid = localId + shape[tsType][k * 2 + 1];
292 B2DEBUG(120,
"cell localId " << loid <<
" layerId " << laid);
301 if (w.superLayerId()) {
317 layer->push_back(ts);
329 B2ERROR(
"No database for CDCTRG dead channel mapping. Channel masking is skipped. exp " << evtMetaData->getExperiment() <<
" run "
330 << evtMetaData->getRun());
331 for (
unsigned int i = 0; i < c_nSuperLayers; i++) {
332 for (
unsigned int j = 0; j < MAX_N_LAYERS; j++) {
333 for (
unsigned int k = 0; k < c_maxNDriftCells; k++) {
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++) {
358 vector<int> filtered_hit;
359 for (
int i = 0; i <
m_cdcHits.getEntries(); ++i) {
360 filtered_hit.push_back(0);
365 int ncdchit_asic[500][6] = {{0}};
366 vector<int> id_ncdchit_asic[500][6];
367 for (
int i = 0; i <
m_cdcHits.getEntries(); ++i) {
368 UChar_t lay =
m_cdcHits[i]->getICLayer();
369 UShort_t IWire =
m_cdcHits[i]->getIWire();
370 WireID wireid(lay, IWire);
371 int boardid = cdc.getBoardID(wireid);
372 int fechid = cdc.getChannelID(wireid);
373 int asicid = fechid / 8;
374 if (boardid >= 0 && boardid < 500 && asicid >= 0 && asicid < 6) {
375 ncdchit_asic[boardid][asicid]++;
376 id_ncdchit_asic[boardid][asicid].push_back(i);
380 for (
int i = 0; i < 500; i++) {
381 for (
int j = 0; j < 6; j++) {
382 if (ncdchit_asic[i][j] >= 4) {
383 std::vector<short> tdc_asic;
384 for (
int k = 0; k < ncdchit_asic[i][j]; k++) {
385 short tdc =
m_cdcHits[id_ncdchit_asic[i][j][k]]->getTDCCount();
386 tdc_asic.push_back(tdc);
388 std::sort(tdc_asic.begin(), tdc_asic.end());
389 for (
int ncoin = ncdchit_asic[i][j]; ncoin >= 4; ncoin--) {
390 bool breakOuterLoop =
false;
391 for (
int k = 0; k < ncdchit_asic[i][j] - ncoin; k++) {
392 if (tdc_asic[k + ncoin - 1] - tdc_asic[k] <= 16) {
393 for (
int l = k; l < k + ncoin - 1; l++) {
394 filtered_hit[id_ncdchit_asic[i][j][l]] = 1;
396 breakOuterLoop =
true;
410 for (
int i = 0; i <
m_cdcHits.getEntries(); ++i) {
415 if (!
deadch_map[h.getISuperLayer()][h.getILayer()][h.getIWire()]) {
420 if (filtered_hit[i] == 1)
continue;
424 if (h.getADCCount() <
m_adccut)
continue;
431 const int tdcCount = floor((cdc.getT0(
WireID(h.getID())) / cdc.getTdcBinWidth()
432 - h.getTDCCount() + 0.5) / 2);
433 TRGTime rise =
TRGTime(tdcCount,
true, w.signal().clock(), w.name());
439 if (w.hit())
continue;
443 0, 0, 0, 0, 0, 0, 0, 0);
450 unsigned neibor_hit[10][1000] = {};
451 for (
unsigned isl = 0; isl <
tsLayers.size(); ++isl) {
452 for (
unsigned its = 0; its <
tsLayers[isl]->nCells(); ++its) {
459 neibor_hit[isl][its] = 1;
465 for (
unsigned isl = 0; isl <
tsLayers.size(); ++isl) {
466 for (
unsigned its = 0; its <
tsLayers[isl]->nCells(); ++its) {
478 if (s.priorityPosition() != 3 && (neibor_hit[isl][(its - 1) %
tsLayers[isl]->nCells()] == 1
479 || neibor_hit[isl][(its + 1) %
tsLayers[isl]->nCells()] == 1))
continue;
485 s.priorityPosition(),
486 s.LUT()->getValue(s.lutPattern()),
490 unsigned short adcSum = 0;
492 for (
unsigned iw = 0; iw < s.wires().size(); ++iw) {
496 double weight = (wire == &(s.priority())) ? 2. : 1.;
505 for (
unsigned imc = 0; imc < mcrel.
size(); ++imc) {
506 mcrel[imc]->addRelationTo(tsHit, mcrel.
weight(imc));
513 B2DEBUG(100, its <<
" creating entry in TrueLUT for pattern: " << s.lutPattern() <<
" : " << simHit->
getLeftRightPassage());
521 B2DEBUG(100, its <<
" creating entry in TrueLUT for pattern: " << s.lutPattern() <<
" : " << simHit->
getLeftRightPassage());
525 B2DEBUG(100, its <<
" creating bghit in TrueLUT for pattern: " << s.lutPattern());
530 B2DEBUG(100, its <<
" creating bghit in TrueLUT for pattern: " << s.lutPattern());
538 if (m_makeRecoLRTable) {
556 bool related =
false;
557 for (
unsigned iHit = 0; iHit < cdcHits.size(); ++iHit) {
559 if (tsHit->
getID() == cdcHits[iHit]->getID()) {
562 if (related ==
false) related =
true;
575 B2DEBUG(100, its <<
" creating entry in recoLUT for pattern: " << s.lutPattern() <<
" : " << lrflag <<
" (recotrack " << ireco <<
583 B2DEBUG(100, its <<
" creating entry in recoLUT for pattern: " << s.lutPattern() <<
" : " << lrflag <<
" (recotrack " << ireco <<
593 B2DEBUG(100, its <<
" creating bghit in recoLUT for pattern: " << s.lutPattern());
598 B2DEBUG(100, its <<
" creating bghit in recoLUT for pattern: " << s.lutPattern());
620 for (
unsigned ic = 0; ic <
clocks.size(); ++ic) {
626 for (
unsigned isl = 0; isl <
superLayers.size(); ++isl) {
627 for (
unsigned il = 0; il <
superLayers[isl].size(); ++il) {
628 for (
unsigned iw = 0; iw <
superLayers[isl][il]->nCells(); ++iw) {
638 for (
unsigned isl = 0; isl <
tsLayers.size(); ++isl) {
639 for (
unsigned its = 0; its <
tsLayers[isl]->nCells(); ++its) {
649 ostream_iterator<unsigned> innerIterator(innerFile,
" ");
656 ostream_iterator<unsigned> outerIterator(outerFile,
" ");
665 if (m_makeRecoLRTable) {
667 ostream_iterator<unsigned> innerIterator(innerFile,
" ");
674 ostream_iterator<unsigned> outerIterator(outerFile,
" ");
687 for (
unsigned isl = 0; isl <
superLayers.size(); ++isl) {
688 if (isl < cdc.getOffsetOfFirstSuperLayer()) {
691 for (
unsigned il = 0; il <
superLayers[isl].size(); ++il) {
692 for (
unsigned iw = 0; iw <
superLayers[isl][il]->nCells(); ++iw) {
698 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...
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
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_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.
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...
std::vector< Belle2::RecoTrack::UsedCDCHit * > getCDCHitList() const
Return an unsorted list of cdc hits.
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.