Drawing a single contour over a TGraph2D using cont4

Hello:

I have a TGraph2D that I want to draw using cont4z. However, I also want to draw a single specific contour over the top of the TGraph2D as a black line or something. I understand that cont4 imposes its own coordinate system on the pad, and so I have followed the advice given here…

root.cern.ch/root/roottalk/roottalk03/3144.html

…which has led to a complication. As you can see in the attached code, when I switch to the second, blank TPad, I have to draw a frame corresponding to that in the first TPad; otherwise, the single contour I want to emphasize is drawn over the whole range of the pad, and not the area of the pad that matches the cont4 pad. But when I use gPad->DrawFrame(), it somehow destroys the “blank” nature of the second TPad.

Any help would be greatly appreciated.

–James
histInvSm.C (4.04 KB)

I had to do ’ configure’ with rootfit enabled.
with that your macro gives me:

Processing histInvSm.C...

RooFit v3.14 -- Developed by Wouter Verkerke and David Kirkby
                Copyright (C) 2000-2010 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

Error: Non-static-const variable in array dimension histInvSm.C:71:
 (cint allows this only in interactive command and special form macro which
  is special extension. It is not allowed in source code. Please ignore
  subsequent errors.)
*** Interpreter error recovered ***

That’s a known CINT limitation (lines 95, 96, 97 in the original “histInvSm.C”). You have to use such macros “precompiled”, e.g. “.x histInvSm.C++”.

ok, when I execute your macro I get:

It produces the following plot. Is it what you get also ?

Yes, that’s what I get, too (ROOT 5.28/00b, Ubuntu 10.04.2 LTS, i686, gcc 4.4.3).
Replace:
TCanvas* tempCanv = new TCanvas("","",2); // is an empty “name” allowed at all?
with:
TCanvas* tempCanv = new TCanvas(“tempCanv”,“tempCanv”,2);
and you’ll get another canvas displayed.

Don’t draw the frame in the transparent pad but define the pad range as shown in the example transpad.C
root.cern.ch/root/html/tutorials … pad.C.html

I’m using 5.28/00a, MacOSX64 and, yes, I’m running the macro with .x histInSm.C+ .

I use that first tempCanv to draw the contours and “list” them, so I can extract the one I want and hopefully overlay it on the cont4 later, on the other canvas.

I get the attached, which is just the single contour line I want, but with a white background:


If you drag the white background off to the side, though, you can see the cont4 plot on the pad underneath:


I’ll look at the transpad.C example now.

Thanks for all the help so far.

Just for future references … an empty object’s “name” is not a good idea … see [url]Empty name of an object for an official statement.

Can you send me the macro which produces this plot ?
The one I have looks very different.
Thanks in advance.

Have you been able to solve this? I’ve run into the same problem with ROOT 5.28.00.

I’ve attached a minimally modified version of transpad.C where I draw a CONT4 Graph2D and try to overlay it with a TGraph. But the TGraph has a white background, like in your screenshots above, that covers the Graph2D below it.
transpad.C (1.75 KB)

No, I was waiting fro the macro I asked you.

void transpad() {
   TCanvas *c1 = new TCanvas("c1","transparent pad",200,10,700,500);
   TPad *pad1 = new TPad("pad1","",0,0,1,1);
   TPad *pad2 = new TPad("pad2","",0,0,1,1);
   pad2->SetFillStyle(0); //will be transparent
   pad2->SetFillColor(0);
   pad2->SetFrameFillStyle(0);
   
   pad1->Draw();
   pad1->cd();

   TGraph2D *h1 = new TGraph2D(1000);
   TGraph *h2 = new TGraph(1000);

   TRandom r;
   for (Int_t i=0;i<1000;i++) {
      Double_t x1 = r.Gaus(0,1.5);
      Double_t x2 = r.Gaus(0,1.5);
      Double_t x3 = r.Gaus(1,1.5);
      h1->SetPoint(i,x1,x2,x3);
      h2->SetPoint(i,x1,x2);
   }
   h1->Draw("CONT4Z");
   pad1->Update();
   
   pad1->Modified();
   c1->cd();
   
   //compute the pad range with suitable margins
   Double_t ymin = 0;
   Double_t ymax = 2000;
   Double_t dy = (ymax-ymin)/0.8; //10 per cent margins top and bottom
   Double_t xmin = -3;
   Double_t xmax = 3;
   Double_t dx = (xmax-xmin)/0.8; //10 per cent margins left and right
   pad2->Range(xmin-0.1*dx,ymin-0.1*dy,xmax+0.1*dx,ymax+0.1*dy);
   pad2->Draw();
   pad2->cd();

   h2->Draw("SAME A*");
   pad2->Update();
}

Thank you very much! That worked.

I do have one more question though. Is it possible to remove the axes from the TGraph? Right now, it draws them on top of the TGraph2D’s axis and it doesn’t look very nice as they overlap a bit. I tried removing the “A” option from the Draw function, which gets rid of the axes but collapses all of the points into one line, as shown in the attached image. I’ve also tried setting the ranges on the axis (when the A option was not used) as shown here: root.cern.ch/drupal/content/how-set-ranges-axis , but that didn’t help.


Before removing the axis I would make sure they overlap exactly.
If they do not overlap (at least the tick marks) it means that the two scales are different and therefore your plot is wrong.

Otherwise, you can make the label size = 0 for one of the plot to make the labels disappear.