Access to a TList Content via At()

Good afternoon,

I built a TList which includes 1D and 2D histograms, together with TParameter<Int_t> and TParameter<Double_t>.

I fill the list using the AddAt(TObject*, Int_t idx) function. For instance:

fetotinit= new TParameter<Double_t>*[nfile] ;
     fetotinit[0]=new TParameter<Double_t>("n 144keV",0.144,'f') ;
for(Int_t iet=0;iet<nfile;iet++) {
       fOutput->AddAt(fetotinit[iet],iet) ;
     }

(currently nfile=1, because I am still testing my code …)

findex = new TParameter<Int_t>("Index",-1,'l') ;
   fOutput->AddAt(findex,nfile) ;

 //Efficiency counters
    fparcounttot = new TParameter<Int_t>*[nfile] ;
    fparcountconv= new TParameter<Int_t>*[nfile] ;
    fparcountdosim= new TParameter<Int_t>*[nfile] ;
    fnevent= new TParameter<Int_t>*[nfile] ;

    for(Int_t in=0;in<nfile;in++) {
     sprintf(name11,"CountConv%d",in+1) ;
     fparcountconv[in]= new TParameter<Int_t>(name11,0,'+')  ;
     
     sprintf(name12,"CountDosim%d",in+1) ;
     fparcountdosim[in]= new TParameter<Int_t>(name12,0,'+')  ;

     sprintf(name13,"CountConv+Dosim%d",in+1) ;
     fparcounttot[in]= new TParameter<Int_t>(name13,0,'+') ;

     sprintf(name14,"CountEvent%d",in+1) ;
     fnevent[in]= new TParameter<Int_t>(name14,0,'f') ;
     
     fOutput->AddAt(fparcountconv[in],in+1+nfile) ;
     fOutput->AddAt(fparcountdosim[in],in+2+nfile) ;
     fOutput->AddAt(fparcounttot[in],in+3+nfile) ;
     fOutput->AddAt(fnevent[in],in+4+nfile) ;

    }

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

    sprintf(name1,"Conv%d",iii+1) ;
    sprintf(name2,"Dosim%d",iii+1) ;
    sprintf(name3,"Conv+Dosim%d",iii+1);
    sprintf(name4,"Bidim%d",iii+1);

   
    fhconv[iii]= new TH1D(name1,fetotinit[iii]->GetName(),convbin[iii], convmin[iii], convmax[iii]) ;
    fhconv[iii]->SetFillColor(0) ;
    fhconv[iii]->SetLineColor(1) ;
    fhconv[iii]->GetXaxis()->SetTitle("E_{Conv}(MeV)") ;
    fhconv[iii]->GetXaxis()->SetTitleOffset(1.3) ;
    fhconv[iii]->GetXaxis()->SetRangeUser(rxmin,convmax[iii]) ;

    fhconv[iii]->GetYaxis()->SetTitle("Counts") ;
    fhconv[iii]->GetYaxis()->SetTitleOffset(1.4) ;
    fhconv[iii]->GetYaxis()->SetRangeUser(0.1,1000000) ;

    fhdosim[iii]= new TH1D(name2,fetotinit[iii]->GetName(),dosimbin[iii], dosimmin[iii], dosimmax[iii]) ;
    fhdosim[iii]->SetFillColor(0) ;
    fhdosim[iii]->SetLineColor(1) ;
    fhdosim[iii]->GetXaxis()->SetTitle("E_{Dosim}(MeV)") ;
    fhdosim[iii]->GetXaxis()->SetTitleOffset(1.3) ;
    fhdosim[iii]->GetXaxis()->SetRangeUser(rxmin,dosimmax[iii]) ;

    fhdosim[iii]->GetYaxis()->SetTitle("Counts") ;
    fhdosim[iii]->GetYaxis()->SetTitleOffset(1.4) ;
    fhdosim[iii]->GetYaxis()->SetRangeUser(0.1,1000000) ;

    fhtot[iii]= new TH1D(name3,fetotinit[iii]->GetName(),etotbin[iii], etotmin[iii], etotmax[iii]) ;
    fhtot[iii]->SetFillColor(0) ;
    fhtot[iii]->SetLineColor(1) ;
    fhtot[iii]->GetXaxis()->SetTitle("E_{Dosim}(MeV)") ;
    fhtot[iii]->GetXaxis()->SetTitleOffset(1.3) ;
    fhtot[iii]->GetXaxis()->SetRangeUser(rxmin,etotmax[iii]) ;

    fhtot[iii]->GetYaxis()->SetTitle("Counts") ;
    fhtot[iii]->GetYaxis()->SetTitleOffset(1.4) ;
    fhtot[iii]->GetYaxis()->SetRangeUser(0.1,1000000) ;

    fh2D[iii]= new TH2D(name4,fetotinit[iii]->GetName(),convbin[iii],convmin[iii],convmax[iii],dosimbin[iii],dosimmin[iii],dosimmax[iii] ) ;
    fh2D[iii]->SetFillColor(0) ;
    fh2D[iii]->GetXaxis()->SetTitle("E_{Conv}(MeV)") ;
    fh2D[iii]->GetXaxis()->SetLabelSize(0.037) ;
    fh2D[iii]->GetYaxis()->SetTitle("E_{Dosim}(MeV)") ;
    fh2D[iii]->GetYaxis()->SetTitleOffset(1.26) ;
    fh2D[iii]->GetYaxis()->SetLabelSize(0.037) ;

     // Adding histograms in the output list

    fOutput->AddAt(fhconv[iii],iii+1+2*nfile+3) ;
    fOutput->AddAt(fhdosim[iii],iii+2+2*nfile+3) ;
    fOutput->AddAt(fhtot[iii],iii+3+2*nfile+3) ;
    fOutput->AddAt(fh2D[iii],iii+4+2*nfile+3) ;

    
   
   } 

When I want to get these objects via the fOutput->FindObject(const char* name), everything is fine.
But when I want to get them via fOutput->At(Int_t idx) , with idx=0 for example, the corresponding object is not found.

The command

TParameter<Double_t>* pareinit=  dynamic_cast<TParameter<Double_t>*>(fOutput->FindObject("n 144keV")) ;

works, but if I replace it by:

TParameter<Double_t>* pareinit=  dynamic_cast<TParameter<Double_t>*>(fOutput->At(0)) ;

the corresponding object is not found because the following message:

which comes from

 if(!pareinit) {
	cout << "Initial Energies missing" << endl ;
	return ;
      }

I do not understand since 0 is the index where this object is put in the List.

Where am I mistaken ?

Thanks for your help.

Have you solved this ?

I use the FindObject function taking the chain of characters in argument and the macro could work.
Anyway if you have an explanation why the implementation with the At() function does not work, I would be glad to know it.
Many thanks.

Yes that’s the way to proceed.