Graphical cut definition?

Hi,

I would like to be able to define a graphical cut on a histogram drawn in an embedded canvas, which is part of a GUI I’m writing.

On a standard canvas, this is done by clicking the ‘Graphical Cut’ button on the toolbar. Is there a way to access this same tool from a menu or with a button in my own GUI ? In other words, what function in what class/object should I call in order to start the graphical cut definition tool ?

I’ve been going through the code for TCanvas, TRootCanvas and TGToolbar to get some ideas, but I’m a bit lost here …

Cheers,

Jan

Hi Jan,

There is no way to show up the canvas tool bar when using an embedded canvas for that moment. I will include your request in our todo list and we will provide this feature.

Cheers, Ilka

Hi Ilka,

Thanks for your quick reply and the kind offer. At the moment, however, I would be happy if I could just access the graphical cut tool, not the complete toolbar.

In the mean time I did some further digging in the old RootTalk archives and apparently

does the trick for CINT.

If I try to include this in a function or program, I run into the same problem as mentioned in http://root.cern.ch/root/roottalk/roottalk00/0477.html, being that the program moves on before I finish defining the cut. So, I tried the sollution suggested by Rene in his reply to the original question and came up with this function :

TCutG * GetTCutG (char * name)
{
  TCutG * cutg = (TCutG *) gPad->WaitPrimitive("CUTG","CutG");
    
  if (cutg==NULL)
    return cutg;
  else
    return new TCutG(name,cutg->GetN(),cutg->GetX(),cutg->GetY());
}

However, if I try to test this function, things go wrong after I define the second point of the cut :

{
  TH2D fHist("Hist","Hist",100,0,100,100,0,100);
  fHist.Draw();

  TCutG * fCut = GetTCutG("fCut");
}

Any suggestions on what I’m doing wrong and how to fix this, would be welcome !

Jan

Hi Jan,

I need some time to investigate how the graphical cut works and will try to provide an example.

According to the information given at:
root.cern.ch/root/roottalk/roottalk00/0507.html
you should change “CUTG” to something else (“myCUTG” for example).

Cheers, Ilka

Hi Jan,

Please find an example in the attached macro. I tried to create it as simple as possible. You have an embedded canvas, status bar and 3 buttons: Draw, CutG and Exit. The signals/slots communication mechanism is used in this example. To draw a histogram click the Draw button; to create a graphical cut - on the CutG button; Exit - will terminate it.

You have to set a name to the TCutG object any time you want to keep it. Use the context menu and SetName command for that. Otherwise, any new TCutG object will replace the old one because they have the same name CUTG.

In addition, you can see how to make available the status bar for an embedded canvas in case you need it.

Best regards, Ilka
embcutG.C (5.39 KB)

Hi Ilka,

Thank you for your very quick and effective reply. This comes very, very close to what I had in mind.

If you ever think of a way of avoiding or working around the renaming of the TCutG object, please let me now.

Again, thanks a lot.

Jan

Hi Jan,

I explained the way you can change the TCutG name and it works fine. There should be some reasons (not in my knowledge) which require the same name of any new TCutG object.

OK, in addition I found that the name is set this way in TCreatePrimitives::PolyLine method where the object is created.

Best regards, Ilka

[quote]There should be some reasons (not in my knowledge) which require the same name of any new TCutG object.[/quote]We use a default name so that the graphically created graphic cut can easily (and predicably) be recovered from the command line.

Cheers,
Philippe.

Hi Philippe,

Thanks for your clarification.

Cheers, Ilka