Logo ROOT  
Reference Guide
FirstContour.C File Reference

Detailed Description

View in nbviewer Open in SWAN Make a contour plot and get the first contour in a TPolyMarker. This macro generates a color contour plot by selecting entries from an ntuple file. The TGraph object corresponding to the first contour line is accessed and displayed into a separate canvas.

void FirstContour()
{
TString dir = gROOT->GetTutorialDir();
dir.Append("/hsimple.C");
dir.ReplaceAll("/./","/");
if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
TFile *file = (TFile*)gROOT->ProcessLineFast("hsimple(1)");
if (!file) return;
TTree *ntuple = (TTree*)file->Get("ntuple");
TCanvas *c1 = new TCanvas("c1","Contours",10,10,800,600);
ntuple->Draw("py:px","px*px+py*py < 20", "contz,list");
//we must call Update to force the canvas to be painted. When
//painting the contour plot, the list of contours is generated
//and a reference to it added to the Root list of special objects
c1->Update();
TCanvas *c2 = new TCanvas("c2","First contour",100,100,800,600);
TObjArray *contours =
(TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
if (!contours) return;
TList *lcontour1 = (TList*)contours->At(0);
if (!lcontour1) return;
TGraph *gc1 = (TGraph*)lcontour1->First();
if (!gc1) return;
if (gc1->GetN() < 10) return;
gc1->SetMarkerStyle(21);
gc1->Draw("alp");
//We make a TCutG object with the array obtained from this graph
TCutG *cutg = new TCutG("cutg",gc1->GetN(),gc1->GetX(),gc1->GetY());
//We create a polymarker object with npmax points.
const Int_t npmax = 50000;
TPolyMarker *pm = new TPolyMarker(npmax);
Int_t np = 0;
while(1) {
Double_t x = -4 +8*gRandom->Rndm();
Double_t y = -4 +8*gRandom->Rndm();
if (cutg->IsInside(x,y)) {
pm->SetPoint(np,x,y);
np++;
if (np == npmax) break;
}
}
pm->Draw();
}
Author
Rene Brun

Definition in file FirstContour.C.

TGraph::IsInside
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:1894
TGraph::Draw
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:760
TObjArray
Definition: TObjArray.h:37
TString::Data
const char * Data() const
Definition: TString.h:369
TTree
Definition: TTree.h:79
gInterpreter
#define gInterpreter
Definition: TInterpreter.h:558
Int_t
int Int_t
Definition: RtypesCore.h:45
x
Double_t x[n]
Definition: legend1.C:17
TObjArray::At
TObject * At(Int_t idx) const
Definition: TObjArray.h:166
TString
Definition: TString.h:136
TString::ReplaceAll
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:692
TList::First
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:658
TGraph::GetX
Double_t * GetX() const
Definition: TGraph.h:130
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
gRandom
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
TTree::Draw
virtual void Draw(Option_t *opt)
Default Draw method for all objects.
Definition: TTree.h:427
TRandom::Rndm
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:541
y
Double_t y[n]
Definition: legend1.C:17
TGraph::GetY
Double_t * GetY() const
Definition: TGraph.h:131
TFile
Definition: TFile.h:54
Double_t
double Double_t
Definition: RtypesCore.h:59
TGraph
Definition: TGraph.h:41
TCanvas
Definition: TCanvas.h:23
file
Definition: file.py:1
TPolyMarker
Definition: TPolyMarker.h:31
TGraph::GetN
Int_t GetN() const
Definition: TGraph.h:123
TPolyMarker::SetPoint
virtual void SetPoint(Int_t point, Double_t x, Double_t y)
Set point number n.
Definition: TPolyMarker.cxx:351
TCutG
Definition: TCutG.h:20
c2
return c2
Definition: legend2.C:14
TPolyMarker::Draw
virtual void Draw(Option_t *option="")
Draw.
Definition: TPolyMarker.cxx:199
TList
Definition: TList.h:44
gROOT
#define gROOT
Definition: TROOT.h:406
c1
return c1
Definition: legend1.C:41