Fill histogram with absolute value

Hi,

I have a histogram let’s say ETA distribution, I would like to plot the absolute value of eta. for this i created another histo which will stock the absolute value of the first one doing this

  TH1F *h1 = new TH1F("abseta", "abs(eta)",100,-4.5,4.5);

   int nbins3 = h3->GetXaxis()->GetNbins();
   for (int i=0; i<nbins1 ;i++){
     Float_t v = Old_hist->GetBinContent(i);
     h1->SetBinContent(i,abs(v));
}

Nevertheless I still get the same distribution as the first,

Am I missing something ?

Can it be that you really want:

TH1F *h1 = new TH1F("abseta", "abs(eta)", 50, 0., 4.5);
for (Int_t i = 1; i <= Old_hist->GetNbinsX(); i++)
  h1->Fill(TMath::Abs(Old_hist->GetBinCenter(i)), Old_hist->GetBinContent(i));
h1->ResetStats(); // reset the statistics including the number of entries

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.