Recording TCutG Data Error

Hello all,

I am having a problem with recording TCutG data for further use.

Background:
In my root session, I load a root file containing 2-D histograms. I draw a histogram and then use to draw several boxes on the histogram and then name them A, B, C, D, etc. Then, I run a piece of code that takes the number of points in the box and the points in their x and y coordinates and writes them to a file that I can use later on.

Problem:
Then I draw the second histogram and draw another, different set of boxes on it named A, B, C, D, etc. When I run the same piece of code that takes the boxes and records them, it doesn’t record the current boxes, but it remembers the first set from the first histogram drawn.

Solution?
If I quit my root session between each histogram and box drawing, this problem will not occur. But, this is not an optimal solution.

Question:
How can I erase the memory of the last set of TCutG boxes and record the current set correctly, without having to gROOT.Reset() or quit and restart my root session?

Many thanks to any replies of help,
Beth

Hi,

The problem ‘might’ be due to the way your retrieve the address of A, B, C and D. Maybe you rely on CINT’s automatic creation of variable (which would happen only once) instead of retrieving them explicitly from a list.

Or, if you already retrieve them explictly for a list, you would need to ‘clean’ the list in between each round of creation.

If this is not sufficient to resolve your problem, please send me the ‘piece of code that takes the number of points…’

Cheers,
Philippe.

Hi, Philippe,

Thank you for your response. Here is how I retrieve the data and put it into newfile:

  Double_t *X = A->GetX();
  Double_t *Y = A->GetY();
  newfile << "#A" << f->GetN() << endl;
  for (Int_t i = 0; i < A->GetN(); i++) newfile << X[i] << "  " << Y[i] << endl;

and likewise for B, C, D, etc.

Would you please tell me more about “cleaning” my list of box names?

The variable name automatically assigned is something like “Graph” or “TCutG” and is identical for the multiple boxes that are drawn. I use the names A, B, C… to delineate between them. Otherwise, I cannot record more than one box at a time.

Best regards,
Beth

Hi,

Unless you skipped an important part of your code in your snippets, you are relying on CINT to automatically create the proper variable. However CINT does not create the proper variable more than once (i.e it wont create something that already exist). Hence in your code ‘A’ always point to the cut your first accessed.

Instead you should do something like:

TCutG *mycutA; mycutA = (TCutG*)gROOT->GetListOfSpecials()->FindObject("A");
and once your done

without this, the next you call FindObject, it would still return the first A (the first one it finds in the list).

Cheers,
Philippe.

Philippe,

Thank you for your input. It worked exactly as you described. Problem fixed!

:smiley:

Sincerely,
Beth


Is there a function that returns whether or not the object A was found?

Thanks,
Beth

Is there a function that returns whether or not the object A was found?

Thanks,
Beth

[quote]Is there a function that returns whether or not the object A was found?
[/quote]

mycutA = (TCutG*)gROOT->GetListOfSpecials()->FindObject("A"); if (mycutA==0) { // we did not find it } if (mycutA->IsA()!=TCutG::Class()) { // this is not a TCutG }

Cheers,
Philippe

Hello!

My name is Balint and I would like to use a graphical cut in my program.More exactly:I have a 2D histogram on which I would like to make a graphical cut and then use the data of it to several things.Naturally I would like to make it with CINT,so I write my program in C++.
My problem is that I didn`t find any verbose manual or document of the TCutG class.
Would one of You send me an example how I can put the cutting to my source?
So, how can I do the thing that I cut a part of my TH2F with the mouse and then read only those bins that I chose with that graphical cut?

Thank You in advance,

Balint

Hi Beth,

Thank you for your answer.I have one more question.So if I make a graphical cut with my
mouse on my 2D histogram,will this algorithm know that I made a graphical cut with my mouse?If you understand my question.In other way:I have a 2D histogram drawn in a Canvas;I make a graphical cut with my mouse;is your source that you sent me enough to the Root to recognize my cut?I mean I have to run my program again,and the Root will recognize on each histogram object that is drawn that I made a graphical cut.Am I right or I am totally wrong?

Sorry for being so stupid but I am an undergraduate student in phyisics and I am studying Root on my own.

Thank you again,

Balint

Balint,

I am also a newbie root user; there are many people on this forum that might answer your questions better, but I’ll give it a shot.

[quote]So if I make a graphical cut with my
mouse on my 2D histogram,will this algorithm know that I made a graphical cut with my mouse?[/quote]

I understand that when you right click over the graphical cut that you made and then SetName to whatever you’d like and then put that name into the code I gave you, it will find and recognize the cuts.

 cut_h = (TCutG*)gROOT->GetListOfSpecials()->FindObject("h");

This code looks for the graphical cut (or polyline, etc) that you have SetName(ed) to “h”.

I understand that so long as you have named the object by the name your code is looking for, it will recognize it.

Sincerely,
Beth

Beth,

Thank You for Your help!Now it works!

Cheers,

Balint