Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
FirstContour.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
4/// Make a contour plot and get the first contour in a TPolyMarker.
5/// This macro generates a color contour plot by selecting entries
6/// from an ntuple file.
7/// The TGraph object corresponding to the first contour line is
8/// accessed and displayed into a separate canvas.
9///
10/// \macro_code
11///
12/// \author Rene Brun
13
14void FirstContour()
15{
16 TString dir = gROOT->GetTutorialDir();
17 dir.Append("/hsimple.C");
18 dir.ReplaceAll("/./","/");
19 if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
20 TFile *file = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
21 if (!file) return;
22 TTree *ntuple = (TTree*)file->Get("ntuple");
23
24 TCanvas *c1 = new TCanvas("c1","Contours",10,10,800,600);
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}
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
#define gInterpreter
#define gROOT
Definition TROOT.h:406
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
The Canvas class.
Definition TCanvas.h:23
Graphical cut class.
Definition TCutG.h:20
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
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:1841
Double_t * GetY() const
Definition TGraph.h:140
Int_t GetN() const
Definition TGraph.h:132
Double_t * GetX() const
Definition TGraph.h:139
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition TGraph.cxx:831
A doubly linked list.
Definition TList.h:38
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:657
An array of TObjects.
Definition TObjArray.h:31
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
TObject * FindObject(const char *name) const override
Find an object in this collection using its name.
A PolyMarker is defined by an array on N points in a 2-D space.
Definition TPolyMarker.h:31
void Draw(Option_t *option="") override
Draw.
virtual void SetPoint(Int_t point, Double_t x, Double_t y)
Set point number n.
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:559
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
TString & Append(const char *cs)
Definition TString.h:572
A TTree represents a columnar dataset.
Definition TTree.h:79
void Draw(Option_t *opt) override
Default Draw method for all objects.
Definition TTree.h:431
Double_t y[n]
Definition legend1.C:17
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
return c2
Definition legend2.C:14