pyROOT and TUnfold ScanLcurve Locks Up Terminal

Hello,

When I try to run the TUnfold ScanLcurve function through pyROOT, the ScanLcurve finishes successfully but it causes my terminal to lock up as if the program is still continuously running. The code in pyROOT is very simple :

import ROOT

file = ROOT.TFile("input_file.root", "read")
mig = file.Get("migration_matrix")
reco = file.Get("data_histogram")
bg = file.Get("background_histogram")
unfold = ROOT.TUnfoldDensity(mig, ROOT.TUnfold.kHistMapOutputVert, ROOT.TUnfold.kRegModeSize, ROOT.TUnfold.kEConstraintArea)
unfold.SetInput(reco, 0.)
unfold.SubtractBackground(bg, "bg")

lcurve = ROOT.TGraph()

unfold.ScanLcurve(30, 1e-7, 1e-1, lcurve)=

And this produces the following output :

Where at the end, the program doesn’t ever exit and doesn’t return my command prompt. I also am not able to interrupt the program normally by doing “CTRL-C”. The only way to stop the program is to pause it using “CTRL-Z” and then manually kill the program. Is this a problem with my code or with python (python v3.10.6)?

Thanks!

ROOT Version:6.26.10
Platform:Ubuntu22
Compiler:_ Not Provided

Hi @Charlie_Chen,

@couet, have you seen that before?
@Charlie_Chen, it would be useful if you could attach the input file so that we could try to reproduce the issue.

Cheers,
J.

No, but I am not using python a lot…

Dear @jalopezg, @couet,

Sorry I should have added a sample root file to my original question. Here is the sample root file with the same histograms that I used in my original code snippet.
sample_histograms_file.root (9.3 KB)

Thanks again,

Charlie

Dear @jalopezg and @couet,

I was wondering if you’ve had a chance to look into this further and were able to reproduce the problem with the sample root file?

Cheers,

Charlie

Sorry for the late reply. I had some other stuff to do.

I get:

 % python3 ChCh.py 
  File "/Users/couet/roottest/ChCh.py", line 13
    unfold.ScanLcurve(30, 1e-7, 1e-1, lcurve)=
    ^
SyntaxError: cannot assign to function call

Can you post a working script ?

Hi @couet,

No apologies needed, sorry there is a trailing “=” at the end of that line:

import ROOT

file = ROOT.TFile("input_file.root", "read")
mig = file.Get("migration_matrix")
reco = file.Get("data_histogram")
bg = file.Get("background_histogram")
unfold = ROOT.TUnfoldDensity(mig, ROOT.TUnfold.kHistMapOutputVert, ROOT.TUnfold.kRegModeSize, ROOT.TUnfold.kEConstraintArea)
unfold.SetInput(reco, 0.)
unfold.SubtractBackground(bg, "bg")

lcurve = ROOT.TGraph()

unfold.ScanLcurve(30, 1e-7, 1e-1, lcurve)

I get this:

% python3 ChCh.py
Info in <TUnfold::SetConstraint>: fConstraint=1
Info in <TUnfold::TUnfold>: underflow and overflow bin do not depend on the input data
Info in <TUnfold::TUnfold>: 23 input bins and 12 output bins
Info in <TUnfoldDensity::TUnfold>: *NOT* unfolding bin #0 (yaxis:[ufl])
Info in <TUnfoldDensity::TUnfold>: *NOT* unfolding bin #13 (yaxis:[ofl])
Info in <TUnfoldDensity::RegularizeOneDistribution>: regularizing yaxis regMode=1 densityMode=3 axisSteering=*[UOB]
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.000000 X=6.781955 Y=9.594321
Info in <TUnfoldDensity::ScanLcurve>: logtau=-7.000000 X=2.196171 Y=9.764503
Info in <TUnfoldDensity::ScanLcurve>: logtau=-4.000000 X=2.196171 Y=9.764503
Info in <TUnfoldDensity::ScanLcurve>: logtau=-2.500000 X=2.276990 Y=9.764023
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.750000 X=4.460515 Y=9.750305
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.375000 X=5.776386 Y=9.702751
Info in <TUnfoldDensity::ScanLcurve>: logtau=-2.125000 X=3.062716 Y=9.761829
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.937500 X=3.749014 Y=9.758272
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.562500 X=5.147097 Y=9.733625
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.187500 X=6.323213 Y=9.654996
Info in <TUnfoldDensity::ScanLcurve>: logtau=-2.312500 X=2.527419 Y=9.763367
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.843750 X=4.105625 Y=9.755059
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.656250 X=4.809022 Y=9.743399
Info in <TUnfoldDensity::ScanLcurve>: logtau=-2.031250 X=3.397474 Y=9.760413
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.468750 X=5.470783 Y=9.720262
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.281250 X=6.061028 Y=9.680899
Info in <TUnfoldDensity::ScanLcurve>: logtau=-2.218750 X=2.764353 Y=9.762759
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.093750 X=6.563019 Y=9.625792
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.890625 X=3.927186 Y=9.756826
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.796875 X=4.283603 Y=9.752910
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.984375 X=3.572034 Y=9.759452
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.703125 X=4.635824 Y=9.747164
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.609375 X=4.979612 Y=9.738917
Info in <TUnfoldDensity::ScanLcurve>: logtau=-2.078125 X=3.226977 Y=9.761195
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.515625 X=5.310981 Y=9.727433
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.421875 X=5.626052 Y=9.712048
Info in <TUnfoldDensity::ScanLcurve>: logtau=-2.171875 X=2.907437 Y=9.762343
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.328125 X=5.921457 Y=9.692361
Info in <TUnfoldDensity::ScanLcurve>: logtau=-1.234375 X=6.194959 Y=9.668416
Info in <TUnfoldDensity::ScanLcurve>: Result logtau=-2.240031 X=2.704321 Y=9.762920

No graphics. I am not familiar with this TUnfold Class. May be @moneta can help ?

Hi,

I can reproduce the problem, it is on exiting the script, if you do python3 -i yourCode.py, it works fine, but them it will hang-up when exiting Python with ctrl-D.
We will investigate the issue, thank your for reporting the problem

Lorenzo

The problem is caused by the TUnfold::ScanLcurve which requires as input a TGraph **. The correct way to use this in Python is as following:

lcurve = ROOT.MakeNullPointer(ROOT.TGraph)

unfold.ScanLcurve(30, 1e-7, 1e-1, lcurve)

lcurve.Draw("AL")

Dear @couet, @moneta,

Thank you taking time to look into this for me, the solution provided by @moneta, worked for me and the script exits as intended.

Cheers,

Charlie

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