Transforming TTree with many variables into a 2D image to use as input for a CNN?

I have a root file that has 360 variables in the TTree. Each variable outputs a 1 or 0 to represent an on or off pixel (18 variables for each row, with a total of 20 rows). Now I want to transform these into a 2D image to feed into the TMVA_CNN_Classification code. How do I properly do that? The example root file is already in an image format, but I’m not sure how to transform my TTree in such a way. Could I simply load each variable one by one in the correct order, and the code knows that it’s taking it in as an image? Such as:

loader.AddVariable(“var1”,“var1”‘I’)

loader.AddVariable(“var360”,“var360”‘I’)

loader.PrepareTrainingAndTestTree(
mycuts,
mycutb,
nTrain_Signal=nTrainSig,
nTrain_Background=nTrainBkg,
SplitMode=“Random”,
SplitSeed=100,
NormMode=“NumEvents”,
V=False,
CalcCorrelations=False,
)

model = Sequential()
model.add(Reshape((20, 18, 1), input_shape=(360,)))
… etc.

Or do I have to do another step in between? Thank you so much.

Hi @abayyari,

thank you for the question. Maybe @moneta could help?

Cheers,
Marta

Thanks for your suggestion, I think it worked and gave good results based off of my ROC plot, but want to be sure it was input correctly.

Hi,
Yes you can add teh variables one by one as you are doing or you can add directly an array using DataLoader::AddVariableArray as in this tutorial.

Best regards

Lorenzo

1 Like