我有三个.root
文件需要合并在一起。通常我会hadd
用来合并文件,但文件包含我需要删除的重复条目。我不能只删除重复的条目,因为 TTree 是只读的。有没有一种简单的方法来合并文件,同时确保只保存唯一的条目?
问问题
2413 次
1 回答
1
我确实设法找到一种方法来生成仅包含唯一条目的直方图,使用TEntryList
. 这允许您指定要使用的树条目。就我而言,每个条目都有一个标识它的事件编号。因此,我生成了一个条目列表,其中条目编号仅对应于唯一事件编号。
set<int> eventIds; // keep track of already seen event numbers
int EVENT;
int nEntries = tree->GetEntries();
tree->SetBranchAddress("EVENT",&EVENT); // grab the event number from the tree
TEntryList *tlist = new TEntryList(tree); // initialize entry list for 'TTree* tree'
// loop over the entries in 'tree'
for (int j = 0; j < nEntries; ++j)
{
tree->GetEvent(j);
// if we have not seen this event yet, add it to the set
// and to the entry list
if (eventIds.count(EVENT) == 0)
{
eventIds.insert(EVENT);
tlist->Enter(j,tree);
}
}
// apply the entry list to the tree
tree->SetEntryList(tlist);
// histogram of the variable 'var' will be drawn only with the
// entries specified by the entry list.
tree->Draw("var");
于 2012-08-23T07:24:51.297 回答