hsimple.cxx

Go to the documentation of this file.
00001 // @(#)root/test:$Id: hsimple.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Rene Brun   19/08/96
00003 
00004 //*-*-*-*-*-*-*Simple examples with histograms created/filled and saved*-*-*-*
00005 //*-*          ========================================================
00006 //*-*
00007 //*-*  This program creates :
00008 //*-*    - a one dimensional histogram
00009 //*-*    - a two dimensional histogram
00010 //*-*    - a profile histogram
00011 //*-*    - an ntuple
00012 //*-*
00013 //*-*  These objects are filled with some random numbers and saved on a file.
00014 //*-*
00015 //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00016 
00017 int hsimple();
00018 
00019 #ifndef __CINT__
00020 #include "TFile.h"
00021 #include "TH1.h"
00022 #include "TH2.h"
00023 #include "TProfile.h"
00024 #include "TNtuple.h"
00025 #include "TRandom.h"
00026 
00027 
00028 //______________________________________________________________________________
00029 int main()
00030 {
00031   return hsimple();
00032 }
00033 #endif
00034 
00035 int hsimple()
00036 {
00037   // Create a new ROOT binary machine independent file.
00038   // Note that this file may contain any kind of ROOT objects, histograms,
00039   // pictures, graphics objects, detector geometries, tracks, events, etc..
00040   // This file is now becoming the current directory.
00041   TFile hfile("hsimple.root","RECREATE","Demo ROOT file with histograms");
00042 
00043   // Create some histograms, a profile histogram and an ntuple
00044   TH1F *hpx   = new TH1F("hpx","This is the px distribution",100,-4,4);
00045   TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
00046   TProfile *hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
00047   TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i");
00048 
00049   // Fill histograms randomly
00050   Float_t px, py, pz;
00051   for ( Int_t i=0; i<10000; i++) {
00052      gRandom->Rannor(px,py); //px and py will be two gaussian random numbers
00053      pz = px*px + py*py;
00054      Float_t random = gRandom->Rndm(1);
00055      hpx->Fill(px);
00056      hpxpy->Fill(px,py);
00057      hprof->Fill(px,pz);
00058      ntuple->Fill(px,py,pz,random,i);
00059   }
00060 
00061   // Save all objects in this file
00062   hfile.Write();
00063 
00064   // Close the file. Note that this is automatically done when you leave
00065   // the application.
00066   hfile.Close();
00067 
00068   return 0;
00069 }

Generated on Tue Jul 5 15:15:03 2011 for ROOT_528-00b_version by  doxygen 1.5.1