Home | News | Documentation | Download

Draw TF1 from saved macro

_ROOT Version: 6.18.02
_Platform: Linux
_Compiler: gcc 5.3.0


I have a macro saved from a plot using TCanvas::SaveAs(“file.C”) (well, really c1->SaveAs(“file.C”) ). When the macro is run it draws the histograms OK and one of the TF1’s, but 3 other TF1’s don’t draw correctly. Looking in the macro, it looks like the 3 that don’t draw correctly have a bunch of calls to TF1::SetSavedPoint(). It turns out that the the one TF1 that draws correctly was made from a “gaus+pol3” while the ones that don’t draw correctly were all made using a functor that is not available in the saved macro.

It seems since the points are saved in the macro and written back into the TF1 using SetSavedPoint, I should be able to have it draw the curve. Is there some trick to getting a TF1 to draw what it has saved in fSave?

The part of the macro is below in case that helps. (full macro exceeds size limit for post).

void online_monitoring_PID()
{
//=========Macro generated from canvas: PID/PID
//=========  (Sat Jan 25 10:28:57 2020) by ROOT version 6.18/02
   TCanvas *PID = new TCanvas("PID", "PID",720,23,1200,600);
   PID->Range(0,0,1,1);
   PID->SetFillColor(0);
   PID->SetBorderMode(0);
   PID->SetBorderSize(2);
   PID->SetFrameBorderMode(0);
  
// ------------>Primitives in pad: PID_1
   TPad *PID_1 = new TPad("PID_1", "PID_1",0.01,0.51,0.49,0.99);
   PID_1->Draw();
   PID_1->cd();
   PID_1->Range(-0.15,-98789.91,1.35,889109.2);
   PID_1->SetFillColor(0);
   PID_1->SetBorderMode(0);
   PID_1->SetBorderSize(2);
   PID_1->SetGridx();
   PID_1->SetGridy();
   PID_1->SetTickx(1);
   PID_1->SetTicky(1);
   PID_1->SetFrameBorderMode(0);
   PID_1->SetFrameBorderMode(0);
   

// ------------>Primitives in pad: PID_2
   TPad *PID_2 = new TPad("PID_2", "PID_2",0.51,0.51,0.99,0.99);
   PID_2->Draw();
   PID_2->cd();
   PID_2->Range(0.6153846,-11.94375,2.153846,107.4938);
   PID_2->SetFillColor(0);
   PID_2->SetBorderMode(0);
   PID_2->SetBorderSize(2);
   PID_2->SetGridx();
   PID_2->SetGridy();
   PID_2->SetTickx(1);
   PID_2->SetTicky(1);
   PID_2->SetLeftMargin(0.12);
   PID_2->SetFrameBorderMode(0);
   PID_2->SetFrameBorderMode(0);
   
   TH1I *KPlusKMinus__2 = new TH1I("KPlusKMinus__2","K^{+}K^{-} inv. mass w/ identified proton",400,0,2);
   KPlusKMinus__2->SetBinContent(198,1);
   KPlusKMinus__2->SetBinContent(199,4);
   KPlusKMinus__2->SetBinContent(200,16);
   KPlusKMinus__2->SetBinContent(201,12);
   KPlusKMinus__2->SetBinContent(202,23);
   KPlusKMinus__2->SetBinContent(203,36);
   KPlusKMinus__2->SetBinContent(204,54);
   KPlusKMinus__2->SetBinContent(205,65);
   KPlusKMinus__2->SetBinContent(206,56);
   KPlusKMinus__2->SetBinContent(207,39);
   KPlusKMinus__2->SetBinContent(208,24);
   KPlusKMinus__2->SetBinContent(209,29);
   KPlusKMinus__2->SetBinContent(210,32);
   KPlusKMinus__2->SetBinContent(211,28);
   KPlusKMinus__2->SetBinContent(212,40);
   KPlusKMinus__2->SetBinContent(213,34);
   KPlusKMinus__2->SetBinContent(214,36);
   KPlusKMinus__2->SetBinContent(215,37);
   KPlusKMinus__2->SetBinContent(216,36);
   KPlusKMinus__2->SetBinContent(217,37);
   KPlusKMinus__2->SetBinContent(218,40);
   KPlusKMinus__2->SetBinContent(219,46);
   KPlusKMinus__2->SetBinContent(220,43);
   KPlusKMinus__2->SetBinContent(221,51);
   KPlusKMinus__2->SetBinContent(222,36);
   KPlusKMinus__2->SetBinContent(223,42);
   KPlusKMinus__2->SetBinContent(224,53);
   KPlusKMinus__2->SetBinContent(225,54);
   KPlusKMinus__2->SetBinContent(226,62);
   KPlusKMinus__2->SetBinContent(227,44);
   KPlusKMinus__2->SetBinContent(228,59);
   KPlusKMinus__2->SetBinContent(229,58);
   KPlusKMinus__2->SetBinContent(230,61);
   KPlusKMinus__2->SetBinContent(231,57);
   KPlusKMinus__2->SetBinContent(232,59);
   KPlusKMinus__2->SetBinContent(233,60);
   KPlusKMinus__2->SetBinContent(234,49);
   KPlusKMinus__2->SetBinContent(235,63);
   KPlusKMinus__2->SetBinContent(236,71);
   KPlusKMinus__2->SetBinContent(237,65);
   KPlusKMinus__2->SetBinContent(238,65);
   KPlusKMinus__2->SetBinContent(239,62);
   KPlusKMinus__2->SetBinContent(240,81);
   KPlusKMinus__2->SetBinContent(241,60);
   KPlusKMinus__2->SetBinContent(242,73);
   KPlusKMinus__2->SetBinContent(243,91);
   KPlusKMinus__2->SetBinContent(244,79);
   KPlusKMinus__2->SetBinContent(245,80);
   KPlusKMinus__2->SetBinContent(246,90);
   KPlusKMinus__2->SetBinContent(247,82);
   KPlusKMinus__2->SetBinContent(248,76);
   KPlusKMinus__2->SetBinContent(249,70);
   KPlusKMinus__2->SetBinContent(250,76);
   KPlusKMinus__2->SetBinContent(251,82);
   KPlusKMinus__2->SetBinContent(252,76);
   KPlusKMinus__2->SetBinContent(253,72);
   KPlusKMinus__2->SetBinContent(254,76);
   KPlusKMinus__2->SetBinContent(255,58);
   KPlusKMinus__2->SetBinContent(256,66);
   KPlusKMinus__2->SetBinContent(257,54);
   KPlusKMinus__2->SetBinContent(258,55);
   KPlusKMinus__2->SetBinContent(259,59);
   KPlusKMinus__2->SetBinContent(260,52);
   KPlusKMinus__2->SetBinContent(261,50);
   KPlusKMinus__2->SetBinContent(262,55);
   KPlusKMinus__2->SetBinContent(263,46);
   KPlusKMinus__2->SetBinContent(264,52);
   KPlusKMinus__2->SetBinContent(265,54);
   KPlusKMinus__2->SetBinContent(266,48);
   KPlusKMinus__2->SetBinContent(267,58);
   KPlusKMinus__2->SetBinContent(268,46);
   KPlusKMinus__2->SetBinContent(269,45);
   KPlusKMinus__2->SetBinContent(270,57);
   KPlusKMinus__2->SetBinContent(271,56);
   KPlusKMinus__2->SetBinContent(272,54);
   KPlusKMinus__2->SetBinContent(273,42);
   KPlusKMinus__2->SetBinContent(274,41);
   KPlusKMinus__2->SetBinContent(275,37);
   KPlusKMinus__2->SetBinContent(276,42);
   KPlusKMinus__2->SetBinContent(277,48);
   KPlusKMinus__2->SetBinContent(278,30);
   KPlusKMinus__2->SetBinContent(279,30);
   KPlusKMinus__2->SetBinContent(280,39);
   KPlusKMinus__2->SetBinContent(281,46);
   KPlusKMinus__2->SetBinContent(282,33);
   KPlusKMinus__2->SetBinContent(283,33);
   KPlusKMinus__2->SetBinContent(284,35);
   KPlusKMinus__2->SetBinContent(285,32);
   KPlusKMinus__2->SetBinContent(286,36);
   KPlusKMinus__2->SetBinContent(287,42);
   KPlusKMinus__2->SetBinContent(288,42);
   KPlusKMinus__2->SetBinContent(289,35);
   KPlusKMinus__2->SetBinContent(290,47);
   KPlusKMinus__2->SetBinContent(291,32);
   KPlusKMinus__2->SetBinContent(292,32);
   KPlusKMinus__2->SetBinContent(293,33);
   KPlusKMinus__2->SetBinContent(294,34);
   KPlusKMinus__2->SetBinContent(295,25);
   KPlusKMinus__2->SetBinContent(296,35);
   KPlusKMinus__2->SetBinContent(297,37);
   KPlusKMinus__2->SetBinContent(298,22);
   KPlusKMinus__2->SetBinContent(299,23);
   KPlusKMinus__2->SetBinContent(300,27);
   KPlusKMinus__2->SetBinContent(301,28);
   KPlusKMinus__2->SetBinContent(302,32);
   KPlusKMinus__2->SetBinContent(303,24);
   KPlusKMinus__2->SetBinContent(304,25);
   KPlusKMinus__2->SetBinContent(305,30);
   KPlusKMinus__2->SetBinContent(306,24);
   KPlusKMinus__2->SetBinContent(307,27);
   KPlusKMinus__2->SetBinContent(308,23);
   KPlusKMinus__2->SetBinContent(309,35);
   KPlusKMinus__2->SetBinContent(310,26);
   KPlusKMinus__2->SetBinContent(311,24);
   KPlusKMinus__2->SetBinContent(312,34);
   KPlusKMinus__2->SetBinContent(313,37);
   KPlusKMinus__2->SetBinContent(314,20);
   KPlusKMinus__2->SetBinContent(315,38);
   KPlusKMinus__2->SetBinContent(316,22);
   KPlusKMinus__2->SetBinContent(317,21);
   KPlusKMinus__2->SetBinContent(318,18);
   KPlusKMinus__2->SetBinContent(319,26);
   KPlusKMinus__2->SetBinContent(320,24);
   KPlusKMinus__2->SetBinContent(321,23);
   KPlusKMinus__2->SetBinContent(322,22);
   KPlusKMinus__2->SetBinContent(323,32);
   KPlusKMinus__2->SetBinContent(324,28);
   KPlusKMinus__2->SetBinContent(325,22);
   KPlusKMinus__2->SetBinContent(326,23);
   KPlusKMinus__2->SetBinContent(327,31);
   KPlusKMinus__2->SetBinContent(328,34);
   KPlusKMinus__2->SetBinContent(329,30);
   KPlusKMinus__2->SetBinContent(330,21);
   KPlusKMinus__2->SetBinContent(331,26);
   KPlusKMinus__2->SetBinContent(332,16);
   KPlusKMinus__2->SetBinContent(333,22);
   KPlusKMinus__2->SetBinContent(334,27);
   KPlusKMinus__2->SetBinContent(335,23);
   KPlusKMinus__2->SetBinContent(336,23);
   KPlusKMinus__2->SetBinContent(337,20);
   KPlusKMinus__2->SetBinContent(338,18);
   KPlusKMinus__2->SetBinContent(339,19);
   KPlusKMinus__2->SetBinContent(340,18);
   KPlusKMinus__2->SetBinContent(341,21);
   KPlusKMinus__2->SetBinContent(342,23);
   KPlusKMinus__2->SetBinContent(343,16);
   KPlusKMinus__2->SetBinContent(344,18);
   KPlusKMinus__2->SetBinContent(345,19);
   KPlusKMinus__2->SetBinContent(346,22);
   KPlusKMinus__2->SetBinContent(347,23);
   KPlusKMinus__2->SetBinContent(348,15);
   KPlusKMinus__2->SetBinContent(349,15);
   KPlusKMinus__2->SetBinContent(350,18);
   KPlusKMinus__2->SetBinContent(351,19);
   KPlusKMinus__2->SetBinContent(352,19);
   KPlusKMinus__2->SetBinContent(353,12);
   KPlusKMinus__2->SetBinContent(354,16);
   KPlusKMinus__2->SetBinContent(355,18);
   KPlusKMinus__2->SetBinContent(356,15);
   KPlusKMinus__2->SetBinContent(357,17);
   KPlusKMinus__2->SetBinContent(358,12);
   KPlusKMinus__2->SetBinContent(359,22);
   KPlusKMinus__2->SetBinContent(360,12);
   KPlusKMinus__2->SetBinContent(361,17);
   KPlusKMinus__2->SetBinContent(362,16);
   KPlusKMinus__2->SetBinContent(363,17);
   KPlusKMinus__2->SetBinContent(364,21);
   KPlusKMinus__2->SetBinContent(365,16);
   KPlusKMinus__2->SetBinContent(366,12);
   KPlusKMinus__2->SetBinContent(367,15);
   KPlusKMinus__2->SetBinContent(368,12);
   KPlusKMinus__2->SetBinContent(369,11);
   KPlusKMinus__2->SetBinContent(370,17);
   KPlusKMinus__2->SetBinContent(371,13);
   KPlusKMinus__2->SetBinContent(372,13);
   KPlusKMinus__2->SetBinContent(373,18);
   KPlusKMinus__2->SetBinContent(374,10);
   KPlusKMinus__2->SetBinContent(375,19);
   KPlusKMinus__2->SetBinContent(376,11);
   KPlusKMinus__2->SetBinContent(377,18);
   KPlusKMinus__2->SetBinContent(378,18);
   KPlusKMinus__2->SetBinContent(379,18);
   KPlusKMinus__2->SetBinContent(380,15);
   KPlusKMinus__2->SetBinContent(381,16);
   KPlusKMinus__2->SetBinContent(382,15);
   KPlusKMinus__2->SetBinContent(383,16);
   KPlusKMinus__2->SetBinContent(384,20);
   KPlusKMinus__2->SetBinContent(385,18);
   KPlusKMinus__2->SetBinContent(386,16);
   KPlusKMinus__2->SetBinContent(387,14);
   KPlusKMinus__2->SetBinContent(388,15);
   KPlusKMinus__2->SetBinContent(389,14);
   KPlusKMinus__2->SetBinContent(390,14);
   KPlusKMinus__2->SetBinContent(391,13);
   KPlusKMinus__2->SetBinContent(392,11);
   KPlusKMinus__2->SetBinContent(393,10);
   KPlusKMinus__2->SetBinContent(394,8);
   KPlusKMinus__2->SetBinContent(395,13);
   KPlusKMinus__2->SetBinContent(396,10);
   KPlusKMinus__2->SetBinContent(397,12);
   KPlusKMinus__2->SetBinContent(398,12);
   KPlusKMinus__2->SetBinContent(399,15);
   KPlusKMinus__2->SetBinContent(400,10);
   KPlusKMinus__2->SetBinContent(401,1405);
   KPlusKMinus__2->SetEntries(7059);
   KPlusKMinus__2->SetStats(0);
   
   TF1 *KPlusKMinus_fun2 = new TF1("*KPlusKMinus_fun",0.988,2,13);
    //The original function : KPlusKMinus_fun had originally been created by:
    //TF1 *KPlusKMinus_fun = new TF1("KPlusKMinus_fun",KPlusKMinus_fun,0.988,2,13, 1, TF1::EAddToList::kNo);
   KPlusKMinus_fun2->SetRange(0.988,2);
   KPlusKMinus_fun2->SetName("KPlusKMinus_fun");
   KPlusKMinus_fun2->SetTitle("KPlusKMinus_fun");
   KPlusKMinus_fun2->SetSavedPoint(0,0.1096942);
   KPlusKMinus_fun2->SetSavedPoint(1,10.76455);
   KPlusKMinus_fun2->SetSavedPoint(2,22.19515);
   KPlusKMinus_fun2->SetSavedPoint(3,59.13176);
   KPlusKMinus_fun2->SetSavedPoint(4,50.37825);
   KPlusKMinus_fun2->SetSavedPoint(5,28.92325);
   KPlusKMinus_fun2->SetSavedPoint(6,29.79705);
   KPlusKMinus_fun2->SetSavedPoint(7,32.38869);
   KPlusKMinus_fun2->SetSavedPoint(8,34.90256);
   KPlusKMinus_fun2->SetSavedPoint(9,37.40195);
   KPlusKMinus_fun2->SetSavedPoint(10,39.95347);
   KPlusKMinus_fun2->SetSavedPoint(11,42.61082);
   KPlusKMinus_fun2->SetSavedPoint(12,45.41181);
   KPlusKMinus_fun2->SetSavedPoint(13,48.37456);
   KPlusKMinus_fun2->SetSavedPoint(14,51.49367);
   KPlusKMinus_fun2->SetSavedPoint(15,54.73734);
   KPlusKMinus_fun2->SetSavedPoint(16,58.04624);
   KPlusKMinus_fun2->SetSavedPoint(17,61.33474);
   KPlusKMinus_fun2->SetSavedPoint(18,64.49509);
   KPlusKMinus_fun2->SetSavedPoint(19,67.4044);
   KPlusKMinus_fun2->SetSavedPoint(20,69.93418);
   KPlusKMinus_fun2->SetSavedPoint(21,71.96144);
   KPlusKMinus_fun2->SetSavedPoint(22,73.38023);
   KPlusKMinus_fun2->SetSavedPoint(23,74.1122);
   KPlusKMinus_fun2->SetSavedPoint(24,74.11484);
   KPlusKMinus_fun2->SetSavedPoint(25,73.38619);
   KPlusKMinus_fun2->SetSavedPoint(26,71.96561);
   KPlusKMinus_fun2->SetSavedPoint(27,69.93019);
   KPlusKMinus_fun2->SetSavedPoint(28,67.38759);
   KPlusKMinus_fun2->SetSavedPoint(29,64.46615);
   KPlusKMinus_fun2->SetSavedPoint(30,61.30359);
   KPlusKMinus_fun2->SetSavedPoint(31,58.03576);
   KPlusKMinus_fun2->SetSavedPoint(32,54.78671);
   KPlusKMinus_fun2->SetSavedPoint(33,51.66104);
   KPlusKMinus_fun2->SetSavedPoint(34,48.73912);
   KPlusKMinus_fun2->SetSavedPoint(35,46.07532);
   KPlusKMinus_fun2->SetSavedPoint(36,43.69882);
   KPlusKMinus_fun2->SetSavedPoint(37,41.61666);
   KPlusKMinus_fun2->SetSavedPoint(38,39.81805);
   KPlusKMinus_fun2->SetSavedPoint(39,38.27933);
   KPlusKMinus_fun2->SetSavedPoint(40,36.9689);
   KPlusKMinus_fun2->SetSavedPoint(41,35.85154);
   KPlusKMinus_fun2->SetSavedPoint(42,34.89194);
   KPlusKMinus_fun2->SetSavedPoint(43,34.05716);
   KPlusKMinus_fun2->SetSavedPoint(44,33.3182);
   KPlusKMinus_fun2->SetSavedPoint(45,32.65076);
   KPlusKMinus_fun2->SetSavedPoint(46,32.03529);
   KPlusKMinus_fun2->SetSavedPoint(47,31.45673);
   KPlusKMinus_fun2->SetSavedPoint(48,30.90383);
   KPlusKMinus_fun2->SetSavedPoint(49,30.36858);
   KPlusKMinus_fun2->SetSavedPoint(50,29.84543);
   KPlusKMinus_fun2->SetSavedPoint(51,29.33072);
   KPlusKMinus_fun2->SetSavedPoint(52,28.82215);
   KPlusKMinus_fun2->SetSavedPoint(53,28.31836);
   KPlusKMinus_fun2->SetSavedPoint(54,27.81864);
   KPlusKMinus_fun2->SetSavedPoint(55,27.32268);
   KPlusKMinus_fun2->SetSavedPoint(56,26.83043);
   KPlusKMinus_fun2->SetSavedPoint(57,26.34198);
   KPlusKMinus_fun2->SetSavedPoint(58,25.85749);
   KPlusKMinus_fun2->SetSavedPoint(59,25.37719);
   KPlusKMinus_fun2->SetSavedPoint(60,24.90128);
   KPlusKMinus_fun2->SetSavedPoint(61,24.42998);
   KPlusKMinus_fun2->SetSavedPoint(62,23.9635);
   KPlusKMinus_fun2->SetSavedPoint(63,23.50203);
   KPlusKMinus_fun2->SetSavedPoint(64,23.04574);
   KPlusKMinus_fun2->SetSavedPoint(65,22.59478);
   KPlusKMinus_fun2->SetSavedPoint(66,22.1493);
   KPlusKMinus_fun2->SetSavedPoint(67,21.70942);
   KPlusKMinus_fun2->SetSavedPoint(68,21.27525);
   KPlusKMinus_fun2->SetSavedPoint(69,20.84688);
   KPlusKMinus_fun2->SetSavedPoint(70,20.42439);
   KPlusKMinus_fun2->SetSavedPoint(71,20.00786);
   KPlusKMinus_fun2->SetSavedPoint(72,19.59735);
   KPlusKMinus_fun2->SetSavedPoint(73,19.19289);
   KPlusKMinus_fun2->SetSavedPoint(74,18.79452);
   KPlusKMinus_fun2->SetSavedPoint(75,18.40227);
   KPlusKMinus_fun2->SetSavedPoint(76,18.01617);
   KPlusKMinus_fun2->SetSavedPoint(77,17.63622);
   KPlusKMinus_fun2->SetSavedPoint(78,17.26242);
   KPlusKMinus_fun2->SetSavedPoint(79,16.89477);
   KPlusKMinus_fun2->SetSavedPoint(80,16.53325);
   KPlusKMinus_fun2->SetSavedPoint(81,16.17786);
   KPlusKMinus_fun2->SetSavedPoint(82,15.82857);
   KPlusKMinus_fun2->SetSavedPoint(83,15.48534);
   KPlusKMinus_fun2->SetSavedPoint(84,15.14816);
   KPlusKMinus_fun2->SetSavedPoint(85,14.81697);
   KPlusKMinus_fun2->SetSavedPoint(86,14.49175);
   KPlusKMinus_fun2->SetSavedPoint(87,14.17244);
   KPlusKMinus_fun2->SetSavedPoint(88,13.85899);
   KPlusKMinus_fun2->SetSavedPoint(89,13.55136);
   KPlusKMinus_fun2->SetSavedPoint(90,13.24949);
   KPlusKMinus_fun2->SetSavedPoint(91,12.95333);
   KPlusKMinus_fun2->SetSavedPoint(92,12.6628);
   KPlusKMinus_fun2->SetSavedPoint(93,12.37786);
   KPlusKMinus_fun2->SetSavedPoint(94,12.09844);
   KPlusKMinus_fun2->SetSavedPoint(95,11.82447);
   KPlusKMinus_fun2->SetSavedPoint(96,11.55588);
   KPlusKMinus_fun2->SetSavedPoint(97,11.29262);
   KPlusKMinus_fun2->SetSavedPoint(98,11.0346);
   KPlusKMinus_fun2->SetSavedPoint(99,10.78176);
   KPlusKMinus_fun2->SetSavedPoint(100,10.53403);
   KPlusKMinus_fun2->SetSavedPoint(101,0.988);
   KPlusKMinus_fun2->SetSavedPoint(102,2);
   KPlusKMinus_fun2->SetBit(TF1::kNotDraw);
   KPlusKMinus_fun2->SetFillColor(19);
   KPlusKMinus_fun2->SetFillStyle(0);
   KPlusKMinus_fun2->SetLineColor(2);
   KPlusKMinus_fun2->SetLineWidth(2);
   KPlusKMinus_fun2->SetChisquare(155.8476);
   KPlusKMinus_fun2->SetNDF(193);
   KPlusKMinus_fun2->GetXaxis()->SetLabelFont(42);
   KPlusKMinus_fun2->GetXaxis()->SetLabelSize(0.035);
   KPlusKMinus_fun2->GetXaxis()->SetTitleSize(0.035);
   KPlusKMinus_fun2->GetXaxis()->SetTitleOffset(1);
   KPlusKMinus_fun2->GetXaxis()->SetTitleFont(42);
   KPlusKMinus_fun2->GetYaxis()->SetLabelFont(42);
   KPlusKMinus_fun2->GetYaxis()->SetLabelSize(0.035);
   KPlusKMinus_fun2->GetYaxis()->SetTitleSize(0.035);
   KPlusKMinus_fun2->GetYaxis()->SetTitleFont(42);
   KPlusKMinus_fun2->SetParameter(0,2);
   KPlusKMinus_fun2->SetParError(0,0);
   KPlusKMinus_fun2->SetParLimits(0,2,2);
   KPlusKMinus_fun2->SetParameter(1,3675.449);
   KPlusKMinus_fun2->SetParError(1,1230.032);
   KPlusKMinus_fun2->SetParLimits(1,0,0);
   KPlusKMinus_fun2->SetParameter(2,0.988);
   KPlusKMinus_fun2->SetParError(2,0);
   KPlusKMinus_fun2->SetParLimits(2,0.988,0.988);
   KPlusKMinus_fun2->SetParameter(3,0.6386741);
   KPlusKMinus_fun2->SetParError(3,0.05174862);
   KPlusKMinus_fun2->SetParLimits(3,0.3,4);
   KPlusKMinus_fun2->SetParameter(4,2.931219);
   KPlusKMinus_fun2->SetParError(4,0.1898994);
   KPlusKMinus_fun2->SetParLimits(4,0.5,8);
   KPlusKMinus_fun2->SetParameter(5,1);
   KPlusKMinus_fun2->SetParError(5,0);
   KPlusKMinus_fun2->SetParLimits(5,1,1);
   KPlusKMinus_fun2->SetParameter(6,0.7425436);
   KPlusKMinus_fun2->SetParError(6,0.1065858);
   KPlusKMinus_fun2->SetParLimits(6,0,0);
   KPlusKMinus_fun2->SetParameter(7,1.021694);
   KPlusKMinus_fun2->SetParError(7,0.0009300469);
   KPlusKMinus_fun2->SetParLimits(7,0,0);
   KPlusKMinus_fun2->SetParameter(8,0.006767793);
   KPlusKMinus_fun2->SetParError(8,0.0008773673);
   KPlusKMinus_fun2->SetParLimits(8,0.003,0.03);
   KPlusKMinus_fun2->SetParameter(9,1);
   KPlusKMinus_fun2->SetParError(9,0);
   KPlusKMinus_fun2->SetParLimits(9,1,1);
   KPlusKMinus_fun2->SetParameter(10,5.989693);
   KPlusKMinus_fun2->SetParError(10,0.9066554);
   KPlusKMinus_fun2->SetParLimits(10,0,0);
   KPlusKMinus_fun2->SetParameter(11,1.227327);
   KPlusKMinus_fun2->SetParError(11,0.004934549);
   KPlusKMinus_fun2->SetParLimits(11,0,0);
   KPlusKMinus_fun2->SetParameter(12,0.07068209);
   KPlusKMinus_fun2->SetParError(12,0.00865763);
   KPlusKMinus_fun2->SetParLimits(12,0.015,0.15);
   KPlusKMinus_fun2->SetParent(KPlusKMinus__2);
   KPlusKMinus__2->GetListOfFunctions()->Add(KPlusKMinus_fun2);

   ci = TColor::GetColor("#000099");
   KPlusKMinus__2->SetLineColor(ci);
   KPlusKMinus__2->GetXaxis()->SetTitle("K^{+}K^{-} inv. mass (GeV)");
   KPlusKMinus__2->GetXaxis()->SetRange(161,400);
   KPlusKMinus__2->GetXaxis()->SetLabelFont(42);
   KPlusKMinus__2->GetXaxis()->SetLabelSize(0.05);
   KPlusKMinus__2->GetXaxis()->SetTitleSize(0.05);
   KPlusKMinus__2->GetXaxis()->SetTitleOffset(1);
   KPlusKMinus__2->GetXaxis()->SetTitleFont(42);
   KPlusKMinus__2->GetYaxis()->SetTitle("Combinations /   5.0 MeV");
   KPlusKMinus__2->GetYaxis()->SetLabelFont(42);
   KPlusKMinus__2->GetYaxis()->SetLabelSize(0.035);
   KPlusKMinus__2->GetYaxis()->SetTitleSize(0.05);
   KPlusKMinus__2->GetYaxis()->SetTitleOffset(0.75);
   KPlusKMinus__2->GetYaxis()->SetTitleFont(42);
   KPlusKMinus__2->GetZaxis()->SetLabelFont(42);
   KPlusKMinus__2->GetZaxis()->SetLabelSize(0.035);
   KPlusKMinus__2->GetZaxis()->SetTitleSize(0.035);
   KPlusKMinus__2->GetZaxis()->SetTitleOffset(1);
   KPlusKMinus__2->GetZaxis()->SetTitleFont(42);
   KPlusKMinus__2->Draw("");
   
   TF1 *KPlusKMinus_fun3 = new TF1("*KPlusKMinus_fun",0.988,2,13);
    //The original function : KPlusKMinus_fun had originally been created by:
    //TF1 *KPlusKMinus_fun = new TF1("KPlusKMinus_fun",KPlusKMinus_fun,0.988,2,13, 1, TF1::EAddToList::kDefault);
   KPlusKMinus_fun3->SetRange(0.988,2);
   KPlusKMinus_fun3->SetName("KPlusKMinus_fun");
   KPlusKMinus_fun3->SetTitle("KPlusKMinus_fun");
   KPlusKMinus_fun3->SetSavedPoint(0,0.1096942);
   KPlusKMinus_fun3->SetSavedPoint(1,10.76455);
   KPlusKMinus_fun3->SetSavedPoint(2,22.19515);
   KPlusKMinus_fun3->SetSavedPoint(3,59.13176);
   KPlusKMinus_fun3->SetSavedPoint(4,50.37825);
   KPlusKMinus_fun3->SetSavedPoint(5,28.92325);
   KPlusKMinus_fun3->SetSavedPoint(6,29.79705);
   KPlusKMinus_fun3->SetSavedPoint(7,32.38869);
   KPlusKMinus_fun3->SetSavedPoint(8,34.90256);
   KPlusKMinus_fun3->SetSavedPoint(9,37.40195);
   KPlusKMinus_fun3->SetSavedPoint(10,39.95347);
   KPlusKMinus_fun3->SetSavedPoint(11,42.61082);
   KPlusKMinus_fun3->SetSavedPoint(12,45.41181);
   KPlusKMinus_fun3->SetSavedPoint(13,48.37456);
   KPlusKMinus_fun3->SetSavedPoint(14,51.49367);
   KPlusKMinus_fun3->SetSavedPoint(15,54.73734);
   KPlusKMinus_fun3->SetSavedPoint(16,58.04624);
   KPlusKMinus_fun3->SetSavedPoint(17,61.33474);
   KPlusKMinus_fun3->SetSavedPoint(18,64.49509);
   KPlusKMinus_fun3->SetSavedPoint(19,67.4044);
   KPlusKMinus_fun3->SetSavedPoint(20,69.93418);
   KPlusKMinus_fun3->SetSavedPoint(21,71.96144);
   KPlusKMinus_fun3->SetSavedPoint(22,73.38023);
   KPlusKMinus_fun3->SetSavedPoint(23,74.1122);
   KPlusKMinus_fun3->SetSavedPoint(24,74.11484);
   KPlusKMinus_fun3->SetSavedPoint(25,73.38619);
   KPlusKMinus_fun3->SetSavedPoint(26,71.96561);
   KPlusKMinus_fun3->SetSavedPoint(27,69.93019);
   KPlusKMinus_fun3->SetSavedPoint(28,67.38759);
   KPlusKMinus_fun3->SetSavedPoint(29,64.46615);
   KPlusKMinus_fun3->SetSavedPoint(30,61.30359);
   KPlusKMinus_fun3->SetSavedPoint(31,58.03576);
   KPlusKMinus_fun3->SetSavedPoint(32,54.78671);
   KPlusKMinus_fun3->SetSavedPoint(33,51.66104);
   KPlusKMinus_fun3->SetSavedPoint(34,48.73912);
   KPlusKMinus_fun3->SetSavedPoint(35,46.07532);
   KPlusKMinus_fun3->SetSavedPoint(36,43.69882);
   KPlusKMinus_fun3->SetSavedPoint(37,41.61666);
   KPlusKMinus_fun3->SetSavedPoint(38,39.81805);
   KPlusKMinus_fun3->SetSavedPoint(39,38.27933);
   KPlusKMinus_fun3->SetSavedPoint(40,36.9689);
   KPlusKMinus_fun3->SetSavedPoint(41,35.85154);
   KPlusKMinus_fun3->SetSavedPoint(42,34.89194);
   KPlusKMinus_fun3->SetSavedPoint(43,34.05716);
   KPlusKMinus_fun3->SetSavedPoint(44,33.3182);
   KPlusKMinus_fun3->SetSavedPoint(45,32.65076);
   KPlusKMinus_fun3->SetSavedPoint(46,32.03529);
   KPlusKMinus_fun3->SetSavedPoint(47,31.45673);
   KPlusKMinus_fun3->SetSavedPoint(48,30.90383);
   KPlusKMinus_fun3->SetSavedPoint(49,30.36858);
   KPlusKMinus_fun3->SetSavedPoint(50,29.84543);
   KPlusKMinus_fun3->SetSavedPoint(51,29.33072);
   KPlusKMinus_fun3->SetSavedPoint(52,28.82215);
   KPlusKMinus_fun3->SetSavedPoint(53,28.31836);
   KPlusKMinus_fun3->SetSavedPoint(54,27.81864);
   KPlusKMinus_fun3->SetSavedPoint(55,27.32268);
   KPlusKMinus_fun3->SetSavedPoint(56,26.83043);
   KPlusKMinus_fun3->SetSavedPoint(57,26.34198);
   KPlusKMinus_fun3->SetSavedPoint(58,25.85749);
   KPlusKMinus_fun3->SetSavedPoint(59,25.37719);
   KPlusKMinus_fun3->SetSavedPoint(60,24.90128);
   KPlusKMinus_fun3->SetSavedPoint(61,24.42998);
   KPlusKMinus_fun3->SetSavedPoint(62,23.9635);
   KPlusKMinus_fun3->SetSavedPoint(63,23.50203);
   KPlusKMinus_fun3->SetSavedPoint(64,23.04574);
   KPlusKMinus_fun3->SetSavedPoint(65,22.59478);
   KPlusKMinus_fun3->SetSavedPoint(66,22.1493);
   KPlusKMinus_fun3->SetSavedPoint(67,21.70942);
   KPlusKMinus_fun3->SetSavedPoint(68,21.27525);
   KPlusKMinus_fun3->SetSavedPoint(69,20.84688);
   KPlusKMinus_fun3->SetSavedPoint(70,20.42439);
   KPlusKMinus_fun3->SetSavedPoint(71,20.00786);
   KPlusKMinus_fun3->SetSavedPoint(72,19.59735);
   KPlusKMinus_fun3->SetSavedPoint(73,19.19289);
   KPlusKMinus_fun3->SetSavedPoint(74,18.79452);
   KPlusKMinus_fun3->SetSavedPoint(75,18.40227);
   KPlusKMinus_fun3->SetSavedPoint(76,18.01617);
   KPlusKMinus_fun3->SetSavedPoint(77,17.63622);
   KPlusKMinus_fun3->SetSavedPoint(78,17.26242);
   KPlusKMinus_fun3->SetSavedPoint(79,16.89477);
   KPlusKMinus_fun3->SetSavedPoint(80,16.53325);
   KPlusKMinus_fun3->SetSavedPoint(81,16.17786);
   KPlusKMinus_fun3->SetSavedPoint(82,15.82857);
   KPlusKMinus_fun3->SetSavedPoint(83,15.48534);
   KPlusKMinus_fun3->SetSavedPoint(84,15.14816);
   KPlusKMinus_fun3->SetSavedPoint(85,14.81697);
   KPlusKMinus_fun3->SetSavedPoint(86,14.49175);
   KPlusKMinus_fun3->SetSavedPoint(87,14.17244);
   KPlusKMinus_fun3->SetSavedPoint(88,13.85899);
   KPlusKMinus_fun3->SetSavedPoint(89,13.55136);
   KPlusKMinus_fun3->SetSavedPoint(90,13.24949);
   KPlusKMinus_fun3->SetSavedPoint(91,12.95333);
   KPlusKMinus_fun3->SetSavedPoint(92,12.6628);
   KPlusKMinus_fun3->SetSavedPoint(93,12.37786);
   KPlusKMinus_fun3->SetSavedPoint(94,12.09844);
   KPlusKMinus_fun3->SetSavedPoint(95,11.82447);
   KPlusKMinus_fun3->SetSavedPoint(96,11.55588);
   KPlusKMinus_fun3->SetSavedPoint(97,11.29262);
   KPlusKMinus_fun3->SetSavedPoint(98,11.0346);
   KPlusKMinus_fun3->SetSavedPoint(99,10.78176);
   KPlusKMinus_fun3->SetSavedPoint(100,10.53403);
   KPlusKMinus_fun3->SetSavedPoint(101,0.988);
   KPlusKMinus_fun3->SetSavedPoint(102,2);
   KPlusKMinus_fun3->SetFillColor(19);
   KPlusKMinus_fun3->SetFillStyle(0);
   KPlusKMinus_fun3->SetLineColor(2);
   KPlusKMinus_fun3->SetLineWidth(2);
   KPlusKMinus_fun3->SetChisquare(155.8476);
   KPlusKMinus_fun3->SetNDF(193);
   KPlusKMinus_fun3->GetXaxis()->SetLabelFont(42);
   KPlusKMinus_fun3->GetXaxis()->SetLabelSize(0.035);
   KPlusKMinus_fun3->GetXaxis()->SetTitleSize(0.035);
   KPlusKMinus_fun3->GetXaxis()->SetTitleOffset(1);
   KPlusKMinus_fun3->GetXaxis()->SetTitleFont(42);
   KPlusKMinus_fun3->GetYaxis()->SetLabelFont(42);
   KPlusKMinus_fun3->GetYaxis()->SetLabelSize(0.035);
   KPlusKMinus_fun3->GetYaxis()->SetTitleSize(0.035);
   KPlusKMinus_fun3->GetYaxis()->SetTitleFont(42);
   KPlusKMinus_fun3->SetParameter(0,2);
   KPlusKMinus_fun3->SetParError(0,0);
   KPlusKMinus_fun3->SetParLimits(0,2,2);
   KPlusKMinus_fun3->SetParameter(1,3675.449);
   KPlusKMinus_fun3->SetParError(1,1230.032);
   KPlusKMinus_fun3->SetParLimits(1,0,0);
   KPlusKMinus_fun3->SetParameter(2,0.988);
   KPlusKMinus_fun3->SetParError(2,0);
   KPlusKMinus_fun3->SetParLimits(2,0.988,0.988);
   KPlusKMinus_fun3->SetParameter(3,0.6386741);
   KPlusKMinus_fun3->SetParError(3,0.05174862);
   KPlusKMinus_fun3->SetParLimits(3,0.3,4);
   KPlusKMinus_fun3->SetParameter(4,2.931219);
   KPlusKMinus_fun3->SetParError(4,0.1898994);
   KPlusKMinus_fun3->SetParLimits(4,0.5,8);
   KPlusKMinus_fun3->SetParameter(5,1);
   KPlusKMinus_fun3->SetParError(5,0);
   KPlusKMinus_fun3->SetParLimits(5,1,1);
   KPlusKMinus_fun3->SetParameter(6,0.7425436);
   KPlusKMinus_fun3->SetParError(6,0.1065858);
   KPlusKMinus_fun3->SetParLimits(6,0,0);
   KPlusKMinus_fun3->SetParameter(7,1.021694);
   KPlusKMinus_fun3->SetParError(7,0.0009300469);
   KPlusKMinus_fun3->SetParLimits(7,0,0);
   KPlusKMinus_fun3->SetParameter(8,0.006767793);
   KPlusKMinus_fun3->SetParError(8,0.0008773673);
   KPlusKMinus_fun3->SetParLimits(8,0.003,0.03);
   KPlusKMinus_fun3->SetParameter(9,1);
   KPlusKMinus_fun3->SetParError(9,0);
   KPlusKMinus_fun3->SetParLimits(9,1,1);
   KPlusKMinus_fun3->SetParameter(10,5.989693);
   KPlusKMinus_fun3->SetParError(10,0.9066554);
   KPlusKMinus_fun3->SetParLimits(10,0,0);
   KPlusKMinus_fun3->SetParameter(11,1.227327);
   KPlusKMinus_fun3->SetParError(11,0.004934549);
   KPlusKMinus_fun3->SetParLimits(11,0,0);
   KPlusKMinus_fun3->SetParameter(12,0.07068209);
   KPlusKMinus_fun3->SetParError(12,0.00865763);
   KPlusKMinus_fun3->SetParLimits(12,0.015,0.15);
   KPlusKMinus_fun3->Draw("same");
   

}

