Using RooChi2MCSModule

Hello Experts

I am trying to follow an example here : … ons.C.html

to do the exact same thing, but the histograms I get as the output of these for chi2 and chi2_reduced
show just the total number of samples generated as 1000.
I am hoping this plot to be a distribution of the chi2 from 1000 pseudo experiments I have asked RooMCStudy to generate and Fit.

This is the code snippet:

RooRealVar cbmean(“cb mean”,“cb_mean”,173.2,165,175);
RooRealVar cbwidth(“cb width”,“cb_width”,10,0,15);
RooRealVar cbn(“cb n”,“cb_n”,150,100,180);
RooRealVar cbalpha(“cb alpha”,“cb_alpha”,5,0,10.);
RooCBShape cb(“cb”,“cb”,x,cbmean,cbwidth,cbalpha,cbn) ;
RooAddPdf sum(“cbfit”,“crystal ball fit”,RooArgList(esig));

RooMCStudy* mcstudy =new RooMCStudy(sum,x,Binned(true),Verbose(false),Extended(),Silence() );
// Add a chi2 module
RooChi2MCSModule chi2mod ;
mcstudy->addModule(chi2mod) ;
// Generate and fit results

// Fill histograms with distributions chi2 and prob(chi2,ndf) that are calculated by RooChiMCSModule
TH1* hist_chi2 = mcstudy->fitParDataSet().createHistogram(“chi2”) ;
TH1* hist_chi2red = mcstudy->fitParDataSet().createHistogram(“chi2red”) ;

TCanvas* c3=new TCanvas();
c3->cd(1) ; gPad->SetLeftMargin(0.15) ; hist_chi2->GetYaxis()->SetTitleOffset(1.4) ; hist_chi2->Draw() ;
c3->cd(2) ; gPad->SetLeftMargin(0.15) ; hist_chi2red->GetYaxis()->SetTitleOffset(1.4) ; hist_chi2red->Draw() ;

Any insights?



Can you please post a running example showing the problem ? It is not 100% clear to me what the problem is and I would need to reproduce it

Thank you


Hi Lorenzo,

Sure I can provide more information for you… I appreciate your help!
I also attached the macro and the input root file is too large to be attached, all I do to run is
root -l fitMassPeak.C+

Sorry the code is not the most clean but it works.
I attached the plots I made with this macro. As you can
see the chi2 and chi2red plots are what I do not understand.

pull.eps (9.92 KB)
resid.eps (10.5 KB)
cb_fit.eps (15.8 KB)
fitMassPeak.C (20.2 KB)
mcstudy_chi2.eps (15.6 KB)


I am still looking to make this work… Any suggestions?

Much Thanks

Lorenzo is away for the time being . I’ll remind him.


Thanks for uploading the files. I’ll look at them as soon I find the time.