# Read different size of vector using TMVA macro

**URL:** <https://root-forum.cern.ch/t/read-different-size-of-vector-using-tmva-macro/31130>\
**Category:** TMVA\
**Created:** [October 16, 2018, 1:45pm UTC](https://root-forum.cern.ch/t/read-different-size-of-vector-using-tmva-macro/31130 "2018-10-16T13:45:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hokyeong](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/hokyeong/32/16928_2.png) [@Hokyeong](https://root-forum.cern.ch/u/Hokyeong)\
**Post date:** [October 16, 2018, 1:45pm UTC](https://root-forum.cern.ch/t/read-different-size-of-vector-using-tmva-macro/31130/1 "2018-10-16T13:45:13Z")

</div>

Dear experts,

I tried modify the TMVAClassification.C macro to analysis for single electron data  
and I get the following message.

: Dataset[dataset] : ERROR while preparing training and testing trees:  
: Dataset[dataset] : multiple array-type expressions of different length were encountered  
: Dataset[dataset] : location of error: event 0 in tree Signal\_Tree of file SingleElectron.root  
: Dataset[dataset] : expression track\_R has Dataset[dataset] : 3 entries, while  
: Dataset[dataset] : expression track\_Eta has Dataset[dataset] : 6 entries  
: Dataset[dataset] : Need to abort  
\*\*\*\> abort program execution  
terminate called after throwing an instance of ‘std::runtime\_error’  
what(): FATAL error

The data file I used have variable which is consist of vector of different size.  
According to error message, that fact seems to be causing error.

> [@Vector entries in TMVAClassification and Application](https://root-forum.cern.ch/t/vector-entries-in-tmvaclassification-and-application/30124):
>
> Hello dear ROOTforum, I have trouble with TMVA’s macros. The tree source has branches type vector, in the part of dataloader I put this dataloader-\>AddVariable( "B\_J\_px2", "B\_J\_px2", "units", 'F' ); and works fine. But in the part of Application, I stated the same variables in the part of classification (like tutorial explain) TMVA::Reader \*reader = new TMVA::Reader( "!Color:!Silent" ); // Create a set of variables and declare them to the reader // - the variable names MUST correspon…

I saw the above topic on ROOT forum.  
And found the something I want. In the end of topic kialbert saied “If the vector is of variable size we need to consider another approach.”  
But I have no idea how the problem can solve.  
Please give me some advice.

I attached the macors.  
[TMVAClassification.C](https://root-forum.cern.ch/uploads/default/original/3X/a/0/a03ffcd4b45ab15d2a5bbe2f120647e759dedc8c.C) (3.1 KB)

And this is the data file I used

> **[SingleElectron.root](https://www.dropbox.com/s/tpfuughqxt3n6ty/SingleElectron.root?dl=0)**
>
> Shared with Dropbox

> **[Background.root](https://www.dropbox.com/s/4emclwv86cbbgwy/Background.root?dl=0)**
>
> Shared with Dropbox

Thank you a lot for your help in advance.

Best regards,  
Hokyeong

---

<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:** [October 22, 2018, 9:40am UTC](https://root-forum.cern.ch/t/read-different-size-of-vector-using-tmva-macro/31130/2 "2018-10-22T09:40:44Z")

</div>

Hi,

Could you elaborate on why the two variables have different length? In a single event there should be a set number of tracks, and all variables referring to track data should have an entry for each track.

I don’t see why the branch `track_R` should have only 3 entries while `track_Eta` should have 6 entries.

The most straight forward solution is to reformat your data so that each branch corresponds to a TMVA variable.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![dlin](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@dlin](https://root-forum.cern.ch/u/dlin)\
**Post date:** [August 2, 2019, 9:58pm UTC](https://root-forum.cern.ch/t/read-different-size-of-vector-using-tmva-macro/31130/3 "2019-08-02T21:58:17Z")

</div>

Dear Kim,

I am learning to use the TMVA classification and facing the similar problem. I have a vector branch with different size for different events, I am wondering if it’s possible to add this branch into the dataloader? and how can I do this?

Thank you very much in advance!  
Best regards,  
Dexu

---

<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:** [August 14, 2019, 4:00pm UTC](https://root-forum.cern.ch/t/read-different-size-of-vector-using-tmva-macro/31130/4 "2019-08-14T16:00:55Z")

</div>

Hi,

(In the future, please post a new question instead of reviving an old one. This to help keep better order in the forum. 🙂 )

Unfortunately, the answer is a negative: This is not something TMVA is designed to handle. You can add array _elements_ (e.g. `dataloader->AddVariable("myArrayBranch[0]")`), but not variable length arrays.

Cheers,  
Kim

---

<div class="post-metadata">

**Author:** ![dlin](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@dlin](https://root-forum.cern.ch/u/dlin)\
**Post date:** [August 14, 2019, 5:47pm UTC](https://root-forum.cern.ch/t/read-different-size-of-vector-using-tmva-macro/31130/5 "2019-08-14T17:47:16Z")

</div>

Many thanks for the reply!  
I will keep in mind to post as a new thread.
