[ROOT] Can't strip TChain

From: Salvatore Rappoccio (rappoccio@heplcdf2.harvard.edu)
Date: Thu Nov 18 2004 - 21:34:24 MET


Hi,

I am trying to read a subset of the events in my TChain object to another 
file, given some selection criteria.

I can write the objects out without complaint, but when I try to read back 
the events that I wrote from the second file of the TChain, I get nonsense 
values.

Any ideas?

My code is:

{
  std::cout << "Getting trees" << std::endl;

  TChain * chain = GetChain();
  TTree * tskim = 0;
  int nskim = 0;
  int counter = 0;
  int prevTreeNum = -1;
  int prevRunNum = -1;
  // Load the tree and set the addresses for the second time
  chain->LoadTree(0);
  chain->GetEntry(0);
  
  if ( stripTree ) {
    std::cout << "Setting up strip tree" << std::endl;
    histf->cd();
    tskim = (TTree*)chain->GetTree()->CloneTree(0);
  }


  prevTreeNum=-1;

  //Loop over the events
  for(int ev=firstEvent; ev<nEvents; ev++) { 
    counter++;
    int lflag = -1;
    lflag = chain->LoadTree(ev);

    // If this tree hasn't already been set, set the branch addresses
    if ( chain->GetTreeNumber() != prevTreeNum ) {
      SetTheAddresses(chain->GetTree());
      prevTreeNum = chain->GetTreeNumber();
    }

    if ( stripTree )
      lflag = chain->GetEntry(ev,1);
    else
      lflag = chain->GetEntry(ev);

    if ( lflag < 0 ) {
      cout << "Error in loading trees" << endl;
      return;
    }
    
    // Decide to strip the event or not
    bool stripEvent = false;

    
    // If this event passes simple cuts, process the
    // event, returning strip status
    if ( PassCuts( ev, lflag ) ) {
      stripEvent = Process( ev, lflag );
      // If desired, strip this event and write to file
      if ( stripTree ) {
	tskim->Fill();
	nskim++;
	if ( nskim % 10000 == 0 ) {
	cout << "Writing to strip tree : nskim = " << nskim << endl;
	tskim->AutoSave();
	}
      }
    }
  }

  // Write stuff to output file
  histf->cd();

  // Strip tree
  if ( stripTree ) {
    cout << "Writing to strip tree : nskim = " << nskim << endl;
    tskim->AutoSave();
  }
  histf -> Close();

}


Thanks,
Sal Rappoccio



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:10 MET