RooCategory cut not being applied on dataset


I’m trying to separate datasets based on their pdg ID numbers. The way I do this is by declaring a RooCategory object, then simply categorize the data based on a variable in my ntuple that stores the pdg ID. In the case of the W and Z (pdg = 24 and 23, respectively), I do something like:

  RooCategory muonCategory("muonCategory","muonCategory");

  RooArgSet muonRecArgSet(muonCategory);

  RooDataSet* ds = new RooDataSet(fileName,fileName,muonArgSet);

  // --- Load the MC tree ---
  int promptNt[50];
  int nmu;
  TChain* tree = new TChain("tree","tree");
  int nFiles = tree->Add(pathName+fileName);
  tree->SetBranchAddress("nmu", &nmu);
  tree->SetBranchAddress("prompt", &promptNt);
   // --- Set branch status ---
  tree->SetBranchStatus("*",0) ;
  tree->SetBranchStatus("nmu", 1);
  tree->SetBranchStatus("prompt", 1);
  for ( int i = 0; i < tree->GetEntries(); ++i ) {

    for (int imu = 0; imu<nmu; ++imu){

      if ( promptNt[imu] == 23) muonArgSet.setCatLabel("muonCategory","Z");
      else if ( promptNt[imu] == 24) muonArgSet.setCatLabel("muonCategory","W");
 ds = (RooDataSet*)ds->reduce(Cut("muonCategory==muonCategory::W"));

However, the number of entries are identical before and after I perform the last line
ds = ds->reduce(Cut(“muonCategory==muonCategory::W”)). I have a work around by making prompt a RooRealVar and cutting on it that way (which gives me the subset I’m looking for). However I’d like to know why the last line doesn’t apply the cut to my data?

I have the same problem.
Here is a small script that summarizes the issue:
ds and ds2 have the same number of events, so no cut was applied.

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("-i", "--input", default=None, action="store", type=str)
    args = parser.parse_args()
    tf = ROOT.TFile(args.input)
    tree = tf.Get("TreePath")
    varList = RooArgSet()
    b_M = RooRealVar( "B0_M", "B0_M", 5000, 6200, Unit="MeV/c^{2}" )
    TIScat = ROOT.RooCategory("B0_L0Global_TIS", "B0_L0Global_TIS")
    TIScat.defineType("passed", 1)
    TIScat.defineType("failed", 0)
    ds = ROOT.RooDataSet("data","data", tree, varList)
    ds2 = ROOT.RooDataSet("data2","data2", ds, varList, 'B0_L0Global_TIS==B0_L0Global_TIS::passed')

A nasty workaround is to define a new leaf that uses instead of the RooCategory a RooRealVar and you cut on it.
Another thing that usually works for me is using RooThresholdCategory, and cutting on it.

Anyway I would really enjoy if anybody can explain me why this is not working.

1 Like

This worked for me:
RooDataSet* d3 = (RooDataSet*) og_asimov->reduce(“channelCat==channelCat::SRWW_Resolved”) ;