RE: [ROOT] How to select events from a chain

From: Philippe Canal (pcanal@fnal.gov)
Date: Fri Oct 04 2002 - 22:11:02 MEST


Hi Milind,

You can do something likne

  Int_t nevents = (Int_t)UpsChain.GetEntries();

  UpsChain.LoadTree(0);
  TFile*newfile = new TFile("newfile.root","NEW");
  TTree*newtree = UpsChain->CloneTree(0);

  for(Int_t iev = 0; iev < nevents; iev++){
    UpsChain.GetEvent(iev);
    ....
    if (...) newtree->Fill();
  }

Cheers,
Philippe.


-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Milind Purohit
Sent: Friday, October 04, 2002 10:40 AM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] How to select events from a chain


I would like to select events in a tree based on cuts. The events are
being read in a chain. Is there a way to write out selected events? In
the code snippet below "mychoice" is a C++ function which selects events
of interest. How do I write them out to one file? This way I could save
a lot of CP time and not read the events of interest over and over
again. I would like to store the entire event, not just the variables
indicated in the "SetBranchAddress" statements below.

Thanks,

Milind Purohit

      .
      .
      .

  TChain UpsChain("h43");

  FILE * RUNEVT;
  RUNEVT = fopen("UpsRunEvt.txt", "w");

  FILE * CHFILE;
  char line[250];
  CHFILE = fopen("UpsChain.txt", "r");
  while((fgets(line, sizeof(line), CHFILE)) != NULL){
    char root_file_name[250];
    sscanf(line, "%s", root_file_name);
    UpsChain.Add(root_file_name);
  }

//Declaration of leaves types
  Int_t           event;
  Int_t           runnumber;

  Int_t           nchb;
  Float_t         masschb[100];   //[nchb]

  UpsChain.SetBranchAddress("event",&event);
  UpsChain.SetBranchAddress("runnumber",&runnumber);

  UpsChain.SetBranchAddress("nchb",&nchb);
  UpsChain.SetBranchAddress("masschb",&masschb);

  Int_t nevents = (Int_t)UpsChain.GetEntries();

  for(Int_t iev = 0; iev < nevents; iev++){
    UpsChain.GetEvent(iev);

    if(mychoice(myvars)){
      ???????
    }
  }

      .
      .
      .



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:12 MET