2012-08-17 149 views
1

我有三个.root文件需要合并在一起。通常我会使用hadd合并这些文件,但这些文件包含我需要删除的重复条目。我不能只删除重复的条目,因为TTrees是只读的。有没有简单的方法来合并文件,同时确保只保存唯一的条目?删除ROOT TTree中的重复条目

回答

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"); 
+0

这是我唯一能够做到这一点的方法,所以我认为这是正确的答案。 – 2012-10-20 11:37:41