Hi,
I have a list of some histos called with file.Get(path).Get(histo_name) for a given release (for example CMSSW_12_5_0_pre5).
I would like to compare each histo (named as h2) with the same from another release (named as h1).
Do to this, I use a function named createPicture2(self, histo1, histo2, filename) in which I try to clone the 2 histos with :
self.cnv = TCanvas(str(id), “canvas”)
print(‘call to histo2 Clone’)
histo2c = histo2.Clone()
print(‘call to histo1 Clone’)
histo3 = histo1.Clone()
print(‘end Cloning’)
self.cnv.Draw()
self.cnv.Update()
self.cnv.SaveAs(filename)
self.cnv.Close()
with the 2 cases histo1.clone & histo2.clone I have a segmentation fault.
with histo2 only, all run correctly.
with histo1 only, I have a segmentation fault.
Into the most of cases, the segmentation appears when h2 is updated into the main loop
adding a canvas/pad/histo.draw option show that without cloning anything, the graphs of h2 or h1 are correct.
So it seems that I cannot have 2 clones at the same time. Is it correct ?
thanks.
Arnaud
ROOT Version: 6.24.04
Platform: Not lxplus
Compiler: Not Provided
Hello @archiron, thank you for your question.
Do you have a more complete example of what you’re trying to do? In principle you should be able to clone however many objects you want.
Are you able to try your use case with a more recent version of ROOT to see if the problem persists?
Hi, thank you for your answer.
Unfortunatly I cannot now try a more recent version of ROOT. I’m working on a T3 at LLR and the only working version is 6.24.04.
to be more concrete, I have a python file (sorry it’s not C++) with a primary loop (see pgm at end) in which I read the ROOT file.
in this main loop I have another secondary loop onto a list of histo names. Into this loop I get the 2 histos I need for comparison and then I send them to a function for a picture creation.
The function is showed at the bottom. There is nothing inside than the cloning.
Arnaud
for elem in sortedRels:
print('=== release : {}'.format(elem))
f_rel = ROOT.TFile(pathDATA + file) # --> read the file
h1 = getHisto(f_rel, tp_1) # --> get the histo
for i in range(0, len(histoArray)): # --> histoArray is a list of histo names
histo_2 = h2.Get(short_histo_names[0])
histo_1 = h1.Get(short_histo_names[0])
gif_name = pathDBox + short_histo_names[0] + '_' + rel + ".gif"
gr.createPicture2b(histo_1, histo_2, gif_name, 0)
ROOT.TFile.Close(f_rel)
print("END !\n")
=======
def createPicture2b(self, histo1, histo2, filename, id):
self.cnv = TCanvas(str(id), "canvas")
histo2c = histo2.Clone()
histo1c = histo1.Clone()
self.cnv.SetCanvasSize(960, 900)
self.cnv.Clear()
self.cnv.SetFillColor(10)
pad1 = ROOT.TPad(str(id), "pad1", 0, 0.25, 1.0, 1.0) # ,0,0,0
pad1.SetBottomMargin(0.05)
pad1.Draw()
pad1.cd()
newDrawOptions = "hist"
histo2.SetStats(1)
histo2.Draw(newDrawOptions)
self.cnv.Draw()
self.cnv.Update()
self.cnv.SaveAs(filename)
self.cnv.Close()
return
Thanks for posting the code sample.
I don’t see h2
defined anywhere: is it coming from outside the main loop? Also, isn’t the inner loop completely invariant with respect to its iteration index? In other words, are you not using i
on purpose?
yes, (sorry I forget it), before the main loop with :
f2 = ROOT.TFile(pathDATA + input_ref_file)
h2 = getHisto(f2, tp_1)
tp_1 is : tp_1 = ‘ElectronMcSignalValidator’
and the GetHisto function is defined as :
def getHisto(file, tp):
path = 'DQMData/Run 1/EgammaV/Run summary/' + tp
t_path = file.Get(path)
return t_path
which gives for the path : DQMData/Run 1/EgammaV/Run summary/ElectronMcSignalValidator
Arnaud
Thanks for the clarification.
However, I still don’t get what is your inner loop supposed to do: aren’t you simply recreating the same picture over and over, since the histogram names you’re using are always the same?
(maybe you wanted to use short_histo_names[i]
instead?)
you’re right ! in fact the method I use is a little more complicated so I made a simplification and forgot to replace 0 with i !
the simplified code is :
f2 = ROOT.TFile(pathDATA + input_ref_file)
h2 = getHisto(f2, tp_1)
for elem in sortedRels:
print('=== release : {}'.format(elem))
f_rel = ROOT.TFile(pathDATA + file) # --> read the file
h1 = getHisto(f_rel, tp_1) # --> get the histo
for i in range(0, len(histoArray)): # --> histoArray is a list of histo names
histo_2 = h2.Get(histoArray[i])
histo_1 = h1.Get(histoArray[i])
gif_name = pathDBox + histoArray[i] + '_' + rel + ".gif"
gr.createPicture2b(histo_1, histo_2, gif_name, 0)
ROOT.TFile.Close(f_rel)
print("END !\n")
To be more precise, I work with 1 release for H2 and 18 others releases for h1. size of the histoArray is actually of 9 but it will be about 240 at the end.
Hi, I made a test onto a lxplus computer, porting my version on.
With the last ROOT version (6.32) all seems OK on interactive mode.
I remade the test with all the graphic parts and all is OK.
I think you were right with the version of ROOT into your fisrst answer ; The version I used and/or the environment I used (T3 at LLR) must have some limitations.
Many thanks to you.
best regards
Arnaud