2012-08-17 147 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