RE: [ROOT] lost histos??

From: Philippe Canal (pcanal@fnal.gov)
Date: Tue Jan 15 2002 - 21:04:44 MET


Hi,

The short answer is: check out the functionality of TDirectory::cd.

More specifically, you probably want to something like:

	file1 = new TFile("mainhisto.root","RECREATE");
	TH1F * h0 = new TH1F("h0",....);
	file2 = new TFile("secondary.root","RECREATE");
	TH1F * h1 = new TH1F("h1",...);
	file1->cd();
	TH1F * h2 = new TH1F("h2",...);

In this example, h0 and h2 will be in the file mainhisto while
h1 is in the file secondary.

Also since I created the pointer variable h0,h1,h2 I can access
the histograms until I actually close the file (independantly of
which file was created last or cd'ed to).

I suspect that you might also be relying on the facility of
the ROOT command line that let it load/created the object
automatically.  This is not a good thing if you are inside
a script and thus should strive to write your code as standard
C++ (Using ACLiC to quickly check the syntax).

Anyway, on the command line you can automatically retrieve/access
object in the current ROOT directory.  Use TDirectory::cd to force
a specific directory as the current directory.
For example:

	file1 = new TFile("mainhisto.root","READ");
	... here the object in mainhisto are available ....
	file2 = new TFile("secondary.root","READ");
	... here the object in secondary are available ....
	file1->cd()
	... here the object in mainhisto are available ....

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Ahmet Sedat Ayan
Sent: Tuesday, January 15, 2002 10:17 AM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] lost histos??



Hi All,
my question is the following:

I read an ntuple (root) file and create many histograms 
e.g.
........
  OBJ: TH1F     h0  L> 3.5 : 0
  OBJ: TH1F     h1  L> 4. : 0
  OBJ: TH1F     h2  L> 5. : 0
etc..
 ......

I would like to write two of these historgrams in different files (one
histogram in one file). But when I create a file, say f1.root, to write h1
, I can not access the other histos anymore. I understand that when I
create the f1.root , current directory becomes this file but i do not know
how to go back to the directory in which I couls list and see all other
histograms, objects etc as shown above...

I would appreciate any comments and helps...

Thanks,
Ahmet

ROOT versions: 3.01/06 on SunSparc

***************

Ahmet Sedat Ayan		

Physics & Astronomy Dept.
Van Allen Hall    
University of Iowa
Iowa City, IA, 52242
  
Voice      : (++ 1 319) 335-1941 (W) (GMT-6)      
Occupation : Ph.D Candidate (But still dreamer!)	
e-mail     : ayan@cms.physics.uiowa.edu
web        : http://jazz.physics.uiowa.edu/~ayan



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:38 MET