# Dataloader GetCorrelationMatrix

**URL:** <https://root-forum.cern.ch/t/dataloader-getcorrelationmatrix/34439>\
**Category:** TMVA\
**Created:** [June 5, 2019, 2:36pm UTC](https://root-forum.cern.ch/t/dataloader-getcorrelationmatrix/34439 "2019-06-05T14:36:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ethorpe](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/d78d45/32.png) [@ethorpe](https://root-forum.cern.ch/u/ethorpe)\
**Post date:** [June 5, 2019, 2:36pm UTC](https://root-forum.cern.ch/t/dataloader-getcorrelationmatrix/34439/1 "2019-06-05T14:36:02Z")

</div>

Hi,

I’m attempting to use h2D = dataloader.GetCorrelationMatrix(“Signal”)

to use the TMVA functionality to draw a correlation matrix only

This is currently returning a null pointer for me

> dataloader = TMVA.DataLoader(weightPath+“HighMass/dataset\_”+weightfilename+“”);  
> for (varname,vartype) in trained\_variables:  
> dataloader.AddVariable(varname,vartype)  
> #load signal  
> dataloader.AddSignalTree(signal[“NominalFixed”], 1.0) #2nd argument is a weight  
> #load backgrounds  
> for bkg in backgrounds:  
> dataloader.AddBackgroundTree(backgrounds[bkg][“NominalFixed”],1.0)  
> analysiscuts=ROOT.TCut(cuts)  
> dataloader.SetBackgroundWeightExpression( AnalysisWeights );  
> dataloader.SetSignalWeightExpression ( AnalysisWeights );  
> h2D = dataloader.GetCorrelationMatrix(“Signal”)  
> print (“-----------------------------”)  
> print (h2D)  
> print (“-----------------------------”)  
> from PlotMaker import PlotMaker  
> savepath=Driver.savepath  
> pltm=PlotMaker()  
> pltm.setSavePath(savepath+“/”+loaded\_samples.name+“/2D/”)  
> pltm.setupPlot(“signal”)  
> pltm.drawTopPad(lambda x: h2D.Draw(“colz text”))  
> pltm.update()  
> pltm.saveAs([“.pdf”])  
> outputFile.Close()

If anybody has any advice I would be very grateful

I’ve attached my full code[TMVAhelp.py](https://root-forum.cern.ch/uploads/default/original/3X/8/f/8f4f7cd60d1cb70fbc111d4c3fbd6d59bcfd505c.py) (9.6 KB)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 5, 2019, 2:39pm UTC](https://root-forum.cern.ch/t/dataloader-getcorrelationmatrix/34439/2 "2019-06-05T14:39:11Z")

</div>

I guess @moneta or @kialbert can help you.

---

<div class="post-metadata">

**Author:** ![kialbert](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kialbert/32/16537_2.png) [@kialbert](https://root-forum.cern.ch/u/kialbert)\
**Post date:** [June 6, 2019, 5:43pm UTC](https://root-forum.cern.ch/t/dataloader-getcorrelationmatrix/34439/3 "2019-06-06T17:43:19Z")

</div>

Hi, This could be a sign that the dataset is not generated yet. The dataset is generated lazily upon request (but apparently not all paths are covered). Thus you need to explicitly trigger the generation before requesting the correlation matrix.

Add these lines before your call to GetCorrelationMatrix:

```auto
d.PrepareTrainingAndTestTree(ROOT.TCut("<global sig cut>"),
                             ROOT.TCut("<global bkg cut>"),
                             "<additional options (can be empty)>")
d.GetDataSetInfo().GetDataSet()

```

The first of these 2 statements defines the splitting into training and test sets (see the TMVA tutorial for more info). The second statement then triggers the generation of the dataset.

Cheers,  
Kim
