# Error when drawing a histogram where a function has been fitted to

**URL:** <https://root-forum.cern.ch/t/error-when-drawing-a-histogram-where-a-function-has-been-fitted-to/34843>\
**Category:** Newbie\
**Created:** [June 26, 2019, 2:11pm UTC](https://root-forum.cern.ch/t/error-when-drawing-a-histogram-where-a-function-has-been-fitted-to/34843 "2019-06-26T14:11:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christoph\_Vogl](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/christoph_vogl/32/19258_2.png) [@Christoph\_Vogl](https://root-forum.cern.ch/u/Christoph_Vogl)\
**Post date:** [June 26, 2019, 2:11pm UTC](https://root-forum.cern.ch/t/error-when-drawing-a-histogram-where-a-function-has-been-fitted-to/34843/1 "2019-06-26T14:11:14Z")

</div>

I have created some histograms and saved them in a .root file (analysis.root). Now I read them using my macro02.C , fit a function to them and save them again in a different .root file (results.root).

Now I want to draw the histograms using the command line interface. Unfortunately that doesn’t work:

```auto
kali: /mnt/e15/comellato/DriftTimeStudies$ root analysis/results.root
root [0]
Attaching file analysis/results.root as _file0...
(TFile *) 0x25b4e20
root [1] .ls
TFile** analysis/results.root
 TFile* analysis/results.root
  KEY: TDirectoryFile dirSCS_fitted;1 dirSCS_fitted
  KEY: TGraphErrors glMeans;1 mean positions of the lower energy gaus
  KEY: TGraphErrors guMeans;1 mean positions of the higher energy gaus
  KEY: TH1D hSCS_0;1 hSCS[0]
  KEY: TH1D hSCS_1;1 hSCS[1]
  KEY: TH1D hSCS_2;1 hSCS[2]
  KEY: TH1D hSCS_3;1 hSCS[3]
  KEY: TH1D hSCS_4;1 hSCS[4]
  KEY: TH1D hSCS_5;1 hSCS[5]
  KEY: TH1D hSCS_6;1 hSCS[6]
  KEY: TH1D hSCS_7;1 hSCS[7]
  KEY: TH1D hSCS_8;1 hSCS[8]
  KEY: TH1D hSCS_9;1 hSCS[9]
  KEY: TH1D hSCS_10;1 hSCS[10]
  KEY: TH1D hSCS_11;1 hSCS[11]
  KEY: TH1D hSCS_12;1 hSCS[12]
  KEY: TH1D hSCS_13;1 hSCS[13]
  KEY: TH1D hSCS_14;1 hSCS[14]
  KEY: TH1D hSCS_15;1 hSCS[15]
  KEY: TH1D hSCS_16;1 hSCS[16]
  KEY: TH1D hSCS_17;1 hSCS[17]
  KEY: TH1D hSCS_18;1 hSCS[18]
  KEY: TH1D hSCS_19;1 hSCS[19]
  KEY: TH1D hSCS_20;1 hSCS[20]
  KEY: TH1D hSCS_21;1 hSCS[21]
  KEY: TH1D hSCS_22;1 hSCS[22]
  KEY: TH1D hSCS_23;1 hSCS[23]
  KEY: TH1D hSCS_24;1 hSCS[24]
  KEY: TH1D hSCS_25;1 hSCS[25]
  KEY: TH1D hSCS_26;1 hSCS[26]
root [2] hSCS_0->Draw()
input_line_44:1:265: error: use of undeclared identifier 't'
  ...t]})+p[8]) ; }
     ^
input_line_44:1:267: error: expected body of lambda expression
  ...})+p[8]) ; }
     ^
Error in <TFormula::Eval>: Can't find TFormula ____ id14707150355920275023 function prototype with arguments Double_t*,Double_t*
root [3] 
root [3] hSCS_0->Draw()
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
Error in <TFormula::Eval>: Formula is invalid or not properly initialized - try calling TFormula::Compile
Error in <TFormula::Eval>: Formula is invalid or not properly initialized - try calling TFormula::Compile

```

When I try do draw it for the first time it gives a different error than wehen I try do draw it again immediately afterwards.

ROOT version: 6.10/06

[macro02.C](https://root-forum.cern.ch/uploads/default/original/3X/7/e/7eba077e425f15b54f5066ff28b908152bf9f210.C) (4.8 KB)  
[results.root](https://root-forum.cern.ch/uploads/default/original/3X/6/1/61cd04f7bc0ad0a313f079a3e81df70dbdfc5e9f.root) (231.6 KB)  
[analysis.root](https://www.dropbox.com/s/88gmtxpzcd1lax3/analysis.root?dl=0)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 26, 2019, 2:48pm UTC](https://root-forum.cern.ch/t/error-when-drawing-a-histogram-where-a-function-has-been-fitted-to/34843/2 "2019-06-26T14:48:44Z")

</div>

I tried to explore a bit your histograms. I did the following:

```auto
root [1] hSCS_0->GetListOfFunctions()->ls()
OBJ: TList	TList	Doubly linked list : 0
 OBJ: TPaveStats	stats X1= 0.023850 Y1=360.576568 X2=0.024100 Y2=446.046567
 OBJ: TF1	fFit	gaus(0) + gaus(3) + [6] * (exp([7]*(x-[8])) + [9])/(exp((x-[8])/[10])+[8]) : 0 at: 0x7fea5528bd00
root [2] hSCS_0->GetListOfFunctions()->FindObject("fFit")
root [3] auto f = (TF1*)hSCS_0->GetListOfFunctions()->FindObject("fFit")
root [4] f->GetName()
(const char *) "fFit"
root [5] f->GetTitle()
(const char *) "gaus(0) + gaus(3) + [6] * (exp([7]*(x-[8])) + [9])/(exp((x-[8])/[10])+[8])"
root [6] 

```

I see that the parameters in your function starts at number 6 … is that normal ? It  
sounds weird. May be @moneta can comment.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 26, 2019, 3:22pm UTC](https://root-forum.cern.ch/t/error-when-drawing-a-histogram-where-a-function-has-been-fitted-to/34843/3 "2019-06-26T15:22:34Z")

</div>

Can you try to run your macro but rename the parameter number “[10]” from “t” to something else like e.g. “time” (in general, “x”, “y”, “z” and “t” have special meanings in ROOT function formulas).

@couet It seems to be fine for me (in the beginning there are two gaussians which use parameters 0 to 5 so the next free one is “[6]”).

---

<div class="post-metadata">

**Author:** ![Christoph\_Vogl](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/christoph_vogl/32/19258_2.png) [@Christoph\_Vogl](https://root-forum.cern.ch/u/Christoph_Vogl)\
**Post date:** [June 27, 2019, 10:42am UTC](https://root-forum.cern.ch/t/error-when-drawing-a-histogram-where-a-function-has-been-fitted-to/34843/4 "2019-06-27T10:42:18Z")

</div>

Thanks Wile!

I changed the naming of parameter [10] from “t” now to “tt” and that worked. I can open my histograms now in my TBrowser without any problem!

I still can’t Draw() them from the command line though. But that’s a problem I have encountered already earlier (see my other topic if you are interested). Therefore we are done here I think.  
Thanks for the help!
