Re: Replacing existing histogram

From: <monika_at_rcf.rhic.bnl.gov>
Date: Tue, 11 Oct 2005 05:15:53 -0400 (EDT)

Hi! Axel,

I tried it but I think I am still making some mistake. This is how I am implementing those two statements in my code :

##########################################################################

  char hname_iso[120];
  char htitle1[120];
  Int_t niso;
  TObject* old=gDirectory->GetList()->FindObject(hadc_iso);   gDirectory->GetList()->Remove(old);

  TH1F *hadc_iso1 = new TH1F[300000];

  //// Booking Histograms for all cells

  for(Int_t i1=12; i1<kmaxsm;i1++) {
    for(Int_t j1=0; j1<kmaxrow;j1++) {

      for(Int_t k1=0; k1<kmaxcol;k1++) {
        niso =  (i1*10000) + j1*100 + k1;
        sprintf(hname_iso,"hadc_iso1%d",niso);
        sprintf(htitle1,"Isolated Cell ADC for cell%d",niso);
        hadc_iso1[niso] = new     
TH1F(Form("hname_iso%d",i1),htitle1,1000,0.,4000.);
      }

    }
  }
############################################################################

But now my program doesn't compile. ROOT complains about TObject* old=gDirectory->GetList()->FindObject(hadc_iso); hadc_iso was the pointer to TH1F class, so I want to delete it and create a new histogram. I am not sure about how to implement it in the code.

Thanks very much.
Regards
Monika

> Hi Monika,
> see e.g. http://root.cern.ch/phpBB2/viewtopic.php?t=2518
> Cheers, Axel.
>
> monika_at_rcf.rhic.bnl.gov wrote:
>> Hi Rooter!,
>>
>> I have an array of 1D histograms and whenever I run the program it says
>> :
>>
>> Warning in <TH1::Build>: Replacing existing histogram: h1_[array_#]
>> (Potential memory leak).
>>
>> Since I have 300K histograms, it writes the warning this many number of
>> times. Can I somehow get rid of the warning.
>>
>> I am also writing my peace of code here :
>>
>> ###################################################################
>> char hname1;
>> char htitle1;
>> Int_t niso;
>> TH1F *h1 = new TH1F[300000];
>>
>> for(Int_t i1=12; i1<kmaxsm;i1++) {
>> for(Int_t j1=0; j1<kmaxrow;j1++) {
>> for(Int_t k1=0; k1<kmaxcol;k1++) {
>> niso = (i1*10000) + j1*100 + k1;
>> sprintf(hname1,"h1%d",niso);
>> sprintf(htitle1,"%d",niso);
>> h1[niso] = new TH1F(hname1,htitle1,1000,0.,4000.);
>> }
>> }
>> }
>> #####################################################################
>>
>> I'll appreciate any help.
>>
>> Thanks
>> Monika
>>
>
Received on Tue Oct 11 2005 - 11:16:11 MEST

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