Hello,
In my experiment, we have TTree’s with Events, which have std::vectors of Tracks.
I would like to define aliases to refer to specific tracks. like
tree->SetAlias("neutrino","track[0]") ;
The documentation states that this should be possible with more or less exactly this example, but it does not work for me.
Below is a self-contained example. Is this expected to work with std::vector?
Thanks in advance,
aart
// illustrates limitation of TTree aliases
// run with root -l alias.C+
#include <vector>
#include <iostream>
using namespace std;
struct Track : public TObject
{
double x,y,z;
ClassDef(Track,1)
};
struct Evt
{
std::vector<Track> tracks;
ClassDef(Evt,1)
};
#include "TFile.h"
#include "TTree.h"
void write()
{
TFile f("eventfile.root","RECREATE");
TTree* T = new TTree("T","a tree");
Evt* e = new Evt();
T->Branch ("Evt", e, 32000, 4);
for (int i=0; i< 5 ; i++ )
{
e->tracks.resize(1);
e->tracks[0].x = i;
T->Fill();
}
f.Write();
f.Close();
}
void alias()
{
write();
TFile* fin = new TFile("eventfile.root");
TTree* T = (TTree*) fin->Get("T");
T->SetAlias("track0x","Evt.tracks[0].x");
T->SetAlias("track0","Evt.tracks[0]");
T->Scan("track0x"); // okay
T->Scan("track0.x"); // Error in <TTreeFormula::Compile>: Bad numerical expression : "track0.x"
}
output:
root -l alias.C+
root [0]
Processing alias.C+...
Info in <TUnixSystem::ACLiC>: creating shared library ./alias_C.so
************************
* Row * track0x *
************************
* 0 * 0 *
* 1 * 1 *
* 2 * 2 *
* 3 * 3 *
* 4 * 4 *
************************
Error in <TTreeFormula::Compile>: Bad numerical expression : "track0.x"
************************
* Row * track0.x *
************************
* 0 * *
* 1 * *
* 2 * *
* 3 * *
* 4 * *
************************
root [1]
Please read tips for efficient and successful posting and posting code
ROOT Version: 6.18/4
Platform: centos7
Compiler: gcc4.8.5