RooDataHist - how to iterate over all bins

Hi,
I have a 2d RooDataHist. I need to check that each bin has decent statistics. How do I iterate over all bins and get content of each bin? I can’t figure out an obvious way to do this from the class reference.
Any ideas?
thanks,
Wojtek

Hi,

You can do that as follows

RooDataSet* dh ;
for(Int_t i=0 ; i<dh->numEntries() ; i++) {
   cout << dh->weight(i) ; 
}

Additionally get(i) can return you a RooArgSet* which contain
the observables at the coordinates of the bin center.

Wouter

Hi,
Then I don’t understand why this doesn’t compile:

void normalizeRooDataHist(RooDataHist* dh){
double sum=dh->sum(false);
cerr<<“histo: “<GetName()<<” total: “<<sum<<”\n”;
for(Int_t i=0 ; inumEntries() ; i++) {
double wgt=dh->weight(i); // COMILATION ERROR
RooArgSet* currarg=dh->get(i);
cerr<<“current weight: “<<wgt<<”\n”;
wgt=wgt/sum;
cerr<<“set to: “<<wgt<<”\n”;
dh->set(*currarg,wgt);
}

cerr<<“after norm: “<sum(false)<<”\n”;

}

the compilation error is this:
normalizeRooDataHist.cpp:9: error: no matching function for call to ‘RooDataHist::weight(Int_t&)’

thanks,
Wojtek

Hi Wojtek,

Apologies, I had only implemented weight(i) in the data storage classes, not yet in data representation classes!
What you can do is the following

RooDataSet* dh ;
for(Int_t i=0 ; inumEntries() ; i++) {
dh->get(i) ;
cout << dh->weight() << endl ;
}

Wouter

Thanks!
w