\HeaderA{hist.ab}{Histogram routines to help compute the cross-correlation between a
pair of spike trains.}{hist.ab}
\aliasA{count.nab}{hist.ab}{count.nab}
\aliasA{histbi.ab}{hist.ab}{histbi.ab}
\aliasA{test.count.hist.nab}{hist.ab}{test.count.hist.nab}
\aliasA{test.count.hist2.nab}{hist.ab}{test.count.hist2.nab}
\aliasA{test.hist.ab}{hist.ab}{test.hist.ab}
\aliasA{test.histograms.versus.r}{hist.ab}{test.histograms.versus.r}
\keyword{math}{hist.ab}
\begin{Description}\relax
For a pair of spike trains, TA (train a) and TB, these related
routines return the count of the number of spikes in B that occur
within some time window [-tmax,tmax] of a spike in A.  For histbi.ab,
we return a histogram of dt values from [-tmax,tmax].  For hist.ab, we
ignore the sign of each dt and just return a histogram in the range
[0,tmax].  Finally, for count.nab, we just return the number of dt
values found in the range [-tmax,tmax], rather than binning dt into a
histogram.
\end{Description}
\begin{Usage}
\begin{verbatim}
hist.ab(ta, tb, tmax, nbins)
histbi.ab(ta, tb, tmax, nbins)
count.nab(ta, tb, tmax)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{ta}] Vector of spike times, sorted such that lowest is first.
\item[\code{tb}] Vector of spike times, sorted such that lowest is first.
\item[\code{tmax}] maximum time (in seconds) to bin
\item[\code{nbins}] Number of bins in the histogram.  For histbi.ab, each bin
is of width (2*tmax)/nbins.  For hist.ab, each bin is (tmax)/nbins wide.
\end{ldescription}
\end{Arguments}
\begin{Value}
\code{hist.ab} returns a histogram of counts ignoring sign.
\code{histbi.ab} returns a histogram of counts respecting sign.
\code{count.nab} returns the number of dt values.
\end{Value}
\begin{Section}{METHOD}
For the histogram routines, each bin is of the form [low, high), with
the exception of the last bin (for +tmax), which is of the form
[tmax-binwid, tmax].  By assuming the spikes are ordered lowest first,
the number of spike comparisons is greatly reduced, rather than
comparing each spike with A with each spike in B.
\end{Section}
\begin{References}\relax
No references here.
\end{References}
\begin{SeeAlso}\relax
Nothing else yet...
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}

stopifnot(isTRUE(all.equal.numeric(
  histbi.ab(c(0), c(-2, -2, 0, 0, 1, 1,1, 1.8,2), tmax=2, nbins=4),
  c(2,0,2,5),
  check.attributes=FALSE)))
stopifnot(identical(TRUE, all.equal.numeric(
  hist.ab(c(0), c(-2, -2, 0, 0, 1, 1,1, 1.8,  2), tmax=2, nbins=4),
  c(2,0,3,4),
  check.attributes=FALSE)))
 
test.hist.ab()

## Not run: 
test.histograms.versus.r()
test.count.hist.nab()
test.count.hist.nab(s)
test.count.hist2.nab(s)
## End(Not run)
\end{ExampleCode}
\end{Examples}

