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

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:

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 (4.8 KB)
results.root (231.6 KB)
analysis.root

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

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.

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]”).

1 Like

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!