- #1
ChrisVer
Gold Member
- 3,378
- 464
Can someone explain me what SetDirectory actually does?
I found the problem with a macro like that:
The problem when I ran the program like this, is that the Canvas appeared empty...
On the other hand if I set for my histos histo1,histo2,histoSUM the ->SetDirectory(0)
the histogram appeared in the canvas...
I only found this:
https://root.cern.ch/drupal/content/histograms-and-current-directory
but it doesn't help me understand how it works.
I found the problem with a macro like that:
C:
#include<iostream>
#include <TH1F.h>
#include <TCanvas.h>
#include <TFile.h>
int histoSum(){
//create histograms to use
TH1F* histo1 = new TH1F("histo1",";A", 100, 0,10);
TH1F* histo2 = new TH1F("histo2",";B", 100, 0,10);
TH1F* histoSUM = new TH1F("histoSUM",";C", 100, 0,10);
//call histograms from a root file
TFile f ("histograms.root");
f.GetObject("h_A_events",histo1);
f.GetObject("h_B_events",histo2);
//add the histograms of A,B
histo1->sumw2();
histo2->sumw2();
histoSUM->Add(histo1,histo2);
//print the histogram of SUM on canvas
TCanvas * c= new TCanvas("sum_histos",900,700);
histoSUM->Draw();
return 0;
}
The problem when I ran the program like this, is that the Canvas appeared empty...
On the other hand if I set for my histos histo1,histo2,histoSUM the ->SetDirectory(0)
C:
[...]
f.GetObject("h_B_events",histo2);
histo1->SetDirectory(0);
histo2->SetDirectory(0);
histoSUM->SetDirectory(0);
//add the histograms of A,B
histo1->sumw2();
[...]
the histogram appeared in the canvas...
I only found this:
https://root.cern.ch/drupal/content/histograms-and-current-directory
but it doesn't help me understand how it works.
Last edited by a moderator: