Changeset 1347 in Sophya for trunk/SophyaLib/Manual
- Timestamp:
- Nov 26, 2000, 12:01:25 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/Manual/sophya.tex
r1340 r1347 311 311 \end{figure} 312 312 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 313 416 \section{Module SkyMap} 314 417 315 418 \section{Module NTools} 419 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 316 488 317 489 \section{Module Samba}
Note:
See TracChangeset
for help on using the changeset viewer.