Dear root users, I’m facing the following problem. I have a TTree containing events and I would like to process only the events that pass a certain cut and then put these events in to a different TTree. So far, following this topic " root.cern.ch/root/roottalk/roottalk03/4281.html " , I was able to wrote this code:
#include "TFile.h"
#include "TTree.h"
#include "TH2.h"
#include "TEventList.h"
#include "TCutG.h"
#include <iostream>
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int CutSelector(){
TFile *rf = new TFile("NNProva.root");
// TFile *wf = new TFile("NNProvaCut.root","RECREATE");
TTree *readTree = (TTree*)rf->Get("outTree");
/* TTree *writeTree = new TTree("writeTree","Cloned Tree");*/
TCutG *cutg = new TCutG("gamma_cut",5);
cutg->SetVarX("TOF");
cutg->SetVarY("Slow Total Ratio");
cutg->SetTitle("Graph");
cutg->SetPoint(0,10.9311,0.437895);
cutg->SetPoint(1,10.3443,0.365263);
cutg->SetPoint(2,11.029,0.308421);
cutg->SetPoint(3,13.0829,0.374737);
cutg->SetPoint(4,10.9311,0.437895);
readTree->Draw(">>elist","gamma_cut");
TEventList *elist = (TEventList*)gDirectory->Get("elist");
cout<<elist->GetN()<<endl; //It writes the number of events that passed the cut
readTree->SetEventList(elist);
// wf->Write();
// wf->Close();
}
it creates the TEventList “elist” of the events that pass the TCutG “gamma_cut”. Now, how can I access to the events of the TTree that are listed in “elist” so that I can process them (e.g. add another branch with a simple 1/0 tag) and put in another TTree? I’ve read the documentation for the TEventList, TEntryList, TTree classes, but I didn’t found the right method, so clearly I’m missing something.
Also, is this method convenient or should I try to do this task in a different, easier way?
Cheers,
Bart