Hi, Obviously the one inside the loop Clone the tree over and over again, losing the previous information! Remove it! Cheers, Philippe. -----Original Message----- From: Salvatore Rappoccio [mailto:rappoccio@heplcdf2.harvard.edu] Sent: Friday, November 19, 2004 12:45 PM To: Philippe Canal Cc: rappocc@fnal.gov; roottalk@pcroot.cern.ch Subject: RE: [ROOT] Can't strip TChain Hi, Philippe, I put them in both places: SetTheAddresses(chain); // set the address of ALL the top branches on the chain an NOT on the tree 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++; if ( chain->GetTreeNumber() != prevTreeNum ) { SetTheAddresses(chain->GetTree()); prevTreeNum = chain->GetTreeNumber(); if ( stripTree ) { histf->cd(); tskim->AutoSave(); tskim = (TTree *)chain->GetTree()->CloneTree(0); } } .... } Thanks, Sal > Cheers, > Philippe. > > -----Original Message----- > From: Salvatore Rappoccio [mailto:rappoccio@heplcdf2.harvard.edu] > Sent: Friday, November 19, 2004 12:13 PM > To: Philippe Canal > Cc: rappocc@fnal.gov; roottalk@pcroot.cern.ch > Subject: RE: [ROOT] Can't strip TChain > > Hi, Philippe, > > I tried this, and now it seems that I only get the events from the > LAST file of the original chain. > > I also tried adding > > SetTheAddresses(chain); // set the address of ALL the top branches > on the chain an NOT on the tree > if ( stripTree ) { > std::cout << "Setting up strip tree" << std::endl; > histf->cd(); > tskim->AutoSave(); > tskim = (TTree*)chain->GetTree()->CloneTree(0); > } > > > How do I tell the chain written to histf to pick up the earlier data? > > Thanks, > Sal > > > > > Cheers, > > Philippe. > > > > -----Original Message----- > > From: Salvatore Rappoccio [mailto:rappoccio@heplcdf2.harvard.edu] > > Sent: Friday, November 19, 2004 10:31 AM > > To: Philippe Canal > > Cc: roottalk@pcroot.cern.ch > > Subject: RE: [ROOT] Can't strip TChain > > > > Hi, Philippe, > > > > I'm using 3.05/07. I'll give this a try. > > > > Thanks! > > Sal > > > > On Thu, 18 Nov 2004, Philippe Canal wrote: > > > > > Hi Salvatore, > > > > > > Which version of ROOT are using? > > > > > > The problem is that you seemingly are setting the addresses of the > > > underlying original tree but not the addresses of the cloned tree: > > > > > > if ( chain->GetTreeNumber() != prevTreeNum ) { > > > SetTheAddresses(chain->GetTree()); > > > prevTreeNum = chain->GetTreeNumber(); > > > } > > > > > > In recent version of ROOT, it is sufficient to set the address of > > > the original chain (using SetBranchAddress). > > > > > > Cheers, > > > Philippe. > > > > > > -----Original Message----- > > > From: owner-roottalk@pcroot.cern.ch > > > [mailto:owner-roottalk@pcroot.cern.ch] > > > On Behalf Of Salvatore Rappoccio > > > Sent: Thursday, November 18, 2004 2:34 PM > > > To: roottalk@pcroot.cern.ch > > > Subject: [ROOT] Can't strip TChain > > > > > > 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