RooDataSet: categorizing variables store in a TTree

I have a built simple TTree in which each branch corresponds to the measurement made under different assumptions. For instance:

Tree : data
Br 1: Mass_a/F
Br 2: Mass_b/F
Br 3: Mass_c/F

Where {a,b,c…} are the different categories.
I would like to import this TTree to a RooDataSet having a unique variable which is Mass but different categories {a,b,c…}.
What is the best way to do this operation?
Is there any tutorial where a similar operation is done?
Many thanks in advance,

Hi Pedro,

There is ‘magic’ command to do this, but it can be done
in a couple of steps.

First you need to make three separate datasets for a,b,c and
make the observable name the same

RooDataSet data_a(“data_a”,“data_a”,Mass_a,Import(myTree)) ;
data_a.changeObservable(“Mass_a”,“mass”) ;

//repeat for b,c

then merge them into a new dataset with the index

RooCategory idx(“idx”,“idx”) ;
RooDataSet simdata(“simdata”,“simdata”,RooArgSet(idx,mass),Index(idx),Import(“a”,*data_a),Import(“b”,*data_b),Import(“c”,*data_c")) ;