Re: Creating and Filling Many Histogram

From: zaldy <zaldy_at_neutrino.kek.jp>
Date: Sat, 12 Feb 2005 17:44:48 +0900 (JST)

Dear Rene,

Still not successful even for the simple line as below. Thanks....

void test_scrip()
{
  const int nb = 34;
  float a=-170.;
  float b=170.;

  TH1F* histo_xvsz_front[nb];
  histo_xvsz_front[1] = new TH1F(Form("histo_xvsz_front_001"), Form("Histogram xvsz_front_1"), nb,a,b); }

Error Message:

Processing test_scrip.C...
Limitation: Variable argument is not supported for this platform FILE:test_scrip.C LINE:8
*** Interpreter error recovered ***

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

//---------------------------------------

> Replace
> for(Int_t i = 1; i <= nb; i++)
> by
> for(Int_t i = 0; i < nb; i++)
>
> Rene Brun
>
> On Sat, 12 Feb 2005, zaldy wrote:
>
> >
> > Hi,
> >
> > What is wrong with this piece of code
> >
> > //--------------------------------
> > void test()
> > {
> > const int nb = 34;
> > float a=-170.;
> > float b=170.;
> >
> > TH1F* histo_xvsz_front[nb];
> > for(Int_t i = 1; i <= nb; i++)
> > {
> > histo_xvsz_front[i] = new TH1F(Form("histo_xvsz_front_%03d",i),Form("Histogram xvsz_front #%d",i), nb,a,b);
> > }
> >
> > }
> >
> > Thanks
> >
> > using RootVersion 4.02/00 29 January 2005
> > on gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
> >
> > //----------------------------
> >
> > > Hi Zaldy,
> > >
> > > zaldy <zaldy_at_neutrino.kek.jp> writes:
> > >
> > > > 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) = .....
> > > > }
> > >
> > > First, you need square brackets for array dereferencing in C++.
> > >
> > > TH1F * histo_[i] = .....
> > >
> > > As for a sequence of similar histograms I often do things like:
> > >
> > >
> > > const int n=100;
> > > TH1F* histo[n];
> > > for(Int_t i=1; i<n; i++)
> > > {
> > > TH1F * histo[i] = new TH1F(Form("name_%03d",i),Form("Histogram #%d",i),...);
> > > }
> > >
> > > If you don't actually care about the name and will always refer to the
> > > histogram via the pointer then you don't need a unique name but you
> > > need to call SetDirectory(0):
> > >
> > > const int n=100;
> > > TH1F* histo[n];
> > > for(Int_t i=1; i<n; i++)
> > > {
> > > TH1F * histo[i] = new TH1F("blah","Blah Blah",...);
> > > histo[i]->SetDirectory(0);
> > > }
> > >
> > >
> > > Luck,
> > > -Brett.
> > >
> >
> >
>
-- 
Zaldy A. Nawang
Received on Sat Feb 12 2005 - 09:38:35 MET

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