-2

I am doing some plotting of ROOT histograms using rootpy and have run in to a bit of a strange problem. I get a ROOT histogram using:

    Histo1 = FilePure.Get(HistoName + str("incl") + str(0))

Where Histoname is the name of the thing I need to. I then want to make two other histograms from this one related to (error values) so I 'Clone' Histo1 twice like so:

    HistoMin = Histo1.Clone();      HistoMax = Histo1.Clone();

Now when I perform an operation on the original Histo1 object (in my case I am rescaling every bin by a constant factor) and then print the values of all 3 histograms the values in Histo1 AND HistoMin have changed but HistoMax has not! I'm very confused byt this so any help would be appreciated! Cheers, Jack

P.s. for non ROOT/rootpy users who nevertheless know a lot about python/OO in general here is a link to the doc. for 'Clone()': http://root.cern.ch/root/html/TNamed.html#TNamed:Clone

ndawe
  • 338
  • 3
  • 14
JMzance
  • 1,704
  • 4
  • 30
  • 49

1 Answers1

0

I think there might be a bug somewhere else in your code that you are not showing.

Is HistoMin somehow referenced back to Histo1 elsewhere in your code?

I see the correct behaviour (only the original histogram is altered):

>>> from rootpy.plotting import Hist
>>> a = Hist(10, -3, 3)
>>> a.FillRandom('gaus')
>>> b = a.Clone()
>>> c = a.Clone()
>>> list(a.y())
[39.0, 136.0, 394.0, 796.0, 1131.0, 1106.0, 817.0, 397.0, 144.0, 40.0]
>>> list(b.y())
[39.0, 136.0, 394.0, 796.0, 1131.0, 1106.0, 817.0, 397.0, 144.0, 40.0]
>>> list(c.y())
[39.0, 136.0, 394.0, 796.0, 1131.0, 1106.0, 817.0, 397.0, 144.0, 40.0]
>>> a *= 3
>>> list(a.y())
[117.0, 408.0, 1182.0, 2388.0, 3393.0, 3318.0, 2451.0, 1191.0, 432.0, 120.0]
>>> list(b.y())
[39.0, 136.0, 394.0, 796.0, 1131.0, 1106.0, 817.0, 397.0, 144.0, 40.0]
>>> list(c.y())
[39.0, 136.0, 394.0, 796.0, 1131.0, 1106.0, 817.0, 397.0, 144.0, 40.0]
ndawe
  • 338
  • 3
  • 14
  • No thats the thing there is no other reference to it anywhere else! I think I solved it though - it was to do with how I was opening the histograms – JMzance Nov 07 '13 at 20:18