Hi Philippe,
Thank you for your indulgence, but from what I have seen in the examples and my understanding of using TF1, what UnbinnedFit does is fit a 'distribution' of events, not the relation between different variables in the tree. If I am wrong, please point me to an example of fitting the relation between two or more tree variables.
For now, for my specialized case, if TTreeFormula's Parameters worked similarly to TFormula, I'm following the minexam.cxx example and using my own fcnk0( ) which has to be modified by hand for every case.
As for an implementation of the 'Minimize' method/routine, it would be something like what is below.
Take care,
Rob Feuerbach
///////////////////////////////////////////////////////////////////
// NON-WORKING CODE -- DO NOT USE !!!!
//
// Would be a general Minimize method for correlations between
// tree variables BUT TTreeFormula's do not have working
// parameters. Based on minexam.cxx
// R.J. Feuerbach 2006
// global variables to pass between fnck0 and Minimize
TTreeFormula *express=0;
TTree *tree=0;
void fcnk0(int &, double *, double &f, double *x, int iflag) {
f = 0;
if (!tree || !express) return;
express->SetParameters(x);
Long64_t *lst = 0;
Long64_t nev=tree->GetEntries();
TEventList *ev = tree->GetEventList();
if (ev) {
lst = ev->GetList();
nev = ev->GetN();
}
for (Long64_t i=0; i<nev; i++) {
tree->GetEntry( (lst ? lst[i] : i ) );
// assuming a 1-dimensional expression
Double_t ex = express->EvalInstance();
f += ex;
}
return;
}
Int_t Minimize(TTree *t, const char* varexp,
const char *select, Double_t *parms) {
{
// take the expression 'varexp' and minimize it, // varying the listed parameters. // the parameters must be initialized.tree = t;
if (select && strlen(select)) {
tree->Draw(">>elist",select);
tree->SetEventList((TEventList*)gDirectory->Get("elist"));
}
// to speed things up, have only the needed branches on
tree->SetBranchStatus("*",0);
for (int i=0; i<express->GetNcodes(); i++) {
TLeaf *lf = express->GetLeaf(i);
if (lf) tree->SetBranchStatus(lf->GetBranch()->GetName(),1);
}
Int_t npar = express->GetNpar();
TVirtualFitter *minuit = TVirtualFitter::Fitter(0,npar);
minuit->SetFCN(fcnk0);
for (int i=0; i<npar; i++) {
minuit->SetParameter(i,Form("%d",i),parms[i],.1,0,0);
}
Double_t arglist[100];
arglist[0]=0;
minuit->ExecuteCommand("SET PRINT", arglist,1);
minuit->ExecuteCommand("MIGRAD", arglist,0);
for (int i=0; i<npar; i++) {
parms[i] = minuit->GetParameter(i);
}
// clean up and turn all branches back on
delete express;
tree->SetBranchStatus("*",1);
}
// called as
Double_t parms[2] = { .1, .1};
Minimize(T,"(electronP-([0]*preshowerE+[1]*showerE))**2","",parms);
////////////
On Wed, 11 Oct 2006, Philippe Canal wrote:
> Date: Wed, 11 Oct 2006 15:56:08 -0500 > From: Philippe Canal <pcanal_at_fnal.gov> > To: 'Robert Feuerbach' <feuerbac_at_jlab.org>, 'Rene Brun' <Rene.Brun_at_cern.ch> > Cc: roottalk_at_pcroot.cern.ch > Subject: RE: [ROOT] Using Parameters in TTreeFormula's? > > Hi Robert, > > What you are looking for really seems to be exactly TTree::UnbinnedFit. > Why is that function not appropriate? > > > This is a very easy routine or method to write for the general case ... > > Out of curiosity, what would it look like? > > 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 Wed Oct 11 2006 - 23:35:45 MEST
This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:01 MET