Home | News | Documentation | Download

TTree Alias as the start of symbol

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


@pcanal do you know if it is possible to define aliases for individual elements of a vector branch (like tracks)?

Indeed at the moment a TTree Alias can not be used as part of a ‘composed variable’ name. Sorry :frowning:

Thanks for the reply.

That’s too bad. I guess the documentation should then be corrected.

It seems to me that a simple textual substitution (prior to all parsing any of the expressions – like a #define) would maybe yield more flexible Aliases. Maybe such aliases can be considered for the future.

The following seems to work, so I guess one could simply define an alias for each
and every member :slight_smile:
T->SetAlias("track0.x","Evt.tracks[0].x");

thanks again,
aart

Thanks for the reply.

That’s too bad. I guess the documentation should then be corrected.

It seems to me that a simple textual substitution (prior to all parsing any of the expressions – like a #define) would maybe yield more flexible Aliases. Maybe such aliases can be considered for the future.

The following seems to work, so I guess one could simply define an alias for each
and every member :slight_smile:
T->SetAlias("track0.x","Evt.tracks[0].x");

thanks again,
aart