Only drawing TTree bins with value above a threshold

I have a string-valued TBranch that I’d like to draw, but there are hundreds of potential string values. I only care about the values that have a large number of entries. Is there a one-line way to plot only these values?

The idea is something like:
tree->Draw(“name”, “tree->GetBranch(“name”)->GetEntries()>50”);

though it doesn’t seem that the draw conditions syntax allows for this kind of command.


This is not possible directly. In order to get the information (i.e. "how many of the entries in the TTree has a given value), the whole TTree needs to be scanned (and TTree::Draw scan through the TTree only once). So you need to first create the full histogram:tree->Draw("name >> fullhisto");and then filter it using a routine similar to TH1F *filter(TH1F *input, double limit) { TAxis *axis = input->GetXaxis(); TH1F *output = new TH1F(input->GetName(),input->GetTitle(),input->GetNbinsX(),axis->GetXmin(),axis->GetXmax()); TIter next(axis->GetLabels()); Int_t bin = 1; TObjString *label; while( (label = (TObjString*)next()) ) { double weight = input->GetBinContent(bin); if (weight > limit) { output->Fill( label->GetString(), weight ); } ++bin; } output->LabelsDeflate(); output->Draw(); return output; }and use as TH1F *filtered_histo = filter(fullhisto,50);