[ROOT] Tree analysis

From: Bernhard Ketzer (Bernhard.Ketzer@cern.ch)
Date: Fri Oct 13 2000 - 10:35:48 MEST


Hi Rooters,

I created a tree with two branches, each containing several arrays of
floats and ints. In order to loop over the entries, I used MakeClass to
create the skeleton analysis class (->Hits.C, Hits.h). Now instead of
opening each ROOT file by hand and typing 
	Root > .L Hits.C
      	Root > Hits t
      	Root > t.GetEntry(12); // Fill t data members with entry number
12
      	Root > t.Show();       // Show values of entry 12
      	Root > t.Show(16);     // Read and show values of entry 16
      	Root > t.Loop();       // Loop on all entries,
I wrote a little macro (analHits.C) to do that, which I append to this
mail. The methods Hcreate and Hplot were added to the skeleton Hits.C to
create and plot some histograms. 

However, I ran into two problems:

1. The Histograms are plotted on a canvas, which, however, gets cleared
immediately after the macro exits. I understand that this is due to the
loacl scope of the histograms created within Hits.C, but is there a way
of saving them to the global scope? 

2. The macro runs without problems the first time it is executed, but
the second time I do it, I get an error message like
>>>>Function analHits() busy. loaded after 
>>>>"/afs/cern.ch/user/k/ketzer/compass/2000/analysis/./Hits.C"
>>>>Error: G__unloadfile() Can not unload 
>>>>"/afs/cern.ch/user/k/ketzer/compass/2000/analysis/./Hits.C", file busy  
>>>>FILE:analHits.C LINE:11
Do I really have to type .U Hits.C before I reexecute the macro?

Any help would be greatly appreciated.

Cheers,

Bernhard

-- 
-----------------------------------------------------------------------------
Bernhard Ketzer                       Tel.: +41 22 76-76002  FAX: -77100
CERN, EP Division                     GSM : +41 79 201 4404 (CERN
164404)   
CH-1211 Geneve 23                     Email: Bernhard.Ketzer@cern.ch

#include <iostream>
#include "TString.h"

int analHits(int run=125, TString module="DGEM2", 
	     TString dir="/shift/pccodt07/data01/compass/gem/hist") {
  
  // Reset ROOT
  gROOT->Reset();

  // Load Hits.C class
  gROOT->LoadMacro("Hits.C");

  // Graphics setup
  TCanvas *c0 = new TCanvas("c0","c0",100,20,700,700);

  // Construct file name
  char runstr[3];
  sprintf(runstr, "%d", run);
  TString fileName = dir;
  fileName = fileName + "/run_" + runstr + "_001.root";

  // Open file, if not already loaded
  TFile *file = (TFile *)gROOT->GetListOfFiles()->
    FindObject((const char *)fileName);
  if (!file) {
    file = new TFile((const char *)fileName);
    file->cd((const char *)module);
  }

  // Read tree named "Hits" in memory
  TTree *T = (TTree*)gDirectory->Get("Hits");
  
  // Print 
  T->Print();

  // Construct Hits object to loop over events
  Hits h(T);

  // Create histograms
  h.Hcreate();

  // Loop
  h.Loop();
  
  // Plot histograms filled in loop
  h.Hplot();

  // Close file
  //  file->Close();

  // Unload Hits.C
  //  G__unloadfile("Hits.C");
  //  gInterpreter->ProcessLine(".U Hits.C");

  return 0;
}



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:35 MET