# Re: Using Parameters in TTreeFormula's?

From: Lorenzo Moneta <Lorenzo.Moneta_at_cern.ch>
Date: Fri, 13 Oct 2006 22:29:40 +0200

Unbinned fit requires probability density functions which must be normalized, otherwise CANNOT converge.
If I have understood well you need a multidimensional least square fit using the Tree data.
At the moment I think you can do this only by using the TVirtualFitter and writing the least square (or chi square) function yourself.
Best Regards,
Lorenzo
On 13 Oct 2006, at 21:24, Robert Feuerbach wrote:

>
> On Fri, 13 Oct 2006, Philippe Canal wrote:
>
>>> T->UnbinnedFit("myf","preshowerE:showerE","(preshowerE>450.)
>>> *electronP");
>>> does not help either.
>>
>> How does it fail?
>
> It does not find the optimum, and instead wanders off to
> infinity. This is probably because the function "myf" is not
> normalized (it is not a probability distribution). Below is a
> very simplified but self-contained test case with which to
> experiment.
>
> UnbinnedFit as written really seems to be for a different
> problem, involving EVENT distributions not variable correlations.
> Just like when one is looking to fit the correlation between TWO
> variables, we typically make a 2-D histogram, then using either
> ProfileX() or FitSlicesY() make a 1-D histogram that can be
> simply fit.
>
> Thanks,
> Rob Feuerbach
>
>
> #ifndef __CINT__
>
> #include "TTree.h"
> #include "TFile.h"
> #include "TRandom.h"
> #include "TF2.h"
>
> #include <iostream>
> using namespace std;
>
> #endif
>
> TTree *tree = 0;
> TF2* myf =0;
> void build_tree() {
> struct {
> Float_t psE, shE, elP;
> } data;
>
> TFile *nf = new TFile("testit.root","RECREATE");
> tree = new TTree("T","testing");
> tree->Branch("data",&data,"psE:shE:elP");
> for (int i=0; i<5000; i++) {
> data.psE = gRandom->Uniform(0.,1000.);
> data.shE = gRandom->Uniform(0.,1000.);
> data.elP = .2*data.psE+.5*data.shE;
> data.elP += 20*gRandom->Gaus(); // noise factor
> tree->Fill();
> }
> }
>
> void fit_tree() {
> // now try to fit the tree
> if (!myf) myf = new TF2("myf","[0]*x+[1]*y",0.,3000.,0.,3000.);
> myf->SetParameters(.1,.1);
> tree->UnbinnedFit("myf","psE:shE","elP");
> }
>
> void testit() {
> build_tree();
> fit_tree();
> tree->Draw("elP:.2*psE+.5*shE"); // verify the tree is good
> }
>
>>
>> Cheers,
>> Philippe.
>>
>> PS. We had no plan on addiung support for [0],[1], etc.
>> since the intend api for what you are trying to do is
>> TTree::UnbinnedFit.
>>
>>
>> -----Original Message-----
>> From: Robert Feuerbach [mailto:feuerbac_at_jlab.org]
>> Sent: Thursday, October 12, 2006 9:36 PM
>> To: Philippe Canal
>> Cc: 'Rene Brun'; roottalk_at_pcroot.cern.ch
>> Subject: RE: [ROOT] Using Parameters in TTreeFormula's?
>>
>>
>> Hi Philippe,
>>
>> Thank you for the suggestion. When I try this, this is what
>> happens:
>>
>> analyzer [8] TF2 *myf = new TF2("myf","[0]*x+[1]*y",
>> 0.,3000.,0.,3000.)
>> analyzer [9] myf->SetParameters(.1,.1)
>> analyzer [10]
>> T->UnbinnedFit
>> ("myf","electronP:preshowerE:showerE","preshowerE>450.")
>> Error in <TTreePlayer::UnbinnedFit>: Function dimension=2 not
>> equal to
>> expression dimension=3
>> (Long64_t)0
>>
>> Playing with:
>> T->UnbinnedFit("myf","preshowerE:showerE","(preshowerE>450.)
>> *electronP");
>>
>> does not help either. Doing
>>
>> T->Fit("myf","preshowerE:showerE","(preshowerE>450.)*electronP","W")
>>
>> (ignore the "error bars" on the temporary histogram being fitted)
>> does sort of work as long as the 2-d histogram being created is
>> binned finely enough that no bin contains more than one event.
>>
>> I do have a solution for this case, it would just be nice to be
>> able to have a general solution that is not restricted to a
>> handful of variables and parameters with a somewhat convoluted
>> approach. This is why I'm interested in having the Parameters
>> work in TTreeFormula's.
>>
>> Rob
>>
>>
>>
>> On Thu, 12 Oct 2006, Philippe Canal wrote:
>>
>>> Date: Thu, 12 Oct 2006 16:40:53 -0500
>>> From: Philippe Canal <pcanal_at_fnal.gov>
>>> To: 'Robert Feuerbach' <feuerbac_at_jlab.org>, 'Rene Brun'
>> <Rene.Brun_at_cern.ch>
>>> Subject: RE: [ROOT] Using Parameters in TTreeFormula's?
>>>
>>> Hi Robert,
>>>
>>>> I do NOT want to 'fit' to the population's distribution like the
>>>> example does -- the function I'm trying to use (TF1 or whatever)
>>>> should NOT return something proportional to the number of events
>>>> in a bin/region. Instead, the evaluation is similar to TGraph,
>>>> where the Chi2 function is built directly from the X and Y
>>>> points.
>>>
>>> As far as I know/understand this is __exactly__ (except for
>>> actually creating the intermediary TGraph2D object) what
>>> TTree::UnbinnedFit does ....
>>>
>>> Seriously, it sound that you want you exactly want is:
>>>
>>> TF2 *myf = new TF2("myf","[0]*x+[1]*y",0.,3000.,0.,3000.);
>>> myf->SetParameters(.1,.1);
>>> tree->UnbinnedFit("myf","electronP:preshowerE:showerE",selection);
>>>
>>> Cheers,
>>> Philippe.
>
> /***************************************************
> * Dr. Robert J. Feuerbach feuerbac_at_jlab.org *
> * 12000 Jefferson Avenue CEBAF Center A120 *
> * Suite 4 Office: (757) 269-7254 *
> * Newport News, VA 23606 Page: 584-7254 *
> * Fax: (757) 269-5703 Mailstop 12H3 *
> ***************************************************/
>
Received on Fri Oct 13 2006 - 22:29:53 MEST

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