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