TH2D:Update doesn't seem to work when data is ADOPTED

Hi,

in 2D mode, I can not display data ADOPTED by a histogram programmatically, but I can display the data manually by first enabling the “Can Edit Histograms” menu option, and then click the left mouse button.
If In 3D mode (lego), data is displayed programmatically. The issue is only in 2D mode.

Essential steps in the program are:

TArrayD data is Adopted by histogram
Histogram is Drawn()
TCanvas is Modified()
TCanvas is Updated()

I even tried TH2D::SetOption(“kCanRebin”) and TH2D::Paint(), but has no effect.

I know the bins got the data; Status bar shows the values as I move the mouse; I can see the data if the histogram is displayed 3D mode (lego).

It is just that I can not see it even with after envoking the TCanvas::Update() function in 2D mode.

Once I have enabled the “Can Edit Histogram” menu option and left-click the mouse, both the Stats box and data are shown.

Is there some other essential function calls needed that I have missed before data is displayed when data is ADOPTED?

Another strange behavior is that, as soon as one histogram has been drawn properly on one canvas, subquently DRAW on a different canvas will immediately display the data (without clicking the left buton on the mouse), even if “can edit histogram” is NOT enabled.

So, it is a mystery why having one properly drawn histogram will permit proper subsequent draws.

What ROOT environment variable(s) could have been changed having drawn one histogram?

How can one programatically enable the “can edit histograms” menu option? SetOption(“kCanRebin”) ?

Thanks for your suggestions.

sVi-Hoa

Could you post the shortest possible running script featuring your problem?

Rene

Thanks Rene. The test codes (TestAdopt.m attached) are given below:

[code]TestAdopt()
{

TFile *f=new TFile(“test.root”,“RECREATE”);

Int_t arraySize=162*162;
TRandom3 *r=new TRandom3;
Double_t *arrayD;
arrayD=new Double_t[arraySize];

r->RndmArray(arraySize,arrayD);

TCanvas *c2=new TCanvas(“c2”,“c2”,10,10, 600,600);
TH2D *h2=new TH2D(“test”,“test1”,160,1,160,160,1,160);
h2->SetOption(“kCanRebin”);
h2->Adopt(arraySize,arrayD);
h2->Draw(“COL”);
c2->Modified();
c2->Update();
}

// At this point one can not see the 2D histogram; Stats box shows zero for values.
// Can see data if histogram is set to 3D mode (using the menu editor).
// To see data in 2D mode, one has to first enable the “Can Edit Histograms” Menu option; then position cursor inisde the histogram drawing area,
// and click left button on mouse. Histogram is displayed with number of enrties equal to zero; each mouse click increases the entries by 1.
// Once the 2D histogram has been drawn, I find and draw the histogram in the current directory using:

// TH2D h3=(TH2D)gDirectory->FindObject(“test”);
// TCanvas *c3=new TCanvas(“c3”,“c3”,10,10, 600,600);
// h3->Draw(“col”);

// note also, once the first canvas has “Can Edit Histogram” enabled, subsequent instances of canvas also had that option enabled,
// until you exit ROOT and re-enter it again.[/code]

I am not surprised that your script does not work. Although the TH1::fArray member is public for people who want to have fast access to the bin contents, you are not supposed to call the Adopt function in this context because the histogram object is not informed of this case.

Rene

Thanks Rene for your explanation.

I was looking for an alternative way to assign a histogram a buffer load of data rather than one by one in the usual way with the fill() method, like that of a TASImage::SetImage().

I just spotted another function histogram method:

void Set(Int_t n, const Double_t* array)

But it is using a const Double* array. This is where my undertsanding of C-pointer get fuzzy.

How can I use the example I have to use the set method()?

There

Vi-Hoa

use TH1::SetContent, but note that this function is copying the data too. We do not support the Adopt case in TH1.

Rene

Thanks Rene,

SetContent(0 works fine for me. This one does not even need the array size to be given!!
I had the impression the function had to be given the array size. Otherwise, how does it know how many to copy? Based on the x and y bin-range in Histogram declaration?

Vi-Hoa

yes

Rene