Adding Histograms Together

Hello,

So I’m collecting data from a time periods in say intervals of 12 hours. and in the end, i want to combine the data. Now all the data are stored in histograms via one root file. Is there a way to sequentially add root files together or histogram data together so that I can have data from 3 - 12 hour runs to add together as if it had ran for 36 hours straight? Any Help would be greatly appreciated.

Cheers,
Edwin Baldelomar

If you have file1.root, file2.root, fileN.root containing histograms or/and Trees, you can create a new file result.root with all histograms added and trees merged by using the hadd utility in $ROOTSYS/bin

hadd -f result.root file1.root file2.root fileN.root
Rene

Hey Rene,

Thanks, I think this will solve my problems as I see from other posts with this problem. I’m new to all this and I’m using a data taking software. I’m trying to figure out what is the right question to ask, but I think it is that; Is there a way to create dictionaries or source dictionaries for needed classes. Here’s my code that I’m using:

//----------------------------------------------------------------------------
// File : hadd.C
// Author : Edwin Baldelomar
// Created : 07/15/2009
//----------------------------------------------------------------------------

#include <string.h>
#include “TChain.h”
#include “TFile.h”
#include “TH1.h”
#include “TTree.h”
#include “TKey.h”
#include “Riostream.h”

TList *FileList;
TFile *Target;

void MergeRootfile( TDirectory *target, TList *sourcelist );

void hadd() {
// in an interactive ROOT session, edit the file names
// Target and FileList, then
// root > .L hadd.C
// root > hadd()

Target = TFile::Open( “/home/e.baldelomar/DataAnalysis/2009_07_15_10_52_00_run/run.root”, “RECREATE” );

FileList = new TList();
FileList->Add( TFile::Open("/data-disk/kpix-data/gem/samples/2009_07_09_15_40_33_run/run.root") );
FileList->Add( TFile::Open("/data-disk/kpix-data/gem/samples/2009_07_13_15_54_17_run/run.root") );
FileList->Add( TFile::Open("/data-disk/kpix-data/gem/samples/2009_07_14_14_39_50_run/run.root") );

MergeRootfile( Target, FileList );

}

and when I run it in root, I get the following error:

root [0] .L hadd.C
root [1] hadd()
Warning in TClass::TClass: no dictionary for class KpixAsic is available
Warning in TClass::TClass: no dictionary for class KpixSample is available
Error: MergeRootfile() declared but not defined hadd.C:34:
*** Interpreter error recovered ***

These are Classes that are specific to the software that acquires data. Again, being new to all this, I’m not sure if I’m asking the right question, but I think it’s that is there a way to create dictionaries for those classes, or would I have to ask the developers of the software. Thank You.

Cheers,
Edwin Baldelomar

[quote]but I think it’s that is there a way to create dictionaries for those classes, or would I have to ask the developers of the software. [/quote]The best is usually to the load the library implementing those classes. However it is often not necessary. In addition, you can very simply create a small library implementing POD (plain old data) version of the classes by doing:

TFile *inputfile = TFile::Open("/data-disk/kpix-data/gem/samples/2009_07_09_15_40_33_run/run.root"); inputfile->MakeProject("mylib","*","RECREATE++");

But you real problem is:Error: MergeRootfile() declared but not defined hadd.C:34: where the function MergeRootfile is not known to the your script.

Cheers,
Philippe.