Bugs with root-6.02 and 5-34 documentation/primer/macros

  1. In macro6,
    replace exp_h->Fill(…); with bkg_h->Fill(…);

  2. in macro9,
    add void type before the pull function of toy MC


thanks for the comment: it’s in the repository
root.cern.ch/gitweb?p=root.git; … 59737f89bc


Note that the same problems appear in ROOT v5-34.

Thanks Danilo and Wile,
Do you guys know a more systematic way of learning Root? I am studying the Primer Guide but it seems it is not including everything and some things are even more advanced for me. At some point I learned to write the following Mathematica code to calculate some function of double integrals numerically. However, as you all know Mathematica is not compatible with complicated calculation (It takes at least two hours to run the following especially if you are not an advanced user). Here is the code and I need some help of doing that in Root. I have seen that there are numerical codes in root but how to complicate those already existing codes into something such complicated? By the way, I am not an Advanced C++ user. But, I am trying to be better in it.

F[u_] = Some nontrivial and long expression in terms of u;

Umax[x_, y_] = Some expression in terms of x and y;

W[x_, y_] := integral of F[u] for u=0..Umax

g[x_ , y_] = Some other expression in terms of x and y;

Alpha[x_] = Some function of x only;

myFunction[x_?NumericQ] := NIntegrat[g[x, y]*W[x,y],{y, Alpha[x], 1}];

Plot[myFunction[x], {x,0,1}]

HI Ashur,

you can give a look to the “Mathematical Libraries” session here:
and to the users’ guide here:
root.cern.ch/root/htmldoc/guide … aries.html
and to the tutorials here, to focus more on examples:
root.cern.ch/root/html528/tutor … index.html

As for the C++ learning, I can imagine some hurdles for someone coming from something like Mathematica, but in my experience the effort has always been rewarding, especially in terms of productivity.


Thank You,

I am typing the following code directly into Root:

gSystem->Load("libRooFit") ;
using namespace RooFit ;

// --- Observable ---
RooRealVar mes("mes","m_{ES} (GeV)",5.20,5.30) ;
// --- Parameters ---
RooRealVar sigmean("sigmean","B^{#pm} mass",5.28,5.20,5.30) ;
RooRealVar sigwidth("sigwidth","B^{#pm} width",0.0027,0.001,1.) ;
// --- Build Gaussian PDF ---
RooGaussian signal("signal","signal PDF",mes,sigmean,sigwidth) ;

// --- Build Argus background PDF ---
RooRealVar argpar("argpar","argus shape parameter",-20.0,-100.,-1.) ;
RooArgusBG background("background","Argus PDF",mes,RooConst(5.291),argpar) ;
// --- Construct signal+background PDF ---
RooRealVar nsig("nsig","#signal events",200,0.,10000) ;
RooRealVar nbkg("nbkg","#background events",800,0.,10000) ;
RooAddPdf model("model","g+a",RooArgList(signal,background),RooArgList(nsig,nbkg)) ;

// --- Generate a toyMC sample from composite PDF ---
RooDataSet *data = model.generate(mes,2000) ;
// --- Perform extended ML fit of composite PDF to toy data ---
model.fitTo(*data) ;
// --- Plot toy data and composite PDF overlaid ---
RooPlot* mesframe = mes.frame() ;
data->plotOn(mesframe) ;
model.plotOn(mesframe) ;
model.plotOn(mesframe,Components(argus),LineStyle(kDashed)) ;

The last line of code gives me this error message:

