Substracting Constant Value from all bins in Root Histogram

Hello everyone,

So, I’m trying to fit a set of data, but before I do this, I need to substract the histogram from 1.

For example, this is how my definition looks like N = 1 - G, where G is a histogram I aready created(no issues with that.)

Now, I will like to subtract histogram G from 1. Any help?

This is what I have tried so far and I feel like it’s not the best way to do;

auto Lab =new TH1F("Lab",
           "All events: Lab vs. Time; Time in seconds; Lab",
  ifstream inp; float x;"Lab1.txt");
  for (int i=1; i<=1000; i++) {
    inp >> x;
Lab->Add(G ,  -1); 


This does: Lab = Lab - G is it what you want ?

Hello Couet,

Yes, Lab = Lab - G is what I want, Lab is an arbitrary number of say 1 or 100.

In the Lab1.txt, I just filled the arbitrary number of about 1000 entries.

Is there any way to substracting arbitrary numbers from Histogram taking into account all the bins?


No, Lab is an histogram (see help)

Okay, but please, how can I do something of say 1 - X, where X is the histogram?

See the various Add methods

Sorry for the late reply! You should be able to use this:

TH1 one("one","1");

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