Suppose I have a histogram : [itex]h(x)[/itex](adsbygoogle = window.adsbygoogle || []).push({});

and I want to take the different values [itex]h(x_i)[/itex] as weights which I can pass in a tree...

The code I wrote so far, which (theoriticially) would do this job for me looks like this:

my problem then is that I am not sure if my logic is plausible, I can't think of any other way to do what I am trying to.Code (C):

TFile* fin = new TFile("file_contains_tree_and_histo.root");

TH1F* h_x = (TH1F*) fin->Get("histo_X");

TTree* myTree = (TTree*) fin->Get("Tree");

Float_t x, w;

float binwidth= h->GetXaxis()->GetBinWidth(1);

myTree->SetBranchAddress("variable_x", &x)

Long64_t N_entries = myTree->GetEntries();

for( int iEntry=0; iEntry<N_entries ; iEntry++){

myTree->GetEntry(iEntry); //Get entry i from the existing tree

int j=0;

while(j<100){

if(x> j *binwidth && x<(j+1)*binwidth){

//checks if value x is in the range of bin j+1,

//if yes then the weight is the value of the histogram

//at that value or bin.

w= h->GetBinContent(j+1);

break; //leave while

}

j++;

}

// Here I need help to pass w in a new tree

}

So for example if the histo's binwidth is [itex]50 ~\text{GeV}[/itex] and the value x of the iEntry is [itex]x_{i}[/itex] and lies between [itex]250 < x_i < 300[/itex], then the value of iEntry-th value of the weight should be the value of the histogram [itex]h(x)[/itex] at the bin# 6.

Then again I am not sure how I can pass/Fill a new tree with the w's... (afterwards I'll try to make the tree friends, and so it will be equivalent to adding safely a new Branch)

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Problem with creating a Tree from another+histogram

Loading...

Similar Threads for Problem creating Tree |
---|

C/++/# Problems with #include<complex.h> |

Running a multidimensional problem on a single core |

JavaScript Problem using dat.GUI controller library |

Fortran Fortran for Computational Fluid Dynamics Problems |

Hacking: Legal and Ethical Problems |

**Physics Forums | Science Articles, Homework Help, Discussion**