Ntuple draw using mathematical operations

Dear all,

I am using a script to open a root file:

TFile* f = TFile::Open(“file.root”);

which contains an ntuple already created and filled. This ntuple has a variable E, so I can now do:


and a histogras is drawn, as expected. So all is fine. However, if I use insetead anything else appart from “E”,
like for example:


I get

Error: Symbol E is not defined in current scope wavelength.C:63:
*** Interpreter error recovered ***
root [1] .q

The same for ntuple->Draw(“2.*E”), or any other operations.

I know that this is working with trees, but I am hoping it is possible for ntuples as well. So is there any way do draw my ntuple using sqrt(E) for example?

The ntuple was defined in the code that created the root file as:

TNtuple* ntuple = new TNtuple(“ntuple”, “ntuple”,“E”);

Thank you,

Best regards,


Well, you should have no problems with these lines.


Maybe you should show the source code “wavelength.C” around line 63.


ntuple->Print() (well it is ntuple_S5_beamline) gives:

root [1] ntuple_S5_beamline->Print()

*Tree :ntuple_S5_beamline: ntuple_S5_beamline *
*Entries : 3203 : Total = 45076 bytes File Size = 39371 *

  •    :          : Tree compression factor =   1.00                       *

*Br 0 :E : Float_t *
*Entries : 3203 : Total Size= 44692 bytes File Size = 37084 *
*Baskets : 296 : Basket Size= 32000 bytes Compression= 1.00 *

line 63 is the

ntuple_S5_beamline->Draw(“E”) line, which works fine, but if I replace that line with

ntuple_S5_beamline->Draw(“sqrt(E)”) it no longer works.

Hwever I have noticed it works from the terminal:

Cristians-iMac:ISIS_TS1 cristian$ root wavelength.C

  •                                     *
  •    W E L C O M E  to  R O O T       *
  •                                     *
  • Version 5.34/01 13 July 2012 *
  •                                     *
  • You are welcome to visit our Web site *
  •      [root.cern.ch](http://root.cern.ch)            *
  •                                     *

ROOT 5.34/01 (tags/v5-34-01@45048, Jul 13 2012, 15:31:31 on macosx64)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing wavelength.C…
Error: Symbol E is not defined in current scope wavelength.C:74:
*** Interpreter error recovered ***
root [1] TCanvas* c = new TCanvas()
root [2] ntuple_S5_beamline->Draw(“sqrt(E)”)
root [3].q

Do I have to include some headers in my script? Now I have:

#include “TMath.h”
#include “TAxis.h”
#include “TH2.h”
#include “TStyle.h”
#include “TCanvas.h”
#include “TNtupleD.h”
#include <stdio.h>
#include <stdlib.h>
#include <vector.h>

Thank you,


Maybe you have some kind of a source code bug around …

root [0] .L wavelength.C++

BTW. #include “TNtupleD.h” is wrong … you have a “Float_t E” … so #include “TNtuple.h”

P.S. you’d better use:


I do apologise for this, the error was not ROOT related, but it was a C++ error close by :blush: . Now it is working fine.

Sorry for bothering you with this,

Best regards,