[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.
|
---|
| 202 | \end{itemize}
|
---|
| 203 | The example below shows writing of objects through the use of overloaded
|
---|
| 204 | operator $ << $ :
|
---|
| 205 | \begin{verbatim}
|
---|
| 206 | #include "fiondblock.h"
|
---|
| 207 | // ...
|
---|
| 208 | POutPersist pos("aa.ppf");
|
---|
| 209 | NDataBlock<r_4> rdb(40);
|
---|
| 210 | rdb = 567.89;
|
---|
| 211 | pos << rdb;
|
---|
| 212 | // We can also use the PutObject method
|
---|
| 213 | NDataBlock<int_4> idb(20);
|
---|
| 214 | idb = 123;
|
---|
| 215 | pos.PutObject(idb);
|
---|
| 216 | \end{verbatim}
|
---|
| 217 | The following sample programs show the reading of the created PPF file :
|
---|
| 218 | \begin{verbatim}
|
---|
| 219 | PInPersist pis("aa.ppf");
|
---|
| 220 | NDataBlock<r_4> rdb;
|
---|
| 221 | pis >> rdb;
|
---|
| 222 | cout << rdb;
|
---|
| 223 | NDataBlock<int_4> idb;
|
---|
| 224 | cout << idb;
|
---|
| 225 | \end{verbatim}
|
---|
[1299] | 226 |
|
---|
| 227 | \subsection{Using DataCards}
|
---|
| 228 | The {\bf DataCards} class can be used to read parameters from a file.
|
---|
| 229 | Each line in the file starting with \@ defines a set of values
|
---|
| 230 | associated with a keyword. In the example below, we read the
|
---|
| 231 | parameters corresponding with the keyword {\tt SIZE} from the
|
---|
| 232 | file {\tt ex.d}. We suppose that {\tt ex.d} contains the line: \\
|
---|
| 233 | {\tt @SIZE 400 250} \\
|
---|
| 234 | \begin{verbatim}
|
---|
| 235 | #include "datacards.h"
|
---|
| 236 | // ...
|
---|
| 237 | // Initializing DataCards object dc from file ex.d
|
---|
| 238 | DataCards dc( "ex.d" );
|
---|
| 239 | // Getting the first and second parameters for keyword size
|
---|
| 240 | // We define a default value 100
|
---|
| 241 | int size_x = dc.IParam("SIZE", 0, 100);
|
---|
| 242 | int size_y = dc.IParam("SIZE", 1, 100);
|
---|
| 243 | cout << " size_x= " << size_x << " size_y= " << size_y << endl;
|
---|
| 244 | \end{verbatim}
|
---|
| 245 |
|
---|
| 246 | \subsection{Dynamic linker}
|
---|
| 247 | The class {\bf PDynLinkMgr} can be used for managing shared libraries
|
---|
| 248 | at run time. The example below shows the run time linking of a function:\\
|
---|
| 249 | {\tt extern "C" { void myfunc(); } } \\
|
---|
| 250 | \begin{verbatim}
|
---|
| 251 | #include "pdlmgr.h"
|
---|
| 252 | // ...
|
---|
| 253 | string soname = "mylib.so";
|
---|
| 254 | string funcname = "myfunc";
|
---|
| 255 | PDynLinkMgr dyl(soname);
|
---|
| 256 | DlFunction f = dyl.GetFunction(funcname);
|
---|
| 257 | if (f != NULL) {
|
---|
| 258 | // Calling the function
|
---|
| 259 | f();
|
---|
| 260 | }
|
---|
| 261 | \end{verbatim}
|
---|
| 262 |
|
---|
| 263 | \section{Module TArray}
|
---|
| 264 | {\bf TArray} module contains template classes for handling standard
|
---|
| 265 | operations on numerical arrays. Using the class {\tt \tcls{TArray} },
|
---|
| 266 | it is possible to create and manipulate up to 5-dimension numerical
|
---|
| 267 | arrays {\tt (int, float, double, complex, \ldots)}.
|
---|
| 268 |
|
---|
| 269 | \begin{figure}[hbt]
|
---|
| 270 | \dclsccc{AnyDataObj}{BaseArray}{\tcls{TArray}}
|
---|
| 271 | \ldots \\
|
---|
| 272 | \dclsccc{\tcls{TArray}}{\tcls{TMatrix}}{\tcls{TVector}}
|
---|
| 273 | \caption{partial class diagram for arrays, matrices and vectors}
|
---|
| 274 | \end{figure}
|
---|
| 275 |
|
---|
| 276 | \subsection{Using arrays}
|
---|
| 277 |
|
---|
[1340] | 278 | The example below shows basic usage of arrays:
|
---|
| 279 | \begin{verbatim}
|
---|
| 280 | #include "array.h"
|
---|
| 281 | // ...
|
---|
| 282 | // Creation , filling of a Matrix
|
---|
| 283 | TMatrix<r_4> ma(7,9);
|
---|
| 284 | ma = RegularSequence(0.1, 0.05);
|
---|
| 285 | cout << "\n ma = " << ma << endl;
|
---|
| 286 | \end{verbatim}
|
---|
| 287 |
|
---|
| 288 | Example of a simple low-pass filter on a one dimensional array (Vector)
|
---|
| 289 | \begin{verbatim}
|
---|
| 290 | // Input Vector containing a noisy periodic signal
|
---|
| 291 | Vector in(1024), out(1024);
|
---|
| 292 | in = RandomSequence(RandomSequence::Gaussian, 0., 1.);
|
---|
| 293 | for(int kk=0; kk<in.Size(); kk++)
|
---|
| 294 | in(kk) += 2*sin(kk*0.05);
|
---|
| 295 | // Compute the output vector by a simple low pass filter
|
---|
| 296 | Vector out(1024);
|
---|
| 297 | int w = 2;
|
---|
| 298 | for(int k=w; k<in.Size()-w; k++)
|
---|
| 299 | out(k) = in(Range(k-w, k+w).Sum()/(2.*w+1.);
|
---|
| 300 | \end{verbatim}
|
---|
| 301 |
|
---|
[988] | 302 | \newpage
|
---|
| 303 |
|
---|
[1299] | 304 | \section{Module HiStats}
|
---|
| 305 | \begin{figure}[hbt]
|
---|
| 306 | \dclsccc{AnyDataObj}{Histo}{HProf}
|
---|
| 307 | \dclsbb{AnyDataObj}{Histo2D}
|
---|
| 308 | \dclsbb{AnyDataObj}{Ntuple}
|
---|
| 309 | \dclsb{XNtuple}
|
---|
| 310 | \caption{partial class diagram for histograms and ntuples}
|
---|
| 311 | \end{figure}
|
---|
| 312 |
|
---|
[1347] | 313 | {\bf HiStats} contains classes for creating, filling, printing and
|
---|
| 314 | doing various operations on one or two dimensional histograms
|
---|
| 315 | {\tt Histo} and {\tt Histo2D} as well as profile histograms {\tt HProf}. \\
|
---|
| 316 | This module also contains {\tt NTuple} and {\tt XNTuple} which are
|
---|
| 317 | more or less the same that the binary FITS tables.
|
---|
| 318 |
|
---|
| 319 | \subsection{1D Histograms}
|
---|
| 320 |
|
---|
| 321 | For 1D histograms, various numerical methods are provided such as
|
---|
| 322 | computing means and sigmas, finding maxima, fitting, rebinning,
|
---|
| 323 | integrating \dots \\
|
---|
| 324 | The example below shows creating and filling a one dimensionnal histogram
|
---|
| 325 | of 100 bins from $-5.$ to $+5.$ to create a gaussian normal distribution
|
---|
| 326 | with errors~:
|
---|
| 327 | \begin{verbatim}
|
---|
| 328 | #include "histos.h"
|
---|
| 329 | // ...
|
---|
| 330 | Histo H(-0.5,0.5,100);
|
---|
| 331 | H.Errors();
|
---|
| 332 | for(int i=0;i<25000;i++) {
|
---|
| 333 | double x = NorRand();
|
---|
| 334 | H.Add(x);
|
---|
| 335 | }
|
---|
| 336 | H.Print(80);
|
---|
| 337 | \end{verbatim}
|
---|
| 338 |
|
---|
| 339 | \subsection{2D Histograms}
|
---|
| 340 |
|
---|
| 341 | Much of these operations are also valid for 2D histograms. 1D projection
|
---|
| 342 | or slices can be set~:
|
---|
| 343 | \begin{verbatim}
|
---|
| 344 | #include "histos2.h"
|
---|
| 345 | // ...
|
---|
| 346 | Histo H2(-1.,1.,100,0.,60.,50);
|
---|
| 347 | H2.SetProjX(); // create the 1D histo for X projection
|
---|
| 348 | H2.SetBandX(25.,35.); // create 1D histo projection for 25.<y<35.
|
---|
| 349 | H2.SetBandX(35.,45.); // create 1D histo projection for 35.<y<45.
|
---|
| 350 | H2.SetBandX(40.,55.); // create 1D histo projection for 40.<y<55.
|
---|
| 351 | //... fill H2 with what ever you want
|
---|
| 352 | H2.Print();
|
---|
| 353 | Histo *hx = H2.HProjX();
|
---|
| 354 | hx->Print(80);
|
---|
| 355 | Histo *hbx2 = HBandX(1); // Get the second X band (35.<y<45.)
|
---|
| 356 | hbx2->Print(80);
|
---|
| 357 | \end{verbatim}
|
---|
| 358 |
|
---|
| 359 | \subsection{Profile Histograms}
|
---|
| 360 |
|
---|
| 361 | Profiles histograms contains the mean and the sigma of the distribution
|
---|
| 362 | of the values filled in each bin. The sigma can be changed to
|
---|
| 363 | the error on the mean. When filled, the profile histogram looks
|
---|
| 364 | like a 1D histogram and much of the operations that can be done on 1D histo
|
---|
| 365 | may be applied onto profile histograms.
|
---|
| 366 |
|
---|
| 367 | \subsection{Ntuples}
|
---|
| 368 |
|
---|
| 369 | NTuple are memory resident tables of 32 bits floating values (float).
|
---|
| 370 | They are arranged in columns. Each line is often called an event.
|
---|
| 371 | These objects are frequently used to analyze data.
|
---|
| 372 | Graphicals tools (spiapp) can plot a column against an other one
|
---|
| 373 | with respect to various selection cuts. \\
|
---|
| 374 | Here is an example of creation and filling~:
|
---|
| 375 | \begin{verbatim}
|
---|
| 376 | #include "ntuple.h"
|
---|
| 377 | #include "srandgen.h"
|
---|
| 378 | // ...
|
---|
| 379 | char* nament[4] = {"i","x","y","ey"};
|
---|
| 380 | r_4 xnt[4];
|
---|
| 381 | NTuple NT(4,nament);
|
---|
| 382 | for(i=0;i<5000;i++) {
|
---|
| 383 | xnt[0] = i+1;
|
---|
| 384 | xnt[1] = 5.*drandpm1(); // a random value between -5 and +5
|
---|
| 385 | xnt[2] = 100.*exp(-0.5*xnt[1]*xnt[1]) + 1.;
|
---|
| 386 | xnt[3] = sqrt(xnt[2]);
|
---|
| 387 | xnt[2] += xnt[3] * NorRand(); // add a random gaussian error
|
---|
| 388 | NT.Fill(xnt);
|
---|
| 389 | }
|
---|
| 390 | \end{verbatim}
|
---|
| 391 |
|
---|
| 392 | XNtuple are sophisticated NTuple : they accept various types
|
---|
| 393 | of column values (float,double,int,...) and can be as big as
|
---|
| 394 | needed (they used buffers on hard disk).
|
---|
| 395 |
|
---|
| 396 | \subsection{Writing, seeing \dots }
|
---|
| 397 |
|
---|
| 398 | All these objects have been design to be written to or read from a persistant file.
|
---|
| 399 | The following example shows how to write the previously created objects
|
---|
| 400 | into such a file~:
|
---|
| 401 | \begin{verbatim}
|
---|
| 402 | //-- Writing
|
---|
| 403 | {
|
---|
| 404 | char *fileout = "myfile.ppf";
|
---|
| 405 | string tag;
|
---|
| 406 | POutPersist outppf(fileout);
|
---|
| 407 | tag = "H"; outppf.PutObject(H,tag);
|
---|
| 408 | tag = "H2"; outppf.PutObject(H2,tag);
|
---|
| 409 | tag = "NT"; outppf.PutObject(NT,tag);
|
---|
| 410 | } // closing ``}'' destroy ``outppf'' and automatically close the file !
|
---|
| 411 | \end{verbatim}
|
---|
| 412 |
|
---|
| 413 | Sophya graphical tools (spiapp) can automatically display and operate
|
---|
| 414 | all these objects.
|
---|
| 415 |
|
---|
[1299] | 416 | \section{Module SkyMap}
|
---|
| 417 |
|
---|
| 418 | \section{Module NTools}
|
---|
| 419 |
|
---|
[1347] | 420 | This module provides elementary numerical tools for numerical integration,
|
---|
| 421 | fitting, sorting and ODE solving. FFTs are also provided (Mayer,FFTPack).
|
---|
| 422 |
|
---|
| 423 | \subsection{Fitting}
|
---|
| 424 |
|
---|
| 425 | Fitting is done with two classes {\tt GeneralFit} and {\tt GeneralFitData}
|
---|
| 426 | and is based on the Levenberg-Marquardt method.
|
---|
| 427 | GeneralFitData is a class which provide a description of the data
|
---|
| 428 | to be fitted. GeneralFit is the fitter class. Parametrized functions
|
---|
| 429 | can be given as classes which inherit {\tt GeneralFunction}
|
---|
| 430 | or as simple C functions. Classes of pre-defined functions are provided
|
---|
| 431 | (see files fct1dfit.h and fct2dfit.h). The user interface is very close
|
---|
| 432 | from that of the CERN {\tt Minuit} fitter.
|
---|
| 433 | Number of objects (Histo, HProf \dots ) are interfaced with GeneralFit
|
---|
| 434 | and can be easily fitted. \\
|
---|
| 435 | Here is a very simple example for fitting the previously created NTuple
|
---|
| 436 | with a gaussian~:
|
---|
| 437 | \begin{verbatim}
|
---|
| 438 | #include "fct1dfit.h"
|
---|
| 439 | // ...
|
---|
| 440 |
|
---|
| 441 | // Read from ppf file
|
---|
| 442 | NTuple nt;
|
---|
| 443 | {
|
---|
| 444 | PInPersist pis("myfile.ppf");
|
---|
| 445 | string tag = "NT"; pis.GetObject(nt,tag);
|
---|
| 446 | }
|
---|
| 447 |
|
---|
| 448 | // Fill GeneralData
|
---|
| 449 | GeneralData mGdata(nt.NEntry());
|
---|
| 450 | for(int i=0; i<nt.NEntry(); i++)
|
---|
| 451 | mGdata.AddData1(xnt[1],xnt[2],xnt[3]); // Fill x, y and error on y
|
---|
| 452 | mGData.PrintStatus();
|
---|
| 453 |
|
---|
| 454 | // Function for fitting : y = f(x) + noise
|
---|
| 455 | Gauss1DPol mFunction; // gaussian + constant
|
---|
| 456 |
|
---|
| 457 | // Prepare for fit
|
---|
| 458 | GeneralFit mFit(&mFunction); // create a fitter for the choosen function
|
---|
| 459 | mFit.SetData(&mGData); // connect data to the fitter
|
---|
| 460 |
|
---|
| 461 | // Set and initialize the parameters (that's non-linear fitting!)
|
---|
| 462 | // (num par, name, guess start, step, [limits min and max])
|
---|
| 463 | mFit.SetParam(0,"high",90.,1..);
|
---|
| 464 | mFit.SetParam(1,"xcenter",0.05,0.01);
|
---|
| 465 | mFit.SetParam(2,"sigma",sig,0.05,0.01,10.);
|
---|
| 466 | // Give limits to avoid division by zero
|
---|
| 467 | mFit.SetParam(3,"constant",0.,1.);
|
---|
| 468 |
|
---|
| 469 | // Fit and print result
|
---|
| 470 | int rcfit = mFit.Fit();
|
---|
| 471 | mFit.PrintFit();
|
---|
| 472 | if(rcfit>0) {)
|
---|
| 473 | cout<<"Reduce_Chisquare = "<<mFit.GetChi2Red()
|
---|
| 474 | <<" nstep="<<mFit.GetNStep()<<" rc="<<rcfit<<endl;
|
---|
| 475 | } else {
|
---|
| 476 | cout<<"Fit_Error, rc = "<<rcfit<<" nstep="<<mFit.GetNStep()<<endl;
|
---|
| 477 | mFit.PrintFitErr(rcfit);
|
---|
| 478 | }
|
---|
| 479 |
|
---|
| 480 | // Get the result for further use
|
---|
| 481 | TVector<r_8> ParResult = mFit.GetParm();
|
---|
| 482 | cout<<ParResult;
|
---|
| 483 | \end{verbatim}
|
---|
| 484 |
|
---|
| 485 | Much more usefull possibilities and detailed informations might be found
|
---|
| 486 | in the HTML pages of the Sophya manual.
|
---|
| 487 |
|
---|
[1350] | 488 | \subsection{Polynomial}
|
---|
[1347] | 489 |
|
---|
[1350] | 490 | Polynomials of 1 or 2 variables are supported ({\tt Poly} and {\tt Poly2}).
|
---|
| 491 | Various operations are supported~:
|
---|
| 492 | \begin{itemize}
|
---|
| 493 | \item elementary operations between polynomials $(+,-,*,/) $
|
---|
| 494 | \item setting or getting coefficients
|
---|
| 495 | \item computing the value of the polynomial for a given value
|
---|
| 496 | of the variable(s),
|
---|
| 497 | \item derivating
|
---|
| 498 | \item computing roots (degre 1 or 2)
|
---|
| 499 | \item fitting the polynomial to vectors of data.
|
---|
| 500 | \end{itemize}
|
---|
| 501 | Here is an example of polynomial fitting~:
|
---|
| 502 | \begin{verbatim}
|
---|
| 503 | #include "poly.h"
|
---|
| 504 | // ...
|
---|
| 505 | Poly pol(2);
|
---|
| 506 | pol[0] = 100.; pol[1] = 0.; pol[2] = 0.01; // Setting coefficients
|
---|
| 507 | TVector<r_8> x(100);
|
---|
| 508 | TVector<r_8> y(100);
|
---|
| 509 | TVector<r_8> ey(100);
|
---|
| 510 | for(int i=0;i<100;i++) {
|
---|
| 511 | x(i) = i;
|
---|
| 512 | ey(i) = 10.;
|
---|
| 513 | y(i) = pol((double) i) + ey(i)*NorRand();
|
---|
| 514 | ey(i) *= ey(i)
|
---|
| 515 | }
|
---|
| 516 |
|
---|
| 517 | TVector<r_8> errcoef;
|
---|
| 518 | Poly polfit;
|
---|
| 519 | polfit.Fit(x,y,ey,2,errcoef);
|
---|
| 520 |
|
---|
| 521 | cout<<"Fit Result"<<polfit<<endl;
|
---|
| 522 | cout<<"Errors :"<<errcoef;
|
---|
| 523 | \end{verbatim}
|
---|
| 524 |
|
---|
| 525 | Similar operations can be done on polynomials with 2 variables.
|
---|
| 526 |
|
---|
[1299] | 527 | \section{Module Samba}
|
---|
| 528 |
|
---|
| 529 | \section{Module SkyT}
|
---|
| 530 |
|
---|
| 531 |
|
---|
[1340] | 532 | \newpage
|
---|
[978] | 533 | \section{Building and installing Sophya}
|
---|
| 534 | Presently, the Sophya library compilation has been tested with the following
|
---|
| 535 | compiler/platform pairs:
|
---|
| 536 |
|
---|
| 537 | \begin{center}
|
---|
| 538 | \begin{tabular}{ll}
|
---|
| 539 | Compaq/DEC OSF1 & cxx (6.0 , 6.2) \\
|
---|
| 540 | Linux & g++ (2.91 , 2.95) \\
|
---|
| 541 | Linux & KCC (3.4) \\
|
---|
| 542 | Solaris & g++ (2.95) \\
|
---|
| 543 | SGI IRIX64 & CC \\
|
---|
| 544 | \end{tabular}
|
---|
| 545 | \end{center}
|
---|
| 546 |
|
---|
| 547 | Some of the modules in the Sophya package uses external libraries. The
|
---|
| 548 | {\bf FitsIOServer} is the example of such a module, where the {\tt libcfitsio.a}
|
---|
| 549 | is used.
|
---|
| 550 | The build procedure expects to find the include files and the libraries in: \\
|
---|
| 551 | {\tt \$EXTLIBDIR/Include/FitsIO } \\
|
---|
| 552 | {\tt \$EXTLIBDIR/`uname`-\$EROSCXX/Libs} \\
|
---|
| 553 |
|
---|
| 554 | The object files from a given Sophya module are grouped in an archive library
|
---|
| 555 | with the module's name ({\tt libmodulename.a}). All Sophya modules
|
---|
| 556 | are grouped in a single shared library ({\tt libsophya.so}), while the
|
---|
| 557 | modules with reference to external libraries are grouped in
|
---|
| 558 | ({\tt libextsophya.so}). The {\bf PI} and {\bf PIext} modules are
|
---|
| 559 | grouped in ({\tt libPI.so}).
|
---|
| 560 |
|
---|
| 561 | The environment variables {\bf DPCDEVREP}, {\bf EXTLIBDIR} and {\bf EROSCXX}
|
---|
| 562 | must be defined in order to install the Sophya package.
|
---|
| 563 | In the example below, we assume that we want to install Sophya from a
|
---|
| 564 | released (tagged) version in the source directory {\tt \$SRC} in the
|
---|
| 565 | {\tt /usr/local/Sophya} diretory, using {\tt g++}. We assume that
|
---|
| 566 | the external libraries directory tree has been set up in
|
---|
| 567 | {\tt /usr/local/ExtLibs/}. \\[3mm]
|
---|
[988] | 568 | \centerline{
|
---|
| 569 | \rule{20mm}{0.5mm}
|
---|
| 570 | {\bf \large the use of GNU make is mandatory}
|
---|
| 571 | \rule{20mm}{0.5mm} }
|
---|
[1299] | 572 |
|
---|
[978] | 573 | \vspace*{3mm}
|
---|
| 574 | \begin{verbatim}
|
---|
| 575 | # We select our C++ compiler
|
---|
| 576 | csh> setenv EROSCXX g++
|
---|
| 577 | # Setup the build directory
|
---|
| 578 | csh> mkdir /usr/local/Sophya/
|
---|
| 579 | csh> setenv DPCDEVREP /usr/local/Sophya/
|
---|
| 580 | csh> setenv EXTLIBDIR /usr/local/ExtLibs/
|
---|
| 581 | # Use the top level makefile in Mgr/
|
---|
[1299] | 582 | csh> cd \$SRC
|
---|
[978] | 583 | csh> cp Mgr/Makefile Makefile
|
---|
| 584 | # Step 1: Create the directory tree and copy the include files (.h)
|
---|
| 585 | csh> make depend
|
---|
| 586 | # Step 2: Compile the modules without external library reference
|
---|
| 587 | csh> make libs
|
---|
| 588 | # Step 3: Compile the modules WITH external library reference (optional)
|
---|
| 589 | csh> make extlibs
|
---|
| 590 | # Step 4: Build libsophya.so
|
---|
| 591 | csh> make slb
|
---|
| 592 | # Step 5: Build libextsophya.so (optional)
|
---|
| 593 | csh> make slbext
|
---|
| 594 | # Step 6: Compile the PI and PIext modules (optional)
|
---|
| 595 | csh> make PI
|
---|
| 596 | # Step 7: Build the corresponding shared library libPI.so (optional)
|
---|
| 597 | csh> make slbpi
|
---|
| 598 | \end{verbatim}
|
---|
| 599 |
|
---|
| 600 | To compile all modules and build the shared libraries, it is possible
|
---|
| 601 | to use:
|
---|
| 602 | \begin{verbatim}
|
---|
| 603 | # Step 2,3,6
|
---|
| 604 | csh> make all
|
---|
| 605 | # Step 4,5,7
|
---|
[1292] | 606 | csh> make slball
|
---|
[978] | 607 | \end{verbatim}
|
---|
| 608 |
|
---|
| 609 | At this step, all libraries sould have been made. Programs using
|
---|
| 610 | Sophya libraries can now be built:
|
---|
| 611 | \begin{verbatim}
|
---|
| 612 | # To compile test programs
|
---|
| 613 | csh> cd Tests
|
---|
| 614 | csh> make arrt ...
|
---|
| 615 | csh> cd ..
|
---|
| 616 | # To compile other programs, for example from the PMixer module
|
---|
| 617 | csh> cd PMixer
|
---|
| 618 | csh> make
|
---|
| 619 | csh> cd ..
|
---|
| 620 | # To build (s)piapp (libPI.so is needed)
|
---|
| 621 | csh> cd ProgPI
|
---|
| 622 | csh> make
|
---|
| 623 | csh> cd ..
|
---|
| 624 | \end{verbatim}
|
---|
| 625 |
|
---|
[988] | 626 | \subsection{Mgr module}
|
---|
| 627 | This module contains scripts which can be used for generating the
|
---|
| 628 | makefiles for each module.
|
---|
| 629 | \begin{itemize}
|
---|
| 630 | \item {\bf Makefile} Top level Makefile for builiding the libraries.
|
---|
| 631 | \item {\bf Makefile.h} contains the defintion of compilation flags for the
|
---|
| 632 | different compilers and systems. This file is used for building the
|
---|
| 633 | library and generating {\bf MakefileUser.h} (to be included in makefiles).
|
---|
| 634 | \item {\bf Makefile.slb} contains the rules for building shared libraries
|
---|
| 635 | for the different compilers and systems. (to be included in makefiles)
|
---|
| 636 | \item {\bf crerep\_sophya} c-shell script for creating the directory tree
|
---|
| 637 | under {\tt \$DPCBASEREP} and {\tt \$DPCDEVREP}
|
---|
| 638 | \item {\bf install\_sophya} c-shell script for installing the Sophya package.
|
---|
| 639 | Usually from {\tt \$DPCDEVREP} to {\tt \$DPCBASEREP}
|
---|
| 640 | \item {\bf mkmflien} c-shell script for making symbolic links or copying
|
---|
| 641 | include files to {\tt \$DPCDEVREP/Include} or {\tt \$DPCBASEREP/Include}
|
---|
| 642 | \item {\bf mkmf} c-shell script for generating module makefiles and the
|
---|
| 643 | top level makefile (named GNUmakefile)
|
---|
| 644 | \item {\bf mkmflib} c-shell script for generating each library module
|
---|
| 645 | makefile (named GNUmakefile)
|
---|
| 646 | \item {\bf mkmfprog} c-shell script for generating makefile for a module
|
---|
| 647 | containing the source for executable programs (named GNUmakefile).
|
---|
| 648 | \item {\bf mkmfPI} c-shell script for generating makefile for PI and PIext
|
---|
| 649 | modules (named GNUmakefile)
|
---|
| 650 | \item {\bf libdirs} List of Sophya modules without reference to external
|
---|
| 651 | libraries.
|
---|
| 652 | \item {\bf extlibdirs} List of Sophya modules with reference to external
|
---|
| 653 | libraries.
|
---|
[887] | 654 |
|
---|
[988] | 655 | \end{itemize}
|
---|
| 656 |
|
---|
| 657 | \newpage
|
---|
[1299] | 658 | \appendix
|
---|
| 659 | \section{Exception handling: An example}
|
---|
| 660 | For simple programs, it is a good practice to handle
|
---|
[988] | 661 | the exceptions at least at high level, in the {\tt main()} function.
|
---|
| 662 | The example below shows the exception handling and the usage
|
---|
| 663 | of Sophya persistence.
|
---|
[1299] | 664 |
|
---|
[988] | 665 | \input{ex1.inc}
|
---|
[887] | 666 |
|
---|
[1292] | 667 |
|
---|
[1299] | 668 | \end{document}
|
---|