Generated macro changes the palette

Hi,

At the beginning of the program, I have defined some style.

  TStyle *style1 = new TStyle("Plain", "style1");
  style1->SetPalette(1);
  style1->SetOptStat(0);
  style1->cd();

In the middle, the program defines some TF1 objects.

  TF1 *f_Log1 = new TF1("f_Log1", Log1, 0, 5, 4);
  TF1 *f_Log2 = new TF1("f_Log2", Log1, 0, 5, 4);

  f_Log1->SetParameters(43, 5, 1, 0.59);
  f_Log1->SetLineWidth(2);
  
  f_Log2->SetParameters(40, 5, 1, 0.65);
  f_Log2->SetLineWidth(2);

At the end when I draw a TH2D histogram with the functions,
looks everything fine.

 h_Th_P_pos[2]->Draw("col");
f_Log1->Draw("Same");
f_Log2->Draw("Same");

I saved this canvas by two ways

  c2->Print("e1-6_Th_Pprot.eps");
  c2->Print("e1-6_Th_Pprot.C");

When I open eps file the image is fine,
but when I run the .C file, I see that the color palette
has been changed, and each time I manually add line

gStyle->SetPalette(1);

in a .C macro. It also gives the following errors

In the .C file it defines TF1 without any function or formula,

   TF1 *f_Log1 = new TF1("f_Log1","",0,5);
   f_Log1->SetFillColor(19);
   f_Log1->SetFillStyle(0);
   f_Log1->SetLineWidth(2);
   f_Log1->SetParameter(0,43);
   f_Log1->SetParError(0,0);
   f_Log1->SetParLimits(0,0,0);
   f_Log1->SetParameter(1,5);
   f_Log1->SetParError(1,0);
   f_Log1->SetParLimits(1,0,0);
   f_Log1->SetParameter(2,1);
   f_Log1->SetParError(2,0);
   f_Log1->SetParLimits(2,0,0);
   f_Log1->SetParameter(3,0.59);
   f_Log1->SetParError(3,0);
   f_Log1->SetParLimits(3,0,0);
   f_Log1->Draw("Same");

I guess therefore function can’t be drawn.

Is there any option which will keep
colour palette and TF1 objects unchanged.

Put it in your rootlogon.C file

I attached the .C and the original .eps file
attachment.tar.gz (75.9 KB)

Yes I understand what you meant.
gStyle->SetPalette(1);
Is not saved in the macro.
I suggested that you put this command in you file rootlogon.C to avoid to modify your macro.

[quote=“couet”]Yes I understand what you meant.
gStyle->SetPalette(1);
Is not saved in the macro.
I suggested that you put this command in you file rootlogon.C to avoid to modify your macro.[/quote]

Hi couet,
Sorry, I dindn’t know what is rootlogon.C, and didn’t understund
what you exactly meant.

Now I made a rootlogon.C file for me, and added that line in it, it
works good.

The issue with functions I didn’t solve yet
(each time I manually define TF1 with formula without parameters in the code).
Do you have any idea?

Your functions are not defined you do:

   TF1 *f_Log1 = new TF1("f_Log1","",0,5);
   TF1 *f_Log2 = new TF1("f_Log2","",0,5);

See how to use TH1 here:
root.cern.ch/root/html/TF1.html

[quote=“couet”]Your functions are not defined you do:

   TF1 *f_Log1 = new TF1("f_Log1","",0,5);
   TF1 *f_Log2 = new TF1("f_Log2","",0,5);

See how to use TH1 here:
root.cern.ch/root/html/TF1.html[/quote]

Hi couet.,

Sorry, if I didn’t understand something clearly, but
In my program TF1 s are defined with functions,
and I set parameters to them.

  TF1 *f_Log1 = new TF1("f_Log1", Log1, 0, 5, 4);
  TF1 *f_Log2 = new TF1("f_Log2", Log1, 0, 5, 4);
  f_Log1->SetParameters(43, 5, 1, 0.59);
  f_Log2->SetParameters(40, 5, 1, 0.65);

TF1 objects without functions are in the generated .C file, not in my program.

   TF1 *f_Log1 = new TF1("f_Log1","",0,5);
   TF1 *f_Log2 = new TF1("f_Log2","",0,5);

My problem is that, in a generated macro the functions are disappear,
it defines TF1 without functions.
If the answer of my question is contained in your previous post,
please excuse me, and specify which line I have to read
in a TF1 Ref. guide.

I have tried myself with the latest root version to save in a .C file a TF1 defined by a user function and it is working for me. See in attachment the original file xx.c and the saved version c1.C
c1.C (5.62 KB)
xx.C (961 Bytes)

Hi couet,

I use root 5.20/00, and generated macro with your
program plots the function.
I found that if I run program with interpreter, then
the generated .C macro draws functions,
but the same program when I run compiled macro (root program.cc+), then
generated .C macro doesn’t draw functions.

You can try attached mytest.C
by interpreter and by compiling, and see
whether in both cases the generated macro draws functions or
not.
mytest.C (574 Bytes)

You are right we will investigate.

Hi,

we now know why (it’s a bug in TF1). Rene will fix it and let you know.

Cheers, Axel.

Hi,

Thanks a lot… :smiley:

This problem is now fixed in the trunk.

Rene