Merging histograms

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


Hello!

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) but can't really get it to work. 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 *list = 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 *IonDecayTimeS =
(TH1F*)Ion_decay_time_s->Clone("IonDecayTimeS");

          IonDecayTimeS->Reset();
          TH1F *h0 = (TH1F*)Ion_decay_time_s->Clone("IonDecayTimeS");


// TH1F *IonDecayTimeS = new TH1F("Isotope decay","Isotope
decay",nobins,minimus,maximus);
// cout << "Hist: "<< IonDecayTimeS->GetXaxis()->GetXmin() << " "
<< IonDecayTimeS->GetXaxis()->GetXmax() << " " << IonDecayTimeS->GetNbinsX() << endl;
// IonDecayTimeS->SetBit(TH1::kCanRebin);
          }

// cout << Ion_decay_time_s->GetXaxis()->GetXmin() << " " <<
Ion_decay_time_s->GetXaxis()->GetXmax() << " " << Ion_decay_time_s->GetNbinsX() <<endl;

// sprintf(name,"h%i",i);
// cout << name << endl;

  if ( i==0 ){ TH1F *h0 = (TH1F*)Ion_decay_time_s->Clone( "h0" );}
  if ( i==1 ){ TH1F *h1 = (TH1F*)Ion_decay_time_s->Clone( "h1" );}
  if ( i==2 ){ TH1F *h2 = (TH1F*)Ion_decay_time_s->Clone( "h2" );}
  if ( i==3 ){ TH1F *h3 = (TH1F*)Ion_decay_time_s->Clone( "h3" );}
  if ( i==4 ){ TH1F *h4 = (TH1F*)Ion_decay_time_s->Clone( "h4" );}
  if ( i==5 ){ TH1F *h5 = (TH1F*)Ion_decay_time_s->Clone( "h5" );}

// TH1F *h0 = (TH1F*)Ion_decay_time_s->Clone( name );

// list->Add( h0 );
// list->Add( Ion_decay_time_s );
// IonDecayTimeS->Add( Ion_decay_time_s );

          //Counter
  i++;

      }
   } Received on Wed Nov 09 2011 - 13:06:00 CET

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