Re: Creating and Filling Many Histogram

From: Dean Andrew Hidas <dhidas_at_fnal.gov>
Date: Wed, 2 Feb 2005 21:34:06 -0600

I've had the same thing come up and used something like:

#include <vector>
#include <sstream>
#include "TH1F.h"

int main ()
{

  std::vector<TH1F*> histo;

  int n = 1234;

  histo.resize(n);

  std::ostringstream name;
  for (int i=0; i != n; ++i)
  {
    name.str("");
    name << "histo_" << i;
    histo[i] = new TH1F(name.str().c_str(), name.str().c_str(), 10, 0, 10);   }

  return 0;
}

then each can be filled via:

histo[i]->Fill(2);

hope that helps...

cheers,

-Dean

Dear Root Experts,

I have two questions.
I would like to create many histogram simultaneously with names of the form: histo_1, histo_2, .... , histo_(i) where i=1,2,3,4,....,n.

I figure out doing it like this:

  for(Int_t i=1; i<n; i++)
  {
    TH1F * histo_(i) = .....
  }

But this method does not simply work here.

  1. How do we give names to the histogram?
  2. How do we fill this histogram? ( histo_(i)->Fill(.....);)

Naming the histogram something like:

  char histo_name[100];
  for(Int_t i=1; i<n; i++)
  {
   sprintf(histo_name,"histo_%d",i);
   TH1F * histo_(i) =....
  }

But it does not simply work.   

Any Hint how to do this?
Thanks

-- 
Zaldy A. Nawang

PS,
Using Version   4.02/00   29 January 2005 on 
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)


----- End forwarded message -----

-- 
Dean Andrew Hidas                   Office: 630 840-2324
dhidas_at_fnal.gov                     Mobile: 626 379-2160
Received on Thu Feb 03 2005 - 04:34:14 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:04 MET