Re: Merging histograms

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Wed, 9 Nov 2011 07:47:25 -0600


Hi Ida,

One thing missing from the code snippet is the way the TFile are opened and close. For the case where the Merge function is used, either the TFile must be kept open or the the histogram must be detached from the file ( Ion_decay_time_s->SetDirectory(0) ).

Either way the alternative:

      AllHistograms->Add( Ion_decay_time_s ); <--- Alternative I tried with no success either....

should apriori have worked (unless the range/binning are not always the same).

Cheers,
Philippe.

On 11/9/11 6:17 AM, Ida Häggström wrote:
> Hello! (please disregard my previous post as it was sent by accident!)
>
> I have a bunch of ROOT-files, each containing several histograms and some trees. I'm trying to merge one of the histograms (same
> in all ROOT-files, called "Ion_decay_time_s", all of equal size) but can't really get it to work. The code below is what I've
> tried with no success... I end up with "*** Break *** segmentation violation" when running (root version 5.28/00a). Any ideas?
> Thanks!
> Ida
>
> Here's my code:
> ---------------------------------
> // Add all ROOT-files in given directory
> TSystemDirectory* dataDir = new TSystemDirectory("",MyDirectoryWithRootFiles);
> TList* contents = dataDir->GetListOfFiles();
> TIter next(contents);
> TSystemFile* file;
> TList *listOfHistograms = new TList;
> Int_t i = 0;
>
> // Loop over all files in directory
> while (( file = (TSystemFile*)next() )) {
> if ( file->IsDirectory() ) { continue; }
> // Add if root-file...
> if ( (TString(file->GetName())).EndsWith(".root") ) {
> if ( i==0 ){
> TH1F *AllHistograms= (TH1F*)Ion_decay_time_s->Clone("AllHistograms");
> AllHistograms->Reset();
> }
> listOfHistograms->Add( Ion_decay_time_s );
> //AllHistograms->Add( Ion_decay_time_s ); <--- Alternative I tried with no success either....
> }
> }
>
> AllHistograms->Merge(listOfHistograms);
> AllHistograms->Draw();
> ---------------------------------
Received on Wed Nov 09 2011 - 14:47:31 CET

This archive was generated by hypermail 2.2.0 : Wed Nov 09 2011 - 17:50:01 CET