Sti TOF for cosmics

StiKalmanTrackNode::getTime()

For collisions:
    double d = sqrt(mFP.x()*mFP.x()+mFP.y()*mFP.y());
    double sn = fabs(mFP._cosCA*mFP.y() - mFP._sinCA*mFP.x())/d;
    if (sn> 0.99) sn =  0.99;
    if (sn<0.2) {
      d *= (1.+sn*sn/6);
    } else {
      d *= asin(sn)/sn;
    }
    d *= sqrt(1.+mFP.tanl()*mFP.tanl());
    double beta = 1;
    double pt = fabs(mFP.ptin());
    if (pt>0.1) {
      pt = 1./pt;
      double p2=(1.+mFP.tanl()*mFP.tanl())*pt*pt;
      double m=StiKalmanTrackFinderParameters::instance()->massHypothesis();
      double m2=m*m;
      double e2=p2+m2;
      double beta2=p2/e2;
      beta = TMath::Sqrt(beta2);
    }
    time = d/(TMath::Ccgs()*beta*1e-6); // mksec  


For lasers:
    if (TMath::Abs(mFP.z()) > 20.0) {
static const double Radius = 197.;
static const int    nsurf  = 6;
static const double surf[6] = {-Radius*Radius, 0, 0, 0, 1, 1};
      double dir[3] = {mFP._cosCA,mFP._sinCA,mFP.tanl()};
      THelixTrack tc(mFP.P,dir,mFP.curv());
      double s = tc.Step(smax, surf, nsurf,0,0,1);
      if (TMath::Abs(s) < smax)
        time = TMath::Abs(s)/(TMath::Ccgs()*1e-6); // mksec
    }


Proposal for cosmics is a hybrid of the two above codes: assume the tracks start at the outer perimeter of the TPC (but with two possible options to choose from, the assumption is to use whichever is higher in global y position because nearly all cosmics come down from above, not up from below [with some ambiguity for horizontally oriented tacks]), and apply a less-than-speed-of-light correction:
static const double Radius = 197.;
static const int    nsurf  = 6;
static const double surf[6] = {-Radius*Radius, 0, 0, 0, 1, 1};
      //double pos[3];
      //getXYZ_g(pos);
      double pos[3] = {x_g(),y_g(),z_g()};
      double dir1[3];
      getGlobalMomentum(dir1);
      THelixTrack tc(pos,dir1,mFP.curv());
      double s1 = tc.Step(smax, surf, nsurf,0,0,0);
      double xyz1[3];
      tc.Eval(s1,xyz1,0);
      double dir2[3] = {-dir1[0],-dir1[1],-dir1[2]};
      tc.Set(pos,dir2,-mFP.curv());
      double s2 = tc.Step(smax, surf, nsurf,0,0,0);
      double xyz2[3];
      tc.Eval(s2,xyz2,0);
      double s = (xyz1[1] > xyz2[1] ? s1 : s2);
      // use whichever end has the higher y to declare as the origin
      if (TMath::Abs(s) < smax) {
        double beta = 1;
        double pt = fabs(mFP.ptin());
        if (pt>0.1) {
          pt = 1./pt;
          double p2=(1.+mFP.tanl()*mFP.tanl())*pt*pt;
          double m=StiKalmanTrackFinderParameters::instance()->massHypothesis();
          double m2=m*m;
          double e2=p2+m2;
          double beta2=p2/e2;
          beta = TMath::Sqrt(beta2);
        }
        time = TMath::Abs(s)/(TMath::Ccgs()*beta*1e-6); // mksec
      }

We could perhaps change the massHypothesis from pion to muon, but the effect of this should be rather small since these are similar in mass.

Unfortunately, my test using the proposed is getting into endless loops inside the tc.Step() functions, and it isn't clear to me why.

-Gene