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

Last change on this file since 1387 was 1387, checked in by lemeur, 25 years ago

doc SkyMap, Samba, FitsioServer

File size: 38.6 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\begin{figure}[hbt]
697\dclsbb{AnyDataObj}{PixelMap}
698\dclsccc{PixelMap}{Sphericalmap}{SphereHEALPix}
699\dclsc{SphereThetaPhi}
700\dclsb{LocalMap}
701\caption{partial class diagram for pixelization classes in Sophya}
702\end{figure}
703The {\bf SkyMap} module provides classes for creating, filling, reading pixelized spherical and 2D-maps. The types of values stored in pixels can be int, float, double , complex etc. according to the specialization of the template type.
704\subsection {Spherical maps}
705There are two kinds of spherical maps according pixelization algorithms. SphereHEALPix represents spheres pixelized following the HEALPIix algorithm (E. Yvon, K. Gorski), SphereThetaPhi represents spheres pixelized following an algorithm developed at LAL-ORSAY. The example below shows creating and filling of a SphereHEALPix with nside = 8 (it will be 12*8*8= 768 pixels) :
706
707\begin{verbatim}
708#include ``spherehealpix.h''
709// ...
710SphereHEALPix<double> sph(8);
711for (int k=0; k< sph.NbPixels(); k++) sph(k) = (double)(10*k);
712\end{verbatim}
713
714SphereThetaPhi is used in a similar way with an argument representing number of slices in theta (Euler angle) for an hemisphere.
715\subsection {Local maps}
716A local map is a 2 dimensional array, with i as column index and j as row index. The map is supposed to lie on a plan tangent to the celestial sphere in a point whose coordinates are (x0,y0) on the local map and (theta0, phi0) on the sphere. The range of the map is defined by two values of angles covered respectively by all the pixels in x direction and all the pixels in y direction (SetSize()). Default value of (x0, y0) is middle of the map, center of pixel(nx/2, ny/2).
717
718Internally, a map is first defined within this reference plane and tranported until the point (theta0, phi0) in such a way that both axes are kept parallel to meridian and parallel lines of the sphere. The user can define its own map with axes rotated with respect to reference axes (this rotation is characterized by angle between the local parallel line and the wanted x-axis-- method SetOrigin(...))
719
720The example below shows creating and filling of a LocalMap with 4 columns and 5 rows. The origin is set to default. The map covers a sphere portion defined by two angles of 30. degrees (methods \textit{SetOrigin()} and \textit{SetSize()} must be called in order to completely define the map).
721\begin{verbatim}
722#include "localmap.h"
723//..............
724 LocalMap<r_4> locmap(4,5);
725 for (int k=0; k<locmap.NbPixels();k++) locmap(k)=10.*k;
726 locmap.SetOrigin();
727 locmap.SetSize(30.,30.);
728\end{verbatim}
729
730\subsection{Writing, viewing \dots }
731
732All these objects have been design to be written to or read from a persistant file.
733The following example shows how to write the previously created objects
734into such a file~:
735\begin{verbatim}
736//-- Writing
737
738#include "fiospherehealpix.h"
739//................
740
741char *fileout = "myfile.ppf";
742POutPersist outppf(fileout);
743FIO_SphereHEALPix<r_8> outsph(sph);
744outsph.Write(outppf);
745FIO_LocalMap<r_8> outloc(locmap);
746outloc.Write(outppf);
747
748\end{verbatim}
749
750Sophya graphical tools (spiapp) can automatically display and operate
751all these objects.
752
753
754\section{Module NTools}
755
756This module provides elementary numerical tools for numerical integration,
757fitting, sorting and ODE solving. FFTs are also provided (Mayer,FFTPack).
758
759\subsection{Fitting}
760
761Fitting is done with two classes {\tt GeneralFit} and {\tt GeneralFitData}
762and is based on the Levenberg-Marquardt method.
763GeneralFitData is a class which provide a description of the data
764to be fitted. GeneralFit is the fitter class. Parametrized functions
765can be given as classes which inherit {\tt GeneralFunction}
766or as simple C functions. Classes of pre-defined functions are provided
767(see files fct1dfit.h and fct2dfit.h). The user interface is very close
768from that of the CERN {\tt Minuit} fitter.
769Number of objects (Histo, HProf \dots ) are interfaced with GeneralFit
770and can be easily fitted. \\
771Here is a very simple example for fitting the previously created NTuple
772with a gaussian~:
773\begin{verbatim}
774#include "fct1dfit.h"
775// ...
776
777// Read from ppf file
778NTuple nt;
779{
780PInPersist pis("myfile.ppf");
781string tag = "NT"; pis.GetObject(nt,tag);
782}
783
784// Fill GeneralData
785GeneralData mGdata(nt.NEntry());
786for(int i=0; i<nt.NEntry(); i++)
787 mGdata.AddData1(xnt[1],xnt[2],xnt[3]); // Fill x, y and error on y
788mGData.PrintStatus();
789
790// Function for fitting : y = f(x) + noise
791Gauss1DPol mFunction; // gaussian + constant
792
793// Prepare for fit
794GeneralFit mFit(&mFunction); // create a fitter for the choosen function
795mFit.SetData(&mGData); // connect data to the fitter
796
797// Set and initialize the parameters (that's non-linear fitting!)
798// (num par, name, guess start, step, [limits min and max])
799mFit.SetParam(0,"high",90.,1..);
800mFit.SetParam(1,"xcenter",0.05,0.01);
801mFit.SetParam(2,"sigma",sig,0.05,0.01,10.);
802 // Give limits to avoid division by zero
803mFit.SetParam(3,"constant",0.,1.);
804
805// Fit and print result
806int rcfit = mFit.Fit();
807mFit.PrintFit();
808if(rcfit>0) {)
809 cout<<"Reduce_Chisquare = "<<mFit.GetChi2Red()
810 <<" nstep="<<mFit.GetNStep()<<" rc="<<rcfit<<endl;
811} else {
812 cout<<"Fit_Error, rc = "<<rcfit<<" nstep="<<mFit.GetNStep()<<endl;
813 mFit.PrintFitErr(rcfit);
814}
815
816// Get the result for further use
817TVector<r_8> ParResult = mFit.GetParm();
818cout<<ParResult;
819\end{verbatim}
820
821Much more usefull possibilities and detailed informations might be found
822in the HTML pages of the Sophya manual.
823
824\subsection{Polynomial}
825
826Polynomials of 1 or 2 variables are supported ({\tt Poly} and {\tt Poly2}).
827Various operations are supported~:
828\begin{itemize}
829\item elementary operations between polynomials $(+,-,*,/) $
830\item setting or getting coefficients
831\item computing the value of the polynomial for a given value
832 of the variable(s),
833\item derivating
834\item computing roots (degre 1 or 2)
835\item fitting the polynomial to vectors of data.
836\end{itemize}
837Here is an example of polynomial fitting~:
838\begin{verbatim}
839#include "poly.h"
840// ...
841Poly pol(2);
842pol[0] = 100.; pol[1] = 0.; pol[2] = 0.01; // Setting coefficients
843TVector<r_8> x(100);
844TVector<r_8> y(100);
845TVector<r_8> ey(100);
846for(int i=0;i<100;i++) {
847 x(i) = i;
848 ey(i) = 10.;
849 y(i) = pol((double) i) + ey(i)*NorRand();
850 ey(i) *= ey(i)
851}
852
853TVector<r_8> errcoef;
854Poly polfit;
855polfit.Fit(x,y,ey,2,errcoef);
856
857cout<<"Fit Result"<<polfit<<endl;
858cout<<"Errors :"<<errcoef;
859\end{verbatim}
860
861Similar operations can be done on polynomials with 2 variables.
862
863\section{Module Samba}
864
865The module provides several classes for spherical harmonic analysis. The main class is \textit{SphericalTranformServer}. It contains methods for analysis and synthesis of spherical maps. The following example fills a vector of Cl's, generate a spherical map from these Cl's. This map is analyzed back to Cl's...
866\begin{verbatim}
867#include "skymap.h"
868#include "samba.h"
869....................
870
871// Generate input spectra a + b* l + c * gaussienne(l, 50, 20)
872int lmax = 92;
873Vector clin(lmax);
874for(int l=0; l<lmax; l++) {
875 double xx = (l-50.)/10.;
876 clin(l) = 1.e-2 -1.e-4*l + 0.1*exp(-xx*xx);
877}
878
879// Compute map from spectra
880SphericalTransformServer<r_8> ylmserver;
881int m = 128; // HealPix pixelisation parameter
882SphereHEALPix<r_8> map(m);
883ylmserver.GenerateFromCl(map, m, clin, 0.);
884// Compute power spectrum from map
885Vector clout = ylmserver.DecomposeToCl(map, lmax, 0.);
886\end{verbatim}
887
888\section{Module SkyT}
889
890\section{Module FitsIOServer}
891\begin{figure}[hbt]
892\dclsbb{FitsFile}{FitsInFile}
893\dclsb{FitsOutFile}
894\end{figure}
895
896This module provides classes for handling file input-output in FITS format using the cfitsio library. It works like the SOPHYA persistence (see Module SysTools), using delegate objects, but its design is simpler. The following example writes a matrix (see module TArray) and a spherical map (see module SkyMap) on a FITS file and reads back from FITS file and creates new objects :
897\begin{verbatim}
898#include "spherehealpix.h"
899#include "fitsspherehealpix.h"
900#include "fitstarray.h"
901#include "tmatrix.h"
902//...........................
903
904int m=...;
905SphereHEALPix<r_8> sph(m);
906................
907int dim1=...;
908int dim2=...;
909TMatrix<r_8> mat(dim1,dim2);
910............
911
912FITS_SphereHEALPix<r_8> sph_temp(sph);
913FITS_TArray<r_8> mat_temp(mat);
914// writing
915
916FitsOutFile os("myfile.fits");
917sph_temp.Write(os);
918mat_temp.Write(os);
919
920// reading
921FitsInFile is("myfile.fits");
922sph_temp.Read(is);
923mat_temp.Read(is);
924SphereHEALPix<r_8> new_sph=(SphereHEALPix<r_8>)sph_temp;
925TMatrix<r_8> new_mat=(TMatrix<r_8>)mat_temp;
926................
927
928\end{verbatim}
929
930
931
932\newpage
933\section{Building and installing Sophya}
934Presently, the Sophya library compilation has been tested with the following
935compiler/platform pairs:
936
937\begin{center}
938\begin{tabular}{ll}
939Compaq/DEC OSF1 & cxx (6.0 , 6.2) \\
940Linux & g++ (2.91 , 2.95) \\
941Linux & KCC (3.4) \\
942Solaris & g++ (2.95) \\
943SGI IRIX64 & CC \\
944\end{tabular}
945\end{center}
946
947Some of the modules in the Sophya package uses external libraries. The
948{\bf FitsIOServer} is the example of such a module, where the {\tt libcfitsio.a}
949is used.
950The build procedure expects to find the include files and the libraries in: \\
951{\tt \$EXTLIBDIR/Include/FitsIO } \\
952{\tt \$EXTLIBDIR/`uname`-\$EROSCXX/Libs} \\
953
954The object files from a given Sophya module are grouped in an archive library
955with the module's name ({\tt libmodulename.a}). All Sophya modules
956 are grouped in a single shared library ({\tt libsophya.so}), while the
957modules with reference to external libraries are grouped in
958({\tt libextsophya.so}). The {\bf PI} and {\bf PIext} modules are
959grouped in ({\tt libPI.so}).
960
961The environment variables {\bf DPCDEVREP}, {\bf EXTLIBDIR} and {\bf EROSCXX}
962must be defined in order to install the Sophya package.
963In the example below, we assume that we want to install Sophya from a
964released (tagged) version in the source directory {\tt \$SRC} in the
965{\tt /usr/local/Sophya} diretory, using {\tt g++}. We assume that
966the external libraries directory tree has been set up in
967{\tt /usr/local/ExtLibs/}. \\[3mm]
968\centerline{
969 \rule{20mm}{0.5mm}
970 {\bf \large the use of GNU make is mandatory}
971 \rule{20mm}{0.5mm} }
972
973\vspace*{3mm}
974\begin{verbatim}
975# We select our C++ compiler
976csh> setenv EROSCXX g++
977# Setup the build directory
978csh> mkdir /usr/local/Sophya/
979csh> setenv DPCDEVREP /usr/local/Sophya/
980csh> setenv EXTLIBDIR /usr/local/ExtLibs/
981# Use the top level makefile in Mgr/
982csh> cd \$SRC
983csh> cp Mgr/Makefile Makefile
984# Step 1: Create the directory tree and copy the include files (.h)
985csh> make depend
986# Step 2: Compile the modules without external library reference
987csh> make libs
988# Step 3: Compile the modules WITH external library reference (optional)
989csh> make extlibs
990# Step 4: Build libsophya.so
991csh> make slb
992# Step 5: Build libextsophya.so (optional)
993csh> make slbext
994# Step 6: Compile the PI and PIext modules (optional)
995csh> make PI
996# Step 7: Build the corresponding shared library libPI.so (optional)
997csh> make slbpi
998\end{verbatim}
999
1000To compile all modules and build the shared libraries, it is possible
1001to use:
1002\begin{verbatim}
1003# Step 2,3,6
1004csh> make all
1005# Step 4,5,7
1006csh> make slball
1007\end{verbatim}
1008
1009At this step, all libraries sould have been made. Programs using
1010Sophya libraries can now be built:
1011\begin{verbatim}
1012# To compile test programs
1013csh> cd Tests
1014csh> make arrt ...
1015csh> cd ..
1016# To compile other programs, for example from the PMixer module
1017csh> cd PMixer
1018csh> make
1019csh> cd ..
1020# To build (s)piapp (libPI.so is needed)
1021csh> cd ProgPI
1022csh> make
1023csh> cd ..
1024\end{verbatim}
1025
1026\subsection{Mgr module}
1027This module contains scripts which can be used for generating the
1028makefiles for each module.
1029\begin{itemize}
1030\item {\bf Makefile} Top level Makefile for builiding the libraries.
1031\item {\bf Makefile.h} contains the defintion of compilation flags for the
1032different compilers and systems. This file is used for building the
1033library and generating {\bf MakefileUser.h} (to be included in makefiles).
1034\item {\bf Makefile.slb} contains the rules for building shared libraries
1035for the different compilers and systems. (to be included in makefiles)
1036\item {\bf crerep\_sophya} c-shell script for creating the directory tree
1037under {\tt \$DPCBASEREP} and {\tt \$DPCDEVREP}
1038\item {\bf install\_sophya} c-shell script for installing the Sophya package.
1039Usually from {\tt \$DPCDEVREP} to {\tt \$DPCBASEREP}
1040\item {\bf mkmflien} c-shell script for making symbolic links or copying
1041include files to {\tt \$DPCDEVREP/Include} or {\tt \$DPCBASEREP/Include}
1042\item {\bf mkmf} c-shell script for generating module makefiles and the
1043top level makefile (named GNUmakefile)
1044\item {\bf mkmflib} c-shell script for generating each library module
1045makefile (named GNUmakefile)
1046\item {\bf mkmfprog} c-shell script for generating makefile for a module
1047containing the source for executable programs (named GNUmakefile).
1048\item {\bf mkmfPI} c-shell script for generating makefile for PI and PIext
1049modules (named GNUmakefile)
1050\item {\bf libdirs} List of Sophya modules without reference to external
1051libraries.
1052\item {\bf extlibdirs} List of Sophya modules with reference to external
1053libraries.
1054
1055\end{itemize}
1056
1057\newpage
1058\appendix
1059\section{SOPHYA Exceptions}
1060\index{Exception classes} \index{PThrowable} \index{PError} \index{PException}
1061SOPHYA library defines a set of exceptions which are used
1062for signaling error conditions. The figure below shows a partial
1063class diagram for exception classes in SOPHYA.
1064\begin{figure}[hbt]
1065\dclsbb{PThrowable}{PError}
1066\dclscc{PError}{AllocationError}
1067\dclscc{PError}{NullPtrError}
1068\dclscc{PError}{ForbiddenError}
1069\dclscc{PError}{AssertionFailedError}
1070\dclsbb{PThrowable}{PException}
1071\dclscc{PException}{IOExc}
1072\dclscc{PException}{SzMismatchError}
1073\dclscc{PException}{RangeCheckError}
1074\dclscc{PException}{ParmError}
1075\dclscc{PException}{TypeMismatchExc}
1076\dclscc{PException}{MathExc}
1077\dclscc{PException}{CaughtSignalExc}
1078\caption{partial class diagram for exception handling in Sophya}
1079\end{figure}
1080
1081For simple programs, it is a good practice to handle
1082the exceptions at least at high level, in the {\tt main()} function.
1083The example below shows the exception handling and the usage
1084of Sophya persistence.
1085
1086\input{ex1.inc}
1087
1088
1089\newpage
1090\addcontentsline{toc}{section}{Index}
1091\printindex
1092\end{document}
1093
Note: See TracBrowser for help on using the repository browser.