Merging histograms

From: Ida Häggström <ida.haggstrom_at_radfys.umu.se>
Date: Wed, 9 Nov 2011 13:17:42 +0100


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 - 13:17:49 CET

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