Taking the absolute value of all the entries in a TBranch in RooFit

Hi I have a million entries in a TBranch and the value for each entry ranges from -2.5 to 2.5. I need to cut another set of data using these entries. Is there any way to turn take the absolute value of all the entries in the TBranch? This is the code I’ve been trying to have work:

 TTree * tree = (TTree*)file->Get("T_mv");
  //find the branch with the data we need in the tree and set the limits
  RooRealVar jpsi("Jpsi_mass", "Mass of Jpsi", 2900, 3300);
  RooRealVar eta1("Muon1_eta","Muon 1's eta", -2.5, 2.5);
  RooRealVar eta2("Muona2_eta","Muon 2's eta", -2.5, 2.5);
  RooDataSet data("data", "Jpsi data set", tree,RooArgSet(jpsi, abs(eta1), abs(eta2)));

I’ve tried using RooAbsReal to eta1, RooAbsRealLValue to eta1. I just don’t quite know what to do here. I’ve made a separate file where I plot the values for eta1 and keep trying to find a way to turn all my negative values positive but for the time being I’ve had no success. Any help would be really appreciated. Thanks!
ROOT Version: 6.14
RooFit Version: 3.60
Platform: Windows
Compiler: mobatek


You would need to create a new data set and loop on the data and fill with the right values.
For example:

RooDataSet data1("data1", "Jpsi data set (original)", tree,RooArgSet(jpsi, eta1, eta2));
// make a new data set but empty (not attached to the Three)
 RooDataSet data2("data2", "Jpsi data set with abs eta1 and eta2", RooArgSet(jpsi, eta1, eta2));
int nEvent = data1.numEntries(); 
for(int i=nStart; i < nevent ; ++i) {
    auto vars = data1.get(i);
    auto v1 = (RooRealVar*) vars->find("eta1");
    auto v2 = (RooRealVar*) vars->find("eta2");
    v1->setVal( std::abs( v1->getVal() ) );
    v2->setVal( std::abs( v2->getVal() ) );
// now data2 will be filled with the abs value of eta1 and eta2 


Hey Lorenzo,
Thank you so much, it’s not the perfect solution but it’s definitely set me on the corrct bpath. I was considering doing a loop but wasn’t quite sure as to how it would work. I should be able to solve my problem now, thanks!