# Choosing Highest Value to input into Histogram

Hi all,

I am having some problem with what i though would be simple code; WHen analyzing data, We have Data sorted into bins with a set of 64 random values within each bin. Now I wanted to chose the highest value out of each bin and I used the following Code:
//I previously created a histogram called hValue

double MaxValue=0;

if (PrevBin==NowBin) //just calls in the active bin
{
for (int channel = 0; channel <64; channel ++) {
if (value>MaxValue) // “value” is the name of 1/64 of the random values and goes through all 64
{
MaxValue=value;
} else;
}
}
else
{
hValue->Fill(MaxValue);
MaxValue=0;
}

PrevBin=NowBin;

Any input would be greatly appreciated.

Cheers,
Edwin Baldelomar

When posting code, please use the “code” button, otherwise the code is hard to read.

Rene

Hi Rene,

I suddenly realized my error. Thanks for your help though. I do have another question I hope you might be able to answer. If not that’s fine. But my question is if I have 2 histogram files in form:

histo1.root
histo2.root

How would i go about subtracting histo2 from histo1? Any ideas would be greatly appreciated.

Thank You,
Edwin Baldelomar

``` TFile *f1 = TFile::Open("file1.root"); TFile *f2 = TFile::Open("file2.root"); TH1 *h1 = (TH1*)f1->Get("histo1"); TH1 *h2 = (TH1*)f2->Get("histo1"); h1->Add(h2,-1); //now h1 contains the difference h1-h2 ```
Rene

Hi Rene,

Thanks so much, just one minor question: when you write:

``````TH1 *h1 = (TH1*)f1->Get("histo1");
TH1 *h2 = (TH1*)f2->Get("histo1");``````

Do you mean i just put the name of the histogram file “histo1”, minus the “.root”. Or what exactly am I inputting (or substituting) in the “histo1” place. Thank You.

Cheers,
Edwin Baldelomar

NO, it is not the name of the histogram file, but the name of the histogram.

Rene