Passing array of RooAbsArg to RooArgList

Dear RooFit users,

I want to define a PDF made by the sum of several gaussian (at least 11) using RooAddPdf. I define an array of RooGaussian like that

RooRealVar Nphe[Npeak];
RooRealVar frac[Npeak];
RooRealVar sigmaNphe[Npeak];
RooGaussian G[Npeak];

for(Int_t i=0;i<Npeak;i++){

new Nphe[i](Form("%dNphe",i+1),Form("%d photoelectron",i),i+1,i,i+2);
new frac[i](Form(“frac%d”,i+1),Frac(“fraction %d”,i+1), 0.,1.);
new sigmaNphe[i](Form("#sigma%d",i+1),Form(“sigma peak %d”,%d),0.,10.); ///vedere dai dati
new G[i](Form(“G%d”,i+1),Form(“distribution %dst phe”,i+1),N,Nphe[i],sigmaNph[i]);


everything works fine till this point. Now I want to sum all those RooGaussianPdf by using RooAdd PDF

I’d like too avoid something like

RooAddPdf Sig(“singlaPDF”,“gauss sum”,RooArgList(G[0],G[1]…frac[Npeak-1]),RooArgList(frac[0],frac[1],…frac[Npeak-1]))

I guess there should be a smarter more compact way to define it. Does someone has any suggestion?

thank you very much


Why you need to create first an array of the objects. ? I would insert directly the elements in the RooArgList when you create then, using the RoArgList::add method.
Or alternatively you could create any Collection (e.g. TList or TObjArray) since RooArgList has a constructor taking a TCollection



Dear Lorenzo,

thanks for your answer. Maybe i didn’t get how to implement the first solution. Using my code, could you please provide me an example?

thank you