I can see both:

   // ...
   KPlusKMinus__2->Draw(""); // the histogram
   // ...
   KPlusKMinus_fun3->Draw("same"); // the function
   // ...

Correct. But the second one draws just a line at the bottom of the plot and not the actual curve that is on the original. I think the problem is that the original TF1 is defined to call a user defined routine, but the macro does not (and probably cannot) save this. Thus, it saves not only the function parameters (useless without the user routine) but also a bunch of points via the SetSavedPoint calls so that it can redraw the curve, even without the user routine.

It seems the call to KPlusKMinus_fun3->Draw(“same”) does not try and plot the points from the fSave member of the TF1 and I’m trying to figure out how to get it to do so.

I get the histogram drawn in “blue” and the fitted curve in “red” (and it goes through histogram points, not “at the bottom”). You can also retrieve the “best fit” parameters and their errors, “chi^2” and “NDF”, (that’s why they are “saved”, too).

BTW. In the TF1 class reference, search for the “WARNING! A function created with this constructor cannot be Cloned.” (such functions cannot be “saved” in ROOT files).

OK. so what version of ROOT are you using and on what platform? I’ve tried this with 6.18.02 on Linux and 6.13.0 on Mac OS X and a colleague tried on what I suspect is another version on his Linux computer and all give the same behavior. Namely the red line is at the bottom of the plot and definitely does NOT go through the histogram.

