Re: Trouble with a fitting demo example from ROOT manual

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Wed, 20 Sep 2006 10:23:37 +0200


Hi,

the problem causing the warning you see is int nBins = 50;
which should be (and in the users guide is) const int nBins = 50;

Cheers, Axel.

Rene Brun wrote:

> There are too many C++ errors in your code that you posted (probably a
> cut/paste problem
> when posting your mail).
> Please fix these problems and post your next iteration as a mail
> attachment, not in the mail body.
> 
> Rene Brun
> 
> Mushtari Afroz wrote:

>> Hi,
>>
>>
>> I am trying a fitting example from ROOT manual and it
>> is giving me the following error message :
>>
>>
>> Non-static-const variable in array dimension
>> FILE:background_fit.C LINE:44
>> (cint allows this only in interactive command and
>> special form macro which
>> is special extension. It is not allowed in source
>> code. Please ignore
>> subsequent errors.)
>> *** Interpreter error recovered ***
>>
>>
>> ROOT version : Version 3.05/07 21 September 2003
>>
>> In the ROOT session I am doing
>> root[0] .L background_fit.C
>> root[1] fittingDemo()
>>
>>
>> The codes is given below
>> #include "TFile.h"
>> #include "TH1.h"
>> #include "TF1.h"
>> #include "TCanvas.h"
>> #include "TString.h"
>> #include Riostream.h"
>> #include "TGraph.h"
>> #include "TStyle.h"
>> #include "TMath.h"
>>
>>
>>
>>
>>
>> Double_t kTH = -0.5;
>>
>> Double_t Background(Double_t *x, Double_t *par)
>>
>> return
>> par[0]+par[1]*x+par[2]*x[0]*x[0];
>>
>> }
>>
>> Double_t Gaussian(Double_t *x, Double_t *par)
>>
>> {
>> return
>> par[0]*TMath::Exp(kTH*((x-par[1])/par[2])*((x-par[1])/par[2]));
>> }
>>
>> {
>>
>>
>>
>> Double_t fitfunction(Double_t
>> *x, Double_t *par)
>>
>> {
>> Double_t tot = Background(x,par) +
>> Gaussian(x,&par[3]);
>> return tot;
>>
>> }
>>
>> void fittingDemo()
>> {
>> int nBins = 50;
>> Stat_t data[nBins] =
>> {332,301,347,381,372,400,399,433,420,403,476,468,464,493,501,528,
>> 577,646,687,759,875,903,1044,1183,1146,1106,
>> 1152,1103,1126,975,875,820,738,746,677,695,655,645,621,621,594,600,609,584,615,$TH1F
>>
>> *histo = new TH1F("assignment","Gaussian Peak on a
>> smooth
>> background",50,0,3);
>>
>> for (int i = 0.5;
>> i<nBins;i+0.05){
>>
>> histo->SetBinContent(i,data[i]);
>> histo->SetBinError(i,TMath::Sqrt(data[i]));
>> }
>>
>> TF1 *fitFcn = new
>> TF1("fitFcn","fitFunction",0,3,6);
>> histo->Fit("fitFcn");
>>
>> }
>>
>> Thank you.
>>
>>
>>
>> Mushtari Afroz
>> Hons. BSc. Program
>> Trinity College, University of Toronto
>> Toronto, Canada.
>>
>>
>>
>> __________________________________________________
>> Do You Yahoo!?
>> Tired of spam? Yahoo! Mail has the best spam protection around
>> http://mail.yahoo.com

> Received on Wed Sep 20 2006 - 10:23:46 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:01 MET