Re: [ROOT] merge histograms with Alphanumeric labels

From: Weijiang Dong (wjdong@physics.ucla.edu)
Date: Mon Aug 04 2003 - 00:19:18 MEST


By doing this, it worked very well. 
To contribute, this is what i did to merge two histograms filled with
labels:


	TH1F *h = (TH1F*)h1->Clone("h");
        h->Reset();
        h->SetStats(0);
        h->SetBit(TH1::kCanRebin);
        
        for(int binx=0;binx<=h1->GetNbinsX()+1;binx++)
        	h->Fill(h1->GetXaxis()->GetBinLabel(binx),h1->GetBinContent(binx));
        
        for(int binx=0;binx<=h2->GetNbinsX()+1;binx++)
		h->Fill(h2->GetXaxis()->GetBinLabel(binx),h2->GetBinContent(binx));


        h->LabelsOption("au");
        h->LabelsDeflate();
	


Thanks.
Weijiang

On Sun, 3 Aug 2003, Rene Brun wrote:

> Hi
> 
> TH1::Merge is unfortunately not able to merge histograms filled
> with labels. This functionality remains to be implemented.
> For the time being, you must loop on all your files,
> loop on all histogram bins, getting the bin label and filling
> the original histogram.
> 
> Rene Brun
> 
> On Fri, 1 
> Aug 2003, Weijiang Dong wrote:
> 
> > Hi,
> > I want to plot the histogram of number of emc points for each runid
> > to check bad runs. 
> > The runid is an integer. However, the runid has 7 digits. For a
> > whole year's experiment, there would be only like a hundred of different
> > runids. To make it worse, the last 6 digits of the integer runid can be
> > anything. So, by using TH1F with 1000000 bins, each bin will be slim as a
> > line on the plot. 
> > I found I can convert the integer runid to string and fill the
> > histogram with the string and a weight(hlabel1.C and hlabel2.C in root
> > tutorial). It worked fine. I submitted hundreds of jobs and each
> > job generated a root file containing a histogram like that. But finally I
> > want to merge these root files. 
> > I ever used the example macro hadd.C to do it. But root
> > complained histograms in each root file have different bin size. It's
> > true. Because not every runid would present for a job, so not every
> > runid string would fill the histogram. Later I found hadd.C used
> > TH1->Add(TH1 *) method and the "Add" method requires each histogram should
> > have the same bin size.  Then I changed the hadd.C macro a little
> > bit. This time I used TH1->Merge(TList *). Root didn't complain anything
> > this time, but the result is strange and not correct. 
> > Am I doing right or I missed something? Is there any other simple way to
> > do this?
> > Thanks.
> > Weijiang
> > 
> > 
> 
> 



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:14 MET