Another note on context: This is for a plot going into a large NIM paper. We were asked to provide macros so the editors could tweak the label sizes etc. to be consistent and well suited for the publication. Thus, this is only for display purposes and I don’t need the actual function to be available in the macro.

I wrote a simple macro that demonstrates this. Simply run this one and then, in a different session, run the “generated.C” macro.

// User defined function
Double_t myFunc(Double_t *xptr, Double_t *p)
{
	return p[0]*sin(xptr[0]);
}

// Main maxcro
void create(void)
{
	auto c1 = new TCanvas("c1");

	auto ftf = new TF1("ftf", myFunc, 0.2, 5.8, 1);
	ftf->SetParameter(0, 2.0);

	auto axes = new TH2D("axes", "An Example", 100, 0.0, 6.0, 100, -3.0, 3.0);
	axes->Draw();
	
	ftf->Draw("same");

	c1->SaveAs("generated.C");
}
TH1F *axes = new TH1F("axes", "An Example;my x axis;my y asis", 2, 0.0, 6.0);
axes->SetMinimum(-3.0); axes->SetMaximum(3.0);
axes->SetStats(kFALSE);
axes->Draw();

So I guess you’re saying to use a TH1F for the empty axes instead of a TH2D. I just tried this and it gave the same behavior as before and so doesn’t fix the issue.

I see no problems with: generated.C (5.5 KB)

OK. So we are clearly getting different behaviors. I still don’t know which version of ROOT you are using.

ROOT 5.34/3[68] and 6.19/02 work fine.

ROOT 6.08/06 to 6.18/04 are indeed broken (the “red” line is improperly drawn at the bottom).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.