Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hlquantiles.C File Reference

Detailed Description

Demo for quantiles (with highlight mode)

TList *lq = 0;
TGraph *gr = 0;
void hlquantiles() {
const Int_t nq = 100;
const Int_t nshots = 10;
Double_t xq[nq]; // position where to compute the quantiles in [0,1]
Double_t yq[nq]; // array to contain the quantiles
for (Int_t i=0;i<nq;i++) xq[i] = Float_t(i+1)/nq;
TGraph *gr70 = new TGraph(nshots);
TGraph *gr90 = new TGraph(nshots);
TGraph *gr98 = new TGraph(nshots);
TGraph *grq[nq];
for (Int_t ig = 0; ig < nq; ig++) grq[ig] = new TGraph(nshots);
TH1F *h = new TH1F("h","demo quantiles",50,-3,3);
for (Int_t shot=0;shot<nshots;shot++) {
h->FillRandom("gaus",50);
h->GetQuantiles(nq,yq,xq);
gr70->SetPoint(shot,shot+1,yq[70]);
gr90->SetPoint(shot,shot+1,yq[90]);
gr98->SetPoint(shot,shot+1,yq[98]);
for (Int_t ig = 0; ig < nq; ig++)
grq[ig]->SetPoint(shot,shot+1,yq[ig]);
}
//show the original histogram in the top pad
TCanvas *c1 = new TCanvas("c1","demo quantiles",10,10,600,900);
c1->SetFillColor(41);
c1->Divide(1,3);
c1->cd(1);
h->SetFillColor(38);
h->Draw();
// show the final quantiles in the middle pad
c1->cd(2);
gPad->SetFrameFillColor(33);
gPad->SetGrid();
gr = new TGraph(nq,xq,yq);
gr->SetTitle("final quantiles");
gr->Draw("ap");
// prepare quantiles
lq = new TList();
for (Int_t ig = 0; ig < nq; ig++) {
grq[ig]->SetMinimum(gr->GetYaxis()->GetXmin());
grq[ig]->SetMaximum(gr->GetYaxis()->GetXmax());
grq[ig]->SetMarkerStyle(23);
grq[ig]->SetMarkerColor(ig%100);
grq[ig]->SetTitle(TString::Format("q%02d", ig));
lq->Add(grq[ig]);
}
TText *info = new TText(0.1, 2.4, "please move the mouse over the graph");
info->SetTextSize(0.08);
info->Draw();
c1->HighlightConnect("HighlightQuantile(TVirtualPad*,TObject*,Int_t,Int_t)");
// show the evolution of some quantiles in the bottom pad
c1->cd(3);
gPad->SetFrameFillColor(17);
gPad->DrawFrame(0,0,nshots+1,3.2);
gPad->SetGrid();
gr98->SetMarkerStyle(22);
gr98->Draw("lp");
gr90->SetMarkerStyle(21);
gr90->Draw("lp");
gr70->SetMarkerStyle(20);
gr70->Draw("lp");
// add a legend
TLegend *legend = new TLegend(0.85,0.74,0.95,0.95);
legend->SetTextFont(72);
legend->SetTextSize(0.05);
legend->AddEntry(gr98," q98","lp");
legend->AddEntry(gr90," q90","lp");
legend->AddEntry(gr70," q70","lp");
legend->Draw();
}
void HighlightQuantile(TVirtualPad *pad, TObject *obj, Int_t ihp, Int_t y)
{
// show the evolution of all quantiles in the bottom pad
if (obj != gr) return;
if (ihp == -1) return;
TVirtualPad *savepad = gPad;
pad->GetCanvas()->cd(3);
lq->At(ihp)->Draw("alp");
gPad->Update();
savepad->cd();
}
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
float Float_t
Definition RtypesCore.h:57
@ kRed
Definition Rtypes.h:66
@ kMagenta
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
int * lq
@ kCannotPick
Definition TObject.h:359
#define gPad
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition TAttMarker.h:31
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:41
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:43
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:45
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:46
Double_t GetXmax() const
Definition TAxis.h:134
Double_t GetXmin() const
Definition TAxis.h:133
The Canvas class.
Definition TCanvas.h:23
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
Definition TCanvas.cxx:708
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition TGraph.cxx:2284
virtual void SetMaximum(Double_t maximum=-1111)
Set the maximum of the graph.
Definition TGraph.cxx:2266
virtual void SetTitle(const char *title="")
Change (i.e.
Definition TGraph.cxx:2339
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition TGraph.cxx:769
virtual void SetHighlight(Bool_t set=kTRUE)
Set highlight (enable/disble) mode for the graph by default highlight mode is disable.
Definition TGraph.cxx:2253
TAxis * GetYaxis() const
Get y axis of the graph.
Definition TGraph.cxx:1650
virtual void SetMinimum(Double_t minimum=-1111)
Set the minimum of the graph.
Definition TGraph.cxx:2275
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:575
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Definition TLegend.cxx:330
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Definition TLegend.cxx:423
A doubly linked list.
Definition TList.h:44
Mother of all ROOT objects.
Definition TObject.h:37
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:696
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:197
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2331
Base class for several text objects.
Definition TText.h:22
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
virtual TCanvas * GetCanvas() const =0
return c1
Definition legend1.C:41
Double_t y[n]
Definition legend1.C:17
TGraphErrors * gr
Definition legend1.C:25
Authors
Rene Brun, Eddy Offermann, Jan Musinsky

Definition in file hlquantiles.C.