Index: trunk/SophyaLib/Manual/sophya.tex
===================================================================
--- trunk/SophyaLib/Manual/sophya.tex	(revision 1340)
+++ trunk/SophyaLib/Manual/sophya.tex	(revision 1347)
@@ -311,7 +311,179 @@
 \end{figure}
 
+{\bf HiStats} contains classes for creating, filling, printing and
+doing various operations on one or two dimensional histograms
+{\tt Histo} and {\tt Histo2D} as well as profile histograms {\tt HProf}. \\
+This module also contains {\tt NTuple} and {\tt XNTuple} which are
+more or less the same that the binary FITS tables.
+
+\subsection{1D Histograms}
+
+For 1D histograms, various numerical methods are provided such as
+computing means and sigmas, finding maxima, fitting, rebinning,
+integrating \dots \\
+The example below shows creating and filling a one dimensionnal histogram
+of 100 bins from $-5.$ to $+5.$ to create a gaussian normal distribution
+with errors~:
+\begin{verbatim}
+#include "histos.h"
+// ...
+Histo H(-0.5,0.5,100);
+H.Errors();
+for(int i=0;i<25000;i++) {
+  double x = NorRand();
+  H.Add(x);
+}
+H.Print(80);
+\end{verbatim}
+
+\subsection{2D Histograms}
+
+Much of these operations are also valid for 2D histograms. 1D projection
+or slices can be set~:
+\begin{verbatim}
+#include "histos2.h"
+// ...
+Histo H2(-1.,1.,100,0.,60.,50);
+H2.SetProjX(); // create the 1D histo for X projection
+H2.SetBandX(25.,35.); // create 1D histo  projection for 25.<y<35.
+H2.SetBandX(35.,45.); // create 1D histo  projection for 35.<y<45.
+H2.SetBandX(40.,55.); // create 1D histo  projection for 40.<y<55.
+//... fill H2 with what ever you want
+H2.Print();
+Histo *hx = H2.HProjX();
+  hx->Print(80);
+Histo *hbx2 = HBandX(1); // Get the second X band (35.<y<45.)
+  hbx2->Print(80);
+\end{verbatim}
+
+\subsection{Profile Histograms}
+
+Profiles histograms contains the mean and the sigma of the distribution
+of the values filled in each bin. The sigma can be changed to
+the error on the mean. When filled, the profile histogram looks
+like a 1D histogram and much of the operations that can be done on 1D histo
+may be applied onto profile histograms.
+
+\subsection{Ntuples}
+
+NTuple are memory resident tables of 32 bits floating values (float).
+They are arranged in columns. Each line is often called an event.
+These objects are frequently used to analyze data.
+Graphicals tools (spiapp) can plot a column against an other one
+with respect to various selection cuts. \\
+Here is an example of creation and filling~:
+\begin{verbatim}
+#include "ntuple.h"
+#include "srandgen.h"
+// ...
+char* nament[4] = {"i","x","y","ey"};
+r_4 xnt[4];
+NTuple NT(4,nament);
+for(i=0;i<5000;i++) {
+  xnt[0] = i+1;
+  xnt[1] = 5.*drandpm1();       // a random value between -5 and +5
+  xnt[2] = 100.*exp(-0.5*xnt[1]*xnt[1]) + 1.;
+  xnt[3] = sqrt(xnt[2]);
+  xnt[2] += xnt[3] * NorRand(); // add a random gaussian error
+  NT.Fill(xnt);
+}
+\end{verbatim}
+
+XNtuple are sophisticated NTuple : they accept various types
+of column values (float,double,int,...) and can be as big as
+needed (they used buffers on hard disk).
+
+\subsection{Writing, seeing \dots }
+
+All these objects have been design to be written to or read from a persistant file.
+The following example shows how to write the previously created objects
+into such a file~:
+\begin{verbatim}
+//-- Writing
+{
+char *fileout = "myfile.ppf";
+string tag;
+POutPersist outppf(fileout);
+tag = "H";   outppf.PutObject(H,tag);
+tag = "H2";   outppf.PutObject(H2,tag);
+tag = "NT";   outppf.PutObject(NT,tag);
+}  // closing ``}'' destroy ``outppf'' and automatically close the file !
+\end{verbatim}
+
+Sophya graphical tools (spiapp) can automatically display and operate
+all these objects.
+
 \section{Module SkyMap}
 
 \section{Module NTools}
+
+This module provides elementary numerical tools for numerical integration,
+fitting, sorting and ODE solving. FFTs are also provided (Mayer,FFTPack).
+
+\subsection{Fitting}
+
+Fitting is done with two classes {\tt GeneralFit} and {\tt GeneralFitData}
+and is based on the Levenberg-Marquardt method.
+GeneralFitData is a class which provide a description of the data
+to be fitted. GeneralFit is the fitter class. Parametrized functions
+can be given as classes which inherit {\tt GeneralFunction}
+or as simple C functions. Classes of pre-defined functions are provided
+(see files fct1dfit.h and fct2dfit.h). The user interface is very close
+from that of the CERN {\tt Minuit} fitter.
+Number of objects (Histo, HProf \dots ) are interfaced with GeneralFit
+and can be easily fitted. \\
+Here is a very simple example for fitting the previously created NTuple
+with a gaussian~:
+\begin{verbatim}
+#include "fct1dfit.h"
+// ...
+
+// Read from ppf file
+NTuple nt;
+{
+PInPersist pis("myfile.ppf");
+string tag = "NT";  pis.GetObject(nt,tag);
+}
+
+// Fill GeneralData
+GeneralData mGdata(nt.NEntry());
+for(int i=0; i<nt.NEntry(); i++)
+  mGdata.AddData1(xnt[1],xnt[2],xnt[3]); // Fill x, y and error on y
+mGData.PrintStatus();
+
+// Function for fitting : y = f(x) + noise
+Gauss1DPol mFunction; // gaussian + constant
+
+// Prepare for fit
+GeneralFit mFit(&mFunction);  // create a fitter for the choosen function
+mFit.SetData(&mGData);        // connect data to the fitter
+
+// Set and initialize the parameters (that's non-linear fitting!)
+//           (num par, name, guess start, step, [limits min and max])
+mFit.SetParam(0,"high",90.,1..);
+mFit.SetParam(1,"xcenter",0.05,0.01);
+mFit.SetParam(2,"sigma",sig,0.05,0.01,10.);
+                              // Give limits to avoid division by zero
+mFit.SetParam(3,"constant",0.,1.);
+
+// Fit and print result
+int rcfit = mFit.Fit();
+mFit.PrintFit();
+if(rcfit>0) {)
+  cout<<"Reduce_Chisquare = "<<mFit.GetChi2Red()
+      <<" nstep="<<mFit.GetNStep()<<" rc="<<rcfit<<endl;
+} else {
+  cout<<"Fit_Error, rc = "<<rcfit<<"  nstep="<<mFit.GetNStep()<<endl;
+  mFit.PrintFitErr(rcfit);
+}
+
+// Get the result for further use
+TVector<r_8> ParResult = mFit.GetParm();
+cout<<ParResult;
+\end{verbatim}
+
+Much more usefull possibilities and detailed informations might be found
+in the HTML pages of the Sophya manual.
+
 
 \section{Module Samba}
