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