selection of ntuple and plot in a Graph

Ulrich Jost (jost@evalo1.ific.uv.es)
Tue, 20 Apr 1999 10:57:30 +0200 (CET)


Hi,

I try to make a selection in an ntuple and plot the surviving points in a
graph, following some examples on the web. In the macro below the entire
ntuple is plotted, ntuple->GetSelectedRows() gives 0. So how do I make the
events 'selected'?
We still have version 2.00/13.

Thanks, Ulrich

{
gROOT->Reset();

TFile* file = new TFile("data/test_repVI_17.4.1999_15:36:54.root",
"read");
TNtuple* ntuple = (TNtuple*) file->Get("ntuple");
TCanvas *canvas = new TCanvas("canvas", "ROOT Canvas", 500, 500);

static Float_t r;

TBranch *brep = ntuple->GetBranch("rep");
brep->SetAddress(&r);

Int_t nevent = ntuple->GetEntries();
Int_t nselected = 0;
Float_t repold = -1;

for (Int_t i=0; i<nevent; i++) {
brep->GetEvent(i); // read branch 'rep' only
if (r == repold) // make some cuts, whatever
continue;
else
repold = r;
ntuple->GetEvent(i); //read complete accepted event in memory. This
// seems not to mark the event as 'selected'.
nselected++;
}

cout<<"GetSelectedRows: "<<ntuple->GetSelectedRows()<<endl;
ntuple->SetEstimate(ntuple->GetSelectedRows());
ntuple->Draw("sy:rep", "", "goff");
TGraph *graph = new TGraph(ntuple->GetSelectedRows(),
ntuple->GetV2(), ntuple->GetV1());
graph->Draw("ac*");

}