Re: Named macro produces no plot

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Sun, 14 Jun 2009 13:13:05 +0200


Hi Roger,

named macros are proper C++, and as such they follow the scoping rules of C++. End of function means end of life for function-local variables - your TF2 is destructed at the end of the function. Simply create it on the heap instead using "new TF2".

Cheers, Axel.

On 2009-06-14 12:31, Roger Mason wrote:
> Hello,
>
> I'm trying to produce the plot of a plane. I can produce the plot from
> an unnamed macro but the named version displays an empty canvas. Here
> are the two macros:
>
> // This produces a plot
> {
> gSystem->Load("libGenVector");
>
> ROOT::Math::XYZPoint p1(500,500,200);
> ROOT::Math::XYZPoint p2(950,250,20);
> ROOT::Math::XYZPoint p3(750,50,20);
> ROOT::Math::Plane3D plane(p1,p2,p3);
>
> Double_t A = plane.A();
> Double_t B = plane.B();
> Double_t C = plane.C();
>
> Double_t a = A/-C;
> Double_t b = B/-C;
> Double_t c = C/-C;
>
> cout << " a = " << a
> << " b = " << b
> << " c = " << c
> << endl;
>
> // View the plane
> TF2 p = TF2("p","[0]*x + [1]*y",-10,10,-10,10);
> p.SetParameters(a,b);
> p.Draw();
>
> }
>
> // This produces an empty canvas
> #ifndef __CINT__
> #include "TMatrixD.h"
> #include "TVectorD.h"
> #include "TMath.h"
> #include "Math/Point3D.h"
> #include "Math/Vector3D.h"
> #include "Math/Vector4D.h"
> #include "Math/Rotation3D.h"
> #include "Math/EulerAngles.h"
> #include "Math/AxisAngle.h"
> #include "Math/Quaternion.h"
> #include "Math/RotationX.h"
> #include "Math/RotationY.h"
> #include "Math/RotationZ.h"
> #include "Math/RotationZYX.h"
> #include "Math/LorentzRotation.h"
> #include "Math/Boost.h"
> #include "Math/BoostX.h"
> #include "Math/BoostY.h"
> #include "Math/BoostZ.h"
> #include "Math/Transform3D.h"
> #include "Math/Plane3D.h"
> #include "Math/VectorUtil.h"
> #endif
>
> void plane2()
> {
> gSystem->Load("libGenVector");
>
> ROOT::Math::XYZPoint p1(500,500,200);
> ROOT::Math::XYZPoint p2(950,250,20);
> ROOT::Math::XYZPoint p3(750,50,20);
> ROOT::Math::Plane3D plane(p1,p2,p3);
>
> Double_t A = plane.A();
> Double_t B = plane.B();
> Double_t C = plane.C();
>
> Double_t a = A/-C;
> Double_t b = B/-C;
> Double_t c = C/-C;
>
> cout << " a = " << a
> << " b = " << b
> << " c = " << c
> << endl;
>
> // View the plane
> TF2 p = TF2("p","[0]*x + [1]*y",-10,10,-10,10);
> p.SetParameters(a,b);
> p.Draw();
>
> }
>
> I'm using ROOT 5.20/00 (trunk_at_24524, May 17 2009, 10:14:00 on linux).
> Can someone explain what I must do to get the named version to produce a
> plot?
>
> Thanks,
> Roger
>
>
Received on Sun Jun 14 2009 - 13:14:23 CEST

This archive was generated by hypermail 2.2.0 : Sun Jun 14 2009 - 17:50:01 CEST