TTree::Draw() with option "SAME"

Hello,

In a macro (in a function called plot_PxSeps) I try:


fov_canvas->Clear();
starGraphs->Draw(“A”); //starGraphs is a TMultiGraph*
TH1F *star_axes = starGraphs->GetHistogram();
star_axes->SetXTitle(“RA (deg)”);
star_axes->SetYTitle(“Dec (deg)”);
starGraphs->Draw(“SAME”);

fov_canvas->Update();

char var[100];
sprintf(var,“PxDEC[%d]:PxRA[%d]:pedVars[%d]”, channel, channel, channel);
tPedStars->Draw(var,"",“COL SAME”); //tPedStars is a TTree*

I get:


*** Break *** bus error
Root > Function plot_PxSeps() busy flag cleared


The last Draw() works without the “SAME” option but that’s not quite what I wanted.

I’m using ROOT 5.12/00e on MacOS X 10.4.9

Any suggestions?

Thanks,

Michael

A plot with option COL over a multigraph will hide the multigraph … but why not … Any way it should not produce a bus error. Can you send a small running example repdroducing the problem ?

Hi,

So I understand now that the “COL” option generates a TH2 object (not a TGraph) thus the empty space are actually white bins and the “SAME” option would be futile anyway.

I have tried drawing from the TTree with the “COL” option and then setting the axes ranges to match the TMultiGraph and drawing the TMultiGraph on top. However, the axes ranges are not updated and the TMultiGraph doesn’t appear unless I use the “A” option (in which case the TTree plot is lost). Am I using SetAxisRange correctly?


fov_canvas->cd();

starGraphs->Draw(“A”); // starGraphs is a TMultiGraph
double fovXmin = starGraphs->GetXaxis()->GetXmin();
double fovXmax = starGraphs->GetXaxis()->GetXmax();
double fovYmin = starGraphs->GetYaxis()->GetXmin();
double fovYmax = starGraphs->GetYaxis()->GetXmax();

cout<<fovXmin<<" “<<fovXmax<<” “<<fovYmin<<” "<<fovYmax<<endl;

fov_canvas->Clear();

char var[100];
sprintf(var,“PxDEC[%d]:PxRA[%d]:pedVars[%d]”, channel, channel, channel);
tPedStars->Draw(var,"",“COL”);

TH2 pxPath = (TH2)gPad->GetPrimitive(“htemp”);
pxPath->SetAxisRange(fovXmin, fovXmax);
pxPath->SetAxisRange(fovYmin, fovYmax, “Y”);
pxPath->SetXTitle(“RA (deg)”);
pxPath->SetYTitle(“Dec (deg)”);
pxPath->SetTitle(“Stars in Field of View”);

pxPath->Draw();
fov_canvas->Update();

starGraphs->Draw("*");
fov_canvas->Update();

Regards,

Michael

P.S.

The following macro regenerates the bus error for me when the “SAME” option is used but not otherwise.

void drawSAME()
{
TTree *t = new TTree(“Tthree”,“three variables”);

Double_t x, y, z;
Double_t xmin=0;
Double_t xmax=0;

t->Branch(“X”,&x,“X/D”);
t->Branch(“Y”,&y,“Y/D”);
t->Branch(“Z”,&z,“Z/D”);

for (int i=0; i<1000; i++)
{
gRandom->Rannor(x,y);
z = x + y;
t->Fill();

  if (x<xmin) xmin=x;
  if (x>xmax) xmax=x;
}

TCanvas *c = new TCanvas(“c”,“see”);

TF1 *diag = new TF1(“diag”, “x”, xmin, xmax);
TGraph *diaGraph = new TGraph(diag);

t->Draw(“X:Y:Z”, “”, “COL SAME”);

diaGraph->Draw(“L”);

}

I should add that the same problem appears on ROOT version v5-15-08. However on my platform it results in a seg fault rather than a bus error.
Cheers

Attached you’ll find a working version of the macro drawSame.
drawSAME.C (561 Bytes)