Re:

From: Valery Fine (Valeri.Faine@cern.ch)
Date: Tue Apr 15 1997 - 15:14:59 MEST


On 15 Apr 97 at 13:36, Robert Loke wrote:

> Suppose there is a given program, which is basically running. After
> some time you find that there is some need for histogramming data
> within this program, which can principally done using root. What are
> the option for implementing root functions without changing more
> than adding a few lines in the source code and adding diverse libs
> and so on in the makefile?
> 

  The "test" subdirectory from our distribution contains the 
hsimple.cxx file and makefile to build it.

  I hope it can be used as pattern to start with.

  The source of that program looks as follows. But I'd like to highlight
It is assumed one needs no interaction (drawing is a kind of the 
interaction too) with his data. It is a "pure" batch job. Then one 
can explore the data file been created with the interactive ROOT 
session later.
                      Valery

 PS. Please, always fill "Subj" field of your E-mail sending it to 
"roottalk" list.

//*CMZ :  1.00/00 17/02/97  16.44.11  by  Fons Rademakers
//*-- Author :    Rene Brun   19/08/96
//______________________________________________________________________________
//*-*-*-*-*-*-*Simple examples with histograms created/filled and saved*-*-*-*
//*-*          ========================================================
//*-*
//*-*  This program creates :
//*-*    - a one dimensional histogram
//*-*    - a two dimensional histogram
//*-*    - a profile histogram
//*-*    - an ntuple
//*-*
//*-*  These objects are filled with some random numbers and saved on a file.
//*-*
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

#include "TROOT.h"
#include "TFile.h"
#include "TH1.h"
#include "TH2.h"
#include "TProfile.h"
#include "TNtuple.h"
#include "TRandom.h"


//______________________________________________________________________________
main(int argc, char **argv)
{
  TROOT simple("simple","Test of histogramming and I/O");

  // Create a new ROOT binary machine independent file.
  // Note that this file may contain any kind of ROOT objects, histograms,
  // pictures, graphics objects, detector geometries, tracks, events, etc..
  // This file is now becoming the current directory.
  TFile hfile("hsimple.root","RECREATE","Demo ROOT file with histograms");

  // Create some histograms, a profile histogram and an ntuple
  TH1F *hpx   = new TH1F("hpx","This is the px distribution",100,-4,4);
  TH2F *hpxpy = new TH2F("hpxpy","py ps px",40,-4,4,40,-4,4);
  TProfile *hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
  TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i");

  // Fill histograms randomly
  Float_t px, py, pz;
  for ( Int_t i=0; i<10000; i++) {
     gRandom->Rannor(px,py); //px and py will be two gaussian random numbers
     pz = px*px + py*py;
     Float_t random = gRandom->Rndm(1);
     hpx->Fill(px);
     hpxpy->Fill(px,py);
     hprof->Fill(px,pz);
     ntuple->Fill(px,py,pz,random,i);
  }

  // Save all objects in this file
  hfile.Write();

  // Close the file. Note that this is automatically done when you leave
  // the application.
  hfile.Close();

  return 0;
}
=================================================================
Dr. Valery Fine                  Telex : 911621 dubna su
    -----------
LCTA/Joint Inst.for NuclearRes   Phone : +7 09621 6 40 80
141980 Dubna, Moscow region      Fax   : +7 09621 6 51 45
Russia                           mailto:fine@main1.jinr.dubna.su
                                 mailto:fine@vxcern.cern.ch
Dr. Valeri Faine
    ------------                 Phone: +41 22 767 6468
CERN                             FAX  : +41 22 782 2601
CH-1211 Geneva, 23               mailto:fine@vxcern.cern.ch 
Switzerland                      http://nicewww.cern.ch/~fine
                                 



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:18 MET