[ROOT] one way to avoid pointer-to-member-function with TF1

From: Dr. John Krane (jkrane@fnal.gov)
Date: Tue Jul 22 2003 - 20:46:18 MEST


Hi everyone,

Just thought I'd let you know that I just declared my fitting class 
outside the body of my macro, along with a simple dummy function:

//define my fitting class out here
func_fit fclass;

//this is just an interface to class func_fit
Double_t dummy_func(Double_t *x, Double_t *par) {
  return fclass.func_val(x,par);
}

void jgo() {
...all my code...assign histograms to fclass, etc...
  //play shell game with dummy_func
  TF1 *fitFcn = new TF1("fitFcn",dummy_func,-600.,-1.,fclass.get_nparam());
  myhisto->Fit("fitFcn","V+","ep");
}

It seems to be working...

    - John

Dr. John Krane wrote:

> Hi Philippe,
>
> The owner is a modified version of MakeClass, that is generic enough 
> to read branches/variables from nearly-identical trees.  Although I at 
> first tried to mimic the destructor with
>
> delete fChain->GetCurrentFile();
>
> as you suggest, this didn't work so I tried numerous other things with 
> poor results.  You see, with the above solution, I still have what 
> appears to be the old files in the TBrowser, but they are just the 
> branches I actually used in the code, not the branches I didn't use. 
> All branches are empty.
>
> If the branches need to be "freed" one by one, shouldn't this be in 
> the default destructor for MakeClass?  Yet it is not.  (I assumed, 
> with all dangers of assuming, that there existed a well-known way of 
> closing the file and associated objects that I just didn't know about...)
>
>     - John
>
> Philippe Canal wrote:
>
>> Hi John,
>>
>> It all depends on how you allocated the TFile containing the TTree.
>>
>> A guess would be that you should replace
>>     fChain->Delete();
>> by
>>     delete fChain;
>>
>> You may also have to do:
>>     if (fChain) delete fChain->GetCurrentFile();
>>
>> But both are wild guesses :) ... The bottom line is that you have to 
>> insure
>> that the 'owner' of the file of the tree closes and delete its file.
>>
>> Cheers,
>> Philippe.
>>
>> -----Original Message-----
>> From: owner-roottalk@pcroot.cern.ch
>> [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Dr. John Krane
>> Sent: Thursday, July 17, 2003 4:36 PM
>> To: roottalk@pcroot.cern.ch
>> Subject: [ROOT] closing TTree files
>>
>>
>> Hi,
>>
>> I want to open a Tree, loop over it creating histograms, close the histo
>> file, close the Tree.  Without leaving Root, I want to repeat the entire
>> process with a different Tree and make a separate histo file.
>>
>> I have most of what I need I think, but I don't know how to close the
>> Tree when I'm done with it.  I do:
>>
>>     // Write histos to disk.  Close all files.
>>     histofile->Write();
>>     histofile->Close();
>>     delete histofile;
>>
>>     fChain->Delete();
>>
>> And this works as I expect with the histofile but not with the Tree.  I
>> get through my loop twice and then seg fault.  When I check the
>> TBrowser, I see both the first and second trees in there, which would
>> cause a seg fault in my code all right.  Can anybody tell me how to get
>> rid of the first Tree?
>>
>>     - John
>>
>>
>>
>
>



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:13 MET