HOW to add histo in ROOT-framework?
01:50 21 Oct 2013

i choose to ask a question here well aware that i can infringe some rules of StackExchange maybe becouse this isn't the right place to ask that, but i saw a lot of question related to CERN ROOT. I know that here people that answer the questions prefer to show the way instead to give a cooked solution, but i need some help and i have no time to learn from the answers, i only want a solution for my problem. I apologize in advance!

Here is my problem: i have two .root files:

  • one of a spectrum ("sezione_misura_90.root"),
  • one from background ("sezione_fondo_90.root").

I have to subtract the second from the first and get a final histogram. Usually i open the file with the TBroswer and i have no idea how to implement a macro of a script to open a .root file or doing everything else, first of all becouse i hate ROOT and all programming related, and i have only a course where i am supposed to use that, without someone tell me how!!! Even the prof. don't know how to use...

If some one that read have a macro or a script ready to use, I will be forever indebted to him for sharing that with me. Thanks in advance!

EDIT I write down a file named run.cxx with the following lines

int run() {

// Open both files side-by-side
TFile* sezione_misura_90 = new TFile("sezione_misura_90.root");
TFile* sezione_fondo_90 = new TFile("sezione_fondo_90.root");

// Get the histograms from the file
// Since you didn't say from your post, I'm going to assume that
// the histograms are called "hist" and that they hold floating
// point values (meaning, they're TH1F histograms.  The "F" means float)

TH1F* h_misura = (TH1F*) sezione_misura_90->Get("hist");
TH1F* h_fondo = (TH1F*) sezione_fondo_90->Get("hist");

// Now we add them together
TH1F* h_sum = h_misura->Add(*h_fondo, -1);

} There was some typos like ( and ;, i correct them but i get back the following.

Error: illegal pointer to class object h_misura 0x0 139 run.cxx:21: ** Interpreter error recovered **

histogram root-framework