CERN ROOT 使用事件标头制作树

发布于 2024-11-30 17:11:13 字数 2110 浏览 0 评论 0原文

我需要制作一棵带有事件标题的树。我从一个 ROOT 文件读入两个 ntuples。每个 ntuples 都具有以下格式:

Index  Event     SubEvent      Characteristic1          Characteristic2 .... 
  1      1            1                 322                      234
  2      1            2                 453                      324
  3      1            3                 ...                      ...
  .      .            .                 ...                      ...
  .      .            .                 ...                      ...
 100     1           100                ...                      ...
 101     2            1                 ...                      ...
 102     2            2                 ...                      ...
  .      .            .                 ...                      ...
  .      .            .                 ...                      ...   
  .      .            .                 ...                      ... 
 207     2           107                ...                      ...
 208     3            1                 ...                      ...
 209     3            2                 ...                      ...

依此类推,索引运行到大约 200 万个。

我用来创建 ntuples 的格式:

TNtuple *tp = new TNtuple("tp","tp","x:y:z");
TNtuple *tn = new TNtuple("tn","tn","x:y:z");

for(Int_t n = 0; n < nEvents; n++) {
    inTree->GetEntry(n);
    Int_t nTracks = trackArray->GetEntries();
    for(Int_t i = 0; i < nTracks; i++) {
    Track* trackData = (Track*)trackArray->At(i);
        if(trackData->fCharge == 1)
        tp->Fill(trackData->x,trackData->y,trackData->z);
        if(trackData->fCharge == -1)
            tn->Fill(trackData->x,trackData->y,trackData->z);
        }
    }

但是,对于 ntuples,我遇到的问题是我想要对其进行的分析变得极其耗时。我希望我的数据结构与我正在读取的数据相同,即一棵有两个分支的树(对于我的两个“文件”),每个分支都包含一个偶数标头,以便我可以循环遍历一个中的事件文件,然后仅针对相同事件在第二个文件上嵌套循环。与上一个问题相关。< /a>

我没有如何构造原始文件的代码,这使得上述写入数据的方式成为可能。

I need to make a Tree with event headers. I read from a ROOT file into two ntuples. Each of these ntuples had the following format:

Index  Event     SubEvent      Characteristic1          Characteristic2 .... 
  1      1            1                 322                      234
  2      1            2                 453                      324
  3      1            3                 ...                      ...
  .      .            .                 ...                      ...
  .      .            .                 ...                      ...
 100     1           100                ...                      ...
 101     2            1                 ...                      ...
 102     2            2                 ...                      ...
  .      .            .                 ...                      ...
  .      .            .                 ...                      ...   
  .      .            .                 ...                      ... 
 207     2           107                ...                      ...
 208     3            1                 ...                      ...
 209     3            2                 ...                      ...

and so on, the index runs till about two million.

The format I used to create the ntuples:

TNtuple *tp = new TNtuple("tp","tp","x:y:z");
TNtuple *tn = new TNtuple("tn","tn","x:y:z");

for(Int_t n = 0; n < nEvents; n++) {
    inTree->GetEntry(n);
    Int_t nTracks = trackArray->GetEntries();
    for(Int_t i = 0; i < nTracks; i++) {
    Track* trackData = (Track*)trackArray->At(i);
        if(trackData->fCharge == 1)
        tp->Fill(trackData->x,trackData->y,trackData->z);
        if(trackData->fCharge == -1)
            tn->Fill(trackData->x,trackData->y,trackData->z);
        }
    }

However, with ntuples I have the problem that the analysis that I want to do on it becomes impossibly time consuming. I would like to have my data structured in the same way as the data I am reading, i.e a tree with two braches (for my two "files") and each containing an even header, so that I can loop over the events in one file and subsequently nest a loop over the second file only for the same events. Related to previous question.

I do not have the code for how the original file was constructed, which allowed the above way of writing data possible.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星光不落少年眉 2024-12-07 17:11:13

两百万并不算多。

  1. 尝试关闭不需要的分支。
  2. 将第二个if改为else if
  3. 另外你可以使用Proof

Two millions is not so much.

  1. Try to switch off branches that you don't need.
  2. Change the second if to else if
  3. In addition you can use Proof
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文