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.