Re: Problem fitting histos

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Thu, 26 Jan 2012 10:21:48 -0600


Hi Francesco,

Indeed in addition to the name you need title and number of bins and an indicator that the range should be calculated.

    new TH1F("histo","title",100,0,0)

Rather than:

    TFile *_file0 = TFile::Open("/data/singlepe/Run000470.root");     TTree *tv__tree = (TTree *) gROOT->FindObject("Events");

I recommend:

    TFile *_file0 = TFile::Open("/data/singlepe/Run000470.root");     TTree *tv__tree; _file0->GetObject("Events",tv_tree);

that more explicitly express you intent.

Cheers,
Philippe.

On 1/26/12 2:37 AM, perfetto_at_na.infn.it wrote:
> Hi Philippe,
>
> thanks for your replay, but don't work, now when run the script I got the
> following error:
>
> Error: Can't call TH1D::TH1D("histo") in current scope auto_lin.C:18:
> Possible candidates are...
> (in TH1D)
> /cern/root-5.26/lib/libHist.so -1:-1 0 public: TH1D TH1D::TH1D(void);
> /cern/root-5.26/lib/libHist.so -1:-1 0 public: TH1D TH1D::TH1D(const
> char* name,const char* title,Int_t nbinsx,Double_t xlow,Double_t xup);
> /cern/root-5.26/lib/libHist.so -1:-1 0 public: TH1D TH1D::TH1D(const
> char* name,const char* title,Int_t nbinsx,const Float_t* xbins);
> /cern/root-5.26/lib/libHist.so -1:-1 0 public: TH1D TH1D::TH1D(const
> char* name,const char* title,Int_t nbinsx,const Double_t* xbins);
> /cern/root-5.26/lib/libHist.so -1:-1 0 public: TH1D TH1D::TH1D(const
> TVectorD& v);
> /cern/root-5.26/lib/libHist.so -1:-1 0 public: TH1D TH1D::TH1D(const
> TH1D& h1d);
> (in TH1)
> *** Interpreter error recovered ***
>
> Francesco.
>
>> Hi,
>>
>> Try with:
>>
>> TH1D *histo = new TH1D("histo"); //<------ I don't put bin and range
>> because
>>
>> The 'name' is required for the use by TTree::Draw.
>>
>> Philippe.
>>
>> On 1/25/12 11:48 AM, perfetto_at_na.infn.it wrote:
>>> Hi All,
>>>
>>> I don't be able to fitting and save some variables of a tree that I put
>>> in
>>> a histo.
>>> The following the part of my code that should do this... But when I run
>>> it:
>>>
>>> .L Fit.C
>>> fit_peak()
>>>
>>> I got the following result:
>>> <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
>>> Warning in<Fit>: Fit data is empty
>>> 0
>>> Warning in<Fit>: Fit data is empty
>>> 0
>>> Warning in<Fit>: Fit data is empty
>>> 0
>>> Warning in<Fit>: Fit data is empty
>>> 0
>>>
>>> and ROOT open an empty canvas.
>>> Is there anyone can help me ?
>>>
>>> I use ROOT 5.26/00 on Scientific Linux 5
>>>
>>> Thanks in advance
>>> Francesco.
>>>
>>> #include<iostream>
>>> #include<fstream>
>>> #include<iomanip>
>>> #include<TH1>
>>>
>>> void fit_peak() {
>>>
>>> ofstream out;
>>> ...
>>> TFile *_file0 = TFile::Open("/data/singlepe/Run000470.root");
>>>
>>> TTree *tv__tree = (TTree *) gROOT->FindObject("Events");
>>>
>>> Double_t res_fit;
>>> TF1 *f = new TF1("f","gaus");
>>>
>>> for (Int_t i = 0; i< 4; i++) {
>>> TH1D *histo = new TH1D(); //<------ I don't put bin and range
>>> because
>>> I do not know in
>>> what
>>> range
>>> the
>>> histo
>>> lives.
>>>
>>> tv__tree->Draw( Form("-channels[%d].regions[0].integral>> histo",
>>> i)
>>> );
>>>
>>> histo->Fit(f);
>>>
>>> res_fit = f->GetParameter(i);
>>>
>>>
>>> out.open("result_fit_from_to.txt", ios::out | ios::app);
>>>
>>> out<< setw(8)<< setprecision(5)<< f->GetParameter(1);
>>> out<< setw(8)<< setprecision(5)<< f->GetParameter(2);
>>> out<< setw(8)<< setprecision(5)<< f->GetParameter(3);
>>> out<< endl;
>>>
>>> out.close();
>>> histo->Delete();
>>> }
>>> ....
>>> ....
>>> }
>>>
>>>
>>>
>>>
>>
>
Received on Thu Jan 26 2012 - 17:22:49 CET

This archive was generated by hypermail 2.2.0 : Thu Jan 26 2012 - 23:50:01 CET