8 #include "trg/cdc/modules/trgcdc/CDCTriggerTSFModule.h"
10 #include <cdc/dataobjects/CDCSimHit.h>
11 #include <cdc/dataobjects/CDCRawHit.h>
12 #include <mdst/dataobjects/MCParticle.h>
14 #include <cdc/geometry/CDCGeometryPar.h>
15 #include <trg/cdc/Layer.h>
16 #include <trg/cdc/Wire.h>
17 #include <trg/cdc/WireHit.h>
18 #include <trg/cdc/Segment.h>
22 #define P3D HepGeom::Point3D<double>
34 "The Track Segment Finder module of the CDC trigger.\n"
35 "Combines CDCHits from the same super layer to CDCTriggerSegmentHits.\n"
40 "Name of the input StoreArray of CDCHits.",
41 string(
"CDCHits4Trg"));
44 "Name of the output StoreArray of CDCTriggerSegmentHits.",
48 "The filename of LUT for track segments from the inner-most super layer",
52 "The filename of LUT for track segments from the outer super layers",
56 "Switch to simulate each data clock cycle separately.",
60 "Switch to create a table of hit pattern <-> "
61 "number of true left / true right, which is needed to create the LUT",
65 "Filename for the true left/right table for the innermost super layer.",
66 string(
"innerTrueLRTable.dat"));
69 "Filename for the true left/right table for the outer super layers.",
70 string(
"outerTrueLRTable.dat"));
73 "Mask dead channels based on database. True:mask False:unmask",
77 "TDC based crosstalk filtering logic on CDCFE. True:enable False:disable",
102 const unsigned nLayers = cdc.nWireLayers();
103 TRGClock* clockTDC =
new TRGClock(
"CDCTrigger TDC clock", 0, 500. / cdc.getTdcBinWidth());
104 TRGClock* clockData =
new TRGClock(
"CDCTrigger data clock", *clockTDC, 1, 16);
105 clocks.push_back(clockTDC);
106 clocks.push_back(clockData);
109 int superLayerId = -1;
110 unsigned lastNWires = 0;
111 int lastShifts = -1000;
118 unsigned axialStereoLayerId;
119 unsigned axialStereoSuperLayerId = 0;
121 for (
unsigned i = 0; i < nLayers; i++) {
122 const unsigned nWiresInLayer = cdc.nWiresInLayer(i);
125 int nShifts = cdc.nShifts(i);
126 bool axial = (nShifts == 0);
129 axialStereoLayerId = (axial) ? ia : is;
132 if ((lastNWires != nWiresInLayer) || (lastShifts != nShifts)) {
137 axialStereoSuperLayerId = (axial) ? ias : iss;
138 lastNWires = nWiresInLayer;
139 lastShifts = nShifts;
143 const float swr = cdc.senseWireR(i);
144 const float innerRadius = cdc.fieldWireR(i - 1);
145 const float outerRadius = (i < nLayers - 1) ?
147 swr + (swr - innerRadius);
154 axialStereoSuperLayerId,
155 cdc.zOffsetWireLayer(i),
157 M_PI * swr * swr / nWiresInLayer,
164 for (
unsigned j = 0; j < nWiresInLayer; j++) {
165 const P3D fp = P3D(cdc.wireForwardPosition(i, j).x(),
166 cdc.wireForwardPosition(i, j).y(),
167 cdc.wireForwardPosition(i, j).z());
168 const P3D bp = P3D(cdc.wireBackwardPosition(i, j).x(),
169 cdc.wireBackwardPosition(i, j).y(),
170 cdc.wireBackwardPosition(i, j).z());
172 layer->push_back(tw);
177 const unsigned nWiresInTS[2] = {15, 11};
178 const int shape[2][30] = {
214 const int layerOffset[2] = {5, 2};
217 for (
unsigned i = 0; i <
superLayers.size(); i++) {
218 unsigned tsType = (i) ? 1 : 0;
226 const unsigned nWiresInLayer = ww->
layer().
nCells();
227 B2DEBUG(100,
"SL " << i <<
" layerOffset " << layerOffset[tsType] <<
", "
228 <<
superLayers[i].size() <<
" layers, " << nWiresInLayer <<
" wires");
229 for (
unsigned j = 0; j < nWiresInLayer; j++) {
233 const unsigned localId = w.localId();
234 const unsigned layerId = w.localLayerId();
235 vector<const TRGCDCWire*> cells;
237 B2DEBUG(110,
"TS localId " << localId <<
" layerId " << layerId);
239 for (
unsigned k = 0; k < nWiresInTS[tsType]; k++) {
240 const int laid = layerId + shape[tsType][k * 2];
241 const int loid = localId + shape[tsType][k * 2 + 1];
243 B2DEBUG(120,
"cell localId " << loid <<
" layerId " << laid);
252 if (w.superLayerId()) {
268 layer->push_back(ts);
280 B2ERROR(
"No database for CDCTRG dead channel mapping. Channel masking is skipped. exp " << evtMetaData->getExperiment() <<
" run "
281 << evtMetaData->getRun());
282 for (
unsigned int i = 0; i < nSuperLayers; i++) {
283 for (
unsigned int j = 0; j < MAX_N_LAYERS; j++) {
284 for (
unsigned int k = 0; k < MAX_N_SCELLS; k++) {
290 for (
unsigned int i = 0; i < nSuperLayers; i++) {
291 for (
unsigned int j = 0; j < MAX_N_LAYERS; j++) {
292 for (
unsigned int k = 0; k < MAX_N_SCELLS; k++) {
309 vector<int> filtered_hit;
310 for (
int i = 0; i <
m_cdcHits.getEntries(); ++i) {
311 filtered_hit.push_back(0);
316 int ncdchit_asic[500][6] = {0};
317 vector<int> id_ncdchit_asic[500][6];
318 for (
int i = 0; i <
m_cdcHits.getEntries(); ++i) {
320 if (cdcrawHits.
size() > 0) {
324 int asicid = fechid / 8;
325 if (boardid >= 0 && boardid < 500 && asicid >= 0 && asicid < 6) {
326 ncdchit_asic[boardid][asicid]++;
327 id_ncdchit_asic[boardid][asicid].push_back(i);
332 for (
int i = 0; i < 500; i++) {
333 for (
int j = 0; j < 6; j++) {
334 if (ncdchit_asic[i][j] >= 4) {
335 std::vector<short> tdc_asic;
336 for (
int k = 0; k < ncdchit_asic[i][j]; k++) {
337 short tdc =
m_cdcHits[id_ncdchit_asic[i][j][k]]->getTDCCount();
338 tdc_asic.push_back(tdc);
340 std::sort(tdc_asic.begin(), tdc_asic.end());
341 for (
int ncoin = ncdchit_asic[i][j]; ncoin >= 4; ncoin--) {
342 for (
int k = 0; k < ncdchit_asic[i][j] - ncoin; k++) {
343 if (tdc_asic[k + ncoin - 1] - tdc_asic[k] <= 16) {
344 for (
int l = k; l < k + ncoin - 1; l++) {
345 filtered_hit[id_ncdchit_asic[i][j][l]] = 1;
360 for (
int i = 0; i <
m_cdcHits.getEntries(); ++i) {
365 if (!
deadch_map[h.getISuperLayer()][h.getILayer()][h.getIWire()]) {
370 if (filtered_hit[i] == 1)
continue;
376 const int tdcCount = floor((cdc.getT0(
WireID(h.getID())) / cdc.getTdcBinWidth()
377 - h.getTDCCount() + 0.5) / 2);
378 TRGTime rise =
TRGTime(tdcCount,
true, w.signal().clock(), w.name());
384 if (w.hit())
continue;
388 0, 0, 0, 0, 0, 0, 0, 0);
395 unsigned neibor_hit[10][1000] = {};
396 for (
unsigned isl = 0; isl <
tsLayers.size(); ++isl) {
397 for (
unsigned its = 0; its <
tsLayers[isl]->nCells(); ++its) {
404 neibor_hit[isl][its] = 1;
410 for (
unsigned isl = 0; isl <
tsLayers.size(); ++isl) {
411 for (
unsigned its = 0; its <
tsLayers[isl]->nCells(); ++its) {
423 if (s.priorityPosition() != 3 && (neibor_hit[isl][(its - 1) %
tsLayers[isl]->nCells()] == 1
424 || neibor_hit[isl][(its + 1) %
tsLayers[isl]->nCells()] == 1))
continue;
430 s.priorityPosition(),
431 s.LUT()->getValue(s.lutPattern()),
436 for (
unsigned iw = 0; iw < s.wires().size(); ++iw) {
440 double weight = (wire == &(s.priority())) ? 2. : 1.;
446 for (
unsigned imc = 0; imc < mcrel.
size(); ++imc) {
447 mcrel[imc]->addRelationTo(tsHit, mcrel.
weight(imc));
476 for (
unsigned ic = 0; ic <
clocks.size(); ++ic) {
482 for (
unsigned isl = 0; isl <
superLayers.size(); ++isl) {
483 for (
unsigned il = 0; il <
superLayers[isl].size(); ++il) {
484 for (
unsigned iw = 0; iw <
superLayers[isl][il]->nCells(); ++iw) {
494 for (
unsigned isl = 0; isl <
tsLayers.size(); ++isl) {
495 for (
unsigned its = 0; its <
tsLayers[isl]->nCells(); ++its) {
505 ostream_iterator<unsigned> innerIterator(innerFile,
" ");
512 ostream_iterator<unsigned> outerIterator(outerFile,
" ");
525 for (
unsigned isl = 0; isl <
superLayers.size(); ++isl) {
526 for (
unsigned il = 0; il <
superLayers[isl].size(); ++il) {
527 for (
unsigned iw = 0; iw <
superLayers[isl][il]->nCells(); ++iw) {
533 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...
The CDCRawHit (suppressed mode) class.
unsigned short getBoardId(void) const
Getter for boar ID.
unsigned short getFEChannel(void) const
Getter for FE channel.
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.
std::vector< TRGCDCLayer * > tsLayers
structure to hold pointers to all track segment shapes
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.
virtual void event() override
Run the TSF for an event.
OptionalDBObjPtr< CDCTriggerDeadch > m_db_deadchannel
dbobject to store deadchannel
StoreArray< CDCTriggerSegmentHit > m_segmentHits
list of output track segment hits
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 > > innerTrueLRTable
list of (# true right, # true left, # true background) for the inner-most super layer
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
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
bool deadch_map[nSuperLayers][MAX_N_LAYERS][MAX_N_SCELLS]
bad channel mapping
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...
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.
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.