Graphical selection of regions in a TH1

Hi rooters,

I’m now writing a GUI application within the root framework, and I’d like to do the follwoing:

  1. Select a few regions in a displayed TH1 (by pointing boudaries using a mouse),
  2. Show the selected regions for example by bounding each region by two vertical bars, by hatching/shading etc.,
    2.1 (optional) expanding/shrinking regions by mouse drag etc., and
  3. Get the bin numbers of the boundaries.

Are there any good and efficient ways (and their examples) of doing the above?

Thanks in advance.

Yours,
Kazuyoshi

see example below

{ TH1F *h1 = new TH1F("h1","test",100,-4,4); h1->FillRandom("gaus",10000); TH1 *h2 = (TH1F*)h1->Clone("h2"); h2->GetXaxis()->SetRange(45,56); h2->SetFillColor(kRed); h1->Draw(); h2->Draw("same"); }

Rene

Thanks for your immediate followup, Rene.

[quote=“brun”]see example below

{ TH1F *h1 = new TH1F("h1","test",100,-4,4); h1->FillRandom("gaus",10000); TH1 *h2 = (TH1F*)h1->Clone("h2"); h2->GetXaxis()->SetRange(45,56); h2->SetFillColor(kRed); h1->Draw(); h2->Draw("same"); }
[/quote]

How do I get bin numbers of the boundaries (and change them afterwords) GRAPHICALLY? (to get the bin numbers 45 and 56 by using a mouse pointer in the example above).

I think I can follow the procedure represented in the example $ROOTSYS/tutorials/hist/DynamicSlice.C (at least to get bin numbers of the specified boundaries)…

Kazuyoshi

Try the following (click left button to select the start bin and release it at the last bin). Use the non TFrame area and the non TAxis area

Rene

[code]TCanvas *c1;
TH1F *h2;
int pxold = -1;
void showRange() {
c1 = new TCanvas(“c1”);
TH1F h1 = new TH1F(“h1”,“test”,100,-4,4);
h1->FillRandom(“gaus”,10000);
h2 = (TH1F
)h1->Clone(“h2”);
//h2->GetXaxis()->SetRange(45,56);
h2->SetFillColor(kRed);
h1->Draw();
h2->Draw(“same”);

//Add a TExec object to the canvas
c1->AddExec(“dynamic”,“DynamicExec()”);
}

void DynamicExec()
{
//c1->GetCanvas()->FeedbackMode(kFALSE);
int px = c1->GetEventX();
int py = c1->GetEventY();
int event = c1->GetEvent();
if (event == 1) {pxold = px; return;}
if (event == 11) {pxold = -1; return;}
if (pxold == -1) return;
Double_t xmin = c1->AbsPixeltoX(pxold);
Double_t xmax = c1->AbsPixeltoX(px);
h2->GetXaxis()->SetRangeUser(xmin,xmax);
//printf(“event=%4d, px=%5d, pxold=%5d, xmin=%g, xmax=%g\n”,event,px,pxold,xmin,xmax);
c1->Modified();
c1->Update();
}

[/code]

[quote=“brun”]Try the following (click left button to select the start bin and release it at the last bin). Use the non TFrame area and the non TAxis area

Rene
[/quote]

Thanks, Rene.

Yours,
Kazuyoshi