Table of histograms

Hello,

I am sure this question was asked several times but I did not find the answer in the FAQ.

I create a table of histograms, the creation is performed inside a loop. At a first passage in the loop, everything is fine but then the macor execution stops with the following message:

[color=#FF0000]Error: Illegal pointer operation (letvalue) displaycrystals_cluster3x3.C:98:
*** Interpreter error recovered *[/color]

It looks like there is an allocation of memory I did not make free, but when I used a delete, the result is worst because then ROOT crashes.Find below the part of my mcro involved :

Does anybody have a solution ?
Thanks a lot !

[color=#40BF00]
[color=#40BFFF]TH1D** henergycryst ;[/color]

for(Int_t ifile=0;ifile<2;ifile++) {

 [color=#40BFFF]henergycryst = new TH1D*() [nbhist] ;[/color]

 gROOT->Reset() ;
 gStyle->SetPalette(1) ;

 if(!TClassTable::GetDict("CaloEvent")) {
   gSystem->Load("$DIREXLTHOMAS/RootObject/libCaloEvent.so") ;

 } // Load the CaloEvent and CaloCryst class from ROOT library

 if(!TClassTable::GetDict("EXLCalorimeterHitData")) {
   gSystem->Load("$DIREXLTHOMAS/RootObject/libEXLCalorimeterHitData.so") ;

 } 
 TFile* tf=new TFile(fichier[ifile]) ; // ROOT file to read

cout << "Reading file: " << fichier[ifile] << endl ;

for(Int_t iii=0;iii<nbhist;iii++) { // Begin Init histo table

 sprintf(name,"CrystalID%d",iii) ;
[color=#40BFFF] henergycryst[iii]= new TH1D(name,titlehisto[ifile],ebin, emin,emax[ifile]) ;[/color]
 cout << "OK ! Histo for: " << name << " created" << endl ;
[color=#40BFFF] henergycryst[iii]->SetFillColor(0) ;[/color]

} // End Init histo table

TTree* calotree=(TTree*)tf->Get(“exltree”) ; // Extract Tree

Int_t nevent= calotree->GetEntries() ; // Get number of events in tree
cout << "Number of entries " << nevent << endl ;

CaloEvent* caevt= new CaloEvent(nbhist) ;

TClonesArray* crystals= caevt->GetCrystals() ;

TBranch* branch=calotree->GetBranch(“CaloEventBranch”) ;

branch->SetAddress(&caevt) ;
cout << “OK” << endl ;

for(Int_t i=0;i<nevent; i++) { // Begin Loop on Events

nb+= calotree->GetEvent(i) ;
//    cout << "Nb: " << nb << endl ;
evtid=caevt->GetEvtID() ;
//cout << "Event number: " << evtid  << endl ;
 nbc=caevt->GetNbCryst() ;
 //  cout << "Number of crystals " << nbc << endl ;
 etot=caevt->GetEtot() ;
 //cout << "Energy " << etot << " MeV" <<  endl ;
 multi=caevt->GetMult() ;

Double_t* ecry= new Double_t [nbhist] ;
for(Int_t ii=0;ii<multi;ii++) ecry[ii]=0.0 ;


for (Int_t icrystal=0 ;icrystal<nbhist;icrystal++) { // Begin Loop on Cryst
         
        CaloCryst* cc= (CaloCryst*)crystals->At(icrystal) ;
    //   cout << "OK 1 " << endl ;
    if(cc) { // Begin If (cc)

         idc=cc->GetID() ;
        
        
        ec=cc->GetEnergy() ;
        [color=#40BFFF]henergycryst[idc]->Fill(ec) ;[/color]

    
     ecry[idc]=ec ;	
    } // End If (cc)
    
        

        
    } // End Loop on Cryst



delete [] ecry ; 
//cout << "Emax in Crystal ID  " << idcmax << " is " << ecmax << " MeV" << endl ;

} // End Loop on events

// Draw histograms
for(Int_t jh=0;jh<nbhist;jh++) { // Begin Loop Draw hist
if(jh<3) (c1->cd(nbhist-jh*3-2))->SetFrameFillColor(0) ; ;
if((jh>=3)&&(jh<6)) c1->cd(nbhist-(jh-3)*3-1)->SetFrameFillColor(0) ; ;
if((jh>=6)&&(jh<9)) c1->cd(nbhist-(jh-6)*3)->SetFrameFillColor(0) ; ;

n_h=henergycryst[jh]->GetEntries() ;
cout << "Histo #" << jh << " Entries: "<< n_h << endl ;
      if(n_h>0) {
    gPad->SetLogy() ;
 }

henergycryst[jh]->GetXaxis()->SetTitle(“E(MeV)”) ;
henergycryst[jh]->GetYaxis()->SetTitle(“Counts”) ;
henergycryst[jh]->GetYaxis()->SetTitleOffset(1.24) ;
henergycryst[jh]->Draw() ;

} // End Loop Draw hist

cout << "End reading file : " << fichier[ifile] << endl ;
cout << " " << endl ;

c1->Print(fichdispps[ifile]) ;
cout << "Saving Canva in: " << fichdispps[ifile] << endl ;
c1->Print(fichdispgif[ifile]) ;
cout << "Saving Canva in: " << fichdispgif[ifile] << endl ;

            } // End Loop on Files

[/color]

Why do you include the following statements in your loop?

gROOT->Reset() ; gStyle->SetPalette(1) ;
Start by removing completely gROOT->Reset() from your program. see doc of TROOT::Reset for more details.

Rene

Thanks,

a cut/paste which was wrong. That was part of the problem.

I also put the following commands outside the loop:

TH1D** henergycryst ; 
henergycryst = new TH1D*() [nbhist] ;

and now the macro is working as I expect. :smiley:

Thomas