13#define TRG_SHORT_NAMES
14#define TRGCDC_SHORT_NAMES
17#include "trg/trg/Utilities.h"
18#include "trg/trg/Debug.h"
19#include "trg/cdc/Wire.h"
20#include "trg/cdc/WireHit.h"
21#include "trg/cdc/Segment.h"
22#include "trg/cdc/SegmentHit.h"
23#include "trg/cdc/LUT.h"
25#include <framework/datastore/StoreArray.h>
26#include <cdc/dataobjects/CDCHit.h>
27#include <trg/cdc/dataobjects/CDCTriggerSegmentHit.h>
28#include <mdst/dataobjects/MCParticle.h>
30#define P3D HepGeom::Point3D<double>
42 const std::string& TSLUTFile,
43 const std::vector<const TCWire*>& cells)
69 const std::string& pre)
const
71 std::cout << pre <<
name() <<
" (ptn=" <<
hitPattern() <<
")" << std::endl;
72 if ((msg.find(
"geometry") != std::string::npos) ||
73 (msg.find(
"detail") != std::string::npos)) {
74 std::cout << pre <<
"id " <<
id();
75 std::cout <<
",local " <<
localId();
76 std::cout <<
",layer " <<
layerId();
79 std::cout << std::endl;
81 if ((msg.find(
"hit") != std::string::npos) ||
82 (msg.find(
"detail") != std::string::npos)) {
83 std::cout << pre <<
"Wires ";
84 for (
unsigned i = 0; i <
m_wires.size(); i++) {
85 std::cout <<
m_wires[i]->name();
89 std::cout << std::endl;
92 std::cout << pre <<
"no wire hit" << std::endl;
94 std::cout << pre <<
"WHit dump : ";
95 for (
unsigned i = 0; i <
m_hits.size(); i++) {
96 std::cout <<
m_hits[i]->cell().name();
100 std::cout << std::endl;
102 for (
unsigned i = 0; i <
m_hits.size(); i++) {
103 m_hits[i]->dump(msg, pre +
" ");
107 std::cout << pre <<
"SHit dump" << std::endl;
110 std::cout << pre <<
"no TSHit" << std::endl;
119 if ((msg.find(
"trigger") != std::string::npos) ||
120 (msg.find(
"detail") != std::string::npos)) {
124 std::cout << pre <<
"no trigger signal" << std::endl;
145 std::string n0 = std::string(
"TS") + TRGUtil::itostring(
layerId());
146 std::string n1 = TRGUtil::itostring(
localId());
152 const std::string& cdcCollectionName,
const std::string& tsCollectionName)
156 for (
unsigned i = 0, n =
m_wires.size(); i < n; i++) {
165 if (clockSimulation) {
178 const unsigned n =
m_wires.size();
180 std::vector<TRGSignal> signals;
183 for (
unsigned i = 0; i < n; i++) {
186 const TCWHit* h =
m_wires[i]->hit();
192 signals.push_back(s);
195 const unsigned width = signals.back().clock().unit(1000);
196 signals.back().widen(width);
202 if (logicLUTFlag == 0) {
218 l0 = signals[0] | signals[1] | signals[2];
219 l1 = signals[3] | signals[4];
221 l3 = signals[6] | signals[7];
222 l4 = signals[8] | signals[9] | signals[10];
232 all = l2 & (wo1 | wo2 | wo3 | wo4);
234 }
else if (n == 15) {
238 l1 = signals[1] | signals[2];
239 l2 = signals[3] | signals[4] | signals[5];
240 l3 = signals[6] | signals[7] | signals[8] | signals[9];
241 l4 = signals[10] | signals[11] | signals[12] | signals[13] | signals[14];
246 all = l0 & (wo1 | wo2 | wo3 | wo4);
262 if (logicLUTFlag == 1) {
265 std::vector<TRGSignal> hitSignals;
266 hitSignals.reserve(signals.size());
267 for (
unsigned iWire = 0; iWire < signals.size(); iWire++) {
268 if (signals[iWire].active()) hitSignals.push_back(signals[iWire]);
272 if (hitSignals.size() != 0) {
273 allSignals = hitSignals[0];
274 for (
unsigned iHitWire = 1; iHitWire < hitSignals.size(); iHitWire++) {
275 allSignals = allSignals & hitSignals[iHitWire];
306 for (
unsigned i = 0, n =
m_wires.size(); i < n; ++i) {
309 int clk0 = s[0]->time();
310 int clk1 = s[s.nEdges() - 2]->time();
311 if (clk0 < clkMin) clkMin = clk0;
312 if (clk1 > clkMax) clkMax = clk1;
318 const int width = 16 * step;
319 clkMin -= clkMin % step;
320 clkMax -= clkMax % step;
321 int lastLutValue = 0;
322 int lastPriority = 0;
324 for (
int iclk = clkMin; iclk <= clkMax; iclk += step) {
326 unsigned pattern =
lutPattern(iclk - width, iclk + step);
327 int lutValue =
m_TSLUT->getValue(pattern);
333 if ((lastLutValue == 3 && lutValue != 3) ||
334 (lastPriority != 3 && priorityPos == 3) ||
335 fastest != lastFastest) {
342 int ipr = (priorityPos == 3) ? 0 : priorityPos;
345 int tdc = priorityWire->
signal()[0]->time();
346 if (tdc < iclk - width) {
347 for (
unsigned itdc = 2, edges = priorityWire->
signal().
nEdges(); itdc < edges; itdc += 2) {
348 tdc = priorityWire->
signal()[itdc]->time();
349 if (tdc >= iclk - width)
break;
364 for (
unsigned iw = 0; iw <
m_wires.size(); ++iw) {
365 if (
m_wires[iw]->
signal().active(iclk - width, iclk + step)) {
367 double weight = (
m_wires[iw] == priorityWire) ? 2. : 1.;
373 for (
unsigned imc = 0; imc < mcrel.
size(); ++imc) {
374 mcrel[imc]->addRelationTo(storeHit, mcrel.
weight(imc));
377 lastLutValue = lutValue;
378 lastPriority = priorityPos;
379 lastFastest = fastest;
391 float tmpFastTime = 9999;
392 for (
unsigned i = 0; i <
m_wires.size(); i++) {
394 float dt =
m_wires[i]->signal()[0]->time();
395 if (dt < tmpFastTime) {
409 for (
unsigned iw = 0; iw <
m_wires.size(); ++iw) {
411 for (
unsigned itdc = 0, edges =
m_wires[iw]->
signal().nEdges(); itdc < edges; itdc += 2) {
412 float dt =
m_wires[iw]->signal()[itdc]->time();
414 if (dt < fastest) fastest = dt;
427 float tmpFoundTime[5] = {9999, 9999, 9999, 9999, 9999};
428 for (
unsigned i = 0; i <
m_wires.size(); i++) {
430 float dt =
m_wires[i]->signal()[0]->time();
433 if (tmpFoundTime[0] > dt) tmpFoundTime[0] = dt;
435 if (tmpFoundTime[1] > dt) tmpFoundTime[1] = dt;
437 if (tmpFoundTime[2] > dt) tmpFoundTime[2] = dt;
439 if (tmpFoundTime[3] > dt) tmpFoundTime[3] = dt;
441 if (tmpFoundTime[4] > dt) tmpFoundTime[4] = dt;
445 if (tmpFoundTime[0] > dt) tmpFoundTime[0] = dt;
447 if (tmpFoundTime[1] > dt) tmpFoundTime[1] = dt;
449 if (tmpFoundTime[2] > dt) tmpFoundTime[2] = dt;
451 if (tmpFoundTime[3] > dt) tmpFoundTime[3] = dt;
453 if (tmpFoundTime[4] > dt) tmpFoundTime[4] = dt;
457 std::sort(tmpFoundTime, tmpFoundTime + 5);
458 return tmpFoundTime[3];
467 if (prioritySignal.
active()) {
468 return prioritySignal[0]->time();
490 if ((priorityL->
signal()[0]->time()) >= (priorityR->
signal()[0]->time()))
return 1;
516 if ((priorityL->
signal()[0]->time()) >= (priorityR->
signal()[0]->time()))
return 1;
529 int offset = (
m_wires.size() == 15) ? 0 : 5;
539 for (
unsigned i = 0; i <
m_wires.size(); i++) {
549 std::vector<float> timeptn;
550 timeptn.reserve(
m_wires.size());
551 for (
unsigned i = 0; i <
m_wires.size(); i++) {
554 timeptn.push_back(s[0]->time());
556 timeptn.push_back(-1);
565 for (
unsigned i = 0; i <
m_wires.size(); i++) {
577 for (
unsigned i = 0; i <
m_wires.size(); i++) {
579 if (s.active(clk0, clk1))
598 unsigned outValue = (
hitPattern(clk0, clk1)) * 2;
608 const unsigned n =
m_wires.size();
609 for (
unsigned i = 0; i < n; i++) {
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Combination of several CDCHits to a track segment hit for the trigger.
A Class to store the Monte Carlo particle information.
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.
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.
std::vector< const TRGCDCWire * > m_wires
Wires.
std::vector< const CDCTriggerSegmentHit * > m_storeHits
list of DataStore hits.
TRGSignal m_signal
Trigger signal.
std::string m_TSLUTFileName
TS LUT file name.
TRGCDCLUT * m_TSLUT
LookUp Table. 0: no hit, 1: right, 2: left, 3: not determined.
std::vector< const TRGCDCWireHit * > m_hits
Wire hits.
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.
virtual bool hasMember(const std::string &a) const override
returns true this has member named a.
std::string name(void) const override
returns name.
const TRGCDCWire & center(void) const
returns a center wire.
unsigned nEdges(void) const
returns # of edges.
const HepGeom::Point3D< double > & forwardPosition(void) const
returns position in forward endplate.
double absoluteTime(int clockPosition) const
returns absolute time of clock position
int priorityPosition(void) const
return priority cell position in TSHit. 0: no hit, 3: 1st priority, 1: 2nd right, 2: 2nd left
float fastestTime(void) const
return fastest time in TSHit.
unsigned id(void) const
returns id.
void addStoreHit(const CDCTriggerSegmentHit *)
sets a pointer to a CDCTriggerSegmentHit.
virtual ~TRGCDCSegment()
Destructor.
void simulateWithoutClock(bool logicLUTFlag)
simulates time-indegrated TF hit
const TRGClock & clock(void) const
returns clock.
unsigned layerId(void) const
returns layer id.
void simulateWithClock(std::string cdcCollectionName, std::string tsCollectionName)
simulates TF hit time-dependently
unsigned localLayerId(void) const
returns local layer id in a super layer.
unsigned hitPattern(void) const
returns hit pattern.
const HepGeom::Point3D< double > & backwardPosition(void) const
returns position in backward endplate.
TRGTime & reverse(void)
reverse edge.
int getValue(unsigned) const
get LUT Values
const std::string & name(void) const
returns name.
static void enterStage(const std::string &stageName)
Declare that you enter new stage.
unsigned superLayerId(void) const
returns super layer id.
const TRGSignal & signal(void) const override
returns trigger output. Null will returned if no signal.
const TRGCDCWire & priority(void) const
returns priority wire.
static TRGCDCLUT * getLUT(const std::string &filename, int)
get LUT from dictionary, load new LUT if it doesn't exist
TRGCDCSegment(unsigned id, const TRGCDCLayer &layer, const TRGCDCWire &w, const TRGClock &clock, const std::string &TSLUTFile, const std::vector< const TRGCDCWire * > &wires)
Constructor.
TRGTime & shift(int unit)
delays by clock unit.
const TRGCDCWireHit * hit(void) const
returns a pointer to a TRGCDCWireHit.
void initialize(void)
initialize variables.
unsigned lutPattern(void) const
hit pattern containing bit for priority position
void simulate(bool clockSimulation, bool logicLUTFlag, const std::string &cdcCollectionName=std::string(""), const std::string &tsCollectionName=std::string(""))
simulates TF hit using wire information.
const TRGCDCLUT * LUT(void) const
returns LUT
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const override
dumps debug information.
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.
float priorityTime(void) const
return priority time in TSHit.
static void leaveStage(const std::string &stageName)
Declare that you leave a stage.
unsigned hitPattern_adc(void) const
returns hit pattern with adc cut.
float foundTime(void) const
return found time in TSHit.
std::vector< float > hitPatternTime(void) const
returns hit pattern with hit time
const TRGCDCSegmentHit * hit(void) const
returns a pointer to a TRGCDCSegmentHit.
bool axial(void) const
returns true if this wire is in an axial layer.
double frequency(void) const
returns frequency in MHz.
unsigned localId(void) const
returns local id in a layer.
Abstract base class for different kinds of events.