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> 
   32#define P3D HepGeom::Point3D<double> 
   44                               const std::string& TSLUTFile,
 
   45                               const std::vector<const TCWire*>& cells)
 
   50             w.backwardPosition()),
 
   53      _signal(
std::string(
"TS_") + TRGUtil::itostring(id), clock),
 
   55      m_TSLUTFileName(TSLUTFile)
 
   72                      const string& pre)
 const 
   75    if ((msg.find(
"geometry") != string::npos) ||
 
   76        (msg.find(
"detail") != string::npos)) {
 
   77      cout << pre << 
"id " << 
id();
 
   84    if ((msg.find(
"hit") != string::npos) ||
 
   85        (msg.find(
"detail") != string::npos)) {
 
   86      cout << pre << 
"Wires ";
 
   87      for (
unsigned i = 0; i < 
_wires.size(); i++) {
 
   94      if (
_hits.size() == 0) {
 
   95        cout << pre << 
"no wire hit" << endl;
 
   97        cout << pre << 
"WHit dump : ";
 
   98        for (
unsigned i = 0; i < 
_hits.size(); i++) {
 
   99          cout << 
_hits[i]->cell().name();
 
  100          if (i < 
_hits.size() - 1)
 
  105        for (
unsigned i = 0; i < 
_hits.size(); i++) {
 
  106          _hits[i]->dump(msg, pre + 
"    ");
 
  110        cout << pre << 
"SHit dump" << endl;
 
  113        cout << pre << 
"no TSHit" << endl;
 
  122    if ((msg.find(
"trigger") != string::npos) ||
 
  123        (msg.find(
"detail") != string::npos)) {
 
  127        cout << pre << 
"no trigger signal" << endl;
 
  148    string n0 = string(
"TS") + TRGUtil::itostring(
layerId());
 
  149    string n1 = TRGUtil::itostring(
localId());
 
  155                          const std::string& cdcCollectionName, 
const std::string& tsCollectionName)
 
  159    for (
unsigned i = 0, n = 
_wires.size(); i < n; i++) {
 
  168    if (clockSimulation) {
 
  181    const unsigned n = 
_wires.size();
 
  183    vector<TRGSignal> signals;
 
  184    for (
unsigned i = 0; i < n; i++) {
 
  187      const TCWHit* h = 
_wires[i]->hit();
 
  193      signals.push_back(s);
 
  196      const unsigned width = signals.back().clock().unit(1000);
 
  197      signals.back().widen(width);
 
  203    if (logicLUTFlag == 0) {
 
  219        l0 = signals[0] | signals[1] | signals[2];
 
  220        l1 = signals[3] | signals[4];
 
  222        l3 = signals[6] | signals[7];
 
  223        l4 = signals[8] | signals[9] | signals[10];
 
  233        all = l2 & (wo1 | wo2 | wo3 | wo4);
 
  235      } 
else if (n == 15) {
 
  239        l1 = signals[1] | signals[2];
 
  240        l2 = signals[3] | signals[4] | signals[5];
 
  241        l3 = signals[6] | signals[7] | signals[8] | signals[9];
 
  242        l4 = signals[10] | signals[11] | signals[12] | signals[13] | signals[14];
 
  247        all = l0 & (wo1 | wo2 | wo3 | wo4);
 
  263    if (logicLUTFlag == 1) {
 
  266      vector<TRGSignal> hitSignals;
 
  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];
 
  305    for (
unsigned i = 0, n = 
_wires.size(); i < n; ++i) {
 
  308        int clk0 = s[0]->time();
 
  309        int clk1 = s[s.nEdges() - 2]->time();
 
  310        if (clk0 < clkMin) clkMin = clk0;
 
  311        if (clk1 > clkMax) clkMax = clk1;
 
  317    const int width = 16 * step;
 
  318    clkMin -= clkMin % step;
 
  319    clkMax -= clkMax % step;
 
  320    int lastLutValue = 0;
 
  321    int lastPriority = 0;
 
  323    for (
int iclk = clkMin; iclk <= clkMax; iclk += step) {
 
  325      unsigned pattern = 
lutPattern(iclk - width, iclk + step);
 
  332        if ((lastLutValue == 3 && lutValue != 3) ||
 
  333            (lastPriority != 3 && priorityPos == 3) ||
 
  334            fastest != lastFastest) {
 
  341          int ipr = (priorityPos == 3) ? 0 : priorityPos;
 
  344          int tdc = priorityWire->
signal()[0]->time();
 
  345          if (tdc < iclk - width) {
 
  346            for (
unsigned itdc = 2, edges = priorityWire->
signal().
nEdges(); itdc < edges; itdc += 2) {
 
  347              tdc = priorityWire->
signal()[itdc]->time();
 
  348              if (tdc >= iclk - width) 
break;
 
  363          for (
unsigned iw = 0; iw < 
_wires.size(); ++iw) {
 
  364            if (
_wires[iw]->
signal().active(iclk - width, iclk + step)) {
 
  366              double weight = (
_wires[iw] == priorityWire) ? 2. : 1.;
 
  372          for (
unsigned imc = 0; imc < mcrel.
size(); ++imc) {
 
  373            mcrel[imc]->addRelationTo(storeHit, mcrel.
weight(imc));
 
  376          lastLutValue = lutValue;
 
  377          lastPriority = priorityPos;
 
  378          lastFastest = fastest;
 
  390      float tmpFastTime = 9999;
 
  391      for (
unsigned i = 0; i < 
_wires.size(); i++) {
 
  393          float dt = 
_wires[i]->signal()[0]->time();
 
  394          if (dt < tmpFastTime) {
 
  408    for (
unsigned iw = 0; iw < 
_wires.size(); ++iw) {
 
  410        for (
unsigned itdc = 0, edges = 
_wires[iw]->
signal().nEdges(); itdc < edges; itdc += 2) {
 
  411          float dt = 
_wires[iw]->signal()[itdc]->time();
 
  413            if (dt < fastest) fastest = dt;
 
  426      float tmpFoundTime[5] = {9999, 9999, 9999, 9999, 9999};
 
  427      for (
unsigned i = 0; i < 
_wires.size(); i++) {
 
  429        float dt = 
_wires[i]->signal()[0]->time();
 
  430        if (
_wires.size() == 11) {
 
  432            if (tmpFoundTime[0] > dt) tmpFoundTime[0] = dt;
 
  434            if (tmpFoundTime[1] > dt) tmpFoundTime[1] = dt;
 
  436            if (tmpFoundTime[2] > dt) tmpFoundTime[2] = dt;
 
  438            if (tmpFoundTime[3] > dt) tmpFoundTime[3] = dt;
 
  440            if (tmpFoundTime[4] > dt) tmpFoundTime[4] = dt;
 
  444            if (tmpFoundTime[0] > dt) tmpFoundTime[0] = dt;
 
  446            if (tmpFoundTime[1] > dt) tmpFoundTime[1] = dt;
 
  448            if (tmpFoundTime[2] > dt) tmpFoundTime[2] = dt;
 
  450            if (tmpFoundTime[3] > dt) tmpFoundTime[3] = dt;
 
  452            if (tmpFoundTime[4] > dt) tmpFoundTime[4] = dt;
 
  456      sort(tmpFoundTime, tmpFoundTime + 5);
 
  457      return tmpFoundTime[3];
 
  466    if (prioritySignal.
active()) {
 
  467      return prioritySignal[0]->time();
 
  480      if (
_wires.size() == 15) {
 
  489          if ((priorityL->
signal()[0]->time()) >= (priorityR->
signal()[0]->time())) 
return 1;
 
  506      if (
_wires.size() == 15) {
 
  515          if ((priorityL->
signal()[0]->time()) >= (priorityR->
signal()[0]->time())) 
return 1;
 
  528    int offset = (
_wires.size() == 15) ? 0 : 5;
 
  538    for (
unsigned i = 0; i < 
_wires.size(); i++) {
 
  550    for (
unsigned i = 0; i < 
_wires.size(); i++) {
 
  562    for (
unsigned i = 0; i < 
_wires.size(); i++) {
 
  564      if (s.active(clk0, clk1))
 
  583    unsigned outValue = (
hitPattern(clk0, clk1)) * 2;
 
  593    const unsigned n = 
_wires.size();
 
  594    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.
std::vector< const TRGCDCWire * > _wires
LookUp Table.
std::vector< const CDCTriggerSegmentHit * > _storeHits
list of DataStore hits.
TRGSignal _signal
Trigger signal.
std::vector< const TRGCDCWireHit * > _hits
Wire hits.
std::string m_TSLUTFileName
TS LUT file name.
TRGCDCLUT * m_TSLUT
LookUp Table. 0: no hit, 1: right, 2: left, 3: not determined.
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.
const TRGCDCWire & center(void) const
returns a center wire.
unsigned nEdges(void) const
returns # of edges.
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.
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)
initilize variables.
std::string name(void) const override
returns name.
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.
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.
void clear(void)
clears contents.
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.
void dump(const std::string &message="", const std::string &pre="") const
dumps contents.
Abstract base class for different kinds of events.