Accessing TString functions from a root macro

I have a tree containing a TString leaf LaserDumpName that I want to cut on with a simple macro or with TTreeViewer. However the string functions don’t seem to work. How do I access them? In the code snippet below the scan returns all LaserDumpName variables rather than selecting those beginning with the DDon string. I’ve tried many workarounds and variations of this macro without success.

#include "TString.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TFile.h"
#include "TTree.h"
void traplifetime(TFile* f) {
  TTree* tree=(TTree*)f->Get("vars");
  TString DDon("DD on res");
  TCut DDonc=TCut("rfout>0.533&&LaserDumpName->BeginsWith(DDon)");
  tree->Scan("LaserDumpName",DDonc;
  }

Hi,

TTreeFormula (and hence TTree::Draw) can only call function that takes simple numerical types as argument (hence no object like a TString and passing a const char* to an arbitrary function). One expection (that you might be able to use) is ‘strstr’.

Cheers,
Philippe.

Thanks Philippe. I had already tried using strcmp, and strstr doesn’t work either. It is clear that only macros that loop through the tree class will do what I want. So I think it is best just to avoid using TStrings in the tree file.