Converting a TH2D to a Matrix for Inversion

Hi all,

From corresponding reconstructed and true values I’ve built a TH2D Histogram that illustrates an energy smearing. I’d like to convert the TH2D to a Matrix in order to be able to build the inverted matrix and put it back into a TH2D for further calculations within my analysis.

I have not been able to find examples doing this.
Can someone point me to relevant examples?

Thanks
Francesca

ROOT Version: 6.22
Platform: macosx64


Hi @fstocker,

This forum post looks similar to what you are trying to attain.

However, the following was suggested in RootTalk here:

TH2D histo(...);
// ...
TMatrix m(nbinsx+2, nbinsy+2, histo.GetArray(), "F")

Maybe @couet and/or @moneta can confirm the validity of the last method?

Cheers,
J.

Sounds good to me. TMatrix has an “Invert” method.

Hi,
Since you are using a TH2D and not TH2F, teh correct code is this one:

H2D histo(...);
// ...
TMatrixD m(nbinsx+2, nbinsy+2, histo.GetArray(), "D")

Also note that the resulting matrix will contain also the underflow and overflow.
If you want to exclude, just do from the previous obtained matrix:

TMatrixD m2 = m.GetSub(1,nbinsx,1,nbinsy)

and now you will obtaioned a matrix containining only the bin contents in the histogram axis range.

Lorenzo

Thank you for the replies @moneta, @couet & @jalopezg!
I tried and they work for implementation, unfortunately my matrix is singular :grimacing: :thinking: and results with a pseudo inverse also do not look satisfying. I guess I’ll have to do some chi2 method

Hi, i am trying to do the same in python but i keep getting errors when using the recommended approach of

