Changeset 1347 in Sophya for trunk/SophyaLib/Manual


Ignore:
Timestamp:
Nov 26, 2000, 12:01:25 AM (25 years ago)
Author:
cmv
Message:

doc NTools and HiStats cmv 25/11/00

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/Manual/sophya.tex

    r1340 r1347  
    311311\end{figure}
    312312
     313{\bf HiStats} contains classes for creating, filling, printing and
     314doing various operations on one or two dimensional histograms
     315{\tt Histo} and {\tt Histo2D} as well as profile histograms {\tt HProf}. \\
     316This module also contains {\tt NTuple} and {\tt XNTuple} which are
     317more or less the same that the binary FITS tables.
     318
     319\subsection{1D Histograms}
     320
     321For 1D histograms, various numerical methods are provided such as
     322computing means and sigmas, finding maxima, fitting, rebinning,
     323integrating \dots \\
     324The example below shows creating and filling a one dimensionnal histogram
     325of 100 bins from $-5.$ to $+5.$ to create a gaussian normal distribution
     326with errors~:
     327\begin{verbatim}
     328#include "histos.h"
     329// ...
     330Histo H(-0.5,0.5,100);
     331H.Errors();
     332for(int i=0;i<25000;i++) {
     333  double x = NorRand();
     334  H.Add(x);
     335}
     336H.Print(80);
     337\end{verbatim}
     338
     339\subsection{2D Histograms}
     340
     341Much of these operations are also valid for 2D histograms. 1D projection
     342or slices can be set~:
     343\begin{verbatim}
     344#include "histos2.h"
     345// ...
     346Histo H2(-1.,1.,100,0.,60.,50);
     347H2.SetProjX(); // create the 1D histo for X projection
     348H2.SetBandX(25.,35.); // create 1D histo  projection for 25.<y<35.
     349H2.SetBandX(35.,45.); // create 1D histo  projection for 35.<y<45.
     350H2.SetBandX(40.,55.); // create 1D histo  projection for 40.<y<55.
     351//... fill H2 with what ever you want
     352H2.Print();
     353Histo *hx = H2.HProjX();
     354  hx->Print(80);
     355Histo *hbx2 = HBandX(1); // Get the second X band (35.<y<45.)
     356  hbx2->Print(80);
     357\end{verbatim}
     358
     359\subsection{Profile Histograms}
     360
     361Profiles histograms contains the mean and the sigma of the distribution
     362of the values filled in each bin. The sigma can be changed to
     363the error on the mean. When filled, the profile histogram looks
     364like a 1D histogram and much of the operations that can be done on 1D histo
     365may be applied onto profile histograms.
     366
     367\subsection{Ntuples}
     368
     369NTuple are memory resident tables of 32 bits floating values (float).
     370They are arranged in columns. Each line is often called an event.
     371These objects are frequently used to analyze data.
     372Graphicals tools (spiapp) can plot a column against an other one
     373with respect to various selection cuts. \\
     374Here is an example of creation and filling~:
     375\begin{verbatim}
     376#include "ntuple.h"
     377#include "srandgen.h"
     378// ...
     379char* nament[4] = {"i","x","y","ey"};
     380r_4 xnt[4];
     381NTuple NT(4,nament);
     382for(i=0;i<5000;i++) {
     383  xnt[0] = i+1;
     384  xnt[1] = 5.*drandpm1();       // a random value between -5 and +5
     385  xnt[2] = 100.*exp(-0.5*xnt[1]*xnt[1]) + 1.;
     386  xnt[3] = sqrt(xnt[2]);
     387  xnt[2] += xnt[3] * NorRand(); // add a random gaussian error
     388  NT.Fill(xnt);
     389}
     390\end{verbatim}
     391
     392XNtuple are sophisticated NTuple : they accept various types
     393of column values (float,double,int,...) and can be as big as
     394needed (they used buffers on hard disk).
     395
     396\subsection{Writing, seeing \dots }
     397
     398All these objects have been design to be written to or read from a persistant file.
     399The following example shows how to write the previously created objects
     400into such a file~:
     401\begin{verbatim}
     402//-- Writing
     403{
     404char *fileout = "myfile.ppf";
     405string tag;
     406POutPersist outppf(fileout);
     407tag = "H";   outppf.PutObject(H,tag);
     408tag = "H2";   outppf.PutObject(H2,tag);
     409tag = "NT";   outppf.PutObject(NT,tag);
     410}  // closing ``}'' destroy ``outppf'' and automatically close the file !
     411\end{verbatim}
     412
     413Sophya graphical tools (spiapp) can automatically display and operate
     414all these objects.
     415
    313416\section{Module SkyMap}
    314417
    315418\section{Module NTools}
     419
     420This module provides elementary numerical tools for numerical integration,
     421fitting, sorting and ODE solving. FFTs are also provided (Mayer,FFTPack).
     422
     423\subsection{Fitting}
     424
     425Fitting is done with two classes {\tt GeneralFit} and {\tt GeneralFitData}
     426and is based on the Levenberg-Marquardt method.
     427GeneralFitData is a class which provide a description of the data
     428to be fitted. GeneralFit is the fitter class. Parametrized functions
     429can be given as classes which inherit {\tt GeneralFunction}
     430or as simple C functions. Classes of pre-defined functions are provided
     431(see files fct1dfit.h and fct2dfit.h). The user interface is very close
     432from that of the CERN {\tt Minuit} fitter.
     433Number of objects (Histo, HProf \dots ) are interfaced with GeneralFit
     434and can be easily fitted. \\
     435Here is a very simple example for fitting the previously created NTuple
     436with a gaussian~:
     437\begin{verbatim}
     438#include "fct1dfit.h"
     439// ...
     440
     441// Read from ppf file
     442NTuple nt;
     443{
     444PInPersist pis("myfile.ppf");
     445string tag = "NT";  pis.GetObject(nt,tag);
     446}
     447
     448// Fill GeneralData
     449GeneralData mGdata(nt.NEntry());
     450for(int i=0; i<nt.NEntry(); i++)
     451  mGdata.AddData1(xnt[1],xnt[2],xnt[3]); // Fill x, y and error on y
     452mGData.PrintStatus();
     453
     454// Function for fitting : y = f(x) + noise
     455Gauss1DPol mFunction; // gaussian + constant
     456
     457// Prepare for fit
     458GeneralFit mFit(&mFunction);  // create a fitter for the choosen function
     459mFit.SetData(&mGData);        // connect data to the fitter
     460
     461// Set and initialize the parameters (that's non-linear fitting!)
     462//           (num par, name, guess start, step, [limits min and max])
     463mFit.SetParam(0,"high",90.,1..);
     464mFit.SetParam(1,"xcenter",0.05,0.01);
     465mFit.SetParam(2,"sigma",sig,0.05,0.01,10.);
     466                              // Give limits to avoid division by zero
     467mFit.SetParam(3,"constant",0.,1.);
     468
     469// Fit and print result
     470int rcfit = mFit.Fit();
     471mFit.PrintFit();
     472if(rcfit>0) {)
     473  cout<<"Reduce_Chisquare = "<<mFit.GetChi2Red()
     474      <<" nstep="<<mFit.GetNStep()<<" rc="<<rcfit<<endl;
     475} else {
     476  cout<<"Fit_Error, rc = "<<rcfit<<"  nstep="<<mFit.GetNStep()<<endl;
     477  mFit.PrintFitErr(rcfit);
     478}
     479
     480// Get the result for further use
     481TVector<r_8> ParResult = mFit.GetParm();
     482cout<<ParResult;
     483\end{verbatim}
     484
     485Much more usefull possibilities and detailed informations might be found
     486in the HTML pages of the Sophya manual.
     487
    316488
    317489\section{Module Samba}
Note: See TracChangeset for help on using the changeset viewer.