source: Sophya/trunk/SophyaLib/Manual/sophya.tex@ 1362

Last change on this file since 1362 was 1362, checked in by ansari, 25 years ago

MAJ documentation Reza 22/12/2000

File size: 33.5 KB
Line 
1\documentclass[twoside,11pt]{article}
2% Package standard : Utilisation de caracteres accentues, mode francais et graphique
3\usepackage{url}
4\usepackage[latin1]{inputenc}
5\usepackage[T1]{fontenc}
6\usepackage[english]{babel}
7\usepackage{graphicx}
8% package a mettre pour faire du pdf
9\usepackage{palatino}
10
11% Extension de symboles mathematiques
12\usepackage{amssymb}
13
14% Definition pour Docs Sophya
15\usepackage{defsophya}
16
17% Constitution d'index
18\usepackage{makeidx}
19\makeindex
20
21\begin{document}
22
23\begin{titlepage}
24% The title page - top of the page with the title of the paper
25\titrehp{Sophya \\ An overview }
26% Authors list
27\auteurs{
28R. Ansari & ansari@lal.in2p3.fr \\
29E. Aubourg & aubourg@hep.saclay.cea.fr \\
30G. Le Meur & lemeur@lal.in2p3.fr \\
31C. Magneville & cmv@hep.saclay.cea.fr \\
32S. Henrot-Versille & versille@in2p3.fr
33}
34% \auteursall
35% The title page - bottom of the page with the paper number
36\vspace{1cm}
37\begin{center}
38{\bf \Large Document being updated !}
39\end{center}
40\titrebp{1}
41\end{titlepage}
42
43\tableofcontents
44
45\newpage
46
47\section{Introduction}
48
49{\bf SOPHYA} ({\bf SO}ftware for {\bf PHY}sics {\bf A}nalysis)
50is a collection of C++ classes designed for numerical and
51physics analysis software development. Our goal is to provide
52easy to use, yet powerful classes which can be used by scientists.
53We have decided to use as much as possible available
54numerical analysis libraries, encapsulating them whenever
55possible.
56
57 The SOPHYA design and implementation has been carried out
58with the specific goal of providing the general framework for
59the Planck-HFI data processing software. However, most of the
60packages presented here have a more general scope than the CMB analysis
61and Planck mission problem.
62 The source directory tree
63\footnote{ CVS: cvsserver.lal.in2p3.fr:/exp/eros/CVSPlanck}
64is organised into a number of modules.
65
66\begin{itemize}
67\item[] {\bf Mgr/} Scripts for code management,
68makefile generation and software installation
69\item[] {\bf SysTools/} General architecture support classes such
70as {\tt PPersist, NDataBlock<T>}, and few utility classes
71({\tt DataCard, DVList} \ldots).
72\item[] {\bf TArray/} template numerical arrays, vectors and matrices \\
73({\tt PixelMap<T> SphericalMap<T>} \ldots)
74\item[] {\bf NTools/} Some standard numerical analysis tools
75(linear, and non linear parameter fitting, FFT, \ldots)
76\item[] {\bf HiStats/} Histogram-ming and data set handling classes \\
77({\tt Histo Histo2D NTuple XNTuple} \ldots)
78\end{itemize}
79
80The modules listed below are more tightly related to the
81CMB (Cosmic Microwave Background) data analysis problem:
82\begin{itemize}
83\item[] {\bf SkyMap/} Local and full sky maps, and few geometry
84handling utility classes. \\
85({\tt PixelMap<T>, LocalMap<T>, SphericalMap<T>, \ldots})
86\item[] {\bf SkyT/}
87classes for spectral emission and detector frequency response modelling \\
88({\tt SpectralResponse, RadSpectra, BlackBody} \ldots)
89\item[] {\bf Samba/} Spherical harmonic analysis.
90\end{itemize}
91
92The following modules contain the interface classes with
93external libraries:
94\begin{itemize}
95\item[] {\bf FitsIOServer/} Classes for handling file input-output
96in FITS format using the cfitsio library.
97\item[] {\bf LinAlg/} Interface with Lapack linear algebra package
98\item[] {\bf IFFTW/} Interface with FFTW package (libfftw.a)
99\end{itemize}
100
101Other modules:
102\begin{itemize}
103\item[] {\bf Tests/} Simple test programs
104\item[] {\bf PrgUtil/} Various utility programs (runcxx, scanppf, scanfits, \ldots)
105\item[] {\bf PMixer/} skymixer and related programs
106\item[] {\bf ProgPI/} interactive analysis tool - It should be noted that
107this module uses the SOPHYA class library and is based on {\bf PI}
108which is a C++ library defining a complete GUI program
109architecture. An additional module (PIext) define the interactive
110analysis program framework and the interfaces with the objects
111in SOPHYA. The {\bf PI/} \footnote{the PI package documentation
112is available from {\bf http://www.lal.in2p3.fr/recherche/eros/PeidaDoc/} }
113and {\bf PIext/} modules are not currently part
114of the SOPHYA CVS structure.
115\end{itemize}
116
117\newpage
118
119\section{Using Sophya}
120Basic usage of Sophya classes are described in in the following sections.
121Complete Sophya documentation can be found at our web site: \\
122{\bf http://hfi-l2.in2p3.fr}.
123
124\subsection{Environment variables}
125Two environment variables {\bf DPCBASEREP} and {\bf EROSCXX} are used
126to define the path where the Sophya libraries and executable are installed.
127{\bf DPCBASEREP} defines the base directory path and {\bf EROSCXX} the
128name of the C++ compiler. The complete path is built using {\bf DPCBASEREP},
129the operating system name (as obtained by the {\tt uname} command), and
130the compiler name. In the example below, we show the complete path
131for a {\tt Linux} system, using the GNU g++ compiler:
132
133\begin{itemize}
134\item \$DPCBASEREP/Include : Include (.h) files
135\item \$DPCBASEREP/Linux-g++/Libs : Path for the archive libraries (.a)
136\item \$DPCBASEREP/Linux-g++/ShLibs : Shared library path (.so)
137\item \$DPCBASEREP/Linux-g++/Exec : Executable file path
138\end{itemize}
139
140In order to use the shared libraries, the {\bf LD\_LIBRARY\_PATH} variable
141should contain the Sophya shared library path
142({\tt \$DPCBASEREP/Linux-g++/ShLibs } when using g++ compiler on Linux)
143
144For modules using external libraries, the {\bf EXTLIBDIR}
145environment variable should contain the path to these libraries
146and corresponding include files.
147C-FitsIO anf FFTW include files should be accessible through: \\
148{\tt \$EXTLIBDIR/Include/FitsIO } \\
149{\tt \$EXTLIBDIR/Include/FFTW } \\
150The corresponding libraries are expected to be found in: \\
151{\tt \$EXTLIBDIR/Linux-g++/Libs} \\
152
153\subsection{User makefiles}
154The file {\tt \$DPCBASEREP/Include/MakefileUser.h} defines the compilation
155flags and the list of Sophya libraries. It should be included in the
156user's makefile. The default compilation rules assumes that the object (.o)
157and executable files would be put in the following diretories: \\
158{\tt \$HOME/`uname`-\$EROSCXX/Objs} \\
159{\tt \$HOME/`uname`-\$EROSCXX/Exec}.
160In the case of a {\tt Linux} system and using {\tt g++} as the C++ compiler,
161these two directories would be translated to \\
162{\tt \$HOME/Linux-g++/Objs} and {\tt \$HOME/Linux-g++/Exec}.
163The GNU make program should be used.
164\par
165The file {\tt \$DPCBASEREP/Include/makefile\_auto} defines the rules to compile
166a given source program, and link it against the Sophya libraries to produce
167an executable. The example below shows the steps to compile a program named
168{\tt trivial.cc }.
169\begin{verbatim}
170csh> cp \$DPCBASEREP/Include/makefile_auto makefile
171csh> make trivial
172\end{verbatim}
173This command should compile the {\tt trivial.cc} file,
174and link it against the sophya libraries. The object and executable
175file names are: \\
176{\tt \$HOME/`uname`-\$EROSCXX/Objs/trivial.o} \\
177{\tt \$HOME/`uname`-\$EROSCXX/Exec/trivial}.
178\par
179The file {\tt \$DPCBASEREP/Include/makefile\_example} provides another
180example makefile.
181
182\subsection{the runcxx program}
183\index{runcxx}
184{\bf runcxx} is a simple program which can be used to compile, link
185and run simple C++ programs. It handles the creation of a
186complete program file, containing the basic set C++ include files,
187the necessary include files for SOPHYA SysTools, TArray, HiStats
188and NTools modules, and the main program with exception handling.
189Other Sophya modules can be included using the {\tt -import} flag.
190\begin{verbatim}
191csh> runcxx -h
192SOPHYA Version 0.9 Revision 97 (V_Oct2000) -- Nov 9 2000 16:20:52 cxx
193 runcxx : compiling and running of a piece of C++ code
194 Usage: runcxx [-compopt CompileOptions] [-linkopt LinkOptions]
195 [-tmpdir TmpDirectory] [-f C++CodeFileName]
196 [-inc includefile] [-inc includefile ...]
197 [-import modulename] [-import modulename ...]
198 [-uarg UserArg1 UserArg2 ...]
199 if no file name is specified, read from standard input
200 modulenames: SkyMap, Samba, SkyT, FitsIOServer, LinAlg, IFFTW
201\end{verbatim}
202Most examples in this manual can be tested using runcxx. The
203example below shows how to compile, link and run a sample
204code.
205\begin{verbatim}
206// File example.icc
207Matrix a(3,3);
208a = IdentityMatrix(1.);
209cout << a ;
210// Executing this sample code
211csh> runcxx -f example.icc
212\end{verbatim}
213
214
215\section{Copy constructor and assignment operator}
216In C++, objects can be copied by assignment or by initialization.
217Copying by initialization corresponds to creating an object and
218initializing its value through the copy constructor.
219The copy constructor has its first argument as a reference, or
220const reference to the object's class type. It can have
221more arguments, if default values are provided.
222Copying by assignment applies to an existing object and
223is performed through the assignment operator (=).
224The copy constructor implements this for identical type objects:
225\begin{verbatim}
226class MyObject {
227public:
228 MyObject(); // Default constructor
229 MyObject(MyObject const & a); // Copy constructor
230 MyObject & operator = (MyObject const & a) // Assignment operator
231}
232\end{verbatim}
233The copy constructors play an important role, as they are
234called when class objects are passed by value,
235returned by value, or thrown as an exception.
236\begin{verbatim}
237// A function declaration with an argument of type MyObject,
238// passed by value, and returning a MyObject
239MyObject f(MyObject x)
240{
241 MyObject r;
242 ...
243 return(r); // Copy constructor is called here
244}
245// Calling the function :
246MyObject a;
247f(a); // Copy constructor called for a
248\end{verbatim}
249It should be noted that the C++ syntax is ambiguous for the
250assignment operator. {\tt MyObject x; x=y; } and
251{\tt MyObject x=y;} have different meaning.
252\begin{verbatim}
253MyObject a; // default constructor call
254MyObject b(a); // copy constructor call
255MyObject bb = a; // identical to bb(a) : copy constructor call
256MyObject c; // default constructor call
257c = a; // assignment operator call
258\end{verbatim}
259
260As a general rule in SOPHYA, objects which implements
261reference sharing on their data members have a copy constructor
262which shares the data, while the assignment operator copies or
263duplicate the data.
264
265\section{Module SysTools}
266
267{\bf SysTools} contains utility classes such as {\tt DataCards} or
268{\tt DVlist}, an hierarchy of exception classes for Sophya, a template
269class {\tcls{NDataBlock}} for handling reference counting on numerical
270arrays, as well as classes providing the services for implementing simple
271serialization.
272\vspace*{5mm}
273
274\subsection{SOPHYA persistence}
275\index{PPersist} \index{PInPersist} \index{POutPersist}
276\begin{figure}[hbt]
277\dclsa{PPersist}
278\dclsbb{PIOPersist}{PInPersist}
279\dclsb{POutPersist}
280\caption{partial class diagram for classes handling persistence in Sophya}
281\end{figure}
282A simple persistence mechanism is defined in SOPHYA. Its main
283features are:
284\begin{itemize}
285\item[] Portable file format, containing the description of the data structures
286and object hierarchy. \\
287{\bf PPF} {\bf P}ortable {\bf P}ersistence file {\bf F}ormat.
288\item[] Handling of read/write for mutiply referenced objects.
289\item[] All write operations are carried using sequential access only. This
290holds also for read operations, unless positional tags are used.
291SOPHYA persistence services can thus be used to transfer objects
292through network links.
293\item[] The serialisation (reading/writing) for objects for a given class
294is implemented through a delegate object. The delegate class inherits
295from {\tt PPersist} class.
296\end{itemize}
297A complete description of SOPHYA persistence mechanism and guidelines
298for writing delegate classes for handling object persistence is beyond
299the scope of this document. The example in the next paragraph shows
300simple use of SOPHYA persistence.
301
302\subsection{\tcls{NDataBlock}}
303\index{\tcls{NDataBlock}}
304\begin{figure}[hbt]
305\dclsbb{AnyDataObj}{\tcls{NDataBlock}}
306\dclsbb{PPersist}{\tcls{FIO\_NDataBlock}}
307\end{figure}
308The {\bf \tcls{NDataBlock}} is designed to handle reference counting
309and sharing of memory blocs (contiguous arrays) for numerical data
310types. Initialisation, resizing, basic arithmetic operations, as
311well as persistence handling services are provided.
312The persistence handler class ({\tt \tcls{FIO\_NDataBlock}}) insures
313that a single copy of data is written for multiply referenced objects,
314and the data is shared among objects when reading.
315\par
316The example below shows writing of NDataBlock objects through the
317use of overloaded operator $ << $ :
318\begin{verbatim}
319#include "fiondblock.h"
320// ...
321POutPersist pos("aa.ppf");
322NDataBlock<r_4> rdb(40);
323rdb = 567.89;
324pos << rdb;
325// We can also use the PutObject method
326NDataBlock<int_4> idb(20);
327idb = 123;
328pos.PutObject(idb);
329\end{verbatim}
330The following sample programs show the reading of the created PPF file :
331\begin{verbatim}
332PInPersist pis("aa.ppf");
333NDataBlock<r_4> rdb;
334pis >> rdb;
335cout << rdb;
336NDataBlock<int_4> idb;
337cout << idb;
338\end{verbatim}
339
340\subsection{Using DVList}
341\index{DVList} \index{MuTyV}
342\begin{figure}[hbt]
343\dclsbb{AnyDataObj}{DVList}
344\dclsbb{PPersist}{\tclsc{ObjFileIO}{DVList}}
345\end{figure}
346The {\bf DVList} class objects can be used to create and manage list
347of values, associated with names. A list of pairs of (MuTyV, name(string))
348is maintained by DVList objects. {\bf MuTyV} is a simple class
349capable of holding string, integer, float or complex values,
350providing easy conversion methods between these objects.
351\begin{verbatim}
352// Using MuTyV objects
353MuTyV s("hello"); // string type value
354MuTyV x;
355x = "3.14159626"; // string type value, ascii representation for Pi
356double d = x; // x converted to double = 3.141596
357x = 314; // x contains the integer value = 314
358// Using DVList
359DVList dvl;
360dvl("Pi") = 3.14159626; // float value, named Pi
361dvl("Log2") = 0.30102999; // float value, named Log2
362dvl("FileName") = "myfile.fits"; // string value, named myfile.fits
363// Printing DVList object
364cout << dvl;
365\end{verbatim}
366
367\subsection{Using DataCards}
368\index{DataCards}
369The {\bf DataCards} class can be used to read parameters from a file.
370Each line in the file starting with \@ defines a set of values
371associated with a keyword. In the example below, we read the
372parameters corresponding with the keyword {\tt SIZE} from the
373file {\tt ex.d}. We suppose that {\tt ex.d} contains the line: \\
374{\tt @SIZE 400 250} \\
375\begin{verbatim}
376#include "datacards.h"
377// ...
378// Initializing DataCards object dc from file ex.d
379DataCards dc( "ex.d" );
380// Getting the first and second parameters for keyword size
381// We define a default value 100
382int size_x = dc.IParam("SIZE", 0, 100);
383int size_y = dc.IParam("SIZE", 1, 100);
384cout << " size_x= " << size_x << " size_y= " << size_y << endl;
385\end{verbatim}
386
387\subsection{Dynamic linker}
388\index{PDynLinkMgr}
389The class {\bf PDynLinkMgr} can be used for managing shared libraries
390at run time. The example below shows the run time linking of a function:\\
391{\tt extern "C" { void myfunc(); } } \\
392\begin{verbatim}
393#include "pdlmgr.h"
394// ...
395string soname = "mylib.so";
396string funcname = "myfunc";
397PDynLinkMgr dyl(soname);
398DlFunction f = dyl.GetFunction(funcname);
399if (f != NULL) {
400// Calling the function
401 f();
402}
403\end{verbatim}
404
405\subsection{CxxCompilerLinker class}
406\index{CxxCompilerLinker}
407This class provides the services to compile C++ code and building
408shared libraries, using the same compiler and options which have
409been used to create the SOPHYA shared library.
410The sample program below illustrates using this class to build
411the shared library (myfunc.so) from the source file myfunc.cc :
412\begin{verbatim}
413#include "cxxcmplnk.h"
414// ...
415string flnm = "myfunc.cc";
416string oname, soname;
417int rc;
418CxxCompilerLinker cxx;
419// The Compile method provides a default object file name
420rc = cxx.Compile(flnm, oname);
421if (rc != 0 ) { // Error when compiling ... }
422// The BuildSO method provides a default shared object file name
423rc = cxx.BuildSO(oname, soname);
424if (rc != 0 ) { // Error when creating shared object ... }
425\end{verbatim}
426
427\section{Module TArray}
428\index{\tcls{TArray}}
429{\bf TArray} module contains template classes for handling standard
430operations on numerical arrays. Using the class {\tt \tcls{TArray} },
431it is possible to create and manipulate up to 5-dimension numerical
432arrays {\tt (int, float, double, complex, \ldots)}. The include
433file {\tt array.h} declares all the classes and definitions
434in module TArray.
435
436\begin{figure}[hbt]
437\dclsccc{AnyDataObj}{BaseArray}{\tcls{TArray}}
438\dclsbb{PPersist}{\tcls{FIO\_TArray}}
439\end{figure}
440
441
442\subsection{Using arrays}
443\index{Sequence} \index{RandomSequence} \index{RegularSequence}
444\index{EnumeratedSequence}
445The example below shows basic usage of arrays, creation, initialization
446and arithmetic operations. Different kind of {\bf Sequence} objects
447can be used for initializing arrays.
448\begin{figure}[hbt]
449\dclsbb{Sequence}{RandomSequence}
450\dclsb{RegularSequence}
451\dclsb{EnumeratedSequence}
452\end{figure}
453
454The example below shows basic usage of arrays:
455\begin{verbatim}
456// Creating and initializing a 1-D array of integers
457TArray<int> ia(5);
458EnumeratedSequence es;
459es = 24, 35, 46, 57, 68;
460ia = es;
461cout << "Array<int> ia = " << ia;
462// 2-D array of float filled with random numbers
463// 2-D array of floats
464TArray<r_4> b(6,4), c(6,4);
465// Initializing b with a constant
466b = 2.71828;
467// Filling c with random numbers
468c = RandomSequence();
469// Arithmetic operations
470TArray<r_4> d = b+0.3f*c;
471cout << "Array<float> d = " << d;
472\end{verbatim}
473
474The copy constructor shares the array data, while the assignment operator
475copies the array elements, as illustrated in the following example:
476\begin{verbatim}
477TArray<int> a1(4,3);
478a1 = RegularSequence(0,2);
479// Array a2 and a1 shares their data
480TArray<int> a2(a1);
481// a3 and a1 have the same size and identical elements
482TArray<int> a3;
483a3 = a1;
484// Changing one of the a2 elements
485a2(1,1,0) = 555;
486// a1(1,1) is also changed to 555, but not a3(1,1)
487cout << "Array<int> a1 = " << a1;
488cout << "Array<int> a3 = " << a3;
489\end{verbatim}
490
491\subsection{Working with sub-arrays and Ranges}
492
493
494\subsection{Matrices and vectors}
495\index{\tcls{TMatrix}} \index{\tcls{TVector}}
496\begin{figure}[hbt]
497\dclsccc{\tcls{TArray}}{\tcls{TMatrix}}{\tcls{TVector}}
498\end{figure}
499Vectors and matrices are 2 dimensional arrays. The array size
500along one dimension is equal 1 for vectors. Column vectors
501have {\tt NCols() = 1} and row vectors have {\tt NRows() = 1}.
502
503Example of a simple low-pass filter on a one dimensional array (Vector)
504\begin{verbatim}
505// Input Vector containing a noisy periodic signal
506 Vector in(1024), out(1024);
507 in = RandomSequence(RandomSequence::Gaussian, 0., 1.);
508 for(int kk=0; kk<in.Size(); kk++)
509 in(kk) += 2*sin(kk*0.05);
510// Compute the output vector by a simple low pass filter
511 Vector out(1024);
512 int w = 2;
513 for(int k=w; k<in.Size()-w; k++)
514 out(k) = in(Range(k-w, k+w).Sum()/(2.*w+1.);
515\end{verbatim}
516
517\subsection{Memory organisation}
518{\tt \tcls{TArray} } can handle numerical arrays with various memory
519organisation, as long as the spacing (steps) along each axis is
520regular. The five axis are labeled X,Y,Z,T,U. The examples below
521illustrates the memory location for a 2-dimensional, $N_x=4 \times N_y=3$.
522The first index is along the X axis and the second index along the Y axis.
523\begin{verbatim}
524 | (0,0) (0,1) (0,2) (0,3) |
525 | (1,0) (1,1) (1,2) (1,3) |
526 | (2,0) (2,1) (2,2) (2,3) |
527\end{verbatim}
528In the first case, the array is completely packed
529($Step_X=1, Step_Y=N_X=4$), with zero offset,
530while in the second case, $Step_X=2, Step_Y=10, Offset=10$:
531\begin{verbatim}
532 | 0 1 2 3 | | 10 12 14 16 |
533Ex1 | 4 5 6 7 | Ex2 | 20 22 24 26 |
534 | 8 9 10 11 | | 30 32 34 36 |
535\end{verbatim}
536
537For matrices and vectors, an optional argument ({\tt MemoryMapping})
538can be used to select the memory mapping, where two basic schemes
539are available: \\
540{\tt CMemoryMapping} and {\tt FortranMemoryMapping}. \\
541In the case where {\tt CMemoryMapping} is used, a given matrix line
542is packed in memory, while the columns are packed when
543{\tt FortranMemoryMapping} is used. The first index when addressing
544the matrix elements (line number index) runs along
545the Y-axis if {\tt CMemoryMapping} is used, and along the X-axis
546in the case of {\tt FortranMemoryMapping}.
547Arithmetic operations between matrices
548with different memory organisation is allowed as long as
549the two matrices have the same sizes (Number of rows and columns).
550The following code example and the corresponding output illustrates
551these two memory mappings.
552\begin{verbatim}
553TArray<r_4> X(4,2);
554X = RegularSequence(1,1);
555cout << "Array X= " << X << endl;
556TMatrix<r_4> X_C(X, true, BaseArray::CMemoryMapping);
557cout << "Matrix X_C (CMemoryMapping) = " << X_C << endl;
558TMatrix<r_4> X_F(X, true, BaseArray::FortranMemoryMapping);
559cout << "Matrix X_F (FortranMemoryMapping) = " << X_F << endl;
560\end{verbatim}
561This code would produce the following output (X\_F = Transpose(X\_C)) :
562\begin{verbatim}
563Array X=
564--- TArray<f> ND=2 SizeX*Y*...= 4x2 ---
5651, 2, 3, 4
5665, 6, 7, 8
567
568Matrix X_C (CMemoryMapping) =
569--- TMatrix<f>(NRows=2, NCols=4) ND=2 SizeX*Y*...= 4x2 ---
5701, 2, 3, 4
5715, 6, 7, 8
572
573Matrix X_F (FortranMemoryMapping) =
574--- TMatrix<f>(NRows=4, NCols=2) ND=2 SizeX*Y*...= 4x2 ---
5751, 5
5762, 6
5773, 7
5784, 8
579\end{verbatim}
580
581\newpage
582
583\section{Module HiStats}
584\begin{figure}[hbt]
585\dclsccc{AnyDataObj}{Histo}{HProf}
586\dclsbb{AnyDataObj}{Histo2D}
587\dclsbb{AnyDataObj}{Ntuple}
588\dclsb{XNtuple}
589\caption{partial class diagram for histograms and ntuples}
590\end{figure}
591
592{\bf HiStats} contains classes for creating, filling, printing and
593doing various operations on one or two dimensional histograms
594{\tt Histo} and {\tt Histo2D} as well as profile histograms {\tt HProf}. \\
595This module also contains {\tt NTuple} and {\tt XNTuple} which are
596more or less the same that the binary FITS tables.
597
598\subsection{1D Histograms}
599
600For 1D histograms, various numerical methods are provided such as
601computing means and sigmas, finding maxima, fitting, rebinning,
602integrating \dots \\
603The example below shows creating and filling a one dimensionnal histogram
604of 100 bins from $-5.$ to $+5.$ to create a gaussian normal distribution
605with errors~:
606\begin{verbatim}
607#include "histos.h"
608// ...
609Histo H(-0.5,0.5,100);
610H.Errors();
611for(int i=0;i<25000;i++) {
612 double x = NorRand();
613 H.Add(x);
614}
615H.Print(80);
616\end{verbatim}
617
618\subsection{2D Histograms}
619
620Much of these operations are also valid for 2D histograms. 1D projection
621or slices can be set~:
622\begin{verbatim}
623#include "histos2.h"
624// ...
625Histo H2(-1.,1.,100,0.,60.,50);
626H2.SetProjX(); // create the 1D histo for X projection
627H2.SetBandX(25.,35.); // create 1D histo projection for 25.<y<35.
628H2.SetBandX(35.,45.); // create 1D histo projection for 35.<y<45.
629H2.SetBandX(40.,55.); // create 1D histo projection for 40.<y<55.
630//... fill H2 with what ever you want
631H2.Print();
632Histo *hx = H2.HProjX();
633 hx->Print(80);
634Histo *hbx2 = HBandX(1); // Get the second X band (35.<y<45.)
635 hbx2->Print(80);
636\end{verbatim}
637
638\subsection{Profile Histograms}
639
640Profiles histograms contains the mean and the sigma of the distribution
641of the values filled in each bin. The sigma can be changed to
642the error on the mean. When filled, the profile histogram looks
643like a 1D histogram and much of the operations that can be done on 1D histo
644may be applied onto profile histograms.
645
646\subsection{Ntuples}
647
648NTuple are memory resident tables of 32 bits floating values (float).
649They are arranged in columns. Each line is often called an event.
650These objects are frequently used to analyze data.
651Graphicals tools (spiapp) can plot a column against an other one
652with respect to various selection cuts. \\
653Here is an example of creation and filling~:
654\begin{verbatim}
655#include "ntuple.h"
656#include "srandgen.h"
657// ...
658char* nament[4] = {"i","x","y","ey"};
659r_4 xnt[4];
660NTuple NT(4,nament);
661for(i=0;i<5000;i++) {
662 xnt[0] = i+1;
663 xnt[1] = 5.*drandpm1(); // a random value between -5 and +5
664 xnt[2] = 100.*exp(-0.5*xnt[1]*xnt[1]) + 1.;
665 xnt[3] = sqrt(xnt[2]);
666 xnt[2] += xnt[3] * NorRand(); // add a random gaussian error
667 NT.Fill(xnt);
668}
669\end{verbatim}
670
671XNtuple are sophisticated NTuple : they accept various types
672of column values (float,double,int,...) and can be as big as
673needed (they used buffers on hard disk).
674
675\subsection{Writing, viewing \dots }
676
677All these objects have been design to be written to or read from a persistant file.
678The following example shows how to write the previously created objects
679into such a file~:
680\begin{verbatim}
681//-- Writing
682{
683char *fileout = "myfile.ppf";
684string tag;
685POutPersist outppf(fileout);
686tag = "H"; outppf.PutObject(H,tag);
687tag = "H2"; outppf.PutObject(H2,tag);
688tag = "NT"; outppf.PutObject(NT,tag);
689} // closing ``}'' destroy ``outppf'' and automatically close the file !
690\end{verbatim}
691
692Sophya graphical tools (spiapp) can automatically display and operate
693all these objects.
694
695\section{Module SkyMap}
696
697\section{Module NTools}
698
699This module provides elementary numerical tools for numerical integration,
700fitting, sorting and ODE solving. FFTs are also provided (Mayer,FFTPack).
701
702\subsection{Fitting}
703
704Fitting is done with two classes {\tt GeneralFit} and {\tt GeneralFitData}
705and is based on the Levenberg-Marquardt method.
706GeneralFitData is a class which provide a description of the data
707to be fitted. GeneralFit is the fitter class. Parametrized functions
708can be given as classes which inherit {\tt GeneralFunction}
709or as simple C functions. Classes of pre-defined functions are provided
710(see files fct1dfit.h and fct2dfit.h). The user interface is very close
711from that of the CERN {\tt Minuit} fitter.
712Number of objects (Histo, HProf \dots ) are interfaced with GeneralFit
713and can be easily fitted. \\
714Here is a very simple example for fitting the previously created NTuple
715with a gaussian~:
716\begin{verbatim}
717#include "fct1dfit.h"
718// ...
719
720// Read from ppf file
721NTuple nt;
722{
723PInPersist pis("myfile.ppf");
724string tag = "NT"; pis.GetObject(nt,tag);
725}
726
727// Fill GeneralData
728GeneralData mGdata(nt.NEntry());
729for(int i=0; i<nt.NEntry(); i++)
730 mGdata.AddData1(xnt[1],xnt[2],xnt[3]); // Fill x, y and error on y
731mGData.PrintStatus();
732
733// Function for fitting : y = f(x) + noise
734Gauss1DPol mFunction; // gaussian + constant
735
736// Prepare for fit
737GeneralFit mFit(&mFunction); // create a fitter for the choosen function
738mFit.SetData(&mGData); // connect data to the fitter
739
740// Set and initialize the parameters (that's non-linear fitting!)
741// (num par, name, guess start, step, [limits min and max])
742mFit.SetParam(0,"high",90.,1..);
743mFit.SetParam(1,"xcenter",0.05,0.01);
744mFit.SetParam(2,"sigma",sig,0.05,0.01,10.);
745 // Give limits to avoid division by zero
746mFit.SetParam(3,"constant",0.,1.);
747
748// Fit and print result
749int rcfit = mFit.Fit();
750mFit.PrintFit();
751if(rcfit>0) {)
752 cout<<"Reduce_Chisquare = "<<mFit.GetChi2Red()
753 <<" nstep="<<mFit.GetNStep()<<" rc="<<rcfit<<endl;
754} else {
755 cout<<"Fit_Error, rc = "<<rcfit<<" nstep="<<mFit.GetNStep()<<endl;
756 mFit.PrintFitErr(rcfit);
757}
758
759// Get the result for further use
760TVector<r_8> ParResult = mFit.GetParm();
761cout<<ParResult;
762\end{verbatim}
763
764Much more usefull possibilities and detailed informations might be found
765in the HTML pages of the Sophya manual.
766
767\subsection{Polynomial}
768
769Polynomials of 1 or 2 variables are supported ({\tt Poly} and {\tt Poly2}).
770Various operations are supported~:
771\begin{itemize}
772\item elementary operations between polynomials $(+,-,*,/) $
773\item setting or getting coefficients
774\item computing the value of the polynomial for a given value
775 of the variable(s),
776\item derivating
777\item computing roots (degre 1 or 2)
778\item fitting the polynomial to vectors of data.
779\end{itemize}
780Here is an example of polynomial fitting~:
781\begin{verbatim}
782#include "poly.h"
783// ...
784Poly pol(2);
785pol[0] = 100.; pol[1] = 0.; pol[2] = 0.01; // Setting coefficients
786TVector<r_8> x(100);
787TVector<r_8> y(100);
788TVector<r_8> ey(100);
789for(int i=0;i<100;i++) {
790 x(i) = i;
791 ey(i) = 10.;
792 y(i) = pol((double) i) + ey(i)*NorRand();
793 ey(i) *= ey(i)
794}
795
796TVector<r_8> errcoef;
797Poly polfit;
798polfit.Fit(x,y,ey,2,errcoef);
799
800cout<<"Fit Result"<<polfit<<endl;
801cout<<"Errors :"<<errcoef;
802\end{verbatim}
803
804Similar operations can be done on polynomials with 2 variables.
805
806\section{Module Samba}
807
808\section{Module SkyT}
809
810
811\newpage
812\section{Building and installing Sophya}
813Presently, the Sophya library compilation has been tested with the following
814compiler/platform pairs:
815
816\begin{center}
817\begin{tabular}{ll}
818Compaq/DEC OSF1 & cxx (6.0 , 6.2) \\
819Linux & g++ (2.91 , 2.95) \\
820Linux & KCC (3.4) \\
821Solaris & g++ (2.95) \\
822SGI IRIX64 & CC \\
823\end{tabular}
824\end{center}
825
826Some of the modules in the Sophya package uses external libraries. The
827{\bf FitsIOServer} is the example of such a module, where the {\tt libcfitsio.a}
828is used.
829The build procedure expects to find the include files and the libraries in: \\
830{\tt \$EXTLIBDIR/Include/FitsIO } \\
831{\tt \$EXTLIBDIR/`uname`-\$EROSCXX/Libs} \\
832
833The object files from a given Sophya module are grouped in an archive library
834with the module's name ({\tt libmodulename.a}). All Sophya modules
835 are grouped in a single shared library ({\tt libsophya.so}), while the
836modules with reference to external libraries are grouped in
837({\tt libextsophya.so}). The {\bf PI} and {\bf PIext} modules are
838grouped in ({\tt libPI.so}).
839
840The environment variables {\bf DPCDEVREP}, {\bf EXTLIBDIR} and {\bf EROSCXX}
841must be defined in order to install the Sophya package.
842In the example below, we assume that we want to install Sophya from a
843released (tagged) version in the source directory {\tt \$SRC} in the
844{\tt /usr/local/Sophya} diretory, using {\tt g++}. We assume that
845the external libraries directory tree has been set up in
846{\tt /usr/local/ExtLibs/}. \\[3mm]
847\centerline{
848 \rule{20mm}{0.5mm}
849 {\bf \large the use of GNU make is mandatory}
850 \rule{20mm}{0.5mm} }
851
852\vspace*{3mm}
853\begin{verbatim}
854# We select our C++ compiler
855csh> setenv EROSCXX g++
856# Setup the build directory
857csh> mkdir /usr/local/Sophya/
858csh> setenv DPCDEVREP /usr/local/Sophya/
859csh> setenv EXTLIBDIR /usr/local/ExtLibs/
860# Use the top level makefile in Mgr/
861csh> cd \$SRC
862csh> cp Mgr/Makefile Makefile
863# Step 1: Create the directory tree and copy the include files (.h)
864csh> make depend
865# Step 2: Compile the modules without external library reference
866csh> make libs
867# Step 3: Compile the modules WITH external library reference (optional)
868csh> make extlibs
869# Step 4: Build libsophya.so
870csh> make slb
871# Step 5: Build libextsophya.so (optional)
872csh> make slbext
873# Step 6: Compile the PI and PIext modules (optional)
874csh> make PI
875# Step 7: Build the corresponding shared library libPI.so (optional)
876csh> make slbpi
877\end{verbatim}
878
879To compile all modules and build the shared libraries, it is possible
880to use:
881\begin{verbatim}
882# Step 2,3,6
883csh> make all
884# Step 4,5,7
885csh> make slball
886\end{verbatim}
887
888At this step, all libraries sould have been made. Programs using
889Sophya libraries can now be built:
890\begin{verbatim}
891# To compile test programs
892csh> cd Tests
893csh> make arrt ...
894csh> cd ..
895# To compile other programs, for example from the PMixer module
896csh> cd PMixer
897csh> make
898csh> cd ..
899# To build (s)piapp (libPI.so is needed)
900csh> cd ProgPI
901csh> make
902csh> cd ..
903\end{verbatim}
904
905\subsection{Mgr module}
906This module contains scripts which can be used for generating the
907makefiles for each module.
908\begin{itemize}
909\item {\bf Makefile} Top level Makefile for builiding the libraries.
910\item {\bf Makefile.h} contains the defintion of compilation flags for the
911different compilers and systems. This file is used for building the
912library and generating {\bf MakefileUser.h} (to be included in makefiles).
913\item {\bf Makefile.slb} contains the rules for building shared libraries
914for the different compilers and systems. (to be included in makefiles)
915\item {\bf crerep\_sophya} c-shell script for creating the directory tree
916under {\tt \$DPCBASEREP} and {\tt \$DPCDEVREP}
917\item {\bf install\_sophya} c-shell script for installing the Sophya package.
918Usually from {\tt \$DPCDEVREP} to {\tt \$DPCBASEREP}
919\item {\bf mkmflien} c-shell script for making symbolic links or copying
920include files to {\tt \$DPCDEVREP/Include} or {\tt \$DPCBASEREP/Include}
921\item {\bf mkmf} c-shell script for generating module makefiles and the
922top level makefile (named GNUmakefile)
923\item {\bf mkmflib} c-shell script for generating each library module
924makefile (named GNUmakefile)
925\item {\bf mkmfprog} c-shell script for generating makefile for a module
926containing the source for executable programs (named GNUmakefile).
927\item {\bf mkmfPI} c-shell script for generating makefile for PI and PIext
928modules (named GNUmakefile)
929\item {\bf libdirs} List of Sophya modules without reference to external
930libraries.
931\item {\bf extlibdirs} List of Sophya modules with reference to external
932libraries.
933
934\end{itemize}
935
936\newpage
937\appendix
938\section{SOPHYA Exceptions}
939\index{Exception classes} \index{PThrowable} \index{PError} \index{PException}
940SOPHYA library defines a set of exceptions which are used
941for signaling error conditions. The figure below shows a partial
942class diagram for exception classes in SOPHYA.
943\begin{figure}[hbt]
944\dclsbb{PThrowable}{PError}
945\dclscc{PError}{AllocationError}
946\dclscc{PError}{NullPtrError}
947\dclscc{PError}{ForbiddenError}
948\dclscc{PError}{AssertionFailedError}
949\dclsbb{PThrowable}{PException}
950\dclscc{PException}{IOExc}
951\dclscc{PException}{SzMismatchError}
952\dclscc{PException}{RangeCheckError}
953\dclscc{PException}{ParmError}
954\dclscc{PException}{TypeMismatchExc}
955\dclscc{PException}{MathExc}
956\dclscc{PException}{CaughtSignalExc}
957\caption{partial class diagram for exception handling in Sophya}
958\end{figure}
959
960For simple programs, it is a good practice to handle
961the exceptions at least at high level, in the {\tt main()} function.
962The example below shows the exception handling and the usage
963of Sophya persistence.
964
965\input{ex1.inc}
966
967
968\newpage
969\addcontentsline{toc}{section}{Index}
970\printindex
971\end{document}
972
Note: See TracBrowser for help on using the repository browser.