Hi,
Iam trying to read a branch from my root tree. The branch and its contents are defined in an external object called Hits. I want to read out 4 entries from Hits, m_row, m_column, m_charge and m_id and dump them to a file using ofstream. When i plot these entries with Draw() everything works fine and i get a beautiful hitmap when i print these entries i always get zero unless initializing the variable with something else then i always get something else which means the variable is not touched somehow. Can anyone help me with this issue ? The code i use is shown below.
Cheers
Roger
#include <iostream>
#include <fstream>
using namespace std;
void readOut() {
TFile *f1 = new TFile("file.root");
TTree *Content;
f1->GetObject("tree", Content);
ofstream myfile;
myfile.open ("hits.dat");
Short_t row;
Short_t col;
Short_t adc;
UInt_t id;
Int_t all;
TH2F *histo = new TH2F("histo", "histo", 250,0,251,768,0,769); //name histogram ,N bin, von, bis
histo->SetTitle("");
histo->SetXTitle("column");
histo->SetYTitle("row");
Content->Draw("Hits.m_row:Hits.m_column>>histo","" ,"");
Content->SetBranchAddress("Hits.m_row", &row);
Content->SetBranchAddress("Hits.m_column", &col);
Content->SetBranchAddress("Hits.m_charge", &adc);
Content->SetBranchAddress("Hits.m_id", &id);
all = Content->GetEntries();
for(int i = 0 ; i < all ; i++){
Content->GetEntry(i);
cout << row << "\n";
myfile << row;
myfile << "\n";
myfile << col;
myfile << "\n";
myfile << adc;
myfile << "\n";
myfile << id;
myfile << "\n";
histo->Fill(row,col);
}
myfile.close();
histo->Draw("colz");
}