我之前在官方根(CERN)论坛上问过这个问题,但到目前为止问题仍未解决。也许这里的任何人都可以通过指出我的错误或提出替代方法来提供帮助?
我有一个带有事件的 TTree;TTree 有一个分支,其中包含每个事件的 UNIX 时间和一些其他分支。我想根据时间间隔选择事件的子集,以便我可以单独分析这些事件。为了进行选择,我创建了另一棵树并在正确的时间间隔内复制所有条目。
以下代码运行良好,并将所有事件从树复制到子树:
void tree_time_filter(TTree* tree, TTree** subtree, Int_t time_i, Int_t time_f){
*subtree = tree->CloneTree(0);
Int_t t;
tree->SetBranchAddress("UNIX time", &t);
for(Long64_t i = 0; i<tree->GetEntries(); i++){
tree->GetEntry(i);
if (true)
{
(*subtree)->Fill();
}
}
cout<<"Tree filtered. "<<(*subtree)->GetEntries()<< " entries were selected.\n";
return;
}
当我用实际条件替换 if(true) 时会出现问题:
void tree_time_filter(TTree* tree, TTree** subtree, Int_t time_i, Int_t time_f){
*subtree = tree->CloneTree(0);
Int_t t;
tree->SetBranchAddress("UNIX time", &t);
for(Long64_t i = 0; i<tree->GetEntries(); i++){
tree->GetEntry(i);
if (t > time_i && t < time_f) //-> the condition
{
(*subtree)->Fill(); //-> this line now gives an error
}
}
cout<<"Tree filtered. "<<(*subtree)->GetEntries()<< " entries were selected.\n";
return;
}
我收到错误:“错误:指向类对象子树的非法指针 0x0 3084 c:/.... * 已恢复解释器错误 * ”
错误行指的是 (*subtree) -> Fill(),与第一个示例中运行良好的代码相同。对于不涉及 t 或任何不涉及子树的 if-body 的任何条件,该代码都有效。谁能解释这里出了什么问题?
谢谢!
(作为参考,原始问题的链接:http ://root.cern.ch/phpBB3/posting.php?mode=edit&f=3&p=79722 )