# Error in TUnfolding

**URL:** <https://root-forum.cern.ch/t/error-in-tunfolding/56738>\
**Category:** Newbie\
**Created:** [October 16, 2023, 6:01am UTC](https://root-forum.cern.ch/t/error-in-tunfolding/56738 "2023-10-16T06:01:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pjana](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@pjana](https://root-forum.cern.ch/u/pjana)\
**Post date:** [October 16, 2023, 6:01am UTC](https://root-forum.cern.ch/t/error-in-tunfolding/56738/1 "2023-10-16T06:01:56Z")

</div>

Dear experts,  
I am trying to do unfolding using TUnfold with regularization, scanning LCurve method. I am using 12 bins for reco MC and 6 bins for Gen MC and data. I am getting errors like-

> Info in TUnfold::SetConstraint: fConstraint=0  
> Info in TUnfold::TUnfold: 12 input bins and 8 output bins (includes 2 underflow/overflow bins)  
> Warning in TUnfold::SetInput: 7/12 input bins have zero error, and are ignored.  
> Error in TUnfold::GetInputInverseEmatrix: number of parameters 8 \> 5 (rank of input covariance). Problem can not be solved  
> Info in TUnfold::InvertMSparseSymmPos: cholesky-decomposition failed, try eigenvalue analysis  
> Warning in TUnfold::DoUnfold: rank of matrix E 5 expect 8  
> Info in TUnfold::InvertMSparseSymmPos: cholesky-decomposition failed, try eigenvalue analysis  
> Warning in TUnfold::DoUnfold: rank of output covariance is 5 expect 8  
> Error in TUnfold::ScanLcurve: too few input bins, NDF\<=0 -3  
> Info in TUnfold::ScanLcurve: logtau=-Infinity X=-28.254760 Y=7.000336  
> Fatal in TUnfold::AddMSparse: Nan detected 0 1 1  
> aborting  
> [/opt/homebrew/Cellar/root/6.28.06/lib/root/libCore.so] ErrorHandler (no debug info)  
> [/opt/homebrew/Cellar/root/6.28.06/lib/root/libCore.so] TObject::Fatal(char const\*, char const\*, …) const (no debug info)  
> [/opt/homebrew/Cellar/root/6.28.06/lib/root/libUnfold.so] TUnfold::AddMSparse(TMatrixTSparse_, double, TMatrixTSparse const_) const (no debug info)  
> [/opt/homebrew/Cellar/root/6.28.06/lib/root/libUnfold.so] TUnfold::DoUnfold() (no debug info)  
> [/opt/homebrew/Cellar/root/6.28.06/lib/root/libUnfold.so] TUnfold::ScanLcurve(int, double, double, TGraph\*\*, TSpline\*\*, TSpline\*\*, TSpline\*\*) (no debug info)  
> [] (no debug info)  
> [] (no debug info)  
> [/opt/homebrew/Cellar/root/6.28.06/lib/root/libCling.so] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value\*) const (no debug info)

The part of the code for unfolding is given below-

> TUnfold::ERegMode regMode=TUnfold::kRegModeSize;
> 
> TUnfold::EConstraint constraintMode=TUnfold::kEConstraintNone;  
> TUnfoldDensity::EDensityMode densityFlags = TUnfoldDensity::kDensityModeBinWidth;  
> TUnfold::EHistMap outputMap = TUnfold::kHistMapOutputHoriz;  
> TUnfold unfold(hEleMu\_RecoGenTauPt[0],  
> TUnfold::kHistMapOutputHoriz,  
> TUnfold::kRegModeSize,  
> TUnfold::kEConstraintNone);  
> unfold.SetInput( hMu\_Pt\_data\_bkgSub,1.0);  
> TGraph \*lcurve=0;  
> TSpline \*logTauX=0,\*logTauY=0;  
> unfold.ScanLcurve(10,0.,0.,&lcurve,&logTauX,&logTauY);  
> double tau=unfold.GetTau();  
> double logTau=TMath::Log10(tau);  
> double lcurveX=logTauX-\>Eval(logTau);  
> double lcurveY=logTauY-\>Eval(logTau);

> unfold.DoUnfold(tau,hMu\_Pt\_data\_bkgSub);  
> TH1 \*hUnfold\_TauPt\_data;  
> unfold.GetOutput(hUnfold\_TauPt\_data);

How can I solve this problem?  
Just to mention non-regularization worked (Not proper unfolding but code ran) for this case with simple case tau=0.  
Any help would be appreciated. Thanks in advance!

Regards,  
Pranati

---

<div class="post-metadata">

**Author:** ![mdessole](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mdessole/32/34021_2.png) [@mdessole](https://root-forum.cern.ch/u/mdessole)\
**Post date:** [October 16, 2023, 7:07am UTC](https://root-forum.cern.ch/t/error-in-tunfolding/56738/2 "2023-10-16T07:07:19Z")

</div>

Hi @pjana,  
thanks for reaching out! Can you post a code snippet to reproduce the error?

Cheers,  
Monica

---

<div class="post-metadata">

**Author:** ![pjana](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@pjana](https://root-forum.cern.ch/u/pjana)\
**Post date:** [October 16, 2023, 7:26am UTC](https://root-forum.cern.ch/t/error-in-tunfolding/56738/3 "2023-10-16T07:26:07Z")

</div>

Hi @mdessole ,  
Thanks!  
I have attached the script.  
[makeUnfold\_data.C](https://root-forum.cern.ch/uploads/short-url/5AxTPPmqzAXv8tZmBiKIvp4LywR.C) (20.7 KB)

Regards,  
Pranati

---

<div class="post-metadata">

**Author:** ![Eddy\_Offermann](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eddy_offermann/32/25079_2.png) [@Eddy\_Offermann](https://root-forum.cern.ch/u/Eddy_Offermann)\
**Post date:** [October 16, 2023, 6:34pm UTC](https://root-forum.cern.ch/t/error-in-tunfolding/56738/4 "2023-10-16T18:34:41Z")

</div>

hi @pjana,

You will have to put a bit more effort in this piece of code to reproduce the error. For starters, you have to supply an input file, like the one mentioned in

```auto
TFile *f1=new TFile("RootFile/GenMatch/Data_MuMuFSR_4thOctober.root","r");

```

In these 592 lines, probable a lot is not used. Please remove it so that  
one can concentrate on the real issue.

-Eddy
