I have a Tree that contains a series of events. In each event I have several candidate particles and I store the physics parameters for each particle in a variable length array. For each event the variable length arrays are the same length but they can be different between events. Unfortunately I didn’t put anything in to count the number of candidates per event.
Up until now this has caused no problem because if I want to plot a histogram I can do:
TFile *f = new TFile(“BsJpsiphi.root”);
TTree t = (TTree)f->Get(“CollectionTree”);
t->Draw(“BsMass”, “BsPt > 10000 && BsChi2 < 6”);
// BsMass, BsPt and BsChi2 are all variable length arrays for each event
This will plot all the candidates that pass the cuts. However what I now want to do is plot the candidate with the lowest Chi2 for each event (as long as it meets the other cuts). There might be some fancy ROOT class that already does this but I haven’t found it!
The only way I can think of doing this is to access the events individually using getEntry and then sort them manually myself before filling a histogram. So far I have been unable to use the code below (which I took straight from the manual) because BsMass is an array of floats not just one.
Int_t nentries = (Int_t)t->GetEntries();
Float_t BsMass;
t->SetBranchAddress(“BsMass”, &BsMass);
for (int i = 0; i<nentries; i++) {
t.GetEntry(i);
cout << "Bs Mass = " << BsMass << endl;
}
I hope this makes sense. Thanks for any help in advance.