/*
 * TrkPhSinCut.cpp
 *
 *  Created on: 13-mar-2009
 *      Author: Sergio Ricciarini, Nicola Mori
 */

/*! @file TrkPhSinCut.cpp The TrkPhSinCut class implementation file */

#include "TrkPhSinCut.h"

int TrkPhSinCut::Check(PamLevel2 *event) {

  if (!(event->GetTrkLevel2()->GetNTracks() == 1))
    return 0; // one track exists (physical or not)

  // selection of the physical track (see TrkId below)
  event->SetSortingMethod(_sortingMethod);
  pamTrack = event->GetTrack(0);

  // NOTE: pamtrack is null pointer if no physical track is selected; this is a redundant check to find bugs in the level2 (at least one physical track should always be present, given that GetNTracks()=1 according to the previous cut).
  if (!pamTrack)
    return 0; // redundant check

  trkTrack = pamTrack->GetTrkTrack();

  if (!(trkTrack->nstep < 100 && trkTrack->chi2 > 0.))
    return 0; // check that the track is meaningful

//  int imatch=0;

    // identification of TRK-track TOF-index (this index is generally different from TRK-track TRK-index)
  iTrackTof = -1000;
  for (int i=0; i<event->GetToFLevel2()->ntrk(); i++) {
    if ( event->GetToFLevel2()->GetToFTrkVar(i)->trkseqno == trkTrack->GetSeqNo() ) {
      iTrackTof = i;
//      cout << "trkseqno " << event->GetToFLevel2()->GetToFTrkVar(i)->trkseqno << " TOF track id " << i << endl;
//      imatch++;
      break;
    }
  }

  return CUTOK;

}