H2D histo(...);
// ...
TMatrixD m(nbinsx+2, nbinsy+2, histo.GetArray(), "D")
Traceback (most recent call last):
  File "/afs/desy.de/user/j/jnitschk/DUST/CAF/TimUnfolding/VIPUnfolding/python_interface//run_vipunfolding.py", line 362, in <module>
    main()
  File "/afs/desy.de/user/j/jnitschk/DUST/CAF/TimUnfolding/VIPUnfolding/python_interface//run_vipunfolding.py", line 281, in main
    ddctest.reweight_to_data_syst(
  File "/nfs/dust/atlas/user/jnitschk/CAF/TimUnfolding/VIPUnfolding/python_interface/vipunfolding/data_driven_closure_test.py", line 170, in reweight_to_data_syst
    hist_weight_unsmoothed, variance = unfolding(hist_weight_unsmoothed, eff_corr, fid_corr, migration_matrix, bkg)
  File "/nfs/dust/atlas/user/jnitschk/CAF/TimUnfolding/VIPUnfolding/python_interface/vipunfolding/data_driven_closure_test.py", line 65, in unfolding
    matrix = ROOT.TMatrix(n_bins + 2, n_bins + 2, migration_matrix.GetArray(), "D")
TypeError: Template method resolution failed:
  none of the 14 overloaded methods succeeded. Full details:
  TMatrixT<float>::TMatrixT<float>(const TMatrixT<float>& another) =>
    TypeError: takes at most 1 arguments (4 given)
  TMatrixT<float>::TMatrixT<float>(const TMatrixTSym<float>& another) =>
    TypeError: takes at most 1 arguments (4 given)
  TMatrixT<float>::TMatrixT<float>(const TMatrixTSparse<float>& another) =>
    TypeError: takes at most 1 arguments (4 given)
  TMatrixT<float>::TMatrixT<float>(const TMatrixTLazy<float>& lazy_constructor) =>
    TypeError: takes at most 1 arguments (4 given)
  TMatrixT<float>::TMatrixT<float>() =>
    TypeError: takes at most 0 arguments (4 given)
  TMatrixT<float>::TMatrixT<float>(int nrows, int ncols) =>
    TypeError: takes at most 2 arguments (4 given)
  TMatrixT<float>::TMatrixT<float>(int row_lwb, int row_upb, int col_lwb, int col_upb) =>
    TypeError: could not convert argument 3 (int/long conversion expects an integer object)
  TMatrixT<float>::TMatrixT<float>(const TMatrixT<float>& a, TMatrixT<float>::EMatrixCreatorsOp2 op, const TMatrixT<float>& b) =>
    TypeError: takes at most 3 arguments (4 given)
  TMatrixT<float>::TMatrixT<float>(const TMatrixT<float>& a, TMatrixT<float>::EMatrixCreatorsOp2 op, const TMatrixTSym<float>& b) =>
    TypeError: takes at most 3 arguments (4 given)
  TMatrixT<float>::TMatrixT<float>(const TMatrixTSym<float>& a, TMatrixT<float>::EMatrixCreatorsOp2 op, const TMatrixT<float>& b) =>
    TypeError: takes at most 3 arguments (4 given)
  TMatrixT<float>::TMatrixT<float>(const TMatrixTSym<float>& a, TMatrixT<float>::EMatrixCreatorsOp2 op, const TMatrixTSym<float>& b) =>
    TypeError: takes at most 3 arguments (4 given)
  TMatrixT<float>::TMatrixT<float>(TMatrixT<float>::EMatrixCreatorsOp1 op, const TMatrixT<float>& prototype) =>
    TypeError: takes at most 2 arguments (4 given)
  TMatrixT<float>::TMatrixT<float>(int nrows, int ncols, const float* data, const char* option = "") =>
    TypeError: could not convert argument 3 (could not convert argument to buffer or nullptr)
  TMatrixT<float>::TMatrixT<float>(int row_lwb, int row_upb, int col_lwb, int col_upb, const float* data, const char* option = "") =>
    TypeError: takes at least 5 arguments (4 given)
  TMatrixT<float>::TMatrixT<float>() =>
    TypeError: takes at most 0 arguments (4 given)

The type of migration_matrix is

<class cppyy.gbl.TH2D at 0x726fb90>

and migration_matrix.Print("All") returns:

TH1.Print Name  = migration_matrix, Entries= 58190, Total sum= 1634.32
 fSumw[0][0]=0, x=-6.375, y=-6.375, error=0
 fSumw[1][0]=0, x=-4.75, y=-6.375, error=0
 fSumw[2][0]=0, x=-3.25, y=-6.375, error=0
 fSumw[3][0]=0, x=-2.75, y=-6.375, error=0
 fSumw[4][0]=0, x=-2.25, y=-6.375, error=0
 fSumw[5][0]=0, x=-1.75, y=-6.375, error=0
 fSumw[6][0]=0, x=-1.25, y=-6.375, error=0
 fSumw[7][0]=0, x=-0.75, y=-6.375, error=0
 fSumw[8][0]=0, x=-0.25, y=-6.375, error=0
 fSumw[9][0]=0, x=0.25, y=-6.375, error=0
 fSumw[10][0]=0, x=0.75, y=-6.375, error=0
 fSumw[11][0]=0, x=1.25, y=-6.375, error=0
 fSumw[12][0]=0, x=1.75, y=-6.375, error=0
 fSumw[13][0]=0, x=2.25, y=-6.375, error=0
 fSumw[14][0]=0, x=2.75, y=-6.375, error=0
 fSumw[15][0]=0, x=3.25, y=-6.375, error=0
 fSumw[16][0]=0, x=4.75, y=-6.375, error=0
 fSumw[17][0]=0, x=6.375, y=-6.375, error=0
 fSumw[0][1]=0, x=-6.375, y=-4.75, error=0
 fSumw[1][1]=10.6512, x=-4.75, y=-4.75, error=0.639735
 fSumw[2][1]=0.0417575, x=-3.25, y=-4.75, error=0.0384068
 fSumw[3][1]=0, x=-2.75, y=-4.75, error=0
 fSumw[4][1]=0, x=-2.25, y=-4.75, error=0
 fSumw[5][1]=0, x=-1.75, y=-4.75, error=0
 fSumw[6][1]=0, x=-1.25, y=-4.75, error=0
 fSumw[7][1]=0, x=-0.75, y=-4.75, error=0
 fSumw[8][1]=0, x=-0.25, y=-4.75, error=0
 fSumw[9][1]=0, x=0.25, y=-4.75, error=0
 fSumw[10][1]=0, x=0.75, y=-4.75, error=0
 fSumw[11][1]=0, x=1.25, y=-4.75, error=0
 fSumw[12][1]=0, x=1.75, y=-4.75, error=0
 fSumw[13][1]=0, x=2.25, y=-4.75, error=0
 fSumw[14][1]=0, x=2.75, y=-4.75, error=0
 fSumw[15][1]=0, x=3.25, y=-4.75, error=0
 fSumw[16][1]=0.0381766, x=4.75, y=-4.75, error=0.0381766
 fSumw[17][1]=0, x=6.375, y=-4.75, error=0
 fSumw[0][2]=0, x=-6.375, y=-3.25, error=0
 fSumw[1][2]=0, x=-4.75, y=-3.25, error=0
 fSumw[2][2]=25.1344, x=-3.25, y=-3.25, error=1.01179
 fSumw[3][2]=0.0615855, x=-2.75, y=-3.25, error=0.0421989
 fSumw[4][2]=0, x=-2.25, y=-3.25, error=0
 fSumw[5][2]=0, x=-1.75, y=-3.25, error=0
 fSumw[6][2]=0, x=-1.25, y=-3.25, error=0
 fSumw[7][2]=0, x=-0.75, y=-3.25, error=0
 fSumw[8][2]=0, x=-0.25, y=-3.25, error=0
 fSumw[9][2]=0, x=0.25, y=-3.25, error=0
 fSumw[10][2]=0, x=0.75, y=-3.25, error=0
 fSumw[11][2]=0, x=1.25, y=-3.25, error=0
 fSumw[12][2]=0, x=1.75, y=-3.25, error=0
 fSumw[13][2]=0.112738, x=2.25, y=-3.25, error=0.0673522
 fSumw[14][2]=0, x=2.75, y=-3.25, error=0
 fSumw[15][2]=0, x=3.25, y=-3.25, error=0
 fSumw[16][2]=0, x=4.75, y=-3.25, error=0
 fSumw[17][2]=0, x=6.375, y=-3.25, error=0
 fSumw[0][3]=0, x=-6.375, y=-2.75, error=0
 fSumw[1][3]=0, x=-4.75, y=-2.75, error=0
 fSumw[2][3]=0.551896, x=-3.25, y=-2.75, error=0.185246
 fSumw[3][3]=56.3238, x=-2.75, y=-2.75, error=1.52229
 fSumw[4][3]=0.614382, x=-2.25, y=-2.75, error=0.155521
 fSumw[5][3]=0, x=-1.75, y=-2.75, error=0
 fSumw[6][3]=0, x=-1.25, y=-2.75, error=0
 fSumw[7][3]=0, x=-0.75, y=-2.75, error=0
 fSumw[8][3]=0, x=-0.25, y=-2.75, error=0
 fSumw[9][3]=0, x=0.25, y=-2.75, error=0
 fSumw[10][3]=0, x=0.75, y=-2.75, error=0
 fSumw[11][3]=0.0418291, x=1.25, y=-2.75, error=0.0416461
 fSumw[12][3]=0.126278, x=1.75, y=-2.75, error=0.0641907
 fSumw[13][3]=0.229813, x=2.25, y=-2.75, error=0.094411
 fSumw[14][3]=0.194029, x=2.75, y=-2.75, error=0.0834439
 fSumw[15][3]=0, x=3.25, y=-2.75, error=0
 fSumw[16][3]=0, x=4.75, y=-2.75, error=0
 fSumw[17][3]=0, x=6.375, y=-2.75, error=0
 fSumw[0][4]=0, x=-6.375, y=-2.25, error=0
 fSumw[1][4]=0, x=-4.75, y=-2.25, error=0
 fSumw[2][4]=0, x=-3.25, y=-2.25, error=0
 fSumw[3][4]=0.653539, x=-2.75, y=-2.25, error=0.156851
 fSumw[4][4]=103.98, x=-2.25, y=-2.25, error=2.051
 fSumw[5][4]=1.30982, x=-1.75, y=-2.25, error=0.263594
 fSumw[6][4]=0, x=-1.25, y=-2.25, error=0
 fSumw[7][4]=0, x=-0.75, y=-2.25, error=0
 fSumw[8][4]=0, x=-0.25, y=-2.25, error=0
 fSumw[9][4]=0.0327656, x=0.25, y=-2.25, error=0.0327656
 fSumw[10][4]=0.250593, x=0.75, y=-2.25, error=0.0984369
 fSumw[11][4]=0.55048, x=1.25, y=-2.25, error=0.146495
 fSumw[12][4]=0.603139, x=1.75, y=-2.25, error=0.158141
 fSumw[13][4]=0.27152, x=2.25, y=-2.25, error=0.103726
 fSumw[14][4]=0.141726, x=2.75, y=-2.25, error=0.0822942
 fSumw[15][4]=0, x=3.25, y=-2.25, error=0
 fSumw[16][4]=0, x=4.75, y=-2.25, error=0
 fSumw[17][4]=0, x=6.375, y=-2.25, error=0
 fSumw[0][5]=0, x=-6.375, y=-1.75, error=0
 fSumw[1][5]=0, x=-4.75, y=-1.75, error=0
 fSumw[2][5]=0, x=-3.25, y=-1.75, error=0
 fSumw[3][5]=0, x=-2.75, y=-1.75, error=0
 fSumw[4][5]=0.976611, x=-2.25, y=-1.75, error=0.190733
 fSumw[5][5]=161.774, x=-1.75, y=-1.75, error=2.56208
 fSumw[6][5]=1.2852, x=-1.25, y=-1.75, error=0.219714
 fSumw[7][5]=0.0249671, x=-0.75, y=-1.75, error=0.0249671
 fSumw[8][5]=0.252351, x=-0.25, y=-1.75, error=0.104038
 fSumw[9][5]=0.354551, x=0.25, y=-1.75, error=0.107499
 fSumw[10][5]=0.99982, x=0.75, y=-1.75, error=0.19421
 fSumw[11][5]=0.8333, x=1.25, y=-1.75, error=0.18344
 fSumw[12][5]=0.358296, x=1.75, y=-1.75, error=0.115839
 fSumw[13][5]=0.147636, x=2.25, y=-1.75, error=0.0758021
 fSumw[14][5]=0.0383323, x=2.75, y=-1.75, error=0.0383323
 fSumw[15][5]=0, x=3.25, y=-1.75, error=0
 fSumw[16][5]=0, x=4.75, y=-1.75, error=0
 fSumw[17][5]=0, x=6.375, y=-1.75, error=0
 fSumw[0][6]=0, x=-6.375, y=-1.25, error=0
 fSumw[1][6]=0, x=-4.75, y=-1.25, error=0
 fSumw[2][6]=0, x=-3.25, y=-1.25, error=0
 fSumw[3][6]=0, x=-2.75, y=-1.25, error=0
 fSumw[4][6]=0, x=-2.25, y=-1.25, error=0
 fSumw[5][6]=1.95469, x=-1.75, y=-1.25, error=0.28075
 fSumw[6][6]=182.603, x=-1.25, y=-1.25, error=2.7323
 fSumw[7][6]=1.59815, x=-0.75, y=-1.25, error=0.255671
 fSumw[8][6]=0.597199, x=-0.25, y=-1.25, error=0.154758
 fSumw[9][6]=0.921672, x=0.25, y=-1.25, error=0.234942
 fSumw[10][6]=0.7385, x=0.75, y=-1.25, error=0.174382
 fSumw[11][6]=0.626941, x=1.25, y=-1.25, error=0.159702
 fSumw[12][6]=0.43144, x=1.75, y=-1.25, error=0.131828
 fSumw[13][6]=0, x=2.25, y=-1.25, error=0
 fSumw[14][6]=0, x=2.75, y=-1.25, error=0
 fSumw[15][6]=0, x=3.25, y=-1.25, error=0
 fSumw[16][6]=0, x=4.75, y=-1.25, error=0
 fSumw[17][6]=0, x=6.375, y=-1.25, error=0
 fSumw[0][7]=0, x=-6.375, y=-0.75, error=0
 fSumw[1][7]=0, x=-4.75, y=-0.75, error=0
 fSumw[2][7]=0, x=-3.25, y=-0.75, error=0
 fSumw[3][7]=0, x=-2.75, y=-0.75, error=0
 fSumw[4][7]=0, x=-2.25, y=-0.75, error=0
 fSumw[5][7]=0.0219406, x=-1.75, y=-0.75, error=0.0219406
 fSumw[6][7]=1.73104, x=-1.25, y=-0.75, error=0.266314
 fSumw[7][7]=146.859, x=-0.75, y=-0.75, error=2.4441
 fSumw[8][7]=1.85875, x=-0.25, y=-0.75, error=0.306077
 fSumw[9][7]=0.603129, x=0.25, y=-0.75, error=0.152647
 fSumw[10][7]=0.383637, x=0.75, y=-0.75, error=0.119996
 fSumw[11][7]=0.441446, x=1.25, y=-0.75, error=0.13583
 fSumw[12][7]=0.0415078, x=1.75, y=-0.75, error=0.0415078
 fSumw[13][7]=0, x=2.25, y=-0.75, error=0
 fSumw[14][7]=0, x=2.75, y=-0.75, error=0
 fSumw[15][7]=0, x=3.25, y=-0.75, error=0
 fSumw[16][7]=0, x=4.75, y=-0.75, error=0
 fSumw[17][7]=0, x=6.375, y=-0.75, error=0
 fSumw[0][8]=0, x=-6.375, y=-0.25, error=0
 fSumw[1][8]=0, x=-4.75, y=-0.25, error=0
 fSumw[2][8]=0, x=-3.25, y=-0.25, error=0
 fSumw[3][8]=0, x=-2.75, y=-0.25, error=0
 fSumw[4][8]=0, x=-2.25, y=-0.25, error=0
 fSumw[5][8]=0, x=-1.75, y=-0.25, error=0
 fSumw[6][8]=0.102035, x=-1.25, y=-0.25, error=0.059336
 fSumw[7][8]=1.00282, x=-0.75, y=-0.25, error=0.199051
 fSumw[8][8]=101.52, x=-0.25, y=-0.25, error=2.08394
 fSumw[9][8]=0.983514, x=0.25, y=-0.25, error=0.199826
 fSumw[10][8]=0.243873, x=0.75, y=-0.25, error=0.100432
 fSumw[11][8]=0.100494, x=1.25, y=-0.25, error=0.0666275
 fSumw[12][8]=0.0441668, x=1.75, y=-0.25, error=0.0441668
 fSumw[13][8]=0, x=2.25, y=-0.25, error=0
 fSumw[14][8]=0, x=2.75, y=-0.25, error=0
 fSumw[15][8]=0, x=3.25, y=-0.25, error=0
 fSumw[16][8]=0, x=4.75, y=-0.25, error=0
 fSumw[17][8]=0, x=6.375, y=-0.25, error=0
 fSumw[0][9]=0, x=-6.375, y=0.25, error=0
 fSumw[1][9]=0, x=-4.75, y=0.25, error=0
 fSumw[2][9]=0, x=-3.25, y=0.25, error=0
 fSumw[3][9]=0, x=-2.75, y=0.25, error=0
 fSumw[4][9]=0, x=-2.25, y=0.25, error=0
 fSumw[5][9]=0, x=-1.75, y=0.25, error=0
 fSumw[6][9]=0.24545, x=-1.25, y=0.25, error=0.101302
 fSumw[7][9]=0.318565, x=-0.75, y=0.25, error=0.109254
 fSumw[8][9]=1.40648, x=-0.25, y=0.25, error=0.23156
 fSumw[9][9]=101.101, x=0.25, y=0.25, error=2.06796
 fSumw[10][9]=1.15076, x=0.75, y=0.25, error=0.210839
 fSumw[11][9]=0.118199, x=1.25, y=0.25, error=0.0675762
 fSumw[12][9]=0, x=1.75, y=0.25, error=0
 fSumw[13][9]=0, x=2.25, y=0.25, error=0
 fSumw[14][9]=0, x=2.75, y=0.25, error=0
 fSumw[15][9]=0, x=3.25, y=0.25, error=0
 fSumw[16][9]=0, x=4.75, y=0.25, error=0
 fSumw[17][9]=0, x=6.375, y=0.25, error=0
 fSumw[0][10]=0, x=-6.375, y=0.75, error=0
 fSumw[1][10]=0, x=-4.75, y=0.75, error=0
 fSumw[2][10]=0, x=-3.25, y=0.75, error=0
 fSumw[3][10]=0, x=-2.75, y=0.75, error=0
 fSumw[4][10]=0, x=-2.25, y=0.75, error=0
 fSumw[5][10]=0.0582596, x=-1.75, y=0.75, error=0.0396236
 fSumw[6][10]=0.417815, x=-1.25, y=0.75, error=0.126769
 fSumw[7][10]=0.382502, x=-0.75, y=0.75, error=0.111245
 fSumw[8][10]=0.479979, x=-0.25, y=0.75, error=0.138567
 fSumw[9][10]=1.04596, x=0.25, y=0.75, error=0.202219
 fSumw[10][10]=148.227, x=0.75, y=0.75, error=2.4826
 fSumw[11][10]=1.8195, x=1.25, y=0.75, error=0.281392
 fSumw[12][10]=0.0457793, x=1.75, y=0.75, error=0.0323825
 fSumw[13][10]=0, x=2.25, y=0.75, error=0
 fSumw[14][10]=0, x=2.75, y=0.75, error=0
 fSumw[15][10]=0, x=3.25, y=0.75, error=0
 fSumw[16][10]=0, x=4.75, y=0.75, error=0
 fSumw[17][10]=0, x=6.375, y=0.75, error=0
 fSumw[0][11]=0, x=-6.375, y=1.25, error=0
 fSumw[1][11]=0, x=-4.75, y=1.25, error=0
 fSumw[2][11]=0, x=-3.25, y=1.25, error=0
 fSumw[3][11]=0, x=-2.75, y=1.25, error=0
 fSumw[4][11]=0.039065, x=-2.25, y=1.25, error=0.038243
 fSumw[5][11]=0.390264, x=-1.75, y=1.25, error=0.122746
 fSumw[6][11]=0.475941, x=-1.25, y=1.25, error=0.131204
 fSumw[7][11]=0.842642, x=-0.75, y=1.25, error=0.191532
 fSumw[8][11]=0.643777, x=-0.25, y=1.25, error=0.167485
 fSumw[9][11]=0.90099, x=0.25, y=1.25, error=0.200424
 fSumw[10][11]=2.02709, x=0.75, y=1.25, error=0.295635
 fSumw[11][11]=185.744, x=1.25, y=1.25, error=2.75706
 fSumw[12][11]=2.0484, x=1.75, y=1.25, error=0.301028
 fSumw[13][11]=0, x=2.25, y=1.25, error=0
 fSumw[14][11]=0, x=2.75, y=1.25, error=0
 fSumw[15][11]=0, x=3.25, y=1.25, error=0
 fSumw[16][11]=0, x=4.75, y=1.25, error=0
 fSumw[17][11]=0, x=6.375, y=1.25, error=0
 fSumw[0][12]=0, x=-6.375, y=1.75, error=0
 fSumw[1][12]=0, x=-4.75, y=1.75, error=0
 fSumw[2][12]=0, x=-3.25, y=1.75, error=0
 fSumw[3][12]=0.0355688, x=-2.75, y=1.75, error=0.0355688
 fSumw[4][12]=0.19822, x=-2.25, y=1.75, error=0.0883422
 fSumw[5][12]=0.212388, x=-1.75, y=1.75, error=0.0901603
 fSumw[6][12]=0.8478, x=-1.25, y=1.75, error=0.203135
 fSumw[7][12]=0.741737, x=-0.75, y=1.75, error=0.173832
 fSumw[8][12]=0.485584, x=-0.25, y=1.75, error=0.137951
 fSumw[9][12]=0.254941, x=0.25, y=1.75, error=0.0968707
 fSumw[10][12]=0.041354, x=0.75, y=1.75, error=0.041354
 fSumw[11][12]=1.2837, x=1.25, y=1.75, error=0.264369
 fSumw[12][12]=164.948, x=1.75, y=1.75, error=2.62351
 fSumw[13][12]=1.04293, x=2.25, y=1.75, error=0.202746
 fSumw[14][12]=0, x=2.75, y=1.75, error=0
 fSumw[15][12]=0, x=3.25, y=1.75, error=0
 fSumw[16][12]=0, x=4.75, y=1.75, error=0
 fSumw[17][12]=0, x=6.375, y=1.75, error=0
 fSumw[0][13]=0, x=-6.375, y=2.25, error=0
 fSumw[1][13]=0, x=-4.75, y=2.25, error=0
 fSumw[2][13]=0, x=-3.25, y=2.25, error=0
 fSumw[3][13]=0, x=-2.75, y=2.25, error=0
 fSumw[4][13]=0.268342, x=-2.25, y=2.25, error=0.10809
 fSumw[5][13]=0.713007, x=-1.75, y=2.25, error=0.217864
 fSumw[6][13]=0.302637, x=-1.25, y=2.25, error=0.10978
 fSumw[7][13]=0.0822815, x=-0.75, y=2.25, error=0.058267
 fSumw[8][13]=0.0461574, x=-0.25, y=2.25, error=0.0461574
 fSumw[9][13]=0, x=0.25, y=2.25, error=0
 fSumw[10][13]=0, x=0.75, y=2.25, error=0
 fSumw[11][13]=0, x=1.25, y=2.25, error=0
 fSumw[12][13]=1.7095, x=1.75, y=2.25, error=0.269559
 fSumw[13][13]=104.289, x=2.25, y=2.25, error=2.07488
 fSumw[14][13]=0.341677, x=2.75, y=2.25, error=0.110283
 fSumw[15][13]=0, x=3.25, y=2.25, error=0
 fSumw[16][13]=0, x=4.75, y=2.25, error=0
 fSumw[17][13]=0, x=6.375, y=2.25, error=0
 fSumw[0][14]=0, x=-6.375, y=2.75, error=0
 fSumw[1][14]=0, x=-4.75, y=2.75, error=0
 fSumw[2][14]=0.035773, x=-3.25, y=2.75, error=0.035773
 fSumw[3][14]=0.111026, x=-2.75, y=2.75, error=0.0644898
 fSumw[4][14]=0.0818691, x=-2.25, y=2.75, error=0.0488416
 fSumw[5][14]=0.287489, x=-1.75, y=2.75, error=0.102648
 fSumw[6][14]=0, x=-1.25, y=2.75, error=0
 fSumw[7][14]=0, x=-0.75, y=2.75, error=0
 fSumw[8][14]=0, x=-0.25, y=2.75, error=0
 fSumw[9][14]=0, x=0.25, y=2.75, error=0
 fSumw[10][14]=0, x=0.75, y=2.75, error=0
 fSumw[11][14]=0, x=1.25, y=2.75, error=0
 fSumw[12][14]=0, x=1.75, y=2.75, error=0
 fSumw[13][14]=0.384547, x=2.25, y=2.75, error=0.118216
 fSumw[14][14]=54.7759, x=2.75, y=2.75, error=1.47236
 fSumw[15][14]=0.0151413, x=3.25, y=2.75, error=0.00998853
 fSumw[16][14]=0, x=4.75, y=2.75, error=0
 fSumw[17][14]=0, x=6.375, y=2.75, error=0
 fSumw[0][15]=0, x=-6.375, y=3.25, error=0
 fSumw[1][15]=0, x=-4.75, y=3.25, error=0
 fSumw[2][15]=0.0450618, x=-3.25, y=3.25, error=0.0315717
 fSumw[3][15]=0.0786808, x=-2.75, y=3.25, error=0.0556475
 fSumw[4][15]=0.159738, x=-2.25, y=3.25, error=0.125418
 fSumw[5][15]=0, x=-1.75, y=3.25, error=0
 fSumw[6][15]=0, x=-1.25, y=3.25, error=0
 fSumw[7][15]=0, x=-0.75, y=3.25, error=0
 fSumw[8][15]=0, x=-0.25, y=3.25, error=0
 fSumw[9][15]=0, x=0.25, y=3.25, error=0
 fSumw[10][15]=0, x=0.75, y=3.25, error=0
 fSumw[11][15]=0, x=1.25, y=3.25, error=0
 fSumw[12][15]=0, x=1.75, y=3.25, error=0
 fSumw[13][15]=0, x=2.25, y=3.25, error=0
 fSumw[14][15]=0.271294, x=2.75, y=3.25, error=0.100657
 fSumw[15][15]=25.1109, x=3.25, y=3.25, error=1.03965
 fSumw[16][15]=0.142877, x=4.75, y=3.25, error=0.0830937
 fSumw[17][15]=0, x=6.375, y=3.25, error=0
 fSumw[0][16]=0, x=-6.375, y=4.75, error=0
 fSumw[1][16]=0, x=-4.75, y=4.75, error=0
 fSumw[2][16]=0, x=-3.25, y=4.75, error=0
 fSumw[3][16]=0, x=-2.75, y=4.75, error=0
 fSumw[4][16]=0, x=-2.25, y=4.75, error=0
 fSumw[5][16]=0, x=-1.75, y=4.75, error=0
 fSumw[6][16]=0, x=-1.25, y=4.75, error=0
 fSumw[7][16]=0, x=-0.75, y=4.75, error=0
 fSumw[8][16]=0, x=-0.25, y=4.75, error=0
 fSumw[9][16]=0, x=0.25, y=4.75, error=0
 fSumw[10][16]=0, x=0.75, y=4.75, error=0
 fSumw[11][16]=0, x=1.25, y=4.75, error=0
 fSumw[12][16]=0, x=1.75, y=4.75, error=0
 fSumw[13][16]=0, x=2.25, y=4.75, error=0
 fSumw[14][16]=0, x=2.75, y=4.75, error=0
 fSumw[15][16]=0.0882225, x=3.25, y=4.75, error=0.0564516
 fSumw[16][16]=10.588, x=4.75, y=4.75, error=0.643155
 fSumw[17][16]=0, x=6.375, y=4.75, error=0
 fSumw[0][17]=0, x=-6.375, y=6.375, error=0
 fSumw[1][17]=0, x=-4.75, y=6.375, error=0
 fSumw[2][17]=0, x=-3.25, y=6.375, error=0
 fSumw[3][17]=0, x=-2.75, y=6.375, error=0
 fSumw[4][17]=0, x=-2.25, y=6.375, error=0
 fSumw[5][17]=0, x=-1.75, y=6.375, error=0
 fSumw[6][17]=0, x=-1.25, y=6.375, error=0
 fSumw[7][17]=0, x=-0.75, y=6.375, error=0
 fSumw[8][17]=0, x=-0.25, y=6.375, error=0
 fSumw[9][17]=0, x=0.25, y=6.375, error=0
 fSumw[10][17]=0, x=0.75, y=6.375, error=0
 fSumw[11][17]=0, x=1.25, y=6.375, error=0
 fSumw[12][17]=0, x=1.75, y=6.375, error=0
 fSumw[13][17]=0, x=2.25, y=6.375, error=0
 fSumw[14][17]=0, x=2.75, y=6.375, error=0
 fSumw[15][17]=0, x=3.25, y=6.375, error=0
 fSumw[16][17]=0, x=4.75, y=6.375, error=0
 fSumw[17][17]=0, x=6.375, y=6.375, error=0

For someone else in my group with different inputs it works fine, but he also gets a type of TH2F for his migration_matrix. But we do not why this should be causing any issues

Cheers

Jan-Eric

I guess @moneta can help.

@vpadulan looks more like a pythonization bug.

matrix = ROOT.TMatrix(n_bins + 2, n_bins + 2, migration_matrix.GetArray(), “D”)

I guess you wanted to follow the approach originally suggested by Lorenzo? But then you should create a TMatrixD, not a TMatrix:

matrix = ROOT.TMatrixD(n_bins + 2, n_bins + 2, migration_matrix.GetArray(), "D")