Mmh no, that’s not what I have here. Let’s take this updated version:
void do_ROOT_job(bool upside_down, int ch, double x0, double y0, double r, double l) {
TFile inFile("../../gedet/surf/ver/ver-gedet-surf-0.root");
TFile nFile("../../gedet/nplus/ver/ver-gedet-nplus-0.root", "RECREATE");
TFile pFile("../../gedet/pplus/ver/ver-gedet-pplus-0.root", "RECREATE");
auto tree = dynamic_cast<TTree*>(inFile.Get("GSSTree"));
auto pTree = tree->CloneTree(0);
auto nTree = tree->CloneTree(0);
double x, y, z;
tree->SetBranchAddress("x_cm", &x);
tree->SetBranchAddress("y_cm", &y);
tree->SetBranchAddress("z_cm", &z);
int N = tree->GetEntries();
if (upside_down) {
for (int i = 0; i < N; ++i) {
tree->GetEntry(i);
if ( (x0-x)*(x0-x)+(y0-y)*(y0-y) <= r*r and z > l ) pTree->Fill();
else nTree->Fill();
}
}
else {
for (int i = 0; i < N; ++i) {
tree->GetEntry(i);
if ( (x0-x)*(x0-x)+(y0-y)*(y0-y) <= r*r and z < l ) pTree->Fill();
else nTree->Fill();
}
}
pFile.WriteTObject(pTree);
nFile.WriteTObject(nTree);
}
Now I’m trying to save the two cloned trees into different files. The result is the following:
$ root ver-gedet-pplus-0.root
root [0]
Attaching file ver-gedet-pplus-0.root as _file0...
(TFile *) 0x7fa96fdb1ef0
root [1] .ls
TFile** ver-gedet-pplus-0.root
TFile* ver-gedet-pplus-0.root
KEY: TTree GSSTree;3 General Surface Sampler Coordinate Tree
KEY: TTree GSSTree;2 General Surface Sampler Coordinate Tree
$ root ver-gedet-nplus-0.root
root [0]
Attaching file ver-gedet-nplus-0.root as _file0...
(TFile *) 0x7f98a90e3430
root [1] .ls
TFile** ver-gedet-nplus-0.root
TFile* ver-gedet-nplus-0.root
KEY: TTree GSSTree;1 General Surface Sampler Coordinate Tree
The doubling of trees in the first file is actually what I don’t understand.