Go to the documentation of this file.00001 {
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 TGo4Analysis* go4=TGo4Analysis::Instance();
00028 go4->CloseAnalysis();
00029 go4->InitEventClasses();
00030
00031 c1 = new TCanvas("c1","Dynamic Filling Example",200,10,700,500);
00032 c1->SetFillColor(42);
00033 c1->GetFrame()->SetFillColor(21);
00034 c1->GetFrame()->SetBorderSize(6);
00035 c1->GetFrame()->SetBorderMode(-1);
00036
00037
00038
00039
00040
00041
00042 TFile *hfile = (TFile*)gROOT->FindObject("hsimple.root"); if (hfile) hfile->Close();
00043 hfile = TFile::Open("hsimple.root","RECREATE","Demo ROOT file with histograms");
00044
00045
00046 hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
00047 hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
00048 hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
00049
00050
00051
00052 ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i");
00053
00054
00055
00056 go4->AddHistogram(hpx);
00057 go4->AddHistogram(hpxpy);
00058 go4->AddHistogram(hprof);
00059 go4->AddTree(ntuple);
00060
00061
00062 hpx->SetFillColor(48);
00063
00064
00065 gRandom->SetSeed();
00066 Float_t px, py, pz;
00067 const Int_t kUPDATE = 1000;
00068 Int_t i=0;
00069 while(1){
00070 std::cout <<"Waiting for the Go4 start button.";
00071 std::cout <<" \n\tUse Canvas menu 'Options/Interrupt' to leave macro." << std::endl;
00072 Int_t seconds=go4->WaitForStart();
00073 if(seconds<0) break;
00074 std::cout <<"Starting execution loop after "<<seconds<<" s of waiting" << std::endl;
00075 gBenchmark->Reset();
00076 gBenchmark->Start("hsimple");
00078 while(go4->Process()==0){
00079
00080 gRandom->Rannor(px,py);
00081 pz = px*px + py*py;
00082 Float_t random = gRandom->Rndm(1);
00083 hpx->Fill(px);
00084 hpxpy->Fill(px,py);
00085 hprof->Fill(px,pz);
00086 ntuple->Fill(px,py,pz,random,i);
00087 if (i && (i%kUPDATE) == 0) {
00088 if (i == kUPDATE) hpx->Draw();
00089 c1->Modified();
00090 c1->Update();
00091 if (gSystem->ProcessEvents())
00092 {
00093 go4->SetRunning(kFALSE);
00094 gROOT->SetInterrupt(kFALSE);
00095 break;
00096 }
00097
00098 }
00099 i++;
00100 }
00102 gBenchmark->Show("hsimple");
00103
00104 hpx->SetFillColor(0);
00105 hfile->Write();
00106 hpx->SetFillColor(48);
00107 c1->Modified();
00108 }
00109 gROOT->SetInterrupt(kFALSE);
00110 go4->RemoveTree(ntuple);
00111
00112
00113
00114 }