I’m a beginner.I create a file pixels.root and a tree with a pixel branch and totE branch. In my programming, I use a loop ( for (int i=0; i< 36; i++) {pixel =i)};I obtain a histogram corresponding to pixels.
My problem: I would like to retrieve the tenth pixel with its energy associated (and so forth) and to create a energy histogram per pixel. Or simply how to access the value of branch variables?
TFile *myfile= new TFile(“pixels.root”,“READ”);
Ttree tree= (Ttree myfile)->Get(“tree”);
tree->SetBranchAddress(“totE”,&totE);
tree->SetBranchAddress(“pixel”,&pixel);
I have a problem:
Error in TTree::SetBranchAddress: The pointer type given “Int_t” (3) does not correspond to the type needed “UInt_t” (13) by the branch: pixel
That’s very weird. Anyway here is the last version of the code, now even without any warnings. I deleted all unnecessary stuff that could lead to your error. It works as well. I run it - I get histo.
[code] {
double totE;
unsigned int pixel;// <---- !!!!
TCanvas *c1= new TCanvas ("c1","c1",800,800);
gPad->Divide(0,2);
TH1F *h= new TH1F("h","h",1000,0,40);
TH1F *h1= new TH1F("h1","h1",1000,0,600);
TFile *myfile= TFile::Open("test4pixels.root");
TTree *tree= (TTree*)myfile->Get("tree");
tree->SetBranchAddress("pixel",&pixel);
tree->SetBranchAddress("totE",&totE);
for (int i=0; i<tree->GetEntries(); i++)
{
tree->GetEntry(i);
h->Fill(pixel);
h1->Fill(totE);
}
h->Draw();
}
[/code]
If it still does not work for you, it’s quite hard for me to tell why - this works perfect for me
For example, I have one particle which arrives in my first pixel. It deposits 80% of his energy (histo 1) and dies in my second pixel where it deposits 20% of his energy (histo 2). I should have a correlation between histo 1 and histo 2. How to proceed?
Hi there,
Can you do the same with chain? Imagine you have 2 root files in a chain with same tree name? To see what the branch content, is that your way to create a histogram to store (fill) them to visualize them? You can follow my question under my name.