Re: Re: Problem with CloneTree

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Sat, 17 Sep 2011 14:37:55 -0500


> but for our analysis I need to use the Loop() function
> in MakeClass() (furthermore I do not understand how to use MakeProxy)

If you case is such that you can not migrate from using the Loop mechanism offered by MakeClass to the TSelector mechansim supported by MakeProxy, you will need to replace the variable by hand with the original objects (so that you can remove the call to SetMakeClass).

Or, as you tried, you can use a 2nd copy of the input files and to fix your code, you just need to actually read the data from the duplicate input file by adding to the inner loop:

       oldtree->GetEntry(jentry);

Of course, the disadvantage is you are reading the data twice (once via fChain->GetChain and once via oldtree->GetEntry. Also it will be a bit harder to extend this to support more than one input file.

I attached the 2 files needs to use MakeProxy. You can use it in any of the following 3 ways:

   TFile *_file0 = TFile::Open("run3008.root");    Events->Draw("analysis_proxy_fra.C+" );

or

   TFile *_file0 = TFile::Open("analisi.root");    Events->MakeProxy("runselector","analysis_proxy_fra.C"); // Need to be done only once.

and

   TFile *_file0 = TFile::Open("analisi.root");    Events->Process("runselector.h+");

or

   TFile *_file0 = TFile::Open("analisi.root");    .L runselector.h+
   runselector s;
   Events->Process(&s,"",100)

Cheers,
Philippe.

On 9/17/11 11:21 AM, perfetto_at_na.infn.it wrote:
> Hi Philippe,
>
> thanks for your reply, I understand that I can't use CloneTree() when I
> using MakeClass(), but for our analysis I need to use the Loop() function
> in MakeClass() (furthermore I do not understand how to use MakeProxy), can
> you suggest a way to solve the problem without that I must to put (to add)
> each variable of the original tree manually in the code ?
>
> Thanks again.
>
> Cheers
> Francesco.
>
> P.S. Why in the new file I write: analisi.root, when I open it I found
> three tree Events: Events;11, Events;12, Events;13 ? ( moreover the two
> tree ;12 and ;13, have 47520 entries while Events;11 has 46145 entries)
>
>> Hi Francesco,
>>
>> Copying a TTree that has been set in MakeClass mode is not supported at
>> the moment.
>>
>> You would need to either load the shared library defining the class
>> EventData or
>> use MakeProxy insted of MakeClass.
>>
>> Cheers,
>> Philippe.
>>
>>> On 16/09/2011 09:33, perfetto_at_na.infn.it wrote:
>>>> Hi Rooters,
>>>>
>>>> I have the following problem (I use root 5.30/01 on osx):
>>>>
>>>> Using MakeClass I have had 2 files, .C and a .h.
>>>> Now in the .C within the Loop() function, I open a root file, get the
>>>> tree, open a new file and in this new file I clone it.
>>>> After I create other variables that I would add to this new file; but
>>>> after the Fill() command, my new tree has the double of entries.
>>>> Where do I do a mistake ?
>>>>
>>>> For clarity I attach a piece of code:
>>>>
>>>>
>>>> void analysis_fra::Loop()
>>>> {
>>>> if (fChain == 0) return;
>>>>
>>>> Long64_t nentries = fChain->GetEntriesFast();
>>>>
>>>> Long64_t nbytes = 0, nb = 0;
>>>>
>>>> Double_t sum_min;
>>>> Bool_t is_cut;
>>>> Int_t n_pmt;
>>>>
>>>> TFile *oldfile = new TFile("run3008.root");<------- In this file
>>>> there
>>>> are 23760 entries
>>>> TTree *oldtree = (TTree*) oldfile->Get("Events");
>>>> TFile *newfile = new TFile("analisi.root","recreate");
>>>> TTree *newtree = oldtree->CloneTree();
>>>>
>>>> // Some variables that I would add to newtree
>>>> newtree->Branch("sum_min",&sum_min, "sum_min/D");
>>>> newtree->Branch("run_id",&run_id, "run_id/I");
>>>> newtree->Branch("is_cut",&is_cut, "is_cut/B");
>>>> newtree->Branch("n_pmt",&n_pmt, "n_pmt/I");
>>>> ....
>>>>
>>>> for (Long64_t jentry=0; jentry<nentries;jentry++) {
>>>> ...
>>>> sum_min = 0.;
>>>> n_pmt = 0;
>>>> for ( Int_t i = 0; i< 35; i++ ) {
>>>> if (channels_npulses[i]> 0) {
>>>> is_cut = kTRUE;
>>>> sum_min = sum_min - channels_minimum[i] + channels_baseline_mean[i];
>>>> n_pmt
>>>> = n_pmt + 1;
>>>> ...
>>>> }
>>>> }
>>>>
>>>> newtree->Fill();<------- If I comment this line I have the correct
>>>> entries 23760, but obviously I don't have the new variables in the
>>>> tree. }
>>>> newtree->Write();
>>>> newfile->Write();
>>>> newfile->Close();
>>>> delete oldfile;
>>>> delete newfile;
>>>> }
>>>> When open newtree this has 47520 entries.
>>>>
>>>> Thank in advance
>>>> Francesco.
>>>>
>>>>
>>>>
>>
>

Received on Sat Sep 17 2011 - 21:38:04 CEST

This archive was generated by hypermail 2.2.0 : Sun Sep 18 2011 - 23:50:02 CEST