[quote]ROOT_prompt_17:1:51: error: cannot take the address of an rvalue of
type 'ELineStyle’
model.plotOn(mesframe,Components(argus),LineStyle(kDashed)) ;
Error while creating dynamic expression for:
model.plotOn(mesframe, Components(argus), LineStyle(kDashed))
with internal representation (look for ):
CallExpr 0x9b8e258 <ROOT_prompt_17:1:1, col:59> ‘’
|-UnresolvedMemberExpr 0x9b8ae84 <col:1, col:7> ‘’ lvalue
| -DeclRefExpr 0x9b8ae6c <col:1> 'class RooAddPdf' lvalue Var 0x9abe1b0 'model' 'class RooAddPdf' |-DeclRefExpr 0x9b8aec8 <col:14> 'class RooPlot *' lvalue Var 0x9b7a560 'mesframe' 'class RooPlot *' |-CallExpr 0x9b8e130 <col:23, col:39> '<dependent type>' | |-UnresolvedLookupExpr 0x9b8aee0 <col:23> '<overloaded function type>' lvalue (ADL) = 'Components' 0x9b8a9d8 0x9b8aae8 |-DeclRefExpr 0x9b8af94 col:34 ‘’ lvalue Var 0x9b8af20 ‘argus’ ‘’
-CXXBindTemporaryExpr 0x9b8e248 <col:41, col:58> 'class RooCmdArg' (CXXTemporary 0x9b8e240)-CallExpr 0x9b8e208 <col:41, col:58> ‘class RooCmdArg’
|-ImplicitCastExpr 0x9b8e1f8 col:41 ‘class RooCmdArg (*)(Style_t)’
| -DeclRefExpr 0x9b8e19c <col:41> 'class RooCmdArg (Style_t)' lvalue Function 0x9b8ac18 'LineStyle' 'class RooCmdArg (Style_t)'-ImplicitCastExpr 0x9b8e228 col:51 ‘Style_t’:‘short’
`-DeclRefExpr 0x9b8e184 col:51 ‘enum ELineStyle’ EnumConstant 0x9b8ad48 ‘kDashed’ ‘enum ELineStyle’[/quote]

How to fix the issue?

“Roo*” questions belong to the “Stat and Math Tool Support” forum.

However the second method “The Workspace” right after the first method is working except that we need to make sure the w() is not the same rvalue w which is the parameter of w(). So, I named the parameter w1 in order to make sure that they are not identical and in the subsequent steps each time you want to point to w will be changed to pointing to w1 parameter. So, you would have w1:: instead of w::


in your code, the variable called argus is not declared.


Oops. I will try it later.

How would you do it? It is not working!


I don’t know, depends on what argus is supposed to be. You are not declaring it nor setting it to any value - I don’t know what to say here.


Here is my code:

#include “TFile.h”
#include “TF2.h”
#include “TH1.h”
#include “TH1F.h”
#include “TH2F.h”
#include “TCanvas.h”
#include “TFitResult.h”
#include “TFrame.h”
#include “TMath.h”
#include “TGraphErrors.h”
#include “TGraph2DErrors.h”
#include “TLegend.h”
#include “TApplication.h”
#include “TGraphPolar.h”
#include “TLatex.h”
#include “TProfile.h”
#include “TRandom3.h”
#include “TStyle.h”

#include <math.h>

void graph() {
//Draw a simple graph
// To see the output of this macro, click begin_html here. end_html
//Author: Rene Brun

TCanvas *c1 = new TCanvas(“c1”,“Final Project”,200,10,700,500);


const Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i = 0; i < n; i++) {
x[i] = i * 0.1;
y[i] = ((x[i])3) * ((log(13.1 * x[i]))(-3));
printf(“i %i %f %f \n”, i, x[i], y[i]);
TGraph *gr = new TGraph(n,x,y);
gr->SetTitle(“Generalized Temperature Denpendency of the Initial Axion Field Number Density”);
gr->GetXaxis()->SetTitle(“T (GeV)”);
gr->GetYaxis()->SetTitle(“n_i (cm^(-3))”);

// TCanvas::Update() draws the frame, after which one can change it

#ifndef CINT
void StandaloneApplication(int argc, char** argv) {
// eventually, evaluate the application parameters argc, argv
// ==>> here the ROOT macro is called
// This is the standard “main” of C++ starting
// a ROOT application
int main(int argc, char** argv) {
TApplication app(“ROOT Application”, &argc, argv);
StandaloneApplication(app.Argc(), app.Argv());
return 0;

I am compile and run it using the command line:

I am having error message:

[quote]Axion_Number_Density.C: In function ‘void graph()’:
Axion_Number_Density.C:39:22: error: invalid type argument of unary ‘’ (have ‘int’)
y[i] = ((x[i])3) * ((log(13.1 * x[i]))(-3));
Axion_Number_Density.C:39:51: error: invalid type argument of unary ‘
’ (have ‘int’)
y[i] = ((x[i])3) * ((log(13.1 * x[i]))(-3));[/quote]

I cannot see the problem and I would appreciate your help.


Thanks dear Wile, it worked!

Is there anyway to avoid seeing negative y-values on the plot?

I was able to do so through the Canvas directly rather than adding more lines of code. I hope this is what usually people do.

I am trying to find some source codes in root or any other software written in C++ able to solve a system of differential equations simultaneously. Here is the only link I found in this website which has some small relevance to the topic but it is way too complicated for me to link it to my special need.


Does anyone knows a better source code to do so?

please create a new post on the forum … you are asking to many different questions under the same thread.