Exemple #1
0
void work(Set* _set, char op, long newTag) {
	if (op == 'I')
		return;
	long i;
	for (i = 0; i < lineNum; i++) {
		if (_set->line[i].valid > 0 && _set->line[i].tag == newTag) {
			addHit();			
			if (op == 'M') {
				addHit();
			}
			setValid(_set->line, i);
			printf("\n");
			return;
		}
	}
	addMiss();
	if (!updateLast(_set)) {
		addEvic();
	}
	setValid(_set->line, _set->lastLine);
	_set->line[_set->lastLine].tag = newTag;
	if (op == 'M'){
		addHit();
	}
	printf("\n");
}
size_t
UTF8SuffixStringFieldSearcher::matchTerms(const FieldRef & f, const size_t mintsz)
{
    (void) mintsz;
    termcount_t words = 0;
    const byte * srcbuf = reinterpret_cast<const byte *> (f.data());
    const byte * srcend = srcbuf + f.size();
    if (f.size() >= _buf->size()) {
        _buf->reserve(f.size() + 1);
    }
    cmptype_t * dstbuf = &(*_buf.get())[0];
    size_t tokenlen = 0;

    for( ; srcbuf < srcend; ) {
        if (*srcbuf == 0) {
            ++_zeroCount;
            ++srcbuf;
        }
        srcbuf = tokenize(srcbuf, _buf->capacity(), dstbuf, tokenlen);
        for (QueryTermList::iterator it = _qtl.begin(), mt = _qtl.end(); it != mt; ++it) {
            QueryTerm & qt = **it;
            const cmptype_t * term;
            termsize_t tsz = qt.term(term);
            if (matchTermSuffix(term, tsz, dstbuf, tokenlen)) {
                addHit(qt, words);
            }
        }
        words++;
    }
    return words;
}
void setTrack(GpuTrack *tr, int hit0_offset, int hit1_offset) {
  // track_ids[hit0_offset] = tr->internalId;
  tr->trackHitsNum = 1;

  double z = hit_Zs[hit0_offset];
  double x = hit_Xs[hit0_offset];
  // double w = hit_Ws[hit0_offset];

  double wz = w * z;

  tr->m_s0  = w;
  tr->m_sx  = w * x;
  tr->m_sz  = wz;
  tr->m_sxz = wz * x;
  tr->m_sz2 = wz * z;

  double y = hit_Ys[hit0_offset];

  tr->m_u0  = w;
  tr->m_uy  = w * y;
  tr->m_uz  = wz;
  tr->m_uyz = wz * y;
  tr->m_uz2 = wz * z;

  // TODO: Remove when not needed
  tr->hits.push_back(hit0_offset);

  addHit (tr, hit1_offset);
}
//=============================================================================
// reset and prepare a new track with these two hits
//=============================================================================
void PatPixelTrack::set( PatPixelHit* h1, PatPixelHit* h2 ) {
  m_backward = false;
  m_hits.clear();
  m_hits.push_back( h1 );

  double z = h1->z();
  double w = h1->wx();
  double x = h1->x();

  m_s0  = w;
  m_sx  = w * x;
  m_sz  = w * z;
  m_sxz = w * x * z;
  m_sz2 = w * z * z;

  w = h1->wy();
  double y = h1->y();

  m_u0  = w;
  m_uy  = w * y;
  m_uz  = w * z;
  m_uyz = w * y * z;
  m_uz2 = w * z * z;

  addHit( h2 );
}
size_t
UTF8StrChrFieldSearcher::matchTerms(const FieldRef & f, const size_t mintsz)
{
    (void) mintsz;
    termcount_t words(0);
    const byte * n = reinterpret_cast<const byte *> (f.data());
    const byte * e = n + f.size();
    if (f.size() >= _buf->size()) {
        _buf->reserve(f.size() + 1);
    }
    cmptype_t * fn = &(*_buf.get())[0];
    size_t fl(0);

    for( ; n < e; ) {
        if (!*n) { _zeroCount++; n++; }
        n = tokenize(n, _buf->capacity(), fn, fl);
        for(QueryTermList::iterator it=_qtl.begin(), mt=_qtl.end(); it != mt; it++) {
            QueryTerm & qt = **it;
            const cmptype_t * term;
            termsize_t tsz = qt.term(term);
            if ((tsz <= fl) && (prefix() || qt.isPrefix() || (tsz == fl))) {
                const cmptype_t *tt=term, *et=term+tsz;
                for (const cmptype_t *fnt=fn; (tt < et) && (*tt == *fnt); tt++, fnt++);
                if (tt == et) {
                    addHit(qt, words);
                }
            }
        }
        words++;
    }
    NEED_CHAR_STAT(addAnyUtf8Field(f.size()));
    return words;
}
bool addHitsOnSensor(SensorInfo *sensor, double xTol, double maxChi2, GpuTrack *tr, int eventId ) {
  if (sensor->hitsNum == 0) return false;
  int offset = eventId * hits_num;

  double xGuess = xAtHit(tr, sensor->z) - xTol; // - 1;
  int lastHit = sensor->startPosition + sensor->hitsNum - 1;

  debug << "last hit x: " << hit_Xs[offset + lastHit] << ", xguess: " << xGuess << endl;
  if(hit_Xs[offset + lastHit] < xGuess) return false;

  int hitStart = sensor->startPosition;

  debug << "(";
  for (int i = hitStart; i <= lastHit; i++)
    debug << hit_IDs[i] << ", ";
  debug << ")";

  unsigned int step = sensor->hitsNum;
  while ( step > 2 ) {
    step = step/2;
    if (hit_Xs[offset + hitStart + step] < xGuess) hitStart += step;
  }

  bool added = false;
  int tmpOffset = 0;
  double xPred;
  for(int iH=hitStart; iH<=lastHit; ++iH) {

    debug << hit_IDs[iH] << ", ";
    tmpOffset = offset + iH;

    if ( hit_IDs[iH] == 172290464 ) {
      debug << " -- The chi2 of 172290464 is: " << chi2Track(tr, tmpOffset) << std::endl;
      debug << "x: " << hit_Xs[tmpOffset] << ", y:" << hit_Ys[tmpOffset] << endl;
    }

    if ( hit_IDs[iH] == 163710761 ) {
      debug << " -- The chi2 of 163710761 is: " << chi2Track(tr, tmpOffset) << std::endl;
      debug << "x: " << hit_Xs[tmpOffset] << ", y:" << hit_Ys[tmpOffset] << endl;
      debug << "maxChi2: " << maxChi2 << endl;
    }


    xPred = xAtHit(tr, hit_Zs[tmpOffset]);
    if ( hit_Xs[tmpOffset] + xTol < xPred ) continue;
    if ( hit_Xs[tmpOffset] - xTol > xPred ) break;
    if ( chi2Track(tr, tmpOffset) < maxChi2 ) {
      addHit(tr, tmpOffset);
      // *usedHit = tmpOffset; - Used hits are tagged by the end of the algorithm, not before.
      added = true;
    }
  }

  debug << endl;
  return added;
}
Exemple #7
0
void StatsSet::calculateStats(const vector<PositionWeightMatrix::MotifMatch> &M1_matches, const vector<PositionWeightMatrix::MotifMatch> &M2_matches)
{
  vector<PositionWeightMatrix::MotifMatch>::const_iterator jrt_head = M2_matches.begin();
  vector<PositionWeightMatrix::MotifMatch>::const_iterator jrt_tail = M2_matches.begin();

/* We need to filter jrts. There are two cases:
(1) same orientation: looking for jrts satisfying
      min_offset <= jrt->start - irt->start <= max_offset
      irt->start + min_offset <= jrt->start <= irt->start + max_offset

(2) opposite orientation: looking for jrts satisfying
      min_offset <= irt->end - jrt->end <= max_offset
      min_offset <= irt->start + M1->length - jrt->start - M2->length <= max_offset
      - max_offset <= - irt->start - M1->length + jrt->start + M2->length <= - min_offset
      irt->start + M1->length - M2->length - max_offset <= jrt->start <= irt->start + M1->length - M2->length - min_offset
      irt->start + M1->length - M2->length - max_offset <= jrt->start <= irt->start + M1->length - M2->length - min_offset
    but
      M1->length - M2->length - max_offset = M1->length - M2->length - M1->length - margin + 1 = min_offset
      M1->length - M2->length - min_offset = M1->length - M2->length + M2->length + margin - 1 = max_offset
    so the above inequalities are equivalent to
      irt->start + min_offset <= jrt->start <= irt->start + max_offset. */

  for (vector<PositionWeightMatrix::MotifMatch>::const_iterator irt = M1_matches.begin(); irt != M1_matches.end(); irt++)
  {
    while (jrt_head != M2_matches.end() && jrt_head->chrom_id < irt->chrom_id)
      jrt_head++;
    while (jrt_head != M2_matches.end() && jrt_head->chrom_id == irt->chrom_id && jrt_head->start < irt->start + min_offset)
      jrt_head++;

    while (jrt_tail != M2_matches.end() && jrt_tail->chrom_id < irt->chrom_id)
      jrt_tail++;
    while (jrt_tail != M2_matches.end() && jrt_tail->chrom_id == irt->chrom_id && jrt_tail->start <= irt->start + max_offset)
      jrt_tail++;

    for (vector<PositionWeightMatrix::MotifMatch>::const_iterator jrt = jrt_head; jrt != jrt_tail; jrt++)
    {
      if (irt->strand == '+')
        addHit(jrt->start - irt->start, jrt->strand == '+');
      else
        addHit(irt->start + M1->length - jrt->start - M2->length, jrt->strand != '+');
    }
  }
}
Exemple #8
0
void Stats::addInfo(const HitInfo& info)
{
    switch (info.type)
    {
    case HitInfo::HIT:
        addHit();
        break;
    case HitInfo::MISS:
        addMiss();
        break;
    default:
        break;
    }
}
Exemple #9
0
void Interpret::addEvent()
{
	if (Basis::debugSet()) {
		std::stringstream tDebug;
		tDebug << "addEvent() " << _nEvents;
		debug(tDebug.str());
	}
	if (tTotalHits == 0) {
		_nEmptyEvents++;
		if (_createEmptyEventHits) {
			addEventErrorCode(__NO_HIT);
			addHit(0, 0, 0, 0, 0, 0);
		}
	}
	if (tTriggerWord == 0) {
		addEventErrorCode(__NO_TRG_WORD);
		if (_firstTriggerNrSet)  // set the last existing trigger number for events without trigger number if trigger numbers exist
			tEventTriggerNumber = _lastTriggerNumber;
	}
	if (tTriggerWord > 1) {
		addTriggerErrorCode(__TRG_NUMBER_MORE_ONE);
		if (Basis::warningSet())
			warning(std::string("addEvent: # trigger words > 1 at event " + LongIntToStr(_nEvents)));
	}
	if (_useTdcTriggerTimeStamp && tTdcTimeStamp >= 254)
		addEventErrorCode(__TDC_OVERFLOW);

	storeEventHits();
	if (tTotalHits > _nMaxHitsPerEvent)
		_nMaxHitsPerEvent = tTotalHits;
	histogramTriggerErrorCode();
	histogramErrorCode();
	if (_createMetaDataWordIndex) {
		if (_actualMetaWordIndex < _metaWordIndexLength) {
			_metaWordIndex[_actualMetaWordIndex].eventIndex = _nEvents;
			_metaWordIndex[_actualMetaWordIndex].startWordIdex = _startWordIndex;
			_metaWordIndex[_actualMetaWordIndex].stopWordIdex = _nDataWords - 1;
			_startWordIndex = _nDataWords - 1;
			_actualMetaWordIndex++;
		}
		else {
			std::stringstream tInfo;
			tInfo << "Interpret::addEvent(): meta word index array is too small " << _actualMetaWordIndex << ">=" << _metaWordIndexLength;
			throw std::out_of_range(tInfo.str());
		}
	}
	_nEvents++;
	resetEventVariables();
}
void Clusterizer::addHits(HitInfo*& rHitInfo, const unsigned int& rNhits)
{
  if(Basis::debugSet())
	  debug("addHits(...,rNhits="+IntToStr(rNhits)+")");

  _hitInfo = rHitInfo;
  _Nclusters = 0;

  if(rNhits>0 && _actualEventNumber != 0 && rHitInfo[0].eventNumber == _actualEventNumber)
	  warning("addHits: Hit chunks not aligned at events. Clusterizer will not work properly");

  for(unsigned int i = 0; i<rNhits; i++){
	  if(_actualEventNumber != rHitInfo[i].eventNumber){
		  clusterize();
		  addHitClusterInfo(i);
		  clearActualEventVariables();
	  }
	  _actualEventNumber = rHitInfo[i].eventNumber;
	  addHit(i);
  }
//  //manually add remaining hit data
  clusterize();
  addHitClusterInfo(rNhits);
}
Exemple #11
0
bool Interpret::interpretRawData(unsigned int* pDataWords, const unsigned int& pNdataWords)
{
	if (Basis::debugSet()) {
		std::stringstream tDebug;
		tDebug << "interpretRawData with " << pNdataWords << " words at total word " << _nDataWords;
		debug(tDebug.str());
	}
	_hitIndex = 0;
	_actualMetaWordIndex = 0;

	int tActualCol1 = 0;				//column position of the first hit in the actual data record
	int tActualRow1 = 0;				//row position of the first hit in the actual data record
	int tActualTot1 = -1;				//tot value of the first hit in the actual data record
	int tActualCol2 = 0;				//column position of the second hit in the actual data record
	int tActualRow2 = 0;				//row position of the second hit in the actual data record
	int tActualTot2 = -1;				//tot value of the second hit in the actual data record

	for (unsigned int iWord = 0; iWord < pNdataWords; ++iWord) {	//loop over the SRAM words
		if (_debugEvents) {
			if (_nEvents >= _startDebugEvent && _nEvents <= _stopDebugEvent)
				setDebugOutput();
			else
				setDebugOutput(false);
			setInfoOutput(false);
			setWarningOutput(false);  // FIXME: do not unset this always
		}

		correlateMetaWordIndex(_nEvents, _dataWordIndex);
		_nDataWords++;
		_dataWordIndex++;
		unsigned int tActualWord = pDataWords[iWord];			//take the actual SRAM word
		tActualTot1 = -1;												          //TOT1 value stays negative if it can not be set properly in getHitsfromDataRecord()
		tActualTot2 = -1;												          //TOT2 value stays negative if it can not be set properly in getHitsfromDataRecord()
		if (getTimefromDataHeader(tActualWord, tActualLVL1ID, tActualBCID)) {	//data word is data header if true is returned
			_nDataHeaders++;
			if (tNdataHeader > _NbCID - 1) {	                //maximum event window is reached (tNdataHeader > BCIDs, mostly tNdataHeader > 15), so create new event
				if (_alignAtTriggerNumber) {
					addEventErrorCode(__TRUNC_EVENT); //too many data header in the event, abort this event, add truncated flac
					if (Basis::warningSet())
						warning(std::string("addHit: Hit buffer overflow prevented by splitting events at event " + LongIntToStr(_nEvents)), __LINE__);
				}
				addEvent();
			}
			if (tNdataHeader == 0) {								        //set the BCID of the first data header
				tStartBCID = tActualBCID;
				tStartLVL1ID = tActualLVL1ID;
			}
			else {
				tDbCID++;										        //increase relative BCID counter [0:15]
				if (_fEI4B) {
					if (tStartBCID + tDbCID > __BCIDCOUNTERSIZE_FEI4B - 1)	//BCID counter overflow for FEI4B (10 bit BCID counter)
						tStartBCID = tStartBCID - __BCIDCOUNTERSIZE_FEI4B;
				}
				else {
					if (tStartBCID + tDbCID > __BCIDCOUNTERSIZE_FEI4A - 1)	//BCID counter overflow for FEI4A (8 bit BCID counter)
						tStartBCID = tStartBCID - __BCIDCOUNTERSIZE_FEI4A;
				}

				if (tStartBCID + tDbCID != tActualBCID) {  //check if BCID is increasing by 1s in the event window, if not close actual event and create new event with actual data header
					if (tActualLVL1ID == tStartLVL1ID) //happens sometimes, non inc. BCID, FE feature, only abort the LVL1ID is not constant (if no external trigger is used or)
						addEventErrorCode(__BCID_JUMP);
					else if (_alignAtTriggerNumber || _alignAtTdcWord)  //rely here on the trigger number or TDC word and do not start a new event
						addEventErrorCode(__BCID_JUMP);
					else {
						tBCIDerror = true;					       //BCID number wrong, abort event and take actual data header for the first hit of the new event
						addEventErrorCode(__EVENT_INCOMPLETE);
					}
				}
				if (!tBCIDerror && tActualLVL1ID != tStartLVL1ID) {    //LVL1ID not constant, is expected for CMOS pulse trigger/hit OR, but not for trigger word triggering
					addEventErrorCode(__NON_CONST_LVL1ID);
					if (Basis::infoSet())
						info("interpretRawData: LVL1 is not constant: " + IntToStr(tActualLVL1ID) + "!=" + IntToStr(tStartLVL1ID) + " at event " + LongIntToStr(_nEvents));
				}
			}
			tNdataHeader++;										       //increase data header counter
			if (Basis::debugSet())
				debug(std::string(" ") + IntToStr(_nDataWords) + " DH LVL1ID/BCID " + IntToStr(tActualLVL1ID) + "/" + IntToStr(tActualBCID) + "\t" + LongIntToStr(_nEvents));
		}
		else if (isTriggerWord(tActualWord)) { //data word is trigger word, is first word of the event data if external trigger is present
			_nTriggers++;						//increase the total trigger number counter
			if (!_alignAtTriggerNumber) {			// first word is not always the trigger number
				if (tNdataHeader > _NbCID - 1)
					addEvent();
			}
			else if (_firstTriggerNrSet) {		// use trigger number for event building, first word is trigger word in data stream
				addEvent();
			}
			tTriggerWord++;                     //trigger event counter increase

			if (!_useTriggerTimeStamp)
				tTriggerNumber = TRIGGER_NUMBER_MACRO_NEW(tActualWord); //actual trigger number
			else
				tTriggerNumber = TRIGGER_TIME_STAMP_MACRO(tActualWord); //actual trigger number is a time stamp

			if (Basis::debugSet()) {
				if (!_useTriggerTimeStamp)
					debug(std::string(" ") + IntToStr(_nDataWords) + " TR NUMBER " + IntToStr(tTriggerNumber) + "\t WORD " + IntToStr(tActualWord) + "\t" + LongIntToStr(_nEvents));
				else
					debug(std::string(" ") + IntToStr(_nDataWords) + " TR TIME STAMP " + IntToStr(tTriggerNumber) + "\t WORD " + IntToStr(tActualWord) + "\t" + LongIntToStr(_nEvents));
			}

			//TLU error handling
			if (!_firstTriggerNrSet)
				_firstTriggerNrSet = true;
			else if (!_useTriggerTimeStamp && (_lastTriggerNumber + 1 != tTriggerNumber) && !(_lastTriggerNumber == _maxTriggerNumber && tTriggerNumber == 0)) {
				addTriggerErrorCode(__TRG_NUMBER_INC_ERROR);
				if (Basis::warningSet())
					warning("interpretRawData: Trigger Number not increasing by 1 (old/new): " + IntToStr(_lastTriggerNumber) + "/" + IntToStr(tTriggerNumber) + " at event " + LongIntToStr(_nEvents));
			}

			if (tTriggerWord == 1)  			// event trigger number is trigger number of first trigger word within the event
				tEventTriggerNumber = tTriggerNumber;

			_lastTriggerNumber = tTriggerNumber;
		}
		else if (getInfoFromServiceRecord(tActualWord, tActualSRcode, tActualSRcounter)) { //data word is service record
			if (Basis::debugSet())
				debug(std::string(" ") + IntToStr(_nDataWords) + " SR " + IntToStr(tActualSRcode) + " (" + IntToStr(tActualSRcounter) + ") at event " + LongIntToStr(_nEvents));
			addServiceRecord(tActualSRcode, tActualSRcounter);
			addEventErrorCode(__HAS_SR);
			_nServiceRecords++;
		}
		else if (isTdcWord(tActualWord)) {	//data word is a tdc word
			addTdcValue(TDC_COUNT_MACRO(tActualWord));
			_nTDCWords++;
			if (_useTdcTriggerTimeStamp && (TDC_TRIG_DIST_MACRO(tActualWord) > _maxTdcDelay)){  // of the trigger distance if > _maxTdcDelay the TDC word does not belong to this event, thus ignore it
				if (Basis::debugSet())
					debug(std::string(" ") + IntToStr(_nDataWords) + " TDC COUNT " + IntToStr(TDC_COUNT_MACRO(tActualWord)) + "\t" + LongIntToStr(_nEvents) + "\t TRG DIST TIME STAMP " + IntToStr(TDC_TRIG_DIST_MACRO(tActualWord)) + "\t WORD " + IntToStr(tActualWord));
				continue;
			}

			//create new event if the option to align at TDC words is active AND the previous event has seen already all needed data headers OR the previous event was not aligned at a TDC word
			if (_alignAtTdcWord && _firstTdcSet && ( (tNdataHeader > _NbCID - 1) || ((tErrorCode & __TDC_WORD) != __TDC_WORD) )) {
				addEvent();
			}

			_firstTdcSet = true;

			if ((tErrorCode & __TDC_WORD) == __TDC_WORD) {  //if the event has already a TDC word set __MANY_TDC_WORDS
				if (!_useTdcTriggerTimeStamp)  // the first TDC word defines the event TDC value
					addEventErrorCode(__MANY_TDC_WORDS);
				else if (TDC_TRIG_DIST_MACRO(tActualWord) != 255) {  // in trigger time measurement mode the valid TDC word (tTdcTimeStamp != 255) defines the event TDC value
					if (tTdcTimeStamp != 255)  // there is already a valid TDC word for this event
						addEventErrorCode(__MANY_TDC_WORDS);
					else {
						tTdcTimeStamp = TDC_TRIG_DIST_MACRO(tActualWord);
						tTdcCount = TDC_COUNT_MACRO(tActualWord);
					}
				}
			}
			else {
				addEventErrorCode(__TDC_WORD);
				tTdcCount = TDC_COUNT_MACRO(tActualWord);
				if (!_useTdcTriggerTimeStamp)
					tTdcTimeStamp = TDC_TIME_STAMP_MACRO(tActualWord);
				else
					tTdcTimeStamp = TDC_TRIG_DIST_MACRO(tActualWord);
			}
			if (tTdcCount == 0)
				addEventErrorCode(__TDC_OVERFLOW);
			if (Basis::debugSet()) {
				if (_useTdcTriggerTimeStamp)
					debug(std::string(" ") + IntToStr(_nDataWords) + " TDC COUNT " + IntToStr(TDC_COUNT_MACRO(tActualWord)) + "\t" + LongIntToStr(_nEvents) + "\t TRG DIST TIME STAMP " + IntToStr(TDC_TRIG_DIST_MACRO(tActualWord)) + "\t WORD " + IntToStr(tActualWord));
				else
					debug(std::string(" ") + IntToStr(_nDataWords) + " TDC COUNT " + IntToStr(TDC_COUNT_MACRO(tActualWord)) + "\t" + LongIntToStr(_nEvents) + "\t TIME STAMP " + IntToStr(TDC_TIME_STAMP_MACRO(tActualWord)) + "\t WORD " + IntToStr(tActualWord));
			}
		}
		else if (isDataRecord(tActualWord)) {	//data word is data record if true is returned
			if (getHitsfromDataRecord(tActualWord, tActualCol1, tActualRow1, tActualTot1, tActualCol2, tActualRow2, tActualTot2)) {
				tNdataRecord++;										  //increase data record counter for this event
				_nDataRecords++;									  //increase total data record counter
				if (tActualTot1 >= 0)								//add hit if hit info is reasonable (TOT1 >= 0)
					addHit(tDbCID, tActualLVL1ID, tActualCol1, tActualRow1, tActualTot1, tActualBCID);
				if (tActualTot2 >= 0)								//add hit if hit info is reasonable and set (TOT2 >= 0)
					addHit(tDbCID, tActualLVL1ID, tActualCol2, tActualRow2, tActualTot2, tActualBCID);
				if (Basis::debugSet()) {
					std::stringstream tDebug;
					tDebug << " " << _nDataWords << " DR COL1/ROW1/TOT1  COL2/ROW2/TOT2 " << tActualCol1 << "/" << tActualRow1 << "/" << tActualTot1 << "  " << tActualCol2 << "/" << tActualRow2 << "/" << tActualTot2 << " rBCID " << tDbCID << "\t" << _nEvents;
					debug(tDebug.str());
				}
			}
		}
		else {
			if (isOtherWord(tActualWord)) {			//other for hit interpreting uninteressting data, else data word unknown
				_nOtherWords++;
				if (Basis::debugSet()) {
					unsigned int tAddress = 0;
					bool isShiftRegister = false;
					unsigned int tValue = 0;
					if (isAddressRecord(tActualWord, tAddress, isShiftRegister)) {
						if (isShiftRegister)
							debug(std::string(" ") + IntToStr(_nDataWords) + " ADDRESS RECORD SHIFT REG. " + IntToStr(tAddress) + " WORD " + IntToStr(tActualWord) + "\t" + LongIntToStr(_nEvents));
						else
							debug(std::string(" ") + IntToStr(_nDataWords) + " ADDRESS RECORD GLOBAL REG. " + IntToStr(tAddress) + " WORD " + IntToStr(tActualWord) + "\t" + LongIntToStr(_nEvents));
					}
					if (isValueRecord(tActualWord, tValue)) {
						debug(std::string(" ") + IntToStr(_nDataWords) + " VALUE RECORD " + IntToStr(tValue) + "\t" + LongIntToStr(_nEvents));
					}
				}
			}
			else {
				addEventErrorCode(__UNKNOWN_WORD);
				_nUnknownWords++;
				if (Basis::warningSet())
					warning("interpretRawData: " + IntToStr(_nDataWords) + " UNKNOWN WORD " + IntToStr(tActualWord) + " at event " + LongIntToStr(_nEvents));
				if (Basis::debugSet())
					debug(std::string(" ") + IntToStr(_nDataWords) + " UNKNOWN WORD " + IntToStr(tActualWord) + " at event " + LongIntToStr(_nEvents));
			}
		}

		if (tBCIDerror) {	//tBCIDerror is raised if BCID is not increasing by 1, most likely due to incomplete data transmission, so start new event, actual word is data header here
			if (Basis::warningSet())
				warning("interpretRawData " + IntToStr(_nDataWords) + " BCID ERROR at event " + LongIntToStr(_nEvents));
			addEvent();
			_nIncompleteEvents++;
			getTimefromDataHeader(tActualWord, tActualLVL1ID, tStartBCID);
			tNdataHeader = 1;									//tNdataHeader is already 1, because actual word is first data of new event
			tStartBCID = tActualBCID;
			tStartLVL1ID = tActualLVL1ID;
		}
	}
	return true;
}
Exemple #12
0
void searchByPair(int eventId, vector<GpuTrack>& tracks_vector) {
  int lastSensor  = sens_num - 1;
  int firstSensor = 2;

  GpuTrack m_track;

  bool* hit_isUseds = (bool*) calloc(hits_num, sizeof(bool));

  // helper variables
  int event_sensor_displ = eventId * sens_num;
  int event_hit_displ    = eventId * hits_num;

  int sens0, sens1, first1, hit0_no, hit1_no;
  SensorInfo sensor0, sensor1, extra_sensor;
  double dxMax, dyMax;

  debug << "-- searchByPair --" << endl
    << "Number of sensors: " << sens_num << endl
    << "Number of hits: " << hits_num << endl;

  debug << "Starting hits processing..." << endl;

  // Iterate from the last until the first+1 (including it)
  for ( sens0 = lastSensor; firstSensor <= sens0; sens0 -= 1 ) {
    // sens1 is next sensor on the same side
    sens1 = sens0 - 2;

    sensor0.startPosition = sensor_hitStarts [event_sensor_displ + sens0];
    sensor0.hitsNum       = sensor_hitNums   [event_sensor_displ + sens0];
    sensor0.z             = sensor_Zs        [event_sensor_displ + sens0];
    sensor1.startPosition = sensor_hitStarts [event_sensor_displ + sens1];
    sensor1.hitsNum       = sensor_hitNums   [event_sensor_displ + sens1];
    sensor1.z             = sensor_Zs        [event_sensor_displ + sens1];

    /*
       debug << "sensor 0: " << endl
       << " Z: " << sensor0.z << endl
       << " sP: " << sensor0.startPosition << endl
       << " hitsNum: " << sensor0.hitsNum << endl;
       */

    // Indicator of max dx, dy permissible over next hit
    dxMax = m_maxXSlope * fabs( sensor1.z - sensor0.z );
    dyMax = m_maxYSlope * fabs( sensor1.z - sensor0.z );

    first1 = 0;
    for (hit0_no = 0; hit0_no < sensor0.hitsNum; hit0_no++) {
      int hit0_offset = event_hit_displ + sensor0.startPosition + hit0_no;
      if ( hit_isUseds[hit0_offset - event_hit_displ] ) {
        continue;
      }
      double x0  = hit_Xs[hit0_offset];
      double y0  = hit_Ys[hit0_offset];

      // Min and max x permissible over next hit
      double xMin = x0 - dxMax;
      double xMax = x0 + dxMax;

      // Iterate hits in s1
      for (hit1_no = first1; hit1_no < sensor1.hitsNum; hit1_no++) {

        int hit1_offset = event_hit_displ + sensor1.startPosition + hit1_no;
        double x1 = hit_Xs[hit1_offset];

        //  debug << " hit " << hit_IDs[hit0_offset] << " against: " << hit_IDs[hit1_offset] << endl;

        // Require second hit not to be used, and to be within x limits
        if ( x1 < xMin ) {
          first1 = hit1_no + 1; // Start on the item (hit1_no+1) for next iteration
          continue;
        }
        if ( x1 > xMax ) {
          break; // hits are ordered by x (clever)
        }
        if ( hit_isUseds[hit1_offset - event_hit_displ] ) {
          continue;
        }

        // Check hit is within y limits
        double y1  = hit_Ys[hit1_offset];
        if ( fabs( y1 - y0 ) > dyMax ) {
          continue;
        }

        // Creates a GpuTrack starting at itH0 (first hit) and containing itH1 (second hit - addHit)
        m_track.hits.clear();
        setTrack(&m_track, hit0_offset, hit1_offset);

        debug << endl << "hit" << hit_IDs[hit0_offset] << " and hit" << hit_IDs[hit1_offset] << " are compatible, creating GpuTrack" << endl;

        //== Cut on R2Beam if needed : backward tracks, i.e zBeam > first hit
        if (sensor0.z < m_maxZForRBeamCut) {
          double z_beam  = zBeam(&m_track);
          if ( z_beam > sensor0.z ) {
            double r2Beam = r2AtZ(z_beam, &m_track);
            if ( r2Beam > m_maxR2Beam ) {
              continue;
            }
          }
        }

        //== Extend downstream, on both sides of the detector as soon as one hit is missed
        int extraStep = 2;
        int extraSens = sens1-extraStep;

        int nbMissed = 0;

        double lastZ = sensor1.z;

        while ( extraSens >= 0 ) {
          extra_sensor.startPosition = sensor_hitStarts[event_sensor_displ + extraSens];
          extra_sensor.hitsNum       = sensor_hitNums[event_sensor_displ + extraSens];
          extra_sensor.z             = sensor_Zs[event_sensor_displ + extraSens];

          double tol     = m_extraTol;
          double maxChi2 = m_maxChi2ToAdd;
          if ( extra_sensor.z < lastZ - 100.0 ) {
            tol     = 2 * tol;
            maxChi2 = 2 * maxChi2;
          }

          debug << "s" << extraSens << " ";
          bool added = addHitsOnSensor(&extra_sensor, tol, maxChi2, &m_track, eventId);
          if ( added ) {
            nbMissed = 0;
            lastZ = extra_sensor.z;
          } else {
            nbMissed += extraStep;
            extraStep = 1;
          }
          if ( m_maxMissed < nbMissed ) {
            break;
          }

          extraSens -= extraStep;
        }

        debug << endl;

        //== Try upstream if almost forward tracks
        if ( sensor0.z > m_maxZForRBeamCut ) {
          int extraStep = 1;
          int extraSens = sens0 + 3;  // + 2 already tried...
          nbMissed = 2;

          while ( extraSens <= lastSensor ) {
            extra_sensor.startPosition = sensor_hitStarts[event_sensor_displ + extraSens];
            extra_sensor.hitsNum       = sensor_hitNums[event_sensor_displ + extraSens];
            extra_sensor.z = sensor_Zs[event_sensor_displ + extraSens];

            bool added = addHitsOnSensor(&extra_sensor, m_extraTol, m_maxChi2ToAdd, &m_track, eventId);

            if ( added ) {
              nbMissed = 0;
            } else {
              nbMissed += extraStep;
            }
            if ( m_maxMissed < nbMissed ) {
              break;
            }
            extraSens += extraStep;
          }

        }

        removeWorstHit(&m_track);

        if ( m_track.trackHitsNum < 3 ) {
          debug << "Track only has " << m_track.trackHitsNum << " hits!" << endl;
          continue;
        }

        //== Add compatible hits in sens0 and sens1.
        int next_hit = hit0_no + 1 + sensor0.startPosition;
        if ( next_hit != sensor0.startPosition + sensor0.hitsNum ) {
          if ( chi2Track(&m_track, event_hit_displ + next_hit) < m_maxChi2SameSensor ) {
            hit0_no++;
            addHit(&m_track, event_hit_displ + next_hit);
          }
        }

        next_hit = hit1_no + 1 + sensor1.startPosition;
        if ( next_hit != sensor1.startPosition + sensor1.hitsNum ) {
          if ( chi2Track(&m_track, event_hit_displ + next_hit) < m_maxChi2SameSensor ) {
            hit1_no++;
            addHit(&m_track, event_hit_displ + next_hit);
          }
        }

        //== Final check: if only 3 hits, all should be unused and chi2 good.
        if ( m_track.trackHitsNum == 3 ) {
          /*if ( !all3SensorsAreDifferent(&m_track) ) {
          // debug << "Not all three sensors are different" << endl;
          continue;
          } */
          if( nbUnused(&m_track, hit_isUseds, event_hit_displ) != 3) {
            // debug << "There is less than 3 non-used hits" << endl;
            continue;
          }
          if( chi2(&m_track) > m_maxChi2Short) {
            // debug << "Chi2 test not passed" << endl;
            continue;
          }
        } else {
          if ( nbUnused(&m_track, hit_isUseds, event_hit_displ) < .6 * m_track.trackHitsNum ) {
            // debug << "More than 60% of the hits are used already" << endl;
            continue;
          }
        }

        // debug << endl << "++ Writing GpuTrack" << endl;
        tracks_vector.push_back(m_track);
        addHitIDs(m_track.hits);

        // Tag used hits IF the GpuTrack is bigger than 3!!
        if (m_track.trackHitsNum > 3) {
          for (size_t i = 0; i < m_track.hits.size(); i++) {
            hit_isUseds[m_track.hits[i] - event_hit_displ] = 1;
          }
          break;
        }
      } // itH1
    } // itH0
  } // sens0
  // return tracks;
  free(hit_isUseds);
}