Transferring objects from file to file

I have several histograms on a .root file that I would like to rename and transfer to another file. However, once I get them in memory, I have to change directories to open the destination file, and so I can no longer access them until I change directories back. Is there some way to do this?

Grab their addresses explicitly:TH1 *h; myfile->GetObject("myhisto_1",h);


I couldn’t get that to work, although my problem has actually just changed. Instead, now I just want to write objects in the memory to the file. However, the same problem with scope occurs: as soon as I open the file, the objects in the memory become inaccessible.

For example:

root [] selectKKK myObject;
root [] myObject.Loop(); //Creates histograms h_KKKs_bDeltaE_cut, h_KKKs_bmES_cut, and h_KKKs_bbRoeThrustCos_cut
root [] TFile f1(“KKKs.root”,“UPDATE”); //Open the existing file
root [] h_KKKs_bDeltaE_cut->Write();

And then it generates an error that h_KKKs_bDeltaE_cut is not in the current scope.

Assuming that you add a pointer to those histogram to your selector object. I suppose you can simply do:

[quote]I couldn’t get that to work[/quote]Most likely you were not looking those histogram in the ‘correct’ TFile object.