Re: Input PadHi Folks!

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Mar 02 1998 - 08:56:35 MET


Diego Casadei wrote:
> 
> I'm developing a monitoring software (ok, really I wrote only
> few functions of the software...) and I would like to have a
> way, different from the browser, to select among about 1000
> histograms.
> Actually, I want to fetch all the histograms, stored in a file,
> related to one of the 112 channels of the TOF system for the
> AMS experiment.  These channels have names like "2.05N", i.e.
> Plane.CounterSide.
> I'd like to have one of these possibilities:
> 1) from a menu I select the Plane, getting the Counter sub-menu
>    and finally the Side sub-menu;
> 2) I type "2.05N" in a input pad, and then press "OK".
> 
> I have of course a function that asks the string "2.05N" from
> the  shell and then computes the histograms identifiers, but
> it is not so good.  Usually I'm looking the graphical interface,
> that hides the shell...

You should structure your histograms in a hierarchy using
the built-in mechanism in Root (Class TDirectory/TFile).
The macro below is an example:

Rene Brun

{
// .........................macro dirs.C............................
// This macro illustrates how to create a hierarchy of directories
// in a Root file.
// 10 directories called plane0, plane1, plane9 are created.
// Each plane directory contains 200 histograms.
// The hierarchy can be browsed by the Root browser as shown below
//   Root > TBrowser b;
//    click on the left pane on one of the plane directories.
//    this shows the list of all histograms in this directory.
//    Double click on one histogram to draw it (left mouse button).
//    Select different options with the right mouse button.
//
//    Instead of using the browser, you can also do:
//   Root > top->cd();
//   Root > plane3->cd();
//   Root > h3_90N->Draw();

   gROOT->Reset();

    // create a new Root file
   TFile *top = new TFile("top.root","recreate");

   // create a subdirectory "tof" in this file
   TDirectory *cdtof = top->mkdir("tof");
   cdtof->cd();    // make the "tof" directory the current directory

   // create a new subdirectory for each plane
   const Int_t nplanes = 10;
   const Int_t ncounters = 100;
   char dirname[50];
   char hname[20];
   char htitle[80];
   for (Int_t i=0;i<nplanes;i++) {
      sprintf(dirname,"plane%d",i);
      TDirectory *cdplane = cdtof->mkdir(dirname);
      cdplane->cd();
      // create counter histograms
      for (Int_t j=0;j<ncounters;j++) {
         sprintf(hname,"h%d_%dN",i,j);
         sprintf(htitle,"hist for counter:%d in plane:%d North",j,i);
         TH1F *hn = new TH1F(hname,htitle,100,0,100);
         sprintf(hname,"h%d_%dS",i,j);
         sprintf(htitle,"hist for counter:%d in plane:%d South",j,i);
         TH1F *hs = new TH1F(hname,htitle,100,0,100);
      }
      cdtof->cd();    // change current directory to top
   }

     // .. fill histograms

     // save histogram hierarchy in the file
   top->Write();
   delete top;
}



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:30 MET