Below is a list of methods implementing operations on histograms.
Add "other" histo to current histo.
Subtract "other" histo from current histo.
Multiply "other" histo with current histo.
Divide current histogram by "other" histo.
Divide current histo by "other" histo using "binomial error"
Notice that operations with another histogram exists with two signatures, the first one allowing to directly assign the result of an operation.
This is an example of code to add two histograms:
HepRef(PHisto1D) histo1 =
new(db_) PHisto1D( "Histo1: parabolic function", 20,0.,20.);
...
for (int i = 0; i < 50000; i++)
histo1->fill(x,w);
// Now create a clone of histo1
HepRef(Histo1D) histo2 = histo1->clone();
// Add histo1 to histo2 and change histogram name
histo2->add( *histo1 );
histo2->set_name( "Histo2 = Histo2+Histo1 = 2*Histo1" );
//
// It is also possible to clone and perform an operation on single
// statement:
// histo2 = histo1->clone()->add( histo1 );
//
As discussed in the first paragraph, it's important to first make a clone of the original histogram. Another way to clone a histogram is using a copy constructor, as described in Chapter Chapter 8., Constructors.