TTree::Draw, gate not being applied

When drawing a histogram from a TTree, gates that I pass seem to be applied inconsistently. The order in which gates are specified seems to affect whether the gate is applied at all. In addition, remaking a histogram with the same parameters does not reproduce the same histogram.

Below are two scripts that demonstrate the issue. The first script generates a TTree and saves it to a file. The second script creates gated histograms based on that tree, then prints the number of entries in those histograms. Based on the values generated in the tree, each of the histograms generated by the second script should have exactly 256 counts. However, the first histogram has 512 counts, the second 256, and the third has 0. The first and third histograms are created with an identical gate, and so they should be identical. The first and second histograms differ only in the order of the gates, which shouldn’t change anything.

[code]void generate_file(){
TFile *tf = new TFile(“dummy_data.root”,“recreate”);
TTree *tree = new TTree(“tree”, “tree”);

double a,b,c,d,e;

tree->Branch(“a”, &a, “a/D”);
tree->Branch(“b”, &b, “b/D”);
tree->Branch(“c”, &c, “c/D”);
tree->Branch(“d”, &d, “d/D”);
tree->Branch(“e”, &e, “e/D”);

for (int i = 0; i < 2048; i++){
if(i % 2 == 0){
// Inside cutg_1
a = 0;
b = 0;
} else {
a = 5;
b = 5;
}

if(i % 4 < 2){
  // Inside cutg_2
  c = 0;
  d = 0;
} else {
  c = 5;
  d = 5;
}

e = i/1024.0;

tree->Fill();

}

tree->Write("",TObject::kOverwrite);
tf->Close();
}
[/code]

[code]void plot_from_file(){
TFile *tf = TFile::Open(“dummy_data.root”);

TCutG* cutg_1 = new TCutG(“cutg_1”,4);
cutg_1->SetVarX(“a”);
cutg_1->SetVarY(“b”);
cutg_1->SetPoint(0, -1, -1);
cutg_1->SetPoint(1, -1, 1);
cutg_1->SetPoint(2, 1, 1);
cutg_1->SetPoint(3, 1, -1);

TCutG *cutg_2 = new TCutG(“cutg_2”,8);
cutg_2->SetVarX(“c”);
cutg_2->SetVarY(“d”);
cutg_2->SetPoint(0, -1, -1);
cutg_2->SetPoint(1, -1, 1);
cutg_2->SetPoint(2, 1, 1);
cutg_2->SetPoint(3, 1, -1);

tree->Project(“h1”, “1”,
“cutg_1 && cutg_2 && e < 1”);
std::cout << "h1 counts: " << h1->GetEntries() << std::endl;

tree->Project(“h2”, “1”,
“e < 1 && cutg_1 && cutg_2”);
std::cout << "h2 counts: " << h2->GetEntries() << std::endl;

tree->Project(“h3”, “1”,
“cutg_1 && cutg_2 && e < 1”);
std::cout << "h3 counts: " << h3->GetEntries() << std::endl;
}
[/code]

I am uncertain how to proceed with this issue, as I am not familiar enough with the internals of root to diagnose the issue. All my testing has been done with root v5.34/09.

In TTree::Project the 2nd parameter is a variable expression:
root.cern.ch/root/html534/TTree … ee:Project

you put “1”… looks weird … ? no ?

I think (s)he simply wants to “count” the number of entries that pass cuts, that’s why there’s “1”.
Anyhow, I tried this example on ROOT 5.34/32, and in all cases from “plot_from_file”, I get 256 entries that pass (actually I think I remember some time ago a bug was fixed in ROOT which was related to retrieving tree variables but I can’t find any corresponding link now).

Wile E. Coyote is correct. My intent was to count the number of entries that pass the cuts, and not introduce any extra factors that could be mistaken as the issue.

Thank you, as testing with 5.34/32, I can reproduce Wile’s results, and the bug seems to be gone. I am still a bit confused, as I don’t see anything in the changelog (root.cern.ch/drupal/content/roo … ease-notes) between 5.34/09 and 5.34/32 that references this issue.

Hi,

The problem (see Inconsistent results with TTree::Draw() and sft.its.cern.ch/jira/browse/ROOT-6332) has been in fixed in v5.34/19 (and v6.00/01) and indeed
the note was missing from the release notes.

Cheers,
Philippe.