About RooArgList

Hi, rooters,

I am fittting my samples(see attachment XePaix.txt) with polynomial 10.
Here is my code:

/// \file


#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooDataHist.h"
#include "RooGaussian.h"
#include "TCanvas.h"
#include "RooPlot.h"
#include "TTree.h"
#include "TH1D.h"
#include "TRandom.h"
using namespace RooFit;


void rf_mathematical_integral()
{
	
	 RooRealVar x("x", "x", 0,0.12);
   RooRealVar weight("weight", "weight", 0, 4e-5);  
	 RooDataSet *data =  RooDataSet::read("XePaix.txt",RooArgList(x,weight));
	 // create a weighted data
	 RooDataSet wdata(data->GetName(),data->GetTitle(),data,*data->get(),0,weight.GetName());
   
   
	 //pdf is pol6
	 RooRealVar poly_c1("poly_c1", "coefficient of x^1 term", 3.52922e-06);
	 RooRealVar poly_c2("poly_c2", "coefficient of x^2 term", 0.0168763,-1,1);
	 RooRealVar poly_c3("poly_c3", "coefficient of x^3 term", 0.193026,0,1);
	 RooRealVar poly_c4("poly_c4", "coefficient of x^4 term", -15.7153,-18,-14);
	 RooRealVar poly_c5("poly_c5", "coefficient of x^5 term", 674.883);
	 RooRealVar poly_c6("poly_c6", "coefficient of x^6 term", -18735.3);
	 RooRealVar poly_c7("poly_c7", "coefficient of x^7 term", 280024);
	 RooRealVar poly_c8("poly_c8", "coefficient of x^8 term", -2.26168e+06);
	 RooRealVar poly_c9("poly_c9", "coefficient of x^9 term", 9.43141e+06);
	 RooRealVar poly_c10("poly_c10", "coefficient of x^10 term", -1.60257e+07);
   RooPolynomial poly("poly", "poly", x, RooArgList(poly_c1,poly_c2,poly_c3,poly_c4,poly_c5,poly_c6,poly_c7,poly_c8,poly_c9,poly_c10),0);
   
	 
   poly.fitTo(wdata, Range(0, 0.12), Extended(kTRUE));
	 
	 
	 //poly.fitTo(wdata,SumW2Error(kTRUE));

   
   TCanvas *c = new TCanvas("rf102", "rf102", 800, 400); 
   RooPlot* xframe = x.frame();
   wdata.plotOn(xframe);
   poly.plotOn(xframe);
   poly.paramOn(xframe,Layout(0.67,0.95,0.98));
	 xframe->Draw();
    
}


The fit result is:

I guess the [RooArgList::RooArgList](const RooArgSet & set ) is less than 8. But my set is 10.
But I don’t know how to write my code with agrList.add().

Looking forward to your reply.
Best regards,
hurricane

XePaix.txt (3.9 KB)

Hi @hurricane1127,

Which version of ROOT are you using?

Actually, I have seen here (i.e., in ROOT master branch), that there is a RooArgList constructor based on a variadic template. This constructor should be happy to take your 10 RooRealVar arguments.

Given that, I think your code should compile on newer ROOT, buy maybe @jonas could confirm that.

Cheers,
J.

Hi @Profile - hurricane1127 - ROOT Forum,

from your screenshot I can see that you are using ROOT 6.20. Support for an arbitrary number of arguments to the RooArgList constructor was only added in ROOT 6.24.

Indeed you have to use RooArgLIst::add() to add the arguments that are too much for the constructor. The code would look like this:

     RooArgList coefList(poly_c1,poly_c2,poly_c3,poly_c4,poly_c5,
                         poly_c6,poly_c7,poly_c8,poly_c9);
     coefList.add(poly_c10);
     RooPolynomial poly("poly", "poly", x, coefList, 0);

Of course you can also start with an empty RooArgLIst and then add() all coefficients one after the other.

I hope that solves your problem, don’t hesitate to ask further questions!

Cheers,
Jonas

Thanks for your reply. The bug originates my ROOT version 6.20 .

Thanks for your reply.

Hi @hurricane1127, sorry for the late reply!

This is just a quick post to keep the thread from being automatically closed after 14 days. I have not forgotten about this and will write a real answer shortly.

Thanks, looking forward to your reply.

Best regards,
hurricane

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.