Hi Zhou, While this doesn't answer your path question, I believe you can get the behaviour you want by doing the nt1->Project without first changing directories. You would first have to modify declare the nt1 variable. This is what I find quite useful about ROOT -- you can declare your object and pass it around to different routines, not worrying about if you are in the same directory as the object (Ntuple in this case). Rene, perhaps a variation on TTree::Project that takes the pointer to a TH1 or TH2 object would be useful? You might want to try: { TFile* f = new TFile("data.root"); TNtuple *nt1 = (TNtuple *)f->Get("nt1"); // Added to declare nt1 f->mkdir("analysis");// make a subdirectory to hold the result f->cd("analysis"); // change to the created subdirectory TH1F* p1 = TH1F("h1","h1",100, 0., 120.); //create some result histograms TH1F* p2 = TH1F("h2","h2",100, 0., 1000.); TH1F* p3 = TH1F("h3","h3",100, 0., 10.); // gFile->cd(); // go back to the top directory // Not needed nt1->Project("h1","t0"); //fill the histogram in the subdirectory } Take care. /*************************************************** * Robert Feuerbach feuerbac@ernest.phys.cmu.edu * * CMU Physics Department (412) 268-2772 * * Pittsburgh, PA 15213 FAX: (412) 681-0648 * ***************************************************/ On Mon, 12 Jun 2000, Zhou Zhang wrote: > Hi rooters, > > I have a root file which contains some ntuples. Now I want to write a > macro to do some analysis on these ntuples and put the results which are > also some histograms and ntuples under a created analysis subdirectory > which are associated with the root file. My macro is such as: > { > TFile* f = new TFile("data.root"); > > f->mkdir("analysis");// make a subdirectory to hold the result > > f->cd("analysis"); // change to the created subdirectory > > TH1F* p1 = TH1F("h1","h1",100, 0., 120.); //create some result histograms > TH1F* p2 = TH1F("h2","h2",100, 0., 1000.); > TH1F* p3 = TH1F("h3","h3",100, 0., 10.); > > gFile->cd(); // go back to the top directory > nt1->Project("h1","t0"); //fill the histogram in the subdirectory > > } > > It failed because h1 is not in the current directory. But I don't know how > to specify the path for the h1. Who could tell me how to do it? > > regards, > > zhou > >
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:27 MET