00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00038
00039
00040
00041 TFile hfile("hsimple.root","RECREATE","Demo ROOT file with histograms");
00042
00043
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
00050 Float_t px, py, pz;
00051 for ( Int_t i=0; i<10000; i++) {
00052 gRandom->Rannor(px,py);
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
00062 hfile.Write();
00063
00064
00065
00066 hfile.Close();
00067
00068 return 0;
00069 }