Invoking TCutG toolbar button from the command line

Hello all, first of I apologize for the awkward name of this post, if anyone has any better ideas please let me know.

I have several hundred runs of data, each of those runs needs several different graphical cuts. I takes me about 5 minutes per run to load the root file, generate the plots, create the TCutGs with the toolbar button on the canvas, name the TCutGs, save the TCutGs’ data into an appropriate format. The idea being that in the future I can use a macro to load the run and the various cuts for that run simultaneously.

To try and speed this process up I have been writing a script, this script needs to loop across the run numbers calculate the file names, load the files, create and display the histograms, then get the cut for that histogram from the mouse clicks like the toolbar button does, then save the cut and move on to the next histogram / run.

The idea being that the user executes the script, it displays a histogram they draw the cut, it displays the next histogram, so on and so forth.
I can fairly easily accomplish everything except getting the cut. I have an idea on how to go about that but I do not know how to make it work.

Idea: Fake the system into thinking that the button was pressed and wait until the TCutG editing function returns. There are two problems with this idea: First, I am uncertain how to make the system think the user pushed a button. Second, I am not sure how to make the script wait for the editor to return.

If anyone can give me some advice on ways to accomplish this, either by showing me how to make my idea work or by some alternative method I would be very grateful.

Cheers,
James

A very simple way would be to do in your macro canvas->ToggleToolBar();
then the user will on have to click on the cut button before entering the cut.
that extra click is too much already ?

Thanks for the quick reply.

That is quite simple, and the extra button click is no problem.

But how would I make the script wait for the user to finish all the clicking so that the script can then retrieve the newly created TCutG object?

Cheers,
James

Ah yes good point … I need to check

I had hoped that by simulating the button click the canvas would enter some sort of uninterruptable mode but digging through the source code has made me start to think otherwise. My original goal was to see where the functionality was implemented and try to replicate that in the script. I hunted my way down through the TRootCanvas object and the ShowToolBar procedure and the process message procedure and while I never found the base part that handled the clicks it appears that it is not some uninterruptable mode but rather it just telling the canvas a different way to interpret the user’s clicks.

I suppose a better name for this thread would be, how to make a script pause for certain GUI events?

Cheers,
James

I think the following macro could be what you are looking for:

void twocuts() {
   TFile *f = new TFile("hsimple.root","READ");
   TH2 *h;
   h = (TH2*)f->Get("hpxpy");
   TCanvas *c1 = new TCanvas("c1","c1",10,10,700,500);
   h ->Draw();
   cout << "The first cut..." <<endl;
   cut1=(TCutG*)gPad->WaitPrimitive("CUTG","CutG");
   cut1->SetName("cut1");
   cout << "The second cut..."<< endl;;
   cut2=(TCutG*)gPad->WaitPrimitive("CUTG","CutG");
   cut2->SetName("cut2");
   TCanvas *c2 = new TCanvas("c2","c2",10,500,700,500);
   c2->Divide(1,3);
   c2->Update();
   h->ProjectionX("a",-1,-1,"[cut1]");
   h->ProjectionX("b",-1,-1,"[cut2]");
   h->ProjectionX("c",-1,-1,"[cut1,cut2]");
   c2->cd(1);
   a->Draw();
   c2->cd(2);
   b->Draw();
   c2->cd(3);
   c->Draw();
}

Thank you very much.

That makes my life much simpler, and now I know about the wait primitive function in the future. I will have to read more about that command in the future.

Earlier I had started to have inklings of sleeping for half a second and checking to see if the editor was still in CutG mode, if it was then go back to sleep, etc. But this is much more elegant and easy to read.

Thank you again.

Cheers,
James