ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FirstContour.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// Make a contour plot and get the first contour in a TPolyMarker.
4 /// This macro generates a color contour plot by selecting entries
5 /// from an ntuple file.
6 /// The TGraph object corresponding to the first contour line is
7 /// accessed and displayed into a separate canvas.
8 ///
9 /// \macro_code
10 ///
11 /// \author Rene Brun
12 
13 void FirstContour()
14 {
15  TString dir = gSystem->UnixPathName(__FILE__);
16  dir.ReplaceAll("FirstContour.C","../hsimple.C");
17  dir.ReplaceAll("/./","/");
18  if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
19  TFile *file = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
20  if (!file) return;
21  TTree *ntuple = (TTree*)file->Get("ntuple");
22 
23  TCanvas *c1 = new TCanvas("c1","Contours",10,10,800,600);
24  gStyle->SetPalette(1);
25  ntuple->Draw("py:px","px*px+py*py < 20", "contz,list");
26 
27  //we must call Update to force the canvas to be painted. When
28  //painting the contour plot, the list of contours is generated
29  //and a reference to it added to the Root list of special objects
30  c1->Update();
31 
32  TCanvas *c2 = new TCanvas("c2","First contour",100,100,800,600);
33 
34 
35  TObjArray *contours =
36  (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
37  if (!contours) return;
38  TList *lcontour1 = (TList*)contours->At(0);
39  if (!lcontour1) return;
40  TGraph *gc1 = (TGraph*)lcontour1->First();
41  if (!gc1) return;
42  if (gc1->GetN() < 10) return;
43  gc1->SetMarkerStyle(21);
44  gc1->Draw("alp");
45 
46  //We make a TCutG object with the array obtained from this graph
47  TCutG *cutg = new TCutG("cutg",gc1->GetN(),gc1->GetX(),gc1->GetY());
48 
49  //We create a polymarker object with npmax points.
50  const Int_t npmax = 50000;
51  TPolyMarker *pm = new TPolyMarker(npmax);
52  Int_t np = 0;
53  while(1) {
54  Double_t x = -4 +8*gRandom->Rndm();
55  Double_t y = -4 +8*gRandom->Rndm();
56  if (cutg->IsInside(x,y)) {
57  pm->SetPoint(np,x,y);
58  np++;
59  if (np == npmax) break;
60  }
61  }
62  pm->Draw();
63 }
virtual void Draw(Option_t *option="")
Draw.
An array of TObjects.
Definition: TObjArray.h:39
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom.cxx:512
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
virtual Int_t IsInside(Double_t x, Double_t y) const
Return 1 if the point (x,y) is inside the polygon defined by the graph vertices 0 otherwise...
Definition: TGraph.cxx:1771
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
#define gROOT
Definition: TROOT.h:344
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
#define gInterpreter
Definition: TInterpreter.h:502
Int_t GetN() const
Definition: TGraph.h:132
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:740
virtual const char * UnixPathName(const char *unixpathname)
Convert from a Unix pathname to a local pathname.
Definition: TSystem.cxx:1020
const char * Data() const
Definition: TString.h:349
Double_t * GetY() const
Definition: TGraph.h:140
Graphical cut class.
Definition: TCutG.h:29
A doubly linked list.
Definition: TList.h:47
Double_t * GetX() const
Definition: TGraph.h:139
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
virtual void SetMarkerStyle(Style_t mstyle=1)
Definition: TAttMarker.h:53
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
virtual void SetPoint(Int_t point, Double_t x, Double_t y)
Set point number n.
The Canvas class.
Definition: TCanvas.h:48
A PolyMarker is defined by an array on N points in a 2-D space.
Definition: TPolyMarker.h:37
double Double_t
Definition: RtypesCore.h:55
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition: TTree.h:360
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:557
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
A TTree object has a header with a name and a title.
Definition: TTree.h:98
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179
void SetPalette(Int_t ncolors=kBird, Int_t *colors=0, Float_t alpha=1.)
See TColor::SetPalette.
Definition: TStyle.cxx:1445