2012-08-17 2 views
1

나는 병합해야하는 파일이 3 개 있습니다. .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

이것이 내가 할 수 있었던 유일한 방법이므로 이것이 올바른 대답이라고 생각합니다. –