ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
hksimple.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// Illustrates the advantages of a TH1K histogram
4 ///
5 /// \macro_image
6 /// \macro_code
7 ///
8 /// \author Victor Perevovchikov
9 
10 void padRefresh(TPad *pad,int flag=0);
11 void hksimple()
12 {
13 // Create a new canvas.
14  c1 = new TCanvas("c1","Dynamic Filling Example",200,10,600,900);
15  c1->SetFillColor(42);
16 
17 // Create a normal histogram and two TH1K histograms
18  TH1 *hpx[3];
19  hpx[0] = new TH1F("hp0","Normal histogram",1000,-4,4);
20  hpx[1] = new TH1K("hk1","Nearest Neighbour of order 3",1000,-4,4);
21  hpx[2] = new TH1K("hk2","Nearest Neighbour of order 16",1000,-4,4,16);
22  c1->Divide(1,3);
23  Int_t j;
24  for (j=0;j<3;j++) {
25  c1->cd(j+1);
26  gPad->SetFrameFillColor(33);
27  hpx[j]->SetFillColor(48);
28  hpx[j]->Draw();
29  }
30 
31 // Fill histograms randomly
32  gRandom->SetSeed();
33  Float_t px, py, pz;
34  const Int_t kUPDATE = 10;
35  for (Int_t i = 0; i <= 300; i++) {
36  gRandom->Rannor(px,py);
37  for (j=0;j<3;j++) {hpx[j]->Fill(px);}
38  if (i && (i%kUPDATE) == 0) {
39  padRefresh(c1);
40  }
41  }
42 
43  for (j=0;j<3;j++) hpx[j]->Fit("gaus");
44  padRefresh(c1);
45 }
46 void padRefresh(TPad *pad,int flag)
47 {
48  if (!pad) return;
49  pad->Modified();
50  pad->Update();
51  TList *tl = pad->GetListOfPrimitives();
52  if (!tl) return;
53  TListIter next(tl);
54  TObject *to;
55  while ((to=next())) {
56  if (to->InheritsFrom(TPad::Class())) padRefresh((TPad*)to,1);}
57  if (flag) return;
59 }
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:420
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition: TRandom.cxx:460
Float_t pz
Definition: hprod.C:33
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
float Float_t
Definition: RtypesCore.h:53
TCanvas * c1
Definition: legend1.C:2
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
virtual void Update()
Update pad.
Definition: TPad.cxx:2721
int Int_t
Definition: RtypesCore.h:41
Float_t py
Definition: hprod.C:33
virtual void SetSeed(UInt_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:568
Iterator of linked list.
Definition: TList.h:187
void Class()
Definition: Class.C:29
A doubly linked list.
Definition: TList.h:47
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
The most important graphics class in the ROOT system.
Definition: TPad.h:46
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
TH1K class supports the nearest K Neighbours method, widely used in cluster analysis.
Definition: TH1K.h:27
The Canvas class.
Definition: TCanvas.h:48
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:133
The TH1 histogram class.
Definition: TH1.h:80
Mother of all ROOT objects.
Definition: TObject.h:58
Float_t px
Definition: hprod.C:33
TList * GetListOfPrimitives() const
Definition: TPad.h:240
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1073
#define gPad
Definition: TVirtualPad.h:288
void Modified(Bool_t flag=1)
Definition: TPad.h:407