Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist056_TPolyMarker_contour.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/// \date January 2017
13/// \author Rene Brun
14
16{
17 TString dir = gROOT->GetTutorialDir();
18 dir.Append("/hsimple.C");
19 dir.ReplaceAll("/./", "/");
20 if (!gInterpreter->IsLoaded(dir.Data()))
21 gInterpreter->LoadMacro(dir.Data());
22 TFile *file = (TFile *)gROOT->ProcessLineFast("hsimple(1)");
23 if (!file)
24 return;
25 TTree *ntuple = (TTree *)file->Get("ntuple");
26
27 TCanvas *c1 = new TCanvas("c1", "Contours", 10, 10, 800, 600);
28 ntuple->Draw("py:px", "px*px+py*py < 20", "contz,list");
29
30 // we must call Update to force the canvas to be painted. When
31 // painting the contour plot, the list of contours is generated
32 // and a reference to it added to the Root list of special objects
33 c1->Update();
34
35 TCanvas *c2 = new TCanvas("c2", "First contour", 100, 100, 800, 600);
36
37 TObjArray *contours = (TObjArray *)gROOT->GetListOfSpecials()->FindObject("contours");
38 if (!contours)
39 return;
40 TList *lcontour1 = (TList *)contours->At(0);
41 if (!lcontour1)
42 return;
43 TGraph *gc1 = (TGraph *)lcontour1->First();
44 if (!gc1)
45 return;
46 if (gc1->GetN() < 10)
47 return;
48 gc1->SetMarkerStyle(21);
49 gc1->Draw("alp");
50
51 // We make a TCutG object with the array obtained from this graph
52 TCutG *cutg = new TCutG("cutg", gc1->GetN(), gc1->GetX(), gc1->GetY());
53
54 // We create a polymarker object with npmax points.
55 const Int_t npmax = 50000;
57 Int_t np = 0;
58 while (1) {
59 Double_t x = -4 + 8 * gRandom->Rndm();
60 Double_t y = -4 + 8 * gRandom->Rndm();
61 if (cutg->IsInside(x, y)) {
62 pm->SetPoint(np, x, y);
63 np++;
64 if (np == npmax)
65 break;
66 }
67 }
68 pm->Draw();
69}
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
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:131
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
A doubly linked list.
Definition TList.h:38
An array of TObjects.
Definition TObjArray.h:31
A PolyMarker is defined by an array on N points in a 2-D space.
Definition TPolyMarker.h:31
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
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